-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(chart-data): add rowcount, timegrain and column result types #13271
Conversation
if self.datasource: | ||
cache_dict["datasource"] = self.datasource.uid | ||
if self.result_type: | ||
cache_dict["result_type"] = self.result_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are only added to the dict if defined to avoid invalidating cache keys of currently cached objects.
Codecov Report
@@ Coverage Diff @@
## master #13271 +/- ##
===========================================
+ Coverage 64.23% 79.95% +15.72%
===========================================
Files 971 300 -671
Lines 45178 24381 -20797
Branches 4129 0 -4129
===========================================
- Hits 29019 19495 -9524
+ Misses 16159 4886 -11273
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, left a couple of comments
superset/common/query_context.py
Outdated
@@ -152,13 +152,39 @@ def get_single_payload( | |||
self, query_obj: QueryObject, force_cached: Optional[bool] = False, | |||
) -> Dict[str, Any]: | |||
"""Return results payload for a single quey""" | |||
if self.result_type == utils.ChartDataResultType.QUERY: | |||
result_type = query_obj.result_type or self.result_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could make sense to document the constructor since, not passing result_type
assumes it is FULL
or passed on the query_obj
c875131
to
f295794
Compare
f295794
to
9146bb8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! loved the refactor also
9d92d93
to
1aa52a5
Compare
ChartDataResultType.QUERY: _get_query, | ||
ChartDataResultType.SAMPLES: _get_samples, | ||
ChartDataResultType.FULL: _get_full, | ||
ChartDataResultType.RESULTS: _get_results, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@villebro Sorry for being late to the party, but it there a reason why is_rowcount
is not implemented as another ChartDataResultType
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the way I thought about implementing it first, but I felt it better to implement it as a QueryObject
property, as it has to be passed to the SQLA model as it affects the rendered query (I feel QueryObject
should be mostly 1-1 mapped to the query dict that's unpacked into get_sqla_query
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't you still have that mapping if you just create a _get_rowcount
function that sets QueryObjects
's is_rowcount
to True
? I see no difference in setting is_rowcount
in a _get_rowcount
function than manipulating other fields of QueryObject
in _get_samples
and _get_query
.
The reason why I think a new result type makes more sense is that from the client-side point of view, ResultType.SAMPLES
, ResultType.QUERY
, and ResultType.ROW_COUNT
are mutually exclusive, i.e., you cannot have a QueryObject
with both result_type = ResultType.SAMPLES
and is_rowcount = True
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind adding a result type as a convenience method for fetching the row count. However, the preferred method for retrieving row counts should IMO be explicitly setting is_rowcount
on QueryObject
, as it will make it possible to set ResultType.QUERY
on QueryContext
and by doing so fetch only the queries for all QueryObject
s (we don't yet support showing queries for multiple queries, but I hope we can add it soon):
beforeOpen={() => beforeOpen('query')} |
SUMMARY
This PR adds some features to
/api/v1/chart/data
needed for native filters, namely:To avoid adding more clutter to
QueryContext
, the result actions have been moved to a separate modulesuperset/common/actions.py
to avoid havingquery_context.py
grow further in size. In addition, some general refactoring has been done.Going forward I believe we should consier splitting up
/api/v1/chart/data
into multiple endpoints (e.g.api/v1/chart/data/annotation
,api/v1/chart/data/query
,api/v1/chart/data/metadata
etc), or consider moving certain endpoints to GraphQL to make it easier to retrieve nested data in one request.TEST PLAN
CI + added tests. I have also tested this with
GLOBAL_ASYNC_QUERIES
feature flag, and it works fine for all request types.ADDITIONAL INFORMATION