-
Notifications
You must be signed in to change notification settings - Fork 74
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
fix(isthmus): allow for conversion of plans containing Calcite aggregate functions #230
fix(isthmus): allow for conversion of plans containing Calcite aggregate functions #230
Conversation
bc32c60
to
f7a2a65
Compare
FYI Check failures are unrelated to the change:
|
f7a2a65
to
2139cff
Compare
5501161
to
b9855de
Compare
b9855de
to
0e29574
Compare
8201204
to
6c0c6fd
Compare
return Optional.of( | ||
fun.getKind() == SqlKind.MIN ? AggregateFunctions.MIN : AggregateFunctions.MAX); | ||
} else if (aggFunction instanceof SqlAvgAggFunction) { | ||
return Optional.of(AggregateFunctions.AVG); | ||
} else if (aggFunction instanceof SqlSumAggFunction) { | ||
return Optional.of(AggregateFunctions.SUM); | ||
} else if (aggFunction instanceof SqlSumEmptyIsZeroAggFunction) { | ||
return Optional.of(AggregateFunctions.SUM0); | ||
} else { | ||
return Optional.empty(); | ||
} |
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.
Re-ordered the checks to match the function definitions above.
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 these changes!
I was poking around to add the conversionHandlesBuiltInSum0CallAddedByRule
test and made some small changes along the way as well.
If the code in 6c0c6fd looks good to you, we can merge this in.
AggregateFunctions.getSubstraitAggVariant(aggFunction).orElse(aggFunction); | ||
// Replace default Calcite aggregate calls with Substrait specific variants. | ||
// See toSubstraitAggVariant for more details. | ||
AggregateFunctions.toSubstraitAggVariant(aggFunction).orElse(aggFunction); |
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.
Added more detailed docs to the function definition
public class OptimizerIntegrationTest extends PlanTestBase { | ||
|
||
@Test | ||
void conversionHandlesBuiltInSum0CallAddedByRule() throws SqlParseException, 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.
This test captures how the default Calcite aggregate calls can be introduced by rules and verifies the conversion executes without failing even when this occur (thanks to your changes ✨ )
} | ||
|
||
final SubstraitBuilder b = new SubstraitBuilder(EXTENSION_COLLECTION); | ||
public class AggregateFunctionConverterTest extends PlanTestBase { |
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.
Re-using code from PlanTestBase
.
@@ -55,5 +30,6 @@ public void testFunctionFinderMatch() { | |||
null)); | |||
assertNotNull(functionFinder); | |||
assertEquals("sum0", functionFinder.getName()); | |||
assertEquals(AggregateFunctions.SUM0, functionFinder.getOperator()); |
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.
Comparing the name is insufficient as both SqlSumEmptyIsZeroAggFunction
and SubstraitSumEmptyIsZeroAggFunction
have the same name.
6c0c6fd
to
09b6b2f
Compare
It looks good to me! Thanks for all the improvements / suggestions! |
…Functions (substrait-io#230) Calcite planning rules can introduce the Calcite variants of SqlAggFunctions In substrait-io#180, Substrait specific variants for these function were introduced which better matched the type inference for these functions as defined in Substrait Those changes cause failures when converting the Calcite variants to Substrait, which is what these changes address --------- Co-authored-by: Victor Barua <victor.barua@datadoghq.com>
Some of the Calcite CoreRules might bring their own functions at a late stage, so I've decided to make the converter flexible enough and handle the superclass types correctly (since we already do a similar conversion to
APPROX_COUNT_DISTINCT
in the same spot).Another alternative would be to improve the matchers and check if names match or if it's an
instanceof
the passing call -- todaysignatures
is anIdentityHashMap
, so it's really strict.