61yao commented on code in PR #9907:
URL: https://github.com/apache/pinot/pull/9907#discussion_r1048184091
##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/HashJoinOperator.java:
##########
@@ -42,48 +41,70 @@
/**
* This basic {@code BroadcastJoinOperator} implement a basic broadcast join
algorithm.
+ * This algorithm assumes that the broadcast table has to fit in memory since
we are not supporting any spilling.
*
+ * For left join, inner join, right join and full join,
* <p>It takes the right table as the broadcast side and materialize a hash
table. Then for each of the left table row,
* it looks up for the corresponding row(s) from the hash table and create a
joint row.
*
* <p>For each of the data block received from the left table, it will
generate a joint data block.
- *
- * We currently support left join, inner join and semi join.
+ * We currently support left join, inner join, right join and full join.
* The output is in the format of [left_row, right_row]
*/
// TODO: Move inequi out of hashjoin.
(https://github.com/apache/pinot/issues/9728)
public class HashJoinOperator extends BaseOperator<TransferableBlock> {
+ private class BroadcastRows {
+ public BroadcastRows(List<Object[]> rows, boolean hasMatch) {
+ _rows = rows;
+ _hasMatch = hasMatch;
+ }
+
+ public List<Object[]> _rows;
+ public boolean _hasMatch = false;
+ };
+
private static final String EXPLAIN_NAME = "HASH_JOIN";
- private static final Set<JoinRelType> SUPPORTED_JOIN_TYPES =
ImmutableSet.of(JoinRelType.INNER, JoinRelType.LEFT);
- private final HashMap<Key, List<Object[]>> _broadcastHashTable;
+ private static final Set<JoinRelType> SUPPORTED_JOIN_TYPES =
+ ImmutableSet.of(JoinRelType.INNER, JoinRelType.LEFT, JoinRelType.RIGHT,
JoinRelType.FULL);
+ private final HashMap<Key, BroadcastRows> _broadcastHashTable;
private final Operator<TransferableBlock> _leftTableOperator;
private final Operator<TransferableBlock> _rightTableOperator;
private final JoinRelType _joinType;
private final DataSchema _resultSchema;
+ private final int _leftRowSize;
private final int _resultRowSize;
private final List<FilterOperand> _joinClauseEvaluators;
private boolean _isHashTableBuilt;
+
+ // Used only by full join.
+ // Needed for full join to indicate we have finished processing all results
after returning last block.
+ // TODO: Remove this special handling by fixing data block EOS abstraction
or operator's invariant.
+ private boolean _isTerminated;
private TransferableBlock _upstreamErrorBlock;
private KeySelector<Object[], Object[]> _leftKeySelector;
private KeySelector<Object[], Object[]> _rightKeySelector;
public HashJoinOperator(Operator<TransferableBlock> leftTableOperator,
Operator<TransferableBlock> rightTableOperator,
- DataSchema outputSchema, JoinNode.JoinKeys joinKeys, List<RexExpression>
joinClauses, JoinRelType joinType) {
- Preconditions.checkState(SUPPORTED_JOIN_TYPES.contains(joinType),
- "Join type: " + joinType + " is not supported!");
- _leftKeySelector = joinKeys.getLeftJoinKeySelector();
- _rightKeySelector = joinKeys.getRightJoinKeySelector();
+ DataSchema leftSchema, JoinNode node) {
Review Comment:
not necessary. but I made the change to make the ctor simpler.
##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/HashJoinOperator.java:
##########
@@ -148,39 +172,73 @@ private TransferableBlock
buildJoinedDataBlock(TransferableBlock leftBlock)
if (leftBlock.isErrorBlock()) {
_upstreamErrorBlock = leftBlock;
return _upstreamErrorBlock;
- } else if (TransferableBlockUtils.isNoOpBlock(leftBlock) ||
TransferableBlockUtils.isEndOfStream(leftBlock)) {
+ }
+ if (leftBlock.isNoOpBlock() || (leftBlock.isEOSBlock() && (_joinType !=
JoinRelType.FULL
+ && _joinType != JoinRelType.RIGHT))) {
return leftBlock;
}
+ if (leftBlock.isEOSBlock()) {
+ // Return remaining non-matched rows for full join in broadcast table
Review Comment:
Updated the comment
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]