insertTelnetLines.py 11.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
###################################################################
#           Copyright (c) 2021 by TAOS Technologies, Inc.
#                     All rights reserved.
#
#  This file is proprietary and confidential to TAOS Technologies.
#  No part of this file may be reproduced, stored, transmitted,
#  disclosed or used in any form or by any means other than as
#  expressly provided by the written permission from Jianhui Tao
#
###################################################################

# -*- coding: utf-8 -*-

import sys
from util.log import *
from util.cases import *
from util.sql import *


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

    def run(self):
        print("running {}".format(__file__))
        tdSql.execute("drop database if exists test")
        tdSql.execute("create database if not exists test precision 'us'")
        tdSql.execute('use test')

        ### metric ###
        print("============= step1 : test metric  ================")
        lines0 = [
35 36 37
                        "stb0_0 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"",
                        "stb0_1 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"",
                        "stb0_2 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"",
38
                        "`.stb0.3.` 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"",
39 40
                   ]

41
        code = self._conn.schemaless_insert(lines0, 1, None)
42
        print("schemaless_insert result {}".format(code))
43 44

        tdSql.query("show stables")
45
        tdSql.checkRows(4)
46 47 48 49 50 51 52 53 54 55

        tdSql.query("describe stb0_0")
        tdSql.checkRows(4)

        tdSql.query("describe stb0_1")
        tdSql.checkRows(4)

        tdSql.query("describe stb0_2")
        tdSql.checkRows(4)

56
        tdSql.query("describe `.stb0.3.`")
57 58
        tdSql.checkRows(4)

59 60 61 62 63 64
        ### timestamp ###
        print("============= step2 : test timestamp  ================")
        lines1 = [
                      "stb1 1626006833s 1i8 host=\"host0\"",
                      "stb1 1626006833639000000ns 2i8 host=\"host0\"",
                      "stb1 1626006833640000us 3i8 host=\"host0\"",
65 66 67 68
                      "stb1 1626006833641 4i8 host=\"host0\"",
                      "stb1 1626006834 5i8 host=\"host0\"",
                      "stb1 1626006833651ms 6i8 host=\"host0\"",
                      "stb1 0 7i8 host=\"host0\"",
69 70
                    ]

71
        code = self._conn.schemaless_insert(lines1, 1, None)
72
        print("schemaless_insert result {}".format(code))
73 74

        tdSql.query("select * from stb1")
75
        tdSql.checkRows(7)
76 77 78 79 80 81 82 83 84

        ### metric value ###
        print("============= step3 : test metric value  ================")

        #tinyint
        lines2_0 = [
                        "stb2_0 1626006833651ms -127i8 host=\"host0\"",
                        "stb2_0 1626006833652ms 127i8 host=\"host0\""
                     ]
85
        code = self._conn.schemaless_insert(lines2_0, 1, None)
86
        print("schemaless_insert result {}".format(code))
87 88 89 90 91 92 93 94 95 96 97 98 99

        tdSql.query("select * from stb2_0")
        tdSql.checkRows(2)

        tdSql.query("describe stb2_0")
        tdSql.checkRows(3)
        tdSql.checkData(1, 1, "TINYINT")

        #smallint
        lines2_1 = [
                        "stb2_1 1626006833651ms -32767i16 host=\"host0\"",
                        "stb2_1 1626006833652ms 32767i16 host=\"host0\""
                     ]
100
        code = self._conn.schemaless_insert(lines2_1, 1, None)
101
        print("schemaless_insert result {}".format(code))
102 103 104 105 106 107 108 109 110 111 112 113 114 115

        tdSql.query("select * from stb2_1")
        tdSql.checkRows(2)

        tdSql.query("describe stb2_1")
        tdSql.checkRows(3)
        tdSql.checkData(1, 1, "SMALLINT")

        #int
        lines2_2 = [
                        "stb2_2 1626006833651ms -2147483647i32 host=\"host0\"",
                        "stb2_2 1626006833652ms 2147483647i32 host=\"host0\""
                     ]

116
        code = self._conn.schemaless_insert(lines2_2, 1, None)
117
        print("schemaless_insert result {}".format(code))
118 119 120 121 122 123 124 125 126 127 128

        tdSql.query("select * from stb2_2")
        tdSql.checkRows(2)

        tdSql.query("describe stb2_2")
        tdSql.checkRows(3)
        tdSql.checkData(1, 1, "INT")

        #bigint
        lines2_3 = [
                        "stb2_3 1626006833651ms -9223372036854775807i64 host=\"host0\"",
129
                        "stb2_3 1626006833652ms 9223372036854775807i64 host=\"host0\""
130 131
                     ]

132
        code = self._conn.schemaless_insert(lines2_3, 1, None)
133
        print("schemaless_insert result {}".format(code))
134 135

        tdSql.query("select * from stb2_3")
136
        tdSql.checkRows(2)
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155

        tdSql.query("describe stb2_3")
        tdSql.checkRows(3)
        tdSql.checkData(1, 1, "BIGINT")

        #float
        lines2_4 = [
                        "stb2_4 1626006833610ms 3f32 host=\"host0\"",
                        "stb2_4 1626006833620ms -3f32 host=\"host0\"",
                        "stb2_4 1626006833630ms 3.4f32 host=\"host0\"",
                        "stb2_4 1626006833640ms -3.4f32 host=\"host0\"",
                        "stb2_4 1626006833650ms 3.4E10f32 host=\"host0\"",
                        "stb2_4 1626006833660ms -3.4e10f32 host=\"host0\"",
                        "stb2_4 1626006833670ms 3.4E+2f32 host=\"host0\"",
                        "stb2_4 1626006833680ms -3.4e-2f32 host=\"host0\"",
                        "stb2_4 1626006833700ms 3.4E38f32 host=\"host0\"",
                        "stb2_4 1626006833710ms -3.4E38f32 host=\"host0\""
                     ]

156
        code = self._conn.schemaless_insert(lines2_4, 1, None)
157
        print("schemaless_insert result {}".format(code))
158 159

        tdSql.query("select * from stb2_4")
160
        tdSql.checkRows(10)
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176

        tdSql.query("describe stb2_4")
        tdSql.checkRows(3)
        tdSql.checkData(1, 1, "FLOAT")

        #double
        lines2_5 = [
                        "stb2_5 1626006833610ms 3f64 host=\"host0\"",
                        "stb2_5 1626006833620ms -3f64 host=\"host0\"",
                        "stb2_5 1626006833630ms 3.4f64 host=\"host0\"",
                        "stb2_5 1626006833640ms -3.4f64 host=\"host0\"",
                        "stb2_5 1626006833650ms 3.4E10f64 host=\"host0\"",
                        "stb2_5 1626006833660ms -3.4e10f64 host=\"host0\"",
                        "stb2_5 1626006833670ms 3.4E+2f64 host=\"host0\"",
                        "stb2_5 1626006833680ms -3.4e-2f64 host=\"host0\"",
                        "stb2_5 1626006833690ms 1.7E308f64 host=\"host0\"",
177
                        "stb2_5 1626006833700ms -1.7E308f64 host=\"host0\"",
178
                        "stb2_5 1626006833710ms 3 host=\"host0\""
179 180
                     ]

181
        code = self._conn.schemaless_insert(lines2_5, 1, None)
182
        print("schemaless_insert result {}".format(code))
183 184

        tdSql.query("select * from stb2_5")
185
        tdSql.checkRows(11)
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204

        tdSql.query("describe stb2_5")
        tdSql.checkRows(3)
        tdSql.checkData(1, 1, "DOUBLE")

        #bool
        lines2_6 = [
                        "stb2_6 1626006833610ms t host=\"host0\"",
                        "stb2_6 1626006833620ms T host=\"host0\"",
                        "stb2_6 1626006833630ms true host=\"host0\"",
                        "stb2_6 1626006833640ms True host=\"host0\"",
                        "stb2_6 1626006833650ms TRUE host=\"host0\"",
                        "stb2_6 1626006833660ms f host=\"host0\"",
                        "stb2_6 1626006833670ms F host=\"host0\"",
                        "stb2_6 1626006833680ms false host=\"host0\"",
                        "stb2_6 1626006833690ms False host=\"host0\"",
                        "stb2_6 1626006833700ms FALSE host=\"host0\""
                     ]

205
        code = self._conn.schemaless_insert(lines2_6, 1, None)
206
        print("schemaless_insert result {}".format(code))
207 208 209 210 211 212 213 214 215 216

        tdSql.query("select * from stb2_6")
        tdSql.checkRows(10)

        tdSql.query("describe stb2_6")
        tdSql.checkRows(3)
        tdSql.checkData(1, 1, "BOOL")

        #binary
        lines2_7 = [
G
Ganlin Zhao 已提交
217
                        "stb2_7 1626006833610ms \"  binary_val  .!@#$%^&*  \" host=\"host0\"",
218 219 220 221
                        "stb2_7 1626006833620ms \"binary_val.:;,./?|+-=\" host=\"host0\"",
                        "stb2_7 1626006833630ms \"binary_val.()[]{}<>\" host=\"host0\""
                     ]

222
        code = self._conn.schemaless_insert(lines2_7, 1, None)
223
        print("schemaless_insert result {}".format(code))
224 225 226 227 228 229 230 231 232 233

        tdSql.query("select * from stb2_7")
        tdSql.checkRows(3)

        tdSql.query("describe stb2_7")
        tdSql.checkRows(3)
        tdSql.checkData(1, 1, "BINARY")

        #nchar
        lines2_8 = [
G
Ganlin Zhao 已提交
234
                        "stb2_8 1626006833610ms L\"  nchar_val  数值一  \" host=\"host0\"",
235 236 237
                        "stb2_8 1626006833620ms L\"nchar_val数值二\" host=\"host0\""
                     ]

238
        code = self._conn.schemaless_insert(lines2_8, 1, None)
239
        print("schemaless_insert result {}".format(code))
240 241 242 243 244 245 246 247 248 249 250 251

        tdSql.query("select * from stb2_8")
        tdSql.checkRows(2)

        tdSql.query("describe stb2_8")
        tdSql.checkRows(3)
        tdSql.checkData(1, 1, "NCHAR")

        ### tags ###
        print("============= step3 : test tags  ================")
        #tag value types
        lines3_0 = [
252 253
                        "stb3_0 1626006833610ms 1 t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=3.4E38f32 t6=1.7E308f64 t7=true t8=\"binary_val_1\" t9=L\"标签值1\"",
                        "stb3_0 1626006833610ms 2 t1=-127i8 t2=-32767i16 t3=-2147483647i32 t4=-9223372036854775807i64 t5=-3.4E38f32 t6=-1.7E308f64 t7=false t8=\"binary_val_2\" t9=L\"标签值2\""
254 255
                     ]

256
        code = self._conn.schemaless_insert(lines3_0, 1, None)
257
        print("schemaless_insert result {}".format(code))
258 259 260 261 262 263 264

        tdSql.query("select * from stb3_0")
        tdSql.checkRows(2)

        tdSql.query("describe stb3_0")
        tdSql.checkRows(11)

265
        tdSql.checkData(2, 1, "NCHAR")
266 267
        tdSql.checkData(2, 3, "TAG")

268
        tdSql.checkData(3, 1, "NCHAR")
269 270
        tdSql.checkData(3, 3, "TAG")

271
        tdSql.checkData(4, 1, "NCHAR")
272 273
        tdSql.checkData(4, 3, "TAG")

274
        tdSql.checkData(5, 1, "NCHAR")
275 276
        tdSql.checkData(5, 3, "TAG")

277
        tdSql.checkData(6, 1, "NCHAR")
278 279
        tdSql.checkData(6, 3, "TAG")

280
        tdSql.checkData(7, 1, "NCHAR")
281 282
        tdSql.checkData(7, 3, "TAG")

283
        tdSql.checkData(8, 1, "NCHAR")
284 285
        tdSql.checkData(8, 3, "TAG")

286
        tdSql.checkData(9, 1, "NCHAR")
287 288 289 290 291 292 293 294
        tdSql.checkData(9, 3, "TAG")

        tdSql.checkData(10, 1, "NCHAR")
        tdSql.checkData(10, 3, "TAG")


        #tag ID as child table name
        lines3_1 = [
295 296 297
                        "stb3_1 1626006833610ms 1 id=child_table1 host=host1",
                        "stb3_1 1626006833610ms 2 host=host2 iD=child_table2",
                        "stb3_1 1626006833610ms 3 ID=child_table3 host=host3"
298 299
                     ]

300
        code = self._conn.schemaless_insert(lines3_1, 1, None)
301
        print("schemaless_insert result {}".format(code))
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317

        tdSql.query("select * from stb3_1")
        tdSql.checkRows(3)

        tdSql.query("show tables like \"child%\"")
        tdSql.checkRows(3)

        tdSql.checkData(0, 0, "child_table1")

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


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