Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug][DynamicPartition]Fix bug that Modify a dynamic partition property in a non-dynamic partition table will throw a Exception #4127

Merged
merged 4 commits into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -1392,8 +1392,18 @@ public void process(List<AlterClause> alterClauses, String clusterName, Database
sendClearAlterTask(db, olapTable);
return;
} else if (DynamicPartitionUtil.checkDynamicPartitionPropertiesExist(properties)) {
Catalog.getCurrentCatalog().modifyTableDynamicPartition(db, olapTable, properties);
return;
if (!DynamicPartitionUtil.checkDynamicPartitionTableRegistered(db.getId(), olapTable.getId())) {
try {
DynamicPartitionUtil.checkInputDynamicPartitionProperties(properties, olapTable.getPartitionInfo());
} catch (DdlException e) {
// This table is not a dynamic partition table and didn't supply all dynamic partition properties
throw new DdlException("Table " + db.getFullName() + "." +
olapTable.getName() + " is not a dynamic partition table. Use command `HELP ALTER TABLE` " +
"to see how to change a normal table to a dynamic partition table.");
}
}
Catalog.getCurrentCatalog().modifyTableDynamicPartition(db, olapTable, properties);
return;
} else if (properties.containsKey("default." + PropertyAnalyzer.PROPERTIES_REPLICATION_NUM)) {
Preconditions.checkNotNull(properties.get(PropertyAnalyzer.PROPERTIES_REPLICATION_NUM));
Catalog.getCurrentCatalog().modifyTableDefaultReplicationNum(db, olapTable, properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public void removeDynamicPartitionTable(Long dbId, Long tableId) {
dynamicPartitionTableInfo.remove(new Pair<>(dbId, tableId));
}

public boolean checkDynamicPartitionTableRegistered(Long dbId, Long tableId) {
return dynamicPartitionTableInfo.contains(new Pair<>(dbId, tableId));
}

public String getRuntimeInfo(String tableName, String key) {
Map<String, String> tableRuntimeInfo = runtimeInfos.getOrDefault(tableName, createDefaultRuntimeInfo());
return tableRuntimeInfo.getOrDefault(key, DEFAULT_RUNTIME_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static boolean checkDynamicPartitionPropertiesExist(Map<String, String> p
properties.containsKey(DynamicPartitionProperty.START_DAY_OF_MONTH);
}

private static boolean checkInputDynamicPartitionProperties(Map<String, String> properties, PartitionInfo partitionInfo) throws DdlException{
public static boolean checkInputDynamicPartitionProperties(Map<String, String> properties, PartitionInfo partitionInfo) throws DdlException{
if (properties == null || properties.isEmpty()) {
return false;
}
Expand All @@ -192,7 +192,6 @@ private static boolean checkInputDynamicPartitionProperties(Map<String, String>
String timeZone = properties.get(DynamicPartitionProperty.TIME_ZONE);
String end = properties.get(DynamicPartitionProperty.END);
String buckets = properties.get(DynamicPartitionProperty.BUCKETS);
String replicationNum = properties.get(DynamicPartitionProperty.REPLICATION_NUM);
String enable = properties.get(DynamicPartitionProperty.ENABLE);
if (!((Strings.isNullOrEmpty(enable) &&
Strings.isNullOrEmpty(timeUnit) &&
Expand Down Expand Up @@ -312,7 +311,8 @@ public static void checkAlterAllowed(OlapTable olapTable) throws DdlException {
if (tableProperty != null && tableProperty.getDynamicPartitionProperty() != null &&
tableProperty.getDynamicPartitionProperty().isExist() &&
tableProperty.getDynamicPartitionProperty().getEnable()) {
throw new DdlException("Cannot add/drop partition on a Dynamic Partition Table, set `dynamic_partition.enable` to false firstly.");
throw new DdlException("Cannot add/drop partition on a Dynamic Partition Table, " +
"Use command `ALTER TABLE tbl_name SET (\"dynamic_partition.enable\" = \"false\")` firstly.");
}
}

Expand All @@ -330,6 +330,10 @@ public static boolean isDynamicPartitionTable(Table table) {
return rangePartitionInfo.getPartitionColumns().size() == 1 && tableProperty.getDynamicPartitionProperty().getEnable();
}

public static boolean checkDynamicPartitionTableRegistered(Long dbId, Long tableId) {
return Catalog.getCurrentCatalog().getDynamicPartitionScheduler().checkDynamicPartitionTableRegistered(dbId, tableId);
}

/**
* properties should be checked before call this method
*/
Expand Down