superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ville...@apache.org
Subject [incubator-superset] branch master updated: compile column names (#7646)
Date Wed, 19 Jun 2019 18:48:53 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 43ea51b  compile column names (#7646)
43ea51b is described below

commit 43ea51b701a6df4a110d9ec70c34e19d517b90a4
Author: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
AuthorDate: Wed Jun 19 21:48:45 2019 +0300

    compile column names (#7646)
---
 superset/data/birth_names.py | 8 ++++++--
 superset/data/country_map.py | 4 +++-
 superset/data/energy.py      | 4 +++-
 superset/data/world_bank.py  | 5 ++++-
 4 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/superset/data/birth_names.py b/superset/data/birth_names.py
index 4f11ac5..85de019 100644
--- a/superset/data/birth_names.py
+++ b/superset/data/birth_names.py
@@ -19,6 +19,7 @@ import textwrap
 
 import pandas as pd
 from sqlalchemy import DateTime, String
+from sqlalchemy.sql import column
 
 from superset import db, security_manager
 from superset.connectors.sqla.models import SqlMetric, TableColumn
@@ -64,15 +65,18 @@ def load_birth_names():
     obj.filter_select_enabled = True
 
     if not any(col.column_name == 'num_california' for col in obj.columns):
+        col_state = str(column('state').compile(db.engine))
+        col_num = str(column('num').compile(db.engine))
         obj.columns.append(TableColumn(
             column_name='num_california',
-            expression="CASE WHEN state = 'CA' THEN num ELSE 0 END",
+            expression=f"CASE WHEN {col_state} = 'CA' THEN {col_num} ELSE 0 END",
         ))
 
     if not any(col.metric_name == 'sum__num' for col in obj.metrics):
+        col = str(column('num').compile(db.engine))
         obj.metrics.append(SqlMetric(
             metric_name='sum__num',
-            expression='SUM(num)',
+            expression=f'SUM({col})',
         ))
 
     db.session.merge(obj)
diff --git a/superset/data/country_map.py b/superset/data/country_map.py
index e74638b..303b85d 100644
--- a/superset/data/country_map.py
+++ b/superset/data/country_map.py
@@ -18,6 +18,7 @@ import datetime
 
 import pandas as pd
 from sqlalchemy import BigInteger, Date, String
+from sqlalchemy.sql import column
 
 from superset import db
 from superset.connectors.sqla.models import SqlMetric
@@ -69,9 +70,10 @@ def load_country_map_data():
     obj.main_dttm_col = 'dttm'
     obj.database = utils.get_or_create_main_db()
     if not any(col.metric_name == 'avg__2004' for col in obj.metrics):
+        col = str(column('2004').compile(db.engine))
         obj.metrics.append(SqlMetric(
             metric_name='avg__2004',
-            expression='AVG(2004)',
+            expression=f'AVG({col})',
         ))
     db.session.merge(obj)
     db.session.commit()
diff --git a/superset/data/energy.py b/superset/data/energy.py
index e1d48e7..293dca5 100644
--- a/superset/data/energy.py
+++ b/superset/data/energy.py
@@ -20,6 +20,7 @@ import textwrap
 
 import pandas as pd
 from sqlalchemy import Float, String
+from sqlalchemy.sql import column
 
 from superset import db
 from superset.connectors.sqla.models import SqlMetric
@@ -54,9 +55,10 @@ def load_energy():
     tbl.database = utils.get_or_create_main_db()
 
     if not any(col.metric_name == 'sum__value' for col in tbl.metrics):
+        col = str(column('value').compile(db.engine))
         tbl.metrics.append(SqlMetric(
             metric_name='sum__value',
-            expression='SUM(value)',
+            expression=f'SUM({col})',
         ))
 
     db.session.merge(tbl)
diff --git a/superset/data/world_bank.py b/superset/data/world_bank.py
index 94aa468..d5370ec 100644
--- a/superset/data/world_bank.py
+++ b/superset/data/world_bank.py
@@ -22,6 +22,7 @@ import textwrap
 
 import pandas as pd
 from sqlalchemy import DateTime, String
+from sqlalchemy.sql import column
 
 from superset import db
 from superset.connectors.sqla.models import SqlMetric
@@ -75,9 +76,11 @@ def load_world_bank_health_n_pop():
     ]
     for m in metrics:
         if not any(col.metric_name == m for col in tbl.metrics):
+            aggr_func = m[:3]
+            col = str(column(m[5:]).compile(db.engine))
             tbl.metrics.append(SqlMetric(
                 metric_name=m,
-                expression=f'{m[:3]}({m[5:]})',
+                expression=f'{aggr_func}({col})',
             ))
 
     db.session.merge(tbl)


Mime
View raw message