openTsdbTelnetLinesInsert.py 65.8 KB
Newer Older
J
jiajingbin 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
###################################################################
#           Copyright (c) 2021 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 traceback
import random
16
from taos.error import TelnetLinesError
J
jiajingbin 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
import time
import numpy as np
from util.log import *
from util.cases import *
from util.sql import *
from util.common import tdCom
import threading

class TDTestCase:
    def init(self, conn, logSql):
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor(), logSql)
        self._conn = conn 

    def createDb(self, name="test", db_update_tag=0):
        if db_update_tag == 0:
            tdSql.execute(f"drop database if exists {name}")
            tdSql.execute(f"create database if not exists {name} precision 'us'")
        else:
            tdSql.execute(f"drop database if exists {name}")
            tdSql.execute(f"create database if not exists {name} precision 'us' update 1")
        tdSql.execute(f'use {name}')

    def timeTrans(self, time_value):
41
        if time_value.lower().endswith("ns"):
J
jiajingbin 已提交
42
            ts = int(''.join(list(filter(str.isdigit, time_value))))/1000000000
43
        elif time_value.lower().endswith("us") or time_value.isdigit() and int(time_value) != 0:
J
jiajingbin 已提交
44
            ts = int(''.join(list(filter(str.isdigit, time_value))))/1000000
45
        elif time_value.lower().endswith("ms"):
J
jiajingbin 已提交
46
            ts = int(''.join(list(filter(str.isdigit, time_value))))/1000
47
        elif time_value.lower().endswith("s") and list(time_value)[-1] not in "num":
J
jiajingbin 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
            ts = int(''.join(list(filter(str.isdigit, time_value))))/1
        elif int(time_value) == 0:
            ts = time.time()
        else:
            print("input ts maybe not right format")
        ulsec = repr(ts).split('.')[1][:6]
        if len(ulsec) < 6 and int(ulsec) != 0:
            ulsec = int(ulsec) * (10 ** (6 - len(ulsec)))
        elif int(ulsec) == 0:
            ulsec *= 6
            # * follow two rows added for tsCheckCase
            td_ts = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ts))
            return td_ts
        #td_ts = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ts))
        td_ts = time.strftime("%Y-%m-%d %H:%M:%S.{}".format(ulsec), time.localtime(ts))
        return td_ts
        #return repr(datetime.datetime.strptime(td_ts, "%Y-%m-%d %H:%M:%S.%f"))
    
    def dateToTs(self, datetime_input):
        return int(time.mktime(time.strptime(datetime_input, "%Y-%m-%d %H:%M:%S.%f")))

    def getTdTypeValue(self, value):
70
        if value.lower().endswith("i8"):
J
jiajingbin 已提交
71 72
            td_type = "TINYINT"
            td_tag_value = ''.join(list(value)[:-2])
73
        elif value.lower().endswith("i16"):
J
jiajingbin 已提交
74 75
            td_type = "SMALLINT"
            td_tag_value = ''.join(list(value)[:-3])
76
        elif value.lower().endswith("i32"):
J
jiajingbin 已提交
77 78
            td_type = "INT"
            td_tag_value = ''.join(list(value)[:-3])
79
        elif value.lower().endswith("i64"):
J
jiajingbin 已提交
80 81
            td_type = "BIGINT"
            td_tag_value = ''.join(list(value)[:-3])
82
        elif value.lower().endswith("u64"):
J
jiajingbin 已提交
83 84
            td_type = "BIGINT UNSIGNED"
            td_tag_value = ''.join(list(value)[:-3])
85
        elif value.lower().endswith("f32"):
J
jiajingbin 已提交
86 87 88
            td_type = "FLOAT"
            td_tag_value = ''.join(list(value)[:-3])
            td_tag_value = '{}'.format(np.float32(td_tag_value))
89
        elif value.lower().endswith("f64"):
J
jiajingbin 已提交
90 91
            td_type = "DOUBLE"
            td_tag_value = ''.join(list(value)[:-3])
92
        elif value.lower().startswith('l"'):
J
jiajingbin 已提交
93 94 95 96 97
            td_type = "NCHAR"
            td_tag_value = ''.join(list(value)[2:-1])
        elif value.startswith('"') and value.endswith('"'):
            td_type = "BINARY"
            td_tag_value = ''.join(list(value)[1:-1])
98
        elif value.lower() == "t" or value.lower() == "true":
J
jiajingbin 已提交
99 100
            td_type = "BOOL"
            td_tag_value = "True"
101
        elif value.lower() == "f" or value.lower() == "false":
J
jiajingbin 已提交
102 103
            td_type = "BOOL"
            td_tag_value = "False"
104 105
        elif value.isdigit():
            td_type = "BIGINT"
J
jiajingbin 已提交
106
            td_tag_value = value
107 108 109 110 111 112
        else:
            td_type = "DOUBLE"
            if "e" in value.lower():
                td_tag_value = str(float(value))
            else:
                td_tag_value = value
J
jiajingbin 已提交
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
        return td_type, td_tag_value

    def typeTrans(self, type_list):
        type_num_list = []
        for tp in type_list:
            if tp.upper() == "TIMESTAMP":
                type_num_list.append(9)
            elif tp.upper() == "BOOL":
                type_num_list.append(1)
            elif tp.upper() == "TINYINT":
                type_num_list.append(2)
            elif tp.upper() == "SMALLINT":
                type_num_list.append(3)
            elif tp.upper() == "INT":
                type_num_list.append(4)
            elif tp.upper() == "BIGINT":
                type_num_list.append(5)
            elif tp.upper() == "FLOAT":
                type_num_list.append(6)
            elif tp.upper() == "DOUBLE":
                type_num_list.append(7)
            elif tp.upper() == "BINARY":
                type_num_list.append(8)
            elif tp.upper() == "NCHAR":
                type_num_list.append(10)
            elif tp.upper() == "BIGINT UNSIGNED":
                type_num_list.append(14)
        return type_num_list

    def inputHandle(self, input_sql):
        input_sql_split_list = input_sql.split(" ")
        stb_name = input_sql_split_list[0]
145
        stb_tag_list = input_sql_split_list[3:]
J
jiajingbin 已提交
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
        stb_col_value = input_sql_split_list[2]
        ts_value = self.timeTrans(input_sql_split_list[1])

        tag_name_list = []
        tag_value_list = []
        td_tag_value_list = []
        td_tag_type_list = []

        col_name_list = []
        col_value_list = []
        td_col_value_list = []
        td_col_type_list = []

        for elm in stb_tag_list:
            if "id=" in elm.lower():
                tb_name = elm.split('=')[1]
            else:
                tag_name_list.append(elm.split("=")[0])
                tag_value_list.append(elm.split("=")[1])
                tb_name = ""
                td_tag_value_list.append(self.getTdTypeValue(elm.split("=")[1])[1])
                td_tag_type_list.append(self.getTdTypeValue(elm.split("=")[1])[0])
        
        col_name_list.append('value')
        col_value_list.append(stb_col_value)

        td_col_value_list.append(self.getTdTypeValue(stb_col_value)[1])
        td_col_type_list.append(self.getTdTypeValue(stb_col_value)[0])

        final_field_list = []
        final_field_list.extend(col_name_list)
        final_field_list.extend(tag_name_list)

        final_type_list = []
        final_type_list.append("TIMESTAMP")
        final_type_list.extend(td_col_type_list)
        final_type_list.extend(td_tag_type_list)
        final_type_list = self.typeTrans(final_type_list)

        final_value_list = []
        final_value_list.append(ts_value)
        final_value_list.extend(td_col_value_list)
        final_value_list.extend(td_tag_value_list)
        return final_value_list, final_field_list, final_type_list, stb_name, tb_name

    def genFullTypeSql(self, stb_name="", tb_name="", value="", t0="", t1="127i8", t2="32767i16", t3="2147483647i32",
                        t4="9223372036854775807i64", t5="11.12345f32", t6="22.123456789f64", t7="\"binaryTagValue\"",
                        t8="L\"ncharTagValue\"", ts="1626006833639000000ns",
                        id_noexist_tag=None, id_change_tag=None, id_upper_tag=None, id_double_tag=None,
195
                        t_add_tag=None, t_mul_tag=None, t_multi_tag=None, c_blank_tag=None, t_blank_tag=None, 
196
                        chinese_tag=None, multi_field_tag=None, point_trans_tag=None):
J
jiajingbin 已提交
197 198 199 200 201 202 203 204 205 206 207 208
        if stb_name == "":
            stb_name = tdCom.getLongName(len=6, mode="letters")
        if tb_name == "":
            tb_name = f'{stb_name}_{random.randint(0, 65535)}_{random.randint(0, 65535)}'
        if t0 == "":
            t0 = random.choice(["f", "F", "false", "False", "t", "T", "true", "True", "TRUE", "FALSE"])
        if value == "":
            value = random.choice(["f", "F", "false", "False", "t", "T", "true", "True", "TRUE", "FALSE"])
        if id_upper_tag is not None:
            id = "ID"
        else:
            id = "id"
209
        sql_seq = f'{stb_name} {ts} {value} {id}=\"{tb_name}\" t0={t0} t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6} t7={t7} t8={t8}'
J
jiajingbin 已提交
210
        if id_noexist_tag is not None:
211
            sql_seq = f'{stb_name} {ts} {value} t0={t0} t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6} t7={t7} t8={t8}'
J
jiajingbin 已提交
212
            if t_add_tag is not None:
213
                sql_seq = f'{stb_name} {ts} {value} t0={t0} t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6} t7={t7} t8={t8} t9={t8}'
J
jiajingbin 已提交
214
        if id_change_tag is not None:
215
            sql_seq = f'{stb_name} {ts} {value} t0={t0} {id}=\"{tb_name}\" t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6} t7={t7} t8={t8}'
J
jiajingbin 已提交
216
        if id_double_tag is not None:
217
            sql_seq = f'{stb_name} {ts} {value} {id}=\"{tb_name}_1\" t0={t0} t1={t1} {id}=\"{tb_name}_2\" t2={t2} t3={t3} t4={t4} t5={t5} t6={t6} t7={t7} t8={t8}'
J
jiajingbin 已提交
218
        if t_add_tag is not None:
219
            sql_seq = f'{stb_name} {ts} {value} {id}=\"{tb_name}\" t0={t0} t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6} t7={t7} t8={t8} t11={t1} t10={t8}'
J
jiajingbin 已提交
220
        if t_mul_tag is not None:
221
            sql_seq = f'{stb_name} {ts} {value} {id}=\"{tb_name}\" t0={t0} t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6}'
J
jiajingbin 已提交
222
            if id_noexist_tag is not None:
223
                sql_seq = f'{stb_name} {ts} {value} t0={t0} t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6}'
J
jiajingbin 已提交
224
        if t_multi_tag is not None:
225
            sql_seq = f'{stb_name} {ts} {value} {value} {id}=\"{tb_name}\" t0={t0} t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6}'
226
        if c_blank_tag is not None:
227
            sql_seq = f'{stb_name} {ts} {id}=\"{tb_name}\" t0={t0} t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6} t7={t7} t8={t8}'
228 229 230
        if t_blank_tag is not None:
            sql_seq = f'{stb_name} {ts} {value} {id}=\"{tb_name}\"'
        if chinese_tag is not None:
231
            sql_seq = f'{stb_name} {ts} L"涛思数据" t0={t0} t1=L"涛思数据"'
232
        if multi_field_tag is not None:
233 234 235
            sql_seq = f'{stb_name} {ts} {value} {id}=\"{tb_name}\" t0={t0} {value}'
        if point_trans_tag is not None:
            sql_seq = f'point.trans.test {ts} {value} t0={t0}'
J
jiajingbin 已提交
236 237 238 239 240 241 242 243 244 245 246
        return sql_seq, stb_name
    
    def genMulTagColStr(self, genType, count=1):
        """
            genType must be tag/col
        """
        tag_str = ""
        col_str = ""
        if genType == "tag":
            for i in range(0, count):
                if i < (count-1):
247
                    tag_str += f't{i}=f '
J
jiajingbin 已提交
248 249 250 251 252 253 254 255 256 257 258 259 260
                else:
                    tag_str += f't{i}=f'
            return tag_str
        if genType == "col":
            col_str = "t"
            return col_str

    def genLongSql(self, tag_count):
        stb_name = tdCom.getLongName(7, mode="letters")
        tb_name = f'{stb_name}_1'
        tag_str = self.genMulTagColStr("tag", tag_count)
        col_str = self.genMulTagColStr("col")
        ts = "1626006833640000000ns"
261
        long_sql = stb_name + ' ' + ts + ' ' + col_str + ' ' + f'id=\"{tb_name}\"' + ' ' + tag_str
J
jiajingbin 已提交
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
        return long_sql, stb_name

    def getNoIdTbName(self, stb_name):
        query_sql = f"select tbname from {stb_name}"
        tb_name = self.resHandle(query_sql, True)[0][0]
        return tb_name

    def resHandle(self, query_sql, query_tag):
        tdSql.execute('reset query cache')
        row_info = tdSql.query(query_sql, query_tag)
        col_info = tdSql.getColNameList(query_sql, query_tag)
        res_row_list = []
        sub_list = []
        for row_mem in row_info:
            for i in row_mem:
                sub_list.append(str(i))
            res_row_list.append(sub_list)
        res_field_list_without_ts = col_info[0][1:]
        res_type_list = col_info[1]
        return res_row_list, res_field_list_without_ts, res_type_list

    def resCmp(self, input_sql, stb_name, query_sql="select * from", condition="", ts=None, id=True, none_check_tag=None):
        expect_list = self.inputHandle(input_sql)
        self._conn.insert_telnet_lines([input_sql])
        query_sql = f"{query_sql} {stb_name} {condition}"
        res_row_list, res_field_list_without_ts, res_type_list = self.resHandle(query_sql, True)
        if ts == 0:
            res_ts = self.dateToTs(res_row_list[0][0])
            current_time = time.time()
            if current_time - res_ts < 60:
                tdSql.checkEqual(res_row_list[0][1:], expect_list[0][1:])
            else:
                print("timeout")
                tdSql.checkEqual(res_row_list[0], expect_list[0])
        else:
            if none_check_tag is not None:
                none_index_list = [i for i,x in enumerate(res_row_list[0]) if x=="None"]
                none_index_list.reverse()
                for j in none_index_list:
                    res_row_list[0].pop(j)
                    expect_list[0].pop(j)
            tdSql.checkEqual(res_row_list[0], expect_list[0])
        tdSql.checkEqual(res_field_list_without_ts, expect_list[1])
        for i in range(len(res_type_list)):
            tdSql.checkEqual(res_type_list[i], expect_list[2][i])

    def initCheckCase(self):
        """
            normal tags and cols, one for every elm
        """
        tdCom.cleanTb()
        input_sql, stb_name = self.genFullTypeSql()
        self.resCmp(input_sql, stb_name)

    def boolTypeCheckCase(self):
        """
            check all normal type
        """
        tdCom.cleanTb()
        full_type_list = ["f", "F", "false", "False", "t", "T", "true", "True"]
        for t_type in full_type_list:
            input_sql, stb_name = self.genFullTypeSql(t0=t_type)
            self.resCmp(input_sql, stb_name)
        
    def symbolsCheckCase(self):
        """
            check symbols = `~!@#$%^&*()_-+={[}]\|:;'\",<.>/? 
        """
        '''
            please test :
            binary_symbols = '\"abcd`~!@#$%^&*()_-{[}]|:;<.>?lfjal"\'\'"\"'
        '''
        tdCom.cleanTb()
335
        binary_symbols = '"abcd`~!@#$%^&*()_-{[}]|:;<.>?lfjal"'
J
jiajingbin 已提交
336 337
        nchar_symbols = f'L{binary_symbols}'
        input_sql1, stb_name1 = self.genFullTypeSql(value=binary_symbols, t7=binary_symbols, t8=nchar_symbols)
338
        input_sql2, stb_name2 = self.genFullTypeSql(value=nchar_symbols, t7=binary_symbols, t8=nchar_symbols)
J
jiajingbin 已提交
339
        self.resCmp(input_sql1, stb_name1)
340
        self.resCmp(input_sql2, stb_name2)
J
jiajingbin 已提交
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396

    def tsCheckCase(self):
        """
            test ts list --> ["1626006833639000000ns", "1626006833639019us", "1626006833640ms", "1626006834s", "1626006822639022"]
        """
        tdCom.cleanTb()
        ts_list = ["1626006833639000000ns", "1626006833639019us", "1626006833640ms", "1626006834s", "1626006822639022", 0]
        for ts in ts_list:
            input_sql, stb_name = self.genFullTypeSql(ts=ts)
            self.resCmp(input_sql, stb_name, ts=ts)
    
    def idSeqCheckCase(self):
        """
            check id.index in tags
            eg: t0=**,id=**,t1=**
        """
        tdCom.cleanTb()
        input_sql, stb_name = self.genFullTypeSql(id_change_tag=True)
        self.resCmp(input_sql, stb_name)
    
    def idUpperCheckCase(self):
        """
            check id param
            eg: id and ID
        """
        tdCom.cleanTb()
        input_sql, stb_name = self.genFullTypeSql(id_upper_tag=True)
        self.resCmp(input_sql, stb_name)
        input_sql, stb_name = self.genFullTypeSql(id_change_tag=True, id_upper_tag=True)
        self.resCmp(input_sql, stb_name)

    def noIdCheckCase(self):
        """
            id not exist
        """
        tdCom.cleanTb()
        input_sql, stb_name = self.genFullTypeSql(id_noexist_tag=True)
        self.resCmp(input_sql, stb_name)
        query_sql = f"select tbname from {stb_name}"
        res_row_list = self.resHandle(query_sql, True)[0]
        if len(res_row_list[0][0]) > 0:
            tdSql.checkColNameList(res_row_list, res_row_list)
        else:
            tdSql.checkColNameList(res_row_list, "please check noIdCheckCase")

    def maxColTagCheckCase(self):
        """
            max tag count is 128
        """
        for input_sql in [self.genLongSql(128)[0]]:
            tdCom.cleanTb()
            self._conn.insert_telnet_lines([input_sql])
        for input_sql in [self.genLongSql(129)[0]]:
            tdCom.cleanTb()
            try:
                self._conn.insert_telnet_lines([input_sql])
397 398 399 400
                raise Exception("should not reach here")
            except TelnetLinesError as err:
                tdSql.checkNotEqual(err.errno, 0)

J
jiajingbin 已提交
401 402 403 404 405 406 407 408 409 410 411
    def idIllegalNameCheckCase(self):
        """
            test illegal id name
            mix "`~!@#$¥%^&*()-+={}|[]、「」【】\:;《》<>?"
        """
        tdCom.cleanTb()
        rstr = list("`~!@#$¥%^&*()-+={}|[]、「」【】\:;《》<>?")
        for i in rstr:
            input_sql = self.genFullTypeSql(tb_name=f"\"aaa{i}bbb\"")[0]
            try:
                self._conn.insert_telnet_lines([input_sql])
412 413 414
                raise Exception("should not reach here")
            except TelnetLinesError as err:
                tdSql.checkNotEqual(err.errno, 0)
J
jiajingbin 已提交
415 416 417 418 419 420 421 422 423

    def idStartWithNumCheckCase(self):
        """
            id is start with num
        """
        tdCom.cleanTb()
        input_sql = self.genFullTypeSql(tb_name=f"\"1aaabbb\"")[0]
        try:
            self._conn.insert_telnet_lines([input_sql])
424 425 426
            raise Exception("should not reach here")
        except TelnetLinesError as err:
            tdSql.checkNotEqual(err.errno, 0)
J
jiajingbin 已提交
427 428 429 430 431 432 433 434 435

    def nowTsCheckCase(self):
        """
            check now unsupported
        """
        tdCom.cleanTb()
        input_sql = self.genFullTypeSql(ts="now")[0]
        try:
            self._conn.insert_telnet_lines([input_sql])
436 437 438
            raise Exception("should not reach here")
        except TelnetLinesError as err:
            tdSql.checkNotEqual(err.errno, 0)
J
jiajingbin 已提交
439 440 441 442 443 444 445 446 447

    def dateFormatTsCheckCase(self):
        """
            check date format ts unsupported
        """
        tdCom.cleanTb()
        input_sql = self.genFullTypeSql(ts="2021-07-21\ 19:01:46.920")[0]
        try:
            self._conn.insert_telnet_lines([input_sql])
448 449 450
            raise Exception("should not reach here")
        except TelnetLinesError as err:
            tdSql.checkNotEqual(err.errno, 0)
J
jiajingbin 已提交
451 452 453 454 455 456 457 458 459
    
    def illegalTsCheckCase(self):
        """
            check ts format like 16260068336390us19
        """
        tdCom.cleanTb()
        input_sql = self.genFullTypeSql(ts="16260068336390us19")[0]
        try:
            self._conn.insert_telnet_lines([input_sql])
460 461 462
            raise Exception("should not reach here")
        except TelnetLinesError as err:
            tdSql.checkNotEqual(err.errno, 0)
J
jiajingbin 已提交
463 464 465 466 467 468 469 470 471 472 473 474 475 476

    def tagValueLengthCheckCase(self):
        """
            check full type tag value limit
        """
        tdCom.cleanTb()
        # i8
        for t1 in ["-127i8", "127i8"]:
            input_sql, stb_name = self.genFullTypeSql(t1=t1)
            self.resCmp(input_sql, stb_name)
        for t1 in ["-128i8", "128i8"]:
            input_sql = self.genFullTypeSql(t1=t1)[0]
            try:
                self._conn.insert_telnet_lines([input_sql])
477 478 479
                raise Exception("should not reach here")
            except TelnetLinesError as err:
                tdSql.checkNotEqual(err.errno, 0)
J
jiajingbin 已提交
480 481 482 483 484 485 486 487 488

        #i16
        for t2 in ["-32767i16", "32767i16"]:
            input_sql, stb_name = self.genFullTypeSql(t2=t2)
            self.resCmp(input_sql, stb_name)
        for t2 in ["-32768i16", "32768i16"]:
            input_sql = self.genFullTypeSql(t2=t2)[0]
            try:
                self._conn.insert_telnet_lines([input_sql])
489 490 491
                raise Exception("should not reach here")
            except TelnetLinesError as err:
                tdSql.checkNotEqual(err.errno, 0)
J
jiajingbin 已提交
492 493 494 495 496 497 498 499 500

        #i32
        for t3 in ["-2147483647i32", "2147483647i32"]:
            input_sql, stb_name = self.genFullTypeSql(t3=t3)
            self.resCmp(input_sql, stb_name)
        for t3 in ["-2147483648i32", "2147483648i32"]:
            input_sql = self.genFullTypeSql(t3=t3)[0]
            try:
                self._conn.insert_telnet_lines([input_sql])
501 502 503
                raise Exception("should not reach here")
            except TelnetLinesError as err:
                tdSql.checkNotEqual(err.errno, 0)
J
jiajingbin 已提交
504 505 506 507 508 509 510 511 512

        #i64
        for t4 in ["-9223372036854775807i64", "9223372036854775807i64"]:
            input_sql, stb_name = self.genFullTypeSql(t4=t4)
            self.resCmp(input_sql, stb_name)
        for t4 in ["-9223372036854775808i64", "9223372036854775808i64"]:
            input_sql = self.genFullTypeSql(t4=t4)[0]
            try:
                self._conn.insert_telnet_lines([input_sql])
513 514 515
                raise Exception("should not reach here")
            except TelnetLinesError as err:
                tdSql.checkNotEqual(err.errno, 0)
J
jiajingbin 已提交
516 517 518 519 520 521 522 523 524 525 526

        # f32
        for t5 in [f"{-3.4028234663852885981170418348451692544*(10**38)}f32", f"{3.4028234663852885981170418348451692544*(10**38)}f32"]:
            input_sql, stb_name = self.genFullTypeSql(t5=t5)
            self.resCmp(input_sql, stb_name)
        # * limit set to 4028234664*(10**38)
        for t5 in [f"{-3.4028234664*(10**38)}f32", f"{3.4028234664*(10**38)}f32"]:
            input_sql = self.genFullTypeSql(t5=t5)[0]
            try:
                self._conn.insert_telnet_lines([input_sql])
                raise Exception("should not reach here")
527
            except TelnetLinesError as err:
J
jiajingbin 已提交
528 529 530 531 532 533 534 535
                tdSql.checkNotEqual(err.errno, 0)


        # f64
        for t6 in [f'{-1.79769*(10**308)}f64', f'{-1.79769*(10**308)}f64']:
            input_sql, stb_name = self.genFullTypeSql(t6=t6)
            self.resCmp(input_sql, stb_name)
        # * limit set to 1.797693134862316*(10**308)
536 537
        for t6 in [f'{-1.797693134862316*(10**308)}f64', f'{-1.797693134862316*(10**308)}f64']:
            input_sql = self.genFullTypeSql(t6=t6)[0]
J
jiajingbin 已提交
538 539 540
            try:
                self._conn.insert_telnet_lines([input_sql])
                raise Exception("should not reach here")
541
            except TelnetLinesError as err:
J
jiajingbin 已提交
542 543 544 545
                tdSql.checkNotEqual(err.errno, 0)

        # binary 
        stb_name = tdCom.getLongName(7, "letters")
546
        input_sql = f'{stb_name} 1626006833639000000ns t t0=t t1="{tdCom.getLongName(16374, "letters")}"'
J
jiajingbin 已提交
547 548
        self._conn.insert_telnet_lines([input_sql])
        
549
        input_sql = f'{stb_name} 1626006833639000000ns t t0=t t1="{tdCom.getLongName(16375, "letters")}"'
J
jiajingbin 已提交
550 551 552
        try:
            self._conn.insert_telnet_lines([input_sql])
            raise Exception("should not reach here")
553 554
        except TelnetLinesError as err:
            tdSql.checkNotEqual(err.errno, 0)
J
jiajingbin 已提交
555 556 557
        # nchar
        # * legal nchar could not be larger than 16374/4
        stb_name = tdCom.getLongName(7, "letters")
558
        input_sql = f'{stb_name} 1626006833639000000ns t t0=t t1=L"{tdCom.getLongName(4093, "letters")}"'
J
jiajingbin 已提交
559 560
        self._conn.insert_telnet_lines([input_sql])

561
        input_sql = f'{stb_name} 1626006833639000000ns t t0=t t1=L"{tdCom.getLongName(4094, "letters")}"'
J
jiajingbin 已提交
562 563 564
        try:
            self._conn.insert_telnet_lines([input_sql])
            raise Exception("should not reach here")
565
        except TelnetLinesError as err:
J
jiajingbin 已提交
566 567 568 569 570 571 572 573
            tdSql.checkNotEqual(err.errno, 0)

    def colValueLengthCheckCase(self):
        """
            check full type col value limit
        """
        tdCom.cleanTb()
        # i8
574 575
        for value in ["-127i8", "127i8"]:
            input_sql, stb_name = self.genFullTypeSql(value=value)
J
jiajingbin 已提交
576
            self.resCmp(input_sql, stb_name)
577 578 579
        tdCom.cleanTb()
        for value in ["-128i8", "128i8"]:
            input_sql = self.genFullTypeSql(value=value)[0]
J
jiajingbin 已提交
580 581 582
            try:
                self._conn.insert_telnet_lines([input_sql])
                raise Exception("should not reach here")
583
            except TelnetLinesError as err:
J
jiajingbin 已提交
584 585
                tdSql.checkNotEqual(err.errno, 0)
        # i16
586 587 588
        tdCom.cleanTb()
        for value in ["-32767i16"]:
            input_sql, stb_name = self.genFullTypeSql(value=value)
J
jiajingbin 已提交
589
            self.resCmp(input_sql, stb_name)
590 591 592
        tdCom.cleanTb()
        for value in ["-32768i16", "32768i16"]:
            input_sql = self.genFullTypeSql(value=value)[0]
J
jiajingbin 已提交
593 594 595
            try:
                self._conn.insert_telnet_lines([input_sql])
                raise Exception("should not reach here")
596
            except TelnetLinesError as err:
J
jiajingbin 已提交
597 598 599
                tdSql.checkNotEqual(err.errno, 0)

        # i32
600 601 602
        tdCom.cleanTb()
        for value in ["-2147483647i32"]:
            input_sql, stb_name = self.genFullTypeSql(value=value)
J
jiajingbin 已提交
603
            self.resCmp(input_sql, stb_name)
604 605 606
        tdCom.cleanTb()
        for value in ["-2147483648i32", "2147483648i32"]:
            input_sql = self.genFullTypeSql(value=value)[0]
J
jiajingbin 已提交
607 608 609
            try:
                self._conn.insert_telnet_lines([input_sql])
                raise Exception("should not reach here")
610
            except TelnetLinesError as err:
J
jiajingbin 已提交
611 612 613
                tdSql.checkNotEqual(err.errno, 0)

        # i64
614 615 616
        tdCom.cleanTb()
        for value in ["-9223372036854775807i64"]:
            input_sql, stb_name = self.genFullTypeSql(value=value)
J
jiajingbin 已提交
617
            self.resCmp(input_sql, stb_name)
618 619 620
        tdCom.cleanTb()
        for value in ["-9223372036854775808i64", "9223372036854775808i64"]:
            input_sql = self.genFullTypeSql(value=value)[0]
J
jiajingbin 已提交
621 622 623
            try:
                self._conn.insert_telnet_lines([input_sql])
                raise Exception("should not reach here")
624
            except TelnetLinesError as err:
J
jiajingbin 已提交
625 626 627
                tdSql.checkNotEqual(err.errno, 0)

        # f32       
628 629 630
        tdCom.cleanTb()
        for value in [f"{-3.4028234663852885981170418348451692544*(10**38)}f32", f"{3.4028234663852885981170418348451692544*(10**38)}f32"]:
            input_sql, stb_name = self.genFullTypeSql(value=value)
J
jiajingbin 已提交
631 632
            self.resCmp(input_sql, stb_name)
        # * limit set to 4028234664*(10**38)
633 634 635
        tdCom.cleanTb()
        for value in [f"{-3.4028234664*(10**38)}f32", f"{3.4028234664*(10**38)}f32"]:
            input_sql = self.genFullTypeSql(value=value)[0]
J
jiajingbin 已提交
636 637 638
            try:
                self._conn.insert_telnet_lines([input_sql])
                raise Exception("should not reach here")
639
            except TelnetLinesError as err:
J
jiajingbin 已提交
640 641 642
                tdSql.checkNotEqual(err.errno, 0)

        # f64
643 644 645
        tdCom.cleanTb()
        for value in [f'{-1.79769313486231570814527423731704356798070567525844996598917476803157260780*(10**308)}f64', f'{-1.79769313486231570814527423731704356798070567525844996598917476803157260780*(10**308)}f64']:
            input_sql, stb_name = self.genFullTypeSql(value=value)
J
jiajingbin 已提交
646 647
            self.resCmp(input_sql, stb_name)
        # * limit set to 1.797693134862316*(10**308)
648 649 650
        tdCom.cleanTb()
        for value in [f'{-1.797693134862316*(10**308)}f64', f'{-1.797693134862316*(10**308)}f64']:
            input_sql = self.genFullTypeSql(value=value)[0]
J
jiajingbin 已提交
651 652 653
            try:
                self._conn.insert_telnet_lines([input_sql])
                raise Exception("should not reach here")
654
            except TelnetLinesError as err:
J
jiajingbin 已提交
655 656 657
                tdSql.checkNotEqual(err.errno, 0)

        # # binary 
658
        tdCom.cleanTb()
J
jiajingbin 已提交
659 660 661 662
        stb_name = tdCom.getLongName(7, "letters")
        input_sql = f'{stb_name} 1626006833639000000ns "{tdCom.getLongName(16374, "letters")}" t0=t'
        self._conn.insert_telnet_lines([input_sql])
        
663
        tdCom.cleanTb()
J
jiajingbin 已提交
664 665 666 667
        input_sql = f'{stb_name} 1626006833639000000ns "{tdCom.getLongName(16375, "letters")}" t0=t'
        try:
            self._conn.insert_telnet_lines([input_sql])
            raise Exception("should not reach here")
668
        except TelnetLinesError as err:
J
jiajingbin 已提交
669 670 671 672
            tdSql.checkNotEqual(err.errno, 0)

        # nchar
        # * legal nchar could not be larger than 16374/4
673
        tdCom.cleanTb()
J
jiajingbin 已提交
674 675 676 677
        stb_name = tdCom.getLongName(7, "letters")
        input_sql = f'{stb_name} 1626006833639000000ns L"{tdCom.getLongName(4093, "letters")}" t0=t'
        self._conn.insert_telnet_lines([input_sql])

678
        tdCom.cleanTb()
J
jiajingbin 已提交
679 680 681 682
        input_sql = f'{stb_name} 1626006833639000000ns L"{tdCom.getLongName(4094, "letters")}" t0=t'
        try:
            self._conn.insert_telnet_lines([input_sql])
            raise Exception("should not reach here")
683
        except TelnetLinesError as err:
J
jiajingbin 已提交
684 685 686 687 688 689 690 691 692 693
            tdSql.checkNotEqual(err.errno, 0)

    def tagColIllegalValueCheckCase(self):

        """
            test illegal tag col value
        """
        tdCom.cleanTb()
        # bool
        for i in ["TrUe", "tRue", "trUe", "truE", "FalsE", "fAlse", "faLse", "falSe", "falsE"]:
694 695 696 697
            input_sql1, stb_name = self.genFullTypeSql(t0=i)
            self.resCmp(input_sql1, stb_name)
            input_sql2, stb_name = self.genFullTypeSql(value=i)
            self.resCmp(input_sql2, stb_name)
J
jiajingbin 已提交
698 699 700 701 702 703 704 705 706 707 708 709 710

        # i8 i16 i32 i64 f32 f64
        for input_sql in [
                self.genFullTypeSql(t1="1s2i8")[0], 
                self.genFullTypeSql(t2="1s2i16")[0],
                self.genFullTypeSql(t3="1s2i32")[0],
                self.genFullTypeSql(t4="1s2i64")[0],
                self.genFullTypeSql(t5="11.1s45f32")[0],
                self.genFullTypeSql(t6="11.1s45f64")[0], 
            ]:
            try:
                self._conn.insert_telnet_lines([input_sql])
                raise Exception("should not reach here")
711
            except TelnetLinesError as err:
J
jiajingbin 已提交
712 713 714
                tdSql.checkNotEqual(err.errno, 0)

        # check binary and nchar blank
715 716 717 718
        input_sql1 = f'{tdCom.getLongName(7, "letters")} 1626006833639000000ns "abc aaa" t0=t'
        input_sql2 = f'{tdCom.getLongName(7, "letters")} 1626006833639000000ns L"abc aaa" t0=t'
        input_sql3 = f'{tdCom.getLongName(7, "letters")} 1626006833639000000ns t t0="abc aaa"'
        input_sql4 = f'{tdCom.getLongName(7, "letters")} 1626006833639000000ns t t0=L"abc aaa"'
J
jiajingbin 已提交
719 720 721
        for input_sql in [input_sql1, input_sql2, input_sql3, input_sql4]:
            try:
                self._conn.insert_telnet_lines([input_sql])
722 723 724
                raise Exception("should not reach here")
            except TelnetLinesError as err:
                tdSql.checkNotEqual(err.errno, 0)
J
jiajingbin 已提交
725 726 727 728

        # check accepted binary and nchar symbols 
        # # * ~!@#$¥%^&*()-+={}|[]、「」:;
        for symbol in list('~!@#$¥%^&*()-+={}|[]、「」:;'):
729
            input_sql1 = f'{tdCom.getLongName(7, "letters")} 1626006833639000000ns "abc{symbol}aaa" t0=t'
730
            input_sql2 = f'{tdCom.getLongName(7, "letters")} 1626006833639000000ns t t0=t t1="abc{symbol}aaa"'
J
jiajingbin 已提交
731 732
            self._conn.insert_telnet_lines([input_sql1])
            self._conn.insert_telnet_lines([input_sql2])
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
    
    def blankCheckCase(self):
        '''
            check blank case
        '''
        tdCom.cleanTb()
        input_sql_list = [f'{tdCom.getLongName(7, "letters")} {tdCom.getLongName(7, "letters")} 1626006833639000000ns "abcaaa" t0=t',
                        f'{tdCom.getLongName(7, "letters")} 16260068336 39000000ns L"bcdaaa" t1=f',
                        f'{tdCom.getLongName(7, "letters")} 1626006833639000000ns t t0="abc  aaa"',
                        f'{tdCom.getLongName(7, "letters")} 1626006833639000000ns t t0=L"abc  aaa"',
                        f'{tdCom.getLongName(7, "letters")} 1626006833639000000ns "abc  aaa" t0=L"abcaaa"',
                        f'{tdCom.getLongName(7, "letters")} 1626006833639000000ns L"abc  aaa" t0=L"abcaaa"',
                        f'{tdCom.getLongName(7, "letters")} 1626006833639000000ns L"abaaa"  t0=L"abcaaa1"',
                        f'{tdCom.getLongName(7, "letters")} 1626006833639000000ns  L"abaaa" t0=L"abcaaa2"',
                        f'{tdCom.getLongName(7, "letters")} 1626006833639000000ns L"abaaa" t0=t t1="abc t2="taa""',
                        f'{tdCom.getLongName(7, "letters")}  1626006833639000000ns L"abaaa" t0=L"abcaaa3"']
        for input_sql in input_sql_list:
            try:
                self._conn.insert_telnet_lines([input_sql])
                raise Exception("should not reach here")
            except TelnetLinesError as err:
                tdSql.checkNotEqual(err.errno, 0)
J
jiajingbin 已提交
755 756 757 758 759 760 761 762 763 764

    def duplicateIdTagColInsertCheckCase(self):
        """
            check duplicate Id Tag Col
        """
        tdCom.cleanTb()
        input_sql_id = self.genFullTypeSql(id_double_tag=True)[0]
        try:
            self._conn.insert_telnet_lines([input_sql_id])
            raise Exception("should not reach here")
765
        except TelnetLinesError as err:
J
jiajingbin 已提交
766 767 768 769 770 771 772
            tdSql.checkNotEqual(err.errno, 0)

        input_sql = self.genFullTypeSql()[0]
        input_sql_tag = input_sql.replace("t5", "t6")
        try:
            self._conn.insert_telnet_lines([input_sql_tag])
            raise Exception("should not reach here")
773
        except TelnetLinesError as err:
J
jiajingbin 已提交
774 775 776 777 778 779 780
            tdSql.checkNotEqual(err.errno, 0)

    ##### stb exist #####
    def noIdStbExistCheckCase(self):
        """
            case no id when stb exist
        """
781
        print("noIdStbExistCheckCase")
J
jiajingbin 已提交
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
        tdCom.cleanTb()
        input_sql, stb_name = self.genFullTypeSql(tb_name="sub_table_0123456", t0="f", value="f")
        self.resCmp(input_sql, stb_name)
        input_sql, stb_name = self.genFullTypeSql(stb_name=stb_name, id_noexist_tag=True, t0="f", value="f")
        self.resCmp(input_sql, stb_name, condition='where tbname like "t_%"')
        tdSql.query(f"select * from {stb_name}")
        tdSql.checkRows(2)

    def duplicateInsertExistCheckCase(self):
        """
            check duplicate insert when stb exist
        """
        tdCom.cleanTb()
        input_sql, stb_name = self.genFullTypeSql()
        self.resCmp(input_sql, stb_name)
        self._conn.insert_telnet_lines([input_sql])
        self.resCmp(input_sql, stb_name)

    def tagColBinaryNcharLengthCheckCase(self):
        """
            check length increase
        """
804
        print("tagColBinaryNcharLengthCheckCase")
J
jiajingbin 已提交
805 806 807 808
        tdCom.cleanTb()
        input_sql, stb_name = self.genFullTypeSql()
        self.resCmp(input_sql, stb_name)
        tb_name = tdCom.getLongName(5, "letters")
809
        input_sql, stb_name = self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name,t7="\"binaryTagValuebinaryTagValue\"", t8="L\"ncharTagValuencharTagValue\"")
J
jiajingbin 已提交
810 811 812 813
        self.resCmp(input_sql, stb_name, condition=f'where tbname like "{tb_name}"')

    def tagColAddDupIDCheckCase(self):
        """
814
            check tag count add, stb and tb duplicate
J
jiajingbin 已提交
815 816 817 818 819 820
            * tag: alter table ...
            * col: when update==0 and ts is same, unchange
            * so this case tag&&value will be added, 
            * col is added without value when update==0
            * col is added with value when update==1
        """
821
        print("tagColAddDupIDCheckCase")
J
jiajingbin 已提交
822 823 824 825 826 827 828
        tdCom.cleanTb()
        tb_name = tdCom.getLongName(7, "letters")
        for db_update_tag in [0, 1]:
            if db_update_tag == 1 :
                self.createDb("test_update", db_update_tag=db_update_tag)
            input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name, t0="f", value="f")
            self.resCmp(input_sql, stb_name)
829
            self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t0="f", value="f", t_add_tag=True)
J
jiajingbin 已提交
830 831 832 833
            if db_update_tag == 1 :
                self.resCmp(input_sql, stb_name, condition=f'where tbname like "{tb_name}"')
            else:
                self.resCmp(input_sql, stb_name, condition=f'where tbname like "{tb_name}"', none_check_tag=True)
834
            self.createDb()
J
jiajingbin 已提交
835 836 837

    def tagColAddCheckCase(self):
        """
838
            check tag count add
J
jiajingbin 已提交
839
        """
840
        print("tagColAddCheckCase")
J
jiajingbin 已提交
841 842 843 844 845
        tdCom.cleanTb()
        tb_name = tdCom.getLongName(7, "letters")
        input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name, t0="f", value="f")
        self.resCmp(input_sql, stb_name)
        tb_name_1 = tdCom.getLongName(7, "letters")
846
        input_sql, stb_name = self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name_1, t0="f", value="f", t_add_tag=True)
J
jiajingbin 已提交
847
        self.resCmp(input_sql, stb_name, condition=f'where tbname like "{tb_name_1}"')
848 849
        res_row_list = self.resHandle(f"select t10,t11 from {tb_name}", True)[0]
        tdSql.checkEqual(res_row_list[0], ['None', 'None'])
J
jiajingbin 已提交
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
        self.resCmp(input_sql, stb_name, condition=f'where tbname like "{tb_name}"', none_check_tag=True)

    def tagMd5Check(self):
        """
            condition: stb not change
            insert two table, keep tag unchange, change col
        """
        tdCom.cleanTb()
        input_sql, stb_name = self.genFullTypeSql(t0="f", value="f", id_noexist_tag=True)
        self.resCmp(input_sql, stb_name)
        tb_name1 = self.getNoIdTbName(stb_name)
        input_sql, stb_name = self.genFullTypeSql(stb_name=stb_name, t0="f", value="f", id_noexist_tag=True)
        self.resCmp(input_sql, stb_name)
        tb_name2 = self.getNoIdTbName(stb_name)
        tdSql.query(f"select * from {stb_name}")
        tdSql.checkRows(1)
        tdSql.checkEqual(tb_name1, tb_name2)
867
        input_sql, stb_name = self.genFullTypeSql(stb_name=stb_name, t0="f", value="f", id_noexist_tag=True, t_add_tag=True)
J
jiajingbin 已提交
868 869 870 871 872 873 874 875 876 877 878 879 880 881
        self._conn.insert_telnet_lines([input_sql])
        tb_name3 = self.getNoIdTbName(stb_name)
        tdSql.query(f"select * from {stb_name}")
        tdSql.checkRows(2)
        tdSql.checkNotEqual(tb_name1, tb_name3)

    # * tag binary max is 16384, col+ts binary max  49151
    def tagColBinaryMaxLengthCheckCase(self):
        """
            every binary and nchar must be length+2
        """
        tdCom.cleanTb()
        stb_name = tdCom.getLongName(7, "letters")
        tb_name = f'{stb_name}_1'
882

883
        input_sql = f'{stb_name} 1626006833639000000ns f id="{tb_name}" t0=t'
J
jiajingbin 已提交
884 885 886
        self._conn.insert_telnet_lines([input_sql])

        # * every binary and nchar must be length+2, so here is two tag, max length could not larger than 16384-2*2
887
        input_sql = f'{stb_name} 1626006833639000000ns f t0=t t1="{tdCom.getLongName(16374, "letters")}" t2="{tdCom.getLongName(5, "letters")}"'
J
jiajingbin 已提交
888 889 890 891
        self._conn.insert_telnet_lines([input_sql])
        
        tdSql.query(f"select * from {stb_name}")
        tdSql.checkRows(2)
892
        input_sql = f'{stb_name} 1626006833639000000ns f t0=t t1="{tdCom.getLongName(16374, "letters")}" t2="{tdCom.getLongName(6, "letters")}"'
J
jiajingbin 已提交
893 894 895
        try:
            self._conn.insert_telnet_lines([input_sql])
            raise Exception("should not reach here")
896 897
        except TelnetLinesError as err:
            tdSql.checkNotEqual(err.errno, 0)
J
jiajingbin 已提交
898 899 900 901 902 903 904 905 906 907 908
        tdSql.query(f"select * from {stb_name}")
        tdSql.checkRows(2)

    # * tag nchar max is 16374/4, col+ts nchar max  49151
    def tagColNcharMaxLengthCheckCase(self):
        """
            check nchar length limit
        """
        tdCom.cleanTb()
        stb_name = tdCom.getLongName(7, "letters")
        tb_name = f'{stb_name}_1'
909
        input_sql = f'{stb_name} 1626006833639000000ns f id="{tb_name}" t0=t'
910
        self._conn.insert_telnet_lines([input_sql])
J
jiajingbin 已提交
911 912

        # * legal nchar could not be larger than 16374/4
913
        input_sql = f'{stb_name} 1626006833639000000ns f t0=t t1=L"{tdCom.getLongName(4093, "letters")}" t2=L"{tdCom.getLongName(1, "letters")}"'
J
jiajingbin 已提交
914 915 916
        self._conn.insert_telnet_lines([input_sql])
        tdSql.query(f"select * from {stb_name}")
        tdSql.checkRows(2)
917
        input_sql = f'{stb_name} 1626006833639000000ns f t0=t t1=L"{tdCom.getLongName(4093, "letters")}" t2=L"{tdCom.getLongName(2, "letters")}"'
J
jiajingbin 已提交
918 919 920
        try:
            self._conn.insert_telnet_lines([input_sql])
            raise Exception("should not reach here")
921
        except TelnetLinesError as err:
J
jiajingbin 已提交
922 923 924 925 926 927 928 929 930 931 932
            tdSql.checkNotEqual(err.errno, 0)
        tdSql.query(f"select * from {stb_name}")
        tdSql.checkRows(2)

    def batchInsertCheckCase(self):
        """
            test batch insert
        """
        tdCom.cleanTb()
        stb_name = tdCom.getLongName(8, "letters")
        tdSql.execute(f'create stable {stb_name}(ts timestamp, f int) tags(t1 bigint)')
933
        
934 935 936 937 938 939 940 941 942
        lines = ["st123456 1626006833639000000ns 1i64 t1=3i64 t2=4f64 t3=\"t3\"",
                "st123456 1626006833640000000ns 2i64 t1=4i64 t3=\"t4\" t2=5f64 t4=5f64",
                f'{stb_name} 1626056811823316532ns 3i64 t2=5f64 t3=L\"ste\"',
                "stf567890 1626006933640000000ns 4i64 t1=4i64 t3=\"t4\" t2=5f64 t4=5f64",
                "st123456 1626006833642000000ns 5i64 t1=4i64 t2=5f64 t3=\"t4\"",
                f'{stb_name} 1626056811843316532ns 6i64 t2=5f64 t3=L\"ste2\"',
                f'{stb_name} 1626056812843316532ns 7i64 t2=5f64 t3=L\"ste2\"',
                "st123456 1626006933640000000ns 8i64 t1=4i64 t3=\"t4\" t2=5f64 t4=5f64",
                "st123456 1626006933641000000ns 9i64 t1=4i64 t3=\"t4\" t2=5f64 t4=5f64"
J
jiajingbin 已提交
943 944
                ]
        self._conn.insert_telnet_lines(lines)
945 946 947 948 949 950
        tdSql.query('show stables')
        tdSql.checkRows(3)
        tdSql.query('show tables')
        tdSql.checkRows(6)
        tdSql.query('select * from st123456')
        tdSql.checkRows(5)
J
jiajingbin 已提交
951 952 953 954 955 956 957 958 959 960
    
    def multiInsertCheckCase(self, count):
            """
                test multi insert
            """
            tdCom.cleanTb()
            sql_list = []
            stb_name = tdCom.getLongName(8, "letters")
            tdSql.execute(f'create stable {stb_name}(ts timestamp, f int) tags(t1 bigint)')
            for i in range(count):
961
                input_sql = self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True)[0]
J
jiajingbin 已提交
962 963
                sql_list.append(input_sql)
            self._conn.insert_telnet_lines(sql_list)
964
            tdSql.query('show tables')
965
            tdSql.checkRows(count)
J
jiajingbin 已提交
966 967 968 969 970 971 972

    def batchErrorInsertCheckCase(self):
        """
            test batch error insert
        """
        tdCom.cleanTb()
        stb_name = tdCom.getLongName(8, "letters")
973 974
        lines = ["st123456 1626006833639000000ns 3i 64 t1=3i64 t2=4f64 t3=\"t3\"",
                f"{stb_name} 1626056811823316532ns tRue t2=5f64 t3=L\"ste\""]
J
jiajingbin 已提交
975 976 977
        try:
            self._conn.insert_telnet_lines(lines)
            raise Exception("should not reach here")
978
        except TelnetLinesError as err:
J
jiajingbin 已提交
979 980
            tdSql.checkNotEqual(err.errno, 0)

981 982 983 984 985 986 987 988 989
    def multiColsInsertCheckCase(self):
        """
            test multi cols insert
        """
        tdCom.cleanTb()
        input_sql = self.genFullTypeSql(t_multi_tag=True)[0]
        try:
            self._conn.insert_telnet_lines([input_sql])
            raise Exception("should not reach here")
990
        except TelnetLinesError as err:
991 992 993 994 995 996 997 998 999 1000 1001
            tdSql.checkNotEqual(err.errno, 0)
    
    def blankColInsertCheckCase(self):
        """
            test blank col insert
        """
        tdCom.cleanTb()
        input_sql = self.genFullTypeSql(c_blank_tag=True)[0]
        try:
            self._conn.insert_telnet_lines([input_sql])
            raise Exception("should not reach here")
1002
        except TelnetLinesError as err:
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
            tdSql.checkNotEqual(err.errno, 0)

    def blankTagInsertCheckCase(self):
        """
            test blank tag insert
        """
        tdCom.cleanTb()
        input_sql = self.genFullTypeSql(t_blank_tag=True)[0]
        try:
            self._conn.insert_telnet_lines([input_sql])
            raise Exception("should not reach here")
1014
        except TelnetLinesError as err:
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
            tdSql.checkNotEqual(err.errno, 0)
    
    def chineseCheckCase(self):
        """
            check nchar ---> chinese
        """
        tdCom.cleanTb()
        input_sql, stb_name = self.genFullTypeSql(chinese_tag=True)
        self.resCmp(input_sql, stb_name)

    def multiFieldCheckCase(self):
        '''
            multi_field
        '''
        tdCom.cleanTb()
        input_sql = self.genFullTypeSql(multi_field_tag=True)[0]
        try:
            self._conn.insert_telnet_lines([input_sql])
            raise Exception("should not reach here")
1034
        except TelnetLinesError as err:
1035 1036
            tdSql.checkNotEqual(err.errno, 0)

J
jiajingbin 已提交
1037 1038
    def errorTypeCheckCase(self):
        stb_name = tdCom.getLongName(8, "letters")
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
        input_sql_list = [f'{stb_name}_1 1626006833639000000Ns "hkgjiwdj" t0=f t1=127I8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="vozamcts" t8=L"ncharTagValue"', \
                        f'{stb_name}_2 1626006833639000001nS "hkgjiwdj" t0=f t1=127i8 t2=32767I16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="vozamcts" t8=L"ncharTagValue"', \
                        f'{stb_name}_3 1626006833639000002NS "hkgjiwdj" t0=f t1=127i8 t2=32767I16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="vozamcts" t8=L"ncharTagValue"', \
                        f'{stb_name}_4 1626006833639019Us "hkgjiwdj" t0=f t1=127i8 t2=32767I16 t3=2147483647I32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="vozamcts" t8=L"ncharTagValue"', \
                        f'{stb_name}_5 1626006833639018uS "hkgjiwdj" t0=f t1=127i8 t2=32767I16 t3=2147483647i32 t4=9223372036854775807I64 t5=11.12345f32 t6=22.123456789f64 t7="vozamcts" t8=L"ncharTagValue"', \
                        f'{stb_name}_6 1626006833639017US "hkgjiwdj" t0=f t1=127i8 t2=32767I16 t3=2147483647i32 t4=9223372036854775807I64 t5=11.12345f32 t6=22.123456789f64 t7="vozamcts" t8=L"ncharTagValue"', \
                        f'{stb_name}_7 1626006833640Ms "hkgjiwdj" t0=f t1=127i8 t2=32767I16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789F64 t7="vozamcts" t8=L"ncharTagValue"', \
                        f'{stb_name}_8 1626006833641mS "hkgjiwdj" t0=f t1=127i8 t2=32767I16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="vozamcts" t8=L"ncharTagValue"', \
                        f'{stb_name}_9 1626006833642MS "hkgjiwdj" t0=f t1=127i8 t2=32767I16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="vozamcts" t8=L"ncharTagValue"', \
                        f'{stb_name}_10 1626006834S "hkgjiwdj" t0=f t1=127i8 t2=32767I16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="vozamcts" t8=l"ncharTagValue"', \
                        f'{stb_name}_11 1626006834S "hkgjiwdj" t0=f t1=127i8 t2=32767I16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="vozamcts" t8=L"ncharTagValue"']
J
jiajingbin 已提交
1050
        for input_sql in input_sql_list:
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
            stb_name = input_sql.split(" ")[0]
            self.resCmp(input_sql, stb_name)

    def pointTransCheckCase(self):
        """
            metric value "." trans to "_"
        """
        tdCom.cleanTb()
        input_sql = self.genFullTypeSql(point_trans_tag=True)[0]
        stb_name = input_sql.split(" ")[0].replace(".", "_")
        self.resCmp(input_sql, stb_name)

    def defaultTypeCheckCase(self):
        stb_name = tdCom.getLongName(8, "letters")
        input_sql_list = [f'{stb_name}_1 1626006833639000000Ns 9223372036854775807 t0=f t1=127 t2=32767i16 t3=2147483647i32 t4=9223372036854775807 t5=11.12345f32 t6=22.123456789f64 t7="vozamcts" t8=L"ncharTagValue"', \
                        f'{stb_name}_2 1626006834S 22.123456789 t0=f t1=127i8 t2=32767I16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789 t7="vozamcts" t8=L"ncharTagValue"', \
                        f'{stb_name}_3 1626006834S 10e5 t0=f t1=127i8 t2=32767I16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=10e5 t7="vozamcts" t8=L"ncharTagValue"', \
                        f'{stb_name}_4 1626006834S 10.0e5 t0=f t1=127i8 t2=32767I16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=10.0e5 t7="vozamcts" t8=L"ncharTagValue"', \
                        f'{stb_name}_5 1626006834S -10.0e5 t0=f t1=127i8 t2=32767I16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=-10.0e5 t7="vozamcts" t8=L"ncharTagValue"']
        for input_sql in input_sql_list:
            stb_name = input_sql.split(" ")[0]
            self.resCmp(input_sql, stb_name)
J
jiajingbin 已提交
1073

J
jiajingbin 已提交
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087
    def genSqlList(self, count=5, stb_name="", tb_name=""):
        """
            stb --> supertable
            tb  --> table
            ts  --> timestamp, same default
            col --> column, same default
            tag --> tag, same default
            d   --> different
            s   --> same
            a   --> add
            m   --> minus
        """
        d_stb_d_tb_list = list()
        s_stb_s_tb_list = list()
1088 1089
        s_stb_s_tb_a_tag_list = list()
        s_stb_s_tb_m_tag_list = list()
J
jiajingbin 已提交
1090
        s_stb_d_tb_list = list()
1091 1092
        s_stb_d_tb_m_tag_list = list()
        s_stb_d_tb_a_tag_list = list()
J
jiajingbin 已提交
1093
        s_stb_s_tb_d_ts_list = list()
1094 1095
        s_stb_s_tb_d_ts_m_tag_list = list()
        s_stb_s_tb_d_ts_a_tag_list = list()
J
jiajingbin 已提交
1096
        s_stb_d_tb_d_ts_list = list()
1097 1098
        s_stb_d_tb_d_ts_m_tag_list = list()
        s_stb_d_tb_d_ts_a_tag_list = list()
J
jiajingbin 已提交
1099
        for i in range(count):
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
            d_stb_d_tb_list.append(self.genFullTypeSql(t0="f", value="f"))
            s_stb_s_tb_list.append(self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"'))
            s_stb_s_tb_a_tag_list.append(self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', t_add_tag=True))
            s_stb_s_tb_m_tag_list.append(self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', t_mul_tag=True))
            s_stb_d_tb_list.append(self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True))
            s_stb_d_tb_m_tag_list.append(self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True, t_mul_tag=True))
            s_stb_d_tb_a_tag_list.append(self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True, t_add_tag=True))
            s_stb_s_tb_d_ts_list.append(self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', ts=0))
            s_stb_s_tb_d_ts_m_tag_list.append(self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', ts=0, t_mul_tag=True))
            s_stb_s_tb_d_ts_a_tag_list.append(self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', ts=0, t_add_tag=True))
            s_stb_d_tb_d_ts_list.append(self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True, ts=0))
            s_stb_d_tb_d_ts_m_tag_list.append(self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True, ts=0, t_mul_tag=True))
            s_stb_d_tb_d_ts_a_tag_list.append(self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True, ts=0, t_add_tag=True))

        return d_stb_d_tb_list, s_stb_s_tb_list, s_stb_s_tb_a_tag_list, s_stb_s_tb_m_tag_list, \
            s_stb_d_tb_list, s_stb_d_tb_m_tag_list, s_stb_d_tb_a_tag_list, s_stb_s_tb_d_ts_list, \
            s_stb_s_tb_d_ts_m_tag_list, s_stb_s_tb_d_ts_a_tag_list, s_stb_d_tb_d_ts_list, \
            s_stb_d_tb_d_ts_m_tag_list, s_stb_d_tb_d_ts_a_tag_list
J
jiajingbin 已提交
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148


    def genMultiThreadSeq(self, sql_list):
        tlist = list()
        for insert_sql in sql_list:
            t = threading.Thread(target=self._conn.insert_telnet_lines,args=([insert_sql[0]],))
            tlist.append(t)
        return tlist

    def multiThreadRun(self, tlist):
        for t in tlist:
            t.start()
        for t in tlist:
            t.join()

    def stbInsertMultiThreadCheckCase(self):
        """
            thread input different stb
        """
        tdCom.cleanTb()
        input_sql = self.genSqlList()[0]
        self.multiThreadRun(self.genMultiThreadSeq(input_sql))
        tdSql.query(f"show tables;")
        tdSql.checkRows(5)
    
    def sStbStbDdataInsertMultiThreadCheckCase(self):
        """
            thread input same stb tb, different data, result keep first data
        """
        tdCom.cleanTb()
        tb_name = tdCom.getLongName(7, "letters")
1149
        input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name, value="\"binaryTagValue\"")
J
jiajingbin 已提交
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159
        self.resCmp(input_sql, stb_name)
        s_stb_s_tb_list = self.genSqlList(stb_name=stb_name, tb_name=tb_name)[1]
        self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_list))
        tdSql.query(f"show tables;")
        tdSql.checkRows(1)
        expected_tb_name = self.getNoIdTbName(stb_name)[0]
        tdSql.checkEqual(tb_name, expected_tb_name)
        tdSql.query(f"select * from {stb_name};")
        tdSql.checkRows(1)

1160
    def sStbStbDdataAtInsertMultiThreadCheckCase(self):
J
jiajingbin 已提交
1161 1162 1163 1164 1165
        """
            thread input same stb tb, different data, add columes and tags,  result keep first data
        """
        tdCom.cleanTb()
        tb_name = tdCom.getLongName(7, "letters")
1166
        input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name, value="\"binaryTagValue\"")
J
jiajingbin 已提交
1167
        self.resCmp(input_sql, stb_name)
1168 1169
        s_stb_s_tb_a_tag_list = self.genSqlList(stb_name=stb_name, tb_name=tb_name)[2]
        self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_a_tag_list))
J
jiajingbin 已提交
1170 1171 1172 1173 1174 1175 1176
        tdSql.query(f"show tables;")
        tdSql.checkRows(1)
        expected_tb_name = self.getNoIdTbName(stb_name)[0]
        tdSql.checkEqual(tb_name, expected_tb_name)
        tdSql.query(f"select * from {stb_name};")
        tdSql.checkRows(1)
    
1177
    def sStbStbDdataMtInsertMultiThreadCheckCase(self):
J
jiajingbin 已提交
1178 1179 1180 1181 1182
        """
            thread input same stb tb, different data, minus columes and tags,  result keep first data
        """
        tdCom.cleanTb()
        tb_name = tdCom.getLongName(7, "letters")
1183
        input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name, value="\"binaryTagValue\"")
J
jiajingbin 已提交
1184
        self.resCmp(input_sql, stb_name)
1185 1186
        s_stb_s_tb_m_tag_list = self.genSqlList(stb_name=stb_name, tb_name=tb_name)[3]
        self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_m_tag_list))
J
jiajingbin 已提交
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
        tdSql.query(f"show tables;")
        tdSql.checkRows(1)
        expected_tb_name = self.getNoIdTbName(stb_name)[0]
        tdSql.checkEqual(tb_name, expected_tb_name)
        tdSql.query(f"select * from {stb_name};")
        tdSql.checkRows(1)

    def sStbDtbDdataInsertMultiThreadCheckCase(self):
        """
            thread input same stb, different tb, different data
        """
        tdCom.cleanTb()
1199
        input_sql, stb_name = self.genFullTypeSql(value="\"binaryTagValue\"")
J
jiajingbin 已提交
1200 1201 1202 1203 1204 1205
        self.resCmp(input_sql, stb_name)
        s_stb_d_tb_list = self.genSqlList(stb_name=stb_name)[4]
        self.multiThreadRun(self.genMultiThreadSeq(s_stb_d_tb_list))
        tdSql.query(f"show tables;")
        tdSql.checkRows(6)

1206
    def sStbDtbDdataMtInsertMultiThreadCheckCase(self):
J
jiajingbin 已提交
1207 1208 1209 1210
        """
            thread input same stb, different tb, different data, add col, mul tag
        """
        tdCom.cleanTb()
1211
        input_sql, stb_name = self.genFullTypeSql(value="\"binaryTagValue\"")
J
jiajingbin 已提交
1212
        self.resCmp(input_sql, stb_name)
1213 1214 1215 1216 1217
        s_stb_d_tb_m_tag_list = [(f'{stb_name} 1626006833639000000ns "omfdhyom" t0=F t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'yzwswz'),  \
                                (f'{stb_name} 1626006833639000000ns "vqowydbc" t0=F t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'yzwswz'),  \
                                (f'{stb_name} 1626006833639000000ns "plgkckpv" t0=F t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'yzwswz'),  \
                                (f'{stb_name} 1626006833639000000ns "cujyqvlj" t0=F t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'yzwswz'),  \
                                (f'{stb_name} 1626006833639000000ns "twjxisat" t0=T t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'yzwswz')]
1218
        self.multiThreadRun(self.genMultiThreadSeq(s_stb_d_tb_m_tag_list))
J
jiajingbin 已提交
1219
        tdSql.query(f"show tables;")
1220
        tdSql.checkRows(3)
J
jiajingbin 已提交
1221

1222
    def sStbDtbDdataAtInsertMultiThreadCheckCase(self):
J
jiajingbin 已提交
1223 1224 1225 1226
        """
            thread input same stb, different tb, different data, add tag, mul col
        """
        tdCom.cleanTb()
1227
        input_sql, stb_name = self.genFullTypeSql(value="\"binaryTagValue\"")
J
jiajingbin 已提交
1228
        self.resCmp(input_sql, stb_name)
1229 1230
        s_stb_d_tb_a_tag_list = self.genSqlList(stb_name=stb_name)[6]
        self.multiThreadRun(self.genMultiThreadSeq(s_stb_d_tb_a_tag_list))
J
jiajingbin 已提交
1231 1232 1233 1234 1235 1236 1237 1238 1239
        tdSql.query(f"show tables;")
        tdSql.checkRows(6)

    def sStbStbDdataDtsInsertMultiThreadCheckCase(self):
        """
            thread input same stb tb, different ts
        """
        tdCom.cleanTb()
        tb_name = tdCom.getLongName(7, "letters")
1240
        input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name, value="\"binaryTagValue\"")
J
jiajingbin 已提交
1241
        self.resCmp(input_sql, stb_name)
1242 1243 1244 1245 1246
        s_stb_s_tb_d_ts_list = [(f'{stb_name} 0 "hkgjiwdj" id="{tb_name}" t0=f t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="vozamcts" t8=L"ncharTagValue"', 'dwpthv'), \
                                (f'{stb_name} 0 "rljjrrul" id="{tb_name}" t0=False t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="bmcanhbs" t8=L"ncharTagValue"', 'dwpthv'), \
                                (f'{stb_name} 0 "basanglx" id="{tb_name}" t0=False t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="enqkyvmb" t8=L"ncharTagValue"', 'dwpthv'), \
                                (f'{stb_name} 0 "clsajzpp" id="{tb_name}" t0=F t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="eivaegjk" t8=L"ncharTagValue"', 'dwpthv'), \
                                (f'{stb_name} 0 "jitwseso" id="{tb_name}" t0=T t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="yhlwkddq" t8=L"ncharTagValue"', 'dwpthv')]
J
jiajingbin 已提交
1247 1248 1249 1250 1251 1252
        self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_d_ts_list))
        tdSql.query(f"show tables;")
        tdSql.checkRows(1)
        tdSql.query(f"select * from {stb_name}")
        tdSql.checkRows(6)

1253
    def sStbStbDdataDtsMtInsertMultiThreadCheckCase(self):
J
jiajingbin 已提交
1254 1255 1256 1257 1258
        """
            thread input same stb tb, different ts, add col, mul tag
        """
        tdCom.cleanTb()
        tb_name = tdCom.getLongName(7, "letters")
1259
        input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name, value="\"binaryTagValue\"")
J
jiajingbin 已提交
1260
        self.resCmp(input_sql, stb_name)
1261 1262
        s_stb_s_tb_d_ts_m_tag_list = self.genSqlList(stb_name=stb_name, tb_name=tb_name)[8]
        self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_d_ts_m_tag_list))
J
jiajingbin 已提交
1263 1264 1265 1266 1267 1268 1269
        tdSql.query(f"show tables;")
        tdSql.checkRows(1)
        tdSql.query(f"select * from {stb_name}")
        tdSql.checkRows(6)
        tdSql.query(f"select * from {stb_name} where t8 is not NULL")
        tdSql.checkRows(6)

1270
    def sStbStbDdataDtsAtInsertMultiThreadCheckCase(self):
J
jiajingbin 已提交
1271 1272 1273 1274 1275
        """
            thread input same stb tb, different ts, add tag, mul col
        """
        tdCom.cleanTb()
        tb_name = tdCom.getLongName(7, "letters")
1276
        input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name, value="\"binaryTagValue\"")
J
jiajingbin 已提交
1277
        self.resCmp(input_sql, stb_name)
1278 1279 1280 1281 1282
        s_stb_s_tb_d_ts_a_tag_list = [(f'{stb_name} 0 "clummqfy" id="{tb_name}" t0=False t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="hpxzrdiw" t8=L"ncharTagValue" t11=127i8 t10=L"ncharTagValue"', 'bokaxl'), \
                                    (f'{stb_name} 0 "yqeztggb" id="{tb_name}" t0=F t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="gdtblmrc" t8=L"ncharTagValue" t11=127i8 t10=L"ncharTagValue"', 'bokaxl'), \
                                    (f'{stb_name} 0 "gbkinqdk" id="{tb_name}" t0=f t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="iqniuvco" t8=L"ncharTagValue" t11=127i8 t10=L"ncharTagValue"', 'bokaxl'), \
                                    (f'{stb_name} 0 "ldxxejbd" id="{tb_name}" t0=f t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="vxkipags" t8=L"ncharTagValue" t11=127i8 t10=L"ncharTagValue"', 'bokaxl'), \
                                    (f'{stb_name} 0 "tlvzwjes" id="{tb_name}" t0=true t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="enwrlrtj" t8=L"ncharTagValue" t11=127i8 t10=L"ncharTagValue"', 'bokaxl')]
1283
        self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_d_ts_a_tag_list))
J
jiajingbin 已提交
1284 1285 1286 1287 1288 1289
        tdSql.query(f"show tables;")
        tdSql.checkRows(1)
        tdSql.query(f"select * from {stb_name}")
        tdSql.checkRows(6)
        for t in ["t10", "t11"]:
            tdSql.query(f"select * from {stb_name} where {t} is not NULL;")
1290
            tdSql.checkRows(0)
J
jiajingbin 已提交
1291 1292 1293 1294 1295 1296

    def sStbDtbDdataDtsInsertMultiThreadCheckCase(self):
        """
            thread input same stb, different tb, data, ts
        """
        tdCom.cleanTb()
1297
        input_sql, stb_name = self.genFullTypeSql(value="\"binaryTagValue\"")
J
jiajingbin 已提交
1298 1299 1300 1301 1302 1303
        self.resCmp(input_sql, stb_name)
        s_stb_d_tb_d_ts_list = self.genSqlList(stb_name=stb_name)[10]
        self.multiThreadRun(self.genMultiThreadSeq(s_stb_d_tb_d_ts_list))
        tdSql.query(f"show tables;")
        tdSql.checkRows(6)

1304
    def sStbDtbDdataDtsMtInsertMultiThreadCheckCase(self):
J
jiajingbin 已提交
1305 1306 1307 1308
        """
            thread input same stb, different tb, data, ts, add col, mul tag
        """
        tdCom.cleanTb()
1309
        input_sql, stb_name = self.genFullTypeSql(value="\"binaryTagValue\"")
J
jiajingbin 已提交
1310
        self.resCmp(input_sql, stb_name)
1311 1312 1313 1314 1315
        s_stb_d_tb_d_ts_m_tag_list = [(f'{stb_name} 0 "mnpmtzul" t0=f t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'pcppkg'), \
                                    (f'{stb_name} 0 "zbvwckcd" t0=True t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'pcppkg'), \
                                    (f'{stb_name} 0 "vymcjfwc" t0=F t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'pcppkg'), \
                                    (f'{stb_name} 0 "laumkwfn" t0=False t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'pcppkg'), \
                                    (f'{stb_name} 0 "nyultzxr" t0=false t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'pcppkg')]
1316
        self.multiThreadRun(self.genMultiThreadSeq(s_stb_d_tb_d_ts_m_tag_list))
J
jiajingbin 已提交
1317
        tdSql.query(f"show tables;")
1318
        tdSql.checkRows(3)
J
jiajingbin 已提交
1319 1320 1321

    def test(self):
        try:
1322
            input_sql = f'test_nchar 0 L"涛思数据" t0=f t1=L"涛思数据" t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64'
1323
            self._conn.insert_telnet_lines([input_sql])
1324
        except TelnetLinesError as err:
J
jiajingbin 已提交
1325 1326 1327
            print(err.errno)

    def runAll(self):
1328 1329
        self.initCheckCase()
        self.boolTypeCheckCase()
1330
        self.symbolsCheckCase()
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343
        self.tsCheckCase()
        self.idSeqCheckCase()
        self.idUpperCheckCase()
        self.noIdCheckCase()
        self.maxColTagCheckCase()
        self.idIllegalNameCheckCase()
        self.idStartWithNumCheckCase()
        self.nowTsCheckCase()
        self.dateFormatTsCheckCase()
        self.illegalTsCheckCase()
        self.tagValueLengthCheckCase()
        self.colValueLengthCheckCase()
        self.tagColIllegalValueCheckCase()
1344
        self.blankCheckCase()
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354
        self.duplicateIdTagColInsertCheckCase()
        self.noIdStbExistCheckCase()
        self.duplicateInsertExistCheckCase()
        self.tagColBinaryNcharLengthCheckCase()
        self.tagColAddDupIDCheckCase()
        self.tagColAddCheckCase()
        self.tagMd5Check()
        self.tagColBinaryMaxLengthCheckCase()
        self.tagColNcharMaxLengthCheckCase()
        self.batchInsertCheckCase()
1355
        self.multiInsertCheckCase(10)
1356 1357 1358 1359 1360 1361
        self.batchErrorInsertCheckCase()
        self.multiColsInsertCheckCase()
        self.blankColInsertCheckCase()
        self.blankTagInsertCheckCase()
        self.chineseCheckCase()
        self.multiFieldCheckCase()
J
jiajingbin 已提交
1362
        self.errorTypeCheckCase()
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377
        self.pointTransCheckCase()
        self.defaultTypeCheckCase()
        # # MultiThreads
        self.stbInsertMultiThreadCheckCase()
        self.sStbStbDdataInsertMultiThreadCheckCase()
        self.sStbStbDdataAtInsertMultiThreadCheckCase()
        self.sStbStbDdataMtInsertMultiThreadCheckCase()
        self.sStbDtbDdataInsertMultiThreadCheckCase()
        self.sStbDtbDdataMtInsertMultiThreadCheckCase()
        self.sStbDtbDdataAtInsertMultiThreadCheckCase()
        self.sStbStbDdataDtsInsertMultiThreadCheckCase()
        self.sStbStbDdataDtsMtInsertMultiThreadCheckCase()
        self.sStbStbDdataDtsAtInsertMultiThreadCheckCase()
        self.sStbDtbDdataDtsInsertMultiThreadCheckCase()
        self.sStbDtbDdataDtsMtInsertMultiThreadCheckCase()
J
jiajingbin 已提交
1378 1379 1380 1381 1382 1383

    def run(self):
        print("running {}".format(__file__))
        self.createDb()
        try:
            self.runAll()
1384
            # self.test()
J
jiajingbin 已提交
1385 1386 1387 1388 1389 1390 1391 1392 1393 1394
        except Exception as err:
            print(''.join(traceback.format_exception(None, err, err.__traceback__)))
            raise err

    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)

tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())