rusackas commented on code in PR #42895:
URL: https://github.com/apache/superset/pull/42895#discussion_r3817903195


##########
tests/unit_tests/models/helpers_test.py:
##########
@@ -2133,6 +2133,65 @@ def 
test_adhoc_metric_to_sqla_invalid_simple_aggregate_raises_validation_error(
         table.adhoc_metric_to_sqla(metric, {})
 
 
+def test_adhoc_metric_to_sqla_extended_aggregate_on_supported_engine() -> None:
+    """
+    MEDIAN/STDDEV_SAMP/VAR_SAMP compile correctly end-to-end on an engine that
+    supports them (Postgres), via the same `adhoc_metric_to_sqla` path every
+    other aggregate uses -- no pivot-table-specific code involved.

Review Comment:
   Parametrized this over all three aggregates (MEDIAN/STDDEV_SAMP/VAR_SAMP), 
each asserting its own expected SQL fragment.



##########
tests/unit_tests/db_engine_specs/test_duckdb.py:
##########
@@ -191,3 +191,26 @@ def test_fetch_data_preserves_cursor_description(mocker: 
MockerFixture) -> None:
         assert [col[0] for col in cursor.description] == ["col1", "col2"]
     finally:
         raw_conn.close()
+
+
+def test_extended_aggregation_func_median_stddev_var() -> None:
+    """
+    Verified against a live in-process duckdb instance, including under
+    GROUPING SETS: values match the same-input results from postgres/mysql
+    exactly.
+    """

Review Comment:
   Added a second test that runs these against a live in-process DuckDB 
connection and checks the results against `statistics.median/stdev/variance`. 
Left the compile-only test too, retitled so its docstring matches what it 
actually checks.



##########
superset/utils/core.py:
##########
@@ -1820,7 +1831,9 @@ def get_metric_type_from_column(column: Any, datasource: 
Explorable) -> str:
     expression: str = metric.expression
 
     match = re.match(
-        r"(SUM|AVG|COUNT|COUNT_DISTINCT|MIN|MAX|FIRST|LAST)\((.*)\)", 
expression
+        r"(SUM|AVG|COUNT|COUNT_DISTINCT|MIN|MAX|FIRST|LAST"
+        r"|MEDIAN|STDDEV_SAMP|VAR_SAMP)\((.*)\)",

Review Comment:
   Made the regex case-insensitive and tolerant of whitespace before the paren. 
Note the case sensitivity predates this PR (same pattern already applied to 
SUM/AVG/etc.) but worth fixing while touching this line.



-- 
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]

Reply via email to