apache / superset

Apache Superset is a Data Visualization and Data Exploration Platform
https://superset.apache.org/
Apache License 2.0
63.01k stars 13.96k forks source link

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

Open xavier-GitHub76 opened 1 month ago

xavier-GitHub76 commented 1 month ago

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

dosubot[bot] commented 1 month ago

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.