未验证 提交 65fe36ff 编写于 作者: G Ganlin Zhao 提交者: GitHub

Merge pull request #12295 from taosdata/feature/3.0_glzhao

fix(query): fix histogram normalized result incorrect for super table
......@@ -112,6 +112,7 @@ typedef struct SHistoFuncBin {
typedef struct SHistoFuncInfo {
int32_t numOfBins;
int32_t totalCount;
bool normalized;
SHistoFuncBin bins[];
} SHistoFuncInfo;
......@@ -2580,6 +2581,9 @@ bool histogramFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo *pResultIn
}
SHistoFuncInfo *pInfo = GET_ROWCELL_INTERBUF(pResultInfo);
pInfo->numOfBins = 0;
pInfo->totalCount = 0;
pInfo->normalized = 0;
int8_t binType = getHistogramBinType(varDataVal(pCtx->param[1].param.pz));
if (binType == UNKNOWN_BIN) {
......@@ -2609,7 +2613,6 @@ int32_t histogramFunction(SqlFunctionCtx *pCtx) {
int32_t numOfRows = pInput->numOfRows;
int32_t numOfElems = 0;
int32_t totalElems = 0;
for (int32_t i = start; i < numOfRows + start; ++i) {
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
continue;
......@@ -2624,23 +2627,13 @@ int32_t histogramFunction(SqlFunctionCtx *pCtx) {
for (int32_t k = 0; k < pInfo->numOfBins; ++k) {
if (v > pInfo->bins[k].lower && v <= pInfo->bins[k].upper) {
pInfo->bins[k].count++;
totalElems++;
pInfo->totalCount++;
break;
}
}
}
if (pInfo->normalized) {
for (int32_t k = 0; k < pInfo->numOfBins; ++k) {
if(totalElems != 0) {
pInfo->bins[k].percentage = pInfo->bins[k].count / (double)totalElems;
} else {
pInfo->bins[k].percentage = 0;
}
}
}
SET_VAL(GET_RES_INFO(pCtx), numOfElems, pInfo->numOfBins);
return TSDB_CODE_SUCCESS;
}
......@@ -2653,6 +2646,16 @@ int32_t histogramFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
int32_t currentRow = pBlock->info.rows;
if (pInfo->normalized) {
for (int32_t k = 0; k < pResInfo->numOfRes; ++k) {
if(pInfo->totalCount != 0) {
pInfo->bins[k].percentage = pInfo->bins[k].count / (double)pInfo->totalCount;
} else {
pInfo->bins[k].percentage = 0;
}
}
}
for (int32_t i = 0; i < pResInfo->numOfRes; ++i) {
int32_t len;
char buf[512] = {0};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册