TDengine/tests/system-test/2-query/smaTest.py

128 lines
3.8 KiB
Python
Raw Normal View History

2022-04-24 12:39:10 +00:00
###################################################################
# 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
from numpy.lib.function_base import insert
import taos
from util.log import *
from util.cases import *
from util.sql import *
import numpy as np
# constant define
WAITS = 5 # wait seconds
class TDTestCase:
#
# --------------- main frame -------------------
#
2022-05-05 14:17:25 +00:00
# updatecfgDict = {'debugFlag': 135}
# updatecfgDict = {'fqdn': 135}
2022-04-24 12:39:10 +00:00
# init
def init(self, conn, logSql, replicaVar=1):
self.replicaVar = int(replicaVar)
2022-04-24 12:39:10 +00:00
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor())
tdSql.prepare()
self.create_tables();
self.ts = 1500000000000
2022-08-17 10:18:48 +00:00
# run case
2022-04-24 12:39:10 +00:00
def run(self):
# insert data
2022-08-17 10:18:48 +00:00
dbname = "db"
2022-11-24 03:45:40 +00:00
self.insert_data1(f"{dbname}.t1", self.ts, 10*10000)
self.insert_data1(f"{dbname}.t4", self.ts, 10*10000)
2022-04-24 12:39:10 +00:00
# test base case
# self.test_case1()
tdLog.debug(" LIMIT test_case1 ............ [OK]")
# test advance case
# self.test_case2()
tdLog.debug(" LIMIT test_case2 ............ [OK]")
2022-08-17 10:18:48 +00:00
# stop
2022-04-24 12:39:10 +00:00
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
#
# --------------- case -------------------
#
# create table
2022-08-17 10:18:48 +00:00
def create_tables(self, dbname="db"):
2022-04-24 12:39:10 +00:00
# super table
2022-08-17 10:18:48 +00:00
tdSql.execute(f"create table {dbname}.st(ts timestamp, i1 int,i2 int) tags(area int)")
2022-04-24 12:39:10 +00:00
# child table
2022-08-17 10:18:48 +00:00
tdSql.execute(f"create table {dbname}.t1 using {dbname}.st tags(1)")
2022-04-24 12:39:10 +00:00
2022-08-17 10:18:48 +00:00
tdSql.execute(f"create table {dbname}.st1(ts timestamp, i1 int ,i2 int) tags(area int) sma(i2) ")
tdSql.execute(f"create table {dbname}.t4 using {dbname}.st1 tags(1)")
2022-04-24 12:39:10 +00:00
2022-08-17 10:18:48 +00:00
return
2022-04-24 12:39:10 +00:00
# insert data1
def insert_data(self, tbname, ts_start, count):
2022-11-24 03:45:40 +00:00
pre_insert = "insert into %s values" % tbname
2022-04-24 12:39:10 +00:00
sql = pre_insert
2022-11-24 03:45:40 +00:00
tdLog.debug("insert table %s rows=%d ..." % (tbname, count))
2022-04-24 12:39:10 +00:00
for i in range(count):
2022-11-24 03:45:40 +00:00
sql += " (%d,%d)" % (ts_start + i*1000, i)
if i > 0 and i % 20000 == 0:
tdLog.info("%d rows inserted" % i)
2022-04-24 12:39:10 +00:00
tdSql.execute(sql)
sql = pre_insert
2022-08-17 10:18:48 +00:00
# end sql
2022-11-24 03:45:40 +00:00
tdLog.info("insert_data end")
2022-04-24 12:39:10 +00:00
if sql != pre_insert:
tdSql.execute(sql)
tdLog.debug("INSERT TABLE DATA ............ [OK]")
return
def insert_data1(self, tbname, ts_start, count):
2022-11-24 03:45:40 +00:00
pre_insert = "insert into %s values" % tbname
2022-04-24 12:39:10 +00:00
sql = pre_insert
2022-11-24 03:45:40 +00:00
tdLog.debug("insert table %s rows=%d ..." % (tbname, count))
2022-04-24 12:39:10 +00:00
for i in range(count):
2022-11-24 03:45:40 +00:00
sql += " (%d,%d,%d)" % (ts_start + i*1000, i, i+1)
if i > 0 and i % 20000 == 0:
tdLog.info("%d rows inserted" % i)
2022-04-24 12:39:10 +00:00
tdSql.execute(sql)
sql = pre_insert
2022-08-17 10:18:48 +00:00
# end sql
2022-11-24 03:45:40 +00:00
tdLog.info("insert_data1 end")
2022-04-24 12:39:10 +00:00
if sql != pre_insert:
tdSql.execute(sql)
tdLog.debug("INSERT TABLE DATA ............ [OK]")
return
2022-08-17 10:18:48 +00:00
# test case1 base
2022-04-24 12:39:10 +00:00
# def test_case1(self):
2022-08-17 10:18:48 +00:00
# #
2022-04-24 12:39:10 +00:00
# # limit base function
# #
# # base no where
# sql = "select * from t1 limit 10"
# tdSql.waitedQuery(sql, 10, WAITS)
#
# add case with filename
#
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())