You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jo...@apache.org on 2019/01/11 02:22:30 UTC
[incubator-superset] 26/43: fix tesT
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 42838de679a4411f7b2ce50b40d55c9fc635d127
Author: Conglei Shi <co...@airbnb.com>
AuthorDate: Fri Dec 14 10:57:46 2018 -0800
fix tesT
---
superset/connectors/sqla/models.py | 1 -
superset/views/api.py | 7 +++----
superset/viz.py | 36 ++++++++++++++++--------------------
3 files changed, 19 insertions(+), 25 deletions(-)
diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py
index feb4c9a..e3ca718 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -572,7 +572,6 @@ 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 '
diff --git a/superset/views/api.py b/superset/views/api.py
index e5a9462..8f03525 100644
--- a/superset/views/api.py
+++ b/superset/views/api.py
@@ -18,13 +18,13 @@ class Api(BaseSupersetView):
@api
@handle_api_exception
@has_access_api
- @expose('/v1/query/', methods=['POST'])
+ @expose('/v1/query', methods=['POST'])
def query(self):
"""
Takes a query_obj constructed in the client and returns payload data response
for the given query_obj.
"""
- query_context = QueryContext(**json.loads(request.form.get('query_context')))
+ query_context = QueryConext(**json.loads(request.form.get('query_context')))
security_manager.assert_datasource_permission(query_context.datasource)
payload_json = query_context.get_payload()
return json.dumps(payload_json)
@@ -33,7 +33,7 @@ class Api(BaseSupersetView):
@api
@handle_api_exception
@has_access_api
- @expose('/v1/form_data/', methods=['GET'])
+ @expose('/v1/form_data', methods=['GET'])
def query_form_data(self):
"""
Takes a query_obj constructed in the client and returns payload data response
@@ -41,7 +41,6 @@ class Api(BaseSupersetView):
"""
form_data = {}
slice_id = request.args.get('slice_id')
- print(slice_id)
if slice_id:
slc = db.session.query(models.Slice).filter_by(id=slice_id).one_or_none()
if slc:
diff --git a/superset/viz.py b/superset/viz.py
index 55a4e8a..8b57b6c 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -108,6 +108,11 @@ class BaseViz(object):
label = self.get_metric_label(o)
if isinstance(o, dict):
o['label'] = label
+ else:
+ o = {
+ 'label': o,
+ 'expressionType': 'BUILTIN',
+ }
self.metric_dict[label] = o
# Cast to list needed to return serializable object in py3
@@ -786,13 +791,10 @@ class CalHeatmapViz(BaseViz):
data = {}
records = df.to_dict('records')
for metric in self.metric_labels:
- values = {}
- for obj in records:
- v = obj[DTTM_ALIAS]
- if hasattr(v, 'value'):
- v = v.value
- values[str(v / 10**9)] = obj.get(metric)
- data[metric] = values
+ data[metric] = {
+ str(obj[DTTM_ALIAS] / 10**9): obj.get(metric)
+ for obj in records
+ }
start, end = utils.get_since_until(form_data.get('time_range'),
form_data.get('since'),
@@ -1467,16 +1469,6 @@ class HistogramViz(BaseViz):
d['groupby'] = []
return d
- def labelify(self, keys, column):
- if isinstance(keys, str):
- keys = (keys,)
- # removing undesirable characters
- labels = [re.sub(r'\W+', r'_', k) for k in keys]
- if len(self.columns) > 1 or not self.groupby:
- # Only show numeric column in label if there are many
- labels = [column] + labels
- return '__'.join(labels)
-
def get_data(self, df):
"""Returns the chart data"""
chart_data = []
@@ -1485,10 +1477,14 @@ class HistogramViz(BaseViz):
else:
groups = [((), df)]
for keys, data in groups:
+ if isinstance(keys, str):
+ keys = (keys,)
+ # removing undesirable characters
+ keys = [re.sub(r'\W+', r'_', k) for k in keys]
chart_data.extend([{
- 'key': self.labelify(keys, column),
- 'values': data[column].tolist()}
- for column in self.columns])
+ 'key': '__'.join([c] + keys),
+ 'values': data[c].tolist()}
+ for c in self.columns])
return chart_data