This is an automated email from the ASF dual-hosted git repository.
gabriellee 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 cc072d35b7 [Bug](date) Fix wrong type in TimestampArithmeticExpr
(#12727)
cc072d35b7 is described below
commit cc072d35b7fae9b820a4d40ccd8b84c8920d5849
Author: Gabriel <[email protected]>
AuthorDate: Tue Sep 20 21:08:48 2022 +0800
[Bug](date) Fix wrong type in TimestampArithmeticExpr (#12727)
---
.../doris/analysis/TimestampArithmeticExpr.java | 19 ++++++++++++++++++-
.../datetime_functions/test_date_function.out | 7 +++++++
.../datetime_functions/test_date_function.groovy | 3 +++
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/TimestampArithmeticExpr.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/TimestampArithmeticExpr.java
index bc2cbc5090..2fc7850abc 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/analysis/TimestampArithmeticExpr.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/analysis/TimestampArithmeticExpr.java
@@ -275,8 +275,25 @@ public class TimestampArithmeticExpr extends Expr {
(op == ArithmeticExpr.Operator.ADD) ? "ADD" : "SUB");
}
- fn = getBuiltinFunction(funcOpName.toLowerCase(),
collectChildReturnTypes(),
+ Type[] childrenTypes = collectChildReturnTypes();
+ fn = getBuiltinFunction(funcOpName.toLowerCase(), childrenTypes,
Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF);
+ Preconditions.checkArgument(fn != null);
+ Type[] argTypes = fn.getArgs();
+ if (argTypes.length > 0) {
+ // Implicitly cast all the children to match the function if
necessary
+ for (int i = 0; i < childrenTypes.length; ++i) {
+ // For varargs, we must compare with the last type in
callArgs.argTypes.
+ int ix = Math.min(argTypes.length - 1, i);
+ if (!childrenTypes[i].matchesType(argTypes[ix]) &&
Config.enable_date_conversion
+ && !childrenTypes[i].isDateType() &&
(argTypes[ix].isDate() || argTypes[ix].isDatetime())) {
+
uncheckedCastChild(ScalarType.getDefaultDateType(argTypes[ix]), i);
+ } else if (!childrenTypes[i].matchesType(argTypes[ix]) && !(
+ childrenTypes[i].isDateType() &&
argTypes[ix].isDateType())) {
+ uncheckedCastChild(argTypes[ix], i);
+ }
+ }
+ }
LOG.debug("fn is {} name is {}", fn, funcOpName);
}
diff --git
a/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
b/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
index a669d92bd8..7dd6e39d9e 100644
---
a/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
+++
b/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
@@ -430,3 +430,10 @@ true
-- !sql --
2019-08-01T13:21:02
+
+-- !sql --
+\N
+
+-- !sql --
+\N
+
diff --git
a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
index c7cdd4ddca..389b778e79 100644
---
a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
+++
b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
@@ -359,4 +359,7 @@ suite("test_date_function") {
qt_sql """ select minutes_sub(test_time,1) result from ${tableName}; """
//seconds_sub
qt_sql """ select seconds_sub(test_time,1) result from ${tableName}; """
+
+ qt_sql """ select date_add(NULL, INTERVAL 1 month); """
+ qt_sql """ select date_add(NULL, INTERVAL 1 day); """
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]