private void parseCorrelTable(RelNode relNode, Result x) { for (CorrelationId id : relNode.getVariablesSet()) { correlTableMap.put(id, x.qualifiedContext()); } } }
for (final CorrelationId correlation : rel.getVariablesSet()) { rel.accept( new CorrelationReferenceFinder() {
private void parseCorrelTable(RelNode relNode, Result x) { for (CorrelationId id : relNode.getVariablesSet()) { correlTableMap.put(id, x.qualifiedContext()); } }
private void parseCorrelTable(RelNode relNode, Result x) { for (CorrelationId id : relNode.getVariablesSet()) { correlTableMap.put(id, x.qualifiedContext()); } }
public void visit( RelNode p, int ordinal, RelNode parent) { super.visit(p, ordinal, parent); p.collectVariablesUsed(variables); // Important! Remove stopped variables AFTER we visit children // (which what super.visit() does) variables.removeAll(p.getVariablesSet()); } }
public void visit( RelNode p, int ordinal, RelNode parent) { super.visit(p, ordinal, parent); p.collectVariablesUsed(variables); // Important! Remove stopped variables AFTER we visit children // (which what super.visit() does) variables.removeAll(p.getVariablesSet()); } }
public Set<CorrelationId> correlationIds() { final ImmutableSet.Builder<CorrelationId> builder = ImmutableSet.builder(); for (RelNode r : stack) { builder.addAll(r.getVariablesSet()); } return builder.build(); }
public Set<CorrelationId> correlationIds() { final ImmutableSet.Builder<CorrelationId> builder = ImmutableSet.builder(); for (RelNode r : stack) { builder.addAll(r.getVariablesSet()); } return builder.build(); }
@Override public RelNode visit(RelNode other) { other.collectVariablesUsed(vuv.variables); other.accept(vuv); RelNode result = super.visit(other); // Important! Remove stopped variables AFTER we visit // children. (which what super.visit() does) vuv.variables.removeAll(other.getVariablesSet()); return result; } }
@Override public RelNode visit(RelNode other) { other.collectVariablesUsed(vuv.variables); other.accept(vuv); RelNode result = super.visit(other); // Important! Remove stopped variables AFTER we visit // children. (which what super.visit() does) vuv.variables.removeAll(other.getVariablesSet()); return result; } }
@Override public RelNode visit(LogicalFilter filter) { final boolean hasSubQuery = RexUtil.SubQueryFinder.find(filter.getCondition()) != null; try { if (!corNodeStack.isEmpty()) { mapSubQueryNodeToCorSet.put(filter, corNodeStack.peek().getVariablesSet()); } if (hasSubQuery) { corNodeStack.push(filter); } checkCorCondition(filter); filter.getCondition().accept(rexVisitor(filter)); for (CorrelationId correlationId : filter.getVariablesSet()) { mapCorToCorRel.put(correlationId, filter); } } finally { if (hasSubQuery) { corNodeStack.pop(); } } return super.visit(filter); }
protected TrimResult result(RelNode r, final Mapping mapping) { final RexBuilder rexBuilder = relBuilder.getRexBuilder(); for (final CorrelationId correlation : r.getVariablesSet()) { r = r.accept( new CorrelationReferenceFinder() { protected RexNode handle(RexFieldAccess fieldAccess) { final RexCorrelVariable v = (RexCorrelVariable) fieldAccess.getReferenceExpr(); if (v.id.equals(correlation) && v.getType().getFieldCount() == mapping.getSourceCount()) { final int old = fieldAccess.getField().getIndex(); final int new_ = mapping.getTarget(old); final RelDataTypeFactory.Builder typeBuilder = relBuilder.getTypeFactory().builder(); for (int target : Util.range(mapping.getTargetCount())) { typeBuilder.add( v.getType().getFieldList().get(mapping.getSource(target))); } final RexNode newV = rexBuilder.makeCorrel(typeBuilder.build(), v.id); if (old != new_) { return rexBuilder.makeFieldAccess(newV, new_); } } return fieldAccess; } }); } return new TrimResult(r, mapping); }
@Override public RelNode visit(LogicalProject project) { hasOverNode = RexOver.containsOver(project.getProjects(), null); final boolean hasSubQuery = RexUtil.SubQueryFinder.find(project.getProjects()) != null; try { if (!corNodeStack.isEmpty()) { mapSubQueryNodeToCorSet.put(project, corNodeStack.peek().getVariablesSet()); } if (hasSubQuery) { corNodeStack.push(project); } checkCorCondition(project); for (RexNode node : project.getProjects()) { node.accept(rexVisitor(project)); } } finally { if (hasSubQuery) { corNodeStack.pop(); } } return super.visit(project); }
protected TrimResult result(RelNode r, final Mapping mapping) { final RexBuilder rexBuilder = relBuilder.getRexBuilder(); for (final CorrelationId correlation : r.getVariablesSet()) { r = r.accept( new CorrelationReferenceFinder() { protected RexNode handle(RexFieldAccess fieldAccess) { final RexCorrelVariable v = (RexCorrelVariable) fieldAccess.getReferenceExpr(); if (v.id.equals(correlation) && v.getType().getFieldCount() == mapping.getSourceCount()) { final int old = fieldAccess.getField().getIndex(); final int new_ = mapping.getTarget(old); final RelDataTypeFactory.Builder typeBuilder = relBuilder.getTypeFactory().builder(); for (int target : Util.range(mapping.getTargetCount())) { typeBuilder.add( v.getType().getFieldList().get(mapping.getSource(target))); } final RexNode newV = rexBuilder.makeCorrel(typeBuilder.build(), v.id); if (old != new_) { return rexBuilder.makeFieldAccess(newV, new_); } } return fieldAccess; } }); } return new TrimResult(r, mapping); }
@Override public Void visitSubQuery(RexSubQuery subQuery) { RelNode newRel = subQuery.rel; if (subQuery.getKind() == SqlKind.IN) { newRel = addProjectionForIn(subQuery.rel); } final Frame frame = decorrelator.getInvoke(newRel); if (frame != null && frame.c != null) { Frame target = frame; if (subQuery.getKind() == SqlKind.EXISTS) { target = addProjectionForExists(frame); } final DecorrelateRexShuttle shuttle = new DecorrelateRexShuttle( rel.getRowType(), target.r.getRowType(), rel.getVariablesSet()); final RexNode newCondition = target.c.accept(shuttle); Pair<RelNode, RexNode> newNodeAndCondition = new Pair<>(target.r, newCondition); subQueryMap.put(subQuery, newNodeAndCondition); } return null; } };
try { if (!corNodeStack.isEmpty()) { mapSubQueryNodeToCorSet.put(join, corNodeStack.peek().getVariablesSet());
Util.minus( RelOptUtil.getVariablesSet(rel), rel.getVariablesSet()), RelOptUtil.getVariablesUsed(rel)); this.allSets.add(set);
Util.minus( RelOptUtil.getVariablesSet(rel), rel.getVariablesSet()), RelOptUtil.getVariablesUsed(rel)); this.allSets.add(set);
for (final CorrelationId correlation : rel.getVariablesSet()) { rel.accept( new CorrelationReferenceFinder() {
for (final CorrelationId correlation : rel.getVariablesSet()) { rel.accept( new CorrelationReferenceFinder() {