GeezerVison is showing github.com — fix: keep first duplicate column name and align columnsNames with row keys by Gioee · Pull Request #285 · sqlitecloud/sqlitecloud-js
Conversation
Fixes #282
Problem
When a query returns several columns with the same name (e.g. SELECT * over a join), SQLiteCloudRowset renames them so each SQLiteCloudRow can hold them as object keys. Two bugs:
- The renaming was backwards. The loop renamed the current column whenever any other column had the same name, so the first
id became id_0, the second id_0_1, and only the last kept id. row.id returned the value of the last id column instead of the first.
columnsNames didn't match the row keys. The constructor renamed a local copy, but the getter rebuilt names from metadata.columns on every call. Code that read row[name] for each name in columnsNames silently got the last duplicate's value in every duplicate column.
Fix
- Unique names are computed once in the constructor (
getUniqueColumnsNames):
- missing names become
column_N (unchanged)
- the first occurrence keeps its name; later duplicates get
_1, _2, …
- suffixes that already belong to another column are skipped (
id, id, id_1 → id, id_2, id_1)
columnsNames returns those same names (as a copy), so columnsNames + row[name] is consistent with getData().
- New
originalColumnsNames getter returns the names exactly as the query returned them, duplicates included.
slice() / filter() rebuild from metadata, so they get the same names.
⚠️ Behaviour change
- Rows with duplicate column names now use different keys: before
{ id_0: 7, id: 42 }, now { id: 7, id_1: 42 }.
columnsNames now returns deduplicated names (and column_N for empty names) instead of the raw metadata names. If you need the raw names, use originalColumnsNames.
Queries without duplicate or empty column names are not affected. This should go in the release notes.
Tests
test/rowset.test.ts:
- offline unit tests: renaming order,
columnsNames matching row keys, suffix collisions, missing names, columnsNames returning a copy, and slice/filter
- integration test against chinook with a join that returns duplicate
AlbumId/Title columns
Run locally: rowset, row, database, connection-tls, connection-ws suites all pass. tsc is clean.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
… keys
Duplicate column names in a rowset (e.g. SELECT * over a join) were renamed
starting from the first occurrence, so row.id returned the last id column
instead of the first. columnsNames also returned the raw metadata names, which
did not match the keys used in each row.
- keep the first occurrence of a name and suffix later duplicates with _1, _2,
skipping suffixes already used by another column
- columnsNames now returns the same unique names used as row keys
- add originalColumnsNames with the names exactly as returned by the query
Fixes #282
|
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.45%. Comparing base (bb3026e) to head (124f87c).
Additional details and impacted files
@@ Coverage Diff @@
## main #285 +/- ##
==========================================
+ Coverage 85.23% 85.45% +0.21%
==========================================
Files 11 11
Lines 1131 1141 +10
Branches 374 375 +1
==========================================
+ Hits 964 975 +11
+ Misses 167 154 -13
- Partials 0 12 +12
☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.
🚀 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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This branch has not been deployed
No deployments
Reviewers
At least 1 approving review is required to merge this pull request.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
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.
|