|
65 | 65 | import org.apache.doris.datasource.property.storage.AbstractS3CompatibleProperties; |
66 | 66 | import org.apache.doris.datasource.property.storage.S3Properties; |
67 | 67 | import org.apache.doris.datasource.property.storage.StorageProperties; |
| 68 | +import org.apache.doris.mtmv.MTMVRefreshContext; |
| 69 | +import org.apache.doris.mtmv.MTMVRelatedTableIf; |
| 70 | +import org.apache.doris.mtmv.MTMVSnapshotIdSnapshot; |
| 71 | +import org.apache.doris.mtmv.MTMVSnapshotIf; |
68 | 72 | import org.apache.doris.nereids.exceptions.NotSupportedException; |
69 | 73 | import org.apache.doris.nereids.trees.expressions.literal.Result; |
70 | 74 | import org.apache.doris.nereids.types.VarBinaryType; |
|
158 | 162 | import java.util.Comparator; |
159 | 163 | import java.util.EnumMap; |
160 | 164 | import java.util.HashMap; |
| 165 | +import java.util.LinkedHashMap; |
161 | 166 | import java.util.LinkedHashSet; |
162 | 167 | import java.util.List; |
163 | 168 | import java.util.Locale; |
@@ -2637,6 +2642,45 @@ public static <T> T withSnapshotCacheValue(Optional<MvccSnapshot> snapshot, |
2637 | 2642 | return withLatestSnapshotCacheValue(dorisTable, action); |
2638 | 2643 | } |
2639 | 2644 |
|
| 2645 | + /** Derive all MV partition versions from one view without retaining an unbudgeted map. */ |
| 2646 | + public static Map<String, MTMVSnapshotIf> getPartitionSnapshots(ExternalTable dorisTable, |
| 2647 | + Set<String> partitionNames, MTMVRefreshContext context, Optional<MvccSnapshot> snapshot) |
| 2648 | + throws AnalysisException { |
| 2649 | + Map<String, MTMVSnapshotIf> versions = new LinkedHashMap<>(); |
| 2650 | + if (partitionNames.isEmpty()) { |
| 2651 | + return versions; |
| 2652 | + } |
| 2653 | + IcebergSnapshotCacheValue value = getSnapshotCacheValue(snapshot, dorisTable); |
| 2654 | + IcebergPartitionInfo info = value.getPartitionInfo(); |
| 2655 | + for (String name : partitionNames) { |
| 2656 | + try { |
| 2657 | + versions.put(name, partitionSnapshotOf(name, info, value.getSnapshot().getSnapshotId())); |
| 2658 | + } catch (AnalysisException e) { |
| 2659 | + context.recordPartitionSnapshotFailure((MTMVRelatedTableIf) dorisTable, name, e); |
| 2660 | + } |
| 2661 | + } |
| 2662 | + return versions; |
| 2663 | + } |
| 2664 | + |
| 2665 | + public static MTMVSnapshotIf getPartitionSnapshot(String partitionName, IcebergSnapshotCacheValue value) |
| 2666 | + throws AnalysisException { |
| 2667 | + return partitionSnapshotOf(partitionName, value.getPartitionInfo(), value.getSnapshot().getSnapshotId()); |
| 2668 | + } |
| 2669 | + |
| 2670 | + private static MTMVSnapshotIf partitionSnapshotOf(String partitionName, |
| 2671 | + IcebergPartitionInfo info, long tableSnapshotId) throws AnalysisException { |
| 2672 | + long latestSnapshotId = info.getLatestSnapshotId(partitionName); |
| 2673 | + // last_updated_snapshot_id can be absent; retain the table-snapshot fallback for MV refresh. |
| 2674 | + if (latestSnapshotId <= 0) { |
| 2675 | + if (tableSnapshotId <= 0) { |
| 2676 | + throw new AnalysisException("can not find partition: " + partitionName |
| 2677 | + + ", and table snapshot ID is also invalid"); |
| 2678 | + } |
| 2679 | + return new MTMVSnapshotIdSnapshot(tableSnapshotId); |
| 2680 | + } |
| 2681 | + return new MTMVSnapshotIdSnapshot(latestSnapshotId); |
| 2682 | + } |
| 2683 | + |
2640 | 2684 | public static IcebergSnapshotCacheValue getSnapshotCacheValue(Optional<MvccSnapshot> snapshot, |
2641 | 2685 | ExternalTable dorisTable) { |
2642 | 2686 | if (snapshot.isPresent() && snapshot.get() instanceof IcebergMvccSnapshot) { |
|
0 commit comments