提交 575686c6 编写于 作者: W wenzhouwww

Merge branch 'develop' into test/case_runCI_query

......@@ -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;
}
......
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/
......
......@@ -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
......@@ -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:
......
......@@ -4,7 +4,7 @@
<TargetFrameworks>net5;netstandard2.0;net45</TargetFrameworks>
<PackageId>TDengine.Connector</PackageId>
<PackageIcon>logo.jpg</PackageIcon>
<Version>1.0.3</Version>
<Version>1.0.4</Version>
<Authors>taosdata</Authors>
<Company>www.taosdata.com</Company>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
......@@ -14,7 +14,7 @@
This C # connector supports: Linux 64/Windows x64/Windows x86.
more information please visit: https://www.taosdata.com
</Description>
<RepositoryUrl>https://github.com/taosdata/TDengine/tree/develop/src/connector/C%23</RepositoryUrl>
<RepositoryUrl>https://github.com/taosdata/TDengine/tree/develop/src/connector/C%2523/src/TDengineDriver</RepositoryUrl>
<NoWarn>CS1591</NoWarn>
</PropertyGroup>
<ItemGroup>
......
......@@ -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)
if (!String.IsNullOrEmpty(arr[i]))
{
arrStrBuilder.Append(arr[i]);
}
else if (!String.IsNullOrEmpty(arr[i]) && typeSize > itemLength)
for (int j = 0; j < itemLength; j++)
{
arrStrBuilder.Append(arr[i]);
arrStrBuilder.Append(AlignCharArr(typeSize - itemLength));
//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 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)
if (!String.IsNullOrEmpty(arr[i]))
{
arrStrBuilder.Append(arr[i]);
}
else if (!String.IsNullOrEmpty(arr[i]) && typeSize > itemLength)
for (int j = 0; j < itemLength; j++)
{
arrStrBuilder.Append(arr[i]);
arrStrBuilder.Append(AlignCharArr(typeSize - itemLength));
//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;
......@@ -614,7 +607,7 @@ 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);
}
......
using System;
using Test.UtilsTools;
using System.Collections.Generic;
namespace Cases
{
public class FetchLengthCase
{
/// <author>xiaolei</author>
/// <Name>TestRetrieveBinary</Name>
/// <describe>TD-12103 C# connector fetch_row with binary data retrieving error</describe>
/// <filename>FetchLength.cs</filename>
/// <result>pass or failed </result>
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<List<string>> result = UtilsTools.GetResultSet(resPtr);
List<string> colname = result[0];
List<string> data = result[1];
UtilsTools.AssertEqual("db3", data[0]);
UtilsTools.AssertEqual("log", data[1]);
UtilsTools.AssertEqual("db02", data[2]);
UtilsTools.AssertEqual("test", data[3]);
}
}
}
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();
}
}
}
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
{
/// <author>xiaolei</author>
/// <Name>StableStmtCases.TestBindSingleLineCn</Name>
/// <describe>Test stmt insert single line of chinese character into stable by column after column </describe>
/// <filename>StmtSTable.cs</filename>
/// <result>pass or failed </result>
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);
}
/// <author>xiaolei</author>
/// <Name>StableStmtCases.TestBindColumnCn</Name>
/// <describe>Test stmt insert single line of chinese character into stable by column after column </describe>
/// <filename>StmtSTable.cs</filename>
/// <result>pass or failed </result>
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);
}
/// <author>xiaolei</author>
/// <Name>StableStmtCases.TestBindMultiLineCn</Name>
/// <describe>Test stmt insert single line of chinese character into stable by column after column </describe>
/// <filename>StmtSTable.cs</filename>
/// <result>pass or failed </result>
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
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<TDengineMeta> metas = new List<TDengineMeta>();
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);
}
}
}
}
}
using System;
using Test.UtilsTools;
using TDengineDriver;
using System.Collections.Generic;
namespace Test.UtilsTools.DataSource
{
public class DataSource
......@@ -23,7 +23,10 @@ namespace Test.UtilsTools.DataSource
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()
// 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);
......@@ -41,8 +44,59 @@ namespace Test.UtilsTools.DataSource
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<String> GetTagData()
{
List<String> tagData = new List<String>();
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<string> GetMultiBindStableRowData()
{
List<string> rowData = new List<String>();
List<string> 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;
public static TAOS_BIND[] getCNTags()
}
// 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);
......@@ -57,11 +111,32 @@ namespace Test.UtilsTools.DataSource
binds[9] = TaosBind.BindFloat(11.11F);
binds[10] = TaosBind.BindDouble(22.22D);
binds[11] = TaosBind.BindBinary("TDengine涛思数据");
binds[12] = TaosBind.BindNchar("涛思");
binds[12] = TaosBind.BindNchar("涛思数据taos");
return binds;
}
public static TAOS_BIND[] getNtableCNRow()
// Get the tag data within and string list
// Which will be retrieved as a string List
private static List<String> GetTagCnData()
{
List<String> tagData = new List<String>();
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);
......@@ -81,8 +156,40 @@ namespace Test.UtilsTools.DataSource
binds[14] = TaosBind.BindNil();
return binds;
}
//Get and list data that will be insert into table
public static List<String> GetNtableCNRowData()
{
var data = new List<string>{
"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<String> GetStableCNRowData()
{
List<String> columnData = GetNtableCNRowData();
List<String> tagData = GetTagCnData();
columnData.AddRange(tagData);
return columnData;
}
public static TAOS_BIND[] getNtableRow()
// 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);
......@@ -102,6 +209,31 @@ namespace Test.UtilsTools.DataSource
binds[14] = TaosBind.BindNil();
return binds;
}
// A List of data ,use as expectResData. The value is equal to getNtableRow()
public static List<String> GetNtableRowData()
{
var data = new List<string>{
"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];
......@@ -121,6 +253,35 @@ namespace Test.UtilsTools.DataSource
mBinds[13] = TaosMultiBind.MultiBindNchar(ncharArr);
return mBinds;
}
// A List of data ,use as expectResData. The value is equal to GetMultiBindCNArr()
public static List<string> GetMultiBindResData()
{
var rowData = new List<string>();
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];
......@@ -140,6 +301,62 @@ namespace Test.UtilsTools.DataSource
mBinds[13] = TaosMultiBind.MultiBindNchar(NcharArrCn);
return mBinds;
}
// A List of data ,use as expectResData. The value is equal to GetMultiBindCNArr()
public static List<string> GetMultiBindCNRowData()
{
var rowData = new List<string>();
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<String> GetMultiBindStableCNRowData()
{
List<String> columnData = new List<string>();
List<String> 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()
{
......@@ -158,7 +375,47 @@ namespace Test.UtilsTools.DataSource
{
TaosMultiBind.FreeTaosBind(mbinds);
}
//Get the TDengineMeta list from the ddl either normal table or stable
public static List<TDengineMeta> GetMetaFromDLL(string dllStr)
{
var expectResMeta = new List<TDengineMeta>();
//"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
using System;
using Test.UtilsTools;
using System.Collections.Generic;
using Xunit;
using TDengineDriver;
using Test.UtilsTools.ResultSet;
namespace Cases
{
public class FetchLengthCase
{
/// <author>xiaolei</author>
/// <Name>TestRetrieveBinary</Name>
/// <describe>TD-12103 C# connector fetch_row with binary data retrieving error</describe>
/// <filename>FetchLength.cs</filename>
/// <result>pass or failed </result>
[Fact(DisplayName = "Skip FetchLengthCase.TestRetrieveBinary()")]
public void TestRetrieveBinary()
{
IntPtr conn = UtilsTools.TDConnection();
var expectData = new List<string> { "log", "test", "db02", "db3" };
var expectMeta = new List<TDengineMeta>{
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<string> actualData = actualResult.GetResultData();
List<TDengineMeta> 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);
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
<NoWarn>CS1591;CS0168</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<DocumentationFile>..\doc\FunctionTest.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\TDengineDriver\TDengineDriver.csproj" />
</ItemGroup>
</Project>
using System;
using TDengineDriver;
using System.Runtime.InteropServices;
using System.Text;
using System.Collections.Generic;
namespace Test.UtilsTools.ResultSet
{
public class ResultSet
{
private List<TDengineMeta> resultMeta;
private List<String> resultData;
// private bool isValidResult = false;
public ResultSet(IntPtr res)
{
resultMeta = UtilsTools.GetResField(res);
resultData = UtilsTools.GetResData(res);
}
public ResultSet(List<TDengineMeta> metas, List<String> datas)
{
resultMeta = metas;
resultData = datas;
}
public List<String> GetResultData()
{
return resultData;
}
public List<TDengineMeta> GetResultMeta()
{
return resultMeta;
}
}
}
\ No newline at end of file
......@@ -2,81 +2,119 @@ 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 NtableSingleLine
public class NormalTableStmtCases
{
/// <author>xiaolei</author>
/// <Name>NtableSingleLine.Test</Name>
/// <describe>Test stmt insert sinle line data into normal table</describe>
/// <Name>NormalTableStmtCases.TestBindSingleLineCn</Name>
/// <describe>Test stmt insert single line of chinese character into normal table by column after column </describe>
/// <filename>StmtNormalTable.cs</filename>
/// <result>pass or failed </result>
public void Test(IntPtr conn, string tableName)
[Fact(DisplayName = "NormalTableStmtCases.TestBindSingleLineCn()")]
public void TestBindSingleLineCn()
{
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);
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<string> expectResData = DataSource.GetNtableCNRowData();
List<TDengineMeta> 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.BindParam(stmt, _valuesRow);
StmtUtilTools.AddBatch(stmt);
StmtUtilTools.StmtExecute(stmt);
StmtUtilTools.StmtClose(stmt);
DataSource.FreeTaosBind(valuesRow);
DataSource.FreeTaosBind(_valuesRow);
}
}
IntPtr res = UtilsTools.ExecuteQuery(conn, querySql);
ResultSet actualResult = new ResultSet(res);
List<TDengineMeta> actualResMeta = actualResult.GetResultMeta();
List<string> actualResData = actualResult.GetResultData();
public class NtableMutipleLine
// Assert retrieve data
for (int i = 0; i < actualResData.Count; i++)
{
/// <author>xiaolei</author>
/// <Name>NtableMutipleLine.Test</Name>
/// <describe>Test stmt insert multiple rows of data into normal table</describe>
/// <filename>StmtNormalTable.cs</filename>
/// <result>pass or failed </result>
public void Test(IntPtr conn, string tableName)
Assert.Equal(expectResData[i], actualResData[i]);
}
// Assert metadata
for (int i = 0; i < actualResMeta.Count; i++)
{
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);
Assert.Equal(expectResMeta[i].name, actualResMeta[i].name);
Assert.Equal(expectResMeta[i].type, actualResMeta[i].type);
Assert.Equal(expectResMeta[i].size, actualResMeta[i].size);
}
}
public class NtableColumnByColumn
{
/// <author>xiaolei</author>
/// <Name>NtableColumnByColumn.Test</Name>
/// <describe>Test stmt insert multiple rows of data into normal table by column after column </describe>
/// <Name>NormalTableStmtCases.TestBindColumnCn</Name>
/// <describe>Test stmt insert single line of chinese character into normal table by column after column </describe>
/// <filename>StmtNormalTable.cs</filename>
/// <result>pass or failed </result>
public void Test(IntPtr conn, string tableName)
[Fact(DisplayName = "NormalTableStmtCases.TestBindColumnCn()")]
public void TestBindColumnCn()
{
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 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<string> expectResData = DataSource.GetMultiBindCNRowData();
TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindCNArr();
List<TDengineMeta> expectResMeta = DataSource.GetMetaFromDLL(createTb);
IntPtr conn = UtilsTools.TDConnection();
UtilsTools.ExecuteUpdate(conn, dropSql);
UtilsTools.ExecuteUpdate(conn, createTb);
IntPtr stmt = StmtUtilTools.StmtInit(conn);
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);
......@@ -98,23 +136,133 @@ namespace Cases
DataSource.FreeTaosMBind(mbind);
string querySql = "select * from " + tableName;
IntPtr res = UtilsTools.ExecuteQuery(conn, querySql);
ResultSet actualResult = new ResultSet(res);
List<TDengineMeta> actualResMeta = actualResult.GetResultMeta();
List<string> 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);
}
}
public class NormalTableStmtCases
{
/// <author>xiaolei</author>
/// <Name>NormalTableStmtCases.TestBindSingleLineCn</Name>
/// <Name>NormalTableStmtCases.TestBindMultiLineCn</Name>
/// <describe>Test stmt insert single line of chinese character into normal table by column after column </describe>
/// <filename>StmtNormalTable.cs</filename>
/// <result>pass or failed </result>
public void TestBindSingleLineCn(IntPtr conn, string tableName)
[Fact(DisplayName = "NormalTableStmtCases.TestBindMultiLineCn()")]
public void TestBindMultiLineCn()
{
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();
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<string> expectResData = DataSource.GetMultiBindCNRowData();
List<TDengineMeta> 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<TDengineMeta> actualResMeta = actualResult.GetResultMeta();
List<string> 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);
}
}
/// <author>xiaolei</author>
/// <Name>NormalTableStmtCases.TestBindSingleLine</Name>
/// <describe>Test stmt insert sinle line data into normal table</describe>
/// <filename>StmtNormalTable.cs</filename>
/// <result>pass or failed </result>
[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<string> expectResData = DataSource.GetNtableRowData();
List<TDengineMeta> 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);
......@@ -124,31 +272,140 @@ namespace Cases
StmtUtilTools.StmtClose(stmt);
DataSource.FreeTaosBind(valuesRow);
IntPtr res = UtilsTools.ExecuteQuery(conn, querySql);
ResultSet actualResult = new ResultSet(res);
List<TDengineMeta> actualResMeta = actualResult.GetResultMeta();
List<string> 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);
}
}
/// <author>xiaolei</author>
/// <Name>NtableMutipleLine.TestBindMultiLine</Name>
/// <describe>Test stmt insert multiple rows of data into normal table</describe>
/// <filename>StmtNormalTable.cs</filename>
/// <result>pass or failed </result>
[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<string> expectResData = DataSource.GetMultiBindResData();
TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindArr();
List<TDengineMeta> 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);
UtilsTools.DisplayRes(res);
ResultSet actualResult = new ResultSet(res);
List<TDengineMeta> actualResMeta = actualResult.GetResultMeta();
List<string> 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);
}
}
/// <author>xiaolei</author>
/// <Name>NormalTableStmtCases.TestBindColumnCn</Name>
/// <describe>Test stmt insert single line of chinese character into normal table by column after column </describe>
/// <Name>NtableColumnByColumn.TestBindColumnCn</Name>
/// <describe>Test stmt insert multiple rows of data into normal table by column after column </describe>
/// <filename>StmtNormalTable.cs</filename>
/// <result>pass or failed </result>
public void TestBindColumnCn(IntPtr conn,string tableName)
[Fact(DisplayName = "NormalTableStmtCases.TestBindColumn()")]
public void TestBindColumn()
{
string tableName = "normal_tablestmt_cases_test_bind_column_cn";
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 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<string> expectResData = DataSource.GetMultiBindResData();
TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindArr();
List<TDengineMeta> expectResMeta = DataSource.GetMetaFromDLL(createTb);
IntPtr conn = UtilsTools.TDConnection();
UtilsTools.ExecuteUpdate(conn, dropSql);
UtilsTools.ExecuteUpdate(conn, createTb);
IntPtr stmt = StmtUtilTools.StmtInit(conn);
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);
......@@ -172,34 +429,27 @@ namespace Cases
string querySql = "select * from " + tableName;
IntPtr res = UtilsTools.ExecuteQuery(conn, querySql);
UtilsTools.DisplayRes(res);
}
/// <author>xiaolei</author>
/// <Name>NormalTableStmtCases.TestBindMultiLineCn</Name>
/// <describe>Test stmt insert single line of chinese character into normal table by column after column </describe>
/// <filename>StmtNormalTable.cs</filename>
/// <result>pass or failed </result>
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(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
ResultSet actualResult = new ResultSet(res);
UtilsTools.ExecuteUpdate(conn, createTb);
List<TDengineMeta> actualResMeta = actualResult.GetResultMeta();
List<string> actualResData = actualResult.GetResultData();
Assert.Equal(expectResMeta.Count, actualResMeta.Count);
Assert.Equal(expectResData.Count, actualResData.Count);
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);
// 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);
}
string querySql = "select * from " + tableName;
IntPtr res = UtilsTools.ExecuteQuery(conn, querySql);
UtilsTools.DisplayRes(res);
}
}
}
\ No newline at end of file
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
{
/// <author>xiaolei</author>
/// <Name>StableStmtCases.TestBindSingleLineCn</Name>
/// <describe>Test stmt insert single line of chinese character into stable by column after column </describe>
/// <filename>StmtSTable.cs</filename>
/// <result>pass or failed </result>
[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<TDengineMeta> expectResMeta = DataSource.GetMetaFromDLL(createSql);
List<String> 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<TDengineMeta> actualResMeta = actualResult.GetResultMeta();
List<string> 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);
}
}
/// <author>xiaolei</author>
/// <Name>StableStmtCases.TestBindColumnCn</Name>
/// <describe>Test stmt insert single line of chinese character into stable by column after column </describe>
/// <filename>StmtSTable.cs</filename>
/// <result>pass or failed </result>
[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<TDengineMeta> expectResMeta = DataSource.GetMetaFromDLL(createSql);
List<String> 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<TDengineMeta> actualResMeta = actualResult.GetResultMeta();
List<string> 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);
}
}
/// <author>xiaolei</author>
/// <Name>StableStmtCases.TestBindMultiLineCn</Name>
/// <describe>Test stmt insert single line of chinese character into stable by column after column </describe>
/// <filename>StmtSTable.cs</filename>
/// <result>pass or failed </result>
[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<TDengineMeta> expectResMeta = DataSource.GetMetaFromDLL(createSql);
List<String> 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<TDengineMeta> actualResMeta = actualResult.GetResultMeta();
List<string> 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);
}
}
/// <author>xiaolei</author>
/// <Name>StableStmtCases.TestBindMultiLine</Name>
/// <describe>Test stmt insert single line into stable by column after column </describe>
/// <filename>StmtSTable.cs</filename>
/// <result>pass or failed </result>
[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<TDengineMeta> expectResMeta = DataSource.GetMetaFromDLL(createSql);
List<String> 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<TDengineMeta> actualResMeta = actualResult.GetResultMeta();
List<string> 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);
}
}
/// <author>xiaolei</author>
/// <Name>StableStmtCases.TestBindColumn</Name>
/// <describe>Test stmt insert single line of chinese character into stable by column after column </describe>
/// <filename>StmtSTable.cs</filename>
/// <result>pass or failed </result>
[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<TDengineMeta> expectResMeta = DataSource.GetMetaFromDLL(createSql);
List<String> 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<TDengineMeta> actualResMeta = actualResult.GetResultMeta();
List<string> 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
using System;
using Test.UtilsTools;
using TDengineDriver;
using System.Collections.Generic;
using Xunit;
using Test.UtilsTools.ResultSet;
namespace Cases
{
public class FetchFieldCases
{
/// <author>xiaolei</author>
/// <Name>FetchFieldCases.TestFetchFieldJsonTag</Name>
/// <describe>test taos_fetch_fields(), check the meta data</describe>
/// <filename>TaosFeild.cs</filename>
/// <result>pass or failed </result>
[Fact(DisplayName = "FetchFieldCases.TestFetchFieldJsonTag()")]
public void TestFetchFieldJsonTag()
{
IntPtr conn = UtilsTools.TDConnection();
IntPtr _res = IntPtr.Zero;
string tableName = "fetchfeilds";
var expectResMeta = new List<TDengineMeta> {
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<String> { "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<TDengineMeta> 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);
}
}
}
}
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<TDengineMeta> metas = GetResField(res);
int fieldCount = metas.Count;
IntPtr rowdata;
// StringBuilder builder = new StringBuilder();
List<string> 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<List<string>> GetResultSet(IntPtr res)
{
List<List<string>> result = new List<List<string>>();
List<string> colName = new List<string>();
List<string> dataRaw = new List<string>();
if (!IsValidResult(res))
{
ExitProgram();
}
List<TDengineMeta> 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<TDengineMeta> GetResField(IntPtr res)
{
List<TDengineMeta> 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<String> GetResData(IntPtr res)
{
List<string> colName = new List<string>();
List<string> dataRaw = new List<string>();
if (!IsValidResult(res))
{
ExitProgram();
}
List<TDengineMeta> 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<string> QueryRes(IntPtr res, List<TDengineMeta> metas)
{
IntPtr rowdata;
long queryRows = 0;
List<string> dataRaw = new List<string>();
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;
}
}
}
......@@ -6,6 +6,11 @@ namespace TDengineDriver.Test
{
public class TestTDengineMeta
{
/// <author>xiaolei</author>
/// <Name>TestTDengineMeta.TestTypeNameBool</Name>
/// <describe>Unit test for oject TDengineDriver.TDengineMeta's bool meta info</describe>
/// <filename>TestTDengineMeta.cs</filename>
/// <result>pass or failed </result>
[Fact]
public void TestTypeNameBool()
{
......@@ -17,7 +22,11 @@ namespace TDengineDriver.Test
Assert.Equal(metaTypeName, typeName);
}
/// <author>xiaolei</author>
/// <Name>TestTDengineMeta.TestTypeNameTINYINT</Name>
/// <describe>Unit test for oject TDengineDriver.TDengineMeta's TinnyInt's meta info</describe>
/// <filename>TestTDengineMeta.cs</filename>
/// <result>pass or failed </result>
[Fact]
public void TestTypeNameTINYINT()
{
......@@ -29,6 +38,11 @@ namespace TDengineDriver.Test
Assert.Equal(metaTypeName, typeName);
}
/// <author>xiaolei</author>
/// <Name>TestTDengineMeta.TestTypeNameSMALLINT</Name>
/// <describe>Unit test for oject TDengineDriver.TDengineMeta's SMALLINT's meta info</describe>
/// <filename>TestTDengineMeta.cs</filename>
/// <result>pass or failed </result>
[Fact]
public void TestTypeNameSMALLINT()
{
......@@ -40,6 +54,11 @@ namespace TDengineDriver.Test
Assert.Equal(metaTypeName, typeName);
}
/// <author>xiaolei</author>
/// <Name>TestTDengineMeta.TestTypeNameINT</Name>
/// <describe>Unit test for oject TDengineDriver.TDengineMeta's INT's meta info</describe>
/// <filename>TestTDengineMeta.cs</filename>
/// <result>pass or failed </result>
[Fact]
public void TestTypeNameINT()
{
......@@ -51,6 +70,11 @@ namespace TDengineDriver.Test
Assert.Equal(metaTypeName, typeName);
}
/// <author>xiaolei</author>
/// <Name>TestTDengineMeta.TestTypeNameBIGINT</Name>
/// <describe>Unit test for oject TDengineDriver.TDengineMeta's BIGINT's meta info</describe>
/// <filename>TestTDengineMeta.cs</filename>
/// <result>pass or failed </result>
[Fact]
public void TestTypeNameBIGINT()
{
......@@ -62,6 +86,11 @@ namespace TDengineDriver.Test
Assert.Equal(metaTypeName, typeName);
}
/// <author>xiaolei</author>
/// <Name>TestTDengineMeta.TestTypeNameUTINYINT</Name>
/// <describe>Unit test for oject TDengineDriver.TDengineMeta's TINYINT UNSIGNED's meta info</describe>
/// <filename>TestTDengineMeta.cs</filename>
/// <result>pass or failed </result>
[Fact]
public void TestTypeNameUTINYINT()
{
......@@ -73,6 +102,11 @@ namespace TDengineDriver.Test
Assert.Equal(metaTypeName, typeName);
}
/// <author>xiaolei</author>
/// <Name>TestTDengineMeta.TestTypeNameUSMALLINT</Name>
/// <describe>Unit test for oject TDengineDriver.TDengineMeta's SMALLINT UNSIGNED's meta info</describe>
/// <filename>TestTDengineMeta.cs</filename>
/// <result>pass or failed </result>
[Fact]
public void TestTypeNameUSMALLINT()
{
......@@ -84,6 +118,11 @@ namespace TDengineDriver.Test
Assert.Equal(metaTypeName, typeName);
}
/// <author>xiaolei</author>
/// <Name>TestTDengineMeta.TestTypeNameUINT</Name>
/// <describe>Unit test for oject TDengineDriver.TDengineMeta's INT UNSIGNED's meta info</describe>
/// <filename>TestTDengineMeta.cs</filename>
/// <result>pass or failed </result>
[Fact]
public void TestTypeNameUINT()
{
......@@ -95,6 +134,11 @@ namespace TDengineDriver.Test
Assert.Equal(metaTypeName, typeName);
}
/// <author>xiaolei</author>
/// <Name>TestTDengineMeta.TestTypeNameUBIGINT</Name>
/// <describe>Unit test for oject TDengineDriver.TDengineMeta's BIGINT UNSIGNED's meta info</describe>
/// <filename>TestTDengineMeta.cs</filename>
/// <result>pass or failed </result>
[Fact]
public void TestTypeNameUBIGINT()
{
......@@ -106,7 +150,11 @@ namespace TDengineDriver.Test
Assert.Equal(metaTypeName, typeName);
}
/// <author>xiaolei</author>
/// <Name>TestTDengineMeta.TestTypeNameFLOAT</Name>
/// <describe>Unit test for oject TDengineDriver.TDengineMeta's FLOAT's meta info</describe>
/// <filename>TestTDengineMeta.cs</filename>
/// <result>pass or failed </result>
[Fact]
public void TestTypeNameFLOAT()
{
......@@ -118,6 +166,11 @@ namespace TDengineDriver.Test
Assert.Equal(metaTypeName, typeName);
}
/// <author>xiaolei</author>
/// <Name>TestTDengineMeta.TestTypeNameDOUBLE</Name>
/// <describe>Unit test for oject TDengineDriver.TDengineMeta's DOUBLE's meta info</describe>
/// <filename>TestTDengineMeta.cs</filename>
/// <result>pass or failed </result>
[Fact]
public void TestTypeNameDOUBLE()
{
......@@ -129,10 +182,15 @@ namespace TDengineDriver.Test
Assert.Equal(metaTypeName, typeName);
}
/// <author>xiaolei</author>
/// <Name>TestTDengineMeta.TestTypeNameSTRING</Name>
/// <describe>Unit test for oject TDengineDriver.TDengineMeta's BINARY's meta info</describe>
/// <filename>TestTDengineMeta.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTDengineMeta.TestTypeNameTIMESTAMP</Name>
/// <describe>Unit test for oject TDengineDriver.TDengineMeta's TIMESTAMP's meta info</describe>
/// <filename>TestTDengineMeta.cs</filename>
/// <result>pass or failed </result>
[Fact]
public void TestTypeNameTIMESTAMP()
{
......@@ -151,6 +214,11 @@ namespace TDengineDriver.Test
Assert.Equal(metaTypeName, typeName);
}
/// <author>xiaolei</author>
/// <Name>TestTDengineMeta.TestTypeNameNCHAR</Name>
/// <describe>Unit test for oject TDengineDriver.TDengineMeta's NCHAR's meta info</describe>
/// <filename>TestTDengineMeta.cs</filename>
/// <result>pass or failed </result>
[Fact]
public void TestTypeNameNCHAR()
{
......@@ -162,6 +230,11 @@ namespace TDengineDriver.Test
Assert.Equal(metaTypeName, typeName);
}
/// <author>xiaolei</author>
/// <Name>TestTDengineMeta.TestTypeNameUndefined</Name>
/// <describe>Unit test for oject TDengineDriver.TDengineMeta's undefine's meta info</describe>
/// <filename>TestTDengineMeta.cs</filename>
/// <result>pass or failed </result>
[Fact]
public void TestTypeNameUndefined()
{
......
......@@ -7,6 +7,11 @@ namespace TDengineDriver.Test
{
public class TestTaosBind
{
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindBoolTrue</Name>
/// <describe>Unit test for binding boolean true value using TAOS_BIND struct through stmt</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindBoolFalse</Name>
/// <describe>Unit test for binding boolean false value using TAOS_BIND struct through stmt</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindTinyIntZero</Name>
/// <describe>Unit test for binding tinny int zero value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindTinyIntPositive</Name>
/// <describe>Unit test for binding tinny int positive value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindTinyIntNegative</Name>
/// <describe>Unit test for binding tinny int negative value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindSmallIntNegative</Name>
/// <describe>Unit test for binding small int negative value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindSmallIntZero</Name>
/// <describe>Unit test for binding small int zero value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindSmallIntPositive</Name>
/// <describe>Unit test for binding small int positive value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindIntNegative</Name>
/// <describe>Unit test for binding small int positive value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindIntZero</Name>
/// <describe>Unit test for binding int zero value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindIntPositive</Name>
/// <describe>Unit test for binding int positive value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindBigIntNegative</Name>
/// <describe>Unit test for binding int negative value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindBigIntZero</Name>
/// <describe>Unit test for binding big int zero value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindBigIntPositive</Name>
/// <describe>Unit test for binding big int positive value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindBigIntPositive</Name>
/// <describe>Unit test for binding big int positive value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindUTinyPositive</Name>
/// <describe>Unit test for binding unsigned tinny int positive value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindUSmallIntZero</Name>
/// <describe>Unit test for binding unsigned small int zero value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindUSmallIntPositive</Name>
/// <describe>Unit test for binding unsigned small int positive value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindUIntZero</Name>
/// <describe>Unit test for binding unsigned int zero value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindUIntPositive</Name>
/// <describe>Unit test for binding unsigned int positive value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindUBigIntZero</Name>
/// <describe>Unit test for binding unsigned big int zero value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindUBigIntPositive</Name>
/// <describe>Unit test for binding unsigned big int positive value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindFloatNegative</Name>
/// <describe>Unit test for binding float negative value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindFloatNegative</Name>
/// <describe>Unit test for binding float zero value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindFloatPositive</Name>
/// <describe>Unit test for binding float positive value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindDoubleZero</Name>
/// <describe>Unit test for binding double zero value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindDoublePositive</Name>
/// <describe>Unit test for binding double positive value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindDoubleNegative</Name>
/// <describe>Unit test for binding double negative value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindBinaryEn</Name>
/// <describe>Unit test for binding binary character without CN character using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindBinaryCn</Name>
/// <describe>Unit test for binding binary character with CN character using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindBinaryCnAndEn</Name>
/// <describe>Unit test for binding binary characters with CN and other characters using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindNcharEn</Name>
/// <describe>Unit test for binding nchar characters without cn using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindNcharCn</Name>
/// <describe>Unit test for binding nchar characters with cn using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindNcharCnAndEn</Name>
/// <describe>Unit test for binding nchar with cn characters and other characters using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindNil</Name>
/// <describe>Unit test for binding null value using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindTimestampNegative</Name>
/// <describe>Unit test for binding negative timestamp using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindTimestampZero</Name>
/// <describe>Unit test for binding zero timestamp using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
}
/// <author>xiaolei</author>
/// <Name>TestTaosBind.TestBindTimestampPositive</Name>
/// <describe>Unit test for binding positive timestamp using TAOS_BIND struct through stmt.</describe>
/// <filename>TestTaosBind.cs</filename>
/// <result>pass or failed </result>
[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);
......
......@@ -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
......
......@@ -11,3 +11,5 @@ stmt/bin/
stmt/obj/
taosdemo/bin/
taosdemo/obj/
jsonTag/bin/
jsonTag/obj/
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)
{
......
......@@ -3,7 +3,7 @@ using TDengineDriver;
using System.Runtime.InteropServices;
using System.Text;
using System.Collections.Generic;
namespace Test.UtilsTools
namespace Utils
{
public class UtilsTools
{
......@@ -189,103 +189,6 @@ namespace Test.UtilsTools
TDengine.FreeResult(res); Console.WriteLine("");
}
public static List<List<string>> GetResultSet(IntPtr res)
{
List<List<string>> result = new List<List<string>>();
List<string> colName = new List<string>();
List<string> dataRaw = new List<string>();
long queryRows = 0;
if (!IsValidResult(res))
{
ExitProgram();
}
int fieldCount = TDengine.FieldCount(res);
List<TDengineMeta> 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,23 +217,6 @@ namespace Test.UtilsTools
}
}
}
public static List<TDengineMeta> getField(IntPtr res)
{
List<TDengineMeta> 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();
......
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\..\TDengineDriver\TDengineDriver.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<NoWarn>CS1591</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<DocumentationFile>..\doc\FunctionTest.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TDengine.Connector" Version="1.0.3" />
</ItemGroup>
</Project>
......@@ -53,7 +53,7 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.0</version>
<version>2.17.1</version>
</dependency>
<!-- proxool -->
<dependency>
......
......@@ -88,7 +88,7 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.0</version>
<version>2.17.1</version>
</dependency>
<!-- junit -->
<dependency>
......
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 \'\<Spent.+s\>\' 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()
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()
......@@ -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
......
......@@ -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()
......
......@@ -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'")
......
###################################################################
# 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 <wenzhouwww>: [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())
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册