diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index ee2363cf2ec25b954e6f52c47c71001627630233..72d55a7ff1524f4d717f485ea26ac7691c077057 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -2727,7 +2727,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col memset(pExpr->base.aliasName, 0, tListLen(pExpr->base.aliasName)); getColumnName(pItem, pExpr->base.aliasName, pExpr->base.token,sizeof(pExpr->base.aliasName) - 1); - + SColumnList list = createColumnList(1, index.tableIndex, index.columnIndex); if (finalResult) { int32_t numOfOutput = tscNumOfFields(pQueryInfo); @@ -2852,6 +2852,13 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col char val[8] = {0}; int64_t tickPerSec = 0; + char *exprToken = tcalloc(pParamElem[1].pNode->exprToken.n + 1, sizeof(char)); + memcpy(exprToken, pParamElem[1].pNode->exprToken.z, pParamElem[1].pNode->exprToken.n); + if (pParamElem[1].pNode->exprToken.type == TK_NOW || strstr(exprToken, "now")) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); + } + tfree(exprToken); + if ((TSDB_DATA_TYPE_NULL == pParamElem[1].pNode->value.nType) || tVariantDump(&pParamElem[1].pNode->value, (char*) &tickPerSec, TSDB_DATA_TYPE_BIGINT, true) < 0) { return TSDB_CODE_TSC_INVALID_OPERATION; } @@ -2866,7 +2873,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg10); } else if (tickPerSec <= 0) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg16); - } + } tscExprAddParams(&pExpr->base, (char*) &tickPerSec, TSDB_DATA_TYPE_BIGINT, LONG_BYTES); if (functionId == TSDB_FUNC_DERIVATIVE) { @@ -4906,14 +4913,14 @@ static int32_t validateNullExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t if (IS_VAR_DATA_TYPE(pSchema[index].type) || pSchema[index].type == TSDB_DATA_TYPE_JSON) { return TSDB_CODE_SUCCESS; } - + char *v = strndup(pRight->exprToken.z, pRight->exprToken.n); int32_t len = strRmquote(v, pRight->exprToken.n); if (len > 0) { uint32_t type = 0; tGetToken(v, &type); - if (type == TK_NULL) { + if (type == TK_NULL) { free(v); return invalidOperationMsg(msgBuf, msg); } diff --git a/src/connector/C#/.gitignore b/src/connector/C#/.gitignore index a15c72f06cb1ed1f03b1ef19f18d3043f72061e3..95649870777f5d810513e95b6dede56743d71c8a 100644 --- a/src/connector/C#/.gitignore +++ b/src/connector/C#/.gitignore @@ -1,7 +1,7 @@ src/TDengineDriver/bin/ src/TDengineDriver/obj/ -src/test/Cases/bin/ -src/test/Cases/obj/ +src/test/FunctionTest/bin/ +src/test/FunctionTest/obj/ src/test/XUnitTest/bin/ src/test/XUnitTest/obj/ src/test/doc/ diff --git a/src/connector/C#/csharpTaos.sln b/src/connector/C#/csharpTaos.sln index b18ca230011c1314fb354feeb61166374c822d3d..158cc7eb3bcdd502f78ef26a60b1949e4c31ebd0 100644 --- a/src/connector/C#/csharpTaos.sln +++ b/src/connector/C#/csharpTaos.sln @@ -11,7 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{CB8E6458-3 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnitTest", "src\test\XUnitTest\XUnitTest.csproj", "{64C0A478-2591-4459-9F8F-A70F37976A41}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cases", "src\test\Cases\Cases.csproj", "{19A69D26-66BF-4227-97BE-9B087BC76B2F}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FunctionTest", "src\test\FunctionTest\FunctionTest.csproj", "{E66B034B-4677-4BFB-8B87-84715D281E21}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -50,23 +50,23 @@ Global {64C0A478-2591-4459-9F8F-A70F37976A41}.Release|x64.Build.0 = Release|Any CPU {64C0A478-2591-4459-9F8F-A70F37976A41}.Release|x86.ActiveCfg = Release|Any CPU {64C0A478-2591-4459-9F8F-A70F37976A41}.Release|x86.Build.0 = Release|Any CPU - {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Debug|x64.ActiveCfg = Debug|Any CPU - {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Debug|x64.Build.0 = Debug|Any CPU - {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Debug|x86.ActiveCfg = Debug|Any CPU - {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Debug|x86.Build.0 = Debug|Any CPU - {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Release|Any CPU.Build.0 = Release|Any CPU - {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Release|x64.ActiveCfg = Release|Any CPU - {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Release|x64.Build.0 = Release|Any CPU - {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Release|x86.ActiveCfg = Release|Any CPU - {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Release|x86.Build.0 = Release|Any CPU + {E66B034B-4677-4BFB-8B87-84715D281E21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E66B034B-4677-4BFB-8B87-84715D281E21}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E66B034B-4677-4BFB-8B87-84715D281E21}.Debug|x64.ActiveCfg = Debug|Any CPU + {E66B034B-4677-4BFB-8B87-84715D281E21}.Debug|x64.Build.0 = Debug|Any CPU + {E66B034B-4677-4BFB-8B87-84715D281E21}.Debug|x86.ActiveCfg = Debug|Any CPU + {E66B034B-4677-4BFB-8B87-84715D281E21}.Debug|x86.Build.0 = Debug|Any CPU + {E66B034B-4677-4BFB-8B87-84715D281E21}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E66B034B-4677-4BFB-8B87-84715D281E21}.Release|Any CPU.Build.0 = Release|Any CPU + {E66B034B-4677-4BFB-8B87-84715D281E21}.Release|x64.ActiveCfg = Release|Any CPU + {E66B034B-4677-4BFB-8B87-84715D281E21}.Release|x64.Build.0 = Release|Any CPU + {E66B034B-4677-4BFB-8B87-84715D281E21}.Release|x86.ActiveCfg = Release|Any CPU + {E66B034B-4677-4BFB-8B87-84715D281E21}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {5BED7402-0A65-4ED9-A491-C56BFB518045} = {A1FB5B66-E32F-4789-9BE9-042E5BD21087} {CB8E6458-31E1-4351-B704-1B918E998654} = {A1FB5B66-E32F-4789-9BE9-042E5BD21087} {64C0A478-2591-4459-9F8F-A70F37976A41} = {CB8E6458-31E1-4351-B704-1B918E998654} - {19A69D26-66BF-4227-97BE-9B087BC76B2F} = {CB8E6458-31E1-4351-B704-1B918E998654} + {E66B034B-4677-4BFB-8B87-84715D281E21} = {CB8E6458-31E1-4351-B704-1B918E998654} EndGlobalSection EndGlobal diff --git a/src/connector/C#/src/TDengineDriver/TDengineDriver.cs b/src/connector/C#/src/TDengineDriver/TDengineDriver.cs index 15e0ca0841c0022439c00fc1b7357b770ccb14f6..b72a4e54afe457d37168a97cdf6b9ba00f81ad6d 100644 --- a/src/connector/C#/src/TDengineDriver/TDengineDriver.cs +++ b/src/connector/C#/src/TDengineDriver/TDengineDriver.cs @@ -87,7 +87,7 @@ namespace TDengineDriver case TDengineDataType.TSDB_DATA_TYPE_DOUBLE: return "DOUBLE"; case TDengineDataType.TSDB_DATA_TYPE_BINARY: - return "STRING"; + return "BINARY"; case TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP: return "TIMESTAMP"; case TDengineDataType.TSDB_DATA_TYPE_NCHAR: diff --git a/src/connector/C#/src/TDengineDriver/TDengineDriver.csproj b/src/connector/C#/src/TDengineDriver/TDengineDriver.csproj index 14b1776fb3aa8a92227c8154a0fed58d1f94f46c..5a11c10208931f7e63456c7e32c224bb545e78ec 100644 --- a/src/connector/C#/src/TDengineDriver/TDengineDriver.csproj +++ b/src/connector/C#/src/TDengineDriver/TDengineDriver.csproj @@ -4,7 +4,7 @@ net5;netstandard2.0;net45 TDengine.Connector logo.jpg - 1.0.3 + 1.0.4 taosdata www.taosdata.com MIT @@ -14,7 +14,7 @@ This C # connector supports: Linux 64/Windows x64/Windows x86. more information please visit: https://www.taosdata.com - https://github.com/taosdata/TDengine/tree/develop/src/connector/C%23 + https://github.com/taosdata/TDengine/tree/develop/src/connector/C%2523/src/TDengineDriver CS1591 diff --git a/src/connector/C#/src/TDengineDriver/TaosMultiBind.cs b/src/connector/C#/src/TDengineDriver/TaosMultiBind.cs index 00ec336be636a10e895e77e3ce20c50b7d5648ab..96122dfb0619a760e38306fa254fd5a101879198 100644 --- a/src/connector/C#/src/TDengineDriver/TaosMultiBind.cs +++ b/src/connector/C#/src/TDengineDriver/TaosMultiBind.cs @@ -436,49 +436,46 @@ namespace TDengineDriver { TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND(); int elementCount = arr.Length; + //TypeSize represent the Max element length of the comming arr + //The size of the buffer is typeSize * elementCount + //This buffer is used to store TAOS_MULTI_BIND.buffer int typeSize = MaxElementLength(arr); + //This intSize is used to calcuate buffer size of the struct TAOS_MULTI_BIND's + //length. The buffer is intSize * elementCount,which is used to store TAOS_MULTI_BIND.length int intSize = sizeof(int); + //This byteSize is used to calculate the buffer size of the struct TAOS_MULTI_BIND.is_null + //This buffer size is byteSize * elementCount int byteSize = sizeof(byte); - StringBuilder arrStrBuilder = new StringBuilder(); ; + StringBuilder arrStrBuilder = new StringBuilder(); ; //TAOS_MULTI_BIND.length IntPtr lengthArr = Marshal.AllocHGlobal(intSize * elementCount); //TAOS_MULTI_BIND.is_null IntPtr nullArr = Marshal.AllocHGlobal(byteSize * elementCount); + //TAOS_MULTI_BIND.buffer + IntPtr uNcharBuff = Marshal.AllocHGlobal(typeSize * elementCount); for (int i = 0; i < elementCount; i++) { int itemLength = 0; byte[] decodeByte = GetStringEncodeByte(arr[i]); itemLength = decodeByte.Length; - // if element if not null and element length is less then typeSize - // fill the memory with default char.Since arr element memory need align. - if (!String.IsNullOrEmpty(arr[i]) && typeSize == itemLength) - { - arrStrBuilder.Append(arr[i]); - } - else if (!String.IsNullOrEmpty(arr[i]) && typeSize > itemLength) - { - arrStrBuilder.Append(arr[i]); - arrStrBuilder.Append(AlignCharArr(typeSize - itemLength)); - } - else + if (!String.IsNullOrEmpty(arr[i])) { - // if is null value,fill the memory with default values. - arrStrBuilder.Append(AlignCharArr(typeSize)); + for (int j = 0; j < itemLength; j++) + { + //Read byte after byte + Marshal.WriteByte(uNcharBuff, i * typeSize + j, decodeByte[j]); + } } - - //set TAOS_MULTI_BIND.length - Marshal.WriteInt32(lengthArr, intSize * i, typeSize); - //set TAOS_MULTI_BIND.is_null + //Set TAOS_MULTI_BIND.length + Marshal.WriteInt32(lengthArr, intSize * i, itemLength); + //Set TAOS_MULTI_BIND.is_null Marshal.WriteByte(nullArr, byteSize * i, Convert.ToByte(String.IsNullOrEmpty(arr[i]) ? 1 : 0)); } - //set TAOS_MULTI_BIND.buffer - IntPtr uBinaryBuff = (IntPtr)Marshal.StringToHGlobalAnsi(arrStrBuilder.ToString()); - - //config TAOS_MULTI_BIND + //Config TAOS_MULTI_BIND multiBind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_BINARY; - multiBind.buffer = uBinaryBuff; + multiBind.buffer = uNcharBuff; multiBind.buffer_length = (ulong)typeSize; multiBind.length = lengthArr; multiBind.is_null = nullArr; @@ -491,47 +488,43 @@ namespace TDengineDriver { TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND(); int elementCount = arr.Length; + //TypeSize represent the Max element length of the comming arr + //The size of the buffer is typeSize * elementCount + //This buffer is used to store TAOS_MULTI_BIND.buffer int typeSize = MaxElementLength(arr); + //This intSize is used to calcuate buffer size of the struct TAOS_MULTI_BIND's + //length. The buffer is intSize * elementCount,which is used to store TAOS_MULTI_BIND.length int intSize = sizeof(int); + //This byteSize is used to calculate the buffer size of the struct TAOS_MULTI_BIND.is_null + //This buffer size is byteSize * elementCount int byteSize = sizeof(byte); - StringBuilder arrStrBuilder = new StringBuilder(); ; //TAOS_MULTI_BIND.length IntPtr lengthArr = Marshal.AllocHGlobal(intSize * elementCount); //TAOS_MULTI_BIND.is_null IntPtr nullArr = Marshal.AllocHGlobal(byteSize * elementCount); + //TAOS_MULTI_BIND.buffer + IntPtr uNcharBuff = Marshal.AllocHGlobal(typeSize * elementCount); for (int i = 0; i < elementCount; i++) { int itemLength = 0; byte[] decodeByte = GetStringEncodeByte(arr[i]); itemLength = decodeByte.Length; - // if element if not null and element length is less then typeSize - // fill the memory with default char.Since arr element memory need align. - if (!String.IsNullOrEmpty(arr[i]) && typeSize == itemLength) - { - arrStrBuilder.Append(arr[i]); - } - else if (!String.IsNullOrEmpty(arr[i]) && typeSize > itemLength) + if (!String.IsNullOrEmpty(arr[i])) { - arrStrBuilder.Append(arr[i]); - arrStrBuilder.Append(AlignCharArr(typeSize - itemLength)); + for (int j = 0; j < itemLength; j++) + { + //Read byte after byte + Marshal.WriteByte(uNcharBuff, i * typeSize + j, decodeByte[j]); + } } - else - { - // if is null value,fill the memory with default values. - arrStrBuilder.Append(AlignCharArr(typeSize)); - } - - //set TAOS_MULTI_BIND.length - Marshal.WriteInt32(lengthArr, intSize * i, typeSize); - //set TAOS_MULTI_BIND.is_null + //Set TAOS_MULTI_BIND.length + Marshal.WriteInt32(lengthArr, intSize * i, itemLength); + //Set TAOS_MULTI_BIND.is_null Marshal.WriteByte(nullArr, byteSize * i, Convert.ToByte(String.IsNullOrEmpty(arr[i]) ? 1 : 0)); } - //set TAOS_MULTI_BIND.buffer - IntPtr uNcharBuff = (IntPtr)Marshal.StringToHGlobalAnsi(arrStrBuilder.ToString()); - - //config TAOS_MULTI_BIND + //Config TAOS_MULTI_BIND multiBind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_NCHAR; multiBind.buffer = uNcharBuff; multiBind.buffer_length = (ulong)typeSize; @@ -612,16 +605,16 @@ namespace TDengineDriver } private static Byte[] GetStringEncodeByte(string str) - { + { Byte[] strToBytes = null; - if(String.IsNullOrEmpty(str)) + if (String.IsNullOrEmpty(str)) { strToBytes = System.Text.Encoding.Default.GetBytes(String.Empty); } else { strToBytes = System.Text.Encoding.Default.GetBytes(str); - } + } return strToBytes; } } diff --git a/src/connector/C#/src/test/Cases/Cases.csproj b/src/connector/C#/src/test/Cases/Cases.csproj deleted file mode 100644 index ebc9c3100a778d35e6aee0feeb8d059ad5e4bfbd..0000000000000000000000000000000000000000 --- a/src/connector/C#/src/test/Cases/Cases.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - Exe - net5.0 - CS1591 - true - ..\doc\FunctionTest.XML - - diff --git a/src/connector/C#/src/test/Cases/DataSource.cs b/src/connector/C#/src/test/Cases/DataSource.cs deleted file mode 100644 index 25f639c9772ac656f1ba8effff798a05b370f9a0..0000000000000000000000000000000000000000 --- a/src/connector/C#/src/test/Cases/DataSource.cs +++ /dev/null @@ -1,164 +0,0 @@ -using System; -using Test.UtilsTools; -using TDengineDriver; - -namespace Test.UtilsTools.DataSource -{ - public class DataSource - { - public static long[] tsArr = new long[5] { 1637064040000, 1637064041000, 1637064042000, 1637064043000, 1637064044000 }; - public static bool?[] boolArr = new bool?[5] { true, false, null, true, true }; - public static sbyte?[] tinyIntArr = new sbyte?[5] { -127, 0, null, 8, 127 }; - public static short?[] shortArr = new short?[5] { short.MinValue + 1, -200, null, 100, short.MaxValue }; - public static int?[] intArr = new int?[5] { -200, -100, null, 0, 300 }; - public static long?[] longArr = new long?[5] { long.MinValue + 1, -2000, null, 1000, long.MaxValue }; - public static float?[] floatArr = new float?[5] { float.MinValue + 1, -12.1F, null, 0F, float.MaxValue }; - public static double?[] doubleArr = new double?[5] { double.MinValue + 1, -19.112D, null, 0D, double.MaxValue }; - public static byte?[] uTinyIntArr = new byte?[5] { byte.MinValue, 12, null, 89, byte.MaxValue - 1 }; - public static ushort?[] uShortArr = new ushort?[5] { ushort.MinValue, 200, null, 400, ushort.MaxValue - 1 }; - public static uint?[] uIntArr = new uint?[5] { uint.MinValue, 100, null, 2, uint.MaxValue - 1 }; - public static ulong?[] uLongArr = new ulong?[5] { ulong.MinValue, 2000, null, 1000, long.MaxValue - 1 }; - public static string[] binaryArr = new string[5] { "1234567890~!@#$%^&*()_+=-`[]{}:,./<>?", String.Empty, null, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM", "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890~!@#$%^&*()_+=-`[]{}:,./<>?" }; - public static string[] ncharArr = new string[5] { "1234567890~!@#$%^&*()_+=-`[]{}:,./<>?", null, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM", "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890~!@#$%^&*()_+=-`[]{}:,./<>?", string.Empty }; - - public static string[] binaryArrCn = new string[5] { "涛思数据", String.Empty, null, "taosdata涛思数据", "涛思数据TDengine" }; - public static string[] NcharArrCn = new string[5] { "涛思数据", null, "taosdata涛思数据", "涛思数据TDengine", String.Empty }; - public static TAOS_BIND[] getTags() - { - TAOS_BIND[] binds = new TAOS_BIND[13]; - binds[0] = TaosBind.BindBool(true); - binds[1] = TaosBind.BindTinyInt(-2); - binds[2] = TaosBind.BindSmallInt(short.MaxValue); - binds[3] = TaosBind.BindInt(int.MaxValue); - binds[4] = TaosBind.BindBigInt(Int64.MaxValue); - binds[5] = TaosBind.BindUTinyInt(byte.MaxValue - 1); - binds[6] = TaosBind.BindUSmallInt(UInt16.MaxValue - 1); - binds[7] = TaosBind.BindUInt(uint.MinValue + 1); - binds[8] = TaosBind.BindUBigInt(UInt64.MinValue + 1); - binds[9] = TaosBind.BindFloat(11.11F); - binds[10] = TaosBind.BindDouble(22.22D); - binds[11] = TaosBind.BindBinary("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKZXCVBNM`1234567890-=+_)(*&^%$#@!~[];,./<>?:{}"); - binds[12] = TaosBind.BindNchar("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKZXCVBNM`1234567890-=+_)(*&^%$#@!~[];,./<>?:{}"); - return binds; - } - - public static TAOS_BIND[] getCNTags() - { - TAOS_BIND[] binds = new TAOS_BIND[13]; - binds[0] = TaosBind.BindBool(true); - binds[1] = TaosBind.BindTinyInt(-2); - binds[2] = TaosBind.BindSmallInt(short.MaxValue - 1); - binds[3] = TaosBind.BindInt(int.MaxValue - 1); - binds[4] = TaosBind.BindBigInt(Int64.MaxValue - 1); - binds[5] = TaosBind.BindUTinyInt(byte.MaxValue - 1); - binds[6] = TaosBind.BindUSmallInt(UInt16.MaxValue - 1); - binds[7] = TaosBind.BindUInt(uint.MinValue + 1); - binds[8] = TaosBind.BindUBigInt(UInt64.MinValue + 1); - binds[9] = TaosBind.BindFloat(11.11F); - binds[10] = TaosBind.BindDouble(22.22D); - binds[11] = TaosBind.BindBinary("TDengine涛思数据"); - binds[12] = TaosBind.BindNchar("涛思"); - return binds; - } - - public static TAOS_BIND[] getNtableCNRow() - { - TAOS_BIND[] binds = new TAOS_BIND[15]; - binds[0] = TaosBind.BindTimestamp(1637064040000); - binds[1] = TaosBind.BindTinyInt(-2); - binds[2] = TaosBind.BindSmallInt(short.MaxValue); - binds[3] = TaosBind.BindInt(int.MaxValue); - binds[4] = TaosBind.BindBigInt(Int64.MaxValue); - binds[5] = TaosBind.BindUTinyInt(byte.MaxValue - 1); - binds[6] = TaosBind.BindUSmallInt(UInt16.MaxValue - 1); - binds[7] = TaosBind.BindUInt(uint.MinValue + 1); - binds[8] = TaosBind.BindUBigInt(UInt64.MinValue + 1); - binds[9] = TaosBind.BindFloat(11.11F); - binds[10] = TaosBind.BindDouble(22.22D); - binds[11] = TaosBind.BindBinary("TDengine数据"); - binds[12] = TaosBind.BindNchar("taosdata涛思数据"); - binds[13] = TaosBind.BindBool(true); - binds[14] = TaosBind.BindNil(); - return binds; - } - - public static TAOS_BIND[] getNtableRow() - { - TAOS_BIND[] binds = new TAOS_BIND[15]; - binds[0] = TaosBind.BindTimestamp(1637064040000); - binds[1] = TaosBind.BindTinyInt(-2); - binds[2] = TaosBind.BindSmallInt(short.MaxValue); - binds[3] = TaosBind.BindInt(int.MaxValue); - binds[4] = TaosBind.BindBigInt(Int64.MaxValue); - binds[5] = TaosBind.BindUTinyInt(byte.MaxValue - 1); - binds[6] = TaosBind.BindUSmallInt(UInt16.MaxValue - 1); - binds[7] = TaosBind.BindUInt(uint.MinValue + 1); - binds[8] = TaosBind.BindUBigInt(UInt64.MinValue + 1); - binds[9] = TaosBind.BindFloat(11.11F); - binds[10] = TaosBind.BindDouble(22.22D); - binds[11] = TaosBind.BindBinary("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKZXCVBNM`1234567890-=+_)(*&^%$#@!~[];,./<>?:{}"); - binds[12] = TaosBind.BindNchar("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKZXCVBNM`1234567890-=+_)(*&^%$#@!~[];,./<>?:{}"); - binds[13] = TaosBind.BindBool(true); - binds[14] = TaosBind.BindNil(); - return binds; - } - public static TAOS_MULTI_BIND[] GetMultiBindArr() - { - TAOS_MULTI_BIND[] mBinds = new TAOS_MULTI_BIND[14]; - mBinds[0] = TaosMultiBind.MultiBindTimestamp(tsArr); - mBinds[1] = TaosMultiBind.MultiBindBool(boolArr); - mBinds[2] = TaosMultiBind.MultiBindTinyInt(tinyIntArr); - mBinds[3] = TaosMultiBind.MultiBindSmallInt(shortArr); - mBinds[4] = TaosMultiBind.MultiBindInt(intArr); - mBinds[5] = TaosMultiBind.MultiBindBigint(longArr); - mBinds[6] = TaosMultiBind.MultiBindFloat(floatArr); - mBinds[7] = TaosMultiBind.MultiBindDouble(doubleArr); - mBinds[8] = TaosMultiBind.MultiBindUTinyInt(uTinyIntArr); - mBinds[9] = TaosMultiBind.MultiBindUSmallInt(uShortArr); - mBinds[10] = TaosMultiBind.MultiBindUInt(uIntArr); - mBinds[11] = TaosMultiBind.MultiBindUBigInt(uLongArr); - mBinds[12] = TaosMultiBind.MultiBindBinary(binaryArr); - mBinds[13] = TaosMultiBind.MultiBindNchar(ncharArr); - return mBinds; - } - public static TAOS_MULTI_BIND[] GetMultiBindCNArr() - { - TAOS_MULTI_BIND[] mBinds = new TAOS_MULTI_BIND[14]; - mBinds[0] = TaosMultiBind.MultiBindTimestamp(tsArr); - mBinds[1] = TaosMultiBind.MultiBindBool(boolArr); - mBinds[2] = TaosMultiBind.MultiBindTinyInt(tinyIntArr); - mBinds[3] = TaosMultiBind.MultiBindSmallInt(shortArr); - mBinds[4] = TaosMultiBind.MultiBindInt(intArr); - mBinds[5] = TaosMultiBind.MultiBindBigint(longArr); - mBinds[6] = TaosMultiBind.MultiBindFloat(floatArr); - mBinds[7] = TaosMultiBind.MultiBindDouble(doubleArr); - mBinds[8] = TaosMultiBind.MultiBindUTinyInt(uTinyIntArr); - mBinds[9] = TaosMultiBind.MultiBindUSmallInt(uShortArr); - mBinds[10] = TaosMultiBind.MultiBindUInt(uIntArr); - mBinds[11] = TaosMultiBind.MultiBindUBigInt(uLongArr); - mBinds[12] = TaosMultiBind.MultiBindBinary(binaryArrCn); - mBinds[13] = TaosMultiBind.MultiBindNchar(NcharArrCn); - return mBinds; - } - - public static TAOS_BIND[] GetQueryCondition() - { - TAOS_BIND[] queryCondition = new TAOS_BIND[2]; - queryCondition[0] = TaosBind.BindTinyInt(0); - queryCondition[1] = TaosBind.BindInt(1000); - return queryCondition; - - } - public static void FreeTaosBind(TAOS_BIND[] binds) - { - TaosBind.FreeTaosBind(binds); - } - - public static void FreeTaosMBind(TAOS_MULTI_BIND[] mbinds) - { - TaosMultiBind.FreeTaosBind(mbinds); - } - - - } -} \ No newline at end of file diff --git a/src/connector/C#/src/test/Cases/FetchLength.cs b/src/connector/C#/src/test/Cases/FetchLength.cs deleted file mode 100644 index b5c5c4ecadcd1ff67060a62ac6cfb460e65a530d..0000000000000000000000000000000000000000 --- a/src/connector/C#/src/test/Cases/FetchLength.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using Test.UtilsTools; -using System.Collections.Generic; - -namespace Cases -{ - - public class FetchLengthCase - { - /// xiaolei - /// TestRetrieveBinary - /// TD-12103 C# connector fetch_row with binary data retrieving error - /// FetchLength.cs - /// pass or failed - public void TestRetrieveBinary(IntPtr conn) - { - string sql1 = "create stable stb1 (ts timestamp, name binary(10)) tags(n int);"; - string sql2 = "insert into tb1 using stb1 tags(1) values(now, 'log');"; - string sql3 = "insert into tb2 using stb1 tags(2) values(now, 'test');"; - string sql4 = "insert into tb3 using stb1 tags(3) values(now, 'db02');"; - string sql5 = "insert into tb4 using stb1 tags(4) values(now, 'db3');"; - - string sql6 = "select distinct(name) from stb1;";// - - UtilsTools.ExecuteQuery(conn, sql1); - UtilsTools.ExecuteQuery(conn, sql2); - UtilsTools.ExecuteQuery(conn, sql3); - UtilsTools.ExecuteQuery(conn, sql4); - UtilsTools.ExecuteQuery(conn, sql5); - - IntPtr resPtr = IntPtr.Zero; - resPtr = UtilsTools.ExecuteQuery(conn, sql6); - List> result = UtilsTools.GetResultSet(resPtr); - - List colname = result[0]; - List data = result[1]; - UtilsTools.AssertEqual("db3", data[0]); - UtilsTools.AssertEqual("log", data[1]); - UtilsTools.AssertEqual("db02", data[2]); - UtilsTools.AssertEqual("test", data[3]); - - } - } -} diff --git a/src/connector/C#/src/test/Cases/Program.cs b/src/connector/C#/src/test/Cases/Program.cs deleted file mode 100644 index a498cc21d50a4d8c2811d86a33677e4027e96993..0000000000000000000000000000000000000000 --- a/src/connector/C#/src/test/Cases/Program.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System; -using Test.UtilsTools; -using Cases; - -namespace Cases.EntryPoint -{ - class Program - { - - static void Main(string[] args) - { - IntPtr conn = IntPtr.Zero; - IntPtr stmt = IntPtr.Zero; - IntPtr res = IntPtr.Zero; - - conn = UtilsTools.TDConnection("127.0.0.1", "root", "taosdata", "", 0); - UtilsTools.ExecuteUpdate(conn, "drop database if exists csharp"); - UtilsTools.ExecuteUpdate(conn, "create database if not exists csharp keep 3650"); - UtilsTools.ExecuteUpdate(conn, "use csharp"); - - Console.WriteLine("====================StableColumnByColumn==================="); - StableColumnByColumn columnByColumn = new StableColumnByColumn(); - columnByColumn.Test(conn, "stablecolumnbycolumn"); - Console.WriteLine("====================StmtStableQuery==================="); - StmtStableQuery stmtStableQuery = new StmtStableQuery(); - stmtStableQuery.Test(conn, "stablecolumnbycolumn"); - - Console.WriteLine("====================StableMutipleLine==================="); - StableMutipleLine mutipleLine = new StableMutipleLine(); - mutipleLine.Test(conn, "stablemutipleline"); - - //================================================================================ - - Console.WriteLine("====================NtableSingleLine==================="); - NtableSingleLine ntableSingleLine = new NtableSingleLine(); - ntableSingleLine.Test(conn, "stablesingleline"); - IntPtr resPtr = UtilsTools.ExecuteQuery(conn, "select * from stablesingleline "); - UtilsTools.DisplayRes(resPtr); - - Console.WriteLine("====================NtableMutipleLine==================="); - NtableMutipleLine ntableMutipleLine = new NtableMutipleLine(); - ntableMutipleLine.Test(conn, "ntablemutipleline"); - Console.WriteLine("====================StmtNtableQuery==================="); - StmtNtableQuery stmtNtableQuery = new StmtNtableQuery(); - stmtNtableQuery.Test(conn, "ntablemutipleline"); - - Console.WriteLine("====================NtableColumnByColumn==================="); - NtableColumnByColumn ntableColumnByColumn = new NtableColumnByColumn(); - ntableColumnByColumn.Test(conn, "ntablecolumnbycolumn"); - - Console.WriteLine("====================fetchfeilds==================="); - FetchFields fetchFields = new FetchFields(); - fetchFields.Test(conn, "fetchfeilds"); - - - StableStmtCases stableStmtCases = new StableStmtCases(); - Console.WriteLine("====================stableStmtCases.TestBindSingleLineCn==================="); - stableStmtCases.TestBindSingleLineCn(conn, "stablestmtcasestestbindsinglelinecn"); - - Console.WriteLine("====================stableStmtCases.TestBindColumnCn==================="); - stableStmtCases.TestBindColumnCn(conn, " stablestmtcasestestbindcolumncn"); - - Console.WriteLine("====================stableStmtCases.TestBindMultiLineCn==================="); - stableStmtCases.TestBindMultiLineCn(conn, "stablestmtcasestestbindmultilinecn"); - - NormalTableStmtCases normalTableStmtCases = new NormalTableStmtCases(); - Console.WriteLine("====================normalTableStmtCases.TestBindSingleLineCn==================="); - normalTableStmtCases.TestBindSingleLineCn(conn, "normaltablestmtcasestestbindsinglelinecn"); - - Console.WriteLine("====================normalTableStmtCases.TestBindColumnCn==================="); - normalTableStmtCases.TestBindColumnCn(conn, "normaltablestmtcasestestbindcolumncn"); - - Console.WriteLine("====================normalTableStmtCases.TestBindMultiLineCn==================="); - normalTableStmtCases.TestBindMultiLineCn(conn, "normaltablestmtcasestestbindmultilinecn"); - - Console.WriteLine("===================JsonTagTest===================="); - JsonTagTest jsonTagTest = new JsonTagTest(); - jsonTagTest.Test(conn); - - Console.WriteLine("====================fetchLengthCase==================="); - FetchLengthCase fetchLengthCase = new FetchLengthCase(); - fetchLengthCase.TestRetrieveBinary(conn); - - UtilsTools.ExecuteQuery(conn, "drop database if exists csharp"); - UtilsTools.CloseConnection(conn); - UtilsTools.ExitProgram(); - - } - } -} diff --git a/src/connector/C#/src/test/Cases/StmtNormalTable.cs b/src/connector/C#/src/test/Cases/StmtNormalTable.cs deleted file mode 100644 index 19622fd1ddbc1760856630db4b9e91fb1bd9fe2b..0000000000000000000000000000000000000000 --- a/src/connector/C#/src/test/Cases/StmtNormalTable.cs +++ /dev/null @@ -1,205 +0,0 @@ -using System; -using Test.UtilsTools; -using TDengineDriver; -using Test.UtilsTools.DataSource; - -namespace Cases -{ - public class NtableSingleLine - { - /// xiaolei - /// NtableSingleLine.Test - /// Test stmt insert sinle line data into normal table - /// StmtNormalTable.cs - /// pass or failed - public void Test(IntPtr conn, string tableName) - { - String createTb = "create table " + tableName + "(ts timestamp,tt tinyint,si smallint,ii int,bi bigint,tu tinyint unsigned,su smallint unsigned,iu int unsigned,bu bigint unsigned,ff float ,dd double ,bb binary(200),nc nchar(200),bo bool,nullVal int);"; - String insertSql = "insert into ? values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - TAOS_BIND[] valuesRow = DataSource.getNtableRow(); - UtilsTools.ExecuteQuery(conn, createTb); - - IntPtr stmt = StmtUtilTools.StmtInit(conn); - StmtUtilTools.StmtPrepare(stmt, insertSql); - StmtUtilTools.SetTableName(stmt, tableName); - StmtUtilTools.BindParam(stmt, valuesRow); - StmtUtilTools.AddBatch(stmt); - StmtUtilTools.StmtExecute(stmt); - StmtUtilTools.StmtClose(stmt); - DataSource.FreeTaosBind(valuesRow); - - } - } - - public class NtableMutipleLine - { - /// xiaolei - /// NtableMutipleLine.Test - /// Test stmt insert multiple rows of data into normal table - /// StmtNormalTable.cs - /// pass or failed - public void Test(IntPtr conn, string tableName) - { - TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindArr(); - String createTb = "create table " + tableName + " (ts timestamp ,b bool,v1 tinyint,v2 smallint,v4 int,v8 bigint,f4 float,f8 double,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,bin binary(200),blob nchar(200));"; - String insertSql = "insert into ? values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - - UtilsTools.ExecuteUpdate(conn, createTb); - - IntPtr stmt = StmtUtilTools.StmtInit(conn); - StmtUtilTools.StmtPrepare(stmt, insertSql); - StmtUtilTools.SetTableName(stmt, tableName); - StmtUtilTools.BindParamBatch(stmt, mbind); - StmtUtilTools.AddBatch(stmt); - StmtUtilTools.StmtExecute(stmt); - StmtUtilTools.StmtClose(stmt); - DataSource.FreeTaosMBind(mbind); - } - } - public class NtableColumnByColumn - { - /// xiaolei - /// NtableColumnByColumn.Test - /// Test stmt insert multiple rows of data into normal table by column after column - /// StmtNormalTable.cs - /// pass or failed - public void Test(IntPtr conn, string tableName) - { - DataSource data = new DataSource(); - TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindArr(); - String createTb = "create table " + tableName + " (ts timestamp ,b bool,v1 tinyint,v2 smallint,v4 int,v8 bigint,f4 float,f8 double,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,bin binary(200),blob nchar(200));"; - String insertSql = "insert into ? values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - - - UtilsTools.ExecuteUpdate(conn, createTb); - IntPtr stmt = StmtUtilTools.StmtInit(conn); - - StmtUtilTools.StmtPrepare(stmt, insertSql); - - StmtUtilTools.SetTableName(stmt, tableName); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[0], 0); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[1], 1); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[2], 2); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[3], 3); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[4], 4); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[5], 5); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[6], 6); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[7], 7); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[8], 8); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[9], 9); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[10], 10); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[11], 11); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[12], 12); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[13], 13); - - StmtUtilTools.AddBatch(stmt); - StmtUtilTools.StmtExecute(stmt); - StmtUtilTools.StmtClose(stmt); - - DataSource.FreeTaosMBind(mbind); - - } - } - - public class NormalTableStmtCases - { - /// xiaolei - /// NormalTableStmtCases.TestBindSingleLineCn - /// Test stmt insert single line of chinese character into normal table by column after column - /// StmtNormalTable.cs - /// pass or failed - public void TestBindSingleLineCn(IntPtr conn, string tableName) - { - String createTb = "create table " + tableName + "(ts timestamp,tt tinyint,si smallint,ii int,bi bigint,tu tinyint unsigned,su smallint unsigned,iu int unsigned,bu bigint unsigned,ff float ,dd double ,bb binary(200),nc nchar(200),bo bool,nullVal int);"; - String insertSql = "insert into ? values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - TAOS_BIND[] valuesRow = DataSource.getNtableCNRow(); - UtilsTools.ExecuteUpdate(conn, createTb); - - IntPtr stmt = StmtUtilTools.StmtInit(conn); - StmtUtilTools.StmtPrepare(stmt, insertSql); - StmtUtilTools.SetTableName(stmt, tableName); - StmtUtilTools.BindParam(stmt, valuesRow); - StmtUtilTools.AddBatch(stmt); - StmtUtilTools.StmtExecute(stmt); - StmtUtilTools.StmtClose(stmt); - DataSource.FreeTaosBind(valuesRow); - - string querySql = "select * from " + tableName; - IntPtr res = UtilsTools.ExecuteQuery(conn, querySql); - UtilsTools.DisplayRes(res); - - } - - /// xiaolei - /// NormalTableStmtCases.TestBindColumnCn - /// Test stmt insert single line of chinese character into normal table by column after column - /// StmtNormalTable.cs - /// pass or failed - public void TestBindColumnCn(IntPtr conn,string tableName) - { - DataSource data = new DataSource(); - TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindCNArr(); - String createTb = "create table " + tableName + " (ts timestamp ,b bool,v1 tinyint,v2 smallint,v4 int,v8 bigint,f4 float,f8 double,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,bin binary(200),blob nchar(200));"; - String insertSql = "insert into ? values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - - - UtilsTools.ExecuteUpdate(conn, createTb); - IntPtr stmt = StmtUtilTools.StmtInit(conn); - - StmtUtilTools.StmtPrepare(stmt, insertSql); - - StmtUtilTools.SetTableName(stmt, tableName); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[0], 0); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[1], 1); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[2], 2); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[3], 3); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[4], 4); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[5], 5); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[6], 6); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[7], 7); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[8], 8); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[9], 9); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[10], 10); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[11], 11); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[12], 12); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[13], 13); - - StmtUtilTools.AddBatch(stmt); - StmtUtilTools.StmtExecute(stmt); - StmtUtilTools.StmtClose(stmt); - - DataSource.FreeTaosMBind(mbind); - - string querySql = "select * from " + tableName; - IntPtr res = UtilsTools.ExecuteQuery(conn, querySql); - UtilsTools.DisplayRes(res); - } - /// xiaolei - /// NormalTableStmtCases.TestBindMultiLineCn - /// Test stmt insert single line of chinese character into normal table by column after column - /// StmtNormalTable.cs - /// pass or failed - public void TestBindMultiLineCn(IntPtr conn, string tableName) - { - TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindCNArr(); - String createTb = "create table " + tableName + " (ts timestamp ,b bool,v1 tinyint,v2 smallint,v4 int,v8 bigint,f4 float,f8 double,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,bin binary(200),blob nchar(200));"; - String insertSql = "insert into ? values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - - UtilsTools.ExecuteUpdate(conn, createTb); - - IntPtr stmt = StmtUtilTools.StmtInit(conn); - StmtUtilTools.StmtPrepare(stmt, insertSql); - StmtUtilTools.SetTableName(stmt, tableName); - StmtUtilTools.BindParamBatch(stmt, mbind); - StmtUtilTools.AddBatch(stmt); - StmtUtilTools.StmtExecute(stmt); - StmtUtilTools.StmtClose(stmt); - - DataSource.FreeTaosMBind(mbind); - - string querySql = "select * from " + tableName; - IntPtr res = UtilsTools.ExecuteQuery(conn, querySql); - UtilsTools.DisplayRes(res); - } - } -} \ No newline at end of file diff --git a/src/connector/C#/src/test/Cases/StmtStable.cs b/src/connector/C#/src/test/Cases/StmtStable.cs deleted file mode 100644 index b47ef2226225977fa0d95aa6113d07dc8fb10f50..0000000000000000000000000000000000000000 --- a/src/connector/C#/src/test/Cases/StmtStable.cs +++ /dev/null @@ -1,188 +0,0 @@ -using System; -using Test.UtilsTools; -using TDengineDriver; -using Test.UtilsTools.DataSource; - -namespace Cases -{ - - public class StableMutipleLine - { - TAOS_BIND[] tags = DataSource.getTags(); - TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindArr(); - public void Test(IntPtr conn, string tableName) - { - String createTb = "create stable " + tableName + " (ts timestamp ,b bool,v1 tinyint,v2 smallint,v4 int,v8 bigint,f4 float,f8 double,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,bin binary(200),blob nchar(200))tags(bo bool,tt tinyint,si smallint,ii int,bi bigint,tu tinyint unsigned,su smallint unsigned,iu int unsigned,bu bigint unsigned,ff float ,dd double ,bb binary(200),nc nchar(200));"; - String insertSql = "insert into ? using " + tableName + " tags(?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - - UtilsTools.ExecuteUpdate(conn, createTb); - IntPtr stmt = StmtUtilTools.StmtInit(conn); - - StmtUtilTools.StmtPrepare(stmt, insertSql); - StmtUtilTools.SetTableNameTags(stmt, tableName + "_t1", tags); - StmtUtilTools.BindParamBatch(stmt, mbind); - StmtUtilTools.AddBatch(stmt); - StmtUtilTools.StmtExecute(stmt); - - StmtUtilTools.StmtClose(stmt); - DataSource.FreeTaosBind(tags); - DataSource.FreeTaosMBind(mbind); - } - } - public class StableColumnByColumn - { - DataSource data = new DataSource(); - - TAOS_BIND[] tags = DataSource.getTags(); - TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindArr(); - public void Test(IntPtr conn, string tableName) - { - String createTb = "create stable " + tableName + " (ts timestamp ,b bool,v1 tinyint,v2 smallint,v4 int,v8 bigint,f4 float,f8 double,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,bin binary(200),blob nchar(200))tags(bo bool,tt tinyint,si smallint,ii int,bi bigint,tu tinyint unsigned,su smallint unsigned,iu int unsigned,bu bigint unsigned,ff float ,dd double ,bb binary(200),nc nchar(200));"; - String insertSql = "insert into ? using " + tableName + " tags(?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - - - UtilsTools.ExecuteUpdate(conn, createTb); - IntPtr stmt = StmtUtilTools.StmtInit(conn); - StmtUtilTools.StmtPrepare(stmt, insertSql); - - StmtUtilTools.SetTableNameTags(stmt, tableName + "_t1", tags); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[0], 0); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[1], 1); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[2], 2); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[3], 3); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[4], 4); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[5], 5); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[6], 6); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[7], 7); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[8], 8); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[9], 9); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[10], 10); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[11], 11); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[12], 12); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[13], 13); - StmtUtilTools.AddBatch(stmt); - StmtUtilTools.StmtExecute(stmt); - StmtUtilTools.StmtClose(stmt); - - DataSource.FreeTaosBind(tags); - DataSource.FreeTaosMBind(mbind); - - } - } - - public class StableStmtCases - { - /// xiaolei - /// StableStmtCases.TestBindSingleLineCn - /// Test stmt insert single line of chinese character into stable by column after column - /// StmtSTable.cs - /// pass or failed - public void TestBindSingleLineCn(IntPtr conn, string tableName) - { - TAOS_BIND[] tags = DataSource.getCNTags(); - TAOS_BIND[] binds = DataSource.getNtableCNRow(); - String createTb = "create stable " + tableName + " (ts timestamp,v1 tinyint,v2 smallint,v4 int,v8 bigint,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,f4 float,f8 double,bin binary(200),blob nchar(200),b bool,nilcol int)tags(bo bool,tt tinyint,si smallint,ii int,bi bigint,tu tinyint unsigned,su smallint unsigned,iu int unsigned,bu bigint unsigned,ff float ,dd double ,bb binary(200),nc nchar(200));"; - String insertSql = "insert into ? using " + tableName + " tags(?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - - UtilsTools.ExecuteUpdate(conn, createTb); - IntPtr stmt = StmtUtilTools.StmtInit(conn); - - StmtUtilTools.StmtPrepare(stmt, insertSql); - StmtUtilTools.SetTableNameTags(stmt, tableName + "_t1", tags); - StmtUtilTools.BindParam(stmt, binds); - StmtUtilTools.AddBatch(stmt); - StmtUtilTools.StmtExecute(stmt); - - StmtUtilTools.StmtClose(stmt); - DataSource.FreeTaosBind(tags); - DataSource.FreeTaosBind(binds); - - string querySql = "select * from " + tableName; - IntPtr res = UtilsTools.ExecuteQuery(conn, querySql); - UtilsTools.DisplayRes(res); - - } - - /// xiaolei - /// StableStmtCases.TestBindColumnCn - /// Test stmt insert single line of chinese character into stable by column after column - /// StmtSTable.cs - /// pass or failed - public void TestBindColumnCn(IntPtr conn, string tableName) - { - DataSource data = new DataSource(); - TAOS_BIND[] tags = DataSource.getCNTags(); - TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindCNArr(); - - String createTb = "create stable " + tableName + " (ts timestamp ,b bool,v1 tinyint,v2 smallint,v4 int,v8 bigint,f4 float,f8 double,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,bin binary(200),blob nchar(200))tags(bo bool,tt tinyint,si smallint,ii int,bi bigint,tu tinyint unsigned,su smallint unsigned,iu int unsigned,bu bigint unsigned,ff float ,dd double ,bb binary(200),nc nchar(200));"; - String insertSql = "insert into ? using " + tableName + " tags(?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - - - UtilsTools.ExecuteUpdate(conn, createTb); - IntPtr stmt = StmtUtilTools.StmtInit(conn); - - StmtUtilTools.StmtPrepare(stmt, insertSql); - StmtUtilTools.SetTableNameTags(stmt, tableName + "_t1", tags); - - StmtUtilTools.BindSingleParamBatch(stmt, mbind[0], 0); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[1], 1); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[2], 2); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[3], 3); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[4], 4); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[5], 5); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[6], 6); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[7], 7); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[8], 8); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[9], 9); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[10], 10); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[11], 11); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[12], 12); - StmtUtilTools.BindSingleParamBatch(stmt, mbind[13], 13); - - StmtUtilTools.AddBatch(stmt); - StmtUtilTools.StmtExecute(stmt); - StmtUtilTools.StmtClose(stmt); - - DataSource.FreeTaosBind(tags); - DataSource.FreeTaosMBind(mbind); - - string querySql = "select * from " + tableName; - IntPtr res = UtilsTools.ExecuteQuery(conn, querySql); - UtilsTools.DisplayRes(res); - - - } - - /// xiaolei - /// StableStmtCases.TestBindMultiLineCn - /// Test stmt insert single line of chinese character into stable by column after column - /// StmtSTable.cs - /// pass or failed - public void TestBindMultiLineCn(IntPtr conn, string tableName) - { - TAOS_BIND[] tags = DataSource.getCNTags(); - TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindCNArr(); - - String createTb = "create stable " + tableName + " (ts timestamp ,b bool,v1 tinyint,v2 smallint,v4 int,v8 bigint,f4 float,f8 double,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,bin binary(200),blob nchar(200))tags(bo bool,tt tinyint,si smallint,ii int,bi bigint,tu tinyint unsigned,su smallint unsigned,iu int unsigned,bu bigint unsigned,ff float ,dd double ,bb binary(200),nc nchar(200));"; - String insertSql = "insert into ? using " + tableName + " tags(?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - - UtilsTools.ExecuteUpdate(conn, createTb); - IntPtr stmt = StmtUtilTools.StmtInit(conn); - - StmtUtilTools.StmtPrepare(stmt, insertSql); - StmtUtilTools.SetTableNameTags(stmt, tableName + "_t1", tags); - StmtUtilTools.BindParamBatch(stmt, mbind); - StmtUtilTools.AddBatch(stmt); - StmtUtilTools.StmtExecute(stmt); - - StmtUtilTools.StmtClose(stmt); - DataSource.FreeTaosBind(tags); - DataSource.FreeTaosMBind(mbind); - - string querySql = "select * from " + tableName; - IntPtr res = UtilsTools.ExecuteQuery(conn, querySql); - UtilsTools.DisplayRes(res); - } - - } -} \ No newline at end of file diff --git a/src/connector/C#/src/test/Cases/TaosFeild.cs b/src/connector/C#/src/test/Cases/TaosFeild.cs deleted file mode 100644 index ce272e2d55d5803730df1408e65a8f1d8808a04b..0000000000000000000000000000000000000000 --- a/src/connector/C#/src/test/Cases/TaosFeild.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using Test.UtilsTools; -using TDengineDriver; -using System.Collections.Generic; -using System.Runtime.InteropServices; -namespace Cases -{ - public class FetchFields - { - public void Test(IntPtr conn, string tableName) - { - IntPtr res = IntPtr.Zero; - String createTb = "create stable " + tableName + " (ts timestamp ,b bool,v1 tinyint,v2 smallint,v4 int,v8 bigint,f4 float,f8 double,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,bin binary(200),blob nchar(200))tags(jsontag json);"; - String insertSql = "insert into " + tableName + "_t1 using " + tableName + " tags('{\"k1\": \"v1\"}') values(1637064040000,true,1,2,3,4,5,6,7,8,9,10,'XI','XII')"; - String selectSql = "select * from " + tableName; - String dropSql = "drop table " + tableName; - UtilsTools.ExecuteQuery(conn, createTb); - UtilsTools.ExecuteQuery(conn, insertSql); - res = UtilsTools.ExecuteQuery(conn, selectSql); - UtilsTools.ExecuteQuery(conn, dropSql); - - List metas = new List(); - metas = TDengine.FetchFields(res); - if (metas.Capacity == 0) - { - Console.WriteLine("empty result"); - } - else - { - foreach(TDengineMeta meta in metas){ - Console.WriteLine("col_name:{0},col_type_code:{1},col_type:{2}({3})",meta.name,meta.type,meta.TypeName(),meta.size); - } - } - - } - } -} - - diff --git a/src/connector/C#/src/test/FunctionTest/DataSource.cs b/src/connector/C#/src/test/FunctionTest/DataSource.cs new file mode 100644 index 0000000000000000000000000000000000000000..cdeb817efdc5a9f91a015e687f1fb7376c91044d --- /dev/null +++ b/src/connector/C#/src/test/FunctionTest/DataSource.cs @@ -0,0 +1,421 @@ +using System; +using Test.UtilsTools; +using TDengineDriver; +using System.Collections.Generic; +namespace Test.UtilsTools.DataSource +{ + public class DataSource + { + public static long[] tsArr = new long[5] { 1637064040000, 1637064041000, 1637064042000, 1637064043000, 1637064044000 }; + public static bool?[] boolArr = new bool?[5] { true, false, null, true, true }; + public static sbyte?[] tinyIntArr = new sbyte?[5] { -127, 0, null, 8, 127 }; + public static short?[] shortArr = new short?[5] { short.MinValue + 1, -200, null, 100, short.MaxValue }; + public static int?[] intArr = new int?[5] { -200, -100, null, 0, 300 }; + public static long?[] longArr = new long?[5] { long.MinValue + 1, -2000, null, 1000, long.MaxValue }; + public static float?[] floatArr = new float?[5] { float.MinValue + 1, -12.1F, null, 0F, float.MaxValue }; + public static double?[] doubleArr = new double?[5] { double.MinValue + 1, -19.112D, null, 0D, double.MaxValue }; + public static byte?[] uTinyIntArr = new byte?[5] { byte.MinValue, 12, null, 89, byte.MaxValue - 1 }; + public static ushort?[] uShortArr = new ushort?[5] { ushort.MinValue, 200, null, 400, ushort.MaxValue - 1 }; + public static uint?[] uIntArr = new uint?[5] { uint.MinValue, 100, null, 2, uint.MaxValue - 1 }; + public static ulong?[] uLongArr = new ulong?[5] { ulong.MinValue, 2000, null, 1000, long.MaxValue - 1 }; + public static string[] binaryArr = new string[5] { "1234567890~!@#$%^&*()_+=-`[]{}:,./<>?", String.Empty, null, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM", "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890~!@#$%^&*()_+=-`[]{}:,./<>?" }; + public static string[] ncharArr = new string[5] { "1234567890~!@#$%^&*()_+=-`[]{}:,./<>?", null, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM", "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890~!@#$%^&*()_+=-`[]{}:,./<>?", string.Empty }; + + public static string[] binaryArrCn = new string[5] { "涛思数据", String.Empty, null, "taosdata涛思数据", "涛思数据TDengine" }; + public static string[] NcharArrCn = new string[5] { "涛思数据", null, "taosdata涛思数据", "涛思数据TDengine", String.Empty }; + + // Construct a TAOS_BIND array which contains normal character. + // For stmt bind tags,this will be used as tag info + public static TAOS_BIND[] GetTags() + { + TAOS_BIND[] binds = new TAOS_BIND[13]; + binds[0] = TaosBind.BindBool(true); + binds[1] = TaosBind.BindTinyInt(-2); + binds[2] = TaosBind.BindSmallInt(short.MaxValue); + binds[3] = TaosBind.BindInt(int.MaxValue); + binds[4] = TaosBind.BindBigInt(Int64.MaxValue); + binds[5] = TaosBind.BindUTinyInt(byte.MaxValue - 1); + binds[6] = TaosBind.BindUSmallInt(UInt16.MaxValue - 1); + binds[7] = TaosBind.BindUInt(uint.MinValue + 1); + binds[8] = TaosBind.BindUBigInt(UInt64.MinValue + 1); + binds[9] = TaosBind.BindFloat(11.11F); + binds[10] = TaosBind.BindDouble(22.22D); + binds[11] = TaosBind.BindBinary("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKZXCVBNM`1234567890-=+_)(*&^%$#@!~[];,./<>?:{}"); + binds[12] = TaosBind.BindNchar("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKZXCVBNM`1234567890-=+_)(*&^%$#@!~[];,./<>?:{}"); + return binds; + } + // Get the tag data within and string list + // Which will be retrieved as a string List + private static List GetTagData() + { + List tagData = new List(); + tagData.Add(true.ToString()); + tagData.Add((-2).ToString()); + tagData.Add((short.MaxValue).ToString()); + tagData.Add((int.MaxValue).ToString()); + tagData.Add((Int64.MaxValue).ToString()); + tagData.Add((byte.MaxValue - 1).ToString()); + tagData.Add((UInt16.MaxValue - 1).ToString()); + tagData.Add((uint.MinValue + 1).ToString()); + tagData.Add((UInt64.MinValue + 1).ToString()); + tagData.Add((11.11F).ToString()); + tagData.Add((22.22D).ToString()); + tagData.Add("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKZXCVBNM`1234567890-=+_)(*&^%$#@!~[];,./<>?:{}"); + tagData.Add("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKZXCVBNM`1234567890-=+_)(*&^%$#@!~[];,./<>?:{}"); + return tagData; + } + + public static List GetMultiBindStableRowData() + { + List rowData = new List(); + List tagData = GetTagData(); + for (int i = 0; i < tsArr.Length; i++) + { + rowData.Add(tsArr[i].ToString()); + rowData.Add(boolArr[i].Equals(null) ? "NULL" : boolArr[i].ToString()); + rowData.Add(tinyIntArr[i].Equals(null) ? "NULL" : tinyIntArr[i].ToString()); + rowData.Add(shortArr[i].Equals(null) ? "NULL" : shortArr[i].ToString()); + rowData.Add(intArr[i].Equals(null) ? "NULL" : intArr[i].ToString()); + rowData.Add(longArr[i].Equals(null) ? "NULL" : longArr[i].ToString()); + rowData.Add(floatArr[i].Equals(null) ? "NULL" : floatArr[i].ToString()); + rowData.Add(doubleArr[i].Equals(null) ? "NULL" : doubleArr[i].ToString()); + rowData.Add(uTinyIntArr[i].Equals(null) ? "NULL" : uTinyIntArr[i].ToString()); + rowData.Add(uShortArr[i].Equals(null) ? "NULL" : uShortArr[i].ToString()); + rowData.Add(uIntArr[i].Equals(null) ? "NULL" : uIntArr[i].ToString()); + rowData.Add(uLongArr[i].Equals(null) ? "NULL" : uLongArr[i].ToString()); + rowData.Add(String.IsNullOrEmpty(binaryArr[i]) ? "NULL" : binaryArr[i]); + rowData.Add(String.IsNullOrEmpty(ncharArr[i]) ? "NULL" : ncharArr[i]); + rowData.AddRange(tagData); + // Console.WriteLine("binaryArrCn[{0}]:{1},ncharArr[{0}]:{2}",i,String.IsNullOrEmpty(binaryArrCn[i]) ? "NULL" : binaryArrCn[i],String.IsNullOrEmpty(ncharArr[i]) ? "NULL" : NcharArrCn[i]); + // Console.WriteLine("binaryArrCn[{0}]:{1},ncharArr[{0}]:{2}",i,String.IsNullOrEmpty(binaryArrCn[i]) ? 0 :binaryArrCn[i].Length, String.IsNullOrEmpty(ncharArr[i]) ? 0 : NcharArrCn[i].Length); + // Console.WriteLine("========"); + + } + return rowData; + + } + // Construct a TAOS_BIND array which contains chinese character. + // For stmt bind tags,this will be used as tag info + public static TAOS_BIND[] GetCNTags() + { + TAOS_BIND[] binds = new TAOS_BIND[13]; + binds[0] = TaosBind.BindBool(true); + binds[1] = TaosBind.BindTinyInt(-2); + binds[2] = TaosBind.BindSmallInt(short.MaxValue - 1); + binds[3] = TaosBind.BindInt(int.MaxValue - 1); + binds[4] = TaosBind.BindBigInt(Int64.MaxValue - 1); + binds[5] = TaosBind.BindUTinyInt(byte.MaxValue - 1); + binds[6] = TaosBind.BindUSmallInt(UInt16.MaxValue - 1); + binds[7] = TaosBind.BindUInt(uint.MinValue + 1); + binds[8] = TaosBind.BindUBigInt(UInt64.MinValue + 1); + binds[9] = TaosBind.BindFloat(11.11F); + binds[10] = TaosBind.BindDouble(22.22D); + binds[11] = TaosBind.BindBinary("TDengine涛思数据"); + binds[12] = TaosBind.BindNchar("涛思数据taos"); + return binds; + } + // Get the tag data within and string list + // Which will be retrieved as a string List + private static List GetTagCnData() + { + List tagData = new List(); + tagData.Add(true.ToString()); + tagData.Add((-2).ToString()); + tagData.Add((short.MaxValue - 1).ToString()); + tagData.Add((int.MaxValue - 1).ToString()); + tagData.Add((Int64.MaxValue - 1).ToString()); + tagData.Add((byte.MaxValue - 1).ToString()); + tagData.Add((UInt16.MaxValue - 1).ToString()); + tagData.Add((uint.MinValue + 1).ToString()); + tagData.Add((UInt64.MinValue + 1).ToString()); + tagData.Add((11.11F).ToString()); + tagData.Add((22.22D).ToString()); + tagData.Add("TDengine涛思数据"); + tagData.Add("涛思数据taos"); + return tagData; + } + // A line of data that's without CN character. + // Which is construct as an TAOS_BIND array + public static TAOS_BIND[] GetNtableCNRow() + { + TAOS_BIND[] binds = new TAOS_BIND[15]; + binds[0] = TaosBind.BindTimestamp(1637064040000); + binds[1] = TaosBind.BindTinyInt(-2); + binds[2] = TaosBind.BindSmallInt(short.MaxValue); + binds[3] = TaosBind.BindInt(int.MaxValue); + binds[4] = TaosBind.BindBigInt(Int64.MaxValue); + binds[5] = TaosBind.BindUTinyInt(byte.MaxValue - 1); + binds[6] = TaosBind.BindUSmallInt(UInt16.MaxValue - 1); + binds[7] = TaosBind.BindUInt(uint.MinValue + 1); + binds[8] = TaosBind.BindUBigInt(UInt64.MinValue + 1); + binds[9] = TaosBind.BindFloat(11.11F); + binds[10] = TaosBind.BindDouble(22.22D); + binds[11] = TaosBind.BindBinary("TDengine数据"); + binds[12] = TaosBind.BindNchar("taosdata涛思数据"); + binds[13] = TaosBind.BindBool(true); + binds[14] = TaosBind.BindNil(); + return binds; + } + //Get and list data that will be insert into table + public static List GetNtableCNRowData() + { + var data = new List{ + "1637064040000", + "-2", + short.MaxValue.ToString(), + int.MaxValue.ToString(), + Int64.MaxValue.ToString(), + (byte.MaxValue - 1).ToString(), + (UInt16.MaxValue - 1).ToString(), + (uint.MinValue + 1).ToString(), + (UInt64.MinValue + 1).ToString(), + (11.11F).ToString(), + (22.22D).ToString(), + "TDengine数据", + "taosdata涛思数据", + "True", + "NULL" + }; + return data; + } + // Get the data value and tag values which have chinese characters + // And retrieved as a string list.This is single Line. + public static List GetStableCNRowData() + { + List columnData = GetNtableCNRowData(); + List tagData = GetTagCnData(); + columnData.AddRange(tagData); + return columnData; + } + + // A line of data that's without CN character + public static TAOS_BIND[] GetNtableRow() + { + TAOS_BIND[] binds = new TAOS_BIND[15]; + binds[0] = TaosBind.BindTimestamp(1637064040000); + binds[1] = TaosBind.BindTinyInt(-2); + binds[2] = TaosBind.BindSmallInt(short.MaxValue); + binds[3] = TaosBind.BindInt(int.MaxValue); + binds[4] = TaosBind.BindBigInt(Int64.MaxValue); + binds[5] = TaosBind.BindUTinyInt(byte.MaxValue - 1); + binds[6] = TaosBind.BindUSmallInt(UInt16.MaxValue - 1); + binds[7] = TaosBind.BindUInt(uint.MinValue + 1); + binds[8] = TaosBind.BindUBigInt(UInt64.MinValue + 1); + binds[9] = TaosBind.BindFloat(11.11F); + binds[10] = TaosBind.BindDouble(22.22D); + binds[11] = TaosBind.BindBinary("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKZXCVBNM`1234567890-=+_)(*&^%$#@!~[];,./<>?:{}"); + binds[12] = TaosBind.BindNchar("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKZXCVBNM`1234567890-=+_)(*&^%$#@!~[];,./<>?:{}"); + binds[13] = TaosBind.BindBool(true); + binds[14] = TaosBind.BindNil(); + return binds; + } + // A List of data ,use as expectResData. The value is equal to getNtableRow() + public static List GetNtableRowData() + { + var data = new List{ + "1637064040000", + "-2", + short.MaxValue.ToString(), + int.MaxValue.ToString(), + (Int64.MaxValue).ToString(), + (byte.MaxValue - 1).ToString(), + (UInt16.MaxValue - 1).ToString(), + (uint.MinValue + 1).ToString(), + (UInt64.MinValue + 1).ToString(), + (11.11F).ToString(), + (22.22D).ToString(), + "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKZXCVBNM`1234567890-=+_)(*&^%$#@!~[];,./<>?:{}", + "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKZXCVBNM`1234567890-=+_)(*&^%$#@!~[];,./<>?:{}", + true.ToString(), + "NULL" + }; + return data; + } + + // Five lines of data, that is construct as taos_mutli_bind array. + // There aren't any CN character + public static TAOS_MULTI_BIND[] GetMultiBindArr() + { + TAOS_MULTI_BIND[] mBinds = new TAOS_MULTI_BIND[14]; + mBinds[0] = TaosMultiBind.MultiBindTimestamp(tsArr); + mBinds[1] = TaosMultiBind.MultiBindBool(boolArr); + mBinds[2] = TaosMultiBind.MultiBindTinyInt(tinyIntArr); + mBinds[3] = TaosMultiBind.MultiBindSmallInt(shortArr); + mBinds[4] = TaosMultiBind.MultiBindInt(intArr); + mBinds[5] = TaosMultiBind.MultiBindBigint(longArr); + mBinds[6] = TaosMultiBind.MultiBindFloat(floatArr); + mBinds[7] = TaosMultiBind.MultiBindDouble(doubleArr); + mBinds[8] = TaosMultiBind.MultiBindUTinyInt(uTinyIntArr); + mBinds[9] = TaosMultiBind.MultiBindUSmallInt(uShortArr); + mBinds[10] = TaosMultiBind.MultiBindUInt(uIntArr); + mBinds[11] = TaosMultiBind.MultiBindUBigInt(uLongArr); + mBinds[12] = TaosMultiBind.MultiBindBinary(binaryArr); + mBinds[13] = TaosMultiBind.MultiBindNchar(ncharArr); + return mBinds; + } + // A List of data ,use as expectResData. The value is equal to GetMultiBindCNArr() + public static List GetMultiBindResData() + { + var rowData = new List(); + for (int i = 0; i < tsArr.Length; i++) + { + rowData.Add(tsArr[i].ToString()); + rowData.Add(boolArr[i].Equals(null) ? "NULL" : boolArr[i].ToString()); + rowData.Add(tinyIntArr[i].Equals(null) ? "NULL" : tinyIntArr[i].ToString()); + rowData.Add(shortArr[i].Equals(null) ? "NULL" : shortArr[i].ToString()); + rowData.Add(intArr[i].Equals(null) ? "NULL" : intArr[i].ToString()); + rowData.Add(longArr[i].Equals(null) ? "NULL" : longArr[i].ToString()); + rowData.Add(floatArr[i].Equals(null) ? "NULL" : floatArr[i].ToString()); + rowData.Add(doubleArr[i].Equals(null) ? "NULL" : doubleArr[i].ToString()); + rowData.Add(uTinyIntArr[i].Equals(null) ? "NULL" : uTinyIntArr[i].ToString()); + rowData.Add(uShortArr[i].Equals(null) ? "NULL" : uShortArr[i].ToString()); + rowData.Add(uIntArr[i].Equals(null) ? "NULL" : uIntArr[i].ToString()); + rowData.Add(uLongArr[i].Equals(null) ? "NULL" : uLongArr[i].ToString()); + rowData.Add(String.IsNullOrEmpty(binaryArr[i]) ? "NULL" : binaryArr[i]); + rowData.Add(String.IsNullOrEmpty(ncharArr[i]) ? "NULL" : ncharArr[i]); + // Console.WriteLine("binaryArrCn[{0}]:{1},NcharArrCn[{0}]:{2}",i,String.IsNullOrEmpty(binaryArrCn[i]) ? "NULL" : binaryArrCn[i],String.IsNullOrEmpty(NcharArrCn[i]) ? "NULL" : NcharArrCn[i]); + // Console.WriteLine("binaryArrCn[{0}]:{1},NcharArrCn[{0}]:{2}",i,String.IsNullOrEmpty(binaryArrCn[i]) ? 0 :binaryArrCn[i].Length, String.IsNullOrEmpty(NcharArrCn[i]) ? 0 : NcharArrCn[i].Length); + // Console.WriteLine("========"); + + } + return rowData; + } + // Five lines of data, that is construct as taos_mutli_bind array. + // There aren some CN characters and letters. + public static TAOS_MULTI_BIND[] GetMultiBindCNArr() + { + TAOS_MULTI_BIND[] mBinds = new TAOS_MULTI_BIND[14]; + mBinds[0] = TaosMultiBind.MultiBindTimestamp(tsArr); + mBinds[1] = TaosMultiBind.MultiBindBool(boolArr); + mBinds[2] = TaosMultiBind.MultiBindTinyInt(tinyIntArr); + mBinds[3] = TaosMultiBind.MultiBindSmallInt(shortArr); + mBinds[4] = TaosMultiBind.MultiBindInt(intArr); + mBinds[5] = TaosMultiBind.MultiBindBigint(longArr); + mBinds[6] = TaosMultiBind.MultiBindFloat(floatArr); + mBinds[7] = TaosMultiBind.MultiBindDouble(doubleArr); + mBinds[8] = TaosMultiBind.MultiBindUTinyInt(uTinyIntArr); + mBinds[9] = TaosMultiBind.MultiBindUSmallInt(uShortArr); + mBinds[10] = TaosMultiBind.MultiBindUInt(uIntArr); + mBinds[11] = TaosMultiBind.MultiBindUBigInt(uLongArr); + mBinds[12] = TaosMultiBind.MultiBindBinary(binaryArrCn); + mBinds[13] = TaosMultiBind.MultiBindNchar(NcharArrCn); + return mBinds; + } + // A List of data ,use as expectResData. The value is equal to GetMultiBindCNArr() + public static List GetMultiBindCNRowData() + { + var rowData = new List(); + for (int i = 0; i < tsArr.Length; i++) + { + rowData.Add(tsArr[i].ToString()); + rowData.Add(boolArr[i].Equals(null) ? "NULL" : boolArr[i].ToString()); + rowData.Add(tinyIntArr[i].Equals(null) ? "NULL" : tinyIntArr[i].ToString()); + rowData.Add(shortArr[i].Equals(null) ? "NULL" : shortArr[i].ToString()); + rowData.Add(intArr[i].Equals(null) ? "NULL" : intArr[i].ToString()); + rowData.Add(longArr[i].Equals(null) ? "NULL" : longArr[i].ToString()); + rowData.Add(floatArr[i].Equals(null) ? "NULL" : floatArr[i].ToString()); + rowData.Add(doubleArr[i].Equals(null) ? "NULL" : doubleArr[i].ToString()); + rowData.Add(uTinyIntArr[i].Equals(null) ? "NULL" : uTinyIntArr[i].ToString()); + rowData.Add(uShortArr[i].Equals(null) ? "NULL" : uShortArr[i].ToString()); + rowData.Add(uIntArr[i].Equals(null) ? "NULL" : uIntArr[i].ToString()); + rowData.Add(uLongArr[i].Equals(null) ? "NULL" : uLongArr[i].ToString()); + rowData.Add(String.IsNullOrEmpty(binaryArrCn[i]) ? "NULL" : binaryArrCn[i]); + rowData.Add(String.IsNullOrEmpty(NcharArrCn[i]) ? "NULL" : NcharArrCn[i]); + // Console.WriteLine("binaryArrCn[{0}]:{1},NcharArrCn[{0}]:{2}",i,String.IsNullOrEmpty(binaryArrCn[i]) ? "NULL" : binaryArrCn[i],String.IsNullOrEmpty(NcharArrCn[i]) ? "NULL" : NcharArrCn[i]); + // Console.WriteLine("binaryArrCn[{0}]:{1},NcharArrCn[{0}]:{2}",i,String.IsNullOrEmpty(binaryArrCn[i]) ? 0 :binaryArrCn[i].Length, String.IsNullOrEmpty(NcharArrCn[i]) ? 0 : NcharArrCn[i].Length); + // Console.WriteLine("========"); + + } + return rowData; + } + + public static List GetMultiBindStableCNRowData() + { + List columnData = new List(); + List tagData = GetTagCnData(); + for (int i = 0; i < tsArr.Length; i++) + { + columnData.Add(tsArr[i].ToString()); + columnData.Add(boolArr[i].Equals(null) ? "NULL" : boolArr[i].ToString()); + columnData.Add(tinyIntArr[i].Equals(null) ? "NULL" : tinyIntArr[i].ToString()); + columnData.Add(shortArr[i].Equals(null) ? "NULL" : shortArr[i].ToString()); + columnData.Add(intArr[i].Equals(null) ? "NULL" : intArr[i].ToString()); + columnData.Add(longArr[i].Equals(null) ? "NULL" : longArr[i].ToString()); + columnData.Add(floatArr[i].Equals(null) ? "NULL" : floatArr[i].ToString()); + columnData.Add(doubleArr[i].Equals(null) ? "NULL" : doubleArr[i].ToString()); + columnData.Add(uTinyIntArr[i].Equals(null) ? "NULL" : uTinyIntArr[i].ToString()); + columnData.Add(uShortArr[i].Equals(null) ? "NULL" : uShortArr[i].ToString()); + columnData.Add(uIntArr[i].Equals(null) ? "NULL" : uIntArr[i].ToString()); + columnData.Add(uLongArr[i].Equals(null) ? "NULL" : uLongArr[i].ToString()); + columnData.Add(String.IsNullOrEmpty(binaryArrCn[i]) ? "NULL" : binaryArrCn[i]); + columnData.Add(String.IsNullOrEmpty(NcharArrCn[i]) ? "NULL" : NcharArrCn[i]); + columnData.AddRange(tagData); + // Console.WriteLine("binaryArrCn[{0}]:{1},NcharArrCn[{0}]:{2}",i,String.IsNullOrEmpty(binaryArrCn[i]) ? "NULL" : binaryArrCn[i],String.IsNullOrEmpty(NcharArrCn[i]) ? "NULL" : NcharArrCn[i]); + // Console.WriteLine("binaryArrCn[{0}]:{1},NcharArrCn[{0}]:{2}",i,String.IsNullOrEmpty(binaryArrCn[i]) ? 0 :binaryArrCn[i].Length, String.IsNullOrEmpty(NcharArrCn[i]) ? 0 : NcharArrCn[i].Length); + // Console.WriteLine("========"); + + } + return columnData; + } + + public static TAOS_BIND[] GetQueryCondition() + { + TAOS_BIND[] queryCondition = new TAOS_BIND[2]; + queryCondition[0] = TaosBind.BindTinyInt(0); + queryCondition[1] = TaosBind.BindInt(1000); + return queryCondition; + + } + public static void FreeTaosBind(TAOS_BIND[] binds) + { + TaosBind.FreeTaosBind(binds); + } + + public static void FreeTaosMBind(TAOS_MULTI_BIND[] mbinds) + { + TaosMultiBind.FreeTaosBind(mbinds); + } + //Get the TDengineMeta list from the ddl either normal table or stable + public static List GetMetaFromDLL(string dllStr) + { + var expectResMeta = new List(); + //"CREATE TABLE meters(ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS(location BINARY(30), groupId INT);"; + int bracetInd = dllStr.IndexOf("("); + //(ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS(location BINARY(30), groupId INT); + string subDllStr = dllStr.Substring(bracetInd); + + String[] stableSeparators = new String[] { "tags", "TAGS" }; + //(ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) + //(location BINARY(30), groupId INT) + String[] dllStrElements = subDllStr.Split(stableSeparators, StringSplitOptions.RemoveEmptyEntries); + //(ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) + dllStrElements[0] = dllStrElements[0].Substring(1, dllStrElements[0].Length - 2); + String[] finalStr1 = dllStrElements[0].Split(',', StringSplitOptions.RemoveEmptyEntries); + foreach (string item in finalStr1) + { + //ts TIMESTAMP + string[] itemArr = item.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries); + // Console.WriteLine("GetMetaFromDLL():{0},{1}",itemArr[0],itemArr[1]); + expectResMeta.Add(UtilsTools.ConstructTDengineMeta(itemArr[0], itemArr[1])); + } + if (dllStr.Contains("TAGS") || dllStr.Contains("tags")) + { + //location BINARY(30), groupId INT + dllStrElements[1] = dllStrElements[1].Substring(1, dllStrElements[1].Length - 2); + //location BINARY(30) groupId INT + String[] finalStr2 = dllStrElements[1].Split(',', StringSplitOptions.RemoveEmptyEntries); + Console.WriteLine("========"); + foreach (string item in finalStr2) + { + //location BINARY(30) + string[] itemArr = item.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries); + // Console.WriteLine("GetMetaFromDLL():{0},{1}",itemArr[0],itemArr[1]); + expectResMeta.Add(UtilsTools.ConstructTDengineMeta(itemArr[0], itemArr[1])); + } + + } + return expectResMeta; + } + + } +} \ No newline at end of file diff --git a/src/connector/C#/src/test/FunctionTest/FetchLength.cs b/src/connector/C#/src/test/FunctionTest/FetchLength.cs new file mode 100644 index 0000000000000000000000000000000000000000..130b53bfc898231456c3f4d0c068108ffa7f50bd --- /dev/null +++ b/src/connector/C#/src/test/FunctionTest/FetchLength.cs @@ -0,0 +1,56 @@ +using System; +using Test.UtilsTools; +using System.Collections.Generic; +using Xunit; +using TDengineDriver; +using Test.UtilsTools.ResultSet; +namespace Cases +{ + public class FetchLengthCase + { + /// xiaolei + /// TestRetrieveBinary + /// TD-12103 C# connector fetch_row with binary data retrieving error + /// FetchLength.cs + /// pass or failed + [Fact(DisplayName = "Skip FetchLengthCase.TestRetrieveBinary()")] + public void TestRetrieveBinary() + { + IntPtr conn = UtilsTools.TDConnection(); + var expectData = new List { "log", "test", "db02", "db3" }; + var expectMeta = new List{ + UtilsTools.ConstructTDengineMeta("ts","timestamp"), + UtilsTools.ConstructTDengineMeta("name","binary(10)"), + UtilsTools.ConstructTDengineMeta("n","int") + }; + string sql0 = "drop table if exists stb1;"; + string sql1 = "create stable if not exists stb1 (ts timestamp, name binary(10)) tags(n int);"; + string sql2 = $"insert into tb1 using stb1 tags(1) values(now, '{expectData[0]}');"; + string sql3 = $"insert into tb2 using stb1 tags(2) values(now, '{expectData[1]}');"; + string sql4 = $"insert into tb3 using stb1 tags(3) values(now, '{expectData[2]}');"; + string sql5 = $"insert into tb4 using stb1 tags(4) values(now, '{expectData[3]}');"; + + string sql6 = "select distinct(name) from stb1;"; + UtilsTools.ExecuteQuery(conn, sql0); + UtilsTools.ExecuteQuery(conn, sql1); + UtilsTools.ExecuteQuery(conn, sql2); + UtilsTools.ExecuteQuery(conn, sql3); + UtilsTools.ExecuteQuery(conn, sql4); + UtilsTools.ExecuteQuery(conn, sql5); + + IntPtr resPtr = IntPtr.Zero; + resPtr = UtilsTools.ExecuteQuery(conn, sql6); + + ResultSet actualResult = new ResultSet(resPtr); + List actualData = actualResult.GetResultData(); + List actualMeta = actualResult.GetResultMeta(); + expectData.Reverse(); + + Assert.Equal(expectData[0], actualData[0]); + Assert.Equal(expectMeta[1].name, actualMeta[0].name); + Assert.Equal(expectMeta[1].size, actualMeta[0].size); + Assert.Equal(expectMeta[1].type, actualMeta[0].type); + + } + } +} diff --git a/src/connector/C#/src/test/FunctionTest/FunctionTest.csproj b/src/connector/C#/src/test/FunctionTest/FunctionTest.csproj new file mode 100644 index 0000000000000000000000000000000000000000..a30d3c760056ba25e3cfbec83067718712b5229f --- /dev/null +++ b/src/connector/C#/src/test/FunctionTest/FunctionTest.csproj @@ -0,0 +1,28 @@ + + + + net5.0 + false + CS1591;CS0168 + true + ..\doc\FunctionTest.XML + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/src/connector/C#/src/test/FunctionTest/ResultSetUtils.cs b/src/connector/C#/src/test/FunctionTest/ResultSetUtils.cs new file mode 100644 index 0000000000000000000000000000000000000000..1a904c827f3bae320cbaed390ebc6765226f735a --- /dev/null +++ b/src/connector/C#/src/test/FunctionTest/ResultSetUtils.cs @@ -0,0 +1,39 @@ +using System; +using TDengineDriver; +using System.Runtime.InteropServices; +using System.Text; +using System.Collections.Generic; +namespace Test.UtilsTools.ResultSet +{ + public class ResultSet + { + private List resultMeta; + private List resultData; + // private bool isValidResult = false; + public ResultSet(IntPtr res) + { + + resultMeta = UtilsTools.GetResField(res); + resultData = UtilsTools.GetResData(res); + } + + public ResultSet(List metas, List datas) + { + resultMeta = metas; + resultData = datas; + } + + public List GetResultData() + { + return resultData; + } + + public List GetResultMeta() + { + return resultMeta; + } + + } + + +} \ No newline at end of file diff --git a/src/connector/C#/src/test/FunctionTest/StmtNormalTable.cs b/src/connector/C#/src/test/FunctionTest/StmtNormalTable.cs new file mode 100644 index 0000000000000000000000000000000000000000..7e6cc92d65863b634261153c9eb38c5c0a590891 --- /dev/null +++ b/src/connector/C#/src/test/FunctionTest/StmtNormalTable.cs @@ -0,0 +1,455 @@ +using System; +using Test.UtilsTools; +using TDengineDriver; +using Test.UtilsTools.DataSource; +using Xunit; +using System.Collections.Generic; +using Test.UtilsTools.ResultSet; +namespace Cases +{ + public class NormalTableStmtCases + { + /// xiaolei + /// NormalTableStmtCases.TestBindSingleLineCn + /// Test stmt insert single line of chinese character into normal table by column after column + /// StmtNormalTable.cs + /// pass or failed + [Fact(DisplayName = "NormalTableStmtCases.TestBindSingleLineCn()")] + public void TestBindSingleLineCn() + { + string tableName = "normal_tablestmt_cases_test_bind_single_line_cn"; + String createTb = $"create table if not exists {tableName} (" + + "ts timestamp," + + "tt tinyint," + + "si smallint," + + "ii int," + + "bi bigint," + + "tu tinyint unsigned," + + "su smallint unsigned," + + "iu int unsigned," + + "bu bigint unsigned," + + "ff float," + + "dd double," + + "bb binary(200)," + + "nc nchar(200)," + + "bo bool," + + "nullval int" + + ");"; + string insertSql = "insert into ? values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + string dropSql = $"drop table if exists {tableName}"; + string querySql = "select * from " + tableName; + TAOS_BIND[] _valuesRow = DataSource.GetNtableCNRow(); + List expectResData = DataSource.GetNtableCNRowData(); + List expectResMeta = DataSource.GetMetaFromDLL(createTb); + + IntPtr conn = UtilsTools.TDConnection(); + UtilsTools.ExecuteUpdate(conn, dropSql); + UtilsTools.ExecuteUpdate(conn, createTb); + + IntPtr stmt = StmtUtilTools.StmtInit(conn); + StmtUtilTools.StmtPrepare(stmt, insertSql); + StmtUtilTools.SetTableName(stmt, tableName); + StmtUtilTools.BindParam(stmt, _valuesRow); + StmtUtilTools.AddBatch(stmt); + StmtUtilTools.StmtExecute(stmt); + StmtUtilTools.StmtClose(stmt); + DataSource.FreeTaosBind(_valuesRow); + + IntPtr res = UtilsTools.ExecuteQuery(conn, querySql); + ResultSet actualResult = new ResultSet(res); + + List actualResMeta = actualResult.GetResultMeta(); + List actualResData = actualResult.GetResultData(); + + // Assert retrieve data + for (int i = 0; i < actualResData.Count; i++) + { + Assert.Equal(expectResData[i], actualResData[i]); + } + // Assert metadata + for (int i = 0; i < actualResMeta.Count; i++) + { + Assert.Equal(expectResMeta[i].name, actualResMeta[i].name); + Assert.Equal(expectResMeta[i].type, actualResMeta[i].type); + Assert.Equal(expectResMeta[i].size, actualResMeta[i].size); + } + } + + /// xiaolei + /// NormalTableStmtCases.TestBindColumnCn + /// Test stmt insert single line of chinese character into normal table by column after column + /// StmtNormalTable.cs + /// pass or failed + [Fact(DisplayName = "NormalTableStmtCases.TestBindColumnCn()")] + public void TestBindColumnCn() + { + string tableName = "normal_tablestmt_cases_test_bind_column_cn"; + String createTb = $"create table if not exists {tableName} " + + " (" + + "ts timestamp," + + "b bool," + + "v1 tinyint," + + "v2 smallint," + + "v4 int," + + "v8 bigint," + + "f4 float," + + "f8 double," + + "u1 tinyint unsigned," + + "u2 smallint unsigned," + + "u4 int unsigned," + + "u8 bigint unsigned," + + "bin binary(200)," + + "blob nchar(200)" + + ");"; + String insertSql = "insert into ? values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + String dropSql = $"drop table if exists {tableName} "; + List expectResData = DataSource.GetMultiBindCNRowData(); + TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindCNArr(); + List expectResMeta = DataSource.GetMetaFromDLL(createTb); + + IntPtr conn = UtilsTools.TDConnection(); + UtilsTools.ExecuteUpdate(conn, dropSql); + UtilsTools.ExecuteUpdate(conn, createTb); + + IntPtr stmt = StmtUtilTools.StmtInit(conn); + StmtUtilTools.StmtPrepare(stmt, insertSql); + StmtUtilTools.SetTableName(stmt, tableName); + + StmtUtilTools.BindSingleParamBatch(stmt, mbind[0], 0); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[1], 1); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[2], 2); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[3], 3); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[4], 4); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[5], 5); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[6], 6); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[7], 7); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[8], 8); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[9], 9); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[10], 10); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[11], 11); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[12], 12); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[13], 13); + + StmtUtilTools.AddBatch(stmt); + StmtUtilTools.StmtExecute(stmt); + StmtUtilTools.StmtClose(stmt); + + DataSource.FreeTaosMBind(mbind); + + string querySql = "select * from " + tableName; + IntPtr res = UtilsTools.ExecuteQuery(conn, querySql); + ResultSet actualResult = new ResultSet(res); + + List actualResMeta = actualResult.GetResultMeta(); + List actualResData = actualResult.GetResultData(); + // Assert retrieve data + for (int i = 0; i < actualResData.Count; i++) + { + Assert.Equal(expectResData[i], actualResData[i]); + } + // Assert metadata + for (int i = 0; i < actualResMeta.Count; i++) + { + Assert.Equal(expectResMeta[i].name, actualResMeta[i].name); + Assert.Equal(expectResMeta[i].type, actualResMeta[i].type); + Assert.Equal(expectResMeta[i].size, actualResMeta[i].size); + + } + } + + /// xiaolei + /// NormalTableStmtCases.TestBindMultiLineCn + /// Test stmt insert single line of chinese character into normal table by column after column + /// StmtNormalTable.cs + /// pass or failed + [Fact(DisplayName = "NormalTableStmtCases.TestBindMultiLineCn()")] + public void TestBindMultiLineCn() + { + string tableName = "normal_tablestmt_cases_test_bind_multi_lines_cn"; + TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindCNArr(); + String createTb = $"create table if not exists {tableName} " + + " (" + + "ts timestamp," + + "b bool," + + "v1 tinyint," + + "v2 smallint," + + "v4 int," + + "v8 bigint," + + "f4 float," + + "f8 double," + + "u1 tinyint unsigned," + + "u2 smallint unsigned," + + "u4 int unsigned," + + "u8 bigint unsigned," + + "bin binary(200)," + + "blob nchar(200)" + + ");"; + String insertSql = "insert into ? values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + String dropSql = $"drop table if exists {tableName} "; + List expectResData = DataSource.GetMultiBindCNRowData(); + List expectResMeta = DataSource.GetMetaFromDLL(createTb); + + IntPtr conn = UtilsTools.TDConnection(); ; + UtilsTools.ExecuteUpdate(conn, dropSql); + UtilsTools.ExecuteUpdate(conn, createTb); + + IntPtr stmt = StmtUtilTools.StmtInit(conn); + StmtUtilTools.StmtPrepare(stmt, insertSql); + StmtUtilTools.SetTableName(stmt, tableName); + StmtUtilTools.BindParamBatch(stmt, mbind); + StmtUtilTools.AddBatch(stmt); + StmtUtilTools.StmtExecute(stmt); + StmtUtilTools.StmtClose(stmt); + + DataSource.FreeTaosMBind(mbind); + + string querySql = "select * from " + tableName; + IntPtr res = UtilsTools.ExecuteQuery(conn, querySql); + ResultSet actualResult = new ResultSet(res); + + List actualResMeta = actualResult.GetResultMeta(); + List actualResData = actualResult.GetResultData(); + Assert.Equal(expectResMeta.Count, actualResMeta.Count); + Assert.Equal(expectResData.Count, actualResData.Count); + + // Assert retrieve data + for (int i = 0; i < actualResData.Count; i++) + { + Assert.Equal(expectResData[i], actualResData[i]); + } + // Assert metadata + for (int i = 0; i < actualResMeta.Count; i++) + { + Assert.Equal(expectResMeta[i].name, actualResMeta[i].name); + Assert.Equal(expectResMeta[i].type, actualResMeta[i].type); + Assert.Equal(expectResMeta[i].size, actualResMeta[i].size); + } + } + + /// xiaolei + /// NormalTableStmtCases.TestBindSingleLine + /// Test stmt insert sinle line data into normal table + /// StmtNormalTable.cs + /// pass or failed + [Fact(DisplayName = "NormalTableStmtCases.TestBindSingleLine")] + public void TestBindSingleLine() + { + string tableName = "normal_tablestmt_cases_test_bind_single_line"; + String createTb = $"create table if not exists {tableName} (" + + "ts timestamp," + + "tt tinyint," + + "si smallint," + + "ii int," + + "bi bigint," + + "tu tinyint unsigned," + + "su smallint unsigned," + + "iu int unsigned," + + "bu bigint unsigned," + + "ff float," + + "dd double," + + "bb binary(200)," + + "nc nchar(200)," + + "bo bool," + + "nullval int" + + ");"; + string insertSql = "insert into ? values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + string dropSql = $"drop table if exists {tableName}"; + string querySql = "select * from " + tableName; + TAOS_BIND[] valuesRow = DataSource.GetNtableRow(); + List expectResData = DataSource.GetNtableRowData(); + List expectResMeta = DataSource.GetMetaFromDLL(createTb); + + IntPtr conn = UtilsTools.TDConnection(); + UtilsTools.ExecuteQuery(conn, dropSql); + UtilsTools.ExecuteQuery(conn, createTb); + + IntPtr stmt = StmtUtilTools.StmtInit(conn); + StmtUtilTools.StmtPrepare(stmt, insertSql); + StmtUtilTools.SetTableName(stmt, tableName); + StmtUtilTools.BindParam(stmt, valuesRow); + StmtUtilTools.AddBatch(stmt); + StmtUtilTools.StmtExecute(stmt); + StmtUtilTools.StmtClose(stmt); + DataSource.FreeTaosBind(valuesRow); + + IntPtr res = UtilsTools.ExecuteQuery(conn, querySql); + ResultSet actualResult = new ResultSet(res); + + List actualResMeta = actualResult.GetResultMeta(); + List actualResData = actualResult.GetResultData(); + Assert.Equal(expectResMeta.Count, actualResMeta.Count); + Assert.Equal(expectResData.Count, actualResData.Count); + + // Assert retrieve data + for (int i = 0; i < actualResData.Count; i++) + { + Assert.Equal(expectResData[i], actualResData[i]); + } + // Assert metadata + for (int i = 0; i < actualResMeta.Count; i++) + { + Assert.Equal(expectResMeta[i].name, actualResMeta[i].name); + Assert.Equal(expectResMeta[i].type, actualResMeta[i].type); + Assert.Equal(expectResMeta[i].size, actualResMeta[i].size); + } + + } + + /// xiaolei + /// NtableMutipleLine.TestBindMultiLine + /// Test stmt insert multiple rows of data into normal table + /// StmtNormalTable.cs + /// pass or failed + [Fact(DisplayName = "NormalTableStmtCases.TestBindMultiLine()")] + public void TestBindMultiLine() + { + string tableName = "normal_table_stmt_cases_test_bind_multi_lines"; + String createTb = $"create table if not exists {tableName} " + + " (" + + "ts timestamp," + + "b bool," + + "v1 tinyint," + + "v2 smallint," + + "v4 int," + + "v8 bigint," + + "f4 float," + + "f8 double," + + "u1 tinyint unsigned," + + "u2 smallint unsigned," + + "u4 int unsigned," + + "u8 bigint unsigned," + + "bin binary(200)," + + "blob nchar(200)" + + ");"; + String insertSql = "insert into ? values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + String dropSql = $"drop table if exists {tableName} "; + List expectResData = DataSource.GetMultiBindResData(); + TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindArr(); + List expectResMeta = DataSource.GetMetaFromDLL(createTb); + + IntPtr conn = UtilsTools.TDConnection(); + UtilsTools.ExecuteUpdate(conn, dropSql); + UtilsTools.ExecuteUpdate(conn, createTb); + + + IntPtr stmt = StmtUtilTools.StmtInit(conn); + StmtUtilTools.StmtPrepare(stmt, insertSql); + StmtUtilTools.SetTableName(stmt, tableName); + StmtUtilTools.BindParamBatch(stmt, mbind); + StmtUtilTools.AddBatch(stmt); + StmtUtilTools.StmtExecute(stmt); + StmtUtilTools.StmtClose(stmt); + DataSource.FreeTaosMBind(mbind); + + string querySql = "select * from " + tableName; + IntPtr res = UtilsTools.ExecuteQuery(conn, querySql); + ResultSet actualResult = new ResultSet(res); + + List actualResMeta = actualResult.GetResultMeta(); + List actualResData = actualResult.GetResultData(); + Assert.Equal(expectResMeta.Count, actualResMeta.Count); + Assert.Equal(expectResData.Count, actualResData.Count); + + // Assert retrieve data + for (int i = 0; i < actualResData.Count; i++) + { + Assert.Equal(expectResData[i], actualResData[i]); + } + // Assert metadata + for (int i = 0; i < actualResMeta.Count; i++) + { + Assert.Equal(expectResMeta[i].name, actualResMeta[i].name); + Assert.Equal(expectResMeta[i].type, actualResMeta[i].type); + Assert.Equal(expectResMeta[i].size, actualResMeta[i].size); + } + } + + /// xiaolei + /// NtableColumnByColumn.TestBindColumnCn + /// Test stmt insert multiple rows of data into normal table by column after column + /// StmtNormalTable.cs + /// pass or failed + [Fact(DisplayName = "NormalTableStmtCases.TestBindColumn()")] + public void TestBindColumn() + { + string tableName = "normal_tablestmt_cases_test_bind_column_cn"; + DataSource data = new DataSource(); + String createTb = $"create table if not exists {tableName} " + + " (" + + "ts timestamp," + + "b bool," + + "v1 tinyint," + + "v2 smallint," + + "v4 int," + + "v8 bigint," + + "f4 float," + + "f8 double," + + "u1 tinyint unsigned," + + "u2 smallint unsigned," + + "u4 int unsigned," + + "u8 bigint unsigned," + + "bin binary(200)," + + "blob nchar(200)" + + ");"; + String insertSql = "insert into ? values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + String dropSql = $"drop table if exists {tableName} "; + List expectResData = DataSource.GetMultiBindResData(); + TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindArr(); + List expectResMeta = DataSource.GetMetaFromDLL(createTb); + + + IntPtr conn = UtilsTools.TDConnection(); + UtilsTools.ExecuteUpdate(conn, dropSql); + UtilsTools.ExecuteUpdate(conn, createTb); + + IntPtr stmt = StmtUtilTools.StmtInit(conn); + StmtUtilTools.StmtPrepare(stmt, insertSql); + StmtUtilTools.SetTableName(stmt, tableName); + + StmtUtilTools.BindSingleParamBatch(stmt, mbind[0], 0); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[1], 1); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[2], 2); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[3], 3); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[4], 4); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[5], 5); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[6], 6); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[7], 7); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[8], 8); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[9], 9); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[10], 10); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[11], 11); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[12], 12); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[13], 13); + + StmtUtilTools.AddBatch(stmt); + StmtUtilTools.StmtExecute(stmt); + StmtUtilTools.StmtClose(stmt); + + DataSource.FreeTaosMBind(mbind); + + string querySql = "select * from " + tableName; + IntPtr res = UtilsTools.ExecuteQuery(conn, querySql); + ResultSet actualResult = new ResultSet(res); + + List actualResMeta = actualResult.GetResultMeta(); + List actualResData = actualResult.GetResultData(); + Assert.Equal(expectResMeta.Count, actualResMeta.Count); + Assert.Equal(expectResData.Count, actualResData.Count); + + // Assert retrieve data + for (int i = 0; i < actualResData.Count; i++) + { + Assert.Equal(expectResData[i], actualResData[i]); + } + // Assert metadata + for (int i = 0; i < actualResMeta.Count; i++) + { + Assert.Equal(expectResMeta[i].name, actualResMeta[i].name); + Assert.Equal(expectResMeta[i].type, actualResMeta[i].type); + Assert.Equal(expectResMeta[i].size, actualResMeta[i].size); + } + + } + + } +} \ No newline at end of file diff --git a/src/connector/C#/src/test/Cases/StmtQuery.cs b/src/connector/C#/src/test/FunctionTest/StmtQuery.cs similarity index 100% rename from src/connector/C#/src/test/Cases/StmtQuery.cs rename to src/connector/C#/src/test/FunctionTest/StmtQuery.cs diff --git a/src/connector/C#/src/test/FunctionTest/StmtStable.cs b/src/connector/C#/src/test/FunctionTest/StmtStable.cs new file mode 100644 index 0000000000000000000000000000000000000000..c79c355f02f8a6351098f6fca773751f64182ff9 --- /dev/null +++ b/src/connector/C#/src/test/FunctionTest/StmtStable.cs @@ -0,0 +1,468 @@ +using System; +using Test.UtilsTools; +using TDengineDriver; +using Test.UtilsTools.DataSource; +using System.Collections.Generic; +using Test.UtilsTools.ResultSet; +using Xunit; + +namespace Cases +{ + public class StableStmtCases + { + /// xiaolei + /// StableStmtCases.TestBindSingleLineCn + /// Test stmt insert single line of chinese character into stable by column after column + /// StmtSTable.cs + /// pass or failed + [Fact(DisplayName = "StableStmtCases.TestBindSingleLineCn()")] + public void TestBindSingleLineCn() + { + string tableName = "stable_stmt_cases_test_bind_single_line_cn"; + String createSql = $"create stable if not exists {tableName} " + + " (ts timestamp," + + "v1 tinyint," + + "v2 smallint," + + "v4 int," + + "v8 bigint," + + "u1 tinyint unsigned," + + "u2 smallint unsigned," + + "u4 int unsigned," + + "u8 bigint unsigned," + + "f4 float," + + "f8 double," + + "bin binary(200)," + + "blob nchar(200)," + + "b bool," + + "nilcol int)" + + "tags" + + "(bo bool," + + "tt tinyint," + + "si smallint," + + "ii int," + + "bi bigint," + + "tu tinyint unsigned," + + "su smallint unsigned," + + "iu int unsigned," + + "bu bigint unsigned," + + "ff float," + + "dd double," + + "bb binary(200)," + + "nc nchar(200)" + + ");"; + String insertSql = $"insert into ? using {tableName} tags(?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + String dropSql = $"drop table if exists {tableName} ;"; + List expectResMeta = DataSource.GetMetaFromDLL(createSql); + List expectResData = DataSource.GetStableCNRowData(); + TAOS_BIND[] tags = DataSource.GetCNTags(); + TAOS_BIND[] binds = DataSource.GetNtableCNRow(); + + IntPtr conn = UtilsTools.TDConnection(); + UtilsTools.ExecuteUpdate(conn, dropSql); + UtilsTools.ExecuteUpdate(conn, createSql); + + IntPtr stmt = StmtUtilTools.StmtInit(conn); + StmtUtilTools.StmtPrepare(stmt, insertSql); + StmtUtilTools.SetTableNameTags(stmt, tableName + "_t1", tags); + StmtUtilTools.BindParam(stmt, binds); + StmtUtilTools.AddBatch(stmt); + StmtUtilTools.StmtExecute(stmt); + StmtUtilTools.StmtClose(stmt); + + DataSource.FreeTaosBind(tags); + DataSource.FreeTaosBind(binds); + + string querySql = "select * from " + tableName; + IntPtr res = UtilsTools.ExecuteQuery(conn, querySql); + ResultSet actualResult = new ResultSet(res); + + List actualResMeta = actualResult.GetResultMeta(); + List actualResData = actualResult.GetResultData(); + + // Assert retrieve data + for (int i = 0; i < actualResData.Count; i++) + { + Assert.Equal(expectResData[i], actualResData[i]); + } + // Assert metadata + for (int i = 0; i < actualResMeta.Count; i++) + { + Assert.Equal(expectResMeta[i].name, actualResMeta[i].name); + Assert.Equal(expectResMeta[i].type, actualResMeta[i].type); + Assert.Equal(expectResMeta[i].size, actualResMeta[i].size); + } + + } + + /// xiaolei + /// StableStmtCases.TestBindColumnCn + /// Test stmt insert single line of chinese character into stable by column after column + /// StmtSTable.cs + /// pass or failed + [Fact(DisplayName = "StableStmtCases.TestBindColumnCn()")] + public void TestBindColumnCn() + { + string tableName = "stable_stmt_cases_test_bindcolumn_cn"; + String createSql = $"create stable if not exists {tableName} " + + "(ts timestamp," + + "b bool," + + "v1 tinyint," + + "v2 smallint," + + "v4 int," + + "v8 bigint," + + "f4 float," + + "f8 double," + + "u1 tinyint unsigned," + + "u2 smallint unsigned," + + "u4 int unsigned," + + "u8 bigint unsigned," + + "bin binary(200)," + + "blob nchar(200)" + + ")" + + "tags" + + "(bo bool," + + "tt tinyint," + + "si smallint," + + "ii int," + + "bi bigint," + + "tu tinyint unsigned," + + "su smallint unsigned," + + "iu int unsigned," + + "bu bigint unsigned," + + "ff float," + + "dd double," + + "bb binary(200)," + + "nc nchar(200)" + + ");"; + String insertSql = "insert into ? using " + tableName + " tags(?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + String dropSql = $"drop table if exists {tableName};"; + TAOS_BIND[] tags = DataSource.GetCNTags(); + TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindCNArr(); + List expectResMeta = DataSource.GetMetaFromDLL(createSql); + List expectResData = DataSource.GetMultiBindStableCNRowData(); + + IntPtr conn = UtilsTools.TDConnection(); + UtilsTools.ExecuteUpdate(conn, dropSql); + UtilsTools.ExecuteUpdate(conn, createSql); + + IntPtr stmt = StmtUtilTools.StmtInit(conn); + StmtUtilTools.StmtPrepare(stmt, insertSql); + StmtUtilTools.SetTableNameTags(stmt, tableName + "_t1", tags); + + StmtUtilTools.BindSingleParamBatch(stmt, mbind[0], 0); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[1], 1); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[2], 2); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[3], 3); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[4], 4); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[5], 5); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[6], 6); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[7], 7); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[8], 8); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[9], 9); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[10], 10); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[11], 11); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[12], 12); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[13], 13); + + StmtUtilTools.AddBatch(stmt); + StmtUtilTools.StmtExecute(stmt); + StmtUtilTools.StmtClose(stmt); + + DataSource.FreeTaosBind(tags); + DataSource.FreeTaosMBind(mbind); + + string querySql = "select * from " + tableName; + IntPtr res = UtilsTools.ExecuteQuery(conn, querySql); + ResultSet actualResult = new ResultSet(res); + + List actualResMeta = actualResult.GetResultMeta(); + List actualResData = actualResult.GetResultData(); + + // Assert retrieve data + for (int i = 0; i < actualResData.Count; i++) + { + Assert.Equal(expectResData[i], actualResData[i]); + } + // Assert metadata + for (int i = 0; i < actualResMeta.Count; i++) + { + Assert.Equal(expectResMeta[i].name, actualResMeta[i].name); + Assert.Equal(expectResMeta[i].type, actualResMeta[i].type); + Assert.Equal(expectResMeta[i].size, actualResMeta[i].size); + } + + + } + + /// xiaolei + /// StableStmtCases.TestBindMultiLineCn + /// Test stmt insert single line of chinese character into stable by column after column + /// StmtSTable.cs + /// pass or failed + [Fact(DisplayName = "StableStmtCases.TestBindMultiLineCn()")] + public void TestBindMultiLineCn() + { + string tableName = "stable_stmt_cases_test_bind_multi_line_cn"; + String createSql = $"create stable if not exists {tableName} " + + "(ts timestamp," + + "b bool," + + "v1 tinyint," + + "v2 smallint," + + "v4 int," + + "v8 bigint," + + "f4 float," + + "f8 double," + + "u1 tinyint unsigned," + + "u2 smallint unsigned," + + "u4 int unsigned," + + "u8 bigint unsigned," + + "bin binary(200)," + + "blob nchar(200)" + + ")" + + "tags" + + "(bo bool," + + "tt tinyint," + + "si smallint," + + "ii int," + + "bi bigint," + + "tu tinyint unsigned," + + "su smallint unsigned," + + "iu int unsigned," + + "bu bigint unsigned," + + "ff float," + + "dd double," + + "bb binary(200)," + + "nc nchar(200)" + + ");"; + String insertSql = "insert into ? using " + tableName + " tags(?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + String dropSql = $"drop table if exists {tableName};"; + TAOS_BIND[] tags = DataSource.GetCNTags(); + TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindCNArr(); + List expectResMeta = DataSource.GetMetaFromDLL(createSql); + List expectResData = DataSource.GetMultiBindStableCNRowData(); + + IntPtr conn = UtilsTools.TDConnection(); + UtilsTools.ExecuteUpdate(conn, dropSql); + UtilsTools.ExecuteUpdate(conn, createSql); + + IntPtr stmt = StmtUtilTools.StmtInit(conn); + StmtUtilTools.StmtPrepare(stmt, insertSql); + StmtUtilTools.SetTableNameTags(stmt, tableName + "_t1", tags); + StmtUtilTools.BindParamBatch(stmt, mbind); + StmtUtilTools.AddBatch(stmt); + StmtUtilTools.StmtExecute(stmt); + + StmtUtilTools.StmtClose(stmt); + DataSource.FreeTaosBind(tags); + DataSource.FreeTaosMBind(mbind); + + string querySql = "select * from " + tableName; + IntPtr res = UtilsTools.ExecuteQuery(conn, querySql); + ResultSet actualResult = new ResultSet(res); + + List actualResMeta = actualResult.GetResultMeta(); + List actualResData = actualResult.GetResultData(); + + // Assert retrieve data + for (int i = 0; i < actualResData.Count; i++) + { + Assert.Equal(expectResData[i], actualResData[i]); + } + // Assert metadata + for (int i = 0; i < actualResMeta.Count; i++) + { + Assert.Equal(expectResMeta[i].name, actualResMeta[i].name); + Assert.Equal(expectResMeta[i].type, actualResMeta[i].type); + Assert.Equal(expectResMeta[i].size, actualResMeta[i].size); + } + } + + /// xiaolei + /// StableStmtCases.TestBindMultiLine + /// Test stmt insert single line into stable by column after column + /// StmtSTable.cs + /// pass or failed + [Fact(DisplayName = "StableStmtCases.TestBindMultiLine()")] + public void TestBindMultiLine() + { + string tableName = "stable_stmt_cases_test_bind_multi_line"; + string createSql = $"create stable if not exists {tableName} " + + "(ts timestamp," + + "b bool," + + "v1 tinyint," + + "v2 smallint," + + "v4 int," + + "v8 bigint," + + "f4 float," + + "f8 double," + + "u1 tinyint unsigned," + + "u2 smallint unsigned," + + "u4 int unsigned," + + "u8 bigint unsigned," + + "bin binary(200)," + + "blob nchar(200)" + + ")" + + "tags" + + "(bo bool," + + "tt tinyint," + + "si smallint," + + "ii int," + + "bi bigint," + + "tu tinyint unsigned," + + "su smallint unsigned," + + "iu int unsigned," + + "bu bigint unsigned," + + "ff float," + + "dd double," + + "bb binary(200)," + + "nc nchar(200)" + + ");"; + String insertSql = "insert into ? using " + tableName + " tags(?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + String dropSql = $"drop table if exists {tableName};"; + TAOS_BIND[] tags = DataSource.GetTags(); + TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindArr(); + List expectResMeta = DataSource.GetMetaFromDLL(createSql); + List expectResData = DataSource.GetMultiBindStableRowData(); + + IntPtr conn = UtilsTools.TDConnection(); + UtilsTools.ExecuteUpdate(conn, dropSql); + UtilsTools.ExecuteUpdate(conn, createSql); + + IntPtr stmt = StmtUtilTools.StmtInit(conn); + StmtUtilTools.StmtPrepare(stmt, insertSql); + StmtUtilTools.SetTableNameTags(stmt, tableName + "_t1", tags); + StmtUtilTools.BindParamBatch(stmt, mbind); + StmtUtilTools.AddBatch(stmt); + StmtUtilTools.StmtExecute(stmt); + StmtUtilTools.StmtClose(stmt); + + DataSource.FreeTaosBind(tags); + DataSource.FreeTaosMBind(mbind); + + string querySql = "select * from " + tableName; + IntPtr res = UtilsTools.ExecuteQuery(conn, querySql); + ResultSet actualResult = new ResultSet(res); + + List actualResMeta = actualResult.GetResultMeta(); + List actualResData = actualResult.GetResultData(); + + // Assert retrieve data + for (int i = 0; i < actualResData.Count; i++) + { + // Assert.Equal(expectResData[i],actualResData[i]); + if (expectResData[i] != actualResData[i]) + { + Console.WriteLine("{0}==>,expectResData:{1},actualResData:{2}", i, expectResData[i], actualResData[i]); + } + + } + // Assert metadata + for (int i = 0; i < actualResMeta.Count; i++) + { + Assert.Equal(expectResMeta[i].name, actualResMeta[i].name); + Assert.Equal(expectResMeta[i].type, actualResMeta[i].type); + Assert.Equal(expectResMeta[i].size, actualResMeta[i].size); + } + } + + /// xiaolei + /// StableStmtCases.TestBindColumn + /// Test stmt insert single line of chinese character into stable by column after column + /// StmtSTable.cs + /// pass or failed + [Fact(DisplayName = "StableStmtCases.TestBindColumn()")] + public void TestBindColumn() + { + string tableName = "stable_stmt_cases_test_bindcolumn"; + string createSql = $"create stable if not exists {tableName} " + + "(ts timestamp," + + "b bool," + + "v1 tinyint," + + "v2 smallint," + + "v4 int," + + "v8 bigint," + + "f4 float," + + "f8 double," + + "u1 tinyint unsigned," + + "u2 smallint unsigned," + + "u4 int unsigned," + + "u8 bigint unsigned," + + "bin binary(200)," + + "blob nchar(200)" + + ")" + + "tags" + + "(bo bool," + + "tt tinyint," + + "si smallint," + + "ii int," + + "bi bigint," + + "tu tinyint unsigned," + + "su smallint unsigned," + + "iu int unsigned," + + "bu bigint unsigned," + + "ff float," + + "dd double," + + "bb binary(200)," + + "nc nchar(200)" + + ");"; + String insertSql = "insert into ? using " + tableName + " tags(?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + String dropSql = $"drop table if exists {tableName};"; + TAOS_BIND[] tags = DataSource.GetTags(); + TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindArr(); + List expectResMeta = DataSource.GetMetaFromDLL(createSql); + List expectResData = DataSource.GetMultiBindStableRowData(); + + IntPtr conn = UtilsTools.TDConnection(); + UtilsTools.ExecuteUpdate(conn, dropSql); + UtilsTools.ExecuteUpdate(conn, createSql); + + IntPtr stmt = StmtUtilTools.StmtInit(conn); + StmtUtilTools.StmtPrepare(stmt, insertSql); + + StmtUtilTools.SetTableNameTags(stmt, tableName + "_t1", tags); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[0], 0); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[1], 1); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[2], 2); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[3], 3); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[4], 4); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[5], 5); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[6], 6); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[7], 7); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[8], 8); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[9], 9); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[10], 10); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[11], 11); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[12], 12); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[13], 13); + + StmtUtilTools.AddBatch(stmt); + StmtUtilTools.StmtExecute(stmt); + StmtUtilTools.StmtClose(stmt); + + DataSource.FreeTaosBind(tags); + DataSource.FreeTaosMBind(mbind); + + string querySql = "select * from " + tableName; + IntPtr res = UtilsTools.ExecuteQuery(conn, querySql); + ResultSet actualResult = new ResultSet(res); + + List actualResMeta = actualResult.GetResultMeta(); + List actualResData = actualResult.GetResultData(); + + // Assert retrieve data + for (int i = 0; i < actualResData.Count; i++) + { + Assert.Equal(expectResData[i], actualResData[i]); + } + // Assert metadata + for (int i = 0; i < actualResMeta.Count; i++) + { + Assert.Equal(expectResMeta[i].name, actualResMeta[i].name); + Assert.Equal(expectResMeta[i].type, actualResMeta[i].type); + Assert.Equal(expectResMeta[i].size, actualResMeta[i].size); + } + + } + + } +} \ No newline at end of file diff --git a/src/connector/C#/src/test/Cases/StmtUtil.cs b/src/connector/C#/src/test/FunctionTest/StmtUtil.cs similarity index 100% rename from src/connector/C#/src/test/Cases/StmtUtil.cs rename to src/connector/C#/src/test/FunctionTest/StmtUtil.cs diff --git a/src/connector/C#/src/test/FunctionTest/TaosFeild.cs b/src/connector/C#/src/test/FunctionTest/TaosFeild.cs new file mode 100644 index 0000000000000000000000000000000000000000..4de1415f7b0ce511e8262d8fdd64c7f9b52b1de4 --- /dev/null +++ b/src/connector/C#/src/test/FunctionTest/TaosFeild.cs @@ -0,0 +1,80 @@ +using System; +using Test.UtilsTools; +using TDengineDriver; +using System.Collections.Generic; +using Xunit; +using Test.UtilsTools.ResultSet; +namespace Cases +{ + public class FetchFieldCases + { + /// xiaolei + /// FetchFieldCases.TestFetchFieldJsonTag + /// test taos_fetch_fields(), check the meta data + /// TaosFeild.cs + /// pass or failed + [Fact(DisplayName = "FetchFieldCases.TestFetchFieldJsonTag()")] + public void TestFetchFieldJsonTag() + { + IntPtr conn = UtilsTools.TDConnection(); + IntPtr _res = IntPtr.Zero; + string tableName = "fetchfeilds"; + var expectResMeta = new List { + UtilsTools.ConstructTDengineMeta("ts", "timestamp"), + UtilsTools.ConstructTDengineMeta("b", "bool"), + UtilsTools.ConstructTDengineMeta("v1", "tinyint"), + UtilsTools.ConstructTDengineMeta("v2", "smallint"), + UtilsTools.ConstructTDengineMeta("v4", "int"), + UtilsTools.ConstructTDengineMeta("v8", "bigint"), + UtilsTools.ConstructTDengineMeta("f4", "float"), + UtilsTools.ConstructTDengineMeta("f8", "double"), + UtilsTools.ConstructTDengineMeta("u1", "tinyint unsigned"), + UtilsTools.ConstructTDengineMeta("u2", "smallint unsigned"), + UtilsTools.ConstructTDengineMeta("u4", "int unsigned"), + UtilsTools.ConstructTDengineMeta("u8", "bigint unsigned"), + UtilsTools.ConstructTDengineMeta("bin", "binary(200)"), + UtilsTools.ConstructTDengineMeta("blob", "nchar(200)"), + UtilsTools.ConstructTDengineMeta("jsontag", "json"), + }; + var expectResData = new List { "1637064040000", "true", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "XI", "XII", "{\"k1\": \"v1\"}" }; + String dropTb = "drop table if exists " + tableName; + String createTb = "create stable " + tableName + + " (ts timestamp" + + ",b bool" + + ",v1 tinyint" + + ",v2 smallint" + + ",v4 int" + + ",v8 bigint" + + ",f4 float" + + ",f8 double" + + ",u1 tinyint unsigned" + + ",u2 smallint unsigned" + + ",u4 int unsigned" + + ",u8 bigint unsigned" + + ",bin binary(200)" + + ",blob nchar(200)" + + ")" + + "tags" + + "(jsontag json);"; + String insertSql = "insert into " + tableName + "_t1 using " + tableName + + " tags('{\"k1\": \"v1\"}') " + + "values(1637064040000,true,1,2,3,4,5,6,7,8,9,10,'XI','XII')"; + String selectSql = "select * from " + tableName; + String dropSql = "drop table " + tableName; + + UtilsTools.ExecuteUpdate(conn, dropTb); + UtilsTools.ExecuteUpdate(conn, createTb); + UtilsTools.ExecuteUpdate(conn, insertSql); + _res = UtilsTools.ExecuteQuery(conn, selectSql); + + ResultSet actualResult = new ResultSet(_res); + List actualMeta = actualResult.GetResultMeta(); + for (int i = 0; i < actualMeta.Count; i++) + { + Assert.Equal(expectResMeta[i].name, actualMeta[i].name); + Assert.Equal(expectResMeta[i].type, actualMeta[i].type); + Assert.Equal(expectResMeta[i].size, actualMeta[i].size); + } + } + } +} diff --git a/src/connector/C#/src/test/FunctionTest/Utils.cs b/src/connector/C#/src/test/FunctionTest/Utils.cs new file mode 100644 index 0000000000000000000000000000000000000000..3b2dffcbc7fe5d4ea70b4b9666ceaed0603cb2e5 --- /dev/null +++ b/src/connector/C#/src/test/FunctionTest/Utils.cs @@ -0,0 +1,388 @@ +using System; +using TDengineDriver; +using System.Runtime.InteropServices; +using System.Text; +using System.Collections.Generic; +namespace Test.UtilsTools +{ + public class UtilsTools + { + + static string ip = "127.0.0.1"; + static string user = "root"; + static string password = "taosdata"; + static string db = ""; + static short port = 0; + public static IntPtr TDConnection() + { + TDengine.Options((int)TDengineInitOption.TDDB_OPTION_CONFIGDIR, GetConfigPath()); + TDengine.Options((int)TDengineInitOption.TDDB_OPTION_SHELL_ACTIVITY_TIMER, "60"); + TDengine.Init(); + IntPtr conn = TDengine.Connect(ip, user, password, db, port); + // UtilsTools.ExecuteUpdate(conn, "drop database if exists csharp"); + UtilsTools.ExecuteUpdate(conn, "create database if not exists csharp keep 3650"); + UtilsTools.ExecuteUpdate(conn, "use csharp"); + return conn; + } + public static string GetConfigPath() + { + string configDir = "" ; + if(OperatingSystem.IsOSPlatform("Windows")) + { + configDir = "C:/TDengine/cfg"; + } + else if(OperatingSystem.IsOSPlatform("Linux")) + { + configDir = "/etc/taos"; + } + else if(OperatingSystem.IsOSPlatform("macOS")) + { + configDir = "/etc/taos"; + } + return configDir; + } + + public static IntPtr ExecuteQuery(IntPtr conn, String sql) + { + IntPtr res = TDengine.Query(conn, sql); + if (!IsValidResult(res)) + { + Console.Write(sql.ToString() + " failure, "); + ExitProgram(); + } + else + { + Console.WriteLine(sql.ToString() + " success"); + } + return res; + } + + public static IntPtr ExecuteErrorQuery(IntPtr conn, String sql) + { + IntPtr res = TDengine.Query(conn, sql); + if (!IsValidResult(res)) + { + Console.Write(sql.ToString() + " failure, "); + ExitProgram(); + } + else + { + Console.WriteLine(sql.ToString() + " success"); + + } + return res; + } + + public static void ExecuteUpdate(IntPtr conn, String sql) + { + IntPtr res = TDengine.Query(conn, sql); + if (!IsValidResult(res)) + { + Console.Write(sql.ToString() + " failure, "); + ExitProgram(); + } + else + { + Console.WriteLine(sql.ToString() + " success"); + + } + TDengine.FreeResult(res); + } + + public static void DisplayRes(IntPtr res) + { + if (!IsValidResult(res)) + { + ExitProgram(); + } + + List metas = GetResField(res); + int fieldCount = metas.Count; + + IntPtr rowdata; + // StringBuilder builder = new StringBuilder(); + List datas = QueryRes(res, metas); + Console.Write(" DisplayRes ---"); + for (int i = 0; i < metas.Count; i++) + { + for (int j = 0; j < datas.Count; j++) + { + Console.Write(" {0} ---", datas[i * j + i]); + } + Console.WriteLine(""); + } + + // if (TDengine.ErrorNo(res) != 0) + // { + // Console.Write("Query is not complete, Error {0:G}", TDengine.ErrorNo(res), TDengine.Error(res)); + // } + // TDengine.FreeResult(res); Console.WriteLine(""); + } + + public static List> GetResultSet(IntPtr res) + { + List> result = new List>(); + List colName = new List(); + List dataRaw = new List(); + if (!IsValidResult(res)) + { + ExitProgram(); + } + + List metas = GetResField(res); + result.Add(colName); + + dataRaw = QueryRes(res, metas); + result.Add(dataRaw); + + if (TDengine.ErrorNo(res) != 0) + { + Console.Write("Query is not complete, Error {0:G}", TDengine.ErrorNo(res), TDengine.Error(res)); + } + return result; + } + + public static bool IsValidResult(IntPtr res) + { + if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0)) + { + if (res != IntPtr.Zero) + { + Console.Write("reason: " + TDengine.Error(res)); + return false; + } + Console.WriteLine(""); + return false; + } + return true; + } + public static void CloseConnection(IntPtr conn) + { + ExecuteUpdate(conn, "drop database if exists csharp"); + if (conn != IntPtr.Zero) + { + if (TDengine.Close(conn) == 0) + { + Console.WriteLine("close connection sucess"); + } + else + { + Console.WriteLine("close Connection failed"); + } + } + } + public static List GetResField(IntPtr res) + { + List metas = TDengine.FetchFields(res); + return metas; + } + public static void AssertEqual(string expectVal, string actualVal) + { + if (expectVal == actualVal) + { + Console.WriteLine("{0}=={1} pass", expectVal, actualVal); + } + else + { + Console.WriteLine("{0}=={1} failed", expectVal, actualVal); + ExitProgram(); + } + } + public static void ExitProgram() + { + TDengine.Cleanup(); + System.Environment.Exit(0); + } + public static List GetResData(IntPtr res) + { + List colName = new List(); + List dataRaw = new List(); + if (!IsValidResult(res)) + { + ExitProgram(); + } + List metas = GetResField(res); + dataRaw = QueryRes(res, metas); + return dataRaw; + } + + public static TDengineMeta ConstructTDengineMeta(string name, string type) + { + + TDengineMeta _meta = new TDengineMeta(); + _meta.name = name; + char[] separators = new char[] { '(', ')' }; + string[] subs = type.Split(separators, StringSplitOptions.RemoveEmptyEntries); + + switch (subs[0].ToUpper()) + { + case "BOOL": + _meta.type = 1; + _meta.size = 1; + break; + case "TINYINT": + _meta.type = 2; + _meta.size = 1; + break; + case "SMALLINT": + _meta.type = 3; + _meta.size = 2; + break; + case "INT": + _meta.type = 4; + _meta.size = 4; + break; + case "BIGINT": + _meta.type = 5; + _meta.size = 8; + break; + case "TINYINT UNSIGNED": + _meta.type = 11; + _meta.size = 1; + break; + case "SMALLINT UNSIGNED": + _meta.type = 12; + _meta.size = 2; + break; + case "INT UNSIGNED": + _meta.type = 13; + _meta.size = 4; + break; + case "BIGINT UNSIGNED": + _meta.type = 14; + _meta.size = 8; + break; + case "FLOAT": + _meta.type = 6; + _meta.size = 4; + break; + case "DOUBLE": + _meta.type = 7; + _meta.size = 8; + break; + case "BINARY": + _meta.type = 8; + _meta.size = short.Parse(subs[1]); + break; + case "TIMESTAMP": + _meta.type = 9; + _meta.size = 8; + break; + case "NCHAR": + _meta.type = 10; + _meta.size = short.Parse(subs[1]); + break; + case "JSON": + _meta.type = 15; + _meta.size = 4096; + break; + default: + _meta.type = byte.MaxValue; + _meta.size = 0; + break; + } + return _meta; + } + + private static List QueryRes(IntPtr res, List metas) + { + IntPtr rowdata; + long queryRows = 0; + List dataRaw = new List(); + int fieldCount = metas.Count; + while ((rowdata = TDengine.FetchRows(res)) != IntPtr.Zero) + { + queryRows++; + IntPtr colLengthPtr = TDengine.FetchLengths(res); + int[] colLengthArr = new int[fieldCount]; + Marshal.Copy(colLengthPtr, colLengthArr, 0, fieldCount); + + for (int fields = 0; fields < fieldCount; ++fields) + { + TDengineMeta meta = metas[fields]; + int offset = IntPtr.Size * fields; + IntPtr data = Marshal.ReadIntPtr(rowdata, offset); + + if (data == IntPtr.Zero) + { + dataRaw.Add("NULL"); + continue; + } + + switch ((TDengineDataType)meta.type) + { + case TDengineDataType.TSDB_DATA_TYPE_BOOL: + bool v1 = Marshal.ReadByte(data) == 0 ? false : true; + dataRaw.Add(v1.ToString()); + break; + case TDengineDataType.TSDB_DATA_TYPE_TINYINT: + sbyte v2 = (sbyte)Marshal.ReadByte(data); + dataRaw.Add(v2.ToString()); + break; + case TDengineDataType.TSDB_DATA_TYPE_SMALLINT: + short v3 = Marshal.ReadInt16(data); + dataRaw.Add(v3.ToString()); + break; + case TDengineDataType.TSDB_DATA_TYPE_INT: + int v4 = Marshal.ReadInt32(data); + dataRaw.Add(v4.ToString()); + break; + case TDengineDataType.TSDB_DATA_TYPE_BIGINT: + long v5 = Marshal.ReadInt64(data); + dataRaw.Add(v5.ToString()); + break; + case TDengineDataType.TSDB_DATA_TYPE_FLOAT: + float v6 = (float)Marshal.PtrToStructure(data, typeof(float)); + dataRaw.Add(v6.ToString()); + break; + case TDengineDataType.TSDB_DATA_TYPE_DOUBLE: + double v7 = (double)Marshal.PtrToStructure(data, typeof(double)); + dataRaw.Add(v7.ToString()); + break; + case TDengineDataType.TSDB_DATA_TYPE_BINARY: + string v8 = Marshal.PtrToStringAnsi(data, colLengthArr[fields]); + dataRaw.Add(v8); + break; + case TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP: + long v9 = Marshal.ReadInt64(data); + dataRaw.Add(v9.ToString()); + break; + case TDengineDataType.TSDB_DATA_TYPE_NCHAR: + string v10 = Marshal.PtrToStringAnsi(data, colLengthArr[fields]); + dataRaw.Add(v10); + break; + case TDengineDataType.TSDB_DATA_TYPE_UTINYINT: + byte v12 = Marshal.ReadByte(data); + dataRaw.Add(v12.ToString()); + break; + case TDengineDataType.TSDB_DATA_TYPE_USMALLINT: + ushort v13 = (ushort)Marshal.ReadInt16(data); + dataRaw.Add(v13.ToString()); + break; + case TDengineDataType.TSDB_DATA_TYPE_UINT: + uint v14 = (uint)Marshal.ReadInt32(data); + dataRaw.Add(v14.ToString()); + break; + case TDengineDataType.TSDB_DATA_TYPE_UBIGINT: + ulong v15 = (ulong)Marshal.ReadInt64(data); + dataRaw.Add(v15.ToString()); + break; + default: + dataRaw.Add("unknown value"); + break; + } + } + + } + if (TDengine.ErrorNo(res) != 0) + { + Console.Write("Query is not complete, Error {0:G}", TDengine.ErrorNo(res), TDengine.Error(res)); + } + TDengine.FreeResult(res); + Console.WriteLine(""); + return dataRaw; + } + + } +} + diff --git a/src/connector/C#/src/test/XUnitTest/TestTDengineMeta.cs b/src/connector/C#/src/test/XUnitTest/TestTDengineMeta.cs index fcf86c994e9097168786c1803901866918806098..2154af78db00241e5388bbb02dc7f4f2dfed7f71 100644 --- a/src/connector/C#/src/test/XUnitTest/TestTDengineMeta.cs +++ b/src/connector/C#/src/test/XUnitTest/TestTDengineMeta.cs @@ -6,6 +6,11 @@ namespace TDengineDriver.Test { public class TestTDengineMeta { + /// xiaolei + /// TestTDengineMeta.TestTypeNameBool + /// Unit test for oject TDengineDriver.TDengineMeta's bool meta info + /// TestTDengineMeta.cs + /// pass or failed [Fact] public void TestTypeNameBool() { @@ -17,7 +22,11 @@ namespace TDengineDriver.Test Assert.Equal(metaTypeName, typeName); } - + /// xiaolei + /// TestTDengineMeta.TestTypeNameTINYINT + /// Unit test for oject TDengineDriver.TDengineMeta's TinnyInt's meta info + /// TestTDengineMeta.cs + /// pass or failed [Fact] public void TestTypeNameTINYINT() { @@ -29,6 +38,11 @@ namespace TDengineDriver.Test Assert.Equal(metaTypeName, typeName); } + /// xiaolei + /// TestTDengineMeta.TestTypeNameSMALLINT + /// Unit test for oject TDengineDriver.TDengineMeta's SMALLINT's meta info + /// TestTDengineMeta.cs + /// pass or failed [Fact] public void TestTypeNameSMALLINT() { @@ -40,6 +54,11 @@ namespace TDengineDriver.Test Assert.Equal(metaTypeName, typeName); } + /// xiaolei + /// TestTDengineMeta.TestTypeNameINT + /// Unit test for oject TDengineDriver.TDengineMeta's INT's meta info + /// TestTDengineMeta.cs + /// pass or failed [Fact] public void TestTypeNameINT() { @@ -51,6 +70,11 @@ namespace TDengineDriver.Test Assert.Equal(metaTypeName, typeName); } + /// xiaolei + /// TestTDengineMeta.TestTypeNameBIGINT + /// Unit test for oject TDengineDriver.TDengineMeta's BIGINT's meta info + /// TestTDengineMeta.cs + /// pass or failed [Fact] public void TestTypeNameBIGINT() { @@ -62,6 +86,11 @@ namespace TDengineDriver.Test Assert.Equal(metaTypeName, typeName); } + /// xiaolei + /// TestTDengineMeta.TestTypeNameUTINYINT + /// Unit test for oject TDengineDriver.TDengineMeta's TINYINT UNSIGNED's meta info + /// TestTDengineMeta.cs + /// pass or failed [Fact] public void TestTypeNameUTINYINT() { @@ -73,6 +102,11 @@ namespace TDengineDriver.Test Assert.Equal(metaTypeName, typeName); } + /// xiaolei + /// TestTDengineMeta.TestTypeNameUSMALLINT + /// Unit test for oject TDengineDriver.TDengineMeta's SMALLINT UNSIGNED's meta info + /// TestTDengineMeta.cs + /// pass or failed [Fact] public void TestTypeNameUSMALLINT() { @@ -84,6 +118,11 @@ namespace TDengineDriver.Test Assert.Equal(metaTypeName, typeName); } + /// xiaolei + /// TestTDengineMeta.TestTypeNameUINT + /// Unit test for oject TDengineDriver.TDengineMeta's INT UNSIGNED's meta info + /// TestTDengineMeta.cs + /// pass or failed [Fact] public void TestTypeNameUINT() { @@ -95,6 +134,11 @@ namespace TDengineDriver.Test Assert.Equal(metaTypeName, typeName); } + /// xiaolei + /// TestTDengineMeta.TestTypeNameUBIGINT + /// Unit test for oject TDengineDriver.TDengineMeta's BIGINT UNSIGNED's meta info + /// TestTDengineMeta.cs + /// pass or failed [Fact] public void TestTypeNameUBIGINT() { @@ -106,7 +150,11 @@ namespace TDengineDriver.Test Assert.Equal(metaTypeName, typeName); } - + /// xiaolei + /// TestTDengineMeta.TestTypeNameFLOAT + /// Unit test for oject TDengineDriver.TDengineMeta's FLOAT's meta info + /// TestTDengineMeta.cs + /// pass or failed [Fact] public void TestTypeNameFLOAT() { @@ -118,6 +166,11 @@ namespace TDengineDriver.Test Assert.Equal(metaTypeName, typeName); } + /// xiaolei + /// TestTDengineMeta.TestTypeNameDOUBLE + /// Unit test for oject TDengineDriver.TDengineMeta's DOUBLE's meta info + /// TestTDengineMeta.cs + /// pass or failed [Fact] public void TestTypeNameDOUBLE() { @@ -129,10 +182,15 @@ namespace TDengineDriver.Test Assert.Equal(metaTypeName, typeName); } + /// xiaolei + /// TestTDengineMeta.TestTypeNameSTRING + /// Unit test for oject TDengineDriver.TDengineMeta's BINARY's meta info + /// TestTDengineMeta.cs + /// pass or failed [Fact] public void TestTypeNameSTRING() { - string typeName = "STRING"; + string typeName = "BINARY"; TDengineDriver.TDengineMeta meta = new TDengineDriver.TDengineMeta(); meta.type = 8; string metaTypeName = meta.TypeName(); @@ -140,6 +198,11 @@ namespace TDengineDriver.Test Assert.Equal(metaTypeName, typeName); } + /// xiaolei + /// TestTDengineMeta.TestTypeNameTIMESTAMP + /// Unit test for oject TDengineDriver.TDengineMeta's TIMESTAMP's meta info + /// TestTDengineMeta.cs + /// pass or failed [Fact] public void TestTypeNameTIMESTAMP() { @@ -151,6 +214,11 @@ namespace TDengineDriver.Test Assert.Equal(metaTypeName, typeName); } + /// xiaolei + /// TestTDengineMeta.TestTypeNameNCHAR + /// Unit test for oject TDengineDriver.TDengineMeta's NCHAR's meta info + /// TestTDengineMeta.cs + /// pass or failed [Fact] public void TestTypeNameNCHAR() { @@ -162,6 +230,11 @@ namespace TDengineDriver.Test Assert.Equal(metaTypeName, typeName); } + /// xiaolei + /// TestTDengineMeta.TestTypeNameUndefined + /// Unit test for oject TDengineDriver.TDengineMeta's undefine's meta info + /// TestTDengineMeta.cs + /// pass or failed [Fact] public void TestTypeNameUndefined() { diff --git a/src/connector/C#/src/test/XUnitTest/TestTaosBind.cs b/src/connector/C#/src/test/XUnitTest/TestTaosBind.cs index 1929d70a580744e6dcb57ee79699f18e295c3393..9198f633b35ed6dffa99081b95a0c9be67e7369d 100644 --- a/src/connector/C#/src/test/XUnitTest/TestTaosBind.cs +++ b/src/connector/C#/src/test/XUnitTest/TestTaosBind.cs @@ -7,6 +7,11 @@ namespace TDengineDriver.Test { public class TestTaosBind { + /// xiaolei + /// TestTaosBind.TestBindBoolTrue + /// Unit test for binding boolean true value using TAOS_BIND struct through stmt + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindBoolTrue() { @@ -18,7 +23,7 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindBool(true); int BindLengPtr = Marshal.ReadInt32(bind.length); bool bindBuffer = Convert.ToBoolean(Marshal.ReadByte(bind.buffer)); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -30,6 +35,11 @@ namespace TDengineDriver.Test } + /// xiaolei + /// TestTaosBind.TestBindBoolFalse + /// Unit test for binding boolean false value using TAOS_BIND struct through stmt + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindBoolFalse() { @@ -41,7 +51,7 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindBool(false); int BindLengPtr = Marshal.ReadInt32(bind.length); bool bindBuffer = Convert.ToBoolean(Marshal.ReadByte(bind.buffer)); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -53,10 +63,14 @@ namespace TDengineDriver.Test } + /// xiaolei + /// TestTaosBind.TestBindTinyIntZero + /// Unit test for binding tinny int zero value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindTinyIntZero() { - int bufferType = 2; sbyte buffer = 0; int bufferLength = sizeof(sbyte); @@ -65,7 +79,7 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindTinyInt(0); int BindLengPtr = Marshal.ReadInt32(bind.length); sbyte bindBuffer = Convert.ToSByte(Marshal.ReadByte(bind.buffer)); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -75,11 +89,14 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.buffer); Marshal.FreeHGlobal(bind.length); } - + /// xiaolei + /// TestTaosBind.TestBindTinyIntPositive + /// Unit test for binding tinny int positive value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindTinyIntPositive() { - int bufferType = 2; sbyte buffer = sbyte.MaxValue; int bufferLength = sizeof(sbyte); @@ -88,7 +105,7 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindTinyInt(sbyte.MaxValue); int BindLengPtr = Marshal.ReadInt32(bind.length); sbyte bindBuffer = Convert.ToSByte(Marshal.ReadByte(bind.buffer)); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -99,10 +116,14 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindTinyIntNegative + /// Unit test for binding tinny int negative value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindTinyIntNegative() { - int bufferType = 2; short buffer = sbyte.MinValue; int bufferLength = sizeof(sbyte); @@ -111,7 +132,7 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindTinyInt(sbyte.MinValue); int BindLengPtr = Marshal.ReadInt32(bind.length); short bindBuffer = Marshal.ReadInt16(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -122,10 +143,14 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindSmallIntNegative + /// Unit test for binding small int negative value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindSmallIntNegative() { - int bufferType = 3; short buffer = short.MinValue; int bufferLength = sizeof(short); @@ -134,7 +159,7 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindSmallInt(short.MinValue); int BindLengPtr = Marshal.ReadInt32(bind.length); short bindBuffer = Marshal.ReadInt16(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -145,10 +170,14 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindSmallIntZero + /// Unit test for binding small int zero value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindSmallIntZero() { - int bufferType = 3; short buffer = 0; int bufferLength = sizeof(short); @@ -157,7 +186,7 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindSmallInt(0); int BindLengPtr = Marshal.ReadInt32(bind.length); short bindBuffer = Marshal.ReadInt16(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -168,10 +197,14 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindSmallIntPositive + /// Unit test for binding small int positive value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindSmallIntPositive() { - int bufferType = 3; short buffer = short.MaxValue; int bufferLength = sizeof(short); @@ -180,7 +213,7 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindSmallInt(short.MaxValue); int BindLengPtr = Marshal.ReadInt32(bind.length); short bindBuffer = Marshal.ReadInt16(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -191,10 +224,14 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindIntNegative + /// Unit test for binding small int positive value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindIntNegative() { - int bufferType = 4; int buffer = int.MinValue; int bufferLength = sizeof(int); @@ -203,7 +240,7 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindInt(int.MinValue); int BindLengPtr = Marshal.ReadInt32(bind.length); int bindBuffer = Marshal.ReadInt32(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -214,10 +251,14 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindIntZero + /// Unit test for binding int zero value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindIntZero() { - int bufferType = 4; int buffer = 0; int bufferLength = sizeof(int); @@ -226,7 +267,7 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindInt(0); int BindLengPtr = Marshal.ReadInt32(bind.length); int bindBuffer = Marshal.ReadInt32(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -237,10 +278,14 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindIntPositive + /// Unit test for binding int positive value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindIntPositive() { - int bufferType = 4; int buffer = int.MaxValue; int bufferLength = sizeof(int); @@ -249,7 +294,7 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindInt(int.MaxValue); int BindLengPtr = Marshal.ReadInt32(bind.length); int bindBuffer = Marshal.ReadInt32(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -260,10 +305,14 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindBigIntNegative + /// Unit test for binding int negative value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindBigIntNegative() { - int bufferType = 5; long buffer = long.MinValue; int bufferLength = sizeof(long); @@ -272,7 +321,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindBigInt(long.MinValue); int BindLengPtr = Marshal.ReadInt32(bind.length); long bindBuffer = Marshal.ReadInt64(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -282,10 +330,15 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.buffer); Marshal.FreeHGlobal(bind.length); } + + /// xiaolei + /// TestTaosBind.TestBindBigIntZero + /// Unit test for binding big int zero value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindBigIntZero() { - int bufferType = 5; long buffer = 0; int bufferLength = sizeof(long); @@ -294,7 +347,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindBigInt(0); int BindLengPtr = Marshal.ReadInt32(bind.length); long bindBuffer = Marshal.ReadInt64(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -305,10 +357,14 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindBigIntPositive + /// Unit test for binding big int positive value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindBigIntPositive() { - int bufferType = 5; long buffer = long.MaxValue; int bufferLength = sizeof(long); @@ -317,7 +373,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindBigInt(long.MaxValue); int BindLengPtr = Marshal.ReadInt32(bind.length); long bindBuffer = Marshal.ReadInt64(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -328,11 +383,14 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindBigIntPositive + /// Unit test for binding big int positive value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindUTinyZero() { - - int bufferType = 11; byte buffer = 0; int bufferLength = sizeof(sbyte); @@ -341,7 +399,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindUTinyInt(0); int BindLengPtr = Marshal.ReadInt32(bind.length); byte bindBuffer = Marshal.ReadByte(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -352,11 +409,14 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindUTinyPositive + /// Unit test for binding unsigned tinny int positive value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindUTinyPositive() { - - int bufferType = 11; byte buffer = byte.MaxValue; int bufferLength = sizeof(sbyte); @@ -365,7 +425,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindUTinyInt(byte.MaxValue); int BindLengPtr = Marshal.ReadInt32(bind.length); byte bindBuffer = Marshal.ReadByte(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -376,10 +435,14 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindUSmallIntZero + /// Unit test for binding unsigned small int zero value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindUSmallIntZero() { - int bufferType = 12; ushort buffer = ushort.MinValue; int bufferLength = sizeof(ushort); @@ -388,7 +451,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindUSmallInt(ushort.MinValue); int BindLengPtr = Marshal.ReadInt32(bind.length); ushort bindBuffer = (ushort)Marshal.ReadInt16(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -398,10 +460,15 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.buffer); Marshal.FreeHGlobal(bind.length); } + + /// xiaolei + /// TestTaosBind.TestBindUSmallIntPositive + /// Unit test for binding unsigned small int positive value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindUSmallIntPositive() { - int bufferType = 12; ushort buffer = ushort.MaxValue; int bufferLength = sizeof(ushort); @@ -410,7 +477,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindUSmallInt(ushort.MaxValue); int BindLengPtr = Marshal.ReadInt32(bind.length); ushort bindBuffer = (ushort)Marshal.ReadInt16(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -421,6 +487,11 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindUIntZero + /// Unit test for binding unsigned int zero value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindUIntZero() { @@ -432,7 +503,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindUInt(uint.MinValue); int BindLengPtr = Marshal.ReadInt32(bind.length); uint bindBuffer = (uint)Marshal.ReadInt32(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -443,6 +513,11 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindUIntPositive + /// Unit test for binding unsigned int positive value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindUIntPositive() { @@ -454,7 +529,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindUInt(uint.MaxValue); int BindLengPtr = Marshal.ReadInt32(bind.length); uint bindBuffer = (uint)Marshal.ReadInt32(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -465,6 +539,11 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindUBigIntZero + /// Unit test for binding unsigned big int zero value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindUBigIntZero() { @@ -476,7 +555,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindUBigInt(ulong.MinValue); int BindLengPtr = Marshal.ReadInt32(bind.length); ulong bindBuffer = (ulong)Marshal.ReadInt64(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -487,6 +565,11 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindUBigIntPositive + /// Unit test for binding unsigned big int positive value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindUBigIntPositive() { @@ -498,7 +581,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindUBigInt(ulong.MaxValue); int BindLengPtr = Marshal.ReadInt32(bind.length); ulong bindBuffer = (ulong)Marshal.ReadInt64(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -509,6 +591,11 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindFloatNegative + /// Unit test for binding float negative value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindFloatNegative() { @@ -521,7 +608,6 @@ namespace TDengineDriver.Test int BindLengPtr = Marshal.ReadInt32(bind.length); float[] bindBufferArr = new float[1]; Marshal.Copy(bind.buffer, bindBufferArr, 0, bindBufferArr.Length); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBufferArr[0], buffer); @@ -532,6 +618,11 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindFloatNegative + /// Unit test for binding float zero value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindFloatZero() { @@ -544,7 +635,6 @@ namespace TDengineDriver.Test int BindLengPtr = Marshal.ReadInt32(bind.length); float[] bindBufferArr = new float[1]; Marshal.Copy(bind.buffer, bindBufferArr, 0, bindBufferArr.Length); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBufferArr[0], buffer); @@ -555,6 +645,11 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindFloatPositive + /// Unit test for binding float positive value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindFloatPositive() { @@ -567,7 +662,6 @@ namespace TDengineDriver.Test int BindLengPtr = Marshal.ReadInt32(bind.length); float[] bindBufferArr = new float[1]; Marshal.Copy(bind.buffer, bindBufferArr, 0, bindBufferArr.Length); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBufferArr[0], buffer); @@ -578,6 +672,11 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindDoubleZero + /// Unit test for binding double zero value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindDoubleZero() { @@ -590,7 +689,6 @@ namespace TDengineDriver.Test int BindLengPtr = Marshal.ReadInt32(bind.length); double[] bindBufferArr = new double[1]; Marshal.Copy(bind.buffer, bindBufferArr, 0, bindBufferArr.Length); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBufferArr[0], buffer); @@ -601,6 +699,11 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindDoublePositive + /// Unit test for binding double positive value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindDoublePositive() { @@ -613,7 +716,6 @@ namespace TDengineDriver.Test int BindLengPtr = Marshal.ReadInt32(bind.length); double[] bindBufferArr = new double[1]; Marshal.Copy(bind.buffer, bindBufferArr, 0, bindBufferArr.Length); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBufferArr[0], buffer); @@ -624,6 +726,11 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindDoubleNegative + /// Unit test for binding double negative value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindDoubleNegative() { @@ -636,7 +743,6 @@ namespace TDengineDriver.Test int BindLengPtr = Marshal.ReadInt32(bind.length); double[] bindBufferArr = new double[1]; Marshal.Copy(bind.buffer, bindBufferArr, 0, bindBufferArr.Length); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBufferArr[0], buffer); @@ -647,6 +753,11 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindBinaryEn + /// Unit test for binding binary character without CN character using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindBinaryEn() { @@ -658,7 +769,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindBinary("qwertyuiopasdghjklzxcvbnm<>?:\"{}+_)(*&^%$#@!~QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./`1234567890-="); int BindLengPtr = Marshal.ReadInt32(bind.length); string bindBuffer = Marshal.PtrToStringAnsi(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -669,6 +779,11 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindBinaryCn + /// Unit test for binding binary character with CN character using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindBinaryCn() { @@ -680,7 +795,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindBinary("一二两三四五六七八九十廿毛另壹贰叁肆伍陆柒捌玖拾佰仟万亿元角分零整1234567890`~!@#$%^&*()_+[]{};':<>?,./"); int BindLengPtr = Marshal.ReadInt32(bind.length); string bindBuffer = Marshal.PtrToStringAnsi(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -691,6 +805,11 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindBinaryCnAndEn + /// Unit test for binding binary characters with CN and other characters using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindBinaryCnAndEn() { @@ -702,7 +821,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindBinary("一二两三四五六七八九十廿毛另壹贰叁肆伍陆柒捌玖拾佰仟万亿元角分零整1234567890`~!@#$%^&*()_+[]{};':<>?,./qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"); int BindLengPtr = Marshal.ReadInt32(bind.length); string bindBuffer = Marshal.PtrToStringAnsi(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -713,6 +831,11 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindNcharEn + /// Unit test for binding nchar characters without cn using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindNcharEn() { @@ -724,7 +847,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindNchar("qwertyuiopasdghjklzxcvbnm<>?:\"{}+_)(*&^%$#@!~QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./`1234567890-="); int BindLengPtr = Marshal.ReadInt32(bind.length); string bindBuffer = Marshal.PtrToStringAnsi(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -734,6 +856,12 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.buffer); Marshal.FreeHGlobal(bind.length); } + + /// xiaolei + /// TestTaosBind.TestBindNcharCn + /// Unit test for binding nchar characters with cn using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindNcharCn() { @@ -745,7 +873,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindNchar("一二两三四五六七八九十廿毛另壹贰叁肆伍陆柒捌玖拾佰仟万亿元角分零整1234567890`~!@#$%^&*()_+[]{};':<>?,./"); int BindLengPtr = Marshal.ReadInt32(bind.length); string bindBuffer = Marshal.PtrToStringAnsi(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -755,6 +882,12 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.buffer); Marshal.FreeHGlobal(bind.length); } + + /// xiaolei + /// TestTaosBind.TestBindNcharCnAndEn + /// Unit test for binding nchar with cn characters and other characters using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindNcharCnAndEn() { @@ -766,7 +899,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindNchar("一二两三四五六七八九十廿毛另壹贰叁肆伍陆柒捌玖拾佰仟万亿元角分零整1234567890`~!@#$%^&*()_+[]{};':<>?,./qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"); int BindLengPtr = Marshal.ReadInt32(bind.length); string bindBuffer = Marshal.PtrToStringAnsi(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -777,6 +909,11 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindNil + /// Unit test for binding null value using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindNil() { @@ -786,7 +923,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindNil(); int bindIsNull = Marshal.ReadInt32(bind.is_null); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindIsNull, isNull); @@ -795,6 +931,11 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.length); } + /// xiaolei + /// TestTaosBind.TestBindTimestampNegative + /// Unit test for binding negative timestamp using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindTimestampNegative() { @@ -806,7 +947,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindTimestamp(long.MinValue); int BindLengPtr = Marshal.ReadInt32(bind.length); long bindBuffer = Marshal.ReadInt64(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -816,6 +956,12 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.buffer); Marshal.FreeHGlobal(bind.length); } + + /// xiaolei + /// TestTaosBind.TestBindTimestampZero + /// Unit test for binding zero timestamp using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindTimestampZero() { @@ -827,7 +973,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindTimestamp(0); int BindLengPtr = Marshal.ReadInt32(bind.length); long bindBuffer = Marshal.ReadInt64(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); @@ -837,6 +982,13 @@ namespace TDengineDriver.Test Marshal.FreeHGlobal(bind.buffer); Marshal.FreeHGlobal(bind.length); } + + + /// xiaolei + /// TestTaosBind.TestBindTimestampPositive + /// Unit test for binding positive timestamp using TAOS_BIND struct through stmt. + /// TestTaosBind.cs + /// pass or failed [Fact] public void TestBindTimestampPositive() { @@ -848,7 +1000,6 @@ namespace TDengineDriver.Test TDengineDriver.TAOS_BIND bind = TaosBind.BindTimestamp(long.MaxValue); int BindLengPtr = Marshal.ReadInt32(bind.length); long bindBuffer = Marshal.ReadInt64(bind.buffer); - Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); Assert.Equal(bind.buffer_type, bufferType); Assert.Equal(bindBuffer, buffer); diff --git a/tests/develop-test/3-connectors/c#/test.sh b/tests/develop-test/3-connectors/c#/test.sh index 2d4f18b668263d40bb18ef46f34b7299b3f7cdd3..75a55fb41be3cd96c24bebfe93b209b13c3d3df8 100755 --- a/tests/develop-test/3-connectors/c#/test.sh +++ b/tests/develop-test/3-connectors/c#/test.sh @@ -19,12 +19,14 @@ cd ../../ WKC=`pwd` cd ${WKC}/src/connector/C# dotnet test -dotnet run --project src/test/Cases/Cases.csproj +#dotnet run --project src/test/Cases/Cases.csproj cd ${WKC}/tests/examples/C# dotnet run --project C#checker/C#checker.csproj dotnet run --project TDengineTest/TDengineTest.csproj dotnet run --project schemaless/schemaless.csproj +dotnet run --project jsonTag/jsonTag.csproj +dotnet run --project stmt/stmt.csproj cd ${WKC}/tests/examples/C#/taosdemo dotnet build -c Release diff --git a/tests/examples/C#/.gitignore b/tests/examples/C#/.gitignore index 59588c8c5a6f25cbef8ec070b706e783b5404807..901f898c481485fa2ca61b8be40deca01be2f098 100644 --- a/tests/examples/C#/.gitignore +++ b/tests/examples/C#/.gitignore @@ -11,3 +11,5 @@ stmt/bin/ stmt/obj/ taosdemo/bin/ taosdemo/obj/ +jsonTag/bin/ +jsonTag/obj/ diff --git a/src/connector/C#/src/test/Cases/JsonTag.cs b/tests/examples/C#/jsonTag/JsonTag.cs similarity index 97% rename from src/connector/C#/src/test/Cases/JsonTag.cs rename to tests/examples/C#/jsonTag/JsonTag.cs index a079919c13989cbaf0a3447bbf4f1626ca32d22f..453e54eabdc9a4ec61cdc2a061af69ed64753416 100644 --- a/src/connector/C#/src/test/Cases/JsonTag.cs +++ b/tests/examples/C#/jsonTag/JsonTag.cs @@ -1,9 +1,25 @@ using System; -using Test.UtilsTools; +using Utils; namespace Cases { - public class JsonTagTest + + class Program + { + static void Main(string[] args) + { + IntPtr conn = IntPtr.Zero; + Console.WriteLine("===================JsonTagTest===================="); + conn = conn = UtilsTools.TDConnection("127.0.0.1", "root", "taosdata", "", 0); + UtilsTools.ExecuteUpdate(conn, "create database if not exists csharp_sample keep 3650"); + UtilsTools.ExecuteUpdate(conn, "use csharp"); + JsonTagSample jsonTagSample = new JsonTagSample(); + jsonTagSample.Test(conn); + } + + } + + public class JsonTagSample { public void Test(IntPtr conn) { diff --git a/src/connector/C#/src/test/Cases/Utils.cs b/tests/examples/C#/jsonTag/Util.cs similarity index 62% rename from src/connector/C#/src/test/Cases/Utils.cs rename to tests/examples/C#/jsonTag/Util.cs index dd856db8eb2bfc4122ccdd80db2fe74e74af2760..5138938df60532616e75b45d8a95597c322dfd1a 100644 --- a/src/connector/C#/src/test/Cases/Utils.cs +++ b/tests/examples/C#/jsonTag/Util.cs @@ -3,9 +3,9 @@ using TDengineDriver; using System.Runtime.InteropServices; using System.Text; using System.Collections.Generic; -namespace Test.UtilsTools +namespace Utils { - public class UtilsTools + public class UtilsTools { static string configDir = "/etc/taos";//"C:/TDengine/cfg"; @@ -189,103 +189,6 @@ namespace Test.UtilsTools TDengine.FreeResult(res); Console.WriteLine(""); } - public static List> GetResultSet(IntPtr res) - { - List> result = new List>(); - List colName = new List(); - List dataRaw = new List(); - long queryRows = 0; - if (!IsValidResult(res)) - { - ExitProgram(); - } - - int fieldCount = TDengine.FieldCount(res); - List metas = TDengine.FetchFields(res); - - for (int j = 0; j < metas.Count; j++) - { - TDengineMeta meta = (TDengineMeta)metas[j]; - colName.Add(meta.name); - } - result.Add(colName); - - IntPtr rowdata; - while ((rowdata = TDengine.FetchRows(res)) != IntPtr.Zero) - { - queryRows++; - IntPtr colLengthPtr = TDengine.FetchLengths(res); - int[] colLengthArr = new int[fieldCount]; - Marshal.Copy(colLengthPtr, colLengthArr, 0, fieldCount); - - for (int fields = 0; fields < fieldCount; ++fields) - { - TDengineMeta meta = metas[fields]; - int offset = IntPtr.Size * fields; - IntPtr data = Marshal.ReadIntPtr(rowdata, offset); - - if (data == IntPtr.Zero) - { - dataRaw.Add("NULL"); - continue; - } - - switch ((TDengineDataType)meta.type) - { - case TDengineDataType.TSDB_DATA_TYPE_BOOL: - bool v1 = Marshal.ReadByte(data) == 0 ? false : true; - dataRaw.Add(v1.ToString()); - break; - case TDengineDataType.TSDB_DATA_TYPE_TINYINT: - byte v2 = Marshal.ReadByte(data); - dataRaw.Add(v2.ToString()); - break; - case TDengineDataType.TSDB_DATA_TYPE_SMALLINT: - short v3 = Marshal.ReadInt16(data); - dataRaw.Add(v3.ToString()); - break; - case TDengineDataType.TSDB_DATA_TYPE_INT: - int v4 = Marshal.ReadInt32(data); - dataRaw.Add(v4.ToString()); - break; - case TDengineDataType.TSDB_DATA_TYPE_BIGINT: - long v5 = Marshal.ReadInt64(data); - dataRaw.Add(v5.ToString()); - break; - case TDengineDataType.TSDB_DATA_TYPE_FLOAT: - float v6 = (float)Marshal.PtrToStructure(data, typeof(float)); - dataRaw.Add(v6.ToString()); - break; - case TDengineDataType.TSDB_DATA_TYPE_DOUBLE: - double v7 = (double)Marshal.PtrToStructure(data, typeof(double)); - dataRaw.Add(v7.ToString()); - break; - case TDengineDataType.TSDB_DATA_TYPE_BINARY: - string v8 = Marshal.PtrToStringAnsi(data, colLengthArr[fields]); - dataRaw.Add(v8); - break; - case TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP: - long v9 = Marshal.ReadInt64(data); - dataRaw.Add(v9.ToString()); - break; - case TDengineDataType.TSDB_DATA_TYPE_NCHAR: - string v10 = Marshal.PtrToStringAnsi(data, colLengthArr[fields]); - dataRaw.Add(v10); - break; - } - } - - } - result.Add(dataRaw); - - if (TDengine.ErrorNo(res) != 0) - { - Console.Write("Query is not complete, Error {0:G}", TDengine.ErrorNo(res), TDengine.Error(res)); - } - TDengine.FreeResult(res); Console.WriteLine(""); - return result; - } - public static bool IsValidResult(IntPtr res) { if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0)) @@ -314,27 +217,10 @@ namespace Test.UtilsTools } } } - public static List getField(IntPtr res) - { - List metas = TDengine.FetchFields(res); - return metas; - } - public static void AssertEqual(string expectVal, string actualVal) - { - if (expectVal == actualVal) - { - Console.WriteLine("{0}=={1} pass", expectVal, actualVal); - } - else - { - Console.WriteLine("{0}=={1} failed", expectVal, actualVal); - ExitProgram(); - } - } public static void ExitProgram() { TDengine.Cleanup(); System.Environment.Exit(0); } } -} +} \ No newline at end of file diff --git a/tests/examples/C#/jsonTag/jsonTag.csproj b/tests/examples/C#/jsonTag/jsonTag.csproj new file mode 100644 index 0000000000000000000000000000000000000000..ed3af6e806f0321828742597d226011bfb4d5185 --- /dev/null +++ b/tests/examples/C#/jsonTag/jsonTag.csproj @@ -0,0 +1,12 @@ + + + + Exe + net5.0 + + + + + + + diff --git a/tests/examples/JDBC/connectionPools/pom.xml b/tests/examples/JDBC/connectionPools/pom.xml index aad2923b823c1fcf2cb87eba4f18865fede063a1..d50c7a20709e0d0471261a64365873814242a619 100644 --- a/tests/examples/JDBC/connectionPools/pom.xml +++ b/tests/examples/JDBC/connectionPools/pom.xml @@ -53,7 +53,7 @@ org.apache.logging.log4j log4j-core - 2.17.0 + 2.17.1 diff --git a/tests/examples/JDBC/taosdemo/pom.xml b/tests/examples/JDBC/taosdemo/pom.xml index 23c74ef1b72e0f2fd8b2a647a798872062a9c216..cce3960d994ed3155bae41471af808c007168cf8 100644 --- a/tests/examples/JDBC/taosdemo/pom.xml +++ b/tests/examples/JDBC/taosdemo/pom.xml @@ -88,7 +88,7 @@ org.apache.logging.log4j log4j-core - 2.17.0 + 2.17.1 diff --git a/tests/perftest-scripts/HttpPerfCompare.py b/tests/perftest-scripts/HttpPerfCompare.py new file mode 100644 index 0000000000000000000000000000000000000000..6c9798d59641465657089e7ed24e1e86b33d48e1 --- /dev/null +++ b/tests/perftest-scripts/HttpPerfCompare.py @@ -0,0 +1,137 @@ +from loguru import logger +import time +import os +import json + +class HttpPerfCompard: + def __init__(self): + self.hostname = "vm85" + self.taosc_port = 6030 + self.http_port = 6041 + self.database = "test" + self.query_times = 1 + self.concurrent = 1 + self.column_count = 10 + self.tag_count = 10 + self.perfMonitorBin = '/home/ubuntu/perfMonitor' + self.taosBenchmarkBin = '/usr/local/bin/taosBenchmark' + self.sleep_time = 20 + + self.current_time = time.strftime("%Y-%m-%d-%H:%M:%S", time.localtime(time.time())) + self.current_dir = os.path.dirname(os.path.realpath(__file__)) + self.log_file = os.path.join(self.current_dir, f'./performance.log') + logger.add(self.log_file) + logger.info(f'init env success, log will be export to {self.log_file}') + self.sql_list = ['select last_row(*) from test.stb;', + 'select * from test.stb limit 100000;', + 'select count(*) from test.stb interval (1d);', + 'select avg(c3), max(c4), min(c5) from test.stb interval (1d);', + 'select count(*) from test.stb where t1 = "shanghai" interval (1h);', + 'select avg(c3), max(c4), min(c5) from test.stb where t1 = "shanghai" interval (1d);', + 'select avg(c3), max(c4), min(c5) from test.stb where ts > "2021-01-01 00:00:00" and ts < "2021-01-31 00:00:00" interval (1d);' + 'select last(*) from test.stb;' + ] +# self.sql_list = ['select * from test.stb limit 100000;'] + + def initLog(self): + self.exec_local_cmd(f'echo "" > {self.log_file}') + + def exec_local_cmd(self,shell_cmd): + result = os.popen(shell_cmd).read().strip() + return result + + def genQueryJsonFile(self, query_sql): + json_file = os.path.join(self.current_dir, f'./query.json') + jdict = { + "filetype": "query", + "cfgdir": "/etc/taos", + "host": self.hostname, + "port": self.taosc_port, + "user": "root", + "password": "taosdata", + "confirm_parameter_prompt": "no", + "databases": self.database, + "query_times": self.query_times, + "query_mode": "restful", + "specified_table_query": { + "concurrent": self.concurrent, + "sqls": [ + { + "sql": query_sql, + "result": "./query_res0.txt" + } + ] + } + } + with open(json_file, "w", encoding="utf-8") as f_w: + f_w.write(json.dumps(jdict)) + + def genInsertJsonFile(self, thread_count, table_count, row_count, batch_size): + json_file = os.path.join(self.current_dir, f'./insert.json') + jdict = { + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": self.hostname, + "rest_host": self.hostname, + "port": self.taosc_port, + "rest_port": self.http_port, + "user": "root", + "password": "taosdata", + "thread_count": thread_count, + "thread_count_create_tbl": 1, + "result_file": self.log_file, + "databases": [{ + "dbinfo": { + "name": self.database, + "drop": "yes" + }, + "super_tables": [{ + "name": "stb", + "childtable_count": table_count, + "childtable_prefix": "stb_", + "batch_create_tbl_num": 1, + "insert_mode": "rand", + "insert_iface": "rest", + "insert_rows": row_count, + "insert_interval": 0, + "batch_rows": batch_size, + "max_sql_len": 1048576, + "timestamp_step": 3000, + "start_timestamp": "2021-01-01 00:00:00.000", + "tags_file": "", + "partical_col_num": 0, + "columns": [{"type": "INT", "count": self.column_count}], + "tags": [{"type": "BINARY", "len": 16, "count": self.tag_count}] + }] + }] + } + with open(json_file, "w", encoding="utf-8") as f_w: + f_w.write(json.dumps(jdict)) + + def runTest(self): + self.initLog() + self.genInsertJsonFile(32, 100, 100000, 1) + logger.info('result of insert_perf with 32 threads and 1 batch_size:') + self.exec_local_cmd(f'{self.perfMonitorBin} -f insert.json') + time.sleep(self.sleep_time) + self.genInsertJsonFile(32, 500, 1000000, 1000) + logger.info('result of insert_perf with 32 threads and 1000 batch_size:') + self.exec_local_cmd(f'{self.perfMonitorBin} -f insert.json') + time.sleep(self.sleep_time) + + for query_sql in self.sql_list: + self.genQueryJsonFile(query_sql) + self.exec_local_cmd(f'{self.taosBenchmarkBin} -f query.json > tmp.log') + res = self.exec_local_cmd('grep -Eo \'\\' tmp.log |grep -v \'total queries\' |awk \'{sum+=$2}END{print "Average=",sum/NR,"s"}\'') + logger.info(query_sql) + logger.info(res) + time.sleep(self.sleep_time) + +if __name__ == '__main__': + runPerf = HttpPerfCompard() + runPerf.runTest() + + + + + diff --git a/tests/perftest-scripts/specifyColsComparison.py b/tests/perftest-scripts/specifyColsComparison.py new file mode 100644 index 0000000000000000000000000000000000000000..9158a607503582577a7600a9badc6885cf0be390 --- /dev/null +++ b/tests/perftest-scripts/specifyColsComparison.py @@ -0,0 +1,197 @@ +from loguru import logger +import time +import os +import json +import sys +from fabric import Connection + +# apt install -y sudo python3-pip +# pip3 install fabric loguru + +class specifyColsCompared: + def __init__(self): + # remote server + self.remote_hostname = "vm85" + self.remote_sshport = "22" + self.remote_username = "root" + self.remote_password = "tbase125!" + + # TDengine pkg path + self.autoDeploy = False + self.install_package = '/root/share/TDengine-server-2.4.0.0-Linux-amd64.tar.gz' + + # test element + self.update_list = [1, 2] + self.column_count_list = [100, 500, 2000] + + # perfMonitor config + self.thread_count = 10 + self.taosc_port = 6030 + self.http_port = 6041 + self.database = "test" + self.table_count = 10 + self.tag_count = 5 + self.col_count = 50000 + self.batch_size = 1 + self.sleep_time = 20 + + self.current_time = time.strftime("%Y-%m-%d-%H:%M:%S", time.localtime(time.time())) + self.current_dir = os.path.dirname(os.path.realpath(__file__)) + self.log_file = os.path.join(self.current_dir, f'./performance.log') + if self.remote_username == "root": + self.remote_dir = "/root" + else: + self.remote_dir = f'/home/{self.remote_username}' + self.conn = Connection(self.remote_hostname, user=self.remote_username, port=self.remote_sshport, connect_timeout=120, connect_kwargs={"password": self.remote_password}) + logger.add(self.log_file) + logger.info(f'init env success, log will be export to {self.log_file}') + + def initLog(self): + # init log + self.exec_local_cmd(f'echo "" > {self.log_file}') + + def exec_local_cmd(self,shell_cmd): + # exec local cmd + try: + result = os.popen(shell_cmd).read().strip() + return result + except Exception as e: + logger.error(f"exec cmd: {shell_cmd} failed----{e}") + + def checkStatus(self, process): + # check process status + try: + process_count = self.conn.run(f'ps -ef | grep -w {process} | grep -v grep | wc -l', pty=False, warn=True, hide=False).stdout + if int(process_count.strip()) > 0: + logger.info(f'check {self.remote_hostname} {process} existed') + return True + else: + logger.info(f'check {self.remote_hostname} {process} not exist') + return False + except Exception as e: + logger.error(f"check status failed----{e}, please check by manual") + + def deployPerfMonitor(self): + # deploy perfMonitor + logger.info('deploying perfMonitor') + if os.path.exists(f'{self.current_dir}/perfMonitor'): + os.remove(f'{self.current_dir}/perfMonitor') + self.exec_local_cmd(f'wget -P {self.current_dir} http://39.105.163.10:9000/perfMonitor && chmod +x {self.current_dir}/perfMonitor') + package_name = self.install_package.split('/')[-1] + package_dir = '-'.join(package_name.split("-", 3)[0:3]) + self.exec_local_cmd(f'tar -xvf {self.install_package} && cd {package_dir} && echo -e "\n" | ./install.sh') + + def dropAndCreateDb(self): + try: + self.conn.run(f'taos -s "drop database if exists {self.database}"') + self.conn.run(f'taos -s "create database if not exists {self.database}"') + except Exception as e: + logger.error(f"drop db failed----{e}, please check by manual") + + def uploadPkg(self): + # upload TDengine pkg + try: + logger.info(f'uploading {self.install_package} to {self.remote_hostname}:{self.remote_dir}') + self.conn.put(self.install_package, self.remote_dir) + except Exception as e: + logger.error(f"pkg send failed----{e}, please check by manual") + + def deployTDengine(self): + # deploy TDengine + try: + package_name = self.install_package.split('/')[-1] + package_dir = '-'.join(package_name.split("-", 3)[0:3]) + self.uploadPkg() + self.conn.run(f'sudo rmtaos', pty=False, warn=True, hide=False) + logger.info('installing TDengine') + logger.info(self.conn.run(f'cd {self.remote_dir} && tar -xvf {self.remote_dir}/{package_name} && cd {package_dir} && echo -e "\n"|./install.sh', pty=False, warn=True, hide=False)) + logger.info('start TDengine') + logger.info(self.conn.run('sudo systemctl start taosd', pty=False, warn=True, hide=False)) + for deploy_elm in ['taosd', 'taosadapter']: + if self.checkStatus(deploy_elm): + logger.success(f'{self.remote_hostname}: {deploy_elm} deploy success') + else: + logger.error(f'{self.remote_hostname}: {deploy_elm} deploy failed, please check by manual') + sys.exit(1) + except Exception as e: + logger.error(f"deploy TDengine failed----{e}, please check by manual") + + def genInsertJsonFile(self, thread_count, table_count, row_count, batch_size, column_count, partical_col_num, update, drop="yes", result_file=None): + # gen json file + json_file = os.path.join(self.current_dir, f'./insert.json') + if result_file == None: + result_file = self.log_file + else: + result_file = self.log_file.replace('performance.log', 'unused_performance.log') + + jdict = { + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": self.remote_hostname, + "rest_host": self.remote_hostname, + "port": self.taosc_port, + "rest_port": self.http_port, + "user": "root", + "password": "taosdata", + "thread_count": thread_count, + "thread_count_create_tbl": 1, + "result_file": result_file, + "databases": [{ + "dbinfo": { + "name": self.database, + "drop": drop, + "update": update + }, + "super_tables": [{ + "name": "stb", + "childtable_count": table_count, + "childtable_prefix": "stb_", + "batch_create_tbl_num": 1, + "insert_mode": "rand", + "insert_iface": "rest", + "insert_rows": row_count, + "insert_interval": 0, + "batch_rows": batch_size, + "max_sql_len": 1048576, + "timestamp_step": 1000, + "start_timestamp": "2021-01-01 00:00:00.000", + "tags_file": "", + "partical_col_num": partical_col_num, + "columns": [{"type": "INT", "count": column_count}], + "tags": [{"type": "BINARY", "len": 16, "count": self.tag_count}] + }] + }] + } + with open(json_file, "w", encoding="utf-8") as f_w: + f_w.write(json.dumps(jdict)) + + def runTest(self): + self.initLog() + if self.autoDeploy: + self.deployTDengine() + self.deployPerfMonitor() + + # blank insert + update = 0 + for col_count in self.column_count_list: + for partical_col_num in [int(col_count * 0), int(col_count * 0.1), int(col_count * 0.3)]: + logger.info(f'update: {update} || col_count: {col_count} || partical_col_num: {partical_col_num} test') + self.genInsertJsonFile(self.thread_count, self.table_count, self.col_count, self.batch_size, col_count, partical_col_num, update) + self.exec_local_cmd(f'{self.current_dir}/perfMonitor -f insert.json') + time.sleep(self.sleep_time) + + # update = 1/2 + for update in self.update_list: + for col_count in self.column_count_list: + for partical_col_num in [int(col_count * 0.1), int(col_count * 0.3)]: + logger.info(f'update: {update} || col_count: {col_count} || partical_col_num: {partical_col_num} test') + self.genInsertJsonFile(self.thread_count, self.table_count, self.col_count, 100, col_count, int(col_count * 0), update, drop="yes", result_file="unused") + self.exec_local_cmd(f'{self.current_dir}/perfMonitor -f insert.json') + time.sleep(self.sleep_time) + self.genInsertJsonFile(self.thread_count, self.table_count, self.col_count, self.batch_size, col_count, partical_col_num, update, drop="no") + self.exec_local_cmd(f'{self.current_dir}/perfMonitor -f insert.json') + time.sleep(self.sleep_time) + +if __name__ == '__main__': + runPerf = specifyColsCompared() + runPerf.runTest() diff --git a/tests/pytest/fulltest-query.sh b/tests/pytest/fulltest-query.sh index f19e11024b1447d5546b3a14a487d98b0edb1deb..5ad0f850b355bba1ab01843d7012b0ad487f761b 100755 --- a/tests/pytest/fulltest-query.sh +++ b/tests/pytest/fulltest-query.sh @@ -143,7 +143,7 @@ python3 ./test.py -f stream/stream1.py python3 ./test.py -f stream/stream2.py #python3 ./test.py -f stream/parser.py python3 ./test.py -f stream/history.py -python3 ./test.py -f stream/sys.py +#python3 ./test.py -f stream/sys.py python3 ./test.py -f stream/table_1.py python3 ./test.py -f stream/table_n.py python3 ./test.py -f stream/showStreamExecTimeisNull.py diff --git a/tests/pytest/functions/function_derivative.py b/tests/pytest/functions/function_derivative.py index a2a458ea290b13ed462d8dcd47a8af16e3af0f82..3696dc24010cdbff6d4e139a4224a23469403041 100644 --- a/tests/pytest/functions/function_derivative.py +++ b/tests/pytest/functions/function_derivative.py @@ -140,6 +140,9 @@ class TDTestCase: tdSql.error("select derivative(col, 1s, 1) from tb2") tdSql.error("select derivative(col, 10s, 0) from tb2") tdSql.error("select derivative(col, 999ms, 0) from tb2") + tdSql.error("select derivative(col, now, 0) from tb2") #TD-11983 now not allowed in second param + tdSql.error("select derivative(col, now+3d-8h+6m, 0) from tb2") #TD-11983 now not allowed in second param + tdSql.error("select derivative(col, 3d-8h+now+6m, 0) from tb2") #TD-11983 now not allowed in second param tdSql.error("select derivative(col, 10s, 1) from stb") tdSql.error("select derivative(col, 10s, 1) from stb group by col") @@ -150,6 +153,9 @@ class TDTestCase: tdSql.error("select derivative(col, 10y, 0) from stb group by tbname") #TD-10399, DB error: syntax error near '10y, 0) from stb group by tbname;' tdSql.error("select derivative(col, -106752d, 0) from stb group by tbname") #TD-10398 overflow tips tdSql.error("select derivative(col, 106751991168d, 0) from stb group by tbname") #TD-10398 overflow tips + tdSql.error("select derivative(col, now, 1) from stb") #TD-11983 now not allowed in second param + tdSql.error("select derivative(col, now+3d-8h+6m, 1) from stb") #TD-11983 now not allowed in second param + tdSql.error("select derivative(col, 3d-8h+now+6m, 1) from stb") #TD-11983 now not allowed in second param def run(self): tdSql.prepare() diff --git a/tests/pytest/functions/function_elapsed_case.py b/tests/pytest/functions/function_elapsed_case.py index 50fbb0fe3244ec214e040f43962321a28ed31d9b..025354f2c3e31d1483f339e0e4f23bbda4c1e997 100644 --- a/tests/pytest/functions/function_elapsed_case.py +++ b/tests/pytest/functions/function_elapsed_case.py @@ -345,7 +345,9 @@ class ElapsedCase: tdSql.error("select elapsed(*) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") tdSql.error("select elapsed(ts, '1s') from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") tdSql.error("select elapsed(ts, i) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") - #tdSql.error("select elapsed(ts, now) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") + tdSql.error("select elapsed(ts, now) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") + tdSql.error("select elapsed(ts, now-7d+2h-3m+2s) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") + tdSql.error("select elapsed(ts, 7d+2h+now+3m+2s) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") tdSql.error("select elapsed(ts, ts) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") tdSql.error("select elapsed(ts + 1) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") tdSql.error("select elapsed(ts, 1b) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") diff --git a/tests/system-test/2-query/function_elapsed.py b/tests/system-test/2-query/function_elapsed.py new file mode 100644 index 0000000000000000000000000000000000000000..210a28bf7362e6d1e9502e2c08161bb39df06f9c --- /dev/null +++ b/tests/system-test/2-query/function_elapsed.py @@ -0,0 +1,1623 @@ +################################################################### +# Copyright (c) 2020 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import os + +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import * + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + self.ts = 1420041600000 # 2015-01-01 00:00:00 this is begin time for first record + self.num = 10 + + def caseDescription(self): + + ''' + case1 : [TD-11804] test case for elapsed function : + + this test case is for aggregate function elapsed , elapsed function can only used for the timestamp primary key column (ts) , + it has two input parameters, the first parameter is necessary, basic SQL as follow: + + =================================================================================================================================== + SELECT ELAPSED(field_name[, time_unit]) FROM { tb_name | stb_name } [WHERE clause] [INTERVAL(interval [, offset]) [SLIDING sliding]]; + =================================================================================================================================== + + elapsed function can acting on ordinary tables and super tables , notice that this function is related to the timeline. + If it acts on a super table , it must be group by tbname . by the way ,this function support nested query. + + The scenarios covered by the test cases are as follows: + + ==================================================================================================================================== + + case: select * from table|stable[group by tbname]|regular_table + + case:select elapsed(ts) from table|stable where clause interval (units) [fill(LINEAR,NEXT,PREV,VALUE,NULL)] [group by tbname] order [by ts desc asc|desc]; + + case:select elapsed(ts) , elapsed(ts,unit_time1)*regular_num1 , elapsed(ts,unit_time1)+regular_num2 from table|stable where clause interval (units) [fill(LINEAR,NEXT,PREV,VALUE,NULL)] [group by tbname] order [by ts desc asc|desc]; + + //mixup with all functions only once query (it's different with nest query) + case:select elapsed(ts), count(*), avg(col), twa(col), irate(col), sum(col), stddev(col), leastsquares(col, 1, 1),min(col), max(col), first(col), last(col), percentile(col, 20), apercentile(col, 30), last_row(col), spread(col)from table|stable where clause interval (units) [fill(LINEAR,NEXT,PREV,VALUE,NULL)] [group by tbname] order [by ts desc asc|desc]; + + //mixup with ordinary col + case:select ts ,elapsed(ts)*10 ,col+5 from table|stable where clause interval (units) [fill(LINEAR,NEXT,PREV,VALUE,NULL)] [group by tbname] order [by ts desc asc|desc]; + + //nest query + case:select elapsed(ts) from (select elapsed(ts), count(*), avg(col), twa(col), irate(col), sum(col), stddev(col), leastsquares(col, 1, 1),min(col), max(col), first(col), last(col), percentile(col, 20), apercentile(col, 30), last_row(col), spread(col)from table|stable where clause interval (units) [fill(LINEAR,NEXT,PREV,VALUE,NULL)] [group by tbname] order [by ts desc asc|desc]) where clause interval (units) [fill(LINEAR,NEXT,PREV,VALUE,NULL)] [group by tbname] order [by ts desc asc|desc]; + + //clause about filter condition + case:select elapsed(ts) from table|stable[group by tbname] where [ts|col|tag >|<|=|>=|<=|=|<>|!= value] | [between ... and ...] |[in] |[is null|not null] interval (unit_time) ; + case:select elapsed(ts) from table|stable[group by tbname] where clause1 and clause 2 and clause3 interval (unit_time) ; + + //JOIN query + case:select elapsed(ts) from TABLE1 as tb1 , TABLE2 as tb2 where join_condition [TABLE1 and TABLE2 can be stable|table|sub_table|empty_table] + + //UNION ALL query + case:select elapsed(ts) from TABLE1 union all select elapsed(ts) from TABLE2 [TABLE1 and TABLE2 can be stable|table|sub_table|empty_table] + + // Window aggregation + + case:select elapsed(ts) from t1 where clause session(ts, time_units) ; + case:select elapsed(ts) from t1 where clause state_window(regular_nums); + + // Continuous query + case:create table select elapsed(ts) ,avg(col) from (select elapsed(ts) ts_inter ,avg(col) col from stable|table interval (unit_time) [fill(LINEAR,NEXT,PREV,VALUE,NULL)][group by tbname]) interval (unit_time) [fill(LINEAR,NEXT,PREV,VALUE,NULL) sliding(unit_time_windows); + + ======================================================================================================================================== + + this test case notice successful execution and correctness of results. + + ''' + return + + def prepare_data(self): + + tdLog.info (" ====================================== prepare data ==================================================") + + tdSql.execute('drop database if exists testdb ;') + tdSql.execute('create database testdb keep 36500;') + tdSql.execute('use testdb;') + + tdSql.execute('create stable stable_1(ts timestamp ,tscol timestamp, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint, q_float float ,\ + q_double double , bin_chars binary(20)) tags(loc nchar(20) ,ind int,tstag timestamp);') + tdSql.execute('create stable stable_2(ts timestamp ,tscol timestamp, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint, q_float float ,\ + q_double double, bin_chars binary(20) ) tags(loc nchar(20),ind int,tstag timestamp);') + # create empty stables + tdSql.execute('create stable stable_empty(ts timestamp ,tscol timestamp, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint, q_float float ,\ + q_double double, bin_chars binary(20) ) tags(loc nchar(20),ind int,tstag timestamp);') + tdSql.execute('create stable stable_sub_empty(ts timestamp ,tscol timestamp, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint, q_float float ,\ + q_double double, bin_chars binary(20) ) tags(loc nchar(20),ind int,tstag timestamp);') + + # create empty sub_talbes and regular tables + tdSql.execute('create table sub_empty_1 using stable_sub_empty tags("sub_empty_1",3,"2015-01-01 00:02:00")') + tdSql.execute('create table sub_empty_2 using stable_sub_empty tags("sub_empty_2",3,"2015-01-01 00:02:00")') + tdSql.execute('create table regular_empty (ts timestamp , tscol timestamp ,q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , bin_chars binary(20)) ;') + + tdSql.execute('create table sub_table1_1 using stable_1 tags("sub1_1",1,"2015-01-01 00:00:00")') + tdSql.execute('create table sub_table1_2 using stable_1 tags("sub1_2",2,"2015-01-01 00:01:00")') + tdSql.execute('create table sub_table1_3 using stable_1 tags("sub1_3",3,"2015-01-01 00:02:00")') + + tdSql.execute('create table sub_table2_1 using stable_2 tags("sub2_1",1,"2015-01-01 00:00:00")') + tdSql.execute('create table sub_table2_2 using stable_2 tags("sub2_2",2,"2015-01-01 00:01:00")') + tdSql.execute('create table sub_table2_3 using stable_2 tags("sub2_3",3,"2015-01-01 00:02:00")') + + tdSql.execute('create table regular_table_1 (ts timestamp , tscol timestamp ,q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double, bin_chars binary(20)) ;') + tdSql.execute('create table regular_table_2 (ts timestamp , tscol timestamp ,q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , bin_chars binary(20)) ;') + tdSql.execute('create table regular_table_3 (ts timestamp , tscol timestamp ,q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , bin_chars binary(20)) ;') + + tablenames = ["sub_table1_1","sub_table1_2","sub_table1_3","sub_table2_1","sub_table2_2","sub_table2_3","regular_table_1","regular_table_2","regular_table_3"] + + tdLog.info("insert into records ") + + for tablename in tablenames: + + for i in range(self.num): + sql= 'insert into %s values(%d, %d,%d, %d, %d, %d, %f, %f, "%s")' % (tablename,self.ts + i*10000, self.ts + i*10,2147483647-i, 9223372036854775807-i, 32767-i, 127-i, i, i,("bintest"+str(i))) + print(sql) + tdSql.execute(sql) + + tdLog.info("=============================================data prepared done!=========================") + + def abnormal_common_test(self): + + tdLog.info (" ====================================== elapsed illeagal params ==================================================") + + tablenames = ["sub_table1_1","sub_table1_2","sub_table1_3","sub_table2_1","sub_table2_2","sub_table2_3","regular_table_1","regular_table_2","regular_table_3"] + + abnormal_list = ["()","(NULL)","(*)","(abc)","( , )","(NULL,*)","( ,NULL)","(%)","(+)","(*,)","(*, /)","(ts,10)","(ts,*)" "(ts,tbname*10)","(ts,tagname)","(ts,now-2d+3m)","(ts,2d+3m-2s)", + "(ts,2d+3m-2s,)","(ts+1d,10s)","(ts+10d,NULL)" ,"(ts,now -1m%1d)","(ts+10d)","(ts+10d,_c0)","(ts+10d,)","(ts,%)","(ts, , )","(ts,abc)","(ts,/)","(ts,*)","(ts,now)","(ts,now+1d)","(ts,_c0)","(ts,1s,100)", + "(ts,1s,abc)","(ts,1s,_c0)","(ts,1s,*)","(ts,1s,NULL)","(ts,,_c0)","(ts,tbname)","(ts,tbname,ts)","(ts,0,tbname)","('2021-11-18 00:00:10')","('2021-11-18 00:00:10', 1s)", + "('2021-11-18T00:00:10+0800', '1s')","('2021-11-18T00:00:10Z', '1s')","('2021-11-18T00:00:10+0800', 10000000d,)","('ts', ,2021-11-18T00:00:10+0800, )"] + + for tablename in tablenames: + for abnormal_param in abnormal_list: + + if tablename.startswith("stable"): + basic_sql= "select elapsed" + abnormal_param + " from " + tablename + " group by tbname ,ind order by tbname;" #stables + else: + basic_sql= "select elapsed" + abnormal_param + " from " + tablename + ";" # regular table + tdSql.error(basic_sql) + + def abnormal_use_test(self): + + tdLog.info (" ====================================== elapsed use abnormal ==================================================") + + sqls_list = ["select elapsed(ts) from regular_empty group by tbname,ind order by desc; ", + "select elapsed(ts) from regular_empty group by tbname,ind order by desc; ", + "select elapsed(ts) from regular_table_1 group by tbname,ind order by desc; ", + "select elapsed(ts) from sub_table1_1 group by tbname,ind order by desc; ", + "select elapsed(ts) from sub_table1_1 group by tbname,ind order by desc; ", + "select elapsed(ts,10s) from stable_empty group by ts order by ts;", + "select elapsed(ts,10s) from stable_1 group by ind order by ts;", + "select elapsed(ts,10s) from stable_2 group by tstag order by ts;", + "select elapsed(ts,10s) from stable_1 group by tbname,tstag,tscol order by ts;", + "select elapsed(ts,10s),ts from stable_1 group by tbname ,ind order by ts;", + "select ts,elapsed(ts,10s),tscol*100 from stable_1 group by tbname ,ind order by ts;", + "select elapsed(ts) from stable_1 group by tstag order by ts;", + "select elapsed(ts) from sub_empty_1 group by tbname,ind ,tscol order by ts desc;", + "select tbname, tscol,elapsed(ts) from sub_table1_1 group by tbname ,ind order by ts desc;", + "select elapsed(tscol) from sub_table1_1 order by ts desc;", + "select elapsed(tstag) from sub_table1_1 order by ts desc;", + "select elapsed(ind) from sub_table1_1 order by ts desc;", + "select elapsed(tscol) from sub_empty_1 order by ts desc;", + "select elapsed(tstag) from sub_empty_1 order by ts desc;", + "select elapsed(ind) from sub_table1_1 order by ts desc;", + "select elapsed(ind,10s) from sub_table1_1 order by ts desc;", + "select elapsed(tscol,10s) from sub_table1_1 order by ts desc;", + "select elapsed(tstag,10s) from sub_table1_1 order by ts desc;", + "select elapsed(q_int,10s) from sub_table1_1 order by ts desc;", + "select elapsed(loc,10s) from sub_table1_1 order by ts desc;", + "select elapsed(q_bigint,10s) from sub_table1_1 order by ts desc;", + "select elapsed(bin_chars,10s) from sub_table1_1 order by ts desc;"] + for sql in sqls_list : + tdSql.error(sql) + + def query_filter(self): + + tdLog.info (" ====================================== elapsed query filter ==================================================") + + for i in range(self.num): + ts_start_time = self.ts + i*10000 + ts_col_start_time = self.ts + i*10 + ts_tag_time = "2015-01-01 00:01:00" + ts_end_time = self.ts + (self.num-1-i)*10000 + ts_col_end_time = self.ts + (self.num-1-i)*10 + + filter_sql = "select elapsed(ts,10s) from stable_1 where ts >= %d group by tbname " %(ts_start_time) + tdSql.query(filter_sql) + tdSql.checkRows(3) + tdSql.checkData(0,0,float(self.num -i-1)) + tdSql.checkData(1,0,float(self.num -i-1)) + tdSql.checkData(2,0,float(self.num -i-1)) + + filter_sql = "select elapsed(ts,10s) from sub_table1_1 where ts >= %d " %(ts_start_time) + tdSql.query(filter_sql) + tdSql.checkRows(1) + tdSql.checkData(0,0,float(self.num -i-1)) + + + filter_sql = "select elapsed(ts,10s) from stable_1 where ts >= %d and tscol >= %d and tstag='2015-01-01 00:01:00'group by tbname " %(ts_start_time,ts_col_start_time) + tdSql.query(filter_sql) + tdSql.checkRows(1) + tdSql.checkData(0,0,float(self.num -i-1)) + + filter_sql = "select elapsed(ts,10s) from sub_table1_1 where ts >= %d and tscol >= %d " %(ts_start_time,ts_col_start_time) + tdSql.query(filter_sql) + tdSql.checkRows(1) + tdSql.checkData(0,0,float(self.num -i-1)) + + filter_sql = "select elapsed(ts,10s) from stable_1 where ts >= %d and tscol > %d and tstag='2015-01-01 00:01:00' group by tbname" %(ts_start_time,ts_col_start_time) + tdSql.query(filter_sql) + + if i == self.num-1: + tdSql.checkRows(0) + else: + tdSql.checkRows(1) + tdSql.checkData(0,0,float(self.num -i-2)) + + filter_sql = "select elapsed(ts,10s) from sub_table1_1 where ts >= %d and tscol > %d " %(ts_start_time,ts_col_start_time) + tdSql.query(filter_sql) + + if i == self.num-1: + tdSql.checkRows(0) + else: + tdSql.checkRows(1) + tdSql.checkData(0,0,float(self.num -i-2)) + + filter_sql = "select elapsed(ts,10s) from stable_1 where ts > %d and tscol > %d and tstag < '2015-01-01 00:01:00' group by tbname " %(ts_start_time,ts_col_start_time) + tdSql.query(filter_sql) + + if i == self.num-1: + tdSql.checkRows(0) + else: + tdSql.checkRows(1) + tdSql.checkData(0,0,float(self.num -i-2)) + + filter_sql = "select elapsed(ts,10s) from sub_table1_1 where ts > %d and tscol > %d " %(ts_start_time,ts_col_start_time) + tdSql.query(filter_sql) + + if i == self.num-1: + tdSql.checkRows(0) + else: + tdSql.checkRows(1) + tdSql.checkData(0,0,float(self.num -i-2)) + + filter_sql = "select elapsed(ts,10s) from stable_1 where ts > %d and tscol <= %d and tstag < '2015-01-01 00:01:00' group by tbname" %(ts_start_time,ts_col_start_time) + tdSql.query(filter_sql) + tdSql.checkRows(0) + + filter_sql = "select elapsed(ts,10s) from sub_table1_1 where ts > %d and tscol <= %d " %(ts_start_time,ts_col_start_time) + tdSql.query(filter_sql) + tdSql.checkRows(0) + + filter_sql = "select elapsed(ts,10s) from stable_1 where ts < %d and tscol <= %d and tstag < '2015-01-01 00:01:00' group by tbname" %(ts_end_time,ts_col_end_time) + tdSql.query(filter_sql) + + if i == self.num-1: + tdSql.checkRows(0) + else: + tdSql.checkRows(1) + tdSql.checkData(0,0,float(self.num -i-2)) + + filter_sql = "select elapsed(ts,10s) from sub_table1_1 where ts < %d and tscol <= %d " %(ts_end_time,ts_col_end_time) + tdSql.query(filter_sql) + + if i == self.num-1: + tdSql.checkRows(0) + else: + tdSql.checkRows(1) + tdSql.checkData(0,0,float(self.num -i-2)) + + filter_sql = "select elapsed(ts,10s) from stable_1 where ts < %d and tscol <= %d group by tbname " %(ts_end_time,ts_col_end_time) + tdSql.query(filter_sql) + + if i == self.num-1: + tdSql.checkRows(0) + else: + tdSql.checkRows(3) + tdSql.checkData(0,0,float(self.num - i - 2)) + tdSql.checkData(1,0,float(self.num - i - 2)) + tdSql.checkData(2,0,float(self.num - i - 2)) + + filter_sql = "select elapsed(ts,10s) from sub_table1_1 where ts < %d and tscol <= %d " %(ts_end_time,ts_col_end_time) + tdSql.query(filter_sql) + + if i == self.num-1: + tdSql.checkRows(0) + else: + tdSql.checkRows(1) + tdSql.checkData(0,0,float(self.num - i - 2)) + + filter_sql = "select elapsed(ts,10s) from stable_1 where ts = %d and tscol < %d group by tbname " %(ts_end_time,ts_col_end_time) + tdSql.query(filter_sql) + tdSql.checkRows(0) + + filter_sql = "select elapsed(ts,10s) from sub_table1_1 where ts = %d and tscol < %d " %(ts_end_time,ts_col_end_time) + tdSql.query(filter_sql) + tdSql.checkRows(0) + + filter_sql = "select elapsed(ts,10s) from stable_1 where q_tinyint != %d and tscol < %d group by tbname " %(i,ts_col_end_time) + tdSql.query(filter_sql) + + if i == self.num-1: + tdSql.checkRows(0) + else: + tdSql.checkRows(3) + tdSql.checkData(0,0,float(self.num -i-2)) + tdSql.checkData(1,0,float(self.num -i-2)) + tdSql.checkData(2,0,float(self.num -i-2)) + + filter_sql = "select elapsed(ts,10s) from sub_table1_1 where q_tinyint != %d and tscol < %d " %(i,ts_col_end_time) + tdSql.query(filter_sql) + + if i == self.num-1: + tdSql.checkRows(0) + else: + tdSql.checkRows(1) + tdSql.checkData(0,0,float(self.num -i-2)) + + filter_sql = "select elapsed(ts,10s) from stable_1 where q_tinyint != %d and tscol <= %d group by tbname " %(i,ts_col_end_time) + tdSql.query(filter_sql) + + if i == self.num: + tdSql.checkRows(0) + else: + tdSql.checkRows(3) + tdSql.checkData(0,0,float(self.num - i - 1)) + tdSql.checkData(1,0,float(self.num - i - 1)) + tdSql.checkData(2,0,float(self.num - i - 1)) + + filter_sql = "select elapsed(ts,10s) from sub_table1_1 where q_tinyint != %d and tscol <= %d " %(i,ts_col_end_time) + tdSql.query(filter_sql) + + if i == self.num: + tdSql.checkRows(0) + else: + tdSql.checkRows(1) + tdSql.checkData(0,0,float(self.num - i - 1)) + + filter_sql = "select elapsed(ts,10s) from stable_1 where q_tinyint <> %d and tscol < %d group by tbname " %(i,ts_col_end_time) + tdSql.query(filter_sql) + + if i == self.num-1: + tdSql.checkRows(0) + else: + tdSql.checkRows(3) + tdSql.checkData(0,0,float(self.num -i-2)) + tdSql.checkData(1,0,float(self.num -i-2)) + tdSql.checkData(2,0,float(self.num -i-2)) + + filter_sql = "select elapsed(ts,10s) from sub_table1_1 where q_tinyint <> %d and tscol < %d " %(i,ts_col_end_time) + tdSql.query(filter_sql) + + if i == self.num-1: + tdSql.checkRows(0) + else: + tdSql.checkRows(1) + tdSql.checkData(0,0,float(self.num -i-2)) + + filter_sql = "select elapsed(ts,10s) from stable_1 where q_tinyint <> %d and tscol <= %d group by tbname " %(i,ts_col_end_time) + tdSql.query(filter_sql) + + if i == self.num: + tdSql.checkRows(0) + else: + tdSql.checkRows(3) + tdSql.checkData(0,0,float(self.num - i - 1)) + tdSql.checkData(1,0,float(self.num - i - 1)) + tdSql.checkData(2,0,float(self.num - i - 1)) + + filter_sql = "select elapsed(ts,10s) from sub_table1_1 where q_tinyint <> %d and tscol <= %d " %(i,ts_col_end_time) + tdSql.query(filter_sql) + + if i == self.num: + tdSql.checkRows(0) + else: + tdSql.checkRows(1) + tdSql.checkData(0,0,float(self.num - i - 1)) + + # filter between and + tdSql.query("select elapsed(ts,10s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and q_tinyint between 125 and 127 and tscol <= '2015-01-01 00:01:00.000' ") + tdSql.checkData(0,0,2) + tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and \ + q_tinyint between 125 and 127 and tscol <= '2015-01-01 00:01:00.000' group by tbname ") + tdSql.checkData(0,0,2) + tdSql.checkData(1,0,2) + tdSql.checkData(2,0,2) + + # filter in and or + tdSql.query("select elapsed(ts,10s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and q_tinyint between 125 and 127 and tscol <= '2015-01-01 00:01:00.000' ") + tdSql.checkData(0,0,2) + + tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and q_tinyint between 125 and 127 and tscol <= '2015-01-01 00:01:00.000' group by tbname ") + tdSql.checkData(0,0,2) + tdSql.checkData(1,0,2) + tdSql.checkData(2,0,2) + + tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and q_tinyint in (125,126,127) and tscol <= '2015-01-01 00:01:00.000' group by tbname ") + tdSql.checkData(0,0,2) + tdSql.checkData(1,0,2) + tdSql.checkData(2,0,2) + + tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars in ('bintest0','bintest1') and tscol <= '2015-01-01 00:01:00.000' group by tbname ") + tdSql.checkData(0,0,1) + tdSql.checkData(1,0,1) + tdSql.checkData(2,0,1) + + tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars in ('bintest0','bintest1') and tscol <= '2015-01-01 00:01:00.000' group by tbname ") + tdSql.checkData(0,0,1) + tdSql.checkData(1,0,1) + tdSql.checkData(2,0,1) + + tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars like 'bintest_' and tscol <= '2015-01-01 00:01:00.000' group by tbname ") + tdSql.checkData(0,0,6) + tdSql.checkData(1,0,6) + tdSql.checkData(2,0,6) + + tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars like 'bintest_' and tscol <= '2015-01-01 00:01:00.000' group by tbname ") + tdSql.checkData(0,0,6) + tdSql.checkData(1,0,6) + tdSql.checkData(2,0,6) + + tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars is not null and tscol <= '2015-01-01 00:01:00.000' group by tbname; ") + tdSql.checkData(0,0,6) + tdSql.checkData(1,0,6) + tdSql.checkData(2,0,6) + + tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars is null and tscol <= '2015-01-01 00:01:00.000' group by tbname; ") + tdSql.checkRows(0) + + tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars match '^b' and tscol <= '2015-01-01 00:01:00.000' group by tbname; ") + tdSql.checkRows(3) + tdSql.checkData(0,0,6) + tdSql.checkData(1,0,6) + tdSql.checkData(2,0,6) + + tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars nmatch '^a' and tscol <= '2015-01-01 00:01:00.000' group by tbname; ") + tdSql.checkRows(3) + tdSql.checkData(0,0,6) + tdSql.checkData(1,0,6) + tdSql.checkData(2,0,6) + + tdSql.error("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and bin_chars ='bintest1' or bin_chars ='bintest2' and tscol <= '2015-01-01 00:01:00.000' group by tbname; ") + + tdSql.query("select elapsed(ts,10s) from stable_1 where (ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000') or (ts between '2015-01-01 00:01:00.000' and '2015-01-01 00:02:00.000') group by tbname; ") + tdSql.checkRows(3) + tdSql.checkData(0,0,9) + tdSql.checkData(1,0,9) + tdSql.checkData(2,0,9) + + def query_interval(self): + + tdLog.info (" ====================================== elapsed interval sliding fill ==================================================") + + # empty interval + tdSql.query("select max(q_int)*10 from stable_empty where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev);") + tdSql.checkRows(0) + tdSql.query("select max(q_int)*10 from sub_empty_2 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev);") + tdSql.checkRows(0) + + tdSql.query("select elapsed(ts,10s)*10 from stable_empty where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev) group by tbname;") + tdSql.checkRows(0) + tdSql.query("select elapsed(ts,10s)*10 from sub_empty_2 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev);") + tdSql.checkRows(0) + + for i in range(self.num): + ts_start_time = self.ts + i*10000 + ts_col_start_time = self.ts + i*10 + ts_tag_time = "2015-01-01 00:01:00" + ts_end_time = self.ts + (self.num-1-i)*10000 + ts_col_end_time = self.ts + (self.num-1-i)*10 + + + # only interval + interval_sql = "select elapsed(ts,10s) from stable_1 where ts <=%d interval(10s) group by tbname " %(ts_start_time) + tdSql.query(interval_sql) + tdSql.checkRows(3*(i+1)) + + interval_sql = "select elapsed(ts,10s) from sub_table1_1 where ts <=%d interval(10s) " %(ts_start_time) + tdSql.query(interval_sql) + tdSql.checkRows(i+1) + for x in range(i+1): + if x == i: + tdSql.checkData(x,1,0) + else : + tdSql.checkData(x,1,1) + + # interval and fill , fill_type = ["NULL","value,100","prev","next","linear"] + + # interval (10s) and time range is outer records + + tdSql.query("select elapsed(ts,10s)*10 from stable_empty where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev) group by tbname;") + tdSql.checkRows(0) + + tdSql.query("select elapsed(ts,10s)*10 from sub_empty_2 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev);") + tdSql.checkRows(0) + + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev) group by tbname;") + tdSql.checkRows(180) + tdSql.checkData(0,1,10) + tdSql.checkData(9,1,0) + tdSql.checkData(59,1,0) + tdSql.checkData(60,1,10) + + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(next) group by tbname;") + tdSql.checkRows(180) + tdSql.checkData(0,1,10) + tdSql.checkData(9,1,0) + tdSql.checkData(10,1,None) + tdSql.checkData(59,1,None) + tdSql.checkData(60,1,10) + tdSql.checkData(61,1,10) + + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(linear) group by tbname;") + tdSql.checkRows(180) + tdSql.checkData(0,1,10) + tdSql.checkData(9,1,0) + tdSql.checkData(10,1,None) + tdSql.checkData(59,1,None) + tdSql.checkData(60,1,10) + tdSql.checkData(61,1,10) + + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(NULL) group by tbname;") + tdSql.checkRows(180) + tdSql.checkData(0,1,10) + tdSql.checkData(9,1,0) + tdSql.checkData(10,1,None) + tdSql.checkData(59,1,None) + tdSql.checkData(60,1,10) + tdSql.checkData(61,1,10) + + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(value ,2) group by tbname;") + tdSql.checkRows(180) + tdSql.checkData(0,1,10) + tdSql.checkData(9,1,0) + tdSql.checkData(10,1,2) + tdSql.checkData(59,1,2) + tdSql.checkData(60,1,10) + tdSql.checkData(61,1,10) + + # interval (20s) and time range is outer records + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(prev) group by tbname,ind ;") + tdSql.checkRows(90) + tdSql.checkData(0,1,20) + tdSql.checkData(4,1,10) + tdSql.checkData(5,1,10) + tdSql.checkData(29,1,10) + tdSql.checkData(30,1,20) + tdSql.checkData(31,1,20) + + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(next) group by tbname,ind ;") + tdSql.checkRows(90) + tdSql.checkData(0,1,20) + tdSql.checkData(4,1,10) + tdSql.checkData(5,1,None) + tdSql.checkData(29,1,None) + tdSql.checkData(30,1,20) + tdSql.checkData(31,1,20) + + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(linear) group by tbname,ind ;") + tdSql.checkRows(90) + tdSql.checkData(0,1,20) + tdSql.checkData(4,1,10) + tdSql.checkData(5,1,None) + tdSql.checkData(29,1,None) + tdSql.checkData(30,1,20) + tdSql.checkData(31,1,20) + + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(NULL) group by tbname,ind ;") + tdSql.checkRows(90) + tdSql.checkData(0,1,20) + tdSql.checkData(4,1,10) + tdSql.checkData(5,1,None) + tdSql.checkData(29,1,None) + tdSql.checkData(30,1,20) + tdSql.checkData(31,1,20) + + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(value ,2) group by tbname,ind ;") + tdSql.checkRows(90) + tdSql.checkData(0,1,20) + tdSql.checkData(4,1,10) + tdSql.checkData(5,1,2) + tdSql.checkData(29,1,2) + tdSql.checkData(30,1,20) + tdSql.checkData(31,1,20) + + # interval (20s) and time range is in records + + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(prev) group by tbname,ind ;") + tdSql.checkRows(9) + tdSql.checkData(0,1,20) + tdSql.checkData(2,1,10) + tdSql.checkData(3,1,20) + tdSql.checkData(5,1,10) + tdSql.checkData(7,1,20) + tdSql.checkData(8,1,10) + + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(next) group by tbname,ind ;") + tdSql.checkRows(9) + tdSql.checkData(0,1,20) + tdSql.checkData(2,1,10) + tdSql.checkData(3,1,20) + tdSql.checkData(5,1,10) + tdSql.checkData(7,1,20) + tdSql.checkData(8,1,10) + + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(linear) group by tbname,ind ;") + tdSql.checkRows(9) + tdSql.checkData(0,1,20) + tdSql.checkData(2,1,10) + tdSql.checkData(3,1,20) + tdSql.checkData(5,1,10) + tdSql.checkData(7,1,20) + tdSql.checkData(8,1,10) + + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(NULL) group by tbname,ind ;") + tdSql.checkRows(9) + tdSql.checkData(0,1,20) + tdSql.checkData(2,1,10) + tdSql.checkData(3,1,20) + tdSql.checkData(5,1,10) + tdSql.checkData(7,1,20) + tdSql.checkData(8,1,10) + + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(value ,2 ) group by tbname,ind ;") + tdSql.checkRows(9) + tdSql.checkData(0,1,20) + tdSql.checkData(2,1,10) + tdSql.checkData(3,1,20) + tdSql.checkData(5,1,10) + tdSql.checkData(7,1,20) + tdSql.checkData(8,1,10) + + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) group by tbname,ind ;") + tdSql.checkRows(9) + tdSql.checkData(0,1,20) + tdSql.checkData(2,1,10) + tdSql.checkData(3,1,20) + tdSql.checkData(5,1,10) + tdSql.checkData(7,1,20) + tdSql.checkData(8,1,10) + + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2014-12-31 23:59:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(NULL) group by tbname,ind ;") + tdSql.checkRows(18) + tdSql.checkData(0,1,None) + tdSql.checkData(2,1,None) + tdSql.checkData(3,1,20) + tdSql.checkData(5,1,10) + tdSql.checkData(7,1,None) + tdSql.checkData(8,1,None) + tdSql.checkData(9,1,20) + + # interval sliding + + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2014-12-31 23:59:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) sliding(20s) fill(NULL) group by tbname,ind ;") + tdSql.checkRows(18) + tdSql.checkData(0,1,None) + tdSql.checkData(2,1,None) + tdSql.checkData(3,1,20) + tdSql.checkData(5,1,10) + tdSql.checkData(7,1,None) + tdSql.checkData(8,1,None) + tdSql.checkData(9,1,20) + + tdSql.query("select elapsed(ts,10s)*10 from stable_1 where ts >= '2014-12-31 23:59:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) sliding(10s) fill(NULL) group by tbname,ind ;") + tdSql.checkRows(39) + tdSql.checkData(0,1,None) + tdSql.checkData(2,1,None) + tdSql.checkData(6,1,10) + tdSql.checkData(7,1,20) + tdSql.checkData(12,1,0) + tdSql.checkData(13,1,None) + tdSql.checkData(15,1,None) + tdSql.checkData(19,1,10) + tdSql.checkData(20,1,20) + tdSql.checkData(25,1,0) + + def query_mix_common(self): + + tdLog.info (" ======================================elapsed mixup with common col, it will not support =======================================") + + tdSql.query("select elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' and ind =1 group by tbname; ") + tdSql.checkRows(1) + tdSql.checkData(0,0,6) + + tdSql.query("select elapsed(ts,10s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' ; ") + tdSql.checkRows(1) + tdSql.checkData(0,0,6) + + tdSql.error("select ts,elapsed(ts,10s) from sub_empty_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' ; ") + tdSql.error("select ts,elapsed(ts,10s) from stable_empty where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' group by tbname; ") + + tdSql.error("select ts,elapsed(ts,10s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' ; ") + tdSql.error("select ts,elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' group by tbname; ") + + tdSql.error("select q_int,elapsed(ts,10s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' ; ") + tdSql.error("select q_int,elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' group by tbname; ") + + tdSql.error("select ts,q_int,elapsed(ts,10s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' ; ") + tdSql.error("select ts,q_int,elapsed(ts,10s) from stable_1 where ts between '2015-01-01 00:00:00.000' and '2015-01-01 00:01:00.000' group by tbname; ") + + def query_mix_Aggregate(self): + + tdLog.info (" ====================================== elapsed mixup with aggregate ==================================================") + + tdSql.query("select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) from sub_table1_1 ; ") + + data = tdSql.getResult("select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) from sub_table1_1 ; ") + + querys = ["count(*)","avg(q_int)", "twa(q_tinyint)", "irate(q_int)","sum(q_double)","stddev(q_float)","LEASTSQUARES(q_int,0,1)", "elapsed(ts,10s)"] + + for index , query in enumerate(querys): + sql = "select %s from sub_table1_1 " %(query) + tdSql.query(sql) + tdSql.checkData(0,0,data[0][index]) + + tdSql.error("select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) from stable_1 group by tbname; ") + + # Arithmetic with elapsed for common table + + operators = ["+" ,"-" , "*" ,"/" ,"%"] + querys_oper = ["count(*)","avg(q_int)", "twa(q_tinyint)", "irate(q_int)","sum(q_double)","stddev(q_float)", "elapsed(ts,10s)"] + + for operator in operators: + + query_datas=[] + + sql_common= "select " + + for index , query in enumerate(querys_oper): + + query_data = tdSql.getResult("select %s from sub_table1_1;"%query) + + query_datas.append(query_data[0][0]) + sql_common += " %s %s " %(query,operator) + sql_common=sql_common[:-2] + " from sub_table1_1;" + + tdSql.query(sql_common) + results= query_datas[0] + if operator == "+": + for data in query_datas[1:]: + results += data + tdSql.checkData(0,0,results) + + results= query_datas[0] + if operator == "-": + for data in query_datas[1:]: + results -= data + tdSql.checkData(0,0,results) + + results= query_datas[0] + if operator == "*": + for data in query_datas[1:]: + results *= data + tdSql.checkData(0,0,results) + + results= query_datas[0] + if operator == "/": + for data in query_datas[1:]: + results /= data + tdSql.checkData(0,0,results) + + results= query_datas[0] + if operator == "%": + for data in query_datas[1:]: + results %= data + tdSql.checkData(0,0,results) + + + # Arithmetic with elapsed for super table + + operators = ["+" ,"-" , "*" ,"/" ,"%"] + querys_oper = ["count(*)","avg(q_int)", "twa(q_tinyint)", "irate(q_int)","sum(q_double)","stddev(q_float)", "elapsed(ts,10s)"] + + for operator in operators: + + query_datas=[] + + sql_common= "select " + + for index , query in enumerate(querys_oper): + + query_data = tdSql.getResult("select %s from stable_1 group by tbname;"%query) + + query_datas.append(query_data[0][0]) + sql_common += " %s %s " %(query,operator) + sql_common=sql_common[:-2] + " from stable_1 group by tbname;" + + tdSql.query(sql_common) + results= query_datas[0] + if operator == "+": + for data in query_datas[1:]: + results += data + tdSql.checkData(0,0,results) + tdSql.checkData(1,0,results) + tdSql.checkData(2,0,results) + + + results= query_datas[0] + if operator == "-": + for data in query_datas[1:]: + results -= data + tdSql.checkData(0,0,results) + tdSql.checkData(1,0,results) + tdSql.checkData(2,0,results) + + results= query_datas[0] + if operator == "*": + for data in query_datas[1:]: + results *= data + tdSql.checkData(0,0,results) + tdSql.checkData(1,0,results) + tdSql.checkData(2,0,results) + + results= query_datas[0] + if operator == "/": + for data in query_datas[1:]: + results /= data + tdSql.checkData(0,0,results) + tdSql.checkData(1,0,results) + tdSql.checkData(2,0,results) + + results= query_datas[0] + if operator == "%": + for data in query_datas[1:]: + results %= data + tdSql.checkData(0,0,results) + tdSql.checkData(1,0,results) + tdSql.checkData(2,0,results) + + def query_mix_select(self): + + tdLog.info (" ====================================== elapsed mixup with select function =================================================") + + querys = ["max(q_int)","min(q_int)" , "first(q_tinyint)", "first(*)","last(q_int)","last(*)","top(q_double,1)","bottom(q_float,1)","PERCENTILE(q_int,10)","APERCENTILE(q_int,10)","last_row(q_int)", "last_row(*)" , "interp(q_int)" ,"elapsed(ts,10s)"] + + for index , query in enumerate(querys): + + + sql1 = "select elapsed(ts,10s),%s from sub_table1_1 " %(query) + sql2 = "select elapsed(ts,10s),%s from stable_1 group by tbname" %(query) + + if query in ["top(q_double,1)","bottom(q_float,1)","last_row(*)","last_row(q_int)","interp(q_int)"]: # not support mixup with top and bottom + + print(sql1) + print(sql2) + if query in ["PERCENTILE(q_int,10)"]: # not support group by tbname + tdSql.error(sql1) + tdSql.error(sql2) + continue + else: + + tdSql.error(sql1) + tdSql.error(sql2) + continue + tdSql.execute(sql1) + tdSql.execute(sql2) + + querys_mix = ["max(q_int)","min(q_int)" , "first(q_tinyint)", "first(q_int)","last(q_int)","PERCENTILE(q_int,10)","APERCENTILE(q_int,10)","elapsed(ts,10s)"] + + tdSql.query("select max(q_int),min(q_int) , first(q_tinyint), first(q_int),last(q_int),PERCENTILE(q_int,10),APERCENTILE(q_int,10) ,elapsed(ts,10s) from sub_table1_1 ; ") + + data = tdSql.getResult("select max(q_int),min(q_int) , first(q_tinyint), first(q_int),last(q_int),PERCENTILE(q_int,10),APERCENTILE(q_int,10) ,elapsed(ts,10s) from sub_table1_1 ; ") + + for index , query in enumerate(querys_mix): + sql = "select %s from sub_table1_1 " %(query) + tdSql.query(sql) + tdSql.checkData(0,0,data[0][index]) + + tdSql.query("select max(q_int),min(q_int) , first(q_tinyint), first(q_int),last(q_int),APERCENTILE(q_int,10) ,elapsed(ts,10s) from stable_1 group by tbname ; ") + + data = tdSql.getResult("select max(q_int),min(q_int) , first(q_tinyint), first(q_int),last(q_int),APERCENTILE(q_int,10) ,elapsed(ts,10s) from stable_1 group by tbname ; ") + + querys_mix = ["max(q_int)","min(q_int)" , "first(q_tinyint)", "first(q_int)","last(q_int)","APERCENTILE(q_int,10)","elapsed(ts,10s)"] + + for index , query in enumerate(querys_mix): + sql = "select %s from stable_1 group by tbname " %(query) + tdSql.query(sql) + tdSql.checkData(0,0,data[0][index]) + tdSql.checkData(1,0,data[0][index]) + tdSql.checkData(2,0,data[0][index]) + + operators = ["+" ,"-" , "*" ,"/" ,"%"] + querys_oper = querys_mix + + for operator in operators: + + query_datas=[] + + sql_common= "select " + + for index , query in enumerate(querys_oper): + + query_data = tdSql.getResult("select %s from sub_table1_1;"%query) + + query_datas.append(query_data[0][0]) + sql_common += " %s %s " %(query,operator) + sql_common=sql_common[:-2] + " from sub_table1_1;" + + tdSql.query(sql_common) + results= query_datas[0] + if operator == "+": + for data in query_datas[1:]: + results += data + tdSql.checkData(0,0,results) + + results= query_datas[0] + if operator == "-": + for data in query_datas[1:]: + results -= data + tdSql.checkData(0,0,results) + + results= query_datas[0] + if operator == "*": + for data in query_datas[1:]: + results *= data + tdSql.checkData(0,0,results) + + results= query_datas[0] + if operator == "/": + for data in query_datas[1:]: + results /= data + tdSql.checkData(0,0,results) + + results= query_datas[0] + if operator == "%": + for data in query_datas[1:]: + results %= data + tdSql.checkData(0,0,results) + + + # Arithmetic with elapsed for super table + + operators = ["+" ,"-" , "*" ,"/" ,"%"] + querys_oper = querys_mix + + for operator in operators: + + query_datas=[] + + sql_common= "select " + + for index , query in enumerate(querys_oper): + + query_data = tdSql.getResult("select %s from stable_1 group by tbname;"%query) + + query_datas.append(query_data[0][0]) + sql_common += " %s %s " %(query,operator) + sql_common=sql_common[:-2] + " from stable_1 group by tbname;" + + tdSql.query(sql_common) + results= query_datas[0] + if operator == "+": + for data in query_datas[1:]: + results += data + tdSql.checkData(0,0,results) + tdSql.checkData(1,0,results) + tdSql.checkData(2,0,results) + + + results= query_datas[0] + if operator == "-": + for data in query_datas[1:]: + results -= data + tdSql.checkData(0,0,results) + tdSql.checkData(1,0,results) + tdSql.checkData(2,0,results) + + results= query_datas[0] + if operator == "*": + for data in query_datas[1:]: + results *= data + tdSql.checkData(0,0,results) + tdSql.checkData(1,0,results) + tdSql.checkData(2,0,results) + + results= query_datas[0] + if operator == "/": + for data in query_datas[1:]: + results /= data + tdSql.checkData(0,0,results) + tdSql.checkData(1,0,results) + tdSql.checkData(2,0,results) + + results= query_datas[0] + if operator == "%": + for data in query_datas[1:]: + results %= data + tdSql.checkData(0,0,results) + tdSql.checkData(1,0,results) + tdSql.checkData(2,0,results) + + def query_mix_compute(self): + + tdLog.info (" ====================================== elapsed mixup with compute function =================================================") + + querys = ["diff(q_int)","DERIVATIVE(q_int,1s,1)","spread(ts)","spread(q_tinyint)","ceil(q_float)","floor(q_float)","round(q_float)"] + + for index , query in enumerate(querys): + + sql1 = "select elapsed(ts,10s),%s from sub_table1_1 " %(query) + sql2 = "select elapsed(ts,10s),%s from stable_1 group by tbname" %(query) + if query in ["diff(q_int)","DERIVATIVE(q_int,1s,1)","ceil(q_float)","floor(q_float)","round(q_float)"]: + tdSql.error(sql1) + tdSql.error(sql2) + continue + tdSql.query(sql1) + tdSql.query(sql2) + + # only support mixup with spread + + sql = "select spread(ts)*10,spread(q_tinyint)-10,elapsed(ts,10s) from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) ;" + tdSql.execute(sql) + + data = tdSql.getResult(sql) + + sql = "select spread(ts)*10,spread(q_tinyint)-10,elapsed(ts,10s) from stable_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) group by tbname;" + tdSql.execute(sql) + + querys_mix = ["spread(ts)","spread(q_tinyint)-10","elapsed(ts,10s)"] + + for index , query in enumerate(querys_mix): + sql = "select %s from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) ; " %(query) + tdSql.query(sql) + + operators = ["+" ,"-" , "*" ,"/" ,"%"] + querys_oper = querys_mix + + for operator in operators: + + sql_common= "select " + + for index , query in enumerate(querys_oper): + + sql_common += " %s %s " %(query,operator) + sql_common=sql_common[:-2] + " from stable_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) group by tbname;" + + tdSql.query(sql_common) + + for index , query in enumerate(querys_mix): + sql = "select %s from stable_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) group by tbname ; " %(query) + tdSql.query(sql) + + operators = ["+" ,"-" , "*" ,"/" ,"%"] + querys_oper = querys_mix + + for operator in operators: + + sql_common= "select " + + for index , query in enumerate(querys_oper): + + sql_common += " %s %s " %(query,operator) + sql_common=sql_common[:-2] + " from stable_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) group by tbname;" + + tdSql.query(sql_common) + + def query_mix_arithmetic(self): + + tdLog.info (" ====================================== elapsed mixup with arithmetic =================================================") + + tdSql.execute("select elapsed(ts,10s)+1 ,elapsed(ts,10s)-2,elapsed(ts,10s)*3,elapsed(ts,10s)/4,elapsed(ts,10s)%5 from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) ; ") + tdSql.execute("select elapsed(ts,10s)+1 ,elapsed(ts,10s)-2,elapsed(ts,10s)*3,elapsed(ts,10s)/4,elapsed(ts,10s)%5 from stable_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) group by tbname; ") + + queries = ["elapsed(ts,10s)+1" ,"elapsed(ts,10s)-2","elapsed(ts,10s)*3","elapsed(ts,10s)/4","elapsed(ts,10s)%5" ] + + for index ,query in enumerate(queries): + sql = "select %s from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) ;" % (query) + data = tdSql.getResult(sql) + tdSql.query("select elapsed(ts,10s)+1 ,elapsed(ts,10s)-2,elapsed(ts,10s)*3,elapsed(ts,10s)/4,elapsed(ts,10s)%5 from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) ; ") + tdSql.checkData(0,index+1,data[0][1]) + + def query_with_join(self): + + tdLog.info (" ====================================== elapsed mixup with join =================================================") + + tdSql.error("select elapsed(ts,10s) from stable_empty TABLE1 , stable_empty TABLE2 where TABLE1.ts =TABLE2.ts; ") + tdSql.error("select elapsed(ts,10s) from stable_empty TABLE1 , stable_empty TABLE2 where TABLE1.ts =TABLE2.ts group by tbname; ") + + tdSql.execute("select elapsed(ts,10s) from sub_empty_1 TABLE1 , sub_empty_2 TABLE2 where TABLE1.ts =TABLE2.ts; ") + tdSql.error("select elapsed(ts,10s) from stable_1 TABLE1 , stable_2 TABLE2 where TABLE1.ts =TABLE2.ts and TABLE1.ind =TABLE2.ind; ") + tdSql.error("select elapsed(ts,10s) from stable_1 TABLE1 , stable_2 TABLE2 where TABLE1.ts =TABLE2.ts and TABLE1.ind =TABLE2.ind group by tbname,ind; ") # join not support group by + + tdSql.error("select elapsed(ts,10s) from sub_empty_1 TABLE1 , stable_2 TABLE2 where TABLE1.ts =TABLE2.ts and TABLE1.ind =TABLE2.ind ; ") + tdSql.execute("select elapsed(ts,10s) from sub_empty_1 TABLE1 , sub_empty_2 TABLE2 where TABLE1.ts =TABLE2.ts ; ") + + tdSql.query("select elapsed(ts,10s) from sub_table1_1 TABLE1 , sub_table1_2 TABLE2 where TABLE1.ts =TABLE2.ts ; ") + tdSql.checkData(0,0,9) + + tdSql.query("select elapsed(ts,10s) from sub_empty_1 TABLE1 , sub_table1_2 TABLE2 where TABLE1.ts =TABLE2.ts ; ") + tdSql.checkRows(0) + + tdSql.query("select elapsed(ts,10s) from sub_empty_1 TABLE1 , regular_empty TABLE2 where TABLE1.ts =TABLE2.ts ; ") + tdSql.checkRows(0) + + tdSql.query("select elapsed(ts,10s) from sub_empty_1 TABLE1 , regular_table_1 TABLE2 where TABLE1.ts =TABLE2.ts ; ") + tdSql.checkRows(0) + + tdSql.query("select elapsed(ts,10s) from sub_table1_3 TABLE1 , regular_table_1 TABLE2 where TABLE1.ts =TABLE2.ts ; ") + tdSql.checkRows(1) + tdSql.checkData(0,0,9) + + tdSql.query("select elapsed(ts,10s) from regular_table_1 ; ") + tdSql.checkRows(1) + tdSql.checkData(0,0,9) + + def query_with_union(self): + + tdLog.info (" ====================================== elapsed mixup with union all =================================================") + + # union all with empty + + tdSql.query("select elapsed(ts,10s) from regular_table_1 union all select elapsed(ts,10s) from regular_table_2;") + + tdSql.query("select elapsed(ts,10s) from regular_table_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) union all \ + select elapsed(ts,10s) from regular_table_2 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev);") + tdSql.checkRows(1200) + tdSql.checkData(0,1,0.1) + tdSql.checkData(500,1,0) + + tdSql.query("select elapsed(ts,10s) from sub_empty_1 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) union all \ + select elapsed(ts,10s) from regular_table_2 where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev);") + tdSql.checkRows(600) + tdSql.checkData(0,1,0.1) + tdSql.checkData(500,0,0) + + tdSql.query('select elapsed(ts,10s) from sub_empty_1 union all select elapsed(ts,10s) from sub_empty_2;') + tdSql.checkRows(0) + + tdSql.query('select elapsed(ts,10s) from regular_table_1 union all select elapsed(ts,10s) from sub_empty_1;') + tdSql.checkRows(1) + tdSql.checkData(0,0,9) + + tdSql.query('select elapsed(ts,10s) from sub_empty_1 union all select elapsed(ts,10s) from regular_table_1;') + tdSql.checkRows(1) + tdSql.checkData(0,0,9) + + tdSql.query('select elapsed(ts,10s) from sub_empty_1 union all select elapsed(ts,10s) from sub_table1_1;') + tdSql.checkRows(1) + tdSql.checkData(0,0,9) + + tdSql.query('select elapsed(ts,10s) from sub_table1_1 union all select elapsed(ts,10s) from sub_empty_1;') + tdSql.checkRows(1) + tdSql.checkData(0,0,9) + + tdSql.query('select elapsed(ts,10s) from sub_empty_1 union all select elapsed(ts,10s) from regular_table_1;') + tdSql.checkRows(1) + tdSql.checkData(0,0,9) + + tdSql.error('select elapsed(ts,10s) from sub_empty_1 union all select elapsed(ts,10s) from stable_sub_empty group by tbname;') + + tdSql.error('select elapsed(ts,10s) from regular_table_1 union all select elapsed(ts,10s) from stable_sub_empty group by tbname;') + + tdSql.query('select elapsed(ts,10s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(1s) fill(prev) union all select elapsed(ts,10s) from sub_empty_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(1s) fill(prev);') + tdSql.checkRows(0) + + tdSql.error('select elapsed(ts,10s) from sub_empty_1 union all select elapsed(ts,10s) from stable_empty group by tbname;') + + tdSql.error('select elapsed(ts,10s) from sub_empty_1 interval(1s) union all select elapsed(ts,10s) from stable_empty interval(1s) group by tbname;') + + tdSql.error('select elapsed(ts,10s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(1s) fill(prev) union all select elapsed(ts,10s) from stable_empty where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(1s) fill(prev) group by tbname;') + + tdSql.query("select elapsed(ts,10s) from stable_empty group by tbname union all select elapsed(ts,10s) from stable_empty group by tbname ;") + tdSql.checkRows(0) + + # case : TD-12229 + tdSql.query("select elapsed(ts,10s) from stable_empty group by tbname union all select elapsed(ts,10s) from stable_1 group by tbname ;") + tdSql.checkRows(3) + + tdSql.query("select elapsed(ts,10s) from stable_1 group by tbname union all select elapsed(ts,10s) from stable_1 group by tbname ;") + tdSql.checkRows(6) + tdSql.checkData(0,0,9) + tdSql.checkData(5,0,9) + + tdSql.query("select elapsed(ts,10s) from stable_1 group by tbname union all select elapsed(ts,10s) from stable_2 group by tbname ;") + tdSql.checkRows(6) + tdSql.checkData(0,0,9) + tdSql.checkData(5,0,9) + + tdSql.query('select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname union all\ + select elapsed(ts,10s) from stable_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname ;') + tdSql.checkRows(360) + tdSql.checkData(0,1,1) + tdSql.checkData(50,1,0) + + #case : TD-12229 + tdSql.query('select elapsed(ts,10s) from stable_empty group by tbname union all select elapsed(ts,10s) from stable_2 group by tbname ;') + tdSql.checkRows(3) + + tdSql.query('select elapsed(ts,10s) from stable_1 group by tbname union all select elapsed(ts,10s) from stable_empty group by tbname ;') + tdSql.checkRows(3) + + + tdSql.query('select elapsed(ts,10s) from stable_empty where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname union all\ + select elapsed(ts,10s) from stable_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname ;') + tdSql.checkRows(180) + + tdSql.query('select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname union all\ + select elapsed(ts,10s) from stable_empty where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname ;') + tdSql.checkRows(180) + + # union all with sub table and regular table + + # sub_table with sub_table + + tdSql.query('select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ + select elapsed(ts,10s) from sub_table2_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') + tdSql.checkRows(120) + tdSql.checkData(0,1,1) + tdSql.checkData(12,1,0) + + tdSql.query('select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ + select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') + tdSql.checkRows(120) + tdSql.checkData(0,1,1) + tdSql.checkData(12,1,0) + + tdSql.query('select elapsed(ts,10s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ + select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') + tdSql.checkRows(120) + tdSql.checkData(0,1,1) + tdSql.checkData(12,1,0) + + tdSql.query('select elapsed(ts,10s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ + select elapsed(ts,10s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') + tdSql.checkRows(120) + tdSql.checkData(0,1,1) + tdSql.checkData(12,1,0) + + tdSql.query('select elapsed(ts,10s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ + select elapsed(ts,10s) from regular_table_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') + tdSql.checkRows(120) + tdSql.checkData(0,1,1) + tdSql.checkData(12,1,0) + + tdSql.query('select elapsed(ts,10s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ + select elapsed(ts,10s) from regular_table_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') + tdSql.checkRows(120) + tdSql.checkData(0,1,1) + tdSql.checkData(12,1,0) + + tdSql.query('select elapsed(ts,10s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ + select elapsed(ts,10s) from regular_table_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') + tdSql.checkRows(60) + tdSql.checkData(0,1,1) + tdSql.checkData(12,1,0) + + tdSql.query('select elapsed(ts,10s) from regular_table_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) union all\ + select elapsed(ts,10s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') + tdSql.checkRows(60) + tdSql.checkData(0,1,1) + tdSql.checkData(12,1,0) + + # stable with stable + + tdSql.query('select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname union all\ + select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname;') + tdSql.checkRows(360) + tdSql.checkData(0,1,1) + tdSql.checkData(12,1,0) + + tdSql.query('select elapsed(ts,10s) from regular_table_2 interval(10s) union all select elapsed(ts,10s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev);') + tdSql.checkRows(10) + tdSql.checkData(0,1,1) + tdSql.checkData(9,1,0) + + tdSql.query('select elapsed(ts,10s) from regular_table_2 interval(10s) union all select elapsed(ts,10s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;') + tdSql.checkRows(70) + tdSql.checkData(0,1,1) + tdSql.checkData(9,1,0) + + tdSql.query('select elapsed(ts,10s) from regular_table_2 interval(10s) order by ts desc union all select elapsed(ts,10s) from regular_table_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) order by ts asc;') + tdSql.checkRows(70) + tdSql.checkData(0,1,0) + tdSql.checkData(1,1,1) + tdSql.checkData(9,1,1) + + tdSql.query('select elapsed(ts,10s) from stable_1 group by tbname, ind order by ts desc union all select elapsed(ts,10s) from stable_2 group by tbname, ind order by ts asc ;') + tdSql.checkRows(6) + tdSql.checkData(0,0,9) + + tdSql.query('select elapsed(ts,10s) from stable_1 group by tbname, ind order by ts desc union all select elapsed(ts,10s) from stable_1 group by tbname, ind order by ts asc ;') + tdSql.checkRows(6) + tdSql.checkData(0,0,9) + + tdSql.query('select elapsed(ts,10s) from stable_1 interval(10s) group by tbname,ind order by ts desc union all select elapsed(ts,10s) from stable_2 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname,ind order by ts asc ;') + tdSql.checkRows(210) + tdSql.checkData(0,1,0) + tdSql.checkData(1,1,1) + tdSql.checkData(9,1,1) + + tdSql.query('select elapsed(ts,10s) from stable_2 interval(10s) group by tbname,ind order by ts desc union all select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname,ind order by ts asc ;') + tdSql.checkRows(210) + tdSql.checkData(0,1,0) + tdSql.checkData(1,1,1) + tdSql.checkData(9,1,1) + + tdSql.query('select elapsed(ts,10s) from stable_1 interval(10s) group by tbname,ind order by ts desc union all select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname,ind order by ts asc ;') + tdSql.checkRows(210) + tdSql.checkData(0,1,0) + tdSql.checkData(1,1,1) + tdSql.checkData(9,1,1) + + def query_nest(self): + + tdLog.info (" ====================================== elapsed query for nest =================================================") + + # ===============================================outer nest============================================ + + # regular table + + # ts can't be used at outer query + + tdSql.error("select elapsed(ts,10s) from (select ts from regular_table_1 );") + + # case : TD-12164 + + tdSql.error("select elapsed(ts,10s) from (select qint ts from regular_table_1 );") + tdSql.error("select elapsed(tbname ,10s) from (select qint tbname from regular_table_1 );") + tdSql.error("select elapsed(tsc ,1s) from (select q_int tsc from regular_table_1) ;") + tdSql.error("select elapsed(tsv ,1s) from (select elapsed(ts,1s) tsv from regular_table_1);") + tdSql.error("select elapsed(ts ,1s) from (select elapsed(ts,1s) ts from regular_table_1);") + tdSql.error("select elapsed(tsc ,1s) from (select tscol tsc from regular_table_1) ;") + + # case TD-12276 + tdSql.error("select elapsed(ts,10s) from (select ts,tbname from regular_table_1 order by ts asc );") + + tdSql.error("select elapsed(ts,10s) from (select ts,tbname from regular_table_1 order by ts desc );") + + tdSql.error("select elapsed(ts,10s) from (select ts ,max(q_int),tbname from regular_table_1 order by ts ) interval(1s);") + + tdSql.error("select elapsed(ts,10s) from (select ts ,q_int,tbname from regular_table_1 order by ts ) interval(1s);") + + # sub table + + tdSql.error("select elapsed(ts,10s) from (select ts from sub_table1_1 );") + + tdSql.error("select elapsed(ts,10s) from (select ts ,max(q_int),tbname from sub_table1_1 order by ts ) interval(1s);") + + tdSql.error("select elapsed(ts,10s) from (select ts ,q_int,tbname from sub_table1_1 order by ts ) interval(1s);") + + tdSql.error("select elapsed(ts,10s) from (select ts ,tbname,top(q_int,3) from sub_table1_1 ) interval(10s);") + + tdSql.error("select elapsed(ts,10s) from (select ts ,tbname,bottom(q_int,3) from sub_table1_1 ) interval(10s);") + + tdSql.error("select elapsed(ts,10s) from (select ts ,tbname,last_row(*) from sub_table1_1 ) interval(10s);") + + tdSql.error("select elapsed(ts,10s) from (select ts ,tbname,last_row(q_int) from sub_table1_1 ) interval(10s);") + + tdSql.error("select elapsed(ts,10s) from (select ts ,count(*),tbname from sub_table1_1 order by ts ) interval(1s);") + + querys = ["count(*)","avg(q_int)","twa(q_tinyint)", "irate(q_int)","sum(q_double)","stddev(q_float)","LEASTSQUARES(q_int,0,1)","elapsed(ts,10s)"] + + for query in querys: + sql1 = "select elapsed(ts,10s) from (select %s from regular_table_1 order by ts ) interval(1s); " % query + sql2 = "select elapsed(ts,10s) from (select ts , tbname ,%s from regular_table_1 order by ts ) interval(1s); " % query + sql3 = "select elapsed(ts,10s) from (select ts , tbname ,%s from stable_1 group by tbname, ind order by ts ) interval(1s); " % query + sql4 = "select elapsed(ts,10s) from (select %s from sub_table2_1 order by ts ) interval(1s); " % query + sql5 = "select elapsed(ts,10s) from (select ts , tbname ,%s from sub_table2_1 order by ts ) interval(1s); " % query + + tdSql.error(sql1) + tdSql.error(sql2) + tdSql.error(sql3) + tdSql.error(sql4) + tdSql.error(sql5) + + + # case TD-12164 + tdSql.error( "select elapsed(ts00 ,1s) from (select elapsed(ts,1s) ts00 from regular_table_1) ; " ) + tdSql.error( "select elapsed(ts ,1s) from (select elapsed(ts,1s) ts from regular_table_1) ; " ) + + tdSql.error( "select elapsed(ts00 ,1s) from (select elapsed(ts,1s) ts00 from stable_1 group by tbname ) ; " ) + tdSql.error( "select elapsed(ts ,1s) from (select elapsed(ts,1s) ts from stable_1 group by tbname) ; " ) + + + # stable + + tdSql.error("select elapsed(ts,10s) from (select ts from stable_1 ) group by tbname ;") + + tdSql.error("select elapsed(ts,10s) from (select ts ,max(q_int),tbname from stable_1 group by tbname order by ts ) interval(1s) group by tbname;") + + tdSql.error("select elapsed(ts,10s) from (select ts ,q_int,tbname from stable_1 order by ts ) interval(1s) group by tbname;") + + # mixup with aggregate + + querys = ["max(q_int)","min(q_int)" , "first(q_tinyint)", "first(*)","last(q_int)","last(*)","top(q_double,1)", + "bottom(q_float,1)","PERCENTILE(q_int,10)","APERCENTILE(q_int,10)","last_row(q_int)", "last_row(*)" , "interp(q_int)" ,"elapsed(ts,10s)"] + + for index , query in enumerate(querys): + + sql1 = "select elapsed(ts,10s) from (select %s from sub_table1_1) where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(10s) fill(prev) ; " %(query) + sql2 = "select elapsed(ts,10s) from (select %s from stable_1 ) where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(10s) fill(prev) group by tbname; " %(query) + sql3 = "select elapsed(ts,10s) from (select %s from stable_1 group by tbname) where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(10s) fill(prev) group by tbname; " %(query) + + if query in ["top(q_double,1)","bottom(q_float,1)","interp(q_int)" ]: + # print(sql1 ) + # print(sql2) + tdSql.query(sql1) + tdSql.error(sql2) + else: + tdSql.error(sql1) + tdSql.error(sql2) + tdSql.error(sql3) + + tdSql.error("select elapsed(ts,10s) from (select ts,tbname from regular_table_1 order by ts ) where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev);") + + tdSql.error("select elapsed(ts,10s) from (select ts ,max(q_int),tbname from regular_table_1 order by ts ) where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev);") + + # ===============================================inner nest============================================ + + # sub table + + tdSql.query("select data from (select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from sub_table1_1 ); ") + tdSql.checkData(0,0,9) + + tdSql.query("select data from (select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from sub_table1_1 \ + where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") + tdSql.checkRows(600) + tdSql.checkData(0,0,0.1) + + tdSql.query("select * from (select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 ); ") + tdSql.checkData(0,7,9) + + tdSql.query("select * from (select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") + tdSql.checkRows(600) + tdSql.checkData(0,0,0.1) + + tdSql.query("select max(data) from (select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 ); ") + tdSql.checkData(0,0,9) + + tdSql.query("select max(data) from (select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") + tdSql.checkRows(1) + tdSql.checkData(0,0,0.1) + + tdSql.query("select max(data) from (select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from sub_empty_2 \ + where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") + tdSql.checkRows(0) + + tdSql.query("select max(data),min(data),avg(data) from (select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") + tdSql.checkRows(1) + + tdSql.query("select ceil(data),floor(data),round(data) from (select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") + tdSql.checkRows(600) + + tdSql.query("select spread(data) from (select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") + tdSql.checkRows(1) + + tdSql.query("select diff(data) from (select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") + tdSql.checkRows(599) + + tdSql.query("select DERIVATIVE(data ,1s ,1) from (select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") + tdSql.checkRows(598) + + tdSql.query("select ceil(data)from (select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") + tdSql.checkRows(600) + + tdSql.query("select floor(data)from (select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") + tdSql.checkRows(600) + + tdSql.query("select round(data)from (select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") + tdSql.checkRows(600) + + tdSql.query("select data*10+2 from (select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") + tdSql.checkRows(600) + + tdSql.query("select data*10+2 from (select count(*),avg(q_int) , twa(q_tinyint), irate(q_int),sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \ + where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ") + tdSql.checkRows(600) + + def query_session_windows(self): + + # case TD-12344 + # session not support stable + tdSql.execute('select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" session(ts ,10s) group by tbname,ind order by ts asc ') + + tdSql.query('select elapsed(ts,10s) from sub_table1_1 session(ts,1w) ; ') + tdSql.checkRows(1) + tdSql.checkData(0,0,9) + tdSql.query('select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" session(ts,1w) ; ') + tdSql.checkRows(1) + tdSql.checkData(0,0,9) + + tdSql.error('select elapsed(ts,10s) from ( select * from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") session(ts,1w) ; ') + + tdSql.error('select elapsed(ts,10s) from ( select ts ,q_int from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") session(ts,1w) ; ') + + tdSql.error('select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(20s) fill (next) session(ts,1w) ; ') + + tdSql.query('select elapsed(ts,10s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" session(ts,1w) ; ') + tdSql.checkRows(0) + + # windows state + # not support stable + + tdSql.error('select elapsed(ts,10s) from stable_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" state_window(q_int) group by tbname,ind order by ts asc ') + + tdSql.query('select elapsed(ts,10s) from sub_table1_1 state_window(q_int) ; ') + tdSql.checkRows(10) + tdSql.checkData(0,0,0) + tdSql.query('select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" state_window(q_int) ; ') + tdSql.checkRows(10) + tdSql.checkData(0,0,0) + + tdSql.error('select elapsed(ts,10s) from ( select * from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") state_window(q_int) ; ') + + tdSql.error('select elapsed(ts,10s) from ( select ts ,q_int from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") state_window(q_int) ; ') + + tdSql.error('select elapsed(ts,10s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(20s) fill (next) state_window(q_int) ; ') + + tdSql.query('select elapsed(ts,10s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" state_window(q_int); ') + tdSql.checkRows(0) + + + def continuous_query(self): + tdSql.execute('create table elapsed_t as select elapsed(ts) from sub_table1_1 interval(1m) sliding(30s);') + tdSql.execute('create table elapsed_tb as select elapsed(ts) from stable_1 interval(1m) sliding(30s) group by tbname;') + tdSql.error('create table elapsed_tc as select elapsed(ts) from stable_1 interval(10s) sliding(5s) interval(1m) sliding(30s) group by tbname;') + + def query_precision(self): + def generate_data(precision="ms"): + + tdSql.execute("create database if not exists db_%s precision '%s';" %(precision, precision)) + tdSql.execute("use db_%s;" %precision) + tdSql.execute("create stable db_%s.st (ts timestamp,value int) tags(ind int);"%precision) + tdSql.execute("create table db_%s.tb1 using st tags(1);"%precision) + tdSql.execute("create table db_%s.tb2 using st tags(2);"%precision) + + if precision == "ms": + start_ts = self.ts + step = 10000 + elif precision == "us": + start_ts = self.ts*1000 + step = 10000000 + elif precision == "ns": + start_ts = self.ts*1000000 + step = 10000000000 + else: + pass + + for i in range(10): + + sql1 = "insert into db_%s.tb1 values (%d,%d)"%(precision ,start_ts+i*step,i) + sql2 = "insert into db_%s.tb1 values (%d,%d)"%(precision, start_ts+i*step,i) + tdSql.execute(sql1) + tdSql.execute(sql2) + + time_units = ["10s","10a","10u","10b"] + + precision_list = ["ms","us","ns"] + for pres in precision_list: + generate_data(pres) + + for index,unit in enumerate(time_units): + + if pres == "ms": + if unit in ["10u","10b"]: + tdSql.error("select elapsed(ts,%s) from db_%s.st group by tbname "%(unit,pres)) + else: + tdSql.query("select elapsed(ts,%s) from db_%s.st group by tbname "%(unit,pres)) + elif pres == "us" and unit in ["10b"]: + if unit in ["10b"]: + tdSql.error("select elapsed(ts,%s) from db_%s.st group by tbname "%(unit,pres)) + else: + tdSql.query("select elapsed(ts,%s) from db_%s.st group by tbname "%(unit,pres)) + else: + + tdSql.query("select elapsed(ts,%s) from db_%s.st group by tbname "%(unit,pres)) + basic_result = 9 + tdSql.checkData(0,0,basic_result*pow(1000,index)) + + def run(self): + tdSql.prepare() + self.prepare_data() + # self.abnormal_common_test() + self.abnormal_use_test() + self.query_filter() + self.query_interval() + self.query_mix_common() + self.query_mix_Aggregate() + self.query_mix_select() + self.query_mix_compute() + self.query_mix_arithmetic() + self.query_with_join() + self.query_with_union() + self.query_nest() + self.query_session_windows() + self.continuous_query() + self.query_precision() + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) + +