Repository navigation
fix(sql): ignore NULL in the aggregates and in COUNT(column) (#580 gap 3) - #586
Merged
Merged
Conversation
…p 3) SELECT SUM/AVG/MIN/MAX over a column containing a NULL threw InvalidCastException (Object cannot be cast from DBNull to other types) on both storage modes, and COUNT(column) counted the NULL row. The engine projects a stored NULL as DBNull.Value, so the aggregate filter (v is not null) let the sentinel through and count never looked at the column. All eight call sites in SqlParser.ExecuteAggregateQuery now skip null and DBNull, and count(column) counts the non-NULL values while COUNT(*) still counts every row. Red first: NullAggregateTests failed with the InvalidCastException (aggregate) and Expected 1 / Actual 2 (count) before the fix, and passes on directory and single-file after. Core suite 3234/0. Docs: CHANGELOG and the Verified-gaps section of SINGLE_FILE_SQL_LIMITATIONS.md now say fixed instead of workaround.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
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.



Gap 3 of #580, red-proven first.
nnBefore (both storage modes):SELECT SUM(age) FROM userswith a NULL row ->InvalidCastException: Object cannot be cast from DBNull to other typesatSqlParser.DML.cs:2811; andCOUNT(amount)over(100, NULL)-> 2 (Expected: 1 Actual: 2).nnCause: the engine projects a stored NULL asDBNull.Value, so the aggregate filterv is not nulllet the sentinel through toConvert.ToDecimal, and thecountblock never looked at the column at all.nnFix: all eight call sites inSqlParser.ExecuteAggregateQuery(grouped and ungrouped) now skipnullandDBNull, andCOUNT(column)counts the non-NULL values whileCOUNT(*)still counts every row.nnProof:NullAggregateTests(4 cases, directory + single-file) failed on the previous code and passes now; full core suite 3234/0 (3230 before + 4 new), no regression in the shared aggregate path.nnDocs: CHANGELOG entry, anddocs/storage/SINGLE_FILE_SQL_LIMITATIONS.mdgap 3 now says fixed 2026-12-06 with the cause instead of a workaround.