This is an automated email from the ASF dual-hosted git repository.

yjc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new deebd6f  fix(viz): missing groupby and broken adhoc metrics for 
boxplot (#12556)
deebd6f is described below

commit deebd6f7388f0c61481845dc5c4f3e26c7bc36ca
Author: Jesse Yang <[email protected]>
AuthorDate: Fri Jan 15 17:03:12 2021 -0800

    fix(viz): missing groupby and broken adhoc metrics for boxplot (#12556)
---
 superset/common/query_context.py   | 3 ++-
 superset/common/query_object.py    | 6 +++++-
 superset/connectors/sqla/models.py | 3 ++-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/superset/common/query_context.py b/superset/common/query_context.py
index a7900cf..0411007 100644
--- a/superset/common/query_context.py
+++ b/superset/common/query_context.py
@@ -142,7 +142,7 @@ class QueryContext:
     def df_metrics_to_num(df: pd.DataFrame, query_object: QueryObject) -> None:
         """Converting metrics to numeric when pandas.read_sql cannot"""
         for col, dtype in df.dtypes.items():
-            if dtype.type == np.object_ and col in query_object.metrics:
+            if dtype.type == np.object_ and col in query_object.metric_names:
                 df[col] = pd.to_numeric(df[col], errors="coerce")
 
     def get_data(self, df: pd.DataFrame,) -> Union[str, List[Dict[str, Any]]]:
@@ -166,6 +166,7 @@ class QueryContext:
         if self.result_type == utils.ChartDataResultType.SAMPLES:
             row_limit = query_obj.row_limit or math.inf
             query_obj = copy.copy(query_obj)
+            query_obj.is_timeseries = False
             query_obj.orderby = []
             query_obj.groupby = []
             query_obj.metrics = []
diff --git a/superset/common/query_object.py b/superset/common/query_object.py
index 43f7fee..cabbba6 100644
--- a/superset/common/query_object.py
+++ b/superset/common/query_object.py
@@ -28,7 +28,7 @@ from superset import app, is_feature_enabled
 from superset.exceptions import QueryObjectValidationError
 from superset.typing import Metric
 from superset.utils import pandas_postprocessing
-from superset.utils.core import DTTM_ALIAS, json_int_dttm_ser
+from superset.utils.core import DTTM_ALIAS, get_metric_names, json_int_dttm_ser
 from superset.utils.date_parser import get_since_until, parse_human_timedelta
 from superset.views.utils import get_time_range_endpoints
 
@@ -212,6 +212,10 @@ class QueryObject:
                         )
                     self.extras[field.new_name] = value
 
+    @property
+    def metric_names(self) -> List[str]:
+        return get_metric_names(self.metrics)
+
     def to_dict(self) -> Dict[str, Any]:
         query_object_dict = {
             "granularity": self.granularity,
diff --git a/superset/connectors/sqla/models.py 
b/superset/connectors/sqla/models.py
index 65c2a9f..d0887cd 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -993,6 +993,7 @@ class SqlaTable(  # pylint: 
disable=too-many-public-methods,too-many-instance-at
 
         time_range_endpoints = extras.get("time_range_endpoints")
         groupby_exprs_with_timestamp = 
OrderedDict(groupby_exprs_sans_timestamp.items())
+
         if granularity:
             dttm_col = columns_by_name[granularity]
             time_grain = extras.get("time_grain_sqla")
@@ -1032,7 +1033,7 @@ class SqlaTable(  # pylint: 
disable=too-many-public-methods,too-many-instance-at
 
         tbl = self.get_from_clause(template_processor)
 
-        if (is_sip_38 and metrics) or (not is_sip_38 and not columns):
+        if groupby_exprs_with_timestamp:
             qry = qry.group_by(*groupby_exprs_with_timestamp.values())
 
         where_clause_and = []

Reply via email to