fix(query): fix float value min/max query error.
This commit is contained in:
parent
ea18b8a7dc
commit
55d11618d0
|
@ -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) {
|
||||||
// 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 (!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)) {
|
if (IS_SIGNED_NUMERIC_TYPE(type)) {
|
||||||
int64_t prev = 0;
|
int64_t prev = 0;
|
||||||
GET_TYPED_DATA(prev, int64_t, type, pBuf->v);
|
GET_TYPED_DATA(prev, int64_t, type, &pBuf->v);
|
||||||
|
|
||||||
int64_t val = GET_INT64_VAL(tval);
|
int64_t val = GET_INT64_VAL(tval);
|
||||||
if ((prev < val) ^ isMinFunc) {
|
if ((prev < val) ^ isMinFunc) {
|
||||||
pBuf->v = val;
|
pBuf->v = val;
|
||||||
for (int32_t i = 0; i < (pCtx)->subsidiaries.num; ++i) {
|
// for (int32_t i = 0; i < (pCtx)->subsidiaries.num; ++i) {
|
||||||
SqlFunctionCtx* __ctx = pCtx->subsidiaries.pCtx[i];
|
// SqlFunctionCtx* __ctx = pCtx->subsidiaries.pCtx[i];
|
||||||
if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor
|
// if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor
|
||||||
__ctx->tag.i = key;
|
// __ctx->tag.i = key;
|
||||||
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT;
|
// __ctx->tag.nType = TSDB_DATA_TYPE_BIGINT;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
__ctx->fpSet.process(__ctx);
|
// __ctx->fpSet.process(__ctx);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
if (pCtx->subsidiaries.num > 0) {
|
||||||
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
|
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
|
||||||
uint64_t prev = 0;
|
uint64_t prev = 0;
|
||||||
GET_TYPED_DATA(prev, uint64_t, type, pBuf->v);
|
GET_TYPED_DATA(prev, uint64_t, type, &pBuf->v);
|
||||||
|
|
||||||
uint64_t val = GET_UINT64_VAL(tval);
|
uint64_t val = GET_UINT64_VAL(tval);
|
||||||
if ((prev < val) ^ isMinFunc) {
|
if ((prev < val) ^ isMinFunc) {
|
||||||
pBuf->v = val;
|
pBuf->v = val;
|
||||||
for (int32_t i = 0; i < (pCtx)->subsidiaries.num; ++i) {
|
// for (int32_t i = 0; i < (pCtx)->subsidiaries.num; ++i) {
|
||||||
SqlFunctionCtx* __ctx = pCtx->subsidiaries.pCtx[i];
|
// SqlFunctionCtx* __ctx = pCtx->subsidiaries.pCtx[i];
|
||||||
if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor
|
// if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor
|
||||||
__ctx->tag.i = key;
|
// __ctx->tag.i = key;
|
||||||
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT;
|
// __ctx->tag.nType = TSDB_DATA_TYPE_BIGINT;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
__ctx->fpSet.process(__ctx);
|
// __ctx->fpSet.process(__ctx);
|
||||||
|
// }
|
||||||
|
if (pCtx->subsidiaries.num > 0) {
|
||||||
|
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (type == TSDB_DATA_TYPE_DOUBLE) {
|
} else if (type == TSDB_DATA_TYPE_DOUBLE) {
|
||||||
|
double prev = 0;
|
||||||
|
GET_TYPED_DATA(prev, int64_t, type, &pBuf->v);
|
||||||
|
|
||||||
double val = GET_DOUBLE_VAL(tval);
|
double val = GET_DOUBLE_VAL(tval);
|
||||||
UPDATE_DATA(pCtx, *(double*)&pBuf->v, val, numOfElems, isMinFunc, key);
|
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) {
|
} else if (type == TSDB_DATA_TYPE_FLOAT) {
|
||||||
|
double prev = 0;
|
||||||
|
GET_TYPED_DATA(prev, int64_t, type, &pBuf->v);
|
||||||
|
|
||||||
double val = GET_DOUBLE_VAL(tval);
|
double val = GET_DOUBLE_VAL(tval);
|
||||||
UPDATE_DATA(pCtx, *(float*)&pBuf->v, val, numOfElems, isMinFunc, key);
|
if ((prev < val) ^ isMinFunc) {
|
||||||
|
pBuf->v = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCtx->subsidiaries.num > 0) {
|
||||||
|
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pBuf->assign = true;
|
pBuf->assign = true;
|
||||||
|
@ -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) {
|
||||||
// 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) {
|
||||||
|
float v = *(double*) &pRes->v;
|
||||||
|
colDataAppend(pCol, currentRow, (const char*)&v, false);
|
||||||
|
} else {
|
||||||
colDataAppend(pCol, currentRow, (const char*)&pRes->v, false);
|
colDataAppend(pCol, currentRow, (const char*)&pRes->v, false);
|
||||||
setSelectivityValue(pCtx, pBlock, &pRes->tuplePos, currentRow);
|
}
|
||||||
|
|
||||||
|
setSelectivityValue(pCtx, pBlock, &pRes->tuplePos, currentRow);
|
||||||
return pEntryInfo->numOfRes;
|
return pEntryInfo->numOfRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -141,6 +141,7 @@ 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
|
||||||
|
|
Loading…
Reference in New Issue