timothyw553 commented on code in PR #19127:
URL: https://github.com/apache/iceberg/pull/19127#discussion_r4705356684
##########
core/src/main/java/org/apache/iceberg/SchemaUpdate.java:
##########
@@ -281,6 +290,22 @@ public UpdateSchema updateColumn(String name,
Type.PrimitiveType newType) {
return this;
}
+ if (isV3Promotion(field.type(), newType)) {
+ Preconditions.checkArgument(
+ formatVersion >= MIN_FORMAT_VERSION_V3_PROMOTIONS,
+ "Cannot change column type: %s: %s -> %s is only allowed in format
version %s or later, but table is format version %s",
+ name,
+ field.type(),
+ newType,
+ MIN_FORMAT_VERSION_V3_PROMOTIONS,
+ formatVersion);
+ // TODO: remove once v3 type promotions are supported
+ throw new UnsupportedOperationException(
+ String.format(
+ "Unsupported type promotion for format version %s: %s: %s -> %s",
Review Comment:
saying "unsupported type promotion for format version 4" reads like the
format forbids it, when really iceberg just hasn't implemented it yet. also,
removing the `TODO` throw alone won't enable these since
`TypeUtil.isPromotionAllowed` still rejects them. could we reword the message
(and update the tests and comment to match)?
```diff
- "Unsupported type promotion for format version %s: %s: %s ->
%s",
+ "Type promotion is not yet implemented for format version %s:
%s: %s -> %s",
```
##########
core/src/test/java/org/apache/iceberg/TestSchemaUpdate.java:
##########
@@ -2590,4 +2606,66 @@ public void
testCaseInsensitiveMoveAfterNewlyAddedField() {
assertThat(actual.asStruct()).isEqualTo(expected.asStruct());
}
+
+ @Test
+ void dateToTimestampPromotionRejectedBeforeV3() {
+ Schema schema = new Schema(optional(1, "d", Types.DateType.get()));
+ Table table = TestTables.create(tableDir, "test", schema,
PartitionSpec.unpartitioned(), 2);
+
+ assertThatThrownBy(
+ () -> table.updateSchema().updateColumn("d",
Types.TimestampType.withoutZone()))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(
+ "Cannot change column type: d: date -> timestamp is only allowed
in format version 3 or later, but table is format version 2");
+ }
+
+ @Test
+ void schemaUpdateUsesFormatVersionUpgradedInTransaction() {
+ Schema schema = new Schema(optional(1, "d", Types.DateType.get()));
+ Table table = TestTables.create(tableDir, "test", schema,
PartitionSpec.unpartitioned(), 2);
+ Transaction txn = table.newTransaction();
+ txn.updateProperties().set(TableProperties.FORMAT_VERSION, "3").commit();
+
+ assertThatThrownBy(
+ () -> txn.updateSchema().updateColumn("d",
Types.TimestampType.withoutZone()))
+ .isInstanceOf(UnsupportedOperationException.class)
+ .hasMessage("Unsupported type promotion for format version 3: d: date
-> timestamp");
+ }
+
+ @Test
+ void dateToTimestampPromotionUnsupportedInV3() {
+ Schema schema = new Schema(optional(1, "d", Types.DateType.get()));
+
+ assertThatThrownBy(
+ () ->
+ new SchemaUpdate(schema, 1, 3).updateColumn("d",
Types.TimestampType.withoutZone()))
Review Comment:
the new tests only check v2 and v3, missing v4, `date -> timestamp_ns` below
v3, and `unionByNameWith`. if someone accidentally wrote `== 3` instead of `>=
3`, these tests would still pass. could we parameterize over
`TestHelpers.ALL_VERSIONS` for `date -> timestamp` / `timestamp_ns` (and v3+
for `unknown -> string`) and add a `unionByNameWith` case?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]