未验证 提交 cd98f236 编写于 作者: X xiaolei li 提交者: GitHub

[TD-14470]<hotfix>:csharp supplement schemaless and add example to ci (#11217)

上级 806068f3
......@@ -19,8 +19,10 @@ namespace AsyncQueryExample
SubscribeSample subscribeSample = new SubscribeSample();
subscribeSample.RunSubscribeWithCallback(conn, "subscribe_with_callback");
subscribeSample.RunSubscribeWithoutCallback(conn, "subscribe_without_callback");
UtilsTools.CloseConnection(conn);
SchemalessSample schemalessSample = new SchemalessSample();
schemalessSample.RunSchemaless();
}
}
}
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Text;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Collections;
using Sample.UtilsTools;
using TDengineDriver;
namespace Example
{
class SchemalessSample
{
private IntPtr conn = IntPtr.Zero;
private string dbName = "csharp_schemaless_example";
public void RunSchemaless()
{
string[] lines = {
"stg,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000",
"stg,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833641000000"
};
string[] jsonStr = {
"{"
+"\"metric\": \"stb0_0\","
+"\"timestamp\": 1626006833,"
+"\"value\": 10,"
+"\"tags\": {"
+" \"t1\": true,"
+"\"t2\": false,"
+"\"t3\": 10,"
+"\"t4\": \"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>\""
+"}"
+"}"
};
StringBuilder querySql = new StringBuilder();
Console.WriteLine(querySql.ToString());
this.conn = UtilsTools.TDConnection(this.dbName);
schemalessInsert(lines, 2, (int)TDengineSchemalessProtocol.TSDB_SML_LINE_PROTOCOL, (int)TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_NANO_SECONDS);
querySql.Append("select * from ").Append(this.dbName).Append(".").Append("stg");
UtilsTools.DisplayRes(UtilsTools.ExecuteQuery(this.conn, querySql.ToString()));
schemalessInsert(jsonStr, 1, (int)TDengineSchemalessProtocol.TSDB_SML_JSON_PROTOCOL, (int)TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_SECONDS);
querySql.Clear();
querySql.Append("select * from ").Append(this.dbName).Append(".").Append("stb0_0");
UtilsTools.DisplayRes(UtilsTools.ExecuteQuery(this.conn, querySql.ToString()));
querySql.Clear();
querySql.Append("drop database if exists ").Append(this.dbName);
UtilsTools.ExecuteUpdate(this.conn, querySql.ToString());
UtilsTools.CloseConnection(this.conn);
}
public void schemalessInsert(string[] sqlstr, int lineCnt, int protocol, int precision)
{
IntPtr res = TDengine.SchemalessInsert(this.conn, sqlstr, lineCnt, protocol, precision);
if (TDengine.ErrorNo(res) != 0)
{
Console.WriteLine("schemaless_insert failed:{0}", TDengine.Error(res));
Console.WriteLine("line string:{0}", sqlstr);
Console.WriteLine("");
System.Environment.Exit(0);
}
else
{
Console.WriteLine("else");
Console.WriteLine("schemaless insert success:{0}", TDengine.ErrorNo(res));
}
}
}
}
......@@ -15,16 +15,18 @@ namespace Sample.UtilsTools
static short port = 0;
static string globalDbName = "csharp_example_db";
//get a TDengine connection
public static IntPtr TDConnection()
public static IntPtr TDConnection(string dbName = "csharp_example_db")
{
TDengine.Options((int)TDengineInitOption.TSDB_OPTION_CONFIGDIR, GetConfigPath());
TDengine.Options((int)TDengineInitOption.TSDB_OPTION_SHELL_ACTIVITY_TIMER, "60");
TDengine.Init();
IntPtr conn = TDengine.Connect(ip, user, password, db, port);
UtilsTools.ExecuteUpdate(conn, $"drop database if exists {globalDbName}");
UtilsTools.ExecuteUpdate(conn, $"create database if not exists {globalDbName} keep 3650");
UtilsTools.ExecuteUpdate(conn, $"use {globalDbName}");
UtilsTools.ExecuteUpdate(conn, $"drop database if exists {dbName}");
UtilsTools.ExecuteUpdate(conn, $"create database if not exists {dbName} keep 3650");
UtilsTools.ExecuteUpdate(conn, $"use {dbName}");
return conn;
}
//get taos.cfg file based on different os
......@@ -199,7 +201,7 @@ namespace Sample.UtilsTools
int fieldCount = meta.Count;
while ((taosRow = TDengine.FetchRows(res)) != IntPtr.Zero)
{
dataRaw.AddRange(FetchRow(taosRow,res));
dataRaw.AddRange(FetchRow(taosRow, res));
}
if (TDengine.ErrorNo(res) != 0)
{
......@@ -293,7 +295,7 @@ namespace Sample.UtilsTools
case TDengineDataType.TSDB_DATA_TYPE_JSONTAG:
string v16 = Marshal.PtrToStringUTF8(data, colLengthArr[i]);
dataRaw.Add(v16);
break;
break;
default:
dataRaw.Add("nonsupport data type");
break;
......
......@@ -47,6 +47,24 @@ namespace TDengineDriver
TSDB_OPTION_CONFIGDIR = 3,
TSDB_OPTION_SHELL_ACTIVITY_TIMER = 4
}
public enum TDengineSchemalessProtocol
{
TSDB_SML_UNKNOWN_PROTOCOL = 0,
TSDB_SML_LINE_PROTOCOL = 1,
TSDB_SML_TELNET_PROTOCOL = 2,
TSDB_SML_JSON_PROTOCOL = 3
}
public enum TDengineSchemalessPrecision
{
TSDB_SML_TIMESTAMP_NOT_CONFIGURED = 0,
TSDB_SML_TIMESTAMP_HOURS = 1,
TSDB_SML_TIMESTAMP_MINUTES = 2,
TSDB_SML_TIMESTAMP_SECONDS = 3,
TSDB_SML_TIMESTAMP_MILLI_SECONDS = 4,
TSDB_SML_TIMESTAMP_MICRO_SECONDS = 5,
TSDB_SML_TIMESTAMP_NANO_SECONDS = 6
}
enum TaosField
{
STRUCT_SIZE = 68,
......@@ -268,7 +286,9 @@ namespace TDengineDriver
[DllImport("taos", EntryPoint = "taos_result_precision", CallingConvention = CallingConvention.Cdecl)]
static extern public int ResultPrecision(IntPtr taos);
//schemaless API
[DllImport("taos", SetLastError = true, EntryPoint = "taos_schemaless_insert", CallingConvention = CallingConvention.Cdecl)]
static extern public IntPtr SchemalessInsert(IntPtr taos, string[] lines, int numLines, int protocol, int precision);
//stmt APIs:
/// <summary>
......
......@@ -4,7 +4,7 @@
<TargetFrameworks>net5;netstandard2.1;</TargetFrameworks>
<PackageId>TDengine.Connector</PackageId>
<PackageIcon>logo.jpg</PackageIcon>
<Version>1.0.5</Version>
<Version>1.0.6</Version>
<Authors>taosdata</Authors>
<Company>www.taosdata.com</Company>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
......
......@@ -19,8 +19,13 @@ cd ../../
WKC=`pwd`
cd ${WKC}/src/connector/C#
dotnet test
# run example under Driver
cd ${WKC}/src/connector/C#/examples
dotnet run
#dotnet run --project src/test/Cases/Cases.csproj
# run example with neuget package
cd ${WKC}/tests/examples/C#
dotnet run --project C#checker/C#checker.csproj
dotnet run --project TDengineTest/TDengineTest.csproj
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册