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 14dcc53135 [fix](Nereids) cast time should turn nullable on all valid
types (#22242)
14dcc53135 is described below
commit 14dcc5313505b6e0ae8cd1f35d16d63901112ba8
Author: morrySnow <[email protected]>
AuthorDate: Wed Jul 26 17:56:19 2023 +0800
[fix](Nereids) cast time should turn nullable on all valid types (#22242)
valid types to cast to time/timev2:
- TINYINT
- SMALLINT
- INT
- BIGINT
- LARGEINT
- FLOAT
- DOUBLE
- CHAR
- VARCHAR
- STRING
---
.../glue/translator/PhysicalPlanTranslator.java | 2 +-
.../nereids/rules/expression/check/CheckCast.java | 4 ++
.../doris/nereids/trees/expressions/Cast.java | 2 +
.../org/apache/doris/nereids/types/DataType.java | 2 +-
regression-test/data/nereids_syntax_p0/cast.out | 80 ++++++++++++++++++++++
.../suites/nereids_syntax_p0/cast.groovy | 44 ++++++++++++
6 files changed, 132 insertions(+), 2 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
index dbfeade1a4..40d08cddef 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
@@ -594,7 +594,7 @@ public class PhysicalPlanTranslator extends
DefaultPlanVisitor<PlanFragment, Pla
SlotDescriptor slotDescriptor = oneRowTuple.getSlots().get(i);
Expr expr = legacyExprs.get(i);
slotDescriptor.setSourceExpr(expr);
- slotDescriptor.setIsNullable(expr.isNullable());
+ slotDescriptor.setIsNullable(slots.get(i).nullable());
}
UnionNode unionNode = new UnionNode(context.nextPlanNodeId(),
oneRowTuple.getId());
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/check/CheckCast.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/check/CheckCast.java
index 361b5f38f5..c377a0e9e9 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/check/CheckCast.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/check/CheckCast.java
@@ -80,6 +80,10 @@ public class CheckCast extends AbstractExpressionRewriteRule
{
if (targetType.isNullType()) {
return false;
}
+ if (targetType.isTimeLikeType() && !(originalType.isIntegralType()
+ || originalType.isStringLikeType() ||
originalType.isFloatLikeType())) {
+ return false;
+ }
return true;
}
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Cast.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Cast.java
index 012e143dd2..295b22e3f0 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Cast.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Cast.java
@@ -56,6 +56,8 @@ public class Cast extends Expression implements
UnaryExpression {
return true;
} else if (!childDataType.isDateLikeType() &&
targetType.isDateLikeType()) {
return true;
+ } else if (!childDataType.isTimeLikeType() &&
targetType.isTimeLikeType()) {
+ return true;
} else {
return child().nullable();
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java
index affa20df2b..f608292f9b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java
@@ -395,7 +395,7 @@ public abstract class DataType implements AbstractDataType {
}
public boolean isFloatLikeType() {
- return this.isFloatType() || isDoubleType() || isDecimalLikeType();
+ return this.isFloatType() || isDoubleType();
}
public boolean isTinyIntType() {
diff --git a/regression-test/data/nereids_syntax_p0/cast.out
b/regression-test/data/nereids_syntax_p0/cast.out
index 43810027c2..8be6228e0f 100644
--- a/regression-test/data/nereids_syntax_p0/cast.out
+++ b/regression-test/data/nereids_syntax_p0/cast.out
@@ -269,3 +269,83 @@ true 0.1
-- !sql_test_DecimalV3_mode --
1.0
+-- !tinyint --
+00:00:01
+00:00:02
+00:00:03
+
+-- !smallint --
+\N
+\N
+\N
+
+-- !int --
+00:10:01
+00:10:01
+00:10:02
+
+-- !bigint --
+838:59:59
+838:59:59
+838:59:59
+
+-- !largeint --
+-838:59:59
+00:00:00
+838:59:59
+
+-- !float --
+\N
+00:00:06
+00:36:54
+
+-- !double --
+\N
+00:00:00
+00:00:20
+
+-- !char --
+\N
+\N
+\N
+
+-- !varchar --
+\N
+\N
+\N
+
+-- !string --
+\N
+\N
+\N
+
+-- !tinyint --
+00:00:01
+
+-- !smallint --
+00:00:01
+
+-- !int --
+00:00:01
+
+-- !bigint --
+00:00:01
+
+-- !largeint --
+00:00:01
+
+-- !float --
+00:00:00
+
+-- !double --
+00:00:00
+
+-- !char --
+00:00:01
+
+-- !varchar --
+00:00:01
+
+-- !string --
+00:00:01
+
diff --git a/regression-test/suites/nereids_syntax_p0/cast.groovy
b/regression-test/suites/nereids_syntax_p0/cast.groovy
index 8618ef7b10..24dc63628d 100644
--- a/regression-test/suites/nereids_syntax_p0/cast.groovy
+++ b/regression-test/suites/nereids_syntax_p0/cast.groovy
@@ -195,4 +195,48 @@ suite("cast") {
}
qt_sql_test_DecimalV3_mode """select cast(1 as DECIMALV3(1, 0)) % 2.1;""";
+
+ // test cast to time
+ qt_tinyint """select cast(k1 as time) ct from test order by ct;"""
+ qt_smallint """select cast(k2 as time) ct from test order by ct;"""
+ qt_int """select cast(k3 as time) ct from test order by ct;"""
+ qt_bigint """select cast(k4 as time) ct from test order by ct;"""
+ qt_largeint """select cast(k13 as time) ct from test order by ct;"""
+ qt_float """select cast(k9 as time) ct from test order by ct;"""
+ qt_double """select cast(k8 as time) ct from test order by ct;"""
+ qt_char """select cast(k6 as time) ct from test order by ct;"""
+ qt_varchar """select cast(k7 as time) ct from test order by ct;"""
+ qt_string """select cast(k12 as time) ct from test order by ct;"""
+
+ qt_tinyint """select cast(cast(1 as tinyint) as time)"""
+ qt_smallint """select cast(cast(1 as smallint) as time)"""
+ qt_int """select cast(cast(1 as int) as time)"""
+ qt_bigint """select cast(cast(1 as bigint) as time)"""
+ qt_largeint """select cast(cast(1 as largeint) as time)"""
+ qt_float """select cast(cast(0 as float) as time)"""
+ qt_double """select cast(cast(0 as double) as time)"""
+ qt_char """select cast(cast("1" as char(1)) as time)"""
+ qt_varchar """select cast(cast("1" as varchar(1)) as time)"""
+ qt_string """select cast(cast("1" as string) as time)"""
+
+ // boolean
+ test {
+ sql """select cast(k0 as time) ct from test order by ct;"""
+ exception "cannot cast"
+ }
+ // decimal
+ test {
+ sql """select cast(k5 as time) ct from test order by ct;"""
+ exception "cannot cast"
+ }
+ // date
+ test {
+ sql """select cast(k10 as time) ct from test order by ct;"""
+ exception "cannot cast"
+ }
+ // datetime
+ test {
+ sql """select cast(k11 as time) ct from test order by ct;"""
+ exception "cannot cast"
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]