未验证 提交 9a1db8d9 编写于 作者: M Minglei Jin 提交者: GitHub

Merge pull request #11937 from taosdata/xiaoping/cases

test: add demo for tq
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// TAOS standard API example. The same syntax as MySQL, but only a subset
// to compile: gcc -o tqdemo tqdemo.c -ltaos
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <taos.h> // TAOS header file
void print_results(TAOS *taos, char *qstr);
int main(int argc, char *argv[]) {
char qstr[1024];
TAOS_RES *pSql = NULL;
// connect to server
if (argc < 2) {
printf("please input server-ip \n");
return 0;
}
TAOS *taos = taos_connect(argv[1], "root", "taosdata", NULL, 0);
if (taos == NULL) {
printf("failed to connect to server, reason:%s\n", "null taos" /*taos_errstr(taos)*/);
exit(1);
}
TAOS_RES* res;
// create topic
res = taos_query(taos, "create topic tq_test partitions 10");
taos_free_result(res);
res = taos_query(taos, "use tq_test");
taos_free_result(res);
print_results(taos, "show stables");
print_results(taos, "show tables");
// insert data
for (int i = 0; i < 10; i++) {
char *sql = "insert into p%d values(now + %ds, %d, 'test')";
sprintf(qstr, sql, i, i, i);
res = taos_query(taos, qstr);
taos_free_result(res);
}
// query data
print_results(taos, "select * from tq_test.ps");
taos_close(taos);
taos_cleanup();
}
void print_results(TAOS *taos, char *qstr) {
TAOS_RES* res;
res = taos_query(taos, qstr);
if (res == NULL || taos_errno(res) != 0) {
printf("failed to select, reason:%s\n", taos_errstr(res));
taos_free_result(res);
exit(1);
}
TAOS_ROW row;
int rows = 0;
int num_fields = taos_field_count(res);
TAOS_FIELD *fields = taos_fetch_fields(res);
printf("num_fields = %d\n", num_fields);
printf("%s result:\n", qstr);
// fetch the records row by row
while ((row = taos_fetch_row(res))) {
char temp[1024] = {0};
rows++;
taos_print_row(temp, row, fields, num_fields);
printf("%s\n", temp);
}
taos_free_result(res);
}
......@@ -606,6 +606,7 @@
7,,develop-test,python3 ./test.py -f 5-taos-tools/taosdump/taosdumpTestTypeBigInt.py
7,,develop-test,python3 ./test.py -f 2-query/function_timetruncate.py
7,,develop-test,python3 ./test.py -f 2-query/function_timediff.py
7,,pytest,python3 test.py -f tsdb/delete.py
6,,system-test,python3 ./test.py -f 2-query/TD-12229.py
6,,system-test,python3 ./test.py -f 2-query/TD-11943.py
6,,system-test,python3 ./test.py -f 2-query/function_elapsed.py
......
###################################################################
# 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 = 10 # wait seconds
class TDTestCase:
updatecfgDict = {'numOfNodes': 3, '1':{'replica': 3}, '2':{'replica': 3}, '3':{'replica': 3}}
# init
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor())
tdSql.prepare()
self.create_tables()
self.ts = 1500000000000
# run case
def run(self):
# insert data
for i in range(10):
tbname = "t%d"%i
self.insert_data(tbname, self.ts, (i+1)*10000, 20000);
tdLog.debug(" INSERT data 10 tables ....... [OK]")
# test base case
self.test_case1()
tdLog.debug(" DELETE test_case1 ............ [OK]")
# test advance case
self.test_case2()
tdLog.debug(" DELETE test_case2 ............ [OK]")
# test advance case
self.test_case3()
tdLog.debug(" DELETE test_case3 ............ [OK]")
# stop
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
#
# --------------- case -------------------
#
# create table
def create_tables(self):
# super table
tdSql.execute("create table st(ts timestamp, i1 int) tags(area int)")
# child table
for i in range(10):
sql = "create table t%d using st tags(%d)"%(i, i)
tdSql.execute(sql)
return
# insert data1
def insert_data(self, tbname, ts_start, count, batch_num):
pre_insert = "insert into %s values"%tbname
sql = pre_insert
tdLog.debug("doing insert table %s rows=%d ..."%(tbname, count))
for i in range(count):
sql += " (%d,%d)"%(ts_start + i*1000, i)
if i >0 and i%batch_num == 0:
tdSql.execute(sql)
sql = pre_insert
# end sql
if sql != pre_insert:
tdSql.execute(sql)
return
# test case1 base
def test_case1(self):
#
# delete from single table
#
# where <
sql = "select count(*) from t0 where ts < 1500000120000"
tdSql.query(sql)
tdSql.checkData(0, 0, 120)
sql = "delete from t0 where ts < 1500000120000"
tdSql.execute(sql)
tdSql.checkAffectedRows(120)
sql = "select count(*) from t0"
tdSql.query(sql)
tdSql.checkData(0, 0, 10000 - 120 )
sql = "select * from t0 limit 1"
tdSql.query(sql)
tdSql.checkData(0, 1, 120)
# where > and <
sql = "delete from t0 where ts > 1500000240000 and ts <= 1500000300000"
tdSql.execute(sql)
tdSql.checkAffectedRows(60)
sql = "select count(*) from t0"
tdSql.query(sql)
tdSql.checkData(0, 0, 10000 - 120 - 60)
sql = "select * from t0 limit 2 offset 120"
tdSql.query(sql)
tdSql.checkData(0, 1, 240)
tdSql.checkData(1, 1, 301)
# where > delete 1000 rows from end
sql = "delete from t0 where ts >= 1500009000000; "
tdSql.execute(sql)
tdSql.checkAffectedRows(1000)
sql = "select count(*) from t0"
tdSql.query(sql)
tdSql.checkData(0, 0, 10000 - 120 - 60 - 1000)
sql = "select last_row(*) from t0; "
tdSql.query(sql)
tdSql.checkData(0, 1, 8999)
sql = "select last(*) from t0"
tdSql.query(sql)
tdSql.checkData(0, 1, 8999)
# insert last_row
sql = "insert into t0 values(1500009999000,9999); "
tdSql.execute(sql)
sql = "select last_row(*) from t0; "
tdSql.query(sql)
tdSql.checkData(0, 1, 9999)
sql = "select last(*) from t0"
tdSql.query(sql)
tdSql.checkData(0, 1, 9999)
# insert last
sql = "insert into t0 values(1500010000000,10000); "
tdSql.execute(sql)
sql = "insert into t0 values(1500010002000,NULL); "
tdSql.execute(sql)
sql = "insert into t0 values(1500010001000,10001); "
tdSql.execute(sql)
sql = "delete from t0 where ts = 1500010001000; "
tdSql.execute(sql)
sql = "select last_row(i1) from t0; "
tdSql.query(sql)
tdSql.checkData(0, 0, None)
sql = "select last(i1) from t0; "
tdSql.query(sql)
tdSql.checkData(0, 0, 10000)
# delete whole
sql = "delete from t0;"
tdSql.execute(sql)
tdSql.checkAffectedRows(8823)
return
# test advance
def test_case2(self):
#
# delete from super table
#
# where <
sql = "select count(*) from st where ts < 1500000120000;"
tdSql.query(sql)
tdSql.checkData(0, 0, 9*120) #1080
sql = "delete from st where ts < 1500000120000;"
tdSql.execute(sql)
tdSql.checkAffectedRows(9*120) #1080
sql = "select count(*) from st;"
tdSql.query(sql)
tdSql.checkData(0, 0, 540000 - 9*120 )
sql = "select * from st limit 1;"
tdSql.query(sql)
tdSql.checkData(0, 1, 120)
# where > and <
sql = "delete from st where ts > 1500000240000 and ts <= 1500000300000;"
tdSql.execute(sql)
tdSql.checkAffectedRows(9*60)
sql = "select count(*) from st;"
tdSql.query(sql)
tdSql.checkData(0, 0, 540000 - 9*120 - 9*60)
sql = "select * from st limit 2 offset 120"
tdSql.query(sql)
tdSql.checkData(0, 1, 240)
tdSql.checkData(1, 1, 301)
# where > delete 1000 rows from end
sql = "delete from st where ts >= 1500009000000; "
tdSql.execute(sql)
tdSql.checkAffectedRows(459000)
sql = "select count(*) from st;"
tdSql.query(sql)
tdSql.checkData(0, 0, 79380)
sql = "select last_row(*) from st; "
tdSql.query(sql)
tdSql.checkData(0, 1, 8999)
sql = "select last(*) from st"
tdSql.query(sql)
tdSql.checkData(0, 1, 8999)
# insert last_row
sql = "insert into t0 values(1500009999000,9999); "
tdSql.execute(sql)
sql = "select last_row(*) from st; "
tdSql.query(sql)
tdSql.checkData(0, 1, 9999)
sql = "select last(*) from st"
tdSql.query(sql)
tdSql.checkData(0, 1, 9999)
# insert last
sql = "insert into t0 values(1500010000000,10000); "
tdSql.execute(sql)
sql = "insert into t0 values(1500010002000,NULL); "
tdSql.execute(sql)
sql = "insert into t0 values(1500010001000,10001); "
tdSql.execute(sql)
sql = "delete from t0 where ts = 1500010001000; "
tdSql.execute(sql)
sql = "select last_row(i1) from st; "
tdSql.query(sql)
tdSql.checkData(0, 0, None)
sql = "select last(i1) from st; "
tdSql.query(sql)
tdSql.checkData(0, 0, 10000)
# delete whole
sql = "delete from st;"
tdSql.execute(sql)
tdSql.checkAffectedRows(79383)
return
# verify function results after delete
def test_case3(self):
tdSql.execute("create database test")
tdSql.execute("use test")
self.create_tables()
# insert data
for i in range(10):
tbname = "t%d"%i
self.insert_data(tbname, self.ts, (i+1)*10000, 20000);
tdSql.query("select count(*) from st")
tdSql.checkData(0, 0, 550000)
count = tdSql.getData(0, 0)
tdSql.query("select sum(i1) from st")
sum = tdSql.getData(0, 0)
tdSql.query("select avg(i1) from st")
avg = tdSql.getData(0, 0)
tdSql.query("select count(*) from t0")
count1 = tdSql.getData(0, 0)
tdSql.query("select sum(i1) from t0")
sum1 = tdSql.getData(0, 0)
tdSql.query("select avg(i1) from t0")
avg1 = tdSql.getData(0, 0)
tdSql.execute("delete from st where tbname='t0'")
tdSql.checkAffectedRows(count1)
tdSql.query("select count(*) from st")
tdSql.checkData(0, 0, count - count1)
tdSql.query("select sum(i1) from st")
tdSql.checkData(0, 0, sum - sum1)
tdSql.query("select avg(i1) from st")
tdSql.checkData(0, 0, (sum - sum1) / (count - count1))
#
# add case with filename
#
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
\ No newline at end of file
......@@ -135,6 +135,33 @@ class TDTestCase:
tdSql.execute(sql)
tdSql.query('select bottom(c,1) from meters interval(10a)')
tdSql.checkData(0,1,0)
# TD-15187 test case
tdSql.execute("create database dd keep 36500")
tdSql.execute("use dd")
tdSql.execute("create table table_1(ts timestamp , q_int int,q_bool bool)")
tdSql.execute("insert into table_1 (ts , q_int,q_bool) values(1630000000000, 1,0)")
tdSql.execute("insert into table_1 (ts , q_int,q_bool) values(1630000010000, 2,0)")
tdSql.execute("insert into table_1 (ts , q_int,q_bool) values(1630000020000, 3,0)")
tdSql.execute("insert into table_1 (ts , q_int,q_bool) values(1630000100000, 3,0)")
tdSql.execute("insert into table_1 (ts , q_int,q_bool) values(1630000110000, 2,0)")
tdSql.execute("insert into table_1 (ts , q_int,q_bool) values(1630000120000, 1,0)")
tdSql.query("select BOTTOM(q_int,40) from table_1 SESSION(ts,10m) order by ts")
tdSql.checkData(0, 1, 1)
tdSql.checkData(1, 1, 2)
tdSql.checkData(2, 1, 3)
tdSql.checkData(3, 1, 3)
tdSql.checkData(4, 1, 2)
tdSql.checkData(5, 1, 1)
tdSql.query("select BOTTOM(q_int,40) from table_1 SESSION(ts,10m) order by ts desc;")
tdSql.checkData(0, 1, 1)
tdSql.checkData(1, 1, 2)
tdSql.checkData(2, 1, 3)
tdSql.checkData(3, 1, 3)
tdSql.checkData(4, 1, 2)
tdSql.checkData(5, 1, 1)
def stop(self):
tdSql.close()
......
......@@ -60,6 +60,9 @@ class TDTestCase:
# test advance case
self.test_case2()
tdLog.debug(" DELETE test_case2 ............ [OK]")
# test delete with functions
self.test_case3()
tdLog.debug(" DELETE test_case3 ............ [OK]")
# stop
......@@ -277,6 +280,48 @@ class TDTestCase:
tdSql.checkAffectedRows(79383)
return
# verify function results after delete
def test_case3(self):
tdSql.execute("create database test")
tdSql.execute("use test")
self.create_tables()
# insert data
for i in range(10):
tbname = "t%d"%i
self.insert_data(tbname, self.ts, (i+1)*10000, 20000);
tdSql.query("select count(*) from st")
tdSql.checkData(0, 0, 550000)
count = tdSql.getData(0, 0)
tdSql.query("select sum(i1) from st")
sum = tdSql.getData(0, 0)
tdSql.query("select avg(i1) from st")
avg = tdSql.getData(0, 0)
tdSql.query("select count(*) from t0")
count1 = tdSql.getData(0, 0)
tdSql.query("select sum(i1) from t0")
sum1 = tdSql.getData(0, 0)
tdSql.query("select avg(i1) from t0")
avg1 = tdSql.getData(0, 0)
tdSql.execute("delete from st where tbname='t0'")
tdSql.checkAffectedRows(count1)
tdSql.query("select count(*) from st")
tdSql.checkData(0, 0, count - count1)
tdSql.query("select sum(i1) from st")
tdSql.checkData(0, 0, sum - sum1)
tdSql.query("select avg(i1) from st")
tdSql.checkData(0, 0, (sum - sum1) / (count - count1))
#
# add case with filename
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册