-
Notifications
You must be signed in to change notification settings - Fork 72
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
feat: enable support from/to pojo/protobuf for extended expressions #206
feat: enable support from/to pojo/protobuf for extended expressions #206
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks awesome! I took a first pass at the feature, but haven't reviewed the tests yet.
core/src/main/java/io/substrait/extended/expression/ExtendedExpression.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/substrait/extended/expression/ExtendedExpression.java
Outdated
Show resolved
Hide resolved
|
||
@Value.Immutable | ||
public abstract static class ExpressionReference { | ||
public abstract Expression getReferredExpr(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should support AggregateFunction
too according to the protobuf: https://github.com/substrait-io/substrait/blob/8f8d85e63501fc1a085d9585c6566e9c33b81264/proto/substrait/extended_expression.proto#L16C1-L23C2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added AggregateFunction and marked it as an UnsupportedOperationException for now.
core/src/main/java/io/substrait/extended/expression/ExtendedExpression.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/substrait/extended/expression/ExtendedExpressionProtoConverter.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/substrait/extended/expression/ProtoExtendedExpressionConverter.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/substrait/extended/expression/ProtoExtendedExpressionConverter.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/substrait/extension/ImmutableExtensionLookup.java
Outdated
Show resolved
Hide resolved
core/src/test/java/io/substrait/extended/expression/ProtoExtendedExpressionConverterTest.java
Outdated
Show resolved
Hide resolved
f05eedf
to
3d9b927
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks David! I left a few more comments
core/src/main/java/io/substrait/extendedexpression/ExtendedExpressionProtoConverter.java
Outdated
Show resolved
Hide resolved
} else if (expressionType | ||
instanceof io.substrait.extendedexpression.ExtendedExpression.AggregateFunctionType) { | ||
throw new UnsupportedOperationException( | ||
"Aggregate function types are not supported in conversion to proto Extended Expressions for now"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we go ahead and implement in this PR? Would it be a lot of work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this actually may be a fair bit of work to do properly. In the interest of keeping this PR small and moving this work along, I think we could include AggregateFunction support as a future change.
What do you think @danepitkin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 I agree. I didn't realize the level of effort required here. Sorry, @davisusanibar !
core/src/main/java/io/substrait/extendedexpression/ProtoExtendedExpressionConverter.java
Outdated
Show resolved
Hide resolved
core/src/test/java/io/substrait/extendedexpression/ExtendedExpressionProtoConverterTest.java
Outdated
Show resolved
Hide resolved
static final String NAMESPACE = "/functions_arithmetic_decimal.yaml"; | ||
|
||
@Test | ||
public void fromTest() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better to have a single roundtripExtendedExpression
test so that you can test both to/from proto and compare the full objects afterwards (instead of toProtoTest
and fromProtoTest
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just maintain only roundtrip class for Expression, Aggregation and Expression + Aggregation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, @davisusanibar ! Left a few minor comments, but overall LGTM.
core/src/main/java/io/substrait/extendedexpression/ProtoExtendedExpressionConverter.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/substrait/extendedexpression/ProtoExtendedExpressionConverter.java
Outdated
Show resolved
Hide resolved
core/src/test/java/io/substrait/extendedexpression/ExtendedExpressionRoundTripTest.java
Show resolved
Hide resolved
core/src/test/java/io/substrait/extendedexpression/ExtendedExpressionRoundTripTest.java
Show resolved
Hide resolved
Co-authored-by: Dane Pitkin <[email protected]>
core/src/main/java/io/substrait/extendedexpression/ExtendedExpressionProtoConverter.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/substrait/extendedexpression/ExtendedExpressionProtoConverter.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/substrait/extendedexpression/ExtendedExpression.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/substrait/extendedexpression/ProtoExtendedExpressionConverter.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/substrait/extendedexpression/ExtendedExpression.java
Outdated
Show resolved
Hide resolved
Thanks, Victor, for pointing out there is still some work to do to implement AggregateFunctions. It seems like it may be best to push AggregateFunction support to a follow up issue to keep this PR small. |
Hi Dane, just doing my last attempt to try to cover AggregateFunction ... I could suggest that it is needed to have a uniform API that won't change that dramatically later. |
core/src/main/java/io/substrait/extendedexpression/ExtendedExpressionProtoConverter.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/substrait/extendedexpression/ExtendedExpression.java
Show resolved
Hide resolved
I'll let @vbarua comment on if there is more work needed for AggregateFunctions, as I'm not yet that familiar with them. If there is more work required, we should do it in a follow up PR to keep this one small. The Expression support LGTM and I wouldn't want to hold up merging it, especially if the SQL -> ExtendedExpression PR would benefit from it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this. I left some comments about things that we can improve in the future, but overall looks great.
I would like two thing before approving and merging:
- Could you update the
ProtoExtendedExpressionConverter
to not use comparisons togetNumber
and instead compare the protobuf enums. - Could you answer my question about the
@Desugar
annotation.
.collect(java.util.stream.Collectors.toList())) | ||
.setFunctionReference( | ||
functionCollector.getFunctionReference(measure.getFunction().declaration())) | ||
.build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This duplicates code RelProtoConverter#toProto(Aggregate.Measure measure)
.
It's fine for now, but we should consider unifying it in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will create a ticket to address this issue.
.aggregationPhase(Expression.AggregationPhase.fromProto(measure.getPhase())) | ||
.invocation(Expression.AggregationInvocation.fromProto(measure.getInvocation())) | ||
.build()) | ||
.build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This duplicates code in ProtoRelConverter#newAggregate(AggregateRel rel)
.
It's fine for now but we should consider unifying it in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will create a ticket to address this issue.
for (io.substrait.extendedexpression.ExtendedExpression.ExpressionReferenceBase | ||
expressionReference : extendedExpression.getReferredExpressions()) { | ||
if (expressionReference | ||
instanceof io.substrait.extendedexpression.ExtendedExpression.ExpressionReference et) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not a huge fan of these instanceof checks, but we can always improve this later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will create a ticket to address this issue.
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("expressionReferenceProvider") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about @MethodSource
. That's pretty nifty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good. Thanks for working with us on this @davisusanibar!
Thanks, @davisusanibar ! Nice work!! |
To closes #127