/**
   * Determines if a filter condition is a simple one and returns the parameters corresponding to
   * the simple filters.
   *
   * @param calcRel original CalcRel
   * @param filterExprs filter expression being analyzed
   * @param filterList returns the list of filter ordinals in the simple expression
   * @param literals returns the list of literals to be used in the simple comparisons
   * @param op returns the operator to be used in the simple comparison
   * @return true if the filter condition is simple
   */
  private boolean isConditionSimple(
      CalcRel calcRel,
      RexNode filterExprs,
      List<Integer> filterList,
      List<RexLiteral> literals,
      List<CompOperatorEnum> op) {
    SargFactory sargFactory = new SargFactory(calcRel.getCluster().getRexBuilder());
    SargRexAnalyzer rexAnalyzer = sargFactory.newRexAnalyzer(true);
    List<SargBinding> sargBindingList = rexAnalyzer.analyzeAll(filterExprs);

    // Currently, it's all or nothing.  So, if there are filters rejected
    // by the analyzer, we can't process a subset using the reshape
    // exec stream
    if (rexAnalyzer.getNonSargFilterRexNode() != null) {
      return false;
    }

    List<RexInputRef> filterCols = new ArrayList<RexInputRef>();
    List<RexNode> filterOperands = new ArrayList<RexNode>();
    if (FennelRelUtil.extractSimplePredicates(sargBindingList, filterCols, filterOperands, op)) {
      for (RexInputRef filterCol : filterCols) {
        filterList.add(filterCol.getIndex());
      }
      for (RexNode operand : filterOperands) {
        literals.add((RexLiteral) operand);
      }
      return true;
    } else {
      return false;
    }
  }
 private void reduceNotNullableFilter(
     RelOptRuleCall call, FilterRel filter, RexCall rexCall, boolean reverse) {
   // If the expression is a IS [NOT] NULL on a non-nullable
   // column, then we can either remove the filter or replace
   // it with an EmptyRel.
   SqlOperator op = rexCall.getOperator();
   boolean alwaysTrue;
   if (op == SqlStdOperatorTable.isNullOperator
       || op == SqlStdOperatorTable.isUnknownOperator) {
     alwaysTrue = false;
   } else if (op == SqlStdOperatorTable.isNotNullOperator) {
     alwaysTrue = true;
   } else {
     return;
   }
   if (reverse) {
     alwaysTrue = !alwaysTrue;
   }
   RexNode operand = rexCall.getOperands()[0];
   if (operand instanceof RexInputRef) {
     RexInputRef inputRef = (RexInputRef) operand;
     if (!inputRef.getType().isNullable()) {
       if (alwaysTrue) {
         call.transformTo(filter.getChild());
       } else {
         call.transformTo(new EmptyRel(filter.getCluster(), filter.getRowType()));
       }
     }
   }
 }
Beispiel #3
0
 public Void visitInputRef(RexInputRef inputRef) {
   super.visitInputRef(inputRef);
   if (inputRef.getIndex() >= inputRowType.getFieldCount()) {
     throw new IllegalForwardRefException();
   }
   return null;
 }
Beispiel #4
0
 /**
  * Returns whether the leading edge of a given array of expressions is wholly {@link RexInputRef}
  * objects with types corresponding to the underlying datatype.
  */
 public static boolean containIdentity(RexNode[] exprs, RelDataType rowType, boolean fail) {
   final RelDataTypeField[] fields = rowType.getFields();
   if (exprs.length < fields.length) {
     assert !fail : "exprs/rowType length mismatch";
     return false;
   }
   for (int i = 0; i < fields.length; i++) {
     if (!(exprs[i] instanceof RexInputRef)) {
       assert !fail : "expr[" + i + "] is not a RexInputRef";
       return false;
     }
     RexInputRef inputRef = (RexInputRef) exprs[i];
     if (inputRef.getIndex() != i) {
       assert !fail : "expr[" + i + "] has ordinal " + inputRef.getIndex();
       return false;
     }
     if (!RelOptUtil.eq("type1", exprs[i].getType(), "type2", fields[i].getType(), fail)) {
       return false;
     }
   }
   return true;
 }
Beispiel #5
0
  public JavaRel findRel(JavaRel rel, RexNode expression) {
    if (expression instanceof RexInputRef) {
      RexInputRef variable = (RexInputRef) expression;

      // REVIEW jvs 30-May-2005:  What's up with this?  The "&& false"
      // should have at least a comment!
      if ((rel instanceof JoinRelBase) && false) {
        return (JavaRel) findInputRel(rel, variable.getIndex());
      } else {
        return (JavaRel) rel.getInput(variable.getIndex());
      }
    } else if (expression instanceof RexFieldAccess) {
      RexFieldAccess fieldAccess = (RexFieldAccess) expression;
      String fieldName = fieldAccess.getName();
      RexNode refExp = fieldAccess.getReferenceExpr();
      JavaRel rel2 = findRel(rel, refExp); // recursive
      if (rel2 == null) {
        return null;
      }
      return implementFieldAccess(rel2, fieldName);
    } else {
      return null;
    }
  }
Beispiel #6
0
 public Void visitInputRef(RexInputRef inputRef) {
   refCounts[inputRef.getIndex()]++;
   return null;
 }
 protected Integer mapFieldRef(RexNode exp, List<String> origFieldName, RelDataType rowType) {
   RexInputRef fieldAccess = (RexInputRef) exp;
   origFieldName.add(rowType.getFields()[fieldAccess.getIndex()].getName());
   return fieldAccess.getIndex();
 }