From f1ea9905aaa5ea7428c60d67a7367bea167857f9 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 8 Jun 2022 16:50:02 +0800 Subject: [PATCH 01/11] fix: error in schemaless_insert if insert with multi threads --- source/client/src/clientSml.c | 45 ++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index bcdba69692..b6db3b7081 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -303,7 +303,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) { uError("SML:0x%" PRIx64 " apply schema action. reset query cache. error: %s", info->id, taos_errstr(res2)); } taos_free_result(res2); - taosMsleep(500); + taosMsleep(10); } break; } @@ -327,7 +327,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) { uError("SML:0x%" PRIx64 " apply schema action. reset query cache. error: %s", info->id, taos_errstr(res2)); } taos_free_result(res2); - taosMsleep(500); + taosMsleep(10); } break; } @@ -350,7 +350,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) { uError("SML:0x%" PRIx64 " apply schema action. reset query cache. error: %s", info->id, taos_errstr(res2)); } taos_free_result(res2); - taosMsleep(500); + taosMsleep(10); } break; } @@ -373,7 +373,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) { uError("SML:0x%" PRIx64 " apply schema action. reset query cache. error: %s", info->id, taos_errstr(res2)); } taos_free_result(res2); - taosMsleep(500); + taosMsleep(10); } break; } @@ -424,7 +424,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) { uError("SML:0x%" PRIx64 " apply schema action. reset query cache. error: %s", info->id, taos_errstr(res2)); } taos_free_result(res2); - taosMsleep(500); + taosMsleep(10); } break; } @@ -461,18 +461,18 @@ static int32_t smlProcessSchemaAction(SSmlHandle* info, SSchema* schemaField, SH static int32_t smlModifyDBSchemas(SSmlHandle* info) { int32_t code = 0; + SEpSet ep = getEpSet_s(&info->taos->pAppInfo->mgmtEp); + SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}}; + strcpy(pName.dbname, info->pRequest->pDb); SSmlSTableMeta** tableMetaSml = (SSmlSTableMeta**)taosHashIterate(info->superTables, NULL); while (tableMetaSml) { SSmlSTableMeta* sTableData = *tableMetaSml; - STableMeta *pTableMeta = NULL; - SEpSet ep = getEpSet_s(&info->taos->pAppInfo->mgmtEp); size_t superTableLen = 0; void *superTable = taosHashGetKey(tableMetaSml, &superTableLen); - SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}}; - strcpy(pName.dbname, info->pRequest->pDb); + memset(pName.tname, 0, TSDB_TABLE_NAME_LEN); memcpy(pName.tname, superTable, superTableLen); code = catalogGetSTableMeta(info->pCatalog, info->taos->pAppInfo->pTransporter, &ep, &pName, &pTableMeta); @@ -487,7 +487,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle* info) { code = smlApplySchemaAction(info, &schemaAction); if (code != TSDB_CODE_SUCCESS) { uError("SML:0x%"PRIx64" smlApplySchemaAction failed. can not create %s", info->id, schemaAction.createSTable.sTableName); - return code; + goto end; } info->cost.numOfCreateSTables++; }else if (code == TSDB_CODE_SUCCESS) { @@ -502,7 +502,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle* info) { code = smlProcessSchemaAction(info, pTableMeta->schema, hashTmp, sTableData->tags, &schemaAction, true); if (code != TSDB_CODE_SUCCESS) { taosHashCleanup(hashTmp); - return code; + goto end; } taosHashClear(hashTmp); @@ -512,29 +512,33 @@ static int32_t smlModifyDBSchemas(SSmlHandle* info) { code = smlProcessSchemaAction(info, pTableMeta->schema, hashTmp, sTableData->cols, &schemaAction, false); taosHashCleanup(hashTmp); if (code != TSDB_CODE_SUCCESS) { - return code; + goto end; } - code = catalogRefreshTableMeta(info->pCatalog, info->taos->pAppInfo->pTransporter, &ep, &pName, -1); + code = catalogRefreshTableMeta(info->pCatalog, info->taos->pAppInfo->pTransporter, &ep, &pName, 1); if (code != TSDB_CODE_SUCCESS) { - return code; + goto end; } } else { uError("SML:0x%"PRIx64" load table meta error: %s", info->id, tstrerror(code)); - return code; + goto end; } if(pTableMeta) taosMemoryFree(pTableMeta); code = catalogGetSTableMeta(info->pCatalog, info->taos->pAppInfo->pTransporter, &ep, &pName, &pTableMeta); if (code != TSDB_CODE_SUCCESS) { uError("SML:0x%"PRIx64" catalogGetSTableMeta failed. super table name %s", info->id, (char*)superTable); - return code; + goto end; } sTableData->tableMeta = pTableMeta; tableMetaSml = (SSmlSTableMeta**)taosHashIterate(info->superTables, tableMetaSml); } return 0; + +end: + catalogRefreshTableMeta(info->pCatalog, info->taos->pAppInfo->pTransporter, &ep, &pName, 1); + return code; } //========================================================================= @@ -2298,7 +2302,13 @@ static int smlProcess(SSmlHandle *info, char* lines[], int numLines) { info->cost.numOfCTables = taosHashGetSize(info->childTables); info->cost.schemaTime = taosGetTimestampUs(); - code = smlModifyDBSchemas(info); + + int32_t retryNum = 0; + do{ + code = smlModifyDBSchemas(info); + if (code == 0) break; + } while (retryNum++ < taosHashGetSize(info->superTables)); + if (code != 0) { uError("SML:0x%"PRIx64" smlModifyDBSchemas error : %s", info->id, tstrerror(code)); goto cleanup; @@ -2407,6 +2417,7 @@ TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int pr info->pRequest->code = smlProcess(info, lines, numLines); end: + info->taos->schemalessType = 0; uDebug("result:%s", info->msgBuf.buf); smlDestroyInfo(info); return (TAOS_RES*)request; From 48b487dd9d42d5a42f389f10d34e854fd2e8f3e9 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 8 Jun 2022 17:01:20 +0800 Subject: [PATCH 02/11] fix: error in schemaless_insert if insert with multi threads --- source/client/src/clientSml.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index a99c5a4deb..995722a49f 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -2289,6 +2289,8 @@ static int32_t smlParseLine(SSmlHandle *info, char* lines[], int numLines){ static int smlProcess(SSmlHandle *info, char* lines[], int numLines) { int32_t code = TSDB_CODE_SUCCESS; + int32_t retryNum = 0; + info->cost.parseTime = taosGetTimestampUs(); code = smlParseLine(info, lines, numLines); @@ -2303,7 +2305,6 @@ static int smlProcess(SSmlHandle *info, char* lines[], int numLines) { info->cost.schemaTime = taosGetTimestampUs(); - int32_t retryNum = 0; do{ code = smlModifyDBSchemas(info); if (code == 0) break; From 0147e4984894ff8d132790a46afee1b5b0546dda Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 8 Jun 2022 21:01:01 +0800 Subject: [PATCH 03/11] fix:add test case --- source/client/test/smlTest.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/source/client/test/smlTest.cpp b/source/client/test/smlTest.cpp index 1358d45f30..46c451f164 100644 --- a/source/client/test/smlTest.cpp +++ b/source/client/test/smlTest.cpp @@ -1272,14 +1272,40 @@ TEST(testCase, sml_params_Test) { }; TAOS_RES* res = taos_schemaless_insert(taos, (char**)sql, 1, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS); ASSERT_EQ(taos_errno(res), TSDB_CODE_PAR_DB_NOT_SPECIFIED); - taos_free_result(pRes); + taos_free_result(res); pRes = taos_query(taos, "use param"); - taos_free_result(pRes); + taos_free_result(res); res = taos_schemaless_insert(taos, (char**)sql, 1, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS); ASSERT_EQ(taos_errno(res), TSDB_CODE_SML_INVALID_DB_CONF); + taos_free_result(res); +} + +TEST(testCase, sml_16384_Test) { + TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0); + ASSERT_NE(taos, nullptr); + + TAOS_RES* pRes = taos_query(taos, "create database if not exists d16384 schemaless 1"); taos_free_result(pRes); + + const char *sql[] = { + "qelhxo,id=pnnqhsa,t0=t,t1=127i8 c0=t,c1=127i8 1626006833639000000", + }; + + pRes = taos_query(taos, "use d16384"); + taos_free_result(pRes); + + TAOS_RES* res = taos_schemaless_insert(taos, (char**)sql, 1, TSDB_SML_LINE_PROTOCOL, 0); + ASSERT_EQ(taos_errno(res), 0); + taos_free_result(res); + + const char *sql1[] = { + "qelhxo,id=pnnqhsa,t0=t,t1=127i8 c0=f,c1=127i8,c11=L\"ncharColValue\",c10=t 1626006833639000000", + }; + TAOS_RES* res1 = taos_schemaless_insert(taos, (char**)sql1, 1, TSDB_SML_LINE_PROTOCOL, 0); + ASSERT_EQ(taos_errno(res1), 0); + taos_free_result(res1); } TEST(testCase, sml_oom_Test) { From ac5f09251d3de44154c90523d44d8cc0be73647c Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 9 Jun 2022 11:09:23 +0800 Subject: [PATCH 04/11] fix:err in tag scan --- source/libs/executor/src/scanoperator.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index cc76cc29e4..b6ec37982b 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -1756,6 +1756,7 @@ SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysi ; pInfo->readHandle = *pReadHandle; pInfo->curPos = 0; + pInfo->pFilterNode = pPhyNode->node.pConditions; pOperator->name = "TagScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN; pOperator->blocking = false; From 04f1f71095a97ade5901cb76c1bf196740f24732 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 9 Jun 2022 14:27:02 +0800 Subject: [PATCH 05/11] fix:error in schemaless --- source/client/src/clientSml.c | 7 +++++-- source/client/test/smlTest.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index 995722a49f..fe21d48a65 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -1548,7 +1548,7 @@ static int32_t smlParseTSFromJSONObj(SSmlHandle *info, cJSON *root, int64_t *tsV } size_t typeLen = strlen(type->valuestring); - if (typeLen == 1 && type->valuestring[0] == 's') { + if (typeLen == 1 && (type->valuestring[0] == 's' || type->valuestring[0] == 'S')) { //seconds timeDouble = timeDouble * 1e9; if(smlDoubleToInt64OverFlow(timeDouble)){ @@ -1556,9 +1556,10 @@ static int32_t smlParseTSFromJSONObj(SSmlHandle *info, cJSON *root, int64_t *tsV return TSDB_CODE_TSC_INVALID_TIME_STAMP; } *tsVal = timeDouble; - } else if (typeLen == 2 && type->valuestring[1] == 's') { + } else if (typeLen == 2 && (type->valuestring[0] == 's' || type->valuestring[0] == 'S')) { switch (type->valuestring[0]) { case 'm': + case 'M': //milliseconds timeDouble = timeDouble * 1e6; if(smlDoubleToInt64OverFlow(timeDouble)){ @@ -1568,6 +1569,7 @@ static int32_t smlParseTSFromJSONObj(SSmlHandle *info, cJSON *root, int64_t *tsV *tsVal = timeDouble; break; case 'u': + case 'U': //microseconds timeDouble = timeDouble * 1e3; if(smlDoubleToInt64OverFlow(timeDouble)){ @@ -1577,6 +1579,7 @@ static int32_t smlParseTSFromJSONObj(SSmlHandle *info, cJSON *root, int64_t *tsV *tsVal = timeDouble; break; case 'n': + case 'N': //nanoseconds *tsVal = timeDouble; break; diff --git a/source/client/test/smlTest.cpp b/source/client/test/smlTest.cpp index 46c451f164..8c382339b1 100644 --- a/source/client/test/smlTest.cpp +++ b/source/client/test/smlTest.cpp @@ -1329,3 +1329,37 @@ TEST(testCase, sml_oom_Test) { ASSERT_EQ(taos_errno(res), 0); taos_free_result(pRes); } + +TEST(testCase, sml_16368_Test) { + TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0); + ASSERT_NE(taos, nullptr); + + TAOS_RES* pRes = taos_query(taos, "create database if not exists d16368 schemaless 1"); + taos_free_result(pRes); + + pRes = taos_query(taos, "use d16368"); + taos_free_result(pRes); + + SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT); + ASSERT_NE(request, nullptr); + + SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS); + ASSERT_NE(info, nullptr); + + const char *sql[] = { + "[{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833639000, \"type\": \"us\"}, \"value\": 1, \"tags\": {\"t1\": 3, \"t2\": {\"value\": 4, \"type\": \"double\"}, \"t3\": {\"value\": \"t3\", \"type\": \"binary\"}}},\n" + "{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833739000, \"type\": \"us\"}, \"value\": 2, \"tags\": {\"t1\": {\"value\": 4, \"type\": \"double\"}, \"t3\": {\"value\": \"t4\", \"type\": \"binary\"}, \"t2\": {\"value\": 5, \"type\": \"double\"}, \"t4\": {\"value\": 5, \"type\": \"double\"}}},\n" + "{\"metric\": \"stb_name\", \"timestamp\": {\"value\": 1626006833639100, \"type\": \"us\"}, \"value\": 3, \"tags\": {\"t2\": {\"value\": 5, \"type\": \"double\"}, \"t3\": {\"value\": \"ste\", \"type\": \"nchar\"}}},\n" + "{\"metric\": \"stf567890\", \"timestamp\": {\"value\": 1626006833639200, \"type\": \"us\"}, \"value\": 4, \"tags\": {\"t1\": {\"value\": 4, \"type\": \"bigint\"}, \"t3\": {\"value\": \"t4\", \"type\": \"binary\"}, \"t2\": {\"value\": 5, \"type\": \"double\"}, \"t4\": {\"value\": 5, \"type\": \"double\"}}},\n" + "{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833639300, \"type\": \"us\"}, \"value\": {\"value\": 5, \"type\": \"double\"}, \"tags\": {\"t1\": {\"value\": 4, \"type\": \"double\"}, \"t2\": 5.0, \"t3\": {\"value\": \"t4\", \"type\": \"binary\"}}},\n" + "{\"metric\": \"stb_name\", \"timestamp\": {\"value\": 1626006833639400, \"type\": \"us\"}, \"value\": {\"value\": 6, \"type\": \"double\"}, \"tags\": {\"t2\": 5.0, \"t3\": {\"value\": \"ste2\", \"type\": \"nchar\"}}},\n" + "{\"metric\": \"stb_name\", \"timestamp\": {\"value\": 1626006834639400, \"type\": \"us\"}, \"value\": {\"value\": 7, \"type\": \"double\"}, \"tags\": {\"t2\": {\"value\": 5.0, \"type\": \"double\"}, \"t3\": {\"value\": \"ste2\", \"type\": \"nchar\"}}},\n" + "{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833839006, \"type\": \"us\"}, \"value\": {\"value\": 8, \"type\": \"double\"}, \"tags\": {\"t1\": {\"value\": 4, \"type\": \"double\"}, \"t3\": {\"value\": \"t4\", \"type\": \"binary\"}, \"t2\": {\"value\": 5, \"type\": \"double\"}, \"t4\": {\"value\": 5, \"type\": \"double\"}}},\n" + "{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833939007, \"type\": \"us\"}, \"value\": {\"value\": 9, \"type\": \"double\"}, \"tags\": {\"t1\": 4, \"t3\": {\"value\": \"t4\", \"type\": \"binary\"}, \"t2\": {\"value\": 5, \"type\": \"double\"}, \"t4\": {\"value\": 5, \"type\": \"double\"}}}]" + }; + int32_t ret = smlProcess(info, (char**)sql, sizeof(sql)/sizeof(sql[0])); + ASSERT_EQ(ret, 0); + + destroyRequest(request); + smlDestroyInfo(info); +} From 08a19b7b28f86228f9b49dbe635395058f2998ad Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Thu, 9 Jun 2022 15:00:48 +0800 Subject: [PATCH 06/11] enh: set 0 in flen part for tsrow --- source/common/src/tdataformat.c | 24 ++++++-- source/common/test/dataformatTest.cpp | 81 ++++++++++++++------------- 2 files changed, 60 insertions(+), 45 deletions(-) diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 84a2cf0544..1ddb606ccf 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -244,7 +244,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S } } - // ASSERT(flags); // only 1 column(ts) + ASSERT(flags); // decide uint32_t nData = 0; @@ -268,8 +268,8 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S nDataT = BIT2_SIZE(pTSchema->numOfCols - 1) + pTSchema->flen + ntv; break; default: - break; // only ts column - // ASSERT(0); + break; + ASSERT(0); } uint8_t tflags = 0; @@ -374,7 +374,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S ptv = pf + pTSchema->flen; break; default: - // ASSERT(0); + ASSERT(0); break; } } else { @@ -421,12 +421,26 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S _set_none: if ((flags & 0xf0) == 0) { setBitMap(pb, 0, iColumn - 1, flags); + if (flags & TSROW_HAS_VAL) { // set 0 + if (IS_VAR_DATA_TYPE(pTColumn->type)) { + *(VarDataOffsetT *)(pf + pTColumn->offset) = 0; + } else { + tPutValue(pf + pTColumn->offset, &((SValue){0}), pTColumn->type); + } + } } continue; _set_null: if ((flags & 0xf0) == 0) { setBitMap(pb, 1, iColumn - 1, flags); + if (flags & TSROW_HAS_VAL) { // set 0 + if (IS_VAR_DATA_TYPE(pTColumn->type)) { + *(VarDataOffsetT *)(pf + pTColumn->offset) = 0; + } else { + tPutValue(pf + pTColumn->offset, &((SValue){0}), pTColumn->type); + } + } } else { SET_IDX(pidx, pTSKVRow->nCols, nkv, flags); pTSKVRow->nCols++; @@ -497,7 +511,7 @@ void tTSRowGet(STSRow2 *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal SValue value; ASSERT(iCol < pTSchema->numOfCols); - // ASSERT(flags); // only 1 ts column + ASSERT(flags); ASSERT(pRow->sver == pTSchema->version); if (iCol == 0) { diff --git a/source/common/test/dataformatTest.cpp b/source/common/test/dataformatTest.cpp index 81e91da0d6..020b1e0deb 100644 --- a/source/common/test/dataformatTest.cpp +++ b/source/common/test/dataformatTest.cpp @@ -52,61 +52,61 @@ STSchema *genSTSchema(int16_t nCols) { switch (i) { case 0: { - pSchema[0].type = TSDB_DATA_TYPE_TIMESTAMP; - pSchema[0].bytes = TYPE_BYTES[pSchema[0].type]; + pSchema[i].type = TSDB_DATA_TYPE_TIMESTAMP; + pSchema[i].bytes = TYPE_BYTES[pSchema[i].type]; } break; case 1: { - pSchema[1].type = TSDB_DATA_TYPE_INT; - pSchema[1].bytes = TYPE_BYTES[pSchema[1].type]; + pSchema[i].type = TSDB_DATA_TYPE_INT; + pSchema[i].bytes = TYPE_BYTES[pSchema[i].type]; ; } break; case 2: { - pSchema[2].type = TSDB_DATA_TYPE_BIGINT; - pSchema[2].bytes = TYPE_BYTES[pSchema[2].type]; + pSchema[i].type = TSDB_DATA_TYPE_BIGINT; + pSchema[i].bytes = TYPE_BYTES[pSchema[i].type]; } break; case 3: { - pSchema[3].type = TSDB_DATA_TYPE_FLOAT; - pSchema[3].bytes = TYPE_BYTES[pSchema[3].type]; + pSchema[i].type = TSDB_DATA_TYPE_FLOAT; + pSchema[i].bytes = TYPE_BYTES[pSchema[i].type]; } break; case 4: { - pSchema[4].type = TSDB_DATA_TYPE_DOUBLE; - pSchema[4].bytes = TYPE_BYTES[pSchema[4].type]; + pSchema[i].type = TSDB_DATA_TYPE_DOUBLE; + pSchema[i].bytes = TYPE_BYTES[pSchema[i].type]; } break; case 5: { - pSchema[5].type = TSDB_DATA_TYPE_BINARY; - pSchema[5].bytes = 12; + pSchema[i].type = TSDB_DATA_TYPE_BINARY; + pSchema[i].bytes = 12; } break; case 6: { - pSchema[6].type = TSDB_DATA_TYPE_NCHAR; - pSchema[6].bytes = 42; + pSchema[i].type = TSDB_DATA_TYPE_NCHAR; + pSchema[i].bytes = 42; } break; case 7: { - pSchema[7].type = TSDB_DATA_TYPE_TINYINT; - pSchema[7].bytes = TYPE_BYTES[pSchema[7].type]; + pSchema[i].type = TSDB_DATA_TYPE_TINYINT; + pSchema[i].bytes = TYPE_BYTES[pSchema[i].type]; } break; case 8: { - pSchema[8].type = TSDB_DATA_TYPE_SMALLINT; - pSchema[8].bytes = TYPE_BYTES[pSchema[8].type]; + pSchema[i].type = TSDB_DATA_TYPE_SMALLINT; + pSchema[i].bytes = TYPE_BYTES[pSchema[i].type]; } break; case 9: { - pSchema[9].type = TSDB_DATA_TYPE_BOOL; - pSchema[9].bytes = TYPE_BYTES[pSchema[9].type]; + pSchema[i].type = TSDB_DATA_TYPE_BOOL; + pSchema[i].bytes = TYPE_BYTES[pSchema[i].type]; } break; case 10: { - pSchema[10].type = TSDB_DATA_TYPE_UTINYINT; - pSchema[10].bytes = TYPE_BYTES[pSchema[10].type]; + pSchema[i].type = TSDB_DATA_TYPE_UTINYINT; + pSchema[i].bytes = TYPE_BYTES[pSchema[i].type]; } break; case 11: { - pSchema[11].type = TSDB_DATA_TYPE_USMALLINT; - pSchema[11].bytes = TYPE_BYTES[pSchema[11].type]; + pSchema[i].type = TSDB_DATA_TYPE_USMALLINT; + pSchema[i].bytes = TYPE_BYTES[pSchema[i].type]; } break; case 12: { - pSchema[12].type = TSDB_DATA_TYPE_UINT; - pSchema[12].bytes = TYPE_BYTES[pSchema[12].type]; + pSchema[i].type = TSDB_DATA_TYPE_UINT; + pSchema[i].bytes = TYPE_BYTES[pSchema[i].type]; } break; case 13: { - pSchema[13].type = TSDB_DATA_TYPE_UBIGINT; - pSchema[13].bytes = TYPE_BYTES[pSchema[13].type]; + pSchema[i].type = TSDB_DATA_TYPE_UBIGINT; + pSchema[i].bytes = TYPE_BYTES[pSchema[i].type]; } break; default: @@ -146,9 +146,9 @@ static int32_t genTestData(const char **data, int16_t nCols, SArray **pArray) { case 0: sscanf(data[i], "%" PRIi64, &colVal.value.ts); break; - case 1: { + case 1: sscanf(data[i], "%" PRIi32, &colVal.value.i32); - } break; + break; case 2: sscanf(data[i], "%" PRIi64, &colVal.value.i64); break; @@ -404,9 +404,10 @@ static void checkTSRow(const char **data, STSRow2 *row, STSchema *pTSchema) { } TEST(testCase, AllNormTest) { - int16_t nCols = 1; - STSRow2 *row = nullptr; - SArray *pArray = taosArrayInit(nCols, sizeof(SColVal)); + int16_t nCols = 14; + STSRowBuilder rb = tsRowBuilderInit(); + STSRow2 *row = nullptr; + SArray *pArray = taosArrayInit(nCols, sizeof(SColVal)); EXPECT_NE(pArray, nullptr); STSchema *pTSchema = genSTSchema(nCols); @@ -414,15 +415,16 @@ TEST(testCase, AllNormTest) { // ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(10), c6 nchar(10), c7 tinyint, c8 smallint, // c9 bool - char *data[10] = {"1653694220000", "10", "20", "10.1", "10.1", "binary10", "nchar10", "10", "10", "1"}; + char *data[14] = {"1653694220000", "no", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "no", "no", "no", "no", "no"}; genTestData((const char **)&data, nCols, &pArray); - tTSRowNew(NULL, pArray, pTSchema, &row); + tTSRowNew(&rb, pArray, pTSchema, &row); debugPrintTSRow(row, pTSchema, __func__, __LINE__); checkTSRow((const char **)&data, row, pTSchema); + tsRowBuilderClear(&rb); taosArrayDestroy(pArray); taosMemoryFree(pTSchema); } @@ -443,12 +445,12 @@ TEST(testCase, NoneTest) { const char *data[nRows][nCols] = { {"1653694220000", "no", "20", "10.1", "10.1", "binary10", "no", "10", "10", "nu", "10", "20", "30", "40"}, {"1653694220001", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no"}, - {"1653694220002", "no", "no", "no", "no", "no", "nu", "no", "no", "no", "no", "no", "no", "nu"}, - {"1653694220003", "nu", "no", "no", "no", "no", "nu", "no", "no", "no", "no", "no", "no", "no"}, + {"1653694220002", "10", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no"}, + {"1653694220003", "10", "10", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no"}, {"1653694220004", "no", "20", "no", "no", "no", "nchar10", "no", "no", "no", "no", "no", "no", "no"}, {"1653694220005", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu"}, {"1653694220006", "no", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu"}, - {"1653694220007", "no", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "no"}, + {"1653694220007", "no", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "no", "no", "no", "no", "no"}, {"1653694220008", "no", "nu", "nu", "nu", "binary10", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "no"}, {"1653694220009", "no", "nu", "nu", "nu", "binary10", "nu", "nu", "10", "no", "nu", "nu", "nu", "100"}, {"1653694220010", "-1", "-1", "-1", "-1", "binary10", "nu", "-1", "0", "0", "0", "0", "0", "0"}, @@ -465,13 +467,12 @@ TEST(testCase, NoneTest) { {"1653694220019", "no", "9223372036854775807", "nu", "nu", "bin10", "nu", "nu", "10", "no", "254", "nu", "nu", "no"}}; - for (int r = 0; r < nRows; ++r) { genTestData((const char **)&data[r], nCols, &pArray); tTSRowNew(NULL, pArray, pTSchema, &row); debugPrintTSRow(row, pTSchema, __func__, __LINE__); // debug print checkTSRow((const char **)&data[r], row, pTSchema); // check - taosMemoryFreeClear(row); + tTSRowFree(row); taosArrayClear(pArray); } From fb3b66413e1340d7a7ec829f210a9b53ebe44ab2 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Thu, 9 Jun 2022 15:13:58 +0800 Subject: [PATCH 07/11] enh: code optimization for trow --- source/common/test/dataformatTest.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/source/common/test/dataformatTest.cpp b/source/common/test/dataformatTest.cpp index 020b1e0deb..4be0711546 100644 --- a/source/common/test/dataformatTest.cpp +++ b/source/common/test/dataformatTest.cpp @@ -274,9 +274,6 @@ int32_t debugPrintSColVal(SColVal *cv, int8_t type) { case TSDB_DATA_TYPE_MEDIUMBLOB: printf("MedBLOB "); break; - // case TSDB_DATA_TYPE_BINARY: - // printf("BINARY "); - // break; case TSDB_DATA_TYPE_MAX: printf("UNDEF "); break; From fb26a97fae97352063e4e764e72dca67182f2556 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 9 Jun 2022 15:45:31 +0800 Subject: [PATCH 08/11] fix:error in schemaless --- source/client/src/clientSml.c | 2 +- source/client/test/smlTest.cpp | 14 +++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index fe21d48a65..93e193f0ce 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -1556,7 +1556,7 @@ static int32_t smlParseTSFromJSONObj(SSmlHandle *info, cJSON *root, int64_t *tsV return TSDB_CODE_TSC_INVALID_TIME_STAMP; } *tsVal = timeDouble; - } else if (typeLen == 2 && (type->valuestring[0] == 's' || type->valuestring[0] == 'S')) { + } else if (typeLen == 2 && (type->valuestring[1] == 's' || type->valuestring[1] == 'S')) { switch (type->valuestring[0]) { case 'm': case 'M': diff --git a/source/client/test/smlTest.cpp b/source/client/test/smlTest.cpp index 8c382339b1..8ec411fbff 100644 --- a/source/client/test/smlTest.cpp +++ b/source/client/test/smlTest.cpp @@ -1340,12 +1340,6 @@ TEST(testCase, sml_16368_Test) { pRes = taos_query(taos, "use d16368"); taos_free_result(pRes); - SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT); - ASSERT_NE(request, nullptr); - - SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS); - ASSERT_NE(info, nullptr); - const char *sql[] = { "[{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833639000, \"type\": \"us\"}, \"value\": 1, \"tags\": {\"t1\": 3, \"t2\": {\"value\": 4, \"type\": \"double\"}, \"t3\": {\"value\": \"t3\", \"type\": \"binary\"}}},\n" "{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833739000, \"type\": \"us\"}, \"value\": 2, \"tags\": {\"t1\": {\"value\": 4, \"type\": \"double\"}, \"t3\": {\"value\": \"t4\", \"type\": \"binary\"}, \"t2\": {\"value\": 5, \"type\": \"double\"}, \"t4\": {\"value\": 5, \"type\": \"double\"}}},\n" @@ -1357,9 +1351,7 @@ TEST(testCase, sml_16368_Test) { "{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833839006, \"type\": \"us\"}, \"value\": {\"value\": 8, \"type\": \"double\"}, \"tags\": {\"t1\": {\"value\": 4, \"type\": \"double\"}, \"t3\": {\"value\": \"t4\", \"type\": \"binary\"}, \"t2\": {\"value\": 5, \"type\": \"double\"}, \"t4\": {\"value\": 5, \"type\": \"double\"}}},\n" "{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833939007, \"type\": \"us\"}, \"value\": {\"value\": 9, \"type\": \"double\"}, \"tags\": {\"t1\": 4, \"t3\": {\"value\": \"t4\", \"type\": \"binary\"}, \"t2\": {\"value\": 5, \"type\": \"double\"}, \"t4\": {\"value\": 5, \"type\": \"double\"}}}]" }; - int32_t ret = smlProcess(info, (char**)sql, sizeof(sql)/sizeof(sql[0])); - ASSERT_EQ(ret, 0); - - destroyRequest(request); - smlDestroyInfo(info); + pRes = taos_schemaless_insert(taos, (char**)sql, sizeof(sql)/sizeof(sql[0]), TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_MICRO_SECONDS); + ASSERT_EQ(taos_errno(pRes), 0); + taos_free_result(pRes); } From f2b98f773542b9f360d26d8ec05828fe0d151800 Mon Sep 17 00:00:00 2001 From: gccgdb1234 Date: Thu, 9 Jun 2022 15:57:53 +0800 Subject: [PATCH 09/11] docs: refine Grafana plugin installation --- docs-cn/20-third-party/01-grafana.mdx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/docs-cn/20-third-party/01-grafana.mdx b/docs-cn/20-third-party/01-grafana.mdx index 2daaebc32d..31cd434080 100644 --- a/docs-cn/20-third-party/01-grafana.mdx +++ b/docs-cn/20-third-party/01-grafana.mdx @@ -3,6 +3,9 @@ sidebar_label: Grafana title: Grafana --- +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; + TDengine 能够与开源数据可视化系统 [Grafana](https://www.grafana.com/) 快速集成搭建数据监测报警系统,整个过程无需任何代码开发,TDengine 中数据表的内容可以在仪表盘(DashBoard)上进行可视化展现。关于 TDengine 插件的使用您可以在[GitHub](https://github.com/taosdata/grafanaplugin/blob/master/README.md)中了解更多。 ## 前置条件 @@ -23,9 +26,12 @@ TDengine 能够与开源数据可视化系统 [Grafana](https://www.grafana.com/ ## 配置 Grafana -### 安装方式一:安装脚本 +### 安装 Grafana Plugin 并配置数据源 -将集群信息设置为环境变量(也可以使用 [`.env`(dotenv) 文件](https://hexdocs.pm/dotenvy/dotenv-file-format.html) ): + + + +将集群信息设置为环境变量;也可以使用 `.env` 文件,请参考 [dotenv](https://hexdocs.pm/dotenvy/dotenv-file-format.html): ```sh export TDENGINE_API=http://tdengine.local:6041 @@ -42,7 +48,8 @@ bash -c "$(curl -fsSL https://raw.githubusercontent.com/taosdata/grafanaplugin/m 该脚本将自动安装 Grafana 插件并配置数据源。安装完毕后,需要重启 Grafana 服务后生效。 -### 安装方式二:手动安装 TDengine 数据源插件 + + 使用 [`grafana-cli` 命令行工具](https://grafana.com/docs/grafana/latest/administration/cli/) 进行插件[安装](https://grafana.com/grafana/plugins/tdengine-datasource/?tab=installation)。 @@ -94,6 +101,9 @@ GF_INSTALL_PLUGINS=tdengine-datasource ![TDengine Database Grafana plugin add data source](./add_datasource4.webp) + + + ### 创建 Dashboard 回到主界面创建 Dashboard,点击 Add Query 进入面板查询页面: From efad6dc174e0b2fae087677e6b0b3212b169eff3 Mon Sep 17 00:00:00 2001 From: gccgdb1234 Date: Thu, 9 Jun 2022 16:14:14 +0800 Subject: [PATCH 10/11] docs: refine Grafana plugin installation --- docs-en/20-third-party/01-grafana.mdx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/docs-en/20-third-party/01-grafana.mdx b/docs-en/20-third-party/01-grafana.mdx index 1e1b49703e..033ef3b206 100644 --- a/docs-en/20-third-party/01-grafana.mdx +++ b/docs-en/20-third-party/01-grafana.mdx @@ -3,6 +3,9 @@ sidebar_label: Grafana title: Grafana --- +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; + TDengine can be quickly integrated with the open-source data visualization system [Grafana](https://www.grafana.com/) to build a data monitoring and alerting system. The whole process does not require any code development. And you can visualize the contents of the data tables in TDengine on a dashboard. You can learn more about using the TDengine plugin on [GitHub](https://github.com/taosdata/grafanaplugin/blob/master/README.md). @@ -25,7 +28,10 @@ TDengine currently supports Grafana versions 7.5 and above. Users can go to the ## Configuring Grafana -### Option 1: Install with `install.sh` +### Install Grafana Plugin and Configure Data Source + + + Set the url and authorization environment variables by `export` or a [`.env`(dotenv) file](https://hexdocs.pm/dotenvy/dotenv-file-format.html): @@ -46,7 +52,8 @@ With this script, TDengine data source plugin and the Grafana data source will b And then, restart Grafana service and open Grafana in web-browser, usually . -### Option 2: Install Plugin Manually + + Follow the installation steps in [Grafana](https://grafana.com/grafana/plugins/tdengine-datasource/?tab=installation) with the [``grafana-cli`` command-line tool](https://grafana.com/docs/grafana/latest/administration/cli/) for plugin installation. @@ -98,6 +105,9 @@ Click `Save & Test` to test. You should see a success message if the test worked ![TDengine Database TDinsight plugin add database 4](./grafana/add_datasource4.webp) + + + ### Create Dashboard Go back to the main interface to create a dashboard and click Add Query to enter the panel query page: From 8997f2cdc1507e2594f126e9e0cca2a6450c7084 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Thu, 9 Jun 2022 16:26:30 +0800 Subject: [PATCH 11/11] fix: solve a non-standard explicit type conversion --- source/common/test/dataformatTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/common/test/dataformatTest.cpp b/source/common/test/dataformatTest.cpp index 4be0711546..a52bb6b516 100644 --- a/source/common/test/dataformatTest.cpp +++ b/source/common/test/dataformatTest.cpp @@ -402,7 +402,7 @@ static void checkTSRow(const char **data, STSRow2 *row, STSchema *pTSchema) { TEST(testCase, AllNormTest) { int16_t nCols = 14; - STSRowBuilder rb = tsRowBuilderInit(); + STSRowBuilder rb = {0}; STSRow2 *row = nullptr; SArray *pArray = taosArrayInit(nCols, sizeof(SColVal)); EXPECT_NE(pArray, nullptr);