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

chore: Support SET & SHOW commands as read only SQL commands #11868

Merged
merged 3 commits into from
Dec 3, 2020

Conversation

bkyryliuk
Copy link
Member

@bkyryliuk bkyryliuk commented Dec 1, 2020

SUMMARY

Adds support for the SET and SHOW queries in sqllab for the read only queries example queries are:

  • SHOW LOCKS
  • SHOW SCHEMAS
  • SHOW TABLES
  • SET hive variables
  • SET hive queue
    etc

related: #11348

TEST PLAN

  • unit tests
  • dropbox staging

@bkyryliuk bkyryliuk marked this pull request as draft December 1, 2020 00:38
@codecov-io
Copy link

codecov-io commented Dec 1, 2020

Codecov Report

Merging #11868 (ea648a3) into master (721f911) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #11868      +/-   ##
==========================================
- Coverage   63.78%   63.75%   -0.04%     
==========================================
  Files         927      928       +1     
  Lines       45006    45059      +53     
  Branches     4308     4309       +1     
==========================================
+ Hits        28708    28728      +20     
- Misses      16120    16154      +34     
+ Partials      178      177       -1     
Flag Coverage Δ
javascript 63.18% <ø> (+<0.01%) ⬆️
python 64.09% <100.00%> (-0.06%) ⬇️

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

Impacted Files Coverage Δ
superset/connectors/sqla/models.py 90.77% <100.00%> (+0.01%) ⬆️
superset/db_engine_specs/base.py 87.56% <100.00%> (+0.09%) ⬆️
superset/db_engine_specs/hive.py 84.23% <100.00%> (+0.18%) ⬆️
superset/db_engine_specs/presto.py 81.75% <100.00%> (-0.53%) ⬇️
superset/sql_lab.py 80.28% <100.00%> (ø)
superset/sql_parse.py 99.34% <100.00%> (+0.01%) ⬆️
...rc/explore/components/controls/TextAreaControl.jsx 83.33% <0.00%> (-1.86%) ⬇️
superset-frontend/src/views/CRUD/types.ts 100.00% <0.00%> (ø)
...t-frontend/src/views/CRUD/data/query/QueryList.tsx 72.11% <0.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 721f911...ea648a3. Read the comment docs.

@bkyryliuk bkyryliuk force-pushed the bogdan/support_set_and_show branch 4 times, most recently from 2a68eb4 to 6aad364 Compare December 1, 2020 02:25
@bkyryliuk bkyryliuk requested review from villebro and betodealmeida and removed request for villebro December 1, 2020 02:43
@bkyryliuk bkyryliuk marked this pull request as ready for review December 1, 2020 02:45
@bkyryliuk bkyryliuk requested a review from villebro December 1, 2020 02:45
@bkyryliuk bkyryliuk changed the title chore: Support SET & SHOW commands as read only SQL commands [WIP] chore: Support SET & SHOW commands as read only SQL commands Dec 1, 2020
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.

This feels slightly specific to Hive. Could we move this logic into BaseEngineSpec by introducing a def is_dml(statement) or def is_readonly(statement), and let the specific db implementation do the parsing?

@bkyryliuk
Copy link
Member Author

This feels slightly specific to Hive. Could we move this logic into BaseEngineSpec by introducing a def is_dml(statement) or def is_readonly(statement), and let the specific db implementation do the parsing?

Sounds good to me, will refactor it

def is_unknown(self) -> bool:
return self._parsed[0].get_type() == "UNKNOWN"

def is_readonly(self) -> bool:
"""Pessimistic readonly, 100% sure statement won't mutate anything"""
return self.is_select() or self.is_explain()
return self.is_select() or self.is_explain() or self.is_set() or self.is_show()
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious reading this (would have been an issue before this PR) on whether running multiple statements including non-readonly would work well here, as in:

SET foo='bar';
UPDATE {...}

Copy link
Member Author

Choose a reason for hiding this comment

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

@mistercrunch this evaluation happens per statement:
https://github.com/apache/incubator-superset/blob/0409b12a55e893d88f6e992a7df247841a2da8f0/superset/sql_lab.py#L164

Otherwise it will be the same problem for SELECT / EXPLAIN queries

@bkyryliuk bkyryliuk force-pushed the bogdan/support_set_and_show branch from 6aad364 to d99c84e Compare December 3, 2020 01:57
@pull-request-size pull-request-size bot added size/L and removed size/M labels Dec 3, 2020
@bkyryliuk bkyryliuk force-pushed the bogdan/support_set_and_show branch 3 times, most recently from 36a6ca9 to 7194e95 Compare December 3, 2020 04:37
@bkyryliuk
Copy link
Member Author

@villebro what about this solution ?

@bkyryliuk bkyryliuk force-pushed the bogdan/support_set_and_show branch from 7194e95 to e7668cb Compare December 3, 2020 06:08
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.

A few suggestions, but looks pretty good to me.

superset/db_engine_specs/base.py Outdated Show resolved Hide resolved
superset/db_engine_specs/hive.py Outdated Show resolved Hide resolved
superset/db_engine_specs/presto.py Outdated Show resolved Hide resolved
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.

Looks great, especially with the tests! 👍

@bkyryliuk bkyryliuk merged commit 0396c70 into apache:master Dec 3, 2020
@bkyryliuk bkyryliuk deleted the bogdan/support_set_and_show branch December 3, 2020 20:58
@ramyarajasekaran
Copy link

Does this support SET ROLE command with Presto? @bkyryliuk

@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.0.0 labels Mar 12, 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 🚢 1.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants