sashapolo commented on code in PR #2871:
URL: https://github.com/apache/ignite-3/pull/2871#discussion_r1406047101
##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CatalogUtils.java:
##########
@@ -399,4 +405,49 @@ static CatalogIndexDescriptor indexOrThrow(Catalog
catalog, int indexId) throws
return index;
}
+
+ /**
+ * Collects all table indexes (including dropped) that the table had in
the requested catalog version range.
+ *
+ * <p>It is expected that at least one version of the catalog contains
table indexes.</p>
+ *
+ * @param catalogService Catalog service.
+ * @param tableId Table ID for which indexes will be collected.
+ * @param catalogVersionFrom Catalog version from which indexes will be
collected (including).
+ * @param catalogVersionTo Catalog version up to which indexes will be
collected (including).
+ * @return Table indexes sorted by {@link CatalogIndexDescriptor#id()}.
+ */
+ public static List<CatalogIndexDescriptor> collectIndexes(
+ CatalogService catalogService,
+ int tableId,
+ int catalogVersionFrom,
+ int catalogVersionTo
+ ) {
+ assert catalogVersionFrom <= catalogVersionTo : "from=" +
catalogVersionFrom + ", to=" + catalogVersionTo;
+
+ if (catalogVersionFrom == catalogVersionTo) {
+ List<CatalogIndexDescriptor> indexes =
catalogService.indexes(catalogVersionFrom, tableId);
+
+ assert !indexes.isEmpty() : "catalogVersion=" + catalogVersionFrom
+ ", tableId=" + tableId;
+
+ return indexes;
+ }
+
+ var indexByIdMap = new Int2ObjectOpenHashMap<CatalogIndexDescriptor>();
+
+ for (int catalogVersion = catalogVersionFrom; catalogVersion <=
catalogVersionTo; catalogVersion++) {
+ for (CatalogIndexDescriptor index :
catalogService.indexes(catalogVersion, tableId)) {
+ indexByIdMap.put(index.id(), index);
+ }
+ }
+
+ assert !indexByIdMap.isEmpty()
+ : String.format("catalogVersionFrom=%s, catalogVersionTo=%s,
tableId=%s", catalogVersionFrom, catalogVersionTo, tableId);
+
+ var res = new ArrayList<>(indexByIdMap.values());
+
+ res.sort(comparingInt(CatalogObjectDescriptor::id));
+
+ return unmodifiableList(res);
Review Comment:
yep
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]