From 9b0ca45eb252a4e6c593e4be4b1533b69518ec45 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 10 Nov 2021 17:28:15 +0800 Subject: [PATCH] [TD-10897]: SchemaLess : Schemaless will auto convert Convert uppercase letters to lowercase --- src/client/src/tscParseLineProtocol.c | 39 +++++++++------------------ src/client/src/tscPrepare.c | 2 +- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index af57f7ec8c..0ce76e8453 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -261,10 +261,10 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint, static int32_t generateSchemaAction(SSchema* pointColField, SHashObj* dbAttrHash, SArray* dbAttrArray, bool isTag, char sTableName[], SSchemaAction* action, bool* actionNeeded, SSmlLinesInfo* info) { - char fieldNameLowerCase[TSDB_COL_NAME_LEN + TS_ESCAPE_CHAR_SIZE] = {0}; - strtolower(fieldNameLowerCase, pointColField->name); + char fieldName[TSDB_COL_NAME_LEN + TS_ESCAPE_CHAR_SIZE] = {0}; + strcpy(fieldName, pointColField->name); - size_t* pDbIndex = taosHashGet(dbAttrHash, fieldNameLowerCase, strlen(fieldNameLowerCase)); + size_t* pDbIndex = taosHashGet(dbAttrHash, fieldName, strlen(fieldName)); if (pDbIndex) { SSchema* dbAttr = taosArrayGet(dbAttrArray, *pDbIndex); assert(strcasecmp(dbAttr->name, pointColField->name) == 0); @@ -297,7 +297,7 @@ static int32_t generateSchemaAction(SSchema* pointColField, SHashObj* dbAttrHash *actionNeeded = true; } if (*actionNeeded) { - tscDebug("SML:0x%" PRIx64 " generate schema action. column name: %s, action: %d", info->id, fieldNameLowerCase, + tscDebug("SML:0x%" PRIx64 " generate schema action. column name: %s, action: %d", info->id, fieldName, action->action); } return 0; @@ -536,11 +536,8 @@ static int32_t retrieveTableMeta(TAOS* taos, char* tableName, STableMeta** pTabl tscDebug("SML:0x%" PRIx64 " retrieve table meta. super table name: %s", info->id, tableName); - char tableNameLowerCase[TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE]; - strtolower(tableNameLowerCase, tableName); - char sql[256]; - snprintf(sql, 256, "describe %s", tableNameLowerCase); + snprintf(sql, 256, "describe %s", tableName); TAOS_RES* res = taos_query(taos, sql); code = taos_errno(res); if (code != 0) { @@ -561,8 +558,10 @@ static int32_t retrieveTableMeta(TAOS* taos, char* tableName, STableMeta** pTabl pSql->fp = NULL; registerSqlObj(pSql); - SStrToken tableToken = {.z = tableNameLowerCase, .n = (uint32_t)strlen(tableNameLowerCase), .type = TK_ID}; - tGetToken(tableNameLowerCase, &tableToken.type); + char tableNameBuf[TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE]; + memcpy(tableNameBuf, tableName, strlen(tableName)); + SStrToken tableToken = {.z = tableNameBuf, .n = (uint32_t)strlen(tableName), .type = TK_ID}; + tGetToken(tableNameBuf, &tableToken.type); bool dbIncluded = false; // Check if the table name available or not if (tscValidateName(&tableToken, true, &dbIncluded) != TSDB_CODE_SUCCESS) { @@ -1870,24 +1869,14 @@ static int32_t parseSmlTimeStamp(TAOS_SML_KV **pTS, const char **index, SSmlLine bool checkDuplicateKey(char *key, SHashObj *pHash, SSmlLinesInfo* info) { char *val = NULL; - char *cur = key; - char keyLower[TSDB_COL_NAME_LEN]; - size_t keyLen = 0; - while(*cur != '\0') { - keyLower[keyLen] = tolower(*cur); - keyLen++; - cur++; - } - keyLower[keyLen] = '\0'; - - val = taosHashGet(pHash, keyLower, keyLen); + val = taosHashGet(pHash, key, strlen(key)); if (val) { - tscError("SML:0x%"PRIx64" Duplicate key detected:%s", info->id, keyLower); + tscError("SML:0x%"PRIx64" Duplicate key detected:%s", info->id, key); return true; } uint8_t dummy_val = 0; - taosHashPut(pHash, keyLower, strlen(key), &dummy_val, sizeof(uint8_t)); + taosHashPut(pHash, key, strlen(key), &dummy_val, sizeof(uint8_t)); return false; } @@ -1925,7 +1914,6 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash pKV->key = calloc(len + TS_ESCAPE_CHAR_SIZE + 1, 1); memcpy(pKV->key, key, len + 1); - strntolower_s(pKV->key, pKV->key, (int32_t)len); addEscapeCharToString(pKV->key, len); tscDebug("SML:0x%"PRIx64" Key:%s|len:%d", info->id, pKV->key, len); *index = cur + 1; @@ -2053,7 +2041,7 @@ static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index if (*cur == '\\') { escapeSpecialCharacter(1, &cur); } - pSml->stableName[len] = tolower(*cur); + pSml->stableName[len] = *cur; cur++; len++; } @@ -2129,7 +2117,6 @@ static int32_t parseSmlKvPairs(TAOS_SML_KV **pKVs, int *num_kvs, if (!isField && childTableNameLen != 0 && strcasecmp(pkv->key, childTableName) == 0) { smlData->childTableName = malloc(pkv->length + TS_ESCAPE_CHAR_SIZE + 1); memcpy(smlData->childTableName, pkv->value, pkv->length); - strntolower_s(smlData->childTableName, smlData->childTableName, (int32_t)pkv->length); addEscapeCharToString(smlData->childTableName, (int32_t)pkv->length); free(pkv->key); free(pkv->value); diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 04dd7f57ca..c069a0267c 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -1573,7 +1573,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { pRes->qId = 0; pRes->numOfRows = 0; - strtolower(pSql->sqlstr, sql); + strcpy(pSql->sqlstr, sql); tscDebugL("0x%"PRIx64" SQL: %s", pSql->self, pSql->sqlstr); if (tscIsInsertData(pSql->sqlstr)) { -- GitLab