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 7b7845e6951 [fix](planner) choice wrong length of string type output 
of union (#28514)
7b7845e6951 is described below

commit 7b7845e69517a60bd6828523cb1083b5c600b68f
Author: morrySnow <101034200+morrys...@users.noreply.github.com>
AuthorDate: Tue Dec 19 10:43:39 2023 +0800

    [fix](planner) choice wrong length of string type output of union (#28514)
---
 .../apache/doris/analysis/SetOperationStmt.java    | 10 ++-
 regression-test/suites/ddl_p0/test_ctas.groovy     | 87 ++++++++++++++++++++++
 2 files changed, 96 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/SetOperationStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/SetOperationStmt.java
index ac2dafd2f8c..941f965a3a6 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SetOperationStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SetOperationStmt.java
@@ -23,6 +23,7 @@ import org.apache.doris.catalog.Type;
 import org.apache.doris.common.AnalysisException;
 import org.apache.doris.common.Pair;
 import org.apache.doris.common.UserException;
+import org.apache.doris.qe.SessionVariable;
 import org.apache.doris.rewrite.ExprRewriter;
 
 import com.google.common.base.Preconditions;
@@ -485,7 +486,7 @@ public class SetOperationStmt extends QueryStmt {
         List<Pair<Type, Boolean>> selectTypeWithNullable = 
operands.get(0).getQueryStmt().getResultExprs().stream()
                 .map(expr -> Pair.of(expr.getType(), 
expr.isNullable())).collect(Collectors.toList());
         for (int i = 1; i < operands.size(); i++) {
-            for (int j = 1; j < selectTypeWithNullable.size(); j++) {
+            for (int j = 0; j < selectTypeWithNullable.size(); j++) {
                 if (selectTypeWithNullable.get(j).first.isDecimalV2()
                         && 
operands.get(i).getQueryStmt().getResultExprs().get(j).getType().isDecimalV2()) 
{
                     selectTypeWithNullable.get(j).first = 
ScalarType.getAssignmentCompatibleDecimalV2Type(
@@ -498,6 +499,13 @@ public class SetOperationStmt extends QueryStmt {
                             (ScalarType) selectTypeWithNullable.get(j).first,
                             (ScalarType) 
operands.get(i).getQueryStmt().getResultExprs().get(j).getType());
                 }
+                if (selectTypeWithNullable.get(j).first.isStringType() && 
operands.get(i)
+                        
.getQueryStmt().getResultExprs().get(j).getType().isStringType()) {
+                    selectTypeWithNullable.get(j).first = 
ScalarType.getAssignmentCompatibleType(
+                            (ScalarType) selectTypeWithNullable.get(j).first,
+                            (ScalarType) 
operands.get(i).getQueryStmt().getResultExprs().get(j).getType(),
+                            false, SessionVariable.getEnableDecimal256());
+                }
             }
         }
 
diff --git a/regression-test/suites/ddl_p0/test_ctas.groovy 
b/regression-test/suites/ddl_p0/test_ctas.groovy
index d634dc91e0d..2aaf56ee593 100644
--- a/regression-test/suites/ddl_p0/test_ctas.groovy
+++ b/regression-test/suites/ddl_p0/test_ctas.groovy
@@ -290,5 +290,92 @@ suite("test_ctas") {
         sql 'drop table test_ctas_of_view'
         sql 'drop view ctas_view'
     }
+
+    try {
+        sql '''set enable_nereids_planner=false;'''
+        sql '''
+            CREATE TABLE IF NOT EXISTS `ctas1` (
+                `k1` varchar(5) NULL,
+                `k2` varchar(5) NULL
+            ) ENGINE=OLAP
+            DUPLICATE KEY(`k1`)
+            DISTRIBUTED BY HASH(`k1`) BUCKETS 10
+            PROPERTIES (
+                "replication_allocation" = "tag.location.default: 1"
+            );
+        '''
+        sql '''
+            CREATE TABLE IF NOT EXISTS `ctas2` (
+                `k1` varchar(10) NULL,
+                `k2` varchar(10) NULL
+            ) ENGINE=OLAP
+            DUPLICATE KEY(`k1`)
+            DISTRIBUTED BY HASH(`k1`) BUCKETS 10
+            PROPERTIES (
+                "replication_allocation" = "tag.location.default: 1"
+            );
+        '''
+        sql '''
+            insert into ctas1 values('11111','11111');
+        '''
+        sql '''
+            insert into ctas2 values('1111111111','1111111111');
+        '''
+        sql '''
+            create table `ctas3`(k1, k2) 
+            PROPERTIES("replication_num" = "1") 
+            as select * from ctas1
+                union all 
+                select * from ctas2;
+        '''
+    } finally {
+        sql '''DROP TABLE IF EXISTS ctas1'''
+        sql '''DROP TABLE IF EXISTS ctas2'''
+        sql '''DROP TABLE IF EXISTS ctas3'''
+    }
+
+    try {
+        sql '''set enable_nereids_planner=true;'''
+        sql '''set enable_fallback_to_original_planner=false;'''
+        sql '''
+            CREATE TABLE IF NOT EXISTS `ctas1` (
+                `k1` varchar(5) NULL,
+                `k2` varchar(5) NULL
+            ) ENGINE=OLAP
+            DUPLICATE KEY(`k1`)
+            DISTRIBUTED BY HASH(`k1`) BUCKETS 10
+            PROPERTIES (
+                "replication_allocation" = "tag.location.default: 1"
+            );
+        '''
+        sql '''
+            CREATE TABLE IF NOT EXISTS `ctas2` (
+                `k1` varchar(10) NULL,
+                `k2` varchar(10) NULL
+            ) ENGINE=OLAP
+            DUPLICATE KEY(`k1`)
+            DISTRIBUTED BY HASH(`k1`) BUCKETS 10
+            PROPERTIES (
+                "replication_allocation" = "tag.location.default: 1"
+            );
+        '''
+        sql '''
+            insert into ctas1 values('11111','11111');
+        '''
+        sql '''
+            insert into ctas2 values('1111111111','1111111111');
+        '''
+        sql '''
+            create table `ctas3`(k1, k2) 
+            PROPERTIES("replication_num" = "1") 
+            as select * from ctas1
+                union all 
+                select * from ctas2;
+        '''
+    } finally {
+        sql '''DROP TABLE IF EXISTS ctas1'''
+        sql '''DROP TABLE IF EXISTS ctas2'''
+        sql '''DROP TABLE IF EXISTS ctas3'''
+    }
 }
 


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

Reply via email to