From 2aee93f46bd7afc34e91176279df2adbfe15dd70 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 2 Sep 2021 11:49:51 +0800 Subject: [PATCH] [TD-6506]: Add unit test cases for parsing OpenTSDB telnet style data import format --- src/connector/python/taos/cinterface.py | 10 ++++++++++ src/connector/python/taos/connection.py | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/src/connector/python/taos/cinterface.py b/src/connector/python/taos/cinterface.py index 42dac3c2e8..fadef7c397 100644 --- a/src/connector/python/taos/cinterface.py +++ b/src/connector/python/taos/cinterface.py @@ -830,6 +830,16 @@ def taos_insert_lines(connection, lines): if errno != 0: raise LinesError("insert lines error", errno) +def taos_insert_telnet_lines(connection, lines): + # type: (c_void_p, list[str] | tuple(str)) -> None + num_of_lines = len(lines) + lines = (c_char_p(line.encode("utf-8")) for line in lines) + lines_type = ctypes.c_char_p * num_of_lines + p_lines = lines_type(*lines) + errno = _libtaos.taos_insert_telnet_lines(connection, p_lines, num_of_lines) + if errno != 0: + raise LinesError("insert telnet lines error", errno) + class CTaosInterface(object): def __init__(self, config=None): diff --git a/src/connector/python/taos/connection.py b/src/connector/python/taos/connection.py index 7857c8c706..a8a71ecc3a 100644 --- a/src/connector/python/taos/connection.py +++ b/src/connector/python/taos/connection.py @@ -145,6 +145,15 @@ class TaosConnection(object): """ return taos_insert_lines(self._conn, lines) + def insert_telnet_lines(self, lines): + """OpenTSDB telnet style API format support + + ## Example + cpu_load 1626056811855516532ns 2.0f32 id="tb1",host="host0",interface="eth0" + + """ + return taos_insert_telnet_lines(self._conn, lines) + def cursor(self): # type: () -> TaosCursor """Return a new Cursor object using the connection.""" -- GitLab