feat: Implement map-to-string casting - #4647
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| query expect_fallback(Cast from MapType) | ||
| -- Empty map: still falls back because planning sees `map()` as `Map<NullType, NullType>`, | ||
| -- which reaches the existing NullType -> StringType cast fallback. | ||
| query expect_fallback(Cast from NullType to StringType is not supported) |
There was a problem hiding this comment.
not sure if this is the intended behavior. How should we handle the empty map(Map<NullType, NullType) case?
There was a problem hiding this comment.
technically we can cast it, we have everything for it.
Perhaps it would be enough to add NullType to list of supported types?
There was a problem hiding this comment.
@comphead Thanks for review. I updated the code to support empty maps. Please refer to the PR description for details.
Allow map nulltype key value to execute natively for cast map to string by enabling nulltype support in cast and codegen input output paths. Update SQL expectation for empty map from fallback to native query. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| @@ -672,6 +673,8 @@ private[codegen] object CometBatchKernelCodegenInput { | |||
| if (elementNullable) " if (isNullAt(i)) return null;\n" | |||
There was a problem hiding this comment.
This is intentional. NullType has no typed getter to override (there is no getNull API), so we emit no scalar getter here. Null semantics are handled via isNullAt (always true for NullVector) and generic get(..., NullType) dispatch, which returns null.
|
Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days. |
The rendering matches Spark's Four things. Does this honor
Is the map case gated by that check today? If not, a user with the legacy config gets a silently different string. If it is gated, a test with the config on asserting a fallback would pin it. Hidden entries outside a slice or under a null row The function casts the entire This is the same class of problem #5457 is fixing for nested casts generally. Is it reachable here? If the fix lands in
def isSupportedDataType(dt: DataType): Boolean = dt match {
case NullType => trueThat is in Is there an expression where a The propagation test was inverted
That is correct, but it means the original property is no longer covered. Could you add back a case with a genuinely unsupported nested type, for example |
Which issue does this PR close?
Closes #4631.
Rationale for this change
This PR implements native map-to-string casting in Comet to match Spark formatting (
{k -> v, ...}).As part of completing this feature, it also covers the empty-map case (
cast(map() as string)) where Catalyst infersMap<NullType, NullType>.What changes are included in this PR?
native/spark-expr.MapType -> StringTypeinCometCast.NullType -> StringTypein cast support checks.Map<NullType, NullType>:NullTypeNullVector, null-only write/getter handling)cast(map() as string)runs natively instead of fallback.How are these changes tested?
PROFILES='-Pspark-4.0' make format./mvnw -q test -DwildcardSuites=CometSqlFileTestSuite -Dsuites='org.apache.comet.CometSqlFileTestSuite cast_complex_types_to_string' -Dtest=none