From 32ee9bf74f65330e83afe033a459bbd40d53f924 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 29 Sep 2021 11:31:57 +0800 Subject: [PATCH] [TD-10445]: change API name from taos_insert_lines to taos_schemaless_insert --- src/client/src/TSDBJNIConnector.c | 3 +- src/client/src/tscParseLineProtocol.c | 10 +++--- src/client/src/tscParseOpenTSDB.c | 12 +++---- src/connector/python/README.md | 4 +-- src/connector/python/examples/insert-lines.py | 4 +-- src/connector/python/taos/__init__.py | 4 +-- src/connector/python/taos/connection.py | 31 +++++++++++-------- src/connector/python/tests/test_lines.py | 4 +-- 8 files changed, 39 insertions(+), 33 deletions(-) diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index deaadce73f..4828b52853 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -17,6 +17,7 @@ #include "taos.h" #include "tlog.h" #include "tscUtil.h" +#include "tscParseLine.h" #include "com_taosdata_jdbc_TSDBJNIConnector.h" @@ -1070,7 +1071,7 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_insertLinesImp(J c_lines[i] = (char *)(*env)->GetStringUTFChars(env, line, 0); } - int code = taos_schemaless_insert(taos, c_lines, numLines, 0); + int code = taos_schemaless_insert(taos, c_lines, numLines, SML_LINE_PROTOCOL); for (int i = 0; i < numLines; ++i) { jstring line = (jstring)((*env)->GetObjectArrayElement(env, lines, i)); diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index 9d3fc829d5..4c5f1441b7 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -1811,8 +1811,8 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; } while (*cur != '\0') { - if (len > TSDB_COL_NAME_LEN - 1) { - tscError("SML:0x%"PRIx64" Key field cannot exceeds 64 characters", info->id); + if (len >= TSDB_COL_NAME_LEN - 1) { + tscError("SML:0x%"PRIx64" Key field cannot exceeds %d characters", info->id, TSDB_COL_NAME_LEN - 1); return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH; } //unescaped '=' identifies a tag key @@ -1898,8 +1898,8 @@ static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index } while (*cur != '\0') { - if (len > TSDB_TABLE_NAME_LEN - 1) { - tscError("SML:0x%"PRIx64" Measurement field cannot exceeds 192 characters", info->id); + if (len >= TSDB_TABLE_NAME_LEN - 1) { + tscError("SML:0x%"PRIx64" Measurement field cannot exceeds %d characters", info->id, TSDB_TABLE_NAME_LEN - 1); free(pSml->stableName); pSml->stableName = NULL; return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; @@ -1931,7 +1931,7 @@ static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index //Table name can only contain digits(0-9),alphebet(a-z),underscore(_) int32_t isValidChildTableName(const char *pTbName, int16_t len, SSmlLinesInfo* info) { if (len > TSDB_TABLE_NAME_LEN - 1) { - tscError("SML:0x%"PRIx64" child table name cannot exceeds 192 characters", info->id); + tscError("SML:0x%"PRIx64" child table name cannot exceeds %d characters", info->id, TSDB_TABLE_NAME_LEN - 1); return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; } const char *cur = pTbName; diff --git a/src/client/src/tscParseOpenTSDB.c b/src/client/src/tscParseOpenTSDB.c index 164e3affb2..bf127eb49b 100644 --- a/src/client/src/tscParseOpenTSDB.c +++ b/src/client/src/tscParseOpenTSDB.c @@ -48,8 +48,8 @@ static int32_t parseTelnetMetric(TAOS_SML_DATA_POINT *pSml, const char **index, } while (*cur != '\0') { - if (len > TSDB_TABLE_NAME_LEN - 1) { - tscError("OTD:0x%"PRIx64" Metric cannot exceeds 192 characters", info->id); + if (len >= TSDB_TABLE_NAME_LEN - 1) { + tscError("OTD:0x%"PRIx64" Metric cannot exceeds %d characters", info->id, TSDB_TABLE_NAME_LEN - 1); tfree(pSml->stableName); return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; } @@ -180,8 +180,8 @@ static int32_t parseTelnetTagKey(TAOS_SML_KV *pKV, const char **index, SHashObj return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; } while (*cur != '\0') { - if (len > TSDB_COL_NAME_LEN - 1) { - tscError("OTD:0x%"PRIx64" Tag key cannot exceeds 64 characters", info->id); + if (len >= TSDB_COL_NAME_LEN - 1) { + tscError("OTD:0x%"PRIx64" Tag key cannot exceeds %d characters", info->id, TSDB_COL_NAME_LEN - 1); return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH; } if (*cur == ' ') { @@ -447,7 +447,7 @@ static int32_t parseMetricFromJSON(cJSON *root, TAOS_SML_DATA_POINT* pSml, SSmlL size_t stableLen = strlen(metric->valuestring); if (stableLen > TSDB_TABLE_NAME_LEN - 1) { - tscError("OTD:0x%"PRIx64" Metric cannot exceeds 192 characters in JSON", info->id); + tscError("OTD:0x%"PRIx64" Metric cannot exceeds %d characters in JSON", info->id, TSDB_TABLE_NAME_LEN - 1); return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; } @@ -882,7 +882,7 @@ static int32_t parseTagsFromJSON(cJSON *root, TAOS_SML_KV **pKVs, int *num_kvs, //key size_t keyLen = strlen(tag->string); if (keyLen > TSDB_COL_NAME_LEN - 1) { - tscError("OTD:0x%"PRIx64" Tag key cannot exceeds 64 characters in JSON", info->id); + tscError("OTD:0x%"PRIx64" Tag key cannot exceeds %d characters in JSON", info->id, TSDB_COL_NAME_LEN - 1); return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH; } pkv->key = tcalloc(keyLen + 1, sizeof(char)); diff --git a/src/connector/python/README.md b/src/connector/python/README.md index fe3dbec38b..fbc67a6a87 100644 --- a/src/connector/python/README.md +++ b/src/connector/python/README.md @@ -404,13 +404,13 @@ lines = [ 'st,t1=4i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"pass it again",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns', 'stf,t1=4i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"pass it again_stf",c2=false,c5=5f64,c6=7u64 1626006933641000000ns', ] -conn.schemaless_insert(lines) +conn.schemaless_insert(lines, 0) print("inserted") lines = [ 'stf,t1=5i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"pass it again_stf",c2=false,c5=5f64,c6=7u64 1626006933641000000ns', ] -conn.schemaless_insert(lines) +conn.schemaless_insert(lines, 0) result = conn.query("show tables") for row in result: diff --git a/src/connector/python/examples/insert-lines.py b/src/connector/python/examples/insert-lines.py index 73031f79a7..aceffe3988 100644 --- a/src/connector/python/examples/insert-lines.py +++ b/src/connector/python/examples/insert-lines.py @@ -9,10 +9,10 @@ conn.select_db(dbname) lines = [ 'st,t1=3i64,t2=4f64,t3="t3" c1=3i64,c3=L"pass",c2=false,c4=4f64 1626006833639000000ns', ] -conn.schemaless_insert(lines) +conn.schemaless_insert(lines, 0) print("inserted") -conn.schemaless_insert(lines) +conn.schemaless_insert(lines, 0) result = conn.query("show tables") for row in result: diff --git a/src/connector/python/taos/__init__.py b/src/connector/python/taos/__init__.py index 9b324fd50a..bf2be15afe 100644 --- a/src/connector/python/taos/__init__.py +++ b/src/connector/python/taos/__init__.py @@ -406,13 +406,13 @@ lines = [ 'st,t1=4i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns', 'stf,t1=4i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin_stf",c2=false,c5=5f64,c6=7u64 1626006933641000000ns', ] -conn.schemaless_insert(lines) +conn.schemaless_insert(lines, 0) print("inserted") lines = [ 'stf,t1=5i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin_stf",c2=false,c5=5f64,c6=7u64 1626006933641000000ns', ] -conn.schemaless_insert(lines) +conn.schemaless_insert(lines, 0) result = conn.query("show tables") for row in result: diff --git a/src/connector/python/taos/connection.py b/src/connector/python/taos/connection.py index 00919f5a98..65ed89a85d 100644 --- a/src/connector/python/taos/connection.py +++ b/src/connector/python/taos/connection.py @@ -132,19 +132,31 @@ class TaosConnection(object): lines = [ 'ste,t2=5,t3=L"ste" c1=true,c2=4,c3="string" 1626056811855516532', ] - conn.schemaless_insert(lines) + conn.schemaless_insert(lines, 0) ``` 2.OpenTSDB telnet style API format support ## Example - cpu_load 1626056811855516532ns 2.0f32 id="tb1",host="host0",interface="eth0" + import taos + conn = taos.connect() + conn.exec("drop database if exists test") + conn.select_db("test") + lines = [ + 'cpu_load 1626056811855516532ns 2.0f32 id="tb1",host="host0",interface="eth0"', + ] + conn.schemaless_insert(lines, 1) 3.OpenTSDB HTTP JSON format support ## Example - "{ + import taos + conn = taos.connect() + conn.exec("drop database if exists test") + conn.select_db("test") + payload = [''' + { "metric": "cpu_load_0", "timestamp": 1626006833610123, "value": 55.5, @@ -154,16 +166,9 @@ class TaosConnection(object): "interface": "eth0", "Id": "tb0" } - }" - - ## Exception - - ```python - try: - conn.schemaless_insert(lines) - except SchemalessError as err: - print(err) - ``` + } + '''] + conn.schemaless_insert(lines, 2) """ return taos_schemaless_insert(self._conn, lines, protocol) diff --git a/src/connector/python/tests/test_lines.py b/src/connector/python/tests/test_lines.py index d28dff1858..ceef25b0e6 100644 --- a/src/connector/python/tests/test_lines.py +++ b/src/connector/python/tests/test_lines.py @@ -27,13 +27,13 @@ def test_schemaless_insert(conn): 'st,t1=4i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns', 'stf,t1=4i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin_stf",c2=false,c5=5f64,c6=7u64 1626006933641000000ns', ] - conn.schemaless_insert(lines) + conn.schemaless_insert(lines, 0) print("inserted") lines = [ 'stf,t1=5i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin_stf",c2=false,c5=5f64,c6=7u64 1626006933641000000ns', ] - conn.schemaless_insert(lines) + conn.schemaless_insert(lines, 0) print("inserted") result = conn.query("select * from st") print(*result.fields) -- GitLab