Commit d0f0b37
authored
Fix Array(Date) query param binding: serialize container Dates as quoted date strings (#947)
## Description
Fixes #946.
`formatQueryParams` serialized a JS `Date` as a bare Unix-seconds
integer (e.g. `1683244800`) in **every** context. Inside a container
that becomes `[1683244800]`, which ClickHouse accepts for
`Array(DateTime)` but **rejects** for `Array(Date)`/`Array(Date32)`:
```
Code: 27. DB::Exception: Cannot parse input: expected '\'' before: '1683244800]':
value [1683244800] cannot be parsed as Array(Date) for query parameter 'l'.
(CANNOT_PARSE_INPUT_ASSERTION_FAILED)
```
The `Date` branch now mirrors the existing `boolean` handling and uses
the `isInArrayOrTuple` flag: inside arrays, tuples, and maps a `Date` is
emitted as a quoted UTC `'YYYY-MM-DD'` string. Verified against
ClickHouse 26.5 that this is the **single** representation the element
parser accepts for **all** temporal element types — `Array(Date)`,
`Array(Date32)`, `Array(DateTime)`, and `Array(DateTime64)` (bare int,
quoted int, and full datetime strings are all rejected by
`Array(Date)`). Scalar `Date`/`DateTime`/`DateTime64` binding is
**unchanged** (scalar still uses the bare Unix-timestamp form that
scalar `DateTime` relies on).
### Behavioral note (deliberate tradeoff)
Because a query parameter is type-agnostic on the client side (the
formatter can't see whether the target column is `Array(Date)` or
`Array(DateTime)`), a `Date` used inside
`Array(DateTime)`/`Array(DateTime64)` is now bound at **day precision**
— the time-of-day is dropped (`2022-05-02 13:25:55` → `2022-05-02
00:00:00`). Date-only is the only encoding `Array(Date)` accepts, so
this is unavoidable for a type-blind formatter; an integration test pins
this behavior. Scalar `DateTime`/`DateTime64` are untouched and keep
full precision.
This is the JS analog of a cross-client class also fixed in
clickhouse-java (#2898) and reported for clickhouse-connect (#188).
## Changes
- `packages/client-common/src/data_formatter/format_query_params.ts`: in
the `value instanceof Date` branch, when `isInArrayOrTuple` is true,
return `'${value.toISOString().slice(0, 10)}'`. (This file is the single
shared source; `client-node`/`client-web` symlink it, so both clients
get the fix.)
## Test
- **Unit** (`format_query_params.test.ts`): `Date` in an array, nested
array, tuple, and object value all render as quoted date strings;
time-of-day/millis are dropped; a `Date` composes with other element
types in a mixed array. Existing scalar `Date` tests are retained as the
contrast that pins the unchanged scalar output.
- **Integration** (`select_query_binding.test.ts`): binding `[Date,
Date]` to `Array(Date)` round-trips to `["2023-05-05","2021-01-02"]`
(fails on `main` with the parse error above); a `Date` bound to
`Array(DateTime)` returns `2022-05-02 00:00:00`, documenting the
day-precision tradeoff and guarding that `Array(DateTime)` no longer
errors.
Verified the unit tests fail on unpatched code with the exact bug
(`expected '[1659081134]' to be '['2022-07-29']'`) and pass with the
fix; full unit suite (389 passed) and the `select_query_binding`
integration suite (31 passed) are green; `prettier`, `eslint`, and `tsc`
are clean.
## Pre-PR validation gate
- [x] Deterministic repro confirmed (server rejects `[<unix>]` for
`Array(Date)`; new tests fail on `main`)
- [x] Root cause documented above
- [x] Fix targets the root cause (container element encoding)
- [x] Test fails without fix, passes with fix
- [x] No existing tests broken; no existing tests weakened
- [x] Fix on the live runtime path (proven by an end-to-end integration
test through `client.query`)
- [x] Convention compliance verified per `AGENTS.md` / `CONTRIBUTING.md`
- [ ] CHANGELOG entries (added in a follow-up commit on this branch)
---------
Co-authored-by: Polyglot AI <293096396+polyglotAI-bot@users.noreply.github.com>1 parent 3bccc81 commit d0f0b37
5 files changed
Lines changed: 101 additions & 0 deletions
File tree
- packages
- client-common
- __tests__
- integration
- unit
- src/data_formatter
- client-node
- client-web
Lines changed: 29 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
271 | 300 | | |
272 | 301 | | |
273 | 302 | | |
| |||
Lines changed: 48 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
252 | 300 | | |
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
83 | 91 | | |
84 | 92 | | |
85 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
1 | 9 | | |
2 | 10 | | |
3 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
1 | 9 | | |
2 | 10 | | |
3 | 11 | | |
| |||
0 commit comments