use of io.trino.Session in project trino by trinodb.
the class RenameSchemaTask method execute.
@Override
public ListenableFuture<Void> execute(RenameSchema statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
Session session = stateMachine.getSession();
CatalogSchemaName source = createCatalogSchemaName(session, statement, Optional.of(statement.getSource()));
CatalogSchemaName target = new CatalogSchemaName(source.getCatalogName(), statement.getTarget().getValue());
if (!metadata.schemaExists(session, source)) {
throw semanticException(SCHEMA_NOT_FOUND, statement, "Schema '%s' does not exist", source);
}
if (metadata.schemaExists(session, target)) {
throw semanticException(SCHEMA_ALREADY_EXISTS, statement, "Target schema '%s' already exists", target);
}
accessControl.checkCanRenameSchema(session.toSecurityContext(), source, statement.getTarget().getValue());
metadata.renameSchema(session, source, statement.getTarget().getValue());
return immediateVoidFuture();
}
use of io.trino.Session in project trino by trinodb.
the class RevokeRolesTask method execute.
@Override
public ListenableFuture<Void> execute(RevokeRoles statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
Session session = stateMachine.getSession();
Set<String> roles = statement.getRoles().stream().map(role -> role.getValue().toLowerCase(Locale.ENGLISH)).collect(toImmutableSet());
Set<TrinoPrincipal> grantees = statement.getGrantees().stream().map(MetadataUtil::createPrincipal).collect(toImmutableSet());
boolean adminOption = statement.isAdminOption();
Optional<TrinoPrincipal> grantor = statement.getGrantor().map(specification -> createPrincipal(session, specification));
Optional<String> catalog = processRoleCommandCatalog(metadata, session, statement, statement.getCatalog().map(Identifier::getValue));
Set<String> specifiedRoles = new LinkedHashSet<>();
specifiedRoles.addAll(roles);
grantees.stream().filter(principal -> principal.getType() == ROLE).map(TrinoPrincipal::getName).forEach(specifiedRoles::add);
if (grantor.isPresent() && grantor.get().getType() == ROLE) {
specifiedRoles.add(grantor.get().getName());
}
for (String role : specifiedRoles) {
checkRoleExists(session, statement, metadata, role, catalog);
}
accessControl.checkCanRevokeRoles(session.toSecurityContext(), roles, grantees, adminOption, grantor, catalog);
metadata.revokeRoles(session, roles, grantees, adminOption, grantor, catalog);
return immediateVoidFuture();
}
use of io.trino.Session in project trino by trinodb.
the class SetPathTask method execute.
@Override
public ListenableFuture<Void> execute(SetPath statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
Session session = stateMachine.getSession();
if (!session.getClientCapabilities().contains(ClientCapabilities.PATH.toString())) {
throw new TrinoException(NOT_SUPPORTED, "SET PATH not supported by client");
}
// convert to IR before setting HTTP headers - ensures that the representations of all path objects outside the parser remain consistent
SqlPath sqlPath = new SqlPath(Optional.of(statement.getPathSpecification().toString()));
for (SqlPathElement element : sqlPath.getParsedPath()) {
if (element.getCatalog().isEmpty() && session.getCatalog().isEmpty()) {
throw semanticException(MISSING_CATALOG_NAME, statement, "Catalog must be specified for each path element when session catalog is not set");
}
element.getCatalog().ifPresent(catalog -> {
String catalogName = catalog.getValue().toLowerCase(ENGLISH);
getRequiredCatalogHandle(metadata, session, statement, catalogName);
});
}
stateMachine.setSetPath(sqlPath.toString());
return immediateVoidFuture();
}
use of io.trino.Session in project trino by trinodb.
the class SetPropertiesTask method execute.
@Override
public ListenableFuture<Void> execute(SetProperties statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
Session session = stateMachine.getSession();
QualifiedObjectName objectName = createQualifiedObjectName(session, statement, statement.getName());
if (statement.getType() == TABLE) {
Map<String, Optional<Object>> properties = tablePropertyManager.getNullableProperties(getRequiredCatalogHandle(plannerContext.getMetadata(), session, statement, objectName.getCatalogName()), statement.getProperties(), session, plannerContext, accessControl, parameterExtractor(statement, parameters), false);
setTableProperties(statement, objectName, session, properties);
} else if (statement.getType() == MATERIALIZED_VIEW) {
Map<String, Optional<Object>> properties = materializedViewPropertyManager.getNullableProperties(getRequiredCatalogHandle(plannerContext.getMetadata(), session, statement, objectName.getCatalogName()), statement.getProperties(), session, plannerContext, accessControl, parameterExtractor(statement, parameters), false);
setMaterializedViewProperties(statement, objectName, session, properties);
} else {
throw semanticException(NOT_SUPPORTED, statement, "Unsupported target type: %s", statement.getType());
}
return immediateVoidFuture();
}
use of io.trino.Session in project trino by trinodb.
the class SetSchemaAuthorizationTask method execute.
@Override
public ListenableFuture<Void> execute(SetSchemaAuthorization statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
Session session = stateMachine.getSession();
CatalogSchemaName source = createCatalogSchemaName(session, statement, Optional.of(statement.getSource()));
if (!metadata.schemaExists(session, source)) {
throw semanticException(SCHEMA_NOT_FOUND, statement, "Schema '%s' does not exist", source);
}
TrinoPrincipal principal = createPrincipal(statement.getPrincipal());
checkRoleExists(session, statement, metadata, principal, Optional.of(source.getCatalogName()).filter(catalog -> metadata.isCatalogManagedSecurity(session, catalog)));
accessControl.checkCanSetSchemaAuthorization(session.toSecurityContext(), source, principal);
metadata.setSchemaAuthorization(session, source, principal);
return immediateVoidFuture();
}
Aggregations