提交 d8e32fb4 编写于 作者: H Hongze Cheng

more code format

上级 63d9b856
...@@ -59,7 +59,6 @@ enum { ...@@ -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,
...@@ -97,10 +96,10 @@ typedef struct SFilterRange { ...@@ -97,10 +96,10 @@ typedef struct SFilterRange {
char eflag; char eflag;
} SFilterRange; } SFilterRange;
typedef bool (*rangeCompFunc) (const void *, const void *, const void *, const void *, __compar_fn_t); typedef bool (*rangeCompFunc)(const void *, const void *, const void *, const void *, __compar_fn_t);
typedef int32_t(*filter_desc_compare_func)(const void *, const void *); typedef int32_t (*filter_desc_compare_func)(const void *, const void *);
typedef bool(*filter_exec_func)(void*, int32_t, SColumnInfoData*, SColumnDataAgg*, int16_t, int32_t*); typedef bool (*filter_exec_func)(void *, int32_t, SColumnInfoData *, SColumnDataAgg *, int16_t, int32_t *);
typedef int32_t (*filer_get_col_from_name)(void *, int32_t, char*, void **); typedef int32_t (*filer_get_col_from_name)(void *, int32_t, char *, void **);
typedef struct SFilterRangeCompare { typedef struct SFilterRangeCompare {
int64_t s; int64_t s;
...@@ -109,8 +108,8 @@ typedef struct SFilterRangeCompare { ...@@ -109,8 +108,8 @@ typedef struct SFilterRangeCompare {
} SFilterRangeCompare; } SFilterRangeCompare;
typedef struct SFilterRangeNode { typedef struct SFilterRangeNode {
struct SFilterRangeNode* prev; struct SFilterRangeNode *prev;
struct SFilterRangeNode* next; struct SFilterRangeNode *next;
union { union {
SFilterRange ra; SFilterRange ra;
SFilterRangeCompare rc; SFilterRangeCompare rc;
...@@ -126,9 +125,9 @@ typedef struct SFilterRangeCtx { ...@@ -126,9 +125,9 @@ typedef struct SFilterRangeCtx {
bool isrange; bool isrange;
int16_t colId; int16_t colId;
__compar_fn_t pCompareFunc; __compar_fn_t pCompareFunc;
SFilterRangeNode *rf; //freed SFilterRangeNode *rf; // freed
SFilterRangeNode *rs; SFilterRangeNode *rs;
} SFilterRangeCtx ; } SFilterRangeCtx;
typedef struct SFilterVarCtx { typedef struct SFilterVarCtx {
int32_t type; int32_t type;
...@@ -143,8 +142,8 @@ typedef struct SFilterVarCtx { ...@@ -143,8 +142,8 @@ typedef struct SFilterVarCtx {
typedef struct SFilterField { typedef struct SFilterField {
uint16_t flag; uint16_t flag;
void* desc; void *desc;
void* data; void *data;
} SFilterField; } SFilterField;
typedef struct SFilterFields { typedef struct SFilterFields {
...@@ -181,7 +180,7 @@ typedef struct SFilterGroupCtx { ...@@ -181,7 +180,7 @@ typedef struct SFilterGroupCtx {
typedef struct SFilterColCtx { typedef struct SFilterColCtx {
uint32_t colIdx; uint32_t colIdx;
void* ctx; void *ctx;
} SFilterColCtx; } SFilterColCtx;
typedef struct SFilterCompare { typedef struct SFilterCompare {
...@@ -219,8 +218,8 @@ typedef struct SFltTreeStat { ...@@ -219,8 +218,8 @@ typedef struct SFltTreeStat {
int32_t code; int32_t code;
int8_t precision; int8_t precision;
bool scalarMode; bool scalarMode;
SArray* nodeList; SArray *nodeList;
SFilterInfo* info; SFilterInfo *info;
} SFltTreeStat; } SFltTreeStat;
typedef struct SFltScalarCtx { typedef struct SFltScalarCtx {
...@@ -260,31 +259,117 @@ struct SFilterInfo { ...@@ -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); \
#define RESET_RANGE(ctx, r) do { (r)->next = (ctx)->rf; (ctx)->rf = r; } while (0) _t[1] = (op2); \
#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) *(uint32_t *)(_t + 2) = (lidx); \
#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) *(uint32_t *)(_t + 2 + sizeof(uint32_t)) = (ridx); \
#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) } 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 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 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 { ...@@ -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]))
...@@ -313,7 +422,7 @@ struct SFilterInfo { ...@@ -313,7 +422,7 @@ struct SFilterInfo {
#define FILTER_GET_COL_FIELD_DATA(fi, ri) (colDataGetData(((SColumnInfoData *)(fi)->data), (ri))) #define FILTER_GET_COL_FIELD_DATA(fi, ri) (colDataGetData(((SColumnInfoData *)(fi)->data), (ri)))
#define FILTER_GET_VAL_FIELD_TYPE(fi) (((SValueNode *)((fi)->desc))->node.resType.type) #define FILTER_GET_VAL_FIELD_TYPE(fi) (((SValueNode *)((fi)->desc))->node.resType.type)
#define FILTER_GET_VAL_FIELD_DATA(fi) ((char *)(fi)->data) #define FILTER_GET_VAL_FIELD_DATA(fi) ((char *)(fi)->data)
#define FILTER_GET_TYPE(fl) ((fl) & FLD_TYPE_MAX) #define FILTER_GET_TYPE(fl) ((fl)&FLD_TYPE_MAX)
#define FILTER_GROUP_UNIT(i, g, uid) ((i)->units + (g)->unitIdxs[uid]) #define FILTER_GROUP_UNIT(i, g, uid) ((i)->units + (g)->unitIdxs[uid])
#define FILTER_UNIT_LEFT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->left) #define FILTER_UNIT_LEFT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->left)
...@@ -336,14 +445,37 @@ struct SFilterInfo { ...@@ -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); \
#define FILTER_COPY_IDX(dst, src, n) do { *(dst) = taosMemoryMalloc(sizeof(uint32_t) * n); memcpy(*(dst), src, sizeof(uint32_t) * n);} while (0) taosArrayPush((SArray *)((colInfo).info), &u); \
} 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_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_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)
......
...@@ -18,9 +18,9 @@ ...@@ -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;
...@@ -31,23 +31,28 @@ typedef struct SOperatorValueType { ...@@ -31,23 +31,28 @@ typedef struct SOperatorValueType {
typedef struct SScalarCtx { typedef struct SScalarCtx {
int32_t code; int32_t code;
bool dual; bool dual;
SArray *pBlockList; /* element is SSDataBlock* */ SArray* pBlockList; /* element is SSDataBlock* */
SHashObj *pRes; /* element is SScalarParam */ SHashObj* pRes; /* element is SScalarParam */
void *param; // additional parameter (meta actually) for acquire value such as tbname/tags values void* param; // additional parameter (meta actually) for acquire value such as tbname/tags values
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 { ...@@ -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);
...@@ -68,7 +94,7 @@ int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode); ...@@ -68,7 +94,7 @@ int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode);
#define GET_PARAM_BYTES(_c) ((_c)->columnData->info.bytes) #define GET_PARAM_BYTES(_c) ((_c)->columnData->info.bytes)
#define GET_PARAM_PRECISON(_c) ((_c)->columnData->info.precision) #define GET_PARAM_PRECISON(_c) ((_c)->columnData->info.precision)
void sclFreeParam(SScalarParam *param); void sclFreeParam(SScalarParam* param);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -94,8 +94,8 @@ static FORCE_INLINE _getDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType) ...@@ -94,8 +94,8 @@ static FORCE_INLINE _getDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType)
return p; return p;
} }
typedef void (*_bufConverteFunc)(char *buf, SScalarParam* pOut, int32_t outType, int32_t* overflow); typedef void (*_bufConverteFunc)(char *buf, SScalarParam *pOut, int32_t outType, int32_t *overflow);
typedef void (*_bin_scalar_fn_t)(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *output, int32_t order); typedef void (*_bin_scalar_fn_t)(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *output, int32_t order);
_bin_scalar_fn_t getBinScalarOperatorFn(int32_t binOperator); _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binOperator);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -12,44 +12,44 @@ ...@@ -12,44 +12,44 @@
* 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);
return result >= 0; return result >= 0;
} }
bool filterRangeCompGe (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { bool filterRangeCompGe(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);
return result > 0; return result > 0;
} }
bool filterRangeCompLi (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { bool filterRangeCompLi(const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) {
int32_t result = cfunc(minv, maxr); int32_t result = cfunc(minv, maxr);
return result <= 0; return result <= 0;
} }
bool filterRangeCompLe (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { bool filterRangeCompLe(const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) {
int32_t result = cfunc(minv, maxr); int32_t result = cfunc(minv, maxr);
return result < 0; return result < 0;
} }
bool filterRangeCompii (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { bool filterRangeCompii(const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) {
return cfunc(maxv, minr) >= 0 && cfunc(minv, maxr) <= 0; return cfunc(maxv, minr) >= 0 && cfunc(minv, maxr) <= 0;
} }
bool filterRangeCompee (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { bool filterRangeCompee(const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) {
return cfunc(maxv, minr) > 0 && cfunc(minv, maxr) < 0; return cfunc(maxv, minr) > 0 && cfunc(minv, maxr) < 0;
} }
bool filterRangeCompei (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { bool filterRangeCompei(const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) {
return cfunc(maxv, minr) > 0 && cfunc(minv, maxr) <= 0; return cfunc(maxv, minr) > 0 && cfunc(minv, maxr) <= 0;
} }
bool filterRangeCompie (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { bool filterRangeCompie(const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) {
return cfunc(maxv, minr) >= 0 && cfunc(minv, maxr) < 0; return cfunc(maxv, minr) >= 0 && cfunc(minv, maxr) < 0;
} }
...@@ -85,9 +85,8 @@ rangeCompFunc filterGetRangeCompFunc(char sflag, char eflag) { ...@@ -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) { ...@@ -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,
__compar_fn_t gInt8SignCompare[] = { compareChkInString,
compareInt8Val, compareInt8Int16, compareInt8Int32, compareInt8Int64, compareInt8Float, compareInt8Double compareWStrPatternMatch,
}; compareLenPrefixedWStr,
__compar_fn_t gInt8UsignCompare[] = { compareUint8Val,
compareInt8Uint8, compareInt8Uint16, compareInt8Uint32, compareInt8Uint64 compareUint16Val,
}; compareUint32Val,
compareUint64Val,
__compar_fn_t gInt16SignCompare[] = { setChkInBytes1,
compareInt16Int8, compareInt16Val, compareInt16Int32, compareInt16Int64, compareInt16Float, compareInt16Double setChkInBytes2,
}; setChkInBytes4,
__compar_fn_t gInt16UsignCompare[] = { setChkInBytes8,
compareInt16Uint8, compareInt16Uint16, compareInt16Uint32, compareInt16Uint64 compareStrRegexCompMatch,
}; compareStrRegexCompNMatch,
setChkNotInBytes1,
__compar_fn_t gInt32SignCompare[] = { setChkNotInBytes2,
compareInt32Int8, compareInt32Int16, compareInt32Val, compareInt32Int64, compareInt32Float, compareInt32Double setChkNotInBytes4,
}; setChkNotInBytes8,
__compar_fn_t gInt32UsignCompare[] = { compareChkNotInString,
compareInt32Uint8, compareInt32Uint16, compareInt32Uint32, compareInt32Uint64 compareStrPatternNotMatch,
}; compareWStrPatternNotMatch};
__compar_fn_t gInt64SignCompare[] = { __compar_fn_t gInt8SignCompare[] = {compareInt8Val, compareInt8Int16, compareInt8Int32,
compareInt64Int8, compareInt64Int16, compareInt64Int32, compareInt64Val, compareInt64Float, compareInt64Double compareInt8Int64, compareInt8Float, compareInt8Double};
}; __compar_fn_t gInt8UsignCompare[] = {compareInt8Uint8, compareInt8Uint16, compareInt8Uint32, compareInt8Uint64};
__compar_fn_t gInt64UsignCompare[] = {
compareInt64Uint8, compareInt64Uint16, compareInt64Uint32, compareInt64Uint64 __compar_fn_t gInt16SignCompare[] = {compareInt16Int8, compareInt16Val, compareInt16Int32,
}; compareInt16Int64, compareInt16Float, compareInt16Double};
__compar_fn_t gInt16UsignCompare[] = {compareInt16Uint8, compareInt16Uint16, compareInt16Uint32, compareInt16Uint64};
__compar_fn_t gFloatSignCompare[] = {
compareFloatInt8, compareFloatInt16, compareFloatInt32, compareFloatInt64, compareFloatVal, compareFloatDouble __compar_fn_t gInt32SignCompare[] = {compareInt32Int8, compareInt32Int16, compareInt32Val,
}; compareInt32Int64, compareInt32Float, compareInt32Double};
__compar_fn_t gFloatUsignCompare[] = { __compar_fn_t gInt32UsignCompare[] = {compareInt32Uint8, compareInt32Uint16, compareInt32Uint32, compareInt32Uint64};
compareFloatUint8, compareFloatUint16, compareFloatUint32, compareFloatUint64
}; __compar_fn_t gInt64SignCompare[] = {compareInt64Int8, compareInt64Int16, compareInt64Int32,
compareInt64Val, compareInt64Float, compareInt64Double};
__compar_fn_t gDoubleSignCompare[] = { __compar_fn_t gInt64UsignCompare[] = {compareInt64Uint8, compareInt64Uint16, compareInt64Uint32, compareInt64Uint64};
compareDoubleInt8, compareDoubleInt16, compareDoubleInt32, compareDoubleInt64, compareDoubleFloat, compareDoubleVal
}; __compar_fn_t gFloatSignCompare[] = {compareFloatInt8, compareFloatInt16, compareFloatInt32,
__compar_fn_t gDoubleUsignCompare[] = { compareFloatInt64, compareFloatVal, compareFloatDouble};
compareDoubleUint8, compareDoubleUint16, compareDoubleUint32, compareDoubleUint64 __compar_fn_t gFloatUsignCompare[] = {compareFloatUint8, compareFloatUint16, compareFloatUint32, compareFloatUint64};
};
__compar_fn_t gDoubleSignCompare[] = {compareDoubleInt8, compareDoubleInt16, compareDoubleInt32,
__compar_fn_t gUint8SignCompare[] = { compareDoubleInt64, compareDoubleFloat, compareDoubleVal};
compareUint8Int8, compareUint8Int16, compareUint8Int32, compareUint8Int64, compareUint8Float, compareUint8Double __compar_fn_t gDoubleUsignCompare[] = {compareDoubleUint8, compareDoubleUint16, compareDoubleUint32,
}; compareDoubleUint64};
__compar_fn_t gUint8UsignCompare[] = {
compareUint8Val, compareUint8Uint16, compareUint8Uint32, compareUint8Uint64 __compar_fn_t gUint8SignCompare[] = {compareUint8Int8, compareUint8Int16, compareUint8Int32,
}; compareUint8Int64, compareUint8Float, compareUint8Double};
__compar_fn_t gUint8UsignCompare[] = {compareUint8Val, compareUint8Uint16, compareUint8Uint32, compareUint8Uint64};
__compar_fn_t gUint16SignCompare[] = {
compareUint16Int8, compareUint16Int16, compareUint16Int32, compareUint16Int64, compareUint16Float, compareUint16Double __compar_fn_t gUint16SignCompare[] = {compareUint16Int8, compareUint16Int16, compareUint16Int32,
}; compareUint16Int64, compareUint16Float, compareUint16Double};
__compar_fn_t gUint16UsignCompare[] = { __compar_fn_t gUint16UsignCompare[] = {compareUint16Uint8, compareUint16Val, compareUint16Uint32, compareUint16Uint64};
compareUint16Uint8, compareUint16Val, compareUint16Uint32, compareUint16Uint64
}; __compar_fn_t gUint32SignCompare[] = {compareUint32Int8, compareUint32Int16, compareUint32Int32,
compareUint32Int64, compareUint32Float, compareUint32Double};
__compar_fn_t gUint32SignCompare[] = { __compar_fn_t gUint32UsignCompare[] = {compareUint32Uint8, compareUint32Uint16, compareUint32Val, compareUint32Uint64};
compareUint32Int8, compareUint32Int16, compareUint32Int32, compareUint32Int64, compareUint32Float, compareUint32Double
}; __compar_fn_t gUint64SignCompare[] = {compareUint64Int8, compareUint64Int16, compareUint64Int32,
__compar_fn_t gUint32UsignCompare[] = { compareUint64Int64, compareUint64Float, compareUint64Double};
compareUint32Uint8, compareUint32Uint16, compareUint32Val, compareUint32Uint64 __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) { ...@@ -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) { ...@@ -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) { ...@@ -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) {
...@@ -417,7 +424,7 @@ __compar_fn_t filterGetCompFuncEx(int32_t lType, int32_t rType, int32_t optr) { ...@@ -417,7 +424,7 @@ __compar_fn_t filterGetCompFuncEx(int32_t lType, int32_t rType, int32_t optr) {
} }
static FORCE_INLINE int32_t filterCompareGroupCtx(const void *pLeft, const void *pRight) { static FORCE_INLINE int32_t filterCompareGroupCtx(const void *pLeft, const void *pRight) {
SFilterGroupCtx *left = *((SFilterGroupCtx**)pLeft), *right = *((SFilterGroupCtx**)pRight); SFilterGroupCtx *left = *((SFilterGroupCtx **)pLeft), *right = *((SFilterGroupCtx **)pRight);
if (left->colNum > right->colNum) return 1; if (left->colNum > right->colNum) return 1;
if (left->colNum < right->colNum) return -1; if (left->colNum < right->colNum) return -1;
return 0; return 0;
...@@ -437,7 +444,7 @@ int32_t filterInitUnitsFields(SFilterInfo *info) { ...@@ -437,7 +444,7 @@ int32_t filterInitUnitsFields(SFilterInfo *info) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRangeCtx *ctx, SFilterRange* ra) { static FORCE_INLINE SFilterRangeNode *filterNewRange(SFilterRangeCtx *ctx, SFilterRange *ra) {
SFilterRangeNode *r = NULL; SFilterRangeNode *r = NULL;
if (ctx->rf) { if (ctx->rf) {
...@@ -454,8 +461,9 @@ static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRangeCtx *ctx, SFilt ...@@ -454,8 +461,9 @@ static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRangeCtx *ctx, SFilt
return r; return r;
} }
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) { ...@@ -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) ...@@ -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 ...@@ -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 {
...@@ -530,7 +535,7 @@ int32_t filterConvertRange(SFilterRangeCtx *cur, SFilterRange *ra, bool *notNull ...@@ -530,7 +535,7 @@ int32_t filterConvertRange(SFilterRangeCtx *cur, SFilterRange *ra, bool *notNull
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterAddRangeOptr(void* h, uint8_t raOptr, int32_t optr, bool *empty, bool *all) { int32_t filterAddRangeOptr(void *h, uint8_t raOptr, int32_t optr, bool *empty, bool *all) {
SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; SFilterRangeCtx *ctx = (SFilterRangeCtx *)h;
if (optr == LOGIC_COND_TYPE_AND) { if (optr == LOGIC_COND_TYPE_AND) {
...@@ -550,15 +555,13 @@ int32_t filterAddRangeOptr(void* h, uint8_t raOptr, int32_t optr, bool *empty, b ...@@ -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,8 +608,7 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) { ...@@ -605,8 +608,7 @@ 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;
bool emerged = false; bool emerged = false;
...@@ -625,7 +627,7 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) { ...@@ -625,7 +627,7 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) {
cr = ctx->pCompareFunc(&ra->s, &r->ra.e); cr = ctx->pCompareFunc(&ra->s, &r->ra.e);
if (FILTER_GREATER(cr, ra->sflag, r->ra.eflag)) { if (FILTER_GREATER(cr, ra->sflag, r->ra.eflag)) {
if (r->next) { if (r->next) {
r= r->next; r = r->next;
continue; continue;
} }
...@@ -692,23 +694,22 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) { ...@@ -692,23 +694,22 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterAddRange(void* h, SFilterRange* ra, int32_t optr) { int32_t filterAddRange(void *h, SFilterRange *ra, int32_t optr) {
SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; SFilterRangeCtx *ctx = (SFilterRangeCtx *)h;
if (FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) { if (FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) {
SIMPLE_COPY_VALUES(&ra->s, getDataMin(ctx->type)); SIMPLE_COPY_VALUES(&ra->s, getDataMin(ctx->type));
//FILTER_CLR_FLAG(ra->sflag, RA_NULL); // FILTER_CLR_FLAG(ra->sflag, RA_NULL);
} }
if (FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL)) { if (FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL)) {
SIMPLE_COPY_VALUES(&ra->e, getDataMax(ctx->type)); SIMPLE_COPY_VALUES(&ra->e, getDataMax(ctx->type));
//FILTER_CLR_FLAG(ra->eflag, RA_NULL); // FILTER_CLR_FLAG(ra->eflag, RA_NULL);
} }
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,9 +756,7 @@ int32_t filterCopyRangeCtx(void *dst, void *src) { ...@@ -755,9 +756,7 @@ 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;
if (FILTER_GET_FLAG(ctx->status, MR_ST_FIN)) { if (FILTER_GET_FLAG(ctx->status, MR_ST_FIN)) {
...@@ -789,7 +788,7 @@ int32_t filterFinishRange(void* h) { ...@@ -789,7 +788,7 @@ int32_t filterFinishRange(void* h) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterGetRangeNum(void* h, int32_t* num) { int32_t filterGetRangeNum(void *h, int32_t *num) {
filterFinishRange(h); filterFinishRange(h);
SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; SFilterRangeCtx *ctx = (SFilterRangeCtx *)h;
...@@ -806,13 +805,12 @@ int32_t filterGetRangeNum(void* h, int32_t* num) { ...@@ -806,13 +805,12 @@ 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);
SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; SFilterRangeCtx *ctx = (SFilterRangeCtx *)h;
uint32_t num = 0; uint32_t num = 0;
SFilterRangeNode* r = ctx->rs; SFilterRangeNode *r = ctx->rs;
while (r) { while (r) {
if (num) { if (num) {
...@@ -834,11 +832,10 @@ int32_t filterGetRangeRes(void* h, SFilterRange *ra) { ...@@ -834,11 +832,10 @@ 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;
if (src->isnull){ if (src->isnull) {
filterAddRangeOptr(ctx, OP_TYPE_IS_NULL, optr, empty, all); filterAddRangeOptr(ctx, OP_TYPE_IS_NULL, optr, empty, all);
if (FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) { if (FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) {
*all = true; *all = true;
...@@ -867,9 +864,7 @@ int32_t filterSourceRangeFromCtx(SFilterRangeCtx *ctx, void *sctx, int32_t optr, ...@@ -867,9 +864,7 @@ 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,8 +891,7 @@ int32_t filterFreeRangeCtx(void* h) { ...@@ -896,8 +891,7 @@ 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};
gp.unitNum = gp1->unitNum + gp2->unitNum; gp.unitNum = gp1->unitNum + gp2->unitNum;
...@@ -912,8 +906,7 @@ int32_t filterDetachCnfGroup(SFilterGroup *gp1, SFilterGroup *gp2, SArray* group ...@@ -912,8 +906,7 @@ 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,11 +943,10 @@ int32_t filterDetachCnfGroups(SArray* group, SArray* left, SArray* right) { ...@@ -950,11 +943,10 @@ int32_t filterDetachCnfGroups(SArray* group, SArray* left, SArray* right) {
} }
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterGetFiledByDesc(SFilterFields* fields, int32_t type, void *v) { int32_t filterGetFiledByDesc(SFilterFields *fields, int32_t type, void *v) {
for (uint32_t i = 0; i < fields->num; ++i) { for (uint32_t i = 0; i < fields->num; ++i) {
if (nodesEqualNode(fields->fields[i].desc, v)) { if (nodesEqualNode(fields->fields[i].desc, v)) {
return i; return i;
...@@ -964,7 +956,6 @@ int32_t filterGetFiledByDesc(SFilterFields* fields, int32_t type, void *v) { ...@@ -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 ...@@ -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, ...@@ -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, ...@@ -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 ...@@ -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 ...@@ -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, ...@@ -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);
} }
...@@ -1148,7 +1143,7 @@ int32_t filterAddUnitToGroup(SFilterGroup *group, uint32_t unitIdx) { ...@@ -1148,7 +1143,7 @@ int32_t filterAddUnitToGroup(SFilterGroup *group, uint32_t unitIdx) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode *tree, SArray *group) {
SOperatorNode *node = (SOperatorNode *)tree; SOperatorNode *node = (SOperatorNode *)tree;
int32_t ret = TSDB_CODE_SUCCESS; int32_t ret = TSDB_CODE_SUCCESS;
SFilterFieldId left = {0}, right = {0}; SFilterFieldId left = {0}, right = {0};
...@@ -1183,7 +1178,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { ...@@ -1183,7 +1178,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) {
len = tDataTypes[type].bytes; len = tDataTypes[type].bytes;
filterAddField(info, NULL, (void**) &out.columnData->pData, FLD_TYPE_VALUE, &right, len, true); filterAddField(info, NULL, (void **)&out.columnData->pData, FLD_TYPE_VALUE, &right, len, true);
out.columnData->pData = NULL; out.columnData->pData = NULL;
} else { } else {
void *data = taosMemoryCalloc(1, tDataTypes[type].bytes); void *data = taosMemoryCalloc(1, tDataTypes[type].bytes);
...@@ -1191,7 +1186,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { ...@@ -1191,7 +1186,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) {
FLT_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); FLT_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
} }
memcpy(data, nodesGetValueFromNode(valueNode), tDataTypes[type].bytes); memcpy(data, nodesGetValueFromNode(valueNode), tDataTypes[type].bytes);
filterAddField(info, NULL, (void**) &data, FLD_TYPE_VALUE, &right, len, true); filterAddField(info, NULL, (void **)&data, FLD_TYPE_VALUE, &right, len, true);
} }
filterAddUnit(info, OP_TYPE_EQUAL, &left, &right, &uidx); filterAddUnit(info, OP_TYPE_EQUAL, &left, &right, &uidx);
...@@ -1217,8 +1212,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { ...@@ -1217,8 +1212,7 @@ 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);
uint16_t flag = 0; uint16_t flag = 0;
...@@ -1230,7 +1224,8 @@ int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* 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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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);
} }
...@@ -1371,7 +1371,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan ...@@ -1371,7 +1371,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
while (r) { while (r) {
memset(g, 0, sizeof(*g)); memset(g, 0, sizeof(*g));
if ((!FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_NULL)) &&(!FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_NULL))) { if ((!FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_NULL)) && (!FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_NULL))) {
__compar_fn_t func = getComparFunc(type, 0); __compar_fn_t func = getComparFunc(type, 0);
if (func(&r->ra.s, &r->ra.e) == 0) { if (func(&r->ra.s, &r->ra.e) == 0) {
void *data = taosMemoryMalloc(sizeof(int64_t)); void *data = taosMemoryMalloc(sizeof(int64_t));
...@@ -1387,8 +1387,10 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan ...@@ -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 ...@@ -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,11 +1414,12 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan ...@@ -1411,11 +1414,12 @@ 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);
} }
assert (g->unitNum > 0); assert(g->unitNum > 0);
taosArrayPush(res, g); taosArrayPush(res, g);
...@@ -1427,23 +1431,21 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan ...@@ -1427,23 +1431,21 @@ 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;
} }
SFilterGroup* p = (SFilterGroup*) pItem; SFilterGroup *p = (SFilterGroup *)pItem;
taosMemoryFreeClear(p->unitIdxs); taosMemoryFreeClear(p->unitIdxs);
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;
SArray* newGroup = NULL; SArray *newGroup = NULL;
SArray* resGroup = NULL; SArray *resGroup = NULL;
ENodeType nType = nodeType(pNode); ENodeType nType = nodeType(pNode);
SFltBuildGroupCtx *ctx = (SFltBuildGroupCtx *)pContext; SFltBuildGroupCtx *ctx = (SFltBuildGroupCtx *)pContext;
...@@ -1527,24 +1529,24 @@ int32_t fltConverToStr(char *str, int type, void *buf, int32_t bufSize, int32_t ...@@ -1527,24 +1529,24 @@ int32_t fltConverToStr(char *str, int type, void *buf, int32_t bufSize, int32_t
break; break;
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
n = sprintf(str, (*(int8_t*)buf) ? "true" : "false"); n = sprintf(str, (*(int8_t *)buf) ? "true" : "false");
break; break;
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
n = sprintf(str, "%d", *(int8_t*)buf); n = sprintf(str, "%d", *(int8_t *)buf);
break; break;
case TSDB_DATA_TYPE_SMALLINT: case TSDB_DATA_TYPE_SMALLINT:
n = sprintf(str, "%d", *(int16_t*)buf); n = sprintf(str, "%d", *(int16_t *)buf);
break; break;
case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_INT:
n = sprintf(str, "%d", *(int32_t*)buf); n = sprintf(str, "%d", *(int32_t *)buf);
break; break;
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
n = sprintf(str, "%" PRId64, *(int64_t*)buf); n = sprintf(str, "%" PRId64, *(int64_t *)buf);
break; break;
case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_FLOAT:
...@@ -1558,7 +1560,7 @@ int32_t fltConverToStr(char *str, int type, void *buf, int32_t bufSize, int32_t ...@@ -1558,7 +1560,7 @@ int32_t fltConverToStr(char *str, int type, void *buf, int32_t bufSize, int32_t
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
if (bufSize < 0) { if (bufSize < 0) {
// tscError("invalid buf size"); // tscError("invalid buf size");
return TSDB_CODE_TSC_INVALID_VALUE; return TSDB_CODE_TSC_INVALID_VALUE;
} }
...@@ -1569,23 +1571,23 @@ int32_t fltConverToStr(char *str, int type, void *buf, int32_t bufSize, int32_t ...@@ -1569,23 +1571,23 @@ int32_t fltConverToStr(char *str, int type, void *buf, int32_t bufSize, int32_t
break; break;
case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_UTINYINT:
n = sprintf(str, "%d", *(uint8_t*)buf); n = sprintf(str, "%d", *(uint8_t *)buf);
break; break;
case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_USMALLINT:
n = sprintf(str, "%d", *(uint16_t*)buf); n = sprintf(str, "%d", *(uint16_t *)buf);
break; break;
case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_UINT:
n = sprintf(str, "%u", *(uint32_t*)buf); n = sprintf(str, "%u", *(uint32_t *)buf);
break; break;
case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_UBIGINT:
n = sprintf(str, "%" PRIu64, *(uint64_t*)buf); n = sprintf(str, "%" PRIu64, *(uint64_t *)buf);
break; break;
default: default:
// tscError("unsupported type:%d", type); // tscError("unsupported type:%d", type);
return TSDB_CODE_TSC_INVALID_VALUE; return TSDB_CODE_TSC_INVALID_VALUE;
} }
...@@ -1615,19 +1617,20 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) ...@@ -1615,19 +1617,20 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
SFilterField *field = &info->fields[FLD_TYPE_VALUE].fields[i]; SFilterField *field = &info->fields[FLD_TYPE_VALUE].fields[i];
if (field->desc) { if (field->desc) {
if (QUERY_NODE_VALUE != nodeType(field->desc)) { if (QUERY_NODE_VALUE != nodeType(field->desc)) {
qDebug("VAL%d => [type:not value node][val:NIL]", i); //TODO qDebug("VAL%d => [type:not value node][val:NIL]", i); // TODO
continue; continue;
} }
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
} }
} else if (field->data) { } else if (field->data) {
qDebug("VAL%d => [type:NIL][val:NIL]", i); //TODO qDebug("VAL%d => [type:NIL][val:NIL]", i); // TODO
} }
} }
...@@ -1641,8 +1644,9 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) ...@@ -1641,8 +1644,9 @@ 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) {
...@@ -1660,8 +1664,9 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) ...@@ -1660,8 +1664,9 @@ 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) {
...@@ -1678,7 +1683,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) ...@@ -1678,7 +1683,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
strcat(str, "]"); strcat(str, "]");
} }
qDebug("%s", str); //TODO qDebug("%s", str); // TODO
} }
qDebug("GROUP Num:%u", info->groupNum); qDebug("GROUP Num:%u", info->groupNum);
...@@ -1700,26 +1705,27 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) ...@@ -1700,26 +1705,27 @@ 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) {
char str[256] = {0}; char str[256] = {0};
int32_t tlen = 0; int32_t tlen = 0;
if (FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_NULL)) { if (FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_NULL)) {
strcat(str,"(NULL)"); strcat(str, "(NULL)");
} else { } else {
FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? strcat(str,"(") : strcat(str,"["); FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? strcat(str, "(") : strcat(str, "[");
fltConverToStr(str + strlen(str), ctx->type, &r->ra.s, tlen > 32 ? 32 : tlen, &tlen); fltConverToStr(str + strlen(str), ctx->type, &r->ra.s, tlen > 32 ? 32 : tlen, &tlen);
FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? strcat(str,")") : strcat(str,"]"); FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? strcat(str, ")") : strcat(str, "]");
} }
strcat(str, " - "); strcat(str, " - ");
if (FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_NULL)) { if (FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_NULL)) {
strcat(str, "(NULL)"); strcat(str, "(NULL)");
} else { } else {
FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? strcat(str,"(") : strcat(str,"["); FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? strcat(str, "(") : strcat(str, "[");
fltConverToStr(str + strlen(str), ctx->type, &r->ra.e, tlen > 32 ? 32 : tlen, &tlen); fltConverToStr(str + strlen(str), ctx->type, &r->ra.e, tlen > 32 ? 32 : tlen, &tlen);
FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? strcat(str,")") : strcat(str,"]"); FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? strcat(str, ")") : strcat(str, "]");
} }
qDebug("range: %s", str); qDebug("range: %s", str);
...@@ -1739,7 +1745,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) ...@@ -1739,7 +1745,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
} else if (FILTER_GET_FLAG(info->blkFlag, FI_STATUS_BLK_EMPTY)) { } else if (FILTER_GET_FLAG(info->blkFlag, FI_STATUS_BLK_EMPTY)) {
qDebug("Flag:%s", "EMPTY"); qDebug("Flag:%s", "EMPTY");
return; return;
} else if (FILTER_GET_FLAG(info->blkFlag, FI_STATUS_BLK_ACTIVE)){ } else if (FILTER_GET_FLAG(info->blkFlag, FI_STATUS_BLK_ACTIVE)) {
qDebug("Flag:%s", "ACTIVE"); qDebug("Flag:%s", "ACTIVE");
} }
...@@ -1756,36 +1762,35 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) ...@@ -1756,36 +1762,35 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
} }
void filterFreeColInfo(void *data) { void filterFreeColInfo(void *data) {
SFilterColInfo* info = (SFilterColInfo *)data; SFilterColInfo *info = (SFilterColInfo *)data;
if (info->info == NULL) { if (info->info == NULL) {
return; return;
} }
if (info->type == RANGE_TYPE_VAR_HASH) { if (info->type == RANGE_TYPE_VAR_HASH) {
//TODO // TODO
} else if (info->type == RANGE_TYPE_MR_CTX) { } else if (info->type == RANGE_TYPE_MR_CTX) {
filterFreeRangeCtx(info->info); filterFreeRangeCtx(info->info);
} else if (info->type == RANGE_TYPE_UNIT) { } else if (info->type == RANGE_TYPE_UNIT) {
taosArrayDestroy((SArray *)info->info); taosArrayDestroy((SArray *)info->info);
} }
//NO NEED TO FREE UNIT // NO NEED TO FREE UNIT
info->type = 0; info->type = 0;
info->info = NULL; info->info = NULL;
} }
void filterFreeColCtx(void *data) { void filterFreeColCtx(void *data) {
SFilterColCtx* ctx = (SFilterColCtx *)data; SFilterColCtx *ctx = (SFilterColCtx *)data;
if (ctx->ctx) { if (ctx->ctx) {
filterFreeRangeCtx(ctx->ctx); filterFreeRangeCtx(ctx->ctx);
} }
} }
void filterFreeGroupCtx(SFilterGroupCtx *gRes) {
void filterFreeGroupCtx(SFilterGroupCtx* gRes) {
if (gRes == NULL) { if (gRes == NULL) {
return; return;
} }
...@@ -1807,7 +1812,7 @@ void filterFreeGroupCtx(SFilterGroupCtx* gRes) { ...@@ -1807,7 +1812,7 @@ void filterFreeGroupCtx(SFilterGroupCtx* gRes) {
taosMemoryFreeClear(gRes); taosMemoryFreeClear(gRes);
} }
void filterFreeField(SFilterField* field, int32_t type) { void filterFreeField(SFilterField *field, int32_t type) {
if (field == NULL) { if (field == NULL) {
return; return;
} }
...@@ -1868,7 +1873,7 @@ void filterFreeInfo(SFilterInfo *info) { ...@@ -1868,7 +1873,7 @@ void filterFreeInfo(SFilterInfo *info) {
} }
} }
int32_t filterHandleValueExtInfo(SFilterUnit* unit, char extInfo) { int32_t filterHandleValueExtInfo(SFilterUnit *unit, char extInfo) {
assert(extInfo > 0 || extInfo < 0); assert(extInfo > 0 || extInfo < 0);
uint8_t optr = FILTER_UNIT_OPTR(unit); uint8_t optr = FILTER_UNIT_OPTR(unit);
...@@ -1891,24 +1896,23 @@ int32_t filterHandleValueExtInfo(SFilterUnit* unit, char extInfo) { ...@@ -1891,24 +1896,23 @@ 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];
if (unit->right.type != FLD_TYPE_VALUE) { if (unit->right.type != FLD_TYPE_VALUE) {
assert(unit->compare.optr == FILTER_DUMMY_EMPTY_OPTR || scalarGetOperatorParamNum(unit->compare.optr) == 1); assert(unit->compare.optr == FILTER_DUMMY_EMPTY_OPTR || scalarGetOperatorParamNum(unit->compare.optr) == 1);
continue; continue;
} }
SFilterField* right = FILTER_UNIT_RIGHT_FIELD(info, unit); SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit);
assert(FILTER_GET_FLAG(right->flag, FLD_TYPE_VALUE)); assert(FILTER_GET_FLAG(right->flag, FLD_TYPE_VALUE));
uint32_t type = FILTER_UNIT_DATA_TYPE(unit); uint32_t type = FILTER_UNIT_DATA_TYPE(unit);
int8_t precision = FILTER_UNIT_DATA_PRECISION(unit); int8_t precision = FILTER_UNIT_DATA_PRECISION(unit);
SFilterField* fi = right; SFilterField *fi = right;
SValueNode* var = (SValueNode *)fi->desc; SValueNode *var = (SValueNode *)fi->desc;
if (var == NULL) { if (var == NULL) {
assert(fi->data != NULL); assert(fi->data != NULL);
continue; continue;
...@@ -1930,24 +1934,26 @@ int32_t fltInitValFieldData(SFilterInfo *info) { ...@@ -1930,24 +1934,26 @@ 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);
} else { } else {
if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) { //TIME RANGE if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) { // TIME RANGE
/* /*
fi->data = taosMemoryCalloc(dType->bytes, tDataTypes[type].bytes); fi->data = taosMemoryCalloc(dType->bytes, tDataTypes[type].bytes);
for (int32_t a = 0; a < dType->bytes; ++a) { for (int32_t a = 0; a < dType->bytes; ++a) {
int64_t *v = taosArrayGet(var->arr, a); int64_t *v = taosArrayGet(var->arr, a);
assignVal((char *)fi->data + a * tDataTypes[type].bytes, (char *)v, 0, type); assignVal((char *)fi->data + a * tDataTypes[type].bytes, (char *)v, 0, type);
} }
*/ */
continue; continue;
} else { } else {
fi->data = taosMemoryCalloc(1, sizeof(int64_t)); fi->data = taosMemoryCalloc(1, sizeof(int64_t));
...@@ -1979,11 +1985,10 @@ int32_t fltInitValFieldData(SFilterInfo *info) { ...@@ -1979,11 +1985,10 @@ 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) {
qError("filterInitValFieldData taosUcs4ToMbs error 1"); qError("filterInitValFieldData taosUcs4ToMbs error 1");
return TSDB_CODE_QRY_APP_ERROR; return TSDB_CODE_QRY_APP_ERROR;
} }
...@@ -1995,7 +2000,6 @@ int32_t fltInitValFieldData(SFilterInfo *info) { ...@@ -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,8 +2048,7 @@ bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right) ...@@ -2044,8 +2048,7 @@ 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);
void *val = FILTER_UNIT_VAL_DATA(info, u); void *val = FILTER_UNIT_VAL_DATA(info, u);
...@@ -2125,15 +2128,14 @@ _return: ...@@ -2125,15 +2128,14 @@ _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);
int32_t type = gRes->colInfo[colIdx].dataType; int32_t type = gRes->colInfo[colIdx].dataType;
SFilterRangeCtx* ctx = filterInitRangeCtx(type, 0); SFilterRangeCtx *ctx = filterInitRangeCtx(type, 0);
for (uint32_t i = 0; i < size; ++i) { for (uint32_t i = 0; i < size; ++i) {
SFilterUnit* u = taosArrayGetP(colArray, i); SFilterUnit *u = taosArrayGetP(colArray, i);
uint8_t optr = FILTER_UNIT_OPTR(u); uint8_t optr = FILTER_UNIT_OPTR(u);
filterAddRangeOptr(ctx, optr, LOGIC_COND_TYPE_AND, empty, NULL); filterAddRangeOptr(ctx, optr, LOGIC_COND_TYPE_AND, empty, NULL);
...@@ -2143,7 +2145,7 @@ int32_t filterMergeUnits(SFilterInfo *info, SFilterGroupCtx* gRes, uint32_t colI ...@@ -2143,7 +2145,7 @@ int32_t filterMergeUnits(SFilterInfo *info, SFilterGroupCtx* gRes, uint32_t colI
filterAddUnitRange(info, u, ctx, LOGIC_COND_TYPE_AND); filterAddUnitRange(info, u, ctx, LOGIC_COND_TYPE_AND);
FLT_CHK_JMP(MR_EMPTY_RES(ctx)); FLT_CHK_JMP(MR_EMPTY_RES(ctx));
} }
if(FILTER_UNIT_OPTR(u) == OP_TYPE_EQUAL && !FILTER_NO_MERGE_DATA_TYPE(FILTER_UNIT_DATA_TYPE(u))){ if (FILTER_UNIT_OPTR(u) == OP_TYPE_EQUAL && !FILTER_NO_MERGE_DATA_TYPE(FILTER_UNIT_DATA_TYPE(u))) {
gRes->colInfo[colIdx].optr = OP_TYPE_EQUAL; gRes->colInfo[colIdx].optr = OP_TYPE_EQUAL;
SIMPLE_COPY_VALUES(&gRes->colInfo[colIdx].value, FILTER_UNIT_VAL_DATA(info, u)); SIMPLE_COPY_VALUES(&gRes->colInfo[colIdx].value, FILTER_UNIT_VAL_DATA(info, u));
} }
...@@ -2164,15 +2166,14 @@ _return: ...@@ -2164,15 +2166,14 @@ _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));
uint32_t colIdxi = 0; uint32_t colIdxi = 0;
uint32_t gResIdx = 0; uint32_t gResIdx = 0;
for (uint32_t i = 0; i < info->groupNum; ++i) { for (uint32_t i = 0; i < info->groupNum; ++i) {
SFilterGroup* g = info->groups + i; SFilterGroup *g = info->groups + i;
gRes[gResIdx] = taosMemoryCalloc(1, sizeof(SFilterGroupCtx)); gRes[gResIdx] = taosMemoryCalloc(1, sizeof(SFilterGroupCtx));
gRes[gResIdx]->colInfo = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(SFilterColInfo)); gRes[gResIdx]->colInfo = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(SFilterColInfo));
...@@ -2180,7 +2181,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t ...@@ -2180,7 +2181,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t
empty = false; empty = false;
for (uint32_t j = 0; j < g->unitNum; ++j) { for (uint32_t j = 0; j < g->unitNum; ++j) {
SFilterUnit* u = FILTER_GROUP_UNIT(info, g, j); SFilterUnit *u = FILTER_GROUP_UNIT(info, g, j);
uint32_t cidx = FILTER_UNIT_COL_IDX(u); uint32_t cidx = FILTER_UNIT_COL_IDX(u);
if (gRes[gResIdx]->colInfo[cidx].info == NULL) { if (gRes[gResIdx]->colInfo[cidx].info == NULL) {
...@@ -2238,22 +2239,21 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t ...@@ -2238,22 +2239,21 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
bool filterIsSameUnits(SFilterColInfo* pCol1, SFilterColInfo* pCol2) { bool filterIsSameUnits(SFilterColInfo *pCol1, SFilterColInfo *pCol2) {
if (pCol1->type != pCol2->type) { if (pCol1->type != pCol2->type) {
return false; return false;
} }
if (RANGE_TYPE_MR_CTX == pCol1->type) { if (RANGE_TYPE_MR_CTX == pCol1->type) {
SFilterRangeCtx* pCtx1 = (SFilterRangeCtx*)pCol1->info; SFilterRangeCtx *pCtx1 = (SFilterRangeCtx *)pCol1->info;
SFilterRangeCtx* pCtx2 = (SFilterRangeCtx*)pCol2->info; SFilterRangeCtx *pCtx2 = (SFilterRangeCtx *)pCol2->info;
if ((pCtx1->isnull != pCtx2->isnull) || (pCtx1->notnull != pCtx2->notnull) || (pCtx1->isrange != pCtx2->isrange)) { if ((pCtx1->isnull != pCtx2->isnull) || (pCtx1->notnull != pCtx2->notnull) || (pCtx1->isrange != pCtx2->isrange)) {
return false; return false;
} }
SFilterRangeNode *pNode1 = pCtx1->rs;
SFilterRangeNode* pNode1 = pCtx1->rs; SFilterRangeNode *pNode2 = pCtx2->rs;
SFilterRangeNode* pNode2 = pCtx2->rs;
while (true) { while (true) {
if (NULL == pNode1 && NULL == pNode2) { if (NULL == pNode1 && NULL == pNode2) {
...@@ -2264,7 +2264,8 @@ bool filterIsSameUnits(SFilterColInfo* pCol1, SFilterColInfo* pCol2) { ...@@ -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;
} }
...@@ -2276,7 +2277,7 @@ bool filterIsSameUnits(SFilterColInfo* pCol1, SFilterColInfo* pCol2) { ...@@ -2276,7 +2277,7 @@ bool filterIsSameUnits(SFilterColInfo* pCol1, SFilterColInfo* pCol2) {
return true; return true;
} }
void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool *conflict) { void filterCheckColConflict(SFilterGroupCtx *gRes1, SFilterGroupCtx *gRes2, bool *conflict) {
uint32_t idx1 = 0, idx2 = 0, m = 0, n = 0; uint32_t idx1 = 0, idx2 = 0, m = 0, n = 0;
bool equal = false; bool equal = false;
...@@ -2308,8 +2309,8 @@ void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool ...@@ -2308,8 +2309,8 @@ void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool
// for long in operation // for long in operation
if (gRes1->colInfo[idx1].optr == OP_TYPE_EQUAL && gRes2->colInfo[idx2].optr == OP_TYPE_EQUAL) { if (gRes1->colInfo[idx1].optr == OP_TYPE_EQUAL && gRes2->colInfo[idx2].optr == OP_TYPE_EQUAL) {
SFilterRangeCtx* ctx = gRes1->colInfo[idx1].info; SFilterRangeCtx *ctx = gRes1->colInfo[idx1].info;
if (ctx->pCompareFunc(&gRes1->colInfo[idx1].value, &gRes2->colInfo[idx2].value)){ if (ctx->pCompareFunc(&gRes1->colInfo[idx1].value, &gRes2->colInfo[idx2].value)) {
*conflict = true; *conflict = true;
return; return;
} }
...@@ -2330,8 +2331,8 @@ void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool ...@@ -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,8 +2351,7 @@ int32_t filterMergeTwoGroupsImpl(SFilterInfo *info, SFilterRangeCtx **ctx, int32 ...@@ -2350,8 +2351,7 @@ 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;
filterCheckColConflict(*gRes1, *gRes2, &conflict); filterCheckColConflict(*gRes1, *gRes2, &conflict);
...@@ -2367,7 +2367,7 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter ...@@ -2367,7 +2367,7 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter
uint32_t equal1 = 0, equal2 = 0, merNum = 0; uint32_t equal1 = 0, equal2 = 0, merNum = 0;
SFilterRangeCtx *ctx = NULL; SFilterRangeCtx *ctx = NULL;
SFilterColCtx colCtx = {0}; SFilterColCtx colCtx = {0};
SArray* colCtxs = taosArrayInit((*gRes2)->colNum, sizeof(SFilterColCtx)); SArray *colCtxs = taosArrayInit((*gRes2)->colNum, sizeof(SFilterColCtx));
for (; m < (*gRes1)->colNum; ++m) { for (; m < (*gRes1)->colNum; ++m) {
idx1 = (*gRes1)->colIdx[m]; idx1 = (*gRes1)->colIdx[m];
...@@ -2432,7 +2432,7 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter ...@@ -2432,7 +2432,7 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter
assert(merNum > 0); assert(merNum > 0);
SFilterColInfo *colInfo = NULL; SFilterColInfo *colInfo = NULL;
assert (merNum == equal1 || merNum == equal2); assert(merNum == equal1 || merNum == equal2);
filterFreeGroupCtx(*gRes2); filterFreeGroupCtx(*gRes2);
*gRes2 = NULL; *gRes2 = NULL;
...@@ -2469,8 +2469,7 @@ _return: ...@@ -2469,8 +2469,7 @@ _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;
} }
...@@ -2502,7 +2501,7 @@ int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gR ...@@ -2502,7 +2501,7 @@ int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gR
if (gRes[n] == NULL) { if (gRes[n] == NULL) {
if (n < ((*gResNum) - 1)) { if (n < ((*gResNum) - 1)) {
memmove(&gRes[n], &gRes[n+1], (*gResNum-n-1) * POINTER_BYTES); memmove(&gRes[n], &gRes[n + 1], (*gResNum - n - 1) * POINTER_BYTES);
} }
--cEnd; --cEnd;
...@@ -2523,7 +2522,7 @@ int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gR ...@@ -2523,7 +2522,7 @@ int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gR
if (gRes[n] == NULL) { if (gRes[n] == NULL) {
if (n < ((*gResNum) - 1)) { if (n < ((*gResNum) - 1)) {
memmove(&gRes[n], &gRes[n+1], (*gResNum-n-1) * POINTER_BYTES); memmove(&gRes[n], &gRes[n + 1], (*gResNum - n - 1) * POINTER_BYTES);
} }
--cEnd; --cEnd;
...@@ -2556,7 +2555,7 @@ _return: ...@@ -2556,7 +2555,7 @@ _return:
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterConvertGroupFromArray(SFilterInfo *info, SArray* group) { int32_t filterConvertGroupFromArray(SFilterInfo *info, SArray *group) {
size_t groupSize = taosArrayGetSize(group); size_t groupSize = taosArrayGetSize(group);
info->groupNum = (uint32_t)groupSize; info->groupNum = (uint32_t)groupSize;
...@@ -2574,7 +2573,7 @@ int32_t filterConvertGroupFromArray(SFilterInfo *info, SArray* group) { ...@@ -2574,7 +2573,7 @@ int32_t filterConvertGroupFromArray(SFilterInfo *info, SArray* group) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum) { int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t gResNum) {
if (!FILTER_GET_FLAG(info->status, FI_STATUS_REWRITE)) { if (!FILTER_GET_FLAG(info->status, FI_STATUS_REWRITE)) {
qDebug("no need rewrite"); qDebug("no need rewrite");
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -2584,7 +2583,7 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum ...@@ -2584,7 +2583,7 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum
FILTER_SET_FLAG(oinfo.status, FI_STATUS_CLONED); FILTER_SET_FLAG(oinfo.status, FI_STATUS_CLONED);
SArray* group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup)); SArray *group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup));
SFilterGroupCtx *res = NULL; SFilterGroupCtx *res = NULL;
SFilterColInfo *colInfo = NULL; SFilterColInfo *colInfo = NULL;
int32_t optr = 0; int32_t optr = 0;
...@@ -2615,7 +2614,7 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum ...@@ -2615,7 +2614,7 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum
int32_t usize = (int32_t)taosArrayGetSize((SArray *)colInfo->info); int32_t usize = (int32_t)taosArrayGetSize((SArray *)colInfo->info);
for (int32_t n = 0; n < usize; ++n) { for (int32_t n = 0; n < usize; ++n) {
SFilterUnit* u = taosArrayGetP((SArray *)colInfo->info, n); SFilterUnit *u = taosArrayGetP((SArray *)colInfo->info, n);
filterAddUnitFromUnit(info, &oinfo, u, &uidx); filterAddUnitFromUnit(info, &oinfo, u, &uidx);
filterAddUnitToGroup(&ng, uidx); filterAddUnitToGroup(&ng, uidx);
...@@ -2643,7 +2642,7 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum ...@@ -2643,7 +2642,7 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum) { int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t gResNum) {
uint32_t *idxs = NULL; uint32_t *idxs = NULL;
uint32_t colNum = 0; uint32_t colNum = 0;
SFilterGroupCtx *res = NULL; SFilterGroupCtx *res = NULL;
...@@ -2691,10 +2690,10 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_ ...@@ -2691,10 +2690,10 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_
assert(res->colIdx[n] == idxs[m]); assert(res->colIdx[n] == idxs[m]);
SFilterColInfo * colInfo = &res->colInfo[res->colIdx[n]]; SFilterColInfo *colInfo = &res->colInfo[res->colIdx[n]];
if (info->colRange[m] == NULL) { if (info->colRange[m] == NULL) {
info->colRange[m] = filterInitRangeCtx(colInfo->dataType, 0); info->colRange[m] = filterInitRangeCtx(colInfo->dataType, 0);
SFilterField* fi = FILTER_GET_COL_FIELD(info, res->colIdx[n]); SFilterField *fi = FILTER_GET_COL_FIELD(info, res->colIdx[n]);
info->colRange[m]->colId = FILTER_GET_COL_FIELD_ID(fi); info->colRange[m]->colId = FILTER_GET_COL_FIELD_ID(fi);
} }
...@@ -2732,7 +2731,7 @@ _return: ...@@ -2732,7 +2731,7 @@ _return:
int32_t filterPostProcessRange(SFilterInfo *info) { int32_t filterPostProcessRange(SFilterInfo *info) {
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];
SFilterRangeNode *r = ctx->rs; SFilterRangeNode *r = ctx->rs;
while (r) { while (r) {
r->rc.func = filterGetRangeCompFunc(r->ra.sflag, r->ra.eflag); r->rc.func = filterGetRangeCompFunc(r->ra.sflag, r->ra.eflag);
...@@ -2743,7 +2742,6 @@ int32_t filterPostProcessRange(SFilterInfo *info) { ...@@ -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) { ...@@ -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;
...@@ -2801,7 +2798,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3 ...@@ -2801,7 +2798,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3
continue; continue;
} }
for(int32_t i = 0; i < numOfCols; ++i) { for (int32_t i = 0; i < numOfCols; ++i) {
if (pDataStatis[i].colId == cunit->colId) { if (pDataStatis[i].colId == cunit->colId) {
index = i; index = i;
break; break;
...@@ -2838,13 +2835,12 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3 ...@@ -2838,13 +2835,12 @@ 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;
} }
SColumnDataAgg* pDataBlockst = &pDataStatis[index]; SColumnDataAgg *pDataBlockst = &pDataStatis[index];
void *minVal, *maxVal; void *minVal, *maxVal;
float minv = 0; float minv = 0;
float maxv = 0; float maxv = 0;
...@@ -2863,8 +2859,10 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3 ...@@ -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 ...@@ -2903,7 +2901,6 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3
rmUnit = 1; rmUnit = 1;
} }
} }
} }
if (rmUnit == 0) { if (rmUnit == 0) {
...@@ -2925,7 +2922,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3 ...@@ -2925,7 +2922,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3
empty = 0; empty = 0;
// save group idx start pointer // save group idx start pointer
uint32_t * pGroupIdx = unitIdx; uint32_t *pGroupIdx = unitIdx;
for (uint32_t u = 0; u < group->unitNum; ++u) { for (uint32_t u = 0; u < group->unitNum; ++u) {
uint32_t uidx = group->unitIdxs[u]; uint32_t uidx = group->unitIdxs[u];
if (info->blkUnitRes[uidx] == 1) { if (info->blkUnitRes[uidx] == 1) {
...@@ -2976,15 +2973,16 @@ _return: ...@@ -2976,15 +2973,16 @@ _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;
int8_t* p = (int8_t*)pRes->pData; int8_t *p = (int8_t *)pRes->pData;
for (int32_t i = 0; i < numOfRows; ++i) { for (int32_t i = 0; i < numOfRows; ++i) {
//FILTER_UNIT_CLR_F(info); // FILTER_UNIT_CLR_F(info);
unitIdx = info->blkUnits; unitIdx = info->blkUnits;
...@@ -2994,9 +2992,9 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, SColumnInfoD ...@@ -2994,9 +2992,9 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, SColumnInfoD
SFilterComUnit *cunit = &info->cunits[*(unitIdx + u)]; SFilterComUnit *cunit = &info->cunits[*(unitIdx + u)];
void *colData = colDataGetData((SColumnInfoData *)cunit->colData, i); void *colData = colDataGetData((SColumnInfoData *)cunit->colData, i);
//if (FILTER_UNIT_GET_F(info, uidx)) { // if (FILTER_UNIT_GET_F(info, uidx)) {
// p[i] = FILTER_UNIT_GET_R(info, uidx); // p[i] = FILTER_UNIT_GET_R(info, uidx);
//} else { // } else {
uint8_t optr = cunit->optr; uint8_t optr = cunit->optr;
if (colDataIsNull((SColumnInfoData *)(cunit->colData), 0, i, NULL)) { if (colDataIsNull((SColumnInfoData *)(cunit->colData), 0, i, NULL)) {
...@@ -3007,13 +3005,14 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, SColumnInfoD ...@@ -3007,13 +3005,14 @@ 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);
} }
//FILTER_UNIT_SET_R(info, uidx, p[i]); // FILTER_UNIT_SET_R(info, uidx, p[i]);
//FILTER_UNIT_SET_F(info, uidx); // FILTER_UNIT_SET_F(info, uidx);
} }
if (p[i] == 0) { if (p[i] == 0) {
...@@ -3036,9 +3035,8 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, SColumnInfoD ...@@ -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: ...@@ -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;
} }
...@@ -3080,7 +3080,7 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, ...@@ -3080,7 +3080,7 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows,
SFilterInfo *info = (SFilterInfo *)pinfo; SFilterInfo *info = (SFilterInfo *)pinfo;
bool all = true; bool all = true;
int8_t* p = (int8_t*)pRes->pData; int8_t *p = (int8_t *)pRes->pData;
if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) { if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) {
return all; return all;
...@@ -3110,7 +3110,7 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows ...@@ -3110,7 +3110,7 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows
return all; return all;
} }
int8_t* p = (int8_t*)pRes->pData; int8_t *p = (int8_t *)pRes->pData;
for (int32_t i = 0; i < numOfRows; ++i) { for (int32_t i = 0; i < numOfRows; ++i) {
uint32_t uidx = info->groups[0].unitIdxs[0]; uint32_t uidx = info->groups[0].unitIdxs[0];
...@@ -3127,7 +3127,8 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows ...@@ -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;
...@@ -3140,10 +3141,10 @@ bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, SColumnInfoData* pRe ...@@ -3140,10 +3141,10 @@ bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, SColumnInfoData* pRe
return all; return all;
} }
int8_t* p = (int8_t*) pRes->pData; int8_t *p = (int8_t *)pRes->pData;
for (int32_t i = 0; i < numOfRows; ++i) { for (int32_t i = 0; i < numOfRows; ++i) {
SColumnInfoData* pData = info->cunits[0].colData; SColumnInfoData *pData = info->cunits[0].colData;
void *colData = colDataGetData(pData, i); void *colData = colDataGetData(pData, i);
if (colData == NULL || colDataIsNull_s(pData, i)) { if (colData == NULL || colDataIsNull_s(pData, i)) {
...@@ -3172,7 +3173,7 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes ...@@ -3172,7 +3173,7 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes
return all; return all;
} }
int8_t* p = (int8_t*) pRes->pData; int8_t *p = (int8_t *)pRes->pData;
for (int32_t i = 0; i < numOfRows; ++i) { for (int32_t i = 0; i < numOfRows; ++i) {
uint32_t uidx = info->groups[0].unitIdxs[0]; uint32_t uidx = info->groups[0].unitIdxs[0];
...@@ -3184,18 +3185,21 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes ...@@ -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) {
...@@ -3217,10 +3221,10 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SC ...@@ -3217,10 +3221,10 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SC
return all; return all;
} }
int8_t* p = (int8_t*) pRes->pData; int8_t *p = (int8_t *)pRes->pData;
for (int32_t i = 0; i < numOfRows; ++i) { for (int32_t i = 0; i < numOfRows; ++i) {
//FILTER_UNIT_CLR_F(info); // FILTER_UNIT_CLR_F(info);
for (uint32_t g = 0; g < info->groupNum; ++g) { for (uint32_t g = 0; g < info->groupNum; ++g) {
SFilterGroup *group = &info->groups[g]; SFilterGroup *group = &info->groups[g];
...@@ -3229,9 +3233,9 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SC ...@@ -3229,9 +3233,9 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SC
SFilterComUnit *cunit = &info->cunits[uidx]; SFilterComUnit *cunit = &info->cunits[uidx];
void *colData = colDataGetData((SColumnInfoData *)(cunit->colData), i); void *colData = colDataGetData((SColumnInfoData *)(cunit->colData), i);
//if (FILTER_UNIT_GET_F(info, uidx)) { // if (FILTER_UNIT_GET_F(info, uidx)) {
// p[i] = FILTER_UNIT_GET_R(info, uidx); // p[i] = FILTER_UNIT_GET_R(info, uidx);
//} else { // } else {
uint8_t optr = cunit->optr; uint8_t optr = cunit->optr;
if (colData == NULL || colDataIsNull((SColumnInfoData *)(cunit->colData), 0, i, NULL)) { if (colData == NULL || colDataIsNull((SColumnInfoData *)(cunit->colData), 0, i, NULL)) {
...@@ -3242,25 +3246,27 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SC ...@@ -3242,25 +3246,27 @@ 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) {
qError("castConvert1 taosUcs4ToMbs error"); qError("castConvert1 taosUcs4ToMbs error");
}else{ } else {
varDataSetLen(newColData, len); varDataSetLen(newColData, len);
p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, newColData, cunit->valData); p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, newColData, cunit->valData);
} }
taosMemoryFreeClear(newColData); taosMemoryFreeClear(newColData);
}else{ } else {
p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData); p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData);
} }
} }
//FILTER_UNIT_SET_R(info, uidx, p[i]); // FILTER_UNIT_SET_R(info, uidx, p[i]);
//FILTER_UNIT_SET_F(info, uidx); // FILTER_UNIT_SET_F(info, uidx);
} }
if (p[i] == 0) { if (p[i] == 0) {
...@@ -3318,10 +3324,8 @@ int32_t filterSetExecFunc(SFilterInfo *info) { ...@@ -3318,10 +3324,8 @@ 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;
filterMergeGroupUnits(info, gRes, &gResNum); filterMergeGroupUnits(info, gRes, &gResNum);
...@@ -3333,7 +3337,6 @@ int32_t filterPreprocess(SFilterInfo *info) { ...@@ -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,14 +3365,13 @@ _return: ...@@ -3362,14 +3365,13 @@ _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;
} }
for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) {
SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; SFilterField *fi = &info->fields[FLD_TYPE_COLUMN].fields[i];
if (fromColId) { if (fromColId) {
(*fp)(param, FILTER_GET_COL_FIELD_ID(fi), &fi->data); (*fp)(param, FILTER_GET_COL_FIELD_ID(fi), &fi->data);
...@@ -3383,11 +3385,10 @@ int32_t fltSetColFieldDataImpl(SFilterInfo *info, void *param, filer_get_col_fro ...@@ -3383,11 +3385,10 @@ 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;
SArray* group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup)); SArray *group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup));
filterInitUnitsFields(info); filterInitUnitsFields(info);
...@@ -3442,7 +3443,7 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t ...@@ -3442,7 +3443,7 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t
for (uint32_t k = 0; k < info->colRangeNum; ++k) { for (uint32_t k = 0; k < info->colRangeNum; ++k) {
int32_t index = -1; int32_t index = -1;
SFilterRangeCtx *ctx = info->colRange[k]; SFilterRangeCtx *ctx = info->colRange[k];
for(int32_t i = 0; i < numOfCols; ++i) { for (int32_t i = 0; i < numOfCols; ++i) {
if (pDataStatis[i] != NULL && pDataStatis[i]->colId == ctx->colId) { if (pDataStatis[i] != NULL && pDataStatis[i]->colId == ctx->colId) {
index = i; index = i;
break; break;
...@@ -3479,7 +3480,7 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t ...@@ -3479,7 +3480,7 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t
} }
} }
SColumnDataAgg* pDataBlockst = pDataStatis[index]; SColumnDataAgg *pDataBlockst = pDataStatis[index];
SFilterRangeNode *r = ctx->rs; SFilterRangeNode *r = ctx->rs;
float minv = 0; float minv = 0;
...@@ -3512,8 +3513,6 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t ...@@ -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);
...@@ -3591,7 +3590,7 @@ int32_t filterGetTimeRangeImpl(SFilterInfo *info, STimeWindow *win, bool * ...@@ -3591,7 +3590,7 @@ int32_t filterGetTimeRangeImpl(SFilterInfo *info, STimeWindow *win, bool *
filterFreeRangeCtx(prev); filterFreeRangeCtx(prev);
filterFreeRangeCtx(tmpc); filterFreeRangeCtx(tmpc);
qDebug("qFilter time range:[%"PRId64 "]-[%"PRId64 "]", win->skey, win->ekey); qDebug("qFilter time range:[%" PRId64 "]-[%" PRId64 "]", win->skey, win->ekey);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
_return: _return:
...@@ -3601,19 +3600,18 @@ _return: ...@@ -3601,19 +3600,18 @@ _return:
filterFreeRangeCtx(prev); filterFreeRangeCtx(prev);
filterFreeRangeCtx(tmpc); filterFreeRangeCtx(tmpc);
qDebug("qFilter time range:[%"PRId64 "]-[%"PRId64 "]", win->skey, win->ekey); qDebug("qFilter time range:[%" PRId64 "]-[%" PRId64 "]", win->skey, win->ekey);
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;
*isStrict = true; *isStrict = true;
FLT_ERR_RET(filterInitFromNode(pNode, &info, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP)); FLT_ERR_RET(filterInitFromNode(pNode, &info, FLT_OPTION_NO_REWRITE | FLT_OPTION_TIMESTAMP));
if (info->scalarMode) { if (info->scalarMode) {
*win = TSWINDOW_INITIALIZER; *win = TSWINDOW_INITIALIZER;
...@@ -3630,14 +3628,13 @@ _return: ...@@ -3630,14 +3628,13 @@ _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;
} }
for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) {
SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; SFilterField *fi = &info->fields[FLD_TYPE_COLUMN].fields[i];
int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); int32_t type = FILTER_GET_COL_FIELD_TYPE(fi);
if (type == TSDB_DATA_TYPE_NCHAR) { if (type == TSDB_DATA_TYPE_NCHAR) {
SFilterField nfi = {0}; SFilterField nfi = {0};
...@@ -3651,15 +3648,16 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar ...@@ -3651,15 +3648,16 @@ 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;
varDataCopy(dst, src); varDataCopy(dst, src);
continue; continue;
} }
bool ret = taosMbsToUcs4(varDataVal(src), varDataLen(src), (TdUcs4*)varDataVal(dst), bufSize, &len); bool ret = taosMbsToUcs4(varDataVal(src), varDataLen(src), (TdUcs4 *)varDataVal(dst), bufSize, &len);
if(!ret) { if (!ret) {
qError("filterConverNcharColumns taosMbsToUcs4 error"); qError("filterConverNcharColumns taosMbsToUcs4 error");
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
...@@ -3679,9 +3677,9 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar ...@@ -3679,9 +3677,9 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t filterFreeNcharColumns(SFilterInfo* info) { int32_t filterFreeNcharColumns(SFilterInfo *info) {
for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) {
SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; SFilterField *fi = &info->fields[FLD_TYPE_COLUMN].fields[i];
int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); int32_t type = FILTER_GET_COL_FIELD_TYPE(fi);
if (type == TSDB_DATA_TYPE_NCHAR) { if (type == TSDB_DATA_TYPE_NCHAR) {
taosMemoryFreeClear(fi->data); taosMemoryFreeClear(fi->data);
...@@ -3691,7 +3689,7 @@ int32_t filterFreeNcharColumns(SFilterInfo* info) { ...@@ -3691,7 +3689,7 @@ int32_t filterFreeNcharColumns(SFilterInfo* info) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t fltAddValueNodeToConverList(SFltTreeStat *stat, SValueNode* pNode) { int32_t fltAddValueNodeToConverList(SFltTreeStat *stat, SValueNode *pNode) {
if (NULL == stat->nodeList) { if (NULL == stat->nodeList) {
stat->nodeList = taosArrayInit(10, POINTER_BYTES); stat->nodeList = taosArrayInit(10, POINTER_BYTES);
if (NULL == stat->nodeList) { if (NULL == stat->nodeList) {
...@@ -3706,7 +3704,7 @@ int32_t fltAddValueNodeToConverList(SFltTreeStat *stat, SValueNode* pNode) { ...@@ -3706,7 +3704,7 @@ int32_t fltAddValueNodeToConverList(SFltTreeStat *stat, SValueNode* pNode) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { EDealRes fltReviseRewriter(SNode **pNode, void *pContext) {
SFltTreeStat *stat = (SFltTreeStat *)pContext; SFltTreeStat *stat = (SFltTreeStat *)pContext;
if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pNode)) { if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pNode)) {
...@@ -3801,13 +3799,14 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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);
...@@ -3911,7 +3912,7 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { ...@@ -3911,7 +3912,7 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
return DEAL_RES_ERROR; return DEAL_RES_ERROR;
} }
int32_t fltReviseNodes(SFilterInfo *pInfo, SNode** pNode, SFltTreeStat *pStat) { int32_t fltReviseNodes(SFilterInfo *pInfo, SNode **pNode, SFltTreeStat *pStat) {
int32_t code = 0; int32_t code = 0;
nodesRewriteExprPostOrder(pNode, fltReviseRewriter, (void *)pStat); nodesRewriteExprPostOrder(pNode, fltReviseRewriter, (void *)pStat);
...@@ -3930,18 +3931,17 @@ _return: ...@@ -3930,18 +3931,17 @@ _return:
FLT_RET(code); FLT_RET(code);
} }
int32_t fltOptimizeNodes(SFilterInfo *pInfo, SNode** pNode, SFltTreeStat *pStat) { int32_t fltOptimizeNodes(SFilterInfo *pInfo, SNode **pNode, SFltTreeStat *pStat) {
//TODO // TODO
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;
for (int32_t j = 0; j < numOfCols; ++j) { for (int32_t j = 0; j < numOfCols; ++j) {
SColumnInfoData* pColInfo = taosArrayGet(pDataBlock, j); SColumnInfoData *pColInfo = taosArrayGet(pDataBlock, j);
if (id == pColInfo->info.colId) { if (id == pColInfo->info.colId) {
*data = pColInfo; *data = pColInfo;
break; break;
...@@ -3953,20 +3953,19 @@ int32_t fltGetDataFromColId(void *param, int32_t id, void **data) { ...@@ -3953,20 +3953,19 @@ int32_t fltGetDataFromColId(void *param, int32_t id, void **data) {
int32_t fltGetDataFromSlotId(void *param, int32_t id, void **data) { 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;
} }
SColumnInfoData* pColInfo = taosArrayGet(pDataBlock, id); SColumnInfoData *pColInfo = taosArrayGet(pDataBlock, id);
*data = pColInfo; *data = pColInfo;
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,9 +3978,7 @@ int32_t filterSetDataFromColId(SFilterInfo *info, void *param) { ...@@ -3979,9 +3978,7 @@ 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: ...@@ -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;
...@@ -4067,8 +4065,8 @@ bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, SColumnInfoData** p, SC ...@@ -4067,8 +4065,8 @@ bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, SColumnInfoData** p, SC
// todo this should be return during filter procedure // todo this should be return during filter procedure
int32_t num = 0; int32_t num = 0;
for(int32_t i = 0; i < output.numOfRows; ++i) { for (int32_t i = 0; i < output.numOfRows; ++i) {
if (((int8_t*)((*p)->pData))[i] == 1) { if (((int8_t *)((*p)->pData))[i] == 1) {
++num; ++num;
} }
} }
...@@ -4092,10 +4090,10 @@ typedef struct SClassifyConditionCxt { ...@@ -4092,10 +4090,10 @@ typedef struct SClassifyConditionCxt {
bool hasOtherCol; bool hasOtherCol;
} SClassifyConditionCxt; } SClassifyConditionCxt;
static EDealRes classifyConditionImpl(SNode* pNode, void* pContext) { static EDealRes classifyConditionImpl(SNode *pNode, void *pContext) {
SClassifyConditionCxt* pCxt = (SClassifyConditionCxt*)pContext; SClassifyConditionCxt *pCxt = (SClassifyConditionCxt *)pContext;
if (QUERY_NODE_COLUMN == nodeType(pNode)) { if (QUERY_NODE_COLUMN == nodeType(pNode)) {
SColumnNode* pCol = (SColumnNode*)pNode; SColumnNode *pCol = (SColumnNode *)pNode;
if (PRIMARYKEY_TIMESTAMP_COL_ID == pCol->colId && TSDB_SYSTEM_TABLE != pCol->tableType) { if (PRIMARYKEY_TIMESTAMP_COL_ID == pCol->colId && TSDB_SYSTEM_TABLE != pCol->tableType) {
pCxt->hasPrimaryKey = true; pCxt->hasPrimaryKey = true;
} else if (pCol->hasIndex) { } else if (pCol->hasIndex) {
...@@ -4107,9 +4105,9 @@ static EDealRes classifyConditionImpl(SNode* pNode, void* pContext) { ...@@ -4107,9 +4105,9 @@ static EDealRes classifyConditionImpl(SNode* pNode, void* pContext) {
pCxt->hasOtherCol = true; pCxt->hasOtherCol = true;
} }
} else if (QUERY_NODE_FUNCTION == nodeType(pNode)) { } else if (QUERY_NODE_FUNCTION == nodeType(pNode)) {
SFunctionNode* pFunc = (SFunctionNode*)pNode; SFunctionNode *pFunc = (SFunctionNode *)pNode;
if (fmIsPseudoColumnFunc(pFunc->funcId)) { if (fmIsPseudoColumnFunc(pFunc->funcId)) {
if (FUNCTION_TYPE_TBNAME==pFunc->funcType) { if (FUNCTION_TYPE_TBNAME == pFunc->funcType) {
pCxt->hasTagCol = true; pCxt->hasTagCol = true;
} else { } else {
pCxt->hasOtherCol = true; pCxt->hasOtherCol = true;
...@@ -4126,7 +4124,7 @@ typedef enum EConditionType { ...@@ -4126,7 +4124,7 @@ typedef enum EConditionType {
COND_TYPE_NORMAL COND_TYPE_NORMAL
} EConditionType; } EConditionType;
static EConditionType classifyCondition(SNode* pNode) { static EConditionType classifyCondition(SNode *pNode) {
SClassifyConditionCxt cxt = {.hasPrimaryKey = false, .hasTagIndexCol = false, .hasOtherCol = false}; SClassifyConditionCxt cxt = {.hasPrimaryKey = false, .hasTagIndexCol = false, .hasOtherCol = false};
nodesWalkExpr(pNode, classifyConditionImpl, &cxt); nodesWalkExpr(pNode, classifyConditionImpl, &cxt);
return cxt.hasOtherCol ? COND_TYPE_NORMAL return cxt.hasOtherCol ? COND_TYPE_NORMAL
...@@ -4136,16 +4134,16 @@ static EConditionType classifyCondition(SNode* pNode) { ...@@ -4136,16 +4134,16 @@ static EConditionType classifyCondition(SNode* pNode) {
: (cxt.hasTagIndexCol ? COND_TYPE_TAG_INDEX : COND_TYPE_TAG))); : (cxt.hasTagIndexCol ? COND_TYPE_TAG_INDEX : COND_TYPE_TAG)));
} }
static bool isCondColumnsFromMultiTable(SNode* pCond) { static bool isCondColumnsFromMultiTable(SNode *pCond) {
SNodeList* pCondCols = nodesMakeList(); SNodeList *pCondCols = nodesMakeList();
int32_t code = nodesCollectColumnsFromNode(pCond, NULL, COLLECT_COL_TYPE_ALL, &pCondCols); int32_t code = nodesCollectColumnsFromNode(pCond, NULL, COLLECT_COL_TYPE_ALL, &pCondCols);
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
if (LIST_LENGTH(pCondCols) >= 2) { if (LIST_LENGTH(pCondCols) >= 2) {
SColumnNode* pFirstCol = (SColumnNode*)nodesListGetNode(pCondCols, 0); SColumnNode *pFirstCol = (SColumnNode *)nodesListGetNode(pCondCols, 0);
SNode* pColNode = NULL; SNode *pColNode = NULL;
FOREACH(pColNode, pCondCols) { FOREACH(pColNode, pCondCols) {
if (strcmp(((SColumnNode*)pColNode)->dbName, pFirstCol->dbName) != 0 || if (strcmp(((SColumnNode *)pColNode)->dbName, pFirstCol->dbName) != 0 ||
strcmp(((SColumnNode*)pColNode)->tableAlias, pFirstCol->tableAlias) != 0) { strcmp(((SColumnNode *)pColNode)->tableAlias, pFirstCol->tableAlias) != 0) {
nodesDestroyList(pCondCols); nodesDestroyList(pCondCols);
return true; return true;
} }
...@@ -4156,17 +4154,17 @@ static bool isCondColumnsFromMultiTable(SNode* pCond) { ...@@ -4156,17 +4154,17 @@ static bool isCondColumnsFromMultiTable(SNode* pCond) {
return false; return false;
} }
static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, SNode** pTagIndexCond, SNode** pTagCond, static int32_t partitionLogicCond(SNode **pCondition, SNode **pPrimaryKeyCond, SNode **pTagIndexCond, SNode **pTagCond,
SNode** pOtherCond) { SNode **pOtherCond) {
SLogicConditionNode* pLogicCond = (SLogicConditionNode*)(*pCondition); SLogicConditionNode *pLogicCond = (SLogicConditionNode *)(*pCondition);
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
SNodeList* pPrimaryKeyConds = NULL; SNodeList *pPrimaryKeyConds = NULL;
SNodeList* pTagIndexConds = NULL; SNodeList *pTagIndexConds = NULL;
SNodeList* pTagConds = NULL; SNodeList *pTagConds = NULL;
SNodeList* pOtherConds = NULL; SNodeList *pOtherConds = NULL;
SNode* pCond = NULL; SNode *pCond = NULL;
FOREACH(pCond, pLogicCond->pParameterList) { FOREACH(pCond, pLogicCond->pParameterList) {
if (isCondColumnsFromMultiTable(pCond)) { if (isCondColumnsFromMultiTable(pCond)) {
if (NULL != pOtherCond) { if (NULL != pOtherCond) {
...@@ -4205,10 +4203,10 @@ static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, S ...@@ -4205,10 +4203,10 @@ static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, S
} }
} }
SNode* pTempPrimaryKeyCond = NULL; SNode *pTempPrimaryKeyCond = NULL;
SNode* pTempTagIndexCond = NULL; SNode *pTempTagIndexCond = NULL;
SNode* pTempTagCond = NULL; SNode *pTempTagCond = NULL;
SNode* pTempOtherCond = NULL; SNode *pTempOtherCond = NULL;
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = nodesMergeConds(&pTempPrimaryKeyCond, &pPrimaryKeyConds); code = nodesMergeConds(&pTempPrimaryKeyCond, &pPrimaryKeyConds);
} }
...@@ -4251,10 +4249,10 @@ static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, S ...@@ -4251,10 +4249,10 @@ static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, S
return code; return code;
} }
int32_t filterPartitionCond(SNode** pCondition, SNode** pPrimaryKeyCond, SNode** pTagIndexCond, SNode** pTagCond, int32_t filterPartitionCond(SNode **pCondition, SNode **pPrimaryKeyCond, SNode **pTagIndexCond, SNode **pTagCond,
SNode** pOtherCond) { SNode **pOtherCond) {
if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pCondition) && if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pCondition) &&
LOGIC_COND_TYPE_AND == ((SLogicConditionNode*)*pCondition)->condType) { LOGIC_COND_TYPE_AND == ((SLogicConditionNode *)*pCondition)->condType) {
return partitionLogicCond(pCondition, pPrimaryKeyCond, pTagIndexCond, pTagCond, pOtherCond); return partitionLogicCond(pCondition, pPrimaryKeyCond, pTagIndexCond, pTagCond, pOtherCond);
} }
......
#include "scalar.h"
#include "function.h" #include "function.h"
#include "functionMgt.h" #include "functionMgt.h"
#include "nodes.h" #include "nodes.h"
...@@ -5,25 +6,25 @@ ...@@ -5,25 +6,25 @@
#include "sclInt.h" #include "sclInt.h"
#include "sclvector.h" #include "sclvector.h"
#include "tcommon.h" #include "tcommon.h"
#include "tcompare.h"
#include "tdatablock.h" #include "tdatablock.h"
#include "scalar.h"
#include "tudf.h"
#include "ttime.h" #include "ttime.h"
#include "tcompare.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;
} }
return 2; return 2;
} }
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;
} }
...@@ -36,8 +37,8 @@ int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode) { ...@@ -36,8 +37,8 @@ int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows, SScalarParam* pParam) { int32_t sclCreateColumnInfoData(SDataType *pType, int32_t numOfRows, SScalarParam *pParam) {
SColumnInfoData* pColumnData = taosMemoryCalloc(1, sizeof(SColumnInfoData)); SColumnInfoData *pColumnData = taosMemoryCalloc(1, sizeof(SColumnInfoData));
if (pColumnData == NULL) { if (pColumnData == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return terrno; return terrno;
...@@ -60,7 +61,7 @@ int32_t sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows, SScalarPara ...@@ -60,7 +61,7 @@ int32_t sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows, SScalarPara
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out, int32_t* overflow) { int32_t doConvertDataType(SValueNode *pValueNode, SScalarParam *out, int32_t *overflow) {
SScalarParam in = {.numOfRows = 1}; SScalarParam in = {.numOfRows = 1};
int32_t code = sclCreateColumnInfoData(&pValueNode->node.resType, 1, &in); int32_t code = sclCreateColumnInfoData(&pValueNode->node.resType, 1, &in);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
...@@ -111,7 +112,7 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { ...@@ -111,7 +112,7 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) {
int32_t overflow = 0; int32_t overflow = 0;
code = doConvertDataType(valueNode, &out, &overflow); code = doConvertDataType(valueNode, &out, &overflow);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
// sclError("convert data from %d to %d failed", in.type, out.type); // sclError("convert data from %d to %d failed", in.type, out.type);
SCL_ERR_JRET(code); SCL_ERR_JRET(code);
} }
...@@ -213,7 +214,7 @@ void sclFreeParamList(SScalarParam *param, int32_t paramNum) { ...@@ -213,7 +214,7 @@ void sclFreeParamList(SScalarParam *param, int32_t paramNum) {
} }
for (int32_t i = 0; i < paramNum; ++i) { for (int32_t i = 0; i < paramNum; ++i) {
SScalarParam* p = param + i; SScalarParam *p = param + i;
sclFreeParam(p); sclFreeParam(p);
} }
...@@ -226,33 +227,33 @@ void sclDowngradeValueType(SValueNode *valueNode) { ...@@ -226,33 +227,33 @@ void sclDowngradeValueType(SValueNode *valueNode) {
int8_t i8 = valueNode->datum.i; int8_t i8 = valueNode->datum.i;
if (i8 == valueNode->datum.i) { if (i8 == valueNode->datum.i) {
valueNode->node.resType.type = TSDB_DATA_TYPE_TINYINT; valueNode->node.resType.type = TSDB_DATA_TYPE_TINYINT;
*(int8_t*)&valueNode->typeData = i8; *(int8_t *)&valueNode->typeData = i8;
break; break;
} }
int16_t i16 = valueNode->datum.i; int16_t i16 = valueNode->datum.i;
if (i16 == valueNode->datum.i) { if (i16 == valueNode->datum.i) {
valueNode->node.resType.type = TSDB_DATA_TYPE_SMALLINT; valueNode->node.resType.type = TSDB_DATA_TYPE_SMALLINT;
*(int16_t*)&valueNode->typeData = i16; *(int16_t *)&valueNode->typeData = i16;
break; break;
} }
int32_t i32 = valueNode->datum.i; int32_t i32 = valueNode->datum.i;
if (i32 == valueNode->datum.i) { if (i32 == valueNode->datum.i) {
valueNode->node.resType.type = TSDB_DATA_TYPE_INT; valueNode->node.resType.type = TSDB_DATA_TYPE_INT;
*(int32_t*)&valueNode->typeData = i32; *(int32_t *)&valueNode->typeData = i32;
break; break;
} }
break; break;
} }
case TSDB_DATA_TYPE_UBIGINT:{ case TSDB_DATA_TYPE_UBIGINT: {
uint8_t u8 = valueNode->datum.i; uint8_t u8 = valueNode->datum.i;
if (u8 == valueNode->datum.i) { if (u8 == valueNode->datum.i) {
int8_t i8 = valueNode->datum.i; int8_t i8 = valueNode->datum.i;
if (i8 == valueNode->datum.i) { if (i8 == valueNode->datum.i) {
valueNode->node.resType.type = TSDB_DATA_TYPE_TINYINT; valueNode->node.resType.type = TSDB_DATA_TYPE_TINYINT;
*(int8_t*)&valueNode->typeData = i8; *(int8_t *)&valueNode->typeData = i8;
} else { } else {
valueNode->node.resType.type = TSDB_DATA_TYPE_UTINYINT; valueNode->node.resType.type = TSDB_DATA_TYPE_UTINYINT;
*(uint8_t*)&valueNode->typeData = u8; *(uint8_t *)&valueNode->typeData = u8;
} }
break; break;
} }
...@@ -261,10 +262,10 @@ void sclDowngradeValueType(SValueNode *valueNode) { ...@@ -261,10 +262,10 @@ void sclDowngradeValueType(SValueNode *valueNode) {
int16_t i16 = valueNode->datum.i; int16_t i16 = valueNode->datum.i;
if (i16 == valueNode->datum.i) { if (i16 == valueNode->datum.i) {
valueNode->node.resType.type = TSDB_DATA_TYPE_SMALLINT; valueNode->node.resType.type = TSDB_DATA_TYPE_SMALLINT;
*(int16_t*)&valueNode->typeData = i16; *(int16_t *)&valueNode->typeData = i16;
} else { } else {
valueNode->node.resType.type = TSDB_DATA_TYPE_USMALLINT; valueNode->node.resType.type = TSDB_DATA_TYPE_USMALLINT;
*(uint16_t*)&valueNode->typeData = u16; *(uint16_t *)&valueNode->typeData = u16;
} }
break; break;
} }
...@@ -273,10 +274,10 @@ void sclDowngradeValueType(SValueNode *valueNode) { ...@@ -273,10 +274,10 @@ void sclDowngradeValueType(SValueNode *valueNode) {
int32_t i32 = valueNode->datum.i; int32_t i32 = valueNode->datum.i;
if (i32 == valueNode->datum.i) { if (i32 == valueNode->datum.i) {
valueNode->node.resType.type = TSDB_DATA_TYPE_INT; valueNode->node.resType.type = TSDB_DATA_TYPE_INT;
*(int32_t*)&valueNode->typeData = i32; *(int32_t *)&valueNode->typeData = i32;
} else { } else {
valueNode->node.resType.type = TSDB_DATA_TYPE_UINT; valueNode->node.resType.type = TSDB_DATA_TYPE_UINT;
*(uint32_t*)&valueNode->typeData = u32; *(uint32_t *)&valueNode->typeData = u32;
} }
break; break;
} }
...@@ -286,7 +287,7 @@ void sclDowngradeValueType(SValueNode *valueNode) { ...@@ -286,7 +287,7 @@ void sclDowngradeValueType(SValueNode *valueNode) {
float f = valueNode->datum.d; float f = valueNode->datum.d;
if (FLT_EQUAL(f, valueNode->datum.d)) { if (FLT_EQUAL(f, valueNode->datum.d)) {
valueNode->node.resType.type = TSDB_DATA_TYPE_FLOAT; valueNode->node.resType.type = TSDB_DATA_TYPE_FLOAT;
*(float*)&valueNode->typeData = f; *(float *)&valueNode->typeData = f;
break; break;
} }
break; break;
...@@ -296,10 +297,10 @@ void sclDowngradeValueType(SValueNode *valueNode) { ...@@ -296,10 +297,10 @@ void sclDowngradeValueType(SValueNode *valueNode) {
} }
} }
int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t *rowNum) { int32_t sclInitParam(SNode *node, SScalarParam *param, SScalarCtx *ctx, int32_t *rowNum) {
switch (nodeType(node)) { switch (nodeType(node)) {
case QUERY_NODE_LEFT_VALUE: { case QUERY_NODE_LEFT_VALUE: {
SSDataBlock* pb = taosArrayGetP(ctx->pBlockList, 0); SSDataBlock *pb = taosArrayGetP(ctx->pBlockList, 0);
param->numOfRows = pb->info.rows; param->numOfRows = pb->info.rows;
break; break;
} }
...@@ -308,7 +309,7 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t ...@@ -308,7 +309,7 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t
ASSERT(param->columnData == NULL); ASSERT(param->columnData == NULL);
param->numOfRows = 1; param->numOfRows = 1;
/*int32_t code = */sclCreateColumnInfoData(&valueNode->node.resType, 1, param); /*int32_t code = */ sclCreateColumnInfoData(&valueNode->node.resType, 1, param);
if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type || valueNode->isNull) { if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type || valueNode->isNull) {
colDataAppendNULL(param->columnData, 0); colDataAppendNULL(param->columnData, 0);
} else { } else {
...@@ -349,8 +350,8 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t ...@@ -349,8 +350,8 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t
SColumnNode *ref = (SColumnNode *)node; SColumnNode *ref = (SColumnNode *)node;
int32_t index = -1; int32_t index = -1;
for(int32_t i = 0; i < taosArrayGetSize(ctx->pBlockList); ++i) { for (int32_t i = 0; i < taosArrayGetSize(ctx->pBlockList); ++i) {
SSDataBlock* pb = taosArrayGetP(ctx->pBlockList, i); SSDataBlock *pb = taosArrayGetP(ctx->pBlockList, i);
if (pb->info.blockId == ref->dataBlockId) { if (pb->info.blockId == ref->dataBlockId) {
index = i; index = i;
break; break;
...@@ -358,7 +359,8 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t ...@@ -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 ...@@ -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 ...@@ -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) {
...@@ -434,7 +439,7 @@ int32_t sclInitParamList(SScalarParam **pParams, SNodeList* pParamList, SScalarC ...@@ -434,7 +439,7 @@ int32_t sclInitParamList(SScalarParam **pParams, SNodeList* pParamList, SScalarC
SNode *tnode = NULL; SNode *tnode = NULL;
int32_t i = 0; int32_t i = 0;
if (SCL_IS_CONST_CALC(ctx)) { if (SCL_IS_CONST_CALC(ctx)) {
WHERE_EACH (tnode, pParamList) { WHERE_EACH(tnode, pParamList) {
if (!SCL_IS_CONST_NODE(tnode)) { if (!SCL_IS_CONST_NODE(tnode)) {
WHERE_NEXT; WHERE_NEXT;
} else { } else {
...@@ -499,7 +504,6 @@ int32_t sclGetNodeType(SNode *pNode, SScalarCtx *ctx) { ...@@ -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: ...@@ -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);
} }
...@@ -621,7 +626,7 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o ...@@ -621,7 +626,7 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o
complete = false; complete = false;
continue; continue;
} }
char* p = colDataGetData(params[m].columnData, i); char *p = colDataGetData(params[m].columnData, i);
GET_TYPED_DATA(value, bool, params[m].columnData->info.type, p); GET_TYPED_DATA(value, bool, params[m].columnData->info.type, p);
if (LOGIC_COND_TYPE_AND == node->condType && (false == value)) { if (LOGIC_COND_TYPE_AND == node->condType && (false == value)) {
...@@ -636,7 +641,7 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o ...@@ -636,7 +641,7 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o
} }
if (complete) { if (complete) {
colDataAppend(output->columnData, i, (char*) &value, false); colDataAppend(output->columnData, i, (char *)&value, false);
if (value) { if (value) {
numOfQualified++; numOfQualified++;
} }
...@@ -663,7 +668,8 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp ...@@ -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);
} }
} }
...@@ -679,8 +685,8 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp ...@@ -679,8 +685,8 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp
_bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(node->opType); _bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(node->opType);
int32_t paramNum = scalarGetOperatorParamNum(node->opType); int32_t paramNum = scalarGetOperatorParamNum(node->opType);
SScalarParam* pLeft = &params[0]; SScalarParam *pLeft = &params[0];
SScalarParam* pRight = paramNum > 1 ? &params[1] : NULL; SScalarParam *pRight = paramNum > 1 ? &params[1] : NULL;
terrno = TSDB_CODE_SUCCESS; terrno = TSDB_CODE_SUCCESS;
OperatorFn(pLeft, pRight, output, TSDB_ORDER_ASC); OperatorFn(pLeft, pRight, output, TSDB_ORDER_ASC);
...@@ -692,7 +698,7 @@ _return: ...@@ -692,7 +698,7 @@ _return:
SCL_RET(code); SCL_RET(code);
} }
EDealRes sclRewriteNullInOptr(SNode** pNode, SScalarCtx *ctx, EOperatorType opType) { EDealRes sclRewriteNullInOptr(SNode **pNode, SScalarCtx *ctx, EOperatorType opType) {
if (opType <= OP_TYPE_CALC_MAX) { if (opType <= OP_TYPE_CALC_MAX) {
SValueNode *res = (SValueNode *)nodesMakeNode(QUERY_NODE_VALUE); SValueNode *res = (SValueNode *)nodesMakeNode(QUERY_NODE_VALUE);
if (NULL == res) { if (NULL == res) {
...@@ -704,7 +710,7 @@ EDealRes sclRewriteNullInOptr(SNode** pNode, SScalarCtx *ctx, EOperatorType opTy ...@@ -704,7 +710,7 @@ EDealRes sclRewriteNullInOptr(SNode** pNode, SScalarCtx *ctx, EOperatorType opTy
res->node.resType.type = TSDB_DATA_TYPE_NULL; res->node.resType.type = TSDB_DATA_TYPE_NULL;
nodesDestroyNode(*pNode); nodesDestroyNode(*pNode);
*pNode = (SNode*)res; *pNode = (SNode *)res;
} else { } else {
SValueNode *res = (SValueNode *)nodesMakeNode(QUERY_NODE_VALUE); SValueNode *res = (SValueNode *)nodesMakeNode(QUERY_NODE_VALUE);
if (NULL == res) { if (NULL == res) {
...@@ -718,17 +724,17 @@ EDealRes sclRewriteNullInOptr(SNode** pNode, SScalarCtx *ctx, EOperatorType opTy ...@@ -718,17 +724,17 @@ EDealRes sclRewriteNullInOptr(SNode** pNode, SScalarCtx *ctx, EOperatorType opTy
res->datum.b = false; res->datum.b = false;
nodesDestroyNode(*pNode); nodesDestroyNode(*pNode);
*pNode = (SNode*)res; *pNode = (SNode *)res;
} }
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
EDealRes sclAggFuncWalker(SNode* pNode, void* pContext) { EDealRes sclAggFuncWalker(SNode *pNode, void *pContext) {
if (QUERY_NODE_FUNCTION == nodeType(pNode)) { if (QUERY_NODE_FUNCTION == nodeType(pNode)) {
SFunctionNode* pFunc = (SFunctionNode*)pNode; SFunctionNode *pFunc = (SFunctionNode *)pNode;
*(bool*)pContext = fmIsAggFunc(pFunc->funcId); *(bool *)pContext = fmIsAggFunc(pFunc->funcId);
if (*(bool*)pContext) { if (*(bool *)pContext) {
return DEAL_RES_END; return DEAL_RES_END;
} }
} }
...@@ -736,27 +742,26 @@ EDealRes sclAggFuncWalker(SNode* pNode, void* pContext) { ...@@ -736,27 +742,26 @@ 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);
return aggFunc; return aggFunc;
} }
EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) { EDealRes sclRewriteNonConstOperator(SNode **pNode, SScalarCtx *ctx) {
SOperatorNode *node = (SOperatorNode *)*pNode; SOperatorNode *node = (SOperatorNode *)*pNode;
int32_t code = 0; int32_t code = 0;
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;
return DEAL_RES_ERROR; return DEAL_RES_ERROR;
...@@ -770,14 +775,14 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) { ...@@ -770,14 +775,14 @@ 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;
return DEAL_RES_ERROR; return DEAL_RES_ERROR;
...@@ -791,13 +796,13 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) { ...@@ -791,13 +796,13 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) {
if (node->pRight && (QUERY_NODE_NODE_LIST == nodeType(node->pRight))) { if (node->pRight && (QUERY_NODE_NODE_LIST == nodeType(node->pRight))) {
SNodeListNode *listNode = (SNodeListNode *)node->pRight; SNodeListNode *listNode = (SNodeListNode *)node->pRight;
SNode* tnode = NULL; SNode *tnode = NULL;
WHERE_EACH(tnode, listNode->pNodeList) { WHERE_EACH(tnode, listNode->pNodeList) {
if (SCL_IS_NULL_VALUE_NODE(tnode)) { if (SCL_IS_NULL_VALUE_NODE(tnode)) {
if (node->opType == OP_TYPE_IN) { if (node->opType == OP_TYPE_IN) {
ERASE_NODE(listNode->pNodeList); ERASE_NODE(listNode->pNodeList);
continue; continue;
} else { //OP_TYPE_NOT_IN } else { // OP_TYPE_NOT_IN
return sclRewriteNullInOptr(pNode, ctx, node->opType); return sclRewriteNullInOptr(pNode, ctx, node->opType);
} }
} }
...@@ -813,9 +818,9 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) { ...@@ -813,9 +818,9 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { EDealRes sclRewriteFunction(SNode **pNode, SScalarCtx *ctx) {
SFunctionNode *node = (SFunctionNode *)*pNode; SFunctionNode *node = (SFunctionNode *)*pNode;
SNode* tnode = NULL; SNode *tnode = NULL;
if (!fmIsScalarFunc(node->funcId) && (!ctx->dual)) { if (!fmIsScalarFunc(node->funcId) && (!ctx->dual)) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
...@@ -851,12 +856,12 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { ...@@ -851,12 +856,12 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
res->isNull = true; res->isNull = true;
} else { } else {
int32_t type = output.columnData->info.type; int32_t type = output.columnData->info.type;
if (type == TSDB_DATA_TYPE_JSON){ if (type == TSDB_DATA_TYPE_JSON) {
int32_t len = getJsonValueLen(output.columnData->pData); int32_t len = getJsonValueLen(output.columnData->pData);
res->datum.p = taosMemoryCalloc(len, 1); res->datum.p = taosMemoryCalloc(len, 1);
memcpy(res->datum.p, output.columnData->pData, len); memcpy(res->datum.p, output.columnData->pData, len);
} else if (IS_VAR_DATA_TYPE(type)) { } else if (IS_VAR_DATA_TYPE(type)) {
//res->datum.p = taosMemoryCalloc(res->node.resType.bytes + VARSTR_HEADER_SIZE + 1, 1); // res->datum.p = taosMemoryCalloc(res->node.resType.bytes + VARSTR_HEADER_SIZE + 1, 1);
res->datum.p = taosMemoryCalloc(varDataTLen(output.columnData->pData) + 1, 1); res->datum.p = taosMemoryCalloc(varDataTLen(output.columnData->pData) + 1, 1);
res->node.resType.bytes = varDataTLen(output.columnData->pData); res->node.resType.bytes = varDataTLen(output.columnData->pData);
memcpy(res->datum.p, output.columnData->pData, varDataTLen(output.columnData->pData)); memcpy(res->datum.p, output.columnData->pData, varDataTLen(output.columnData->pData));
...@@ -866,13 +871,13 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { ...@@ -866,13 +871,13 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
} }
nodesDestroyNode(*pNode); nodesDestroyNode(*pNode);
*pNode = (SNode*)res; *pNode = (SNode *)res;
sclFreeParam(&output); sclFreeParam(&output);
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) { EDealRes sclRewriteLogic(SNode **pNode, SScalarCtx *ctx) {
SLogicConditionNode *node = (SLogicConditionNode *)*pNode; SLogicConditionNode *node = (SLogicConditionNode *)*pNode;
SScalarParam output = {0}; SScalarParam output = {0};
...@@ -905,13 +910,13 @@ EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) { ...@@ -905,13 +910,13 @@ EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) {
} }
nodesDestroyNode(*pNode); nodesDestroyNode(*pNode);
*pNode = (SNode*)res; *pNode = (SNode *)res;
sclFreeParam(&output); sclFreeParam(&output);
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) { EDealRes sclRewriteOperator(SNode **pNode, SScalarCtx *ctx) {
SOperatorNode *node = (SOperatorNode *)*pNode; SOperatorNode *node = (SOperatorNode *)*pNode;
if ((!SCL_IS_CONST_NODE(node->pLeft)) || (!SCL_IS_CONST_NODE(node->pRight))) { if ((!SCL_IS_CONST_NODE(node->pLeft)) || (!SCL_IS_CONST_NODE(node->pRight))) {
...@@ -949,13 +954,13 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) { ...@@ -949,13 +954,13 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) {
} }
nodesDestroyNode(*pNode); nodesDestroyNode(*pNode);
*pNode = (SNode*)res; *pNode = (SNode *)res;
sclFreeParam(&output); sclFreeParam(&output);
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) { EDealRes sclConstantsRewriter(SNode **pNode, void *pContext) {
SScalarCtx *ctx = (SScalarCtx *)pContext; SScalarCtx *ctx = (SScalarCtx *)pContext;
if (QUERY_NODE_FUNCTION == nodeType(*pNode)) { if (QUERY_NODE_FUNCTION == nodeType(*pNode)) {
...@@ -973,7 +978,7 @@ EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) { ...@@ -973,7 +978,7 @@ EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) { EDealRes sclWalkFunction(SNode *pNode, SScalarCtx *ctx) {
SFunctionNode *node = (SFunctionNode *)pNode; SFunctionNode *node = (SFunctionNode *)pNode;
SScalarParam output = {0}; SScalarParam output = {0};
...@@ -990,7 +995,7 @@ EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) { ...@@ -990,7 +995,7 @@ EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
EDealRes sclWalkLogic(SNode* pNode, SScalarCtx *ctx) { EDealRes sclWalkLogic(SNode *pNode, SScalarCtx *ctx) {
SLogicConditionNode *node = (SLogicConditionNode *)pNode; SLogicConditionNode *node = (SLogicConditionNode *)pNode;
SScalarParam output = {0}; SScalarParam output = {0};
...@@ -1007,7 +1012,7 @@ EDealRes sclWalkLogic(SNode* pNode, SScalarCtx *ctx) { ...@@ -1007,7 +1012,7 @@ EDealRes sclWalkLogic(SNode* pNode, SScalarCtx *ctx) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
EDealRes sclWalkOperator(SNode* pNode, SScalarCtx *ctx) { EDealRes sclWalkOperator(SNode *pNode, SScalarCtx *ctx) {
SOperatorNode *node = (SOperatorNode *)pNode; SOperatorNode *node = (SOperatorNode *)pNode;
SScalarParam output = {0}; SScalarParam output = {0};
...@@ -1024,18 +1029,19 @@ EDealRes sclWalkOperator(SNode* pNode, SScalarCtx *ctx) { ...@@ -1024,18 +1029,19 @@ EDealRes sclWalkOperator(SNode* pNode, SScalarCtx *ctx) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) { 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;
} }
int32_t index = -1; int32_t index = -1;
for(int32_t i = 0; i < taosArrayGetSize(ctx->pBlockList); ++i) { for (int32_t i = 0; i < taosArrayGetSize(ctx->pBlockList); ++i) {
SSDataBlock* pb = taosArrayGetP(ctx->pBlockList, i); SSDataBlock *pb = taosArrayGetP(ctx->pBlockList, i);
if (pb->info.blockId == target->dataBlockId) { if (pb->info.blockId == target->dataBlockId) {
index = i; index = i;
break; break;
...@@ -1043,7 +1049,8 @@ EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) { ...@@ -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) { ...@@ -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;
} }
...@@ -1074,8 +1082,9 @@ EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) { ...@@ -1074,8 +1082,9 @@ EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
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;
} }
...@@ -1102,7 +1111,7 @@ EDealRes sclCalcWalker(SNode* pNode, void* pContext) { ...@@ -1102,7 +1111,7 @@ EDealRes sclCalcWalker(SNode* pNode, void* pContext) {
} }
int32_t sclExtendResRows(SScalarParam *pDst, SScalarParam *pSrc, SArray *pBlockList) { int32_t sclExtendResRows(SScalarParam *pDst, SScalarParam *pSrc, SArray *pBlockList) {
SSDataBlock* pb = taosArrayGetP(pBlockList, 0); SSDataBlock *pb = taosArrayGetP(pBlockList, 0);
SScalarParam *pLeft = taosMemoryCalloc(1, sizeof(SScalarParam)); SScalarParam *pLeft = taosMemoryCalloc(1, sizeof(SScalarParam));
if (NULL == pLeft) { if (NULL == pLeft) {
sclError("calloc %d failed", (int32_t)sizeof(SScalarParam)); sclError("calloc %d failed", (int32_t)sizeof(SScalarParam));
...@@ -1144,8 +1153,8 @@ _return: ...@@ -1144,8 +1153,8 @@ _return:
return code; return code;
} }
static int32_t sclGetMinusOperatorResType(SOperatorNode* pOp) { static int32_t sclGetMinusOperatorResType(SOperatorNode *pOp) {
if (!IS_MATHABLE_TYPE(((SExprNode*)(pOp->pLeft))->resType.type)) { if (!IS_MATHABLE_TYPE(((SExprNode *)(pOp->pLeft))->resType.type)) {
return TSDB_CODE_TSC_INVALID_OPERATION; return TSDB_CODE_TSC_INVALID_OPERATION;
} }
pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE; pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE;
...@@ -1153,9 +1162,9 @@ static int32_t sclGetMinusOperatorResType(SOperatorNode* pOp) { ...@@ -1153,9 +1162,9 @@ static int32_t sclGetMinusOperatorResType(SOperatorNode* pOp) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t sclGetMathOperatorResType(SOperatorNode* pOp) { static int32_t sclGetMathOperatorResType(SOperatorNode *pOp) {
SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType; SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType;
SDataType rdt = ((SExprNode*)(pOp->pRight))->resType; SDataType rdt = ((SExprNode *)(pOp->pRight))->resType;
if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_TIMESTAMP == rdt.type) || if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_TIMESTAMP == rdt.type) ||
(TSDB_DATA_TYPE_TIMESTAMP == ldt.type && (IS_VAR_DATA_TYPE(rdt.type) || IS_FLOAT_TYPE(rdt.type))) || (TSDB_DATA_TYPE_TIMESTAMP == ldt.type && (IS_VAR_DATA_TYPE(rdt.type) || IS_FLOAT_TYPE(rdt.type))) ||
(TSDB_DATA_TYPE_TIMESTAMP == rdt.type && (IS_VAR_DATA_TYPE(ldt.type) || IS_FLOAT_TYPE(ldt.type)))) { (TSDB_DATA_TYPE_TIMESTAMP == rdt.type && (IS_VAR_DATA_TYPE(ldt.type) || IS_FLOAT_TYPE(ldt.type)))) {
...@@ -1175,12 +1184,12 @@ static int32_t sclGetMathOperatorResType(SOperatorNode* pOp) { ...@@ -1175,12 +1184,12 @@ static int32_t sclGetMathOperatorResType(SOperatorNode* pOp) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t sclGetCompOperatorResType(SOperatorNode* pOp) { static int32_t sclGetCompOperatorResType(SOperatorNode *pOp) {
SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType; SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType;
if (OP_TYPE_IN == pOp->opType || OP_TYPE_NOT_IN == pOp->opType) { if (OP_TYPE_IN == pOp->opType || OP_TYPE_NOT_IN == pOp->opType) {
((SExprNode*)(pOp->pRight))->resType = ldt; ((SExprNode *)(pOp->pRight))->resType = ldt;
} else if (nodesIsRegularOp(pOp)) { } else if (nodesIsRegularOp(pOp)) {
SDataType rdt = ((SExprNode*)(pOp->pRight))->resType; SDataType rdt = ((SExprNode *)(pOp->pRight))->resType;
if (!IS_VAR_DATA_TYPE(ldt.type) || QUERY_NODE_VALUE != nodeType(pOp->pRight) || if (!IS_VAR_DATA_TYPE(ldt.type) || QUERY_NODE_VALUE != nodeType(pOp->pRight) ||
(!IS_STR_DATA_TYPE(rdt.type) && (rdt.type != TSDB_DATA_TYPE_NULL))) { (!IS_STR_DATA_TYPE(rdt.type) && (rdt.type != TSDB_DATA_TYPE_NULL))) {
return TSDB_CODE_TSC_INVALID_OPERATION; return TSDB_CODE_TSC_INVALID_OPERATION;
...@@ -1191,9 +1200,9 @@ static int32_t sclGetCompOperatorResType(SOperatorNode* pOp) { ...@@ -1191,9 +1200,9 @@ static int32_t sclGetCompOperatorResType(SOperatorNode* pOp) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t sclGetJsonOperatorResType(SOperatorNode* pOp) { static int32_t sclGetJsonOperatorResType(SOperatorNode *pOp) {
SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType; SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType;
SDataType rdt = ((SExprNode*)(pOp->pRight))->resType; SDataType rdt = ((SExprNode *)(pOp->pRight))->resType;
if (TSDB_DATA_TYPE_JSON != ldt.type || !IS_STR_DATA_TYPE(rdt.type)) { if (TSDB_DATA_TYPE_JSON != ldt.type || !IS_STR_DATA_TYPE(rdt.type)) {
return TSDB_CODE_TSC_INVALID_OPERATION; return TSDB_CODE_TSC_INVALID_OPERATION;
} }
...@@ -1206,20 +1215,15 @@ static int32_t sclGetJsonOperatorResType(SOperatorNode* pOp) { ...@@ -1206,20 +1215,15 @@ static int32_t sclGetJsonOperatorResType(SOperatorNode* pOp) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t sclGetBitwiseOperatorResType(SOperatorNode* pOp) { static int32_t sclGetBitwiseOperatorResType(SOperatorNode *pOp) {
pOp->node.resType.type = TSDB_DATA_TYPE_BIGINT; pOp->node.resType.type = TSDB_DATA_TYPE_BIGINT;
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes; pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes;
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) {
...@@ -1264,9 +1268,9 @@ _return: ...@@ -1264,9 +1268,9 @@ _return:
return code; return code;
} }
int32_t scalarGetOperatorResultType(SOperatorNode* pOp) { int32_t scalarGetOperatorResultType(SOperatorNode *pOp) {
if (TSDB_DATA_TYPE_BLOB == ((SExprNode*)(pOp->pLeft))->resType.type || if (TSDB_DATA_TYPE_BLOB == ((SExprNode *)(pOp->pLeft))->resType.type ||
(NULL != pOp->pRight && TSDB_DATA_TYPE_BLOB == ((SExprNode*)(pOp->pRight))->resType.type)) { (NULL != pOp->pRight && TSDB_DATA_TYPE_BLOB == ((SExprNode *)(pOp->pRight))->resType.type)) {
return TSDB_CODE_TSC_INVALID_OPERATION; return TSDB_CODE_TSC_INVALID_OPERATION;
} }
...@@ -1280,7 +1284,7 @@ int32_t scalarGetOperatorResultType(SOperatorNode* pOp) { ...@@ -1280,7 +1284,7 @@ int32_t scalarGetOperatorResultType(SOperatorNode* pOp) {
case OP_TYPE_MINUS: case OP_TYPE_MINUS:
return sclGetMinusOperatorResType(pOp); return sclGetMinusOperatorResType(pOp);
case OP_TYPE_ASSIGN: case OP_TYPE_ASSIGN:
pOp->node.resType = ((SExprNode*)(pOp->pLeft))->resType; pOp->node.resType = ((SExprNode *)(pOp->pLeft))->resType;
break; break;
case OP_TYPE_BIT_AND: case OP_TYPE_BIT_AND:
case OP_TYPE_BIT_OR: case OP_TYPE_BIT_OR:
......
#include "cJSON.h"
#include "function.h" #include "function.h"
#include "scalar.h" #include "scalar.h"
#include "sclInt.h" #include "sclInt.h"
...@@ -5,20 +6,17 @@ ...@@ -5,20 +6,17 @@
#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);
typedef double (*_double_fn)(double); typedef double (*_double_fn)(double);
typedef double (*_double_fn_2)(double, double); typedef double (*_double_fn_2)(double, double);
typedef int (*_conv_fn)(int); typedef int (*_conv_fn)(int);
typedef void (*_trim_fn)(char *, char*, int32_t, int32_t); 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);
...@@ -47,7 +45,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu ...@@ -47,7 +45,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu
colDataAppendNULL(pOutputData, i); colDataAppendNULL(pOutputData, i);
continue; continue;
} }
out[i] = (in[i] >= 0)? in[i] : -in[i]; out[i] = (in[i] >= 0) ? in[i] : -in[i];
} }
break; break;
} }
...@@ -60,7 +58,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu ...@@ -60,7 +58,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu
colDataAppendNULL(pOutputData, i); colDataAppendNULL(pOutputData, i);
continue; continue;
} }
out[i] = (in[i] >= 0)? in[i] : -in[i]; out[i] = (in[i] >= 0) ? in[i] : -in[i];
} }
break; break;
} }
...@@ -73,7 +71,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu ...@@ -73,7 +71,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu
colDataAppendNULL(pOutputData, i); colDataAppendNULL(pOutputData, i);
continue; continue;
} }
out[i] = (in[i] >= 0)? in[i] : -in[i]; out[i] = (in[i] >= 0) ? in[i] : -in[i];
} }
break; break;
} }
...@@ -86,7 +84,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu ...@@ -86,7 +84,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu
colDataAppendNULL(pOutputData, i); colDataAppendNULL(pOutputData, i);
continue; continue;
} }
out[i] = (in[i] >= 0)? in[i] : -in[i]; out[i] = (in[i] >= 0) ? in[i] : -in[i];
} }
break; break;
} }
...@@ -99,7 +97,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu ...@@ -99,7 +97,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu
colDataAppendNULL(pOutputData, i); colDataAppendNULL(pOutputData, i);
continue; continue;
} }
out[i] = (in[i] >= 0)? in[i] : -in[i]; out[i] = (in[i] >= 0) ? in[i] : -in[i];
} }
break; break;
} }
...@@ -112,7 +110,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu ...@@ -112,7 +110,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu
colDataAppendNULL(pOutputData, i); colDataAppendNULL(pOutputData, i);
continue; continue;
} }
out[i] = (in[i] >= 0)? in[i] : -in[i]; out[i] = (in[i] >= 0) ? in[i] : -in[i];
} }
break; break;
} }
...@@ -133,7 +131,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu ...@@ -133,7 +131,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t doScalarFunctionUnique(SScalarParam *pInput, int32_t inputNum, SScalarParam* pOutput, _double_fn valFn) { static int32_t doScalarFunctionUnique(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _double_fn valFn) {
int32_t type = GET_PARAM_TYPE(pInput); int32_t type = GET_PARAM_TYPE(pInput);
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
...@@ -160,28 +158,26 @@ static int32_t doScalarFunctionUnique(SScalarParam *pInput, int32_t inputNum, SS ...@@ -160,28 +158,26 @@ 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];
for (int32_t i = 0; i < inputNum; ++i) { for (int32_t i = 0; i < inputNum; ++i) {
pInputData[i] = pInput[i].columnData; pInputData[i] = pInput[i].columnData;
getValueFn[i]= getVectorDoubleValueFn(GET_PARAM_TYPE(&pInput[i])); getValueFn[i] = getVectorDoubleValueFn(GET_PARAM_TYPE(&pInput[i]));
} }
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;
} }
...@@ -192,7 +188,7 @@ static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, S ...@@ -192,7 +188,7 @@ static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, S
out[i] = result; out[i] = result;
} }
} }
} else if (pInput[0].numOfRows == 1) { //left operand is constant } else if (pInput[0].numOfRows == 1) { // left operand is constant
if (colDataIsNull_s(pInputData[0], 0) || hasNullType) { if (colDataIsNull_s(pInputData[0], 0) || hasNullType) {
colDataAppendNNULL(pOutputData, 0, pInput[1].numOfRows); colDataAppendNNULL(pOutputData, 0, pInput[1].numOfRows);
} else { } else {
...@@ -236,7 +232,8 @@ static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, S ...@@ -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,14 +285,12 @@ static int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP ...@@ -288,14 +285,12 @@ 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) {
return varDataLen(input); return varDataLen(input);
} else { //NCHAR } else { // NCHAR
return varDataLen(input) / TSDB_NCHAR_SIZE; return varDataLen(input) / TSDB_NCHAR_SIZE;
} }
} }
...@@ -309,7 +304,7 @@ static void tltrim(char *input, char *output, int32_t type, int32_t charLen) { ...@@ -309,7 +304,7 @@ static void tltrim(char *input, char *output, int32_t type, int32_t charLen) {
} }
numOfSpaces++; numOfSpaces++;
} }
} else { //NCHAR } else { // NCHAR
for (int32_t i = 0; i < charLen; ++i) { for (int32_t i = 0; i < charLen; ++i) {
if (!iswspace(*((uint32_t *)varDataVal(input) + i))) { if (!iswspace(*((uint32_t *)varDataVal(input) + i))) {
break; break;
...@@ -339,7 +334,7 @@ static void trtrim(char *input, char *output, int32_t type, int32_t charLen) { ...@@ -339,7 +334,7 @@ static void trtrim(char *input, char *output, int32_t type, int32_t charLen) {
} }
numOfSpaces++; numOfSpaces++;
} }
} else { //NCHAR } else { // NCHAR
for (int32_t i = charLen - 1; i >= 0; --i) { for (int32_t i = charLen - 1; i >= 0; --i) {
if (!iswspace(*((uint32_t *)varDataVal(input) + i))) { if (!iswspace(*((uint32_t *)varDataVal(input) + i))) {
break; break;
...@@ -451,8 +446,7 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu ...@@ -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 ...@@ -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: ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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,9 +542,8 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p ...@@ -551,9 +542,8 @@ 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);
ret = concatCopyHelper(sep, output, hasNchar, GET_PARAM_TYPE(&pInput[0]), &dataLen); ret = concatCopyHelper(sep, output, hasNchar, GET_PARAM_TYPE(&pInput[0]), &dataLen);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
...@@ -604,7 +594,7 @@ static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScala ...@@ -604,7 +594,7 @@ static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScala
for (int32_t j = 0; j < len; ++j) { for (int32_t j = 0; j < len; ++j) {
*(varDataVal(output) + j) = convFn(*(varDataVal(input) + j)); *(varDataVal(output) + j) = convFn(*(varDataVal(input) + j));
} }
} else { //NCHAR } else { // NCHAR
for (int32_t j = 0; j < len / TSDB_NCHAR_SIZE; ++j) { for (int32_t j = 0; j < len / TSDB_NCHAR_SIZE; ++j) {
*((uint32_t *)varDataVal(output) + j) = convFn(*((uint32_t *)varDataVal(input) + j)); *((uint32_t *)varDataVal(output) + j) = convFn(*((uint32_t *)varDataVal(input) + j));
} }
...@@ -620,7 +610,6 @@ static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScala ...@@ -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 ...@@ -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);
} }
...@@ -692,7 +682,7 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu ...@@ -692,7 +682,7 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
} }
varDataSetLen(output, resLen); varDataSetLen(output, resLen);
colDataAppend(pOutputData, i , output, false); colDataAppend(pOutputData, i, output, false);
output += varDataTLen(output); output += varDataTLen(output);
} }
...@@ -710,8 +700,8 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp ...@@ -710,8 +700,8 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
int64_t outputLen = GET_PARAM_BYTES(&pOutput[0]); int64_t outputLen = GET_PARAM_BYTES(&pOutput[0]);
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
char * convBuf = taosMemoryMalloc(inputLen); char *convBuf = taosMemoryMalloc(inputLen);
char * output = taosMemoryCalloc(1, outputLen + TSDB_NCHAR_SIZE); char *output = taosMemoryCalloc(1, outputLen + TSDB_NCHAR_SIZE);
char buf[400] = {0}; char buf[400] = {0};
if (convBuf == NULL || output == NULL) { if (convBuf == NULL || output == NULL) {
...@@ -727,7 +717,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp ...@@ -727,7 +717,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
char *input = colDataGetData(pInput[0].columnData, i); char *input = colDataGetData(pInput[0].columnData, i);
switch(outputType) { switch (outputType) {
case TSDB_DATA_TYPE_TINYINT: { case TSDB_DATA_TYPE_TINYINT: {
if (inputType == TSDB_DATA_TYPE_BINARY) { if (inputType == TSDB_DATA_TYPE_BINARY) {
memcpy(buf, varDataVal(input), varDataLen(input)); memcpy(buf, varDataVal(input), varDataLen(input));
...@@ -948,7 +938,8 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp ...@@ -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);
...@@ -977,7 +968,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp ...@@ -977,7 +968,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
int32_t len; int32_t len;
if (inputType == TSDB_DATA_TYPE_BOOL) { if (inputType == TSDB_DATA_TYPE_BOOL) {
char tmp[8] = {0}; char tmp[8] = {0};
len = sprintf(tmp, "%.*s", outputCharLen, *(int8_t *)input ? "true" : "false" ); len = sprintf(tmp, "%.*s", outputCharLen, *(int8_t *)input ? "true" : "false");
bool ret = taosMbsToUcs4(tmp, len, (TdUcs4 *)varDataVal(output), outputLen - VARSTR_HEADER_SIZE, &len); bool ret = taosMbsToUcs4(tmp, len, (TdUcs4 *)varDataVal(output), outputLen - VARSTR_HEADER_SIZE, &len);
if (!ret) { if (!ret) {
code = TSDB_CODE_FAILED; code = TSDB_CODE_FAILED;
...@@ -987,7 +978,8 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp ...@@ -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;
...@@ -1009,7 +1001,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp ...@@ -1009,7 +1001,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
varDataSetLen(output, len); varDataSetLen(output, len);
} }
//for constant conversion, need to set proper length of pOutput description // for constant conversion, need to set proper length of pOutput description
if (len < outputLen) { if (len < outputLen) {
pOutput->columnData->info.bytes = len + VARSTR_HEADER_SIZE; pOutput->columnData->info.bytes = len + VARSTR_HEADER_SIZE;
} }
...@@ -1027,7 +1019,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp ...@@ -1027,7 +1019,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
pOutput->numOfRows = pInput->numOfRows; pOutput->numOfRows = pInput->numOfRows;
_end: _end:
taosMemoryFree(output); taosMemoryFree(output);
taosMemoryFree(convBuf); taosMemoryFree(convBuf);
return code; return code;
...@@ -1037,7 +1029,7 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam * ...@@ -1037,7 +1029,7 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *
int32_t type = GET_PARAM_TYPE(pInput); int32_t type = GET_PARAM_TYPE(pInput);
bool tzPresent = (inputNum == 2) ? true : false; bool tzPresent = (inputNum == 2) ? true : false;
char* tz; char *tz;
int32_t tzLen; int32_t tzLen;
if (tzPresent) { if (tzPresent) {
tz = varDataVal(pInput[1].columnData->pData); tz = varDataVal(pInput[1].columnData->pData);
...@@ -1079,7 +1071,7 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam * ...@@ -1079,7 +1071,7 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *
strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S", &tmInfo); strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S", &tmInfo);
int32_t len = (int32_t)strlen(buf); int32_t len = (int32_t)strlen(buf);
//add timezone string // add timezone string
snprintf(buf + len, tzLen + 1, "%s", tz); snprintf(buf + len, tzLen + 1, "%s", tz);
len += tzLen; len += tzLen;
...@@ -1095,7 +1087,7 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam * ...@@ -1095,7 +1087,7 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *
if (tzInfo) { if (tzInfo) {
memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo)); memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo));
} else { } else {
//search '-' backwards // search '-' backwards
tzInfo = strrchr(buf, '-'); tzInfo = strrchr(buf, '-');
if (tzInfo) { if (tzInfo) {
memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo)); memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo));
...@@ -1151,25 +1143,25 @@ int32_t toJsonFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu ...@@ -1151,25 +1143,25 @@ int32_t toJsonFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
char tmp[TSDB_MAX_JSON_TAG_LEN] = {0}; char tmp[TSDB_MAX_JSON_TAG_LEN] = {0};
for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { for (int32_t i = 0; i < pInput[0].numOfRows; ++i) {
SArray* pTagVals = taosArrayInit(8, sizeof(STagVal)); SArray *pTagVals = taosArrayInit(8, sizeof(STagVal));
STag* pTag = NULL; STag *pTag = NULL;
if (colDataIsNull_s(pInput[0].columnData, i)) { if (colDataIsNull_s(pInput[0].columnData, i)) {
tTagNew(pTagVals, 1, true, &pTag); tTagNew(pTagVals, 1, true, &pTag);
}else{ } else {
char *input = pInput[0].columnData->pData + pInput[0].columnData->varmeta.offset[i]; char *input = pInput[0].columnData->pData + pInput[0].columnData->varmeta.offset[i];
if (varDataLen(input) > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE){ if (varDataLen(input) > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
taosArrayDestroy(pTagVals); taosArrayDestroy(pTagVals);
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
memcpy(tmp, varDataVal(input), varDataLen(input)); memcpy(tmp, varDataVal(input), varDataLen(input));
tmp[varDataLen(input)] = 0; tmp[varDataLen(input)] = 0;
if(parseJsontoTagData(tmp, pTagVals, &pTag, NULL)){ if (parseJsontoTagData(tmp, pTagVals, &pTag, NULL)) {
tTagNew(pTagVals, 1, true, &pTag); tTagNew(pTagVals, 1, true, &pTag);
} }
} }
colDataAppend(pOutput->columnData, i, (const char*)pTag, false); colDataAppend(pOutput->columnData, i, (const char *)pTag, false);
tTagFree(pTag); tTagFree(pTag);
taosArrayDestroy(pTagVals); taosArrayDestroy(pTagVals);
} }
...@@ -1186,8 +1178,8 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara ...@@ -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;
...@@ -1205,7 +1197,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara ...@@ -1205,7 +1197,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
colDataAppendNULL(pOutput->columnData, i); colDataAppendNULL(pOutput->columnData, i);
continue; continue;
} }
//If converted value is less than 10digits in second, use value in second instead // If converted value is less than 10digits in second, use value in second instead
int64_t timeValSec = timeVal / 1000000000; int64_t timeValSec = timeVal / 1000000000;
if (timeValSec < 1000000000) { if (timeValSec < 1000000000) {
timeVal = timeValSec; timeVal = timeValSec;
...@@ -1246,7 +1238,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara ...@@ -1246,7 +1238,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
timeVal = timeVal / 1000 * 1000; timeVal = timeVal / 1000 * 1000;
} else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) {
timeVal = timeVal / 1000000 * 1000000; timeVal = timeVal / 1000000 * 1000000;
} else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS){ } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) {
timeVal = timeVal * factor; timeVal = timeVal * factor;
} else { } else {
colDataAppendNULL(pOutput->columnData, i); colDataAppendNULL(pOutput->columnData, i);
...@@ -1307,7 +1299,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara ...@@ -1307,7 +1299,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
} else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) {
timeVal = timeVal / 1000000000 / 86400 * 86400 * 1000000000; timeVal = timeVal / 1000000000 / 86400 * 86400 * 1000000000;
} else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) { } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) {
timeVal = timeVal * factor / factor / 86400* 86400 * factor; timeVal = timeVal * factor / factor / 86400 * 86400 * factor;
} else { } else {
colDataAppendNULL(pOutput->columnData, i); colDataAppendNULL(pOutput->columnData, i);
continue; continue;
...@@ -1322,7 +1314,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara ...@@ -1322,7 +1314,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
} else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) {
timeVal = timeVal / 1000000000 / 604800 * 604800 * 1000000000; timeVal = timeVal / 1000000000 / 604800 * 604800 * 1000000000;
} else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) { } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) {
timeVal = timeVal * factor / factor / 604800 * 604800* factor; timeVal = timeVal * factor / factor / 604800 * 604800 * factor;
} else { } else {
colDataAppendNULL(pOutput->columnData, i); colDataAppendNULL(pOutput->columnData, i);
continue; continue;
...@@ -1335,7 +1327,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara ...@@ -1335,7 +1327,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
} }
} }
//truncate the timestamp to db precision // truncate the timestamp to db precision
switch (timePrec) { switch (timePrec) {
case TSDB_TIME_PRECISION_MILLI: { case TSDB_TIME_PRECISION_MILLI: {
if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) {
...@@ -1380,8 +1372,8 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p ...@@ -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,11 +1433,10 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p ...@@ -1441,11 +1433,10 @@ 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) {
case TSDB_TIME_PRECISION_MILLI: { case TSDB_TIME_PRECISION_MILLI: {
result = result / 1000000; result = result / 1000000;
break; break;
...@@ -1461,7 +1452,7 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p ...@@ -1461,7 +1452,7 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
} }
} else { } else {
int64_t unit = timeUnit * 1000 / factor; int64_t unit = timeUnit * 1000 / factor;
switch(unit) { switch (unit) {
case 0: { /* 1u or 1b */ case 0: { /* 1u or 1b */
if (timePrec == TSDB_TIME_PRECISION_NANO && timeUnit == 1) { if (timePrec == TSDB_TIME_PRECISION_NANO && timeUnit == 1) {
result = result / 1; result = result / 1;
...@@ -1694,7 +1685,7 @@ static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOf ...@@ -1694,7 +1685,7 @@ static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOf
} }
#endif #endif
bool getTimePseudoFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { bool getTimePseudoFuncEnv(SFunctionNode *UNUSED_PARAM(pFunc), SFuncExecEnv *pEnv) {
pEnv->calcMemSize = sizeof(int64_t); pEnv->calcMemSize = sizeof(int64_t);
return true; return true;
} }
...@@ -1719,13 +1710,13 @@ int32_t winDurFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu ...@@ -1719,13 +1710,13 @@ int32_t winDurFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
int32_t winStartTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t winStartTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
ASSERT(inputNum == 1); ASSERT(inputNum == 1);
colDataAppendInt64(pOutput->columnData, pOutput->numOfRows, (int64_t*) colDataGetData(pInput->columnData, 3)); colDataAppendInt64(pOutput->columnData, pOutput->numOfRows, (int64_t *)colDataGetData(pInput->columnData, 3));
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t winEndTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t winEndTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
ASSERT(inputNum == 1); ASSERT(inputNum == 1);
colDataAppendInt64(pOutput->columnData, pOutput->numOfRows, (int64_t*) colDataGetData(pInput->columnData, 4)); colDataAppendInt64(pOutput->columnData, pOutput->numOfRows, (int64_t *)colDataGetData(pInput->columnData, 4));
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -1813,12 +1804,12 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS ...@@ -1813,12 +1804,12 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS
break; break;
} }
switch(type) { switch (type) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_TINYINT: { case TSDB_DATA_TYPE_TINYINT: {
int8_t *in = (int8_t *)pInputData->pData; int8_t *in = (int8_t *)pInputData->pData;
int8_t *out = (int8_t *)pOutputData->pData; int8_t *out = (int8_t *)pOutputData->pData;
if((in[i] > *out) ^ isMinFunc) { if ((in[i] > *out) ^ isMinFunc) {
*out = in[i]; *out = in[i];
} }
break; break;
...@@ -1826,7 +1817,7 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS ...@@ -1826,7 +1817,7 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS
case TSDB_DATA_TYPE_SMALLINT: { case TSDB_DATA_TYPE_SMALLINT: {
int16_t *in = (int16_t *)pInputData->pData; int16_t *in = (int16_t *)pInputData->pData;
int16_t *out = (int16_t *)pOutputData->pData; int16_t *out = (int16_t *)pOutputData->pData;
if((in[i] > *out) ^ isMinFunc) { if ((in[i] > *out) ^ isMinFunc) {
*out = in[i]; *out = in[i];
} }
break; break;
...@@ -1834,7 +1825,7 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS ...@@ -1834,7 +1825,7 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS
case TSDB_DATA_TYPE_INT: { case TSDB_DATA_TYPE_INT: {
int32_t *in = (int32_t *)pInputData->pData; int32_t *in = (int32_t *)pInputData->pData;
int32_t *out = (int32_t *)pOutputData->pData; int32_t *out = (int32_t *)pOutputData->pData;
if((in[i] > *out) ^ isMinFunc) { if ((in[i] > *out) ^ isMinFunc) {
*out = in[i]; *out = in[i];
} }
break; break;
...@@ -1842,7 +1833,7 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS ...@@ -1842,7 +1833,7 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS
case TSDB_DATA_TYPE_BIGINT: { case TSDB_DATA_TYPE_BIGINT: {
int64_t *in = (int64_t *)pInputData->pData; int64_t *in = (int64_t *)pInputData->pData;
int64_t *out = (int64_t *)pOutputData->pData; int64_t *out = (int64_t *)pOutputData->pData;
if((in[i] > *out) ^ isMinFunc) { if ((in[i] > *out) ^ isMinFunc) {
*out = in[i]; *out = in[i];
} }
break; break;
...@@ -1850,7 +1841,7 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS ...@@ -1850,7 +1841,7 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS
case TSDB_DATA_TYPE_UTINYINT: { case TSDB_DATA_TYPE_UTINYINT: {
uint8_t *in = (uint8_t *)pInputData->pData; uint8_t *in = (uint8_t *)pInputData->pData;
uint8_t *out = (uint8_t *)pOutputData->pData; uint8_t *out = (uint8_t *)pOutputData->pData;
if((in[i] > *out) ^ isMinFunc) { if ((in[i] > *out) ^ isMinFunc) {
*out = in[i]; *out = in[i];
} }
break; break;
...@@ -1858,7 +1849,7 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS ...@@ -1858,7 +1849,7 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS
case TSDB_DATA_TYPE_USMALLINT: { case TSDB_DATA_TYPE_USMALLINT: {
uint16_t *in = (uint16_t *)pInputData->pData; uint16_t *in = (uint16_t *)pInputData->pData;
uint16_t *out = (uint16_t *)pOutputData->pData; uint16_t *out = (uint16_t *)pOutputData->pData;
if((in[i] > *out) ^ isMinFunc) { if ((in[i] > *out) ^ isMinFunc) {
*out = in[i]; *out = in[i];
} }
break; break;
...@@ -1866,7 +1857,7 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS ...@@ -1866,7 +1857,7 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS
case TSDB_DATA_TYPE_UINT: { case TSDB_DATA_TYPE_UINT: {
uint32_t *in = (uint32_t *)pInputData->pData; uint32_t *in = (uint32_t *)pInputData->pData;
uint32_t *out = (uint32_t *)pOutputData->pData; uint32_t *out = (uint32_t *)pOutputData->pData;
if((in[i] > *out) ^ isMinFunc) { if ((in[i] > *out) ^ isMinFunc) {
*out = in[i]; *out = in[i];
} }
break; break;
...@@ -1874,7 +1865,7 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS ...@@ -1874,7 +1865,7 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS
case TSDB_DATA_TYPE_UBIGINT: { case TSDB_DATA_TYPE_UBIGINT: {
uint64_t *in = (uint64_t *)pInputData->pData; uint64_t *in = (uint64_t *)pInputData->pData;
uint64_t *out = (uint64_t *)pOutputData->pData; uint64_t *out = (uint64_t *)pOutputData->pData;
if((in[i] > *out) ^ isMinFunc) { if ((in[i] > *out) ^ isMinFunc) {
*out = in[i]; *out = in[i];
} }
break; break;
...@@ -1882,7 +1873,7 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS ...@@ -1882,7 +1873,7 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS
case TSDB_DATA_TYPE_FLOAT: { case TSDB_DATA_TYPE_FLOAT: {
float *in = (float *)pInputData->pData; float *in = (float *)pInputData->pData;
float *out = (float *)pOutputData->pData; float *out = (float *)pOutputData->pData;
if((in[i] > *out) ^ isMinFunc) { if ((in[i] > *out) ^ isMinFunc) {
*out = in[i]; *out = in[i];
} }
break; break;
...@@ -1890,7 +1881,7 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS ...@@ -1890,7 +1881,7 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS
case TSDB_DATA_TYPE_DOUBLE: { case TSDB_DATA_TYPE_DOUBLE: {
double *in = (double *)pInputData->pData; double *in = (double *)pInputData->pData;
double *out = (double *)pOutputData->pData; double *out = (double *)pOutputData->pData;
if((in[i] > *out) ^ isMinFunc) { if ((in[i] > *out) ^ isMinFunc) {
*out = in[i]; *out = in[i];
} }
break; break;
...@@ -1928,7 +1919,7 @@ int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam * ...@@ -1928,7 +1919,7 @@ int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *
break; break;
} }
switch(type) { switch (type) {
case TSDB_DATA_TYPE_TINYINT: { case TSDB_DATA_TYPE_TINYINT: {
int8_t *in = (int8_t *)pInputData->pData; int8_t *in = (int8_t *)pInputData->pData;
int64_t *out = (int64_t *)pOutputData->pData; int64_t *out = (int64_t *)pOutputData->pData;
...@@ -2026,7 +2017,7 @@ int32_t stddevScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara ...@@ -2026,7 +2017,7 @@ int32_t stddevScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput); int32_t type = GET_PARAM_TYPE(pInput);
//int64_t count = 0, sum = 0, qSum = 0; // int64_t count = 0, sum = 0, qSum = 0;
bool hasNull = false; bool hasNull = false;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
...@@ -2155,7 +2146,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa ...@@ -2155,7 +2146,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
int32_t type = GET_PARAM_TYPE(pInput); int32_t type = GET_PARAM_TYPE(pInput);
int64_t count = 0; int64_t count = 0;
switch(type) { switch (type) {
case TSDB_DATA_TYPE_TINYINT: { case TSDB_DATA_TYPE_TINYINT: {
int8_t *in = (int8_t *)pInputData->pData; int8_t *in = (int8_t *)pInputData->pData;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
...@@ -2292,11 +2283,10 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa ...@@ -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;
...@@ -2469,7 +2459,7 @@ typedef enum { ...@@ -2469,7 +2459,7 @@ typedef enum {
} \ } \
} while (0) } while (0)
static int8_t getStateOpType(char* opStr) { static int8_t getStateOpType(char *opStr) {
int8_t opType; int8_t opType;
if (strncasecmp(opStr, "LT", 2) == 0) { if (strncasecmp(opStr, "LT", 2) == 0) {
opType = STATE_OPER_LT; opType = STATE_OPER_LT;
...@@ -2490,58 +2480,58 @@ static int8_t getStateOpType(char* opStr) { ...@@ -2490,58 +2480,58 @@ static int8_t getStateOpType(char* opStr) {
return opType; return opType;
} }
static bool checkStateOp(int8_t op, SColumnInfoData* pCol, int32_t index, SScalarParam *pCondParam) { static bool checkStateOp(int8_t op, SColumnInfoData *pCol, int32_t index, SScalarParam *pCondParam) {
char* data = colDataGetData(pCol, index); char *data = colDataGetData(pCol, index);
char* param = pCondParam->columnData->pData; char *param = pCondParam->columnData->pData;
int32_t paramType = GET_PARAM_TYPE(pCondParam); int32_t paramType = GET_PARAM_TYPE(pCondParam);
switch (pCol->info.type) { switch (pCol->info.type) {
case TSDB_DATA_TYPE_TINYINT: { case TSDB_DATA_TYPE_TINYINT: {
int8_t v = *(int8_t*)data; int8_t v = *(int8_t *)data;
STATE_COMP(op, v, param, paramType); STATE_COMP(op, v, param, paramType);
break; break;
} }
case TSDB_DATA_TYPE_UTINYINT: { case TSDB_DATA_TYPE_UTINYINT: {
uint8_t v = *(uint8_t*)data; uint8_t v = *(uint8_t *)data;
STATE_COMP(op, v, param, paramType); STATE_COMP(op, v, param, paramType);
break; break;
} }
case TSDB_DATA_TYPE_SMALLINT: { case TSDB_DATA_TYPE_SMALLINT: {
int16_t v = *(int16_t*)data; int16_t v = *(int16_t *)data;
STATE_COMP(op, v, param, paramType); STATE_COMP(op, v, param, paramType);
break; break;
} }
case TSDB_DATA_TYPE_USMALLINT: { case TSDB_DATA_TYPE_USMALLINT: {
uint16_t v = *(uint16_t*)data; uint16_t v = *(uint16_t *)data;
STATE_COMP(op, v, param, paramType); STATE_COMP(op, v, param, paramType);
break; break;
} }
case TSDB_DATA_TYPE_INT: { case TSDB_DATA_TYPE_INT: {
int32_t v = *(int32_t*)data; int32_t v = *(int32_t *)data;
STATE_COMP(op, v, param, paramType); STATE_COMP(op, v, param, paramType);
break; break;
} }
case TSDB_DATA_TYPE_UINT: { case TSDB_DATA_TYPE_UINT: {
uint32_t v = *(uint32_t*)data; uint32_t v = *(uint32_t *)data;
STATE_COMP(op, v, param, paramType); STATE_COMP(op, v, param, paramType);
break; break;
} }
case TSDB_DATA_TYPE_BIGINT: { case TSDB_DATA_TYPE_BIGINT: {
int64_t v = *(int64_t*)data; int64_t v = *(int64_t *)data;
STATE_COMP(op, v, param, paramType); STATE_COMP(op, v, param, paramType);
break; break;
} }
case TSDB_DATA_TYPE_UBIGINT: { case TSDB_DATA_TYPE_UBIGINT: {
uint64_t v = *(uint64_t*)data; uint64_t v = *(uint64_t *)data;
STATE_COMP(op, v, param, paramType); STATE_COMP(op, v, param, paramType);
break; break;
} }
case TSDB_DATA_TYPE_FLOAT: { case TSDB_DATA_TYPE_FLOAT: {
float v = *(float*)data; float v = *(float *)data;
STATE_COMP(op, v, param, paramType); STATE_COMP(op, v, param, paramType);
break; break;
} }
case TSDB_DATA_TYPE_DOUBLE: { case TSDB_DATA_TYPE_DOUBLE: {
double v = *(double*)data; double v = *(double *)data;
STATE_COMP(op, v, param, paramType); STATE_COMP(op, v, param, paramType);
break; break;
} }
...@@ -2572,7 +2562,7 @@ int32_t stateCountScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalar ...@@ -2572,7 +2562,7 @@ int32_t stateCountScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalar
} else { } else {
count = 0; count = 0;
} }
colDataAppend(pOutputData, i, (char*)&out, false); colDataAppend(pOutputData, i, (char *)&out, false);
} }
pOutput->numOfRows = pInput->numOfRows; pOutput->numOfRows = pInput->numOfRows;
...@@ -2596,7 +2586,7 @@ int32_t stateDurationScalarFunction(SScalarParam *pInput, int32_t inputNum, SSca ...@@ -2596,7 +2586,7 @@ int32_t stateDurationScalarFunction(SScalarParam *pInput, int32_t inputNum, SSca
if (ret) { if (ret) {
out = 0; out = 0;
} }
colDataAppend(pOutputData, i, (char*)&out, false); colDataAppend(pOutputData, i, (char *)&out, false);
} }
pOutput->numOfRows = pInput->numOfRows; pOutput->numOfRows = pInput->numOfRows;
...@@ -2605,7 +2595,7 @@ int32_t stateDurationScalarFunction(SScalarParam *pInput, int32_t inputNum, SSca ...@@ -2605,7 +2595,7 @@ int32_t stateDurationScalarFunction(SScalarParam *pInput, int32_t inputNum, SSca
typedef enum { UNKNOWN_BIN = 0, USER_INPUT_BIN, LINEAR_BIN, LOG_BIN } EHistoBinType; typedef enum { UNKNOWN_BIN = 0, USER_INPUT_BIN, LINEAR_BIN, LOG_BIN } EHistoBinType;
static int8_t getHistogramBinType(char* binTypeStr) { static int8_t getHistogramBinType(char *binTypeStr) {
int8_t binType; int8_t binType;
if (strcasecmp(binTypeStr, "user_input") == 0) { if (strcasecmp(binTypeStr, "user_input") == 0) {
binType = USER_INPUT_BIN; binType = USER_INPUT_BIN;
...@@ -2627,10 +2617,11 @@ typedef struct SHistoFuncBin { ...@@ -2627,10 +2617,11 @@ 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,
cJSON* binDesc = cJSON_Parse(binDescStr); bool normalized) {
cJSON *binDesc = cJSON_Parse(binDescStr);
int32_t numOfBins; int32_t numOfBins;
double* intervals; double *intervals;
if (cJSON_IsObject(binDesc)) { /* linaer/log bins */ if (cJSON_IsObject(binDesc)) { /* linaer/log bins */
int32_t numOfParams = cJSON_GetArraySize(binDesc); int32_t numOfParams = cJSON_GetArraySize(binDesc);
int32_t startIndex; int32_t startIndex;
...@@ -2638,11 +2629,11 @@ static bool getHistogramBinDesc(SHistoFuncBin** bins, int32_t* binNum, char* bin ...@@ -2638,11 +2629,11 @@ static bool getHistogramBinDesc(SHistoFuncBin** bins, int32_t* binNum, char* bin
return false; return false;
} }
cJSON* start = cJSON_GetObjectItem(binDesc, "start"); cJSON *start = cJSON_GetObjectItem(binDesc, "start");
cJSON* factor = cJSON_GetObjectItem(binDesc, "factor"); cJSON *factor = cJSON_GetObjectItem(binDesc, "factor");
cJSON* width = cJSON_GetObjectItem(binDesc, "width"); cJSON *width = cJSON_GetObjectItem(binDesc, "width");
cJSON* count = cJSON_GetObjectItem(binDesc, "count"); cJSON *count = cJSON_GetObjectItem(binDesc, "count");
cJSON* infinity = cJSON_GetObjectItem(binDesc, "infinity"); cJSON *infinity = cJSON_GetObjectItem(binDesc, "infinity");
if (!cJSON_IsNumber(start) || !cJSON_IsNumber(count) || !cJSON_IsBool(infinity)) { if (!cJSON_IsNumber(start) || !cJSON_IsNumber(count) || !cJSON_IsBool(infinity)) {
return false; return false;
...@@ -2719,7 +2710,7 @@ static bool getHistogramBinDesc(SHistoFuncBin** bins, int32_t* binNum, char* bin ...@@ -2719,7 +2710,7 @@ static bool getHistogramBinDesc(SHistoFuncBin** bins, int32_t* binNum, char* bin
} }
numOfBins = cJSON_GetArraySize(binDesc); numOfBins = cJSON_GetArraySize(binDesc);
intervals = taosMemoryCalloc(numOfBins, sizeof(double)); intervals = taosMemoryCalloc(numOfBins, sizeof(double));
cJSON* bin = binDesc->child; cJSON *bin = binDesc->child;
if (bin == NULL) { if (bin == NULL) {
taosMemoryFree(intervals); taosMemoryFree(intervals);
return false; return false;
...@@ -2764,7 +2755,7 @@ int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP ...@@ -2764,7 +2755,7 @@ int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
int32_t totalCount = 0; int32_t totalCount = 0;
int8_t binType = getHistogramBinType(varDataVal(pInput[1].columnData->pData)); int8_t binType = getHistogramBinType(varDataVal(pInput[1].columnData->pData));
char* binDesc = varDataVal(pInput[2].columnData->pData); char *binDesc = varDataVal(pInput[2].columnData->pData);
int64_t normalized = *(int64_t *)(pInput[3].columnData->pData); int64_t normalized = *(int64_t *)(pInput[3].columnData->pData);
int32_t type = GET_PARAM_TYPE(pInput); int32_t type = GET_PARAM_TYPE(pInput);
...@@ -2777,7 +2768,7 @@ int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP ...@@ -2777,7 +2768,7 @@ int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
continue; continue;
} }
char* data = colDataGetData(pInputData, i); char *data = colDataGetData(pInputData, i);
double v; double v;
GET_TYPED_DATA(v, double, type, data); GET_TYPED_DATA(v, double, type, data);
...@@ -2804,11 +2795,11 @@ int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP ...@@ -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);
...@@ -2831,11 +2822,10 @@ int32_t selectScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara ...@@ -2831,11 +2822,10 @@ int32_t selectScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
continue; continue;
} }
char* data = colDataGetData(pInputData, i); char *data = colDataGetData(pInputData, i);
colDataAppend(pOutputData, i, data, false); colDataAppend(pOutputData, i, data, false);
} }
pOutput->numOfRows = 1; pOutput->numOfRows = 1;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
......
...@@ -24,19 +24,20 @@ ...@@ -24,19 +24,20 @@
#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))
void convertNumberToNumber(const void *inData, void *outData, int8_t inType, int8_t outType){ void convertNumberToNumber(const void *inData, void *outData, int8_t inType, int8_t outType) {
switch (outType) { switch (outType) {
case TSDB_DATA_TYPE_BOOL: { case TSDB_DATA_TYPE_BOOL: {
GET_TYPED_DATA(*((bool *)outData), bool, inType, inData); GET_TYPED_DATA(*((bool *)outData), bool, inType, inData);
...@@ -83,13 +84,13 @@ void convertNumberToNumber(const void *inData, void *outData, int8_t inType, int ...@@ -83,13 +84,13 @@ void convertNumberToNumber(const void *inData, void *outData, int8_t inType, int
GET_TYPED_DATA(*((double *)outData), double, inType, inData); GET_TYPED_DATA(*((double *)outData), double, inType, inData);
break; break;
} }
default:{ default: {
ASSERT(0); ASSERT(0);
} }
} }
} }
void convertNcharToDouble(const void *inData, void *outData){ void convertNcharToDouble(const void *inData, void *outData) {
char *tmp = taosMemoryMalloc(varDataTLen(inData)); char *tmp = taosMemoryMalloc(varDataTLen(inData));
int len = taosUcs4ToMbs((TdUcs4 *)varDataVal(inData), varDataLen(inData), tmp); int len = taosUcs4ToMbs((TdUcs4 *)varDataVal(inData), varDataLen(inData), tmp);
if (len < 0) { if (len < 0) {
...@@ -104,9 +105,9 @@ void convertNcharToDouble(const void *inData, void *outData){ ...@@ -104,9 +105,9 @@ void convertNcharToDouble(const void *inData, void *outData){
taosMemoryFreeClear(tmp); taosMemoryFreeClear(tmp);
} }
void convertBinaryToDouble(const void *inData, void *outData){ void convertBinaryToDouble(const void *inData, void *outData) {
char *tmp = taosMemoryCalloc(1, varDataTLen(inData)); char *tmp = taosMemoryCalloc(1, varDataTLen(inData));
if(tmp == NULL){ if (tmp == NULL) {
*((double *)outData) = 0.; *((double *)outData) = 0.;
return; return;
} }
...@@ -118,86 +119,64 @@ void convertBinaryToDouble(const void *inData, void *outData){ ...@@ -118,86 +119,64 @@ 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) { int64_t getVectorBigintValue_JSON(void *src, int32_t index) {
return (int64_t)*((int32_t *)src + index); ASSERT(!colDataIsNull_var(((SColumnInfoData *)src), index));
} char *data = colDataGetVarData((SColumnInfoData *)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){
ASSERT(!colDataIsNull_var(((SColumnInfoData*)src), index));
char *data = colDataGetVarData((SColumnInfoData*)src, index);
double out = 0; double out = 0;
if (*data == TSDB_DATA_TYPE_NULL){ if (*data == TSDB_DATA_TYPE_NULL) {
return 0; return 0;
} else if(*data == TSDB_DATA_TYPE_NCHAR) { // json inner type can not be BINARY } else if (*data == TSDB_DATA_TYPE_NCHAR) { // json inner type can not be BINARY
convertNcharToDouble(data+CHAR_BYTES, &out); convertNcharToDouble(data + CHAR_BYTES, &out);
} else if(tTagIsJson(data)){ } else if (tTagIsJson(data)) {
terrno = TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR; terrno = TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR;
return 0; return 0;
} else { } else {
convertNumberToNumber(data+CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE); convertNumberToNumber(data + CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE);
} }
return (int64_t)out; return (int64_t)out;
} }
_getBigintValue_fn_t getVectorBigintValueFn(int32_t srcType) { _getBigintValue_fn_t getVectorBigintValueFn(int32_t srcType) {
_getBigintValue_fn_t p = NULL; _getBigintValue_fn_t p = NULL;
if (srcType==TSDB_DATA_TYPE_TINYINT) { if (srcType == TSDB_DATA_TYPE_TINYINT) {
p = getVectorBigintValue_TINYINT; p = getVectorBigintValue_TINYINT;
} else if (srcType==TSDB_DATA_TYPE_UTINYINT) { } else if (srcType == TSDB_DATA_TYPE_UTINYINT) {
p = getVectorBigintValue_UTINYINT; p = getVectorBigintValue_UTINYINT;
} else if (srcType==TSDB_DATA_TYPE_SMALLINT) { } else if (srcType == TSDB_DATA_TYPE_SMALLINT) {
p = getVectorBigintValue_SMALLINT; p = getVectorBigintValue_SMALLINT;
} else if (srcType==TSDB_DATA_TYPE_USMALLINT) { } else if (srcType == TSDB_DATA_TYPE_USMALLINT) {
p = getVectorBigintValue_USMALLINT; p = getVectorBigintValue_USMALLINT;
} else if (srcType==TSDB_DATA_TYPE_INT) { } else if (srcType == TSDB_DATA_TYPE_INT) {
p = getVectorBigintValue_INT; p = getVectorBigintValue_INT;
} else if (srcType==TSDB_DATA_TYPE_UINT) { } else if (srcType == TSDB_DATA_TYPE_UINT) {
p = getVectorBigintValue_UINT; p = getVectorBigintValue_UINT;
} else if (srcType==TSDB_DATA_TYPE_BIGINT) { } else if (srcType == TSDB_DATA_TYPE_BIGINT) {
p = getVectorBigintValue_BIGINT; p = getVectorBigintValue_BIGINT;
} else if (srcType==TSDB_DATA_TYPE_UBIGINT) { } else if (srcType == TSDB_DATA_TYPE_UBIGINT) {
p = getVectorBigintValue_UBIGINT; p = getVectorBigintValue_UBIGINT;
} else if (srcType==TSDB_DATA_TYPE_FLOAT) { } else if (srcType == TSDB_DATA_TYPE_FLOAT) {
p = getVectorBigintValue_FLOAT; p = getVectorBigintValue_FLOAT;
} else if (srcType==TSDB_DATA_TYPE_DOUBLE) { } else if (srcType == TSDB_DATA_TYPE_DOUBLE) {
p = getVectorBigintValue_DOUBLE; p = getVectorBigintValue_DOUBLE;
} else if (srcType==TSDB_DATA_TYPE_TIMESTAMP) { } else if (srcType == TSDB_DATA_TYPE_TIMESTAMP) {
p = getVectorBigintValue_BIGINT; p = getVectorBigintValue_BIGINT;
} else if (srcType==TSDB_DATA_TYPE_BOOL) { } else if (srcType == TSDB_DATA_TYPE_BOOL) {
p = getVectorBigintValue_BOOL; p = getVectorBigintValue_BOOL;
} else if (srcType==TSDB_DATA_TYPE_JSON) { } else if (srcType == TSDB_DATA_TYPE_JSON) {
p = getVectorBigintValue_JSON; p = getVectorBigintValue_JSON;
} else if (srcType==TSDB_DATA_TYPE_NULL){ } else if (srcType == TSDB_DATA_TYPE_NULL) {
p = NULL; p = NULL;
} else { } else {
ASSERT(0); ASSERT(0);
...@@ -205,78 +184,54 @@ _getBigintValue_fn_t getVectorBigintValueFn(int32_t srcType) { ...@@ -205,78 +184,54 @@ _getBigintValue_fn_t getVectorBigintValueFn(int32_t srcType) {
return p; return p;
} }
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;
if(srcType==TSDB_DATA_TYPE_TINYINT) { if (srcType == TSDB_DATA_TYPE_TINYINT) {
p = getVectorValueAddr_TINYINT; p = getVectorValueAddr_TINYINT;
}else if(srcType==TSDB_DATA_TYPE_UTINYINT) { } else if (srcType == TSDB_DATA_TYPE_UTINYINT) {
p = getVectorValueAddr_UTINYINT; p = getVectorValueAddr_UTINYINT;
}else if(srcType==TSDB_DATA_TYPE_SMALLINT) { } else if (srcType == TSDB_DATA_TYPE_SMALLINT) {
p = getVectorValueAddr_SMALLINT; p = getVectorValueAddr_SMALLINT;
}else if(srcType==TSDB_DATA_TYPE_USMALLINT) { } else if (srcType == TSDB_DATA_TYPE_USMALLINT) {
p = getVectorValueAddr_USMALLINT; p = getVectorValueAddr_USMALLINT;
}else if(srcType==TSDB_DATA_TYPE_INT) { } else if (srcType == TSDB_DATA_TYPE_INT) {
p = getVectorValueAddr_INT; p = getVectorValueAddr_INT;
}else if(srcType==TSDB_DATA_TYPE_UINT) { } else if (srcType == TSDB_DATA_TYPE_UINT) {
p = getVectorValueAddr_UINT; p = getVectorValueAddr_UINT;
}else if(srcType==TSDB_DATA_TYPE_BIGINT) { } else if (srcType == TSDB_DATA_TYPE_BIGINT) {
p = getVectorValueAddr_BIGINT; p = getVectorValueAddr_BIGINT;
}else if(srcType==TSDB_DATA_TYPE_UBIGINT) { } else if (srcType == TSDB_DATA_TYPE_UBIGINT) {
p = getVectorValueAddr_UBIGINT; p = getVectorValueAddr_UBIGINT;
}else if(srcType==TSDB_DATA_TYPE_FLOAT) { } else if (srcType == TSDB_DATA_TYPE_FLOAT) {
p = getVectorValueAddr_FLOAT; p = getVectorValueAddr_FLOAT;
}else if(srcType==TSDB_DATA_TYPE_DOUBLE) { } else if (srcType == TSDB_DATA_TYPE_DOUBLE) {
p = getVectorValueAddr_DOUBLE; p = getVectorValueAddr_DOUBLE;
}else if(srcType==TSDB_DATA_TYPE_BINARY) { } else if (srcType == TSDB_DATA_TYPE_BINARY) {
p = getVectorValueAddr_VAR; p = getVectorValueAddr_VAR;
}else if(srcType==TSDB_DATA_TYPE_NCHAR) { } else if (srcType == TSDB_DATA_TYPE_NCHAR) {
p = getVectorValueAddr_VAR; p = getVectorValueAddr_VAR;
}else { } else {
p = getVectorValueAddr_default; p = getVectorValueAddr_default;
} }
return p; return p;
} }
static FORCE_INLINE void varToTimestamp(char *buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { static FORCE_INLINE void varToTimestamp(char *buf, SScalarParam *pOut, int32_t rowIndex, int32_t *overflow) {
int64_t value = 0; int64_t value = 0;
if (taosParseTime(buf, &value, strlen(buf), pOut->columnData->info.precision, tsDaylight) != TSDB_CODE_SUCCESS) { if (taosParseTime(buf, &value, strlen(buf), pOut->columnData->info.precision, tsDaylight) != TSDB_CODE_SUCCESS) {
value = 0; value = 0;
...@@ -285,7 +240,7 @@ static FORCE_INLINE void varToTimestamp(char *buf, SScalarParam* pOut, int32_t r ...@@ -285,7 +240,7 @@ static FORCE_INLINE void varToTimestamp(char *buf, SScalarParam* pOut, int32_t r
colDataAppendInt64(pOut->columnData, rowIndex, &value); colDataAppendInt64(pOut->columnData, rowIndex, &value);
} }
static FORCE_INLINE void varToSigned(char *buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { static FORCE_INLINE void varToSigned(char *buf, SScalarParam *pOut, int32_t rowIndex, int32_t *overflow) {
if (overflow) { if (overflow) {
int64_t minValue = tDataTypes[pOut->columnData->info.type].minValue; int64_t minValue = tDataTypes[pOut->columnData->info.type].minValue;
int64_t maxValue = tDataTypes[pOut->columnData->info.type].maxValue; int64_t maxValue = tDataTypes[pOut->columnData->info.type].maxValue;
...@@ -305,28 +260,28 @@ static FORCE_INLINE void varToSigned(char *buf, SScalarParam* pOut, int32_t rowI ...@@ -305,28 +260,28 @@ static FORCE_INLINE void varToSigned(char *buf, SScalarParam* pOut, int32_t rowI
case TSDB_DATA_TYPE_TINYINT: { case TSDB_DATA_TYPE_TINYINT: {
int8_t value = (int8_t)taosStr2Int8(buf, NULL, 10); int8_t value = (int8_t)taosStr2Int8(buf, NULL, 10);
colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*)&value); colDataAppendInt8(pOut->columnData, rowIndex, (int8_t *)&value);
break; break;
} }
case TSDB_DATA_TYPE_SMALLINT: { case TSDB_DATA_TYPE_SMALLINT: {
int16_t value = (int16_t)taosStr2Int16(buf, NULL, 10); int16_t value = (int16_t)taosStr2Int16(buf, NULL, 10);
colDataAppendInt16(pOut->columnData, rowIndex, (int16_t*)&value); colDataAppendInt16(pOut->columnData, rowIndex, (int16_t *)&value);
break; break;
} }
case TSDB_DATA_TYPE_INT: { case TSDB_DATA_TYPE_INT: {
int32_t value = (int32_t)taosStr2Int32(buf, NULL, 10); int32_t value = (int32_t)taosStr2Int32(buf, NULL, 10);
colDataAppendInt32(pOut->columnData, rowIndex, (int32_t*)&value); colDataAppendInt32(pOut->columnData, rowIndex, (int32_t *)&value);
break; break;
} }
case TSDB_DATA_TYPE_BIGINT: { case TSDB_DATA_TYPE_BIGINT: {
int64_t value = (int64_t)taosStr2Int64(buf, NULL, 10); int64_t value = (int64_t)taosStr2Int64(buf, NULL, 10);
colDataAppendInt64(pOut->columnData, rowIndex, (int64_t*)&value); colDataAppendInt64(pOut->columnData, rowIndex, (int64_t *)&value);
break; break;
} }
} }
} }
static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam *pOut, int32_t rowIndex, int32_t *overflow) {
if (overflow) { if (overflow) {
uint64_t minValue = (uint64_t)tDataTypes[pOut->columnData->info.type].minValue; uint64_t minValue = (uint64_t)tDataTypes[pOut->columnData->info.type].minValue;
uint64_t maxValue = (uint64_t)tDataTypes[pOut->columnData->info.type].maxValue; uint64_t maxValue = (uint64_t)tDataTypes[pOut->columnData->info.type].maxValue;
...@@ -345,28 +300,28 @@ static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam* pOut, int32_t ro ...@@ -345,28 +300,28 @@ static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam* pOut, int32_t ro
switch (pOut->columnData->info.type) { switch (pOut->columnData->info.type) {
case TSDB_DATA_TYPE_UTINYINT: { case TSDB_DATA_TYPE_UTINYINT: {
uint8_t value = (uint8_t)taosStr2UInt8(buf, NULL, 10); uint8_t value = (uint8_t)taosStr2UInt8(buf, NULL, 10);
colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*)&value); colDataAppendInt8(pOut->columnData, rowIndex, (int8_t *)&value);
break; break;
} }
case TSDB_DATA_TYPE_USMALLINT: { case TSDB_DATA_TYPE_USMALLINT: {
uint16_t value = (uint16_t)taosStr2UInt16(buf, NULL, 10); uint16_t value = (uint16_t)taosStr2UInt16(buf, NULL, 10);
colDataAppendInt16(pOut->columnData, rowIndex, (int16_t*)&value); colDataAppendInt16(pOut->columnData, rowIndex, (int16_t *)&value);
break; break;
} }
case TSDB_DATA_TYPE_UINT: { case TSDB_DATA_TYPE_UINT: {
uint32_t value = (uint32_t)taosStr2UInt32(buf, NULL, 10); uint32_t value = (uint32_t)taosStr2UInt32(buf, NULL, 10);
colDataAppendInt32(pOut->columnData, rowIndex, (int32_t*)&value); colDataAppendInt32(pOut->columnData, rowIndex, (int32_t *)&value);
break; break;
} }
case TSDB_DATA_TYPE_UBIGINT: { case TSDB_DATA_TYPE_UBIGINT: {
uint64_t value = (uint64_t)taosStr2UInt64(buf, NULL, 10); uint64_t value = (uint64_t)taosStr2UInt64(buf, NULL, 10);
colDataAppendInt64(pOut->columnData, rowIndex, (int64_t*)&value); colDataAppendInt64(pOut->columnData, rowIndex, (int64_t *)&value);
break; break;
} }
} }
} }
static FORCE_INLINE void varToFloat(char *buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { static FORCE_INLINE void varToFloat(char *buf, SScalarParam *pOut, int32_t rowIndex, int32_t *overflow) {
if (TSDB_DATA_TYPE_FLOAT == pOut->columnData->info.type) { if (TSDB_DATA_TYPE_FLOAT == pOut->columnData->info.type) {
float value = taosStr2Float(buf, NULL); float value = taosStr2Float(buf, NULL);
colDataAppendFloat(pOut->columnData, rowIndex, &value); colDataAppendFloat(pOut->columnData, rowIndex, &value);
...@@ -377,29 +332,30 @@ static FORCE_INLINE void varToFloat(char *buf, SScalarParam* pOut, int32_t rowIn ...@@ -377,29 +332,30 @@ static FORCE_INLINE void varToFloat(char *buf, SScalarParam* pOut, int32_t rowIn
colDataAppendDouble(pOut->columnData, rowIndex, &value); colDataAppendDouble(pOut->columnData, rowIndex, &value);
} }
static FORCE_INLINE void varToBool(char *buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { static FORCE_INLINE void varToBool(char *buf, SScalarParam *pOut, int32_t rowIndex, int32_t *overflow) {
int64_t value = taosStr2Int64(buf, NULL, 10); int64_t value = taosStr2Int64(buf, NULL, 10);
bool v = (value != 0)? true:false; bool v = (value != 0) ? true : false;
colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*) &v); colDataAppendInt8(pOut->columnData, rowIndex, (int8_t *)&v);
} }
static FORCE_INLINE void varToNchar(char* buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { static FORCE_INLINE void varToNchar(char *buf, SScalarParam *pOut, int32_t rowIndex, int32_t *overflow) {
int32_t len = 0; int32_t len = 0;
int32_t inputLen = varDataLen(buf); int32_t inputLen = varDataLen(buf);
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);
taosMemoryFree(t); taosMemoryFree(t);
} }
static FORCE_INLINE void ncharToVar(char* buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { static FORCE_INLINE void ncharToVar(char *buf, SScalarParam *pOut, int32_t rowIndex, int32_t *overflow) {
int32_t inputLen = varDataLen(buf); int32_t inputLen = varDataLen(buf);
char* t = taosMemoryCalloc(1, inputLen + VARSTR_HEADER_SIZE); char *t = taosMemoryCalloc(1, inputLen + VARSTR_HEADER_SIZE);
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(buf), varDataLen(buf), varDataVal(t)); int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(buf), varDataLen(buf), varDataVal(t));
if (len < 0) { if (len < 0) {
taosMemoryFree(t); taosMemoryFree(t);
...@@ -411,9 +367,9 @@ static FORCE_INLINE void ncharToVar(char* buf, SScalarParam* pOut, int32_t rowIn ...@@ -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 vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, int32_t inType, int32_t outType, int32_t* overflow) { int32_t *overflow) {
bool vton = false; bool vton = false;
_bufConverteFunc func = NULL; _bufConverteFunc func = NULL;
...@@ -447,25 +403,25 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in ...@@ -447,25 +403,25 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in
continue; continue;
} }
char* data = colDataGetVarData(pIn->columnData, i); char *data = colDataGetVarData(pIn->columnData, i);
int32_t convertType = inType; int32_t convertType = inType;
if(inType == TSDB_DATA_TYPE_JSON){ if (inType == TSDB_DATA_TYPE_JSON) {
if(*data == TSDB_DATA_TYPE_NULL) { if (*data == TSDB_DATA_TYPE_NULL) {
ASSERT(0); ASSERT(0);
} else if(*data == TSDB_DATA_TYPE_NCHAR) { } else if (*data == TSDB_DATA_TYPE_NCHAR) {
data += CHAR_BYTES; data += CHAR_BYTES;
convertType = TSDB_DATA_TYPE_NCHAR; convertType = TSDB_DATA_TYPE_NCHAR;
} else if(tTagIsJson(data)){ } else if (tTagIsJson(data)) {
terrno = TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR; terrno = TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR;
return terrno; return terrno;
} else { } else {
convertNumberToNumber(data+CHAR_BYTES, colDataGetNumData(pOut->columnData, i), *data, outType); convertNumberToNumber(data + CHAR_BYTES, colDataGetNumData(pOut->columnData, i), *data, outType);
continue; continue;
} }
} }
int32_t bufSize = pIn->columnData->info.bytes; int32_t bufSize = pIn->columnData->info.bytes;
char *tmp = taosMemoryMalloc(varDataTLen(data)); char *tmp = taosMemoryMalloc(varDataTLen(data));
if(!tmp){ if (!tmp) {
sclError("out of memory in vectorConvertFromVarData"); sclError("out of memory in vectorConvertFromVarData");
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
...@@ -475,7 +431,7 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in ...@@ -475,7 +431,7 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in
if (TSDB_DATA_TYPE_VARCHAR == convertType) { if (TSDB_DATA_TYPE_VARCHAR == convertType) {
memcpy(tmp, varDataVal(data), varDataLen(data)); memcpy(tmp, varDataVal(data), varDataLen(data));
tmp[varDataLen(data)] = 0; tmp[varDataLen(data)] = 0;
} else if (TSDB_DATA_TYPE_NCHAR == convertType){ } else if (TSDB_DATA_TYPE_NCHAR == convertType) {
ASSERT(varDataLen(data) <= bufSize); ASSERT(varDataLen(data) <= bufSize);
int len = taosUcs4ToMbs((TdUcs4 *)varDataVal(data), varDataLen(data), tmp); int len = taosUcs4ToMbs((TdUcs4 *)varDataVal(data), varDataLen(data), tmp);
...@@ -496,30 +452,30 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in ...@@ -496,30 +452,30 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
double getVectorDoubleValue_JSON(void *src, int32_t index){ double getVectorDoubleValue_JSON(void *src, int32_t index) {
char *data = colDataGetVarData((SColumnInfoData*)src, index); char *data = colDataGetVarData((SColumnInfoData *)src, index);
double out = 0; double out = 0;
if (*data == TSDB_DATA_TYPE_NULL){ if (*data == TSDB_DATA_TYPE_NULL) {
return out; return out;
} else if(*data == TSDB_DATA_TYPE_NCHAR) { // json inner type can not be BINARY } else if (*data == TSDB_DATA_TYPE_NCHAR) { // json inner type can not be BINARY
convertNcharToDouble(data+CHAR_BYTES, &out); convertNcharToDouble(data + CHAR_BYTES, &out);
} else if(tTagIsJson(data)){ } else if (tTagIsJson(data)) {
terrno = TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR; terrno = TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR;
return 0; return 0;
} else{ } else {
convertNumberToNumber(data+CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE); convertNumberToNumber(data + CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE);
} }
return out; return out;
} }
void* ncharTobinary(void *buf){ // todo need to remove , if tobinary is nchar void *ncharTobinary(void *buf) { // todo need to remove , if tobinary is nchar
int32_t inputLen = varDataTLen(buf); int32_t inputLen = varDataTLen(buf);
void* t = taosMemoryCalloc(1, inputLen); void *t = taosMemoryCalloc(1, inputLen);
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(buf), varDataLen(buf), varDataVal(t)); int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(buf), varDataLen(buf), varDataVal(t));
if (len < 0) { if (len < 0) {
sclError("charset:%s to %s. val:%s convert ncharTobinary failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, sclError("charset:%s to %s. val:%s convert ncharTobinary failed.", DEFAULT_UNICODE_ENCODEC, tsCharset,
(char*)varDataVal(buf)); (char *)varDataVal(buf));
taosMemoryFree(t); taosMemoryFree(t);
return NULL; return NULL;
} }
...@@ -527,8 +483,9 @@ void* ncharTobinary(void *buf){ // todo need to remove , if tobinary ...@@ -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;
} }
...@@ -543,7 +500,7 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t ...@@ -543,7 +500,7 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t
return false; return false;
} }
typeLeft = **pLeftData; typeLeft = **pLeftData;
(*pLeftData) ++; (*pLeftData)++;
} }
if (typeRight == TSDB_DATA_TYPE_JSON) { if (typeRight == TSDB_DATA_TYPE_JSON) {
if (tTagIsJson(*pLeftData)) { if (tTagIsJson(*pLeftData)) {
...@@ -551,7 +508,7 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t ...@@ -551,7 +508,7 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t
return false; return false;
} }
typeRight = **pRightData; typeRight = **pRightData;
(*pRightData) ++; (*pRightData)++;
} }
if (optr == OP_TYPE_LIKE || optr == OP_TYPE_NOT_LIKE || optr == OP_TYPE_MATCH || optr == OP_TYPE_NMATCH) { if (optr == OP_TYPE_LIKE || optr == OP_TYPE_NOT_LIKE || optr == OP_TYPE_MATCH || optr == OP_TYPE_NMATCH) {
...@@ -569,7 +526,6 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t ...@@ -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;
...@@ -586,12 +542,12 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t ...@@ -586,12 +542,12 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t
if (IS_NUMERIC_TYPE(type)) { if (IS_NUMERIC_TYPE(type)) {
if (typeLeft == TSDB_DATA_TYPE_NCHAR) { if (typeLeft == TSDB_DATA_TYPE_NCHAR) {
ASSERT(0); ASSERT(0);
// convertNcharToDouble(*pLeftData, pLeftOut); // convertNcharToDouble(*pLeftData, pLeftOut);
// *pLeftData = pLeftOut; // *pLeftData = pLeftOut;
} else if (typeLeft == TSDB_DATA_TYPE_BINARY) { } else if (typeLeft == TSDB_DATA_TYPE_BINARY) {
ASSERT(0); ASSERT(0);
// convertBinaryToDouble(*pLeftData, pLeftOut); // convertBinaryToDouble(*pLeftData, pLeftOut);
// *pLeftData = pLeftOut; // *pLeftData = pLeftOut;
} else if (typeLeft != type) { } else if (typeLeft != type) {
convertNumberToNumber(*pLeftData, pLeftOut, typeLeft, type); convertNumberToNumber(*pLeftData, pLeftOut, typeLeft, type);
*pLeftData = pLeftOut; *pLeftData = pLeftOut;
...@@ -599,12 +555,12 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t ...@@ -599,12 +555,12 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t
if (typeRight == TSDB_DATA_TYPE_NCHAR) { if (typeRight == TSDB_DATA_TYPE_NCHAR) {
ASSERT(0); ASSERT(0);
// convertNcharToDouble(*pRightData, pRightOut); // convertNcharToDouble(*pRightData, pRightOut);
// *pRightData = pRightOut; // *pRightData = pRightOut;
} else if (typeRight == TSDB_DATA_TYPE_BINARY) { } else if (typeRight == TSDB_DATA_TYPE_BINARY) {
ASSERT(0); ASSERT(0);
// convertBinaryToDouble(*pRightData, pRightOut); // convertBinaryToDouble(*pRightData, pRightOut);
// *pRightData = pRightOut; // *pRightData = pRightOut;
} else if (typeRight != type) { } else if (typeRight != type) {
convertNumberToNumber(*pRightData, pRightOut, typeRight, type); convertNumberToNumber(*pRightData, pRightOut, typeRight, type);
*pRightData = pRightOut; *pRightData = pRightOut;
...@@ -625,9 +581,9 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t ...@@ -625,9 +581,9 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t
return true; return true;
} }
int32_t vectorConvertToVarData(const SScalarParam* pIn, SScalarParam* pOut, int16_t inType, int16_t outType) { int32_t vectorConvertToVarData(const SScalarParam *pIn, SScalarParam *pOut, int16_t inType, int16_t outType) {
SColumnInfoData* pInputCol = pIn->columnData; SColumnInfoData *pInputCol = pIn->columnData;
SColumnInfoData* pOutputCol = pOut->columnData; SColumnInfoData *pOutputCol = pOut->columnData;
char tmp[128] = {0}; char tmp[128] = {0};
if (IS_SIGNED_NUMERIC_TYPE(inType) || inType == TSDB_DATA_TYPE_BOOL || inType == TSDB_DATA_TYPE_TIMESTAMP) { if (IS_SIGNED_NUMERIC_TYPE(inType) || inType == TSDB_DATA_TYPE_BOOL || inType == TSDB_DATA_TYPE_TIMESTAMP) {
...@@ -690,9 +646,9 @@ int32_t vectorConvertToVarData(const SScalarParam* pIn, SScalarParam* pOut, int1 ...@@ -690,9 +646,9 @@ int32_t vectorConvertToVarData(const SScalarParam* pIn, SScalarParam* pOut, int1
} }
// TODO opt performance // TODO opt performance
int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t* overflow) { int32_t vectorConvertImpl(const SScalarParam *pIn, SScalarParam *pOut, int32_t *overflow) {
SColumnInfoData* pInputCol = pIn->columnData; SColumnInfoData *pInputCol = pIn->columnData;
SColumnInfoData* pOutputCol = pOut->columnData; SColumnInfoData *pOutputCol = pOut->columnData;
if (NULL == pInputCol) { if (NULL == pInputCol) {
sclError("input column is NULL, hashFilter %p", pIn->pHashFilter); sclError("input column is NULL, hashFilter %p", pIn->pHashFilter);
...@@ -774,7 +730,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t* ...@@ -774,7 +730,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
} }
break; break;
} }
case TSDB_DATA_TYPE_SMALLINT:{ case TSDB_DATA_TYPE_SMALLINT: {
for (int32_t i = 0; i < pIn->numOfRows; ++i) { for (int32_t i = 0; i < pIn->numOfRows; ++i) {
if (colDataIsNull_f(pInputCol->nullbitmap, i)) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
colDataAppendNULL(pOutputCol, i); colDataAppendNULL(pOutputCol, i);
...@@ -787,7 +743,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t* ...@@ -787,7 +743,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
} }
break; break;
} }
case TSDB_DATA_TYPE_INT:{ case TSDB_DATA_TYPE_INT: {
for (int32_t i = 0; i < pIn->numOfRows; ++i) { for (int32_t i = 0; i < pIn->numOfRows; ++i) {
if (colDataIsNull_f(pInputCol->nullbitmap, i)) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
colDataAppendNULL(pOutputCol, i); colDataAppendNULL(pOutputCol, i);
...@@ -814,7 +770,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t* ...@@ -814,7 +770,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
} }
break; break;
} }
case TSDB_DATA_TYPE_UTINYINT:{ case TSDB_DATA_TYPE_UTINYINT: {
for (int32_t i = 0; i < pIn->numOfRows; ++i) { for (int32_t i = 0; i < pIn->numOfRows; ++i) {
if (colDataIsNull_f(pInputCol->nullbitmap, i)) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
colDataAppendNULL(pOutputCol, i); colDataAppendNULL(pOutputCol, i);
...@@ -827,7 +783,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t* ...@@ -827,7 +783,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
} }
break; break;
} }
case TSDB_DATA_TYPE_USMALLINT:{ case TSDB_DATA_TYPE_USMALLINT: {
for (int32_t i = 0; i < pIn->numOfRows; ++i) { for (int32_t i = 0; i < pIn->numOfRows; ++i) {
if (colDataIsNull_f(pInputCol->nullbitmap, i)) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
colDataAppendNULL(pOutputCol, i); colDataAppendNULL(pOutputCol, i);
...@@ -840,7 +796,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t* ...@@ -840,7 +796,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
} }
break; break;
} }
case TSDB_DATA_TYPE_UINT:{ case TSDB_DATA_TYPE_UINT: {
for (int32_t i = 0; i < pIn->numOfRows; ++i) { for (int32_t i = 0; i < pIn->numOfRows; ++i) {
if (colDataIsNull_f(pInputCol->nullbitmap, i)) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
colDataAppendNULL(pOutputCol, i); colDataAppendNULL(pOutputCol, i);
...@@ -862,11 +818,11 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t* ...@@ -862,11 +818,11 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
uint64_t value = 0; uint64_t value = 0;
GET_TYPED_DATA(value, uint64_t, inType, colDataGetData(pInputCol, i)); GET_TYPED_DATA(value, uint64_t, inType, colDataGetData(pInputCol, i));
colDataAppendInt64(pOutputCol, i, (int64_t*)&value); colDataAppendInt64(pOutputCol, i, (int64_t *)&value);
} }
break; break;
} }
case TSDB_DATA_TYPE_FLOAT:{ case TSDB_DATA_TYPE_FLOAT: {
for (int32_t i = 0; i < pIn->numOfRows; ++i) { for (int32_t i = 0; i < pIn->numOfRows; ++i) {
if (colDataIsNull_f(pInputCol->nullbitmap, i)) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
colDataAppendNULL(pOutputCol, i); colDataAppendNULL(pOutputCol, i);
...@@ -875,7 +831,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t* ...@@ -875,7 +831,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
float value = 0; float value = 0;
GET_TYPED_DATA(value, float, inType, colDataGetData(pInputCol, i)); GET_TYPED_DATA(value, float, inType, colDataGetData(pInputCol, i));
colDataAppendFloat(pOutputCol, i, (float*)&value); colDataAppendFloat(pOutputCol, i, (float *)&value);
} }
break; break;
} }
...@@ -888,7 +844,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t* ...@@ -888,7 +844,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
double value = 0; double value = 0;
GET_TYPED_DATA(value, double, inType, colDataGetData(pInputCol, i)); GET_TYPED_DATA(value, double, inType, colDataGetData(pInputCol, i));
colDataAppendDouble(pOutputCol, i, (double*)&value); colDataAppendDouble(pOutputCol, i, (double *)&value);
} }
break; break;
} }
...@@ -904,30 +860,27 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t* ...@@ -904,30 +860,27 @@ 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] = {
/* NULL BOOL TINY SMAL INT BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB */
int8_t gConvertTypes[TSDB_DATA_TYPE_BLOB+1][TSDB_DATA_TYPE_BLOB+1] = { /*NULL*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* NULL BOOL TINY SMAL INT BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB */ /*BOOL*/ 0, 0, 2, 3, 4, 5, 6, 7, 7, 9, 7, 11, 12, 13, 14, 0, 7, 0, 0,
/*NULL*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*TINY*/ 0, 0, 0, 3, 4, 5, 6, 7, 7, 9, 7, 3, 4, 5, 7, 0, 7, 0, 0,
/*BOOL*/ 0, 0, 2, 3, 4, 5, 6, 7, 7, 9, 7, 11, 12, 13, 14, 0, 7, 0, 0, /*SMAL*/ 0, 0, 0, 0, 4, 5, 6, 7, 7, 9, 7, 3, 4, 5, 7, 0, 7, 0, 0,
/*TINY*/ 0, 0, 0, 3, 4, 5, 6, 7, 7, 9, 7, 3, 4, 5, 7, 0, 7, 0, 0, /*INT */ 0, 0, 0, 0, 0, 5, 6, 7, 7, 9, 7, 4, 4, 5, 7, 0, 7, 0, 0,
/*SMAL*/ 0, 0, 0, 0, 4, 5, 6, 7, 7, 9, 7, 3, 4, 5, 7, 0, 7, 0, 0, /*BIGI*/ 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 7, 5, 5, 5, 7, 0, 7, 0, 0,
/*INT */ 0, 0, 0, 0, 0, 5, 6, 7, 7, 9, 7, 4, 4, 5, 7, 0, 7, 0, 0, /*FLOA*/ 0, 0, 0, 0, 0, 0, 0, 7, 7, 6, 7, 6, 6, 6, 6, 0, 7, 0, 0,
/*BIGI*/ 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 7, 5, 5, 5, 7, 0, 7, 0, 0, /*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 0, 7, 0, 0,
/*FLOA*/ 0, 0, 0, 0, 0, 0, 0, 7, 7, 6, 7, 6, 6, 6, 6, 0, 7, 0, 0, /*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 8, 7, 7, 7, 7, 0, 0, 0, 0,
/*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 0, 7, 0, 0, /*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 7, 0, 7, 0, 0,
/*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 8, 7, 7, 7, 7, 0, 0, 0, 0, /*NCHA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0,
/*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 7, 0, 7, 0, 0, /*UTIN*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, 0, 7, 0, 0,
/*NCHA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0, /*USMA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, 0, 7, 0, 0,
/*UTIN*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, 0, 7, 0, 0, /*UINT*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 7, 0, 0,
/*USMA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, 0, 7, 0, 0, /*UBIG*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0,
/*UINT*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 7, 0, 0, /*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/*UBIG*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, /*VARB*/ 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, /*DECI*/ 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, /*BLOB*/ 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
};
int32_t vectorGetConvertType(int32_t type1, int32_t type2) { int32_t vectorGetConvertType(int32_t type1, int32_t type2) {
if (type1 == type2) { if (type1 == type2) {
...@@ -952,14 +905,14 @@ int32_t vectorConvertScalarParam(SScalarParam *input, SScalarParam *output, int3 ...@@ -952,14 +905,14 @@ int32_t vectorConvertScalarParam(SScalarParam *input, SScalarParam *output, int3
code = vectorConvertImpl(input, output, NULL); code = vectorConvertImpl(input, output, NULL);
if (code) { if (code) {
// taosMemoryFreeClear(paramOut1->data); // taosMemoryFreeClear(paramOut1->data);
return code; return code;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* pLeftOut, SScalarParam* pRightOut) { int32_t vectorConvert(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pLeftOut, SScalarParam *pRightOut) {
int32_t leftType = GET_PARAM_TYPE(pLeft); int32_t leftType = GET_PARAM_TYPE(pLeft);
int32_t rightType = GET_PARAM_TYPE(pRight); int32_t rightType = GET_PARAM_TYPE(pRight);
if (leftType == rightType) { if (leftType == rightType) {
...@@ -1009,8 +962,8 @@ enum { ...@@ -1009,8 +962,8 @@ enum {
VECTOR_UN_CONVERT = 0x2, VECTOR_UN_CONVERT = 0x2,
}; };
static int32_t doConvertHelper(SScalarParam* pDest, int32_t* convert, const SScalarParam* pParam, int32_t type) { static int32_t doConvertHelper(SScalarParam *pDest, int32_t *convert, const SScalarParam *pParam, int32_t type) {
SColumnInfoData* pCol = pParam->columnData; SColumnInfoData *pCol = pParam->columnData;
if (IS_VAR_DATA_TYPE(pCol->info.type) && pCol->info.type != TSDB_DATA_TYPE_JSON) { if (IS_VAR_DATA_TYPE(pCol->info.type) && pCol->info.type != TSDB_DATA_TYPE_JSON) {
pDest->numOfRows = pParam->numOfRows; pDest->numOfRows = pParam->numOfRows;
...@@ -1035,7 +988,8 @@ static int32_t doConvertHelper(SScalarParam* pDest, int32_t* convert, const SSca ...@@ -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 ...@@ -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,13 +1023,14 @@ static void vectorMathTsAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pR ...@@ -1069,13 +1023,14 @@ 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);
} }
} }
} }
static SColumnInfoData* doVectorConvert(SScalarParam* pInput, int32_t* doConvert) { static SColumnInfoData *doVectorConvert(SScalarParam *pInput, int32_t *doConvert) {
SScalarParam convertParam = {0}; SScalarParam convertParam = {0};
int32_t code = doConvertHelper(&convertParam, doConvert, pInput, TSDB_DATA_TYPE_DOUBLE); int32_t code = doConvertHelper(&convertParam, doConvert, pInput, TSDB_DATA_TYPE_DOUBLE);
...@@ -1091,18 +1046,18 @@ static SColumnInfoData* doVectorConvert(SScalarParam* pInput, int32_t* doConvert ...@@ -1091,18 +1046,18 @@ static SColumnInfoData* doVectorConvert(SScalarParam* pInput, int32_t* doConvert
} }
} }
static void doReleaseVec(SColumnInfoData* pCol, int32_t type) { static void doReleaseVec(SColumnInfoData *pCol, int32_t type) {
if (type == VECTOR_DO_CONVERT) { if (type == VECTOR_DO_CONVERT) {
colDataDestroy(pCol); colDataDestroy(pCol);
taosMemoryFree(pCol); taosMemoryFree(pCol);
} }
} }
void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorMathAdd(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
SColumnInfoData *pOutputCol = pOut->columnData; SColumnInfoData *pOutputCol = pOut->columnData;
int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
...@@ -1113,7 +1068,8 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut ...@@ -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);
...@@ -1144,7 +1100,7 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut ...@@ -1144,7 +1100,7 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
if (pLeft->numOfRows == pRight->numOfRows) { if (pLeft->numOfRows == pRight->numOfRows) {
for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
if (IS_NULL){ if (IS_NULL) {
colDataAppendNULL(pOutputCol, i); colDataAppendNULL(pOutputCol, i);
continue; // TODO set null or ignore continue; // TODO set null or ignore
} }
...@@ -1162,7 +1118,8 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut ...@@ -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 ...@@ -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,27 +1153,28 @@ static void vectorMathTsSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pR ...@@ -1196,27 +1153,28 @@ 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);
} }
} }
} }
void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorMathSub(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
SColumnInfoData *pOutputCol = pOut->columnData; SColumnInfoData *pOutputCol = pOut->columnData;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
int32_t leftConvert = 0, rightConvert = 0; int32_t leftConvert = 0, rightConvert = 0;
SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
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 ...@@ -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);
...@@ -1280,12 +1239,12 @@ static void vectorMathMultiplyHelper(SColumnInfoData* pLeftCol, SColumnInfoData* ...@@ -1280,12 +1239,12 @@ static void vectorMathMultiplyHelper(SColumnInfoData* pLeftCol, SColumnInfoData*
} }
} }
void vectorMathMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorMathMultiply(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
SColumnInfoData *pOutputCol = pOut->columnData; SColumnInfoData *pOutputCol = pOut->columnData;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
int32_t leftConvert = 0, rightConvert = 0; int32_t leftConvert = 0, rightConvert = 0;
SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
...@@ -1313,12 +1272,12 @@ void vectorMathMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam ...@@ -1313,12 +1272,12 @@ void vectorMathMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam
doReleaseVec(pRightCol, rightConvert); doReleaseVec(pRightCol, rightConvert);
} }
void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorMathDivide(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
SColumnInfoData *pOutputCol = pOut->columnData; SColumnInfoData *pOutputCol = pOut->columnData;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
int32_t leftConvert = 0, rightConvert = 0; int32_t leftConvert = 0, rightConvert = 0;
SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
...@@ -1330,12 +1289,11 @@ void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *p ...@@ -1330,12 +1289,11 @@ void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *p
double *output = (double *)pOutputCol->pData; double *output = (double *)pOutputCol->pData;
if (pLeft->numOfRows == pRight->numOfRows) { if (pLeft->numOfRows == pRight->numOfRows) {
for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
if (IS_NULL || (getVectorDoubleValueFnRight(RIGHT_COL, i) == 0)) { //divide by 0 check if (IS_NULL || (getVectorDoubleValueFnRight(RIGHT_COL, i) == 0)) { // divide by 0 check
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 ...@@ -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 ...@@ -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);
} }
} }
} }
...@@ -1369,12 +1326,12 @@ void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *p ...@@ -1369,12 +1326,12 @@ void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *p
doReleaseVec(pRightCol, rightConvert); doReleaseVec(pRightCol, rightConvert);
} }
void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorMathRemainder(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
SColumnInfoData *pOutputCol = pOut->columnData; SColumnInfoData *pOutputCol = pOut->columnData;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
int32_t leftConvert = 0, rightConvert = 0; int32_t leftConvert = 0, rightConvert = 0;
SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
...@@ -1447,13 +1404,13 @@ void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam ...@@ -1447,13 +1404,13 @@ void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam
doReleaseVec(pRightCol, rightConvert); doReleaseVec(pRightCol, rightConvert);
} }
void vectorMathMinus(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorMathMinus(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
SColumnInfoData *pOutputCol = pOut->columnData; SColumnInfoData *pOutputCol = pOut->columnData;
pOut->numOfRows = pLeft->numOfRows; pOut->numOfRows = pLeft->numOfRows;
int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : (pLeft->numOfRows - 1); int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : (pLeft->numOfRows - 1);
int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
int32_t leftConvert = 0; int32_t leftConvert = 0;
SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
...@@ -1473,14 +1430,14 @@ void vectorMathMinus(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO ...@@ -1473,14 +1430,14 @@ void vectorMathMinus(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO
doReleaseVec(pLeftCol, leftConvert); doReleaseVec(pLeftCol, leftConvert);
} }
void vectorAssign(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorAssign(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
SColumnInfoData *pOutputCol = pOut->columnData; SColumnInfoData *pOutputCol = pOut->columnData;
pOut->numOfRows = pLeft->numOfRows; pOut->numOfRows = pLeft->numOfRows;
if(colDataIsNull_s(pRight->columnData, 0)){ if (colDataIsNull_s(pRight->columnData, 0)) {
colDataAppendNNULL(pOutputCol, 0, pOut->numOfRows); colDataAppendNNULL(pOutputCol, 0, pOut->numOfRows);
} else { } else {
char* d = colDataGetData(pRight->columnData, 0); char *d = colDataGetData(pRight->columnData, 0);
for (int32_t i = 0; i < pOut->numOfRows; ++i) { for (int32_t i = 0; i < pOut->numOfRows; ++i) {
colDataAppend(pOutputCol, i, d, false); colDataAppend(pOutputCol, i, d, false);
} }
...@@ -1490,7 +1447,7 @@ void vectorAssign(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, ...@@ -1490,7 +1447,7 @@ void vectorAssign(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
pOut->numOfQualified = pRight->numOfQualified * pOut->numOfRows; pOut->numOfQualified = pRight->numOfQualified * pOut->numOfRows;
} }
void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { void vectorConcat(SScalarParam *pLeft, SScalarParam *pRight, void *out, int32_t _ord) {
#if 0 #if 0
int32_t len = pLeft->bytes + pRight->bytes; int32_t len = pLeft->bytes + pRight->bytes;
...@@ -1541,7 +1498,8 @@ void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t ...@@ -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);
...@@ -1560,7 +1518,7 @@ static void vectorBitAndHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRigh ...@@ -1560,7 +1518,7 @@ static void vectorBitAndHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRigh
} }
} }
void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorBitAnd(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
SColumnInfoData *pOutputCol = pOut->columnData; SColumnInfoData *pOutputCol = pOut->columnData;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
...@@ -1593,7 +1551,8 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, ...@@ -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);
...@@ -1613,7 +1572,7 @@ static void vectorBitOrHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRight ...@@ -1613,7 +1572,7 @@ static void vectorBitOrHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRight
} }
} }
void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorBitOr(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
SColumnInfoData *pOutputCol = pOut->columnData; SColumnInfoData *pOutputCol = pOut->columnData;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
...@@ -1651,8 +1610,8 @@ int32_t doVectorCompareImpl(int32_t numOfRows, SScalarParam *pOut, int32_t start ...@@ -1651,8 +1610,8 @@ int32_t doVectorCompareImpl(int32_t numOfRows, SScalarParam *pOut, int32_t start
int32_t num = 0; int32_t num = 0;
for (int32_t i = startIndex; i < numOfRows && i >= 0; i += step) { for (int32_t i = startIndex; i < numOfRows && i >= 0; i += step) {
int32_t leftIndex = (i >= pLeft->numOfRows)? 0:i; int32_t leftIndex = (i >= pLeft->numOfRows) ? 0 : i;
int32_t rightIndex = (i >= pRight->numOfRows)? 0:i; int32_t rightIndex = (i >= pRight->numOfRows) ? 0 : i;
if (IS_HELPER_NULL(pLeft->columnData, leftIndex) || IS_HELPER_NULL(pRight->columnData, rightIndex)) { if (IS_HELPER_NULL(pLeft->columnData, leftIndex) || IS_HELPER_NULL(pRight->columnData, rightIndex)) {
bool res = false; bool res = false;
...@@ -1660,8 +1619,8 @@ int32_t doVectorCompareImpl(int32_t numOfRows, SScalarParam *pOut, int32_t start ...@@ -1660,8 +1619,8 @@ int32_t doVectorCompareImpl(int32_t numOfRows, SScalarParam *pOut, int32_t start
continue; continue;
} }
char * pLeftData = colDataGetData(pLeft->columnData, leftIndex); char *pLeftData = colDataGetData(pLeft->columnData, leftIndex);
char * pRightData = colDataGetData(pRight->columnData, rightIndex); char *pRightData = colDataGetData(pRight->columnData, rightIndex);
int64_t leftOut = 0; int64_t leftOut = 0;
int64_t rightOut = 0; int64_t rightOut = 0;
bool freeLeft = false; bool freeLeft = false;
...@@ -1700,7 +1659,7 @@ int32_t doVectorCompareImpl(int32_t numOfRows, SScalarParam *pOut, int32_t start ...@@ -1700,7 +1659,7 @@ int32_t doVectorCompareImpl(int32_t numOfRows, SScalarParam *pOut, int32_t start
return num; return num;
} }
void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, int32_t optr) { void vectorCompareImpl(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord, int32_t optr) {
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
int32_t lType = GET_PARAM_TYPE(pLeft); int32_t lType = GET_PARAM_TYPE(pLeft);
...@@ -1719,13 +1678,13 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam * ...@@ -1719,13 +1678,13 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *
for (; i >= 0 && i < pLeft->numOfRows; i += step) { for (; i >= 0 && i < pLeft->numOfRows; i += step) {
if (IS_HELPER_NULL(pLeft->columnData, i)) { if (IS_HELPER_NULL(pLeft->columnData, i)) {
bool res = false; bool res = false;
colDataAppendInt8(pOut->columnData, i, (int8_t*)&res); colDataAppendInt8(pOut->columnData, i, (int8_t *)&res);
continue; continue;
} }
char *pLeftData = colDataGetData(pLeft->columnData, i); char *pLeftData = colDataGetData(pLeft->columnData, i);
bool res = filterDoCompare(fp, optr, pLeftData, pRight->pHashFilter); bool res = filterDoCompare(fp, optr, pLeftData, pRight->pHashFilter);
colDataAppendInt8(pOut->columnData, i, (int8_t*)&res); colDataAppendInt8(pOut->columnData, i, (int8_t *)&res);
if (res) { if (res) {
pOut->numOfQualified++; pOut->numOfQualified++;
} }
...@@ -1735,7 +1694,7 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam * ...@@ -1735,7 +1694,7 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *
} }
} }
void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, int32_t optr) { void vectorCompare(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord, int32_t optr) {
SScalarParam pLeftOut = {0}; SScalarParam pLeftOut = {0};
SScalarParam pRightOut = {0}; SScalarParam pRightOut = {0};
SScalarParam *param1 = NULL; SScalarParam *param1 = NULL;
...@@ -1765,74 +1724,74 @@ void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut ...@@ -1765,74 +1724,74 @@ void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
sclFreeParam(&pRightOut); sclFreeParam(&pRightOut);
} }
void vectorGreater(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorGreater(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_GREATER_THAN); vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_GREATER_THAN);
} }
void vectorGreaterEqual(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorGreaterEqual(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_GREATER_EQUAL); vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_GREATER_EQUAL);
} }
void vectorLower(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorLower(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_LOWER_THAN); vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_LOWER_THAN);
} }
void vectorLowerEqual(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorLowerEqual(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_LOWER_EQUAL); vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_LOWER_EQUAL);
} }
void vectorEqual(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorEqual(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_EQUAL); vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_EQUAL);
} }
void vectorNotEqual(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorNotEqual(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NOT_EQUAL); vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NOT_EQUAL);
} }
void vectorIn(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorIn(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_IN); vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_IN);
} }
void vectorNotIn(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorNotIn(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NOT_IN); vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NOT_IN);
} }
void vectorLike(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorLike(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_LIKE); vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_LIKE);
} }
void vectorNotLike(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorNotLike(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NOT_LIKE); vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NOT_LIKE);
} }
void vectorMatch(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorMatch(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_MATCH); vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_MATCH);
} }
void vectorNotMatch(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorNotMatch(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NMATCH); vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NMATCH);
} }
void vectorIsNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorIsNull(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
for(int32_t i = 0; i < pLeft->numOfRows; ++i) { for (int32_t i = 0; i < pLeft->numOfRows; ++i) {
int8_t v = IS_HELPER_NULL(pLeft->columnData, i) ? 1 : 0; int8_t v = IS_HELPER_NULL(pLeft->columnData, i) ? 1 : 0;
colDataAppendInt8(pOut->columnData, i, &v); colDataAppendInt8(pOut->columnData, i, &v);
} }
pOut->numOfRows = pLeft->numOfRows; pOut->numOfRows = pLeft->numOfRows;
} }
void vectorNotNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorNotNull(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
for(int32_t i = 0; i < pLeft->numOfRows; ++i) { for (int32_t i = 0; i < pLeft->numOfRows; ++i) {
int8_t v = IS_HELPER_NULL(pLeft->columnData, i) ? 0 : 1; int8_t v = IS_HELPER_NULL(pLeft->columnData, i) ? 0 : 1;
colDataAppendInt8(pOut->columnData, i, &v); colDataAppendInt8(pOut->columnData, i, &v);
} }
pOut->numOfRows = pLeft->numOfRows; pOut->numOfRows = pLeft->numOfRows;
} }
void vectorIsTrue(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorIsTrue(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
vectorConvertImpl(pLeft, pOut, NULL); vectorConvertImpl(pLeft, pOut, NULL);
for(int32_t i = 0; i < pOut->numOfRows; ++i) { for (int32_t i = 0; i < pOut->numOfRows; ++i) {
if(colDataIsNull_s(pOut->columnData, i)) { if (colDataIsNull_s(pOut->columnData, i)) {
int8_t v = 0; int8_t v = 0;
colDataAppendInt8(pOut->columnData, i, &v); colDataAppendInt8(pOut->columnData, i, &v);
colDataSetNotNull_f(pOut->columnData->nullbitmap, i); colDataSetNotNull_f(pOut->columnData->nullbitmap, i);
...@@ -1843,26 +1802,26 @@ void vectorIsTrue(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, ...@@ -1843,26 +1802,26 @@ void vectorIsTrue(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
STagVal getJsonValue(char *json, char *key, bool *isExist) { STagVal getJsonValue(char *json, char *key, bool *isExist) {
STagVal val = {.pKey = key}; STagVal val = {.pKey = key};
if (tTagIsJson((const STag *)json) == false){ if (tTagIsJson((const STag *)json) == false) {
terrno = TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR; terrno = TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR;
if(isExist){ if (isExist) {
*isExist = false; *isExist = false;
} }
return val; return val;
} }
bool find = tTagGet(((const STag *)json), &val); // json value is null and not exist is different bool find = tTagGet(((const STag *)json), &val); // json value is null and not exist is different
if(isExist){ if (isExist) {
*isExist = find; *isExist = find;
} }
return val; return val;
} }
void vectorJsonContains(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorJsonContains(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
SColumnInfoData *pOutputCol = pOut->columnData; SColumnInfoData *pOutputCol = pOut->columnData;
int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
...@@ -1877,17 +1836,16 @@ void vectorJsonContains(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam ...@@ -1877,17 +1836,16 @@ void vectorJsonContains(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam
getJsonValue(pLeftData, jsonKey, &isExist); getJsonValue(pLeftData, jsonKey, &isExist);
} }
colDataAppend(pOutputCol, i, (const char*)(&isExist), false); colDataAppend(pOutputCol, i, (const char *)(&isExist), false);
} }
taosMemoryFree(jsonKey); taosMemoryFree(jsonKey);
} }
void vectorJsonArrow(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorJsonArrow(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
SColumnInfoData *pOutputCol = pOut->columnData; SColumnInfoData *pOutputCol = pOut->columnData;
int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
...@@ -1905,7 +1863,7 @@ void vectorJsonArrow(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO ...@@ -1905,7 +1863,7 @@ void vectorJsonArrow(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO
STagVal value = getJsonValue(pLeftData, jsonKey, &isExist); STagVal value = getJsonValue(pLeftData, jsonKey, &isExist);
char *data = isExist ? tTagValToData(&value, true) : NULL; char *data = isExist ? tTagValToData(&value, true) : NULL;
colDataAppend(pOutputCol, i, data, data == NULL); colDataAppend(pOutputCol, i, data, data == NULL);
if(isExist && IS_VAR_DATA_TYPE(value.type) && data){ if (isExist && IS_VAR_DATA_TYPE(value.type) && data) {
taosMemoryFree(data); taosMemoryFree(data);
} }
} }
...@@ -1971,4 +1929,3 @@ _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) { ...@@ -1971,4 +1929,3 @@ _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) {
return NULL; return NULL;
} }
} }
...@@ -32,19 +32,14 @@ ...@@ -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,9 +61,8 @@ void flttInitLogFile() { ...@@ -66,9 +61,8 @@ 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;
vnode->node.resType.type = dataType; vnode->node.resType.type = dataType;
...@@ -84,10 +78,11 @@ void flttMakeValueNode(SNode **pNode, int32_t dataType, void *value) { ...@@ -84,10 +78,11 @@ 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);
SColumnNode *rnode = (SColumnNode *)node; SColumnNode *rnode = (SColumnNode *)node;
rnode->node.resType.type = dataType; rnode->node.resType.type = dataType;
rnode->node.resType.bytes = dataBytes; rnode->node.resType.bytes = dataBytes;
...@@ -106,7 +101,7 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in ...@@ -106,7 +101,7 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in
if (NULL == *block) { if (NULL == *block) {
SSDataBlock *res = createDataBlock(); SSDataBlock *res = createDataBlock();
for (int32_t i = 0; i < 2; ++i) { for (int32_t i = 0; i < 2; ++i) {
SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_NULL, 10, 1+i); SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_NULL, 10, 1 + i);
blockDataAppendColInfo(res, &idata); blockDataAppendColInfo(res, &idata);
} }
...@@ -133,7 +128,7 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in ...@@ -133,7 +128,7 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in
SSDataBlock *res = *block; SSDataBlock *res = *block;
int32_t idx = taosArrayGetSize(res->pDataBlock); int32_t idx = taosArrayGetSize(res->pDataBlock);
SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 1+idx); SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 1 + idx);
blockDataAppendColInfo(res, &idata); blockDataAppendColInfo(res, &idata);
blockDataEnsureCapacity(res, rowNum); blockDataEnsureCapacity(res, rowNum);
...@@ -156,7 +151,7 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in ...@@ -156,7 +151,7 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in
} }
void flttMakeOpNode(SNode **pNode, EOperatorType opType, int32_t resType, SNode *pLeft, SNode *pRight) { void flttMakeOpNode(SNode **pNode, EOperatorType opType, int32_t resType, SNode *pLeft, SNode *pRight) {
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;
onode->node.resType.bytes = tDataTypes[resType].bytes; onode->node.resType.bytes = tDataTypes[resType].bytes;
...@@ -169,7 +164,7 @@ void flttMakeOpNode(SNode **pNode, EOperatorType opType, int32_t resType, SNode ...@@ -169,7 +164,7 @@ void flttMakeOpNode(SNode **pNode, EOperatorType opType, int32_t resType, SNode
} }
void flttMakeLogicNode(SNode **pNode, ELogicConditionType opType, SNode **nodeList, int32_t nodeNum) { void flttMakeLogicNode(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;
onode->condType = opType; onode->condType = opType;
onode->node.resType.type = TSDB_DATA_TYPE_BOOL; onode->node.resType.type = TSDB_DATA_TYPE_BOOL;
...@@ -184,7 +179,7 @@ void flttMakeLogicNode(SNode **pNode, ELogicConditionType opType, SNode **nodeLi ...@@ -184,7 +179,7 @@ void flttMakeLogicNode(SNode **pNode, ELogicConditionType opType, SNode **nodeLi
} }
void flttMakeLogicNodeFromList(SNode **pNode, ELogicConditionType opType, SNodeList *nodeList) { void flttMakeLogicNodeFromList(SNode **pNode, ELogicConditionType opType, SNodeList *nodeList) {
SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION); SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION);
SLogicConditionNode *onode = (SLogicConditionNode *)node; SLogicConditionNode *onode = (SLogicConditionNode *)node;
onode->condType = opType; onode->condType = opType;
onode->node.resType.type = TSDB_DATA_TYPE_BOOL; onode->node.resType.type = TSDB_DATA_TYPE_BOOL;
...@@ -196,7 +191,7 @@ void flttMakeLogicNodeFromList(SNode **pNode, ELogicConditionType opType, SNodeL ...@@ -196,7 +191,7 @@ void flttMakeLogicNodeFromList(SNode **pNode, ELogicConditionType opType, SNodeL
} }
void flttMakeListNode(SNode **pNode, SNodeList *list, int32_t resType) { void flttMakeListNode(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;
lnode->dataType.type = resType; lnode->dataType.type = resType;
lnode->pNodeList = list; lnode->pNodeList = list;
...@@ -204,12 +199,12 @@ void flttMakeListNode(SNode **pNode, SNodeList *list, int32_t resType) { ...@@ -204,12 +199,12 @@ void flttMakeListNode(SNode **pNode, SNodeList *list, int32_t resType) {
*pNode = (SNode *)lnode; *pNode = (SNode *)lnode;
} }
void initScalarParam(SScalarParam* pParam) { void initScalarParam(SScalarParam *pParam) {
memset(pParam, 0, sizeof(SScalarParam)); memset(pParam, 0, sizeof(SScalarParam));
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;
...@@ -222,17 +217,17 @@ TEST(timerangeTest, greater) { ...@@ -222,17 +217,17 @@ TEST(timerangeTest, greater) {
flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall);
flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval); flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval);
//SFilterInfo *filter = NULL; // SFilterInfo *filter = NULL;
//int32_t code = filterInitFromNode(opNode1, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP); // int32_t code = filterInitFromNode(opNode1, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP);
//ASSERT_EQ(code, 0); // ASSERT_EQ(code, 0);
STimeWindow win = {0}; STimeWindow win = {0};
bool isStrict = false; bool isStrict = false;
int32_t code = filterGetTimeRange(opNode1, &win, &isStrict); int32_t code = filterGetTimeRange(opNode1, &win, &isStrict);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
ASSERT_EQ(isStrict, true); ASSERT_EQ(isStrict, true);
ASSERT_EQ(win.skey, tsmall+1); ASSERT_EQ(win.skey, tsmall + 1);
ASSERT_EQ(win.ekey, INT64_MAX); ASSERT_EQ(win.ekey, INT64_MAX);
//filterFreeInfo(filter); // filterFreeInfo(filter);
nodesDestroyNode(opNode1); nodesDestroyNode(opNode1);
} }
...@@ -254,17 +249,17 @@ TEST(timerangeTest, greater_and_lower) { ...@@ -254,17 +249,17 @@ TEST(timerangeTest, greater_and_lower) {
flttMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2); flttMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2);
//SFilterInfo *filter = NULL; // SFilterInfo *filter = NULL;
//int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP); // int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP);
//ASSERT_EQ(code, 0); // ASSERT_EQ(code, 0);
STimeWindow win = {0}; STimeWindow win = {0};
bool isStrict = false; bool isStrict = false;
int32_t code = filterGetTimeRange(logicNode, &win, &isStrict); int32_t code = filterGetTimeRange(logicNode, &win, &isStrict);
ASSERT_EQ(isStrict, true); ASSERT_EQ(isStrict, true);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
ASSERT_EQ(win.skey, tsmall+1); ASSERT_EQ(win.skey, tsmall + 1);
ASSERT_EQ(win.ekey, tbig-1); ASSERT_EQ(win.ekey, tbig - 1);
//filterFreeInfo(filter); // filterFreeInfo(filter);
nodesDestroyNode(logicNode); nodesDestroyNode(logicNode);
} }
...@@ -286,9 +281,9 @@ TEST(timerangeTest, greater_equal_and_lower_equal) { ...@@ -286,9 +281,9 @@ TEST(timerangeTest, greater_equal_and_lower_equal) {
flttMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2); flttMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2);
//SFilterInfo *filter = NULL; // SFilterInfo *filter = NULL;
//int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP); // int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP);
//ASSERT_EQ(code, 0); // ASSERT_EQ(code, 0);
STimeWindow win = {0}; STimeWindow win = {0};
bool isStrict = false; bool isStrict = false;
int32_t code = filterGetTimeRange(logicNode, &win, &isStrict); int32_t code = filterGetTimeRange(logicNode, &win, &isStrict);
...@@ -296,11 +291,10 @@ TEST(timerangeTest, greater_equal_and_lower_equal) { ...@@ -296,11 +291,10 @@ TEST(timerangeTest, greater_equal_and_lower_equal) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
ASSERT_EQ(win.skey, tsmall); ASSERT_EQ(win.skey, tsmall);
ASSERT_EQ(win.ekey, tbig); ASSERT_EQ(win.ekey, tbig);
//filterFreeInfo(filter); // filterFreeInfo(filter);
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};
...@@ -336,31 +330,29 @@ TEST(timerangeTest, greater_and_lower_not_strict) { ...@@ -336,31 +330,29 @@ TEST(timerangeTest, greater_and_lower_not_strict) {
list[1] = logicNode2; list[1] = logicNode2;
flttMakeLogicNode(&logicNode1, LOGIC_COND_TYPE_OR, list, 2); flttMakeLogicNode(&logicNode1, LOGIC_COND_TYPE_OR, list, 2);
//SFilterInfo *filter = NULL; // SFilterInfo *filter = NULL;
//int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP); // int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP);
//ASSERT_EQ(code, 0); // ASSERT_EQ(code, 0);
STimeWindow win = {0}; STimeWindow win = {0};
bool isStrict = false; bool isStrict = false;
int32_t code = filterGetTimeRange(logicNode1, &win, &isStrict); int32_t code = filterGetTimeRange(logicNode1, &win, &isStrict);
ASSERT_EQ(isStrict, false); ASSERT_EQ(isStrict, false);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
ASSERT_EQ(win.skey, tsmall1+1); ASSERT_EQ(win.skey, tsmall1 + 1);
ASSERT_EQ(win.ekey, tbig2-1); ASSERT_EQ(win.ekey, tbig2 - 1);
//filterFreeInfo(filter); // filterFreeInfo(filter);
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};
double rightv= 2.5; double rightv = 2.5;
int8_t eRes[5] = {0, 0, 1, 1, 1}; int8_t eRes[5] = {0, 0, 1, 1, 1};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SScalarParam res; SScalarParam res;
initScalarParam(&res); initScalarParam(&res);
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv);
flttMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
...@@ -388,7 +380,7 @@ TEST(columnTest, smallint_column_greater_double_value) { ...@@ -388,7 +380,7 @@ TEST(columnTest, smallint_column_greater_double_value) {
keep = filterRangeExecute(filter, &stat, 1, rowNum); keep = filterRangeExecute(filter, &stat, 1, rowNum);
ASSERT_EQ(keep, true); ASSERT_EQ(keep, true);
SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -396,7 +388,7 @@ TEST(columnTest, smallint_column_greater_double_value) { ...@@ -396,7 +388,7 @@ TEST(columnTest, smallint_column_greater_double_value) {
stat.min = 1; stat.min = 1;
stat.numOfNull = 0; stat.numOfNull = 0;
int8_t *rowRes = NULL; int8_t *rowRes = NULL;
keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock));
ASSERT_EQ(keep, false); ASSERT_EQ(keep, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
...@@ -410,13 +402,13 @@ TEST(columnTest, smallint_column_greater_double_value) { ...@@ -410,13 +402,13 @@ TEST(columnTest, smallint_column_greater_double_value) {
TEST(columnTest, int_column_greater_smallint_value) { TEST(columnTest, int_column_greater_smallint_value) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
int32_t leftv[5]= {1, 3, 5, 7, 9}; int32_t leftv[5] = {1, 3, 5, 7, 9};
int16_t rightv= 4; int16_t rightv = 4;
int8_t eRes[5] = {0, 0, 1, 1, 1}; int8_t eRes[5] = {0, 0, 1, 1, 1};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SScalarParam res; SScalarParam res;
initScalarParam(&res); initScalarParam(&res);
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv);
flttMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
...@@ -444,7 +436,7 @@ TEST(columnTest, int_column_greater_smallint_value) { ...@@ -444,7 +436,7 @@ TEST(columnTest, int_column_greater_smallint_value) {
keep = filterRangeExecute(filter, &stat, 1, rowNum); keep = filterRangeExecute(filter, &stat, 1, rowNum);
ASSERT_EQ(keep, false); ASSERT_EQ(keep, false);
SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -452,7 +444,7 @@ TEST(columnTest, int_column_greater_smallint_value) { ...@@ -452,7 +444,7 @@ TEST(columnTest, int_column_greater_smallint_value) {
stat.min = 1; stat.min = 1;
stat.numOfNull = 0; stat.numOfNull = 0;
int8_t *rowRes = NULL; int8_t *rowRes = NULL;
keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock));
ASSERT_EQ(keep, false); ASSERT_EQ(keep, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
...@@ -467,21 +459,21 @@ TEST(columnTest, int_column_greater_smallint_value) { ...@@ -467,21 +459,21 @@ TEST(columnTest, int_column_greater_smallint_value) {
TEST(columnTest, int_column_in_double_list) { TEST(columnTest, int_column_in_double_list) {
SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL; SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL;
int32_t leftv[5] = {1, 2, 3, 4, 5}; int32_t leftv[5] = {1, 2, 3, 4, 5};
double rightv1 = 1.1,rightv2 = 2.2,rightv3 = 3.3; double rightv1 = 1.1, rightv2 = 2.2, rightv3 = 3.3;
bool eRes[5] = {true, true, true, false, false}; bool eRes[5] = {true, true, true, false, false};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SScalarParam res; SScalarParam res;
initScalarParam(&res); initScalarParam(&res);
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv);
SNodeList* list = nodesMakeList(); SNodeList *list = nodesMakeList();
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv1); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv1);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv2); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv2);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv3); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv3);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
flttMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT); flttMakeListNode(&listNode, list, TSDB_DATA_TYPE_INT);
flttMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); flttMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
...@@ -489,7 +481,7 @@ TEST(columnTest, int_column_in_double_list) { ...@@ -489,7 +481,7 @@ TEST(columnTest, int_column_in_double_list) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -497,7 +489,7 @@ TEST(columnTest, int_column_in_double_list) { ...@@ -497,7 +489,7 @@ TEST(columnTest, int_column_in_double_list) {
stat.min = 1; stat.min = 1;
stat.numOfNull = 0; stat.numOfNull = 0;
int8_t *rowRes = NULL; int8_t *rowRes = NULL;
bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock));
ASSERT_EQ(keep, false); ASSERT_EQ(keep, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
...@@ -516,8 +508,8 @@ TEST(columnTest, binary_column_in_binary_list) { ...@@ -516,8 +508,8 @@ TEST(columnTest, binary_column_in_binary_list) {
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SScalarParam res; SScalarParam res;
initScalarParam(&res); initScalarParam(&res);
char leftv[5][5]= {0}; char leftv[5][5] = {0};
char rightv[3][5]= {0}; char rightv[3][5] = {0};
for (int32_t i = 0; i < 5; ++i) { for (int32_t i = 0; i < 5; ++i) {
leftv[i][2] = 'a' + i; leftv[i][2] = 'a' + i;
leftv[i][3] = 'b' + i; leftv[i][3] = 'b' + i;
...@@ -537,16 +529,16 @@ TEST(columnTest, binary_column_in_binary_list) { ...@@ -537,16 +529,16 @@ TEST(columnTest, binary_column_in_binary_list) {
varDataSetLen(rightv[i], 3); varDataSetLen(rightv[i], 3);
} }
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
SNodeList* list = nodesMakeList(); SNodeList *list = nodesMakeList();
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[0]); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[0]);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[1]); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[1]);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[2]); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[2]);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
flttMakeListNode(&listNode,list, TSDB_DATA_TYPE_BINARY); flttMakeListNode(&listNode, list, TSDB_DATA_TYPE_BINARY);
flttMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); flttMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
...@@ -554,7 +546,7 @@ TEST(columnTest, binary_column_in_binary_list) { ...@@ -554,7 +546,7 @@ TEST(columnTest, binary_column_in_binary_list) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -562,7 +554,7 @@ TEST(columnTest, binary_column_in_binary_list) { ...@@ -562,7 +554,7 @@ TEST(columnTest, binary_column_in_binary_list) {
stat.min = 1; stat.min = 1;
stat.numOfNull = 0; stat.numOfNull = 0;
int8_t *rowRes = NULL; int8_t *rowRes = NULL;
bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock));
ASSERT_EQ(keep, false); ASSERT_EQ(keep, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
...@@ -577,7 +569,7 @@ TEST(columnTest, binary_column_in_binary_list) { ...@@ -577,7 +569,7 @@ TEST(columnTest, binary_column_in_binary_list) {
TEST(columnTest, binary_column_like_binary) { TEST(columnTest, binary_column_like_binary) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
char rightv[64] = {0}; char rightv[64] = {0};
char leftv[5][5]= {0}; char leftv[5][5] = {0};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SScalarParam res; SScalarParam res;
initScalarParam(&res); initScalarParam(&res);
...@@ -590,7 +582,7 @@ TEST(columnTest, binary_column_like_binary) { ...@@ -590,7 +582,7 @@ TEST(columnTest, binary_column_like_binary) {
varDataSetLen(leftv[i], 3); varDataSetLen(leftv[i], 3);
} }
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
sprintf(&rightv[2], "%s", "__0"); sprintf(&rightv[2], "%s", "__0");
...@@ -603,7 +595,7 @@ TEST(columnTest, binary_column_like_binary) { ...@@ -603,7 +595,7 @@ TEST(columnTest, binary_column_like_binary) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -611,7 +603,7 @@ TEST(columnTest, binary_column_like_binary) { ...@@ -611,7 +603,7 @@ TEST(columnTest, binary_column_like_binary) {
stat.min = 1; stat.min = 1;
stat.numOfNull = 0; stat.numOfNull = 0;
int8_t *rowRes = NULL; int8_t *rowRes = NULL;
bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock));
ASSERT_EQ(keep, false); ASSERT_EQ(keep, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
...@@ -625,7 +617,7 @@ TEST(columnTest, binary_column_like_binary) { ...@@ -625,7 +617,7 @@ TEST(columnTest, binary_column_like_binary) {
TEST(columnTest, binary_column_is_null) { TEST(columnTest, binary_column_is_null) {
SNode *pLeft = NULL, *opNode = NULL; SNode *pLeft = NULL, *opNode = NULL;
char leftv[5][5]= {0}; char leftv[5][5] = {0};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SScalarParam res; SScalarParam res;
initScalarParam(&res); initScalarParam(&res);
...@@ -638,7 +630,7 @@ TEST(columnTest, binary_column_is_null) { ...@@ -638,7 +630,7 @@ TEST(columnTest, binary_column_is_null) {
varDataSetLen(leftv[i], 3); varDataSetLen(leftv[i], 3);
} }
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock); SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock);
...@@ -651,7 +643,7 @@ TEST(columnTest, binary_column_is_null) { ...@@ -651,7 +643,7 @@ TEST(columnTest, binary_column_is_null) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -659,7 +651,7 @@ TEST(columnTest, binary_column_is_null) { ...@@ -659,7 +651,7 @@ TEST(columnTest, binary_column_is_null) {
stat.min = 1; stat.min = 1;
stat.numOfNull = 0; stat.numOfNull = 0;
int8_t *rowRes = NULL; int8_t *rowRes = NULL;
bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock));
ASSERT_EQ(keep, false); ASSERT_EQ(keep, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
...@@ -673,7 +665,7 @@ TEST(columnTest, binary_column_is_null) { ...@@ -673,7 +665,7 @@ TEST(columnTest, binary_column_is_null) {
TEST(columnTest, binary_column_is_not_null) { TEST(columnTest, binary_column_is_not_null) {
SNode *pLeft = NULL, *opNode = NULL; SNode *pLeft = NULL, *opNode = NULL;
char leftv[5][5]= {0}; char leftv[5][5] = {0};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SScalarParam res; SScalarParam res;
initScalarParam(&res); initScalarParam(&res);
...@@ -686,7 +678,7 @@ TEST(columnTest, binary_column_is_not_null) { ...@@ -686,7 +678,7 @@ TEST(columnTest, binary_column_is_not_null) {
varDataSetLen(leftv[i], 3); varDataSetLen(leftv[i], 3);
} }
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock); SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock);
...@@ -699,7 +691,7 @@ TEST(columnTest, binary_column_is_not_null) { ...@@ -699,7 +691,7 @@ TEST(columnTest, binary_column_is_not_null) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -707,7 +699,7 @@ TEST(columnTest, binary_column_is_not_null) { ...@@ -707,7 +699,7 @@ TEST(columnTest, binary_column_is_not_null) {
stat.min = 1; stat.min = 1;
stat.numOfNull = 0; stat.numOfNull = 0;
int8_t *rowRes = NULL; int8_t *rowRes = NULL;
bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock));
ASSERT_EQ(keep, false); ASSERT_EQ(keep, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
...@@ -722,12 +714,12 @@ TEST(columnTest, binary_column_is_not_null) { ...@@ -722,12 +714,12 @@ TEST(columnTest, binary_column_is_not_null) {
TEST(opTest, smallint_column_greater_int_column) { TEST(opTest, smallint_column_greater_int_column) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
int16_t leftv[5] = {1, -6, -2, 11, 101}; int16_t leftv[5] = {1, -6, -2, 11, 101};
int32_t rightv[5]= {0, -5, -4, 23, 100}; int32_t rightv[5] = {0, -5, -4, 23, 100};
bool eRes[5] = {true, false, true, false, true}; bool eRes[5] = {true, false, true, false, true};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SScalarParam res; SScalarParam res;
initScalarParam(&res); initScalarParam(&res);
int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]);
flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, rightv); flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, rightv);
flttMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
...@@ -737,7 +729,7 @@ TEST(opTest, smallint_column_greater_int_column) { ...@@ -737,7 +729,7 @@ TEST(opTest, smallint_column_greater_int_column) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -745,7 +737,7 @@ TEST(opTest, smallint_column_greater_int_column) { ...@@ -745,7 +737,7 @@ TEST(opTest, smallint_column_greater_int_column) {
stat.min = 1; stat.min = 1;
stat.numOfNull = 0; stat.numOfNull = 0;
int8_t *rowRes = NULL; int8_t *rowRes = NULL;
bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock));
ASSERT_EQ(keep, false); ASSERT_EQ(keep, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
...@@ -760,12 +752,12 @@ TEST(opTest, smallint_column_greater_int_column) { ...@@ -760,12 +752,12 @@ TEST(opTest, smallint_column_greater_int_column) {
TEST(opTest, smallint_value_add_int_column) { TEST(opTest, smallint_value_add_int_column) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
int32_t leftv = 1; int32_t leftv = 1;
int16_t rightv[5]= {0, -1, -4, -1, 100}; int16_t rightv[5] = {0, -1, -4, -1, 100};
bool eRes[5] = {true, false, true, false, true}; bool eRes[5] = {true, false, true, false, true};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SScalarParam res; SScalarParam res;
initScalarParam(&res); initScalarParam(&res);
int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]);
flttMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); flttMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, rightv); flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, rightv);
flttMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
...@@ -776,7 +768,7 @@ TEST(opTest, smallint_value_add_int_column) { ...@@ -776,7 +768,7 @@ TEST(opTest, smallint_value_add_int_column) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -784,7 +776,7 @@ TEST(opTest, smallint_value_add_int_column) { ...@@ -784,7 +776,7 @@ TEST(opTest, smallint_value_add_int_column) {
stat.min = 1; stat.min = 1;
stat.numOfNull = 0; stat.numOfNull = 0;
int8_t *rowRes = NULL; int8_t *rowRes = NULL;
bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock));
ASSERT_EQ(keep, false); ASSERT_EQ(keep, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
...@@ -798,8 +790,8 @@ TEST(opTest, smallint_value_add_int_column) { ...@@ -798,8 +790,8 @@ TEST(opTest, smallint_value_add_int_column) {
TEST(opTest, bigint_column_multi_binary_column) { TEST(opTest, bigint_column_multi_binary_column) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
int64_t leftv[5]= {1, 2, 3, 4, 5}; int64_t leftv[5] = {1, 2, 3, 4, 5};
char rightv[5][5]= {0}; char rightv[5][5] = {0};
for (int32_t i = 0; i < 5; ++i) { for (int32_t i = 0; i < 5; ++i) {
rightv[i][2] = rightv[i][3] = '0'; rightv[i][2] = rightv[i][3] = '0';
rightv[i][4] = '0' + i; rightv[i][4] = '0' + i;
...@@ -809,7 +801,7 @@ TEST(opTest, bigint_column_multi_binary_column) { ...@@ -809,7 +801,7 @@ TEST(opTest, bigint_column_multi_binary_column) {
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SScalarParam res; SScalarParam res;
initScalarParam(&res); initScalarParam(&res);
int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]);
flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), rowNum, leftv); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), rowNum, leftv);
flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv); flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv);
flttMakeOpNode(&opNode, OP_TYPE_MULTI, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_MULTI, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
...@@ -820,7 +812,7 @@ TEST(opTest, bigint_column_multi_binary_column) { ...@@ -820,7 +812,7 @@ TEST(opTest, bigint_column_multi_binary_column) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -828,7 +820,7 @@ TEST(opTest, bigint_column_multi_binary_column) { ...@@ -828,7 +820,7 @@ TEST(opTest, bigint_column_multi_binary_column) {
stat.min = 1; stat.min = 1;
stat.numOfNull = 0; stat.numOfNull = 0;
int8_t *rowRes = NULL; int8_t *rowRes = NULL;
bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock));
ASSERT_EQ(keep, false); ASSERT_EQ(keep, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
...@@ -842,8 +834,8 @@ TEST(opTest, bigint_column_multi_binary_column) { ...@@ -842,8 +834,8 @@ TEST(opTest, bigint_column_multi_binary_column) {
TEST(opTest, smallint_column_and_binary_column) { TEST(opTest, smallint_column_and_binary_column) {
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};
char rightv[5][5]= {0}; char rightv[5][5] = {0};
for (int32_t i = 0; i < 5; ++i) { for (int32_t i = 0; i < 5; ++i) {
rightv[i][2] = rightv[i][3] = '0'; rightv[i][2] = rightv[i][3] = '0';
rightv[i][4] = '0' + i; rightv[i][4] = '0' + i;
...@@ -853,7 +845,7 @@ TEST(opTest, smallint_column_and_binary_column) { ...@@ -853,7 +845,7 @@ TEST(opTest, smallint_column_and_binary_column) {
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SScalarParam res; SScalarParam res;
initScalarParam(&res); initScalarParam(&res);
int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]);
flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv); flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv);
flttMakeOpNode(&opNode, OP_TYPE_BIT_AND, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_BIT_AND, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
...@@ -864,7 +856,7 @@ TEST(opTest, smallint_column_and_binary_column) { ...@@ -864,7 +856,7 @@ TEST(opTest, smallint_column_and_binary_column) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -872,7 +864,7 @@ TEST(opTest, smallint_column_and_binary_column) { ...@@ -872,7 +864,7 @@ TEST(opTest, smallint_column_and_binary_column) {
stat.min = 1; stat.min = 1;
stat.numOfNull = 0; stat.numOfNull = 0;
int8_t *rowRes = NULL; int8_t *rowRes = NULL;
bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock));
ASSERT_EQ(keep, false); ASSERT_EQ(keep, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
...@@ -886,13 +878,13 @@ TEST(opTest, smallint_column_and_binary_column) { ...@@ -886,13 +878,13 @@ TEST(opTest, smallint_column_and_binary_column) {
TEST(opTest, smallint_column_or_float_column) { TEST(opTest, smallint_column_or_float_column) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
int16_t leftv[5]= {1, 2, 0, 4, 5}; int16_t leftv[5] = {1, 2, 0, 4, 5};
float rightv[5]= {2.0, 3.0, 0, 5.2, 6.0}; float rightv[5] = {2.0, 3.0, 0, 5.2, 6.0};
bool eRes[5] = {true, true, false, true, true}; bool eRes[5] = {true, true, false, true, true};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SScalarParam res; SScalarParam res;
initScalarParam(&res); initScalarParam(&res);
int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]);
flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_FLOAT, sizeof(float), rowNum, rightv); flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_FLOAT, sizeof(float), rowNum, rightv);
flttMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
...@@ -903,7 +895,7 @@ TEST(opTest, smallint_column_or_float_column) { ...@@ -903,7 +895,7 @@ TEST(opTest, smallint_column_or_float_column) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -925,13 +917,13 @@ TEST(opTest, smallint_column_or_float_column) { ...@@ -925,13 +917,13 @@ TEST(opTest, smallint_column_or_float_column) {
TEST(opTest, smallint_column_or_double_value) { TEST(opTest, smallint_column_or_double_value) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
int16_t leftv[5]= {0, 2, 3, 0, -1}; int16_t leftv[5] = {0, 2, 3, 0, -1};
double rightv= 10.2; double rightv = 10.2;
bool eRes[5] = {true, true, true, true, true}; bool eRes[5] = {true, true, true, true, true};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SScalarParam res; SScalarParam res;
initScalarParam(&res); initScalarParam(&res);
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv);
flttMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
...@@ -942,7 +934,7 @@ TEST(opTest, smallint_column_or_double_value) { ...@@ -942,7 +934,7 @@ TEST(opTest, smallint_column_or_double_value) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -964,7 +956,7 @@ TEST(opTest, smallint_column_or_double_value) { ...@@ -964,7 +956,7 @@ TEST(opTest, smallint_column_or_double_value) {
TEST(opTest, binary_column_is_true) { TEST(opTest, binary_column_is_true) {
SNode *pLeft = NULL, *opNode = NULL; SNode *pLeft = NULL, *opNode = NULL;
char leftv[5][5]= {0}; char leftv[5][5] = {0};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SScalarParam res; SScalarParam res;
initScalarParam(&res); initScalarParam(&res);
...@@ -977,7 +969,7 @@ TEST(opTest, binary_column_is_true) { ...@@ -977,7 +969,7 @@ TEST(opTest, binary_column_is_true) {
varDataSetLen(leftv[i], 3); varDataSetLen(leftv[i], 3);
} }
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, pLeft, NULL); flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, pLeft, NULL);
...@@ -987,7 +979,7 @@ TEST(opTest, binary_column_is_true) { ...@@ -987,7 +979,7 @@ TEST(opTest, binary_column_is_true) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -1012,14 +1004,14 @@ TEST(filterModelogicTest, diff_columns_and_or_and) { ...@@ -1012,14 +1004,14 @@ TEST(filterModelogicTest, diff_columns_and_or_and) {
SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL; SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL;
SNode *logicNode1 = NULL, *logicNode2 = NULL; SNode *logicNode1 = NULL, *logicNode2 = NULL;
double leftv1[8]= {1, 2, 3, 4, 5,-1,-2,-3}, leftv2[8]= {3.0, 4, 2, 9, -3, 3.9, 4.1, 5.2}; double leftv1[8] = {1, 2, 3, 4, 5, -1, -2, -3}, leftv2[8] = {3.0, 4, 2, 9, -3, 3.9, 4.1, 5.2};
int32_t rightv1= 3, rightv2= 3; int32_t rightv1 = 3, rightv2 = 3;
int8_t eRes[8] = {1, 1, 0, 0, 1, 1, 1, 1}; int8_t eRes[8] = {1, 1, 0, 0, 1, 1, 1, 1};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SNodeList* list = nodesMakeList(); SNodeList *list = nodesMakeList();
int32_t rowNum = sizeof(leftv1)/sizeof(leftv1[0]); int32_t rowNum = sizeof(leftv1) / sizeof(leftv1[0]);
flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1);
flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv1); flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv1);
flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1); flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1);
...@@ -1032,7 +1024,6 @@ TEST(filterModelogicTest, diff_columns_and_or_and) { ...@@ -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,13 +1043,12 @@ TEST(filterModelogicTest, diff_columns_and_or_and) { ...@@ -1052,13 +1043,12 @@ 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);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -1081,14 +1071,14 @@ TEST(filterModelogicTest, diff_columns_and_or_and) { ...@@ -1081,14 +1071,14 @@ TEST(filterModelogicTest, diff_columns_and_or_and) {
TEST(filterModelogicTest, same_column_and_or_and) { TEST(filterModelogicTest, same_column_and_or_and) {
SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL; SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL;
SNode *logicNode1 = NULL, *logicNode2 = NULL; SNode *logicNode1 = NULL, *logicNode2 = NULL;
double leftv1[8]= {1, 2, 3, 4, 5,-1,-2,-3}; double leftv1[8] = {1, 2, 3, 4, 5, -1, -2, -3};
int32_t rightv1= 3, rightv2= 0, rightv3 = 2, rightv4 = -2; int32_t rightv1 = 3, rightv2 = 0, rightv3 = 2, rightv4 = -2;
int8_t eRes[8] = {1, 1, 0, 0, 0, 1, 1, 0}; int8_t eRes[8] = {1, 1, 0, 0, 0, 1, 1, 0};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SNodeList* list = nodesMakeList(); SNodeList *list = nodesMakeList();
int32_t rowNum = sizeof(leftv1)/sizeof(leftv1[0]); int32_t rowNum = sizeof(leftv1) / sizeof(leftv1[0]);
flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1);
flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv1); flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv1);
flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1); flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1);
...@@ -1101,7 +1091,6 @@ TEST(filterModelogicTest, same_column_and_or_and) { ...@@ -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,13 +1110,12 @@ TEST(filterModelogicTest, same_column_and_or_and) { ...@@ -1121,13 +1110,12 @@ 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);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -1150,14 +1138,14 @@ TEST(filterModelogicTest, same_column_and_or_and) { ...@@ -1150,14 +1138,14 @@ TEST(filterModelogicTest, same_column_and_or_and) {
TEST(filterModelogicTest, diff_columns_or_and_or) { TEST(filterModelogicTest, diff_columns_or_and_or) {
SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL; SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL;
SNode *logicNode1 = NULL, *logicNode2 = NULL; SNode *logicNode1 = NULL, *logicNode2 = NULL;
double leftv1[8]= {1, 2, 3, 4, 5,-1,-2,-3}, leftv2[8]= {3.0, 4, 2, 9, -3, 3.9, 4.1, 5.2}; double leftv1[8] = {1, 2, 3, 4, 5, -1, -2, -3}, leftv2[8] = {3.0, 4, 2, 9, -3, 3.9, 4.1, 5.2};
int32_t rightv1= 3, rightv2= 3; int32_t rightv1 = 3, rightv2 = 3;
int8_t eRes[8] = {1, 0, 1, 1, 0, 0, 0, 0}; int8_t eRes[8] = {1, 0, 1, 1, 0, 0, 0, 0};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SNodeList* list = nodesMakeList(); SNodeList *list = nodesMakeList();
int32_t rowNum = sizeof(leftv1)/sizeof(leftv1[0]); int32_t rowNum = sizeof(leftv1) / sizeof(leftv1[0]);
flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1);
flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv1); flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv1);
flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1); flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1);
...@@ -1170,7 +1158,6 @@ TEST(filterModelogicTest, diff_columns_or_and_or) { ...@@ -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,13 +1177,12 @@ TEST(filterModelogicTest, diff_columns_or_and_or) { ...@@ -1190,13 +1177,12 @@ 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);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -1219,14 +1205,14 @@ TEST(filterModelogicTest, diff_columns_or_and_or) { ...@@ -1219,14 +1205,14 @@ TEST(filterModelogicTest, diff_columns_or_and_or) {
TEST(filterModelogicTest, same_column_or_and_or) { TEST(filterModelogicTest, same_column_or_and_or) {
SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL; SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL;
SNode *logicNode1 = NULL, *logicNode2 = NULL; SNode *logicNode1 = NULL, *logicNode2 = NULL;
double leftv1[8]= {1, 2, 3, 4, 5,-1,-2,-3}; double leftv1[8] = {1, 2, 3, 4, 5, -1, -2, -3};
int32_t rightv1= 3, rightv2= 0, rightv3 = 2, rightv4 = -2; int32_t rightv1 = 3, rightv2 = 0, rightv3 = 2, rightv4 = -2;
int8_t eRes[8] = {0, 0, 0, 1, 1, 1, 1, 1}; int8_t eRes[8] = {0, 0, 0, 1, 1, 1, 1, 1};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SNodeList* list = nodesMakeList(); SNodeList *list = nodesMakeList();
int32_t rowNum = sizeof(leftv1)/sizeof(leftv1[0]); int32_t rowNum = sizeof(leftv1) / sizeof(leftv1[0]);
flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1);
flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv1); flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv1);
flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1); flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1);
...@@ -1239,7 +1225,6 @@ TEST(filterModelogicTest, same_column_or_and_or) { ...@@ -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,13 +1244,12 @@ TEST(filterModelogicTest, same_column_or_and_or) { ...@@ -1259,13 +1244,12 @@ 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);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -1290,14 +1274,14 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { ...@@ -1290,14 +1274,14 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) {
SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL; SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL;
SNode *logicNode1 = NULL, *logicNode2 = NULL; SNode *logicNode1 = NULL, *logicNode2 = NULL;
double leftv1[8] = {1, 2, 3, 4, 5,-1,-2,-3}, leftv2[8]= {3.0, 4, 2, 9, -3, 3.9, 4.1, 5.2}; double leftv1[8] = {1, 2, 3, 4, 5, -1, -2, -3}, leftv2[8] = {3.0, 4, 2, 9, -3, 3.9, 4.1, 5.2};
int32_t rightv1[8]= {5, 8, 2, -3, 9,-7,10, 0}, rightv2[8]= {-3, 5, 8, 2, -9, 11, -4, 0}; int32_t rightv1[8] = {5, 8, 2, -3, 9, -7, 10, 0}, rightv2[8] = {-3, 5, 8, 2, -9, 11, -4, 0};
int8_t eRes[8] = {0, 1, 1, 0, 0, 1, 0, 0}; int8_t eRes[8] = {0, 1, 1, 0, 0, 1, 0, 0};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
SNodeList* list = nodesMakeList(); SNodeList *list = nodesMakeList();
int32_t rowNum = sizeof(leftv1)/sizeof(leftv1[0]); int32_t rowNum = sizeof(leftv1) / sizeof(leftv1[0]);
flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1);
flttMakeColumnNode(&pRight1, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, rightv1); flttMakeColumnNode(&pRight1, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, rightv1);
flttMakeOpNode(&opNode1, OP_TYPE_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1); flttMakeOpNode(&opNode1, OP_TYPE_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1);
...@@ -1310,7 +1294,6 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { ...@@ -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,13 +1313,12 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { ...@@ -1330,13 +1313,12 @@ 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);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, &param); code = filterSetDataFromSlotId(filter, &param);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -1356,7 +1338,7 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { ...@@ -1356,7 +1338,7 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) {
blockDataDestroy(src); blockDataDestroy(src);
} }
int main(int argc, char** argv) { int main(int argc, char **argv) {
taosSeedRand(taosGetTimestampSec()); taosSeedRand(taosGetTimestampSec());
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
......
/* /*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com> * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
* *
* This program is free software: you can use, redistribute, and/or modify * This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3 * it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation. * or later ("AGPL"), as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. * FITNESS FOR A PARTICULAR PURPOSE.
* *
* 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 <gtest/gtest.h> #include <gtest/gtest.h>
#include <iostream> #include <iostream>
...@@ -32,17 +32,17 @@ ...@@ -32,17 +32,17 @@
#endif #endif
#include "os.h" #include "os.h"
#include "tglobal.h" #include "filterInt.h"
#include "nodes.h"
#include "parUtil.h"
#include "scalar.h"
#include "stub.h"
#include "taos.h" #include "taos.h"
#include "tdef.h"
#include "tvariant.h"
#include "tdatablock.h" #include "tdatablock.h"
#include "stub.h" #include "tdef.h"
#include "scalar.h" #include "tglobal.h"
#include "nodes.h"
#include "tlog.h" #include "tlog.h"
#include "parUtil.h" #include "tvariant.h"
#include "filterInt.h"
#define _DEBUG_PRINT_ 0 #define _DEBUG_PRINT_ 0
...@@ -65,9 +65,7 @@ SColumnInfo createColumnInfo(int32_t colId, int32_t type, int32_t bytes) { ...@@ -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() { ...@@ -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();
...@@ -94,7 +93,7 @@ void scltAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *s ...@@ -94,7 +93,7 @@ void scltAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *s
res->info.capacity = rows; res->info.capacity = rows;
res->info.rows = rows; res->info.rows = rows;
SColumnInfoData* p = static_cast<SColumnInfoData *>(taosArrayGet(res->pDataBlock, 0)); SColumnInfoData *p = static_cast<SColumnInfoData *>(taosArrayGet(res->pDataBlock, 0));
ASSERT(p->pData != NULL && p->nullbitmap != NULL); ASSERT(p->pData != NULL && p->nullbitmap != NULL);
taosArrayPush(pBlockList, &res); taosArrayPush(pBlockList, &res);
...@@ -114,7 +113,7 @@ void scltAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *s ...@@ -114,7 +113,7 @@ void scltAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *s
} }
void scltMakeValueNode(SNode **pNode, int32_t dataType, void *value) { void scltMakeValueNode(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;
vnode->node.resType.type = dataType; vnode->node.resType.type = dataType;
...@@ -130,8 +129,9 @@ void scltMakeValueNode(SNode **pNode, int32_t dataType, void *value) { ...@@ -130,8 +129,9 @@ 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,
SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_COLUMN); void *value) {
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;
rnode->node.resType.bytes = dataBytes; rnode->node.resType.bytes = dataBytes;
...@@ -198,17 +198,18 @@ void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in ...@@ -198,17 +198,18 @@ 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,
SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_OPERATOR); bool isReverse) {
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;
onode->node.resType.bytes = tDataTypes[resType].bytes; onode->node.resType.bytes = tDataTypes[resType].bytes;
onode->opType = opType; onode->opType = opType;
if(isReverse){ if (isReverse) {
onode->pLeft = pRight; onode->pLeft = pRight;
onode->pRight = pLeft; onode->pRight = pLeft;
}else{ } else {
onode->pLeft = pLeft; onode->pLeft = pLeft;
onode->pRight = pRight; onode->pRight = pRight;
} }
...@@ -217,7 +218,7 @@ void scltMakeOpNode2(SNode **pNode, EOperatorType opType, int32_t resType, SNode ...@@ -217,7 +218,7 @@ void scltMakeOpNode2(SNode **pNode, EOperatorType opType, int32_t resType, SNode
} }
void scltMakeOpNode(SNode **pNode, EOperatorType opType, int32_t resType, SNode *pLeft, SNode *pRight) { void scltMakeOpNode(SNode **pNode, EOperatorType opType, int32_t resType, SNode *pLeft, SNode *pRight) {
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;
onode->node.resType.bytes = tDataTypes[resType].bytes; onode->node.resType.bytes = tDataTypes[resType].bytes;
...@@ -229,9 +230,8 @@ void scltMakeOpNode(SNode **pNode, EOperatorType opType, int32_t resType, SNode ...@@ -229,9 +230,8 @@ 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;
lnode->dataType.type = resType; lnode->dataType.type = resType;
lnode->pNodeList = list; lnode->pNodeList = list;
...@@ -239,9 +239,8 @@ void scltMakeListNode(SNode **pNode, SNodeList *list, int32_t resType) { ...@@ -239,9 +239,8 @@ 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;
onode->condType = opType; onode->condType = opType;
onode->node.resType.type = TSDB_DATA_TYPE_BOOL; onode->node.resType.type = TSDB_DATA_TYPE_BOOL;
...@@ -256,7 +255,7 @@ void scltMakeLogicNode(SNode **pNode, ELogicConditionType opType, SNode **nodeLi ...@@ -256,7 +255,7 @@ void scltMakeLogicNode(SNode **pNode, ELogicConditionType opType, SNode **nodeLi
} }
void scltMakeTargetNode(SNode **pNode, int16_t dataBlockId, int16_t slotId, SNode *snode) { void scltMakeTargetNode(SNode **pNode, int16_t dataBlockId, int16_t slotId, SNode *snode) {
SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_TARGET); SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_TARGET);
STargetNode *onode = (STargetNode *)node; STargetNode *onode = (STargetNode *)node;
onode->pExpr = snode; onode->pExpr = snode;
onode->dataBlockId = dataBlockId; onode->dataBlockId = dataBlockId;
...@@ -264,7 +263,7 @@ void scltMakeTargetNode(SNode **pNode, int16_t dataBlockId, int16_t slotId, SNod ...@@ -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;
...@@ -491,16 +490,16 @@ TEST(constantTest, int_in_smallint1) { ...@@ -491,16 +490,16 @@ TEST(constantTest, int_in_smallint1) {
scltInitLogFile(); scltInitLogFile();
SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL; SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL;
int32_t leftv = 1, rightv1 = 1,rightv2 = 2,rightv3 = 3; int32_t leftv = 1, rightv1 = 1, rightv2 = 2, rightv3 = 3;
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
SNodeList* list = nodesMakeList(); SNodeList *list = nodesMakeList();
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT); scltMakeListNode(&listNode, list, TSDB_DATA_TYPE_INT);
scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
int32_t code = scalarCalculateConstants(opNode, &res); int32_t code = scalarCalculateConstants(opNode, &res);
...@@ -517,16 +516,16 @@ TEST(constantTest, int_in_smallint2) { ...@@ -517,16 +516,16 @@ TEST(constantTest, int_in_smallint2) {
scltInitLogFile(); scltInitLogFile();
SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL; SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL;
int32_t leftv = 4, rightv1 = 1,rightv2 = 2,rightv3 = 3; int32_t leftv = 4, rightv1 = 1, rightv2 = 2, rightv3 = 3;
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
SNodeList* list = nodesMakeList(); SNodeList *list = nodesMakeList();
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT); scltMakeListNode(&listNode, list, TSDB_DATA_TYPE_INT);
scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
int32_t code = scalarCalculateConstants(opNode, &res); int32_t code = scalarCalculateConstants(opNode, &res);
...@@ -541,16 +540,16 @@ TEST(constantTest, int_in_smallint2) { ...@@ -541,16 +540,16 @@ TEST(constantTest, int_in_smallint2) {
TEST(constantTest, int_not_in_smallint1) { TEST(constantTest, int_not_in_smallint1) {
SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL; SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL;
int32_t leftv = 1, rightv1 = 1,rightv2 = 2,rightv3 = 3; int32_t leftv = 1, rightv1 = 1, rightv2 = 2, rightv3 = 3;
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
SNodeList* list = nodesMakeList(); SNodeList *list = nodesMakeList();
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT); scltMakeListNode(&listNode, list, TSDB_DATA_TYPE_INT);
scltMakeOpNode(&opNode, OP_TYPE_NOT_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); scltMakeOpNode(&opNode, OP_TYPE_NOT_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
int32_t code = scalarCalculateConstants(opNode, &res); int32_t code = scalarCalculateConstants(opNode, &res);
...@@ -567,16 +566,16 @@ TEST(constantTest, int_not_in_smallint2) { ...@@ -567,16 +566,16 @@ TEST(constantTest, int_not_in_smallint2) {
scltInitLogFile(); scltInitLogFile();
SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL; SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL;
int32_t leftv = 4, rightv1 = 1,rightv2 = 2,rightv3 = 3; int32_t leftv = 4, rightv1 = 1, rightv2 = 2, rightv3 = 3;
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
SNodeList* list = nodesMakeList(); SNodeList *list = nodesMakeList();
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT); scltMakeListNode(&listNode, list, TSDB_DATA_TYPE_INT);
scltMakeOpNode(&opNode, OP_TYPE_NOT_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); scltMakeOpNode(&opNode, OP_TYPE_NOT_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
int32_t code = scalarCalculateConstants(opNode, &res); int32_t code = scalarCalculateConstants(opNode, &res);
...@@ -1028,31 +1027,30 @@ TEST(constantTest, column_and_value4) { ...@@ -1028,31 +1027,30 @@ 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));
varDataLen(keyVar) = strlen(key); varDataLen(keyVar) = strlen(key);
SNode *pLeft = NULL, *pRight = NULL; SNode *pLeft = NULL, *pRight = NULL;
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, keyVar); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, keyVar);
scltMakeColumnNode(&pLeft, src, TSDB_DATA_TYPE_JSON, ((STag*)json)->len, 1, json); scltMakeColumnNode(&pLeft, src, TSDB_DATA_TYPE_JSON, ((STag *)json)->len, 1, json);
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) {
resType = TSDB_DATA_TYPE_BOOL; resType = TSDB_DATA_TYPE_BOOL;
} }
...@@ -1066,12 +1064,13 @@ void makeOperator(SNode **opNode, SArray *blockList, EOperatorType opType, int32 ...@@ -1066,12 +1064,13 @@ 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;
makeJsonArrow(&src, &opNode, json, (char*)key); makeJsonArrow(&src, &opNode, json, (char *)key);
taosArrayPush(blockList, &src); taosArrayPush(blockList, &src);
makeOperator(&opNode, blockList, opType, rightType, rightData, isReverse); makeOperator(&opNode, blockList, opType, rightType, rightData, isReverse);
...@@ -1083,21 +1082,24 @@ void makeCalculate(void *json, void *key, int32_t rightType, void *rightData, do ...@@ -1083,21 +1082,24 @@ void makeCalculate(void *json, void *key, int32_t rightType, void *rightData, do
ASSERT_EQ(res->info.rows, 1); ASSERT_EQ(res->info.rows, 1);
SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
if(colDataIsNull_f(column->nullbitmap, 0)){ if (colDataIsNull_f(column->nullbitmap, 0)) {
ASSERT_EQ(DBL_MAX, exceptValue); ASSERT_EQ(DBL_MAX, exceptValue);
printf("result:NULL\n"); printf("result:NULL\n");
}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,12 +1110,14 @@ void makeCalculate(void *json, void *key, int32_t rightType, void *rightData, do ...@@ -1108,12 +1110,14 @@ 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));
SArray *tags = taosArrayInit(1, sizeof(STagVal)); SArray *tags = taosArrayInit(1, sizeof(STagVal));
STag* row = NULL; STag *row = NULL;
parseJsontoTagData(rightv, tags, &row, NULL); parseJsontoTagData(rightv, tags, &row, NULL);
const int32_t len = 8; const int32_t len = 8;
...@@ -1123,12 +1127,12 @@ TEST(columnTest, json_column_arith_op) { ...@@ -1123,12 +1127,12 @@ TEST(columnTest, json_column_arith_op) {
printf("--------------------json int-4 op {1, 8, 2, 2, 3, 0, -4, 9}--------------------\n"); printf("--------------------json int-4 op {1, 8, 2, 2, 3, 0, -4, 9}--------------------\n");
char *key = "k1"; char *key = "k1";
double eRes00[len] = {5.0, -4, 8.0, 2.0, 1.0, -4, 4&-4, 4|9}; double eRes00[len] = {5.0, -4, 8.0, 2.0, 1.0, -4, 4 & -4, 4 | 9};
double eRes01[len] = {5.0, 4, 8.0, 0.5, 3, 0, 4&-4, 4|9}; double eRes01[len] = {5.0, 4, 8.0, 0.5, 3, 0, 4 & -4, 4 | 9};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes00[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes00[i], op[i], false);
} }
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes01[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes01[i], op[i], true);
} }
...@@ -1137,10 +1141,10 @@ TEST(columnTest, json_column_arith_op) { ...@@ -1137,10 +1141,10 @@ TEST(columnTest, json_column_arith_op) {
key = "k2"; key = "k2";
double eRes10[len] = {1.0, -8, 0, 0, 0, 0, 0, 9}; double eRes10[len] = {1.0, -8, 0, 0, 0, 0, 0, 9};
double eRes11[len] = {1.0, 8, 0, DBL_MAX, DBL_MAX, 0, 0, 9}; double eRes11[len] = {1.0, 8, 0, DBL_MAX, DBL_MAX, 0, 0, 9};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes10[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes10[i], op[i], false);
} }
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes11[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes11[i], op[i], true);
} }
...@@ -1149,58 +1153,58 @@ TEST(columnTest, json_column_arith_op) { ...@@ -1149,58 +1153,58 @@ TEST(columnTest, json_column_arith_op) {
key = "k3"; key = "k3";
double eRes20[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX}; double eRes20[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX};
double eRes21[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, 0, DBL_MAX, DBL_MAX}; double eRes21[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, 0, DBL_MAX, DBL_MAX};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes20[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes20[i], op[i], false);
} }
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes21[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes21[i], op[i], true);
} }
printf("---------------------json bool- true op {1, 8, 2, 2, 3, 0, -4, 9}-------------------\n"); printf("---------------------json bool- true op {1, 8, 2, 2, 3, 0, -4, 9}-------------------\n");
key = "k4"; key = "k4";
double eRes30[len] = {2.0, -7, 2, 0.5, 1, -1, 1&-4, 1|9}; double eRes30[len] = {2.0, -7, 2, 0.5, 1, -1, 1 & -4, 1 | 9};
double eRes31[len] = {2.0, 7, 2, 2, 0, 0, 1&-4, 1|9}; double eRes31[len] = {2.0, 7, 2, 2, 0, 0, 1 & -4, 1 | 9};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes30[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes30[i], op[i], false);
} }
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes31[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes31[i], op[i], true);
} }
printf("----------------------json double-- 5.44 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n"); printf("----------------------json double-- 5.44 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n");
key = "k5"; key = "k5";
double eRes40[len] = {6.44, -2.56, 10.88, 2.72, 2.44, -5.44, 5&-4, 5|9}; double eRes40[len] = {6.44, -2.56, 10.88, 2.72, 2.44, -5.44, 5 & -4, 5 | 9};
double eRes41[len] = {6.44, 2.56, 10.88, 0.3676470588235294, 3, 0, 5&-4, 5|9}; double eRes41[len] = {6.44, 2.56, 10.88, 0.3676470588235294, 3, 0, 5 & -4, 5 | 9};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes40[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes40[i], op[i], false);
} }
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes41[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes41[i], op[i], true);
} }
printf("----------------------json int-- -10 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n"); printf("----------------------json int-- -10 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n");
key = "k6"; key = "k6";
double eRes50[len] = {-9, -18, -20, -5, -10%3, 10, -10&-4, -10|9}; double eRes50[len] = {-9, -18, -20, -5, -10 % 3, 10, -10 & -4, -10 | 9};
double eRes51[len] = {-9, 18, -20, -0.2, 3%-10, 0, -10&-4, -10|9}; double eRes51[len] = {-9, 18, -20, -0.2, 3 % -10, 0, -10 & -4, -10 | 9};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes50[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes50[i], op[i], false);
} }
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes51[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes51[i], op[i], true);
} }
printf("----------------------json double-- -9.8 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n"); printf("----------------------json double-- -9.8 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n");
key = "k7"; key = "k7";
double eRes60[len] = {-8.8, -17.8, -19.6, -4.9, -0.8, 9.8, -9&-4, -9|9}; double eRes60[len] = {-8.8, -17.8, -19.6, -4.9, -0.8, 9.8, -9 & -4, -9 | 9};
double eRes61[len] = {-8.8, 17.8, -19.6, -0.2040816326530612, 3, 0, -9&-4, -9|9}; double eRes61[len] = {-8.8, 17.8, -19.6, -0.2040816326530612, 3, 0, -9 & -4, -9 | 9};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes60[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes60[i], op[i], false);
} }
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes61[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes61[i], op[i], true);
} }
...@@ -1209,22 +1213,22 @@ TEST(columnTest, json_column_arith_op) { ...@@ -1209,22 +1213,22 @@ TEST(columnTest, json_column_arith_op) {
key = "k8"; key = "k8";
double eRes70[len] = {1.0, -8, 0, 0, 0, 0, 0, 9}; double eRes70[len] = {1.0, -8, 0, 0, 0, 0, 0, 9};
double eRes71[len] = {1.0, 8, 0, DBL_MAX, DBL_MAX, 0, 0, 9}; double eRes71[len] = {1.0, 8, 0, DBL_MAX, DBL_MAX, 0, 0, 9};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes70[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes70[i], op[i], false);
} }
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes71[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes71[i], op[i], true);
} }
printf("----------------------json string-- 8 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n"); printf("----------------------json string-- 8 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n");
key = "k9"; key = "k9";
double eRes80[len] = {9, 0, 16, 4, 8%3, -8, 8&-4, 8|9}; double eRes80[len] = {9, 0, 16, 4, 8 % 3, -8, 8 & -4, 8 | 9};
double eRes81[len] = {9, 0, 16, 0.25, 3%8, 0, 8&-4, 8|9}; double eRes81[len] = {9, 0, 16, 0.25, 3 % 8, 0, 8 & -4, 8 | 9};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes80[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes80[i], op[i], false);
} }
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes81[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes81[i], op[i], true);
} }
...@@ -1233,10 +1237,10 @@ TEST(columnTest, json_column_arith_op) { ...@@ -1233,10 +1237,10 @@ TEST(columnTest, json_column_arith_op) {
key = "k10"; key = "k10";
double eRes90[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX}; double eRes90[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX};
double eRes91[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, 0, DBL_MAX, DBL_MAX}; double eRes91[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, 0, DBL_MAX, DBL_MAX};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes90[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes90[i], op[i], false);
} }
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes91[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes91[i], op[i], true);
} }
...@@ -1244,47 +1248,51 @@ TEST(columnTest, json_column_arith_op) { ...@@ -1244,47 +1248,51 @@ TEST(columnTest, json_column_arith_op) {
taosMemoryFree(row); taosMemoryFree(row);
} }
void *prepareNchar(char* rightData){ void *prepareNchar(char *rightData) {
int32_t len = 0; int32_t len = 0;
int32_t inputLen = strlen(rightData); int32_t inputLen = strlen(rightData);
char* t = (char*)taosMemoryCalloc(1,(inputLen + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE); char *t = (char *)taosMemoryCalloc(1, (inputLen + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE);
taosMbsToUcs4(rightData, inputLen, (TdUcs4*) varDataVal(t), inputLen * TSDB_NCHAR_SIZE, &len); taosMbsToUcs4(rightData, inputLen, (TdUcs4 *)varDataVal(t), inputLen * TSDB_NCHAR_SIZE, &len);
varDataSetLen(t, len); varDataSetLen(t, len);
return t; return t;
} }
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));
SArray *tags = taosArrayInit(1, sizeof(STagVal)); SArray *tags = taosArrayInit(1, sizeof(STagVal));
STag* row = NULL; STag *row = NULL;
parseJsontoTagData(rightv, tags, &row, NULL); parseJsontoTagData(rightv, tags, &row, NULL);
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"};
printf("--------------------json int---4 {1, 8, 2, 2, 3, 0, 0, 0, 0}------------------\n"); printf("--------------------json int---4 {1, 8, 2, 2, 3, 0, 0, 0, 0}------------------\n");
char *key = "k1"; char *key = "k1";
bool eRes[len+len1] = {true, false, false, false, false, true, false, true, true, false, false, false, false}; bool eRes[len + len1] = {true, false, false, false, false, true, false, true, true, false, false, false, false};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes[i], op[i], false);
} }
bool eRes_0[len0] = {false, true, true, true, false, true}; bool eRes_0[len0] = {false, true, true, true, false, true};
for(int i = 0; i < len0; i++){ for (int i = 0; i < len0; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_0[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_0[i], op[i], true);
} }
for(int i = len; i < len + len1; i++){ for (int i = len; i < len + len1; i++) {
void* rightData = prepareNchar(inputNchar[i-len]); void *rightData = prepareNchar(inputNchar[i - len]);
makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes[i], op[i], false);
taosMemoryFree(rightData); taosMemoryFree(rightData);
} }
...@@ -1292,17 +1300,17 @@ TEST(columnTest, json_column_logic_op) { ...@@ -1292,17 +1300,17 @@ TEST(columnTest, json_column_logic_op) {
printf("--------------------json string--0 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); printf("--------------------json string--0 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
key = "k2"; key = "k2";
bool eRes1[len+len1] = {false, false, false, false, false, false, false, true, false, true, false, true, true}; bool eRes1[len + len1] = {false, false, false, false, false, false, false, true, false, true, false, true, true};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes1[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes1[i], op[i], false);
} }
bool eRes_1[len0] = {false, false, false, false, false, false}; bool eRes_1[len0] = {false, false, false, false, false, false};
for(int i = 0; i < len0; i++){ for (int i = 0; i < len0; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_1[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_1[i], op[i], true);
} }
for(int i = len; i < len + len1; i++){ for (int i = len; i < len + len1; i++) {
void* rightData = prepareNchar(inputNchar[i-len]); void *rightData = prepareNchar(inputNchar[i - len]);
makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes1[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes1[i], op[i], false);
taosMemoryFree(rightData); taosMemoryFree(rightData);
} }
...@@ -1310,17 +1318,17 @@ TEST(columnTest, json_column_logic_op) { ...@@ -1310,17 +1318,17 @@ TEST(columnTest, json_column_logic_op) {
printf("--------------------json null---null {1, 8, 2, 2, 3, 0, 0, 0, 0}------------------\n"); printf("--------------------json null---null {1, 8, 2, 2, 3, 0, 0, 0, 0}------------------\n");
key = "k3"; // (null is true) return NULL, so use DBL_MAX represent NULL key = "k3"; // (null is true) return NULL, so use DBL_MAX represent NULL
bool eRes2[len+len1] = {false, false, false, false, false, false, true, false, false, false, false, false, false}; bool eRes2[len + len1] = {false, false, false, false, false, false, true, false, false, false, false, false, false};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes2[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes2[i], op[i], false);
} }
bool eRes_2[len0] = {false, false, false, false, false, false}; bool eRes_2[len0] = {false, false, false, false, false, false};
for(int i = 0; i < len0; i++){ for (int i = 0; i < len0; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_2[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_2[i], op[i], true);
} }
for(int i = len; i < len + len1; i++){ for (int i = len; i < len + len1; i++) {
void* rightData = prepareNchar(inputNchar[i-len]); void *rightData = prepareNchar(inputNchar[i - len]);
makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes2[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes2[i], op[i], false);
taosMemoryFree(rightData); taosMemoryFree(rightData);
} }
...@@ -1328,17 +1336,17 @@ TEST(columnTest, json_column_logic_op) { ...@@ -1328,17 +1336,17 @@ TEST(columnTest, json_column_logic_op) {
printf("--------------------json bool--1 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); printf("--------------------json bool--1 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
key = "k4"; key = "k4";
bool eRes3[len+len1] = {false, false, false, false, false, false, false, true, true, false, false, false, false}; bool eRes3[len + len1] = {false, false, false, false, false, false, false, true, true, false, false, false, false};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes3[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes3[i], op[i], false);
} }
bool eRes_3[len0] = {false, false, false, false, false, false}; bool eRes_3[len0] = {false, false, false, false, false, false};
for(int i = 0; i < len0; i++){ for (int i = 0; i < len0; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_3[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_3[i], op[i], true);
} }
for(int i = len; i < len + len1; i++){ for (int i = len; i < len + len1; i++) {
void* rightData = prepareNchar(inputNchar[i-len]); void *rightData = prepareNchar(inputNchar[i - len]);
makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes3[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes3[i], op[i], false);
taosMemoryFree(rightData); taosMemoryFree(rightData);
} }
...@@ -1346,17 +1354,17 @@ TEST(columnTest, json_column_logic_op) { ...@@ -1346,17 +1354,17 @@ TEST(columnTest, json_column_logic_op) {
printf("--------------------json double--5.44 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); printf("--------------------json double--5.44 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
key = "k5"; key = "k5";
bool eRes4[len+len1] = {true, false, false, false, false, true, false, true, true, false, false, false, false}; bool eRes4[len + len1] = {true, false, false, false, false, true, false, true, true, false, false, false, false};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes4[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes4[i], op[i], false);
} }
bool eRes_4[len0] = {false, true, true, true, false, true}; bool eRes_4[len0] = {false, true, true, true, false, true};
for(int i = 0; i < len0; i++){ for (int i = 0; i < len0; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_4[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_4[i], op[i], true);
} }
for(int i = len; i < len + len1; i++){ for (int i = len; i < len + len1; i++) {
void* rightData = prepareNchar(inputNchar[i-len]); void *rightData = prepareNchar(inputNchar[i - len]);
makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes4[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes4[i], op[i], false);
taosMemoryFree(rightData); taosMemoryFree(rightData);
} }
...@@ -1364,17 +1372,17 @@ TEST(columnTest, json_column_logic_op) { ...@@ -1364,17 +1372,17 @@ TEST(columnTest, json_column_logic_op) {
printf("--------------------json int-- -10 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); printf("--------------------json int-- -10 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
key = "k6"; key = "k6";
bool eRes5[len+len1] = {false, false, true, true, false, true, false, true, true, false, false, false, false}; bool eRes5[len + len1] = {false, false, true, true, false, true, false, true, true, false, false, false, false};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes5[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes5[i], op[i], false);
} }
bool eRes_5[len0] = {true, true, false, false, false, true}; bool eRes_5[len0] = {true, true, false, false, false, true};
for(int i = 0; i < len0; i++){ for (int i = 0; i < len0; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_5[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_5[i], op[i], true);
} }
for(int i = len; i < len + len1; i++){ for (int i = len; i < len + len1; i++) {
void* rightData = prepareNchar(inputNchar[i-len]); void *rightData = prepareNchar(inputNchar[i - len]);
makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes5[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes5[i], op[i], false);
taosMemoryFree(rightData); taosMemoryFree(rightData);
} }
...@@ -1382,55 +1390,53 @@ TEST(columnTest, json_column_logic_op) { ...@@ -1382,55 +1390,53 @@ TEST(columnTest, json_column_logic_op) {
printf("--------------------json double-- -9.8 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); printf("--------------------json double-- -9.8 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
key = "k7"; key = "k7";
bool eRes6[len+len1] = {false, false, true, true, false, true, false, true, true, false, false, false, false}; bool eRes6[len + len1] = {false, false, true, true, false, true, false, true, true, false, false, false, false};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes6[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes6[i], op[i], false);
} }
bool eRes_6[len0] = {true, true, false, false, false, true}; bool eRes_6[len0] = {true, true, false, false, false, true};
for(int i = 0; i < len0; i++){ for (int i = 0; i < len0; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_6[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_6[i], op[i], true);
} }
for(int i = len; i < len + len1; i++){ for (int i = len; i < len + len1; i++) {
void* rightData = prepareNchar(inputNchar[i-len]); void *rightData = prepareNchar(inputNchar[i - len]);
makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes6[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes6[i], op[i], false);
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";
bool eRes7[len+len1] = {false, false, false, false, false, false, false, true, false, false, false, false, false}; bool eRes7[len + len1] = {false, false, false, false, false, false, false, true, false, false, false, false, false};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes7[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes7[i], op[i], false);
} }
bool eRes_7[len0] = {false, false, false, false, false, false}; bool eRes_7[len0] = {false, false, false, false, false, false};
for(int i = 0; i < len0; i++) { for (int i = 0; i < len0; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_7[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_7[i], op[i], true);
} }
for(int i = len; i < len + len1; i++){ for (int i = len; i < len + len1; i++) {
void* rightData = prepareNchar(inputNchar[i-len]); void *rightData = prepareNchar(inputNchar[i - len]);
makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes7[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes7[i], op[i], false);
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";
bool eRes8[len+len1] = {false, false, false, false, false, false, false, true, true, false, true, false, true}; bool eRes8[len + len1] = {false, false, false, false, false, false, false, true, true, false, true, false, true};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes8[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes8[i], op[i], false);
} }
bool eRes_8[len0] = {false, false, false, false, false, false}; bool eRes_8[len0] = {false, false, false, false, false, false};
for(int i = 0; i < len0; i++) { for (int i = 0; i < len0; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_8[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_8[i], op[i], true);
} }
for(int i = len; i < len + len1; i++){ for (int i = len; i < len + len1; i++) {
void* rightData = prepareNchar(inputNchar[i-len]); void *rightData = prepareNchar(inputNchar[i - len]);
makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes8[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes8[i], op[i], false);
taosMemoryFree(rightData); taosMemoryFree(rightData);
} }
...@@ -1438,17 +1444,17 @@ TEST(columnTest, json_column_logic_op) { ...@@ -1438,17 +1444,17 @@ TEST(columnTest, json_column_logic_op) {
printf("---------------------json not exist-- NULL {1, 8, 2, 2, 3, 0, 0, 0, 0}------------------\n"); printf("---------------------json not exist-- NULL {1, 8, 2, 2, 3, 0, 0, 0, 0}------------------\n");
key = "k10"; // (NULL is true) return NULL, so use DBL_MAX represent NULL key = "k10"; // (NULL is true) return NULL, so use DBL_MAX represent NULL
bool eRes9[len+len1] = {false, false, false, false, false, false, true, false, false, false, false, false, false}; bool eRes9[len + len1] = {false, false, false, false, false, false, true, false, false, false, false, false, false};
for(int i = 0; i < len; i++){ for (int i = 0; i < len; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes9[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes9[i], op[i], false);
} }
bool eRes_9[len0] = {false, false, false, false, false, false}; bool eRes_9[len0] = {false, false, false, false, false, false};
for(int i = 0; i < len0; i++) { for (int i = 0; i < len0; i++) {
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_9[i], op[i], true); makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_9[i], op[i], true);
} }
for(int i = len; i < len + len1; i++){ for (int i = len; i < len + len1; i++) {
void* rightData = prepareNchar(inputNchar[i-len]); void *rightData = prepareNchar(inputNchar[i - len]);
makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes9[i], op[i], false); makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes9[i], op[i], false);
taosMemoryFree(rightData); taosMemoryFree(rightData);
} }
...@@ -1462,10 +1468,10 @@ TEST(columnTest, smallint_value_add_int_column) { ...@@ -1462,10 +1468,10 @@ TEST(columnTest, smallint_value_add_int_column) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
int32_t leftv = 1; int32_t leftv = 1;
int16_t rightv[5]= {0, -5, -4, 23, 100}; int16_t rightv[5] = {0, -5, -4, 23, 100};
double eRes[5] = {1.0, -4, -3, 24, 101}; double eRes[5] = {1.0, -4, -3, 24, 101};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]);
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, rightv); scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, rightv);
scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
...@@ -1495,8 +1501,8 @@ TEST(columnTest, smallint_value_add_int_column) { ...@@ -1495,8 +1501,8 @@ TEST(columnTest, smallint_value_add_int_column) {
TEST(columnTest, bigint_column_multi_binary_column) { TEST(columnTest, bigint_column_multi_binary_column) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
int64_t leftv[5]= {1, 2, 3, 4, 5}; int64_t leftv[5] = {1, 2, 3, 4, 5};
char rightv[5][5]= {0}; char rightv[5][5] = {0};
for (int32_t i = 0; i < 5; ++i) { for (int32_t i = 0; i < 5; ++i) {
rightv[i][2] = rightv[i][3] = '0'; rightv[i][2] = rightv[i][3] = '0';
rightv[i][4] = '0' + i; rightv[i][4] = '0' + i;
...@@ -1504,7 +1510,7 @@ TEST(columnTest, bigint_column_multi_binary_column) { ...@@ -1504,7 +1510,7 @@ TEST(columnTest, bigint_column_multi_binary_column) {
} }
double eRes[5] = {0, 2, 6, 12, 20}; double eRes[5] = {0, 2, 6, 12, 20};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]);
scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), rowNum, leftv); scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), rowNum, leftv);
scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv); scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv);
scltMakeOpNode(&opNode, OP_TYPE_MULTI, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); scltMakeOpNode(&opNode, OP_TYPE_MULTI, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
...@@ -1534,8 +1540,8 @@ TEST(columnTest, bigint_column_multi_binary_column) { ...@@ -1534,8 +1540,8 @@ TEST(columnTest, bigint_column_multi_binary_column) {
TEST(columnTest, smallint_column_and_binary_column) { TEST(columnTest, smallint_column_and_binary_column) {
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};
char rightv[5][5]= {0}; char rightv[5][5] = {0};
for (int32_t i = 0; i < 5; ++i) { for (int32_t i = 0; i < 5; ++i) {
rightv[i][2] = rightv[i][3] = '0'; rightv[i][2] = rightv[i][3] = '0';
rightv[i][4] = '0' + i; rightv[i][4] = '0' + i;
...@@ -1543,7 +1549,7 @@ TEST(columnTest, smallint_column_and_binary_column) { ...@@ -1543,7 +1549,7 @@ TEST(columnTest, smallint_column_and_binary_column) {
} }
int64_t eRes[5] = {0, 0, 2, 0, 4}; int64_t eRes[5] = {0, 0, 2, 0, 4};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]);
scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv); scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv);
scltMakeOpNode(&opNode, OP_TYPE_BIT_AND, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); scltMakeOpNode(&opNode, OP_TYPE_BIT_AND, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
...@@ -1572,11 +1578,11 @@ TEST(columnTest, smallint_column_and_binary_column) { ...@@ -1572,11 +1578,11 @@ TEST(columnTest, smallint_column_and_binary_column) {
TEST(columnTest, smallint_column_or_float_column) { TEST(columnTest, smallint_column_or_float_column) {
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};
float rightv[5]= {2.0, 3.0, 4.1, 5.2, 6.0}; float rightv[5] = {2.0, 3.0, 4.1, 5.2, 6.0};
int64_t eRes[5] = {3, 3, 7, 5, 7}; int64_t eRes[5] = {3, 3, 7, 5, 7};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]);
scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_FLOAT, sizeof(float), rowNum, rightv); scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_FLOAT, sizeof(float), rowNum, rightv);
scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
...@@ -1605,11 +1611,11 @@ TEST(columnTest, smallint_column_or_float_column) { ...@@ -1605,11 +1611,11 @@ TEST(columnTest, smallint_column_or_float_column) {
TEST(columnTest, smallint_column_or_double_value) { TEST(columnTest, smallint_column_or_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};
double rightv= 10.2; double rightv = 10.2;
int64_t eRes[5] = {11, 10, 11, 14, 15}; int64_t eRes[5] = {11, 10, 11, 14, 15};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv);
scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
...@@ -1638,11 +1644,11 @@ TEST(columnTest, smallint_column_or_double_value) { ...@@ -1638,11 +1644,11 @@ TEST(columnTest, smallint_column_or_double_value) {
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};
double rightv= 2.5; double rightv = 2.5;
bool eRes[5] = {false, false, true, true, true}; bool eRes[5] = {false, false, true, true, true};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv);
scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
...@@ -1672,19 +1678,19 @@ TEST(columnTest, smallint_column_greater_double_value) { ...@@ -1672,19 +1678,19 @@ TEST(columnTest, smallint_column_greater_double_value) {
TEST(columnTest, int_column_in_double_list) { TEST(columnTest, int_column_in_double_list) {
SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL; SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL;
int32_t leftv[5] = {1, 2, 3, 4, 5}; int32_t leftv[5] = {1, 2, 3, 4, 5};
double rightv1 = 1.1,rightv2 = 2.2,rightv3 = 3.3; double rightv1 = 1.1, rightv2 = 2.2, rightv3 = 3.3;
bool eRes[5] = {true, true, true, false, false}; bool eRes[5] = {true, true, true, false, false};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv); scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv);
SNodeList* list = nodesMakeList(); SNodeList *list = nodesMakeList();
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv1); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv1);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv2); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv2);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv3); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv3);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT); scltMakeListNode(&listNode, list, TSDB_DATA_TYPE_INT);
scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
SArray *blockList = taosArrayInit(1, POINTER_BYTES); SArray *blockList = taosArrayInit(1, POINTER_BYTES);
...@@ -1713,8 +1719,8 @@ TEST(columnTest, binary_column_in_binary_list) { ...@@ -1713,8 +1719,8 @@ TEST(columnTest, binary_column_in_binary_list) {
SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL; SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL;
bool eRes[5] = {true, true, false, false, false}; bool eRes[5] = {true, true, false, false, false};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
char leftv[5][5]= {0}; char leftv[5][5] = {0};
char rightv[3][5]= {0}; char rightv[3][5] = {0};
for (int32_t i = 0; i < 5; ++i) { for (int32_t i = 0; i < 5; ++i) {
leftv[i][2] = 'a' + i; leftv[i][2] = 'a' + i;
leftv[i][3] = 'b' + i; leftv[i][3] = 'b' + i;
...@@ -1734,16 +1740,16 @@ TEST(columnTest, binary_column_in_binary_list) { ...@@ -1734,16 +1740,16 @@ TEST(columnTest, binary_column_in_binary_list) {
varDataSetLen(rightv[i], 3); varDataSetLen(rightv[i], 3);
} }
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
SNodeList* list = nodesMakeList(); SNodeList *list = nodesMakeList();
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[0]); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[0]);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[1]); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[1]);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[2]); scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[2]);
nodesListAppend(list, pRight); nodesListAppend(list, pRight);
scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_BINARY); scltMakeListNode(&listNode, list, TSDB_DATA_TYPE_BINARY);
scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
SArray *blockList = taosArrayInit(1, POINTER_BYTES); SArray *blockList = taosArrayInit(1, POINTER_BYTES);
...@@ -1771,7 +1777,7 @@ TEST(columnTest, binary_column_in_binary_list) { ...@@ -1771,7 +1777,7 @@ TEST(columnTest, binary_column_in_binary_list) {
TEST(columnTest, binary_column_like_binary) { TEST(columnTest, binary_column_like_binary) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
char rightv[64] = {0}; char rightv[64] = {0};
char leftv[5][5]= {0}; char leftv[5][5] = {0};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
bool eRes[5] = {true, false, true, false, true}; bool eRes[5] = {true, false, true, false, true};
...@@ -1782,7 +1788,7 @@ TEST(columnTest, binary_column_like_binary) { ...@@ -1782,7 +1788,7 @@ TEST(columnTest, binary_column_like_binary) {
varDataSetLen(leftv[i], 3); varDataSetLen(leftv[i], 3);
} }
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
sprintf(&rightv[2], "%s", "__0"); sprintf(&rightv[2], "%s", "__0");
...@@ -1815,7 +1821,7 @@ TEST(columnTest, binary_column_like_binary) { ...@@ -1815,7 +1821,7 @@ TEST(columnTest, binary_column_like_binary) {
TEST(columnTest, binary_column_is_true) { TEST(columnTest, binary_column_is_true) {
SNode *pLeft = NULL, *opNode = NULL; SNode *pLeft = NULL, *opNode = NULL;
char leftv[5][5]= {0}; char leftv[5][5] = {0};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
bool eRes[5] = {false, true, false, true, false}; bool eRes[5] = {false, true, false, true, false};
...@@ -1826,7 +1832,7 @@ TEST(columnTest, binary_column_is_true) { ...@@ -1826,7 +1832,7 @@ TEST(columnTest, binary_column_is_true) {
varDataSetLen(leftv[i], 3); varDataSetLen(leftv[i], 3);
} }
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, leftv); scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, leftv);
scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, pLeft, NULL); scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, pLeft, NULL);
...@@ -1855,7 +1861,7 @@ TEST(columnTest, binary_column_is_true) { ...@@ -1855,7 +1861,7 @@ TEST(columnTest, binary_column_is_true) {
TEST(columnTest, binary_column_is_null) { TEST(columnTest, binary_column_is_null) {
SNode *pLeft = NULL, *opNode = NULL; SNode *pLeft = NULL, *opNode = NULL;
char leftv[5][5]= {0}; char leftv[5][5] = {0};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
bool eRes[5] = {false, false, true, false, true}; bool eRes[5] = {false, false, true, false, true};
...@@ -1866,7 +1872,7 @@ TEST(columnTest, binary_column_is_null) { ...@@ -1866,7 +1872,7 @@ TEST(columnTest, binary_column_is_null) {
varDataSetLen(leftv[i], 3); varDataSetLen(leftv[i], 3);
} }
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock); SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock);
...@@ -1899,7 +1905,7 @@ TEST(columnTest, binary_column_is_null) { ...@@ -1899,7 +1905,7 @@ TEST(columnTest, binary_column_is_null) {
TEST(columnTest, binary_column_is_not_null) { TEST(columnTest, binary_column_is_not_null) {
SNode *pLeft = NULL, *opNode = NULL; SNode *pLeft = NULL, *opNode = NULL;
char leftv[5][5]= {0}; char leftv[5][5] = {0};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
bool eRes[5] = {true, true, true, true, false}; bool eRes[5] = {true, true, true, true, false};
...@@ -1910,7 +1916,7 @@ TEST(columnTest, binary_column_is_not_null) { ...@@ -1910,7 +1916,7 @@ TEST(columnTest, binary_column_is_not_null) {
varDataSetLen(leftv[i], 3); varDataSetLen(leftv[i], 3);
} }
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock); SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock);
...@@ -1943,13 +1949,13 @@ TEST(columnTest, binary_column_is_not_null) { ...@@ -1943,13 +1949,13 @@ TEST(columnTest, binary_column_is_not_null) {
TEST(columnTest, greater_and_lower) { TEST(columnTest, greater_and_lower) {
SNode *pcol1 = NULL, *pcol2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL; SNode *pcol1 = NULL, *pcol2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL;
SNode *list[2] = {0}; SNode *list[2] = {0};
int16_t v1[5]= {1, 2, 3, 4, 5}; int16_t v1[5] = {1, 2, 3, 4, 5};
int32_t v2[5]= {5, 1, 4, 2, 6}; int32_t v2[5] = {5, 1, 4, 2, 6};
int64_t v3[5]= {1, 2, 3, 4, 5}; int64_t v3[5] = {1, 2, 3, 4, 5};
int32_t v4[5]= {5, 3, 4, 2, 6}; int32_t v4[5] = {5, 3, 4, 2, 6};
bool eRes[5] = {false, true, false, false, false}; bool eRes[5] = {false, true, false, false, false};
SSDataBlock *src = NULL; SSDataBlock *src = NULL;
int32_t rowNum = sizeof(v1)/sizeof(v1[0]); int32_t rowNum = sizeof(v1) / sizeof(v1[0]);
scltMakeColumnNode(&pcol1, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, v1); scltMakeColumnNode(&pcol1, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, v1);
scltMakeColumnNode(&pcol2, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, v2); scltMakeColumnNode(&pcol2, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, v2);
scltMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol1, pcol2); scltMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol1, pcol2);
...@@ -2012,7 +2018,7 @@ void scltMakeDataBlock(SScalarParam **pInput, int32_t type, void *pVal, int32_t ...@@ -2012,7 +2018,7 @@ void scltMakeDataBlock(SScalarParam **pInput, int32_t type, void *pVal, int32_t
} }
} }
input->columnData = (SColumnInfoData*) taosMemoryCalloc(1, sizeof(SColumnInfoData)); input->columnData = (SColumnInfoData *)taosMemoryCalloc(1, sizeof(SColumnInfoData));
input->numOfRows = num; input->numOfRows = num;
input->columnData->info = createColumnInfo(0, type, bytes); input->columnData->info = createColumnInfo(0, type, bytes);
...@@ -2020,7 +2026,7 @@ void scltMakeDataBlock(SScalarParam **pInput, int32_t type, void *pVal, int32_t ...@@ -2020,7 +2026,7 @@ void scltMakeDataBlock(SScalarParam **pInput, int32_t type, void *pVal, int32_t
if (setVal) { if (setVal) {
for (int32_t i = 0; i < num; ++i) { for (int32_t i = 0; i < num; ++i) {
colDataAppend(input->columnData, i, (const char*) pVal, false); colDataAppend(input->columnData, i, (const char *)pVal, false);
} }
} else { } else {
// memset(input->data, 0, num * bytes); // memset(input->data, 0, num * bytes);
...@@ -2041,7 +2047,7 @@ TEST(ScalarFunctionTest, absFunction_constant) { ...@@ -2041,7 +2047,7 @@ TEST(ScalarFunctionTest, absFunction_constant) {
int32_t rowNum = 3; int32_t rowNum = 3;
int32_t type; int32_t type;
//TINYINT // TINYINT
int8_t val_tinyint = 10; int8_t val_tinyint = 10;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
...@@ -2067,7 +2073,7 @@ TEST(ScalarFunctionTest, absFunction_constant) { ...@@ -2067,7 +2073,7 @@ TEST(ScalarFunctionTest, absFunction_constant) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//SMALLINT // SMALLINT
int16_t val_smallint = 10; int16_t val_smallint = 10;
type = TSDB_DATA_TYPE_SMALLINT; type = TSDB_DATA_TYPE_SMALLINT;
scltMakeDataBlock(&pInput, type, &val_smallint, rowNum, true); scltMakeDataBlock(&pInput, type, &val_smallint, rowNum, true);
...@@ -2093,7 +2099,7 @@ TEST(ScalarFunctionTest, absFunction_constant) { ...@@ -2093,7 +2099,7 @@ TEST(ScalarFunctionTest, absFunction_constant) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//INT // INT
int32_t val_int = 10; int32_t val_int = 10;
type = TSDB_DATA_TYPE_INT; type = TSDB_DATA_TYPE_INT;
scltMakeDataBlock(&pInput, type, &val_int, rowNum, true); scltMakeDataBlock(&pInput, type, &val_int, rowNum, true);
...@@ -2119,7 +2125,7 @@ TEST(ScalarFunctionTest, absFunction_constant) { ...@@ -2119,7 +2125,7 @@ TEST(ScalarFunctionTest, absFunction_constant) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//BIGINT // BIGINT
int64_t val_bigint = 10; int64_t val_bigint = 10;
type = TSDB_DATA_TYPE_BIGINT; type = TSDB_DATA_TYPE_BIGINT;
scltMakeDataBlock(&pInput, type, &val_bigint, rowNum, true); scltMakeDataBlock(&pInput, type, &val_bigint, rowNum, true);
...@@ -2145,7 +2151,7 @@ TEST(ScalarFunctionTest, absFunction_constant) { ...@@ -2145,7 +2151,7 @@ TEST(ScalarFunctionTest, absFunction_constant) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float = 10.15; float val_float = 10.15;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
...@@ -2175,7 +2181,7 @@ TEST(ScalarFunctionTest, absFunction_constant) { ...@@ -2175,7 +2181,7 @@ TEST(ScalarFunctionTest, absFunction_constant) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//DOUBLE // DOUBLE
double val_double = 10.15; double val_double = 10.15;
type = TSDB_DATA_TYPE_DOUBLE; type = TSDB_DATA_TYPE_DOUBLE;
scltMakeDataBlock(&pInput, type, &val_double, rowNum, true); scltMakeDataBlock(&pInput, type, &val_double, rowNum, true);
...@@ -2200,7 +2206,6 @@ TEST(ScalarFunctionTest, absFunction_constant) { ...@@ -2200,7 +2206,6 @@ TEST(ScalarFunctionTest, absFunction_constant) {
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
} }
TEST(ScalarFunctionTest, absFunction_column) { TEST(ScalarFunctionTest, absFunction_column) {
...@@ -2209,14 +2214,14 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -2209,14 +2214,14 @@ TEST(ScalarFunctionTest, absFunction_column) {
int32_t rowNum = 5; int32_t rowNum = 5;
int32_t type; int32_t type;
//TINYINT // TINYINT
int8_t val_tinyint = 10; int8_t val_tinyint = 10;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
int8_t v = val_tinyint + i; int8_t v = val_tinyint + i;
colDataAppend(pInput->columnData, i, (const char*) &v, false); colDataAppend(pInput->columnData, i, (const char *)&v, false);
PRINTF("tiny_int before ABS:%d\n", v); PRINTF("tiny_int before ABS:%d\n", v);
} }
...@@ -2234,7 +2239,7 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -2234,7 +2239,7 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
int8_t v = val_tinyint + i; int8_t v = val_tinyint + i;
colDataAppend(pInput->columnData, i, (const char*) &v, false); colDataAppend(pInput->columnData, i, (const char *)&v, false);
PRINTF("tiny_int before ABS:%d\n", v); PRINTF("tiny_int before ABS:%d\n", v);
} }
...@@ -2247,14 +2252,14 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -2247,14 +2252,14 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//SMALLINT // SMALLINT
int16_t val_smallint = 10; int16_t val_smallint = 10;
type = TSDB_DATA_TYPE_SMALLINT; type = TSDB_DATA_TYPE_SMALLINT;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
int16_t v = val_smallint + i; int16_t v = val_smallint + i;
colDataAppend(pInput->columnData, i, (const char*) &v, false); colDataAppend(pInput->columnData, i, (const char *)&v, false);
PRINTF("small_int before ABS:%d\n", v); PRINTF("small_int before ABS:%d\n", v);
} }
...@@ -2272,7 +2277,7 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -2272,7 +2277,7 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
int16_t v = val_smallint + i; int16_t v = val_smallint + i;
colDataAppend(pInput->columnData, i, (const char*) &v, false); colDataAppend(pInput->columnData, i, (const char *)&v, false);
PRINTF("small_int before ABS:%d\n", v); PRINTF("small_int before ABS:%d\n", v);
} }
...@@ -2285,18 +2290,17 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -2285,18 +2290,17 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//INT // INT
int32_t val_int = 10; int32_t val_int = 10;
type = TSDB_DATA_TYPE_INT; type = TSDB_DATA_TYPE_INT;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
int32_t v = val_int + i; int32_t v = val_int + i;
colDataAppend(pInput->columnData, i, (const char*) &v, false); colDataAppend(pInput->columnData, i, (const char *)&v, false);
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) {
...@@ -2311,7 +2315,7 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -2311,7 +2315,7 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
int32_t v = val_int + i; int32_t v = val_int + i;
colDataAppend(pInput->columnData, i, (const char*) &v, false); colDataAppend(pInput->columnData, i, (const char *)&v, false);
PRINTF("int before ABS:%d\n", v); PRINTF("int before ABS:%d\n", v);
} }
...@@ -2324,14 +2328,14 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -2324,14 +2328,14 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float = 10.15; float val_float = 10.15;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
float v = val_float + i; float v = val_float + i;
colDataAppend(pInput->columnData, i, (const char*) &v, false); colDataAppend(pInput->columnData, i, (const char *)&v, false);
PRINTF("float before ABS:%f\n", v); PRINTF("float before ABS:%f\n", v);
} }
...@@ -2349,7 +2353,7 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -2349,7 +2353,7 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
float v = val_float + i; float v = val_float + i;
colDataAppend(pInput->columnData, i, (const char*) &v, false); colDataAppend(pInput->columnData, i, (const char *)&v, false);
PRINTF("float before ABS:%f\n", v); PRINTF("float before ABS:%f\n", v);
} }
...@@ -2362,14 +2366,14 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -2362,14 +2366,14 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//DOUBLE // DOUBLE
double val_double = 10.15; double val_double = 10.15;
type = TSDB_DATA_TYPE_DOUBLE; type = TSDB_DATA_TYPE_DOUBLE;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
double v = val_double + i; double v = val_double + i;
colDataAppend(pInput->columnData, i, (const char*) &v, false); colDataAppend(pInput->columnData, i, (const char *)&v, false);
PRINTF("double before ABS:%f\n", v); PRINTF("double before ABS:%f\n", v);
} }
...@@ -2387,7 +2391,7 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -2387,7 +2391,7 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
double v = val_double + i; double v = val_double + i;
colDataAppend(pInput->columnData, i, (const char*) &v, false); colDataAppend(pInput->columnData, i, (const char *)&v, false);
PRINTF("double before ABS:%f\n", v); PRINTF("double before ABS:%f\n", v);
} }
...@@ -2410,7 +2414,7 @@ TEST(ScalarFunctionTest, sinFunction_constant) { ...@@ -2410,7 +2414,7 @@ TEST(ScalarFunctionTest, sinFunction_constant) {
int32_t otype = TSDB_DATA_TYPE_DOUBLE; int32_t otype = TSDB_DATA_TYPE_DOUBLE;
double result = 0.42016703682664092; double result = 0.42016703682664092;
//TINYINT // TINYINT
int8_t val_tinyint = 13; int8_t val_tinyint = 13;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
...@@ -2426,7 +2430,7 @@ TEST(ScalarFunctionTest, sinFunction_constant) { ...@@ -2426,7 +2430,7 @@ TEST(ScalarFunctionTest, sinFunction_constant) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float = 13.00; float val_float = 13.00;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
...@@ -2442,7 +2446,6 @@ TEST(ScalarFunctionTest, sinFunction_constant) { ...@@ -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,14 +2456,13 @@ TEST(ScalarFunctionTest, sinFunction_column) { ...@@ -2453,14 +2456,13 @@ 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;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false); colDataAppend(pInput->columnData, i, (const char *)&val_tinyint[i], false);
PRINTF("tiny_int before SIN:%d\n", *(int8_t *)colDataGetData(pInput->columnData, i)); PRINTF("tiny_int before SIN:%d\n", *(int8_t *)colDataGetData(pInput->columnData, i));
} }
...@@ -2473,13 +2475,13 @@ TEST(ScalarFunctionTest, sinFunction_column) { ...@@ -2473,13 +2475,13 @@ TEST(ScalarFunctionTest, sinFunction_column) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float[] = {13.00, 14.00, 15.00}; float val_float[] = {13.00, 14.00, 15.00};
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
colDataAppend(pInput->columnData, i, (const char*) &val_float[i], false); colDataAppend(pInput->columnData, i, (const char *)&val_float[i], false);
PRINTF("float before SIN:%f\n", *((float *)colDataGetData(pInput->columnData, i))); PRINTF("float before SIN:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
} }
...@@ -2502,7 +2504,7 @@ TEST(ScalarFunctionTest, cosFunction_constant) { ...@@ -2502,7 +2504,7 @@ TEST(ScalarFunctionTest, cosFunction_constant) {
int32_t otype = TSDB_DATA_TYPE_DOUBLE; int32_t otype = TSDB_DATA_TYPE_DOUBLE;
double result = 0.90744678145019619; double result = 0.90744678145019619;
//TINYINT // TINYINT
int8_t val_tinyint = 13; int8_t val_tinyint = 13;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
...@@ -2518,7 +2520,7 @@ TEST(ScalarFunctionTest, cosFunction_constant) { ...@@ -2518,7 +2520,7 @@ TEST(ScalarFunctionTest, cosFunction_constant) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float = 13.00; float val_float = 13.00;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
...@@ -2544,13 +2546,13 @@ TEST(ScalarFunctionTest, cosFunction_column) { ...@@ -2544,13 +2546,13 @@ TEST(ScalarFunctionTest, cosFunction_column) {
int32_t otype = TSDB_DATA_TYPE_DOUBLE; int32_t otype = TSDB_DATA_TYPE_DOUBLE;
double result[] = {0.90744678145019619, 0.13673721820783361, -0.75968791285882131}; double result[] = {0.90744678145019619, 0.13673721820783361, -0.75968791285882131};
//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;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false); colDataAppend(pInput->columnData, i, (const char *)&val_tinyint[i], false);
PRINTF("tiny_int before COS:%d\n", *(int8_t *)colDataGetData(pInput->columnData, i)); PRINTF("tiny_int before COS:%d\n", *(int8_t *)colDataGetData(pInput->columnData, i));
} }
...@@ -2563,13 +2565,13 @@ TEST(ScalarFunctionTest, cosFunction_column) { ...@@ -2563,13 +2565,13 @@ TEST(ScalarFunctionTest, cosFunction_column) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float[] = {13.00, 14.00, 15.00}; float val_float[] = {13.00, 14.00, 15.00};
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
colDataAppend(pInput->columnData, i, (const char*) &val_float[i], false); colDataAppend(pInput->columnData, i, (const char *)&val_float[i], false);
PRINTF("float before COS:%f\n", *(float *)colDataGetData(pInput->columnData, i)); PRINTF("float before COS:%f\n", *(float *)colDataGetData(pInput->columnData, i));
} }
...@@ -2592,7 +2594,7 @@ TEST(ScalarFunctionTest, tanFunction_constant) { ...@@ -2592,7 +2594,7 @@ TEST(ScalarFunctionTest, tanFunction_constant) {
int32_t otype = TSDB_DATA_TYPE_DOUBLE; int32_t otype = TSDB_DATA_TYPE_DOUBLE;
double result = 0.46302113293648961; double result = 0.46302113293648961;
//TINYINT // TINYINT
int8_t val_tinyint = 13; int8_t val_tinyint = 13;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
...@@ -2608,7 +2610,7 @@ TEST(ScalarFunctionTest, tanFunction_constant) { ...@@ -2608,7 +2610,7 @@ TEST(ScalarFunctionTest, tanFunction_constant) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float = 13.00; float val_float = 13.00;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
...@@ -2634,13 +2636,13 @@ TEST(ScalarFunctionTest, tanFunction_column) { ...@@ -2634,13 +2636,13 @@ TEST(ScalarFunctionTest, tanFunction_column) {
int32_t otype = TSDB_DATA_TYPE_DOUBLE; int32_t otype = TSDB_DATA_TYPE_DOUBLE;
double result[] = {0.46302113293648961, 7.24460661609480550, -0.85599340090851872}; double result[] = {0.46302113293648961, 7.24460661609480550, -0.85599340090851872};
//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;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false); colDataAppend(pInput->columnData, i, (const char *)&val_tinyint[i], false);
PRINTF("tiny_int before TAN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); PRINTF("tiny_int before TAN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
} }
...@@ -2653,13 +2655,13 @@ TEST(ScalarFunctionTest, tanFunction_column) { ...@@ -2653,13 +2655,13 @@ TEST(ScalarFunctionTest, tanFunction_column) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float[] = {13.00, 14.00, 15.00}; float val_float[] = {13.00, 14.00, 15.00};
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
colDataAppend(pInput->columnData, i, (const char*) &val_float[i], false); colDataAppend(pInput->columnData, i, (const char *)&val_float[i], false);
PRINTF("float before TAN:%f\n", *((float *)colDataGetData(pInput->columnData, i))); PRINTF("float before TAN:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
} }
...@@ -2682,7 +2684,7 @@ TEST(ScalarFunctionTest, asinFunction_constant) { ...@@ -2682,7 +2684,7 @@ TEST(ScalarFunctionTest, asinFunction_constant) {
int32_t otype = TSDB_DATA_TYPE_DOUBLE; int32_t otype = TSDB_DATA_TYPE_DOUBLE;
double result = 1.57079632679489656; double result = 1.57079632679489656;
//TINYINT // TINYINT
int8_t val_tinyint = 1; int8_t val_tinyint = 1;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
...@@ -2698,7 +2700,7 @@ TEST(ScalarFunctionTest, asinFunction_constant) { ...@@ -2698,7 +2700,7 @@ TEST(ScalarFunctionTest, asinFunction_constant) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float = 1.00; float val_float = 1.00;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
...@@ -2724,14 +2726,13 @@ TEST(ScalarFunctionTest, asinFunction_column) { ...@@ -2724,14 +2726,13 @@ 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;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false); colDataAppend(pInput->columnData, i, (const char *)&val_tinyint[i], false);
PRINTF("tiny_int before ASIN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); PRINTF("tiny_int before ASIN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
} }
...@@ -2744,7 +2745,7 @@ TEST(ScalarFunctionTest, asinFunction_column) { ...@@ -2744,7 +2745,7 @@ TEST(ScalarFunctionTest, asinFunction_column) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float[] = {-1.0, 0.0, 1.0}; float val_float[] = {-1.0, 0.0, 1.0};
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
...@@ -2773,7 +2774,7 @@ TEST(ScalarFunctionTest, acosFunction_constant) { ...@@ -2773,7 +2774,7 @@ TEST(ScalarFunctionTest, acosFunction_constant) {
int32_t otype = TSDB_DATA_TYPE_DOUBLE; int32_t otype = TSDB_DATA_TYPE_DOUBLE;
double result = 0.0; double result = 0.0;
//TINYINT // TINYINT
int8_t val_tinyint = 1; int8_t val_tinyint = 1;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
...@@ -2789,7 +2790,7 @@ TEST(ScalarFunctionTest, acosFunction_constant) { ...@@ -2789,7 +2790,7 @@ TEST(ScalarFunctionTest, acosFunction_constant) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float = 1.00; float val_float = 1.00;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
...@@ -2815,7 +2816,7 @@ TEST(ScalarFunctionTest, acosFunction_column) { ...@@ -2815,7 +2816,7 @@ TEST(ScalarFunctionTest, acosFunction_column) {
int32_t otype = TSDB_DATA_TYPE_DOUBLE; int32_t otype = TSDB_DATA_TYPE_DOUBLE;
double result[] = {3.14159265358979312, 1.57079632679489656, 0.0}; double result[] = {3.14159265358979312, 1.57079632679489656, 0.0};
//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;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
...@@ -2834,7 +2835,7 @@ TEST(ScalarFunctionTest, acosFunction_column) { ...@@ -2834,7 +2835,7 @@ TEST(ScalarFunctionTest, acosFunction_column) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float[] = {-1.0, 0.0, 1.0}; float val_float[] = {-1.0, 0.0, 1.0};
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
...@@ -2863,7 +2864,7 @@ TEST(ScalarFunctionTest, atanFunction_constant) { ...@@ -2863,7 +2864,7 @@ TEST(ScalarFunctionTest, atanFunction_constant) {
int32_t otype = TSDB_DATA_TYPE_DOUBLE; int32_t otype = TSDB_DATA_TYPE_DOUBLE;
double result = 0.78539816339744828; double result = 0.78539816339744828;
//TINYINT // TINYINT
int8_t val_tinyint = 1; int8_t val_tinyint = 1;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
...@@ -2879,7 +2880,7 @@ TEST(ScalarFunctionTest, atanFunction_constant) { ...@@ -2879,7 +2880,7 @@ TEST(ScalarFunctionTest, atanFunction_constant) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float = 1.00; float val_float = 1.00;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
...@@ -2905,7 +2906,7 @@ TEST(ScalarFunctionTest, atanFunction_column) { ...@@ -2905,7 +2906,7 @@ TEST(ScalarFunctionTest, atanFunction_column) {
int32_t otype = TSDB_DATA_TYPE_DOUBLE; int32_t otype = TSDB_DATA_TYPE_DOUBLE;
double result[] = {-0.78539816339744828, 0.0, 0.78539816339744828}; double result[] = {-0.78539816339744828, 0.0, 0.78539816339744828};
//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;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
...@@ -2924,7 +2925,7 @@ TEST(ScalarFunctionTest, atanFunction_column) { ...@@ -2924,7 +2925,7 @@ TEST(ScalarFunctionTest, atanFunction_column) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float[] = {-1.0, 0.0, 1.0}; float val_float[] = {-1.0, 0.0, 1.0};
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
...@@ -2952,7 +2953,7 @@ TEST(ScalarFunctionTest, ceilFunction_constant) { ...@@ -2952,7 +2953,7 @@ TEST(ScalarFunctionTest, ceilFunction_constant) {
int32_t type; int32_t type;
double result = 10.0; double result = 10.0;
//TINYINT // TINYINT
int8_t val_tinyint = 10; int8_t val_tinyint = 10;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
...@@ -2968,7 +2969,7 @@ TEST(ScalarFunctionTest, ceilFunction_constant) { ...@@ -2968,7 +2969,7 @@ TEST(ScalarFunctionTest, ceilFunction_constant) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float = 9.5; float val_float = 9.5;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
...@@ -2993,7 +2994,7 @@ TEST(ScalarFunctionTest, ceilFunction_column) { ...@@ -2993,7 +2994,7 @@ TEST(ScalarFunctionTest, ceilFunction_column) {
int32_t type; int32_t type;
double result[] = {-10.0, 0.0, 10.0}; double result[] = {-10.0, 0.0, 10.0};
//TINYINT // TINYINT
int8_t val_tinyint[] = {-10, 0, 10}; int8_t val_tinyint[] = {-10, 0, 10};
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
...@@ -3012,7 +3013,7 @@ TEST(ScalarFunctionTest, ceilFunction_column) { ...@@ -3012,7 +3013,7 @@ TEST(ScalarFunctionTest, ceilFunction_column) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float[] = {-10.5, 0.0, 9.5}; float val_float[] = {-10.5, 0.0, 9.5};
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
...@@ -3040,7 +3041,7 @@ TEST(ScalarFunctionTest, floorFunction_constant) { ...@@ -3040,7 +3041,7 @@ TEST(ScalarFunctionTest, floorFunction_constant) {
int32_t type; int32_t type;
double result = 10.0; double result = 10.0;
//TINYINT // TINYINT
int8_t val_tinyint = 10; int8_t val_tinyint = 10;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
...@@ -3056,7 +3057,7 @@ TEST(ScalarFunctionTest, floorFunction_constant) { ...@@ -3056,7 +3057,7 @@ TEST(ScalarFunctionTest, floorFunction_constant) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float = 10.5; float val_float = 10.5;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
...@@ -3081,7 +3082,7 @@ TEST(ScalarFunctionTest, floorFunction_column) { ...@@ -3081,7 +3082,7 @@ TEST(ScalarFunctionTest, floorFunction_column) {
int32_t type; int32_t type;
double result[] = {-10.0, 0.0, 10.0}; double result[] = {-10.0, 0.0, 10.0};
//TINYINT // TINYINT
int8_t val_tinyint[] = {-10, 0, 10}; int8_t val_tinyint[] = {-10, 0, 10};
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
...@@ -3100,7 +3101,7 @@ TEST(ScalarFunctionTest, floorFunction_column) { ...@@ -3100,7 +3101,7 @@ TEST(ScalarFunctionTest, floorFunction_column) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float[] = {-9.5, 0.0, 10.5}; float val_float[] = {-9.5, 0.0, 10.5};
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
...@@ -3128,7 +3129,7 @@ TEST(ScalarFunctionTest, roundFunction_constant) { ...@@ -3128,7 +3129,7 @@ TEST(ScalarFunctionTest, roundFunction_constant) {
int32_t type; int32_t type;
double result = 10.0; double result = 10.0;
//TINYINT // TINYINT
int8_t val_tinyint = 10; int8_t val_tinyint = 10;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
...@@ -3144,7 +3145,7 @@ TEST(ScalarFunctionTest, roundFunction_constant) { ...@@ -3144,7 +3145,7 @@ TEST(ScalarFunctionTest, roundFunction_constant) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float = 9.5; float val_float = 9.5;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
...@@ -3169,7 +3170,7 @@ TEST(ScalarFunctionTest, roundFunction_column) { ...@@ -3169,7 +3170,7 @@ TEST(ScalarFunctionTest, roundFunction_column) {
int32_t type; int32_t type;
double result[] = {-10.0, 0.0, 10.0}; double result[] = {-10.0, 0.0, 10.0};
//TINYINT // TINYINT
int8_t val_tinyint[] = {-10, 0, 10}; int8_t val_tinyint[] = {-10, 0, 10};
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
...@@ -3188,7 +3189,7 @@ TEST(ScalarFunctionTest, roundFunction_column) { ...@@ -3188,7 +3189,7 @@ TEST(ScalarFunctionTest, roundFunction_column) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float[] = {-9.5, 0.0, 9.5}; float val_float[] = {-9.5, 0.0, 9.5};
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
...@@ -3217,7 +3218,7 @@ TEST(ScalarFunctionTest, sqrtFunction_constant) { ...@@ -3217,7 +3218,7 @@ TEST(ScalarFunctionTest, sqrtFunction_constant) {
int32_t otype = TSDB_DATA_TYPE_DOUBLE; int32_t otype = TSDB_DATA_TYPE_DOUBLE;
double result = 5.0; double result = 5.0;
//TINYINT // TINYINT
int8_t val_tinyint = 25; int8_t val_tinyint = 25;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
...@@ -3233,7 +3234,7 @@ TEST(ScalarFunctionTest, sqrtFunction_constant) { ...@@ -3233,7 +3234,7 @@ TEST(ScalarFunctionTest, sqrtFunction_constant) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float = 25.0; float val_float = 25.0;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
...@@ -3259,7 +3260,7 @@ TEST(ScalarFunctionTest, sqrtFunction_column) { ...@@ -3259,7 +3260,7 @@ TEST(ScalarFunctionTest, sqrtFunction_column) {
int32_t otype = TSDB_DATA_TYPE_DOUBLE; int32_t otype = TSDB_DATA_TYPE_DOUBLE;
double result[] = {5.0, 9.0, 10.0}; double result[] = {5.0, 9.0, 10.0};
//TINYINT // TINYINT
int8_t val_tinyint[] = {25, 81, 100}; int8_t val_tinyint[] = {25, 81, 100};
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
...@@ -3278,7 +3279,7 @@ TEST(ScalarFunctionTest, sqrtFunction_column) { ...@@ -3278,7 +3279,7 @@ TEST(ScalarFunctionTest, sqrtFunction_column) {
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float[] = {25.0, 81.0, 100.0}; float val_float[] = {25.0, 81.0, 100.0};
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
...@@ -3309,7 +3310,7 @@ TEST(ScalarFunctionTest, logFunction_constant) { ...@@ -3309,7 +3310,7 @@ TEST(ScalarFunctionTest, logFunction_constant) {
double result = 3.0; double result = 3.0;
pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam)); pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam));
//TINYINT // TINYINT
int8_t val_tinyint[] = {27, 3}; int8_t val_tinyint[] = {27, 3};
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
for (int32_t i = 0; i < 2; ++i) { for (int32_t i = 0; i < 2; ++i) {
...@@ -3317,8 +3318,7 @@ TEST(ScalarFunctionTest, logFunction_constant) { ...@@ -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);
...@@ -3330,7 +3330,7 @@ TEST(ScalarFunctionTest, logFunction_constant) { ...@@ -3330,7 +3330,7 @@ TEST(ScalarFunctionTest, logFunction_constant) {
scltDestroyDataBlock(input[1]); scltDestroyDataBlock(input[1]);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float[] = {64.0, 4.0}; float val_float[] = {64.0, 4.0};
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
for (int32_t i = 0; i < 2; ++i) { for (int32_t i = 0; i < 2; ++i) {
...@@ -3338,8 +3338,7 @@ TEST(ScalarFunctionTest, logFunction_constant) { ...@@ -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);
...@@ -3351,7 +3350,7 @@ TEST(ScalarFunctionTest, logFunction_constant) { ...@@ -3351,7 +3350,7 @@ TEST(ScalarFunctionTest, logFunction_constant) {
scltDestroyDataBlock(input[1]); scltDestroyDataBlock(input[1]);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//TINYINT AND FLOAT // TINYINT AND FLOAT
int8_t param0 = 64; int8_t param0 = 64;
float param1 = 4.0; float param1 = 4.0;
scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, &param0, rowNum, true); scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, &param0, rowNum, true);
...@@ -3385,18 +3384,16 @@ TEST(ScalarFunctionTest, logFunction_column) { ...@@ -3385,18 +3384,16 @@ TEST(ScalarFunctionTest, logFunction_column) {
double result[] = {2.0, 3.0, 4.0}; double result[] = {2.0, 3.0, 4.0};
pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam)); pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam));
//TINYINT // TINYINT
int8_t val_tinyint[2][3] = {{9, 27, 81}, {3, 3, 3}}; int8_t val_tinyint[2][3] = {{9, 27, 81}, {3, 3, 3}};
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
for (int32_t i = 0; i < 2; ++i) { for (int32_t i = 0; i < 2; ++i) {
scltMakeDataBlock(&input[i], type, 0, rowNum, false); scltMakeDataBlock(&input[i], type, 0, rowNum, false);
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);
...@@ -3411,18 +3408,17 @@ TEST(ScalarFunctionTest, logFunction_column) { ...@@ -3411,18 +3408,17 @@ TEST(ScalarFunctionTest, logFunction_column) {
scltDestroyDataBlock(input[1]); scltDestroyDataBlock(input[1]);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float[2][3] = {{9.0, 27.0, 81.0}, {3.0, 3.0, 3.0}}; float val_float[2][3] = {{9.0, 27.0, 81.0}, {3.0, 3.0, 3.0}};
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
for (int32_t i = 0; i < 2; ++i) { for (int32_t i = 0; i < 2; ++i) {
scltMakeDataBlock(&input[i], type, 0, rowNum, false); scltMakeDataBlock(&input[i], type, 0, rowNum, false);
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_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);
...@@ -3436,23 +3432,21 @@ TEST(ScalarFunctionTest, logFunction_column) { ...@@ -3436,23 +3432,21 @@ TEST(ScalarFunctionTest, logFunction_column) {
scltDestroyDataBlock(input[1]); scltDestroyDataBlock(input[1]);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//TINYINT AND FLOAT // TINYINT AND FLOAT
int8_t param0[] = {9, 27, 81}; int8_t param0[] = {9, 27, 81};
float param1[] = {3.0, 3.0, 3.0}; float param1[] = {3.0, 3.0, 3.0};
scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, 0, rowNum, false); scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, 0, rowNum, false);
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);
...@@ -3479,7 +3473,7 @@ TEST(ScalarFunctionTest, powFunction_constant) { ...@@ -3479,7 +3473,7 @@ TEST(ScalarFunctionTest, powFunction_constant) {
double result = 16.0; double result = 16.0;
pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam)); pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam));
//TINYINT // TINYINT
int8_t val_tinyint[] = {2, 4}; int8_t val_tinyint[] = {2, 4};
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
for (int32_t i = 0; i < 2; ++i) { for (int32_t i = 0; i < 2; ++i) {
...@@ -3487,8 +3481,7 @@ TEST(ScalarFunctionTest, powFunction_constant) { ...@@ -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);
...@@ -3500,7 +3493,7 @@ TEST(ScalarFunctionTest, powFunction_constant) { ...@@ -3500,7 +3493,7 @@ TEST(ScalarFunctionTest, powFunction_constant) {
scltDestroyDataBlock(input[1]); scltDestroyDataBlock(input[1]);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float[] = {2.0, 4.0}; float val_float[] = {2.0, 4.0};
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
for (int32_t i = 0; i < 2; ++i) { for (int32_t i = 0; i < 2; ++i) {
...@@ -3508,8 +3501,7 @@ TEST(ScalarFunctionTest, powFunction_constant) { ...@@ -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);
...@@ -3521,7 +3513,7 @@ TEST(ScalarFunctionTest, powFunction_constant) { ...@@ -3521,7 +3513,7 @@ TEST(ScalarFunctionTest, powFunction_constant) {
scltDestroyDataBlock(input[1]); scltDestroyDataBlock(input[1]);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//TINYINT AND FLOAT // TINYINT AND FLOAT
int8_t param0 = 2; int8_t param0 = 2;
float param1 = 4.0; float param1 = 4.0;
scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, &param0, rowNum, true); scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, &param0, rowNum, true);
...@@ -3555,18 +3547,16 @@ TEST(ScalarFunctionTest, powFunction_column) { ...@@ -3555,18 +3547,16 @@ TEST(ScalarFunctionTest, powFunction_column) {
double result[] = {8.0, 27.0, 64.0}; double result[] = {8.0, 27.0, 64.0};
pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam)); pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam));
//TINYINT // TINYINT
int8_t val_tinyint[2][3] = {{2, 3, 4}, {3, 3, 3}}; int8_t val_tinyint[2][3] = {{2, 3, 4}, {3, 3, 3}};
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
for (int32_t i = 0; i < 2; ++i) { for (int32_t i = 0; i < 2; ++i) {
scltMakeDataBlock(&input[i], type, 0, rowNum, false); scltMakeDataBlock(&input[i], type, 0, rowNum, false);
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);
...@@ -3582,17 +3572,16 @@ TEST(ScalarFunctionTest, powFunction_column) { ...@@ -3582,17 +3572,16 @@ TEST(ScalarFunctionTest, powFunction_column) {
scltDestroyDataBlock(input[1]); scltDestroyDataBlock(input[1]);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//FLOAT // FLOAT
float val_float[2][3] = {{2.0, 3.0, 4.0}, {3.0, 3.0, 3.0}}; float val_float[2][3] = {{2.0, 3.0, 4.0}, {3.0, 3.0, 3.0}};
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
for (int32_t i = 0; i < 2; ++i) { for (int32_t i = 0; i < 2; ++i) {
scltMakeDataBlock(&input[i], type, 0, rowNum, false); scltMakeDataBlock(&input[i], type, 0, rowNum, false);
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_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);
...@@ -3607,22 +3596,21 @@ TEST(ScalarFunctionTest, powFunction_column) { ...@@ -3607,22 +3596,21 @@ TEST(ScalarFunctionTest, powFunction_column) {
scltDestroyDataBlock(input[1]); scltDestroyDataBlock(input[1]);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
//TINYINT AND FLOAT // TINYINT AND FLOAT
int8_t param0[] = {2, 3, 4}; int8_t param0[] = {2, 3, 4};
float param1[] = {3.0, 3.0, 3.0}; float param1[] = {3.0, 3.0, 3.0};
scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, 0, rowNum, false); scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, 0, rowNum, false);
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);
...@@ -3639,11 +3627,10 @@ TEST(ScalarFunctionTest, powFunction_column) { ...@@ -3639,11 +3627,10 @@ TEST(ScalarFunctionTest, powFunction_column) {
taosMemoryFree(pInput); taosMemoryFree(pInput);
} }
int main(int argc, char** argv) { int main(int argc, char **argv) {
taosSeedRand(taosGetTimestampSec()); taosSeedRand(taosGetTimestampSec());
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
...@@ -24,7 +24,7 @@ FORMAT_DIR_LIST=( ...@@ -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"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册