Skip to content

Commit

Permalink
Recursively get the dependency fields of post aggregators (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
x4base authored and mistercrunch committed May 5, 2016
1 parent 6941f1d commit bc71707
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions caravel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,16 +1062,26 @@ def query( # druid
metrics_dict = {m.metric_name: m for m in self.metrics}
all_metrics = []
post_aggs = {}

def recursive_get_fields(_conf):
_fields = _conf.get('fields', [])
field_names = []
for _f in _fields:
_type = _f.get('type')
if _type == 'fieldAccess':
field_names.append(_f.get('fieldName'))
elif _type == 'arithmetic':
field_names += recursive_get_fields(_f)

return list(set(field_names))

for metric_name in metrics:
metric = metrics_dict[metric_name]
if metric.metric_type != 'postagg':
all_metrics.append(metric_name)
else:
conf = metric.json_obj
fields = conf.get('fields', [])
all_metrics += [
f.get('fieldName') for f in fields
if f.get('type') == 'fieldAccess']
all_metrics += recursive_get_fields(conf)
all_metrics += conf.get('fieldNames', [])
if conf.get('type') == 'javascript':
post_aggs[metric_name] = JavascriptPostAggregator(
Expand Down

0 comments on commit bc71707

Please sign in to comment.