[TD-4647]<feature>: auto add column through schemaless line protocol
This commit is contained in:
parent
3a2ace484c
commit
1148a133b5
|
@ -403,6 +403,20 @@ class CTaosInterface(object):
|
||||||
"""
|
"""
|
||||||
return CTaosInterface.libtaos.taos_affected_rows(result)
|
return CTaosInterface.libtaos.taos_affected_rows(result)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def insertLines(connection, lines):
|
||||||
|
'''
|
||||||
|
insert through lines protocol
|
||||||
|
@lines: list of str
|
||||||
|
@rtype: tsdb error codes
|
||||||
|
'''
|
||||||
|
numLines = len(lines)
|
||||||
|
c_lines_type = ctypes.c_char_p*numLines
|
||||||
|
c_lines = c_lines_type()
|
||||||
|
for i in range(numLines):
|
||||||
|
c_lines[i] = ctypes.c_char_p(lines[i].encode('utf-8'))
|
||||||
|
return CTaosInterface.libtaos.taos_insert_lines(connection, c_lines, ctypes.c_int(numLines))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def subscribe(connection, restart, topic, sql, interval):
|
def subscribe(connection, restart, topic, sql, interval):
|
||||||
"""Create a subscription
|
"""Create a subscription
|
||||||
|
|
|
@ -66,6 +66,14 @@ class TDengineConnection(object):
|
||||||
self._conn, restart, topic, sql, interval)
|
self._conn, restart, topic, sql, interval)
|
||||||
return TDengineSubscription(sub)
|
return TDengineSubscription(sub)
|
||||||
|
|
||||||
|
def insertLines(self, lines):
|
||||||
|
"""
|
||||||
|
insert lines through line protocol
|
||||||
|
"""
|
||||||
|
if self._conn is None:
|
||||||
|
return None
|
||||||
|
return CTaosInterface.insertLines(self._conn, lines)
|
||||||
|
|
||||||
def cursor(self):
|
def cursor(self):
|
||||||
"""Return a new Cursor object using the connection.
|
"""Return a new Cursor object using the connection.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -975,9 +975,14 @@ int32_t verify_schema_less(TAOS* taos) {
|
||||||
"stf,t1=4i,t3=\"t4\",t2=5,t4=5 c1=3i,c3=L\"passitagin_stf\",c2=false,c5=5,c6=7u 1626006933641a"
|
"stf,t1=4i,t3=\"t4\",t2=5,t4=5 c1=3i,c3=L\"passitagin_stf\",c2=false,c5=5,c6=7u 1626006933641a"
|
||||||
};
|
};
|
||||||
|
|
||||||
// int code = taos_insert_lines(taos, lines , sizeof(lines)/sizeof(char*));
|
int code = 0;
|
||||||
int code = taos_insert_lines(taos, &lines[0], 1);
|
code = taos_insert_lines(taos, lines , sizeof(lines)/sizeof(char*));
|
||||||
code = taos_insert_lines(taos, &lines[1], 1);
|
char* lines2[] = {
|
||||||
|
"stg,t1=3i,t2=4,t3=\"t3\" c1=3i,c3=L\"passit\",c2=false,c4=4 1626006833639000000",
|
||||||
|
"stg,t1=4i,t3=\"t4\",t2=5,t4=5 c1=3i,c3=L\"passitagin\",c2=true,c4=5,c5=5 1626006833640000000"
|
||||||
|
};
|
||||||
|
code = taos_insert_lines(taos, &lines2[0], 1);
|
||||||
|
code = taos_insert_lines(taos, &lines2[1], 1);
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -1000,10 +1005,7 @@ int main(int argc, char *argv[]) {
|
||||||
printf("client info: %s\n", info);
|
printf("client info: %s\n", info);
|
||||||
|
|
||||||
printf("************ verify shemaless *************\n");
|
printf("************ verify shemaless *************\n");
|
||||||
int code = verify_schema_less(taos);
|
verify_schema_less(taos);
|
||||||
if (code == 0) {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("************ verify query *************\n");
|
printf("************ verify query *************\n");
|
||||||
verify_query(taos);
|
verify_query(taos);
|
||||||
|
|
|
@ -27,6 +27,7 @@ python3 ./test.py -f insert/bug3654.py
|
||||||
python3 ./test.py -f insert/insertDynamicColBeforeVal.py
|
python3 ./test.py -f insert/insertDynamicColBeforeVal.py
|
||||||
python3 ./test.py -f insert/in_function.py
|
python3 ./test.py -f insert/in_function.py
|
||||||
python3 ./test.py -f insert/modify_column.py
|
python3 ./test.py -f insert/modify_column.py
|
||||||
|
python3 ./test.py -f insert/line_insert.py
|
||||||
|
|
||||||
#table
|
#table
|
||||||
python3 ./test.py -f table/alter_wal0.py
|
python3 ./test.py -f table/alter_wal0.py
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
###################################################################
|
||||||
|
# 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')
|
||||||
|
|
||||||
|
tdSql.execute('create stable ste(ts timestamp, f int) tags(t1 bigint)')
|
||||||
|
|
||||||
|
lines = [
|
||||||
|
"st,t1=3i,t2=4,t3=\"t3\" c1=3i,c3=L\"passit\",c2=false,c4=4 1626006833639000000",
|
||||||
|
"st,t1=4i,t3=\"t4\",t2=5,t4=5 c1=3i,c3=L\"passitagin\",c2=true,c4=5,c5=5 1626006833640000000",
|
||||||
|
"ste,t2=5,t3=L\"ste\" c1=true,c2=4,c3=\"iam\" 1626056811823316532",
|
||||||
|
"st,t1=4i,t2=5,t3=\"t4\" c1=3i,c3=L\"passitagain\",c2=true,c4=5 1626006833642000000",
|
||||||
|
"ste,t2=5,t3=L\"ste2\" c3=\"iamszhou\",c4=false 1626056811843316532",
|
||||||
|
"ste,t2=5,t3=L\"ste2\" c3=\"iamszhou\",c4=false,c5=32b,c6=64s,c7=32w,c8=88.88f 1626056812843316532",
|
||||||
|
"st,t1=4i,t3=\"t4\",t2=5,t4=5 c1=3i,c3=L\"passitagin\",c2=true,c4=5,c5=5,c6=7u 1626006933640000000",
|
||||||
|
"stf,t1=4i,t3=\"t4\",t2=5,t4=5 c1=3i,c3=L\"passitagin\",c2=true,c4=5,c5=5,c6=7u 1626006933640000000",
|
||||||
|
"stf,t1=4i,t3=\"t4\",t2=5,t4=5 c1=3i,c3=L\"passitagin_stf\",c2=false,c5=5,c6=7u 1626006933641a"]
|
||||||
|
|
||||||
|
code = self._conn.insertLines(lines)
|
||||||
|
print("insertLines result {}".format(code))
|
||||||
|
|
||||||
|
lines2 = [
|
||||||
|
"stg,t1=3i,t2=4,t3=\"t3\" c1=3i,c3=L\"passit\",c2=false,c4=4 1626006833639000000",
|
||||||
|
"stg,t1=4i,t3=\"t4\",t2=5,t4=5 c1=3i,c3=L\"passitagin\",c2=true,c4=5,c5=5 1626006833640000000"]
|
||||||
|
|
||||||
|
code = self._conn.insertLines([ lines2[0] ])
|
||||||
|
print("insertLines result {}".format(code))
|
||||||
|
|
||||||
|
self._conn.insertLines([ lines2[1] ])
|
||||||
|
print("insertLines result {}".format(code))
|
||||||
|
|
||||||
|
tdSql.query("select * from st");
|
||||||
|
tdSql.checkRows(4)
|
||||||
|
|
||||||
|
tdSql.query("select * from ste");
|
||||||
|
tdSql.checkRows(3)
|
||||||
|
|
||||||
|
tdSql.query("select * from stf");
|
||||||
|
tdSql.checkRows(2)
|
||||||
|
|
||||||
|
tdSql.query("select * from stg");
|
||||||
|
tdSql.checkRows(2)
|
||||||
|
|
||||||
|
tdSql.query("show tables");
|
||||||
|
tdSql.checkRows(8)
|
||||||
|
|
||||||
|
tdSql.query("describe stf");
|
||||||
|
tdSql.checkData(3,2, 14)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
tdSql.close()
|
||||||
|
tdLog.success("%s successfully executed" % __file__)
|
||||||
|
|
||||||
|
|
||||||
|
tdCases.addWindows(__file__, TDTestCase())
|
||||||
|
tdCases.addLinux(__file__, TDTestCase())
|
|
@ -105,6 +105,7 @@ run general/parser/import_commit2.sim
|
||||||
run general/parser/import_commit3.sim
|
run general/parser/import_commit3.sim
|
||||||
run general/parser/insert_tb.sim
|
run general/parser/insert_tb.sim
|
||||||
run general/parser/first_last.sim
|
run general/parser/first_last.sim
|
||||||
|
run general/parser/line_insert.sim
|
||||||
#unsupport run general/parser/import_file.sim
|
#unsupport run general/parser/import_file.sim
|
||||||
run general/parser/lastrow.sim
|
run general/parser/lastrow.sim
|
||||||
run general/parser/nchar.sim
|
run general/parser/nchar.sim
|
||||||
|
|
Loading…
Reference in New Issue