From 19adb32c0cced4d271519a4fe5b88e222c02f868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E6=9E=B8?= Date: Mon, 23 Dec 2024 17:50:43 +0800 Subject: [PATCH] Fix sr/doris partition parentheses issue. --- .../visitor/StarRocksOutputVisitor.java | 20 +++++++++++++ .../sql/visitor/SQLASTOutputVisitor.java | 19 ++---------- .../MySqlCreateTableTest129_ads.java | 18 +++++------ .../createTable/MySqlCreateTableTest43.java | 6 ++-- .../createTable/MySqlCreateTableTest44.java | 6 ++-- .../createTable/MySqlCreateTableTest45.java | 6 ++-- .../createTable/OracleCreateTableTest38.java | 8 ++--- .../createTable/OracleCreateTableTest50.java | 30 +++++++++---------- .../createTable/OracleCreateTableTest69.java | 4 +-- .../src/test/resources/bvt/parser/doris/1.txt | 10 +++---- .../test/resources/bvt/parser/oceanbase/0.txt | 8 ++--- 11 files changed, 70 insertions(+), 65 deletions(-) diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/starrocks/visitor/StarRocksOutputVisitor.java b/core/src/main/java/com/alibaba/druid/sql/dialect/starrocks/visitor/StarRocksOutputVisitor.java index 87207a9e10..d60f07544f 100644 --- a/core/src/main/java/com/alibaba/druid/sql/dialect/starrocks/visitor/StarRocksOutputVisitor.java +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/starrocks/visitor/StarRocksOutputVisitor.java @@ -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; @@ -307,4 +308,23 @@ public boolean visit(StarRocksIndexDefinition x) { } return false; } + + @Override + protected void printSQLPartitions(List 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(')'); + } } diff --git a/core/src/main/java/com/alibaba/druid/sql/visitor/SQLASTOutputVisitor.java b/core/src/main/java/com/alibaba/druid/sql/visitor/SQLASTOutputVisitor.java index dfeb96867c..3e09e2b881 100644 --- a/core/src/main/java/com/alibaba/druid/sql/visitor/SQLASTOutputVisitor.java +++ b/core/src/main/java/com/alibaba/druid/sql/visitor/SQLASTOutputVisitor.java @@ -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; } @@ -8220,7 +8205,7 @@ protected void printSQLPartitions(List partitions) { println(); partitions.get(i).accept(this); if (i != partitionsSize - 1) { - print0(", "); + print0(","); } } this.indentCount--; diff --git a/core/src/test/java/com/alibaba/druid/bvt/sql/mysql/createTable/MySqlCreateTableTest129_ads.java b/core/src/test/java/com/alibaba/druid/bvt/sql/mysql/createTable/MySqlCreateTableTest129_ads.java index cdee05dd91..c52b0dff19 100644 --- a/core/src/test/java/com/alibaba/druid/bvt/sql/mysql/createTable/MySqlCreateTableTest129_ads.java +++ b/core/src/test/java/com/alibaba/druid/bvt/sql/mysql/createTable/MySqlCreateTableTest129_ads.java @@ -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()); @@ -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()); @@ -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()); diff --git a/core/src/test/java/com/alibaba/druid/bvt/sql/mysql/createTable/MySqlCreateTableTest43.java b/core/src/test/java/com/alibaba/druid/bvt/sql/mysql/createTable/MySqlCreateTableTest43.java index 9a89894fe7..cffa3cae8a 100644 --- a/core/src/test/java/com/alibaba/druid/bvt/sql/mysql/createTable/MySqlCreateTableTest43.java +++ b/core/src/test/java/com/alibaba/druid/bvt/sql/mysql/createTable/MySqlCreateTableTest43.java @@ -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); diff --git a/core/src/test/java/com/alibaba/druid/bvt/sql/mysql/createTable/MySqlCreateTableTest44.java b/core/src/test/java/com/alibaba/druid/bvt/sql/mysql/createTable/MySqlCreateTableTest44.java index f228735962..bca3e8ff74 100644 --- a/core/src/test/java/com/alibaba/druid/bvt/sql/mysql/createTable/MySqlCreateTableTest44.java +++ b/core/src/test/java/com/alibaba/druid/bvt/sql/mysql/createTable/MySqlCreateTableTest44.java @@ -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); diff --git a/core/src/test/java/com/alibaba/druid/bvt/sql/mysql/createTable/MySqlCreateTableTest45.java b/core/src/test/java/com/alibaba/druid/bvt/sql/mysql/createTable/MySqlCreateTableTest45.java index 14754f2c6c..08c47039d4 100644 --- a/core/src/test/java/com/alibaba/druid/bvt/sql/mysql/createTable/MySqlCreateTableTest45.java +++ b/core/src/test/java/com/alibaba/druid/bvt/sql/mysql/createTable/MySqlCreateTableTest45.java @@ -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" + diff --git a/core/src/test/java/com/alibaba/druid/bvt/sql/oracle/createTable/OracleCreateTableTest38.java b/core/src/test/java/com/alibaba/druid/bvt/sql/oracle/createTable/OracleCreateTableTest38.java index 837812a9d4..94b7895ad9 100644 --- a/core/src/test/java/com/alibaba/druid/bvt/sql/oracle/createTable/OracleCreateTableTest38.java +++ b/core/src/test/java/com/alibaba/druid/bvt/sql/oracle/createTable/OracleCreateTableTest38.java @@ -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)); diff --git a/core/src/test/java/com/alibaba/druid/bvt/sql/oracle/createTable/OracleCreateTableTest50.java b/core/src/test/java/com/alibaba/druid/bvt/sql/oracle/createTable/OracleCreateTableTest50.java index 14595d6d95..ef4677e5f7 100644 --- a/core/src/test/java/com/alibaba/druid/bvt/sql/oracle/createTable/OracleCreateTableTest50.java +++ b/core/src/test/java/com/alibaba/druid/bvt/sql/oracle/createTable/OracleCreateTableTest50.java @@ -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" + ")",// diff --git a/core/src/test/java/com/alibaba/druid/bvt/sql/oracle/createTable/OracleCreateTableTest69.java b/core/src/test/java/com/alibaba/druid/bvt/sql/oracle/createTable/OracleCreateTableTest69.java index f9bdab3d60..80f9578a83 100644 --- a/core/src/test/java/com/alibaba/druid/bvt/sql/oracle/createTable/OracleCreateTableTest69.java +++ b/core/src/test/java/com/alibaba/druid/bvt/sql/oracle/createTable/OracleCreateTableTest69.java @@ -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" + ")",// diff --git a/core/src/test/resources/bvt/parser/doris/1.txt b/core/src/test/resources/bvt/parser/doris/1.txt index c9c16afe85..1dc90ba7a5 100644 --- a/core/src/test/resources/bvt/parser/doris/1.txt +++ b/core/src/test/resources/bvt/parser/doris/1.txt @@ -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 @@ -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", diff --git a/core/src/test/resources/bvt/parser/oceanbase/0.txt b/core/src/test/resources/bvt/parser/oceanbase/0.txt index cb54e3523c..2559b9785e 100644 --- a/core/src/test/resources/bvt/parser/oceanbase/0.txt +++ b/core/src/test/resources/bvt/parser/oceanbase/0.txt @@ -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) ); ------------------------------------------------------------------------------------------------------------------------ @@ -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) ); \ No newline at end of file