From 7cb90161378fcc3c527e381a26776c40492e038b Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 15 Oct 2021 10:53:14 +0800 Subject: [PATCH] TD-6129 match/nmatch support for nchar --- src/client/src/tscSQLParser.c | 8 +------- src/query/src/qFilter.c | 23 +++++++++++++++++++++-- src/tsdb/src/tsdbRead.c | 3 ++- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 942ff603dc..0948d013ac 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4453,7 +4453,6 @@ static int32_t validateMatchExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_ const char* msg1 = "regular expression string should be less than %d characters"; const char* msg2 = "illegal column type for match/nmatch"; const char* msg3 = "invalid regular expression"; - const char* msg4 = "json column type must encode by binary for match/nmatch"; tSqlExpr* pLeft = pExpr->pLeft; tSqlExpr* pRight = pExpr->pRight; @@ -4466,15 +4465,10 @@ static int32_t validateMatchExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_ } SSchema* pSchema = tscGetTableSchema(pTableMeta); - if ((pLeft->tokenId != TK_ARROW) && (!isTablenameToken(&pLeft->columnName)) - && (pSchema[index].type != TSDB_DATA_TYPE_BINARY)) { + if ((!isTablenameToken(&pLeft->columnName)) && (pSchema[index].type != TSDB_DATA_TYPE_BINARY)) { return invalidOperationMsg(msgBuf, msg2); } - if(pLeft->tokenId == TK_ARROW && pSchema[index].type == TSDB_DATA_TYPE_JSON){ - return invalidOperationMsg(msgBuf, msg4); - } - if (!(pRight->type == SQL_NODE_VALUE && pRight->value.nType == TSDB_DATA_TYPE_BINARY)) { return invalidOperationMsg(msgBuf, msg3); } diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index fdd9ef59cb..a132ffe536 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -2989,8 +2989,18 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SDataStat all = false; continue; } + // match nchar - (*p)[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, colData, info->cunits[uidx].valData); + if(info->cunits[uidx].dataType == TSDB_DATA_TYPE_NCHAR && (info->cunits[uidx].optr == TSDB_RELATION_MATCH || info->cunits[uidx].optr == TSDB_RELATION_NMATCH)){ + char newColData[TSDB_REGEX_STRING_DEFAULT_LEN * TSDB_NCHAR_SIZE] = {0}; + char newValData[TSDB_REGEX_STRING_DEFAULT_LEN * TSDB_NCHAR_SIZE] = {0}; + taosUcs4ToMbs(varDataVal(colData), varDataLen(colData), newColData); + taosUcs4ToMbs(varDataVal(info->cunits[uidx].valData), varDataLen(info->cunits[uidx].valData), newValData); + + (*p)[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, newColData, newValData); + }else{ + (*p)[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, colData, info->cunits[uidx].valData); + } if ((*p)[i] == 0) { all = false; @@ -3038,7 +3048,16 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SDataStatis * } else if (cunit->rfunc >= 0) { (*p)[i] = (*gRangeCompare[cunit->rfunc])(colData, colData, cunit->valData, cunit->valData2, gDataCompare[cunit->func]); } else { - (*p)[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData); + if(cunit->dataType == TSDB_DATA_TYPE_NCHAR && (cunit->optr == TSDB_RELATION_MATCH || cunit->optr == TSDB_RELATION_NMATCH)){ + char newColData[TSDB_REGEX_STRING_DEFAULT_LEN * TSDB_NCHAR_SIZE] = {0}; + char newValData[TSDB_REGEX_STRING_DEFAULT_LEN * TSDB_NCHAR_SIZE] = {0}; + taosUcs4ToMbs(varDataVal(colData), varDataLen(colData), newColData); + taosUcs4ToMbs(varDataVal(cunit->valData), varDataLen(cunit->valData), newValData); + + (*p)[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, newColData, newValData); + }else{ + (*p)[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData); + } } //FILTER_UNIT_SET_R(info, uidx, p[i]); diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 32ce603366..1e230dad49 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -4088,7 +4088,8 @@ static FORCE_INLINE int32_t tsdbGetJsonTagDataFromId(void *param, int32_t id, ch *data = TABLE_NAME(pTable); } else { void* jsonData = getJsonTagValue(pTable, name, TSDB_MAX_JSON_KEY_MD5_LEN, NULL); - if (jsonData != NULL) jsonData += CHAR_BYTES; // jump type + assert(jsonData != NULL); + jsonData += CHAR_BYTES; // jump type *data = jsonData; } -- GitLab