This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 3a747996078 branch-2.1: [fix](Nereids) fix fold constant of time
acquired functions #47288 (#47920)
3a747996078 is described below
commit 3a747996078a4aa5c6958cbd4dcd15ee47208c4f
Author: LiBinfeng <[email protected]>
AuthorDate: Mon Feb 17 14:36:02 2025 +0800
branch-2.1: [fix](Nereids) fix fold constant of time acquired functions
#47288 (#47920)
pick from master #47288
Problem Summary:
explain select substr(current_date, 1, 10);
when logicalPlanBuilder build ast from original sql of date acquired
functions like current_date, it would add an alias above. Which would
stop folding constant when fold constant rule traversing expression tree
So remove alias when translate to ast
---
.../doris/nereids/parser/LogicalPlanBuilder.java | 12 ++++----
.../fold_constant_date_arithmatic.groovy | 32 ++++++++++++++++++++++
2 files changed, 38 insertions(+), 6 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index 0ae1a209f55..b1f32c324e2 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -2017,32 +2017,32 @@ public class LogicalPlanBuilder extends
DorisParserBaseVisitor<Object> {
@Override
public Expression visitCurrentDate(DorisParser.CurrentDateContext ctx) {
- return new CurrentDate().alias("CURRENT_DATE");
+ return new CurrentDate();
}
@Override
public Expression visitCurrentTime(DorisParser.CurrentTimeContext ctx) {
- return new CurrentTime().alias("CURRENT_TIME");
+ return new CurrentTime();
}
@Override
public Expression
visitCurrentTimestamp(DorisParser.CurrentTimestampContext ctx) {
- return new Now().alias("CURRENT_TIMESTAMP");
+ return new Now();
}
@Override
public Expression visitLocalTime(DorisParser.LocalTimeContext ctx) {
- return new CurrentTime().alias("LOCALTIME");
+ return new CurrentTime();
}
@Override
public Expression visitLocalTimestamp(DorisParser.LocalTimestampContext
ctx) {
- return new Now().alias("LOCALTIMESTAMP");
+ return new Now();
}
@Override
public Expression visitCurrentUser(DorisParser.CurrentUserContext ctx) {
- return new CurrentUser().alias("CURRENT_USER");
+ return new CurrentUser();
}
@Override
diff --git
a/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_date_arithmatic.groovy
b/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_date_arithmatic.groovy
new file mode 100644
index 00000000000..5e0ed2e5d25
--- /dev/null
+++
b/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_date_arithmatic.groovy
@@ -0,0 +1,32 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("fold_constant_date_arithmatic") {
+ def db = "fold_constant_date_arithmatic"
+ sql "create database if not exists ${db}"
+
+ sql "set enable_nereids_planner=true"
+ sql "set enable_fallback_to_original_planner=false"
+ sql "set enable_fold_constant_by_be=false"
+
+ testFoldConst("select substr(now(), 1, 10);")
+ testFoldConst("select substr(now(3), 1, 10);")
+ testFoldConst("select substr(curdate(), 1, 10);")
+ testFoldConst("select substr(current_date(), 1, 10);")
+ testFoldConst("select substr(current_timestamp(), 1, 10);")
+ testFoldConst("select substr(current_timestamp(3), 1, 10);")
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]