more code format

This commit is contained in:
Hongze Cheng 2022-10-13 14:03:23 +08:00
parent 63d9b85631
commit d8e32fb439
10 changed files with 4799 additions and 4723 deletions

View File

@ -59,7 +59,6 @@ enum {
RANGE_FLG_NULL = 4, RANGE_FLG_NULL = 4,
}; };
enum { enum {
FI_STATUS_ALL = 1, FI_STATUS_ALL = 1,
FI_STATUS_EMPTY = 2, FI_STATUS_EMPTY = 2,
@ -260,31 +259,117 @@ struct SFilterInfo {
SFilterPCtx pctx; SFilterPCtx pctx;
}; };
#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) == OP_TYPE_IS_NULL || (o) == OP_TYPE_IS_NOT_NULL || (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 == 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_AND_OPTR(ctx, o) \
#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) 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 == 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)))
#define FILTER_GET_FLAG(st, f) (st & f) #define FILTER_GET_FLAG(st, f) (st & f)
#define FILTER_SET_FLAG(st, f) st |= (f) #define FILTER_SET_FLAG(st, f) st |= (f)
#define FILTER_CLR_FLAG(st, f) st &= (~f) #define FILTER_CLR_FLAG(st, f) st &= (~f)
#define SIMPLE_COPY_VALUES(dst, src) *((int64_t *)dst) = *((int64_t *)src) #define SIMPLE_COPY_VALUES(dst, src) *((int64_t *)dst) = *((int64_t *)src)
#define FLT_PACKAGE_UNIT_HASH_KEY(v, op1, op2, lidx, ridx, ridx2) do { char *_t = (char *)(v); _t[0] = (op1); _t[1] = (op2); *(uint32_t *)(_t + 2) = (lidx); *(uint32_t *)(_t + 2 + sizeof(uint32_t)) = (ridx); } while (0) #define FLT_PACKAGE_UNIT_HASH_KEY(v, op1, op2, lidx, ridx, ridx2) \
#define FILTER_GREATER(cr,sflag,eflag) ((cr > 0) || ((cr == 0) && (FILTER_GET_FLAG(sflag,RANGE_FLG_EXCLUDE) || FILTER_GET_FLAG(eflag,RANGE_FLG_EXCLUDE)))) do { \
#define FILTER_COPY_RA(dst, src) do { (dst)->sflag = (src)->sflag; (dst)->eflag = (src)->eflag; (dst)->s = (src)->s; (dst)->e = (src)->e; } while (0) char *_t = (char *)(v); \
_t[0] = (op1); \
_t[1] = (op2); \
*(uint32_t *)(_t + 2) = (lidx); \
*(uint32_t *)(_t + 2 + sizeof(uint32_t)) = (ridx); \
} while (0)
#define FILTER_GREATER(cr, sflag, eflag) \
((cr > 0) || ((cr == 0) && (FILTER_GET_FLAG(sflag, RANGE_FLG_EXCLUDE) || FILTER_GET_FLAG(eflag, RANGE_FLG_EXCLUDE))))
#define FILTER_COPY_RA(dst, src) \
do { \
(dst)->sflag = (src)->sflag; \
(dst)->eflag = (src)->eflag; \
(dst)->s = (src)->s; \
(dst)->e = (src)->e; \
} while (0)
#define RESET_RANGE(ctx, r) do { (r)->next = (ctx)->rf; (ctx)->rf = r; } while (0) #define RESET_RANGE(ctx, r) \
#define FREE_RANGE(ctx, r) do { if ((r)->prev) { (r)->prev->next = (r)->next; } else { (ctx)->rs = (r)->next;} if ((r)->next) { (r)->next->prev = (r)->prev; } RESET_RANGE(ctx, r); } while (0) do { \
#define FREE_FROM_RANGE(ctx, r) do { SFilterRangeNode *_r = r; if ((_r)->prev) { (_r)->prev->next = NULL; } else { (ctx)->rs = NULL;} while (_r) {SFilterRangeNode *n = (_r)->next; RESET_RANGE(ctx, _r); _r = n; } } while (0) (r)->next = (ctx)->rf; \
#define INSERT_RANGE(ctx, r, ra) do { SFilterRangeNode *n = filterNewRange(ctx, ra); n->prev = (r)->prev; if ((r)->prev) { (r)->prev->next = n; } else { (ctx)->rs = n; } (r)->prev = n; n->next = r; } while (0) (ctx)->rf = r; \
#define APPEND_RANGE(ctx, r, ra) do { SFilterRangeNode *n = filterNewRange(ctx, ra); n->prev = (r); if (r) { (r)->next = n; } else { (ctx)->rs = n; } } while (0) } while (0)
#define FREE_RANGE(ctx, r) \
do { \
if ((r)->prev) { \
(r)->prev->next = (r)->next; \
} else { \
(ctx)->rs = (r)->next; \
} \
if ((r)->next) { \
(r)->next->prev = (r)->prev; \
} \
RESET_RANGE(ctx, r); \
} while (0)
#define FREE_FROM_RANGE(ctx, r) \
do { \
SFilterRangeNode *_r = r; \
if ((_r)->prev) { \
(_r)->prev->next = NULL; \
} else { \
(ctx)->rs = NULL; \
} \
while (_r) { \
SFilterRangeNode *n = (_r)->next; \
RESET_RANGE(ctx, _r); \
_r = n; \
} \
} while (0)
#define INSERT_RANGE(ctx, r, ra) \
do { \
SFilterRangeNode *n = filterNewRange(ctx, ra); \
n->prev = (r)->prev; \
if ((r)->prev) { \
(r)->prev->next = n; \
} else { \
(ctx)->rs = n; \
} \
(r)->prev = n; \
n->next = r; \
} while (0)
#define APPEND_RANGE(ctx, r, ra) \
do { \
SFilterRangeNode *n = filterNewRange(ctx, ra); \
n->prev = (r); \
if (r) { \
(r)->next = n; \
} else { \
(ctx)->rs = n; \
} \
} while (0)
#define FLT_IS_COMPARISON_OPERATOR(_op) ((_op) >= OP_TYPE_GREATER_THAN && (_op) < OP_TYPE_IS_NOT_UNKNOWN) #define FLT_IS_COMPARISON_OPERATOR(_op) ((_op) >= OP_TYPE_GREATER_THAN && (_op) < OP_TYPE_IS_NOT_UNKNOWN)
@ -295,12 +380,36 @@ struct SFilterInfo {
#define fltDebug(...) qDebug(__VA_ARGS__) #define fltDebug(...) qDebug(__VA_ARGS__)
#define fltTrace(...) qTrace(__VA_ARGS__) #define fltTrace(...) qTrace(__VA_ARGS__)
#define FLT_CHK_JMP(c) \
#define FLT_CHK_JMP(c) do { if (c) { goto _return; } } while (0) do { \
#define FLT_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0) if (c) { \
#define FLT_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) goto _return; \
#define FLT_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) } \
} while (0)
#define FLT_ERR_RET(c) \
do { \
int32_t _code = c; \
if (_code != TSDB_CODE_SUCCESS) { \
terrno = _code; \
return _code; \
} \
} while (0)
#define FLT_RET(c) \
do { \
int32_t _code = c; \
if (_code != TSDB_CODE_SUCCESS) { \
terrno = _code; \
} \
return _code; \
} while (0)
#define FLT_ERR_JRET(c) \
do { \
code = c; \
if (code != TSDB_CODE_SUCCESS) { \
terrno = code; \
goto _return; \
} \
} while (0)
#define FILTER_GET_FIELD(i, id) (&((i)->fields[(id).type].fields[(id).idx])) #define FILTER_GET_FIELD(i, id) (&((i)->fields[(id).type].fields[(id).idx]))
#define FILTER_GET_COL_FIELD(i, idx) (&((i)->fields[FLD_TYPE_COLUMN].fields[idx])) #define FILTER_GET_COL_FIELD(i, idx) (&((i)->fields[FLD_TYPE_COLUMN].fields[idx]))
@ -336,14 +445,37 @@ struct SFilterInfo {
#define FILTER_UNIT_GET_R(i, idx) ((i)->unitRes[idx]) #define FILTER_UNIT_GET_R(i, idx) ((i)->unitRes[idx])
#define FILTER_UNIT_SET_R(i, idx, v) (i)->unitRes[idx] = (v) #define FILTER_UNIT_SET_R(i, idx, v) (i)->unitRes[idx] = (v)
#define FILTER_PUSH_UNIT(colInfo, u) do { (colInfo).type = RANGE_TYPE_UNIT; (colInfo).dataType = FILTER_UNIT_DATA_TYPE(u);taosArrayPush((SArray *)((colInfo).info), &u);} while (0) #define FILTER_PUSH_UNIT(colInfo, u) \
#define FILTER_PUSH_VAR_HASH(colInfo, ha) do { (colInfo).type = RANGE_TYPE_VAR_HASH; (colInfo).info = ha;} while (0) do { \
#define FILTER_PUSH_CTX(colInfo, ctx) do { (colInfo).type = RANGE_TYPE_MR_CTX; (colInfo).info = ctx;} while (0) (colInfo).type = RANGE_TYPE_UNIT; \
(colInfo).dataType = FILTER_UNIT_DATA_TYPE(u); \
taosArrayPush((SArray *)((colInfo).info), &u); \
} while (0)
#define FILTER_PUSH_VAR_HASH(colInfo, ha) \
do { \
(colInfo).type = RANGE_TYPE_VAR_HASH; \
(colInfo).info = ha; \
} while (0)
#define FILTER_PUSH_CTX(colInfo, ctx) \
do { \
(colInfo).type = RANGE_TYPE_MR_CTX; \
(colInfo).info = ctx; \
} while (0)
#define FILTER_COPY_IDX(dst, src, n) do { *(dst) = taosMemoryMalloc(sizeof(uint32_t) * n); memcpy(*(dst), src, sizeof(uint32_t) * n);} while (0) #define FILTER_COPY_IDX(dst, src, n) \
do { \
#define FILTER_ADD_CTX_TO_GRES(gres, idx, ctx) do { if ((gres)->colCtxs == NULL) { (gres)->colCtxs = taosArrayInit(gres->colNum, sizeof(SFilterColCtx)); } SFilterColCtx cCtx = {idx, ctx}; taosArrayPush((gres)->colCtxs, &cCtx); } while (0) *(dst) = taosMemoryMalloc(sizeof(uint32_t) * n); \
memcpy(*(dst), src, sizeof(uint32_t) * n); \
} while (0)
#define FILTER_ADD_CTX_TO_GRES(gres, idx, ctx) \
do { \
if ((gres)->colCtxs == NULL) { \
(gres)->colCtxs = taosArrayInit(gres->colNum, sizeof(SFilterColCtx)); \
} \
SFilterColCtx cCtx = {idx, ctx}; \
taosArrayPush((gres)->colCtxs, &cCtx); \
} while (0)
#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)

View File

@ -18,9 +18,9 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "query.h"
#include "tcommon.h" #include "tcommon.h"
#include "thash.h" #include "thash.h"
#include "query.h"
typedef struct SOperatorValueType { typedef struct SOperatorValueType {
int32_t opResType; int32_t opResType;
@ -37,17 +37,22 @@ typedef struct SScalarCtx {
SOperatorValueType type; SOperatorValueType type;
} SScalarCtx; } SScalarCtx;
#define SCL_DATA_TYPE_DUMMY_HASH 9000 #define SCL_DATA_TYPE_DUMMY_HASH 9000
#define SCL_DEFAULT_OP_NUM 10 #define SCL_DEFAULT_OP_NUM 10
#define SCL_IS_CONST_NODE(_node) ((NULL == (_node)) || (QUERY_NODE_VALUE == (_node)->type) || (QUERY_NODE_NODE_LIST == (_node)->type)) #define SCL_IS_CONST_NODE(_node) \
((NULL == (_node)) || (QUERY_NODE_VALUE == (_node)->type) || (QUERY_NODE_NODE_LIST == (_node)->type))
#define SCL_IS_CONST_CALC(_ctx) (NULL == (_ctx)->pBlockList) #define SCL_IS_CONST_CALC(_ctx) (NULL == (_ctx)->pBlockList)
//#define SCL_IS_NULL_VALUE_NODE(_node) ((QUERY_NODE_VALUE == nodeType(_node)) && (TSDB_DATA_TYPE_NULL == ((SValueNode *)_node)->node.resType.type) && (((SValueNode *)_node)->placeholderNo <= 0)) //#define SCL_IS_NULL_VALUE_NODE(_node) ((QUERY_NODE_VALUE == nodeType(_node)) && (TSDB_DATA_TYPE_NULL == ((SValueNode
#define SCL_IS_NULL_VALUE_NODE(_node) ((QUERY_NODE_VALUE == nodeType(_node)) && (TSDB_DATA_TYPE_NULL == ((SValueNode *)_node)->node.resType.type)) //*)_node)->node.resType.type) && (((SValueNode *)_node)->placeholderNo <= 0))
#define SCL_IS_NULL_VALUE_NODE(_node) \
((QUERY_NODE_VALUE == nodeType(_node)) && (TSDB_DATA_TYPE_NULL == ((SValueNode*)_node)->node.resType.type))
#define SCL_IS_COMPARISON_OPERATOR(_opType) ((_opType) >= OP_TYPE_GREATER_THAN && (_opType) < OP_TYPE_IS_NOT_UNKNOWN) #define SCL_IS_COMPARISON_OPERATOR(_opType) ((_opType) >= OP_TYPE_GREATER_THAN && (_opType) < OP_TYPE_IS_NOT_UNKNOWN)
#define SCL_DOWNGRADE_DATETYPE(_type) ((_type) == TSDB_DATA_TYPE_BIGINT || TSDB_DATA_TYPE_DOUBLE == (_type) || (_type) == TSDB_DATA_TYPE_UBIGINT) #define SCL_DOWNGRADE_DATETYPE(_type) \
#define SCL_NO_NEED_CONVERT_COMPARISION(_ltype, _rtype, _optr) (IS_NUMERIC_TYPE(_ltype) && IS_NUMERIC_TYPE(_rtype) && ((_optr) >= OP_TYPE_GREATER_THAN && (_optr) <= OP_TYPE_NOT_EQUAL)) ((_type) == TSDB_DATA_TYPE_BIGINT || TSDB_DATA_TYPE_DOUBLE == (_type) || (_type) == TSDB_DATA_TYPE_UBIGINT)
#define SCL_NO_NEED_CONVERT_COMPARISION(_ltype, _rtype, _optr) \
(IS_NUMERIC_TYPE(_ltype) && IS_NUMERIC_TYPE(_rtype) && \
((_optr) >= OP_TYPE_GREATER_THAN && (_optr) <= OP_TYPE_NOT_EQUAL))
#define sclFatal(...) qFatal(__VA_ARGS__) #define sclFatal(...) qFatal(__VA_ARGS__)
#define sclError(...) qError(__VA_ARGS__) #define sclError(...) qError(__VA_ARGS__)
@ -56,9 +61,30 @@ typedef struct SScalarCtx {
#define sclDebug(...) qDebug(__VA_ARGS__) #define sclDebug(...) qDebug(__VA_ARGS__)
#define sclTrace(...) qTrace(__VA_ARGS__) #define sclTrace(...) qTrace(__VA_ARGS__)
#define SCL_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0) #define SCL_ERR_RET(c) \
#define SCL_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) do { \
#define SCL_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) int32_t _code = c; \
if (_code != TSDB_CODE_SUCCESS) { \
terrno = _code; \
return _code; \
} \
} while (0)
#define SCL_RET(c) \
do { \
int32_t _code = c; \
if (_code != TSDB_CODE_SUCCESS) { \
terrno = _code; \
} \
return _code; \
} while (0)
#define SCL_ERR_JRET(c) \
do { \
code = c; \
if (code != TSDB_CODE_SUCCESS) { \
terrno = code; \
goto _return; \
} \
} while (0)
int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out, int32_t* overflow); int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out, int32_t* overflow);
int32_t sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows, SScalarParam* pParam); int32_t sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows, SScalarParam* pParam);

View File

@ -12,17 +12,17 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "os.h"
#include <tlog.h> #include <tlog.h>
#include "os.h"
#include "thash.h" #include "thash.h"
//#include "queryLog.h" //#include "queryLog.h"
#include "filter.h" #include "filter.h"
#include "filterInt.h" #include "filterInt.h"
#include "functionMgt.h"
#include "sclInt.h" #include "sclInt.h"
#include "tcompare.h" #include "tcompare.h"
#include "tdatablock.h" #include "tdatablock.h"
#include "ttime.h" #include "ttime.h"
#include "functionMgt.h"
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) {
int32_t result = cfunc(maxv, minr); int32_t result = cfunc(maxv, minr);
@ -85,9 +85,8 @@ rangeCompFunc filterGetRangeCompFunc(char sflag, char eflag) {
return filterRangeCompii; return filterRangeCompii;
} }
rangeCompFunc gRangeCompare[] = {filterRangeCompee, filterRangeCompei, filterRangeCompie, filterRangeCompii, filterRangeCompGe, rangeCompFunc gRangeCompare[] = {filterRangeCompee, filterRangeCompei, filterRangeCompie, filterRangeCompii,
filterRangeCompGi, filterRangeCompLe, filterRangeCompLi}; filterRangeCompGe, filterRangeCompGi, filterRangeCompLe, filterRangeCompLi};
int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) { int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) {
if (optr2) { if (optr2) {
@ -124,84 +123,75 @@ int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) {
return -1; return -1;
} }
__compar_fn_t gDataCompare[] = {compareInt32Val, compareInt8Val, compareInt16Val, compareInt64Val, compareFloatVal, __compar_fn_t gDataCompare[] = {compareInt32Val,
compareDoubleVal, compareLenPrefixedStr, compareStrPatternMatch, compareChkInString, compareWStrPatternMatch, compareInt8Val,
compareLenPrefixedWStr, compareUint8Val, compareUint16Val, compareUint32Val, compareUint64Val, compareInt16Val,
setChkInBytes1, setChkInBytes2, setChkInBytes4, setChkInBytes8, compareStrRegexCompMatch, compareInt64Val,
compareStrRegexCompNMatch, setChkNotInBytes1, setChkNotInBytes2, setChkNotInBytes4, setChkNotInBytes8, compareFloatVal,
compareChkNotInString, compareStrPatternNotMatch, compareWStrPatternNotMatch compareDoubleVal,
}; compareLenPrefixedStr,
compareStrPatternMatch,
compareChkInString,
compareWStrPatternMatch,
compareLenPrefixedWStr,
compareUint8Val,
compareUint16Val,
compareUint32Val,
compareUint64Val,
setChkInBytes1,
setChkInBytes2,
setChkInBytes4,
setChkInBytes8,
compareStrRegexCompMatch,
compareStrRegexCompNMatch,
setChkNotInBytes1,
setChkNotInBytes2,
setChkNotInBytes4,
setChkNotInBytes8,
compareChkNotInString,
compareStrPatternNotMatch,
compareWStrPatternNotMatch};
__compar_fn_t gInt8SignCompare[] = { __compar_fn_t gInt8SignCompare[] = {compareInt8Val, compareInt8Int16, compareInt8Int32,
compareInt8Val, compareInt8Int16, compareInt8Int32, compareInt8Int64, compareInt8Float, compareInt8Double compareInt8Int64, compareInt8Float, compareInt8Double};
}; __compar_fn_t gInt8UsignCompare[] = {compareInt8Uint8, compareInt8Uint16, compareInt8Uint32, compareInt8Uint64};
__compar_fn_t gInt8UsignCompare[] = {
compareInt8Uint8, compareInt8Uint16, compareInt8Uint32, compareInt8Uint64
};
__compar_fn_t gInt16SignCompare[] = { __compar_fn_t gInt16SignCompare[] = {compareInt16Int8, compareInt16Val, compareInt16Int32,
compareInt16Int8, compareInt16Val, compareInt16Int32, compareInt16Int64, compareInt16Float, compareInt16Double compareInt16Int64, compareInt16Float, compareInt16Double};
}; __compar_fn_t gInt16UsignCompare[] = {compareInt16Uint8, compareInt16Uint16, compareInt16Uint32, compareInt16Uint64};
__compar_fn_t gInt16UsignCompare[] = {
compareInt16Uint8, compareInt16Uint16, compareInt16Uint32, compareInt16Uint64
};
__compar_fn_t gInt32SignCompare[] = { __compar_fn_t gInt32SignCompare[] = {compareInt32Int8, compareInt32Int16, compareInt32Val,
compareInt32Int8, compareInt32Int16, compareInt32Val, compareInt32Int64, compareInt32Float, compareInt32Double compareInt32Int64, compareInt32Float, compareInt32Double};
}; __compar_fn_t gInt32UsignCompare[] = {compareInt32Uint8, compareInt32Uint16, compareInt32Uint32, compareInt32Uint64};
__compar_fn_t gInt32UsignCompare[] = {
compareInt32Uint8, compareInt32Uint16, compareInt32Uint32, compareInt32Uint64
};
__compar_fn_t gInt64SignCompare[] = { __compar_fn_t gInt64SignCompare[] = {compareInt64Int8, compareInt64Int16, compareInt64Int32,
compareInt64Int8, compareInt64Int16, compareInt64Int32, compareInt64Val, compareInt64Float, compareInt64Double compareInt64Val, compareInt64Float, compareInt64Double};
}; __compar_fn_t gInt64UsignCompare[] = {compareInt64Uint8, compareInt64Uint16, compareInt64Uint32, compareInt64Uint64};
__compar_fn_t gInt64UsignCompare[] = {
compareInt64Uint8, compareInt64Uint16, compareInt64Uint32, compareInt64Uint64
};
__compar_fn_t gFloatSignCompare[] = { __compar_fn_t gFloatSignCompare[] = {compareFloatInt8, compareFloatInt16, compareFloatInt32,
compareFloatInt8, compareFloatInt16, compareFloatInt32, compareFloatInt64, compareFloatVal, compareFloatDouble compareFloatInt64, compareFloatVal, compareFloatDouble};
}; __compar_fn_t gFloatUsignCompare[] = {compareFloatUint8, compareFloatUint16, compareFloatUint32, compareFloatUint64};
__compar_fn_t gFloatUsignCompare[] = {
compareFloatUint8, compareFloatUint16, compareFloatUint32, compareFloatUint64
};
__compar_fn_t gDoubleSignCompare[] = { __compar_fn_t gDoubleSignCompare[] = {compareDoubleInt8, compareDoubleInt16, compareDoubleInt32,
compareDoubleInt8, compareDoubleInt16, compareDoubleInt32, compareDoubleInt64, compareDoubleFloat, compareDoubleVal compareDoubleInt64, compareDoubleFloat, compareDoubleVal};
}; __compar_fn_t gDoubleUsignCompare[] = {compareDoubleUint8, compareDoubleUint16, compareDoubleUint32,
__compar_fn_t gDoubleUsignCompare[] = { compareDoubleUint64};
compareDoubleUint8, compareDoubleUint16, compareDoubleUint32, compareDoubleUint64
};
__compar_fn_t gUint8SignCompare[] = { __compar_fn_t gUint8SignCompare[] = {compareUint8Int8, compareUint8Int16, compareUint8Int32,
compareUint8Int8, compareUint8Int16, compareUint8Int32, compareUint8Int64, compareUint8Float, compareUint8Double compareUint8Int64, compareUint8Float, compareUint8Double};
}; __compar_fn_t gUint8UsignCompare[] = {compareUint8Val, compareUint8Uint16, compareUint8Uint32, compareUint8Uint64};
__compar_fn_t gUint8UsignCompare[] = {
compareUint8Val, compareUint8Uint16, compareUint8Uint32, compareUint8Uint64
};
__compar_fn_t gUint16SignCompare[] = { __compar_fn_t gUint16SignCompare[] = {compareUint16Int8, compareUint16Int16, compareUint16Int32,
compareUint16Int8, compareUint16Int16, compareUint16Int32, compareUint16Int64, compareUint16Float, compareUint16Double compareUint16Int64, compareUint16Float, compareUint16Double};
}; __compar_fn_t gUint16UsignCompare[] = {compareUint16Uint8, compareUint16Val, compareUint16Uint32, compareUint16Uint64};
__compar_fn_t gUint16UsignCompare[] = {
compareUint16Uint8, compareUint16Val, compareUint16Uint32, compareUint16Uint64
};
__compar_fn_t gUint32SignCompare[] = { __compar_fn_t gUint32SignCompare[] = {compareUint32Int8, compareUint32Int16, compareUint32Int32,
compareUint32Int8, compareUint32Int16, compareUint32Int32, compareUint32Int64, compareUint32Float, compareUint32Double compareUint32Int64, compareUint32Float, compareUint32Double};
}; __compar_fn_t gUint32UsignCompare[] = {compareUint32Uint8, compareUint32Uint16, compareUint32Val, compareUint32Uint64};
__compar_fn_t gUint32UsignCompare[] = {
compareUint32Uint8, compareUint32Uint16, compareUint32Val, compareUint32Uint64
};
__compar_fn_t gUint64SignCompare[] = {
compareUint64Int8, compareUint64Int16, compareUint64Int32, compareUint64Int64, compareUint64Float, compareUint64Double
};
__compar_fn_t gUint64UsignCompare[] = {
compareUint64Uint8, compareUint64Uint16, compareUint64Uint32, compareUint64Val
};
__compar_fn_t gUint64SignCompare[] = {compareUint64Int8, compareUint64Int16, compareUint64Int32,
compareUint64Int64, compareUint64Float, compareUint64Double};
__compar_fn_t gUint64UsignCompare[] = {compareUint64Uint8, compareUint64Uint16, compareUint64Uint32, compareUint64Val};
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;
@ -262,16 +252,27 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
return 28; return 28;
} }
switch (type) { switch (type) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_TINYINT: comparFn = 1; break; case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_SMALLINT: comparFn = 2; break; comparFn = 1;
case TSDB_DATA_TYPE_INT: comparFn = 0; break; break;
case TSDB_DATA_TYPE_SMALLINT:
comparFn = 2;
break;
case TSDB_DATA_TYPE_INT:
comparFn = 0;
break;
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
case TSDB_DATA_TYPE_TIMESTAMP: comparFn = 3; break; case TSDB_DATA_TYPE_TIMESTAMP:
case TSDB_DATA_TYPE_FLOAT: comparFn = 4; break; comparFn = 3;
case TSDB_DATA_TYPE_DOUBLE: comparFn = 5; break; break;
case TSDB_DATA_TYPE_FLOAT:
comparFn = 4;
break;
case TSDB_DATA_TYPE_DOUBLE:
comparFn = 5;
break;
case TSDB_DATA_TYPE_BINARY: { case TSDB_DATA_TYPE_BINARY: {
if (optr == OP_TYPE_MATCH) { if (optr == OP_TYPE_MATCH) {
comparFn = 19; comparFn = 19;
@ -311,10 +312,18 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
break; break;
} }
case TSDB_DATA_TYPE_UTINYINT: comparFn = 11; break; case TSDB_DATA_TYPE_UTINYINT:
case TSDB_DATA_TYPE_USMALLINT: comparFn = 12;break; comparFn = 11;
case TSDB_DATA_TYPE_UINT: comparFn = 13;break; break;
case TSDB_DATA_TYPE_UBIGINT: comparFn = 14;break; case TSDB_DATA_TYPE_USMALLINT:
comparFn = 12;
break;
case TSDB_DATA_TYPE_UINT:
comparFn = 13;
break;
case TSDB_DATA_TYPE_UBIGINT:
comparFn = 14;
break;
default: default:
comparFn = 0; comparFn = 0;
@ -324,9 +333,7 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
return comparFn; return comparFn;
} }
__compar_fn_t filterGetCompFunc(int32_t type, int32_t optr) { __compar_fn_t filterGetCompFunc(int32_t type, int32_t optr) { return gDataCompare[filterGetCompFuncIdx(type, optr)]; }
return gDataCompare[filterGetCompFuncIdx(type, optr)];
}
__compar_fn_t filterGetCompFuncEx(int32_t lType, int32_t rType, int32_t optr) { __compar_fn_t filterGetCompFuncEx(int32_t lType, int32_t rType, int32_t optr) {
switch (lType) { switch (lType) {
@ -455,7 +462,8 @@ static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRangeCtx *ctx, SFilt
} }
void *filterInitRangeCtx(int32_t type, int32_t options) { void *filterInitRangeCtx(int32_t type, int32_t options) {
if (type > TSDB_DATA_TYPE_UBIGINT || type < TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { if (type > TSDB_DATA_TYPE_UBIGINT || type < TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_BINARY ||
type == TSDB_DATA_TYPE_NCHAR) {
qError("not supported range type:%d", type); qError("not supported range type:%d", type);
return NULL; return NULL;
} }
@ -469,7 +477,6 @@ void* filterInitRangeCtx(int32_t type, int32_t options) {
return ctx; return ctx;
} }
int32_t filterResetRangeCtx(SFilterRangeCtx *ctx) { int32_t filterResetRangeCtx(SFilterRangeCtx *ctx) {
ctx->status = 0; ctx->status = 0;
@ -504,7 +511,6 @@ int32_t filterReuseRangeCtx(SFilterRangeCtx *ctx, int32_t type, int32_t options)
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterConvertRange(SFilterRangeCtx *cur, SFilterRange *ra, bool *notNull) { int32_t filterConvertRange(SFilterRangeCtx *cur, SFilterRange *ra, bool *notNull) {
if (!FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) { if (!FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) {
int32_t sr = cur->pCompareFunc(&ra->s, getDataMin(cur->type)); int32_t sr = cur->pCompareFunc(&ra->s, getDataMin(cur->type));
@ -520,7 +526,6 @@ int32_t filterConvertRange(SFilterRangeCtx *cur, SFilterRange *ra, bool *notNull
} }
} }
if (FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL) && FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL)) { if (FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL) && FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL)) {
*notNull = true; *notNull = true;
} else { } else {
@ -550,15 +555,13 @@ int32_t filterAddRangeOptr(void* h, uint8_t raOptr, int32_t optr, bool *empty, b
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterAddRangeImpl(void *h, SFilterRange *ra, int32_t optr) { int32_t filterAddRangeImpl(void *h, SFilterRange *ra, int32_t optr) {
SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; SFilterRangeCtx *ctx = (SFilterRangeCtx *)h;
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 == LOGIC_COND_TYPE_AND)) (FILTER_GET_FLAG(ctx->status, MR_ST_ALL) && (optr == LOGIC_COND_TYPE_AND)) ||
|| ((!FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) && (optr == LOGIC_COND_TYPE_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);
} }
@ -605,7 +608,6 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
// TSDB_RELATION_OR // TSDB_RELATION_OR
bool smerged = false; bool smerged = false;
@ -708,7 +710,6 @@ int32_t filterAddRange(void* h, SFilterRange* ra, int32_t optr) {
return filterAddRangeImpl(h, ra, optr); return filterAddRangeImpl(h, ra, optr);
} }
int32_t filterAddRangeCtx(void *dst, void *src, int32_t optr) { 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;
@ -755,8 +756,6 @@ int32_t filterCopyRangeCtx(void *dst, void *src) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterFinishRange(void *h) { int32_t filterFinishRange(void *h) {
SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; SFilterRangeCtx *ctx = (SFilterRangeCtx *)h;
@ -806,7 +805,6 @@ int32_t filterGetRangeNum(void* h, int32_t* num) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterGetRangeRes(void *h, SFilterRange *ra) { int32_t filterGetRangeRes(void *h, SFilterRange *ra) {
filterFinishRange(h); filterFinishRange(h);
@ -834,7 +832,6 @@ int32_t filterGetRangeRes(void* h, SFilterRange *ra) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterSourceRangeFromCtx(SFilterRangeCtx *ctx, void *sctx, int32_t optr, bool *empty, bool *all) { int32_t filterSourceRangeFromCtx(SFilterRangeCtx *ctx, void *sctx, int32_t optr, bool *empty, bool *all) {
SFilterRangeCtx *src = (SFilterRangeCtx *)sctx; SFilterRangeCtx *src = (SFilterRangeCtx *)sctx;
@ -867,8 +864,6 @@ int32_t filterSourceRangeFromCtx(SFilterRangeCtx *ctx, void *sctx, int32_t optr,
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterFreeRangeCtx(void *h) { int32_t filterFreeRangeCtx(void *h) {
if (h == NULL) { if (h == NULL) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -896,7 +891,6 @@ int32_t filterFreeRangeCtx(void* h) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterDetachCnfGroup(SFilterGroup *gp1, SFilterGroup *gp2, SArray *group) { int32_t filterDetachCnfGroup(SFilterGroup *gp1, SFilterGroup *gp2, SArray *group) {
SFilterGroup gp = {0}; SFilterGroup gp = {0};
@ -912,7 +906,6 @@ int32_t filterDetachCnfGroup(SFilterGroup *gp1, SFilterGroup *gp2, SArray* group
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterDetachCnfGroups(SArray *group, SArray *left, SArray *right) { int32_t filterDetachCnfGroups(SArray *group, SArray *left, SArray *right) {
int32_t leftSize = (int32_t)taosArrayGetSize(left); int32_t leftSize = (int32_t)taosArrayGetSize(left);
int32_t rightSize = (int32_t)taosArrayGetSize(right); int32_t rightSize = (int32_t)taosArrayGetSize(right);
@ -950,7 +943,6 @@ int32_t filterDetachCnfGroups(SArray* group, SArray* left, SArray* right) {
} }
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -964,7 +956,6 @@ int32_t filterGetFiledByDesc(SFilterFields* fields, int32_t type, void *v) {
return -1; return -1;
} }
int32_t filterGetFiledByData(SFilterInfo *info, int32_t type, void *v, int32_t dataLen) { int32_t filterGetFiledByData(SFilterInfo *info, int32_t type, void *v, int32_t dataLen) {
if (type == FLD_TYPE_VALUE) { if (type == FLD_TYPE_VALUE) {
if (info->pctx.valHash == false) { if (info->pctx.valHash == false) {
@ -981,9 +972,10 @@ int32_t filterGetFiledByData(SFilterInfo *info, int32_t type, void *v, int32_t d
return -1; return -1;
} }
// In the params, we should use void *data instead of void **data, there is no need to use taosMemoryFreeClear(*data) to set *data = 0 // In the params, we should use void *data instead of void **data, there is no need to use taosMemoryFreeClear(*data) to
// Besides, fields data value is a pointer, so dataLen should be POINTER_BYTES for better. // set *data = 0 Besides, fields data value is a pointer, so dataLen should be POINTER_BYTES for better.
int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type, SFilterFieldId *fid, int32_t dataLen, bool freeIfExists) { int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type, SFilterFieldId *fid, int32_t dataLen,
bool freeIfExists) {
int32_t idx = -1; int32_t idx = -1;
uint32_t *num; uint32_t *num;
@ -1001,7 +993,8 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type,
idx = *num; idx = *num;
if (idx >= info->fields[type].size) { if (idx >= info->fields[type].size) {
info->fields[type].size += FILTER_DEFAULT_FIELD_SIZE; info->fields[type].size += FILTER_DEFAULT_FIELD_SIZE;
info->fields[type].fields = taosMemoryRealloc(info->fields[type].fields, info->fields[type].size * sizeof(SFilterField)); info->fields[type].fields =
taosMemoryRealloc(info->fields[type].fields, info->fields[type].size * sizeof(SFilterField));
} }
info->fields[type].fields[idx].flag = type; info->fields[type].fields[idx].flag = type;
@ -1016,7 +1009,8 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type,
if (data && (*data) && dataLen > 0 && FILTER_GET_FLAG(info->options, FLT_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);
} }
taosHashPut(info->pctx.valHash, *data, dataLen, &idx, sizeof(idx)); taosHashPut(info->pctx.valHash, *data, dataLen, &idx, sizeof(idx));
@ -1041,14 +1035,14 @@ static FORCE_INLINE int32_t filterAddColFieldFromField(SFilterInfo *info, SFilte
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterAddFieldFromNode(SFilterInfo *info, SNode *node, SFilterFieldId *fid) { int32_t filterAddFieldFromNode(SFilterInfo *info, SNode *node, SFilterFieldId *fid) {
if (node == NULL) { if (node == NULL) {
fltError("empty node"); fltError("empty node");
FLT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); FLT_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
} }
if (nodeType(node) != QUERY_NODE_COLUMN && nodeType(node) != QUERY_NODE_VALUE && nodeType(node) != QUERY_NODE_NODE_LIST) { if (nodeType(node) != QUERY_NODE_COLUMN && nodeType(node) != QUERY_NODE_VALUE &&
nodeType(node) != QUERY_NODE_NODE_LIST) {
FLT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); FLT_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
} }
@ -1068,10 +1062,12 @@ int32_t filterAddFieldFromNode(SFilterInfo *info, SNode *node, SFilterFieldId *f
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterAddUnitImpl(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFilterFieldId *right, uint8_t optr2, SFilterFieldId *right2, uint32_t *uidx) { int32_t filterAddUnitImpl(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFilterFieldId *right, uint8_t optr2,
SFilterFieldId *right2, uint32_t *uidx) {
if (FILTER_GET_FLAG(info->options, FLT_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 {
char v[14] = {0}; char v[14] = {0};
FLT_PACKAGE_UNIT_HASH_KEY(&v, optr, optr2, left->idx, (right ? right->idx : -1), (right2 ? right2->idx : -1)); FLT_PACKAGE_UNIT_HASH_KEY(&v, optr, optr2, left->idx, (right ? right->idx : -1), (right2 ? right2->idx : -1));
@ -1132,7 +1128,6 @@ int32_t filterAddUnitImpl(SFilterInfo *info, uint8_t optr, SFilterFieldId *left,
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
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) {
return filterAddUnitImpl(info, optr, left, right, 0, NULL, uidx); return filterAddUnitImpl(info, optr, left, right, 0, NULL, uidx);
} }
@ -1217,7 +1212,6 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
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);
@ -1230,7 +1224,8 @@ int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u
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) == OP_TYPE_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);
FILTER_SET_FLAG(t->flag, FLD_DATA_IS_HASH); FILTER_SET_FLAG(t->flag, FLD_DATA_IS_HASH);
@ -1259,7 +1254,8 @@ int32_t filterAddUnitRight(SFilterInfo *info, uint8_t optr, SFilterFieldId *righ
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRangeCtx *ctx, uint32_t cidx, SFilterGroup *g, int32_t optr, SArray *res) { int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRangeCtx *ctx, uint32_t cidx,
SFilterGroup *g, int32_t optr, SArray *res) {
SFilterFieldId left, right, right2; SFilterFieldId left, right, right2;
uint32_t uidx = 0; uint32_t uidx = 0;
@ -1312,8 +1308,10 @@ 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);
filterAddUnitImpl(dst, FILTER_GET_FLAG(ra->sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left, &right, filterAddUnitImpl(
FILTER_GET_FLAG(ra->eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &right2, &uidx); dst, FILTER_GET_FLAG(ra->sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left,
&right, 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;
} }
@ -1323,7 +1321,8 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
void *data = taosMemoryMalloc(sizeof(int64_t)); void *data = taosMemoryMalloc(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) ? OP_TYPE_GREATER_THAN : OP_TYPE_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);
} }
@ -1331,7 +1330,8 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
void *data = taosMemoryMalloc(sizeof(int64_t)); void *data = taosMemoryMalloc(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) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_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);
} }
@ -1387,8 +1387,10 @@ 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);
filterAddUnitImpl(dst, FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left, &right, filterAddUnitImpl(
FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &right2, &uidx); dst, FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left,
&right, 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);
} }
@ -1403,7 +1405,8 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
void *data = taosMemoryMalloc(sizeof(int64_t)); void *data = taosMemoryMalloc(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) ? OP_TYPE_GREATER_THAN : OP_TYPE_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);
} }
@ -1411,7 +1414,8 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
void *data = taosMemoryMalloc(sizeof(int64_t)); void *data = taosMemoryMalloc(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) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_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);
} }
@ -1427,7 +1431,6 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static void filterFreeGroup(void *pItem) { static void filterFreeGroup(void *pItem) {
if (pItem == NULL) { if (pItem == NULL) {
return; return;
@ -1438,7 +1441,6 @@ static void filterFreeGroup(void *pItem) {
taosMemoryFreeClear(p->unitFlags); taosMemoryFreeClear(p->unitFlags);
} }
EDealRes fltTreeToGroup(SNode *pNode, void *pContext) { EDealRes fltTreeToGroup(SNode *pNode, void *pContext) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
SArray *preGroup = NULL; SArray *preGroup = NULL;
@ -1622,7 +1624,8 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
SValueNode *var = (SValueNode *)field->desc; SValueNode *var = (SValueNode *)field->desc;
SDataType *dType = &var->node.resType; SDataType *dType = &var->node.resType;
if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) { if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) {
qDebug("VAL%d => [type:TS][val:[%" PRIi64"] - [%" PRId64 "]]", i, *(int64_t *)field->data, *(((int64_t *)field->data) + 1)); qDebug("VAL%d => [type:TS][val:[%" PRIi64 "] - [%" PRId64 "]]", i, *(int64_t *)field->data,
*(((int64_t *)field->data) + 1));
} else { } else {
qDebug("VAL%d => [type:%d][val:%" PRIx64 "]", i, dType->type, var->datum.i); // TODO qDebug("VAL%d => [type:%d][val:%" PRIx64 "]", i, dType->type, var->datum.i); // TODO
} }
@ -1642,7 +1645,8 @@ 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);
SColumnNode *refNode = (SColumnNode *)left->desc; SColumnNode *refNode = (SColumnNode *)left->desc;
if (unit->compare.optr >= 0 && unit->compare.optr <= OP_TYPE_JSON_CONTAINS) { if (unit->compare.optr >= 0 && unit->compare.optr <= OP_TYPE_JSON_CONTAINS) {
len = sprintf(str, "UNIT[%d] => [%d][%d] %s [", i, refNode->dataBlockId, refNode->slotId, operatorTypeStr(unit->compare.optr)); len = sprintf(str, "UNIT[%d] => [%d][%d] %s [", i, refNode->dataBlockId, refNode->slotId,
operatorTypeStr(unit->compare.optr));
} }
if (unit->right.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != OP_TYPE_IN) { if (unit->right.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != OP_TYPE_IN) {
@ -1661,7 +1665,8 @@ 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 >= 0 && unit->compare.optr2 <= OP_TYPE_JSON_CONTAINS) { if (unit->compare.optr2 >= 0 && unit->compare.optr2 <= OP_TYPE_JSON_CONTAINS) {
sprintf(str + strlen(str), "[%d][%d] %s [", refNode->dataBlockId, refNode->slotId, operatorTypeStr(unit->compare.optr2)); sprintf(str + strlen(str), "[%d][%d] %s [", refNode->dataBlockId, refNode->slotId,
operatorTypeStr(unit->compare.optr2));
} }
if (unit->right2.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != OP_TYPE_IN) { if (unit->right2.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != OP_TYPE_IN) {
@ -1700,7 +1705,8 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
qDebug("RANGE Num:%u", info->colRangeNum); qDebug("RANGE Num:%u", info->colRangeNum);
for (uint32_t i = 0; i < info->colRangeNum; ++i) { for (uint32_t i = 0; i < info->colRangeNum; ++i) {
SFilterRangeCtx *ctx = info->colRange[i]; SFilterRangeCtx *ctx = info->colRange[i];
qDebug("Column ID[%d] RANGE: isnull[%d],notnull[%d],range[%d]", ctx->colId, ctx->isnull, ctx->notnull, ctx->isrange); qDebug("Column ID[%d] RANGE: isnull[%d],notnull[%d],range[%d]", ctx->colId, ctx->isnull, ctx->notnull,
ctx->isrange);
if (ctx->isrange) { if (ctx->isrange) {
SFilterRangeNode *r = ctx->rs; SFilterRangeNode *r = ctx->rs;
while (r) { while (r) {
@ -1784,7 +1790,6 @@ void filterFreeColCtx(void *data) {
} }
} }
void filterFreeGroupCtx(SFilterGroupCtx *gRes) { void filterFreeGroupCtx(SFilterGroupCtx *gRes) {
if (gRes == NULL) { if (gRes == NULL) {
return; return;
@ -1891,7 +1896,6 @@ int32_t filterHandleValueExtInfo(SFilterUnit* unit, char extInfo) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t fltInitValFieldData(SFilterInfo *info) { 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];
@ -1930,12 +1934,14 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
size_t bytes = 0; size_t bytes = 0;
if (type == TSDB_DATA_TYPE_BINARY) { if (type == TSDB_DATA_TYPE_BINARY) {
size_t len = (dType->type == TSDB_DATA_TYPE_BINARY || dType->type == TSDB_DATA_TYPE_NCHAR) ? dType->bytes : MAX_NUM_STR_SIZE; size_t len = (dType->type == TSDB_DATA_TYPE_BINARY || dType->type == TSDB_DATA_TYPE_NCHAR) ? dType->bytes
: MAX_NUM_STR_SIZE;
bytes = len + 1 + VARSTR_HEADER_SIZE; bytes = len + 1 + VARSTR_HEADER_SIZE;
fi->data = taosMemoryCalloc(1, bytes); fi->data = taosMemoryCalloc(1, bytes);
} else if (type == TSDB_DATA_TYPE_NCHAR) { } else if (type == TSDB_DATA_TYPE_NCHAR) {
size_t len = (dType->type == TSDB_DATA_TYPE_BINARY || dType->type == TSDB_DATA_TYPE_NCHAR) ? dType->bytes : MAX_NUM_STR_SIZE; size_t len = (dType->type == TSDB_DATA_TYPE_BINARY || dType->type == TSDB_DATA_TYPE_NCHAR) ? dType->bytes
: MAX_NUM_STR_SIZE;
bytes = (len + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE; bytes = (len + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
fi->data = taosMemoryCalloc(1, bytes); fi->data = taosMemoryCalloc(1, bytes);
@ -1979,8 +1985,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 == OP_TYPE_MATCH || unit->compare.optr == OP_TYPE_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((TdUcs4 *)varDataVal(fi->data), varDataLen(fi->data), varDataVal(newValData)); int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(fi->data), varDataLen(fi->data), varDataVal(newValData));
if (len < 0) { if (len < 0) {
@ -1995,7 +2000,6 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right) { 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);
@ -2044,7 +2048,6 @@ bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right)
return true; return true;
} }
int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit *u, SFilterRangeCtx *ctx, int32_t optr) { int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit *u, SFilterRangeCtx *ctx, int32_t optr) {
int32_t type = FILTER_UNIT_DATA_TYPE(u); int32_t type = FILTER_UNIT_DATA_TYPE(u);
uint8_t uoptr = FILTER_UNIT_OPTR(u); uint8_t uoptr = FILTER_UNIT_OPTR(u);
@ -2125,7 +2128,6 @@ _return:
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterMergeUnits(SFilterInfo *info, SFilterGroupCtx *gRes, uint32_t colIdx, bool *empty) { int32_t filterMergeUnits(SFilterInfo *info, SFilterGroupCtx *gRes, uint32_t colIdx, bool *empty) {
SArray *colArray = (SArray *)gRes->colInfo[colIdx].info; SArray *colArray = (SArray *)gRes->colInfo[colIdx].info;
int32_t size = (int32_t)taosArrayGetSize(colArray); int32_t size = (int32_t)taosArrayGetSize(colArray);
@ -2164,7 +2166,6 @@ _return:
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t *gResNum) { int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t *gResNum) {
bool empty = false; bool empty = false;
uint32_t *colIdx = taosMemoryMalloc(info->fields[FLD_TYPE_COLUMN].num * sizeof(uint32_t)); uint32_t *colIdx = taosMemoryMalloc(info->fields[FLD_TYPE_COLUMN].num * sizeof(uint32_t));
@ -2251,7 +2252,6 @@ bool filterIsSameUnits(SFilterColInfo* pCol1, SFilterColInfo* pCol2) {
return false; return false;
} }
SFilterRangeNode *pNode1 = pCtx1->rs; SFilterRangeNode *pNode1 = pCtx1->rs;
SFilterRangeNode *pNode2 = pCtx2->rs; SFilterRangeNode *pNode2 = pCtx2->rs;
@ -2264,7 +2264,8 @@ bool filterIsSameUnits(SFilterColInfo* pCol1, SFilterColInfo* pCol2) {
return false; return false;
} }
if (pNode1->ra.s != pNode2->ra.s || pNode1->ra.e != pNode2->ra.e || pNode1->ra.sflag != pNode2->ra.sflag || pNode1->ra.eflag != pNode2->ra.eflag) { if (pNode1->ra.s != pNode2->ra.s || pNode1->ra.e != pNode2->ra.e || pNode1->ra.sflag != pNode2->ra.sflag ||
pNode1->ra.eflag != pNode2->ra.eflag) {
return false; return false;
} }
@ -2330,8 +2331,8 @@ void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool
return; return;
} }
int32_t filterMergeTwoGroupsImpl(SFilterInfo *info, SFilterRangeCtx **ctx, int32_t optr, uint32_t cidx,
int32_t filterMergeTwoGroupsImpl(SFilterInfo *info, SFilterRangeCtx **ctx, int32_t optr, uint32_t cidx, SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool *empty, bool *all) { SFilterGroupCtx *gRes1, SFilterGroupCtx *gRes2, bool *empty, bool *all) {
SFilterField *fi = FILTER_GET_COL_FIELD(info, cidx); SFilterField *fi = FILTER_GET_COL_FIELD(info, cidx);
int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); int32_t type = FILTER_GET_COL_FIELD_TYPE(fi);
@ -2350,7 +2351,6 @@ int32_t filterMergeTwoGroupsImpl(SFilterInfo *info, SFilterRangeCtx **ctx, int32
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx **gRes1, SFilterGroupCtx **gRes2, bool *all) { int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx **gRes1, SFilterGroupCtx **gRes2, bool *all) {
bool conflict = false; bool conflict = false;
@ -2469,7 +2469,6 @@ _return:
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t *gResNum) { int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t *gResNum) {
if (*gResNum <= 1) { if (*gResNum <= 1) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -2743,7 +2742,6 @@ int32_t filterPostProcessRange(SFilterInfo *info) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterGenerateComInfo(SFilterInfo *info) { int32_t filterGenerateComInfo(SFilterInfo *info) {
info->cunits = taosMemoryMalloc(info->unitNum * sizeof(*info->cunits)); info->cunits = taosMemoryMalloc(info->unitNum * sizeof(*info->cunits));
info->blkUnitRes = taosMemoryMalloc(sizeof(*info->blkUnitRes) * info->unitNum); info->blkUnitRes = taosMemoryMalloc(sizeof(*info->blkUnitRes) * info->unitNum);
@ -2787,7 +2785,6 @@ int32_t filterUpdateComUnits(SFilterInfo *info) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t numOfCols, int32_t numOfRows) { int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t numOfCols, int32_t numOfRows) {
int32_t rmUnit = 0; int32_t rmUnit = 0;
@ -2838,9 +2835,8 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3
} }
} }
if (cunit->optr == OP_TYPE_IS_NULL || cunit->optr == OP_TYPE_IS_NOT_NULL if (cunit->optr == OP_TYPE_IS_NULL || cunit->optr == OP_TYPE_IS_NOT_NULL || cunit->optr == OP_TYPE_IN ||
|| cunit->optr == OP_TYPE_IN || cunit->optr == OP_TYPE_LIKE || cunit->optr == OP_TYPE_MATCH cunit->optr == OP_TYPE_LIKE || cunit->optr == OP_TYPE_MATCH || cunit->optr == OP_TYPE_NOT_EQUAL) {
|| cunit->optr == OP_TYPE_NOT_EQUAL) {
continue; continue;
} }
@ -2863,8 +2859,10 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3
bool minRes = false, maxRes = false; bool minRes = false, maxRes = false;
if (cunit->rfunc >= 0) { if (cunit->rfunc >= 0) {
minRes = (*gRangeCompare[cunit->rfunc])(minVal, minVal, cunit->valData, cunit->valData2, gDataCompare[cunit->func]); minRes =
maxRes = (*gRangeCompare[cunit->rfunc])(maxVal, maxVal, cunit->valData, cunit->valData2, gDataCompare[cunit->func]); (*gRangeCompare[cunit->rfunc])(minVal, minVal, cunit->valData, cunit->valData2, gDataCompare[cunit->func]);
maxRes =
(*gRangeCompare[cunit->rfunc])(maxVal, maxVal, cunit->valData, cunit->valData2, gDataCompare[cunit->func]);
if (minRes && maxRes) { if (minRes && maxRes) {
info->blkUnitRes[k] = 1; info->blkUnitRes[k] = 1;
@ -2903,7 +2901,6 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3
rmUnit = 1; rmUnit = 1;
} }
} }
} }
if (rmUnit == 0) { if (rmUnit == 0) {
@ -2976,7 +2973,8 @@ _return:
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, SColumnInfoData* pRes, SColumnDataAgg *statis, int16_t numOfCols) { bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SColumnDataAgg *statis,
int16_t numOfCols) {
SFilterInfo *info = (SFilterInfo *)pinfo; SFilterInfo *info = (SFilterInfo *)pinfo;
bool all = true; bool all = true;
uint32_t *unitIdx = NULL; uint32_t *unitIdx = NULL;
@ -3007,7 +3005,8 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, SColumnInfoD
} else if (optr == OP_TYPE_IS_NULL) { } 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 {
p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData); p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData);
} }
@ -3036,9 +3035,8 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, SColumnInfoD
return all; return all;
} }
int32_t filterExecuteBasedOnStatis(SFilterInfo *info, int32_t numOfRows, SColumnInfoData *p, SColumnDataAgg *statis,
int16_t numOfCols, bool *all) {
int32_t filterExecuteBasedOnStatis(SFilterInfo *info, int32_t numOfRows, SColumnInfoData* p, SColumnDataAgg *statis, int16_t numOfCols, bool* all) {
if (statis && numOfRows >= FILTER_RM_UNIT_MIN_ROWS) { if (statis && numOfRows >= FILTER_RM_UNIT_MIN_ROWS) {
info->blkFlag = 0; info->blkFlag = 0;
@ -3067,11 +3065,13 @@ _return:
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static FORCE_INLINE bool filterExecuteImplAll(void *info, int32_t numOfRows, SColumnInfoData* p, SColumnDataAgg *statis, int16_t numOfCols, int32_t* numOfQualified) { static FORCE_INLINE bool filterExecuteImplAll(void *info, int32_t numOfRows, SColumnInfoData *p, SColumnDataAgg *statis,
int16_t numOfCols, int32_t *numOfQualified) {
return true; return true;
} }
static FORCE_INLINE bool filterExecuteImplEmpty(void *info, int32_t numOfRows, SColumnInfoData* p, SColumnDataAgg *statis, int16_t numOfCols, int32_t* numOfQualified) { static FORCE_INLINE bool filterExecuteImplEmpty(void *info, int32_t numOfRows, SColumnInfoData *p,
SColumnDataAgg *statis, int16_t numOfCols, int32_t *numOfQualified) {
return false; return false;
} }
@ -3127,7 +3127,8 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows
return all; return all;
} }
bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, SColumnInfoData* pRes, SColumnDataAgg *statis, int16_t numOfCols, int32_t* numOfQualified) { bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SColumnDataAgg *statis,
int16_t numOfCols, int32_t *numOfQualified) {
SFilterInfo *info = (SFilterInfo *)pinfo; SFilterInfo *info = (SFilterInfo *)pinfo;
bool all = true; bool all = true;
uint16_t dataSize = info->cunits[0].dataSize; uint16_t dataSize = info->cunits[0].dataSize;
@ -3184,18 +3185,21 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes
} }
// 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 == OP_TYPE_MATCH || info->cunits[uidx].optr == OP_TYPE_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 = taosMemoryCalloc(info->cunits[uidx].dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1); char *newColData = taosMemoryCalloc(info->cunits[uidx].dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1);
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(colData), varDataLen(colData), varDataVal(newColData)); int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(colData), varDataLen(colData), varDataVal(newColData));
if (len < 0) { if (len < 0) {
qError("castConvert1 taosUcs4ToMbs error"); qError("castConvert1 taosUcs4ToMbs error");
} else { } else {
varDataSetLen(newColData, len); varDataSetLen(newColData, len);
p[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, newColData, info->cunits[uidx].valData); p[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, newColData,
info->cunits[uidx].valData);
} }
taosMemoryFreeClear(newColData); taosMemoryFreeClear(newColData);
} else { } else {
p[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, colData, info->cunits[uidx].valData); p[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, colData,
info->cunits[uidx].valData);
} }
if (p[i] == 0) { if (p[i] == 0) {
@ -3242,9 +3246,11 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SC
} else if (optr == OP_TYPE_IS_NULL) { } 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 == OP_TYPE_MATCH || cunit->optr == OP_TYPE_NMATCH)){ if (cunit->dataType == TSDB_DATA_TYPE_NCHAR &&
(cunit->optr == OP_TYPE_MATCH || cunit->optr == OP_TYPE_NMATCH)) {
char *newColData = taosMemoryCalloc(cunit->dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1); char *newColData = taosMemoryCalloc(cunit->dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1);
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(colData), varDataLen(colData), varDataVal(newColData)); int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(colData), varDataLen(colData), varDataVal(newColData));
if (len < 0) { if (len < 0) {
@ -3318,8 +3324,6 @@ int32_t filterSetExecFunc(SFilterInfo *info) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterPreprocess(SFilterInfo *info) { int32_t filterPreprocess(SFilterInfo *info) {
SFilterGroupCtx **gRes = taosMemoryCalloc(info->groupNum, sizeof(SFilterGroupCtx *)); SFilterGroupCtx **gRes = taosMemoryCalloc(info->groupNum, sizeof(SFilterGroupCtx *));
int32_t gResNum = 0; int32_t gResNum = 0;
@ -3333,7 +3337,6 @@ int32_t filterPreprocess(SFilterInfo *info) {
goto _return; goto _return;
} }
if (FILTER_GET_FLAG(info->status, FI_STATUS_EMPTY)) { if (FILTER_GET_FLAG(info->status, FI_STATUS_EMPTY)) {
fltInfo("Final - FilterInfo: [EMPTY]"); fltInfo("Final - FilterInfo: [EMPTY]");
goto _return; goto _return;
@ -3362,7 +3365,6 @@ _return:
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t fltSetColFieldDataImpl(SFilterInfo *info, void *param, filer_get_col_from_id fp, bool fromColId) { int32_t fltSetColFieldDataImpl(SFilterInfo *info, void *param, filer_get_col_from_id fp, bool fromColId) {
if (FILTER_ALL_RES(info) || FILTER_EMPTY_RES(info)) { if (FILTER_ALL_RES(info) || FILTER_EMPTY_RES(info)) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -3383,7 +3385,6 @@ int32_t fltSetColFieldDataImpl(SFilterInfo *info, void *param, filer_get_col_fro
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t fltInitFromNode(SNode *tree, SFilterInfo *info, uint32_t options) { int32_t fltInitFromNode(SNode *tree, SFilterInfo *info, uint32_t options) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
@ -3512,8 +3513,6 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t
return ret; return ret;
} }
int32_t filterGetTimeRangeImpl(SFilterInfo *info, STimeWindow *win, bool *isStrict) { int32_t filterGetTimeRangeImpl(SFilterInfo *info, STimeWindow *win, bool *isStrict) {
SFilterRange ra = {0}; SFilterRange ra = {0};
SFilterRangeCtx *prev = filterInitRangeCtx(TSDB_DATA_TYPE_TIMESTAMP, FLT_OPTION_TIMESTAMP); SFilterRangeCtx *prev = filterInitRangeCtx(TSDB_DATA_TYPE_TIMESTAMP, FLT_OPTION_TIMESTAMP);
@ -3606,7 +3605,6 @@ _return:
return code; return code;
} }
int32_t filterGetTimeRange(SNode *pNode, STimeWindow *win, bool *isStrict) { int32_t filterGetTimeRange(SNode *pNode, STimeWindow *win, bool *isStrict) {
SFilterInfo *info = NULL; SFilterInfo *info = NULL;
int32_t code = 0; int32_t code = 0;
@ -3630,7 +3628,6 @@ _return:
FLT_RET(code); FLT_RET(code);
} }
int32_t filterConverNcharColumns(SFilterInfo *info, int32_t rows, bool *gotNchar) { int32_t filterConverNcharColumns(SFilterInfo *info, int32_t rows, bool *gotNchar) {
if (FILTER_EMPTY_RES(info) || FILTER_ALL_RES(info)) { if (FILTER_EMPTY_RES(info) || FILTER_ALL_RES(info)) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -3651,7 +3648,8 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar
int32_t len = 0; int32_t len = 0;
char *varSrc = varDataVal(src); char *varSrc = varDataVal(src);
size_t k = 0, varSrcLen = varDataLen(src); size_t k = 0, varSrcLen = varDataLen(src);
while (k < varSrcLen && varSrc[k++] == -1) {} while (k < varSrcLen && varSrc[k++] == -1) {
}
if (k == varSrcLen) { if (k == varSrcLen) {
/* NULL */ /* NULL */
varDataLen(dst) = (VarDataLenT)varSrcLen; varDataLen(dst) = (VarDataLenT)varSrcLen;
@ -3801,13 +3799,14 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
if (node->opType == OP_TYPE_NOT_IN || node->opType == OP_TYPE_NOT_LIKE || node->opType > OP_TYPE_IS_NOT_NULL || node->opType == OP_TYPE_NOT_EQUAL) { if (node->opType == OP_TYPE_NOT_IN || node->opType == OP_TYPE_NOT_LIKE || node->opType > OP_TYPE_IS_NOT_NULL ||
node->opType == OP_TYPE_NOT_EQUAL) {
stat->scalarMode = true; stat->scalarMode = true;
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) && if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) && (node->opType >= OP_TYPE_NOT_EQUAL) &&
(node->opType >= OP_TYPE_NOT_EQUAL) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL)) { (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL)) {
stat->scalarMode = true; stat->scalarMode = true;
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
@ -3824,8 +3823,9 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
if (OP_TYPE_IS_TRUE == node->opType || OP_TYPE_IS_FALSE == node->opType || OP_TYPE_IS_UNKNOWN == node->opType if (OP_TYPE_IS_TRUE == node->opType || OP_TYPE_IS_FALSE == node->opType || OP_TYPE_IS_UNKNOWN == node->opType ||
|| OP_TYPE_IS_NOT_TRUE == node->opType || OP_TYPE_IS_NOT_FALSE == node->opType || OP_TYPE_IS_NOT_UNKNOWN == node->opType) { OP_TYPE_IS_NOT_TRUE == node->opType || OP_TYPE_IS_NOT_FALSE == node->opType ||
OP_TYPE_IS_NOT_UNKNOWN == node->opType) {
stat->scalarMode = true; stat->scalarMode = true;
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
@ -3835,7 +3835,8 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
if ((QUERY_NODE_COLUMN != nodeType(node->pRight)) && (QUERY_NODE_VALUE != nodeType(node->pRight)) && (QUERY_NODE_NODE_LIST != nodeType(node->pRight))) { if ((QUERY_NODE_COLUMN != nodeType(node->pRight)) && (QUERY_NODE_VALUE != nodeType(node->pRight)) &&
(QUERY_NODE_NODE_LIST != nodeType(node->pRight))) {
stat->scalarMode = true; stat->scalarMode = true;
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
@ -3881,8 +3882,8 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
if (OP_TYPE_IN != node->opType) { if (OP_TYPE_IN != node->opType) {
SColumnNode *refNode = (SColumnNode *)node->pLeft; SColumnNode *refNode = (SColumnNode *)node->pLeft;
SValueNode *valueNode = (SValueNode *)node->pRight; SValueNode *valueNode = (SValueNode *)node->pRight;
if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) &&
&& TSDB_DATA_TYPE_UBIGINT == valueNode->node.resType.type && valueNode->datum.u <= INT64_MAX) { TSDB_DATA_TYPE_UBIGINT == valueNode->node.resType.type && valueNode->datum.u <= INT64_MAX) {
valueNode->node.resType.type = TSDB_DATA_TYPE_BIGINT; valueNode->node.resType.type = TSDB_DATA_TYPE_BIGINT;
} }
int32_t type = vectorGetConvertType(refNode->node.resType.type, valueNode->node.resType.type); int32_t type = vectorGetConvertType(refNode->node.resType.type, valueNode->node.resType.type);
@ -3935,7 +3936,6 @@ int32_t fltOptimizeNodes(SFilterInfo *pInfo, SNode** pNode, SFltTreeStat *pStat)
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t fltGetDataFromColId(void *param, int32_t id, void **data) { int32_t fltGetDataFromColId(void *param, int32_t id, void **data) {
int32_t numOfCols = ((SFilterColumnParam *)param)->numOfCols; int32_t numOfCols = ((SFilterColumnParam *)param)->numOfCols;
SArray *pDataBlock = ((SFilterColumnParam *)param)->pDataBlock; SArray *pDataBlock = ((SFilterColumnParam *)param)->pDataBlock;
@ -3955,7 +3955,8 @@ int32_t fltGetDataFromSlotId(void *param, int32_t id, void **data) {
int32_t numOfCols = ((SFilterColumnParam *)param)->numOfCols; int32_t numOfCols = ((SFilterColumnParam *)param)->numOfCols;
SArray *pDataBlock = ((SFilterColumnParam *)param)->pDataBlock; SArray *pDataBlock = ((SFilterColumnParam *)param)->pDataBlock;
if (id < 0 || id >= numOfCols || id >= taosArrayGetSize(pDataBlock)) { if (id < 0 || id >= numOfCols || id >= taosArrayGetSize(pDataBlock)) {
fltError("invalid slot id, id:%d, numOfCols:%d, arraySize:%d", id, numOfCols, (int32_t)taosArrayGetSize(pDataBlock)); fltError("invalid slot id, id:%d, numOfCols:%d, arraySize:%d", id, numOfCols,
(int32_t)taosArrayGetSize(pDataBlock));
return TSDB_CODE_QRY_APP_ERROR; return TSDB_CODE_QRY_APP_ERROR;
} }
@ -3965,8 +3966,6 @@ int32_t fltGetDataFromSlotId(void *param, int32_t id, void **data) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterSetDataFromSlotId(SFilterInfo *info, void *param) { int32_t filterSetDataFromSlotId(SFilterInfo *info, void *param) {
if (NULL == info) { if (NULL == info) {
return TSDB_CODE_QRY_INVALID_INPUT; return TSDB_CODE_QRY_INVALID_INPUT;
@ -3979,8 +3978,6 @@ int32_t filterSetDataFromColId(SFilterInfo *info, void *param) {
return fltSetColFieldDataImpl(info, param, fltGetDataFromColId, true); return fltSetColFieldDataImpl(info, param, fltGetDataFromColId, true);
} }
int32_t filterInitFromNode(SNode *pNode, SFilterInfo **pInfo, uint32_t options) { int32_t filterInitFromNode(SNode *pNode, SFilterInfo **pInfo, uint32_t options) {
int32_t code = 0; int32_t code = 0;
SFilterInfo *info = NULL; SFilterInfo *info = NULL;
@ -4028,7 +4025,8 @@ _return:
FLT_RET(code); FLT_RET(code);
} }
bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, SColumnInfoData** p, SColumnDataAgg *statis, int16_t numOfCols, int32_t *pResultStatus) { bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, SColumnInfoData **p, SColumnDataAgg *statis, int16_t numOfCols,
int32_t *pResultStatus) {
if (NULL == info) { if (NULL == info) {
*pResultStatus = FILTER_RESULT_ALL_QUALIFIED; *pResultStatus = FILTER_RESULT_ALL_QUALIFIED;
return false; return false;

View File

@ -1,3 +1,4 @@
#include "scalar.h"
#include "function.h" #include "function.h"
#include "functionMgt.h" #include "functionMgt.h"
#include "nodes.h" #include "nodes.h"
@ -5,16 +6,15 @@
#include "sclInt.h" #include "sclInt.h"
#include "sclvector.h" #include "sclvector.h"
#include "tcommon.h" #include "tcommon.h"
#include "tdatablock.h"
#include "scalar.h"
#include "tudf.h"
#include "ttime.h"
#include "tcompare.h" #include "tcompare.h"
#include "tdatablock.h"
#include "ttime.h"
#include "tudf.h"
int32_t scalarGetOperatorParamNum(EOperatorType type) { int32_t scalarGetOperatorParamNum(EOperatorType type) {
if (OP_TYPE_IS_NULL == type || OP_TYPE_IS_NOT_NULL == type || OP_TYPE_IS_TRUE == type || OP_TYPE_IS_NOT_TRUE == type if (OP_TYPE_IS_NULL == type || OP_TYPE_IS_NOT_NULL == type || OP_TYPE_IS_TRUE == type ||
|| OP_TYPE_IS_FALSE == type || OP_TYPE_IS_NOT_FALSE == type || OP_TYPE_IS_UNKNOWN == type || OP_TYPE_IS_NOT_UNKNOWN == type OP_TYPE_IS_NOT_TRUE == type || OP_TYPE_IS_FALSE == type || OP_TYPE_IS_NOT_FALSE == type ||
|| OP_TYPE_MINUS == type) { OP_TYPE_IS_UNKNOWN == type || OP_TYPE_IS_NOT_UNKNOWN == type || OP_TYPE_MINUS == type) {
return 1; return 1;
} }
@ -23,7 +23,8 @@ int32_t scalarGetOperatorParamNum(EOperatorType type) {
int32_t sclConvertToTsValueNode(int8_t precision, SValueNode *valueNode) { int32_t sclConvertToTsValueNode(int8_t precision, SValueNode *valueNode) {
char *timeStr = valueNode->datum.p; char *timeStr = valueNode->datum.p;
int32_t code = convertStringToTimestamp(valueNode->node.resType.type, valueNode->datum.p, precision, &valueNode->datum.i); int32_t code =
convertStringToTimestamp(valueNode->node.resType.type, valueNode->datum.p, precision, &valueNode->datum.i);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return code; return code;
} }
@ -358,7 +359,8 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t
} }
if (index == -1) { if (index == -1) {
sclError("column tupleId is too big, tupleId:%d, dataBlockNum:%d", ref->dataBlockId, (int32_t)taosArrayGetSize(ctx->pBlockList)); sclError("column tupleId is too big, tupleId:%d, dataBlockNum:%d", ref->dataBlockId,
(int32_t)taosArrayGetSize(ctx->pBlockList));
SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
} }
@ -368,13 +370,15 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t
} }
if (ref->slotId >= taosArrayGetSize(block->pDataBlock)) { if (ref->slotId >= taosArrayGetSize(block->pDataBlock)) {
sclError("column slotId is too big, slodId:%d, dataBlockSize:%d", ref->slotId, (int32_t)taosArrayGetSize(block->pDataBlock)); sclError("column slotId is too big, slodId:%d, dataBlockSize:%d", ref->slotId,
(int32_t)taosArrayGetSize(block->pDataBlock));
SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
} }
SColumnInfoData *columnData = (SColumnInfoData *)taosArrayGet(block->pDataBlock, ref->slotId); SColumnInfoData *columnData = (SColumnInfoData *)taosArrayGet(block->pDataBlock, ref->slotId);
#if TAG_FILTER_DEBUG #if TAG_FILTER_DEBUG
qDebug("tagfilter column info, slotId:%d, colId:%d, type:%d", ref->slotId, columnData->info.colId, columnData->info.type); qDebug("tagfilter column info, slotId:%d, colId:%d, type:%d", ref->slotId, columnData->info.colId,
columnData->info.type);
#endif #endif
param->numOfRows = block->info.rows; param->numOfRows = block->info.rows;
param->columnData = columnData; param->columnData = columnData;
@ -409,7 +413,8 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t sclInitParamList(SScalarParam **pParams, SNodeList* pParamList, SScalarCtx *ctx, int32_t *paramNum, int32_t *rowNum) { int32_t sclInitParamList(SScalarParam **pParams, SNodeList *pParamList, SScalarCtx *ctx, int32_t *paramNum,
int32_t *rowNum) {
int32_t code = 0; int32_t code = 0;
if (NULL == pParamList) { if (NULL == pParamList) {
if (ctx->pBlockList) { if (ctx->pBlockList) {
@ -499,7 +504,6 @@ int32_t sclGetNodeType(SNode *pNode, SScalarCtx *ctx) {
return -1; return -1;
} }
void sclSetOperatorValueType(SOperatorNode *node, SScalarCtx *ctx) { void sclSetOperatorValueType(SOperatorNode *node, SScalarCtx *ctx) {
ctx->type.opResType = node->node.resType.type; ctx->type.opResType = node->node.resType.type;
ctx->type.selfType = sclGetNodeType(node->pLeft, ctx); ctx->type.selfType = sclGetNodeType(node->pLeft, ctx);
@ -577,7 +581,8 @@ _return:
int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *output) { int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *output) {
if (NULL == node->pParameterList || node->pParameterList->length <= 0) { 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); sclError("invalid logic parameter list, list:%p, paramNum:%d", node->pParameterList,
node->pParameterList ? node->pParameterList->length : 0);
SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
} }
@ -663,7 +668,8 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp
// json not support in in operator // json not support in in operator
if (nodeType(node->pLeft) == QUERY_NODE_VALUE) { if (nodeType(node->pLeft) == QUERY_NODE_VALUE) {
SValueNode *valueNode = (SValueNode *)node->pLeft; SValueNode *valueNode = (SValueNode *)node->pLeft;
if (valueNode->node.resType.type == TSDB_DATA_TYPE_JSON && (node->opType == OP_TYPE_IN || node->opType == OP_TYPE_NOT_IN)) { if (valueNode->node.resType.type == TSDB_DATA_TYPE_JSON &&
(node->opType == OP_TYPE_IN || node->opType == OP_TYPE_NOT_IN)) {
SCL_RET(TSDB_CODE_QRY_JSON_IN_ERROR); SCL_RET(TSDB_CODE_QRY_JSON_IN_ERROR);
} }
} }
@ -736,7 +742,6 @@ EDealRes sclAggFuncWalker(SNode* pNode, void* pContext) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
bool sclContainsAggFuncNode(SNode *pNode) { bool sclContainsAggFuncNode(SNode *pNode) {
bool aggFunc = false; bool aggFunc = false;
nodesWalkExpr(pNode, sclAggFuncWalker, (void *)&aggFunc); nodesWalkExpr(pNode, sclAggFuncWalker, (void *)&aggFunc);
@ -749,13 +754,13 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) {
if (node->pLeft && (QUERY_NODE_VALUE == nodeType(node->pLeft))) { if (node->pLeft && (QUERY_NODE_VALUE == nodeType(node->pLeft))) {
SValueNode *valueNode = (SValueNode *)node->pLeft; SValueNode *valueNode = (SValueNode *)node->pLeft;
if (SCL_IS_NULL_VALUE_NODE(valueNode) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL) if (SCL_IS_NULL_VALUE_NODE(valueNode) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL) &&
&& (!sclContainsAggFuncNode(node->pRight))) { (!sclContainsAggFuncNode(node->pRight))) {
return sclRewriteNullInOptr(pNode, ctx, node->opType); return sclRewriteNullInOptr(pNode, ctx, node->opType);
} }
if (IS_STR_DATA_TYPE(valueNode->node.resType.type) && node->pRight && nodesIsExprNode(node->pRight) if (IS_STR_DATA_TYPE(valueNode->node.resType.type) && node->pRight && nodesIsExprNode(node->pRight) &&
&& ((SExprNode*)node->pRight)->resType.type == TSDB_DATA_TYPE_TIMESTAMP) { ((SExprNode *)node->pRight)->resType.type == TSDB_DATA_TYPE_TIMESTAMP) {
code = sclConvertToTsValueNode(((SExprNode *)node->pRight)->resType.precision, valueNode); code = sclConvertToTsValueNode(((SExprNode *)node->pRight)->resType.precision, valueNode);
if (code) { if (code) {
ctx->code = code; ctx->code = code;
@ -770,13 +775,13 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) {
if (node->pRight && (QUERY_NODE_VALUE == nodeType(node->pRight))) { if (node->pRight && (QUERY_NODE_VALUE == nodeType(node->pRight))) {
SValueNode *valueNode = (SValueNode *)node->pRight; SValueNode *valueNode = (SValueNode *)node->pRight;
if (SCL_IS_NULL_VALUE_NODE(valueNode) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL) if (SCL_IS_NULL_VALUE_NODE(valueNode) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL) &&
&& (!sclContainsAggFuncNode(node->pLeft))) { (!sclContainsAggFuncNode(node->pLeft))) {
return sclRewriteNullInOptr(pNode, ctx, node->opType); return sclRewriteNullInOptr(pNode, ctx, node->opType);
} }
if (IS_STR_DATA_TYPE(valueNode->node.resType.type) && node->pLeft && nodesIsExprNode(node->pLeft) if (IS_STR_DATA_TYPE(valueNode->node.resType.type) && node->pLeft && nodesIsExprNode(node->pLeft) &&
&& ((SExprNode*)node->pLeft)->resType.type == TSDB_DATA_TYPE_TIMESTAMP) { ((SExprNode *)node->pLeft)->resType.type == TSDB_DATA_TYPE_TIMESTAMP) {
code = sclConvertToTsValueNode(((SExprNode *)node->pLeft)->resType.precision, valueNode); code = sclConvertToTsValueNode(((SExprNode *)node->pLeft)->resType.precision, valueNode);
if (code) { if (code) {
ctx->code = code; ctx->code = code;
@ -1028,7 +1033,8 @@ EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) {
STargetNode *target = (STargetNode *)pNode; STargetNode *target = (STargetNode *)pNode;
if (target->dataBlockId >= taosArrayGetSize(ctx->pBlockList)) { if (target->dataBlockId >= taosArrayGetSize(ctx->pBlockList)) {
sclError("target tupleId is too big, tupleId:%d, dataBlockNum:%d", target->dataBlockId, (int32_t)taosArrayGetSize(ctx->pBlockList)); sclError("target tupleId is too big, tupleId:%d, dataBlockNum:%d", target->dataBlockId,
(int32_t)taosArrayGetSize(ctx->pBlockList));
ctx->code = TSDB_CODE_QRY_INVALID_INPUT; ctx->code = TSDB_CODE_QRY_INVALID_INPUT;
return DEAL_RES_ERROR; return DEAL_RES_ERROR;
} }
@ -1043,7 +1049,8 @@ EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) {
} }
if (index == -1) { if (index == -1) {
sclError("column tupleId is too big, tupleId:%d, dataBlockNum:%d", target->dataBlockId, (int32_t)taosArrayGetSize(ctx->pBlockList)); sclError("column tupleId is too big, tupleId:%d, dataBlockNum:%d", target->dataBlockId,
(int32_t)taosArrayGetSize(ctx->pBlockList));
ctx->code = TSDB_CODE_QRY_INVALID_INPUT; ctx->code = TSDB_CODE_QRY_INVALID_INPUT;
return DEAL_RES_ERROR; return DEAL_RES_ERROR;
} }
@ -1051,7 +1058,8 @@ EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) {
SSDataBlock *block = *(SSDataBlock **)taosArrayGet(ctx->pBlockList, index); SSDataBlock *block = *(SSDataBlock **)taosArrayGet(ctx->pBlockList, index);
if (target->slotId >= taosArrayGetSize(block->pDataBlock)) { if (target->slotId >= taosArrayGetSize(block->pDataBlock)) {
sclError("target slot not exist, dataBlockId:%d, slotId:%d, dataBlockNum:%d", target->dataBlockId, target->slotId, (int32_t)taosArrayGetSize(block->pDataBlock)); sclError("target slot not exist, dataBlockId:%d, slotId:%d, dataBlockNum:%d", target->dataBlockId, target->slotId,
(int32_t)taosArrayGetSize(block->pDataBlock));
ctx->code = TSDB_CODE_QRY_INVALID_INPUT; ctx->code = TSDB_CODE_QRY_INVALID_INPUT;
return DEAL_RES_ERROR; return DEAL_RES_ERROR;
} }
@ -1075,7 +1083,8 @@ EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) {
} }
EDealRes sclCalcWalker(SNode *pNode, void *pContext) { EDealRes sclCalcWalker(SNode *pNode, void *pContext) {
if (QUERY_NODE_VALUE == nodeType(pNode) || QUERY_NODE_NODE_LIST == nodeType(pNode) || QUERY_NODE_COLUMN == nodeType(pNode)|| QUERY_NODE_LEFT_VALUE == nodeType(pNode)) { if (QUERY_NODE_VALUE == nodeType(pNode) || QUERY_NODE_NODE_LIST == nodeType(pNode) ||
QUERY_NODE_COLUMN == nodeType(pNode) || QUERY_NODE_LEFT_VALUE == nodeType(pNode)) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
@ -1212,14 +1221,9 @@ static int32_t sclGetBitwiseOperatorResType(SOperatorNode* pOp) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) { return sclCalcConstants(pNode, false, pRes); }
int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) { int32_t scalarCalculateConstantsFromDual(SNode *pNode, SNode **pRes) { return sclCalcConstants(pNode, true, pRes); }
return sclCalcConstants(pNode, false, pRes);
}
int32_t scalarCalculateConstantsFromDual(SNode *pNode, SNode **pRes) {
return sclCalcConstants(pNode, true, pRes);
}
int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) { int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) {
if (NULL == pNode || NULL == pBlockList) { if (NULL == pNode || NULL == pBlockList) {

View File

@ -1,3 +1,4 @@
#include "cJSON.h"
#include "function.h" #include "function.h"
#include "scalar.h" #include "scalar.h"
#include "sclInt.h" #include "sclInt.h"
@ -5,7 +6,6 @@
#include "tdatablock.h" #include "tdatablock.h"
#include "tjson.h" #include "tjson.h"
#include "ttime.h" #include "ttime.h"
#include "cJSON.h"
#include "vnode.h" #include "vnode.h"
typedef float (*_float_fn)(float); typedef float (*_float_fn)(float);
@ -16,9 +16,7 @@ typedef void (*_trim_fn)(char *, char*, int32_t, int32_t);
typedef int16_t (*_len_fn)(char *, int32_t); typedef int16_t (*_len_fn)(char *, int32_t);
/** Math functions **/ /** Math functions **/
static double tlog(double v) { static double tlog(double v) { return log(v); }
return log(v);
}
static double tlog2(double v, double base) { static double tlog2(double v, double base) {
double a = log(v); double a = log(v);
@ -160,7 +158,8 @@ static int32_t doScalarFunctionUnique(SScalarParam *pInput, int32_t inputNum, SS
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, SScalarParam* pOutput, _double_fn_2 valFn) { static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput,
_double_fn_2 valFn) {
SColumnInfoData *pInputData[2]; SColumnInfoData *pInputData[2];
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
_getDoubleValue_fn_t getValueFn[2]; _getDoubleValue_fn_t getValueFn[2];
@ -173,15 +172,12 @@ static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, S
double *out = (double *)pOutputData->pData; double *out = (double *)pOutputData->pData;
double result; double result;
bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) || bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) || IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1])));
IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1])));
int32_t numOfRows = TMAX(pInput[0].numOfRows, pInput[1].numOfRows); int32_t numOfRows = TMAX(pInput[0].numOfRows, pInput[1].numOfRows);
if (pInput[0].numOfRows == pInput[1].numOfRows) { if (pInput[0].numOfRows == pInput[1].numOfRows) {
for (int32_t i = 0; i < numOfRows; ++i) { for (int32_t i = 0; i < numOfRows; ++i) {
if (colDataIsNull_s(pInputData[0], i) || if (colDataIsNull_s(pInputData[0], i) || colDataIsNull_s(pInputData[1], i) || hasNullType) {
colDataIsNull_s(pInputData[1], i) ||
hasNullType) {
colDataAppendNULL(pOutputData, i); colDataAppendNULL(pOutputData, i);
continue; continue;
} }
@ -236,7 +232,8 @@ static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, S
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam* pOutput, _float_fn f1, _double_fn d1) { static int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _float_fn f1,
_double_fn d1) {
int32_t type = GET_PARAM_TYPE(pInput); int32_t type = GET_PARAM_TYPE(pInput);
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
@ -288,9 +285,7 @@ static int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
} }
/** String functions **/ /** String functions **/
static int16_t tlength(char *input, int32_t type) { static int16_t tlength(char *input, int32_t type) { return varDataLen(input); }
return varDataLen(input);
}
static int16_t tcharlength(char *input, int32_t type) { static int16_t tcharlength(char *input, int32_t type) {
if (type == TSDB_DATA_TYPE_VARCHAR) { if (type == TSDB_DATA_TYPE_VARCHAR) {
@ -451,8 +446,7 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
for (int32_t k = 0; k < numOfRows; ++k) { for (int32_t k = 0; k < numOfRows; ++k) {
bool hasNull = false; bool hasNull = false;
for (int32_t i = 0; i < inputNum; ++i) { for (int32_t i = 0; i < inputNum; ++i) {
if (colDataIsNull_s(pInputData[i], k) || if (colDataIsNull_s(pInputData[i], k) || IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[i]))) {
IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[i]))) {
colDataAppendNULL(pOutputData, k); colDataAppendNULL(pOutputData, k);
hasNull = true; hasNull = true;
break; break;
@ -463,7 +457,6 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
continue; continue;
} }
int16_t dataLen = 0; int16_t dataLen = 0;
for (int32_t i = 0; i < inputNum; ++i) { for (int32_t i = 0; i < inputNum; ++i) {
int32_t rowIdx = (pInput[i].numOfRows == 1) ? 0 : k; int32_t rowIdx = (pInput[i].numOfRows == 1) ? 0 : k;
@ -489,7 +482,6 @@ DONE:
return ret; return ret;
} }
int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
int32_t ret = TSDB_CODE_SUCCESS; int32_t ret = TSDB_CODE_SUCCESS;
SColumnInfoData **pInputData = taosMemoryCalloc(inputNum, sizeof(SColumnInfoData *)); SColumnInfoData **pInputData = taosMemoryCalloc(inputNum, sizeof(SColumnInfoData *));
@ -515,7 +507,8 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
int32_t numOfNulls = getNumOfNullEntries(pInputData[i], pInput[i].numOfRows); int32_t numOfNulls = getNumOfNullEntries(pInputData[i], pInput[i].numOfRows);
if (i == 0) { if (i == 0) {
// calculate required separator space // calculate required separator space
inputLen += (pInputData[0]->varmeta.length - VARSTR_HEADER_SIZE) * (numOfRows - numOfNulls) * (inputNum - 2) * factor; inputLen +=
(pInputData[0]->varmeta.length - VARSTR_HEADER_SIZE) * (numOfRows - numOfNulls) * (inputNum - 2) * factor;
} else if (pInput[i].numOfRows == 1) { } else if (pInput[i].numOfRows == 1) {
inputLen += (pInputData[i]->varmeta.length - VARSTR_HEADER_SIZE) * (numOfRows - numOfNulls) * factor; inputLen += (pInputData[i]->varmeta.length - VARSTR_HEADER_SIZE) * (numOfRows - numOfNulls) * factor;
} else { } else {
@ -528,8 +521,7 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
char *output = outputBuf; char *output = outputBuf;
for (int32_t k = 0; k < numOfRows; ++k) { for (int32_t k = 0; k < numOfRows; ++k) {
if (colDataIsNull_s(pInputData[0], k) || if (colDataIsNull_s(pInputData[0], k) || IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0]))) {
IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0]))) {
colDataAppendNULL(pOutputData, k); colDataAppendNULL(pOutputData, k);
continue; continue;
} }
@ -537,8 +529,7 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
int16_t dataLen = 0; int16_t dataLen = 0;
bool hasNull = false; bool hasNull = false;
for (int32_t i = 1; i < inputNum; ++i) { for (int32_t i = 1; i < inputNum; ++i) {
if (colDataIsNull_s(pInputData[i], k) || if (colDataIsNull_s(pInputData[i], k) || IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[i]))) {
IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[i]))) {
hasNull = true; hasNull = true;
break; break;
} }
@ -551,7 +542,6 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
goto DONE; goto DONE;
} }
if (i < inputNum - 1) { if (i < inputNum - 1) {
// insert the separator // insert the separator
char *sep = (pInput[0].numOfRows == 1) ? colDataGetData(pInputData[0], 0) : colDataGetData(pInputData[0], k); char *sep = (pInput[0].numOfRows == 1) ? colDataGetData(pInputData[0], 0) : colDataGetData(pInputData[0], k);
@ -620,7 +610,6 @@ static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScala
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _trim_fn trimFn) { static int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _trim_fn trimFn) {
int32_t type = GET_PARAM_TYPE(pInput); int32_t type = GET_PARAM_TYPE(pInput);
@ -682,7 +671,8 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
startPosBytes = (GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? subPos - 1 : (subPos - 1) * TSDB_NCHAR_SIZE; startPosBytes = (GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? subPos - 1 : (subPos - 1) * TSDB_NCHAR_SIZE;
startPosBytes = TMIN(startPosBytes, len); startPosBytes = TMIN(startPosBytes, len);
} else { } else {
startPosBytes = (GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? len + subPos : len + subPos * TSDB_NCHAR_SIZE; startPosBytes =
(GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? len + subPos : len + subPos * TSDB_NCHAR_SIZE;
startPosBytes = TMAX(startPosBytes, 0); startPosBytes = TMAX(startPosBytes, 0);
} }
@ -948,7 +938,8 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
case TSDB_DATA_TYPE_BINARY: { case TSDB_DATA_TYPE_BINARY: {
if (inputType == TSDB_DATA_TYPE_BOOL) { if (inputType == TSDB_DATA_TYPE_BOOL) {
// NOTE: sprintf will append '\0' at the end of string // NOTE: sprintf will append '\0' at the end of string
int32_t len = sprintf(varDataVal(output), "%.*s", (int32_t)(outputLen - VARSTR_HEADER_SIZE), *(int8_t *)input ? "true" : "false"); int32_t len = sprintf(varDataVal(output), "%.*s", (int32_t)(outputLen - VARSTR_HEADER_SIZE),
*(int8_t *)input ? "true" : "false");
varDataSetLen(output, len); varDataSetLen(output, len);
} else if (inputType == TSDB_DATA_TYPE_BINARY) { } else if (inputType == TSDB_DATA_TYPE_BINARY) {
int32_t len = TMIN(varDataLen(input), outputLen - VARSTR_HEADER_SIZE); int32_t len = TMIN(varDataLen(input), outputLen - VARSTR_HEADER_SIZE);
@ -987,7 +978,8 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
varDataSetLen(output, len); varDataSetLen(output, len);
} else if (inputType == TSDB_DATA_TYPE_BINARY) { } else if (inputType == TSDB_DATA_TYPE_BINARY) {
len = outputCharLen > varDataLen(input) ? varDataLen(input) : outputCharLen; len = outputCharLen > varDataLen(input) ? varDataLen(input) : outputCharLen;
bool ret = taosMbsToUcs4(input + VARSTR_HEADER_SIZE, len, (TdUcs4 *)varDataVal(output), outputLen - VARSTR_HEADER_SIZE, &len); bool ret = taosMbsToUcs4(input + VARSTR_HEADER_SIZE, len, (TdUcs4 *)varDataVal(output),
outputLen - VARSTR_HEADER_SIZE, &len);
if (!ret) { if (!ret) {
code = TSDB_CODE_FAILED; code = TSDB_CODE_FAILED;
goto _end; goto _end;
@ -1186,8 +1178,8 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
GET_TYPED_DATA(timeUnit, int64_t, GET_PARAM_TYPE(&pInput[1]), pInput[1].columnData->pData); GET_TYPED_DATA(timeUnit, int64_t, GET_PARAM_TYPE(&pInput[1]), pInput[1].columnData->pData);
GET_TYPED_DATA(timePrec, int64_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData); GET_TYPED_DATA(timePrec, int64_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData);
int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : int64_t factor =
(timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
int64_t unit = timeUnit * 1000 / factor; int64_t unit = timeUnit * 1000 / factor;
@ -1380,8 +1372,8 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
GET_TYPED_DATA(timePrec, int64_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData); GET_TYPED_DATA(timePrec, int64_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData);
} }
int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : int64_t factor =
(timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
int32_t numOfRows = 0; int32_t numOfRows = 0;
for (int32_t i = 0; i < inputNum; ++i) { for (int32_t i = 0; i < inputNum; ++i) {
@ -1441,8 +1433,7 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
continue; continue;
} }
int64_t result = (timeVal[0] >= timeVal[1]) ? (timeVal[0] - timeVal[1]) : int64_t result = (timeVal[0] >= timeVal[1]) ? (timeVal[0] - timeVal[1]) : (timeVal[1] - timeVal[0]);
(timeVal[1] - timeVal[0]);
if (timeUnit < 0) { // if no time unit given use db precision if (timeUnit < 0) { // if no time unit given use db precision
switch (timePrec) { switch (timePrec) {
@ -2292,11 +2283,10 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
matrix12 /= matrix[1][1]; matrix12 /= matrix[1][1];
char buf[64] = {0}; char buf[64] = {0};
size_t len = size_t len = snprintf(varDataVal(buf), sizeof(buf) - VARSTR_HEADER_SIZE, "{slop:%.6lf, intercept:%.6lf}", matrix02,
snprintf(varDataVal(buf), sizeof(buf) - VARSTR_HEADER_SIZE, "{slop:%.6lf, intercept:%.6lf}", matrix02, matrix12); matrix12);
varDataSetLen(buf, len); varDataSetLen(buf, len);
colDataAppend(pOutputData, 0, buf, false); colDataAppend(pOutputData, 0, buf, false);
} }
pOutput->numOfRows = 1; pOutput->numOfRows = 1;
@ -2627,7 +2617,8 @@ typedef struct SHistoFuncBin {
double percentage; double percentage;
} SHistoFuncBin; } SHistoFuncBin;
static bool getHistogramBinDesc(SHistoFuncBin** bins, int32_t* binNum, char* binDescStr, int8_t binType, bool normalized) { static bool getHistogramBinDesc(SHistoFuncBin **bins, int32_t *binNum, char *binDescStr, int8_t binType,
bool normalized) {
cJSON *binDesc = cJSON_Parse(binDescStr); cJSON *binDesc = cJSON_Parse(binDescStr);
int32_t numOfBins; int32_t numOfBins;
double *intervals; double *intervals;
@ -2804,11 +2795,11 @@ int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
int32_t len; int32_t len;
char buf[512] = {0}; char buf[512] = {0};
if (!normalized) { if (!normalized) {
len = sprintf(varDataVal(buf), "{\"lower_bin\":%g, \"upper_bin\":%g, \"count\":%" PRId64 "}", len = sprintf(varDataVal(buf), "{\"lower_bin\":%g, \"upper_bin\":%g, \"count\":%" PRId64 "}", bins[k].lower,
bins[k].lower, bins[k].upper, bins[k].count); bins[k].upper, bins[k].count);
} else { } else {
len = sprintf(varDataVal(buf), "{\"lower_bin\":%g, \"upper_bin\":%g, \"count\":%lf}", len = sprintf(varDataVal(buf), "{\"lower_bin\":%g, \"upper_bin\":%g, \"count\":%lf}", bins[k].lower,
bins[k].lower, bins[k].upper, bins[k].percentage); bins[k].upper, bins[k].percentage);
} }
varDataSetLen(buf, len); varDataSetLen(buf, len);
colDataAppend(pOutputData, k, buf, false); colDataAppend(pOutputData, k, buf, false);
@ -2835,7 +2826,6 @@ int32_t selectScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
colDataAppend(pOutputData, i, data, false); colDataAppend(pOutputData, i, data, false);
} }
pOutput->numOfRows = 1; pOutput->numOfRows = 1;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }

View File

@ -24,15 +24,16 @@
#include "tcompare.h" #include "tcompare.h"
#include "tdatablock.h" #include "tdatablock.h"
#include "tdataformat.h" #include "tdataformat.h"
#include "ttypes.h"
#include "ttime.h" #include "ttime.h"
#include "ttypes.h"
#define LEFT_COL ((pLeftCol->info.type == TSDB_DATA_TYPE_JSON ? (void *)pLeftCol : pLeftCol->pData)) #define LEFT_COL ((pLeftCol->info.type == TSDB_DATA_TYPE_JSON ? (void *)pLeftCol : pLeftCol->pData))
#define RIGHT_COL ((pRightCol->info.type == TSDB_DATA_TYPE_JSON ? (void *)pRightCol : pRightCol->pData)) #define RIGHT_COL ((pRightCol->info.type == TSDB_DATA_TYPE_JSON ? (void *)pRightCol : pRightCol->pData))
#define IS_NULL colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(pRight->columnData, i) \ #define IS_NULL \
|| IS_JSON_NULL(pLeft->columnData->info.type, colDataGetVarData(pLeft->columnData, i)) \ colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(pRight->columnData, i) || \
|| IS_JSON_NULL(pRight->columnData->info.type, colDataGetVarData(pRight->columnData, i)) IS_JSON_NULL(pLeft->columnData->info.type, colDataGetVarData(pLeft->columnData, i)) || \
IS_JSON_NULL(pRight->columnData->info.type, colDataGetVarData(pRight->columnData, i))
#define IS_HELPER_NULL(col, i) colDataIsNull_s(col, i) || IS_JSON_NULL(col->info.type, colDataGetVarData(col, i)) #define IS_HELPER_NULL(col, i) colDataIsNull_s(col, i) || IS_JSON_NULL(col->info.type, colDataGetVarData(col, i))
@ -118,39 +119,17 @@ void convertBinaryToDouble(const void *inData, void *outData){
typedef int64_t (*_getBigintValue_fn_t)(void *src, int32_t index); typedef int64_t (*_getBigintValue_fn_t)(void *src, int32_t index);
int64_t getVectorBigintValue_TINYINT(void *src, int32_t index) { int64_t getVectorBigintValue_TINYINT(void *src, int32_t index) { return (int64_t) * ((int8_t *)src + index); }
return (int64_t)*((int8_t *)src + index); int64_t getVectorBigintValue_UTINYINT(void *src, int32_t index) { return (int64_t) * ((uint8_t *)src + index); }
} int64_t getVectorBigintValue_SMALLINT(void *src, int32_t index) { return (int64_t) * ((int16_t *)src + index); }
int64_t getVectorBigintValue_UTINYINT(void *src, int32_t index) { int64_t getVectorBigintValue_USMALLINT(void *src, int32_t index) { return (int64_t) * ((uint16_t *)src + index); }
return (int64_t)*((uint8_t *)src + index); int64_t getVectorBigintValue_INT(void *src, int32_t index) { return (int64_t) * ((int32_t *)src + index); }
} int64_t getVectorBigintValue_UINT(void *src, int32_t index) { return (int64_t) * ((uint32_t *)src + index); }
int64_t getVectorBigintValue_SMALLINT(void *src, int32_t index) { int64_t getVectorBigintValue_BIGINT(void *src, int32_t index) { return (int64_t) * ((int64_t *)src + index); }
return (int64_t)*((int16_t *)src + index); int64_t getVectorBigintValue_UBIGINT(void *src, int32_t index) { return (int64_t) * ((uint64_t *)src + index); }
} int64_t getVectorBigintValue_FLOAT(void *src, int32_t index) { return (int64_t) * ((float *)src + index); }
int64_t getVectorBigintValue_USMALLINT(void *src, int32_t index) { int64_t getVectorBigintValue_DOUBLE(void *src, int32_t index) { return (int64_t) * ((double *)src + index); }
return (int64_t)*((uint16_t *)src + index); int64_t getVectorBigintValue_BOOL(void *src, int32_t index) { return (int64_t) * ((bool *)src + index); }
}
int64_t getVectorBigintValue_INT(void *src, int32_t index) {
return (int64_t)*((int32_t *)src + index);
}
int64_t getVectorBigintValue_UINT(void *src, int32_t index) {
return (int64_t)*((uint32_t *)src + index);
}
int64_t getVectorBigintValue_BIGINT(void *src, int32_t index) {
return (int64_t)*((int64_t *)src + index);
}
int64_t getVectorBigintValue_UBIGINT(void *src, int32_t index) {
return (int64_t)*((uint64_t *)src + index);
}
int64_t getVectorBigintValue_FLOAT(void *src, int32_t index) {
return (int64_t)*((float *)src + index);
}
int64_t getVectorBigintValue_DOUBLE(void *src, int32_t index) {
return (int64_t)*((double *)src + index);
}
int64_t getVectorBigintValue_BOOL(void *src, int32_t index) {
return (int64_t)*((bool *)src + index);
}
int64_t getVectorBigintValue_JSON(void *src, int32_t index) { int64_t getVectorBigintValue_JSON(void *src, int32_t index) {
ASSERT(!colDataIsNull_var(((SColumnInfoData *)src), index)); ASSERT(!colDataIsNull_var(((SColumnInfoData *)src), index));
@ -207,42 +186,18 @@ _getBigintValue_fn_t getVectorBigintValueFn(int32_t srcType) {
typedef void *(*_getValueAddr_fn_t)(void *src, int32_t index); typedef void *(*_getValueAddr_fn_t)(void *src, int32_t index);
void* getVectorValueAddr_TINYINT(void *src, int32_t index) { void *getVectorValueAddr_TINYINT(void *src, int32_t index) { return (void *)((int8_t *)src + index); }
return (void*)((int8_t *)src + index); void *getVectorValueAddr_UTINYINT(void *src, int32_t index) { return (void *)((uint8_t *)src + index); }
} void *getVectorValueAddr_SMALLINT(void *src, int32_t index) { return (void *)((int16_t *)src + index); }
void* getVectorValueAddr_UTINYINT(void *src, int32_t index) { void *getVectorValueAddr_USMALLINT(void *src, int32_t index) { return (void *)((uint16_t *)src + index); }
return (void*)((uint8_t *)src + index); void *getVectorValueAddr_INT(void *src, int32_t index) { return (void *)((int32_t *)src + index); }
} void *getVectorValueAddr_UINT(void *src, int32_t index) { return (void *)((uint32_t *)src + index); }
void* getVectorValueAddr_SMALLINT(void *src, int32_t index) { void *getVectorValueAddr_BIGINT(void *src, int32_t index) { return (void *)((int64_t *)src + index); }
return (void*)((int16_t *)src + index); void *getVectorValueAddr_UBIGINT(void *src, int32_t index) { return (void *)((uint64_t *)src + index); }
} void *getVectorValueAddr_FLOAT(void *src, int32_t index) { return (void *)((float *)src + index); }
void* getVectorValueAddr_USMALLINT(void *src, int32_t index) { void *getVectorValueAddr_DOUBLE(void *src, int32_t index) { return (void *)((double *)src + index); }
return (void*)((uint16_t *)src + index); void *getVectorValueAddr_default(void *src, int32_t index) { return src; }
} void *getVectorValueAddr_VAR(void *src, int32_t index) { return colDataGetData((SColumnInfoData *)src, index); }
void* getVectorValueAddr_INT(void *src, int32_t index) {
return (void*)((int32_t *)src + index);
}
void* getVectorValueAddr_UINT(void *src, int32_t index) {
return (void*)((uint32_t *)src + index);
}
void* getVectorValueAddr_BIGINT(void *src, int32_t index) {
return (void*)((int64_t *)src + index);
}
void* getVectorValueAddr_UBIGINT(void *src, int32_t index) {
return (void*)((uint64_t *)src + index);
}
void* getVectorValueAddr_FLOAT(void *src, int32_t index) {
return (void*)((float *)src + index);
}
void* getVectorValueAddr_DOUBLE(void *src, int32_t index) {
return (void*)((double *)src + index);
}
void* getVectorValueAddr_default(void *src, int32_t index) {
return src;
}
void* getVectorValueAddr_VAR(void *src, int32_t index) {
return colDataGetData((SColumnInfoData *)src, index);
}
_getValueAddr_fn_t getVectorValueAddrFn(int32_t srcType) { _getValueAddr_fn_t getVectorValueAddrFn(int32_t srcType) {
_getValueAddr_fn_t p = NULL; _getValueAddr_fn_t p = NULL;
@ -389,7 +344,8 @@ static FORCE_INLINE void varToNchar(char* buf, SScalarParam* pOut, int32_t rowIn
int32_t outputMaxLen = (inputLen + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE; int32_t outputMaxLen = (inputLen + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
char *t = taosMemoryCalloc(1, outputMaxLen); char *t = taosMemoryCalloc(1, outputMaxLen);
/*int32_t resLen = */taosMbsToUcs4(varDataVal(buf), inputLen, (TdUcs4*) varDataVal(t), outputMaxLen - VARSTR_HEADER_SIZE, &len); /*int32_t resLen = */ taosMbsToUcs4(varDataVal(buf), inputLen, (TdUcs4 *)varDataVal(t),
outputMaxLen - VARSTR_HEADER_SIZE, &len);
varDataSetLen(t, len); varDataSetLen(t, len);
colDataAppend(pOut->columnData, rowIndex, t, false); colDataAppend(pOut->columnData, rowIndex, t, false);
@ -411,9 +367,9 @@ static FORCE_INLINE void ncharToVar(char* buf, SScalarParam* pOut, int32_t rowIn
taosMemoryFree(t); taosMemoryFree(t);
} }
// TODO opt performance, tmp is not needed. // TODO opt performance, tmp is not needed.
int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, int32_t inType, int32_t outType, int32_t* overflow) { int32_t vectorConvertFromVarData(const SScalarParam *pIn, SScalarParam *pOut, int32_t inType, int32_t outType,
int32_t *overflow) {
bool vton = false; bool vton = false;
_bufConverteFunc func = NULL; _bufConverteFunc func = NULL;
@ -527,8 +483,9 @@ void* ncharTobinary(void *buf){ // todo need to remove , if tobinary
return t; return t;
} }
bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t typeRight, char **pLeftData, char **pRightData, bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t typeRight, char **pLeftData,
void *pLeftOut, void *pRightOut, bool *isNull, bool *freeLeft, bool *freeRight){ char **pRightData, void *pLeftOut, void *pRightOut, bool *isNull, bool *freeLeft,
bool *freeRight) {
if (optr == OP_TYPE_JSON_CONTAINS) { if (optr == OP_TYPE_JSON_CONTAINS) {
return true; return true;
} }
@ -569,7 +526,6 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t
((typeRight == TSDB_DATA_TYPE_BOOL) && (typeLeft != TSDB_DATA_TYPE_BOOL))) ((typeRight == TSDB_DATA_TYPE_BOOL) && (typeLeft != TSDB_DATA_TYPE_BOOL)))
return false; return false;
if (typeLeft == TSDB_DATA_TYPE_NULL || typeRight == TSDB_DATA_TYPE_NULL) { if (typeLeft == TSDB_DATA_TYPE_NULL || typeRight == TSDB_DATA_TYPE_NULL) {
*isNull = true; *isNull = true;
return true; return true;
@ -904,8 +860,6 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int8_t gConvertTypes[TSDB_DATA_TYPE_BLOB + 1][TSDB_DATA_TYPE_BLOB + 1] = { int8_t gConvertTypes[TSDB_DATA_TYPE_BLOB + 1][TSDB_DATA_TYPE_BLOB + 1] = {
/* NULL BOOL TINY SMAL INT BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB */ /* NULL BOOL TINY SMAL INT BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB */
/*NULL*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*NULL*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -926,8 +880,7 @@ int8_t gConvertTypes[TSDB_DATA_TYPE_BLOB+1][TSDB_DATA_TYPE_BLOB+1] = {
/*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/*VARB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*VARB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/*DECI*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*DECI*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/*BLOB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /*BLOB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
};
int32_t vectorGetConvertType(int32_t type1, int32_t type2) { int32_t vectorGetConvertType(int32_t type1, int32_t type2) {
if (type1 == type2) { if (type1 == type2) {
@ -1035,7 +988,8 @@ static int32_t doConvertHelper(SScalarParam* pDest, int32_t* convert, const SSca
} }
// TODO not correct for descending order scan // TODO not correct for descending order scan
static void vectorMathAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { static void vectorMathAddHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol,
int32_t numOfRows, int32_t step, int32_t i) {
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
@ -1049,13 +1003,13 @@ static void vectorMathAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRig
colDataAppendNULL(pOutputCol, i); colDataAppendNULL(pOutputCol, i);
continue; // TODO set null or ignore continue; // TODO set null or ignore
} }
*output = getVectorDoubleValueFnLeft(LEFT_COL, i) *output = getVectorDoubleValueFnLeft(LEFT_COL, i) + getVectorDoubleValueFnRight(RIGHT_COL, 0);
+ getVectorDoubleValueFnRight(RIGHT_COL, 0);
} }
} }
} }
static void vectorMathTsAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { static void vectorMathTsAddHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol,
int32_t numOfRows, int32_t step, int32_t i) {
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
@ -1069,7 +1023,8 @@ static void vectorMathTsAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pR
colDataAppendNULL(pOutputCol, i); colDataAppendNULL(pOutputCol, i);
continue; // TODO set null or ignore continue; // TODO set null or ignore
} }
*output = taosTimeAdd(getVectorBigintValueFnLeft(pLeftCol->pData, i), getVectorBigintValueFnRight(pRightCol->pData, 0), *output =
taosTimeAdd(getVectorBigintValueFnLeft(pLeftCol->pData, i), getVectorBigintValueFnRight(pRightCol->pData, 0),
pRightCol->info.scale, pRightCol->info.precision); pRightCol->info.scale, pRightCol->info.precision);
} }
} }
@ -1113,7 +1068,8 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
if ((GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_TIMESTAMP && IS_INTEGER_TYPE(GET_PARAM_TYPE(pRight))) || if ((GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_TIMESTAMP && IS_INTEGER_TYPE(GET_PARAM_TYPE(pRight))) ||
(GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_TIMESTAMP && IS_INTEGER_TYPE(GET_PARAM_TYPE(pLeft))) || (GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_TIMESTAMP && IS_INTEGER_TYPE(GET_PARAM_TYPE(pLeft))) ||
(GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_TIMESTAMP && GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_BOOL) || (GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_TIMESTAMP && GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_BOOL) ||
(GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_TIMESTAMP && GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_BOOL)) { //timestamp plus duration (GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_TIMESTAMP &&
GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_BOOL)) { // timestamp plus duration
int64_t *output = (int64_t *)pOutputCol->pData; int64_t *output = (int64_t *)pOutputCol->pData;
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
@ -1162,7 +1118,8 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
} }
// TODO not correct for descending order scan // TODO not correct for descending order scan
static void vectorMathSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t factor, int32_t i) { static void vectorMathSubHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol,
int32_t numOfRows, int32_t step, int32_t factor, int32_t i) {
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
@ -1176,13 +1133,13 @@ static void vectorMathSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRig
colDataAppendNULL(pOutputCol, i); colDataAppendNULL(pOutputCol, i);
continue; // TODO set null or ignore continue; // TODO set null or ignore
} }
*output = (getVectorDoubleValueFnLeft(LEFT_COL, i) *output = (getVectorDoubleValueFnLeft(LEFT_COL, i) - getVectorDoubleValueFnRight(RIGHT_COL, 0)) * factor;
- getVectorDoubleValueFnRight(RIGHT_COL, 0)) * factor;
} }
} }
} }
static void vectorMathTsSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t factor, int32_t i) { static void vectorMathTsSubHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol,
int32_t numOfRows, int32_t step, int32_t factor, int32_t i) {
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
@ -1196,9 +1153,9 @@ static void vectorMathTsSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pR
colDataAppendNULL(pOutputCol, i); colDataAppendNULL(pOutputCol, i);
continue; // TODO set null or ignore continue; // TODO set null or ignore
} }
*output = taosTimeAdd(getVectorBigintValueFnLeft(pLeftCol->pData, i), -getVectorBigintValueFnRight(pRightCol->pData, 0), *output =
taosTimeAdd(getVectorBigintValueFnLeft(pLeftCol->pData, i), -getVectorBigintValueFnRight(pRightCol->pData, 0),
pRightCol->info.scale, pRightCol->info.precision); pRightCol->info.scale, pRightCol->info.precision);
} }
} }
} }
@ -1216,7 +1173,8 @@ void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert); SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
if ((GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_TIMESTAMP && GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_BIGINT) || if ((GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_TIMESTAMP && GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_BIGINT) ||
(GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_TIMESTAMP && GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_BIGINT)) { //timestamp minus duration (GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_TIMESTAMP &&
GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_BIGINT)) { // timestamp minus duration
int64_t *output = (int64_t *)pOutputCol->pData; int64_t *output = (int64_t *)pOutputCol->pData;
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
@ -1261,7 +1219,8 @@ void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
} }
// TODO not correct for descending order scan // TODO not correct for descending order scan
static void vectorMathMultiplyHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { static void vectorMathMultiplyHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol,
int32_t numOfRows, int32_t step, int32_t i) {
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
@ -1334,8 +1293,7 @@ void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *p
colDataAppendNULL(pOutputCol, i); colDataAppendNULL(pOutputCol, i);
continue; continue;
} }
*output = getVectorDoubleValueFnLeft(LEFT_COL, i) *output = getVectorDoubleValueFnLeft(LEFT_COL, i) / getVectorDoubleValueFnRight(RIGHT_COL, i);
/ getVectorDoubleValueFnRight(RIGHT_COL, i);
} }
} else if (pLeft->numOfRows == 1) { } else if (pLeft->numOfRows == 1) {
if (IS_HELPER_NULL(pLeftCol, 0)) { // Set pLeft->numOfRows NULL value if (IS_HELPER_NULL(pLeftCol, 0)) { // Set pLeft->numOfRows NULL value
@ -1346,12 +1304,12 @@ void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *p
colDataAppendNULL(pOutputCol, i); colDataAppendNULL(pOutputCol, i);
continue; continue;
} }
*output = getVectorDoubleValueFnLeft(LEFT_COL, 0) *output = getVectorDoubleValueFnLeft(LEFT_COL, 0) / getVectorDoubleValueFnRight(RIGHT_COL, i);
/ getVectorDoubleValueFnRight(RIGHT_COL, i);
} }
} }
} else if (pRight->numOfRows == 1) { } else if (pRight->numOfRows == 1) {
if (IS_HELPER_NULL(pRightCol, 0) || (getVectorDoubleValueFnRight(RIGHT_COL, 0) == 0)) { // Set pLeft->numOfRows NULL value (divde by 0 check) if (IS_HELPER_NULL(pRightCol, 0) ||
(getVectorDoubleValueFnRight(RIGHT_COL, 0) == 0)) { // Set pLeft->numOfRows NULL value (divde by 0 check)
colDataAppendNNULL(pOutputCol, 0, pLeft->numOfRows); colDataAppendNNULL(pOutputCol, 0, pLeft->numOfRows);
} else { } else {
for (; i >= 0 && i < pLeft->numOfRows; i += step, output += 1) { for (; i >= 0 && i < pLeft->numOfRows; i += step, output += 1) {
@ -1359,8 +1317,7 @@ void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *p
colDataAppendNULL(pOutputCol, i); colDataAppendNULL(pOutputCol, i);
continue; continue;
} }
*output = getVectorDoubleValueFnLeft(LEFT_COL, i) *output = getVectorDoubleValueFnLeft(LEFT_COL, i) / getVectorDoubleValueFnRight(RIGHT_COL, 0);
/ getVectorDoubleValueFnRight(RIGHT_COL, 0);
} }
} }
} }
@ -1541,7 +1498,8 @@ void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t
#endif #endif
} }
static void vectorBitAndHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { static void vectorBitAndHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol,
int32_t numOfRows, int32_t step, int32_t i) {
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
@ -1593,7 +1551,8 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
doReleaseVec(pRightCol, rightConvert); doReleaseVec(pRightCol, rightConvert);
} }
static void vectorBitOrHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { static void vectorBitOrHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol,
int32_t numOfRows, int32_t step, int32_t i) {
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
@ -1878,7 +1837,6 @@ void vectorJsonContains(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam
} }
colDataAppend(pOutputCol, i, (const char *)(&isExist), false); colDataAppend(pOutputCol, i, (const char *)(&isExist), false);
} }
taosMemoryFree(jsonKey); taosMemoryFree(jsonKey);
} }
@ -1971,4 +1929,3 @@ _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) {
return NULL; return NULL;
} }
} }

View File

@ -32,19 +32,14 @@
#endif #endif
#include "os.h" #include "os.h"
#include "tglobal.h"
#include "taos.h"
#include "tdef.h"
#include "tvariant.h"
#include "tdatablock.h"
#include "stub.h"
#include "scalar.h"
#include "filter.h" #include "filter.h"
#include "nodes.h" #include "nodes.h"
#include "scalar.h" #include "scalar.h"
#include "stub.h" #include "stub.h"
#include "taos.h" #include "taos.h"
#include "tdatablock.h"
#include "tdef.h" #include "tdef.h"
#include "tglobal.h"
#include "tlog.h" #include "tlog.h"
#include "tvariant.h" #include "tvariant.h"
@ -66,7 +61,6 @@ void flttInitLogFile() {
} }
} }
void flttMakeValueNode(SNode **pNode, int32_t dataType, void *value) { void flttMakeValueNode(SNode **pNode, int32_t dataType, void *value) {
SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_VALUE); SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_VALUE);
SValueNode *vnode = (SValueNode *)node; SValueNode *vnode = (SValueNode *)node;
@ -84,7 +78,8 @@ void flttMakeValueNode(SNode **pNode, int32_t dataType, void *value) {
*pNode = (SNode *)vnode; *pNode = (SNode *)vnode;
} }
void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, int32_t dataBytes, int32_t rowNum, void *value) { void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, int32_t dataBytes, int32_t rowNum,
void *value) {
static uint64_t dbidx = 0; static uint64_t dbidx = 0;
SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_COLUMN); SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_COLUMN);
@ -209,7 +204,7 @@ void initScalarParam(SScalarParam* pParam) {
pParam->colAlloced = true; pParam->colAlloced = true;
} }
} } // namespace
TEST(timerangeTest, greater) { TEST(timerangeTest, greater) {
SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL; SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL;
@ -300,7 +295,6 @@ TEST(timerangeTest, greater_equal_and_lower_equal) {
nodesDestroyNode(logicNode); nodesDestroyNode(logicNode);
} }
TEST(timerangeTest, greater_and_lower_not_strict) { TEST(timerangeTest, greater_and_lower_not_strict) {
SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode1 = NULL, *logicNode2 = NULL; SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode1 = NULL, *logicNode2 = NULL;
bool eRes[5] = {false, false, true, true, true}; bool eRes[5] = {false, false, true, true, true};
@ -350,8 +344,6 @@ TEST(timerangeTest, greater_and_lower_not_strict) {
nodesDestroyNode(logicNode1); nodesDestroyNode(logicNode1);
} }
TEST(columnTest, smallint_column_greater_double_value) { TEST(columnTest, smallint_column_greater_double_value) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
int16_t leftv[5] = {1, 2, 3, 4, 5}; int16_t leftv[5] = {1, 2, 3, 4, 5};
@ -1032,7 +1024,6 @@ TEST(filterModelogicTest, diff_columns_and_or_and) {
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list);
list = nodesMakeList(); list = nodesMakeList();
flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1);
@ -1052,7 +1043,6 @@ TEST(filterModelogicTest, diff_columns_and_or_and) {
nodesListAppend(list, logicNode2); nodesListAppend(list, logicNode2);
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
int32_t code = filterInitFromNode(logicNode1, &filter, 0); int32_t code = filterInitFromNode(logicNode1, &filter, 0);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
@ -1101,7 +1091,6 @@ TEST(filterModelogicTest, same_column_and_or_and) {
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list);
list = nodesMakeList(); list = nodesMakeList();
flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1);
@ -1121,7 +1110,6 @@ TEST(filterModelogicTest, same_column_and_or_and) {
nodesListAppend(list, logicNode2); nodesListAppend(list, logicNode2);
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
int32_t code = filterInitFromNode(logicNode1, &filter, 0); int32_t code = filterInitFromNode(logicNode1, &filter, 0);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
@ -1170,7 +1158,6 @@ TEST(filterModelogicTest, diff_columns_or_and_or) {
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list);
list = nodesMakeList(); list = nodesMakeList();
flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1);
@ -1190,7 +1177,6 @@ TEST(filterModelogicTest, diff_columns_or_and_or) {
nodesListAppend(list, logicNode2); nodesListAppend(list, logicNode2);
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
int32_t code = filterInitFromNode(logicNode1, &filter, 0); int32_t code = filterInitFromNode(logicNode1, &filter, 0);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
@ -1239,7 +1225,6 @@ TEST(filterModelogicTest, same_column_or_and_or) {
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list);
list = nodesMakeList(); list = nodesMakeList();
flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1);
@ -1259,7 +1244,6 @@ TEST(filterModelogicTest, same_column_or_and_or) {
nodesListAppend(list, logicNode2); nodesListAppend(list, logicNode2);
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
int32_t code = filterInitFromNode(logicNode1, &filter, 0); int32_t code = filterInitFromNode(logicNode1, &filter, 0);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
@ -1310,7 +1294,6 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) {
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list);
list = nodesMakeList(); list = nodesMakeList();
flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1);
@ -1330,7 +1313,6 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) {
nodesListAppend(list, logicNode2); nodesListAppend(list, logicNode2);
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
int32_t code = filterInitFromNode(logicNode1, &filter, 0); int32_t code = filterInitFromNode(logicNode1, &filter, 0);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);

View File

@ -32,17 +32,17 @@
#endif #endif
#include "os.h" #include "os.h"
#include "tglobal.h"
#include "taos.h"
#include "tdef.h"
#include "tvariant.h"
#include "tdatablock.h"
#include "stub.h"
#include "scalar.h"
#include "nodes.h"
#include "tlog.h"
#include "parUtil.h"
#include "filterInt.h" #include "filterInt.h"
#include "nodes.h"
#include "parUtil.h"
#include "scalar.h"
#include "stub.h"
#include "taos.h"
#include "tdatablock.h"
#include "tdef.h"
#include "tglobal.h"
#include "tlog.h"
#include "tvariant.h"
#define _DEBUG_PRINT_ 0 #define _DEBUG_PRINT_ 0
@ -65,9 +65,7 @@ SColumnInfo createColumnInfo(int32_t colId, int32_t type, int32_t bytes) {
int64_t scltLeftV = 21, scltRightV = 10; int64_t scltLeftV = 21, scltRightV = 10;
double scltLeftVd = 21.0, scltRightVd = 10.0; double scltLeftVd = 21.0, scltRightVd = 10.0;
void scltFreeDataBlock(void *block) { void scltFreeDataBlock(void *block) { blockDataDestroy(*(SSDataBlock **)block); }
blockDataDestroy(*(SSDataBlock **)block);
}
void scltInitLogFile() { void scltInitLogFile() {
const char *defaultLogFileNamePrefix = "taoslog"; const char *defaultLogFileNamePrefix = "taoslog";
@ -82,7 +80,8 @@ void scltInitLogFile() {
} }
} }
void scltAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *slotId, bool newBlock, int32_t rows, SColumnInfo *colInfo) { void scltAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *slotId, bool newBlock, int32_t rows,
SColumnInfo *colInfo) {
if (newBlock) { if (newBlock) {
SSDataBlock *res = createDataBlock(); SSDataBlock *res = createDataBlock();
@ -130,7 +129,8 @@ void scltMakeValueNode(SNode **pNode, int32_t dataType, void *value) {
*pNode = (SNode *)vnode; *pNode = (SNode *)vnode;
} }
void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, int32_t dataBytes, int32_t rowNum, void *value) { void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, int32_t dataBytes, int32_t rowNum,
void *value) {
SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_COLUMN); SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_COLUMN);
SColumnNode *rnode = (SColumnNode *)node; SColumnNode *rnode = (SColumnNode *)node;
rnode->node.resType.type = dataType; rnode->node.resType.type = dataType;
@ -198,7 +198,8 @@ void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in
*pNode = (SNode *)rnode; *pNode = (SNode *)rnode;
} }
void scltMakeOpNode2(SNode **pNode, EOperatorType opType, int32_t resType, SNode *pLeft, SNode *pRight, bool isReverse) { void scltMakeOpNode2(SNode **pNode, EOperatorType opType, int32_t resType, SNode *pLeft, SNode *pRight,
bool isReverse) {
SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_OPERATOR); SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_OPERATOR);
SOperatorNode *onode = (SOperatorNode *)node; SOperatorNode *onode = (SOperatorNode *)node;
onode->node.resType.type = resType; onode->node.resType.type = resType;
@ -229,7 +230,6 @@ void scltMakeOpNode(SNode **pNode, EOperatorType opType, int32_t resType, SNode
*pNode = (SNode *)onode; *pNode = (SNode *)onode;
} }
void scltMakeListNode(SNode **pNode, SNodeList *list, int32_t resType) { void scltMakeListNode(SNode **pNode, SNodeList *list, int32_t resType) {
SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_NODE_LIST); SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_NODE_LIST);
SNodeListNode *lnode = (SNodeListNode *)node; SNodeListNode *lnode = (SNodeListNode *)node;
@ -239,7 +239,6 @@ void scltMakeListNode(SNode **pNode, SNodeList *list, int32_t resType) {
*pNode = (SNode *)lnode; *pNode = (SNode *)lnode;
} }
void scltMakeLogicNode(SNode **pNode, ELogicConditionType opType, SNode **nodeList, int32_t nodeNum) { void scltMakeLogicNode(SNode **pNode, ELogicConditionType opType, SNode **nodeList, int32_t nodeNum) {
SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION); SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION);
SLogicConditionNode *onode = (SLogicConditionNode *)node; SLogicConditionNode *onode = (SLogicConditionNode *)node;
@ -264,7 +263,7 @@ void scltMakeTargetNode(SNode **pNode, int16_t dataBlockId, int16_t slotId, SNod
*pNode = (SNode *)onode; *pNode = (SNode *)onode;
} }
} } // namespace
TEST(constantTest, bigint_add_bigint) { TEST(constantTest, bigint_add_bigint) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
@ -1028,7 +1027,6 @@ TEST(constantTest, column_and_value4) {
nodesDestroyNode(res); nodesDestroyNode(res);
} }
void makeJsonArrow(SSDataBlock **src, SNode **opNode, void *json, char *key) { void makeJsonArrow(SSDataBlock **src, SNode **opNode, void *json, char *key) {
char keyVar[32] = {0}; char keyVar[32] = {0};
memcpy(varDataVal(keyVar), key, strlen(key)); memcpy(varDataVal(keyVar), key, strlen(key));
@ -1040,16 +1038,16 @@ void makeJsonArrow(SSDataBlock **src, SNode **opNode, void *json, char *key){
scltMakeOpNode(opNode, OP_TYPE_JSON_GET_VALUE, TSDB_DATA_TYPE_JSON, pLeft, pRight); scltMakeOpNode(opNode, OP_TYPE_JSON_GET_VALUE, TSDB_DATA_TYPE_JSON, pLeft, pRight);
} }
void makeOperator(SNode **opNode, SArray *blockList, EOperatorType opType, int32_t rightType, void *rightData, bool isReverse){ void makeOperator(SNode **opNode, SArray *blockList, EOperatorType opType, int32_t rightType, void *rightData,
bool isReverse) {
int32_t resType = TSDB_DATA_TYPE_NULL; int32_t resType = TSDB_DATA_TYPE_NULL;
if(opType == OP_TYPE_ADD || opType == OP_TYPE_SUB || opType == OP_TYPE_MULTI || if (opType == OP_TYPE_ADD || opType == OP_TYPE_SUB || opType == OP_TYPE_MULTI || opType == OP_TYPE_DIV ||
opType == OP_TYPE_DIV || opType == OP_TYPE_REM || opType == OP_TYPE_MINUS){ opType == OP_TYPE_REM || opType == OP_TYPE_MINUS) {
resType = TSDB_DATA_TYPE_DOUBLE; resType = TSDB_DATA_TYPE_DOUBLE;
} else if (opType == OP_TYPE_BIT_AND || opType == OP_TYPE_BIT_OR) { } else if (opType == OP_TYPE_BIT_AND || opType == OP_TYPE_BIT_OR) {
resType = TSDB_DATA_TYPE_BIGINT; resType = TSDB_DATA_TYPE_BIGINT;
}else if(opType == OP_TYPE_GREATER_THAN || opType == OP_TYPE_GREATER_EQUAL || } else if (opType == OP_TYPE_GREATER_THAN || opType == OP_TYPE_GREATER_EQUAL || opType == OP_TYPE_LOWER_THAN ||
opType == OP_TYPE_LOWER_THAN || opType == OP_TYPE_LOWER_EQUAL || opType == OP_TYPE_LOWER_EQUAL || opType == OP_TYPE_EQUAL || opType == OP_TYPE_NOT_EQUAL ||
opType == OP_TYPE_EQUAL || opType == OP_TYPE_NOT_EQUAL ||
opType == OP_TYPE_IS_NULL || opType == OP_TYPE_IS_NOT_NULL || opType == OP_TYPE_IS_TRUE || opType == OP_TYPE_IS_NULL || opType == OP_TYPE_IS_NOT_NULL || opType == OP_TYPE_IS_TRUE ||
opType == OP_TYPE_LIKE || opType == OP_TYPE_NOT_LIKE || opType == OP_TYPE_MATCH || opType == OP_TYPE_LIKE || opType == OP_TYPE_NOT_LIKE || opType == OP_TYPE_MATCH ||
opType == OP_TYPE_NMATCH) { opType == OP_TYPE_NMATCH) {
@ -1066,7 +1064,8 @@ void makeOperator(SNode **opNode, SArray *blockList, EOperatorType opType, int32
scltMakeTargetNode(opNode, dataBlockId, slotId, *opNode); scltMakeTargetNode(opNode, dataBlockId, slotId, *opNode);
} }
void makeCalculate(void *json, void *key, int32_t rightType, void *rightData, double exceptValue, EOperatorType opType, bool isReverse){ void makeCalculate(void *json, void *key, int32_t rightType, void *rightData, double exceptValue, EOperatorType opType,
bool isReverse) {
SArray *blockList = taosArrayInit(2, POINTER_BYTES); SArray *blockList = taosArrayInit(2, POINTER_BYTES);
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SNode *opNode = NULL; SNode *opNode = NULL;
@ -1089,15 +1088,18 @@ void makeCalculate(void *json, void *key, int32_t rightType, void *rightData, do
} else if (opType == OP_TYPE_ADD || opType == OP_TYPE_SUB || opType == OP_TYPE_MULTI || opType == OP_TYPE_DIV || } else if (opType == OP_TYPE_ADD || opType == OP_TYPE_SUB || opType == OP_TYPE_MULTI || opType == OP_TYPE_DIV ||
opType == OP_TYPE_REM || opType == OP_TYPE_MINUS) { opType == OP_TYPE_REM || opType == OP_TYPE_MINUS) {
printf("op:%s,1result:%f,except:%f\n", operatorTypeStr(opType), *((double *)colDataGetData(column, 0)), exceptValue); printf("op:%s,1result:%f,except:%f\n", operatorTypeStr(opType), *((double *)colDataGetData(column, 0)),
exceptValue);
ASSERT_TRUE(fabs(*((double *)colDataGetData(column, 0)) - exceptValue) < 0.0001); ASSERT_TRUE(fabs(*((double *)colDataGetData(column, 0)) - exceptValue) < 0.0001);
} else if (opType == OP_TYPE_BIT_AND || opType == OP_TYPE_BIT_OR) { } else if (opType == OP_TYPE_BIT_AND || opType == OP_TYPE_BIT_OR) {
printf("op:%s,2result:%" PRId64 ",except:%f\n", operatorTypeStr(opType), *((int64_t *)colDataGetData(column, 0)), exceptValue); printf("op:%s,2result:%" PRId64 ",except:%f\n", operatorTypeStr(opType), *((int64_t *)colDataGetData(column, 0)),
exceptValue);
ASSERT_EQ(*((int64_t *)colDataGetData(column, 0)), exceptValue); ASSERT_EQ(*((int64_t *)colDataGetData(column, 0)), exceptValue);
} else if (opType == OP_TYPE_GREATER_THAN || opType == OP_TYPE_GREATER_EQUAL || opType == OP_TYPE_LOWER_THAN || } else if (opType == OP_TYPE_GREATER_THAN || opType == OP_TYPE_GREATER_EQUAL || opType == OP_TYPE_LOWER_THAN ||
opType == OP_TYPE_LOWER_EQUAL || opType == OP_TYPE_EQUAL || opType == OP_TYPE_NOT_EQUAL || opType == OP_TYPE_LOWER_EQUAL || opType == OP_TYPE_EQUAL || opType == OP_TYPE_NOT_EQUAL ||
opType == OP_TYPE_IS_NULL || opType == OP_TYPE_IS_NOT_NULL || opType == OP_TYPE_IS_TRUE || opType == OP_TYPE_IS_NULL || opType == OP_TYPE_IS_NOT_NULL || opType == OP_TYPE_IS_TRUE ||
opType == OP_TYPE_LIKE || opType == OP_TYPE_NOT_LIKE || opType == OP_TYPE_MATCH || opType == OP_TYPE_NMATCH){ opType == OP_TYPE_LIKE || opType == OP_TYPE_NOT_LIKE || opType == OP_TYPE_MATCH ||
opType == OP_TYPE_NMATCH) {
printf("op:%s,3result:%d,except:%f\n", operatorTypeStr(opType), *((bool *)colDataGetData(column, 0)), exceptValue); printf("op:%s,3result:%d,except:%f\n", operatorTypeStr(opType), *((bool *)colDataGetData(column, 0)), exceptValue);
ASSERT_EQ(*((bool *)colDataGetData(column, 0)), exceptValue); ASSERT_EQ(*((bool *)colDataGetData(column, 0)), exceptValue);
} }
@ -1108,7 +1110,9 @@ void makeCalculate(void *json, void *key, int32_t rightType, void *rightData, do
TEST(columnTest, json_column_arith_op) { TEST(columnTest, json_column_arith_op) {
scltInitLogFile(); scltInitLogFile();
char *rightvTmp= "{\"k1\":4,\"k2\":\"hello\",\"k3\":null,\"k4\":true,\"k5\":5.44,\"k6\":-10,\"k7\":-9.8,\"k8\":false,\"k9\":\"8hel\"}"; char *rightvTmp =
"{\"k1\":4,\"k2\":\"hello\",\"k3\":null,\"k4\":true,\"k5\":5.44,\"k6\":-10,\"k7\":-9.8,\"k8\":false,\"k9\":"
"\"8hel\"}";
char rightv[256] = {0}; char rightv[256] = {0};
memcpy(rightv, rightvTmp, strlen(rightvTmp)); memcpy(rightv, rightvTmp, strlen(rightvTmp));
@ -1256,7 +1260,9 @@ void *prepareNchar(char* rightData){
TEST(columnTest, json_column_logic_op) { TEST(columnTest, json_column_logic_op) {
scltInitLogFile(); scltInitLogFile();
char *rightvTmp= "{\"k1\":4,\"k2\":\"hello\",\"k3\":null,\"k4\":true,\"k5\":5.44,\"k6\":-10,\"k7\":-9.8,\"k8\":false,\"k9\":\"6.6hello\"}"; char *rightvTmp =
"{\"k1\":4,\"k2\":\"hello\",\"k3\":null,\"k4\":true,\"k5\":5.44,\"k6\":-10,\"k7\":-9.8,\"k8\":false,\"k9\":\"6."
"6hello\"}";
char rightv[256] = {0}; char rightv[256] = {0};
memcpy(rightv, rightvTmp, strlen(rightvTmp)); memcpy(rightv, rightvTmp, strlen(rightvTmp));
@ -1267,8 +1273,10 @@ TEST(columnTest, json_column_logic_op) {
const int32_t len0 = 6; const int32_t len0 = 6;
const int32_t len = 9; const int32_t len = 9;
const int32_t len1 = 4; const int32_t len1 = 4;
EOperatorType op[len+len1] = {OP_TYPE_GREATER_THAN, OP_TYPE_GREATER_EQUAL, OP_TYPE_LOWER_THAN, OP_TYPE_LOWER_EQUAL, OP_TYPE_EQUAL, OP_TYPE_NOT_EQUAL, EOperatorType op[len + len1] = {OP_TYPE_GREATER_THAN, OP_TYPE_GREATER_EQUAL, OP_TYPE_LOWER_THAN, OP_TYPE_LOWER_EQUAL,
OP_TYPE_IS_NULL, OP_TYPE_IS_NOT_NULL, OP_TYPE_IS_TRUE, OP_TYPE_LIKE, OP_TYPE_NOT_LIKE, OP_TYPE_MATCH, OP_TYPE_NMATCH}; OP_TYPE_EQUAL, OP_TYPE_NOT_EQUAL, OP_TYPE_IS_NULL, OP_TYPE_IS_NOT_NULL,
OP_TYPE_IS_TRUE, OP_TYPE_LIKE, OP_TYPE_NOT_LIKE, OP_TYPE_MATCH,
OP_TYPE_NMATCH};
int32_t input[len] = {1, 8, 2, 2, 3, 0, 0, 0, 0}; int32_t input[len] = {1, 8, 2, 2, 3, 0, 0, 0, 0};
char *inputNchar[len1] = {"hell_", "hel%", "hell", "llll"}; char *inputNchar[len1] = {"hell_", "hel%", "hell", "llll"};
@ -1397,7 +1405,6 @@ TEST(columnTest, json_column_logic_op) {
taosMemoryFree(rightData); taosMemoryFree(rightData);
} }
printf("--------------------json bool-- 0 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); printf("--------------------json bool-- 0 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
key = "k8"; key = "k8";
@ -1416,7 +1423,6 @@ TEST(columnTest, json_column_logic_op) {
taosMemoryFree(rightData); taosMemoryFree(rightData);
} }
printf("--------------------json string-- 6.6hello {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); printf("--------------------json string-- 6.6hello {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
key = "k9"; key = "k9";
@ -2200,7 +2206,6 @@ TEST(ScalarFunctionTest, absFunction_constant) {
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
} }
TEST(ScalarFunctionTest, absFunction_column) { TEST(ScalarFunctionTest, absFunction_column) {
@ -2296,7 +2301,6 @@ TEST(ScalarFunctionTest, absFunction_column) {
PRINTF("int before ABS:%d\n", v); PRINTF("int before ABS:%d\n", v);
} }
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
@ -2442,7 +2446,6 @@ TEST(ScalarFunctionTest, sinFunction_constant) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
} }
TEST(ScalarFunctionTest, sinFunction_column) { TEST(ScalarFunctionTest, sinFunction_column) {
@ -2453,7 +2456,6 @@ TEST(ScalarFunctionTest, sinFunction_column) {
int32_t otype = TSDB_DATA_TYPE_DOUBLE; int32_t otype = TSDB_DATA_TYPE_DOUBLE;
double result[] = {0.42016703682664092, 0.99060735569487035, 0.65028784015711683}; double result[] = {0.42016703682664092, 0.99060735569487035, 0.65028784015711683};
// TINYINT // TINYINT
int8_t val_tinyint[] = {13, 14, 15}; int8_t val_tinyint[] = {13, 14, 15};
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
@ -2724,7 +2726,6 @@ TEST(ScalarFunctionTest, asinFunction_column) {
int32_t otype = TSDB_DATA_TYPE_DOUBLE; int32_t otype = TSDB_DATA_TYPE_DOUBLE;
double result[] = {-1.57079632679489656, 0.0, 1.57079632679489656}; double result[] = {-1.57079632679489656, 0.0, 1.57079632679489656};
// TINYINT // TINYINT
int8_t val_tinyint[] = {-1, 0, 1}; int8_t val_tinyint[] = {-1, 0, 1};
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
@ -3317,8 +3318,7 @@ TEST(ScalarFunctionTest, logFunction_constant) {
pInput[i] = *input[i]; pInput[i] = *input[i];
} }
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
PRINTF("tiny_int before LOG: %d,%d\n", *((int8_t *)pInput[0].data), PRINTF("tiny_int before LOG: %d,%d\n", *((int8_t *)pInput[0].data), *((int8_t *)pInput[1].data));
*((int8_t *)pInput[1].data));
code = logFunction(pInput, 2, pOutput); code = logFunction(pInput, 2, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
@ -3338,8 +3338,7 @@ TEST(ScalarFunctionTest, logFunction_constant) {
pInput[i] = *input[i]; pInput[i] = *input[i];
} }
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
PRINTF("float before LOG: %f,%f\n", *((float *)pInput[0].data), PRINTF("float before LOG: %f,%f\n", *((float *)pInput[0].data), *((float *)pInput[1].data));
*((float *)pInput[1].data));
code = logFunction(pInput, 2, pOutput); code = logFunction(pInput, 2, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
@ -3393,10 +3392,8 @@ TEST(ScalarFunctionTest, logFunction_column) {
pInput[i] = *input[i]; pInput[i] = *input[i];
for (int32_t j = 0; j < rowNum; ++j) { for (int32_t j = 0; j < rowNum; ++j) {
colDataAppend(pInput[i].columnData, j, (const char *)&val_tinyint[i][j], false); colDataAppend(pInput[i].columnData, j, (const char *)&val_tinyint[i][j], false);
} }
PRINTF("tiny_int before LOG:%d,%d,%d\n", *((int8_t *)pInput[i].data + 0), PRINTF("tiny_int before LOG:%d,%d,%d\n", *((int8_t *)pInput[i].data + 0), *((int8_t *)pInput[i].data + 1),
*((int8_t *)pInput[i].data + 1),
*((int8_t *)pInput[i].data + 2)); *((int8_t *)pInput[i].data + 2));
} }
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
@ -3421,8 +3418,7 @@ TEST(ScalarFunctionTest, logFunction_column) {
colDataAppend(pInput[i].columnData, j, (const char *)&val_float[i][j], false); colDataAppend(pInput[i].columnData, j, (const char *)&val_float[i][j], false);
} }
PRINTF("float before LOG:%f,%f,%f\n", *((float *)colDataGetData(pInput[i], 0)), PRINTF("float before LOG:%f,%f,%f\n", *((float *)colDataGetData(pInput[i], 0)),
*((float *)colDataGetData(pInput[i], 1)), *((float *)colDataGetData(pInput[i], 1)), *((float *)colDataGetData(pInput[i], 2)));
*((float *)colDataGetData(pInput[i], 2)));
} }
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
@ -3443,16 +3439,14 @@ TEST(ScalarFunctionTest, logFunction_column) {
pInput[0] = *input[0]; pInput[0] = *input[0];
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
colDataAppend(pInput[0].columnData, i, (const char *)&param0[i], false); colDataAppend(pInput[0].columnData, i, (const char *)&param0[i], false);
} }
scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, 0, rowNum, false); scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, 0, rowNum, false);
pInput[1] = *input[1]; pInput[1] = *input[1];
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
colDataAppend(pInput[1].columnData, i, (const char *)&param1[i], false); colDataAppend(pInput[1].columnData, i, (const char *)&param1[i], false);
} }
PRINTF("tiny_int, float before LOG:{%d,%f}, {%d,%f}, {%d,%f}\n", *((int8_t *)pInput[0].data + 0), *((float *)pInput[1].data + 0), PRINTF("tiny_int, float before LOG:{%d,%f}, {%d,%f}, {%d,%f}\n", *((int8_t *)pInput[0].data + 0),
*((int8_t *)pInput[0].data + 1), *((float *)pInput[1].data + 1), *((float *)pInput[1].data + 0), *((int8_t *)pInput[0].data + 1), *((float *)pInput[1].data + 1),
*((int8_t *)pInput[0].data + 2), *((float *)pInput[1].data + 2)); *((int8_t *)pInput[0].data + 2), *((float *)pInput[1].data + 2));
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
@ -3487,8 +3481,7 @@ TEST(ScalarFunctionTest, powFunction_constant) {
pInput[i] = *input[i]; pInput[i] = *input[i];
} }
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
PRINTF("tiny_int before POW: %d,%d\n", *((int8_t *)pInput[0].data), PRINTF("tiny_int before POW: %d,%d\n", *((int8_t *)pInput[0].data), *((int8_t *)pInput[1].data));
*((int8_t *)pInput[1].data));
code = powFunction(pInput, 2, pOutput); code = powFunction(pInput, 2, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
@ -3508,8 +3501,7 @@ TEST(ScalarFunctionTest, powFunction_constant) {
pInput[i] = *input[i]; pInput[i] = *input[i];
} }
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
PRINTF("float before POW: %f,%f\n", *((float *)pInput[0].data), PRINTF("float before POW: %f,%f\n", *((float *)pInput[0].data), *((float *)pInput[1].data));
*((float *)pInput[1].data));
code = powFunction(pInput, 2, pOutput); code = powFunction(pInput, 2, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
@ -3563,10 +3555,8 @@ TEST(ScalarFunctionTest, powFunction_column) {
pInput[i] = *input[i]; pInput[i] = *input[i];
for (int32_t j = 0; j < rowNum; ++j) { for (int32_t j = 0; j < rowNum; ++j) {
colDataAppend(pInput[i].columnData, j, (const char *)&val_tinyint[i][j], false); colDataAppend(pInput[i].columnData, j, (const char *)&val_tinyint[i][j], false);
} }
PRINTF("tiny_int before POW:%d,%d,%d\n", *((int8_t *)pInput[i].data + 0), PRINTF("tiny_int before POW:%d,%d,%d\n", *((int8_t *)pInput[i].data + 0), *((int8_t *)pInput[i].data + 1),
*((int8_t *)pInput[i].data + 1),
*((int8_t *)pInput[i].data + 2)); *((int8_t *)pInput[i].data + 2));
} }
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
@ -3591,8 +3581,7 @@ TEST(ScalarFunctionTest, powFunction_column) {
for (int32_t j = 0; j < rowNum; ++j) { for (int32_t j = 0; j < rowNum; ++j) {
colDataAppend(pInput[i].columnData, j, (const char *)&val_float[i][j], false); colDataAppend(pInput[i].columnData, j, (const char *)&val_float[i][j], false);
} }
PRINTF("float before POW:%f,%f,%f\n", *((float *)pInput[i].data + 0), PRINTF("float before POW:%f,%f,%f\n", *((float *)pInput[i].data + 0), *((float *)pInput[i].data + 1),
*((float *)pInput[i].data + 1),
*((float *)pInput[i].data + 2)); *((float *)pInput[i].data + 2));
} }
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
@ -3614,15 +3603,14 @@ TEST(ScalarFunctionTest, powFunction_column) {
pInput[0] = *input[0]; pInput[0] = *input[0];
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
colDataAppend(pInput[0].columnData, i, (const char *)&param0[i], false); colDataAppend(pInput[0].columnData, i, (const char *)&param0[i], false);
} }
scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, 0, rowNum, false); scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, 0, rowNum, false);
pInput[1] = *input[1]; pInput[1] = *input[1];
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
colDataAppend(pInput[1].columnData, i, (const char *)&param1[i], false); colDataAppend(pInput[1].columnData, i, (const char *)&param1[i], false);
} }
PRINTF("tiny_int, float before POW:{%d,%f}, {%d,%f}, {%d,%f}\n", *((int8_t *)pInput[0].data + 0), *((float *)pInput[1].data + 0), PRINTF("tiny_int, float before POW:{%d,%f}, {%d,%f}, {%d,%f}\n", *((int8_t *)pInput[0].data + 0),
*((int8_t *)pInput[0].data + 1), *((float *)pInput[1].data + 1), *((float *)pInput[1].data + 0), *((int8_t *)pInput[0].data + 1), *((float *)pInput[1].data + 1),
*((int8_t *)pInput[0].data + 2), *((float *)pInput[1].data + 2)); *((int8_t *)pInput[0].data + 2), *((float *)pInput[1].data + 2));
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
@ -3646,4 +3634,3 @@ int main(int argc, char** argv) {
} }
#pragma GCC diagnostic pop #pragma GCC diagnostic pop

View File

@ -24,7 +24,7 @@ FORMAT_DIR_LIST=(
"${PRJ_ROOT_DIR}/source/libs/planner" "${PRJ_ROOT_DIR}/source/libs/planner"
# "${PRJ_ROOT_DIR}/source/libs/qcom" # "${PRJ_ROOT_DIR}/source/libs/qcom"
# "${PRJ_ROOT_DIR}/source/libs/qworker" # "${PRJ_ROOT_DIR}/source/libs/qworker"
# "${PRJ_ROOT_DIR}/source/libs/scalar" "${PRJ_ROOT_DIR}/source/libs/scalar"
"${PRJ_ROOT_DIR}/source/libs/stream" "${PRJ_ROOT_DIR}/source/libs/stream"
# "${PRJ_ROOT_DIR}/source/libs/sync" # "${PRJ_ROOT_DIR}/source/libs/sync"
"${PRJ_ROOT_DIR}/source/libs/tdb" "${PRJ_ROOT_DIR}/source/libs/tdb"