codeant-ai-for-open-source[bot] commented on code in PR #43891:
URL: https://github.com/apache/superset/pull/43891#discussion_r3949601451
##########
superset/connectors/sqla/partition_mapping.py:
##########
@@ -689,27 +783,94 @@ def preview_partition_mapping(
transform=value_transform,
engine=engine,
):
- return {"valid": False, "error": str(issue.message)}
+ return {
+ "valid": False,
+ # The parse failure is the one an owner sees constantly, and it is
+ # the only one the mockup gives its own headline to.
+ "reason": (
+ "parse"
+ if issue.field == "partition_value_transform"
+ and not is_parseable(value_transform, engine)
+ else "validation"
+ ),
+ "error": str(issue.message),
+ }
- evaluated = evaluate_transform(
- datasource.database,
- datasource.catalog,
- datasource.schema,
- cast(str, value_transform),
- [sample_value],
+ mapping = PartitionMapping(
+ partition_column=str(partition_column),
+ mapped_column=mapped_column,
+ value_transform=cast(str, value_transform),
+ is_monotonic=is_monotonic,
)
- if evaluated is None:
+ sample_input = _render_sample_input(mapped_column, operator, sample_values)
+
+ if not mapping.mirrors(operator):
return {
"valid": False,
- "error": _("The transform could not be evaluated against the
database."),
+ "reason": "operator",
+ "sample_input": sample_input,
+ "error": _(
+ "A %(operator)s filter is only mirrored when the transform "
+ "preserves ordering, which this one is not declared to do.",
+ operator=operator.value,
+ ),
+ }
+
+ value: Any = sample_values if operator == FilterOperator.IN else
sample_values[0]
+ errors: list[str] = []
+ predicates = build_mirrored_predicates(
+ datasource, mapping, [(operator, value)], errors=errors
+ )
Review Comment:
Yes, this is a valid issue. `TEMPORAL_RANGE` is included in
`MIRRORABLE_OPERATORS`, but this preview path supplies a scalar value:
```python
[(operator, value)]
```
`build_mirrored_predicates` eventually routes that to the scalar comparison
handler, where `TEMPORAL_RANGE` raises `ValueError`, resulting in a 500.
The preview should not advertise an operator it cannot construct correctly.
Since the current payload and UI provide only one sample bound, the minimal
safe fix is to reject `TEMPORAL_RANGE` for preview requests with a validation
response, or remove it from the preview schema’s `OneOf` list while leaving it
supported by the chart-query path.
If preview support is required, it must instead accept two bounds and pass
them through the same temporal-range representation used by chart queries; it
should not call the scalar comparison handler. Add a regression test asserting
that a `TEMPORAL_RANGE` preview cannot produce a 500.
--
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]