Skip to content

feat: introduce SchemaCollector #391

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
May 2, 2025
Merged

feat: introduce SchemaCollector #391

merged 4 commits into from
May 2, 2025

Conversation

vbarua
Copy link
Member

@vbarua vbarua commented Apr 19, 2025

SchemaCollector can be used to produce a CalciteSchema from a Substrait Rel

BREAKING CHANGE: LookupCalciteSchema has been removed

SubstraitSchema newSubSchema = new SubstraitSchema();
schema = schema.add(schemaName, newSubSchema);
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

The existing LookupCalciteSchema code didn't handle nested schemas. I've added support for it here.

if (!existingSchema.equals(namedScan.getInitialSchema())) {
throw new IllegalArgumentException(
String.format(
"NamedScan for %s is present multiple times with different schemas", tableName));
Copy link
Member Author

@vbarua vbarua Apr 19, 2025

Choose a reason for hiding this comment

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

It's helpful to guard against this because it can result in some very weird errors. The same table can appear multiple times in a plan (i.e. through joins), and if an external producer applies field trimming and those tables are trimmed to have different fields, unpleasantness can ensue.

@vbarua vbarua marked this pull request as ready for review April 19, 2025 19:23
@vbarua
Copy link
Member Author

vbarua commented Apr 29, 2025

The LookupCalciteSchema requires some further updates when we try and upgrade to Calcite 1.39. Rather than invest more in it, I've chose to simplify the schema processing somewhat and get rid of the LookupCalciteSchema entirely.

This works by introducing 2 classes that extend from Calcite:

  • SubstraitTable extends AbstractTable
  • SubstraitSchema extends AbstractSchema

And then using these to build out a schema from a Substrait relation using the new public SchemaCollector visitor. The new collector also handles nested schemas and performs basic validation on schemas. There are tests to go along with is as well.

This new implementation can be upgraded to Calcite 1.39 without issues.

@vbarua vbarua requested a review from Blizzara April 29, 2025 21:11
@vbarua vbarua requested a review from EpsilonPrime May 1, 2025 23:18
@vbarua vbarua merged commit 5d3abd8 into main May 2, 2025
12 checks passed
@vbarua vbarua deleted the vbarua/schema-collector branch May 2, 2025 02:36
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