Merge pull request #6583 from taosdata/dev/chr
[TD-4314]<test>: add testcase of nested query with top/bottom function
This commit is contained in:
commit
60c326f954
|
@ -235,6 +235,8 @@ python3 ./test.py -f query/queryTscomputWithNow.py
|
||||||
python3 ./test.py -f query/computeErrorinWhere.py
|
python3 ./test.py -f query/computeErrorinWhere.py
|
||||||
python3 ./test.py -f query/queryTsisNull.py
|
python3 ./test.py -f query/queryTsisNull.py
|
||||||
python3 ./test.py -f query/subqueryFilter.py
|
python3 ./test.py -f query/subqueryFilter.py
|
||||||
|
python3 ./test.py -f query/nestedQuery/queryInterval.py
|
||||||
|
python3 ./test.py -f query/queryStateWindow.py
|
||||||
|
|
||||||
|
|
||||||
#stream
|
#stream
|
||||||
|
@ -325,6 +327,7 @@ python3 ./test.py -f query/queryGroupbySort.py
|
||||||
python3 ./test.py -f functions/queryTestCases.py
|
python3 ./test.py -f functions/queryTestCases.py
|
||||||
python3 ./test.py -f functions/function_stateWindow.py
|
python3 ./test.py -f functions/function_stateWindow.py
|
||||||
python3 ./test.py -f functions/function_derivative.py
|
python3 ./test.py -f functions/function_derivative.py
|
||||||
|
python3 ./test.py -f functions/function_irate.py
|
||||||
|
|
||||||
python3 ./test.py -f insert/unsignedInt.py
|
python3 ./test.py -f insert/unsignedInt.py
|
||||||
python3 ./test.py -f insert/unsignedBigint.py
|
python3 ./test.py -f insert/unsignedBigint.py
|
||||||
|
|
|
@ -0,0 +1,228 @@
|
||||||
|
###################################################################
|
||||||
|
# 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, 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 taos
|
||||||
|
from util.log import *
|
||||||
|
from util.cases import *
|
||||||
|
from util.sql import *
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
class TDTestCase:
|
||||||
|
def init(self, conn, logSql):
|
||||||
|
tdLog.debug("start to execute %s" % __file__)
|
||||||
|
tdSql.init(conn.cursor())
|
||||||
|
|
||||||
|
self.rowNum = 100
|
||||||
|
self.ts = 1537146000000
|
||||||
|
self.ts1 = 1537146000000000
|
||||||
|
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
# db precison ms
|
||||||
|
tdSql.prepare()
|
||||||
|
tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double,
|
||||||
|
col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned) tags(loc nchar(20), tag1 int)''')
|
||||||
|
tdSql.execute("create table test1 using test tags('beijing', 10)")
|
||||||
|
tdSql.execute("create table gtest1 (ts timestamp, col1 float)")
|
||||||
|
tdSql.execute("create table gtest2 (ts timestamp, col1 tinyint)")
|
||||||
|
tdSql.execute("create table gtest3 (ts timestamp, col1 tinyint)")
|
||||||
|
tdSql.execute("create table gtest4 (ts timestamp, col1 tinyint)")
|
||||||
|
tdSql.execute("create table gtest5 (ts timestamp, col1 tinyint)")
|
||||||
|
tdSql.execute("create table gtest6 (ts timestamp, col1 tinyint)")
|
||||||
|
tdSql.execute("create table gtest7 (ts timestamp, col1 tinyint)")
|
||||||
|
tdSql.execute("create table gtest8 (ts timestamp, col1 tinyint)")
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(self.rowNum):
|
||||||
|
tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)"
|
||||||
|
% (self.ts + i*1000, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1))
|
||||||
|
|
||||||
|
tdSql.execute("insert into gtest1 values(1537146000000,0);")
|
||||||
|
tdSql.execute("insert into gtest1 values(1537146001100,1.2);")
|
||||||
|
tdSql.execute("insert into gtest2 values(1537146001001,1);")
|
||||||
|
tdSql.execute("insert into gtest2 values(1537146001101,2);")
|
||||||
|
tdSql.execute("insert into gtest3 values(1537146001101,2);")
|
||||||
|
tdSql.execute("insert into gtest4(ts) values(1537146001101);")
|
||||||
|
tdSql.execute("insert into gtest5 values(1537146001002,4);")
|
||||||
|
tdSql.execute("insert into gtest5 values(1537146002202,4);")
|
||||||
|
tdSql.execute("insert into gtest6 values(1537146000000,5);")
|
||||||
|
tdSql.execute("insert into gtest6 values(1537146001000,2);")
|
||||||
|
tdSql.execute("insert into gtest7 values(1537146001000,1);")
|
||||||
|
tdSql.execute("insert into gtest7 values(1537146008000,2);")
|
||||||
|
tdSql.execute("insert into gtest7 values(1537146009000,6);")
|
||||||
|
tdSql.execute("insert into gtest7 values(1537146012000,3);")
|
||||||
|
tdSql.execute("insert into gtest7 values(1537146015000,3);")
|
||||||
|
tdSql.execute("insert into gtest7 values(1537146017000,1);")
|
||||||
|
tdSql.execute("insert into gtest7 values(1537146019000,3);")
|
||||||
|
tdSql.execute("insert into gtest8 values(1537146000002,4);")
|
||||||
|
tdSql.execute("insert into gtest8 values(1537146002202,4);")
|
||||||
|
|
||||||
|
# irate verifacation
|
||||||
|
tdSql.query("select irate(col1) from test1;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
tdSql.query("select irate(col1) from test1 interval(10s);")
|
||||||
|
tdSql.checkData(0, 1, 1)
|
||||||
|
tdSql.query("select irate(col1) from test1;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
tdSql.query("select irate(col2) from test1;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
tdSql.query("select irate(col3) from test1;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
tdSql.query("select irate(col4) from test1;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
tdSql.query("select irate(col5) from test1;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
tdSql.query("select irate(col6) from test1;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
tdSql.query("select irate(col11) from test1;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
tdSql.query("select irate(col12) from test1;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
tdSql.query("select irate(col13) from test1;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
tdSql.query("select irate(col14) from test1;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
tdSql.query("select irate(col2) from test1;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
tdSql.query("select irate(col2) from test1;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
|
||||||
|
tdSql.query("select irate(col1) from gtest1;")
|
||||||
|
tdSql.checkData(0, 0, 1.2/1.1)
|
||||||
|
tdSql.query("select irate(col1) from gtest2;")
|
||||||
|
tdSql.checkData(0, 0, 10)
|
||||||
|
tdSql.query("select irate(col1) from gtest3;")
|
||||||
|
tdSql.checkData(0, 0, 0)
|
||||||
|
tdSql.query("select irate(col1) from gtest4;")
|
||||||
|
tdSql.checkRows(0)
|
||||||
|
tdSql.query("select irate(col1) from gtest5;")
|
||||||
|
tdSql.checkData(0, 0, 0)
|
||||||
|
tdSql.query("select irate(col1) from gtest6;")
|
||||||
|
tdSql.checkData(0, 0, 2)
|
||||||
|
tdSql.query("select irate(col1) from gtest7;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
tdSql.query("select irate(col1) from gtest7 interval(5s) order by ts asc;")
|
||||||
|
tdSql.checkData(1, 1, 4)
|
||||||
|
tdSql.checkData(2, 1, 0)
|
||||||
|
tdSql.checkData(3, 1, 1)
|
||||||
|
tdSql.query("select irate(col1) from gtest7 interval(5s) order by ts desc ;")
|
||||||
|
tdSql.checkData(1, 1, 0)
|
||||||
|
tdSql.checkData(2, 1, 4)
|
||||||
|
tdSql.checkData(3, 1, 0)
|
||||||
|
|
||||||
|
#error
|
||||||
|
tdSql.error("select irate(col1) from test")
|
||||||
|
tdSql.error("select irate(ts) from test1")
|
||||||
|
tdSql.error("select irate(col7) from test1")
|
||||||
|
tdSql.error("select irate(col8) from test1")
|
||||||
|
tdSql.error("select irate(col9) from test1")
|
||||||
|
tdSql.error("select irate(loc) from test1")
|
||||||
|
tdSql.error("select irate(tag1) from test1")
|
||||||
|
|
||||||
|
# use db1 precision us
|
||||||
|
tdSql.execute("create database db1 precision 'us' keep 3650 UPDATE 1")
|
||||||
|
tdSql.execute("use db1 ")
|
||||||
|
tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double,
|
||||||
|
col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned) tags(loc nchar(20))''')
|
||||||
|
tdSql.execute("create table test1 using test tags('beijing')")
|
||||||
|
tdSql.execute("create table gtest1 (ts timestamp, col1 float)")
|
||||||
|
tdSql.execute("create table gtest2 (ts timestamp, col1 tinyint)")
|
||||||
|
tdSql.execute("create table gtest3 (ts timestamp, col1 tinyint)")
|
||||||
|
tdSql.execute("create table gtest4 (ts timestamp, col1 tinyint)")
|
||||||
|
tdSql.execute("create table gtest5 (ts timestamp, col1 tinyint)")
|
||||||
|
tdSql.execute("create table gtest6 (ts timestamp, col1 tinyint)")
|
||||||
|
tdSql.execute("create table gtest7 (ts timestamp, col1 tinyint)")
|
||||||
|
tdSql.execute("create table gtest8 (ts timestamp, col1 tinyint)")
|
||||||
|
tdSql.execute("create table gtest9 (ts timestamp, col1 tinyint)")
|
||||||
|
|
||||||
|
for i in range(self.rowNum):
|
||||||
|
tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)"
|
||||||
|
% (self.ts1 + i*1000000, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1))
|
||||||
|
|
||||||
|
tdSql.execute("insert into gtest1 values(1537146000000000,0);")
|
||||||
|
tdSql.execute("insert into gtest1 values(1537146001100000,1.2);")
|
||||||
|
tdSql.execute("insert into gtest2 values(1537146001001000,1);")
|
||||||
|
tdSql.execute("insert into gtest2 values(1537146001101000,2);")
|
||||||
|
tdSql.execute("insert into gtest3 values(1537146001101000,2);")
|
||||||
|
tdSql.execute("insert into gtest4(ts) values(1537146001101000);")
|
||||||
|
tdSql.execute("insert into gtest5 values(1537146001002000,4);")
|
||||||
|
tdSql.execute("insert into gtest5 values(1537146002202000,4);")
|
||||||
|
tdSql.execute("insert into gtest6 values(1537146000000000,5);")
|
||||||
|
tdSql.execute("insert into gtest6 values(1537146001000000,2);")
|
||||||
|
tdSql.execute("insert into gtest7 values(1537146001000000,1);")
|
||||||
|
tdSql.execute("insert into gtest7 values(1537146008000000,2);")
|
||||||
|
tdSql.execute("insert into gtest7 values(1537146009000000,6);")
|
||||||
|
tdSql.execute("insert into gtest7 values(1537146012000000,3);")
|
||||||
|
tdSql.execute("insert into gtest7 values(1537146015000000,3);")
|
||||||
|
tdSql.execute("insert into gtest7 values(1537146017000000,1);")
|
||||||
|
tdSql.execute("insert into gtest7 values(1537146019000000,3);")
|
||||||
|
tdSql.execute("insert into gtest8 values(1537146000002000,3);")
|
||||||
|
tdSql.execute("insert into gtest8 values(1537146001003000,4);")
|
||||||
|
tdSql.execute("insert into gtest9 values(1537146000000000,4);")
|
||||||
|
tdSql.execute("insert into gtest9 values(1537146000000001,5);")
|
||||||
|
|
||||||
|
|
||||||
|
# irate verifacation
|
||||||
|
tdSql.query("select irate(col1) from test1;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
tdSql.query("select irate(col1) from test1 interval(10s);")
|
||||||
|
tdSql.checkData(0, 1, 1)
|
||||||
|
tdSql.query("select irate(col1) from test1;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
tdSql.query("select irate(col1) from gtest1;")
|
||||||
|
tdSql.checkData(0, 0, 1.2/1.1)
|
||||||
|
tdSql.query("select irate(col1) from gtest2;")
|
||||||
|
tdSql.checkData(0, 0, 10)
|
||||||
|
tdSql.query("select irate(col1) from gtest3;")
|
||||||
|
tdSql.checkData(0, 0, 0)
|
||||||
|
tdSql.query("select irate(col1) from gtest4;")
|
||||||
|
tdSql.checkRows(0)
|
||||||
|
tdSql.query("select irate(col1) from gtest5;")
|
||||||
|
tdSql.checkData(0, 0, 0)
|
||||||
|
tdSql.query("select irate(col1) from gtest6;")
|
||||||
|
tdSql.checkData(0, 0, 2)
|
||||||
|
tdSql.query("select irate(col1) from gtest7;")
|
||||||
|
tdSql.checkData(0, 0, 1)
|
||||||
|
tdSql.query("select irate(col1) from gtest7 interval(5s) order by ts asc;")
|
||||||
|
tdSql.checkData(1, 1, 4)
|
||||||
|
tdSql.checkData(2, 1, 0)
|
||||||
|
tdSql.checkData(3, 1, 1)
|
||||||
|
tdSql.query("select irate(col1) from gtest7 interval(5s) order by ts desc ;")
|
||||||
|
tdSql.checkData(1, 1, 0)
|
||||||
|
tdSql.checkData(2, 1, 4)
|
||||||
|
tdSql.checkData(3, 1, 0)
|
||||||
|
tdSql.query("select irate(col1) from gtest8;")
|
||||||
|
tdSql.checkData(0, 0, 1/1.001)
|
||||||
|
tdSql.query("select irate(col1) from gtest9;")
|
||||||
|
tdSql.checkData(0, 0, 1000000)
|
||||||
|
|
||||||
|
#error
|
||||||
|
tdSql.error("select irate(col1) from test")
|
||||||
|
tdSql.error("select irate(ts) from test1")
|
||||||
|
tdSql.error("select irate(col7) from test1")
|
||||||
|
tdSql.error("select irate(col8) from test1")
|
||||||
|
tdSql.error("select irate(col9) from test1")
|
||||||
|
tdSql.error("select irate(loc) from test1")
|
||||||
|
tdSql.error("select irate(tag1) from test1")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
tdSql.close()
|
||||||
|
tdLog.success("%s successfully executed" % __file__)
|
||||||
|
|
||||||
|
tdCases.addWindows(__file__, TDTestCase())
|
||||||
|
tdCases.addLinux(__file__, TDTestCase())
|
|
@ -0,0 +1,62 @@
|
||||||
|
{
|
||||||
|
"filetype": "insert",
|
||||||
|
"cfgdir": "/etc/taos",
|
||||||
|
"host": "127.0.0.1",
|
||||||
|
"port": 6030,
|
||||||
|
"user": "root",
|
||||||
|
"password": "taosdata",
|
||||||
|
"thread_count": 4,
|
||||||
|
"thread_count_create_tbl": 4,
|
||||||
|
"result_file":"./insert_res.txt",
|
||||||
|
"confirm_parameter_prompt": "no",
|
||||||
|
"insert_interval": 0,
|
||||||
|
"interlace_rows": 10,
|
||||||
|
"num_of_records_per_req": 1000,
|
||||||
|
"max_sql_len": 1024000,
|
||||||
|
"databases": [{
|
||||||
|
"dbinfo": {
|
||||||
|
"name": "db",
|
||||||
|
"drop": "yes",
|
||||||
|
"replica": 1,
|
||||||
|
"days": 10,
|
||||||
|
"cache": 50,
|
||||||
|
"blocks": 8,
|
||||||
|
"precision": "ms",
|
||||||
|
"keep": 365,
|
||||||
|
"minRows": 100,
|
||||||
|
"maxRows": 4096,
|
||||||
|
"comp":2,
|
||||||
|
"walLevel":1,
|
||||||
|
"cachelast":0,
|
||||||
|
"quorum":1,
|
||||||
|
"fsync":3000,
|
||||||
|
"update": 0
|
||||||
|
},
|
||||||
|
"super_tables": [{
|
||||||
|
"name": "stb0",
|
||||||
|
"child_table_exists":"no",
|
||||||
|
"childtable_count": 1,
|
||||||
|
"childtable_prefix": "stb0_",
|
||||||
|
"auto_create_table": "no",
|
||||||
|
"batch_create_tbl_num": 10,
|
||||||
|
"data_source": "rand",
|
||||||
|
"insert_mode": "taosc",
|
||||||
|
"insert_rows": 100000,
|
||||||
|
"childtable_limit": -1,
|
||||||
|
"childtable_offset": 0,
|
||||||
|
"multi_thread_write_one_tbl": "no",
|
||||||
|
"interlace_rows": 0,
|
||||||
|
"insert_interval": 0,
|
||||||
|
"max_sql_len": 1024000,
|
||||||
|
"disorder_ratio": 0,
|
||||||
|
"disorder_range": 1,
|
||||||
|
"timestamp_step": 1000,
|
||||||
|
"start_timestamp": "2020-10-01 00:00:00.000",
|
||||||
|
"sample_format": "csv",
|
||||||
|
"sample_file": "./tools/taosdemoAllTest/sample.csv",
|
||||||
|
"tags_file": "",
|
||||||
|
"columns": [{"type": "INT", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BOOL"}],
|
||||||
|
"tags": [{"type": "TINYINT", "count":1}, {"type": "BINARY", "len": 16, "count":1}]
|
||||||
|
}]
|
||||||
|
}]
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
###################################################################
|
||||||
|
# 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, 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
|
||||||
|
from util.log import *
|
||||||
|
from util.cases import *
|
||||||
|
from util.sql import *
|
||||||
|
from util.dnodes import *
|
||||||
|
|
||||||
|
|
||||||
|
class TDTestCase:
|
||||||
|
def init(self, conn, logSql):
|
||||||
|
tdLog.debug("start to execute %s" % __file__)
|
||||||
|
tdSql.init(conn.cursor(), logSql)
|
||||||
|
|
||||||
|
def getBuildPath(self):
|
||||||
|
selfPath = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
|
if ("community" in selfPath):
|
||||||
|
projPath = selfPath[:selfPath.find("community")]
|
||||||
|
else:
|
||||||
|
projPath = selfPath[:selfPath.find("tests")]
|
||||||
|
|
||||||
|
for root, dirs, files in os.walk(projPath):
|
||||||
|
if ("taosd" in files):
|
||||||
|
rootRealPath = os.path.dirname(os.path.realpath(root))
|
||||||
|
if ("packaging" not in rootRealPath):
|
||||||
|
buildPath = root[:len(root)-len("/build/bin")]
|
||||||
|
break
|
||||||
|
return buildPath
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
buildPath = self.getBuildPath()
|
||||||
|
if (buildPath == ""):
|
||||||
|
tdLog.exit("taosd not found!")
|
||||||
|
else:
|
||||||
|
tdLog.info("taosd found in %s" % buildPath)
|
||||||
|
binPath = buildPath+ "/build/bin/"
|
||||||
|
|
||||||
|
# insert: create one or mutiple tables per sql and insert multiple rows per sql
|
||||||
|
os.system("%staosdemo -f query/nestedQuery/insertData.json -y " % binPath)
|
||||||
|
tdSql.execute("use db")
|
||||||
|
tdSql.query("select count (tbname) from stb0")
|
||||||
|
tdSql.checkData(0, 0, 1000)
|
||||||
|
tdSql.query("select count (tbname) from stb1")
|
||||||
|
tdSql.checkData(0, 0, 1000)
|
||||||
|
tdSql.query("select count(*) from stb00_0")
|
||||||
|
tdSql.checkData(0, 0, 100)
|
||||||
|
tdSql.query("select count(*) from stb0")
|
||||||
|
tdSql.checkData(0, 0, 100000)
|
||||||
|
tdSql.query("select count(*) from stb01_1")
|
||||||
|
tdSql.checkData(0, 0, 200)
|
||||||
|
tdSql.query("select count(*) from stb1")
|
||||||
|
tdSql.checkData(0, 0, 200000)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
testcaseFilename = os.path.split(__file__)[-1]
|
||||||
|
os.system("rm -rf ./insert_res.txt")
|
||||||
|
os.system("rm -rf query/nestedQuery/%s.sql" % testcaseFilename )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
tdSql.close()
|
||||||
|
tdLog.success("%s successfully executed" % __file__)
|
||||||
|
|
||||||
|
|
||||||
|
tdCases.addWindows(__file__, TDTestCase())
|
||||||
|
tdCases.addLinux(__file__, TDTestCase())
|
|
@ -0,0 +1,106 @@
|
||||||
|
###################################################################
|
||||||
|
# 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, 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
|
||||||
|
from util.dnodes import tdDnodes
|
||||||
|
import random
|
||||||
|
|
||||||
|
class TDTestCase:
|
||||||
|
def init(self, conn, logSql):
|
||||||
|
tdLog.debug("start to execute %s" % __file__)
|
||||||
|
tdSql.init(conn.cursor(), logSql)
|
||||||
|
|
||||||
|
self.ts1 = 1593548685000
|
||||||
|
self.ts2 = 1593548785000
|
||||||
|
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
# tdSql.execute("drop database db ")
|
||||||
|
tdSql.prepare()
|
||||||
|
tdSql.execute("create table st (ts timestamp, num int, value int , t_instance int) tags (loc nchar(30))")
|
||||||
|
node = 5
|
||||||
|
number = 10
|
||||||
|
for n in range(node):
|
||||||
|
for m in range(number):
|
||||||
|
dt= m*300000+n*60000 # collecting'frequency is 10s
|
||||||
|
args1=(n,n,self.ts1+dt,n,100+2*m+2*n,10+m+n)
|
||||||
|
# args2=(n,self.ts2+dt,n,120+n,15+n)
|
||||||
|
tdSql.execute("insert into t%d using st tags('beijing%d') values(%d, %d, %d, %d)" % args1)
|
||||||
|
# tdSql.execute("insert into t1 using st tags('shanghai') values(%d, %d, %d, %d)" % args2)
|
||||||
|
|
||||||
|
# interval function
|
||||||
|
tdSql.query("select avg(value) from st interval(10m)")
|
||||||
|
# print(tdSql.queryResult)
|
||||||
|
tdSql.checkRows(6)
|
||||||
|
tdSql.checkData(0, 0, "2020-07-01 04:20:00")
|
||||||
|
tdSql.checkData(1, 1, 107.4)
|
||||||
|
|
||||||
|
# subquery with interval
|
||||||
|
tdSql.query("select avg(avg_val) from(select avg(value) as avg_val from st where loc='beijing0' interval(10m));")
|
||||||
|
tdSql.checkData(0, 0, 109.0)
|
||||||
|
|
||||||
|
# subquery with interval and select two Column in parent query
|
||||||
|
tdSql.error("select ts,avg(avg_val) from(select avg(value) as avg_val from st where loc='beijing0' interval(10m));")
|
||||||
|
|
||||||
|
# subquery with interval and sliding
|
||||||
|
tdSql.query("select avg(value) as avg_val from st where loc='beijing0' interval(8m) sliding(30s) limit 1;")
|
||||||
|
tdSql.checkData(0, 0, "2020-07-01 04:17:00")
|
||||||
|
tdSql.checkData(0, 1, 100)
|
||||||
|
tdSql.query("select avg(avg_val) from(select avg(value) as avg_val from st where loc='beijing1' interval(8m) sliding(30s));")
|
||||||
|
tdSql.checkData(0, 0, 111)
|
||||||
|
|
||||||
|
# subquery with interval and offset
|
||||||
|
tdSql.query("select avg(value) as avg_val from st where loc='beijing0' interval(5m,1m);")
|
||||||
|
tdSql.checkData(0, 0, "2020-07-01 04:21:00")
|
||||||
|
tdSql.checkData(0, 1, 100)
|
||||||
|
tdSql.query("select avg(avg_val) from(select avg(value) as avg_val from st where loc='beijing0' interval(5m,1m) group by loc);")
|
||||||
|
tdSql.checkData(0, 0, 109)
|
||||||
|
|
||||||
|
# subquery with interval,sliding and group by ; parent query with interval
|
||||||
|
tdSql.query("select avg(value) as avg_val from st where loc='beijing0' interval(8m) sliding(1m) group by loc limit 1 offset 52 ;")
|
||||||
|
tdSql.checkData(0, 0, "2020-07-01 05:09:00")
|
||||||
|
tdSql.checkData(0, 1, 118)
|
||||||
|
tdSql.query("select avg(avg_val) as ncst from(select avg(value) as avg_val from st where loc!='beijing0' interval(8m) sliding(1m) group by loc ) interval(5m);")
|
||||||
|
tdSql.checkData(1, 1, 105)
|
||||||
|
|
||||||
|
# # subquery and parent query with interval and sliding
|
||||||
|
tdSql.query("select avg(avg_val) from(select avg(value) as avg_val from st where loc='beijing1' interval(8m) sliding(5m)) interval(10m) sliding(2m);")
|
||||||
|
tdSql.checkData(29, 0, "2020-07-01 05:10:00.000")
|
||||||
|
|
||||||
|
# subquery and parent query with top and bottom
|
||||||
|
tdSql.query("select top(avg_val,2) from(select avg(value) as avg_val,num from st where loc!='beijing0' group by num) order by avg_val desc;")
|
||||||
|
tdSql.checkData(0, 1, 117)
|
||||||
|
tdSql.query("select bottom(avg_val,3) from(select avg(value) as avg_val,num from st where loc!='beijing0' group by num) order by avg_val asc;")
|
||||||
|
tdSql.checkData(0, 1, 111)
|
||||||
|
|
||||||
|
#
|
||||||
|
tdSql.query("select top(avg_val,2) from(select avg(value) as avg_val from st where loc='beijing1' interval(8m) sliding(3m));")
|
||||||
|
tdSql.checkData(0, 1, 120)
|
||||||
|
|
||||||
|
# clear env
|
||||||
|
testcaseFilename = os.path.split(__file__)[-1]
|
||||||
|
os.system("rm -rf ./insert_res.txt")
|
||||||
|
os.system("rm -rf wal/%s.sql" % testcaseFilename )
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
tdSql.close()
|
||||||
|
tdLog.success("%s successfully executed" % __file__)
|
||||||
|
|
||||||
|
|
||||||
|
tdCases.addWindows(__file__, TDTestCase())
|
||||||
|
tdCases.addLinux(__file__, TDTestCase())
|
|
@ -0,0 +1,111 @@
|
||||||
|
###################################################################
|
||||||
|
# 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, 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 taos
|
||||||
|
from util.log import *
|
||||||
|
from util.cases import *
|
||||||
|
from util.sql import *
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
class TDTestCase:
|
||||||
|
def init(self, conn, logSql):
|
||||||
|
tdLog.debug("start to execute %s" % __file__)
|
||||||
|
tdSql.init(conn.cursor())
|
||||||
|
self.rowNum = 100000
|
||||||
|
self.ts = 1537146000000
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
tdSql.prepare()
|
||||||
|
|
||||||
|
print("==============step1")
|
||||||
|
tdSql.execute(
|
||||||
|
"create table if not exists st (ts timestamp, t1 int, t2 timestamp, t3 bigint, t4 float, t5 double, t6 binary(10), t7 smallint, t8 tinyint, t9 bool, t10 nchar(10), t11 int unsigned, t12 bigint unsigned, t13 smallint unsigned, t14 tinyint unsigned ,t15 int) tags(dev nchar(50), tag2 binary(16))")
|
||||||
|
tdSql.execute(
|
||||||
|
'CREATE TABLE if not exists dev_001 using st tags("dev_01", "tag_01")')
|
||||||
|
tdSql.execute(
|
||||||
|
'CREATE TABLE if not exists dev_002 using st tags("dev_02", "tag_02")')
|
||||||
|
|
||||||
|
print("==============step2")
|
||||||
|
|
||||||
|
tdSql.execute(
|
||||||
|
"INSERT INTO dev_001 VALUES('2020-05-13 10:00:00.000', 1, '2020-05-13 10:00:00.000', 10, 3.1, 3.14, 'test', -10, -126, true, '测试', 15, 10, 65534, 254, 1)('2020-05-13 10:00:01.000', 1, '2020-05-13 10:00:01.000', 10, 3.1, 3.14, 'test', -10, -126, true, '测试', 15, 10, 65534, 253, 5)('2020-05-13 10:00:02.000', 10, '2020-05-13 10:00:00.000', 11, 3.1, 3.14, 'test', 10, -127, false, '测试', 15, 10, 65534, 253, 10)('2020-05-13 10:00:03.000', 1, '2020-05-13 10:00:00.000', 11, 3.1, 3.14, 'test', -10, -126, true, '测试', 14, 12, 65532, 254, 15)")
|
||||||
|
|
||||||
|
for i in range(self.rowNum):
|
||||||
|
tdSql.execute("insert into dev_002 (ts,t1) values(%d, %d,)" % (self.ts + i, i + 1))
|
||||||
|
|
||||||
|
tdSql.query("select count(ts) from dev_001 state_window(t1)")
|
||||||
|
tdSql.checkRows(3)
|
||||||
|
tdSql.checkData(0, 0, 2)
|
||||||
|
tdSql.query("select count(ts) from dev_001 state_window(t3)")
|
||||||
|
tdSql.checkRows(2)
|
||||||
|
tdSql.checkData(1, 0, 2)
|
||||||
|
tdSql.query("select count(ts) from dev_001 state_window(t7)")
|
||||||
|
tdSql.checkRows(3)
|
||||||
|
tdSql.checkData(1, 0, 1)
|
||||||
|
tdSql.query("select count(ts) from dev_001 state_window(t8)")
|
||||||
|
tdSql.checkRows(3)
|
||||||
|
tdSql.checkData(2, 0, 1)
|
||||||
|
tdSql.query("select count(ts) from dev_001 state_window(t11)")
|
||||||
|
tdSql.checkRows(2)
|
||||||
|
tdSql.checkData(0, 0, 3)
|
||||||
|
tdSql.query("select count(ts) from dev_001 state_window(t12)")
|
||||||
|
tdSql.checkRows(2)
|
||||||
|
tdSql.checkData(1, 0, 1)
|
||||||
|
tdSql.query("select count(ts) from dev_001 state_window(t13)")
|
||||||
|
tdSql.checkRows(2)
|
||||||
|
tdSql.checkData(1, 0, 1)
|
||||||
|
tdSql.query("select count(ts) from dev_001 state_window(t14)")
|
||||||
|
tdSql.checkRows(3)
|
||||||
|
tdSql.checkData(1, 0, 2)
|
||||||
|
tdSql.query("select count(ts) from dev_002 state_window(t1)")
|
||||||
|
tdSql.checkRows(100000)
|
||||||
|
|
||||||
|
# with all aggregate function
|
||||||
|
tdSql.query("select count(*),sum(t1),avg(t1),twa(t1),stddev(t15),leastsquares(t15,1,1),first(t15),last(t15),spread(t15),percentile(t15,90),t9 from dev_001 state_window(t9);")
|
||||||
|
tdSql.checkRows(3)
|
||||||
|
tdSql.checkData(0, 0, 2)
|
||||||
|
tdSql.checkData(1, 1, 10)
|
||||||
|
tdSql.checkData(0, 2, 1)
|
||||||
|
# tdSql.checkData(0, 3, 1)
|
||||||
|
tdSql.checkData(0, 4, np.std([1,5]))
|
||||||
|
# tdSql.checkData(0, 5, 1)
|
||||||
|
tdSql.checkData(0, 6, 1)
|
||||||
|
tdSql.checkData(0, 7, 5)
|
||||||
|
tdSql.checkData(0, 8, 4)
|
||||||
|
tdSql.checkData(0, 9, 4.6)
|
||||||
|
tdSql.checkData(0, 10, 'True')
|
||||||
|
|
||||||
|
# with where
|
||||||
|
tdSql.query("select avg(t15),t9 from dev_001 where t9='true' state_window(t9);")
|
||||||
|
tdSql.checkData(0, 0, 7)
|
||||||
|
tdSql.checkData(0, 1, 'True')
|
||||||
|
|
||||||
|
# error
|
||||||
|
tdSql.error("select count(*) from dev_001 state_window(t2)")
|
||||||
|
tdSql.error("select count(*) from st state_window(t3)")
|
||||||
|
tdSql.error("select count(*) from dev_001 state_window(t4)")
|
||||||
|
tdSql.error("select count(*) from dev_001 state_window(t5)")
|
||||||
|
tdSql.error("select count(*) from dev_001 state_window(t6)")
|
||||||
|
tdSql.error("select count(*) from dev_001 state_window(t10)")
|
||||||
|
tdSql.error("select count(*) from dev_001 state_window(tag2)")
|
||||||
|
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
tdSql.close()
|
||||||
|
tdLog.success("%s successfully executed" % __file__)
|
||||||
|
|
||||||
|
|
||||||
|
tdCases.addWindows(__file__, TDTestCase())
|
||||||
|
tdCases.addLinux(__file__, TDTestCase())
|
Loading…
Reference in New Issue