Skip to content

Commit bbaaeb5

Browse files
committed
Merge branch 'main' into feat/stmt2/decimal
2 parents c701fea + 3fe094c commit bbaaeb5

11 files changed

Lines changed: 570 additions & 60 deletions

File tree

nodejs/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodejs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tdengine/websocket",
3-
"version": "3.3.0",
3+
"version": "3.4.0",
44
"description": "The websocket Node.js connector for TDengine. TDengine versions 3.3.2.0 and above are recommended to use this connector.",
55
"source": "index.ts",
66
"main": "lib/index.js",

nodejs/src/common/constant.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const TDengineTypeName: IndexableString = {
3434
14: "BIGINT UNSIGNED",
3535
15: "JSON",
3636
16: "VARBINARY",
37+
18: "BLOB",
3738
20: "GEOMETRY",
3839
};
3940

@@ -43,6 +44,7 @@ export const ColumnsBlockType: StringIndexable = {
4344
NCHAR: 2,
4445
GEOMETRY: 3,
4546
VARBINARY: 4,
47+
BLOB: 5,
4648
};
4749

4850
export enum TDengineTypeCode {
@@ -65,6 +67,7 @@ export enum TDengineTypeCode {
6567
JSON = 15,
6668
VARBINARY = 16,
6769
DECIMAL = 17,
70+
BLOB = 18,
6871
GEOMETRY = 20,
6972
DECIMAL64 = 21,
7073
}

nodejs/src/common/taosResult.ts

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,6 @@ export class TaosResult {
164164
return null;
165165
}
166166

167-
/**
168-
* Mapping the WebSocket response type code to TDengine's type name.
169-
*/
170167
private getTDengineMeta(): Array<TDengineMeta> | null {
171168
if (this._meta) {
172169
let tdMeta = new Array<TDengineMeta>();
@@ -226,7 +223,6 @@ export function parseBlock(
226223

227224
let byteArrayIndex = i >> 3;
228225
let bitwiseOffset = 7 - (i & 7);
229-
// let bitMapArr = dataBuffer.slice(colBlockHead, colBlockHead + bitMapSize)
230226
let bitMapArr = new DataView(
231227
dataView.buffer,
232228
dataView.byteOffset + colBlockHead,
@@ -267,34 +263,38 @@ export function parseBlock(
267263
INT_32_SIZE * rows +
268264
dataView.getInt32(j * INT_32_SIZE, true);
269265
} else {
270-
colDataHead =
271-
colBlockHead + INT_32_SIZE * rows + varOffset;
272-
let dataLength = dataView.getInt16(colDataHead, true);
266+
colDataHead = colBlockHead + INT_32_SIZE * rows + varOffset;
267+
const dataHeadSize = isVarType == ColumnsBlockType.BLOB ? 4 : 2;
268+
let dataLength =
269+
isVarType == ColumnsBlockType.BLOB
270+
? dataView.getUint32(colDataHead, true)
271+
: dataView.getUint16(colDataHead, true);
273272
if (isVarType == ColumnsBlockType.VARCHAR) {
274273
row.push(
275274
readVarchar(
276275
dataView.buffer,
277-
dataView.byteOffset + colDataHead + 2,
276+
dataView.byteOffset + colDataHead + dataHeadSize,
278277
dataLength,
279278
textDecoder
280279
)
281280
);
282281
} else if (
283282
isVarType == ColumnsBlockType.GEOMETRY ||
284-
isVarType == ColumnsBlockType.VARBINARY
283+
isVarType == ColumnsBlockType.VARBINARY ||
284+
isVarType == ColumnsBlockType.BLOB
285285
) {
286286
row.push(
287287
readBinary(
288288
dataView.buffer,
289-
dataView.byteOffset + colDataHead + 2,
289+
dataView.byteOffset + colDataHead + dataHeadSize,
290290
dataLength
291291
)
292292
);
293293
} else {
294294
row.push(
295295
readNchar(
296296
dataView.buffer,
297-
dataView.byteOffset + colDataHead + 2,
297+
dataView.byteOffset + colDataHead + dataHeadSize,
298298
dataLength
299299
)
300300
);
@@ -320,25 +320,28 @@ export function parseBlock(
320320
export function _isVarType(metaType: number): Number {
321321
switch (metaType) {
322322
case TDengineTypeCode.NCHAR: {
323-
return ColumnsBlockType["NCHAR"];
323+
return ColumnsBlockType.NCHAR;
324324
}
325325
case TDengineTypeCode.VARCHAR: {
326-
return ColumnsBlockType["VARCHAR"];
326+
return ColumnsBlockType.VARCHAR;
327327
}
328328
case TDengineTypeCode.BINARY: {
329-
return ColumnsBlockType["VARCHAR"];
329+
return ColumnsBlockType.VARCHAR;
330330
}
331331
case TDengineTypeCode.JSON: {
332-
return ColumnsBlockType["VARCHAR"];
332+
return ColumnsBlockType.VARCHAR;
333333
}
334334
case TDengineTypeCode.GEOMETRY: {
335-
return ColumnsBlockType["GEOMETRY"];
335+
return ColumnsBlockType.GEOMETRY;
336336
}
337337
case TDengineTypeCode.VARBINARY: {
338338
return ColumnsBlockType.VARBINARY;
339339
}
340+
case TDengineTypeCode.BLOB: {
341+
return ColumnsBlockType.BLOB;
342+
}
340343
default: {
341-
return ColumnsBlockType["SOLID"];
344+
return ColumnsBlockType.SOLID;
342345
}
343346
}
344347
}
@@ -569,16 +572,18 @@ export function readSolidData(
569572
}
570573

571574
export function readBinary(
572-
dataBuffer: ArrayBuffer,
575+
dataBuffer: ArrayBufferLike,
573576
colDataHead: number,
574577
length: number
575578
): ArrayBuffer {
576-
let buff = dataBuffer.slice(colDataHead, colDataHead + length);
579+
const buff = new ArrayBuffer(length);
580+
const source = new Uint8Array(dataBuffer, colDataHead, length);
581+
new Uint8Array(buff).set(source);
577582
return buff;
578583
}
579584

580585
export function readVarchar(
581-
dataBuffer: ArrayBuffer,
586+
dataBuffer: ArrayBufferLike,
582587
colDataHead: number,
583588
length: number,
584589
textDecoder: TextDecoder
@@ -588,7 +593,7 @@ export function readVarchar(
588593
}
589594

590595
export function readNchar(
591-
dataBuffer: ArrayBuffer,
596+
dataBuffer: ArrayBufferLike,
592597
colDataHead: number,
593598
length: number
594599
): string {
@@ -614,15 +619,8 @@ export function getString(
614619
return textDecoder.decode(dataView);
615620
}
616621

617-
function iteratorBuff(arr: ArrayBuffer) {
618-
let buf = Buffer.from(arr);
619-
for (const value of buf) {
620-
logger.debug(value.toString());
621-
}
622-
}
623-
624-
function isNull(bitMapArr: ArrayBuffer, n: number) {
625-
let c = new Uint8Array(bitMapArr);
622+
function isNull(bitMapArr: Uint8Array, n: number) {
623+
let c = bitMapArr;
626624
let position = n >>> 3;
627625
let index = n & 0x7;
628626
return (c[position] & (1 << (7 - index))) == 1 << (7 - index);

nodejs/src/stmt/wsParams1.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export class Stmt1BindParams extends StmtBindParams implements IDataEncoder {
3434
"StmtBindParams params is invalid!"
3535
);
3636
}
37+
if (columnType === TDengineTypeCode.BLOB) {
38+
throw new TaosError(
39+
ErrorCode.ERR_INVALID_PARAMS,
40+
"BLOB parameters are not supported for stmt1"
41+
);
42+
}
3743
if (
3844
dataType === "number" ||
3945
dataType === "bigint" ||

nodejs/src/stmt/wsParamsBase.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,7 @@ export abstract class StmtBindParams {
263263
"SetVarcharColumn params is invalid!"
264264
);
265265
}
266-
this.addParams(
267-
params,
268-
TDengineTypeName[8],
269-
0,
270-
TDengineTypeCode.VARCHAR
271-
);
266+
this.addParams(params, TDengineTypeName[8], 0, TDengineTypeCode.VARCHAR);
272267
}
273268

274269
setBinary(params: any[]) {
@@ -308,12 +303,17 @@ export abstract class StmtBindParams {
308303
"SetVarBinaryColumn params is invalid!"
309304
);
310305
}
311-
this.addParams(
312-
params,
313-
TDengineTypeName[16],
314-
0,
315-
TDengineTypeCode.VARBINARY
316-
);
306+
this.addParams(params, TDengineTypeName[16], 0, TDengineTypeCode.VARBINARY);
307+
}
308+
309+
setBlob(params: any[]) {
310+
if (!params || params.length == 0) {
311+
throw new TaosError(
312+
ErrorCode.ERR_INVALID_PARAMS,
313+
"SetBlobColumn params is invalid!"
314+
);
315+
}
316+
this.addParams(params, TDengineTypeName[18], 0, TDengineTypeCode.BLOB);
317317
}
318318

319319
setGeometry(params: any[]) {
@@ -323,12 +323,7 @@ export abstract class StmtBindParams {
323323
"SetGeometryColumn params is invalid!"
324324
);
325325
}
326-
this.addParams(
327-
params,
328-
TDengineTypeName[20],
329-
0,
330-
TDengineTypeCode.GEOMETRY
331-
);
326+
this.addParams(params, TDengineTypeName[20], 0, TDengineTypeCode.GEOMETRY);
332327
}
333328

334329
setTimestamp(params: any[]) {

nodejs/src/tmq/tmqResponse.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,32 +343,32 @@ export class WSTmqFetchBlockInfo {
343343
value = null;
344344
} else {
345345
let header = start + offsets[i];
346+
const dataHeadSize = isVarType == ColumnsBlockType.BLOB ? 4 : 2;
346347
let dataLength =
347-
dataView.getInt16(header, true) & 0xffff;
348+
isVarType == ColumnsBlockType.BLOB
349+
? dataView.getUint32(header, true)
350+
: dataView.getUint16(header, true);
348351
if (isVarType == ColumnsBlockType.VARCHAR) {
349-
//decode var char
350-
351352
value = readVarchar(
352353
dataView.buffer,
353-
dataView.byteOffset + header + 2,
354+
dataView.byteOffset + header + dataHeadSize,
354355
dataLength,
355356
this.textDecoder
356357
);
357358
} else if (
358359
isVarType == ColumnsBlockType.GEOMETRY ||
359-
isVarType == ColumnsBlockType.VARBINARY
360+
isVarType == ColumnsBlockType.VARBINARY ||
361+
isVarType == ColumnsBlockType.BLOB
360362
) {
361-
//decode binary
362363
value = readBinary(
363364
dataView.buffer,
364-
dataView.byteOffset + header + 2,
365+
dataView.byteOffset + header + dataHeadSize,
365366
dataLength
366367
);
367368
} else {
368-
//decode nchar
369369
value = readNchar(
370370
dataView.buffer,
371-
dataView.byteOffset + header + 2,
371+
dataView.byteOffset + header + dataHeadSize,
372372
dataLength
373373
);
374374
}

0 commit comments

Comments
 (0)