[fix](alter) alter partition without storage_policy property will also cancel storage_policy (#51662) (#51910)

### What problem does this PR solve?

pick #51662 to branch-2.1

### Release note

None

### Check List (For Author)

- Test <!-- At least one of them must be included. -->
    - [ ] Regression test
    - [ ] Unit Test
    - [ ] Manual test (add detailed scripts or steps below)
    - [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
        - [ ] Previous test can cover this change.
        - [ ] No code files have been changed.
        - [ ] Other reason <!-- Add your reason?  -->

- Behavior changed:
    - [ ] No.
    - [ ] Yes. <!-- Explain the behavior change -->

- Does this need documentation?
    - [ ] No.
- [ ] Yes. <!-- Add document PR link here. eg:
https://github.com/apache/doris-website/pull/1214 -->

### Check List (For Reviewer who merge this PR)

- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR
should merge into -->
This commit is contained in:
camby
2025-06-20 12:18:36 +08:00
committed by GitHub
parent 75989dae5e
commit 8c2713b2e5
3 changed files with 21 additions and 1 deletions

View File

@ -860,7 +860,9 @@ public class Alter {
// check currentStoragePolicy resource exist.
Env.getCurrentEnv().getPolicyMgr().checkStoragePolicyExist(currentStoragePolicy);
partitionInfo.setStoragePolicy(partition.getId(), currentStoragePolicy);
} else {
} else if (PropertyAnalyzer.hasStoragePolicy(properties)) {
// only set "storage_policy" = "", means cancel storage policy
// if current partition is already in remote storage
if (partition.getRemoteDataSize() > 0) {
throw new AnalysisException(
"Cannot cancel storage policy for partition which is already on code storage.");

View File

@ -1025,6 +1025,13 @@ public class PropertyAnalyzer {
return storagePolicy;
}
public static boolean hasStoragePolicy(Map<String, String> properties) {
if (properties != null && properties.containsKey(PROPERTIES_STORAGE_POLICY)) {
return true;
}
return false;
}
// analyze property like : "type" = "xxx";
public static String analyzeType(Map<String, String> properties) throws AnalysisException {
String type = null;