Skip to content

feat(client): add queryTable for column-aware query results - #51

Merged
AayushMainali-Github merged 2 commits into
mainfrom
feat/34-query-table
Jul 25, 2026
Merged

feat(client): add queryTable for column-aware query results#51
AayushMainali-Github merged 2 commits into
mainfrom
feat/34-query-table

Conversation

@AayushMainali-Github

Copy link
Copy Markdown
Owner

Adds client.queryTable(), returning a result's columns alongside its rows.

What probing the server changed about this issue

The issue asked for "column metadata and typed row helpers". The server only supports half of that, so this delivers the half that is real and documents why the rest is not.

Accept: application/json, which query() uses, turned out to lose two things:

  • Key order is alphabetical, not select order. SELECT v, city returns {"city": ..., "v": ...}, so column order cannot be recovered from the response.
  • A NULL column is omitted from that row's object entirely. SELECT city, v, n over two rows returns [{"city":"Pokhara","n":7,"v":1.5},{"city":"Lalitpur","v":2.5}]. The second row has no n key at all, so row objects differ in shape and a typed T promising n: number is simply wrong.

Accept: application/csv carries the column names in their true order, emits every column for every row, and still returns the header row when nothing matched. That is what queryTable() uses.

No response format carries column types, so "typed row helpers" cannot be built on anything but guesswork. Values come back as raw strings and the caller converts what it needs. Guessing wrong on a large integer or a timestamp is worse than an honest string.

One ambiguity is unavoidable and documented: CSV renders both NULL and an empty string as an empty field, so the two cannot be told apart.

Implementation

A small hand-written RFC 4180 parser in src/csv/, rather than a dependency: the grammar is tiny, the input comes from one known producer, and a parser is easier to audit than another supply-chain entry in a client whose only job is talking to one server. It handles quoted fields, doubled quotes, embedded commas and newlines, CRLF and bare CR, and empty leading, middle, and trailing fields.

query() is untouched. This is an addition, not a replacement: JSON remains the more convenient option when you know the columns and none of them are nullable.

Also exports the Compression type from the package root. It was added as a client option in 0.2.0 but was never importable, so anyone annotating a variable with it could not.

Testing

52 new unit tests, taking the suite from 295 to 347. 22 cover the CSV parser directly, including the doubled-quote form CnosDB actually emits.

Four integration tests confirm the behaviour against a live server rather than against my reading of it: column order survives, an empty result still reports its columns, a NULL stays aligned instead of vanishing, and a value containing both a comma and a quote round-trips.

npm run check and the full integration suite pass.

Closes #34

The JSON format sorts keys alphabetically and omits any column that is NULL
for a row, so column order is unrecoverable and row objects differ in shape.
CSV carries the real column order and every column for every row.

No response format carries column types, so values stay raw strings rather
than being guessed at.
@AayushMainali-Github AayushMainali-Github added this to the v0.2.0 milestone Jul 25, 2026
@AayushMainali-Github AayushMainali-Github added type: feature New functionality area: client Area: client area: types Area: types labels Jul 25, 2026
@github-actions github-actions Bot added area: testing Area: testing area: documentation Area: documentation area: release Area: release labels Jul 25, 2026
2.4.3 returns the header row for an empty result; 2.4.1 returns an empty body.
The ping string cannot distinguish them, since 2.4.1 reports itself as 2.4.0,
so the test accepts both and the docs no longer promise columns below 2.4.3.
@AayushMainali-Github
AayushMainali-Github merged commit 6340578 into main Jul 25, 2026
14 checks passed
@AayushMainali-Github
AayushMainali-Github deleted the feat/34-query-table branch July 25, 2026 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: client Area: client area: documentation Area: documentation area: release Area: release area: testing Area: testing area: types Area: types type: feature New functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Expose column metadata and typed row helpers for query results

1 participant