提交 75ae1bad 编写于 作者: G Ganlin Zhao

[TD-11222]<feature>: Histogram function

上级 f6bbd2c5
...@@ -4972,8 +4972,10 @@ static bool histogram_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* p ...@@ -4972,8 +4972,10 @@ static bool histogram_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* p
pRes->normalized = normalized; pRes->normalized = normalized;
pRes->orderedBins = (SHistogramFuncBin*)((char*)pRes + sizeof(SHistogramFuncInfo)); pRes->orderedBins = (SHistogramFuncBin*)((char*)pRes + sizeof(SHistogramFuncInfo));
for (int32_t i = 0; i < numOfBins; ++i) { for (int32_t i = 0; i < numOfBins; ++i) {
pRes->orderedBins[i].lower = listBin[i]; double lower = listBin[i] < listBin[i + 1] ? listBin[i] : listBin[i + 1];
pRes->orderedBins[i].upper = listBin[i+1]; double upper = listBin[i + 1] > listBin[i] ? listBin[i + 1] : listBin[i];
pRes->orderedBins[i].lower = lower;
pRes->orderedBins[i].upper = upper;
pRes->orderedBins[i].count = 0; pRes->orderedBins[i].count = 0;
} }
return true; return true;
...@@ -5047,10 +5049,10 @@ static void histogram_func_finalizer(SQLFunctionCtx *pCtx) { ...@@ -5047,10 +5049,10 @@ static void histogram_func_finalizer(SQLFunctionCtx *pCtx) {
int sz; int sz;
if (!pRes->normalized) { if (!pRes->normalized) {
int64_t count = (int64_t)pRes->orderedBins[i].count; int64_t count = (int64_t)pRes->orderedBins[i].count;
sz = sprintf(pCtx->pOutput + VARSTR_HEADER_SIZE, "(%g-%g]:%"PRId64, sz = sprintf(pCtx->pOutput + VARSTR_HEADER_SIZE, "(%g:%g]:%"PRId64,
pRes->orderedBins[i].lower, pRes->orderedBins[i].upper, count); pRes->orderedBins[i].lower, pRes->orderedBins[i].upper, count);
} else { } else {
sz = sprintf(pCtx->pOutput + VARSTR_HEADER_SIZE, "(%g-%g]:%lf", sz = sprintf(pCtx->pOutput + VARSTR_HEADER_SIZE, "(%g:%g]:%lf",
pRes->orderedBins[i].lower, pRes->orderedBins[i].upper, pRes->orderedBins[i].count); pRes->orderedBins[i].lower, pRes->orderedBins[i].upper, pRes->orderedBins[i].count);
} }
varDataSetLen(pCtx->pOutput, sz); varDataSetLen(pCtx->pOutput, sz);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册