You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "andygrove (via GitHub)" <gi...@apache.org> on 2026/09/28 15:51:40 UTC
[PR] docs: document casts involving arrays, structs, and maps [datafusion-comet]
andygrove opened a new pull request, #6320:
URL: https://github.com/apache/datafusion-comet/pull/6320
## Which issue does this PR close?
Closes #2743.
## Rationale for this change
The cast compatibility page only covers casts between primitive types. #2760 was closed until the
complex-type casts had test coverage, which the #4248 work has since added.
## What changes are included in this PR?
A new Complex Types section in the cast compatibility template, which is copied into every Spark
version's page:
- The rule: arrays, structs and maps are cast element by element, field by field, and key and
value by key and value, so a complex-type cast is compatible only when every cast it contains
is compatible.
- A table covering array to array, array to string, struct to struct (fields matched by position),
struct to string, map to map, and map to string, which has no native path.
- The exceptions: `ARRAY<DATE>`, `DATE` struct fields and map values cast to numeric or boolean
types, and `spark.sql.legacy.castComplexTypesToString.enabled`.
- A known-issue note for a Try-mode map cast whose key cast fails (#5995).
- Pointers to the new section from the page intro and from Date to Numeric Types.
The `DATE` struct field and map value bullet describes the behavior after #6319, so this should
merge after that PR.
## How are these changes tested?
Documentation only. I checked each claim against `CometCast.isSupported`, and against Spark with a
probe over every container shape (struct field, map value, array element, array of struct) for
each primitive target type in Legacy mode. That probe is what turned up #6316. The #5995 failure
reproduces on `main`. The page renders through `GenerateDocs` for Spark 4.1, and prettier passes.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] docs: document casts involving arrays, structs, and maps [datafusion-comet]
Posted by "kazuyukitanimura (via GitHub)" <gi...@apache.org>.
kazuyukitanimura commented on code in PR #6320:
URL: https://github.com/apache/datafusion-comet/pull/6320#discussion_r4225575662
##########
docs/source/user-guide/latest/compatibility/expressions/_category_template/cast.md:
##########
@@ -161,6 +165,38 @@ Spark's behavior of using Java `BigDecimal.toString()` semantics, which produces
notation (e.g. a value of 12300 stored as `Decimal(7,-2)` with unscaled value 123 is rendered
as `"1.23E+4"`).
+## Complex Types
+
+Comet casts arrays, structs, and maps by casting each element, field, key, and value with the
+rules for primitive types, using the table for the same eval mode. A complex-type cast is
+therefore compatible only when every cast it contains is compatible. For example, casting
+`ARRAY<INT>` to `ARRAY<BIGINT>` has the same support level as casting `INT` to `BIGINT`, and a
+struct cast with one unsupported field cast is unsupported. The rules apply at every level of
+nesting, so casting `ARRAY<STRUCT<a: INT>>` to `ARRAY<STRUCT<a: BIGINT>>` also has the same
+support level as casting `INT` to `BIGINT`.
+
+| From | To | Support level |
+| ----------- | ------------- | ---------------------------------------------------------------------------- |
+| `ARRAY<T>` | `ARRAY<U>` | Same as `T` to `U` |
+| `ARRAY<T>` | `STRING` | Same as `T` to `STRING` |
+| `STRUCT` | `STRUCT` | Compatible if every field cast is compatible. Fields are matched by position |
+| `STRUCT` | `STRING` | Compatible if the cast from every field to `STRING` is compatible |
+| `MAP<K, V>` | `MAP<K2, V2>` | Compatible if `K` to `K2` and `V` to `V2` are both compatible |
+| `MAP<K, V>` | `STRING` | Unsupported |
+
+The following casts are exceptions to these rules:
+
+- `ARRAY<DATE>` can only be cast natively to `ARRAY<INT>` or `ARRAY<STRING>`. Casts to other array
+ types are unsupported.
+- A cast from a `DATE` struct field or map value to a numeric or boolean type is unsupported. In
+ Legacy mode these casts always return `NULL` (see [Date to Numeric Types](#date-to-numeric-types)).
+- When `spark.sql.legacy.castComplexTypesToString.enabled=true`, casts from arrays, structs, and
+ maps to `STRING` are unsupported, because Comet's native cast only produces Spark's default
+ string format.
+
+In Try mode, a cast between maps fails with an error when a key cannot be cast, where Spark returns
Review Comment:
One coordination question about this paragraph. #6178 is open and makes this cast avoid the failing path, but it doesn't touch cast.md. Could we make sure whichever PR lands second removes or updates this note? Otherwise the page will keep listing a known issue that's already been fixed. It might also help to say that this only affects key casts that Spark accepts under TRY_CAST, such as narrowing BIGINT to INT. Spark already rejects a STRING key cast at analysis.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] docs: document casts involving arrays, structs, and maps [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #6320:
URL: https://github.com/apache/datafusion-comet/pull/6320#discussion_r4285487479
##########
docs/source/user-guide/latest/compatibility/expressions/_category_template/cast.md:
##########
@@ -161,6 +165,38 @@ Spark's behavior of using Java `BigDecimal.toString()` semantics, which produces
notation (e.g. a value of 12300 stored as `Decimal(7,-2)` with unscaled value 123 is rendered
as `"1.23E+4"`).
+## Complex Types
+
+Comet casts arrays, structs, and maps by casting each element, field, key, and value with the
+rules for primitive types, using the table for the same eval mode. A complex-type cast is
+therefore compatible only when every cast it contains is compatible. For example, casting
+`ARRAY<INT>` to `ARRAY<BIGINT>` has the same support level as casting `INT` to `BIGINT`, and a
+struct cast with one unsupported field cast is unsupported. The rules apply at every level of
+nesting, so casting `ARRAY<STRUCT<a: INT>>` to `ARRAY<STRUCT<a: BIGINT>>` also has the same
+support level as casting `INT` to `BIGINT`.
+
+| From | To | Support level |
+| ----------- | ------------- | ---------------------------------------------------------------------------- |
+| `ARRAY<T>` | `ARRAY<U>` | Same as `T` to `U` |
+| `ARRAY<T>` | `STRING` | Same as `T` to `STRING` |
+| `STRUCT` | `STRUCT` | Compatible if every field cast is compatible. Fields are matched by position |
+| `STRUCT` | `STRING` | Compatible if the cast from every field to `STRING` is compatible |
+| `MAP<K, V>` | `MAP<K2, V2>` | Compatible if `K` to `K2` and `V` to `V2` are both compatible |
+| `MAP<K, V>` | `STRING` | Unsupported |
+
+The following casts are exceptions to these rules:
+
+- `ARRAY<DATE>` can only be cast natively to `ARRAY<INT>` or `ARRAY<STRING>`. Casts to other array
+ types are unsupported.
+- A cast from a `DATE` struct field or map value to a numeric or boolean type is unsupported. In
+ Legacy mode these casts always return `NULL` (see [Date to Numeric Types](#date-to-numeric-types)).
+- When `spark.sql.legacy.castComplexTypesToString.enabled=true`, casts from arrays, structs, and
+ maps to `STRING` are unsupported, because Comet's native cast only produces Spark's default
+ string format.
+
+In Try mode, a cast between maps fails with an error when a key cannot be cast, where Spark returns
Review Comment:
Good point on the scope. I added a sentence saying the note only applies to key casts that Spark accepts under TRY_CAST, such as narrowing BIGINT to INT, and that Spark rejects a STRING key cast at analysis (39b23dc142). On ordering, whichever of this PR and #6178 lands second should delete or update the note. I'll check this page when #6178 merges, and I'll note the cast.md follow-up on that PR so it isn't missed.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] docs: document casts involving arrays, structs, and maps [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove merged PR #6320:
URL: https://github.com/apache/datafusion-comet/pull/6320
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org