This is an automated email from the ASF dual-hosted git repository.
morrysnow 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 60231454cc [fix](nereids) fix bug in multiply return data type (#15949)
60231454cc is described below
commit 60231454cc319884109b9e9b01bffbd3a3d126b0
Author: minghong <[email protected]>
AuthorDate: Fri Jan 20 11:44:24 2023 +0800
[fix](nereids) fix bug in multiply return data type (#15949)
---
.../doris/nereids/trees/expressions/Multiply.java | 8 ++++++-
.../doris/nereids/util/TypeCoercionUtils.java | 4 +++-
.../rules/expression/rewrite/FoldConstantTest.java | 2 +-
.../data/nereids_datev2_p1/tpch/q14.out | 4 ++--
regression-test/data/nereids_tpch_p1/tpch/q14.out | 4 ++--
.../suites/nereids_syntax_p0/test_join3.groovy | 6 ++---
.../suites/nereids_syntax_p0/using_join.groovy | 28 +++++++++++-----------
7 files changed, 32 insertions(+), 24 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Multiply.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Multiply.java
index 818e8a43cd..bd91f3449e 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Multiply.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Multiply.java
@@ -22,6 +22,7 @@ import
org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DataType;
import org.apache.doris.nereids.types.coercion.AbstractDataType;
import org.apache.doris.nereids.types.coercion.NumericType;
+import org.apache.doris.nereids.util.TypeCoercionUtils;
import com.google.common.base.Preconditions;
@@ -44,7 +45,12 @@ public class Multiply extends BinaryArithmetic {
@Override
public DataType getDataType() {
- return left().getDataType().promotion();
+ DataType rightType = child(0).getDataType();
+ DataType leftType = child(1).getDataType();
+ DataType outputType = TypeCoercionUtils.findTightestCommonType(this,
+ rightType, leftType).orElseGet(() -> rightType);
+ outputType = outputType.promotion();
+ return outputType;
}
@Override
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java
index b3f6733c47..b35fbd9fca 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java
@@ -214,7 +214,7 @@ public class TypeCoercionUtils {
} else if (left instanceof CharacterType && right instanceof
CharacterType) {
tightestCommonType =
CharacterType.widerCharacterType((CharacterType) left, (CharacterType) right);
} else if (left instanceof CharacterType && right instanceof
DateLikeType
- || left instanceof DateLikeType && right instanceof
CharacterType) {
+ || left instanceof DateLikeType && right instanceof
CharacterType) {
// TODO: need check implicitCastMap to keep the behavior
consistent with old optimizer
tightestCommonType = right;
} else if (left instanceof CharacterType || right instanceof
CharacterType) {
@@ -259,6 +259,8 @@ public class TypeCoercionUtils {
//do not upgrade data type, keep Float
tightestCommonType = FloatType.INSTANCE;
}
+ } else if (left instanceof DecimalV2Type && right instanceof
DecimalV2Type) {
+ tightestCommonType =
DecimalV2Type.widerDecimalV2Type((DecimalV2Type) left, (DecimalV2Type) right);
} else if (canCompareDate(left, right)) {
if (binaryOperator instanceof BinaryArithmetic) {
tightestCommonType = IntegerType.INSTANCE;
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rewrite/FoldConstantTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rewrite/FoldConstantTest.java
index d0d86a3559..394c97da1a 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rewrite/FoldConstantTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rewrite/FoldConstantTest.java
@@ -120,7 +120,7 @@ public class FoldConstantTest extends
ExpressionRewriteTestHelper {
}
@Test
- public void testNotFold() {
+ public void testNotPredicateFold() {
executor = new
ExpressionRuleExecutor(ImmutableList.of(TypeCoercion.INSTANCE,
FoldConstantRuleOnFE.INSTANCE));
assertRewriteAfterTypeCoercion("not 1 > 2", "true");
assertRewriteAfterTypeCoercion("not null + 1 > 2", "null");
diff --git a/regression-test/data/nereids_datev2_p1/tpch/q14.out
b/regression-test/data/nereids_datev2_p1/tpch/q14.out
index 91122b64a2..90897ced93 100644
--- a/regression-test/data/nereids_datev2_p1/tpch/q14.out
+++ b/regression-test/data/nereids_datev2_p1/tpch/q14.out
@@ -1,7 +1,7 @@
-- This file is automatically generated. You should know what you did if you
want to edit this
-- !select --
-16.283855689
+16.283855700
-- !select --
-16.283855689
+16.283855700
diff --git a/regression-test/data/nereids_tpch_p1/tpch/q14.out
b/regression-test/data/nereids_tpch_p1/tpch/q14.out
index 91122b64a2..90897ced93 100644
--- a/regression-test/data/nereids_tpch_p1/tpch/q14.out
+++ b/regression-test/data/nereids_tpch_p1/tpch/q14.out
@@ -1,7 +1,7 @@
-- This file is automatically generated. You should know what you did if you
want to edit this
-- !select --
-16.283855689
+16.283855700
-- !select --
-16.283855689
+16.283855700
diff --git a/regression-test/suites/nereids_syntax_p0/test_join3.groovy
b/regression-test/suites/nereids_syntax_p0/test_join3.groovy
index cf59e8f79c..c3ab7b1c02 100644
--- a/regression-test/suites/nereids_syntax_p0/test_join3.groovy
+++ b/regression-test/suites/nereids_syntax_p0/test_join3.groovy
@@ -25,9 +25,9 @@ suite("nereids_test_join3", "query,p0") {
sql "CREATE DATABASE IF NOT EXISTS ${DBname}"
sql "use ${DBname}"
- def tbName1 = "t1"
- def tbName2 = "t2"
- def tbName3 = "t3"
+ def tbName1 = "nereids_test_join3t1"
+ def tbName2 = "nereids_test_join3t2"
+ def tbName3 = "nereids_test_join3t3"
sql """CREATE TABLE IF NOT EXISTS ${tbName1} (name varchar(255), n
INTEGER) DISTRIBUTED BY HASH(name) properties("replication_num" = "1");"""
sql """CREATE TABLE IF NOT EXISTS ${tbName2} (name varchar(255), n
INTEGER) DISTRIBUTED BY HASH(name) properties("replication_num" = "1");"""
diff --git a/regression-test/suites/nereids_syntax_p0/using_join.groovy
b/regression-test/suites/nereids_syntax_p0/using_join.groovy
index d53d378650..795dc07b48 100644
--- a/regression-test/suites/nereids_syntax_p0/using_join.groovy
+++ b/regression-test/suites/nereids_syntax_p0/using_join.groovy
@@ -24,10 +24,10 @@ suite("nereids_using_join") {
SET enable_nereids_planner=true
"""
- sql """DROP TABLE IF EXISTS t1"""
+ sql """DROP TABLE IF EXISTS nereids_using_join_t1"""
sql """
- CREATE TABLE `t1` (
+ CREATE TABLE `nereids_using_join_t1` (
`col1` varchar(4) NULL,
`col2` int(11) NULL,
`col3` int(11) NULL
@@ -40,10 +40,10 @@ suite("nereids_using_join") {
);
"""
- sql """DROP TABLE IF EXISTS t2"""
+ sql """DROP TABLE IF EXISTS nereids_using_join_t2"""
sql """
- CREATE TABLE `t2` (
+ CREATE TABLE `nereids_using_join_t2` (
`col1` varchar(4) NULL,
`col2` int(11) NULL,
`col3` int(11) NULL
@@ -56,22 +56,22 @@ suite("nereids_using_join") {
);
"""
- sql """INSERT INTO t1 VALUES('1', 1, 1)"""
- sql """INSERT INTO t1 VALUES('2', 2, 1)"""
- sql """INSERT INTO t1 VALUES('3', 3, 1)"""
- sql """INSERT INTO t1 VALUES('4', 4, 1)"""
+ sql """INSERT INTO nereids_using_join_t1 VALUES('1', 1, 1)"""
+ sql """INSERT INTO nereids_using_join_t1 VALUES('2', 2, 1)"""
+ sql """INSERT INTO nereids_using_join_t1 VALUES('3', 3, 1)"""
+ sql """INSERT INTO nereids_using_join_t1 VALUES('4', 4, 1)"""
- sql """INSERT INTO t2 VALUES('1', 1, 1)"""
- sql """INSERT INTO t2 VALUES('2', 2, 1)"""
- sql """INSERT INTO t2 VALUES('6', 3, 1)"""
- sql """INSERT INTO t2 VALUES('7', 4, 1)"""
+ sql """INSERT INTO nereids_using_join_t2 VALUES('1', 1, 1)"""
+ sql """INSERT INTO nereids_using_join_t2 VALUES('2', 2, 1)"""
+ sql """INSERT INTO nereids_using_join_t2 VALUES('6', 3, 1)"""
+ sql """INSERT INTO nereids_using_join_t2 VALUES('7', 4, 1)"""
order_qt_sql """
- SELECT t1.col1 FROM t1 JOIN t2 USING (col1)
+ SELECT nereids_using_join_t1.col1 FROM nereids_using_join_t1 JOIN
nereids_using_join_t2 USING (col1)
"""
order_qt_sql """
- SELECT t1.col1 FROM t1 JOIN t2 USING (col1, col2)
+ SELECT nereids_using_join_t1.col1 FROM nereids_using_join_t1 JOIN
nereids_using_join_t2 USING (col1, col2)
"""
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]