You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@superset.apache.org by GitBox <gi...@apache.org> on 2018/01/12 05:45:38 UTC

[GitHub] mistercrunch closed pull request #4114: Fix using undefined DruidMetrics for limit_spec

mistercrunch closed pull request #4114: Fix using undefined DruidMetrics for limit_spec
URL: https://github.com/apache/incubator-superset/pull/4114
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/connectors/druid/models.py b/superset/connectors/druid/models.py
index a1d9ec0944..ca35aaefe7 100644
--- a/superset/connectors/druid/models.py
+++ b/superset/connectors/druid/models.py
@@ -1001,6 +1001,22 @@ def intervals_from_dttms(self, from_dttm, to_dttm):
             to_dttm.isoformat() if to_dttm else '',
         )
 
+    @staticmethod
+    def _dimensions_to_values(dimensions):
+        """
+        Replace dimensions specs with their `dimension`
+        values, and ignore those without
+        """
+        values = []
+        for dimension in dimensions:
+            if isinstance(dimension, dict):
+                if 'dimension' in dimension:
+                    values.append(dimension['dimension'])
+            else:
+                values.append(dimension)
+
+        return values
+
     def run_query(  # noqa / druid
             self,
             groupby, metrics,
@@ -1101,12 +1117,9 @@ def run_query(  # noqa / druid
             pre_qry['threshold'] = min(row_limit,
                                        timeseries_limit or row_limit)
             pre_qry['metric'] = order_by
-            if isinstance(dim, dict):
-                if 'dimension' in dim:
-                    pre_qry['dimension'] = dim['dimension']
-            else:
-                pre_qry['dimension'] = dim
+            pre_qry['dimension'] = self._dimensions_to_values(qry.get('dimensions'))[0]
             del pre_qry['dimensions']
+
             client.topn(**pre_qry)
             logging.info('Phase 1 Complete')
             query_str += '// Two phase query\n// Phase 1\n'
@@ -1136,11 +1149,17 @@ def run_query(  # noqa / druid
             logging.info('Running groupby query for dimensions [{}]'.format(dimensions))
             if timeseries_limit and is_timeseries:
                 logging.info('Running two-phase query for timeseries')
-                order_by = metrics[0] if metrics else self.metrics[0]
+
+                pre_qry = deepcopy(qry)
+                pre_qry_dims = self._dimensions_to_values(qry['dimensions'])
+                pre_qry['dimensions'] = list(set(pre_qry_dims))
+
+                order_by = metrics[0] if metrics else pre_qry_dims[0]
+
                 if timeseries_limit_metric:
                     order_by = timeseries_limit_metric
+
                 # Limit on the number of timeseries, doing a two-phases query
-                pre_qry = deepcopy(qry)
                 pre_qry['granularity'] = 'all'
                 pre_qry['limit_spec'] = {
                     'type': 'default',
@@ -1152,16 +1171,6 @@ def run_query(  # noqa / druid
                         'direction': order_direction,
                     }],
                 }
-                pre_qry_dims = []
-                # Replace dimensions specs with their `dimension`
-                # values, and ignore those without
-                for dim in qry['dimensions']:
-                    if isinstance(dim, dict):
-                        if 'dimension' in dim:
-                            pre_qry_dims.append(dim['dimension'])
-                    else:
-                        pre_qry_dims.append(dim)
-                pre_qry['dimensions'] = list(set(pre_qry_dims))
                 client.groupby(**pre_qry)
                 logging.info('Phase 1 Complete')
                 query_str += '// Two phase query\n// Phase 1\n'
@@ -1180,12 +1189,13 @@ def run_query(  # noqa / druid
                 )
                 qry['limit_spec'] = None
             if row_limit:
+                dimension_values = self._dimensions_to_values(dimensions)
                 qry['limit_spec'] = {
                     'type': 'default',
                     'limit': row_limit,
                     'columns': [{
                         'dimension': (
-                            metrics[0] if metrics else self.metrics[0]),
+                            metrics[0] if metrics else dimension_values[0]),
                         'direction': order_direction,
                     }],
                 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services