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

Improve support for timestamp queries in MongoTransformer #590

Merged
merged 9 commits into from Jan 19, 2021

Conversation

ml-evs
Copy link
Member

@ml-evs ml-evs commented Nov 7, 2020

Addresses #102, where it was decided that timestamps should be handled by the transformers, rather than in the grammar themselves (which would have involved a horrible regexp, and goes slightly against the specification).

This PR adds an extra step in the MongoTransformer to detect OPTIMADE timestamp fields (just last_modified at the moment), and encode the filter value properly with BSON.

Pending the next few PRs (e.g. #504), filter transformers will get access to schemas directly, allowing them to directly query for e.g. fields of type DataType.TIMESTAMP, rather than hard-coding last_modified.

As RFC3339 does not support fractional seconds, the only operation that can be tested by the optimade-validator is >= (as fractional seconds will always lead to rounded times in the underlying database). This means that there will always be an inconsistency between e.g. the MongoDB server (which has milliseconds) and the JSON response (which does not).

  • Add postprocessing methods to find timestamps
  • Add filtertransformer tests
  • Add server tests to check documents are actually returned with various operations
  • Add server validation, modulo microseconds in the timestamp

@ml-evs ml-evs added enhancement New feature or request priority/medium Issue or PR with a consensus of medium priority transformer/MongoDB Related to filter transformer for MongoDB labels Nov 7, 2020
@codecov
Copy link

codecov bot commented Nov 7, 2020

Codecov Report

Merging #590 (2170328) into master (31818d4) will decrease coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #590      +/-   ##
==========================================
- Coverage   93.27%   93.18%   -0.09%     
==========================================
  Files          61       61              
  Lines        3344     3361      +17     
==========================================
+ Hits         3119     3132      +13     
- Misses        225      229       +4     
Flag Coverage Δ
project 93.18% <100.00%> (-0.09%) ⬇️
validator 66.17% <90.47%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
optimade/models/jsonapi.py 92.56% <ø> (ø)
optimade/validator/config.py 100.00% <ø> (ø)
optimade/filtertransformers/mongo.py 97.57% <100.00%> (+0.20%) ⬆️
optimade/server/warnings.py 87.50% <100.00%> (+0.83%) ⬆️
optimade/validator/validator.py 82.28% <100.00%> (-0.60%) ⬇️
optimade/server/exceptions.py 94.11% <0.00%> (-5.89%) ⬇️

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 31818d4...2170328. Read the comment docs.

@ml-evs ml-evs force-pushed the ml-evs/mongo_datetime branch 3 times, most recently from 0dcb4d3 to a4a5530 Compare November 23, 2020 15:47
@ml-evs ml-evs marked this pull request as ready for review November 23, 2020 16:08
""" Find cases where the query dict is operating on a timestamp field. """
if self.mapper is not None:
prop = self.mapper.alias_of(prop)
return prop == "last_modified"
Copy link
Member Author

Choose a reason for hiding this comment

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

Just a heads up, eventually this can use the mapper/schema mechanism to find all implementation-defined fields of type DataType.TIMESTAMP, but that will have to wait

@ml-evs ml-evs force-pushed the ml-evs/mongo_datetime branch 2 times, most recently from 3193e0c to a4a5530 Compare November 23, 2020 16:55
@ml-evs
Copy link
Member Author

ml-evs commented Dec 24, 2020

I think this was uncontroversial after our discussion on Slack a few weeks ago, so I'll merge these changes later today unless anyone stops me.

@ml-evs ml-evs force-pushed the ml-evs/mongo_datetime branch 6 times, most recently from 6f48fe0 to 9e4bfec Compare January 4, 2021 10:46
@ml-evs
Copy link
Member Author

ml-evs commented Jan 19, 2021

I think this was uncontroversial after our discussion on Slack a few weeks ago, so I'll merge these changes later today unless anyone stops me.

Forgot about this PR, @shyamd would be good if you could have a look as this will affect MP

@ml-evs ml-evs merged commit f759651 into master Jan 19, 2021
@ml-evs ml-evs deleted the ml-evs/mongo_datetime branch January 19, 2021 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority/medium Issue or PR with a consensus of medium priority transformer/MongoDB Related to filter transformer for MongoDB
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants