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

more code format

上级 63d9b856
...@@ -28,19 +28,19 @@ extern "C" { ...@@ -28,19 +28,19 @@ extern "C" {
#include "thash.h" #include "thash.h"
#include "tname.h" #include "tname.h"
#define FILTER_DEFAULT_GROUP_SIZE 4 #define FILTER_DEFAULT_GROUP_SIZE 4
#define FILTER_DEFAULT_UNIT_SIZE 4 #define FILTER_DEFAULT_UNIT_SIZE 4
#define FILTER_DEFAULT_FIELD_SIZE 4 #define FILTER_DEFAULT_FIELD_SIZE 4
#define FILTER_DEFAULT_VALUE_SIZE 4 #define FILTER_DEFAULT_VALUE_SIZE 4
#define FILTER_DEFAULT_GROUP_UNIT_SIZE 2 #define FILTER_DEFAULT_GROUP_UNIT_SIZE 2
#define FILTER_DUMMY_EMPTY_OPTR 127 #define FILTER_DUMMY_EMPTY_OPTR 127
#define FILTER_RM_UNIT_MIN_ROWS 100 #define FILTER_RM_UNIT_MIN_ROWS 100
enum { enum {
FLD_TYPE_COLUMN = 1, FLD_TYPE_COLUMN = 1,
FLD_TYPE_VALUE = 2, FLD_TYPE_VALUE = 2,
FLD_TYPE_MAX = 3, FLD_TYPE_MAX = 3,
FLD_DATA_NO_FREE = 8, FLD_DATA_NO_FREE = 8,
FLD_DATA_IS_HASH = 16, FLD_DATA_IS_HASH = 16,
...@@ -56,10 +56,9 @@ enum { ...@@ -56,10 +56,9 @@ enum {
enum { enum {
RANGE_FLG_EXCLUDE = 1, RANGE_FLG_EXCLUDE = 1,
RANGE_FLG_INCLUDE = 2, RANGE_FLG_INCLUDE = 2,
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,
...@@ -93,63 +92,63 @@ typedef struct OptrStr { ...@@ -93,63 +92,63 @@ typedef struct OptrStr {
typedef struct SFilterRange { typedef struct SFilterRange {
int64_t s; int64_t s;
int64_t e; int64_t e;
char sflag; char sflag;
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;
int64_t e; int64_t e;
rangeCompFunc func; rangeCompFunc func;
} 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;
}; };
} SFilterRangeNode; } SFilterRangeNode;
typedef struct SFilterRangeCtx { typedef struct SFilterRangeCtx {
int32_t type; int32_t type;
int32_t options; int32_t options;
int8_t status; int8_t status;
bool isnull; bool isnull;
bool notnull; bool notnull;
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;
int32_t options; int32_t options;
int8_t status; int8_t status;
bool isnull; bool isnull;
bool notnull; bool notnull;
bool isrange; bool isrange;
SHashObj *wild; SHashObj *wild;
SHashObj *value; SHashObj *value;
} SFilterVarCtx; } 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 {
uint32_t size; uint32_t size;
uint32_t num; uint32_t num;
SFilterField *fields; SFilterField *fields;
} SFilterFields; } SFilterFields;
...@@ -174,40 +173,40 @@ typedef struct SFilterColInfo { ...@@ -174,40 +173,40 @@ typedef struct SFilterColInfo {
} SFilterColInfo; } SFilterColInfo;
typedef struct SFilterGroupCtx { typedef struct SFilterGroupCtx {
uint32_t colNum; uint32_t colNum;
uint32_t *colIdx; uint32_t *colIdx;
SFilterColInfo *colInfo; SFilterColInfo *colInfo;
} SFilterGroupCtx; } 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 {
uint8_t type; uint8_t type;
int8_t precision; int8_t precision;
uint8_t optr; uint8_t optr;
uint8_t optr2; uint8_t optr2;
} SFilterCompare; } SFilterCompare;
typedef struct SFilterUnit { typedef struct SFilterUnit {
SFilterCompare compare; SFilterCompare compare;
SFilterFieldId left; SFilterFieldId left;
SFilterFieldId right; SFilterFieldId right;
SFilterFieldId right2; SFilterFieldId right2;
} SFilterUnit; } SFilterUnit;
typedef struct SFilterComUnit { typedef struct SFilterComUnit {
void *colData; // pointer to SColumnInfoData void *colData; // pointer to SColumnInfoData
void *valData; void *valData;
void *valData2; void *valData2;
uint16_t colId; uint16_t colId;
uint16_t dataSize; uint16_t dataSize;
uint8_t dataType; uint8_t dataType;
uint8_t optr; uint8_t optr;
int8_t func; int8_t func;
int8_t rfunc; int8_t rfunc;
} SFilterComUnit; } SFilterComUnit;
typedef struct SFilterPCtx { typedef struct SFilterPCtx {
...@@ -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 {
...@@ -237,7 +236,7 @@ struct SFilterInfo { ...@@ -237,7 +236,7 @@ struct SFilterInfo {
bool scalarMode; bool scalarMode;
SFltScalarCtx sclCtx; SFltScalarCtx sclCtx;
uint32_t options; uint32_t options;
uint32_t status; uint32_t status;
uint32_t unitSize; uint32_t unitSize;
uint32_t unitNum; uint32_t unitNum;
uint32_t groupNum; uint32_t groupNum;
...@@ -249,7 +248,7 @@ struct SFilterInfo { ...@@ -249,7 +248,7 @@ struct SFilterInfo {
uint8_t *unitRes; // result uint8_t *unitRes; // result
uint8_t *unitFlags; // got result uint8_t *unitFlags; // got result
SFilterRangeCtx **colRange; SFilterRangeCtx **colRange;
filter_exec_func func; filter_exec_func func;
uint8_t blkFlag; uint8_t blkFlag;
uint32_t blkGroupNum; uint32_t blkGroupNum;
uint32_t *blkUnits; uint32_t *blkUnits;
...@@ -257,98 +256,231 @@ struct SFilterInfo { ...@@ -257,98 +256,231 @@ struct SFilterInfo {
void *pTable; void *pTable;
SArray *blkList; SArray *blkList;
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)
#define fltFatal(...) qFatal(__VA_ARGS__) #define fltFatal(...) qFatal(__VA_ARGS__)
#define fltError(...) qError(__VA_ARGS__) #define fltError(...) qError(__VA_ARGS__)
#define fltWarn(...) qWarn(__VA_ARGS__) #define fltWarn(...) qWarn(__VA_ARGS__)
#define fltInfo(...) qInfo(__VA_ARGS__) #define fltInfo(...) qInfo(__VA_ARGS__)
#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) \
#define FILTER_GET_FIELD(i, id) (&((i)->fields[(id).type].fields[(id).idx])) do { \
#define FILTER_GET_COL_FIELD(i, idx) (&((i)->fields[FLD_TYPE_COLUMN].fields[idx])) int32_t _code = c; \
#define FILTER_GET_COL_FIELD_TYPE(fi) (((SColumnNode *)((fi)->desc))->node.resType.type) 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_COL_FIELD(i, idx) (&((i)->fields[FLD_TYPE_COLUMN].fields[idx]))
#define FILTER_GET_COL_FIELD_TYPE(fi) (((SColumnNode *)((fi)->desc))->node.resType.type)
#define FILTER_GET_COL_FIELD_PRECISION(fi) (((SColumnNode *)((fi)->desc))->node.resType.precision) #define FILTER_GET_COL_FIELD_PRECISION(fi) (((SColumnNode *)((fi)->desc))->node.resType.precision)
#define FILTER_GET_COL_FIELD_SIZE(fi) (((SColumnNode *)((fi)->desc))->node.resType.bytes) #define FILTER_GET_COL_FIELD_SIZE(fi) (((SColumnNode *)((fi)->desc))->node.resType.bytes)
#define FILTER_GET_COL_FIELD_ID(fi) (((SColumnNode *)((fi)->desc))->colId) #define FILTER_GET_COL_FIELD_ID(fi) (((SColumnNode *)((fi)->desc))->colId)
#define FILTER_GET_COL_FIELD_SLOT_ID(fi) (((SColumnNode *)((fi)->desc))->slotId) #define FILTER_GET_COL_FIELD_SLOT_ID(fi) (((SColumnNode *)((fi)->desc))->slotId)
#define FILTER_GET_COL_FIELD_DESC(fi) ((SColumnNode *)((fi)->desc)) #define FILTER_GET_COL_FIELD_DESC(fi) ((SColumnNode *)((fi)->desc))
#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)
#define FILTER_UNIT_RIGHT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->right) #define FILTER_UNIT_RIGHT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->right)
#define FILTER_UNIT_RIGHT2_FIELD(i, u) FILTER_GET_FIELD(i, (u)->right2) #define FILTER_UNIT_RIGHT2_FIELD(i, u) FILTER_GET_FIELD(i, (u)->right2)
#define FILTER_UNIT_DATA_TYPE(u) ((u)->compare.type) #define FILTER_UNIT_DATA_TYPE(u) ((u)->compare.type)
#define FILTER_UNIT_DATA_PRECISION(u) ((u)->compare.precision) #define FILTER_UNIT_DATA_PRECISION(u) ((u)->compare.precision)
#define FILTER_UNIT_COL_DESC(i, u) FILTER_GET_COL_FIELD_DESC(FILTER_UNIT_LEFT_FIELD(i, u)) #define FILTER_UNIT_COL_DESC(i, u) FILTER_GET_COL_FIELD_DESC(FILTER_UNIT_LEFT_FIELD(i, u))
#define FILTER_UNIT_COL_DATA(i, u, ri) FILTER_GET_COL_FIELD_DATA(FILTER_UNIT_LEFT_FIELD(i, u), ri) #define FILTER_UNIT_COL_DATA(i, u, ri) FILTER_GET_COL_FIELD_DATA(FILTER_UNIT_LEFT_FIELD(i, u), ri)
#define FILTER_UNIT_COL_SIZE(i, u) FILTER_GET_COL_FIELD_SIZE(FILTER_UNIT_LEFT_FIELD(i, u)) #define FILTER_UNIT_COL_SIZE(i, u) FILTER_GET_COL_FIELD_SIZE(FILTER_UNIT_LEFT_FIELD(i, u))
#define FILTER_UNIT_COL_ID(i, u) FILTER_GET_COL_FIELD_ID(FILTER_UNIT_LEFT_FIELD(i, u)) #define FILTER_UNIT_COL_ID(i, u) FILTER_GET_COL_FIELD_ID(FILTER_UNIT_LEFT_FIELD(i, u))
#define FILTER_UNIT_VAL_DATA(i, u) FILTER_GET_VAL_FIELD_DATA(FILTER_UNIT_RIGHT_FIELD(i, u)) #define FILTER_UNIT_VAL_DATA(i, u) FILTER_GET_VAL_FIELD_DATA(FILTER_UNIT_RIGHT_FIELD(i, u))
#define FILTER_UNIT_COL_IDX(u) ((u)->left.idx) #define FILTER_UNIT_COL_IDX(u) ((u)->left.idx)
#define FILTER_UNIT_OPTR(u) ((u)->compare.optr) #define FILTER_UNIT_OPTR(u) ((u)->compare.optr)
#define FILTER_UNIT_COMP_FUNC(u) ((u)->compare.func) #define FILTER_UNIT_COMP_FUNC(u) ((u)->compare.func)
#define FILTER_UNIT_CLR_F(i) memset((i)->unitFlags, 0, (i)->unitNum * sizeof(*info->unitFlags)) #define FILTER_UNIT_CLR_F(i) memset((i)->unitFlags, 0, (i)->unitNum * sizeof(*info->unitFlags))
#define FILTER_UNIT_SET_F(i, idx) (i)->unitFlags[idx] = 1 #define FILTER_UNIT_SET_F(i, idx) (i)->unitFlags[idx] = 1
#define FILTER_UNIT_GET_F(i, idx) ((i)->unitFlags[idx]) #define FILTER_UNIT_GET_F(i, idx) ((i)->unitFlags[idx])
#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; \
#define FILTER_ALL_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_ALL) (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_EMPTY_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_EMPTY) #define FILTER_EMPTY_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_EMPTY)
extern bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right); extern bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right);
extern __compar_fn_t filterGetCompFunc(int32_t type, int32_t optr); extern __compar_fn_t filterGetCompFunc(int32_t type, int32_t optr);
extern __compar_fn_t filterGetCompFuncEx(int32_t lType, int32_t rType, int32_t optr); extern __compar_fn_t filterGetCompFuncEx(int32_t lType, int32_t rType, int32_t optr);
......
...@@ -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;
...@@ -29,46 +29,72 @@ typedef struct SOperatorValueType { ...@@ -29,46 +29,72 @@ typedef struct SOperatorValueType {
} SOperatorValueType; } 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__)
#define sclWarn(...) qWarn(__VA_ARGS__) #define sclWarn(...) qWarn(__VA_ARGS__)
#define sclInfo(...) qInfo(__VA_ARGS__) #define sclInfo(...) qInfo(__VA_ARGS__)
#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);
int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode); int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode);
#define GET_PARAM_TYPE(_c) ((_c)->columnData ? (_c)->columnData->info.type : (_c)->hashValueType) #define GET_PARAM_TYPE(_c) ((_c)->columnData ? (_c)->columnData->info.type : (_c)->hashValueType)
#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,12 +94,12 @@ static FORCE_INLINE _getDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType) ...@@ -94,12 +94,12 @@ 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
} }
#endif #endif
#endif /*_TD_COMMON_BIN_SCALAR_OPERATOR_H_*/ #endif /*_TD_COMMON_BIN_SCALAR_OPERATOR_H_*/
...@@ -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) {
...@@ -108,100 +107,91 @@ int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) { ...@@ -108,100 +107,91 @@ int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) {
return 3; return 3;
} else { } else {
switch (optr) { switch (optr) {
case OP_TYPE_GREATER_THAN: case OP_TYPE_GREATER_THAN:
return 4; return 4;
case OP_TYPE_GREATER_EQUAL: case OP_TYPE_GREATER_EQUAL:
return 5; return 5;
case OP_TYPE_LOWER_THAN: case OP_TYPE_LOWER_THAN:
return 6; return 6;
case OP_TYPE_LOWER_EQUAL: case OP_TYPE_LOWER_EQUAL:
return 7; return 7;
default: default:
break; break;
} }
} }
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);
} }
...@@ -568,7 +571,7 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) { ...@@ -568,7 +571,7 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) {
SFilterRangeNode *r = ctx->rs; SFilterRangeNode *r = ctx->rs;
SFilterRangeNode *rn = NULL; SFilterRangeNode *rn = NULL;
int32_t cr = 0; int32_t cr = 0;
if (optr == LOGIC_COND_TYPE_AND) { if (optr == LOGIC_COND_TYPE_AND) {
while (r != NULL) { while (r != NULL) {
...@@ -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,14 +864,12 @@ int32_t filterSourceRangeFromCtx(SFilterRangeCtx *ctx, void *sctx, int32_t optr, ...@@ -867,14 +864,12 @@ 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;
} }
SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; SFilterRangeCtx *ctx = (SFilterRangeCtx *)h;
SFilterRangeNode *r = ctx->rs; SFilterRangeNode *r = ctx->rs;
SFilterRangeNode *rn = NULL; SFilterRangeNode *rn = NULL;
...@@ -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,10 +972,11 @@ int32_t filterGetFiledByData(SFilterInfo *info, int32_t type, void *v, int32_t d ...@@ -981,10 +972,11 @@ 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,
int32_t idx = -1; bool freeIfExists) {
int32_t idx = -1;
uint32_t *num; uint32_t *num;
num = &info->fields[type].num; num = &info->fields[type].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,19 +1035,19 @@ static FORCE_INLINE int32_t filterAddColFieldFromField(SFilterInfo *info, SFilte ...@@ -1041,19 +1035,19 @@ 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);
} }
int32_t type; int32_t type;
void *v; void *v;
if (nodeType(node) == QUERY_NODE_COLUMN) { if (nodeType(node) == QUERY_NODE_COLUMN) {
type = FLD_TYPE_COLUMN; type = FLD_TYPE_COLUMN;
...@@ -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));
...@@ -1101,7 +1097,7 @@ int32_t filterAddUnitImpl(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, ...@@ -1101,7 +1097,7 @@ int32_t filterAddUnitImpl(SFilterInfo *info, uint8_t optr, SFilterFieldId *left,
if (right2) { if (right2) {
u->right2 = *right2; u->right2 = *right2;
} }
if (u->right.type == FLD_TYPE_VALUE) { if (u->right.type == FLD_TYPE_VALUE) {
SFilterField *val = FILTER_UNIT_RIGHT_FIELD(info, u); SFilterField *val = FILTER_UNIT_RIGHT_FIELD(info, u);
assert(FILTER_GET_FLAG(val->flag, FLD_TYPE_VALUE)); assert(FILTER_GET_FLAG(val->flag, FLD_TYPE_VALUE));
...@@ -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,19 +1143,19 @@ int32_t filterAddUnitToGroup(SFilterGroup *group, uint32_t unitIdx) { ...@@ -1148,19 +1143,19 @@ 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};
filterAddFieldFromNode(info, node->pLeft, &left); filterAddFieldFromNode(info, node->pLeft, &left);
uint8_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(info, left)); uint8_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(info, left));
int32_t len = 0; int32_t len = 0;
uint32_t uidx = 0; uint32_t uidx = 0;
int32_t code = 0; int32_t code = 0;
if (node->opType == OP_TYPE_IN && (!IS_VAR_DATA_TYPE(type))) { if (node->opType == OP_TYPE_IN && (!IS_VAR_DATA_TYPE(type))) {
SNodeListNode *listNode = (SNodeListNode *)node->pRight; SNodeListNode *listNode = (SNodeListNode *)node->pRight;
SListCell *cell = listNode->pNodeList->pHead; SListCell *cell = listNode->pNodeList->pHead;
SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))};
out.columnData->info.type = type; out.columnData->info.type = type;
...@@ -1172,7 +1167,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { ...@@ -1172,7 +1167,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) {
int32_t overflow = 0; int32_t overflow = 0;
code = doConvertDataType(valueNode, &out, &overflow); code = doConvertDataType(valueNode, &out, &overflow);
if (code) { if (code) {
// fltError("convert from %d to %d failed", in.type, out.type); // fltError("convert from %d to %d failed", in.type, out.type);
FLT_ERR_RET(code); FLT_ERR_RET(code);
} }
...@@ -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,11 +1212,10 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { ...@@ -1217,11 +1212,10 @@ 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;
filterAddField(dst, FILTER_UNIT_COL_DESC(src, u), NULL, FLD_TYPE_COLUMN, &left, 0, false); filterAddField(dst, FILTER_UNIT_COL_DESC(src, u), NULL, FLD_TYPE_COLUMN, &left, 0, false);
SFilterField *t = FILTER_UNIT_LEFT_FIELD(src, u); SFilterField *t = FILTER_UNIT_LEFT_FIELD(src, u);
...@@ -1229,8 +1223,9 @@ int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u ...@@ -1229,8 +1223,9 @@ int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u
if (u->right.type == FLD_TYPE_VALUE) { if (u->right.type == FLD_TYPE_VALUE) {
void *data = FILTER_UNIT_VAL_DATA(src, u); void *data = FILTER_UNIT_VAL_DATA(src, u);
if (IS_VAR_DATA_TYPE(type)) { if (IS_VAR_DATA_TYPE(type)) {
if (FILTER_UNIT_OPTR(u) == 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,9 +1254,10 @@ int32_t filterAddUnitRight(SFilterInfo *info, uint8_t optr, SFilterFieldId *righ ...@@ -1259,9 +1254,10 @@ 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;
SFilterField *col = FILTER_GET_COL_FIELD(src, cidx); SFilterField *col = FILTER_GET_COL_FIELD(src, cidx);
...@@ -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,24 +1431,22 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan ...@@ -1427,24 +1431,22 @@ 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;
if (QUERY_NODE_LOGIC_CONDITION == nodeType(pNode)) { if (QUERY_NODE_LOGIC_CONDITION == nodeType(pNode)) {
...@@ -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;
} }
...@@ -1606,7 +1608,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) ...@@ -1606,7 +1608,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
qDebug("COLUMN Field Num:%u", info->fields[FLD_TYPE_COLUMN].num); qDebug("COLUMN Field Num:%u", info->fields[FLD_TYPE_COLUMN].num);
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 *field = &info->fields[FLD_TYPE_COLUMN].fields[i]; SFilterField *field = &info->fields[FLD_TYPE_COLUMN].fields[i];
SColumnNode *refNode = (SColumnNode *)field->desc; SColumnNode *refNode = (SColumnNode *)field->desc;
qDebug("COL%d => [%d][%d]", i, refNode->dataBlockId, refNode->slotId); qDebug("COL%d => [%d][%d]", i, refNode->dataBlockId, refNode->slotId);
} }
...@@ -1615,39 +1617,41 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) ...@@ -1615,39 +1617,41 @@ 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
} }
} }
qDebug("UNIT Num:%u", info->unitNum); qDebug("UNIT Num:%u", info->unitNum);
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];
int32_t type = FILTER_UNIT_DATA_TYPE(unit); int32_t type = FILTER_UNIT_DATA_TYPE(unit);
int32_t len = 0; int32_t len = 0;
int32_t tlen = 0; int32_t tlen = 0;
char str[512] = {0}; char str[512] = {0};
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) {
SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit); SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit);
char *data = right->data; char *data = right->data;
if (IS_VAR_DATA_TYPE(type)) { if (IS_VAR_DATA_TYPE(type)) {
tlen = varDataLen(data); tlen = varDataLen(data);
data += VARSTR_HEADER_SIZE; data += VARSTR_HEADER_SIZE;
...@@ -1660,13 +1664,14 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) ...@@ -1660,13 +1664,14 @@ 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) {
SFilterField *right = FILTER_UNIT_RIGHT2_FIELD(info, unit); SFilterField *right = FILTER_UNIT_RIGHT2_FIELD(info, unit);
char *data = right->data; char *data = right->data;
if (IS_VAR_DATA_TYPE(type)) { if (IS_VAR_DATA_TYPE(type)) {
tlen = varDataLen(data); tlen = varDataLen(data);
data += VARSTR_HEADER_SIZE; data += VARSTR_HEADER_SIZE;
...@@ -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;
...@@ -1927,27 +1931,29 @@ int32_t fltInitValFieldData(SFilterInfo *info) { ...@@ -1927,27 +1931,29 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
} }
SDataType *dType = &var->node.resType; SDataType *dType = &var->node.resType;
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,13 +2048,12 @@ bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right) ...@@ -2044,13 +2048,12 @@ 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);
SFilterRange ra = {0}; SFilterRange ra = {0};
int64_t tmp = 0; int64_t tmp = 0;
switch (uoptr) { switch (uoptr) {
case OP_TYPE_GREATER_THAN: case OP_TYPE_GREATER_THAN:
...@@ -2125,16 +2128,15 @@ _return: ...@@ -2125,16 +2128,15 @@ _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);
FLT_CHK_JMP(*empty); FLT_CHK_JMP(*empty);
...@@ -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,8 +2181,8 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t ...@@ -2180,8 +2181,8 @@ 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) {
gRes[gResIdx]->colInfo[cidx].info = (SArray *)taosArrayInit(4, POINTER_BYTES); gRes[gResIdx]->colInfo[cidx].info = (SArray *)taosArrayInit(4, POINTER_BYTES);
...@@ -2238,33 +2239,33 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t ...@@ -2238,33 +2239,33 @@ 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) {
break; break;
} }
if (NULL == pNode1 || NULL == pNode2) { if (NULL == pNode1 || NULL == pNode2) {
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,9 +2277,9 @@ bool filterIsSameUnits(SFilterColInfo* pCol1, SFilterColInfo* pCol2) { ...@@ -2276,9 +2277,9 @@ 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;
for (; m < gRes1->colNum; ++m) { for (; m < gRes1->colNum; ++m) {
idx1 = gRes1->colIdx[m]; idx1 = gRes1->colIdx[m];
...@@ -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,10 +2331,10 @@ void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool ...@@ -2330,10 +2331,10 @@ 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);
if ((*ctx) == NULL) { if ((*ctx) == NULL) {
*ctx = filterInitRangeCtx(type, 0); *ctx = filterInitRangeCtx(type, 0);
...@@ -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);
...@@ -2361,13 +2361,13 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter ...@@ -2361,13 +2361,13 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter
FILTER_SET_FLAG(info->status, FI_STATUS_REWRITE); FILTER_SET_FLAG(info->status, FI_STATUS_REWRITE);
uint32_t idx1 = 0, idx2 = 0, m = 0, n = 0; uint32_t idx1 = 0, idx2 = 0, m = 0, n = 0;
bool numEqual = (*gRes1)->colNum == (*gRes2)->colNum; bool numEqual = (*gRes1)->colNum == (*gRes2)->colNum;
bool equal = false; bool equal = false;
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,14 +2432,14 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter ...@@ -2432,14 +2432,14 @@ 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;
assert(colCtxs && taosArrayGetSize(colCtxs) > 0); assert(colCtxs && taosArrayGetSize(colCtxs) > 0);
int32_t ctxSize = (int32_t)taosArrayGetSize(colCtxs); int32_t ctxSize = (int32_t)taosArrayGetSize(colCtxs);
SFilterColCtx *pctx = NULL; SFilterColCtx *pctx = NULL;
for (int32_t i = 0; i < ctxSize; ++i) { for (int32_t i = 0; i < ctxSize; ++i) {
...@@ -2469,18 +2469,17 @@ _return: ...@@ -2469,18 +2469,17 @@ _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;
} }
taosSort(gRes, *gResNum, POINTER_BYTES, filterCompareGroupCtx); taosSort(gRes, *gResNum, POINTER_BYTES, filterCompareGroupCtx);
int32_t pEnd = 0, cStart = 0, cEnd = 0; int32_t pEnd = 0, cStart = 0, cEnd = 0;
uint32_t pColNum = 0, cColNum = 0; uint32_t pColNum = 0, cColNum = 0;
int32_t movedNum = 0; int32_t movedNum = 0;
bool all = false; bool all = false;
cColNum = gRes[0]->colNum; cColNum = gRes[0]->colNum;
...@@ -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,11 +2583,11 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum ...@@ -2584,11 +2583,11 @@ 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;
uint32_t uidx = 0; uint32_t uidx = 0;
memset(info, 0, sizeof(*info)); memset(info, 0, sizeof(*info));
...@@ -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,15 +2642,15 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum ...@@ -2643,15 +2642,15 @@ 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;
uint32_t *idxNum = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(*idxNum)); uint32_t *idxNum = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(*idxNum));
for (int32_t i = 0; i < gResNum; ++i) { for (int32_t i = 0; i < gResNum; ++i) {
for (uint32_t m = 0; m < gRes[i]->colNum; ++m) { for (uint32_t m = 0; m < gRes[i]->colNum; ++m) {
SFilterColInfo *colInfo = &gRes[i]->colInfo[gRes[i]->colIdx[m]]; SFilterColInfo *colInfo = &gRes[i]->colInfo[gRes[i]->colIdx[m]];
if (FILTER_NO_MERGE_DATA_TYPE(colInfo->dataType)) { if (FILTER_NO_MERGE_DATA_TYPE(colInfo->dataType)) {
continue; continue;
} }
...@@ -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,21 +2785,20 @@ int32_t filterUpdateComUnits(SFilterInfo *info) { ...@@ -2787,21 +2785,20 @@ 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;
memset(info->blkUnitRes, 0, sizeof(*info->blkUnitRes) * info->unitNum); memset(info->blkUnitRes, 0, sizeof(*info->blkUnitRes) * info->unitNum);
for (uint32_t k = 0; k < info->unitNum; ++k) { for (uint32_t k = 0; k < info->unitNum; ++k) {
int32_t index = -1; int32_t index = -1;
SFilterComUnit *cunit = &info->cunits[k]; SFilterComUnit *cunit = &info->cunits[k];
if (FILTER_NO_MERGE_DATA_TYPE(cunit->dataType)) { if (FILTER_NO_MERGE_DATA_TYPE(cunit->dataType)) {
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,16 +2835,15 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3 ...@@ -2838,16 +2835,15 @@ 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;
if (cunit->dataType == TSDB_DATA_TYPE_FLOAT) { if (cunit->dataType == TSDB_DATA_TYPE_FLOAT) {
minv = (float)(*(double *)(&pDataBlockst->min)); minv = (float)(*(double *)(&pDataBlockst->min));
...@@ -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) {
...@@ -2915,7 +2912,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3 ...@@ -2915,7 +2912,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3
uint32_t *unitNum = info->blkUnits; uint32_t *unitNum = info->blkUnits;
uint32_t *unitIdx = unitNum + 1; uint32_t *unitIdx = unitNum + 1;
int32_t all = 0, empty = 0; int32_t all = 0, empty = 0;
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];
...@@ -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;
...@@ -2992,30 +2990,31 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, SColumnInfoD ...@@ -2992,30 +2990,31 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, SColumnInfoD
uint32_t unitNum = *(unitIdx++); uint32_t unitNum = *(unitIdx++);
for (uint32_t u = 0; u < unitNum; ++u) { for (uint32_t u = 0; u < unitNum; ++u) {
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)) {
p[i] = (optr == OP_TYPE_IS_NULL) ? true : false; p[i] = (optr == OP_TYPE_IS_NULL) ? true : false;
} else {
if (optr == OP_TYPE_IS_NOT_NULL) {
p[i] = 1;
} else if (optr == OP_TYPE_IS_NULL) {
p[i] = 0;
} else if (cunit->rfunc >= 0) {
p[i] = (*gRangeCompare[cunit->rfunc])(colData, colData, cunit->valData, cunit->valData2,
gDataCompare[cunit->func]);
} else { } else {
if (optr == OP_TYPE_IS_NOT_NULL) { p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData);
p[i] = 1;
} else if (optr == OP_TYPE_IS_NULL) {
p[i] = 0;
} else if (cunit->rfunc >= 0) {
p[i] = (*gRangeCompare[cunit->rfunc])(colData, colData, cunit->valData, cunit->valData2, gDataCompare[cunit->func]);
} else {
p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData);
}
//FILTER_UNIT_SET_R(info, uidx, p[i]);
//FILTER_UNIT_SET_F(info, uidx);
} }
// FILTER_UNIT_SET_R(info, uidx, p[i]);
// FILTER_UNIT_SET_F(info, uidx);
}
if (p[i] == 0) { if (p[i] == 0) {
break; break;
} }
...@@ -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,20 +3065,22 @@ _return: ...@@ -3067,20 +3065,22 @@ _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;
} }
static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes,
SColumnDataAgg *statis, int16_t numOfCols, int32_t *numOfQualified) { SColumnDataAgg *statis, int16_t numOfCols, int32_t *numOfQualified) {
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;
...@@ -3088,7 +3088,7 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, ...@@ -3088,7 +3088,7 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows,
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];
void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i); void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i);
p[i] = ((colData == NULL) || colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL)); p[i] = ((colData == NULL) || colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL));
if (p[i] == 0) { if (p[i] == 0) {
...@@ -3104,17 +3104,17 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, ...@@ -3104,17 +3104,17 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows,
static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes,
SColumnDataAgg *statis, int16_t numOfCols, int32_t *numOfQualified) { SColumnDataAgg *statis, int16_t numOfCols, int32_t *numOfQualified) {
SFilterInfo *info = (SFilterInfo *)pinfo; SFilterInfo *info = (SFilterInfo *)pinfo;
bool all = true; bool all = true;
if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) { if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) {
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];
void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i); void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i);
p[i] = ((colData != NULL) && !colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL)); p[i] = ((colData != NULL) && !colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL));
if (p[i] == 0) { if (p[i] == 0) {
...@@ -3127,23 +3127,24 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows ...@@ -3127,23 +3127,24 @@ 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,
SFilterInfo *info = (SFilterInfo *)pinfo; int16_t numOfCols, int32_t *numOfQualified) {
bool all = true; SFilterInfo *info = (SFilterInfo *)pinfo;
uint16_t dataSize = info->cunits[0].dataSize; bool all = true;
uint16_t dataSize = info->cunits[0].dataSize;
rangeCompFunc rfunc = gRangeCompare[info->cunits[0].rfunc]; rangeCompFunc rfunc = gRangeCompare[info->cunits[0].rfunc];
void *valData = info->cunits[0].valData; void *valData = info->cunits[0].valData;
void *valData2 = info->cunits[0].valData2; void *valData2 = info->cunits[0].valData2;
__compar_fn_t func = gDataCompare[info->cunits[0].func]; __compar_fn_t func = gDataCompare[info->cunits[0].func];
if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) { if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) {
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)) {
...@@ -3166,17 +3167,17 @@ bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, SColumnInfoData* pRe ...@@ -3166,17 +3167,17 @@ bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, SColumnInfoData* pRe
bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SColumnDataAgg *statis, bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SColumnDataAgg *statis,
int16_t numOfCols, int32_t *numOfQualified) { int16_t numOfCols, int32_t *numOfQualified) {
SFilterInfo *info = (SFilterInfo *)pinfo; SFilterInfo *info = (SFilterInfo *)pinfo;
bool all = true; bool all = true;
if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) { if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) {
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];
void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i); void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i);
if (colData == NULL || colDataIsNull_s((SColumnInfoData *)info->cunits[uidx].colData, i)) { if (colData == NULL || colDataIsNull_s((SColumnInfoData *)info->cunits[uidx].colData, i)) {
p[i] = 0; p[i] = 0;
all = false; all = false;
...@@ -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 &&
char *newColData = taosMemoryCalloc(info->cunits[uidx].dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1); (info->cunits[uidx].optr == OP_TYPE_MATCH || info->cunits[uidx].optr == OP_TYPE_NMATCH)) {
int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(colData), varDataLen(colData), varDataVal(newColData)); char *newColData = taosMemoryCalloc(info->cunits[uidx].dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1);
if (len < 0){ int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(colData), varDataLen(colData), varDataVal(newColData));
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) {
...@@ -3211,58 +3215,60 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes ...@@ -3211,58 +3215,60 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes
bool filterExecuteImpl(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SColumnDataAgg *statis, int16_t numOfCols, bool filterExecuteImpl(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SColumnDataAgg *statis, int16_t numOfCols,
int32_t *numOfQualified) { int32_t *numOfQualified) {
SFilterInfo *info = (SFilterInfo *)pinfo; SFilterInfo *info = (SFilterInfo *)pinfo;
bool all = true; bool all = true;
if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) { if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) {
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];
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];
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)) {
p[i] = optr == OP_TYPE_IS_NULL ? true : false; p[i] = optr == OP_TYPE_IS_NULL ? true : false;
} else {
if (optr == OP_TYPE_IS_NOT_NULL) {
p[i] = 1;
} else if (optr == OP_TYPE_IS_NULL) {
p[i] = 0;
} else if (cunit->rfunc >= 0) {
p[i] = (*gRangeCompare[cunit->rfunc])(colData, colData, cunit->valData, cunit->valData2,
gDataCompare[cunit->func]);
} else { } else {
if (optr == OP_TYPE_IS_NOT_NULL) { if (cunit->dataType == TSDB_DATA_TYPE_NCHAR &&
p[i] = 1; (cunit->optr == OP_TYPE_MATCH || cunit->optr == OP_TYPE_NMATCH)) {
} else if (optr == OP_TYPE_IS_NULL) { char *newColData = taosMemoryCalloc(cunit->dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1);
p[i] = 0; int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(colData), varDataLen(colData), varDataVal(newColData));
} else if (cunit->rfunc >= 0) { if (len < 0) {
p[i] = (*gRangeCompare[cunit->rfunc])(colData, colData, cunit->valData, cunit->valData2, gDataCompare[cunit->func]); qError("castConvert1 taosUcs4ToMbs error");
} else { } else {
if(cunit->dataType == TSDB_DATA_TYPE_NCHAR && (cunit->optr == OP_TYPE_MATCH || cunit->optr == OP_TYPE_NMATCH)){ varDataSetLen(newColData, len);
char *newColData = taosMemoryCalloc(cunit->dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1); p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, newColData, cunit->valData);
int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(colData), varDataLen(colData), varDataVal(newColData));
if (len < 0){
qError("castConvert1 taosUcs4ToMbs error");
}else{
varDataSetLen(newColData, len);
p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, newColData, cunit->valData);
}
taosMemoryFreeClear(newColData);
}else{
p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData);
} }
taosMemoryFreeClear(newColData);
} else {
p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData);
} }
//FILTER_UNIT_SET_R(info, uidx, p[i]);
//FILTER_UNIT_SET_F(info, uidx);
} }
// FILTER_UNIT_SET_R(info, uidx, p[i]);
// FILTER_UNIT_SET_F(info, uidx);
}
if (p[i] == 0) { if (p[i] == 0) {
break; break;
} }
...@@ -3318,11 +3324,9 @@ int32_t filterSetExecFunc(SFilterInfo *info) { ...@@ -3318,11 +3324,9 @@ 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);
...@@ -3436,13 +3437,13 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t ...@@ -3436,13 +3437,13 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t
return true; return true;
} }
bool ret = true; bool ret = true;
void *minVal, *maxVal; void *minVal, *maxVal;
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,11 +3480,11 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t ...@@ -3479,11 +3480,11 @@ 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;
float maxv = 0; float maxv = 0;
if (ctx->type == TSDB_DATA_TYPE_FLOAT) { if (ctx->type == TSDB_DATA_TYPE_FLOAT) {
minv = (float)(*(double *)(&pDataBlockst->min)); minv = (float)(*(double *)(&pDataBlockst->min));
...@@ -3512,17 +3513,15 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t ...@@ -3512,17 +3513,15 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t
return ret; return ret;
} }
int32_t filterGetTimeRangeImpl(SFilterInfo *info, STimeWindow *win, bool *isStrict) {
SFilterRange ra = {0};
int32_t filterGetTimeRangeImpl(SFilterInfo *info, STimeWindow *win, bool *isStrict) {
SFilterRange ra = {0};
SFilterRangeCtx *prev = filterInitRangeCtx(TSDB_DATA_TYPE_TIMESTAMP, FLT_OPTION_TIMESTAMP); SFilterRangeCtx *prev = filterInitRangeCtx(TSDB_DATA_TYPE_TIMESTAMP, FLT_OPTION_TIMESTAMP);
SFilterRangeCtx *tmpc = filterInitRangeCtx(TSDB_DATA_TYPE_TIMESTAMP, FLT_OPTION_TIMESTAMP); SFilterRangeCtx *tmpc = filterInitRangeCtx(TSDB_DATA_TYPE_TIMESTAMP, FLT_OPTION_TIMESTAMP);
SFilterRangeCtx *cur = NULL; SFilterRangeCtx *cur = NULL;
int32_t num = 0; int32_t num = 0;
int32_t optr = 0; int32_t optr = 0;
int32_t code = 0; int32_t code = 0;
bool empty = false, all = false; bool empty = false, all = false;
for (uint32_t i = 0; i < info->groupNum; ++i) { for (uint32_t i = 0; i < info->groupNum; ++i) {
SFilterGroup *group = &info->groups[i]; SFilterGroup *group = &info->groups[i];
...@@ -3535,7 +3534,7 @@ int32_t filterGetTimeRangeImpl(SFilterInfo *info, STimeWindow *win, bool * ...@@ -3535,7 +3534,7 @@ int32_t filterGetTimeRangeImpl(SFilterInfo *info, STimeWindow *win, bool *
} }
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];
SFilterUnit *unit = &info->units[uidx]; SFilterUnit *unit = &info->units[uidx];
uint8_t raOptr = FILTER_UNIT_OPTR(unit); uint8_t raOptr = FILTER_UNIT_OPTR(unit);
...@@ -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,15 +3628,14 @@ _return: ...@@ -3630,15 +3628,14 @@ _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};
nfi.desc = fi->desc; nfi.desc = fi->desc;
...@@ -3646,20 +3643,21 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar ...@@ -3646,20 +3643,21 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar
nfi.data = taosMemoryMalloc(rows * bytes); nfi.data = taosMemoryMalloc(rows * bytes);
int32_t bufSize = bytes - VARSTR_HEADER_SIZE; int32_t bufSize = bytes - VARSTR_HEADER_SIZE;
for (int32_t j = 0; j < rows; ++j) { for (int32_t j = 0; j < rows; ++j) {
char *src = FILTER_GET_COL_FIELD_DATA(fi, j); char *src = FILTER_GET_COL_FIELD_DATA(fi, j);
char *dst = FILTER_GET_COL_FIELD_DATA(&nfi, j); char *dst = FILTER_GET_COL_FIELD_DATA(&nfi, j);
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,10 +3677,10 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar ...@@ -3679,10 +3677,10 @@ 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,12 +3704,12 @@ int32_t fltAddValueNodeToConverList(SFltTreeStat *stat, SValueNode* pNode) { ...@@ -3706,12 +3704,12 @@ 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)) {
SLogicConditionNode *node = (SLogicConditionNode *)*pNode; SLogicConditionNode *node = (SLogicConditionNode *)*pNode;
SListCell *cell = node->pParameterList->pHead; SListCell *cell = node->pParameterList->pHead;
for (int32_t i = 0; i < node->pParameterList->length; ++i) { for (int32_t i = 0; i < node->pParameterList->length; ++i) {
if (NULL == cell || NULL == cell->pNode) { if (NULL == cell || NULL == cell->pNode) {
fltError("invalid cell, cell:%p, pNode:%p", cell, cell->pNode); fltError("invalid cell, cell:%p, pNode:%p", cell, cell->pNode);
...@@ -3777,8 +3775,8 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { ...@@ -3777,8 +3775,8 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
} }
SValueNode *valueNode = (SValueNode *)listNode->pNodeList->pHead->pNode; SValueNode *valueNode = (SValueNode *)listNode->pNodeList->pHead->pNode;
uint8_t type = valueNode->node.resType.type; uint8_t type = valueNode->node.resType.type;
SNode *node = NULL; SNode *node = NULL;
FOREACH(node, listNode->pNodeList) { FOREACH(node, listNode->pNodeList) {
if (type != ((SValueNode *)node)->node.resType.type) { if (type != ((SValueNode *)node)->node.resType.type) {
stat->scalarMode = true; stat->scalarMode = true;
...@@ -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;
} }
...@@ -3880,9 +3881,9 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { ...@@ -3880,9 +3881,9 @@ 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);
...@@ -3891,9 +3892,9 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { ...@@ -3891,9 +3892,9 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
} else { } else {
SColumnNode *refNode = (SColumnNode *)node->pLeft; SColumnNode *refNode = (SColumnNode *)node->pLeft;
SNodeListNode *listNode = (SNodeListNode *)node->pRight; SNodeListNode *listNode = (SNodeListNode *)node->pRight;
int32_t type = vectorGetConvertType(refNode->node.resType.type, listNode->dataType.type); int32_t type = vectorGetConvertType(refNode->node.resType.type, listNode->dataType.type);
if (0 != type && type != refNode->node.resType.type) { if (0 != type && type != refNode->node.resType.type) {
stat->scalarMode = true; stat->scalarMode = true;
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
...@@ -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,10 +3978,8 @@ int32_t filterSetDataFromColId(SFilterInfo *info, void *param) { ...@@ -3979,10 +3978,8 @@ 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 code = 0;
int32_t filterInitFromNode(SNode* pNode, SFilterInfo **pInfo, uint32_t options) {
int32_t code = 0;
SFilterInfo *info = NULL; SFilterInfo *info = NULL;
if (pNode == NULL || pInfo == NULL) { if (pNode == NULL || pInfo == NULL) {
...@@ -4028,14 +4025,15 @@ _return: ...@@ -4028,14 +4025,15 @@ _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;
} }
SScalarParam output = {0}; SScalarParam output = {0};
SDataType type = {.type = TSDB_DATA_TYPE_BOOL, .bytes = sizeof(bool)}; SDataType type = {.type = TSDB_DATA_TYPE_BOOL, .bytes = sizeof(bool)};
int32_t code = sclCreateColumnInfoData(&type, pSrc->info.rows, &output); int32_t code = sclCreateColumnInfoData(&type, pSrc->info.rows, &output);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
...@@ -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,16 +37,16 @@ int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode) { ...@@ -36,16 +37,16 @@ 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;
} }
pColumnData->info.type = pType->type; pColumnData->info.type = pType->type;
pColumnData->info.bytes = pType->bytes; pColumnData->info.bytes = pType->bytes;
pColumnData->info.scale = pType->scale; pColumnData->info.scale = pType->scale;
pColumnData->info.precision = pType->precision; pColumnData->info.precision = pType->precision;
int32_t code = colInfoDataEnsureCapacity(pColumnData, numOfRows); int32_t code = colInfoDataEnsureCapacity(pColumnData, numOfRows);
...@@ -60,9 +61,9 @@ int32_t sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows, SScalarPara ...@@ -60,9 +61,9 @@ 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) {
return code; return code;
} }
...@@ -85,13 +86,13 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { ...@@ -85,13 +86,13 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) {
taosHashSetEqualFp(pObj, taosGetDefaultEqualFunction(type)); taosHashSetEqualFp(pObj, taosGetDefaultEqualFunction(type));
int32_t code = 0; int32_t code = 0;
SNodeListNode *nodeList = (SNodeListNode *)pNode; SNodeListNode *nodeList = (SNodeListNode *)pNode;
SListCell *cell = nodeList->pNodeList->pHead; SListCell *cell = nodeList->pNodeList->pHead;
SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))};
int32_t len = 0; int32_t len = 0;
void *buf = NULL; void *buf = NULL;
for (int32_t i = 0; i < nodeList->pNodeList->length; ++i) { for (int32_t i = 0; i < nodeList->pNodeList->length; ++i) {
SValueNode *valueNode = (SValueNode *)cell->pNode; SValueNode *valueNode = (SValueNode *)cell->pNode;
...@@ -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);
} }
...@@ -164,7 +165,7 @@ _return: ...@@ -164,7 +165,7 @@ _return:
void sclFreeRes(SHashObj *res) { void sclFreeRes(SHashObj *res) {
SScalarParam *p = NULL; SScalarParam *p = NULL;
void *pIter = taosHashIterate(res, NULL); void *pIter = taosHashIterate(res, NULL);
while (pIter) { while (pIter) {
p = (SScalarParam *)pIter; p = (SScalarParam *)pIter;
...@@ -180,7 +181,7 @@ void sclFreeParam(SScalarParam *param) { ...@@ -180,7 +181,7 @@ void sclFreeParam(SScalarParam *param) {
if (!param->colAlloced) { if (!param->colAlloced) {
return; return;
} }
if (param->columnData != NULL) { if (param->columnData != NULL) {
colDataDestroy(param->columnData); colDataDestroy(param->columnData);
taosMemoryFreeClear(param->columnData); taosMemoryFreeClear(param->columnData);
...@@ -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) {
...@@ -431,10 +436,10 @@ int32_t sclInitParamList(SScalarParam **pParams, SNodeList* pParamList, SScalarC ...@@ -431,10 +436,10 @@ int32_t sclInitParamList(SScalarParam **pParams, SNodeList* pParamList, SScalarC
} }
if (pParamList) { if (pParamList) {
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);
...@@ -538,9 +542,9 @@ _return: ...@@ -538,9 +542,9 @@ _return:
int32_t sclExecFunction(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *output) { int32_t sclExecFunction(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *output) {
SScalarParam *params = NULL; SScalarParam *params = NULL;
int32_t rowNum = 0; int32_t rowNum = 0;
int32_t paramNum = 0; int32_t paramNum = 0;
int32_t code = 0; int32_t code = 0;
SCL_ERR_RET(sclInitParamList(&params, node->pParameterList, ctx, &paramNum, &rowNum)); SCL_ERR_RET(sclInitParamList(&params, node->pParameterList, ctx, &paramNum, &rowNum));
if (fmIsUserDefinedFunc(node->funcId)) { if (fmIsUserDefinedFunc(node->funcId)) {
...@@ -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);
} }
...@@ -592,9 +597,9 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o ...@@ -592,9 +597,9 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o
} }
SScalarParam *params = NULL; SScalarParam *params = NULL;
int32_t rowNum = 0; int32_t rowNum = 0;
int32_t paramNum = 0; int32_t paramNum = 0;
int32_t code = 0; int32_t code = 0;
SCL_ERR_RET(sclInitParamList(&params, node->pParameterList, ctx, &paramNum, &rowNum)); SCL_ERR_RET(sclInitParamList(&params, node->pParameterList, ctx, &paramNum, &rowNum));
if (NULL == params) { if (NULL == params) {
output->numOfRows = 0; output->numOfRows = 0;
...@@ -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++;
} }
...@@ -657,13 +662,14 @@ _return: ...@@ -657,13 +662,14 @@ _return:
int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *output) { int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *output) {
SScalarParam *params = NULL; SScalarParam *params = NULL;
int32_t rowNum = 0; int32_t rowNum = 0;
int32_t code = 0; int32_t code = 0;
// 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);
} }
} }
...@@ -678,9 +684,9 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp ...@@ -678,9 +684,9 @@ 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;
...@@ -765,19 +770,19 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) { ...@@ -765,19 +770,19 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) {
if (SCL_IS_COMPARISON_OPERATOR(node->opType) && SCL_DOWNGRADE_DATETYPE(valueNode->node.resType.type)) { if (SCL_IS_COMPARISON_OPERATOR(node->opType) && SCL_DOWNGRADE_DATETYPE(valueNode->node.resType.type)) {
sclDowngradeValueType(valueNode); sclDowngradeValueType(valueNode);
} }
} }
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;
...@@ -786,18 +791,18 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) { ...@@ -786,18 +791,18 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) {
if (SCL_IS_COMPARISON_OPERATOR(node->opType) && SCL_DOWNGRADE_DATETYPE(valueNode->node.resType.type)) { if (SCL_IS_COMPARISON_OPERATOR(node->opType) && SCL_DOWNGRADE_DATETYPE(valueNode->node.resType.type)) {
sclDowngradeValueType(valueNode); sclDowngradeValueType(valueNode);
} }
} }
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,9 +978,9 @@ EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) { ...@@ -973,9 +978,9 @@ 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};
ctx->code = sclExecFunction(node, ctx, &output); ctx->code = sclExecFunction(node, ctx, &output);
if (ctx->code) { if (ctx->code) {
...@@ -990,9 +995,9 @@ EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) { ...@@ -990,9 +995,9 @@ 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};
ctx->code = sclExecLogic(node, ctx, &output); ctx->code = sclExecLogic(node, ctx, &output);
if (ctx->code) { if (ctx->code) {
...@@ -1007,9 +1012,9 @@ EDealRes sclWalkLogic(SNode* pNode, SScalarCtx *ctx) { ...@@ -1007,9 +1012,9 @@ 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};
ctx->code = sclExecOperator(node, ctx, &output); ctx->code = sclExecOperator(node, ctx, &output);
if (ctx->code) { if (ctx->code) {
...@@ -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));
...@@ -1125,7 +1134,7 @@ int32_t sclCalcConstants(SNode *pNode, bool dual, SNode **pRes) { ...@@ -1125,7 +1134,7 @@ int32_t sclCalcConstants(SNode *pNode, bool dual, SNode **pRes) {
SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
} }
int32_t code = 0; int32_t code = 0;
SScalarCtx ctx = {0}; SScalarCtx ctx = {0};
ctx.dual = dual; ctx.dual = dual;
ctx.pRes = taosHashInit(SCL_DEFAULT_OP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); ctx.pRes = taosHashInit(SCL_DEFAULT_OP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
...@@ -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,27 +1215,22 @@ static int32_t sclGetJsonOperatorResType(SOperatorNode* pOp) { ...@@ -1206,27 +1215,22 @@ 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) {
SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
} }
int32_t code = 0; int32_t code = 0;
SScalarCtx ctx = {.code = 0, .pBlockList = pBlockList, .param = pDst ? pDst->param : NULL}; SScalarCtx ctx = {.code = 0, .pBlockList = pBlockList, .param = pDst ? pDst->param : NULL};
// TODO: OPT performance // TODO: OPT performance
...@@ -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);
...@@ -33,86 +31,86 @@ static double tlog2(double v, double base) { ...@@ -33,86 +31,86 @@ static double tlog2(double v, double base) {
} }
int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput); int32_t type = GET_PARAM_TYPE(pInput);
switch (type) { switch (type) {
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;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
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;
} }
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;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
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;
} }
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;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
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;
} }
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;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
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;
} }
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;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
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;
} }
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;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
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,
SColumnInfoData *pInputData[2]; _double_fn_2 valFn) {
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pInputData[2];
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,15 +232,16 @@ static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, S ...@@ -236,15 +232,16 @@ 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;
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
switch (type) { switch (type) {
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;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
...@@ -258,7 +255,7 @@ static int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP ...@@ -258,7 +255,7 @@ static int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
} }
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;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
...@@ -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;
...@@ -362,7 +357,7 @@ static void trtrim(char *input, char *output, int32_t type, int32_t charLen) { ...@@ -362,7 +357,7 @@ static void trtrim(char *input, char *output, int32_t type, int32_t charLen) {
static int32_t doLengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _len_fn lenFn) { static int32_t doLengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _len_fn lenFn) {
int32_t type = GET_PARAM_TYPE(pInput); int32_t type = GET_PARAM_TYPE(pInput);
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
ASSERT(pOutputData->info.type == TSDB_DATA_TYPE_BIGINT); ASSERT(pOutputData->info.type == TSDB_DATA_TYPE_BIGINT);
...@@ -386,7 +381,7 @@ static int32_t concatCopyHelper(const char *input, char *output, bool hasNchar, ...@@ -386,7 +381,7 @@ static int32_t concatCopyHelper(const char *input, char *output, bool hasNchar,
if (hasNchar && type == TSDB_DATA_TYPE_VARCHAR) { if (hasNchar && type == TSDB_DATA_TYPE_VARCHAR) {
TdUcs4 *newBuf = taosMemoryCalloc((varDataLen(input) + 1) * TSDB_NCHAR_SIZE, 1); TdUcs4 *newBuf = taosMemoryCalloc((varDataLen(input) + 1) * TSDB_NCHAR_SIZE, 1);
int32_t len = varDataLen(input); int32_t len = varDataLen(input);
bool ret = taosMbsToUcs4(varDataVal(input), len, newBuf, (varDataLen(input) + 1) * TSDB_NCHAR_SIZE, &len); bool ret = taosMbsToUcs4(varDataVal(input), len, newBuf, (varDataLen(input) + 1) * TSDB_NCHAR_SIZE, &len);
if (!ret) { if (!ret) {
taosMemoryFree(newBuf); taosMemoryFree(newBuf);
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
...@@ -415,15 +410,15 @@ static int32_t getNumOfNullEntries(SColumnInfoData *pColumnInfoData, int32_t num ...@@ -415,15 +410,15 @@ static int32_t getNumOfNullEntries(SColumnInfoData *pColumnInfoData, int32_t num
} }
int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t concatFunction(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 *));
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
char **input = taosMemoryCalloc(inputNum, POINTER_BYTES); char **input = taosMemoryCalloc(inputNum, POINTER_BYTES);
char *outputBuf = NULL; char *outputBuf = NULL;
int32_t inputLen = 0; int32_t inputLen = 0;
int32_t numOfRows = 0; int32_t numOfRows = 0;
bool hasNchar = (GET_PARAM_TYPE(pOutput) == TSDB_DATA_TYPE_NCHAR) ? true : false; bool hasNchar = (GET_PARAM_TYPE(pOutput) == TSDB_DATA_TYPE_NCHAR) ? true : false;
for (int32_t i = 0; i < inputNum; ++i) { for (int32_t i = 0; i < inputNum; ++i) {
if (pInput[i].numOfRows > numOfRows) { if (pInput[i].numOfRows > numOfRows) {
numOfRows = pInput[i].numOfRows; numOfRows = pInput[i].numOfRows;
...@@ -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,17 +482,16 @@ DONE: ...@@ -489,17 +482,16 @@ 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 *));
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
char **input = taosMemoryCalloc(inputNum, POINTER_BYTES); char **input = taosMemoryCalloc(inputNum, POINTER_BYTES);
char *outputBuf = NULL; char *outputBuf = NULL;
int32_t inputLen = 0; int32_t inputLen = 0;
int32_t numOfRows = 0; int32_t numOfRows = 0;
bool hasNchar = (GET_PARAM_TYPE(pOutput) == TSDB_DATA_TYPE_NCHAR) ? true : false; bool hasNchar = (GET_PARAM_TYPE(pOutput) == TSDB_DATA_TYPE_NCHAR) ? true : false;
for (int32_t i = 1; i < inputNum; ++i) { for (int32_t i = 1; i < inputNum; ++i) {
if (pInput[i].numOfRows > numOfRows) { if (pInput[i].numOfRows > numOfRows) {
numOfRows = pInput[i].numOfRows; numOfRows = pInput[i].numOfRows;
...@@ -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,17 +521,15 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p ...@@ -528,17 +521,15 @@ 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;
} }
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,11 +542,10 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p ...@@ -551,11 +542,10 @@ 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) {
goto DONE; goto DONE;
} }
...@@ -585,12 +575,12 @@ DONE: ...@@ -585,12 +575,12 @@ DONE:
static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _conv_fn convFn) { static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _conv_fn convFn) {
int32_t type = GET_PARAM_TYPE(pInput); int32_t type = GET_PARAM_TYPE(pInput);
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
int32_t outputLen = pInputData->varmeta.length; int32_t outputLen = pInputData->varmeta.length;
char *outputBuf = taosMemoryCalloc(outputLen, 1); char *outputBuf = taosMemoryCalloc(outputLen, 1);
char *output = outputBuf; char *output = outputBuf;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
...@@ -598,13 +588,13 @@ static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScala ...@@ -598,13 +588,13 @@ static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScala
continue; continue;
} }
char *input = colDataGetData(pInput[0].columnData, i); char *input = colDataGetData(pInput[0].columnData, i);
int32_t len = varDataLen(input); int32_t len = varDataLen(input);
if (type == TSDB_DATA_TYPE_VARCHAR) { if (type == TSDB_DATA_TYPE_VARCHAR) {
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,16 +610,15 @@ static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScala ...@@ -620,16 +610,15 @@ 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);
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
int32_t outputLen = pInputData->varmeta.length; int32_t outputLen = pInputData->varmeta.length;
char *outputBuf = taosMemoryCalloc(outputLen, 1); char *outputBuf = taosMemoryCalloc(outputLen, 1);
char *output = outputBuf; char *output = outputBuf;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
...@@ -637,7 +626,7 @@ static int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarPar ...@@ -637,7 +626,7 @@ static int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarPar
continue; continue;
} }
char *input = colDataGetData(pInputData, i); char *input = colDataGetData(pInputData, i);
int32_t len = varDataLen(input); int32_t len = varDataLen(input);
int32_t charLen = (type == TSDB_DATA_TYPE_VARCHAR) ? len : len / TSDB_NCHAR_SIZE; int32_t charLen = (type == TSDB_DATA_TYPE_VARCHAR) ? len : len / TSDB_NCHAR_SIZE;
trimFn(input, output, type, charLen); trimFn(input, output, type, charLen);
...@@ -662,19 +651,19 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu ...@@ -662,19 +651,19 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
subLen = (GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? subLen : subLen * TSDB_NCHAR_SIZE; subLen = (GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? subLen : subLen * TSDB_NCHAR_SIZE;
} }
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
int32_t outputLen = pInputData->varmeta.length * pInput->numOfRows; int32_t outputLen = pInputData->varmeta.length * pInput->numOfRows;
char *outputBuf = taosMemoryCalloc(outputLen, 1); char *outputBuf = taosMemoryCalloc(outputLen, 1);
char *output = outputBuf; char *output = outputBuf;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
colDataAppendNULL(pOutputData, i); colDataAppendNULL(pOutputData, i);
continue; continue;
} }
char *input = colDataGetData(pInput[0].columnData, i); char *input = colDataGetData(pInput[0].columnData, i);
int32_t len = varDataLen(input); int32_t len = varDataLen(input);
int32_t startPosBytes; int32_t startPosBytes;
...@@ -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);
} }
...@@ -704,14 +694,14 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu ...@@ -704,14 +694,14 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
/** Conversion functions **/ /** Conversion functions **/
int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
int16_t inputType = GET_PARAM_TYPE(&pInput[0]); int16_t inputType = GET_PARAM_TYPE(&pInput[0]);
int16_t inputLen = GET_PARAM_BYTES(&pInput[0]); int16_t inputLen = GET_PARAM_BYTES(&pInput[0]);
int16_t outputType = GET_PARAM_TYPE(&pOutput[0]); int16_t outputType = GET_PARAM_TYPE(&pOutput[0]);
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,14 +717,14 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp ...@@ -727,14 +717,14 @@ 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));
buf[varDataLen(input)] = 0; buf[varDataLen(input)] = 0;
*(int8_t *)output = taosStr2Int8(buf, NULL, 10); *(int8_t *)output = taosStr2Int8(buf, NULL, 10);
} else if (inputType == TSDB_DATA_TYPE_NCHAR) { } else if (inputType == TSDB_DATA_TYPE_NCHAR) {
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf);
if (len < 0) { if (len < 0) {
code = TSDB_CODE_FAILED; code = TSDB_CODE_FAILED;
goto _end; goto _end;
...@@ -753,7 +743,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp ...@@ -753,7 +743,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
buf[varDataLen(input)] = 0; buf[varDataLen(input)] = 0;
*(int16_t *)output = taosStr2Int16(buf, NULL, 10); *(int16_t *)output = taosStr2Int16(buf, NULL, 10);
} else if (inputType == TSDB_DATA_TYPE_NCHAR) { } else if (inputType == TSDB_DATA_TYPE_NCHAR) {
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf);
if (len < 0) { if (len < 0) {
code = TSDB_CODE_FAILED; code = TSDB_CODE_FAILED;
goto _end; goto _end;
...@@ -771,7 +761,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp ...@@ -771,7 +761,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
buf[varDataLen(input)] = 0; buf[varDataLen(input)] = 0;
*(int32_t *)output = taosStr2Int32(buf, NULL, 10); *(int32_t *)output = taosStr2Int32(buf, NULL, 10);
} else if (inputType == TSDB_DATA_TYPE_NCHAR) { } else if (inputType == TSDB_DATA_TYPE_NCHAR) {
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf);
if (len < 0) { if (len < 0) {
code = TSDB_CODE_FAILED; code = TSDB_CODE_FAILED;
goto _end; goto _end;
...@@ -790,7 +780,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp ...@@ -790,7 +780,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
buf[varDataLen(input)] = 0; buf[varDataLen(input)] = 0;
*(int64_t *)output = taosStr2Int64(buf, NULL, 10); *(int64_t *)output = taosStr2Int64(buf, NULL, 10);
} else if (inputType == TSDB_DATA_TYPE_NCHAR) { } else if (inputType == TSDB_DATA_TYPE_NCHAR) {
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf);
if (len < 0) { if (len < 0) {
code = TSDB_CODE_FAILED; code = TSDB_CODE_FAILED;
goto _end; goto _end;
...@@ -881,7 +871,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp ...@@ -881,7 +871,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
buf[varDataLen(input)] = 0; buf[varDataLen(input)] = 0;
*(float *)output = taosStr2Float(buf, NULL); *(float *)output = taosStr2Float(buf, NULL);
} else if (inputType == TSDB_DATA_TYPE_NCHAR) { } else if (inputType == TSDB_DATA_TYPE_NCHAR) {
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf);
if (len < 0) { if (len < 0) {
code = TSDB_CODE_FAILED; code = TSDB_CODE_FAILED;
goto _end; goto _end;
...@@ -899,7 +889,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp ...@@ -899,7 +889,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
buf[varDataLen(input)] = 0; buf[varDataLen(input)] = 0;
*(double *)output = taosStr2Double(buf, NULL); *(double *)output = taosStr2Double(buf, NULL);
} else if (inputType == TSDB_DATA_TYPE_NCHAR) { } else if (inputType == TSDB_DATA_TYPE_NCHAR) {
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf);
if (len < 0) { if (len < 0) {
code = TSDB_CODE_FAILED; code = TSDB_CODE_FAILED;
goto _end; goto _end;
...@@ -917,7 +907,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp ...@@ -917,7 +907,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
buf[varDataLen(input)] = 0; buf[varDataLen(input)] = 0;
*(bool *)output = taosStr2Int8(buf, NULL, 10); *(bool *)output = taosStr2Int8(buf, NULL, 10);
} else if (inputType == TSDB_DATA_TYPE_NCHAR) { } else if (inputType == TSDB_DATA_TYPE_NCHAR) {
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf);
if (len < 0) { if (len < 0) {
code = TSDB_CODE_FAILED; code = TSDB_CODE_FAILED;
goto _end; goto _end;
...@@ -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;
...@@ -1036,8 +1028,8 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp ...@@ -1036,8 +1028,8 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
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);
...@@ -1051,12 +1043,12 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam * ...@@ -1051,12 +1043,12 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *
} }
char *input = colDataGetData(pInput[0].columnData, i); char *input = colDataGetData(pInput[0].columnData, i);
char fraction[20] = {0}; char fraction[20] = {0};
bool hasFraction = false; bool hasFraction = false;
NUM_TO_STRING(type, input, sizeof(fraction), fraction); NUM_TO_STRING(type, input, sizeof(fraction), fraction);
int32_t tsDigits = (int32_t)strlen(fraction); int32_t tsDigits = (int32_t)strlen(fraction);
char buf[64] = {0}; char buf[64] = {0};
int64_t timeVal; int64_t timeVal;
GET_TYPED_DATA(timeVal, int64_t, type, input); GET_TYPED_DATA(timeVal, int64_t, type, input);
if (tsDigits > TSDB_TIME_PRECISION_SEC_DIGITS) { if (tsDigits > TSDB_TIME_PRECISION_SEC_DIGITS) {
...@@ -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;
} }
...@@ -1743,7 +1734,7 @@ int32_t qTbnameFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pO ...@@ -1743,7 +1734,7 @@ int32_t qTbnameFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pO
/** Aggregation functions **/ /** Aggregation functions **/
int32_t countScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t countScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
int64_t *out = (int64_t *)pOutputData->pData; int64_t *out = (int64_t *)pOutputData->pData;
...@@ -1760,11 +1751,11 @@ int32_t countScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam ...@@ -1760,11 +1751,11 @@ int32_t countScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam
} }
int32_t sumScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t sumScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput); int32_t type = GET_PARAM_TYPE(pInput);
bool hasNull = false; bool hasNull = false;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
hasNull = true; hasNull = true;
...@@ -1772,15 +1763,15 @@ int32_t sumScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam * ...@@ -1772,15 +1763,15 @@ int32_t sumScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *
} }
if (IS_SIGNED_NUMERIC_TYPE(type)) { if (IS_SIGNED_NUMERIC_TYPE(type)) {
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;
*out += in[i]; *out += in[i];
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) { } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
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;
*out += in[i]; *out += in[i];
} else if (IS_FLOAT_TYPE(type)) { } else if (IS_FLOAT_TYPE(type)) {
double *in = (double *)pInputData->pData; double *in = (double *)pInputData->pData;
double *out = (double *)pOutputData->pData; double *out = (double *)pOutputData->pData;
*out += in[i]; *out += in[i];
} }
...@@ -1795,7 +1786,7 @@ int32_t sumScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam * ...@@ -1795,7 +1786,7 @@ int32_t sumScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *
} }
static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, bool isMinFunc) { static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, bool isMinFunc) {
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput); int32_t type = GET_PARAM_TYPE(pInput);
...@@ -1813,84 +1804,84 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS ...@@ -1813,84 +1804,84 @@ 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;
} }
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;
} }
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;
} }
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;
} }
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;
} }
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;
} }
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;
} }
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;
} }
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;
} }
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;
...@@ -1915,12 +1906,12 @@ int32_t maxScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam * ...@@ -1915,12 +1906,12 @@ int32_t maxScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *
} }
int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
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; int64_t count = 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) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
...@@ -1928,72 +1919,72 @@ int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam * ...@@ -1928,72 +1919,72 @@ 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;
*out += in[i]; *out += in[i];
count++; count++;
break; break;
} }
case TSDB_DATA_TYPE_SMALLINT: { case TSDB_DATA_TYPE_SMALLINT: {
int16_t *in = (int16_t *)pInputData->pData; int16_t *in = (int16_t *)pInputData->pData;
int64_t *out = (int64_t *)pOutputData->pData; int64_t *out = (int64_t *)pOutputData->pData;
*out += in[i]; *out += in[i];
count++; count++;
break; break;
} }
case TSDB_DATA_TYPE_INT: { case TSDB_DATA_TYPE_INT: {
int32_t *in = (int32_t *)pInputData->pData; int32_t *in = (int32_t *)pInputData->pData;
int64_t *out = (int64_t *)pOutputData->pData; int64_t *out = (int64_t *)pOutputData->pData;
*out += in[i]; *out += in[i];
count++; count++;
break; break;
} }
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;
*out += in[i]; *out += in[i];
count++; count++;
break; break;
} }
case TSDB_DATA_TYPE_UTINYINT: { case TSDB_DATA_TYPE_UTINYINT: {
uint8_t *in = (uint8_t *)pInputData->pData; uint8_t *in = (uint8_t *)pInputData->pData;
uint64_t *out = (uint64_t *)pOutputData->pData; uint64_t *out = (uint64_t *)pOutputData->pData;
*out += in[i]; *out += in[i];
count++; count++;
break; break;
} }
case TSDB_DATA_TYPE_USMALLINT: { case TSDB_DATA_TYPE_USMALLINT: {
uint16_t *in = (uint16_t *)pInputData->pData; uint16_t *in = (uint16_t *)pInputData->pData;
uint64_t *out = (uint64_t *)pOutputData->pData; uint64_t *out = (uint64_t *)pOutputData->pData;
*out += in[i]; *out += in[i];
count++; count++;
break; break;
} }
case TSDB_DATA_TYPE_UINT: { case TSDB_DATA_TYPE_UINT: {
uint32_t *in = (uint32_t *)pInputData->pData; uint32_t *in = (uint32_t *)pInputData->pData;
uint64_t *out = (uint64_t *)pOutputData->pData; uint64_t *out = (uint64_t *)pOutputData->pData;
*out += in[i]; *out += in[i];
count++; count++;
break; break;
} }
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;
*out += in[i]; *out += in[i];
count++; count++;
break; break;
} }
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;
*out += in[i]; *out += in[i];
count++; count++;
break; break;
} }
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;
*out += in[i]; *out += in[i];
count++; count++;
...@@ -2006,13 +1997,13 @@ int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam * ...@@ -2006,13 +1997,13 @@ int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *
colDataAppendNULL(pOutputData, 0); colDataAppendNULL(pOutputData, 0);
} else { } else {
if (IS_SIGNED_NUMERIC_TYPE(type)) { if (IS_SIGNED_NUMERIC_TYPE(type)) {
int64_t *out = (int64_t *)pOutputData->pData; int64_t *out = (int64_t *)pOutputData->pData;
*(double *)out = *out / (double)count; *(double *)out = *out / (double)count;
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) { } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
uint64_t *out = (uint64_t *)pOutputData->pData; uint64_t *out = (uint64_t *)pOutputData->pData;
*(double *)out = *out / (double)count; *(double *)out = *out / (double)count;
} else if (IS_FLOAT_TYPE(type)) { } else if (IS_FLOAT_TYPE(type)) {
double *out = (double *)pOutputData->pData; double *out = (double *)pOutputData->pData;
*(double *)out = *out / (double)count; *(double *)out = *out / (double)count;
} }
} }
...@@ -2022,11 +2013,11 @@ int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam * ...@@ -2022,11 +2013,11 @@ int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *
} }
int32_t stddevScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t stddevScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
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) {
...@@ -2110,7 +2101,7 @@ int32_t stddevScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara ...@@ -2110,7 +2101,7 @@ int32_t stddevScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
#endif #endif
} }
double *out = (double *)pOutputData->pData; double *out = (double *)pOutputData->pData;
if (hasNull) { if (hasNull) {
colDataAppendNULL(pOutputData, 0); colDataAppendNULL(pOutputData, 0);
} else { } else {
...@@ -2144,7 +2135,7 @@ int32_t stddevScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara ...@@ -2144,7 +2135,7 @@ int32_t stddevScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
} while (0) } while (0)
int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
double startVal, stepVal; double startVal, stepVal;
...@@ -2155,9 +2146,9 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa ...@@ -2155,9 +2146,9 @@ 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) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
continue; continue;
...@@ -2169,7 +2160,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa ...@@ -2169,7 +2160,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
break; break;
} }
case TSDB_DATA_TYPE_SMALLINT: { case TSDB_DATA_TYPE_SMALLINT: {
int16_t *in = (int16_t *)pInputData->pData; int16_t *in = (int16_t *)pInputData->pData;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
continue; continue;
...@@ -2181,7 +2172,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa ...@@ -2181,7 +2172,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
break; break;
} }
case TSDB_DATA_TYPE_INT: { case TSDB_DATA_TYPE_INT: {
int32_t *in = (int32_t *)pInputData->pData; int32_t *in = (int32_t *)pInputData->pData;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
continue; continue;
...@@ -2193,7 +2184,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa ...@@ -2193,7 +2184,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
break; break;
} }
case TSDB_DATA_TYPE_BIGINT: { case TSDB_DATA_TYPE_BIGINT: {
int64_t *in = (int64_t *)pInputData->pData; int64_t *in = (int64_t *)pInputData->pData;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
continue; continue;
...@@ -2205,7 +2196,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa ...@@ -2205,7 +2196,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
break; break;
} }
case TSDB_DATA_TYPE_UTINYINT: { case TSDB_DATA_TYPE_UTINYINT: {
uint8_t *in = (uint8_t *)pInputData->pData; uint8_t *in = (uint8_t *)pInputData->pData;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
continue; continue;
...@@ -2217,7 +2208,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa ...@@ -2217,7 +2208,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
break; break;
} }
case TSDB_DATA_TYPE_USMALLINT: { case TSDB_DATA_TYPE_USMALLINT: {
uint16_t *in = (uint16_t *)pInputData->pData; uint16_t *in = (uint16_t *)pInputData->pData;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
continue; continue;
...@@ -2229,7 +2220,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa ...@@ -2229,7 +2220,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
break; break;
} }
case TSDB_DATA_TYPE_UINT: { case TSDB_DATA_TYPE_UINT: {
uint32_t *in = (uint32_t *)pInputData->pData; uint32_t *in = (uint32_t *)pInputData->pData;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
continue; continue;
...@@ -2241,7 +2232,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa ...@@ -2241,7 +2232,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
break; break;
} }
case TSDB_DATA_TYPE_UBIGINT: { case TSDB_DATA_TYPE_UBIGINT: {
uint64_t *in = (uint64_t *)pInputData->pData; uint64_t *in = (uint64_t *)pInputData->pData;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
continue; continue;
...@@ -2253,7 +2244,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa ...@@ -2253,7 +2244,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
break; break;
} }
case TSDB_DATA_TYPE_FLOAT: { case TSDB_DATA_TYPE_FLOAT: {
float *in = (float *)pInputData->pData; float *in = (float *)pInputData->pData;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
continue; continue;
...@@ -2265,7 +2256,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa ...@@ -2265,7 +2256,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
break; break;
} }
case TSDB_DATA_TYPE_DOUBLE: { case TSDB_DATA_TYPE_DOUBLE: {
double *in = (double *)pInputData->pData; double *in = (double *)pInputData->pData;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
continue; continue;
...@@ -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;
...@@ -2304,13 +2294,13 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa ...@@ -2304,13 +2294,13 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
} }
int32_t percentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t percentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput); int32_t type = GET_PARAM_TYPE(pInput);
double val; double val;
bool hasNull = false; bool hasNull = false;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
hasNull = true; hasNull = true;
...@@ -2335,7 +2325,7 @@ int32_t apercentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScala ...@@ -2335,7 +2325,7 @@ int32_t apercentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScala
} }
int32_t spreadScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t spreadScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput); int32_t type = GET_PARAM_TYPE(pInput);
...@@ -2377,11 +2367,11 @@ int32_t spreadScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara ...@@ -2377,11 +2367,11 @@ int32_t spreadScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
} }
int32_t nonCalcScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t nonCalcScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput); int32_t type = GET_PARAM_TYPE(pInput);
bool hasNull = false; bool hasNull = false;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) { if (colDataIsNull_s(pInputData, i)) {
...@@ -2390,7 +2380,7 @@ int32_t nonCalcScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPar ...@@ -2390,7 +2380,7 @@ int32_t nonCalcScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPar
} }
} }
double *out = (double *)pOutputData->pData; double *out = (double *)pOutputData->pData;
if (hasNull) { if (hasNull) {
colDataAppendNULL(pOutputData, 0); colDataAppendNULL(pOutputData, 0);
} else { } else {
...@@ -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;
} }
...@@ -2553,10 +2543,10 @@ static bool checkStateOp(int8_t op, SColumnInfoData* pCol, int32_t index, SScala ...@@ -2553,10 +2543,10 @@ static bool checkStateOp(int8_t op, SColumnInfoData* pCol, int32_t index, SScala
} }
int32_t stateCountScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t stateCountScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
int8_t op = getStateOpType(varDataVal(pInput[1].columnData->pData)); int8_t op = getStateOpType(varDataVal(pInput[1].columnData->pData));
int64_t count = 0; int64_t count = 0;
for (int32_t i = 0; i < pInput->numOfRows; ++i) { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
...@@ -2565,14 +2555,14 @@ int32_t stateCountScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalar ...@@ -2565,14 +2555,14 @@ int32_t stateCountScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalar
continue; continue;
} }
bool ret = checkStateOp(op, pInputData, i, &pInput[2]); bool ret = checkStateOp(op, pInputData, i, &pInput[2]);
int64_t out = -1; int64_t out = -1;
if (ret) { if (ret) {
out = ++count; out = ++count;
} 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;
...@@ -2580,7 +2570,7 @@ int32_t stateCountScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalar ...@@ -2580,7 +2570,7 @@ int32_t stateCountScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalar
} }
int32_t stateDurationScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t stateDurationScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
int8_t op = getStateOpType(varDataVal(pInput[1].columnData->pData)); int8_t op = getStateOpType(varDataVal(pInput[1].columnData->pData));
...@@ -2591,12 +2581,12 @@ int32_t stateDurationScalarFunction(SScalarParam *pInput, int32_t inputNum, SSca ...@@ -2591,12 +2581,12 @@ int32_t stateDurationScalarFunction(SScalarParam *pInput, int32_t inputNum, SSca
continue; continue;
} }
bool ret = checkStateOp(op, pInputData, i, &pInput[2]); bool ret = checkStateOp(op, pInputData, i, &pInput[2]);
int64_t out = -1; int64_t out = -1;
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;
...@@ -2756,15 +2747,15 @@ static bool getHistogramBinDesc(SHistoFuncBin** bins, int32_t* binNum, char* bin ...@@ -2756,15 +2747,15 @@ static bool getHistogramBinDesc(SHistoFuncBin** bins, int32_t* binNum, char* bin
} }
int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
SHistoFuncBin *bins; SHistoFuncBin *bins;
int32_t numOfBins = 0; int32_t numOfBins = 0;
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);
...@@ -2820,7 +2811,7 @@ int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP ...@@ -2820,7 +2811,7 @@ int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
} }
int32_t selectScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t selectScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData; SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput); int32_t type = GET_PARAM_TYPE(pInput);
...@@ -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,15 +84,15 @@ void convertNumberToNumber(const void *inData, void *outData, int8_t inType, int ...@@ -83,15 +84,15 @@ 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) {
sclError("castConvert taosUcs4ToMbs error 1"); sclError("castConvert taosUcs4ToMbs error 1");
} }
...@@ -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,165 +119,119 @@ void convertBinaryToDouble(const void *inData, void *outData){ ...@@ -118,165 +119,119 @@ 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);
} }
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,30 +332,31 @@ static FORCE_INLINE void varToFloat(char *buf, SScalarParam* pOut, int32_t rowIn ...@@ -377,30 +332,31 @@ 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);
return; return;
...@@ -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;
...@@ -425,11 +381,11 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in ...@@ -425,11 +381,11 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in
func = varToUnsigned; func = varToUnsigned;
} else if (IS_FLOAT_TYPE(outType)) { } else if (IS_FLOAT_TYPE(outType)) {
func = varToFloat; func = varToFloat;
} else if (outType == TSDB_DATA_TYPE_BINARY) { // nchar -> binary } else if (outType == TSDB_DATA_TYPE_BINARY) { // nchar -> binary
ASSERT(inType == TSDB_DATA_TYPE_NCHAR); ASSERT(inType == TSDB_DATA_TYPE_NCHAR);
func = ncharToVar; func = ncharToVar;
vton = true; vton = true;
} else if (outType == TSDB_DATA_TYPE_NCHAR) { // binary -> nchar } else if (outType == TSDB_DATA_TYPE_NCHAR) { // binary -> nchar
ASSERT(inType == TSDB_DATA_TYPE_VARCHAR); ASSERT(inType == TSDB_DATA_TYPE_VARCHAR);
func = varToNchar; func = varToNchar;
vton = true; vton = true;
...@@ -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,10 +581,10 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t ...@@ -625,10 +581,10 @@ 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) {
for (int32_t i = 0; i < pIn->numOfRows; ++i) { for (int32_t i = 0; i < pIn->numOfRows; ++i) {
...@@ -690,17 +646,17 @@ int32_t vectorConvertToVarData(const SScalarParam* pIn, SScalarParam* pOut, int1 ...@@ -690,17 +646,17 @@ 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);
return TSDB_CODE_APP_ERROR; return TSDB_CODE_APP_ERROR;
} }
int16_t inType = pInputCol->info.type; int16_t inType = pInputCol->info.type;
int16_t outType = pOutputCol->info.type; int16_t outType = pOutputCol->info.type;
if (IS_VAR_DATA_TYPE(inType)) { if (IS_VAR_DATA_TYPE(inType)) {
return vectorConvertFromVarData(pIn, pOut, inType, outType, overflow); return vectorConvertFromVarData(pIn, pOut, inType, outType, overflow);
...@@ -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,15 +905,15 @@ int32_t vectorConvertScalarParam(SScalarParam *input, SScalarParam *output, int3 ...@@ -952,15 +905,15 @@ 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) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -968,7 +921,7 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p ...@@ -968,7 +921,7 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p
SScalarParam *param1 = NULL, *paramOut1 = NULL; SScalarParam *param1 = NULL, *paramOut1 = NULL;
SScalarParam *param2 = NULL, *paramOut2 = NULL; SScalarParam *param2 = NULL, *paramOut2 = NULL;
int32_t code = 0; int32_t code = 0;
if (leftType < rightType) { if (leftType < rightType) {
param1 = pLeft; param1 = pLeft;
...@@ -1009,14 +962,14 @@ enum { ...@@ -1009,14 +962,14 @@ 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;
SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; SDataType t = {.type = type, .bytes = tDataTypes[type].bytes};
int32_t code = sclCreateColumnInfoData(&t, pParam->numOfRows, pDest); int32_t code = sclCreateColumnInfoData(&t, pParam->numOfRows, pDest);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return code; return code;
} }
...@@ -1035,8 +988,9 @@ static int32_t doConvertHelper(SScalarParam* pDest, int32_t* convert, const SSca ...@@ -1035,8 +988,9 @@ 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,
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); int32_t numOfRows, int32_t step, int32_t i) {
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
double *output = (double *)pOutputCol->pData; double *output = (double *)pOutputCol->pData;
...@@ -1049,14 +1003,14 @@ static void vectorMathAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRig ...@@ -1049,14 +1003,14 @@ 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,
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); int32_t numOfRows, int32_t step, int32_t i) {
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
int64_t *output = (int64_t *)pOutputCol->pData; int64_t *output = (int64_t *)pOutputCol->pData;
...@@ -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 =
pRightCol->info.scale, pRightCol->info.precision); taosTimeAdd(getVectorBigintValueFnLeft(pLeftCol->pData, i), getVectorBigintValueFnRight(pRightCol->pData, 0),
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,31 +1046,32 @@ static SColumnInfoData* doVectorConvert(SScalarParam* pInput, int32_t* doConvert ...@@ -1091,31 +1046,32 @@ 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);
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 && 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 &&
int64_t *output = (int64_t *)pOutputCol->pData; GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_BOOL)) { // timestamp plus duration
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); int64_t *output = (int64_t *)pOutputCol->pData;
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
if (pLeft->numOfRows == 1 && pRight->numOfRows == 1) { if (pLeft->numOfRows == 1 && pRight->numOfRows == 1) {
...@@ -1138,13 +1094,13 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut ...@@ -1138,13 +1094,13 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
} }
} }
} else { } else {
double *output = (double *)pOutputCol->pData; double *output = (double *)pOutputCol->pData;
_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);
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,8 +1118,9 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut ...@@ -1162,8 +1118,9 @@ 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,
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); int32_t numOfRows, int32_t step, int32_t factor, int32_t i) {
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
double *output = (double *)pOutputCol->pData; double *output = (double *)pOutputCol->pData;
...@@ -1176,14 +1133,14 @@ static void vectorMathSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRig ...@@ -1176,14 +1133,14 @@ 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,
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); int32_t numOfRows, int32_t step, int32_t factor, int32_t i) {
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
int64_t *output = (int64_t *)pOutputCol->pData; int64_t *output = (int64_t *)pOutputCol->pData;
...@@ -1196,29 +1153,30 @@ static void vectorMathTsSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pR ...@@ -1196,29 +1153,30 @@ 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 =
pRightCol->info.scale, pRightCol->info.precision); taosTimeAdd(getVectorBigintValueFnLeft(pLeftCol->pData, i), -getVectorBigintValueFnRight(pRightCol->pData, 0),
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 &&
int64_t *output = (int64_t *)pOutputCol->pData; GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_BIGINT)) { // timestamp minus duration
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); int64_t *output = (int64_t *)pOutputCol->pData;
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
if (pLeft->numOfRows == 1 && pRight->numOfRows == 1) { if (pLeft->numOfRows == 1 && pRight->numOfRows == 1) {
...@@ -1237,8 +1195,8 @@ void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut ...@@ -1237,8 +1195,8 @@ void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
} }
} }
} else { } else {
double *output = (double *)pOutputCol->pData; double *output = (double *)pOutputCol->pData;
_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);
if (pLeft->numOfRows == pRight->numOfRows) { if (pLeft->numOfRows == pRight->numOfRows) {
...@@ -1256,13 +1214,14 @@ void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut ...@@ -1256,13 +1214,14 @@ void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
} }
} }
doReleaseVec(pLeftCol, leftConvert); doReleaseVec(pLeftCol, leftConvert);
doReleaseVec(pRightCol, rightConvert); doReleaseVec(pRightCol, rightConvert);
} }
// 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,
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); int32_t numOfRows, int32_t step, int32_t i) {
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
double *output = (double *)pOutputCol->pData; double *output = (double *)pOutputCol->pData;
...@@ -1280,18 +1239,18 @@ static void vectorMathMultiplyHelper(SColumnInfoData* pLeftCol, SColumnInfoData* ...@@ -1280,18 +1239,18 @@ 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);
SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert); SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
_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);
double *output = (double *)pOutputCol->pData; double *output = (double *)pOutputCol->pData;
...@@ -1313,45 +1272,44 @@ void vectorMathMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam ...@@ -1313,45 +1272,44 @@ 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);
SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert); SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
_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);
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
colDataAppendNNULL(pOutputCol, 0, pRight->numOfRows); colDataAppendNNULL(pOutputCol, 0, pRight->numOfRows);
} else { } else {
for (; i >= 0 && i < pRight->numOfRows; i += step, output += 1) { for (; i >= 0 && i < pRight->numOfRows; i += step, output += 1) {
if (IS_HELPER_NULL(pRightCol, i) || (getVectorDoubleValueFnRight(RIGHT_COL, i) == 0)) { // divide by 0 check if (IS_HELPER_NULL(pRightCol, i) || (getVectorDoubleValueFnRight(RIGHT_COL, i) == 0)) { // divide by 0 check
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,28 +1317,27 @@ void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *p ...@@ -1359,28 +1317,27 @@ 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);
} }
} }
} }
doReleaseVec(pLeftCol, leftConvert); doReleaseVec(pLeftCol, leftConvert);
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);
SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert); SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
_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);
double *output = (double *)pOutputCol->pData; double *output = (double *)pOutputCol->pData;
...@@ -1447,18 +1404,18 @@ void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam ...@@ -1447,18 +1404,18 @@ 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);
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
double *output = (double *)pOutputCol->pData; double *output = (double *)pOutputCol->pData;
for (; i < pLeft->numOfRows && i >= 0; i += step, output += 1) { for (; i < pLeft->numOfRows && i >= 0; i += step, output += 1) {
...@@ -1470,17 +1427,17 @@ void vectorMathMinus(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO ...@@ -1470,17 +1427,17 @@ void vectorMathMinus(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO
*output = (result == 0) ? 0 : -result; *output = (result == 0) ? 0 : -result;
} }
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,8 +1498,9 @@ void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t ...@@ -1541,8 +1498,9 @@ 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,
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); int32_t numOfRows, int32_t step, int32_t i) {
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
int64_t *output = (int64_t *)pOutputCol->pData; int64_t *output = (int64_t *)pOutputCol->pData;
...@@ -1560,18 +1518,18 @@ static void vectorBitAndHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRigh ...@@ -1560,18 +1518,18 @@ 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);
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);
_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);
int64_t *output = (int64_t *)pOutputCol->pData; int64_t *output = (int64_t *)pOutputCol->pData;
...@@ -1589,12 +1547,13 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, ...@@ -1589,12 +1547,13 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
vectorBitAndHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i); vectorBitAndHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i);
} }
doReleaseVec(pLeftCol, leftConvert); doReleaseVec(pLeftCol, leftConvert);
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,
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); int32_t numOfRows, int32_t step, int32_t i) {
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
int64_t *output = (int64_t *)pOutputCol->pData; int64_t *output = (int64_t *)pOutputCol->pData;
...@@ -1613,18 +1572,18 @@ static void vectorBitOrHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRight ...@@ -1613,18 +1572,18 @@ 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);
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);
_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);
int64_t *output = (int64_t *)pOutputCol->pData; int64_t *output = (int64_t *)pOutputCol->pData;
...@@ -1642,17 +1601,17 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, ...@@ -1642,17 +1601,17 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
vectorBitOrHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i); vectorBitOrHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i);
} }
doReleaseVec(pLeftCol, leftConvert); doReleaseVec(pLeftCol, leftConvert);
doReleaseVec(pRightCol, rightConvert); doReleaseVec(pRightCol, rightConvert);
} }
int32_t doVectorCompareImpl(int32_t numOfRows, SScalarParam *pOut, int32_t startIndex, int32_t step, __compar_fn_t fp, int32_t doVectorCompareImpl(int32_t numOfRows, SScalarParam *pOut, int32_t startIndex, int32_t step, __compar_fn_t fp,
SScalarParam *pLeft, SScalarParam *pRight, int32_t optr) { SScalarParam *pLeft, SScalarParam *pRight, int32_t optr) {
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,15 +1619,15 @@ int32_t doVectorCompareImpl(int32_t numOfRows, SScalarParam *pOut, int32_t start ...@@ -1660,15 +1619,15 @@ 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;
bool freeRight = false; bool freeRight = false;
bool isJsonnull = false; bool isJsonnull = false;
bool result = convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData, bool result = convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData,
&leftOut, &rightOut, &isJsonnull, &freeLeft, &freeRight); &leftOut, &rightOut, &isJsonnull, &freeLeft, &freeRight);
if (isJsonnull) { if (isJsonnull) {
ASSERT(0); ASSERT(0);
...@@ -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);
...@@ -1718,14 +1677,14 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam * ...@@ -1718,14 +1677,14 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *
if (pRight->pHashFilter != NULL) { if (pRight->pHashFilter != NULL) {
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,9 +1694,9 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam * ...@@ -1735,9 +1694,9 @@ 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;
SScalarParam *param2 = NULL; SScalarParam *param2 = 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);
...@@ -1900,12 +1858,12 @@ void vectorJsonArrow(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO ...@@ -1900,12 +1858,12 @@ void vectorJsonArrow(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO
pOutputCol->hasNull = true; pOutputCol->hasNull = true;
continue; continue;
} }
char *pLeftData = colDataGetVarData(pLeft->columnData, i); char *pLeftData = colDataGetVarData(pLeft->columnData, i);
bool isExist = false; bool isExist = false;
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,26 +32,21 @@ ...@@ -32,26 +32,21 @@
#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"
namespace { namespace {
int64_t flttLeftV = 21, flttRightV = 10; int64_t flttLeftV = 21, flttRightV = 10;
double flttLeftVd = 21.0, flttRightVd = 10.0; double flttLeftVd = 21.0, flttRightVd = 10.0;
void flttInitLogFile() { void flttInitLogFile() {
const char *defaultLogFileNamePrefix = "taoslog"; const char *defaultLogFileNamePrefix = "taoslog";
...@@ -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;
...@@ -80,19 +74,20 @@ void flttMakeValueNode(SNode **pNode, int32_t dataType, void *value) { ...@@ -80,19 +74,20 @@ void flttMakeValueNode(SNode **pNode, int32_t dataType, void *value) {
vnode->node.resType.bytes = tDataTypes[dataType].bytes; vnode->node.resType.bytes = tDataTypes[dataType].bytes;
assignVal((char *)nodesGetValueFromNode(vnode), (const char *)value, 0, dataType); assignVal((char *)nodesGetValueFromNode(vnode), (const char *)value, 0, dataType);
} }
*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;
rnode->dataBlockId = 0; rnode->dataBlockId = 0;
sprintf(rnode->dbName, "%" PRIu64, dbidx++); sprintf(rnode->dbName, "%" PRIu64, dbidx++);
if (NULL == block) { if (NULL == block) {
...@@ -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);
} }
...@@ -131,9 +126,9 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in ...@@ -131,9 +126,9 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in
*block = res; *block = res;
} else { } else {
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);
...@@ -147,7 +142,7 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in ...@@ -147,7 +142,7 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in
value = (char *)value + dataBytes; value = (char *)value + dataBytes;
} }
} }
rnode->slotId = idx; rnode->slotId = idx;
rnode->colId = 1 + idx; rnode->colId = 1 + idx;
} }
...@@ -156,11 +151,11 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in ...@@ -156,11 +151,11 @@ 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;
onode->opType = opType; onode->opType = opType;
onode->pLeft = pLeft; onode->pLeft = pLeft;
onode->pRight = pRight; onode->pRight = pRight;
...@@ -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;
...@@ -179,24 +174,24 @@ void flttMakeLogicNode(SNode **pNode, ELogicConditionType opType, SNode **nodeLi ...@@ -179,24 +174,24 @@ void flttMakeLogicNode(SNode **pNode, ELogicConditionType opType, SNode **nodeLi
for (int32_t i = 0; i < nodeNum; ++i) { for (int32_t i = 0; i < nodeNum; ++i) {
nodesListAppend(onode->pParameterList, nodeList[i]); nodesListAppend(onode->pParameterList, nodeList[i]);
} }
*pNode = (SNode *)onode; *pNode = (SNode *)onode;
} }
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;
onode->node.resType.bytes = sizeof(bool); onode->node.resType.bytes = sizeof(bool);
onode->pParameterList = nodeList; onode->pParameterList = nodeList;
*pNode = (SNode *)onode; *pNode = (SNode *)onode;
} }
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,169 +199,166 @@ void flttMakeListNode(SNode **pNode, SNodeList *list, int32_t resType) { ...@@ -204,169 +199,166 @@ 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;
bool eRes[5] = {false, false, true, true, true}; bool eRes[5] = {false, false, true, true, true};
SScalarParam res; SScalarParam res;
initScalarParam(&res); initScalarParam(&res);
int64_t tsmall = 222, tbig = 333; int64_t tsmall = 222, tbig = 333;
flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL);
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);
} }
TEST(timerangeTest, greater_and_lower) { TEST(timerangeTest, greater_and_lower) {
SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL; SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL;
bool eRes[5] = {false, false, true, true, true}; bool eRes[5] = {false, false, true, true, true};
SScalarParam res; SScalarParam res;
initScalarParam(&res); initScalarParam(&res);
int64_t tsmall = 222, tbig = 333; int64_t tsmall = 222, tbig = 333;
flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL);
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);
flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL);
flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tbig); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tbig);
flttMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval); flttMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval);
SNode *list[2] = {0}; SNode *list[2] = {0};
list[0] = opNode1; list[0] = opNode1;
list[1] = opNode2; list[1] = opNode2;
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);
} }
TEST(timerangeTest, greater_equal_and_lower_equal) { TEST(timerangeTest, greater_equal_and_lower_equal) {
SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL; SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL;
bool eRes[5] = {false, false, true, true, true}; bool eRes[5] = {false, false, true, true, true};
SScalarParam res; SScalarParam res;
initScalarParam(&res); initScalarParam(&res);
int64_t tsmall = 222, tbig = 333; int64_t tsmall = 222, tbig = 333;
flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL);
flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall);
flttMakeOpNode(&opNode1, OP_TYPE_GREATER_EQUAL, TSDB_DATA_TYPE_BOOL, pcol, pval); flttMakeOpNode(&opNode1, OP_TYPE_GREATER_EQUAL, TSDB_DATA_TYPE_BOOL, pcol, pval);
flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL);
flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tbig); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tbig);
flttMakeOpNode(&opNode2, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pcol, pval); flttMakeOpNode(&opNode2, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pcol, pval);
SNode *list[2] = {0}; SNode *list[2] = {0};
list[0] = opNode1; list[0] = opNode1;
list[1] = opNode2; list[1] = opNode2;
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); 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};
SScalarParam res; SScalarParam res;
initScalarParam(&res); initScalarParam(&res);
int64_t tsmall1 = 222, tbig1 = 333; int64_t tsmall1 = 222, tbig1 = 333;
int64_t tsmall2 = 444, tbig2 = 555; int64_t tsmall2 = 444, tbig2 = 555;
SNode *list[2] = {0}; SNode *list[2] = {0};
flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL);
flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall1); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall1);
flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval); flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval);
flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL);
flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tbig1); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tbig1);
flttMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval); flttMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval);
list[0] = opNode1; list[0] = opNode1;
list[1] = opNode2; list[1] = opNode2;
flttMakeLogicNode(&logicNode1, LOGIC_COND_TYPE_AND, list, 2); flttMakeLogicNode(&logicNode1, LOGIC_COND_TYPE_AND, list, 2);
flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL);
flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall2); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall2);
flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval); flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval);
flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL);
flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tbig2); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tbig2);
flttMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval); flttMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval);
list[0] = opNode1; list[0] = opNode1;
list[1] = opNode2; list[1] = opNode2;
flttMakeLogicNode(&logicNode2, LOGIC_COND_TYPE_AND, list, 2); flttMakeLogicNode(&logicNode2, LOGIC_COND_TYPE_AND, list, 2);
list[0] = logicNode1; list[0] = logicNode1;
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);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
int32_t code = filterInitFromNode(opNode, &filter, 0); int32_t code = filterInitFromNode(opNode, &filter, 0);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
...@@ -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) {
...@@ -409,20 +401,20 @@ TEST(columnTest, smallint_column_greater_double_value) { ...@@ -409,20 +401,20 @@ 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);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
int32_t code = filterInitFromNode(opNode, &filter, 0); int32_t code = filterInitFromNode(opNode, &filter, 0);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0}; SColumnDataAgg stat = {0};
...@@ -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) {
...@@ -465,31 +457,31 @@ TEST(columnTest, int_column_greater_smallint_value) { ...@@ -465,31 +457,31 @@ 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;
int32_t code = filterInitFromNode(opNode, &filter, 0); int32_t code = filterInitFromNode(opNode, &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);
...@@ -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) {
...@@ -511,13 +503,13 @@ TEST(columnTest, int_column_in_double_list) { ...@@ -511,13 +503,13 @@ TEST(columnTest, int_column_in_double_list) {
} }
TEST(columnTest, binary_column_in_binary_list) { 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;
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,24 +529,24 @@ TEST(columnTest, binary_column_in_binary_list) { ...@@ -537,24 +529,24 @@ 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;
int32_t code = filterInitFromNode(opNode, &filter, 0); int32_t code = filterInitFromNode(opNode, &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);
...@@ -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) {
...@@ -575,9 +567,9 @@ TEST(columnTest, binary_column_in_binary_list) { ...@@ -575,9 +567,9 @@ 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");
...@@ -599,11 +591,11 @@ TEST(columnTest, binary_column_like_binary) { ...@@ -599,11 +591,11 @@ TEST(columnTest, binary_column_like_binary) {
flttMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
int32_t code = filterInitFromNode(opNode, &filter, 0); int32_t code = filterInitFromNode(opNode, &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);
...@@ -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) {
...@@ -624,8 +616,8 @@ TEST(columnTest, binary_column_like_binary) { ...@@ -624,8 +616,8 @@ 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);
...@@ -647,11 +639,11 @@ TEST(columnTest, binary_column_is_null) { ...@@ -647,11 +639,11 @@ TEST(columnTest, binary_column_is_null) {
flttMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL); flttMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
int32_t code = filterInitFromNode(opNode, &filter, 0); int32_t code = filterInitFromNode(opNode, &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);
...@@ -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) {
...@@ -672,8 +664,8 @@ TEST(columnTest, binary_column_is_null) { ...@@ -672,8 +664,8 @@ 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);
...@@ -695,11 +687,11 @@ TEST(columnTest, binary_column_is_not_null) { ...@@ -695,11 +687,11 @@ TEST(columnTest, binary_column_is_not_null) {
flttMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL); flttMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
int32_t code = filterInitFromNode(opNode, &filter, 0); int32_t code = filterInitFromNode(opNode, &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);
...@@ -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) {
...@@ -720,24 +712,24 @@ TEST(columnTest, binary_column_is_not_null) { ...@@ -720,24 +712,24 @@ 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);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
int32_t code = filterInitFromNode(opNode, &filter, 0); int32_t code = filterInitFromNode(opNode, &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);
...@@ -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) {
...@@ -758,25 +750,25 @@ TEST(opTest, smallint_column_greater_int_column) { ...@@ -758,25 +750,25 @@ 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);
flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
int32_t code = filterInitFromNode(opNode, &filter, 0); int32_t code = filterInitFromNode(opNode, &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);
...@@ -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) {
...@@ -797,30 +789,30 @@ TEST(opTest, smallint_value_add_int_column) { ...@@ -797,30 +789,30 @@ 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;
varDataSetLen(rightv[i], 3); varDataSetLen(rightv[i], 3);
} }
bool eRes[5] = {false, true, true, true, true}; bool eRes[5] = {false, true, true, 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_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);
flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
int32_t code = filterInitFromNode(opNode, &filter, 0); int32_t code = filterInitFromNode(opNode, &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);
...@@ -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) {
...@@ -841,30 +833,30 @@ TEST(opTest, bigint_column_multi_binary_column) { ...@@ -841,30 +833,30 @@ 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;
varDataSetLen(rightv[i], 3); varDataSetLen(rightv[i], 3);
} }
bool eRes[5] = {false, false, true, false, true}; bool eRes[5] = {false, 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_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);
flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
int32_t code = filterInitFromNode(opNode, &filter, 0); int32_t code = filterInitFromNode(opNode, &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);
...@@ -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) {
...@@ -885,25 +877,25 @@ TEST(opTest, smallint_column_and_binary_column) { ...@@ -885,25 +877,25 @@ 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);
flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
int32_t code = filterInitFromNode(opNode, &filter, 0); int32_t code = filterInitFromNode(opNode, &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);
...@@ -911,7 +903,7 @@ TEST(opTest, smallint_column_or_float_column) { ...@@ -911,7 +903,7 @@ TEST(opTest, smallint_column_or_float_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, taosArrayGetSize(src->pDataBlock)); bool keep = filterExecute(filter, src, &rowRes, &stat, 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) {
...@@ -924,25 +916,25 @@ TEST(opTest, smallint_column_or_float_column) { ...@@ -924,25 +916,25 @@ 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);
flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
int32_t code = filterInitFromNode(opNode, &filter, 0); int32_t code = filterInitFromNode(opNode, &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);
...@@ -950,7 +942,7 @@ TEST(opTest, smallint_column_or_double_value) { ...@@ -950,7 +942,7 @@ TEST(opTest, smallint_column_or_double_value) {
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, taosArrayGetSize(src->pDataBlock)); bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock));
ASSERT_EQ(keep, true); ASSERT_EQ(keep, true);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
...@@ -963,8 +955,8 @@ TEST(opTest, smallint_column_or_double_value) { ...@@ -963,8 +955,8 @@ 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,17 +969,17 @@ TEST(opTest, binary_column_is_true) { ...@@ -977,17 +969,17 @@ 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);
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
int32_t code = filterInitFromNode(opNode, &filter, 0); int32_t code = filterInitFromNode(opNode, &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);
...@@ -995,7 +987,7 @@ TEST(opTest, binary_column_is_true) { ...@@ -995,7 +987,7 @@ TEST(opTest, binary_column_is_true) {
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, taosArrayGetSize(src->pDataBlock)); bool keep = filterExecute(filter, src, &rowRes, &stat, 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) {
...@@ -1010,16 +1002,16 @@ TEST(opTest, binary_column_is_true) { ...@@ -1010,16 +1002,16 @@ TEST(opTest, binary_column_is_true) {
TEST(filterModelogicTest, diff_columns_and_or_and) { TEST(filterModelogicTest, diff_columns_and_or_and) {
flttInitLogFile(); flttInitLogFile();
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);
...@@ -1066,7 +1056,7 @@ TEST(filterModelogicTest, diff_columns_and_or_and) { ...@@ -1066,7 +1056,7 @@ TEST(filterModelogicTest, diff_columns_and_or_and) {
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, taosArrayGetSize(src->pDataBlock)); bool keep = filterExecute(filter, src, &rowRes, &stat, 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) {
...@@ -1079,16 +1069,16 @@ TEST(filterModelogicTest, diff_columns_and_or_and) { ...@@ -1079,16 +1069,16 @@ 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);
...@@ -1135,7 +1123,7 @@ TEST(filterModelogicTest, same_column_and_or_and) { ...@@ -1135,7 +1123,7 @@ TEST(filterModelogicTest, same_column_and_or_and) {
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, taosArrayGetSize(src->pDataBlock)); bool keep = filterExecute(filter, src, &rowRes, &stat, 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) {
...@@ -1148,16 +1136,16 @@ TEST(filterModelogicTest, same_column_and_or_and) { ...@@ -1148,16 +1136,16 @@ 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);
...@@ -1204,7 +1190,7 @@ TEST(filterModelogicTest, diff_columns_or_and_or) { ...@@ -1204,7 +1190,7 @@ TEST(filterModelogicTest, diff_columns_or_and_or) {
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, taosArrayGetSize(src->pDataBlock)); bool keep = filterExecute(filter, src, &rowRes, &stat, 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) {
...@@ -1217,16 +1203,16 @@ TEST(filterModelogicTest, diff_columns_or_and_or) { ...@@ -1217,16 +1203,16 @@ 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);
...@@ -1273,7 +1257,7 @@ TEST(filterModelogicTest, same_column_or_and_or) { ...@@ -1273,7 +1257,7 @@ TEST(filterModelogicTest, same_column_or_and_or) {
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, taosArrayGetSize(src->pDataBlock)); bool keep = filterExecute(filter, src, &rowRes, &stat, 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) {
...@@ -1288,16 +1272,16 @@ TEST(filterModelogicTest, same_column_or_and_or) { ...@@ -1288,16 +1272,16 @@ TEST(filterModelogicTest, same_column_or_and_or) {
TEST(scalarModelogicTest, diff_columns_or_and_or) { TEST(scalarModelogicTest, diff_columns_or_and_or) {
flttInitLogFile(); flttInitLogFile();
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);
...@@ -1344,9 +1326,9 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { ...@@ -1344,9 +1326,9 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) {
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, taosArrayGetSize(src->pDataBlock)); bool keep = filterExecute(filter, src, &rowRes, &stat, 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) {
ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]);
} }
...@@ -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();
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
...@@ -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.
先完成此消息的编辑!
想要评论请 注册