aminghadersohi commented on code in PR #44270:
URL: https://github.com/apache/superset/pull/44270#discussion_r4034958884


##########
superset/mcp_service/semantic_layer/tool/get_table.py:
##########
@@ -180,8 +194,52 @@ def _resolve_external_view(
             error_type="ValidationError",
         )
 
+    duration: str | None
+    valid_grains: dict[str, str] = {
+        duration: grain["name"]
+        for grain in view.get_time_grains()
+        if (duration := grain["duration"]) is not None
+    }
+    grain_column: str | None = request.time_column
+    if request.time_grain:
+        selected: list[str] = sorted(set(request.dimensions) & 
valid_dttm_columns)
+        if grain_column is None:
+            if len(selected) != 1:
+                return SemanticLayerError.create(
+                    error=f"time_grain on view '{display_name}' requires one 
temporal "
+                    f"dimension; selected: {selected}. Set time_column 
explicitly.",
+                    error_type="ValidationError",
+                )
+            grain_column = selected[0]
+        # The mapper chooses variants by dimension name, not the view-wide 
union.
+        valid_grains = {
+            dimension.grain.representation: dimension.grain.name
+            for dimension in view.implementation.get_dimensions()
+            if dimension.name == grain_column and dimension.grain is not None
+        }
+        if request.time_grain not in valid_grains:
+            choices: str = ", ".join(
+                f"{duration} ({name})"
+                for duration, name in sorted(valid_grains.items())
+            )

Review Comment:
   Reusing `valid_grains` for the per-column narrowing also narrows what 
reaches `_validate_request_names`, so the grain-alias hint regresses: with 
`time_grain=P1D` on `metric_time`, `signup_date__Year` no longer gets the 
`time_grain='P1Y'` redirect (verified).
   
   ```suggestion
           column_grains: dict[str, str] = {
               dimension.grain.representation: dimension.grain.name
               for dimension in view.implementation.get_dimensions()
               if dimension.name == grain_column and dimension.grain is not None
           }
           if request.time_grain not in column_grains:
               choices: str = ", ".join(
                   f"{duration} ({name})"
                   for duration, name in sorted(column_grains.items())
               )
   ```



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