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

When creating a metric, CUSTOM SQL does not use quotation marks even though they are sometimes necessary #30637

Open
3 tasks done
xavier-GitHub76 opened this issue Oct 17, 2024 · 1 comment
Labels
explore:metrics Related to metrics of Explore

Comments

@xavier-GitHub76
Copy link
Contributor

xavier-GitHub76 commented Oct 17, 2024

Bug description

Have a table with colum name using a space (It's not a good pratice but it is possible)

To succed, the SQL query must use quote (Select "name with space" from...) like
image

When creating a simple metric, the Custom SQL is generated
The metric is OK a result is well returned
image

but the Custom SQL is wrong, It does not use quotes
image

If a user create saved metric with this Custom SQL, the saved metric is unusable
image

Sincerly

Screenshots/recordings

No response

Superset version

master / latest-dev

Python version

3.9

Node version

16

Browser

Chrome

Additional context

No response

Checklist

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
Copy link

dosubot bot commented Oct 17, 2024

To address the issue of Custom SQL not using quotation marks for column names with spaces, you can ensure that the SQL generation logic in Superset correctly applies quotes to column names. Superset's SQL generation logic typically handles this by checking if column names are already quoted and applying quotes if they are not. This is done in the _get_fields method, which processes column names and ensures they are quoted correctly [1].

If you are using the Snowflake engine, the force_column_alias_quotes attribute is set to True, which ensures that column aliases are quoted, thus handling column names with spaces correctly [2].

If this issue persists across different database engines, you might need to check if there are specific configurations or patches required for the engine you are using. Additionally, reviewing the SQL generation logic in the Superset codebase for your specific setup might provide further insights into how to enforce quoting for column names with spaces.

To continue talking to Dosu, mention @dosu.

@dosubot dosubot bot added the explore:metrics Related to metrics of Explore label Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
explore:metrics Related to metrics of Explore
Projects
None yet
Development

No branches or pull requests

1 participant