-
Notifications
You must be signed in to change notification settings - Fork 18
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
DM-16496: add support for XOR #435
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK to my parser-untrained eye. Maybe more tests with more complicated grammar could be added to convince us that its perfect.
switch (_logicalOperatorType) { | ||
case LogicalOperatorCBH::AND: { | ||
logicalTerm = make_shared<query::AndTerm>(); | ||
for (auto term : _terms) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto const&
maybe to avoid copy (and below)
case LogicalOperatorCBH::AND: { | ||
logicalTerm = make_shared<query::AndTerm>(); | ||
for (auto term : _terms) { | ||
if (false == logicalTerm->merge(*term)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a special !
operator in C++ for this kind of test (also named not
) 😉
logicalTerm = make_shared<query::OrTerm>(); | ||
for (auto term : _terms) { | ||
if (false == logicalTerm->merge(*term)) { | ||
logicalTerm->addBoolTerm(make_shared<query::AndTerm>(term)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason you have to wrap it into AndTerm
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has something to do with getting it into disjunctive normal form. @fritzm can explain it to us (me, again) in the meeting tomorrow.
} else { | ||
auto term = dynamic_pointer_cast<query::BoolFactor>(otherTerm->copySyntax()); | ||
ASSERT_EXECUTION_CONDITION(term != nullptr, "XOR currently only works with BoolFactor", _ctx); | ||
term->setHasNot(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this handle terms that already have NOT, I mean something like:
A XOR NOT B
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hrm. good question! I'll investigate.
@@ -271,7 +273,9 @@ BoolFactorTerm::Ptr BetweenPredicate::clone() const { | |||
|
|||
void BetweenPredicate::dbgPrint(std::ostream& os) const { | |||
os << "BetweenPredicate(value:" << value; | |||
os << ", NOT:" << (hasNot ? "true" : "false"); | |||
if (hasNot) { | |||
os << " NOT,"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will make two commas
"select ra_PS, objectId from Object where (ra_PS > 1 and not ra_PS < 2) OR (not ra_PS > 1 and ra_PS < 2)", | ||
[](query::SelectStmt::Ptr const & selectStatement) {}, | ||
"SELECT ra_PS,objectId FROM Object WHERE (ra_PS>1 AND NOT ra_PS<2) OR (NOT ra_PS>1 AND ra_PS<2)" | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With that nontrivial transforms I'd prefer to see more tests with XOR combinations, e.g.
A XOR NOT B
NOT A XOR NOT B
A XOR B XOR C
A XOR B OR C XOR D
A XOR B AND C XOR D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last couple of expressions were about operator precedence but I'm not sure that they cover all cases correctly, try to think about more cases. In mysql XOR is between AND and OR in precedence.
No description provided.