Search in sources :

Example 6 with NodeRef

use of com.facebook.presto.sql.tree.NodeRef in project presto by prestodb.

the class TestSqlToRowExpressionTranslator method testPossibleExponentialOptimizationTime.

@Test(timeOut = 10_000)
public void testPossibleExponentialOptimizationTime() {
    Expression expression = new LongLiteral("1");
    ImmutableMap.Builder<NodeRef<Expression>, Type> types = ImmutableMap.builder();
    types.put(NodeRef.of(expression), BIGINT);
    for (int i = 0; i < 100; i++) {
        expression = new CoalesceExpression(expression, new LongLiteral("2"));
        types.put(NodeRef.of(expression), BIGINT);
    }
    translator.translateAndOptimize(expression, types.build());
}
Also used : NodeRef(com.facebook.presto.sql.tree.NodeRef) Type(com.facebook.presto.common.type.Type) DecimalType.createDecimalType(com.facebook.presto.common.type.DecimalType.createDecimalType) 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) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.testng.annotations.Test)

Example 7 with NodeRef

use of com.facebook.presto.sql.tree.NodeRef in project presto by prestodb.

the class CommonSubExpressionBenchmark method rowExpression.

private RowExpression rowExpression(String value) {
    Expression expression = createExpression(value, METADATA, TypeProvider.copyOf(symbolTypes));
    Map<NodeRef<Expression>, Type> expressionTypes = getExpressionTypes(TEST_SESSION, METADATA, SQL_PARSER, TypeProvider.copyOf(symbolTypes), expression, emptyList(), WarningCollector.NOOP);
    RowExpression rowExpression = SqlToRowExpressionTranslator.translate(expression, expressionTypes, sourceLayout, METADATA.getFunctionAndTypeManager(), TEST_SESSION);
    RowExpressionOptimizer optimizer = new RowExpressionOptimizer(METADATA);
    return optimizer.optimize(rowExpression, OPTIMIZED, TEST_SESSION.toConnectorSession());
}
Also used : NodeRef(com.facebook.presto.sql.tree.NodeRef) Type(com.facebook.presto.common.type.Type) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) FunctionAssertions.createExpression(com.facebook.presto.operator.scalar.FunctionAssertions.createExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) Expression(com.facebook.presto.sql.tree.Expression) RowExpression(com.facebook.presto.spi.relation.RowExpression) RowExpressionOptimizer(com.facebook.presto.sql.relational.RowExpressionOptimizer)

Example 8 with NodeRef

use of com.facebook.presto.sql.tree.NodeRef in project presto by prestodb.

the class PageProcessorBenchmark method rowExpression.

private RowExpression rowExpression(String value) {
    Expression expression = createExpression(value, METADATA, TypeProvider.copyOf(symbolTypes));
    Map<NodeRef<Expression>, Type> expressionTypes = getExpressionTypes(TEST_SESSION, METADATA, SQL_PARSER, TypeProvider.copyOf(symbolTypes), expression, emptyList(), WarningCollector.NOOP);
    RowExpression rowExpression = SqlToRowExpressionTranslator.translate(expression, expressionTypes, sourceLayout, METADATA.getFunctionAndTypeManager(), TEST_SESSION);
    RowExpressionOptimizer optimizer = new RowExpressionOptimizer(METADATA);
    return optimizer.optimize(rowExpression, OPTIMIZED, TEST_SESSION.toConnectorSession());
}
Also used : NodeRef(com.facebook.presto.sql.tree.NodeRef) Type(com.facebook.presto.common.type.Type) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) FunctionAssertions.createExpression(com.facebook.presto.operator.scalar.FunctionAssertions.createExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) Expression(com.facebook.presto.sql.tree.Expression) RowExpression(com.facebook.presto.spi.relation.RowExpression) RowExpressionOptimizer(com.facebook.presto.sql.relational.RowExpressionOptimizer)

Example 9 with NodeRef

use of com.facebook.presto.sql.tree.NodeRef in project presto by prestodb.

the class TestCommonSubExpressionRewritter method rowExpression.

private RowExpression rowExpression(String sql) {
    Expression expression = rewriteIdentifiersToSymbolReferences(new SqlParser().createExpression(sql));
    Map<NodeRef<Expression>, Type> expressionTypes = getExpressionTypes(SESSION, METADATA, new SqlParser(), TYPES, expression, ImmutableList.of(), WarningCollector.NOOP);
    return SqlToRowExpressionTranslator.translate(expression, expressionTypes, ImmutableMap.of(), METADATA.getFunctionAndTypeManager(), SESSION);
}
Also used : NodeRef(com.facebook.presto.sql.tree.NodeRef) Type(com.facebook.presto.common.type.Type) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) Expression(com.facebook.presto.sql.tree.Expression) SqlParser(com.facebook.presto.sql.parser.SqlParser)

Example 10 with NodeRef

use of com.facebook.presto.sql.tree.NodeRef in project presto by prestodb.

the class TestingRowExpressionTranslator method simplifyExpression.

Expression simplifyExpression(Expression expression) {
    // Testing simplified expressions is important, since simplification may create CASTs or function calls that cannot be simplified by the ExpressionOptimizer
    Map<NodeRef<Expression>, Type> expressionTypes = getExpressionTypes(expression, TypeProvider.empty());
    ExpressionInterpreter interpreter = ExpressionInterpreter.expressionOptimizer(expression, metadata, TEST_SESSION, expressionTypes);
    Object value = interpreter.optimize(NoOpVariableResolver.INSTANCE);
    return literalEncoder.toExpression(value, expressionTypes.get(NodeRef.of(expression)));
}
Also used : NodeRef(com.facebook.presto.sql.tree.NodeRef) Type(com.facebook.presto.common.type.Type) ExpressionInterpreter(com.facebook.presto.sql.planner.ExpressionInterpreter)

Aggregations

NodeRef (com.facebook.presto.sql.tree.NodeRef)15 Type (com.facebook.presto.common.type.Type)14 Expression (com.facebook.presto.sql.tree.Expression)9 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)8 RowExpression (com.facebook.presto.spi.relation.RowExpression)6 ExpressionInterpreter (com.facebook.presto.sql.planner.ExpressionInterpreter)5 SqlParser (com.facebook.presto.sql.parser.SqlParser)4 OperatorType (com.facebook.presto.common.function.OperatorType)3 ArrayType (com.facebook.presto.common.type.ArrayType)3 Metadata (com.facebook.presto.metadata.Metadata)3 LambdaExpression (com.facebook.presto.sql.tree.LambdaExpression)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 List (java.util.List)3 Session (com.facebook.presto.Session)2 DecimalType.createDecimalType (com.facebook.presto.common.type.DecimalType.createDecimalType)2 FunctionType (com.facebook.presto.common.type.FunctionType)2 RowType (com.facebook.presto.common.type.RowType)2 VarcharType.createVarcharType (com.facebook.presto.common.type.VarcharType.createVarcharType)2 FunctionAssertions.createExpression (com.facebook.presto.operator.scalar.FunctionAssertions.createExpression)2