This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-1.2-lts in repository https://gitbox.apache.org/repos/asf/doris.git
commit eeaa0d270218b90a468ce282e515bcfaae6cf349 Author: LiBinfeng <46676950+libinfeng...@users.noreply.github.com> AuthorDate: Wed Aug 2 20:04:59 2023 +0800 [Fix](Planner) fix create view tosql not include partition (#22482) Problem: When create view with join in table partitions, an error would rise like "Unknown column" Example: CREATE VIEW my_view AS SELECT t1.* FROM t1 PARTITION(p1) JOIN t2 PARTITION(p2) ON t1.k1 = t2.k1; select * from my_view ==> errCode = 2, detailMessage = Unknown column 'k1' in 't2' Reason: When create view, we do tosql first in order to persistent view sql. And when doing tosql of table reference, partition key word was removed to keep neat of sql string. But here when we remove partition keyword it would regarded as an alias. So "PARTITION" keyword can not be removed. Solved: Add “PARTITION” keyword back to tosql string. --- .../java/org/apache/doris/analysis/TableRef.java | 14 ++++---- .../suites/ddl_p0/test_create_view.groovy | 42 ++++++++++++++++++++++ 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/TableRef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/TableRef.java index 7e9deadd84..377a3bc9ed 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/TableRef.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/TableRef.java @@ -247,13 +247,6 @@ public class TableRef implements ParseNode, Writable { output.append("[").append(Joiner.on(", ").join(joinHints)).append("] "); } output.append(tableRefToSql()).append(" "); - if (partitionNames != null) { - StringJoiner sj = new StringJoiner(",", "", " "); - for (String partName : partitionNames.getPartitionNames()) { - sj.add(partName); - } - output.append(sj.toString()); - } if (usingColNames != null) { output.append("USING (").append(Joiner.on(", ").join(usingColNames)).append(")"); } else if (onClause != null) { @@ -754,6 +747,13 @@ public class TableRef implements ParseNode, Writable { tblName += " " + viewRef.toSql(); } } + if (partitionNames != null) { + StringJoiner sj = new StringJoiner(",", "", " "); + for (String partName : partitionNames.getPartitionNames()) { + sj.add(partName); + } + return tblName + " PARTITION(" + sj.toString() + ")"; + } return tblName; } diff --git a/regression-test/suites/ddl_p0/test_create_view.groovy b/regression-test/suites/ddl_p0/test_create_view.groovy index 4c401017ee..c209d42bd3 100644 --- a/regression-test/suites/ddl_p0/test_create_view.groovy +++ b/regression-test/suites/ddl_p0/test_create_view.groovy @@ -69,4 +69,46 @@ suite("test_create_view") { sql """select * from test_count_distinct""" sql """DROP VIEW IF EXISTS test_count_distinct""" sql """DROP TABLE IF EXISTS count_distinct""" + + sql """DROP TABLE IF EXISTS t1""" + sql """ + CREATE TABLE `t1` ( + k1 int, + k2 date, + v1 int + ) ENGINE=OLAP + UNIQUE KEY(`k1`,`k2`) + COMMENT '测试' + PARTITION BY RANGE(k2) ( + PARTITION p1 VALUES [('2023-07-01'), ('2023-07-10')), + PARTITION p2 VALUES [('2023-07-11'), ('2023-07-20')) + ) + DISTRIBUTED BY HASH(`k1`) BUCKETS 3 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + );""" + sql """DROP TABLE IF EXISTS t2""" + sql """ + CREATE TABLE `t2` ( + k1 int, + k2 date, + v1 int + ) ENGINE=OLAP + UNIQUE KEY(`k1`,`k2`) + COMMENT '测试' + PARTITION BY RANGE(k2) ( + PARTITION p1 VALUES [('2023-07-01'), ('2023-07-05')), + PARTITION p2 VALUES [('2023-07-05'), ('2023-07-15')) + ) + DISTRIBUTED BY HASH(`k1`) BUCKETS 3 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); """ + sql """ + CREATE VIEW IF NOT EXISTS my_view AS + SELECT t1.* FROM t1 PARTITION(p1) JOIN t2 PARTITION(p2) ON t1.k1 = t2.k1; """ + sql """SELECT * FROM my_view""" + sql """DROP VIEW IF EXISTS my_view""" + sql """DROP TABLE IF EXISTS t1""" + sql """DROP TABLE IF EXISTS t2""" } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org