'Test generation of metrics and post-aggregations from an initial list
of superset metrics (which may include the results of either). This
primarily tests that specifying a post-aggregator metric will also
require the raw aggregation of the associated druid metric column.'

def test_metrics_and_post_aggs(self):

    metrics_dict = {u'unused_count': DruidMetric(metric_name=u'unused_count', verbose_name=u'COUNT(*)', metric_type=u'count', json=json.dumps({u'type': u'count', u'name': u'unused_count'})), u'some_sum': DruidMetric(metric_name=u'some_sum', verbose_name=u'SUM(*)', metric_type=u'sum', json=json.dumps({u'type': u'sum', u'name': u'sum'})), u'a_histogram': DruidMetric(metric_name=u'a_histogram', verbose_name=u'APPROXIMATE_HISTOGRAM(*)', metric_type=u'approxHistogramFold', json=json.dumps({u'type': u'approxHistogramFold', u'name': u'a_histogram'})), u'aCustomMetric': DruidMetric(metric_name=u'aCustomMetric', verbose_name=u'MY_AWESOME_METRIC(*)', metric_type=u'aCustomType', json=json.dumps({u'type': u'customMetric', u'name': u'aCustomMetric'})), u'quantile_p95': DruidMetric(metric_name=u'quantile_p95', verbose_name=u'P95(*)', metric_type=u'postagg', json=json.dumps({u'type': u'quantile', u'probability': 0.95, u'name': u'p95', u'fieldName': u'a_histogram'})), u'aCustomPostAgg': DruidMetric(metric_name=u'aCustomPostAgg', verbose_name=u'CUSTOM_POST_AGG(*)', metric_type=u'postagg', json=json.dumps({u'type': u'customPostAgg', u'name': u'aCustomPostAgg', u'field': {u'type': u'fieldAccess', u'fieldName': u'aCustomMetric'}}))}
    metrics = [u'some_sum']
    (all_metrics, post_aggs) = DruidDatasource._metrics_and_post_aggs(metrics, metrics_dict)
    assert (all_metrics == [u'some_sum'])
    assert (post_aggs == {})
    metrics = [u'quantile_p95']
    (all_metrics, post_aggs) = DruidDatasource._metrics_and_post_aggs(metrics, metrics_dict)
    result_postaggs = set([u'quantile_p95'])
    assert (all_metrics == [u'a_histogram'])
    assert (set(post_aggs.keys()) == result_postaggs)
    metrics = [u'aCustomPostAgg']
    (all_metrics, post_aggs) = DruidDatasource._metrics_and_post_aggs(metrics, metrics_dict)
    result_postaggs = set([u'aCustomPostAgg'])
    assert (all_metrics == [u'aCustomMetric'])
    assert (set(post_aggs.keys()) == result_postaggs)
