diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index 096f5695019b9fae5d9845a02241759d83be1f7e..42adc6fac12f61053aea6784a200685a217918ac 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -2991,12 +2991,18 @@ static void col_project_function(SQLFunctionCtx *pCtx) { char *pData = GET_INPUT_DATA_LIST(pCtx); if (pCtx->order == TSDB_ORDER_ASC) { + // ASC int32_t numOfRows = (pCtx->param[0].i64 == 1)? 1:pCtx->size; memcpy(pCtx->pOutput, pData, (size_t) numOfRows * pCtx->inputBytes); } else { + // DESC for(int32_t i = 0; i < pCtx->size; ++i) { - memcpy(pCtx->pOutput + (pCtx->size - 1 - i) * pCtx->inputBytes, pData + i * pCtx->inputBytes, - pCtx->inputBytes); + char* dst = pCtx->pOutput + (pCtx->size - 1 - i) * pCtx->inputBytes; + char* src = pData + i * pCtx->inputBytes; + if (IS_VAR_DATA_TYPE(pCtx->inputType)) + varDataCopy(dst, src); + else + memcpy(dst, src, pCtx->inputBytes); } } }