Exemplo n.º 1
0
  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;
  }
Exemplo n.º 2
0
 private static boolean executeFilter(
     SourceOperatorFactory operatorFactory, Split split, Session session) {
   SourceOperator operator = operatorFactory.createOperator(createDriverContext(session));
   operator.addSplit(split);
   operator.noMoreSplits();
   return executeFilter(operator);
 }
Exemplo n.º 3
0
 private Object selectSingleValue(
     SourceOperatorFactory operatorFactory, Split split, Session session) {
   SourceOperator operator = operatorFactory.createOperator(createDriverContext(session));
   operator.addSplit(split);
   operator.noMoreSplits();
   return selectSingleValue(operator);
 }