[TD-6560]<test>: Add unit test cases for parsing OpenTSDB HTTP JSON data import format
This commit is contained in:
parent
ca4ffac45a
commit
b27bfa1dce
|
@ -838,8 +838,14 @@ def taos_insert_telnet_lines(connection, lines):
|
||||||
p_lines = lines_type(*lines)
|
p_lines = lines_type(*lines)
|
||||||
errno = _libtaos.taos_insert_telnet_lines(connection, p_lines, num_of_lines)
|
errno = _libtaos.taos_insert_telnet_lines(connection, p_lines, num_of_lines)
|
||||||
if errno != 0:
|
if errno != 0:
|
||||||
raise LinesError("insert telnet lines error", errno)
|
raise TelnetLinesError("insert telnet lines error", errno)
|
||||||
|
|
||||||
|
def taos_insert_json_payload(connection, payload):
|
||||||
|
# type: (c_void_p, list[str] | tuple(str)) -> None
|
||||||
|
payload = payload.encode("utf-8")
|
||||||
|
errno = _libtaos.taos_insert_json_payload(connection, payload)
|
||||||
|
if errno != 0:
|
||||||
|
raise JsonPayloadError("insert json payload error", errno)
|
||||||
|
|
||||||
class CTaosInterface(object):
|
class CTaosInterface(object):
|
||||||
def __init__(self, config=None):
|
def __init__(self, config=None):
|
||||||
|
|
|
@ -154,6 +154,25 @@ class TaosConnection(object):
|
||||||
"""
|
"""
|
||||||
return taos_insert_telnet_lines(self._conn, lines)
|
return taos_insert_telnet_lines(self._conn, lines)
|
||||||
|
|
||||||
|
def insert_json_payload(self, payload):
|
||||||
|
"""OpenTSDB HTTP JSON format support
|
||||||
|
|
||||||
|
## Example
|
||||||
|
"{
|
||||||
|
"metric": "cpu_load_0",
|
||||||
|
"timestamp": 1626006833610123,
|
||||||
|
"value": 55.5,
|
||||||
|
"tags":
|
||||||
|
{
|
||||||
|
"host": "ubuntu",
|
||||||
|
"interface": "eth0",
|
||||||
|
"Id": "tb0"
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
|
||||||
|
"""
|
||||||
|
return taos_insert_json_payload(self._conn, payload)
|
||||||
|
|
||||||
def cursor(self):
|
def cursor(self):
|
||||||
# type: () -> TaosCursor
|
# type: () -> TaosCursor
|
||||||
"""Return a new Cursor object using the connection."""
|
"""Return a new Cursor object using the connection."""
|
||||||
|
|
|
@ -83,4 +83,14 @@ class ResultError(DatabaseError):
|
||||||
class LinesError(DatabaseError):
|
class LinesError(DatabaseError):
|
||||||
"""taos_insert_lines errors."""
|
"""taos_insert_lines errors."""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class TelnetLinesError(DatabaseError):
|
||||||
|
"""taos_insert_telnet_lines errors."""
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
class JsonPayloadError(DatabaseError):
|
||||||
|
"""taos_insert_json_payload errors."""
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
Loading…
Reference in New Issue