fix(isthmus): improve derivation of AggregateRel return type#508
Conversation
1a9fd66 to
c7ece87
Compare
c7ece87 to
c48a180
Compare
vbarua
left a comment
There was a problem hiding this comment.
Just saw your new update from this morning. So this issue is associated with the presence of multiple grouping set? It would be helpful to have a direct/minimal reproducer for this to be able to understand what exactly the issue is. The TPCDS test hits the issue, but it doesn't really help identify it.
We should also update the title indicate the issue that's being fixed. Fixing TCPDs 67 is a side-effect of fixing an actual underlying issue.
c48a180 to
62f552d
Compare
|
I've updated the PR title and commit message from "fix tpcds query 67" to be more descriptive. I've added the new test case to the Substrait2SqlTest class. I wasn't entirely sure this was the right spot, as the class name is a bit confusing (it seems to cover a full sql<->substrait roundtrip). However, since it already contains tests for various SQL clauses, I thought adding the rollup test here would be consistent. Please let me know if you think there's a better place for this test. |
|
Thanks for the reproducer for this. I'm digging into this a bit because there's a general pattern of bugs we've also noticed due to disagreement between Calcite and Substrait as to nullabilities. |
|
Haven't found time to dig into this, but I figured I would update on why I haven't merged. Effectively, tweaking the return type like you have isn't really in keeping with the spec for AggregateRel, which as defined now should output all inputs types as given without tweaking nullabilities. This isn't probably quite correct, and the issue arises when Calcite and Substrait have different expectations around the nullabilities of the columns. Calcite is probably correct in this case, but I think it's worth understanding exactly why it's wrong to update the core spec and make our AggregateRel more correct. Variants of this have arisen before #336, and there is actually an issue to look into this further #379. |
I couldn't find that statement in the spec. However, the logic applied in the PR was a bit different than in the spec, that says Instead, all grouping columns were made nullable in case of more than one grouping sets. I have fixed the logic according to the spec. This change doesn't affect the ROLLUP function (the target of this PR) because ROLLUP generates grouping sets in a way that no single grouping column appears in all of them. |
Replace the deprecated com.palantir.graal plugin, which was last released in June 2022 and is no longer maintained. Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
Alternate forms for TPC-DS queries 27, 36, 70 and 86. These forms rewrite queries that use the GROUPING aggregate function, which does not have a direct Substrait equivalent. These test cases now pass. Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
There is an info level log in FunctionConverter for every every Calcite operator for which there is no direct Substrait mapping. This message makes the logs extremely busy and provides no value to end users. This change reclassifies the message as debug log. Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
substrait-io#517) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Benefits from Java 25 performance optimizations. Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
5c6f19b to
00e7786
Compare
|
Oh, you're right we do actually have something in the spec for grouping sets:
and
|
|
I tried adding an extra integer, while it works with minimal reproducer, it somehow breaks the calcite validation when |
@vbarua are you ok with merging this fix for the nullability and tackle the missing grouping set index in a separate PR? I created this issue for adding the grouping set index: #527 |
Co-authored-by: Niels Pardon <mail@niels-pardon.de>
| final LinkedHashSet<Expression> uniqueGroupingExpressions = | ||
| getGroupings().stream() | ||
| .flatMap(g -> g.getExpressions().stream()) | ||
| .collect(Collectors.toCollection(LinkedHashSet::new)); |
There was a problem hiding this comment.
I'm not entirely sure this will work as expected because I'm not sure if expression equality / hash coding is well defined. That being said, we're already working on switching to the new grouping field mechanism that will make this obsolete in #521
vbarua
left a comment
There was a problem hiding this comment.
Apologies for the delay. I agree that this is reasonable to merge in as its strictly improving the existing deficiency, even if it's not fully solving it. The followup issue tracks the remaining work #527
I'll merge this myself later today, I want to make include a succint description in the body for the release notes. Strictly speaking, while this fixes rollup queries, that's more a side-effect of correcting the type-derivation.
|
Ah, a test appears to have broken following the merge of #518 😢 I don't have time to follow up and dig into it, but if either of @ZorinAnton or @nielspardon can address it, I can prioritize merging this PR in this week. |
Thank you, it would be great. After merging the failure has gone. |
|
Thanks for your work on this @ZorinAnton |
Minimal reproducing query:
If this query gets converted to
subtrait protoand then tosubstrait pojo, the latter looks as follows:The ROLLUP function makes grouping columns nullable. This was causing a Calcite validation error because the outer projection's CHARCOL column was incorrectly defined as non-nullable. This fix corrects the column type, allowing the conversion to succeed.