Skip to content

fix(sql): ignore NULL in the aggregates and in COUNT(column) (#580 gap 3) - #586

Merged
MPCoreDeveloper merged 1 commit into
masterfrom
fix/580-null-aggregates
Dec 6, 2026
Merged

MPCoreDeveloper merged 1 commit into
masterfrom
fix/580-null-aggregates

Conversation

@MPCoreDeveloper

Copy link
Copy Markdown
Owner

Gap 3 of #580, red-proven first.nnBefore (both storage modes): SELECT SUM(age) FROM users with a NULL row -> InvalidCastException: Object cannot be cast from DBNull to other types at SqlParser.DML.cs:2811; and COUNT(amount) over (100, NULL) -> 2 (Expected: 1 Actual: 2).nnCause: the engine projects a stored NULL as DBNull.Value, so the aggregate filter v is not null let the sentinel through to Convert.ToDecimal, and the count block never looked at the column at all.nnFix: all eight call sites in SqlParser.ExecuteAggregateQuery (grouped and ungrouped) now skip null and DBNull, and COUNT(column) counts the non-NULL values while COUNT(*) 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, and docs/storage/SINGLE_FILE_SQL_LIMITATIONS.md gap 3 now says fixed 2026-12-06 with the cause instead of a workaround.

…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

codecov Bot commented Dec 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/SharpCoreDB/Services/SqlParser.DML.cs 60.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@sonarqubecloud

sonarqubecloud Bot commented Dec 6, 2026

Copy link
Copy Markdown

@MPCoreDeveloper
MPCoreDeveloper merged commit 1dcaa9f into master Dec 6, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant