提交 75984ed3 编写于 作者: H Haojun Liao

[td-2895] refactor

上级 51db5f57
...@@ -214,7 +214,7 @@ typedef struct SAggFunctionInfo { ...@@ -214,7 +214,7 @@ typedef struct SAggFunctionInfo {
void (*xFinalize)(SQLFunctionCtx *pCtx); void (*xFinalize)(SQLFunctionCtx *pCtx);
void (*mergeFunc)(SQLFunctionCtx *pCtx); void (*mergeFunc)(SQLFunctionCtx *pCtx);
int32_t (*dataReqFunc)(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId); int32_t (*dataReqFunc)(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId);
} SAggFunctionInfo; } SAggFunctionInfo;
#define GET_RES_INFO(ctx) ((ctx)->resultInfo) #define GET_RES_INFO(ctx) ((ctx)->resultInfo)
...@@ -247,7 +247,7 @@ extern struct SAggFunctionInfo aAggs[]; ...@@ -247,7 +247,7 @@ extern struct SAggFunctionInfo aAggs[];
extern int32_t functionCompatList[]; // compatible check array list extern int32_t functionCompatList[]; // compatible check array list
bool topbot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, const char *minval, const char *maxval); bool topbot_datablock_filter(SQLFunctionCtx *pCtx, const char *minval, const char *maxval);
/** /**
* the numOfRes should be kept, since it may be used later * the numOfRes should be kept, since it may be used later
......
...@@ -249,6 +249,7 @@ typedef struct SOperatorInfo { ...@@ -249,6 +249,7 @@ typedef struct SOperatorInfo {
int32_t numOfOutput; int32_t numOfOutput;
__operator_fn_t exec; __operator_fn_t exec;
__operator_fn_t cleanup;
struct SOperatorInfo *upstream; struct SOperatorInfo *upstream;
} SOperatorInfo; } SOperatorInfo;
...@@ -292,11 +293,6 @@ typedef struct SQueryRuntimeEnv { ...@@ -292,11 +293,6 @@ typedef struct SQueryRuntimeEnv {
SGroupResInfo groupResInfo; SGroupResInfo groupResInfo;
} SQueryRuntimeEnv; } SQueryRuntimeEnv;
typedef struct {
char* name;
void* info;
} SQEStage;
enum { enum {
QUERY_RESULT_NOT_READY = 1, QUERY_RESULT_NOT_READY = 1,
QUERY_RESULT_READY = 2, QUERY_RESULT_READY = 2,
...@@ -345,11 +341,11 @@ typedef struct SQueryParam { ...@@ -345,11 +341,11 @@ typedef struct SQueryParam {
typedef struct STableScanInfo { typedef struct STableScanInfo {
SQueryRuntimeEnv *pRuntimeEnv; SQueryRuntimeEnv *pRuntimeEnv;
void *pQueryHandle; void *pQueryHandle;
int32_t numOfBlocks; int32_t numOfBlocks;
int32_t numOfSkipped; int32_t numOfSkipped;
int32_t numOfBlockStatis; int32_t numOfBlockStatis;
int64_t numOfRows; int64_t numOfRows;
int32_t order; // scan order int32_t order; // scan order
...@@ -359,11 +355,16 @@ typedef struct STableScanInfo { ...@@ -359,11 +355,16 @@ typedef struct STableScanInfo {
int32_t reverseTimes; // 0 by default int32_t reverseTimes; // 0 by default
SSDataBlock block; SSDataBlock block;
SQLFunctionCtx* pCtx; // next operator query context
SResultRowInfo* pResultRowInfo;
int32_t numOfOutput;
int64_t elapsedTime; int64_t elapsedTime;
} STableScanInfo; } STableScanInfo;
typedef struct SAggOperatorInfo { typedef struct SAggOperatorInfo {
SResultRowInfo *pResultRowInfo; SResultRowInfo resultRowInfo;
STableQueryInfo *pTableQueryInfo; STableQueryInfo *pTableQueryInfo;
SQueryRuntimeEnv *pRuntimeEnv; SQueryRuntimeEnv *pRuntimeEnv;
SQLFunctionCtx *pCtx; SQLFunctionCtx *pCtx;
...@@ -372,7 +373,9 @@ typedef struct SAggOperatorInfo { ...@@ -372,7 +373,9 @@ typedef struct SAggOperatorInfo {
typedef struct SArithOperatorInfo { typedef struct SArithOperatorInfo {
STableQueryInfo *pTableQueryInfo; STableQueryInfo *pTableQueryInfo;
SQueryRuntimeEnv *pRuntimeEnv; SQueryRuntimeEnv *pRuntimeEnv;
SQLFunctionCtx* pCtx; SQLFunctionCtx *pCtx;
SResultRowInfo resultRowInfo;
SSDataBlock *pOutput;
} SArithOperatorInfo; } SArithOperatorInfo;
typedef struct SLimitOperatorInfo { typedef struct SLimitOperatorInfo {
...@@ -388,10 +391,10 @@ typedef struct SOffsetOperatorInfo { ...@@ -388,10 +391,10 @@ typedef struct SOffsetOperatorInfo {
} SOffsetOperatorInfo; } SOffsetOperatorInfo;
typedef struct SHashIntervalOperatorInfo { typedef struct SHashIntervalOperatorInfo {
SResultRowInfo *pResultRowInfo;
STableQueryInfo *pTableQueryInfo; STableQueryInfo *pTableQueryInfo;
SQueryRuntimeEnv *pRuntimeEnv; SQueryRuntimeEnv *pRuntimeEnv;
SQLFunctionCtx *pCtx; SQLFunctionCtx *pCtx;
SResultRowInfo resultRowInfo;
} SHashIntervalOperatorInfo; } SHashIntervalOperatorInfo;
typedef struct SFillOperatorInfo { typedef struct SFillOperatorInfo {
...@@ -400,6 +403,12 @@ typedef struct SFillOperatorInfo { ...@@ -400,6 +403,12 @@ typedef struct SFillOperatorInfo {
SQueryRuntimeEnv *pRuntimeEnv; SQueryRuntimeEnv *pRuntimeEnv;
} SFillOperatorInfo; } SFillOperatorInfo;
typedef struct SFilterOperatorInfo {
SResultRowInfo *pResultRowInfo;
STableQueryInfo *pTableQueryInfo;
SQueryRuntimeEnv *pRuntimeEnv;
} SFilterOperatorInfo;
void freeParam(SQueryParam *param); void freeParam(SQueryParam *param);
int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param); int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param);
int32_t createQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t numOfOutput, SExprInfo **pExprInfo, SSqlFuncMsg **pExprMsg, int32_t createQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t numOfOutput, SExprInfo **pExprInfo, SSqlFuncMsg **pExprMsg,
......
...@@ -457,7 +457,7 @@ static void count_func_merge(SQLFunctionCtx *pCtx) { ...@@ -457,7 +457,7 @@ static void count_func_merge(SQLFunctionCtx *pCtx) {
* @param filterCols * @param filterCols
* @return * @return
*/ */
int32_t count_load_data_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { int32_t countRequired(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId) {
if (colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) { if (colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
return BLK_DATA_NO_NEEDED; return BLK_DATA_NO_NEEDED;
} else { } else {
...@@ -465,7 +465,7 @@ int32_t count_load_data_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32 ...@@ -465,7 +465,7 @@ int32_t count_load_data_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32
} }
} }
int32_t no_data_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { int32_t noDataRequired(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId) {
return BLK_DATA_NO_NEEDED; return BLK_DATA_NO_NEEDED;
} }
...@@ -667,16 +667,16 @@ static void sum_func_merge(SQLFunctionCtx *pCtx) { ...@@ -667,16 +667,16 @@ static void sum_func_merge(SQLFunctionCtx *pCtx) {
} }
} }
static int32_t statisRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { static int32_t statisRequired(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId) {
return BLK_DATA_STATIS_NEEDED; return BLK_DATA_STATIS_NEEDED;
} }
static int32_t dataBlockRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { static int32_t dataBlockRequired(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId) {
return BLK_DATA_ALL_NEEDED; return BLK_DATA_ALL_NEEDED;
} }
// todo: if column in current data block are null, opt for this case // todo: if column in current data block are null, opt for this case
static int32_t firstFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { static int32_t firstFuncRequired(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId) {
if (pCtx->order == TSDB_ORDER_DESC) { if (pCtx->order == TSDB_ORDER_DESC) {
return BLK_DATA_NO_NEEDED; return BLK_DATA_NO_NEEDED;
} }
...@@ -689,7 +689,7 @@ static int32_t firstFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, i ...@@ -689,7 +689,7 @@ static int32_t firstFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, i
} }
} }
static int32_t lastFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { static int32_t lastFuncRequired(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId) {
if (pCtx->order != pCtx->param[0].i64) { if (pCtx->order != pCtx->param[0].i64) {
return BLK_DATA_NO_NEEDED; return BLK_DATA_NO_NEEDED;
} }
...@@ -701,7 +701,7 @@ static int32_t lastFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, in ...@@ -701,7 +701,7 @@ static int32_t lastFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, in
} }
} }
static int32_t firstDistFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { static int32_t firstDistFuncRequired(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId) {
if (pCtx->order == TSDB_ORDER_DESC) { if (pCtx->order == TSDB_ORDER_DESC) {
return BLK_DATA_NO_NEEDED; return BLK_DATA_NO_NEEDED;
} }
...@@ -717,11 +717,11 @@ static int32_t firstDistFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY en ...@@ -717,11 +717,11 @@ static int32_t firstDistFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY en
if (pInfo->hasResult != DATA_SET_FLAG) { if (pInfo->hasResult != DATA_SET_FLAG) {
return BLK_DATA_ALL_NEEDED; return BLK_DATA_ALL_NEEDED;
} else { // data in current block is not earlier than current result } else { // data in current block is not earlier than current result
return (pInfo->ts <= start) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED; return (pInfo->ts <= w->skey) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED;
} }
} }
static int32_t lastDistFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { static int32_t lastDistFuncRequired(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId) {
if (pCtx->order != pCtx->param[0].i64) { if (pCtx->order != pCtx->param[0].i64) {
return BLK_DATA_NO_NEEDED; return BLK_DATA_NO_NEEDED;
} }
...@@ -737,7 +737,7 @@ static int32_t lastDistFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end ...@@ -737,7 +737,7 @@ static int32_t lastDistFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end
if (pInfo->hasResult != DATA_SET_FLAG) { if (pInfo->hasResult != DATA_SET_FLAG) {
return BLK_DATA_ALL_NEEDED; return BLK_DATA_ALL_NEEDED;
} else { } else {
return (pInfo->ts > end) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED; return (pInfo->ts > w->ekey) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED;
} }
} }
...@@ -2412,7 +2412,7 @@ static STopBotInfo *getTopBotOutputInfo(SQLFunctionCtx *pCtx) { ...@@ -2412,7 +2412,7 @@ static STopBotInfo *getTopBotOutputInfo(SQLFunctionCtx *pCtx) {
} }
} }
bool topbot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, const char *minval, const char *maxval) { bool topbot_datablock_filter(SQLFunctionCtx *pCtx, const char *minval, const char *maxval) {
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
if (pResInfo == NULL) { if (pResInfo == NULL) {
return true; return true;
...@@ -2427,7 +2427,7 @@ bool topbot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, const cha ...@@ -2427,7 +2427,7 @@ bool topbot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, const cha
tValuePair **pRes = (tValuePair**) pTopBotInfo->res; tValuePair **pRes = (tValuePair**) pTopBotInfo->res;
if (functionId == TSDB_FUNC_TOP) { if (pCtx->functionId == TSDB_FUNC_TOP) {
switch (pCtx->inputType) { switch (pCtx->inputType) {
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
return GET_INT8_VAL(maxval) > pRes[0]->v.i64; return GET_INT8_VAL(maxval) > pRes[0]->v.i64;
...@@ -4549,7 +4549,7 @@ SAggFunctionInfo aAggs[] = {{ ...@@ -4549,7 +4549,7 @@ SAggFunctionInfo aAggs[] = {{
no_next_step, no_next_step,
doFinalizer, doFinalizer,
count_func_merge, count_func_merge,
count_load_data_info, countRequired,
}, },
{ {
// 1 // 1
...@@ -4734,7 +4734,7 @@ SAggFunctionInfo aAggs[] = {{ ...@@ -4734,7 +4734,7 @@ SAggFunctionInfo aAggs[] = {{
no_next_step, no_next_step,
spread_function_finalizer, spread_function_finalizer,
spread_func_merge, spread_func_merge,
count_load_data_info, countRequired,
}, },
{ {
// 14 // 14
...@@ -4776,7 +4776,7 @@ SAggFunctionInfo aAggs[] = {{ ...@@ -4776,7 +4776,7 @@ SAggFunctionInfo aAggs[] = {{
no_next_step, no_next_step,
doFinalizer, doFinalizer,
copy_function, copy_function,
no_data_info, noDataRequired,
}, },
{ {
// 17 // 17
...@@ -4804,7 +4804,7 @@ SAggFunctionInfo aAggs[] = {{ ...@@ -4804,7 +4804,7 @@ SAggFunctionInfo aAggs[] = {{
no_next_step, no_next_step,
doFinalizer, doFinalizer,
copy_function, copy_function,
no_data_info, noDataRequired,
}, },
{ {
// 19 // 19
...@@ -4832,7 +4832,7 @@ SAggFunctionInfo aAggs[] = {{ ...@@ -4832,7 +4832,7 @@ SAggFunctionInfo aAggs[] = {{
no_next_step, no_next_step,
doFinalizer, doFinalizer,
copy_function, copy_function,
no_data_info, noDataRequired,
}, },
{ {
// 21, column project sql function // 21, column project sql function
...@@ -4860,7 +4860,7 @@ SAggFunctionInfo aAggs[] = {{ ...@@ -4860,7 +4860,7 @@ SAggFunctionInfo aAggs[] = {{
no_next_step, no_next_step,
doFinalizer, doFinalizer,
copy_function, copy_function,
no_data_info, noDataRequired,
}, },
{ {
// 23 // 23
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册