sadpandajoe commented on code in PR #43527:
URL: https://github.com/apache/superset/pull/43527#discussion_r3867635875


##########
superset/datasource/schemas.py:
##########
@@ -140,3 +147,110 @@ def get_changed_on_delta_humanized(self, obj: 
SemanticView) -> str:
 
     def get_changed_on_utc(self, obj: SemanticView) -> str:
         return obj.changed_on_utc()
+
+
+class DatasourceQueryOrderSchema(Schema):
+    """One ordering term, mirroring SemanticQuery's OrderTuple."""
+
+    column = fields.String(
+        required=True,
+        metadata={"description": "Metric or dimension name to sort by."},
+    )
+    descending = fields.Boolean(
+        load_default=True,
+        metadata={"description": "Sort this column descending."},
+    )
+
+
+class DatasourceQuerySchema(Schema):
+    """Name-based query request for POST /datasource/<type>/<id>/query.
+
+    Field names mirror the semantic-layer vocabulary (``dimensions``,
+    ``metrics``) rather than Explore's (``columns``); translation to the
+    QueryObject shape happens in ``superset.common.tabular_query``.
+    """
+
+    # Raw, not String: Metric/Column are `AdhocMetric | str` and
+    # `AdhocColumn | str`, so ad-hoc expressions are accepted for datasets
+    # exactly as ChartDataQueryObjectSchema accepts them. Semantic views
+    # reject ad-hoc metrics downstream, in the mapper that owns that rule.
+    metrics = fields.List(
+        fields.Raw(),
+        load_default=list,
+        metadata={
+            "description": "Saved metric names, or ad-hoc metric objects "
+            "(datasets only). See ChartDataAdhocMetricSchema."
+        },
+    )
+    dimensions = fields.List(
+        fields.Raw(),
+        load_default=list,
+        metadata={"description": "Dimension/column names to group by."},
+    )
+    filters = fields.List(
+        fields.Nested(ChartDataFilterSchema),
+        load_default=list,
+        metadata={"description": "Filters to apply, AND-ed together."},
+    )
+    time_range = fields.String(
+        allow_none=True,
+        load_default=None,
+        metadata={"description": "e.g. 'Last 30 days' or '2024-01-01 : 
2024-12-31'."},
+    )
+    time_column = fields.String(
+        allow_none=True,
+        load_default=None,
+        metadata={
+            "description": "Temporal column the time range applies to. 
Inferred "
+            "from the datasource when omitted."
+        },
+    )
+    time_grain = fields.String(
+        allow_none=True,
+        load_default=None,
+        metadata={"description": "ISO 8601 duration, e.g. 'P1D' or 'PT1H'."},
+    )
+    limit = fields.Integer(
+        allow_none=True,
+        load_default=None,
+        validate=[Range(min=1, max=MAX_ROW_LIMIT)],
+        metadata={
+            "description": "Rows to return. Also clamped server-side by 
ROW_LIMIT."
+        },
+    )
+    offset = fields.Integer(
+        load_default=0,
+        validate=[Range(min=0)],
+        metadata={"description": "Rows to skip, for pagination."},
+    )
+    order = fields.List(
+        fields.Nested(DatasourceQueryOrderSchema),
+        load_default=list,
+        metadata={
+            "description": "Ordering terms, applied in sequence. Each carries 
its "
+            "own direction."
+        },
+    )
+    result_format = fields.Enum(

Review Comment:
   This enum also accepts `csv` and `xlsx`, but the response code only has 
Arrow and JSON branches. Either format produces bytes which the JSON response 
path then tries to serialize, so a valid request returns a 500 instead of the 
advertised result. Could this endpoint reject those formats until it has a 
matching response branch?



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