yuqi1129 commented on code in PR #10466:
URL: https://github.com/apache/gravitino/pull/10466#discussion_r2958846300
##########
core/src/test/java/org/apache/gravitino/storage/relational/service/TestTableColumnMetaService.java:
##########
@@ -593,6 +594,75 @@ public void
testGetColumnIdByNamePrefersNonDeletedRecordInSameVersion() throws I
Assertions.assertEquals(newColumn.id(), selectedColumnId);
}
+ @TestTemplate
+ public void
testUpdateTableWithSchemaAndColumnChangesUpdatesAllColumnSchemaIds()
+ throws IOException {
+ String catalogName = "catalog1";
+ String oldSchemaName = "schema1";
+ String newSchemaName = "schema2";
+ createParentEntities(METALAKE_NAME, catalogName, oldSchemaName,
AUDIT_INFO);
+ createAndInsertSchema(METALAKE_NAME, catalogName, newSchemaName);
+
+ ColumnEntity existingColumn =
+ ColumnEntity.builder()
+ .withId(RandomIdGenerator.INSTANCE.nextId())
+ .withName("column1")
+ .withPosition(0)
+ .withComment("comment1")
+ .withDataType(Types.IntegerType.get())
+ .withNullable(true)
+ .withAutoIncrement(false)
+ .withDefaultValue(Literals.integerLiteral(1))
+ .withAuditInfo(AUDIT_INFO)
+ .build();
+
+ TableEntity createdTable =
+ TableEntity.builder()
+ .withId(RandomIdGenerator.INSTANCE.nextId())
+ .withName("table_move_schema")
+ .withNamespace(Namespace.of(METALAKE_NAME, catalogName,
oldSchemaName))
+ .withColumns(Lists.newArrayList(existingColumn))
+ .withAuditInfo(AUDIT_INFO)
+ .build();
+ TableMetaService.getInstance().insertTable(createdTable, false);
+
+ ColumnEntity newColumn =
+ ColumnEntity.builder()
+ .withId(RandomIdGenerator.INSTANCE.nextId())
+ .withName("column2")
+ .withPosition(1)
+ .withComment("comment2")
+ .withDataType(Types.StringType.get())
+ .withNullable(true)
+ .withAutoIncrement(false)
+ .withDefaultValue(Literals.stringLiteral("v2"))
+ .withAuditInfo(AUDIT_INFO)
+ .build();
+
+ TableEntity movedAndUpdatedTable =
+ TableEntity.builder()
+ .withId(createdTable.id())
+ .withName(createdTable.name())
+ .withNamespace(Namespace.of(METALAKE_NAME, catalogName,
newSchemaName))
+ .withColumns(Lists.newArrayList(existingColumn, newColumn))
+ .withAuditInfo(AUDIT_INFO)
+ .build();
+
+ TableMetaService.getInstance()
+ .updateTable(createdTable.nameIdentifier(), old ->
movedAndUpdatedTable);
+
+ long newSchemaId =
+ EntityIdService.getEntityId(
+ NameIdentifier.of(METALAKE_NAME, catalogName, newSchemaName),
Entity.EntityType.SCHEMA);
+ ColumnPO existingColumnPO =
+
TableColumnMetaService.getInstance().getColumnPOById(existingColumn.id());
+
+ Assertions.assertEquals(
+ newSchemaId,
+ existingColumnPO.getSchemaId(),
+ "Existing column schema id should be updated to new schema id");
Review Comment:
Suggest adding extra tests
```java
ColumnPO newColumnPO =
TableColumnMetaService.getInstance().getColumnPOById(newColumn.id());
Assertions.assertEquals(newSchemaId, newColumnPO.getSchemaId(),
"Newly inserted column schema id should also point to new schema id");
```
--
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]