This is an automated email from the ASF dual-hosted git repository.
kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new f33811411ec [fix](planner) varchar should be cast if length is not
same #28514 (#28515)
f33811411ec is described below
commit f33811411ec9d1e5b7226f9cc9af308bee5f005f
Author: morrySnow <[email protected]>
AuthorDate: Sun Dec 17 20:51:03 2023 +0800
[fix](planner) varchar should be cast if length is not same #28514 (#28515)
[fix](planner) choice wrong length of string type output of union
---
.../apache/doris/analysis/SetOperationStmt.java | 18 ++++++++-
regression-test/suites/ddl_p0/test_ctas.groovy | 43 ++++++++++++++++++++++
2 files changed, 60 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 984f2c58224..065865141cc 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
@@ -17,6 +17,7 @@
package org.apache.doris.analysis;
+import org.apache.doris.catalog.PrimitiveType;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.catalog.Type;
@@ -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,21 @@ 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())
{
+ if (selectTypeWithNullable.get(j).first.getPrimitiveType()
== PrimitiveType.STRING
+ ||
operands.get(i).getQueryStmt().getResultExprs().get(j).getType().getPrimitiveType()
+ == PrimitiveType.STRING) {
+ selectTypeWithNullable.get(j).first =
ScalarType.createStringType();
+ } else if (selectTypeWithNullable.get(j).first.getLength()
< 0
+ ||
operands.get(i).getQueryStmt().getResultExprs().get(j).getType().getLength() <
0) {
+ selectTypeWithNullable.get(j).first =
ScalarType.createVarcharType();
+ } else {
+ int length =
Math.max(selectTypeWithNullable.get(j).first.getLength(),
+
operands.get(i).getQueryStmt().getResultExprs().get(j).getType().getLength());
+ selectTypeWithNullable.get(j).first =
ScalarType.createVarchar(length);
+ }
+ }
}
}
diff --git a/regression-test/suites/ddl_p0/test_ctas.groovy
b/regression-test/suites/ddl_p0/test_ctas.groovy
index db9385a841a..d5a6a9b539f 100644
--- a/regression-test/suites/ddl_p0/test_ctas.groovy
+++ b/regression-test/suites/ddl_p0/test_ctas.groovy
@@ -252,5 +252,48 @@ suite("test_ctas") {
sql 'drop table c'
sql 'drop table test_date_v2'
}
+
+ 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'''
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]