fix(isthmus): std_dev, variance function mappings#780
Open
nielspardon wants to merge 1 commit intosubstrait-io:mainfrom
Open
fix(isthmus): std_dev, variance function mappings#780nielspardon wants to merge 1 commit intosubstrait-io:mainfrom
nielspardon wants to merge 1 commit intosubstrait-io:mainfrom
Conversation
Signed-off-by: Niels Pardon <par@zurich.ibm.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Disclaimers upfront: I have been assisted by AI generating parts of the code, documentation and PR description.
This PR still uses the to be deprecated function signatures using options. I will migrate the code to enum arguments in a follow-up.
Since this PR also casts the input arguments to
FP64if necessary, we do not need the integer based function signatures proposed in substrait-io/substrait#1012This PR fixes the bidirectional conversion between Calcite and Substrait for statistical aggregate functions (standard deviation and variance). Previously, these functions were not properly mapped, preventing SQL queries using
STDDEV_POP,STDDEV_SAMP,VAR_POP, andVAR_SAMPfrom being correctly converted to Substrait and back.Problem
Substrait uses a single function name for both population and sample variants of statistical functions:
std_devfor bothSTDDEV_POPandSTDDEV_SAMPvariancefor bothVAR_POPandVAR_SAMPThe distinction between population (n denominator) and sample (n-1 denominator) variants is made via a
distributionfunction option (POPULATIONorSAMPLE), but this mechanism was not implemented in the Isthmus converter. The tests did pass prior to this change since the existing TPC-DS testcases using these functions were incorrectly mapped to theAVGfunction since Calcite maps these statistical functions toSqlAvgAggFunction.Solution
Calcite → Substrait Direction:
FunctionMappingsfor all four statistical operatorsAggregateFunctionConverter.generateBinding()to automatically inject thedistributionoption based on the CalciteSqlKind:STDDEV_SAMP,VAR_SAMP→distribution=SAMPLESTDDEV_POP,VAR_POP→distribution=POPULATIONSubstrait → Calcite Direction:
FunctionConverter.getSqlOperatorFromSubstraitFunc()to accept function options as a parameterfilterByFunctionOptions()to disambiguate operators using thedistributionoptionSubstraitRelVisitorto pass function options during conversionDSL Support:
SubstraitBuilder:stddevPopulation(),stddevSample(),variancePopulation(),varianceSample()distributionoption