Skip to content

Commit

Permalink
Fix issue-1428, 1408
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfengHKU committed Mar 31, 2023
1 parent 7116e2e commit 23f83f0
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/binder/bind/bind_projection_clause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ void Binder::bindOrderBySkipLimitIfNecessary(
// reference expression.
auto projectionExpressionSet =
expression_set{projectionExpressions.begin(), projectionExpressions.end()};

for (auto& orderByExpression : orderByExpressions) {
if (!projectionExpressionSet.contains(orderByExpression)) {
throw BinderException("Order by expression " + orderByExpression->toString() +
Expand Down
15 changes: 15 additions & 0 deletions src/expression_evaluator/function_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ bool FunctionExpressionEvaluator::select(SelectionVector& selVector) {
for (auto& child : children) {
child->evaluate();
}
// Temporary code path for function whose return type is BOOL but select interface is not
// implemented (e.g. list_contains). We should remove this if statement eventually.
if (selectFunc == nullptr) {
assert(resultVector->dataType.typeID == BOOL);
execFunc(parameters, *resultVector);
auto numSelectedValues = 0u;
for (auto i = 0u; i < resultVector->state->selVector->selectedSize; ++i) {
auto pos = resultVector->state->selVector->selectedPositions[i];
auto selectedPosBuffer = selVector.getSelectedPositionsBuffer();
selectedPosBuffer[numSelectedValues] = pos;
numSelectedValues += resultVector->getValue<bool>(pos);
}
selVector.selectedSize = numSelectedValues;
return numSelectedValues > 0;
}
return selectFunc(parameters, selVector);
}

Expand Down
3 changes: 3 additions & 0 deletions src/include/planner/projection_planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class ProjectionPlanner {
void planProjectionBody(const binder::BoundProjectionBody& projectionBody, LogicalPlan& plan);
void planAggregate(const binder::expression_vector& expressionsToAggregate,
const binder::expression_vector& expressionsToGroupBy, LogicalPlan& plan);
void planOrderBy(const binder::expression_vector& expressionsToProject,
const binder::expression_vector& expressionsToOrderBy, const std::vector<bool>& isAscOrders,
LogicalPlan& plan);

void appendProjection(const binder::expression_vector& expressionsToProject, LogicalPlan& plan);
void appendAggregate(const binder::expression_vector& expressionsToGroupBy,
Expand Down
19 changes: 17 additions & 2 deletions src/planner/projection_planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ void ProjectionPlanner::planProjectionBody(
planAggregate(expressionsToAggregate, expressionsToGroupBy, plan);
}
if (projectionBody.hasOrderByExpressions()) {
appendOrderBy(
projectionBody.getOrderByExpressions(), projectionBody.getSortingOrders(), plan);
planOrderBy(expressionsToProject, projectionBody.getOrderByExpressions(),
projectionBody.getSortingOrders(), plan);
}
appendProjection(expressionsToProject, plan);
if (projectionBody.getIsDistinct()) {
Expand Down Expand Up @@ -86,6 +86,21 @@ void ProjectionPlanner::planAggregate(const expression_vector& expressionsToAggr
appendAggregate(expressionsToGroupBy, expressionsToAggregate, plan);
}

void ProjectionPlanner::planOrderBy(const binder::expression_vector& expressionsToProject,
const binder::expression_vector& expressionsToOrderBy, const std::vector<bool>& isAscOrders,
kuzu::planner::LogicalPlan& plan) {
auto expressionsToProjectBeforeOrderBy = expressionsToProject;
auto expressionsToProjectSet =
expression_set{expressionsToProject.begin(), expressionsToProject.end()};
for (auto& expression : expressionsToOrderBy) {
if (!expressionsToProjectSet.contains(expression)) {
expressionsToProjectBeforeOrderBy.push_back(expression);
}
}
appendProjection(expressionsToProjectBeforeOrderBy, plan);
appendOrderBy(expressionsToOrderBy, isAscOrders, plan);
}

void ProjectionPlanner::appendProjection(
const expression_vector& expressionsToProject, LogicalPlan& plan) {
for (auto& expression : expressionsToProject) {
Expand Down
6 changes: 6 additions & 0 deletions test/test_files/tinysnb/function/list.test
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,12 @@ True
False
True

-NAME ListContainsSelect
-QUERY MATCH (a:person) WHERE list_contains(a.courseScoresPerTerm, [8]) RETURN a.ID
---- 2
7
8

-NAME ListContainsStructuredListOfStrings
-QUERY MATCH (a:person) RETURN list_has(a.usedNames, "Grad")
---- 8
Expand Down
18 changes: 9 additions & 9 deletions test/test_files/tinysnb/order_by/single_label.test
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
-NAME OrderByInt64Test
-QUERY MATCH (p:person) RETURN p.age ORDER BY p.age
-QUERY MATCH (p:person) RETURN p.ID, p.age ORDER BY p.age + p.ID
-PARALLELISM 3
---- 8
20
20
25
30
35
40
45
83
5|20
7|20
2|30
8|25
0|35
3|45
9|40
10|83

-NAME OrderByInt32Test
-QUERY MATCH (m:movies) RETURN m.length ORDER BY m.length
Expand Down

0 comments on commit 23f83f0

Please sign in to comment.