Skip to content

feat(isthmus): convert Calcite RelRoot to Substrait Plan.Root #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 8, 2025

Conversation

vbarua
Copy link
Member

@vbarua vbarua commented Apr 3, 2025

In the SubstraitRelVisitor, RelRoots must be converted to Plan.Roots in order to
ensure that names are handled correctly.

BREAKING CHANGE: converting a Calcite RelRoot no longer produces a Substrait Rel

@vbarua vbarua changed the title fix: name should be retained during roundtripping fix: names should be retained during roundtripping Apr 3, 2025
public static Rel convert(RelRoot root, SimpleExtension.ExtensionCollection extensions) {
return convert(root.rel, extensions, FEATURES_DEFAULT);
public static Plan.Root convert(RelRoot relRoot, SimpleExtension.ExtensionCollection extensions) {
return convert(relRoot, extensions, FEATURES_DEFAULT);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking API change.

A CalciteRelRoot corresponds to POJO Plan.Root, not a POJO Rel.

assertEquals(expectedNames, substraitRelRoot.getNames());

org.apache.calcite.rel.RelRoot calciteRelRoot2 = substraitToCalcite.convert(substraitRelRoot);
assertEquals(expectedNames, calciteRelRoot2.validatedRowType.getFieldNames());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping to be able to use to the new Plan.Root based assertFullRoundTrip to test this, but it doesn't quite work: #371

Rel pojo1 = SubstraitRelVisitor.convert(relRoot, EXTENSION_COLLECTION);
List<RelRoot> relRoots = s.sqlToRelNode(query, creates);
assertEquals(1, relRoots.size());
RelRoot relRoot1 = relRoots.get(0);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice we only ever generate a single RelRoot. Capturing this here and removing the looping to simplify our test code.

@vbarua vbarua changed the title fix: names should be retained during roundtripping feat(isthmus): convert Calcite RelRoot to Substrait Plan.Root Apr 3, 2025
@vbarua vbarua marked this pull request as ready for review April 3, 2025 23:01
@vbarua
Copy link
Member Author

vbarua commented Apr 3, 2025

This is the other direction of #339, which was implemented by @nielspardon

I added a test for this in e230dcc which failed in CI (as expected). The failure was

Expected :[a, B]
Actual   :[A, B]

Effectively, the names were lost when going from Calcite to Substrait and back because we were converting the Calcite RelRoot to a Substrait Rel, which has nowhere to stash the names. Calcite then generates names based on the table definition, and as the colums are capitalized it uses the capitalized names.

@vbarua vbarua force-pushed the vbarua/fix-name-roundtripping branch from fe400a6 to 2479476 Compare April 4, 2025 20:08
@vbarua vbarua changed the base branch from main to vbarua/plan-builder-static-methods April 4, 2025 20:09
Base automatically changed from vbarua/plan-builder-static-methods to main April 7, 2025 15:20
vbarua added 4 commits April 7, 2025 11:20
…isitor

RelRoots must be converted to Plan.Roots in order to ensure that names
are handled correctly.

BREAKING CHANGE: converting a Calcite RelRoot no longer produces a Substrait Rel
@vbarua vbarua force-pushed the vbarua/fix-name-roundtripping branch from 2479476 to 0e7ad03 Compare April 8, 2025 15:42
Copy link
Member

@bvolpato bvolpato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense + looks good to me, thanks!

The fix for the breaking change is quite easy to figure out too

@vbarua vbarua merged commit b7abddd into main Apr 8, 2025
12 checks passed
@vbarua vbarua deleted the vbarua/fix-name-roundtripping branch April 8, 2025 22:52
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.

3 participants