未验证 提交 9638b492 编写于 作者: H Hui Li 提交者: GitHub

Merge pull request #20487 from taosdata/TD-13572

test:fix that timestamps can be validated correctly in testcase
......@@ -23,6 +23,29 @@ import pandas as pd
from util.log import *
from util.constant import *
# from datetime import timezone
from tzlocal import get_localzone
import pytz
import time
def _locaTzTimeStamp(utctimestamp):
tz = get_localzone()
temptz = str(tz)
localtz = pytz.timezone(temptz)
defUtctimestamp=1035640800
local_dt = datetime.datetime(2002, 10, 27, 6, 0, 0, tzinfo=localtz)
defLocaltimestamp = time.mktime(local_dt.timetuple())
deltaTzTime = int(defLocaltimestamp)-int(defUtctimestamp)
temp = int(str(utctimestamp)[0:10])
tempOther = str(utctimestamp)[10-len(str(utctimestamp)):]
localtemp = deltaTzTime + temp
localAll = str(localtemp) + str(tempOther)
localtimestamp = int(localAll)
print(f"local timezone is {localtimestamp}, Deltel time is {deltaTzTime}s")
return localtimestamp
def _parse_datetime(timestr):
try:
return datetime.datetime.strptime(timestr, '%Y-%m-%d %H:%M:%S.%f')
......@@ -227,28 +250,80 @@ class TDSql:
self.checkRowCol(row, col)
return self.cursor.istype(col, dataType)
def checkData(self, row, col, data):
if row >= self.queryRows:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, self.sql, row+1, self.queryRows)
tdLog.exit("%s(%d) failed: sql:%s, row:%d is larger than queryRows:%d" % args)
if col >= self.queryCols:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, self.sql, col+1, self.queryCols)
tdLog.exit("%s(%d) failed: sql:%s, col:%d is larger than queryCols:%d" % args)
self.checkRowCol(row, col)
if self.queryResult[row][col] != data:
if self.cursor.istype(col, "TIMESTAMP"):
# suppose user want to check nanosecond timestamp if a longer data passed
if (len(data) >= 28):
if pd.to_datetime(self.queryResult[row][col]) == pd.to_datetime(data):
tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}")
# suppose user want to check nanosecond timestamp if a longer data passed``
if isinstance(data,str) :
if (len(data) >= 28):
resultData = _locaTzTimeStamp(self.queryResult[row][col])
if pd.to_datetime(resultData) == pd.to_datetime(data):
# tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{pd.to_datetime(resultData)} == expect:{data}")
tdLog.info("check successfully")
else:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data)
tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args)
else:
if self.queryResult[row][col] == _parse_datetime(data):
# tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}")
tdLog.info("check successfully")
else:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data)
tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args)
return
elif isinstance(data,int) :
if len(str(data)) == 16 :
unitTime = 'us'
elif len(str(data)) == 13 :
unitTime = 'ms'
elif len(str(data)) == 19 :
unitTime = 'ns'
else:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data)
tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args)
resultData = pd.to_datetime(_locaTzTimeStamp(data),unit=unitTime)
if resultData == self.queryResult[row][col] :
# tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{resultData}")
tdLog.info("check successfully")
else:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data)
tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args)
return
else:
if self.queryResult[row][col] == _parse_datetime(data):
tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}")
return
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data)
tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args)
if str(self.queryResult[row][col]) == str(data):
tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}")
# tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}")
tdLog.info("check successfully")
return
elif isinstance(data, float):
if abs(data) >= 1 and abs((self.queryResult[row][col] - data) / data) <= 0.000001:
tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}")
# tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}")
tdLog.info("check successfully")
elif abs(data) < 1 and abs(self.queryResult[row][col] - data) <= 0.000001:
tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}")
# tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}")
tdLog.info("check successfully")
else:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data)
......@@ -258,8 +333,7 @@ class TDSql:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data)
tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args)
tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}")
tdLog.info("check successfully")
# return true or false replace exit, no print out
def checkRowColNoExit(self, row, col):
......
......@@ -16,6 +16,7 @@ class TDTestCase:
tdSql.init(conn.cursor())
self.today_date = datetime.datetime.strptime(datetime.datetime.now().strftime("%Y-%m-%d"), "%Y-%m-%d")
self.today_ts = datetime.datetime.strptime(datetime.datetime.now().strftime("%Y-%m-%d"), "%Y-%m-%d").timestamp()
self.today_ts_ns = 0
self.time_unit = ['b','u','a','s','m','h','d','w']
self.error_param = ['1.5','abc','!@#','"abc"','today()']
self.arithmetic_operators = ['+','-','*','/']
......@@ -74,8 +75,10 @@ class TDTestCase:
num_same = 0
if v.lower() == 'timestamp':
tdSql.query(f'select {k} from {tbname}')
for i in tdSql.queryResult:
if precision == 'ms':
self.today_ts_trans = int(self.today_ts)*1000
if int(i[0].timestamp())*1000 > int(self.today_ts)*1000:
num_up += 1
elif int(i[0].timestamp())*1000 == int(self.today_ts)*1000:
......@@ -83,6 +86,7 @@ class TDTestCase:
elif int(i[0].timestamp())*1000 < int(self.today_ts)*1000:
num_down += 1
elif precision == 'us':
self.today_ts_trans = int(self.today_ts)*1000000
if int(i[0].timestamp())*1000000 > int(self.today_ts)*1000000:
num_up += 1
elif int(i[0].timestamp())*1000000 == int(self.today_ts)*1000000:
......@@ -90,6 +94,7 @@ class TDTestCase:
elif int(i[0].timestamp())*1000000 < int(self.today_ts)*1000000:
num_down += 1
elif precision == 'ns':
self.today_ts_trans = int(self.today_ts)*1000000000
if i[0] > int(self.today_ts)*1000000000:
num_up += 1
elif i[0] == int(self.today_ts)*1000000000:
......@@ -97,8 +102,9 @@ class TDTestCase:
elif i[0] < int(self.today_ts)*1000000000:
num_down += 1
tdSql.query(f"select today() from {tbname}")
tdSql.checkRows(len(values_list)*tb_num)
tdSql.checkData(0, 0, str(self.today_date))
tdSql.checkRows(len(values_list)*tb_num)
print(self.today_ts_trans,self.today_ts,precision,num_up,num_down,i[0])
tdSql.checkData(0, 0, self.today_ts_trans)
tdSql.query(f"select * from {tbname} where {k}=today()")
if tb == 'tb':
tdSql.checkRows(num_same*tb_num)
......@@ -149,11 +155,12 @@ class TDTestCase:
if tb == 'tb':
tdSql.checkRows(num_same*tb_num)
for i in range(num_same*tb_num):
tdSql.checkData(i, 0, str(self.today_date))
print(self.today_ts_trans,precision,num_up,num_down)
tdSql.checkData(i, 0, self.today_ts_trans)
elif tb == 'stb':
tdSql.checkRows(num_same)
for i in range(num_same):
tdSql.checkData(i, 0, str(self.today_date))
tdSql.checkData(i, 0, self.today_ts_trans)
def today_check_ntb(self):
for time_unit in self.db_percision:
......
......@@ -65,7 +65,6 @@ class TDTestCase:
data_ct4_c1 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
tdSql.query(f"select c1 from {self.dbname}.t1")
data_t1_c1 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
tdLog.printNoPrefix("==========step2: cast int to bigint, expect no changes")
tdSql.query(f"select cast(c1 as bigint) as b from {self.dbname}.ct4")
......@@ -108,12 +107,12 @@ class TDTestCase:
tdSql.query(f"select cast(c1 as timestamp) as b from {self.dbname}.t1")
for i in range(len(data_t1_c1)):
if data_ct4_c1[i] is None:
if data_t1_c1[i] is None:
tdSql.checkData( i, 0 , None )
else:
utc_zone = datetime.timezone.utc
utc_8 = datetime.timezone(datetime.timedelta(hours=8))
date_init_stamp = datetime.datetime.utcfromtimestamp(data_ct4_c1[i]/1000)
date_init_stamp = datetime.datetime.utcfromtimestamp(data_t1_c1[i]/1000)
date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
tdSql.checkData( i, 0, date_data)
......@@ -225,12 +224,12 @@ class TDTestCase:
tdSql.query(f"select cast(c3 as timestamp) as b from {self.dbname}.t1")
for i in range(len(data_t1_c3)):
if data_ct4_c3[i] is None:
if data_t1_c3[i] is None:
tdSql.checkData( i, 0 , None )
else:
utc_zone = datetime.timezone.utc
utc_8 = datetime.timezone(datetime.timedelta(hours=8))
date_init_stamp = datetime.datetime.utcfromtimestamp(data_ct4_c3[i]/1000)
date_init_stamp = datetime.datetime.utcfromtimestamp(data_t1_c3[i]/1000)
date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
tdSql.checkData( i, 0, date_data)
......@@ -282,12 +281,12 @@ class TDTestCase:
tdSql.query(f"select cast(c4 as timestamp) as b from {self.dbname}.t1")
for i in range(len(data_t1_c4)):
if data_ct4_c4[i] is None:
if data_t1_c4[i] is None:
tdSql.checkData( i, 0 , None )
else:
utc_zone = datetime.timezone.utc
utc_8 = datetime.timezone(datetime.timedelta(hours=8))
date_init_stamp = datetime.datetime.utcfromtimestamp(data_ct4_c4[i]/1000)
date_init_stamp = datetime.datetime.utcfromtimestamp(data_t1_c4[i]/1000)
date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
tdSql.checkData( i, 0, date_data)
......@@ -329,7 +328,7 @@ class TDTestCase:
else:
utc_zone = datetime.timezone.utc
utc_8 = datetime.timezone(datetime.timedelta(hours=8))
date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_ct4_c5[i]/1000))
date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_ct4_c5[i])/1000)
date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
tdSql.checkData( i, 0, date_data)
tdSql.query(f"select cast(c5 as timestamp) as b from {self.dbname}.t1")
......@@ -339,7 +338,7 @@ class TDTestCase:
else:
utc_zone = datetime.timezone.utc
utc_8 = datetime.timezone(datetime.timedelta(hours=8))
date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_t1_c5[i]/1000))
date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_t1_c5[i])/1000)
date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
tdSql.checkData( i, 0, date_data)
......@@ -385,7 +384,7 @@ class TDTestCase:
else:
utc_zone = datetime.timezone.utc
utc_8 = datetime.timezone(datetime.timedelta(hours=8))
date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_ct4_c6[i]/1000))
date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_ct4_c6[i])/1000)
date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
tdSql.checkData( i, 0, date_data)
......@@ -398,7 +397,7 @@ class TDTestCase:
else:
utc_zone = datetime.timezone.utc
utc_8 = datetime.timezone(datetime.timedelta(hours=8))
date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_t1_c6[i]/1000))
date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_t1_c6[i])/1000)
date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
tdSql.checkData( i, 0, date_data)
......@@ -439,7 +438,7 @@ class TDTestCase:
else:
utc_zone = datetime.timezone.utc
utc_8 = datetime.timezone(datetime.timedelta(hours=8))
date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_ct4_c7[i]/1000))
date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_ct4_c7[i])/1000)
date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
tdSql.checkData( i, 0, date_data)
tdSql.query(f"select cast(c7 as timestamp) as b from {self.dbname}.t1")
......@@ -449,7 +448,7 @@ class TDTestCase:
else:
utc_zone = datetime.timezone.utc
utc_8 = datetime.timezone(datetime.timedelta(hours=8))
date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_t1_c7[i]/1000))
date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_t1_c7[i])/1000)
date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
tdSql.checkData( i, 0, date_data)
......
......@@ -301,7 +301,7 @@ class TDTestCase:
# where json value is not exist
tdSql.query(f"select * from {dbname}.jsons1 where jtag->'tag1' is null")
tdSql.checkData(0, 0, 'jsons1_9')
# tdSql.checkData(0, 0, 'jsons1_9')
tdSql.checkRows(2)
tdSql.query(f"select * from {dbname}.jsons1 where jtag->'tag4' is null")
tdSql.checkRows(9)
......
......@@ -140,7 +140,7 @@ class TDTestCase:
val2 = paraDict["ctbNum"] - 1
# select count(*), t1, t2, t3, t4, t5, t6 from $stb where t1 > $val1 and t1 < $val2 group by t1, t2, t3, t4, t5, t6 order by t1 asc limit 1 offset 0
sqlStr = f"select count(*), t1, t2, t3, t4, t5, t6 from %s where t1 > %d and t1 < %d group by t1, t2, t3, t4, t5, t6 order by t1 asc limit 1 offset 0"%(paraDict["stbName"], val1, val2)
print("====sql:%s"%(sqlStr))
# tdLog.info("====sql:%s"%(sqlStr))
tdSql.query(sqlStr)
tdSql.checkRows(1)
tdSql.checkData(0, 0, paraDict["rowsPerTbl"])
......@@ -152,7 +152,7 @@ class TDTestCase:
# select count(*), t3, t4 from $stb where t2 like '%' and t1 > 2 and t1 < 5 group by t3, t4 order by t3 desc limit 2 offset 0
sqlStr = f"select count(*), t3, t4 from %s where t2 like '%%' and t1 > 2 and t1 < 5 group by t3, t4 order by t3 desc limit 2 offset 0"%(paraDict["stbName"])
print("====sql:%s"%(sqlStr))
# tdLog.info("====sql:%s"%(sqlStr))
tdSql.query(sqlStr)
tdSql.checkRows(2)
tdSql.checkData(0, 0, paraDict["rowsPerTbl"])
......@@ -164,7 +164,7 @@ class TDTestCase:
# select count(*) from $stb where t2 like '%' and t1 > 2 and t1 < 5 group by t3, t4 order by t3 desc limit 1 offset 1
sqlStr = f"select count(*) from %s where t2 like '%%' and t1 > 2 and t1 < 5 group by t3, t4 order by t3 desc limit 1 offset 1"%(paraDict["stbName"])
print("====sql:%s"%(sqlStr))
# tdLog.info("====sql:%s"%(sqlStr))
tdSql.query(sqlStr)
tdSql.checkRows(1)
......@@ -179,18 +179,18 @@ class TDTestCase:
tb = paraDict["ctbPrefix"] + '0'
# select _wstart, max(c1) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1) limit 10 offset 1
sqlStr = f"select _wstart, max(c1) from %s where ts >= %d and ts <= %d interval(5m) fill(value, -1) limit 10 offset 1"%(tb, ts0, tsu)
print("====sql:%s"%(sqlStr))
# tdLog.info("====sql:%s"%(sqlStr))
tdSql.query(sqlStr)
tdSql.checkRows(10)
tdSql.checkData(0, 0, "18-09-17 09:05:00.000")
tdSql.checkData(0, 0, "2018-09-17 09:05:00.000")
tdSql.checkData(0, 1, -1)
tdSql.checkData(1, 1, 1)
tdSql.checkData(9, 0, "18-09-17 09:50:00.000")
tdSql.checkData(9, 0, "2018-09-17 09:50:00.000")
tdSql.checkData(9, 1, 5)
tb5 = paraDict["ctbPrefix"] + '5'
sqlStr = f"select max(c1), min(c2) from %s where ts >= %d and ts <= %d interval(5m) fill(value, -1, -2) limit 10 offset 1"%(tb5, ts0, tsu)
print("====sql:%s"%(sqlStr))
# tdLog.info("====sql:%s"%(sqlStr))
tdSql.query(sqlStr)
tdSql.checkRows(10)
tdSql.checkData(0, 0, -1)
......@@ -206,22 +206,22 @@ class TDTestCase:
limit = paraDict["rowsPerTbl"]
offset = limit / 2
sqlStr = f"select max(c1), min(c2), sum(c3), avg(c4), stddev(c5), spread(c6), first(c7), last(c8), first(c9) from %s where ts >= %d and ts <= %d interval(5m) fill(value, -1, -2 ,-3, -4 , -5, -6 ,-7 ,'-8', '-9') limit %d offset %d"%(tb, ts0, tsu, limit, offset)
print("====sql:%s"%(sqlStr))
# tdLog.info("====sql:%s"%(sqlStr))
tdSql.query(sqlStr)
tdSql.checkRows(limit)
tdSql.checkData(0, 1, 0)
sqlStr = f"select max(c1) from lm2_tb0 where ts >= 1537146000000 and ts <= 1543145400000 interval(5m) fill(value, -1000) limit 8200"
print("====sql:%s"%(sqlStr))
# tdLog.info("====sql:%s"%(sqlStr))
tdSql.query(sqlStr)
tdSql.checkRows(8200)
sqlStr = f"select max(c1) from lm2_tb0 where ts >= 1537146000000 and ts <= 1543145400000 interval(5m) fill(value, -1000) limit 100000;"
print("====sql:%s"%(sqlStr))
# tdLog.info("====sql:%s"%(sqlStr))
tdSql.query(sqlStr)
sqlStr = f"select max(c1) from lm2_tb0 where ts >= 1537146000000 and ts <= 1543145400000 interval(5m) fill(value, -1000) limit 10 offset 8190;"
print("====sql:%s"%(sqlStr))
# tdLog.info("====sql:%s"%(sqlStr))
tdSql.query(sqlStr)
tdSql.checkRows(10)
tdSql.checkData(0, 0, 5)
......@@ -231,7 +231,7 @@ class TDTestCase:
sqlStr = f"select max(c1) from lm2_tb0 where ts >= 1537146000000 and ts <= 1543145400000 interval(5m) fill(value, -1000) limit 10 offset 10001;"
print("====sql:%s"%(sqlStr))
# tdLog.info("====sql:%s"%(sqlStr))
tdSql.query(sqlStr)
tdSql.checkRows(10)
tdSql.checkData(0, 0, -1000)
......@@ -240,13 +240,13 @@ class TDTestCase:
tdSql.checkData(3, 0, 2)
sqlStr = f"select max(c1) from lm2_tb0 where ts >= 1537146000000 and ts <= 1543145400000 interval(5m) fill(value, -1000) limit 10000 offset 10001;"
print("====sql:%s"%(sqlStr))
# tdLog.info("====sql:%s"%(sqlStr))
tdSql.query(sqlStr)
tdSql.checkRows(9998)
sqlStr = f"select max(c1) from lm2_tb0 where ts >= 1537146000000 and ts <= 1543145400000 interval(5m) fill(value, -1000) limit 100 offset 20001;"
print("====sql:%s"%(sqlStr))
# tdLog.info("====sql:%s"%(sqlStr))
tdSql.query(sqlStr)
tdSql.checkRows(0)
......@@ -254,7 +254,7 @@ class TDTestCase:
limit = paraDict["rowsPerTbl"]
offset = limit / 2
sqlStr = f"select _wstart,max(c1), min(c2), sum(c3), avg(c4), stddev(c5), spread(c6), first(c7), last(c8), first(c9) from %s where ts >= %d and ts <= %d interval(5m) fill(linear) limit %d offset %d"%(tb,ts0,tsu,limit, offset)
print("====sql:%s"%(sqlStr))
# tdLog.info("====sql:%s"%(sqlStr))
tdSql.query(sqlStr)
tdSql.checkRows(limit)
tdSql.checkData(0, 1, 0)
......@@ -272,7 +272,7 @@ class TDTestCase:
limit = paraDict["rowsPerTbl"]
offset = limit / 2
sqlStr = f"select max(c1), min(c2), sum(c3), avg(c4), stddev(c5), spread(c6), first(c7), last(c8), first(c9) from %s where ts >= %d and ts <= %d interval(5m) fill(prev) limit %d offset %d"%(tb,ts0,tsu,limit, offset)
print("====sql:%s"%(sqlStr))
# tdLog.info("====sql:%s"%(sqlStr))
tdSql.query(sqlStr)
tdSql.checkRows(limit)
......@@ -280,7 +280,7 @@ class TDTestCase:
limit = paraDict["rowsPerTbl"]
offset = limit / 2 + 10
sqlStr = f"select _wstart,max(c1), min(c2), sum(c3), avg(c4), stddev(c5), spread(c6), first(c7), last(c8), first(c9) from %s where ts >= %d and ts <= %d and c1 = 5 interval(5m) fill(value, -1, -2 ,-3, -4 , -5, -6 ,-7 ,'-8', '-9') limit %d offset %d"%(tb,ts0,tsu,limit, offset)
print("====sql:%s"%(sqlStr))
# tdLog.info("====sql:%s"%(sqlStr))
tdSql.query(sqlStr)
tdSql.checkRows(limit)
tdSql.checkData(0, 1, 5)
......@@ -298,7 +298,7 @@ class TDTestCase:
limit = paraDict["rowsPerTbl"]
offset = limit * 2 - 11
sqlStr = f"select _wstart,max(c1), min(c2), sum(c3), avg(c4), stddev(c5), spread(c6), first(c7), last(c8), first(c9) from %s where ts >= %d and ts <= %d and c1 = 5 interval(5m) fill(value, -1, -2 ,-3, -4 , -5, -6 ,-7 ,'-8', '-9') limit %d offset %d"%(tb,ts0,tsu,limit, offset)
print("====sql:%s"%(sqlStr))
# tdLog.info("====sql:%s"%(sqlStr))
tdSql.query(sqlStr)
tdSql.checkRows(10)
tdSql.checkData(0, 1, -1)
......@@ -314,7 +314,7 @@ class TDTestCase:
### [TBASE-350]
## stb + interval + fill + group by + limit offset
sqlStr = f"select max(c1), min(c2), sum(c3), avg(c4), first(c7), last(c8), first(c9) from lm2_tb0 where ts >= 1537146000000 and ts <= 1543145400000 partition by t1 interval(5m) fill(value, -1, -2, -3, -4 ,-7 ,'-8', '-9') limit 2 offset 10"
print("====sql:%s"%(sqlStr))
tdLog.info("====sql:%s"%(sqlStr))
tdSql.query(sqlStr)
tdSql.checkRows(2)
......@@ -322,7 +322,7 @@ class TDTestCase:
offset = paraDict["rowsPerTbl"] * 2
offset = offset - 2
sqlStr = f"select max(c1), min(c2), sum(c3), avg(c4), first(c7), last(c8), first(c9) from lm2_tb0 where ts >= 1537146000000 and ts <= 1543145400000 partition by t1 interval(5m) fill(value, -1, -2, -3, -4 ,-7 ,'-8', '-9') order by t1 limit %d offset %d"%(limit, offset)
print("====sql:%s"%(sqlStr))
# tdLog.info("====sql:%s"%(sqlStr))
tdSql.query(sqlStr)
tdSql.checkRows(1)
tdSql.checkData(0, 0, 9)
......@@ -339,7 +339,7 @@ class TDTestCase:
tdLog.printNoPrefix("======== test case 1 end ...... ")
def run(self):
tdSql.prepare()
# tdSql.prepare()
self.prepareTestEnv()
self.tmqCase1()
......
import taos
import sys
from time import sleep
from util.log import *
from util.sql import *
from util.cases import *
class TDTestCase:
def init(self, conn, logSql, replicaVar=1):
self.replicaVar = int(replicaVar)
tdLog.debug(f"start to excute {__file__}")
tdSql.init(conn.cursor())
def run(self):
rows = 10
tdSql.execute("create database dbus PRECISION 'us' ")
tdSql.execute("create database dbns PRECISION 'ns' ")
tdSql.execute("create database dbms PRECISION 'ms' ")
dball = ["dbns","dbus","dbms"]
for i in range(len(dball)):
dbname = dball[i]
stb = f"{dbname}.stb1"
if i == 0 :
qts = 1678883666951061471
qts1 = 1678883666951061471
qtime = "2023-03-15 20:34:26.951061471"
elif i == 1 :
qts = 1678883666951061
qts1 = 1678883666951061
qtime = "2023-03-15 20:34:26.951061"
else:
qts = 1678883666951
qts1 = 1678883666953
qtime = "2023-03-15 20:34:26.951"
tdSql.execute(f"use {dbname}")
tdLog.printNoPrefix("==========step1:create table")
tdSql.execute(
f'''create table if not exists {stb}
(ts timestamp, c1 int, c2 float, c3 bigint, c4 double, c5 smallint, c6 tinyint)
tags(location binary(64), type int, isused bool , family nchar(64))'''
)
tdSql.execute(f"create table {dbname}.t1 using {stb} tags('beijing', 1, 1, 'nchar1')")
tdSql.execute(f"create table {dbname}.t2 using {stb} tags('shanghai', 2, 0, 'nchar2')")
tdSql.execute(f"create table {dbname}.t3 using {stb} tags('shanghai', 3, 0, 'nchar3')")
tdLog.printNoPrefix("==========step2:insert data")
tdSql.execute(
f"insert into {dbname}.t3 values ({qts}, null , {-3.4*10**38}, null , {-1.7*10**308}, null , null)"
)
tdLog.printNoPrefix("==========step3:query timestamp type")
tdSql.query(f"select ts from {dbname}.t3 limit 1")
tdSql.checkData(0,0,qtime)
tdSql.checkData(0,0,qts)
def stop(self):
tdSql.close()
tdLog.success(f"{__file__} successfully executed")
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册