Skip to content

[SPARK-56561][PYTHON][DOCS] Document order preservation for array_distinct, array_intersect, array_union, array_except#56250

Open
brijrajk wants to merge 1 commit into
apache:masterfrom
brijrajk:SPARK-56561-array-set-order-docs
Open

[SPARK-56561][PYTHON][DOCS] Document order preservation for array_distinct, array_intersect, array_union, array_except#56250
brijrajk wants to merge 1 commit into
apache:masterfrom
brijrajk:SPARK-56561-array-set-order-docs

Conversation

@brijrajk
Copy link
Copy Markdown
Contributor

@brijrajk brijrajk commented Jun 1, 2026

What changes were proposed in this pull request?

Added explicit order-preservation notes to the docstrings of four array set
functions in PySpark: array_distinct, array_intersect, array_union, and
array_except. Previously the docstrings were silent on whether input order is
preserved, leaving users to guess or test empirically.

The additions are:

  • array_distinct: preserving the order of first occurrence
  • array_intersect: preserving the order of elements from col1
  • array_union: preserving the order from col1 followed by elements in col2 not in col1
  • array_except: preserving the order of elements from col1

Why are the changes needed?

Order-preservation is a useful guarantee for users composing these functions in
pipelines — e.g. knowing that array_distinct keeps the first occurrence means
there is no need to sort afterwards to get a stable result. This is useful to
cite in code reviews and helps inform AI coding assistants as noted in
SPARK-56561.

Fixes https://issues.apache.org/jira/browse/SPARK-56561

Does this PR introduce any user-facing change?

No. Documentation (docstring) only — no logic changes.

How was this patch tested?

No logic change. Confirmed order-preservation behavior by reading the
ArraySetLike trait and ArrayDistinct, ArrayIntersect, ArrayUnion, and
ArrayExcept implementations in collectionOperations.scala.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude (Anthropic)

…tinct, array_intersect, array_union, array_except

The docstrings for these four array set functions did not mention whether
they preserve the order of input elements. Added explicit order-preservation
notes to each:

- array_distinct: preserves order of first occurrence
- array_intersect: preserves order of elements from col1
- array_union: preserves order from col1, then elements from col2 not in col1
- array_except: preserves order of elements from col1

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant