/**
   * get a Target instance. A target consists of a reference name and an EvalNode corresponding to
   * the reference name. According to evaluation state, it returns different EvalNodes. If the
   * expression corresponding to the reference name is evaluated, it just returns {@link FieldEval}
   * (i.e., a column reference). Otherwise, it returns the original EvalNode of the expression.
   *
   * @param referenceName The reference name to get EvalNode
   * @param unevaluatedForm If TRUE, it always return the annotated EvalNode of the expression.
   * @return
   */
  public Target getTarget(String referenceName, boolean unevaluatedForm) {
    String normalized = referenceName;
    int refId = nameToIdMap.get(normalized);

    if (!unevaluatedForm
        && evaluationStateMap.containsKey(refId)
        && evaluationStateMap.get(refId)) {
      EvalNode evalNode = idToEvalMap.get(refId);

      // If the expression is already evaluated, it should use the FieldEval to access a field
      // value.
      // But, if this reference name is not primary name, it cannot use the reference name.
      // It changes the given reference name to the primary name.
      if (isEvaluated(normalized) && !isPrimaryName(refId, referenceName)) {
        return new Target(
            new FieldEval(getPrimaryName(refId), evalNode.getValueType()), referenceName);
      }

      EvalNode referredEval;
      if (evalNode.getType() == EvalType.CONST) {
        referredEval = evalNode;
      } else {
        referredEval = new FieldEval(idToNamesMap.get(refId).get(0), evalNode.getValueType());
      }
      return new Target(referredEval, referenceName);

    } else {
      if (idToEvalMap.containsKey(refId)) {
        return new Target(idToEvalMap.get(refId), referenceName);
      } else {
        return null;
      }
    }
  }
Example #2
0
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("\"Having\": {\"qual\": \"").append(qual.toString()).append("\",");
    sb.append("\n  \"out schema\": ").append(getOutSchema()).append(",");
    sb.append("\n  \"in schema\": ").append(getInSchema()).append("}");

    return sb.toString() + "\n" + getChild().toString();
  }
Example #3
0
  public Tuple next() throws IOException {
    Tuple previous;

    for (; ; ) {
      if (!outerIterator.hasNext() && !innerIterator.hasNext()) {
        if (end) {
          return null;
        }

        if (outerTuple == null) {
          outerTuple = leftChild.next();
        }
        if (innerTuple == null) {
          innerTuple = rightChild.next();
        }

        outerTupleSlots.clear();
        innerTupleSlots.clear();

        int cmp;
        while ((cmp = joincomparator.compare(outerTuple, innerTuple)) != 0) {
          if (cmp > 0) {
            innerTuple = rightChild.next();
          } else if (cmp < 0) {
            outerTuple = leftChild.next();
          }
          if (innerTuple == null || outerTuple == null) {
            return null;
          }
        }

        try {
          previous = outerTuple.clone();
          do {
            outerTupleSlots.add(outerTuple.clone());
            outerTuple = leftChild.next();
            if (outerTuple == null) {
              end = true;
              break;
            }
          } while (tupleComparator[0].compare(previous, outerTuple) == 0);
          outerIterator = outerTupleSlots.iterator();
          outerNext = outerIterator.next();

          previous = innerTuple.clone();
          do {
            innerTupleSlots.add(innerTuple.clone());
            innerTuple = rightChild.next();
            if (innerTuple == null) {
              end = true;
              break;
            }
          } while (tupleComparator[1].compare(previous, innerTuple) == 0);
          innerIterator = innerTupleSlots.iterator();
        } catch (CloneNotSupportedException e) {

        }
      }

      if (!innerIterator.hasNext()) {
        outerNext = outerIterator.next();
        innerIterator = innerTupleSlots.iterator();
      }

      frameTuple.set(outerNext, innerIterator.next());
      joinQual.eval(qualCtx, inSchema, frameTuple);
      if (joinQual.terminate(qualCtx).asBool()) {
        projector.eval(evalContexts, frameTuple);
        projector.terminate(evalContexts, outTuple);
        return outTuple;
      }
    }
  }
Example #4
0
 @Override
 public PlanString getPlanString() {
   return new PlanString(this).appendTitle(" (").appendTitle(qual.toString()).appendTitle(")");
 }