This is an automated email from the ASF dual-hosted git repository. starocean999 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 a1fa7f5fafd [fix](nereids)str_to_date function's signature for folding constant is wrong (#32474) a1fa7f5fafd is described below commit a1fa7f5fafd106871145a4d6c2387bef7e1b5ea1 Author: starocean999 <40539150+starocean...@users.noreply.github.com> AuthorDate: Fri Mar 22 10:19:44 2024 +0800 [fix](nereids)str_to_date function's signature for folding constant is wrong (#32474) --- .../src/main/java/org/apache/doris/mtmv/MTMVUtil.java | 15 +++++++++++---- .../functions/executable/DateTimeExtractAndTransform.java | 11 ++++++++--- .../partition_prune/test_date_function_prune.groovy | 5 +++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVUtil.java b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVUtil.java index 16459fa1303..01033a9615a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVUtil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVUtil.java @@ -33,6 +33,8 @@ import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeA import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeArithmetic; import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeExtractAndTransform; import org.apache.doris.nereids.trees.expressions.literal.DateTimeLiteral; +import org.apache.doris.nereids.trees.expressions.literal.DateTimeV2Literal; +import org.apache.doris.nereids.trees.expressions.literal.DateV2Literal; import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral; @@ -163,12 +165,17 @@ public class MTMVUtil { String dateFormat = dateFormatOptional.get(); Expression strToDate = DateTimeExtractAndTransform .strToDate(new VarcharLiteral(expr.getStringValue()), new VarcharLiteral(dateFormat)); - if (!(strToDate instanceof DateTimeLiteral)) { + if (strToDate instanceof DateTimeV2Literal) { + return ((IntegerLiteral) DateTimeExtractAndTransform + .unixTimestamp((DateTimeV2Literal) strToDate)).getValue(); + } else if (strToDate instanceof DateV2Literal) { + return ((IntegerLiteral) DateTimeExtractAndTransform + .unixTimestamp((DateV2Literal) strToDate)).getValue(); + } else { throw new AnalysisException( - String.format("strToDate failed, stringValue: %s, dateFormat: %s", expr.getStringValue(), - dateFormat)); + String.format("strToDate failed, stringValue: %s, dateFormat: %s", + expr.getStringValue(), dateFormat)); } - return ((IntegerLiteral) DateTimeExtractAndTransform.unixTimestamp((DateTimeLiteral) strToDate)).getValue(); } /** 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 fa1e1ee2a7d..2e53f454752 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 @@ -593,10 +593,15 @@ public class DateTimeExtractAndTransform { /** * date transformation function: str_to_date */ - @ExecFunction(name = "str_to_date", argTypes = {"VARCHAR, VARCHAR"}, returnType = "DATETIME") + @ExecFunction(name = "str_to_date", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "DATETIMEV2") public static Expression strToDate(VarcharLiteral str, VarcharLiteral format) { - return DateTimeLiteral.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue()) - .toFormatter(), str.getValue())); + if (org.apache.doris.analysis.DateLiteral.hasTimePart(format.getStringValue())) { + return DateTimeV2Literal.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue()) + .toFormatter(), str.getValue())); + } else { + return DateV2Literal.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue()) + .toFormatter(), str.getValue())); + } } @ExecFunction(name = "timestamp", argTypes = {"DATETIME"}, returnType = "DATETIME") diff --git a/regression-test/suites/nereids_rules_p0/partition_prune/test_date_function_prune.groovy b/regression-test/suites/nereids_rules_p0/partition_prune/test_date_function_prune.groovy index 6f570672316..c126206eba0 100644 --- a/regression-test/suites/nereids_rules_p0/partition_prune/test_date_function_prune.groovy +++ b/regression-test/suites/nereids_rules_p0/partition_prune/test_date_function_prune.groovy @@ -86,4 +86,9 @@ suite("test_date_function_prune") { sql "select * from dp where date(date_time) = null or date(date_time) = '2020-01-01'" contains("partitions=1/3 (p1)") } + + explain { + sql "select * from dp where date_time > str_to_date('2020-01-02','%Y-%m-%d')" + contains("partitions=2/3 (p2,p3)") + } } \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org