提交 2b84d450 编写于 作者: L liu0x54

[TD-1001] adapt nodejs connector

上级 d7eafe9c
...@@ -346,7 +346,7 @@ CTaosInterface.prototype.useResult = function useResult(result) { ...@@ -346,7 +346,7 @@ CTaosInterface.prototype.useResult = function useResult(result) {
}) })
} }
} }
return {fields:fields} return fields;
} }
CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) { CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) {
let pblock = ref.ref(ref.ref(ref.NULL)); // equal to our raw data let pblock = ref.ref(ref.ref(ref.NULL)); // equal to our raw data
...@@ -355,7 +355,6 @@ CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) { ...@@ -355,7 +355,6 @@ CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) {
return {block:null, num_of_rows:0}; return {block:null, num_of_rows:0};
} }
var fieldL = this.libtaos.taos_fetch_lengths(result); var fieldL = this.libtaos.taos_fetch_lengths(result);
var numoffields = this.libtaos.taos_field_count(result);
let isMicro = (this.libtaos.taos_result_precision(result) == FieldTypes.C_TIMESTAMP_MICRO); let isMicro = (this.libtaos.taos_result_precision(result) == FieldTypes.C_TIMESTAMP_MICRO);
...@@ -363,26 +362,25 @@ CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) { ...@@ -363,26 +362,25 @@ CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) {
if (ref.isNull(fieldL) == false) { if (ref.isNull(fieldL) == false) {
for (let i = 0; i < numoffields; i ++) { for (let i = 0; i < fields.length; i ++) {
let plen = ref.reinterpret(fieldL, 4, i*4); let plen = ref.reinterpret(fieldL, 4, i*4);
let len = plen.readInt32LE(0); let len = plen.readInt32LE(0);
fieldlens.push(len); fieldlens.push(len);
} }
} }
let blocks = new Array(numoffields); let blocks = new Array(fields.length);
blocks.fill(null); blocks.fill(null);
num_of_rows = Math.abs(num_of_rows); num_of_rows = Math.abs(num_of_rows);
let offset = 0; let offset = 0;
pblock = pblock.deref(); pblock = pblock.deref();
for (let i = 0; i < numoffields; i++) { for (let i = 0; i < fields.length; i++) {
pdata = ref.reinterpret(pblock,8,i*8);
if (!convertFunctions[fields['fields'][i]['type']] ) { pdata = ref.ref(pdata.readPointer());
if (!convertFunctions[fields[i]['type']] ) {
throw new errors.DatabaseError("Invalid data type returned from database"); throw new errors.DatabaseError("Invalid data type returned from database");
} }
blocks[i] = convertFunctions[fields['fields'][i]['type']](pblock, num_of_rows, fieldlens[i], offset, isMicro); blocks[i] = convertFunctions[fields[i]['type']](pdata, 1, fieldlens[i], offset, isMicro);
console.log(blocks[i]);
offset += fields['fields'][i]['bytes'] * num_of_rows;
} }
return {blocks: blocks, num_of_rows:Math.abs(num_of_rows)} return {blocks: blocks, num_of_rows:Math.abs(num_of_rows)}
} }
...@@ -429,9 +427,7 @@ CTaosInterface.prototype.fetch_rows_a = function fetch_rows_a(result, callback, ...@@ -429,9 +427,7 @@ CTaosInterface.prototype.fetch_rows_a = function fetch_rows_a(result, callback,
let asyncCallbackWrapper = function (param2, result2, numOfRows2) { let asyncCallbackWrapper = function (param2, result2, numOfRows2) {
// Data preparation to pass to cursor. Could be bottleneck in query execution callback times. // Data preparation to pass to cursor. Could be bottleneck in query execution callback times.
let row = cti.libtaos.taos_fetch_row(result2); let row = cti.libtaos.taos_fetch_row(result2);
console.log(row);
let fields = cti.fetchFields_a(result2); let fields = cti.fetchFields_a(result2);
let isMicro = (cti.libtaos.taos_result_precision(result2) == FieldTypes.C_TIMESTAMP_MICRO); let isMicro = (cti.libtaos.taos_result_precision(result2) == FieldTypes.C_TIMESTAMP_MICRO);
let blocks = new Array(fields.length); let blocks = new Array(fields.length);
...@@ -446,21 +442,17 @@ CTaosInterface.prototype.fetch_rows_a = function fetch_rows_a(result, callback, ...@@ -446,21 +442,17 @@ CTaosInterface.prototype.fetch_rows_a = function fetch_rows_a(result, callback,
let plen = ref.reinterpret(fieldL, 8, i*8); let plen = ref.reinterpret(fieldL, 8, i*8);
let len = ref.get(plen,0,ref.types.int32); let len = ref.get(plen,0,ref.types.int32);
fieldlens.push(len); fieldlens.push(len);
console.log('11111111111111111111');
console.log(fields.length);
console.log(len);
} }
} }
if (numOfRows2 > 0){ if (numOfRows2 > 0){
for (let i = 0; i < fields.length; i++) { for (let i = 0; i < fields.length; i++) {
if (!convertFunctions[fields[i]['type']] ) { if (!convertFunctions[fields[i]['type']] ) {
throw new errors.DatabaseError("Invalid data type returned from database"); throw new errors.DatabaseError("Invalid data type returned from database");
} }
let prow = ref.reinterpret(row,8,i*8); let prow = ref.reinterpret(row,8,i*8);
//blocks[i] = convertFunctions[fields[i]['type']](ref.get(prow,0,ref.types.void_ptr), numOfRows2, fieldlens[i], 0, isMicro); prow = prow.readPointer();
console.log(prow); prow = ref.ref(prow);
blocks[i] = convertFunctions[fields[i]['type']](ref.readPointer(prow), numOfRows2, fieldlens[i], 0, isMicro); blocks[i] = convertFunctions[fields[i]['type']](prow, 1, fieldlens[i], offset, isMicro);
//offset += fields[i]['bytes'] * numOfRows2; //offset += fields[i]['bytes'] * numOfRows2;
} }
} }
......
...@@ -133,8 +133,6 @@ TDengineCursor.prototype.execute = function execute(operation, options, callback ...@@ -133,8 +133,6 @@ TDengineCursor.prototype.execute = function execute(operation, options, callback
else { else {
this._fields = this._chandle.useResult(this._result); this._fields = this._chandle.useResult(this._result);
this.fields = this._fields; this.fields = this._fields;
console.log('++++++++++++++++++++++++++');
console.log(this._result);
wrapCB(callback); wrapCB(callback);
return this._result; //return a pointer to the result return this._result; //return a pointer to the result
...@@ -205,10 +203,12 @@ TDengineCursor.prototype.fetchall = function fetchall(options, callback) { ...@@ -205,10 +203,12 @@ TDengineCursor.prototype.fetchall = function fetchall(options, callback) {
break; break;
} }
this._rowcount += num_of_rows; this._rowcount += num_of_rows;
let numoffields = this._fields.length;
for (let i = 0; i < num_of_rows; i++) { for (let i = 0; i < num_of_rows; i++) {
data.push([]); data.push([]);
let rowBlock = new Array(this._fields.length);
for (let j = 0; j < this._fields.length; j++) { let rowBlock = new Array(numoffields);
for (let j = 0; j < numoffields; j++) {
rowBlock[j] = block[j][i]; rowBlock[j] = block[j][i];
} }
data[data.length-1] = (rowBlock); data[data.length-1] = (rowBlock);
...@@ -268,7 +268,7 @@ TDengineCursor.prototype.execute_a = function execute_a (operation, options, cal ...@@ -268,7 +268,7 @@ TDengineCursor.prototype.execute_a = function execute_a (operation, options, cal
let fieldCount = cr._chandle.numFields(res2); let fieldCount = cr._chandle.numFields(res2);
if (fieldCount == 0) { if (fieldCount == 0) {
cr._chandle.freeResult(res2); cr._chandle.freeResult(res2);
} }
else { else {
return res2; return res2;
} }
......
...@@ -28,7 +28,7 @@ c1.execute('create table if not exists stabletest (ts timestamp, v1 int, v2 int, ...@@ -28,7 +28,7 @@ c1.execute('create table if not exists stabletest (ts timestamp, v1 int, v2 int,
// Shell Test : The following uses the cursor to imitate the taos shell // Shell Test : The following uses the cursor to imitate the taos shell
// Insert // Insert
for (let i = 0; i < 100; i++) { for (let i = 0; i < 1000; i++) {
let insertData = ["now+" + i + "s", // Timestamp let insertData = ["now+" + i + "s", // Timestamp
parseInt( R(-Math.pow(2,31) + 1 , Math.pow(2,31) - 1) ), // Int parseInt( R(-Math.pow(2,31) + 1 , Math.pow(2,31) - 1) ), // Int
parseInt( R(-Math.pow(2,31) + 1 , Math.pow(2,31) - 1) ), // BigInt parseInt( R(-Math.pow(2,31) + 1 , Math.pow(2,31) - 1) ), // BigInt
...@@ -40,18 +40,18 @@ for (let i = 0; i < 100; i++) { ...@@ -40,18 +40,18 @@ for (let i = 0; i < 100; i++) {
randomBool(), randomBool(),
"\"Nchars\""]; // Bool "\"Nchars\""]; // Bool
c1.execute('insert into td_connector_test.all_types values(' + insertData.join(',') + ' );', {quiet:true}); c1.execute('insert into td_connector_test.all_types values(' + insertData.join(',') + ' );', {quiet:true});
if (i % 10 == 0) { if (i % 100 == 0) {
console.log("Insert # " , i); console.log("Insert # " , i);
} }
} }
// Select // Select
console.log('select * from td_connector_test.all_types limit 3 offset 100;'); console.log('select * from td_connector_test.all_types limit 3 offset 100;');
c1.execute('select * from td_connector_test.all_types limit 1 offset 100;'); c1.execute('select * from td_connector_test.all_types limit 2 offset 100;');
var d = c1.fetchall(); var d = c1.fetchall();
console.log(c1.fields); console.log(c1.fields);
console.log(d); console.log(d);
/*
// Functions // Functions
console.log('select count(*), avg(_int), sum(_float), max(_bigint), min(_double) from td_connector_test.all_types;') console.log('select count(*), avg(_int), sum(_float), max(_bigint), min(_double) from td_connector_test.all_types;')
c1.execute('select count(*), avg(_int), sum(_float), max(_bigint), min(_double) from td_connector_test.all_types;'); c1.execute('select count(*), avg(_int), sum(_float), max(_bigint), min(_double) from td_connector_test.all_types;');
...@@ -61,12 +61,14 @@ console.log(d); ...@@ -61,12 +61,14 @@ console.log(d);
// Immediate Execution like the Shell // Immediate Execution like the Shell
c1.query('select count(*), stddev(_double), min(_tinyint) from all_types where _tinyint > 50 and _int < 0;', true).then(function(result){ //c1.query('select count(*), stddev(_double), min(_tinyint) from all_types where _tinyint > 50 and _int < 0;', true).then(function(result){
result.pretty(); // result.pretty();
}) //})
c1.query('select _tinyint, _bool from all_types where _tinyint > 50 and _int < 0 limit 50;', true).then(function(result){ c1.query('select _tinyint, _bool from all_types where _tinyint > 50 and _int < 0 limit 50;', true).then(function(result){
result.pretty(); result.pretty();
}) })
c1.query('select stddev(_double), stddev(_bigint), stddev(_float) from all_types;', true).then(function(result){ c1.query('select stddev(_double), stddev(_bigint), stddev(_float) from all_types;', true).then(function(result){
result.pretty(); result.pretty();
}) })
...@@ -136,4 +138,3 @@ setTimeout(function(){ ...@@ -136,4 +138,3 @@ setTimeout(function(){
c1.query('drop database td_connector_test;'); c1.query('drop database td_connector_test;');
},2000); },2000);
conn.close(); conn.close();
*/
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册