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


##########
superset/mcp_service/chart/schemas.py:
##########
@@ -1045,6 +1045,63 @@ def reject_sql_expression_on_dimensions(self) -> 
"PieChartConfig":
         return self
 
 
+class SankeyChartConfig(BaseChartConfig):
+    """Config for sankey charts (viz_type ``sankey_v2``).
+
+    Matches the frontend Sankey buildQuery contract: a ``source`` and a
+    ``target`` column define the edges of the flow diagram and one ``metric``
+    weights each edge. When ``sort_by_metric`` is set the query orders by the
+    metric descending.
+    """
+
+    model_config = ConfigDict(extra="ignore", populate_by_name=True)
+
+    chart_type: Literal["sankey_v2"] = "sankey_v2"
+    source: ColumnRef = Field(
+        ...,
+        description="Column used as the source (origin) node of each edge",
+    )
+    target: ColumnRef = Field(
+        ...,
+        description="Column used as the target (destination) node of each 
edge",
+    )
+    metric: ColumnRef = Field(
+        ...,
+        description="Metric weighting each edge (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 edges by the metric descending (frontend default)",
+    )
+    row_limit: int = Field(10000, description="Max edges queried", ge=1, 
le=100000)
+    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_nodes(self) -> "SankeyChartConfig":
+        """source and target are node dimensions, not metrics."""
+        for col, name in ((self.source, "source"), (self.target, "target")):
+            _reject_sql_expression_on_dimension(col, name)
+            if col and col.saved_metric:
+                raise ValueError(
+                    f"{name} cannot use saved_metric=True; "
+                    "saved metrics belong in the 'metric' field"
+                )

Review Comment:
   ✅ **CodeAnt verified this suggestion was addressed in subsequent commits and 
marked this thread resolved** as of `c47db17`.
   
   Source and target are now rejected when `col.is_metric` is true, covering 
aggregated or saved-metric references and requiring plain node columns.
   
   <sub>If that's not right, unresolve this thread and CodeAnt will leave it 
open.</sub>
   
   <!-- codeant-auto-resolve-reply -->



##########
superset/mcp_service/chart/chart_utils.py:
##########
@@ -1017,6 +1018,27 @@ def map_pie_config(config: PieChartConfig) -> Dict[str, 
Any]:
     return form_data
 
 
+def map_sankey_config(config: SankeyChartConfig) -> Dict[str, Any]:
+    """Map sankey config to Superset form_data (viz_type ``sankey_v2``).
+
+    Matches the frontend Sankey buildQuery contract: a ``source`` and
+    ``target`` column form the edges (the query groups by both) and one
+    ``metric`` weights each edge. When ``sort_by_metric`` is set the query
+    orders by the metric descending.
+    """
+    form_data: Dict[str, Any] = {
+        "viz_type": "sankey_v2",
+        "source": config.source.name,
+        "target": config.target.name,
+        "metric": create_metric_object(config.metric),

Review Comment:
   ✅ **CodeAnt verified this suggestion was addressed in subsequent commits and 
marked this thread resolved** as of `c47db17`.
   
   The Sankey form data now explicitly includes `groupby` containing both the 
source and target column names.
   
   <sub>If that's not right, unresolve this thread and CodeAnt will leave it 
open.</sub>
   
   <!-- codeant-auto-resolve-reply -->



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