Package org.apache.drill.common.expression

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


    g.setMappingSet(mainMapping);

    for (Ordering od : orderings) {
      // first, we rewrite the evaluation stack for each side of the comparison.
      ErrorCollector collector = new ErrorCollectorImpl();
      final LogicalExpression expr = ExpressionTreeMaterializer.materialize(od.getExpr(), batch, collector, context.getFunctionRegistry());
      if (collector.hasErrors()) {
        throw new SchemaChangeException("Failure while materializing expression. " + collector.toErrorString());
      }
      g.setMappingSet(leftMapping);
      HoldingContainer left = g.addExpr(expr, false);
      g.setMappingSet(rightMapping);
      HoldingContainer right = g.addExpr(expr, false);
      g.setMappingSet(mainMapping);

      // next we wrap the two comparison sides and add the expression block for the comparison.
      LogicalExpression fh = FunctionGenerationHelper.getComparator(left, right, context.getFunctionRegistry());
      HoldingContainer out = g.addExpr(fh, false);
      JConditional jc = g.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)));

      if (od.getDirection() == Direction.ASCENDING) {
        jc._then()._return(out.getValue());
View Full Code Here


      withins.add(new NamedExpression(fr, fr));
    }

    for (AggregateCall aggCall : window.getAggregateCalls(this)) {
      FieldReference ref = new FieldReference(aggCall.getName());
      LogicalExpression expr = toDrill(aggCall, childFields);
      aggs.add(new NamedExpression(expr, ref));
    }

    WindowPOP windowPOP = new WindowPOP(
        childPOP,
View Full Code Here

    // for count(1).
    if (args.isEmpty()) {
      args.add(new ValueExpressions.LongExpression(1l));
    }
    LogicalExpression expr = new FunctionCall(call.getAggregation().getName().toLowerCase(), args, ExpressionPosition.UNKNOWN);
    return expr;
  }
View Full Code Here

              incoming.getValueVectorId(
                  popConfig.getColumn()).getFieldIds()[0]).getValueClass(),
          incoming.getValueVectorId(popConfig.getColumn()).getFieldIds()).getValueVector());

    NamedExpression namedExpression = new NamedExpression(popConfig.getColumn(), new FieldReference(popConfig.getColumn()));
    LogicalExpression expr = ExpressionTreeMaterializer.materialize(namedExpression.getExpr(), incoming, collector, context.getFunctionRegistry(), true);
    ValueVectorReadExpression vectorRead = (ValueVectorReadExpression) expr;
    TypedFieldId id = vectorRead.getFieldId();
    Preconditions.checkNotNull(incoming);

    TransferPair tp = null;
    if (flattenField instanceof RepeatedMapVector) {
      tp = ((RepeatedMapVector)flattenField).getTransferPairToSingleMap();
    } else {
      ValueVector vvIn = flattenField.getAccessor().getAllChildValues();
      tp = vvIn.getTransferPair();
    }
    transfers.add(tp);
    container.add(tp.getTo());
    transferFieldIds.add(vectorRead.getFieldId().getFieldIds()[0]);

    logger.debug("Added transfer for project expression.");

    ClassifierResult result = new ClassifierResult();

    for (int i = 0; i < exprs.size(); i++) {
      namedExpression = exprs.get(i);
      result.clear();

      String outputName = getRef(namedExpression).getRootSegment().getPath();
      if (result != null && result.outputNames != null && result.outputNames.size() > 0) {
        for (int j = 0; j < result.outputNames.size(); j++) {
          if (!result.outputNames.get(j).equals(EMPTY_STRING)) {
            outputName = result.outputNames.get(j);
            break;
          }
        }
      }

      expr = ExpressionTreeMaterializer.materialize(namedExpression.getExpr(), incoming, collector, context.getFunctionRegistry(), true);
      final MaterializedField outputField = MaterializedField.create(outputName, expr.getMajorType());
      if (collector.hasErrors()) {
        throw new SchemaChangeException(String.format("Failure while trying to materialize incoming schema.  Errors:\n %s.", collector.toErrorString()));
      }
      if (expr instanceof DrillFuncHolderExpr &&
          ((DrillFuncHolderExpr) expr).isComplexWriterFuncHolder())  {
View Full Code Here

    boolean nextLeftIndexDeclared = false;

    cg.setMappingSet(compareLeftMapping);

    for (JoinCondition condition : conditions) {
      final LogicalExpression leftFieldExpr = condition.getLeft();

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

      // generate compareNextLeftKey()
      ////////////////////////////////
      cg.setMappingSet(compareLeftMapping);
      cg.getSetupBlock().assign(JExpr._this().ref(incomingRecordBatch), JExpr._this().ref(incomingLeftRecordBatch));

      if (!nextLeftIndexDeclared) {
        // int nextLeftIndex = leftIndex + 1;
        cg.getEvalBlock().decl(JType.parse(cg.getModel(), "int"), "nextLeftIndex", JExpr.direct("leftIndex").plus(JExpr.lit(1)));
        nextLeftIndexDeclared = true;
      }
      // check if the next key is in this batch
      cg.getEvalBlock()._if(joinStatus.invoke("isNextLeftPositionInCurrentBatch").eq(JExpr.lit(false)))
                       ._then()
                         ._return(JExpr.lit(-1));

      // generate VV read expressions
      ClassGenerator.HoldingContainer compareThisLeftExprHolder = cg.addExpr(materializedLeftExpr, false);
      cg.setMappingSet(compareNextLeftMapping); // change mapping from 'leftIndex' to 'nextLeftIndex'
      ClassGenerator.HoldingContainer compareNextLeftExprHolder = cg.addExpr(materializedLeftExpr, false);

      if (compareThisLeftExprHolder.isOptional()) {
        // handle null == null
        cg.getEvalBlock()._if(compareThisLeftExprHolder.getIsSet().eq(JExpr.lit(0))
                              .cand(compareNextLeftExprHolder.getIsSet().eq(JExpr.lit(0))))
                         ._then()
                           ._return(JExpr.lit(0));

        // handle null == !null
        cg.getEvalBlock()._if(compareThisLeftExprHolder.getIsSet().eq(JExpr.lit(0))
                              .cor(compareNextLeftExprHolder.getIsSet().eq(JExpr.lit(0))))
                         ._then()
                           ._return(JExpr.lit(1));
      }

      // check value equality

      LogicalExpression gh = FunctionGenerationHelper.getComparator(compareThisLeftExprHolder,
        compareNextLeftExprHolder,
        context.getFunctionRegistry());
      HoldingContainer out = cg.addExpr(gh, false);

      //If not 0, it means not equal. We return this out value.
View Full Code Here

    cg.setMappingSet(compareMapping);
    if (status.getLastRight() != IterOutcome.NONE) {

      for (JoinCondition condition : conditions) {
        final LogicalExpression leftFieldExpr = condition.getLeft();
        final LogicalExpression rightFieldExpr = condition.getRight();

        // materialize value vector readers from join expression
        LogicalExpression materializedLeftExpr;
        if (worker == null || status.isLeftPositionAllowed()) {
          materializedLeftExpr = ExpressionTreeMaterializer.materialize(leftFieldExpr, left, collector, context.getFunctionRegistry());
        } else {
          materializedLeftExpr = new TypedNullConstant(Types.optional(MinorType.INT));
        }
        if (collector.hasErrors()) {
          throw new ClassTransformationException(String.format(
              "Failure while trying to materialize incoming left field.  Errors:\n %s.", collector.toErrorString()));
        }

        LogicalExpression materializedRightExpr;
        if (worker == null || status.isRightPositionAllowed()) {
          materializedRightExpr = ExpressionTreeMaterializer.materialize(rightFieldExpr, right, collector, context.getFunctionRegistry());
        } else {
          materializedRightExpr = new TypedNullConstant(Types.optional(MinorType.INT));
        }
        if (collector.hasErrors()) {
          throw new ClassTransformationException(String.format(
              "Failure while trying to materialize incoming right field.  Errors:\n %s.", collector.toErrorString()));
        }

        // generate compare()
        ////////////////////////
        cg.setMappingSet(compareMapping);
        cg.getSetupBlock().assign(JExpr._this().ref(incomingRecordBatch), JExpr._this().ref(incomingLeftRecordBatch));
        ClassGenerator.HoldingContainer compareLeftExprHolder = cg.addExpr(materializedLeftExpr, false);

        cg.setMappingSet(compareRightMapping);
        cg.getSetupBlock().assign(JExpr._this().ref(incomingRecordBatch), JExpr._this().ref(incomingRightRecordBatch));
        ClassGenerator.HoldingContainer compareRightExprHolder = cg.addExpr(materializedRightExpr, false);

        LogicalExpression fh = FunctionGenerationHelper.getComparator(compareLeftExprHolder,
          compareRightExprHolder,
          context.getFunctionRegistry());
        HoldingContainer out = cg.addExpr(fh, false);

        // If not 0, it means not equal. We return this out value.
View Full Code Here

    ErrorCollector collector = new ErrorCollectorImpl();

    for (int i = 0; i < configLength; i++) {
      NamedExpression ne = popConfig.getAggregations()[i];
      final LogicalExpression expr = ExpressionTreeMaterializer.materialize(ne.getExpr(), incoming, collector, context.getFunctionRegistry());
      if (expr == null) {
        continue;
      }

      final MaterializedField outputField = MaterializedField.create(ne.getRef(), expr.getMajorType());
      container.addOrGet(outputField);
      TypedFieldId id = container.getValueVectorId(outputField.getPath());
      assert id != null : "Got null TypedFieldId";
      valueExprs.add(new ValueVectorWriteExpression(id, expr, true));
    }

    int j = 0;
    LogicalExpression[] windowExprs = new LogicalExpression[incoming.getSchema().getFieldCount()];
    // TODO: Should transfer all existing columns instead of copy. Currently this is not easily doable because
    // we are not processing one entire batch in one iteration, so cannot simply transfer.
    for (VectorWrapper wrapper : incoming) {
      ValueVector vv = wrapper.isHyper() ? wrapper.getValueVectors()[0] : wrapper.getValueVector();
      container.addOrGet(vv.getField());
      TypedFieldId id = container.getValueVectorId(vv.getField().getPath());
      final LogicalExpression expr = ExpressionTreeMaterializer.materialize(
          new ValueVectorReadExpression(new TypedFieldId(vv.getField().getType(), wrapper.isHyper(), j)),
          incoming,
          collector,
          context.getFunctionRegistry());
      windowExprs[j] = new ValueVectorWriteExpression(id, expr, true);
      j++;
    }

    for (int i = 0; i < keyExprs.length; i++) {
      NamedExpression ne = popConfig.getWithins()[i];

      final LogicalExpression expr = ExpressionTreeMaterializer.materialize(ne.getExpr(), incoming, collector, context.getFunctionRegistry());
      if (expr == null) {
        continue;
      }

      keyExprs[i] = expr;
View Full Code Here

      cg.setMappingSet(ISA_B1);
      ClassGenerator.HoldingContainer first = cg.addExpr(expr, false);
      cg.setMappingSet(ISA_B2);
      ClassGenerator.HoldingContainer second = cg.addExpr(expr, false);

      LogicalExpression fh = FunctionGenerationHelper.getComparator(first, second, context.getFunctionRegistry());
      ClassGenerator.HoldingContainer out = cg.addExpr(fh, false);
      cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)))._then()._return(JExpr.FALSE);
    }
    cg.getEvalBlock()._return(JExpr.TRUE);
  }
View Full Code Here

      cg.setMappingSet(IS_SAME_I1);
      ClassGenerator.HoldingContainer first = cg.addExpr(expr, false);
      cg.setMappingSet(IS_SAME_I2);
      ClassGenerator.HoldingContainer second = cg.addExpr(expr, false);

      LogicalExpression fh = FunctionGenerationHelper.getComparator(first, second, context.getFunctionRegistry());
      ClassGenerator.HoldingContainer out = cg.addExpr(fh, false);
      cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)))._then()._return(JExpr.FALSE);
    }
    cg.getEvalBlock()._return(JExpr.TRUE);
  }
View Full Code Here

    final ClassGenerator<SampleCopier> cg = CodeGenerator.getRoot(SampleCopier.TEMPLATE_DEFINITION,
        context.getFunctionRegistry());

    int i = 0;
    for (Ordering od : orderings) {
      final LogicalExpression expr = ExpressionTreeMaterializer.materialize(od.getExpr(), incoming, collector, context.getFunctionRegistry());
      SchemaPath schemaPath = SchemaPath.getSimplePath("f" + i++);
      TypeProtos.MajorType.Builder builder = TypeProtos.MajorType.newBuilder().mergeFrom(expr.getMajorType())
          .clearMode().setMode(TypeProtos.DataMode.REQUIRED);
      TypeProtos.MajorType newType = builder.build();
      MaterializedField outputField = MaterializedField.create(schemaPath, newType);
      if (collector.hasErrors()) {
        throw new SchemaChangeException(String.format(
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.