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(Databricks): Escape catalog and schema names in pre-queries #31199

Merged
merged 1 commit into from
Dec 2, 2024

Conversation

Vitor-Avila
Copy link
Contributor

@Vitor-Avila Vitor-Avila commented Nov 29, 2024

SUMMARY

It's possible to create catalogs and schemas in Databricks with special characters, which requires to always "escape" them in queries. For example, if you use a hyphen in a catalog name, you must run:

USE CATALOG `my-catalog`;

This PR escapes the catalog and schema names in the get_prequeries method for the Databricks Native Connector (if they were not escaped in the connect_args JSON).

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

No UI changes.

TESTING INSTRUCTIONS

Unit tests added. For manual testing:

  1. Create a catalog and a schema containing hyphens in Databricks.
  2. Connect Superset to the instance using the Databricks Native connector.
  3. Run a query in SQL Lab.

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

@dosubot dosubot bot added the data:connect:databricks Databricks DB Experience label Nov 29, 2024
@@ -464,8 +464,10 @@ def get_prequeries(
) -> list[str]:
prequeries = []
if catalog:
catalog = f"`{catalog}`" if not catalog.startswith("`") else catalog
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't use database.quote_identifier(), because the Database is no longer passed as an argument in >=4.1.0: https://github.com/apache/superset/blob/4.1.0/superset/db_engine_specs/base.py#L1412-L1431

Since this method is specifically for Databricks, I thought it was OK to hardcode the quote identifiers.

Copy link
Member

@betodealmeida betodealmeida left a comment

Choose a reason for hiding this comment

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

tenor-1030972582

@Vitor-Avila Vitor-Avila merged commit d66ac9f into master Dec 2, 2024
36 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data:connect:databricks Databricks DB Experience size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants