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 @@ -17,6 +17,7 @@
import com.facebook.presto.iceberg.transaction.IcebergTransactionMetadata;
import com.facebook.presto.spi.ConnectorSession;
import com.facebook.presto.spi.SchemaTableName;
import com.facebook.presto.spi.classloader.ThreadContextClassLoader;
import com.facebook.presto.spi.procedure.Procedure;
import com.facebook.presto.spi.procedure.Procedure.Argument;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -68,10 +69,12 @@ public Procedure get()

public void fastForwardToBranch(ConnectorSession clientSession, String schemaName, String tableName, String fromBranch, String targetBranch)
{
SchemaTableName schemaTableName = new SchemaTableName(schemaName, tableName);
IcebergTransactionMetadata metadata = metadataFactory.create();
Table icebergTable = getIcebergTable(metadata, clientSession, schemaTableName);
icebergTable.manageSnapshots().fastForwardBranch(fromBranch, targetBranch).commit();
metadata.commit();
try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(getClass().getClassLoader())) {
SchemaTableName schemaTableName = new SchemaTableName(schemaName, tableName);
IcebergTransactionMetadata metadata = metadataFactory.create();
Table icebergTable = getIcebergTable(metadata, clientSession, schemaTableName);
icebergTable.manageSnapshots().fastForwardBranch(fromBranch, targetBranch).commit();
metadata.commit();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.facebook.presto.iceberg.transaction.IcebergTransactionMetadata;
import com.facebook.presto.spi.ConnectorSession;
import com.facebook.presto.spi.SchemaTableName;
import com.facebook.presto.spi.classloader.ThreadContextClassLoader;
import com.facebook.presto.spi.procedure.Procedure;
import com.facebook.presto.spi.procedure.Procedure.Argument;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -66,10 +67,12 @@ public Procedure get()

public void rollbackToSnapshot(ConnectorSession clientSession, String schema, String table, Long snapshotId)
{
SchemaTableName schemaTableName = new SchemaTableName(schema, table);
IcebergTransactionMetadata metadata = metadataFactory.create();
getIcebergTable(metadata, clientSession, schemaTableName)
.manageSnapshots().rollbackTo(snapshotId).commit();
metadata.commit();
try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(getClass().getClassLoader())) {
SchemaTableName schemaTableName = new SchemaTableName(schema, table);
IcebergTransactionMetadata metadata = metadataFactory.create();
getIcebergTable(metadata, clientSession, schemaTableName)
.manageSnapshots().rollbackTo(snapshotId).commit();
metadata.commit();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.facebook.presto.iceberg.transaction.IcebergTransactionMetadata;
import com.facebook.presto.spi.ConnectorSession;
import com.facebook.presto.spi.SchemaTableName;
import com.facebook.presto.spi.classloader.ThreadContextClassLoader;
import com.facebook.presto.spi.procedure.Procedure;
import com.facebook.presto.spi.procedure.Procedure.Argument;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -71,14 +72,16 @@ public Procedure get()

public void setCurrentSnapshot(ConnectorSession clientSession, String schema, String table, Long snapshotId, String reference)
{
checkState((snapshotId != null && reference == null) || (snapshotId == null && reference != null),
"Either snapshot_id or reference must be provided, not both");
SchemaTableName schemaTableName = new SchemaTableName(schema, table);
IcebergTransactionMetadata metadata = metadataFactory.create();
Table icebergTable = getIcebergTable(metadata, clientSession, schemaTableName);
long targetSnapshotId = snapshotId != null ? snapshotId : getSnapshotIdFromReference(icebergTable, reference);
icebergTable.manageSnapshots().setCurrentSnapshot(targetSnapshotId).commit();
metadata.commit();
try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(getClass().getClassLoader())) {
checkState((snapshotId != null && reference == null) || (snapshotId == null && reference != null),
"Either snapshot_id or reference must be provided, not both");
SchemaTableName schemaTableName = new SchemaTableName(schema, table);
IcebergTransactionMetadata metadata = metadataFactory.create();
Table icebergTable = getIcebergTable(metadata, clientSession, schemaTableName);
long targetSnapshotId = snapshotId != null ? snapshotId : getSnapshotIdFromReference(icebergTable, reference);
icebergTable.manageSnapshots().setCurrentSnapshot(targetSnapshotId).commit();
metadata.commit();
}
}

private long getSnapshotIdFromReference(Table table, String refName)
Expand Down
Loading