-
Notifications
You must be signed in to change notification settings - Fork 31.3k
sqlite: add aggregate function #56600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sqlite: add aggregate function #56600
Conversation
Also, tests and docs are needed. |
@geeksilva97 are you still planning to work on this? |
Hi @cjihrig . Yes, I plan to continue this. The last few weeks have been tough though. If nobody beats me I plan to get this done by April. |
beaf983
to
70dff34
Compare
70dff34
to
f4e4869
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #56600 +/- ##
==========================================
- Coverage 90.24% 90.22% -0.02%
==========================================
Files 630 630
Lines 184990 185424 +434
Branches 36216 36347 +131
==========================================
+ Hits 166948 167307 +359
- Misses 11003 11016 +13
- Partials 7039 7101 +62
🚀 New features to boost your workflow:
|
I got an implementation that works. I need to add tests and clean up the code. |
cd3f0aa
to
22da3ad
Compare
22da3ad
to
9badd9b
Compare
It needs re-approval because I accepted Jasmes' suggestions. |
Commit Queue failed- Loading data for nodejs/node/pull/56600 ✔ Done loading data for nodejs/node/pull/56600 ----------------------------------- PR info ------------------------------------ Title sqlite: add aggregate function (#56600) Author Edy Silva <[email protected]> (@geeksilva97) Branch geeksilva97:sqlite-aggregate-function -> nodejs:main Labels c++, author ready, needs-ci, commit-queue-squash, sqlite Commits 3 - sqlite,doc,test: add aggregate function - apply review suggestions - apply review suggestion Committers 2 - Edy Silva <[email protected]> - GitHub <[email protected]> PR-URL: https://github.com/nodejs/node/pull/56600 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/56600 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> -------------------------------------------------------------------------------- ⚠ Commits were pushed since the last approving review: ⚠ - sqlite,doc,test: add aggregate function ⚠ - apply review suggestions ⚠ - apply review suggestion ℹ This PR was created on Tue, 14 Jan 2025 19:05:19 GMT ✔ Approvals: 2 ✔ - Colin Ihrig (@cjihrig): https://github.com/nodejs/node/pull/56600#pullrequestreview-2744917456 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/56600#pullrequestreview-2745190851 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2025-04-06T17:31:02Z: https://ci.nodejs.org/job/node-test-pull-request/66092/ ⚠ Commits were pushed after the last Full PR CI run: ⚠ - apply review suggestion - Querying data for job/node-test-pull-request/66092/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/14310034479 |
Landed in 437c6aa |
bool lossless; | ||
int64_t as_int = value.As<BigInt>()->Int64Value(&lossless); | ||
if (!lossless) { | ||
sqlite3_result_error(ctx, "BigInt value is too large for SQLite", -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Today we got a Coverity report for this line:
*** CID 519229: Memory - corruptions (BAD_FREE)
/src/node_sqlite.cc: 189 in node::sqlite::JSValueToSQLiteResult(v8::Isolate *, sqlite3_context *, v8::Local<v8::Value>)()
183 ArrayBufferViewContents<uint8_t> buf(value);
184 sqlite3_result_blob(ctx, buf.data(), buf.length(), SQLITE_TRANSIENT);
185 } else if (value->IsBigInt()) {
186 bool lossless;
187 int64_t as_int = [value.As](http://value.as/)<BigInt>()->Int64Value(&lossless);
188 if (!lossless) {
>>> CID 519229: Memory - corruptions (BAD_FREE)
>>> "sqlite3_result_error" frees array ""BigInt value is too large for SQLite"".
189 sqlite3_result_error(ctx, "BigInt value is too large for SQLite", -1);
190 return;
191 }
192 sqlite3_result_int64(ctx, as_int);
193 } else if (value->IsPromise()) {
194 sqlite3_result_error(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it something I can check locally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's weird that it was not complaining before. It was inline in the code; I just moved it to a method. Maybe adding inline
would fix it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might have complained before already. I just noticed the notification in my emails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possibly a false-positive. If you can confirm that, I will mark it as such.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't confirm with absolute certainty that this is a false positive, but I also can't find anything (online examples, etc.) to support what coverity is reporting.
This paragraph from the docs makes me think this is not an issue:
The sqlite3_result_error() and sqlite3_result_error16() functions cause the implemented SQL function to throw an exception. SQLite uses the string pointed to by the 2nd parameter of sqlite3_result_error() or sqlite3_result_error16() as the text of an error message. SQLite interprets the error message string from sqlite3_result_error() as UTF-8. SQLite interprets the string from sqlite3_result_error16() as UTF-16 using the same byte-order determination rules as sqlite3_bind_text16(). If the third parameter to sqlite3_result_error() or sqlite3_result_error16() is negative then SQLite takes as the error message all text up through the first zero character. If the third parameter to sqlite3_result_error() or sqlite3_result_error16() is non-negative then SQLite takes that many bytes (not characters) from the 2nd parameter as the error message. The sqlite3_result_error() and sqlite3_result_error16() routines make a private copy of the error message text before they return. Hence, the calling function can deallocate or modify the text after they return without harm. The sqlite3_result_error_code() function changes the error code returned by SQLite as a result of an error in a function. By default, the error code is SQLITE_ERROR. A subsequent call to sqlite3_result_error() or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the calling function can deallocate or modify the text after they return without harm
If we can do that, it's certainly not freed by sqlite. Marking as a false-positive, thanks!
PR-URL: nodejs#56600 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
Closes #56511
inspired by https://github.com/WiseLibs/better-sqlite3/blob/master/docs/api.md#aggregatename-options---this