diff --git a/Jenkinsfile b/Jenkinsfile index 4a584fbb35973cc1da82c235f0f47bebe3c50ca2..91855a92fb811a7380ea9dca75745d21386f8496 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -235,18 +235,11 @@ pipeline { npm install td2.0-connector > /dev/null 2>&1 node nodejsChecker.js host=localhost node test1970.js - cd ${WKC}/tests/connectorTest/nodejsTest/nanosupport - npm install td2.0-connector > /dev/null 2>&1 - node nanosecondTest.js - ''' sh ''' cd ${WKC}/tests/examples/C#/taosdemo mcs -out:taosdemo *.cs > /dev/null 2>&1 echo '' |./taosdemo -c /etc/taos - cd ${WKC}/tests/connectorTest/C#Test/nanosupport - mcs -out:nano *.cs > /dev/null 2>&1 - echo '' |./nano ''' sh ''' cd ${WKC}/tests/gotest diff --git a/tests/connectorTest/C#Test/nanosupport/TDengineDriver.cs b/tests/connectorTest/C#Test/nanosupport/TDengineDriver.cs deleted file mode 100644 index e6c3a598adc0bc4bcf5ea84953f649b418199555..0000000000000000000000000000000000000000 --- a/tests/connectorTest/C#Test/nanosupport/TDengineDriver.cs +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; - -namespace TDengineDriver -{ - enum TDengineDataType - { - TSDB_DATA_TYPE_NULL = 0, // 1 bytes - TSDB_DATA_TYPE_BOOL = 1, // 1 bytes - TSDB_DATA_TYPE_TINYINT = 2, // 1 bytes - TSDB_DATA_TYPE_SMALLINT = 3, // 2 bytes - TSDB_DATA_TYPE_INT = 4, // 4 bytes - TSDB_DATA_TYPE_BIGINT = 5, // 8 bytes - TSDB_DATA_TYPE_FLOAT = 6, // 4 bytes - TSDB_DATA_TYPE_DOUBLE = 7, // 8 bytes - TSDB_DATA_TYPE_BINARY = 8, // string - TSDB_DATA_TYPE_TIMESTAMP = 9,// 8 bytes - TSDB_DATA_TYPE_NCHAR = 10, // unicode string - TSDB_DATA_TYPE_UTINYINT = 11,// 1 byte - TSDB_DATA_TYPE_USMALLINT= 12,// 2 bytes - TSDB_DATA_TYPE_UINT = 13, // 4 bytes - TSDB_DATA_TYPE_UBIGINT= 14 // 8 bytes - } - - enum TDengineInitOption - { - TSDB_OPTION_LOCALE = 0, - TSDB_OPTION_CHARSET = 1, - TSDB_OPTION_TIMEZONE = 2, - TDDB_OPTION_CONFIGDIR = 3, - TDDB_OPTION_SHELL_ACTIVITY_TIMER = 4 - } - - class TDengineMeta - { - public string name; - public short size; - public byte type; - public string TypeName() - { - switch ((TDengineDataType)type) - { - case TDengineDataType.TSDB_DATA_TYPE_BOOL: - return "BOOL"; - case TDengineDataType.TSDB_DATA_TYPE_TINYINT: - return "TINYINT"; - case TDengineDataType.TSDB_DATA_TYPE_SMALLINT: - return "SMALLINT"; - case TDengineDataType.TSDB_DATA_TYPE_INT: - return "INT"; - case TDengineDataType.TSDB_DATA_TYPE_BIGINT: - return "BIGINT"; - case TDengineDataType.TSDB_DATA_TYPE_UTINYINT: - return "TINYINT UNSIGNED"; - case TDengineDataType.TSDB_DATA_TYPE_USMALLINT: - return "SMALLINT UNSIGNED"; - case TDengineDataType.TSDB_DATA_TYPE_UINT: - return "INT UNSIGNED"; - case TDengineDataType.TSDB_DATA_TYPE_UBIGINT: - return "BIGINT UNSIGNED"; - case TDengineDataType.TSDB_DATA_TYPE_FLOAT: - return "FLOAT"; - case TDengineDataType.TSDB_DATA_TYPE_DOUBLE: - return "DOUBLE"; - case TDengineDataType.TSDB_DATA_TYPE_BINARY: - return "STRING"; - case TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP: - return "TIMESTAMP"; - case TDengineDataType.TSDB_DATA_TYPE_NCHAR: - return "NCHAR"; - default: - return "undefine"; - } - } - } - - class TDengine - { - public const int TSDB_CODE_SUCCESS = 0; - - [DllImport("taos", EntryPoint = "taos_init", CallingConvention = CallingConvention.Cdecl)] - static extern public void Init(); - - [DllImport("taos", EntryPoint = "taos_cleanup", CallingConvention = CallingConvention.Cdecl)] - static extern public void Cleanup(); - - [DllImport("taos", EntryPoint = "taos_options", CallingConvention = CallingConvention.Cdecl)] - static extern public void Options(int option, string value); - - [DllImport("taos", EntryPoint = "taos_connect", CallingConvention = CallingConvention.Cdecl)] - static extern public IntPtr Connect(string ip, string user, string password, string db, short port); - - [DllImport("taos", EntryPoint = "taos_errstr", CallingConvention = CallingConvention.Cdecl)] - static extern private IntPtr taos_errstr(IntPtr res); - static public string Error(IntPtr res) - { - IntPtr errPtr = taos_errstr(res); - return Marshal.PtrToStringAnsi(errPtr); - } - - [DllImport("taos", EntryPoint = "taos_errno", CallingConvention = CallingConvention.Cdecl)] - static extern public int ErrorNo(IntPtr res); - - [DllImport("taos", EntryPoint = "taos_query", CallingConvention = CallingConvention.Cdecl)] - static extern public IntPtr Query(IntPtr conn, string sqlstr); - - [DllImport("taos", EntryPoint = "taos_affected_rows", CallingConvention = CallingConvention.Cdecl)] - static extern public int AffectRows(IntPtr res); - - [DllImport("taos", EntryPoint = "taos_field_count", CallingConvention = CallingConvention.Cdecl)] - static extern public int FieldCount(IntPtr res); - - [DllImport("taos", EntryPoint = "taos_fetch_fields", CallingConvention = CallingConvention.Cdecl)] - static extern private IntPtr taos_fetch_fields(IntPtr res); - static public List FetchFields(IntPtr res) - { - const int fieldSize = 68; - - List metas = new List(); - if (res == IntPtr.Zero) - { - return metas; - } - - int fieldCount = FieldCount(res); - IntPtr fieldsPtr = taos_fetch_fields(res); - - for (int i = 0; i < fieldCount; ++i) - { - int offset = i * fieldSize; - - TDengineMeta meta = new TDengineMeta(); - meta.name = Marshal.PtrToStringAnsi(fieldsPtr + offset); - meta.type = Marshal.ReadByte(fieldsPtr + offset + 65); - meta.size = Marshal.ReadInt16(fieldsPtr + offset + 66); - metas.Add(meta); - } - - return metas; - } - - [DllImport("taos", EntryPoint = "taos_fetch_row", CallingConvention = CallingConvention.Cdecl)] - static extern public IntPtr FetchRows(IntPtr res); - - [DllImport("taos", EntryPoint = "taos_free_result", CallingConvention = CallingConvention.Cdecl)] - static extern public IntPtr FreeResult(IntPtr res); - - [DllImport("taos", EntryPoint = "taos_close", CallingConvention = CallingConvention.Cdecl)] - static extern public int Close(IntPtr taos); - //get precisionin parameter restultset - [DllImport("taos", EntryPoint = "taos_result_precision", CallingConvention = CallingConvention.Cdecl)] - static extern public int ResultPrecision(IntPtr taos); - } -} diff --git a/tests/connectorTest/C#Test/nanosupport/nanotest.cs b/tests/connectorTest/C#Test/nanosupport/nanotest.cs deleted file mode 100644 index b9eaefef8c740f8196a715282c8c28ffd79bbdac..0000000000000000000000000000000000000000 --- a/tests/connectorTest/C#Test/nanosupport/nanotest.cs +++ /dev/null @@ -1,502 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -using System; -using System.Text; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Collections; -namespace TDengineDriver -{ - class TDengineNanoTest - { - //connect parameters - private string host="localhost"; - private string configDir="/etc/taos"; - private string user="root"; - private string password="taosdata"; - private short port = 0; - - //sql parameters - private string dbName; - private string tbName; - private string precision; - - private bool isInsertData; - private bool isQueryData; - - private long tableCount; - private long totalRows; - private long batchRows; - private long beginTimestamp = 1551369600000L; - - private IntPtr conn = IntPtr.Zero; - private long rowsInserted = 0; - - static void Main(string[] args) - { - TDengineNanoTest tester = new TDengineNanoTest(); - //tester.ReadArgument(args); - - tester.InitTDengine(); - tester.ConnectTDengine(); - tester.execute("reset query cache"); - tester.execute("drop database if exists db"); - tester.execute("create database db precision 'ns'"); - tester.executeQuery("show databases;"); - //tester.checkData(0,16,"ns"); - tester.execute("use db"); - - Console.WriteLine("testing nanosecond support in 1st timestamp"); - tester.execute("create table tb (ts timestamp, speed int)"); - tester.execute("insert into tb values('2021-06-10 0:00:00.100000001', 1);"); - tester.execute("insert into tb values(1623254400150000000, 2);"); - tester.execute("import into tb values(1623254400300000000, 3);"); - tester.execute("import into tb values(1623254400299999999, 4);"); - tester.execute("insert into tb values(1623254400300000001, 5);"); - tester.execute("insert into tb values(1623254400999999999, 7);"); - tester.executeQuery("select * from tb;"); - - Console.WriteLine("expect data is "); - - tester.executeQuery("select * from tb;"); - - // Console.WriteLine("expected is : {0}", width); - // tdSql.checkData(0,0,"2021-06-10 0:00:00.100000001"); - // tdSql.checkData(1,0,"2021-06-10 0:00:00.150000000"); - // tdSql.checkData(2,0,"2021-06-10 0:00:00.299999999"); - // tdSql.checkData(3,1,3); - // tdSql.checkData(4,1,5); - // tdSql.checkData(5,1,7); - // tdSql.checkRows(6); - - tester.executeQuery("select count(*) from tb where ts > 1623254400100000000 and ts < 1623254400100000002;"); - Console.WriteLine("expected is : 1 " ); - tester.executeQuery("select count(*) from tb where ts > '2021-06-10 0:00:00.100000001' and ts < '2021-06-10 0:00:00.160000000';"); - Console.WriteLine("expected is : 1 " ); - - tester.executeQuery("select count(*) from tb where ts > 1623254400100000000 and ts < 1623254400150000000;"); - Console.WriteLine("expected is : 1 " ); - tester.executeQuery("select count(*) from tb where ts > '2021-06-10 0:00:00.100000000' and ts < '2021-06-10 0:00:00.150000000';"); - Console.WriteLine("expected is : 1 " ); - - tester.executeQuery("select count(*) from tb where ts > 1623254400400000000;"); - Console.WriteLine("expected is : 1 " ); - tester.executeQuery("select count(*) from tb where ts < '2021-06-10 00:00:00.400000000';"); - Console.WriteLine("expected is : 5 " ); - - tester.executeQuery("select count(*) from tb where ts > now + 400000000b;"); - Console.WriteLine("expected is : 0 " ); - - tester.executeQuery("select count(*) from tb where ts >= '2021-06-10 0:00:00.100000001';"); - Console.WriteLine("expected is : 6 " ); - - tester.executeQuery("select count(*) from tb where ts <= 1623254400300000000;"); - Console.WriteLine("expected is : 4 " ); - - tester.executeQuery("select count(*) from tb where ts = '2021-06-10 0:00:00.000000000';"); - Console.WriteLine("expected is : 0 " ); - - tester.executeQuery("select count(*) from tb where ts = 1623254400150000000;"); - Console.WriteLine("expected is : 1 " ); - - tester.executeQuery("select count(*) from tb where ts = '2021-06-10 0:00:00.100000001';"); - Console.WriteLine("expected is : 1 " ); - - tester.executeQuery("select count(*) from tb where ts between 1623254400000000000 and 1623254400400000000;"); - Console.WriteLine("expected is : 5 " ); - - tester.executeQuery("select count(*) from tb where ts between '2021-06-10 0:00:00.299999999' and '2021-06-10 0:00:00.300000001';"); - Console.WriteLine("expected is : 3 " ); - - tester.executeQuery("select avg(speed) from tb interval(5000000000b);"); - Console.WriteLine("expected is : 1 " ); - - tester.executeQuery("select avg(speed) from tb interval(100000000b)"); - Console.WriteLine("expected is : 4 " ); - - // tdSql.error("select avg(speed) from tb interval(1b);") - // tdSql.error("select avg(speed) from tb interval(999b);") - - tester.executeQuery("select avg(speed) from tb interval(1000b);"); - Console.WriteLine("expected is : 5 rows " ); - - tester.executeQuery("select avg(speed) from tb interval(1u);"); - Console.WriteLine("expected is : 5 rows " ); - - tester.executeQuery("select avg(speed) from tb interval(100000000b) sliding (100000000b);"); - Console.WriteLine("expected is : 4 rows " ); - - tester.executeQuery("select last(*) from tb"); - Console.WriteLine("expected is :1623254400999999999 " ); - - // tdSql.checkData(0,0, "2021-06-10 0:00:00.999999999") - // tdSql.checkData(0,0, 1623254400999999999) - - tester.executeQuery("select first(*) from tb"); - Console.WriteLine("expected is : 1623254400100000001" ); - // tdSql.checkData(0,0, 1623254400100000001); - // tdSql.checkData(0,0, "2021-06-10 0:00:00.100000001"); - - tester.execute("insert into tb values(now + 500000000b, 6);"); - tester.executeQuery("select * from tb;"); - // tdSql.checkRows(7); - - tester.execute("create table tb2 (ts timestamp, speed int, ts2 timestamp);"); - tester.execute("insert into tb2 values('2021-06-10 0:00:00.100000001', 1, '2021-06-11 0:00:00.100000001');"); - tester.execute("insert into tb2 values(1623254400150000000, 2, 1623340800150000000);"); - tester.execute("import into tb2 values(1623254400300000000, 3, 1623340800300000000);"); - tester.execute("import into tb2 values(1623254400299999999, 4, 1623340800299999999);"); - tester.execute("insert into tb2 values(1623254400300000001, 5, 1623340800300000001);"); - tester.execute("insert into tb2 values(1623254400999999999, 7, 1623513600999999999);"); - - tester.executeQuery("select * from tb2;"); - // tdSql.checkData(0,0,"2021-06-10 0:00:00.100000001"); - // tdSql.checkData(1,0,"2021-06-10 0:00:00.150000000"); - // tdSql.checkData(2,1,4); - // tdSql.checkData(3,1,3); - // tdSql.checkData(4,2,"2021-06-11 00:00:00.300000001"); - // tdSql.checkData(5,2,"2021-06-13 00:00:00.999999999"); - // tdSql.checkRows(6); - tester.executeQuery("select count(*) from tb2 where ts2 > 1623340800000000000 and ts2 < 1623340800150000000;"); - Console.WriteLine("expected is : 1 " ); - // tdSql.checkData(0,0,1); - - tester.executeQuery("select count(*) from tb2 where ts2 > '2021-06-11 0:00:00.100000000' and ts2 < '2021-06-11 0:00:00.100000002';"); - Console.WriteLine("expected is : 1 " ); - // tdSql.checkData(0,0,1); - - tester.executeQuery("select count(*) from tb2 where ts2 > 1623340800500000000;"); - Console.WriteLine("expected is : 1 " ); - // tdSql.checkData(0,0,1); - tester.executeQuery("select count(*) from tb2 where ts2 < '2021-06-11 0:00:00.400000000';"); - Console.WriteLine("expected is : 5 " ); - // tdSql.checkData(0,0,5); - - tester.executeQuery("select count(*) from tb2 where ts2 > now + 400000000b;"); - Console.WriteLine("expected is : 0 " ); - // tdSql.checkRows(0); - - tester.executeQuery("select count(*) from tb2 where ts2 >= '2021-06-11 0:00:00.100000001';"); - Console.WriteLine("expected is : 6 " ); - // tdSql.checkData(0,0,6); - - tester.executeQuery("select count(*) from tb2 where ts2 <= 1623340800400000000;"); - Console.WriteLine("expected is : 5 " ); - // tdSql.checkData(0,0,5); - - tester.executeQuery("select count(*) from tb2 where ts2 = '2021-06-11 0:00:00.000000000';"); - Console.WriteLine("expected is : 0 " ); - // tdSql.checkRows(0); - - tester.executeQuery("select count(*) from tb2 where ts2 = '2021-06-11 0:00:00.300000001';"); - Console.WriteLine("expected is : 1 " ); - // tdSql.checkData(0,0,1); - - tester.executeQuery("select count(*) from tb2 where ts2 = 1623340800300000001;"); - Console.WriteLine("expected is : 1 " ); - // tdSql.checkData(0,0,1); - - tester.executeQuery("select count(*) from tb2 where ts2 between 1623340800000000000 and 1623340800450000000;"); - Console.WriteLine("expected is : 5 " ); - // tdSql.checkData(0,0,5); - - tester.executeQuery("select count(*) from tb2 where ts2 between '2021-06-11 0:00:00.299999999' and '2021-06-11 0:00:00.300000001';"); - Console.WriteLine("expected is : 3 " ); - // tdSql.checkData(0,0,3); - - tester.executeQuery("select count(*) from tb2 where ts2 <> 1623513600999999999;"); - Console.WriteLine("expected is : 5 " ); - // tdSql.checkData(0,0,5); - - tester.executeQuery("select count(*) from tb2 where ts2 <> '2021-06-11 0:00:00.100000001';"); - Console.WriteLine("expected is : 5 " ); - // tdSql.checkData(0,0,5); - - tester.executeQuery("select count(*) from tb2 where ts2 <> '2021-06-11 0:00:00.100000000';"); - Console.WriteLine("expected is : 6 " ); - // tdSql.checkData(0,0,6); - - tester.executeQuery("select count(*) from tb2 where ts2 != 1623513600999999999;"); - Console.WriteLine("expected is : 5 " ); - // tdSql.checkData(0,0,5); - - tester.executeQuery("select count(*) from tb2 where ts2 != '2021-06-11 0:00:00.100000001';"); - Console.WriteLine("expected is : 5 " ); - // tdSql.checkData(0,0,5); - - tester.executeQuery("select count(*) from tb2 where ts2 != '2021-06-11 0:00:00.100000000';"); - Console.WriteLine("expected is : 6 " ); - // tdSql.checkData(0,0,6); - - tester.execute("insert into tb2 values(now + 500000000b, 6, now +2d);"); - tester.executeQuery("select * from tb2;"); - Console.WriteLine("expected is : 7 rows" ); - // tdSql.checkRows(7); - - // tdLog.debug("testing ill nanosecond format handling"); - tester.execute("create table tb3 (ts timestamp, speed int);"); - // tdSql.error("insert into tb3 values(16232544001500000, 2);"); - tester.execute("insert into tb3 values('2021-06-10 0:00:00.123456', 2);"); - tester.executeQuery("select * from tb3 where ts = '2021-06-10 0:00:00.123456000';"); - // tdSql.checkRows(1); - Console.WriteLine("expected is : 1 rows " ); - - tester.execute("insert into tb3 values('2021-06-10 0:00:00.123456789000', 2);"); - tester.executeQuery("select * from tb3 where ts = '2021-06-10 0:00:00.123456789';"); - // tdSql.checkRows(1); - Console.WriteLine("expected is : 1 rows " ); - - // check timezone support - Console.WriteLine("nsdb" ); - tester.execute("drop database if exists nsdb;"); - tester.execute("create database nsdb precision 'ns';"); - tester.execute("use nsdb;"); - tester.execute("create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);"); - tester.execute("insert into tb1 using st tags('2021-06-10 0:00:00.123456789' , 1 ) values('2021-06-10T0:00:00.123456789+07:00' , 1.0);" ); - tester.executeQuery("select first(*) from tb1;"); - Console.WriteLine("expected is : 1623258000123456789 " ); - // tdSql.checkData(0,0,1623258000123456789); - - - - Console.WriteLine("usdb" ); - tester.execute("create database usdb precision 'us';"); - tester.execute("use usdb;"); - tester.execute("create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);"); - tester.execute("insert into tb1 using st tags('2021-06-10 0:00:00.123456' , 1 ) values('2021-06-10T0:00:00.123456+07:00' , 1.0);" ); - tester.executeQuery("select first(*) from tb1;"); - - Console.WriteLine("expected is : 1623258000123456 " ); - - Console.WriteLine("msdb" ); - tester.execute("drop database if exists msdb;"); - tester.execute("create database msdb precision 'ms';"); - tester.execute("use msdb;"); - tester.execute("create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);"); - tester.execute("insert into tb1 using st tags('2021-06-10 0:00:00.123' , 1 ) values('2021-06-10T0:00:00.123+07:00' , 1.0);" ); - tester.executeQuery("select first(*) from tb1;"); - Console.WriteLine("expected is : 1623258000123 " ); - - - - tester.CloseConnection(); - tester.cleanup(); - - - } - - public void InitTDengine() - { - TDengine.Options((int)TDengineInitOption.TDDB_OPTION_CONFIGDIR, this.configDir); - TDengine.Options((int)TDengineInitOption.TDDB_OPTION_SHELL_ACTIVITY_TIMER, "60"); - Console.WriteLine("init..."); - TDengine.Init(); - Console.WriteLine("get connection starting..."); - } - - public void ConnectTDengine() - { - string db = ""; - this.conn = TDengine.Connect(this.host, this.user, this.password, db, this.port); - if (this.conn == IntPtr.Zero) - { - Console.WriteLine("connection failed: " + this.host); - ExitProgram(); - } - else - { - Console.WriteLine("[ OK ] Connection established."); - } - } - //EXECUTE SQL - public void execute(string sql) - { - DateTime dt1 = DateTime.Now; - IntPtr res = TDengine.Query(this.conn, sql.ToString()); - DateTime dt2 = DateTime.Now; - TimeSpan span = dt2 - dt1; - - if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0)) - { - Console.Write(sql.ToString() + " failure, "); - if (res != IntPtr.Zero) { - Console.Write("reason: " + TDengine.Error(res)); - } - Console.WriteLine(""); - ExitProgram(); - } - else - { - Console.WriteLine(sql.ToString() + " success"); - } - TDengine.FreeResult(res); - } - //EXECUTE QUERY - public void executeQuery(string sql) - { - - DateTime dt1 = DateTime.Now; - long queryRows = 0; - IntPtr res = TDengine.Query(conn, sql); - getPrecision(res); - if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0)) - { - Console.Write(sql.ToString() + " failure, "); - if (res != IntPtr.Zero) { - Console.Write("reason: " + TDengine.Error(res)); - } - Console.WriteLine(""); - ExitProgram(); - } - DateTime dt2 = DateTime.Now; - TimeSpan span = dt2 - dt1; - Console.WriteLine("[OK] time cost: " + span.ToString() + "ms, execute statement ====> " + sql.ToString()); - int fieldCount = TDengine.FieldCount(res); - - List metas = TDengine.FetchFields(res); - for (int j = 0; j < metas.Count; j++) - { - TDengineMeta meta = (TDengineMeta)metas[j]; - } - - IntPtr rowdata; - StringBuilder builder = new StringBuilder(); - while ((rowdata = TDengine.FetchRows(res)) != IntPtr.Zero) - { - queryRows++; - for (int fields = 0; fields < fieldCount; ++fields) - { - TDengineMeta meta = metas[fields]; - int offset = IntPtr.Size * fields; - IntPtr data = Marshal.ReadIntPtr(rowdata, offset); - - builder.Append("---"); - - if (data == IntPtr.Zero) - { - builder.Append("NULL"); - continue; - } - - switch ((TDengineDataType)meta.type) - { - case TDengineDataType.TSDB_DATA_TYPE_BOOL: - bool v1 = Marshal.ReadByte(data) == 0 ? false : true; - builder.Append(v1); - break; - case TDengineDataType.TSDB_DATA_TYPE_TINYINT: - byte v2 = Marshal.ReadByte(data); - builder.Append(v2); - break; - case TDengineDataType.TSDB_DATA_TYPE_SMALLINT: - short v3 = Marshal.ReadInt16(data); - builder.Append(v3); - break; - case TDengineDataType.TSDB_DATA_TYPE_INT: - int v4 = Marshal.ReadInt32(data); - builder.Append(v4); - break; - case TDengineDataType.TSDB_DATA_TYPE_BIGINT: - long v5 = Marshal.ReadInt64(data); - builder.Append(v5); - break; - case TDengineDataType.TSDB_DATA_TYPE_FLOAT: - float v6 = (float)Marshal.PtrToStructure(data, typeof(float)); - builder.Append(v6); - break; - case TDengineDataType.TSDB_DATA_TYPE_DOUBLE: - double v7 = (double)Marshal.PtrToStructure(data, typeof(double)); - builder.Append(v7); - break; - case TDengineDataType.TSDB_DATA_TYPE_BINARY: - string v8 = Marshal.PtrToStringAnsi(data); - builder.Append(v8); - break; - case TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP: - long v9 = Marshal.ReadInt64(data); - builder.Append(v9); - break; - case TDengineDataType.TSDB_DATA_TYPE_NCHAR: - string v10 = Marshal.PtrToStringAnsi(data); - builder.Append(v10); - break; - } - } - builder.Append("---"); - - if (queryRows <= 10) - { - Console.WriteLine(builder.ToString()); - } - builder.Clear(); - } - - if (TDengine.ErrorNo(res) != 0) - { - Console.Write("Query is not complete, Error {0:G}", TDengine.ErrorNo(res), TDengine.Error(res)); - } - Console.WriteLine(""); - - TDengine.FreeResult(res); - - } - - public void CloseConnection() - { - if (this.conn != IntPtr.Zero) - { - TDengine.Close(this.conn); - Console.WriteLine("connection closed."); - } - } - - static void ExitProgram() - { - System.Environment.Exit(0); - } - - public void cleanup() - { - Console.WriteLine("clean up..."); - System.Environment.Exit(0); - } - - // method to get db precision - public void getPrecision(IntPtr res) - { - int psc=TDengine.ResultPrecision(res); - switch(psc) - { - case 0: - Console.WriteLine("db:[{0:G}]'s precision is {1:G}",this.dbName,"millisecond"); - break; - case 1: - Console.WriteLine("db:[{0:G}]'s precision is {1:G}",this.dbName,"microsecond"); - break; - case 2: - Console.WriteLine("db:[{0:G}]'s precision is {1:G}",this.dbName,"nanosecond"); - break; - } - - } - - // public void checkData(int x ,int y , long ts ){ - - // } - - } -} - diff --git a/tests/connectorTest/nodejsTest/nanosupport/nanosecondTest.js b/tests/connectorTest/nodejsTest/nanosupport/nanosecondTest.js deleted file mode 100644 index 11812ac84b91d5c639a3b3bd73c8b81838c5cc23..0000000000000000000000000000000000000000 --- a/tests/connectorTest/nodejsTest/nanosupport/nanosecondTest.js +++ /dev/null @@ -1,290 +0,0 @@ -const taos = require('td2.0-connector'); -var conn = taos.connect({host:"localhost", user:"root", password:"taosdata", config:"/etc/taos",port:6030}) -var c1 = conn.cursor(); - - -function checkData(sql,row,col,data){ - - - console.log(sql) - c1.execute(sql) - var d = c1.fetchall(); - let checkdata = d[row][col]; - if (checkdata == data) { - - console.log('check pass') - } - else{ - console.log('check failed') - console.log('checked is :',checkdata) - console.log("expected is :",data) - - - } -} - - -// nano basic case - -c1.execute('reset query cache') -c1.execute('drop database if exists db') -c1.execute('create database db precision "ns";') -c1.execute('use db'); -c1.execute('create table tb (ts timestamp, speed int)') -c1.execute('insert into tb values(\'2021-06-10 00:00:00.100000001\', 1);') -c1.execute('insert into tb values(1623254400150000000, 2);') -c1.execute('import into tb values(1623254400300000000, 3);') -c1.execute('import into tb values(1623254400299999999, 4);') -c1.execute('insert into tb values(1623254400300000001, 5);') -c1.execute('insert into tb values(1623254400999999999, 7);') -c1.execute('insert into tb values(1623254400123456789, 8);') -sql = 'select * from tb;' - -console.log('*******************************************') -console.log('this is area about checkdata result') -//check data about insert data -checkData(sql,0,0,'2021-06-10 00:00:00.100000001') -checkData(sql,1,0,'2021-06-10 00:00:00.123456789') -checkData(sql,2,0,'2021-06-10 00:00:00.150000000') -checkData(sql,3,0,'2021-06-10 00:00:00.299999999') -checkData(sql,4,0,'2021-06-10 00:00:00.300000000') -checkData(sql,5,0,'2021-06-10 00:00:00.300000001') -checkData(sql,6,0,'2021-06-10 00:00:00.999999999') -checkData(sql,0,1,1) -checkData(sql,1,1,8) -checkData(sql,2,1,2) -checkData(sql,5,1,5) - - - -// us basic case - -c1.execute('reset query cache') -c1.execute('drop database if exists usdb') -c1.execute('create database usdb precision "us";') -c1.execute('use usdb'); -c1.execute('create table tb (ts timestamp, speed int)') -c1.execute('insert into tb values(\'2021-06-10 00:00:00.100001\', 1);') -c1.execute('insert into tb values(1623254400150000, 2);') -c1.execute('import into tb values(1623254400300000, 3);') -c1.execute('import into tb values(1623254400299999, 4);') -c1.execute('insert into tb values(1623254400300001, 5);') -c1.execute('insert into tb values(1623254400999999, 7);') -c1.execute('insert into tb values(1623254400123789, 8);') -sql = 'select * from tb;' - -console.log('*******************************************') - -//check data about insert data -checkData(sql,0,0,'2021-06-10 00:00:00.100001') -checkData(sql,1,0,'2021-06-10 00:00:00.123789') -checkData(sql,2,0,'2021-06-10 00:00:00.150000') -checkData(sql,3,0,'2021-06-10 00:00:00.299999') -checkData(sql,4,0,'2021-06-10 00:00:00.300000') -checkData(sql,5,0,'2021-06-10 00:00:00.300001') -checkData(sql,6,0,'2021-06-10 00:00:00.999999') -checkData(sql,0,1,1) -checkData(sql,1,1,8) -checkData(sql,2,1,2) -checkData(sql,5,1,5) - -console.log('*******************************************') - -// ms basic case - -c1.execute('reset query cache') -c1.execute('drop database if exists msdb') -c1.execute('create database msdb precision "ms";') -c1.execute('use msdb'); -c1.execute('create table tb (ts timestamp, speed int)') -c1.execute('insert into tb values(\'2021-06-10 00:00:00.101\', 1);') -c1.execute('insert into tb values(1623254400150, 2);') -c1.execute('import into tb values(1623254400300, 3);') -c1.execute('import into tb values(1623254400299, 4);') -c1.execute('insert into tb values(1623254400301, 5);') -c1.execute('insert into tb values(1623254400789, 7);') -c1.execute('insert into tb values(1623254400999, 8);') -sql = 'select * from tb;' - -console.log('*******************************************') -console.log('this is area about checkdata result') -//check data about insert data -checkData(sql,0,0,'2021-06-10 00:00:00.101') -checkData(sql,1,0,'2021-06-10 00:00:00.150') -checkData(sql,2,0,'2021-06-10 00:00:00.299') -checkData(sql,3,0,'2021-06-10 00:00:00.300') -checkData(sql,4,0,'2021-06-10 00:00:00.301') -checkData(sql,5,0,'2021-06-10 00:00:00.789') -checkData(sql,6,0,'2021-06-10 00:00:00.999') -checkData(sql,0,1,1) -checkData(sql,1,1,2) -checkData(sql,2,1,4) -checkData(sql,5,1,7) - -console.log('*******************************************') - -// offfical query result to show -// console.log('this is area about fetch all data') -// var query = c1.query(sql) -// var promise = query.execute(); -// promise.then(function(result) { -// result.pretty(); -// }); - -console.log('*******************************************') -c1.execute('use db') - -sql2 = 'select count(*) from tb where ts > 1623254400100000000 and ts < 1623254400100000002;' -checkData(sql2,0,0,1) - -sql3 = 'select count(*) from tb where ts > \'2021-06-10 0:00:00.100000001\' and ts < \'2021-06-10 0:00:00.160000000\';' -checkData(sql3,0,0,2) - -sql4 = 'select count(*) from tb where ts > 1623254400100000000 and ts < 1623254400150000000;' -checkData(sql4,0,0,2) - -sql5 = 'select count(*) from tb where ts > \'2021-06-10 0:00:00.100000000\' and ts < \'2021-06-10 0:00:00.150000000\';' -checkData(sql5,0,0,2) - -sql6 = 'select count(*) from tb where ts > 1623254400400000000;' -checkData(sql6,0,0,1) - -sql7 = 'select count(*) from tb where ts < \'2021-06-10 00:00:00.400000000\';' -checkData(sql7,0,0,6) - -sql8 = 'select count(*) from tb where ts > now + 400000000b;' -c1.execute(sql8) - -sql9 = 'select count(*) from tb where ts >= \'2021-06-10 0:00:00.100000001\';' -checkData(sql9,0,0,7) - -sql10 = 'select count(*) from tb where ts <= 1623254400300000000;' -checkData(sql10,0,0,5) - -sql11 = 'select count(*) from tb where ts = \'2021-06-10 0:00:00.000000000\';' -c1.execute(sql11) - -sql12 = 'select count(*) from tb where ts = 1623254400150000000;' -checkData(sql12,0,0,1) - -sql13 = 'select count(*) from tb where ts = \'2021-06-10 0:00:00.100000001\';' -checkData(sql13,0,0,1) - -sql14 = 'select count(*) from tb where ts between 1623254400000000000 and 1623254400400000000;' -checkData(sql14,0,0,6) - -sql15 = 'select count(*) from tb where ts between \'2021-06-10 0:00:00.299999999\' and \'2021-06-10 0:00:00.300000001\';' -checkData(sql15,0,0,3) - -sql16 = 'select avg(speed) from tb interval(5000000000b);' -checkData(sql16,0,0,'2021-06-10 00:00:00.000000000') - -sql17 = 'select avg(speed) from tb interval(100000000b)' -checkData(sql17,0,1,3.6666666666666665) -checkData(sql17,1,1,4.000000000) - -checkData(sql17,2,0,'2021-06-10 00:00:00.300000000') -checkData(sql17,3,0,'2021-06-10 00:00:00.900000000') - -console.log("print break ") - -// sql18 = 'select avg(speed) from tb interval(999b)' -// c1.execute(sql18) - -console.log("print break2 ") -sql19 = 'select avg(speed) from tb interval(1u);' -checkData(sql19,2,1,2.000000000) -checkData(sql19,3,0,'2021-06-10 00:00:00.299999000') - -sql20 = 'select avg(speed) from tb interval(100000000b) sliding (100000000b);' -checkData(sql20,2,1,4.000000000) -checkData(sql20,3,0,'2021-06-10 00:00:00.900000000') - -sql21 = 'select last(*) from tb;' -checkData(sql21,0,0,'2021-06-10 00:00:00.999999999') - -sql22 = 'select first(*) from tb;' -checkData(sql22,0,0,'2021-06-10 00:00:00.100000001') - -// timezone support - -console.log('testing nanosecond support in other timestamps') - -c1.execute('create table tb2 (ts timestamp, speed int, ts2 timestamp);') -c1.execute('insert into tb2 values(\'2021-06-10 0:00:00.100000001\', 1, \'2021-06-11 0:00:00.100000001\');') -c1.execute('insert into tb2 values(1623254400150000000, 2, 1623340800150000000);') -c1.execute('import into tb2 values(1623254400300000000, 3, 1623340800300000000);') -c1.execute('import into tb2 values(1623254400299999999, 4, 1623340800299999999);') -c1.execute('insert into tb2 values(1623254400300000001, 5, 1623340800300000001);') -c1.execute('insert into tb2 values(1623254400999999999, 7, 1623513600999999999);') - -sql23 = 'select * from tb2;' -checkData(sql23,0,0,'2021-06-10 00:00:00.100000001') -checkData(sql23,1,0,'2021-06-10 00:00:00.150000000') -checkData(sql23,2,1,4) -checkData(sql23,3,1,3) -checkData(sql23,4,2,'2021-06-11 00:00:00.300000001') -checkData(sql23,5,2,'2021-06-13 00:00:00.999999999') - -sql24 = 'select count(*) from tb2 where ts2 >= \'2021-06-11 0:00:00.100000001\';' -checkData(sql24,0,0,6) - -sql25 = 'select count(*) from tb2 where ts2 <= 1623340800400000000;' -checkData(sql25,0,0,5) - -sql26 = 'select count(*) from tb2 where ts2 = \'2021-06-11 0:00:00.300000001\';' -checkData(sql26,0,0,1) - -sql27 = 'select count(*) from tb2 where ts2 = 1623340800300000001;' -checkData(sql27,0,0,1) - -sql28 = 'select count(*) from tb2 where ts2 between 1623340800000000000 and 1623340800450000000;' -checkData(sql28,0,0,5) - -sql29 = 'select count(*) from tb2 where ts2 between \'2021-06-11 0:00:00.299999999\' and \'2021-06-11 0:00:00.300000001\';' -checkData(sql29,0,0,3) - -sql30 = 'select count(*) from tb2 where ts2 <> 1623513600999999999;' -checkData(sql30,0,0,5) - -sql31 = 'select count(*) from tb2 where ts2 <> \'2021-06-11 0:00:00.100000001\';' -checkData(sql31,0,0,5) - -sql32 = 'select count(*) from tb2 where ts2 != 1623513600999999999;' -checkData(sql32,0,0,5) - -sql33 = 'select count(*) from tb2 where ts2 != \'2021-06-11 0:00:00.100000001\';' -checkData(sql33,0,0,5) - -c1.execute('insert into tb2 values(now + 500000000b, 6, now +2d);') - -sql34 = 'select count(*) from tb2;' -checkData(sql34,0,0,7) - - -// check timezone support - -c1.execute('use db;') -c1.execute('create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);') -c1.execute('insert into stb1 using st tags("2021-06-10 0:00:00.123456789" , 1 ) values("2021-06-10T0:00:00.123456789+07:00" , 1.0);' ) -sql35 = 'select first(*) from stb1;' -checkData(sql35,0,0,'2021-06-10 01:00:00.123456789') - -c1.execute('use usdb;') -c1.execute('create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);') -c1.execute('insert into stb1 using st tags("2021-06-10 0:00:00.123456" , 1 ) values("2021-06-10T0:00:00.123456+07:00" , 1.0);' ) -sql36 = 'select first(*) from stb1;' -checkData(sql36,0,0,'2021-06-10 01:00:00.123456') - -c1.execute('use msdb;') -c1.execute('create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);') -c1.execute('insert into stb1 using st tags("2021-06-10 0:00:00.123456" , 1 ) values("2021-06-10T0:00:00.123456+07:00" , 1.0);' ) -sql36 = 'select first(*) from stb1;' -checkData(sql36,0,0,'2021-06-10 01:00:00.123') - - - - - - - diff --git a/tests/connectorTest/nodejsTest/nodetaos/cinterface.js b/tests/connectorTest/nodejsTest/nodetaos/cinterface.js deleted file mode 100644 index 03d27e5593ccb15d8ff47cd3c3dedba765d14fc1..0000000000000000000000000000000000000000 --- a/tests/connectorTest/nodejsTest/nodetaos/cinterface.js +++ /dev/null @@ -1,587 +0,0 @@ -/** - * C Interface with TDengine Module - * @module CTaosInterface - */ - -const ref = require('ref-napi'); -const os = require('os'); -const ffi = require('ffi-napi'); -const ArrayType = require('ref-array-napi'); -const Struct = require('ref-struct-napi'); -const FieldTypes = require('./constants'); -const errors = require('./error'); -const TaosObjects = require('./taosobjects'); -const { NULL_POINTER } = require('ref-napi'); - -module.exports = CTaosInterface; - -function convertTimestamp(data, num_of_rows, nbytes = 0, offset = 0, precision = 0) { - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); - let res = []; - let currOffset = 0; - while (currOffset < data.length) { - let time = data.readInt64LE(currOffset); - currOffset += nbytes; - res.push(new TaosObjects.TaosTimestamp(time, precision)); - } - return res; -} -function convertBool(data, num_of_rows, nbytes = 0, offset = 0, precision = 0) { - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); - let res = new Array(data.length); - for (let i = 0; i < data.length; i++) { - if (data[i] == 0) { - res[i] = false; - } - else if (data[i] == 1) { - res[i] = true; - } - else if (data[i] == FieldTypes.C_BOOL_NULL) { - res[i] = null; - } - } - return res; -} -function convertTinyint(data, num_of_rows, nbytes = 0, offset = 0, precision = 0) { - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); - let res = []; - let currOffset = 0; - while (currOffset < data.length) { - let d = data.readIntLE(currOffset, 1); - res.push(d == FieldTypes.C_TINYINT_NULL ? null : d); - currOffset += nbytes; - } - return res; -} -function convertSmallint(data, num_of_rows, nbytes = 0, offset = 0, precision = 0) { - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); - let res = []; - let currOffset = 0; - while (currOffset < data.length) { - let d = data.readIntLE(currOffset, 2); - res.push(d == FieldTypes.C_SMALLINT_NULL ? null : d); - currOffset += nbytes; - } - return res; -} -function convertInt(data, num_of_rows, nbytes = 0, offset = 0, precision = 0) { - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); - let res = []; - let currOffset = 0; - while (currOffset < data.length) { - let d = data.readInt32LE(currOffset); - res.push(d == FieldTypes.C_INT_NULL ? null : d); - currOffset += nbytes; - } - return res; -} -function convertBigint(data, num_of_rows, nbytes = 0, offset = 0, precision = 0) { - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); - let res = []; - let currOffset = 0; - while (currOffset < data.length) { - let d = data.readInt64LE(currOffset); - res.push(d == FieldTypes.C_BIGINT_NULL ? null : BigInt(d)); - currOffset += nbytes; - } - return res; -} -function convertFloat(data, num_of_rows, nbytes = 0, offset = 0, precision = 0) { - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); - let res = []; - let currOffset = 0; - while (currOffset < data.length) { - let d = parseFloat(data.readFloatLE(currOffset).toFixed(5)); - res.push(isNaN(d) ? null : d); - currOffset += nbytes; - } - return res; -} -function convertDouble(data, num_of_rows, nbytes = 0, offset = 0, precision = 0) { - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); - let res = []; - let currOffset = 0; - while (currOffset < data.length) { - let d = parseFloat(data.readDoubleLE(currOffset).toFixed(16)); - res.push(isNaN(d) ? null : d); - currOffset += nbytes; - } - return res; -} - -function convertNchar(data, num_of_rows, nbytes = 0, offset = 0, precision = 0) { - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); - let res = []; - - let currOffset = 0; - while (currOffset < data.length) { - let len = data.readIntLE(currOffset, 2); - let dataEntry = data.slice(currOffset + 2, currOffset + len + 2); //one entry in a row under a column; - res.push(dataEntry.toString("utf-8")); - currOffset += nbytes; - } - return res; -} - -// Object with all the relevant converters from pblock data to javascript readable data -let convertFunctions = { - [FieldTypes.C_BOOL]: convertBool, - [FieldTypes.C_TINYINT]: convertTinyint, - [FieldTypes.C_SMALLINT]: convertSmallint, - [FieldTypes.C_INT]: convertInt, - [FieldTypes.C_BIGINT]: convertBigint, - [FieldTypes.C_FLOAT]: convertFloat, - [FieldTypes.C_DOUBLE]: convertDouble, - [FieldTypes.C_BINARY]: convertNchar, - [FieldTypes.C_TIMESTAMP]: convertTimestamp, - [FieldTypes.C_NCHAR]: convertNchar -} - -// Define TaosField structure -var char_arr = ArrayType(ref.types.char); -var TaosField = Struct({ - 'name': char_arr, -}); -TaosField.fields.name.type.size = 65; -TaosField.defineProperty('type', ref.types.char); -TaosField.defineProperty('bytes', ref.types.short); - - -/** - * - * @param {Object} config - Configuration options for the interface - * @return {CTaosInterface} - * @class CTaosInterface - * @classdesc The CTaosInterface is the interface through which Node.JS communicates data back and forth with TDengine. It is not advised to - * access this class directly and use it unless you understand what these functions do. - */ -function CTaosInterface(config = null, pass = false) { - ref.types.char_ptr = ref.refType(ref.types.char); - ref.types.void_ptr = ref.refType(ref.types.void); - ref.types.void_ptr2 = ref.refType(ref.types.void_ptr); - /*Declare a bunch of functions first*/ - /* Note, pointers to TAOS_RES, TAOS, are ref.types.void_ptr. The connection._conn buffer is supplied for pointers to TAOS * */ - - if ('win32' == os.platform()) { - taoslibname = 'taos'; - } else { - taoslibname = 'libtaos'; - } - this.libtaos = ffi.Library(taoslibname, { - 'taos_options': [ref.types.int, [ref.types.int, ref.types.void_ptr]], - 'taos_init': [ref.types.void, []], - //TAOS *taos_connect(char *ip, char *user, char *pass, char *db, int port) - 'taos_connect': [ref.types.void_ptr, [ref.types.char_ptr, ref.types.char_ptr, ref.types.char_ptr, ref.types.char_ptr, ref.types.int]], - //void taos_close(TAOS *taos) - 'taos_close': [ref.types.void, [ref.types.void_ptr]], - //int *taos_fetch_lengths(TAOS_RES *res); - 'taos_fetch_lengths': [ref.types.void_ptr, [ref.types.void_ptr]], - //int taos_query(TAOS *taos, char *sqlstr) - 'taos_query': [ref.types.void_ptr, [ref.types.void_ptr, ref.types.char_ptr]], - //int taos_affected_rows(TAOS_RES *res) - 'taos_affected_rows': [ref.types.int, [ref.types.void_ptr]], - //int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) - 'taos_fetch_block': [ref.types.int, [ref.types.void_ptr, ref.types.void_ptr]], - //int taos_num_fields(TAOS_RES *res); - 'taos_num_fields': [ref.types.int, [ref.types.void_ptr]], - //TAOS_ROW taos_fetch_row(TAOS_RES *res) - //TAOS_ROW is void **, but we set the return type as a reference instead to get the row - 'taos_fetch_row': [ref.refType(ref.types.void_ptr2), [ref.types.void_ptr]], - 'taos_print_row': [ref.types.int, [ref.types.char_ptr, ref.types.void_ptr, ref.types.void_ptr, ref.types.int]], - //int taos_result_precision(TAOS_RES *res) - 'taos_result_precision': [ref.types.int, [ref.types.void_ptr]], - //void taos_free_result(TAOS_RES *res) - 'taos_free_result': [ref.types.void, [ref.types.void_ptr]], - //int taos_field_count(TAOS *taos) - 'taos_field_count': [ref.types.int, [ref.types.void_ptr]], - //TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) - 'taos_fetch_fields': [ref.refType(TaosField), [ref.types.void_ptr]], - //int taos_errno(TAOS *taos) - 'taos_errno': [ref.types.int, [ref.types.void_ptr]], - //char *taos_errstr(TAOS *taos) - 'taos_errstr': [ref.types.char_ptr, [ref.types.void_ptr]], - //void taos_stop_query(TAOS_RES *res); - 'taos_stop_query': [ref.types.void, [ref.types.void_ptr]], - //char *taos_get_server_info(TAOS *taos); - 'taos_get_server_info': [ref.types.char_ptr, [ref.types.void_ptr]], - //char *taos_get_client_info(); - 'taos_get_client_info': [ref.types.char_ptr, []], - - // ASYNC - // void taos_query_a(TAOS *taos, char *sqlstr, void (*fp)(void *, TAOS_RES *, int), void *param) - 'taos_query_a': [ref.types.void, [ref.types.void_ptr, ref.types.char_ptr, ref.types.void_ptr, ref.types.void_ptr]], - // void taos_fetch_rows_a(TAOS_RES *res, void (*fp)(void *param, TAOS_RES *, int numOfRows), void *param); - 'taos_fetch_rows_a': [ref.types.void, [ref.types.void_ptr, ref.types.void_ptr, ref.types.void_ptr]], - - // Subscription - //TAOS_SUB *taos_subscribe(TAOS* taos, int restart, const char* topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, void *param, int interval) - 'taos_subscribe': [ref.types.void_ptr, [ref.types.void_ptr, ref.types.int, ref.types.char_ptr, ref.types.char_ptr, ref.types.void_ptr, ref.types.void_ptr, ref.types.int]], - // TAOS_RES *taos_consume(TAOS_SUB *tsub) - 'taos_consume': [ref.types.void_ptr, [ref.types.void_ptr]], - //void taos_unsubscribe(TAOS_SUB *tsub); - 'taos_unsubscribe': [ref.types.void, [ref.types.void_ptr]], - - // Continuous Query - //TAOS_STREAM *taos_open_stream(TAOS *taos, char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), - // int64_t stime, void *param, void (*callback)(void *)); - 'taos_open_stream': [ref.types.void_ptr, [ref.types.void_ptr, ref.types.char_ptr, ref.types.void_ptr, ref.types.int64, ref.types.void_ptr, ref.types.void_ptr]], - //void taos_close_stream(TAOS_STREAM *tstr); - 'taos_close_stream': [ref.types.void, [ref.types.void_ptr]] - - }); - if (pass == false) { - if (config == null) { - this._config = ref.alloc(ref.types.char_ptr, ref.NULL); - } - else { - try { - this._config = ref.allocCString(config); - } - catch (err) { - throw "Attribute Error: config is expected as a str"; - } - } - if (config != null) { - this.libtaos.taos_options(3, this._config); - } - this.libtaos.taos_init(); - } - return this; -} -CTaosInterface.prototype.config = function config() { - return this._config; -} -CTaosInterface.prototype.connect = function connect(host = null, user = "root", password = "taosdata", db = null, port = 0) { - let _host, _user, _password, _db, _port; - try { - _host = host != null ? ref.allocCString(host) : ref.NULL; - } - catch (err) { - throw "Attribute Error: host is expected as a str"; - } - try { - _user = ref.allocCString(user) - } - catch (err) { - throw "Attribute Error: user is expected as a str"; - } - try { - _password = ref.allocCString(password); - } - catch (err) { - throw "Attribute Error: password is expected as a str"; - } - try { - _db = db != null ? ref.allocCString(db) : ref.NULL; - } - catch (err) { - throw "Attribute Error: db is expected as a str"; - } - try { - _port = ref.alloc(ref.types.int, port); - } - catch (err) { - throw TypeError("port is expected as an int") - } - let connection = this.libtaos.taos_connect(_host, _user, _password, _db, _port); - if (ref.isNull(connection)) { - throw new errors.TDError('Failed to connect to TDengine'); - } - else { - console.log('Successfully connected to TDengine'); - } - return connection; -} -CTaosInterface.prototype.close = function close(connection) { - this.libtaos.taos_close(connection); - console.log("Connection is closed"); -} -CTaosInterface.prototype.query = function query(connection, sql) { - return this.libtaos.taos_query(connection, ref.allocCString(sql)); -} -CTaosInterface.prototype.affectedRows = function affectedRows(result) { - return this.libtaos.taos_affected_rows(result); -} -CTaosInterface.prototype.useResult = function useResult(result) { - - let fields = []; - let pfields = this.fetchFields(result); - if (ref.isNull(pfields) == false) { - pfields = ref.reinterpret(pfields, this.fieldsCount(result) * 68, 0); - for (let i = 0; i < pfields.length; i += 68) { - //0 - 63 = name //64 - 65 = bytes, 66 - 67 = type - fields.push({ - name: ref.readCString(ref.reinterpret(pfields, 65, i)), - type: pfields[i + 65], - bytes: pfields[i + 66] - }) - } - } - return fields; -} -CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) { - let pblock = ref.NULL_POINTER; - let num_of_rows = this.libtaos.taos_fetch_block(result, pblock); - if (ref.isNull(pblock.deref()) == true) { - return { block: null, num_of_rows: 0 }; - } - - var fieldL = this.libtaos.taos_fetch_lengths(result); - let precision = this.libtaos.taos_result_precision(result); - - var fieldlens = []; - - if (ref.isNull(fieldL) == false) { - for (let i = 0; i < fields.length; i++) { - let plen = ref.reinterpret(fieldL, 4, i * 4); - let len = plen.readInt32LE(0); - fieldlens.push(len); - } - } - - let blocks = new Array(fields.length); - blocks.fill(null); - num_of_rows = Math.abs(num_of_rows); - let offset = 0; - let ptr = pblock.deref(); - - for (let i = 0; i < fields.length; i++) { - pdata = ref.reinterpret(ptr, 8, i * 8); - if (ref.isNull(pdata.readPointer())) { - blocks[i] = new Array(); - } else { - pdata = ref.ref(pdata.readPointer()); - if (!convertFunctions[fields[i]['type']]) { - throw new errors.DatabaseError("Invalid data type returned from database"); - } - blocks[i] = convertFunctions[fields[i]['type']](pdata, num_of_rows, fieldlens[i], offset, precision); - } - } - return { blocks: blocks, num_of_rows } -} -CTaosInterface.prototype.fetchRow = function fetchRow(result, fields) { - let row = this.libtaos.taos_fetch_row(result); - return row; -} -CTaosInterface.prototype.freeResult = function freeResult(result) { - this.libtaos.taos_free_result(result); - result = null; -} -/** Number of fields returned in this result handle, must use with async */ -CTaosInterface.prototype.numFields = function numFields(result) { - return this.libtaos.taos_num_fields(result); -} -// Fetch fields count by connection, the latest query -CTaosInterface.prototype.fieldsCount = function fieldsCount(result) { - return this.libtaos.taos_field_count(result); -} -CTaosInterface.prototype.fetchFields = function fetchFields(result) { - return this.libtaos.taos_fetch_fields(result); -} -CTaosInterface.prototype.errno = function errno(result) { - return this.libtaos.taos_errno(result); -} -CTaosInterface.prototype.errStr = function errStr(result) { - return ref.readCString(this.libtaos.taos_errstr(result)); -} -// Async -CTaosInterface.prototype.query_a = function query_a(connection, sql, callback, param = ref.ref(ref.NULL)) { - // void taos_query_a(TAOS *taos, char *sqlstr, void (*fp)(void *param, TAOS_RES *, int), void *param) - callback = ffi.Callback(ref.types.void, [ref.types.void_ptr, ref.types.void_ptr, ref.types.int], callback); - this.libtaos.taos_query_a(connection, ref.allocCString(sql), callback, param); - return param; -} -/** Asynchrnously fetches the next block of rows. Wraps callback and transfers a 4th argument to the cursor, the row data as blocks in javascript form - * Note: This isn't a recursive function, in order to fetch all data either use the TDengine cursor object, TaosQuery object, or implement a recrusive - * function yourself using the libtaos.taos_fetch_rows_a function - */ -CTaosInterface.prototype.fetch_rows_a = function fetch_rows_a(result, callback, param = ref.ref(ref.NULL)) { - // void taos_fetch_rows_a(TAOS_RES *res, void (*fp)(void *param, TAOS_RES *, int numOfRows), void *param); - var cti = this; - // wrap callback with a function so interface can access the numOfRows value, needed in order to properly process the binary data - let asyncCallbackWrapper = function (param2, result2, numOfRows2) { - // Data preparation to pass to cursor. Could be bottleneck in query execution callback times. - let row = cti.libtaos.taos_fetch_row(result2); - let fields = cti.fetchFields_a(result2); - - let precision = cti.libtaos.taos_result_precision(result2); - let blocks = new Array(fields.length); - blocks.fill(null); - numOfRows2 = Math.abs(numOfRows2); - let offset = 0; - var fieldL = cti.libtaos.taos_fetch_lengths(result); - var fieldlens = []; - if (ref.isNull(fieldL) == false) { - - for (let i = 0; i < fields.length; i++) { - let plen = ref.reinterpret(fieldL, 8, i * 8); - let len = ref.get(plen, 0, ref.types.int32); - fieldlens.push(len); - } - } - if (numOfRows2 > 0) { - for (let i = 0; i < fields.length; i++) { - if (ref.isNull(pdata.readPointer())) { - blocks[i] = new Array(); - } else { - if (!convertFunctions[fields[i]['type']]) { - throw new errors.DatabaseError("Invalid data type returned from database"); - } - let prow = ref.reinterpret(row, 8, i * 8); - prow = prow.readPointer(); - prow = ref.ref(prow); - blocks[i] = convertFunctions[fields[i]['type']](prow, 1, fieldlens[i], offset, precision); - //offset += fields[i]['bytes'] * numOfRows2; - } - } - } - callback(param2, result2, numOfRows2, blocks); - } - asyncCallbackWrapper = ffi.Callback(ref.types.void, [ref.types.void_ptr, ref.types.void_ptr, ref.types.int], asyncCallbackWrapper); - this.libtaos.taos_fetch_rows_a(result, asyncCallbackWrapper, param); - return param; -} -// Fetch field meta data by result handle -CTaosInterface.prototype.fetchFields_a = function fetchFields_a(result) { - let pfields = this.fetchFields(result); - let pfieldscount = this.numFields(result); - let fields = []; - if (ref.isNull(pfields) == false) { - pfields = ref.reinterpret(pfields, 68 * pfieldscount, 0); - for (let i = 0; i < pfields.length; i += 68) { - //0 - 64 = name //65 = type, 66 - 67 = bytes - fields.push({ - name: ref.readCString(ref.reinterpret(pfields, 65, i)), - type: pfields[i + 65], - bytes: pfields[i + 66] - }) - } - } - return fields; -} -// Stop a query by result handle -CTaosInterface.prototype.stopQuery = function stopQuery(result) { - if (result != null) { - this.libtaos.taos_stop_query(result); - } - else { - throw new errors.ProgrammingError("No result handle passed to stop query"); - } -} -CTaosInterface.prototype.getServerInfo = function getServerInfo(connection) { - return ref.readCString(this.libtaos.taos_get_server_info(connection)); -} -CTaosInterface.prototype.getClientInfo = function getClientInfo() { - return ref.readCString(this.libtaos.taos_get_client_info()); -} - -// Subscription -CTaosInterface.prototype.subscribe = function subscribe(connection, restart, topic, sql, interval) { - let topicOrig = topic; - let sqlOrig = sql; - try { - sql = sql != null ? ref.allocCString(sql) : ref.alloc(ref.types.char_ptr, ref.NULL); - } - catch (err) { - throw "Attribute Error: sql is expected as a str"; - } - try { - topic = topic != null ? ref.allocCString(topic) : ref.alloc(ref.types.char_ptr, ref.NULL); - } - catch (err) { - throw TypeError("topic is expected as a str"); - } - - restart = ref.alloc(ref.types.int, restart); - - let subscription = this.libtaos.taos_subscribe(connection, restart, topic, sql, null, null, interval); - if (ref.isNull(subscription)) { - throw new errors.TDError('Failed to subscribe to TDengine | Database: ' + dbOrig + ', Table: ' + tableOrig); - } - else { - console.log('Successfully subscribed to TDengine - Topic: ' + topicOrig); - } - return subscription; -} - -CTaosInterface.prototype.consume = function consume(subscription) { - let result = this.libtaos.taos_consume(subscription); - let fields = []; - let pfields = this.fetchFields(result); - if (ref.isNull(pfields) == false) { - pfields = ref.reinterpret(pfields, this.numFields(result) * 68, 0); - for (let i = 0; i < pfields.length; i += 68) { - //0 - 63 = name //64 - 65 = bytes, 66 - 67 = type - fields.push({ - name: ref.readCString(ref.reinterpret(pfields, 64, i)), - bytes: pfields[i + 64], - type: pfields[i + 66] - }) - } - } - - let data = []; - while (true) { - let { blocks, num_of_rows } = this.fetchBlock(result, fields); - if (num_of_rows == 0) { - break; - } - for (let i = 0; i < num_of_rows; i++) { - data.push([]); - let rowBlock = new Array(fields.length); - for (let j = 0; j < fields.length; j++) { - rowBlock[j] = blocks[j][i]; - } - data[data.length - 1] = (rowBlock); - } - } - return { data: data, fields: fields, result: result }; -} -CTaosInterface.prototype.unsubscribe = function unsubscribe(subscription) { - //void taos_unsubscribe(TAOS_SUB *tsub); - this.libtaos.taos_unsubscribe(subscription); -} - -// Continuous Query -CTaosInterface.prototype.openStream = function openStream(connection, sql, callback, stime, stoppingCallback, param = ref.ref(ref.NULL)) { - try { - sql = ref.allocCString(sql); - } - catch (err) { - throw "Attribute Error: sql string is expected as a str"; - } - var cti = this; - let asyncCallbackWrapper = function (param2, result2, row) { - let fields = cti.fetchFields_a(result2); - let precision = cti.libtaos.taos_result_precision(result2); - let blocks = new Array(fields.length); - blocks.fill(null); - let numOfRows2 = 1; - let offset = 0; - if (numOfRows2 > 0) { - for (let i = 0; i < fields.length; i++) { - if (!convertFunctions[fields[i]['type']]) { - throw new errors.DatabaseError("Invalid data type returned from database"); - } - blocks[i] = convertFunctions[fields[i]['type']](row, numOfRows2, fields[i]['bytes'], offset, precision); - offset += fields[i]['bytes'] * numOfRows2; - } - } - callback(param2, result2, blocks, fields); - } - asyncCallbackWrapper = ffi.Callback(ref.types.void, [ref.types.void_ptr, ref.types.void_ptr, ref.refType(ref.types.void_ptr2)], asyncCallbackWrapper); - asyncStoppingCallbackWrapper = ffi.Callback(ref.types.void, [ref.types.void_ptr], stoppingCallback); - let streamHandle = this.libtaos.taos_open_stream(connection, sql, asyncCallbackWrapper, stime, param, asyncStoppingCallbackWrapper); - if (ref.isNull(streamHandle)) { - throw new errors.TDError('Failed to open a stream with TDengine'); - return false; - } - else { - console.log("Succesfully opened stream"); - return streamHandle; - } -} -CTaosInterface.prototype.closeStream = function closeStream(stream) { - this.libtaos.taos_close_stream(stream); - console.log("Closed stream"); -} diff --git a/tests/connectorTest/nodejsTest/nodetaos/connection.js b/tests/connectorTest/nodejsTest/nodetaos/connection.js deleted file mode 100644 index 08186f87053ad0ed0982ec8941f0cf38c4ad0467..0000000000000000000000000000000000000000 --- a/tests/connectorTest/nodejsTest/nodetaos/connection.js +++ /dev/null @@ -1,84 +0,0 @@ -const TDengineCursor = require('./cursor') -const CTaosInterface = require('./cinterface') -module.exports = TDengineConnection; - -/** - * TDengine Connection Class - * @param {object} options - Options for configuring the connection with TDengine - * @return {TDengineConnection} - * @class TDengineConnection - * @constructor - * @example - * //Initialize a new connection - * var conn = new TDengineConnection({host:"127.0.0.1", user:"root", password:"taosdata", config:"/etc/taos",port:0}) - * - */ -function TDengineConnection(options) { - this._conn = null; - this._host = null; - this._user = "root"; //The default user - this._password = "taosdata"; //The default password - this._database = null; - this._port = 0; - this._config = null; - this._chandle = null; - this._configConn(options) - return this; -} -/** - * Configure the connection to TDengine - * @private - * @memberof TDengineConnection - */ -TDengineConnection.prototype._configConn = function _configConn(options) { - if (options['host']) { - this._host = options['host']; - } - if (options['user']) { - this._user = options['user']; - } - if (options['password']) { - this._password = options['password']; - } - if (options['database']) { - this._database = options['database']; - } - if (options['port']) { - this._port = options['port']; - } - if (options['config']) { - this._config = options['config']; - } - this._chandle = new CTaosInterface(this._config); - this._conn = this._chandle.connect(this._host, this._user, this._password, this._database, this._port); -} -/** Close the connection to TDengine */ -TDengineConnection.prototype.close = function close() { - this._chandle.close(this._conn); -} -/** - * Initialize a new cursor to interact with TDengine with - * @return {TDengineCursor} - */ -TDengineConnection.prototype.cursor = function cursor() { - //Pass the connection object to the cursor - return new TDengineCursor(this); -} -TDengineConnection.prototype.commit = function commit() { - return this; -} -TDengineConnection.prototype.rollback = function rollback() { - return this; -} -/** - * Clear the results from connector - * @private - */ -/* - TDengineConnection.prototype._clearResultSet = function _clearResultSet() { - var result = this._chandle.useResult(this._conn).result; - if (result) { - this._chandle.freeResult(result) - } -} -*/ diff --git a/tests/connectorTest/nodejsTest/nodetaos/constants.js b/tests/connectorTest/nodejsTest/nodetaos/constants.js deleted file mode 100644 index cd6a0c9fbaff51e7f0ecd3ab06907b7b1fb7dcb1..0000000000000000000000000000000000000000 --- a/tests/connectorTest/nodejsTest/nodetaos/constants.js +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Contains the the definitions/values assigned to various field types - * @module FieldTypes - */ -/** - * TDengine Field Types and their type codes - * @typedef {Object} FieldTypes - * @global - * @property {number} C_NULL - Null - * @property {number} C_BOOL - Boolean. Note, 0x02 is the C_BOOL_NULL value. - * @property {number} C_TINYINT - Tiny Int, values in the range [-2^7+1, 2^7-1]. Note, -2^7 has been used as the C_TINYINT_NULL value - * @property {number} C_SMALLINT - Small Int, values in the range [-2^15+1, 2^15-1]. Note, -2^15 has been used as the C_SMALLINT_NULL value - * @property {number} C_INT - Int, values in the range [-2^31+1, 2^31-1]. Note, -2^31 has been used as the C_INT_NULL value - * @property {number} C_BIGINT - Big Int, values in the range [-2^59, 2^59]. - * @property {number} C_FLOAT - Float, values in the range [-3.4E38, 3.4E38], accurate up to 6-7 decimal places. - * @property {number} C_DOUBLE - Double, values in the range [-1.7E308, 1.7E308], accurate up to 15-16 decimal places. - * @property {number} C_BINARY - Binary, encoded in utf-8. - * @property {number} C_TIMESTAMP - Timestamp in format "YYYY:MM:DD HH:MM:SS.MMM". Measured in number of milliseconds passed after - 1970-01-01 08:00:00.000 GMT. - * @property {number} C_NCHAR - NChar field type encoded in ASCII, a wide string. - * - * - * - * @property {number} C_TIMESTAMP_MILLI - The code for millisecond timestamps, as returned by libtaos.taos_result_precision(result). - * @property {number} C_TIMESTAMP_MICRO - The code for microsecond timestamps, as returned by libtaos.taos_result_precision(result). - */ -module.exports = { - C_NULL : 0, - C_BOOL : 1, - C_TINYINT : 2, - C_SMALLINT : 3, - C_INT : 4, - C_BIGINT : 5, - C_FLOAT : 6, - C_DOUBLE : 7, - C_BINARY : 8, - C_TIMESTAMP : 9, - C_NCHAR : 10, - // NULL value definition - // NOTE: These values should change according to C definition in tsdb.h - C_BOOL_NULL : 2, - C_TINYINT_NULL : -128, - C_SMALLINT_NULL : -32768, - C_INT_NULL : -2147483648, - C_BIGINT_NULL : -9223372036854775808, - C_FLOAT_NULL : 2146435072, - C_DOUBLE_NULL : -9223370937343148032, - C_NCHAR_NULL : 4294967295, - C_BINARY_NULL : 255, - C_TIMESTAMP_MILLI : 0, - C_TIMESTAMP_MICRO : 1, - getType, -} - -const typeCodesToName = { - 0 : 'Null', - 1 : 'Boolean', - 2 : 'Tiny Int', - 3 : 'Small Int', - 4 : 'Int', - 5 : 'Big Int', - 6 : 'Float', - 7 : 'Double', - 8 : 'Binary', - 9 : 'Timestamp', - 10 : 'Nchar', -} - -/** - * @function - * @param {number} typecode - The code to get the name of the type for - * @return {string} Name of the field type - */ -function getType(typecode) { - return typeCodesToName[typecode]; -} diff --git a/tests/connectorTest/nodejsTest/nodetaos/cursor.js b/tests/connectorTest/nodejsTest/nodetaos/cursor.js deleted file mode 100644 index f879d89d487eae9290fd9fc70259699f27937928..0000000000000000000000000000000000000000 --- a/tests/connectorTest/nodejsTest/nodetaos/cursor.js +++ /dev/null @@ -1,476 +0,0 @@ -const ref = require('ref-napi'); -require('./globalfunc.js') -const CTaosInterface = require('./cinterface') -const errors = require('./error') -const TaosQuery = require('./taosquery') -const { PerformanceObserver, performance } = require('perf_hooks'); -module.exports = TDengineCursor; - -/** - * @typedef {Object} Buffer - A Node.js buffer. Please refer to {@link https://nodejs.org/api/buffer.html} for more details - * @global - */ - -/** - * @class TDengineCursor - * @classdesc The TDengine Cursor works directly with the C Interface which works with TDengine. It refrains from - * returning parsed data and majority of functions return the raw data such as cursor.fetchall() as compared to the TaosQuery class which - * has functions that "prettify" the data and add more functionality and can be used through cursor.query("your query"). Instead of - * promises, the class and its functions use callbacks. - * @param {TDengineConnection} - The TDengine Connection this cursor uses to interact with TDengine - * @property {data} - Latest retrieved data from query execution. It is an empty array by default - * @property {fields} - Array of the field objects in order from left to right of the latest data retrieved - * @since 1.0.0 - */ -function TDengineCursor(connection = null) { - //All parameters are store for sync queries only. - this._rowcount = -1; - this._connection = null; - this._result = null; - this._fields = null; - this.data = []; - this.fields = null; - if (connection != null) { - this._connection = connection - this._chandle = connection._chandle //pass through, just need library loaded. - } - else { - throw new errors.ProgrammingError("A TDengineConnection object is required to be passed to the TDengineCursor"); - } - -} -/** - * Get the row counts of the latest query - * @since 1.0.0 - * @return {number} Rowcount - */ -TDengineCursor.prototype.rowcount = function rowcount() { - return this._rowcount; -} -/** - * Close the cursor by setting its connection to null and freeing results from the connection and resetting the results it has stored - * @return {boolean} Whether or not the cursor was succesfully closed - * @since 1.0.0 - */ -TDengineCursor.prototype.close = function close() { - if (this._connection == null) { - return false; - } - this._connection._clearResultSet(); - this._reset_result(); - this._connection = null; - return true; -} -/** - * Create a TaosQuery object to perform a query to TDengine and retrieve data. - * @param {string} operation - The operation string to perform a query on - * @param {boolean} execute - Whether or not to immedietely perform the query. Default is false. - * @return {TaosQuery | Promise} A TaosQuery object - * @example - * var query = cursor.query("select count(*) from meterinfo.meters"); - * query.execute(); - * @since 1.0.6 - */ -TDengineCursor.prototype.query = function query(operation, execute = false) { - return new TaosQuery(operation, this, execute); -} - -/** - * Execute a query. Also stores all the field meta data returned from the query into cursor.fields. It is preferable to use cursor.query() to create - * queries and execute them instead of using the cursor object directly. - * @param {string} operation - The query operation to execute in the taos shell - * @param {Object} options - Execution options object. quiet : true turns off logging from queries - * @param {boolean} options.quiet - True if you want to surpress logging such as "Query OK, 1 row(s) ..." - * @param {function} callback - A callback function to execute after the query is made to TDengine - * @return {number | Buffer} Number of affected rows or a Buffer that points to the results of the query - * @since 1.0.0 - */ -TDengineCursor.prototype.execute = function execute(operation, options, callback) { - if (operation == undefined) { - throw new errors.ProgrammingError('No operation passed as argument'); - return null; - } - - if (typeof options == 'function') { - callback = options; - } - if (typeof options != 'object') options = {} - if (this._connection == null) { - throw new errors.ProgrammingError('Cursor is not connected'); - } - - this._reset_result(); - - let stmt = operation; - let time = 0; - let res; - if (options['quiet'] != true) { - const obs = new PerformanceObserver((items) => { - time = items.getEntries()[0].duration; - performance.clearMarks(); - }); - obs.observe({ entryTypes: ['measure'] }); - performance.mark('A'); - this._result = this._chandle.query(this._connection._conn, stmt); - performance.mark('B'); - performance.measure('query', 'A', 'B'); - } - else { - this._result = this._chandle.query(this._connection._conn, stmt); - } - res = this._chandle.errno(this._result); - if (res == 0) { - let fieldCount = this._chandle.fieldsCount(this._result); - if (fieldCount == 0) { - let affectedRowCount = this._chandle.affectedRows(this._result); - let response = this._createAffectedResponse(affectedRowCount, time) - if (options['quiet'] != true) { - console.log(response); - } - wrapCB(callback); - return affectedRowCount; //return num of affected rows, common with insert, use statements - } - else { - this._fields = this._chandle.useResult(this._result); - this.fields = this._fields; - wrapCB(callback); - - return this._result; //return a pointer to the result - } - } - else { - throw new errors.ProgrammingError(this._chandle.errStr(this._result)) - } - -} -TDengineCursor.prototype._createAffectedResponse = function (num, time) { - return "Query OK, " + num + " row(s) affected (" + (time * 0.001).toFixed(8) + "s)"; -} -TDengineCursor.prototype._createSetResponse = function (num, time) { - return "Query OK, " + num + " row(s) in set (" + (time * 0.001).toFixed(8) + "s)"; -} -TDengineCursor.prototype.executemany = function executemany() { - -} -TDengineCursor.prototype.fetchone = function fetchone() { - -} -TDengineCursor.prototype.fetchmany = function fetchmany() { - -} -/** - * Fetches all results from a query and also stores results into cursor.data. It is preferable to use cursor.query() to create - * queries and execute them instead of using the cursor object directly. - * @param {function} callback - callback function executing on the complete fetched data - * @return {Array} The resultant array, with entries corresponding to each retreived row from the query results, sorted in - * order by the field name ordering in the table. - * @since 1.0.0 - * @example - * cursor.execute('select * from db.table'); - * var data = cursor.fetchall(function(results) { - * results.forEach(row => console.log(row)); - * }) - */ -TDengineCursor.prototype.fetchall = function fetchall(options, callback) { - if (this._result == null || this._fields == null) { - throw new errors.OperationalError("Invalid use of fetchall, either result or fields from query are null. First execute a query first"); - } - - let num_of_rows = this._chandle.affectedRows(this._result); - let data = new Array(num_of_rows); - - this._rowcount = 0; - - let time = 0; - const obs = new PerformanceObserver((items) => { - time += items.getEntries()[0].duration; - performance.clearMarks(); - }); - obs.observe({ entryTypes: ['measure'] }); - performance.mark('A'); - while (true) { - let blockAndRows = this._chandle.fetchBlock(this._result, this._fields); - // console.log(blockAndRows); - // break; - let block = blockAndRows.blocks; - let num_of_rows = blockAndRows.num_of_rows; - if (num_of_rows == 0) { - break; - } - this._rowcount += num_of_rows; - let numoffields = this._fields.length; - for (let i = 0; i < num_of_rows; i++) { - // data.push([]); - - let rowBlock = new Array(numoffields); - for (let j = 0; j < numoffields; j++) { - rowBlock[j] = block[j][i]; - } - data[this._rowcount - num_of_rows + i] = (rowBlock); - // data.push(rowBlock); - } - - } - - performance.mark('B'); - performance.measure('query', 'A', 'B'); - let response = this._createSetResponse(this._rowcount, time) - console.log(response); - - // this._connection._clearResultSet(); - let fields = this.fields; - this._reset_result(); - this.data = data; - this.fields = fields; - - wrapCB(callback, data); - - return data; -} -/** - * Asynchrnously execute a query to TDengine. NOTE, insertion requests must be done in sync if on the same table. - * @param {string} operation - The query operation to execute in the taos shell - * @param {Object} options - Execution options object. quiet : true turns off logging from queries - * @param {boolean} options.quiet - True if you want to surpress logging such as "Query OK, 1 row(s) ..." - * @param {function} callback - A callback function to execute after the query is made to TDengine - * @return {number | Buffer} Number of affected rows or a Buffer that points to the results of the query - * @since 1.0.0 - */ -TDengineCursor.prototype.execute_a = function execute_a(operation, options, callback, param) { - if (operation == undefined) { - throw new errors.ProgrammingError('No operation passed as argument'); - return null; - } - if (typeof options == 'function') { - //we expect the parameter after callback to be param - param = callback; - callback = options; - } - if (typeof options != 'object') options = {} - if (this._connection == null) { - throw new errors.ProgrammingError('Cursor is not connected'); - } - if (typeof callback != 'function') { - throw new errors.ProgrammingError("No callback function passed to execute_a function"); - } - // Async wrapper for callback; - var cr = this; - - let asyncCallbackWrapper = function (param2, res2, resCode) { - if (typeof callback == 'function') { - callback(param2, res2, resCode); - } - - if (resCode >= 0) { - // let fieldCount = cr._chandle.numFields(res2); - // if (fieldCount == 0) { - // //cr._chandle.freeResult(res2); - // return res2; - // } - // else { - // return res2; - // } - return res2; - - } - else { - throw new errors.ProgrammingError("Error occuring with use of execute_a async function. Status code was returned with failure"); - } - } - - let stmt = operation; - let time = 0; - - // Use ref module to write to buffer in cursor.js instead of taosquery to maintain a difference in levels. Have taosquery stay high level - // through letting it pass an object as param - var buf = ref.alloc('Object'); - ref.writeObject(buf, 0, param); - const obs = new PerformanceObserver((items) => { - time = items.getEntries()[0].duration; - performance.clearMarks(); - }); - obs.observe({ entryTypes: ['measure'] }); - performance.mark('A'); - this._chandle.query_a(this._connection._conn, stmt, asyncCallbackWrapper, buf); - performance.mark('B'); - performance.measure('query', 'A', 'B'); - return param; - - -} -/** - * Fetches all results from an async query. It is preferable to use cursor.query_a() to create - * async queries and execute them instead of using the cursor object directly. - * @param {Object} options - An options object containing options for this function - * @param {function} callback - callback function that is callbacked on the COMPLETE fetched data (it is calledback only once!). - * Must be of form function (param, result, rowCount, rowData) - * @param {Object} param - A parameter that is also passed to the main callback function. Important! Param must be an object, and the key "data" cannot be used - * @return {{param:Object, result:Buffer}} An object with the passed parameters object and the buffer instance that is a pointer to the result handle. - * @since 1.2.0 - * @example - * cursor.execute('select * from db.table'); - * var data = cursor.fetchall(function(results) { - * results.forEach(row => console.log(row)); - * }) - */ -TDengineCursor.prototype.fetchall_a = function fetchall_a(result, options, callback, param = {}) { - if (typeof options == 'function') { - //we expect the parameter after callback to be param - param = callback; - callback = options; - } - if (typeof options != 'object') options = {} - if (this._connection == null) { - throw new errors.ProgrammingError('Cursor is not connected'); - } - if (typeof callback != 'function') { - throw new errors.ProgrammingError('No callback function passed to fetchall_a function') - } - if (param.data) { - throw new errors.ProgrammingError("You aren't allowed to set the key 'data' for the parameters object"); - } - let buf = ref.alloc('Object'); - param.data = []; - var cr = this; - - // This callback wrapper accumulates the data from the fetch_rows_a function from the cinterface. It is accumulated by passing the param2 - // object which holds accumulated data in the data key. - let asyncCallbackWrapper = function asyncCallbackWrapper(param2, result2, numOfRows2, rowData) { - param2 = ref.readObject(param2); //return the object back from the pointer - if (numOfRows2 > 0 && rowData.length != 0) { - // Keep fetching until now rows left. - let buf2 = ref.alloc('Object'); - param2.data.push(rowData); - ref.writeObject(buf2, 0, param2); - cr._chandle.fetch_rows_a(result2, asyncCallbackWrapper, buf2); - } - else { - let finalData = param2.data; - let fields = cr._chandle.fetchFields_a(result2); - let data = []; - for (let i = 0; i < finalData.length; i++) { - let num_of_rows = finalData[i][0].length; //fetched block number i; - let block = finalData[i]; - for (let j = 0; j < num_of_rows; j++) { - data.push([]); - let rowBlock = new Array(fields.length); - for (let k = 0; k < fields.length; k++) { - rowBlock[k] = block[k][j]; - } - data[data.length - 1] = rowBlock; - } - } - cr._chandle.freeResult(result2); // free result, avoid seg faults and mem leaks! - callback(param2, result2, numOfRows2, { data: data, fields: fields }); - - } - } - ref.writeObject(buf, 0, param); - param = this._chandle.fetch_rows_a(result, asyncCallbackWrapper, buf); //returned param - return { param: param, result: result }; -} -/** - * Stop a query given the result handle. - * @param {Buffer} result - The buffer that acts as the result handle - * @since 1.3.0 - */ -TDengineCursor.prototype.stopQuery = function stopQuery(result) { - this._chandle.stopQuery(result); -} -TDengineCursor.prototype._reset_result = function _reset_result() { - this._rowcount = -1; - if (this._result != null) { - this._chandle.freeResult(this._result); - } - this._result = null; - this._fields = null; - this.data = []; - this.fields = null; -} -/** - * Get server info such as version number - * @return {string} - * @since 1.3.0 - */ -TDengineCursor.prototype.getServerInfo = function getServerInfo() { - return this._chandle.getServerInfo(this._connection._conn); -} -/** - * Get client info such as version number - * @return {string} - * @since 1.3.0 - */ -TDengineCursor.prototype.getClientInfo = function getClientInfo() { - return this._chandle.getClientInfo(); -} -/** - * Subscribe to a table from a database in TDengine. - * @param {Object} config - A configuration object containing the configuration options for the subscription - * @param {string} config.restart - whether or not to continue a subscription if it already exits, otherwise start from beginning - * @param {string} config.topic - The unique identifier of a subscription - * @param {string} config.sql - A sql statement for data query - * @param {string} config.interval - The pulling interval - * @return {Buffer} A buffer pointing to the subscription session handle - * @since 1.3.0 - */ -TDengineCursor.prototype.subscribe = function subscribe(config) { - let restart = config.restart ? 1 : 0; - return this._chandle.subscribe(this._connection._conn, restart, config.topic, config.sql, config.interval); -}; -/** - * An infinite loop that consumes the latest data and calls a callback function that is provided. - * @param {Buffer} subscription - A buffer object pointing to the subscription session handle - * @param {function} callback - The callback function that takes the row data, field/column meta data, and the subscription session handle as input - * @since 1.3.0 - */ -TDengineCursor.prototype.consumeData = async function consumeData(subscription, callback) { - while (true) { - let { data, fields, result } = this._chandle.consume(subscription); - callback(data, fields, result); - } -} -/** - * Unsubscribe the provided buffer object pointing to the subscription session handle - * @param {Buffer} subscription - A buffer object pointing to the subscription session handle that is to be unsubscribed - * @since 1.3.0 - */ -TDengineCursor.prototype.unsubscribe = function unsubscribe(subscription) { - this._chandle.unsubscribe(subscription); -} -/** - * Open a stream with TDengine to run the sql query periodically in the background - * @param {string} sql - The query to run - * @param {function} callback - The callback function to run after each query, accepting inputs as param, result handle, data, fields meta data - * @param {number} stime - The time of the stream starts in the form of epoch milliseconds. If 0 is given, the start time is set as the current time. - * @param {function} stoppingCallback - The callback function to run when the continuous query stops. It takes no inputs - * @param {object} param - A parameter that is passed to the main callback function - * @return {Buffer} A buffer pointing to the stream handle - * @since 1.3.0 - */ -TDengineCursor.prototype.openStream = function openStream(sql, callback, stime = 0, stoppingCallback, param = {}) { - let buf = ref.alloc('Object'); - ref.writeObject(buf, 0, param); - - let asyncCallbackWrapper = function (param2, result2, blocks, fields) { - let data = []; - let num_of_rows = blocks[0].length; - for (let j = 0; j < num_of_rows; j++) { - data.push([]); - let rowBlock = new Array(fields.length); - for (let k = 0; k < fields.length; k++) { - rowBlock[k] = blocks[k][j]; - } - data[data.length - 1] = rowBlock; - } - callback(param2, result2, blocks, fields); - } - return this._chandle.openStream(this._connection._conn, sql, asyncCallbackWrapper, stime, stoppingCallback, buf); -} -/** - * Close a stream - * @param {Buffer} - A buffer pointing to the handle of the stream to be closed - * @since 1.3.0 - */ -TDengineCursor.prototype.closeStream = function closeStream(stream) { - this._chandle.closeStream(stream); -} diff --git a/tests/connectorTest/nodejsTest/nodetaos/error.js b/tests/connectorTest/nodejsTest/nodetaos/error.js deleted file mode 100644 index 8ab91a50c7d81a4675246617e0969ee8c81c514e..0000000000000000000000000000000000000000 --- a/tests/connectorTest/nodejsTest/nodetaos/error.js +++ /dev/null @@ -1,96 +0,0 @@ - -/** - * TDengine Error Class - * @ignore - */ -class TDError extends Error { - constructor(args) { - super(args) - this.name = "TDError"; - } -} -/** Exception raised for important warnings like data truncations while inserting. - * @ignore - */ -class Warning extends Error { - constructor(args) { - super(args) - this.name = "Warning"; - } -} -/** Exception raised for errors that are related to the database interface rather than the database itself. - * @ignore - */ -class InterfaceError extends TDError { - constructor(args) { - super(args) - this.name = "TDError.InterfaceError"; - } -} -/** Exception raised for errors that are related to the database. - * @ignore - */ -class DatabaseError extends TDError { - constructor(args) { - super(args) - this.name = "TDError.DatabaseError"; - } -} -/** Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range. - * @ignore - */ -class DataError extends DatabaseError { - constructor(args) { - super(args) - this.name = "TDError.DatabaseError.DataError"; - } -} -/** Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer - * @ignore - */ -class OperationalError extends DatabaseError { - constructor(args) { - super(args) - this.name = "TDError.DatabaseError.OperationalError"; - } -} -/** Exception raised when the relational integrity of the database is affected. - * @ignore - */ -class IntegrityError extends DatabaseError { - constructor(args) { - super(args) - this.name = "TDError.DatabaseError.IntegrityError"; - } -} -/** Exception raised when the database encounters an internal error. - * @ignore - */ -class InternalError extends DatabaseError { - constructor(args) { - super(args) - this.name = "TDError.DatabaseError.InternalError"; - } -} -/** Exception raised for programming errors. - * @ignore - */ -class ProgrammingError extends DatabaseError { - constructor(args) { - super(args) - this.name = "TDError.DatabaseError.ProgrammingError"; - } -} -/** Exception raised in case a method or database API was used which is not supported by the database. - * @ignore - */ -class NotSupportedError extends DatabaseError { - constructor(args) { - super(args) - this.name = "TDError.DatabaseError.NotSupportedError"; - } -} - -module.exports = { - TDError, Warning, InterfaceError, DatabaseError, DataError, OperationalError, IntegrityError, InternalError, ProgrammingError, NotSupportedError -}; diff --git a/tests/connectorTest/nodejsTest/nodetaos/globalfunc.js b/tests/connectorTest/nodejsTest/nodetaos/globalfunc.js deleted file mode 100644 index cf7344c868ee94831eba47ff55369a684e34b02f..0000000000000000000000000000000000000000 --- a/tests/connectorTest/nodejsTest/nodetaos/globalfunc.js +++ /dev/null @@ -1,14 +0,0 @@ -/* Wrap a callback, reduce code amount */ -function wrapCB(callback, input) { - if (typeof callback === 'function') { - callback(input); - } - return; -} -global.wrapCB = wrapCB; -function toTaosTSString(date) { - date = new Date(date); - let tsArr = date.toISOString().split("T") - return tsArr[0] + " " + tsArr[1].substring(0, tsArr[1].length-1); -} -global.toTaosTSString = toTaosTSString; diff --git a/tests/connectorTest/nodejsTest/nodetaos/taosobjects.js b/tests/connectorTest/nodejsTest/nodetaos/taosobjects.js deleted file mode 100644 index 3bc0fe0aca060a32daa7a5cebd2dbfb99ac29a7c..0000000000000000000000000000000000000000 --- a/tests/connectorTest/nodejsTest/nodetaos/taosobjects.js +++ /dev/null @@ -1,152 +0,0 @@ -const FieldTypes = require('./constants'); -const util = require('util'); -/** - * Various objects such as TaosRow and TaosColumn that help make parsing data easier - * @module TaosObjects - * - */ - -/** - * The TaosRow object. Contains the data from a retrieved row from a database and functions that parse the data. - * @typedef {Object} TaosRow - A row of data retrieved from a table. - * @global - * @example - * var trow = new TaosRow(row); - * console.log(trow.data); - */ -function TaosRow(row) { - this.data = row; - this.length = row.length; - return this; -} - -/** - * @typedef {Object} TaosField - A field/column's metadata from a table. - * @global - * @example - * var tfield = new TaosField(field); - * console.log(tfield.name); - */ - -function TaosField(field) { - this._field = field; - this.name = field.name; - this.type = FieldTypes.getType(field.type); - return this; -} - -/** - * A TaosTimestamp object, which is the standard date object with added functionality - * @global - * @memberof TaosObjects - * @param {Date} date - A Javascript date time object or the time in milliseconds past 1970-1-1 00:00:00.000 - */ -class TaosTimestamp extends Date { - constructor(date, precision = 0) { - if (precision === 1) { - super(Math.floor(date / 1000)); - this.precisionExtras = date % 1000; - } else if (precision === 2) { - // use BigInt to fix: 1623254400999999999 / 1000000 = 1623254401000 which not expected - super(parseInt(BigInt(date) / 1000000n)); - // use BigInt to fix: 1625801548423914405 % 1000000 = 914496 which not expected (914405) - this.precisionExtras = parseInt(BigInt(date) % 1000000n); - } else { - super(parseInt(date)); - } - this.precision = precision; - } - - /** - * TDengine raw timestamp. - * @returns raw taos timestamp (int64) - */ - taosTimestamp() { - if (this.precision == 1) { - return (this * 1000 + this.precisionExtras); - } else if (this.precision == 2) { - return (this * 1000000 + this.precisionExtras); - } else { - return Math.floor(this); - } - } - - /** - * Gets the microseconds of a Date. - * @return {Int} A microseconds integer - */ - getMicroseconds() { - if (this.precision == 1) { - return this.getMilliseconds() * 1000 + this.precisionExtras; - } else if (this.precision == 2) { - return this.getMilliseconds() * 1000 + this.precisionExtras / 1000; - } else { - return 0; - } - } - /** - * Gets the nanoseconds of a TaosTimestamp. - * @return {Int} A nanoseconds integer - */ - getNanoseconds() { - if (this.precision == 1) { - return this.getMilliseconds() * 1000000 + this.precisionExtras * 1000; - } else if (this.precision == 2) { - return this.getMilliseconds() * 1000000 + this.precisionExtras; - } else { - return 0; - } - } - - /** - * @returns {String} a string for timestamp string format - */ - _precisionExtra() { - if (this.precision == 1) { - return String(this.precisionExtras).padStart(3, '0'); - } else if (this.precision == 2) { - return String(this.precisionExtras).padStart(6, '0'); - } else { - return ''; - } - } - /** - * @function Returns the date into a string usable by TDengine - * @return {string} A Taos Timestamp String - */ - toTaosString() { - var tzo = -this.getTimezoneOffset(), - dif = tzo >= 0 ? '+' : '-', - pad = function (num) { - var norm = Math.floor(Math.abs(num)); - return (norm < 10 ? '0' : '') + norm; - }, - pad2 = function (num) { - var norm = Math.floor(Math.abs(num)); - if (norm < 10) return '00' + norm; - if (norm < 100) return '0' + norm; - if (norm < 1000) return norm; - }; - return this.getFullYear() + - '-' + pad(this.getMonth() + 1) + - '-' + pad(this.getDate()) + - ' ' + pad(this.getHours()) + - ':' + pad(this.getMinutes()) + - ':' + pad(this.getSeconds()) + - '.' + pad2(this.getMilliseconds()) + - '' + this._precisionExtra(); - } - - /** - * Custom console.log - * @returns {String} string format for debug - */ - [util.inspect.custom](depth, opts) { - return this.toTaosString() + JSON.stringify({ precision: this.precision, precisionExtras: this.precisionExtras }, opts); - } - toString() { - return this.toTaosString(); - } -} - -module.exports = { TaosRow, TaosField, TaosTimestamp } diff --git a/tests/connectorTest/nodejsTest/nodetaos/taosquery.js b/tests/connectorTest/nodejsTest/nodetaos/taosquery.js deleted file mode 100644 index eeede3ff6885e27c1d1c569a7a410f88109c9acd..0000000000000000000000000000000000000000 --- a/tests/connectorTest/nodejsTest/nodetaos/taosquery.js +++ /dev/null @@ -1,112 +0,0 @@ -var TaosResult = require('./taosresult') -require('./globalfunc.js') -module.exports = TaosQuery; - - -/** - * @class TaosQuery - * @classdesc The TaosQuery class is one level above the TDengine Cursor in that it makes sure to generally return promises from functions, and wrap - * all data with objects such as wrapping a row of data with Taos Row. This is meant to enable an higher level API that allows additional - * functionality and save time whilst also making it easier to debug and enter less problems with the use of promises. - * @param {string} query - Query to construct object from - * @param {TDengineCursor} cursor - The cursor from which this query will execute from - * @param {boolean} execute - Whether or not to immedietely execute the query synchronously and fetch all results. Default is false. - * @property {string} query - The current query in string format the TaosQuery object represents - * @return {TaosQuery} - * @since 1.0.6 - */ -function TaosQuery(query = "", cursor = null, execute = false) { - this.query = query; - this._cursor = cursor; - if (execute == true) { - return this.execute(); - } - return this; -} - -/** - * Executes the query object and returns a Promise - * @memberof TaosQuery - * @return {Promise} A promise that resolves with a TaosResult object, or rejects with an error - * @since 1.0.6 - */ -TaosQuery.prototype.execute = async function execute() { - var taosQuery = this; //store the current instance of taosQuery to avoid async issues? - var executionPromise = new Promise(function(resolve, reject) { - let data = []; - let fields = []; - let result; - try { - taosQuery._cursor.execute(taosQuery.query); - if (taosQuery._cursor._fields) fields = taosQuery._cursor._fields; - if (taosQuery._cursor._result != null) data = taosQuery._cursor.fetchall(); - result = new TaosResult(data, fields) - } - catch(err) { - reject(err); - } - resolve(result) - - }); - return executionPromise; -} - -/** - * Executes the query object asynchronously and returns a Promise. Completes query to completion. - * @memberof TaosQuery - * @param {Object} options - Execution options - * @return {Promise} A promise that resolves with a TaosResult object, or rejects with an error - * @since 1.2.0 - */ -TaosQuery.prototype.execute_a = async function execute_a(options = {}) { - var executionPromise = new Promise( (resolve, reject) => { - - }); - var fres; - var frej; - var fetchPromise = new Promise( (resolve, reject) => { - fres = resolve; - frej = reject; - }); - let asyncCallbackFetchall = async function(param, res, numOfRows, blocks) { - if (numOfRows > 0) { - // Likely a query like insert - fres(); - } - else { - fres(new TaosResult(blocks.data, blocks.fields)); - } - } - let asyncCallback = async function(param, res, code) { - //upon success, we fetchall results - this._cursor.fetchall_a(res, options, asyncCallbackFetchall, {}); - } - this._cursor.execute_a(this.query, asyncCallback.bind(this), {}); - return fetchPromise; -} - -/** - * Bind arguments to the query and automatically parses them into the right format - * @param {array | ...args} args - A number of arguments to bind to each ? in the query - * @return {TaosQuery} - * @example - * // An example of binding a javascript date and a number to a query - * var query = cursor.query("select count(*) from meterinfo.meters where ts <= ? and areaid = ?").bind(new Date(), 3); - * var promise1 = query.execute(); - * promise1.then(function(result) { - * result.pretty(); // Log the prettified version of the results. - * }); - * @since 1.0.6 - */ -TaosQuery.prototype.bind = function bind(f, ...args) { - if (typeof f == 'object' && f.constructor.name != 'Array') args.unshift(f); //param is not an array object - else if (typeof f != 'object') args.unshift(f); - else { args = f; } - args.forEach(function(arg) { - if (arg.constructor.name == 'TaosTimestamp') arg = "\"" + arg.toTaosString() + "\""; - else if (arg.constructor.name == 'Date') arg = "\"" + toTaosTSString(arg) + "\""; - else if (typeof arg == 'string') arg = "\"" + arg + "\""; - this.query = this.query.replace(/\?/,arg); - }, this); - return this; -} diff --git a/tests/connectorTest/nodejsTest/nodetaos/taosresult.js b/tests/connectorTest/nodejsTest/nodetaos/taosresult.js deleted file mode 100644 index 4138ebbec6e1b792691d17a25b7c18d35b6a922a..0000000000000000000000000000000000000000 --- a/tests/connectorTest/nodejsTest/nodetaos/taosresult.js +++ /dev/null @@ -1,85 +0,0 @@ -require('./globalfunc.js') -const TaosObjects = require('./taosobjects'); -const TaosRow = TaosObjects.TaosRow; -const TaosField = TaosObjects.TaosField; - -module.exports = TaosResult; -/** - * @class TaosResult - * @classdesc A TaosResult class consts of the row data and the fields metadata, all wrapped under various objects for higher functionality. - * @param {Array} data - Array of result rows - * @param {Array} fields - Array of field meta data - * @property {Array} data - Array of TaosRows forming the result data (this does not include field meta data) - * @property {Array} fields - Array of TaosFields forming the fields meta data array. - * @return {TaosResult} - * @since 1.0.6 - */ -function TaosResult(data, fields) { - this.data = data.map(row => new TaosRow(row)); - this.rowcount = this.data.length; - this.fields = fields.map(field => new TaosField(field)); -} -/** - * Pretty print data and the fields meta data as if you were using the taos shell - * @memberof TaosResult - * @function pretty - * @since 1.0.6 - */ - -TaosResult.prototype.pretty = function pretty() { - let fieldsStr = ""; - let sizing = []; - this.fields.forEach((field,i) => { - if (field._field.type == 8 || field._field.type == 10){ - sizing.push(Math.max(field.name.length, field._field.bytes)); - } - else { - sizing.push(Math.max(field.name.length, suggestedMinWidths[field._field.type])); - } - fieldsStr += fillEmpty(Math.floor(sizing[i]/2 - field.name.length / 2)) + field.name + fillEmpty(Math.ceil(sizing[i]/2 - field.name.length / 2)) + " | "; - }); - var sumLengths = sizing.reduce((a,b)=> a+=b,(0)) + sizing.length * 3; - - console.log("\n" + fieldsStr); - console.log(printN("=",sumLengths)); - this.data.forEach(row => { - let rowStr = ""; - row.data.forEach((entry, i) => { - if (this.fields[i]._field.type == 9) { - entry = entry.toTaosString(); - } else { - entry = entry == null ? 'null' : entry.toString(); - } - rowStr += entry - rowStr += fillEmpty(sizing[i] - entry.length) + " | "; - }); - console.log(rowStr); - }); -} -const suggestedMinWidths = { - 0: 4, - 1: 4, - 2: 4, - 3: 6, - 4: 11, - 5: 12, - 6: 24, - 7: 24, - 8: 10, - 9: 25, - 10: 10, -} -function printN(s, n) { - let f = ""; - for (let i = 0; i < n; i ++) { - f += s; - } - return f; -} -function fillEmpty(n) { - let str = ""; - for (let i = 0; i < n; i++) { - str += " "; - } - return str; -} diff --git a/tests/connectorTest/nodejsTest/readme.md b/tests/connectorTest/nodejsTest/readme.md deleted file mode 100644 index 26a28afbdd514ad97e969302e7d790f6240bb770..0000000000000000000000000000000000000000 --- a/tests/connectorTest/nodejsTest/readme.md +++ /dev/null @@ -1,161 +0,0 @@ -# TDengine Node.js connector -[![minzip](https://img.shields.io/bundlephobia/minzip/td2.0-connector.svg)](https://github.com/taosdata/TDengine/tree/master/src/connector/nodejs) [![NPM](https://img.shields.io/npm/l/td2.0-connector.svg)](https://github.com/taosdata/TDengine/#what-is-tdengine) - -This is the Node.js library that lets you connect to [TDengine](https://www.github.com/taosdata/tdengine) 2.0 version. It is built so that you can use as much of it as you want or as little of it as you want through providing an extensive API. If you want the raw data in the form of an array of arrays for the row data retrieved from a table, you can do that. If you want to wrap that data with objects that allow you easily manipulate and display data such as using a prettifier function, you can do that! - -## Installation - -To get started, just type in the following to install the connector through [npm](https://www.npmjs.com/) - -```cmd -npm install td2.0-connector -``` - -To interact with TDengine, we make use of the [node-gyp](https://github.com/nodejs/node-gyp) library. To install, you will need to install the following depending on platform (the following instructions are quoted from node-gyp) - -### On Linux - -- `python` (`v2.7` recommended, `v3.x.x` is **not** supported) -- `make` -- A proper C/C++ compiler toolchain, like [GCC](https://gcc.gnu.org) -- `node` (between `v10.x` and `v11.x`, other version has some dependency compatibility problems) - -### On macOS - -- `python` (`v2.7` recommended, `v3.x.x` is **not** supported) (already installed on macOS) - -- Xcode - - - You also need to install the - - ``` - Command Line Tools - ``` - - via Xcode. You can find this under the menu - - ``` - Xcode -> Preferences -> Locations - ``` - - (or by running - - ``` - xcode-select --install - ``` - - in your Terminal) - - - This step will install `gcc` and the related toolchain containing `make` - -### On Windows - -#### Option 1 - -Install all the required tools and configurations using Microsoft's [windows-build-tools](https://github.com/felixrieseberg/windows-build-tools) using `npm install --global --production windows-build-tools` from an elevated PowerShell or CMD.exe (run as Administrator). - -#### Option 2 - -Install tools and configuration manually: - -- Install Visual C++ Build Environment: [Visual Studio Build Tools](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools) (using "Visual C++ build tools" workload) or [Visual Studio 2017 Community](https://visualstudio.microsoft.com/pl/thank-you-downloading-visual-studio/?sku=Community) (using the "Desktop development with C++" workload) -- Install [Python 2.7](https://www.python.org/downloads/) (`v3.x.x` is not supported), and run `npm config set python python2.7` (or see below for further instructions on specifying the proper Python version and path.) -- Launch cmd, `npm config set msvs_version 2017` - -If the above steps didn't work for you, please visit [Microsoft's Node.js Guidelines for Windows](https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#compiling-native-addon-modules) for additional tips. - -To target native ARM64 Node.js on Windows 10 on ARM, add the components "Visual C++ compilers and libraries for ARM64" and "Visual C++ ATL for ARM64". - -## Usage - -The following is a short summary of the basic usage of the connector, the full api and documentation can be found [here](http://docs.taosdata.com/node) - -### Connection - -To use the connector, first require the library ```td2.0-connector```. Running the function ```taos.connect``` with the connection options passed in as an object will return a TDengine connection object. The required connection option is ```host```, other options if not set, will be the default values as shown below. - -A cursor also needs to be initialized in order to interact with TDengine from Node.js. - -```javascript -const taos = require('td2.0-connector'); -var conn = taos.connect({host:"127.0.0.1", user:"root", password:"taosdata", config:"/etc/taos",port:0}) -var cursor = conn.cursor(); // Initializing a new cursor -``` - -Close a connection - -```javascript -conn.close(); -``` - -### Queries - -We can now start executing simple queries through the ```cursor.query``` function, which returns a TaosQuery object. - -```javascript -var query = cursor.query('show databases;') -``` - -We can get the results of the queries through the ```query.execute()``` function, which returns a promise that resolves with a TaosResult object, which contains the raw data and additional functionalities such as pretty printing the results. - -```javascript -var promise = query.execute(); -promise.then(function(result) { - result.pretty(); //logs the results to the console as if you were in the taos shell -}); -``` - -You can also query by binding parameters to a query by filling in the question marks in a string as so. The query will automatically parse what was binded and convert it to the proper format for use with TDengine -```javascript -var query = cursor.query('select * from meterinfo.meters where ts <= ? and areaid = ?;').bind(new Date(), 5); -query.execute().then(function(result) { - result.pretty(); -}) -``` - -The TaosQuery object can also be immediately executed upon creation by passing true as the second argument, returning a promise instead of a TaosQuery. -```javascript -var promise = cursor.query('select * from meterinfo.meters where v1 = 30;', true) -promise.then(function(result) { - result.pretty(); -}) -``` - -If you want to execute queries without objects being wrapped around the data, use ```cursor.execute()``` directly and ```cursor.fetchall()``` to retrieve data if there is any. -```javascript -cursor.execute('select count(*), avg(v1), min(v2) from meterinfo.meters where ts >= \"2019-07-20 00:00:00.000\";'); -var data = cursor.fetchall(); -console.log(cursor.fields); // Latest query's Field metadata is stored in cursor.fields -console.log(cursor.data); // Latest query's result data is stored in cursor.data, also returned by fetchall. -``` - -### Async functionality - -Async queries can be performed using the same functions such as `cursor.execute`, `TaosQuery.query`, but now with `_a` appended to them. - -Say you want to execute an two async query on two separate tables, using `cursor.query`, you can do that and get a TaosQuery object, which upon executing with the `execute_a` function, returns a promise that resolves with a TaosResult object. - -```javascript -var promise1 = cursor.query('select count(*), avg(v1), avg(v2) from meter1;').execute_a() -var promise2 = cursor.query('select count(*), avg(v1), avg(v2) from meter2;').execute_a(); -promise1.then(function(result) { - result.pretty(); -}) -promise2.then(function(result) { - result.pretty(); -}) -``` - -## Example - -An example of using the NodeJS connector to create a table with weather data and create and execute queries can be found [here](https://github.com/taosdata/TDengine/tree/master/tests/examples/nodejs/node-example.js) (The preferred method for using the connector) - -An example of using the NodeJS connector to achieve the same things but without all the object wrappers that wrap around the data returned to achieve higher functionality can be found [here](https://github.com/taosdata/TDengine/tree/master/tests/examples/nodejs/node-example-raw.js) - -## Contributing to TDengine - -Please follow the [contribution guidelines](https://github.com/taosdata/TDengine/blob/master/CONTRIBUTING.md) to contribute to the project. - -## License - -[GNU AGPL v3.0](http://www.gnu.org/licenses/agpl-3.0.html) diff --git a/tests/connectorTest/nodejsTest/tdengine.js b/tests/connectorTest/nodejsTest/tdengine.js deleted file mode 100644 index 047c744a4fc90c6306e851eaa529a7f9f578fe12..0000000000000000000000000000000000000000 --- a/tests/connectorTest/nodejsTest/tdengine.js +++ /dev/null @@ -1,4 +0,0 @@ -var TDengineConnection = require('./nodetaos/connection.js') -module.exports.connect = function (connection={}) { - return new TDengineConnection(connection); -} diff --git a/tests/connectorTest/nodejsTest/test/nanosecondTest.js b/tests/connectorTest/nodejsTest/test/nanosecondTest.js deleted file mode 100644 index 36fb398ea4acc51eeae1dd0549aca503aabdba0e..0000000000000000000000000000000000000000 --- a/tests/connectorTest/nodejsTest/test/nanosecondTest.js +++ /dev/null @@ -1,351 +0,0 @@ -const taos = require('../tdengine'); -var conn = taos.connect({config:"/etc/taos"}); -var c1 = conn.cursor(); - - -function checkData(sql,row,col,data){ - - c1.execute(sql) - var d = c1.fetchall(); - let checkdata = d[row][col]; - if (checkdata == data) { - - // console.log('check pass') - } - else{ - console.log('check failed') - console.log(checkdata) - console.log(data) - - - } -} - - -// nano basic case - -c1.execute('reset query cache') -c1.execute('drop database if exists db') -c1.execute('create database db precision "ns";') -c1.execute('use db'); -c1.execute('create table tb (ts timestamp, speed int)') -c1.execute('insert into tb values(\'2021-06-10 00:00:00.100000001\', 1);') -c1.execute('insert into tb values(1623254400150000000, 2);') -c1.execute('import into tb values(1623254400300000000, 3);') -c1.execute('import into tb values(1623254400299999999, 4);') -c1.execute('insert into tb values(1623254400300000001, 5);') -c1.execute('insert into tb values(1623254400999999999, 7);') -c1.execute('insert into tb values(1623254400123456789, 8);') -sql = 'select * from tb;' - -console.log('*******************************************') -console.log('this is area about checkdata result') -//check data about insert data -checkData(sql,0,0,'2021-06-10 00:00:00.100000001') -checkData(sql,1,0,'2021-06-10 00:00:00.123456789') -checkData(sql,2,0,'2021-06-10 00:00:00.150000000') -checkData(sql,3,0,'2021-06-10 00:00:00.299999999') //error -checkData(sql,4,0,'2021-06-10 00:00:00.300000000') -checkData(sql,5,0,'2021-06-10 00:00:00.300000001') -checkData(sql,6,0,'2021-06-10 00:00:00.999999999') //error - -// // us basic case - -// c1.execute('reset query cache') -// c1.execute('drop database if exists db') -// c1.execute('create database db precision "us";') -// c1.execute('use db'); -// c1.execute('create table tb (ts timestamp, speed int)') -// c1.execute('insert into tb values(\'2021-06-10 00:00:00.100001\', 1);') -// c1.execute('insert into tb values(1623254400150000, 2);') -// c1.execute('import into tb values(1623254400300000, 3);') -// c1.execute('import into tb values(1623254400299999, 4);') -// c1.execute('insert into tb values(1623254400300001, 5);') -// c1.execute('insert into tb values(1623254400999999, 7);') -// c1.execute('insert into tb values(1623254400123789, 8);') -// sql = 'select * from tb;' - -// console.log('*******************************************') - -// //check data about insert data -// checkData(sql,0,0,'2021-06-10 00:00:00.100001') -// checkData(sql,1,0,'2021-06-10 00:00:00.123789') -// checkData(sql,2,0,'2021-06-10 00:00:00.150000') -// checkData(sql,3,0,'2021-06-10 00:00:00.299999') -// checkData(sql,4,0,'2021-06-10 00:00:00.300000') -// checkData(sql,5,0,'2021-06-10 00:00:00.300001') -// checkData(sql,6,0,'2021-06-10 00:00:00.999999') - -// console.log('*******************************************') - -// // ms basic case - -// c1.execute('reset query cache') -// c1.execute('drop database if exists db') -// c1.execute('create database db precision "ms";') -// c1.execute('use db'); -// c1.execute('create table tb (ts timestamp, speed int)') -// c1.execute('insert into tb values(\'2021-06-10 00:00:00.101\', 1);') -// c1.execute('insert into tb values(1623254400150, 2);') -// c1.execute('import into tb values(1623254400300, 3);') -// c1.execute('import into tb values(1623254400299, 4);') -// c1.execute('insert into tb values(1623254400301, 5);') -// c1.execute('insert into tb values(1623254400789, 7);') -// c1.execute('insert into tb values(1623254400999, 8);') -// sql = 'select * from tb;' - -// console.log('*******************************************') -// console.log('this is area about checkdata result') -// //check data about insert data -// checkData(sql,0,0,'2021-06-10 00:00:00.101') -// checkData(sql,1,0,'2021-06-10 00:00:00.150') -// checkData(sql,2,0,'2021-06-10 00:00:00.299') -// checkData(sql,3,0,'2021-06-10 00:00:00.300') -// checkData(sql,4,0,'2021-06-10 00:00:00.301') -// checkData(sql,5,0,'2021-06-10 00:00:00.789') -// checkData(sql,6,0,'2021-06-10 00:00:00.999') - -console.log('*******************************************') - -// offfical query result to show -// console.log('this is area about fetch all data') -// var query = c1.query(sql) -// var promise = query.execute(); -// promise.then(function(result) { -// result.pretty(); -// }); - -console.log('*******************************************') -// checkData(sql,3,1,3) -// checkData(sql,4,1,5) -// checkData(sql,5,1,7) - - - - - - -// checkData(3,1,3) -// checkData(4,1,5) -// checkData(5,1,7) - -// tdSql.query('select count(*) from tb where ts > 1623254400100000000 and ts < 1623254400100000002;') -// tdSql.checkData(0,0,1) -// tdSql.query('select count(*) from tb where ts > \'2021-06-10 0:00:00.100000001\' and ts < \'2021-06-10 0:00:00.160000000\';') -// tdSql.checkData(0,0,1) - -// tdSql.query('select count(*) from tb where ts > 1623254400100000000 and ts < 1623254400150000000;') -// tdSql.checkData(0,0,1) -// tdSql.query('select count(*) from tb where ts > \'2021-06-10 0:00:00.100000000\' and ts < \'2021-06-10 0:00:00.150000000\';') -// tdSql.checkData(0,0,1) - -// tdSql.query('select count(*) from tb where ts > 1623254400400000000;') -// tdSql.checkData(0,0,1) -// tdSql.query('select count(*) from tb where ts < \'2021-06-10 00:00:00.400000000\';') -// tdSql.checkData(0,0,5) - -// tdSql.query('select count(*) from tb where ts > now + 400000000b;') -// tdSql.checkRows(0) - -// tdSql.query('select count(*) from tb where ts >= \'2021-06-10 0:00:00.100000001\';') -// tdSql.checkData(0,0,6) - -// tdSql.query('select count(*) from tb where ts <= 1623254400300000000;') -// tdSql.checkData(0,0,4) - -// tdSql.query('select count(*) from tb where ts = \'2021-06-10 0:00:00.000000000\';') -// tdSql.checkRows(0) - -// tdSql.query('select count(*) from tb where ts = 1623254400150000000;') -// tdSql.checkData(0,0,1) - -// tdSql.query('select count(*) from tb where ts = \'2021-06-10 0:00:00.100000001\';') -// tdSql.checkData(0,0,1) - -// tdSql.query('select count(*) from tb where ts between 1623254400000000000 and 1623254400400000000;') -// tdSql.checkData(0,0,5) - -// tdSql.query('select count(*) from tb where ts between \'2021-06-10 0:00:00.299999999\' and \'2021-06-10 0:00:00.300000001\';') -// tdSql.checkData(0,0,3) - -// tdSql.query('select avg(speed) from tb interval(5000000000b);') -// tdSql.checkRows(1) - -// tdSql.query('select avg(speed) from tb interval(100000000b)') -// tdSql.checkRows(4) - -// tdSql.error('select avg(speed) from tb interval(1b);') -// tdSql.error('select avg(speed) from tb interval(999b);') - -// tdSql.query('select avg(speed) from tb interval(1000b);') -// tdSql.checkRows(5) - -// tdSql.query('select avg(speed) from tb interval(1u);') -// tdSql.checkRows(5) - -// tdSql.query('select avg(speed) from tb interval(100000000b) sliding (100000000b);') -// tdSql.checkRows(4) - -// tdSql.query('select last(*) from tb') -// tdSql.checkData(0,0, '2021-06-10 0:00:00.999999999') -// tdSql.checkData(0,0, 1623254400999999999) - -// tdSql.query('select first(*) from tb') -// tdSql.checkData(0,0, 1623254400100000001) -// tdSql.checkData(0,0, '2021-06-10 0:00:00.100000001') - -// c1.execute('insert into tb values(now + 500000000b, 6);') -// tdSql.query('select * from tb;') -// tdSql.checkRows(7) - -// tdLog.debug('testing nanosecond support in other timestamps') -// c1.execute('create table tb2 (ts timestamp, speed int, ts2 timestamp);') -// c1.execute('insert into tb2 values(\'2021-06-10 0:00:00.100000001\', 1, \'2021-06-11 0:00:00.100000001\');') -// c1.execute('insert into tb2 values(1623254400150000000, 2, 1623340800150000000);') -// c1.execute('import into tb2 values(1623254400300000000, 3, 1623340800300000000);') -// c1.execute('import into tb2 values(1623254400299999999, 4, 1623340800299999999);') -// c1.execute('insert into tb2 values(1623254400300000001, 5, 1623340800300000001);') -// c1.execute('insert into tb2 values(1623254400999999999, 7, 1623513600999999999);') - -// tdSql.query('select * from tb2;') -// tdSql.checkData(0,0,'2021-06-10 0:00:00.100000001') -// tdSql.checkData(1,0,'2021-06-10 0:00:00.150000000') -// tdSql.checkData(2,1,4) -// tdSql.checkData(3,1,3) -// tdSql.checkData(4,2,'2021-06-11 00:00:00.300000001') -// tdSql.checkData(5,2,'2021-06-13 00:00:00.999999999') -// tdSql.checkRows(6) -// tdSql.query('select count(*) from tb2 where ts2 > 1623340800000000000 and ts2 < 1623340800150000000;') -// tdSql.checkData(0,0,1) -// tdSql.query('select count(*) from tb2 where ts2 > \'2021-06-11 0:00:00.100000000\' and ts2 < \'2021-06-11 0:00:00.100000002\';') -// tdSql.checkData(0,0,1) - -// tdSql.query('select count(*) from tb2 where ts2 > 1623340800500000000;') -// tdSql.checkData(0,0,1) -// tdSql.query('select count(*) from tb2 where ts2 < \'2021-06-11 0:00:00.400000000\';') -// tdSql.checkData(0,0,5) - -// tdSql.query('select count(*) from tb2 where ts2 > now + 400000000b;') -// tdSql.checkRows(0) - -// tdSql.query('select count(*) from tb2 where ts2 >= \'2021-06-11 0:00:00.100000001\';') -// tdSql.checkData(0,0,6) - -// tdSql.query('select count(*) from tb2 where ts2 <= 1623340800400000000;') -// tdSql.checkData(0,0,5) - -// tdSql.query('select count(*) from tb2 where ts2 = \'2021-06-11 0:00:00.000000000\';') -// tdSql.checkRows(0) - -// tdSql.query('select count(*) from tb2 where ts2 = \'2021-06-11 0:00:00.300000001\';') -// tdSql.checkData(0,0,1) - -// tdSql.query('select count(*) from tb2 where ts2 = 1623340800300000001;') -// tdSql.checkData(0,0,1) - -// tdSql.query('select count(*) from tb2 where ts2 between 1623340800000000000 and 1623340800450000000;') -// tdSql.checkData(0,0,5) - -// tdSql.query('select count(*) from tb2 where ts2 between \'2021-06-11 0:00:00.299999999\' and \'2021-06-11 0:00:00.300000001\';') -// tdSql.checkData(0,0,3) - -// tdSql.query('select count(*) from tb2 where ts2 <> 1623513600999999999;') -// tdSql.checkData(0,0,5) - -// tdSql.query('select count(*) from tb2 where ts2 <> \'2021-06-11 0:00:00.100000001\';') -// tdSql.checkData(0,0,5) - -// tdSql.query('select count(*) from tb2 where ts2 <> \'2021-06-11 0:00:00.100000000\';') -// tdSql.checkData(0,0,6) - -// tdSql.query('select count(*) from tb2 where ts2 != 1623513600999999999;') -// tdSql.checkData(0,0,5) - -// tdSql.query('select count(*) from tb2 where ts2 != \'2021-06-11 0:00:00.100000001\';') -// tdSql.checkData(0,0,5) - -// tdSql.query('select count(*) from tb2 where ts2 != \'2021-06-11 0:00:00.100000000\';') -// tdSql.checkData(0,0,6) - -// c1.execute('insert into tb2 values(now + 500000000b, 6, now +2d);') -// tdSql.query('select * from tb2;') -// tdSql.checkRows(7) - -// tdLog.debug('testing ill nanosecond format handling') -// c1.execute('create table tb3 (ts timestamp, speed int);') - -// tdSql.error('insert into tb3 values(16232544001500000, 2);') -// c1.execute('insert into tb3 values(\'2021-06-10 0:00:00.123456\', 2);') -// tdSql.query('select * from tb3 where ts = \'2021-06-10 0:00:00.123456000\';') -// tdSql.checkRows(1) - -// c1.execute('insert into tb3 values(\'2021-06-10 0:00:00.123456789000\', 2);') -// tdSql.query('select * from tb3 where ts = \'2021-06-10 0:00:00.123456789\';') -// tdSql.checkRows(1) - -// # check timezone support - -// c1.execute('use db;') -// c1.execute('create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);') -// c1.execute('insert into tb1 using st tags("2021-06-10 0:00:00.123456789" , 1 ) values("2021-06-10 0:00:00.123456789+07:00" , 1.0);' ) -// tdSql.query("select first(*) from tb1;") -// tdSql.checkData(0,0,1623258000123456789) -// c1.execute('insert into tb1 using st tags("2021-06-10 0:00:00.123456789" , 1 ) values("2021-06-10T0:00:00.123456789+06:00" , 2.0);' ) -// tdSql.query("select last(*) from tb1;") -// tdSql.checkData(0,0,1623261600123456789) - -// c1.execute('create database usdb precision "us";') -// c1.execute('use usdb;') -// c1.execute('create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);') -// c1.execute('insert into tb1 using st tags("2021-06-10 0:00:00.123456" , 1 ) values("2021-06-10 0:00:00.123456+07:00" , 1.0);' ) -// res = tdSql.getResult("select first(*) from tb1;") -// print(res) -// if res == [(datetime.datetime(2021, 6, 10, 1, 0, 0, 123456), 1.0)]: -// tdLog.info('check timezone pass about us database') - -// c1.execute('create database msdb precision "ms";') -// c1.execute('use msdb;') -// c1.execute('create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);') -// c1.execute('insert into tb1 using st tags("2021-06-10 0:00:00.123" , 1 ) values("2021-06-10 0:00:00.123+07:00" , 1.0);' ) -// res = tdSql.getResult("select first(*) from tb1;") -// print(res) -// if res ==[(datetime.datetime(2021, 6, 10, 1, 0, 0, 123000), 1.0)]: -// tdLog.info('check timezone pass about ms database') - - - - - - - - - - -// c1.execute('create database if not exists ' + dbname + ' precision "ns"'); -// c1.execute('use ' + dbname) -// c1.execute('create table if not exists tstest (ts timestamp, _int int);'); -// c1.execute('insert into tstest values(1625801548423914405, 0)'); -// // Select -// console.log('select * from tstest'); -// c1.execute('select * from tstest'); - -// var d = c1.fetchall(); -// console.log(c1.fields); -// let ts = d[0][0]; -// console.log(ts); - -// if (ts.taosTimestamp() != 1625801548423914405) { -// throw "nanosecond not match!"; -// } -// if (ts.getNanoseconds() % 1000000 !== 914405) { -// throw "nanosecond precision error"; -// } -// setTimeout(function () { -// c1.query('drop database nodejs_ns_test;'); -// }, 200); - -// setTimeout(function () { -// conn.close(); -// }, 2000); - - diff --git a/tests/connectorTest/nodejsTest/test/performance.js b/tests/connectorTest/nodejsTest/test/performance.js deleted file mode 100644 index ea197f034435e28edd67df8d5f4b141f410fed81..0000000000000000000000000000000000000000 --- a/tests/connectorTest/nodejsTest/test/performance.js +++ /dev/null @@ -1,89 +0,0 @@ -function memoryUsageData() { - let s = process.memoryUsage() - for (key in s) { - s[key] = (s[key]/1000000).toFixed(3) + "MB"; - } - return s; -} -console.log("initial mem usage:", memoryUsageData()); - -const { PerformanceObserver, performance } = require('perf_hooks'); -const taos = require('../tdengine'); -var conn = taos.connect({host:"127.0.0.1", user:"root", password:"taosdata", config:"/etc/taos",port:0}); -var c1 = conn.cursor(); - -// Initialize env -c1.execute('create database if not exists td_connector_test;'); -c1.execute('use td_connector_test;') -c1.execute('create table if not exists all_types (ts timestamp, _int int, _bigint bigint, _float float, _double double, _binary binary(40), _smallint smallint, _tinyint tinyint, _bool bool, _nchar nchar(40));'); -c1.execute('create table if not exists stabletest (ts timestamp, v1 int, v2 int, v3 int, v4 double) tags (id int, location binary(20));') - - -// Insertion into single table Performance Test -var dataPrepTime = 0; -var insertTime = 0; -var insertTime5000 = 0; -var avgInsert5ktime = 0; -const obs = new PerformanceObserver((items) => { - let entry = items.getEntries()[0]; - - if (entry.name == 'Data Prep') { - dataPrepTime += entry.duration; - } - else if (entry.name == 'Insert'){ - insertTime += entry.duration - } - else { - console.log(entry.name + ': ' + (entry.duration/1000).toFixed(8) + 's'); - } - performance.clearMarks(); -}); -obs.observe({ entryTypes: ['measure'] }); - -function R(l,r) { - return Math.random() * (r - l) - r; -} -function randomBool() { - if (Math.random() < 0.5) { - return true; - } - return false; -} -function insertN(n) { - for (let i = 0; i < n; i++) { - performance.mark('A3'); - let insertData = ["now + " + i + "m", // 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) ), // BigInt - parseFloat( R(-3.4E38, 3.4E38) ), // Float - parseFloat( R(-1.7E308, 1.7E308) ), // Double - "\"Long Binary\"", // Binary - parseInt( R(-32767, 32767) ), // Small Int - parseInt( R(-127, 127) ), // Tiny Int - randomBool(), - "\"Nchars 一些中文字幕\""]; // Bool - let query = 'insert into td_connector_test.all_types values(' + insertData.join(',') + ' );'; - performance.mark('B3'); - performance.measure('Data Prep', 'A3', 'B3'); - performance.mark('A2'); - c1.execute(query, {quiet:true}); - performance.mark('B2'); - performance.measure('Insert', 'A2', 'B2'); - if ( i % 5000 == 4999) { - console.log("Insert # " + (i+1)); - console.log('Insert 5k records: ' + ((insertTime - insertTime5000)/1000).toFixed(8) + 's'); - insertTime5000 = insertTime; - avgInsert5ktime = (avgInsert5ktime/1000 * Math.floor(i / 5000) + insertTime5000/1000) / Math.ceil( i / 5000); - console.log('DataPrepTime So Far: ' + (dataPrepTime/1000).toFixed(8) + 's | Inserting time So Far: ' + (insertTime/1000).toFixed(8) + 's | Avg. Insert 5k time: ' + avgInsert5ktime.toFixed(8)); - - - } - } -} -performance.mark('insert 1E5') -insertN(1E5); -performance.mark('insert 1E5 2') -performance.measure('Insert With Logs', 'insert 1E5', 'insert 1E5 2'); -console.log('DataPrepTime: ' + (dataPrepTime/1000).toFixed(8) + 's | Inserting time: ' + (insertTime/1000).toFixed(8) + 's'); -dataPrepTime = 0; insertTime = 0; -//'insert into td_connector_test.all_types values (now, null,null,null,null,null,null,null,null,null);' diff --git a/tests/connectorTest/nodejsTest/test/test.js b/tests/connectorTest/nodejsTest/test/test.js deleted file mode 100644 index caf05955da4c960ebedc872f400c17d18be767dd..0000000000000000000000000000000000000000 --- a/tests/connectorTest/nodejsTest/test/test.js +++ /dev/null @@ -1,170 +0,0 @@ -const taos = require('../tdengine'); -var conn = taos.connect(); -var c1 = conn.cursor(); -let stime = new Date(); -let interval = 1000; - -function convertDateToTS(date) { - let tsArr = date.toISOString().split("T") - return "\"" + tsArr[0] + " " + tsArr[1].substring(0, tsArr[1].length-1) + "\""; -} -function R(l,r) { - return Math.random() * (r - l) - r; -} -function randomBool() { - if (Math.random() < 0.5) { - return true; - } - return false; -} - -// Initialize -//c1.execute('drop database td_connector_test;'); -c1.execute('create database if not exists td_connector_test;'); -c1.execute('use td_connector_test;') -c1.execute('create table if not exists all_types (ts timestamp, _int int, _bigint bigint, _float float, _double double, _binary binary(40), _smallint smallint, _tinyint tinyint, _bool bool, _nchar nchar(40));'); -c1.execute('create table if not exists stabletest (ts timestamp, v1 int, v2 int, v3 int, v4 double) tags (id int, location binary(20));') - -// Shell Test : The following uses the cursor to imitate the taos shell - -// Insert -for (let i = 0; i < 10000; i++) { - 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) ), // BigInt - parseFloat( R(-3.4E38, 3.4E38) ), // Float - parseFloat( R(-1.7E30, 1.7E30) ), // Double - "\"Long Binary\"", // Binary - parseInt( R(-32767, 32767) ), // Small Int - parseInt( R(-127, 127) ), // Tiny Int - randomBool(), - "\"Nchars\""]; // Bool - c1.execute('insert into td_connector_test.all_types values(' + insertData.join(',') + ' );', {quiet:true}); - if (i % 1000 == 0) { - console.log("Insert # " , i); - } -} - -// Select -console.log('select * from td_connector_test.all_types limit 3 offset 100;'); -c1.execute('select * from td_connector_test.all_types limit 2 offset 100;'); - -var d = c1.fetchall(); -console.log(c1.fields); -console.log(d); - -// Functions -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;'); -var d = c1.fetchall(); -console.log(c1.fields); -console.log(d); - -// 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){ - result.pretty(); -}) - -c1.query('select _tinyint, _bool from all_types where _tinyint > 50 and _int < 0 limit 50;', true).then(function(result){ - result.pretty(); -}) - -c1.query('select stddev(_double), stddev(_bigint), stddev(_float) from all_types;', true).then(function(result){ - result.pretty(); -}) -c1.query('select stddev(_double), stddev(_bigint), stddev(_float) from all_types interval(1m) limit 100;', true).then(function(result){ - result.pretty(); -}) - -// Binding arguments, and then using promise -var q = c1.query('select _nchar from td_connector_test.all_types where ts >= ? and _int > ? limit 100 offset 40;').bind(new Date(1231), 100) -console.log(q.query); -q.execute().then(function(r) { - r.pretty(); -}); - - -// test query null value -c1.execute("create table if not exists td_connector_test.weather(ts timestamp, temperature float, humidity int) tags(location nchar(64))"); -c1.execute("insert into t1 using weather tags('北京') values(now, 11.11, 11)"); -c1.execute("insert into t1(ts, temperature) values(now, 22.22)"); -c1.execute("insert into t1(ts, humidity) values(now, 33)"); -c1.query('select * from test.t1', true).then(function (result) { - result.pretty(); -}); - -var q = c1.query('select * from td_connector_test.weather'); -console.log(q.query); -q.execute().then(function(r) { - r.pretty(); -}); - -function sleep(sleepTime) { - for(var start = +new Date; +new Date - start <= sleepTime; ) { } -} - -sleep(10000); - -// Raw Async Testing (Callbacks, not promises) -function cb2(param, result, rowCount, rd) { - console.log('CB2 Callbacked!'); - console.log("RES *", result); - console.log("Async fetched", rowCount, " rows"); - console.log("Passed Param: ", param); - console.log("Fields ", rd.fields); - console.log("Data ", rd.data); -} -function cb1(param,result,code) { - console.log('CB1 Callbacked!'); - console.log("RES * ", result); - console.log("Status: ", code); - console.log("Passed Param ", param); - c1.fetchall_a(result, cb2, param); -} - -c1.execute_a("describe td_connector_test.all_types;", cb1, {myparam:3.141}); - -function cb4(param, result, rowCount, rd) { - console.log('CB4 Callbacked!'); - console.log("RES *", result); - console.log("Async fetched", rowCount, "rows"); - console.log("Passed Param: ", param); - console.log("Fields", rd.fields); - console.log("Data", rd.data); -} -// Without directly calling fetchall_a -var thisRes; -function cb3(param,result,code) { - console.log('CB3 Callbacked!'); - console.log("RES *", result); - console.log("Status:", code); - console.log("Passed Param", param); - thisRes = result; -} -//Test calling execute and fetchall seperately and not through callbacks -var param = c1.execute_a("describe td_connector_test.all_types;", cb3, {e:2.718}); -console.log("Passed Param outside of callback: ", param); -console.log(param); -setTimeout(function(){ - c1.fetchall_a(thisRes, cb4, param); -},100); - - -// Async through promises -var aq = c1.query('select count(*) from td_connector_test.all_types;',false); -aq.execute_a().then(function(data) { - data.pretty(); -}); - -c1.query('describe td_connector_test.stabletest').execute_a().then(function(r){ - r.pretty() -}); - -setTimeout(function(){ - c1.query('drop database td_connector_test;'); -},200); - -setTimeout(function(){ - conn.close(); -},2000); diff --git a/tests/connectorTest/nodejsTest/test/testMicroseconds.js b/tests/connectorTest/nodejsTest/test/testMicroseconds.js deleted file mode 100644 index cc65b3d919f92b3b4d7e0e216c6c8ac64a294d7f..0000000000000000000000000000000000000000 --- a/tests/connectorTest/nodejsTest/test/testMicroseconds.js +++ /dev/null @@ -1,49 +0,0 @@ -const taos = require('../tdengine'); -var conn = taos.connect(); -var c1 = conn.cursor(); -let stime = new Date(); -let interval = 1000; - -function convertDateToTS(date) { - let tsArr = date.toISOString().split("T") - return "\"" + tsArr[0] + " " + tsArr[1].substring(0, tsArr[1].length - 1) + "\""; -} -function R(l, r) { - return Math.random() * (r - l) - r; -} -function randomBool() { - if (Math.random() < 0.5) { - return true; - } - return false; -} - -// Initialize -//c1.execute('drop database td_connector_test;'); -const dbname = 'nodejs_test_us'; -c1.execute('create database if not exists ' + dbname + ' precision "us"'); -c1.execute('use ' + dbname) -c1.execute('create table if not exists tstest (ts timestamp, _int int);'); -c1.execute('insert into tstest values(1625801548423914, 0)'); -// Select -console.log('select * from tstest'); -c1.execute('select * from tstest'); - -var d = c1.fetchall(); -console.log(c1.fields); -let ts = d[0][0]; -console.log(ts); - -if (ts.taosTimestamp() != 1625801548423914) { - throw "microseconds not match!"; -} -if (ts.getMicroseconds() % 1000 !== 914) { - throw "micronsecond precision error"; -} -setTimeout(function () { - c1.query('drop database nodejs_us_test;'); -}, 200); - -setTimeout(function () { - conn.close(); -}, 2000); diff --git a/tests/connectorTest/nodejsTest/test/testNanoseconds.js b/tests/connectorTest/nodejsTest/test/testNanoseconds.js deleted file mode 100644 index 85a7600b01f2c908f22e621488f22678083149ea..0000000000000000000000000000000000000000 --- a/tests/connectorTest/nodejsTest/test/testNanoseconds.js +++ /dev/null @@ -1,49 +0,0 @@ -const taos = require('../tdengine'); -var conn = taos.connect(); -var c1 = conn.cursor(); -let stime = new Date(); -let interval = 1000; - -function convertDateToTS(date) { - let tsArr = date.toISOString().split("T") - return "\"" + tsArr[0] + " " + tsArr[1].substring(0, tsArr[1].length - 1) + "\""; -} -function R(l, r) { - return Math.random() * (r - l) - r; -} -function randomBool() { - if (Math.random() < 0.5) { - return true; - } - return false; -} - -// Initialize -//c1.execute('drop database td_connector_test;'); -const dbname = 'nodejs_test_ns'; -c1.execute('create database if not exists ' + dbname + ' precision "ns"'); -c1.execute('use ' + dbname) -c1.execute('create table if not exists tstest (ts timestamp, _int int);'); -c1.execute('insert into tstest values(1625801548423914405, 0)'); -// Select -console.log('select * from tstest'); -c1.execute('select * from tstest'); - -var d = c1.fetchall(); -console.log(c1.fields); -let ts = d[0][0]; -console.log(ts); - -if (ts.taosTimestamp() != 1625801548423914405) { - throw "nanosecond not match!"; -} -if (ts.getNanoseconds() % 1000000 !== 914405) { - throw "nanosecond precision error"; -} -setTimeout(function () { - c1.query('drop database nodejs_ns_test;'); -}, 200); - -setTimeout(function () { - conn.close(); -}, 2000); diff --git a/tests/connectorTest/nodejsTest/test/testSubscribe.js b/tests/connectorTest/nodejsTest/test/testSubscribe.js deleted file mode 100644 index 30fb3f425683f0113873534f2b67255db811edcc..0000000000000000000000000000000000000000 --- a/tests/connectorTest/nodejsTest/test/testSubscribe.js +++ /dev/null @@ -1,16 +0,0 @@ -const taos = require('../tdengine'); -var conn = taos.connect({host:"127.0.0.1", user:"root", password:"taosdata", config:"/etc/taos",port:10}); -var c1 = conn.cursor(); -let stime = new Date(); -let interval = 1000; -c1.execute('use td_connector_test'); -let sub = c1.subscribe({ - restart: true, - sql: "select AVG(_int) from td_connector_test.all_Types;", - topic: 'all_Types', - interval: 1000 -}); - -c1.consumeData(sub, (data, fields) => { - console.log(data); -}); \ No newline at end of file diff --git a/tests/connectorTest/odbcTest/nanosupport/nanoTest_odbc.py b/tests/connectorTest/odbcTest/nanosupport/nanoTest_odbc.py deleted file mode 100644 index e6a4bc73aef3e19bc56e817325acd62d21156d67..0000000000000000000000000000000000000000 --- a/tests/connectorTest/odbcTest/nanosupport/nanoTest_odbc.py +++ /dev/null @@ -1,111 +0,0 @@ -import pyodbc -import argparse -import sys - -parser = argparse.ArgumentParser(description='Access TDengine via ODBC.') -parser.add_argument('--DSN', help='DSN to use') -parser.add_argument('--UID', help='UID to use') -parser.add_argument('--PWD', help='PWD to use') -parser.add_argument('--Server', help='Server to use') -parser.add_argument('-C', metavar='CONNSTR', help='Connection string to use') - -args = parser.parse_args() - -a = 'DSN=%s'%args.DSN if args.DSN else None -b = 'UID=%s'%args.UID if args.UID else None -c = 'PWD=%s'%args.PWD if args.PWD else None -d = 'Server=%s'%args.Server if args.Server else None -conn_str = ';'.join(filter(None, [a,b,c,d])) if args.DSN else None -conn_str = conn_str if conn_str else args.C -if not conn_str: - parser.print_help(file=sys.stderr) - exit() - -print('connecting: [%s]' % conn_str) -cnxn = pyodbc.connect(conn_str, autocommit=True) -cnxn.setdecoding(pyodbc.SQL_CHAR, encoding='utf-8') - -cursor = cnxn.cursor() -cursor.execute("drop database if exists db"); -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("create database db"); -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("create table db.mt (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(10), blob nchar(10))"); -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("insert into db.mt values('2020-10-13 06:44:00.123', 1, 127, 32767, 2147483647, 32769, 123.456, 789.987, 'hello', 'helloworld')") -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("insert into db.mt values(?,?,?,?,?,?,?,?,?,?)", "2020-10-13 07:06:00.234", 0, 127, 32767, 32768, 32769, 123.456, 789.987, "hel后lo".encode('utf-8'), "wo哈rlxd129") -##cursor.execute("insert into db.mt values(?,?,?,?,?,?,?,?,?,?)", 1502535178128, 9223372036854775807, 127, 32767, 32768, 32769, 123.456, 789.987, "hel后lo".encode('utf-8'), "wo哈rlxd123"); -cursor.close() - -cursor = cnxn.cursor() -cursor.execute(""" -INSERT INTO db.mt (ts,b,v1,v2,v4,v8,f4,f8,bin,blob) values (?,?,?,?,?,?,?,?,?,?) -""", -"2020-12-12 00:00:00", -'true', -'-127', -'-32767', -'-2147483647', -'-9223372036854775807', -'-1.23e10', -'-11.23e6', -'abcdefghij'.encode('utf-8'), -"人啊大发测试及abc") -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("drop database if exists db"); -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("create database db"); -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("create table db.t (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(4), blob nchar(4))"); -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("insert into db.t values('2020-10-13 06:44:00', 1, 127, 32767, 32768, 32769, 123.456, 789.987, 'hell', 'w我你z')") -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("create table db.v (ts timestamp, v1 tinyint, v2 smallint, name nchar(10), ts2 timestamp)") -cursor.close() - -params = [ ('2020-10-16 00:00:00.123', 19, '2111-01-02 01:02:03.123'), - ('2020-10-16 00:00:01', 41, '2111-01-02 01:02:03.423'), - ('2020-10-16 00:00:02', 57, '2111-01-02 01:02:03.153'), - ('2020-10-16 00:00:03.009', 26, '2111-01-02 01:02:03.623') ] -cursor = cnxn.cursor() -cursor.fast_executemany = True -print('py:...................') -cursor.executemany("insert into db.v (ts, v1, ts2) values (?, ?, ?)", params) -print('py:...................') -cursor.close() - -## cursor = cnxn.cursor() -## cursor.execute("SELECT * from db.v where v1 > ?", 4) -## row = cursor.fetchone() -## while row: -## print(row) -## row = cursor.fetchone() -## cursor.close() -## -## cursor = cnxn.cursor() -## cursor.execute("SELECT * from db.v where v1 > ?", '5') -## row = cursor.fetchone() -## while row: -## print(row) -## row = cursor.fetchone() -## cursor.close() - diff --git a/tests/connectorTest/odbcTest/nanosupport/odbc.go b/tests/connectorTest/odbcTest/nanosupport/odbc.go deleted file mode 100644 index 4d9c760c4e87a4a899051edc74692ecca8a19d15..0000000000000000000000000000000000000000 --- a/tests/connectorTest/odbcTest/nanosupport/odbc.go +++ /dev/null @@ -1,84 +0,0 @@ -package main - -import ( - "context" - "database/sql" - "flag" - "log" - "os" - "os/signal" - "time" - _ "github.com/alexbrainman/odbc" -) - -var pool *sql.DB // Database connection pool. - -func main() { - id := flag.Int64("id", 32768, "person ID to find") - dsn := flag.String("dsn", os.Getenv("DSN"), "connection data source name") - flag.Parse() - - if len(*dsn) == 0 { - log.Fatal("missing dsn flag") - } - if *id == 0 { - log.Fatal("missing person ID") - } - var err error - - // Opening a driver typically will not attempt to connect to the database. - pool, err = sql.Open("odbc", *dsn) - if err != nil { - // This will not be a connection error, but a DSN parse error or - // another initialization error. - log.Fatal("unable to use data source name", err) - } - defer pool.Close() - - pool.SetConnMaxLifetime(0) - pool.SetMaxIdleConns(3) - pool.SetMaxOpenConns(3) - - ctx, stop := context.WithCancel(context.Background()) - defer stop() - - appSignal := make(chan os.Signal, 3) - signal.Notify(appSignal, os.Interrupt) - - go func() { - select { - case <-appSignal: - stop() - } - }() - - Ping(ctx) - - Query(ctx, *id) -} - -// Ping the database to verify DSN provided by the user is valid and the -// server accessible. If the ping fails exit the program with an error. -func Ping(ctx context.Context) { - ctx, cancel := context.WithTimeout(ctx, 1*time.Second) - defer cancel() - - if err := pool.PingContext(ctx); err != nil { - log.Fatalf("unable to connect to database: %v", err) - } -} - -// Query the database for the information requested and prints the results. -// If the query fails exit the program with an error. -func Query(ctx context.Context, id int64) { - ctx, cancel := context.WithTimeout(ctx, 5*time.Second) - defer cancel() - - var name string - err := pool.QueryRowContext(ctx, "select name from m.t").Scan(&name) - if err != nil { - log.Fatal("unable to execute search query", err) - } - log.Println("name=", name) -} - diff --git a/tests/connectorTest/odbcTest/nanosupport/odbc.py b/tests/connectorTest/odbcTest/nanosupport/odbc.py deleted file mode 100644 index cee0cf1a13f6360790de368637e2b6a05de3564f..0000000000000000000000000000000000000000 --- a/tests/connectorTest/odbcTest/nanosupport/odbc.py +++ /dev/null @@ -1,115 +0,0 @@ -import pyodbc -import argparse -import sys - -parser = argparse.ArgumentParser(description='Access TDengine via ODBC.') -parser.add_argument('--DSN', help='DSN to use') -parser.add_argument('--UID', help='UID to use') -parser.add_argument('--PWD', help='PWD to use') -parser.add_argument('--Server', help='Server to use') -parser.add_argument('-C', metavar='CONNSTR', help='Connection string to use') - -args = parser.parse_args() - -a = 'DSN=%s'%args.DSN if args.DSN else None -b = 'UID=%s'%args.UID if args.UID else None -c = 'PWD=%s'%args.PWD if args.PWD else None -d = 'Server=%s'%args.Server if args.Server else None -conn_str = ';'.join(filter(None, [a,b,c,d])) if args.DSN else None -conn_str = conn_str if conn_str else args.C -if not conn_str: - parser.print_help(file=sys.stderr) - exit() - -print('connecting: [%s]' % conn_str) -cnxn = pyodbc.connect(conn_str, autocommit=True) -cnxn.setdecoding(pyodbc.SQL_CHAR, encoding='utf-8') - -cursor = cnxn.cursor() -cursor.execute("drop database if exists db"); -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("create database db"); -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("create table db.mt (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(10), blob nchar(10))"); -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("insert into db.mt values('2020-10-13 06:44:00.123', 1, 127, 32767, 2147483647, 32769, 123.456, 789.987, 'hello', 'helloworld')") -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("insert into db.mt values(?,?,?,?,?,?,?,?,?,?)", "2020-10-13 07:06:00.234", 0, 127, 32767, 32768, 32769, 123.456, 789.987, "hel后lo".encode('utf-8'), "wo哈rlxd129") -##cursor.execute("insert into db.mt values(?,?,?,?,?,?,?,?,?,?)", 1502535178128, 9223372036854775807, 127, 32767, 32768, 32769, 123.456, 789.987, "hel后lo".encode('utf-8'), "wo哈rlxd123"); -cursor.close() - -cursor = cnxn.cursor() -cursor.execute(""" -INSERT INTO db.mt (ts,b,v1,v2,v4,v8,f4,f8,bin,blob) values (?,?,?,?,?,?,?,?,?,?) -""", -"2020-12-12 00:00:00", -'true', -'-127', -'-32767', -'-2147483647', -'-9223372036854775807', -'-1.23e10', -'-11.23e6', -'abcdefghij'.encode('utf-8'), -"人啊大发测试及abc") -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("drop database if exists db"); -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("create database db"); -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("create table db.t (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(4), blob nchar(4))"); -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("insert into db.t values('2020-10-13 06:44:00', 1, 127, 32767, 32768, 32769, 123.456, 789.987, 'hell', 'w我你z')") -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("create table db.v (ts timestamp, v1 tinyint, v2 smallint, name nchar(10), ts2 timestamp)") -cursor.close() - -cursor = cnxn.cursor() -cursor.execute("select * from db.v") -cursor.close() - -params = [ ('2020-10-16 00:00:00.123', 19, '2111-01-02 01:02:03.123'), - ('2020-10-16 00:00:01', 41, '2111-01-02 01:02:03.423'), - ('2020-10-16 00:00:02', 57, '2111-01-02 01:02:03.153'), - ('2020-10-16 00:00:03.009', 26, '2111-01-02 01:02:03.623') ] -cursor = cnxn.cursor() -cursor.fast_executemany = True -print('py:...................') -cursor.executemany("insert into db.v (ts, v1, ts2) values (?, ?, ?)", params) -print('py:...................') -cursor.close() - -## cursor = cnxn.cursor() -## cursor.execute("SELECT * from db.v where v1 > ?", 4) -## row = cursor.fetchone() -## while row: -## print(row) -## row = cursor.fetchone() -## cursor.close() -## -## cursor = cnxn.cursor() -## cursor.execute("SELECT * from db.v where v1 > ?", '5') -## row = cursor.fetchone() -## while row: -## print(row) -## row = cursor.fetchone() -## cursor.close() - diff --git a/tests/gotest/batchtest.sh b/tests/gotest/batchtest.sh index 95d984a7013ef4e7715af8764531434a564a382b..8f5a7fe8f032134e55c9d9675361590ed6d5b19b 100755 --- a/tests/gotest/batchtest.sh +++ b/tests/gotest/batchtest.sh @@ -19,6 +19,3 @@ go env -w GOPROXY=https://goproxy.io,direct bash ./case001/case001.sh $severIp $serverPort bash ./case002/case002.sh $severIp $serverPort #bash ./case003/case003.sh $severIp $serverPort - -cd nanosupport -go run main.go diff --git a/tests/gotest/case001/case001.go b/tests/gotest/case001/case001.go index 29bc92f2a0668b3f576145d5bd6d08ed37c82f1b..9d35888f313461a2ce90c7a6ed4ef2791229866c 100644 --- a/tests/gotest/case001/case001.go +++ b/tests/gotest/case001/case001.go @@ -12,6 +12,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ + package main import ( diff --git a/tests/gotest/case001/case001.sh b/tests/gotest/case001/case001.sh index 831e9f83ac482c0a2c668e2ad0d16c4bf59f19aa..94e5bb44e03a1f7d2704752fcf9c080abcb4f23f 100644 --- a/tests/gotest/case001/case001.sh +++ b/tests/gotest/case001/case001.sh @@ -15,7 +15,8 @@ script_dir="$(dirname $(readlink -f $0))" ###### step 3: start build cd $script_dir rm -f go.* -go mod init demotest -go build +go mod init demotest > /dev/null 2>&1 +go mod tidy > /dev/null 2>&1 +go build > /dev/null 2>&1 sleep 1s ./demotest -h $1 -p $2 diff --git a/tests/gotest/case001/demotest b/tests/gotest/case001/demotest deleted file mode 100755 index c9422c3497d8ebbf45d1cf7a68a408b9f2a5c785..0000000000000000000000000000000000000000 Binary files a/tests/gotest/case001/demotest and /dev/null differ diff --git a/tests/gotest/case001/go.mod b/tests/gotest/case001/go.mod deleted file mode 100644 index 71f1979348ad92cf903fc2036aa0a45c0384b7a1..0000000000000000000000000000000000000000 --- a/tests/gotest/case001/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module demotest - -go 1.13 - -require github.com/taosdata/driver-go v0.0.0-20210811072315-2cda9f1dc9ed diff --git a/tests/gotest/case001/go.sum b/tests/gotest/case001/go.sum deleted file mode 100644 index 0b56f082753bda620823217408bf5e6f3a41586b..0000000000000000000000000000000000000000 --- a/tests/gotest/case001/go.sum +++ /dev/null @@ -1,8 +0,0 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/taosdata/driver-go v0.0.0-20210811072315-2cda9f1dc9ed h1:inSmPB0XSiyPZ6B66KnMsfyVVshH0mg2L0ld1b2aLtA= -github.com/taosdata/driver-go v0.0.0-20210811072315-2cda9f1dc9ed/go.mod h1:k0UvvUy5mlSz4M+InxT3MZYO/eaTWXs7hO9ndLTeevU= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/tests/gotest/nanosupport/connector/executor.go b/tests/gotest/nanosupport/connector/executor.go deleted file mode 100644 index 218ea29af3b34a8cfb5ab56585eeb07bc467d209..0000000000000000000000000000000000000000 --- a/tests/gotest/nanosupport/connector/executor.go +++ /dev/null @@ -1,208 +0,0 @@ -package connector - -import ( - "context" - "fmt" - "reflect" - "time" - - "github.com/taosdata/go-utils/log" - "github.com/taosdata/go-utils/tdengine/config" - "github.com/taosdata/go-utils/tdengine/connector" - tdengineExecutor "github.com/taosdata/go-utils/tdengine/executor" -) - -type Executor struct { - executor *tdengineExecutor.Executor - ctx context.Context -} - -var Logger = log.NewLogger("taos test") - -func NewExecutor(conf *config.TDengineGo, db string, showSql bool) (*Executor, error) { - tdengineConnector, err := connector.NewTDengineConnector("go", conf) - if err != nil { - return nil, err - } - executor := tdengineExecutor.NewExecutor(tdengineConnector, db, showSql, Logger) - return &Executor{ - executor: executor, - ctx: context.Background(), - }, nil -} - -func (e *Executor) Execute(sql string) (int64, error) { - return e.executor.DoExec(e.ctx, sql) -} -func (e *Executor) Query(sql string) (*connector.Data, error) { - fmt.Println("query :", sql) - return e.executor.DoQuery(e.ctx, sql) -} -func (e *Executor) CheckData(row, col int, value interface{}, data *connector.Data) (bool, error) { - if data == nil { - return false, fmt.Errorf("data is nil") - } - if col >= len(data.Head) { - return false, fmt.Errorf("col out of data") - } - if row >= len(data.Data) { - return false, fmt.Errorf("row out of data") - } - dataValue := data.Data[row][col] - - if dataValue == nil && value != nil { - return false, fmt.Errorf("dataValue is nil but value is not nil") - } - if dataValue == nil && value == nil { - return true, nil - } - if reflect.TypeOf(dataValue) != reflect.TypeOf(value) { - return false, fmt.Errorf("type not match expect %s got %s", reflect.TypeOf(value), reflect.TypeOf(dataValue)) - } - switch value.(type) { - case time.Time: - t, _ := dataValue.(time.Time) - if value.(time.Time).Nanosecond() != t.Nanosecond() { - return false, fmt.Errorf("value not match expect %d got %d", value.(time.Time).Nanosecond(), t.Nanosecond()) - } - case string: - if value.(string) != dataValue.(string) { - return false, fmt.Errorf("value not match expect %s got %s", value.(string), dataValue.(string)) - } - case int8: - if value.(int8) != dataValue.(int8) { - return false, fmt.Errorf("value not match expect %d got %d", value.(int8), dataValue.(int8)) - } - case int16: - if value.(int16) != dataValue.(int16) { - return false, fmt.Errorf("value not match expect %d got %d", value.(int16), dataValue.(int16)) - } - case int32: - if value.(int32) != dataValue.(int32) { - return false, fmt.Errorf("value not match expect %d got %d", value.(int32), dataValue.(int32)) - } - case int64: - if value.(int64) != dataValue.(int64) { - return false, fmt.Errorf("value not match expect %d got %d", value.(int64), dataValue.(int64)) - } - case float32: - if value.(float32) != dataValue.(float32) { - return false, fmt.Errorf("value not match expect %f got %f", value.(float32), dataValue.(float32)) - } - case float64: - if value.(float64) != dataValue.(float64) { - return false, fmt.Errorf("value not match expect %f got %f", value.(float32), dataValue.(float32)) - } - case bool: - if value.(bool) != dataValue.(bool) { - return false, fmt.Errorf("value not match expect %t got %t", value.(bool), dataValue.(bool)) - } - default: - return false, fmt.Errorf("unsupport type %v", reflect.TypeOf(value)) - } - return true, nil -} - -func (e *Executor) CheckData2(row, col int, value interface{}, data *connector.Data) { - - match, err := e.CheckData(row, col, value, data) - fmt.Println("expect data is :", value) - fmt.Println("go got data is :", data.Data[row][col]) - if err != nil { - fmt.Println(err) - } - if !match { - fmt.Println(" data not match") - - } - - /* - fmt.Println(value) - if data == nil { - // return false, fmt.Errorf("data is nil") - // fmt.Println("check failed") - } - if col >= len(data.Head) { - // return false, fmt.Errorf("col out of data") - // fmt.Println("check failed") - } - if row >= len(data.Data) { - // return false, fmt.Errorf("row out of data") - // fmt.Println("check failed") - } - dataValue := data.Data[row][col] - - if dataValue == nil && value != nil { - // return false, fmt.Errorf("dataValue is nil but value is not nil") - // fmt.Println("check failed") - } - if dataValue == nil && value == nil { - // return true, nil - fmt.Println("check pass") - } - if reflect.TypeOf(dataValue) != reflect.TypeOf(value) { - // return false, fmt.Errorf("type not match expect %s got %s", reflect.TypeOf(value), reflect.TypeOf(dataValue)) - fmt.Println("check failed") - } - switch value.(type) { - case time.Time: - t, _ := dataValue.(time.Time) - if value.(time.Time).Nanosecond() != t.Nanosecond() { - // return false, fmt.Errorf("value not match expect %d got %d", value.(time.Time).Nanosecond(), t.Nanosecond()) - // fmt.Println("check failed") - } - case string: - if value.(string) != dataValue.(string) { - // return false, fmt.Errorf("value not match expect %s got %s", value.(string), dataValue.(string)) - // fmt.Println("check failed") - } - case int8: - if value.(int8) != dataValue.(int8) { - // return false, fmt.Errorf("value not match expect %d got %d", value.(int8), dataValue.(int8)) - // fmt.Println("check failed") - } - case int16: - if value.(int16) != dataValue.(int16) { - // return false, fmt.Errorf("value not match expect %d got %d", value.(int16), dataValue.(int16)) - // fmt.Println("check failed") - } - case int32: - if value.(int32) != dataValue.(int32) { - // return false, fmt.Errorf("value not match expect %d got %d", value.(int32), dataValue.(int32)) - // fmt.Println("check failed") - } - case int64: - if value.(int64) != dataValue.(int64) { - // return false, fmt.Errorf("value not match expect %d got %d", value.(int64), dataValue.(int64)) - // fmt.Println("check failed") - } - case float32: - if value.(float32) != dataValue.(float32) { - // return false, fmt.Errorf("value not match expect %f got %f", value.(float32), dataValue.(float32)) - // fmt.Println("check failed") - } - case float64: - if value.(float64) != dataValue.(float64) { - // return false, fmt.Errorf("value not match expect %f got %f", value.(float32), dataValue.(float32)) - // fmt.Println("check failed") - } - case bool: - if value.(bool) != dataValue.(bool) { - // return false, fmt.Errorf("value not match expect %t got %t", value.(bool), dataValue.(bool)) - // fmt.Println("check failed") - } - default: - // return false, fmt.Errorf("unsupport type %v", reflect.TypeOf(value)) - // fmt.Println("check failed") - } - // return true, nil - // fmt.Println("check pass") - */ -} - -func (e *Executor) CheckRow(count int, data *connector.Data) { - - if len(data.Data) != count { - fmt.Println("check failed !") - } -} diff --git a/tests/gotest/nanosupport/go.mod b/tests/gotest/nanosupport/go.mod deleted file mode 100644 index 6b0a0021f394bdc40a77c24d37b07df969b1a541..0000000000000000000000000000000000000000 --- a/tests/gotest/nanosupport/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module taos - -go 1.16 - -require github.com/taosdata/go-utils v0.0.0-20210811075537-2ce661ccb743 diff --git a/tests/gotest/nanosupport/go.sum b/tests/gotest/nanosupport/go.sum deleted file mode 100644 index ef93bc6a0940ad371442bada008f0fa3c4acaf90..0000000000000000000000000000000000000000 --- a/tests/gotest/nanosupport/go.sum +++ /dev/null @@ -1,75 +0,0 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/gin-contrib/cors v1.3.1/go.mod h1:jjEJ4268OPZUcU7k9Pm653S7lXUGcqMADzFA61xsmDk= -github.com/gin-contrib/gzip v0.0.3/go.mod h1:YxxswVZIqOvcHEQpsSn+QF5guQtO1dCfy0shBPy4jFc= -github.com/gin-contrib/pprof v1.3.0/go.mod h1:waMjT1H9b179t3CxuG1cV3DHpga6ybizwfBaM5OXaB0= -github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do= -github.com/gin-gonic/gin v1.6.2/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= -github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= -github.com/gin-gonic/gin v1.7.2/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY= -github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= -github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= -github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= -github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= -github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= -github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= -github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ= -github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= -github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/panjf2000/ants/v2 v2.4.6 h1:drmj9mcygn2gawZ155dRbo+NfXEfAssjZNU1qoIb4gQ= -github.com/panjf2000/ants/v2 v2.4.6/go.mod h1:f6F0NZVFsGCp5A7QW/Zj/m92atWwOkY0OIhFxRNFr4A= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= -github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/taosdata/driver-go v0.0.0-20210811072315-2cda9f1dc9ed h1:inSmPB0XSiyPZ6B66KnMsfyVVshH0mg2L0ld1b2aLtA= -github.com/taosdata/driver-go v0.0.0-20210811072315-2cda9f1dc9ed/go.mod h1:k0UvvUy5mlSz4M+InxT3MZYO/eaTWXs7hO9ndLTeevU= -github.com/taosdata/go-utils v0.0.0-20210811075537-2ce661ccb743 h1:w90OkSLXv4d7uEcU8fH70pB5tawNYYZ1qjhDfg7oFTQ= -github.com/taosdata/go-utils v0.0.0-20210811075537-2ce661ccb743/go.mod h1:WRQlPHYbVvsRmtIDJ4GS31BbiTQnFHFdhh0XpLavTIg= -github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= -github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= -gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/tests/gotest/nanosupport/main.go b/tests/gotest/nanosupport/main.go deleted file mode 100644 index c5440c81f6c6708be227c36e52a1a4747a2e3011..0000000000000000000000000000000000000000 --- a/tests/gotest/nanosupport/main.go +++ /dev/null @@ -1,269 +0,0 @@ -package main - -import ( - "fmt" - "log" - "taos/connector" - "time" - - "github.com/taosdata/go-utils/tdengine/config" -) - -func main() { - e, err := connector.NewExecutor(&config.TDengineGo{ - Address: "root:taosdata@/tcp(127.0.0.1:6030)/", - MaxIdle: 20, - MaxOpen: 30, - MaxLifetime: 30, - }, "db", false) - if err != nil { - panic(err) - } - prepareData(e) - data, err := e.Query("select * from tb") - if err != nil { - panic(err) - } - - layout := "2006-01-02 15:04:05.999999999" - t0, _ := time.Parse(layout, "2021-06-10 00:00:00.100000001") - t1, _ := time.Parse(layout, "2021-06-10 00:00:00.150000000") - t2, _ := time.Parse(layout, "2021-06-10 00:00:00.299999999") - t3, _ := time.Parse(layout, "2021-06-10 00:00:00.300000000") - t4, _ := time.Parse(layout, "2021-06-10 00:00:00.300000001") - t5, _ := time.Parse(layout, "2021-06-10 00:00:00.999999999") - - e.CheckData2(0, 0, t0, data) - e.CheckData2(1, 0, t1, data) - e.CheckData2(2, 0, t2, data) - e.CheckData2(3, 0, t3, data) - e.CheckData2(4, 0, t4, data) - e.CheckData2(5, 0, t5, data) - e.CheckData2(3, 1, int32(3), data) - e.CheckData2(4, 1, int32(5), data) - e.CheckData2(5, 1, int32(7), data) - - fmt.Println(" start check nano support!") - - data, _ = e.Query("select count(*) from tb where ts > 1623254400100000000 and ts < 1623254400100000002;") - e.CheckData2(0, 0, int64(1), data) - - data, _ = e.Query("select count(*) from tb where ts > \"2021-06-10 0:00:00.100000001\" and ts < \"2021-06-10 0:00:00.160000000\";") - e.CheckData2(0, 0, int64(1), data) - - data, _ = e.Query("select count(*) from tb where ts > 1623254400100000000 and ts < 1623254400150000000;") - e.CheckData2(0, 0, int64(1), data) - data, _ = e.Query("select count(*) from tb where ts > \"2021-06-10 0:00:00.100000000\" and ts < \"2021-06-10 0:00:00.150000000\";") - e.CheckData2(0, 0, int64(1), data) - - data, _ = e.Query("select count(*) from tb where ts > 1623254400400000000;") - e.CheckData2(0, 0, int64(1), data) - data, _ = e.Query("select count(*) from tb where ts < \"2021-06-10 00:00:00.400000000\";") - e.CheckData2(0, 0, int64(5), data) - - data, _ = e.Query("select count(*) from tb where ts < now + 400000000b;") - e.CheckData2(0, 0, int64(6), data) - - data, _ = e.Query("select count(*) from tb where ts >= \"2021-06-10 0:00:00.100000001\";") - e.CheckData2(0, 0, int64(6), data) - - data, _ = e.Query("select count(*) from tb where ts <= 1623254400300000000;") - e.CheckData2(0, 0, int64(4), data) - - data, _ = e.Query("select count(*) from tb where ts = \"2021-06-10 0:00:00.000000000\";") - - data, _ = e.Query("select count(*) from tb where ts = 1623254400150000000;") - e.CheckData2(0, 0, int64(1), data) - - data, _ = e.Query("select count(*) from tb where ts = \"2021-06-10 0:00:00.100000001\";") - e.CheckData2(0, 0, int64(1), data) - - data, _ = e.Query("select count(*) from tb where ts between 1623254400000000000 and 1623254400400000000;") - e.CheckData2(0, 0, int64(5), data) - - data, _ = e.Query("select count(*) from tb where ts between \"2021-06-10 0:00:00.299999999\" and \"2021-06-10 0:00:00.300000001\";") - e.CheckData2(0, 0, int64(3), data) - - data, _ = e.Query("select avg(speed) from tb interval(5000000000b);") - e.CheckRow(1, data) - - data, _ = e.Query("select avg(speed) from tb interval(100000000b)") - e.CheckRow(4, data) - - data, _ = e.Query("select avg(speed) from tb interval(1000b);") - e.CheckRow(5, data) - - data, _ = e.Query("select avg(speed) from tb interval(1u);") - e.CheckRow(5, data) - - data, _ = e.Query("select avg(speed) from tb interval(100000000b) sliding (100000000b);") - e.CheckRow(4, data) - - data, _ = e.Query("select last(*) from tb") - tt, _ := time.Parse(layout, "2021-06-10 0:00:00.999999999") - e.CheckData2(0, 0, tt, data) - - data, _ = e.Query("select first(*) from tb") - tt1, _ := time.Parse(layout, "2021-06-10 0:00:00.100000001") - e.CheckData2(0, 0, tt1, data) - - e.Execute("insert into tb values(now + 500000000b, 6);") - data, _ = e.Query("select * from tb;") - e.CheckRow(7, data) - - e.Execute("create table tb2 (ts timestamp, speed int, ts2 timestamp);") - e.Execute("insert into tb2 values(\"2021-06-10 0:00:00.100000001\", 1, \"2021-06-11 0:00:00.100000001\");") - e.Execute("insert into tb2 values(1623254400150000000, 2, 1623340800150000000);") - e.Execute("import into tb2 values(1623254400300000000, 3, 1623340800300000000);") - e.Execute("import into tb2 values(1623254400299999999, 4, 1623340800299999999);") - e.Execute("insert into tb2 values(1623254400300000001, 5, 1623340800300000001);") - e.Execute("insert into tb2 values(1623254400999999999, 7, 1623513600999999999);") - - data, _ = e.Query("select * from tb2;") - tt2, _ := time.Parse(layout, "2021-06-10 0:00:00.100000001") - tt3, _ := time.Parse(layout, "2021-06-10 0:00:00.150000000") - - e.CheckData2(0, 0, tt2, data) - e.CheckData2(1, 0, tt3, data) - e.CheckData2(2, 1, int32(4), data) - e.CheckData2(3, 1, int32(3), data) - tt4, _ := time.Parse(layout, "2021-06-11 00:00:00.300000001") - e.CheckData2(4, 2, tt4, data) - e.CheckRow(6, data) - - data, _ = e.Query("select count(*) from tb2 where ts2 > 1623340800000000000 and ts2 < 1623340800150000000;") - e.CheckData2(0, 0, int64(1), data) - - data, _ = e.Query("select count(*) from tb2 where ts2 > \"2021-06-11 0:00:00.100000000\" and ts2 < \"2021-06-11 0:00:00.100000002\";") - e.CheckData2(0, 0, int64(1), data) - - data, _ = e.Query("select count(*) from tb2 where ts2 > 1623340800500000000;") - e.CheckData2(0, 0, int64(1), data) - data, _ = e.Query("select count(*) from tb2 where ts2 < \"2021-06-11 0:00:00.400000000\";") - e.CheckData2(0, 0, int64(5), data) - - data, _ = e.Query("select count(*) from tb2 where ts2 < now + 400000000b;") - e.CheckData2(0, 0, int64(6), data) - - data, _ = e.Query("select count(*) from tb2 where ts2 >= \"2021-06-11 0:00:00.100000001\";") - e.CheckData2(0, 0, int64(6), data) - - data, _ = e.Query("select count(*) from tb2 where ts2 <= 1623340800400000000;") - e.CheckData2(0, 0, int64(5), data) - - data, _ = e.Query("select count(*) from tb2 where ts2 = \"2021-06-11 0:00:00.000000000\";") - - data, _ = e.Query("select count(*) from tb2 where ts2 = \"2021-06-11 0:00:00.300000001\";") - e.CheckData2(0, 0, int64(1), data) - - data, _ = e.Query("select count(*) from tb2 where ts2 = 1623340800300000001;") - e.CheckData2(0, 0, int64(1), data) - - data, _ = e.Query("select count(*) from tb2 where ts2 between 1623340800000000000 and 1623340800450000000;") - e.CheckData2(0, 0, int64(5), data) - - data, _ = e.Query("select count(*) from tb2 where ts2 between \"2021-06-11 0:00:00.299999999\" and \"2021-06-11 0:00:00.300000001\";") - e.CheckData2(0, 0, int64(3), data) - - data, _ = e.Query("select count(*) from tb2 where ts2 <> 1623513600999999999;") - e.CheckData2(0, 0, int64(5), data) - - data, _ = e.Query("select count(*) from tb2 where ts2 <> \"2021-06-11 0:00:00.100000001\";") - e.CheckData2(0, 0, int64(5), data) - - data, _ = e.Query("select count(*) from tb2 where ts2 <> \"2021-06-11 0:00:00.100000000\";") - e.CheckData2(0, 0, int64(6), data) - - data, _ = e.Query("select count(*) from tb2 where ts2 != 1623513600999999999;") - e.CheckData2(0, 0, int64(5), data) - - data, _ = e.Query("select count(*) from tb2 where ts2 != \"2021-06-11 0:00:00.100000001\";") - e.CheckData2(0, 0, int64(5), data) - - data, _ = e.Query("select count(*) from tb2 where ts2 != \"2021-06-11 0:00:00.100000000\";") - e.CheckData2(0, 0, int64(6), data) - - e.Execute("insert into tb2 values(now + 500000000b, 6, now +2d);") - data, _ = e.Query("select * from tb2;") - e.CheckRow(7, data) - - e.Execute("create table tb3 (ts timestamp, speed int);") - _, err = e.Execute("insert into tb3 values(16232544001500000, 2);") - if err != nil { - fmt.Println("check pass! ") - } - - e.Execute("insert into tb3 values(\"2021-06-10 0:00:00.123456\", 2);") - data, _ = e.Query("select * from tb3 where ts = \"2021-06-10 0:00:00.123456000\";") - e.CheckRow(1, data) - - e.Execute("insert into tb3 values(\"2021-06-10 0:00:00.123456789000\", 2);") - data, _ = e.Query("select * from tb3 where ts = \"2021-06-10 0:00:00.123456789\";") - e.CheckRow(1, data) - - // check timezone support - - e.Execute("drop database if exists nsdb;") - e.Execute("create database nsdb precision 'ns';") - e.Execute("use nsdb;") - e.Execute("create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);") - e.Execute("insert into tb1 using st tags('2021-06-10 0:00:00.123456789' , 1 ) values('2021-06-10T0:00:00.123456789+07:00' , 1.0);") - data, _ = e.Query("select first(*) from tb1;") - - ttt, _ := time.Parse(layout, "2021-06-10 01:00:00.123456789") - e.CheckData2(0, 0, ttt, data) - - e.Execute("create database usdb precision 'us';") - e.Execute("use usdb;") - e.Execute("create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);") - e.Execute("insert into tb1 using st tags('2021-06-10 0:00:00.123456' , 1 ) values('2021-06-10T0:00:00.123456+07:00' , 1.0);") - data, _ = e.Query("select first(*) from tb1;") - ttt2, _ := time.Parse(layout, "2021-06-10 01:00:00.123456") - e.CheckData2(0, 0, ttt2, data) - - e.Execute("drop database if exists msdb;") - e.Execute("create database msdb precision 'ms';") - e.Execute("use msdb;") - e.Execute("create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);") - e.Execute("insert into tb1 using st tags('2021-06-10 0:00:00.123' , 1 ) values('2021-06-10T0:00:00.123+07:00' , 1.0);") - data, _ = e.Query("select first(*) from tb1;") - ttt3, _ := time.Parse(layout, "2021-06-10 01:00:00.123") - e.CheckData2(0, 0, ttt3, data) - fmt.Println("all test done!") - -} - -func prepareData(e *connector.Executor) { - sqlList := []string{ - "reset query cache;", - "drop database if exists db;", - "create database db;", - "use db;", - "reset query cache;", - "drop database if exists db;", - "create database db precision 'ns';", - "show databases;", - "use db;", - "create table tb (ts timestamp, speed int);", - "insert into tb values('2021-06-10 0:00:00.100000001', 1);", - "insert into tb values(1623254400150000000, 2);", - "import into tb values(1623254400300000000, 3);", - "import into tb values(1623254400299999999, 4);", - "insert into tb values(1623254400300000001, 5);", - "insert into tb values(1623254400999999999, 7);", - } - for _, sql := range sqlList { - err := executeSql(e, sql) - if err != nil { - log.Fatalf("prepare data error:%v, sql:%s", err, sql) - } - } -} - -func executeSql(e *connector.Executor, sql string) error { - _, err := e.Execute(sql) - if err != nil { - return err - } - return nil -} diff --git a/tests/pytest/nanosupport/nanosupportTestCase.py b/tests/pytest/dbmgmt/nanoSecondCheck.py similarity index 82% rename from tests/pytest/nanosupport/nanosupportTestCase.py rename to tests/pytest/dbmgmt/nanoSecondCheck.py index 0645814576b448418ee02c332b929b8a1b1806db..a5e9adacee53a9172a2d8990ccc4d83feb983bdd 100644 --- a/tests/pytest/nanosupport/nanosupportTestCase.py +++ b/tests/pytest/dbmgmt/nanoSecondCheck.py @@ -1,4 +1,3 @@ - # ################################################################# # Copyright (c) 2016 by TAOS Technologies, Inc. # All rights reserved. @@ -21,7 +20,7 @@ from util.sql import * import time from datetime import datetime import os -import datetime + class TDTestCase: def init(self, conn, logSql): @@ -209,43 +208,6 @@ class TDTestCase: tdSql.query('select * from tb3 where ts = \'2021-06-10 0:00:00.123456789\';') tdSql.checkRows(1) - # check timezone support - tdSql.execute('drop database if exists nsdb;') - tdSql.execute('create database nsdb precision "ns";') - tdSql.execute('use nsdb;') - tdSql.execute('create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);') - tdSql.execute('insert into tb1 using st tags("2021-06-10 0:00:00.123456789" , 1 ) values("2021-06-10T0:00:00.123456789+07:00" , 1.0);' ) - tdSql.query("select first(*) from tb1;") - res = tdSql.getResult("select first(*) from tb1;") - tdSql.checkData(0,0,1623258000123456789) - tdSql.execute('insert into tb1 using st tags("2021-06-10 0:00:00.123456789" , 1 ) values("2021-06-10T0:00:00.123456789+06:00" , 2.0);' ) - tdSql.query("select last(*) from tb1;") - - - - tdSql.execute('create database usdb precision "us";') - tdSql.execute('use usdb;') - tdSql.execute('create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);') - tdSql.execute('insert into tb1 using st tags("2021-06-10 0:00:00.123456" , 1 ) values("2021-06-10T0:00:00.123456+07:00" , 1.0);' ) - res = tdSql.getResult("select first(*) from tb1;") - print(res) - if res == [(datetime.datetime(2021, 6, 10, 1, 0, 0, 123456), 1.0)]: - tdLog.info('check timezone pass about us database') - - tdSql.execute('drop database if exists msdb;') - tdSql.execute('create database msdb precision "ms";') - tdSql.execute('use msdb;') - tdSql.execute('create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);') - tdSql.execute('insert into tb1 using st tags("2021-06-10 0:00:00.123" , 1 ) values("2021-06-10T0:00:00.123+07:00" , 1.0);' ) - res = tdSql.getResult("select first(*) from tb1;") - print(res) - if res ==[(datetime.datetime(2021, 6, 10, 1, 0, 0, 123000), 1.0)]: - tdLog.info('check timezone pass about ms database') - - - os.system('rm -rf ./*.py.sql') - - os.system('sudo timedatectl set-ntp on') def stop(self): @@ -254,4 +216,4 @@ class TDTestCase: tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index ca837f54e0f22276304b5d05b89f86cab06d47c6..06ec3c6bfabfe4d9c378c9d17dda944990f624a8 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -13,7 +13,6 @@ python3 ./test.py -f insert/tinyint.py python3 ./test.py -f insert/date.py python3 ./test.py -f insert/binary.py python3 ./test.py -f insert/nchar.py - #python3 ./test.py -f insert/nchar-boundary.py python3 ./test.py -f insert/nchar-unicode.py python3 ./test.py -f insert/multi.py @@ -83,9 +82,8 @@ python3 ./test.py -f tag_lite/tinyint.py python3 ./test.py -f tag_lite/timestamp.py python3 ./test.py -f tag_lite/TestModifyTag.py - -#nano support test -python3 test.py -f nanosupport/nanosupportTestCase.py +#python3 ./test.py -f dbmgmt/database-name-boundary.py +python3 test.py -f dbmgmt/nanoSecondCheck.py python3 ./test.py -f import_merge/importBlock1HO.py python3 ./test.py -f import_merge/importBlock1HPO.py