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(BigQuery): Support special characters in column/metric names used in ORDER BY #26461

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,9 @@
and db_engine_spec.allows_hidden_cc_in_orderby
and col.name in [select_col.name for select_col in select_exprs]
):
col = literal_column(col.name)
engine = self.database._get_sqla_engine()
quote = engine.dialect.identifier_preparer.quote
col = literal_column(quote(col.name))

Check warning on line 1979 in superset/models/helpers.py

View check run for this annotation

Codecov / codecov/patch

superset/models/helpers.py#L1977-L1979

Added lines #L1977 - L1979 were not covered by tests
Copy link
Member

Choose a reason for hiding this comment

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

Interesting. Typically the SQLAlchemy dialect should handle the quoting. Additionally it's unclear whether forceably quoting the column would be problematic when combined with an alias.

@villebro do you have any insights on this? I see previously you registered sqlalchemy/sqlalchemy#4730 related to SQLAlchemy not quoting.

direction = sa.asc if ascending else sa.desc
qry = qry.order_by(direction(col))

Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/db_engine_specs/bigquery_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,4 @@ def test_calculated_column_in_order_by(self):
"orderby": [["gender_cc", True]],
}
sql = table.get_query_str(query_obj)
assert "ORDER BY gender_cc ASC" in sql
assert "ORDER BY `gender_cc` ASC" in sql
Loading