bito-code-review[bot] commented on code in PR #44744:
URL: https://github.com/apache/superset/pull/44744#discussion_r4122625008


##########
superset/mcp_service/chart/chart_helpers.py:
##########
@@ -767,14 +767,63 @@ def _build_single_query_dict(
     return qd
 
 
-def _build_gantt_or_big_number_query_dicts(
+def _build_specialized_query_dicts(
     form_data: dict[str, Any],
     viz_type: str,
     metrics: list[Any],
     row_limit: int | None,
     order_desc: bool | None,
 ) -> list[dict[str, Any]] | None:
-    """Build query dictionaries for the two specialized MCP chart contracts."""
+    """Build query dictionaries matching specialized frontend chart 
contracts."""
+    if viz_type == "histogram_v2":
+        column = form_data["column"]
+        groupby = form_data.get("groupby") or []
+        histogram_metrics = (
+            [
+                {
+                    "expressionType": "SQL",
+                    "sqlExpression": "COUNT(*)",
+                    "label": "COUNT(*)",
+                }
+            ]
+            if form_data.get("having")
+            else []
+        )
+        query = _build_single_query_dict(
+            form_data, [*groupby, column], histogram_metrics, 
row_limit=row_limit
+        )
+        query["post_processing"] = [
+            {
+                "operation": "histogram",
+                "options": {
+                    "column": get_column_name(column),
+                    "groupby": [get_column_name(group) for group in groupby],
+                    "bins": int(form_data.get("bins", 5)),
+                    "normalize": form_data.get("normalize", False),
+                    "cumulative": form_data.get("cumulative", False),
+                },
+            }
+        ]
+        return [query]
+
+    if viz_type == "waterfall":
+        axis = form_data.get("x_axis") or form_data.get("granularity_sqla")
+        columns = list(axis) if isinstance(axis, list) else [axis] if axis 
else []
+        columns.extend(form_data.get("groupby") or [])
+        query = _build_single_query_dict(
+            form_data, columns, metrics, row_limit=row_limit
+        )
+        query["orderby"] = [(column, True) for column in columns]
+        # Bind the time grain to the SQL time column, as extractExtras does.
+        granularity = form_data.get("granularity", 
form_data.get("granularity_sqla"))
+        if granularity is not None:
+            query["granularity"] = granularity
+        if form_data.get("time_grain_sqla") is not None:
+            query.setdefault("extras", {})["time_grain_sqla"] = form_data[
+                "time_grain_sqla"
+            ]

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>duplicated temporal binding</b></div>
   <div id="fix">
   
   The granularity fallback (`form_data.get("granularity", 
form_data.get("granularity_sqla"))`) and `extras["time_grain_sqla"]` binding 
here duplicate `_apply_treemap_query_fields` (lines 714-716) and the deck.gl 
path (lines 959-960). Three copies of the same temporal-binding rule will drift 
if precedence or extras handling changes. Consider a shared 
`_bind_time_grain(query, form_data)` helper.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #b1e383</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



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