Setting the file. One moment.
Nothing Test · Clickhouse Js Node Rowbinary · ClickHouse/agent-skills · Skills Docs
ContentsBack to the top of the page (opens in a new tab)
tests/ nothing.test.ts
TypeScript · 75 lines · 3 KB
)
:
Promise
<
Cursor
> {
8 return new Cursor ( await query ( `SELECT ${ expr } FORMAT RowBinary` ));
9 }
10
11 /**
12 * `Nothing` is the empty type: it has NO values and occupies ZERO bytes. It is
13 * never a column on its own (you cannot materialize a value of it) — it only
14 * shows up wrapped, as the inferred element of a literal with no type:
15 *
16 * - `[]` -> `Array(Nothing)` -> always the empty array (varint len 0)
17 * - `NULL` -> `Nullable(Nothing)` -> always NULL (lone flag byte 0x01)
18 *
19 * So there is no dedicated reader, and no "read a Nothing" ever happens: the
20 * Array is empty (the element reader is not called) and the Nullable is NULL
21 * (the inner reader is not called). The throwing readers below assert exactly
22 * that — wrap with readArray / readNullable and the inner fn is unreachable.
23 *
24 * In practice, CAST a bare `[]`/`NULL` to a concrete type before SELECTing if
25 * you want real elements; `Nothing` only appears for untyped literals.
26 */
27 describe ( "Nothing (zero-width — only appears as Array(Nothing) / Nullable(Nothing))" , () => {
28 it ( "Array(Nothing) is the empty array; the element reader is never called" , async () => {
29 const r = await reader ( "[]" );
30 // readNothing throws if ever called; the empty array means it never is.
31 expect ( readArray (readNothing)(r)). toEqual ([]);
32 expect (r.pos). toBe ( 1 ); // just the varint length 0x00
33 });
34
35 it ( "Nullable(Nothing) is NULL; the inner reader is never called" , async () => {
36 const r = await reader ( "NULL" );
37 // readNothing throws if ever called; the NULL flag means it never is.
38 expect ( readNullable (readNothing)(r)). toBeNull ();
39 expect (r.pos). toBe ( 1 ); // lone NULL flag 0x01
40 });
41
42 describe ( "advance() edge cases" , () => {
43 it ( "Array(Nothing): throws NeedMoreData for every incomplete prefix" , async () => {
44 const full = await query ( "SELECT [] FORMAT RowBinary" ); // single 0x00 count byte
45 for ( let len = 0 ; len < full. length ; len ++ ) {
46 const r = new Cursor (full. subarray ( 0 , len));
47 let thrown : unknown ;
48 try {
49 readArray (() => {
50 throw new Error ( "element reader must not run" );
51 })(r);
52 } catch (e) {
53 thrown = e;
54 }
55 expect (thrown, `prefix length ${ len }` ). toBe (NeedMoreData);
56 }
57 });
58
59 it ( "Nullable(Nothing): throws NeedMoreData for every incomplete prefix" , async () => {
60 const full = await query ( "SELECT NULL FORMAT RowBinary" ); // single 0x01 flag byte
61 for ( let len = 0 ; len < full. length ; len ++ ) {
62 const r = new Cursor (full. subarray ( 0 , len));
63 let thrown : unknown ;
64 try {
65 readNullable (() => {
66 throw new Error ( "inner reader must not run" );
67 })(r);
68 } catch (e) {
69 thrown = e;
70 }
71 expect (thrown, `prefix length ${ len }` ). toBe (NeedMoreData);
72 }
73 });
74 });
75 });