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


##########
superset/mcp_service/chart/schemas.py:
##########
@@ -1045,6 +1045,61 @@ def reject_sql_expression_on_dimensions(self) -> 
"PieChartConfig":
         return self
 
 
+class TreemapChartConfig(BaseChartConfig):
+    """Config for treemap charts (viz_type ``treemap_v2``).
+
+    Matches the frontend Treemap buildQuery contract: one ``metric`` sizing
+    the tiles plus an ordered ``groupby`` hierarchy — the first column is the
+    outermost level and each subsequent column nests inside it. When
+    ``sort_by_metric`` is set, tiles are ordered by the metric descending.
+    """
+
+    model_config = ConfigDict(extra="ignore", populate_by_name=True)
+
+    chart_type: Literal["treemap_v2"] = "treemap_v2"
+    groupby: List[ColumnRef] = Field(
+        ...,
+        min_length=1,
+        description="Ordered category columns forming the treemap hierarchy "
+        "(first = outermost level; order defines nesting)",
+    )
+    metric: ColumnRef = Field(
+        ...,
+        description="Value metric sizing the tiles (use aggregate e.g. SUM, "
+        "COUNT for ad-hoc, or set saved_metric=True for a saved dataset 
metric)",
+    )
+    sort_by_metric: bool = Field(
+        True,
+        description="Order tiles by the metric descending (frontend default)",
+    )
+    row_limit: int = Field(100, description="Max rows queried", ge=1, le=10000)
+    filters: List[FilterConfig] | None = Field(
+        None,
+        description="Structured filters (column/op/value). "
+        "Do NOT use adhoc_filters or raw SQL expressions.",
+    )
+    color_scheme: str | None = Field(
+        None,
+        description=(
+            "Superset color scheme ID (e.g. 'supersetColors', 'lyftColors', "
+            "'googleCategory10c', 'd3Category10'). Defaults to 
'supersetColors'."
+        ),
+        max_length=100,
+    )
+
+    @model_validator(mode="after")
+    def reject_metric_style_groupby(self) -> "TreemapChartConfig":
+        """groupby entries are hierarchy dimensions, not metrics."""
+        for i, col in enumerate(self.groupby or []):
+            _reject_sql_expression_on_dimension(col, f"groupby[{i}]")
+            if col.saved_metric:
+                raise ValueError(
+                    f"groupby[{i}] cannot use saved_metric=True; "
+                    "saved metrics belong in the 'metric' field"
+                )
+        return self

Review Comment:
   **Suggestion:** The validator rejects `saved_metric` and `sql_expression`, 
but it still accepts `aggregate` on a `groupby` entry even though `aggregate` 
also marks a `ColumnRef` as a metric. `map_treemap_config` later emits only 
each entry's name, silently discarding the aggregate and changing an invalid 
metric-style hierarchy entry into an unaggregated dimension. Reject non-null 
`aggregate` values for treemap hierarchy columns as well. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Minor 🧹</summary>
   
   ```mdx
   - ⚠️ `generate_chart` accepts invalid metric-style treemap hierarchy entries.
   - ⚠️ Treemap form-data silently drops requested aggregates.
   - ⚠️ Generated hierarchy differs from the caller’s configuration.
   ```
   </details>
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![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=221fa095b50448aa9a326e094b04484a&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=221fa095b50448aa9a326e094b04484a&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/mcp_service/chart/schemas.py
   **Line:** 1090:1100
   **Comment:**
        *Api Mismatch: The validator rejects `saved_metric` and 
`sql_expression`, but it still accepts `aggregate` on a `groupby` entry even 
though `aggregate` also marks a `ColumnRef` as a metric. `map_treemap_config` 
later emits only each entry's name, silently discarding the aggregate and 
changing an invalid metric-style hierarchy entry into an unaggregated 
dimension. Reject non-null `aggregate` values for treemap hierarchy columns as 
well.
   
   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%2F43569&comment_hash=1149f400fdf1b757df82dd5b46363477f1abb7380314e5a56a4dc9c5c11b1a12&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43569&comment_hash=1149f400fdf1b757df82dd5b46363477f1abb7380314e5a56a4dc9c5c11b1a12&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