@Override public RelNode visit(LogicalJoin join) { try { Stacks.push(stack, join); join.getCondition().accept(rexVisitor(join)); } finally { Stacks.pop(stack, join); } return visitJoin(join); }
rightFrame.r, decorrelateExpr(rel.getCondition()), rel.getJoinType() );
right = convert(right, right.getTraitSet().replace(OLAPRel.CONVENTION)); final JoinInfo info = JoinInfo.of(left, right, join.getCondition()); if (!info.isEqui() && join.getJoinType() != JoinRelType.INNER) {
/** * check whether the predicate on join has unsupported correlation condition. * e.g. SELECT * FROM l WHERE a IN (SELECT c FROM r WHERE l.b IN (SELECT e FROM t)) */ private void checkCorCondition(final LogicalJoin join) { if (!hasUnsupportedCorCondition) { join.getCondition().accept(new RexVisitorImpl<Void>(true) { @Override public Void visitCorrelVariable(RexCorrelVariable correlVariable) { hasUnsupportedCorCondition = true; return super.visitCorrelVariable(correlVariable); } }); } }
@Override public RelNode visit(LogicalJoin join) { try { stack.push(join); join.getCondition().accept(rexVisitor(join)); } finally { stack.pop(); } return visitJoin(join); }
@Override public RelNode visit(LogicalJoin join) { try { stack.push(join); join.getCondition().accept(rexVisitor(join)); } finally { stack.pop(); } return visitJoin(join); }
@Override public RelNode visit(LogicalJoin join) { try { stack.push(join); join.getCondition().accept(rexVisitor(join)); } finally { stack.pop(); } return visitJoin(join); }
private static boolean populate(List<RelNode> nodes, List<int[][]> tempLinks, RelNode rel) { if (nodes.isEmpty() && rel instanceof LogicalProject) { return populate(nodes, tempLinks, ((LogicalProject) rel).getInput()); } if (rel instanceof TableScan) { nodes.add(rel); return true; } if (rel instanceof LogicalJoin) { LogicalJoin join = (LogicalJoin) rel; if (join.getJoinType() != JoinRelType.INNER) { throw new RuntimeException("only inner join allowed, but got " + join.getJoinType()); } populate(nodes, tempLinks, join.getLeft()); populate(nodes, tempLinks, join.getRight()); for (RexNode rex : RelOptUtil.conjunctions(join.getCondition())) { tempLinks.add(grab(nodes, rex)); } return true; } throw new RuntimeException("Invalid node type " + rel.getClass().getSimpleName() + " in lattice query"); }
private static boolean populate(List<RelNode> nodes, List<int[][]> tempLinks, RelNode rel) { if (nodes.isEmpty() && rel instanceof LogicalProject) { return populate(nodes, tempLinks, ((LogicalProject) rel).getInput()); } if (rel instanceof TableScan) { nodes.add(rel); return true; } if (rel instanceof LogicalJoin) { LogicalJoin join = (LogicalJoin) rel; if (join.getJoinType() != JoinRelType.INNER) { throw new RuntimeException("only inner join allowed, but got " + join.getJoinType()); } populate(nodes, tempLinks, join.getLeft()); populate(nodes, tempLinks, join.getRight()); for (RexNode rex : RelOptUtil.conjunctions(join.getCondition())) { tempLinks.add(grab(nodes, rex)); } return true; } throw new RuntimeException("Invalid node type " + rel.getClass().getSimpleName() + " in lattice query"); }
@Override public RelNode visit(LogicalJoin join) { // to the best of my knowledge join.systemFieldList is always empty Preconditions.checkState(join.getSystemFieldList().isEmpty(), "join.systemFieldList is not empty!"); final RelNode left = join.getLeft().accept(this); final RelNode right = join.getRight().accept(this); return new LogicalJoin( cluster, copyOf(join.getTraitSet()), left, right, copyOf(join.getCondition()), join.getVariablesSet(), join.getJoinType(), join.isSemiJoinDone(), ImmutableList.<RelDataTypeField>of() ); }
@Override public RelNode visit(LogicalJoin join) { final RexNode conditionExpr = join.getCondition().accept(unwrappingExpressionVisitor); join = join.copy(join.getTraitSet(), conditionExpr, join.getLeft(), join.getRight(), join.getJoinType(), join.isSemiJoinDone()); return visitChildren(join); }
@Override public RelNode visit(LogicalJoin join) { final RexNode conditionExpr = join.getCondition().accept(unwrappingExpressionVisitor); join = join.copy(join.getTraitSet(), conditionExpr, join.getLeft(), join.getRight(), join.getJoinType(), join.isSemiJoinDone()); return visitChildren(join); }
/** Test case for * <a href="https://issues.apache.org/jira/browse/CALCITE-833">[CALCITE-833] * RelOptUtil.splitJoinCondition attempts to split a Join-Condition which * has a remaining condition</a>. */ @Test public void testSplitJoinCondition() { final String sql = "select * \n" + "from emp a \n" + "INNER JOIN dept b \n" + "ON CAST(a.empno AS int) <> b.deptno"; final RelNode relNode = toRel(sql); final LogicalProject project = (LogicalProject) relNode; final LogicalJoin join = (LogicalJoin) project.getInput(0); final List<RexNode> leftJoinKeys = new ArrayList<>(); final List<RexNode> rightJoinKeys = new ArrayList<>(); final ArrayList<RelDataTypeField> sysFieldList = new ArrayList<>(); final RexNode remaining = RelOptUtil.splitJoinCondition(sysFieldList, join.getInputs().get(0), join.getInputs().get(1), join.getCondition(), leftJoinKeys, rightJoinKeys, null, null); assertThat(remaining.toString(), is("<>(CAST($0):INTEGER NOT NULL, $9)")); assertThat(leftJoinKeys.isEmpty(), is(true)); assertThat(rightJoinKeys.isEmpty(), is(true)); }
public void rewriteRel(LogicalJoin rel) { LogicalJoin newRel = LogicalJoin.create(getNewForOldRel(rel.getLeft()), getNewForOldRel(rel.getRight()), rel.getCondition().accept(new RewriteRexShuttle()), rel.getVariablesSet(), rel.getJoinType()); setNewForOldRel(rel, newRel); }
public void rewriteRel(LogicalJoin rel) { LogicalJoin newRel = LogicalJoin.create(getNewForOldRel(rel.getLeft()), getNewForOldRel(rel.getRight()), rel.getCondition().accept(new RewriteRexShuttle()), rel.getVariablesSet(), rel.getJoinType()); setNewForOldRel(rel, newRel); }
void translate(final LogicalJoin join, final TranslatorContext translatorContext) { JoinInputNode.InputType inputTypeOnLeft = getInputType(join.getLeft(), translatorContext); JoinInputNode.InputType inputTypeOnRight = getInputType(join.getRight(), translatorContext); // Do the validation of join query validateJoinQuery(join, inputTypeOnLeft, inputTypeOnRight); // At this point, one of the sides is a table. Let's figure out if it is on left or right side. boolean isTablePosOnRight = (inputTypeOnRight != JoinInputNode.InputType.STREAM); // stream and table keyIds are used to extract the join condition field (key) names and values out of the stream // and table records. List<Integer> streamKeyIds = new LinkedList<>(); List<Integer> tableKeyIds = new LinkedList<>(); // Fetch the stream and table indices corresponding to the fields given in the join condition. populateStreamAndTableKeyIds(((RexCall) join.getCondition()).getOperands(), join, isTablePosOnRight, streamKeyIds, tableKeyIds); // Get the two input nodes (stream and table nodes) for the join. JoinInputNode streamNode = new JoinInputNode(isTablePosOnRight ? join.getLeft() : join.getRight(), streamKeyIds, isTablePosOnRight ? inputTypeOnLeft : inputTypeOnRight, !isTablePosOnRight); JoinInputNode tableNode = new JoinInputNode(isTablePosOnRight ? join.getRight() : join.getLeft(), tableKeyIds, isTablePosOnRight ? inputTypeOnRight : inputTypeOnLeft, isTablePosOnRight); MessageStream<SamzaSqlRelMessage> inputStream = translatorContext.getMessageStream(streamNode.getRelNode().getId()); Table table = getTable(tableNode, translatorContext); MessageStream<SamzaSqlRelMessage> outputStream = joinStreamWithTable(inputStream, table, streamNode, tableNode, join, translatorContext); translatorContext.registerMessageStream(join.getId(), outputStream); outputStream.map(outputMetricsMF); }
public RelNode convert(RelNode rel) { final LogicalJoin join = (LogicalJoin) rel; final BindableConvention out = BindableConvention.INSTANCE; final RelTraitSet traitSet = join.getTraitSet().replace(out); return new BindableJoin(rel.getCluster(), traitSet, convert(join.getLeft(), join.getLeft().getTraitSet() .replace(BindableConvention.INSTANCE)), convert(join.getRight(), join.getRight().getTraitSet() .replace(BindableConvention.INSTANCE)), join.getCondition(), join.getVariablesSet(), join.getJoinType()); } }
public RelNode convert(RelNode rel) { final LogicalJoin join = (LogicalJoin) rel; final BindableConvention out = BindableConvention.INSTANCE; final RelTraitSet traitSet = join.getTraitSet().replace(out); return new BindableJoin(rel.getCluster(), traitSet, convert(join.getLeft(), join.getLeft().getTraitSet() .replace(BindableConvention.INSTANCE)), convert(join.getRight(), join.getRight().getTraitSet() .replace(BindableConvention.INSTANCE)), join.getCondition(), join.getVariablesSet(), join.getJoinType()); } }
private void validateJoinQuery(LogicalJoin join, JoinInputNode.InputType inputTypeOnLeft, JoinInputNode.InputType inputTypeOnRight) { JoinRelType joinRelType = join.getJoinType(); if (joinRelType.compareTo(JoinRelType.INNER) != 0 && joinRelType.compareTo(JoinRelType.LEFT) != 0 && joinRelType.compareTo(JoinRelType.RIGHT) != 0) { throw new SamzaException("Query with only INNER and LEFT/RIGHT OUTER join are supported."); } boolean isTablePosOnLeft = (inputTypeOnLeft != JoinInputNode.InputType.STREAM); boolean isTablePosOnRight = (inputTypeOnRight != JoinInputNode.InputType.STREAM); if (!isTablePosOnLeft && !isTablePosOnRight) { throw new SamzaException("Invalid query with both sides of join being denoted as 'stream'. " + "Stream-stream join is not yet supported. " + dumpRelPlanForNode(join)); } if (isTablePosOnLeft && isTablePosOnRight) { throw new SamzaException("Invalid query with both sides of join being denoted as 'table'. " + dumpRelPlanForNode(join)); } if (joinRelType.compareTo(JoinRelType.LEFT) == 0 && isTablePosOnLeft && !isTablePosOnRight) { throw new SamzaException("Invalid query for outer left join. Left side of the join should be a 'stream' and " + "right side of join should be a 'table'. " + dumpRelPlanForNode(join)); } if (joinRelType.compareTo(JoinRelType.RIGHT) == 0 && isTablePosOnRight && !isTablePosOnLeft) { throw new SamzaException("Invalid query for outer right join. Left side of the join should be a 'table' and " + "right side of join should be a 'stream'. " + dumpRelPlanForNode(join)); } validateJoinCondition(join.getCondition()); }
private void validateJoinQuery(LogicalJoin join) { JoinRelType joinRelType = join.getJoinType(); if (joinRelType.compareTo(JoinRelType.INNER) != 0 && joinRelType.compareTo(JoinRelType.LEFT) != 0 && joinRelType.compareTo(JoinRelType.RIGHT) != 0) { throw new SamzaException("Query with only INNER and LEFT/RIGHT OUTER join are supported."); } boolean isTablePosOnLeft = isTable(join.getLeft()); boolean isTablePosOnRight = isTable(join.getRight()); if (!isTablePosOnLeft && !isTablePosOnRight) { throw new SamzaException("Invalid query with both sides of join being denoted as 'stream'. " + "Stream-stream join is not yet supported. " + dumpRelPlanForNode(join)); } if (isTablePosOnLeft && isTablePosOnRight) { throw new SamzaException("Invalid query with both sides of join being denoted as 'table'. " + dumpRelPlanForNode(join)); } if (joinRelType.compareTo(JoinRelType.LEFT) == 0 && isTablePosOnLeft && !isTablePosOnRight) { throw new SamzaException("Invalid query for outer left join. Left side of the join should be a 'stream' and " + "right side of join should be a 'table'. " + dumpRelPlanForNode(join)); } if (joinRelType.compareTo(JoinRelType.RIGHT) == 0 && isTablePosOnRight && !isTablePosOnLeft) { throw new SamzaException("Invalid query for outer right join. Left side of the join should be a 'table' and " + "right side of join should be a 'stream'. " + dumpRelPlanForNode(join)); } validateJoinCondition(join.getCondition()); }