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

yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git

commit e66dcd0e72cb073c6faafaddf3a6f6812a9d6f97
Author: Pxl <[email protected]>
AuthorDate: Mon Apr 29 14:27:56 2024 +0800

    [Bug](materialized-view) change nvl to ifnull when create mv (#34272)
    
    change nvl to ifnull when create mv
---
 .../org/apache/doris/rewrite/FunctionAlias.java    |  2 +-
 regression-test/data/mv_p0/test_nvl/test_nvl.out   | 17 +++++
 .../suites/mv_p0/test_nvl/test_nvl.groovy          | 75 ++++++++++++++++++++++
 3 files changed, 93 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FunctionAlias.java 
b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FunctionAlias.java
index 29cf2988cfd..878319ac563 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FunctionAlias.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FunctionAlias.java
@@ -40,7 +40,7 @@ public final class FunctionAlias implements ExprRewriteRule {
             .put("date_sub", "days_sub").put("subdate", 
"days_sub").put("inet_ntoa", "ipv4_num_to_string")
             .put("inet_aton", "ipv4_string_to_num_or_null").put("inet6_ntoa", 
"ipv6_num_to_string")
             .put("inet6_aton", "ipv6_string_to_num_or_null").put("lcase", 
"lower").put("add_months", "months_add")
-            .put("current_timestamp", "now").put("localtime", 
"now").put("localtimestamp", "now").put("ifnull", "nvl")
+            .put("current_timestamp", "now").put("localtime", 
"now").put("localtimestamp", "now").put("nvl", "ifnull")
             .put("rand", "random").put("sha", "sha1").put("substr", 
"substring").put("ucase", "upper")
             .put("approx_count_distinct", "ndv").build();
 
diff --git a/regression-test/data/mv_p0/test_nvl/test_nvl.out 
b/regression-test/data/mv_p0/test_nvl/test_nvl.out
new file mode 100644
index 00000000000..77b859604c7
--- /dev/null
+++ b/regression-test/data/mv_p0/test_nvl/test_nvl.out
@@ -0,0 +1,17 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !select_mv --
+1
+2
+
+-- !select_mv --
+1
+2
+
+-- !select_mv --
+1
+2
+
+-- !select_mv --
+1
+2
+
diff --git a/regression-test/suites/mv_p0/test_nvl/test_nvl.groovy 
b/regression-test/suites/mv_p0/test_nvl/test_nvl.groovy
new file mode 100644
index 00000000000..e7c0d32f826
--- /dev/null
+++ b/regression-test/suites/mv_p0/test_nvl/test_nvl.groovy
@@ -0,0 +1,75 @@
+// 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.
+
+import org.codehaus.groovy.runtime.IOGroovyMethods
+
+suite ("test_nvl") {
+    sql """ drop table if exists dwd;"""
+
+    sql """
+        CREATE TABLE `dwd` (
+            `id` bigint(20) NULL COMMENT 'id',
+            `created_at` datetime NULL,
+            `dt` date NULL
+            ) ENGINE=OLAP
+            DUPLICATE KEY(`id`)
+            DISTRIBUTED BY HASH(`id`) BUCKETS 10
+            PROPERTIES (
+            "replication_allocation" = "tag.location.default: 1"
+        );
+        """
+
+    sql """insert into dwd(id) values(1);"""
+
+    createMV ("""
+            create materialized view dwd_mv as  select nvl(id,0) from dwd;
+    """)
+
+    sql """insert into dwd(id) values(2);"""
+
+    explain {
+        sql("select nvl(id,0) from dwd order by 1;")
+        contains "(dwd_mv)"
+    }
+    qt_select_mv "select nvl(id,0) from dwd order by 1;"
+
+    explain {
+        sql("select ifnull(id,0) from dwd order by 1;")
+        contains "(dwd_mv)"
+    }
+    qt_select_mv "select ifnull(id,0) from dwd order by 1;"
+
+    sql """ drop materialized view dwd_mv on dwd;
+    """
+
+    createMV ("""
+            create materialized view dwd_mv as  select ifnull(id,0) from dwd;
+    """)
+
+    explain {
+        sql("select nvl(id,0) from dwd order by 1;")
+        contains "(dwd_mv)"
+    }
+    qt_select_mv "select nvl(id,0) from dwd order by 1;"
+
+    explain {
+        sql("select ifnull(id,0) from dwd order by 1;")
+        contains "(dwd_mv)"
+    }
+    qt_select_mv "select ifnull(id,0) from dwd order by 1;"
+
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to