Skip to content

Commit

Permalink
[WiP] Attempting to support Druid's granularity origin as a hidden ur…
Browse files Browse the repository at this point in the history
…l param (#194)

* Supporting Druid'd time origin feature

* Adding origin to form, making it free form
  • Loading branch information
mistercrunch committed Apr 16, 2016
1 parent f316851 commit 899fe19
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
14 changes: 12 additions & 2 deletions caravel/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ def __init__(self, viz):
'Y',
choices=self.choicify(datasource.column_names),
description="Columns to display"),
'druid_time_origin': SelectField(
'Origin',
choices=(
('', 'default'),
('now', 'now'),
),
description=(
"Defines the origin where time buckets start, "
"accepts natural dates as in 'now', 'sunday' or '1970-01-01'")),
'granularity': FreeFormSelectField(
'Time Granularity', default="one day",
choices=self.choicify([
Expand Down Expand Up @@ -617,9 +626,10 @@ def add_to_form(attrs):
time_fields = 'granularity_sqla'
add_to_form((time_fields, ))
else:
time_fields = 'granularity'
add_to_form(('granularity',))
time_fields = ('granularity', 'druid_time_origin')
add_to_form(('granularity', 'druid_time_origin'))
field_css_classes['granularity'] = ['form-control', 'select2_freeform']
field_css_classes['druid_time_origin'] = ['form-control', 'select2_freeform']
add_to_form(('since', 'until'))

QueryForm.fieldsets = ({
Expand Down
4 changes: 4 additions & 0 deletions caravel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,10 @@ def query(
granularity).total_seconds() * 1000
if not isinstance(granularity, string_types):
granularity = {"type": "duration", "duration": granularity}
origin = extras.get('druid_time_origin')
if origin:
dttm = utils.parse_human_datetime(origin)
granularity['origin'] = dttm.isoformat()

qry = dict(
datasource=self.datasource_name,
Expand Down
1 change: 1 addition & 0 deletions caravel/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def query_obj(self):
'where': form_data.get("where", ''),
'having': form_data.get("having", ''),
'time_grain_sqla': form_data.get("time_grain_sqla", ''),
'druid_time_origin': form_data.get("druid_time_origin", ''),
}
d = {
'granularity': granularity,
Expand Down

0 comments on commit 899fe19

Please sign in to comment.