Package org.apache.drill.common.expression

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


      }
    }
   
    for (Pair<RexNode, String> pair : projects()) {
      if (! StarColumnHelper.subsumeRegColumn(starColPrefixes, pair.right)) {
        LogicalExpression expr = DrillOptiq.toDrill(context, getChild(), pair.left);
        expressions.add(new NamedExpression(expr, FieldReference.getWithQuotedRef(pair.right)));
      }
    }
    return expressions;
  }
View Full Code Here


    parse_return ret = parser.parse();
    return ret.e;
  }

  private String getExpressionCode(String expression, RecordBatch batch) throws Exception {
    LogicalExpression expr = parseExpr(expression);
    ErrorCollector error = new ErrorCollectorImpl();
    LogicalExpression materializedExpr = ExpressionTreeMaterializer.materialize(expr, batch, error, registry);
    if (error.getErrorCount() != 0) {
      logger.error("Failure while materializing expression [{}].  Errors: {}", expression, error);
      assertEquals(0, error.getErrorCount());
    }

    ClassGenerator<Projector> cg = CodeGenerator.get(Projector.TEMPLATE_DEFINITION, new FunctionImplementationRegistry(DrillConfig.create())).getRoot();
    cg.addExpr(new ValueVectorWriteExpression(new TypedFieldId(materializedExpr.getMajorType(), -1), materializedExpr));
    return cg.getCodeGenerator().generateAndGet();
  }
View Full Code Here

    return COMPARE_FUNCTIONS_TRANSPOSE_MAP.keySet().contains(functionName);
  }

  public static CompareFunctionsProcessor process(FunctionCall call, boolean nullComparatorSupported) {
    String functionName = call.getName();
    LogicalExpression nameArg = call.args.get(0);
    LogicalExpression valueArg = call.args.size() == 2 ? call.args.get(1) : null;
    CompareFunctionsProcessor evaluator = new CompareFunctionsProcessor(functionName);

    if (valueArg != null) { // binary function
      if (VALUE_EXPRESSION_CLASSES.contains(nameArg.getClass())) {
        LogicalExpression swapArg = valueArg;
        valueArg = nameArg;
        nameArg = swapArg;
        evaluator.functionName = COMPARE_FUNCTIONS_TRANSPOSE_MAP.get(functionName);
      }
      evaluator.success = nameArg.accept(evaluator, valueArg);
View Full Code Here

       * this flag to not do a re-processing of the rule on the already transformed call.
       */
      return;
    }

    LogicalExpression conditionExp = DrillOptiq.toDrill(new DrillParseContext(), scan, condition);
    HBaseFilterBuilder hbaseFilterBuilder = new HBaseFilterBuilder(groupScan, conditionExp);
    HBaseScanSpec newScanSpec = hbaseFilterBuilder.parseTree();
    if (newScanSpec == null) {
      return; //no filter pushdown ==> No transformation.
    }
View Full Code Here

  @Override
  public Boolean visitFunctionHolderExpression(FunctionHolderExpression holder, ErrorCollector errors) {
    if (holder.isAggregating()) {
      for (int i = 0; i < holder.args.size(); i++) {
        LogicalExpression e = holder.args.get(i);
        if(e.accept(this, errors)) {
          errors.addGeneralError(e.getPosition(),
            String.format("Aggregating function call %s includes nested aggregations at arguments number %d. " +
              "This isn't allowed.", holder.getName(), i));
        }
      }
      return true;
    } else {
      for (LogicalExpression e : holder.args) {
        if (e.accept(this, errors)) {
          return true;
        }
      }
      return false;
    }
View Full Code Here

  @Override
  public LogicalExpression visitFunctionHolderExpression(FunctionHolderExpression holder, Void value) throws RuntimeException {
    List<LogicalExpression> args = Lists.newArrayList();
    for (int i = 0; i < holder.args.size(); ++i) {
      LogicalExpression newExpr = holder.args.get(i).accept(this, value);
      assert newExpr != null;
      args.add(newExpr);
    }

    //replace with a new function call, since its argument could be changed.
View Full Code Here

  }


  @Override
  public LogicalExpression visitIfExpression(IfExpression ifExpr, Void value) throws RuntimeException{
    LogicalExpression newElseExpr = ifExpr.elseExpression.accept(this, value);
    IfCondition conditions = ifExpr.ifCondition;

    LogicalExpression newCondition = conditions.condition.accept(this, value);
    LogicalExpression newExpr = conditions.expression.accept(this, value);
    conditions = new IfExpression.IfCondition(newCondition, newExpr);

    return IfExpression.newBuilder().setElse(newElseExpr).setIfCondition(conditions).build();
  }
View Full Code Here

    }

    for (Ord<AggregateCall> aggCall : Ord.zip(aggCalls)) {
      int aggExprOrdinal = groupSet.cardinality() + aggCall.i;
      FieldReference ref = new FieldReference(fields.get(aggExprOrdinal));
      LogicalExpression expr = toDrill(aggCall.e, childFields);
      NamedExpression ne = new NamedExpression(expr, ref);
      aggExprs.add(ne);

      if (getOperatorPhase() == OperatorPhase.PHASE_1of2) {
        if (aggCall.e.getAggregation().getName().equals("COUNT")) {
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

    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

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.