Skip to content

Commit

Permalink
Read the user origin specification. (#1541)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkyryliuk authored Nov 4, 2016
1 parent 3b9f7cb commit 6298707
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions caravel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,7 @@ def time_offset(granularity):
# http://druid.io/docs/0.8.0/querying/granularities.html
# TODO: pass origin from the UI
@staticmethod
def granularity(period_name, timezone=None):
def granularity(period_name, timezone=None, origin=None):
if not period_name or period_name == 'all':
return 'all'
iso_8601_dict = {
Expand All @@ -1828,6 +1828,10 @@ def granularity(period_name, timezone=None):
if timezone:
granularity['timezone'] = timezone

if origin:
dttm = utils.parse_human_datetime(origin)
granularity['origin'] = dttm.isoformat()

if period_name in iso_8601_dict:
granularity['period'] = iso_8601_dict[period_name]
if period_name in ('week_ending_saturday', 'week_starting_sunday'):
Expand Down Expand Up @@ -1931,7 +1935,10 @@ def recursive_get_fields(_conf):
dimensions=groupby,
aggregations=aggregations,
granularity=DruidDatasource.granularity(
granularity, timezone=timezone),
granularity,
timezone=timezone,
origin=extras.get('druid_time_origin'),
),
post_aggregations=post_aggs,
intervals=from_dttm.isoformat() + '/' + to_dttm.isoformat(),
)
Expand Down

0 comments on commit 6298707

Please sign in to comment.