Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.concurrent.atomic.AtomicReference;

import static com.google.common.base.Preconditions.checkState;
Expand Down Expand Up @@ -73,7 +74,7 @@ public abstract class AbstractIcebergTableOperations
protected TableMetadata currentMetadata;
protected String currentMetadataLocation;
protected boolean shouldRefresh = true;
protected int version = -1;
protected OptionalInt version = OptionalInt.empty();

protected AbstractIcebergTableOperations(
FileIO fileIo,
Expand All @@ -98,7 +99,7 @@ public void initializeFromMetadata(TableMetadata tableMetadata)
currentMetadata = tableMetadata;
currentMetadataLocation = tableMetadata.metadataFileLocation();
shouldRefresh = false;
version = parseVersion(currentMetadataLocation).orElse(-1);
version = parseVersion(currentMetadataLocation);
}

@Override
Expand Down Expand Up @@ -228,7 +229,7 @@ protected void refreshFromMetadataLocation(String newLocation)

currentMetadata = newMetadata.get();
currentMetadataLocation = newLocation;
version = parseVersion(newLocation).orElse(-1);
version = parseVersion(newLocation);
shouldRefresh = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected void commitToExistingTable(TableMetadata base, TableMetadata metadata)
currentMetadataLocation, metadataLocation, getSchemaTableName());
}

String newMetadataLocation = writeNewMetadata(metadata, version + 1);
String newMetadataLocation = writeNewMetadata(metadata, version.orElseThrow() + 1);

Table table = Table.builder(currentTable)
.setDataColumns(toHiveColumns(metadata.schema().columns()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected String getRefreshedLocation(boolean invalidateCaches)
@Override
protected void commitNewTable(TableMetadata metadata)
{
verify(version == -1, "commitNewTable called on a table which already exists");
verify(version.isEmpty(), "commitNewTable called on a table which already exists");
String newMetadataLocation = writeNewMetadata(metadata, 0);
TableInput tableInput = getTableInput(tableName, owner, ImmutableMap.of(METADATA_LOCATION_PROP, newMetadataLocation));

Expand All @@ -115,7 +115,7 @@ protected void commitNewTable(TableMetadata metadata)
@Override
protected void commitToExistingTable(TableMetadata base, TableMetadata metadata)
{
String newMetadataLocation = writeNewMetadata(metadata, version + 1);
String newMetadataLocation = writeNewMetadata(metadata, version.orElseThrow() + 1);
TableInput tableInput = getTableInput(
tableName,
owner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import java.util.Optional;

import static com.google.common.base.Verify.verify;
import static io.trino.plugin.hive.HiveMetadata.TABLE_COMMENT;
import static io.trino.plugin.hive.ViewReaderUtil.isHiveOrPrestoView;
import static io.trino.plugin.hive.ViewReaderUtil.isPrestoView;
Expand Down Expand Up @@ -89,7 +90,8 @@ protected final String getRefreshedLocation(boolean invalidateCaches)
@Override
protected final void commitNewTable(TableMetadata metadata)
{
String newMetadataLocation = writeNewMetadata(metadata, version + 1);
verify(version.isEmpty(), "commitNewTable called on a table which already exists");
String newMetadataLocation = writeNewMetadata(metadata, 0);

Table.Builder builder = Table.builder()
.setDatabaseName(database)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public HiveMetastoreTableOperations(
@Override
protected void commitToExistingTable(TableMetadata base, TableMetadata metadata)
{
String newMetadataLocation = writeNewMetadata(metadata, version + 1);
String newMetadataLocation = writeNewMetadata(metadata, version.orElseThrow() + 1);

long lockId = thriftMetastore.acquireTableExclusiveLock(
new AcidTransactionOwner(session.getUser()),
Expand Down