Skip to content

Commit

Permalink
Deprecate fromPrimitiveString
Browse files Browse the repository at this point in the history
  • Loading branch information
aihuaxu committed Feb 3, 2025
1 parent fcb3b67 commit 50d1482
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
4 changes: 0 additions & 4 deletions .palantir/revapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1146,10 +1146,6 @@ acceptedBreaks:
\ org.apache.iceberg.TableMetadata)"
justification: "Removing deprecated code"
"1.7.0":
org.apache.iceberg:iceberg-api:
- code: "java.method.removed"
old: "method org.apache.iceberg.types.Type.PrimitiveType org.apache.iceberg.types.Types::fromPrimitiveString(java.lang.String)"
justification: "Replace with fromTypeString to support variant type"
org.apache.iceberg:iceberg-core:
- code: "java.method.removed"
old: "method <T extends org.apache.iceberg.StructLike> org.apache.iceberg.deletes.PositionDeleteIndex\
Expand Down
10 changes: 10 additions & 0 deletions api/src/main/java/org/apache/iceberg/types/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ public static Type fromTypeString(String typeString) {
throw new IllegalArgumentException("Cannot parse type string to primitive: " + typeString);
}

@Deprecated
public static PrimitiveType fromPrimitiveString(String typeString) {
Type type = fromTypeString(typeString);
if (type.isPrimitiveType()) {
return (PrimitiveType) type;
}

throw new IllegalArgumentException("Cannot parse type string to primitive: " + typeString);
}

public static class BooleanType extends PrimitiveType {
private static final BooleanType INSTANCE = new BooleanType();

Expand Down
30 changes: 30 additions & 0 deletions api/src/test/java/org/apache/iceberg/types/TestTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,34 @@ public void fromTypeString() {
.isThrownBy(() -> Types.fromTypeString("abcdefghij"))
.withMessage("Cannot parse type string to primitive: abcdefghij");
}

@Test
public void fromPrimitiveString() {
assertThat(Types.fromPrimitiveString("boolean")).isSameAs(Types.BooleanType.get());
assertThat(Types.fromPrimitiveString("BooLean")).isSameAs(Types.BooleanType.get());

assertThat(Types.fromPrimitiveString("timestamp")).isSameAs(Types.TimestampType.withoutZone());
assertThat(Types.fromPrimitiveString("timestamptz")).isSameAs(Types.TimestampType.withZone());
assertThat(Types.fromPrimitiveString("timestamp_ns"))
.isSameAs(Types.TimestampNanoType.withoutZone());
assertThat(Types.fromPrimitiveString("timestamptz_ns"))
.isSameAs(Types.TimestampNanoType.withZone());

assertThat(Types.fromPrimitiveString("Fixed[ 3 ]")).isEqualTo(Types.FixedType.ofLength(3));

assertThat(Types.fromPrimitiveString("Decimal( 2 , 3 )")).isEqualTo(Types.DecimalType.of(2, 3));

assertThat(Types.fromPrimitiveString("Decimal(2,3)")).isEqualTo(Types.DecimalType.of(2, 3));

assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> Types.fromPrimitiveString("variant"))
.withMessage("Cannot parse type string to primitive: variant");
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> Types.fromPrimitiveString("Variant"))
.withMessage("Cannot parse type string to primitive: Variant");

assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> Types.fromPrimitiveString("abcdefghij"))
.withMessage("Cannot parse type string to primitive: abcdefghij");
}
}

0 comments on commit 50d1482

Please sign in to comment.