From fef6560edbdb5b8f60c73c6e43419f479f400544 Mon Sep 17 00:00:00 2001 From: shylock <33566796+Shylock-Hg@users.noreply.github.com> Date: Tue, 6 Dec 2022 14:31:19 +0800 Subject: [PATCH] Fix rewrite edge node filter. (#4815) * Fix rewrite edge node filter. * Fix return null. Co-authored-by: jie.wang <38901892+jievince@users.noreply.github.com> --- src/common/function/FunctionManager.cpp | 17 +++++++++++++++++ .../function/test/FunctionManagerTest.cpp | 13 +++++++++++++ .../optimizer/rule/PushEFilterDownRule.cpp | 9 ++++----- .../scheduler/AsyncMsgNotifyBasedScheduler.h | 2 -- .../features/bugfix/RewriteEdgeFilter.feature | 16 ++++++++++++++++ 5 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 tests/tck/features/bugfix/RewriteEdgeFilter.feature diff --git a/src/common/function/FunctionManager.cpp b/src/common/function/FunctionManager.cpp index 333081be4bb..646e09dc911 100644 --- a/src/common/function/FunctionManager.cpp +++ b/src/common/function/FunctionManager.cpp @@ -8,6 +8,7 @@ #include #include +#include #include "common/base/Base.h" #include "common/datatypes/DataSet.h" @@ -41,6 +42,7 @@ std::unordered_map FunctionManager::variadicFunReturnT {"concat_ws", Value::Type::STRING}, {"cos_similarity", Value::Type::FLOAT}, {"coalesce", Value::Type::__EMPTY__}, + {"_any", Value::Type::__EMPTY__}, }; std::unordered_map> FunctionManager::typeSignature_ = { @@ -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 diff --git a/src/common/function/test/FunctionManagerTest.cpp b/src/common/function/test/FunctionManagerTest.cpp index 0c3b025a319..be68924d4e6 100644 --- a/src/common/function/test/FunctionManagerTest.cpp +++ b/src/common/function/test/FunctionManagerTest.cpp @@ -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::kNullValue}), Value::kNullBadData); } + // ok + { TEST_FUNCTION(_any, std::vector({Value(), Value::kNullValue, Value(1)}), Value(1)); } + // only one + { TEST_FUNCTION(_any, std::vector({Value(1)}), Value(1)); } +} + } // namespace nebula int main(int argc, char **argv) { diff --git a/src/graph/optimizer/rule/PushEFilterDownRule.cpp b/src/graph/optimizer/rule/PushEFilterDownRule.cpp index fc338243403..3b5df8904d2 100644 --- a/src/graph/optimizer/rule/PushEFilterDownRule.cpp +++ b/src/graph/optimizer/rule/PushEFilterDownRule.cpp @@ -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" @@ -123,17 +124,15 @@ std::string PushEFilterDownRule::toString() const { return nullptr; } } else { - ret = LogicalExpression::makeOr(pool); - std::vector 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(ret)->setOperands(std::move(operands)); + ret = FunctionCallExpression::make(pool, "_any", args); } return ret; }; diff --git a/src/graph/scheduler/AsyncMsgNotifyBasedScheduler.h b/src/graph/scheduler/AsyncMsgNotifyBasedScheduler.h index b6d3cd88f02..5698d2fcce3 100644 --- a/src/graph/scheduler/AsyncMsgNotifyBasedScheduler.h +++ b/src/graph/scheduler/AsyncMsgNotifyBasedScheduler.h @@ -63,8 +63,6 @@ class AsyncMsgNotifyBasedScheduler final : public Scheduler { folly::Future execute(Executor* executor) const; QueryContext* qctx_{nullptr}; - // used for debugging when core on runtime - std::string query_; }; } // namespace graph } // namespace nebula diff --git a/tests/tck/features/bugfix/RewriteEdgeFilter.feature b/tests/tck/features/bugfix/RewriteEdgeFilter.feature new file mode 100644 index 00000000000..e99d5f9731d --- /dev/null +++ b/tests/tck/features/bugfix/RewriteEdgeFilter.feature @@ -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}] |