diff --git a/tests/pytest/stable/json_tagBenchmark.py b/tests/pytest/stable/json_tagBenchmark.py new file mode 100644 index 0000000000000000000000000000000000000000..b32259531d2b4fa438b9a5c07438523a2c757343 --- /dev/null +++ b/tests/pytest/stable/json_tagBenchmark.py @@ -0,0 +1,91 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, db_test.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 +import taos +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql +import time +import random +import datetime +class TDTestCase: + + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + # def assertCheck(self, filename, queryResult, expectResult): + # self.filename = filename + # self.queryResult = queryResult + # self.expectResult = expectResult + # args0 = (filename, queryResult, expectResult) + # assert queryResult == expectResult, "Queryfile:%s ,result is %s != expect: %s" % args0 + + def assertfileDataExport(self, filename, expectResult): + self.filename = filename + self.expectResult = expectResult + with open("%s" % filename, 'r+') as f1: + for line in f1.readlines(): + queryResultTaosc = line.strip().split(',')[0] + # self.assertCheck(filename, queryResultTaosc, expectResult) + + def run(self): + starttime = 1537146000000 + tdSql.prepare() + tdSql.execute("drop database if exists db_json;") + print("==============step1 tag format =======") + tdLog.info("create database db_jsonB ") + tdSql.execute("create database db_jsonB") + tdSql.execute("use db_jsonB") + # test Benchmark + tdSql.execute("create table if not exists jsons1(ts timestamp,dataFloat float) tags(jtag json)") + for numTables in range(500): + json = "{\"loc1%d\":\"beijingandshanghaiandchangzhouandshijiazhuanganda%d\",\"loc2%d\":\"beijingandshanghaiandchangzhouandshijiazhuangandb%d\" ,\"loc3%d\":\"beijingandshanghaiandchangzhouandshijiazhuangandc%d\",\ + \"loc4%d\":\"beijingandshanghaiandchangzhouandshijiazhuangandd%d\",\"loc5%d\":\"beijingandshanghaiandchangzhouandshijiazhuangande%d\",\"loc6%d\":\"beijingandshanghaiandchangzhouandshijiazhuangandf%d\",\ + \"loc7%d\":\"beijingandshanghaiandchangzhouandshijiazhuangandg%d\"}"% (numTables,numTables,numTables,numTables,numTables,numTables,numTables,numTables,numTables,numTables,numTables,numTables,numTables,numTables) + print(json) + createTableSqls = "create table if not exists jsons1_%d using jsons1 tags('%s')" %(numTables,json) + print(createTableSqls) + tdLog.info(createTableSqls) + tdSql.execute(createTableSqls) + for numRecords in range(1,101): + dataFloatSql=numRecords*10+numRecords*0.01 + insertDataSqls = "insert into jsons1_%d values(%d+%ds, %d) " %(numTables,starttime,numRecords,dataFloatSql) + tdLog.info(insertDataSqls) + tdSql.execute(insertDataSqls) + tdSql.execute("use db_jsonB") + now_time1 = datetime.datetime.now() + tdSql.query("select * from jsons1 where ts>1537145900000 and ts<1537156000000;") + spendTimes1 = datetime.datetime.now() - now_time1 + print(spendTimes1) + now_time2 = datetime.datetime.now() + tdSql.query("select * from jsons1 where ts>1537156000000;") + spendTimes2 = datetime.datetime.now() - now_time2 + print(spendTimes2) + + tdSql.execute("drop database db_jsonB") + + testcaseFilename = os.path.split(__file__)[-1] + os.system("rm -rf ./insert_res.txt") + os.system("rm -rf tools/taosdemoAllTest/%s.sql" % testcaseFilename ) + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/tag_lite/json_tag_extra.py b/tests/pytest/tag_lite/json_tag_extra.py index 094359d05141d02e181bd2ed92beffbfd612f507..c1ddbbb1a033050329a6d1eec1b769cf99817c11 100644 --- a/tests/pytest/tag_lite/json_tag_extra.py +++ b/tests/pytest/tag_lite/json_tag_extra.py @@ -12,6 +12,7 @@ # -*- coding: utf-8 -*- import sys +import os import taos from util.log import tdLog from util.cases import tdCases @@ -25,6 +26,21 @@ class TDTestCase: tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) + # def assertCheck(self, filename, queryResult, expectResult): + # self.filename = filename + # self.queryResult = queryResult + # self.expectResult = expectResult + # args0 = (filename, queryResult, expectResult) + # assert queryResult == expectResult, "Queryfile:%s ,result is %s != expect: %s" % args0 + + def assertfileDataExport(self, filename, expectResult): + self.filename = filename + self.expectResult = expectResult + with open("%s" % filename, 'r+') as f1: + for line in f1.readlines(): + queryResultTaosc = line.strip().split(',')[0] + # self.assertCheck(filename, queryResultTaosc, expectResult) + def run(self): tdSql.prepare() tdSql.execute("drop database if exists db_json;") @@ -62,8 +78,18 @@ class TDTestCase: tdSql.error("CREATE TABLE if not exists jsons4_1 using jsons4 tags('{\"%s1\":5}')" % char2) # len(key)=257 tdSql.execute("CREATE TABLE if not exists jsons4_2 using jsons4 tags('{\"T\":\"%s\"}')" % char3) # len(object)=4096 tdSql.error("CREATE TABLE if not exists jsons4_2 using jsons4 tags('{\"TS\":\"%s\"}')" % char3) # len(object)=4097 + + # test the min/max length of double type , and int64 is not required + tdSql.error("CREATE TABLE if not exists jsons4_3 using jsons4 tags('{\"doublength\":-1.8e308}')") + tdSql.error("CREATE TABLE if not exists jsons4_3 using jsons4 tags('{\"doublength\":1.8e308}')") + tdSql.execute("CREATE TABLE if not exists jsons4_4 using jsons4 tags('{\"doublength\":-1.7e308}')") + tdSql.execute("CREATE TABLE if not exists jsons4_5 using jsons4 tags('{\"doublength\":1.71e308}')") + tdSql.query("select jtag from jsons4 where jtag->'doublength'<-1.69e+308;") + tdSql.checkRows(1) + tdSql.query("select jtag from jsons4 where jtag->'doublength'>1.7e+308;") + tdSql.checkRows(1) - tdSql.execute("insert into jsons1_1 values(now, 1, 'json1')") + tdSql.execute("insert into jsons1_1 values(now+2s, 1, 'json1')") tdSql.execute("insert into jsons1_1 values(now+1s, 1, 'json1')") tdSql.execute("insert into jsons1_2 using jsons1 tags('{\"num\":5,\"location\":\"beijing\"}') values (now, 1, 'json2')") tdSql.execute("insert into jsons1_3 using jsons1 tags('{\"num\":34,\"location\":\"beijing\",\"level\":\"l1\"}') values (now, 1, 'json3')") @@ -194,15 +220,12 @@ class TDTestCase: tdSql.checkRows(0) # # test where condition in - # tdSql.query("select * from jsons1 where jtag->'location' in ('beijing')") + tdSql.error("select * from jsons1 where jtag->'location' in ('beijing')") # tdSql.checkRows(3) - - # tdSql.query("select * from jsons1 where jtag->'num' in (5,34)") + tdSql.error("select * from jsons1 where jtag->'num' in (5,34)") # tdSql.checkRows(2) - - # 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.error("select * from jsons1 where jtag->'num' in ('5',34)") + tdSql.error("select * from jsons1 where jtag->'location' in ('beijing') and jtag->'class'=55") # tdSql.checkRows(1) # test where condition match @@ -412,8 +435,25 @@ class TDTestCase: 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' ;") + + tdSql.query("select count(jtag) from jsons1 ;") + tdSql.checkData(0, 0, 15) + tdSql.error("select count( jtag->'location'='beijing') from jsons1 ;") + tdSql.error("select count( jtag contains 'age') from jsons1 ;") + functionName = ['avg','twa','irate','stddev', 'stddev', 'leastsquares'] + print(functionName) + for fn in functionName: + tdSql.error("select %s( jtag) from jsons1 ;"%fn) + tdSql.error("select %s( jtag->'location'='beijing') from jsons1 ;"%fn) + tdSql.error("select %s( jtag contains 'age') from jsons1 ;"%fn) + # tdSql.error("select avg( jtag) from jsons1 ;") + # tdSql.error("select avg( jtag->'location'='beijing') from jsons1 ;") + # tdSql.error("select avg( jtag contains 'age') from jsons1 ;") + + + # Select_exprs is SQL function -Selection function @@ -467,6 +507,13 @@ class TDTestCase: tdSql.checkRows(4) tdSql.checkData(0,1,2) tdSql.checkData(2,1,4) + #error + functionName = ['min','max','last','TOP','last_row','bottom','apercentile','interp'] + print(functionName) + for fn in functionName: + tdSql.error("select %s( jtag) from jsons1 ;"%fn) + tdSql.error("select %s( jtag->'location'='beijing') from jsons1 ;"%fn) + tdSql.error("select %s( jtag contains 'age') from jsons1 ;"%fn) # 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 ;") @@ -500,13 +547,21 @@ class TDTestCase: 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';") + functionName = ['diff','Derivative','SPREAD','ceil','round','floor'] + print(functionName) + for fn in functionName: + tdSql.error("select %s( jtag) from jsons1 ;"%fn) + tdSql.error("select %s( jtag->'location'='beijing') from jsons1 ;"%fn) + tdSql.error("select %s( jtag contains 'age') from jsons1 ;"%fn) + + #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) + tdSql.query("select jtag from jsons7 where jtag->'tea'<-1.01;") + tdSql.checkRows(1) # test join tdSql.execute("create table if not exists jsons6(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50)) tags(jtag json)") @@ -572,6 +627,28 @@ class TDTestCase: tdSql.query(" select stddev(dataint) from jsons8 group by datatime;") tdSql.error(" select stddev(datatime) from jsons8 group by datadouble;") + # #test import and export + # tdSql.execute("select * from jsons1 >> jsons1_data.csv;") + # tdSql.query("select * from jsons1 ") + # with open("./jsons1_data.csv", 'r+') as f1: + # # count=len(open("./jsons1_data.csv",'rU').readlines()) + # # print(count) + # rows=0 + # for line in f1.readlines(): + # # for columns in range(4): # it will be replaced with column length later,but now it is setted to a fixed value first + # queryResultInt = line.strip().split(',')[1] + # # queryResultTag = line.strip().split(',')[3] + # # for rows in range(9): + # # print(rows,1,queryResultInt,queryResultTag) + # tdSql.checkData(rows, 1, "%s" %queryResultInt) + # # tdSql.checkData(rows, 3, "%s" %queryResultTag) + # rows +=1 + + # # test taos -f + # os.system("taos -f stable/json_tag_extra.py.sql ") + # tdSql.execute("use db_json") + # tdSql.query("select * from jsons1") + # tdSql.checkRows(9) # # test drop tables and databases # tdSql.execute("drop table jsons1_1") @@ -579,7 +656,10 @@ class TDTestCase: # tdSql.execute("drop stable jsons3") # tdSql.execute("drop stable jsons2") # tdSql.execute("drop database db_json") - + + testcaseFilename = os.path.split(__file__)[-1] + os.system("rm -rf ./insert_res.txt") + os.system("rm -rf tools/taosdemoAllTest/%s.sql" % testcaseFilename ) def stop(self):