use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class SetViewAuthorizationTask method execute.
@Override
public ListenableFuture<Void> execute(SetViewAuthorization statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
Session session = stateMachine.getSession();
QualifiedObjectName viewName = createQualifiedObjectName(session, statement, statement.getSource());
getRequiredCatalogHandle(metadata, session, statement, viewName.getCatalogName());
ViewDefinition view = metadata.getView(session, viewName).orElseThrow(() -> semanticException(TABLE_NOT_FOUND, statement, "View '%s' does not exist", viewName));
TrinoPrincipal principal = createPrincipal(statement.getPrincipal());
checkRoleExists(session, statement, metadata, principal, Optional.of(viewName.getCatalogName()).filter(catalog -> metadata.isCatalogManagedSecurity(session, catalog)));
if (!view.isRunAsInvoker() && !isAllowSetViewAuthorization) {
throw new TrinoException(NOT_SUPPORTED, format("Cannot set authorization for view %s to %s: this feature is disabled", viewName.getCatalogName() + '.' + viewName.getSchemaName() + '.' + viewName.getObjectName(), principal));
}
accessControl.checkCanSetViewAuthorization(session.toSecurityContext(), viewName, principal);
metadata.setViewAuthorization(session, viewName.asCatalogSchemaTableName(), principal);
return immediateVoidFuture();
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class RenameMaterializedViewTask method execute.
@Override
public ListenableFuture<Void> execute(RenameMaterializedView statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
Session session = stateMachine.getSession();
QualifiedObjectName materializedViewName = createQualifiedObjectName(session, statement, statement.getSource());
if (!metadata.isMaterializedView(session, materializedViewName)) {
if (metadata.isView(session, materializedViewName)) {
throw semanticException(TABLE_NOT_FOUND, statement, "Materialized View '%s' does not exist, but a view with that name exists. Did you mean ALTER VIEW %s RENAME ...?", materializedViewName, materializedViewName);
}
Optional<TableHandle> table = metadata.getTableHandle(session, materializedViewName);
if (table.isPresent()) {
throw semanticException(TABLE_NOT_FOUND, statement, "Materialized View '%s' does not exist, but a table with that name exists. Did you mean ALTER TABLE %s RENAME ...?", materializedViewName, materializedViewName);
}
if (statement.isExists()) {
return immediateVoidFuture();
}
throw semanticException(TABLE_NOT_FOUND, statement, "Materialized View '%s' does not exist", materializedViewName);
}
QualifiedObjectName target = createQualifiedObjectName(session, statement, statement.getTarget());
if (metadata.getCatalogHandle(session, target.getCatalogName()).isEmpty()) {
throw semanticException(CATALOG_NOT_FOUND, statement, "Target catalog '%s' does not exist", target.getCatalogName());
}
if (metadata.isMaterializedView(session, target)) {
throw semanticException(TABLE_ALREADY_EXISTS, statement, "Target materialized view '%s' already exists", target);
}
if (metadata.isView(session, target)) {
throw semanticException(TABLE_ALREADY_EXISTS, statement, "Target materialized view '%s' does not exist, but a view with that name exists.", target);
}
if (metadata.getTableHandle(session, target).isPresent()) {
throw semanticException(TABLE_ALREADY_EXISTS, statement, "Target materialized view '%s' does not exist, but a table with that name exists.", target);
}
if (!materializedViewName.getCatalogName().equals(target.getCatalogName())) {
throw semanticException(NOT_SUPPORTED, statement, "Materialized View rename across catalogs is not supported");
}
accessControl.checkCanRenameMaterializedView(session.toSecurityContext(), materializedViewName, target);
metadata.renameMaterializedView(session, materializedViewName, target);
return immediateVoidFuture();
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TruncateTableTask method execute.
@Override
public ListenableFuture<Void> execute(TruncateTable statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
Session session = stateMachine.getSession();
QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName());
if (metadata.isMaterializedView(session, tableName)) {
throw semanticException(NOT_SUPPORTED, statement, "Cannot truncate a materialized view");
}
if (metadata.isView(session, tableName)) {
throw semanticException(NOT_SUPPORTED, statement, "Cannot truncate a view");
}
Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
if (tableHandle.isEmpty()) {
throw semanticException(TABLE_NOT_FOUND, statement, "Table '%s' does not exist", tableName);
}
accessControl.checkCanTruncateTable(session.toSecurityContext(), tableName);
metadata.truncateTable(session, tableHandle.get());
return immediateFuture(null);
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class InjectedConnectorAccessControl method checkCanExecuteProcedure.
@Override
public void checkCanExecuteProcedure(ConnectorSecurityContext context, SchemaRoutineName procedure) {
checkArgument(context == null, "context must be null");
accessControl.checkCanExecuteProcedure(securityContext, new QualifiedObjectName(catalogName, procedure.getSchemaName(), procedure.getRoutineName()));
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestHiveDistributedJoinQueries method testJoinWithEmptyBuildSide.
@Test
public void testJoinWithEmptyBuildSide() {
Session session = Session.builder(getSession()).setSystemProperty(JOIN_DISTRIBUTION_TYPE, BROADCAST.name()).build();
ResultWithQueryId<MaterializedResult> result = getDistributedQueryRunner().executeWithQueryId(session, "SELECT * FROM lineitem JOIN orders ON lineitem.orderkey = orders.orderkey AND orders.totalprice = 123.4567");
assertEquals(result.getResult().getRowCount(), 0);
OperatorStats probeStats = searchScanFilterAndProjectOperatorStats(result.getQueryId(), new QualifiedObjectName(HIVE_CATALOG, "tpch", "lineitem"));
// Probe-side is not scanned at all, due to dynamic filtering:
assertEquals(probeStats.getInputPositions(), 0L);
assertEquals(probeStats.getDynamicFilterSplitsProcessed(), probeStats.getTotalDrivers());
}
Aggregations