use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class TestPushJoinIntoTableScan method testPushJoinIntoTableScanDoesNotFireForDifferentCatalogs.
@Test
public void testPushJoinIntoTableScanDoesNotFireForDifferentCatalogs() {
try (RuleTester ruleTester = defaultRuleTester()) {
MockConnectorFactory connectorFactory = createMockConnectorFactory((session, applyJoinType, left, right, joinConditions, leftAssignments, rightAssignments) -> {
throw new IllegalStateException("applyJoin should not be called!");
});
ruleTester.getQueryRunner().createCatalog(MOCK_CATALOG, connectorFactory, ImmutableMap.of());
ruleTester.getQueryRunner().createCatalog("another_catalog", "mock", ImmutableMap.of());
TableHandle tableBHandleAnotherCatalog = createTableHandle(new MockConnectorTableHandle(new SchemaTableName(SCHEMA, TABLE_B)), "another_catalog");
ruleTester.assertThat(new PushJoinIntoTableScan(ruleTester.getMetadata())).on(p -> {
Symbol columnA1Symbol = p.symbol(COLUMN_A1);
Symbol columnA2Symbol = p.symbol(COLUMN_A2);
Symbol columnB1Symbol = p.symbol(COLUMN_B1);
TableScanNode left = p.tableScan(TABLE_A_HANDLE, ImmutableList.of(columnA1Symbol, columnA2Symbol), ImmutableMap.of(columnA1Symbol, COLUMN_A1_HANDLE, columnA2Symbol, COLUMN_A2_HANDLE));
TableScanNode right = p.tableScan(tableBHandleAnotherCatalog, ImmutableList.of(columnB1Symbol), ImmutableMap.of(columnB1Symbol, COLUMN_B1_HANDLE));
return p.join(INNER, left, right, new JoinNode.EquiJoinClause(columnA1Symbol, columnB1Symbol));
}).withSession(MOCK_SESSION).doesNotFire();
}
}
use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class FileBasedAccessControl method checkCanSelectFromColumns.
@Override
public void checkCanSelectFromColumns(ConnectorSecurityContext context, SchemaTableName tableName, Set<String> columnNames) {
if (INFORMATION_SCHEMA_NAME.equals(tableName.getSchemaName())) {
return;
}
ConnectorIdentity identity = context.getIdentity();
boolean allowed = tableRules.stream().filter(rule -> rule.matches(identity.getUser(), identity.getEnabledSystemRoles(), identity.getGroups(), tableName)).map(rule -> rule.canSelectColumns(columnNames)).findFirst().orElse(false);
if (!allowed) {
denySelectTable(tableName.toString());
}
}
use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class FileBasedAccessControl method filterColumns.
@Override
public Set<String> filterColumns(ConnectorSecurityContext context, SchemaTableName tableName, Set<String> columns) {
if (INFORMATION_SCHEMA_NAME.equals(tableName.getSchemaName())) {
return columns;
}
ConnectorIdentity identity = context.getIdentity();
TableAccessControlRule rule = tableRules.stream().filter(tableRule -> tableRule.matches(identity.getUser(), identity.getEnabledSystemRoles(), identity.getGroups(), tableName)).findFirst().orElse(null);
if (rule == null || rule.getPrivileges().isEmpty()) {
return ImmutableSet.of();
}
// if user has privileges other than select, show all columns
if (rule.getPrivileges().stream().anyMatch(privilege -> SELECT != privilege)) {
return columns;
}
Set<String> restrictedColumns = rule.getRestrictedColumns();
return columns.stream().filter(column -> !restrictedColumns.contains(column)).collect(toImmutableSet());
}
use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class FileBasedSystemAccessControl method getColumnMask.
@Override
public Optional<ViewExpression> getColumnMask(SystemSecurityContext context, CatalogSchemaTableName table, String columnName, Type type) {
SchemaTableName tableName = table.getSchemaTableName();
if (INFORMATION_SCHEMA_NAME.equals(tableName.getSchemaName())) {
return Optional.empty();
}
Identity identity = context.getIdentity();
return tableRules.stream().filter(rule -> rule.matches(identity.getUser(), identity.getEnabledRoles(), identity.getGroups(), table)).map(rule -> rule.getColumnMask(identity.getUser(), table.getCatalogName(), table.getSchemaTableName().getSchemaName(), columnName)).findFirst().flatMap(Function.identity());
}
use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class FileBasedSystemAccessControl method getRowFilter.
@Override
public Optional<ViewExpression> getRowFilter(SystemSecurityContext context, CatalogSchemaTableName table) {
SchemaTableName tableName = table.getSchemaTableName();
if (INFORMATION_SCHEMA_NAME.equals(tableName.getSchemaName())) {
return Optional.empty();
}
Identity identity = context.getIdentity();
return tableRules.stream().filter(rule -> rule.matches(identity.getUser(), identity.getEnabledRoles(), identity.getGroups(), table)).map(rule -> rule.getFilter(identity.getUser(), table.getCatalogName(), tableName.getSchemaName())).findFirst().flatMap(Function.identity());
}
Aggregations