mistercrunch commented on a change in pull request #6220: [SIP-5] Open a new 
/api/v1/query endpoint that takes query_obj
URL: 
https://github.com/apache/incubator-superset/pull/6220#discussion_r229451149
 
 

 ##########
 File path: superset/models/core.py
 ##########
 @@ -87,6 +87,37 @@ def copy_dashboard(mapper, connection, target):
     session.commit()
 
 
+def query_obj_backfill(form_data, datasource_id=None, datasource_type=None):
+    # Backfill query_obj. This will be generated on the client in the future.
+    # Note we unpack the metrics on the viz here so we can create the metrics
+    # dictionary during viz initialization without leveraging form_data.
+    #
+    # TODO: Note structure of the backfilled query_obj is temporary. It will be
+    # restructured as we build out the query object on the client side.
+    # The fields included are necessary to load a table viz without form_data
+    query_obj = {
+        'viz_type': form_data.get('viz_type', 'table'),
+        'time_range': form_data.get('time_range'),
+        'include_time': form_data.get('include_time'),
+        'token': form_data.get('token'),
+        'metrics': form_data.get('metrics'),
+        'percent_metrics': form_data.get('percent_metrics'),
+        'granularity_sqla': form_data.get('granularity_sqla'),
+        'time_grain_sqla': form_data.get('time_grain_sqla'),
+        'query': {
+            'groupby': form_data.get('groupby'),
+            'metrics': [form_data.get(mkey) for mkey in METRIC_KEYS if mkey in 
form_data],
+            'granularity': form_data.get('granularity'),
+        },
+    }
+    if datasource_type and datasource_id:
+        query_obj['datasource'] = {
+            'id': datasource_id,
+            'type': datasource_type,
+        }
+    return query_obj
 
 Review comment:
   Surprised not to find `filters` here and things like `is_timeseries`. Seems 
like the query object's schema here should match the interface for the 
connector. 
   
https://github.com/apache/incubator-superset/blob/master/superset/connectors/sqla/models.py#L524-L539
   same as 
   
https://github.com/apache/incubator-superset/blob/master/superset/connectors/druid/models.py#L1095-L1109

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to