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

905 store min max date in metadata for versionstore #952

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion arctic/store/version_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,27 @@ def append(self, symbol, data, metadata=None, prune_previous_version=True, upser
metadata=version.pop('metadata', None), data=None,
host=self._arctic_lib.arctic.mongo_host)


def _add_min_max_date_to_metadata(self, metadata, data):
min_data=max_date = None

if 'date' in data.index.names:
dates = data.index.get_level_values('date')
min_date = dates.min()
max_date = dates.max()

elif 'date' in data.columns:
min_date = data['date'].min()
max_date = data['date'].max()

metadata = metadata or {}

if 'min_date' not in metadata and 'max_date' not in metadata:
metadata['min_date'] = min_date
metadata['max_date'] = max_date

return metadata

@mongo_retry
def write(self, symbol, data, metadata=None, prune_previous_version=True, **kwargs):
"""
Expand Down Expand Up @@ -642,7 +663,7 @@ def write(self, symbol, data, metadata=None, prune_previous_version=True, **kwar
version['version'] = self._version_nums.find_one_and_update({'symbol': symbol},
{'$inc': {'version': 1}},
upsert=True, new=True)['version']
version['metadata'] = metadata
version['metadata'] = self._add_min_max_date_to_metadata(metadata, data)

previous_version = self._versions.find_one({'symbol': symbol, 'version': {'$lt': version['version']}},
sort=[('version', pymongo.DESCENDING)])
Expand Down