[td-225]refactor codes
This commit is contained in:
parent
5bc5563816
commit
afc8b5a3cd
|
@ -396,10 +396,6 @@ static void function_finalizer(SQLFunctionCtx *pCtx) {
|
||||||
doFinalizer(pCtx);
|
doFinalizer(pCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool usePreVal(SQLFunctionCtx *pCtx) {
|
|
||||||
return pCtx->preAggVals.isSet && pCtx->size == pCtx->preAggVals.size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* count function does need the finalize, if data is missing, the default value, which is 0, is used
|
* count function does need the finalize, if data is missing, the default value, which is 0, is used
|
||||||
* count function does not use the pCtx->interResBuf to keep the intermediate buffer
|
* count function does not use the pCtx->interResBuf to keep the intermediate buffer
|
||||||
|
@ -412,7 +408,7 @@ static void count_function(SQLFunctionCtx *pCtx) {
|
||||||
* 2. for general non-primary key columns, pCtx->hasNull may be true or false, pCtx->preAggVals.isSet == true;
|
* 2. for general non-primary key columns, pCtx->hasNull may be true or false, pCtx->preAggVals.isSet == true;
|
||||||
* 3. for primary key column, pCtx->hasNull always be false, pCtx->preAggVals.isSet == false;
|
* 3. for primary key column, pCtx->hasNull always be false, pCtx->preAggVals.isSet == false;
|
||||||
*/
|
*/
|
||||||
if (usePreVal(pCtx)) {
|
if (pCtx->preAggVals.isSet) {
|
||||||
numOfElem = pCtx->size - pCtx->preAggVals.statis.numOfNull;
|
numOfElem = pCtx->size - pCtx->preAggVals.statis.numOfNull;
|
||||||
} else {
|
} else {
|
||||||
if (pCtx->hasNull) {
|
if (pCtx->hasNull) {
|
||||||
|
@ -537,7 +533,7 @@ static void do_sum(SQLFunctionCtx *pCtx) {
|
||||||
int32_t notNullElems = 0;
|
int32_t notNullElems = 0;
|
||||||
|
|
||||||
// Only the pre-computing information loaded and actual data does not loaded
|
// Only the pre-computing information loaded and actual data does not loaded
|
||||||
if (pCtx->preAggVals.isSet && pCtx->preAggVals.size == pCtx->size) {
|
if (pCtx->preAggVals.isSet) {
|
||||||
notNullElems = pCtx->size - pCtx->preAggVals.statis.numOfNull;
|
notNullElems = pCtx->size - pCtx->preAggVals.statis.numOfNull;
|
||||||
assert(pCtx->size >= pCtx->preAggVals.statis.numOfNull);
|
assert(pCtx->size >= pCtx->preAggVals.statis.numOfNull);
|
||||||
|
|
||||||
|
@ -768,7 +764,7 @@ static void avg_function(SQLFunctionCtx *pCtx) {
|
||||||
SAvgInfo *pAvgInfo = (SAvgInfo *)pResInfo->interResultBuf;
|
SAvgInfo *pAvgInfo = (SAvgInfo *)pResInfo->interResultBuf;
|
||||||
double * pVal = &pAvgInfo->sum;
|
double * pVal = &pAvgInfo->sum;
|
||||||
|
|
||||||
if (usePreVal(pCtx)) {
|
if (pCtx->preAggVals.isSet) {
|
||||||
// Pre-aggregation
|
// Pre-aggregation
|
||||||
notNullElems = pCtx->size - pCtx->preAggVals.statis.numOfNull;
|
notNullElems = pCtx->size - pCtx->preAggVals.statis.numOfNull;
|
||||||
assert(notNullElems >= 0);
|
assert(notNullElems >= 0);
|
||||||
|
@ -932,7 +928,7 @@ static void avg_finalizer(SQLFunctionCtx *pCtx) {
|
||||||
|
|
||||||
static void minMax_function(SQLFunctionCtx *pCtx, char *pOutput, int32_t isMin, int32_t *notNullElems) {
|
static void minMax_function(SQLFunctionCtx *pCtx, char *pOutput, int32_t isMin, int32_t *notNullElems) {
|
||||||
// data in current data block are qualified to the query
|
// data in current data block are qualified to the query
|
||||||
if (usePreVal(pCtx)) {
|
if (pCtx->preAggVals.isSet) {
|
||||||
*notNullElems = pCtx->size - pCtx->preAggVals.statis.numOfNull;
|
*notNullElems = pCtx->size - pCtx->preAggVals.statis.numOfNull;
|
||||||
assert(*notNullElems >= 0);
|
assert(*notNullElems >= 0);
|
||||||
|
|
||||||
|
@ -2916,7 +2912,7 @@ static void leastsquares_finalizer(SQLFunctionCtx *pCtx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void date_col_output_function(SQLFunctionCtx *pCtx) {
|
static void date_col_output_function(SQLFunctionCtx *pCtx) {
|
||||||
if (pCtx->scanFlag == REVERSE_SCAN) {
|
if (pCtx->scanFlag == REVERSE_SCAN) { // todo : remove it
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3423,7 +3419,7 @@ static void spread_function(SQLFunctionCtx *pCtx) {
|
||||||
|
|
||||||
// todo : opt with pre-calculated result
|
// todo : opt with pre-calculated result
|
||||||
// column missing cause the hasNull to be true
|
// column missing cause the hasNull to be true
|
||||||
if (usePreVal(pCtx)) {
|
if (pCtx->preAggVals.isSet) {
|
||||||
numOfElems = pCtx->size - pCtx->preAggVals.statis.numOfNull;
|
numOfElems = pCtx->size - pCtx->preAggVals.statis.numOfNull;
|
||||||
|
|
||||||
// all data are null in current data block, ignore current data block
|
// all data are null in current data block, ignore current data block
|
||||||
|
|
|
@ -126,7 +126,6 @@ typedef struct SArithmeticSupport {
|
||||||
|
|
||||||
typedef struct SQLPreAggVal {
|
typedef struct SQLPreAggVal {
|
||||||
bool isSet;
|
bool isSet;
|
||||||
int32_t size;
|
|
||||||
SDataStatis statis;
|
SDataStatis statis;
|
||||||
} SQLPreAggVal;
|
} SQLPreAggVal;
|
||||||
|
|
||||||
|
@ -174,7 +173,6 @@ typedef struct SQLFunctionCtx {
|
||||||
int16_t outputBytes; // size of results, determined by function and input column data type
|
int16_t outputBytes; // size of results, determined by function and input column data type
|
||||||
bool hasNull; // null value exist in current block
|
bool hasNull; // null value exist in current block
|
||||||
int16_t functionId; // function id
|
int16_t functionId; // function id
|
||||||
int32_t blockStatus; // Indicate if data is loaded, it is first/last/internal block. Only for file blocks
|
|
||||||
void * aInputElemBuf;
|
void * aInputElemBuf;
|
||||||
char * aOutputBuf; // final result output buffer, point to sdata->data
|
char * aOutputBuf; // final result output buffer, point to sdata->data
|
||||||
uint8_t currentStage; // record current running step, default: 0
|
uint8_t currentStage; // record current running step, default: 0
|
||||||
|
|
|
@ -1342,14 +1342,13 @@ void setExecParams(SQuery *pQuery, SQLFunctionCtx *pCtx, void *inputData, TSKEY
|
||||||
|
|
||||||
if (pStatis != NULL) {
|
if (pStatis != NULL) {
|
||||||
pCtx->preAggVals.isSet = true;
|
pCtx->preAggVals.isSet = true;
|
||||||
pCtx->preAggVals.size = size;
|
|
||||||
pCtx->preAggVals.statis = *pStatis;
|
pCtx->preAggVals.statis = *pStatis;
|
||||||
} else {
|
} else {
|
||||||
pCtx->preAggVals.isSet = false;
|
pCtx->preAggVals.isSet = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pCtx->startOffset = QUERY_IS_ASC_QUERY(pQuery) ? pQuery->pos : 0;
|
pCtx->startOffset = QUERY_IS_ASC_QUERY(pQuery) ? pQuery->pos : 0;
|
||||||
pCtx->size = QUERY_IS_ASC_QUERY(pQuery) ? size - pQuery->pos : pQuery->pos + 1;
|
pCtx->size = size;
|
||||||
|
|
||||||
uint32_t status = aAggs[functionId].nStatus;
|
uint32_t status = aAggs[functionId].nStatus;
|
||||||
if (((status & (TSDB_FUNCSTATE_SELECTIVITY | TSDB_FUNCSTATE_NEED_TS)) != 0) && (tsCol != NULL)) {
|
if (((status & (TSDB_FUNCSTATE_SELECTIVITY | TSDB_FUNCSTATE_NEED_TS)) != 0) && (tsCol != NULL)) {
|
||||||
|
@ -1377,6 +1376,8 @@ void setExecParams(SQuery *pQuery, SQLFunctionCtx *pCtx, void *inputData, TSKEY
|
||||||
|
|
||||||
} else if (functionId == TSDB_FUNC_ARITHM) {
|
} else if (functionId == TSDB_FUNC_ARITHM) {
|
||||||
pCtx->param[1].pz = param;
|
pCtx->param[1].pz = param;
|
||||||
|
} else if (functionId == TSDB_FUNC_SPREAD) {
|
||||||
|
pCtx->
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_DEBUG_VIEW)
|
#if defined(_DEBUG_VIEW)
|
||||||
|
|
Loading…
Reference in New Issue