Skip to content

Spark map_from_arrays / map_from_entries return wrong results for sliced lists #25419

Closed

Description

@neilconway

Describe the bug

When the input list array is sliced, map_from_arrays and map_from_entries in datafusion-spark pair the correct values with keys taken from rows outside the slice.

To Reproduce

datafusion-cli --spark:

> CREATE TABLE t AS VALUES ([99, 98], [990, 980]), ([1, 2], [10, 20]);

> SELECT map_from_arrays(column1, column2)
  FROM (SELECT * FROM t ORDER BY column2 DESC LIMIT 1 OFFSET 1) s;
+--------------------------------------+
| map_from_arrays(s.column1,s.column2) |
+--------------------------------------+
| {99: 10, 98: 20}                     |
+--------------------------------------+

> CREATE TABLE e AS VALUES
    ([struct(99, 990), struct(98, 980)], 1),
    ([struct(1, 10), struct(2, 20)], 2);

> SELECT map_from_entries(column1)
  FROM (SELECT * FROM e ORDER BY column2 LIMIT 1 OFFSET 1) s;
+-----------------------------+
| map_from_entries(s.column1) |
+-----------------------------+
| {99: 10, 98: 20}            |
+-----------------------------+

Expected behavior

Both queries should return {1: 10, 2: 20}. Without the OFFSET, both queries return the correct results.

Additional context

No response

Activity

  1. added theissue type on Sep 17, 2026
  2. self-assigned this
    on Sep 17, 2026
  3. Himanshu-2005-code commented on Sep 17, 2026

    @Himanshu-2005-code

    Would love to work on this can you assign me this

  4. neilconway commented on Sep 17, 2026

    @neilconway
    ContributorAuthor

    @Himanshu-2005-code Thanks! I actually already had a fix for this in-progress, but I would love your review of the change if you get a moment: #25431

  5. Himanshu-2005-code commented on Sep 17, 2026

    @Himanshu-2005-code

    Sorry Sir, I hadn't seen you'd already opened a fix when I asked to be assigned. Reviewed #25431: pulled the branch, built it, and ran the datafusion-spark test suite plus the two updated .slt files — all pass, and cargo clippy is clean. The fix looks correct to me — it slices flat_keys down to the current row range before filtering, so the mask lines up with the values it's applied against. I also checked the FixedSizeList/LargeList cases specifically (arrow-rs re-bases FixedSizeListArray::values() on slice already, so the fix's assumptions hold there too), and the new unit tests cover the LAST_WIN and null-row interactions well. Nothing I'd change.

  6. neilconway commented on Sep 17, 2026

    @neilconway
    ContributorAuthor
  7. added a commit that references this issue on Sep 18, 2026
    6e4d9ba
  8. added a commit that references this issue on Sep 19, 2026
    694f6e7
  9. added a commit that references this issue on Oct 11, 2026
    7edd85e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions