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

TD-6129<feature> support null true false for json tag

上级 c4f9466e
......@@ -4420,7 +4420,7 @@ static int32_t validateLikeExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t
// check for match expression
static int32_t validateJsonTagExpr(tSqlExpr* pExpr, char* msgBuf) {
const char* msg1 = "not support json tag column filter";
const char* msg2 = "tag json key is too long, exceed to 64";
const char* msg2 = "tag json key is invalidate";
const char* msg3 = "tag json key must be string";
tSqlExpr* pLeft = pExpr->pLeft;
......@@ -4430,17 +4430,17 @@ static int32_t validateJsonTagExpr(tSqlExpr* pExpr, char* msgBuf) {
if (pRight != NULL && !IS_VAR_DATA_TYPE(pRight->value.nType))
return invalidOperationMsg(msgBuf, msg3);
if (pRight != NULL && pRight->value.nLen >= TSDB_COL_NAME_LEN)
if (pRight != NULL && (pRight->value.nLen > TSDB_MAX_JSON_KEY_LEN || pRight->value.nLen <= 0))
return invalidOperationMsg(msgBuf, msg2);
} else {
if (pLeft != NULL && pLeft->tokenId == TK_ID && pExpr->tokenId != TK_NULL) {
if (pLeft != NULL && pLeft->tokenId == TK_ID && pExpr->tokenId != TK_ISNULL && pExpr->tokenId != TK_NOTNULL) {
return invalidOperationMsg(msgBuf, msg1);
}
if (pLeft != NULL && pLeft->tokenId == TK_ARROW) {
if (pLeft->pRight && !IS_VAR_DATA_TYPE(pLeft->pRight->value.nType))
return invalidOperationMsg(msgBuf, msg3);
if (pLeft->pRight && pLeft->pRight->value.nLen >= TSDB_COL_NAME_LEN)
if (pLeft->pRight && (pLeft->pRight->value.nLen > TSDB_MAX_JSON_KEY_LEN || pLeft->pRight->value.nLen <= 0))
return invalidOperationMsg(msgBuf, msg2);
}
}
......
......@@ -5210,7 +5210,7 @@ void parseTagValue2Dst(char* result, char* dst){
char tagJsonValue[TSDB_MAX_TAGS_LEN] = {0};
int32_t length = taosUcs4ToMbs(varDataVal(realData),
varDataLen(realData), tagJsonValue);
if (length == 0) {
if (length < 0) {
tscError("charset:%s to %s. val:%s convert json value failed.", DEFAULT_UNICODE_ENCODEC, tsCharset,
(char*)result);
return;
......
......@@ -1161,7 +1161,7 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g
if(pLeft->nodeType == TSQL_NODE_EXPR && pLeft->_node.optr == TSDB_RELATION_ARROW){ // json tag -> operation
assert(info->pTable != NULL);
SSchema* schema = pLeft->_node.pLeft->pSchema;
if(pLeft->_node.pRight->pVal->nLen >= TSDB_MAX_JSON_KEY_LEN) return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
if(pLeft->_node.pRight->pVal->nLen > TSDB_MAX_JSON_KEY_LEN) return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
char keyMd5[TSDB_MAX_JSON_KEY_MD5_LEN] = {0};
jsonKeyMd5(pLeft->_node.pRight->pVal->pz, pLeft->_node.pRight->pVal->nLen, keyMd5);
memcpy(schema->name, keyMd5, TSDB_MAX_JSON_KEY_MD5_LEN);
......@@ -1174,7 +1174,7 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g
pLeft = pLeft->_node.pLeft; // -> operation use left as input
}else if(tree->_node.optr == TSDB_RELATION_QUESTION){
SSchema* schema = pLeft->pSchema;
if(tree->_node.pRight->pVal->nLen >= TSDB_MAX_JSON_KEY_LEN) return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
if(tree->_node.pRight->pVal->nLen > TSDB_MAX_JSON_KEY_LEN) return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
char keyMd5[TSDB_MAX_JSON_KEY_MD5_LEN] = {0};
jsonKeyMd5(tree->_node.pRight->pVal->pz, tree->_node.pRight->pVal->nLen, keyMd5);
memcpy(schema->name, keyMd5, TSDB_MAX_JSON_KEY_MD5_LEN);
......
......@@ -61,9 +61,12 @@ class TDTestCase:
#tdSql.error("select * from db_json_tag_test.jsons1 where jtag->'location'=4")
tdSql.error("select * from db_json_tag_test.jsons1 where jtag->location='beijing'")
tdSql.error("select * from db_json_tag_test.jsons1 where jtag->'location'")
tdSql.error("select * from db_json_tag_test.jsons1 where jtag->''")
tdSql.error("select * from db_json_tag_test.jsons1 where jtag->''=9")
tdSql.error("select jtag->location from db_json_tag_test.jsons1")
tdSql.error("select jtag?location from db_json_tag_test.jsons1")
tdSql.error("select * from db_json_tag_test.jsons1 where jtag?location")
tdSql.error("select * from db_json_tag_test.jsons1 where jtag?''")
tdSql.error("select * from db_json_tag_test.jsons1 where jtag?'location'='beijing'")
# test select condition
......@@ -170,12 +173,33 @@ class TDTestCase:
tdSql.error("CREATE TABLE if not exists db_json_tag_test.jsons1_5 using db_json_tag_test.jsons1 tags('efwewf')")
tdSql.error("CREATE TABLE if not exists db_json_tag_test.jsons1_5 using db_json_tag_test.jsons1 tags('\t')")
tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_6 using db_json_tag_test.jsons1 tags('')")
tdSql.query("select jtag from db_json_tag_test.jsons1_6")
tdSql.checkData(0, 0, "NULL")
tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_7 using db_json_tag_test.jsons1 tags('{}')")
tdSql.query("select jtag from db_json_tag_test.jsons1_7")
tdSql.checkData(0, 0, "NULL")
tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_8 using db_json_tag_test.jsons1 tags('null')")
tdSql.query("select jtag from db_json_tag_test.jsons1_8")
tdSql.checkData(0, 0, "NULL")
tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_9 using db_json_tag_test.jsons1 tags('{\"\":4, \"time\":null}')")
tdSql.query("select jtag from db_json_tag_test.jsons1_9")
tdSql.checkData(0, 0, "NULL")
tdSql.execute("CREATE TABLE if not exists db_json_tag_test.jsons1_10 using db_json_tag_test.jsons1 tags('{\"k1\":\"\",\"k1\":\"v1\",\"k2\":true,\"k3\":false,\"k4\":55}')")
tdSql.query("select * from db_json_tag_test.jsons1 where datastr match 'json and jtag->'location' match 'jin'")
tdSql.checkRows(2)
tdSql.query("select jtag from db_json_tag_test.jsons1_10")
tdSql.checkData(0, 0, "{\"k1\":\"\",\"k2\":true,\"k3\":false,\"k4\":55}")
tdSql.query("select jtag->'k2' from db_json_tag_test.jsons1_10")
tdSql.checkData(0, 0, "true")
tdSql.query("select jtag from db_json_tag_test.jsons1 where jtag->'k1'=''")
tdSql.checkRows(1)
tdSql.query("select jtag from db_json_tag_test.jsons1 where jtag->'k2'=true")
tdSql.checkRows(1)
def stop(self):
tdSql.close()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册