fix(BigQuery): Support special characters in column/metric names used in ORDER BY (#26461)

This commit is contained in:
Vitor Avila 2024-01-24 00:26:53 -03:00 committed by GitHub
parent 8150c25dbb
commit 4592dd13fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View File

@ -1972,7 +1972,9 @@ class ExploreMixin: # pylint: disable=too-many-public-methods
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))

View File

@ -381,4 +381,4 @@ class TestBigQueryDbEngineSpec(TestDbEngineSpec):
"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