feature/qnode

This commit is contained in:
dapan1121 2022-02-23 14:34:17 +08:00
parent b5982c5c3d
commit aa556cb462
14 changed files with 309 additions and 326 deletions

View File

@ -81,45 +81,6 @@ typedef struct SValueNode {
} datum; } datum;
} SValueNode; } SValueNode;
typedef enum EOperatorType {
// arithmetic operator
OP_TYPE_ADD = 1,
OP_TYPE_SUB,
OP_TYPE_MULTI,
OP_TYPE_DIV,
OP_TYPE_MOD,
// bit operator
OP_TYPE_BIT_AND,
OP_TYPE_BIT_OR,
// comparison operator
OP_TYPE_GREATER_THAN,
OP_TYPE_GREATER_EQUAL,
OP_TYPE_LOWER_THAN,
OP_TYPE_LOWER_EQUAL,
OP_TYPE_EQUAL,
OP_TYPE_NOT_EQUAL,
OP_TYPE_IN,
OP_TYPE_NOT_IN,
OP_TYPE_LIKE,
OP_TYPE_NOT_LIKE,
OP_TYPE_MATCH,
OP_TYPE_NMATCH,
OP_TYPE_IS_NULL,
OP_TYPE_IS_NOT_NULL,
OP_TYPE_IS_TRUE,
OP_TYPE_IS_FALSE,
OP_TYPE_IS_UNKNOWN,
OP_TYPE_IS_NOT_TRUE,
OP_TYPE_IS_NOT_FALSE,
OP_TYPE_IS_NOT_UNKNOWN,
// json operator
OP_TYPE_JSON_GET_VALUE,
OP_TYPE_JSON_CONTAINS
} EOperatorType;
typedef struct SOperatorNode { typedef struct SOperatorNode {
SExprNode node; // QUERY_NODE_OPERATOR SExprNode node; // QUERY_NODE_OPERATOR
EOperatorType opType; EOperatorType opType;
@ -127,11 +88,6 @@ typedef struct SOperatorNode {
SNode* pRight; SNode* pRight;
} SOperatorNode; } SOperatorNode;
typedef enum ELogicConditionType {
LOGIC_COND_TYPE_AND,
LOGIC_COND_TYPE_OR,
LOGIC_COND_TYPE_NOT,
} ELogicConditionType;
typedef struct SLogicConditionNode { typedef struct SLogicConditionNode {
SExprNode node; // QUERY_NODE_LOGIC_CONDITION SExprNode node; // QUERY_NODE_LOGIC_CONDITION

View File

@ -20,6 +20,14 @@ extern "C" {
#endif #endif
typedef struct SFilterInfo SFilterInfo; typedef struct SFilterInfo SFilterInfo;
typedef int32_t (*filer_get_col_from_id)(void *, int32_t, void **);
enum {
FLT_OPTION_NO_REWRITE = 1,
FLT_OPTION_TIMESTAMP = 2,
FLT_OPTION_NEED_UNIQE = 4,
};
typedef struct SFilterColumnParam{ typedef struct SFilterColumnParam{
int32_t numOfCols; int32_t numOfCols;
@ -27,6 +35,16 @@ typedef struct SFilterColumnParam{
} SFilterColumnParam; } SFilterColumnParam;
extern int32_t filterInitFromNode(SNode *pNode, SFilterInfo **pinfo, uint32_t options);
extern bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnDataAgg *statis, int16_t numOfCols);
extern int32_t filterSetDataFromSlotId(SFilterInfo *info, void *param, filer_get_col_from_id fp);
extern int32_t filterSetDataFromColId(SFilterInfo *info, void *param, filer_get_col_from_id fp);
extern int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win);
extern int32_t filterConverNcharColumns(SFilterInfo* pFilterInfo, int32_t rows, bool *gotNchar);
extern int32_t filterFreeNcharColumns(SFilterInfo* pFilterInfo);
extern void filterFreeInfo(SFilterInfo *info);
extern bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t numOfCols, int32_t numOfRows);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -108,35 +108,52 @@ do { \
(src) = (void *)((char *)src + sizeof(type));\ (src) = (void *)((char *)src + sizeof(type));\
} while(0) } while(0)
typedef enum EOperatorType {
// arithmetic operator
OP_TYPE_ADD = 1,
OP_TYPE_SUB,
OP_TYPE_MULTI,
OP_TYPE_DIV,
OP_TYPE_MOD,
// TODO: check if below is necessary // bit operator
#define TSDB_RELATION_INVALID 0 OP_TYPE_BIT_AND,
#define TSDB_RELATION_LESS 1 OP_TYPE_BIT_OR,
#define TSDB_RELATION_GREATER 2
#define TSDB_RELATION_EQUAL 3
#define TSDB_RELATION_LESS_EQUAL 4
#define TSDB_RELATION_GREATER_EQUAL 5
#define TSDB_RELATION_NOT_EQUAL 6
#define TSDB_RELATION_LIKE 7
#define TSDB_RELATION_NOT_LIKE 8
#define TSDB_RELATION_ISNULL 9
#define TSDB_RELATION_NOTNULL 10
#define TSDB_RELATION_IN 11
#define TSDB_RELATION_NOT_IN 12
#define TSDB_RELATION_AND 13 // comparison operator
#define TSDB_RELATION_OR 14 OP_TYPE_GREATER_THAN,
#define TSDB_RELATION_NOT 15 OP_TYPE_GREATER_EQUAL,
OP_TYPE_LOWER_THAN,
OP_TYPE_LOWER_EQUAL,
OP_TYPE_EQUAL,
OP_TYPE_NOT_EQUAL,
OP_TYPE_IN,
OP_TYPE_NOT_IN,
OP_TYPE_LIKE,
OP_TYPE_NOT_LIKE,
OP_TYPE_MATCH,
OP_TYPE_NMATCH,
OP_TYPE_IS_NULL,
OP_TYPE_IS_NOT_NULL,
OP_TYPE_IS_TRUE,
OP_TYPE_IS_FALSE,
OP_TYPE_IS_UNKNOWN,
OP_TYPE_IS_NOT_TRUE,
OP_TYPE_IS_NOT_FALSE,
OP_TYPE_IS_NOT_UNKNOWN,
#define TSDB_RELATION_MATCH 16 // json operator
#define TSDB_RELATION_NMATCH 17 OP_TYPE_JSON_GET_VALUE,
OP_TYPE_JSON_CONTAINS
} EOperatorType;
typedef enum ELogicConditionType {
LOGIC_COND_TYPE_AND,
LOGIC_COND_TYPE_OR,
LOGIC_COND_TYPE_NOT,
} ELogicConditionType;
#define TSDB_BINARY_OP_ADD 4000
#define TSDB_BINARY_OP_SUBTRACT 4001
#define TSDB_BINARY_OP_MULTIPLY 4002
#define TSDB_BINARY_OP_DIVIDE 4003
#define TSDB_BINARY_OP_REMAINDER 4004
#define TSDB_BINARY_OP_CONCAT 4005
#define FUNCTION_CEIL 4500 #define FUNCTION_CEIL 4500
#define FUNCTION_FLOOR 4501 #define FUNCTION_FLOOR 4501
@ -148,9 +165,6 @@ do { \
#define FUNCTION_LTRIM 4802 #define FUNCTION_LTRIM 4802
#define FUNCTION_RTRIM 4803 #define FUNCTION_RTRIM 4803
#define IS_RELATION_OPTR(op) (((op) >= TSDB_RELATION_LESS) && ((op) < TSDB_RELATION_IN))
#define IS_ARITHMETIC_OPTR(op) (((op) >= TSDB_BINARY_OP_ADD) && ((op) <= TSDB_BINARY_OP_REMAINDER))
#define TSDB_NAME_DELIMITER_LEN 1 #define TSDB_NAME_DELIMITER_LEN 1
#define TSDB_UNI_LEN 24 #define TSDB_UNI_LEN 24

View File

@ -31,7 +31,7 @@ SColumnFilterInfo* tFilterInfoDup(const SColumnFilterInfo* src, int32_t numOfFil
} }
assert(src->filterstr == 0 || src->filterstr == 1); assert(src->filterstr == 0 || src->filterstr == 1);
assert(!(src->lowerRelOptr == TSDB_RELATION_INVALID && src->upperRelOptr == TSDB_RELATION_INVALID)); assert(!(src->lowerRelOptr == 0 && src->upperRelOptr == 0));
return pFilter; return pFilter;
} }

View File

@ -585,7 +585,7 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) {
} }
void operateVal(void *dst, void *s1, void *s2, int32_t optr, int32_t type) { void operateVal(void *dst, void *s1, void *s2, int32_t optr, int32_t type) {
if (optr == TSDB_BINARY_OP_ADD) { if (optr == OP_TYPE_ADD) {
switch (type) { switch (type) {
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
*((int8_t *)dst) = GET_INT8_VAL(s1) + GET_INT8_VAL(s2); *((int8_t *)dst) = GET_INT8_VAL(s1) + GET_INT8_VAL(s2);

View File

@ -25,6 +25,7 @@
#include "thash.h" #include "thash.h"
#include "texpr.h" #include "texpr.h"
#include "tvariant.h" #include "tvariant.h"
#include "tdef.h"
//static uint8_t UNUSED_FUNC isQueryOnPrimaryKey(const char *primaryColumnName, const tExprNode *pLeft, const tExprNode *pRight) { //static uint8_t UNUSED_FUNC isQueryOnPrimaryKey(const char *primaryColumnName, const tExprNode *pLeft, const tExprNode *pRight) {
// if (pLeft->nodeType == TEXPR_COL_NODE) { // if (pLeft->nodeType == TEXPR_COL_NODE) {
@ -94,7 +95,7 @@ bool exprTreeApplyFilter(tExprNode *pExpr, const void *pItem, SExprTraverseSupp
//non-leaf nodes, recursively traverse the expression tree in the post-root order //non-leaf nodes, recursively traverse the expression tree in the post-root order
if (pLeft->nodeType == TEXPR_BINARYEXPR_NODE && pRight->nodeType == TEXPR_BINARYEXPR_NODE) { if (pLeft->nodeType == TEXPR_BINARYEXPR_NODE && pRight->nodeType == TEXPR_BINARYEXPR_NODE) {
if (pExpr->_node.optr == TSDB_RELATION_OR) { // or if (pExpr->_node.optr == LOGIC_COND_TYPE_OR) { // or
if (exprTreeApplyFilter(pLeft, pItem, param)) { if (exprTreeApplyFilter(pLeft, pItem, param)) {
return true; return true;
} }
@ -255,7 +256,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_LIKE, QUERY_COND_REL_PREFIX_LIKE_LEN) == 0) { if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_LIKE, QUERY_COND_REL_PREFIX_LIKE_LEN) == 0) {
right->nodeType = TEXPR_VALUE_NODE; right->nodeType = TEXPR_VALUE_NODE;
expr->_node.optr = TSDB_RELATION_LIKE; expr->_node.optr = OP_TYPE_LIKE;
SVariant* pVal = exception_calloc(1, sizeof(SVariant)); SVariant* pVal = exception_calloc(1, sizeof(SVariant));
right->pVal = pVal; right->pVal = pVal;
size_t len = strlen(tbnameCond + QUERY_COND_REL_PREFIX_LIKE_LEN) + 1; size_t len = strlen(tbnameCond + QUERY_COND_REL_PREFIX_LIKE_LEN) + 1;
@ -266,7 +267,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
} else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_MATCH, QUERY_COND_REL_PREFIX_MATCH_LEN) == 0) { } else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_MATCH, QUERY_COND_REL_PREFIX_MATCH_LEN) == 0) {
right->nodeType = TEXPR_VALUE_NODE; right->nodeType = TEXPR_VALUE_NODE;
expr->_node.optr = TSDB_RELATION_MATCH; expr->_node.optr = OP_TYPE_MATCH;
SVariant* pVal = exception_calloc(1, sizeof(SVariant)); SVariant* pVal = exception_calloc(1, sizeof(SVariant));
right->pVal = pVal; right->pVal = pVal;
size_t len = strlen(tbnameCond + QUERY_COND_REL_PREFIX_MATCH_LEN) + 1; size_t len = strlen(tbnameCond + QUERY_COND_REL_PREFIX_MATCH_LEN) + 1;
@ -276,7 +277,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
pVal->nLen = (int32_t)len; pVal->nLen = (int32_t)len;
} else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_NMATCH, QUERY_COND_REL_PREFIX_NMATCH_LEN) == 0) { } else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_NMATCH, QUERY_COND_REL_PREFIX_NMATCH_LEN) == 0) {
right->nodeType = TEXPR_VALUE_NODE; right->nodeType = TEXPR_VALUE_NODE;
expr->_node.optr = TSDB_RELATION_NMATCH; expr->_node.optr = OP_TYPE_NMATCH;
SVariant* pVal = exception_calloc(1, sizeof(SVariant)); SVariant* pVal = exception_calloc(1, sizeof(SVariant));
right->pVal = pVal; right->pVal = pVal;
size_t len = strlen(tbnameCond + QUERY_COND_REL_PREFIX_NMATCH_LEN) + 1; size_t len = strlen(tbnameCond + QUERY_COND_REL_PREFIX_NMATCH_LEN) + 1;
@ -286,7 +287,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
pVal->nLen = (int32_t)len; pVal->nLen = (int32_t)len;
} else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN) == 0) { } else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN) == 0) {
right->nodeType = TEXPR_VALUE_NODE; right->nodeType = TEXPR_VALUE_NODE;
expr->_node.optr = TSDB_RELATION_IN; expr->_node.optr = OP_TYPE_IN;
SVariant* pVal = exception_calloc(1, sizeof(SVariant)); SVariant* pVal = exception_calloc(1, sizeof(SVariant));
right->pVal = pVal; right->pVal = pVal;
pVal->nType = TSDB_DATA_TYPE_POINTER_ARRAY; pVal->nType = TSDB_DATA_TYPE_POINTER_ARRAY;

View File

@ -884,7 +884,7 @@ SColumnFilterInfo* tFilterInfoDup(const SColumnFilterInfo* src, int32_t numOfFil
} }
assert(src->filterstr == 0 || src->filterstr == 1); assert(src->filterstr == 0 || src->filterstr == 1);
assert(!(src->lowerRelOptr == TSDB_RELATION_INVALID && src->upperRelOptr == TSDB_RELATION_INVALID)); assert(!(src->lowerRelOptr == 0 && src->upperRelOptr == 0));
return pFilter; return pFilter;
} }
@ -1507,45 +1507,45 @@ int32_t getTagFilterSerializeLen(SQueryStmtInfo* pQueryInfo) {
uint32_t convertRelationalOperator(SToken *pToken) { uint32_t convertRelationalOperator(SToken *pToken) {
switch (pToken->type) { switch (pToken->type) {
case TK_LT: case TK_LT:
return TSDB_RELATION_LESS; return OP_TYPE_LOWER_THAN;
case TK_LE: case TK_LE:
return TSDB_RELATION_LESS_EQUAL; return OP_TYPE_LOWER_EQUAL;
case TK_GT: case TK_GT:
return TSDB_RELATION_GREATER; return OP_TYPE_GREATER_THAN;
case TK_GE: case TK_GE:
return TSDB_RELATION_GREATER_EQUAL; return OP_TYPE_GREATER_EQUAL;
case TK_NE: case TK_NE:
return TSDB_RELATION_NOT_EQUAL; return OP_TYPE_NOT_EQUAL;
case TK_AND: case TK_AND:
return TSDB_RELATION_AND; return LOGIC_COND_TYPE_AND;
case TK_OR: case TK_OR:
return TSDB_RELATION_OR; return LOGIC_COND_TYPE_OR;
case TK_EQ: case TK_EQ:
return TSDB_RELATION_EQUAL; return OP_TYPE_EQUAL;
case TK_PLUS: case TK_PLUS:
return TSDB_BINARY_OP_ADD; return OP_TYPE_ADD;
case TK_MINUS: case TK_MINUS:
return TSDB_BINARY_OP_SUBTRACT; return OP_TYPE_SUB;
case TK_STAR: case TK_STAR:
return TSDB_BINARY_OP_MULTIPLY; return OP_TYPE_MULTI;
case TK_SLASH: case TK_SLASH:
case TK_DIVIDE: case TK_DIVIDE:
return TSDB_BINARY_OP_DIVIDE; return OP_TYPE_DIV;
case TK_REM: case TK_REM:
return TSDB_BINARY_OP_REMAINDER; return OP_TYPE_MOD;
case TK_LIKE: case TK_LIKE:
return TSDB_RELATION_LIKE; return OP_TYPE_LIKE;
case TK_MATCH: case TK_MATCH:
return TSDB_RELATION_MATCH; return OP_TYPE_MATCH;
case TK_NMATCH: case TK_NMATCH:
return TSDB_RELATION_NMATCH; return OP_TYPE_NMATCH;
case TK_ISNULL: case TK_ISNULL:
return TSDB_RELATION_ISNULL; return OP_TYPE_IS_NULL;
case TK_NOTNULL: case TK_NOTNULL:
return TSDB_RELATION_NOTNULL; return OP_TYPE_IS_NOT_NULL;
case TK_IN: case TK_IN:
return TSDB_RELATION_IN; return OP_TYPE_IN;
default: { return 0; } default: { return 0; }
} }
} }

View File

@ -593,7 +593,7 @@ TEST(testCase, function_Test6) {
SExprInfo* p2 = (SExprInfo*) taosArrayGetP(pQueryInfo->exprList[1], 0); SExprInfo* p2 = (SExprInfo*) taosArrayGetP(pQueryInfo->exprList[1], 0);
ASSERT_EQ(p2->pExpr->nodeType, TEXPR_BINARYEXPR_NODE); ASSERT_EQ(p2->pExpr->nodeType, TEXPR_BINARYEXPR_NODE);
ASSERT_EQ(p2->pExpr->_node.optr, TSDB_BINARY_OP_ADD); ASSERT_EQ(p2->pExpr->_node.optr, OP_TYPE_ADD);
ASSERT_EQ(p2->pExpr->_node.pLeft->nodeType, TEXPR_COL_NODE); ASSERT_EQ(p2->pExpr->_node.pLeft->nodeType, TEXPR_COL_NODE);
ASSERT_EQ(p2->pExpr->_node.pRight->nodeType, TEXPR_COL_NODE); ASSERT_EQ(p2->pExpr->_node.pRight->nodeType, TEXPR_COL_NODE);

View File

@ -43,7 +43,6 @@ enum {
FLD_TYPE_COLUMN = 1, FLD_TYPE_COLUMN = 1,
FLD_TYPE_VALUE = 2, FLD_TYPE_VALUE = 2,
FLD_TYPE_MAX = 3, FLD_TYPE_MAX = 3,
FLD_DESC_NO_FREE = 4,
FLD_DATA_NO_FREE = 8, FLD_DATA_NO_FREE = 8,
FLD_DATA_IS_HASH = 16, FLD_DATA_IS_HASH = 16,
}; };
@ -61,11 +60,6 @@ enum {
RANGE_FLG_NULL = 4, RANGE_FLG_NULL = 4,
}; };
enum {
FI_OPTION_NO_REWRITE = 1,
FI_OPTION_TIMESTAMP = 2,
FI_OPTION_NEED_UNIQE = 4,
};
enum { enum {
FI_STATUS_ALL = 1, FI_STATUS_ALL = 1,
@ -107,7 +101,6 @@ typedef struct SFilterRange {
typedef bool (*rangeCompFunc) (const void *, const void *, const void *, const void *, __compar_fn_t); typedef bool (*rangeCompFunc) (const void *, const void *, const void *, const void *, __compar_fn_t);
typedef int32_t(*filter_desc_compare_func)(const void *, const void *); typedef int32_t(*filter_desc_compare_func)(const void *, const void *);
typedef bool(*filter_exec_func)(void *, int32_t, int8_t**, SColumnDataAgg *, int16_t); typedef bool(*filter_exec_func)(void *, int32_t, int8_t**, SColumnDataAgg *, int16_t);
typedef int32_t (*filer_get_col_from_id)(void *, int32_t, void **);
typedef int32_t (*filer_get_col_from_name)(void *, int32_t, char*, void **); typedef int32_t (*filer_get_col_from_name)(void *, int32_t, char*, void **);
typedef struct SFilterRangeCompare { typedef struct SFilterRangeCompare {
@ -264,12 +257,12 @@ typedef struct SFilterInfo {
} SFilterInfo; } SFilterInfo;
#define FILTER_NO_MERGE_DATA_TYPE(t) ((t) == TSDB_DATA_TYPE_BINARY || (t) == TSDB_DATA_TYPE_NCHAR || (t) == TSDB_DATA_TYPE_JSON) #define FILTER_NO_MERGE_DATA_TYPE(t) ((t) == TSDB_DATA_TYPE_BINARY || (t) == TSDB_DATA_TYPE_NCHAR || (t) == TSDB_DATA_TYPE_JSON)
#define FILTER_NO_MERGE_OPTR(o) ((o) == TSDB_RELATION_ISNULL || (o) == TSDB_RELATION_NOTNULL || (o) == FILTER_DUMMY_EMPTY_OPTR) #define FILTER_NO_MERGE_OPTR(o) ((o) == OP_TYPE_IS_NULL || (o) == OP_TYPE_IS_NOT_NULL || (o) == FILTER_DUMMY_EMPTY_OPTR)
#define MR_EMPTY_RES(ctx) (ctx->rs == NULL) #define MR_EMPTY_RES(ctx) (ctx->rs == NULL)
#define SET_AND_OPTR(ctx, o) do {if (o == TSDB_RELATION_ISNULL) { (ctx)->isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { if (!(ctx)->isrange) { (ctx)->notnull = true; } } else if (o != FILTER_DUMMY_EMPTY_OPTR) { (ctx)->isrange = true; (ctx)->notnull = false; } } while (0) #define SET_AND_OPTR(ctx, o) do {if (o == OP_TYPE_IS_NULL) { (ctx)->isnull = true; } else if (o == OP_TYPE_IS_NOT_NULL) { if (!(ctx)->isrange) { (ctx)->notnull = true; } } else if (o != FILTER_DUMMY_EMPTY_OPTR) { (ctx)->isrange = true; (ctx)->notnull = false; } } while (0)
#define SET_OR_OPTR(ctx,o) do {if (o == TSDB_RELATION_ISNULL) { (ctx)->isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { (ctx)->notnull = true; (ctx)->isrange = false; } else if (o != FILTER_DUMMY_EMPTY_OPTR) { if (!(ctx)->notnull) { (ctx)->isrange = true; } } } while (0) #define SET_OR_OPTR(ctx,o) do {if (o == OP_TYPE_IS_NULL) { (ctx)->isnull = true; } else if (o == OP_TYPE_IS_NOT_NULL) { (ctx)->notnull = true; (ctx)->isrange = false; } else if (o != FILTER_DUMMY_EMPTY_OPTR) { if (!(ctx)->notnull) { (ctx)->isrange = true; } } } while (0)
#define CHK_OR_OPTR(ctx) ((ctx)->isnull == true && (ctx)->notnull == true) #define CHK_OR_OPTR(ctx) ((ctx)->isnull == true && (ctx)->notnull == true)
#define CHK_AND_OPTR(ctx) ((ctx)->isnull == true && (((ctx)->notnull == true) || ((ctx)->isrange == true))) #define CHK_AND_OPTR(ctx) ((ctx)->isnull == true && (((ctx)->notnull == true) || ((ctx)->isrange == true)))
@ -351,23 +344,10 @@ typedef struct SFilterInfo {
#define FILTER_ALL_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_ALL) #define FILTER_ALL_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_ALL)
#define FILTER_EMPTY_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_EMPTY) #define FILTER_EMPTY_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_EMPTY)
#if 0
extern int32_t filterInitFromTree(tExprNode* tree, void **pinfo, uint32_t options);
extern bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t** p, SColumnDataAgg *statis, int16_t numOfCols);
extern int32_t filterSetColFieldData(SFilterInfo *info, void *param, filer_get_col_from_id fp);
extern int32_t filterSetJsonColFieldData(SFilterInfo *info, void *param, filer_get_col_from_name fp);
extern int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win);
extern int32_t filterConverNcharColumns(SFilterInfo* pFilterInfo, int32_t rows, bool *gotNchar);
extern int32_t filterFreeNcharColumns(SFilterInfo* pFilterInfo);
extern void filterFreeInfo(SFilterInfo *info);
extern bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t numOfCols, int32_t numOfRows);
#else
//REMOVE THESE!!!!!!!!!!!!!!!!!!!!
#include "function.h"
#endif
extern bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right); extern bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right);
extern __compar_fn_t filterGetCompFunc(int32_t type, int32_t optr); extern __compar_fn_t filterGetCompFunc(int32_t type, int32_t optr);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -24,7 +24,6 @@ extern "C" {
typedef void (*_bin_scalar_fn_t)(SScalarParam* pLeft, SScalarParam* pRight, void *output, int32_t order); typedef void (*_bin_scalar_fn_t)(SScalarParam* pLeft, SScalarParam* pRight, void *output, int32_t order);
_bin_scalar_fn_t getBinScalarOperatorFn(int32_t binOperator); _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binOperator);
bool isBinaryStringOp(int32_t op);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -21,22 +21,42 @@
#include "filter.h" #include "filter.h"
OptrStr gOptrStr[] = { OptrStr gOptrStr[] = {
{TSDB_RELATION_INVALID, "invalid"}, {0, "invalid"},
{TSDB_RELATION_LESS, "<"}, {OP_TYPE_ADD, "+"},
{TSDB_RELATION_GREATER, ">"}, {OP_TYPE_SUB, "-"},
{TSDB_RELATION_EQUAL, "="}, {OP_TYPE_MULTI, "*"},
{TSDB_RELATION_LESS_EQUAL, "<="}, {OP_TYPE_DIV, "/"},
{TSDB_RELATION_GREATER_EQUAL, ">="}, {OP_TYPE_MOD, "%"},
{TSDB_RELATION_NOT_EQUAL, "!="},
{TSDB_RELATION_LIKE, "like"}, // bit operator
{TSDB_RELATION_ISNULL, "is null"}, {OP_TYPE_BIT_AND, "&"},
{TSDB_RELATION_NOTNULL, "not null"}, {OP_TYPE_BIT_OR, "|"},
{TSDB_RELATION_IN, "in"},
{TSDB_RELATION_AND, "and"}, // comparison operator
{TSDB_RELATION_OR, "or"}, {OP_TYPE_GREATER_THAN, ">"},
{TSDB_RELATION_NOT, "not"}, {OP_TYPE_GREATER_EQUAL, ">="},
{TSDB_RELATION_MATCH, "match"}, {OP_TYPE_LOWER_THAN, "<"},
{TSDB_RELATION_NMATCH, "nmatch"} {OP_TYPE_LOWER_EQUAL, "<="},
{OP_TYPE_EQUAL, "=="},
{OP_TYPE_NOT_EQUAL, "!="},
{OP_TYPE_IN, "in"},
{OP_TYPE_NOT_IN, "not in"},
{OP_TYPE_LIKE, "like"},
{OP_TYPE_NOT_LIKE, "not like"},
{OP_TYPE_MATCH, "match"},
{OP_TYPE_NMATCH, "nmatch"},
{OP_TYPE_IS_NULL, "is null"},
{OP_TYPE_IS_NOT_NULL, "not null"},
{OP_TYPE_IS_TRUE, "is true"},
{OP_TYPE_IS_FALSE, "is false"},
{OP_TYPE_IS_UNKNOWN, "is unknown"},
{OP_TYPE_IS_NOT_TRUE, "not true"},
{OP_TYPE_IS_NOT_FALSE, "not false"},
{OP_TYPE_IS_NOT_UNKNOWN, "not unknown"},
// json operator
{OP_TYPE_JSON_GET_VALUE, "json get"},
{OP_TYPE_JSON_CONTAINS, "json contains"}
}; };
bool filterRangeCompGi (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { bool filterRangeCompGi (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) {
@ -110,30 +130,30 @@ rangeCompFunc gRangeCompare[] = {filterRangeCompee, filterRangeCompei, filterRan
int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) { int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) {
if (optr2) { if (optr2) {
assert(optr2 == TSDB_RELATION_LESS || optr2 == TSDB_RELATION_LESS_EQUAL); assert(optr2 == OP_TYPE_LOWER_THAN || optr2 == OP_TYPE_LOWER_EQUAL);
if (optr == TSDB_RELATION_GREATER) { if (optr == OP_TYPE_GREATER_THAN) {
if (optr2 == TSDB_RELATION_LESS) { if (optr2 == OP_TYPE_LOWER_THAN) {
return 0; return 0;
} }
return 1; return 1;
} }
if (optr2 == TSDB_RELATION_LESS) { if (optr2 == OP_TYPE_LOWER_THAN) {
return 2; return 2;
} }
return 3; return 3;
} else { } else {
switch (optr) { switch (optr) {
case TSDB_RELATION_GREATER: case OP_TYPE_GREATER_THAN:
return 4; return 4;
case TSDB_RELATION_GREATER_EQUAL: case OP_TYPE_GREATER_EQUAL:
return 5; return 5;
case TSDB_RELATION_LESS: case OP_TYPE_LOWER_THAN:
return 6; return 6;
case TSDB_RELATION_LESS_EQUAL: case OP_TYPE_LOWER_EQUAL:
return 7; return 7;
default: default:
break; break;
@ -154,7 +174,7 @@ __compar_fn_t gDataCompare[] = {compareInt32Val, compareInt8Val, compareInt16Val
int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
int8_t comparFn = 0; int8_t comparFn = 0;
if (optr == TSDB_RELATION_IN && (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR)) { if (optr == OP_TYPE_IN && (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR)) {
switch (type) { switch (type) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
@ -177,7 +197,7 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
} }
} }
if (optr == TSDB_RELATION_NOT_IN && (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR)) { if (optr == OP_TYPE_NOT_IN && (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR)) {
switch (type) { switch (type) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
@ -210,17 +230,17 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
case TSDB_DATA_TYPE_FLOAT: comparFn = 4; break; case TSDB_DATA_TYPE_FLOAT: comparFn = 4; break;
case TSDB_DATA_TYPE_DOUBLE: comparFn = 5; break; case TSDB_DATA_TYPE_DOUBLE: comparFn = 5; break;
case TSDB_DATA_TYPE_BINARY: { case TSDB_DATA_TYPE_BINARY: {
if (optr == TSDB_RELATION_MATCH) { if (optr == OP_TYPE_MATCH) {
comparFn = 19; comparFn = 19;
} else if (optr == TSDB_RELATION_NMATCH) { } else if (optr == OP_TYPE_NMATCH) {
comparFn = 20; comparFn = 20;
} else if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */ } else if (optr == OP_TYPE_LIKE) { /* wildcard query using like operator */
comparFn = 7; comparFn = 7;
} else if (optr == TSDB_RELATION_NOT_LIKE) { /* wildcard query using like operator */ } else if (optr == OP_TYPE_NOT_LIKE) { /* wildcard query using like operator */
comparFn = 26; comparFn = 26;
} else if (optr == TSDB_RELATION_IN) { } else if (optr == OP_TYPE_IN) {
comparFn = 8; comparFn = 8;
} else if (optr == TSDB_RELATION_NOT_IN) { } else if (optr == OP_TYPE_NOT_IN) {
comparFn = 25; comparFn = 25;
} else { /* normal relational comparFn */ } else { /* normal relational comparFn */
comparFn = 6; comparFn = 6;
@ -230,17 +250,17 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
} }
case TSDB_DATA_TYPE_NCHAR: { case TSDB_DATA_TYPE_NCHAR: {
if (optr == TSDB_RELATION_MATCH) { if (optr == OP_TYPE_MATCH) {
comparFn = 19; comparFn = 19;
} else if (optr == TSDB_RELATION_NMATCH) { } else if (optr == OP_TYPE_NMATCH) {
comparFn = 20; comparFn = 20;
} else if (optr == TSDB_RELATION_LIKE) { } else if (optr == OP_TYPE_LIKE) {
comparFn = 9; comparFn = 9;
} else if (optr == TSDB_RELATION_LIKE) { } else if (optr == OP_TYPE_LIKE) {
comparFn = 27; comparFn = 27;
} else if (optr == TSDB_RELATION_IN) { } else if (optr == OP_TYPE_IN) {
comparFn = 8; comparFn = 8;
} else if (optr == TSDB_RELATION_NOT_IN) { } else if (optr == OP_TYPE_NOT_IN) {
comparFn = 25; comparFn = 25;
} else { } else {
comparFn = 10; comparFn = 10;
@ -383,7 +403,7 @@ int32_t filterConvertRange(SFilterRangeCtx *cur, SFilterRange *ra, bool *notNull
int32_t filterAddRangeOptr(void* h, uint8_t raOptr, int32_t optr, bool *empty, bool *all) { int32_t filterAddRangeOptr(void* h, uint8_t raOptr, int32_t optr, bool *empty, bool *all) {
SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; SFilterRangeCtx *ctx = (SFilterRangeCtx *)h;
if (optr == TSDB_RELATION_AND) { if (optr == LOGIC_COND_TYPE_AND) {
SET_AND_OPTR(ctx, raOptr); SET_AND_OPTR(ctx, raOptr);
if (CHK_AND_OPTR(ctx) || (raOptr == FILTER_DUMMY_EMPTY_OPTR)) { if (CHK_AND_OPTR(ctx) || (raOptr == FILTER_DUMMY_EMPTY_OPTR)) {
FILTER_SET_FLAG(ctx->status, MR_ST_EMPTY); FILTER_SET_FLAG(ctx->status, MR_ST_EMPTY);
@ -407,8 +427,8 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) {
if (ctx->rs == NULL) { if (ctx->rs == NULL) {
if ((FILTER_GET_FLAG(ctx->status, MR_ST_START) == 0) if ((FILTER_GET_FLAG(ctx->status, MR_ST_START) == 0)
|| (FILTER_GET_FLAG(ctx->status, MR_ST_ALL) && (optr == TSDB_RELATION_AND)) || (FILTER_GET_FLAG(ctx->status, MR_ST_ALL) && (optr == LOGIC_COND_TYPE_AND))
|| ((!FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) && (optr == TSDB_RELATION_OR))) { || ((!FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) && (optr == LOGIC_COND_TYPE_OR))) {
APPEND_RANGE(ctx, ctx->rs, ra); APPEND_RANGE(ctx, ctx->rs, ra);
FILTER_SET_FLAG(ctx->status, MR_ST_START); FILTER_SET_FLAG(ctx->status, MR_ST_START);
} }
@ -420,7 +440,7 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) {
SFilterRangeNode *rn = NULL; SFilterRangeNode *rn = NULL;
int32_t cr = 0; int32_t cr = 0;
if (optr == TSDB_RELATION_AND) { if (optr == LOGIC_COND_TYPE_AND) {
while (r != NULL) { while (r != NULL) {
cr = ctx->pCompareFunc(&r->ra.s, &ra->e); cr = ctx->pCompareFunc(&r->ra.s, &ra->e);
if (FILTER_GREATER(cr, r->ra.sflag, ra->eflag)) { if (FILTER_GREATER(cr, r->ra.sflag, ra->eflag)) {
@ -532,7 +552,7 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) {
if (notnull) { if (notnull) {
bool all = false; bool all = false;
FREE_FROM_RANGE(ctx, ctx->rs); FREE_FROM_RANGE(ctx, ctx->rs);
filterAddRangeOptr(h, TSDB_RELATION_NOTNULL, optr, NULL, &all); filterAddRangeOptr(h, OP_TYPE_IS_NOT_NULL, optr, NULL, &all);
if (all) { if (all) {
FILTER_SET_FLAG(ctx->status, MR_ST_ALL); FILTER_SET_FLAG(ctx->status, MR_ST_ALL);
} }
@ -563,7 +583,7 @@ int32_t filterAddRangeCtx(void *dst, void *src, int32_t optr) {
SFilterRangeCtx *dctx = (SFilterRangeCtx *)dst; SFilterRangeCtx *dctx = (SFilterRangeCtx *)dst;
SFilterRangeCtx *sctx = (SFilterRangeCtx *)src; SFilterRangeCtx *sctx = (SFilterRangeCtx *)src;
assert(optr == TSDB_RELATION_OR); assert(optr == LOGIC_COND_TYPE_OR);
if (sctx->rs == NULL) { if (sctx->rs == NULL) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -614,13 +634,13 @@ int32_t filterFinishRange(void* h) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (FILTER_GET_FLAG(ctx->options, FI_OPTION_TIMESTAMP)) { if (FILTER_GET_FLAG(ctx->options, FLT_OPTION_TIMESTAMP)) {
SFilterRangeNode *r = ctx->rs; SFilterRangeNode *r = ctx->rs;
SFilterRangeNode *rn = NULL; SFilterRangeNode *rn = NULL;
while (r && r->next) { while (r && r->next) {
int64_t tmp = 1; int64_t tmp = 1;
operateVal(&tmp, &r->ra.e, &tmp, TSDB_BINARY_OP_ADD, ctx->type); operateVal(&tmp, &r->ra.e, &tmp, OP_TYPE_ADD, ctx->type);
if (ctx->pCompareFunc(&tmp, &r->next->ra.s) == 0) { if (ctx->pCompareFunc(&tmp, &r->next->ra.s) == 0) {
rn = r->next; rn = r->next;
SIMPLE_COPY_VALUES((char *)&r->next->ra.s, (char *)&r->ra.s); SIMPLE_COPY_VALUES((char *)&r->next->ra.s, (char *)&r->ra.s);
@ -685,14 +705,14 @@ int32_t filterSourceRangeFromCtx(SFilterRangeCtx *ctx, void *sctx, int32_t optr,
SFilterRangeCtx *src = (SFilterRangeCtx *)sctx; SFilterRangeCtx *src = (SFilterRangeCtx *)sctx;
if (src->isnull){ if (src->isnull){
filterAddRangeOptr(ctx, TSDB_RELATION_ISNULL, optr, empty, all); filterAddRangeOptr(ctx, OP_TYPE_IS_NULL, optr, empty, all);
if (FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) { if (FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) {
*all = true; *all = true;
} }
} }
if (src->notnull) { if (src->notnull) {
filterAddRangeOptr(ctx, TSDB_RELATION_NOTNULL, optr, empty, all); filterAddRangeOptr(ctx, OP_TYPE_IS_NOT_NULL, optr, empty, all);
if (FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) { if (FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) {
*all = true; *all = true;
} }
@ -701,7 +721,7 @@ int32_t filterSourceRangeFromCtx(SFilterRangeCtx *ctx, void *sctx, int32_t optr,
if (src->isrange) { if (src->isrange) {
filterAddRangeOptr(ctx, 0, optr, empty, all); filterAddRangeOptr(ctx, 0, optr, empty, all);
if (!(optr == TSDB_RELATION_OR && ctx->notnull)) { if (!(optr == LOGIC_COND_TYPE_OR && ctx->notnull)) {
filterAddRangeCtx(ctx, src, optr); filterAddRangeCtx(ctx, src, optr);
} }
@ -764,13 +784,26 @@ int32_t filterDetachCnfGroups(SArray* group, SArray* left, SArray* right) {
int32_t rightSize = (int32_t)taosArrayGetSize(right); int32_t rightSize = (int32_t)taosArrayGetSize(right);
if (taosArrayGetSize(left) <= 0) { if (taosArrayGetSize(left) <= 0) {
fltDebug("empty group"); if (taosArrayGetSize(right) <= 0) {
fltError("both groups are empty");
FLT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); FLT_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
} }
SFilterGroup *gp = NULL;
while (gp = (SFilterGroup *)taosArrayPop(right)) {
taosArrayPush(group, gp);
}
return TSDB_CODE_SUCCESS;
}
if (taosArrayGetSize(right) <= 0) { if (taosArrayGetSize(right) <= 0) {
fltDebug("empty group"); SFilterGroup *gp = NULL;
FLT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); while (gp = (SFilterGroup *)taosArrayPop(left)) {
taosArrayPush(group, gp);
}
return TSDB_CODE_SUCCESS;
} }
for (int32_t l = 0; l < leftSize; ++l) { for (int32_t l = 0; l < leftSize; ++l) {
@ -825,7 +858,7 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type,
if (*num > 0) { if (*num > 0) {
if (type == FLD_TYPE_COLUMN) { if (type == FLD_TYPE_COLUMN) {
idx = filterGetFiledByDesc(&info->fields[type], type, desc); idx = filterGetFiledByDesc(&info->fields[type], type, desc);
} else if (data && (*data) && dataLen > 0 && FILTER_GET_FLAG(info->options, FI_OPTION_NEED_UNIQE)) { } else if (data && (*data) && dataLen > 0 && FILTER_GET_FLAG(info->options, FLT_OPTION_NEED_UNIQE)) {
idx = filterGetFiledByData(info, type, *data, dataLen); idx = filterGetFiledByData(info, type, *data, dataLen);
} }
} }
@ -847,7 +880,7 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type,
++(*num); ++(*num);
if (data && (*data) && dataLen > 0 && FILTER_GET_FLAG(info->options, FI_OPTION_NEED_UNIQE)) { if (data && (*data) && dataLen > 0 && FILTER_GET_FLAG(info->options, FLT_OPTION_NEED_UNIQE)) {
if (info->pctx.valHash == NULL) { if (info->pctx.valHash == NULL) {
info->pctx.valHash = taosHashInit(FILTER_DEFAULT_GROUP_SIZE * FILTER_DEFAULT_VALUE_SIZE, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, false); info->pctx.valHash = taosHashInit(FILTER_DEFAULT_GROUP_SIZE * FILTER_DEFAULT_VALUE_SIZE, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, false);
} }
@ -855,10 +888,6 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type,
taosHashPut(info->pctx.valHash, *data, dataLen, &idx, sizeof(idx)); taosHashPut(info->pctx.valHash, *data, dataLen, &idx, sizeof(idx));
} }
} else { } else {
if (freeIfExists) {
tfree(desc);
}
if (data && freeIfExists) { if (data && freeIfExists) {
tfree(*data); tfree(*data);
} }
@ -873,7 +902,6 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type,
static FORCE_INLINE int32_t filterAddColFieldFromField(SFilterInfo *info, SFilterField *field, SFilterFieldId *fid) { static FORCE_INLINE int32_t filterAddColFieldFromField(SFilterInfo *info, SFilterField *field, SFilterFieldId *fid) {
filterAddField(info, field->desc, &field->data, FILTER_GET_TYPE(field->flag), fid, 0, false); filterAddField(info, field->desc, &field->data, FILTER_GET_TYPE(field->flag), fid, 0, false);
FILTER_SET_FLAG(field->flag, FLD_DESC_NO_FREE);
FILTER_SET_FLAG(field->flag, FLD_DATA_NO_FREE); FILTER_SET_FLAG(field->flag, FLD_DATA_NO_FREE);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -907,7 +935,7 @@ int32_t filterAddFieldFromNode(SFilterInfo *info, SNode *node, SFilterFieldId *f
} }
int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFilterFieldId *right, uint32_t *uidx) { int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFilterFieldId *right, uint32_t *uidx) {
if (FILTER_GET_FLAG(info->options, FI_OPTION_NEED_UNIQE)) { if (FILTER_GET_FLAG(info->options, FLT_OPTION_NEED_UNIQE)) {
if (info->pctx.unitHash == NULL) { if (info->pctx.unitHash == NULL) {
info->pctx.unitHash = taosHashInit(FILTER_DEFAULT_GROUP_SIZE * FILTER_DEFAULT_UNIT_SIZE, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, false); info->pctx.unitHash = taosHashInit(FILTER_DEFAULT_GROUP_SIZE * FILTER_DEFAULT_UNIT_SIZE, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, false);
} else { } else {
@ -940,7 +968,7 @@ int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFi
SFilterField *val = FILTER_UNIT_RIGHT_FIELD(info, u); SFilterField *val = FILTER_UNIT_RIGHT_FIELD(info, u);
assert(FILTER_GET_FLAG(val->flag, FLD_TYPE_VALUE)); assert(FILTER_GET_FLAG(val->flag, FLD_TYPE_VALUE));
} else { } else {
if(optr != TSDB_RELATION_ISNULL && optr != TSDB_RELATION_NOTNULL && optr != FILTER_DUMMY_EMPTY_OPTR){ if(optr != OP_TYPE_IS_NULL && optr != OP_TYPE_IS_NOT_NULL && optr != FILTER_DUMMY_EMPTY_OPTR){
return -1; return -1;
} }
} }
@ -952,7 +980,7 @@ int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFi
*uidx = info->unitNum; *uidx = info->unitNum;
if (FILTER_GET_FLAG(info->options, FI_OPTION_NEED_UNIQE)) { if (FILTER_GET_FLAG(info->options, FLT_OPTION_NEED_UNIQE)) {
int64_t v = 0; int64_t v = 0;
FILTER_PACKAGE_UNIT_HASH_KEY(&v, optr, left->idx, right ? right->idx : -1); FILTER_PACKAGE_UNIT_HASH_KEY(&v, optr, left->idx, right ? right->idx : -1);
taosHashPut(info->pctx.unitHash, &v, sizeof(v), uidx, sizeof(*uidx)); taosHashPut(info->pctx.unitHash, &v, sizeof(v), uidx, sizeof(*uidx));
@ -1010,7 +1038,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) {
filterAddField(info, NULL, &fdata, FLD_TYPE_VALUE, &right, len, true); filterAddField(info, NULL, &fdata, FLD_TYPE_VALUE, &right, len, true);
filterAddUnit(info, TSDB_RELATION_EQUAL, &left, &right, &uidx); filterAddUnit(info, OP_TYPE_EQUAL, &left, &right, &uidx);
SFilterGroup fgroup = {0}; SFilterGroup fgroup = {0};
filterAddUnitToGroup(&fgroup, uidx); filterAddUnitToGroup(&fgroup, uidx);
@ -1035,16 +1063,15 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) {
int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u, uint32_t *uidx) { int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u, uint32_t *uidx) {
SFilterFieldId left, right, *pright = &right; SFilterFieldId left, right, *pright = &right;
int32_t type = FILTER_UNIT_DATA_TYPE(u); int32_t type = FILTER_UNIT_DATA_TYPE(u);
uint16_t flag = FLD_DESC_NO_FREE; uint16_t flag = 0;
filterAddField(dst, FILTER_UNIT_COL_DESC(src, u), NULL, FLD_TYPE_COLUMN, &left, 0, false); filterAddField(dst, FILTER_UNIT_COL_DESC(src, u), NULL, FLD_TYPE_COLUMN, &left, 0, false);
SFilterField *t = FILTER_UNIT_LEFT_FIELD(src, u); SFilterField *t = FILTER_UNIT_LEFT_FIELD(src, u);
FILTER_SET_FLAG(t->flag, flag);
if (u->right.type == FLD_TYPE_VALUE) { if (u->right.type == FLD_TYPE_VALUE) {
void *data = FILTER_UNIT_VAL_DATA(src, u); void *data = FILTER_UNIT_VAL_DATA(src, u);
if (IS_VAR_DATA_TYPE(type)) { if (IS_VAR_DATA_TYPE(type)) {
if (FILTER_UNIT_OPTR(u) == TSDB_RELATION_IN) { if (FILTER_UNIT_OPTR(u) == OP_TYPE_IN) {
filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, POINTER_BYTES, false); // POINTER_BYTES should be sizeof(SHashObj), but POINTER_BYTES is also right. filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, POINTER_BYTES, false); // POINTER_BYTES should be sizeof(SHashObj), but POINTER_BYTES is also right.
t = FILTER_GET_FIELD(dst, right); t = FILTER_GET_FIELD(dst, right);
@ -1087,17 +1114,17 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
int32_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(dst, left)); int32_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(dst, left));
if (optr == TSDB_RELATION_AND) { if (optr == LOGIC_COND_TYPE_AND) {
if (ctx->isnull) { if (ctx->isnull) {
assert(ctx->notnull == false && ctx->isrange == false); assert(ctx->notnull == false && ctx->isrange == false);
filterAddUnit(dst, TSDB_RELATION_ISNULL, &left, NULL, &uidx); filterAddUnit(dst, OP_TYPE_IS_NULL, &left, NULL, &uidx);
filterAddUnitToGroup(g, uidx); filterAddUnitToGroup(g, uidx);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (ctx->notnull) { if (ctx->notnull) {
assert(ctx->isnull == false && ctx->isrange == false); assert(ctx->isnull == false && ctx->isrange == false);
filterAddUnit(dst, TSDB_RELATION_NOTNULL, &left, NULL, &uidx); filterAddUnit(dst, OP_TYPE_IS_NOT_NULL, &left, NULL, &uidx);
filterAddUnitToGroup(g, uidx); filterAddUnitToGroup(g, uidx);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -1119,7 +1146,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
void *data = malloc(sizeof(int64_t)); void *data = malloc(sizeof(int64_t));
SIMPLE_COPY_VALUES(data, &ra->s); SIMPLE_COPY_VALUES(data, &ra->s);
filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true);
filterAddUnit(dst, TSDB_RELATION_EQUAL, &left, &right, &uidx); filterAddUnit(dst, OP_TYPE_EQUAL, &left, &right, &uidx);
filterAddUnitToGroup(g, uidx); filterAddUnitToGroup(g, uidx);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else { } else {
@ -1130,8 +1157,8 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
SIMPLE_COPY_VALUES(data2, &ra->e); SIMPLE_COPY_VALUES(data2, &ra->e);
filterAddField(dst, NULL, &data2, FLD_TYPE_VALUE, &right2, tDataTypes[type].bytes, true); filterAddField(dst, NULL, &data2, FLD_TYPE_VALUE, &right2, tDataTypes[type].bytes, true);
filterAddUnit(dst, FILTER_GET_FLAG(ra->sflag, RANGE_FLG_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right, &uidx); filterAddUnit(dst, FILTER_GET_FLAG(ra->sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left, &right, &uidx);
filterAddUnitRight(dst, FILTER_GET_FLAG(ra->eflag, RANGE_FLG_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &right2, uidx); filterAddUnitRight(dst, FILTER_GET_FLAG(ra->eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &right2, uidx);
filterAddUnitToGroup(g, uidx); filterAddUnitToGroup(g, uidx);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -1141,7 +1168,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
void *data = malloc(sizeof(int64_t)); void *data = malloc(sizeof(int64_t));
SIMPLE_COPY_VALUES(data, &ra->s); SIMPLE_COPY_VALUES(data, &ra->s);
filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true);
filterAddUnit(dst, FILTER_GET_FLAG(ra->sflag, RANGE_FLG_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right, &uidx); filterAddUnit(dst, FILTER_GET_FLAG(ra->sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left, &right, &uidx);
filterAddUnitToGroup(g, uidx); filterAddUnitToGroup(g, uidx);
} }
@ -1149,7 +1176,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
void *data = malloc(sizeof(int64_t)); void *data = malloc(sizeof(int64_t));
SIMPLE_COPY_VALUES(data, &ra->e); SIMPLE_COPY_VALUES(data, &ra->e);
filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true);
filterAddUnit(dst, FILTER_GET_FLAG(ra->eflag, RANGE_FLG_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right, &uidx); filterAddUnit(dst, FILTER_GET_FLAG(ra->eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &left, &right, &uidx);
filterAddUnitToGroup(g, uidx); filterAddUnitToGroup(g, uidx);
} }
@ -1164,7 +1191,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
assert(ctx->isnull || ctx->notnull || ctx->isrange); assert(ctx->isnull || ctx->notnull || ctx->isrange);
if (ctx->isnull) { if (ctx->isnull) {
filterAddUnit(dst, TSDB_RELATION_ISNULL, &left, NULL, &uidx); filterAddUnit(dst, OP_TYPE_IS_NULL, &left, NULL, &uidx);
filterAddUnitToGroup(g, uidx); filterAddUnitToGroup(g, uidx);
taosArrayPush(res, g); taosArrayPush(res, g);
} }
@ -1173,7 +1200,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
assert(!ctx->isrange); assert(!ctx->isrange);
memset(g, 0, sizeof(*g)); memset(g, 0, sizeof(*g));
filterAddUnit(dst, TSDB_RELATION_NOTNULL, &left, NULL, &uidx); filterAddUnit(dst, OP_TYPE_IS_NOT_NULL, &left, NULL, &uidx);
filterAddUnitToGroup(g, uidx); filterAddUnitToGroup(g, uidx);
taosArrayPush(res, g); taosArrayPush(res, g);
} }
@ -1195,7 +1222,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
void *data = malloc(sizeof(int64_t)); void *data = malloc(sizeof(int64_t));
SIMPLE_COPY_VALUES(data, &r->ra.s); SIMPLE_COPY_VALUES(data, &r->ra.s);
filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true);
filterAddUnit(dst, TSDB_RELATION_EQUAL, &left, &right, &uidx); filterAddUnit(dst, OP_TYPE_EQUAL, &left, &right, &uidx);
filterAddUnitToGroup(g, uidx); filterAddUnitToGroup(g, uidx);
} else { } else {
void *data = malloc(sizeof(int64_t)); void *data = malloc(sizeof(int64_t));
@ -1205,8 +1232,8 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
SIMPLE_COPY_VALUES(data2, &r->ra.e); SIMPLE_COPY_VALUES(data2, &r->ra.e);
filterAddField(dst, NULL, &data2, FLD_TYPE_VALUE, &right2, tDataTypes[type].bytes, true); filterAddField(dst, NULL, &data2, FLD_TYPE_VALUE, &right2, tDataTypes[type].bytes, true);
filterAddUnit(dst, FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right, &uidx); filterAddUnit(dst, FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left, &right, &uidx);
filterAddUnitRight(dst, FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &right2, uidx); filterAddUnitRight(dst, FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &right2, uidx);
filterAddUnitToGroup(g, uidx); filterAddUnitToGroup(g, uidx);
} }
@ -1221,7 +1248,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
void *data = malloc(sizeof(int64_t)); void *data = malloc(sizeof(int64_t));
SIMPLE_COPY_VALUES(data, &r->ra.s); SIMPLE_COPY_VALUES(data, &r->ra.s);
filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true);
filterAddUnit(dst, FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right, &uidx); filterAddUnit(dst, FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left, &right, &uidx);
filterAddUnitToGroup(g, uidx); filterAddUnitToGroup(g, uidx);
} }
@ -1229,7 +1256,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
void *data = malloc(sizeof(int64_t)); void *data = malloc(sizeof(int64_t));
SIMPLE_COPY_VALUES(data, &r->ra.e); SIMPLE_COPY_VALUES(data, &r->ra.e);
filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true);
filterAddUnit(dst, FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right, &uidx); filterAddUnit(dst, FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &left, &right, &uidx);
filterAddUnitToGroup(g, uidx); filterAddUnitToGroup(g, uidx);
} }
@ -1262,7 +1289,7 @@ EDealRes fltTreeToGroup(SNode* pNode, void* pContext) {
SArray* preGroup = NULL; SArray* preGroup = NULL;
SArray* newGroup = NULL; SArray* newGroup = NULL;
SArray* resGroup = NULL; SArray* resGroup = NULL;
ENodeType nType = nodeType(nType); ENodeType nType = nodeType(pNode);
SFltBuildGroupCtx *ctx = (SFltBuildGroupCtx *)pContext; SFltBuildGroupCtx *ctx = (SFltBuildGroupCtx *)pContext;
if (QUERY_NODE_LOGIC_CONDITION == nodeType(pNode)) { if (QUERY_NODE_LOGIC_CONDITION == nodeType(pNode)) {
@ -1280,16 +1307,16 @@ EDealRes fltTreeToGroup(SNode* pNode, void* pContext) {
FLT_ERR_JRET(filterDetachCnfGroups(resGroup, preGroup, newGroup)); FLT_ERR_JRET(filterDetachCnfGroups(resGroup, preGroup, newGroup));
taosArrayDestroyEx(newGroup, filterFreeGroup); taosArrayDestroyEx(newGroup, filterFreeGroup);
newGroup = NULL;
taosArrayDestroyEx(preGroup, filterFreeGroup); taosArrayDestroyEx(preGroup, filterFreeGroup);
preGroup = resGroup; preGroup = resGroup;
resGroup = NULL;
} }
taosArrayAddAll(ctx->group, resGroup); taosArrayAddAll(ctx->group, preGroup);
taosArrayDestroyEx(newGroup, filterFreeGroup); taosArrayDestroy(preGroup);
taosArrayDestroyEx(preGroup, filterFreeGroup);
taosArrayDestroyEx(resGroup, filterFreeGroup);
return DEAL_RES_IGNORE_CHILD; return DEAL_RES_IGNORE_CHILD;
} }
@ -1312,7 +1339,7 @@ EDealRes fltTreeToGroup(SNode* pNode, void* pContext) {
if (QUERY_NODE_OPERATOR == nType) { if (QUERY_NODE_OPERATOR == nType) {
FLT_ERR_JRET(fltAddGroupUnitFromNode(ctx->info, pNode, ctx->group)); FLT_ERR_JRET(fltAddGroupUnitFromNode(ctx->info, pNode, ctx->group));
return DEAL_RES_CONTINUE; return DEAL_RES_IGNORE_CHILD;
} }
fltError("invalid node type for filter, type:%d", nodeType(pNode)); fltError("invalid node type for filter, type:%d", nodeType(pNode));
@ -1448,11 +1475,11 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
SFilterField *left = FILTER_UNIT_LEFT_FIELD(info, unit); SFilterField *left = FILTER_UNIT_LEFT_FIELD(info, unit);
SColumnRefNode *refNode = (SColumnRefNode *)left->desc; SColumnRefNode *refNode = (SColumnRefNode *)left->desc;
if (unit->compare.optr >= TSDB_RELATION_INVALID && unit->compare.optr <= TSDB_RELATION_NMATCH){ if (unit->compare.optr >= 0 && unit->compare.optr <= OP_TYPE_JSON_CONTAINS){
len = sprintf(str, "UNIT[%d] => [%d][%d] %s [", i, refNode->tupleId, refNode->slotId, gOptrStr[unit->compare.optr].str); len = sprintf(str, "UNIT[%d] => [%d][%d] %s [", i, refNode->tupleId, refNode->slotId, gOptrStr[unit->compare.optr].str);
} }
if (unit->right.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != TSDB_RELATION_IN) { if (unit->right.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != OP_TYPE_IN) {
SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit); SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit);
char *data = right->data; char *data = right->data;
if (IS_VAR_DATA_TYPE(type)) { if (IS_VAR_DATA_TYPE(type)) {
@ -1467,11 +1494,11 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
if (unit->compare.optr2) { if (unit->compare.optr2) {
strcat(str, " && "); strcat(str, " && ");
if (unit->compare.optr2 >= TSDB_RELATION_INVALID && unit->compare.optr2 <= TSDB_RELATION_NMATCH){ if (unit->compare.optr2 >= 0 && unit->compare.optr2 <= OP_TYPE_JSON_CONTAINS){
sprintf(str + strlen(str), "[%d][%d] %s [", refNode->tupleId, refNode->slotId, gOptrStr[unit->compare.optr2].str); sprintf(str + strlen(str), "[%d][%d] %s [", refNode->tupleId, refNode->slotId, gOptrStr[unit->compare.optr2].str);
} }
if (unit->right2.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != TSDB_RELATION_IN) { if (unit->right2.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != OP_TYPE_IN) {
SFilterField *right = FILTER_UNIT_RIGHT2_FIELD(info, unit); SFilterField *right = FILTER_UNIT_RIGHT2_FIELD(info, unit);
char *data = right->data; char *data = right->data;
if (IS_VAR_DATA_TYPE(type)) { if (IS_VAR_DATA_TYPE(type)) {
@ -1619,14 +1646,6 @@ void filterFreeField(SFilterField* field, int32_t type) {
return; return;
} }
if (!FILTER_GET_FLAG(field->flag, FLD_DESC_NO_FREE)) {
if (type == FLD_TYPE_VALUE) {
taosVariantDestroy(field->desc);
}
tfree(field->desc);
}
if (!FILTER_GET_FLAG(field->flag, FLD_DATA_NO_FREE)) { if (!FILTER_GET_FLAG(field->flag, FLD_DATA_NO_FREE)) {
if (FILTER_GET_FLAG(field->flag, FLD_DATA_IS_HASH)) { if (FILTER_GET_FLAG(field->flag, FLD_DATA_IS_HASH)) {
taosHashCleanup(field->data); taosHashCleanup(field->data);
@ -1688,15 +1707,15 @@ int32_t filterHandleValueExtInfo(SFilterUnit* unit, char extInfo) {
uint8_t optr = FILTER_UNIT_OPTR(unit); uint8_t optr = FILTER_UNIT_OPTR(unit);
switch (optr) { switch (optr) {
case TSDB_RELATION_GREATER: case OP_TYPE_GREATER_THAN:
case TSDB_RELATION_GREATER_EQUAL: case OP_TYPE_GREATER_EQUAL:
unit->compare.optr = (extInfo > 0) ? FILTER_DUMMY_EMPTY_OPTR : TSDB_RELATION_NOTNULL; unit->compare.optr = (extInfo > 0) ? FILTER_DUMMY_EMPTY_OPTR : OP_TYPE_IS_NOT_NULL;
break; break;
case TSDB_RELATION_LESS: case OP_TYPE_LOWER_THAN:
case TSDB_RELATION_LESS_EQUAL: case OP_TYPE_LOWER_EQUAL:
unit->compare.optr = (extInfo > 0) ? TSDB_RELATION_NOTNULL : FILTER_DUMMY_EMPTY_OPTR; unit->compare.optr = (extInfo > 0) ? OP_TYPE_IS_NOT_NULL : FILTER_DUMMY_EMPTY_OPTR;
break; break;
case TSDB_RELATION_EQUAL: case OP_TYPE_EQUAL:
unit->compare.optr = FILTER_DUMMY_EMPTY_OPTR; unit->compare.optr = FILTER_DUMMY_EMPTY_OPTR;
break; break;
default: default:
@ -1711,7 +1730,7 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
for (uint32_t i = 0; i < info->unitNum; ++i) { for (uint32_t i = 0; i < info->unitNum; ++i) {
SFilterUnit* unit = &info->units[i]; SFilterUnit* unit = &info->units[i];
if (unit->right.type != FLD_TYPE_VALUE) { if (unit->right.type != FLD_TYPE_VALUE) {
assert(unit->compare.optr == TSDB_RELATION_ISNULL || unit->compare.optr == TSDB_RELATION_NOTNULL || unit->compare.optr == FILTER_DUMMY_EMPTY_OPTR); assert(unit->compare.optr == OP_TYPE_IS_NULL || unit->compare.optr == OP_TYPE_IS_NOT_NULL || unit->compare.optr == FILTER_DUMMY_EMPTY_OPTR);
continue; continue;
} }
@ -1729,7 +1748,7 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
continue; continue;
} }
if (unit->compare.optr == TSDB_RELATION_IN) { if (unit->compare.optr == OP_TYPE_IN) {
FLT_ERR_RET(scalarGenerateSetFromList((void **)&fi->data, fi->desc, type)); FLT_ERR_RET(scalarGenerateSetFromList((void **)&fi->data, fi->desc, type));
if (fi->data == NULL) { if (fi->data == NULL) {
fltError("failed to convert in param"); fltError("failed to convert in param");
@ -1779,7 +1798,7 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
// match/nmatch for nchar type need convert from ucs4 to mbs // match/nmatch for nchar type need convert from ucs4 to mbs
if(type == TSDB_DATA_TYPE_NCHAR && if(type == TSDB_DATA_TYPE_NCHAR &&
(unit->compare.optr == TSDB_RELATION_MATCH || unit->compare.optr == TSDB_RELATION_NMATCH)){ (unit->compare.optr == OP_TYPE_MATCH || unit->compare.optr == OP_TYPE_NMATCH)){
char newValData[TSDB_REGEX_STRING_DEFAULT_LEN * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE] = {0}; char newValData[TSDB_REGEX_STRING_DEFAULT_LEN * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE] = {0};
int32_t len = taosUcs4ToMbs(varDataVal(fi->data), varDataLen(fi->data), varDataVal(newValData)); int32_t len = taosUcs4ToMbs(varDataVal(fi->data), varDataLen(fi->data), varDataVal(newValData));
if (len < 0){ if (len < 0){
@ -1799,40 +1818,40 @@ bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right)
int32_t ret = func(left, right); int32_t ret = func(left, right);
switch (optr) { switch (optr) {
case TSDB_RELATION_EQUAL: { case OP_TYPE_EQUAL: {
return ret == 0; return ret == 0;
} }
case TSDB_RELATION_NOT_EQUAL: { case OP_TYPE_NOT_EQUAL: {
return ret != 0; return ret != 0;
} }
case TSDB_RELATION_GREATER_EQUAL: { case OP_TYPE_GREATER_EQUAL: {
return ret >= 0; return ret >= 0;
} }
case TSDB_RELATION_GREATER: { case OP_TYPE_GREATER_THAN: {
return ret > 0; return ret > 0;
} }
case TSDB_RELATION_LESS_EQUAL: { case OP_TYPE_LOWER_EQUAL: {
return ret <= 0; return ret <= 0;
} }
case TSDB_RELATION_LESS: { case OP_TYPE_LOWER_THAN: {
return ret < 0; return ret < 0;
} }
case TSDB_RELATION_LIKE: { case OP_TYPE_LIKE: {
return ret == 0; return ret == 0;
} }
case TSDB_RELATION_NOT_LIKE: { case OP_TYPE_NOT_LIKE: {
return ret == 0; return ret == 0;
} }
case TSDB_RELATION_MATCH: { case OP_TYPE_MATCH: {
return ret == 0; return ret == 0;
} }
case TSDB_RELATION_NMATCH: { case OP_TYPE_NMATCH: {
return ret == 0; return ret == 0;
} }
case TSDB_RELATION_IN: { case OP_TYPE_IN: {
return ret == 1; return ret == 1;
} }
case TSDB_RELATION_NOT_IN: { case OP_TYPE_NOT_IN: {
return ret == 1; return ret == 1;
} }
@ -1852,25 +1871,25 @@ int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit* u, SFilterRangeCtx *c
int64_t tmp = 0; int64_t tmp = 0;
switch (uoptr) { switch (uoptr) {
case TSDB_RELATION_GREATER: case OP_TYPE_GREATER_THAN:
SIMPLE_COPY_VALUES(&ra.s, val); SIMPLE_COPY_VALUES(&ra.s, val);
FILTER_SET_FLAG(ra.sflag, RANGE_FLG_EXCLUDE); FILTER_SET_FLAG(ra.sflag, RANGE_FLG_EXCLUDE);
FILTER_SET_FLAG(ra.eflag, RANGE_FLG_NULL); FILTER_SET_FLAG(ra.eflag, RANGE_FLG_NULL);
break; break;
case TSDB_RELATION_GREATER_EQUAL: case OP_TYPE_GREATER_EQUAL:
SIMPLE_COPY_VALUES(&ra.s, val); SIMPLE_COPY_VALUES(&ra.s, val);
FILTER_SET_FLAG(ra.eflag, RANGE_FLG_NULL); FILTER_SET_FLAG(ra.eflag, RANGE_FLG_NULL);
break; break;
case TSDB_RELATION_LESS: case OP_TYPE_LOWER_THAN:
SIMPLE_COPY_VALUES(&ra.e, val); SIMPLE_COPY_VALUES(&ra.e, val);
FILTER_SET_FLAG(ra.eflag, RANGE_FLG_EXCLUDE); FILTER_SET_FLAG(ra.eflag, RANGE_FLG_EXCLUDE);
FILTER_SET_FLAG(ra.sflag, RANGE_FLG_NULL); FILTER_SET_FLAG(ra.sflag, RANGE_FLG_NULL);
break; break;
case TSDB_RELATION_LESS_EQUAL: case OP_TYPE_LOWER_EQUAL:
SIMPLE_COPY_VALUES(&ra.e, val); SIMPLE_COPY_VALUES(&ra.e, val);
FILTER_SET_FLAG(ra.sflag, RANGE_FLG_NULL); FILTER_SET_FLAG(ra.sflag, RANGE_FLG_NULL);
break; break;
case TSDB_RELATION_NOT_EQUAL: case OP_TYPE_NOT_EQUAL:
assert(type == TSDB_DATA_TYPE_BOOL); assert(type == TSDB_DATA_TYPE_BOOL);
if (GET_INT8_VAL(val)) { if (GET_INT8_VAL(val)) {
SIMPLE_COPY_VALUES(&ra.s, &tmp); SIMPLE_COPY_VALUES(&ra.s, &tmp);
@ -1881,7 +1900,7 @@ int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit* u, SFilterRangeCtx *c
SIMPLE_COPY_VALUES(&ra.e, &tmp); SIMPLE_COPY_VALUES(&ra.e, &tmp);
} }
break; break;
case TSDB_RELATION_EQUAL: case OP_TYPE_EQUAL:
SIMPLE_COPY_VALUES(&ra.s, val); SIMPLE_COPY_VALUES(&ra.s, val);
SIMPLE_COPY_VALUES(&ra.e, val); SIMPLE_COPY_VALUES(&ra.e, val);
break; break;
@ -1935,15 +1954,15 @@ int32_t filterMergeUnits(SFilterInfo *info, SFilterGroupCtx* gRes, uint32_t colI
SFilterUnit* u = taosArrayGetP(colArray, i); SFilterUnit* u = taosArrayGetP(colArray, i);
uint8_t optr = FILTER_UNIT_OPTR(u); uint8_t optr = FILTER_UNIT_OPTR(u);
filterAddRangeOptr(ctx, optr, TSDB_RELATION_AND, empty, NULL); filterAddRangeOptr(ctx, optr, LOGIC_COND_TYPE_AND, empty, NULL);
FLT_CHK_JMP(*empty); FLT_CHK_JMP(*empty);
if (!FILTER_NO_MERGE_OPTR(optr)) { if (!FILTER_NO_MERGE_OPTR(optr)) {
filterAddUnitRange(info, u, ctx, TSDB_RELATION_AND); filterAddUnitRange(info, u, ctx, LOGIC_COND_TYPE_AND);
FLT_CHK_JMP(MR_EMPTY_RES(ctx)); FLT_CHK_JMP(MR_EMPTY_RES(ctx));
} }
if(FILTER_UNIT_OPTR(u) == TSDB_RELATION_EQUAL && !FILTER_NO_MERGE_DATA_TYPE(FILTER_UNIT_DATA_TYPE(u))){ if(FILTER_UNIT_OPTR(u) == OP_TYPE_EQUAL && !FILTER_NO_MERGE_DATA_TYPE(FILTER_UNIT_DATA_TYPE(u))){
gRes->colInfo[colIdx].optr = TSDB_RELATION_EQUAL; gRes->colInfo[colIdx].optr = OP_TYPE_EQUAL;
SIMPLE_COPY_VALUES(&gRes->colInfo[colIdx].value, FILTER_UNIT_VAL_DATA(info, u)); SIMPLE_COPY_VALUES(&gRes->colInfo[colIdx].value, FILTER_UNIT_VAL_DATA(info, u));
} }
} }
@ -2063,7 +2082,7 @@ void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool
} }
// for long in operation // for long in operation
if (gRes1->colInfo[idx1].optr == TSDB_RELATION_EQUAL && gRes2->colInfo[idx2].optr == TSDB_RELATION_EQUAL) { if (gRes1->colInfo[idx1].optr == OP_TYPE_EQUAL && gRes2->colInfo[idx2].optr == OP_TYPE_EQUAL) {
SFilterRangeCtx* ctx = gRes1->colInfo[idx1].info; SFilterRangeCtx* ctx = gRes1->colInfo[idx1].info;
if (ctx->pCompareFunc(&gRes1->colInfo[idx1].value, &gRes2->colInfo[idx2].value)){ if (ctx->pCompareFunc(&gRes1->colInfo[idx1].value, &gRes2->colInfo[idx2].value)){
*conflict = true; *conflict = true;
@ -2139,7 +2158,7 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter
++merNum; ++merNum;
filterMergeTwoGroupsImpl(info, &ctx, TSDB_RELATION_OR, idx1, *gRes1, *gRes2, NULL, all); filterMergeTwoGroupsImpl(info, &ctx, LOGIC_COND_TYPE_OR, idx1, *gRes1, *gRes2, NULL, all);
FLT_CHK_JMP(*all); FLT_CHK_JMP(*all);
@ -2353,14 +2372,14 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum
oinfo.colRangeNum = 0; oinfo.colRangeNum = 0;
oinfo.colRange = NULL; oinfo.colRange = NULL;
FILTER_SET_FLAG(info->options, FI_OPTION_NEED_UNIQE); FILTER_SET_FLAG(info->options, FLT_OPTION_NEED_UNIQE);
filterInitUnitsFields(info); filterInitUnitsFields(info);
for (int32_t i = 0; i < gResNum; ++i) { for (int32_t i = 0; i < gResNum; ++i) {
res = gRes[i]; res = gRes[i];
optr = (res->colNum > 1) ? TSDB_RELATION_AND : TSDB_RELATION_OR; optr = (res->colNum > 1) ? LOGIC_COND_TYPE_AND : LOGIC_COND_TYPE_OR;
SFilterGroup ng = {0}; SFilterGroup ng = {0};
@ -2457,7 +2476,7 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_
assert(colInfo->type == RANGE_TYPE_MR_CTX); assert(colInfo->type == RANGE_TYPE_MR_CTX);
bool all = false; bool all = false;
filterSourceRangeFromCtx(info->colRange[m], colInfo->info, TSDB_RELATION_OR, NULL, &all); filterSourceRangeFromCtx(info->colRange[m], colInfo->info, LOGIC_COND_TYPE_OR, NULL, &all);
if (all) { if (all) {
filterFreeRangeCtx(info->colRange[m]); filterFreeRangeCtx(info->colRange[m]);
info->colRange[m] = NULL; info->colRange[m] = NULL;
@ -2572,20 +2591,20 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3
} }
if (pDataStatis[index].numOfNull <= 0) { if (pDataStatis[index].numOfNull <= 0) {
if (cunit->optr == TSDB_RELATION_ISNULL) { if (cunit->optr == OP_TYPE_IS_NULL) {
info->blkUnitRes[k] = -1; info->blkUnitRes[k] = -1;
rmUnit = 1; rmUnit = 1;
continue; continue;
} }
if (cunit->optr == TSDB_RELATION_NOTNULL) { if (cunit->optr == OP_TYPE_IS_NOT_NULL) {
info->blkUnitRes[k] = 1; info->blkUnitRes[k] = 1;
rmUnit = 1; rmUnit = 1;
continue; continue;
} }
} else { } else {
if (pDataStatis[index].numOfNull == numOfRows) { if (pDataStatis[index].numOfNull == numOfRows) {
if (cunit->optr == TSDB_RELATION_ISNULL) { if (cunit->optr == OP_TYPE_IS_NULL) {
info->blkUnitRes[k] = 1; info->blkUnitRes[k] = 1;
rmUnit = 1; rmUnit = 1;
continue; continue;
@ -2597,9 +2616,9 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3
} }
} }
if (cunit->optr == TSDB_RELATION_ISNULL || cunit->optr == TSDB_RELATION_NOTNULL if (cunit->optr == OP_TYPE_IS_NULL || cunit->optr == OP_TYPE_IS_NOT_NULL
|| cunit->optr == TSDB_RELATION_IN || cunit->optr == TSDB_RELATION_LIKE || cunit->optr == TSDB_RELATION_MATCH || cunit->optr == OP_TYPE_IN || cunit->optr == OP_TYPE_LIKE || cunit->optr == OP_TYPE_MATCH
|| cunit->optr == TSDB_RELATION_NOT_EQUAL) { || cunit->optr == OP_TYPE_NOT_EQUAL) {
continue; continue;
} }
@ -2629,8 +2648,8 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3
info->blkUnitRes[k] = 1; info->blkUnitRes[k] = 1;
rmUnit = 1; rmUnit = 1;
} else if ((!minRes) && (!maxRes)) { } else if ((!minRes) && (!maxRes)) {
minRes = filterDoCompare(gDataCompare[cunit->func], TSDB_RELATION_LESS_EQUAL, minVal, cunit->valData); minRes = filterDoCompare(gDataCompare[cunit->func], OP_TYPE_LOWER_EQUAL, minVal, cunit->valData);
maxRes = filterDoCompare(gDataCompare[cunit->func], TSDB_RELATION_GREATER_EQUAL, maxVal, cunit->valData2); maxRes = filterDoCompare(gDataCompare[cunit->func], OP_TYPE_GREATER_EQUAL, maxVal, cunit->valData2);
if (minRes && maxRes) { if (minRes && maxRes) {
continue; continue;
@ -2647,9 +2666,9 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3
info->blkUnitRes[k] = 1; info->blkUnitRes[k] = 1;
rmUnit = 1; rmUnit = 1;
} else if ((!minRes) && (!maxRes)) { } else if ((!minRes) && (!maxRes)) {
if (cunit->optr == TSDB_RELATION_EQUAL) { if (cunit->optr == OP_TYPE_EQUAL) {
minRes = filterDoCompare(gDataCompare[cunit->func], TSDB_RELATION_GREATER, minVal, cunit->valData); minRes = filterDoCompare(gDataCompare[cunit->func], OP_TYPE_GREATER_THAN, minVal, cunit->valData);
maxRes = filterDoCompare(gDataCompare[cunit->func], TSDB_RELATION_LESS, maxVal, cunit->valData); maxRes = filterDoCompare(gDataCompare[cunit->func], OP_TYPE_LOWER_THAN, maxVal, cunit->valData);
if (minRes || maxRes) { if (minRes || maxRes) {
info->blkUnitRes[k] = -1; info->blkUnitRes[k] = -1;
rmUnit = 1; rmUnit = 1;
@ -2753,11 +2772,11 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, int8_t** p,
uint8_t optr = cunit->optr; uint8_t optr = cunit->optr;
if (isNull(colData, cunit->dataType)) { if (isNull(colData, cunit->dataType)) {
(*p)[i] = optr == TSDB_RELATION_ISNULL ? true : false; (*p)[i] = optr == OP_TYPE_IS_NULL ? true : false;
} else { } else {
if (optr == TSDB_RELATION_NOTNULL) { if (optr == OP_TYPE_IS_NOT_NULL) {
(*p)[i] = 1; (*p)[i] = 1;
} else if (optr == TSDB_RELATION_ISNULL) { } else if (optr == OP_TYPE_IS_NULL) {
(*p)[i] = 0; (*p)[i] = 0;
} else if (cunit->rfunc >= 0) { } else if (cunit->rfunc >= 0) {
(*p)[i] = (*gRangeCompare[cunit->rfunc])(colData, colData, cunit->valData, cunit->valData2, gDataCompare[cunit->func]); (*p)[i] = (*gRangeCompare[cunit->rfunc])(colData, colData, cunit->valData, cunit->valData2, gDataCompare[cunit->func]);
@ -2959,7 +2978,7 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDa
} }
// match/nmatch for nchar type need convert from ucs4 to mbs // match/nmatch for nchar type need convert from ucs4 to mbs
if(info->cunits[uidx].dataType == TSDB_DATA_TYPE_NCHAR && (info->cunits[uidx].optr == TSDB_RELATION_MATCH || info->cunits[uidx].optr == TSDB_RELATION_NMATCH)){ if(info->cunits[uidx].dataType == TSDB_DATA_TYPE_NCHAR && (info->cunits[uidx].optr == OP_TYPE_MATCH || info->cunits[uidx].optr == OP_TYPE_NMATCH)){
char *newColData = calloc(info->cunits[uidx].dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1); char *newColData = calloc(info->cunits[uidx].dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1);
int32_t len = taosUcs4ToMbs(varDataVal(colData), varDataLen(colData), varDataVal(newColData)); int32_t len = taosUcs4ToMbs(varDataVal(colData), varDataLen(colData), varDataVal(newColData));
if (len < 0){ if (len < 0){
@ -3010,16 +3029,16 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDataAg
uint8_t optr = cunit->optr; uint8_t optr = cunit->optr;
if (colData == NULL || isNull(colData, cunit->dataType)) { if (colData == NULL || isNull(colData, cunit->dataType)) {
(*p)[i] = optr == TSDB_RELATION_ISNULL ? true : false; (*p)[i] = optr == OP_TYPE_IS_NULL ? true : false;
} else { } else {
if (optr == TSDB_RELATION_NOTNULL) { if (optr == OP_TYPE_IS_NOT_NULL) {
(*p)[i] = 1; (*p)[i] = 1;
} else if (optr == TSDB_RELATION_ISNULL) { } else if (optr == OP_TYPE_IS_NULL) {
(*p)[i] = 0; (*p)[i] = 0;
} else if (cunit->rfunc >= 0) { } else if (cunit->rfunc >= 0) {
(*p)[i] = (*gRangeCompare[cunit->rfunc])(colData, colData, cunit->valData, cunit->valData2, gDataCompare[cunit->func]); (*p)[i] = (*gRangeCompare[cunit->rfunc])(colData, colData, cunit->valData, cunit->valData2, gDataCompare[cunit->func]);
} else { } else {
if(cunit->dataType == TSDB_DATA_TYPE_NCHAR && (cunit->optr == TSDB_RELATION_MATCH || cunit->optr == TSDB_RELATION_NMATCH)){ if(cunit->dataType == TSDB_DATA_TYPE_NCHAR && (cunit->optr == OP_TYPE_MATCH || cunit->optr == OP_TYPE_NMATCH)){
char *newColData = calloc(cunit->dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1); char *newColData = calloc(cunit->dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1);
int32_t len = taosUcs4ToMbs(varDataVal(colData), varDataLen(colData), varDataVal(newColData)); int32_t len = taosUcs4ToMbs(varDataVal(colData), varDataLen(colData), varDataVal(newColData));
if (len < 0){ if (len < 0){
@ -3072,12 +3091,12 @@ int32_t filterSetExecFunc(SFilterInfo *info) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (info->units[0].compare.optr == TSDB_RELATION_ISNULL) { if (info->units[0].compare.optr == OP_TYPE_IS_NULL) {
info->func = filterExecuteImplIsNull; info->func = filterExecuteImplIsNull;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (info->units[0].compare.optr == TSDB_RELATION_NOTNULL) { if (info->units[0].compare.optr == OP_TYPE_IS_NOT_NULL) {
info->func = filterExecuteImplNotNull; info->func = filterExecuteImplNotNull;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -3173,7 +3192,7 @@ int32_t fltInitFromNode(SNode* tree, SFilterInfo *info, uint32_t options) {
FLT_ERR_JRET(fltInitValFieldData(info)); FLT_ERR_JRET(fltInitValFieldData(info));
if (!FILTER_GET_FLAG(info->options, FI_OPTION_NO_REWRITE)) { if (!FILTER_GET_FLAG(info->options, FLT_OPTION_NO_REWRITE)) {
filterDumpInfoToString(info, "Before preprocess", 0); filterDumpInfoToString(info, "Before preprocess", 0);
FLT_ERR_JRET(filterPreprocess(info)); FLT_ERR_JRET(filterPreprocess(info));
@ -3194,7 +3213,7 @@ int32_t fltInitFromNode(SNode* tree, SFilterInfo *info, uint32_t options) {
_return: _return:
qInfo("No filter, code:%d", code); qInfo("init from node failed, code:%d", code);
return code; return code;
} }
@ -3291,8 +3310,8 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t
int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) { int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) {
SFilterRange ra = {0}; SFilterRange ra = {0};
SFilterRangeCtx *prev = filterInitRangeCtx(TSDB_DATA_TYPE_TIMESTAMP, FI_OPTION_TIMESTAMP); SFilterRangeCtx *prev = filterInitRangeCtx(TSDB_DATA_TYPE_TIMESTAMP, FLT_OPTION_TIMESTAMP);
SFilterRangeCtx *tmpc = filterInitRangeCtx(TSDB_DATA_TYPE_TIMESTAMP, FI_OPTION_TIMESTAMP); SFilterRangeCtx *tmpc = filterInitRangeCtx(TSDB_DATA_TYPE_TIMESTAMP, FLT_OPTION_TIMESTAMP);
SFilterRangeCtx *cur = NULL; SFilterRangeCtx *cur = NULL;
int32_t num = 0; int32_t num = 0;
int32_t optr = 0; int32_t optr = 0;
@ -3303,10 +3322,10 @@ int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) {
SFilterGroup *group = &info->groups[i]; SFilterGroup *group = &info->groups[i];
if (group->unitNum > 1) { if (group->unitNum > 1) {
cur = tmpc; cur = tmpc;
optr = TSDB_RELATION_AND; optr = LOGIC_COND_TYPE_AND;
} else { } else {
cur = prev; cur = prev;
optr = TSDB_RELATION_OR; optr = LOGIC_COND_TYPE_OR;
} }
for (uint32_t u = 0; u < group->unitNum; ++u) { for (uint32_t u = 0; u < group->unitNum; ++u) {
@ -3315,7 +3334,7 @@ int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) {
uint8_t raOptr = FILTER_UNIT_OPTR(unit); uint8_t raOptr = FILTER_UNIT_OPTR(unit);
filterAddRangeOptr(cur, raOptr, TSDB_RELATION_AND, &empty, NULL); filterAddRangeOptr(cur, raOptr, LOGIC_COND_TYPE_AND, &empty, NULL);
FLT_CHK_JMP(empty); FLT_CHK_JMP(empty);
if (FILTER_NO_MERGE_OPTR(raOptr)) { if (FILTER_NO_MERGE_OPTR(raOptr)) {
@ -3338,7 +3357,7 @@ int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) {
} }
if (group->unitNum > 1) { if (group->unitNum > 1) {
filterSourceRangeFromCtx(prev, cur, TSDB_RELATION_OR, &empty, &all); filterSourceRangeFromCtx(prev, cur, LOGIC_COND_TYPE_OR, &empty, &all);
filterResetRangeCtx(cur); filterResetRangeCtx(cur);
if (all) { if (all) {
break; break;
@ -3469,7 +3488,7 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
if (QUERY_NODE_VALUE == nodeType(*pNode)) { if (QUERY_NODE_VALUE == nodeType(*pNode) || QUERY_NODE_NODE_LIST == nodeType(*pNode) || QUERY_NODE_COLUMN_REF == nodeType(*pNode)) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
@ -3623,7 +3642,7 @@ _return:
FLT_RET(code); FLT_RET(code);
} }
FORCE_INLINE bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnDataAgg *statis, int16_t numOfCols) { bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnDataAgg *statis, int16_t numOfCols) {
if (info->scalarMode) { if (info->scalarMode) {
SScalarParam output = {0}; SScalarParam output = {0};
FLT_ERR_RET(scalarCalculate(info->sclCtx.node, pSrc, &output)); FLT_ERR_RET(scalarCalculate(info->sclCtx.node, pSrc, &output));

View File

@ -268,9 +268,6 @@ static void setScalarFuncParam(SScalarParam* param, int32_t type, int32_t bytes,
param->data = pInput; param->data = pInput;
} }
bool isStringOp(int32_t op) {
return op == TSDB_BINARY_OP_CONCAT;
}
#if 0 #if 0
int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarFuncParam* pOutput, void* param, int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarFuncParam* pOutput, void* param,

View File

@ -23,6 +23,7 @@
#include "query.h" #include "query.h"
#include "sclInt.h" #include "sclInt.h"
#include "tep.h" #include "tep.h"
#include "filter.h"
//GET_TYPED_DATA(v, double, pRight->type, (char *)&((right)[i])); //GET_TYPED_DATA(v, double, pRight->type, (char *)&((right)[i]));
@ -1380,51 +1381,51 @@ void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t
} }
void vectorGreater(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { void vectorGreater(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
vectorCompare(pLeft, pRight, out, _ord, TSDB_RELATION_GREATER); vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_GREATER_THAN);
} }
void vectorGreaterEqual(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { void vectorGreaterEqual(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
vectorCompare(pLeft, pRight, out, _ord, TSDB_RELATION_GREATER_EQUAL); vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_GREATER_EQUAL);
} }
void vectorLower(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { void vectorLower(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
vectorCompare(pLeft, pRight, out, _ord, TSDB_RELATION_LESS); vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_LOWER_THAN);
} }
void vectorLowerEqual(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { void vectorLowerEqual(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
vectorCompare(pLeft, pRight, out, _ord, TSDB_RELATION_LESS_EQUAL); vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_LOWER_EQUAL);
} }
void vectorEqual(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { void vectorEqual(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
vectorCompare(pLeft, pRight, out, _ord, TSDB_RELATION_EQUAL); vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_EQUAL);
} }
void vectorNotEqual(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { void vectorNotEqual(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
vectorCompare(pLeft, pRight, out, _ord, TSDB_RELATION_NOT_EQUAL); vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_NOT_EQUAL);
} }
void vectorIn(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { void vectorIn(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
vectorCompare(pLeft, pRight, out, _ord, TSDB_RELATION_IN); vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_IN);
} }
void vectorNotIn(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { void vectorNotIn(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
vectorCompare(pLeft, pRight, out, _ord, TSDB_RELATION_NOT_IN); vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_NOT_IN);
} }
void vectorLike(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { void vectorLike(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
vectorCompare(pLeft, pRight, out, _ord, TSDB_RELATION_LIKE); vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_LIKE);
} }
void vectorNotLike(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { void vectorNotLike(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
vectorCompare(pLeft, pRight, out, _ord, TSDB_RELATION_NOT_LIKE); vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_NOT_LIKE);
} }
void vectorMatch(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { void vectorMatch(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
vectorCompare(pLeft, pRight, out, _ord, TSDB_RELATION_MATCH); vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_MATCH);
} }
void vectorNotMatch(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { void vectorNotMatch(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
vectorCompare(pLeft, pRight, out, _ord, TSDB_RELATION_NMATCH); vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_NMATCH);
} }
void vectorIsNull(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { void vectorIsNull(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
@ -1543,6 +1544,4 @@ _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) {
} }
} }
bool isBinaryStringOp(int32_t op) {
return op == TSDB_BINARY_OP_CONCAT;
}

View File

@ -466,7 +466,7 @@ int32_t compareWStrPatternNotMatch(const void* pLeft, const void* pRight) {
__compar_fn_t getComparFunc(int32_t type, int32_t optr) { __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
__compar_fn_t comparFn = NULL; __compar_fn_t comparFn = NULL;
if (optr == TSDB_RELATION_IN && (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR)) { if (optr == OP_TYPE_IN && (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR)) {
switch (type) { switch (type) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
@ -489,7 +489,7 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
} }
} }
if (optr == TSDB_RELATION_NOT_IN && (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR)) { if (optr == OP_TYPE_NOT_IN && (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR)) {
switch (type) { switch (type) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
@ -522,17 +522,17 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
case TSDB_DATA_TYPE_FLOAT: comparFn = compareFloatVal; break; case TSDB_DATA_TYPE_FLOAT: comparFn = compareFloatVal; break;
case TSDB_DATA_TYPE_DOUBLE: comparFn = compareDoubleVal; break; case TSDB_DATA_TYPE_DOUBLE: comparFn = compareDoubleVal; break;
case TSDB_DATA_TYPE_BINARY: { case TSDB_DATA_TYPE_BINARY: {
if (optr == TSDB_RELATION_MATCH) { if (optr == OP_TYPE_MATCH) {
comparFn = compareStrRegexCompMatch; comparFn = compareStrRegexCompMatch;
} else if (optr == TSDB_RELATION_NMATCH) { } else if (optr == OP_TYPE_NMATCH) {
comparFn = compareStrRegexCompNMatch; comparFn = compareStrRegexCompNMatch;
} else if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */ } else if (optr == OP_TYPE_LIKE) { /* wildcard query using like operator */
comparFn = compareStrPatternMatch; comparFn = compareStrPatternMatch;
} else if (optr == TSDB_RELATION_NOT_LIKE) { /* wildcard query using like operator */ } else if (optr == OP_TYPE_NOT_LIKE) { /* wildcard query using like operator */
comparFn = compareStrPatternNotMatch; comparFn = compareStrPatternNotMatch;
} else if (optr == TSDB_RELATION_IN) { } else if (optr == OP_TYPE_IN) {
comparFn = compareChkInString; comparFn = compareChkInString;
} else if (optr == TSDB_RELATION_NOT_IN) { } else if (optr == OP_TYPE_NOT_IN) {
comparFn = compareChkNotInString; comparFn = compareChkNotInString;
} else { /* normal relational comparFn */ } else { /* normal relational comparFn */
comparFn = compareLenPrefixedStr; comparFn = compareLenPrefixedStr;
@ -542,17 +542,17 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
} }
case TSDB_DATA_TYPE_NCHAR: { case TSDB_DATA_TYPE_NCHAR: {
if (optr == TSDB_RELATION_MATCH) { if (optr == OP_TYPE_MATCH) {
comparFn = compareStrRegexCompMatch; comparFn = compareStrRegexCompMatch;
} else if (optr == TSDB_RELATION_NMATCH) { } else if (optr == OP_TYPE_NMATCH) {
comparFn = compareStrRegexCompNMatch; comparFn = compareStrRegexCompNMatch;
} else if (optr == TSDB_RELATION_LIKE) { } else if (optr == OP_TYPE_LIKE) {
comparFn = compareWStrPatternMatch; comparFn = compareWStrPatternMatch;
} else if (optr == TSDB_RELATION_NOT_LIKE) { } else if (optr == OP_TYPE_NOT_LIKE) {
comparFn = compareWStrPatternNotMatch; comparFn = compareWStrPatternNotMatch;
} else if (optr == TSDB_RELATION_IN) { } else if (optr == OP_TYPE_IN) {
comparFn = compareChkInString; comparFn = compareChkInString;
} else if (optr == TSDB_RELATION_NOT_IN) { } else if (optr == OP_TYPE_NOT_IN) {
comparFn = compareChkNotInString; comparFn = compareChkNotInString;
} else { } else {
comparFn = compareLenPrefixedWStr; comparFn = compareLenPrefixedWStr;