From fbb1f42c6e4e1153204f403fe1439bd213d65362 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Wed, 25 Nov 2015 18:32:13 -0800 Subject: [PATCH] don't merge predicate to negated and group --- src/object-store/parser/parser.cpp | 5 ++--- src/object-store/parser/queryTests.json | 3 ++- tests/QueryTests.js | 24 ------------------------ 3 files changed, 4 insertions(+), 28 deletions(-) diff --git a/src/object-store/parser/parser.cpp b/src/object-store/parser/parser.cpp index b9b0373d..f478d1c5 100644 --- a/src/object-store/parser/parser.cpp +++ b/src/object-store/parser/parser.cpp @@ -179,9 +179,8 @@ struct ParserState auto &sub_preds = current_group()->cpnd.sub_predicates; auto second_last = sub_preds.end() - 2; - if (second_last->type == Predicate::Type::And) { - // if we are in an OR group and second to last predicate group is - // an AND group then move the last predicate inside + if (second_last->type == Predicate::Type::And && !second_last->negate) { + // make a new and group populated with the last two predicates second_last->cpnd.sub_predicates.push_back(std::move(sub_preds.back())); sub_preds.pop_back(); } diff --git a/src/object-store/parser/queryTests.json b/src/object-store/parser/queryTests.json index 15f7fefa..630694e8 100644 --- a/src/object-store/parser/queryTests.json +++ b/src/object-store/parser/queryTests.json @@ -273,7 +273,8 @@ ["ObjectSet", [0, 1], "IntObject", "intCol == 0 || intCol == 1 && intCol >= 1"], ["ObjectSet", [0, 1, 2],"IntObject", "intCol == 0 || intCol == 1 || intCol <= 2"], ["ObjectSet", [0, 1], "IntObject", "intCol == 1 && intCol >= 1 || intCol == 0"], - ["ObjectSet", [0, 1], "IntObject", "intCol == 1 || intCol == 0 && intCol <= 0 && intCol >= 0"] + ["ObjectSet", [0, 1], "IntObject", "intCol == 1 || intCol == 0 && intCol <= 0 && intCol >= 0"], + ["ObjectSet", [0, 1], "IntObject", "intCol == 0 || NOT (intCol == 3 && intCol >= 0) && intCol == 1"] ] } diff --git a/tests/QueryTests.js b/tests/QueryTests.js index a26c6c02..093716d1 100644 --- a/tests/QueryTests.js +++ b/tests/QueryTests.js @@ -942,30 +942,6 @@ module.exports = BaseTest.extend({ XCTAssertThrows([CircleArrayObject objectsInRealm:realm where:@"NONE data.circles = '2'"]); } -- (void)testCompoundOrQuery { - RLMRealm *realm = [RLMRealm defaultRealm]; - - [realm beginWriteTransaction]; - [PersonObject createInRealm:realm withValue:@[@"Tim", @29]]; - [PersonObject createInRealm:realm withValue:@[@"Ari", @33]]; - [realm commitWriteTransaction]; - - XCTAssertEqual(2U, [[PersonObject objectsWhere:@"name == 'Ari' or age < 30"] count]); - XCTAssertEqual(1U, [[PersonObject objectsWhere:@"name == 'Ari' or age > 40"] count]); -} - -- (void)testCompoundAndQuery { - RLMRealm *realm = [RLMRealm defaultRealm]; - - [realm beginWriteTransaction]; - [PersonObject createInRealm:realm withValue:@[@"Tim", @29]]; - [PersonObject createInRealm:realm withValue:@[@"Ari", @33]]; - [realm commitWriteTransaction]; - - XCTAssertEqual(1U, [[PersonObject objectsWhere:@"name == 'Ari' and age > 30"] count]); - XCTAssertEqual(0U, [[PersonObject objectsWhere:@"name == 'Ari' and age > 40"] count]); -} - - (void)testClass:(Class)class withNormalCount:(NSUInteger)normalCount notCount:(NSUInteger)notCount