Skip to content

feat: Implement map-to-string casting#4647

Open
getChan wants to merge 4 commits into
apache:mainfrom
getChan:fix-map-cast-string
Open

feat: Implement map-to-string casting#4647
getChan wants to merge 4 commits into
apache:mainfrom
getChan:fix-map-cast-string

Conversation

@getChan

@getChan getChan commented Jun 13, 2026

Copy link
Copy Markdown

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 infers Map<NullType, NullType>.

What changes are included in this PR?

  • Implement native map-to-string rendering in native/spark-expr.
  • Wire Spark-side cast support for MapType -> StringType in CometCast.
  • Include empty map support by handling NullType -> StringType in cast support checks.
  • Extend codegen NullType handling needed by Map<NullType, NullType>:
    • type admission for NullType
    • output path (NullVector, null-only write/getter handling)
    • input nested read/copy path (NullType getter/copy handling).
  • Update SQL test expectation so 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

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@andygrove andygrove changed the title Implement map-to-string casting feat: Implement map-to-string casting Jun 13, 2026
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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this is the intended behavior. How should we handle the empty map(Map<NullType, NullType) case?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically we can cast it, we have everything for it.
Perhaps it would be enough to add NullType to list of supported types?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@comphead Thanks for review. I updated the code to support empty maps. Please refer to the PR description for details.

getChan and others added 2 commits June 21, 2026 23:37
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"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: Improve cast MapType to String

2 participants