mirror of
https://github.com/apache/superset.git
synced 2026-04-07 10:31:50 +00:00
* [SIP-5] Open a new /api/v1/query endpoint that takes query_obj - Introduce a new handle_superset_exception decorator to avoid repeating the logic for catching SupersetExceptions - Create a query_obj_backfill method that takes form_data and constructs a query_obj that will be constructed in the client in the future. Use the backfill in explore_json. - Create a new /api/v1/query endpoint that takes query_obj only and returns the payload data. Note the query_obj is constructed in the client. The endpoint currently only handles query_obj for table view viz (we'll be adding support to new viz types as we go). - Unit test to verify the new endpoint for table view * fix tests and lint errors * - Move the new query endpoint into its own api.py view. - Create QueryObject and QueryContext class to encapsulate query_object to be built from the client and additional info (e.g. datasource) needed to get the data payload for a given query - Remove the query_obj_backfill as we'll start building the first query_object on the client so it no longer makes sense to have a short-lived backfill for the matter of days. * Fixing lint and test errors * Fixing additional lint error from the previous rebase. * fixing additional lint error * addressing additional pr comments * Make /query accept a list of queries in the query_context object. * fixing a lint error * - Move time_shift based calculation and since, until check into util - Add typing info for get_since_until - Add new unit tests to verify time_shift calculation and the since until check
32 lines
1020 B
Python
32 lines
1020 B
Python
# pylint: disable=R
|
|
import json
|
|
|
|
from flask import g, request
|
|
from flask_appbuilder import expose
|
|
from flask_appbuilder.security.decorators import has_access_api
|
|
|
|
from superset import appbuilder, security_manager
|
|
from superset.common.query_context import QueryContext
|
|
from superset.models.core import Log
|
|
from .base import api, BaseSupersetView, data_payload_response, handle_superset_exception
|
|
|
|
|
|
class Api(BaseSupersetView):
|
|
@Log.log_this
|
|
@api
|
|
@handle_superset_exception
|
|
@has_access_api
|
|
@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')))
|
|
security_manager.assert_datasource_permission(query_context.datasource, g.user)
|
|
payload_json = query_context.get_data()
|
|
return data_payload_response(payload_json)
|
|
|
|
|
|
appbuilder.add_view_no_menu(Api)
|