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

fix(sql lab): Use quote_schema instead of quote method to format schema name #26281

Merged
merged 1 commit into from
Dec 20, 2023

Conversation

guenp
Copy link
Contributor

@guenp guenp commented Dec 14, 2023

SUMMARY

DuckDB supports multiple databases. This means schemas can be specified as <db name>.<schema name>, e.g., "my db".main. However, when such a schema name is specified, it gets quoted as "my db.main" instead of "my db"."main". This PR fixes that by using the quote_schema method of the identifier_preparer instead of quote. This method defaults to identifier_preparer.quote is overridden in the DuckDB sqlalchemy driver to parse the string and add quotes in the right places.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Congrats on making your first PR and thank you for contributing to Superset! 🎉 ❤️

We hope to see you in our Slack community too! Not signed up? Use our Slack App to self-register.

Copy link

codecov bot commented Dec 15, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (fca5b82) 69.18% compared to head (724c08a) 69.18%.
Report is 13 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #26281   +/-   ##
=======================================
  Coverage   69.18%   69.18%           
=======================================
  Files        1945     1945           
  Lines       75948    75950    +2     
  Branches     8458     8458           
=======================================
+ Hits        52546    52548    +2     
  Misses      21217    21217           
  Partials     2185     2185           
Flag Coverage Δ
hive 53.67% <100.00%> (+<0.01%) ⬆️
mysql 78.06% <100.00%> (-0.02%) ⬇️
postgres 78.18% <100.00%> (+<0.01%) ⬆️
presto 53.63% <100.00%> (+<0.01%) ⬆️
python 82.86% <100.00%> (+<0.01%) ⬆️
sqlite 76.84% <100.00%> (+<0.01%) ⬆️
unit 55.79% <50.00%> (-0.01%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

Nice! A quick glance at my venv revealed that at least the default MSSQL and Snowflake dialects are overriding this with their own logic, with the default falling back to quote as stated here. LGTM

@@ -1433,8 +1433,9 @@ def select_star( # pylint: disable=too-many-arguments,too-many-locals
if show_cols:
fields = cls._get_fields(cols)
quote = engine.dialect.identifier_preparer.quote
quote_schema = engine.dialect.identifier_preparer.quote_schema
Copy link
Member

Choose a reason for hiding this comment

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

Daydreaming: How I wish Python had this syntax like JS/TS does..

{ quote, quote_schema } = engine.dialect.identifier_preparer

Copy link
Member

Choose a reason for hiding this comment

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

TIL I learned that quote_schema was a thing. Do we need to use this everywhere we use the quote method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wherever a schema is the input argument, yes. For table names and the like, quote is fine. As far as I could tell this is the only place where a schema name is formatted

@guenp
Copy link
Contributor Author

guenp commented Dec 20, 2023

Please merge this PR. We need it to address this issue: #26286

@john-bodley john-bodley merged commit 9d37968 into apache:master Dec 20, 2023
34 checks passed
@guenp guenp deleted the guenp/fixes-for-schema-dropdown branch December 20, 2023 17:58
@michael-s-molina michael-s-molina added v3.1 Label added by the release manager to track PRs to be included in the 3.1 branch v3.0 Label added by the release manager to track PRs to be included in the 3.0 branch labels Dec 21, 2023
michael-s-molina pushed a commit that referenced this pull request Dec 27, 2023
michael-s-molina pushed a commit that referenced this pull request Dec 27, 2023
josedev-union pushed a commit to Ortege-xyz/studio that referenced this pull request Jan 22, 2024
@mistercrunch mistercrunch added 🍒 3.0.3 🍒 3.0.4 🍒 3.1.0 🍒 3.1.1 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels labels Mar 8, 2024
sfirke pushed a commit to sfirke/superset that referenced this pull request Mar 22, 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/XS v3.0 Label added by the release manager to track PRs to be included in the 3.0 branch v3.1 Label added by the release manager to track PRs to be included in the 3.1 branch 🍒 3.0.3 🍒 3.0.4 🍒 3.1.0 🍒 3.1.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants