diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index b8bb94b26d5117cb9e99468dfa94155ca70c4193..034716c4d3f8379d8434b45890f24e4235b729e9 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -345,6 +345,7 @@ python3 ./test.py -f functions/function_spread.py -r 1 python3 ./test.py -f functions/function_stddev.py -r 1 python3 ./test.py -f functions/function_sum.py -r 1 python3 ./test.py -f functions/function_top.py -r 1 +python3 ./test.py -f functions/function_sample.py -r 1 python3 ./test.py -f functions/function_twa.py -r 1 python3 ./test.py -f functions/function_twa_test2.py python3 ./test.py -f functions/function_stddev_td2555.py diff --git a/tests/pytest/functions/function_sample.py b/tests/pytest/functions/function_sample.py new file mode 100644 index 0000000000000000000000000000000000000000..88deb8dc6c319bf96ba00752ad1e1f6e9fd33457 --- /dev/null +++ b/tests/pytest/functions/function_sample.py @@ -0,0 +1,69 @@ +################################################################### +# 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 +import collections + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.sample_times = 10000 + self.ts = 1537146000000 + + def run(self): + 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))''') + tdSql.execute("create table test1 using test tags('beijing')") + 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, i, 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)) + + + print("begin sampling") + freqDict = collections.defaultdict(int) + for i in range(self.sample_times): + tdSql.query('select sample(col1, 2) from test1') + res1 = tdSql.getData(0, 1); + res2 = tdSql.getData(1, 1); + freqDict[res1] = freqDict[res1] + 1 + freqDict[res2] = freqDict[res2] + 1 + print("end sampling") + + lower_bound = self.sample_times/5 - self.sample_times/50; + upper_bound = self.sample_times/5 + self.sample_times/50; + for i in range(self.rowNum): + print("{} are sampled in {} times", i, freqDict[i]) + + if not (freqDict[i]>lower_bound and freqDict[i]