int nullIndicatorPos) { final RelDataTypeFactory typeFactory = join.getCluster().getTypeFactory(); final RelNode left = join.getLeft(); final JoinRelType joinType = join.getJoinType();
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"); }
int deltaKeyIdx = rightRef.getIndex() - join.getLeft().getRowType().getFieldCount(); streamKeyIds.add(isTablePosOnRight ? leftRef.getIndex() : deltaKeyIdx); tableKeyIds.add(isTablePosOnRight ? deltaKeyIdx : leftRef.getIndex());
join.getLeft().getRowType().getFieldCount(); RexInputRef leftFieldAccess = (RexInputRef) leftComparand; if (!(leftFieldAccess.getIndex() < leftFieldCount)) {
join.getLeft().getRowType().getFieldCount(); RexInputRef leftFieldAccess = (RexInputRef) leftComparand; if (!(leftFieldAccess.getIndex() < leftFieldCount)) {
@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() ); }
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); }
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; } }
@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); }
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()); } }
@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) { 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(); } } } } }
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); }
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()); }
final LogicalJoin join = call.rel(0); RelNode right = join.getRight(); final RelNode left = join.getLeft(); final int leftFieldCount = left.getRowType().getFieldCount(); final RelOptCluster cluster = join.getCluster();
final LogicalJoin join = call.rel(0); RelNode right = join.getRight(); final RelNode left = join.getLeft(); final int leftFieldCount = left.getRowType().getFieldCount(); final RelOptCluster cluster = join.getCluster();