Skip to content

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

Merged

Conversation

geeksilva97
Copy link
Contributor

@geeksilva97 geeksilva97 commented Jan 14, 2025

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem. labels Jan 14, 2025
@cjihrig
Copy link
Contributor

cjihrig commented Jan 20, 2025

Also, tests and docs are needed.

@cjihrig
Copy link
Contributor

cjihrig commented Mar 11, 2025

@geeksilva97 are you still planning to work on this?

@geeksilva97
Copy link
Contributor Author

@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.

@geeksilva97 geeksilva97 added the wip Issues and PRs that are still a work in progress. label Mar 15, 2025
@geeksilva97 geeksilva97 force-pushed the sqlite-aggregate-function branch 7 times, most recently from beaf983 to 70dff34 Compare March 19, 2025 13:00
@geeksilva97 geeksilva97 marked this pull request as ready for review March 19, 2025 13:01
@geeksilva97 geeksilva97 force-pushed the sqlite-aggregate-function branch from 70dff34 to f4e4869 Compare March 19, 2025 13:17
Copy link

codecov bot commented Mar 19, 2025

Codecov Report

Attention: Patch coverage is 80.48780% with 48 lines in your changes missing coverage. Please review.

Project coverage is 90.22%. Comparing base (9aa57bf) to head (484d68d).
Report is 43 commits behind head on main.

Files with missing lines Patch % Lines
src/node_sqlite.cc 80.48% 25 Missing and 23 partials ⚠️
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     
Files with missing lines Coverage Δ
src/node_sqlite.h 63.63% <ø> (ø)
src/node_sqlite.cc 80.47% <80.48%> (-0.05%) ⬇️

... and 48 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@geeksilva97
Copy link
Contributor Author

I got an implementation that works. I need to add tests and clean up the code.

@geeksilva97 geeksilva97 force-pushed the sqlite-aggregate-function branch 3 times, most recently from cd3f0aa to 22da3ad Compare March 20, 2025 19:56
@geeksilva97 geeksilva97 changed the title sqlite: add aggregate function [wip] sqlite: add aggregate function Mar 20, 2025
@geeksilva97 geeksilva97 force-pushed the sqlite-aggregate-function branch from 22da3ad to 9badd9b Compare March 20, 2025 20:59
@geeksilva97 geeksilva97 added the commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. label Apr 7, 2025
@geeksilva97
Copy link
Contributor Author

geeksilva97 commented Apr 7, 2025

It needs re-approval because I accepted Jasmes' suggestions.

@geeksilva97 geeksilva97 requested review from jasnell and cjihrig April 7, 2025 13:09
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Apr 7, 2025
@nodejs-github-bot
Copy link
Collaborator

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/.ncu
https://github.com/nodejs/node/actions/runs/14310034479

@cjihrig cjihrig added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 7, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 7, 2025
@nodejs-github-bot
Copy link
Collaborator

@geeksilva97 geeksilva97 added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 8, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 8, 2025
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@cjihrig cjihrig added commit-queue Add this label to land a pull request using GitHub Actions. and removed needs-ci PRs that need a full CI run. commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Apr 9, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 9, 2025
@nodejs-github-bot nodejs-github-bot merged commit 437c6aa into nodejs:main Apr 9, 2025
63 checks passed
@nodejs-github-bot
Copy link
Collaborator

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);
Copy link
Member

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(

Copy link
Contributor Author

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?

Copy link
Contributor Author

@geeksilva97 geeksilva97 Apr 9, 2025

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?

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some details from the coverity interface:
image
image

Copy link
Member

@targos targos Apr 9, 2025

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.

Copy link
Contributor

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.

Copy link
Member

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!

JonasBa pushed a commit to JonasBa/node that referenced this pull request Apr 11, 2025
PR-URL: nodejs#56600
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. sqlite Issues and PRs related to the SQLite subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

node:sqlite: sqlite module should provide wrapper for sqlite3_create_window_function api
6 participants