more code format
This commit is contained in:
parent
63d9b85631
commit
d8e32fb439
|
@ -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 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 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 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 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_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_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_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_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_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_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_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_ADD_CTX_TO_GRES(gres, idx, ctx) \
|
||||
do { \
|
||||
if ((gres)->colCtxs == NULL) { \
|
||||
(gres)->colCtxs = taosArrayInit(gres->colNum, sizeof(SFilterColCtx)); \
|
||||
} \
|
||||
SFilterColCtx cCtx = {idx, ctx}; \
|
||||
taosArrayPush((gres)->colCtxs, &cCtx); \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define FILTER_ALL_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_ALL)
|
||||
#define FILTER_ALL_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_ALL)
|
||||
#define FILTER_EMPTY_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_EMPTY)
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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_*/
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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 "tdatablock.h"
|
||||
#include "scalar.h"
|
||||
#include "tudf.h"
|
||||
#include "ttime.h"
|
||||
#include "tcompare.h"
|
||||
#include "tdatablock.h"
|
||||
#include "ttime.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:
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue