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

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

上级 01f6add4
......@@ -4371,7 +4371,7 @@ static int32_t validateNullExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t
if (pRight->tokenId == TK_STRING) {
SSchema* pSchema = tscGetTableSchema(pTableMeta);
if (IS_VAR_DATA_TYPE(pSchema[index].type)) {
if (IS_VAR_DATA_TYPE(pSchema[index].type) || pSchema[index].type == TSDB_DATA_TYPE_JSON) {
return TSDB_CODE_SUCCESS;
}
......
......@@ -288,10 +288,10 @@ int32_t* taosGetErrno();
#define TSDB_CODE_QRY_INCONSISTAN TAOS_DEF_ERROR_CODE(0, 0x070C) //"File inconsistency in replica")
#define TSDB_CODE_QRY_INVALID_TIME_CONDITION TAOS_DEF_ERROR_CODE(0, 0x070D) //"invalid time condition")
#define TSDB_CODE_QRY_SYS_ERROR TAOS_DEF_ERROR_CODE(0, 0x070E) //"System error")
//#define TSDB_CODE_QRY_JSON_KEY_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x070F) //"json tag key not exist")
#define TSDB_CODE_QRY_JSON_SUPPORT_ERROR TAOS_DEF_ERROR_CODE(0, 0x070F) //"only support is [not] null")
#define TSDB_CODE_QRY_JSON_KEY_TYPE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0710) //"json tag key type not match")
#define TSDB_CODE_QRY_JSON_KEY_NOT_STR_ERROR TAOS_DEF_ERROR_CODE(0, 0x0711) //"json tag key must be string in match/nmatch")
#define TSDB_CODE_QRY_JSON_INVALID_EXP TAOS_DEF_ERROR_CODE(0, 0x0712) // "invalid regular expression")
// grant
#define TSDB_CODE_GRANT_EXPIRED TAOS_DEF_ERROR_CODE(0, 0x0800) //"License expired")
#define TSDB_CODE_GRANT_DNODE_LIMITED TAOS_DEF_ERROR_CODE(0, 0x0801) //"DNode creation limited by licence")
......
......@@ -1154,8 +1154,6 @@ _return:
return code;
}
int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *group) {
tExprNode* pLeft = tree->_node.pLeft;
if(pLeft->nodeType == TSQL_NODE_EXPR && pLeft->_node.optr == TSDB_RELATION_ARROW){ // json tag -> operation
......@@ -1172,19 +1170,41 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g
assert(schema->type > TSDB_DATA_TYPE_NULL && schema->type < TSDB_DATA_TYPE_JSON);
}
pLeft = pLeft->_node.pLeft; // -> operation use left as input
if (IS_VAR_DATA_TYPE(tree->_node.pRight->pVal->nType)) {
schema = pLeft->pSchema;
if (!IS_VAR_DATA_TYPE(schema->type)) {
char *v = strndup(tree->_node.pRight->pVal->pz, tree->_node.pRight->pVal->nLen);
uint32_t type = 0;
tGetToken(v, &type);
if (type == TK_NULL) {
free(v);
return TSDB_CODE_QRY_JSON_SUPPORT_ERROR;
}
free(v);
}
}
}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;
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);
}else if(tree->_node.optr == TSDB_RELATION_ISNULL || tree->_node.optr == TSDB_RELATION_NOTNULL){
SSchema* schema = pLeft->pSchema;
char keyMd5[TSDB_MAX_JSON_KEY_MD5_LEN] = {0};
uint8_t nullData = TSDB_DATA_JSON_NULL;
jsonKeyMd5(&nullData, 1, keyMd5);
memcpy(schema->name, keyMd5, TSDB_MAX_JSON_KEY_MD5_LEN);
}
SSchema* schema = pLeft->pSchema;
if(schema->type == TSDB_DATA_TYPE_JSON) {
if(tree->_node.optr == TSDB_RELATION_ISNULL || tree->_node.optr == TSDB_RELATION_NOTNULL){
char keyMd5[TSDB_MAX_JSON_KEY_MD5_LEN] = {0};
uint8_t nullData = TSDB_DATA_JSON_NULL;
jsonKeyMd5(&nullData, 1, keyMd5);
memcpy(schema->name, keyMd5, TSDB_MAX_JSON_KEY_MD5_LEN);
}else if(tree->_node.optr == TSDB_RELATION_MATCH || tree->_node.optr == TSDB_RELATION_NMATCH || tree->_node.optr == TSDB_RELATION_LIKE){
if(!IS_VAR_DATA_TYPE(schema->type)){
return TSDB_CODE_QRY_JSON_INVALID_EXP;
}
}
}
SFilterFieldId left = {0}, right = {0};
filterAddFieldFromNode(info, pLeft, &left);
......
......@@ -294,9 +294,10 @@ TAOS_DEFINE_ERROR(TSDB_CODE_QRY_NOT_ENOUGH_BUFFER, "Query buffer limit ha
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INCONSISTAN, "File inconsistance in replica")
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_TIME_CONDITION, "One valid time range condition expected")
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_SYS_ERROR, "System error")
//TAOS_DEFINE_ERROR(TSDB_CODE_QRY_JSON_KEY_NOT_EXIST, "json tag key not exist")
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_JSON_SUPPORT_ERROR, "only support is [not] null")
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_JSON_KEY_TYPE_ERROR, "json tag key type not match")
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_JSON_KEY_NOT_STR_ERROR, "json tag key must be string in match/nmatch")
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_JSON_INVALID_EXP, "invalid regular expression")
// grant
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, "License expired")
......
......@@ -145,6 +145,8 @@ 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%'")
# test where condition in
tdSql.query("select * from db_json_tag_test.jsons1 where jtag->'location' in ('beijing')")
tdSql.checkRows(2)
......@@ -169,7 +171,7 @@ class TDTestCase:
tdSql.error("select * from db_json_tag_test.jsons1 where jtag->'num' match '5'")
# test json
# 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')")
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('')")
......@@ -207,6 +209,12 @@ class TDTestCase:
tdSql.query("select jtag from db_json_tag_test.jsons1 where jtag is not null")
tdSql.checkRows(5)
#tdSql.query("select * from db_json_tag_test.jsons1 where jtag->'location'='null'")
#tdSql.checkRows(5)
#tdSql.query("select * from db_json_tag_test.jsons1 where jtag->'num'='null'")
#tdSql.checkRows(5)
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册