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 rewrite edge node filter. #4815

Merged
merged 3 commits into from
Dec 6, 2022

Conversation

Shylock-Hg
Copy link
Contributor

@Shylock-Hg Shylock-Hg commented Nov 1, 2022

What type of PR is this?

  • bug
  • feature
  • enhancement

What problem(s) does this PR solve?

Issue(s) number:

Close https://github.com/vesoft-inc/nebula-ent/issues/1534
Close #4989

Description:

Rewrite edge property like*.prop to _any(e1.prop, e2,prop ...)

How do you solve it?

Special notes for your reviewer, ex. impact of this fix, design document, etc:

Checklist:

Tests:

  • Unit test(positive and negative cases)
  • Function test
  • Performance test
  • N/A

Affects:

  • Documentation affected (Please add the label if documentation needs to be modified.)
  • Incompatibility (If it breaks the compatibility, please describe it and add the label.)
  • If it's needed to cherry-pick (If cherry-pick to some branches is required, please label the destination version(s).)
  • Performance impacted: Consumes more CPU/Memory

Release notes:

Please confirm whether to be reflected in release notes and how to describe:

ex. Fixed the bug .....

@Shylock-Hg Shylock-Hg added the ready-for-testing PR: ready for the CI test label Nov 1, 2022
@Shylock-Hg Shylock-Hg marked this pull request as ready for review November 1, 2022 09:01
@codecov-commenter
Copy link

codecov-commenter commented Nov 7, 2022

Codecov Report

Base: 76.78% // Head: 76.84% // Increases project coverage by +0.05% 🎉

Coverage data is based on head (a95430f) compared to base (6f240e3).
Patch coverage: 70.66% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4815      +/-   ##
==========================================
+ Coverage   76.78%   76.84%   +0.05%     
==========================================
  Files        1102     1102              
  Lines       80953    81001      +48     
==========================================
+ Hits        62160    62242      +82     
+ Misses      18793    18759      -34     
Impacted Files Coverage Δ
src/graph/validator/ACLValidator.h 89.65% <ø> (ø)
src/meta/processors/job/JobManager.h 100.00% <ø> (ø)
src/meta/processors/job/JobManager.cpp 70.32% <6.25%> (-1.66%) ⬇️
src/meta/processors/parts/DropSpaceProcessor.cpp 64.35% <58.33%> (-0.82%) ⬇️
src/storage/exec/StorageIterator.h 93.33% <81.81%> (-1.98%) ⬇️
src/common/function/FunctionManager.cpp 79.44% <100.00%> (+0.12%) ⬆️
src/graph/optimizer/rule/PushEFilterDownRule.cpp 78.35% <100.00%> (-0.44%) ⬇️
src/graph/validator/ACLValidator.cpp 74.48% <100.00%> (+1.96%) ⬆️
src/graph/visitor/ExtractFilterExprVisitor.cpp 75.18% <100.00%> (+0.09%) ⬆️
src/graph/visitor/PropertyTrackerVisitor.cpp 82.97% <100.00%> (-1.28%) ⬇️
... and 44 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Scenario: Order by after match
When executing query:
"""
match (v)-[e:like|teammate{start_year: 2010}]->() where id(v) == 'Tim Duncan' return e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In openCypher, this edge filter means to find these edges which contain like or teammate labels and have the property start_year equal to 2010. So I think this filter should be converted to following format in NebulaGraph:

("like" in tags(e) and e.like.start_year = 2010) or ("teammate" in tags(e) and e.teammate.start_year=2010)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not only *.prop = xxxx, but we should have an equivalent representation of *.prop of edge property consists multiple edge types.

@Shylock-Hg Shylock-Hg requested a review from yixinglu November 7, 2022 06:31
@@ -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__},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new added _any function, is it callable from query?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood correctly, it seems to me that you mean _all, not _any. If there are 10 edge types, all of which has the same prop: prop_x, the semantics of any could be satisfied if only 1 such prop_x is found from all 10 edge types. all means making sure and finding all prop_x from all 10 edge types. I think you mean the latter one.

}
static_cast<LogicalExpression *>(ret)->setOperands(std::move(operands));
ret = FunctionCallExpression::make(pool, "_any", args);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just rewrite it as like.start_year==2010 or teammate.start_year==2010?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about others?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`like.start_year > xx' ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`like.start_year > xx' ?

This filter could not be used in path pattern. I don't understand the purpose of the _any inner function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Storage don't support *.prop, so rewrite it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @czpmango comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what @Shylock-Hg wants is a generic way. In the path pattern alone, however, rewriting with == suffices.

@Shylock-Hg Shylock-Hg added the type/bug Type: something is unexpected label Nov 9, 2022
return arg.get();
}
}
return Value::kNullBadData;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kNullBadData is designed for error andkNullValue is sufficient for ignoring behavior. Fwiw, the bad null should be passed through by all functions or expressions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What' your meaning?

@Shylock-Hg Shylock-Hg requested a review from czpmango November 22, 2022 02:12
@xtcyclist xtcyclist force-pushed the fix/rewrite-edge-filter branch from 44905d0 to 55fa604 Compare December 2, 2022 02:21
Copy link
Contributor

@xtcyclist xtcyclist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*.prop equals to something like union(e1.prop, e2,prop ...) semantically, not _any(e1.prop, e2,prop ...). Please make sure it's ok to change such semantics.

@Shylock-Hg
Copy link
Contributor Author

Shylock-Hg commented Dec 2, 2022

*.prop equals to something like union(e1.prop, e2,prop ...) semantically, not _any(e1.prop, e2,prop ...). Please make sure it's ok to change such semantics.

match (v)-[e:like|serve]->() return e.likeness will return any non-null value of like.likeness or serve. likeness

@Shylock-Hg Shylock-Hg requested a review from xtcyclist December 2, 2022 02:34
@jievince
Copy link
Contributor

jievince commented Dec 5, 2022

Please look at this issue: #4989

Comment on lines +2825 to +2839
// 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;
};
}
Copy link
Contributor

@jievince jievince Dec 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think _any is very similar to the function

coalesce() | coalesce(input :: ANY?) :: (ANY?) | Returns the first non-null value in a list of expressions.

Both neo4j and nebula support it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to resuse it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ignore EMPTY too.

@Shylock-Hg Shylock-Hg requested a review from jievince December 6, 2022 03:30
@jievince jievince mentioned this pull request Dec 6, 2022
11 tasks
@yixinglu yixinglu merged commit fef6560 into vesoft-inc:master Dec 6, 2022
@Shylock-Hg Shylock-Hg deleted the fix/rewrite-edge-filter branch December 6, 2022 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review ready-for-testing PR: ready for the CI test type/bug Type: something is unexpected
Projects
None yet
8 participants