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 dc9de4b6b560260cca1190355b9f11b1683e40b4
Author: Pxl <pxl...@qq.com>
AuthorDate: Wed Mar 6 20:39:40 2024 +0800

    [Bug](load) fix wrong data in mv when routine load with function mapping 
(#31787)
---
 .../src/main/java/org/apache/doris/load/Load.java  | 10 ++---
 .../routine_load_mapping/routine_load_mapping.out  |  9 ++++
 .../data/mv_p0/routine_load_mapping/test           |  1 +
 .../routine_load_mapping.groovy                    | 52 ++++++++++++++++++++++
 4 files changed, 67 insertions(+), 5 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/load/Load.java 
b/fe/fe-core/src/main/java/org/apache/doris/load/Load.java
index aaace9b37df..cbd3c21a30c 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/load/Load.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/load/Load.java
@@ -568,14 +568,14 @@ public class Load {
             List<SlotRef> slots = Lists.newArrayList();
             entry.getValue().collect(SlotRef.class, slots);
             for (SlotRef slot : slots) {
-                if (slotDescByName.get(slot.getColumnName()) != null) {
-                    smap.getLhs().add(slot);
-                    smap.getRhs().add(
-                            getExprFromDesc(analyzer, 
getSlotFromDesc(slotDescByName.get(slot.getColumnName())), slot));
-                } else if (exprsByName.get(slot.getColumnName()) != null) {
+                if (exprsByName.get(slot.getColumnName()) != null) {
                     smap.getLhs().add(slot);
                     smap.getRhs().add(new 
CastExpr(tbl.getColumn(slot.getColumnName()).getType(),
                             exprsByName.get(slot.getColumnName())));
+                } else if (slotDescByName.get(slot.getColumnName()) != null) {
+                    smap.getLhs().add(slot);
+                    smap.getRhs().add(
+                            getExprFromDesc(analyzer, 
getSlotFromDesc(slotDescByName.get(slot.getColumnName())), slot));
                 } else {
                     if (entry.getKey().equalsIgnoreCase(Column.DELETE_SIGN)) {
                         throw new UserException("unknown reference column in 
DELETE ON clause:" + slot.getColumnName());
diff --git 
a/regression-test/data/mv_p0/routine_load_mapping/routine_load_mapping.out 
b/regression-test/data/mv_p0/routine_load_mapping/routine_load_mapping.out
new file mode 100644
index 00000000000..b70955720b3
--- /dev/null
+++ b/regression-test/data/mv_p0/routine_load_mapping/routine_load_mapping.out
@@ -0,0 +1,9 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !select --
+'ad_sdk_request'       2007-12-01T00:30:19     'b'
+ad_sdk_request 2024-03-04T00:00        a
+
+-- !select_mv --
+2007-12-01T00:30:19    1
+2024-03-04T00:00       1
+
diff --git a/regression-test/data/mv_p0/routine_load_mapping/test 
b/regression-test/data/mv_p0/routine_load_mapping/test
new file mode 100644
index 00000000000..98b8c2bab05
--- /dev/null
+++ b/regression-test/data/mv_p0/routine_load_mapping/test
@@ -0,0 +1 @@
+'ad_sdk_request',1196440219,'b'
\ No newline at end of file
diff --git 
a/regression-test/suites/mv_p0/routine_load_mapping/routine_load_mapping.groovy 
b/regression-test/suites/mv_p0/routine_load_mapping/routine_load_mapping.groovy
new file mode 100644
index 00000000000..1188e3031c0
--- /dev/null
+++ 
b/regression-test/suites/mv_p0/routine_load_mapping/routine_load_mapping.groovy
@@ -0,0 +1,52 @@
+// 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 ("routine_load_mapping") {
+
+    sql """ DROP TABLE IF EXISTS test; """
+
+    sql """
+        CREATE TABLE `test` (
+            `event_id` varchar(50) NULL COMMENT '',
+            `time_stamp` datetime NULL COMMENT '',
+            `device_id` varchar(150) NULL DEFAULT "" COMMENT ''
+            ) ENGINE=OLAP
+            DUPLICATE KEY(`event_id`)
+            DISTRIBUTED BY HASH(`device_id`) BUCKETS AUTO
+            PROPERTIES (
+            "replication_allocation" = "tag.location.default: 1"
+        ); 
+        """
+
+    sql """insert into test(event_id,time_stamp,device_id) 
values('ad_sdk_request','2024-03-04 00:00:00','a');"""
+
+    createMV("""create materialized view m_view as select time_stamp, 
count(device_id) from test group by time_stamp;""")
+
+    streamLoad {
+        table "test"
+        set 'column_separator', ','
+        set 'columns', 
'event_id,time_stamp,device_id,time_stamp=from_unixtime(`time_stamp`)'
+
+        file './test'
+        time 10000 // limit inflight 10s
+    }
+
+    qt_select "select * from test order by 1,2,3;"
+    qt_select_mv "select * from test index m_view order by 1,2;"
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to