AMashenkov commented on code in PR #6830:
URL: https://github.com/apache/ignite-3/pull/6830#discussion_r2465583080
##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/descriptors/CatalogTableSchemaVersions.java:
##########
@@ -46,25 +51,59 @@ public List<CatalogTableColumnDescriptor> columns() {
public int typeId() {
return MarshallableEntryType.DESCRIPTOR_TABLE_VERSION.id();
}
+
+ private TableVersion assignColumnIds(IdGenerator idGenerator,
Object2IntMap<String> knownColumns) {
+ if (columns.isEmpty()) {
+ return this;
+ }
+
+ List<CatalogTableColumnDescriptor> newColumns = new
ArrayList<>(columns.size());
+ Set<String> columnsExistingInCurrentVersion =
IgniteUtils.newHashSet(columns.size());
+ for (CatalogTableColumnDescriptor column : columns) {
+ columnsExistingInCurrentVersion.add(column.name());
+
+ int newId = knownColumns.computeIfAbsent(column.name(), k ->
idGenerator.nextId());
+
+ newColumns.add(column.clone(newId));
+ }
+
+ // Cleanup ids for non existing columns as new column may be
created with the same name,
+ // but they must be assigned with new id.
+ knownColumns.keySet().removeIf(name ->
!columnsExistingInCurrentVersion.contains(name));
+
+ return new TableVersion(newColumns);
+ }
}
private final int base;
+ private final int nextColumnId;
private final TableVersion[] versions;
/**
* Constructor.
*
- * @param versions Array of table versions.
+ * @param version Array of table versions.
*/
- public CatalogTableSchemaVersions(TableVersion... versions) {
- this(CatalogTableDescriptor.INITIAL_TABLE_VERSION, versions);
+ public CatalogTableSchemaVersions(TableVersion version) {
+ this(
+ CatalogTableDescriptor.INITIAL_TABLE_VERSION,
+ version.columns.size(),
+ version.assignColumnIds(new IdGenerator(0), new
Object2IntOpenHashMap<>())
+ );
}
- CatalogTableSchemaVersions(int base, TableVersion... versions) {
+ CatalogTableSchemaVersions(int base, int nextColumnId, TableVersion...
versions) {
+ validateColumnIdsAreAssigned(versions);
Review Comment:
Should we also check inside the validation method that all `column.id` are
less than given `nextColumnId`?
--
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]