提交 32ee9bf7 编写于 作者: G Ganlin Zhao

[TD-10445]<enhance>: change API name from taos_insert_lines to taos_schemaless_insert

上级 0182f95c
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "taos.h" #include "taos.h"
#include "tlog.h" #include "tlog.h"
#include "tscUtil.h" #include "tscUtil.h"
#include "tscParseLine.h"
#include "com_taosdata_jdbc_TSDBJNIConnector.h" #include "com_taosdata_jdbc_TSDBJNIConnector.h"
...@@ -1070,7 +1071,7 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_insertLinesImp(J ...@@ -1070,7 +1071,7 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_insertLinesImp(J
c_lines[i] = (char *)(*env)->GetStringUTFChars(env, line, 0); 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) { for (int i = 0; i < numLines; ++i) {
jstring line = (jstring)((*env)->GetObjectArrayElement(env, lines, i)); jstring line = (jstring)((*env)->GetObjectArrayElement(env, lines, i));
......
...@@ -1811,8 +1811,8 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash ...@@ -1811,8 +1811,8 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
} }
while (*cur != '\0') { while (*cur != '\0') {
if (len > TSDB_COL_NAME_LEN - 1) { if (len >= TSDB_COL_NAME_LEN - 1) {
tscError("SML:0x%"PRIx64" Key field cannot exceeds 64 characters", info->id); tscError("SML:0x%"PRIx64" Key field cannot exceeds %d characters", info->id, TSDB_COL_NAME_LEN - 1);
return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH; return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
} }
//unescaped '=' identifies a tag key //unescaped '=' identifies a tag key
...@@ -1898,8 +1898,8 @@ static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index ...@@ -1898,8 +1898,8 @@ static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index
} }
while (*cur != '\0') { while (*cur != '\0') {
if (len > TSDB_TABLE_NAME_LEN - 1) { if (len >= TSDB_TABLE_NAME_LEN - 1) {
tscError("SML:0x%"PRIx64" Measurement field cannot exceeds 192 characters", info->id); tscError("SML:0x%"PRIx64" Measurement field cannot exceeds %d characters", info->id, TSDB_TABLE_NAME_LEN - 1);
free(pSml->stableName); free(pSml->stableName);
pSml->stableName = NULL; pSml->stableName = NULL;
return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH;
...@@ -1931,7 +1931,7 @@ static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index ...@@ -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(_) //Table name can only contain digits(0-9),alphebet(a-z),underscore(_)
int32_t isValidChildTableName(const char *pTbName, int16_t len, SSmlLinesInfo* info) { int32_t isValidChildTableName(const char *pTbName, int16_t len, SSmlLinesInfo* info) {
if (len > TSDB_TABLE_NAME_LEN - 1) { 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; return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH;
} }
const char *cur = pTbName; const char *cur = pTbName;
......
...@@ -48,8 +48,8 @@ static int32_t parseTelnetMetric(TAOS_SML_DATA_POINT *pSml, const char **index, ...@@ -48,8 +48,8 @@ static int32_t parseTelnetMetric(TAOS_SML_DATA_POINT *pSml, const char **index,
} }
while (*cur != '\0') { while (*cur != '\0') {
if (len > TSDB_TABLE_NAME_LEN - 1) { if (len >= TSDB_TABLE_NAME_LEN - 1) {
tscError("OTD:0x%"PRIx64" Metric cannot exceeds 192 characters", info->id); tscError("OTD:0x%"PRIx64" Metric cannot exceeds %d characters", info->id, TSDB_TABLE_NAME_LEN - 1);
tfree(pSml->stableName); tfree(pSml->stableName);
return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH;
} }
...@@ -180,8 +180,8 @@ static int32_t parseTelnetTagKey(TAOS_SML_KV *pKV, const char **index, SHashObj ...@@ -180,8 +180,8 @@ static int32_t parseTelnetTagKey(TAOS_SML_KV *pKV, const char **index, SHashObj
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
} }
while (*cur != '\0') { while (*cur != '\0') {
if (len > TSDB_COL_NAME_LEN - 1) { if (len >= TSDB_COL_NAME_LEN - 1) {
tscError("OTD:0x%"PRIx64" Tag key cannot exceeds 64 characters", info->id); tscError("OTD:0x%"PRIx64" Tag key cannot exceeds %d characters", info->id, TSDB_COL_NAME_LEN - 1);
return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH; return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
} }
if (*cur == ' ') { if (*cur == ' ') {
...@@ -447,7 +447,7 @@ static int32_t parseMetricFromJSON(cJSON *root, TAOS_SML_DATA_POINT* pSml, SSmlL ...@@ -447,7 +447,7 @@ static int32_t parseMetricFromJSON(cJSON *root, TAOS_SML_DATA_POINT* pSml, SSmlL
size_t stableLen = strlen(metric->valuestring); size_t stableLen = strlen(metric->valuestring);
if (stableLen > TSDB_TABLE_NAME_LEN - 1) { 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; 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, ...@@ -882,7 +882,7 @@ static int32_t parseTagsFromJSON(cJSON *root, TAOS_SML_KV **pKVs, int *num_kvs,
//key //key
size_t keyLen = strlen(tag->string); size_t keyLen = strlen(tag->string);
if (keyLen > TSDB_COL_NAME_LEN - 1) { 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; return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
} }
pkv->key = tcalloc(keyLen + 1, sizeof(char)); pkv->key = tcalloc(keyLen + 1, sizeof(char));
......
...@@ -404,13 +404,13 @@ lines = [ ...@@ -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', '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', '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") print("inserted")
lines = [ 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', '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") result = conn.query("show tables")
for row in result: for row in result:
......
...@@ -9,10 +9,10 @@ conn.select_db(dbname) ...@@ -9,10 +9,10 @@ conn.select_db(dbname)
lines = [ lines = [
'st,t1=3i64,t2=4f64,t3="t3" c1=3i64,c3=L"pass",c2=false,c4=4f64 1626006833639000000ns', '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") print("inserted")
conn.schemaless_insert(lines) conn.schemaless_insert(lines, 0)
result = conn.query("show tables") result = conn.query("show tables")
for row in result: for row in result:
......
...@@ -406,13 +406,13 @@ lines = [ ...@@ -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', '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', '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") print("inserted")
lines = [ lines = [
'stf,t1=5i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin_stf",c2=false,c5=5f64,c6=7u64 1626006933641000000ns', '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") result = conn.query("show tables")
for row in result: for row in result:
......
...@@ -132,19 +132,31 @@ class TaosConnection(object): ...@@ -132,19 +132,31 @@ class TaosConnection(object):
lines = [ lines = [
'ste,t2=5,t3=L"ste" c1=true,c2=4,c3="string" 1626056811855516532', '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 2.OpenTSDB telnet style API format support
## Example ## 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 3.OpenTSDB HTTP JSON format support
## Example ## Example
"{ import taos
conn = taos.connect()
conn.exec("drop database if exists test")
conn.select_db("test")
payload = ['''
{
"metric": "cpu_load_0", "metric": "cpu_load_0",
"timestamp": 1626006833610123, "timestamp": 1626006833610123,
"value": 55.5, "value": 55.5,
...@@ -154,16 +166,9 @@ class TaosConnection(object): ...@@ -154,16 +166,9 @@ class TaosConnection(object):
"interface": "eth0", "interface": "eth0",
"Id": "tb0" "Id": "tb0"
} }
}" }
''']
## Exception conn.schemaless_insert(lines, 2)
```python
try:
conn.schemaless_insert(lines)
except SchemalessError as err:
print(err)
```
""" """
return taos_schemaless_insert(self._conn, lines, protocol) return taos_schemaless_insert(self._conn, lines, protocol)
......
...@@ -27,13 +27,13 @@ def test_schemaless_insert(conn): ...@@ -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', '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', '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") print("inserted")
lines = [ lines = [
'stf,t1=5i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin_stf",c2=false,c5=5f64,c6=7u64 1626006933641000000ns', '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") print("inserted")
result = conn.query("select * from st") result = conn.query("select * from st")
print(*result.fields) print(*result.fields)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册