Search in sources :

Example 1 with NOT_FOUND

use of io.trino.spi.StandardErrorCode.NOT_FOUND in project trino by trinodb.

the class TestErrorThrowableInQuery method createQueryRunner.

@Override
protected DistributedQueryRunner createQueryRunner() throws Exception {
    Session session = testSessionBuilder().setSystemProperty("task_concurrency", "1").setCatalog("mock").setSchema("default").setClientInfo("{\"clientVersion\":\"testVersion\"}").build();
    DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(session).setNodeCount(1).build();
    try {
        queryRunner.installPlugin(new TpchPlugin());
        queryRunner.installPlugin(new ResourceGroupManagerPlugin());
        queryRunner.installPlugin(new Plugin() {

            @Override
            public Iterable<ConnectorFactory> getConnectorFactories() {
                SchemaTableName stackOverflowErrorTableName = new SchemaTableName("default", "stack_overflow_during_planning");
                SchemaTableName classFormatErrorTableName = new SchemaTableName("default", "class_format_error_during_planning");
                MockConnectorFactory connectorFactory = MockConnectorFactory.builder().withListTables((session, s) -> ImmutableList.of(stackOverflowErrorTableName)).withGetColumns(schemaTableName -> ImmutableList.of(new ColumnMetadata("test_varchar", createUnboundedVarcharType()), new ColumnMetadata("test_bigint", BIGINT))).withGetTableHandle((session, schemaTableName) -> new MockConnectorTableHandle(schemaTableName)).withApplyProjection((session, handle, projections, assignments) -> {
                    MockConnectorTableHandle mockTableHandle = (MockConnectorTableHandle) handle;
                    if (stackOverflowErrorTableName.equals(mockTableHandle.getTableName())) {
                        throw new StackOverflowError("We run out of stack!!!!!!!!!!!");
                    }
                    if (classFormatErrorTableName.equals(mockTableHandle.getTableName())) {
                        throw new ClassFormatError("Bad class format!!!!!!!!!!");
                    }
                    throw new TrinoException(NOT_FOUND, "Unknown table: " + mockTableHandle.getTableName());
                }).build();
                return ImmutableList.of(connectorFactory);
            }
        });
        queryRunner.createCatalog("mock", "mock", ImmutableMap.of());
    } catch (Exception e) {
        queryRunner.close();
        throw e;
    }
    return queryRunner;
}
Also used : NOT_FOUND(io.trino.spi.StandardErrorCode.NOT_FOUND) ImmutableMap(com.google.common.collect.ImmutableMap) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) TrinoException(io.trino.spi.TrinoException) Test(org.testng.annotations.Test) SchemaTableName(io.trino.spi.connector.SchemaTableName) AbstractTestQueryFramework(io.trino.testing.AbstractTestQueryFramework) Plugin(io.trino.spi.Plugin) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ImmutableList(com.google.common.collect.ImmutableList) MockConnectorFactory(io.trino.connector.MockConnectorFactory) BIGINT(io.trino.spi.type.BigintType.BIGINT) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) Session(io.trino.Session) MockConnectorFactory(io.trino.connector.MockConnectorFactory) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) TpchPlugin(io.trino.plugin.tpch.TpchPlugin) SchemaTableName(io.trino.spi.connector.SchemaTableName) TrinoException(io.trino.spi.TrinoException) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) TrinoException(io.trino.spi.TrinoException) Session(io.trino.Session) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) Plugin(io.trino.spi.Plugin) TpchPlugin(io.trino.plugin.tpch.TpchPlugin)

Example 2 with NOT_FOUND

use of io.trino.spi.StandardErrorCode.NOT_FOUND in project trino by trinodb.

the class UseTask method execute.

@Override
public ListenableFuture<Void> execute(Use statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
    Session session = stateMachine.getSession();
    String catalog = statement.getCatalog().map(identifier -> identifier.getValue().toLowerCase(ENGLISH)).orElseGet(() -> session.getCatalog().orElseThrow(() -> semanticException(MISSING_CATALOG_NAME, statement, "Catalog must be specified when session catalog is not set")));
    if (metadata.getCatalogHandle(session, catalog).isEmpty()) {
        throw new TrinoException(NOT_FOUND, "Catalog does not exist: " + catalog);
    }
    String schema = statement.getSchema().getValue().toLowerCase(ENGLISH);
    CatalogSchemaName name = new CatalogSchemaName(catalog, schema);
    if (!metadata.schemaExists(session, name)) {
        throw new TrinoException(NOT_FOUND, "Schema does not exist: " + name);
    }
    if (statement.getCatalog().isPresent()) {
        stateMachine.setSetCatalog(catalog);
    }
    stateMachine.setSetSchema(schema);
    return immediateVoidFuture();
}
Also used : NOT_FOUND(io.trino.spi.StandardErrorCode.NOT_FOUND) Futures.immediateVoidFuture(com.google.common.util.concurrent.Futures.immediateVoidFuture) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TrinoException(io.trino.spi.TrinoException) MISSING_CATALOG_NAME(io.trino.spi.StandardErrorCode.MISSING_CATALOG_NAME) Use(io.trino.sql.tree.Use) Inject(javax.inject.Inject) List(java.util.List) Objects.requireNonNull(java.util.Objects.requireNonNull) WarningCollector(io.trino.execution.warnings.WarningCollector) CatalogSchemaName(io.trino.spi.connector.CatalogSchemaName) Metadata(io.trino.metadata.Metadata) Expression(io.trino.sql.tree.Expression) SemanticExceptions.semanticException(io.trino.sql.analyzer.SemanticExceptions.semanticException) ENGLISH(java.util.Locale.ENGLISH) Session(io.trino.Session) CatalogSchemaName(io.trino.spi.connector.CatalogSchemaName) TrinoException(io.trino.spi.TrinoException) Session(io.trino.Session)

Example 3 with NOT_FOUND

use of io.trino.spi.StandardErrorCode.NOT_FOUND in project trino by trinodb.

the class TableProceduresPropertyManager method getProperties.

public Map<String, Object> getProperties(CatalogName catalog, String procedureName, Map<String, Expression> sqlPropertyValues, Session session, PlannerContext plannerContext, AccessControl accessControl, Map<NodeRef<Parameter>, Expression> parameters) {
    Map<String, PropertyMetadata<?>> supportedProperties = connectorProperties.get(new Key(catalog, procedureName));
    if (supportedProperties == null) {
        throw new TrinoException(NOT_FOUND, format("Catalog '%s' table procedure '%s' property not found", catalog, procedureName));
    }
    Map<String, Optional<Object>> propertyValues = evaluateProperties(sqlPropertyValues.entrySet().stream().map(entry -> new Property(new Identifier(entry.getKey()), entry.getValue())).collect(toImmutableList()), session, plannerContext, accessControl, parameters, true, supportedProperties, INVALID_PROCEDURE_ARGUMENT, format("catalog '%s' table procedure '%s' property", catalog, procedureName));
    return propertyValues.entrySet().stream().filter(entry -> entry.getValue().isPresent()).collect(toImmutableMap(Entry::getKey, entry -> entry.getValue().orElseThrow()));
}
Also used : PropertyUtil.evaluateProperties(io.trino.metadata.PropertyUtil.evaluateProperties) ConcurrentMap(java.util.concurrent.ConcurrentMap) INVALID_PROCEDURE_ARGUMENT(io.trino.spi.StandardErrorCode.INVALID_PROCEDURE_ARGUMENT) CatalogName(io.trino.connector.CatalogName) NodeRef(io.trino.sql.tree.NodeRef) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Property(io.trino.sql.tree.Property) Identifier(io.trino.sql.tree.Identifier) NOT_FOUND(io.trino.spi.StandardErrorCode.NOT_FOUND) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TrinoException(io.trino.spi.TrinoException) PropertyMetadata(io.trino.spi.session.PropertyMetadata) Maps(com.google.common.collect.Maps) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) AccessControl(io.trino.security.AccessControl) Parameter(io.trino.sql.tree.Parameter) Entry(java.util.Map.Entry) Optional(java.util.Optional) Expression(io.trino.sql.tree.Expression) Session(io.trino.Session) PlannerContext(io.trino.sql.PlannerContext) Identifier(io.trino.sql.tree.Identifier) Optional(java.util.Optional) PropertyMetadata(io.trino.spi.session.PropertyMetadata) TrinoException(io.trino.spi.TrinoException) Property(io.trino.sql.tree.Property)

Aggregations

Session (io.trino.Session)3 NOT_FOUND (io.trino.spi.StandardErrorCode.NOT_FOUND)3 TrinoException (io.trino.spi.TrinoException)3 Expression (io.trino.sql.tree.Expression)2 List (java.util.List)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 Maps (com.google.common.collect.Maps)1 Futures.immediateVoidFuture (com.google.common.util.concurrent.Futures.immediateVoidFuture)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 CatalogName (io.trino.connector.CatalogName)1 MockConnectorFactory (io.trino.connector.MockConnectorFactory)1 MockConnectorTableHandle (io.trino.connector.MockConnectorTableHandle)1 WarningCollector (io.trino.execution.warnings.WarningCollector)1 Metadata (io.trino.metadata.Metadata)1