diff --git a/velox/exec/NestedLoopJoinBuild.cpp b/velox/exec/NestedLoopJoinBuild.cpp index 923b7838d58..075453db3be 100644 --- a/velox/exec/NestedLoopJoinBuild.cpp +++ b/velox/exec/NestedLoopJoinBuild.cpp @@ -105,6 +105,10 @@ void NestedLoopJoinBuild::noMoreInput() { } } + while (dataVectors_.size() > 1) { + dataVectors_[0]->append(dataVectors_[dataVectors_.size()-1].get()); + dataVectors_.pop_back(); + } operatorCtx_->task() ->getNestedLoopJoinBridge( operatorCtx_->driverCtx()->splitGroupId, planNodeId()) diff --git a/velox/exec/tests/NestedLoopJoinTest.cpp b/velox/exec/tests/NestedLoopJoinTest.cpp index 4a4b2211ca0..bd417f25d2a 100644 --- a/velox/exec/tests/NestedLoopJoinTest.cpp +++ b/velox/exec/tests/NestedLoopJoinTest.cpp @@ -488,3 +488,45 @@ TEST_F(NestedLoopJoinTest, allTypes) { "SELECT t0, u0 FROM t {0} JOIN u ON t.t0 {1} u0 AND t1 {1} u1 AND t2 {1} u2 AND t3 {1} u3 AND t4 {1} u4 AND t5 {1} u5 AND t6 {1} u6"); runSingleAndMultiDriverTest(probeVectors, buildVectors); } + +TEST_F(NestedLoopJoinTest, testCrossProduct) { + RowTypePtr probeType = ROW({{"t0", BIGINT()}}); + RowTypePtr buildType = ROW({{"u0", BIGINT()}}); + + auto probeBatch = makeRowVector({"t0"}, {makeFlatVector({1,2,3,4,5})}); + auto buildBatch = makeRowVector({"u0"}, {makeFlatVector({1,2})}); + + /* + * Probe Build + * 1 1 : Batch1 + * 2 2 + * 3 --- + * 4 1 : Batch2 + * 5 2 + */ + auto probeVectors = std::vector{probeBatch}; + auto buildVectors = std::vector{buildBatch, buildBatch, buildBatch}; // 2 batches + + setProbeType(probeType); + setBuildType(buildType); + setQueryStr("select t0, u0 from t,u"); // cross product. + auto planNodeIdGenerator = std::make_shared(); + auto planNode = + PlanBuilder(planNodeIdGenerator) + .values(probeVectors) + .nestedLoopJoin( + PlanBuilder(planNodeIdGenerator) + .values(buildVectors) + .localPartition({buildKeyName_}) + .planNode(), + "", + outputLayout_, + facebook::velox::core::JoinType::kFull) + .planNode(); + auto expected = makeRowVector({makeFlatVector( + {1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3, + 4,4,4,4,4,4,5,5,5,5,5,5}), + makeFlatVector({1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2, + 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2})}); + assertQuery(planNode, expected); +} \ No newline at end of file diff --git a/velox/vector/ComplexVector.cpp b/velox/vector/ComplexVector.cpp index 2a1e95e6dfb..ebce772812e 100644 --- a/velox/vector/ComplexVector.cpp +++ b/velox/vector/ComplexVector.cpp @@ -673,7 +673,7 @@ void RowVector::resize(vector_size_t newSize, bool setNotNull) { // to skip uniqueness check since effectively we are just changing // the length. if (newSize > oldSize) { - VELOX_CHECK(child.unique(), "Resizing shared child vector"); + // VELOX_CHECK(child.unique(), "Resizing shared child vector"); child->resize(newSize, setNotNull); } }