Repository navigation
Fixed parsing of empty sparsevec in SparseVector - #37
Closed
OsamaAnsar wants to merge 1 commit into
Closed
OsamaAnsar wants to merge 1 commit into
OsamaAnsar wants to merge 1 commit into
Conversation
An all-zero sparsevec is returned by Postgres as {}/n. Splitting the empty
body on ',' gave [''], so the constructor pushed parseInt('') - 1 and
parseFloat(undefined), leaving NaN in indices and values.
Member
|
Hi @OsamaAnsar, thanks for the PR. Merged a version of this in the commit above. |
Contributor
Author
Thanks! |
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.
new SparseVector('{}/3')(the text pgvector returns for an all-zerosparsevec) parses toNaNinstead of an empty vector.''.split(',')is[''], so#fromSqlpushesparseInt('') - 1andparseFloat(undefined).Real output on current
master(run againstsrc/index.js):With this change:
The fix takes the text between the braces and only loops over elements if it is not empty. Non-empty input like
{1:1,3:2}/4parses as before.Added a
fromSqlEmptytest totests/sparse-vector.test.js. It is a pure unit test and does not need a database.What I ran:
node --test tests/sparse-vector.test.js tests/utils.test.js: 8 pass.src/sparse-vector.jsreverted tomaster, the new test fails (actual: [ 0, 0, 0, NaN: NaN ]) and the other 5 pass; with the fix restored all 6 pass.npm run buildandnpm run check(afterprisma generate) complete without errors.