提交 30ac5c18 编写于 作者: haoranc's avatar haoranc

[TD-6677]<test>: add Selection function tests

上级 ed4e0033
......@@ -89,11 +89,13 @@ class TDTestCase:
tdSql.checkData(0, 0, None)
tdSql.execute("CREATE TABLE if not exists jsons2_6 using jsons2 tags('{\"nv\":null,\"tea\":true,\"\":false,\"\":123,\"tea\":false}')")
tdSql.query("select jtag2 from jsons2_6")
tdSql.checkData(0, 0, "{\"tea\":true}")
tdSql.error("CREATE TABLE if not exists jsons2_7 using jsons2 tags('{\"nv\":null,\"tea\":123,\"\":false,\"\":123,\"tea\":false}')")
tdSql.checkData(0, 0, "{\"nv\":null,\"tea\":true}")
tdSql.execute("CREATE TABLE if not exists jsons2_7 using jsons2 tags('{\"test7\":\"\"}')")
tdSql.query("select jtag2 from jsons2_7")
tdSql.checkData(0, 0, "{\"test7\":\"\"}")
tdSql.execute("CREATE TABLE if not exists jsons2_8 using jsons2 tags('{\"nv\":null,\"tea\":123,\"\":false,\"\":123,\"tea\":false}')")
tdSql.query("select jtag2 from jsons2_8")
tdSql.checkData(0, 0, "{\"nv\":null,\"tea\":123}")
print("==============step2 alter json table==")
tdLog.info("alter stable add tag")
......@@ -144,30 +146,30 @@ class TDTestCase:
tdSql.query("select jtag from jsons1_1")
tdSql.checkRows(1)
tdSql.query("select * from jsons1 where jtag?'sex' or jtag?'num'")
tdSql.query("select * from jsons1 where jtag contains 'sex' or jtag contains 'num'")
tdSql.checkRows(5)
tdSql.query("select * from jsons1 where jtag?'sex' and jtag?'num'")
tdSql.query("select * from jsons1 where jtag contains 'sex' and jtag contains 'num'")
tdSql.checkRows(0)
tdSql.query("select jtag->'sex' from jsons1 where jtag?'sex' or jtag?'num'")
tdSql.checkData(0, 0, "femail")
tdSql.query("select jtag->'sex' from jsons1 where jtag contains 'sex' or jtag contains 'num'")
tdSql.checkData(0, 0, "\"femail\"")
tdSql.checkRows(3)
tdSql.query("select *,tbname from jsons1 where jtag->'location'='beijing'")
tdSql.checkRows(3)
tdSql.query("select *,tbname from jsons1 where jtag->'num'=5 or jtag?'sex'")
tdSql.query("select *,tbname from jsons1 where jtag->'num'=5 or jtag contains 'sex'")
tdSql.checkRows(4)
# test with tbname
tdSql.query("select * from jsons1 where tbname = 'jsons1_1'")
tdSql.checkRows(3)
tdSql.query("select * from jsons1 where tbname = 'jsons1_1' or jtag?'num'")
tdSql.query("select * from jsons1 where tbname = 'jsons1_1' or jtag contains 'num'")
tdSql.checkRows(5)
tdSql.query("select * from jsons1 where tbname = 'jsons1_1' and jtag?'num'")
tdSql.query("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'num'")
tdSql.checkRows(0)
tdSql.query("select * from jsons1 where tbname = 'jsons1_1' or jtag->'num'=5")
......@@ -189,19 +191,20 @@ class TDTestCase:
tdSql.query("select *,tbname from jsons1 where (jtag->'location' like 'shanghai%' or jtag->'num'=34) and jtag->'class'=55")
tdSql.checkRows(0)
tdSql.error("select * from jsons1 where jtag->'num' like '5%'")
tdSql.query("select * from jsons1 where jtag->'num' like '5%'")
tdSql.checkRows(0)
# test where condition in
tdSql.query("select * from jsons1 where jtag->'location' in ('beijing')")
tdSql.checkRows(3)
# # test where condition in
# tdSql.query("select * from jsons1 where jtag->'location' in ('beijing')")
# tdSql.checkRows(3)
tdSql.query("select * from jsons1 where jtag->'num' in (5,34)")
tdSql.checkRows(2)
# tdSql.query("select * from jsons1 where jtag->'num' in (5,34)")
# tdSql.checkRows(2)
tdSql.error("select * from jsons1 where jtag->'num' in ('5',34)")
# tdSql.error("select * from jsons1 where jtag->'num' in ('5',34)")
tdSql.query("select * from jsons1 where jtag->'location' in ('beijing') and jtag->'class'=55")
tdSql.checkRows(1)
# tdSql.query("select * from jsons1 where jtag->'location' in ('beijing') and jtag->'class'=55")
# tdSql.checkRows(1)
# test where condition match
tdSql.query("select * from jsons1 where jtag->'location' match 'jin$'")
......@@ -213,7 +216,8 @@ class TDTestCase:
tdSql.query("select * from jsons1 where datastr match 'json' and jtag->'location' match 'jin'")
tdSql.checkRows(3)
tdSql.error("select * from jsons1 where jtag->'num' match '5'")
tdSql.query("select * from jsons1 where jtag->'num' match '5'")
tdSql.checkRows(0)
# test json string parse
tdSql.error("CREATE TABLE if not exists jsons1_5 using jsons1 tags('efwewf')")
......@@ -231,7 +235,7 @@ class TDTestCase:
tdSql.query("select jtag from jsons1_8")
tdSql.checkData(0, 0, None)
tdSql.execute("CREATE TABLE if not exists jsons1_9 using jsons1 tags('{\"\":4, \"time\":null}')")
tdSql.execute("CREATE TABLE if not exists jsons1_9 using jsons1 tags('{\"\":4,\"time\":null}')")
tdSql.query("select jtag from jsons1_9")
tdSql.checkData(0, 0, None)
......@@ -266,7 +270,8 @@ class TDTestCase:
tdSql.query("select * from jsons1 where jtag->'location'='null'")
tdSql.checkRows(0)
tdSql.error("select * from jsons1 where jtag->'num'='null'")
tdSql.query("select * from jsons1 where jtag->'num'=null")
tdSql.checkRows(0)
# test distinct
tdSql.query("select distinct jtag from jsons1")
......@@ -293,18 +298,28 @@ class TDTestCase:
tdSql.query("select tbname,jtag->'tbname' from jsons1 where jtag->'tbname'='tt'")
tdSql.checkRows(1)
# tdSql.query("select * from jsons1 where jtag->'num' is not null or jtag?'class' and jtag?'databool'")
# tdSql.checkRows(0)
# test filter : and /or / in/ like
tdSql.query("select * from jsons1 where jtag->'num' is not null or jtag contains 'class' and jtag contains 'databool'")
tdSql.checkRows(2)
tdSql.query("select * from jsons1 where jtag->'num' is not null and jtag contains 'class' or jtag contains 'databool'")
tdSql.checkRows(1)
tdSql.checkData(0, 1, 4)
# tdSql.query("select * from jsons1 where jtag->'num' is not null or jtag?'class' and jtag?'databool' and jtag->'k1' match '中' or jtag->'location' in ('beijing') and jtag->'location' like 'bei%'")
tdSql.query("select * from jsons1 where jtag->'num' is not null or jtag contains 'class' and jtag contains 'databool' and jtag->'k1' match '中' and jtag->'location' like 'bei%'")
tdSql.checkRows(2)
# tdSql.query("select * from jsons1 where datastr like '你就会' and ( jtag->'num' is not null or jtag?'class' and jtag?'databool' )")
tdSql.query("select * from jsons1 where datastr like '你就会' and ( jtag->'num' is not null or jtag contains 'tbname' and jtag contains 'databool' )")
tdSql.checkRows(1)
tdSql.checkData(0, 1, 4)
tdSql.error("select * from jsons1 where datastr like '你就会' and jtag->'num' is not null or jtag contains 'class' and jtag contains 'databool'")
tdSql.error("select * from jsons1 where datastr like '你就会' or jtag->'num' is not null or jtag?'class' and jtag?'databool' and jtag->'k1' match '中' or jtag->'location' in ('beijing') and jtag->'location' like 'bei%' ")
# tdSql.query("select * from jsons1 where datastr like '你就会' and (jtag->'num' is not null or jtag?'class' and jtag?'databool' and jtag->'k1' match '中' or jtag->'location' in ('beijing') and jtag->'location' like 'bei%' )")
# tdSql.checkRows(0)
tdSql.error("select * from jsons1 where datastr like '你就会' or jtag->'num' is not null or jtag contains 'class' and jtag contains 'databool' and jtag->'k1' match '中' or jtag->'location' in ('beijing') and jtag->'location' like 'bei%' ")
tdSql.query("select * from jsons1 where datastr like '你就会' and (jtag->'num' is not null or jtag contains 'class' and jtag contains 'databool' and jtag->'k1' match '中' and jtag->'location' like 'bei%' )")
tdSql.checkRows(0)
tdSql.error("select *,tbname,jtag from jsons1 where dataBool=true")
......@@ -327,34 +342,236 @@ class TDTestCase:
tdSql.checkRows(1)
tdSql.error("select jtag3->k1 from jsons3 ")
tdSql.error("select jtag3 from jsons3 where jtag3->'k1'")
tdSql.error("select jtag3 from jsons3 where jtag3?'k1'=true")
tdSql.error("select jtag3?'k1' from jsons3;")
tdSql.error("select jtag3?'k1'=true from jsons3;")
tdSql.error("select jtag3 from jsons3 where jtag3 contains 'k1'=true")
tdSql.error("select jtag3 contains 'k1' from jsons3;")
tdSql.error("select jtag3 contains 'k1'=true from jsons3;")
tdSql.error("select jtag3->'k1'=true from jsons3;")
tdSql.error("insert into jsons3_5 using jsons3 tags('{\"t\":true,\"t123\":789,\"k1\":1,\"s\":null}') values(now, 5, true, 'test')")
tdSql.execute("insert into jsons3_5 using jsons3 tags('{\"t\":true,\"t123\":012,\"k1\":null,\"s\":null}') values(now, 5, true, 'test')")
tdSql.execute("insert into jsons3_5 using jsons3 tags('{\"t\":true,\"t123\":789,\"k1\":123,\"s\":null}') values(now, 5, true, 'test')")
tdSql.execute("insert into jsons3_5 using jsons3 tags('{\"t\":true,\"t123\":012,\"k2\":null,\"s\":null}') values(now+1s, 5, true, 'test')")
tdSql.query("select jtag3 from jsons3_5")
tdSql.checkData(0, 0, '{\"t\":true,\"t123\":789,\"k1\":123,\"s\":null}')
tdSql.execute("insert into jsons3_6 using jsons3 tags('{\"t\":true,\"t123\":789,\"k1\":false,\"s\":null}') values(now, 5, true, 'test')")
# tdSql.execute("select distinct jtag3 from jsons3 where jtag3->'t123'=12 or jtag3?'k1'")
# tdSql.checkRows(3)
tdSql.query("select jtag3 from jsons3 where jtag3->'t123'=12 or jtag3 contains 'k1'")
tdSql.checkRows(4)
tdSql.query("select distinct jtag3 from jsons3 where jtag3->'t123'=12 or jtag3 contains 'k1'")
tdSql.checkRows(4)
tdSql.execute("INSERT INTO jsons1_14 using jsons1 tags('{\"tbname\":\"tt\",\"location\":\"tianjing\",\"dataStr\":\"是是是\"}') values(now,5, \"你就会\")")
# tdSql.execute("select ts,dataint3,jtag->tbname from jsons1 where dataint>=1 and jtag->'location' in ('tianjing','123') and jtag?'tbname'")
# tdSql.checkRows(1)
# tdSql.checkData(0, 2, 'tt')
tdSql.query("select ts,jtag->'tbname',tbname from jsons1 where dataint>=1 and jtag contains 'tbname'")
tdSql.checkRows(2)
tdSql.checkData(0, 1, '\"tt\"')
tdSql.query("select ts,jtag->'tbname',jtag->'location',tbname from jsons1 where dataint between 1 and 5 and jtag->'location'='tianjing'")
tdSql.checkRows(1)
tdSql.checkData(0, 3, 'jsons1_14')
tdSql.query("select ts,jtag3->'tbname', jtag3->'str1',tbname from jsons3 where jtag3->'t123' between 456 and 789 and jtag3->'str1' like '11%' ")
tdSql.checkRows(2)
for i in range(1):
if tdSql.queryResult[i][1] == 'jsons3_3':
tdSql.checkData(i, 2, 111)
# query normal column and tag column
tdSql.query("select jtag3->'',dataint3 from jsons3")
tdSql.checkRows(5)
for i in range(4):
if tdSql.queryResult[i][1] == 4:
tdSql.checkData(i, 0, None)
tdSql.query("select tbname,dataint3,jtag3->'k1' from jsons3;")
tdSql.checkRows(5)
for i in range(4):
if tdSql.queryResult[i][1] == 4:
tdSql.checkData(i, 2, 'true')
# Select_exprs is SQL function -Aggregation function , tests includes group by and order by
tdSql.query("select avg(dataInt),count(dataint),sum(dataint) from jsons1 group by jtag->'location' order by jtag->'location';")
tdSql.checkData(2, 3, '\"tianjing\"')
tdSql.checkRows(3)
for i in range(2):
if tdSql.queryResult[i][3] == 'beijing':
tdSql.checkData(i, 0, 1)
tdSql.checkData(i, 1, 3)
tdSql.error("select avg(dataInt) as 123 ,count(dataint),sum(dataint) from jsons1 group by jtag->'location' order by 123")
tdSql.error("select avg(dataInt) as avgdata ,count(dataint),sum(dataint) from jsons1 group by jtag->'location' order by avgdata ;")
tdSql.query("select avg(dataInt),count(dataint),sum(dataint) from jsons1 group by jtag->'location' order by ts;")
tdSql.checkRows(3)
tdSql.error("select avg(dataInt),count(dataint),sum(dataint) from jsons1 group by jtag->'age' order by tbname;")
#notice,it should return error ****
tdSql.error("select avg(dataInt),count(dataint),sum(dataint) from jsons1 group by jtag->'age' order by jtag->'num' ;")
tdSql.query("select avg(dataInt),count(dataint),sum(dataint) from jsons1 group by jtag->'age' order by jtag->'age' ;")
tdSql.checkRows(2)
tdSql.error("select avg(dataInt) from jsons1 group by jtag->'location' order by dataInt;")
tdSql.error("select avg(dataInt),tbname from jsons1 group by jtag->'location' order by tbname;")
tdSql.execute("CREATE TABLE if not exists jsons1_15 using jsons1 tags('{\"tbname\":\"tt\",\"location\":\"beijing\"}')")
tdSql.execute("insert into jsons1_15 values(now+1s, 2, 'json1')")
tdSql.error("select twa(dataint) from jsons1 group by jtag->'location' order by jtag->'location';")
tdSql.error("select irate(dataint) from jsons1 where jtag->'location' in ('beijing','tianjing') or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.query(" select stddev(dataint) from jsons1 group by jtag->'location';")
tdSql.checkRows(3)
tdSql.query(" select stddev(dataint) from jsons1 where jtag->'location'='beijing';")
tdSql.checkRows(1)
tdSql.error(" select LEASTSQUARES(dataint,1,2) from jsons1_1 where jtag->'location' ='beijing' ;")
# Select_exprs is SQL function -Selection function
tdSql.query(" select min(dataint),jtag from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing' or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.checkRows(1)
tdSql.checkData(0, 0, 1)
tdSql.query(" select max(dataint),jtag from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing'or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.checkRows(1)
tdSql.checkData(0, 0, 12)
tdSql.query(" select first(*) from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing'or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.checkRows(1)
tdSql.query(" select last(*) from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing'or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.checkRows(1)
tdSql.error(" select last(*),jtag from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing'or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.query(" select last_row(*) from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing'or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.checkRows(1)
tdSql.query(" select apercentile(dataint,0) from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing'or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.checkRows(1)
tdSql.query(" select apercentile(dataint,50) from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing'or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.checkRows(1)
tdSql.query(" select apercentile(dataint,90) from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing'or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.checkRows(1)
tdSql.query(" select apercentile(dataint,100) from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing'or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.checkRows(1)
tdSql.query(" select apercentile(dataint,0,'t-digest') from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing'or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.checkRows(1)
tdSql.query(" select apercentile(dataint,50,'t-digest') from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing'or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.checkRows(1)
tdSql.query(" select apercentile(dataint,100,'t-digest') from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing'or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.checkRows(1)
tdSql.query("select top(dataint,1) from jsons1 group by jtag->'location';")
tdSql.query("select tbname,top(dataint,1) from jsons1 group by jtag->'location' order by jtag->'location' asc;")
tdSql.query("select tbname,top(dataint,1) from jsons1 group by jtag->'location' order by jtag->'location' desc;")
tdSql.query("select top(dataint,1) from jsons1 group by jtag->'location' order by ts desc;")
tdSql.query("select top(dataint,1) from jsons1 group by jtag->'location' order by ts asc;")
tdSql.query("select top(dataint,100) from jsons1 group by jtag->'location';")
tdSql.query("select bottom(dataint,1) from jsons1 group by jtag->'location';")
tdSql.query("select bottom(dataint,100) from jsons1 group by jtag->'location';")
tdSql.execute("create table if not exists jsons_interp(ts timestamp, dataInt int, dataBool bool, datafloat float, datadouble double,dataStr nchar(50)) tags(jtag json)")
tdSql.execute("insert into jsons_interp_1 using jsons_interp tags('{\"nv\":null,\"tea\":true,\"rate\":456,\"tea\":false}') values ('2021-07-25 02:19:54.119',2,'true',0.9,0.1,'123')")
tdSql.execute("insert into jsons_interp_1 values ('2021-07-25 02:19:54.219',3,'true',-4.8,-5.5,'123') ")
tdSql.execute("insert into jsons_interp_2 using jsons_interp tags('{\"nv\":null,\"tea\":true,\"level\":\"123456\",\"rate\":123,\"tea\":false}') values ('2021-07-25 02:19:54.319',4,'true',0.9,0.1,'123')")
tdSql.execute("insert into jsons_interp_2 values ('2021-07-25 02:19:54.419',5,'true',-5.1,1.3,'123') ")
tdSql.query("select interp(dataint) as itd from jsons_interp where (jtag->'rate'=123 or jtag->'rate'=456) and ts >= '2021-07-25 02:19:53.19' and ts<= '2021-07-25 02:19:54.519' every(100a) group by tbname order by ts desc ;")
tdSql.checkRows(4)
tdSql.checkData(0,1,3)
tdSql.checkData(2,1,5)
# query child table
tdSql.query("select interp(dataint) as itd from jsons_interp where (jtag->'rate'=123 or jtag->'rate'=456) and ts >= '2021-07-25 02:19:53.19' and ts<= '2021-07-25 02:19:54.519' every(100a) group by tbname order by tbname asc;")
tdSql.checkRows(4)
tdSql.checkData(0,1,2)
tdSql.checkData(2,1,4)
# Select_exprs is SQL function -Calculation function
tdSql.error(" select diff(dataint) from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing'or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.error(" select Derivative(dataint) from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing'or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.query(" select SPREAD(dataint) from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing'or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.checkData(0, 0, 11)
tdSql.query(" select ceil(dataint) from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing'or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.query(" select floor(dataint) from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing'or jtag contains 'num' or jtag->'age'=35 ;")
tdSql.query(" select round(dataint) from jsons1 where jtag->'location'= 'beijing' or jtag->'location'= 'tianjing'or jtag contains 'num' or jtag->'age'=35 ;")
#need insert new data --data type is double or float and tests ceil floor round .
tdSql.execute("create table if not exists jsons7(ts timestamp, dataInt int, dataBool bool, datafloat float, datadouble double,dataStr nchar(50)) tags(jtag json)")
tdSql.execute("insert into jsons7_1 using jsons7 tags('{\"nv\":null,\"tea\":true,\"\":false,\" \":123,\"tea\":false}') values (now+2s,2,'true',0.9,0.1,'123')")
tdSql.execute("insert into jsons7_1 using jsons7 tags('{\"nv\":null,\"tea\":true,\"tea\":false}') values (now+3s,2,'true',0.9,0.1,'123')")
tdSql.query("select * from jsons7 where jtag->'tea'=0 ;")
tdSql.checkRows(0)
tdSql.query("select * from jsons7 where jtag->'tea'=3;")
# tdSql.checkRows(0)
tdSql.execute("insert into jsons7_1 values (now+1s,3,'true',-4.8,-5.5,'123') ")
tdSql.execute("insert into jsons7_1 values (now+2s,4,'true',1.9998,2.00001,'123') ")
tdSql.execute("insert into jsons7_2 using jsons7 tags('{\"nv\":null,\"tea\":true,\"\":false,\"tag\":123,\"tea\":false}') values (now,5,'true',4.01,2.2,'123') ")
tdSql.execute("insert into jsons7_2 using jsons7 tags('{\"nv\":null,\"tea\":true,\"tag\":123,\"tea\":false}') values (now+5s,5,'false',4.01,2.2,'123') ")
tdSql.execute("insert into jsons7_2 (ts,datadouble) values (now+3s,-0.9) ")
tdSql.execute("insert into jsons7_2 (ts,datadouble) values (now+4s,-2.9) ")
tdSql.execute("insert into jsons7_2 (ts,datafloat) values (now+1s,-0.9) ")
tdSql.execute("insert into jsons7_2 (ts,datafloat) values (now+2s,-1.9) ")
tdSql.execute("CREATE TABLE if not exists jsons7_3 using jsons7 tags('{\"nv\":null,\"tea\":true,\"\":false,\"tag\":4569,\"tea\":false}') ")
tdSql.query("select ts,ceil(dataint),ceil(datafloat),ceil(datadouble) from jsons7 where jtag contains 'tea';")
tdSql.query("select ceil(dataint),ceil(datafloat),ceil(datadouble) from jsons7 where jtag contains 'tea';")
tdSql.query("select ts,floor(dataint),floor(datafloat),floor(datadouble) from jsons7 where jtag contains 'tea';")
tdSql.query("select floor(dataint),floor(datafloat),floor(datadouble) from jsons7 where jtag contains 'tea';")
tdSql.query("select ts,round(dataint),round(datafloat),round(datadouble) from jsons7 where jtag contains 'tea';")
tdSql.query("select round(dataint),round(datafloat),round(datadouble) from jsons7 where jtag contains 'tea';")
#modify one same key and diffirent data type,include negative number of double
tdSql.execute("insert into jsons7_4 using jsons7 tags('{\"nv\":null,\"tea\":123,\"tag\":123,\"tea\":false}') values (now+1s,5,'true',4.01,2.2,'abc'); ")
tdSql.execute("insert into jsons7_5 using jsons7 tags('{\"nv\":null,\"tea\":\"app\",\"tag\":123,\"tea\":false}') values (now+2s,5,'true',4.01,2.2,'abc'); ")
tdSql.error("insert into jsons7_6 using jsons7 tags('{\"nv\":null,\"tea\":-1.111111111111111111111111111111111111111111111111111111111111111111111,\"tag\":123,\"tea\":false}') values (now+3s,5,'true',4.01,2.2,'123'); ")
tdSql.execute("insert into jsons7_6 using jsons7 tags('{\"nv\":null,\"tea\":-1.111111111,\"tag\":123,\"tea\":false}') values (now,5,'false',4.01,2.2,'t123'); ")
tdSql.query("select jtag from jsons7 where jtag->'tea'>-1.01;")
# tdSql.checkRows(2)
# test join
tdSql.execute("create table if not exists jsons6(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50)) tags(jtag json)")
tdSql.execute("create table if not exists jsons5(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50)) tags(jtag json)")
tdSql.execute("CREATE TABLE if not exists jsons6_1 using jsons6 tags('{\"loc\":\"fff\",\"id\":6,\"user\":\"ffc\"}')")
tdSql.execute("CREATE TABLE if not exists jsons6_2 using jsons6 tags('{\"loc\":\"ffc\",\"id\":5}')")
tdSql.execute("insert into jsons6_1 values ('2020-04-18 15:00:00.000', 1, false, 'json1')")
tdSql.execute("insert into jsons6_2 values ('2020-04-18 15:00:01.000', 2, false, 'json1')")
tdSql.execute("insert into jsons5_1 using jsons5 tags('{\"loc\":\"fff\",\"num\":5,\"location\":\"beijing\"}') values ('2020-04-18 15:00:00.000', 2, true, 'json2')")
tdSql.execute("insert into jsons5_2 using jsons5 tags('{\"loc\":\"fff\",\"id\":5,\"location\":\"beijing\"}') values ('2020-04-18 15:00:01.000', 2, true, 'json2')")
tdSql.error("select 'sss',33,a.jtag->'loc' from jsons6 a,jsons5 b where a.ts=b.ts and a.jtag->'loc'=b.jtag->'loc'")
tdSql.error("select 'sss',33,a.jtag->'loc' from jsons6 a,jsons5 b where a.ts=b.ts and a.jtag->'user'=b.jtag->'loc';")
tdSql.query("select 'sss',33,a.jtag->'loc' from jsons6 a,jsons5 b where a.ts=b.ts and a.jtag->'id'=b.jtag->'id'")
tdSql.checkData(0, 0, "sss")
tdSql.checkData(0, 2, "\"ffc\"")
# #nested query
tdSql.error("select jtag->'tag' from (select tbname,jtag,ts,ceil(dataint) as cdata,ceil(datafloat) ,ceil(datadouble) from jsons7 where jtag contains 'tea') where cdata=3 ") # not currently supported
tdSql.error("select jtag from (select tbname,jtag,ts,ceil(dataint) as cdata,ceil(datafloat) ,ceil(datadouble) from jsons7 where jtag contains 'tea') where jtag->'tag'=123 ") # not currently supported
tdSql.query("select * from (select tbname,jtag->'tea',ts,ceil(dataint) as cdata,ceil(datafloat) ,ceil(datadouble) from jsons7 where jtag contains 'tea') where cdata=5 ")
tdSql.checkRows(5)
for i in range(5):
if tdSql.queryResult[i][0] == 'jsons7_4':
tdSql.checkData(i, 1, 123)
tdSql.checkData(i, 3, 5)
if tdSql.queryResult[i][0] == 'jsons7_5':
tdSql.checkData(i, 1, "\"app\"")
# query child table
tdSql.error("select * from jsons3_2 where jtag3->'k1'=true;")
# tdSql.checkData(0, 0, None)
# tdSql.checkRows(3)
# union all :max times is 100
unioSql = "select ts,jtag->'tbname',jtag->'location',tbname from jsons1 where dataint between 1 and 5 and jtag->'location'='tianjing' union all "
for i in range(99):
if (i < 98):
unioSql += "select ts,jtag->'tbname',jtag->'location',tbname from jsons1 where dataint between 1 and 5 and jtag->'location'='tianjing' union all "
else:
print(i)
unioSql += " select ts,jtag->'tbname',jtag->'location',tbname from jsons1 where dataint between 1 and 5 and jtag->'location'='tianjing'"
tdSql.query(unioSql)
tdSql.checkRows(100)
unioSql += " union all select ts,jtag->'tbname',jtag->'location',tbname from jsons1 where dataint between 1 and 5 and jtag->'location'='tianjing'"
tdSql.error(unioSql)
# fuction testcase : stddev, supported data type: int\str\bool unsupported data type: float\double
tdSql.query(" select stddev(datafloat),dataint from jsons7 group by dataint;")
tdSql.checkRows(5)
tdSql.query(" select stddev(dataint) from jsons7 group by datastr;")
tdSql.checkRows(4)
tdSql.query(" select stddev(dataint) from jsons7 group by databool;")
tdSql.checkRows(3)
tdSql.error(" select stddev(dataint) from jsons7 group by datafloat;")
tdSql.error(" select stddev(dataint) from jsons7 group by datadouble;")
tdSql.execute("create table if not exists jsons8(ts timestamp, dataInt int, dataBool bool, datafloat float, datadouble double,dataStr nchar(50),datatime timestamp) tags(jtag json)")
tdSql.execute("insert into jsons8_1 using jsons8 tags('{\"nv\":null,\"tea\":true,\"\":false,\" \":123,\"tea\":false}') values (now,2,'true',0.9,0.1,'abc',now+60s)")
tdSql.execute("insert into jsons8_2 using jsons8 tags('{\"nv\":null,\"tea\":true,\"\":false,\" \":123,\"tea\":false}') values (now+5s,2,'true',0.9,0.1,'abc',now+65s)")
tdSql.query(" select stddev(dataint) from jsons8 group by datatime;")
tdSql.error(" select stddev(datatime) from jsons8 group by datadouble;")
# # test drop tables and databases
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册