codeant-ai-for-open-source[bot] commented on code in PR #42895:
URL: https://github.com/apache/superset/pull/42895#discussion_r3761946104


##########
superset/utils/core.py:
##########
@@ -1797,7 +1808,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:
   **Suggestion:** The newly recognized aggregates are matched only in exact 
uppercase form and only when the opening parenthesis immediately follows the 
function name. Valid saved metric expressions such as `stddev_samp(value)` or 
`STDDEV_SAMP (value)` therefore fall through to the empty type, causing 
incorrect dtype inference. Make the match case-insensitive, normalize the 
captured operation before looking it up, and allow optional whitespace before 
the parenthesis. [type error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Numeric aggregate results can receive incorrect inferred types.
   - ⚠️ Affected charts with all-null aggregate result columns.
   - ⚠️ Lowercase SQLAlchemy aggregate expressions are already emitted by 
supported engines.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a97579e1e22e4beeb908551756c760cb&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a97579e1e22e4beeb908551756c760cb&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/utils/core.py
   **Line:** 1811:1812
   **Comment:**
        *Type Error: The newly recognized aggregates are matched only in exact 
uppercase form and only when the opening parenthesis immediately follows the 
function name. Valid saved metric expressions such as `stddev_samp(value)` or 
`STDDEV_SAMP (value)` therefore fall through to the empty type, causing 
incorrect dtype inference. Make the match case-insensitive, normalize the 
captured operation before looking it up, and allow optional whitespace before 
the parenthesis.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42895&comment_hash=b7e57a6c1023e438d6e3b9e22f887d112742138c96acda39084add23caa02304&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42895&comment_hash=b7e57a6c1023e438d6e3b9e22f887d112742138c96acda39084add23caa02304&reaction=dislike'>👎</a>



##########
superset/db_engine_specs/postgres.py:
##########
@@ -192,6 +194,18 @@ class PostgresBaseEngineSpec(BaseEngineSpec):
         TimeGrain.YEAR: "DATE_TRUNC('year', {col})",
     }
 
+    # Verified against a live postgres:16 instance, including under GROUPING
+    # SETS (the pivot table's non-additive-total rollup pattern): the grand
+    # total correctly reflects every row, not an aggregate-of-aggregates.
+    # Inherited by Redshift (a Postgres fork); its SQL function reference
+    # documents the same PERCENTILE_CONT/STDDEV_SAMP/VAR_SAMP support, but
+    # that has not been separately verified against a live Redshift instance.
+    _extended_aggregations: dict[str, Callable[[ColumnElement], 
ColumnElement]] = {
+        "MEDIAN": lambda col: sa.func.percentile_cont(0.5).within_group(col),
+        "STDDEV_SAMP": sa.func.stddev_samp,
+        "VAR_SAMP": sa.func.var_samp,
+    }

Review Comment:
   **Suggestion:** The mapping is defined on `PostgresBaseEngineSpec`, so every 
subclass that does not explicitly override `_extended_aggregations` inherits 
these functions. This enables PostgreSQL-specific aggregate SQL for unverified 
subclasses such as `TimescaleDBEngineSpec` and `AuroraPostgresEngineSpec`, 
contrary to the opt-in contract and potentially causing query failures or 
incorrect results on those engines. Define the mapping only on verified 
concrete specs, or explicitly opt out every unverified subclass. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ TimescaleDB queries may emit unverified PostgreSQL aggregate SQL.
   - ❌ Aurora PostgreSQL queries bypass the intended opt-in boundary.
   - ⚠️ Unsupported aggregates can fail during chart query execution.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a3371f60b0434f4db62fde4e524e91db&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a3371f60b0434f4db62fde4e524e91db&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/db_engine_specs/postgres.py
   **Line:** 203:207
   **Comment:**
        *Api Mismatch: The mapping is defined on `PostgresBaseEngineSpec`, so 
every subclass that does not explicitly override `_extended_aggregations` 
inherits these functions. This enables PostgreSQL-specific aggregate SQL for 
unverified subclasses such as `TimescaleDBEngineSpec` and 
`AuroraPostgresEngineSpec`, contrary to the opt-in contract and potentially 
causing query failures or incorrect results on those engines. Define the 
mapping only on verified concrete specs, or explicitly opt out every unverified 
subclass.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42895&comment_hash=6122476b06756c2359c551aeb04887cecf10ed552af80f0c87f77091df22e03e&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42895&comment_hash=6122476b06756c2359c551aeb04887cecf10ed552af80f0c87f77091df22e03e&reaction=dislike'>👎</a>



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