Skip to content

[Feature] CAST(MapType AS MapType) falls back even though native cast_map_to_map exists #4491

@andygrove

Description

@andygrove

Describe the bug

CometCast.isSupported has no MapType arm; any cast involving a MapType source or target falls into the default case _ => unsupported(fromType, toType) and falls back to Spark.

However, the native side already has a cast_map_to_map function (see native/spark-expr/src/conversion_funcs/cast.rs around line 423). The Scala side just never routes to it, so CAST(<map> AS MAP<...>) falls back unnecessarily.

Surfaced by the cast audit (collection PR queue).

Expected behavior

Add a (MapType, MapType) arm to CometCast.isSupported that recursively checks the source / target key and value types and returns Compatible (or Incompatible(reason)) when both inner casts are supported. Wire the recursion the same way Array -> Array and Struct -> Struct are handled in CometCast.scala.

Additional context

  • Native impl: native/spark-expr/src/conversion_funcs/cast.rs::cast_map_to_map
  • Comet matrix: CometCast.scala
  • For Map -> String, Spark formats as {k1 -> v1, k2 -> v2}; the native path would need a cast_map_to_string analogous to the existing cast_struct_to_string. Out of scope here; this issue is only the Map -> Map case.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions