Repository navigation
Handle NULL values in SQL filters, projections and joins - #904
Open
AarushShetty346 wants to merge 2 commits into
Open
AarushShetty346 wants to merge 2 commits into
AarushShetty346 wants to merge 2 commits into
Conversation
Follow-up to apache#893, as asked in its review. The SQL API now follows SQL NULL semantics outside aggregates as well: - Filters: comparisons, LIKE, NOT, PLUS/MINUS and CAST give NULL (unknown) for a NULL operand, AND/OR use three-valued logic, SEARCH uses the Sarg's NULL result (e.g. NULL AS TRUE), and a WHERE keeps a row only if its condition is TRUE. - Projections: arithmetic with a NULL operand gives NULL. - Joins: rows with a NULL key are dropped before the join when a key column is nullable, so NULL never matches NULL. - Scans already read empty CSV fields of typed columns as NULL; a new test covers that.
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.
Follow-up to #893, as Juri Petersen asked there: NULL handling for the other SQL operations. Related: #890, #891. Based on #893, so it includes that commit until #893 is merged.
What changes were proposed in this pull request?
FilterPredicateImpl): comparisons,LIKE,NOT,+/-andCASTgive NULL (unknown) for a NULL operand instead of an NPE.AND/ORuse three-valued logic.SEARCHuses the Sarg's NULL result (e.g.NULL AS TRUEforx IN (1, 3) OR x IS NULL), kept in a smallSargValuerecord. A row passes only if the condition is TRUE.ProjectMapFuncImpl):+ - * /with a NULL operand give NULL.JoinKeyNotNullFilterdrops records with a NULL key before the join (only when a key column is nullable), so NULL never matches NULL."", as in Calcite's file adapter.On
exampleNull.csv(col1= 1, NULL, 3, NULL):WHERE col1 > 1WHERE col1 <> 1WHERE col1 > 1 OR col2 > 15SELECT col1 + col2a JOIN b ON a.col1 = b.col1How was this patch tested?
10 new tests in
SqlToWayangRelTestwith a newexampleNull.csv: scans, filters, projections and joins (one and two keys) on Java, filters, projections and joins on Spark, plus a unit test ofFilterPredicateImplfor NULL strings inLIKEandNOTover unknown. 9 of them fail without this change (the scan test passes either way). All 44wayang-api-sqltests pass, andmvn verifyon the module (RAT included) succeeds.Not in this PR
SEARCHonly checks the span of the Sarg, soIN (1, 5)also matches 3 onceFILTER_INTO_JOINmakes it a Sarg, andNOT INthen fails with "range unbounded". That isn't about NULLs, so I can open a separate issue.