################################################################### # 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 random import os import time import taos import subprocess from faker import Faker from util.log import tdLog from util.cases import tdCases from util.sql import tdSql from util.dnodes import tdDnodes from util.dnodes import * class TDTestCase: updatecfgDict = {'debugflag':0,'stdebugFlag': 143 ,"tqDebugflag":135} def init(self, conn, logSql, replicaVar): tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) self.testcasePath = os.path.split(__file__)[0] self.testcaseFilename = os.path.split(__file__)[-1] os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) self.db = "sel_null" def insert_data(self,database,vgroups): num_random = 10 tdSql.execute('''drop database if exists %s ;''' %database) tdSql.execute('''create database %s keep 36500 vgroups %d PRECISION 'us';'''%(database,vgroups)) tdSql.execute('''use %s;'''%database) tdSql.execute('''create stable %s.stb0 (ts timestamp , c0 int , c1 double , c0null int , c1null double ) tags( t0 tinyint , t1 varchar(16) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint , t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);'''%database) for i in range(5): tdSql.execute('''create table %s.stb0_%d using %s.stb0 tags(%d,'varchar%d',%d,%d, %d, %d,%d,'binary%d','nchar%d',%d,%d,%d ) ;'''%(database,i,database,i,i,i,i,i,i,i,i,i,i,i,i)) # insert data for i in range(num_random): for j in range(50): tdSql.execute('''insert into %s.stb0_0 (ts , c1 , c0) values(now, %d, %d) ;''' % (database,j,j)) tdSql.execute('''insert into %s.stb0_1 (ts , c1 , c0) values(now, %d, %d) ;''' % (database,j,j)) tdSql.execute('''insert into %s.stb0_2 (ts , c1 , c0) values(now, %d, %d) ;''' % (database,j,j)) tdSql.execute('''insert into %s.stb0_3 (ts , c1 , c0) values(now, %d, %d) ;''' % (database,j,j)) tdSql.execute('''insert into %s.stb0_4 (ts , c1 , c0) values(now, %d, %d) ;''' % (database,j,j)) tdSql.query("select count(*) from %s.stb0;" %database) tdSql.checkData(0,0,5*num_random*50) tdSql.query("select count(*) from %s.stb0_0;"%database) tdSql.checkData(0,0,num_random*50) def ts_3085(self,database): sql = "select count(c0null) from(select * from %s.stb0 limit 20,4) "%(database) tdSql.query(sql) tdSql.checkData(0,0,0) offset = random.randint(10,100) for i in range(offset): sql = "select count(c0null) from(select * from %s.stb0 limit %d,%d) "%(database,offset,i) tdSql.query(sql) tdSql.checkData(0,0,0) sql = "select count(c1null) from(select * from %s.stb0 limit %d,%d) "%(database,offset,i) tdSql.query(sql) tdSql.checkData(0,0,0) sql = "select count(c0) from(select * from %s.stb0 limit %d,%d) "%(database,offset,i) tdSql.query(sql) tdSql.checkData(0,0,i) sql = "select count(c1) from(select * from %s.stb0 limit %d,%d) "%(database,offset,i) tdSql.query(sql) tdSql.checkData(0,0,i) sql = "select count(t0) from(select * from %s.stb0 limit %d,%d) "%(database,offset,i) tdSql.query(sql) tdSql.checkData(0,0,i) sql = "select count(t1) from(select * from %s.stb0 limit %d,%d) "%(database,offset,i) tdSql.query(sql) tdSql.checkData(0,0,i) def ts_2974_max(self,database): sql = "select max(c0) from %s.stb0 where ts '2023-1-1' and c第一列 != 0 and 标签1 == 0 limit 10", queryTimes=1) tdSql.checkRows(10) tdSql.query("select count(*) as 计数 from sel_null.stb0_0 partition by c0 as 分组列", queryTimes=1) tdSql.error("create database 数据库") tdSql.error("create table sel_null.中文库 (ts timestamp, c2 int)") tdSql.error("create table sel_null.table1(ts timestamp, 列2 int)") tdSql.execute("create stable sel_null.stable1(ts timestamp, `值` int) tags(`标签1` int, `标签2` int)") tdSql.execute('insert into sel_null.ct1 using sel_null.stable1 tags(1, 1) values(now, 1)', queryTimes=1) tdSql.execute('insert into sel_null.ct1 using sel_null.stable1 tags(2, 2) values(now, 2)', queryTimes=1) tdSql.execute('insert into sel_null.ct1 using sel_null.stable1 tags(2, 2) values(now, 3)', queryTimes=1) tdSql.query('select 值 , 标签1 from sel_null.stable1', queryTimes=1) tdSql.query('select case 值 when 标签1 then 标签1 else 标签2 end from sel_null.stable1', queryTimes=1) tdSql.query('select count(*) from sel_null.stable1 group by 值 having sum(标签1) > 0', queryTimes=1) tdSql.query('show table tags `标签1` 标签n from sel_null.stable1', queryTimes=1) tdSql.query('create sma index a on sel_null.stable1 FUNCTION (sum(值)) interval(1s)', queryTimes=1) tdSql.query('select count(值) from sel_null.stable1', queryTimes=1) tdSql.query('select stable1.值 from sel_null.stable1', queryTimes=1) tdSql.query('select stable1.值 from sel_null.stable1 order by 值', queryTimes=1) tdSql.execute('create stable sel_null.join_stable(`时间戳` timestamp, c1 int) tags(`标签1` int)', queryTimes=1) tdSql.query('select a.值 from sel_null.stable1 a join sel_null.join_stable b on a.ts = 时间戳;', queryTimes=1) tdSql.query('select a.值 from sel_null.stable1 a join sel_null.join_stable b on a.ts = b.时间戳;', queryTimes=1) tdSql.execute('create user user1 pass "asd"', queryTimes=1) tdSql.execute('grant write on sel_null.stable1 with 标签1 = 1 to user1',queryTimes=1) tdSql.execute('select count(*) from sel_null.stable1 state_window(值)', queryTimes=1) def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) tdCases.addWindows(__file__, TDTestCase()) tdCases.addLinux(__file__, TDTestCase())