diff --git a/src/optimizer/correlated_subquery_unnest_solver.cpp b/src/optimizer/correlated_subquery_unnest_solver.cpp index 8712709993..d048fbdafe 100644 --- a/src/optimizer/correlated_subquery_unnest_solver.cpp +++ b/src/optimizer/correlated_subquery_unnest_solver.cpp @@ -1,7 +1,9 @@ #include "optimizer/correlated_subquery_unnest_solver.h" +#include "common/exception/internal.h" #include "planner/operator/logical_hash_join.h" #include "planner/operator/scan/logical_expressions_scan.h" + using namespace kuzu::planner; namespace kuzu { @@ -30,13 +32,18 @@ void CorrelatedSubqueryUnnestSolver::solveAccHashJoin(LogicalOperator* op) const auto acc = op->getChild(0).get(); auto rightSolver = std::make_unique(acc); rightSolver->solve(hashJoin.getChild(1).get()); - auto leftSolver = std::make_unique(nullptr); + auto leftSolver = std::make_unique(accumulateOp); leftSolver->solve(acc->getChild(0).get()); } void CorrelatedSubqueryUnnestSolver::visitExpressionsScan(LogicalOperator* op) { auto expressionsScan = op->ptrCast(); - KU_ASSERT(accumulateOp != nullptr); + // LCOV_EXCL_START + if (accumulateOp == nullptr) { + throw common::InternalException( + "Failed to execute CorrelatedSubqueryUnnestSolver. This should not happen."); + } + // LCOV_EXCL_STOP expressionsScan->setOuterAccumulate(accumulateOp); } diff --git a/test/test_files/issue/issue.test b/test/test_files/issue/issue.test index cb49cc37dc..6322a3137a 100644 --- a/test/test_files/issue/issue.test +++ b/test/test_files/issue/issue.test @@ -2,6 +2,25 @@ -- +-CASE 4080 +-STATEMENT CREATE NODE TABLE V(id INT, PRIMARY KEY(id)); +---- ok +-STATEMENT CREATE REL TABLE links_to(FROM V to V); +---- ok +-STATEMENT CREATE REL TABLE parent(FROM V to V); +---- ok +-STATEMENT CREATE (:V {id: 1}), (:V {id: 2}); +---- ok +-STATEMENT MATCH (v1:V {id: 1}), (v2:V {id: 2}) + CREATE (v1)-[:links_to]->(v2), (v1)-[:parent]->(v2) +---- ok +-STATEMENT WITH 2 as parent_id + OPTIONAL MATCH (v1:V)-[:links_to*1..]->(:V) + WHERE EXISTS {MATCH (v1)-[:parent]->(:V {id: parent_id})} + RETURN v1.id; +---- 1 +1 + -CASE listContainsCast -STATEMENT CREATE NODE TABLE A(id SERIAL, primary key(id)); ---- ok