Search in sources :

Example 1 with Operator

use of com.facebook.presto.operator.Operator in project presto by prestodb.

the class FunctionAssertions method executeProjectionWithAll.

private List<Object> executeProjectionWithAll(String projection, Type expectedType, Session session, ExpressionCompiler compiler) {
    requireNonNull(projection, "projection is null");
    Expression projectionExpression = createExpression(projection, metadata, SYMBOL_TYPES);
    List<Object> results = new ArrayList<>();
    // If the projection does not need bound values, execute query using full engine
    if (!needsBoundValue(projectionExpression)) {
        MaterializedResult result = runner.execute("SELECT " + projection);
        assertType(result.getTypes(), expectedType);
        assertEquals(result.getTypes().size(), 1);
        assertEquals(result.getMaterializedRows().size(), 1);
        Object queryResult = Iterables.getOnlyElement(result.getMaterializedRows()).getField(0);
        results.add(queryResult);
    }
    // execute as standalone operator
    OperatorFactory operatorFactory = compileFilterProject(TRUE_LITERAL, projectionExpression, compiler);
    assertType(operatorFactory.getTypes(), expectedType);
    Object directOperatorValue = selectSingleValue(operatorFactory, session);
    results.add(directOperatorValue);
    // interpret
    Operator interpretedFilterProject = interpretedFilterProject(TRUE_LITERAL, projectionExpression, session);
    assertType(interpretedFilterProject.getTypes(), expectedType);
    Object interpretedValue = selectSingleValue(interpretedFilterProject);
    results.add(interpretedValue);
    // execute over normal operator
    SourceOperatorFactory scanProjectOperatorFactory = compileScanFilterProject(TRUE_LITERAL, projectionExpression, compiler);
    assertType(scanProjectOperatorFactory.getTypes(), expectedType);
    Object scanOperatorValue = selectSingleValue(scanProjectOperatorFactory, createNormalSplit(), session);
    results.add(scanOperatorValue);
    // execute over record set
    Object recordValue = selectSingleValue(scanProjectOperatorFactory, createRecordSetSplit(), session);
    results.add(recordValue);
    // If the projection does not need bound values, execute query using full engine
    if (!needsBoundValue(projectionExpression)) {
        MaterializedResult result = runner.execute("SELECT " + projection);
        assertType(result.getTypes(), expectedType);
        assertEquals(result.getTypes().size(), 1);
        assertEquals(result.getMaterializedRows().size(), 1);
        Object queryResult = Iterables.getOnlyElement(result.getMaterializedRows()).getField(0);
        results.add(queryResult);
    }
    return results;
}
Also used : FilterAndProjectOperator(com.facebook.presto.operator.FilterAndProjectOperator) Operator(com.facebook.presto.operator.Operator) SourceOperator(com.facebook.presto.operator.SourceOperator) ScanFilterAndProjectOperator(com.facebook.presto.operator.ScanFilterAndProjectOperator) 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) SourceOperatorFactory(com.facebook.presto.operator.SourceOperatorFactory) OperatorFactory(com.facebook.presto.operator.OperatorFactory) ArrayList(java.util.ArrayList) MaterializedResult(com.facebook.presto.testing.MaterializedResult) SourceOperatorFactory(com.facebook.presto.operator.SourceOperatorFactory)

Aggregations

FilterAndProjectOperator (com.facebook.presto.operator.FilterAndProjectOperator)1 Operator (com.facebook.presto.operator.Operator)1 OperatorFactory (com.facebook.presto.operator.OperatorFactory)1 ScanFilterAndProjectOperator (com.facebook.presto.operator.ScanFilterAndProjectOperator)1 SourceOperator (com.facebook.presto.operator.SourceOperator)1 SourceOperatorFactory (com.facebook.presto.operator.SourceOperatorFactory)1 CanonicalizeExpressions.canonicalizeExpression (com.facebook.presto.sql.planner.optimizations.CanonicalizeExpressions.canonicalizeExpression)1 RowExpression (com.facebook.presto.sql.relational.RowExpression)1 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)1 Expression (com.facebook.presto.sql.tree.Expression)1 MaterializedResult (com.facebook.presto.testing.MaterializedResult)1 ArrayList (java.util.ArrayList)1