enh(query): avg function use pre-agg results
This commit is contained in:
parent
2926d141ca
commit
2a6dfbb0d7
|
@ -642,8 +642,8 @@ bool avgFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) {
|
|||
int32_t avgFunction(SqlFunctionCtx* pCtx) {
|
||||
int32_t numOfElem = 0;
|
||||
|
||||
// Only the pre-computing information loaded and actual data does not loaded
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
SColumnDataAgg* pAgg = pInput->pColumnDataAgg[0];
|
||||
int32_t type = pInput->pData[0]->info.type;
|
||||
|
||||
SAvgRes* pAvgRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||
|
@ -660,6 +660,17 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
|
|||
goto _avg_over;
|
||||
}
|
||||
|
||||
if (pInput->colDataAggIsSet) {
|
||||
numOfElem = numOfRows - pAgg->numOfNull;
|
||||
ASSERT(numOfElem >= 0);
|
||||
|
||||
pAvgRes->count += numOfElem;
|
||||
if (IS_INTEGER_TYPE(type)) {
|
||||
pAvgRes->sum.isum += pAgg->sum;
|
||||
} else if (IS_FLOAT_TYPE(type)) {
|
||||
pAvgRes->sum.dsum += GET_DOUBLE_VAL((const char*)&(pAgg->sum));
|
||||
}
|
||||
} else { // computing based on the true data block
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_TINYINT: {
|
||||
int8_t* plist = (int8_t*)pCol->pData;
|
||||
|
@ -750,6 +761,7 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_avg_over:
|
||||
// data in the check operation are all null, not output
|
||||
|
|
Loading…
Reference in New Issue