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

yongjiezhao 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 0721f54  fix: use expected label in the metrics map (#15707)
0721f54 is described below

commit 0721f54580426c4f53902c59067438adf30d5955
Author: Yongjie Zhao <[email protected]>
AuthorDate: Fri Jul 16 07:02:00 2021 +0100

    fix: use expected label in the metrics map (#15707)
    
    * fix: use expected label in metrics map
    
    * added comments
    
    * fix type
---
 superset/connectors/sqla/models.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/superset/connectors/sqla/models.py 
b/superset/connectors/sqla/models.py
index a6aeabf..cf38631 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -887,7 +887,7 @@ class SqlaTable(  # pylint: 
disable=too-many-public-methods,too-many-instance-at
 
     def adhoc_metric_to_sqla(
         self, metric: AdhocMetric, columns_by_name: Dict[str, TableColumn]
-    ) -> Column:
+    ) -> ColumnElement:
         """
         Turn an adhoc metric into a sqlalchemy column.
 
@@ -917,8 +917,8 @@ class SqlaTable(  # pylint: 
disable=too-many-public-methods,too-many-instance-at
         return self.make_sqla_column_compatible(sqla_metric, label)
 
     def make_sqla_column_compatible(
-        self, sqla_col: Column, label: Optional[str] = None
-    ) -> Column:
+        self, sqla_col: ColumnElement, label: Optional[str] = None
+    ) -> ColumnElement:
         """Takes a sqlalchemy column object and adds label info if supported 
by engine.
         also adds quotes to the column if engine is configured for quotes.
         :param sqla_col: sqlalchemy column instance
@@ -1086,7 +1086,8 @@ class SqlaTable(  # pylint: 
disable=too-many-public-methods,too-many-instance-at
 
         # To ensure correct handling of the ORDER BY labeling we need to 
reference the
         # metric instance if defined in the SELECT clause.
-        metrics_exprs_by_label = {m.name: m for m in metrics_exprs}
+        # use the key of the ColumnClause for the expected label
+        metrics_exprs_by_label = {m.key: m for m in metrics_exprs}
         metrics_exprs_by_expr = {str(m): m for m in metrics_exprs}
 
         # Since orderby may use adhoc metrics, too; we need to process them 
first

Reply via email to