superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johnbod...@apache.org
Subject [incubator-superset] 17/43: enable worldcloid
Date Fri, 11 Jan 2019 02:22:21 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 3deffcabdefc15f2f37b9531deb50b42dd9e11e5
Author: Conglei Shi <conglei.shi@airbnb.com>
AuthorDate: Fri Nov 30 09:57:05 2018 -0800

    enable worldcloid
---
 superset/assets/src/chart/chartAction.js                    |  2 +-
 superset/assets/src/explore/actions/saveModalActions.js     |  2 +-
 .../assets/src/explore/components/DisplayQueryButton.jsx    |  2 +-
 superset/assets/src/explore/exploreUtils.js                 | 13 ++++++++++++-
 superset/assets/src/visualizations/wordcloud/FormData.ts    |  2 ++
 superset/assets/src/visualizations/wordcloud/buildQuery.ts  |  2 ++
 .../assets/src/visualizations/wordcloud/transformProps.js   |  2 +-
 superset/common/query_context.py                            |  2 +-
 superset/common/query_object.py                             |  9 ++++++---
 superset/views/api.py                                       |  4 ++--
 10 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/superset/assets/src/chart/chartAction.js b/superset/assets/src/chart/chartAction.js
index 6c6ddab..c4a81b6 100644
--- a/superset/assets/src/chart/chartAction.js
+++ b/superset/assets/src/chart/chartAction.js
@@ -156,7 +156,7 @@ export function runQuery(formData, force = false, timeout = 60, key) {
 
     let querySettings = {
       url,
-      postPayload: { form_data: payload },
+      postPayload: { ...payload },
       signal,
       timeout: timeout * 1000,
     };
diff --git a/superset/assets/src/explore/actions/saveModalActions.js b/superset/assets/src/explore/actions/saveModalActions.js
index 1993a38..ac9c1be 100644
--- a/superset/assets/src/explore/actions/saveModalActions.js
+++ b/superset/assets/src/explore/actions/saveModalActions.js
@@ -52,7 +52,7 @@ export function saveSlice(formData, requestParams) {
       requestParams,
     });
 
-    return SupersetClient.post({ url, postPayload: { form_data: payload } })
+    return SupersetClient.post({ url, postPayload: { ...payload } })
       .then(({ json }) => dispatch(saveSliceSuccess(json)))
       .catch(() => dispatch(saveSliceFailed()));
   };
diff --git a/superset/assets/src/explore/components/DisplayQueryButton.jsx b/superset/assets/src/explore/components/DisplayQueryButton.jsx
index 1912b2c..5b838b8 100644
--- a/superset/assets/src/explore/components/DisplayQueryButton.jsx
+++ b/superset/assets/src/explore/components/DisplayQueryButton.jsx
@@ -61,7 +61,7 @@ export default class DisplayQueryButton extends React.PureComponent {
     });
     SupersetClient.post({
       url,
-      postPayload: { form_data: payload },
+      postPayload: { ...payload },
     })
       .then(({ json }) => {
         this.setState({
diff --git a/superset/assets/src/explore/exploreUtils.js b/superset/assets/src/explore/exploreUtils.js
index e9bcc9f..68b77d0 100644
--- a/superset/assets/src/explore/exploreUtils.js
+++ b/superset/assets/src/explore/exploreUtils.js
@@ -1,6 +1,7 @@
 /* eslint camelcase: 0 */
 import URI from 'urijs';
 import { availableDomains } from '../utils/hostNamesConfig';
+import { getChartBuildQueryRegistry } from '@superset-ui/chart';
 
 const MAX_URL_LENGTH = 8000;
 
@@ -39,6 +40,10 @@ export function getURIDirectory(formData, endpointType = 'base') {
   if (['json', 'csv', 'query', 'results', 'samples'].indexOf(endpointType) >= 0) {
     directory = '/superset/explore_json/';
   }
+  // const buildQueryRegistry = getChartBuildQueryRegistry();
+  if (formData.viz_type === 'word_cloud') {
+    directory = '/api/v1/query/';
+  }
   return directory;
 }
 
@@ -129,7 +134,13 @@ export function getExploreUrlAndPayload({
     });
   }
   uri = uri.search(search).directory(directory);
-  const payload = { ...formData };
+  let payload = { form_data: { ...formData } };
+
+  const buildQuery = getChartBuildQueryRegistry().get(formData.viz_type);
+  if (buildQuery) {
+    console.log(formData);
+    payload = { query_context: buildQuery(formData) };
+  }
 
   return {
     url: uri.toString(),
diff --git a/superset/assets/src/visualizations/wordcloud/FormData.ts b/superset/assets/src/visualizations/wordcloud/FormData.ts
index 55f8131..a2f85ea 100644
--- a/superset/assets/src/visualizations/wordcloud/FormData.ts
+++ b/superset/assets/src/visualizations/wordcloud/FormData.ts
@@ -3,6 +3,8 @@ import { FormData as GenericFormData } from 'src/query';
 // FormData specific to the wordcloud viz
 interface WordCloudFormData {
   series: string;
+  metric: string;
+  time_range: string;
 }
 
 // FormData for wordcloud contains both common properties of all form data
diff --git a/superset/assets/src/visualizations/wordcloud/buildQuery.ts b/superset/assets/src/visualizations/wordcloud/buildQuery.ts
index 2aa0f2c..f44f558 100644
--- a/superset/assets/src/visualizations/wordcloud/buildQuery.ts
+++ b/superset/assets/src/visualizations/wordcloud/buildQuery.ts
@@ -6,5 +6,7 @@ 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 ef824e9..87016de 100644
--- a/superset/assets/src/visualizations/wordcloud/transformProps.js
+++ b/superset/assets/src/visualizations/wordcloud/transformProps.js
@@ -21,7 +21,7 @@ export default function transformProps(chartProps) {
   return {
     width,
     height,
-    data: transformData(payload.data, formData),
+    data: transformData(payload[0].data, formData),
     colorScheme,
     rotation,
     sizeRange: [sizeFrom, sizeTo],
diff --git a/superset/common/query_context.py b/superset/common/query_context.py
index 82249a6..cb106f9 100644
--- a/superset/common/query_context.py
+++ b/superset/common/query_context.py
@@ -97,7 +97,7 @@ class QueryContext:
 
     def df_metrics_to_num(self, df, query_object):
         """Converting metrics to numeric when pandas.read_sql cannot"""
-        metrics = [metric.label for metric in query_object.metrics]
+        metrics = [metric for metric in query_object.metrics]
         for col, dtype in df.dtypes.items():
             if dtype.type == np.object_ and col in metrics:
                 df[col] = pd.to_numeric(df[col], errors='coerce')
diff --git a/superset/common/query_object.py b/superset/common/query_object.py
index 9e38263..edbc460 100644
--- a/superset/common/query_object.py
+++ b/superset/common/query_object.py
@@ -21,7 +21,7 @@ class QueryObject:
             granularity: str,
             groupby: List[str],
             metrics: List[Dict],
-            filters: List[str],
+            filters: List[str] = None,
             time_range: Optional[str] = None,
             time_shift: Optional[str] = None,
             is_timeseries: bool = False,
@@ -39,12 +39,13 @@ class QueryObject:
         self.groupby = groupby
         self.metrics = metrics
         self.row_limit = row_limit
+        self.filter = filters if filters is not None else []
         self.timeseries_limit = int(limit)
         self.timeseries_limit_metric = timeseries_limit_metric
         self.order_desc = order_desc
         self.prequeries = []
         self.is_prequery = False
-        self.extras = extras
+        self.extras = extras if extras is not None else {}
 
     def to_dict(self):
         query_object_dict = {
@@ -53,13 +54,15 @@ class QueryObject:
             'to_dttm': self.to_dttm,
             'is_timeseries': self.is_timeseries,
             'groupby': self.groupby,
+            'metrics': self.metrics,
             'row_limit': self.row_limit,
-            'filters': self.filter,
+            'filter': self.filter,
             'timeseries_limit': self.timeseries_limit,
             'timeseries_limit_metric': self.timeseries_limit_metric,
             'order_desc': self.order_desc,
             'prequeries': self.prequeries,
             'is_prequery': self.is_prequery,
+            'extras': self.extras,
         }
         query_object_dict.update(self.extras)
         return query_object_dict
diff --git a/superset/views/api.py b/superset/views/api.py
index 0fff55b..2f91951 100644
--- a/superset/views/api.py
+++ b/superset/views/api.py
@@ -23,9 +23,9 @@ class Api(BaseSupersetView):
         for the given query_obj.
         """
         query_context = QueryContext(**json.loads(request.form.get('query_context')))
-        security_manager.assert_datasource_permission(query_context.datasource, g.user)
+        security_manager.assert_datasource_permission(query_context.datasource)
         payload_json = query_context.get_payload()
-        return data_payload_response(payload_json)
+        return json.dumps(payload_json)
 
 
 appbuilder.add_view_no_menu(Api)


Mime
View raw message