Search in sources :

Example 1 with IdentityLinkedHashMap

use of com.facebook.presto.util.maps.IdentityLinkedHashMap in project presto by prestodb.

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);
    analyzer.analyze(expression, Scope.builder().build());
    Type actualType = analyzer.getExpressionTypes().get(expression);
    if (!metadata.getTypeManager().canCoerce(actualType, expectedType)) {
        throw new SemanticException(SemanticErrorCode.TYPE_MISMATCH, expression, String.format("Cannot cast type %s to %s", expectedType.getTypeSignature(), actualType.getTypeSignature()));
    }
    IdentityLinkedHashMap<Expression, Type> coercions = new IdentityLinkedHashMap<>();
    coercions.putAll(analyzer.getExpressionCoercions());
    coercions.put(expression, expectedType);
    return evaluateConstantExpression(expression, coercions, metadata, session, ImmutableSet.of(), parameters);
}
Also used : ComparisonExpressionType(com.facebook.presto.sql.tree.ComparisonExpressionType) RowType(com.facebook.presto.type.RowType) OperatorType(com.facebook.presto.spi.function.OperatorType) Type(com.facebook.presto.spi.type.Type) FunctionType(com.facebook.presto.type.FunctionType) VarcharType.createVarcharType(com.facebook.presto.spi.type.VarcharType.createVarcharType) ArrayType(com.facebook.presto.type.ArrayType) IdentityLinkedHashMap(com.facebook.presto.util.maps.IdentityLinkedHashMap) SubqueryExpression(com.facebook.presto.sql.tree.SubqueryExpression) SubscriptExpression(com.facebook.presto.sql.tree.SubscriptExpression) LogicalBinaryExpression(com.facebook.presto.sql.tree.LogicalBinaryExpression) SearchedCaseExpression(com.facebook.presto.sql.tree.SearchedCaseExpression) CoalesceExpression(com.facebook.presto.sql.tree.CoalesceExpression) SimpleCaseExpression(com.facebook.presto.sql.tree.SimpleCaseExpression) NotExpression(com.facebook.presto.sql.tree.NotExpression) LambdaExpression(com.facebook.presto.sql.tree.LambdaExpression) IfExpression(com.facebook.presto.sql.tree.IfExpression) QuantifiedComparisonExpression(com.facebook.presto.sql.tree.QuantifiedComparisonExpression) InListExpression(com.facebook.presto.sql.tree.InListExpression) TryExpression(com.facebook.presto.sql.tree.TryExpression) ArithmeticUnaryExpression(com.facebook.presto.sql.tree.ArithmeticUnaryExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) NullIfExpression(com.facebook.presto.sql.tree.NullIfExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) LiteralInterpreter.toExpression(com.facebook.presto.sql.planner.LiteralInterpreter.toExpression) Expression(com.facebook.presto.sql.tree.Expression) ArithmeticBinaryExpression(com.facebook.presto.sql.tree.ArithmeticBinaryExpression) ExpressionAnalyzer(com.facebook.presto.sql.analyzer.ExpressionAnalyzer) SemanticException(com.facebook.presto.sql.analyzer.SemanticException)

Example 2 with IdentityLinkedHashMap

use of com.facebook.presto.util.maps.IdentityLinkedHashMap in project presto by prestodb.

the class LogicalPlanner method buildLambdaDeclarationToSymbolMap.

private static IdentityLinkedHashMap<LambdaArgumentDeclaration, Symbol> buildLambdaDeclarationToSymbolMap(Analysis analysis, SymbolAllocator symbolAllocator) {
    IdentityLinkedHashMap<LambdaArgumentDeclaration, Symbol> resultMap = new IdentityLinkedHashMap<>();
    for (Map.Entry<Expression, Type> entry : analysis.getTypes().entrySet()) {
        if (!(entry.getKey() instanceof LambdaArgumentDeclaration)) {
            continue;
        }
        LambdaArgumentDeclaration lambdaArgumentDeclaration = (LambdaArgumentDeclaration) entry.getKey();
        if (resultMap.containsKey(lambdaArgumentDeclaration)) {
            continue;
        }
        resultMap.put(lambdaArgumentDeclaration, symbolAllocator.newSymbol(lambdaArgumentDeclaration, entry.getValue()));
    }
    return resultMap;
}
Also used : IdentityLinkedHashMap(com.facebook.presto.util.maps.IdentityLinkedHashMap) Type(com.facebook.presto.spi.type.Type) RelationType(com.facebook.presto.sql.analyzer.RelationType) LambdaArgumentDeclaration(com.facebook.presto.sql.tree.LambdaArgumentDeclaration) Expression(com.facebook.presto.sql.tree.Expression) Map(java.util.Map) IdentityLinkedHashMap(com.facebook.presto.util.maps.IdentityLinkedHashMap)

Example 3 with IdentityLinkedHashMap

use of com.facebook.presto.util.maps.IdentityLinkedHashMap in project presto by prestodb.

the class TestSqlToRowExpressionTranslator method testPossibleExponentialOptimizationTime.

@Test(timeOut = 10_000)
public void testPossibleExponentialOptimizationTime() {
    Expression expression = new LongLiteral("1");
    IdentityLinkedHashMap<Expression, Type> types = new IdentityLinkedHashMap<>();
    types.put(expression, BIGINT);
    for (int i = 0; i < 100; i++) {
        expression = new CoalesceExpression(expression);
        types.put(expression, BIGINT);
    }
    SqlToRowExpressionTranslator.translate(expression, SCALAR, types, FUNCTION_REGISTRY, TYPE_MANAGER, TEST_SESSION, true);
}
Also used : IdentityLinkedHashMap(com.facebook.presto.util.maps.IdentityLinkedHashMap) Type(com.facebook.presto.spi.type.Type) Expression(com.facebook.presto.sql.tree.Expression) CoalesceExpression(com.facebook.presto.sql.tree.CoalesceExpression) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) CoalesceExpression(com.facebook.presto.sql.tree.CoalesceExpression) Test(org.testng.annotations.Test)

Aggregations

Type (com.facebook.presto.spi.type.Type)3 Expression (com.facebook.presto.sql.tree.Expression)3 IdentityLinkedHashMap (com.facebook.presto.util.maps.IdentityLinkedHashMap)3 CoalesceExpression (com.facebook.presto.sql.tree.CoalesceExpression)2 OperatorType (com.facebook.presto.spi.function.OperatorType)1 VarcharType.createVarcharType (com.facebook.presto.spi.type.VarcharType.createVarcharType)1 ExpressionAnalyzer (com.facebook.presto.sql.analyzer.ExpressionAnalyzer)1 RelationType (com.facebook.presto.sql.analyzer.RelationType)1 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)1 LiteralInterpreter.toExpression (com.facebook.presto.sql.planner.LiteralInterpreter.toExpression)1 ArithmeticBinaryExpression (com.facebook.presto.sql.tree.ArithmeticBinaryExpression)1 ArithmeticUnaryExpression (com.facebook.presto.sql.tree.ArithmeticUnaryExpression)1 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)1 ComparisonExpressionType (com.facebook.presto.sql.tree.ComparisonExpressionType)1 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)1 IfExpression (com.facebook.presto.sql.tree.IfExpression)1 InListExpression (com.facebook.presto.sql.tree.InListExpression)1 LambdaArgumentDeclaration (com.facebook.presto.sql.tree.LambdaArgumentDeclaration)1 LambdaExpression (com.facebook.presto.sql.tree.LambdaExpression)1 LogicalBinaryExpression (com.facebook.presto.sql.tree.LogicalBinaryExpression)1