-
Notifications
You must be signed in to change notification settings - Fork 91
fix(isthmus): adding support for new proto and deprecated form in AggregateRel #521
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
vbarua
merged 13 commits into
substrait-io:main
from
gord02:gordon.hamilton/aggregateGroupingNewSubstraitForm
Oct 3, 2025
+190
−8
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3ee086c
fix: adding support for both deprecated and new proto representation…
gord02 e28168f
fix: adding support for both deprecated and new proto of Groupings fo…
gord02 50ee1bc
add tests, fixed bugs in code, and added support for both forms of pr…
gord02 6ffc6ee
fix: add tests, fixed bugs in code, and added support for both forms …
gord02 f854ed1
Merge branch 'gordon.hamilton/aggregateGroupingNewSubstraitForm' of g…
gord02 b793c85
fix: adding support for both deprecated and new proto representation…
gord02 7861549
fix: adding support for both deprecated and new proto of Groupings fo…
gord02 0a13b15
fix: add tests, fixed bugs in code, and added support for both forms …
gord02 cc7ad0b
fix: fixed grouping creation, removed rel to proto support and added …
gord02 b362c9a
fix: resloving conflicts with remote
gord02 7ebb95a
fix: resloving conflicts with remote
gord02 5215971
Merge branch 'gordon.hamilton/aggregateGroupingNewSubstraitForm' of g…
gord02 d3cf639
fix: improving naming conventions and minor pre-converting outside of…
gord02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
core/src/test/java/io/substrait/relation/AggregateRelTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
package io.substrait.relation; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import io.substrait.TestBase; | ||
import io.substrait.extension.ExtensionLookup; | ||
import io.substrait.extension.ImmutableExtensionLookup; | ||
import io.substrait.proto.AggregateRel; | ||
import io.substrait.proto.Expression; | ||
import io.substrait.proto.Plan; | ||
import io.substrait.proto.ReadRel; | ||
import io.substrait.proto.Rel; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class AggregateRelTest extends TestBase { | ||
|
||
protected static final Plan plan = Plan.newBuilder().build(); | ||
protected static final ExtensionLookup functionLookup = | ||
ImmutableExtensionLookup.builder().from(plan).build(); | ||
protected static final io.substrait.proto.NamedStruct namedStruct = createSchema(); | ||
|
||
public static io.substrait.proto.NamedStruct createSchema() { | ||
|
||
io.substrait.proto.Type i32Type = | ||
io.substrait.proto.Type.newBuilder() | ||
.setI32(io.substrait.proto.Type.I32.getDefaultInstance()) | ||
.build(); | ||
|
||
// Build a NamedStruct schema with two fields: col1, col2 | ||
io.substrait.proto.Type.Struct structType = | ||
io.substrait.proto.Type.Struct.newBuilder().addTypes(i32Type).addTypes(i32Type).build(); | ||
|
||
return io.substrait.proto.NamedStruct.newBuilder() | ||
.setStruct(structType) | ||
.addNames("col1") | ||
.addNames("col2") | ||
.build(); | ||
} | ||
|
||
public static io.substrait.proto.Expression createFieldReference(int col) { | ||
// Build a ReferenceSegment that refers to struct field col | ||
Expression.ReferenceSegment seg1 = | ||
Expression.ReferenceSegment.newBuilder() | ||
.setStructField( | ||
Expression.ReferenceSegment.StructField.newBuilder().setField(col).build()) | ||
.build(); | ||
|
||
// Build a FieldReference that uses the directReference and a rootReference | ||
Expression.FieldReference fieldRef1 = | ||
Expression.FieldReference.newBuilder() | ||
.setDirectReference(seg1) | ||
.setRootReference(Expression.FieldReference.RootReference.getDefaultInstance()) | ||
.build(); | ||
|
||
// Wrap the FieldReference in an Expression.selection | ||
return Expression.newBuilder().setSelection(fieldRef1).build(); | ||
} | ||
|
||
@Test | ||
public void testDeprecatedGroupingExpressionConversion() { | ||
Expression col1Ref = createFieldReference(0); | ||
Expression col2Ref = createFieldReference(1); | ||
|
||
AggregateRel.Grouping grouping = | ||
AggregateRel.Grouping.newBuilder() | ||
.addGroupingExpressions(col1Ref) // deprecated proto form | ||
.addGroupingExpressions(col2Ref) | ||
.build(); | ||
|
||
// Build an input ReadRel | ||
ReadRel readProto = ReadRel.newBuilder().setBaseSchema(namedStruct).build(); | ||
|
||
// Build the AggregateRel with the new grouping_expressions field | ||
AggregateRel aggrProto = | ||
AggregateRel.newBuilder() | ||
.setInput(Rel.newBuilder().setRead(readProto)) | ||
.addGroupings(grouping) | ||
.build(); | ||
|
||
Rel relProto = Rel.newBuilder().setAggregate(aggrProto).build(); | ||
ProtoRelConverter converter = new ProtoRelConverter(functionLookup); | ||
io.substrait.relation.Rel resultRel = converter.from(relProto); | ||
|
||
assertTrue(resultRel instanceof Aggregate); | ||
Aggregate agg = (Aggregate) resultRel; | ||
assertEquals(1, agg.getGroupings().size()); | ||
assertEquals(2, agg.getGroupings().get(0).getExpressions().size()); | ||
} | ||
|
||
@Test | ||
public void testAggregateWithSingleGrouping() { | ||
Expression col1Ref = createFieldReference(0); | ||
Expression col2Ref = createFieldReference(1); | ||
|
||
AggregateRel.Grouping grouping = | ||
AggregateRel.Grouping.newBuilder() | ||
.addExpressionReferences(0) | ||
.addExpressionReferences(1) | ||
.build(); | ||
|
||
// Build an input ReadRel | ||
ReadRel readProto = ReadRel.newBuilder().setBaseSchema(namedStruct).build(); | ||
|
||
// Build the AggregateRel with the new grouping_expressions field | ||
AggregateRel aggrProto = | ||
AggregateRel.newBuilder() | ||
.setInput(Rel.newBuilder().setRead(readProto)) | ||
.addGroupingExpressions(col1Ref) | ||
.addGroupingExpressions(col2Ref) | ||
.addGroupings(grouping) | ||
.build(); | ||
|
||
Rel relProto = Rel.newBuilder().setAggregate(aggrProto).build(); | ||
ProtoRelConverter converter = new ProtoRelConverter(functionLookup); | ||
io.substrait.relation.Rel resultRel = converter.from(relProto); | ||
|
||
assertTrue(resultRel instanceof Aggregate); | ||
Aggregate agg = (Aggregate) resultRel; | ||
assertEquals(1, agg.getGroupings().size()); | ||
assertEquals(2, agg.getGroupings().get(0).getExpressions().size()); | ||
} | ||
|
||
@Test | ||
public void testAggregateWithMultipleGroupings() { | ||
Expression col1Ref = createFieldReference(0); | ||
Expression col2Ref = createFieldReference(1); | ||
|
||
AggregateRel.Grouping grouping1 = | ||
AggregateRel.Grouping.newBuilder() | ||
.addExpressionReferences(0) // new proto form | ||
.addExpressionReferences(1) | ||
.build(); | ||
|
||
AggregateRel.Grouping grouping2 = | ||
AggregateRel.Grouping.newBuilder().addExpressionReferences(1).build(); | ||
|
||
// Build an input ReadRel | ||
ReadRel readProto = ReadRel.newBuilder().setBaseSchema(namedStruct).build(); | ||
|
||
// Build the AggregateRel with the new grouping_expressions field | ||
AggregateRel aggrProto = | ||
AggregateRel.newBuilder() | ||
.setInput(Rel.newBuilder().setRead(readProto)) | ||
.addGroupingExpressions(col1Ref) | ||
.addGroupingExpressions(col2Ref) | ||
.addGroupings(grouping1) | ||
.addGroupings(grouping2) | ||
.build(); | ||
|
||
Rel relProto = Rel.newBuilder().setAggregate(aggrProto).build(); | ||
ProtoRelConverter converter = new ProtoRelConverter(functionLookup); | ||
io.substrait.relation.Rel resultRel = converter.from(relProto); | ||
|
||
assertTrue(resultRel instanceof Aggregate); | ||
Aggregate agg = (Aggregate) resultRel; | ||
assertEquals(2, agg.getGroupings().size()); | ||
assertEquals(2, agg.getGroupings().get(0).getExpressions().size()); | ||
assertEquals(1, agg.getGroupings().get(1).getExpressions().size()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.