betodealmeida opened a new pull request #15824:
URL: https://github.com/apache/superset/pull/15824
### SUMMARY
<!--- Describe the change below, including rationale and design decisions -->
This PR adds a new column to the `slices` table called `query_context`. It
also modifies Explore to save the query context to this column whenever a chart
is saved.
Having the query context is needed in order to generate data for a saved
chart with the `api/v1/char/data` endpoint. Since the query context is built by
each visualization from `slices.params` via Javascript, there's currently no
way to fetch data for a given chart from Python.
With the new column we will be able to generate CSV reports for new
(JS-only) charts, like the pivot table v2.
The migration script only adds the column, but doesn't populate it for
existing charts since that would be too expensive and complex.
Migration benchmark:
```
Results:
Current: 0.26 s
10+: 0.35 s
100+: 0.30 s
1000+: 0.22 s
10000+: 0.22 s
```
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
<!--- Skip this if not applicable -->
N/A
### TESTING INSTRUCTIONS
<!--- Required! What steps can be taken to manually verify the changes? -->
Save a chart and check the `slices.query_context` column:
```
mysql> SELECT params, query_context FROM slices WHERE id=143\G
*************************** 1. row ***************************
params: {
"adhoc_filters": [],
"aggregateFunction": "Sum",
"colOrder": "key_a_to_z",
"colTotals": true,
"datasource": "3__table",
"extra_form_data": {},
"granularity_sqla": "ds",
"groupbyColumns": [
"state"
],
"groupbyRows": [
"name"
],
"metrics": [
{
"aggregate": "SUM",
"column": {
"column_name": "num",
"type": "BIGINT"
},
"expressionType": "SIMPLE",
"label": "Births",
"optionName": "metric_11"
}
],
"metricsLayout": "COLUMNS",
"rowOrder": "key_a_to_z",
"rowTotals": true,
"row_limit": 50000,
"slice_id": 143,
"tableRenderer": "Table With Subtotal",
"time_grain_sqla": "P1D",
"time_range": "100 years ago : now",
"time_range_endpoints": [
"inclusive",
"exclusive"
],
"url_params": {},
"valueFormat": "SMART_NUMBER",
"viz_type": "pivot_table_v2"
}
query_context: {
"datasource": {
"id": 3,
"type": "table"
},
"force": false,
"queries": [
{
"time_range": "100 years ago : now",
"granularity": "ds",
"filters": [],
"extras": {
"time_grain_sqla": "P1D",
"time_range_endpoints": [
"inclusive",
"exclusive"
],
"having": "",
"having_druid": [],
"where": ""
},
"applied_time_extras": {},
"columns": [
"state",
"name"
],
"metrics": [
{
"aggregate": "SUM",
"column": {
"column_name": "num",
"type": "BIGINT"
},
"expressionType": "SIMPLE",
"label": "Births",
"optionName": "metric_11"
}
],
"annotation_layers": [],
"row_limit": 50000,
"timeseries_limit": 0,
"order_desc": true,
"url_params": {},
"custom_params": {},
"custom_form_data": {}
}
],
"result_format": "json",
"result_type": "full"
}
1 row in set (0.00 sec)
```
### ADDITIONAL INFORMATION
<!--- Check any relevant boxes with "x" -->
<!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
- [ ] Has associated issue:
- [ ] Changes UI
- [x] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [x] Migration is atomic, supports rollback & is backwards-compatible
- [x] Confirm DB migration upgrade and downgrade tested
- [x] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]