Skip to content

fix(isthmus)!: preserve grouping-set indices through Calcite conversion - #1287

Open
alexandrefimov wants to merge 1 commit into
substrait-io:mainfrom
alexandrefimov:issue-1182-1209-grouping-set-index
Open

fix(isthmus)!: preserve grouping-set indices through Calcite conversion#1287
alexandrefimov wants to merge 1 commit into
substrait-io:mainfrom
alexandrefimov:issue-1182-1209-grouping-set-index

Conversation

@alexandrefimov

Copy link
Copy Markdown
Contributor

Substrait defines the grouping-set index as the zero-based position in the declared set list, with type i32 (spec v0.102.0). Calcite's GROUP_ID returns zero for distinct sets, and its normalized set order can change which set an index identifies after a round trip.

Build the index from grouping-key membership and the occurrence of duplicate sets. For declared sets (b), (a), (b), the corresponding rows retain indices 0, 1, and 2. Calcite may keep its normalized set order; a projection preserves the index visible to parent relations. Translate SQL GROUPING/GROUPING_ID through Substrait's implicit index so these values also survive conversion back to Substrait.

Calcite 1.42.0 still has an execution limitation with mixed empty and non-empty grouping sets on empty input: a row for an empty set can be lost. The same failure occurs with a Calcite-only plan.

Closes #1182
Closes #1209

BREAKING CHANGE: The grouping-set index produced by Substrait-to-Calcite conversion now has INTEGER (i32) type instead of BIGINT. Callers that assume a BIGINT output column must use the i32 schema declared by Substrait.

Substrait defines the grouping-set index as the zero-based position in the declared set list, with type i32 ([spec v0.102.0](https://github.com/substrait-io/substrait/blob/v0.102.0/site/docs/relations/logical_relations.md#aggregate-operation)). Calcite's GROUP_ID returns zero for distinct sets, and its normalized set order can change which set an index identifies after a round trip.

Build the index from grouping-key membership and the occurrence of duplicate sets. For declared sets (b), (a), (b), the corresponding rows retain indices 0, 1, and 2. Calcite may keep its normalized set order; a projection preserves the index visible to parent relations. Translate SQL GROUPING/GROUPING_ID through Substrait's implicit index so these values also survive conversion back to Substrait.

Calcite 1.42.0 still has an execution limitation with mixed empty and non-empty grouping sets on empty input: a row for an empty set can be lost. The same failure occurs with a Calcite-only plan.

Closes substrait-io#1182
Closes substrait-io#1209

BREAKING CHANGE: The grouping-set index produced by Substrait-to-Calcite conversion now has INTEGER (i32) type instead of BIGINT. Callers that assume a BIGINT output column must use the i32 schema declared by Substrait.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant