use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestRowFilter method testInsert.
@Test
public void testInsert() {
accessControl.reset();
accessControl.rowFilter(new QualifiedObjectName(MOCK_CATALOG, "tiny", "nation"), USER, new ViewExpression(USER, Optional.empty(), Optional.empty(), "nationkey > 100"));
// Within allowed row filter
assertions.query("INSERT INTO mock.tiny.nation VALUES (101, 'POLAND', 0, 'No comment')").assertThat().skippingTypesCheck().matches("SELECT BIGINT '1'");
// Outside allowed row filter
assertThatThrownBy(() -> assertions.query("INSERT INTO mock.tiny.nation VALUES (26, 'POLAND', 0, 'No comment')")).hasMessage("Access Denied: Cannot insert row that does not match to a row filter");
assertThatThrownBy(() -> assertions.query("INSERT INTO mock.tiny.nation VALUES " + "(26, 'POLAND', 0, 'No comment')," + "(27, 'HOLLAND', 0, 'A comment')")).hasMessage("Access Denied: Cannot insert row that does not match to a row filter");
assertThatThrownBy(() -> assertions.query("INSERT INTO mock.tiny.nation VALUES " + "(26, 'POLAND', 0, 'No comment')," + "(27, 'HOLLAND', 0, 'A comment')")).hasMessage("Access Denied: Cannot insert row that does not match to a row filter");
assertThatThrownBy(() -> assertions.query("INSERT INTO mock.tiny.nation(nationkey) VALUES (null)")).hasMessage("Access Denied: Cannot insert row that does not match to a row filter");
assertThatThrownBy(() -> assertions.query("INSERT INTO mock.tiny.nation(regionkey) VALUES (0)")).hasMessage("Access Denied: Cannot insert row that does not match to a row filter");
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestRowFilter method testRowFilterOnHiddenColumn.
@Test
public void testRowFilterOnHiddenColumn() {
accessControl.reset();
accessControl.rowFilter(new QualifiedObjectName(MOCK_CATALOG, "tiny", "nation_with_hidden_column"), USER, new ViewExpression(USER, Optional.empty(), Optional.empty(), "\"$hidden\" < 1"));
assertions.query("SELECT count(*) FROM mock.tiny.nation_with_hidden_column").assertThat().skippingTypesCheck().matches("VALUES BIGINT '25'");
// TODO https://github.com/trinodb/trino/issues/10006 - support insert into a table with row filter that is using hidden columns
assertThatThrownBy(() -> assertions.query("INSERT INTO mock.tiny.nation_with_hidden_column VALUES (101, 'POLAND', 0, 'No comment')")).isInstanceOf(ArrayIndexOutOfBoundsException.class).hasMessage("Index 4 out of bounds for length 4");
assertThatThrownBy(() -> assertions.query("UPDATE mock.tiny.nation_with_hidden_column SET name = 'POLAND'")).isInstanceOf(TrinoException.class).hasMessageContaining("Updating a table with a row filter is not supported");
assertions.query("DELETE FROM mock.tiny.nation_with_hidden_column WHERE regionkey < 5").assertThat().skippingTypesCheck().matches("SELECT BIGINT '25'");
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestFilterInaccessibleColumns method testMaskingWithCaseOnNotAccessibleColumn.
@Test
public void testMaskingWithCaseOnNotAccessibleColumn() {
accessControl.deny(privilege(USER, "nation.nationkey", SELECT_COLUMN));
accessControl.columnMask(new QualifiedObjectName(CATALOG, TINY_SCHEMA_NAME, "nation"), "comment", USER, new ViewExpression(ADMIN, Optional.of(CATALOG), Optional.of(TINY_SCHEMA_NAME), "CASE nationkey WHEN 6 THEN 'masked-comment' ELSE comment END"));
assertThat(assertions.query("SELECT * FROM nation WHERE name = 'FRANCE'")).matches("VALUES (CAST('FRANCE' AS VARCHAR(25)), BIGINT '3', CAST('masked-comment' AS VARCHAR(152)))");
assertThat(assertions.query("SELECT * FROM nation WHERE name = 'CANADA'")).matches("VALUES (CAST('CANADA' AS VARCHAR(25)), BIGINT '1', CAST('eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold' AS VARCHAR(152)))");
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestFilterInaccessibleColumns method testMaskingWithCaseOnNotAccessibleColumnKO.
@Test
public void testMaskingWithCaseOnNotAccessibleColumnKO() {
accessControl.deny(privilege(USER, "nation.nationkey", SELECT_COLUMN));
accessControl.columnMask(new QualifiedObjectName(CATALOG, TINY_SCHEMA_NAME, "nation"), "comment", USER, new ViewExpression(USER, Optional.of(CATALOG), Optional.of(TINY_SCHEMA_NAME), "CASE nationkey WHEN 6 THEN 'masked-comment' ELSE comment END"));
assertThatThrownBy(() -> assertions.query("SELECT * FROM nation WHERE name = 'FRANCE'")).hasMessage("Access Denied: Cannot select from columns [nationkey, regionkey, name, comment] in table or view local.tiny.nation");
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestSourcePartitionedScheduler method createStageExecution.
private StageExecution createStageExecution(PlanFragment fragment, NodeTaskMap nodeTaskMap) {
StageId stageId = new StageId(QUERY_ID, 0);
SqlStage stage = SqlStage.createSqlStage(stageId, fragment, ImmutableMap.of(TABLE_SCAN_NODE_ID, new TableInfo(new QualifiedObjectName("test", "test", "test"), TupleDomain.all())), new MockRemoteTaskFactory(queryExecutor, scheduledExecutor), TEST_SESSION, true, nodeTaskMap, queryExecutor, new SplitSchedulerStats());
ImmutableMap.Builder<PlanFragmentId, OutputBufferManager> outputBuffers = ImmutableMap.builder();
outputBuffers.put(fragment.getId(), new PartitionedOutputBufferManager(FIXED_HASH_DISTRIBUTION, 1));
fragment.getRemoteSourceNodes().stream().flatMap(node -> node.getSourceFragmentIds().stream()).forEach(fragmentId -> outputBuffers.put(fragmentId, new PartitionedOutputBufferManager(FIXED_HASH_DISTRIBUTION, 10)));
return createPipelinedStageExecution(stage, outputBuffers.buildOrThrow(), TaskLifecycleListener.NO_OP, new NoOpFailureDetector(), queryExecutor, Optional.of(new int[] { 0 }), 0);
}
Aggregations