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

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

上级 4a05b48e
......@@ -5305,10 +5305,10 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in
uint8_t typeVal = TSDB_DATA_JSON_NULL;
tdAddColToKVRow(kvRowBuilder, startColId++, TSDB_DATA_TYPE_JSON, &typeVal, false); // add json type
return TSDB_CODE_SUCCESS;
}else{
int8_t typeVal = TSDB_DATA_JSON_OBJECT;
tdAddColToKVRow(kvRowBuilder, startColId++, TSDB_DATA_TYPE_JSON, &typeVal, false); // add json type
}
int jsonIndex = ++startColId;
int8_t typeVal = TSDB_DATA_JSON_OBJECT;
tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_JSON, &typeVal, false); // add json type
cJSON *root = cJSON_Parse(json);
if (root == NULL){
......@@ -5324,7 +5324,6 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in
int retCode = 0;
SHashObj* keyHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, false);
int jsonIndex = ++startColId;
for(int i = 0; i < size; i++) {
cJSON* item = cJSON_GetArrayItem(root, i);
if (!item) {
......@@ -5394,6 +5393,11 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in
}
}
if(taosHashGetSize(keyHash) == 0){
typeVal = TSDB_DATA_JSON_NULL;
memcpy(kvRowBuilder->buf, &typeVal, CHAR_BYTES);
}
end:
taosHashCleanup(keyHash);
cJSON_Delete(root);
......
......@@ -1178,6 +1178,12 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g
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);
}
SFilterFieldId left = {0}, right = {0};
......
......@@ -1102,7 +1102,7 @@ static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable, bool refSuper
int16_t nCols = kvRowNCols(pTable->tagVal);
ASSERT(nCols%2 == 0);
for (int j = 0; j < nCols; ++j) {
if (j != 0 && j%2 != 0) continue; // jump value
if (j != 0 && j != 1 && j%2 != 0) continue; // jump value
SColIdx * pColIdx = kvRowColIdxAt(pTable->tagVal, j);
void* val = (kvRowColVal(pTable->tagVal, pColIdx));
if (j == 0){ // json value is the first
......@@ -1111,6 +1111,13 @@ static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable, bool refSuper
continue;
}
char nullData[VARSTR_HEADER_SIZE + CHAR_BYTES] = {0};
if( j == 1 && *(uint8_t*)val == TSDB_DATA_JSON_NULL){ // for null json data, add index to jsonKeyMap
varDataSetLen(nullData, CHAR_BYTES);
*(uint8_t*)(varDataVal(nullData)) = TSDB_DATA_JSON_NULL;
val = nullData;
}
char keyMd5[TSDB_MAX_JSON_KEY_MD5_LEN] = {0};
jsonKeyMd5(varDataVal(val), varDataLen(val), keyMd5);
SArray* tablistNew = NULL;
......
......@@ -4087,7 +4087,13 @@ static FORCE_INLINE int32_t tsdbGetJsonTagDataFromId(void *param, int32_t id, ch
if (id == TSDB_TBNAME_COLUMN_INDEX) {
*data = TABLE_NAME(pTable);
} else {
void* jsonData = getJsonTagValue(pTable, name, TSDB_MAX_JSON_KEY_MD5_LEN, NULL);
int16_t colId = 0;
void* jsonData = getJsonTagValue(pTable, name, TSDB_MAX_JSON_KEY_MD5_LEN, &colId);
if(colId == id + 2){ // if find json tag is NULL
if(jsonData != NULL) *data = NULL;
else *data = pTable;
return TSDB_CODE_SUCCESS;
}
// jsonData == NULL for ? operation
if(jsonData != NULL) jsonData += CHAR_BYTES; // jump type
*data = jsonData;
......
......@@ -45,7 +45,7 @@ int taosCheckVersion(char *input_client_version, char *input_server_version, in
char * taosIpStr(uint32_t ipInt);
uint32_t ip2uint(const char *const ip_addr);
void jsonKeyMd5(char *pMsg, int msgLen, void *pKey);
void jsonKeyMd5(void *pMsg, int msgLen, void *pKey);
static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *target) {
MD5_CTX context;
......
......@@ -456,7 +456,7 @@ char *taosIpStr(uint32_t ipInt) {
return ipStr;
}
void jsonKeyMd5(char *pMsg, int msgLen, void *pKey) {
void jsonKeyMd5(void *pMsg, int msgLen, void *pKey) {
MD5_CTX context;
MD5Init(&context);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册