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 Apache Superset When creating a metric, CUSTOM SQL does not use quotation marks even though they are sometimes necessary

When creating a simple metric, the Custom SQL is generated The metric is OK a result is well returned Apache Superset When creating a metric, CUSTOM SQL does not use quotation marks even though they are sometimes necessary

but the Custom SQL is wrong, It does not use quotes Apache Superset When creating a metric, CUSTOM SQL does not use quotation marks even though they are sometimes necessary

If a user create saved metric with this Custom SQL, the saved metric is unusable Apache Superset When creating a metric, CUSTOM SQL does not use quotation marks even though they are sometimes necessary

Sincerly

Screenshots/recordings

No response

Superset version

master / latest-dev

Python version

3.9

Node version

16

Browser

Chrome

Additional context

No response

Checklist

  • [X] I have searched Superset docs and Slack and didn't find a solution to my problem.
  • [X] I have searched the GitHub issue tracker and didn't find a similar bug report.
  • [X] 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.

Comment From: dosubot[bot]

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.

Comment From: rluech

We notice the same issue (querying Oracle where force_column_alias_quotes is set True by default: class OracleEngineSpec).

Comment From: rusackas

Is this still the case on master now that SQLGlot has replaced SQLParse