superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johnbod...@apache.org
Subject [incubator-superset] 18/43: working version
Date Fri, 11 Jan 2019 02:22:22 GMT
This is an automated email from the ASF dual-hosted git repository.

johnbodley pushed a commit to branch feature--embeddable-charts-pilot
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git

commit 8f352e41ba7c228426aaf673415e8a0a763d5d54
Author: Conglei Shi <conglei.shi@airbnb.com>
AuthorDate: Fri Nov 30 13:15:22 2018 -0800

    working version
---
 superset/assets/src/visualizations/wordcloud/buildQuery.ts |  1 -
 .../assets/src/visualizations/wordcloud/transformProps.js  | 14 ++++++++------
 superset/connectors/sqla/models.py                         |  8 ++++----
 superset/utils/core.py                                     |  3 ++-
 4 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/superset/assets/src/visualizations/wordcloud/buildQuery.ts b/superset/assets/src/visualizations/wordcloud/buildQuery.ts
index f44f558..feee0de 100644
--- a/superset/assets/src/visualizations/wordcloud/buildQuery.ts
+++ b/superset/assets/src/visualizations/wordcloud/buildQuery.ts
@@ -6,7 +6,6 @@ export default function buildQuery(formData: FormData) {
   return buildQueryContext(formData, (baseQueryObject) => [{
     ...baseQueryObject,
     groupby: [formData.series],
-    metrics: [formData.metric],
     time_range: formData.time_range,
   }]);
 }
diff --git a/superset/assets/src/visualizations/wordcloud/transformProps.js b/superset/assets/src/visualizations/wordcloud/transformProps.js
index 87016de..183c63c 100644
--- a/superset/assets/src/visualizations/wordcloud/transformProps.js
+++ b/superset/assets/src/visualizations/wordcloud/transformProps.js
@@ -1,12 +1,14 @@
 function transformData(data, formData) {
   const { metric, series } = formData;
+  if (metric && series) {
+    const transformedData = data.map(datum => ({
+      text: datum[series],
+      size: datum[metric.label || metric],
+    }));
 
-  const transformedData = data.map(datum => ({
-    text: datum[series],
-    size: datum[metric.label || metric],
-  }));
-
-  return transformedData;
+    return transformedData;
+  }
+  return [];
 }
 
 export default function transformProps(chartProps) {
diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py
index 779e4a3..feb4c9a 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -572,7 +572,7 @@ class SqlaTable(Model, BaseDatasource):
 
         cols = {col.column_name: col for col in self.columns}
         metrics_dict = {m.metric_name: m for m in self.metrics}
-
+        print(metrics_dict)
         if not granularity and is_timeseries:
             raise Exception(_(
                 'Datetime column not provided as part table configuration '
@@ -583,10 +583,10 @@ class SqlaTable(Model, BaseDatasource):
         for m in metrics:
             if utils.is_adhoc_metric(m):
                 metrics_exprs.append(self.adhoc_metric_to_sqla(m, cols))
-            elif m in metrics_dict:
-                metrics_exprs.append(metrics_dict.get(m).get_sqla_col())
+            elif m['label'] in metrics_dict:
+                metrics_exprs.append(metrics_dict.get(m['label']).get_sqla_col())
             else:
-                raise Exception(_("Metric '{}' is not valid".format(m)))
+                raise Exception(_("Metric '{}' is not valid".format(m['label'])))
         if metrics_exprs:
             main_metric_expr = metrics_exprs[0]
         else:
diff --git a/superset/utils/core.py b/superset/utils/core.py
index 5bf3054..06d98ef 100644
--- a/superset/utils/core.py
+++ b/superset/utils/core.py
@@ -872,6 +872,7 @@ def get_main_database(session):
 def is_adhoc_metric(metric):
     return (
         isinstance(metric, dict) and
+        'expressionType' in metric and
         (
             (
                 metric['expressionType'] == ADHOC_METRIC_EXPRESSION_TYPES['SIMPLE'] and
@@ -888,7 +889,7 @@ def is_adhoc_metric(metric):
 
 
 def get_metric_name(metric):
-    return metric['label'] if is_adhoc_metric(metric) else metric
+    return metric['label']
 
 
 def get_metric_names(metrics):


Mime
View raw message