Skip to content

Commit

Permalink
fix(BigQuery): Support special characters in column/metric names used…
Browse files Browse the repository at this point in the history
… in ORDER BY (#26461)

(cherry picked from commit 4592dd1)
  • Loading branch information
Vitor-Avila authored and michael-s-molina committed Jan 25, 2024
1 parent 31680e3 commit a2c78c1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1965,7 +1965,9 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
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)
with self.database.get_sqla_engine_with_context() as engine:
quote = engine.dialect.identifier_preparer.quote
col = literal_column(quote(col.name))
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

0 comments on commit a2c78c1

Please sign in to comment.