Package org.apache.drill.common.expression

Examples of org.apache.drill.common.expression.LogicalExpression


      }
    };

    ErrorCollector ec = new ErrorCollectorImpl();

    LogicalExpression expr = new IfExpression.Builder()
        .addCondition(
            new IfExpression.IfCondition( //
                new FieldReference("test", ExpressionPosition.UNKNOWN), //
                new IfExpression.Builder()
                    //
                    .addCondition( //
                        new IfExpression.IfCondition(
                            //
                            new ValueExpressions.BooleanExpression("true", ExpressionPosition.UNKNOWN),
                            new FieldReference("test1", ExpressionPosition.UNKNOWN)))
                    .setElse(new ValueExpressions.LongExpression(1L, ExpressionPosition.UNKNOWN)).build()) //
        ) //
        .setElse(new ValueExpressions.LongExpression(1L, ExpressionPosition.UNKNOWN)).build();
    LogicalExpression newExpr = ExpressionTreeMaterializer.materialize(expr, batch, ec);
    assertTrue(newExpr instanceof IfExpression);
    IfExpression newIfExpr = (IfExpression) newExpr;
    assertEquals(1, newIfExpr.conditions.size());
    IfExpression.IfCondition ifCondition = newIfExpr.conditions.get(0);
    assertTrue(ifCondition.expression instanceof IfExpression);
View Full Code Here


        result = new TypedFieldId(Types.required(MinorType.BIGINT), -5);
      }
    };

   
    LogicalExpression functionCallExpr = new FunctionCall(FunctionDefinition.simple("testFunc",
        new ArgumentValidator() {
          @Override
          public void validateArguments(ExpressionPosition expr, List<LogicalExpression> expressions,
              ErrorCollector errors) {
            errors.addGeneralError(expr, "Error!");
          }

          @Override
          public String[] getArgumentNamesByPosition() {
            return new String[0];
          }
        }, OutputTypeDeterminer.FIXED_BIT), ImmutableList.of((LogicalExpression) //
            new FieldReference("test", ExpressionPosition.UNKNOWN) ), ExpressionPosition.UNKNOWN);
    LogicalExpression newExpr = ExpressionTreeMaterializer.materialize(functionCallExpr, batch, ec);
    assertTrue(newExpr instanceof FunctionCall);
    FunctionCall funcExpr = (FunctionCall) newExpr;
    assertEquals(1, funcExpr.args.size());
    assertEquals(bigIntType, funcExpr.args.get(0).getMajorType());
    assertEquals(1, ec.getErrorCount());
View Full Code Here

    g.setMappingSet(MAIN_MAPPING);
   
    for(OrderDef od : popConfig.getOrderings()){
      // first, we rewrite the evaluation stack for each side of the comparison.
      ErrorCollector collector = new ErrorCollectorImpl();
      final LogicalExpression expr = ExpressionTreeMaterializer.materialize(od.getExpr(), this, collector);
      if(collector.hasErrors()) throw new SchemaChangeException("Failure while materializing expression. " + collector.toErrorString());
      g.setMappingSet(LEFT_MAPPING);
      HoldingContainer left = g.addExpr(expr, false);
      g.setMappingSet(RIGHT_MAPPING);
      HoldingContainer right = g.addExpr(expr, false);
View Full Code Here

   
    ErrorCollector collector = new ErrorCollectorImpl();
   
    for(int i =0; i < keyExprs.length; i++){
      NamedExpression ne = popConfig.getKeys()[i];
      final LogicalExpression expr = ExpressionTreeMaterializer.materialize(ne.getExpr(), incoming, collector);
      if(expr == null) continue;
      keyExprs[i] = expr;
      final MaterializedField outputField = MaterializedField.create(ne.getRef(), expr.getMajorType());
      ValueVector vector = TypeHelper.getNewVector(outputField, context.getAllocator());
      allocators.add(VectorAllocator.getAllocator(vector, 50));
      keyOutputIds[i] = container.add(vector);
    }
   
    for(int i =0; i < valueExprs.length; i++){
      NamedExpression ne = popConfig.getExprs()[i];
      final LogicalExpression expr = ExpressionTreeMaterializer.materialize(ne.getExpr(), incoming, collector);
      if(expr == null) continue;
     
      final MaterializedField outputField = MaterializedField.create(ne.getRef(), expr.getMajorType());
      ValueVector vector = TypeHelper.getNewVector(outputField, context.getAllocator());
      allocators.add(VectorAllocator.getAllocator(vector, 50));
      TypedFieldId id = container.add(vector);
      valueExprs[i] = new ValueVectorWriteExpression(id, expr, true);
    }
View Full Code Here

  private JoinWorker generateNewWorker() throws ClassTransformationException, IOException, SchemaChangeException{

    final CodeGenerator<JoinWorker> cg = new CodeGenerator<>(JoinWorker.TEMPLATE_DEFINITION, context.getFunctionRegistry());
    final ErrorCollector collector = new ErrorCollectorImpl();
    final LogicalExpression leftFieldExpr = condition.getLeft();
    final LogicalExpression rightFieldExpr = condition.getRight();

    // Generate members and initialization code
    /////////////////////////////////////////

    // declare and assign JoinStatus member
    cg.setMappingSet(SETUP_MAPPING);
    JClass joinStatusClass = cg.getModel().ref(JoinStatus.class);
    JVar joinStatus = cg.clazz.field(JMod.NONE, joinStatusClass, "status");
    cg.getSetupBlock().assign(JExpr._this().ref(joinStatus), JExpr.direct("status"));

    // declare and assign outgoing VectorContainer member
    JClass vectorContainerClass = cg.getModel().ref(VectorContainer.class);
    JVar outgoingVectorContainer = cg.clazz.field(JMod.NONE, vectorContainerClass, "outgoing");
    cg.getSetupBlock().assign(JExpr._this().ref(outgoingVectorContainer), JExpr.direct("outgoing"));

    // declare and assign incoming left RecordBatch member
    JClass recordBatchClass = cg.getModel().ref(RecordBatch.class);
    JVar incomingLeftRecordBatch = cg.clazz.field(JMod.NONE, recordBatchClass, "incomingLeft");
    cg.getSetupBlock().assign(JExpr._this().ref(incomingLeftRecordBatch), joinStatus.ref("left"));

    // declare and assign incoming right RecordBatch member
    JVar incomingRightRecordBatch = cg.clazz.field(JMod.NONE, recordBatchClass, "incomingRight");
    cg.getSetupBlock().assign(JExpr._this().ref(incomingRightRecordBatch), joinStatus.ref("right"));

    // declare 'incoming' member so VVReadExpr generated code can point to the left or right batch
    JVar incomingRecordBatch = cg.clazz.field(JMod.NONE, recordBatchClass, "incoming");

    // materialize value vector readers from join expression
    final LogicalExpression materializedLeftExpr = ExpressionTreeMaterializer.materialize(leftFieldExpr, left, collector);
    if (collector.hasErrors())
      throw new ClassTransformationException(String.format(
          "Failure while trying to materialize incoming left field.  Errors:\n %s.", collector.toErrorString()));

    final LogicalExpression materializedRightExpr = ExpressionTreeMaterializer.materialize(rightFieldExpr, right, collector);
    if (collector.hasErrors())
      throw new ClassTransformationException(String.format(
          "Failure while trying to materialize incoming right field.  Errors:\n %s.", collector.toErrorString()));

View Full Code Here

  }
 
  @Override
  protected void setupNewSchema() throws SchemaChangeException {
    container.clear();
    LogicalExpression filterExpression = popConfig.getExpr();
    final ErrorCollector collector = new ErrorCollectorImpl();
    final List<TransferPair> transfers = Lists.newArrayList();
    final CodeGenerator<Filterer> cg = new CodeGenerator<Filterer>(Filterer.TEMPLATE_DEFINITION, context.getFunctionRegistry());
   
    final LogicalExpression expr = ExpressionTreeMaterializer.materialize(filterExpression, incoming, collector);
    if(collector.hasErrors()){
      throw new SchemaChangeException(String.format("Failure while trying to materialize incoming schema.  Errors:\n %s.", collector.toErrorString()));
    }
   
    cg.addExpr(new ReturnValueExpression(expr));
View Full Code Here

    incoming.kill();
  }
 
  private void generatePartitionFunction() throws SchemaChangeException {

    LogicalExpression filterExpression = operator.getExpr();
    final ErrorCollector collector = new ErrorCollectorImpl();
    final CodeGenerator<Partitioner> cg = new CodeGenerator<Partitioner>(Partitioner.TEMPLATE_DEFINITION, context.getFunctionRegistry());

    final LogicalExpression expr = ExpressionTreeMaterializer.materialize(filterExpression, incoming, collector);
    if(collector.hasErrors()){
      throw new SchemaChangeException(String.format("Failure while trying to materialize incoming schema.  Errors:\n %s.", collector.toErrorString()));
    }

    cg.addExpr(new ReturnValueExpression(expr));
View Full Code Here

  }

  private void createPartitioner() throws SchemaChangeException {

    // set up partitioning function
    final LogicalExpression expr = operator.getExpr();
    final ErrorCollector collector = new ErrorCollectorImpl();
    final CodeGenerator<Partitioner> cg = new CodeGenerator<Partitioner>(Partitioner.TEMPLATE_DEFINITION,
                                                                         context.getFunctionRegistry());

    final LogicalExpression materializedExpr = ExpressionTreeMaterializer.materialize(expr, incoming, collector);
    if (collector.hasErrors()) {
      throw new SchemaChangeException(String.format(
          "Failure while trying to materialize incoming schema.  Errors:\n %s.",
          collector.toErrorString()));
    }
View Full Code Here

   
    final CodeGenerator<Projector> cg = new CodeGenerator<Projector>(Projector.TEMPLATE_DEFINITION, context.getFunctionRegistry());
   
    for(int i =0; i < exprs.size(); i++){
      final NamedExpression namedExpression = exprs.get(i);
      final LogicalExpression expr = ExpressionTreeMaterializer.materialize(namedExpression.getExpr(), incoming, collector);
      final MaterializedField outputField = MaterializedField.create(getRef(namedExpression), expr.getMajorType());
      if(collector.hasErrors()){
        throw new SchemaChangeException(String.format("Failure while trying to materialize incoming schema.  Errors:\n %s.", collector.toErrorString()));
      }
     
      // add value vector to transfer if direct reference and this is allowed, otherwise, add to evaluation stack.
View Full Code Here

    }

    private HoldingContainer visitValueVectorWriteExpression(ValueVectorWriteExpression e, ClassGenerator<?> generator) {

      final LogicalExpression child = e.getChild();
      final HoldingContainer inputContainer = child.accept(this, generator);
      final boolean complex = Types.isComplex(inputContainer.getMajorType());
      final boolean repeated = Types.isRepeated(inputContainer.getMajorType());

      JBlock block = generator.getEvalBlock();
      JExpression outIndex = generator.getMappingSet().getValueWriteIndex();
View Full Code Here

TOP

Related Classes of org.apache.drill.common.expression.LogicalExpression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.