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 io.trino.plugin.deltalake.DeltaLakeMetadataFactory;
import io.trino.plugin.deltalake.statistics.DeltaLakeStatisticsAccess;
import io.trino.spi.TrinoException;
import io.trino.spi.connector.ConnectorAccessControl;
import io.trino.spi.connector.ConnectorSession;
import io.trino.spi.connector.SchemaTableName;
import io.trino.spi.procedure.Procedure;
Expand All @@ -42,6 +43,7 @@ public class DropExtendedStatsProcedure
DropExtendedStatsProcedure.class,
"dropStats",
ConnectorSession.class,
ConnectorAccessControl.class,
// Schema name and table name
String.class,
String.class);
Expand All @@ -68,7 +70,7 @@ public Procedure get()
PROCEDURE_METHOD.bindTo(this));
}

public void dropStats(ConnectorSession session, String schema, String table)
public void dropStats(ConnectorSession session, ConnectorAccessControl accessControl, String schema, String table)
{
checkProcedureArgument(schema != null, "schema_name cannot be null");
checkProcedureArgument(table != null, "table_name cannot be null");
Expand All @@ -78,6 +80,7 @@ public void dropStats(ConnectorSession session, String schema, String table)
if (metadata.getTableHandle(session, name) == null) {
throw new TrinoException(INVALID_PROCEDURE_ARGUMENT, format("Table '%s' does not exist", name));
}
accessControl.checkCanInsertIntoTable(null, name);
statsAccess.deleteDeltaLakeStatistics(session, metadata.getMetastore().getTableLocation(name, session));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.trino.plugin.hive.HdfsEnvironment;
import io.trino.spi.TrinoException;
import io.trino.spi.classloader.ThreadContextClassLoader;
import io.trino.spi.connector.ConnectorAccessControl;
import io.trino.spi.connector.ConnectorSession;
import io.trino.spi.connector.SchemaTableName;
import io.trino.spi.procedure.Procedure;
Expand Down Expand Up @@ -73,6 +74,7 @@ public class VacuumProcedure
VacuumProcedure.class,
"vacuum",
ConnectorSession.class,
ConnectorAccessControl.class,
String.class,
String.class,
String.class);
Expand Down Expand Up @@ -111,12 +113,13 @@ public Procedure get()

public void vacuum(
ConnectorSession session,
ConnectorAccessControl accessControl,
String schema,
String table,
String retention)
{
try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(getClass().getClassLoader())) {
doVacuum(session, schema, table, retention);
doVacuum(session, accessControl, schema, table, retention);
}
catch (TrinoException e) {
throw e;
Expand All @@ -129,6 +132,7 @@ public void vacuum(

private void doVacuum(
ConnectorSession session,
ConnectorAccessControl accessControl,
String schema,
String table,
String retention)
Expand Down Expand Up @@ -159,6 +163,9 @@ private void doVacuum(
DeltaLakeTableHandle handle = metadata.getTableHandle(session, tableName);
checkProcedureArgument(handle != null, "Table '%s' does not exist", tableName);

accessControl.checkCanInsertIntoTable(null, tableName);
accessControl.checkCanDeleteFromTable(null, tableName);

TableSnapshot tableSnapshot = transactionLogAccess.loadSnapshot(tableName, new Path(handle.getLocation()), session);
Path tableLocation = tableSnapshot.getTableLocation();
Path transactionLogDir = getTransactionLogDir(tableLocation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
import static io.trino.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE;
import static io.trino.plugin.deltalake.DeltaLakeQueryRunner.DELTA_CATALOG;
import static io.trino.plugin.deltalake.transactionlog.TransactionLogUtil.TRANSACTION_LOG_DIRECTORY;
import static io.trino.testing.TestingAccessControlManager.TestingPrivilegeType.DELETE_TABLE;
import static io.trino.testing.TestingAccessControlManager.TestingPrivilegeType.INSERT_TABLE;
import static io.trino.testing.TestingAccessControlManager.privilege;
import static io.trino.testing.TestingSession.testSessionBuilder;
import static io.trino.testing.assertions.Assert.assertEquals;
import static io.trino.testing.assertions.Assert.assertEventually;
Expand Down Expand Up @@ -1257,6 +1260,25 @@ public void testVacuumParameterValidation()
assertUpdate("DROP TABLE " + tableName);
}

@Test
public void testVacuumAccessControl()
{
String tableName = "test_deny_vacuum_" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + " WITH (location = '" + getLocationForTable(bucketName, tableName) + "') " +
"AS SELECT * FROM orders", "SELECT count(*) FROM orders");

assertAccessDenied(
"CALL system.vacuum(schema_name => CURRENT_SCHEMA, table_name => '" + tableName + "', retention => '30d')",
"Cannot insert into table .*",
privilege(tableName, INSERT_TABLE));
assertAccessDenied(
"CALL system.vacuum(schema_name => CURRENT_SCHEMA, table_name => '" + tableName + "', retention => '30d')",
"Cannot delete from table .*",
privilege(tableName, DELETE_TABLE));

assertUpdate("DROP TABLE " + tableName);
}

@Test
public void testOptimize()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import static com.google.common.collect.MoreCollectors.onlyElement;
import static io.trino.plugin.deltalake.DeltaLakeDockerizedMinioDataLake.createDockerizedMinioDataLakeForDeltaLake;
import static io.trino.plugin.deltalake.DeltaLakeQueryRunner.DELTA_CATALOG;
import static io.trino.testing.TestingAccessControlManager.TestingPrivilegeType.INSERT_TABLE;
import static io.trino.testing.TestingAccessControlManager.privilege;
import static io.trino.testing.sql.TestTable.randomTableSuffix;
import static java.lang.String.format;
import static java.time.ZoneOffset.UTC;
Expand Down Expand Up @@ -481,6 +483,22 @@ public void testDropMissingStats()
}
}

@Test
public void testDropStatsAccessControl()
{
String path = "test_deny_drop_stats_" + randomTableSuffix();

try (TestTable table = new TestTable(
getQueryRunner()::execute,
"test_deny_drop_stats",
format("WITH (location = '%s') AS SELECT * FROM tpch.sf1.nation", getLocationForTable(path)))) {
assertAccessDenied(
format("CALL %s.system.drop_extended_stats('%s', '%s')", DELTA_CATALOG, SCHEMA, table.getName()),
"Cannot insert into table .*",
privilege(table.getName(), INSERT_TABLE));
}
}

private void runAnalyzeVerifySplitCount(String tableName, long expectedSplitCount)
{
ResultWithQueryId<MaterializedResult> analyzeResult = getDistributedQueryRunner().executeWithQueryId(getSession(), "ANALYZE " + tableName);
Expand Down