diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index 139336e547..55e95c2aa5 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -117,8 +117,8 @@ typedef struct { //================================================================================================= static uint64_t linesSmlHandleId = 0; -static const char* TS = "ts"; -static const char* TAG = "tagNone"; +static const char* TS = "_ts"; +static const char* TAG = "_tagNone"; //================================================================================================= @@ -350,13 +350,26 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) { int n = sprintf(result, "create stable %s (", action->createSTable.sTableName); char* pos = result + n; int freeBytes = capacity - n; + size_t size = taosHashGetSize(action->createSTable.fields); + SArray *cols = taosArrayInit(size, POINTER_BYTES); SSmlKv **kv = taosHashIterate(action->createSTable.fields, NULL); while(kv){ - smlBuildColumnDescription(*kv, pos, freeBytes, &outBytes); - pos += outBytes; freeBytes -= outBytes; - *pos = ','; ++pos; --freeBytes; + if(strncmp((*kv)->key, TS, strlen(TS)) == 0 && (*kv)->type == TSDB_DATA_TYPE_TIMESTAMP){ + taosArrayInsert(cols, 0, kv); + }else{ + taosArrayPush(cols, kv); + } kv = taosHashIterate(action->createSTable.fields, kv); } + + for(int i = 0; i < taosArrayGetSize(cols); i++){ + SSmlKv *kvNew = taosArrayGetP(cols, i); + smlBuildColumnDescription(kvNew, pos, freeBytes, &outBytes); + pos += outBytes; freeBytes -= outBytes; + *pos = ','; ++pos; --freeBytes; + } + taosArrayDestroy(cols); + --pos; ++freeBytes; outBytes = snprintf(pos, freeBytes, ") tags ("); @@ -419,7 +432,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle* info) { code = catalogGetSTableMeta(info->pCatalog, info->taos->pAppInfo->pTransporter, &ep, &pName, &pTableMeta); - if (code == TSDB_CODE_TDB_INVALID_TABLE_ID) { + if (code == TSDB_CODE_TDB_INVALID_TABLE_ID || code == TSDB_CODE_MND_INVALID_STB) { SSchemaAction schemaAction = {0}; schemaAction.action = SCHEMA_ACTION_CREATE_STABLE; memcpy(schemaAction.createSTable.sTableName, superTable, superTableLen); diff --git a/source/client/test/smlTest.cpp b/source/client/test/smlTest.cpp index 190abd0145..5f0f188b0b 100644 --- a/source/client/test/smlTest.cpp +++ b/source/client/test/smlTest.cpp @@ -456,6 +456,12 @@ TEST(testCase, smlParseLine_Test) { TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(taos, NULL); + TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db"); + taos_free_result(pRes); + + pRes = taos_query(taos, "use sml_db"); + taos_free_result(pRes); + SRequestObj *request = createRequest(taos, NULL, NULL, TSDB_SQL_INSERT); ASSERT_NE(request, NULL); @@ -467,9 +473,10 @@ TEST(testCase, smlParseLine_Test) { "readings,name=truck_1,fleet=South,driver=Albert,model=F-150,device_version=v1.5 load_capacity=2000,fuel_capacity=200,nominal_fuel_consumption=15,latitude=72.45258,longitude=68.83761,elevation=255,velocity=0,heading=181,grade=0,fuel_consumption=25 1451606400000000000", "readings,name=truck_2,fleet=North,driver=Derek,model=F-150,device_version=v1.5 load_capacity=2000,fuel_capacity=200,nominal_fuel_consumption=15,latitude=24.5208,longitude=28.09377,elevation=428,velocity=0,heading=304,grade=0,fuel_consumption=25 1451606400000000000" }; - for (int i = 0; i < 3; i++) { - smlParseLine(info, sql[i]); - } + smlInsertLines(info, sql, 3); +// for (int i = 0; i < 3; i++) { +// smlParseLine(info, sql[i]); +// } } // TEST(testCase, smlParseTS_Test) { diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index d59473b26b..1e90d664a9 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -1624,10 +1624,6 @@ static int32_t smlParseTags(SArray *cols, SKVRowBuilder *tagsBuilder, SParsedDat int32_t smlBindData(void *handle, SArray *tags, SArray *colsFormat, SHashObj *colsHash, SArray *cols, bool format, STableMeta *pTableMeta, char *msgBuf, int16_t msgBufLen) { SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen}; - int32_t rowNum = taosArrayGetSize(cols); - if(rowNum <= 0) { - return buildInvalidOperationMsg(&pBuf, "cols size <= 0"); - } SSmlExecHandle *smlHandle = (SSmlExecHandle *)handle; SSchema* pTagsSchema = getTableTagSchema(pTableMeta); @@ -1679,6 +1675,10 @@ int32_t smlBindData(void *handle, SArray *tags, SArray *colsFormat, SHashObj *co initRowBuilder(&pDataBlock->rowBuilder, pDataBlock->pTableMeta->sversion, &pDataBlock->boundColumnInfo); + int32_t rowNum = format ? taosArrayGetSize(colsFormat) : taosArrayGetSize(cols); + if(rowNum <= 0) { + return buildInvalidOperationMsg(&pBuf, "cols size <= 0"); + } ret = allocateMemForSize(pDataBlock, extendedRowSize * rowNum); if(ret != TSDB_CODE_SUCCESS){ buildInvalidOperationMsg(&pBuf, "allocate memory error"); diff --git a/source/libs/transport/src/rpcTcp.c b/source/libs/transport/src/rpcTcp.c index 52c5ddcf63..edc685f498 100644 --- a/source/libs/transport/src/rpcTcp.c +++ b/source/libs/transport/src/rpcTcp.c @@ -21,7 +21,7 @@ #include "taoserror.h" #include "tutil.h" -#ifndef USE_UV +#ifndef USEf_UV typedef struct SFdObj { void * signature; TdSocketPtr pSocket; // TCP socket FD