robdiciuccio commented on a change in pull request #11499:
URL: 
https://github.com/apache/incubator-superset/pull/11499#discussion_r537833807



##########
File path: superset/charts/api.py
##########
@@ -490,47 +544,88 @@ def data(self) -> Response:
             json_body = json.loads(request.form["form_data"])
         else:
             return self.response_400(message="Request is not JSON")
+
         try:
-            query_context = ChartDataQueryContextSchema().load(json_body)
-        except KeyError:
-            return self.response_400(message="Request is incorrect")
+            command = ChartDataCommand()
+            query_context = command.set_query_context(json_body)
+            command.validate()
         except ValidationError as error:
             return self.response_400(
                 message=_("Request is incorrect: %(error)s", 
error=error.messages)
             )
-        try:
-            query_context.raise_for_access()
         except SupersetSecurityException:
             return self.response_401()
-        payload = query_context.get_payload()
-        for query in payload:
-            if query.get("error"):
-                return self.response_400(message=f"Error: {query['error']}")
-        result_format = query_context.result_format
 
-        response = self.response_400(
-            message=f"Unsupported result_format: {result_format}"
-        )
+        # TODO: support CSV, SQL query and other non-JSON types
+        if (
+            is_feature_enabled("GLOBAL_ASYNC_QUERIES")
+            and query_context.result_format == ChartDataResultFormat.JSON
+            and query_context.result_type == ChartDataResultType.FULL
+        ):
 
-        if result_format == ChartDataResultFormat.CSV:
-            # return the first result
-            result = payload[0]["data"]
-            response = CsvResponse(
-                result,
-                status=200,
-                headers=generate_download_headers("csv"),
-                mimetype="application/csv",
-            )
+            try:
+                command.validate_async_request(request)
+            except AsyncQueryTokenException:
+                return self.response_401()
 
-        if result_format == ChartDataResultFormat.JSON:
-            response_data = simplejson.dumps(
-                {"result": payload}, default=json_int_dttm_ser, ignore_nan=True
+            result = command.run_async()
+            return self.response(202, **result)
+
+        return self.get_data_response(command)
+
+    @expose("/data/<cache_key>", methods=["GET"])

Review comment:
       New endpoint to fetch cached data based on a cache key passed to the FE 
via the async event payload.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



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

Reply via email to