cast.py 40.4 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 15 16 17



class TDTestCase:

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

C
cpwu 已提交
20 21 22 23
    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 已提交
24
        for i in range(tdSql.queryRows):
C
cpwu 已提交
25 26 27 28 29 30 31 32 33 34 35
            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 已提交
36
        for i in range(tdSql.queryRows):
C
cpwu 已提交
37 38
            if data_tb_col[i] is None:
                tdSql.checkData( i, 0 , None )
C
cpwu 已提交
39
            if col_name not in ["c2", "double"] or tbname != f"{self.dbname}.t1" or i != 10:
C
cpwu 已提交
40 41 42 43 44 45 46 47 48 49 50 51
                utc_zone = datetime.timezone.utc
                utc_8 = datetime.timezone(datetime.timedelta(hours=8))
                date_init_stamp = datetime.datetime.utcfromtimestamp(data_tb_col[i]/1000)
                date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
                tdSql.checkData( i, 0, date_data)

    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 已提交
52
        __table_list = [f"{self.dbname}.ct1", f"{self.dbname}.ct4", f"{self.dbname}.t1"]
C
cpwu 已提交
53 54 55 56
        __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 已提交
57
        __table_list = [f"{self.dbname}.ct1", f"{self.dbname}.ct4", f"{self.dbname}.t1"]
C
cpwu 已提交
58 59 60
        __col_list = ["c1","c2","c3","c4","c5","c6","c7","c1+c2"]
        self.__range_to_timestamp(cols=__col_list, tables=__table_list)

C
cpwu 已提交
61
    def all_test(self):
C
cpwu 已提交
62

C
cpwu 已提交
63
        tdSql.query(f"select c1  from {self.dbname}.ct4")
C
cpwu 已提交
64
        data_ct4_c1 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
C
cpwu 已提交
65
        tdSql.query(f"select c1  from {self.dbname}.t1")
C
cpwu 已提交
66
        data_t1_c1 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
C
cpwu 已提交
67 68 69

        tdLog.printNoPrefix("==========step2: cast int to bigint, expect no changes")

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

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

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

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

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

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

C
cpwu 已提交
97
        tdSql.query(f"select cast(c1 as timestamp) as b from {self.dbname}.ct4")
C
cpwu 已提交
98 99
        for i in range(len(data_ct4_c1)):
            if data_ct4_c1[i] is None:
C
cpwu 已提交
100 101
                tdSql.checkData( i, 0 , None )
            else:
C
cpwu 已提交
102 103 104 105
                utc_zone = datetime.timezone.utc
                utc_8 = datetime.timezone(datetime.timedelta(hours=8))
                date_init_stamp = datetime.datetime.utcfromtimestamp(data_ct4_c1[i]/1000)
                date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
C
cpwu 已提交
106
                tdSql.checkData( i, 0, date_data)
C
cpwu 已提交
107

C
cpwu 已提交
108
        tdSql.query(f"select cast(c1 as timestamp) as b from {self.dbname}.t1")
C
cpwu 已提交
109 110 111 112 113 114 115 116 117 118 119 120
        for i in range(len(data_t1_c1)):
            if data_ct4_c1[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
                utc_zone = datetime.timezone.utc
                utc_8 = datetime.timezone(datetime.timedelta(hours=8))
                date_init_stamp = datetime.datetime.utcfromtimestamp(data_ct4_c1[i]/1000)
                date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
                tdSql.checkData( i, 0, date_data)


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

C
cpwu 已提交
126
        tdSql.query(f"select cast(c2 as bigint) as b from {self.dbname}.ct4")
C
cpwu 已提交
127 128
        for i in range(len(data_ct4_c2)):
            tdSql.checkData( i, 0, data_ct4_c2[i])
C
cpwu 已提交
129
        tdSql.query(f"select cast(c2 as bigint) as b from {self.dbname}.t1")
C
cpwu 已提交
130 131 132 133 134 135
        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 已提交
136
        tdSql.query(f"select cast(c2 as binary(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 binary(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("==========step10: cast bigint to nchar, expect changes to str(int) ")

C
cpwu 已提交
145
        tdSql.query(f"select cast(c2 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
146 147
        for i in range(len(data_ct4_c2)):
            tdSql.checkData( i, 0, str(data_ct4_c2[i]) )
C
cpwu 已提交
148
        tdSql.query(f"select cast(c2 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
149 150 151 152 153
        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 已提交
154
        tdSql.query(f"select cast(c2 as timestamp) as b from {self.dbname}.ct4")
C
cpwu 已提交
155 156 157 158 159 160 161 162 163 164
        for i in range(len(data_ct4_c2)):
            if data_ct4_c2[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
                utc_zone = datetime.timezone.utc
                utc_8 = datetime.timezone(datetime.timedelta(hours=8))
                date_init_stamp = datetime.datetime.utcfromtimestamp(data_ct4_c2[i]/1000)
                date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
                tdSql.checkData( i, 0, date_data)

C
cpwu 已提交
165

C
cpwu 已提交
166
        tdSql.query(f"select cast(c2 as timestamp) as b from {self.dbname}.t1")
C
cpwu 已提交
167 168 169 170 171 172 173 174 175 176 177
        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:
                utc_zone = datetime.timezone.utc
                utc_8 = datetime.timezone(datetime.timedelta(hours=8))
                date_init_stamp = datetime.datetime.utcfromtimestamp(data_t1_c2[i]/1000)
                date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
                tdSql.checkData( i, 0, date_data)
C
cpwu 已提交
178 179 180


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

C
cpwu 已提交
186
        tdSql.query(f"select cast(c3 as bigint) as b from {self.dbname}.ct4")
C
cpwu 已提交
187 188
        for i in range(len(data_ct4_c3)):
            tdSql.checkData( i, 0, data_ct4_c3[i])
C
cpwu 已提交
189
        tdSql.query(f"select cast(c3 as bigint) as b from {self.dbname}.t1")
C
cpwu 已提交
190 191 192 193 194 195
        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 已提交
196
        tdSql.query(f"select cast(c3 as binary(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
197 198
        for i in range(len(data_ct4_c3)):
            tdSql.checkData( i, 0, str(data_ct4_c3[i]) )
C
cpwu 已提交
199
        tdSql.query(f"select cast(c3 as binary(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
200 201 202 203 204
        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 已提交
205
        tdSql.query(f"select cast(c3 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
206 207
        for i in range(len(data_ct4_c3)):
            tdSql.checkData( i, 0, str(data_ct4_c3[i]) )
C
cpwu 已提交
208
        tdSql.query(f"select cast(c3 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
209 210 211 212 213
        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 已提交
214
        tdSql.query(f"select cast(c3 as timestamp) as b from {self.dbname}.ct4")
C
cpwu 已提交
215 216 217 218 219 220 221 222 223 224
        for i in range(len(data_ct4_c3)):
            if data_ct4_c3[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
                utc_zone = datetime.timezone.utc
                utc_8 = datetime.timezone(datetime.timedelta(hours=8))
                date_init_stamp = datetime.datetime.utcfromtimestamp(data_ct4_c3[i]/1000)
                date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
                tdSql.checkData( i, 0, date_data)

C
cpwu 已提交
225
        tdSql.query(f"select cast(c3 as timestamp) as b from {self.dbname}.t1")
C
cpwu 已提交
226 227 228 229 230 231 232 233 234 235 236
        for i in range(len(data_t1_c3)):
            if data_ct4_c3[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
                utc_zone = datetime.timezone.utc
                utc_8 = datetime.timezone(datetime.timedelta(hours=8))
                date_init_stamp = datetime.datetime.utcfromtimestamp(data_ct4_c3[i]/1000)
                date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
                tdSql.checkData( i, 0, date_data)


C
cpwu 已提交
237
        tdLog.printNoPrefix("==========step16: cast tinyint to bigint, expect no changes")
C
cpwu 已提交
238
        tdSql.query(f"select c4  from {self.dbname}.ct4")
C
cpwu 已提交
239
        data_ct4_c4 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
C
cpwu 已提交
240
        tdSql.query(f"select c4  from {self.dbname}.t1")
C
cpwu 已提交
241 242
        data_t1_c4 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]

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


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

C
cpwu 已提交
253
        tdSql.query(f"select cast(c4 as binary(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
254 255
        for i in range(len(data_ct4_c4)):
            tdSql.checkData( i, 0, str(data_ct4_c4[i]) )
C
cpwu 已提交
256
        tdSql.query(f"select cast(c4 as binary(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
257 258 259
        for i in range(len(data_t1_c4)):
            tdSql.checkData( i, 0, str(data_t1_c4[i]) )

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

C
cpwu 已提交
262
        tdSql.query(f"select cast(c4 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
263 264
        for i in range(len(data_ct4_c4)):
            tdSql.checkData( i, 0, str(data_ct4_c4[i]) )
C
cpwu 已提交
265
        tdSql.query(f"select cast(c4 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
266 267 268
        for i in range(len(data_t1_c4)):
            tdSql.checkData( i, 0, str(data_t1_c4[i]) )

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

C
cpwu 已提交
271
        tdSql.query(f"select cast(c4 as timestamp) as b from {self.dbname}.ct4")
C
cpwu 已提交
272 273 274 275 276 277 278 279 280 281
        for i in range(len(data_ct4_c4)):
            if data_ct4_c4[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
                utc_zone = datetime.timezone.utc
                utc_8 = datetime.timezone(datetime.timedelta(hours=8))
                date_init_stamp = datetime.datetime.utcfromtimestamp(data_ct4_c4[i]/1000)
                date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
                tdSql.checkData( i, 0, date_data)

C
cpwu 已提交
282
        tdSql.query(f"select cast(c4 as timestamp) as b from {self.dbname}.t1")
C
cpwu 已提交
283 284 285 286 287 288 289 290 291 292 293 294
        for i in range(len(data_t1_c4)):
            if data_ct4_c4[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
                utc_zone = datetime.timezone.utc
                utc_8 = datetime.timezone(datetime.timedelta(hours=8))
                date_init_stamp = datetime.datetime.utcfromtimestamp(data_ct4_c4[i]/1000)
                date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
                tdSql.checkData( i, 0, date_data)


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

C
cpwu 已提交
300
        tdSql.query(f"select cast(c5 as bigint) as b from {self.dbname}.ct4")
C
cpwu 已提交
301
        for i in range(len(data_ct4_c5)):
C
cpwu 已提交
302
            tdSql.checkData( i, 0, None ) if data_ct4_c5[i] is None else tdSql.checkData( i, 0, int(data_ct4_c5[i]) )
C
cpwu 已提交
303
        tdSql.query(f"select cast(c5 as bigint) as b from {self.dbname}.t1")
C
cpwu 已提交
304
        for i in range(len(data_t1_c5)):
C
cpwu 已提交
305
            tdSql.checkData( i, 0, None ) if data_t1_c5[i] is None else tdSql.checkData( i, 0, int(data_t1_c5[i]) )
C
cpwu 已提交
306 307

        tdLog.printNoPrefix("==========step21: cast float to binary, expect changes to str(int) ")
C
cpwu 已提交
308
        tdSql.query(f"select cast(c5 as binary(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
309
        for i in range(len(data_ct4_c5)):
C
cpwu 已提交
310
            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 已提交
311
        tdSql.query(f"select cast(c5 as binary(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
312
        for i in range(len(data_t1_c5)):
C
cpwu 已提交
313
            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 已提交
314 315

        tdLog.printNoPrefix("==========step22: cast float to nchar, expect changes to str(int) ")
C
cpwu 已提交
316
        tdSql.query(f"select cast(c5 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
317
        for i in range(len(data_ct4_c5)):
C
cpwu 已提交
318
            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 已提交
319
        tdSql.query(f"select cast(c5 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
320
        for i in range(len(data_t1_c5)):
C
cpwu 已提交
321
            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 已提交
322 323

        tdLog.printNoPrefix("==========step23: cast float to timestamp, expect changes to timestamp ")
C
cpwu 已提交
324
        tdSql.query(f"select cast(c5 as timestamp) as b from {self.dbname}.ct4")
C
cpwu 已提交
325 326 327 328 329 330 331 332 333
        for i in range(len(data_ct4_c5)):
            if data_ct4_c5[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
                utc_zone = datetime.timezone.utc
                utc_8 = datetime.timezone(datetime.timedelta(hours=8))
                date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_ct4_c5[i]/1000))
                date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
                tdSql.checkData( i, 0, date_data)
C
cpwu 已提交
334
        tdSql.query(f"select cast(c5 as timestamp) as b from {self.dbname}.t1")
C
cpwu 已提交
335 336 337 338 339 340 341 342 343 344 345
        for i in range(len(data_t1_c5)):
            if data_t1_c5[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
                utc_zone = datetime.timezone.utc
                utc_8 = datetime.timezone(datetime.timedelta(hours=8))
                date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_t1_c5[i]/1000))
                date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
                tdSql.checkData( i, 0, date_data)

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

C
cpwu 已提交
351
        tdSql.query(f"select cast(c6 as bigint) as b from {self.dbname}.ct4")
C
cpwu 已提交
352
        for i in range(len(data_ct4_c6)):
C
cpwu 已提交
353
            tdSql.checkData( i, 0, None ) if data_ct4_c6[i] is None else tdSql.checkData( i, 0, int(data_ct4_c6[i]) )
C
cpwu 已提交
354
        tdSql.query(f"select cast(c6 as bigint) as b from {self.dbname}.t1")
C
cpwu 已提交
355
        for i in range(len(data_t1_c6)):
C
cpwu 已提交
356 357 358 359 360 361
            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 已提交
362 363

        tdLog.printNoPrefix("==========step25: cast double to binary, expect changes to str(int) ")
C
cpwu 已提交
364
        tdSql.query(f"select cast(c6 as binary(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
365
        for i in range(len(data_ct4_c6)):
C
cpwu 已提交
366
            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 已提交
367
        tdSql.query(f"select cast(c6 as binary(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
368
        for i in range(len(data_t1_c6)):
C
cpwu 已提交
369
            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 已提交
370 371

        tdLog.printNoPrefix("==========step26: cast double to nchar, expect changes to str(int) ")
C
cpwu 已提交
372
        tdSql.query(f"select cast(c6 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
373
        for i in range(len(data_ct4_c6)):
C
cpwu 已提交
374
            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 已提交
375
        tdSql.query(f"select cast(c6 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
376
        for i in range(len(data_t1_c6)):
C
cpwu 已提交
377
            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 已提交
378 379

        tdLog.printNoPrefix("==========step27: cast double to timestamp, expect changes to timestamp ")
C
cpwu 已提交
380
        tdSql.query(f"select cast(c6 as timestamp) as b from {self.dbname}.ct4")
C
cpwu 已提交
381 382 383 384 385 386 387 388 389
        for i in range(len(data_ct4_c6)):
            if data_ct4_c6[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
                utc_zone = datetime.timezone.utc
                utc_8 = datetime.timezone(datetime.timedelta(hours=8))
                date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_ct4_c6[i]/1000))
                date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
                tdSql.checkData( i, 0, date_data)
C
cpwu 已提交
390

C
cpwu 已提交
391
        tdSql.query(f"select cast(c6 as timestamp) as b from {self.dbname}.t1")
C
cpwu 已提交
392 393 394 395 396 397 398 399 400 401 402
        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:
                utc_zone = datetime.timezone.utc
                utc_8 = datetime.timezone(datetime.timedelta(hours=8))
                date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_t1_c6[i]/1000))
                date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
                tdSql.checkData( i, 0, date_data)
C
cpwu 已提交
403 404

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

C
cpwu 已提交
410
        tdSql.query(f"select cast(c7 as bigint) as b from {self.dbname}.ct4")
C
cpwu 已提交
411 412
        for i in range(len(data_ct4_c7)):
            tdSql.checkData( i, 0, data_ct4_c7[i])
C
cpwu 已提交
413
        tdSql.query(f"select cast(c7 as bigint) as b from {self.dbname}.t1")
C
cpwu 已提交
414 415 416 417
        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 已提交
418
        tdSql.query(f"select cast(c7 as binary(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
419
        for i in range(len(data_ct4_c7)):
C
cpwu 已提交
420
            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 已提交
421
        tdSql.query(f"select cast(c7 as binary(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
422
        for i in range(len(data_t1_c7)):
C
cpwu 已提交
423
            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 已提交
424 425

        tdLog.printNoPrefix("==========step30: cast bool to nchar, expect changes to str(int) ")
C
cpwu 已提交
426
        tdSql.query(f"select cast(c7 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
427
        for i in range(len(data_ct4_c7)):
C
cpwu 已提交
428
            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 已提交
429
        tdSql.query(f"select cast(c7 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
430
        for i in range(len(data_t1_c7)):
C
cpwu 已提交
431
            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 已提交
432 433

        tdLog.printNoPrefix("==========step31: cast bool to timestamp, expect changes to timestamp ")
C
cpwu 已提交
434
        tdSql.query(f"select cast(c7 as timestamp) as b from {self.dbname}.ct4")
C
cpwu 已提交
435 436 437 438 439 440 441 442 443
        for i in range(len(data_ct4_c7)):
            if data_ct4_c7[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
                utc_zone = datetime.timezone.utc
                utc_8 = datetime.timezone(datetime.timedelta(hours=8))
                date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_ct4_c7[i]/1000))
                date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
                tdSql.checkData( i, 0, date_data)
C
cpwu 已提交
444
        tdSql.query(f"select cast(c7 as timestamp) as b from {self.dbname}.t1")
C
cpwu 已提交
445 446 447 448 449 450 451 452 453 454 455
        for i in range(len(data_t1_c7)):
            if data_t1_c7[i] is None:
                tdSql.checkData( i, 0 , None )
            else:
                utc_zone = datetime.timezone.utc
                utc_8 = datetime.timezone(datetime.timedelta(hours=8))
                date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_t1_c7[i]/1000))
                date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f")
                tdSql.checkData( i, 0, date_data)


C
cpwu 已提交
456
        tdSql.query(f"select c8  from {self.dbname}.ct4")
C
cpwu 已提交
457
        data_ct4_c8 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
C
cpwu 已提交
458
        tdSql.query(f"select c8  from {self.dbname}.t1")
C
cpwu 已提交
459 460 461
        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 已提交
462
        tdSql.query(f"select cast(c8 as binary(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
463
        for i in range(len(data_ct4_c8)):
C
cpwu 已提交
464
            tdSql.checkData( i, 0, None ) if data_ct4_c8[i] is None else  tdSql.checkData(i,0,data_ct4_c8[i])
C
cpwu 已提交
465

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

C
cpwu 已提交
470
        tdLog.printNoPrefix("==========step33: cast binary to binary, expect truncate ")
C
cpwu 已提交
471
        tdSql.query(f"select cast(c8 as binary(2)) as b from {self.dbname}.ct4")
C
cpwu 已提交
472
        for i in range(len(data_ct4_c8)):
C
cpwu 已提交
473 474
            if data_ct4_c8[i] is None:
                tdSql.checkData( i, 0, None)
C
cpwu 已提交
475 476
            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 已提交
477 478
            else:
                caller = inspect.getframeinfo(inspect.stack()[1][0])
C
cpwu 已提交
479
                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 已提交
480
        tdSql.query(f"select cast(c8 as binary(2)) as b from {self.dbname}.t1")
C
cpwu 已提交
481
        for i in range(len(data_t1_c8)):
C
cpwu 已提交
482 483
            if data_t1_c8[i] is None:
                tdSql.checkData( i, 0, None)
C
cpwu 已提交
484 485
            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 已提交
486 487
            else:
                caller = inspect.getframeinfo(inspect.stack()[1][0])
C
cpwu 已提交
488
                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 已提交
489 490

        tdLog.printNoPrefix("==========step34: cast binary to nchar, expect changes to str(int) ")
C
cpwu 已提交
491
        tdSql.query(f"select cast(c8 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
492
        for i in range(len(data_ct4_c8)):
C
cpwu 已提交
493 494
            if data_ct4_c8[i] is None:
                tdSql.checkData( i, 0, None)
C
cpwu 已提交
495
            elif tdSql.getData(i,0) == data_ct4_c8[i]:
C
cpwu 已提交
496 497 498 499
                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 已提交
500
        tdSql.query(f"select cast(c8 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
501
        for i in range(len(data_t1_c8)):
C
cpwu 已提交
502 503
            if data_t1_c8[i] is None:
                tdSql.checkData( i, 0, None)
C
cpwu 已提交
504
            elif tdSql.getData(i,0) == data_t1_c8[i]:
C
cpwu 已提交
505 506 507 508
                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 已提交
509 510


C
cpwu 已提交
511
        tdSql.query(f"select c9  from {self.dbname}.ct4")
C
cpwu 已提交
512
        data_ct4_c9 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
C
cpwu 已提交
513
        tdSql.query(f"select c9  from {self.dbname}.t1")
C
cpwu 已提交
514 515 516 517
        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 已提交
518
        tdSql.query(f"select cast(c9 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
519
        for i in range(len(data_ct4_c9)):
C
cpwu 已提交
520 521
            if data_ct4_c9[i] is None:
                tdSql.checkData( i, 0, None)
C
cpwu 已提交
522
            elif tdSql.getData(i,0) == data_ct4_c9[i]:
C
cpwu 已提交
523 524 525 526
                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 已提交
527
        tdSql.query(f"select cast(c9 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
528 529
        for i in range(len(data_t1_c9)):
            tdSql.checkData( i, 0, data_t1_c9[i] )
C
cpwu 已提交
530 531
            if data_t1_c9[i] is None:
                tdSql.checkData( i, 0, None)
C
cpwu 已提交
532
            elif tdSql.getData(i,0) == data_t1_c9[i]:
C
cpwu 已提交
533 534 535 536
                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 已提交
537 538

        tdLog.printNoPrefix("==========step36: cast nchar to nchar, expect truncate ")
C
cpwu 已提交
539
        tdSql.query(f"select cast(c9 as nchar(2)) as b from {self.dbname}.ct4")
C
cpwu 已提交
540
        for i in range(len(data_ct4_c9)):
C
cpwu 已提交
541 542
            if data_ct4_c9[i] is None:
                tdSql.checkData( i, 0, None)
C
cpwu 已提交
543 544
            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 已提交
545 546
            else:
                caller = inspect.getframeinfo(inspect.stack()[1][0])
C
cpwu 已提交
547
                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 已提交
548
        tdSql.query(f"select cast(c9 as nchar(2)) as b from {self.dbname}.t1")
C
cpwu 已提交
549
        for i in range(len(data_t1_c9)):
C
cpwu 已提交
550 551
            if data_t1_c9[i] is None:
                tdSql.checkData( i, 0, None)
C
cpwu 已提交
552 553
            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 已提交
554 555
            else:
                caller = inspect.getframeinfo(inspect.stack()[1][0])
C
cpwu 已提交
556
                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 已提交
557

C
cpwu 已提交
558
        tdSql.query(f"select c10  from {self.dbname}.ct4")
C
cpwu 已提交
559
        data_ct4_c10 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)]
C
cpwu 已提交
560
        tdSql.query(f"select c10  from {self.dbname}.t1")
C
cpwu 已提交
561 562 563
        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 已提交
564
        tdSql.query(f"select cast(c10 as nchar(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
565
        for i in range(len(data_ct4_c10)):
C
cpwu 已提交
566 567 568
            if data_ct4_c10[i] is None:
                tdSql.checkData( i, 0, None )
            else:
wafwerar's avatar
wafwerar 已提交
569
                time2str = str(int((data_ct4_c10[i]-datetime.datetime.fromtimestamp(0)).total_seconds()*1000))
C
cpwu 已提交
570
                tdSql.checkData( i, 0, time2str )
C
cpwu 已提交
571
        tdSql.query(f"select cast(c10 as nchar(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
572
        for i in range(len(data_t1_c10)):
C
cpwu 已提交
573 574
            if data_t1_c10[i] is None:
                tdSql.checkData( i, 0, None )
C
cpwu 已提交
575 576
            elif i == 10:
                continue
C
cpwu 已提交
577
            else:
wafwerar's avatar
wafwerar 已提交
578
                time2str = str(int((data_t1_c10[i]-datetime.datetime.fromtimestamp(0)).total_seconds()*1000))
C
cpwu 已提交
579
                tdSql.checkData( i, 0, time2str )
C
cpwu 已提交
580 581

        tdLog.printNoPrefix("==========step38: cast timestamp to binary, expect no changes ")
C
cpwu 已提交
582
        tdSql.query(f"select cast(c10 as binary(32)) as b from {self.dbname}.ct4")
C
cpwu 已提交
583
        for i in range(len(data_ct4_c10)):
C
cpwu 已提交
584 585 586
            if data_ct4_c10[i] is None:
                tdSql.checkData( i, 0, None )
            else:
wafwerar's avatar
wafwerar 已提交
587
                time2str = str(int((data_ct4_c10[i]-datetime.datetime.fromtimestamp(0)).total_seconds()*1000))
C
cpwu 已提交
588
                tdSql.checkData( i, 0, time2str )
C
cpwu 已提交
589
        tdSql.query(f"select cast(c10 as binary(32)) as b from {self.dbname}.t1")
C
cpwu 已提交
590
        for i in range(len(data_t1_c10)):
C
cpwu 已提交
591 592
            if data_t1_c10[i] is None:
                tdSql.checkData( i, 0, None )
C
cpwu 已提交
593 594
            elif i == 10:
                continue
C
cpwu 已提交
595
            else:
wafwerar's avatar
wafwerar 已提交
596
                time2str = str(int((data_t1_c10[i]-datetime.datetime.fromtimestamp(0)).total_seconds()*1000))
C
cpwu 已提交
597
                tdSql.checkData( i, 0, time2str )
C
cpwu 已提交
598

C
cpwu 已提交
599
        tdLog.printNoPrefix("==========step39: cast constant operation to bigint, expect change to int ")
C
cpwu 已提交
600
        tdSql.query(f"select cast(12121.23323131  as bigint) as b from {self.dbname}.ct4")
C
cpwu 已提交
601
        ( tdSql.checkData(i, 0, 12121) for i in range(tdSql.queryRows) )
C
cpwu 已提交
602
        tdSql.query(f"select cast(12121.23323131  as binary(16)) as b from {self.dbname}.ct4")
C
cpwu 已提交
603
        ( tdSql.checkData(i, 0, '12121.233231') for i in range(tdSql.queryRows) )
C
cpwu 已提交
604
        tdSql.query(f"select cast(12121.23323131  as binary(2)) as b from {self.dbname}.ct4")
C
cpwu 已提交
605
        ( tdSql.checkData(i, 0, '12') for i in range(tdSql.queryRows) )
C
cpwu 已提交
606
        tdSql.query(f"select cast(12121.23323131  as nchar(16)) as b from {self.dbname}.ct4")
C
cpwu 已提交
607
        ( tdSql.checkData(i, 0, '12121.233231') for i in range(tdSql.queryRows) )
C
cpwu 已提交
608
        tdSql.query(f"select cast(12121.23323131  as nchar(2)) as b from {self.dbname}.ct4")
C
cpwu 已提交
609
        ( tdSql.checkData(i, 0, '12') for i in range(tdSql.queryRows) )
C
cpwu 已提交
610

C
cpwu 已提交
611
        tdSql.query(f"select cast(12121.23323131 + 321.876897998  as bigint) as b from {self.dbname}.ct4")
C
cpwu 已提交
612
        ( tdSql.checkData(i, 0, 12443) for i in range(tdSql.queryRows) )
C
cpwu 已提交
613
        tdSql.query(f"select cast(12121.23323131 + 321.876897998  as binary(16)) as b from {self.dbname}.ct4")
C
cpwu 已提交
614
        ( tdSql.checkData(i, 0, '12443.110129') for i in range(tdSql.queryRows) )
C
cpwu 已提交
615
        tdSql.query(f"select cast(12121.23323131 + 321.876897998  as binary(3)) as b from {self.dbname}.ct4")
C
cpwu 已提交
616
        ( tdSql.checkData(i, 0, '124') for i in range(tdSql.queryRows) )
C
cpwu 已提交
617
        tdSql.query(f"select cast(12121.23323131 + 321.876897998  as nchar(16)) as b from {self.dbname}.ct4")
C
cpwu 已提交
618
        ( tdSql.checkData(i, 0, '12443.110129') for i in range(tdSql.queryRows) )
C
cpwu 已提交
619
        tdSql.query(f"select cast(12121.23323131 + 321.876897998  as nchar(3)) as b from {self.dbname}.ct4")
C
cpwu 已提交
620
        ( tdSql.checkData(i, 0, '124') for i in range(tdSql.queryRows) )
C
cpwu 已提交
621

C
cpwu 已提交
622
        tdSql.query(f"select cast(12121.23323131 + 'test~!@`#$%^&*(){'}'}{'{'}][;><.,' as bigint) as b from {self.dbname}.ct4")
C
cpwu 已提交
623
        ( tdSql.checkData(i, 0, 12121) for i in range(tdSql.queryRows) )
C
cpwu 已提交
624
        tdSql.query(f"select cast(12121.23323131 + 'test~!@`#$%^&*(){'}'}{'{'}][;><.,' as binary(16)) as b from {self.dbname}.ct4")
C
cpwu 已提交
625
        ( tdSql.checkData(i, 0, '12121.233231') for i in range(tdSql.queryRows) )
C
cpwu 已提交
626
        tdSql.query(f"select cast(12121.23323131 + 'test~!@`#$%^&*(){'}'}{'{'}][;><.,' as binary(2)) as b from {self.dbname}.ct4")
C
cpwu 已提交
627
        ( tdSql.checkData(i, 0, '12') for i in range(tdSql.queryRows) )
C
cpwu 已提交
628
        tdSql.query(f"select cast(12121.23323131 + 'test~!@`#$%^&*(){'}'}{'{'}][;><.,' as nchar(16)) as b from {self.dbname}.ct4")
C
cpwu 已提交
629
        ( tdSql.checkData(i, 0, '12121.233231') for i in range(tdSql.queryRows) )
C
cpwu 已提交
630
        tdSql.query(f"select cast(12121.23323131 + 'test~!@`#$%^&*(){'}'}{'{'}][;><.,' as nchar(2)) as b from {self.dbname}.ct4")
C
cpwu 已提交
631
        ( tdSql.checkData(i, 0, '12') for i in range(tdSql.queryRows) )
C
cpwu 已提交
632

C
cpwu 已提交
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
        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 已提交
655 656 657 658 659 660

    def run(self):
        tdSql.prepare()

        tdLog.printNoPrefix("==========step1:create table")
        tdSql.execute(
C
cpwu 已提交
661
            f'''create table {self.dbname}.stb1
C
cpwu 已提交
662 663 664 665 666
            (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 已提交
667 668
            f'''
            create table {self.dbname}.t1
C
cpwu 已提交
669 670 671 672
            (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 已提交
673
            tdSql.execute(f'create table {self.dbname}.ct{i+1} using {self.dbname}.stb1 tags ( {i+1} )')
C
cpwu 已提交
674 675 676 677

        tdLog.printNoPrefix("==========step2:insert data")
        for i in range(9):
            tdSql.execute(
C
cpwu 已提交
678
                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 已提交
679 680
            )
            tdSql.execute(
C
cpwu 已提交
681
                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 已提交
682
            )
C
cpwu 已提交
683 684
        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 已提交
685

C
cpwu 已提交
686 687 688
        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 已提交
689 690

        tdSql.execute(
C
cpwu 已提交
691
            f'''insert into {self.dbname}.t1 values
C
cpwu 已提交
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
            ( '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 已提交
709 710
        # tdDnodes.stop(1)
        # tdDnodes.start(1)
C
cpwu 已提交
711

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

C
cpwu 已提交
714
        self.all_test()
C
cpwu 已提交
715 716 717 718 719 720 721

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

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