diff --git a/source/libs/scalar/inc/filterInt.h b/source/libs/scalar/inc/filterInt.h
index ef3d3f79f959805681d0bc0e2e0b101cd8518388..e26bc59d47e368487370d9f0c260d61b24dc84a7 100644
--- a/source/libs/scalar/inc/filterInt.h
+++ b/source/libs/scalar/inc/filterInt.h
@@ -28,19 +28,19 @@ extern "C" {
#include "thash.h"
#include "tname.h"
-#define FILTER_DEFAULT_GROUP_SIZE 4
-#define FILTER_DEFAULT_UNIT_SIZE 4
-#define FILTER_DEFAULT_FIELD_SIZE 4
-#define FILTER_DEFAULT_VALUE_SIZE 4
+#define FILTER_DEFAULT_GROUP_SIZE 4
+#define FILTER_DEFAULT_UNIT_SIZE 4
+#define FILTER_DEFAULT_FIELD_SIZE 4
+#define FILTER_DEFAULT_VALUE_SIZE 4
#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
enum {
FLD_TYPE_COLUMN = 1,
- FLD_TYPE_VALUE = 2,
+ FLD_TYPE_VALUE = 2,
FLD_TYPE_MAX = 3,
FLD_DATA_NO_FREE = 8,
FLD_DATA_IS_HASH = 16,
@@ -56,10 +56,9 @@ enum {
enum {
RANGE_FLG_EXCLUDE = 1,
RANGE_FLG_INCLUDE = 2,
- RANGE_FLG_NULL = 4,
+ RANGE_FLG_NULL = 4,
};
-
enum {
FI_STATUS_ALL = 1,
FI_STATUS_EMPTY = 2,
@@ -93,63 +92,63 @@ typedef struct OptrStr {
typedef struct SFilterRange {
int64_t s;
int64_t e;
- char sflag;
- char eflag;
+ char sflag;
+ char eflag;
} SFilterRange;
-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 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 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 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 struct SFilterRangeCompare {
- int64_t s;
- int64_t e;
+ int64_t s;
+ int64_t e;
rangeCompFunc func;
} SFilterRangeCompare;
typedef struct SFilterRangeNode {
- struct SFilterRangeNode* prev;
- struct SFilterRangeNode* next;
+ struct SFilterRangeNode *prev;
+ struct SFilterRangeNode *next;
union {
- SFilterRange ra;
+ SFilterRange ra;
SFilterRangeCompare rc;
};
} SFilterRangeNode;
typedef struct SFilterRangeCtx {
- int32_t type;
- int32_t options;
- int8_t status;
- bool isnull;
- bool notnull;
- bool isrange;
- int16_t colId;
- __compar_fn_t pCompareFunc;
- SFilterRangeNode *rf; //freed
+ int32_t type;
+ int32_t options;
+ int8_t status;
+ bool isnull;
+ bool notnull;
+ bool isrange;
+ int16_t colId;
+ __compar_fn_t pCompareFunc;
+ SFilterRangeNode *rf; // freed
SFilterRangeNode *rs;
-} SFilterRangeCtx ;
+} SFilterRangeCtx;
typedef struct SFilterVarCtx {
- int32_t type;
- int32_t options;
- int8_t status;
- bool isnull;
- bool notnull;
- bool isrange;
+ int32_t type;
+ int32_t options;
+ int8_t status;
+ bool isnull;
+ bool notnull;
+ bool isrange;
SHashObj *wild;
SHashObj *value;
} SFilterVarCtx;
typedef struct SFilterField {
uint16_t flag;
- void* desc;
- void* data;
+ void *desc;
+ void *data;
} SFilterField;
typedef struct SFilterFields {
- uint32_t size;
- uint32_t num;
+ uint32_t size;
+ uint32_t num;
SFilterField *fields;
} SFilterFields;
@@ -174,40 +173,40 @@ typedef struct SFilterColInfo {
} SFilterColInfo;
typedef struct SFilterGroupCtx {
- uint32_t colNum;
- uint32_t *colIdx;
- SFilterColInfo *colInfo;
+ uint32_t colNum;
+ uint32_t *colIdx;
+ SFilterColInfo *colInfo;
} SFilterGroupCtx;
typedef struct SFilterColCtx {
- uint32_t colIdx;
- void* ctx;
+ uint32_t colIdx;
+ void *ctx;
} SFilterColCtx;
typedef struct SFilterCompare {
- uint8_t type;
- int8_t precision;
- uint8_t optr;
- uint8_t optr2;
+ uint8_t type;
+ int8_t precision;
+ uint8_t optr;
+ uint8_t optr2;
} SFilterCompare;
typedef struct SFilterUnit {
- SFilterCompare compare;
- SFilterFieldId left;
- SFilterFieldId right;
- SFilterFieldId right2;
+ SFilterCompare compare;
+ SFilterFieldId left;
+ SFilterFieldId right;
+ SFilterFieldId right2;
} SFilterUnit;
typedef struct SFilterComUnit {
- void *colData; // pointer to SColumnInfoData
- void *valData;
- void *valData2;
+ void *colData; // pointer to SColumnInfoData
+ void *valData;
+ void *valData2;
uint16_t colId;
uint16_t dataSize;
- uint8_t dataType;
- uint8_t optr;
- int8_t func;
- int8_t rfunc;
+ uint8_t dataType;
+ uint8_t optr;
+ int8_t func;
+ int8_t rfunc;
} SFilterComUnit;
typedef struct SFilterPCtx {
@@ -219,8 +218,8 @@ typedef struct SFltTreeStat {
int32_t code;
int8_t precision;
bool scalarMode;
- SArray* nodeList;
- SFilterInfo* info;
+ SArray *nodeList;
+ SFilterInfo *info;
} SFltTreeStat;
typedef struct SFltScalarCtx {
@@ -237,7 +236,7 @@ struct SFilterInfo {
bool scalarMode;
SFltScalarCtx sclCtx;
uint32_t options;
- uint32_t status;
+ uint32_t status;
uint32_t unitSize;
uint32_t unitNum;
uint32_t groupNum;
@@ -249,7 +248,7 @@ struct SFilterInfo {
uint8_t *unitRes; // result
uint8_t *unitFlags; // got result
SFilterRangeCtx **colRange;
- filter_exec_func func;
+ filter_exec_func func;
uint8_t blkFlag;
uint32_t blkGroupNum;
uint32_t *blkUnits;
@@ -257,98 +256,231 @@ struct SFilterInfo {
void *pTable;
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 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_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 SET_AND_OPTR(ctx, o) \
+ do { \
+ if (o == OP_TYPE_IS_NULL) { \
+ (ctx)->isnull = true; \
+ } else if (o == OP_TYPE_IS_NOT_NULL) { \
+ if (!(ctx)->isrange) { \
+ (ctx)->notnull = true; \
+ } \
+ } else if (o != FILTER_DUMMY_EMPTY_OPTR) { \
+ (ctx)->isrange = true; \
+ (ctx)->notnull = false; \
+ } \
+ } while (0)
+#define SET_OR_OPTR(ctx, o) \
+ do { \
+ if (o == 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_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_SET_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 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 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_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 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 fltFatal(...) qFatal(__VA_ARGS__)
-#define fltError(...) qError(__VA_ARGS__)
-#define fltWarn(...) qWarn(__VA_ARGS__)
-#define fltInfo(...) qInfo(__VA_ARGS__)
-#define fltDebug(...) qDebug(__VA_ARGS__)
-#define fltTrace(...) qTrace(__VA_ARGS__)
-
-
-#define FLT_CHK_JMP(c) do { if (c) { goto _return; } } while (0)
-#define FLT_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
-#define FLT_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
-#define FLT_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
-
-
-#define FILTER_GET_FIELD(i, id) (&((i)->fields[(id).type].fields[(id).idx]))
-#define FILTER_GET_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 fltFatal(...) qFatal(__VA_ARGS__)
+#define fltError(...) qError(__VA_ARGS__)
+#define fltWarn(...) qWarn(__VA_ARGS__)
+#define fltInfo(...) qInfo(__VA_ARGS__)
+#define fltDebug(...) qDebug(__VA_ARGS__)
+#define fltTrace(...) qTrace(__VA_ARGS__)
+
+#define FLT_CHK_JMP(c) \
+ do { \
+ if (c) { \
+ goto _return; \
+ } \
+ } while (0)
+#define FLT_ERR_RET(c) \
+ do { \
+ int32_t _code = c; \
+ if (_code != TSDB_CODE_SUCCESS) { \
+ terrno = _code; \
+ return _code; \
+ } \
+ } while (0)
+#define FLT_RET(c) \
+ do { \
+ int32_t _code = c; \
+ if (_code != TSDB_CODE_SUCCESS) { \
+ terrno = _code; \
+ } \
+ return _code; \
+ } while (0)
+#define FLT_ERR_JRET(c) \
+ do { \
+ code = c; \
+ if (code != TSDB_CODE_SUCCESS) { \
+ terrno = code; \
+ goto _return; \
+ } \
+ } while (0)
+
+#define FILTER_GET_FIELD(i, id) (&((i)->fields[(id).type].fields[(id).idx]))
+#define FILTER_GET_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_SIZE(fi) (((SColumnNode *)((fi)->desc))->node.resType.bytes)
-#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_DESC(fi) ((SColumnNode *)((fi)->desc))
-#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_DATA(fi) ((char *)(fi)->data)
-#define FILTER_GET_TYPE(fl) ((fl) & FLD_TYPE_MAX)
-
-#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_RIGHT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->right)
+#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_SLOT_ID(fi) (((SColumnNode *)((fi)->desc))->slotId)
+#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_VAL_FIELD_TYPE(fi) (((SValueNode *)((fi)->desc))->node.resType.type)
+#define FILTER_GET_VAL_FIELD_DATA(fi) ((char *)(fi)->data)
+#define FILTER_GET_TYPE(fl) ((fl)&FLD_TYPE_MAX)
+
+#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_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_DATA_TYPE(u) ((u)->compare.type)
-#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_DATA_TYPE(u) ((u)->compare.type)
+#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_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_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_COL_IDX(u) ((u)->left.idx)
-#define FILTER_UNIT_OPTR(u) ((u)->compare.optr)
-#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_SET_F(i, idx) (i)->unitFlags[idx] = 1
-#define FILTER_UNIT_GET_F(i, idx) ((i)->unitFlags[idx])
-#define FILTER_UNIT_GET_R(i, idx) ((i)->unitRes[idx])
+#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_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_OPTR(u) ((u)->compare.optr)
+#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_SET_F(i, idx) (i)->unitFlags[idx] = 1
+#define FILTER_UNIT_GET_F(i, idx) ((i)->unitFlags[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_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_VAR_HASH(colInfo, ha) do { (colInfo).type = RANGE_TYPE_VAR_HASH; (colInfo).info = ha;} while (0)
-#define FILTER_PUSH_CTX(colInfo, ctx) do { (colInfo).type = RANGE_TYPE_MR_CTX; (colInfo).info = ctx;} while (0)
-
-#define FILTER_COPY_IDX(dst, src, n) do { *(dst) = taosMemoryMalloc(sizeof(uint32_t) * n); memcpy(*(dst), src, sizeof(uint32_t) * n);} while (0)
-
-#define FILTER_ADD_CTX_TO_GRES(gres, idx, ctx) do { if ((gres)->colCtxs == NULL) { (gres)->colCtxs = taosArrayInit(gres->colNum, sizeof(SFilterColCtx)); } SFilterColCtx cCtx = {idx, ctx}; taosArrayPush((gres)->colCtxs, &cCtx); } while (0)
-
-
-#define FILTER_ALL_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_ALL)
+#define FILTER_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_VAR_HASH(colInfo, ha) \
+ do { \
+ (colInfo).type = RANGE_TYPE_VAR_HASH; \
+ (colInfo).info = ha; \
+ } while (0)
+#define FILTER_PUSH_CTX(colInfo, ctx) \
+ do { \
+ (colInfo).type = RANGE_TYPE_MR_CTX; \
+ (colInfo).info = ctx; \
+ } while (0)
+
+#define FILTER_COPY_IDX(dst, src, n) \
+ do { \
+ *(dst) = taosMemoryMalloc(sizeof(uint32_t) * n); \
+ memcpy(*(dst), src, sizeof(uint32_t) * n); \
+ } while (0)
+
+#define FILTER_ADD_CTX_TO_GRES(gres, idx, ctx) \
+ do { \
+ if ((gres)->colCtxs == NULL) { \
+ (gres)->colCtxs = taosArrayInit(gres->colNum, sizeof(SFilterColCtx)); \
+ } \
+ SFilterColCtx cCtx = {idx, ctx}; \
+ taosArrayPush((gres)->colCtxs, &cCtx); \
+ } while (0)
+
+#define FILTER_ALL_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_ALL)
#define FILTER_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 filterGetCompFuncEx(int32_t lType, int32_t rType, int32_t optr);
diff --git a/source/libs/scalar/inc/sclInt.h b/source/libs/scalar/inc/sclInt.h
index 15e9026ddbc2eea8ad4e066519dd4bbea9767b7e..0a9913e00447b42567d8f3d7ac74a37247d6a942 100644
--- a/source/libs/scalar/inc/sclInt.h
+++ b/source/libs/scalar/inc/sclInt.h
@@ -18,9 +18,9 @@
#ifdef __cplusplus
extern "C" {
#endif
+#include "query.h"
#include "tcommon.h"
#include "thash.h"
-#include "query.h"
typedef struct SOperatorValueType {
int32_t opResType;
@@ -29,46 +29,72 @@ typedef struct SOperatorValueType {
} SOperatorValueType;
typedef struct SScalarCtx {
- int32_t code;
- bool dual;
- SArray *pBlockList; /* element is SSDataBlock* */
- SHashObj *pRes; /* element is SScalarParam */
- void *param; // additional parameter (meta actually) for acquire value such as tbname/tags values
+ int32_t code;
+ bool dual;
+ SArray* pBlockList; /* element is SSDataBlock* */
+ SHashObj* pRes; /* element is SScalarParam */
+ void* param; // additional parameter (meta actually) for acquire value such as tbname/tags values
SOperatorValueType type;
} SScalarCtx;
-
#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_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 *)_node)->node.resType.type))
+//#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*)_node)->node.resType.type))
#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_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 SCL_DOWNGRADE_DATETYPE(_type) \
+ ((_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 sclError(...) qError(__VA_ARGS__)
-#define sclWarn(...) qWarn(__VA_ARGS__)
-#define sclInfo(...) qInfo(__VA_ARGS__)
-#define sclDebug(...) qDebug(__VA_ARGS__)
-#define sclTrace(...) qTrace(__VA_ARGS__)
+#define sclFatal(...) qFatal(__VA_ARGS__)
+#define sclError(...) qError(__VA_ARGS__)
+#define sclWarn(...) qWarn(__VA_ARGS__)
+#define sclInfo(...) qInfo(__VA_ARGS__)
+#define sclDebug(...) qDebug(__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_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)
+#define SCL_ERR_RET(c) \
+ do { \
+ 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 sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows, SScalarParam* pParam);
int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode);
-#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_PRECISON(_c) ((_c)->columnData->info.precision)
+#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_PRECISON(_c) ((_c)->columnData->info.precision)
-void sclFreeParam(SScalarParam *param);
+void sclFreeParam(SScalarParam* param);
#ifdef __cplusplus
}
diff --git a/source/libs/scalar/inc/sclvector.h b/source/libs/scalar/inc/sclvector.h
index a1bf1ce1ef7fa899ccea3b40485925c5b519a97a..1a749c61b3dd369da570cfff367e0e0870cc1714 100644
--- a/source/libs/scalar/inc/sclvector.h
+++ b/source/libs/scalar/inc/sclvector.h
@@ -94,12 +94,12 @@ static FORCE_INLINE _getDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType)
return p;
}
-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 (*_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);
_bin_scalar_fn_t getBinScalarOperatorFn(int32_t binOperator);
#ifdef __cplusplus
}
#endif
-#endif /*_TD_COMMON_BIN_SCALAR_OPERATOR_H_*/
+#endif /*_TD_COMMON_BIN_SCALAR_OPERATOR_H_*/
diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c
index dbb5214415624c4215e2bfe33a7ed5aa3fd74729..132e0ed2141c81d4a3abca587bf0e2668b1e25f8 100644
--- a/source/libs/scalar/src/filter.c
+++ b/source/libs/scalar/src/filter.c
@@ -12,44 +12,44 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
-#include "os.h"
#include
+#include "os.h"
#include "thash.h"
//#include "queryLog.h"
#include "filter.h"
#include "filterInt.h"
+#include "functionMgt.h"
#include "sclInt.h"
#include "tcompare.h"
#include "tdatablock.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);
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);
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);
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);
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;
}
-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;
}
-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;
}
-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;
}
@@ -85,9 +85,8 @@ rangeCompFunc filterGetRangeCompFunc(char sflag, char eflag) {
return filterRangeCompii;
}
-rangeCompFunc gRangeCompare[] = {filterRangeCompee, filterRangeCompei, filterRangeCompie, filterRangeCompii, filterRangeCompGe,
- filterRangeCompGi, filterRangeCompLe, filterRangeCompLi};
-
+rangeCompFunc gRangeCompare[] = {filterRangeCompee, filterRangeCompei, filterRangeCompie, filterRangeCompii,
+ filterRangeCompGe, filterRangeCompGi, filterRangeCompLe, filterRangeCompLi};
int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) {
if (optr2) {
@@ -108,100 +107,91 @@ int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) {
return 3;
} else {
switch (optr) {
- case OP_TYPE_GREATER_THAN:
- return 4;
- case OP_TYPE_GREATER_EQUAL:
- return 5;
- case OP_TYPE_LOWER_THAN:
- return 6;
- case OP_TYPE_LOWER_EQUAL:
- return 7;
- default:
- break;
+ case OP_TYPE_GREATER_THAN:
+ return 4;
+ case OP_TYPE_GREATER_EQUAL:
+ return 5;
+ case OP_TYPE_LOWER_THAN:
+ return 6;
+ case OP_TYPE_LOWER_EQUAL:
+ return 7;
+ default:
+ break;
}
}
return -1;
}
-__compar_fn_t gDataCompare[] = {compareInt32Val, compareInt8Val, compareInt16Val, compareInt64Val, compareFloatVal,
- compareDoubleVal, compareLenPrefixedStr, compareStrPatternMatch, compareChkInString, compareWStrPatternMatch,
- compareLenPrefixedWStr, compareUint8Val, compareUint16Val, compareUint32Val, compareUint64Val,
- setChkInBytes1, setChkInBytes2, setChkInBytes4, setChkInBytes8, compareStrRegexCompMatch,
- compareStrRegexCompNMatch, setChkNotInBytes1, setChkNotInBytes2, setChkNotInBytes4, setChkNotInBytes8,
- compareChkNotInString, compareStrPatternNotMatch, compareWStrPatternNotMatch
-};
-
-__compar_fn_t gInt8SignCompare[] = {
- compareInt8Val, compareInt8Int16, compareInt8Int32, compareInt8Int64, compareInt8Float, compareInt8Double
-};
-__compar_fn_t gInt8UsignCompare[] = {
- compareInt8Uint8, compareInt8Uint16, compareInt8Uint32, compareInt8Uint64
-};
-
-__compar_fn_t gInt16SignCompare[] = {
- compareInt16Int8, compareInt16Val, compareInt16Int32, compareInt16Int64, compareInt16Float, compareInt16Double
-};
-__compar_fn_t gInt16UsignCompare[] = {
- compareInt16Uint8, compareInt16Uint16, compareInt16Uint32, compareInt16Uint64
-};
-
-__compar_fn_t gInt32SignCompare[] = {
- compareInt32Int8, compareInt32Int16, compareInt32Val, compareInt32Int64, compareInt32Float, compareInt32Double
-};
-__compar_fn_t gInt32UsignCompare[] = {
- compareInt32Uint8, compareInt32Uint16, compareInt32Uint32, compareInt32Uint64
-};
-
-__compar_fn_t gInt64SignCompare[] = {
- compareInt64Int8, compareInt64Int16, compareInt64Int32, compareInt64Val, compareInt64Float, compareInt64Double
-};
-__compar_fn_t gInt64UsignCompare[] = {
- compareInt64Uint8, compareInt64Uint16, compareInt64Uint32, compareInt64Uint64
-};
-
-__compar_fn_t gFloatSignCompare[] = {
- compareFloatInt8, compareFloatInt16, compareFloatInt32, compareFloatInt64, compareFloatVal, compareFloatDouble
-};
-__compar_fn_t gFloatUsignCompare[] = {
- compareFloatUint8, compareFloatUint16, compareFloatUint32, compareFloatUint64
-};
-
-__compar_fn_t gDoubleSignCompare[] = {
- compareDoubleInt8, compareDoubleInt16, compareDoubleInt32, compareDoubleInt64, compareDoubleFloat, compareDoubleVal
-};
-__compar_fn_t gDoubleUsignCompare[] = {
- compareDoubleUint8, compareDoubleUint16, compareDoubleUint32, compareDoubleUint64
-};
-
-__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 gUint16UsignCompare[] = {
- compareUint16Uint8, compareUint16Val, compareUint16Uint32, compareUint16Uint64
-};
-
-__compar_fn_t gUint32SignCompare[] = {
- compareUint32Int8, compareUint32Int16, compareUint32Int32, compareUint32Int64, compareUint32Float, compareUint32Double
-};
-__compar_fn_t gUint32UsignCompare[] = {
- compareUint32Uint8, compareUint32Uint16, compareUint32Val, compareUint32Uint64
-};
-
-__compar_fn_t gUint64SignCompare[] = {
- compareUint64Int8, compareUint64Int16, compareUint64Int32, compareUint64Int64, compareUint64Float, compareUint64Double
-};
-__compar_fn_t gUint64UsignCompare[] = {
- compareUint64Uint8, compareUint64Uint16, compareUint64Uint32, compareUint64Val
-};
-
+__compar_fn_t gDataCompare[] = {compareInt32Val,
+ compareInt8Val,
+ compareInt16Val,
+ compareInt64Val,
+ compareFloatVal,
+ compareDoubleVal,
+ compareLenPrefixedStr,
+ compareStrPatternMatch,
+ compareChkInString,
+ compareWStrPatternMatch,
+ compareLenPrefixedWStr,
+ compareUint8Val,
+ compareUint16Val,
+ compareUint32Val,
+ compareUint64Val,
+ setChkInBytes1,
+ setChkInBytes2,
+ setChkInBytes4,
+ setChkInBytes8,
+ compareStrRegexCompMatch,
+ compareStrRegexCompNMatch,
+ setChkNotInBytes1,
+ setChkNotInBytes2,
+ setChkNotInBytes4,
+ setChkNotInBytes8,
+ compareChkNotInString,
+ compareStrPatternNotMatch,
+ compareWStrPatternNotMatch};
+
+__compar_fn_t gInt8SignCompare[] = {compareInt8Val, compareInt8Int16, compareInt8Int32,
+ compareInt8Int64, compareInt8Float, compareInt8Double};
+__compar_fn_t gInt8UsignCompare[] = {compareInt8Uint8, compareInt8Uint16, compareInt8Uint32, compareInt8Uint64};
+
+__compar_fn_t gInt16SignCompare[] = {compareInt16Int8, compareInt16Val, compareInt16Int32,
+ compareInt16Int64, compareInt16Float, compareInt16Double};
+__compar_fn_t gInt16UsignCompare[] = {compareInt16Uint8, compareInt16Uint16, compareInt16Uint32, compareInt16Uint64};
+
+__compar_fn_t gInt32SignCompare[] = {compareInt32Int8, compareInt32Int16, compareInt32Val,
+ compareInt32Int64, compareInt32Float, compareInt32Double};
+__compar_fn_t gInt32UsignCompare[] = {compareInt32Uint8, compareInt32Uint16, compareInt32Uint32, compareInt32Uint64};
+
+__compar_fn_t gInt64SignCompare[] = {compareInt64Int8, compareInt64Int16, compareInt64Int32,
+ compareInt64Val, compareInt64Float, compareInt64Double};
+__compar_fn_t gInt64UsignCompare[] = {compareInt64Uint8, compareInt64Uint16, compareInt64Uint32, compareInt64Uint64};
+
+__compar_fn_t gFloatSignCompare[] = {compareFloatInt8, compareFloatInt16, compareFloatInt32,
+ compareFloatInt64, compareFloatVal, compareFloatDouble};
+__compar_fn_t gFloatUsignCompare[] = {compareFloatUint8, compareFloatUint16, compareFloatUint32, compareFloatUint64};
+
+__compar_fn_t gDoubleSignCompare[] = {compareDoubleInt8, compareDoubleInt16, compareDoubleInt32,
+ compareDoubleInt64, compareDoubleFloat, compareDoubleVal};
+__compar_fn_t gDoubleUsignCompare[] = {compareDoubleUint8, compareDoubleUint16, compareDoubleUint32,
+ compareDoubleUint64};
+
+__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 gUint16UsignCompare[] = {compareUint16Uint8, compareUint16Val, compareUint16Uint32, compareUint16Uint64};
+
+__compar_fn_t gUint32SignCompare[] = {compareUint32Int8, compareUint32Int16, compareUint32Int32,
+ compareUint32Int64, compareUint32Float, compareUint32Double};
+__compar_fn_t gUint32UsignCompare[] = {compareUint32Uint8, compareUint32Uint16, compareUint32Val, compareUint32Uint64};
+
+__compar_fn_t gUint64SignCompare[] = {compareUint64Int8, compareUint64Int16, compareUint64Int32,
+ compareUint64Int64, compareUint64Float, compareUint64Double};
+__compar_fn_t gUint64UsignCompare[] = {compareUint64Uint8, compareUint64Uint16, compareUint64Uint32, compareUint64Val};
int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
int8_t comparFn = 0;
@@ -262,16 +252,27 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
return 28;
}
-
switch (type) {
case TSDB_DATA_TYPE_BOOL:
- case TSDB_DATA_TYPE_TINYINT: comparFn = 1; break;
- case TSDB_DATA_TYPE_SMALLINT: comparFn = 2; break;
- case TSDB_DATA_TYPE_INT: comparFn = 0; break;
+ case TSDB_DATA_TYPE_TINYINT:
+ comparFn = 1;
+ 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_TIMESTAMP: comparFn = 3; break;
- case TSDB_DATA_TYPE_FLOAT: comparFn = 4; break;
- case TSDB_DATA_TYPE_DOUBLE: comparFn = 5; break;
+ case TSDB_DATA_TYPE_TIMESTAMP:
+ comparFn = 3;
+ break;
+ case TSDB_DATA_TYPE_FLOAT:
+ comparFn = 4;
+ break;
+ case TSDB_DATA_TYPE_DOUBLE:
+ comparFn = 5;
+ break;
case TSDB_DATA_TYPE_BINARY: {
if (optr == OP_TYPE_MATCH) {
comparFn = 19;
@@ -311,10 +312,18 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
break;
}
- case TSDB_DATA_TYPE_UTINYINT: comparFn = 11; 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;
+ case TSDB_DATA_TYPE_UTINYINT:
+ comparFn = 11;
+ 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:
comparFn = 0;
@@ -324,9 +333,7 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
return comparFn;
}
-__compar_fn_t filterGetCompFunc(int32_t type, int32_t optr) {
- return gDataCompare[filterGetCompFuncIdx(type, optr)];
-}
+__compar_fn_t filterGetCompFunc(int32_t type, int32_t optr) { return gDataCompare[filterGetCompFuncIdx(type, optr)]; }
__compar_fn_t filterGetCompFuncEx(int32_t lType, int32_t rType, int32_t optr) {
switch (lType) {
@@ -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) {
- 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;
return 0;
@@ -437,7 +444,7 @@ int32_t filterInitUnitsFields(SFilterInfo *info) {
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;
if (ctx->rf) {
@@ -454,8 +461,9 @@ static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRangeCtx *ctx, SFilt
return r;
}
-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) {
+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) {
qError("not supported range type:%d", type);
return NULL;
}
@@ -469,7 +477,6 @@ void* filterInitRangeCtx(int32_t type, int32_t options) {
return ctx;
}
-
int32_t filterResetRangeCtx(SFilterRangeCtx *ctx) {
ctx->status = 0;
@@ -504,7 +511,6 @@ int32_t filterReuseRangeCtx(SFilterRangeCtx *ctx, int32_t type, int32_t options)
return TSDB_CODE_SUCCESS;
}
-
int32_t filterConvertRange(SFilterRangeCtx *cur, SFilterRange *ra, bool *notNull) {
if (!FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) {
int32_t sr = cur->pCompareFunc(&ra->s, getDataMin(cur->type));
@@ -520,7 +526,6 @@ int32_t filterConvertRange(SFilterRangeCtx *cur, SFilterRange *ra, bool *notNull
}
}
-
if (FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL) && FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL)) {
*notNull = true;
} else {
@@ -530,7 +535,7 @@ int32_t filterConvertRange(SFilterRangeCtx *cur, SFilterRange *ra, bool *notNull
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;
if (optr == LOGIC_COND_TYPE_AND) {
@@ -550,15 +555,13 @@ int32_t filterAddRangeOptr(void* h, uint8_t raOptr, int32_t optr, bool *empty, b
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;
if (ctx->rs == NULL) {
- 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_OR))) {
+ 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_OR))) {
APPEND_RANGE(ctx, ctx->rs, ra);
FILTER_SET_FLAG(ctx->status, MR_ST_START);
}
@@ -568,7 +571,7 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) {
SFilterRangeNode *r = ctx->rs;
SFilterRangeNode *rn = NULL;
- int32_t cr = 0;
+ int32_t cr = 0;
if (optr == LOGIC_COND_TYPE_AND) {
while (r != NULL) {
@@ -605,8 +608,7 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) {
return TSDB_CODE_SUCCESS;
}
-
- //TSDB_RELATION_OR
+ // TSDB_RELATION_OR
bool smerged = false;
bool emerged = false;
@@ -625,7 +627,7 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) {
cr = ctx->pCompareFunc(&ra->s, &r->ra.e);
if (FILTER_GREATER(cr, ra->sflag, r->ra.eflag)) {
if (r->next) {
- r= r->next;
+ r = r->next;
continue;
}
@@ -692,23 +694,22 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) {
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;
if (FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) {
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)) {
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);
}
-
int32_t filterAddRangeCtx(void *dst, void *src, int32_t optr) {
SFilterRangeCtx *dctx = (SFilterRangeCtx *)dst;
SFilterRangeCtx *sctx = (SFilterRangeCtx *)src;
@@ -755,9 +756,7 @@ int32_t filterCopyRangeCtx(void *dst, void *src) {
return TSDB_CODE_SUCCESS;
}
-
-
-int32_t filterFinishRange(void* h) {
+int32_t filterFinishRange(void *h) {
SFilterRangeCtx *ctx = (SFilterRangeCtx *)h;
if (FILTER_GET_FLAG(ctx->status, MR_ST_FIN)) {
@@ -789,7 +788,7 @@ int32_t filterFinishRange(void* h) {
return TSDB_CODE_SUCCESS;
}
-int32_t filterGetRangeNum(void* h, int32_t* num) {
+int32_t filterGetRangeNum(void *h, int32_t *num) {
filterFinishRange(h);
SFilterRangeCtx *ctx = (SFilterRangeCtx *)h;
@@ -806,13 +805,12 @@ int32_t filterGetRangeNum(void* h, int32_t* num) {
return TSDB_CODE_SUCCESS;
}
-
-int32_t filterGetRangeRes(void* h, SFilterRange *ra) {
+int32_t filterGetRangeRes(void *h, SFilterRange *ra) {
filterFinishRange(h);
- SFilterRangeCtx *ctx = (SFilterRangeCtx *)h;
- uint32_t num = 0;
- SFilterRangeNode* r = ctx->rs;
+ SFilterRangeCtx *ctx = (SFilterRangeCtx *)h;
+ uint32_t num = 0;
+ SFilterRangeNode *r = ctx->rs;
while (r) {
if (num) {
@@ -834,11 +832,10 @@ int32_t filterGetRangeRes(void* h, SFilterRange *ra) {
return TSDB_CODE_SUCCESS;
}
-
int32_t filterSourceRangeFromCtx(SFilterRangeCtx *ctx, void *sctx, int32_t optr, bool *empty, bool *all) {
SFilterRangeCtx *src = (SFilterRangeCtx *)sctx;
- if (src->isnull){
+ if (src->isnull) {
filterAddRangeOptr(ctx, OP_TYPE_IS_NULL, optr, empty, all);
if (FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) {
*all = true;
@@ -867,14 +864,12 @@ int32_t filterSourceRangeFromCtx(SFilterRangeCtx *ctx, void *sctx, int32_t optr,
return TSDB_CODE_SUCCESS;
}
-
-
-int32_t filterFreeRangeCtx(void* h) {
+int32_t filterFreeRangeCtx(void *h) {
if (h == NULL) {
return TSDB_CODE_SUCCESS;
}
- SFilterRangeCtx *ctx = (SFilterRangeCtx *)h;
+ SFilterRangeCtx *ctx = (SFilterRangeCtx *)h;
SFilterRangeNode *r = ctx->rs;
SFilterRangeNode *rn = NULL;
@@ -896,8 +891,7 @@ int32_t filterFreeRangeCtx(void* h) {
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};
gp.unitNum = gp1->unitNum + gp2->unitNum;
@@ -912,8 +906,7 @@ int32_t filterDetachCnfGroup(SFilterGroup *gp1, SFilterGroup *gp2, SArray* group
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 rightSize = (int32_t)taosArrayGetSize(right);
@@ -950,11 +943,10 @@ int32_t filterDetachCnfGroups(SArray* group, SArray* left, SArray* right) {
}
}
-
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) {
if (nodesEqualNode(fields->fields[i].desc, v)) {
return i;
@@ -964,7 +956,6 @@ int32_t filterGetFiledByDesc(SFilterFields* fields, int32_t type, void *v) {
return -1;
}
-
int32_t filterGetFiledByData(SFilterInfo *info, int32_t type, void *v, int32_t dataLen) {
if (type == FLD_TYPE_VALUE) {
if (info->pctx.valHash == false) {
@@ -981,10 +972,11 @@ int32_t filterGetFiledByData(SFilterInfo *info, int32_t type, void *v, int32_t d
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
-// 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 idx = -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 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 idx = -1;
uint32_t *num;
num = &info->fields[type].num;
@@ -1001,7 +993,8 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type,
idx = *num;
if (idx >= info->fields[type].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;
@@ -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 (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));
@@ -1041,19 +1035,19 @@ static FORCE_INLINE int32_t filterAddColFieldFromField(SFilterInfo *info, SFilte
return TSDB_CODE_SUCCESS;
}
-
int32_t filterAddFieldFromNode(SFilterInfo *info, SNode *node, SFilterFieldId *fid) {
if (node == NULL) {
fltError("empty node");
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);
}
int32_t type;
- void *v;
+ void *v;
if (nodeType(node) == QUERY_NODE_COLUMN) {
type = FLD_TYPE_COLUMN;
@@ -1068,10 +1062,12 @@ int32_t filterAddFieldFromNode(SFilterInfo *info, SNode *node, SFilterFieldId *f
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 (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 {
char v[14] = {0};
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,
if (right2) {
u->right2 = *right2;
}
-
+
if (u->right.type == FLD_TYPE_VALUE) {
SFilterField *val = FILTER_UNIT_RIGHT_FIELD(info, u);
assert(FILTER_GET_FLAG(val->flag, FLD_TYPE_VALUE));
@@ -1132,7 +1128,6 @@ int32_t filterAddUnitImpl(SFilterInfo *info, uint8_t optr, SFilterFieldId *left,
return TSDB_CODE_SUCCESS;
}
-
int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFilterFieldId *right, uint32_t *uidx) {
return filterAddUnitImpl(info, optr, left, right, 0, NULL, uidx);
}
@@ -1148,19 +1143,19 @@ int32_t filterAddUnitToGroup(SFilterGroup *group, uint32_t unitIdx) {
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;
- int32_t ret = TSDB_CODE_SUCCESS;
+ int32_t ret = TSDB_CODE_SUCCESS;
SFilterFieldId left = {0}, right = {0};
filterAddFieldFromNode(info, node->pLeft, &left);
- uint8_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(info, left));
- int32_t len = 0;
+ uint8_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(info, left));
+ int32_t len = 0;
uint32_t uidx = 0;
- int32_t code = 0;
+ int32_t code = 0;
if (node->opType == OP_TYPE_IN && (!IS_VAR_DATA_TYPE(type))) {
SNodeListNode *listNode = (SNodeListNode *)node->pRight;
- SListCell *cell = listNode->pNodeList->pHead;
+ SListCell *cell = listNode->pNodeList->pHead;
SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))};
out.columnData->info.type = type;
@@ -1172,7 +1167,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) {
int32_t overflow = 0;
code = doConvertDataType(valueNode, &out, &overflow);
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);
}
@@ -1183,7 +1178,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) {
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;
} else {
void *data = taosMemoryCalloc(1, tDataTypes[type].bytes);
@@ -1191,7 +1186,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) {
FLT_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
}
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);
@@ -1217,11 +1212,10 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) {
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;
- int32_t type = FILTER_UNIT_DATA_TYPE(u);
- uint16_t flag = 0;
+ int32_t type = FILTER_UNIT_DATA_TYPE(u);
+ uint16_t flag = 0;
filterAddField(dst, FILTER_UNIT_COL_DESC(src, u), NULL, FLD_TYPE_COLUMN, &left, 0, false);
SFilterField *t = FILTER_UNIT_LEFT_FIELD(src, u);
@@ -1229,8 +1223,9 @@ int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u
if (u->right.type == FLD_TYPE_VALUE) {
void *data = FILTER_UNIT_VAL_DATA(src, u);
if (IS_VAR_DATA_TYPE(type)) {
- 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.
+ 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.
t = FILTER_GET_FIELD(dst, right);
FILTER_SET_FLAG(t->flag, FLD_DATA_IS_HASH);
@@ -1259,9 +1254,10 @@ int32_t filterAddUnitRight(SFilterInfo *info, uint8_t optr, SFilterFieldId *righ
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;
- uint32_t uidx = 0;
+ uint32_t uidx = 0;
SFilterField *col = FILTER_GET_COL_FIELD(src, cidx);
@@ -1312,8 +1308,10 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
SIMPLE_COPY_VALUES(data2, &ra->e);
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,
- FILTER_GET_FLAG(ra->eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &right2, &uidx);
+ filterAddUnitImpl(
+ 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);
return TSDB_CODE_SUCCESS;
}
@@ -1323,7 +1321,8 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
void *data = taosMemoryMalloc(sizeof(int64_t));
SIMPLE_COPY_VALUES(data, &ra->s);
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);
}
@@ -1331,7 +1330,8 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
void *data = taosMemoryMalloc(sizeof(int64_t));
SIMPLE_COPY_VALUES(data, &ra->e);
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);
}
@@ -1371,7 +1371,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
while (r) {
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);
if (func(&r->ra.s, &r->ra.e) == 0) {
void *data = taosMemoryMalloc(sizeof(int64_t));
@@ -1387,8 +1387,10 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
SIMPLE_COPY_VALUES(data2, &r->ra.e);
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,
- FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &right2, &uidx);
+ filterAddUnitImpl(
+ 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);
}
@@ -1403,7 +1405,8 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
void *data = taosMemoryMalloc(sizeof(int64_t));
SIMPLE_COPY_VALUES(data, &r->ra.s);
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);
}
@@ -1411,11 +1414,12 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
void *data = taosMemoryMalloc(sizeof(int64_t));
SIMPLE_COPY_VALUES(data, &r->ra.e);
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);
}
- assert (g->unitNum > 0);
+ assert(g->unitNum > 0);
taosArrayPush(res, g);
@@ -1427,24 +1431,22 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan
return TSDB_CODE_SUCCESS;
}
-
static void filterFreeGroup(void *pItem) {
if (pItem == NULL) {
return;
}
- SFilterGroup* p = (SFilterGroup*) pItem;
+ SFilterGroup *p = (SFilterGroup *)pItem;
taosMemoryFreeClear(p->unitIdxs);
taosMemoryFreeClear(p->unitFlags);
}
-
-EDealRes fltTreeToGroup(SNode* pNode, void* pContext) {
- int32_t code = TSDB_CODE_SUCCESS;
- SArray* preGroup = NULL;
- SArray* newGroup = NULL;
- SArray* resGroup = NULL;
- ENodeType nType = nodeType(pNode);
+EDealRes fltTreeToGroup(SNode *pNode, void *pContext) {
+ int32_t code = TSDB_CODE_SUCCESS;
+ SArray *preGroup = NULL;
+ SArray *newGroup = NULL;
+ SArray *resGroup = NULL;
+ ENodeType nType = nodeType(pNode);
SFltBuildGroupCtx *ctx = (SFltBuildGroupCtx *)pContext;
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
break;
case TSDB_DATA_TYPE_BOOL:
- n = sprintf(str, (*(int8_t*)buf) ? "true" : "false");
+ n = sprintf(str, (*(int8_t *)buf) ? "true" : "false");
break;
case TSDB_DATA_TYPE_TINYINT:
- n = sprintf(str, "%d", *(int8_t*)buf);
+ n = sprintf(str, "%d", *(int8_t *)buf);
break;
case TSDB_DATA_TYPE_SMALLINT:
- n = sprintf(str, "%d", *(int16_t*)buf);
+ n = sprintf(str, "%d", *(int16_t *)buf);
break;
case TSDB_DATA_TYPE_INT:
- n = sprintf(str, "%d", *(int32_t*)buf);
+ n = sprintf(str, "%d", *(int32_t *)buf);
break;
case TSDB_DATA_TYPE_BIGINT:
case TSDB_DATA_TYPE_TIMESTAMP:
- n = sprintf(str, "%" PRId64, *(int64_t*)buf);
+ n = sprintf(str, "%" PRId64, *(int64_t *)buf);
break;
case TSDB_DATA_TYPE_FLOAT:
@@ -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_NCHAR:
if (bufSize < 0) {
-// tscError("invalid buf size");
+ // tscError("invalid buf size");
return TSDB_CODE_TSC_INVALID_VALUE;
}
@@ -1569,23 +1571,23 @@ int32_t fltConverToStr(char *str, int type, void *buf, int32_t bufSize, int32_t
break;
case TSDB_DATA_TYPE_UTINYINT:
- n = sprintf(str, "%d", *(uint8_t*)buf);
+ n = sprintf(str, "%d", *(uint8_t *)buf);
break;
case TSDB_DATA_TYPE_USMALLINT:
- n = sprintf(str, "%d", *(uint16_t*)buf);
+ n = sprintf(str, "%d", *(uint16_t *)buf);
break;
case TSDB_DATA_TYPE_UINT:
- n = sprintf(str, "%u", *(uint32_t*)buf);
+ n = sprintf(str, "%u", *(uint32_t *)buf);
break;
case TSDB_DATA_TYPE_UBIGINT:
- n = sprintf(str, "%" PRIu64, *(uint64_t*)buf);
+ n = sprintf(str, "%" PRIu64, *(uint64_t *)buf);
break;
default:
-// tscError("unsupported type:%d", type);
+ // tscError("unsupported type:%d", type);
return TSDB_CODE_TSC_INVALID_VALUE;
}
@@ -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);
for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++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);
}
@@ -1615,39 +1617,41 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
SFilterField *field = &info->fields[FLD_TYPE_VALUE].fields[i];
if (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;
}
SValueNode *var = (SValueNode *)field->desc;
- SDataType *dType = &var->node.resType;
+ SDataType *dType = &var->node.resType;
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 {
- 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) {
- qDebug("VAL%d => [type:NIL][val:NIL]", i); //TODO
+ qDebug("VAL%d => [type:NIL][val:NIL]", i); // TODO
}
}
qDebug("UNIT Num:%u", info->unitNum);
for (uint32_t i = 0; i < info->unitNum; ++i) {
SFilterUnit *unit = &info->units[i];
- int32_t type = FILTER_UNIT_DATA_TYPE(unit);
- int32_t len = 0;
- int32_t tlen = 0;
- char str[512] = {0};
+ int32_t type = FILTER_UNIT_DATA_TYPE(unit);
+ int32_t len = 0;
+ int32_t tlen = 0;
+ char str[512] = {0};
SFilterField *left = FILTER_UNIT_LEFT_FIELD(info, unit);
- SColumnNode *refNode = (SColumnNode *)left->desc;
- 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));
+ SColumnNode *refNode = (SColumnNode *)left->desc;
+ 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));
}
if (unit->right.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != OP_TYPE_IN) {
SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit);
- char *data = right->data;
+ char *data = right->data;
if (IS_VAR_DATA_TYPE(type)) {
tlen = varDataLen(data);
data += VARSTR_HEADER_SIZE;
@@ -1660,13 +1664,14 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
if (unit->compare.optr2) {
strcat(str, " && ");
- 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));
+ 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));
}
if (unit->right2.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != OP_TYPE_IN) {
SFilterField *right = FILTER_UNIT_RIGHT2_FIELD(info, unit);
- char *data = right->data;
+ char *data = right->data;
if (IS_VAR_DATA_TYPE(type)) {
tlen = varDataLen(data);
data += VARSTR_HEADER_SIZE;
@@ -1678,7 +1683,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
strcat(str, "]");
}
- qDebug("%s", str); //TODO
+ qDebug("%s", str); // TODO
}
qDebug("GROUP Num:%u", info->groupNum);
@@ -1700,26 +1705,27 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
qDebug("RANGE Num:%u", info->colRangeNum);
for (uint32_t i = 0; i < info->colRangeNum; ++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) {
SFilterRangeNode *r = ctx->rs;
while (r) {
- char str[256] = {0};
+ char str[256] = {0};
int32_t tlen = 0;
if (FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_NULL)) {
- strcat(str,"(NULL)");
+ strcat(str, "(NULL)");
} 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);
- 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, " - ");
if (FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_NULL)) {
strcat(str, "(NULL)");
} 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);
- 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);
@@ -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)) {
qDebug("Flag:%s", "EMPTY");
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");
}
@@ -1756,36 +1762,35 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
}
void filterFreeColInfo(void *data) {
- SFilterColInfo* info = (SFilterColInfo *)data;
+ SFilterColInfo *info = (SFilterColInfo *)data;
if (info->info == NULL) {
return;
}
if (info->type == RANGE_TYPE_VAR_HASH) {
- //TODO
+ // TODO
} else if (info->type == RANGE_TYPE_MR_CTX) {
filterFreeRangeCtx(info->info);
} else if (info->type == RANGE_TYPE_UNIT) {
taosArrayDestroy((SArray *)info->info);
}
- //NO NEED TO FREE UNIT
+ // NO NEED TO FREE UNIT
info->type = 0;
info->info = NULL;
}
void filterFreeColCtx(void *data) {
- SFilterColCtx* ctx = (SFilterColCtx *)data;
+ SFilterColCtx *ctx = (SFilterColCtx *)data;
if (ctx->ctx) {
filterFreeRangeCtx(ctx->ctx);
}
}
-
-void filterFreeGroupCtx(SFilterGroupCtx* gRes) {
+void filterFreeGroupCtx(SFilterGroupCtx *gRes) {
if (gRes == NULL) {
return;
}
@@ -1807,7 +1812,7 @@ void filterFreeGroupCtx(SFilterGroupCtx* gRes) {
taosMemoryFreeClear(gRes);
}
-void filterFreeField(SFilterField* field, int32_t type) {
+void filterFreeField(SFilterField *field, int32_t type) {
if (field == NULL) {
return;
}
@@ -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);
uint8_t optr = FILTER_UNIT_OPTR(unit);
@@ -1891,24 +1896,23 @@ int32_t filterHandleValueExtInfo(SFilterUnit* unit, char extInfo) {
return TSDB_CODE_SUCCESS;
}
-
int32_t fltInitValFieldData(SFilterInfo *info) {
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) {
assert(unit->compare.optr == FILTER_DUMMY_EMPTY_OPTR || scalarGetOperatorParamNum(unit->compare.optr) == 1);
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));
- uint32_t type = FILTER_UNIT_DATA_TYPE(unit);
- int8_t precision = FILTER_UNIT_DATA_PRECISION(unit);
- SFilterField* fi = right;
+ uint32_t type = FILTER_UNIT_DATA_TYPE(unit);
+ int8_t precision = FILTER_UNIT_DATA_PRECISION(unit);
+ SFilterField *fi = right;
- SValueNode* var = (SValueNode *)fi->desc;
+ SValueNode *var = (SValueNode *)fi->desc;
if (var == NULL) {
assert(fi->data != NULL);
continue;
@@ -1927,27 +1931,29 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
}
SDataType *dType = &var->node.resType;
- size_t bytes = 0;
+ size_t bytes = 0;
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;
fi->data = taosMemoryCalloc(1, bytes);
} 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;
fi->data = taosMemoryCalloc(1, bytes);
} else {
- if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) { //TIME RANGE
-/*
- fi->data = taosMemoryCalloc(dType->bytes, tDataTypes[type].bytes);
- for (int32_t a = 0; a < dType->bytes; ++a) {
- int64_t *v = taosArrayGet(var->arr, a);
- assignVal((char *)fi->data + a * tDataTypes[type].bytes, (char *)v, 0, type);
- }
-*/
+ if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) { // TIME RANGE
+ /*
+ fi->data = taosMemoryCalloc(dType->bytes, tDataTypes[type].bytes);
+ for (int32_t a = 0; a < dType->bytes; ++a) {
+ int64_t *v = taosArrayGet(var->arr, a);
+ assignVal((char *)fi->data + a * tDataTypes[type].bytes, (char *)v, 0, type);
+ }
+ */
continue;
} else {
fi->data = taosMemoryCalloc(1, sizeof(int64_t));
@@ -1979,11 +1985,10 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
}
// match/nmatch for nchar type need convert from ucs4 to mbs
- if(type == TSDB_DATA_TYPE_NCHAR &&
- (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};
- int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(fi->data), varDataLen(fi->data), varDataVal(newValData));
- if (len < 0){
+ if (type == TSDB_DATA_TYPE_NCHAR && (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};
+ int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(fi->data), varDataLen(fi->data), varDataVal(newValData));
+ if (len < 0) {
qError("filterInitValFieldData taosUcs4ToMbs error 1");
return TSDB_CODE_QRY_APP_ERROR;
}
@@ -1995,7 +2000,6 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
return TSDB_CODE_SUCCESS;
}
-
bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right) {
int32_t ret = func(left, right);
@@ -2044,13 +2048,12 @@ bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right)
return true;
}
-
-int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit* u, SFilterRangeCtx *ctx, int32_t optr) {
- int32_t type = FILTER_UNIT_DATA_TYPE(u);
- uint8_t uoptr = FILTER_UNIT_OPTR(u);
- void *val = FILTER_UNIT_VAL_DATA(info, u);
+int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit *u, SFilterRangeCtx *ctx, int32_t optr) {
+ int32_t type = FILTER_UNIT_DATA_TYPE(u);
+ uint8_t uoptr = FILTER_UNIT_OPTR(u);
+ void *val = FILTER_UNIT_VAL_DATA(info, u);
SFilterRange ra = {0};
- int64_t tmp = 0;
+ int64_t tmp = 0;
switch (uoptr) {
case OP_TYPE_GREATER_THAN:
@@ -2125,16 +2128,15 @@ _return:
return TSDB_CODE_SUCCESS;
}
-
-int32_t filterMergeUnits(SFilterInfo *info, SFilterGroupCtx* gRes, uint32_t colIdx, bool *empty) {
- SArray* colArray = (SArray *)gRes->colInfo[colIdx].info;
- int32_t size = (int32_t)taosArrayGetSize(colArray);
- int32_t type = gRes->colInfo[colIdx].dataType;
- SFilterRangeCtx* ctx = filterInitRangeCtx(type, 0);
+int32_t filterMergeUnits(SFilterInfo *info, SFilterGroupCtx *gRes, uint32_t colIdx, bool *empty) {
+ SArray *colArray = (SArray *)gRes->colInfo[colIdx].info;
+ int32_t size = (int32_t)taosArrayGetSize(colArray);
+ int32_t type = gRes->colInfo[colIdx].dataType;
+ SFilterRangeCtx *ctx = filterInitRangeCtx(type, 0);
for (uint32_t i = 0; i < size; ++i) {
- SFilterUnit* u = taosArrayGetP(colArray, i);
- uint8_t optr = FILTER_UNIT_OPTR(u);
+ SFilterUnit *u = taosArrayGetP(colArray, i);
+ uint8_t optr = FILTER_UNIT_OPTR(u);
filterAddRangeOptr(ctx, optr, LOGIC_COND_TYPE_AND, empty, NULL);
FLT_CHK_JMP(*empty);
@@ -2143,7 +2145,7 @@ int32_t filterMergeUnits(SFilterInfo *info, SFilterGroupCtx* gRes, uint32_t colI
filterAddUnitRange(info, u, ctx, LOGIC_COND_TYPE_AND);
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;
SIMPLE_COPY_VALUES(&gRes->colInfo[colIdx].value, FILTER_UNIT_VAL_DATA(info, u));
}
@@ -2164,15 +2166,14 @@ _return:
return TSDB_CODE_SUCCESS;
}
-
-int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t* gResNum) {
- bool empty = false;
+int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t *gResNum) {
+ bool empty = false;
uint32_t *colIdx = taosMemoryMalloc(info->fields[FLD_TYPE_COLUMN].num * sizeof(uint32_t));
- uint32_t colIdxi = 0;
- uint32_t gResIdx = 0;
+ uint32_t colIdxi = 0;
+ uint32_t gResIdx = 0;
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]->colInfo = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(SFilterColInfo));
@@ -2180,8 +2181,8 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t
empty = false;
for (uint32_t j = 0; j < g->unitNum; ++j) {
- SFilterUnit* u = FILTER_GROUP_UNIT(info, g, j);
- uint32_t cidx = FILTER_UNIT_COL_IDX(u);
+ SFilterUnit *u = FILTER_GROUP_UNIT(info, g, j);
+ uint32_t cidx = FILTER_UNIT_COL_IDX(u);
if (gRes[gResIdx]->colInfo[cidx].info == NULL) {
gRes[gResIdx]->colInfo[cidx].info = (SArray *)taosArrayInit(4, POINTER_BYTES);
@@ -2238,33 +2239,33 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t
return TSDB_CODE_SUCCESS;
}
-bool filterIsSameUnits(SFilterColInfo* pCol1, SFilterColInfo* pCol2) {
+bool filterIsSameUnits(SFilterColInfo *pCol1, SFilterColInfo *pCol2) {
if (pCol1->type != pCol2->type) {
return false;
}
if (RANGE_TYPE_MR_CTX == pCol1->type) {
- SFilterRangeCtx* pCtx1 = (SFilterRangeCtx*)pCol1->info;
- SFilterRangeCtx* pCtx2 = (SFilterRangeCtx*)pCol2->info;
+ SFilterRangeCtx *pCtx1 = (SFilterRangeCtx *)pCol1->info;
+ SFilterRangeCtx *pCtx2 = (SFilterRangeCtx *)pCol2->info;
if ((pCtx1->isnull != pCtx2->isnull) || (pCtx1->notnull != pCtx2->notnull) || (pCtx1->isrange != pCtx2->isrange)) {
return false;
}
-
- SFilterRangeNode* pNode1 = pCtx1->rs;
- SFilterRangeNode* pNode2 = pCtx2->rs;
+ SFilterRangeNode *pNode1 = pCtx1->rs;
+ SFilterRangeNode *pNode2 = pCtx2->rs;
while (true) {
if (NULL == pNode1 && NULL == pNode2) {
break;
}
-
+
if (NULL == pNode1 || NULL == pNode2) {
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;
}
@@ -2276,9 +2277,9 @@ bool filterIsSameUnits(SFilterColInfo* pCol1, SFilterColInfo* pCol2) {
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;
- bool equal = false;
+ bool equal = false;
for (; m < gRes1->colNum; ++m) {
idx1 = gRes1->colIdx[m];
@@ -2308,8 +2309,8 @@ void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool
// for long in operation
if (gRes1->colInfo[idx1].optr == OP_TYPE_EQUAL && gRes2->colInfo[idx2].optr == OP_TYPE_EQUAL) {
- SFilterRangeCtx* ctx = gRes1->colInfo[idx1].info;
- if (ctx->pCompareFunc(&gRes1->colInfo[idx1].value, &gRes2->colInfo[idx2].value)){
+ SFilterRangeCtx *ctx = gRes1->colInfo[idx1].info;
+ if (ctx->pCompareFunc(&gRes1->colInfo[idx1].value, &gRes2->colInfo[idx2].value)) {
*conflict = true;
return;
}
@@ -2330,10 +2331,10 @@ void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool
return;
}
-
-int32_t filterMergeTwoGroupsImpl(SFilterInfo *info, SFilterRangeCtx **ctx, int32_t optr, uint32_t cidx, SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool *empty, bool *all) {
+int32_t filterMergeTwoGroupsImpl(SFilterInfo *info, SFilterRangeCtx **ctx, int32_t optr, uint32_t cidx,
+ SFilterGroupCtx *gRes1, SFilterGroupCtx *gRes2, bool *empty, bool *all) {
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) {
*ctx = filterInitRangeCtx(type, 0);
@@ -2350,8 +2351,7 @@ int32_t filterMergeTwoGroupsImpl(SFilterInfo *info, SFilterRangeCtx **ctx, int32
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;
filterCheckColConflict(*gRes1, *gRes2, &conflict);
@@ -2361,13 +2361,13 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter
FILTER_SET_FLAG(info->status, FI_STATUS_REWRITE);
- uint32_t idx1 = 0, idx2 = 0, m = 0, n = 0;
- bool numEqual = (*gRes1)->colNum == (*gRes2)->colNum;
- bool equal = false;
- uint32_t equal1 = 0, equal2 = 0, merNum = 0;
+ uint32_t idx1 = 0, idx2 = 0, m = 0, n = 0;
+ bool numEqual = (*gRes1)->colNum == (*gRes2)->colNum;
+ bool equal = false;
+ uint32_t equal1 = 0, equal2 = 0, merNum = 0;
SFilterRangeCtx *ctx = NULL;
- SFilterColCtx colCtx = {0};
- SArray* colCtxs = taosArrayInit((*gRes2)->colNum, sizeof(SFilterColCtx));
+ SFilterColCtx colCtx = {0};
+ SArray *colCtxs = taosArrayInit((*gRes2)->colNum, sizeof(SFilterColCtx));
for (; m < (*gRes1)->colNum; ++m) {
idx1 = (*gRes1)->colIdx[m];
@@ -2432,14 +2432,14 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter
assert(merNum > 0);
SFilterColInfo *colInfo = NULL;
- assert (merNum == equal1 || merNum == equal2);
+ assert(merNum == equal1 || merNum == equal2);
filterFreeGroupCtx(*gRes2);
*gRes2 = NULL;
assert(colCtxs && taosArrayGetSize(colCtxs) > 0);
- int32_t ctxSize = (int32_t)taosArrayGetSize(colCtxs);
+ int32_t ctxSize = (int32_t)taosArrayGetSize(colCtxs);
SFilterColCtx *pctx = NULL;
for (int32_t i = 0; i < ctxSize; ++i) {
@@ -2469,18 +2469,17 @@ _return:
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) {
return TSDB_CODE_SUCCESS;
}
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;
- int32_t movedNum = 0;
- bool all = false;
+ int32_t movedNum = 0;
+ bool all = false;
cColNum = gRes[0]->colNum;
@@ -2502,7 +2501,7 @@ int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gR
if (gRes[n] == NULL) {
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;
@@ -2523,7 +2522,7 @@ int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gR
if (gRes[n] == NULL) {
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;
@@ -2556,7 +2555,7 @@ _return:
return TSDB_CODE_SUCCESS;
}
-int32_t filterConvertGroupFromArray(SFilterInfo *info, SArray* group) {
+int32_t filterConvertGroupFromArray(SFilterInfo *info, SArray *group) {
size_t groupSize = taosArrayGetSize(group);
info->groupNum = (uint32_t)groupSize;
@@ -2574,7 +2573,7 @@ int32_t filterConvertGroupFromArray(SFilterInfo *info, SArray* group) {
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)) {
qDebug("no need rewrite");
return TSDB_CODE_SUCCESS;
@@ -2584,11 +2583,11 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum
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;
- SFilterColInfo *colInfo = NULL;
- int32_t optr = 0;
- uint32_t uidx = 0;
+ SFilterColInfo *colInfo = NULL;
+ int32_t optr = 0;
+ uint32_t uidx = 0;
memset(info, 0, sizeof(*info));
@@ -2615,7 +2614,7 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum
int32_t usize = (int32_t)taosArrayGetSize((SArray *)colInfo->info);
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);
filterAddUnitToGroup(&ng, uidx);
@@ -2643,15 +2642,15 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum
return TSDB_CODE_SUCCESS;
}
-int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum) {
- uint32_t *idxs = NULL;
- uint32_t colNum = 0;
+int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t gResNum) {
+ uint32_t *idxs = NULL;
+ uint32_t colNum = 0;
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 (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)) {
continue;
}
@@ -2691,10 +2690,10 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_
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) {
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);
}
@@ -2732,7 +2731,7 @@ _return:
int32_t filterPostProcessRange(SFilterInfo *info) {
for (uint32_t i = 0; i < info->colRangeNum; ++i) {
- SFilterRangeCtx* ctx = info->colRange[i];
+ SFilterRangeCtx *ctx = info->colRange[i];
SFilterRangeNode *r = ctx->rs;
while (r) {
r->rc.func = filterGetRangeCompFunc(r->ra.sflag, r->ra.eflag);
@@ -2743,7 +2742,6 @@ int32_t filterPostProcessRange(SFilterInfo *info) {
return TSDB_CODE_SUCCESS;
}
-
int32_t filterGenerateComInfo(SFilterInfo *info) {
info->cunits = taosMemoryMalloc(info->unitNum * sizeof(*info->cunits));
info->blkUnitRes = taosMemoryMalloc(sizeof(*info->blkUnitRes) * info->unitNum);
@@ -2787,21 +2785,20 @@ int32_t filterUpdateComUnits(SFilterInfo *info) {
return TSDB_CODE_SUCCESS;
}
-
int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t numOfCols, int32_t numOfRows) {
int32_t rmUnit = 0;
memset(info->blkUnitRes, 0, sizeof(*info->blkUnitRes) * info->unitNum);
for (uint32_t k = 0; k < info->unitNum; ++k) {
- int32_t index = -1;
+ int32_t index = -1;
SFilterComUnit *cunit = &info->cunits[k];
if (FILTER_NO_MERGE_DATA_TYPE(cunit->dataType)) {
continue;
}
- for(int32_t i = 0; i < numOfCols; ++i) {
+ for (int32_t i = 0; i < numOfCols; ++i) {
if (pDataStatis[i].colId == cunit->colId) {
index = i;
break;
@@ -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
- || cunit->optr == OP_TYPE_IN || cunit->optr == OP_TYPE_LIKE || cunit->optr == OP_TYPE_MATCH
- || cunit->optr == OP_TYPE_NOT_EQUAL) {
+ if (cunit->optr == OP_TYPE_IS_NULL || cunit->optr == OP_TYPE_IS_NOT_NULL || cunit->optr == OP_TYPE_IN ||
+ cunit->optr == OP_TYPE_LIKE || cunit->optr == OP_TYPE_MATCH || cunit->optr == OP_TYPE_NOT_EQUAL) {
continue;
}
- SColumnDataAgg* pDataBlockst = &pDataStatis[index];
- void *minVal, *maxVal;
- float minv = 0;
- float maxv = 0;
+ SColumnDataAgg *pDataBlockst = &pDataStatis[index];
+ void *minVal, *maxVal;
+ float minv = 0;
+ float maxv = 0;
if (cunit->dataType == TSDB_DATA_TYPE_FLOAT) {
minv = (float)(*(double *)(&pDataBlockst->min));
@@ -2863,8 +2859,10 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3
bool minRes = false, maxRes = false;
if (cunit->rfunc >= 0) {
- minRes = (*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]);
+ minRes =
+ (*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) {
info->blkUnitRes[k] = 1;
@@ -2903,7 +2901,6 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3
rmUnit = 1;
}
}
-
}
if (rmUnit == 0) {
@@ -2915,7 +2912,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3
uint32_t *unitNum = info->blkUnits;
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) {
SFilterGroup *group = &info->groups[g];
@@ -2925,7 +2922,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3
empty = 0;
// save group idx start pointer
- uint32_t * pGroupIdx = unitIdx;
+ uint32_t *pGroupIdx = unitIdx;
for (uint32_t u = 0; u < group->unitNum; ++u) {
uint32_t uidx = group->unitIdxs[u];
if (info->blkUnitRes[uidx] == 1) {
@@ -2976,15 +2973,16 @@ _return:
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;
- bool all = true;
- uint32_t *unitIdx = NULL;
+ bool all = true;
+ 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) {
- //FILTER_UNIT_CLR_F(info);
+ // FILTER_UNIT_CLR_F(info);
unitIdx = info->blkUnits;
@@ -2992,30 +2990,31 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, SColumnInfoD
uint32_t unitNum = *(unitIdx++);
for (uint32_t u = 0; u < unitNum; ++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)) {
- // p[i] = FILTER_UNIT_GET_R(info, uidx);
- //} else {
- uint8_t optr = cunit->optr;
+ // if (FILTER_UNIT_GET_F(info, uidx)) {
+ // p[i] = FILTER_UNIT_GET_R(info, uidx);
+ // } else {
+ uint8_t optr = cunit->optr;
- if (colDataIsNull((SColumnInfoData *)(cunit->colData), 0, i, NULL)) {
- p[i] = (optr == OP_TYPE_IS_NULL) ? true : false;
+ if (colDataIsNull((SColumnInfoData *)(cunit->colData), 0, i, NULL)) {
+ 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 {
- 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 {
- 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);
+ 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);
+ }
+
if (p[i] == 0) {
break;
}
@@ -3036,9 +3035,8 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, SColumnInfoD
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) {
info->blkFlag = 0;
@@ -3067,20 +3065,22 @@ _return:
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;
}
-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;
}
static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes,
SColumnDataAgg *statis, int16_t numOfCols, int32_t *numOfQualified) {
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) {
return all;
@@ -3088,7 +3088,7 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows,
for (int32_t i = 0; i < numOfRows; ++i) {
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));
if (p[i] == 0) {
@@ -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,
SColumnDataAgg *statis, int16_t numOfCols, int32_t *numOfQualified) {
SFilterInfo *info = (SFilterInfo *)pinfo;
- bool all = true;
+ bool all = true;
if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) {
return all;
}
- int8_t* p = (int8_t*)pRes->pData;
+ int8_t *p = (int8_t *)pRes->pData;
for (int32_t i = 0; i < numOfRows; ++i) {
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));
if (p[i] == 0) {
@@ -3127,23 +3127,24 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows
return all;
}
-bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, SColumnInfoData* pRes, SColumnDataAgg *statis, int16_t numOfCols, int32_t* numOfQualified) {
- SFilterInfo *info = (SFilterInfo *)pinfo;
- bool all = true;
- uint16_t dataSize = info->cunits[0].dataSize;
+bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SColumnDataAgg *statis,
+ int16_t numOfCols, int32_t *numOfQualified) {
+ SFilterInfo *info = (SFilterInfo *)pinfo;
+ bool all = true;
+ uint16_t dataSize = info->cunits[0].dataSize;
rangeCompFunc rfunc = gRangeCompare[info->cunits[0].rfunc];
- void *valData = info->cunits[0].valData;
- void *valData2 = info->cunits[0].valData2;
+ void *valData = info->cunits[0].valData;
+ void *valData2 = info->cunits[0].valData2;
__compar_fn_t func = gDataCompare[info->cunits[0].func];
if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) {
return all;
}
- int8_t* p = (int8_t*) pRes->pData;
+ int8_t *p = (int8_t *)pRes->pData;
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);
if (colData == NULL || colDataIsNull_s(pData, i)) {
@@ -3166,17 +3167,17 @@ bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, SColumnInfoData* pRe
bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SColumnDataAgg *statis,
int16_t numOfCols, int32_t *numOfQualified) {
SFilterInfo *info = (SFilterInfo *)pinfo;
- bool all = true;
+ bool all = true;
if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) {
return all;
}
- int8_t* p = (int8_t*) pRes->pData;
+ int8_t *p = (int8_t *)pRes->pData;
for (int32_t i = 0; i < numOfRows; ++i) {
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)) {
p[i] = 0;
all = false;
@@ -3184,18 +3185,21 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes
}
// 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)){
- char *newColData = taosMemoryCalloc(info->cunits[uidx].dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1);
- int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(colData), varDataLen(colData), varDataVal(newColData));
- if (len < 0){
+ if (info->cunits[uidx].dataType == TSDB_DATA_TYPE_NCHAR &&
+ (info->cunits[uidx].optr == OP_TYPE_MATCH || info->cunits[uidx].optr == OP_TYPE_NMATCH)) {
+ char *newColData = taosMemoryCalloc(info->cunits[uidx].dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1);
+ int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(colData), varDataLen(colData), varDataVal(newColData));
+ if (len < 0) {
qError("castConvert1 taosUcs4ToMbs error");
- }else{
+ } else {
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);
- }else{
- p[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, colData, info->cunits[uidx].valData);
+ } else {
+ p[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, colData,
+ info->cunits[uidx].valData);
}
if (p[i] == 0) {
@@ -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,
int32_t *numOfQualified) {
SFilterInfo *info = (SFilterInfo *)pinfo;
- bool all = true;
+ bool all = true;
if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) {
return all;
}
- int8_t* p = (int8_t*) pRes->pData;
+ int8_t *p = (int8_t *)pRes->pData;
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) {
SFilterGroup *group = &info->groups[g];
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];
- void *colData = colDataGetData((SColumnInfoData *)(cunit->colData), i);
+ void *colData = colDataGetData((SColumnInfoData *)(cunit->colData), i);
- //if (FILTER_UNIT_GET_F(info, uidx)) {
- // p[i] = FILTER_UNIT_GET_R(info, uidx);
- //} else {
- uint8_t optr = cunit->optr;
+ // if (FILTER_UNIT_GET_F(info, uidx)) {
+ // p[i] = FILTER_UNIT_GET_R(info, uidx);
+ // } else {
+ uint8_t optr = cunit->optr;
- if (colData == NULL || colDataIsNull((SColumnInfoData *)(cunit->colData), 0, i, NULL)) {
- p[i] = optr == OP_TYPE_IS_NULL ? true : false;
+ if (colData == NULL || colDataIsNull((SColumnInfoData *)(cunit->colData), 0, i, NULL)) {
+ 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 {
- 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 {
- if(cunit->dataType == TSDB_DATA_TYPE_NCHAR && (cunit->optr == OP_TYPE_MATCH || cunit->optr == OP_TYPE_NMATCH)){
- char *newColData = taosMemoryCalloc(cunit->dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1);
- 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);
+ if (cunit->dataType == TSDB_DATA_TYPE_NCHAR &&
+ (cunit->optr == OP_TYPE_MATCH || cunit->optr == OP_TYPE_NMATCH)) {
+ char *newColData = taosMemoryCalloc(cunit->dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1);
+ 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);
}
-
- //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) {
break;
}
@@ -3318,11 +3324,9 @@ int32_t filterSetExecFunc(SFilterInfo *info) {
return TSDB_CODE_SUCCESS;
}
-
-
int32_t filterPreprocess(SFilterInfo *info) {
- SFilterGroupCtx** gRes = taosMemoryCalloc(info->groupNum, sizeof(SFilterGroupCtx *));
- int32_t gResNum = 0;
+ SFilterGroupCtx **gRes = taosMemoryCalloc(info->groupNum, sizeof(SFilterGroupCtx *));
+ int32_t gResNum = 0;
filterMergeGroupUnits(info, gRes, &gResNum);
@@ -3333,7 +3337,6 @@ int32_t filterPreprocess(SFilterInfo *info) {
goto _return;
}
-
if (FILTER_GET_FLAG(info->status, FI_STATUS_EMPTY)) {
fltInfo("Final - FilterInfo: [EMPTY]");
goto _return;
@@ -3362,14 +3365,13 @@ _return:
return TSDB_CODE_SUCCESS;
}
-
int32_t fltSetColFieldDataImpl(SFilterInfo *info, void *param, filer_get_col_from_id fp, bool fromColId) {
if (FILTER_ALL_RES(info) || FILTER_EMPTY_RES(info)) {
return TSDB_CODE_SUCCESS;
}
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) {
(*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
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;
- SArray* group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup));
+ SArray *group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup));
filterInitUnitsFields(info);
@@ -3436,13 +3437,13 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t
return true;
}
- bool ret = true;
+ bool ret = true;
void *minVal, *maxVal;
for (uint32_t k = 0; k < info->colRangeNum; ++k) {
- int32_t index = -1;
+ int32_t index = -1;
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) {
index = i;
break;
@@ -3479,11 +3480,11 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t
}
}
- SColumnDataAgg* pDataBlockst = pDataStatis[index];
+ SColumnDataAgg *pDataBlockst = pDataStatis[index];
SFilterRangeNode *r = ctx->rs;
- float minv = 0;
- float maxv = 0;
+ float minv = 0;
+ float maxv = 0;
if (ctx->type == TSDB_DATA_TYPE_FLOAT) {
minv = (float)(*(double *)(&pDataBlockst->min));
@@ -3512,17 +3513,15 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t
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 *tmpc = filterInitRangeCtx(TSDB_DATA_TYPE_TIMESTAMP, FLT_OPTION_TIMESTAMP);
SFilterRangeCtx *cur = NULL;
- int32_t num = 0;
- int32_t optr = 0;
- int32_t code = 0;
- bool empty = false, all = false;
+ int32_t num = 0;
+ int32_t optr = 0;
+ int32_t code = 0;
+ bool empty = false, all = false;
for (uint32_t i = 0; i < info->groupNum; ++i) {
SFilterGroup *group = &info->groups[i];
@@ -3535,7 +3534,7 @@ int32_t filterGetTimeRangeImpl(SFilterInfo *info, STimeWindow *win, bool *
}
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];
uint8_t raOptr = FILTER_UNIT_OPTR(unit);
@@ -3591,7 +3590,7 @@ int32_t filterGetTimeRangeImpl(SFilterInfo *info, STimeWindow *win, bool *
filterFreeRangeCtx(prev);
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:
@@ -3601,19 +3600,18 @@ _return:
filterFreeRangeCtx(prev);
filterFreeRangeCtx(tmpc);
- qDebug("qFilter time range:[%"PRId64 "]-[%"PRId64 "]", win->skey, win->ekey);
+ qDebug("qFilter time range:[%" PRId64 "]-[%" PRId64 "]", win->skey, win->ekey);
return code;
}
-
int32_t filterGetTimeRange(SNode *pNode, STimeWindow *win, bool *isStrict) {
SFilterInfo *info = NULL;
- int32_t code = 0;
+ int32_t code = 0;
*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) {
*win = TSWINDOW_INITIALIZER;
@@ -3630,15 +3628,14 @@ _return:
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)) {
return TSDB_CODE_SUCCESS;
}
for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) {
- SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i];
- int32_t type = FILTER_GET_COL_FIELD_TYPE(fi);
+ SFilterField *fi = &info->fields[FLD_TYPE_COLUMN].fields[i];
+ int32_t type = FILTER_GET_COL_FIELD_TYPE(fi);
if (type == TSDB_DATA_TYPE_NCHAR) {
SFilterField nfi = {0};
nfi.desc = fi->desc;
@@ -3646,20 +3643,21 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar
nfi.data = taosMemoryMalloc(rows * bytes);
int32_t bufSize = bytes - VARSTR_HEADER_SIZE;
for (int32_t j = 0; j < rows; ++j) {
- char *src = FILTER_GET_COL_FIELD_DATA(fi, j);
- char *dst = FILTER_GET_COL_FIELD_DATA(&nfi, j);
+ char *src = FILTER_GET_COL_FIELD_DATA(fi, j);
+ char *dst = FILTER_GET_COL_FIELD_DATA(&nfi, j);
int32_t len = 0;
- char *varSrc = varDataVal(src);
- size_t k = 0, varSrcLen = varDataLen(src);
- while (k < varSrcLen && varSrc[k++] == -1) {}
+ char *varSrc = varDataVal(src);
+ size_t k = 0, varSrcLen = varDataLen(src);
+ while (k < varSrcLen && varSrc[k++] == -1) {
+ }
if (k == varSrcLen) {
/* NULL */
- varDataLen(dst) = (VarDataLenT) varSrcLen;
+ varDataLen(dst) = (VarDataLenT)varSrcLen;
varDataCopy(dst, src);
continue;
}
- bool ret = taosMbsToUcs4(varDataVal(src), varDataLen(src), (TdUcs4*)varDataVal(dst), bufSize, &len);
- if(!ret) {
+ bool ret = taosMbsToUcs4(varDataVal(src), varDataLen(src), (TdUcs4 *)varDataVal(dst), bufSize, &len);
+ if (!ret) {
qError("filterConverNcharColumns taosMbsToUcs4 error");
return TSDB_CODE_FAILED;
}
@@ -3679,10 +3677,10 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar
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) {
- SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i];
- int32_t type = FILTER_GET_COL_FIELD_TYPE(fi);
+ SFilterField *fi = &info->fields[FLD_TYPE_COLUMN].fields[i];
+ int32_t type = FILTER_GET_COL_FIELD_TYPE(fi);
if (type == TSDB_DATA_TYPE_NCHAR) {
taosMemoryFreeClear(fi->data);
}
@@ -3691,7 +3689,7 @@ int32_t filterFreeNcharColumns(SFilterInfo* info) {
return TSDB_CODE_SUCCESS;
}
-int32_t fltAddValueNodeToConverList(SFltTreeStat *stat, SValueNode* pNode) {
+int32_t fltAddValueNodeToConverList(SFltTreeStat *stat, SValueNode *pNode) {
if (NULL == stat->nodeList) {
stat->nodeList = taosArrayInit(10, POINTER_BYTES);
if (NULL == stat->nodeList) {
@@ -3706,12 +3704,12 @@ int32_t fltAddValueNodeToConverList(SFltTreeStat *stat, SValueNode* pNode) {
return TSDB_CODE_SUCCESS;
}
-EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
+EDealRes fltReviseRewriter(SNode **pNode, void *pContext) {
SFltTreeStat *stat = (SFltTreeStat *)pContext;
if (QUERY_NODE_LOGIC_CONDITION == nodeType(*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) {
if (NULL == cell || NULL == cell->pNode) {
fltError("invalid cell, cell:%p, pNode:%p", cell, cell->pNode);
@@ -3777,8 +3775,8 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
}
SValueNode *valueNode = (SValueNode *)listNode->pNodeList->pHead->pNode;
- uint8_t type = valueNode->node.resType.type;
- SNode *node = NULL;
+ uint8_t type = valueNode->node.resType.type;
+ SNode *node = NULL;
FOREACH(node, listNode->pNodeList) {
if (type != ((SValueNode *)node)->node.resType.type) {
stat->scalarMode = true;
@@ -3801,13 +3799,14 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
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;
return DEAL_RES_CONTINUE;
}
- if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) &&
- (node->opType >= OP_TYPE_NOT_EQUAL) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL)) {
+ if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) && (node->opType >= OP_TYPE_NOT_EQUAL) &&
+ (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL)) {
stat->scalarMode = true;
return DEAL_RES_CONTINUE;
}
@@ -3824,8 +3823,9 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
return DEAL_RES_CONTINUE;
}
- 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) {
+ 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) {
stat->scalarMode = true;
return DEAL_RES_CONTINUE;
}
@@ -3835,7 +3835,8 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
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;
return DEAL_RES_CONTINUE;
}
@@ -3880,9 +3881,9 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
if (OP_TYPE_IN != node->opType) {
SColumnNode *refNode = (SColumnNode *)node->pLeft;
- SValueNode *valueNode = (SValueNode *)node->pRight;
- if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP)
- && TSDB_DATA_TYPE_UBIGINT == valueNode->node.resType.type && valueNode->datum.u <= INT64_MAX) {
+ SValueNode *valueNode = (SValueNode *)node->pRight;
+ if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) &&
+ TSDB_DATA_TYPE_UBIGINT == valueNode->node.resType.type && valueNode->datum.u <= INT64_MAX) {
valueNode->node.resType.type = TSDB_DATA_TYPE_BIGINT;
}
int32_t type = vectorGetConvertType(refNode->node.resType.type, valueNode->node.resType.type);
@@ -3891,9 +3892,9 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
return DEAL_RES_CONTINUE;
}
} else {
- SColumnNode *refNode = (SColumnNode *)node->pLeft;
+ SColumnNode *refNode = (SColumnNode *)node->pLeft;
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) {
stat->scalarMode = true;
return DEAL_RES_CONTINUE;
@@ -3911,7 +3912,7 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
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;
nodesRewriteExprPostOrder(pNode, fltReviseRewriter, (void *)pStat);
@@ -3930,18 +3931,17 @@ _return:
FLT_RET(code);
}
-int32_t fltOptimizeNodes(SFilterInfo *pInfo, SNode** pNode, SFltTreeStat *pStat) {
- //TODO
+int32_t fltOptimizeNodes(SFilterInfo *pInfo, SNode **pNode, SFltTreeStat *pStat) {
+ // TODO
return TSDB_CODE_SUCCESS;
}
-
int32_t fltGetDataFromColId(void *param, int32_t id, void **data) {
int32_t numOfCols = ((SFilterColumnParam *)param)->numOfCols;
- SArray* pDataBlock = ((SFilterColumnParam *)param)->pDataBlock;
+ SArray *pDataBlock = ((SFilterColumnParam *)param)->pDataBlock;
for (int32_t j = 0; j < numOfCols; ++j) {
- SColumnInfoData* pColInfo = taosArrayGet(pDataBlock, j);
+ SColumnInfoData *pColInfo = taosArrayGet(pDataBlock, j);
if (id == pColInfo->info.colId) {
*data = pColInfo;
break;
@@ -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 numOfCols = ((SFilterColumnParam *)param)->numOfCols;
- SArray* pDataBlock = ((SFilterColumnParam *)param)->pDataBlock;
+ SArray *pDataBlock = ((SFilterColumnParam *)param)->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;
}
- SColumnInfoData* pColInfo = taosArrayGet(pDataBlock, id);
+ SColumnInfoData *pColInfo = taosArrayGet(pDataBlock, id);
*data = pColInfo;
return TSDB_CODE_SUCCESS;
}
-
-
int32_t filterSetDataFromSlotId(SFilterInfo *info, void *param) {
if (NULL == info) {
return TSDB_CODE_QRY_INVALID_INPUT;
@@ -3979,10 +3978,8 @@ int32_t filterSetDataFromColId(SFilterInfo *info, void *param) {
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;
if (pNode == NULL || pInfo == NULL) {
@@ -4028,14 +4025,15 @@ _return:
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) {
*pResultStatus = FILTER_RESULT_ALL_QUALIFIED;
return false;
}
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);
if (code != TSDB_CODE_SUCCESS) {
@@ -4067,8 +4065,8 @@ bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, SColumnInfoData** p, SC
// todo this should be return during filter procedure
int32_t num = 0;
- for(int32_t i = 0; i < output.numOfRows; ++i) {
- if (((int8_t*)((*p)->pData))[i] == 1) {
+ for (int32_t i = 0; i < output.numOfRows; ++i) {
+ if (((int8_t *)((*p)->pData))[i] == 1) {
++num;
}
}
@@ -4092,10 +4090,10 @@ typedef struct SClassifyConditionCxt {
bool hasOtherCol;
} SClassifyConditionCxt;
-static EDealRes classifyConditionImpl(SNode* pNode, void* pContext) {
- SClassifyConditionCxt* pCxt = (SClassifyConditionCxt*)pContext;
+static EDealRes classifyConditionImpl(SNode *pNode, void *pContext) {
+ SClassifyConditionCxt *pCxt = (SClassifyConditionCxt *)pContext;
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) {
pCxt->hasPrimaryKey = true;
} else if (pCol->hasIndex) {
@@ -4107,9 +4105,9 @@ static EDealRes classifyConditionImpl(SNode* pNode, void* pContext) {
pCxt->hasOtherCol = true;
}
} else if (QUERY_NODE_FUNCTION == nodeType(pNode)) {
- SFunctionNode* pFunc = (SFunctionNode*)pNode;
+ SFunctionNode *pFunc = (SFunctionNode *)pNode;
if (fmIsPseudoColumnFunc(pFunc->funcId)) {
- if (FUNCTION_TYPE_TBNAME==pFunc->funcType) {
+ if (FUNCTION_TYPE_TBNAME == pFunc->funcType) {
pCxt->hasTagCol = true;
} else {
pCxt->hasOtherCol = true;
@@ -4126,7 +4124,7 @@ typedef enum EConditionType {
COND_TYPE_NORMAL
} EConditionType;
-static EConditionType classifyCondition(SNode* pNode) {
+static EConditionType classifyCondition(SNode *pNode) {
SClassifyConditionCxt cxt = {.hasPrimaryKey = false, .hasTagIndexCol = false, .hasOtherCol = false};
nodesWalkExpr(pNode, classifyConditionImpl, &cxt);
return cxt.hasOtherCol ? COND_TYPE_NORMAL
@@ -4136,16 +4134,16 @@ static EConditionType classifyCondition(SNode* pNode) {
: (cxt.hasTagIndexCol ? COND_TYPE_TAG_INDEX : COND_TYPE_TAG)));
}
-static bool isCondColumnsFromMultiTable(SNode* pCond) {
- SNodeList* pCondCols = nodesMakeList();
- int32_t code = nodesCollectColumnsFromNode(pCond, NULL, COLLECT_COL_TYPE_ALL, &pCondCols);
+static bool isCondColumnsFromMultiTable(SNode *pCond) {
+ SNodeList *pCondCols = nodesMakeList();
+ int32_t code = nodesCollectColumnsFromNode(pCond, NULL, COLLECT_COL_TYPE_ALL, &pCondCols);
if (code == TSDB_CODE_SUCCESS) {
if (LIST_LENGTH(pCondCols) >= 2) {
- SColumnNode* pFirstCol = (SColumnNode*)nodesListGetNode(pCondCols, 0);
- SNode* pColNode = NULL;
+ SColumnNode *pFirstCol = (SColumnNode *)nodesListGetNode(pCondCols, 0);
+ SNode *pColNode = NULL;
FOREACH(pColNode, pCondCols) {
- if (strcmp(((SColumnNode*)pColNode)->dbName, pFirstCol->dbName) != 0 ||
- strcmp(((SColumnNode*)pColNode)->tableAlias, pFirstCol->tableAlias) != 0) {
+ if (strcmp(((SColumnNode *)pColNode)->dbName, pFirstCol->dbName) != 0 ||
+ strcmp(((SColumnNode *)pColNode)->tableAlias, pFirstCol->tableAlias) != 0) {
nodesDestroyList(pCondCols);
return true;
}
@@ -4156,17 +4154,17 @@ static bool isCondColumnsFromMultiTable(SNode* pCond) {
return false;
}
-static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, SNode** pTagIndexCond, SNode** pTagCond,
- SNode** pOtherCond) {
- SLogicConditionNode* pLogicCond = (SLogicConditionNode*)(*pCondition);
+static int32_t partitionLogicCond(SNode **pCondition, SNode **pPrimaryKeyCond, SNode **pTagIndexCond, SNode **pTagCond,
+ SNode **pOtherCond) {
+ SLogicConditionNode *pLogicCond = (SLogicConditionNode *)(*pCondition);
int32_t code = TSDB_CODE_SUCCESS;
- SNodeList* pPrimaryKeyConds = NULL;
- SNodeList* pTagIndexConds = NULL;
- SNodeList* pTagConds = NULL;
- SNodeList* pOtherConds = NULL;
- SNode* pCond = NULL;
+ SNodeList *pPrimaryKeyConds = NULL;
+ SNodeList *pTagIndexConds = NULL;
+ SNodeList *pTagConds = NULL;
+ SNodeList *pOtherConds = NULL;
+ SNode *pCond = NULL;
FOREACH(pCond, pLogicCond->pParameterList) {
if (isCondColumnsFromMultiTable(pCond)) {
if (NULL != pOtherCond) {
@@ -4205,10 +4203,10 @@ static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, S
}
}
- SNode* pTempPrimaryKeyCond = NULL;
- SNode* pTempTagIndexCond = NULL;
- SNode* pTempTagCond = NULL;
- SNode* pTempOtherCond = NULL;
+ SNode *pTempPrimaryKeyCond = NULL;
+ SNode *pTempTagIndexCond = NULL;
+ SNode *pTempTagCond = NULL;
+ SNode *pTempOtherCond = NULL;
if (TSDB_CODE_SUCCESS == code) {
code = nodesMergeConds(&pTempPrimaryKeyCond, &pPrimaryKeyConds);
}
@@ -4251,10 +4249,10 @@ static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, S
return code;
}
-int32_t filterPartitionCond(SNode** pCondition, SNode** pPrimaryKeyCond, SNode** pTagIndexCond, SNode** pTagCond,
- SNode** pOtherCond) {
+int32_t filterPartitionCond(SNode **pCondition, SNode **pPrimaryKeyCond, SNode **pTagIndexCond, SNode **pTagCond,
+ SNode **pOtherCond) {
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);
}
diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c
index b4b99be6362c31ac752df190920f55b22a6aec32..da7e2860364c03dcabcb97bc422f64091d996309 100644
--- a/source/libs/scalar/src/scalar.c
+++ b/source/libs/scalar/src/scalar.c
@@ -1,3 +1,4 @@
+#include "scalar.h"
#include "function.h"
#include "functionMgt.h"
#include "nodes.h"
@@ -5,25 +6,25 @@
#include "sclInt.h"
#include "sclvector.h"
#include "tcommon.h"
+#include "tcompare.h"
#include "tdatablock.h"
-#include "scalar.h"
-#include "tudf.h"
#include "ttime.h"
-#include "tcompare.h"
+#include "tudf.h"
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
- || OP_TYPE_IS_FALSE == type || OP_TYPE_IS_NOT_FALSE == type || OP_TYPE_IS_UNKNOWN == type || OP_TYPE_IS_NOT_UNKNOWN == type
- || OP_TYPE_MINUS == type) {
+ if (OP_TYPE_IS_NULL == type || OP_TYPE_IS_NOT_NULL == type || OP_TYPE_IS_TRUE == type ||
+ OP_TYPE_IS_NOT_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_MINUS == type) {
return 1;
}
return 2;
}
-int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode) {
- char *timeStr = valueNode->datum.p;
- int32_t code = convertStringToTimestamp(valueNode->node.resType.type, valueNode->datum.p, precision, &valueNode->datum.i);
+int32_t sclConvertToTsValueNode(int8_t precision, SValueNode *valueNode) {
+ char *timeStr = valueNode->datum.p;
+ int32_t code =
+ convertStringToTimestamp(valueNode->node.resType.type, valueNode->datum.p, precision, &valueNode->datum.i);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
@@ -36,16 +37,16 @@ int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode) {
return TSDB_CODE_SUCCESS;
}
-int32_t sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows, SScalarParam* pParam) {
- SColumnInfoData* pColumnData = taosMemoryCalloc(1, sizeof(SColumnInfoData));
+int32_t sclCreateColumnInfoData(SDataType *pType, int32_t numOfRows, SScalarParam *pParam) {
+ SColumnInfoData *pColumnData = taosMemoryCalloc(1, sizeof(SColumnInfoData));
if (pColumnData == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return terrno;
}
- pColumnData->info.type = pType->type;
- pColumnData->info.bytes = pType->bytes;
- pColumnData->info.scale = pType->scale;
+ pColumnData->info.type = pType->type;
+ pColumnData->info.bytes = pType->bytes;
+ pColumnData->info.scale = pType->scale;
pColumnData->info.precision = pType->precision;
int32_t code = colInfoDataEnsureCapacity(pColumnData, numOfRows);
@@ -60,9 +61,9 @@ int32_t sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows, SScalarPara
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};
- int32_t code = sclCreateColumnInfoData(&pValueNode->node.resType, 1, &in);
+ int32_t code = sclCreateColumnInfoData(&pValueNode->node.resType, 1, &in);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
@@ -85,13 +86,13 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) {
taosHashSetEqualFp(pObj, taosGetDefaultEqualFunction(type));
- int32_t code = 0;
+ int32_t code = 0;
SNodeListNode *nodeList = (SNodeListNode *)pNode;
- SListCell *cell = nodeList->pNodeList->pHead;
- SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))};
+ SListCell *cell = nodeList->pNodeList->pHead;
+ SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))};
int32_t len = 0;
- void *buf = NULL;
+ void *buf = NULL;
for (int32_t i = 0; i < nodeList->pNodeList->length; ++i) {
SValueNode *valueNode = (SValueNode *)cell->pNode;
@@ -111,7 +112,7 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) {
int32_t overflow = 0;
code = doConvertDataType(valueNode, &out, &overflow);
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);
}
@@ -164,7 +165,7 @@ _return:
void sclFreeRes(SHashObj *res) {
SScalarParam *p = NULL;
- void *pIter = taosHashIterate(res, NULL);
+ void *pIter = taosHashIterate(res, NULL);
while (pIter) {
p = (SScalarParam *)pIter;
@@ -180,7 +181,7 @@ void sclFreeParam(SScalarParam *param) {
if (!param->colAlloced) {
return;
}
-
+
if (param->columnData != NULL) {
colDataDestroy(param->columnData);
taosMemoryFreeClear(param->columnData);
@@ -213,7 +214,7 @@ void sclFreeParamList(SScalarParam *param, int32_t paramNum) {
}
for (int32_t i = 0; i < paramNum; ++i) {
- SScalarParam* p = param + i;
+ SScalarParam *p = param + i;
sclFreeParam(p);
}
@@ -226,33 +227,33 @@ void sclDowngradeValueType(SValueNode *valueNode) {
int8_t i8 = valueNode->datum.i;
if (i8 == valueNode->datum.i) {
valueNode->node.resType.type = TSDB_DATA_TYPE_TINYINT;
- *(int8_t*)&valueNode->typeData = i8;
+ *(int8_t *)&valueNode->typeData = i8;
break;
}
int16_t i16 = valueNode->datum.i;
if (i16 == valueNode->datum.i) {
valueNode->node.resType.type = TSDB_DATA_TYPE_SMALLINT;
- *(int16_t*)&valueNode->typeData = i16;
+ *(int16_t *)&valueNode->typeData = i16;
break;
}
int32_t i32 = valueNode->datum.i;
if (i32 == valueNode->datum.i) {
valueNode->node.resType.type = TSDB_DATA_TYPE_INT;
- *(int32_t*)&valueNode->typeData = i32;
+ *(int32_t *)&valueNode->typeData = i32;
break;
}
break;
}
- case TSDB_DATA_TYPE_UBIGINT:{
+ case TSDB_DATA_TYPE_UBIGINT: {
uint8_t u8 = valueNode->datum.i;
if (u8 == valueNode->datum.i) {
int8_t i8 = valueNode->datum.i;
if (i8 == valueNode->datum.i) {
valueNode->node.resType.type = TSDB_DATA_TYPE_TINYINT;
- *(int8_t*)&valueNode->typeData = i8;
+ *(int8_t *)&valueNode->typeData = i8;
} else {
valueNode->node.resType.type = TSDB_DATA_TYPE_UTINYINT;
- *(uint8_t*)&valueNode->typeData = u8;
+ *(uint8_t *)&valueNode->typeData = u8;
}
break;
}
@@ -261,10 +262,10 @@ void sclDowngradeValueType(SValueNode *valueNode) {
int16_t i16 = valueNode->datum.i;
if (i16 == valueNode->datum.i) {
valueNode->node.resType.type = TSDB_DATA_TYPE_SMALLINT;
- *(int16_t*)&valueNode->typeData = i16;
+ *(int16_t *)&valueNode->typeData = i16;
} else {
valueNode->node.resType.type = TSDB_DATA_TYPE_USMALLINT;
- *(uint16_t*)&valueNode->typeData = u16;
+ *(uint16_t *)&valueNode->typeData = u16;
}
break;
}
@@ -273,10 +274,10 @@ void sclDowngradeValueType(SValueNode *valueNode) {
int32_t i32 = valueNode->datum.i;
if (i32 == valueNode->datum.i) {
valueNode->node.resType.type = TSDB_DATA_TYPE_INT;
- *(int32_t*)&valueNode->typeData = i32;
+ *(int32_t *)&valueNode->typeData = i32;
} else {
valueNode->node.resType.type = TSDB_DATA_TYPE_UINT;
- *(uint32_t*)&valueNode->typeData = u32;
+ *(uint32_t *)&valueNode->typeData = u32;
}
break;
}
@@ -286,7 +287,7 @@ void sclDowngradeValueType(SValueNode *valueNode) {
float f = valueNode->datum.d;
if (FLT_EQUAL(f, valueNode->datum.d)) {
valueNode->node.resType.type = TSDB_DATA_TYPE_FLOAT;
- *(float*)&valueNode->typeData = f;
+ *(float *)&valueNode->typeData = f;
break;
}
break;
@@ -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)) {
case QUERY_NODE_LEFT_VALUE: {
- SSDataBlock* pb = taosArrayGetP(ctx->pBlockList, 0);
+ SSDataBlock *pb = taosArrayGetP(ctx->pBlockList, 0);
param->numOfRows = pb->info.rows;
break;
}
@@ -308,7 +309,7 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t
ASSERT(param->columnData == NULL);
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) {
colDataAppendNULL(param->columnData, 0);
} else {
@@ -349,8 +350,8 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t
SColumnNode *ref = (SColumnNode *)node;
int32_t index = -1;
- for(int32_t i = 0; i < taosArrayGetSize(ctx->pBlockList); ++i) {
- SSDataBlock* pb = taosArrayGetP(ctx->pBlockList, i);
+ for (int32_t i = 0; i < taosArrayGetSize(ctx->pBlockList); ++i) {
+ SSDataBlock *pb = taosArrayGetP(ctx->pBlockList, i);
if (pb->info.blockId == ref->dataBlockId) {
index = i;
break;
@@ -358,7 +359,8 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t
}
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);
}
@@ -368,13 +370,15 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t
}
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);
}
SColumnInfoData *columnData = (SColumnInfoData *)taosArrayGet(block->pDataBlock, ref->slotId);
#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
param->numOfRows = block->info.rows;
param->columnData = columnData;
@@ -409,7 +413,8 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t
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;
if (NULL == pParamList) {
if (ctx->pBlockList) {
@@ -431,10 +436,10 @@ int32_t sclInitParamList(SScalarParam **pParams, SNodeList* pParamList, SScalarC
}
if (pParamList) {
- SNode *tnode = NULL;
+ SNode *tnode = NULL;
int32_t i = 0;
if (SCL_IS_CONST_CALC(ctx)) {
- WHERE_EACH (tnode, pParamList) {
+ WHERE_EACH(tnode, pParamList) {
if (!SCL_IS_CONST_NODE(tnode)) {
WHERE_NEXT;
} else {
@@ -499,7 +504,6 @@ int32_t sclGetNodeType(SNode *pNode, SScalarCtx *ctx) {
return -1;
}
-
void sclSetOperatorValueType(SOperatorNode *node, SScalarCtx *ctx) {
ctx->type.opResType = node->node.resType.type;
ctx->type.selfType = sclGetNodeType(node->pLeft, ctx);
@@ -538,9 +542,9 @@ _return:
int32_t sclExecFunction(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *output) {
SScalarParam *params = NULL;
- int32_t rowNum = 0;
- int32_t paramNum = 0;
- int32_t code = 0;
+ int32_t rowNum = 0;
+ int32_t paramNum = 0;
+ int32_t code = 0;
SCL_ERR_RET(sclInitParamList(¶ms, node->pParameterList, ctx, ¶mNum, &rowNum));
if (fmIsUserDefinedFunc(node->funcId)) {
@@ -577,7 +581,8 @@ _return:
int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *output) {
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);
}
@@ -592,9 +597,9 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o
}
SScalarParam *params = NULL;
- int32_t rowNum = 0;
- int32_t paramNum = 0;
- int32_t code = 0;
+ int32_t rowNum = 0;
+ int32_t paramNum = 0;
+ int32_t code = 0;
SCL_ERR_RET(sclInitParamList(¶ms, node->pParameterList, ctx, ¶mNum, &rowNum));
if (NULL == params) {
output->numOfRows = 0;
@@ -621,7 +626,7 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o
complete = false;
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);
if (LOGIC_COND_TYPE_AND == node->condType && (false == value)) {
@@ -636,7 +641,7 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o
}
if (complete) {
- colDataAppend(output->columnData, i, (char*) &value, false);
+ colDataAppend(output->columnData, i, (char *)&value, false);
if (value) {
numOfQualified++;
}
@@ -657,13 +662,14 @@ _return:
int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *output) {
SScalarParam *params = NULL;
- int32_t rowNum = 0;
- int32_t code = 0;
+ int32_t rowNum = 0;
+ int32_t code = 0;
// json not support in in operator
if (nodeType(node->pLeft) == QUERY_NODE_VALUE) {
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);
}
}
@@ -678,9 +684,9 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp
_bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(node->opType);
- int32_t paramNum = scalarGetOperatorParamNum(node->opType);
- SScalarParam* pLeft = ¶ms[0];
- SScalarParam* pRight = paramNum > 1 ? ¶ms[1] : NULL;
+ int32_t paramNum = scalarGetOperatorParamNum(node->opType);
+ SScalarParam *pLeft = ¶ms[0];
+ SScalarParam *pRight = paramNum > 1 ? ¶ms[1] : NULL;
terrno = TSDB_CODE_SUCCESS;
OperatorFn(pLeft, pRight, output, TSDB_ORDER_ASC);
@@ -692,7 +698,7 @@ _return:
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) {
SValueNode *res = (SValueNode *)nodesMakeNode(QUERY_NODE_VALUE);
if (NULL == res) {
@@ -704,7 +710,7 @@ EDealRes sclRewriteNullInOptr(SNode** pNode, SScalarCtx *ctx, EOperatorType opTy
res->node.resType.type = TSDB_DATA_TYPE_NULL;
nodesDestroyNode(*pNode);
- *pNode = (SNode*)res;
+ *pNode = (SNode *)res;
} else {
SValueNode *res = (SValueNode *)nodesMakeNode(QUERY_NODE_VALUE);
if (NULL == res) {
@@ -718,17 +724,17 @@ EDealRes sclRewriteNullInOptr(SNode** pNode, SScalarCtx *ctx, EOperatorType opTy
res->datum.b = false;
nodesDestroyNode(*pNode);
- *pNode = (SNode*)res;
+ *pNode = (SNode *)res;
}
return DEAL_RES_CONTINUE;
}
-EDealRes sclAggFuncWalker(SNode* pNode, void* pContext) {
+EDealRes sclAggFuncWalker(SNode *pNode, void *pContext) {
if (QUERY_NODE_FUNCTION == nodeType(pNode)) {
- SFunctionNode* pFunc = (SFunctionNode*)pNode;
- *(bool*)pContext = fmIsAggFunc(pFunc->funcId);
- if (*(bool*)pContext) {
+ SFunctionNode *pFunc = (SFunctionNode *)pNode;
+ *(bool *)pContext = fmIsAggFunc(pFunc->funcId);
+ if (*(bool *)pContext) {
return DEAL_RES_END;
}
}
@@ -736,27 +742,26 @@ EDealRes sclAggFuncWalker(SNode* pNode, void* pContext) {
return DEAL_RES_CONTINUE;
}
-
-bool sclContainsAggFuncNode(SNode* pNode) {
+bool sclContainsAggFuncNode(SNode *pNode) {
bool aggFunc = false;
nodesWalkExpr(pNode, sclAggFuncWalker, (void *)&aggFunc);
return aggFunc;
}
-EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) {
+EDealRes sclRewriteNonConstOperator(SNode **pNode, SScalarCtx *ctx) {
SOperatorNode *node = (SOperatorNode *)*pNode;
- int32_t code = 0;
+ int32_t code = 0;
if (node->pLeft && (QUERY_NODE_VALUE == nodeType(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)
- && (!sclContainsAggFuncNode(node->pRight))) {
+ if (SCL_IS_NULL_VALUE_NODE(valueNode) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL) &&
+ (!sclContainsAggFuncNode(node->pRight))) {
return sclRewriteNullInOptr(pNode, ctx, node->opType);
}
- if (IS_STR_DATA_TYPE(valueNode->node.resType.type) && node->pRight && nodesIsExprNode(node->pRight)
- && ((SExprNode*)node->pRight)->resType.type == TSDB_DATA_TYPE_TIMESTAMP) {
- code = sclConvertToTsValueNode(((SExprNode*)node->pRight)->resType.precision, valueNode);
+ if (IS_STR_DATA_TYPE(valueNode->node.resType.type) && node->pRight && nodesIsExprNode(node->pRight) &&
+ ((SExprNode *)node->pRight)->resType.type == TSDB_DATA_TYPE_TIMESTAMP) {
+ code = sclConvertToTsValueNode(((SExprNode *)node->pRight)->resType.precision, valueNode);
if (code) {
ctx->code = code;
return DEAL_RES_ERROR;
@@ -765,19 +770,19 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) {
if (SCL_IS_COMPARISON_OPERATOR(node->opType) && SCL_DOWNGRADE_DATETYPE(valueNode->node.resType.type)) {
sclDowngradeValueType(valueNode);
- }
+ }
}
if (node->pRight && (QUERY_NODE_VALUE == nodeType(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)
- && (!sclContainsAggFuncNode(node->pLeft))) {
+ if (SCL_IS_NULL_VALUE_NODE(valueNode) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL) &&
+ (!sclContainsAggFuncNode(node->pLeft))) {
return sclRewriteNullInOptr(pNode, ctx, node->opType);
}
- if (IS_STR_DATA_TYPE(valueNode->node.resType.type) && node->pLeft && nodesIsExprNode(node->pLeft)
- && ((SExprNode*)node->pLeft)->resType.type == TSDB_DATA_TYPE_TIMESTAMP) {
- code = sclConvertToTsValueNode(((SExprNode*)node->pLeft)->resType.precision, valueNode);
+ if (IS_STR_DATA_TYPE(valueNode->node.resType.type) && node->pLeft && nodesIsExprNode(node->pLeft) &&
+ ((SExprNode *)node->pLeft)->resType.type == TSDB_DATA_TYPE_TIMESTAMP) {
+ code = sclConvertToTsValueNode(((SExprNode *)node->pLeft)->resType.precision, valueNode);
if (code) {
ctx->code = code;
return DEAL_RES_ERROR;
@@ -786,18 +791,18 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) {
if (SCL_IS_COMPARISON_OPERATOR(node->opType) && SCL_DOWNGRADE_DATETYPE(valueNode->node.resType.type)) {
sclDowngradeValueType(valueNode);
- }
+ }
}
if (node->pRight && (QUERY_NODE_NODE_LIST == nodeType(node->pRight))) {
SNodeListNode *listNode = (SNodeListNode *)node->pRight;
- SNode* tnode = NULL;
+ SNode *tnode = NULL;
WHERE_EACH(tnode, listNode->pNodeList) {
if (SCL_IS_NULL_VALUE_NODE(tnode)) {
if (node->opType == OP_TYPE_IN) {
ERASE_NODE(listNode->pNodeList);
continue;
- } else { //OP_TYPE_NOT_IN
+ } else { // OP_TYPE_NOT_IN
return sclRewriteNullInOptr(pNode, ctx, node->opType);
}
}
@@ -813,9 +818,9 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) {
return DEAL_RES_CONTINUE;
}
-EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
+EDealRes sclRewriteFunction(SNode **pNode, SScalarCtx *ctx) {
SFunctionNode *node = (SFunctionNode *)*pNode;
- SNode* tnode = NULL;
+ SNode *tnode = NULL;
if (!fmIsScalarFunc(node->funcId) && (!ctx->dual)) {
return DEAL_RES_CONTINUE;
}
@@ -851,12 +856,12 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
res->isNull = true;
} else {
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);
res->datum.p = taosMemoryCalloc(len, 1);
memcpy(res->datum.p, output.columnData->pData, len);
} 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->node.resType.bytes = 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) {
}
nodesDestroyNode(*pNode);
- *pNode = (SNode*)res;
+ *pNode = (SNode *)res;
sclFreeParam(&output);
return DEAL_RES_CONTINUE;
}
-EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) {
+EDealRes sclRewriteLogic(SNode **pNode, SScalarCtx *ctx) {
SLogicConditionNode *node = (SLogicConditionNode *)*pNode;
SScalarParam output = {0};
@@ -905,13 +910,13 @@ EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) {
}
nodesDestroyNode(*pNode);
- *pNode = (SNode*)res;
+ *pNode = (SNode *)res;
sclFreeParam(&output);
return DEAL_RES_CONTINUE;
}
-EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) {
+EDealRes sclRewriteOperator(SNode **pNode, SScalarCtx *ctx) {
SOperatorNode *node = (SOperatorNode *)*pNode;
if ((!SCL_IS_CONST_NODE(node->pLeft)) || (!SCL_IS_CONST_NODE(node->pRight))) {
@@ -949,13 +954,13 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) {
}
nodesDestroyNode(*pNode);
- *pNode = (SNode*)res;
+ *pNode = (SNode *)res;
sclFreeParam(&output);
return DEAL_RES_CONTINUE;
}
-EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) {
+EDealRes sclConstantsRewriter(SNode **pNode, void *pContext) {
SScalarCtx *ctx = (SScalarCtx *)pContext;
if (QUERY_NODE_FUNCTION == nodeType(*pNode)) {
@@ -973,9 +978,9 @@ EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) {
return DEAL_RES_CONTINUE;
}
-EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) {
+EDealRes sclWalkFunction(SNode *pNode, SScalarCtx *ctx) {
SFunctionNode *node = (SFunctionNode *)pNode;
- SScalarParam output = {0};
+ SScalarParam output = {0};
ctx->code = sclExecFunction(node, ctx, &output);
if (ctx->code) {
@@ -990,9 +995,9 @@ EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) {
return DEAL_RES_CONTINUE;
}
-EDealRes sclWalkLogic(SNode* pNode, SScalarCtx *ctx) {
+EDealRes sclWalkLogic(SNode *pNode, SScalarCtx *ctx) {
SLogicConditionNode *node = (SLogicConditionNode *)pNode;
- SScalarParam output = {0};
+ SScalarParam output = {0};
ctx->code = sclExecLogic(node, ctx, &output);
if (ctx->code) {
@@ -1007,9 +1012,9 @@ EDealRes sclWalkLogic(SNode* pNode, SScalarCtx *ctx) {
return DEAL_RES_CONTINUE;
}
-EDealRes sclWalkOperator(SNode* pNode, SScalarCtx *ctx) {
+EDealRes sclWalkOperator(SNode *pNode, SScalarCtx *ctx) {
SOperatorNode *node = (SOperatorNode *)pNode;
- SScalarParam output = {0};
+ SScalarParam output = {0};
ctx->code = sclExecOperator(node, ctx, &output);
if (ctx->code) {
@@ -1024,18 +1029,19 @@ EDealRes sclWalkOperator(SNode* pNode, SScalarCtx *ctx) {
return DEAL_RES_CONTINUE;
}
-EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) {
+EDealRes sclWalkTarget(SNode *pNode, SScalarCtx *ctx) {
STargetNode *target = (STargetNode *)pNode;
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;
return DEAL_RES_ERROR;
}
int32_t index = -1;
- for(int32_t i = 0; i < taosArrayGetSize(ctx->pBlockList); ++i) {
- SSDataBlock* pb = taosArrayGetP(ctx->pBlockList, i);
+ for (int32_t i = 0; i < taosArrayGetSize(ctx->pBlockList); ++i) {
+ SSDataBlock *pb = taosArrayGetP(ctx->pBlockList, i);
if (pb->info.blockId == target->dataBlockId) {
index = i;
break;
@@ -1043,7 +1049,8 @@ EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) {
}
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;
return DEAL_RES_ERROR;
}
@@ -1051,7 +1058,8 @@ EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) {
SSDataBlock *block = *(SSDataBlock **)taosArrayGet(ctx->pBlockList, index);
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;
return DEAL_RES_ERROR;
}
@@ -1074,8 +1082,9 @@ EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) {
return DEAL_RES_CONTINUE;
}
-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)) {
+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)) {
return DEAL_RES_CONTINUE;
}
@@ -1102,7 +1111,7 @@ EDealRes sclCalcWalker(SNode* pNode, void* pContext) {
}
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));
if (NULL == pLeft) {
sclError("calloc %d failed", (int32_t)sizeof(SScalarParam));
@@ -1125,7 +1134,7 @@ int32_t sclCalcConstants(SNode *pNode, bool dual, SNode **pRes) {
SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
}
- int32_t code = 0;
+ int32_t code = 0;
SScalarCtx ctx = {0};
ctx.dual = dual;
ctx.pRes = taosHashInit(SCL_DEFAULT_OP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
@@ -1144,8 +1153,8 @@ _return:
return code;
}
-static int32_t sclGetMinusOperatorResType(SOperatorNode* pOp) {
- if (!IS_MATHABLE_TYPE(((SExprNode*)(pOp->pLeft))->resType.type)) {
+static int32_t sclGetMinusOperatorResType(SOperatorNode *pOp) {
+ if (!IS_MATHABLE_TYPE(((SExprNode *)(pOp->pLeft))->resType.type)) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE;
@@ -1153,9 +1162,9 @@ static int32_t sclGetMinusOperatorResType(SOperatorNode* pOp) {
return TSDB_CODE_SUCCESS;
}
-static int32_t sclGetMathOperatorResType(SOperatorNode* pOp) {
- SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType;
- SDataType rdt = ((SExprNode*)(pOp->pRight))->resType;
+static int32_t sclGetMathOperatorResType(SOperatorNode *pOp) {
+ SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType;
+ SDataType rdt = ((SExprNode *)(pOp->pRight))->resType;
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 == rdt.type && (IS_VAR_DATA_TYPE(ldt.type) || IS_FLOAT_TYPE(ldt.type)))) {
@@ -1175,12 +1184,12 @@ static int32_t sclGetMathOperatorResType(SOperatorNode* pOp) {
return TSDB_CODE_SUCCESS;
}
-static int32_t sclGetCompOperatorResType(SOperatorNode* pOp) {
- SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType;
+static int32_t sclGetCompOperatorResType(SOperatorNode *pOp) {
+ SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType;
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)) {
- 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) ||
(!IS_STR_DATA_TYPE(rdt.type) && (rdt.type != TSDB_DATA_TYPE_NULL))) {
return TSDB_CODE_TSC_INVALID_OPERATION;
@@ -1191,9 +1200,9 @@ static int32_t sclGetCompOperatorResType(SOperatorNode* pOp) {
return TSDB_CODE_SUCCESS;
}
-static int32_t sclGetJsonOperatorResType(SOperatorNode* pOp) {
- SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType;
- SDataType rdt = ((SExprNode*)(pOp->pRight))->resType;
+static int32_t sclGetJsonOperatorResType(SOperatorNode *pOp) {
+ SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType;
+ SDataType rdt = ((SExprNode *)(pOp->pRight))->resType;
if (TSDB_DATA_TYPE_JSON != ldt.type || !IS_STR_DATA_TYPE(rdt.type)) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
@@ -1206,27 +1215,22 @@ static int32_t sclGetJsonOperatorResType(SOperatorNode* pOp) {
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.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes;
return TSDB_CODE_SUCCESS;
}
+int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) { return sclCalcConstants(pNode, false, pRes); }
-int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) {
- return sclCalcConstants(pNode, false, pRes);
-}
-
-int32_t scalarCalculateConstantsFromDual(SNode *pNode, SNode **pRes) {
- return sclCalcConstants(pNode, true, pRes);
-}
+int32_t scalarCalculateConstantsFromDual(SNode *pNode, SNode **pRes) { return sclCalcConstants(pNode, true, pRes); }
int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) {
if (NULL == pNode || NULL == pBlockList) {
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};
// TODO: OPT performance
@@ -1264,9 +1268,9 @@ _return:
return code;
}
-int32_t scalarGetOperatorResultType(SOperatorNode* pOp) {
- if (TSDB_DATA_TYPE_BLOB == ((SExprNode*)(pOp->pLeft))->resType.type ||
- (NULL != pOp->pRight && TSDB_DATA_TYPE_BLOB == ((SExprNode*)(pOp->pRight))->resType.type)) {
+int32_t scalarGetOperatorResultType(SOperatorNode *pOp) {
+ if (TSDB_DATA_TYPE_BLOB == ((SExprNode *)(pOp->pLeft))->resType.type ||
+ (NULL != pOp->pRight && TSDB_DATA_TYPE_BLOB == ((SExprNode *)(pOp->pRight))->resType.type)) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
@@ -1280,7 +1284,7 @@ int32_t scalarGetOperatorResultType(SOperatorNode* pOp) {
case OP_TYPE_MINUS:
return sclGetMinusOperatorResType(pOp);
case OP_TYPE_ASSIGN:
- pOp->node.resType = ((SExprNode*)(pOp->pLeft))->resType;
+ pOp->node.resType = ((SExprNode *)(pOp->pLeft))->resType;
break;
case OP_TYPE_BIT_AND:
case OP_TYPE_BIT_OR:
diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c
index 91044a96b53aed1c8d32c8fc57278f9b14499fd5..339065633bce5107df2879d45fbf259609a544a6 100644
--- a/source/libs/scalar/src/sclfunc.c
+++ b/source/libs/scalar/src/sclfunc.c
@@ -1,3 +1,4 @@
+#include "cJSON.h"
#include "function.h"
#include "scalar.h"
#include "sclInt.h"
@@ -5,20 +6,17 @@
#include "tdatablock.h"
#include "tjson.h"
#include "ttime.h"
-#include "cJSON.h"
#include "vnode.h"
typedef float (*_float_fn)(float);
typedef double (*_double_fn)(double);
typedef double (*_double_fn_2)(double, double);
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);
/** Math functions **/
-static double tlog(double v) {
- return log(v);
-}
+static double tlog(double v) { return log(v); }
static double tlog2(double v, double base) {
double a = log(v);
@@ -33,86 +31,86 @@ static double tlog2(double v, double base) {
}
int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput);
switch (type) {
case TSDB_DATA_TYPE_FLOAT: {
- float *in = (float *)pInputData->pData;
+ float *in = (float *)pInputData->pData;
float *out = (float *)pOutputData->pData;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) {
colDataAppendNULL(pOutputData, i);
continue;
}
- out[i] = (in[i] >= 0)? in[i] : -in[i];
+ out[i] = (in[i] >= 0) ? in[i] : -in[i];
}
break;
}
case TSDB_DATA_TYPE_DOUBLE: {
- double *in = (double *)pInputData->pData;
+ double *in = (double *)pInputData->pData;
double *out = (double *)pOutputData->pData;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) {
colDataAppendNULL(pOutputData, i);
continue;
}
- out[i] = (in[i] >= 0)? in[i] : -in[i];
+ out[i] = (in[i] >= 0) ? in[i] : -in[i];
}
break;
}
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;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) {
colDataAppendNULL(pOutputData, i);
continue;
}
- out[i] = (in[i] >= 0)? in[i] : -in[i];
+ out[i] = (in[i] >= 0) ? in[i] : -in[i];
}
break;
}
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;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) {
colDataAppendNULL(pOutputData, i);
continue;
}
- out[i] = (in[i] >= 0)? in[i] : -in[i];
+ out[i] = (in[i] >= 0) ? in[i] : -in[i];
}
break;
}
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;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) {
colDataAppendNULL(pOutputData, i);
continue;
}
- out[i] = (in[i] >= 0)? in[i] : -in[i];
+ out[i] = (in[i] >= 0) ? in[i] : -in[i];
}
break;
}
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;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) {
colDataAppendNULL(pOutputData, i);
continue;
}
- out[i] = (in[i] >= 0)? in[i] : -in[i];
+ out[i] = (in[i] >= 0) ? in[i] : -in[i];
}
break;
}
@@ -133,7 +131,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu
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);
SColumnInfoData *pInputData = pInput->columnData;
@@ -160,28 +158,26 @@ static int32_t doScalarFunctionUnique(SScalarParam *pInput, int32_t inputNum, SS
return TSDB_CODE_SUCCESS;
}
-static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, SScalarParam* pOutput, _double_fn_2 valFn) {
- SColumnInfoData *pInputData[2];
- SColumnInfoData *pOutputData = pOutput->columnData;
+static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput,
+ _double_fn_2 valFn) {
+ SColumnInfoData *pInputData[2];
+ SColumnInfoData *pOutputData = pOutput->columnData;
_getDoubleValue_fn_t getValueFn[2];
for (int32_t i = 0; i < inputNum; ++i) {
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 result;
+ double result;
- bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) ||
- IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1])));
+ bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) || IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1])));
int32_t numOfRows = TMAX(pInput[0].numOfRows, pInput[1].numOfRows);
if (pInput[0].numOfRows == pInput[1].numOfRows) {
for (int32_t i = 0; i < numOfRows; ++i) {
- if (colDataIsNull_s(pInputData[0], i) ||
- colDataIsNull_s(pInputData[1], i) ||
- hasNullType) {
+ if (colDataIsNull_s(pInputData[0], i) || colDataIsNull_s(pInputData[1], i) || hasNullType) {
colDataAppendNULL(pOutputData, i);
continue;
}
@@ -192,7 +188,7 @@ static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, S
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) {
colDataAppendNNULL(pOutputData, 0, pInput[1].numOfRows);
} else {
@@ -236,15 +232,16 @@ static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, S
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);
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
switch (type) {
case TSDB_DATA_TYPE_FLOAT: {
- float *in = (float *)pInputData->pData;
+ float *in = (float *)pInputData->pData;
float *out = (float *)pOutputData->pData;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
@@ -258,7 +255,7 @@ static int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
}
case TSDB_DATA_TYPE_DOUBLE: {
- double *in = (double *)pInputData->pData;
+ double *in = (double *)pInputData->pData;
double *out = (double *)pOutputData->pData;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
@@ -288,14 +285,12 @@ static int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
}
/** String functions **/
-static int16_t tlength(char *input, int32_t type) {
- return varDataLen(input);
-}
+static int16_t tlength(char *input, int32_t type) { return varDataLen(input); }
static int16_t tcharlength(char *input, int32_t type) {
if (type == TSDB_DATA_TYPE_VARCHAR) {
return varDataLen(input);
- } else { //NCHAR
+ } else { // NCHAR
return varDataLen(input) / TSDB_NCHAR_SIZE;
}
}
@@ -309,7 +304,7 @@ static void tltrim(char *input, char *output, int32_t type, int32_t charLen) {
}
numOfSpaces++;
}
- } else { //NCHAR
+ } else { // NCHAR
for (int32_t i = 0; i < charLen; ++i) {
if (!iswspace(*((uint32_t *)varDataVal(input) + i))) {
break;
@@ -339,7 +334,7 @@ static void trtrim(char *input, char *output, int32_t type, int32_t charLen) {
}
numOfSpaces++;
}
- } else { //NCHAR
+ } else { // NCHAR
for (int32_t i = charLen - 1; i >= 0; --i) {
if (!iswspace(*((uint32_t *)varDataVal(input) + i))) {
break;
@@ -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) {
int32_t type = GET_PARAM_TYPE(pInput);
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
ASSERT(pOutputData->info.type == TSDB_DATA_TYPE_BIGINT);
@@ -386,7 +381,7 @@ static int32_t concatCopyHelper(const char *input, char *output, bool hasNchar,
if (hasNchar && type == TSDB_DATA_TYPE_VARCHAR) {
TdUcs4 *newBuf = taosMemoryCalloc((varDataLen(input) + 1) * TSDB_NCHAR_SIZE, 1);
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) {
taosMemoryFree(newBuf);
return TSDB_CODE_FAILED;
@@ -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 ret = TSDB_CODE_SUCCESS;
+ int32_t ret = TSDB_CODE_SUCCESS;
SColumnInfoData **pInputData = taosMemoryCalloc(inputNum, sizeof(SColumnInfoData *));
- SColumnInfoData *pOutputData = pOutput->columnData;
- char **input = taosMemoryCalloc(inputNum, POINTER_BYTES);
- char *outputBuf = NULL;
+ SColumnInfoData *pOutputData = pOutput->columnData;
+ char **input = taosMemoryCalloc(inputNum, POINTER_BYTES);
+ char *outputBuf = NULL;
int32_t inputLen = 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) {
if (pInput[i].numOfRows > numOfRows) {
numOfRows = pInput[i].numOfRows;
@@ -451,8 +446,7 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
for (int32_t k = 0; k < numOfRows; ++k) {
bool hasNull = false;
for (int32_t i = 0; i < inputNum; ++i) {
- if (colDataIsNull_s(pInputData[i], k) ||
- IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[i]))) {
+ if (colDataIsNull_s(pInputData[i], k) || IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[i]))) {
colDataAppendNULL(pOutputData, k);
hasNull = true;
break;
@@ -463,7 +457,6 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
continue;
}
-
int16_t dataLen = 0;
for (int32_t i = 0; i < inputNum; ++i) {
int32_t rowIdx = (pInput[i].numOfRows == 1) ? 0 : k;
@@ -489,17 +482,16 @@ DONE:
return ret;
}
-
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 *pOutputData = pOutput->columnData;
- char **input = taosMemoryCalloc(inputNum, POINTER_BYTES);
- char *outputBuf = NULL;
+ SColumnInfoData *pOutputData = pOutput->columnData;
+ char **input = taosMemoryCalloc(inputNum, POINTER_BYTES);
+ char *outputBuf = NULL;
int32_t inputLen = 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) {
if (pInput[i].numOfRows > numOfRows) {
numOfRows = pInput[i].numOfRows;
@@ -515,7 +507,8 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
int32_t numOfNulls = getNumOfNullEntries(pInputData[i], pInput[i].numOfRows);
if (i == 0) {
// 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) {
inputLen += (pInputData[i]->varmeta.length - VARSTR_HEADER_SIZE) * (numOfRows - numOfNulls) * factor;
} else {
@@ -528,17 +521,15 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
char *output = outputBuf;
for (int32_t k = 0; k < numOfRows; ++k) {
- if (colDataIsNull_s(pInputData[0], k) ||
- IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0]))) {
+ if (colDataIsNull_s(pInputData[0], k) || IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0]))) {
colDataAppendNULL(pOutputData, k);
continue;
}
int16_t dataLen = 0;
- bool hasNull = false;
+ bool hasNull = false;
for (int32_t i = 1; i < inputNum; ++i) {
- if (colDataIsNull_s(pInputData[i], k) ||
- IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[i]))) {
+ if (colDataIsNull_s(pInputData[i], k) || IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[i]))) {
hasNull = true;
break;
}
@@ -551,11 +542,10 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
goto DONE;
}
-
if (i < inputNum - 1) {
- //insert the separator
+ // insert the separator
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) {
goto DONE;
}
@@ -585,12 +575,12 @@ DONE:
static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _conv_fn convFn) {
int32_t type = GET_PARAM_TYPE(pInput);
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
int32_t outputLen = pInputData->varmeta.length;
- char *outputBuf = taosMemoryCalloc(outputLen, 1);
- char *output = outputBuf;
+ char *outputBuf = taosMemoryCalloc(outputLen, 1);
+ char *output = outputBuf;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) {
@@ -598,13 +588,13 @@ static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScala
continue;
}
- char *input = colDataGetData(pInput[0].columnData, i);
+ char *input = colDataGetData(pInput[0].columnData, i);
int32_t len = varDataLen(input);
if (type == TSDB_DATA_TYPE_VARCHAR) {
for (int32_t j = 0; j < len; ++j) {
*(varDataVal(output) + j) = convFn(*(varDataVal(input) + j));
}
- } else { //NCHAR
+ } else { // NCHAR
for (int32_t j = 0; j < len / TSDB_NCHAR_SIZE; ++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
return TSDB_CODE_SUCCESS;
}
-
static int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _trim_fn trimFn) {
int32_t type = GET_PARAM_TYPE(pInput);
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
int32_t outputLen = pInputData->varmeta.length;
- char *outputBuf = taosMemoryCalloc(outputLen, 1);
- char *output = outputBuf;
+ char *outputBuf = taosMemoryCalloc(outputLen, 1);
+ char *output = outputBuf;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) {
@@ -637,7 +626,7 @@ static int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarPar
continue;
}
- char *input = colDataGetData(pInputData, i);
+ char *input = colDataGetData(pInputData, i);
int32_t len = varDataLen(input);
int32_t charLen = (type == TSDB_DATA_TYPE_VARCHAR) ? len : len / TSDB_NCHAR_SIZE;
trimFn(input, output, type, charLen);
@@ -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;
}
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
int32_t outputLen = pInputData->varmeta.length * pInput->numOfRows;
- char *outputBuf = taosMemoryCalloc(outputLen, 1);
- char *output = outputBuf;
+ char *outputBuf = taosMemoryCalloc(outputLen, 1);
+ char *output = outputBuf;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) {
colDataAppendNULL(pOutputData, i);
continue;
}
- char *input = colDataGetData(pInput[0].columnData, i);
+ char *input = colDataGetData(pInput[0].columnData, i);
int32_t len = varDataLen(input);
int32_t startPosBytes;
@@ -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 = TMIN(startPosBytes, len);
} 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);
}
@@ -692,7 +682,7 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
}
varDataSetLen(output, resLen);
- colDataAppend(pOutputData, i , output, false);
+ colDataAppend(pOutputData, i, output, false);
output += varDataTLen(output);
}
@@ -704,14 +694,14 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
/** Conversion functions **/
int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
- int16_t inputType = GET_PARAM_TYPE(&pInput[0]);
- int16_t inputLen = GET_PARAM_BYTES(&pInput[0]);
+ int16_t inputType = GET_PARAM_TYPE(&pInput[0]);
+ int16_t inputLen = GET_PARAM_BYTES(&pInput[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;
- char * convBuf = taosMemoryMalloc(inputLen);
- char * output = taosMemoryCalloc(1, outputLen + TSDB_NCHAR_SIZE);
+ char *convBuf = taosMemoryMalloc(inputLen);
+ char *output = taosMemoryCalloc(1, outputLen + TSDB_NCHAR_SIZE);
char buf[400] = {0};
if (convBuf == NULL || output == NULL) {
@@ -727,14 +717,14 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
char *input = colDataGetData(pInput[0].columnData, i);
- switch(outputType) {
+ switch (outputType) {
case TSDB_DATA_TYPE_TINYINT: {
if (inputType == TSDB_DATA_TYPE_BINARY) {
memcpy(buf, varDataVal(input), varDataLen(input));
buf[varDataLen(input)] = 0;
*(int8_t *)output = taosStr2Int8(buf, NULL, 10);
} 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) {
code = TSDB_CODE_FAILED;
goto _end;
@@ -753,7 +743,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
buf[varDataLen(input)] = 0;
*(int16_t *)output = taosStr2Int16(buf, NULL, 10);
} 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) {
code = TSDB_CODE_FAILED;
goto _end;
@@ -771,7 +761,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
buf[varDataLen(input)] = 0;
*(int32_t *)output = taosStr2Int32(buf, NULL, 10);
} 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) {
code = TSDB_CODE_FAILED;
goto _end;
@@ -790,7 +780,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
buf[varDataLen(input)] = 0;
*(int64_t *)output = taosStr2Int64(buf, NULL, 10);
} 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) {
code = TSDB_CODE_FAILED;
goto _end;
@@ -881,7 +871,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
buf[varDataLen(input)] = 0;
*(float *)output = taosStr2Float(buf, NULL);
} 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) {
code = TSDB_CODE_FAILED;
goto _end;
@@ -899,7 +889,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
buf[varDataLen(input)] = 0;
*(double *)output = taosStr2Double(buf, NULL);
} 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) {
code = TSDB_CODE_FAILED;
goto _end;
@@ -917,7 +907,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
buf[varDataLen(input)] = 0;
*(bool *)output = taosStr2Int8(buf, NULL, 10);
} 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) {
code = TSDB_CODE_FAILED;
goto _end;
@@ -948,7 +938,8 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
case TSDB_DATA_TYPE_BINARY: {
if (inputType == TSDB_DATA_TYPE_BOOL) {
// 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);
} else if (inputType == TSDB_DATA_TYPE_BINARY) {
int32_t len = TMIN(varDataLen(input), outputLen - VARSTR_HEADER_SIZE);
@@ -977,7 +968,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
int32_t len;
if (inputType == TSDB_DATA_TYPE_BOOL) {
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);
if (!ret) {
code = TSDB_CODE_FAILED;
@@ -987,7 +978,8 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
varDataSetLen(output, len);
} else if (inputType == TSDB_DATA_TYPE_BINARY) {
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) {
code = TSDB_CODE_FAILED;
goto _end;
@@ -1009,7 +1001,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
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) {
pOutput->columnData->info.bytes = len + VARSTR_HEADER_SIZE;
}
@@ -1027,7 +1019,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
pOutput->numOfRows = pInput->numOfRows;
- _end:
+_end:
taosMemoryFree(output);
taosMemoryFree(convBuf);
return code;
@@ -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 type = GET_PARAM_TYPE(pInput);
- bool tzPresent = (inputNum == 2) ? true : false;
- char* tz;
+ bool tzPresent = (inputNum == 2) ? true : false;
+ char *tz;
int32_t tzLen;
if (tzPresent) {
tz = varDataVal(pInput[1].columnData->pData);
@@ -1051,12 +1043,12 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *
}
char *input = colDataGetData(pInput[0].columnData, i);
- char fraction[20] = {0};
- bool hasFraction = false;
+ char fraction[20] = {0};
+ bool hasFraction = false;
NUM_TO_STRING(type, input, sizeof(fraction), fraction);
int32_t tsDigits = (int32_t)strlen(fraction);
- char buf[64] = {0};
+ char buf[64] = {0};
int64_t timeVal;
GET_TYPED_DATA(timeVal, int64_t, type, input);
if (tsDigits > TSDB_TIME_PRECISION_SEC_DIGITS) {
@@ -1079,7 +1071,7 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *
strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S", &tmInfo);
int32_t len = (int32_t)strlen(buf);
- //add timezone string
+ // add timezone string
snprintf(buf + len, tzLen + 1, "%s", tz);
len += tzLen;
@@ -1095,7 +1087,7 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *
if (tzInfo) {
memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo));
} else {
- //search '-' backwards
+ // search '-' backwards
tzInfo = strrchr(buf, '-');
if (tzInfo) {
memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo));
@@ -1151,25 +1143,25 @@ int32_t toJsonFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
char tmp[TSDB_MAX_JSON_TAG_LEN] = {0};
for (int32_t i = 0; i < pInput[0].numOfRows; ++i) {
- SArray* pTagVals = taosArrayInit(8, sizeof(STagVal));
- STag* pTag = NULL;
+ SArray *pTagVals = taosArrayInit(8, sizeof(STagVal));
+ STag *pTag = NULL;
if (colDataIsNull_s(pInput[0].columnData, i)) {
tTagNew(pTagVals, 1, true, &pTag);
- }else{
+ } else {
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);
return TSDB_CODE_FAILED;
}
memcpy(tmp, varDataVal(input), varDataLen(input));
tmp[varDataLen(input)] = 0;
- if(parseJsontoTagData(tmp, pTagVals, &pTag, NULL)){
+ if (parseJsontoTagData(tmp, pTagVals, &pTag, NULL)) {
tTagNew(pTagVals, 1, true, &pTag);
}
}
- colDataAppend(pOutput->columnData, i, (const char*)pTag, false);
+ colDataAppend(pOutput->columnData, i, (const char *)pTag, false);
tTagFree(pTag);
taosArrayDestroy(pTagVals);
}
@@ -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(timePrec, int64_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData);
- int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 :
- (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
+ int64_t factor =
+ (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
int64_t unit = timeUnit * 1000 / factor;
@@ -1205,7 +1197,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
colDataAppendNULL(pOutput->columnData, i);
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;
if (timeValSec < 1000000000) {
timeVal = timeValSec;
@@ -1246,7 +1238,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
timeVal = timeVal / 1000 * 1000;
} else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) {
timeVal = timeVal / 1000000 * 1000000;
- } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS){
+ } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) {
timeVal = timeVal * factor;
} else {
colDataAppendNULL(pOutput->columnData, i);
@@ -1307,7 +1299,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
} else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) {
timeVal = timeVal / 1000000000 / 86400 * 86400 * 1000000000;
} else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) {
- timeVal = timeVal * factor / factor / 86400* 86400 * factor;
+ timeVal = timeVal * factor / factor / 86400 * 86400 * factor;
} else {
colDataAppendNULL(pOutput->columnData, i);
continue;
@@ -1322,7 +1314,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
} else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) {
timeVal = timeVal / 1000000000 / 604800 * 604800 * 1000000000;
} else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) {
- timeVal = timeVal * factor / factor / 604800 * 604800* factor;
+ timeVal = timeVal * factor / factor / 604800 * 604800 * factor;
} else {
colDataAppendNULL(pOutput->columnData, i);
continue;
@@ -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) {
case TSDB_TIME_PRECISION_MILLI: {
if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) {
@@ -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);
}
- int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 :
- (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
+ int64_t factor =
+ (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
int32_t numOfRows = 0;
for (int32_t i = 0; i < inputNum; ++i) {
@@ -1441,11 +1433,10 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
continue;
}
- int64_t result = (timeVal[0] >= timeVal[1]) ? (timeVal[0] - timeVal[1]) :
- (timeVal[1] - timeVal[0]);
+ int64_t result = (timeVal[0] >= timeVal[1]) ? (timeVal[0] - timeVal[1]) : (timeVal[1] - timeVal[0]);
- if (timeUnit < 0) { // if no time unit given use db precision
- switch(timePrec) {
+ if (timeUnit < 0) { // if no time unit given use db precision
+ switch (timePrec) {
case TSDB_TIME_PRECISION_MILLI: {
result = result / 1000000;
break;
@@ -1461,7 +1452,7 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
}
} else {
int64_t unit = timeUnit * 1000 / factor;
- switch(unit) {
+ switch (unit) {
case 0: { /* 1u or 1b */
if (timePrec == TSDB_TIME_PRECISION_NANO && timeUnit == 1) {
result = result / 1;
@@ -1694,7 +1685,7 @@ static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOf
}
#endif
-bool getTimePseudoFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
+bool getTimePseudoFuncEnv(SFunctionNode *UNUSED_PARAM(pFunc), SFuncExecEnv *pEnv) {
pEnv->calcMemSize = sizeof(int64_t);
return true;
}
@@ -1719,13 +1710,13 @@ int32_t winDurFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
int32_t winStartTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
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;
}
int32_t winEndTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
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;
}
@@ -1743,7 +1734,7 @@ int32_t qTbnameFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pO
/** Aggregation functions **/
int32_t countScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
int64_t *out = (int64_t *)pOutputData->pData;
@@ -1760,11 +1751,11 @@ int32_t countScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam
}
int32_t sumScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput);
- bool hasNull = false;
+ bool hasNull = false;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) {
hasNull = true;
@@ -1772,15 +1763,15 @@ int32_t sumScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *
}
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;
*out += in[i];
} 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;
*out += in[i];
} else if (IS_FLOAT_TYPE(type)) {
- double *in = (double *)pInputData->pData;
+ double *in = (double *)pInputData->pData;
double *out = (double *)pOutputData->pData;
*out += in[i];
}
@@ -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) {
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput);
@@ -1813,84 +1804,84 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS
break;
}
- switch(type) {
+ switch (type) {
case TSDB_DATA_TYPE_BOOL:
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;
- if((in[i] > *out) ^ isMinFunc) {
+ if ((in[i] > *out) ^ isMinFunc) {
*out = in[i];
}
break;
}
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;
- if((in[i] > *out) ^ isMinFunc) {
+ if ((in[i] > *out) ^ isMinFunc) {
*out = in[i];
}
break;
}
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;
- if((in[i] > *out) ^ isMinFunc) {
+ if ((in[i] > *out) ^ isMinFunc) {
*out = in[i];
}
break;
}
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;
- if((in[i] > *out) ^ isMinFunc) {
+ if ((in[i] > *out) ^ isMinFunc) {
*out = in[i];
}
break;
}
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;
- if((in[i] > *out) ^ isMinFunc) {
+ if ((in[i] > *out) ^ isMinFunc) {
*out = in[i];
}
break;
}
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;
- if((in[i] > *out) ^ isMinFunc) {
+ if ((in[i] > *out) ^ isMinFunc) {
*out = in[i];
}
break;
}
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;
- if((in[i] > *out) ^ isMinFunc) {
+ if ((in[i] > *out) ^ isMinFunc) {
*out = in[i];
}
break;
}
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;
- if((in[i] > *out) ^ isMinFunc) {
+ if ((in[i] > *out) ^ isMinFunc) {
*out = in[i];
}
break;
}
case TSDB_DATA_TYPE_FLOAT: {
- float *in = (float *)pInputData->pData;
+ float *in = (float *)pInputData->pData;
float *out = (float *)pOutputData->pData;
- if((in[i] > *out) ^ isMinFunc) {
+ if ((in[i] > *out) ^ isMinFunc) {
*out = in[i];
}
break;
}
case TSDB_DATA_TYPE_DOUBLE: {
- double *in = (double *)pInputData->pData;
+ double *in = (double *)pInputData->pData;
double *out = (double *)pOutputData->pData;
- if((in[i] > *out) ^ isMinFunc) {
+ if ((in[i] > *out) ^ isMinFunc) {
*out = in[i];
}
break;
@@ -1915,12 +1906,12 @@ int32_t maxScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *
}
int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput);
int64_t count = 0;
- bool hasNull = false;
+ bool hasNull = false;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) {
@@ -1928,72 +1919,72 @@ int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *
break;
}
- switch(type) {
+ switch (type) {
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;
*out += in[i];
count++;
break;
}
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;
*out += in[i];
count++;
break;
}
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;
*out += in[i];
count++;
break;
}
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;
*out += in[i];
count++;
break;
}
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;
*out += in[i];
count++;
break;
}
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;
*out += in[i];
count++;
break;
}
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;
*out += in[i];
count++;
break;
}
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;
*out += in[i];
count++;
break;
}
case TSDB_DATA_TYPE_FLOAT: {
- float *in = (float *)pInputData->pData;
+ float *in = (float *)pInputData->pData;
float *out = (float *)pOutputData->pData;
*out += in[i];
count++;
break;
}
case TSDB_DATA_TYPE_DOUBLE: {
- double *in = (double *)pInputData->pData;
+ double *in = (double *)pInputData->pData;
double *out = (double *)pOutputData->pData;
*out += in[i];
count++;
@@ -2006,13 +1997,13 @@ int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *
colDataAppendNULL(pOutputData, 0);
} else {
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;
} 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;
} else if (IS_FLOAT_TYPE(type)) {
- double *out = (double *)pOutputData->pData;
+ double *out = (double *)pOutputData->pData;
*(double *)out = *out / (double)count;
}
}
@@ -2022,11 +2013,11 @@ int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *
}
int32_t stddevScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
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;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
@@ -2110,7 +2101,7 @@ int32_t stddevScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
#endif
}
- double *out = (double *)pOutputData->pData;
+ double *out = (double *)pOutputData->pData;
if (hasNull) {
colDataAppendNULL(pOutputData, 0);
} else {
@@ -2144,7 +2135,7 @@ int32_t stddevScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
} while (0)
int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
double startVal, stepVal;
@@ -2155,9 +2146,9 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
int32_t type = GET_PARAM_TYPE(pInput);
int64_t count = 0;
- switch(type) {
+ switch (type) {
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) {
if (colDataIsNull_s(pInputData, i)) {
continue;
@@ -2169,7 +2160,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
break;
}
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) {
if (colDataIsNull_s(pInputData, i)) {
continue;
@@ -2181,7 +2172,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
break;
}
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) {
if (colDataIsNull_s(pInputData, i)) {
continue;
@@ -2193,7 +2184,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
break;
}
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) {
if (colDataIsNull_s(pInputData, i)) {
continue;
@@ -2205,7 +2196,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
break;
}
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) {
if (colDataIsNull_s(pInputData, i)) {
continue;
@@ -2217,7 +2208,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
break;
}
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) {
if (colDataIsNull_s(pInputData, i)) {
continue;
@@ -2229,7 +2220,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
break;
}
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) {
if (colDataIsNull_s(pInputData, i)) {
continue;
@@ -2241,7 +2232,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
break;
}
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) {
if (colDataIsNull_s(pInputData, i)) {
continue;
@@ -2253,7 +2244,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
break;
}
case TSDB_DATA_TYPE_FLOAT: {
- float *in = (float *)pInputData->pData;
+ float *in = (float *)pInputData->pData;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) {
continue;
@@ -2265,7 +2256,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
break;
}
case TSDB_DATA_TYPE_DOUBLE: {
- double *in = (double *)pInputData->pData;
+ double *in = (double *)pInputData->pData;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) {
continue;
@@ -2292,11 +2283,10 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
matrix12 /= matrix[1][1];
char buf[64] = {0};
- size_t len =
- snprintf(varDataVal(buf), sizeof(buf) - VARSTR_HEADER_SIZE, "{slop:%.6lf, intercept:%.6lf}", matrix02, matrix12);
+ size_t len = snprintf(varDataVal(buf), sizeof(buf) - VARSTR_HEADER_SIZE, "{slop:%.6lf, intercept:%.6lf}", matrix02,
+ matrix12);
varDataSetLen(buf, len);
colDataAppend(pOutputData, 0, buf, false);
-
}
pOutput->numOfRows = 1;
@@ -2304,13 +2294,13 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
}
int32_t percentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput);
double val;
- bool hasNull = false;
+ bool hasNull = false;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) {
hasNull = true;
@@ -2335,7 +2325,7 @@ int32_t apercentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScala
}
int32_t spreadScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput);
@@ -2377,11 +2367,11 @@ int32_t spreadScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
}
int32_t nonCalcScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput);
- bool hasNull = false;
+ bool hasNull = false;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) {
@@ -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) {
colDataAppendNULL(pOutputData, 0);
} else {
@@ -2469,7 +2459,7 @@ typedef enum {
} \
} while (0)
-static int8_t getStateOpType(char* opStr) {
+static int8_t getStateOpType(char *opStr) {
int8_t opType;
if (strncasecmp(opStr, "LT", 2) == 0) {
opType = STATE_OPER_LT;
@@ -2490,58 +2480,58 @@ static int8_t getStateOpType(char* opStr) {
return opType;
}
-static bool checkStateOp(int8_t op, SColumnInfoData* pCol, int32_t index, SScalarParam *pCondParam) {
- char* data = colDataGetData(pCol, index);
- char* param = pCondParam->columnData->pData;
+static bool checkStateOp(int8_t op, SColumnInfoData *pCol, int32_t index, SScalarParam *pCondParam) {
+ char *data = colDataGetData(pCol, index);
+ char *param = pCondParam->columnData->pData;
int32_t paramType = GET_PARAM_TYPE(pCondParam);
switch (pCol->info.type) {
case TSDB_DATA_TYPE_TINYINT: {
- int8_t v = *(int8_t*)data;
+ int8_t v = *(int8_t *)data;
STATE_COMP(op, v, param, paramType);
break;
}
case TSDB_DATA_TYPE_UTINYINT: {
- uint8_t v = *(uint8_t*)data;
+ uint8_t v = *(uint8_t *)data;
STATE_COMP(op, v, param, paramType);
break;
}
case TSDB_DATA_TYPE_SMALLINT: {
- int16_t v = *(int16_t*)data;
+ int16_t v = *(int16_t *)data;
STATE_COMP(op, v, param, paramType);
break;
}
case TSDB_DATA_TYPE_USMALLINT: {
- uint16_t v = *(uint16_t*)data;
+ uint16_t v = *(uint16_t *)data;
STATE_COMP(op, v, param, paramType);
break;
}
case TSDB_DATA_TYPE_INT: {
- int32_t v = *(int32_t*)data;
+ int32_t v = *(int32_t *)data;
STATE_COMP(op, v, param, paramType);
break;
}
case TSDB_DATA_TYPE_UINT: {
- uint32_t v = *(uint32_t*)data;
+ uint32_t v = *(uint32_t *)data;
STATE_COMP(op, v, param, paramType);
break;
}
case TSDB_DATA_TYPE_BIGINT: {
- int64_t v = *(int64_t*)data;
+ int64_t v = *(int64_t *)data;
STATE_COMP(op, v, param, paramType);
break;
}
case TSDB_DATA_TYPE_UBIGINT: {
- uint64_t v = *(uint64_t*)data;
+ uint64_t v = *(uint64_t *)data;
STATE_COMP(op, v, param, paramType);
break;
}
case TSDB_DATA_TYPE_FLOAT: {
- float v = *(float*)data;
+ float v = *(float *)data;
STATE_COMP(op, v, param, paramType);
break;
}
case TSDB_DATA_TYPE_DOUBLE: {
- double v = *(double*)data;
+ double v = *(double *)data;
STATE_COMP(op, v, param, paramType);
break;
}
@@ -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) {
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->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;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
@@ -2565,14 +2555,14 @@ int32_t stateCountScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalar
continue;
}
- bool ret = checkStateOp(op, pInputData, i, &pInput[2]);
+ bool ret = checkStateOp(op, pInputData, i, &pInput[2]);
int64_t out = -1;
if (ret) {
out = ++count;
} else {
count = 0;
}
- colDataAppend(pOutputData, i, (char*)&out, false);
+ colDataAppend(pOutputData, i, (char *)&out, false);
}
pOutput->numOfRows = pInput->numOfRows;
@@ -2580,7 +2570,7 @@ int32_t stateCountScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalar
}
int32_t stateDurationScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
int8_t op = getStateOpType(varDataVal(pInput[1].columnData->pData));
@@ -2591,12 +2581,12 @@ int32_t stateDurationScalarFunction(SScalarParam *pInput, int32_t inputNum, SSca
continue;
}
- bool ret = checkStateOp(op, pInputData, i, &pInput[2]);
+ bool ret = checkStateOp(op, pInputData, i, &pInput[2]);
int64_t out = -1;
if (ret) {
out = 0;
}
- colDataAppend(pOutputData, i, (char*)&out, false);
+ colDataAppend(pOutputData, i, (char *)&out, false);
}
pOutput->numOfRows = pInput->numOfRows;
@@ -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;
-static int8_t getHistogramBinType(char* binTypeStr) {
+static int8_t getHistogramBinType(char *binTypeStr) {
int8_t binType;
if (strcasecmp(binTypeStr, "user_input") == 0) {
binType = USER_INPUT_BIN;
@@ -2627,10 +2617,11 @@ typedef struct SHistoFuncBin {
double percentage;
} SHistoFuncBin;
-static bool getHistogramBinDesc(SHistoFuncBin** bins, int32_t* binNum, char* binDescStr, int8_t binType, bool normalized) {
- cJSON* binDesc = cJSON_Parse(binDescStr);
+static bool getHistogramBinDesc(SHistoFuncBin **bins, int32_t *binNum, char *binDescStr, int8_t binType,
+ bool normalized) {
+ cJSON *binDesc = cJSON_Parse(binDescStr);
int32_t numOfBins;
- double* intervals;
+ double *intervals;
if (cJSON_IsObject(binDesc)) { /* linaer/log bins */
int32_t numOfParams = cJSON_GetArraySize(binDesc);
int32_t startIndex;
@@ -2638,11 +2629,11 @@ static bool getHistogramBinDesc(SHistoFuncBin** bins, int32_t* binNum, char* bin
return false;
}
- cJSON* start = cJSON_GetObjectItem(binDesc, "start");
- cJSON* factor = cJSON_GetObjectItem(binDesc, "factor");
- cJSON* width = cJSON_GetObjectItem(binDesc, "width");
- cJSON* count = cJSON_GetObjectItem(binDesc, "count");
- cJSON* infinity = cJSON_GetObjectItem(binDesc, "infinity");
+ cJSON *start = cJSON_GetObjectItem(binDesc, "start");
+ cJSON *factor = cJSON_GetObjectItem(binDesc, "factor");
+ cJSON *width = cJSON_GetObjectItem(binDesc, "width");
+ cJSON *count = cJSON_GetObjectItem(binDesc, "count");
+ cJSON *infinity = cJSON_GetObjectItem(binDesc, "infinity");
if (!cJSON_IsNumber(start) || !cJSON_IsNumber(count) || !cJSON_IsBool(infinity)) {
return false;
@@ -2719,7 +2710,7 @@ static bool getHistogramBinDesc(SHistoFuncBin** bins, int32_t* binNum, char* bin
}
numOfBins = cJSON_GetArraySize(binDesc);
intervals = taosMemoryCalloc(numOfBins, sizeof(double));
- cJSON* bin = binDesc->child;
+ cJSON *bin = binDesc->child;
if (bin == NULL) {
taosMemoryFree(intervals);
return false;
@@ -2756,15 +2747,15 @@ static bool getHistogramBinDesc(SHistoFuncBin** bins, int32_t* binNum, char* bin
}
int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
SHistoFuncBin *bins;
- int32_t numOfBins = 0;
- int32_t totalCount = 0;
+ int32_t numOfBins = 0;
+ int32_t totalCount = 0;
- int8_t binType = getHistogramBinType(varDataVal(pInput[1].columnData->pData));
- char* binDesc = varDataVal(pInput[2].columnData->pData);
+ int8_t binType = getHistogramBinType(varDataVal(pInput[1].columnData->pData));
+ char *binDesc = varDataVal(pInput[2].columnData->pData);
int64_t normalized = *(int64_t *)(pInput[3].columnData->pData);
int32_t type = GET_PARAM_TYPE(pInput);
@@ -2777,7 +2768,7 @@ int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
continue;
}
- char* data = colDataGetData(pInputData, i);
+ char *data = colDataGetData(pInputData, i);
double v;
GET_TYPED_DATA(v, double, type, data);
@@ -2804,11 +2795,11 @@ int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
int32_t len;
char buf[512] = {0};
if (!normalized) {
- len = sprintf(varDataVal(buf), "{\"lower_bin\":%g, \"upper_bin\":%g, \"count\":%" PRId64 "}",
- bins[k].lower, bins[k].upper, bins[k].count);
+ len = sprintf(varDataVal(buf), "{\"lower_bin\":%g, \"upper_bin\":%g, \"count\":%" PRId64 "}", bins[k].lower,
+ bins[k].upper, bins[k].count);
} else {
- len = sprintf(varDataVal(buf), "{\"lower_bin\":%g, \"upper_bin\":%g, \"count\":%lf}",
- bins[k].lower, bins[k].upper, bins[k].percentage);
+ len = sprintf(varDataVal(buf), "{\"lower_bin\":%g, \"upper_bin\":%g, \"count\":%lf}", bins[k].lower,
+ bins[k].upper, bins[k].percentage);
}
varDataSetLen(buf, len);
colDataAppend(pOutputData, k, buf, false);
@@ -2820,7 +2811,7 @@ int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
}
int32_t selectScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
- SColumnInfoData *pInputData = pInput->columnData;
+ SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput);
@@ -2831,11 +2822,10 @@ int32_t selectScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
continue;
}
- char* data = colDataGetData(pInputData, i);
+ char *data = colDataGetData(pInputData, i);
colDataAppend(pOutputData, i, data, false);
}
-
pOutput->numOfRows = 1;
return TSDB_CODE_SUCCESS;
}
diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c
index 339b18bc06e20f5e42b75927c01429dbc32b06b3..e83fe7ecd06adbb2f9ca022a72c603087b4771a3 100644
--- a/source/libs/scalar/src/sclvector.c
+++ b/source/libs/scalar/src/sclvector.c
@@ -24,19 +24,20 @@
#include "tcompare.h"
#include "tdatablock.h"
#include "tdataformat.h"
-#include "ttypes.h"
#include "ttime.h"
+#include "ttypes.h"
-#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 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 IS_NULL colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(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_NULL \
+ colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(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) {
case TSDB_DATA_TYPE_BOOL: {
GET_TYPED_DATA(*((bool *)outData), bool, inType, inData);
@@ -83,15 +84,15 @@ void convertNumberToNumber(const void *inData, void *outData, int8_t inType, int
GET_TYPED_DATA(*((double *)outData), double, inType, inData);
break;
}
- default:{
+ default: {
ASSERT(0);
}
}
}
-void convertNcharToDouble(const void *inData, void *outData){
+void convertNcharToDouble(const void *inData, void *outData) {
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) {
sclError("castConvert taosUcs4ToMbs error 1");
}
@@ -104,9 +105,9 @@ void convertNcharToDouble(const void *inData, void *outData){
taosMemoryFreeClear(tmp);
}
-void convertBinaryToDouble(const void *inData, void *outData){
+void convertBinaryToDouble(const void *inData, void *outData) {
char *tmp = taosMemoryCalloc(1, varDataTLen(inData));
- if(tmp == NULL){
+ if (tmp == NULL) {
*((double *)outData) = 0.;
return;
}
@@ -118,165 +119,119 @@ void convertBinaryToDouble(const void *inData, void *outData){
typedef int64_t (*_getBigintValue_fn_t)(void *src, int32_t index);
-int64_t getVectorBigintValue_TINYINT(void *src, int32_t 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_USMALLINT(void *src, int32_t index) {
- return (int64_t)*((uint16_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_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);
+int64_t getVectorBigintValue_TINYINT(void *src, int32_t 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_USMALLINT(void *src, int32_t index) { return (int64_t) * ((uint16_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_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;
- if (*data == TSDB_DATA_TYPE_NULL){
+ if (*data == TSDB_DATA_TYPE_NULL) {
return 0;
- } else if(*data == TSDB_DATA_TYPE_NCHAR) { // json inner type can not be BINARY
- convertNcharToDouble(data+CHAR_BYTES, &out);
- } else if(tTagIsJson(data)){
+ } else if (*data == TSDB_DATA_TYPE_NCHAR) { // json inner type can not be BINARY
+ convertNcharToDouble(data + CHAR_BYTES, &out);
+ } else if (tTagIsJson(data)) {
terrno = TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR;
return 0;
} 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;
}
_getBigintValue_fn_t getVectorBigintValueFn(int32_t srcType) {
- _getBigintValue_fn_t p = NULL;
- if (srcType==TSDB_DATA_TYPE_TINYINT) {
- p = getVectorBigintValue_TINYINT;
- } else if (srcType==TSDB_DATA_TYPE_UTINYINT) {
- p = getVectorBigintValue_UTINYINT;
- } else if (srcType==TSDB_DATA_TYPE_SMALLINT) {
- p = getVectorBigintValue_SMALLINT;
- } else if (srcType==TSDB_DATA_TYPE_USMALLINT) {
- p = getVectorBigintValue_USMALLINT;
- } else if (srcType==TSDB_DATA_TYPE_INT) {
- p = getVectorBigintValue_INT;
- } else if (srcType==TSDB_DATA_TYPE_UINT) {
- p = getVectorBigintValue_UINT;
- } else if (srcType==TSDB_DATA_TYPE_BIGINT) {
- p = getVectorBigintValue_BIGINT;
- } else if (srcType==TSDB_DATA_TYPE_UBIGINT) {
- p = getVectorBigintValue_UBIGINT;
- } else if (srcType==TSDB_DATA_TYPE_FLOAT) {
- p = getVectorBigintValue_FLOAT;
- } else if (srcType==TSDB_DATA_TYPE_DOUBLE) {
- p = getVectorBigintValue_DOUBLE;
- } else if (srcType==TSDB_DATA_TYPE_TIMESTAMP) {
- p = getVectorBigintValue_BIGINT;
- } else if (srcType==TSDB_DATA_TYPE_BOOL) {
- p = getVectorBigintValue_BOOL;
- } else if (srcType==TSDB_DATA_TYPE_JSON) {
- p = getVectorBigintValue_JSON;
- } else if (srcType==TSDB_DATA_TYPE_NULL){
- p = NULL;
- } else {
- ASSERT(0);
- }
- return p;
+ _getBigintValue_fn_t p = NULL;
+ if (srcType == TSDB_DATA_TYPE_TINYINT) {
+ p = getVectorBigintValue_TINYINT;
+ } else if (srcType == TSDB_DATA_TYPE_UTINYINT) {
+ p = getVectorBigintValue_UTINYINT;
+ } else if (srcType == TSDB_DATA_TYPE_SMALLINT) {
+ p = getVectorBigintValue_SMALLINT;
+ } else if (srcType == TSDB_DATA_TYPE_USMALLINT) {
+ p = getVectorBigintValue_USMALLINT;
+ } else if (srcType == TSDB_DATA_TYPE_INT) {
+ p = getVectorBigintValue_INT;
+ } else if (srcType == TSDB_DATA_TYPE_UINT) {
+ p = getVectorBigintValue_UINT;
+ } else if (srcType == TSDB_DATA_TYPE_BIGINT) {
+ p = getVectorBigintValue_BIGINT;
+ } else if (srcType == TSDB_DATA_TYPE_UBIGINT) {
+ p = getVectorBigintValue_UBIGINT;
+ } else if (srcType == TSDB_DATA_TYPE_FLOAT) {
+ p = getVectorBigintValue_FLOAT;
+ } else if (srcType == TSDB_DATA_TYPE_DOUBLE) {
+ p = getVectorBigintValue_DOUBLE;
+ } else if (srcType == TSDB_DATA_TYPE_TIMESTAMP) {
+ p = getVectorBigintValue_BIGINT;
+ } else if (srcType == TSDB_DATA_TYPE_BOOL) {
+ p = getVectorBigintValue_BOOL;
+ } else if (srcType == TSDB_DATA_TYPE_JSON) {
+ p = getVectorBigintValue_JSON;
+ } else if (srcType == TSDB_DATA_TYPE_NULL) {
+ p = NULL;
+ } else {
+ ASSERT(0);
+ }
+ 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) {
- 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_USMALLINT(void *src, int32_t index) {
- return (void*)((uint16_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_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);
-}
+void *getVectorValueAddr_TINYINT(void *src, int32_t 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_USMALLINT(void *src, int32_t index) { return (void *)((uint16_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_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 p = NULL;
- if(srcType==TSDB_DATA_TYPE_TINYINT) {
- p = getVectorValueAddr_TINYINT;
- }else if(srcType==TSDB_DATA_TYPE_UTINYINT) {
- p = getVectorValueAddr_UTINYINT;
- }else if(srcType==TSDB_DATA_TYPE_SMALLINT) {
- p = getVectorValueAddr_SMALLINT;
- }else if(srcType==TSDB_DATA_TYPE_USMALLINT) {
- p = getVectorValueAddr_USMALLINT;
- }else if(srcType==TSDB_DATA_TYPE_INT) {
- p = getVectorValueAddr_INT;
- }else if(srcType==TSDB_DATA_TYPE_UINT) {
- p = getVectorValueAddr_UINT;
- }else if(srcType==TSDB_DATA_TYPE_BIGINT) {
- p = getVectorValueAddr_BIGINT;
- }else if(srcType==TSDB_DATA_TYPE_UBIGINT) {
- p = getVectorValueAddr_UBIGINT;
- }else if(srcType==TSDB_DATA_TYPE_FLOAT) {
- p = getVectorValueAddr_FLOAT;
- }else if(srcType==TSDB_DATA_TYPE_DOUBLE) {
- p = getVectorValueAddr_DOUBLE;
- }else if(srcType==TSDB_DATA_TYPE_BINARY) {
- p = getVectorValueAddr_VAR;
- }else if(srcType==TSDB_DATA_TYPE_NCHAR) {
- p = getVectorValueAddr_VAR;
- }else {
- p = getVectorValueAddr_default;
- }
- return p;
-}
-
-static FORCE_INLINE void varToTimestamp(char *buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) {
+ _getValueAddr_fn_t p = NULL;
+ if (srcType == TSDB_DATA_TYPE_TINYINT) {
+ p = getVectorValueAddr_TINYINT;
+ } else if (srcType == TSDB_DATA_TYPE_UTINYINT) {
+ p = getVectorValueAddr_UTINYINT;
+ } else if (srcType == TSDB_DATA_TYPE_SMALLINT) {
+ p = getVectorValueAddr_SMALLINT;
+ } else if (srcType == TSDB_DATA_TYPE_USMALLINT) {
+ p = getVectorValueAddr_USMALLINT;
+ } else if (srcType == TSDB_DATA_TYPE_INT) {
+ p = getVectorValueAddr_INT;
+ } else if (srcType == TSDB_DATA_TYPE_UINT) {
+ p = getVectorValueAddr_UINT;
+ } else if (srcType == TSDB_DATA_TYPE_BIGINT) {
+ p = getVectorValueAddr_BIGINT;
+ } else if (srcType == TSDB_DATA_TYPE_UBIGINT) {
+ p = getVectorValueAddr_UBIGINT;
+ } else if (srcType == TSDB_DATA_TYPE_FLOAT) {
+ p = getVectorValueAddr_FLOAT;
+ } else if (srcType == TSDB_DATA_TYPE_DOUBLE) {
+ p = getVectorValueAddr_DOUBLE;
+ } else if (srcType == TSDB_DATA_TYPE_BINARY) {
+ p = getVectorValueAddr_VAR;
+ } else if (srcType == TSDB_DATA_TYPE_NCHAR) {
+ p = getVectorValueAddr_VAR;
+ } else {
+ p = getVectorValueAddr_default;
+ }
+ return p;
+}
+
+static FORCE_INLINE void varToTimestamp(char *buf, SScalarParam *pOut, int32_t rowIndex, int32_t *overflow) {
int64_t value = 0;
if (taosParseTime(buf, &value, strlen(buf), pOut->columnData->info.precision, tsDaylight) != TSDB_CODE_SUCCESS) {
value = 0;
@@ -285,7 +240,7 @@ static FORCE_INLINE void varToTimestamp(char *buf, SScalarParam* pOut, int32_t r
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) {
int64_t minValue = tDataTypes[pOut->columnData->info.type].minValue;
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
case TSDB_DATA_TYPE_TINYINT: {
int8_t value = (int8_t)taosStr2Int8(buf, NULL, 10);
- colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*)&value);
+ colDataAppendInt8(pOut->columnData, rowIndex, (int8_t *)&value);
break;
}
case TSDB_DATA_TYPE_SMALLINT: {
int16_t value = (int16_t)taosStr2Int16(buf, NULL, 10);
- colDataAppendInt16(pOut->columnData, rowIndex, (int16_t*)&value);
+ colDataAppendInt16(pOut->columnData, rowIndex, (int16_t *)&value);
break;
}
case TSDB_DATA_TYPE_INT: {
int32_t value = (int32_t)taosStr2Int32(buf, NULL, 10);
- colDataAppendInt32(pOut->columnData, rowIndex, (int32_t*)&value);
+ colDataAppendInt32(pOut->columnData, rowIndex, (int32_t *)&value);
break;
}
case TSDB_DATA_TYPE_BIGINT: {
int64_t value = (int64_t)taosStr2Int64(buf, NULL, 10);
- colDataAppendInt64(pOut->columnData, rowIndex, (int64_t*)&value);
+ colDataAppendInt64(pOut->columnData, rowIndex, (int64_t *)&value);
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) {
uint64_t minValue = (uint64_t)tDataTypes[pOut->columnData->info.type].minValue;
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
switch (pOut->columnData->info.type) {
case TSDB_DATA_TYPE_UTINYINT: {
uint8_t value = (uint8_t)taosStr2UInt8(buf, NULL, 10);
- colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*)&value);
+ colDataAppendInt8(pOut->columnData, rowIndex, (int8_t *)&value);
break;
}
case TSDB_DATA_TYPE_USMALLINT: {
uint16_t value = (uint16_t)taosStr2UInt16(buf, NULL, 10);
- colDataAppendInt16(pOut->columnData, rowIndex, (int16_t*)&value);
+ colDataAppendInt16(pOut->columnData, rowIndex, (int16_t *)&value);
break;
}
case TSDB_DATA_TYPE_UINT: {
uint32_t value = (uint32_t)taosStr2UInt32(buf, NULL, 10);
- colDataAppendInt32(pOut->columnData, rowIndex, (int32_t*)&value);
+ colDataAppendInt32(pOut->columnData, rowIndex, (int32_t *)&value);
break;
}
case TSDB_DATA_TYPE_UBIGINT: {
uint64_t value = (uint64_t)taosStr2UInt64(buf, NULL, 10);
- colDataAppendInt64(pOut->columnData, rowIndex, (int64_t*)&value);
+ colDataAppendInt64(pOut->columnData, rowIndex, (int64_t *)&value);
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) {
float value = taosStr2Float(buf, NULL);
colDataAppendFloat(pOut->columnData, rowIndex, &value);
@@ -377,30 +332,31 @@ static FORCE_INLINE void varToFloat(char *buf, SScalarParam* pOut, int32_t rowIn
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);
- bool v = (value != 0)? true:false;
- colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*) &v);
+ bool v = (value != 0) ? true : false;
+ 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 inputLen = varDataLen(buf);
int32_t outputMaxLen = (inputLen + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
- char* t = taosMemoryCalloc(1, outputMaxLen);
- /*int32_t resLen = */taosMbsToUcs4(varDataVal(buf), inputLen, (TdUcs4*) varDataVal(t), outputMaxLen - VARSTR_HEADER_SIZE, &len);
+ char *t = taosMemoryCalloc(1, outputMaxLen);
+ /*int32_t resLen = */ taosMbsToUcs4(varDataVal(buf), inputLen, (TdUcs4 *)varDataVal(t),
+ outputMaxLen - VARSTR_HEADER_SIZE, &len);
varDataSetLen(t, len);
colDataAppend(pOut->columnData, rowIndex, t, false);
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);
- char* t = taosMemoryCalloc(1, inputLen + VARSTR_HEADER_SIZE);
- int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(buf), varDataLen(buf), varDataVal(t));
+ char *t = taosMemoryCalloc(1, inputLen + VARSTR_HEADER_SIZE);
+ int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(buf), varDataLen(buf), varDataVal(t));
if (len < 0) {
taosMemoryFree(t);
return;
@@ -411,9 +367,9 @@ static FORCE_INLINE void ncharToVar(char* buf, SScalarParam* pOut, int32_t rowIn
taosMemoryFree(t);
}
-
-//TODO opt performance, tmp is not needed.
-int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, int32_t inType, int32_t outType, int32_t* overflow) {
+// TODO opt performance, tmp is not needed.
+int32_t vectorConvertFromVarData(const SScalarParam *pIn, SScalarParam *pOut, int32_t inType, int32_t outType,
+ int32_t *overflow) {
bool vton = false;
_bufConverteFunc func = NULL;
@@ -425,11 +381,11 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in
func = varToUnsigned;
} else if (IS_FLOAT_TYPE(outType)) {
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);
func = ncharToVar;
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);
func = varToNchar;
vton = true;
@@ -447,25 +403,25 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in
continue;
}
- char* data = colDataGetVarData(pIn->columnData, i);
+ char *data = colDataGetVarData(pIn->columnData, i);
int32_t convertType = inType;
- if(inType == TSDB_DATA_TYPE_JSON){
- if(*data == TSDB_DATA_TYPE_NULL) {
+ if (inType == TSDB_DATA_TYPE_JSON) {
+ if (*data == TSDB_DATA_TYPE_NULL) {
ASSERT(0);
- } else if(*data == TSDB_DATA_TYPE_NCHAR) {
+ } else if (*data == TSDB_DATA_TYPE_NCHAR) {
data += CHAR_BYTES;
convertType = TSDB_DATA_TYPE_NCHAR;
- } else if(tTagIsJson(data)){
+ } else if (tTagIsJson(data)) {
terrno = TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR;
return terrno;
} else {
- convertNumberToNumber(data+CHAR_BYTES, colDataGetNumData(pOut->columnData, i), *data, outType);
+ convertNumberToNumber(data + CHAR_BYTES, colDataGetNumData(pOut->columnData, i), *data, outType);
continue;
}
}
int32_t bufSize = pIn->columnData->info.bytes;
- char *tmp = taosMemoryMalloc(varDataTLen(data));
- if(!tmp){
+ char *tmp = taosMemoryMalloc(varDataTLen(data));
+ if (!tmp) {
sclError("out of memory in vectorConvertFromVarData");
return TSDB_CODE_OUT_OF_MEMORY;
}
@@ -475,7 +431,7 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in
if (TSDB_DATA_TYPE_VARCHAR == convertType) {
memcpy(tmp, varDataVal(data), varDataLen(data));
tmp[varDataLen(data)] = 0;
- } else if (TSDB_DATA_TYPE_NCHAR == convertType){
+ } else if (TSDB_DATA_TYPE_NCHAR == convertType) {
ASSERT(varDataLen(data) <= bufSize);
int len = taosUcs4ToMbs((TdUcs4 *)varDataVal(data), varDataLen(data), tmp);
@@ -496,30 +452,30 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in
return TSDB_CODE_SUCCESS;
}
-double getVectorDoubleValue_JSON(void *src, int32_t index){
- char *data = colDataGetVarData((SColumnInfoData*)src, index);
+double getVectorDoubleValue_JSON(void *src, int32_t index) {
+ char *data = colDataGetVarData((SColumnInfoData *)src, index);
double out = 0;
- if (*data == TSDB_DATA_TYPE_NULL){
+ if (*data == TSDB_DATA_TYPE_NULL) {
return out;
- } else if(*data == TSDB_DATA_TYPE_NCHAR) { // json inner type can not be BINARY
- convertNcharToDouble(data+CHAR_BYTES, &out);
- } else if(tTagIsJson(data)){
+ } else if (*data == TSDB_DATA_TYPE_NCHAR) { // json inner type can not be BINARY
+ convertNcharToDouble(data + CHAR_BYTES, &out);
+ } else if (tTagIsJson(data)) {
terrno = TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR;
return 0;
- } else{
- convertNumberToNumber(data+CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE);
+ } else {
+ convertNumberToNumber(data + CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE);
}
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);
- void* t = taosMemoryCalloc(1, inputLen);
- int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(buf), varDataLen(buf), varDataVal(t));
+ void *t = taosMemoryCalloc(1, inputLen);
+ int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(buf), varDataLen(buf), varDataVal(t));
if (len < 0) {
sclError("charset:%s to %s. val:%s convert ncharTobinary failed.", DEFAULT_UNICODE_ENCODEC, tsCharset,
- (char*)varDataVal(buf));
+ (char *)varDataVal(buf));
taosMemoryFree(t);
return NULL;
}
@@ -527,8 +483,9 @@ void* ncharTobinary(void *buf){ // todo need to remove , if tobinary
return t;
}
-bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t typeRight, char **pLeftData, char **pRightData,
- void *pLeftOut, void *pRightOut, bool *isNull, bool *freeLeft, bool *freeRight){
+bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t typeRight, char **pLeftData,
+ char **pRightData, void *pLeftOut, void *pRightOut, bool *isNull, bool *freeLeft,
+ bool *freeRight) {
if (optr == OP_TYPE_JSON_CONTAINS) {
return true;
}
@@ -543,7 +500,7 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t
return false;
}
typeLeft = **pLeftData;
- (*pLeftData) ++;
+ (*pLeftData)++;
}
if (typeRight == TSDB_DATA_TYPE_JSON) {
if (tTagIsJson(*pLeftData)) {
@@ -551,7 +508,7 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t
return false;
}
typeRight = **pRightData;
- (*pRightData) ++;
+ (*pRightData)++;
}
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
((typeRight == TSDB_DATA_TYPE_BOOL) && (typeLeft != TSDB_DATA_TYPE_BOOL)))
return false;
-
if (typeLeft == TSDB_DATA_TYPE_NULL || typeRight == TSDB_DATA_TYPE_NULL) {
*isNull = true;
return true;
@@ -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 (typeLeft == TSDB_DATA_TYPE_NCHAR) {
ASSERT(0);
-// convertNcharToDouble(*pLeftData, pLeftOut);
-// *pLeftData = pLeftOut;
+ // convertNcharToDouble(*pLeftData, pLeftOut);
+ // *pLeftData = pLeftOut;
} else if (typeLeft == TSDB_DATA_TYPE_BINARY) {
ASSERT(0);
-// convertBinaryToDouble(*pLeftData, pLeftOut);
-// *pLeftData = pLeftOut;
+ // convertBinaryToDouble(*pLeftData, pLeftOut);
+ // *pLeftData = pLeftOut;
} else if (typeLeft != type) {
convertNumberToNumber(*pLeftData, pLeftOut, typeLeft, type);
*pLeftData = pLeftOut;
@@ -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) {
ASSERT(0);
-// convertNcharToDouble(*pRightData, pRightOut);
-// *pRightData = pRightOut;
+ // convertNcharToDouble(*pRightData, pRightOut);
+ // *pRightData = pRightOut;
} else if (typeRight == TSDB_DATA_TYPE_BINARY) {
ASSERT(0);
-// convertBinaryToDouble(*pRightData, pRightOut);
-// *pRightData = pRightOut;
+ // convertBinaryToDouble(*pRightData, pRightOut);
+ // *pRightData = pRightOut;
} else if (typeRight != type) {
convertNumberToNumber(*pRightData, pRightOut, typeRight, type);
*pRightData = pRightOut;
@@ -625,10 +581,10 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t
return true;
}
-int32_t vectorConvertToVarData(const SScalarParam* pIn, SScalarParam* pOut, int16_t inType, int16_t outType) {
- SColumnInfoData* pInputCol = pIn->columnData;
- SColumnInfoData* pOutputCol = pOut->columnData;
- char tmp[128] = {0};
+int32_t vectorConvertToVarData(const SScalarParam *pIn, SScalarParam *pOut, int16_t inType, int16_t outType) {
+ SColumnInfoData *pInputCol = pIn->columnData;
+ SColumnInfoData *pOutputCol = pOut->columnData;
+ char tmp[128] = {0};
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) {
@@ -690,17 +646,17 @@ int32_t vectorConvertToVarData(const SScalarParam* pIn, SScalarParam* pOut, int1
}
// TODO opt performance
-int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t* overflow) {
- SColumnInfoData* pInputCol = pIn->columnData;
- SColumnInfoData* pOutputCol = pOut->columnData;
+int32_t vectorConvertImpl(const SScalarParam *pIn, SScalarParam *pOut, int32_t *overflow) {
+ SColumnInfoData *pInputCol = pIn->columnData;
+ SColumnInfoData *pOutputCol = pOut->columnData;
if (NULL == pInputCol) {
sclError("input column is NULL, hashFilter %p", pIn->pHashFilter);
return TSDB_CODE_APP_ERROR;
}
- int16_t inType = pInputCol->info.type;
- int16_t outType = pOutputCol->info.type;
+ int16_t inType = pInputCol->info.type;
+ int16_t outType = pOutputCol->info.type;
if (IS_VAR_DATA_TYPE(inType)) {
return vectorConvertFromVarData(pIn, pOut, inType, outType, overflow);
@@ -774,7 +730,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
}
break;
}
- case TSDB_DATA_TYPE_SMALLINT:{
+ case TSDB_DATA_TYPE_SMALLINT: {
for (int32_t i = 0; i < pIn->numOfRows; ++i) {
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
colDataAppendNULL(pOutputCol, i);
@@ -787,7 +743,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
}
break;
}
- case TSDB_DATA_TYPE_INT:{
+ case TSDB_DATA_TYPE_INT: {
for (int32_t i = 0; i < pIn->numOfRows; ++i) {
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
colDataAppendNULL(pOutputCol, i);
@@ -814,7 +770,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
}
break;
}
- case TSDB_DATA_TYPE_UTINYINT:{
+ case TSDB_DATA_TYPE_UTINYINT: {
for (int32_t i = 0; i < pIn->numOfRows; ++i) {
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
colDataAppendNULL(pOutputCol, i);
@@ -827,7 +783,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
}
break;
}
- case TSDB_DATA_TYPE_USMALLINT:{
+ case TSDB_DATA_TYPE_USMALLINT: {
for (int32_t i = 0; i < pIn->numOfRows; ++i) {
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
colDataAppendNULL(pOutputCol, i);
@@ -840,7 +796,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
}
break;
}
- case TSDB_DATA_TYPE_UINT:{
+ case TSDB_DATA_TYPE_UINT: {
for (int32_t i = 0; i < pIn->numOfRows; ++i) {
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
colDataAppendNULL(pOutputCol, i);
@@ -862,11 +818,11 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
uint64_t value = 0;
GET_TYPED_DATA(value, uint64_t, inType, colDataGetData(pInputCol, i));
- colDataAppendInt64(pOutputCol, i, (int64_t*)&value);
+ colDataAppendInt64(pOutputCol, i, (int64_t *)&value);
}
break;
}
- case TSDB_DATA_TYPE_FLOAT:{
+ case TSDB_DATA_TYPE_FLOAT: {
for (int32_t i = 0; i < pIn->numOfRows; ++i) {
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
colDataAppendNULL(pOutputCol, i);
@@ -875,7 +831,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
float value = 0;
GET_TYPED_DATA(value, float, inType, colDataGetData(pInputCol, i));
- colDataAppendFloat(pOutputCol, i, (float*)&value);
+ colDataAppendFloat(pOutputCol, i, (float *)&value);
}
break;
}
@@ -888,7 +844,7 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
double value = 0;
GET_TYPED_DATA(value, double, inType, colDataGetData(pInputCol, i));
- colDataAppendDouble(pOutputCol, i, (double*)&value);
+ colDataAppendDouble(pOutputCol, i, (double *)&value);
}
break;
}
@@ -904,30 +860,27 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
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 */
-/*NULL*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/*BOOL*/ 0, 0, 2, 3, 4, 5, 6, 7, 7, 9, 7, 11, 12, 13, 14, 0, 7, 0, 0,
-/*TINY*/ 0, 0, 0, 3, 4, 5, 6, 7, 7, 9, 7, 3, 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,
-/*INT */ 0, 0, 0, 0, 0, 5, 6, 7, 7, 9, 7, 4, 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,
-/*FLOA*/ 0, 0, 0, 0, 0, 0, 0, 7, 7, 6, 7, 6, 6, 6, 6, 0, 7, 0, 0,
-/*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 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,
-/*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 7, 0, 7, 0, 0,
-/*NCHA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0,
-/*UTIN*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 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,
-/*UINT*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
-/*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/*VARB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/*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
-};
+int8_t gConvertTypes[TSDB_DATA_TYPE_BLOB + 1][TSDB_DATA_TYPE_BLOB + 1] = {
+ /* NULL BOOL TINY SMAL INT BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB */
+ /*NULL*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ /*BOOL*/ 0, 0, 2, 3, 4, 5, 6, 7, 7, 9, 7, 11, 12, 13, 14, 0, 7, 0, 0,
+ /*TINY*/ 0, 0, 0, 3, 4, 5, 6, 7, 7, 9, 7, 3, 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,
+ /*INT */ 0, 0, 0, 0, 0, 5, 6, 7, 7, 9, 7, 4, 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,
+ /*FLOA*/ 0, 0, 0, 0, 0, 0, 0, 7, 7, 6, 7, 6, 6, 6, 6, 0, 7, 0, 0,
+ /*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 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,
+ /*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 7, 0, 7, 0, 0,
+ /*NCHA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0,
+ /*UTIN*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 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,
+ /*UINT*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
+ /*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ /*VARB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ /*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) {
if (type1 == type2) {
@@ -952,15 +905,15 @@ int32_t vectorConvertScalarParam(SScalarParam *input, SScalarParam *output, int3
code = vectorConvertImpl(input, output, NULL);
if (code) {
-// taosMemoryFreeClear(paramOut1->data);
+ // taosMemoryFreeClear(paramOut1->data);
return code;
}
return TSDB_CODE_SUCCESS;
}
-int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* pLeftOut, SScalarParam* pRightOut) {
- int32_t leftType = GET_PARAM_TYPE(pLeft);
+int32_t vectorConvert(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pLeftOut, SScalarParam *pRightOut) {
+ int32_t leftType = GET_PARAM_TYPE(pLeft);
int32_t rightType = GET_PARAM_TYPE(pRight);
if (leftType == rightType) {
return TSDB_CODE_SUCCESS;
@@ -968,7 +921,7 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p
SScalarParam *param1 = NULL, *paramOut1 = NULL;
SScalarParam *param2 = NULL, *paramOut2 = NULL;
- int32_t code = 0;
+ int32_t code = 0;
if (leftType < rightType) {
param1 = pLeft;
@@ -1009,14 +962,14 @@ enum {
VECTOR_UN_CONVERT = 0x2,
};
-static int32_t doConvertHelper(SScalarParam* pDest, int32_t* convert, const SScalarParam* pParam, int32_t type) {
- SColumnInfoData* pCol = pParam->columnData;
+static int32_t doConvertHelper(SScalarParam *pDest, int32_t *convert, const SScalarParam *pParam, int32_t type) {
+ SColumnInfoData *pCol = pParam->columnData;
if (IS_VAR_DATA_TYPE(pCol->info.type) && pCol->info.type != TSDB_DATA_TYPE_JSON) {
pDest->numOfRows = pParam->numOfRows;
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) {
return code;
}
@@ -1035,8 +988,9 @@ static int32_t doConvertHelper(SScalarParam* pDest, int32_t* convert, const SSca
}
// 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) {
- _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
+static void vectorMathAddHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol,
+ int32_t numOfRows, int32_t step, int32_t i) {
+ _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
double *output = (double *)pOutputCol->pData;
@@ -1049,14 +1003,14 @@ static void vectorMathAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRig
colDataAppendNULL(pOutputCol, i);
continue; // TODO set null or ignore
}
- *output = getVectorDoubleValueFnLeft(LEFT_COL, i)
- + getVectorDoubleValueFnRight(RIGHT_COL, 0);
+ *output = getVectorDoubleValueFnLeft(LEFT_COL, i) + getVectorDoubleValueFnRight(RIGHT_COL, 0);
}
}
}
-static void vectorMathTsAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) {
- _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
+static void vectorMathTsAddHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol,
+ int32_t numOfRows, int32_t step, int32_t i) {
+ _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
int64_t *output = (int64_t *)pOutputCol->pData;
@@ -1069,13 +1023,14 @@ static void vectorMathTsAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pR
colDataAppendNULL(pOutputCol, i);
continue; // TODO set null or ignore
}
- *output = taosTimeAdd(getVectorBigintValueFnLeft(pLeftCol->pData, i), getVectorBigintValueFnRight(pRightCol->pData, 0),
- pRightCol->info.scale, pRightCol->info.precision);
+ *output =
+ 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};
int32_t code = doConvertHelper(&convertParam, doConvert, pInput, TSDB_DATA_TYPE_DOUBLE);
@@ -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) {
colDataDestroy(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;
- 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 i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
+ int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
- int32_t leftConvert = 0, rightConvert = 0;
- SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
- SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
+ int32_t leftConvert = 0, rightConvert = 0;
+ SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
+ SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
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(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
- int64_t *output = (int64_t *)pOutputCol->pData;
- _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
+ (GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_TIMESTAMP &&
+ GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_BOOL)) { // timestamp plus duration
+ int64_t *output = (int64_t *)pOutputCol->pData;
+ _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
if (pLeft->numOfRows == 1 && pRight->numOfRows == 1) {
@@ -1138,13 +1094,13 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
}
}
} else {
- double *output = (double *)pOutputCol->pData;
- _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
+ double *output = (double *)pOutputCol->pData;
+ _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
if (pLeft->numOfRows == pRight->numOfRows) {
for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
- if (IS_NULL){
+ if (IS_NULL) {
colDataAppendNULL(pOutputCol, i);
continue; // TODO set null or ignore
}
@@ -1162,8 +1118,9 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
}
// 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) {
- _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
+static void vectorMathSubHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol,
+ int32_t numOfRows, int32_t step, int32_t factor, int32_t i) {
+ _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
double *output = (double *)pOutputCol->pData;
@@ -1176,14 +1133,14 @@ static void vectorMathSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRig
colDataAppendNULL(pOutputCol, i);
continue; // TODO set null or ignore
}
- *output = (getVectorDoubleValueFnLeft(LEFT_COL, i)
- - getVectorDoubleValueFnRight(RIGHT_COL, 0)) * factor;
+ *output = (getVectorDoubleValueFnLeft(LEFT_COL, i) - 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) {
- _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
+static void vectorMathTsSubHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol,
+ int32_t numOfRows, int32_t step, int32_t factor, int32_t i) {
+ _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
int64_t *output = (int64_t *)pOutputCol->pData;
@@ -1196,29 +1153,30 @@ static void vectorMathTsSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pR
colDataAppendNULL(pOutputCol, i);
continue; // TODO set null or ignore
}
- *output = taosTimeAdd(getVectorBigintValueFnLeft(pLeftCol->pData, i), -getVectorBigintValueFnRight(pRightCol->pData, 0),
- pRightCol->info.scale, pRightCol->info.precision);
-
+ *output =
+ 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;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
- 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 i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
+ int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
- int32_t leftConvert = 0, rightConvert = 0;
- SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
- SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
+ int32_t leftConvert = 0, rightConvert = 0;
+ SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
+ SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
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
- int64_t *output = (int64_t *)pOutputCol->pData;
- _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
+ (GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_TIMESTAMP &&
+ GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_BIGINT)) { // timestamp minus duration
+ int64_t *output = (int64_t *)pOutputCol->pData;
+ _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
if (pLeft->numOfRows == 1 && pRight->numOfRows == 1) {
@@ -1237,8 +1195,8 @@ void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
}
}
} else {
- double *output = (double *)pOutputCol->pData;
- _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
+ double *output = (double *)pOutputCol->pData;
+ _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
if (pLeft->numOfRows == pRight->numOfRows) {
@@ -1256,13 +1214,14 @@ void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
}
}
- doReleaseVec(pLeftCol, leftConvert);
+ doReleaseVec(pLeftCol, leftConvert);
doReleaseVec(pRightCol, rightConvert);
}
// 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) {
- _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
+static void vectorMathMultiplyHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol,
+ int32_t numOfRows, int32_t step, int32_t i) {
+ _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
double *output = (double *)pOutputCol->pData;
@@ -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;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
- 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 i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
+ int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
- int32_t leftConvert = 0, rightConvert = 0;
- SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
- SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
+ int32_t leftConvert = 0, rightConvert = 0;
+ SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
+ 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);
double *output = (double *)pOutputCol->pData;
@@ -1313,45 +1272,44 @@ void vectorMathMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam
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;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
- 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 i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
+ int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
- int32_t leftConvert = 0, rightConvert = 0;
- SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
+ int32_t leftConvert = 0, rightConvert = 0;
+ SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
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);
double *output = (double *)pOutputCol->pData;
if (pLeft->numOfRows == pRight->numOfRows) {
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);
continue;
}
- *output = getVectorDoubleValueFnLeft(LEFT_COL, i)
- / getVectorDoubleValueFnRight(RIGHT_COL, i);
+ *output = getVectorDoubleValueFnLeft(LEFT_COL, i) / getVectorDoubleValueFnRight(RIGHT_COL, i);
}
} else if (pLeft->numOfRows == 1) {
if (IS_HELPER_NULL(pLeftCol, 0)) { // Set pLeft->numOfRows NULL value
colDataAppendNNULL(pOutputCol, 0, pRight->numOfRows);
} else {
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);
continue;
}
- *output = getVectorDoubleValueFnLeft(LEFT_COL, 0)
- / getVectorDoubleValueFnRight(RIGHT_COL, i);
+ *output = getVectorDoubleValueFnLeft(LEFT_COL, 0) / getVectorDoubleValueFnRight(RIGHT_COL, i);
}
}
} 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);
} else {
for (; i >= 0 && i < pLeft->numOfRows; i += step, output += 1) {
@@ -1359,28 +1317,27 @@ void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *p
colDataAppendNULL(pOutputCol, i);
continue;
}
- *output = getVectorDoubleValueFnLeft(LEFT_COL, i)
- / getVectorDoubleValueFnRight(RIGHT_COL, 0);
+ *output = getVectorDoubleValueFnLeft(LEFT_COL, i) / getVectorDoubleValueFnRight(RIGHT_COL, 0);
}
}
}
- doReleaseVec(pLeftCol, leftConvert);
+ doReleaseVec(pLeftCol, leftConvert);
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;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
- 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 i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
+ int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
- int32_t leftConvert = 0, rightConvert = 0;
- SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
+ int32_t leftConvert = 0, rightConvert = 0;
+ SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
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);
double *output = (double *)pOutputCol->pData;
@@ -1447,18 +1404,18 @@ void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam
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;
pOut->numOfRows = pLeft->numOfRows;
- int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : (pLeft->numOfRows - 1);
- int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1;
+ int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : (pLeft->numOfRows - 1);
+ int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
- int32_t leftConvert = 0;
- SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
+ int32_t leftConvert = 0;
+ 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;
for (; i < pLeft->numOfRows && i >= 0; i += step, output += 1) {
@@ -1470,17 +1427,17 @@ void vectorMathMinus(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO
*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;
pOut->numOfRows = pLeft->numOfRows;
- if(colDataIsNull_s(pRight->columnData, 0)){
+ if (colDataIsNull_s(pRight->columnData, 0)) {
colDataAppendNNULL(pOutputCol, 0, pOut->numOfRows);
} else {
- char* d = colDataGetData(pRight->columnData, 0);
+ char *d = colDataGetData(pRight->columnData, 0);
for (int32_t i = 0; i < pOut->numOfRows; ++i) {
colDataAppend(pOutputCol, i, d, false);
}
@@ -1490,7 +1447,7 @@ void vectorAssign(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
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
int32_t len = pLeft->bytes + pRight->bytes;
@@ -1541,8 +1498,9 @@ void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t
#endif
}
-static void vectorBitAndHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) {
- _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
+static void vectorBitAndHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol,
+ int32_t numOfRows, int32_t step, int32_t i) {
+ _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
int64_t *output = (int64_t *)pOutputCol->pData;
@@ -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;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
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 leftConvert = 0, rightConvert = 0;
- SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
- SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
+ int32_t leftConvert = 0, rightConvert = 0;
+ SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
+ 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);
int64_t *output = (int64_t *)pOutputCol->pData;
@@ -1589,12 +1547,13 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
vectorBitAndHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i);
}
- doReleaseVec(pLeftCol, leftConvert);
+ doReleaseVec(pLeftCol, leftConvert);
doReleaseVec(pRightCol, rightConvert);
}
-static void vectorBitOrHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) {
- _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
+static void vectorBitOrHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol,
+ int32_t numOfRows, int32_t step, int32_t i) {
+ _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
int64_t *output = (int64_t *)pOutputCol->pData;
@@ -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;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
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 leftConvert = 0, rightConvert = 0;
- SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
- SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
+ int32_t leftConvert = 0, rightConvert = 0;
+ SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
+ 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);
int64_t *output = (int64_t *)pOutputCol->pData;
@@ -1642,17 +1601,17 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
vectorBitOrHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i);
}
- doReleaseVec(pLeftCol, leftConvert);
+ doReleaseVec(pLeftCol, leftConvert);
doReleaseVec(pRightCol, rightConvert);
}
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;
for (int32_t i = startIndex; i < numOfRows && i >= 0; i += step) {
- int32_t leftIndex = (i >= pLeft->numOfRows)? 0:i;
- int32_t rightIndex = (i >= pRight->numOfRows)? 0:i;
+ int32_t leftIndex = (i >= pLeft->numOfRows) ? 0 : i;
+ int32_t rightIndex = (i >= pRight->numOfRows) ? 0 : i;
if (IS_HELPER_NULL(pLeft->columnData, leftIndex) || IS_HELPER_NULL(pRight->columnData, rightIndex)) {
bool res = false;
@@ -1660,15 +1619,15 @@ int32_t doVectorCompareImpl(int32_t numOfRows, SScalarParam *pOut, int32_t start
continue;
}
- char * pLeftData = colDataGetData(pLeft->columnData, leftIndex);
- char * pRightData = colDataGetData(pRight->columnData, rightIndex);
+ char *pLeftData = colDataGetData(pLeft->columnData, leftIndex);
+ char *pRightData = colDataGetData(pRight->columnData, rightIndex);
int64_t leftOut = 0;
int64_t rightOut = 0;
bool freeLeft = false;
bool freeRight = 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);
if (isJsonnull) {
ASSERT(0);
@@ -1700,7 +1659,7 @@ int32_t doVectorCompareImpl(int32_t numOfRows, SScalarParam *pOut, int32_t start
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 step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
int32_t lType = GET_PARAM_TYPE(pLeft);
@@ -1718,14 +1677,14 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *
if (pRight->pHashFilter != NULL) {
for (; i >= 0 && i < pLeft->numOfRows; i += step) {
if (IS_HELPER_NULL(pLeft->columnData, i)) {
- bool res = false;
- colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);
+ bool res = false;
+ colDataAppendInt8(pOut->columnData, i, (int8_t *)&res);
continue;
}
char *pLeftData = colDataGetData(pLeft->columnData, i);
bool res = filterDoCompare(fp, optr, pLeftData, pRight->pHashFilter);
- colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);
+ colDataAppendInt8(pOut->columnData, i, (int8_t *)&res);
if (res) {
pOut->numOfQualified++;
}
@@ -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) {
- SScalarParam pLeftOut = {0};
- SScalarParam pRightOut = {0};
+void vectorCompare(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord, int32_t optr) {
+ SScalarParam pLeftOut = {0};
+ SScalarParam pRightOut = {0};
SScalarParam *param1 = NULL;
SScalarParam *param2 = NULL;
@@ -1765,74 +1724,74 @@ void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
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);
}
-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);
}
-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);
}
-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);
}
-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);
}
-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);
}
-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);
}
-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);
}
-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);
}
-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);
}
-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);
}
-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);
}
-void vectorIsNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
- for(int32_t i = 0; i < pLeft->numOfRows; ++i) {
+void vectorIsNull(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
+ for (int32_t i = 0; i < pLeft->numOfRows; ++i) {
int8_t v = IS_HELPER_NULL(pLeft->columnData, i) ? 1 : 0;
colDataAppendInt8(pOut->columnData, i, &v);
}
pOut->numOfRows = pLeft->numOfRows;
}
-void vectorNotNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
- for(int32_t i = 0; i < pLeft->numOfRows; ++i) {
+void vectorNotNull(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) {
+ for (int32_t i = 0; i < pLeft->numOfRows; ++i) {
int8_t v = IS_HELPER_NULL(pLeft->columnData, i) ? 0 : 1;
colDataAppendInt8(pOut->columnData, i, &v);
}
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);
- for(int32_t i = 0; i < pOut->numOfRows; ++i) {
- if(colDataIsNull_s(pOut->columnData, i)) {
+ for (int32_t i = 0; i < pOut->numOfRows; ++i) {
+ if (colDataIsNull_s(pOut->columnData, i)) {
int8_t v = 0;
colDataAppendInt8(pOut->columnData, i, &v);
colDataSetNotNull_f(pOut->columnData->nullbitmap, i);
@@ -1843,26 +1802,26 @@ void vectorIsTrue(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
STagVal getJsonValue(char *json, char *key, bool *isExist) {
STagVal val = {.pKey = key};
- if (tTagIsJson((const STag *)json) == false){
+ if (tTagIsJson((const STag *)json) == false) {
terrno = TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR;
- if(isExist){
+ if (isExist) {
*isExist = false;
}
return val;
}
bool find = tTagGet(((const STag *)json), &val); // json value is null and not exist is different
- if(isExist){
+ if (isExist) {
*isExist = find;
}
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;
- 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 i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
+ int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
@@ -1877,17 +1836,16 @@ void vectorJsonContains(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam
getJsonValue(pLeftData, jsonKey, &isExist);
}
- colDataAppend(pOutputCol, i, (const char*)(&isExist), false);
-
+ colDataAppend(pOutputCol, i, (const char *)(&isExist), false);
}
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;
- 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 i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
+ int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
@@ -1900,12 +1858,12 @@ void vectorJsonArrow(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO
pOutputCol->hasNull = true;
continue;
}
- char *pLeftData = colDataGetVarData(pLeft->columnData, i);
- bool isExist = false;
+ char *pLeftData = colDataGetVarData(pLeft->columnData, i);
+ bool isExist = false;
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);
- if(isExist && IS_VAR_DATA_TYPE(value.type) && data){
+ if (isExist && IS_VAR_DATA_TYPE(value.type) && data) {
taosMemoryFree(data);
}
}
@@ -1971,4 +1929,3 @@ _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) {
return NULL;
}
}
-
diff --git a/source/libs/scalar/test/filter/filterTests.cpp b/source/libs/scalar/test/filter/filterTests.cpp
index bb7745dbd9a7af32e735e8131834d139221af9bd..ca304cd3291643d437083521409b997d327ffb1a 100644
--- a/source/libs/scalar/test/filter/filterTests.cpp
+++ b/source/libs/scalar/test/filter/filterTests.cpp
@@ -32,26 +32,21 @@
#endif
#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 "nodes.h"
#include "scalar.h"
#include "stub.h"
#include "taos.h"
+#include "tdatablock.h"
#include "tdef.h"
+#include "tglobal.h"
#include "tlog.h"
#include "tvariant.h"
namespace {
int64_t flttLeftV = 21, flttRightV = 10;
-double flttLeftVd = 21.0, flttRightVd = 10.0;
+double flttLeftVd = 21.0, flttRightVd = 10.0;
void flttInitLogFile() {
const char *defaultLogFileNamePrefix = "taoslog";
@@ -66,9 +61,8 @@ void flttInitLogFile() {
}
}
-
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;
vnode->node.resType.type = dataType;
@@ -80,19 +74,20 @@ void flttMakeValueNode(SNode **pNode, int32_t dataType, void *value) {
vnode->node.resType.bytes = tDataTypes[dataType].bytes;
assignVal((char *)nodesGetValueFromNode(vnode), (const char *)value, 0, dataType);
}
-
+
*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;
-
- SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_COLUMN);
+
+ SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_COLUMN);
SColumnNode *rnode = (SColumnNode *)node;
rnode->node.resType.type = dataType;
rnode->node.resType.bytes = dataBytes;
rnode->dataBlockId = 0;
-
+
sprintf(rnode->dbName, "%" PRIu64, dbidx++);
if (NULL == block) {
@@ -106,7 +101,7 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in
if (NULL == *block) {
SSDataBlock *res = createDataBlock();
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);
}
@@ -131,9 +126,9 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in
*block = res;
} else {
SSDataBlock *res = *block;
-
- int32_t idx = taosArrayGetSize(res->pDataBlock);
- SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 1+idx);
+
+ int32_t idx = taosArrayGetSize(res->pDataBlock);
+ SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 1 + idx);
blockDataAppendColInfo(res, &idata);
blockDataEnsureCapacity(res, rowNum);
@@ -147,7 +142,7 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in
value = (char *)value + dataBytes;
}
}
-
+
rnode->slotId = idx;
rnode->colId = 1 + idx;
}
@@ -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) {
- SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_OPERATOR);
+ SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_OPERATOR);
SOperatorNode *onode = (SOperatorNode *)node;
onode->node.resType.type = resType;
onode->node.resType.bytes = tDataTypes[resType].bytes;
-
+
onode->opType = opType;
onode->pLeft = pLeft;
onode->pRight = pRight;
@@ -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) {
- SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION);
+ SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION);
SLogicConditionNode *onode = (SLogicConditionNode *)node;
onode->condType = opType;
onode->node.resType.type = TSDB_DATA_TYPE_BOOL;
@@ -179,24 +174,24 @@ void flttMakeLogicNode(SNode **pNode, ELogicConditionType opType, SNode **nodeLi
for (int32_t i = 0; i < nodeNum; ++i) {
nodesListAppend(onode->pParameterList, nodeList[i]);
}
-
+
*pNode = (SNode *)onode;
}
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;
onode->condType = opType;
onode->node.resType.type = TSDB_DATA_TYPE_BOOL;
onode->node.resType.bytes = sizeof(bool);
onode->pParameterList = nodeList;
-
+
*pNode = (SNode *)onode;
}
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;
lnode->dataType.type = resType;
lnode->pNodeList = list;
@@ -204,169 +199,166 @@ void flttMakeListNode(SNode **pNode, SNodeList *list, int32_t resType) {
*pNode = (SNode *)lnode;
}
-void initScalarParam(SScalarParam* pParam) {
+void initScalarParam(SScalarParam *pParam) {
memset(pParam, 0, sizeof(SScalarParam));
pParam->colAlloced = true;
}
-}
+} // namespace
TEST(timerangeTest, greater) {
- SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL;
- bool eRes[5] = {false, false, true, true, true};
+ SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL;
+ bool eRes[5] = {false, false, true, true, true};
SScalarParam res;
initScalarParam(&res);
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);
flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval);
- //SFilterInfo *filter = NULL;
- //int32_t code = filterInitFromNode(opNode1, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP);
- //ASSERT_EQ(code, 0);
+ // SFilterInfo *filter = NULL;
+ // int32_t code = filterInitFromNode(opNode1, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP);
+ // ASSERT_EQ(code, 0);
STimeWindow win = {0};
- bool isStrict = false;
- int32_t code = filterGetTimeRange(opNode1, &win, &isStrict);
+ bool isStrict = false;
+ int32_t code = filterGetTimeRange(opNode1, &win, &isStrict);
ASSERT_EQ(code, 0);
- ASSERT_EQ(isStrict, true);
- ASSERT_EQ(win.skey, tsmall+1);
- ASSERT_EQ(win.ekey, INT64_MAX);
- //filterFreeInfo(filter);
+ ASSERT_EQ(isStrict, true);
+ ASSERT_EQ(win.skey, tsmall + 1);
+ ASSERT_EQ(win.ekey, INT64_MAX);
+ // filterFreeInfo(filter);
nodesDestroyNode(opNode1);
}
TEST(timerangeTest, greater_and_lower) {
- SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL;
- bool eRes[5] = {false, false, true, true, true};
+ SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL;
+ bool eRes[5] = {false, false, true, true, true};
SScalarParam res;
initScalarParam(&res);
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);
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);
flttMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval);
SNode *list[2] = {0};
list[0] = opNode1;
list[1] = opNode2;
-
+
flttMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2);
- //SFilterInfo *filter = NULL;
- //int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP);
- //ASSERT_EQ(code, 0);
+ // SFilterInfo *filter = NULL;
+ // int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP);
+ // ASSERT_EQ(code, 0);
STimeWindow win = {0};
- bool isStrict = false;
- int32_t code = filterGetTimeRange(logicNode, &win, &isStrict);
+ bool isStrict = false;
+ int32_t code = filterGetTimeRange(logicNode, &win, &isStrict);
ASSERT_EQ(isStrict, true);
ASSERT_EQ(code, 0);
- ASSERT_EQ(win.skey, tsmall+1);
- ASSERT_EQ(win.ekey, tbig-1);
- //filterFreeInfo(filter);
+ ASSERT_EQ(win.skey, tsmall + 1);
+ ASSERT_EQ(win.ekey, tbig - 1);
+ // filterFreeInfo(filter);
nodesDestroyNode(logicNode);
}
TEST(timerangeTest, greater_equal_and_lower_equal) {
- SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL;
- bool eRes[5] = {false, false, true, true, true};
- SScalarParam res;
+ SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL;
+ bool eRes[5] = {false, false, true, true, true};
+ SScalarParam res;
initScalarParam(&res);
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);
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);
flttMakeOpNode(&opNode2, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pcol, pval);
SNode *list[2] = {0};
list[0] = opNode1;
list[1] = opNode2;
-
+
flttMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2);
- //SFilterInfo *filter = NULL;
- //int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP);
- //ASSERT_EQ(code, 0);
+ // SFilterInfo *filter = NULL;
+ // int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP);
+ // ASSERT_EQ(code, 0);
STimeWindow win = {0};
- bool isStrict = false;
- int32_t code = filterGetTimeRange(logicNode, &win, &isStrict);
+ bool isStrict = false;
+ int32_t code = filterGetTimeRange(logicNode, &win, &isStrict);
ASSERT_EQ(isStrict, true);
ASSERT_EQ(code, 0);
ASSERT_EQ(win.skey, tsmall);
- ASSERT_EQ(win.ekey, tbig);
- //filterFreeInfo(filter);
+ ASSERT_EQ(win.ekey, tbig);
+ // filterFreeInfo(filter);
nodesDestroyNode(logicNode);
}
-
TEST(timerangeTest, greater_and_lower_not_strict) {
- SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode1 = NULL, *logicNode2 = NULL;
- bool eRes[5] = {false, false, true, true, true};
+ SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode1 = NULL, *logicNode2 = NULL;
+ bool eRes[5] = {false, false, true, true, true};
SScalarParam res;
initScalarParam(&res);
int64_t tsmall1 = 222, tbig1 = 333;
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);
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);
flttMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval);
list[0] = opNode1;
list[1] = opNode2;
-
+
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);
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);
flttMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval);
list[0] = opNode1;
list[1] = opNode2;
-
+
flttMakeLogicNode(&logicNode2, LOGIC_COND_TYPE_AND, list, 2);
list[0] = logicNode1;
list[1] = logicNode2;
flttMakeLogicNode(&logicNode1, LOGIC_COND_TYPE_OR, list, 2);
- //SFilterInfo *filter = NULL;
- //int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP);
- //ASSERT_EQ(code, 0);
+ // SFilterInfo *filter = NULL;
+ // int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP);
+ // ASSERT_EQ(code, 0);
STimeWindow win = {0};
- bool isStrict = false;
- int32_t code = filterGetTimeRange(logicNode1, &win, &isStrict);
+ bool isStrict = false;
+ int32_t code = filterGetTimeRange(logicNode1, &win, &isStrict);
ASSERT_EQ(isStrict, false);
ASSERT_EQ(code, 0);
- ASSERT_EQ(win.skey, tsmall1+1);
- ASSERT_EQ(win.ekey, tbig2-1);
- //filterFreeInfo(filter);
+ ASSERT_EQ(win.skey, tsmall1 + 1);
+ ASSERT_EQ(win.ekey, tbig2 - 1);
+ // filterFreeInfo(filter);
nodesDestroyNode(logicNode1);
}
-
-
TEST(columnTest, smallint_column_greater_double_value) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
- int16_t leftv[5]= {1, 2, 3, 4, 5};
- double rightv= 2.5;
- int8_t eRes[5] = {0, 0, 1, 1, 1};
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
+ int16_t leftv[5] = {1, 2, 3, 4, 5};
+ double rightv = 2.5;
+ int8_t eRes[5] = {0, 0, 1, 1, 1};
SSDataBlock *src = NULL;
SScalarParam 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);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv);
flttMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
-
+
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(opNode, &filter, 0);
+ int32_t code = filterInitFromNode(opNode, &filter, 0);
ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0};
@@ -388,7 +380,7 @@ TEST(columnTest, smallint_column_greater_double_value) {
keep = filterRangeExecute(filter, &stat, 1, rowNum);
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, ¶m);
ASSERT_EQ(code, 0);
@@ -396,7 +388,7 @@ TEST(columnTest, smallint_column_greater_double_value) {
stat.min = 1;
stat.numOfNull = 0;
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);
for (int32_t i = 0; i < rowNum; ++i) {
@@ -409,20 +401,20 @@ TEST(columnTest, smallint_column_greater_double_value) {
}
TEST(columnTest, int_column_greater_smallint_value) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
- int32_t leftv[5]= {1, 3, 5, 7, 9};
- int16_t rightv= 4;
- int8_t eRes[5] = {0, 0, 1, 1, 1};
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
+ int32_t leftv[5] = {1, 3, 5, 7, 9};
+ int16_t rightv = 4;
+ int8_t eRes[5] = {0, 0, 1, 1, 1};
SSDataBlock *src = NULL;
SScalarParam 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);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv);
flttMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(opNode, &filter, 0);
+ int32_t code = filterInitFromNode(opNode, &filter, 0);
ASSERT_EQ(code, 0);
SColumnDataAgg stat = {0};
@@ -444,7 +436,7 @@ TEST(columnTest, int_column_greater_smallint_value) {
keep = filterRangeExecute(filter, &stat, 1, rowNum);
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, ¶m);
ASSERT_EQ(code, 0);
@@ -452,7 +444,7 @@ TEST(columnTest, int_column_greater_smallint_value) {
stat.min = 1;
stat.numOfNull = 0;
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);
for (int32_t i = 0; i < rowNum; ++i) {
@@ -465,31 +457,31 @@ TEST(columnTest, int_column_greater_smallint_value) {
}
TEST(columnTest, int_column_in_double_list) {
- SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL;
- int32_t leftv[5] = {1, 2, 3, 4, 5};
- double rightv1 = 1.1,rightv2 = 2.2,rightv3 = 3.3;
- bool eRes[5] = {true, true, true, false, false};
+ SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL;
+ int32_t leftv[5] = {1, 2, 3, 4, 5};
+ double rightv1 = 1.1, rightv2 = 2.2, rightv3 = 3.3;
+ bool eRes[5] = {true, true, true, false, false};
SSDataBlock *src = NULL;
SScalarParam 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);
- SNodeList* list = nodesMakeList();
+ SNodeList *list = nodesMakeList();
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv1);
nodesListAppend(list, pRight);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv2);
nodesListAppend(list, pRight);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv3);
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);
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(opNode, &filter, 0);
+ int32_t code = filterInitFromNode(opNode, &filter, 0);
ASSERT_EQ(code, 0);
- SColumnDataAgg stat = {0};
- SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock };
+ SColumnDataAgg stat = {0};
+ SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, ¶m);
ASSERT_EQ(code, 0);
@@ -497,7 +489,7 @@ TEST(columnTest, int_column_in_double_list) {
stat.min = 1;
stat.numOfNull = 0;
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);
for (int32_t i = 0; i < rowNum; ++i) {
@@ -511,13 +503,13 @@ TEST(columnTest, int_column_in_double_list) {
}
TEST(columnTest, binary_column_in_binary_list) {
- SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL;
- bool eRes[5] = {true, true, false, false, false};
+ SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL;
+ bool eRes[5] = {true, true, false, false, false};
SSDataBlock *src = NULL;
SScalarParam res;
initScalarParam(&res);
- char leftv[5][5]= {0};
- char rightv[3][5]= {0};
+ char leftv[5][5] = {0};
+ char rightv[3][5] = {0};
for (int32_t i = 0; i < 5; ++i) {
leftv[i][2] = 'a' + i;
leftv[i][3] = 'b' + i;
@@ -537,24 +529,24 @@ TEST(columnTest, binary_column_in_binary_list) {
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);
- SNodeList* list = nodesMakeList();
+ SNodeList *list = nodesMakeList();
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[0]);
nodesListAppend(list, pRight);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[1]);
nodesListAppend(list, pRight);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[2]);
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);
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(opNode, &filter, 0);
+ int32_t code = filterInitFromNode(opNode, &filter, 0);
ASSERT_EQ(code, 0);
- SColumnDataAgg stat = {0};
- SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock };
+ SColumnDataAgg stat = {0};
+ SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, ¶m);
ASSERT_EQ(code, 0);
@@ -562,7 +554,7 @@ TEST(columnTest, binary_column_in_binary_list) {
stat.min = 1;
stat.numOfNull = 0;
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);
for (int32_t i = 0; i < rowNum; ++i) {
@@ -575,9 +567,9 @@ TEST(columnTest, binary_column_in_binary_list) {
}
TEST(columnTest, binary_column_like_binary) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
- char rightv[64] = {0};
- char leftv[5][5]= {0};
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
+ char rightv[64] = {0};
+ char leftv[5][5] = {0};
SSDataBlock *src = NULL;
SScalarParam res;
initScalarParam(&res);
@@ -590,7 +582,7 @@ TEST(columnTest, binary_column_like_binary) {
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);
sprintf(&rightv[2], "%s", "__0");
@@ -599,11 +591,11 @@ TEST(columnTest, binary_column_like_binary) {
flttMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(opNode, &filter, 0);
+ int32_t code = filterInitFromNode(opNode, &filter, 0);
ASSERT_EQ(code, 0);
- SColumnDataAgg stat = {0};
- SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock };
+ SColumnDataAgg stat = {0};
+ SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, ¶m);
ASSERT_EQ(code, 0);
@@ -611,7 +603,7 @@ TEST(columnTest, binary_column_like_binary) {
stat.min = 1;
stat.numOfNull = 0;
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);
for (int32_t i = 0; i < rowNum; ++i) {
@@ -624,8 +616,8 @@ TEST(columnTest, binary_column_like_binary) {
}
TEST(columnTest, binary_column_is_null) {
- SNode *pLeft = NULL, *opNode = NULL;
- char leftv[5][5]= {0};
+ SNode *pLeft = NULL, *opNode = NULL;
+ char leftv[5][5] = {0};
SSDataBlock *src = NULL;
SScalarParam res;
initScalarParam(&res);
@@ -638,7 +630,7 @@ TEST(columnTest, binary_column_is_null) {
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);
SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock);
@@ -647,11 +639,11 @@ TEST(columnTest, binary_column_is_null) {
flttMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL);
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(opNode, &filter, 0);
+ int32_t code = filterInitFromNode(opNode, &filter, 0);
ASSERT_EQ(code, 0);
- SColumnDataAgg stat = {0};
- SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock };
+ SColumnDataAgg stat = {0};
+ SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, ¶m);
ASSERT_EQ(code, 0);
@@ -659,7 +651,7 @@ TEST(columnTest, binary_column_is_null) {
stat.min = 1;
stat.numOfNull = 0;
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);
for (int32_t i = 0; i < rowNum; ++i) {
@@ -672,8 +664,8 @@ TEST(columnTest, binary_column_is_null) {
}
TEST(columnTest, binary_column_is_not_null) {
- SNode *pLeft = NULL, *opNode = NULL;
- char leftv[5][5]= {0};
+ SNode *pLeft = NULL, *opNode = NULL;
+ char leftv[5][5] = {0};
SSDataBlock *src = NULL;
SScalarParam res;
initScalarParam(&res);
@@ -686,7 +678,7 @@ TEST(columnTest, binary_column_is_not_null) {
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);
SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock);
@@ -695,11 +687,11 @@ TEST(columnTest, binary_column_is_not_null) {
flttMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL);
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(opNode, &filter, 0);
+ int32_t code = filterInitFromNode(opNode, &filter, 0);
ASSERT_EQ(code, 0);
- SColumnDataAgg stat = {0};
- SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock };
+ SColumnDataAgg stat = {0};
+ SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, ¶m);
ASSERT_EQ(code, 0);
@@ -707,7 +699,7 @@ TEST(columnTest, binary_column_is_not_null) {
stat.min = 1;
stat.numOfNull = 0;
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);
for (int32_t i = 0; i < rowNum; ++i) {
@@ -720,24 +712,24 @@ TEST(columnTest, binary_column_is_not_null) {
}
TEST(opTest, smallint_column_greater_int_column) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
- int16_t leftv[5] = {1, -6, -2, 11, 101};
- int32_t rightv[5]= {0, -5, -4, 23, 100};
- bool eRes[5] = {true, false, true, false, true};
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
+ int16_t leftv[5] = {1, -6, -2, 11, 101};
+ int32_t rightv[5] = {0, -5, -4, 23, 100};
+ bool eRes[5] = {true, false, true, false, true};
SSDataBlock *src = NULL;
SScalarParam 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(&pRight, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, rightv);
flttMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(opNode, &filter, 0);
+ int32_t code = filterInitFromNode(opNode, &filter, 0);
ASSERT_EQ(code, 0);
- SColumnDataAgg stat = {0};
- SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock };
+ SColumnDataAgg stat = {0};
+ SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, ¶m);
ASSERT_EQ(code, 0);
@@ -745,7 +737,7 @@ TEST(opTest, smallint_column_greater_int_column) {
stat.min = 1;
stat.numOfNull = 0;
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);
for (int32_t i = 0; i < rowNum; ++i) {
@@ -758,25 +750,25 @@ TEST(opTest, smallint_column_greater_int_column) {
}
TEST(opTest, smallint_value_add_int_column) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
- int32_t leftv = 1;
- int16_t rightv[5]= {0, -1, -4, -1, 100};
- bool eRes[5] = {true, false, true, false, true};
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
+ int32_t leftv = 1;
+ int16_t rightv[5] = {0, -1, -4, -1, 100};
+ bool eRes[5] = {true, false, true, false, true};
SSDataBlock *src = NULL;
SScalarParam 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);
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_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(opNode, &filter, 0);
+ int32_t code = filterInitFromNode(opNode, &filter, 0);
ASSERT_EQ(code, 0);
- SColumnDataAgg stat = {0};
- SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock };
+ SColumnDataAgg stat = {0};
+ SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, ¶m);
ASSERT_EQ(code, 0);
@@ -784,7 +776,7 @@ TEST(opTest, smallint_value_add_int_column) {
stat.min = 1;
stat.numOfNull = 0;
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);
for (int32_t i = 0; i < rowNum; ++i) {
@@ -797,30 +789,30 @@ TEST(opTest, smallint_value_add_int_column) {
}
TEST(opTest, bigint_column_multi_binary_column) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
- int64_t leftv[5]= {1, 2, 3, 4, 5};
- char rightv[5][5]= {0};
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
+ int64_t leftv[5] = {1, 2, 3, 4, 5};
+ char rightv[5][5] = {0};
for (int32_t i = 0; i < 5; ++i) {
rightv[i][2] = rightv[i][3] = '0';
rightv[i][4] = '0' + i;
varDataSetLen(rightv[i], 3);
}
- bool eRes[5] = {false, true, true, true, true};
+ bool eRes[5] = {false, true, true, true, true};
SSDataBlock *src = NULL;
SScalarParam 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(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv);
flttMakeOpNode(&opNode, OP_TYPE_MULTI, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(opNode, &filter, 0);
+ int32_t code = filterInitFromNode(opNode, &filter, 0);
ASSERT_EQ(code, 0);
- SColumnDataAgg stat = {0};
- SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock };
+ SColumnDataAgg stat = {0};
+ SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, ¶m);
ASSERT_EQ(code, 0);
@@ -828,7 +820,7 @@ TEST(opTest, bigint_column_multi_binary_column) {
stat.min = 1;
stat.numOfNull = 0;
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);
for (int32_t i = 0; i < rowNum; ++i) {
@@ -841,30 +833,30 @@ TEST(opTest, bigint_column_multi_binary_column) {
}
TEST(opTest, smallint_column_and_binary_column) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
- int16_t leftv[5]= {1, 2, 3, 4, 5};
- char rightv[5][5]= {0};
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
+ int16_t leftv[5] = {1, 2, 3, 4, 5};
+ char rightv[5][5] = {0};
for (int32_t i = 0; i < 5; ++i) {
rightv[i][2] = rightv[i][3] = '0';
rightv[i][4] = '0' + i;
varDataSetLen(rightv[i], 3);
}
- bool eRes[5] = {false, false, true, false, true};
+ bool eRes[5] = {false, false, true, false, true};
SSDataBlock *src = NULL;
SScalarParam 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(&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_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(opNode, &filter, 0);
+ int32_t code = filterInitFromNode(opNode, &filter, 0);
ASSERT_EQ(code, 0);
- SColumnDataAgg stat = {0};
- SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock };
+ SColumnDataAgg stat = {0};
+ SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, ¶m);
ASSERT_EQ(code, 0);
@@ -872,7 +864,7 @@ TEST(opTest, smallint_column_and_binary_column) {
stat.min = 1;
stat.numOfNull = 0;
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);
for (int32_t i = 0; i < rowNum; ++i) {
@@ -885,25 +877,25 @@ TEST(opTest, smallint_column_and_binary_column) {
}
TEST(opTest, smallint_column_or_float_column) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
- int16_t leftv[5]= {1, 2, 0, 4, 5};
- float rightv[5]= {2.0, 3.0, 0, 5.2, 6.0};
- bool eRes[5] = {true, true, false, true, true};
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
+ int16_t leftv[5] = {1, 2, 0, 4, 5};
+ float rightv[5] = {2.0, 3.0, 0, 5.2, 6.0};
+ bool eRes[5] = {true, true, false, true, true};
SSDataBlock *src = NULL;
SScalarParam 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(&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_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(opNode, &filter, 0);
+ int32_t code = filterInitFromNode(opNode, &filter, 0);
ASSERT_EQ(code, 0);
- SColumnDataAgg stat = {0};
- SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock };
+ SColumnDataAgg stat = {0};
+ SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, ¶m);
ASSERT_EQ(code, 0);
@@ -911,7 +903,7 @@ TEST(opTest, smallint_column_or_float_column) {
stat.min = 1;
stat.numOfNull = 0;
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);
for (int32_t i = 0; i < rowNum; ++i) {
@@ -924,25 +916,25 @@ TEST(opTest, smallint_column_or_float_column) {
}
TEST(opTest, smallint_column_or_double_value) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
- int16_t leftv[5]= {0, 2, 3, 0, -1};
- double rightv= 10.2;
- bool eRes[5] = {true, true, true, true, true};
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
+ int16_t leftv[5] = {0, 2, 3, 0, -1};
+ double rightv = 10.2;
+ bool eRes[5] = {true, true, true, true, true};
SSDataBlock *src = NULL;
SScalarParam 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);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv);
flttMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(opNode, &filter, 0);
+ int32_t code = filterInitFromNode(opNode, &filter, 0);
ASSERT_EQ(code, 0);
- SColumnDataAgg stat = {0};
- SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock };
+ SColumnDataAgg stat = {0};
+ SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, ¶m);
ASSERT_EQ(code, 0);
@@ -950,7 +942,7 @@ TEST(opTest, smallint_column_or_double_value) {
stat.min = 1;
stat.numOfNull = 0;
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);
for (int32_t i = 0; i < rowNum; ++i) {
@@ -963,8 +955,8 @@ TEST(opTest, smallint_column_or_double_value) {
}
TEST(opTest, binary_column_is_true) {
- SNode *pLeft = NULL, *opNode = NULL;
- char leftv[5][5]= {0};
+ SNode *pLeft = NULL, *opNode = NULL;
+ char leftv[5][5] = {0};
SSDataBlock *src = NULL;
SScalarParam res;
initScalarParam(&res);
@@ -977,17 +969,17 @@ TEST(opTest, binary_column_is_true) {
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);
flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, pLeft, NULL);
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(opNode, &filter, 0);
+ int32_t code = filterInitFromNode(opNode, &filter, 0);
ASSERT_EQ(code, 0);
- SColumnDataAgg stat = {0};
- SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock };
+ SColumnDataAgg stat = {0};
+ SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, ¶m);
ASSERT_EQ(code, 0);
@@ -995,7 +987,7 @@ TEST(opTest, binary_column_is_true) {
stat.min = 1;
stat.numOfNull = 0;
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);
for (int32_t i = 0; i < rowNum; ++i) {
@@ -1010,16 +1002,16 @@ TEST(opTest, binary_column_is_true) {
TEST(filterModelogicTest, diff_columns_and_or_and) {
flttInitLogFile();
- SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = 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};
- int32_t rightv1= 3, rightv2= 3;
- int8_t eRes[8] = {1, 1, 0, 0, 1, 1, 1, 1};
+ SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = 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};
+ int32_t rightv1 = 3, rightv2 = 3;
+ int8_t eRes[8] = {1, 1, 0, 0, 1, 1, 1, 1};
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);
flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv1);
flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1);
@@ -1032,7 +1024,6 @@ TEST(filterModelogicTest, diff_columns_and_or_and) {
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list);
-
list = nodesMakeList();
flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1);
@@ -1052,13 +1043,12 @@ TEST(filterModelogicTest, diff_columns_and_or_and) {
nodesListAppend(list, logicNode2);
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list);
-
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(logicNode1, &filter, 0);
+ int32_t code = filterInitFromNode(logicNode1, &filter, 0);
ASSERT_EQ(code, 0);
- SColumnDataAgg stat = {0};
- SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock };
+ SColumnDataAgg stat = {0};
+ SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, ¶m);
ASSERT_EQ(code, 0);
@@ -1066,7 +1056,7 @@ TEST(filterModelogicTest, diff_columns_and_or_and) {
stat.min = 1;
stat.numOfNull = 0;
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);
for (int32_t i = 0; i < rowNum; ++i) {
@@ -1079,16 +1069,16 @@ TEST(filterModelogicTest, diff_columns_and_or_and) {
}
TEST(filterModelogicTest, same_column_and_or_and) {
- SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL;
- SNode *logicNode1 = NULL, *logicNode2 = NULL;
- double leftv1[8]= {1, 2, 3, 4, 5,-1,-2,-3};
- int32_t rightv1= 3, rightv2= 0, rightv3 = 2, rightv4 = -2;
- int8_t eRes[8] = {1, 1, 0, 0, 0, 1, 1, 0};
+ SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL;
+ SNode *logicNode1 = NULL, *logicNode2 = NULL;
+ double leftv1[8] = {1, 2, 3, 4, 5, -1, -2, -3};
+ int32_t rightv1 = 3, rightv2 = 0, rightv3 = 2, rightv4 = -2;
+ int8_t eRes[8] = {1, 1, 0, 0, 0, 1, 1, 0};
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);
flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv1);
flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1);
@@ -1101,7 +1091,6 @@ TEST(filterModelogicTest, same_column_and_or_and) {
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list);
-
list = nodesMakeList();
flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1);
@@ -1121,13 +1110,12 @@ TEST(filterModelogicTest, same_column_and_or_and) {
nodesListAppend(list, logicNode2);
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list);
-
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(logicNode1, &filter, 0);
+ int32_t code = filterInitFromNode(logicNode1, &filter, 0);
ASSERT_EQ(code, 0);
- SColumnDataAgg stat = {0};
- SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock };
+ SColumnDataAgg stat = {0};
+ SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, ¶m);
ASSERT_EQ(code, 0);
@@ -1135,7 +1123,7 @@ TEST(filterModelogicTest, same_column_and_or_and) {
stat.min = 1;
stat.numOfNull = 0;
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);
for (int32_t i = 0; i < rowNum; ++i) {
@@ -1148,16 +1136,16 @@ TEST(filterModelogicTest, same_column_and_or_and) {
}
TEST(filterModelogicTest, diff_columns_or_and_or) {
- SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = 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};
- int32_t rightv1= 3, rightv2= 3;
- int8_t eRes[8] = {1, 0, 1, 1, 0, 0, 0, 0};
+ SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = 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};
+ int32_t rightv1 = 3, rightv2 = 3;
+ int8_t eRes[8] = {1, 0, 1, 1, 0, 0, 0, 0};
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);
flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv1);
flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1);
@@ -1170,7 +1158,6 @@ TEST(filterModelogicTest, diff_columns_or_and_or) {
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list);
-
list = nodesMakeList();
flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1);
@@ -1190,13 +1177,12 @@ TEST(filterModelogicTest, diff_columns_or_and_or) {
nodesListAppend(list, logicNode2);
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list);
-
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(logicNode1, &filter, 0);
+ int32_t code = filterInitFromNode(logicNode1, &filter, 0);
ASSERT_EQ(code, 0);
- SColumnDataAgg stat = {0};
- SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock };
+ SColumnDataAgg stat = {0};
+ SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, ¶m);
ASSERT_EQ(code, 0);
@@ -1204,7 +1190,7 @@ TEST(filterModelogicTest, diff_columns_or_and_or) {
stat.min = 1;
stat.numOfNull = 0;
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);
for (int32_t i = 0; i < rowNum; ++i) {
@@ -1217,16 +1203,16 @@ TEST(filterModelogicTest, diff_columns_or_and_or) {
}
TEST(filterModelogicTest, same_column_or_and_or) {
- SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL;
- SNode *logicNode1 = NULL, *logicNode2 = NULL;
- double leftv1[8]= {1, 2, 3, 4, 5,-1,-2,-3};
- int32_t rightv1= 3, rightv2= 0, rightv3 = 2, rightv4 = -2;
- int8_t eRes[8] = {0, 0, 0, 1, 1, 1, 1, 1};
+ SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL;
+ SNode *logicNode1 = NULL, *logicNode2 = NULL;
+ double leftv1[8] = {1, 2, 3, 4, 5, -1, -2, -3};
+ int32_t rightv1 = 3, rightv2 = 0, rightv3 = 2, rightv4 = -2;
+ int8_t eRes[8] = {0, 0, 0, 1, 1, 1, 1, 1};
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);
flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv1);
flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1);
@@ -1239,7 +1225,6 @@ TEST(filterModelogicTest, same_column_or_and_or) {
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list);
-
list = nodesMakeList();
flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1);
@@ -1259,13 +1244,12 @@ TEST(filterModelogicTest, same_column_or_and_or) {
nodesListAppend(list, logicNode2);
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list);
-
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(logicNode1, &filter, 0);
+ int32_t code = filterInitFromNode(logicNode1, &filter, 0);
ASSERT_EQ(code, 0);
- SColumnDataAgg stat = {0};
- SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock };
+ SColumnDataAgg stat = {0};
+ SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, ¶m);
ASSERT_EQ(code, 0);
@@ -1273,7 +1257,7 @@ TEST(filterModelogicTest, same_column_or_and_or) {
stat.min = 1;
stat.numOfNull = 0;
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);
for (int32_t i = 0; i < rowNum; ++i) {
@@ -1288,16 +1272,16 @@ TEST(filterModelogicTest, same_column_or_and_or) {
TEST(scalarModelogicTest, diff_columns_or_and_or) {
flttInitLogFile();
- SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = 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};
- 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};
+ SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = 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};
+ 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};
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(&pRight1, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, rightv1);
flttMakeOpNode(&opNode1, OP_TYPE_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1);
@@ -1310,7 +1294,6 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) {
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list);
-
list = nodesMakeList();
flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1);
@@ -1330,13 +1313,12 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) {
nodesListAppend(list, logicNode2);
flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list);
-
SFilterInfo *filter = NULL;
- int32_t code = filterInitFromNode(logicNode1, &filter, 0);
+ int32_t code = filterInitFromNode(logicNode1, &filter, 0);
ASSERT_EQ(code, 0);
- SColumnDataAgg stat = {0};
- SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock };
+ SColumnDataAgg stat = {0};
+ SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock};
code = filterSetDataFromSlotId(filter, ¶m);
ASSERT_EQ(code, 0);
@@ -1344,9 +1326,9 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) {
stat.min = 1;
stat.numOfNull = 0;
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);
-
+
for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]);
}
@@ -1356,7 +1338,7 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) {
blockDataDestroy(src);
}
-int main(int argc, char** argv) {
+int main(int argc, char **argv) {
taosSeedRand(taosGetTimestampSec());
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
diff --git a/source/libs/scalar/test/scalar/scalarTests.cpp b/source/libs/scalar/test/scalar/scalarTests.cpp
index 7229fdec386b7df5bb626ea0524144d4f42dd995..39055b534d937ca74ecde5d017710534112fc91a 100644
--- a/source/libs/scalar/test/scalar/scalarTests.cpp
+++ b/source/libs/scalar/test/scalar/scalarTests.cpp
@@ -1,17 +1,17 @@
/*
-* Copyright (c) 2019 TAOS Data, Inc.
-*
-* This program is free software: you can use, redistribute, and/or modify
-* it under the terms of the GNU Affero General Public License, version 3
-* or later ("AGPL"), as published by the Free Software Foundation.
-*
-* This program is distributed in the hope that it will be useful, but WITHOUT
-* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-* FITNESS FOR A PARTICULAR PURPOSE.
-*
-* You should have received a copy of the GNU Affero General Public License
-* along with this program. If not, see .
-*/
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
#include
#include
@@ -32,17 +32,17 @@
#endif
#include "os.h"
-#include "tglobal.h"
+#include "filterInt.h"
+#include "nodes.h"
+#include "parUtil.h"
+#include "scalar.h"
+#include "stub.h"
#include "taos.h"
-#include "tdef.h"
-#include "tvariant.h"
#include "tdatablock.h"
-#include "stub.h"
-#include "scalar.h"
-#include "nodes.h"
+#include "tdef.h"
+#include "tglobal.h"
#include "tlog.h"
-#include "parUtil.h"
-#include "filterInt.h"
+#include "tvariant.h"
#define _DEBUG_PRINT_ 0
@@ -55,3595 +55,3582 @@
namespace {
SColumnInfo createColumnInfo(int32_t colId, int32_t type, int32_t bytes) {
- SColumnInfo info = {0};
- info.colId = colId;
- info.type = type;
- info.bytes = bytes;
- return info;
+ SColumnInfo info = {0};
+ info.colId = colId;
+ info.type = type;
+ info.bytes = bytes;
+ return info;
}
int64_t scltLeftV = 21, scltRightV = 10;
-double scltLeftVd = 21.0, scltRightVd = 10.0;
+double scltLeftVd = 21.0, scltRightVd = 10.0;
-void scltFreeDataBlock(void *block) {
- blockDataDestroy(*(SSDataBlock **)block);
-}
+void scltFreeDataBlock(void *block) { blockDataDestroy(*(SSDataBlock **)block); }
void scltInitLogFile() {
- const char *defaultLogFileNamePrefix = "taoslog";
- const int32_t maxLogFileNum = 10;
+ const char *defaultLogFileNamePrefix = "taoslog";
+ const int32_t maxLogFileNum = 10;
- tsAsyncLog = 0;
- qDebugFlag = 159;
- strcpy(tsLogDir, TD_LOG_DIR_PATH);
+ tsAsyncLog = 0;
+ qDebugFlag = 159;
+ strcpy(tsLogDir, TD_LOG_DIR_PATH);
- if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
- printf("failed to open log file in directory:%s\n", tsLogDir);
- }
+ if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
+ printf("failed to open log file in directory:%s\n", tsLogDir);
+ }
}
-void scltAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *slotId, bool newBlock, int32_t rows, SColumnInfo *colInfo) {
- if (newBlock) {
- SSDataBlock *res = createDataBlock();
+void scltAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *slotId, bool newBlock, int32_t rows,
+ SColumnInfo *colInfo) {
+ if (newBlock) {
+ SSDataBlock *res = createDataBlock();
- SColumnInfoData idata = {0};
- idata.info = *colInfo;
- colInfoDataEnsureCapacity(&idata, rows);
+ SColumnInfoData idata = {0};
+ idata.info = *colInfo;
+ colInfoDataEnsureCapacity(&idata, rows);
- blockDataAppendColInfo(res, &idata);
+ blockDataAppendColInfo(res, &idata);
- res->info.capacity = rows;
- res->info.rows = rows;
- SColumnInfoData* p = static_cast(taosArrayGet(res->pDataBlock, 0));
- ASSERT(p->pData != NULL && p->nullbitmap != NULL);
+ res->info.capacity = rows;
+ res->info.rows = rows;
+ SColumnInfoData *p = static_cast(taosArrayGet(res->pDataBlock, 0));
+ ASSERT(p->pData != NULL && p->nullbitmap != NULL);
- taosArrayPush(pBlockList, &res);
- *dataBlockId = taosArrayGetSize(pBlockList) - 1;
- res->info.blockId = *dataBlockId;
- *slotId = 0;
- } else {
- SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(pBlockList);
- SColumnInfoData idata = {0};
- idata.info = *colInfo;
- colInfoDataEnsureCapacity(&idata, rows);
- blockDataAppendColInfo(res, &idata);
+ taosArrayPush(pBlockList, &res);
+ *dataBlockId = taosArrayGetSize(pBlockList) - 1;
+ res->info.blockId = *dataBlockId;
+ *slotId = 0;
+ } else {
+ SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(pBlockList);
+ SColumnInfoData idata = {0};
+ idata.info = *colInfo;
+ colInfoDataEnsureCapacity(&idata, rows);
+ blockDataAppendColInfo(res, &idata);
- *dataBlockId = taosArrayGetSize(pBlockList) - 1;
- *slotId = taosArrayGetSize(res->pDataBlock) - 1;
- }
+ *dataBlockId = taosArrayGetSize(pBlockList) - 1;
+ *slotId = taosArrayGetSize(res->pDataBlock) - 1;
+ }
}
void scltMakeValueNode(SNode **pNode, int32_t dataType, void *value) {
- SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_VALUE);
- SValueNode *vnode = (SValueNode *)node;
- vnode->node.resType.type = dataType;
-
- if (IS_VAR_DATA_TYPE(dataType)) {
- vnode->datum.p = (char *)taosMemoryMalloc(varDataTLen(value));
- varDataCopy(vnode->datum.p, value);
- vnode->node.resType.bytes = varDataTLen(value);
- } else {
- vnode->node.resType.bytes = tDataTypes[dataType].bytes;
- assignVal((char *)nodesGetValueFromNode(vnode), (const char *)value, 0, dataType);
- }
-
- *pNode = (SNode *)vnode;
-}
-
-void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, int32_t dataBytes, int32_t rowNum, void *value) {
- SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_COLUMN);
- SColumnNode *rnode = (SColumnNode *)node;
- rnode->node.resType.type = dataType;
- rnode->node.resType.bytes = dataBytes;
- rnode->dataBlockId = 0;
-
- if (NULL == block) {
- *pNode = (SNode *)rnode;
- return;
- }
-
- if (NULL == *block) {
- SSDataBlock *res = createDataBlock();
- for (int32_t i = 0; i < 2; ++i) {
- SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_INT, 10, i + 1);
- colInfoDataEnsureCapacity(&idata, rowNum);
- blockDataAppendColInfo(res, &idata);
- }
-
- SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 3);
- colInfoDataEnsureCapacity(&idata, rowNum);
- blockDataAppendColInfo(res, &idata);
- res->info.capacity = rowNum;
-
- res->info.rows = rowNum;
- SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
- for (int32_t i = 0; i < rowNum; ++i) {
- colDataAppend(pColumn, i, (const char *)value, false);
- if (IS_VAR_DATA_TYPE(dataType)) {
- value = (char *)value + varDataTLen(value);
- } else {
- value = (char *)value + dataBytes;
- }
- }
-
- rnode->slotId = 2;
- rnode->colId = 3;
-
- *block = res;
- } else {
- SSDataBlock *res = *block;
-
- int32_t idx = taosArrayGetSize(res->pDataBlock);
- SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 1 + idx);
- colInfoDataEnsureCapacity(&idata, rowNum);
-
- res->info.capacity = rowNum;
- blockDataAppendColInfo(res, &idata);
-
- SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
-
- for (int32_t i = 0; i < rowNum; ++i) {
- colDataAppend(pColumn, i, (const char *)value, false);
- if (IS_VAR_DATA_TYPE(dataType)) {
- value = (char *)value + varDataTLen(value);
- } else {
- value = (char *)value + dataBytes;
- }
- }
-
- rnode->slotId = idx;
- rnode->colId = 1 + idx;
- }
-
- *pNode = (SNode *)rnode;
-}
-
-void scltMakeOpNode2(SNode **pNode, EOperatorType opType, int32_t resType, SNode *pLeft, SNode *pRight, bool isReverse) {
- SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_OPERATOR);
- SOperatorNode *onode = (SOperatorNode *)node;
- onode->node.resType.type = resType;
- onode->node.resType.bytes = tDataTypes[resType].bytes;
-
- onode->opType = opType;
- if(isReverse){
- onode->pLeft = pRight;
- onode->pRight = pLeft;
- }else{
- onode->pLeft = pLeft;
- onode->pRight = pRight;
- }
-
- *pNode = (SNode *)onode;
+ SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_VALUE);
+ SValueNode *vnode = (SValueNode *)node;
+ vnode->node.resType.type = dataType;
+
+ if (IS_VAR_DATA_TYPE(dataType)) {
+ vnode->datum.p = (char *)taosMemoryMalloc(varDataTLen(value));
+ varDataCopy(vnode->datum.p, value);
+ vnode->node.resType.bytes = varDataTLen(value);
+ } else {
+ vnode->node.resType.bytes = tDataTypes[dataType].bytes;
+ assignVal((char *)nodesGetValueFromNode(vnode), (const char *)value, 0, dataType);
+ }
+
+ *pNode = (SNode *)vnode;
+}
+
+void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, int32_t dataBytes, int32_t rowNum,
+ void *value) {
+ SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_COLUMN);
+ SColumnNode *rnode = (SColumnNode *)node;
+ rnode->node.resType.type = dataType;
+ rnode->node.resType.bytes = dataBytes;
+ rnode->dataBlockId = 0;
+
+ if (NULL == block) {
+ *pNode = (SNode *)rnode;
+ return;
+ }
+
+ if (NULL == *block) {
+ SSDataBlock *res = createDataBlock();
+ for (int32_t i = 0; i < 2; ++i) {
+ SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_INT, 10, i + 1);
+ colInfoDataEnsureCapacity(&idata, rowNum);
+ blockDataAppendColInfo(res, &idata);
+ }
+
+ SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 3);
+ colInfoDataEnsureCapacity(&idata, rowNum);
+ blockDataAppendColInfo(res, &idata);
+ res->info.capacity = rowNum;
+
+ res->info.rows = rowNum;
+ SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ colDataAppend(pColumn, i, (const char *)value, false);
+ if (IS_VAR_DATA_TYPE(dataType)) {
+ value = (char *)value + varDataTLen(value);
+ } else {
+ value = (char *)value + dataBytes;
+ }
+ }
+
+ rnode->slotId = 2;
+ rnode->colId = 3;
+
+ *block = res;
+ } else {
+ SSDataBlock *res = *block;
+
+ int32_t idx = taosArrayGetSize(res->pDataBlock);
+ SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 1 + idx);
+ colInfoDataEnsureCapacity(&idata, rowNum);
+
+ res->info.capacity = rowNum;
+ blockDataAppendColInfo(res, &idata);
+
+ SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
+
+ for (int32_t i = 0; i < rowNum; ++i) {
+ colDataAppend(pColumn, i, (const char *)value, false);
+ if (IS_VAR_DATA_TYPE(dataType)) {
+ value = (char *)value + varDataTLen(value);
+ } else {
+ value = (char *)value + dataBytes;
+ }
+ }
+
+ rnode->slotId = idx;
+ rnode->colId = 1 + idx;
+ }
+
+ *pNode = (SNode *)rnode;
+}
+
+void scltMakeOpNode2(SNode **pNode, EOperatorType opType, int32_t resType, SNode *pLeft, SNode *pRight,
+ bool isReverse) {
+ SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_OPERATOR);
+ SOperatorNode *onode = (SOperatorNode *)node;
+ onode->node.resType.type = resType;
+ onode->node.resType.bytes = tDataTypes[resType].bytes;
+
+ onode->opType = opType;
+ if (isReverse) {
+ onode->pLeft = pRight;
+ onode->pRight = pLeft;
+ } else {
+ onode->pLeft = pLeft;
+ onode->pRight = pRight;
+ }
+
+ *pNode = (SNode *)onode;
}
void scltMakeOpNode(SNode **pNode, EOperatorType opType, int32_t resType, SNode *pLeft, SNode *pRight) {
- SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_OPERATOR);
- SOperatorNode *onode = (SOperatorNode *)node;
- onode->node.resType.type = resType;
- onode->node.resType.bytes = tDataTypes[resType].bytes;
+ SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_OPERATOR);
+ SOperatorNode *onode = (SOperatorNode *)node;
+ onode->node.resType.type = resType;
+ onode->node.resType.bytes = tDataTypes[resType].bytes;
- onode->opType = opType;
- onode->pLeft = pLeft;
- onode->pRight = pRight;
+ onode->opType = opType;
+ onode->pLeft = pLeft;
+ onode->pRight = pRight;
- *pNode = (SNode *)onode;
+ *pNode = (SNode *)onode;
}
-
void scltMakeListNode(SNode **pNode, SNodeList *list, int32_t resType) {
- SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_NODE_LIST);
- SNodeListNode *lnode = (SNodeListNode *)node;
- lnode->dataType.type = resType;
- lnode->pNodeList = list;
+ SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_NODE_LIST);
+ SNodeListNode *lnode = (SNodeListNode *)node;
+ lnode->dataType.type = resType;
+ lnode->pNodeList = list;
- *pNode = (SNode *)lnode;
+ *pNode = (SNode *)lnode;
}
-
void scltMakeLogicNode(SNode **pNode, ELogicConditionType opType, SNode **nodeList, int32_t nodeNum) {
- SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION);
- SLogicConditionNode *onode = (SLogicConditionNode *)node;
- onode->condType = opType;
- onode->node.resType.type = TSDB_DATA_TYPE_BOOL;
- onode->node.resType.bytes = sizeof(bool);
+ SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION);
+ SLogicConditionNode *onode = (SLogicConditionNode *)node;
+ onode->condType = opType;
+ onode->node.resType.type = TSDB_DATA_TYPE_BOOL;
+ onode->node.resType.bytes = sizeof(bool);
- onode->pParameterList = nodesMakeList();
- for (int32_t i = 0; i < nodeNum; ++i) {
- nodesListAppend(onode->pParameterList, nodeList[i]);
- }
+ onode->pParameterList = nodesMakeList();
+ for (int32_t i = 0; i < nodeNum; ++i) {
+ nodesListAppend(onode->pParameterList, nodeList[i]);
+ }
- *pNode = (SNode *)onode;
+ *pNode = (SNode *)onode;
}
void scltMakeTargetNode(SNode **pNode, int16_t dataBlockId, int16_t slotId, SNode *snode) {
- SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_TARGET);
- STargetNode *onode = (STargetNode *)node;
- onode->pExpr = snode;
- onode->dataBlockId = dataBlockId;
- onode->slotId = slotId;
+ SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_TARGET);
+ STargetNode *onode = (STargetNode *)node;
+ onode->pExpr = snode;
+ onode->dataBlockId = dataBlockId;
+ onode->slotId = slotId;
- *pNode = (SNode *)onode;
-}
+ *pNode = (SNode *)onode;
}
+} // namespace
TEST(constantTest, bigint_add_bigint) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BIGINT, &scltLeftV);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BIGINT, &scltRightV);
- scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BIGINT, &scltLeftV);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BIGINT, &scltRightV);
+ scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_DOUBLE);
- ASSERT_FLOAT_EQ(v->datum.d, (scltLeftV + scltRightV));
- nodesDestroyNode(res);
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_DOUBLE);
+ ASSERT_FLOAT_EQ(v->datum.d, (scltLeftV + scltRightV));
+ nodesDestroyNode(res);
}
TEST(constantTest, double_sub_bigint) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_DOUBLE, &scltLeftVd);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BIGINT, &scltRightV);
- scltMakeOpNode(&opNode, OP_TYPE_SUB, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_DOUBLE, &scltLeftVd);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BIGINT, &scltRightV);
+ scltMakeOpNode(&opNode, OP_TYPE_SUB, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_DOUBLE);
- ASSERT_FLOAT_EQ(v->datum.d, (scltLeftVd - scltRightV));
- nodesDestroyNode(res);
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_DOUBLE);
+ ASSERT_FLOAT_EQ(v->datum.d, (scltLeftVd - scltRightV));
+ nodesDestroyNode(res);
}
TEST(constantTest, tinyint_and_smallint) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_TINYINT, &scltLeftV);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &scltRightV);
- scltMakeOpNode(&opNode, OP_TYPE_BIT_AND, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_TINYINT, &scltLeftV);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &scltRightV);
+ scltMakeOpNode(&opNode, OP_TYPE_BIT_AND, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BIGINT);
- ASSERT_EQ(v->datum.i, (int64_t)scltLeftV & (int64_t)scltRightV);
- nodesDestroyNode(res);
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BIGINT);
+ ASSERT_EQ(v->datum.i, (int64_t)scltLeftV & (int64_t)scltRightV);
+ nodesDestroyNode(res);
}
TEST(constantTest, bigint_or_double) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BIGINT, &scltLeftV);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &scltRightVd);
- scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BIGINT, &scltLeftV);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &scltRightVd);
+ scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BIGINT);
- ASSERT_EQ(v->datum.i, (int64_t)scltLeftV | (int64_t)scltRightVd);
- nodesDestroyNode(res);
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BIGINT);
+ ASSERT_EQ(v->datum.i, (int64_t)scltLeftV | (int64_t)scltRightVd);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_or_binary) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- char binaryStr[64] = {0};
- sprintf(&binaryStr[2], "%d", scltRightV);
- varDataSetLen(binaryStr, strlen(&binaryStr[2]));
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &scltLeftV);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, binaryStr);
- scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BIGINT);
- ASSERT_EQ(v->datum.b, scltLeftV | scltRightV);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ char binaryStr[64] = {0};
+ sprintf(&binaryStr[2], "%d", scltRightV);
+ varDataSetLen(binaryStr, strlen(&binaryStr[2]));
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &scltLeftV);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, binaryStr);
+ scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BIGINT);
+ ASSERT_EQ(v->datum.b, scltLeftV | scltRightV);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_greater_double) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &scltLeftV);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &scltRightVd);
- scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &scltLeftV);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &scltRightVd);
+ scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, scltLeftV > scltRightVd);
- nodesDestroyNode(res);
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, scltLeftV > scltRightVd);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_greater_equal_binary) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- char binaryStr[64] = {0};
- sprintf(&binaryStr[2], "%d", scltRightV);
- varDataSetLen(binaryStr, strlen(&binaryStr[2]));
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &scltLeftV);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, binaryStr);
- scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, scltLeftV > scltRightVd);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ char binaryStr[64] = {0};
+ sprintf(&binaryStr[2], "%d", scltRightV);
+ varDataSetLen(binaryStr, strlen(&binaryStr[2]));
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &scltLeftV);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, binaryStr);
+ scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, scltLeftV > scltRightVd);
+ nodesDestroyNode(res);
}
TEST(constantTest, tinyint_lower_ubigint) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_TINYINT, &scltLeftV);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_UBIGINT, &scltRightV);
- scltMakeOpNode(&opNode, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_TINYINT, &scltLeftV);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_UBIGINT, &scltRightV);
+ scltMakeOpNode(&opNode, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, scltLeftV < scltRightV);
- nodesDestroyNode(res);
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, scltLeftV < scltRightV);
+ nodesDestroyNode(res);
}
TEST(constantTest, usmallint_lower_equal_ubigint) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- int32_t leftv = 1;
- int64_t rightv = 1;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_USMALLINT, &leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_UBIGINT, &rightv);
- scltMakeOpNode(&opNode, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, leftv <= rightv);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ int32_t leftv = 1;
+ int64_t rightv = 1;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_USMALLINT, &leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_UBIGINT, &rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, leftv <= rightv);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_equal_smallint1) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- int32_t leftv = 1;
- int16_t rightv = 1;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv);
- scltMakeOpNode(&opNode, OP_TYPE_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, leftv == rightv);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ int32_t leftv = 1;
+ int16_t rightv = 1;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, leftv == rightv);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_equal_smallint2) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- int32_t leftv = 0, rightv = 1;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv);
- scltMakeOpNode(&opNode, OP_TYPE_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, leftv == rightv);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ int32_t leftv = 0, rightv = 1;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, leftv == rightv);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_not_equal_smallint1) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- int32_t leftv = 1, rightv = 1;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv);
- scltMakeOpNode(&opNode, OP_TYPE_NOT_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, leftv != rightv);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ int32_t leftv = 1, rightv = 1;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_NOT_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, leftv != rightv);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_not_equal_smallint2) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- int32_t leftv = 0, rightv = 1;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv);
- scltMakeOpNode(&opNode, OP_TYPE_NOT_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, leftv != rightv);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ int32_t leftv = 0, rightv = 1;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_NOT_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, leftv != rightv);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_in_smallint1) {
- scltInitLogFile();
-
- SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL;
- int32_t leftv = 1, rightv1 = 1,rightv2 = 2,rightv3 = 3;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
- SNodeList* list = nodesMakeList();
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1);
- nodesListAppend(list, pRight);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2);
- nodesListAppend(list, pRight);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3);
- nodesListAppend(list, pRight);
- scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT);
- scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, true);
- nodesDestroyNode(res);
+ scltInitLogFile();
+
+ SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL;
+ int32_t leftv = 1, rightv1 = 1, rightv2 = 2, rightv3 = 3;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
+ SNodeList *list = nodesMakeList();
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1);
+ nodesListAppend(list, pRight);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2);
+ nodesListAppend(list, pRight);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3);
+ nodesListAppend(list, pRight);
+ scltMakeListNode(&listNode, list, TSDB_DATA_TYPE_INT);
+ scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, true);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_in_smallint2) {
- scltInitLogFile();
-
- SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL;
- int32_t leftv = 4, rightv1 = 1,rightv2 = 2,rightv3 = 3;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
- SNodeList* list = nodesMakeList();
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1);
- nodesListAppend(list, pRight);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2);
- nodesListAppend(list, pRight);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3);
- nodesListAppend(list, pRight);
- scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT);
- scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, false);
- nodesDestroyNode(res);
+ scltInitLogFile();
+
+ SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL;
+ int32_t leftv = 4, rightv1 = 1, rightv2 = 2, rightv3 = 3;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
+ SNodeList *list = nodesMakeList();
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1);
+ nodesListAppend(list, pRight);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2);
+ nodesListAppend(list, pRight);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3);
+ nodesListAppend(list, pRight);
+ scltMakeListNode(&listNode, list, TSDB_DATA_TYPE_INT);
+ scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, false);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_not_in_smallint1) {
- SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL;
- int32_t leftv = 1, rightv1 = 1,rightv2 = 2,rightv3 = 3;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
- SNodeList* list = nodesMakeList();
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1);
- nodesListAppend(list, pRight);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2);
- nodesListAppend(list, pRight);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3);
- nodesListAppend(list, pRight);
- scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT);
- scltMakeOpNode(&opNode, OP_TYPE_NOT_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, false);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL;
+ int32_t leftv = 1, rightv1 = 1, rightv2 = 2, rightv3 = 3;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
+ SNodeList *list = nodesMakeList();
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1);
+ nodesListAppend(list, pRight);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2);
+ nodesListAppend(list, pRight);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3);
+ nodesListAppend(list, pRight);
+ scltMakeListNode(&listNode, list, TSDB_DATA_TYPE_INT);
+ scltMakeOpNode(&opNode, OP_TYPE_NOT_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, false);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_not_in_smallint2) {
- scltInitLogFile();
-
- SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL;
- int32_t leftv = 4, rightv1 = 1,rightv2 = 2,rightv3 = 3;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
- SNodeList* list = nodesMakeList();
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1);
- nodesListAppend(list, pRight);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2);
- nodesListAppend(list, pRight);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3);
- nodesListAppend(list, pRight);
- scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT);
- scltMakeOpNode(&opNode, OP_TYPE_NOT_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, true);
- nodesDestroyNode(res);
+ scltInitLogFile();
+
+ SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL;
+ int32_t leftv = 4, rightv1 = 1, rightv2 = 2, rightv3 = 3;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
+ SNodeList *list = nodesMakeList();
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1);
+ nodesListAppend(list, pRight);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2);
+ nodesListAppend(list, pRight);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3);
+ nodesListAppend(list, pRight);
+ scltMakeListNode(&listNode, list, TSDB_DATA_TYPE_INT);
+ scltMakeOpNode(&opNode, OP_TYPE_NOT_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, true);
+ nodesDestroyNode(res);
}
TEST(constantTest, binary_like_binary1) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- char leftv[64] = {0}, rightv[64] = {0};
- sprintf(&leftv[2], "%s", "abc");
- varDataSetLen(leftv, strlen(&leftv[2]));
- sprintf(&rightv[2], "%s", "a_c");
- varDataSetLen(rightv, strlen(&rightv[2]));
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
- scltMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, true);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ char leftv[64] = {0}, rightv[64] = {0};
+ sprintf(&leftv[2], "%s", "abc");
+ varDataSetLen(leftv, strlen(&leftv[2]));
+ sprintf(&rightv[2], "%s", "a_c");
+ varDataSetLen(rightv, strlen(&rightv[2]));
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, true);
+ nodesDestroyNode(res);
}
TEST(constantTest, binary_like_binary2) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- char leftv[64] = {0}, rightv[64] = {0};
- sprintf(&leftv[2], "%s", "abc");
- varDataSetLen(leftv, strlen(&leftv[2]));
- sprintf(&rightv[2], "%s", "ac");
- varDataSetLen(rightv, strlen(&rightv[2]));
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
- scltMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, false);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ char leftv[64] = {0}, rightv[64] = {0};
+ sprintf(&leftv[2], "%s", "abc");
+ varDataSetLen(leftv, strlen(&leftv[2]));
+ sprintf(&rightv[2], "%s", "ac");
+ varDataSetLen(rightv, strlen(&rightv[2]));
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, false);
+ nodesDestroyNode(res);
}
TEST(constantTest, binary_not_like_binary1) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- char leftv[64] = {0}, rightv[64] = {0};
- sprintf(&leftv[2], "%s", "abc");
- varDataSetLen(leftv, strlen(&leftv[2]));
- sprintf(&rightv[2], "%s", "a%c");
- varDataSetLen(rightv, strlen(&rightv[2]));
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
- scltMakeOpNode(&opNode, OP_TYPE_NOT_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, false);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ char leftv[64] = {0}, rightv[64] = {0};
+ sprintf(&leftv[2], "%s", "abc");
+ varDataSetLen(leftv, strlen(&leftv[2]));
+ sprintf(&rightv[2], "%s", "a%c");
+ varDataSetLen(rightv, strlen(&rightv[2]));
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_NOT_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, false);
+ nodesDestroyNode(res);
}
TEST(constantTest, binary_not_like_binary2) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- char leftv[64] = {0}, rightv[64] = {0};
- sprintf(&leftv[2], "%s", "abc");
- varDataSetLen(leftv, strlen(&leftv[2]));
- sprintf(&rightv[2], "%s", "ac");
- varDataSetLen(rightv, strlen(&rightv[2]));
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
- scltMakeOpNode(&opNode, OP_TYPE_NOT_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, true);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ char leftv[64] = {0}, rightv[64] = {0};
+ sprintf(&leftv[2], "%s", "abc");
+ varDataSetLen(leftv, strlen(&leftv[2]));
+ sprintf(&rightv[2], "%s", "ac");
+ varDataSetLen(rightv, strlen(&rightv[2]));
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_NOT_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, true);
+ nodesDestroyNode(res);
}
TEST(constantTest, binary_match_binary1) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- char leftv[64] = {0}, rightv[64] = {0};
- sprintf(&leftv[2], "%s", "abc");
- varDataSetLen(leftv, strlen(&leftv[2]));
- sprintf(&rightv[2], "%s", ".*");
- varDataSetLen(rightv, strlen(&rightv[2]));
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
- scltMakeOpNode(&opNode, OP_TYPE_MATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, true);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ char leftv[64] = {0}, rightv[64] = {0};
+ sprintf(&leftv[2], "%s", "abc");
+ varDataSetLen(leftv, strlen(&leftv[2]));
+ sprintf(&rightv[2], "%s", ".*");
+ varDataSetLen(rightv, strlen(&rightv[2]));
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_MATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, true);
+ nodesDestroyNode(res);
}
TEST(constantTest, binary_match_binary2) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- char leftv[64] = {0}, rightv[64] = {0};
- sprintf(&leftv[2], "%s", "abc");
- varDataSetLen(leftv, strlen(&leftv[2]));
- sprintf(&rightv[2], "%s", "abc.+");
- varDataSetLen(rightv, strlen(&rightv[2]));
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
- scltMakeOpNode(&opNode, OP_TYPE_MATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, false);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ char leftv[64] = {0}, rightv[64] = {0};
+ sprintf(&leftv[2], "%s", "abc");
+ varDataSetLen(leftv, strlen(&leftv[2]));
+ sprintf(&rightv[2], "%s", "abc.+");
+ varDataSetLen(rightv, strlen(&rightv[2]));
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_MATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, false);
+ nodesDestroyNode(res);
}
TEST(constantTest, binary_not_match_binary1) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- char leftv[64] = {0}, rightv[64] = {0};
- sprintf(&leftv[2], "%s", "abc");
- varDataSetLen(leftv, strlen(&leftv[2]));
- sprintf(&rightv[2], "%s", "a[1-9]c");
- varDataSetLen(rightv, strlen(&rightv[2]));
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
- scltMakeOpNode(&opNode, OP_TYPE_NMATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, true);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ char leftv[64] = {0}, rightv[64] = {0};
+ sprintf(&leftv[2], "%s", "abc");
+ varDataSetLen(leftv, strlen(&leftv[2]));
+ sprintf(&rightv[2], "%s", "a[1-9]c");
+ varDataSetLen(rightv, strlen(&rightv[2]));
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_NMATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, true);
+ nodesDestroyNode(res);
}
TEST(constantTest, binary_not_match_binary2) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- char leftv[64] = {0}, rightv[64] = {0};
- sprintf(&leftv[2], "%s", "abc");
- varDataSetLen(leftv, strlen(&leftv[2]));
- sprintf(&rightv[2], "%s", "a[ab]c");
- varDataSetLen(rightv, strlen(&rightv[2]));
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
- scltMakeOpNode(&opNode, OP_TYPE_NMATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, false);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ char leftv[64] = {0}, rightv[64] = {0};
+ sprintf(&leftv[2], "%s", "abc");
+ varDataSetLen(leftv, strlen(&leftv[2]));
+ sprintf(&rightv[2], "%s", "a[ab]c");
+ varDataSetLen(rightv, strlen(&rightv[2]));
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_NMATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, false);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_is_null1) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- int32_t leftv = 1, rightv = 1;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
- scltMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ int32_t leftv = 1, rightv = 1;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
+ scltMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, false);
- nodesDestroyNode(res);
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, false);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_is_null2) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- int32_t leftv = TSDB_DATA_INT_NULL, rightv = 1;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_NULL, &leftv);
- scltMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ int32_t leftv = TSDB_DATA_INT_NULL, rightv = 1;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_NULL, &leftv);
+ scltMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, true);
- nodesDestroyNode(res);
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, true);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_is_not_null1) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- int32_t leftv = 1, rightv = 1;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
- scltMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ int32_t leftv = 1, rightv = 1;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
+ scltMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, true);
- nodesDestroyNode(res);
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, true);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_is_not_null2) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- int32_t leftv = 1, rightv = 1;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_NULL, &leftv);
- scltMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ int32_t leftv = 1, rightv = 1;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_NULL, &leftv);
+ scltMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, false);
- nodesDestroyNode(res);
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, false);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_add_int_is_true1) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- int32_t leftv = 1, rightv = 1;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv);
- scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
- scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, true);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ int32_t leftv = 1, rightv = 1;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
+ scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, true);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_add_int_is_true2) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- int32_t leftv = 1, rightv = -1;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv);
- scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
- scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, false);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ int32_t leftv = 1, rightv = -1;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
+ scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, false);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_greater_int_is_true1) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- int32_t leftv = 1, rightv = 1;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv);
- scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
- scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, false);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ int32_t leftv = 1, rightv = 1;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+ scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, false);
+ nodesDestroyNode(res);
}
TEST(constantTest, int_greater_int_is_true2) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
- int32_t leftv = 1, rightv = 0;
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv);
- scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
- scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
-
- int32_t code = scalarCalculateConstants(opNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, true);
- nodesDestroyNode(res);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
+ int32_t leftv = 1, rightv = 0;
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+ scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
+
+ int32_t code = scalarCalculateConstants(opNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, true);
+ nodesDestroyNode(res);
}
TEST(constantTest, greater_and_lower) {
- scltInitLogFile();
-
- SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL;
- bool eRes[5] = {false, false, true, true, true};
- int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20;
- SNode *list[2] = {0};
- scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1);
- scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2);
- scltMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
- scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3);
- scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v4);
- scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
- list[0] = opNode1;
- list[1] = opNode2;
- scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2);
-
- int32_t code = scalarCalculateConstants(logicNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, true);
- nodesDestroyNode(res);
+ scltInitLogFile();
+
+ SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL;
+ bool eRes[5] = {false, false, true, true, true};
+ int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20;
+ SNode *list[2] = {0};
+ scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1);
+ scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2);
+ scltMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
+ scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3);
+ scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v4);
+ scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
+ list[0] = opNode1;
+ list[1] = opNode2;
+ scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2);
+
+ int32_t code = scalarCalculateConstants(logicNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, true);
+ nodesDestroyNode(res);
}
TEST(constantTest, column_and_value1) {
- scltInitLogFile();
-
- SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL;
- bool eRes[5] = {false, false, true, true, true};
- int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20;
- SNode *list[2] = {0};
- scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1);
- scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2);
- scltMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
- scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3);
- scltMakeColumnNode(&pval2, NULL, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 0, NULL);
- scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
- list[0] = opNode1;
- list[1] = opNode2;
- scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2);
-
- int32_t code = scalarCalculateConstants(logicNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_LOGIC_CONDITION);
- SLogicConditionNode *v = (SLogicConditionNode *)res;
- ASSERT_EQ(v->condType, LOGIC_COND_TYPE_AND);
- ASSERT_EQ(v->pParameterList->length, 1);
- nodesDestroyNode(res);
+ scltInitLogFile();
+
+ SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL;
+ bool eRes[5] = {false, false, true, true, true};
+ int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20;
+ SNode *list[2] = {0};
+ scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1);
+ scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2);
+ scltMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
+ scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3);
+ scltMakeColumnNode(&pval2, NULL, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 0, NULL);
+ scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
+ list[0] = opNode1;
+ list[1] = opNode2;
+ scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2);
+
+ int32_t code = scalarCalculateConstants(logicNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_LOGIC_CONDITION);
+ SLogicConditionNode *v = (SLogicConditionNode *)res;
+ ASSERT_EQ(v->condType, LOGIC_COND_TYPE_AND);
+ ASSERT_EQ(v->pParameterList->length, 1);
+ nodesDestroyNode(res);
}
TEST(constantTest, column_and_value2) {
- scltInitLogFile();
-
- SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL;
- bool eRes[5] = {false, false, true, true, true};
- int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20;
- SNode *list[2] = {0};
- scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1);
- scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2);
- scltMakeOpNode(&opNode1, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
- scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3);
- scltMakeColumnNode(&pval2, NULL, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 0, NULL);
- scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
- list[0] = opNode1;
- list[1] = opNode2;
- scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2);
-
- int32_t code = scalarCalculateConstants(logicNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, false);
- nodesDestroyNode(res);
+ scltInitLogFile();
+
+ SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL;
+ bool eRes[5] = {false, false, true, true, true};
+ int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20;
+ SNode *list[2] = {0};
+ scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1);
+ scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2);
+ scltMakeOpNode(&opNode1, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
+ scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3);
+ scltMakeColumnNode(&pval2, NULL, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 0, NULL);
+ scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
+ list[0] = opNode1;
+ list[1] = opNode2;
+ scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2);
+
+ int32_t code = scalarCalculateConstants(logicNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, false);
+ nodesDestroyNode(res);
}
TEST(constantTest, column_and_value3) {
- scltInitLogFile();
-
- SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL;
- bool eRes[5] = {false, false, true, true, true};
- int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20;
- SNode *list[2] = {0};
- scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1);
- scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2);
- scltMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
- scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3);
- scltMakeColumnNode(&pval2, NULL, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 0, NULL);
- scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
- list[0] = opNode1;
- list[1] = opNode2;
- scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_OR, list, 2);
-
- int32_t code = scalarCalculateConstants(logicNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
- SValueNode *v = (SValueNode *)res;
- ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(v->datum.b, true);
- nodesDestroyNode(res);
+ scltInitLogFile();
+
+ SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL;
+ bool eRes[5] = {false, false, true, true, true};
+ int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20;
+ SNode *list[2] = {0};
+ scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1);
+ scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2);
+ scltMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
+ scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3);
+ scltMakeColumnNode(&pval2, NULL, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 0, NULL);
+ scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
+ list[0] = opNode1;
+ list[1] = opNode2;
+ scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_OR, list, 2);
+
+ int32_t code = scalarCalculateConstants(logicNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
+ SValueNode *v = (SValueNode *)res;
+ ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(v->datum.b, true);
+ nodesDestroyNode(res);
}
TEST(constantTest, column_and_value4) {
- scltInitLogFile();
-
- SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL;
- bool eRes[5] = {false, false, true, true, true};
- int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20;
- SNode *list[2] = {0};
- scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1);
- scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2);
- scltMakeOpNode(&opNode1, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
- scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3);
- scltMakeColumnNode(&pval2, NULL, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 0, NULL);
- scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
- list[0] = opNode1;
- list[1] = opNode2;
- scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_OR, list, 2);
-
- int32_t code = scalarCalculateConstants(logicNode, &res);
- ASSERT_EQ(code, 0);
- ASSERT_TRUE(res);
- ASSERT_EQ(nodeType(res), QUERY_NODE_LOGIC_CONDITION);
- SLogicConditionNode *v = (SLogicConditionNode *)res;
- ASSERT_EQ(v->condType, LOGIC_COND_TYPE_OR);
- ASSERT_EQ(v->pParameterList->length, 1);
- nodesDestroyNode(res);
-}
-
-
-void makeJsonArrow(SSDataBlock **src, SNode **opNode, void *json, char *key){
- char keyVar[32] = {0};
- memcpy(varDataVal(keyVar), key, strlen(key));
- varDataLen(keyVar) = strlen(key);
-
- SNode *pLeft = NULL, *pRight = NULL;
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, keyVar);
- scltMakeColumnNode(&pLeft, src, TSDB_DATA_TYPE_JSON, ((STag*)json)->len, 1, json);
- scltMakeOpNode(opNode, OP_TYPE_JSON_GET_VALUE, TSDB_DATA_TYPE_JSON, pLeft, pRight);
-}
-
-void makeOperator(SNode **opNode, SArray *blockList, EOperatorType opType, int32_t rightType, void *rightData, bool isReverse){
- int32_t resType = TSDB_DATA_TYPE_NULL;
- if(opType == OP_TYPE_ADD || opType == OP_TYPE_SUB || opType == OP_TYPE_MULTI ||
- opType == OP_TYPE_DIV || opType == OP_TYPE_REM || opType == OP_TYPE_MINUS){
- resType = TSDB_DATA_TYPE_DOUBLE;
- }else if(opType == OP_TYPE_BIT_AND || opType == OP_TYPE_BIT_OR){
- resType = TSDB_DATA_TYPE_BIGINT;
- }else if(opType == OP_TYPE_GREATER_THAN || opType == OP_TYPE_GREATER_EQUAL ||
- opType == OP_TYPE_LOWER_THAN || opType == OP_TYPE_LOWER_EQUAL ||
- opType == OP_TYPE_EQUAL || opType == OP_TYPE_NOT_EQUAL ||
- opType == OP_TYPE_IS_NULL || opType == OP_TYPE_IS_NOT_NULL || opType == OP_TYPE_IS_TRUE ||
- opType == OP_TYPE_LIKE || opType == OP_TYPE_NOT_LIKE || opType == OP_TYPE_MATCH ||
- opType == OP_TYPE_NMATCH){
- resType = TSDB_DATA_TYPE_BOOL;
- }
-
- SNode *right = NULL;
- scltMakeValueNode(&right, rightType, rightData);
- scltMakeOpNode2(opNode, opType, resType, *opNode, right, isReverse);
-
- SColumnInfo colInfo = createColumnInfo(1, resType, tDataTypes[resType].bytes);
- int16_t dataBlockId = 0, slotId = 0;
- scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, 1, &colInfo);
- scltMakeTargetNode(opNode, dataBlockId, slotId, *opNode);
-}
-
-void makeCalculate(void *json, void *key, int32_t rightType, void *rightData, double exceptValue, EOperatorType opType, bool isReverse){
- SArray *blockList = taosArrayInit(2, POINTER_BYTES);
- SSDataBlock *src = NULL;
- SNode *opNode = NULL;
-
- makeJsonArrow(&src, &opNode, json, (char*)key);
- taosArrayPush(blockList, &src);
-
- makeOperator(&opNode, blockList, opType, rightType, rightData, isReverse);
-
- int32_t code = scalarCalculate(opNode, blockList, NULL);
- ASSERT_EQ(code, 0);
-
- SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
- ASSERT_EQ(res->info.rows, 1);
- SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
-
- if(colDataIsNull_f(column->nullbitmap, 0)){
- ASSERT_EQ(DBL_MAX, exceptValue);
- printf("result:NULL\n");
-
- }else if(opType == OP_TYPE_ADD || opType == OP_TYPE_SUB || opType == OP_TYPE_MULTI || opType == OP_TYPE_DIV ||
- opType == OP_TYPE_REM || opType == OP_TYPE_MINUS){
- printf("op:%s,1result:%f,except:%f\n", operatorTypeStr(opType), *((double *)colDataGetData(column, 0)), exceptValue);
- ASSERT_TRUE(fabs(*((double *)colDataGetData(column, 0)) - exceptValue) < 0.0001);
- }else if(opType == OP_TYPE_BIT_AND || opType == OP_TYPE_BIT_OR){
- printf("op:%s,2result:%" PRId64 ",except:%f\n", operatorTypeStr(opType), *((int64_t *)colDataGetData(column, 0)), exceptValue);
- ASSERT_EQ(*((int64_t *)colDataGetData(column, 0)), exceptValue);
- }else if(opType == OP_TYPE_GREATER_THAN || opType == OP_TYPE_GREATER_EQUAL || opType == OP_TYPE_LOWER_THAN ||
- opType == OP_TYPE_LOWER_EQUAL || opType == OP_TYPE_EQUAL || opType == OP_TYPE_NOT_EQUAL ||
- opType == OP_TYPE_IS_NULL || opType == OP_TYPE_IS_NOT_NULL || opType == OP_TYPE_IS_TRUE ||
- opType == OP_TYPE_LIKE || opType == OP_TYPE_NOT_LIKE || opType == OP_TYPE_MATCH || opType == OP_TYPE_NMATCH){
- printf("op:%s,3result:%d,except:%f\n", operatorTypeStr(opType), *((bool *)colDataGetData(column, 0)), exceptValue);
- ASSERT_EQ(*((bool *)colDataGetData(column, 0)), exceptValue);
- }
-
- taosArrayDestroyEx(blockList, scltFreeDataBlock);
- nodesDestroyNode(opNode);
+ scltInitLogFile();
+
+ SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL;
+ bool eRes[5] = {false, false, true, true, true};
+ int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20;
+ SNode *list[2] = {0};
+ scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1);
+ scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2);
+ scltMakeOpNode(&opNode1, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
+ scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3);
+ scltMakeColumnNode(&pval2, NULL, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 0, NULL);
+ scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2);
+ list[0] = opNode1;
+ list[1] = opNode2;
+ scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_OR, list, 2);
+
+ int32_t code = scalarCalculateConstants(logicNode, &res);
+ ASSERT_EQ(code, 0);
+ ASSERT_TRUE(res);
+ ASSERT_EQ(nodeType(res), QUERY_NODE_LOGIC_CONDITION);
+ SLogicConditionNode *v = (SLogicConditionNode *)res;
+ ASSERT_EQ(v->condType, LOGIC_COND_TYPE_OR);
+ ASSERT_EQ(v->pParameterList->length, 1);
+ nodesDestroyNode(res);
+}
+
+void makeJsonArrow(SSDataBlock **src, SNode **opNode, void *json, char *key) {
+ char keyVar[32] = {0};
+ memcpy(varDataVal(keyVar), key, strlen(key));
+ varDataLen(keyVar) = strlen(key);
+
+ SNode *pLeft = NULL, *pRight = NULL;
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, keyVar);
+ scltMakeColumnNode(&pLeft, src, TSDB_DATA_TYPE_JSON, ((STag *)json)->len, 1, json);
+ scltMakeOpNode(opNode, OP_TYPE_JSON_GET_VALUE, TSDB_DATA_TYPE_JSON, pLeft, pRight);
+}
+
+void makeOperator(SNode **opNode, SArray *blockList, EOperatorType opType, int32_t rightType, void *rightData,
+ bool isReverse) {
+ int32_t resType = TSDB_DATA_TYPE_NULL;
+ if (opType == OP_TYPE_ADD || opType == OP_TYPE_SUB || opType == OP_TYPE_MULTI || opType == OP_TYPE_DIV ||
+ opType == OP_TYPE_REM || opType == OP_TYPE_MINUS) {
+ resType = TSDB_DATA_TYPE_DOUBLE;
+ } else if (opType == OP_TYPE_BIT_AND || opType == OP_TYPE_BIT_OR) {
+ resType = TSDB_DATA_TYPE_BIGINT;
+ } else if (opType == OP_TYPE_GREATER_THAN || opType == OP_TYPE_GREATER_EQUAL || opType == OP_TYPE_LOWER_THAN ||
+ opType == OP_TYPE_LOWER_EQUAL || opType == OP_TYPE_EQUAL || opType == OP_TYPE_NOT_EQUAL ||
+ opType == OP_TYPE_IS_NULL || opType == OP_TYPE_IS_NOT_NULL || opType == OP_TYPE_IS_TRUE ||
+ opType == OP_TYPE_LIKE || opType == OP_TYPE_NOT_LIKE || opType == OP_TYPE_MATCH ||
+ opType == OP_TYPE_NMATCH) {
+ resType = TSDB_DATA_TYPE_BOOL;
+ }
+
+ SNode *right = NULL;
+ scltMakeValueNode(&right, rightType, rightData);
+ scltMakeOpNode2(opNode, opType, resType, *opNode, right, isReverse);
+
+ SColumnInfo colInfo = createColumnInfo(1, resType, tDataTypes[resType].bytes);
+ int16_t dataBlockId = 0, slotId = 0;
+ scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, 1, &colInfo);
+ scltMakeTargetNode(opNode, dataBlockId, slotId, *opNode);
+}
+
+void makeCalculate(void *json, void *key, int32_t rightType, void *rightData, double exceptValue, EOperatorType opType,
+ bool isReverse) {
+ SArray *blockList = taosArrayInit(2, POINTER_BYTES);
+ SSDataBlock *src = NULL;
+ SNode *opNode = NULL;
+
+ makeJsonArrow(&src, &opNode, json, (char *)key);
+ taosArrayPush(blockList, &src);
+
+ makeOperator(&opNode, blockList, opType, rightType, rightData, isReverse);
+
+ int32_t code = scalarCalculate(opNode, blockList, NULL);
+ ASSERT_EQ(code, 0);
+
+ SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
+ ASSERT_EQ(res->info.rows, 1);
+ SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
+
+ if (colDataIsNull_f(column->nullbitmap, 0)) {
+ ASSERT_EQ(DBL_MAX, exceptValue);
+ printf("result:NULL\n");
+
+ } else if (opType == OP_TYPE_ADD || opType == OP_TYPE_SUB || opType == OP_TYPE_MULTI || opType == OP_TYPE_DIV ||
+ opType == OP_TYPE_REM || opType == OP_TYPE_MINUS) {
+ printf("op:%s,1result:%f,except:%f\n", operatorTypeStr(opType), *((double *)colDataGetData(column, 0)),
+ exceptValue);
+ ASSERT_TRUE(fabs(*((double *)colDataGetData(column, 0)) - exceptValue) < 0.0001);
+ } else if (opType == OP_TYPE_BIT_AND || opType == OP_TYPE_BIT_OR) {
+ printf("op:%s,2result:%" PRId64 ",except:%f\n", operatorTypeStr(opType), *((int64_t *)colDataGetData(column, 0)),
+ exceptValue);
+ ASSERT_EQ(*((int64_t *)colDataGetData(column, 0)), exceptValue);
+ } else if (opType == OP_TYPE_GREATER_THAN || opType == OP_TYPE_GREATER_EQUAL || opType == OP_TYPE_LOWER_THAN ||
+ opType == OP_TYPE_LOWER_EQUAL || opType == OP_TYPE_EQUAL || opType == OP_TYPE_NOT_EQUAL ||
+ opType == OP_TYPE_IS_NULL || opType == OP_TYPE_IS_NOT_NULL || opType == OP_TYPE_IS_TRUE ||
+ opType == OP_TYPE_LIKE || opType == OP_TYPE_NOT_LIKE || opType == OP_TYPE_MATCH ||
+ opType == OP_TYPE_NMATCH) {
+ printf("op:%s,3result:%d,except:%f\n", operatorTypeStr(opType), *((bool *)colDataGetData(column, 0)), exceptValue);
+ ASSERT_EQ(*((bool *)colDataGetData(column, 0)), exceptValue);
+ }
+
+ taosArrayDestroyEx(blockList, scltFreeDataBlock);
+ nodesDestroyNode(opNode);
}
TEST(columnTest, json_column_arith_op) {
- scltInitLogFile();
- char *rightvTmp= "{\"k1\":4,\"k2\":\"hello\",\"k3\":null,\"k4\":true,\"k5\":5.44,\"k6\":-10,\"k7\":-9.8,\"k8\":false,\"k9\":\"8hel\"}";
-
- char rightv[256] = {0};
- memcpy(rightv, rightvTmp, strlen(rightvTmp));
- SArray *tags = taosArrayInit(1, sizeof(STagVal));
- STag* row = NULL;
- parseJsontoTagData(rightv, tags, &row, NULL);
-
- const int32_t len = 8;
- EOperatorType op[len] = {OP_TYPE_ADD, OP_TYPE_SUB, OP_TYPE_MULTI, OP_TYPE_DIV,
- OP_TYPE_REM, OP_TYPE_MINUS, OP_TYPE_BIT_AND, OP_TYPE_BIT_OR};
- int32_t input[len] = {1, 8, 2, 2, 3, 0, -4, 9};
-
- printf("--------------------json int-4 op {1, 8, 2, 2, 3, 0, -4, 9}--------------------\n");
- char *key = "k1";
- double eRes00[len] = {5.0, -4, 8.0, 2.0, 1.0, -4, 4&-4, 4|9};
- double eRes01[len] = {5.0, 4, 8.0, 0.5, 3, 0, 4&-4, 4|9};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes00[i], op[i], false);
- }
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes01[i], op[i], true);
- }
-
- printf("--------------------json string- 0 op {1, 8, 2, 2, 3, 0, -4, 9}--------------------\n");
-
- key = "k2";
- double eRes10[len] = {1.0, -8, 0, 0, 0, 0, 0, 9};
- double eRes11[len] = {1.0, 8, 0, DBL_MAX, DBL_MAX, 0, 0, 9};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes10[i], op[i], false);
- }
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes11[i], op[i], true);
- }
-
- printf("---------------------json null- null op {1, 8, 2, 2, 3, 0, -4, 9}-------------------\n");
-
- key = "k3";
- double eRes20[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX};
- double eRes21[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, 0, DBL_MAX, DBL_MAX};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes20[i], op[i], false);
- }
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes21[i], op[i], true);
- }
-
- printf("---------------------json bool- true op {1, 8, 2, 2, 3, 0, -4, 9}-------------------\n");
-
- key = "k4";
- double eRes30[len] = {2.0, -7, 2, 0.5, 1, -1, 1&-4, 1|9};
- double eRes31[len] = {2.0, 7, 2, 2, 0, 0, 1&-4, 1|9};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes30[i], op[i], false);
- }
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes31[i], op[i], true);
- }
-
- printf("----------------------json double-- 5.44 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n");
-
- key = "k5";
- double eRes40[len] = {6.44, -2.56, 10.88, 2.72, 2.44, -5.44, 5&-4, 5|9};
- double eRes41[len] = {6.44, 2.56, 10.88, 0.3676470588235294, 3, 0, 5&-4, 5|9};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes40[i], op[i], false);
- }
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes41[i], op[i], true);
- }
-
- printf("----------------------json int-- -10 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n");
-
- key = "k6";
- double eRes50[len] = {-9, -18, -20, -5, -10%3, 10, -10&-4, -10|9};
- double eRes51[len] = {-9, 18, -20, -0.2, 3%-10, 0, -10&-4, -10|9};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes50[i], op[i], false);
- }
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes51[i], op[i], true);
- }
-
- printf("----------------------json double-- -9.8 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n");
-
- key = "k7";
- double eRes60[len] = {-8.8, -17.8, -19.6, -4.9, -0.8, 9.8, -9&-4, -9|9};
- double eRes61[len] = {-8.8, 17.8, -19.6, -0.2040816326530612, 3, 0, -9&-4, -9|9};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes60[i], op[i], false);
- }
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes61[i], op[i], true);
- }
-
- printf("----------------------json bool-- 0 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n");
-
- key = "k8";
- double eRes70[len] = {1.0, -8, 0, 0, 0, 0, 0, 9};
- double eRes71[len] = {1.0, 8, 0, DBL_MAX, DBL_MAX, 0, 0, 9};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes70[i], op[i], false);
- }
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes71[i], op[i], true);
- }
-
- printf("----------------------json string-- 8 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n");
-
- key = "k9";
- double eRes80[len] = {9, 0, 16, 4, 8%3, -8, 8&-4, 8|9};
- double eRes81[len] = {9, 0, 16, 0.25, 3%8, 0, 8&-4, 8|9};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes80[i], op[i], false);
- }
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes81[i], op[i], true);
- }
-
- printf("---------------------json not exist-- NULL op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n");
-
- key = "k10";
- double eRes90[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX};
- double eRes91[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, 0, DBL_MAX, DBL_MAX};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes90[i], op[i], false);
- }
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes91[i], op[i], true);
- }
-
- taosArrayDestroy(tags);
- taosMemoryFree(row);
-}
-
-void *prepareNchar(char* rightData){
- int32_t len = 0;
- int32_t inputLen = strlen(rightData);
-
- char* t = (char*)taosMemoryCalloc(1,(inputLen + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE);
- taosMbsToUcs4(rightData, inputLen, (TdUcs4*) varDataVal(t), inputLen * TSDB_NCHAR_SIZE, &len);
- varDataSetLen(t, len);
- return t;
+ scltInitLogFile();
+ char *rightvTmp =
+ "{\"k1\":4,\"k2\":\"hello\",\"k3\":null,\"k4\":true,\"k5\":5.44,\"k6\":-10,\"k7\":-9.8,\"k8\":false,\"k9\":"
+ "\"8hel\"}";
+
+ char rightv[256] = {0};
+ memcpy(rightv, rightvTmp, strlen(rightvTmp));
+ SArray *tags = taosArrayInit(1, sizeof(STagVal));
+ STag *row = NULL;
+ parseJsontoTagData(rightv, tags, &row, NULL);
+
+ const int32_t len = 8;
+ EOperatorType op[len] = {OP_TYPE_ADD, OP_TYPE_SUB, OP_TYPE_MULTI, OP_TYPE_DIV,
+ OP_TYPE_REM, OP_TYPE_MINUS, OP_TYPE_BIT_AND, OP_TYPE_BIT_OR};
+ int32_t input[len] = {1, 8, 2, 2, 3, 0, -4, 9};
+
+ printf("--------------------json int-4 op {1, 8, 2, 2, 3, 0, -4, 9}--------------------\n");
+ char *key = "k1";
+ double eRes00[len] = {5.0, -4, 8.0, 2.0, 1.0, -4, 4 & -4, 4 | 9};
+ double eRes01[len] = {5.0, 4, 8.0, 0.5, 3, 0, 4 & -4, 4 | 9};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes00[i], op[i], false);
+ }
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes01[i], op[i], true);
+ }
+
+ printf("--------------------json string- 0 op {1, 8, 2, 2, 3, 0, -4, 9}--------------------\n");
+
+ key = "k2";
+ double eRes10[len] = {1.0, -8, 0, 0, 0, 0, 0, 9};
+ double eRes11[len] = {1.0, 8, 0, DBL_MAX, DBL_MAX, 0, 0, 9};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes10[i], op[i], false);
+ }
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes11[i], op[i], true);
+ }
+
+ printf("---------------------json null- null op {1, 8, 2, 2, 3, 0, -4, 9}-------------------\n");
+
+ key = "k3";
+ double eRes20[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX};
+ double eRes21[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, 0, DBL_MAX, DBL_MAX};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes20[i], op[i], false);
+ }
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes21[i], op[i], true);
+ }
+
+ printf("---------------------json bool- true op {1, 8, 2, 2, 3, 0, -4, 9}-------------------\n");
+
+ key = "k4";
+ double eRes30[len] = {2.0, -7, 2, 0.5, 1, -1, 1 & -4, 1 | 9};
+ double eRes31[len] = {2.0, 7, 2, 2, 0, 0, 1 & -4, 1 | 9};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes30[i], op[i], false);
+ }
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes31[i], op[i], true);
+ }
+
+ printf("----------------------json double-- 5.44 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n");
+
+ key = "k5";
+ double eRes40[len] = {6.44, -2.56, 10.88, 2.72, 2.44, -5.44, 5 & -4, 5 | 9};
+ double eRes41[len] = {6.44, 2.56, 10.88, 0.3676470588235294, 3, 0, 5 & -4, 5 | 9};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes40[i], op[i], false);
+ }
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes41[i], op[i], true);
+ }
+
+ printf("----------------------json int-- -10 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n");
+
+ key = "k6";
+ double eRes50[len] = {-9, -18, -20, -5, -10 % 3, 10, -10 & -4, -10 | 9};
+ double eRes51[len] = {-9, 18, -20, -0.2, 3 % -10, 0, -10 & -4, -10 | 9};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes50[i], op[i], false);
+ }
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes51[i], op[i], true);
+ }
+
+ printf("----------------------json double-- -9.8 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n");
+
+ key = "k7";
+ double eRes60[len] = {-8.8, -17.8, -19.6, -4.9, -0.8, 9.8, -9 & -4, -9 | 9};
+ double eRes61[len] = {-8.8, 17.8, -19.6, -0.2040816326530612, 3, 0, -9 & -4, -9 | 9};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes60[i], op[i], false);
+ }
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes61[i], op[i], true);
+ }
+
+ printf("----------------------json bool-- 0 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n");
+
+ key = "k8";
+ double eRes70[len] = {1.0, -8, 0, 0, 0, 0, 0, 9};
+ double eRes71[len] = {1.0, 8, 0, DBL_MAX, DBL_MAX, 0, 0, 9};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes70[i], op[i], false);
+ }
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes71[i], op[i], true);
+ }
+
+ printf("----------------------json string-- 8 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n");
+
+ key = "k9";
+ double eRes80[len] = {9, 0, 16, 4, 8 % 3, -8, 8 & -4, 8 | 9};
+ double eRes81[len] = {9, 0, 16, 0.25, 3 % 8, 0, 8 & -4, 8 | 9};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes80[i], op[i], false);
+ }
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes81[i], op[i], true);
+ }
+
+ printf("---------------------json not exist-- NULL op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n");
+
+ key = "k10";
+ double eRes90[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX};
+ double eRes91[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, 0, DBL_MAX, DBL_MAX};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes90[i], op[i], false);
+ }
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes91[i], op[i], true);
+ }
+
+ taosArrayDestroy(tags);
+ taosMemoryFree(row);
+}
+
+void *prepareNchar(char *rightData) {
+ int32_t len = 0;
+ int32_t inputLen = strlen(rightData);
+
+ char *t = (char *)taosMemoryCalloc(1, (inputLen + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE);
+ taosMbsToUcs4(rightData, inputLen, (TdUcs4 *)varDataVal(t), inputLen * TSDB_NCHAR_SIZE, &len);
+ varDataSetLen(t, len);
+ return t;
}
TEST(columnTest, json_column_logic_op) {
- scltInitLogFile();
- char *rightvTmp= "{\"k1\":4,\"k2\":\"hello\",\"k3\":null,\"k4\":true,\"k5\":5.44,\"k6\":-10,\"k7\":-9.8,\"k8\":false,\"k9\":\"6.6hello\"}";
-
- char rightv[256] = {0};
- memcpy(rightv, rightvTmp, strlen(rightvTmp));
- SArray *tags = taosArrayInit(1, sizeof(STagVal));
- STag* row = NULL;
- parseJsontoTagData(rightv, tags, &row, NULL);
-
- const int32_t len0 = 6;
- const int32_t len = 9;
- const int32_t len1 = 4;
- EOperatorType op[len+len1] = {OP_TYPE_GREATER_THAN, OP_TYPE_GREATER_EQUAL, OP_TYPE_LOWER_THAN, OP_TYPE_LOWER_EQUAL, OP_TYPE_EQUAL, OP_TYPE_NOT_EQUAL,
- OP_TYPE_IS_NULL, OP_TYPE_IS_NOT_NULL, OP_TYPE_IS_TRUE, OP_TYPE_LIKE, OP_TYPE_NOT_LIKE, OP_TYPE_MATCH, OP_TYPE_NMATCH};
-
- int32_t input[len] = {1, 8, 2, 2, 3, 0, 0, 0, 0};
- char *inputNchar[len1] = {"hell_", "hel%", "hell", "llll"};
-
- printf("--------------------json int---4 {1, 8, 2, 2, 3, 0, 0, 0, 0}------------------\n");
- char *key = "k1";
- bool eRes[len+len1] = {true, false, false, false, false, true, false, true, true, false, false, false, false};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes[i], op[i], false);
- }
- bool eRes_0[len0] = {false, true, true, true, false, true};
- for(int i = 0; i < len0; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_0[i], op[i], true);
- }
- for(int i = len; i < len + len1; i++){
- void* rightData = prepareNchar(inputNchar[i-len]);
- makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes[i], op[i], false);
- taosMemoryFree(rightData);
- }
-
- printf("--------------------json string--0 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
-
- key = "k2";
- bool eRes1[len+len1] = {false, false, false, false, false, false, false, true, false, true, false, true, true};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes1[i], op[i], false);
- }
- bool eRes_1[len0] = {false, false, false, false, false, false};
- for(int i = 0; i < len0; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_1[i], op[i], true);
- }
-
- for(int i = len; i < len + len1; i++){
- void* rightData = prepareNchar(inputNchar[i-len]);
- makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes1[i], op[i], false);
- taosMemoryFree(rightData);
- }
-
- printf("--------------------json null---null {1, 8, 2, 2, 3, 0, 0, 0, 0}------------------\n");
-
- key = "k3"; // (null is true) return NULL, so use DBL_MAX represent NULL
- bool eRes2[len+len1] = {false, false, false, false, false, false, true, false, false, false, false, false, false};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes2[i], op[i], false);
- }
- bool eRes_2[len0] = {false, false, false, false, false, false};
- for(int i = 0; i < len0; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_2[i], op[i], true);
- }
-
- for(int i = len; i < len + len1; i++){
- void* rightData = prepareNchar(inputNchar[i-len]);
- makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes2[i], op[i], false);
- taosMemoryFree(rightData);
- }
-
- printf("--------------------json bool--1 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
-
- key = "k4";
- bool eRes3[len+len1] = {false, false, false, false, false, false, false, true, true, false, false, false, false};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes3[i], op[i], false);
- }
- bool eRes_3[len0] = {false, false, false, false, false, false};
- for(int i = 0; i < len0; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_3[i], op[i], true);
- }
-
- for(int i = len; i < len + len1; i++){
- void* rightData = prepareNchar(inputNchar[i-len]);
- makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes3[i], op[i], false);
- taosMemoryFree(rightData);
- }
-
- printf("--------------------json double--5.44 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
-
- key = "k5";
- bool eRes4[len+len1] = {true, false, false, false, false, true, false, true, true, false, false, false, false};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes4[i], op[i], false);
- }
- bool eRes_4[len0] = {false, true, true, true, false, true};
- for(int i = 0; i < len0; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_4[i], op[i], true);
- }
-
- for(int i = len; i < len + len1; i++){
- void* rightData = prepareNchar(inputNchar[i-len]);
- makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes4[i], op[i], false);
- taosMemoryFree(rightData);
- }
-
- printf("--------------------json int-- -10 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
-
- key = "k6";
- bool eRes5[len+len1] = {false, false, true, true, false, true, false, true, true, false, false, false, false};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes5[i], op[i], false);
- }
- bool eRes_5[len0] = {true, true, false, false, false, true};
- for(int i = 0; i < len0; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_5[i], op[i], true);
- }
-
- for(int i = len; i < len + len1; i++){
- void* rightData = prepareNchar(inputNchar[i-len]);
- makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes5[i], op[i], false);
- taosMemoryFree(rightData);
- }
-
- printf("--------------------json double-- -9.8 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
-
- key = "k7";
- bool eRes6[len+len1] = {false, false, true, true, false, true, false, true, true, false, false, false, false};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes6[i], op[i], false);
- }
- bool eRes_6[len0] = {true, true, false, false, false, true};
- for(int i = 0; i < len0; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_6[i], op[i], true);
- }
-
- for(int i = len; i < len + len1; i++){
- void* rightData = prepareNchar(inputNchar[i-len]);
- makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes6[i], op[i], false);
- taosMemoryFree(rightData);
- }
-
-
- printf("--------------------json bool-- 0 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
-
- key = "k8";
- bool eRes7[len+len1] = {false, false, false, false, false, false, false, true, false, false, false, false, false};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes7[i], op[i], false);
- }
- bool eRes_7[len0] = {false, false, false, false, false, false};
- for(int i = 0; i < len0; i++) {
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_7[i], op[i], true);
- }
-
- for(int i = len; i < len + len1; i++){
- void* rightData = prepareNchar(inputNchar[i-len]);
- makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes7[i], op[i], false);
- taosMemoryFree(rightData);
- }
-
-
- printf("--------------------json string-- 6.6hello {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
-
- key = "k9";
- bool eRes8[len+len1] = {false, false, false, false, false, false, false, true, true, false, true, false, true};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes8[i], op[i], false);
- }
- bool eRes_8[len0] = {false, false, false, false, false, false};
- for(int i = 0; i < len0; i++) {
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_8[i], op[i], true);
- }
-
- for(int i = len; i < len + len1; i++){
- void* rightData = prepareNchar(inputNchar[i-len]);
- makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes8[i], op[i], false);
- taosMemoryFree(rightData);
- }
-
- printf("---------------------json not exist-- NULL {1, 8, 2, 2, 3, 0, 0, 0, 0}------------------\n");
-
- key = "k10"; // (NULL is true) return NULL, so use DBL_MAX represent NULL
- bool eRes9[len+len1] = {false, false, false, false, false, false, true, false, false, false, false, false, false};
- for(int i = 0; i < len; i++){
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes9[i], op[i], false);
- }
- bool eRes_9[len0] = {false, false, false, false, false, false};
- for(int i = 0; i < len0; i++) {
- makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_9[i], op[i], true);
- }
-
- for(int i = len; i < len + len1; i++){
- void* rightData = prepareNchar(inputNchar[i-len]);
- makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes9[i], op[i], false);
- taosMemoryFree(rightData);
- }
-
- taosArrayDestroy(tags);
- taosMemoryFree(row);
+ scltInitLogFile();
+ char *rightvTmp =
+ "{\"k1\":4,\"k2\":\"hello\",\"k3\":null,\"k4\":true,\"k5\":5.44,\"k6\":-10,\"k7\":-9.8,\"k8\":false,\"k9\":\"6."
+ "6hello\"}";
+
+ char rightv[256] = {0};
+ memcpy(rightv, rightvTmp, strlen(rightvTmp));
+ SArray *tags = taosArrayInit(1, sizeof(STagVal));
+ STag *row = NULL;
+ parseJsontoTagData(rightv, tags, &row, NULL);
+
+ const int32_t len0 = 6;
+ const int32_t len = 9;
+ const int32_t len1 = 4;
+ EOperatorType op[len + len1] = {OP_TYPE_GREATER_THAN, OP_TYPE_GREATER_EQUAL, OP_TYPE_LOWER_THAN, OP_TYPE_LOWER_EQUAL,
+ OP_TYPE_EQUAL, OP_TYPE_NOT_EQUAL, OP_TYPE_IS_NULL, OP_TYPE_IS_NOT_NULL,
+ OP_TYPE_IS_TRUE, OP_TYPE_LIKE, OP_TYPE_NOT_LIKE, OP_TYPE_MATCH,
+ OP_TYPE_NMATCH};
+
+ int32_t input[len] = {1, 8, 2, 2, 3, 0, 0, 0, 0};
+ char *inputNchar[len1] = {"hell_", "hel%", "hell", "llll"};
+
+ printf("--------------------json int---4 {1, 8, 2, 2, 3, 0, 0, 0, 0}------------------\n");
+ char *key = "k1";
+ bool eRes[len + len1] = {true, false, false, false, false, true, false, true, true, false, false, false, false};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes[i], op[i], false);
+ }
+ bool eRes_0[len0] = {false, true, true, true, false, true};
+ for (int i = 0; i < len0; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_0[i], op[i], true);
+ }
+ for (int i = len; i < len + len1; i++) {
+ void *rightData = prepareNchar(inputNchar[i - len]);
+ makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes[i], op[i], false);
+ taosMemoryFree(rightData);
+ }
+
+ printf("--------------------json string--0 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
+
+ key = "k2";
+ bool eRes1[len + len1] = {false, false, false, false, false, false, false, true, false, true, false, true, true};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes1[i], op[i], false);
+ }
+ bool eRes_1[len0] = {false, false, false, false, false, false};
+ for (int i = 0; i < len0; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_1[i], op[i], true);
+ }
+
+ for (int i = len; i < len + len1; i++) {
+ void *rightData = prepareNchar(inputNchar[i - len]);
+ makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes1[i], op[i], false);
+ taosMemoryFree(rightData);
+ }
+
+ printf("--------------------json null---null {1, 8, 2, 2, 3, 0, 0, 0, 0}------------------\n");
+
+ key = "k3"; // (null is true) return NULL, so use DBL_MAX represent NULL
+ bool eRes2[len + len1] = {false, false, false, false, false, false, true, false, false, false, false, false, false};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes2[i], op[i], false);
+ }
+ bool eRes_2[len0] = {false, false, false, false, false, false};
+ for (int i = 0; i < len0; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_2[i], op[i], true);
+ }
+
+ for (int i = len; i < len + len1; i++) {
+ void *rightData = prepareNchar(inputNchar[i - len]);
+ makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes2[i], op[i], false);
+ taosMemoryFree(rightData);
+ }
+
+ printf("--------------------json bool--1 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
+
+ key = "k4";
+ bool eRes3[len + len1] = {false, false, false, false, false, false, false, true, true, false, false, false, false};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes3[i], op[i], false);
+ }
+ bool eRes_3[len0] = {false, false, false, false, false, false};
+ for (int i = 0; i < len0; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_3[i], op[i], true);
+ }
+
+ for (int i = len; i < len + len1; i++) {
+ void *rightData = prepareNchar(inputNchar[i - len]);
+ makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes3[i], op[i], false);
+ taosMemoryFree(rightData);
+ }
+
+ printf("--------------------json double--5.44 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
+
+ key = "k5";
+ bool eRes4[len + len1] = {true, false, false, false, false, true, false, true, true, false, false, false, false};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes4[i], op[i], false);
+ }
+ bool eRes_4[len0] = {false, true, true, true, false, true};
+ for (int i = 0; i < len0; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_4[i], op[i], true);
+ }
+
+ for (int i = len; i < len + len1; i++) {
+ void *rightData = prepareNchar(inputNchar[i - len]);
+ makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes4[i], op[i], false);
+ taosMemoryFree(rightData);
+ }
+
+ printf("--------------------json int-- -10 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
+
+ key = "k6";
+ bool eRes5[len + len1] = {false, false, true, true, false, true, false, true, true, false, false, false, false};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes5[i], op[i], false);
+ }
+ bool eRes_5[len0] = {true, true, false, false, false, true};
+ for (int i = 0; i < len0; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_5[i], op[i], true);
+ }
+
+ for (int i = len; i < len + len1; i++) {
+ void *rightData = prepareNchar(inputNchar[i - len]);
+ makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes5[i], op[i], false);
+ taosMemoryFree(rightData);
+ }
+
+ printf("--------------------json double-- -9.8 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
+
+ key = "k7";
+ bool eRes6[len + len1] = {false, false, true, true, false, true, false, true, true, false, false, false, false};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes6[i], op[i], false);
+ }
+ bool eRes_6[len0] = {true, true, false, false, false, true};
+ for (int i = 0; i < len0; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_6[i], op[i], true);
+ }
+
+ for (int i = len; i < len + len1; i++) {
+ void *rightData = prepareNchar(inputNchar[i - len]);
+ makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes6[i], op[i], false);
+ taosMemoryFree(rightData);
+ }
+
+ printf("--------------------json bool-- 0 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
+
+ key = "k8";
+ bool eRes7[len + len1] = {false, false, false, false, false, false, false, true, false, false, false, false, false};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes7[i], op[i], false);
+ }
+ bool eRes_7[len0] = {false, false, false, false, false, false};
+ for (int i = 0; i < len0; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_7[i], op[i], true);
+ }
+
+ for (int i = len; i < len + len1; i++) {
+ void *rightData = prepareNchar(inputNchar[i - len]);
+ makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes7[i], op[i], false);
+ taosMemoryFree(rightData);
+ }
+
+ printf("--------------------json string-- 6.6hello {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n");
+
+ key = "k9";
+ bool eRes8[len + len1] = {false, false, false, false, false, false, false, true, true, false, true, false, true};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes8[i], op[i], false);
+ }
+ bool eRes_8[len0] = {false, false, false, false, false, false};
+ for (int i = 0; i < len0; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_8[i], op[i], true);
+ }
+
+ for (int i = len; i < len + len1; i++) {
+ void *rightData = prepareNchar(inputNchar[i - len]);
+ makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes8[i], op[i], false);
+ taosMemoryFree(rightData);
+ }
+
+ printf("---------------------json not exist-- NULL {1, 8, 2, 2, 3, 0, 0, 0, 0}------------------\n");
+
+ key = "k10"; // (NULL is true) return NULL, so use DBL_MAX represent NULL
+ bool eRes9[len + len1] = {false, false, false, false, false, false, true, false, false, false, false, false, false};
+ for (int i = 0; i < len; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes9[i], op[i], false);
+ }
+ bool eRes_9[len0] = {false, false, false, false, false, false};
+ for (int i = 0; i < len0; i++) {
+ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_9[i], op[i], true);
+ }
+
+ for (int i = len; i < len + len1; i++) {
+ void *rightData = prepareNchar(inputNchar[i - len]);
+ makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes9[i], op[i], false);
+ taosMemoryFree(rightData);
+ }
+
+ taosArrayDestroy(tags);
+ taosMemoryFree(row);
}
TEST(columnTest, smallint_value_add_int_column) {
- scltInitLogFile();
-
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
- int32_t leftv = 1;
- int16_t rightv[5]= {0, -5, -4, 23, 100};
- double eRes[5] = {1.0, -4, -3, 24, 101};
- SSDataBlock *src = NULL;
- int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]);
- scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
- scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, rightv);
- scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
-
- SArray *blockList = taosArrayInit(2, POINTER_BYTES);
- taosArrayPush(blockList, &src);
- SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_DOUBLE, sizeof(double));
- int16_t dataBlockId = 0, slotId = 0;
- scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo);
- scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
-
- int32_t code = scalarCalculate(opNode, blockList, NULL);
- ASSERT_EQ(code, 0);
-
- SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
- ASSERT_EQ(res->info.rows, rowNum);
- SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
- ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_DOUBLE);
- ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(column, i)), eRes[i]);
- }
-
- taosArrayDestroyEx(blockList, scltFreeDataBlock);
- nodesDestroyNode(opNode);
+ scltInitLogFile();
+
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
+ int32_t leftv = 1;
+ int16_t rightv[5] = {0, -5, -4, 23, 100};
+ double eRes[5] = {1.0, -4, -3, 24, 101};
+ SSDataBlock *src = NULL;
+ int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]);
+ scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
+ scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
+
+ SArray *blockList = taosArrayInit(2, POINTER_BYTES);
+ taosArrayPush(blockList, &src);
+ SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_DOUBLE, sizeof(double));
+ int16_t dataBlockId = 0, slotId = 0;
+ scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo);
+ scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
+
+ int32_t code = scalarCalculate(opNode, blockList, NULL);
+ ASSERT_EQ(code, 0);
+
+ SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
+ ASSERT_EQ(res->info.rows, rowNum);
+ SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
+ ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_DOUBLE);
+ ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(column, i)), eRes[i]);
+ }
+
+ taosArrayDestroyEx(blockList, scltFreeDataBlock);
+ nodesDestroyNode(opNode);
}
TEST(columnTest, bigint_column_multi_binary_column) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
- int64_t leftv[5]= {1, 2, 3, 4, 5};
- char rightv[5][5]= {0};
- for (int32_t i = 0; i < 5; ++i) {
- rightv[i][2] = rightv[i][3] = '0';
- rightv[i][4] = '0' + i;
- varDataSetLen(rightv[i], 3);
- }
- double eRes[5] = {0, 2, 6, 12, 20};
- SSDataBlock *src = NULL;
- int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]);
- scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), rowNum, leftv);
- scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv);
- scltMakeOpNode(&opNode, OP_TYPE_MULTI, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
-
- SArray *blockList = taosArrayInit(1, POINTER_BYTES);
- taosArrayPush(blockList, &src);
-
- SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_DOUBLE, sizeof(double));
- int16_t dataBlockId = 0, slotId = 0;
- scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo);
- scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
-
- int32_t code = scalarCalculate(opNode, blockList, NULL);
- ASSERT_EQ(code, 0);
-
- SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
- ASSERT_EQ(res->info.rows, rowNum);
- SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
- ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_DOUBLE);
- ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(column, i)), eRes[i]);
- }
- taosArrayDestroyEx(blockList, scltFreeDataBlock);
- nodesDestroyNode(opNode);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
+ int64_t leftv[5] = {1, 2, 3, 4, 5};
+ char rightv[5][5] = {0};
+ for (int32_t i = 0; i < 5; ++i) {
+ rightv[i][2] = rightv[i][3] = '0';
+ rightv[i][4] = '0' + i;
+ varDataSetLen(rightv[i], 3);
+ }
+ double eRes[5] = {0, 2, 6, 12, 20};
+ SSDataBlock *src = NULL;
+ int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]);
+ scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), rowNum, leftv);
+ scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_MULTI, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
+
+ SArray *blockList = taosArrayInit(1, POINTER_BYTES);
+ taosArrayPush(blockList, &src);
+
+ SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_DOUBLE, sizeof(double));
+ int16_t dataBlockId = 0, slotId = 0;
+ scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo);
+ scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
+
+ int32_t code = scalarCalculate(opNode, blockList, NULL);
+ ASSERT_EQ(code, 0);
+
+ SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
+ ASSERT_EQ(res->info.rows, rowNum);
+ SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
+ ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_DOUBLE);
+ ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(column, i)), eRes[i]);
+ }
+ taosArrayDestroyEx(blockList, scltFreeDataBlock);
+ nodesDestroyNode(opNode);
}
TEST(columnTest, smallint_column_and_binary_column) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
- int16_t leftv[5]= {1, 2, 3, 4, 5};
- char rightv[5][5]= {0};
- for (int32_t i = 0; i < 5; ++i) {
- rightv[i][2] = rightv[i][3] = '0';
- rightv[i][4] = '0' + i;
- varDataSetLen(rightv[i], 3);
- }
- int64_t eRes[5] = {0, 0, 2, 0, 4};
- SSDataBlock *src = NULL;
- int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]);
- scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
- scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv);
- scltMakeOpNode(&opNode, OP_TYPE_BIT_AND, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
-
- SArray *blockList = taosArrayInit(1, POINTER_BYTES);
- taosArrayPush(blockList, &src);
- SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t));
- int16_t dataBlockId = 0, slotId = 0;
- scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo);
- scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
-
- int32_t code = scalarCalculate(opNode, blockList, NULL);
- ASSERT_EQ(code, 0);
-
- SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
- ASSERT_EQ(res->info.rows, rowNum);
- SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
- ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BIGINT);
- ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int64_t *)colDataGetData(column, i)), eRes[i]);
- }
- taosArrayDestroyEx(blockList, scltFreeDataBlock);
- nodesDestroyNode(opNode);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
+ int16_t leftv[5] = {1, 2, 3, 4, 5};
+ char rightv[5][5] = {0};
+ for (int32_t i = 0; i < 5; ++i) {
+ rightv[i][2] = rightv[i][3] = '0';
+ rightv[i][4] = '0' + i;
+ varDataSetLen(rightv[i], 3);
+ }
+ int64_t eRes[5] = {0, 0, 2, 0, 4};
+ SSDataBlock *src = NULL;
+ int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]);
+ scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
+ scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_BIT_AND, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
+
+ SArray *blockList = taosArrayInit(1, POINTER_BYTES);
+ taosArrayPush(blockList, &src);
+ SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t));
+ int16_t dataBlockId = 0, slotId = 0;
+ scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo);
+ scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
+
+ int32_t code = scalarCalculate(opNode, blockList, NULL);
+ ASSERT_EQ(code, 0);
+
+ SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
+ ASSERT_EQ(res->info.rows, rowNum);
+ SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
+ ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BIGINT);
+ ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int64_t *)colDataGetData(column, i)), eRes[i]);
+ }
+ taosArrayDestroyEx(blockList, scltFreeDataBlock);
+ nodesDestroyNode(opNode);
}
TEST(columnTest, smallint_column_or_float_column) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
- int16_t leftv[5]= {1, 2, 3, 4, 5};
- float rightv[5]= {2.0, 3.0, 4.1, 5.2, 6.0};
- int64_t eRes[5] = {3, 3, 7, 5, 7};
- SSDataBlock *src = NULL;
- int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]);
- scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
- scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_FLOAT, sizeof(float), rowNum, rightv);
- scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
-
- SArray *blockList = taosArrayInit(1, POINTER_BYTES);
- taosArrayPush(blockList, &src);
- SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t));
- int16_t dataBlockId = 0, slotId = 0;
- scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo);
- scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
-
- int32_t code = scalarCalculate(opNode, blockList, NULL);
- ASSERT_EQ(code, 0);
-
- SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
- ASSERT_EQ(res->info.rows, rowNum);
- SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
- ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BIGINT);
- ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int64_t *)colDataGetData(column, i)), eRes[i]);
- }
- taosArrayDestroyEx(blockList, scltFreeDataBlock);
- nodesDestroyNode(opNode);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
+ int16_t leftv[5] = {1, 2, 3, 4, 5};
+ float rightv[5] = {2.0, 3.0, 4.1, 5.2, 6.0};
+ int64_t eRes[5] = {3, 3, 7, 5, 7};
+ SSDataBlock *src = NULL;
+ int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]);
+ scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
+ scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_FLOAT, sizeof(float), rowNum, rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
+
+ SArray *blockList = taosArrayInit(1, POINTER_BYTES);
+ taosArrayPush(blockList, &src);
+ SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t));
+ int16_t dataBlockId = 0, slotId = 0;
+ scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo);
+ scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
+
+ int32_t code = scalarCalculate(opNode, blockList, NULL);
+ ASSERT_EQ(code, 0);
+
+ SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
+ ASSERT_EQ(res->info.rows, rowNum);
+ SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
+ ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BIGINT);
+ ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int64_t *)colDataGetData(column, i)), eRes[i]);
+ }
+ taosArrayDestroyEx(blockList, scltFreeDataBlock);
+ nodesDestroyNode(opNode);
}
TEST(columnTest, smallint_column_or_double_value) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
- int16_t leftv[5]= {1, 2, 3, 4, 5};
- double rightv= 10.2;
- int64_t eRes[5] = {11, 10, 11, 14, 15};
- SSDataBlock *src = NULL;
- int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
- scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv);
- scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
-
- SArray *blockList = taosArrayInit(1, POINTER_BYTES);
- taosArrayPush(blockList, &src);
- SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t));
- int16_t dataBlockId = 0, slotId = 0;
- scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo);
- scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
-
- int32_t code = scalarCalculate(opNode, blockList, NULL);
- ASSERT_EQ(code, 0);
-
- SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
- ASSERT_EQ(res->info.rows, rowNum);
- SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
- ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BIGINT);
- ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int64_t *)colDataGetData(column, i)), eRes[i]);
- }
- taosArrayDestroyEx(blockList, scltFreeDataBlock);
- nodesDestroyNode(opNode);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
+ int16_t leftv[5] = {1, 2, 3, 4, 5};
+ double rightv = 10.2;
+ int64_t eRes[5] = {11, 10, 11, 14, 15};
+ SSDataBlock *src = NULL;
+ int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
+ scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
+
+ SArray *blockList = taosArrayInit(1, POINTER_BYTES);
+ taosArrayPush(blockList, &src);
+ SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t));
+ int16_t dataBlockId = 0, slotId = 0;
+ scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo);
+ scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
+
+ int32_t code = scalarCalculate(opNode, blockList, NULL);
+ ASSERT_EQ(code, 0);
+
+ SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
+ ASSERT_EQ(res->info.rows, rowNum);
+ SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
+ ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BIGINT);
+ ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int64_t *)colDataGetData(column, i)), eRes[i]);
+ }
+ taosArrayDestroyEx(blockList, scltFreeDataBlock);
+ nodesDestroyNode(opNode);
}
TEST(columnTest, smallint_column_greater_double_value) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
- int16_t leftv[5]= {1, 2, 3, 4, 5};
- double rightv= 2.5;
- bool eRes[5] = {false, false, true, true, true};
- SSDataBlock *src = NULL;
- int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
- scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv);
- scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
-
- SArray *blockList = taosArrayInit(1, POINTER_BYTES);
- taosArrayPush(blockList, &src);
- SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool));
- int16_t dataBlockId = 0, slotId = 0;
- scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo);
- scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
-
- int32_t code = scalarCalculate(opNode, blockList, NULL);
- ASSERT_EQ(code, 0);
-
- SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
- ASSERT_EQ(res->info.rows, rowNum);
- SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
- ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]);
- }
- taosArrayDestroyEx(blockList, scltFreeDataBlock);
- nodesDestroyNode(opNode);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
+ int16_t leftv[5] = {1, 2, 3, 4, 5};
+ double rightv = 2.5;
+ bool eRes[5] = {false, false, true, true, true};
+ SSDataBlock *src = NULL;
+ int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
+ scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+
+ SArray *blockList = taosArrayInit(1, POINTER_BYTES);
+ taosArrayPush(blockList, &src);
+ SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool));
+ int16_t dataBlockId = 0, slotId = 0;
+ scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo);
+ scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
+
+ int32_t code = scalarCalculate(opNode, blockList, NULL);
+ ASSERT_EQ(code, 0);
+
+ SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
+ ASSERT_EQ(res->info.rows, rowNum);
+ SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
+ ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]);
+ }
+ taosArrayDestroyEx(blockList, scltFreeDataBlock);
+ nodesDestroyNode(opNode);
}
TEST(columnTest, int_column_in_double_list) {
- SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL;
- int32_t leftv[5] = {1, 2, 3, 4, 5};
- double rightv1 = 1.1,rightv2 = 2.2,rightv3 = 3.3;
- bool eRes[5] = {true, true, true, false, false};
- SSDataBlock *src = NULL;
- int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
- scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv);
- SNodeList* list = nodesMakeList();
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv1);
- nodesListAppend(list, pRight);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv2);
- nodesListAppend(list, pRight);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv3);
- nodesListAppend(list, pRight);
- scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT);
- scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
-
- SArray *blockList = taosArrayInit(1, POINTER_BYTES);
- taosArrayPush(blockList, &src);
- SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool));
- int16_t dataBlockId = 0, slotId = 0;
- scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo);
- scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
-
- int32_t code = scalarCalculate(opNode, blockList, NULL);
- ASSERT_EQ(code, 0);
-
- SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
- ASSERT_EQ(res->info.rows, rowNum);
- SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
- ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]);
- }
- taosArrayDestroyEx(blockList, scltFreeDataBlock);
- nodesDestroyNode(opNode);
+ SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL;
+ int32_t leftv[5] = {1, 2, 3, 4, 5};
+ double rightv1 = 1.1, rightv2 = 2.2, rightv3 = 3.3;
+ bool eRes[5] = {true, true, true, false, false};
+ SSDataBlock *src = NULL;
+ int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
+ scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv);
+ SNodeList *list = nodesMakeList();
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv1);
+ nodesListAppend(list, pRight);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv2);
+ nodesListAppend(list, pRight);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv3);
+ nodesListAppend(list, pRight);
+ scltMakeListNode(&listNode, list, TSDB_DATA_TYPE_INT);
+ scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
+
+ SArray *blockList = taosArrayInit(1, POINTER_BYTES);
+ taosArrayPush(blockList, &src);
+ SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool));
+ int16_t dataBlockId = 0, slotId = 0;
+ scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo);
+ scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
+
+ int32_t code = scalarCalculate(opNode, blockList, NULL);
+ ASSERT_EQ(code, 0);
+
+ SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
+ ASSERT_EQ(res->info.rows, rowNum);
+ SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
+ ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]);
+ }
+ taosArrayDestroyEx(blockList, scltFreeDataBlock);
+ nodesDestroyNode(opNode);
}
TEST(columnTest, binary_column_in_binary_list) {
- SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL;
- bool eRes[5] = {true, true, false, false, false};
- SSDataBlock *src = NULL;
- char leftv[5][5]= {0};
- char rightv[3][5]= {0};
- for (int32_t i = 0; i < 5; ++i) {
- leftv[i][2] = 'a' + i;
- leftv[i][3] = 'b' + i;
- leftv[i][4] = '0' + i;
- varDataSetLen(leftv[i], 3);
- }
- for (int32_t i = 0; i < 2; ++i) {
- rightv[i][2] = 'a' + i;
- rightv[i][3] = 'b' + i;
- rightv[i][4] = '0' + i;
- varDataSetLen(rightv[i], 3);
- }
- for (int32_t i = 2; i < 3; ++i) {
- rightv[i][2] = 'a' + i;
- rightv[i][3] = 'a' + i;
- rightv[i][4] = 'a' + i;
- varDataSetLen(rightv[i], 3);
- }
-
- int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
- scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
- SNodeList* list = nodesMakeList();
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[0]);
- nodesListAppend(list, pRight);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[1]);
- nodesListAppend(list, pRight);
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[2]);
- nodesListAppend(list, pRight);
- scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_BINARY);
- scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
-
- SArray *blockList = taosArrayInit(1, POINTER_BYTES);
- taosArrayPush(blockList, &src);
- SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool));
- int16_t dataBlockId = 0, slotId = 0;
- scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo);
- scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
-
- int32_t code = scalarCalculate(opNode, blockList, NULL);
- ASSERT_EQ(code, 0);
-
- SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
- ASSERT_EQ(res->info.rows, rowNum);
- SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
- ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]);
- }
- taosArrayDestroyEx(blockList, scltFreeDataBlock);
- nodesDestroyNode(opNode);
+ SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL;
+ bool eRes[5] = {true, true, false, false, false};
+ SSDataBlock *src = NULL;
+ char leftv[5][5] = {0};
+ char rightv[3][5] = {0};
+ for (int32_t i = 0; i < 5; ++i) {
+ leftv[i][2] = 'a' + i;
+ leftv[i][3] = 'b' + i;
+ leftv[i][4] = '0' + i;
+ varDataSetLen(leftv[i], 3);
+ }
+ for (int32_t i = 0; i < 2; ++i) {
+ rightv[i][2] = 'a' + i;
+ rightv[i][3] = 'b' + i;
+ rightv[i][4] = '0' + i;
+ varDataSetLen(rightv[i], 3);
+ }
+ for (int32_t i = 2; i < 3; ++i) {
+ rightv[i][2] = 'a' + i;
+ rightv[i][3] = 'a' + i;
+ rightv[i][4] = 'a' + i;
+ varDataSetLen(rightv[i], 3);
+ }
+
+ int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
+ scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
+ SNodeList *list = nodesMakeList();
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[0]);
+ nodesListAppend(list, pRight);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[1]);
+ nodesListAppend(list, pRight);
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[2]);
+ nodesListAppend(list, pRight);
+ scltMakeListNode(&listNode, list, TSDB_DATA_TYPE_BINARY);
+ scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
+
+ SArray *blockList = taosArrayInit(1, POINTER_BYTES);
+ taosArrayPush(blockList, &src);
+ SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool));
+ int16_t dataBlockId = 0, slotId = 0;
+ scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo);
+ scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
+
+ int32_t code = scalarCalculate(opNode, blockList, NULL);
+ ASSERT_EQ(code, 0);
+
+ SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
+ ASSERT_EQ(res->info.rows, rowNum);
+ SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
+ ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]);
+ }
+ taosArrayDestroyEx(blockList, scltFreeDataBlock);
+ nodesDestroyNode(opNode);
}
TEST(columnTest, binary_column_like_binary) {
- SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
- char rightv[64] = {0};
- char leftv[5][5]= {0};
- SSDataBlock *src = NULL;
- bool eRes[5] = {true, false, true, false, true};
-
- for (int32_t i = 0; i < 5; ++i) {
- leftv[i][2] = 'a';
- leftv[i][3] = 'a';
- leftv[i][4] = '0' + i % 2;
- varDataSetLen(leftv[i], 3);
- }
-
- int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
- scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
-
- sprintf(&rightv[2], "%s", "__0");
- varDataSetLen(rightv, strlen(&rightv[2]));
- scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
- scltMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
-
- SArray *blockList = taosArrayInit(1, POINTER_BYTES);
- taosArrayPush(blockList, &src);
- SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool));
- int16_t dataBlockId = 0, slotId = 0;
- scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo);
- scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
-
- int32_t code = scalarCalculate(opNode, blockList, NULL);
- ASSERT_EQ(code, 0);
-
- SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
- ASSERT_EQ(res->info.rows, rowNum);
- SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
- ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]);
- }
-
- taosArrayDestroyEx(blockList, scltFreeDataBlock);
- nodesDestroyNode(opNode);
+ SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
+ char rightv[64] = {0};
+ char leftv[5][5] = {0};
+ SSDataBlock *src = NULL;
+ bool eRes[5] = {true, false, true, false, true};
+
+ for (int32_t i = 0; i < 5; ++i) {
+ leftv[i][2] = 'a';
+ leftv[i][3] = 'a';
+ leftv[i][4] = '0' + i % 2;
+ varDataSetLen(leftv[i], 3);
+ }
+
+ int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
+ scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
+
+ sprintf(&rightv[2], "%s", "__0");
+ varDataSetLen(rightv, strlen(&rightv[2]));
+ scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
+ scltMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
+
+ SArray *blockList = taosArrayInit(1, POINTER_BYTES);
+ taosArrayPush(blockList, &src);
+ SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool));
+ int16_t dataBlockId = 0, slotId = 0;
+ scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo);
+ scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
+
+ int32_t code = scalarCalculate(opNode, blockList, NULL);
+ ASSERT_EQ(code, 0);
+
+ SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
+ ASSERT_EQ(res->info.rows, rowNum);
+ SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
+ ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]);
+ }
+
+ taosArrayDestroyEx(blockList, scltFreeDataBlock);
+ nodesDestroyNode(opNode);
}
TEST(columnTest, binary_column_is_true) {
- SNode *pLeft = NULL, *opNode = NULL;
- char leftv[5][5]= {0};
- SSDataBlock *src = NULL;
- bool eRes[5] = {false, true, false, true, false};
-
- for (int32_t i = 0; i < 5; ++i) {
- leftv[i][2] = '0' + i % 2;
- leftv[i][3] = 'a';
- leftv[i][4] = '0' + i % 2;
- varDataSetLen(leftv[i], 3);
- }
-
- int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
- scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, leftv);
-
- scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, pLeft, NULL);
-
- SArray *blockList = taosArrayInit(1, POINTER_BYTES);
- taosArrayPush(blockList, &src);
- SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool));
- int16_t dataBlockId = 0, slotId = 0;
- scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo);
- scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
-
- int32_t code = scalarCalculate(opNode, blockList, NULL);
- ASSERT_EQ(code, 0);
-
- SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
- ASSERT_EQ(res->info.rows, rowNum);
- SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
- ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]);
- }
- taosArrayDestroyEx(blockList, scltFreeDataBlock);
- nodesDestroyNode(opNode);
+ SNode *pLeft = NULL, *opNode = NULL;
+ char leftv[5][5] = {0};
+ SSDataBlock *src = NULL;
+ bool eRes[5] = {false, true, false, true, false};
+
+ for (int32_t i = 0; i < 5; ++i) {
+ leftv[i][2] = '0' + i % 2;
+ leftv[i][3] = 'a';
+ leftv[i][4] = '0' + i % 2;
+ varDataSetLen(leftv[i], 3);
+ }
+
+ int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
+ scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, leftv);
+
+ scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, pLeft, NULL);
+
+ SArray *blockList = taosArrayInit(1, POINTER_BYTES);
+ taosArrayPush(blockList, &src);
+ SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool));
+ int16_t dataBlockId = 0, slotId = 0;
+ scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo);
+ scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
+
+ int32_t code = scalarCalculate(opNode, blockList, NULL);
+ ASSERT_EQ(code, 0);
+
+ SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
+ ASSERT_EQ(res->info.rows, rowNum);
+ SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
+ ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]);
+ }
+ taosArrayDestroyEx(blockList, scltFreeDataBlock);
+ nodesDestroyNode(opNode);
}
TEST(columnTest, binary_column_is_null) {
- SNode *pLeft = NULL, *opNode = NULL;
- char leftv[5][5]= {0};
- SSDataBlock *src = NULL;
- bool eRes[5] = {false, false, true, false, true};
-
- for (int32_t i = 0; i < 5; ++i) {
- leftv[i][2] = '0' + i % 2;
- leftv[i][3] = 'a';
- leftv[i][4] = '0' + i % 2;
- varDataSetLen(leftv[i], 3);
- }
-
- int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
- scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
-
- SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock);
- colDataAppend(pcolumn, 2, NULL, true);
- colDataAppend(pcolumn, 4, NULL, true);
-
- scltMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL);
-
- SArray *blockList = taosArrayInit(1, POINTER_BYTES);
- taosArrayPush(blockList, &src);
- SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool));
- int16_t dataBlockId = 0, slotId = 0;
- scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo);
- scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
-
- int32_t code = scalarCalculate(opNode, blockList, NULL);
- ASSERT_EQ(code, 0);
-
- SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
- ASSERT_EQ(res->info.rows, rowNum);
- SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
- ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]);
- }
- taosArrayDestroyEx(blockList, scltFreeDataBlock);
- nodesDestroyNode(opNode);
+ SNode *pLeft = NULL, *opNode = NULL;
+ char leftv[5][5] = {0};
+ SSDataBlock *src = NULL;
+ bool eRes[5] = {false, false, true, false, true};
+
+ for (int32_t i = 0; i < 5; ++i) {
+ leftv[i][2] = '0' + i % 2;
+ leftv[i][3] = 'a';
+ leftv[i][4] = '0' + i % 2;
+ varDataSetLen(leftv[i], 3);
+ }
+
+ int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
+ scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
+
+ SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock);
+ colDataAppend(pcolumn, 2, NULL, true);
+ colDataAppend(pcolumn, 4, NULL, true);
+
+ scltMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL);
+
+ SArray *blockList = taosArrayInit(1, POINTER_BYTES);
+ taosArrayPush(blockList, &src);
+ SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool));
+ int16_t dataBlockId = 0, slotId = 0;
+ scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo);
+ scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
+
+ int32_t code = scalarCalculate(opNode, blockList, NULL);
+ ASSERT_EQ(code, 0);
+
+ SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
+ ASSERT_EQ(res->info.rows, rowNum);
+ SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
+ ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]);
+ }
+ taosArrayDestroyEx(blockList, scltFreeDataBlock);
+ nodesDestroyNode(opNode);
}
TEST(columnTest, binary_column_is_not_null) {
- SNode *pLeft = NULL, *opNode = NULL;
- char leftv[5][5]= {0};
- SSDataBlock *src = NULL;
- bool eRes[5] = {true, true, true, true, false};
-
- for (int32_t i = 0; i < 5; ++i) {
- leftv[i][2] = '0' + i % 2;
- leftv[i][3] = 'a';
- leftv[i][4] = '0' + i % 2;
- varDataSetLen(leftv[i], 3);
- }
-
- int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
- scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
-
- SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock);
- colDataAppend(pcolumn, 4, NULL, true);
-
- scltMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL);
-
- SArray *blockList = taosArrayInit(1, POINTER_BYTES);
- taosArrayPush(blockList, &src);
- SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool));
- int16_t dataBlockId = 0, slotId = 0;
- scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo);
- scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
-
- int32_t code = scalarCalculate(opNode, blockList, NULL);
- ASSERT_EQ(code, 0);
-
- SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
- ASSERT_EQ(res->info.rows, rowNum);
- SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
- ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]);
- }
- taosArrayDestroyEx(blockList, scltFreeDataBlock);
- nodesDestroyNode(opNode);
+ SNode *pLeft = NULL, *opNode = NULL;
+ char leftv[5][5] = {0};
+ SSDataBlock *src = NULL;
+ bool eRes[5] = {true, true, true, true, false};
+
+ for (int32_t i = 0; i < 5; ++i) {
+ leftv[i][2] = '0' + i % 2;
+ leftv[i][3] = 'a';
+ leftv[i][4] = '0' + i % 2;
+ varDataSetLen(leftv[i], 3);
+ }
+
+ int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
+ scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
+
+ SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock);
+ colDataAppend(pcolumn, 4, NULL, true);
+
+ scltMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL);
+
+ SArray *blockList = taosArrayInit(1, POINTER_BYTES);
+ taosArrayPush(blockList, &src);
+ SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool));
+ int16_t dataBlockId = 0, slotId = 0;
+ scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo);
+ scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode);
+
+ int32_t code = scalarCalculate(opNode, blockList, NULL);
+ ASSERT_EQ(code, 0);
+
+ SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
+ ASSERT_EQ(res->info.rows, rowNum);
+ SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
+ ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]);
+ }
+ taosArrayDestroyEx(blockList, scltFreeDataBlock);
+ nodesDestroyNode(opNode);
}
TEST(columnTest, greater_and_lower) {
- SNode *pcol1 = NULL, *pcol2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL;
- SNode *list[2] = {0};
- int16_t v1[5]= {1, 2, 3, 4, 5};
- int32_t v2[5]= {5, 1, 4, 2, 6};
- int64_t v3[5]= {1, 2, 3, 4, 5};
- int32_t v4[5]= {5, 3, 4, 2, 6};
- bool eRes[5] = {false, true, false, false, false};
- SSDataBlock *src = NULL;
- int32_t rowNum = sizeof(v1)/sizeof(v1[0]);
- scltMakeColumnNode(&pcol1, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, v1);
- scltMakeColumnNode(&pcol2, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, v2);
- scltMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol1, pcol2);
- scltMakeColumnNode(&pcol1, &src, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), rowNum, v3);
- scltMakeColumnNode(&pcol2, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, v4);
- scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pcol1, pcol2);
- list[0] = opNode1;
- list[1] = opNode2;
- scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2);
-
- SArray *blockList = taosArrayInit(1, POINTER_BYTES);
- taosArrayPush(blockList, &src);
- SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool));
- int16_t dataBlockId = 0, slotId = 0;
- scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo);
- scltMakeTargetNode(&logicNode, dataBlockId, slotId, logicNode);
-
- int32_t code = scalarCalculate(logicNode, blockList, NULL);
- ASSERT_EQ(code, 0);
-
- SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
- ASSERT_EQ(res->info.rows, rowNum);
- SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
- ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL);
- ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]);
- }
- taosArrayDestroyEx(blockList, scltFreeDataBlock);
- nodesDestroyNode(logicNode);
+ SNode *pcol1 = NULL, *pcol2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL;
+ SNode *list[2] = {0};
+ int16_t v1[5] = {1, 2, 3, 4, 5};
+ int32_t v2[5] = {5, 1, 4, 2, 6};
+ int64_t v3[5] = {1, 2, 3, 4, 5};
+ int32_t v4[5] = {5, 3, 4, 2, 6};
+ bool eRes[5] = {false, true, false, false, false};
+ SSDataBlock *src = NULL;
+ int32_t rowNum = sizeof(v1) / sizeof(v1[0]);
+ scltMakeColumnNode(&pcol1, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, v1);
+ scltMakeColumnNode(&pcol2, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, v2);
+ scltMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol1, pcol2);
+ scltMakeColumnNode(&pcol1, &src, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), rowNum, v3);
+ scltMakeColumnNode(&pcol2, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, v4);
+ scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pcol1, pcol2);
+ list[0] = opNode1;
+ list[1] = opNode2;
+ scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2);
+
+ SArray *blockList = taosArrayInit(1, POINTER_BYTES);
+ taosArrayPush(blockList, &src);
+ SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool));
+ int16_t dataBlockId = 0, slotId = 0;
+ scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo);
+ scltMakeTargetNode(&logicNode, dataBlockId, slotId, logicNode);
+
+ int32_t code = scalarCalculate(logicNode, blockList, NULL);
+ ASSERT_EQ(code, 0);
+
+ SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList);
+ ASSERT_EQ(res->info.rows, rowNum);
+ SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock);
+ ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL);
+ ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]);
+ }
+ taosArrayDestroyEx(blockList, scltFreeDataBlock);
+ nodesDestroyNode(logicNode);
}
void scltMakeDataBlock(SScalarParam **pInput, int32_t type, void *pVal, int32_t num, bool setVal) {
- SScalarParam *input = (SScalarParam *)taosMemoryCalloc(1, sizeof(SScalarParam));
- int32_t bytes;
- switch (type) {
- case TSDB_DATA_TYPE_TINYINT: {
- bytes = sizeof(int8_t);
- break;
- }
- case TSDB_DATA_TYPE_SMALLINT: {
- bytes = sizeof(int16_t);
- break;
- }
- case TSDB_DATA_TYPE_INT: {
- bytes = sizeof(int32_t);
- break;
- }
- case TSDB_DATA_TYPE_BIGINT: {
- bytes = sizeof(int64_t);
- break;
- }
- case TSDB_DATA_TYPE_FLOAT: {
- bytes = sizeof(float);
- break;
- }
- case TSDB_DATA_TYPE_DOUBLE: {
- bytes = sizeof(double);
- break;
- }
- }
-
- input->columnData = (SColumnInfoData*) taosMemoryCalloc(1, sizeof(SColumnInfoData));
- input->numOfRows = num;
-
- input->columnData->info = createColumnInfo(0, type, bytes);
- colInfoDataEnsureCapacity(input->columnData, num);
-
- if (setVal) {
- for (int32_t i = 0; i < num; ++i) {
- colDataAppend(input->columnData, i, (const char*) pVal, false);
- }
- } else {
- // memset(input->data, 0, num * bytes);
- }
-
- *pInput = input;
+ SScalarParam *input = (SScalarParam *)taosMemoryCalloc(1, sizeof(SScalarParam));
+ int32_t bytes;
+ switch (type) {
+ case TSDB_DATA_TYPE_TINYINT: {
+ bytes = sizeof(int8_t);
+ break;
+ }
+ case TSDB_DATA_TYPE_SMALLINT: {
+ bytes = sizeof(int16_t);
+ break;
+ }
+ case TSDB_DATA_TYPE_INT: {
+ bytes = sizeof(int32_t);
+ break;
+ }
+ case TSDB_DATA_TYPE_BIGINT: {
+ bytes = sizeof(int64_t);
+ break;
+ }
+ case TSDB_DATA_TYPE_FLOAT: {
+ bytes = sizeof(float);
+ break;
+ }
+ case TSDB_DATA_TYPE_DOUBLE: {
+ bytes = sizeof(double);
+ break;
+ }
+ }
+
+ input->columnData = (SColumnInfoData *)taosMemoryCalloc(1, sizeof(SColumnInfoData));
+ input->numOfRows = num;
+
+ input->columnData->info = createColumnInfo(0, type, bytes);
+ colInfoDataEnsureCapacity(input->columnData, num);
+
+ if (setVal) {
+ for (int32_t i = 0; i < num; ++i) {
+ colDataAppend(input->columnData, i, (const char *)pVal, false);
+ }
+ } else {
+ // memset(input->data, 0, num * bytes);
+ }
+
+ *pInput = input;
}
void scltDestroyDataBlock(SScalarParam *pInput) {
- colDataDestroy(pInput->columnData);
- taosMemoryFree(pInput->columnData);
- taosMemoryFree(pInput);
+ colDataDestroy(pInput->columnData);
+ taosMemoryFree(pInput->columnData);
+ taosMemoryFree(pInput);
}
TEST(ScalarFunctionTest, absFunction_constant) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
-
- //TINYINT
- int8_t val_tinyint = 10;
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), val_tinyint);
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- val_tinyint = -10;
- scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), -val_tinyint);
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //SMALLINT
- int16_t val_smallint = 10;
- type = TSDB_DATA_TYPE_SMALLINT;
- scltMakeDataBlock(&pInput, type, &val_smallint, rowNum, true);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), val_smallint);
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- val_smallint = -10;
- scltMakeDataBlock(&pInput, type, &val_smallint, rowNum, true);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), -val_smallint);
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //INT
- int32_t val_int = 10;
- type = TSDB_DATA_TYPE_INT;
- scltMakeDataBlock(&pInput, type, &val_int, rowNum, true);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), val_int);
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- val_int = -10;
- scltMakeDataBlock(&pInput, type, &val_int, rowNum, true);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), -val_int);
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //BIGINT
- int64_t val_bigint = 10;
- type = TSDB_DATA_TYPE_BIGINT;
- scltMakeDataBlock(&pInput, type, &val_bigint, rowNum, true);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int64_t *)colDataGetData(pOutput->columnData, i)), val_bigint);
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- val_bigint = -10;
- scltMakeDataBlock(&pInput, type, &val_bigint, rowNum, true);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int64_t *)colDataGetData(pOutput->columnData, i)), -val_bigint);
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float = 10.15;
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- PRINTF("float before ABS:%f\n", *(float *)pInput->data);
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), val_float);
- PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- val_float = -10.15;
- scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- PRINTF("float before ABS:%f\n", *(float *)pInput->data);
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), -val_float);
- PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //DOUBLE
- double val_double = 10.15;
- type = TSDB_DATA_TYPE_DOUBLE;
- scltMakeDataBlock(&pInput, type, &val_double, rowNum, true);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), val_double);
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- val_double = -10.15;
- scltMakeDataBlock(&pInput, type, &val_double, rowNum, true);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), -val_double);
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+
+ // TINYINT
+ int8_t val_tinyint = 10;
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), val_tinyint);
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ val_tinyint = -10;
+ scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), -val_tinyint);
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // SMALLINT
+ int16_t val_smallint = 10;
+ type = TSDB_DATA_TYPE_SMALLINT;
+ scltMakeDataBlock(&pInput, type, &val_smallint, rowNum, true);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), val_smallint);
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ val_smallint = -10;
+ scltMakeDataBlock(&pInput, type, &val_smallint, rowNum, true);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), -val_smallint);
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // INT
+ int32_t val_int = 10;
+ type = TSDB_DATA_TYPE_INT;
+ scltMakeDataBlock(&pInput, type, &val_int, rowNum, true);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), val_int);
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ val_int = -10;
+ scltMakeDataBlock(&pInput, type, &val_int, rowNum, true);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), -val_int);
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // BIGINT
+ int64_t val_bigint = 10;
+ type = TSDB_DATA_TYPE_BIGINT;
+ scltMakeDataBlock(&pInput, type, &val_bigint, rowNum, true);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int64_t *)colDataGetData(pOutput->columnData, i)), val_bigint);
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ val_bigint = -10;
+ scltMakeDataBlock(&pInput, type, &val_bigint, rowNum, true);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int64_t *)colDataGetData(pOutput->columnData, i)), -val_bigint);
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float = 10.15;
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ PRINTF("float before ABS:%f\n", *(float *)pInput->data);
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), val_float);
+ PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ val_float = -10.15;
+ scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ PRINTF("float before ABS:%f\n", *(float *)pInput->data);
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), -val_float);
+ PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // DOUBLE
+ double val_double = 10.15;
+ type = TSDB_DATA_TYPE_DOUBLE;
+ scltMakeDataBlock(&pInput, type, &val_double, rowNum, true);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), val_double);
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ val_double = -10.15;
+ scltMakeDataBlock(&pInput, type, &val_double, rowNum, true);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), -val_double);
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, absFunction_column) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 5;
- int32_t type;
-
- //TINYINT
- int8_t val_tinyint = 10;
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- int8_t v = val_tinyint + i;
- colDataAppend(pInput->columnData, i, (const char*) &v, false);
- PRINTF("tiny_int before ABS:%d\n", v);
- }
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), val_tinyint + i);
- PRINTF("tiny_int after ABS:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- val_tinyint = -10;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- int8_t v = val_tinyint + i;
- colDataAppend(pInput->columnData, i, (const char*) &v, false);
- PRINTF("tiny_int before ABS:%d\n", v);
- }
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), -(val_tinyint + i));
- PRINTF("tiny_int after ABS:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //SMALLINT
- int16_t val_smallint = 10;
- type = TSDB_DATA_TYPE_SMALLINT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- int16_t v = val_smallint + i;
- colDataAppend(pInput->columnData, i, (const char*) &v, false);
- PRINTF("small_int before ABS:%d\n", v);
- }
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), val_smallint + i);
- PRINTF("small_int after ABS:%d\n", *((int16_t *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- val_smallint = -10;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- int16_t v = val_smallint + i;
- colDataAppend(pInput->columnData, i, (const char*) &v, false);
- PRINTF("small_int before ABS:%d\n", v);
- }
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), -(val_smallint + i));
- PRINTF("small_int after ABS:%d\n", *((int16_t *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //INT
- int32_t val_int = 10;
- type = TSDB_DATA_TYPE_INT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- int32_t v = val_int + i;
- colDataAppend(pInput->columnData, i, (const char*) &v, false);
- PRINTF("int before ABS:%d\n", v);
- }
-
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), val_int + i);
- PRINTF("int after ABS:%d\n", *((int32_t *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- val_int = -10;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- int32_t v = val_int + i;
- colDataAppend(pInput->columnData, i, (const char*) &v, false);
- PRINTF("int before ABS:%d\n", v);
- }
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), -(val_int + i));
- PRINTF("int after ABS:%d\n", *((int32_t *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float = 10.15;
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- float v = val_float + i;
- colDataAppend(pInput->columnData, i, (const char*) &v, false);
- PRINTF("float before ABS:%f\n", v);
- }
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), val_float + i);
- PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- val_float = -10.15;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- float v = val_float + i;
- colDataAppend(pInput->columnData, i, (const char*) &v, false);
- PRINTF("float before ABS:%f\n", v);
- }
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), -(val_float + i));
- PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //DOUBLE
- double val_double = 10.15;
- type = TSDB_DATA_TYPE_DOUBLE;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- double v = val_double + i;
- colDataAppend(pInput->columnData, i, (const char*) &v, false);
- PRINTF("double before ABS:%f\n", v);
- }
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), val_double + i);
- PRINTF("double after ABS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- val_double = -10.15;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- double v = val_double + i;
- colDataAppend(pInput->columnData, i, (const char*) &v, false);
- PRINTF("double before ABS:%f\n", v);
- }
-
- code = absFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), -(val_double + i));
- PRINTF("double after ABS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 5;
+ int32_t type;
+
+ // TINYINT
+ int8_t val_tinyint = 10;
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ int8_t v = val_tinyint + i;
+ colDataAppend(pInput->columnData, i, (const char *)&v, false);
+ PRINTF("tiny_int before ABS:%d\n", v);
+ }
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), val_tinyint + i);
+ PRINTF("tiny_int after ABS:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ val_tinyint = -10;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ int8_t v = val_tinyint + i;
+ colDataAppend(pInput->columnData, i, (const char *)&v, false);
+ PRINTF("tiny_int before ABS:%d\n", v);
+ }
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), -(val_tinyint + i));
+ PRINTF("tiny_int after ABS:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // SMALLINT
+ int16_t val_smallint = 10;
+ type = TSDB_DATA_TYPE_SMALLINT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ int16_t v = val_smallint + i;
+ colDataAppend(pInput->columnData, i, (const char *)&v, false);
+ PRINTF("small_int before ABS:%d\n", v);
+ }
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), val_smallint + i);
+ PRINTF("small_int after ABS:%d\n", *((int16_t *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ val_smallint = -10;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ int16_t v = val_smallint + i;
+ colDataAppend(pInput->columnData, i, (const char *)&v, false);
+ PRINTF("small_int before ABS:%d\n", v);
+ }
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), -(val_smallint + i));
+ PRINTF("small_int after ABS:%d\n", *((int16_t *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // INT
+ int32_t val_int = 10;
+ type = TSDB_DATA_TYPE_INT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ int32_t v = val_int + i;
+ colDataAppend(pInput->columnData, i, (const char *)&v, false);
+ PRINTF("int before ABS:%d\n", v);
+ }
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), val_int + i);
+ PRINTF("int after ABS:%d\n", *((int32_t *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ val_int = -10;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ int32_t v = val_int + i;
+ colDataAppend(pInput->columnData, i, (const char *)&v, false);
+ PRINTF("int before ABS:%d\n", v);
+ }
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), -(val_int + i));
+ PRINTF("int after ABS:%d\n", *((int32_t *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float = 10.15;
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ float v = val_float + i;
+ colDataAppend(pInput->columnData, i, (const char *)&v, false);
+ PRINTF("float before ABS:%f\n", v);
+ }
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), val_float + i);
+ PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ val_float = -10.15;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ float v = val_float + i;
+ colDataAppend(pInput->columnData, i, (const char *)&v, false);
+ PRINTF("float before ABS:%f\n", v);
+ }
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), -(val_float + i));
+ PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // DOUBLE
+ double val_double = 10.15;
+ type = TSDB_DATA_TYPE_DOUBLE;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ double v = val_double + i;
+ colDataAppend(pInput->columnData, i, (const char *)&v, false);
+ PRINTF("double before ABS:%f\n", v);
+ }
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), val_double + i);
+ PRINTF("double after ABS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ val_double = -10.15;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ double v = val_double + i;
+ colDataAppend(pInput->columnData, i, (const char *)&v, false);
+ PRINTF("double before ABS:%f\n", v);
+ }
+
+ code = absFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), -(val_double + i));
+ PRINTF("double after ABS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, sinFunction_constant) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- int32_t otype = TSDB_DATA_TYPE_DOUBLE;
- double result = 0.42016703682664092;
-
- //TINYINT
- int8_t val_tinyint = 13;
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- PRINTF("tiny_int before SIN:%d\n", *((int8_t *)pInput->data));
-
- code = sinFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("tiny_int after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float = 13.00;
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- PRINTF("float before SIN:%f\n", *((float *)pInput->data));
-
- code = sinFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("float after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ int32_t otype = TSDB_DATA_TYPE_DOUBLE;
+ double result = 0.42016703682664092;
+
+ // TINYINT
+ int8_t val_tinyint = 13;
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ PRINTF("tiny_int before SIN:%d\n", *((int8_t *)pInput->data));
+
+ code = sinFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("tiny_int after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float = 13.00;
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ PRINTF("float before SIN:%f\n", *((float *)pInput->data));
+
+ code = sinFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("float after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, sinFunction_column) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- int32_t otype = TSDB_DATA_TYPE_DOUBLE;
- double result[] = {0.42016703682664092, 0.99060735569487035, 0.65028784015711683};
-
-
- //TINYINT
- int8_t val_tinyint[] = {13, 14, 15};
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false);
- PRINTF("tiny_int before SIN:%d\n", *(int8_t *)colDataGetData(pInput->columnData, i));
- }
-
- code = sinFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("tiny_int after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float[] = {13.00, 14.00, 15.00};
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- colDataAppend(pInput->columnData, i, (const char*) &val_float[i], false);
- PRINTF("float before SIN:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
- }
-
- code = sinFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("float after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ int32_t otype = TSDB_DATA_TYPE_DOUBLE;
+ double result[] = {0.42016703682664092, 0.99060735569487035, 0.65028784015711683};
+
+ // TINYINT
+ int8_t val_tinyint[] = {13, 14, 15};
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ colDataAppend(pInput->columnData, i, (const char *)&val_tinyint[i], false);
+ PRINTF("tiny_int before SIN:%d\n", *(int8_t *)colDataGetData(pInput->columnData, i));
+ }
+
+ code = sinFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("tiny_int after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float[] = {13.00, 14.00, 15.00};
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ colDataAppend(pInput->columnData, i, (const char *)&val_float[i], false);
+ PRINTF("float before SIN:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
+ }
+
+ code = sinFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("float after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, cosFunction_constant) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- int32_t otype = TSDB_DATA_TYPE_DOUBLE;
- double result = 0.90744678145019619;
-
- //TINYINT
- int8_t val_tinyint = 13;
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- PRINTF("tiny_int before COS:%d\n", *((int8_t *)pInput->data));
-
- code = cosFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("tiny_int after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float = 13.00;
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- PRINTF("float before COS:%f\n", *((float *)pInput->data));
-
- code = cosFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("float after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ int32_t otype = TSDB_DATA_TYPE_DOUBLE;
+ double result = 0.90744678145019619;
+
+ // TINYINT
+ int8_t val_tinyint = 13;
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ PRINTF("tiny_int before COS:%d\n", *((int8_t *)pInput->data));
+
+ code = cosFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("tiny_int after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float = 13.00;
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ PRINTF("float before COS:%f\n", *((float *)pInput->data));
+
+ code = cosFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("float after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, cosFunction_column) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- int32_t otype = TSDB_DATA_TYPE_DOUBLE;
- double result[] = {0.90744678145019619, 0.13673721820783361, -0.75968791285882131};
-
- //TINYINT
- int8_t val_tinyint[] = {13, 14, 15};
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false);
- PRINTF("tiny_int before COS:%d\n", *(int8_t *)colDataGetData(pInput->columnData, i));
- }
-
- code = cosFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("tiny_int after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float[] = {13.00, 14.00, 15.00};
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- colDataAppend(pInput->columnData, i, (const char*) &val_float[i], false);
- PRINTF("float before COS:%f\n", *(float *)colDataGetData(pInput->columnData, i));
- }
-
- code = cosFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("float after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ int32_t otype = TSDB_DATA_TYPE_DOUBLE;
+ double result[] = {0.90744678145019619, 0.13673721820783361, -0.75968791285882131};
+
+ // TINYINT
+ int8_t val_tinyint[] = {13, 14, 15};
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ colDataAppend(pInput->columnData, i, (const char *)&val_tinyint[i], false);
+ PRINTF("tiny_int before COS:%d\n", *(int8_t *)colDataGetData(pInput->columnData, i));
+ }
+
+ code = cosFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("tiny_int after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float[] = {13.00, 14.00, 15.00};
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ colDataAppend(pInput->columnData, i, (const char *)&val_float[i], false);
+ PRINTF("float before COS:%f\n", *(float *)colDataGetData(pInput->columnData, i));
+ }
+
+ code = cosFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("float after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, tanFunction_constant) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- int32_t otype = TSDB_DATA_TYPE_DOUBLE;
- double result = 0.46302113293648961;
-
- //TINYINT
- int8_t val_tinyint = 13;
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- PRINTF("tiny_int before TAN:%d\n", *((int8_t *)pInput->data));
-
- code = tanFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("tiny_int after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float = 13.00;
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- PRINTF("float before TAN:%f\n", *((float *)pInput->data));
-
- code = tanFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("float after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ int32_t otype = TSDB_DATA_TYPE_DOUBLE;
+ double result = 0.46302113293648961;
+
+ // TINYINT
+ int8_t val_tinyint = 13;
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ PRINTF("tiny_int before TAN:%d\n", *((int8_t *)pInput->data));
+
+ code = tanFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("tiny_int after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float = 13.00;
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ PRINTF("float before TAN:%f\n", *((float *)pInput->data));
+
+ code = tanFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("float after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, tanFunction_column) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- int32_t otype = TSDB_DATA_TYPE_DOUBLE;
- double result[] = {0.46302113293648961, 7.24460661609480550, -0.85599340090851872};
-
- //TINYINT
- int8_t val_tinyint[] = {13, 14, 15};
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false);
- PRINTF("tiny_int before TAN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
- }
-
- code = tanFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_NEAR(*((double *)colDataGetData(pOutput->columnData, i)), result[i], 1e-15);
- PRINTF("tiny_int after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float[] = {13.00, 14.00, 15.00};
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- colDataAppend(pInput->columnData, i, (const char*) &val_float[i], false);
- PRINTF("float before TAN:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
- }
-
- code = tanFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_NEAR(*((double *)colDataGetData(pOutput->columnData, i)), result[i], 1e-15);
- PRINTF("float after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ int32_t otype = TSDB_DATA_TYPE_DOUBLE;
+ double result[] = {0.46302113293648961, 7.24460661609480550, -0.85599340090851872};
+
+ // TINYINT
+ int8_t val_tinyint[] = {13, 14, 15};
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ colDataAppend(pInput->columnData, i, (const char *)&val_tinyint[i], false);
+ PRINTF("tiny_int before TAN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
+ }
+
+ code = tanFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_NEAR(*((double *)colDataGetData(pOutput->columnData, i)), result[i], 1e-15);
+ PRINTF("tiny_int after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float[] = {13.00, 14.00, 15.00};
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ colDataAppend(pInput->columnData, i, (const char *)&val_float[i], false);
+ PRINTF("float before TAN:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
+ }
+
+ code = tanFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_NEAR(*((double *)colDataGetData(pOutput->columnData, i)), result[i], 1e-15);
+ PRINTF("float after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, asinFunction_constant) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- int32_t otype = TSDB_DATA_TYPE_DOUBLE;
- double result = 1.57079632679489656;
-
- //TINYINT
- int8_t val_tinyint = 1;
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- PRINTF("tiny_int before ASIN:%d\n", *((int8_t *)pInput->data));
-
- code = asinFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("tiny_int after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float = 1.00;
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- PRINTF("float before ASIN:%f\n", *((float *)pInput->data));
-
- code = asinFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("float after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ int32_t otype = TSDB_DATA_TYPE_DOUBLE;
+ double result = 1.57079632679489656;
+
+ // TINYINT
+ int8_t val_tinyint = 1;
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ PRINTF("tiny_int before ASIN:%d\n", *((int8_t *)pInput->data));
+
+ code = asinFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("tiny_int after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float = 1.00;
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ PRINTF("float before ASIN:%f\n", *((float *)pInput->data));
+
+ code = asinFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("float after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, asinFunction_column) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- int32_t otype = TSDB_DATA_TYPE_DOUBLE;
- double result[] = {-1.57079632679489656, 0.0, 1.57079632679489656};
-
-
- //TINYINT
- int8_t val_tinyint[] = {-1, 0, 1};
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false);
- PRINTF("tiny_int before ASIN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
- }
-
- code = asinFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("tiny_int after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float[] = {-1.0, 0.0, 1.0};
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
- PRINTF("float before ASIN:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
- }
-
- code = asinFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("float after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ int32_t otype = TSDB_DATA_TYPE_DOUBLE;
+ double result[] = {-1.57079632679489656, 0.0, 1.57079632679489656};
+
+ // TINYINT
+ int8_t val_tinyint[] = {-1, 0, 1};
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ colDataAppend(pInput->columnData, i, (const char *)&val_tinyint[i], false);
+ PRINTF("tiny_int before ASIN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
+ }
+
+ code = asinFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("tiny_int after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float[] = {-1.0, 0.0, 1.0};
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
+ PRINTF("float before ASIN:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
+ }
+
+ code = asinFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("float after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, acosFunction_constant) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- int32_t otype = TSDB_DATA_TYPE_DOUBLE;
- double result = 0.0;
-
- //TINYINT
- int8_t val_tinyint = 1;
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- PRINTF("tiny_int before ACOS:%d\n", *((int8_t *)pInput->data));
-
- code = acosFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("tiny_int after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float = 1.00;
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- PRINTF("float before ACOS:%f\n", *((float *)pInput->data));
-
- code = acosFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("float after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ int32_t otype = TSDB_DATA_TYPE_DOUBLE;
+ double result = 0.0;
+
+ // TINYINT
+ int8_t val_tinyint = 1;
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ PRINTF("tiny_int before ACOS:%d\n", *((int8_t *)pInput->data));
+
+ code = acosFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("tiny_int after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float = 1.00;
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ PRINTF("float before ACOS:%f\n", *((float *)pInput->data));
+
+ code = acosFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("float after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, acosFunction_column) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- int32_t otype = TSDB_DATA_TYPE_DOUBLE;
- double result[] = {3.14159265358979312, 1.57079632679489656, 0.0};
-
- //TINYINT
- int8_t val_tinyint[] = {-1, 0, 1};
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i];
- PRINTF("tiny_int before ACOS:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
- }
-
- code = acosFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("tiny_int after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float[] = {-1.0, 0.0, 1.0};
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
- PRINTF("float before ACOS:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
- }
-
- code = acosFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("float after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ int32_t otype = TSDB_DATA_TYPE_DOUBLE;
+ double result[] = {3.14159265358979312, 1.57079632679489656, 0.0};
+
+ // TINYINT
+ int8_t val_tinyint[] = {-1, 0, 1};
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i];
+ PRINTF("tiny_int before ACOS:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
+ }
+
+ code = acosFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("tiny_int after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float[] = {-1.0, 0.0, 1.0};
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
+ PRINTF("float before ACOS:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
+ }
+
+ code = acosFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("float after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, atanFunction_constant) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- int32_t otype = TSDB_DATA_TYPE_DOUBLE;
- double result = 0.78539816339744828;
-
- //TINYINT
- int8_t val_tinyint = 1;
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- PRINTF("tiny_int before ATAN:%d\n", *((int8_t *)pInput->data));
-
- code = atanFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("tiny_int after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float = 1.00;
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- PRINTF("float before ATAN:%f\n", *((float *)pInput->data));
-
- code = atanFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("float after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ int32_t otype = TSDB_DATA_TYPE_DOUBLE;
+ double result = 0.78539816339744828;
+
+ // TINYINT
+ int8_t val_tinyint = 1;
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ PRINTF("tiny_int before ATAN:%d\n", *((int8_t *)pInput->data));
+
+ code = atanFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("tiny_int after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float = 1.00;
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ PRINTF("float before ATAN:%f\n", *((float *)pInput->data));
+
+ code = atanFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("float after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, atanFunction_column) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- int32_t otype = TSDB_DATA_TYPE_DOUBLE;
- double result[] = {-0.78539816339744828, 0.0, 0.78539816339744828};
-
- //TINYINT
- int8_t val_tinyint[] = {-1, 0, 1};
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i];
- PRINTF("tiny_int before ATAN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
- }
-
- code = atanFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("tiny_int after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float[] = {-1.0, 0.0, 1.0};
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
- PRINTF("float before ATAN:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
- }
-
- code = atanFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("float after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ int32_t otype = TSDB_DATA_TYPE_DOUBLE;
+ double result[] = {-0.78539816339744828, 0.0, 0.78539816339744828};
+
+ // TINYINT
+ int8_t val_tinyint[] = {-1, 0, 1};
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i];
+ PRINTF("tiny_int before ATAN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
+ }
+
+ code = atanFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("tiny_int after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float[] = {-1.0, 0.0, 1.0};
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
+ PRINTF("float before ATAN:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
+ }
+
+ code = atanFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("float after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, ceilFunction_constant) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- double result = 10.0;
-
- //TINYINT
- int8_t val_tinyint = 10;
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- PRINTF("tiny_int before CEIL:%d\n", *((int8_t *)pInput->data));
-
- code = ceilFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), (int8_t)result);
- PRINTF("tiny_int after CEIL:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float = 9.5;
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- PRINTF("float before CEIL:%f\n", *((float *)pInput->data));
-
- code = ceilFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), (float)result);
- PRINTF("float after CEIL:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ double result = 10.0;
+
+ // TINYINT
+ int8_t val_tinyint = 10;
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ PRINTF("tiny_int before CEIL:%d\n", *((int8_t *)pInput->data));
+
+ code = ceilFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), (int8_t)result);
+ PRINTF("tiny_int after CEIL:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float = 9.5;
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ PRINTF("float before CEIL:%f\n", *((float *)pInput->data));
+
+ code = ceilFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), (float)result);
+ PRINTF("float after CEIL:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, ceilFunction_column) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- double result[] = {-10.0, 0.0, 10.0};
-
- //TINYINT
- int8_t val_tinyint[] = {-10, 0, 10};
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i];
- PRINTF("tiny_int before CEIL:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
- }
-
- code = ceilFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("tiny_int after CEIL:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float[] = {-10.5, 0.0, 9.5};
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
- PRINTF("float before CEIL:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
- }
-
- code = ceilFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("float after CEIL:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ double result[] = {-10.0, 0.0, 10.0};
+
+ // TINYINT
+ int8_t val_tinyint[] = {-10, 0, 10};
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i];
+ PRINTF("tiny_int before CEIL:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
+ }
+
+ code = ceilFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("tiny_int after CEIL:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float[] = {-10.5, 0.0, 9.5};
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
+ PRINTF("float before CEIL:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
+ }
+
+ code = ceilFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("float after CEIL:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, floorFunction_constant) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- double result = 10.0;
-
- //TINYINT
- int8_t val_tinyint = 10;
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- PRINTF("tiny_int before FLOOR:%d\n", *((int8_t *)pInput->data));
-
- code = floorFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), (int8_t)result);
- PRINTF("tiny_int after FLOOR:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float = 10.5;
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- PRINTF("float before FLOOR:%f\n", *((float *)pInput->data));
-
- code = floorFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), (float)result);
- PRINTF("float after FLOOR:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ double result = 10.0;
+
+ // TINYINT
+ int8_t val_tinyint = 10;
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ PRINTF("tiny_int before FLOOR:%d\n", *((int8_t *)pInput->data));
+
+ code = floorFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), (int8_t)result);
+ PRINTF("tiny_int after FLOOR:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float = 10.5;
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ PRINTF("float before FLOOR:%f\n", *((float *)pInput->data));
+
+ code = floorFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), (float)result);
+ PRINTF("float after FLOOR:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, floorFunction_column) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- double result[] = {-10.0, 0.0, 10.0};
-
- //TINYINT
- int8_t val_tinyint[] = {-10, 0, 10};
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i];
- PRINTF("tiny_int before FLOOR:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
- }
-
- code = floorFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("tiny_int after FLOOR:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float[] = {-9.5, 0.0, 10.5};
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
- PRINTF("float before FLOOR:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
- }
-
- code = floorFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("float after FLOOR:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ double result[] = {-10.0, 0.0, 10.0};
+
+ // TINYINT
+ int8_t val_tinyint[] = {-10, 0, 10};
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i];
+ PRINTF("tiny_int before FLOOR:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
+ }
+
+ code = floorFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("tiny_int after FLOOR:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float[] = {-9.5, 0.0, 10.5};
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
+ PRINTF("float before FLOOR:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
+ }
+
+ code = floorFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("float after FLOOR:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, roundFunction_constant) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- double result = 10.0;
-
- //TINYINT
- int8_t val_tinyint = 10;
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- PRINTF("tiny_int before ROUND:%d\n", *((int8_t *)pInput->data));
-
- code = roundFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), (int8_t)result);
- PRINTF("tiny_int after ROUND:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float = 9.5;
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- PRINTF("float before ROUND:%f\n", *((float *)pInput->data));
-
- code = roundFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), (float)result);
- PRINTF("float after ROUND:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ double result = 10.0;
+
+ // TINYINT
+ int8_t val_tinyint = 10;
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ PRINTF("tiny_int before ROUND:%d\n", *((int8_t *)pInput->data));
+
+ code = roundFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), (int8_t)result);
+ PRINTF("tiny_int after ROUND:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float = 9.5;
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ PRINTF("float before ROUND:%f\n", *((float *)pInput->data));
+
+ code = roundFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), (float)result);
+ PRINTF("float after ROUND:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, roundFunction_column) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- double result[] = {-10.0, 0.0, 10.0};
-
- //TINYINT
- int8_t val_tinyint[] = {-10, 0, 10};
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i];
- PRINTF("tiny_int before ROUND:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
- }
-
- code = roundFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("tiny_int after ROUND:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float[] = {-9.5, 0.0, 9.5};
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
- PRINTF("float before ROUND:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
- }
-
- code = roundFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("float after ROUND:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ double result[] = {-10.0, 0.0, 10.0};
+
+ // TINYINT
+ int8_t val_tinyint[] = {-10, 0, 10};
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i];
+ PRINTF("tiny_int before ROUND:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
+ }
+
+ code = roundFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("tiny_int after ROUND:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float[] = {-9.5, 0.0, 9.5};
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
+ PRINTF("float before ROUND:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
+ }
+
+ code = roundFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("float after ROUND:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, sqrtFunction_constant) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- int32_t otype = TSDB_DATA_TYPE_DOUBLE;
- double result = 5.0;
-
- //TINYINT
- int8_t val_tinyint = 25;
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- PRINTF("tiny_int before SQRT:%d\n", *((int8_t *)pInput->data));
-
- code = sqrtFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("tiny_int after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float = 25.0;
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- PRINTF("float before SQRT:%f\n", *((float *)pInput->data));
-
- code = sqrtFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("float after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ int32_t otype = TSDB_DATA_TYPE_DOUBLE;
+ double result = 5.0;
+
+ // TINYINT
+ int8_t val_tinyint = 25;
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ PRINTF("tiny_int before SQRT:%d\n", *((int8_t *)pInput->data));
+
+ code = sqrtFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("tiny_int after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float = 25.0;
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ PRINTF("float before SQRT:%f\n", *((float *)pInput->data));
+
+ code = sqrtFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("float after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, sqrtFunction_column) {
- SScalarParam *pInput, *pOutput;
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- int32_t otype = TSDB_DATA_TYPE_DOUBLE;
- double result[] = {5.0, 9.0, 10.0};
-
- //TINYINT
- int8_t val_tinyint[] = {25, 81, 100};
- type = TSDB_DATA_TYPE_TINYINT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i];
- PRINTF("tiny_int before SQRT:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
- }
-
- code = sqrtFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("tiny_int after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float[] = {25.0, 81.0, 100.0};
- type = TSDB_DATA_TYPE_FLOAT;
- scltMakeDataBlock(&pInput, type, 0, rowNum, false);
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- for (int32_t i = 0; i < rowNum; ++i) {
- *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
- PRINTF("float before SQRT:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
- }
-
- code = sqrtFunction(pInput, 1, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("float after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(pInput);
- scltDestroyDataBlock(pOutput);
+ SScalarParam *pInput, *pOutput;
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ int32_t otype = TSDB_DATA_TYPE_DOUBLE;
+ double result[] = {5.0, 9.0, 10.0};
+
+ // TINYINT
+ int8_t val_tinyint[] = {25, 81, 100};
+ type = TSDB_DATA_TYPE_TINYINT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i];
+ PRINTF("tiny_int before SQRT:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
+ }
+
+ code = sqrtFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("tiny_int after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float[] = {25.0, 81.0, 100.0};
+ type = TSDB_DATA_TYPE_FLOAT;
+ scltMakeDataBlock(&pInput, type, 0, rowNum, false);
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
+ PRINTF("float before SQRT:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
+ }
+
+ code = sqrtFunction(pInput, 1, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("float after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(pInput);
+ scltDestroyDataBlock(pOutput);
}
TEST(ScalarFunctionTest, logFunction_constant) {
- SScalarParam *pInput, *pOutput;
- SScalarParam *input[2];
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- int32_t otype = TSDB_DATA_TYPE_DOUBLE;
- double result = 3.0;
- pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam));
-
- //TINYINT
- int8_t val_tinyint[] = {27, 3};
- type = TSDB_DATA_TYPE_TINYINT;
- for (int32_t i = 0; i < 2; ++i) {
- scltMakeDataBlock(&input[i], type, &val_tinyint[i], rowNum, true);
- pInput[i] = *input[i];
- }
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- PRINTF("tiny_int before LOG: %d,%d\n", *((int8_t *)pInput[0].data),
- *((int8_t *)pInput[1].data));
-
- code = logFunction(pInput, 2, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("tiny_int after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(input[0]);
- scltDestroyDataBlock(input[1]);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float[] = {64.0, 4.0};
- type = TSDB_DATA_TYPE_FLOAT;
- for (int32_t i = 0; i < 2; ++i) {
- scltMakeDataBlock(&input[i], type, &val_float[i], rowNum, true);
- pInput[i] = *input[i];
- }
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- PRINTF("float before LOG: %f,%f\n", *((float *)pInput[0].data),
- *((float *)pInput[1].data));
-
- code = logFunction(pInput, 2, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(input[0]);
- scltDestroyDataBlock(input[1]);
- scltDestroyDataBlock(pOutput);
-
- //TINYINT AND FLOAT
- int8_t param0 = 64;
- float param1 = 4.0;
- scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, ¶m0, rowNum, true);
- pInput[0] = *input[0];
- scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, ¶m1, rowNum, true);
- pInput[1] = *input[1];
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
-
- PRINTF("tiny_int,float before LOG: %d,%f\n", *((int8_t *)pInput[0].data), *((float *)pInput[1].data));
-
- code = logFunction(pInput, 2, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("tiny_int,float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(input[0]);
- scltDestroyDataBlock(input[1]);
- scltDestroyDataBlock(pOutput);
- taosMemoryFree(pInput);
+ SScalarParam *pInput, *pOutput;
+ SScalarParam *input[2];
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ int32_t otype = TSDB_DATA_TYPE_DOUBLE;
+ double result = 3.0;
+ pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam));
+
+ // TINYINT
+ int8_t val_tinyint[] = {27, 3};
+ type = TSDB_DATA_TYPE_TINYINT;
+ for (int32_t i = 0; i < 2; ++i) {
+ scltMakeDataBlock(&input[i], type, &val_tinyint[i], rowNum, true);
+ pInput[i] = *input[i];
+ }
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ PRINTF("tiny_int before LOG: %d,%d\n", *((int8_t *)pInput[0].data), *((int8_t *)pInput[1].data));
+
+ code = logFunction(pInput, 2, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("tiny_int after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(input[0]);
+ scltDestroyDataBlock(input[1]);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float[] = {64.0, 4.0};
+ type = TSDB_DATA_TYPE_FLOAT;
+ for (int32_t i = 0; i < 2; ++i) {
+ scltMakeDataBlock(&input[i], type, &val_float[i], rowNum, true);
+ pInput[i] = *input[i];
+ }
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ PRINTF("float before LOG: %f,%f\n", *((float *)pInput[0].data), *((float *)pInput[1].data));
+
+ code = logFunction(pInput, 2, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(input[0]);
+ scltDestroyDataBlock(input[1]);
+ scltDestroyDataBlock(pOutput);
+
+ // TINYINT AND FLOAT
+ int8_t param0 = 64;
+ float param1 = 4.0;
+ scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, ¶m0, rowNum, true);
+ pInput[0] = *input[0];
+ scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, ¶m1, rowNum, true);
+ pInput[1] = *input[1];
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+
+ PRINTF("tiny_int,float before LOG: %d,%f\n", *((int8_t *)pInput[0].data), *((float *)pInput[1].data));
+
+ code = logFunction(pInput, 2, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("tiny_int,float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(input[0]);
+ scltDestroyDataBlock(input[1]);
+ scltDestroyDataBlock(pOutput);
+ taosMemoryFree(pInput);
}
TEST(ScalarFunctionTest, logFunction_column) {
- SScalarParam *pInput, *pOutput;
- SScalarParam *input[2];
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- int32_t otype = TSDB_DATA_TYPE_DOUBLE;
- double result[] = {2.0, 3.0, 4.0};
- pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam));
-
- //TINYINT
- int8_t val_tinyint[2][3] = {{9, 27, 81}, {3, 3, 3}};
- type = TSDB_DATA_TYPE_TINYINT;
- for (int32_t i = 0; i < 2; ++i) {
- scltMakeDataBlock(&input[i], type, 0, rowNum, false);
- pInput[i] = *input[i];
- for (int32_t j = 0; j < rowNum; ++j) {
- colDataAppend(pInput[i].columnData, j, (const char*) &val_tinyint[i][j], false);
-
- }
- PRINTF("tiny_int before LOG:%d,%d,%d\n", *((int8_t *)pInput[i].data + 0),
- *((int8_t *)pInput[i].data + 1),
- *((int8_t *)pInput[i].data + 2));
- }
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
-
- code = logFunction(pInput, 2, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("tiny_int after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(input[0]);
- scltDestroyDataBlock(input[1]);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float[2][3] = {{9.0, 27.0, 81.0}, {3.0, 3.0, 3.0}};
- type = TSDB_DATA_TYPE_FLOAT;
- for (int32_t i = 0; i < 2; ++i) {
- scltMakeDataBlock(&input[i], type, 0, rowNum, false);
- pInput[i] = *input[i];
- for (int32_t j = 0; j < rowNum; ++j) {
- colDataAppend(pInput[i].columnData, j, (const char*) &val_float[i][j], false);
- }
- PRINTF("float before LOG:%f,%f,%f\n", *((float *)colDataGetData(pInput[i], 0)),
- *((float *)colDataGetData(pInput[i], 1)),
- *((float *)colDataGetData(pInput[i], 2)));
- }
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
-
- code = logFunction(pInput, 2, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(input[0]);
- scltDestroyDataBlock(input[1]);
- scltDestroyDataBlock(pOutput);
-
- //TINYINT AND FLOAT
- int8_t param0[] = {9, 27, 81};
- float param1[] = {3.0, 3.0, 3.0};
- scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, 0, rowNum, false);
- pInput[0] = *input[0];
- for (int32_t i = 0; i < rowNum; ++i) {
- colDataAppend(pInput[0].columnData, i, (const char*) ¶m0[i], false);
-
- }
- scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, 0, rowNum, false);
- pInput[1] = *input[1];
- for (int32_t i = 0; i < rowNum; ++i) {
- colDataAppend(pInput[1].columnData, i, (const char*) ¶m1[i], false);
-
- }
- PRINTF("tiny_int, float before LOG:{%d,%f}, {%d,%f}, {%d,%f}\n", *((int8_t *)pInput[0].data + 0), *((float *)pInput[1].data + 0),
- *((int8_t *)pInput[0].data + 1), *((float *)pInput[1].data + 1),
- *((int8_t *)pInput[0].data + 2), *((float *)pInput[1].data + 2));
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
-
- code = logFunction(pInput, 2, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("tiny_int,float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(input[0]);
- scltDestroyDataBlock(input[1]);
- scltDestroyDataBlock(pOutput);
- taosMemoryFree(pInput);
+ SScalarParam *pInput, *pOutput;
+ SScalarParam *input[2];
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ int32_t otype = TSDB_DATA_TYPE_DOUBLE;
+ double result[] = {2.0, 3.0, 4.0};
+ pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam));
+
+ // TINYINT
+ int8_t val_tinyint[2][3] = {{9, 27, 81}, {3, 3, 3}};
+ type = TSDB_DATA_TYPE_TINYINT;
+ for (int32_t i = 0; i < 2; ++i) {
+ scltMakeDataBlock(&input[i], type, 0, rowNum, false);
+ pInput[i] = *input[i];
+ for (int32_t j = 0; j < rowNum; ++j) {
+ colDataAppend(pInput[i].columnData, j, (const char *)&val_tinyint[i][j], false);
+ }
+ PRINTF("tiny_int before LOG:%d,%d,%d\n", *((int8_t *)pInput[i].data + 0), *((int8_t *)pInput[i].data + 1),
+ *((int8_t *)pInput[i].data + 2));
+ }
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+
+ code = logFunction(pInput, 2, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("tiny_int after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(input[0]);
+ scltDestroyDataBlock(input[1]);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float[2][3] = {{9.0, 27.0, 81.0}, {3.0, 3.0, 3.0}};
+ type = TSDB_DATA_TYPE_FLOAT;
+ for (int32_t i = 0; i < 2; ++i) {
+ scltMakeDataBlock(&input[i], type, 0, rowNum, false);
+ pInput[i] = *input[i];
+ for (int32_t j = 0; j < rowNum; ++j) {
+ colDataAppend(pInput[i].columnData, j, (const char *)&val_float[i][j], false);
+ }
+ PRINTF("float before LOG:%f,%f,%f\n", *((float *)colDataGetData(pInput[i], 0)),
+ *((float *)colDataGetData(pInput[i], 1)), *((float *)colDataGetData(pInput[i], 2)));
+ }
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+
+ code = logFunction(pInput, 2, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(input[0]);
+ scltDestroyDataBlock(input[1]);
+ scltDestroyDataBlock(pOutput);
+
+ // TINYINT AND FLOAT
+ int8_t param0[] = {9, 27, 81};
+ float param1[] = {3.0, 3.0, 3.0};
+ scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, 0, rowNum, false);
+ pInput[0] = *input[0];
+ for (int32_t i = 0; i < rowNum; ++i) {
+ colDataAppend(pInput[0].columnData, i, (const char *)¶m0[i], false);
+ }
+ scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, 0, rowNum, false);
+ pInput[1] = *input[1];
+ for (int32_t i = 0; i < rowNum; ++i) {
+ colDataAppend(pInput[1].columnData, i, (const char *)¶m1[i], false);
+ }
+ PRINTF("tiny_int, float before LOG:{%d,%f}, {%d,%f}, {%d,%f}\n", *((int8_t *)pInput[0].data + 0),
+ *((float *)pInput[1].data + 0), *((int8_t *)pInput[0].data + 1), *((float *)pInput[1].data + 1),
+ *((int8_t *)pInput[0].data + 2), *((float *)pInput[1].data + 2));
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+
+ code = logFunction(pInput, 2, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("tiny_int,float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(input[0]);
+ scltDestroyDataBlock(input[1]);
+ scltDestroyDataBlock(pOutput);
+ taosMemoryFree(pInput);
}
TEST(ScalarFunctionTest, powFunction_constant) {
- SScalarParam *pInput, *pOutput;
- SScalarParam *input[2];
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- int32_t otype = TSDB_DATA_TYPE_DOUBLE;
- double result = 16.0;
- pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam));
-
- //TINYINT
- int8_t val_tinyint[] = {2, 4};
- type = TSDB_DATA_TYPE_TINYINT;
- for (int32_t i = 0; i < 2; ++i) {
- scltMakeDataBlock(&input[i], type, &val_tinyint[i], rowNum, true);
- pInput[i] = *input[i];
- }
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- PRINTF("tiny_int before POW: %d,%d\n", *((int8_t *)pInput[0].data),
- *((int8_t *)pInput[1].data));
-
- code = powFunction(pInput, 2, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("tiny_int after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(input[0]);
- scltDestroyDataBlock(input[1]);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float[] = {2.0, 4.0};
- type = TSDB_DATA_TYPE_FLOAT;
- for (int32_t i = 0; i < 2; ++i) {
- scltMakeDataBlock(&input[i], type, &val_float[i], rowNum, true);
- pInput[i] = *input[i];
- }
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
- PRINTF("float before POW: %f,%f\n", *((float *)pInput[0].data),
- *((float *)pInput[1].data));
-
- code = powFunction(pInput, 2, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(input[0]);
- scltDestroyDataBlock(input[1]);
- scltDestroyDataBlock(pOutput);
-
- //TINYINT AND FLOAT
- int8_t param0 = 2;
- float param1 = 4.0;
- scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, ¶m0, rowNum, true);
- pInput[0] = *input[0];
- scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, ¶m1, rowNum, true);
- pInput[1] = *input[1];
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
-
- PRINTF("tiny_int,float before POW: %d,%f\n", *((int8_t *)pInput[0].data), *((float *)pInput[1].data));
-
- code = powFunction(pInput, 2, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
- PRINTF("tiny_int,float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(input[0]);
- scltDestroyDataBlock(input[1]);
- scltDestroyDataBlock(pOutput);
- taosMemoryFree(pInput);
+ SScalarParam *pInput, *pOutput;
+ SScalarParam *input[2];
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ int32_t otype = TSDB_DATA_TYPE_DOUBLE;
+ double result = 16.0;
+ pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam));
+
+ // TINYINT
+ int8_t val_tinyint[] = {2, 4};
+ type = TSDB_DATA_TYPE_TINYINT;
+ for (int32_t i = 0; i < 2; ++i) {
+ scltMakeDataBlock(&input[i], type, &val_tinyint[i], rowNum, true);
+ pInput[i] = *input[i];
+ }
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ PRINTF("tiny_int before POW: %d,%d\n", *((int8_t *)pInput[0].data), *((int8_t *)pInput[1].data));
+
+ code = powFunction(pInput, 2, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("tiny_int after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(input[0]);
+ scltDestroyDataBlock(input[1]);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float[] = {2.0, 4.0};
+ type = TSDB_DATA_TYPE_FLOAT;
+ for (int32_t i = 0; i < 2; ++i) {
+ scltMakeDataBlock(&input[i], type, &val_float[i], rowNum, true);
+ pInput[i] = *input[i];
+ }
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+ PRINTF("float before POW: %f,%f\n", *((float *)pInput[0].data), *((float *)pInput[1].data));
+
+ code = powFunction(pInput, 2, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(input[0]);
+ scltDestroyDataBlock(input[1]);
+ scltDestroyDataBlock(pOutput);
+
+ // TINYINT AND FLOAT
+ int8_t param0 = 2;
+ float param1 = 4.0;
+ scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, ¶m0, rowNum, true);
+ pInput[0] = *input[0];
+ scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, ¶m1, rowNum, true);
+ pInput[1] = *input[1];
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+
+ PRINTF("tiny_int,float before POW: %d,%f\n", *((int8_t *)pInput[0].data), *((float *)pInput[1].data));
+
+ code = powFunction(pInput, 2, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
+ PRINTF("tiny_int,float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(input[0]);
+ scltDestroyDataBlock(input[1]);
+ scltDestroyDataBlock(pOutput);
+ taosMemoryFree(pInput);
}
TEST(ScalarFunctionTest, powFunction_column) {
- SScalarParam *pInput, *pOutput;
- SScalarParam *input[2];
- int32_t code = TSDB_CODE_SUCCESS;
- int32_t rowNum = 3;
- int32_t type;
- int32_t otype = TSDB_DATA_TYPE_DOUBLE;
- double result[] = {8.0, 27.0, 64.0};
- pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam));
-
- //TINYINT
- int8_t val_tinyint[2][3] = {{2, 3, 4}, {3, 3, 3}};
- type = TSDB_DATA_TYPE_TINYINT;
- for (int32_t i = 0; i < 2; ++i) {
- scltMakeDataBlock(&input[i], type, 0, rowNum, false);
- pInput[i] = *input[i];
- for (int32_t j = 0; j < rowNum; ++j) {
- colDataAppend(pInput[i].columnData, j, (const char*) &val_tinyint[i][j], false);
-
- }
- PRINTF("tiny_int before POW:%d,%d,%d\n", *((int8_t *)pInput[i].data + 0),
- *((int8_t *)pInput[i].data + 1),
- *((int8_t *)pInput[i].data + 2));
- }
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
-
- code = powFunction(pInput, 2, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("tiny_int after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(input[0]);
- scltDestroyDataBlock(input[1]);
- scltDestroyDataBlock(pOutput);
-
- //FLOAT
- float val_float[2][3] = {{2.0, 3.0, 4.0}, {3.0, 3.0, 3.0}};
- type = TSDB_DATA_TYPE_FLOAT;
- for (int32_t i = 0; i < 2; ++i) {
- scltMakeDataBlock(&input[i], type, 0, rowNum, false);
- pInput[i] = *input[i];
- for (int32_t j = 0; j < rowNum; ++j) {
- colDataAppend(pInput[i].columnData, j, (const char*) &val_float[i][j], false);
- }
- PRINTF("float before POW:%f,%f,%f\n", *((float *)pInput[i].data + 0),
- *((float *)pInput[i].data + 1),
- *((float *)pInput[i].data + 2));
- }
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
-
- code = powFunction(pInput, 2, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
- scltDestroyDataBlock(input[0]);
- scltDestroyDataBlock(input[1]);
- scltDestroyDataBlock(pOutput);
-
- //TINYINT AND FLOAT
- int8_t param0[] = {2, 3, 4};
- float param1[] = {3.0, 3.0, 3.0};
- scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, 0, rowNum, false);
- pInput[0] = *input[0];
- for (int32_t i = 0; i < rowNum; ++i) {
- colDataAppend(pInput[0].columnData, i, (const char*) ¶m0[i], false);
-
- }
- scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, 0, rowNum, false);
- pInput[1] = *input[1];
- for (int32_t i = 0; i < rowNum; ++i) {
- colDataAppend(pInput[1].columnData, i, (const char*) ¶m1[i], false);
- }
- PRINTF("tiny_int, float before POW:{%d,%f}, {%d,%f}, {%d,%f}\n", *((int8_t *)pInput[0].data + 0), *((float *)pInput[1].data + 0),
- *((int8_t *)pInput[0].data + 1), *((float *)pInput[1].data + 1),
- *((int8_t *)pInput[0].data + 2), *((float *)pInput[1].data + 2));
- scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
-
- code = powFunction(pInput, 2, pOutput);
- ASSERT_EQ(code, TSDB_CODE_SUCCESS);
- for (int32_t i = 0; i < rowNum; ++i) {
- ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
- PRINTF("tiny_int,float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
- }
-
- scltDestroyDataBlock(input[0]);
- scltDestroyDataBlock(input[1]);
- scltDestroyDataBlock(pOutput);
- taosMemoryFree(pInput);
-}
-
-int main(int argc, char** argv) {
- taosSeedRand(taosGetTimestampSec());
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
+ SScalarParam *pInput, *pOutput;
+ SScalarParam *input[2];
+ int32_t code = TSDB_CODE_SUCCESS;
+ int32_t rowNum = 3;
+ int32_t type;
+ int32_t otype = TSDB_DATA_TYPE_DOUBLE;
+ double result[] = {8.0, 27.0, 64.0};
+ pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam));
+
+ // TINYINT
+ int8_t val_tinyint[2][3] = {{2, 3, 4}, {3, 3, 3}};
+ type = TSDB_DATA_TYPE_TINYINT;
+ for (int32_t i = 0; i < 2; ++i) {
+ scltMakeDataBlock(&input[i], type, 0, rowNum, false);
+ pInput[i] = *input[i];
+ for (int32_t j = 0; j < rowNum; ++j) {
+ colDataAppend(pInput[i].columnData, j, (const char *)&val_tinyint[i][j], false);
+ }
+ PRINTF("tiny_int before POW:%d,%d,%d\n", *((int8_t *)pInput[i].data + 0), *((int8_t *)pInput[i].data + 1),
+ *((int8_t *)pInput[i].data + 2));
+ }
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+
+ code = powFunction(pInput, 2, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("tiny_int after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(input[0]);
+ scltDestroyDataBlock(input[1]);
+ scltDestroyDataBlock(pOutput);
+
+ // FLOAT
+ float val_float[2][3] = {{2.0, 3.0, 4.0}, {3.0, 3.0, 3.0}};
+ type = TSDB_DATA_TYPE_FLOAT;
+ for (int32_t i = 0; i < 2; ++i) {
+ scltMakeDataBlock(&input[i], type, 0, rowNum, false);
+ pInput[i] = *input[i];
+ for (int32_t j = 0; j < rowNum; ++j) {
+ colDataAppend(pInput[i].columnData, j, (const char *)&val_float[i][j], false);
+ }
+ PRINTF("float before POW:%f,%f,%f\n", *((float *)pInput[i].data + 0), *((float *)pInput[i].data + 1),
+ *((float *)pInput[i].data + 2));
+ }
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+
+ code = powFunction(pInput, 2, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+ scltDestroyDataBlock(input[0]);
+ scltDestroyDataBlock(input[1]);
+ scltDestroyDataBlock(pOutput);
+
+ // TINYINT AND FLOAT
+ int8_t param0[] = {2, 3, 4};
+ float param1[] = {3.0, 3.0, 3.0};
+ scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, 0, rowNum, false);
+ pInput[0] = *input[0];
+ for (int32_t i = 0; i < rowNum; ++i) {
+ colDataAppend(pInput[0].columnData, i, (const char *)¶m0[i], false);
+ }
+ scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, 0, rowNum, false);
+ pInput[1] = *input[1];
+ for (int32_t i = 0; i < rowNum; ++i) {
+ colDataAppend(pInput[1].columnData, i, (const char *)¶m1[i], false);
+ }
+ PRINTF("tiny_int, float before POW:{%d,%f}, {%d,%f}, {%d,%f}\n", *((int8_t *)pInput[0].data + 0),
+ *((float *)pInput[1].data + 0), *((int8_t *)pInput[0].data + 1), *((float *)pInput[1].data + 1),
+ *((int8_t *)pInput[0].data + 2), *((float *)pInput[1].data + 2));
+ scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
+
+ code = powFunction(pInput, 2, pOutput);
+ ASSERT_EQ(code, TSDB_CODE_SUCCESS);
+ for (int32_t i = 0; i < rowNum; ++i) {
+ ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
+ PRINTF("tiny_int,float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
+ }
+
+ scltDestroyDataBlock(input[0]);
+ scltDestroyDataBlock(input[1]);
+ scltDestroyDataBlock(pOutput);
+ taosMemoryFree(pInput);
+}
+
+int main(int argc, char **argv) {
+ taosSeedRand(taosGetTimestampSec());
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
}
#pragma GCC diagnostic pop
-
diff --git a/tools/scripts/codeFormat.sh b/tools/scripts/codeFormat.sh
index e2fef0bb93ce52f06b5feb329ca6570b911cc7e2..f45dce8a807a0df1bc70b18bb0bc5c90b75973f2 100644
--- a/tools/scripts/codeFormat.sh
+++ b/tools/scripts/codeFormat.sh
@@ -24,7 +24,7 @@ FORMAT_DIR_LIST=(
"${PRJ_ROOT_DIR}/source/libs/planner"
# "${PRJ_ROOT_DIR}/source/libs/qcom"
# "${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/sync"
"${PRJ_ROOT_DIR}/source/libs/tdb"