未验证 提交 8713f96d 编写于 作者: H Huo Linhe 提交者: GitHub

[TD-3204]<fix>: support usigned integer types for C# connector (#5808)

Added unsigned integer types and change taosdemo insert and select queries for these types.

taos define | taos sql | c#
--- | --- | ---
UTINYINT | TINYINT UNSIGNED | `byte`
USMALLINT | SMALLINT UNSIGNED | `ushort`
UINT | INT UNSIGNED | `uint`
UBIGINT | BIGINT UNSIGNED | `ulong`
TINYINT | TINYINT | `sbyte`

Note: also change the tinyint value type to C# `sbyte`(the right signed one byte type) in this pr.
上级 e70ddee6
...@@ -31,7 +31,11 @@ namespace TDengineDriver ...@@ -31,7 +31,11 @@ namespace TDengineDriver
TSDB_DATA_TYPE_DOUBLE = 7, // 8 bytes TSDB_DATA_TYPE_DOUBLE = 7, // 8 bytes
TSDB_DATA_TYPE_BINARY = 8, // string TSDB_DATA_TYPE_BINARY = 8, // string
TSDB_DATA_TYPE_TIMESTAMP = 9,// 8 bytes TSDB_DATA_TYPE_TIMESTAMP = 9,// 8 bytes
TSDB_DATA_TYPE_NCHAR = 10 // unicode string TSDB_DATA_TYPE_NCHAR = 10, // unicode string
TSDB_DATA_TYPE_UTINYINT = 11,// 1 byte
TSDB_DATA_TYPE_USMALLINT= 12,// 2 bytes
TSDB_DATA_TYPE_UINT = 13, // 4 bytes
TSDB_DATA_TYPE_UBIGINT= 14 // 8 bytes
} }
enum TDengineInitOption enum TDengineInitOption
...@@ -53,15 +57,23 @@ namespace TDengineDriver ...@@ -53,15 +57,23 @@ namespace TDengineDriver
switch ((TDengineDataType)type) switch ((TDengineDataType)type)
{ {
case TDengineDataType.TSDB_DATA_TYPE_BOOL: case TDengineDataType.TSDB_DATA_TYPE_BOOL:
return "BOOLEAN"; return "BOOL";
case TDengineDataType.TSDB_DATA_TYPE_TINYINT: case TDengineDataType.TSDB_DATA_TYPE_TINYINT:
return "BYTE"; return "TINYINT";
case TDengineDataType.TSDB_DATA_TYPE_SMALLINT: case TDengineDataType.TSDB_DATA_TYPE_SMALLINT:
return "SHORT"; return "SMALLINT";
case TDengineDataType.TSDB_DATA_TYPE_INT: case TDengineDataType.TSDB_DATA_TYPE_INT:
return "INT"; return "INT";
case TDengineDataType.TSDB_DATA_TYPE_BIGINT: case TDengineDataType.TSDB_DATA_TYPE_BIGINT:
return "LONG"; return "BIGINT";
case TDengineDataType.TSDB_DATA_TYPE_UTINYINT:
return "TINYINT UNSIGNED";
case TDengineDataType.TSDB_DATA_TYPE_USMALLINT:
return "SMALLINT UNSIGNED";
case TDengineDataType.TSDB_DATA_TYPE_UINT:
return "INT UNSIGNED";
case TDengineDataType.TSDB_DATA_TYPE_UBIGINT:
return "BIGINT UNSIGNED";
case TDengineDataType.TSDB_DATA_TYPE_FLOAT: case TDengineDataType.TSDB_DATA_TYPE_FLOAT:
return "FLOAT"; return "FLOAT";
case TDengineDataType.TSDB_DATA_TYPE_DOUBLE: case TDengineDataType.TSDB_DATA_TYPE_DOUBLE:
......
...@@ -63,7 +63,7 @@ namespace TDengineDriver ...@@ -63,7 +63,7 @@ namespace TDengineDriver
static void HelpPrint(string arg, string desc) static void HelpPrint(string arg, string desc)
{ {
string indent = " "; string indent = " ";
Console.WriteLine("{0}{1}", indent, arg.PadRight(25)+desc); Console.WriteLine("{0}{1}", indent, arg.PadRight(25) + desc);
} }
static void PrintHelp(String[] argv) static void PrintHelp(String[] argv)
...@@ -142,33 +142,33 @@ namespace TDengineDriver ...@@ -142,33 +142,33 @@ namespace TDengineDriver
verbose = this.GetArgumentAsFlag(argv, "-v", true); verbose = this.GetArgumentAsFlag(argv, "-v", true);
debug = this.GetArgumentAsFlag(argv, "-g", true); debug = this.GetArgumentAsFlag(argv, "-g", true);
VerbosePrint ("###################################################################\n"); VerbosePrint("###################################################################\n");
VerbosePrintFormat ("# Server IP: {0}\n", host); VerbosePrintFormat("# Server IP: {0}\n", host);
VerbosePrintFormat ("# User: {0}\n", user); VerbosePrintFormat("# User: {0}\n", user);
VerbosePrintFormat ("# Password: {0}\n", password); VerbosePrintFormat("# Password: {0}\n", password);
VerbosePrintFormat ("# Number of Columns per record: {0}\n", colsPerRecord); VerbosePrintFormat("# Number of Columns per record: {0}\n", colsPerRecord);
VerbosePrintFormat ("# Number of Threads: {0}\n", numOfThreads); VerbosePrintFormat("# Number of Threads: {0}\n", numOfThreads);
VerbosePrintFormat ("# Number of Tables: {0}\n", numOfTables); VerbosePrintFormat("# Number of Tables: {0}\n", numOfTables);
VerbosePrintFormat ("# Number of records per Table: {0}\n", recordsPerTable); VerbosePrintFormat("# Number of records per Table: {0}\n", recordsPerTable);
VerbosePrintFormat ("# Records/Request: {0}\n", recordsPerRequest); VerbosePrintFormat("# Records/Request: {0}\n", recordsPerRequest);
VerbosePrintFormat ("# Database name: {0}\n", dbName); VerbosePrintFormat("# Database name: {0}\n", dbName);
VerbosePrintFormat ("# Replica: {0}\n", replica); VerbosePrintFormat("# Replica: {0}\n", replica);
VerbosePrintFormat ("# Use STable: {0}\n", useStable); VerbosePrintFormat("# Use STable: {0}\n", useStable);
VerbosePrintFormat ("# Table prefix: {0}\n", tablePrefix); VerbosePrintFormat("# Table prefix: {0}\n", tablePrefix);
if (useStable == true) if (useStable == true)
{ {
VerbosePrintFormat("# STable prefix: {0}\n", stablePrefix); VerbosePrintFormat("# STable prefix: {0}\n", stablePrefix);
} }
VerbosePrintFormat ("# Data order: {0}\n", order); VerbosePrintFormat("# Data order: {0}\n", order);
VerbosePrintFormat ("# Data out of order rate: {0}\n", rateOfOutorder); VerbosePrintFormat("# Data out of order rate: {0}\n", rateOfOutorder);
VerbosePrintFormat ("# Delete method: {0}\n", methodOfDelete); VerbosePrintFormat("# Delete method: {0}\n", methodOfDelete);
VerbosePrintFormat ("# Query command: {0}\n", query); VerbosePrintFormat("# Query command: {0}\n", query);
VerbosePrintFormat ("# Query Mode: {0}\n", queryMode); VerbosePrintFormat("# Query Mode: {0}\n", queryMode);
VerbosePrintFormat ("# Insert Only: {0}\n", isInsertOnly); VerbosePrintFormat("# Insert Only: {0}\n", isInsertOnly);
VerbosePrintFormat ("# Verbose output {0}\n", verbose); VerbosePrintFormat("# Verbose output {0}\n", verbose);
VerbosePrintFormat ("# Test time: {0}\n", DateTime.Now.ToString("h:mm:ss tt")); VerbosePrintFormat("# Test time: {0}\n", DateTime.Now.ToString("h:mm:ss tt"));
VerbosePrint ("###################################################################\n"); VerbosePrint("###################################################################\n");
if (skipReadKey == false) if (skipReadKey == false)
{ {
...@@ -406,7 +406,7 @@ namespace TDengineDriver ...@@ -406,7 +406,7 @@ namespace TDengineDriver
sql.Clear(); sql.Clear();
sql.Append("CREATE TABLE IF NOT EXISTS "). sql.Append("CREATE TABLE IF NOT EXISTS ").
Append(this.dbName).Append(".").Append(this.stablePrefix). Append(this.dbName).Append(".").Append(this.stablePrefix).
Append("(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 float, v7 double, v8 binary(10), v9 nchar(10)) tags(t1 int)"); Append("(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 float, v7 double, v8 binary(10), v9 nchar(10), v10 tinyint unsigned, v11 smallint unsigned, v12 int unsigned, v13 bigint unsigned) tags(t1 int)");
IntPtr res = TDengine.Query(this.conn, sql.ToString()); IntPtr res = TDengine.Query(this.conn, sql.ToString());
if (res != IntPtr.Zero) if (res != IntPtr.Zero)
{ {
...@@ -523,7 +523,7 @@ namespace TDengineDriver ...@@ -523,7 +523,7 @@ namespace TDengineDriver
int offset = IntPtr.Size * fields; int offset = IntPtr.Size * fields;
IntPtr data = Marshal.ReadIntPtr(rowdata, offset); IntPtr data = Marshal.ReadIntPtr(rowdata, offset);
builder.Append("---"); builder.Append(" | ");
if (data == IntPtr.Zero) if (data == IntPtr.Zero)
{ {
...@@ -538,7 +538,7 @@ namespace TDengineDriver ...@@ -538,7 +538,7 @@ namespace TDengineDriver
builder.Append(v1); builder.Append(v1);
break; break;
case TDengineDataType.TSDB_DATA_TYPE_TINYINT: case TDengineDataType.TSDB_DATA_TYPE_TINYINT:
byte v2 = Marshal.ReadByte(data); sbyte v2 = (sbyte)Marshal.ReadByte(data);
builder.Append(v2); builder.Append(v2);
break; break;
case TDengineDataType.TSDB_DATA_TYPE_SMALLINT: case TDengineDataType.TSDB_DATA_TYPE_SMALLINT:
...@@ -573,9 +573,25 @@ namespace TDengineDriver ...@@ -573,9 +573,25 @@ namespace TDengineDriver
string v10 = Marshal.PtrToStringAnsi(data); string v10 = Marshal.PtrToStringAnsi(data);
builder.Append(v10); builder.Append(v10);
break; break;
case TDengineDataType.TSDB_DATA_TYPE_UTINYINT:
byte v11 = Marshal.ReadByte(data);
builder.Append(v11);
break;
case TDengineDataType.TSDB_DATA_TYPE_USMALLINT:
ushort v12 = (ushort)Marshal.ReadInt16(data);
builder.Append(v12);
break;
case TDengineDataType.TSDB_DATA_TYPE_UINT:
uint v13 = (uint)Marshal.ReadInt32(data);
builder.Append(v13);
break;
case TDengineDataType.TSDB_DATA_TYPE_UBIGINT:
ulong v14 = (ulong)Marshal.ReadInt64(data);
builder.Append(v14);
break;
} }
} }
builder.Append("---"); builder.Append(" | ");
VerbosePrint(builder.ToString() + "\n"); VerbosePrint(builder.ToString() + "\n");
builder.Clear(); builder.Clear();
...@@ -642,8 +658,8 @@ namespace TDengineDriver ...@@ -642,8 +658,8 @@ namespace TDengineDriver
tester.ExecuteQuery(); tester.ExecuteQuery();
watch.Stop(); watch.Stop();
elapsedMs = watch.Elapsed.TotalMilliseconds; elapsedMs = watch.Elapsed.TotalMilliseconds;
Console.WriteLine("C# taosdemo: Spent {0} seconds to query {1} records.\n", Console.WriteLine("C# taosdemo: Spent {0} seconds to query {1} records.\n",
elapsedMs/1000, elapsedMs / 1000,
tester.recordsPerTable * tester.numOfTables tester.recordsPerTable * tester.numOfTables
); );
} }
...@@ -714,7 +730,7 @@ namespace TDengineDriver ...@@ -714,7 +730,7 @@ namespace TDengineDriver
long baseTimestamp = 1609430400000; // 2021/01/01 0:0:0 long baseTimestamp = 1609430400000; // 2021/01/01 0:0:0
VerbosePrintFormat("beginTime is {0} + {1}h:{2}m:{3}s\n", baseTimestamp, h, m, s); VerbosePrintFormat("beginTime is {0} + {1}h:{2}m:{3}s\n", baseTimestamp, h, m, s);
long beginTimestamp = baseTimestamp + ((h*60 + m) * 60 + s) * 1000; long beginTimestamp = baseTimestamp + ((h * 60 + m) * 60 + s) * 1000;
Random random = new Random(); Random random = new Random();
long rowsInserted = 0; long rowsInserted = 0;
...@@ -755,11 +771,16 @@ namespace TDengineDriver ...@@ -755,11 +771,16 @@ namespace TDengineDriver
sql.Append("(") sql.Append("(")
.Append(writeTimeStamp) .Append(writeTimeStamp)
.Append(", 1, 2, 3,") .Append(", 1, -2, -3,")
.Append(i + batch) .Append(i + batch - 127)
.Append(", 5, 6, 7, 'abc', 'def')"); .Append(", -5, -6, -7, 'abc', 'def', 254, 65534,")
.Append(4294967294 - (uint)i - (uint)batch)
.Append(",")
.Append(18446744073709551614 - (ulong)i - (ulong)batch)
.Append(")");
} }
VerbosePrint(sql.ToString() + "\n");
IntPtr res = TDengine.Query(this.conn, sql.ToString()); IntPtr res = TDengine.Query(this.conn, sql.ToString());
if (res == IntPtr.Zero) if (res == IntPtr.Zero)
{ {
...@@ -837,7 +858,7 @@ namespace TDengineDriver ...@@ -837,7 +858,7 @@ namespace TDengineDriver
} }
else else
{ {
sql = sql.Append("(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 float, v7 double, v8 binary(10), v9 nchar(10))"); sql = sql.Append("(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 float, v7 double, v8 binary(10), v9 nchar(10), v10 tinyint unsigned, v11 smallint unsigned, v12 int unsigned, v13 bigint unsigned)");
} }
IntPtr res = TDengine.Query(this.conn, sql.ToString()); IntPtr res = TDengine.Query(this.conn, sql.ToString());
if (res != IntPtr.Zero) if (res != IntPtr.Zero)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册