Search in sources :

Example 1 with SemanticException

use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.

the class AbstractTestQueries method testExecuteWithParametersInGroupBy.

@Test
public void testExecuteWithParametersInGroupBy() {
    try {
        String query = "SELECT a + ?, count(1) FROM (VALUES 1, 2, 3, 2) t(a) GROUP BY a + ?";
        Session session = Session.builder(getSession()).addPreparedStatement("my_query", query).build();
        computeActual(session, "EXECUTE my_query USING 1, 1");
        fail("parameters in GROUP BY and SELECT should fail");
    } catch (SemanticException e) {
        assertEquals(e.getCode(), MUST_BE_AGGREGATE_OR_GROUP_BY);
    } catch (RuntimeException e) {
        assertEquals(e.getMessage(), "line 1:10: '(a + ?)' must be an aggregate expression or appear in GROUP BY clause");
    }
}
Also used : Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException) Test(org.testng.annotations.Test)

Example 2 with SemanticException

use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.

the class UseTask method execute.

@Override
public ListenableFuture<?> execute(Use statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
    Session session = stateMachine.getSession();
    // This section of code loads the dc sub catalogs
    DataCenterUtility.loadDCCatalogForUseTask(statement, metadata, session);
    if (!statement.getCatalog().isPresent() && !session.getCatalog().isPresent()) {
        throw new SemanticException(CATALOG_NOT_SPECIFIED, statement, "Catalog must be specified when session catalog is not set");
    }
    if (statement.getCatalog().isPresent()) {
        String catalog = statement.getCatalog().get().getValue().toLowerCase(ENGLISH);
        if (!metadata.getCatalogHandle(session, catalog).isPresent()) {
            throw new PrestoException(NOT_FOUND, "Catalog does not exist: " + catalog);
        }
        stateMachine.setSetCatalog(catalog);
    }
    // Fix accepting nonexistent schema name in USE <schema> command
    validateSchema(metadata, session, statement);
    stateMachine.setSetSchema(statement.getSchema().getValue().toLowerCase(ENGLISH));
    return immediateFuture(null);
}
Also used : PrestoException(io.prestosql.spi.PrestoException) Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Example 3 with SemanticException

use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.

the class MetadataUtil method createQualifiedObjectName.

public static QualifiedObjectName createQualifiedObjectName(Session session, Node node, QualifiedName name) {
    requireNonNull(session, "session is null");
    requireNonNull(name, "name is null");
    // Hetu supports cluster so that there can be 4 dots in <cluster>.<catalog>.<schema>.<table>
    if (name.getParts().size() > 4) {
        throw new PrestoException(SYNTAX_ERROR, format("Too many dots in table name: %s", name));
    }
    List<String> parts = Lists.reverse(name.getParts());
    String objectName = parts.get(0);
    String schemaName = (parts.size() > 1) ? parts.get(1) : session.getSchema().orElseThrow(() -> new SemanticException(SCHEMA_NOT_SPECIFIED, node, "Schema must be specified when session schema is not set"));
    String catalogName;
    // If there are 4 dots, combine the first two components into one and use it as catalog
    if (parts.size() > 3) {
        catalogName = (parts.size() > 3) ? parts.get(3) + "." + parts.get(2) : session.getCatalog().orElseThrow(() -> new SemanticException(CATALOG_NOT_SPECIFIED, node, "Catalog must be specified when session catalog is not set"));
    } else {
        catalogName = (parts.size() > 2) ? parts.get(2) : session.getCatalog().orElseThrow(() -> new SemanticException(CATALOG_NOT_SPECIFIED, node, "Catalog must be specified when session catalog is not set"));
    }
    return new QualifiedObjectName(catalogName, schemaName, objectName);
}
Also used : PrestoException(io.prestosql.spi.PrestoException) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Example 4 with SemanticException

use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.

the class Failures method toFailure.

private static ExecutionFailureInfo toFailure(Throwable throwable, Set<Throwable> seenFailures) {
    if (throwable == null) {
        return null;
    }
    String type;
    HostAddress remoteHost = null;
    SemanticErrorCode semanticErrorCode = null;
    if (throwable instanceof Failure) {
        type = ((Failure) throwable).getType();
    } else {
        Class<?> clazz = throwable.getClass();
        type = firstNonNull(clazz.getCanonicalName(), clazz.getName());
    }
    if (throwable instanceof PrestoTransportException) {
        remoteHost = ((PrestoTransportException) throwable).getRemoteHost();
    }
    if (throwable instanceof SemanticException) {
        semanticErrorCode = ((SemanticException) throwable).getCode();
    }
    if (seenFailures.contains(throwable)) {
        return new ExecutionFailureInfo(type, "[cyclic] " + throwable.getMessage(), null, ImmutableList.of(), ImmutableList.of(), null, GENERIC_INTERNAL_ERROR.toErrorCode(), Optional.ofNullable(semanticErrorCode), remoteHost);
    }
    seenFailures.add(throwable);
    ExecutionFailureInfo cause = toFailure(throwable.getCause(), seenFailures);
    ErrorCode errorCode = toErrorCode(throwable);
    if (errorCode == null) {
        if (cause == null) {
            errorCode = GENERIC_INTERNAL_ERROR.toErrorCode();
        } else {
            errorCode = cause.getErrorCode();
        }
    }
    return new ExecutionFailureInfo(type, throwable.getMessage(), cause, Arrays.stream(throwable.getSuppressed()).map(failure -> toFailure(failure, seenFailures)).collect(toImmutableList()), Lists.transform(asList(throwable.getStackTrace()), toStringFunction()), getErrorLocation(throwable), errorCode, Optional.ofNullable(semanticErrorCode), remoteHost);
}
Also used : SemanticErrorCode(io.prestosql.sql.analyzer.SemanticErrorCode) ErrorCode(io.prestosql.spi.ErrorCode) StandardErrorCode(io.prestosql.spi.StandardErrorCode) HostAddress(io.prestosql.spi.HostAddress) SemanticErrorCode(io.prestosql.sql.analyzer.SemanticErrorCode) PrestoTransportException(io.prestosql.spi.PrestoTransportException) Failure(io.prestosql.execution.Failure) SemanticException(io.prestosql.sql.analyzer.SemanticException) ExecutionFailureInfo(io.prestosql.execution.ExecutionFailureInfo)

Example 5 with SemanticException

use of io.prestosql.sql.analyzer.SemanticException in project hetu-core by openlookeng.

the class ExpressionInterpreter method evaluateConstantExpression.

public static Object evaluateConstantExpression(Expression expression, Type expectedType, Metadata metadata, Session session, List<Expression> parameters) {
    ExpressionAnalyzer analyzer = createConstantAnalyzer(metadata, session, parameters, WarningCollector.NOOP);
    analyzer.analyze(expression, Scope.create());
    Type actualType = analyzer.getExpressionTypes().get(NodeRef.of(expression));
    if (!new TypeCoercion(metadata::getType).canCoerce(actualType, expectedType)) {
        throw new SemanticException(SemanticErrorCode.TYPE_MISMATCH, expression, String.format("Cannot cast type %s to %s", actualType.getTypeSignature(), expectedType.getTypeSignature()));
    }
    Map<NodeRef<Expression>, Type> coercions = ImmutableMap.<NodeRef<Expression>, Type>builder().putAll(analyzer.getExpressionCoercions()).put(NodeRef.of(expression), expectedType).build();
    return evaluateConstantExpression(expression, coercions, analyzer.getTypeOnlyCoercions(), metadata, session, ImmutableSet.of(), parameters);
}
Also used : NodeRef(io.prestosql.sql.tree.NodeRef) RowType(io.prestosql.spi.type.RowType) VarcharType.createVarcharType(io.prestosql.spi.type.VarcharType.createVarcharType) CharType(io.prestosql.spi.type.CharType) VarcharType(io.prestosql.spi.type.VarcharType) OperatorType(io.prestosql.spi.function.OperatorType) Type(io.prestosql.spi.type.Type) ArrayType(io.prestosql.spi.type.ArrayType) LiteralFunction.isSupportedLiteralType(io.prestosql.metadata.LiteralFunction.isSupportedLiteralType) FunctionType(io.prestosql.spi.type.FunctionType) CanonicalizeExpressionRewriter.canonicalizeExpression(io.prestosql.sql.planner.iterative.rule.CanonicalizeExpressionRewriter.canonicalizeExpression) ArithmeticUnaryExpression(io.prestosql.sql.tree.ArithmeticUnaryExpression) LambdaExpression(io.prestosql.sql.tree.LambdaExpression) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) SimpleCaseExpression(io.prestosql.sql.tree.SimpleCaseExpression) BindExpression(io.prestosql.sql.tree.BindExpression) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression) IfExpression(io.prestosql.sql.tree.IfExpression) InListExpression(io.prestosql.sql.tree.InListExpression) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) SearchedCaseExpression(io.prestosql.sql.tree.SearchedCaseExpression) SubscriptExpression(io.prestosql.sql.tree.SubscriptExpression) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) NullIfExpression(io.prestosql.sql.tree.NullIfExpression) ExpressionAnalyzer(io.prestosql.sql.analyzer.ExpressionAnalyzer) TypeCoercion(io.prestosql.type.TypeCoercion) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Aggregations

SemanticException (io.prestosql.sql.analyzer.SemanticException)34 Session (io.prestosql.Session)27 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)16 MetadataUtil.createQualifiedObjectName (io.prestosql.metadata.MetadataUtil.createQualifiedObjectName)14 PrestoException (io.prestosql.spi.PrestoException)13 TableHandle (io.prestosql.spi.metadata.TableHandle)11 Expression (io.prestosql.sql.tree.Expression)8 CubeMetaStore (io.hetu.core.spi.cube.io.CubeMetaStore)7 CatalogName (io.prestosql.spi.connector.CatalogName)7 HeuristicIndexerManager (io.prestosql.heuristicindex.HeuristicIndexerManager)6 Futures.immediateFuture (com.google.common.util.concurrent.Futures.immediateFuture)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 Metadata (io.prestosql.metadata.Metadata)5 AccessControl (io.prestosql.security.AccessControl)5 Type (io.prestosql.spi.type.Type)5 TransactionManager (io.prestosql.transaction.TransactionManager)5 List (java.util.List)5 Map (java.util.Map)4 Optional (java.util.Optional)4 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)3