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

DM-16496: add support for XOR #435

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

DM-16496: add support for XOR #435

wants to merge 1 commit into from

Conversation

n8pease
Copy link
Contributor

@n8pease n8pease commented Dec 18, 2018

No description provided.

Copy link
Contributor

@andy-slac andy-slac left a 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) {
Copy link
Contributor

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)) {
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 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));
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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

Copy link
Contributor Author

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,";
Copy link
Contributor

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)"
),
Copy link
Contributor

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

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, will do.

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants