[presto] Move out M2Y from RegressionState for regr_slope and regr_intercept functions #25475
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.
Description
Currently we don't enforce intermediate/return type are the same in Coordinator and Prestissimo Worker.
Velox creates vectors for intermediate/return results based on a plan that comes from Coordinator. Then Prestissimo tries to use those vector and not crash.
In practise we had a crash some time ago due to such a mismatch (D74199165).
And I added validation to Velox to catch such kind of mismatches early: facebookincubator/velox#13322
But we wasn't able to enable it in prod, because the validation failed for "regr_slope" and "regr_intercept" functions.
What's changed?
In this diff I'm fixing "regr_slope" and "regr_intercept" intermediate types. Basically in Java
AggregationState
for all these functions is the same:But in Prestissimo the state storage is more optimal:
These 2 aggregation functions don't have M2Y field. And this is more efficient, because we don't waste memory and CPU on the field, that aren't needed.
So I moved M2Y to extended class, the same as it works in Velox: https://github.com/facebookincubator/velox/blob/main/velox/functions/prestosql/aggregates/CovarianceAggregates.cpp?fbclid=IwY2xjawLRTetleHRuA2FlbQIxMQBicmlkETFiT0N3UFR0M2VKOHl6MHRhAR6KRQ1VUQdCkZXzwj14sMQrVZ-R9QBH1utuGJb5U_lyGzDwt8PwV317QRVNJg_aem_-ePxZ-fHO5MNgfUmayVJFA#L326-L337
No major changes, mostly just reorganized the code.
Next steps
In this diff I'm trying to apply the same optimization to Java. With this fix, the signatures will become the same in Java and Prestissimo and we will be able to enable the validation
Differential Revision: D77625566
Release Notes
Please follow release notes guidelines and fill in the release notes below.