Skip to content

Adding $nor operator support #4768

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

Merged
merged 14 commits into from
May 18, 2018
Merged

Conversation

jeremypiednoel
Copy link
Contributor

@jeremypiednoel jeremypiednoel commented May 18, 2018

@dplewis tell me if you want me to investigate on postgresql !

@dplewis
Copy link
Member

dplewis commented May 18, 2018

@jeremypiednoel Go for it! Let me know if you need anything.

@jeremypiednoel
Copy link
Contributor Author

@dplewis I'm very noob in postgresql. So let's see if i can figure out

@flovilmart
Copy link
Contributor

flovilmart commented May 18, 2018

Very nice! We'll need to add some docs as the logical explanation is not trivial for a non seasoned developer.

@jeremypiednoel
Copy link
Contributor Author

jeremypiednoel commented May 18, 2018

Btw am i the only one to have pb with .github/ISSUE_TEMPLATE/Bug_report.md maybe it's my IDE but it always updates this file and ask me to commit it

@flovilmart
Copy link
Contributor

@jeremypiednoel did you pull the latest master& this should be good now.

@jeremypiednoel
Copy link
Contributor Author

see the latest commit it's a CRLF error i think. does it make sense to fix it ?

@dplewis
Copy link
Member

dplewis commented May 18, 2018

@jeremypiednoel That issue was fixed minutes ago #4767

@jeremypiednoel
Copy link
Contributor Author

@dplewis very true i had to commit the file first to pull the upstream then.
nvm it's fixed 👍

@jeremypiednoel
Copy link
Contributor Author

@dplewis how can i specify i want the test to run on postgresql ?

@dplewis
Copy link
Member

dplewis commented May 18, 2018

@jeremypiednoel
Copy link
Contributor Author

Thanks ! i'll try to make it work

@dplewis
Copy link
Member

dplewis commented May 18, 2018

@jeremypiednoel If you want to cheat you can find a solution on my branch for PG.

https://github.com/dplewis/parse-server/tree/nor-op

You will still need test for empty $nor array (I know that mongo and pg throws an error for nonempty $or, $and, $nor) and a test for invalid nor (not array)

@jeremypiednoel
Copy link
Contributor Author

thnaks @dplewis i'm gonna check that after lunch !

@codecov
Copy link

codecov bot commented May 18, 2018

Codecov Report

Merging #4768 into master will decrease coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4768      +/-   ##
==========================================
- Coverage   92.68%   92.64%   -0.05%     
==========================================
  Files         119      119              
  Lines        8659     8663       +4     
==========================================
  Hits         8026     8026              
- Misses        633      637       +4
Impacted Files Coverage Δ
src/Adapters/Storage/Mongo/MongoTransform.js 86.66% <100%> (-0.03%) ⬇️
...dapters/Storage/Postgres/PostgresStorageAdapter.js 97.13% <100%> (ø) ⬆️
src/Controllers/DatabaseController.js 94.64% <100%> (+0.04%) ⬆️
src/Adapters/Auth/meetup.js 84.21% <0%> (-5.27%) ⬇️
src/RestWrite.js 93.06% <0%> (-0.55%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a9ebc2b...318501c. Read the comment docs.

@jeremypiednoel
Copy link
Contributor Author

@dplewis can you take a look ?

@@ -2567,6 +2567,48 @@ describe('Parse.Query testing', () => {
});
});

it('$select inside $nor', (done) => {
Copy link
Member

Choose a reason for hiding this comment

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

Change the name as $select isn't being used here

obj.save().then(() => {
return rp.get(Parse.serverURL + "/classes/TestObject", options);
}).then(done.fail).catch((error) => {
equal(error.error.code, Parse.Error.INVALID_JSON);
Copy link
Member

Choose a reason for hiding this comment

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

Should be INVALID_QUERY.

@@ -62,7 +62,7 @@ const validateQuery = (query: any): void => {
}

if (query.$or) {
if (query.$or instanceof Array) {
Copy link
Member

Choose a reason for hiding this comment

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

Revert these changes to $or and $and as are they are causing tests to fail.

They also have nothing to do with the PR.

});
});

it('$nor invalid query', (done) => {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe another test when $nor: 1234 (non array)

@jeremypiednoel
Copy link
Contributor Author

Thanks for the feedback, it's fixed

i'll fix the minimum size of the $and and $or in another PR according to the mongo doc

$and performs a logical AND operation on an array of two or more expressions
The $or operator performs a logical OR operation on an array of two or more

@dplewis dplewis requested a review from flovilmart May 18, 2018 18:10
dplewis
dplewis previously approved these changes May 18, 2018
const clauses = [];
const clauseValues = [];
fieldValue.forEach((subQuery) => {
const clause = buildWhereClause({ schema, query: subQuery, index });
if (clause.pattern.length > 0) {
if (fieldName === '$nor') {
clause.pattern = `(NOT ${clause.pattern})`;
}
Copy link
Contributor

@flovilmart flovilmart May 18, 2018

Choose a reason for hiding this comment

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

you're doing (NOT query1) AND (NOT query2) instead of NOT (query1 OR query2) whhich tecnically work but can be a bit misleading for maintenance. Can« you document it or revert the logic with the help of line 323? Event if it's the same, rtaht will help for comprehension in the future ;)

Copy link
Member

Choose a reason for hiding this comment

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

True I was pretty lazy 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I figured it worked but letMs write it cleanly please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll fix that

Copy link
Contributor

@flovilmart flovilmart left a comment

Choose a reason for hiding this comment

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

A small nit for maintainability :)

@jeremypiednoel
Copy link
Contributor Author

@flovilmart @dplewis i reverted the logic.
Thanks for the feedbacks

@flovilmart
Copy link
Contributor

@jeremypiednoel thanks for the changes, looking good, waiting for the CI.

@jeremypiednoel
Copy link
Contributor Author

@flovilmart do you think it makes sense to add the array.length test on $end and $or conditions ?

@flovilmart
Copy link
Contributor

Let’s not change it now, as it would be a breaking change for the clients (change in behavior) that yield an error instead of returning results.

@dplewis dplewis merged commit 77ed10f into parse-community:master May 18, 2018
@dplewis dplewis mentioned this pull request May 24, 2018
8 tasks
UnderratedDev pushed a commit to UnderratedDev/parse-server that referenced this pull request Mar 21, 2020
* adding nor to specialQuerykeys

* adding nor suport

* adding test

* CRLF

* adding postgres NOR

* adding nor validation

* adding NOR test

* adding test amd fixing NOR cases

* revert the nor logic
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.

3 participants