@Override public RelNode convert(RelNode rel) { LogicalJoin join = (LogicalJoin) rel; RelNode left = join.getInput(0); RelNode right = join.getInput(1); RelTraitSet traitSet = join.getTraitSet().replace(OLAPRel.CONVENTION); left = convert(left, left.getTraitSet().replace(OLAPRel.CONVENTION)); right = convert(right, right.getTraitSet().replace(OLAPRel.CONVENTION)); final JoinInfo info = JoinInfo.of(left, right, join.getCondition()); if (!info.isEqui() && join.getJoinType() != JoinRelType.INNER) { RelOptCluster cluster = join.getCluster(); RelNode newRel; try { newRel = new OLAPJoinRel(cluster, traitSet, left, right, // info.leftKeys, info.rightKeys, join.getVariablesSet(), join.getJoinType()); } catch (InvalidRelException e) {
LogicalProject project, int nullIndicatorPos) { final RelDataTypeFactory typeFactory = join.getCluster().getTypeFactory(); final RelNode left = join.getLeft(); final JoinRelType joinType = join.getJoinType(); nullIndicatorPos, typeFactory.createTypeWithNullability( join.getRowType().getFieldList().get(nullIndicatorPos) .getType(), true));
} else { r = LogicalJoin.create(r, distinct, cluster.getRexBuilder().makeLiteral(true), ImmutableSet.<CorrelationId>of(), JoinRelType.INNER);
final RelNode oldLeft = rel.getInput(0); final RelNode oldRight = rel.getInput(1); final RelNode newJoin = HiveJoin.getJoin(rel.getCluster(), leftFrame.r, rightFrame.r, decorrelateExpr(rel.getCondition()), rel.getJoinType() ); assert rel.getRowType().getFieldCount() == oldLeftFieldCount + oldRightFieldCount;
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"); }
final RelNode oldLeft = rel.getInput(0); final RelNode oldRight = rel.getInput(1); LogicalJoin.create(leftFrame.r, rightFrame.r, decorrelateExpr(currentRel, map, cm, rel.getCondition()), ImmutableSet.of(), rel.getJoinType()); assert rel.getRowType().getFieldCount() == oldLeftFieldCount + oldRightFieldCount;
@Override public RelNode convert(RelNode rel) { LogicalJoin join = (LogicalJoin) rel; final JoinInfo info = JoinInfo.of(join.getLeft(), join.getRight(), join.getCondition()); if (join.getJoinType() != JoinRelType.INNER) { final List<RelCollation> collations = new ArrayList<>(); int offset = 0; for (Ord<RelNode> ord : Ord.zip(join.getInputs())) { RelTraitSet traits = ord.e.getTraitSet() .replace(EnumerableConvention.INSTANCE); final RelOptCluster cluster = join.getCluster(); RelNode newRel; try { RelTraitSet traits = join.getTraitSet() .replace(EnumerableConvention.INSTANCE); if (!collations.isEmpty()) { info.leftKeys, info.rightKeys, join.getVariablesSet(), join.getJoinType()); } catch (InvalidRelException e) { EnumerableRules.LOGGER.debug(e.toString());
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 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()); } }
@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 convert(RelNode rel) { LogicalJoin join = (LogicalJoin) rel; List<RelNode> newInputs = new ArrayList<>(); for (RelNode input : join.getInputs()) { if (!(input.getConvention() instanceof EnumerableConvention)) { input = final RelOptCluster cluster = join.getCluster(); final RelTraitSet traitSet = join.getTraitSet().replace(EnumerableConvention.INSTANCE); final RelNode left = newInputs.get(0); final RelNode right = newInputs.get(1); final JoinInfo info = JoinInfo.of(left, right, join.getCondition()); if (!info.isEqui() && join.getJoinType() != JoinRelType.INNER) { join.getCondition(), join.getVariablesSet(), join.getJoinType()); } catch (InvalidRelException e) { EnumerableRules.LOGGER.debug(e.toString()); newRel = new EnumerableJoin( cluster, join.getTraitSet().replace(EnumerableConvention.INSTANCE), left, right, info.leftKeys, info.rightKeys, join.getVariablesSet(), join.getJoinType()); } catch (InvalidRelException e) {
@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() ); }
throw new SamzaException("SQL query is not supported. Join condition " + join.getCondition() + " should have " + "reference operands but the types are " + operands.get(0).getClass() + " and " + operands.get(1).getClass()); int deltaKeyIdx = rightRef.getIndex() - join.getLeft().getRowType().getFieldCount(); streamKeyIds.add(isTablePosOnRight ? leftRef.getIndex() : deltaKeyIdx); tableKeyIds.add(isTablePosOnRight ? deltaKeyIdx : leftRef.getIndex());
@Override public RelNode visit(LogicalJoin join) { for (;;) { RelNode rel = super.visit(join); if (rel == join || !(rel instanceof LogicalJoin)) { return rel; } join = (LogicalJoin) rel; final ProjectFilterTable left = ProjectFilterTable.of(join.getLeft()); if (left != null) { final ProjectFilterTable right = ProjectFilterTable.of(join.getRight()); if (right != null) { try { match(left, right, join.getCluster()); } catch (Util.FoundOne e) { return (RelNode) e.getNode(); } } } } }
@Override public RelNode visit(LogicalJoin join) { try { Stacks.push(stack, join); join.getCondition().accept(rexVisitor(join)); } finally { Stacks.pop(stack, join); } return visitJoin(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)); }
LogicalJoin.create(left, right, joinCond, ImmutableSet.<CorrelationId>of(), joinType); int nullIndicatorPos = join.getRowType().getFieldCount() - 1; nullIndicatorPos, cluster.getTypeFactory().createTypeWithNullability( join.getRowType().getFieldList() .get(nullIndicatorPos).getType(), true));
int nSourceFields = join.getLeft().getRowType().getFieldCount(); final List<RexNode> projects = new ArrayList<>(); for (int level1Idx = 0; level1Idx < nLevel1Exprs; level1Idx++) {
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 Table loadLocalTable(boolean isTablePosOnRight, List<Integer> tableKeyIds, LogicalJoin join, TranslatorContext context) { RelNode relNode = isTablePosOnRight ? join.getRight() : join.getLeft(); MessageStream<SamzaSqlRelMessage> relOutputStream = context.getMessageStream(relNode.getId()); SqlIOConfig sourceConfig = resolveSourceConfig(relNode); if (!sourceConfig.getTableDescriptor().isPresent()) { String errMsg = "Failed to resolve table source in join operation: node=" + relNode; log.error(errMsg); throw new SamzaException(errMsg); } // Create a table backed by RocksDb store with the fields in the join condition as composite key and relational // message as the value. Send the messages from the input stream denoted as 'table' to the created table store. Table<KV<SamzaSqlCompositeKey, SamzaSqlRelMessage>> table = context.getStreamAppDescriptor().getTable(sourceConfig.getTableDescriptor().get()); relOutputStream .map(m -> new KV(createSamzaSqlCompositeKey(m, tableKeyIds), m)) .sendTo(table); return table; } }