fix: fix error in json and add test cases for json
This commit is contained in:
parent
bae49baa98
commit
0232394386
|
@ -105,8 +105,6 @@ int32_t compareStrPatternNotMatch(const void *pLeft, const void *pRight);
|
|||
int32_t compareWStrPatternMatch(const void *pLeft, const void *pRight);
|
||||
int32_t compareWStrPatternNotMatch(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareJsonContainsKey(const void *pLeft, const void *pRight);
|
||||
|
||||
__compar_fn_t getComparFunc(int32_t type, int32_t optr);
|
||||
__compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order);
|
||||
int32_t doCompare(const char *a, const char *b, int32_t type, size_t size);
|
||||
|
|
|
@ -64,6 +64,7 @@ static SKeyword keywordTable[] = {
|
|||
{"CONSUMER", TK_CONSUMER},
|
||||
{"COUNT", TK_COUNT},
|
||||
{"CREATE", TK_CREATE},
|
||||
{"CONTAINS", TK_CONTAINS},
|
||||
{"DATABASE", TK_DATABASE},
|
||||
{"DATABASES", TK_DATABASES},
|
||||
{"DAYS", TK_DAYS},
|
||||
|
|
|
@ -847,8 +847,12 @@ static EDealRes translateJsonOperator(STranslateContext* pCxt, SOperatorNode* pO
|
|||
if (TSDB_DATA_TYPE_JSON != ldt.type || TSDB_DATA_TYPE_BINARY != rdt.type) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName);
|
||||
}
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_JSON;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_JSON].bytes;
|
||||
if(pOp->opType == OP_TYPE_JSON_GET_VALUE){
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_JSON;
|
||||
}else if(pOp->opType == OP_TYPE_JSON_CONTAINS){
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_BOOL;
|
||||
}
|
||||
pOp->node.resType.bytes = tDataTypes[pOp->node.resType.type].bytes;
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ __compar_fn_t gDataCompare[] = {compareInt32Val, compareInt8Val, compareInt16Val
|
|||
compareLenPrefixedWStr, compareUint8Val, compareUint16Val, compareUint32Val, compareUint64Val,
|
||||
setChkInBytes1, setChkInBytes2, setChkInBytes4, setChkInBytes8, compareStrRegexCompMatch,
|
||||
compareStrRegexCompNMatch, setChkNotInBytes1, setChkNotInBytes2, setChkNotInBytes4, setChkNotInBytes8,
|
||||
compareChkNotInString, compareStrPatternNotMatch, compareWStrPatternNotMatch, compareJsonContainsKey
|
||||
compareChkNotInString, compareStrPatternNotMatch, compareWStrPatternNotMatch
|
||||
};
|
||||
|
||||
int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
|
||||
|
|
|
@ -944,6 +944,31 @@ STagVal getJsonValue(char *json, char *key, bool *isExist) {
|
|||
return val;
|
||||
}
|
||||
|
||||
void vectorJsonContains(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
|
||||
SColumnInfoData *pOutputCol = pOut->columnData;
|
||||
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1;
|
||||
|
||||
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
|
||||
|
||||
char *pRightData = colDataGetVarData(pRight->columnData, 0);
|
||||
char *jsonKey = taosMemoryCalloc(1, varDataLen(pRightData) + 1);
|
||||
memcpy(jsonKey, varDataVal(pRightData), varDataLen(pRightData));
|
||||
for (; i >= 0 && i < pLeft->numOfRows; i += step) {
|
||||
bool isExist = false;
|
||||
|
||||
if (!colDataIsNull_var(pLeft->columnData, i)) {
|
||||
char *pLeftData = colDataGetVarData(pLeft->columnData, i);
|
||||
getJsonValue(pLeftData, jsonKey, &isExist);
|
||||
}
|
||||
|
||||
colDataAppend(pOutputCol, i, (const char*)(&isExist), false);
|
||||
|
||||
}
|
||||
taosMemoryFree(jsonKey);
|
||||
}
|
||||
|
||||
void vectorJsonArrow(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
|
||||
SColumnInfoData *pOutputCol = pOut->columnData;
|
||||
|
||||
|
|
|
@ -222,11 +222,6 @@ int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight) {
|
|||
return compareLenPrefixedWStr(pRight, pLeft);
|
||||
}
|
||||
|
||||
int32_t compareJsonContainsKey(const void* pLeft, const void* pRight) {
|
||||
if(pLeft) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// string > number > bool > null
|
||||
// ref: https://dev.mysql.com/doc/refman/8.0/en/json.html#json-comparison
|
||||
int32_t compareJsonVal(const void *pLeft, const void *pRight) {
|
||||
|
|
Loading…
Reference in New Issue