mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
[WiP] Attempting to support Druid's granularity origin as a hidden url param (#194)
* Supporting Druid'd time origin feature * Adding origin to form, making it free form
This commit is contained in:
parent
f3168518e2
commit
899fe19afb
@ -214,6 +214,15 @@ class FormFactory(object):
|
||||
'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([
|
||||
@ -617,9 +626,10 @@ class FormFactory(object):
|
||||
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 = ({
|
||||
|
@ -1013,6 +1013,10 @@ class DruidDatasource(Model, AuditMixinNullable, Queryable):
|
||||
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,
|
||||
|
@ -206,6 +206,7 @@ class BaseViz(object):
|
||||
'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,
|
||||
|
Loading…
Reference in New Issue
Block a user