This is an automated email from the ASF dual-hosted git repository. dataroaring pushed a commit to branch branch-3.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push: new aa4007e865d [fix](Nereids) fix fold constant of time acquired functions (#47288) (#48212) aa4007e865d is described below commit aa4007e865d90d4814fd7fc43f59759bb52b417c Author: LiBinfeng <libinf...@selectdb.com> AuthorDate: Mon Feb 24 11:39:29 2025 +0800 [fix](Nereids) fix fold constant of time acquired functions (#47288) (#48212) pick: #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 | 14 +++++----- .../nereids_p0/datatype/test_date_acquire.groovy | 3 -- .../fold_constant_date_arithmatic.groovy | 32 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 10 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 445a5f247ed..62bca860765 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 @@ -2055,37 +2055,37 @@ 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 public Expression visitSessionUser(DorisParser.SessionUserContext ctx) { - return new SessionUser().alias("SESSION_USER"); + return new SessionUser(); } @Override diff --git a/regression-test/suites/nereids_p0/datatype/test_date_acquire.groovy b/regression-test/suites/nereids_p0/datatype/test_date_acquire.groovy index a3545f74022..4a4579d579d 100644 --- a/regression-test/suites/nereids_p0/datatype/test_date_acquire.groovy +++ b/regression-test/suites/nereids_p0/datatype/test_date_acquire.groovy @@ -24,9 +24,6 @@ suite("test_date_acquire") { res1 = res1.split('VUNION')[1] assertFalse(res1.contains("()") || res1.contains("(3)")) - String res2 = sql 'explain select CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, LOCALTIME, LOCALTIMESTAMP, CURRENT_USER' - assertTrue(res2.contains("CURRENT_DATE") || res2.contains("CURRENT_TIME") || res2.contains("CURRENT_TIMESTAMP") || res2.contains("LOCALTIME") || res2.contains("LOCALTIMESTAMP") || res2.contains("CURRENT_USER")) - sql "set enable_fold_constant_by_be=true" sql "set time_zone='+08:00'" 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: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org