add few more cases and support check data type in connector.

This commit is contained in:
Shuduo Sang 2020-05-20 14:17:40 +08:00
parent 3936e2df0d
commit 0280f36664
9 changed files with 6718 additions and 37 deletions

View File

@ -1,5 +1,7 @@
from .cinterface import CTaosInterface
from .error import *
from .constants import FieldType
class TDengineCursor(object):
"""Database cursor which is used to manage the context of a fetch operation.
@ -44,7 +46,8 @@ class TDengineCursor(object):
raise OperationalError("Invalid use of fetch iterator")
if self._block_rows <= self._block_iter:
block, self._block_rows = CTaosInterface.fetchBlock(self._result, self._fields)
block, self._block_rows = CTaosInterface.fetchBlock(
self._result, self._fields)
if self._block_rows == 0:
raise StopIteration
self._block = list(map(tuple, zip(*block)))
@ -112,13 +115,17 @@ class TDengineCursor(object):
res = CTaosInterface.query(self._connection._conn, stmt)
if res == 0:
if CTaosInterface.fieldsCount(self._connection._conn) == 0:
self._affected_rows += CTaosInterface.affectedRows(self._connection._conn)
self._affected_rows += CTaosInterface.affectedRows(
self._connection._conn)
return CTaosInterface.affectedRows(self._connection._conn)
else:
self._result, self._fields = CTaosInterface.useResult(self._connection._conn)
self._result, self._fields = CTaosInterface.useResult(
self._connection._conn)
return self._handle_result()
else:
raise ProgrammingError(CTaosInterface.errStr(self._connection._conn))
raise ProgrammingError(
CTaosInterface.errStr(
self._connection._conn))
def executemany(self, operation, seq_of_parameters):
"""Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters.
@ -130,6 +137,37 @@ class TDengineCursor(object):
"""
pass
def istype(self, col, dataType):
if (dataType.upper() == "BOOL"):
if (self._description[col][1] == FieldType.C_BOOL):
return True
if (dataType.upper() == "TINYINT"):
if (self._description[col][1] == FieldType.C_TINYINT):
return True
if (dataType.upper() == "INT"):
if (self._description[col][1] == FieldType.C_INT):
return True
if (dataType.upper() == "BIGINT"):
if (self._description[col][1] == FieldType.C_INT):
return True
if (dataType.upper() == "FLOAT"):
if (self._description[col][1] == FieldType.C_FLOAT):
return True
if (dataType.upper() == "DOUBLE"):
if (self._description[col][1] == FieldType.C_DOUBLE):
return True
if (dataType.upper() == "BINARY"):
if (self._description[col][1] == FieldType.C_BINARY):
return True
if (dataType.upper() == "TIMESTAMP"):
if (self._description[col][1] == FieldType.C_TIMESTAMP):
return True
if (dataType.upper() == "NCHAR"):
if (self._description[col][1] == FieldType.C_NCHAR):
return True
return False
def fetchmany(self):
pass
@ -142,8 +180,10 @@ class TDengineCursor(object):
buffer = [[] for i in range(len(self._fields))]
self._rowcount = 0
while True:
block, num_of_fields = CTaosInterface.fetchBlock(self._result, self._fields)
if num_of_fields == 0: break
block, num_of_fields = CTaosInterface.fetchBlock(
self._result, self._fields)
if num_of_fields == 0:
break
self._rowcount += num_of_fields
for i in range(len(self._fields)):
buffer[i].extend(block[i])
@ -152,8 +192,6 @@ class TDengineCursor(object):
return list(map(tuple, zip(*buffer)))
def nextset(self):
"""
"""
@ -182,6 +220,7 @@ class TDengineCursor(object):
"""
self._description = []
for ele in self._fields:
self._description.append((ele['name'], ele['type'], None, None, None, None, False))
self._description.append(
(ele['name'], ele['type'], None, None, None, None, False))
return self._result

View File

@ -1,8 +1,10 @@
from .cinterface import CTaosInterface
from .error import *
from .constants import FieldType
# querySeqNum = 0
class TDengineCursor(object):
"""Database cursor which is used to manage the context of a fetch operation.
@ -46,7 +48,8 @@ class TDengineCursor(object):
raise OperationalError("Invalid use of fetch iterator")
if self._block_rows <= self._block_iter:
block, self._block_rows = CTaosInterface.fetchBlock(self._result, self._fields)
block, self._block_rows = CTaosInterface.fetchBlock(
self._result, self._fields)
if self._block_rows == 0:
raise StopIteration
self._block = list(map(tuple, zip(*block)))
@ -111,7 +114,6 @@ class TDengineCursor(object):
if params is not None:
pass
# global querySeqNum
# querySeqNum += 1
# localSeqNum = querySeqNum # avoid raice condition
@ -121,13 +123,17 @@ class TDengineCursor(object):
if res == 0:
if CTaosInterface.fieldsCount(self._connection._conn) == 0:
self._affected_rows += CTaosInterface.affectedRows(self._connection._conn)
self._affected_rows += CTaosInterface.affectedRows(
self._connection._conn)
return CTaosInterface.affectedRows(self._connection._conn)
else:
self._result, self._fields = CTaosInterface.useResult(self._connection._conn)
self._result, self._fields = CTaosInterface.useResult(
self._connection._conn)
return self._handle_result()
else:
raise ProgrammingError(CTaosInterface.errStr(self._connection._conn))
raise ProgrammingError(
CTaosInterface.errStr(
self._connection._conn))
def executemany(self, operation, seq_of_parameters):
"""Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters.
@ -142,6 +148,37 @@ class TDengineCursor(object):
def fetchmany(self):
pass
def istype(self, col, dataType):
if (dataType.upper() == "BOOL"):
if (self._description[col][1] == FieldType.C_BOOL):
return True
if (dataType.upper() == "TINYINT"):
if (self._description[col][1] == FieldType.C_TINYINT):
return True
if (dataType.upper() == "INT"):
if (self._description[col][1] == FieldType.C_INT):
return True
if (dataType.upper() == "BIGINT"):
if (self._description[col][1] == FieldType.C_INT):
return True
if (dataType.upper() == "FLOAT"):
if (self._description[col][1] == FieldType.C_FLOAT):
return True
if (dataType.upper() == "DOUBLE"):
if (self._description[col][1] == FieldType.C_DOUBLE):
return True
if (dataType.upper() == "BINARY"):
if (self._description[col][1] == FieldType.C_BINARY):
return True
if (dataType.upper() == "TIMESTAMP"):
if (self._description[col][1] == FieldType.C_TIMESTAMP):
return True
if (dataType.upper() == "NCHAR"):
if (self._description[col][1] == FieldType.C_NCHAR):
return True
return False
def fetchall(self):
"""Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples). Note that the cursor's arraysize attribute can affect the performance of this operation.
"""
@ -151,8 +188,10 @@ class TDengineCursor(object):
buffer = [[] for i in range(len(self._fields))]
self._rowcount = 0
while True:
block, num_of_fields = CTaosInterface.fetchBlock(self._result, self._fields)
if num_of_fields == 0: break
block, num_of_fields = CTaosInterface.fetchBlock(
self._result, self._fields)
if num_of_fields == 0:
break
self._rowcount += num_of_fields
for i in range(len(self._fields)):
buffer[i].extend(block[i])
@ -161,8 +200,6 @@ class TDengineCursor(object):
return list(map(tuple, zip(*buffer)))
def nextset(self):
"""
"""
@ -191,6 +228,7 @@ class TDengineCursor(object):
"""
self._description = []
for ele in self._fields:
self._description.append((ele['name'], ele['type'], None, None, None, None, False))
self._description.append(
(ele['name'], ele['type'], None, None, None, None, False))
return self._result

View File

@ -22,6 +22,32 @@ python3 ./test.py $1 -f table/tablename-boundary.py
# tag
python3 ./test.py $1 -f tag_lite/filter.py
python3 ./test.py $1 -f tag_lite/create-tags-boundary.py
python3 ./test.py $1 -f tag_lite/3.py
python3 ./test.py $1 -f tag_lite/4.py
python3 ./test.py $1 -f tag_lite/5.py
python3 ./test.py $1 -f tag_lite/6.py
python3 ./test.py $1 -f tag_lite/add.py
python3 ./test.py $1 -f tag_lite/bigint.py
python3 ./test.py $1 -f tag_lite/binary_binary.py
python3 ./test.py $1 -f tag_lite/binary.py
python3 ./test.py $1 -f tag_lite/bool_binary.py
python3 ./test.py $1 -f tag_lite/bool_int.py
python3 ./test.py $1 -f tag_lite/bool.py
python3 ./test.py $1 -f tag_lite/change.py
python3 ./test.py $1 -f tag_lite/column.py
python3 ./test.py $1 -f tag_lite/commit.py
python3 ./test.py $1 -f tag_lite/create.py
python3 ./test.py $1 -f tag_lite/datatype.py
python3 ./test.py $1 -f tag_lite/datatype-without-alter.py
python3 ./test.py $1 -f tag_lite/delete.py
python3 ./test.py $1 -f tag_lite/double.py
python3 ./test.py $1 -f tag_lite/float.py
python3 ./test.py $1 -f tag_lite/int_binary.py
python3 ./test.py $1 -f tag_lite/int_float.py
python3 ./test.py $1 -f tag_lite/int.py
python3 ./test.py $1 -f tag_lite/set.py
python3 ./test.py $1 -f tag_lite/smallint.py
python3 ./test.py $1 -f tag_lite/tinyint.py
python3 ./test.py $1 -f dbmgmt/database-name-boundary.py

1767
tests/pytest/tag_lite/add.py Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,876 @@
# -*- coding: utf-8 -*-
import sys
from util.log import *
from util.cases import *
from util.sql import *
class TDTestCase:
def init(self, conn):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor())
def run(self):
tdSql.prepare()
# TSIM: system sh/stop_dnodes.sh
# TSIM:
# TSIM:
# TSIM: system sh/deploy.sh -n dnode1 -i 1
# TSIM: system sh/cfg.sh -n dnode1 -c walLevel -v 0
# TSIM: system sh/exec.sh -n dnode1 -s start
# TSIM:
# TSIM: sleep 3000
# TSIM: sql connect
# TSIM:
# TSIM: print ======================== dnode1 start
tdLog.info('======================== dnode1 start')
# TSIM:
# TSIM: $dbPrefix = ta_se_db
# TSIM: $tbPrefix = ta_se_tb
tbPrefix = "ta_se_tb"
# TSIM: $mtPrefix = ta_se_mt
mtPrefix = "ta_se_mt"
# TSIM: $tbNum = 10
tbNum = 10
# TSIM: $rowNum = 20
rowNum = 20
# TSIM: $totalNum = 200
totalNum = 200
# TSIM:
# TSIM: print =============== step1
tdLog.info('=============== step1')
# TSIM: $i = 0
i = 0
# TSIM: $db = $dbPrefix . $i
# TSIM:
# TSIM: sql create database $db
# TSIM: sql use $db
# TSIM:
# TSIM: print =============== step2
tdLog.info('=============== step2')
# TSIM: $i = 2
i = 2
# TSIM: $mt = $mtPrefix . $i
mt = "%s%d" % (mtPrefix, i)
# TSIM: $tb = $tbPrefix . $i
tb = "%s%d" % (tbPrefix, i)
# TSIM: sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1
# bool, tgcol2 int)
tdLog.info(
'create table %s (ts timestamp, tbcol int) TAGS(tgcol1 bool, tgcol2 int)' %
(mt))
tdSql.execute(
'create table %s (ts timestamp, tbcol int) TAGS(tgcol1 bool, tgcol2 int)' %
(mt))
# TSIM: sql create table $tb using $mt tags( 1, 2 )
tdLog.info('create table %s using %s tags( 1, 2 )' % (tb, mt))
tdSql.execute('create table %s using %s tags( 1, 2 )' % (tb, mt))
# TSIM: sql insert into $tb values(now, 1)
tdLog.info('insert into %s values(now, 1)' % (tb))
tdSql.execute('insert into %s values(now, 1)' % (tb))
# TSIM: sql select * from $mt where tgcol1 = 1
tdLog.info('select * from %s where tgcol1 = 1' % (mt))
tdSql.query('select * from %s where tgcol1 = 1' % (mt))
# TSIM: if $rows != 1 then
tdLog.info('tdSql.checkRow(1)')
tdSql.checkRows(1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data01 != 1 then
tdLog.info('tdSql.checkData(0, 1, 1)')
tdSql.checkData(0, 1, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data02 != 1 then
tdLog.info('tdSql.checkData(0, 2, 1)')
tdSql.checkData(0, 2, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data03 != 2 then
tdLog.info('tdSql.checkData(0, 3, 2)')
tdSql.checkData(0, 3, 2)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: sql alter table $tb set tag tagcx 1 -x step21
tdLog.info('alter table %s set tag tagcx 1 -x step21' % (tb))
tdSql.error('alter table %s set tag tagcx 11' % (tb))
# TSIM: return -1
# TSIM: step21:
# TSIM: sql alter table $tb set tag tgcol1=false
tdLog.info('alter table %s set tag tgcol1=false' % (tb))
tdSql.execute('alter table %s set tag tgcol1=false' % (tb))
# TSIM: sql alter table $tb set tag tgcol2=4
tdLog.info('alter table %s set tag tgcol2=4' % (tb))
tdSql.execute('alter table %s set tag tgcol2=4' % (tb))
# TSIM:
# TSIM: sql reset query cache
tdLog.info('reset query cache')
tdSql.execute('reset query cache')
# TSIM:
# TSIM: sql select * from $mt where tgcol1 = false
tdLog.info('select * from %s where tgcol1 = false' % (mt))
tdSql.query('select * from %s where tgcol1 = false' % (mt))
# TSIM: print $data01 $data02 $data03
tdLog.info('$data01 $data02 $data03')
# TSIM: if $rows != 1 then
tdLog.info('tdSql.checkRow(1)')
tdSql.checkRows(1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data01 != 1 then
tdLog.info('tdSql.checkData(0, 1, 1)')
tdSql.checkData(0, 1, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data02 != 0 then
tdLog.info('tdSql.checkData(0, 2, 0)')
tdSql.checkData(0, 2, 0)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data03 != 4 then
tdLog.info('tdSql.checkData(0, 3, 4)')
tdSql.checkData(0, 3, 4)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: sql select * from $mt where tgcol2 = 4
tdLog.info('select * from %s where tgcol2 = 4' % (mt))
tdSql.query('select * from %s where tgcol2 = 4' % (mt))
# TSIM: print $data01 $data02 $data03
tdLog.info('$data01 $data02 $data03')
# TSIM: if $rows != 1 then
tdLog.info('tdSql.checkRow(1)')
tdSql.checkRows(1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data01 != 1 then
tdLog.info('tdSql.checkData(0, 1, 1)')
tdSql.checkData(0, 1, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data02 != 0 then
tdLog.info('tdSql.checkData(0, 2, 0)')
tdSql.checkData(0, 2, 0)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data03 != 4 then
tdLog.info('tdSql.checkData(0, 3, 4)')
tdSql.checkData(0, 3, 4)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: sql describe $tb
tdLog.info('describe %s' % (tb))
tdSql.query('describe %s' % (tb))
# TSIM: print $data21 $data23 $data32 $data33
tdLog.info('$data21 $data23 $data32 $data33')
# TSIM: if $data21 != BOOL then
tdLog.info('tdSql.checkDataType(2, 1, "BOOL")')
tdSql.checkDataType(2, 1, "BOOL")
# TSIM: return -1
#TSIM: endi
# TSIM: if $data31 != INT then
tdLog.info('tdSql.checkDataType(3, 1, "INT")')
tdSql.checkDataType(3, 1, "INT")
# TSIM: return -1
#TSIM: endi
# TSIM: if $data23 != false then
tdLog.info('tdSql.checkData(2, 3, false)')
tdSql.checkData(2, 3, false)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data33 != 4 then
tdLog.info('tdSql.checkData(3, 3, 4)')
tdSql.checkData(3, 3, 4)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: print =============== step3
tdLog.info('=============== step3')
# TSIM: $i = 3
i = 3
# TSIM: $mt = $mtPrefix . $i
mt = "%s%d" % (mtPrefix, i)
# TSIM: $tb = $tbPrefix . $i
tb = "%s%d" % (tbPrefix, i)
# TSIM: sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1
# smallint, tgcol2 tinyint)
tdLog.info(
'create table %s (ts timestamp, tbcol int) TAGS(tgcol1 smallint, tgcol2 tinyint)' %
(mt))
tdSql.execute(
'create table %s (ts timestamp, tbcol int) TAGS(tgcol1 smallint, tgcol2 tinyint)' %
(mt))
# TSIM: sql create table $tb using $mt tags( 1, 2 )
tdLog.info('create table %s using %s tags( 1, 2 )' % (tb, mt))
tdSql.execute('create table %s using %s tags( 1, 2 )' % (tb, mt))
# TSIM: sql insert into $tb values(now, 1)
tdLog.info('insert into %s values(now, 1)' % (tb))
tdSql.execute('insert into %s values(now, 1)' % (tb))
# TSIM: sql select * from $mt where tgcol1 = 1
tdLog.info('select * from %s where tgcol1 = 1' % (mt))
tdSql.query('select * from %s where tgcol1 = 1' % (mt))
# TSIM: if $rows != 1 then
tdLog.info('tdSql.checkRow(1)')
tdSql.checkRows(1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data01 != 1 then
tdLog.info('tdSql.checkData(0, 1, 1)')
tdSql.checkData(0, 1, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data02 != 1 then
tdLog.info('tdSql.checkData(0, 2, 1)')
tdSql.checkData(0, 2, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data03 != 2 then
tdLog.info('tdSql.checkData(0, 3, 2)')
tdSql.checkData(0, 3, 2)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: sql alter table $tb set tag tgcol1=3
tdLog.info('alter table %s set tag tgcol1=3' % (tb))
tdSql.execute('alter table %s set tag tgcol1=3' % (tb))
# TSIM: sql alter table $tb set tag tgcol2=4
tdLog.info('alter table %s set tag tgcol2=4' % (tb))
tdSql.execute('alter table %s set tag tgcol2=4' % (tb))
# TSIM:
# TSIM: sql reset query cache
tdLog.info('reset query cache')
tdSql.execute('reset query cache')
# TSIM:
# TSIM: sql select * from $mt where tgcol1 = 3
tdLog.info('select * from %s where tgcol1 = 3' % (mt))
tdSql.query('select * from %s where tgcol1 = 3' % (mt))
# TSIM: print $data01 $data02 $data03
tdLog.info('$data01 $data02 $data03')
# TSIM: if $rows != 1 then
tdLog.info('tdSql.checkRow(1)')
tdSql.checkRows(1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data01 != 1 then
tdLog.info('tdSql.checkData(0, 1, 1)')
tdSql.checkData(0, 1, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data02 != 3 then
tdLog.info('tdSql.checkData(0, 2, 3)')
tdSql.checkData(0, 2, 3)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data03 != 4 then
tdLog.info('tdSql.checkData(0, 3, 4)')
tdSql.checkData(0, 3, 4)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: sql select * from $mt where tgcol2 = 4
tdLog.info('select * from %s where tgcol2 = 4' % (mt))
tdSql.query('select * from %s where tgcol2 = 4' % (mt))
# TSIM: print $data01 $data02 $data03
tdLog.info('$data01 $data02 $data03')
# TSIM: if $rows != 1 then
tdLog.info('tdSql.checkRow(1)')
tdSql.checkRows(1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data01 != 1 then
tdLog.info('tdSql.checkData(0, 1, 1)')
tdSql.checkData(0, 1, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data02 != 3 then
tdLog.info('tdSql.checkData(0, 2, 3)')
tdSql.checkData(0, 2, 3)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data03 != 4 then
tdLog.info('tdSql.checkData(0, 3, 4)')
tdSql.checkData(0, 3, 4)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: sql select * from $mt where tgcol2 = 2
tdLog.info('select * from %s where tgcol2 = 2' % (mt))
tdSql.query('select * from %s where tgcol2 = 2' % (mt))
# TSIM: if $rows != 0 then
tdLog.info('tdSql.checkRow(0)')
tdSql.checkRows(0)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM:
# TSIM: print =============== step4
tdLog.info('=============== step4')
# TSIM: $i = 4
i = 4
# TSIM: $mt = $mtPrefix . $i
mt = "%s%d" % (mtPrefix, i)
# TSIM: $tb = $tbPrefix . $i
tb = "%s%d" % (tbPrefix, i)
# TSIM: sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1
# bigint, tgcol2 float)
tdLog.info(
'create table %s (ts timestamp, tbcol int) TAGS(tgcol1 bigint, tgcol2 float)' %
(mt))
tdSql.execute(
'create table %s (ts timestamp, tbcol int) TAGS(tgcol1 bigint, tgcol2 float)' %
(mt))
# TSIM: sql create table $tb using $mt tags( 1, 2 )
tdLog.info('create table %s using %s tags( 1, 2 )' % (tb, mt))
tdSql.execute('create table %s using %s tags( 1, 2 )' % (tb, mt))
# TSIM: sql insert into $tb values(now, 1)
tdLog.info('insert into %s values(now, 1)' % (tb))
tdSql.execute('insert into %s values(now, 1)' % (tb))
# TSIM: sql select * from $mt where tgcol1 = 1
tdLog.info('select * from %s where tgcol1 = 1' % (mt))
tdSql.query('select * from %s where tgcol1 = 1' % (mt))
# TSIM: if $rows != 1 then
tdLog.info('tdSql.checkRow(1)')
tdSql.checkRows(1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data01 != 1 then
tdLog.info('tdSql.checkData(0, 1, 1)')
tdSql.checkData(0, 1, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data02 != 1 then
tdLog.info('tdSql.checkData(0, 2, 1)')
tdSql.checkData(0, 2, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data03 != 2.00000 then
tdLog.info('tdSql.checkData(0, 3, 2.00000)')
tdSql.checkData(0, 3, 2.00000)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: sql alter table $tb set tag tgcol1=3
tdLog.info('alter table %s set tag tgcol1=3' % (tb))
tdSql.execute('alter table %s set tag tgcol1=3' % (tb))
# TSIM: sql alter table $tb set tag tgcol2=4
tdLog.info('alter table %s set tag tgcol2=4' % (tb))
tdSql.execute('alter table %s set tag tgcol2=4' % (tb))
# TSIM:
# TSIM: sql reset query cache
tdLog.info('reset query cache')
tdSql.execute('reset query cache')
# TSIM:
# TSIM: sql select * from $mt where tgcol1 = 3
tdLog.info('select * from %s where tgcol1 = 3' % (mt))
tdSql.query('select * from %s where tgcol1 = 3' % (mt))
# TSIM: print $data01 $data02 $data03
tdLog.info('$data01 $data02 $data03')
# TSIM: if $rows != 1 then
tdLog.info('tdSql.checkRow(1)')
tdSql.checkRows(1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data01 != 1 then
tdLog.info('tdSql.checkData(0, 1, 1)')
tdSql.checkData(0, 1, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data02 != 3 then
tdLog.info('tdSql.checkData(0, 2, 3)')
tdSql.checkData(0, 2, 3)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data03 != 4.00000 then
tdLog.info('tdSql.checkData(0, 3, 4.00000)')
tdSql.checkData(0, 3, 4.00000)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: sql select * from $mt where tgcol2 = 4
tdLog.info('select * from %s where tgcol2 = 4' % (mt))
tdSql.query('select * from %s where tgcol2 = 4' % (mt))
# TSIM: print $data01 $data02 $data03
tdLog.info('$data01 $data02 $data03')
# TSIM: if $rows != 1 then
tdLog.info('tdSql.checkRow(1)')
tdSql.checkRows(1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data01 != 1 then
tdLog.info('tdSql.checkData(0, 1, 1)')
tdSql.checkData(0, 1, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data02 != 3 then
tdLog.info('tdSql.checkData(0, 2, 3)')
tdSql.checkData(0, 2, 3)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data03 != 4.00000 then
tdLog.info('tdSql.checkData(0, 3, 4.00000)')
tdSql.checkData(0, 3, 4.00000)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM:
# TSIM: print =============== step5
tdLog.info('=============== step5')
# TSIM: $i = 5
i = 5
# TSIM: $mt = $mtPrefix . $i
mt = "%s%d" % (mtPrefix, i)
# TSIM: $tb = $tbPrefix . $i
tb = "%s%d" % (tbPrefix, i)
# TSIM: sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1
# double, tgcol2 binary(10))
tdLog.info(
'create table %s (ts timestamp, tbcol int) TAGS(tgcol1 double, tgcol2 binary(10))' %
(mt))
tdSql.execute(
'create table %s (ts timestamp, tbcol int) TAGS(tgcol1 double, tgcol2 binary(10))' %
(mt))
# TSIM: sql create table $tb using $mt tags( 1, '2' )
tdLog.info('create table %s using %s tags( 1, "2" )' % (tb, mt))
tdSql.execute('create table %s using %s tags( 1, "2" )' % (tb, mt))
# TSIM: sql insert into $tb values(now, 1)
tdLog.info('insert into %s values(now, 1)' % (tb))
tdSql.execute('insert into %s values(now, 1)' % (tb))
# TSIM: sql select * from $mt where tgcol2 = '2'
tdLog.info('select * from %s where tgcol2 = "2"' % (mt))
tdSql.query('select * from %s where tgcol2 = "2"' % (mt))
# TSIM: if $rows != 1 then
tdLog.info('tdSql.checkRow(1)')
tdSql.checkRows(1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data01 != 1 then
tdLog.info('tdSql.checkData(0, 1, 1)')
tdSql.checkData(0, 1, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data02 != 1.000000000 then
tdLog.info('tdSql.checkData(0, 2, 1.000000000)')
tdSql.checkData(0, 2, 1.000000000)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data03 != 2 then
tdLog.info('tdSql.checkData(0, 3, 2)')
tdSql.checkData(0, 3, 2)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: sql alter table $tb set tag tgcol1=3
tdLog.info('alter table %s set tag tgcol1=3' % (tb))
tdSql.execute('alter table %s set tag tgcol1=3' % (tb))
# TSIM: sql alter table $tb set tag tgcol2='4'
tdLog.info('alter table %s set tag tgcol2="4"' % (tb))
tdSql.execute('alter table %s set tag tgcol2="4"' % (tb))
# TSIM:
# TSIM: sql reset query cache
tdLog.info('reset query cache')
tdSql.execute('reset query cache')
# TSIM:
# TSIM: sql select * from $mt where tgcol1 = 3
tdLog.info('select * from %s where tgcol1 = 3' % (mt))
tdSql.query('select * from %s where tgcol1 = 3' % (mt))
# TSIM: print $data01 $data02 $data03
tdLog.info('$data01 $data02 $data03')
# TSIM: if $rows != 1 then
tdLog.info('tdSql.checkRow(1)')
tdSql.checkRows(1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data01 != 1 then
tdLog.info('tdSql.checkData(0, 1, 1)')
tdSql.checkData(0, 1, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data02 != 3.000000000 then
tdLog.info('tdSql.checkData(0, 2, 3.000000000)')
tdSql.checkData(0, 2, 3.000000000)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data03 != 4 then
tdLog.info('tdSql.checkData(0, 3, 4)')
tdSql.checkData(0, 3, 4)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: sql select * from $mt where tgcol2 = '4'
tdLog.info('select * from %s where tgcol2 = "4"' % (mt))
tdSql.query('select * from %s where tgcol2 = "4"' % (mt))
# TSIM: print $data01 $data02 $data03
tdLog.info('$data01 $data02 $data03')
# TSIM: if $rows != 1 then
tdLog.info('tdSql.checkRow(1)')
tdSql.checkRows(1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data01 != 1 then
tdLog.info('tdSql.checkData(0, 1, 1)')
tdSql.checkData(0, 1, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data02 != 3.000000000 then
tdLog.info('tdSql.checkData(0, 2, 3.000000000)')
tdSql.checkData(0, 2, 3.000000000)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data03 != 4 then
tdLog.info('tdSql.checkData(0, 3, 4)')
tdSql.checkData(0, 3, 4)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: print =============== step6
tdLog.info('=============== step6')
# TSIM: $i = 6
i = 6
# TSIM: $mt = $mtPrefix . $i
mt = "%s%d" % (mtPrefix, i)
# TSIM: $tb = $tbPrefix . $i
tb = "%s%d" % (tbPrefix, i)
# TSIM: sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1
# binary(10), tgcol2 int, tgcol3 smallint, tgcol4 binary(11), tgcol5
# double, tgcol6 binary(20))
tdLog.info(
'create table %s (ts timestamp, tbcol int) TAGS(tgcol1 binary(10), tgcol2 int, tgcol3 smallint, tgcol4 binary(11), tgcol5 double, tgcol6 binary(20))' %
(mt))
tdSql.execute(
'create table %s (ts timestamp, tbcol int) TAGS(tgcol1 binary(10), tgcol2 int, tgcol3 smallint, tgcol4 binary(11), tgcol5 double, tgcol6 binary(20))' %
(mt))
# TSIM: sql create table $tb using $mt tags( '1', 2, 3, '4', 5, '6' )
tdLog.info(
'create table %s using %s tags( "1", 2, 3, "4", 5, "6" )' %
(tb, mt))
tdSql.execute(
'create table %s using %s tags( "1", 2, 3, "4", 5, "6" )' %
(tb, mt))
# TSIM: sql insert into $tb values(now, 1)
tdLog.info('insert into %s values(now, 1)' % (tb))
tdSql.execute('insert into %s values(now, 1)' % (tb))
# TSIM: sql select * from $mt where tgcol1 = '1'
tdLog.info('select * from %s where tgcol1 = "1"' % (mt))
tdSql.query('select * from %s where tgcol1 = "1"' % (mt))
# TSIM: if $rows != 1 then
tdLog.info('tdSql.checkRow(1)')
tdSql.checkRows(1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data01 != 1 then
tdLog.info('tdSql.checkData(0, 1, 1)')
tdSql.checkData(0, 1, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data02 != 1 then
tdLog.info('tdSql.checkData(0, 2, 1)')
tdSql.checkData(0, 2, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data03 != 2 then
tdLog.info('tdSql.checkData(0, 3, 2)')
tdSql.checkData(0, 3, 2)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data04 != 3 then
tdLog.info('tdSql.checkData(0, 4, 3)')
tdSql.checkData(0, 4, 3)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data05 != 4 then
tdLog.info('tdSql.checkData(0, 5, 4)')
tdSql.checkData(0, 5, 4)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data06 != 5.000000000 then
tdLog.info('tdSql.checkData(0, 6, 5.000000000)')
tdSql.checkData(0, 6, 5.000000000)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data07 != 6 then
tdLog.info('tdSql.checkData(0, 7, 6)')
tdSql.checkData(0, 7, 6)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: sql alter table $mt drop tag tgcol3
tdLog.info('alter table %s drop tag tgcol3' % (mt))
tdSql.execute('alter table %s drop tag tgcol3' % (mt))
# TSIM: sql alter table $tb set tag tgcol1='7'
tdLog.info('alter table %s set tag tgcol1="7"' % (tb))
tdSql.execute('alter table %s set tag tgcol1="7"' % (tb))
# TSIM: sql alter table $tb set tag tgcol2=8
tdLog.info('alter table %s set tag tgcol2=8' % (tb))
tdSql.execute('alter table %s set tag tgcol2=8' % (tb))
# TSIM: sql alter table $tb set tag tgcol4='9'
tdLog.info('alter table %s set tag tgcol4="9"' % (tb))
tdSql.execute('alter table %s set tag tgcol4="9"' % (tb))
# TSIM: sql alter table $tb set tag tgcol5=10
tdLog.info('alter table %s set tag tgcol5=10' % (tb))
tdSql.execute('alter table %s set tag tgcol5=10' % (tb))
# TSIM: sql alter table $tb set tag tgcol6='11'
tdLog.info('alter table %s set tag tgcol6="11"' % (tb))
tdSql.execute('alter table %s set tag tgcol6="11"' % (tb))
# TSIM:
# TSIM: sql reset query cache
tdLog.info('reset query cache')
tdSql.execute('reset query cache')
# TSIM:
# TSIM: sql select * from $mt where tgcol1 = '7'
tdLog.info('select * from %s where tgcol1 = "7"' % (mt))
tdSql.query('select * from %s where tgcol1 = "7"' % (mt))
# TSIM: print $data01 $data02 $data03
tdLog.info('$data01 $data02 $data03')
# TSIM: if $rows != 1 then
tdLog.info('tdSql.checkRow(1)')
tdSql.checkRows(1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data01 != 1 then
tdLog.info('tdSql.checkData(0, 1, 1)')
tdSql.checkData(0, 1, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data02 != 7 then
tdLog.info('tdSql.checkData(0, 2, 7)')
tdSql.checkData(0, 2, 7)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data03 != 8 then
tdLog.info('tdSql.checkData(0, 3, 8)')
tdSql.checkData(0, 3, 8)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data04 != 9 then
tdLog.info('tdSql.checkData(0, 4, 9)')
tdSql.checkData(0, 4, 9)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data05 != 10.000000000 then
tdLog.info('tdSql.checkData(0, 5, 10.000000000)')
tdSql.checkData(0, 5, 10.000000000)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data06 != 11 then
tdLog.info('tdSql.checkData(0, 6, 11)')
tdSql.checkData(0, 6, 11)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data07 != NULL then
tdLog.info('tdSql.checkData(0, 7, NULL)')
tdSql.checkData(0, 7, None)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: sql select * from $mt where tgcol2 = 8
tdLog.info('select * from %s where tgcol2 = 8' % (mt))
tdSql.query('select * from %s where tgcol2 = 8' % (mt))
# TSIM: print $data01 $data02 $data03
tdLog.info('$data01 $data02 $data03')
# TSIM: if $rows != 1 then
tdLog.info('tdSql.checkRow(1)')
tdSql.checkRows(1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data01 != 1 then
tdLog.info('tdSql.checkData(0, 1, 1)')
tdSql.checkData(0, 1, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data02 != 7 then
tdLog.info('tdSql.checkData(0, 2, 7)')
tdSql.checkData(0, 2, 7)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data03 != 8 then
tdLog.info('tdSql.checkData(0, 3, 8)')
tdSql.checkData(0, 3, 8)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data04 != 9 then
tdLog.info('tdSql.checkData(0, 4, 9)')
tdSql.checkData(0, 4, 9)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data05 != 10.000000000 then
tdLog.info('tdSql.checkData(0, 5, 10.000000000)')
tdSql.checkData(0, 5, 10.000000000)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data06 != 11 then
tdLog.info('tdSql.checkData(0, 6, 11)')
tdSql.checkData(0, 6, 11)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data07 != NULL then
tdLog.info('tdSql.checkData(0, 7, NULL)')
tdSql.checkData(0, 7, None)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: sql select * from $mt where tgcol4 = '9'
tdLog.info('select * from %s where tgcol4 = "9"' % (mt))
tdSql.query('select * from %s where tgcol4 = "9"' % (mt))
# TSIM: print $data01 $data02 $data03
tdLog.info('$data01 $data02 $data03')
# TSIM: if $rows != 1 then
tdLog.info('tdSql.checkRow(1)')
tdSql.checkRows(1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data01 != 1 then
tdLog.info('tdSql.checkData(0, 1, 1)')
tdSql.checkData(0, 1, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data02 != 7 then
tdLog.info('tdSql.checkData(0, 2, 7)')
tdSql.checkData(0, 2, 7)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data03 != 8 then
tdLog.info('tdSql.checkData(0, 3, 8)')
tdSql.checkData(0, 3, 8)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data04 != 9 then
tdLog.info('tdSql.checkData(0, 4, 9)')
tdSql.checkData(0, 4, 9)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data05 != 10.000000000 then
tdLog.info('tdSql.checkData(0, 5, 10.000000000)')
tdSql.checkData(0, 5, 10.000000000)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data06 != 11 then
tdLog.info('tdSql.checkData(0, 6, 11)')
tdSql.checkData(0, 6, 11)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data07 != NULL then
tdLog.info('tdSql.checkData(0, 7, NULL)')
tdSql.checkData(0, 7, None)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: sql select * from $mt where tgcol5 = 10
tdLog.info('select * from %s where tgcol5 = 10' % (mt))
tdSql.query('select * from %s where tgcol5 = 10' % (mt))
# TSIM: print $data01 $data02 $data03
tdLog.info('$data01 $data02 $data03')
# TSIM: if $rows != 1 then
tdLog.info('tdSql.checkRow(1)')
tdSql.checkRows(1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data01 != 1 then
tdLog.info('tdSql.checkData(0, 1, 1)')
tdSql.checkData(0, 1, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data02 != 7 then
tdLog.info('tdSql.checkData(0, 2, 7)')
tdSql.checkData(0, 2, 7)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data03 != 8 then
tdLog.info('tdSql.checkData(0, 3, 8)')
tdSql.checkData(0, 3, 8)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data04 != 9 then
tdLog.info('tdSql.checkData(0, 4, 9)')
tdSql.checkData(0, 4, 9)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data05 != 10.000000000 then
tdLog.info('tdSql.checkData(0, 5, 10.000000000)')
tdSql.checkData(0, 5, 10.000000000)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data06 != 11 then
tdLog.info('tdSql.checkData(0, 6, 11)')
tdSql.checkData(0, 6, 11)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data07 != NULL then
tdLog.info('tdSql.checkData(0, 7, NULL)')
tdSql.checkData(0, 7, None)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: sql select * from $mt where tgcol6 = '11'
tdLog.info('select * from %s where tgcol6 = "11"' % (mt))
tdSql.query('select * from %s where tgcol6 = "11"' % (mt))
# TSIM: print $data01 $data02 $data03
tdLog.info('$data01 $data02 $data03')
# TSIM: if $rows != 1 then
tdLog.info('tdSql.checkRow(1)')
tdSql.checkRows(1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data01 != 1 then
tdLog.info('tdSql.checkData(0, 1, 1)')
tdSql.checkData(0, 1, 1)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data02 != 7 then
tdLog.info('tdSql.checkData(0, 2, 7)')
tdSql.checkData(0, 2, 7)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data03 != 8 then
tdLog.info('tdSql.checkData(0, 3, 8)')
tdSql.checkData(0, 3, 8)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data04 != 9 then
tdLog.info('tdSql.checkData(0, 4, 9)')
tdSql.checkData(0, 4, 9)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data05 != 10.000000000 then
tdLog.info('tdSql.checkData(0, 5, 10.000000000)')
tdSql.checkData(0, 5, 10.000000000)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data06 != 11 then
tdLog.info('tdSql.checkData(0, 6, 11)')
tdSql.checkData(0, 6, 11)
# TSIM: return -1
#TSIM: endi
# TSIM: if $data07 != NULL then
tdLog.info('tdSql.checkData(0, 7, NULL)')
tdSql.checkData(0, 7, None)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: print =============== clear
tdLog.info('=============== clear')
# TSIM: sql drop database $db
tdLog.info('sql drop database $db')
tdSql.execute('sql drop database $db')
# TSIM: sql show databases
tdLog.info('show databases')
tdSql.query('show databases')
# TSIM: if $rows != 0 then
tdLog.info('tdSql.checkRow(0)')
tdSql.checkRows(0)
# TSIM: return -1
#TSIM: endi
# TSIM:
# TSIM: system sh/exec.sh -n dnode1 -s stop -x SIGINT
# convert end
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())

View File

@ -23,7 +23,7 @@ class TDLog:
self.path = ""
def info(self, info):
print("%s %s" % (datetime.datetime.now(), info))
print("%s %s\n" % (datetime.datetime.now(), info))
def sleep(self, sec):
print("%s sleep %d seconds" % (datetime.datetime.now(), sec))

View File

@ -77,6 +77,31 @@ class TDSql:
tdLog.info("sql:%s, queryRows:%d == expect:%d" %
(self.sql, self.queryRows, expectRows))
def checkDataType(self, row, col, dataType):
frame = inspect.stack()[1]
callerModule = inspect.getmodule(frame[0])
callerFilename = callerModule.__file__
if row < 0:
tdLog.exit(
"%s failed: sql:%s, row:%d is smaller than zero" %
(callerFilename, self.sql, row))
if col < 0:
tdLog.exit(
"%s failed: sql:%s, col:%d is smaller than zero" %
(callerFilename, self.sql, col))
if row > self.queryRows:
tdLog.exit(
"%s failed: sql:%s, row:%d is larger than queryRows:%d" %
(callerFilename, self.sql, row, self.queryRows))
if col > self.queryCols:
tdLog.exit(
"%s failed: sql:%s, col:%d is larger than queryCols:%d" %
(callerFilename, self.sql, col, self.queryCols))
return self.cursor.istype(col, dataType)
def checkData(self, row, col, data):
frame = inspect.stack()[1]
callerModule = inspect.getmodule(frame[0])