diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index adacea8efdee339eab5e6c7aff3aada8894f13fa..1cb47a0bf139c7ff638e34be1c351044bd3a5bdc 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -703,7 +703,6 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { if (pInput->colDataAggIsSet) { numOfElems = pInput->numOfRows - pAgg->numOfNull; ASSERT(pInput->numOfRows == pInput->totalRows && numOfElems >= 0); - if (numOfElems == 0) { return numOfElems; } @@ -722,48 +721,79 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { // the index is the original position, not the relative position TSKEY key = (pCtx->ptsList != NULL) ? pCtx->ptsList[index] : TSKEY_INITIAL_VAL; - if (IS_SIGNED_NUMERIC_TYPE(type)) { - int64_t prev = 0; - GET_TYPED_DATA(prev, int64_t, type, pBuf->v); - - int64_t val = GET_INT64_VAL(tval); - if ((prev < val) ^ isMinFunc) { - pBuf->v = val; - for (int32_t i = 0; i < (pCtx)->subsidiaries.num; ++i) { - SqlFunctionCtx* __ctx = pCtx->subsidiaries.pCtx[i]; - if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor - __ctx->tag.i = key; - __ctx->tag.nType = TSDB_DATA_TYPE_BIGINT; + if (!pBuf->assign) { + pBuf->v = *(int64_t*)tval; + if (pCtx->subsidiaries.num > 0) { + saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos); + } + } else { + if (IS_SIGNED_NUMERIC_TYPE(type)) { + int64_t prev = 0; + GET_TYPED_DATA(prev, int64_t, type, &pBuf->v); + + int64_t val = GET_INT64_VAL(tval); + if ((prev < val) ^ isMinFunc) { + pBuf->v = val; + // for (int32_t i = 0; i < (pCtx)->subsidiaries.num; ++i) { + // SqlFunctionCtx* __ctx = pCtx->subsidiaries.pCtx[i]; + // if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor + // __ctx->tag.i = key; + // __ctx->tag.nType = TSDB_DATA_TYPE_BIGINT; + // } + // + // __ctx->fpSet.process(__ctx); + // } + + if (pCtx->subsidiaries.num > 0) { + saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos); } + } - __ctx->fpSet.process(__ctx); + } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) { + uint64_t prev = 0; + GET_TYPED_DATA(prev, uint64_t, type, &pBuf->v); + + uint64_t val = GET_UINT64_VAL(tval); + if ((prev < val) ^ isMinFunc) { + pBuf->v = val; + // for (int32_t i = 0; i < (pCtx)->subsidiaries.num; ++i) { + // SqlFunctionCtx* __ctx = pCtx->subsidiaries.pCtx[i]; + // if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor + // __ctx->tag.i = key; + // __ctx->tag.nType = TSDB_DATA_TYPE_BIGINT; + // } + // + // __ctx->fpSet.process(__ctx); + // } + if (pCtx->subsidiaries.num > 0) { + saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos); + } } + } else if (type == TSDB_DATA_TYPE_DOUBLE) { + double prev = 0; + GET_TYPED_DATA(prev, int64_t, type, &pBuf->v); - saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos); - } - } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) { - uint64_t prev = 0; - GET_TYPED_DATA(prev, uint64_t, type, pBuf->v); - - uint64_t val = GET_UINT64_VAL(tval); - if ((prev < val) ^ isMinFunc) { - pBuf->v = val; - for (int32_t i = 0; i < (pCtx)->subsidiaries.num; ++i) { - SqlFunctionCtx* __ctx = pCtx->subsidiaries.pCtx[i]; - if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor - __ctx->tag.i = key; - __ctx->tag.nType = TSDB_DATA_TYPE_BIGINT; + double val = GET_DOUBLE_VAL(tval); + if ((prev < val) ^ isMinFunc) { + pBuf->v = val; + + if (pCtx->subsidiaries.num > 0) { + saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos); } + } + } else if (type == TSDB_DATA_TYPE_FLOAT) { + double prev = 0; + GET_TYPED_DATA(prev, int64_t, type, &pBuf->v); - __ctx->fpSet.process(__ctx); + double val = GET_DOUBLE_VAL(tval); + if ((prev < val) ^ isMinFunc) { + pBuf->v = val; + } + + if (pCtx->subsidiaries.num > 0) { + saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos); } } - } else if (type == TSDB_DATA_TYPE_DOUBLE) { - double val = GET_DOUBLE_VAL(tval); - UPDATE_DATA(pCtx, *(double*)&pBuf->v, val, numOfElems, isMinFunc, key); - } else if (type == TSDB_DATA_TYPE_FLOAT) { - double val = GET_DOUBLE_VAL(tval); - UPDATE_DATA(pCtx, *(float*)&pBuf->v, val, numOfElems, isMinFunc, key); } pBuf->assign = true; @@ -1058,7 +1088,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { } } else if (type == TSDB_DATA_TYPE_FLOAT) { float* pData = (float*)pCol->pData; - float* val = (float*)&pBuf->v; + double* val = (double*)&pBuf->v; for (int32_t i = start; i < start + numOfRows; ++i) { if ((pCol->hasNull) && colDataIsNull_f(pCol->nullbitmap, i)) { @@ -1119,10 +1149,14 @@ int32_t minmaxFunctionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { // todo assign the tag value int32_t currentRow = pBlock->info.rows; - if (type) - colDataAppend(pCol, currentRow, (const char*)&pRes->v, false); - setSelectivityValue(pCtx, pBlock, &pRes->tuplePos, currentRow); + if (pCol->info.type == TSDB_DATA_TYPE_FLOAT) { + float v = *(double*) &pRes->v; + colDataAppend(pCol, currentRow, (const char*)&v, false); + } else { + colDataAppend(pCol, currentRow, (const char*)&pRes->v, false); + } + setSelectivityValue(pCtx, pBlock, &pRes->tuplePos, currentRow); return pEntryInfo->numOfRes; } diff --git a/tests/script/tsim/insert/basic0.sim b/tests/script/tsim/insert/basic0.sim index 94bd0f1ecffb388af56773a241b5f89982e5b23a..d8dde20e4e92f762c6dfca5435f0d92b9a3ffdb9 100644 --- a/tests/script/tsim/insert/basic0.sim +++ b/tests/script/tsim/insert/basic0.sim @@ -140,7 +140,8 @@ endi if $data00 != -13 then return -1 endi -if $data01 != -2.30000 then +if $data01 != -2.30000 then + print expect -2.30000, actual: $data01 return -1 endi if $data02 != -3.300000000 then