Skip to content
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(sqllab): save query parameters in database #21682

Merged
merged 7 commits into from
Oct 7, 2022

Conversation

mayurnewase
Copy link
Contributor

@mayurnewase mayurnewase commented Oct 3, 2022

SUMMARY

  • Saves template parameters when query is saved.
  • Updates frontend to use v1 saved query rest api,
  • Removes unnecessary parameters from the payload which api doesn't need.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

  1. Enable ENABLE_TEMPLATE_PROCESSING flag
  2. write any query in sqllab with params eg.: SELECT '{{ p1 }}' and set parameters {"p1": "value from params"}
  3. save the query and close the tab then go to saved queries
  4. when saved query is opened, paramter values should show up exactly as it was saved, and when query is run it should show 1 column with value value from params
  5. updating the query with sql or parameters should correctly update the query.
  6. also test changing the query name, and it should update tab name.

ADDITIONAL INFORMATION

  • Has associated issue: [SQL Lab] Saved Queries do not include parameters #20576
  • Required feature flags: ENABLE_TEMPLATE_PROCESSING
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided -> not needed, cuz it just adds 1 column without default value
  • Introduces new feature or API
  • Removes existing feature or API

@mayurnewase mayurnewase changed the title [WIP] feat: save query parameters in saved query [WIP] feat(sqllab): save query parameters in saved query Oct 3, 2022
@mayurnewase mayurnewase changed the title [WIP] feat(sqllab): save query parameters in saved query [WIP] feat(sqllab): save query parameters while saving query Oct 3, 2022
@mayurnewase mayurnewase changed the title [WIP] feat(sqllab): save query parameters while saving query [WIP]feat(sqllab): save query parameters while saving query Oct 3, 2022
@mayurnewase mayurnewase changed the title [WIP]feat(sqllab): save query parameters while saving query feat(sqllab): save query parameters while saving query Oct 4, 2022
@villebro
Copy link
Member

villebro commented Oct 4, 2022

@mayurnewase I sometimes wonder what purpose query parameters have in SQL Lab, other than while developing virtual table queries that are meant to accept query parameters. Do you have a clear use case for persisting query params? It would be great to understand how this feature is usually leveraged in the wild.

@mayurnewase
Copy link
Contributor Author

mayurnewase commented Oct 4, 2022

hi @villebro I have seen similar issue raised in the associated ticket.
And 1 more case when people write and save query with parameters and share with other people who are not familier with sql and just want to modify the parameters, so sql writers need to send parameters json separately.

Do you think its worth saving it in the db?

@villebro
Copy link
Member

villebro commented Oct 4, 2022

hi @villebro I have seen similar issue raised in the associated ticket. And 1 more case when people write and save query with parameters and share with other people who are not familier with sql and just want to modify the parameters, so sql writers need to send parameters json separately.

Do you think its worth saving it in the db?

Hi,

yes, I think the params should be persisted if they weren't previously if there's a clear use case for it. Personally I've just never really seen a very clear use case for query params in SQL Lab, but that may just be me and how I use SQL Lab. But IMO this PR looks good, so I'm happy to review/test when it's ready.

@pull-request-size pull-request-size bot added size/L and removed size/M labels Oct 6, 2022
@mayurnewase mayurnewase marked this pull request as ready for review October 6, 2022 02:27
@mayurnewase mayurnewase requested a review from a team as a code owner October 6, 2022 02:27
@mayurnewase mayurnewase changed the title feat(sqllab): save query parameters while saving query feat(sqllab): save query parameters in database Oct 6, 2022
@codecov
Copy link

codecov bot commented Oct 6, 2022

Codecov Report

Merging #21682 (764c14e) into master (31895f4) will increase coverage by 0.01%.
The diff coverage is 58.82%.

@@            Coverage Diff             @@
##           master   #21682      +/-   ##
==========================================
+ Coverage   66.82%   66.84%   +0.01%     
==========================================
  Files        1799     1799              
  Lines       68830    68886      +56     
  Branches     7332     7320      -12     
==========================================
+ Hits        45997    46047      +50     
+ Misses      20953    20952       -1     
- Partials     1880     1887       +7     
Flag Coverage Δ
hive 52.92% <100.00%> (+0.02%) ⬆️
javascript 53.14% <53.33%> (-0.01%) ⬇️
mysql 78.24% <100.00%> (+0.03%) ⬆️
postgres 78.30% <100.00%> (+0.03%) ⬆️
presto 52.82% <100.00%> (+0.02%) ⬆️
python 81.44% <100.00%> (+0.02%) ⬆️
sqlite 76.80% <100.00%> (+0.02%) ⬆️
unit 50.95% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...frontend/src/SqlLab/components/SaveQuery/index.tsx 75.00% <0.00%> (-1.75%) ⬇️
...frontend/src/SqlLab/components/SqlEditor/index.jsx 55.67% <ø> (+1.82%) ⬆️
superset-frontend/src/SqlLab/reducers/sqlLab.js 35.22% <0.00%> (ø)
superset-frontend/src/SqlLab/actions/sqlLab.js 62.66% <75.00%> (+0.72%) ⬆️
...src/SqlLab/components/SqlEditorTabHeader/index.tsx 90.47% <100.00%> (ø)
superset-frontend/src/SqlLab/fixtures.ts 100.00% <100.00%> (ø)
superset/models/sql_lab.py 74.80% <100.00%> (-1.72%) ⬇️
superset/queries/saved_queries/api.py 95.28% <100.00%> (ø)
...src/filters/components/Range/RangeFilterPlugin.tsx 70.75% <0.00%> (-2.84%) ⬇️
superset-frontend/src/filters/utils.ts 92.10% <0.00%> (-2.64%) ⬇️
... and 65 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@mayurnewase mayurnewase marked this pull request as draft October 6, 2022 05:16
@mayurnewase mayurnewase marked this pull request as ready for review October 6, 2022 10:43
Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice work @mayurnewase ! LGTM and tested to work as expected

Comment on lines -932 to +941
endpoint: '/savedqueryviewapi/api/create',
postPayload: convertQueryToServer(query),
stringify: false,
endpoint: '/api/v1/saved_query/',
jsonPayload: convertQueryToServer(payload),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the migration to v1 API! 🚀

@mayurnewase mayurnewase merged commit 61319fd into apache:master Oct 7, 2022
@mayurnewase mayurnewase deleted the add-params-in-saved-query branch October 7, 2022 07:20
@kenho811
Copy link

kenho811 commented Oct 7, 2022

@mayurnewase

Thank you so much for adding this feature!!

I was one of those who asked for that, because I had some complex jinja templated SQL query and I had trouble using the Native Dashboard filter to allow users to click and select the desired values for substitution.

#20576 (comment)

With your new feature, users can simply take the templated SQL, update the saved paramters and press RUN to get the output (as raw data without visualisation).

THank you :)))

Now I cannot wait until a new release is ready with your feature :))

@villebro
Copy link
Member

Thanks @kenho811 for sharing your use case! And thanks again @mayurnewase for taking this on and doing a thorough cleanup of the related code + adding tests, really stellar work!

@eschutho eschutho added the v2.0 label Oct 13, 2022
sadpandajoe added a commit to preset-io/superset that referenced this pull request Oct 17, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.0 and removed 🚢 2.1.3 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants