use of io.trino.spi.TrinoException 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.spi.TrinoException 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.spi.TrinoException in project trino by trinodb.
the class QueryTracker method failAbandonedQueries.
private void failAbandonedQueries() {
for (T query : queries.values()) {
try {
if (query.isDone()) {
continue;
}
if (isAbandoned(query)) {
log.info("Failing abandoned query %s", query.getQueryId());
query.fail(new TrinoException(ABANDONED_QUERY, format("Query %s has not been accessed since %s: currentTime %s", query.getQueryId(), query.getLastHeartbeat(), DateTime.now())));
}
} catch (RuntimeException e) {
log.error(e, "Exception failing abandoned query %s", query.getQueryId());
}
}
}
use of io.trino.spi.TrinoException in project trino by trinodb.
the class PrepareTask method execute.
@Override
public ListenableFuture<Void> execute(Prepare prepare, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
Statement statement = prepare.getStatement();
if ((statement instanceof Prepare) || (statement instanceof Execute) || (statement instanceof Deallocate)) {
String type = statement.getClass().getSimpleName().toUpperCase(ENGLISH);
throw new TrinoException(NOT_SUPPORTED, "Invalid statement type for prepared statement: " + type);
}
String sql = getFormattedSql(statement, sqlParser);
stateMachine.addPreparedStatement(prepare.getName().getValue(), sql);
return immediateVoidFuture();
}
use of io.trino.spi.TrinoException in project trino by trinodb.
the class SessionPropertyManager method getJsonCodecForType.
private static <T> JsonCodec<T> getJsonCodecForType(Type type) {
if (VarcharType.VARCHAR.equals(type)) {
return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(String.class);
}
if (BooleanType.BOOLEAN.equals(type)) {
return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Boolean.class);
}
if (BigintType.BIGINT.equals(type)) {
return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Long.class);
}
if (IntegerType.INTEGER.equals(type)) {
return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Integer.class);
}
if (DoubleType.DOUBLE.equals(type)) {
return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Double.class);
}
if (type instanceof ArrayType) {
Type elementType = ((ArrayType) type).getElementType();
return (JsonCodec<T>) JSON_CODEC_FACTORY.listJsonCodec(getJsonCodecForType(elementType));
}
if (type instanceof MapType) {
Type keyType = ((MapType) type).getKeyType();
Type valueType = ((MapType) type).getValueType();
return (JsonCodec<T>) JSON_CODEC_FACTORY.mapJsonCodec(getMapKeyType(keyType), getJsonCodecForType(valueType));
}
throw new TrinoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type));
}
Aggregations