Skip to content

Commit 7d197f7

Browse files
committed
Merge branch 'arrays_support' into js_doc
2 parents 10d70c3 + 3acd71f commit 7d197f7

File tree

7 files changed

+98
-13
lines changed

7 files changed

+98
-13
lines changed

src/buffer/base.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ abstract class SenderBufferBase implements SenderBuffer {
151151
}
152152

153153
/**
154-
* Writes a symbol name and value into the buffer.
154+
* Writes a symbol name and value into the buffer. <br>
155+
* Use it to insert into SYMBOL columns.
155156
*
156157
* @param {string} name - Symbol name.
157158
* @param {unknown} value - Symbol value, toString() is called to extract the actual symbol value from the parameter.
@@ -178,7 +179,8 @@ abstract class SenderBufferBase implements SenderBuffer {
178179
}
179180

180181
/**
181-
* Writes a string column with its value into the buffer.
182+
* Writes a string column with its value into the buffer. <br>
183+
* Use it to insert into VARCHAR and STRING columns.
182184
*
183185
* @param {string} name - Column name.
184186
* @param {string} value - Column value, accepts only string values.
@@ -200,7 +202,8 @@ abstract class SenderBufferBase implements SenderBuffer {
200202
}
201203

202204
/**
203-
* Writes a boolean column with its value into the buffer.
205+
* Writes a boolean column with its value into the buffer. <br>
206+
* Use it to insert into BOOLEAN columns.
204207
*
205208
* @param {string} name - Column name.
206209
* @param {boolean} value - Column value, accepts only boolean values.
@@ -220,7 +223,8 @@ abstract class SenderBufferBase implements SenderBuffer {
220223
}
221224

222225
/**
223-
* Writes a float column with its value into the buffer.
226+
* Writes a 64-bit floating point value into the buffer. <br>
227+
* Use it to insert into DOUBLE or FLOAT database columns.
224228
*
225229
* @param {string} name - Column name.
226230
* @param {number} value - Column value, accepts only number values.
@@ -238,7 +242,8 @@ abstract class SenderBufferBase implements SenderBuffer {
238242
abstract arrayColumn(name: string, value: unknown[]): SenderBuffer;
239243

240244
/**
241-
* Writes an integer column with its value into the buffer.
245+
* Writes a 64-bit signed integer into the buffer. <br>
246+
* Use it to insert into LONG, INT, SHORT and BYTE columns.
242247
*
243248
* @param {string} name - Column name.
244249
* @param {number} value - Column value, accepts only number values.
@@ -259,7 +264,8 @@ abstract class SenderBufferBase implements SenderBuffer {
259264
}
260265

261266
/**
262-
* Writes a timestamp column with its value into the buffer.
267+
* Writes a timestamp column with its value into the buffer. <br>
268+
* Use it to insert into TIMESTAMP columns.
263269
*
264270
* @param {string} name - Column name.
265271
* @param {number | bigint} value - Epoch timestamp, accepts numbers or BigInts.

src/buffer/bufferv1.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class SenderBufferV1 extends SenderBufferBase {
1717
}
1818

1919
/**
20-
* Writes a float column with its value into the buffer using v1 serialization (text format).
20+
* Writes a 64-bit floating point value into the buffer using v1 serialization (text format). <br>
21+
* Use it to insert into DOUBLE or FLOAT database columns.
2122
*
2223
* @param {string} name - Column name.
2324
* @param {number} value - Column value, accepts only number values.

src/buffer/bufferv2.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class SenderBufferV2 extends SenderBufferBase {
2929
}
3030

3131
/**
32-
* Writes a float column with its value into the buffer using v2 serialization (binary format).
32+
* Writes a 64-bit floating point value into the buffer using v2 serialization (binary format). <br>
33+
* Use it to insert into DOUBLE or FLOAT database columns.
3334
*
3435
* @param {string} name - Column name.
3536
* @param {number} value - Column value, accepts only number values.
@@ -104,7 +105,7 @@ class SenderBufferV2 extends SenderBufferBase {
104105
this.writeArrayValues(arr[i] as unknown[], dimensions);
105106
}
106107
} else {
107-
const type = arr[0] ? typeof arr[0] : null;
108+
const type = arr[0] !== undefined ? typeof arr[0] : null;
108109
switch (type) {
109110
case "number":
110111
for (let i = 0; i < arr.length; i++) {

src/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function validateArray(data: unknown[], dimensions: number[]): ArrayPrimitive {
134134
}
135135
} else {
136136
// leaf level, expecting primitives
137-
if (expectedType === null && array[0]) {
137+
if (expectedType === null && array[0] !== undefined) {
138138
expectedType = typeof array[0] as ArrayPrimitive;
139139
}
140140

@@ -171,7 +171,7 @@ async function fetchJson<T>(
171171
): Promise<T> {
172172
const controller = new AbortController();
173173
const { signal } = controller;
174-
setTimeout(() => controller.abort(), timeout);
174+
const timeoutId = setTimeout(() => controller.abort(), timeout);
175175

176176
let response: globalThis.Response;
177177
try {
@@ -181,6 +181,8 @@ async function fetchJson<T>(
181181
});
182182
} catch (error) {
183183
throw new Error(`Failed to load ${url} [error=${error}]`);
184+
} finally {
185+
clearTimeout(timeoutId);
184186
}
185187

186188
if (!response.ok) {

test/options.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ const proxyOptions = {
1515
ca: readFileSync("test/certs/ca/ca.crt"),
1616
};
1717

18-
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";
19-
2018
describe("Configuration string parser suite", function () {
2119
const mockHttp = new MockHttp();
2220
const mockHttps = new MockHttp();

test/sender.buffer.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,22 @@ describe("Sender message builder test suite (anything not covered in client inte
199199
await sender.close();
200200
});
201201

202+
it("supports arrays with zeros", async function () {
203+
const sender = new Sender({
204+
protocol: "tcp",
205+
protocol_version: "2",
206+
host: "host",
207+
init_buf_size: 1024,
208+
});
209+
await sender.table("tableName").arrayColumn("arrayCol", [0.0, 0.0]).atNow();
210+
expect(bufferContentHex(sender)).toBe(
211+
toHex("tableName arrayCol==") +
212+
" 0e 0a 01 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " +
213+
toHex("\n"),
214+
);
215+
await sender.close();
216+
});
217+
202218
it("supports multidimensional arrays with protocol v2", async function () {
203219
const sender = new Sender({
204220
protocol: "tcp",

test/sender.integration.test.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,67 @@ describe("Sender tests with containerized QuestDB instance", () => {
363363
await sender.close();
364364
});
365365

366+
it("can ingest zero vector via HTTP with protocol v2", async () => {
367+
const tableName = "test_http_v2_zeros";
368+
const schema = [
369+
{ name: "location", type: "SYMBOL" },
370+
{ name: "temperatures", type: "ARRAY", elemType: "DOUBLE", dim: 2 },
371+
{ name: "timestamp", type: "TIMESTAMP" },
372+
];
373+
374+
const sender = await Sender.fromConfig(
375+
`http::addr=${container.getHost()}:${container.getMappedPort(QUESTDB_HTTP_PORT)}`,
376+
);
377+
378+
// ingest via client
379+
await sender
380+
.table(tableName)
381+
.symbol("location", "us")
382+
.arrayColumn("temperatures", [
383+
[17.1, 17.7, 18.4],
384+
[17.1, 17.7, 18.4],
385+
])
386+
.at(1658484765000000000n, "ns");
387+
await sender
388+
.table(tableName)
389+
.symbol("location", "gb")
390+
.arrayColumn("temperatures", [
391+
[0.0, 0.0, 0.0],
392+
[0.0, 0.0, 0.0],
393+
])
394+
.at(1658484765000666000n, "ns");
395+
await sender.flush();
396+
397+
// wait for the table
398+
await waitForTable(container, tableName);
399+
400+
// query table
401+
const select1Result = await runSelect(container, tableName, 2);
402+
expect(select1Result.query).toBe(tableName);
403+
expect(select1Result.count).toBe(2);
404+
expect(select1Result.columns).toStrictEqual(schema);
405+
expect(select1Result.dataset).toStrictEqual([
406+
[
407+
"us",
408+
[
409+
[17.1, 17.7, 18.4],
410+
[17.1, 17.7, 18.4],
411+
],
412+
"2022-07-22T10:12:45.000000Z",
413+
],
414+
[
415+
"gb",
416+
[
417+
[0.0, 0.0, 0.0],
418+
[0.0, 0.0, 0.0],
419+
],
420+
"2022-07-22T10:12:45.000666Z",
421+
],
422+
]);
423+
424+
await sender.close();
425+
});
426+
366427
it("can ingest empty array via HTTP with protocol v2", async () => {
367428
const tableName = "test_http_v2_empty";
368429
const schema = [

0 commit comments

Comments
 (0)