diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index cd8415c5f355ec77baaed69fbfd74f8028fbf9e1..ed4b719b784dd23436c5e4dd569cb26a273d7ee6 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -245,16 +245,19 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint, if (!point->childTableName) { buildSmlChildTableName(point, info); } - const char tagNullName[] = "`_tag_null`"; - size_t* pTagNullIdx = taosHashGet(pStableSchema->tagHash, tagNullName, strlen(tagNullName)); + char tagNullName[TSDB_COL_NAME_LEN] = {0}; + int16_t nameLen = strlen(tsSmlTagNullName); + strncpy(tagNullName, tsSmlTagNullName, nameLen); + addEscapeCharToString(tagNullName, nameLen); + size_t* pTagNullIdx = taosHashGet(pStableSchema->tagHash, tagNullName, nameLen + TS_ESCAPE_CHAR_SIZE); if (!pTagNullIdx) { SSchema tagNull = {0}; tagNull.type = TSDB_DATA_TYPE_NCHAR; - tagNull.bytes = 6; - strncpy(tagNull.name, tagNullName, strlen(tagNullName)); + tagNull.bytes = TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE; + strncpy(tagNull.name, tagNullName, nameLen + TS_ESCAPE_CHAR_SIZE); taosArrayPush(pStableSchema->tags, &tagNull); size_t tagNullIdx = taosArrayGetSize(pStableSchema->tags) - 1; - taosHashPut(pStableSchema->tagHash, tagNull.name, strlen(tagNullName), &tagNullIdx, sizeof(tagNullIdx)); + taosHashPut(pStableSchema->tagHash, tagNull.name, nameLen + TS_ESCAPE_CHAR_SIZE, &tagNullIdx, sizeof(tagNullIdx)); } } diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index 317d48ea5987935c5d53af6ad578834071643f26..49ca1e31c5f4fc21beeed169b431f21e8985a642 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -237,6 +237,7 @@ extern int8_t tsDeadLockKillQuery; // schemaless extern char tsDefaultJSONStrType[]; extern char tsSmlChildTableName[]; +extern char tsSmlTagNullName[]; typedef struct { diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 62baaadbac2596bc66bf5955262a3d5ff35fcfc1..83026a3774ab77aa4b5d4998225a4dcc5d10c121 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -291,7 +291,11 @@ int8_t tsDeadLockKillQuery = 0; // default JSON string type char tsDefaultJSONStrType[7] = "nchar"; -char tsSmlChildTableName[TSDB_TABLE_NAME_LEN] = ""; //user defined child table name can be specified in tag value. If set to empty system will generate table name using MD5 hash. +char tsSmlChildTableName[TSDB_TABLE_NAME_LEN] = ""; //user defined child table name can be specified in tag value. + //If set to empty system will generate table name using MD5 hash. +char tsSmlTagNullName[TSDB_COL_NAME_LEN] = "_tag_null"; //for line protocol if tag is omitted, add a tag with NULL value + //to make sure inserted records belongs to the same measurement + //default name is _tag_null and can be user configurable int32_t (*monStartSystemFp)() = NULL; void (*monStopSystemFp)() = NULL; @@ -1701,6 +1705,17 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); + // name for a NULL value tag added for Line Protocol when tag fields are omitted + cfg.option = "smlTagNullName"; + cfg.ptr = tsSmlTagNullName; + cfg.valType = TAOS_CFG_VTYPE_STRING; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = tListLen(tsSmlTagNullName); + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + // flush vnode wal file if walSize > walFlushSize and walSize > cache*0.5*blocks cfg.option = "walFlushSize"; cfg.ptr = &tsdbWalFlushSize;