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 2024/07/07 00:11:40 UTC
(doris) branch master updated: [fix](Nereids) constant folding for str_to_date on datev1 is wrong (#37360)
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 beb42a09590 [fix](Nereids) constant folding for str_to_date on datev1 is wrong (#37360)
beb42a09590 is described below
commit beb42a09590c3fec6203833afc51692f575d2b1d
Author: morrySnow <10...@users.noreply.github.com>
AuthorDate: Sun Jul 7 08:11:33 2024 +0800
[fix](Nereids) constant folding for str_to_date on datev1 is wrong (#37360)
when enable datev1, we should return datev1/datetimev1
---
.../executable/DateTimeExtractAndTransform.java | 24 ++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java
index 754c13e43d1..a5cffe3dabd 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java
@@ -17,6 +17,8 @@
package org.apache.doris.nereids.trees.expressions.functions.executable;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.catalog.Type;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.ExecFunction;
import org.apache.doris.nereids.trees.expressions.Expression;
@@ -32,8 +34,10 @@ import org.apache.doris.nereids.trees.expressions.literal.SmallIntLiteral;
import org.apache.doris.nereids.trees.expressions.literal.StringLikeLiteral;
import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral;
import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
+import org.apache.doris.nereids.types.DataType;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.DateType;
+import org.apache.doris.nereids.types.DateV2Type;
import org.apache.doris.nereids.types.DecimalV3Type;
import org.apache.doris.nereids.types.VarcharType;
import org.apache.doris.nereids.util.DateUtils;
@@ -611,11 +615,23 @@ public class DateTimeExtractAndTransform {
@ExecFunction(name = "str_to_date", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "DATETIMEV2")
public static Expression strToDate(StringLikeLiteral str, StringLikeLiteral format) {
if (org.apache.doris.analysis.DateLiteral.hasTimePart(format.getStringValue())) {
- return DateTimeV2Literal.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue())
- .toFormatter(), str.getValue()));
+ DataType returnType = DataType.fromCatalogType(ScalarType.getDefaultDateType(Type.DATETIME));
+ if (returnType instanceof DateTimeV2Type) {
+ return DateTimeV2Literal.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue())
+ .toFormatter(), str.getValue()));
+ } else {
+ return DateTimeLiteral.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue())
+ .toFormatter(), str.getValue()));
+ }
} else {
- return DateV2Literal.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue())
- .toFormatter(), str.getValue()));
+ DataType returnType = DataType.fromCatalogType(ScalarType.getDefaultDateType(Type.DATE));
+ if (returnType instanceof DateV2Type) {
+ return DateV2Literal.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue())
+ .toFormatter(), str.getValue()));
+ } else {
+ return DateLiteral.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue())
+ .toFormatter(), str.getValue()));
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org