Skip to content

Commit

Permalink
Fix rewrite edge node filter. (#4815)
Browse files Browse the repository at this point in the history
* Fix rewrite edge node filter.

* Fix return null.

Co-authored-by: jie.wang <38901892+jievince@users.noreply.github.com>
  • Loading branch information
Shylock-Hg and jievince committed Dec 6, 2022
1 parent 81feb43 commit fef6560
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
17 changes: 17 additions & 0 deletions src/common/function/FunctionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <folly/json.h>

#include <boost/algorithm/string/replace.hpp>
#include <cstdint>

#include "common/base/Base.h"
#include "common/datatypes/DataSet.h"
Expand Down Expand Up @@ -41,6 +42,7 @@ std::unordered_map<std::string, Value::Type> FunctionManager::variadicFunReturnT
{"concat_ws", Value::Type::STRING},
{"cos_similarity", Value::Type::FLOAT},
{"coalesce", Value::Type::__EMPTY__},
{"_any", Value::Type::__EMPTY__},
};

std::unordered_map<std::string, std::vector<TypeSignature>> FunctionManager::typeSignature_ = {
Expand Down Expand Up @@ -2820,6 +2822,21 @@ FunctionManager::FunctionManager() {
}
};
}
// Get any argument which is not empty/null
{
auto &attr = functions_["_any"];
attr.minArity_ = 1;
attr.maxArity_ = INT64_MAX;
attr.isAlwaysPure_ = true;
attr.body_ = [](const auto &args) -> Value {
for (const auto &arg : args) {
if (!arg.get().isNull() && !arg.get().empty()) {
return arg.get();
}
}
return Value::kNullValue;
};
}
} // NOLINT

// static
Expand Down
13 changes: 13 additions & 0 deletions src/common/function/test/FunctionManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1983,6 +1983,19 @@ TEST_F(FunctionManagerTest, PurityTest) {
ASSERT_TRUE(result.ok() && result.value() == true);
}

TEST_F(FunctionManagerTest, Any) {
auto dataset = DataSet({"col0", "col1", "col2"});
dataset.emplace_back(Row({1, true, "233"}));
dataset.emplace_back(Row({4, false, "456"}));
Value datasetValue = Value(std::move(dataset));
// null all
{ TEST_FUNCTION(_any, std::vector<Value>({Value(), Value::kNullValue}), Value::kNullBadData); }
// ok
{ TEST_FUNCTION(_any, std::vector<Value>({Value(), Value::kNullValue, Value(1)}), Value(1)); }
// only one
{ TEST_FUNCTION(_any, std::vector<Value>({Value(1)}), Value(1)); }
}

} // namespace nebula

int main(int argc, char **argv) {
Expand Down
9 changes: 4 additions & 5 deletions src/graph/optimizer/rule/PushEFilterDownRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "graph/optimizer/rule/PushEFilterDownRule.h"

#include "common/expression/Expression.h"
#include "common/expression/FunctionCallExpression.h"
#include "graph/optimizer/OptContext.h"
#include "graph/optimizer/OptGroup.h"
#include "graph/planner/plan/PlanNode.h"
Expand Down Expand Up @@ -123,17 +124,15 @@ std::string PushEFilterDownRule::toString() const {
return nullptr;
}
} else {
ret = LogicalExpression::makeOr(pool);
std::vector<Expression *> operands;
operands.reserve(edges.size());
auto args = ArgumentList::make(pool);
for (auto &edge : edges) {
auto reEdgeExp = rewriteStarEdge(propertyExpr, spaceId, edge, schemaMng, pool);
if (reEdgeExp == nullptr) {
return nullptr;
}
operands.emplace_back(reEdgeExp);
args->addArgument(reEdgeExp);
}
static_cast<LogicalExpression *>(ret)->setOperands(std::move(operands));
ret = FunctionCallExpression::make(pool, "_any", args);
}
return ret;
};
Expand Down
2 changes: 0 additions & 2 deletions src/graph/scheduler/AsyncMsgNotifyBasedScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ class AsyncMsgNotifyBasedScheduler final : public Scheduler {
folly::Future<Status> execute(Executor* executor) const;

QueryContext* qctx_{nullptr};
// used for debugging when core on runtime
std::string query_;
};
} // namespace graph
} // namespace nebula
Expand Down
16 changes: 16 additions & 0 deletions tests/tck/features/bugfix/RewriteEdgeFilter.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) 2022 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.
Feature: Test match used in pipe

Background:
Given a graph with space named "nba"

Scenario: Order by after match
When executing query:
"""
match (v)-[e:like|teammate{start_year: 2010}]->() where id(v) == 'Tim Duncan' return e
"""
Then the result should be, in any order, with relax comparison:
| e |
| [:teammate "Tim Duncan"->"Danny Green" @0 {end_year: 2016, start_year: 2010}] |

0 comments on commit fef6560

Please sign in to comment.