use of io.trino.Session in project trino by trinodb.
the class SetTableAuthorizationTask method execute.
@Override
public ListenableFuture<Void> execute(SetTableAuthorization statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
Session session = stateMachine.getSession();
QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getSource());
getRequiredCatalogHandle(metadata, session, statement, tableName.getCatalogName());
if (metadata.getTableHandle(session, tableName).isEmpty()) {
throw semanticException(TABLE_NOT_FOUND, statement, "Table '%s' does not exist", tableName);
}
TrinoPrincipal principal = createPrincipal(statement.getPrincipal());
checkRoleExists(session, statement, metadata, principal, Optional.of(tableName.getCatalogName()).filter(catalog -> metadata.isCatalogManagedSecurity(session, catalog)));
accessControl.checkCanSetTableAuthorization(session.toSecurityContext(), tableName, principal);
metadata.setTableAuthorization(session, tableName.asCatalogSchemaTableName(), principal);
return immediateVoidFuture();
}
use of io.trino.Session 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.Session 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.Session 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.Session in project trino by trinodb.
the class DomainTranslator method toPredicate.
private Expression toPredicate(Session session, Domain domain, SymbolReference reference) {
if (domain.getValues().isNone()) {
return domain.isNullAllowed() ? new IsNullPredicate(reference) : FALSE_LITERAL;
}
if (domain.getValues().isAll()) {
return domain.isNullAllowed() ? TRUE_LITERAL : new NotExpression(new IsNullPredicate(reference));
}
List<Expression> disjuncts = new ArrayList<>();
disjuncts.addAll(domain.getValues().getValuesProcessor().transform(ranges -> extractDisjuncts(session, domain.getType(), ranges, reference), discreteValues -> extractDisjuncts(session, domain.getType(), discreteValues, reference), allOrNone -> {
throw new IllegalStateException("Case should not be reachable");
}));
// Add nullability disjuncts
if (domain.isNullAllowed()) {
disjuncts.add(new IsNullPredicate(reference));
}
return combineDisjunctsWithDefault(plannerContext.getMetadata(), disjuncts, TRUE_LITERAL);
}
Aggregations