Skip to content

feat: Implement map-to-string casting#4647

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

feat: Implement map-to-string casting#4647
getChan wants to merge 2 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

Comet should render Spark map-to-string casts natively for non-empty maps, matching Spark's {k -> v, ...} formatting. Empty map() still falls back because Catalyst types it as Map<NullType, NullType>; no special-case handling is added here, so once null casting is supported this path should work naturally.

What changes are included in this PR?

  • Add native map-to-string rendering in native/spark-expr.
  • Update CometCast support checks so non-empty maps can execute natively.
  • Replace fallback expectations with result assertions for map string cases in cast_complex_types_to_string.sql, while keeping empty map fallback.
  • Add Scala regression coverage for the support check.
  • Used the implement-comet-expression workflow to scaffold the implementation.

How are these changes tested?

  • PROFILES='-Pspark-4.0' make format
  • ./mvnw test -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?

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

1 participant