예제 #1
0
파일: RexUtil.java 프로젝트: kunlqt/optiq
 public Void visitCall(RexCall call) {
   final RexNode[] operands = call.getOperands();
   for (int i = 0; i < operands.length; i++) {
     RexNode operand = operands[i];
     operand.accept(this);
   }
   return null;
 }
예제 #2
0
파일: RexUtil.java 프로젝트: kunlqt/optiq
 /**
  * Returns whether a list of expressions contains complex expressions, that is, a call whose
  * arguments are not {@link RexVariable} (or a subtype such as {@link RexInputRef}) or {@link
  * RexLiteral}.
  */
 public static boolean containComplexExprs(List<RexNode> exprs) {
   for (RexNode expr : exprs) {
     if (expr instanceof RexCall) {
       RexCall rexCall = (RexCall) expr;
       final RexNode[] operands = rexCall.getOperands();
       for (int j = 0; j < operands.length; j++) {
         RexNode operand = operands[j];
         if (!isAtomic(operand)) {
           return true;
         }
       }
     }
   }
   return false;
 }
예제 #3
0
파일: RexUtil.java 프로젝트: kunlqt/optiq
 public RexNode visitCall(RexCall call) {
   List<RexNode> normalizedOperands = new ArrayList<RexNode>();
   int diffCount = 0;
   for (RexNode operand : call.getOperands()) {
     operand.accept(this);
     final RexNode normalizedOperand = lookup(operand);
     normalizedOperands.add(normalizedOperand);
     if (normalizedOperand != operand) {
       ++diffCount;
     }
   }
   if (diffCount > 0) {
     call = call.clone(call.getType(), normalizedOperands);
   }
   return register(call);
 }
예제 #4
0
파일: RexUtil.java 프로젝트: kunlqt/optiq
 /**
  * Returns whether an array of exp contains aggregate function calls whose arguments are not
  * {@link RexInputRef}.s
  *
  * @param exprs Expressions
  * @param fail Whether to assert if there is such a function call
  */
 static boolean containNonTrivialAggs(RexNode[] exprs, boolean fail) {
   for (int i = 0; i < exprs.length; i++) {
     RexNode expr = exprs[i];
     if (expr instanceof RexCall) {
       RexCall rexCall = (RexCall) expr;
       if (rexCall.getOperator() instanceof SqlAggFunction) {
         final RexNode[] operands = rexCall.getOperands();
         for (int j = 0; j < operands.length; j++) {
           RexNode operand = operands[j];
           if (!(operand instanceof RexLocalRef)) {
             assert !fail : "contains non trivial agg";
             return true;
           }
         }
       }
     }
   }
   return false;
 }
  /**
   * Determines if a projection is simple.
   *
   * @param calcRel CalcRel containing the projection
   * @param projOrdinals if the projection is simple, returns the ordinals of the projection inputs
   * @return rowtype corresponding to the projection, provided it is simple; otherwise null is
   *     returned
   */
  private RelDataType isProjectSimple(CalcRel calcRel, List<Integer> projOrdinals) {
    // Loop through projection expressions.  If we find a non-simple
    // projection expression, simply return.
    RexProgram program = calcRel.getProgram();
    List<RexLocalRef> projList = program.getProjectList();
    int nProjExprs = projList.size();
    RelDataType[] types = new RelDataType[nProjExprs];
    String[] fieldNames = new String[nProjExprs];
    RelDataTypeField[] projFields = calcRel.getRowType().getFields();

    for (int i = 0; i < nProjExprs; i++) {
      RexNode projExpr = program.expandLocalRef(projList.get(i));
      if (projExpr instanceof RexInputRef) {
        projOrdinals.add(((RexInputRef) projExpr).getIndex());
        types[i] = projExpr.getType();
        fieldNames[i] = projFields[i].getName();
        continue;
      } else if (!(projExpr instanceof RexCall)) {
        return null;
      }

      RexCall rexCall = (RexCall) projExpr;
      if (rexCall.getOperator() != SqlStdOperatorTable.castFunc) {
        return null;
      }
      RexNode castOperand = rexCall.getOperands()[0];
      if (!(castOperand instanceof RexInputRef)) {
        return null;
      }
      RelDataType castType = projExpr.getType();
      RelDataType origType = castOperand.getType();
      if (isCastSimple(origType, castType)) {
        projOrdinals.add(((RexInputRef) castOperand).getIndex());
        types[i] = castType;
        fieldNames[i] = projFields[i].getName();
      } else {
        return null;
      }
    }

    // return the rowtype corresponding to the output of the projection
    return calcRel.getCluster().getTypeFactory().createStructType(types, fieldNames);
  }