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

Introduce grammar v0.10.1 #112

Merged
merged 15 commits into from Jan 14, 2020
Merged

Introduce grammar v0.10.1 #112

merged 15 commits into from Jan 14, 2020

Conversation

CasperWA
Copy link
Member

@CasperWA CasperWA commented Dec 12, 2019

Update from v0.10.0: Implement Materials-Consortia/OPTIMADE#221

I guess this needs some more additions as the OPTiMaDe spec is updated to v0.10.1.

IMPORTANT: This PR will up the package version to 0.3.0 and the OPTiMaDe version to 0.10.1.

@CasperWA CasperWA added the grammar Concerns the Lark grammar files label Dec 12, 2019
@codecov
Copy link

codecov bot commented Dec 12, 2019

Codecov Report

Merging #112 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #112   +/-   ##
=======================================
  Coverage   84.86%   84.86%           
=======================================
  Files          39       39           
  Lines        1817     1817           
=======================================
  Hits         1542     1542           
  Misses        275      275
Flag Coverage Δ
#unittests 84.86% <ø> (ø) ⬆️

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 8303424...b377b7b. Read the comment docs.

Copy link
Member

@ml-evs ml-evs left a comment

Choose a reason for hiding this comment

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

This also looks good to me, are we expecting any further grammar changes before 0.10.1, or can we get this merged?

@CasperWA
Copy link
Member Author

CasperWA commented Dec 22, 2019

This also looks good to me, are we expecting any further grammar changes before 0.10.1, or can we get this merged?

Not at the moment - but since v0.10.1 is not officially out, there definitely may come some. But most likely not for the grammar - so this should be good to go @ml-evs once approved.

@CasperWA
Copy link
Member Author

CasperWA commented Jan 7, 2020

Newest commit should also address the fact that constant <op> constant is not allowed if both are strings (Materials-Consortia/OPTIMADE#229).

@CasperWA CasperWA force-pushed the update_grammar_v0.10.1 branch 2 times, most recently from d70e3e2 to ed7c985 Compare January 8, 2020 09:53
@ml-evs
Copy link
Member

ml-evs commented Jan 8, 2020

This PR (nearly) closes #86, it would be good to have this working in the interim and then we can target #98 in a future PR.

Copy link
Member

@ml-evs ml-evs left a comment

Choose a reason for hiding this comment

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

This LGTM, though I'm trusting the grammar tests to spot any issues in the grammar file itself!

optimade/filtertransformers/mongo.py Show resolved Hide resolved
@CasperWA
Copy link
Member Author

CasperWA commented Jan 8, 2020

This PR (nearly) closes #86, it would be good to have this working in the interim and then we can target #98 in a future PR.

This PR doesn't really address the usage of the grammar, only the grammar itself.
So nothing should have really changed with respect to implementing LENGTH query (#86).

With respect to "the interrim" here, do you mean after or before merging this PR?

@ml-evs
Copy link
Member

ml-evs commented Jan 8, 2020

This PR doesn't really address the usage of the grammar, only the grammar itself.
So nothing should have really changed with respect to implementing LENGTH query (#86).

Misunderstanding: I thought length queries didn't work at all before this.

With respect to "the interrim" here, do you mean after or before merging this PR?

After!

@CasperWA
Copy link
Member Author

CasperWA commented Jan 8, 2020

This LGTM, though I'm trusting the grammar tests to spot any issues in the grammar file itself!

Right - I can see from the diff here that it's basically impossible to see the changes from v0.10.0.
So here's a short list:

  • Introduce non_string_value.
  • Use OPERATOR non_string_value instead of value_op_rhs for the value in constant_first_comparison.
  • Change predicate_comparison to length_op_rhs and set the value to the new LENGTH [ OPERATOR ] value.
  • Add length_op_rhs to property_first_comparison.
  • Remove predicate_comparison from expression_phrase.

@CasperWA
Copy link
Member Author

CasperWA commented Jan 8, 2020

The only issue I'm having, is how to clearly make a 501 Not Implemented response when constant <op> constant is made, where constant are strings?

We could probably do it in the transformer, but that's backend-specific, so one would have to always implement it for all transformers, which seems a bit weird. So I'd rather implement this in the grammar itself, in some way.

Also, is it fine if one of the constants is a string? This is the case now, as the first constant can be a string.

@CasperWA
Copy link
Member Author

CasperWA commented Jan 9, 2020

Since this PR updates the package version, I think I'm going to push and publish a tag to master immediately after merging this.

Copy link
Member

@ml-evs ml-evs left a comment

Choose a reason for hiding this comment

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

This is looking very close now @CasperWA!

As this constant <op> constant stuff is turning out to be quite fiddly, would you mind adding a couple of negative tests that show it raising the error? If it's something that has to be handled in the transformers, it would be good if the test is there and skipped even if its not working correctly as of this PR.

@CasperWA
Copy link
Member Author

CasperWA commented Jan 10, 2020

As this constant <op> constant stuff is turning out to be quite fiddly, would you mind adding a couple of negative tests that show it raising the error? If it's something that has to be handled in the transformers, it would be good if the test is there and skipped even if its not working correctly as of this PR.

Working on it now.

Could you possibly just push the changes you had in mind concerning using $where or something like that? Just don't touch the tests, since I am in the process of updating them.

EDIT: Reading the stackoverflow page @fekad has linked to in the transformer, it seems the intent was more to not use $where, but instead add information to an extra?

@ml-evs
Copy link
Member

ml-evs commented Jan 10, 2020

EDIT: Reading the stackoverflow page @fekad has linked to in the transformer, it seems the intent was more to not use $where, but instead add information to an extra?

Yeah it probably needs a bit more discussion on that issue (so I won't add anything to this PR), I'll write my thoughts there when I get a sec

There is no need to have the old MongoTransformer.
The current MongoTransformer should work for the newest grammar always.
Either that or one should create a new Transformer per grammar version -
this may be desired.

Start to convert previously skipped tests to run, using `assertRaises`
for not yet implemented parts.
@ml-evs
Copy link
Member

ml-evs commented Jan 10, 2020

Also does this currently close #82?

@CasperWA
Copy link
Member Author

CasperWA commented Jan 10, 2020

Also does this currently close #82?

Technically, yes. But as stated in the issue, the Transformer should be further tested, so that we now it truly works. But it should... At least for constant OPERATOR non-string-value, e.g., "5 < nelements" will be turned into {"nelements": {"$gt": 5}}.

However, does not work (as far as I know) for property OPERATOR property, so there is no flip, it will always be from left to right as written, but that should still make sense, I guess?

@ml-evs
Copy link
Member

ml-evs commented Jan 10, 2020

Does this also need to be updated? Currently the mongo tests run against the old grammar.

A special grammar expression `not_implemented_string` is used to detect
if strings are compared, while still making sure the Transformer can
handle the error.
This should be removed when comparisons of strings are properly
documented in the specification.
This is for all "valid" filter statement that have not yet been
implemented in the Transformer.
@CasperWA
Copy link
Member Author

Does this also need to be updated? Currently the mongo tests run against the old grammar.

Yup, it does. And it has. Feel free to re-review :)

@CasperWA CasperWA requested a review from ml-evs January 10, 2020 15:57
@CasperWA
Copy link
Member Author

CasperWA commented Jan 10, 2020

Also does this currently close #82?

Technically, yes. But as stated in the issue, the Transformer should be further tested, so that we now it truly works. But it should... At least for constant OPERATOR non-string-value, e.g., "5 < nelements" will be turned into {"nelements": {"$gt": 5}}.

However, does not work (as far as I know) for property OPERATOR property, so there is no flip, it will always be from left to right as written, but that should still make sense, I guess?

Thinking a bit more about this, I am not so sure this is true. There are several comparisons done in property_first_comparison that are not taken into account for constant_first_comparison that essentially "handles" RHS comparisons.

EDIT: Hmm... but then, reading the spec, it seems the RHS comparisons are only valid for logical operators, which is exactly what constant_first_comparison supports ... So it may work? But should be properly tested.

@ml-evs
Copy link
Member

ml-evs commented Jan 13, 2020

Thinking a bit more about this, I am not so sure this is true. There are several comparisons done in property_first_comparison that are not taken into account for constant_first_comparison that essentially "handles" RHS comparisons.

EDIT: Hmm... but then, reading the spec, it seems the RHS comparisons are only valid for logical operators, which is exactly what constant_first_comparison supports ... So it may work? But should be properly tested.

I think either way we should try to get this merged so we can have a chance to break it. There's still things to discuss in #86 and #98 for us to be completely compliant with 0.10.1 but this PR is both very large and very useful :)

I'm happy to accept this as is, and you can decide whether you want to add some further tests for RHS comparisons (and whether to close #82) before merging!

@CasperWA
Copy link
Member Author

Is it all right to merge this, publish it as version 0.3.0 and then perhaps start using a develop branch for future PRs?

@ml-evs
Copy link
Member

ml-evs commented Jan 14, 2020

Is it all right to merge this, publish it as version 0.3.0 and then perhaps start using a develop branch for future PRs?

Makes sense to me.

@CasperWA CasperWA merged commit af87544 into master Jan 14, 2020
@CasperWA CasperWA deleted the update_grammar_v0.10.1 branch January 14, 2020 19:09
@CasperWA CasperWA mentioned this pull request Feb 5, 2020
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
grammar Concerns the Lark grammar files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants