From 36f0b8a648a8b577937e5248f9e95f29dc5a1251 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Tue, 13 Jul 2021 22:41:04 +0800 Subject: [PATCH] add more data type --- src/client/src/tscParseLineProtocol.c | 18 +++++++++++++++++- tests/examples/c/apitest.c | 9 ++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index a198a7b42a..9f86d780d3 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -912,6 +912,12 @@ int32_t parseItemValue(SLPItem* item, LPItemKind kind) { item->value = malloc(item->length); char* endptr = NULL; *(int64_t*)(item->value) = strtoll(sv, &endptr, 10); + } else if (*last == 'u') { + item->type = TSDB_DATA_TYPE_UBIGINT; + item->length = (int16_t)tDataTypes[item->type].bytes; + item->value = malloc(item->length); + char* endptr = NULL; + *(uint64_t*)(item->value) = (uint64_t)strtoull(sv, &endptr, 10); } else if (*last == 'b') { item->type = TSDB_DATA_TYPE_TINYINT; item->length = (int16_t)tDataTypes[item->type].bytes; @@ -989,6 +995,16 @@ int32_t parsePointTime(SLPPoint* point) { } else { char* endptr = NULL; point->ts = strtoll(point->tsToken.z, &endptr, 10); + char* last = point->tsToken.z + point->tsToken.n - 1; + if (*last == 's') { + point->ts *= (int64_t)1e9; + } else if (*last == 'a') { + point->ts *= (int64_t)1e6; + } else if (*last == 'u') { + point->ts *= (int64_t)1e3; + } else if (*last == 'b') { + point->ts *= 1; + } } return 0; } @@ -1083,7 +1099,7 @@ int32_t tscParseLine(SStrToken line, SLPPoint* point) { int32_t tscParseLines(char* lines[], int numLines, SArray* points, SArray* failedLines) { for (int32_t i = 0; i < numLines; ++i) { - SStrToken tkLine = {.z = lines[i], .n = (uint32_t)strlen(lines[i])+1}; + SStrToken tkLine = {.z = lines[i], .n = (uint32_t)strlen(lines[i])}; SLPPoint point; tscParseLine(tkLine, &point); taosArrayPush(points, &point); diff --git a/tests/examples/c/apitest.c b/tests/examples/c/apitest.c index 376b00ef71..ed76e7b2b0 100644 --- a/tests/examples/c/apitest.c +++ b/tests/examples/c/apitest.c @@ -966,13 +966,16 @@ int32_t verify_schema_less(TAOS* taos) { char* 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", - "st,t1=4i,t2=5,t3=\"t4\" c1=3i,c3=L\"passitagain\",c2=true,c4=5 1626006833642000000", "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" + "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" }; - //int code = taos_insert_by_lines(taos, lines , 6); +// int code = taos_insert_by_lines(taos, lines , sizeof(lines)/sizeof(char*)); int code = taos_insert_by_lines(taos, &lines[0], 1); code = taos_insert_by_lines(taos, &lines[1], 1); -- GitLab