提交 55d11618 编写于 作者: H Haojun Liao

fix(query): fix float value min/max query error.

上级 ea18b8a7
...@@ -703,7 +703,6 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { ...@@ -703,7 +703,6 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
if (pInput->colDataAggIsSet) { if (pInput->colDataAggIsSet) {
numOfElems = pInput->numOfRows - pAgg->numOfNull; numOfElems = pInput->numOfRows - pAgg->numOfNull;
ASSERT(pInput->numOfRows == pInput->totalRows && numOfElems >= 0); ASSERT(pInput->numOfRows == pInput->totalRows && numOfElems >= 0);
if (numOfElems == 0) { if (numOfElems == 0) {
return numOfElems; return numOfElems;
} }
...@@ -722,48 +721,79 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { ...@@ -722,48 +721,79 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
// the index is the original position, not the relative position // the index is the original position, not the relative position
TSKEY key = (pCtx->ptsList != NULL) ? pCtx->ptsList[index] : TSKEY_INITIAL_VAL; TSKEY key = (pCtx->ptsList != NULL) ? pCtx->ptsList[index] : TSKEY_INITIAL_VAL;
if (IS_SIGNED_NUMERIC_TYPE(type)) { if (!pBuf->assign) {
int64_t prev = 0; pBuf->v = *(int64_t*)tval;
GET_TYPED_DATA(prev, int64_t, type, pBuf->v); if (pCtx->subsidiaries.num > 0) {
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
int64_t val = GET_INT64_VAL(tval); }
if ((prev < val) ^ isMinFunc) { } else {
pBuf->v = val; if (IS_SIGNED_NUMERIC_TYPE(type)) {
for (int32_t i = 0; i < (pCtx)->subsidiaries.num; ++i) { int64_t prev = 0;
SqlFunctionCtx* __ctx = pCtx->subsidiaries.pCtx[i]; GET_TYPED_DATA(prev, int64_t, type, &pBuf->v);
if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor
__ctx->tag.i = key; int64_t val = GET_INT64_VAL(tval);
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT; 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); double val = GET_DOUBLE_VAL(tval);
} if ((prev < val) ^ isMinFunc) {
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) { pBuf->v = val;
uint64_t prev = 0;
GET_TYPED_DATA(prev, uint64_t, type, pBuf->v); if (pCtx->subsidiaries.num > 0) {
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
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;
} }
}
} 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; pBuf->assign = true;
...@@ -1058,7 +1088,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { ...@@ -1058,7 +1088,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
} }
} else if (type == TSDB_DATA_TYPE_FLOAT) { } else if (type == TSDB_DATA_TYPE_FLOAT) {
float* pData = (float*)pCol->pData; float* pData = (float*)pCol->pData;
float* val = (float*)&pBuf->v; double* val = (double*)&pBuf->v;
for (int32_t i = start; i < start + numOfRows; ++i) { for (int32_t i = start; i < start + numOfRows; ++i) {
if ((pCol->hasNull) && colDataIsNull_f(pCol->nullbitmap, i)) { if ((pCol->hasNull) && colDataIsNull_f(pCol->nullbitmap, i)) {
...@@ -1119,10 +1149,14 @@ int32_t minmaxFunctionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { ...@@ -1119,10 +1149,14 @@ int32_t minmaxFunctionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
// todo assign the tag value // todo assign the tag value
int32_t currentRow = pBlock->info.rows; int32_t currentRow = pBlock->info.rows;
if (type) if (pCol->info.type == TSDB_DATA_TYPE_FLOAT) {
colDataAppend(pCol, currentRow, (const char*)&pRes->v, false); float v = *(double*) &pRes->v;
setSelectivityValue(pCtx, pBlock, &pRes->tuplePos, currentRow); 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; return pEntryInfo->numOfRes;
} }
......
...@@ -140,7 +140,8 @@ endi ...@@ -140,7 +140,8 @@ endi
if $data00 != -13 then if $data00 != -13 then
return -1 return -1
endi endi
if $data01 != -2.30000 then if $data01 != -2.30000 then
print expect -2.30000, actual: $data01
return -1 return -1
endi endi
if $data02 != -3.300000000 then if $data02 != -3.300000000 then
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册