[fix](storage_policy) fix cannot cancel a partition's storage policy (#35890)
This commit is contained in:
@ -779,6 +779,12 @@ public class Alter {
|
||||
// check currentStoragePolicy resource exist.
|
||||
Env.getCurrentEnv().getPolicyMgr().checkStoragePolicyExist(currentStoragePolicy);
|
||||
partitionInfo.setStoragePolicy(partition.getId(), currentStoragePolicy);
|
||||
} else {
|
||||
if (partition.getRemoteDataSize() > 0) {
|
||||
throw new AnalysisException(
|
||||
"Cannot cancel storage policy for partition which is already on code storage.");
|
||||
}
|
||||
partitionInfo.setStoragePolicy(partition.getId(), "");
|
||||
}
|
||||
|
||||
// 4.4 analyze new properties
|
||||
|
||||
@ -244,11 +244,9 @@ public class PropertyAnalyzer {
|
||||
} else if (key.equalsIgnoreCase(PROPERTIES_STORAGE_COOLDOWN_TIME)) {
|
||||
DateLiteral dateLiteral = new DateLiteral(value, ScalarType.getDefaultDateType(Type.DATETIME));
|
||||
cooldownTimestamp = dateLiteral.unixTimestamp(TimeUtils.getTimeZone());
|
||||
} else if (!hasStoragePolicy && key.equalsIgnoreCase(PROPERTIES_STORAGE_POLICY)) {
|
||||
if (!Strings.isNullOrEmpty(value)) {
|
||||
hasStoragePolicy = true;
|
||||
newStoragePolicy = value;
|
||||
}
|
||||
} else if (key.equalsIgnoreCase(PROPERTIES_STORAGE_POLICY)) {
|
||||
hasStoragePolicy = true;
|
||||
newStoragePolicy = value;
|
||||
}
|
||||
} // end for properties
|
||||
|
||||
@ -277,7 +275,7 @@ public class PropertyAnalyzer {
|
||||
cooldownTimestamp = DataProperty.MAX_COOLDOWN_TIME_MS;
|
||||
}
|
||||
|
||||
if (hasStoragePolicy) {
|
||||
if (hasStoragePolicy && !"".equals(newStoragePolicy)) {
|
||||
// check remote storage policy
|
||||
StoragePolicy checkedPolicy = StoragePolicy.ofCheck(newStoragePolicy);
|
||||
Policy policy = Env.getCurrentEnv().getPolicyMgr().getPolicy(checkedPolicy);
|
||||
|
||||
@ -156,6 +156,32 @@ suite("test_show_storage_policy_using") {
|
||||
"""
|
||||
assertTrue(show_result.size() >= 4)
|
||||
|
||||
// test cancel a partition's storage policy
|
||||
sql """
|
||||
ALTER TABLE partition_with_multiple_storage_policy MODIFY PARTITION (`p201701`) SET ("storage_policy"="")
|
||||
"""
|
||||
show_result = sql """
|
||||
show storage policy using for ${policy_name}
|
||||
"""
|
||||
assertEquals(show_result.size(), 1)
|
||||
assertTrue(show_result[0][2].equals("table_with_storage_policy_1"))
|
||||
|
||||
sql """
|
||||
ALTER TABLE partition_with_multiple_storage_policy MODIFY PARTITION (`p201701`) SET ("storage_policy"="${policy_name}")
|
||||
"""
|
||||
show_result = sql """
|
||||
show storage policy using for ${policy_name}
|
||||
"""
|
||||
assertEquals(show_result.size(), 2)
|
||||
|
||||
sql """
|
||||
ALTER TABLE partition_with_multiple_storage_policy MODIFY PARTITION (`p201701`) SET ("replication_num"="1")
|
||||
"""
|
||||
show_result = sql """
|
||||
show storage policy using for ${policy_name}
|
||||
"""
|
||||
assertEquals(show_result.size(), 2)
|
||||
|
||||
// cleanup
|
||||
sql """ DROP TABLE IF EXISTS table_with_storage_policy_1 """
|
||||
sql """ DROP TABLE IF EXISTS table_no_storage_policy_1 """
|
||||
|
||||
Reference in New Issue
Block a user