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

Added a Lark to Django Query converter #61

Merged

Conversation

tachyontraveler
Copy link
Member

Additions:

  • Query converter
  • A few tests for the same

@codecov
Copy link

codecov bot commented Sep 21, 2019

Codecov Report

Merging #61 into master will increase coverage by 1.56%.
The diff coverage is 92.85%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #61      +/-   ##
=========================================
+ Coverage   76.73%   78.3%   +1.56%     
=========================================
  Files          19      21       +2     
  Lines         649     719      +70     
=========================================
+ Hits          498     563      +65     
- Misses        151     156       +5
Impacted Files Coverage Δ
optimade/filtertransformers/tests/test_django.py 100% <100%> (ø)
optimade/filtertransformers/django.py 91.37% <91.37%> (ø)

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 ec204b0...47e9846. Read the comment docs.

@ml-evs
Copy link
Member

ml-evs commented Sep 23, 2019

Thanks for this @tachyontraveler , looks really useful.

Not a Django person, so happy to defer to you, but is there a reason we can't have the same interface as in MongoTransformer (which inherits from lark.Transformer), with basically the same tests? I can't immediately tell that they both have the same functionality at the moment (though I'm sure they do).

Would you also be able to run these through black if they haven't been already?

@tachyontraveler
Copy link
Member Author

Thanks for the comments and suggestions, @ml-evs .
I ran the scripts by black and committed those changes to this pull request.

About the Django transformer:
The Django's querying interface with SQL DBs is significantly different from that of MongoDB. So for the practical implementation of these complex queries, it is needed to use a set of django.db.models.Q class objects added together. As far as I know, Lark.Transformer is an excellent class to make string-type query combinations, but making a queryset based on an external class is either impossible as of now, or not so straightforward to my knowledge.
Because of the same reason, it wouldn't be possible to use the same unittest scripts to check the functionality of django.py script. I can confirm the reliance of these scripts since we've already implemented it successfully within OQMD database (to be released for public very soon). That said, I'd highly appreciate any further concerns or suggestions to improve these scripts at this point.

I used the non-generic keywords like band_gap and natoms on unittests since it's an example transformer to help anyone interested to quickly implement these scripts (specifying the connections of these keywords to their custom SQL DBs is an important part - as shown in the script)

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.

Hey @tachyontraveler , thanks for the details, I thought that might be the case. This is clearly useful for anyone using Django, so I'm happy to accept.

Adding some docstrings would be nice but understand time pressures, and don't want to hold you to a higher standard than the mongo equivalent!

@tachyontraveler
Copy link
Member Author

Great, thank for the review. I can definitely add the docstring sometime later.

@tachyontraveler tachyontraveler merged commit 72e3411 into Materials-Consortia:master Sep 25, 2019
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