Skip to content

Native Iceberg scan returns incorrect results for storage-partitioned joins #2390

Description

@lyne7-sc

Describe the bug

Native Iceberg scans do not preserve Spark's key-grouped input partitions. This can cause incorrect results in storage-partitioned joins.

To Reproduce

Create two Iceberg tables partitioned by the join key:

CREATE TABLE local.db.t_left (id INT, p INT)
USING iceberg
PARTITIONED BY (p);

INSERT INTO local.db.t_left VALUES (0, 0), (1, 1);

CREATE TABLE local.db.t_right (value INT, p INT)
USING iceberg
PARTITIONED BY (p);

INSERT INTO local.db.t_right VALUES (10, 0), (11, 0), (12, 1);

Enable storage-partitioned joins:

spark.sql.sources.v2.bucketing.enabled=true
spark.sql.iceberg.planning.preserve-data-grouping=true

Run a sort-merge join:

SELECT /*+ MERGE(l, r) */ l.id, l.p, r.value
FROM local.db.t_left l
JOIN local.db.t_right r ON l.p = r.p;

Expected behavior

The query returns:

(0, 0, 10)
(0, 0, 11)
(1, 1, 12)

Actual result

The query returns only one row:

(0, 0, 11)

The expected rows (0, 0, 10) and (1, 1, 12) are missing.

Screenshots

Additional context

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

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions