Пример #1
0
  public static Collection<Quad> collectQuads(Op op, Collection<Quad> result) {
    if (op instanceof OpLeftJoin) {
      OpLeftJoin x = (OpLeftJoin) op;
      collectQuads(x.getLeft(), result);
      collectQuads(x.getRight(), result);
    } else if (op instanceof OpFilter) {
      OpFilter x = (OpFilter) op;
      collectQuads(x.getSubOp(), result);
    } else if (op instanceof OpJoin) {
      OpJoin x = (OpJoin) op;

      collectQuads(x.getLeft(), result);
      collectQuads(x.getRight(), result);
    } else if (op instanceof OpUnion) {
      System.out.println(
          "Warning: Collecting expressions from unions. Since the same vars may appear within different (parts of) unions, it may be ambiguous to which part the expression refers.");

      OpUnion x = (OpUnion) op;

      collectQuads(x.getLeft(), result);
      collectQuads(x.getRight(), result);
    } else if (op instanceof OpQuadPattern) {
      OpQuadPattern x = (OpQuadPattern) op;
      result.addAll(x.getPattern().getList());
    } else if (op instanceof OpSequence) {
      OpSequence x = (OpSequence) op;
      for (Op element : x.getElements()) {
        collectQuads(element, result);
      }
    } else {
      throw new NotImplementedException("Encountered class: " + op);
    }

    return result;
  }
  @Override
  public Op transform(OpLeftJoin opLeftJoin, Op opLeft, Op opRight) {
    // Test whether we can do an indexed substitute into the right if possible.
    boolean canDoLinear = LeftJoinClassifier.isLinear(opLeftJoin);

    if (canDoLinear) {
      // Pass left into right for substitution before right side evaluation.
      // In an indexed left join, the LHS bindings are visible to the
      // RHS execution so the expression is evaluated by moving it to be
      // a filter over the RHS pattern.

      if (opLeftJoin.getExprs() != null) opRight = OpFilter.filter(opLeftJoin.getExprs(), opRight);
      return new OpConditional(opLeft, opRight);
    }

    // Not index-able.
    return super.transform(opLeftJoin, opLeft, opRight);
  }
Пример #3
0
  public static ExprList collectExprs(Op op, ExprList result) {
    if (op instanceof OpLeftJoin) {
      OpLeftJoin x = (OpLeftJoin) op;

      if (x.getExprs() != null) {
        result.addAll(x.getExprs());
      }

      collectExprs(x.getLeft(), result);
      collectExprs(x.getRight(), result);
    } else if (op instanceof OpFilter) {
      OpFilter x = (OpFilter) op;
      result.addAll(x.getExprs());
      collectExprs(x.getSubOp(), result);
    } else if (op instanceof OpJoin) {
      OpJoin x = (OpJoin) op;

      collectExprs(x.getLeft(), result);
      collectExprs(x.getRight(), result);
    } else if (op instanceof OpUnion) {
      System.out.println(
          "Warning: Collecting expressions from unions. Since the same vars may appear within different (parts of) unions, it may be ambiguous to which part the expression refers.");

      OpUnion x = (OpUnion) op;

      collectExprs(x.getLeft(), result);
      collectExprs(x.getRight(), result);
    } else if (op instanceof OpQuadPattern) {

    } else if (op instanceof OpSequence) {
      OpSequence x = (OpSequence) op;
      for (Op element : x.getElements()) {
        collectExprs(element, result);
      }
    } else {
      throw new RuntimeException("Not implemented. Type: " + op.getClass());
    }

    return result;
  }
Пример #4
0
 public void visit(OpLeftJoin opLeftJoin) {
   System.out.println(opLeftJoin.toString());
 }
 public void visit(OpLeftJoin opLeftJoin) {
   Table left = eval(opLeftJoin.getLeft());
   Table right = eval(opLeftJoin.getRight());
   Table table = evaluator.leftJoin(left, right, opLeftJoin.getExprs());
   push(table);
 }