line_insert.py 6.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
###################################################################
#           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 *
18
from util.types import TDSmlProtocolType, TDSmlTimestampType
19 20 21 22 23 24


class TDTestCase:
    def init(self, conn, logSql):
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor(), logSql)
25
        self._conn = conn
26 27 28 29 30 31 32 33 34

    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')

        tdSql.execute('create stable ste(ts timestamp, f int) tags(t1 bigint)')

35
        lines = [   "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"\"\"a    pa,\"s   si,t \"\"\",c2=false,c4=4f64 1626006833639000000",
36
                    "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000",
37
                    "ste,t2=5f64,t3=L\"ste\" c1=true,c2=4i64,c3=\" i,\"a \"m,\"\"\" 1626056811823316532",
38 39 40 41 42 43
                    "stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000",
                    "st,t1=4i64,t2=5f64,t3=\"t4\" c1=3i64,c3=L\"passitagain\",c2=true,c4=5f64 1626006833642000000",
                    "ste,t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false 1626056811843316532",
                    "ste,t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false,c5=32i8,c6=64i16,c7=32i32,c8=88.88f32 1626056812843316532",
                    "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000",
                    "stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 1626006933641000000"
44
                ]
45

46
        code = self._conn.schemaless_insert(lines, TDSmlProtocolType.LINE.value, TDSmlTimestampType.NANO_SECOND.value)
47
        print("schemaless_insert result {}".format(code))
48

49 50
        lines2 = [  "stg,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000",
                    "stg,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000"
51
                ]
52

53
        code = self._conn.schemaless_insert([ lines2[0] ], TDSmlProtocolType.LINE.value, TDSmlTimestampType.NANO_SECOND.value)
54
        print("schemaless_insert result {}".format(code))
55

56
        code = self._conn.schemaless_insert([ lines2[1] ], TDSmlProtocolType.LINE.value, TDSmlTimestampType.NANO_SECOND.value)
57
        print("schemaless_insert result {}".format(code))
58

59
        tdSql.query("select * from st")
60 61
        tdSql.checkRows(4)

62
        tdSql.query("select * from ste")
63 64
        tdSql.checkRows(3)

65
        tdSql.query("select * from stf")
66 67
        tdSql.checkRows(2)

68
        tdSql.query("select * from stg")
69 70
        tdSql.checkRows(2)

71
        tdSql.query("show tables")
72 73
        tdSql.checkRows(8)

74
        tdSql.query("describe stf")
75
        tdSql.checkData(2, 2, 14)
76

77
        self._conn.schemaless_insert([
78
                                "sth,t1=4i64,t2=5f64,t4=5f64,ID=childtable c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 1626006933641",
79
                                "sth,t1=4i64,t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 1626006933654"
80
                                ], TDSmlProtocolType.LINE.value, TDSmlTimestampType.MILLI_SECOND.value)
81 82
        tdSql.execute('reset query cache')

83 84 85
        tdSql.query('select tbname, * from sth')
        tdSql.checkRows(2)

G
Ganlin Zhao 已提交
86 87
        #tdSql.query('select tbname, * from childtable')
        #tdSql.checkRows(1)
88 89 90 91 92 93 94 95

        ###Special Character and keyss
        self._conn.schemaless_insert([
                                "1234,id=3456,abc=4i64,def=3i64 123=3i64,int=2i64,bool=false,into=5f64,column=7u64,!@#$.%^&*()=false 1626006933641",
                                "int,id=and,123=4i64,smallint=5f64,double=5f64,of=3i64,key=L\"passitagin_stf\",!@#$.%^&*()=false abc=false 1626006933654",
                                "double,id=for,123=4i64,smallint=5f64,double=5f64,of=3i64,key=L\"passitagin_stf\",!@#$.%^&*()=false abc=false 1626006933664",
                                "from,id=!@#$.%^,123=4i64,smallint=5f64,double=5f64,of=3i64,key=L\"passitagin_stf\",!@#$.%^&*()=false abc=false 1626006933674",
                                "!@#$.%^&*(),id=none,123=4i64,smallint=5f64,double=5f64,of=3i64,key=L\"passitagin_stf\",!@#$.%^&*()=false abc=false 1626006933684",
96
                                "STABLE,id=CREATE,123=4i64,smallint=5f64,DOUBLE=5f64,of=3i64,key=L\"passitagin_stf\",!@#$.%^&*()=false SELECT=false 1626006933684",
97 98 99 100
                                ], TDSmlProtocolType.LINE.value, TDSmlTimestampType.MILLI_SECOND.value)
        tdSql.execute('reset query cache')

        tdSql.query('describe `1234`')
G
Ganlin Zhao 已提交
101
        tdSql.checkRows(10)
102 103

        tdSql.query('describe `int`')
G
Ganlin Zhao 已提交
104
        tdSql.checkRows(9)
105 106

        tdSql.query('describe `double`')
G
Ganlin Zhao 已提交
107
        tdSql.checkRows(9)
108 109

        tdSql.query('describe `from`')
G
Ganlin Zhao 已提交
110
        tdSql.checkRows(9)
111 112

        tdSql.query('describe `!@#$.%^&*()`')
G
Ganlin Zhao 已提交
113
        tdSql.checkRows(9)
114

115
        tdSql.query('describe `stable`')
G
Ganlin Zhao 已提交
116
        tdSql.checkRows(9)
117

G
Ganlin Zhao 已提交
118 119
        #tdSql.query('select * from `3456`')
        #tdSql.checkRows(1)
120

G
Ganlin Zhao 已提交
121 122
        #tdSql.query('select * from `and`')
        #tdSql.checkRows(1)
123

G
Ganlin Zhao 已提交
124 125
        #tdSql.query('select * from `for`')
        #tdSql.checkRows(1)
126

G
Ganlin Zhao 已提交
127 128
        #tdSql.query('select * from `!@#$.%^`')
        #tdSql.checkRows(1)
129

G
Ganlin Zhao 已提交
130 131
        #tdSql.query('select * from `none`')
        #tdSql.checkRows(1)
132

G
Ganlin Zhao 已提交
133 134
        #tdSql.query('select * from `create`')
        #tdSql.checkRows(1)
135 136 137 138 139 140 141
    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)


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