Skip to content

feat: SortRel mlir implementation#187

Open
xwkuang5 wants to merge 1 commit intosubstrait-io:mainfrom
xwkuang5:main
Open

feat: SortRel mlir implementation#187
xwkuang5 wants to merge 1 commit intosubstrait-io:mainfrom
xwkuang5:main

Conversation

@xwkuang5
Copy link
Copy Markdown

@xwkuang5 xwkuang5 commented Feb 1, 2026

This commit adds support for the Substrait SortRel relation in the MLIR dialect.

Key Changes:

  • Operations: Added substrait.sort and substrait.sort_field_compare operations to SubstraitOps.td.
  • Enums: Added SortFieldComparisonType to SubstraitEnums.td to represent standard sort directions (e.g., ASC_NULLS_FIRST, DESC_NULLS_LAST).
  • Import Logic: Implemented importSortRel in Import.cpp. This uses a temporary dummy region to instantiate the sort expression once, which is then cloned using IRMapping to populate the comparison block for both the LHS and RHS rows.
  • Export Logic: Implemented exportOperation for SortOp in Export.cpp to generate the corresponding SortRel protobuf message.
  • Verification: Added SortOp::verifyRegions to ensure the sort region is well-formed (blocks take two arguments and yield si8).

Supported Features:

  • All standard sort directions defined in the Substrait specification (ASC_NULLS_FIRST, ASC_NULLS_LAST, DESC_NULLS_FIRST, DESC_NULLS_LAST, CLUSTERED).
  • Sorting by arbitrary expressions supported by the dialect (field references, literals, etc.).

Limitations:

  • Custom Comparison Functions: comparison_function_reference in SortField is not yet supported. The import process will emit an error if this field is set.

Tests:

  • Added test/Target/SubstraitPB/Import/sort.textpb
  • Added test/Target/SubstraitPB/Export/sort.mlir

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 1, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@xwkuang5 xwkuang5 force-pushed the main branch 3 times, most recently from 8c6a963 to 394942d Compare February 1, 2026 23:16
@xwkuang5 xwkuang5 changed the title Implement SortRel. feat: Implement SortRel. Feb 1, 2026
This commit adds support for the Substrait `SortRel` relation in the MLIR dialect (substrait-io#116).

Key Changes:
- **Operations**: Added `substrait.sort` and `substrait.sort_field_compare` operations to `SubstraitOps.td`.
- **Enums**: Added `SortFieldComparisonType` to `SubstraitEnums.td` to represent standard sort directions (e.g., `ASC_NULLS_FIRST`, `DESC_NULLS_LAST`).
- **Import Logic**: Implemented `importSortRel` in `Import.cpp`. This uses a temporary dummy region to instantiate the sort expression once, which is then cloned using `IRMapping` to populate the comparison block for both the LHS and RHS
rows.
- **Export Logic**: Implemented `exportOperation` for `SortOp` in `Export.cpp` to generate the corresponding `SortRel` protobuf message.
- **Verification**: Added `SortOp::verifyRegions` to ensure the sort region is well-formed (blocks take two arguments and yield `si8`).

Supported Features:
- All standard sort directions defined in the Substrait specification (`ASC_NULLS_FIRST`, `ASC_NULLS_LAST`, `DESC_NULLS_FIRST`, `DESC_NULLS_LAST`, `CLUSTERED`).
- Sorting by arbitrary expressions supported by the dialect (field references, literals, etc.).

Limitations:
- **Custom Comparison Functions**: `comparison_function_reference` in `SortField` is not yet supported. The import process will emit an error if this field is set.

Tests:
- Added `test/Target/SubstraitPB/Import/sort.textpb`
- Added `test/Target/SubstraitPB/Export/sort.mlir`
@xwkuang5 xwkuang5 changed the title feat: Implement SortRel. feat: SortRel mlir implementation Feb 1, 2026
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.

2 participants