Search in sources :

Example 1 with SourceOperatorFactory

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

the class FunctionAssertions method executeFilterWithAll.

private List<Boolean> executeFilterWithAll(String filter, Session session, boolean executeWithNoInputColumns, ExpressionCompiler compiler) {
    requireNonNull(filter, "filter is null");
    Expression filterExpression = createExpression(filter, metadata, SYMBOL_TYPES);
    List<Boolean> results = new ArrayList<>();
    // execute as standalone operator
    OperatorFactory operatorFactory = compileFilterProject(filterExpression, TRUE_LITERAL, compiler);
    results.add(executeFilter(operatorFactory, session));
    if (executeWithNoInputColumns) {
        // execute as standalone operator
        operatorFactory = compileFilterWithNoInputColumns(filterExpression, compiler);
        results.add(executeFilterWithNoInputColumns(operatorFactory, session));
    }
    // interpret
    boolean interpretedValue = executeFilter(interpretedFilterProject(filterExpression, TRUE_LITERAL, session));
    results.add(interpretedValue);
    // execute over normal operator
    SourceOperatorFactory scanProjectOperatorFactory = compileScanFilterProject(filterExpression, TRUE_LITERAL, compiler);
    boolean scanOperatorValue = executeFilter(scanProjectOperatorFactory, createNormalSplit(), session);
    results.add(scanOperatorValue);
    // execute over record set
    boolean recordValue = executeFilter(scanProjectOperatorFactory, createRecordSetSplit(), session);
    results.add(recordValue);
    // If the filter does not need bound values, execute query using full engine
    if (!needsBoundValue(filterExpression)) {
        MaterializedResult result = runner.execute("SELECT TRUE WHERE " + filter);
        assertEquals(result.getTypes().size(), 1);
        Boolean queryResult;
        if (result.getMaterializedRows().isEmpty()) {
            queryResult = false;
        } else {
            assertEquals(result.getMaterializedRows().size(), 1);
            queryResult = (Boolean) Iterables.getOnlyElement(result.getMaterializedRows()).getField(0);
        }
        results.add(queryResult);
    }
    return results;
}
Also used : 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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MaterializedResult(com.facebook.presto.testing.MaterializedResult) SourceOperatorFactory(com.facebook.presto.operator.SourceOperatorFactory)

Example 2 with SourceOperatorFactory

use of com.facebook.presto.operator.SourceOperatorFactory 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

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