Skip to content

Avoid per-row sort dispatch when normalizing singleton maps #5886

Description

@viirya

What is the problem the feature request solves?

spark_map_sort currently slices keys and invokes Arrow sorting for every nonempty map, including maps with exactly one entry. A singleton already has its only possible ordering, so this per-row allocation and kernel dispatch adds avoidable normalization cost before nested-key hashing.

Describe the potential solution

For supported flat key types, append a singleton's original entry index directly to the global permutation. Keep Arrow sorting for other rows and for key types whose sorting can report errors. Use a batch-level check and a specialized fallback loop to avoid adding a singleton branch to each row of batches without eligible singletons.

Preserve output values, offsets, null buffers, schema metadata, early returns, and unsupported-key errors, including sliced maps and physical entries under null maps. Hashing behavior and configuration defaults should remain unchanged.

Additional context

Follow-up to the benchmark isolation work in #5822 (which closed #5818). Validate normalization-only, hash-only, and combined execution separately, including singleton, empty, mixed and larger maps, nulls, long strings, and sliced inputs. Independently remeasure flagged regressions.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions