Skip to content

fix(native): return null for insufficient variance samples - #1520

Open
hutiefang76 wants to merge 1 commit into
xerial:masterfrom
hutiefang76:frank/fix-sqlite1514-null-sample-20261118
Open

hutiefang76 wants to merge 1 commit into
xerial:masterfrom
hutiefang76:frank/fix-sqlite1514-null-sample-20261118

Conversation

@hutiefang76

@hutiefang76 hutiefang76 commented Nov 18, 2026 •

Copy link
Copy Markdown

Related to #1514; this addresses the insufficient-sample result only. The issue's separate request to filter nonnumeric text remains open.

Both aggregates already calculate sample statistics with denominator n - 1. For fewer than two non-NULL inputs, return SQL NULL instead of reporting a variance or standard deviation of 0. Valid samples retain their existing calculation, including a real zero result for two equal values. Input acceptance and text/BLOB coercion are unchanged.

The 18 parameterized cases test stdev and variance independently: empty/all-NULL input, single integer/REAL values, one value among NULLs, distinct pairs, equal pairs and valid pairs containing NULL.

Validation used a separately built Mac/aarch64 source JNI from the unchanged upstream base, with no dependency on the square() fix. The project's make clean-native and make native rebuilt the library after the C change; custom library name/output directories kept bundled binaries unchanged. Maven's org.sqlite.lib.path and org.sqlite.lib.name selected the built library.

  • Before the fix: 18 cases, 12 NULL-result assertion failures and 6 passing controls; 0 errors/skips.
  • After rebuilding: all 18 pass.
  • JDK 11 full mvn verify: 523 tests, 0 failures/errors, 8 skipped; Spotless passed.
  • JDK 25 MathFunctionsTest and ExtensionTest: 57 tests, 0 failures/errors, 1 skipped. JVM loading diagnostics confirm the rebuilt JNI was loaded.

This changes the undefined-sample result from 0.0 to NULL, so callers must handle NULL. This PR contains source and tests only. The official Build Native run 44288286018 built all 24 native targets successfully. Its final automatic push failed with HTTP 403 because the bot token is read-only; the workflow as a whole is therefore failed.

All 24 artifact ZIP digests were checked against GitHub metadata. The generated libraries were recovered through a normal user push solely on a separate verification branch. A fresh JDK 11 full verify using Maven's default JNI loader and the cross-compiled Mac/aarch64 artifact completed with 523 test records: 515 passed, 0 failures/errors and 8 skipped.

Official CI on verification commit c9d2f1219875 is queued; runtime results for other platforms remain pending. This PR's source commit and bundled binaries are unchanged. Upstream PR CI still needs maintainer approval, and tests using older bundled binaries do not validate the C change.

AI assistance: DeepSeek generated the initial patch/tests and performed a first-pass review. Codex checked the complete diff and executed the native validation.

Return SQL NULL when stdev() or variance() has fewer than two non-NULL
inputs. Retain the sample calculation and existing input coercion.

Refs xerial#1514

Generated-by: DeepSeek deepseek-v4-pro
Generated-by: OpenAI Codex
@hutiefang76

Copy link
Copy Markdown
Author

The upstream JDK 21 job reports the 12 pre-fix failures: stdev and variance return 0.0 for inputs with insufficient samples. It runs mvn test against the merge ref and copies the checked-in native resources. The Linux x86-64 library in this source PR has the same Git blob as its base.

The verification matrix with the JNI libraries rebuilt from this exact source commit has now passed. The rebuilt libraries are on the separate verification branch linked in the description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants