You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by da...@apache.org on 2023/01/01 03:09:06 UTC

[doris] branch master updated: [Bug](decimalv3) Fix wrong decimalv3 value after insertion (#15505)

This is an automated email from the ASF dual-hosted git repository.

dataroaring pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new ad9a67a76a [Bug](decimalv3) Fix wrong decimalv3 value after insertion (#15505)
ad9a67a76a is described below

commit ad9a67a76a64026e6bb67796d9f256b06a51d129
Author: Gabriel <ga...@gmail.com>
AuthorDate: Sun Jan 1 11:08:59 2023 +0800

    [Bug](decimalv3) Fix wrong decimalv3 value after insertion (#15505)
---
 be/src/util/string_parser.hpp                      |  2 +-
 .../data/datatype_p0/decimalv3/test_load.out       |  6 +++
 .../datatype_p0/decimalv3/test_data/test.csv       |  3 ++
 .../suites/datatype_p0/decimalv3/test_load.groovy  | 58 ++++++++++++++++++++++
 4 files changed, 68 insertions(+), 1 deletion(-)

diff --git a/be/src/util/string_parser.hpp b/be/src/util/string_parser.hpp
index 7562c22d06..653f0dac14 100644
--- a/be/src/util/string_parser.hpp
+++ b/be/src/util/string_parser.hpp
@@ -757,8 +757,8 @@ inline T StringParser::string_to_decimal(const char* s, int len, int type_precis
                 divisor = get_scale_multiplier<T>(shift);
             }
             if (LIKELY(divisor >= 0)) {
-                value /= divisor;
                 T remainder = value % divisor;
+                value /= divisor;
                 if ((remainder > 0 ? T(remainder) : T(-remainder)) >= (divisor >> 1)) {
                     value += 1;
                 }
diff --git a/regression-test/data/datatype_p0/decimalv3/test_load.out b/regression-test/data/datatype_p0/decimalv3/test_load.out
new file mode 100644
index 0000000000..35c355781e
--- /dev/null
+++ b/regression-test/data/datatype_p0/decimalv3/test_load.out
@@ -0,0 +1,6 @@
+-- This file is automatically generated. You should know what you did if you want to edit this
+-- !select_default --
+0.000132253565002480
+0.000135039891190100
+0.000390160098269360
+
diff --git a/regression-test/suites/datatype_p0/decimalv3/test_data/test.csv b/regression-test/suites/datatype_p0/decimalv3/test_data/test.csv
new file mode 100644
index 0000000000..667fe01c08
--- /dev/null
+++ b/regression-test/suites/datatype_p0/decimalv3/test_data/test.csv
@@ -0,0 +1,3 @@
+0.00013225356500247968
+0.00039016009826936000
+0.00013503989119010048
diff --git a/regression-test/suites/datatype_p0/decimalv3/test_load.groovy b/regression-test/suites/datatype_p0/decimalv3/test_load.groovy
new file mode 100644
index 0000000000..ba7b04ad94
--- /dev/null
+++ b/regression-test/suites/datatype_p0/decimalv3/test_load.groovy
@@ -0,0 +1,58 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+import org.codehaus.groovy.runtime.IOGroovyMethods
+
+import java.nio.charset.StandardCharsets
+import java.nio.file.Files
+import java.nio.file.Paths
+
+suite("test_load") {
+    def dbName = "test_load"
+    sql "CREATE DATABASE IF NOT EXISTS ${dbName}"
+    sql "USE $dbName"
+
+    def tableName = "test_decimal_load"
+    try {
+        sql """ DROP TABLE IF EXISTS ${tableName} """
+        sql """
+        CREATE TABLE IF NOT EXISTS ${tableName} (
+              `a` decimalv3(38,18)
+            ) ENGINE=OLAP
+            DUPLICATE KEY(`a`)
+            COMMENT 'OLAP'
+            DISTRIBUTED BY HASH(`a`) BUCKETS 1
+            PROPERTIES (
+            "replication_allocation" = "tag.location.default: 1"
+        );
+        """
+
+        StringBuilder commandBuilder = new StringBuilder()
+        commandBuilder.append("""curl --location-trusted -u ${context.config.feHttpUser}:${context.config.feHttpPassword}""")
+        commandBuilder.append(""" -H format:csv -T ${context.file.parent}/test_data/test.csv http://${context.config.feHttpAddress}/api/""" + dbName + "/" + tableName + "/_stream_load")
+        command = commandBuilder.toString()
+        process = command.execute()
+        code = process.waitFor()
+        err = IOGroovyMethods.getText(new BufferedReader(new InputStreamReader(process.getErrorStream())))
+        out = process.getText()
+        logger.info("Run command: command=" + command + ",code=" + code + ", out=" + out + ", err=" + err)
+        assertEquals(code, 0)
+        qt_select_default """ SELECT * FROM ${tableName} t ORDER BY a; """
+    } finally {
+        try_sql("DROP TABLE IF EXISTS ${tableName}")
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org