This is an automated email from the ASF dual-hosted git repository.

morrysnow 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 6356146274 [Fix](Nereids) fix nereids fold failed by be return null 
exception (#19013)
6356146274 is described below

commit 6356146274fc6a05b9e1a216e650248027b550f0
Author: mch_ucchi <41606806+sohardforan...@users.noreply.github.com>
AuthorDate: Wed Apr 26 14:57:45 2023 +0800

    [Fix](Nereids) fix nereids fold failed by be return null exception (#19013)
    
    ```sql
    select if(
        date_format(CONCAT_WS('', '9999-07', '-26'), '%Y-%m') = 
DATE_FORMAT(curdate(), '%Y-%m'),
        curdate(),
        DATE_FORMAT(DATE_SUB(month_ceil(CONCAT_WS('', '9999-07', '-26')), 1), 
'%Y-%m-%d')
    )
    ```
    return null when construct new children of if(), we find that the the more 
than "0" index in result map doesn't replace the const map caused by incorrect 
value-assignment in code.
---
 .../expression/rules/FoldConstantRuleOnBE.java     |  4 +--
 .../fold_constant/fold_constant_by_be.groovy       | 34 ++++++++++++++++++++++
 .../fold_constant/fold_constant_by_fe.groovy       | 23 +++++++++++++++
 .../suites/nereids_p0/fold_constant/load.groovy    | 22 ++++++++++++++
 4 files changed, 81 insertions(+), 2 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java
index 1e14685128..7994344ff8 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java
@@ -192,9 +192,9 @@ public class FoldConstantRuleOnBE extends 
AbstractExpressionRewriteRule {
                             DataType t1 = 
DataType.convertFromString(staleExpr.getType().getPrimitiveType().toString());
                             ret = 
Literal.of(staleExpr.getStringValue()).castTo(t1);
                         } else {
-                            ret = constMap.get(e.getKey());
+                            ret = constMap.get(e1.getKey());
                         }
-                        resultMap.put(e.getKey(), ret);
+                        resultMap.put(e1.getKey(), ret);
                     }
                 }
 
diff --git 
a/regression-test/suites/nereids_p0/fold_constant/fold_constant_by_be.groovy 
b/regression-test/suites/nereids_p0/fold_constant/fold_constant_by_be.groovy
new file mode 100644
index 0000000000..483f2366a4
--- /dev/null
+++ b/regression-test/suites/nereids_p0/fold_constant/fold_constant_by_be.groovy
@@ -0,0 +1,34 @@
+// 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_by_be") {
+    sql 'use nereids_fold_constant_test'
+
+    sql 'set enable_nereids_planner=true'
+    sql 'set enable_fallback_to_original_planner=false'
+    sql 'set enable_fold_constant_by_be=true'
+
+    test {
+        sql '''
+            select if(
+                date_format(CONCAT_WS('', '9999-07', '-26'), '%Y-%m') = 
DATE_FORMAT(curdate(), '%Y-%m'),
+                curdate(),
+                DATE_FORMAT(DATE_SUB(month_ceil(CONCAT_WS('', '9999-07', 
'-26')), 1), '%Y-%m-%d'))
+        '''
+        result([['9999-07-31']])
+    }
+}
\ No newline at end of file
diff --git 
a/regression-test/suites/nereids_p0/fold_constant/fold_constant_by_fe.groovy 
b/regression-test/suites/nereids_p0/fold_constant/fold_constant_by_fe.groovy
new file mode 100644
index 0000000000..7e746a26f5
--- /dev/null
+++ b/regression-test/suites/nereids_p0/fold_constant/fold_constant_by_fe.groovy
@@ -0,0 +1,23 @@
+// 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_by_fe") {
+    sql 'use nereids_fold_constant_test'
+
+    sql 'set enable_nereids_planner=true'
+    sql 'set enable_fallback_to_original_planner=false'
+}
\ No newline at end of file
diff --git a/regression-test/suites/nereids_p0/fold_constant/load.groovy 
b/regression-test/suites/nereids_p0/fold_constant/load.groovy
new file mode 100644
index 0000000000..493122afe8
--- /dev/null
+++ b/regression-test/suites/nereids_p0/fold_constant/load.groovy
@@ -0,0 +1,22 @@
+// 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("load") {
+    sql 'create database if not exists nereids_fold_constant_test'
+
+    sql 'use nereids_fold_constant_test'
+}
\ 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

Reply via email to