Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ public String generateDropPartitionDefinitionDDL(String schemaName, @NonNull Str
SqlBuilder sqlBuilder = sqlBuilder();
sqlBuilder.append("ALTER TABLE ");
if (StringUtils.isNotEmpty(schemaName)) {
sqlBuilder.append(schemaName).append(".");
sqlBuilder.identifier(schemaName).append(".");
}
sqlBuilder.append(tableName).append(" DROP PARTITION (");
sqlBuilder.identifier(tableName).append(" DROP PARTITION (");
Validate.isTrue(!CollectionUtils.isEmpty(definitions), "Partition elements can not be empty");

return sqlBuilder.append(definitions.stream().map(d -> sqlBuilder().identifier(d.getName()).toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ public String generateAddPartitionDefinitionDDL(String schemaName, @NonNull Stri
SqlBuilder sqlBuilder = sqlBuilder();
sqlBuilder.append("ALTER TABLE ");
if (StringUtils.isNotEmpty(schemaName)) {
sqlBuilder.append(schemaName).append(".");
sqlBuilder.identifier(schemaName).append(".");
}
sqlBuilder.append(tableName).append(" ADD PARTITION (").append("\n\t");
sqlBuilder.identifier(tableName).append(" ADD PARTITION (").append("\n\t");
Validate.isTrue(!CollectionUtils.isEmpty(definitions), "Partition elements can not be empty");
for (int i = 0; i < definitions.size(); i++) {
appendDefinition(option, definitions.get(i), sqlBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ public String generateAddPartitionDefinitionDDL(String schemaName, @NonNull Stri
SqlBuilder sqlBuilder = sqlBuilder();
sqlBuilder.append("ALTER TABLE ");
if (StringUtils.isNotEmpty(schemaName)) {
sqlBuilder.append(schemaName).append(".");
sqlBuilder.identifier(schemaName).append(".");
}
sqlBuilder.append(tableName).append(" ADD ").append("\n\t");
sqlBuilder.identifier(tableName).append(" ADD ").append("\n\t");
Validate.isTrue(!CollectionUtils.isEmpty(definitions), "Partition elements can not be empty");
for (int i = 0; i < definitions.size(); i++) {
appendDefinition(option, definitions.get(i), sqlBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
]
}
},
"output": "ALTER TABLE schema.table ADD PARTITION (\n\tPARTITION `p1` VALUES LESS THAN (1000),\n\tPARTITION `p2` VALUES LESS THAN (2000));\n"
"output": "ALTER TABLE `schema`.`table` ADD PARTITION (\n\tPARTITION `p1` VALUES LESS THAN (1000),\n\tPARTITION `p2` VALUES LESS THAN (2000));\n"
},
{
"id": 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
]
}
},
"output": "ALTER TABLE schema.table DROP PARTITION (\"p1\", \"p2\");\n"
"output": "ALTER TABLE \"schema\".\"table\" DROP PARTITION (\"p1\", \"p2\");\n"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
]
}
},
"output": "ALTER TABLE schema.table ADD \n\tPARTITION \"p1\" VALUES LESS THAN (1000),\n\tPARTITION \"p2\" VALUES LESS THAN (2000);\n"
"output": "ALTER TABLE \"schema\".\"table\" ADD \n\tPARTITION \"p1\" VALUES LESS THAN (1000),\n\tPARTITION \"p2\" VALUES LESS THAN (2000);\n"
},
{
"id": 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void generatePartitionDdl_mysqlOnlyCreate_generateSucceed() throws Except
connection, DialectType.OB_MYSQL, configuration.getDefaultDBName(), tableConfig);
Map<PartitionPlanStrategy, List<String>> expect = new HashMap<>();
expect.put(PartitionPlanStrategy.CREATE, Collections.singletonList(String.format(
"ALTER TABLE %s.%s ADD PARTITION (\n"
"ALTER TABLE `%s`.`%s` ADD PARTITION (\n"
+ "\tPARTITION `p20240125` VALUES LESS THAN (20220801,'2024-01-26'),\n"
+ "\tPARTITION `p20240125` VALUES LESS THAN (20220802,'2024-01-27'),\n"
+ "\tPARTITION `p20240125` VALUES LESS THAN (20220803,'2024-01-28'),\n"
Expand All @@ -221,7 +221,7 @@ public void generatePartitionDdl_mysqlOnlyDrop_generateSucceed() throws Exceptio
connection, DialectType.OB_MYSQL, configuration.getDefaultDBName(), tableConfig);
Map<PartitionPlanStrategy, List<String>> expect = new HashMap<>();
expect.put(PartitionPlanStrategy.DROP, Collections.singletonList(String.format(
"ALTER TABLE %s.%s DROP PARTITION (`p20220830`, `p20220829`);\n",
"ALTER TABLE `%s`.`%s` DROP PARTITION (`p20220830`, `p20220829`);\n",
configuration.getDefaultDBName(), MYSQL_REAL_RANGE_TABLE_NAME)));
Assert.assertEquals(expect, actual);
}
Expand Down Expand Up @@ -250,10 +250,10 @@ public void generatePartitionDdl_mysqlBothCreateAndDrop_generateSucceed() throws
connection, DialectType.OB_MYSQL, configuration.getDefaultDBName(), tableConfig);
Map<PartitionPlanStrategy, List<String>> expect = new HashMap<>();
expect.put(PartitionPlanStrategy.DROP, Collections.singletonList(String.format(
"ALTER TABLE %s.%s DROP PARTITION (`p20220830`, `p20220829`);\n",
"ALTER TABLE `%s`.`%s` DROP PARTITION (`p20220830`, `p20220829`);\n",
configuration.getDefaultDBName(), MYSQL_REAL_RANGE_TABLE_NAME)));
expect.put(PartitionPlanStrategy.CREATE, Collections.singletonList(String.format(
"ALTER TABLE %s.%s ADD PARTITION (\n"
"ALTER TABLE `%s`.`%s` ADD PARTITION (\n"
+ "\tPARTITION `p20240126` VALUES LESS THAN (20220801,'2024-01-26'),\n"
+ "\tPARTITION `p20240127` VALUES LESS THAN (20220802,'2024-01-27'),\n"
+ "\tPARTITION `p20240128` VALUES LESS THAN (20220803,'2024-01-28'),\n"
Expand Down Expand Up @@ -287,17 +287,18 @@ public void generatePartitionDdl_oracleBothCreateAndDropWithOverlap_generateSucc
connection, DialectType.OB_ORACLE, configuration.getDefaultDBName(), tableConfig);
Map<PartitionPlanStrategy, List<String>> expect = new HashMap<>();
expect.put(PartitionPlanStrategy.DROP, Collections.singletonList(String.format(
"ALTER TABLE %s.%s DROP PARTITION (\"P1\", \"P0\") UPDATE GLOBAL INDEXES;",
"ALTER TABLE \"%s\".\"%s\" DROP PARTITION (\"P1\", \"P0\") UPDATE GLOBAL INDEXES;",
configuration.getDefaultDBName(), ORACLE_RANGE_TABLE_NAME)));
expect.put(PartitionPlanStrategy.CREATE, Collections.singletonList(String.format("ALTER TABLE %s.%s ADD \n"
+ "\tPARTITION \"P20240225\" VALUES LESS THAN (TO_DATE(' 2025-01-01 00:00:00', "
+ "'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'),Timestamp '2025-12-31 23:59:59'),\n"
+ "\tPARTITION \"P20240325\" VALUES LESS THAN (TO_DATE(' 2025-01-02 00:00:00', "
+ "'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'),Timestamp '2026-12-31 23:59:59'),\n"
+ "\tPARTITION \"P20240525\" VALUES LESS THAN (TO_DATE(' 2025-01-04 00:00:00', "
+ "'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'),Timestamp '2028-12-31 23:59:59'),\n"
+ "\tPARTITION \"P20240625\" VALUES LESS THAN (TO_DATE(' 2025-01-05 00:00:00', "
+ "'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'),Timestamp '2029-12-31 23:59:59');\n",
expect.put(PartitionPlanStrategy.CREATE, Collections.singletonList(String.format(
"ALTER TABLE \"%s\".\"%s\" ADD \n"
+ "\tPARTITION \"P20240225\" VALUES LESS THAN (TO_DATE(' 2025-01-01 00:00:00', "
+ "'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'),Timestamp '2025-12-31 23:59:59'),\n"
+ "\tPARTITION \"P20240325\" VALUES LESS THAN (TO_DATE(' 2025-01-02 00:00:00', "
+ "'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'),Timestamp '2026-12-31 23:59:59'),\n"
+ "\tPARTITION \"P20240525\" VALUES LESS THAN (TO_DATE(' 2025-01-04 00:00:00', "
+ "'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'),Timestamp '2028-12-31 23:59:59'),\n"
+ "\tPARTITION \"P20240625\" VALUES LESS THAN (TO_DATE(' 2025-01-05 00:00:00', "
+ "'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'),Timestamp '2029-12-31 23:59:59');\n",
configuration.getDefaultDBName(), ORACLE_RANGE_TABLE_NAME)));
Assert.assertEquals(expect, actual);
}
Expand Down Expand Up @@ -326,10 +327,10 @@ public void generatePartitionDdl_mysqlBothCreateAndDropWithOverlap_generateSucce
connection, DialectType.OB_MYSQL, configuration.getDefaultDBName(), tableConfig);
Map<PartitionPlanStrategy, List<String>> expect = new HashMap<>();
expect.put(PartitionPlanStrategy.DROP, Collections.singletonList(String.format(
"ALTER TABLE %s.%s DROP PARTITION (`p20220830`, `p20220829`);\n",
"ALTER TABLE `%s`.`%s` DROP PARTITION (`p20220830`, `p20220829`);\n",
configuration.getDefaultDBName(), MYSQL_OVERLAP_RANGE_TABLE_NAME)));
expect.put(PartitionPlanStrategy.CREATE, Collections.singletonList(String.format(
"ALTER TABLE %s.%s ADD PARTITION (\n"
"ALTER TABLE `%s`.`%s` ADD PARTITION (\n"
+ "\tPARTITION `p20240126` VALUES LESS THAN (20220801,'2024-01-26'),\n"
+ "\tPARTITION `p20240127` VALUES LESS THAN (20220802,'2024-01-27'),\n"
+ "\tPARTITION `p20240128` VALUES LESS THAN (20220803,'2024-01-28'),\n"
Expand Down Expand Up @@ -391,15 +392,15 @@ public void preview_twoTables_succeed() {
List<PartitionPlanPreViewResp> actual = this.partitionPlanService.generatePartitionDdl(
"id", Arrays.asList(p1, p2), false);
PartitionPlanPreViewResp r1 = new PartitionPlanPreViewResp();
r1.setSqls(Collections.singletonList(String.format("ALTER TABLE %s.%s ADD PARTITION (\n"
r1.setSqls(Collections.singletonList(String.format("ALTER TABLE `%s`.`%s` ADD PARTITION (\n"
+ "\tPARTITION `p20240126` VALUES LESS THAN (20220801,'2024-01-26'),\n"
+ "\tPARTITION `p20240127` VALUES LESS THAN (20220802,'2024-01-27'),\n"
+ "\tPARTITION `p20240128` VALUES LESS THAN (20220803,'2024-01-28'),\n"
+ "\tPARTITION `p20240129` VALUES LESS THAN (20220804,'2024-01-29'));\n",
configuration.getDefaultDBName(), MYSQL_OVERLAP_RANGE_TABLE_NAME)));
r1.setTableName(MYSQL_OVERLAP_RANGE_TABLE_NAME);
PartitionPlanPreViewResp r2 = new PartitionPlanPreViewResp();
r2.setSqls(Collections.singletonList(String.format("ALTER TABLE %s.%s ADD PARTITION (\n"
r2.setSqls(Collections.singletonList(String.format("ALTER TABLE `%s`.`%s` ADD PARTITION (\n"
+ "\tPARTITION `p20240125` VALUES LESS THAN (20220801,'2024-01-26'),\n"
+ "\tPARTITION `p20240125` VALUES LESS THAN (20220802,'2024-01-27'),\n"
+ "\tPARTITION `p20240125` VALUES LESS THAN (20220803,'2024-01-28'),\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public void generateCreatePartitionDdls_normal_succeed() throws Exception {
partition.setTableName(dbTable.getName());
partition.setSchemaName(dbTable.getSchemaName());
List<String> actuals = extensionPoint.generateCreatePartitionDdls(connection, partition);
List<String> expects = Collections.singletonList(String.format("ALTER TABLE %s.%s ADD PARTITION (\n"
List<String> expects = Collections.singletonList(String.format("ALTER TABLE `%s`.`%s` ADD PARTITION (\n"
+ "\tPARTITION `p20240126` VALUES LESS THAN (20220801,'2024-01-26'),\n"
+ "\tPARTITION `p20240127` VALUES LESS THAN (20220802,'2024-01-27'),\n"
+ "\tPARTITION `p20240128` VALUES LESS THAN (20220803,'2024-01-28'),\n"
Expand All @@ -253,7 +253,7 @@ public void generateDropPartitionDdls_reloadIndexes_succeed() throws Exception {
dbTablePartition.setTableName(dbTable.getName());
dbTablePartition.setSchemaName(dbTable.getSchemaName());
List<String> actual = extensionPoint.generateDropPartitionDdls(connection, dbTablePartition, true);
List<String> expects = Collections.singletonList(String.format("ALTER TABLE %s.%s DROP PARTITION "
List<String> expects = Collections.singletonList(String.format("ALTER TABLE `%s`.`%s` DROP PARTITION "
+ "(`p20220830`, `p20220829`);\n", configuration.getDefaultDBName(), REAL_RANGE_TABLE_NAME));
Assert.assertEquals(expects, actual);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void generateCreatePartitionDdls_normal_succeed() throws Exception {
partition.setTableName(dbTable.getName());
partition.setSchemaName(dbTable.getSchemaName());
List<String> actuals = extensionPoint.generateCreatePartitionDdls(connection, partition);
List<String> expects = Collections.singletonList(String.format("ALTER TABLE %s.%s ADD \n"
List<String> expects = Collections.singletonList(String.format("ALTER TABLE \"%s\".\"%s\" ADD \n"
+ "\tPARTITION \"P20240225\" VALUES LESS THAN (TO_DATE(' 2024-12-31 23:59:59', "
+ "'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'),Timestamp '2024-01-26 00:00:00'),\n"
+ "\tPARTITION \"P20240325\" VALUES LESS THAN (TO_DATE(' 2025-12-31 23:59:59', "
Expand Down Expand Up @@ -177,7 +177,7 @@ public void generateDropPartitionDdls_reloadIndexes_succeed() throws Exception {
dbTablePartition.setSchemaName(dbTable.getSchemaName());
List<String> actual = extensionPoint.generateDropPartitionDdls(connection, dbTablePartition, true);
List<String> expects = Collections.singletonList(String.format(
"ALTER TABLE %s.%s DROP PARTITION (\"P0\") UPDATE GLOBAL INDEXES;",
"ALTER TABLE \"%s\".\"%s\" DROP PARTITION (\"P0\") UPDATE GLOBAL INDEXES;",
configuration.getDefaultDBName(), RANGE_TABLE_NAME));
Assert.assertEquals(expects, actual);
}
Expand All @@ -199,8 +199,8 @@ public void generateDropPartitionDdls_dontReloadIndexes_succeed() throws Excepti
dbTablePartition.setTableName(dbTable.getName());
dbTablePartition.setSchemaName(dbTable.getSchemaName());
List<String> actual = extensionPoint.generateDropPartitionDdls(connection, dbTablePartition, false);
List<String> expects =
Collections.singletonList(String.format("ALTER TABLE %s.%s DROP PARTITION (\"P0\");\n",
List<String> expects = Collections.singletonList(
String.format("ALTER TABLE \"%s\".\"%s\" DROP PARTITION (\"P0\");\n",
configuration.getDefaultDBName(), RANGE_TABLE_NAME));
Assert.assertEquals(expects, actual);
}
Expand Down