Search in sources :

Example 16 with TrinoException

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();
}
Also used : SqlPath(io.trino.sql.SqlPath) TrinoException(io.trino.spi.TrinoException) SqlPathElement(io.trino.sql.SqlPathElement) Session(io.trino.Session)

Example 17 with TrinoException

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();
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) MetadataUtil.checkRoleExists(io.trino.metadata.MetadataUtil.checkRoleExists) Inject(javax.inject.Inject) NOT_SUPPORTED(io.trino.spi.StandardErrorCode.NOT_SUPPORTED) MetadataUtil.createQualifiedObjectName(io.trino.metadata.MetadataUtil.createQualifiedObjectName) TABLE_NOT_FOUND(io.trino.spi.StandardErrorCode.TABLE_NOT_FOUND) Objects.requireNonNull(java.util.Objects.requireNonNull) SemanticExceptions.semanticException(io.trino.sql.analyzer.SemanticExceptions.semanticException) Futures.immediateVoidFuture(com.google.common.util.concurrent.Futures.immediateVoidFuture) SetViewAuthorization(io.trino.sql.tree.SetViewAuthorization) ViewDefinition(io.trino.metadata.ViewDefinition) TrinoException(io.trino.spi.TrinoException) MetadataUtil.getRequiredCatalogHandle(io.trino.metadata.MetadataUtil.getRequiredCatalogHandle) String.format(java.lang.String.format) List(java.util.List) FeaturesConfig(io.trino.FeaturesConfig) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) AccessControl(io.trino.security.AccessControl) TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) MetadataUtil.createPrincipal(io.trino.metadata.MetadataUtil.createPrincipal) WarningCollector(io.trino.execution.warnings.WarningCollector) Metadata(io.trino.metadata.Metadata) Optional(java.util.Optional) Expression(io.trino.sql.tree.Expression) Session(io.trino.Session) ViewDefinition(io.trino.metadata.ViewDefinition) TrinoException(io.trino.spi.TrinoException) TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) MetadataUtil.createQualifiedObjectName(io.trino.metadata.MetadataUtil.createQualifiedObjectName) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Session(io.trino.Session)

Example 18 with TrinoException

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());
        }
    }
}
Also used : EXCEEDED_TIME_LIMIT(io.trino.spi.StandardErrorCode.EXCEEDED_TIME_LIMIT) TrinoException(io.trino.spi.TrinoException)

Example 19 with TrinoException

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();
}
Also used : Execute(io.trino.sql.tree.Execute) Deallocate(io.trino.sql.tree.Deallocate) Statement(io.trino.sql.tree.Statement) Prepare(io.trino.sql.tree.Prepare) TrinoException(io.trino.spi.TrinoException)

Example 20 with TrinoException

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));
}
Also used : ArrayType(io.trino.spi.type.ArrayType) JsonCodec(io.airlift.json.JsonCodec) DoubleType(io.trino.spi.type.DoubleType) Type(io.trino.spi.type.Type) BooleanType(io.trino.spi.type.BooleanType) BigintType(io.trino.spi.type.BigintType) VarcharType(io.trino.spi.type.VarcharType) IntegerType(io.trino.spi.type.IntegerType) MapType(io.trino.spi.type.MapType) ArrayType(io.trino.spi.type.ArrayType) TrinoException(io.trino.spi.TrinoException) MapType(io.trino.spi.type.MapType)

Aggregations

TrinoException (io.trino.spi.TrinoException)623 IOException (java.io.IOException)151 ImmutableList (com.google.common.collect.ImmutableList)105 List (java.util.List)100 Type (io.trino.spi.type.Type)93 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)90 SchemaTableName (io.trino.spi.connector.SchemaTableName)83 Path (org.apache.hadoop.fs.Path)83 Optional (java.util.Optional)79 ArrayList (java.util.ArrayList)77 Map (java.util.Map)76 ImmutableMap (com.google.common.collect.ImmutableMap)70 Objects.requireNonNull (java.util.Objects.requireNonNull)69 ConnectorSession (io.trino.spi.connector.ConnectorSession)63 TableNotFoundException (io.trino.spi.connector.TableNotFoundException)62 ImmutableSet (com.google.common.collect.ImmutableSet)56 VarcharType (io.trino.spi.type.VarcharType)54 Set (java.util.Set)54 Slice (io.airlift.slice.Slice)53 Table (io.trino.plugin.hive.metastore.Table)52