Skip to content

Commit

Permalink
Fix sr/doris partition parentheses issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
lingo-xp authored and wenshao committed Dec 23, 2024
1 parent 14d444a commit 19adb32
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.alibaba.druid.sql.ast.DistributedByType;
import com.alibaba.druid.sql.ast.SQLDataType;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLPartition;
import com.alibaba.druid.sql.ast.expr.SQLArrayExpr;
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAlterColumn;
Expand Down Expand Up @@ -307,4 +308,23 @@ public boolean visit(StarRocksIndexDefinition x) {
}
return false;
}

@Override
protected void printSQLPartitions(List<SQLPartition> partitions) {
int partitionsSize = partitions.size();
print0(" (");
if (partitionsSize > 0) {
this.indentCount++;
for (int i = 0; i < partitionsSize; ++i) {
println();
partitions.get(i).accept(this);
if (i != partitionsSize - 1) {
print0(",");
}
}
this.indentCount--;
println();
}
print(')');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8130,22 +8130,7 @@ public boolean visit(SQLPartitionByRange x) {
}

printPartitionsCountAndSubPartitions(x);

if (x.getPartitions().size() > 0) {
print(" (");
this.indentCount++;
for (int i = 0, size = x.getPartitions().size(); i < size; ++i) {
if (i != 0) {
print(',');
}
println();
x.getPartitions().get(i).accept(this);
}
this.indentCount--;
println();
print(')');
}

printSQLPartitions(x.getPartitions());
return false;
}

Expand Down Expand Up @@ -8220,7 +8205,7 @@ protected void printSQLPartitions(List<SQLPartition> partitions) {
println();
partitions.get(i).accept(this);
if (i != partitionsSize - 1) {
print0(", ");
print0(",");
}
}
this.indentCount--;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ public void test_2() throws Exception {
")\n" +
"PARTITION BY HASH KEY(id)\n" +
"SUBPARTITION BY RANGE (\n" +
"\tPARTITION p0 VALUES LESS THAN (1991), \n" +
"\tPARTITION p1 VALUES LESS THAN (1996), \n" +
"\tPARTITION p2 VALUES LESS THAN (2001), \n" +
"\tPARTITION p0 VALUES LESS THAN (1991),\n" +
"\tPARTITION p1 VALUES LESS THAN (1996),\n" +
"\tPARTITION p2 VALUES LESS THAN (2001),\n" +
"\tPARTITION p3 VALUES LESS THAN MAXVALUE\n" +
")\n" +
"TABLEGROUP group0;", stmt.toString());
Expand Down Expand Up @@ -153,9 +153,9 @@ public void test_3() throws Exception {
")\n" +
"PARTITION BY HASH KEY(id)\n" +
"SUBPARTITION BY LIST (store_id) (\n" +
"\tPARTITION pNorth VALUES IN (3, 5, 6, 9, 17), \n" +
"\tPARTITION pEast VALUES IN (1, 2, 10, 11, 19, 20), \n" +
"\tPARTITION pWest VALUES IN (4, 12, 13, 14, 18), \n" +
"\tPARTITION pNorth VALUES IN (3, 5, 6, 9, 17),\n" +
"\tPARTITION pEast VALUES IN (1, 2, 10, 11, 19, 20),\n" +
"\tPARTITION pWest VALUES IN (4, 12, 13, 14, 18),\n" +
"\tPARTITION pCentral VALUES IN (7, 8, 15, 16)\n" +
")\n" +
"TABLEGROUP group0;", stmt.toString());
Expand Down Expand Up @@ -203,9 +203,9 @@ public void test_4() throws Exception {
")\n" +
"PARTITION BY HASH KEY(id)\n" +
"SUBPARTITION BY LIST (store_id) (\n" +
"\tPARTITION pNorth VALUES IN (3, 5, 6, 9, 17), \n" +
"\tPARTITION pEast VALUES IN (1, 2, 10, 11, 19, 20), \n" +
"\tPARTITION pWest VALUES IN (4, 12, 13, 14, 18), \n" +
"\tPARTITION pNorth VALUES IN (3, 5, 6, 9, 17),\n" +
"\tPARTITION pEast VALUES IN (1, 2, 10, 11, 19, 20),\n" +
"\tPARTITION pWest VALUES IN (4, 12, 13, 14, 18),\n" +
"\tPARTITION pCentral VALUES IN (7, 8, 15, 16)\n" +
")\n" +
"TABLEGROUP group0;", stmt.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public void test_0() throws Exception {
"\tname VARCHAR(35)\n" +
")\n" +
"PARTITION BY LIST (id) (\n" +
"\tPARTITION r0 VALUES IN (1, 5, 9, 13, 17, 21), \n" +
"\tPARTITION r1 VALUES IN (2, 6, 10, 14, 18, 22), \n" +
"\tPARTITION r2 VALUES IN (3, 7, 11, 15, 19, 23), \n" +
"\tPARTITION r0 VALUES IN (1, 5, 9, 13, 17, 21),\n" +
"\tPARTITION r1 VALUES IN (2, 6, 10, 14, 18, 22),\n" +
"\tPARTITION r2 VALUES IN (3, 7, 11, 15, 19, 23),\n" +
"\tPARTITION r3 VALUES IN (4, 8, 12, 16, 20, 24)\n" +
");", output);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public void test_0() throws Exception {
"\tb INT NULL\n" +
")\n" +
"PARTITION BY LIST COLUMNS (a, b) (\n" +
"\tPARTITION p0 VALUES IN ((0, 0), (NULL, NULL)), \n" +
"\tPARTITION p1 VALUES IN ((0, 1), (0, 2), (0, 3), (1, 1), (1, 2)), \n" +
"\tPARTITION p2 VALUES IN ((1, 0), (2, 0), (2, 1), (3, 0), (3, 1)), \n" +
"\tPARTITION p0 VALUES IN ((0, 0), (NULL, NULL)),\n" +
"\tPARTITION p1 VALUES IN ((0, 1), (0, 2), (0, 3), (1, 1), (1, 2)),\n" +
"\tPARTITION p2 VALUES IN ((1, 0), (2, 0), (2, 1), (3, 0), (3, 1)),\n" +
"\tPARTITION p3 VALUES IN ((1, 3), (2, 2), (2, 3), (3, 2), (3, 3))\n" +
");", output);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ public void test_0() throws Exception {
"PARTITION BY LIST (YEAR(adate)) (\n" +
"\tPARTITION p1999 VALUES IN (1995, 1999, 2003)\n" +
"\t\tDATA DIRECTORY '/var/appdata/95/data'\n" +
"\t\tINDEX DIRECTORY '/var/appdata/95/idx', \n" +
"\t\tINDEX DIRECTORY '/var/appdata/95/idx',\n" +
"\tPARTITION p2000 VALUES IN (1996, 2000, 2004)\n" +
"\t\tDATA DIRECTORY '/var/appdata/96/data'\n" +
"\t\tINDEX DIRECTORY '/var/appdata/96/idx', \n" +
"\t\tINDEX DIRECTORY '/var/appdata/96/idx',\n" +
"\tPARTITION p2001 VALUES IN (1997, 2001, 2005)\n" +
"\t\tDATA DIRECTORY '/var/appdata/97/data'\n" +
"\t\tINDEX DIRECTORY '/var/appdata/97/idx', \n" +
"\t\tINDEX DIRECTORY '/var/appdata/97/idx',\n" +
"\tPARTITION p2002 VALUES IN (1998, 2002, 2006)\n" +
"\t\tDATA DIRECTORY '/var/appdata/98/data'\n" +
"\t\tINDEX DIRECTORY '/var/appdata/98/idx'\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public void test_types() throws Exception {
"\tcust_email VARCHAR2(40)\n" +
")\n" +
"PARTITION BY LIST (nls_territory) (\n" +
"\tPARTITION asia VALUES ('CHINA', 'THAILAND'), \n" +
"\tPARTITION europe VALUES ('GERMANY', 'ITALY', 'SWITZERLAND'), \n" +
"\tPARTITION west VALUES ('AMERICA'), \n" +
"\tPARTITION east VALUES ('INDIA'), \n" +
"\tPARTITION asia VALUES ('CHINA', 'THAILAND'),\n" +
"\tPARTITION europe VALUES ('GERMANY', 'ITALY', 'SWITZERLAND'),\n" +
"\tPARTITION west VALUES ('AMERICA'),\n" +
"\tPARTITION east VALUES ('INDIA'),\n" +
"\tPARTITION rest VALUES (DEFAULT)\n" +
");",//
SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,35 +249,35 @@ public void test_types() throws Exception {
")\n" +
"PARTITION BY HASH (\"COMPANY_ID\") (\n" +
"\tPARTITION \"PRODUCT_HASH_P1\"\n" +
"\t\tTABLESPACE \"APPDATA1M\", \n" +
"\t\tTABLESPACE \"APPDATA1M\",\n" +
"\tPARTITION \"PRODUCT_HASH_P2\"\n" +
"\t\tTABLESPACE \"APPDATA1M\", \n" +
"\t\tTABLESPACE \"APPDATA1M\",\n" +
"\tPARTITION \"PRODUCT_HASH_P3\"\n" +
"\t\tTABLESPACE \"APPDATA1M\", \n" +
"\t\tTABLESPACE \"APPDATA1M\",\n" +
"\tPARTITION \"PRODUCT_HASH_P4\"\n" +
"\t\tTABLESPACE \"APPDATA1M\", \n" +
"\t\tTABLESPACE \"APPDATA1M\",\n" +
"\tPARTITION \"PRODUCT_HASH_P5\"\n" +
"\t\tTABLESPACE \"APPDATA1M\", \n" +
"\t\tTABLESPACE \"APPDATA1M\",\n" +
"\tPARTITION \"PRODUCT_HASH_P6\"\n" +
"\t\tTABLESPACE \"APPDATA1M\", \n" +
"\t\tTABLESPACE \"APPDATA1M\",\n" +
"\tPARTITION \"PRODUCT_HASH_P7\"\n" +
"\t\tTABLESPACE \"APPDATA1M\", \n" +
"\t\tTABLESPACE \"APPDATA1M\",\n" +
"\tPARTITION \"PRODUCT_HASH_P8\"\n" +
"\t\tTABLESPACE \"APPDATA1M\", \n" +
"\t\tTABLESPACE \"APPDATA1M\",\n" +
"\tPARTITION \"PRODUCT_HASH_P9\"\n" +
"\t\tTABLESPACE \"APPDATA1M\", \n" +
"\t\tTABLESPACE \"APPDATA1M\",\n" +
"\tPARTITION \"PRODUCT_HASH_P10\"\n" +
"\t\tTABLESPACE \"APPDATA1M\", \n" +
"\t\tTABLESPACE \"APPDATA1M\",\n" +
"\tPARTITION \"PRODUCT_HASH_P11\"\n" +
"\t\tTABLESPACE \"APPDATA1M\", \n" +
"\t\tTABLESPACE \"APPDATA1M\",\n" +
"\tPARTITION \"PRODUCT_HASH_P12\"\n" +
"\t\tTABLESPACE \"APPDATA1M\", \n" +
"\t\tTABLESPACE \"APPDATA1M\",\n" +
"\tPARTITION \"PRODUCT_HASH_P13\"\n" +
"\t\tTABLESPACE \"APPDATA1M\", \n" +
"\t\tTABLESPACE \"APPDATA1M\",\n" +
"\tPARTITION \"PRODUCT_HASH_P14\"\n" +
"\t\tTABLESPACE \"APPDATA1M\", \n" +
"\t\tTABLESPACE \"APPDATA1M\",\n" +
"\tPARTITION \"PRODUCT_HASH_P15\"\n" +
"\t\tTABLESPACE \"APPDATA1M\", \n" +
"\t\tTABLESPACE \"APPDATA1M\",\n" +
"\tPARTITION \"PRODUCT_HASH_P16\"\n" +
"\t\tTABLESPACE \"APPDATA1M\"\n" +
")",//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public void test_types() throws Exception {
")\n" +
"PARTITION BY HASH (COL) (\n" +
"\tPARTITION PART01\n" +
"\t\tTABLESPACE HASH_TS01, \n" +
"\t\tTABLESPACE HASH_TS01,\n" +
"\tPARTITION PART02\n" +
"\t\tTABLESPACE HASH_TS02, \n" +
"\t\tTABLESPACE HASH_TS02,\n" +
"\tPARTITION PART03\n" +
"\t\tTABLESPACE HASH_TS03\n" +
")",//
Expand Down
10 changes: 5 additions & 5 deletions core/src/test/resources/bvt/parser/doris/1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ CREATE TABLE `bbbbbb` (
UNIQUE KEY (`table_name`, `media_platform`, `account_id`)
COMMENT '广告域-globalad-account误差监控(账户数据是否采集)'
PARTITION BY LIST (`table_name`) (
PARTITION p_dwd_ad_country_reports VALUES IN ("onedata_dwd.dwd_tiktok_ad_country_reports"),
PARTITION p_dwd_ad_reports VALUES IN ("onedata_dwd.dwd_tiktok_ad_reports"),
PARTITION p_ods_ad_country_reports VALUES IN ("onedata_warehouse.ods_tiktok_country_reports_integrated_basic"),
PARTITION p_ods_ad_reports VALUES IN ("onedata_warehouse.ods_tiktok_reports_integrated_basic"),
PARTITION p_dwd_ad_country_reports VALUES IN ("onedata_dwd.dwd_tiktok_ad_country_reports"),
PARTITION p_dwd_ad_reports VALUES IN ("onedata_dwd.dwd_tiktok_ad_reports"),
PARTITION p_ods_ad_country_reports VALUES IN ("onedata_warehouse.ods_tiktok_country_reports_integrated_basic"),
PARTITION p_ods_ad_reports VALUES IN ("onedata_warehouse.ods_tiktok_reports_integrated_basic"),
PARTITION p_dws_ad_reports VALUES IN ("tec_cdm.dws_ad_ad_performance_1d")
)
DISTRIBUTED BY HASH (`table_name`, `media_platform`, `account_id`) BUCKETS 6
Expand Down Expand Up @@ -329,7 +329,7 @@ CREATE TABLE example_db.dynamic_partition (
v2 DATETIME DEFAULT "2014-02-04 15:36:00"
)
DUPLICATE KEY (k1, k2, k3)
PARTITION BY RANGE (k1)
PARTITION BY RANGE (k1) ()
DISTRIBUTED BY HASH (k2) BUCKETS 32
PROPERTIES (
"dynamic_partition.time_unit" = "DAY",
Expand Down
8 changes: 4 additions & 4 deletions core/src/test/resources/bvt/parser/oceanbase/0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ CREATE TABLE t2_m_lch (
)
PARTITION BY LIST COLUMNS (col1)
SUBPARTITION BY HASH (col2) SUBPARTITIONS 5 (
PARTITION p0 VALUES IN (100),
PARTITION p1 VALUES IN (200),
PARTITION p0 VALUES IN (100),
PARTITION p1 VALUES IN (200),
PARTITION p2 VALUES IN (300)
);
------------------------------------------------------------------------------------------------------------------------
Expand All @@ -32,7 +32,7 @@ CREATE TABLE t2_m_lh (
)
PARTITION BY LIST (col1)
SUBPARTITION BY HASH (col3) SUBPARTITIONS 3 (
PARTITION p0 VALUES IN (100),
PARTITION p1 VALUES IN (200),
PARTITION p0 VALUES IN (100),
PARTITION p1 VALUES IN (200),
PARTITION p2 VALUES IN (300)
);

0 comments on commit 19adb32

Please sign in to comment.