mirror of
https://github.com/apache/superset.git
synced 2026-04-19 16:14:52 +00:00
[SIP-5] Open a new /api/v1/query endpoint that takes query_obj (#6220)
* [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
This commit is contained in:
committed by
Maxime Beauchemin
parent
4ce475f287
commit
8c0551ed46
47
superset/common/query_object.py
Normal file
47
superset/common/query_object.py
Normal file
@@ -0,0 +1,47 @@
|
||||
# pylint: disable=R
|
||||
from typing import Dict, List, Optional, Union
|
||||
|
||||
from superset import app
|
||||
from superset.utils import core as utils
|
||||
|
||||
# TODO: Type Metrics dictionary with TypedDict when it becomes a vanilla python type
|
||||
# https://github.com/python/mypy/issues/5288
|
||||
Metric = Union[str, Dict]
|
||||
|
||||
|
||||
class QueryObject:
|
||||
"""
|
||||
The query object's schema matches the interfaces of DB connectors like sqla
|
||||
and druid. The query objects are constructed on the client.
|
||||
"""
|
||||
def __init__(
|
||||
self,
|
||||
granularity: str,
|
||||
groupby: List[str],
|
||||
metrics: List[Metric],
|
||||
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,
|
||||
order_desc: bool = True,
|
||||
extras: Optional[Dict] = None,
|
||||
):
|
||||
self.granularity = granularity
|
||||
self.from_dttm, self.to_dttm = utils.get_since_until(time_range, time_shift)
|
||||
self.is_timeseries = is_timeseries
|
||||
self.groupby = groupby
|
||||
self.metrics = metrics
|
||||
self.row_limit = row_limit
|
||||
self.filter = filters
|
||||
self.timeseries_limit = int(limit)
|
||||
self.timeseries_limit_metric = timeseries_limit_metric
|
||||
self.order_desc = order_desc
|
||||
self.prequeries = []
|
||||
self.is_prequery = False
|
||||
self.extras = extras
|
||||
|
||||
def to_dict(self):
|
||||
raise NotImplementedError()
|
||||
Reference in New Issue
Block a user