Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
nastra committed Nov 22, 2024
1 parent 2c00e4a commit 4515c45
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
10 changes: 5 additions & 5 deletions core/src/main/java/org/apache/iceberg/SerializableTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private FileIO fileIO(Table table) {
return table.io();
}

protected Table lazyTable() {
private Table lazyTable() {
if (lazyTable == null) {
synchronized (this) {
if (lazyTable == null) {
Expand All @@ -143,6 +143,10 @@ protected Table newTable(TableOperations ops, String tableName) {
return new BaseTable(ops, tableName);
}

public Table underlyingTable() {
return lazyTable();
}

@Override
public String name() {
return name;
Expand Down Expand Up @@ -428,10 +432,6 @@ public StaticTableOperations operations() {
this.getClass().getName() + " does not support operations()");
}

public BaseMetadataTable underlyingMetadataTable() {
return (BaseMetadataTable) lazyTable();
}

public MetadataTableType type() {
return type;
}
Expand Down
25 changes: 7 additions & 18 deletions core/src/main/java/org/apache/iceberg/TableUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,13 @@ private TableUtil() {}
public static int formatVersion(Table table) {
Preconditions.checkArgument(null != table, "Invalid table: null");

// being able to read the format version from the PositionDeletesTable is mainly needed in
// SparkPositionDeletesRewrite when determining whether to rewrite V2 position deletes to DVs
if (table instanceof BaseMetadataTable) {
Preconditions.checkArgument(
table instanceof PositionDeletesTable,
"%s table does not have a format version",
((BaseMetadataTable) table).metadataTableType());

return ((PositionDeletesTable) table).table().operations().current().formatVersion();
} else if (table instanceof SerializableTable.SerializableMetadataTable) {
SerializableTable.SerializableMetadataTable metadataTable =
(SerializableTable.SerializableMetadataTable) table;
Preconditions.checkArgument(
metadataTable.type() == MetadataTableType.POSITION_DELETES,
"%s table does not have a format version",
metadataTable.type());

return metadataTable.underlyingMetadataTable().table().operations().current().formatVersion();
if (table instanceof SerializableTable) {
return formatVersion(((SerializableTable) table).underlyingTable());
} else if (table instanceof PositionDeletesTable) {
// being able to read the format version from the PositionDeletesTable is mainly needed in
// SparkPositionDeletesRewrite when determining whether to rewrite V2 position deletes to DVs
PositionDeletesTable positionDeletesTable = (PositionDeletesTable) table;
return positionDeletesTable.table().operations().current().formatVersion();
} else if (table instanceof HasTableOperations) {
return ((HasTableOperations) table).operations().current().formatVersion();
} else {
Expand Down
6 changes: 4 additions & 2 deletions core/src/test/java/org/apache/iceberg/TestTableUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@ public void formatVersionForMetadataTables() {
Table metadataTable = MetadataTableUtils.createMetadataTableInstance(table, type);
assertThatThrownBy(() -> TableUtil.formatVersion(metadataTable))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("%s table does not have a format version", type);
.hasMessage(
"%s does not have a format version", metadataTable.getClass().getSimpleName());

assertThatThrownBy(() -> TableUtil.formatVersion(SerializableTable.copyOf(metadataTable)))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("%s table does not have a format version", type);
.hasMessage(
"%s does not have a format version", metadataTable.getClass().getSimpleName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void testSerializableMetadataTable() throws IOException, ClassNotFoundExc
} else {
assertThatThrownBy(() -> TableUtil.formatVersion(serializableTable))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("%s table does not have a format version", type);
.hasMessageEndingWith("does not have a format version");
}
}
}
Expand Down

0 comments on commit 4515c45

Please sign in to comment.