feat: add sort/group logic for json
This commit is contained in:
parent
020372cc75
commit
30b8bd1b16
|
@ -30,7 +30,8 @@ OptrStr gOptrStr[] = {
|
|||
{OP_TYPE_MULTI, "*"},
|
||||
{OP_TYPE_DIV, "/"},
|
||||
{OP_TYPE_MOD, "%"},
|
||||
|
||||
{OP_TYPE_MINUS, "minus"},
|
||||
{OP_TYPE_ASSIGN, "assign"},
|
||||
// bit operator
|
||||
{OP_TYPE_BIT_AND, "&"},
|
||||
{OP_TYPE_BIT_OR, "|"},
|
||||
|
|
|
@ -452,13 +452,13 @@ double getVectorDoubleValue_JSON(void *src, int32_t index){
|
|||
return out;
|
||||
}
|
||||
|
||||
void convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t typeRight, char **pLeftData, char **pRightData, void *pLeftOut, void *pRightOut, bool *isNull){
|
||||
bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t typeRight, char **pLeftData, char **pRightData, void *pLeftOut, void *pRightOut, bool *isNull){
|
||||
if(optr == OP_TYPE_JSON_CONTAINS) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(typeLeft != TSDB_DATA_TYPE_JSON && typeRight != TSDB_DATA_TYPE_JSON){
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(typeLeft == TSDB_DATA_TYPE_JSON){
|
||||
|
@ -469,15 +469,22 @@ void convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t
|
|||
typeRight = **pRightData;
|
||||
(*pRightData) ++;
|
||||
}
|
||||
|
||||
if(optr == OP_TYPE_LIKE || optr == OP_TYPE_NOT_LIKE || optr == OP_TYPE_MATCH || optr == OP_TYPE_NMATCH){
|
||||
if(typeLeft != TSDB_DATA_TYPE_NCHAR && typeLeft != TSDB_DATA_TYPE_BINARY){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(typeLeft == TSDB_DATA_TYPE_NULL || typeRight == TSDB_DATA_TYPE_NULL){
|
||||
*isNull = true;
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
int8_t type = vectorGetConvertType(typeLeft, typeRight);
|
||||
|
||||
if(type == 0) {
|
||||
*fp = filterGetCompFunc(typeLeft, optr);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
*fp = filterGetCompFunc(type, optr);
|
||||
|
@ -497,6 +504,7 @@ void convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t
|
|||
convertNumberToNumber(*pRightData, pRightOut, typeRight, type);
|
||||
*pRightData = pRightOut;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t vectorConvertToVarData(const SScalarParam* pIn, SScalarParam* pOut, int16_t inType, int16_t outType) {
|
||||
|
@ -1533,12 +1541,16 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *
|
|||
int64_t leftOut = 0;
|
||||
int64_t rightOut = 0;
|
||||
bool isJsonnull = false;
|
||||
convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData, &leftOut, &rightOut, &isJsonnull);
|
||||
bool result = convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData, &leftOut, &rightOut, &isJsonnull);
|
||||
if(isJsonnull){
|
||||
ASSERT(0);
|
||||
}
|
||||
bool res = filterDoCompare(fp, optr, pLeftData, pRightData);
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);
|
||||
if(!result){
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&result);
|
||||
}else{
|
||||
bool res = filterDoCompare(fp, optr, pLeftData, pRightData);
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);
|
||||
}
|
||||
}
|
||||
} else if (pRight->numOfRows == 1) {
|
||||
ASSERT(pLeft->pHashFilter == NULL);
|
||||
|
@ -1554,12 +1566,16 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *
|
|||
int64_t leftOut = 0;
|
||||
int64_t rightOut = 0;
|
||||
bool isJsonnull = false;
|
||||
convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData, &leftOut, &rightOut, &isJsonnull);
|
||||
bool result = convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData, &leftOut, &rightOut, &isJsonnull);
|
||||
if(isJsonnull){
|
||||
ASSERT(0);
|
||||
}
|
||||
bool res = filterDoCompare(fp, optr, pLeftData, pRightData);
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);
|
||||
if(!result){
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&result);
|
||||
}else{
|
||||
bool res = filterDoCompare(fp, optr, pLeftData, pRightData);
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);
|
||||
}
|
||||
}
|
||||
} else if (pLeft->numOfRows == 1) {
|
||||
for (; i >= 0 && i < pRight->numOfRows; i += step) {
|
||||
|
@ -1574,12 +1590,16 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *
|
|||
int64_t leftOut = 0;
|
||||
int64_t rightOut = 0;
|
||||
bool isJsonnull = false;
|
||||
convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData, &leftOut, &rightOut, &isJsonnull);
|
||||
bool result = convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData, &leftOut, &rightOut, &isJsonnull);
|
||||
if(isJsonnull){
|
||||
ASSERT(0);
|
||||
}
|
||||
bool res = filterDoCompare(fp, optr, pLeftData, pRightData);
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);
|
||||
if(!result){
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&result);
|
||||
}else{
|
||||
bool res = filterDoCompare(fp, optr, pLeftData, pRightData);
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1382,7 +1382,7 @@ TEST(columnTest, json_column_logic_op) {
|
|||
printf("--------------------json int-- -10 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
|
||||
|
||||
key = "k6";
|
||||
bool eRes5[len+len1] = {false, false, true, true, false, true, false, true, true, false, false, false, true};
|
||||
bool eRes5[len+len1] = {false, false, true, true, false, true, false, true, true, false, false, false, false};
|
||||
for(int i = 0; i < len; i++){
|
||||
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes5[i], op[i], false);
|
||||
}
|
||||
|
@ -1411,7 +1411,7 @@ TEST(columnTest, json_column_logic_op) {
|
|||
|
||||
for(int i = len; i < len + len1; i++){
|
||||
void* rightData = prepareNchar(inputNchar[i-len]);
|
||||
makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes5[i], op[i], false);
|
||||
makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes6[i], op[i], false);
|
||||
taosMemoryFree(rightData);
|
||||
}
|
||||
|
||||
|
@ -1430,7 +1430,7 @@ TEST(columnTest, json_column_logic_op) {
|
|||
|
||||
for(int i = len; i < len + len1; i++){
|
||||
void* rightData = prepareNchar(inputNchar[i-len]);
|
||||
makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes5[i], op[i], false);
|
||||
makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes7[i], op[i], false);
|
||||
taosMemoryFree(rightData);
|
||||
}
|
||||
|
||||
|
@ -1438,7 +1438,7 @@ TEST(columnTest, json_column_logic_op) {
|
|||
printf("--------------------json string-- 6.6hello {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
|
||||
|
||||
key = "k9";
|
||||
bool eRes8[len+len1] = {true, false, false, false, false, true, false, true, true, false, true, true, true};
|
||||
bool eRes8[len+len1] = {true, false, false, false, false, true, false, true, true, false, true, false, true};
|
||||
for(int i = 0; i < len; i++){
|
||||
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes8[i], op[i], false);
|
||||
}
|
||||
|
@ -1449,7 +1449,7 @@ TEST(columnTest, json_column_logic_op) {
|
|||
|
||||
for(int i = len; i < len + len1; i++){
|
||||
void* rightData = prepareNchar(inputNchar[i-len]);
|
||||
makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes5[i], op[i], false);
|
||||
makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes8[i], op[i], false);
|
||||
taosMemoryFree(rightData);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue