dosubot[bot] commented on issue #30256:
URL: https://github.com/apache/superset/issues/30256#issuecomment-2346800341
<!-- Greeting -->
Hey @xiaoshan1213! 👋 I'm here to help you with bug fixes, questions, and
becoming a contributor. Let's squash some bugs together!
<!-- Answer -->
To implement the proposed changes in the SIP, you can follow these steps:
### 1. Modify the `/api/v1/saved_query/ POST` Function
Update the request parameters to include the `results_id` field. Here is an
example of how to modify the `post_data` dictionary:
```python
post_data = {
"schema": "schema1",
"label": "label1",
"description": "some description",
"sql": "SELECT col1, col2 from table1",
"db_id": example_db.id,
"results_id": some_results_id, # Add this line
}
```
### 2. Modify the `/api/v1/saved_query/{savedQueryId} GET` Function
Update the response parameters to include the `results_id` field. Here is an
example of how to modify the expected result:
```python
expected_result = {
"id": saved_query.id,
"catalog": None,
"database": {"id": saved_query.database.id, "database_name": "examples"},
"description": "cool description",
"changed_by": None,
"changed_on_delta_humanized": "now",
"created_by": {
"first_name": saved_query.created_by.first_name,
"id": saved_query.created_by.id,
"last_name": saved_query.created_by.last_name,
},
"sql": "SELECT col1, col2 from table1",
"sql_tables": [{"catalog": None, "schema": None, "table": "table1"}],
"schema": "schema1",
"label": "label1",
"template_parameters": None,
"results_id": saved_query.results_id, # Add this line
}
data = json.loads(rv.data.decode("utf-8"))
for key, value in data["result"].items():
if key != "changed_on":
assert value == expected_result[key]
```
### 3. Modify the Saved Query Metadata Database
Add a new `results_id` field to the `saved_query` table. Here is an Alembic
migration script to achieve this:
```python
from alembic import op
import sqlalchemy as sa
# Add a new column 'results_id' to the 'saved_query' table
def upgrade():
op.add_column('saved_query', sa.Column('results_id', sa.Integer,
nullable=True))
# Remove the 'results_id' column from the 'saved_query' table
def downgrade():
op.drop_column('saved_query', 'results_id')
```
### References
- Modifying the `/api/v1/saved_query/ POST` function to include `results_id`
<sup>[[1]](https://github.com/apache/superset/blob/master/tests/integration_tests/queries/saved_queries/api_tests.py)</sup>.
- Modifying the `/api/v1/saved_query/{savedQueryId} GET` function to include
`results_id`
<sup>[[1]](https://github.com/apache/superset/blob/master/tests/integration_tests/queries/saved_queries/api_tests.py)</sup>.
- Adding a new `results_id` field to the `saved_query` table
<sup>[[2]](https://github.com/apache/superset/blob/master/superset/migrations/shared/catalogs.py)</sup><sup>[[3]](https://github.com/apache/superset/blob/master/superset/migrations/versions/2017-03-29_15-04_2fcdcb35e487_saved_queries.py)</sup>.
These changes will ensure that the query results are saved and associated
with the sharable link, allowing users to view the results without rerunning
the query.
<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
--
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]