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 b6714a2d90e15476e105efad2a61b2275cb5092c Author: Conglei Shi <[email protected]> AuthorDate: Tue Nov 13 14:31:08 2018 -0800 revised the metric part --- superset/common/query_context.py | 4 +++- superset/common/query_object.py | 15 ++++----------- superset/views/api.py | 2 +- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/superset/common/query_context.py b/superset/common/query_context.py index 2415ca3..27e03a0 100644 --- a/superset/common/query_context.py +++ b/superset/common/query_context.py @@ -41,6 +41,8 @@ class QueryContext: self.custom_cache_timeout = custom_cache_timeout + self.enforce_numerical_metrics = True + def get_query_result(self, query_object): """Returns a pandas dataframe based on the query object""" @@ -89,7 +91,7 @@ class QueryContext: def df_metrics_to_num(self, df, query_object): """Converting metrics to numeric when pandas.read_sql cannot""" - metrics = query_object.get_metric_labels() + metrics = [metric.label 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 3add741..d12620c 100644 --- a/superset/common/query_object.py +++ b/superset/common/query_object.py @@ -8,8 +8,6 @@ import simplejson as json # TODO: Type Metrics dictionary with TypedDict when it becomes a vanilla python type # https://github.com/python/mypy/issues/5288 -Metric = Dict - class QueryObject: """ @@ -19,15 +17,15 @@ class QueryObject: def __init__( self, granularity: str, - groupby: List[str] = None, - metrics: List[Metric] = None, - filters: List[str] = None, + groupby: List[str], + metrics: List[Dict], + filters: List[str], time_range: Optional[str] = None, time_shift: Optional[str] = None, is_timeseries: bool = False, row_limit: int = app.config.get('ROW_LIMIT'), limit: int = 0, - timeseries_limit_metric: Optional[Metric] = None, + timeseries_limit_metric: Optional[Dict] = None, order_desc: bool = True, extras: Optional[Dict] = None, ): @@ -48,11 +46,6 @@ class QueryObject: def to_dict(self): raise NotImplementedError() - - def get_metric_labels(self): - raise NotImplementedError() - - def cache_key(self, **extra): """ The cache key is made out of the key/values in `query_obj`, plus any diff --git a/superset/views/api.py b/superset/views/api.py index 5f684f3..0fff55b 100644 --- a/superset/views/api.py +++ b/superset/views/api.py @@ -24,7 +24,7 @@ class Api(BaseSupersetView): """ query_context = QueryContext(**json.loads(request.form.get('query_context'))) security_manager.assert_datasource_permission(query_context.datasource, g.user) - payload_json = query_context.get_data() + payload_json = query_context.get_payload() return data_payload_response(payload_json)
