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

Merge pull request #12326 from taosdata/xiaoping/cases

test: add test cases for state_window
......@@ -14,25 +14,27 @@
*/
// TAOS standard API example. The same syntax as MySQL, but only a subset
// to compile: gcc -o tqdemo tqdemo.c -ltaos
// to compile: gcc -o tqdemo tqdemo.c -ltaos -lcurl
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <taos.h> // TAOS header file
#include <curl/curl.h>
void print_results(TAOS *taos, char *qstr);
void restful_demo(char *host, char *qstr);
int main(int argc, char *argv[]) {
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) {
......@@ -43,7 +45,7 @@ int main(int argc, char *argv[]) {
TAOS_RES* res;
// create topic
res = taos_query(taos, "create topic tq_test partitions 10");
taos_free_result(res);
taos_free_result(res);
res = taos_query(taos, "use tq_test");
taos_free_result(res);
......@@ -60,10 +62,13 @@ int main(int argc, char *argv[]) {
}
// query data
print_results(taos, "select * from tq_test.ps");
// print_results(taos, "select * from tq_test.ps");
taos_close(taos);
taos_cleanup();
// restful demo
restful_demo(argv[1], "show topics");
}
......@@ -92,3 +97,26 @@ void print_results(TAOS *taos, char *qstr) {
}
taos_free_result(res);
}
void restful_demo(char *host, char *qstr) {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl == NULL) {
printf("failed to create curl connection");
return;
}
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Authorization: Basic cm9vdDp0YW9zZGF0YQ==");
char url[1000];
sprintf(url, "%s:6041/rest/sql", host);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, qstr);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
......@@ -19,7 +19,8 @@ from util.sql import *
import numpy as np
class TDTestCase:
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor())
......@@ -42,8 +43,12 @@ class TDTestCase:
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))
for i in range(10):
sql = "insert into dev_002 (ts,t1) values "
for j in range(int(self.rowNum / 1000)):
sql += "(%d, %d,)" % (self.ts + i * 1000 + j, i * 1000 + j + 1)
tdSql.execute(sql)
tdSql.query("select count(ts) from dev_001 state_window(t1)")
tdSql.checkRows(3)
......@@ -70,7 +75,7 @@ class TDTestCase:
tdSql.checkRows(3)
tdSql.checkData(1, 0, 2)
tdSql.query("select count(ts) from dev_002 state_window(t1)")
tdSql.checkRows(100000)
tdSql.checkRows(1000)
# 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);")
......@@ -100,7 +105,43 @@ class TDTestCase:
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)")
# TD-15164, TD-15226, TD-15227, TD-15186
tdSql.execute("drop database if exists dd")
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 STDDEV(q_int) from table_1 STATE_WINDOW(q_bool) order by ts ")
tdSql.checkData(0, 0, 0.8164965)
tdSql.query("select STDDEV(q_int) from table_1 STATE_WINDOW(q_bool) order by ts desc")
tdSql.checkData(0, 0, 0.8164965)
tdSql.query("select MAX(q_int) from table_1 STATE_WINDOW(q_bool) order by ts;")
tdSql.checkData(0, 0, 3)
tdSql.query("select MAX(q_int) from table_1 STATE_WINDOW(q_bool) order by ts desc;")
tdSql.checkData(0, 0, 3)
tdSql.query("select MAX(q_int) from table_1 where q_bool in ( true , false) STATE_WINDOW(q_bool) order by ts desc")
tdSql.checkData(0, 0, 3)
tdSql.query("select TOP(q_int,3) from table_1 STATE_WINDOW(q_bool) order by ts")
tdSql.checkData(0, 1, 2)
tdSql.checkData(1, 1, 3)
tdSql.checkData(2, 1, 3)
tdSql.query("select TOP(q_int,3) from table_1 STATE_WINDOW(q_bool) order by ts desc")
tdSql.checkData(0, 1, 3)
tdSql.checkData(1, 1, 3)
tdSql.checkData(2, 1, 2)
def stop(self):
tdSql.close()
......
......@@ -62,6 +62,54 @@ class TDTestCase:
tdSql.query("select sum(k) from t1 interval(1d) sliding(1h)")
tdSql.checkRows(24)
# TD-14690
tdSql.execute("drop database if exists ceil")
tdSql.execute("create database ceil keep 36500")
tdSql.execute("use ceil")
tdSql.execute("create stable stable_1 (ts timestamp , q_nchar nchar(20) ) tags(loc nchar(100))")
tdSql.execute("create table stable_1_1 using stable_1 tags('stable_1_1')")
tdSql.execute("create table stable_1_2 using stable_1 tags('stable_1_2')")
self.ts = 1630000000000
for i in range(10):
if i <= 5:
tdSql.execute("insert into stable_1_1 (ts , q_nchar) values(%d, %d)" % (self.ts + i * 1000, i % 5 + 1))
tdSql.execute("insert into stable_1_2 (ts , q_nchar) values(%d, %d)" % (self.ts + i * 1000, i % 5 + 1))
else:
tdSql.execute("insert into stable_1_1 (ts , q_nchar) values(%d, %d)" % (self.ts + 39000 + i * 1000, i % 5))
tdSql.execute("insert into stable_1_2 (ts , q_nchar) values(%d, %d)" % (self.ts + 10000 + i * 1000, i % 5 + 1))
tdSql.execute("insert into stable_1_1 (ts , q_nchar) values(%d, %d)" % (1630000049000, 5))
tdSql.execute("insert into stable_1_2 (ts , q_nchar) values(%d, %d)" % (1630000020000, 1))
tdSql.query("select COUNT(q_nchar) from stable_1 interval(20s) sliding(10s) order by ts")
tdSql.checkRows(6)
tdSql.checkData(0, 1, 12)
tdSql.checkData(1, 1, 16)
tdSql.checkData(2, 1, 5)
tdSql.checkData(3, 1, 1)
tdSql.checkData(4, 1, 5)
tdSql.checkData(5, 1, 5)
tdSql.query("select COUNT(q_nchar) from (select * from stable_1) interval(20s) sliding(10s) order by ts")
tdSql.checkRows(6)
tdSql.checkData(0, 1, 12)
tdSql.checkData(1, 1, 16)
tdSql.checkData(2, 1, 5)
tdSql.checkData(3, 1, 1)
tdSql.checkData(4, 1, 5)
tdSql.checkData(5, 1, 5)
tdSql.query("select COUNT(q_nchar) from (select * from stable_1 order by ts) interval(20s) sliding(10s);")
tdSql.checkRows(6)
tdSql.checkData(0, 1, 12)
tdSql.checkData(1, 1, 16)
tdSql.checkData(2, 1, 5)
tdSql.checkData(3, 1, 1)
tdSql.checkData(4, 1, 5)
tdSql.checkData(5, 1, 5)
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册