提交 7a7d49d3 编写于 作者: wmmhello's avatar wmmhello

enable different value type of the same key in json

上级 d62844be
......@@ -4716,6 +4716,7 @@ static int32_t validateJsonTagExpr(tSqlExpr* pExpr, char* msgBuf) {
const char* msg1 = "not support json tag column filter";
const char* msg2 = "tag json key is invalidate";
const char* msg3 = "tag json key must be string";
const char* msg4 = "in operation not support in tag json";
tSqlExpr* pLeft = pExpr->pLeft;
tSqlExpr* pRight = pExpr->pRight;
......@@ -4726,6 +4727,8 @@ static int32_t validateJsonTagExpr(tSqlExpr* pExpr, char* msgBuf) {
if (pRight != NULL && (pRight->value.nLen > TSDB_MAX_JSON_KEY_LEN || pRight->value.nLen <= 0))
return invalidOperationMsg(msgBuf, msg2);
} else if(pExpr->tokenId == TK_IN){
return invalidOperationMsg(msgBuf, msg4);
} else {
if (pLeft != NULL && pLeft->tokenId == TK_ID && pExpr->tokenId != TK_ISNULL && pExpr->tokenId != TK_NOTNULL) {
return invalidOperationMsg(msgBuf, msg1);
......
......@@ -234,6 +234,8 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
comparFn = 19;
} else if (optr == TSDB_RELATION_NMATCH) {
comparFn = 20;
} else if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */
comparFn = 9;
} else if (optr == TSDB_RELATION_QUESTION) {
comparFn = 21;
} else {
......@@ -3061,6 +3063,19 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SDataStat
(*p)[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, newColData, newValData);
tfree(newColData);
}
}else if(info->cunits[uidx].optr == TSDB_RELATION_LIKE){
uint8_t jsonType = *(char*)colData;
char* realData = colData + CHAR_BYTES;
if (jsonType != TSDB_DATA_TYPE_NCHAR){
(*p)[i] = false;
}else{
tVariant* val = info->cunits[uidx].valData;
char* newValData = calloc(val->nLen + VARSTR_HEADER_SIZE, 1);
memcpy(varDataVal(newValData), val->pz, val->nLen);
varDataSetLen(newValData, val->nLen);
(*p)[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, realData, newValData);
tfree(newValData);
}
}else{
(*p)[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, colData, info->cunits[uidx].valData);
}
......@@ -3138,6 +3153,19 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SDataStatis *
(*p)[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, newColData, newValData);
tfree(newColData);
}
}else if(cunit->optr == TSDB_RELATION_LIKE){
uint8_t jsonType = *(char*)colData;
char* realData = colData + CHAR_BYTES;
if (jsonType != TSDB_DATA_TYPE_NCHAR){
(*p)[i] = false;
}else{
tVariant* val = cunit->valData;
char* newValData = calloc(val->nLen + VARSTR_HEADER_SIZE, 1);
memcpy(varDataVal(newValData), val->pz, val->nLen);
varDataSetLen(newValData, val->nLen);
(*p)[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, realData, newValData);
tfree(newValData);
}
}else{
(*p)[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData);
}
......
......@@ -540,6 +540,8 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
comparFn = compareStrRegexCompMatch;
} else if (optr == TSDB_RELATION_NMATCH) {
comparFn = compareStrRegexCompNMatch;
} else if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */
comparFn = compareWStrPatternComp;
} else if (optr == TSDB_RELATION_QUESTION) {
comparFn = compareStrContainJson;
} else {
......
......@@ -142,20 +142,14 @@ class TDTestCase:
tdSql.query("select *,tbname from db_json_tag_test.jsons1 where (jtag->'location' like 'bei%' or jtag->'num'=34) and jtag->'class'=55")
tdSql.checkRows(0)
tdSql.error("select * from db_json_tag_test.jsons1 where jtag->'num' like '5%'")
tdSql.query("select * from db_json_tag_test.jsons1 where jtag->'num' like '5%'")
tdSql.checkRows(0)
# test where condition in
tdSql.query("select * from db_json_tag_test.jsons1 where jtag->'location' in ('beijing')")
tdSql.checkRows(2)
tdSql.query("select * from db_json_tag_test.jsons1 where jtag->'num' in (5,34)")
tdSql.checkRows(2)
tdSql.error("select * from db_json_tag_test.jsons1 where jtag->'location' in ('beijing')")
tdSql.error("select * from db_json_tag_test.jsons1 where jtag->'num' in ('5',34)")
tdSql.query("select * from db_json_tag_test.jsons1 where jtag->'location' in ('shanghai') and jtag->'class'=55")
tdSql.checkRows(1)
# test where condition match
tdSql.query("select * from db_json_tag_test.jsons1 where jtag->'location' match 'jin$'")
tdSql.checkRows(0)
......@@ -166,7 +160,8 @@ class TDTestCase:
tdSql.query("select * from db_json_tag_test.jsons1 where datastr match 'json' and jtag->'location' match 'jin'")
tdSql.checkRows(2)
tdSql.error("select * from db_json_tag_test.jsons1 where jtag->'num' match '5'")
tdSql.query("select * from db_json_tag_test.jsons1 where jtag->'num' match '5'")
tdSql.checkRows(0)
# test json string parse
tdSql.error("CREATE TABLE if not exists db_json_tag_test.jsons1_5 using db_json_tag_test.jsons1 tags('efwewf')")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册