Beispiel #1
0
 /**
  * Creates an expression which references the <i> fieldOrdinal</i><sup>th</sup> field of the
  * <i>ordinal</i><sup>th</sup> input.
  *
  * <p>(We can potentially optimize the generation process, so we can access field values without
  * actually instantiating the row.)
  */
 public Expression translateInputField(JavaRel rel, int ordinal, int fieldOrdinal) {
   assert ordinal >= 0;
   assert ordinal < rel.getInputs().size();
   assert fieldOrdinal >= 0;
   assert fieldOrdinal < rel.getInput(ordinal).getRowType().getFieldList().size();
   RelDataType rowType = rel.getRowType();
   final RelDataTypeField[] fields = rowType.getFields();
   final int fieldIndex = computeFieldOffset(rel, ordinal) + fieldOrdinal;
   assert fieldIndex >= 0;
   assert fieldIndex < fields.length;
   final RexNode expr = rexBuilder.makeInputRef(fields[fieldIndex].getType(), fieldIndex);
   return translate(rel, expr);
 }
Beispiel #2
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;
    }
  }