Skip to content
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

Merged
merged 14 commits into from
Dec 14, 2023

Conversation

davisusanibar
Copy link
Contributor

To closes #127

Copy link
Contributor

@danepitkin danepitkin left a 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.


@Value.Immutable
public abstract static class ExpressionReference {
public abstract Expression getReferredExpr();
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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.

Copy link
Contributor

@danepitkin danepitkin left a 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/type/NamedStruct.java Outdated Show resolved Hide resolved
Comment on lines 38 to 41
} 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");
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just added.

Copy link
Member

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

Copy link
Contributor

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 !

static final String NAMESPACE = "/functions_arithmetic_decimal.yaml";

@Test
public void fromTest() throws IOException {
Copy link
Contributor

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).

Copy link
Contributor Author

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

Copy link
Contributor

@danepitkin danepitkin left a 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.

Co-authored-by: Dane Pitkin <[email protected]>
@danepitkin
Copy link
Contributor

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.

@davisusanibar
Copy link
Contributor Author

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.

@danepitkin
Copy link
Contributor

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!

Copy link
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.

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:

  1. Could you update the ProtoExtendedExpressionConverter to not use comparisons to getNumber and instead compare the protobuf enums.
  2. Could you answer my question about the @Desugar annotation.

.collect(java.util.stream.Collectors.toList()))
.setFunctionReference(
functionCollector.getFunctionReference(measure.getFunction().declaration()))
.build();
Copy link
Member

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.

Copy link
Contributor Author

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();
Copy link
Member

@vbarua vbarua Dec 13, 2023

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.

Copy link
Contributor Author

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) {
Copy link
Member

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.

Copy link
Contributor Author

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")
Copy link
Member

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.

Copy link
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.

Changes look good. Thanks for working with us on this @davisusanibar!

@vbarua vbarua merged commit 9e023a7 into substrait-io:main Dec 14, 2023
8 checks passed
@danepitkin
Copy link
Contributor

Thanks, @davisusanibar ! Nice work!!

ajegou pushed a commit to ajegou/substrait-java that referenced this pull request Mar 29, 2024
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.

Implement ExtendedExpression
3 participants