use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class ResetSessionTask method execute.
@Override
public ListenableFuture<?> execute(ResetSession statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
List<String> parts = statement.getName().getParts();
if (parts.size() > 2) {
throw new SemanticException(INVALID_SESSION_PROPERTY, statement, "Invalid session property '%s'", statement.getName());
}
// validate the property name
if (parts.size() == 1) {
metadata.getSessionPropertyManager().getSystemSessionPropertyMetadata(parts.get(0)).orElseThrow(() -> new SemanticException(INVALID_SESSION_PROPERTY, statement, "Session property %s does not exist", statement.getName()));
} else {
CatalogName catalogName = metadata.getCatalogHandle(stateMachine.getSession(), parts.get(0)).orElseThrow(() -> new SemanticException(MISSING_CATALOG, statement, "Catalog %s does not exist", parts.get(0)));
metadata.getSessionPropertyManager().getConnectorSessionPropertyMetadata(catalogName, parts.get(1)).orElseThrow(() -> new SemanticException(INVALID_SESSION_PROPERTY, statement, "Session property %s does not exist", statement.getName()));
}
stateMachine.addResetSessionProperties(statement.getName().toString());
return immediateFuture(null);
}
use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class RevokeTask method execute.
@Override
public ListenableFuture<?> execute(Revoke statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
Session session = stateMachine.getSession();
QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName());
Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
if (!tableHandle.isPresent()) {
throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
}
Set<Privilege> privileges;
if (statement.getPrivileges().isPresent()) {
privileges = statement.getPrivileges().get().stream().map(privilege -> parsePrivilege(statement, privilege)).collect(toImmutableSet());
} else {
// All privileges
privileges = EnumSet.allOf(Privilege.class);
}
// verify current identity has permissions to revoke permissions
for (Privilege privilege : privileges) {
accessControl.checkCanRevokeTablePrivilege(session.getRequiredTransactionId(), session.getIdentity(), privilege, tableName, createPrincipal(statement.getGrantee()), statement.isGrantOptionFor());
}
metadata.revokeTablePrivileges(session, tableName, privileges, createPrincipal(statement.getGrantee()), statement.isGrantOptionFor());
return immediateFuture(null);
}
use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class SetPathTask method execute.
@Override
public ListenableFuture<?> execute(SetPath statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
Session session = stateMachine.getSession();
if (!session.getClientCapabilities().contains(ClientCapabilities.PATH.toString())) {
throw new PrestoException(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().isPresent() && !session.getCatalog().isPresent()) {
throw new SemanticException(CATALOG_NOT_SPECIFIED, 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);
if (!metadata.getCatalogHandle(session, catalogName).isPresent()) {
throw new PrestoException(NOT_FOUND, "Catalog does not exist: " + catalogName);
}
});
}
stateMachine.setSetPath(sqlPath.toString());
return immediateFuture(null);
}
use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class RevokeRolesTask method execute.
@Override
public ListenableFuture<?> execute(RevokeRoles statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
Session session = stateMachine.getSession();
Set<String> roles = statement.getRoles().stream().map(role -> role.getValue().toLowerCase(Locale.ENGLISH)).collect(toImmutableSet());
Set<PrestoPrincipal> grantees = statement.getGrantees().stream().map(MetadataUtil::createPrincipal).collect(toImmutableSet());
boolean adminOptionFor = statement.isAdminOptionFor();
Optional<PrestoPrincipal> grantor = statement.getGrantor().map(specification -> createPrincipal(session, specification));
String catalog = createCatalogName(session, statement);
Set<String> availableRoles = metadata.listRoles(session, catalog);
Set<String> specifiedRoles = new LinkedHashSet<>();
specifiedRoles.addAll(roles);
grantees.stream().filter(principal -> principal.getType() == ROLE).map(PrestoPrincipal::getName).forEach(specifiedRoles::add);
if (grantor.isPresent() && grantor.get().getType() == ROLE) {
specifiedRoles.add(grantor.get().getName());
}
for (String role : specifiedRoles) {
if (!availableRoles.contains(role)) {
throw new SemanticException(MISSING_ROLE, statement, "Role '%s' does not exist", role);
}
}
accessControl.checkCanRevokeRoles(session.getRequiredTransactionId(), session.getIdentity(), roles, grantees, adminOptionFor, grantor, catalog);
metadata.revokeRoles(session, roles, grantees, adminOptionFor, grantor, catalog);
return immediateFuture(null);
}
use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.
the class SetSessionTask method execute.
@Override
public ListenableFuture<?> execute(SetSession statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
Session session = stateMachine.getSession();
QualifiedName propertyName = statement.getName();
List<String> parts = propertyName.getParts();
if (parts.size() > 2) {
throw new SemanticException(INVALID_SESSION_PROPERTY, statement, "Invalid session property '%s'", propertyName);
}
// validate the property name
PropertyMetadata<?> propertyMetadata;
if (parts.size() == 1) {
accessControl.checkCanSetSystemSessionProperty(session.getIdentity(), parts.get(0));
propertyMetadata = metadata.getSessionPropertyManager().getSystemSessionPropertyMetadata(parts.get(0)).orElseThrow(() -> new SemanticException(INVALID_SESSION_PROPERTY, statement, "Session property %s does not exist", statement.getName()));
} else {
CatalogName catalogName = metadata.getCatalogHandle(stateMachine.getSession(), parts.get(0)).orElseThrow(() -> new SemanticException(MISSING_CATALOG, statement, "Catalog %s does not exist", parts.get(0)));
accessControl.checkCanSetCatalogSessionProperty(session.getRequiredTransactionId(), session.getIdentity(), parts.get(0), parts.get(1));
propertyMetadata = metadata.getSessionPropertyManager().getConnectorSessionPropertyMetadata(catalogName, parts.get(1)).orElseThrow(() -> new SemanticException(INVALID_SESSION_PROPERTY, statement, "Session property %s does not exist", statement.getName()));
}
Type type = propertyMetadata.getSqlType();
Object objectValue;
try {
objectValue = evaluatePropertyValue(statement.getValue(), type, session, metadata, parameters);
} catch (SemanticException e) {
throw new PrestoException(StandardErrorCode.INVALID_SESSION_PROPERTY, String.format("Unable to set session property '%s' to '%s': %s", propertyName, statement.getValue(), e.getMessage()));
}
String value = serializeSessionProperty(type, objectValue);
// verify the SQL value can be decoded by the property
propertyMetadata.decode(objectValue);
stateMachine.addSetSessionProperties(propertyName.toString(), value);
return immediateFuture(null);
}
Aggregations