Skip to content

feat(isthmus): support converting Substrait Plan.Root to Calcite RelRoot#339

Merged
vbarua merged 1 commit into
substrait-io:mainfrom
nielspardon:par-convert-root
Mar 14, 2025
Merged

feat(isthmus): support converting Substrait Plan.Root to Calcite RelRoot#339
vbarua merged 1 commit into
substrait-io:mainfrom
nielspardon:par-convert-root

Conversation

@nielspardon
Copy link
Copy Markdown
Member

Isthmus currently only supports converting a Substrait Rel into a Calcite RelNode losing the final column names which are encoded in the Substrait Plan.Root and which should be converted into a Calcite RelRoot.

This PR adds a convert() method for converting a Substrait Plan.Root into a Calcite RelRoot preserving the final column names.

Currently, substrait-java does not support DML/DDL relations likeWriteRel so the conversion may have to be revisited once support for DML/DDL relations is being added.

Comment thread isthmus/src/main/java/io/substrait/isthmus/SubstraitToCalcite.java Outdated
Comment thread isthmus/src/main/java/io/substrait/isthmus/SubstraitToCalcite.java Outdated
@nielspardon nielspardon force-pushed the par-convert-root branch 2 times, most recently from 6524fc8 to 1a2c794 Compare March 13, 2025 12:15
@nielspardon nielspardon requested a review from Blizzara March 13, 2025 12:16

public class SubstraitToCalciteTest extends PlanTestBase {
@Test
void testConvertRoot() throws Exception {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

might be nice to split this into separate test functions 😄

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

sure. I can split it up

Copy link
Copy Markdown
Contributor

@Blizzara Blizzara left a comment

Choose a reason for hiding this comment

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

Thanks - this makes sense to me! However I'm not using Calcite myself, @vbarua I think you might, do you wanna check this through as well?

Just to state the status if I understand it correctly: this correctly reads the proper DFS names lists, but only renames the top-level fields in Calcite. I think that's still an improvement, so fine to merge as it is and improve on it, but let me know if you think otherwise.

@nielspardon
Copy link
Copy Markdown
Member Author

Just to state the status if I understand it correctly: this correctly reads the proper DFS names lists, but only renames the top-level fields in Calcite. I think that's still an improvement, so fine to merge as it is and improve on it, but let me know if you think otherwise.

Correct, it stores all the field names from the Substrait Plan.Root in the Calcite RelRoot. The only caveat is that Calcite currently only applies the names from the top-level. With a Calcite fix it could use the information provided in the provided row type to also apply the aliases for nested fields. And yes, it is still an improvement since currently substrait-java didn't even provide the top-level names to Calcite.

@vbarua vbarua self-requested a review March 13, 2025 22:44
Copy link
Copy Markdown
Member

@vbarua vbarua left a comment

Choose a reason for hiding this comment

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

Overall this looks reasonable to me. Left a number of minor comments. Feel free to address any that make sense to you @nielspardon. I can take another look tomorrow and merge this in.

Comment thread isthmus/src/test/java/io/substrait/isthmus/SubstraitToCalciteTest.java Outdated
Comment thread isthmus/src/test/java/io/substrait/isthmus/SubstraitToCalciteTest.java Outdated
Comment thread isthmus/src/test/java/io/substrait/isthmus/SubstraitToCalciteTest.java Outdated
Comment thread isthmus/src/test/java/io/substrait/isthmus/SubstraitToCalciteTest.java Outdated
ImmutableRoot.builder()
.input(
substraitBuilder.namedScan(
Collections.singleton("stores"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor/opinionated: I would use List.of("stores") here. For table names, order matters, think tpcds.store vs store.tpcds. Collections.singleton returns a Set.

Now, none of this actually matters if there's only a single name, like in this case, but we use List.of(<single_name>) in a bunch of other places and it would be nice to be consistent.

This applies to you other usages of Collections.singleton as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Makes sense to me. Do you think the use of the Iterable type in SubstraitBuilder should be reconsidered to reflect that the order matters for some of these types?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I changed the Collections.singleton() to either List.of() or Set.of().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you think the use of the Iterable type in SubstraitBuilder should be reconsidered to reflect that the order matters for some of these types?

That's actually a really good idea. Very much beyond the scope of this PR.

Comment thread isthmus/src/test/java/io/substrait/isthmus/SubstraitToCalciteTest.java Outdated
Comment thread isthmus/src/main/java/io/substrait/isthmus/SubstraitToCalcite.java Outdated
Comment thread isthmus/src/main/java/io/substrait/isthmus/SubstraitToCalcite.java Outdated
@nielspardon nielspardon force-pushed the par-convert-root branch 2 times, most recently from b55efba to 67b5f9e Compare March 14, 2025 12:23
Signed-off-by: Niels Pardon <par@zurich.ibm.com>
@vbarua vbarua merged commit 42b87ae into substrait-io:main Mar 14, 2025
@vbarua
Copy link
Copy Markdown
Member

vbarua commented Mar 14, 2025

Thanks for working on this @nielspardon!

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