Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check procedure argument for NULL in RollbackToSnapshotProcedure #15503

Merged
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 @@ -26,6 +26,7 @@

import java.lang.invoke.MethodHandle;

import static io.trino.plugin.base.util.Procedures.checkProcedureArgument;
import static io.trino.spi.type.BigintType.BIGINT;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static java.lang.invoke.MethodHandles.lookup;
Expand Down Expand Up @@ -68,6 +69,10 @@ public Procedure get()

public void rollbackToSnapshot(ConnectorSession clientSession, String schema, String table, Long snapshotId)
{
checkProcedureArgument(schema != null, "schema cannot be null");
checkProcedureArgument(table != null, "table cannot be null");
checkProcedureArgument(snapshotId != null, "snapshot_id cannot be null");

try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(getClass().getClassLoader())) {
SchemaTableName schemaTableName = new SchemaTableName(schema, table);
Table icebergTable = catalogFactory.create(clientSession.getIdentity()).loadTable(clientSession, schemaTableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.testng.annotations.Test;

import static io.trino.tempto.assertions.QueryAssert.Row.row;
import static io.trino.tempto.assertions.QueryAssert.assertQueryFailure;
import static io.trino.tempto.assertions.QueryAssert.assertThat;
import static io.trino.testing.TestingNames.randomNameSuffix;
import static io.trino.tests.product.TestGroups.ICEBERG;
Expand Down Expand Up @@ -47,6 +48,18 @@ public void testRollbackToSnapshot()
onTrino().executeQuery(format("DROP TABLE IF EXISTS %s", tableName));
}

@Test(groups = {ICEBERG, PROFILE_SPECIFIC_TESTS})
public void testRollbackToSnapshotWithNullArgument()
{
onTrino().executeQuery("USE iceberg.default");
assertQueryFailure(() -> onTrino().executeQuery("CALL system.rollback_to_snapshot(NULL, 'customer_orders', 8954597067493422955)"))
.hasMessageMatching(".*schema cannot be null.*");
assertQueryFailure(() -> onTrino().executeQuery("CALL system.rollback_to_snapshot('testdb', NULL, 8954597067493422955)"))
.hasMessageMatching(".*table cannot be null.*");
assertQueryFailure(() -> onTrino().executeQuery("CALL system.rollback_to_snapshot('testdb', 'customer_orders', NULL)"))
.hasMessageMatching(".*snapshot_id cannot be null.*");
}

private long getSecondOldestTableSnapshot(String tableName)
{
return (Long) onTrino().executeQuery(
Expand Down