Search in sources :

Example 1 with SymbolToInputRewriter

use of com.facebook.presto.sql.planner.SymbolToInputRewriter in project presto by prestodb.

the class PageProcessorBenchmark method rowExpression.

private RowExpression rowExpression(String expression, Type type) {
    SymbolToInputRewriter symbolToInputRewriter = new SymbolToInputRewriter(sourceLayout);
    Expression inputReferenceExpression = symbolToInputRewriter.rewrite(createExpression(expression, METADATA, symbolTypes));
    ImmutableMap.Builder<Integer, Type> builder = ImmutableMap.builder();
    for (int i = 0; i < columnCount; i++) {
        builder.put(i, type);
    }
    Map<Integer, Type> types = builder.build();
    IdentityLinkedHashMap<Expression, Type> expressionTypes = getExpressionTypesFromInput(TEST_SESSION, METADATA, SQL_PARSER, types, inputReferenceExpression, emptyList());
    return SqlToRowExpressionTranslator.translate(inputReferenceExpression, SCALAR, expressionTypes, METADATA.getFunctionRegistry(), METADATA.getTypeManager(), TEST_SESSION, true);
}
Also used : Type(com.facebook.presto.spi.type.Type) RowExpression(com.facebook.presto.sql.relational.RowExpression) Expression(com.facebook.presto.sql.tree.Expression) FunctionAssertions.createExpression(com.facebook.presto.operator.scalar.FunctionAssertions.createExpression) SymbolToInputRewriter(com.facebook.presto.sql.planner.SymbolToInputRewriter) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with SymbolToInputRewriter

use of com.facebook.presto.sql.planner.SymbolToInputRewriter in project presto by prestodb.

the class ExpressionEquivalence method toRowExpression.

private RowExpression toRowExpression(Session session, Expression expression, Map<Symbol, Integer> symbolInput, Map<Integer, Type> inputTypes) {
    // replace qualified names with input references since row expressions do not support these
    Expression expressionWithInputReferences = new SymbolToInputRewriter(symbolInput).rewrite(expression);
    // determine the type of every expression
    IdentityLinkedHashMap<Expression, Type> expressionTypes = getExpressionTypesFromInput(session, metadata, sqlParser, inputTypes, expressionWithInputReferences, emptyList());
    // convert to row expression
    return translate(expressionWithInputReferences, SCALAR, expressionTypes, metadata.getFunctionRegistry(), metadata.getTypeManager(), session, false);
}
Also used : Type(com.facebook.presto.spi.type.Type) LambdaDefinitionExpression(com.facebook.presto.sql.relational.LambdaDefinitionExpression) CallExpression(com.facebook.presto.sql.relational.CallExpression) RowExpression(com.facebook.presto.sql.relational.RowExpression) VariableReferenceExpression(com.facebook.presto.sql.relational.VariableReferenceExpression) ConstantExpression(com.facebook.presto.sql.relational.ConstantExpression) InputReferenceExpression(com.facebook.presto.sql.relational.InputReferenceExpression) Expression(com.facebook.presto.sql.tree.Expression) SymbolToInputRewriter(com.facebook.presto.sql.planner.SymbolToInputRewriter)

Example 3 with SymbolToInputRewriter

use of com.facebook.presto.sql.planner.SymbolToInputRewriter in project presto by prestodb.

the class FunctionAssertions method compileScanFilterProject.

private SourceOperatorFactory compileScanFilterProject(Expression filter, Expression projection, ExpressionCompiler compiler) {
    filter = new SymbolToInputRewriter(INPUT_MAPPING).rewrite(filter);
    projection = new SymbolToInputRewriter(INPUT_MAPPING).rewrite(projection);
    IdentityLinkedHashMap<Expression, Type> expressionTypes = getExpressionTypesFromInput(TEST_SESSION, metadata, SQL_PARSER, INPUT_TYPES, ImmutableList.of(filter, projection), emptyList());
    try {
        Supplier<CursorProcessor> cursorProcessor = compiler.compileCursorProcessor(toRowExpression(filter, expressionTypes), ImmutableList.of(toRowExpression(projection, expressionTypes)), SOURCE_ID);
        Supplier<PageProcessor> pageProcessor = compiler.compilePageProcessor(toRowExpression(filter, expressionTypes), ImmutableList.of(toRowExpression(projection, expressionTypes)));
        return new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(0, new PlanNodeId("test"), SOURCE_ID, PAGE_SOURCE_PROVIDER, cursorProcessor, pageProcessor, ImmutableList.of(), ImmutableList.of(expressionTypes.get(projection)));
    } catch (Throwable e) {
        if (e instanceof UncheckedExecutionException) {
            e = e.getCause();
        }
        throw new RuntimeException("Error compiling " + projection + ": " + e.getMessage(), e);
    }
}
Also used : CursorProcessor(com.facebook.presto.operator.CursorProcessor) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) Type(com.facebook.presto.spi.type.Type) PageProcessor(com.facebook.presto.operator.PageProcessor) GenericPageProcessor(com.facebook.presto.operator.GenericPageProcessor) RowExpression(com.facebook.presto.sql.relational.RowExpression) CanonicalizeExpressions.canonicalizeExpression(com.facebook.presto.sql.planner.optimizations.CanonicalizeExpressions.canonicalizeExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) Expression(com.facebook.presto.sql.tree.Expression) SymbolToInputRewriter(com.facebook.presto.sql.planner.SymbolToInputRewriter)

Example 4 with SymbolToInputRewriter

use of com.facebook.presto.sql.planner.SymbolToInputRewriter in project presto by prestodb.

the class FunctionAssertions method compileFilterWithNoInputColumns.

private OperatorFactory compileFilterWithNoInputColumns(Expression filter, ExpressionCompiler compiler) {
    filter = new SymbolToInputRewriter(ImmutableMap.of()).rewrite(filter);
    IdentityLinkedHashMap<Expression, Type> expressionTypes = getExpressionTypesFromInput(TEST_SESSION, metadata, SQL_PARSER, INPUT_TYPES, ImmutableList.of(filter), emptyList());
    try {
        Supplier<PageProcessor> processor = compiler.compilePageProcessor(toRowExpression(filter, expressionTypes), ImmutableList.of());
        return new FilterAndProjectOperator.FilterAndProjectOperatorFactory(0, new PlanNodeId("test"), processor, ImmutableList.of());
    } catch (Throwable e) {
        if (e instanceof UncheckedExecutionException) {
            e = e.getCause();
        }
        throw new RuntimeException("Error compiling " + filter + ": " + e.getMessage(), e);
    }
}
Also used : PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) Type(com.facebook.presto.spi.type.Type) PageProcessor(com.facebook.presto.operator.PageProcessor) GenericPageProcessor(com.facebook.presto.operator.GenericPageProcessor) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) RowExpression(com.facebook.presto.sql.relational.RowExpression) CanonicalizeExpressions.canonicalizeExpression(com.facebook.presto.sql.planner.optimizations.CanonicalizeExpressions.canonicalizeExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) Expression(com.facebook.presto.sql.tree.Expression) SymbolToInputRewriter(com.facebook.presto.sql.planner.SymbolToInputRewriter)

Example 5 with SymbolToInputRewriter

use of com.facebook.presto.sql.planner.SymbolToInputRewriter in project presto by prestodb.

the class FunctionAssertions method compileFilterProject.

private OperatorFactory compileFilterProject(Expression filter, Expression projection, ExpressionCompiler compiler) {
    filter = new SymbolToInputRewriter(INPUT_MAPPING).rewrite(filter);
    projection = new SymbolToInputRewriter(INPUT_MAPPING).rewrite(projection);
    IdentityLinkedHashMap<Expression, Type> expressionTypes = getExpressionTypesFromInput(TEST_SESSION, metadata, SQL_PARSER, INPUT_TYPES, ImmutableList.of(filter, projection), emptyList());
    try {
        List<RowExpression> projections = ImmutableList.of(toRowExpression(projection, expressionTypes));
        Supplier<PageProcessor> processor = compiler.compilePageProcessor(toRowExpression(filter, expressionTypes), projections);
        return new FilterAndProjectOperator.FilterAndProjectOperatorFactory(0, new PlanNodeId("test"), processor, ImmutableList.of(expressionTypes.get(projection)));
    } catch (Throwable e) {
        if (e instanceof UncheckedExecutionException) {
            e = e.getCause();
        }
        throw new RuntimeException("Error compiling " + projection + ": " + e.getMessage(), e);
    }
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) RowExpression(com.facebook.presto.sql.relational.RowExpression) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) Type(com.facebook.presto.spi.type.Type) PageProcessor(com.facebook.presto.operator.PageProcessor) GenericPageProcessor(com.facebook.presto.operator.GenericPageProcessor) RowExpression(com.facebook.presto.sql.relational.RowExpression) CanonicalizeExpressions.canonicalizeExpression(com.facebook.presto.sql.planner.optimizations.CanonicalizeExpressions.canonicalizeExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) Expression(com.facebook.presto.sql.tree.Expression) SymbolToInputRewriter(com.facebook.presto.sql.planner.SymbolToInputRewriter)

Aggregations

Type (com.facebook.presto.spi.type.Type)5 SymbolToInputRewriter (com.facebook.presto.sql.planner.SymbolToInputRewriter)5 RowExpression (com.facebook.presto.sql.relational.RowExpression)5 Expression (com.facebook.presto.sql.tree.Expression)5 GenericPageProcessor (com.facebook.presto.operator.GenericPageProcessor)3 PageProcessor (com.facebook.presto.operator.PageProcessor)3 CanonicalizeExpressions.canonicalizeExpression (com.facebook.presto.sql.planner.optimizations.CanonicalizeExpressions.canonicalizeExpression)3 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)3 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)3 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)3 CursorProcessor (com.facebook.presto.operator.CursorProcessor)1 FunctionAssertions.createExpression (com.facebook.presto.operator.scalar.FunctionAssertions.createExpression)1 CallExpression (com.facebook.presto.sql.relational.CallExpression)1 ConstantExpression (com.facebook.presto.sql.relational.ConstantExpression)1 InputReferenceExpression (com.facebook.presto.sql.relational.InputReferenceExpression)1 LambdaDefinitionExpression (com.facebook.presto.sql.relational.LambdaDefinitionExpression)1 VariableReferenceExpression (com.facebook.presto.sql.relational.VariableReferenceExpression)1 ImmutableMap (com.google.common.collect.ImmutableMap)1