提交 75ede63c 编写于 作者: D dapan1121

feature/qnode

上级 de41059d
...@@ -23,8 +23,12 @@ ...@@ -23,8 +23,12 @@
extern "C" { extern "C" {
#endif #endif
int32_t compareStrPatternComp(const void* pLeft, const void* pRight); int32_t compareStrPatternMatch(const void* pLeft, const void* pRight);
int32_t compareWStrPatternComp(const void* pLeft, const void* pRight); 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);
__compar_fn_t getComparFunc(int32_t type, int32_t optr); __compar_fn_t getComparFunc(int32_t type, int32_t optr);
__compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order); __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); int32_t doCompare(const char* a, const char* b, int32_t type, size_t size);
...@@ -33,4 +37,4 @@ int32_t doCompare(const char* a, const char* b, int32_t type, size_t size) ...@@ -33,4 +37,4 @@ int32_t doCompare(const char* a, const char* b, int32_t type, size_t size)
} }
#endif #endif
#endif /*_TD_TCOMPARE_H_*/ #endif /*_TD_TCOMPARE_H_*/
\ No newline at end of file
...@@ -78,9 +78,12 @@ typedef struct { ...@@ -78,9 +78,12 @@ typedef struct {
case TSDB_DATA_TYPE_UINT: \ case TSDB_DATA_TYPE_UINT: \
(_v) = (_finalType)GET_UINT32_VAL(_data); \ (_v) = (_finalType)GET_UINT32_VAL(_data); \
break; \ break; \
default: \ case TSDB_DATA_TYPE_INT: \
(_v) = (_finalType)GET_INT32_VAL(_data); \ (_v) = (_finalType)GET_INT32_VAL(_data); \
break; \ break; \
default: \
(_v) = (_finalType)varDataLen(_data); \
break; \
} \ } \
} while (0) } while (0)
...@@ -115,9 +118,13 @@ typedef struct { ...@@ -115,9 +118,13 @@ typedef struct {
case TSDB_DATA_TYPE_UINT: \ case TSDB_DATA_TYPE_UINT: \
*(uint32_t *)(_v) = (uint32_t)(_data); \ *(uint32_t *)(_v) = (uint32_t)(_data); \
break; \ break; \
default: \ case TSDB_DATA_TYPE_INT: \
*(int32_t *)(_v) = (int32_t)(_data); \ *(int32_t *)(_v) = (int32_t)(_data); \
break; \ break; \
default: \
(void *)(_v) = (void *)(_data); \
(void *)(_data) = NULL; \
break; \
} \ } \
} while (0) } while (0)
...@@ -138,6 +145,9 @@ typedef struct { ...@@ -138,6 +145,9 @@ typedef struct {
#define IS_VALID_FLOAT(_t) ((_t) >= -FLT_MAX && (_t) <= FLT_MAX) #define IS_VALID_FLOAT(_t) ((_t) >= -FLT_MAX && (_t) <= FLT_MAX)
#define IS_VALID_DOUBLE(_t) ((_t) >= -DBL_MAX && (_t) <= DBL_MAX) #define IS_VALID_DOUBLE(_t) ((_t) >= -DBL_MAX && (_t) <= DBL_MAX)
#define IS_CONVERT_AS_SIGNED(_t) (IS_SIGNED_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL) || (_t) == (TSDB_DATA_TYPE_TIMESTAMP))
#define IS_CONVERT_AS_UNSIGNED(_t) (IS_UNSIGNED_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL))
static FORCE_INLINE bool isNull(const void *val, int32_t type) { static FORCE_INLINE bool isNull(const void *val, int32_t type) {
switch (type) { switch (type) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
...@@ -205,6 +215,7 @@ void* getDataMax(int32_t type); ...@@ -205,6 +215,7 @@ void* getDataMax(int32_t type);
#define SET_DOUBLE_NULL(v) (*(uint64_t *)(v) = TSDB_DATA_DOUBLE_NULL) #define SET_DOUBLE_NULL(v) (*(uint64_t *)(v) = TSDB_DATA_DOUBLE_NULL)
#define SET_BIGINT_NULL(v) (*(uint64_t *)(v) = TSDB_DATA_BIGINT_NULL)
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -118,6 +118,13 @@ typedef struct SFuncExecFuncs { ...@@ -118,6 +118,13 @@ typedef struct SFuncExecFuncs {
FExecFinalize finalize; FExecFinalize finalize;
} SFuncExecFuncs; } SFuncExecFuncs;
typedef int32_t (*FScalarExecProcess)(SScalarFuncParam *pInput, int32_t inputNum, SScalarFuncParam *pOutput);
typedef struct SScalarFuncExecFuncs {
FScalarExecProcess process;
} SScalarFuncExecFuncs;
int32_t fmFuncMgtInit(); int32_t fmFuncMgtInit();
int32_t fmGetHandle(FuncMgtHandle* pHandle); int32_t fmGetHandle(FuncMgtHandle* pHandle);
...@@ -136,7 +143,8 @@ bool fmIsTimeorderFunc(int32_t funcId); ...@@ -136,7 +143,8 @@ bool fmIsTimeorderFunc(int32_t funcId);
int32_t fmFuncScanType(int32_t funcId); int32_t fmFuncScanType(int32_t funcId);
int32_t fmGetFuncExecFuncs(FuncMgtHandle handle, int32_t funcId, SFuncExecFuncs* pFpSet); int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet);
int32_t fmGetScalarFuncExecFuncs(int32_t funcId, SScalarFuncExecFuncs* pFpSet);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -93,6 +93,10 @@ typedef enum EOperatorType { ...@@ -93,6 +93,10 @@ typedef enum EOperatorType {
OP_TYPE_NOT_LIKE, OP_TYPE_NOT_LIKE,
OP_TYPE_MATCH, OP_TYPE_MATCH,
OP_TYPE_NMATCH, OP_TYPE_NMATCH,
OP_TYPE_ISNULL,
OP_TYPE_NOTNULL,
OP_TYPE_BIT_AND,
OP_TYPE_BIT_OR,
// json operator // json operator
OP_TYPE_JSON_GET_VALUE, OP_TYPE_JSON_GET_VALUE,
...@@ -277,4 +281,4 @@ bool nodesIsTimelineQuery(const SNode* pQuery); ...@@ -277,4 +281,4 @@ bool nodesIsTimelineQuery(const SNode* pQuery);
} }
#endif #endif
#endif /*_TD_QUERY_NODES_H_*/ #endif /*_TD_QUERY_NODES_H_*/
\ No newline at end of file
...@@ -49,10 +49,19 @@ int32_t WCSPatternMatch(const wchar_t *pattern, const wchar_t *str, size_t size, ...@@ -49,10 +49,19 @@ int32_t WCSPatternMatch(const wchar_t *pattern, const wchar_t *str, size_t size,
int32_t taosArrayCompareString(const void *a, const void *b); int32_t taosArrayCompareString(const void *a, const void *b);
int32_t setCompareBytes1(const void *pLeft, const void *pRight); int32_t setChkInBytes1(const void *pLeft, const void *pRight);
int32_t setCompareBytes2(const void *pLeft, const void *pRight); int32_t setChkInBytes2(const void *pLeft, const void *pRight);
int32_t setCompareBytes4(const void *pLeft, const void *pRight); int32_t setChkInBytes4(const void *pLeft, const void *pRight);
int32_t setCompareBytes8(const void *pLeft, const void *pRight); int32_t setChkInBytes8(const void *pLeft, const void *pRight);
int32_t setChkNotInBytes1(const void *pLeft, const void *pRight);
int32_t setChkNotInBytes2(const void *pLeft, const void *pRight);
int32_t setChkNotInBytes4(const void *pLeft, const void *pRight);
int32_t setChkNotInBytes8(const void *pLeft, const void *pRight);
int32_t compareChkInString(const void *pLeft, const void *pRight);
int32_t compareChkNotInString(const void *pLeft, const void *pRight);
int32_t compareInt8Val(const void *pLeft, const void *pRight); int32_t compareInt8Val(const void *pLeft, const void *pRight);
int32_t compareInt16Val(const void *pLeft, const void *pRight); int32_t compareInt16Val(const void *pLeft, const void *pRight);
...@@ -74,7 +83,6 @@ int32_t compareStrRegexComp(const void *pLeft, const void *pRight); ...@@ -74,7 +83,6 @@ int32_t compareStrRegexComp(const void *pLeft, const void *pRight);
int32_t compareStrRegexCompMatch(const void *pLeft, const void *pRight); int32_t compareStrRegexCompMatch(const void *pLeft, const void *pRight);
int32_t compareStrRegexCompNMatch(const void *pLeft, const void *pRight); int32_t compareStrRegexCompNMatch(const void *pLeft, const void *pRight);
int32_t compareFindItemInSet(const void *pLeft, const void *pRight);
int32_t compareInt8ValDesc(const void *pLeft, const void *pRight); int32_t compareInt8ValDesc(const void *pLeft, const void *pRight);
int32_t compareInt16ValDesc(const void *pLeft, const void *pRight); int32_t compareInt16ValDesc(const void *pLeft, const void *pRight);
......
...@@ -118,16 +118,18 @@ do { \ ...@@ -118,16 +118,18 @@ do { \
#define TSDB_RELATION_GREATER_EQUAL 5 #define TSDB_RELATION_GREATER_EQUAL 5
#define TSDB_RELATION_NOT_EQUAL 6 #define TSDB_RELATION_NOT_EQUAL 6
#define TSDB_RELATION_LIKE 7 #define TSDB_RELATION_LIKE 7
#define TSDB_RELATION_ISNULL 8 #define TSDB_RELATION_NOT_LIKE 8
#define TSDB_RELATION_NOTNULL 9 #define TSDB_RELATION_ISNULL 9
#define TSDB_RELATION_IN 10 #define TSDB_RELATION_NOTNULL 10
#define TSDB_RELATION_IN 11
#define TSDB_RELATION_AND 11 #define TSDB_RELATION_NOT_IN 12
#define TSDB_RELATION_OR 12
#define TSDB_RELATION_NOT 13 #define TSDB_RELATION_AND 13
#define TSDB_RELATION_OR 14
#define TSDB_RELATION_MATCH 14 #define TSDB_RELATION_NOT 15
#define TSDB_RELATION_NMATCH 15
#define TSDB_RELATION_MATCH 16
#define TSDB_RELATION_NMATCH 17
#define TSDB_BINARY_OP_ADD 4000 #define TSDB_BINARY_OP_ADD 4000
#define TSDB_BINARY_OP_SUBTRACT 4001 #define TSDB_BINARY_OP_SUBTRACT 4001
......
...@@ -66,6 +66,7 @@ static FORCE_INLINE double taos_align_get_double(const char *pBuf) { ...@@ -66,6 +66,7 @@ static FORCE_INLINE double taos_align_get_double(const char *pBuf) {
// #else // #else
#define GET_FLOAT_VAL(x) (*(float *)(x)) #define GET_FLOAT_VAL(x) (*(float *)(x))
#define GET_DOUBLE_VAL(x) (*(double *)(x)) #define GET_DOUBLE_VAL(x) (*(double *)(x))
#define SET_BIGINT_VAL(x, y) { (*(int64_t *)(x)) = (int64_t)(y); }
#define SET_FLOAT_VAL(x, y) { (*(float *)(x)) = (float)(y); } #define SET_FLOAT_VAL(x, y) { (*(float *)(x)) = (float)(y); }
#define SET_DOUBLE_VAL(x, y) { (*(double *)(x)) = (double)(y); } #define SET_DOUBLE_VAL(x, y) { (*(double *)(x)) = (double)(y); }
#define SET_FLOAT_PTR(x, y) { (*(float *)(x)) = (*(float *)(y)); } #define SET_FLOAT_PTR(x, y) { (*(float *)(x)) = (*(float *)(y)); }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "tcompare.h" #include "tcompare.h"
int32_t compareStrPatternComp(const void* pLeft, const void* pRight) { int32_t compareStrPatternMatch(const void* pLeft, const void* pRight) {
SPatternCompareInfo pInfo = {'%', '_'}; SPatternCompareInfo pInfo = {'%', '_'};
assert(varDataLen(pRight) <= TSDB_MAX_FIELD_LEN); assert(varDataLen(pRight) <= TSDB_MAX_FIELD_LEN);
...@@ -33,7 +33,11 @@ int32_t compareStrPatternComp(const void* pLeft, const void* pRight) { ...@@ -33,7 +33,11 @@ int32_t compareStrPatternComp(const void* pLeft, const void* pRight) {
return (ret == TSDB_PATTERN_MATCH) ? 0 : 1; return (ret == TSDB_PATTERN_MATCH) ? 0 : 1;
} }
int32_t compareWStrPatternComp(const void* pLeft, const void* pRight) { int32_t compareStrPatternNotMatch(const void* pLeft, const void* pRight) {
return compareStrPatternMatch(pLeft, pRight) ? 0 : 1;
}
int32_t compareWStrPatternMatch(const void* pLeft, const void* pRight) {
SPatternCompareInfo pInfo = {'%', '_'}; SPatternCompareInfo pInfo = {'%', '_'};
assert(varDataLen(pRight) <= TSDB_MAX_FIELD_LEN * TSDB_NCHAR_SIZE); assert(varDataLen(pRight) <= TSDB_MAX_FIELD_LEN * TSDB_NCHAR_SIZE);
...@@ -47,6 +51,10 @@ int32_t compareWStrPatternComp(const void* pLeft, const void* pRight) { ...@@ -47,6 +51,10 @@ int32_t compareWStrPatternComp(const void* pLeft, const void* pRight) {
return (ret == TSDB_PATTERN_MATCH) ? 0 : 1; return (ret == TSDB_PATTERN_MATCH) ? 0 : 1;
} }
int32_t compareWStrPatternNotMatch(const void* pLeft, const void* pRight) {
return compareWStrPatternMatch(pLeft, pRight) ? 0 : 1;
}
__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;
...@@ -55,19 +63,42 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) { ...@@ -55,19 +63,42 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_UTINYINT:
return setCompareBytes1; return setChkInBytes1;
case TSDB_DATA_TYPE_SMALLINT: case TSDB_DATA_TYPE_SMALLINT:
case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_USMALLINT:
return setCompareBytes2; return setChkInBytes2;
case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_INT:
case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_UINT:
case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_FLOAT:
return setCompareBytes4; return setChkInBytes4;
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_UBIGINT:
case TSDB_DATA_TYPE_DOUBLE: case TSDB_DATA_TYPE_DOUBLE:
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
return setCompareBytes8; return setChkInBytes8;
default:
assert(0);
}
}
if (optr == TSDB_RELATION_NOT_IN && (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR)) {
switch (type) {
case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_UTINYINT:
return setChkNotInBytes1;
case TSDB_DATA_TYPE_SMALLINT:
case TSDB_DATA_TYPE_USMALLINT:
return setChkNotInBytes2;
case TSDB_DATA_TYPE_INT:
case TSDB_DATA_TYPE_UINT:
case TSDB_DATA_TYPE_FLOAT:
return setChkNotInBytes4;
case TSDB_DATA_TYPE_BIGINT:
case TSDB_DATA_TYPE_UBIGINT:
case TSDB_DATA_TYPE_DOUBLE:
case TSDB_DATA_TYPE_TIMESTAMP:
return setChkNotInBytes8;
default: default:
assert(0); assert(0);
} }
...@@ -88,9 +119,13 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) { ...@@ -88,9 +119,13 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
} else if (optr == TSDB_RELATION_NMATCH) { } else if (optr == TSDB_RELATION_NMATCH) {
comparFn = compareStrRegexCompNMatch; comparFn = compareStrRegexCompNMatch;
} else if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */ } else if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */
comparFn = compareStrPatternComp; comparFn = compareStrPatternMatch;
} else if (optr == TSDB_RELATION_NOT_LIKE) { /* wildcard query using like operator */
comparFn = compareStrPatternNotMatch;
} else if (optr == TSDB_RELATION_IN) { } else if (optr == TSDB_RELATION_IN) {
comparFn = compareFindItemInSet; comparFn = compareChkInString;
} else if (optr == TSDB_RELATION_NOT_IN) {
comparFn = compareChkNotInString;
} else { /* normal relational comparFn */ } else { /* normal relational comparFn */
comparFn = compareLenPrefixedStr; comparFn = compareLenPrefixedStr;
} }
...@@ -104,9 +139,13 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) { ...@@ -104,9 +139,13 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
} else if (optr == TSDB_RELATION_NMATCH) { } else if (optr == TSDB_RELATION_NMATCH) {
comparFn = compareStrRegexCompNMatch; comparFn = compareStrRegexCompNMatch;
} else if (optr == TSDB_RELATION_LIKE) { } else if (optr == TSDB_RELATION_LIKE) {
comparFn = compareWStrPatternComp; comparFn = compareWStrPatternMatch;
} else if (optr == TSDB_RELATION_NOT_LIKE) {
comparFn = compareWStrPatternNotMatch;
} else if (optr == TSDB_RELATION_IN) { } else if (optr == TSDB_RELATION_IN) {
comparFn = compareFindItemInSet; comparFn = compareChkInString;
} else if (optr == TSDB_RELATION_NOT_IN) {
comparFn = compareChkNotInString;
} else { } else {
comparFn = compareLenPrefixedWStr; comparFn = compareLenPrefixedWStr;
} }
...@@ -218,4 +257,4 @@ int32_t doCompare(const char* f1, const char* f2, int32_t type, size_t size) { ...@@ -218,4 +257,4 @@ int32_t doCompare(const char* f1, const char* f2, int32_t type, size_t size) {
} }
} }
} }
} }
\ No newline at end of file
...@@ -156,9 +156,11 @@ int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) { ...@@ -156,9 +156,11 @@ int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) {
} }
__compar_fn_t gDataCompare[] = {compareInt32Val, compareInt8Val, compareInt16Val, compareInt64Val, compareFloatVal, __compar_fn_t gDataCompare[] = {compareInt32Val, compareInt8Val, compareInt16Val, compareInt64Val, compareFloatVal,
compareDoubleVal, compareLenPrefixedStr, compareStrPatternComp, compareFindItemInSet, compareWStrPatternComp, compareDoubleVal, compareLenPrefixedStr, compareStrPatternMatch, compareChkInString, compareWStrPatternMatch,
compareLenPrefixedWStr, compareUint8Val, compareUint16Val, compareUint32Val, compareUint64Val, compareLenPrefixedWStr, compareUint8Val, compareUint16Val, compareUint32Val, compareUint64Val,
setCompareBytes1, setCompareBytes2, setCompareBytes4, setCompareBytes8, compareStrRegexCompMatch, compareStrRegexCompNMatch setChkInBytes1, setChkInBytes2, setChkInBytes4, setChkInBytes8, compareStrRegexCompMatch,
compareStrRegexCompNMatch, setChkNotInBytes1, setChkNotInBytes2, setChkNotInBytes4, setChkNotInBytes8,
compareChkNotInString, compareStrPatternNotMatch, compareWStrPatternNotMatch
}; };
int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
...@@ -186,6 +188,29 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { ...@@ -186,6 +188,29 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
assert(0); assert(0);
} }
} }
if (optr == TSDB_RELATION_NOT_IN && (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR)) {
switch (type) {
case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_UTINYINT:
return 21;
case TSDB_DATA_TYPE_SMALLINT:
case TSDB_DATA_TYPE_USMALLINT:
return 22;
case TSDB_DATA_TYPE_INT:
case TSDB_DATA_TYPE_UINT:
case TSDB_DATA_TYPE_FLOAT:
return 23;
case TSDB_DATA_TYPE_BIGINT:
case TSDB_DATA_TYPE_UBIGINT:
case TSDB_DATA_TYPE_DOUBLE:
case TSDB_DATA_TYPE_TIMESTAMP:
return 24;
default:
assert(0);
}
}
switch (type) { switch (type) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
...@@ -203,8 +228,12 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { ...@@ -203,8 +228,12 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
comparFn = 20; comparFn = 20;
} else if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */ } else if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */
comparFn = 7; comparFn = 7;
} else if (optr == TSDB_RELATION_NOT_LIKE) { /* wildcard query using like operator */
comparFn = 26;
} else if (optr == TSDB_RELATION_IN) { } else if (optr == TSDB_RELATION_IN) {
comparFn = 8; comparFn = 8;
} else if (optr == TSDB_RELATION_NOT_IN) {
comparFn = 25;
} else { /* normal relational comparFn */ } else { /* normal relational comparFn */
comparFn = 6; comparFn = 6;
} }
...@@ -219,8 +248,12 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { ...@@ -219,8 +248,12 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
comparFn = 20; comparFn = 20;
} else if (optr == TSDB_RELATION_LIKE) { } else if (optr == TSDB_RELATION_LIKE) {
comparFn = 9; comparFn = 9;
} else if (optr == TSDB_RELATION_LIKE) {
comparFn = 27;
} else if (optr == TSDB_RELATION_IN) { } else if (optr == TSDB_RELATION_IN) {
comparFn = 8; comparFn = 8;
} else if (optr == TSDB_RELATION_NOT_IN) {
comparFn = 25;
} else { } else {
comparFn = 10; comparFn = 10;
} }
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
extern "C" { extern "C" {
#endif #endif
typedef struct SScalarCalcContext {
} SScalarCalcContext;
#define sclFatal(...) qFatal(__VA_ARGS__) #define sclFatal(...) qFatal(__VA_ARGS__)
#define sclError(...) qError(__VA_ARGS__) #define sclError(...) qError(__VA_ARGS__)
......
#include "nodes.h" #include "nodes.h"
#include "tscalar.h" #include "tscalar.h"
EDealRes sclCalculateConstants(SNode** pNode, void* pContext) { int32_t sclGetOperatorParamNum(EOperatorType type) {
if (OP_TYPE_ISNULL == type || OP_TYPE_NOTNULL == type) {
return 1;
}
return 2;
}
int32_t sclPrepareFunctionParams(SScalarFuncParam **pParams, SNodeList* pParameterList) {
*pParams = calloc(pParameterList->length, sizeof(SScalarFuncParam));
if (NULL == *pParams) {
sclError("calloc %d failed", pParameterList->length * sizeof(SScalarFuncParam));
return TSDB_CODE_QRY_OUT_OF_MEMORY;
}
SListCell *cell = pParameterList->pHead;
for (int32_t i = 0; i < pParameterList->length; ++i) {
if (NULL == cell || NULL == cell->pNode) {
sclError("invalid cell, cell:%p, pNode:%p", cell, cell->pNode);
tfree(*pParams);
return TSDB_CODE_QRY_INVALID_INPUT;
}
if (QUERY_NODE_VALUE != nodeType(cell->pNode)) {
sclError("invalid node type in cell, type:%d", nodeType(cell->pNode));
tfree(*pParams);
return TSDB_CODE_QRY_APP_ERROR;
}
SValueNode *valueNode = (SValueNode *)cell->pNode;
pParams[i].data = nodesGetValueFromNode(valueNode);
pParams[i].num = 1;
pParams[i].type = valueNode->node.resType.type;
pParams[i].bytes = valueNode->node.resType.bytes;
cell = cell->pNext;
}
return TSDB_CODE_SUCCESS;
}
EDealRes sclRewriteFunction(SNode** pNode, void* pContext) {
SFunctionNode *node = (SFunctionNode *)*pNode;
if (NULL == node->pParameterList || node->pParameterList->length <= 0) {
sclError("invalid function parameter list, list:%p, paramNum:%d", node->pParameterList, node->pParameterList ? node->pParameterList->length : 0);
*(int32_t *)pContext = TSDB_CODE_QRY_INVALID_INPUT;
return DEAL_RES_ERROR;
}
SScalarFuncExecFuncs ffpSet = {0};
int32_t code = fmGetScalarFuncExecFuncs(node->funcId, &ffpSet);
if (code) {
sclError("fmGetFuncExecFuncs failed, funcId:%d, code:%s", node->funcId, tstrerror(code));
*(int32_t *)pContext = code;
return DEAL_RES_ERROR;
}
SScalarFuncParam *input = NULL;
if (sclPrepareFunctionParams(&input, node->pParameterList)) {
return DEAL_RES_ERROR;
}
SScalarFuncParam output = {0};
code = (*ffpSet.process)(input, node->pParameterList->length, &output);
if (code) {
sclError("scalar function exec failed, funcId:%d, code:%s", node->funcId, tstrerror(code));
*(int32_t *)pContext = code;
return DEAL_RES_ERROR;
}
SValueNode *res = nodesMakeNode(QUERY_NODE_VALUE);
if (NULL == res) {
sclError("make value node failed");
*(int32_t *)pContext = TSDB_CODE_QRY_OUT_OF_MEMORY;
return DEAL_RES_ERROR;
}
res->node.resType = node->node.resType;
SET_TYPED_DATA(nodesGetValueFromNode(res), output.type, output.data);
nodesDestroyNode(*pNode);
*pNode = (SNode*)res;
tfree(output.data);
return DEAL_RES_CONTINUE;
}
EDealRes sclRewriteLogic(SNode** pNode, void* pContext) {
SLogicConditionNode *node = (SLogicConditionNode *)*pNode;
if (NULL == node->pParameterList || node->pParameterList->length <= 0) {
sclError("invalid logic parameter list, list:%p, paramNum:%d", node->pParameterList, node->pParameterList ? node->pParameterList->length : 0);
*(int32_t *)pContext = TSDB_CODE_QRY_INVALID_INPUT;
return DEAL_RES_ERROR;
}
if (LOGIC_COND_TYPE_NOT == node->condType && node->pParameterList->length > 1) {
sclError("invalid NOT operation parameter number, paramNum:%d", node->pParameterList->length);
*(int32_t *)pContext = TSDB_CODE_QRY_INVALID_INPUT;
return DEAL_RES_ERROR;
}
bool value = false;
SListCell *cell = node->pParameterList->pHead;
for (int32_t i = 0; i < node->pParameterList->length; ++i) {
if (NULL == cell || NULL == cell->pNode) {
sclError("invalid cell, cell:%p, pNode:%p", cell, cell->pNode);
return TSDB_CODE_QRY_INVALID_INPUT;
}
if (QUERY_NODE_VALUE != nodeType(cell->pNode)) {
sclError("invalid node type in cell, type:%d", nodeType(cell->pNode));
return TSDB_CODE_QRY_APP_ERROR;
}
SValueNode *valueNode = (SValueNode *)cell->pNode;
GET_TYPED_DATA(value, bool, valueNode->node.resType.type, nodesGetValueFromNode(valueNode));
if (LOGIC_COND_TYPE_AND == node->condType && (false == value)) {
break;
} else if (LOGIC_COND_TYPE_OR == node->condType && value) {
break;
} else if (LOGIC_COND_TYPE_NOT == node->condType) {
value = !value;
}
cell = cell->pNext;
}
SValueNode *res = nodesMakeNode(QUERY_NODE_VALUE);
if (NULL == res) {
sclError("make value node failed");
*(int32_t *)pContext = TSDB_CODE_QRY_OUT_OF_MEMORY;
return DEAL_RES_ERROR;
}
res->node.resType = node->node.resType;
SET_TYPED_DATA(nodesGetValueFromNode(res), res->node.resType.type, value);
nodesDestroyNode(*pNode);
*pNode = (SNode*)res;
return DEAL_RES_CONTINUE;
}
EDealRes sclRewriteOperator(SNode** pNode, void* pContext) {
SOperatorNode *oper = (SOperatorNode *)*pNode;
int32_t paramNum = sclGetOperatorParamNum(oper->opType);
if (NULL == oper->pLeft || (paramNum == 2 && NULL == oper->pRight)) {
sclError("invalid operation node, left:%p, right:%p", oper->pLeft, oper->pRight);
*(int32_t *)pContext = TSDB_CODE_QRY_INVALID_INPUT;
return DEAL_RES_ERROR;
}
if (QUERY_NODE_VALUE != nodeType(oper->pLeft) || (paramNum == 2 && QUERY_NODE_VALUE != nodeType(oper->pRight))) {
sclError("invalid operation node, leftType:%d, rightType:%d", nodeType(oper->pLeft), oper->pRight ? nodeType(oper->pRight) : 0);
*(int32_t *)pContext = TSDB_CODE_QRY_INVALID_INPUT;
return DEAL_RES_ERROR;
}
SValueNode *res = nodesMakeNode(QUERY_NODE_VALUE);
if (NULL == res) {
sclError("make value node failed");
*(int32_t *)pContext = TSDB_CODE_QRY_OUT_OF_MEMORY;
return DEAL_RES_ERROR;
}
res->node.resType = oper->node.resType;
SValueNode *leftValue = (SValueNode *)oper->pLeft;
SValueNode *rightValue = (SValueNode *)oper->pRight;
SScalarFuncParam leftParam = {0}, rightParam = {0};
_bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(oper->opType);
setScalarFuncParam(&leftParam, leftValue->node.resType.type, 0, nodesGetValueFromNode(leftValue), 1);
if (2 == paramNum) {
setScalarFuncParam(&rightParam, rightValue->node.resType.type, 0, nodesGetValueFromNode(rightValue), 1);
}
OperatorFn(&leftParam, &rightParam, nodesGetValueFromNode(res), TSDB_ORDER_ASC);
nodesDestroyNode(*pNode);
*pNode = (SNode*)res;
return DEAL_RES_CONTINUE;
}
EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) {
if (QUERY_NODE_VALUE == nodeType(*pNode)) {
return DEAL_RES_CONTINUE;
}
if (QUERY_NODE_FUNCTION == nodeType(*pNode)) {
return sclRewriteFunction(pNode, pContext);
}
if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pNode)) {
return sclRewriteLogic(pNode, pContext);
}
if (QUERY_NODE_OPERATOR != nodeType(*pNode)) {
sclError("invalid node type for calculating constants, type:%d", );
*(int32_t *)pContext = TSDB_CODE_QRY_INVALID_INPUT;
return DEAL_RES_ERROR;
}
return sclRewriteOperator(pNode, pContext);
}
EDealRes sclCalculate(SNode** pNode, void* pContext) {
if (QUERY_NODE_VALUE == nodeType(*pNode)) { if (QUERY_NODE_VALUE == nodeType(*pNode)) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
if (QUERY_NODE_FUNCTION == nodeType(*pNode)) {
return sclCalculateFunction(pNode, pContext);
}
if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pNode)) {
return sclCalculateLogic(pNode, pContext);
}
if (QUERY_NODE_OPERATOR != nodeType(*pNode)) { if (QUERY_NODE_OPERATOR != nodeType(*pNode)) {
sclError("invalid node type for calculating constants, type:%d", ); sclError("invalid node type for calculating constants, type:%d", );
*(int32_t *)pContext = TSDB_CODE_QRY_INVALID_INPUT; *(int32_t *)pContext = TSDB_CODE_QRY_INVALID_INPUT;
...@@ -13,14 +233,15 @@ EDealRes sclCalculateConstants(SNode** pNode, void* pContext) { ...@@ -13,14 +233,15 @@ EDealRes sclCalculateConstants(SNode** pNode, void* pContext) {
} }
SOperatorNode *oper = (SOperatorNode *)*pNode; SOperatorNode *oper = (SOperatorNode *)*pNode;
if (NULL == oper->pLeft || NULL == oper->pRight) { int32_t paramNum = sclGetOperatorParamNum(oper->opType);
if (NULL == oper->pLeft || (paramNum == 2 && NULL == oper->pRight)) {
sclError("invalid operation node, left:%p, right:%p", oper->pLeft, oper->pRight); sclError("invalid operation node, left:%p, right:%p", oper->pLeft, oper->pRight);
*(int32_t *)pContext = TSDB_CODE_QRY_INVALID_INPUT; *(int32_t *)pContext = TSDB_CODE_QRY_INVALID_INPUT;
return DEAL_RES_ERROR; return DEAL_RES_ERROR;
} }
if (QUERY_NODE_VALUE != nodeType(oper->pLeft) || QUERY_NODE_VALUE != nodeType(oper->pRight)) { if (QUERY_NODE_VALUE != nodeType(oper->pLeft) || (paramNum == 2 && QUERY_NODE_VALUE != nodeType(oper->pRight))) {
sclError("invalid operation node, leftType:%d, rightType:%d", nodeType(oper->pLeft), nodeType(oper->pRight)); sclError("invalid operation node, leftType:%d, rightType:%d", nodeType(oper->pLeft), oper->pRight ? nodeType(oper->pRight) : 0);
*(int32_t *)pContext = TSDB_CODE_QRY_INVALID_INPUT; *(int32_t *)pContext = TSDB_CODE_QRY_INVALID_INPUT;
return DEAL_RES_ERROR; return DEAL_RES_ERROR;
} }
...@@ -37,10 +258,12 @@ EDealRes sclCalculateConstants(SNode** pNode, void* pContext) { ...@@ -37,10 +258,12 @@ EDealRes sclCalculateConstants(SNode** pNode, void* pContext) {
SValueNode *leftValue = (SValueNode *)oper->pLeft; SValueNode *leftValue = (SValueNode *)oper->pLeft;
SValueNode *rightValue = (SValueNode *)oper->pRight; SValueNode *rightValue = (SValueNode *)oper->pRight;
SScalarFuncParam leftParam = {0}, rightParam = {0}; SScalarFuncParam leftParam = {0}, rightParam = {0};
_bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(oper->opType); _bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(oper->opType);
setScalarFuncParam(&leftParam, leftValue->node.resType, 0, nodesGetValueFromNode(leftValue), 1); setScalarFuncParam(&leftParam, leftValue->node.resType.type, 0, nodesGetValueFromNode(leftValue), 1);
setScalarFuncParam(&rightParam, rightValue->node.resType, 0, nodesGetValueFromNode(rightValue), 1); if (2 == paramNum) {
setScalarFuncParam(&rightParam, rightValue->node.resType.type, 0, nodesGetValueFromNode(rightValue), 1);
}
OperatorFn(&leftParam, &rightParam, nodesGetValueFromNode(res), TSDB_ORDER_ASC); OperatorFn(&leftParam, &rightParam, nodesGetValueFromNode(res), TSDB_ORDER_ASC);
...@@ -50,6 +273,8 @@ EDealRes sclCalculateConstants(SNode** pNode, void* pContext) { ...@@ -50,6 +273,8 @@ EDealRes sclCalculateConstants(SNode** pNode, void* pContext) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) { int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) {
if (NULL == pNode) { if (NULL == pNode) {
SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
...@@ -57,7 +282,26 @@ int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) { ...@@ -57,7 +282,26 @@ int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) {
int32_t code = 0; int32_t code = 0;
nodesRewriteNodePostOrder(&pNode, sclCalculateConstants, (void *)&code); nodesRewriteNodePostOrder(&pNode, sclConstantsRewriter, (void *)&code);
if (code) {
nodesDestroyNode(pNode);
SCL_ERR_RET(code);
}
*pRes = pNode;
SCL_RET(code);
}
int32_t scalarCalculate(SNode *pNode, SSDataBlock *pSrc, SSDataBlock *pDst) {
if (NULL == pNode) {
SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
}
int32_t code = 0;
nodesRewriteNodePostOrder(&pNode, sclCalculate, (void *)&code);
if (code) { if (code) {
nodesDestroyNode(pNode); nodesDestroyNode(pNode);
......
...@@ -24,22 +24,48 @@ ...@@ -24,22 +24,48 @@
#include "types.h" #include "types.h"
#include "ulog.h" #include "ulog.h"
int32_t setCompareBytes1(const void *pLeft, const void *pRight) { int32_t setChkInBytes1(const void *pLeft, const void *pRight) {
return NULL != taosHashGet((SHashObj *)pRight, pLeft, 1) ? 1 : 0; return NULL != taosHashGet((SHashObj *)pRight, pLeft, 1) ? 1 : 0;
} }
int32_t setCompareBytes2(const void *pLeft, const void *pRight) { int32_t setChkInBytes2(const void *pLeft, const void *pRight) {
return NULL != taosHashGet((SHashObj *)pRight, pLeft, 2) ? 1 : 0; return NULL != taosHashGet((SHashObj *)pRight, pLeft, 2) ? 1 : 0;
} }
int32_t setCompareBytes4(const void *pLeft, const void *pRight) { int32_t setChkInBytes4(const void *pLeft, const void *pRight) {
return NULL != taosHashGet((SHashObj *)pRight, pLeft, 4) ? 1 : 0; return NULL != taosHashGet((SHashObj *)pRight, pLeft, 4) ? 1 : 0;
} }
int32_t setCompareBytes8(const void *pLeft, const void *pRight) { int32_t setChkInBytes8(const void *pLeft, const void *pRight) {
return NULL != taosHashGet((SHashObj *)pRight, pLeft, 8) ? 1 : 0; return NULL != taosHashGet((SHashObj *)pRight, pLeft, 8) ? 1 : 0;
} }
int32_t setChkNotInBytes1(const void *pLeft, const void *pRight) {
return NULL == taosHashGet((SHashObj *)pRight, pLeft, 1) ? 1 : 0;
}
int32_t setChkNotInBytes2(const void *pLeft, const void *pRight) {
return NULL == taosHashGet((SHashObj *)pRight, pLeft, 2) ? 1 : 0;
}
int32_t setChkNotInBytes4(const void *pLeft, const void *pRight) {
return NULL == taosHashGet((SHashObj *)pRight, pLeft, 4) ? 1 : 0;
}
int32_t setChkNotInBytes8(const void *pLeft, const void *pRight) {
return NULL == taosHashGet((SHashObj *)pRight, pLeft, 8) ? 1 : 0;
}
int32_t compareChkInString(const void *pLeft, const void* pRight) {
return NULL != taosHashGet((SHashObj *)pRight, varDataVal(pLeft), varDataLen(pLeft)) ? 1 : 0;
}
int32_t compareChkNotInString(const void *pLeft, const void* pRight) {
return NULL == taosHashGet((SHashObj *)pRight, varDataVal(pLeft), varDataLen(pLeft)) ? 1 : 0;
}
int32_t compareInt8Val(const void *pLeft, const void *pRight) { int32_t compareInt8Val(const void *pLeft, const void *pRight) {
int8_t left = GET_INT8_VAL(pLeft), right = GET_INT8_VAL(pRight); int8_t left = GET_INT8_VAL(pLeft), right = GET_INT8_VAL(pRight);
if (left > right) return 1; if (left > right) return 1;
...@@ -392,7 +418,3 @@ int32_t taosArrayCompareString(const void* a, const void* b) { ...@@ -392,7 +418,3 @@ int32_t taosArrayCompareString(const void* a, const void* b) {
return compareLenPrefixedStr(x, y); return compareLenPrefixedStr(x, y);
} }
int32_t compareFindItemInSet(const void *pLeft, const void* pRight) {
return NULL != taosHashGet((SHashObj *)pRight, varDataVal(pLeft), varDataLen(pLeft)) ? 1 : 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册