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

[TD-10547]<feature>:c# support json tag (#9069)

* [TD-10547]<feature>:c# support json tag

* fix conflict

* fix conflict  2nd

* ci re run

* fix ci

* ci test

* ci test3rd

* split git ingnore file into prject direction

* fix format JsonTag.cs
上级 49466e4d
......@@ -86,7 +86,6 @@ tests/script/api/batchprepare
tests/script/api/stmt
tests/script/api/stmtBatchTest
tests/script/api/stmtTest
# Emacs
# -*- mode: gitignore; -*-
*~
......
src/TDengineDriver/bin/
src/TDengineDriver/obj/
src/test/Cases/bin/
src/test/Cases/obj/
src/test/XUnitTest/bin/
src/test/XUnitTest/obj/
......@@ -35,7 +35,8 @@ namespace TDengineDriver
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
TSDB_DATA_TYPE_UBIGINT = 14, // 8 bytes
TSDB_DATA_TYPE_JSONTAG = 15 //4096 bytes
}
public enum TDengineInitOption
......@@ -46,7 +47,6 @@ namespace TDengineDriver
TDDB_OPTION_CONFIGDIR = 3,
TDDB_OPTION_SHELL_ACTIVITY_TIMER = 4
}
enum TaosField
{
STRUCT_SIZE = 68,
......@@ -92,6 +92,8 @@ namespace TDengineDriver
return "TIMESTAMP";
case TDengineDataType.TSDB_DATA_TYPE_NCHAR:
return "NCHAR";
case TDengineDataType.TSDB_DATA_TYPE_JSONTAG:
return "JSON";
default:
return "undefine";
}
......@@ -204,6 +206,7 @@ namespace TDengineDriver
metas.Add(meta);
}
return metas;
}
......
using System;
using Test.UtilsTools;
namespace Cases
{
public class JsonTagTest
{
public void Test(IntPtr conn)
{
Console.WriteLine("STEP 1 prepare data & validate json string===== ");
UtilsTools.ExecuteQuery(conn, "create table if not exists jsons1(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)");
UtilsTools.ExecuteQuery(conn, "insert into jsons1_1 using jsons1 tags('{\"tag1\":\"fff\",\"tag2\":5, \"tag3\":true}') values(1591060618000, 1, false, 'json1', '涛思数据') (1591060608000, 23, true, '涛思数据', 'json')");
UtilsTools.ExecuteQuery(conn, "insert into jsons1_2 using jsons1 tags('{\"tag1\":5,\"tag2\":\"beijing\"}') values (1591060628000, 2, true, 'json2', 'sss')");
UtilsTools.ExecuteQuery(conn, "insert into jsons1_3 using jsons1 tags('{\"tag1\":false,\"tag2\":\"beijing\"}') values (1591060668000, 3, false, 'json3', 'efwe')");
UtilsTools.ExecuteQuery(conn, "insert into jsons1_4 using jsons1 tags('{\"tag1\":null,\"tag2\":\"shanghai\",\"tag3\":\"hello\"}') values (1591060728000, 4, true, 'json4', '323sd')");
UtilsTools.ExecuteQuery(conn, "insert into jsons1_5 using jsons1 tags('{\"tag1\":1.232, \"tag2\":null}') values(1591060928000, 1, false, '涛思数据', 'ewe')");
UtilsTools.ExecuteQuery(conn, "insert into jsons1_6 using jsons1 tags('{\"tag1\":11,\"tag2\":\"\",\"tag2\":null}') values(1591061628000, 11, false, '涛思数据','')");
UtilsTools.ExecuteQuery(conn, "insert into jsons1_7 using jsons1 tags('{\"tag1\":\"涛思数据\",\"tag2\":\"\",\"tag3\":null}') values(1591062628000, 2, NULL, '涛思数据', 'dws')");
Console.WriteLine("");
Console.WriteLine("test duplicate key using the first one. elimate empty key======== ");
UtilsTools.ExecuteQuery(conn, "CREATE TABLE if not exists jsons1_8 using jsons1 tags('{\"tag1\":null, \"tag1\":true, \"tag1\":45, \"1tag$\":2, \" \":90}')");
Console.WriteLine("");
Console.WriteLine("test empty json string, save as jtag is NULL========== ");
UtilsTools.ExecuteQuery(conn, "insert into jsons1_9 using jsons1 tags('\t') values (1591062328000, 24, NULL, '涛思数据', '2sdw')");
UtilsTools.ExecuteQuery(conn, "CREATE TABLE if not exists jsons1_10 using jsons1 tags('')");
UtilsTools.ExecuteQuery(conn, "CREATE TABLE if not exists jsons1_11 using jsons1 tags(' ')");
UtilsTools.ExecuteQuery(conn, "CREATE TABLE if not exists jsons1_12 using jsons1 tags('{}')");
UtilsTools.ExecuteQuery(conn, "CREATE TABLE if not exists jsons1_13 using jsons1 tags('null')");
Console.WriteLine("");
Console.WriteLine("test invalidate json==================== ");
UtilsTools.ExecuteErrorQuery(conn, "CREATE TABLE if not exists jsons1_14 using jsons1 tags('\"efwewf\"')");
UtilsTools.ExecuteErrorQuery(conn, "CREATE TABLE if not exists jsons1_14 using jsons1 tags('3333')");
UtilsTools.ExecuteErrorQuery(conn, "CREATE TABLE if not exists jsons1_14 using jsons1 tags('33.33')");
UtilsTools.ExecuteErrorQuery(conn, "CREATE TABLE if not exists jsons1_14 using jsons1 tags('false')");
UtilsTools.ExecuteErrorQuery(conn, "CREATE TABLE if not exists jsons1_14 using jsons1 tags('[1,true]')");
UtilsTools.ExecuteErrorQuery(conn, "CREATE TABLE if not exists jsons1_14 using jsons1 tags('{222}')");
UtilsTools.ExecuteErrorQuery(conn, "CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"fe\"}')");
Console.WriteLine("");
Console.WriteLine("test invalidate json key, key must can be printed assic char========== ");
UtilsTools.ExecuteErrorQuery(conn, "CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"tag1\":[1,true]}')");
UtilsTools.ExecuteErrorQuery(conn, "CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"tag1\":{}}')");
UtilsTools.ExecuteErrorQuery(conn, "CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"。loc\":\"fff\"}')");
UtilsTools.ExecuteErrorQuery(conn, "CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"\":\"fff\"}')");
UtilsTools.ExecuteErrorQuery(conn, "CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"\t\":\"fff\"}')");
UtilsTools.ExecuteErrorQuery(conn, "CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"试试\":\"fff\"}')");
Console.WriteLine("");
Console.WriteLine("STEP 2 alter table json tag============");
UtilsTools.ExecuteErrorQuery(conn, "ALTER STABLE jsons1 add tag tag2 nchar(20)");
UtilsTools.ExecuteErrorQuery(conn, "ALTER STABLE jsons1 drop tag jtag");
UtilsTools.ExecuteErrorQuery(conn, "ALTER TABLE jsons1_1 SET TAG jtag=4");
UtilsTools.ExecuteQuery(conn, "ALTER TABLE jsons1_1 SET TAG jtag='{\"tag1\":\"femail\",\"tag2\":35,\"tag3\":true}'");
Console.WriteLine("");
Console.WriteLine("STEP 3 query table============");
Console.WriteLine("test error syntax============");
UtilsTools.ExecuteErrorQuery(conn, "select * from jsons1 where jtag->tag1='beijing'");
UtilsTools.ExecuteErrorQuery(conn, "select * from jsons1 where jtag->'location'");
UtilsTools.ExecuteErrorQuery(conn, "select * from jsons1 where jtag->''");
UtilsTools.ExecuteErrorQuery(conn, "select * from jsons1 where jtag->''=9");
UtilsTools.ExecuteErrorQuery(conn, "select -> from jsons1");
UtilsTools.ExecuteErrorQuery(conn, "select * from jsons1 where contains");
UtilsTools.ExecuteErrorQuery(conn, "select * from jsons1 where jtag->");
UtilsTools.ExecuteErrorQuery(conn, "select jtag->location from jsons1");
UtilsTools.ExecuteErrorQuery(conn, "select jtag contains location from jsons1");
UtilsTools.ExecuteErrorQuery(conn, "select * from jsons1 where jtag contains location");
UtilsTools.ExecuteErrorQuery(conn, "select * from jsons1 where jtag contains''");
UtilsTools.ExecuteErrorQuery(conn, "select * from jsons1 where jtag contains 'location'='beijing'");
Console.WriteLine("");
Console.WriteLine("test select normal column===========");
IntPtr res = IntPtr.Zero;
res = UtilsTools.ExecuteQuery(conn, "select dataint from jsons1");
UtilsTools.DisplayRes(res);
Console.WriteLine("test select json tag===========");
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select jtag from jsons1");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select jtag from jsons1 where jtag is null");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select jtag from jsons1 where jtag is not null");
UtilsTools.DisplayRes(res);
Console.WriteLine("test #line 41===========");
res = UtilsTools.ExecuteQuery(conn, "select jtag from jsons1_8");
UtilsTools.DisplayRes(res);
Console.WriteLine("test #line 72===========");
res = UtilsTools.ExecuteQuery(conn, "select jtag from jsons1_1");
UtilsTools.DisplayRes(res);
Console.WriteLine("test jtag is NULL===========");
res = UtilsTools.ExecuteQuery(conn, "select jtag from jsons1_9");
UtilsTools.DisplayRes(res);
Console.WriteLine("test select json tag->'key', value is string ===========");
res = UtilsTools.ExecuteQuery(conn, "select jtag->'tag1' from jsons1_1");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select jtag->'tag2' from jsons1_6");
UtilsTools.DisplayRes(res);
Console.WriteLine("test select json tag->'key', value is int===========");
res = UtilsTools.ExecuteQuery(conn, "select jtag->'tag2' from jsons1_1");
UtilsTools.DisplayRes(res);
Console.WriteLine("test select json tag->'key', value is bool===========");
res = UtilsTools.ExecuteQuery(conn, "select jtag->'tag3' from jsons1_1");
UtilsTools.DisplayRes(res);
Console.WriteLine("test select json tag->'key', value is null===========");
res = UtilsTools.ExecuteQuery(conn, "select jtag->'tag1' from jsons1_4");
UtilsTools.DisplayRes(res);
Console.WriteLine("test select json tag->'key', value is double===========");
res = UtilsTools.ExecuteQuery(conn, "select jtag->'tag1' from jsons1_5");
UtilsTools.DisplayRes(res);
Console.WriteLine("test select json tag->'key', key is not exist===========");
res = UtilsTools.ExecuteQuery(conn, "select jtag->'tag10' from jsons1_4");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select jtag->'tag1' from jsons1");
UtilsTools.DisplayRes(res);
Console.WriteLine("test header name===========");
res = UtilsTools.ExecuteQuery(conn, "select jtag->'tag1' from jsons1");
UtilsTools.DisplayRes(res);
Console.WriteLine("test where with json tag===========");
UtilsTools.ExecuteErrorQuery(conn, "select * from jsons1_1 where jtag is not null");
UtilsTools.ExecuteErrorQuery(conn, "select * from jsons1 where jtag='{\"tag1\":11,\"tag2\":\"\"}'");
UtilsTools.ExecuteErrorQuery(conn, "select * from jsons1 where jtag->'tag1'={}");
Console.WriteLine("where json value is string===========");
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag2'='beijing'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select dataint,tbname,jtag->'tag1',jtag from jsons1 where jtag->'tag2'='beijing'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'='beijing'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'='涛思数据'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag2'>'beijing'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag2'>='beijing'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag2'<'beijing'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag2'<='beijing'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag2'!='beijing'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag2'=''");
UtilsTools.DisplayRes(res);
Console.WriteLine("where json value is int===========");
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'=5");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'=10");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'<54");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'<=11");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'>4");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'>=5");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'!=5");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'!=55");
UtilsTools.DisplayRes(res);
Console.WriteLine("where json value is double===========");
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'=1.232");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'<1.232");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'<=1.232");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'>1.23");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'>=1.232");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'!=1.232");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'!=3.232");
UtilsTools.DisplayRes(res);
UtilsTools.ExecuteErrorQuery(conn, "select * from jsons1 where jtag->'tag1'/0=3");
UtilsTools.ExecuteErrorQuery(conn, "select * from jsons1 where jtag->'tag1'/5=1");
Console.WriteLine("where json value is bool===========");
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'=true");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'=false");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'!=false");
UtilsTools.DisplayRes(res);
UtilsTools.ExecuteErrorQuery(conn, "select * from jsons1 where jtag->'tag1'>false");
Console.WriteLine("where json value is null===========");
Console.WriteLine("only json suport =null. This synatx will change later.===========");
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'=null");
UtilsTools.DisplayRes(res);
Console.WriteLine("where json is null===========");
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag is null");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag is not null");
UtilsTools.DisplayRes(res);
Console.WriteLine("where json key is null===========");
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag_no_exist'=3");
UtilsTools.DisplayRes(res);
Console.WriteLine("where json value is not exist===========");
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1' is null");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag4' is null");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag3' is not null");
UtilsTools.DisplayRes(res);
Console.WriteLine("test contains===========");
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag contains 'tag1'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag contains 'tag3'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag contains 'tag_no_exist'");
UtilsTools.DisplayRes(res);
Console.WriteLine("test json tag in where condition with and/or===========");
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='beijing'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'=false or jtag->'tag2'='beijing'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='shanghai'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='shanghai'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'=13 or jtag->'tag2'>35");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'=13 or jtag->'tag2'>35");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1' is not null and jtag contains 'tag3'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1'='femail' and jtag contains 'tag3'");
UtilsTools.DisplayRes(res);
Console.WriteLine("test with tbname/normal column===========");
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where tbname = 'jsons1_1'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3' and dataint=3");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3' and dataint=23");
UtilsTools.DisplayRes(res);
Console.WriteLine("test where condition like===========");
res = UtilsTools.ExecuteQuery(conn, "select *,tbname from jsons1 where jtag->'tag2' like 'bei%'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select *,tbname from jsons1 where jtag->'tag1' like 'fe%' and jtag->'tag2' is not null");
UtilsTools.DisplayRes(res);
Console.WriteLine("test where condition in no support in===========");
UtilsTools.ExecuteErrorQuery(conn, "select * from jsons1 where jtag->'tag1' in ('beijing')");
Console.WriteLine("test where condition match===========");
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1' match 'ma'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1' match 'ma$'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag2' match 'jing$'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select * from jsons1 where jtag->'tag1' match '收到'");
UtilsTools.DisplayRes(res);
Console.WriteLine("test distinct===========");
UtilsTools.ExecuteQuery(conn, "insert into jsons1_14 using jsons1 tags('{\"tag1\":\"涛思数据\",\"tag2\":\"\",\"tag3\":null}') values(1591062628000, 2, NULL, '涛思数据', 'dws')");
res = UtilsTools.ExecuteQuery(conn, "select distinct jtag->'tag1' from jsons1");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select distinct jtag from jsons1");
UtilsTools.DisplayRes(res);
Console.WriteLine("test dumplicate key with normal colomn===========");
UtilsTools.ExecuteQuery(conn, "INSERT INTO jsons1_15 using jsons1 tags('{\"tbname\":\"tt\",\"databool\":true,\"datastr\":\"涛思数据\"}') values(1591060828000, 4, false, 'jjsf', \"你就会\")");
res = UtilsTools.ExecuteQuery(conn, "select *,tbname,jtag from jsons1 where jtag->'datastr' match '涛思数据' and datastr match 'js'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select tbname,jtag->'tbname' from jsons1 where jtag->'tbname'='tt' and tbname='jsons1_14'");
UtilsTools.DisplayRes(res);
Console.WriteLine("test join===========");
UtilsTools.ExecuteQuery(conn, "create table if not exists jsons2(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)");
UtilsTools.ExecuteQuery(conn, "insert into jsons2_1 using jsons2 tags('{\"tag1\":\"fff\",\"tag2\":5, \"tag3\":true}') values(1591060618000, 2, false, 'json2', '涛思数据2')");
UtilsTools.ExecuteQuery(conn, "insert into jsons2_2 using jsons2 tags('{\"tag1\":5,\"tag2\":null}') values (1591060628000, 2, true, 'json2', 'sss')");
UtilsTools.ExecuteQuery(conn, "create table if not exists jsons3(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)");
UtilsTools.ExecuteQuery(conn, "insert into jsons3_1 using jsons3 tags('{\"tag1\":\"fff\",\"tag2\":5, \"tag3\":true}') values(1591060618000, 3, false, 'json3', '涛思数据3')");
UtilsTools.ExecuteQuery(conn, "insert into jsons3_2 using jsons3 tags('{\"tag1\":5,\"tag2\":\"beijing\"}') values (1591060638000, 2, true, 'json3', 'sss')");
res = UtilsTools.ExecuteQuery(conn, "select 'sss',33,a.jtag->'tag3' from jsons2 a,jsons3 b where a.ts=b.ts and a.jtag->'tag1'=b.jtag->'tag1'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select 'sss',33,a.jtag->'tag3' from jsons2 a,jsons3 b where a.ts=b.ts and a.jtag->'tag1'=b.jtag->'tag1'");
UtilsTools.DisplayRes(res);
Console.WriteLine("test group by & order by json tag===========");
res = UtilsTools.ExecuteQuery(conn, "select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag1' desc");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag1' asc");
UtilsTools.DisplayRes(res);
Console.WriteLine("test stddev with group by json tag===========");
res = UtilsTools.ExecuteQuery(conn, "select stddev(dataint) from jsons1 group by jtag->'tag1'");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select stddev(dataint) from jsons1 group by jsons1.jtag->'tag1'");
UtilsTools.DisplayRes(res);
Console.WriteLine("test top/bottom with group by json tag===========");
res = UtilsTools.ExecuteQuery(conn, "select top(dataint,100) from jsons1 group by jtag->'tag1'");
UtilsTools.DisplayRes(res);
Console.WriteLine("subquery with json tag===========");
res = UtilsTools.ExecuteQuery(conn, "select * from (select jtag, dataint from jsons1)");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select jtag->'tag1' from (select jtag->'tag1', dataint from jsons1)");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select jtag->'tag1' from (select jtag->'tag1', dataint from jsons1)");
UtilsTools.DisplayRes(res);
res = UtilsTools.ExecuteQuery(conn, "select ts,tbname,jtag->'tag1' from (select jtag->'tag1',tbname,ts from jsons1 order by ts)");
UtilsTools.DisplayRes(res);
Console.WriteLine("");
}
}
}
\ No newline at end of file
......@@ -48,12 +48,17 @@ namespace Cases.EntryPoint
Console.WriteLine("====================fetchfeilds===================");
FetchFields fetchFields = new FetchFields();
fetchFields.Test(conn, "fetchfeilds");
fetchFields.Test(conn,"fetchfeilds");
UtilsTools.ExecuteQuery(conn, "drop database if exists csharp");
Console.WriteLine("===================JsonTagTest====================");
JsonTagTest jsonTagTest = new JsonTagTest();
jsonTagTest.Test(conn);
// UtilsTools.ExecuteQuery(conn, "drop database if exists csharp");
UtilsTools.CloseConnection(conn);
UtilsTools.ExitProgram();
}
}
}
......@@ -10,8 +10,8 @@ namespace Cases
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(id int);";
String insertSql = "insert into " + tableName + "_t1 using " + tableName + " tags(1) values(1637064040000,true,1,2,3,4,5,6,7,8,9,10,'XI','XII')";
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);
......@@ -35,3 +35,5 @@ namespace Cases
}
}
}
......@@ -39,6 +39,28 @@ namespace Test.UtilsTools
}
return res;
}
public static IntPtr ExecuteErrorQuery(IntPtr conn, String sql)
{
IntPtr res = TDengine.Query(conn, sql);
if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0))
{
Console.Write(sql.ToString() + " failure, ");
if (res != IntPtr.Zero)
{
Console.Write("reason: " + TDengine.Error(res));
}
Console.WriteLine("");
}
else
{
Console.WriteLine(sql.ToString() + " success");
}
return res;
}
public static void DisplayRes(IntPtr res)
{
long queryRows = 0;
......@@ -120,6 +142,10 @@ namespace Test.UtilsTools
string v10 = Marshal.PtrToStringAnsi(data);
builder.Append(v10);
break;
case TDengineDataType.TSDB_DATA_TYPE_JSONTAG:
string v11 = Marshal.PtrToStringAnsi(data);
builder.Append(v11);
break;
}
}
builder.Append("---");
......
C#checker/bin/
C#checker/obj/
TDengineTest/bin/
TDengineTest/obj/
schemaless/bin/
schemaless/obj/
stmt/TDengineDriver.cs
stmt/TaosBind.cs
stmt/TaosMultiBind.cs
stmt/bin/
stmt/obj/
taosdemo/bin/
taosdemo/obj/
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册