rusackas commented on code in PR #41870:
URL: https://github.com/apache/superset/pull/41870#discussion_r3543524043
##########
tests/integration_tests/db_engine_specs/base_engine_spec_tests.py:
##########
@@ -202,6 +204,51 @@ def
test_calculated_column_in_order_by_base_engine_spec(self):
in sql
)
+ @mock.patch("superset.models.core.Database.db_engine_spec", BaseEngineSpec)
+ @pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
+ def test_jinja_calculated_column_in_order_by(self) -> None:
+ """
+ A calculated column referenced by a SIMPLE adhoc metric in `orderby`
+ should have its Jinja template rendered, the same way it is for
+ SELECT/WHERE/GROUP BY.
+ """
+ table = self.get_table(name="birth_names")
+ TableColumn(
+ column_name="gender_cc_jinja",
+ type="VARCHAR(255)",
+ table=table,
+ expression="""
+ case
+ when gender='boy' then {{ "'male'" }}
+ else {{ "'female'" }}
+ end
+ """,
+ )
+
+ table.database.sqlalchemy_uri = "sqlite://"
+ query_obj = {
+ "groupby": ["gender_cc_jinja"],
+ "is_timeseries": False,
+ "filter": [],
+ "orderby": [
+ [
+ {
+ "expressionType": "SIMPLE",
+ "column": {"column_name": "gender_cc_jinja"},
+ "aggregate": "MAX",
+ "label": "max_gender_cc_jinja",
+ },
+ True,
+ ]
+ ],
+ }
+ sql = table.get_query_str(cast(QueryObjectDict, query_obj))
Review Comment:
Annotated `query_obj` as `QueryObjectDict` directly and dropped the cast.
Had to switch the `orderby` entry from a list to a tuple to satisfy mypy
against `OrderBy`, which is `tuple[Metric | Column, bool]`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]