@tdengine/websocket 3.1.0 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/example/all_type_query.d.ts +2 -0
- package/lib/example/all_type_query.d.ts.map +1 -0
- package/lib/example/all_type_query.js +89 -0
- package/lib/example/all_type_stmt.d.ts +2 -0
- package/lib/example/all_type_stmt.d.ts.map +1 -0
- package/lib/example/all_type_stmt.js +130 -0
- package/lib/example/basicBatchTmq.d.ts +2 -0
- package/lib/example/basicBatchTmq.d.ts.map +1 -0
- package/lib/example/basicBatchTmq.js +129 -0
- package/lib/example/basicSql.js +9 -7
- package/lib/example/basicStmt.js +34 -20
- package/lib/example/basicTmq.js +22 -20
- package/lib/example/logs/.007e668bb78549e9a304b8466671945ab2a1553e-audit.json +15 -0
- package/lib/example/logs/app-2024-10-12.log.gz +0 -0
- package/lib/example/logs/app-2024-11-06.log +542 -0
- package/lib/example/test.d.ts +2 -0
- package/lib/example/test.d.ts.map +1 -0
- package/lib/example/test.js +88 -0
- package/lib/src/client/wsClient.d.ts +2 -5
- package/lib/src/client/wsClient.d.ts.map +1 -1
- package/lib/src/client/wsClient.js +4 -54
- package/lib/src/client/wsConnector.js +3 -3
- package/lib/src/client/wsResponse.d.ts +10 -15
- package/lib/src/client/wsResponse.d.ts.map +1 -1
- package/lib/src/client/wsResponse.js +31 -19
- package/lib/src/common/constant.d.ts +23 -1
- package/lib/src/common/constant.d.ts.map +1 -1
- package/lib/src/common/constant.js +25 -22
- package/lib/src/common/log.js +1 -1
- package/lib/src/common/taosResult.d.ts +11 -5
- package/lib/src/common/taosResult.d.ts.map +1 -1
- package/lib/src/common/taosResult.js +106 -76
- package/lib/src/common/utils.d.ts +2 -0
- package/lib/src/common/utils.d.ts.map +1 -1
- package/lib/src/common/utils.js +34 -1
- package/lib/src/sql/wsRows.d.ts.map +1 -1
- package/lib/src/sql/wsRows.js +21 -10
- package/lib/src/sql/wsSql.d.ts.map +1 -1
- package/lib/src/sql/wsSql.js +29 -19
- package/lib/src/stmt/wsParams.js +40 -40
- package/lib/src/tmq/constant.d.ts +15 -0
- package/lib/src/tmq/constant.d.ts.map +1 -1
- package/lib/src/tmq/constant.js +17 -1
- package/lib/src/tmq/tmqResponse.d.ts +20 -8
- package/lib/src/tmq/tmqResponse.d.ts.map +1 -1
- package/lib/src/tmq/tmqResponse.js +214 -89
- package/lib/src/tmq/wsTmq.d.ts +0 -1
- package/lib/src/tmq/wsTmq.d.ts.map +1 -1
- package/lib/src/tmq/wsTmq.js +18 -32
- package/lib/test/bulkPulling/log.test.d.ts +2 -0
- package/lib/test/bulkPulling/log.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/log.test.js +44 -0
- package/lib/test/bulkPulling/schemaless.test.js +7 -6
- package/lib/test/bulkPulling/sql.test.js +38 -18
- package/lib/test/bulkPulling/stmt.func.test.js +72 -56
- package/lib/test/bulkPulling/stmt.type.test.js +1 -5
- package/lib/test/bulkPulling/tmq.test.js +22 -15
- package/lib/test/bulkPulling/wsConnectPool.test.js +9 -2
- package/lib/test/utils.d.ts +0 -1
- package/lib/test/utils.d.ts.map +1 -1
- package/lib/test/utils.js +17 -17
- package/package.json +2 -2
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.bitmapLen = exports.setBitmapNull = exports.getCharOffset = exports.readNchar = exports.readVarchar = exports.readBinary = exports.readSolidData = exports.readSolidDataToArray = exports._isVarType = exports.parseBlock = exports.TaosResult = void 0;
|
|
6
|
+
exports.bitmapLen = exports.setBitmapNull = exports.getCharOffset = exports.getString = exports.readNchar = exports.readVarchar = exports.readBinary = exports.readSolidData = exports.readSolidDataToArray = exports._isVarType = exports.parseBlock = exports.TaosResult = void 0;
|
|
7
7
|
const constant_1 = require("./constant");
|
|
8
8
|
const wsError_1 = require("./wsError");
|
|
9
9
|
const ut8Helper_1 = require("./ut8Helper");
|
|
@@ -12,8 +12,8 @@ class TaosResult {
|
|
|
12
12
|
constructor(queryResponse) {
|
|
13
13
|
this._totalTime = 0;
|
|
14
14
|
if (queryResponse == null) {
|
|
15
|
-
this._meta =
|
|
16
|
-
this._data =
|
|
15
|
+
this._meta = [];
|
|
16
|
+
this._data = [];
|
|
17
17
|
this._timing = BigInt(0);
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
@@ -43,6 +43,9 @@ class TaosResult {
|
|
|
43
43
|
this._precision = queryResponse.precision;
|
|
44
44
|
this._totalTime = queryResponse.totalTime;
|
|
45
45
|
}
|
|
46
|
+
setPrecision(precision) {
|
|
47
|
+
this._precision = precision;
|
|
48
|
+
}
|
|
46
49
|
setRowsAndTime(rows, timing) {
|
|
47
50
|
if (this._affectRows) {
|
|
48
51
|
this._affectRows += rows;
|
|
@@ -54,9 +57,23 @@ class TaosResult {
|
|
|
54
57
|
this.setTiming(timing);
|
|
55
58
|
}
|
|
56
59
|
}
|
|
60
|
+
getTopic() {
|
|
61
|
+
if (this._topic) {
|
|
62
|
+
return this._topic;
|
|
63
|
+
}
|
|
64
|
+
return "";
|
|
65
|
+
}
|
|
66
|
+
setTopic(topic = "") {
|
|
67
|
+
this._topic = topic;
|
|
68
|
+
}
|
|
57
69
|
getMeta() {
|
|
58
70
|
return this.getTDengineMeta();
|
|
59
71
|
}
|
|
72
|
+
setMeta(metaData) {
|
|
73
|
+
if (this._meta) {
|
|
74
|
+
this._meta.push(metaData);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
60
77
|
getData() {
|
|
61
78
|
return this._data;
|
|
62
79
|
}
|
|
@@ -105,10 +122,15 @@ class TaosResult {
|
|
|
105
122
|
}
|
|
106
123
|
}
|
|
107
124
|
exports.TaosResult = TaosResult;
|
|
108
|
-
function parseBlock(
|
|
125
|
+
function parseBlock(blocks, taosResult) {
|
|
109
126
|
let metaList = taosResult.getTaosMeta();
|
|
110
127
|
let dataList = taosResult.getData();
|
|
111
|
-
|
|
128
|
+
let textDecoder = new TextDecoder();
|
|
129
|
+
if (metaList && dataList && blocks && blocks.data) {
|
|
130
|
+
let rows = blocks.data.getUint32(8, true);
|
|
131
|
+
if (rows == 0) {
|
|
132
|
+
return taosResult;
|
|
133
|
+
}
|
|
112
134
|
taosResult.setTiming(blocks.timing);
|
|
113
135
|
const INT_32_SIZE = 4;
|
|
114
136
|
// Offset num of bytes from rawBlockBuffer.
|
|
@@ -117,7 +139,9 @@ function parseBlock(rows, blocks, taosResult) {
|
|
|
117
139
|
log_1.default.debug("===colLengthBlockSize:" + colLengthBlockSize);
|
|
118
140
|
let bitMapSize = (rows + (1 << 3) - 1) >> 3;
|
|
119
141
|
// whole raw block ArrayBuffer
|
|
120
|
-
let dataBuffer = blocks.data.slice(bufferOffset);
|
|
142
|
+
// let dataBuffer = blocks.data.slice(bufferOffset);
|
|
143
|
+
let headOffset = blocks.data.byteOffset + bufferOffset;
|
|
144
|
+
let dataView = new DataView(blocks.data.buffer, headOffset);
|
|
121
145
|
// record the head of column in block
|
|
122
146
|
let colBlockHead = 0;
|
|
123
147
|
for (let i = 0; i < rows; i++) {
|
|
@@ -128,41 +152,42 @@ function parseBlock(rows, blocks, taosResult) {
|
|
|
128
152
|
let colDataHead = colBlockHead;
|
|
129
153
|
// traverse row after row.
|
|
130
154
|
for (let j = 0; j < metaList.length; j++) {
|
|
131
|
-
let isVarType = _isVarType(metaList[j]);
|
|
155
|
+
let isVarType = _isVarType(metaList[j].type);
|
|
132
156
|
if (isVarType == constant_1.ColumnsBlockType.SOLID) {
|
|
133
157
|
colDataHead = colBlockHead + bitMapSize + metaList[j].length * i;
|
|
134
158
|
let byteArrayIndex = i >> 3;
|
|
135
159
|
let bitwiseOffset = 7 - (i & 7);
|
|
136
|
-
let bitMapArr = dataBuffer.slice(colBlockHead, colBlockHead + bitMapSize)
|
|
137
|
-
let
|
|
160
|
+
// let bitMapArr = dataBuffer.slice(colBlockHead, colBlockHead + bitMapSize)
|
|
161
|
+
let bitMapArr = new DataView(dataView.buffer, dataView.byteOffset + colBlockHead, bitMapSize);
|
|
162
|
+
let bitFlag = (bitMapArr.getUint8(byteArrayIndex) & (1 << bitwiseOffset)) >> bitwiseOffset;
|
|
138
163
|
if (bitFlag == 1) {
|
|
139
164
|
row.push("NULL");
|
|
140
165
|
}
|
|
141
166
|
else {
|
|
142
|
-
row.push(readSolidData(
|
|
167
|
+
row.push(readSolidData(dataView, colDataHead, metaList[j]));
|
|
143
168
|
}
|
|
144
|
-
colBlockHead = colBlockHead + bitMapSize + (
|
|
169
|
+
colBlockHead = colBlockHead + bitMapSize + dataView.getInt32(INT_32_SIZE * j, true);
|
|
145
170
|
}
|
|
146
171
|
else {
|
|
147
172
|
// if null check
|
|
148
|
-
let varOffset =
|
|
173
|
+
let varOffset = dataView.getInt32(colBlockHead + (INT_32_SIZE * i), true);
|
|
149
174
|
if (varOffset == -1) {
|
|
150
175
|
row.push("NULL");
|
|
151
|
-
colBlockHead = colBlockHead + INT_32_SIZE * rows + (
|
|
176
|
+
colBlockHead = colBlockHead + INT_32_SIZE * rows + dataView.getInt32(j * INT_32_SIZE, true);
|
|
152
177
|
}
|
|
153
178
|
else {
|
|
154
179
|
colDataHead = colBlockHead + INT_32_SIZE * rows + varOffset;
|
|
155
|
-
let dataLength =
|
|
180
|
+
let dataLength = dataView.getInt16(colDataHead, true);
|
|
156
181
|
if (isVarType == constant_1.ColumnsBlockType.VARCHAR) {
|
|
157
|
-
row.push(readVarchar(
|
|
182
|
+
row.push(readVarchar(dataView.buffer, dataView.byteOffset + colDataHead + 2, dataLength, textDecoder));
|
|
158
183
|
}
|
|
159
184
|
else if (isVarType == constant_1.ColumnsBlockType.GEOMETRY || isVarType == constant_1.ColumnsBlockType.VARBINARY) {
|
|
160
|
-
row.push(readBinary(
|
|
185
|
+
row.push(readBinary(dataView.buffer, dataView.byteOffset + colDataHead + 2, dataLength));
|
|
161
186
|
}
|
|
162
187
|
else {
|
|
163
|
-
row.push(readNchar(
|
|
188
|
+
row.push(readNchar(dataView.buffer, dataView.byteOffset + colDataHead + 2, dataLength));
|
|
164
189
|
}
|
|
165
|
-
colBlockHead = colBlockHead + INT_32_SIZE * rows + (
|
|
190
|
+
colBlockHead = colBlockHead + INT_32_SIZE * rows + dataView.getInt32(j * INT_32_SIZE, true);
|
|
166
191
|
}
|
|
167
192
|
}
|
|
168
193
|
}
|
|
@@ -175,25 +200,25 @@ function parseBlock(rows, blocks, taosResult) {
|
|
|
175
200
|
}
|
|
176
201
|
}
|
|
177
202
|
exports.parseBlock = parseBlock;
|
|
178
|
-
function _isVarType(
|
|
179
|
-
switch (
|
|
180
|
-
case constant_1.TDengineTypeCode
|
|
203
|
+
function _isVarType(metaType) {
|
|
204
|
+
switch (metaType) {
|
|
205
|
+
case constant_1.TDengineTypeCode.NCHAR: {
|
|
181
206
|
return constant_1.ColumnsBlockType['NCHAR'];
|
|
182
207
|
}
|
|
183
|
-
case constant_1.TDengineTypeCode
|
|
208
|
+
case constant_1.TDengineTypeCode.VARCHAR: {
|
|
184
209
|
return constant_1.ColumnsBlockType['VARCHAR'];
|
|
185
210
|
}
|
|
186
|
-
case constant_1.TDengineTypeCode
|
|
211
|
+
case constant_1.TDengineTypeCode.BINARY: {
|
|
187
212
|
return constant_1.ColumnsBlockType['VARCHAR'];
|
|
188
213
|
}
|
|
189
|
-
case constant_1.TDengineTypeCode
|
|
214
|
+
case constant_1.TDengineTypeCode.JSON: {
|
|
190
215
|
return constant_1.ColumnsBlockType['VARCHAR'];
|
|
191
216
|
}
|
|
192
|
-
case constant_1.TDengineTypeCode
|
|
217
|
+
case constant_1.TDengineTypeCode.GEOMETRY: {
|
|
193
218
|
return constant_1.ColumnsBlockType['GEOMETRY'];
|
|
194
219
|
}
|
|
195
|
-
case constant_1.TDengineTypeCode
|
|
196
|
-
return constant_1.ColumnsBlockType
|
|
220
|
+
case constant_1.TDengineTypeCode.VARBINARY: {
|
|
221
|
+
return constant_1.ColumnsBlockType.VARBINARY;
|
|
197
222
|
}
|
|
198
223
|
default: {
|
|
199
224
|
return constant_1.ColumnsBlockType['SOLID'];
|
|
@@ -201,13 +226,12 @@ function _isVarType(meta) {
|
|
|
201
226
|
}
|
|
202
227
|
}
|
|
203
228
|
exports._isVarType = _isVarType;
|
|
204
|
-
function readSolidDataToArray(
|
|
205
|
-
let dataBuffer = new DataView(buffer);
|
|
229
|
+
function readSolidDataToArray(dataBuffer, colBlockHead, rows, metaType, bitMapArr) {
|
|
206
230
|
let result = [];
|
|
207
|
-
switch (
|
|
208
|
-
case constant_1.TDengineTypeCode
|
|
209
|
-
case constant_1.TDengineTypeCode
|
|
210
|
-
case constant_1.TDengineTypeCode
|
|
231
|
+
switch (metaType) {
|
|
232
|
+
case constant_1.TDengineTypeCode.BOOL:
|
|
233
|
+
case constant_1.TDengineTypeCode.TINYINT:
|
|
234
|
+
case constant_1.TDengineTypeCode.TINYINT_UNSIGNED: {
|
|
211
235
|
for (let i = 0; i < rows; i++, colBlockHead++) {
|
|
212
236
|
if (isNull(bitMapArr, i)) {
|
|
213
237
|
result.push(null);
|
|
@@ -218,7 +242,7 @@ function readSolidDataToArray(buffer, colBlockHead, rows, meta, bitMapArr) {
|
|
|
218
242
|
}
|
|
219
243
|
break;
|
|
220
244
|
}
|
|
221
|
-
case constant_1.TDengineTypeCode
|
|
245
|
+
case constant_1.TDengineTypeCode.SMALLINT: {
|
|
222
246
|
for (let i = 0; i < rows; i++, colBlockHead += 2) {
|
|
223
247
|
if (isNull(bitMapArr, i)) {
|
|
224
248
|
result.push(null);
|
|
@@ -229,7 +253,7 @@ function readSolidDataToArray(buffer, colBlockHead, rows, meta, bitMapArr) {
|
|
|
229
253
|
}
|
|
230
254
|
break;
|
|
231
255
|
}
|
|
232
|
-
case constant_1.TDengineTypeCode
|
|
256
|
+
case constant_1.TDengineTypeCode.INT: {
|
|
233
257
|
for (let i = 0; i < rows; i++, colBlockHead += 4) {
|
|
234
258
|
if (isNull(bitMapArr, i)) {
|
|
235
259
|
result.push(null);
|
|
@@ -240,7 +264,7 @@ function readSolidDataToArray(buffer, colBlockHead, rows, meta, bitMapArr) {
|
|
|
240
264
|
}
|
|
241
265
|
break;
|
|
242
266
|
}
|
|
243
|
-
case constant_1.TDengineTypeCode
|
|
267
|
+
case constant_1.TDengineTypeCode.BIGINT: {
|
|
244
268
|
for (let i = 0; i < rows; i++, colBlockHead += 8) {
|
|
245
269
|
if (isNull(bitMapArr, i)) {
|
|
246
270
|
result.push(null);
|
|
@@ -251,7 +275,7 @@ function readSolidDataToArray(buffer, colBlockHead, rows, meta, bitMapArr) {
|
|
|
251
275
|
}
|
|
252
276
|
break;
|
|
253
277
|
}
|
|
254
|
-
case constant_1.TDengineTypeCode
|
|
278
|
+
case constant_1.TDengineTypeCode.SMALLINT_UNSIGNED: {
|
|
255
279
|
for (let i = 0; i < rows; i++, colBlockHead += 2) {
|
|
256
280
|
if (isNull(bitMapArr, i)) {
|
|
257
281
|
result.push(null);
|
|
@@ -262,7 +286,7 @@ function readSolidDataToArray(buffer, colBlockHead, rows, meta, bitMapArr) {
|
|
|
262
286
|
}
|
|
263
287
|
break;
|
|
264
288
|
}
|
|
265
|
-
case constant_1.TDengineTypeCode
|
|
289
|
+
case constant_1.TDengineTypeCode.INT_UNSIGNED: {
|
|
266
290
|
for (let i = 0; i < rows; i++, colBlockHead += 4) {
|
|
267
291
|
if (isNull(bitMapArr, i)) {
|
|
268
292
|
result.push(null);
|
|
@@ -273,7 +297,7 @@ function readSolidDataToArray(buffer, colBlockHead, rows, meta, bitMapArr) {
|
|
|
273
297
|
}
|
|
274
298
|
break;
|
|
275
299
|
}
|
|
276
|
-
case constant_1.TDengineTypeCode
|
|
300
|
+
case constant_1.TDengineTypeCode.BIGINT_UNSIGNED: {
|
|
277
301
|
for (let i = 0; i < rows; i++, colBlockHead += 8) {
|
|
278
302
|
if (isNull(bitMapArr, i)) {
|
|
279
303
|
result.push(null);
|
|
@@ -284,7 +308,7 @@ function readSolidDataToArray(buffer, colBlockHead, rows, meta, bitMapArr) {
|
|
|
284
308
|
}
|
|
285
309
|
break;
|
|
286
310
|
}
|
|
287
|
-
case constant_1.TDengineTypeCode
|
|
311
|
+
case constant_1.TDengineTypeCode.FLOAT: {
|
|
288
312
|
for (let i = 0; i < rows; i++, colBlockHead += 4) {
|
|
289
313
|
if (isNull(bitMapArr, i)) {
|
|
290
314
|
result.push(null);
|
|
@@ -295,7 +319,7 @@ function readSolidDataToArray(buffer, colBlockHead, rows, meta, bitMapArr) {
|
|
|
295
319
|
}
|
|
296
320
|
break;
|
|
297
321
|
}
|
|
298
|
-
case constant_1.TDengineTypeCode
|
|
322
|
+
case constant_1.TDengineTypeCode.DOUBLE: {
|
|
299
323
|
for (let i = 0; i < rows; i++, colBlockHead += 8) {
|
|
300
324
|
if (isNull(bitMapArr, i)) {
|
|
301
325
|
result.push(null);
|
|
@@ -306,7 +330,7 @@ function readSolidDataToArray(buffer, colBlockHead, rows, meta, bitMapArr) {
|
|
|
306
330
|
}
|
|
307
331
|
break;
|
|
308
332
|
}
|
|
309
|
-
case constant_1.TDengineTypeCode
|
|
333
|
+
case constant_1.TDengineTypeCode.TIMESTAMP: {
|
|
310
334
|
for (let i = 0; i < rows; i++, colBlockHead += 8) {
|
|
311
335
|
if (isNull(bitMapArr, i)) {
|
|
312
336
|
result.push(null);
|
|
@@ -318,7 +342,7 @@ function readSolidDataToArray(buffer, colBlockHead, rows, meta, bitMapArr) {
|
|
|
318
342
|
break;
|
|
319
343
|
}
|
|
320
344
|
default: {
|
|
321
|
-
throw new wsError_1.WebSocketQueryInterFaceError(wsError_1.ErrorCode.ERR_UNSUPPORTED_TDENGINE_TYPE, `unspported type ${
|
|
345
|
+
throw new wsError_1.WebSocketQueryInterFaceError(wsError_1.ErrorCode.ERR_UNSUPPORTED_TDENGINE_TYPE, `unspported type ${metaType}`);
|
|
322
346
|
}
|
|
323
347
|
}
|
|
324
348
|
return result;
|
|
@@ -326,41 +350,41 @@ function readSolidDataToArray(buffer, colBlockHead, rows, meta, bitMapArr) {
|
|
|
326
350
|
exports.readSolidDataToArray = readSolidDataToArray;
|
|
327
351
|
function readSolidData(dataBuffer, colDataHead, meta) {
|
|
328
352
|
switch (meta.type) {
|
|
329
|
-
case constant_1.TDengineTypeCode
|
|
330
|
-
return (Boolean)(
|
|
353
|
+
case constant_1.TDengineTypeCode.BOOL: {
|
|
354
|
+
return (Boolean)(dataBuffer.getInt8(colDataHead));
|
|
331
355
|
}
|
|
332
|
-
case constant_1.TDengineTypeCode
|
|
333
|
-
return
|
|
356
|
+
case constant_1.TDengineTypeCode.TINYINT: {
|
|
357
|
+
return dataBuffer.getInt8(colDataHead);
|
|
334
358
|
}
|
|
335
|
-
case constant_1.TDengineTypeCode
|
|
336
|
-
return
|
|
359
|
+
case constant_1.TDengineTypeCode.SMALLINT: {
|
|
360
|
+
return dataBuffer.getInt16(colDataHead, true);
|
|
337
361
|
}
|
|
338
|
-
case constant_1.TDengineTypeCode
|
|
339
|
-
return
|
|
362
|
+
case constant_1.TDengineTypeCode.INT: {
|
|
363
|
+
return dataBuffer.getInt32(colDataHead, true);
|
|
340
364
|
}
|
|
341
|
-
case constant_1.TDengineTypeCode
|
|
342
|
-
return
|
|
365
|
+
case constant_1.TDengineTypeCode.BIGINT: {
|
|
366
|
+
return dataBuffer.getBigInt64(colDataHead, true);
|
|
343
367
|
}
|
|
344
|
-
case constant_1.TDengineTypeCode
|
|
345
|
-
return
|
|
368
|
+
case constant_1.TDengineTypeCode.TINYINT_UNSIGNED: {
|
|
369
|
+
return dataBuffer.getUint8(colDataHead);
|
|
346
370
|
}
|
|
347
|
-
case constant_1.TDengineTypeCode
|
|
348
|
-
return
|
|
371
|
+
case constant_1.TDengineTypeCode.SMALLINT_UNSIGNED: {
|
|
372
|
+
return dataBuffer.getUint16(colDataHead, true);
|
|
349
373
|
}
|
|
350
|
-
case constant_1.TDengineTypeCode
|
|
351
|
-
return
|
|
374
|
+
case constant_1.TDengineTypeCode.INT_UNSIGNED: {
|
|
375
|
+
return dataBuffer.getUint32(colDataHead, true);
|
|
352
376
|
}
|
|
353
|
-
case constant_1.TDengineTypeCode
|
|
354
|
-
return
|
|
377
|
+
case constant_1.TDengineTypeCode.BIGINT_UNSIGNED: {
|
|
378
|
+
return dataBuffer.getBigUint64(colDataHead, true);
|
|
355
379
|
}
|
|
356
|
-
case constant_1.TDengineTypeCode
|
|
357
|
-
return
|
|
380
|
+
case constant_1.TDengineTypeCode.FLOAT: {
|
|
381
|
+
return parseFloat(dataBuffer.getFloat32(colDataHead, true).toFixed(5));
|
|
358
382
|
}
|
|
359
|
-
case constant_1.TDengineTypeCode
|
|
360
|
-
return
|
|
383
|
+
case constant_1.TDengineTypeCode.DOUBLE: {
|
|
384
|
+
return parseFloat(dataBuffer.getFloat64(colDataHead, true).toFixed(15));
|
|
361
385
|
}
|
|
362
|
-
case constant_1.TDengineTypeCode
|
|
363
|
-
return
|
|
386
|
+
case constant_1.TDengineTypeCode.TIMESTAMP: {
|
|
387
|
+
return dataBuffer.getBigInt64(colDataHead, true);
|
|
364
388
|
// could change
|
|
365
389
|
}
|
|
366
390
|
default: {
|
|
@@ -374,22 +398,28 @@ function readBinary(dataBuffer, colDataHead, length) {
|
|
|
374
398
|
return buff;
|
|
375
399
|
}
|
|
376
400
|
exports.readBinary = readBinary;
|
|
377
|
-
function readVarchar(dataBuffer, colDataHead, length) {
|
|
378
|
-
let
|
|
379
|
-
let
|
|
380
|
-
|
|
381
|
-
return data;
|
|
401
|
+
function readVarchar(dataBuffer, colDataHead, length, textDecoder) {
|
|
402
|
+
// let buff = dataBuffer.slice(colDataHead, colDataHead + length)
|
|
403
|
+
let dataView = new DataView(dataBuffer, colDataHead, length);
|
|
404
|
+
return textDecoder.decode(dataView);
|
|
382
405
|
}
|
|
383
406
|
exports.readVarchar = readVarchar;
|
|
384
407
|
function readNchar(dataBuffer, colDataHead, length) {
|
|
385
|
-
let data =
|
|
386
|
-
let buff = dataBuffer.slice(colDataHead, colDataHead + length);
|
|
408
|
+
let data = [];
|
|
409
|
+
// let buff: ArrayBuffer = dataBuffer.slice(colDataHead, colDataHead + length);
|
|
410
|
+
let dataView = new DataView(dataBuffer, colDataHead, length);
|
|
387
411
|
for (let i = 0; i < length / 4; i++) {
|
|
388
|
-
data
|
|
412
|
+
data.push((0, ut8Helper_1.appendRune)(dataView.getUint32(i * 4, true)));
|
|
389
413
|
}
|
|
390
|
-
return data;
|
|
414
|
+
return data.join('');
|
|
391
415
|
}
|
|
392
416
|
exports.readNchar = readNchar;
|
|
417
|
+
function getString(dataBuffer, colDataHead, length, textDecoder) {
|
|
418
|
+
// let buff = dataBuffer.slice(colDataHead, colDataHead + length - 1)
|
|
419
|
+
let dataView = new Uint8Array(dataBuffer.buffer, dataBuffer.byteOffset + colDataHead, length - 1);
|
|
420
|
+
return textDecoder.decode(dataView);
|
|
421
|
+
}
|
|
422
|
+
exports.getString = getString;
|
|
393
423
|
function iteratorBuff(arr) {
|
|
394
424
|
let buf = Buffer.from(arr);
|
|
395
425
|
for (const value of buf) {
|
|
@@ -2,4 +2,6 @@ import { WSConfig } from "./config";
|
|
|
2
2
|
export declare function getUrl(wsConfig: WSConfig): URL;
|
|
3
3
|
export declare function sleep(ms: number): Promise<void>;
|
|
4
4
|
export declare function isEmpty(value: any): boolean;
|
|
5
|
+
export declare function getBinarySql(action: bigint, reqId: bigint, resultId: bigint, sql?: string): ArrayBuffer;
|
|
6
|
+
export declare function zigzagDecode(n: number): number;
|
|
5
7
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/common/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,wBAAgB,MAAM,CAAC,QAAQ,EAAC,QAAQ,GAAE,GAAG,CAe5C;AAED,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAGD,wBAAgB,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAM3C"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/common/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,wBAAgB,MAAM,CAAC,QAAQ,EAAC,QAAQ,GAAE,GAAG,CAe5C;AAED,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAGD,wBAAgB,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAM3C;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAC,MAAM,EAAE,KAAK,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAM,EAAE,GAAG,CAAC,EAAC,MAAM,GAAG,WAAW,CA6BnG;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE9C"}
|
package/lib/src/common/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isEmpty = exports.sleep = exports.getUrl = void 0;
|
|
3
|
+
exports.zigzagDecode = exports.getBinarySql = exports.isEmpty = exports.sleep = exports.getUrl = void 0;
|
|
4
4
|
function getUrl(wsConfig) {
|
|
5
5
|
let url = new URL(wsConfig.getUrl());
|
|
6
6
|
if (wsConfig.getUser()) {
|
|
@@ -31,3 +31,36 @@ function isEmpty(value) {
|
|
|
31
31
|
return false;
|
|
32
32
|
}
|
|
33
33
|
exports.isEmpty = isEmpty;
|
|
34
|
+
function getBinarySql(action, reqId, resultId, sql) {
|
|
35
|
+
// construct msg
|
|
36
|
+
if (sql) {
|
|
37
|
+
const encoder = new TextEncoder();
|
|
38
|
+
const buffer = encoder.encode(sql);
|
|
39
|
+
let messageLen = 30 + buffer.length;
|
|
40
|
+
let sqlBuffer = new ArrayBuffer(messageLen);
|
|
41
|
+
let sqlView = new DataView(sqlBuffer);
|
|
42
|
+
sqlView.setBigUint64(0, reqId, true);
|
|
43
|
+
sqlView.setBigInt64(8, resultId, true);
|
|
44
|
+
sqlView.setBigInt64(16, action, true);
|
|
45
|
+
sqlView.setInt16(24, 1, true);
|
|
46
|
+
sqlView.setInt32(26, buffer.length, true);
|
|
47
|
+
let offset = 30;
|
|
48
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
49
|
+
sqlView.setUint8(offset + i, buffer[i]);
|
|
50
|
+
}
|
|
51
|
+
return sqlBuffer;
|
|
52
|
+
}
|
|
53
|
+
let messageLen = 26;
|
|
54
|
+
let sqlBuffer = new ArrayBuffer(messageLen);
|
|
55
|
+
let sqlView = new DataView(sqlBuffer);
|
|
56
|
+
sqlView.setBigUint64(0, reqId, true);
|
|
57
|
+
sqlView.setBigInt64(8, resultId, true);
|
|
58
|
+
sqlView.setBigInt64(16, action, true);
|
|
59
|
+
sqlView.setInt16(24, 1, true);
|
|
60
|
+
return sqlBuffer;
|
|
61
|
+
}
|
|
62
|
+
exports.getBinarySql = getBinarySql;
|
|
63
|
+
function zigzagDecode(n) {
|
|
64
|
+
return (n >> 1) ^ (-(n & 1));
|
|
65
|
+
}
|
|
66
|
+
exports.zigzagDecode = zigzagDecode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsRows.d.ts","sourceRoot":"","sources":["../../../src/sql/wsRows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"wsRows.d.ts","sourceRoot":"","sources":["../../../src/sql/wsRows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0B,MAAM,sBAAsB,CAAC;AAE5E,OAAO,EAAwB,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAM9C,qBAAa,MAAM;IACf,OAAO,CAAC,SAAS,CAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAkB;IACnD,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,QAAQ,CAAW;gBAEf,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,eAAe;IAOlD,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;YAoBhB,YAAY;IA4B1B,OAAO,IAAG,KAAK,CAAC,YAAY,CAAC,GAAG,IAAI;IAIpC,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS;IAc3B,KAAK,IAAG,OAAO,CAAC,IAAI,CAAC;CAQ9B"}
|
package/lib/src/sql/wsRows.js
CHANGED
|
@@ -6,7 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.WSRows = void 0;
|
|
7
7
|
const taosResult_1 = require("../common/taosResult");
|
|
8
8
|
const wsError_1 = require("../common/wsError");
|
|
9
|
+
const wsResponse_1 = require("../client/wsResponse");
|
|
9
10
|
const log_1 = __importDefault(require("../common/log"));
|
|
11
|
+
const reqid_1 = require("../common/reqid");
|
|
12
|
+
const utils_1 = require("../common/utils");
|
|
13
|
+
const constant_1 = require("../common/constant");
|
|
10
14
|
class WSRows {
|
|
11
15
|
constructor(wsInterface, resp) {
|
|
12
16
|
this._wsClient = wsInterface;
|
|
@@ -33,15 +37,22 @@ class WSRows {
|
|
|
33
37
|
}
|
|
34
38
|
async getBlockData() {
|
|
35
39
|
try {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
this.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
if (this._wsQueryResponse.id) {
|
|
41
|
+
let bigintReqId = BigInt(reqid_1.ReqId.getReqID());
|
|
42
|
+
let resp = await this._wsClient.sendBinaryMsg(bigintReqId, "binary_query", (0, utils_1.getBinarySql)(constant_1.FetchRawBlockMessage, bigintReqId, BigInt(this._wsQueryResponse.id)), false, true);
|
|
43
|
+
this._taosResult.addTotalTime(resp.totalTime);
|
|
44
|
+
let wsResponse = new wsResponse_1.WSFetchBlockResponse(resp.msg);
|
|
45
|
+
if (wsResponse.code != 0) {
|
|
46
|
+
log_1.default.error("Executing SQL statement returns error: ", wsResponse.code, wsResponse.message);
|
|
47
|
+
throw new wsError_1.TaosResultError(wsResponse.code, wsResponse.message);
|
|
48
|
+
}
|
|
49
|
+
if (wsResponse.finished == 1) {
|
|
50
|
+
this.close();
|
|
51
|
+
this._taosResult.setData(null);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
(0, taosResult_1.parseBlock)(wsResponse, this._taosResult);
|
|
55
|
+
}
|
|
45
56
|
}
|
|
46
57
|
return this._taosResult;
|
|
47
58
|
}
|
|
@@ -70,7 +81,7 @@ class WSRows {
|
|
|
70
81
|
return;
|
|
71
82
|
}
|
|
72
83
|
this._isClose = true;
|
|
73
|
-
|
|
84
|
+
this._wsClient.freeResult(this._wsQueryResponse);
|
|
74
85
|
}
|
|
75
86
|
}
|
|
76
87
|
exports.WSRows = WSRows;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsSql.d.ts","sourceRoot":"","sources":["../../../src/sql/wsSql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,
|
|
1
|
+
{"version":3,"file":"wsSql.d.ts","sourceRoot":"","sources":["../../../src/sql/wsSql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAc,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAG7D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAG3C,OAAO,EAAE,SAAS,EAAyB,eAAe,EAAE,MAAM,WAAW,CAAA;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAKvC,qBAAa,KAAK;IACd,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,SAAS,CAAW;gBAChB,QAAQ,EAAC,QAAQ;WAMhB,IAAI,CAAC,QAAQ,EAAC,QAAQ,GAAE,OAAO,CAAC,KAAK,CAAC;IAmBnD,KAAK;IAIL;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAI1B,KAAK,IAAG,OAAO,CAAC,IAAI,CAAC;IAIrB,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BnI,QAAQ,CAAC,KAAK,CAAC,EAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAuBxC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,GAAC,MAAuB,GAAG,OAAO,CAAC,UAAU,CAAC;YA4C9E,uBAAuB;IAa/B,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAWxD,OAAO,CAAC,MAAM;CAajB"}
|
package/lib/src/sql/wsSql.js
CHANGED
|
@@ -9,6 +9,7 @@ const taosResult_1 = require("../common/taosResult");
|
|
|
9
9
|
const wsClient_1 = require("../client/wsClient");
|
|
10
10
|
const wsError_1 = require("../common/wsError");
|
|
11
11
|
const utils_1 = require("../common/utils");
|
|
12
|
+
const wsResponse_1 = require("../client/wsResponse");
|
|
12
13
|
const wsStmt_1 = require("../stmt/wsStmt");
|
|
13
14
|
const reqid_1 = require("../common/reqid");
|
|
14
15
|
const constant_1 = require("../common/constant");
|
|
@@ -93,33 +94,41 @@ class WsSql {
|
|
|
93
94
|
}
|
|
94
95
|
throw (new wsError_1.TDWebSocketClientError(wsError_1.ErrorCode.ERR_CONNECTION_CLOSED, "stmt connect closed"));
|
|
95
96
|
}
|
|
96
|
-
async exec(sql, reqId, action = '
|
|
97
|
+
async exec(sql, reqId, action = 'binary_query') {
|
|
97
98
|
try {
|
|
98
|
-
let
|
|
99
|
+
let bigintReqId = BigInt(reqid_1.ReqId.getReqID(reqId));
|
|
100
|
+
let wsQueryResponse = await this._wsClient.sendBinaryMsg(bigintReqId, action, (0, utils_1.getBinarySql)(constant_1.BinaryQueryMessage, bigintReqId, BigInt(0), sql));
|
|
99
101
|
let taosResult = new taosResult_1.TaosResult(wsQueryResponse);
|
|
100
102
|
if (wsQueryResponse.is_update) {
|
|
101
103
|
return taosResult;
|
|
102
104
|
}
|
|
103
105
|
else {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
106
|
+
if (wsQueryResponse.id) {
|
|
107
|
+
try {
|
|
108
|
+
while (true) {
|
|
109
|
+
let bigintReqId = BigInt(reqid_1.ReqId.getReqID(reqId));
|
|
110
|
+
let resp = await this._wsClient.sendBinaryMsg(bigintReqId, action, (0, utils_1.getBinarySql)(constant_1.FetchRawBlockMessage, bigintReqId, BigInt(wsQueryResponse.id)), false, true);
|
|
111
|
+
taosResult.addTotalTime(resp.totalTime);
|
|
112
|
+
let wsResponse = new wsResponse_1.WSFetchBlockResponse(resp.msg);
|
|
113
|
+
if (wsResponse.code != 0) {
|
|
114
|
+
log_1.default.error("Executing SQL statement returns error: ", wsResponse.code, wsResponse.message);
|
|
115
|
+
throw new wsError_1.TaosResultError(wsResponse.code, wsResponse.message);
|
|
116
|
+
}
|
|
117
|
+
if (wsResponse.finished == 1) {
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
(0, taosResult_1.parseBlock)(wsResponse, taosResult);
|
|
113
121
|
}
|
|
122
|
+
return taosResult;
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
throw new wsError_1.TaosResultError(err.code, err.message);
|
|
126
|
+
}
|
|
127
|
+
finally {
|
|
128
|
+
this._wsClient.freeResult(wsQueryResponse);
|
|
114
129
|
}
|
|
115
|
-
return taosResult;
|
|
116
|
-
}
|
|
117
|
-
catch (err) {
|
|
118
|
-
throw new wsError_1.TaosResultError(err.code, err.message);
|
|
119
|
-
}
|
|
120
|
-
finally {
|
|
121
|
-
this._wsClient.freeResult(wsQueryResponse);
|
|
122
130
|
}
|
|
131
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_FETCH_MESSAGE_DATA, "The result data of the query is incorrect");
|
|
123
132
|
}
|
|
124
133
|
}
|
|
125
134
|
catch (err) {
|
|
@@ -141,7 +150,8 @@ class WsSql {
|
|
|
141
150
|
}
|
|
142
151
|
async query(sql, reqId) {
|
|
143
152
|
try {
|
|
144
|
-
let
|
|
153
|
+
let bigintReqId = BigInt(reqid_1.ReqId.getReqID(reqId));
|
|
154
|
+
let wsQueryResponse = await this._wsClient.sendBinaryMsg(bigintReqId, 'binary_query', (0, utils_1.getBinarySql)(constant_1.BinaryQueryMessage, bigintReqId, BigInt(0), sql));
|
|
145
155
|
return new wsRows_1.WSRows(this._wsClient, wsQueryResponse);
|
|
146
156
|
}
|
|
147
157
|
catch (err) {
|