|
45 | 45 | import java.util.Set; |
46 | 46 |
|
47 | 47 | public class MTMVPropertyUtil { |
| 48 | + /** The properties a partition_sync_limit window is built from; see MTMV#alterMvProperties. */ |
| 49 | + private static final List<String> PARTITION_SYNC_WINDOW_KEYS = Lists.newArrayList( |
| 50 | + PropertyAnalyzer.PROPERTIES_PARTITION_SYNC_LIMIT, |
| 51 | + PropertyAnalyzer.PROPERTIES_PARTITION_TIME_UNIT, |
| 52 | + PropertyAnalyzer.PROPERTIES_PARTITION_DATE_FORMAT); |
| 53 | + |
48 | 54 | public static final Set<String> MV_PROPERTY_KEYS = Sets.newHashSet( |
49 | 55 | PropertyAnalyzer.PROPERTIES_GRACE_PERIOD, |
50 | 56 | PropertyAnalyzer.PROPERTIES_EXCLUDED_TRIGGER_TABLES, |
@@ -231,6 +237,56 @@ public static boolean hasPartitionSyncLimit(Map<String, String> mvProperties) { |
231 | 237 | return !StringUtils.isEmpty(value) && Integer.parseInt(value) > 0; |
232 | 238 | } |
233 | 239 |
|
| 240 | + /** Whether the given (altered) properties touch the partition_sync_limit window. */ |
| 241 | + public static boolean containsPartitionSyncWindow(Map<String, String> properties) { |
| 242 | + for (String property : PARTITION_SYNC_WINDOW_KEYS) { |
| 243 | + if (properties.containsKey(property)) { |
| 244 | + return true; |
| 245 | + } |
| 246 | + } |
| 247 | + return false; |
| 248 | + } |
| 249 | + |
| 250 | + /** |
| 251 | + * Whether the change from {@code oldWindowProperties} to {@code newWindowProperties} can bring base |
| 252 | + * partitions back into the window the MV maintains: a limit that is removed, or a wider one. Those |
| 253 | + * partitions' deltas were skipped while they were outside, so nothing incremental can repair them. |
| 254 | + * |
| 255 | + * <p>A window that starts applying is not such a change -- it only takes partitions out of what the MV |
| 256 | + * maintains, and partition sync drops those before the refresh plans -- and neither is a narrower one. |
| 257 | + * Windows in different units or date formats are not comparable without a clock, so a change to either |
| 258 | + * is treated as one that may widen. |
| 259 | + */ |
| 260 | + public static boolean partitionSyncWindowWidens(Map<String, String> oldWindowProperties, |
| 261 | + Map<String, String> newWindowProperties) { |
| 262 | + MTMVPartitionSyncConfig oldWindow = MTMVRelatedPartitionDescSyncLimitGenerator |
| 263 | + .generateMTMVPartitionSyncConfigByProperties(oldWindowProperties); |
| 264 | + if (oldWindow.getSyncLimit() <= 0) { |
| 265 | + return false; |
| 266 | + } |
| 267 | + MTMVPartitionSyncConfig newWindow = MTMVRelatedPartitionDescSyncLimitGenerator |
| 268 | + .generateMTMVPartitionSyncConfigByProperties(newWindowProperties); |
| 269 | + if (newWindow.getSyncLimit() <= 0) { |
| 270 | + return true; |
| 271 | + } |
| 272 | + return !oldWindow.getTimeUnit().equals(newWindow.getTimeUnit()) |
| 273 | + || !oldWindow.getDateFormat().equals(newWindow.getDateFormat()) |
| 274 | + || newWindow.getSyncLimit() > oldWindow.getSyncLimit(); |
| 275 | + } |
| 276 | + |
| 277 | + /** |
| 278 | + * The window the given properties describe, for comparing it across an ALTER. Only the properties the |
| 279 | + * window is built from are read, and the values are compared as they are stored: setting the same |
| 280 | + * window again changes nothing about which rows the MV owes and must not force a rebuild. |
| 281 | + */ |
| 282 | + public static Map<String, String> partitionSyncWindowOf(Map<String, String> properties) { |
| 283 | + Map<String, String> res = Maps.newHashMap(); |
| 284 | + for (String property : PARTITION_SYNC_WINDOW_KEYS) { |
| 285 | + res.put(property, properties.get(property)); |
| 286 | + } |
| 287 | + return res; |
| 288 | + } |
| 289 | + |
234 | 290 | /** |
235 | 291 | * Look up the window limit configured for a base table, mirroring the |
236 | 292 | * excluded_trigger_tables name-matching semantics (empty db/ctl wildcard). |
|
0 commit comments