cast.py 41.3 KB
Newer Older
C
cpwu 已提交
1 2
import taos
import sys
C
cpwu 已提交
3
import datetime
C
cpwu 已提交
4
import inspect
C
cpwu 已提交
5 6 7 8

from util.log import *
from util.sql import *
from util.cases import *
C
cpwu 已提交
9
from util.dnodes import *
C
cpwu 已提交
10 11 12 13 14



class TDTestCase:

15
    def init(self, conn, logSql, replicaVar=1):
16
        self.replicaVar = int(replicaVar)
C
cpwu 已提交
17
        tdLog.debug(f"start to excute {__file__}")
18
        tdSql.init(conn.cursor(), True)
C
cpwu 已提交
19
        self.dbname = "db"
C
cpwu 已提交
20

C
cpwu 已提交
21 22 23 24
    def __cast_to_bigint(self, col_name, tbname):
        __sql = f"select cast({col_name} as bigint), {col_name} from {tbname}"
        tdSql.query(sql=__sql)
        data_tb_col = [result[1] for result in tdSql.queryResult]
C
cpwu 已提交
25
        for i in range(tdSql.queryRows):
C
cpwu 已提交
26 27 28 29 30 31 32 33 34 35 36
            tdSql.checkData( i, 0, None ) if data_tb_col[i] is None else tdSql.checkData( i, 0, int(data_tb_col[i]) )

    def __range_to_bigint(self,cols,tables):
        for col in cols:
            for table in tables:
                self.__cast_to_bigint(col_name=col, tbname=table)

    def __cast_to_timestamp(self, col_name, tbname):
        __sql = f"select cast({col_name} as timestamp), {col_name} from {tbname}"
        tdSql.query(sql=__sql)
        data_tb_col = [result[1] for result in tdSql.queryResult]
C
cpwu 已提交
37
        for i in range(tdSql.queryRows):
C
cpwu 已提交
38 39
            if data_tb_col[i] is None:
                tdSql.checkData( i, 0 , None )
C
cpwu 已提交
40
            if col_name not in ["c2", "double"] or tbname != f"{self.dbname}.t1" or i != 10:
41 42
                date_init_stamp = datetime.datetime.fromtimestamp(data_tb_col[i]/1000)
                tdSql.checkData( i, 0, date_init_stamp)
C
cpwu 已提交
43 44 45 46 47 48 49

    def __range_to_timestamp(self, cols, tables):
        for col in cols:
            for table in tables:
                self.__cast_to_timestamp(col_name=col, tbname=table)

    def __test_bigint(self):
C
cpwu 已提交
50
        __table_list = [f"{self.dbname}.ct1", f"{self.dbname}.ct4", f"{self.dbname}.t1"]
C
cpwu 已提交
51 52 53 54
        __col_list = ["c1","c2","c3","c4","c5","c6","c7","c10","c1+c2"]
        self.__range_to_bigint(cols=__col_list, tables=__table_list)

    def __test_timestamp(self):
C
cpwu 已提交
55
        __table_list = [f"{self.dbname}.ct1", f"{self.dbname}.ct4", f"{self.dbname}.t1"]
C
cpwu 已提交
56 57 58
        __col_list = ["c1","c2","c3","c4","c5","c6","c7","c1+c2"]
        self.__range_to_timestamp(cols=__col_list, tables=__table_list)

C
cpwu 已提交
59
    def all_test(self):
60
        _datetime_epoch = datetime.datetime.fromtimestamp(0)
C
cpwu 已提交
61
        tdSql.query(f"select c1  from {self.dbname}.ct4")
C
cpwu 已提交
62
        data_ct4_c1 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
C
cpwu 已提交
63
        tdSql.query(f"select c1  from {self.dbname}.t1")
C
cpwu 已提交
64
        data_t1_c1 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
C
cpwu 已提交
65 66
        tdLog.printNoPrefix("==========step2: cast int to bigint, expect no changes")

C
cpwu 已提交
67
        tdSql.query(f"select cast(c1 as bigint) as b from {self.dbname}.ct4")
C
cpwu 已提交
68 69
        for i in range(len(data_ct4_c1)):
            tdSql.checkData( i, 0, data_ct4_c1[i])
C
cpwu 已提交
70
        tdSql.query(f"select cast(c1 as bigint) as b from {self.dbname}.t1")
C
cpwu 已提交
71 72
        for i in range(len(data_t1_c1)):
            tdSql.checkData( i, 0, data_t1_c1[i])
C
cpwu 已提交
73

C
cpwu 已提交
74
        tdLog.printNoPrefix("==========step5: cast int to binary, expect changes to str(int) ")
C
cpwu 已提交
75

C
cpwu 已提交
76
        #tdSql.query(f"select cast(c1 as binary(32)) as b from {self.dbname}.ct4")
S
shenglian zhou 已提交
77 78
        #for i in range(len(data_ct4_c1)):
        #    tdSql.checkData( i, 0, str(data_ct4_c1[i]) )
C
cpwu 已提交
79
        tdSql.query(f"select cast(c1 as binary(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
80 81
        for i in range(len(data_t1_c1)):
            tdSql.checkData( i, 0, str(data_t1_c1[i]) )
C
cpwu 已提交
82

C
cpwu 已提交
83
        tdLog.printNoPrefix("==========step6: cast int to nchar, expect changes to str(int) ")
C
cpwu 已提交
84

C
cpwu 已提交
85
        tdSql.query(f"select cast(c1 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
86 87
        for i in range(len(data_ct4_c1)):
            tdSql.checkData( i, 0, str(data_ct4_c1[i]) )
C
cpwu 已提交
88
        tdSql.query(f"select cast(c1 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
89 90
        for i in range(len(data_t1_c1)):
            tdSql.checkData( i, 0, str(data_t1_c1[i]) )
C
cpwu 已提交
91

C
cpwu 已提交
92
        tdLog.printNoPrefix("==========step7: cast int to timestamp, expect changes to timestamp ")
C
cpwu 已提交
93

C
cpwu 已提交
94
        tdSql.query(f"select cast(c1 as timestamp) as b from {self.dbname}.ct4")
C
cpwu 已提交
95 96
        for i in range(len(data_ct4_c1)):
            if data_ct4_c1[i] is None:
C
cpwu 已提交
97 98
                tdSql.checkData( i, 0 , None )
            else:
99 100
                date_init_stamp = _datetime_epoch+datetime.timedelta(seconds=int(data_ct4_c1[i]) / 1000.0)
                tdSql.checkData( i, 0, date_init_stamp)
C
cpwu 已提交
101

C
cpwu 已提交
102
        tdSql.query(f"select cast(c1 as timestamp) as b from {self.dbname}.t1")
C
cpwu 已提交
103
        for i in range(len(data_t1_c1)):
D
dapan1121 已提交
104
            if data_t1_c1[i] is None:
C
cpwu 已提交
105 106
                tdSql.checkData( i, 0 , None )
            else:
107 108
                date_init_stamp = _datetime_epoch+datetime.timedelta(seconds=int(data_t1_c1[i]) / 1000.0)
                tdSql.checkData( i, 0, date_init_stamp)
C
cpwu 已提交
109 110 111


        tdLog.printNoPrefix("==========step8: cast bigint to bigint, expect no changes")
C
cpwu 已提交
112
        tdSql.query(f"select c2  from {self.dbname}.ct4")
C
cpwu 已提交
113
        data_ct4_c2 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
C
cpwu 已提交
114
        tdSql.query(f"select c2  from {self.dbname}.t1")
C
cpwu 已提交
115 116
        data_t1_c2 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]

C
cpwu 已提交
117
        tdSql.query(f"select cast(c2 as bigint) as b from {self.dbname}.ct4")
C
cpwu 已提交
118 119
        for i in range(len(data_ct4_c2)):
            tdSql.checkData( i, 0, data_ct4_c2[i])
C
cpwu 已提交
120
        tdSql.query(f"select cast(c2 as bigint) as b from {self.dbname}.t1")
C
cpwu 已提交
121 122 123 124 125 126
        for i in range(len(data_t1_c2)):
            tdSql.checkData( i, 0, data_t1_c2[i])


        tdLog.printNoPrefix("==========step9: cast bigint to binary, expect changes to str(int) ")

C
cpwu 已提交
127
        tdSql.query(f"select cast(c2 as binary(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
128 129
        for i in range(len(data_ct4_c2)):
            tdSql.checkData( i, 0, str(data_ct4_c2[i]) )
C
cpwu 已提交
130
        tdSql.query(f"select cast(c2 as binary(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
131 132 133 134 135
        for i in range(len(data_t1_c2)):
            tdSql.checkData( i, 0, str(data_t1_c2[i]) )

        tdLog.printNoPrefix("==========step10: cast bigint to nchar, expect changes to str(int) ")

C
cpwu 已提交
136
        tdSql.query(f"select cast(c2 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
137 138
        for i in range(len(data_ct4_c2)):
            tdSql.checkData( i, 0, str(data_ct4_c2[i]) )
C
cpwu 已提交
139
        tdSql.query(f"select cast(c2 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
140 141 142 143 144
        for i in range(len(data_t1_c2)):
            tdSql.checkData( i, 0, str(data_t1_c2[i]) )

        tdLog.printNoPrefix("==========step11: cast bigint to timestamp, expect changes to timestamp ")

C
cpwu 已提交
145
        tdSql.query(f"select cast(c2 as timestamp) as b from {self.dbname}.ct4")
C
cpwu 已提交
146 147 148 149
        for i in range(len(data_ct4_c2)):
            if data_ct4_c2[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
150 151
                date_init_stamp = _datetime_epoch+datetime.timedelta(seconds=int(data_ct4_c2[i]) / 1000.0)
                tdSql.checkData( i, 0, date_init_stamp)
C
cpwu 已提交
152

C
cpwu 已提交
153

C
cpwu 已提交
154
        tdSql.query(f"select cast(c2 as timestamp) as b from {self.dbname}.t1")
C
cpwu 已提交
155 156 157 158 159 160
        for i in range(len(data_t1_c2)):
            if data_t1_c2[i] is None:
                tdSql.checkData( i, 0 , None )
            elif i == 10:
                continue
            else:
161 162
                date_init_stamp = _datetime_epoch+datetime.timedelta(seconds=int(data_t1_c2[i]) / 1000.0)
                tdSql.checkData( i, 0, date_init_stamp)
C
cpwu 已提交
163 164 165


        tdLog.printNoPrefix("==========step12: cast smallint to bigint, expect no changes")
C
cpwu 已提交
166
        tdSql.query(f"select c3  from {self.dbname}.ct4")
C
cpwu 已提交
167
        data_ct4_c3 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
C
cpwu 已提交
168
        tdSql.query(f"select c3  from {self.dbname}.t1")
C
cpwu 已提交
169 170
        data_t1_c3 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]

C
cpwu 已提交
171
        tdSql.query(f"select cast(c3 as bigint) as b from {self.dbname}.ct4")
C
cpwu 已提交
172 173
        for i in range(len(data_ct4_c3)):
            tdSql.checkData( i, 0, data_ct4_c3[i])
C
cpwu 已提交
174
        tdSql.query(f"select cast(c3 as bigint) as b from {self.dbname}.t1")
C
cpwu 已提交
175 176 177 178 179 180
        for i in range(len(data_t1_c3)):
            tdSql.checkData( i, 0, data_t1_c3[i])


        tdLog.printNoPrefix("==========step13: cast smallint to binary, expect changes to str(int) ")

C
cpwu 已提交
181
        tdSql.query(f"select cast(c3 as binary(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
182 183
        for i in range(len(data_ct4_c3)):
            tdSql.checkData( i, 0, str(data_ct4_c3[i]) )
C
cpwu 已提交
184
        tdSql.query(f"select cast(c3 as binary(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
185 186 187 188 189
        for i in range(len(data_t1_c3)):
            tdSql.checkData( i, 0, str(data_t1_c3[i]) )

        tdLog.printNoPrefix("==========step14: cast smallint to nchar, expect changes to str(int) ")

C
cpwu 已提交
190
        tdSql.query(f"select cast(c3 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
191 192
        for i in range(len(data_ct4_c3)):
            tdSql.checkData( i, 0, str(data_ct4_c3[i]) )
C
cpwu 已提交
193
        tdSql.query(f"select cast(c3 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
194 195 196 197 198
        for i in range(len(data_t1_c3)):
            tdSql.checkData( i, 0, str(data_t1_c3[i]) )

        tdLog.printNoPrefix("==========step15: cast smallint to timestamp, expect changes to timestamp ")

C
cpwu 已提交
199
        tdSql.query(f"select cast(c3 as timestamp) as b from {self.dbname}.ct4")
C
cpwu 已提交
200 201 202 203
        for i in range(len(data_ct4_c3)):
            if data_ct4_c3[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
204 205
                date_init_stamp = _datetime_epoch+datetime.timedelta(seconds=int(data_ct4_c3[i]) / 1000.0)
                tdSql.checkData( i, 0, date_init_stamp)
C
cpwu 已提交
206

C
cpwu 已提交
207
        tdSql.query(f"select cast(c3 as timestamp) as b from {self.dbname}.t1")
C
cpwu 已提交
208
        for i in range(len(data_t1_c3)):
D
dapan1121 已提交
209
            if data_t1_c3[i] is None:
C
cpwu 已提交
210 211
                tdSql.checkData( i, 0 , None )
            else:
212 213
                date_init_stamp = _datetime_epoch+datetime.timedelta(seconds=int(data_t1_c3[i]) / 1000.0)
                tdSql.checkData( i, 0, date_init_stamp)
C
cpwu 已提交
214 215


C
cpwu 已提交
216
        tdLog.printNoPrefix("==========step16: cast tinyint to bigint, expect no changes")
C
cpwu 已提交
217
        tdSql.query(f"select c4  from {self.dbname}.ct4")
C
cpwu 已提交
218
        data_ct4_c4 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
C
cpwu 已提交
219
        tdSql.query(f"select c4  from {self.dbname}.t1")
C
cpwu 已提交
220 221
        data_t1_c4 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]

C
cpwu 已提交
222
        tdSql.query(f"select cast(c4 as bigint) as b from {self.dbname}.ct4")
C
cpwu 已提交
223 224
        for i in range(len(data_ct4_c4)):
            tdSql.checkData( i, 0, data_ct4_c4[i])
C
cpwu 已提交
225
        tdSql.query(f"select cast(c4 as bigint) as b from {self.dbname}.t1")
C
cpwu 已提交
226 227 228 229
        for i in range(len(data_t1_c4)):
            tdSql.checkData( i, 0, data_t1_c4[i])


C
cpwu 已提交
230
        tdLog.printNoPrefix("==========step17: cast tinyint to binary, expect changes to str(int) ")
C
cpwu 已提交
231

C
cpwu 已提交
232
        tdSql.query(f"select cast(c4 as binary(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
233 234
        for i in range(len(data_ct4_c4)):
            tdSql.checkData( i, 0, str(data_ct4_c4[i]) )
C
cpwu 已提交
235
        tdSql.query(f"select cast(c4 as binary(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
236 237 238
        for i in range(len(data_t1_c4)):
            tdSql.checkData( i, 0, str(data_t1_c4[i]) )

C
cpwu 已提交
239
        tdLog.printNoPrefix("==========step18: cast tinyint to nchar, expect changes to str(int) ")
C
cpwu 已提交
240

C
cpwu 已提交
241
        tdSql.query(f"select cast(c4 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
242 243
        for i in range(len(data_ct4_c4)):
            tdSql.checkData( i, 0, str(data_ct4_c4[i]) )
C
cpwu 已提交
244
        tdSql.query(f"select cast(c4 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
245 246 247
        for i in range(len(data_t1_c4)):
            tdSql.checkData( i, 0, str(data_t1_c4[i]) )

C
cpwu 已提交
248
        tdLog.printNoPrefix("==========step19: cast tinyint to timestamp, expect changes to timestamp ")
C
cpwu 已提交
249

C
cpwu 已提交
250
        tdSql.query(f"select cast(c4 as timestamp) as b from {self.dbname}.ct4")
C
cpwu 已提交
251 252 253 254
        for i in range(len(data_ct4_c4)):
            if data_ct4_c4[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
255 256
                date_init_stamp = _datetime_epoch+datetime.timedelta(seconds=int(data_ct4_c4[i]) / 1000.0)
                tdSql.checkData( i, 0, date_init_stamp)
C
cpwu 已提交
257

C
cpwu 已提交
258
        tdSql.query(f"select cast(c4 as timestamp) as b from {self.dbname}.t1")
C
cpwu 已提交
259
        for i in range(len(data_t1_c4)):
D
dapan1121 已提交
260
            if data_t1_c4[i] is None:
C
cpwu 已提交
261 262
                tdSql.checkData( i, 0 , None )
            else:
263 264
                date_init_stamp = _datetime_epoch+datetime.timedelta(seconds=int(data_t1_c4[i]) / 1000.0)
                tdSql.checkData( i, 0, date_init_stamp)
C
cpwu 已提交
265 266 267


        tdLog.printNoPrefix("==========step20: cast float to bigint, expect no changes")
C
cpwu 已提交
268
        tdSql.query(f"select c5  from {self.dbname}.ct4")
C
cpwu 已提交
269
        data_ct4_c5 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
C
cpwu 已提交
270
        tdSql.query(f"select c5  from {self.dbname}.t1")
C
cpwu 已提交
271 272
        data_t1_c5 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]

C
cpwu 已提交
273
        tdSql.query(f"select cast(c5 as bigint) as b from {self.dbname}.ct4")
C
cpwu 已提交
274
        for i in range(len(data_ct4_c5)):
C
cpwu 已提交
275
            tdSql.checkData( i, 0, None ) if data_ct4_c5[i] is None else tdSql.checkData( i, 0, int(data_ct4_c5[i]) )
C
cpwu 已提交
276
        tdSql.query(f"select cast(c5 as bigint) as b from {self.dbname}.t1")
C
cpwu 已提交
277
        for i in range(len(data_t1_c5)):
C
cpwu 已提交
278
            tdSql.checkData( i, 0, None ) if data_t1_c5[i] is None else tdSql.checkData( i, 0, int(data_t1_c5[i]) )
C
cpwu 已提交
279 280

        tdLog.printNoPrefix("==========step21: cast float to binary, expect changes to str(int) ")
C
cpwu 已提交
281
        tdSql.query(f"select cast(c5 as binary(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
282
        for i in range(len(data_ct4_c5)):
C
cpwu 已提交
283
            tdSql.checkData( i, 0, str(data_ct4_c5[i]) )  if data_ct4_c5[i] is None else  tdSql.checkData( i, 0, f'{data_ct4_c5[i]:.6f}' )
C
cpwu 已提交
284
        tdSql.query(f"select cast(c5 as binary(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
285
        for i in range(len(data_t1_c5)):
C
cpwu 已提交
286
            tdSql.checkData( i, 0, str(data_t1_c5[i]) )  if data_t1_c5[i] is None else tdSql.checkData( i, 0, f'{data_t1_c5[i]:.6f}' )
C
cpwu 已提交
287 288

        tdLog.printNoPrefix("==========step22: cast float to nchar, expect changes to str(int) ")
C
cpwu 已提交
289
        tdSql.query(f"select cast(c5 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
290
        for i in range(len(data_ct4_c5)):
C
cpwu 已提交
291
            tdSql.checkData( i, 0, None )  if data_ct4_c5[i] is None else  tdSql.checkData( i, 0, f'{data_ct4_c5[i]:.6f}' )
C
cpwu 已提交
292
        tdSql.query(f"select cast(c5 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
293
        for i in range(len(data_t1_c5)):
C
cpwu 已提交
294
            tdSql.checkData( i, 0, None )  if data_t1_c5[i] is None else tdSql.checkData( i, 0, f'{data_t1_c5[i]:.6f}' )
C
cpwu 已提交
295 296

        tdLog.printNoPrefix("==========step23: cast float to timestamp, expect changes to timestamp ")
C
cpwu 已提交
297
        tdSql.query(f"select cast(c5 as timestamp) as b from {self.dbname}.ct4")
C
cpwu 已提交
298 299 300 301
        for i in range(len(data_ct4_c5)):
            if data_ct4_c5[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
302 303
                date_init_stamp = _datetime_epoch+datetime.timedelta(seconds=int(data_ct4_c5[i]) / 1000.0)
                tdSql.checkData( i, 0, date_init_stamp)
C
cpwu 已提交
304
        tdSql.query(f"select cast(c5 as timestamp) as b from {self.dbname}.t1")
C
cpwu 已提交
305 306 307 308
        for i in range(len(data_t1_c5)):
            if data_t1_c5[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
309 310
                date_init_stamp = _datetime_epoch+datetime.timedelta(seconds=int(data_t1_c5[i]) / 1000.0)
                tdSql.checkData( i, 0, date_init_stamp)
C
cpwu 已提交
311 312

        tdLog.printNoPrefix("==========step24: cast double to bigint, expect no changes")
C
cpwu 已提交
313
        tdSql.query(f"select c6  from {self.dbname}.ct4")
C
cpwu 已提交
314
        data_ct4_c6 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
C
cpwu 已提交
315
        tdSql.query(f"select c6  from {self.dbname}.t1")
C
cpwu 已提交
316 317
        data_t1_c6 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]

C
cpwu 已提交
318
        tdSql.query(f"select cast(c6 as bigint) as b from {self.dbname}.ct4")
C
cpwu 已提交
319
        for i in range(len(data_ct4_c6)):
C
cpwu 已提交
320
            tdSql.checkData( i, 0, None ) if data_ct4_c6[i] is None else tdSql.checkData( i, 0, int(data_ct4_c6[i]) )
C
cpwu 已提交
321
        tdSql.query(f"select cast(c6 as bigint) as b from {self.dbname}.t1")
C
cpwu 已提交
322
        for i in range(len(data_t1_c6)):
C
cpwu 已提交
323 324 325 326 327 328
            if data_t1_c6[i] is None:
                tdSql.checkData( i, 0, None )
            elif data_t1_c6[i] > 99999999 or data_t1_c6[i] < -999999:
                continue
            else:
                tdSql.checkData( i, 0, int(data_t1_c6[i]) )
C
cpwu 已提交
329 330

        tdLog.printNoPrefix("==========step25: cast double to binary, expect changes to str(int) ")
C
cpwu 已提交
331
        tdSql.query(f"select cast(c6 as binary(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
332
        for i in range(len(data_ct4_c6)):
C
cpwu 已提交
333
            tdSql.checkData( i, 0, None )  if data_ct4_c6[i] is None else  tdSql.checkData( i, 0, f'{data_ct4_c6[i]:.6f}' )
C
cpwu 已提交
334
        tdSql.query(f"select cast(c6 as binary(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
335
        for i in range(len(data_t1_c6)):
C
cpwu 已提交
336
            tdSql.checkData( i, 0, None )  if data_t1_c6[i] is None else  tdSql.checkData( i, 0, f'{data_t1_c6[i]:.6f}' )
C
cpwu 已提交
337 338

        tdLog.printNoPrefix("==========step26: cast double to nchar, expect changes to str(int) ")
C
cpwu 已提交
339
        tdSql.query(f"select cast(c6 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
340
        for i in range(len(data_ct4_c6)):
C
cpwu 已提交
341
            tdSql.checkData( i, 0, None )  if data_ct4_c6[i] is None else  tdSql.checkData( i, 0, f'{data_ct4_c6[i]:.6f}' )
C
cpwu 已提交
342
        tdSql.query(f"select cast(c6 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
343
        for i in range(len(data_t1_c6)):
C
cpwu 已提交
344
            tdSql.checkData( i, 0, None )  if data_t1_c6[i] is None else  tdSql.checkData( i, 0, f'{data_t1_c6[i]:.6f}' )
C
cpwu 已提交
345 346

        tdLog.printNoPrefix("==========step27: cast double to timestamp, expect changes to timestamp ")
C
cpwu 已提交
347
        tdSql.query(f"select cast(c6 as timestamp) as b from {self.dbname}.ct4")
C
cpwu 已提交
348 349 350 351
        for i in range(len(data_ct4_c6)):
            if data_ct4_c6[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
352 353
                date_init_stamp = _datetime_epoch+datetime.timedelta(seconds=int(data_ct4_c6[i]) / 1000.0)
                tdSql.checkData( i, 0, date_init_stamp)
C
cpwu 已提交
354

C
cpwu 已提交
355
        tdSql.query(f"select cast(c6 as timestamp) as b from {self.dbname}.t1")
C
cpwu 已提交
356 357 358 359 360 361
        for i in range(len(data_t1_c6)):
            if data_t1_c6[i] is None:
                tdSql.checkData( i, 0 , None )
            elif i == 10:
                continue
            else:
362 363
                date_init_stamp = _datetime_epoch+datetime.timedelta(seconds=int(data_t1_c6[i]) / 1000.0)
                tdSql.checkData( i, 0, date_init_stamp)
C
cpwu 已提交
364 365

        tdLog.printNoPrefix("==========step28: cast bool to bigint, expect no changes")
C
cpwu 已提交
366
        tdSql.query(f"select c7  from {self.dbname}.ct4")
C
cpwu 已提交
367
        data_ct4_c7 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
C
cpwu 已提交
368
        tdSql.query(f"select c7  from {self.dbname}.t1")
C
cpwu 已提交
369 370
        data_t1_c7 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]

C
cpwu 已提交
371
        tdSql.query(f"select cast(c7 as bigint) as b from {self.dbname}.ct4")
C
cpwu 已提交
372 373
        for i in range(len(data_ct4_c7)):
            tdSql.checkData( i, 0, data_ct4_c7[i])
C
cpwu 已提交
374
        tdSql.query(f"select cast(c7 as bigint) as b from {self.dbname}.t1")
C
cpwu 已提交
375 376 377 378
        for i in range(len(data_t1_c7)):
            tdSql.checkData( i, 0, data_t1_c7[i])

        tdLog.printNoPrefix("==========step29: cast bool to binary, expect changes to str(int) ")
C
cpwu 已提交
379
        tdSql.query(f"select cast(c7 as binary(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
380
        for i in range(len(data_ct4_c7)):
C
cpwu 已提交
381
            tdSql.checkData( i, 0, None ) if data_ct4_c7[i] is None else tdSql.checkData( i, 0, str(data_ct4_c7[i]).lower() )
C
cpwu 已提交
382
        tdSql.query(f"select cast(c7 as binary(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
383
        for i in range(len(data_t1_c7)):
C
cpwu 已提交
384
            tdSql.checkData( i, 0, None ) if data_t1_c7[i] is None else tdSql.checkData( i, 0, str(data_t1_c7[i]).lower() )
C
cpwu 已提交
385 386

        tdLog.printNoPrefix("==========step30: cast bool to nchar, expect changes to str(int) ")
C
cpwu 已提交
387
        tdSql.query(f"select cast(c7 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
388
        for i in range(len(data_ct4_c7)):
C
cpwu 已提交
389
            tdSql.checkData( i, 0, None ) if data_ct4_c7[i] is None else tdSql.checkData( i, 0, str(data_ct4_c7[i]).lower() )
C
cpwu 已提交
390
        tdSql.query(f"select cast(c7 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
391
        for i in range(len(data_t1_c7)):
C
cpwu 已提交
392
            tdSql.checkData( i, 0, None ) if data_t1_c7[i] is None else tdSql.checkData( i, 0, str(data_t1_c7[i]).lower() )
C
cpwu 已提交
393 394

        tdLog.printNoPrefix("==========step31: cast bool to timestamp, expect changes to timestamp ")
C
cpwu 已提交
395
        tdSql.query(f"select cast(c7 as timestamp) as b from {self.dbname}.ct4")
C
cpwu 已提交
396 397 398 399
        for i in range(len(data_ct4_c7)):
            if data_ct4_c7[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
400 401
                date_init_stamp = _datetime_epoch+datetime.timedelta(seconds=int(data_ct4_c7[i]) / 1000.0)
                tdSql.checkData( i, 0, date_init_stamp)
C
cpwu 已提交
402
        tdSql.query(f"select cast(c7 as timestamp) as b from {self.dbname}.t1")
C
cpwu 已提交
403 404 405 406
        for i in range(len(data_t1_c7)):
            if data_t1_c7[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
407 408
                date_init_stamp = _datetime_epoch+datetime.timedelta(seconds=int(data_t1_c7[i]) / 1000.0)
                tdSql.checkData( i, 0, date_init_stamp)
C
cpwu 已提交
409 410


C
cpwu 已提交
411
        tdSql.query(f"select c8  from {self.dbname}.ct4")
C
cpwu 已提交
412
        data_ct4_c8 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
C
cpwu 已提交
413
        tdSql.query(f"select c8  from {self.dbname}.t1")
C
cpwu 已提交
414 415 416
        data_t1_c8 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]

        tdLog.printNoPrefix("==========step32: cast binary to binary, expect no changes ")
C
cpwu 已提交
417
        tdSql.query(f"select cast(c8 as binary(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
418
        for i in range(len(data_ct4_c8)):
C
cpwu 已提交
419
            tdSql.checkData( i, 0, None ) if data_ct4_c8[i] is None else  tdSql.checkData(i,0,data_ct4_c8[i])
C
cpwu 已提交
420

C
cpwu 已提交
421
        tdSql.query(f"select cast(c8 as binary(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
422
        for i in range(len(data_t1_c8)):
C
cpwu 已提交
423 424
            tdSql.checkData( i, 0, None ) if data_t1_c8[i] is None else  tdSql.checkData(i,0,data_t1_c8[i])

C
cpwu 已提交
425
        tdLog.printNoPrefix("==========step33: cast binary to binary, expect truncate ")
C
cpwu 已提交
426
        tdSql.query(f"select cast(c8 as binary(2)) as b from {self.dbname}.ct4")
C
cpwu 已提交
427
        for i in range(len(data_ct4_c8)):
C
cpwu 已提交
428 429
            if data_ct4_c8[i] is None:
                tdSql.checkData( i, 0, None)
C
cpwu 已提交
430 431
            elif tdSql.getData(i,0) == data_ct4_c8[i][:2]:
                tdLog.info( f"sql:{tdSql.sql}, row:{i} col:0 data:{tdSql.queryResult[i][0]} == expect:{data_ct4_c8[i][:2]}" )
C
cpwu 已提交
432 433
            else:
                caller = inspect.getframeinfo(inspect.stack()[1][0])
C
cpwu 已提交
434
                tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_ct4_c8[i][:2]}")
C
cpwu 已提交
435
        tdSql.query(f"select cast(c8 as binary(2)) as b from {self.dbname}.t1")
C
cpwu 已提交
436
        for i in range(len(data_t1_c8)):
C
cpwu 已提交
437 438
            if data_t1_c8[i] is None:
                tdSql.checkData( i, 0, None)
C
cpwu 已提交
439 440
            elif tdSql.getData(i,0) == data_t1_c8[i][:2]:
                tdLog.info( f"sql:{tdSql.sql}, row:{i} col:0 data:{tdSql.queryResult[i][0]} == expect:{data_t1_c8[i][:2]}" )
C
cpwu 已提交
441 442
            else:
                caller = inspect.getframeinfo(inspect.stack()[1][0])
C
cpwu 已提交
443
                tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_t1_c8[i][:2]}")
C
cpwu 已提交
444 445

        tdLog.printNoPrefix("==========step34: cast binary to nchar, expect changes to str(int) ")
C
cpwu 已提交
446
        tdSql.query(f"select cast(c8 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
447
        for i in range(len(data_ct4_c8)):
C
cpwu 已提交
448 449
            if data_ct4_c8[i] is None:
                tdSql.checkData( i, 0, None)
C
cpwu 已提交
450
            elif tdSql.getData(i,0) == data_ct4_c8[i]:
C
cpwu 已提交
451 452 453 454
                tdLog.info( f"sql:{tdSql.sql}, row:{i} col:0 data:{tdSql.queryResult[i][0]} == expect:{data_ct4_c8[i]}" )
            else:
                caller = inspect.getframeinfo(inspect.stack()[1][0])
                tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_ct4_c8[i]}")
C
cpwu 已提交
455
        tdSql.query(f"select cast(c8 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
456
        for i in range(len(data_t1_c8)):
C
cpwu 已提交
457 458
            if data_t1_c8[i] is None:
                tdSql.checkData( i, 0, None)
C
cpwu 已提交
459
            elif tdSql.getData(i,0) == data_t1_c8[i]:
C
cpwu 已提交
460 461 462 463
                tdLog.info( f"sql:{tdSql.sql}, row:{i} col:0 data:{tdSql.queryResult[i][0]} == expect:{data_t1_c8[i]}" )
            else:
                caller = inspect.getframeinfo(inspect.stack()[1][0])
                tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_t1_c8[i]}")
C
cpwu 已提交
464 465


C
cpwu 已提交
466
        tdSql.query(f"select c9  from {self.dbname}.ct4")
C
cpwu 已提交
467
        data_ct4_c9 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
C
cpwu 已提交
468
        tdSql.query(f"select c9  from {self.dbname}.t1")
C
cpwu 已提交
469 470 471 472
        data_t1_c9 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
        "c10 timestamp"

        tdLog.printNoPrefix("==========step35: cast nchar to nchar, expect no changes ")
C
cpwu 已提交
473
        tdSql.query(f"select cast(c9 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
474
        for i in range(len(data_ct4_c9)):
C
cpwu 已提交
475 476
            if data_ct4_c9[i] is None:
                tdSql.checkData( i, 0, None)
C
cpwu 已提交
477
            elif tdSql.getData(i,0) == data_ct4_c9[i]:
C
cpwu 已提交
478 479 480 481
                tdLog.info( f"sql:{tdSql.sql}, row:{i} col:0 data:{tdSql.queryResult[i][0]} == expect:{data_ct4_c9[i]}" )
            else:
                caller = inspect.getframeinfo(inspect.stack()[1][0])
                tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_ct4_c9[i]}")
C
cpwu 已提交
482
        tdSql.query(f"select cast(c9 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
483 484
        for i in range(len(data_t1_c9)):
            tdSql.checkData( i, 0, data_t1_c9[i] )
C
cpwu 已提交
485 486
            if data_t1_c9[i] is None:
                tdSql.checkData( i, 0, None)
C
cpwu 已提交
487
            elif tdSql.getData(i,0) == data_t1_c9[i]:
C
cpwu 已提交
488 489 490 491
                tdLog.info( f"sql:{tdSql.sql}, row:{i} col:0 data:{tdSql.queryResult[i][0]} == expect:{data_t1_c9[i]}" )
            else:
                caller = inspect.getframeinfo(inspect.stack()[1][0])
                tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_t1_c9[i]}")
C
cpwu 已提交
492 493

        tdLog.printNoPrefix("==========step36: cast nchar to nchar, expect truncate ")
C
cpwu 已提交
494
        tdSql.query(f"select cast(c9 as nchar(2)) as b from {self.dbname}.ct4")
C
cpwu 已提交
495
        for i in range(len(data_ct4_c9)):
C
cpwu 已提交
496 497
            if data_ct4_c9[i] is None:
                tdSql.checkData( i, 0, None)
C
cpwu 已提交
498 499
            elif tdSql.getData(i,0) == data_ct4_c9[i][:2]:
                tdLog.info( f"sql:{tdSql.sql}, row:{i} col:0 data:{tdSql.queryResult[i][0]} == expect:{data_ct4_c9[i][:2]}" )
C
cpwu 已提交
500 501
            else:
                caller = inspect.getframeinfo(inspect.stack()[1][0])
C
cpwu 已提交
502
                tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_ct4_c9[i][:2]}")
C
cpwu 已提交
503
        tdSql.query(f"select cast(c9 as nchar(2)) as b from {self.dbname}.t1")
C
cpwu 已提交
504
        for i in range(len(data_t1_c9)):
C
cpwu 已提交
505 506
            if data_t1_c9[i] is None:
                tdSql.checkData( i, 0, None)
C
cpwu 已提交
507 508
            elif tdSql.getData(i,0) == data_t1_c9[i][:2]:
                tdLog.info( f"sql:{tdSql.sql}, row:{i} col:0 data:{tdSql.queryResult[i][0]} == expect:{data_t1_c9[i][:2]}" )
C
cpwu 已提交
509 510
            else:
                caller = inspect.getframeinfo(inspect.stack()[1][0])
C
cpwu 已提交
511
                tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_t1_c9[i][:2]}")
C
cpwu 已提交
512

C
cpwu 已提交
513
        tdSql.query(f"select c10  from {self.dbname}.ct4")
C
cpwu 已提交
514
        data_ct4_c10 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
C
cpwu 已提交
515
        tdSql.query(f"select c10  from {self.dbname}.t1")
C
cpwu 已提交
516 517 518
        data_t1_c10 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]

        tdLog.printNoPrefix("==========step37: cast timestamp to nchar, expect no changes ")
C
cpwu 已提交
519
        tdSql.query(f"select cast(c10 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
520
        for i in range(len(data_ct4_c10)):
C
cpwu 已提交
521 522 523
            if data_ct4_c10[i] is None:
                tdSql.checkData( i, 0, None )
            else:
X
Xuefeng Tan 已提交
524
                time2str = str(int((data_ct4_c10[i]-datetime.datetime.fromtimestamp(0,data_ct4_c10[i].tzinfo)).total_seconds())*1000+int(data_ct4_c10[i].microsecond / 1000))
C
cpwu 已提交
525
                tdSql.checkData( i, 0, time2str )
C
cpwu 已提交
526
        tdSql.query(f"select cast(c10 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
527
        for i in range(len(data_t1_c10)):
C
cpwu 已提交
528 529
            if data_t1_c10[i] is None:
                tdSql.checkData( i, 0, None )
C
cpwu 已提交
530 531
            elif i == 10:
                continue
C
cpwu 已提交
532
            else:
X
Xuefeng Tan 已提交
533
                time2str = str(int((data_t1_c10[i]-datetime.datetime.fromtimestamp(0,data_t1_c10[i].tzinfo)).total_seconds())*1000+int(data_t1_c10[i].microsecond / 1000))
C
cpwu 已提交
534
                tdSql.checkData( i, 0, time2str )
C
cpwu 已提交
535 536

        tdLog.printNoPrefix("==========step38: cast timestamp to binary, expect no changes ")
C
cpwu 已提交
537
        tdSql.query(f"select cast(c10 as binary(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
538
        for i in range(len(data_ct4_c10)):
C
cpwu 已提交
539 540 541
            if data_ct4_c10[i] is None:
                tdSql.checkData( i, 0, None )
            else:
X
Xuefeng Tan 已提交
542
                time2str = str(int((data_ct4_c10[i]-datetime.datetime.fromtimestamp(0,data_ct4_c10[i].tzinfo)).total_seconds())*1000+int(data_ct4_c10[i].microsecond / 1000))
C
cpwu 已提交
543
                tdSql.checkData( i, 0, time2str )
C
cpwu 已提交
544
        tdSql.query(f"select cast(c10 as binary(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
545
        for i in range(len(data_t1_c10)):
C
cpwu 已提交
546 547
            if data_t1_c10[i] is None:
                tdSql.checkData( i, 0, None )
C
cpwu 已提交
548 549
            elif i == 10:
                continue
C
cpwu 已提交
550
            else:
X
Xuefeng Tan 已提交
551
                time2str = str(int((data_t1_c10[i]-datetime.datetime.fromtimestamp(0,data_t1_c10[i].tzinfo)).total_seconds())*1000+int(data_t1_c10[i].microsecond / 1000))
C
cpwu 已提交
552
                tdSql.checkData( i, 0, time2str )
C
cpwu 已提交
553

C
cpwu 已提交
554
        tdLog.printNoPrefix("==========step39: cast constant operation to bigint, expect change to int ")
C
cpwu 已提交
555
        tdSql.query(f"select cast(12121.23323131  as bigint) as b from {self.dbname}.ct4")
C
cpwu 已提交
556
        ( tdSql.checkData(i, 0, 12121) for i in range(tdSql.queryRows) )
C
cpwu 已提交
557
        tdSql.query(f"select cast(12121.23323131  as binary(16)) as b from {self.dbname}.ct4")
C
cpwu 已提交
558
        ( tdSql.checkData(i, 0, '12121.233231') for i in range(tdSql.queryRows) )
C
cpwu 已提交
559
        tdSql.query(f"select cast(12121.23323131  as binary(2)) as b from {self.dbname}.ct4")
C
cpwu 已提交
560
        ( tdSql.checkData(i, 0, '12') for i in range(tdSql.queryRows) )
C
cpwu 已提交
561
        tdSql.query(f"select cast(12121.23323131  as nchar(16)) as b from {self.dbname}.ct4")
C
cpwu 已提交
562
        ( tdSql.checkData(i, 0, '12121.233231') for i in range(tdSql.queryRows) )
C
cpwu 已提交
563
        tdSql.query(f"select cast(12121.23323131  as nchar(2)) as b from {self.dbname}.ct4")
C
cpwu 已提交
564
        ( tdSql.checkData(i, 0, '12') for i in range(tdSql.queryRows) )
C
cpwu 已提交
565

C
cpwu 已提交
566
        tdSql.query(f"select cast(12121.23323131 + 321.876897998  as bigint) as b from {self.dbname}.ct4")
C
cpwu 已提交
567
        ( tdSql.checkData(i, 0, 12443) for i in range(tdSql.queryRows) )
C
cpwu 已提交
568
        tdSql.query(f"select cast(12121.23323131 + 321.876897998  as binary(16)) as b from {self.dbname}.ct4")
C
cpwu 已提交
569
        ( tdSql.checkData(i, 0, '12443.110129') for i in range(tdSql.queryRows) )
C
cpwu 已提交
570
        tdSql.query(f"select cast(12121.23323131 + 321.876897998  as binary(3)) as b from {self.dbname}.ct4")
C
cpwu 已提交
571
        ( tdSql.checkData(i, 0, '124') for i in range(tdSql.queryRows) )
C
cpwu 已提交
572
        tdSql.query(f"select cast(12121.23323131 + 321.876897998  as nchar(16)) as b from {self.dbname}.ct4")
C
cpwu 已提交
573
        ( tdSql.checkData(i, 0, '12443.110129') for i in range(tdSql.queryRows) )
C
cpwu 已提交
574
        tdSql.query(f"select cast(12121.23323131 + 321.876897998  as nchar(3)) as b from {self.dbname}.ct4")
C
cpwu 已提交
575
        ( tdSql.checkData(i, 0, '124') for i in range(tdSql.queryRows) )
C
cpwu 已提交
576

C
cpwu 已提交
577
        tdSql.query(f"select cast(12121.23323131 + 'test~!@`#$%^&*(){'}'}{'{'}][;><.,' as bigint) as b from {self.dbname}.ct4")
C
cpwu 已提交
578
        ( tdSql.checkData(i, 0, 12121) for i in range(tdSql.queryRows) )
C
cpwu 已提交
579
        tdSql.query(f"select cast(12121.23323131 + 'test~!@`#$%^&*(){'}'}{'{'}][;><.,' as binary(16)) as b from {self.dbname}.ct4")
C
cpwu 已提交
580
        ( tdSql.checkData(i, 0, '12121.233231') for i in range(tdSql.queryRows) )
C
cpwu 已提交
581
        tdSql.query(f"select cast(12121.23323131 + 'test~!@`#$%^&*(){'}'}{'{'}][;><.,' as binary(2)) as b from {self.dbname}.ct4")
C
cpwu 已提交
582
        ( tdSql.checkData(i, 0, '12') for i in range(tdSql.queryRows) )
C
cpwu 已提交
583
        tdSql.query(f"select cast(12121.23323131 + 'test~!@`#$%^&*(){'}'}{'{'}][;><.,' as nchar(16)) as b from {self.dbname}.ct4")
C
cpwu 已提交
584
        ( tdSql.checkData(i, 0, '12121.233231') for i in range(tdSql.queryRows) )
C
cpwu 已提交
585
        tdSql.query(f"select cast(12121.23323131 + 'test~!@`#$%^&*(){'}'}{'{'}][;><.,' as nchar(2)) as b from {self.dbname}.ct4")
C
cpwu 已提交
586
        ( tdSql.checkData(i, 0, '12') for i in range(tdSql.queryRows) )
C
cpwu 已提交
587

C
cpwu 已提交
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
        tdLog.printNoPrefix("==========step40: current cast condition, should return ok ")
        tdSql.query(f"select cast(c1 as int) as b from {self.dbname}.ct4")
        tdSql.query(f"select cast(c1 as bool) as b from {self.dbname}.ct4")
        tdSql.query(f"select cast(c1 as tinyint) as b from {self.dbname}.ct4")
        tdSql.query(f"select cast(c1 as smallint) as b from {self.dbname}.ct4")
        tdSql.query(f"select cast(c1 as float) as b from {self.dbname}.ct4")
        tdSql.query(f"select cast(c1 as double) as b from {self.dbname}.ct4")
        tdSql.query(f"select cast(c1 as tinyint unsigned) as b from {self.dbname}.ct4")
        tdSql.query(f"select cast(c1 as smallint unsigned) as b from {self.dbname}.ct4")
        tdSql.query(f"select cast(c1 as int unsigned) as b from {self.dbname}.ct4")

        tdSql.query(f"select cast(c2 as int) as b from {self.dbname}.ct4")
        tdSql.query(f"select cast(c3 as bool) as b from {self.dbname}.ct4")
        tdSql.query(f"select cast(c4 as tinyint) as b from {self.dbname}.ct4")
        tdSql.query(f"select cast(c5 as smallint) as b from {self.dbname}.ct4")
        tdSql.query(f"select cast(c6 as float) as b from {self.dbname}.ct4")
        tdSql.query(f"select cast(c7 as double) as b from {self.dbname}.ct4")
        tdSql.query(f"select cast(c8 as tinyint unsigned) as b from {self.dbname}.ct4")

        tdSql.query(f"select cast(c8 as timestamp ) as b from {self.dbname}.ct4")
        tdSql.query(f"select cast(c9 as timestamp ) as b from {self.dbname}.ct4")
        tdSql.query(f"select cast(c9 as binary(64) ) as b from {self.dbname}.ct4")
C
cpwu 已提交
610

611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
        # enh of cast function about coverage

        tdSql.query(f"select cast(c1 as int) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c1 as bool) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c1 as tinyint) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c1 as smallint) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c1 as float) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c1 as double) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c1 as tinyint unsigned) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c1 as smallint unsigned) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c1 as int unsigned) as b from {self.dbname}.stb1")

        tdSql.query(f"select cast(c2 as int) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c3 as bool) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c4 as tinyint) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c5 as smallint) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c6 as float) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c7 as double) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c8 as tinyint unsigned) as b from {self.dbname}.stb1")

        tdSql.query(f"select cast(c8 as timestamp ) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c9 as timestamp ) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c9 as binary(64) ) as b from {self.dbname}.stb1")

        tdSql.query(f"select cast(abs(c2) as int) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c3 as bool) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(floor(c4) as tinyint) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c5+2 as smallint) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(2 as float) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c7 as double) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast('123' as tinyint unsigned) as b from {self.dbname}.stb1")

        tdSql.query(f"select max(cast(abs(c2) as int)) as b from {self.dbname}.stb1")
        tdSql.query(f"select log(cast(c3 as int),2) as b from {self.dbname}.stb1")
        tdSql.query(f"select abs(cast(floor(c4) as tinyint)) as b from {self.dbname}.stb1")
        tdSql.query(f"select last(cast(c5+2 as smallint)) as b from {self.dbname}.stb1")
        tdSql.query(f"select mavg(cast(2 as float),3) as b from {self.dbname}.stb1 partition by tbname")
        tdSql.query(f"select cast(c7 as double) as b from {self.dbname}.stb1 partition by tbname order by tbname")
        tdSql.query(f"select cast('123' as tinyint unsigned) as b from {self.dbname}.stb1 partition by tbname")

        # uion with cast and common cols
652

653 654 655 656 657 658 659 660 661 662
        tdSql.query(f"select cast(c2 as int) as b from {self.dbname}.stb1 union all select c1 from {self.dbname}.stb1 ")
        tdSql.query(f"select cast(c3 as bool) as b from {self.dbname}.stb1 union all select c7 from {self.dbname}.ct1 ")
        tdSql.query(f"select cast(c4 as tinyint) as b from {self.dbname}.stb1 union all select c4 from {self.dbname}.stb1")
        tdSql.query(f"select cast(c5 as smallint) as b from {self.dbname}.stb1 union all select cast(c5 as smallint) as b from {self.dbname}.stb1")
        tdSql.query(f"select cast(c6 as float) as b from {self.dbname}.stb1 union all select c5 from {self.dbname}.stb1")
        tdSql.query(f"select cast(c7 as double) as b from {self.dbname}.stb1 union all select 123 from {self.dbname}.stb1 ")
        tdSql.query(f"select cast(c8 as tinyint unsigned) as b from {self.dbname}.stb1 union all select last(cast(c8 as tinyint unsigned)) from {self.dbname}.stb1")



C
cpwu 已提交
663 664 665 666 667
    def run(self):
        tdSql.prepare()

        tdLog.printNoPrefix("==========step1:create table")
        tdSql.execute(
C
cpwu 已提交
668
            f'''create table {self.dbname}.stb1
C
cpwu 已提交
669 670 671 672 673
            (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp)
            tags (t1 int)
            '''
        )
        tdSql.execute(
C
cpwu 已提交
674 675
            f'''
            create table {self.dbname}.t1
C
cpwu 已提交
676 677 678 679
            (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp)
            '''
        )
        for i in range(4):
C
cpwu 已提交
680
            tdSql.execute(f'create table {self.dbname}.ct{i+1} using {self.dbname}.stb1 tags ( {i+1} )')
C
cpwu 已提交
681 682 683 684

        tdLog.printNoPrefix("==========step2:insert data")
        for i in range(9):
            tdSql.execute(
C
cpwu 已提交
685
                f"insert into {self.dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )"
C
cpwu 已提交
686 687
            )
            tdSql.execute(
C
cpwu 已提交
688
                f"insert into {self.dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )"
C
cpwu 已提交
689
            )
C
cpwu 已提交
690 691
        tdSql.execute(f"insert into {self.dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )")
        tdSql.execute(f"insert into {self.dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )")
C
cpwu 已提交
692

C
cpwu 已提交
693 694 695
        tdSql.execute(f"insert into {self.dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
        tdSql.execute(f"insert into {self.dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
        tdSql.execute(f"insert into {self.dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL  ) ")
C
cpwu 已提交
696 697

        tdSql.execute(
C
cpwu 已提交
698
            f'''insert into {self.dbname}.t1 values
C
cpwu 已提交
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
            ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
            ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a )
            ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a )
            ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a )
            ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a )
            ( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
            ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a )
            ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a )
            ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" )
            ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" )
            ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" )
            ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
            '''
        )

        self.all_test()

C
cpwu 已提交
716 717
        # tdDnodes.stop(1)
        # tdDnodes.start(1)
C
cpwu 已提交
718

C
cpwu 已提交
719
        tdSql.execute(f"flush database {self.dbname}")
C
cpwu 已提交
720

C
cpwu 已提交
721
        self.all_test()
C
cpwu 已提交
722 723 724 725 726 727 728

    def stop(self):
        tdSql.close()
        tdLog.success(f"{__file__} successfully executed")

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