Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 1428, 1408 #1430

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
andyfengHKU marked this conversation as resolved.
Show resolved Hide resolved
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