You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2022/06/08 16:35:28 UTC

[incubator-doris] branch master updated: [fix](regression-test) fix the comparison errors caused by inconsistent accuracy (#9931)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new e5ed259da6 [fix](regression-test) fix the comparison errors caused by inconsistent accuracy (#9931)
e5ed259da6 is described below

commit e5ed259da6b4f401db39f0a4206ba2ba2a048086
Author: Ashin Gau <As...@users.noreply.github.com>
AuthorDate: Thu Jun 9 00:35:22 2022 +0800

    [fix](regression-test) fix the comparison errors caused by inconsistent accuracy (#9931)
---
 .../org/apache/doris/regression/util/OutputUtils.groovy  | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/regression-test/framework/src/main/groovy/org/apache/doris/regression/util/OutputUtils.groovy b/regression-test/framework/src/main/groovy/org/apache/doris/regression/util/OutputUtils.groovy
index e8f193f376..b220f4deeb 100644
--- a/regression-test/framework/src/main/groovy/org/apache/doris/regression/util/OutputUtils.groovy
+++ b/regression-test/framework/src/main/groovy/org/apache/doris/regression/util/OutputUtils.groovy
@@ -24,6 +24,8 @@ import org.apache.commons.csv.CSVPrinter
 import org.apache.commons.csv.CSVRecord
 import org.apache.commons.io.LineIterator
 
+import java.math.BigDecimal
+import java.math.RoundingMode
 import java.util.function.Function
 import java.sql.ResultSetMetaData
 
@@ -54,7 +56,7 @@ class OutputUtils {
     }
 
     static String checkCell(String info, int line, String expectCell, String realCell, String dataType) {
-        if (dataType == "FLOAT" || dataType == "DOUBLE") {
+        if (dataType == "FLOAT" || dataType == "DOUBLE" || dataType == "DECIMAL") {
             Boolean expectNull = expectCell.equals("\\\\N")
             Boolean actualNull = realCell.equals("\\\\N")
 
@@ -69,6 +71,18 @@ class OutputUtils {
                 double expectRelativeError = 1e-10
 
                 if(expectRelativeError < realRelativeError) {
+                    // Keep the scale of low precision data to solve TPCH cases like:
+                    // "Expect cell is: 0.0395, But real is: 0.039535109"
+                    int expectDecimalPlaces = expectCell.contains(".") ? expectCell.length() - expectCell.lastIndexOf(".") - 1 : 0
+                    int realDecimalPlaces = realCell.contains(".") ? realCell.length() - realCell.lastIndexOf(".") - 1 : 0
+                    if (expectDecimalPlaces != realDecimalPlaces) {
+                        int lowDecimalPlaces = Math.min(expectDecimalPlaces, realDecimalPlaces)
+                        double lowNumber = expectDecimalPlaces < realDecimalPlaces ? expectDouble : realDouble
+                        double highNumber = expectDecimalPlaces < realDecimalPlaces ? realDouble : expectDouble
+                        if (new BigDecimal(highNumber).setScale(lowDecimalPlaces, RoundingMode.HALF_UP).doubleValue() == lowNumber) {
+                            return null
+                        }
+                    }
                     return "${info}, line ${line}, ${dataType} result mismatch.\nExpect cell is: ${expectCell}\nBut real is: ${realCell}\nrelative error is: ${realRelativeError}, bigger than ${expectRelativeError}"
                 }
             }


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