Repository navigation
Skip NULL values in SQL aggregates - #893
Open
AarushShetty346 wants to merge 1 commit into
Open
AarushShetty346 wants to merge 1 commit into
AarushShetty346 wants to merge 1 commit into
Conversation
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.
Fixes #891
What changes were proposed in this pull request?
SQL aggregates now ignore NULL values, as in standard SQL:
AggregateAddCols:COUNT(col)adds 0 for a row where its argument is null.COUNT(*)has no arguments, so it still adds 1. ForAVG, the column now holds{value, 1}, or{null, 0}when the value is null, so the number of non-null values is tracked separately from the row count.AggregateFunction:castAndMapreturns the other side when one side is null.SUM,MINandMAXtherefore skip nulls, and if all values are null the result stays null.AVGmerges the sum and the count separately. This also removes thecountDonehandling, which updated the shared row count from inside the AVG case.AggregateGetResult:AVGdivides the sum by the number of non-null values. If there are none, it returns null.How was this patch tested?
I added three tests to
SqlToWayangRelTest, using a newexampleNullGroups.csv(six rows in groupsa,b,c; groupchas only a NULL):javaAggregatesSkipNullsrunsCOUNT(*),COUNT(col1),SUM,AVG,MINandMAXwithoutGROUP BY. Each aggregate runs as its own query because of a separate problem with several aggregates and noGROUP BY, which I can open an issue for.javaGroupedAggregatesSkipNullsandsparkGroupedAggregatesSkipNullsrunCOUNT(col1),SUMandAVGper group. The expected rows are(a, 1, 1, 1.0),(b, 2, 8, 4.0)and(c, 0, null, null).On main,
COUNT(col1)returns 6 instead of 3, the grouped Java query throws an NPE inJavaReduceBy, and the Spark test fails as well. With this change, allwayang-api-sqltests pass (34 in total, Spark included).