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: improve adhoc SQL validation #19454

Merged
merged 3 commits into from
Mar 31, 2022

Conversation

betodealmeida
Copy link
Member

@betodealmeida betodealmeida commented Mar 31, 2022

SUMMARY

Improve the validate_adhoc_subquery function.

I changed the logic of insert_rls. As originally written we'd pass (1) the adhoc SQL, (2) the dataset name and (3) the associated RLS predicate. In order to use it here I modified it to receive (1) the adhoc SQL with the (2) database and (3) schema where it will run. We then parse the adhoc SQL, and for each table found we check if there's an associated RLS rule; if so, we modify the SQL to include the RLS predicate(s).

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TESTING INSTRUCTIONS

Updated unit tests, will add more.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • 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
  • Introduces new feature or API
  • Removes existing feature or API

@@ -984,15 +992,14 @@ def is_alias_used_in_orderby(col: ColumnElement) -> bool:

def _get_sqla_row_level_filters(
self, template_processor: BaseTemplateProcessor
) -> List[str]:
) -> List[TextClause]:
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure why mypy didn't catch this.

@@ -1420,7 +1441,6 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
and db_engine_spec.allows_hidden_cc_in_orderby
and col.name in [select_col.name for select_col in select_exprs]
):
validate_adhoc_subquery(str(col.expression))
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved this up, where it's still a string.

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.

Tested to work very nicely except in one edge case (would be great to add a test for that case, too).

superset/sql_parse.py Outdated Show resolved Hide resolved
tests/unit_tests/sql_parse_tests.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 31, 2022

Codecov Report

Merging #19454 (b83a64f) into master (8e29ec5) will increase coverage by 0.00%.
The diff coverage is 93.02%.

@@           Coverage Diff           @@
##           master   #19454   +/-   ##
=======================================
  Coverage   66.57%   66.58%           
=======================================
  Files        1675     1675           
  Lines       64092    64107   +15     
  Branches     6519     6519           
=======================================
+ Hits        42672    42684   +12     
- Misses      19729    19732    +3     
  Partials     1691     1691           
Flag Coverage Δ
hive 52.69% <44.18%> (-0.01%) ⬇️
mysql 81.90% <93.02%> (-0.01%) ⬇️
postgres 81.95% <93.02%> (-0.01%) ⬇️
presto 52.54% <44.18%> (-0.01%) ⬇️
python 82.39% <93.02%> (-0.01%) ⬇️
sqlite 81.72% <93.02%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
superset/connectors/sqla/utils.py 94.50% <88.88%> (+0.12%) ⬆️
superset/sql_parse.py 97.38% <92.30%> (-0.92%) ⬇️
superset/connectors/sqla/models.py 89.32% <100.00%> (+<0.01%) ⬆️
superset/db_engine_specs/drill.py 87.17% <0.00%> (+0.33%) ⬆️

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 8e29ec5...b83a64f. Read the comment docs.

@betodealmeida betodealmeida merged commit 6828624 into apache:master Mar 31, 2022
suddjian pushed a commit to preset-io/superset that referenced this pull request Mar 31, 2022
* feat: improve adhoc SQL validation

* Small changes

* Add more unit tests
sadpandajoe pushed a commit to preset-io/superset that referenced this pull request Apr 1, 2022
* feat: improve adhoc SQL validation

* Small changes

* Add more unit tests

(cherry picked from commit 6828624)
@villebro villebro added the lts-v1 label Apr 1, 2022
villebro pushed a commit that referenced this pull request Apr 3, 2022
* feat: improve adhoc SQL validation

* Small changes

* Add more unit tests

(cherry picked from commit 6828624)
villebro pushed a commit that referenced this pull request Apr 4, 2022
* feat: improve adhoc SQL validation

* Small changes

* Add more unit tests

(cherry picked from commit 6828624)
@sadpandajoe
Copy link
Member

🏷️ preset:2022.11

philipher29 pushed a commit to ValtechMobility/superset that referenced this pull request Jun 9, 2022
* feat: improve adhoc SQL validation

* Small changes

* Add more unit tests
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.0.0 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 lts-v1 preset:2022.11 size/L 🍒 1.5.0 🍒 1.5.1 🍒 1.5.2 🍒 1.5.3 🚢 2.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants