From 97fbc9c5d75203df222acd032e726c6e0be68957 Mon Sep 17 00:00:00 2001 From: Jia Ke Date: Fri, 8 Nov 2024 16:29:43 +0800 Subject: [PATCH] fix full outer join with null value compare in right side --- velox/exec/MergeJoin.cpp | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/velox/exec/MergeJoin.cpp b/velox/exec/MergeJoin.cpp index d528530e19f6..bc0d659eb4be 100644 --- a/velox/exec/MergeJoin.cpp +++ b/velox/exec/MergeJoin.cpp @@ -1009,14 +1009,16 @@ RowVectorPtr MergeJoin::getOutput() { } else if (isAntiJoin(joinType_)) { output = filterOutputForAntiJoin(output); if (output) { + std::cout << "the output is " << output->toString(0, output->size()) + << "\n"; return output; } // No rows survived the filter for anti join. Get more rows. continue; } else { - // std::cout << "the output is " << output->toString(0, output->size()) - // << "\n"; + std::cout << "the output is " << output->toString(0, output->size()) + << "\n"; return output; } } @@ -1038,22 +1040,19 @@ RowVectorPtr MergeJoin::getOutput() { if (rightInput_) { // std::cout << "the right input is " << rightInput_->toString(0, // rightInput_->size()) << "\n"; - if (isFullJoin(joinType_)) { - rightIndex_ = 0; - } else { - auto firstNonNullIndex = firstNonNull(rightInput_, rightKeys_); - if (isRightJoin(joinType_) && firstNonNullIndex > 0) { - prepareOutput(nullptr, rightInput_); - for (auto i = 0; i < firstNonNullIndex; ++i) { - addOutputRowForRightJoin(rightInput_, i); - } - } - rightIndex_ = firstNonNullIndex; - if (rightIndex_ == rightInput_->size()) { - // Ran out of rows on the right side. - rightInput_ = nullptr; + auto firstNonNullIndex = firstNonNull(rightInput_, rightKeys_); + if ((isRightJoin(joinType_) || isFullJoin(joinType_)) && + firstNonNullIndex > 0) { + prepareOutput(nullptr, rightInput_); + for (auto i = 0; i < firstNonNullIndex; ++i) { + addOutputRowForRightJoin(rightInput_, i); } } + rightIndex_ = firstNonNullIndex; + if (rightIndex_ == rightInput_->size()) { + // Ran out of rows on the right side. + rightInput_ = nullptr; + } } else { noMoreRightInput_ = true; }