提交 3efadc9a 编写于 作者: G Ganlin Zhao

[TD-11222]<feature>: Histogram function

上级 a1d6e6af
...@@ -213,8 +213,7 @@ typedef struct { ...@@ -213,8 +213,7 @@ typedef struct {
typedef struct { typedef struct {
double lower; // >lower double lower; // >lower
double upper; // <=upper double upper; // <=upper
int64_t count; double count;
double count_norm;
} SHistogramFuncBin; } SHistogramFuncBin;
typedef struct{ typedef struct{
...@@ -5012,7 +5011,7 @@ static void histogram_function(SQLFunctionCtx *pCtx) { ...@@ -5012,7 +5011,7 @@ static void histogram_function(SQLFunctionCtx *pCtx) {
if (pRes->normalized) { if (pRes->normalized) {
for (int32_t b = 0; b < pRes->numOfBins; ++b) { for (int32_t b = 0; b < pRes->numOfBins; ++b) {
pRes->orderedBins[b].count_norm = pRes->orderedBins[b].count / (double)totalElems; pRes->orderedBins[b].count = pRes->orderedBins[b].count / (double)totalElems;
} }
} }
...@@ -5047,11 +5046,12 @@ static void histogram_func_finalizer(SQLFunctionCtx *pCtx) { ...@@ -5047,11 +5046,12 @@ static void histogram_func_finalizer(SQLFunctionCtx *pCtx) {
for (int32_t i = 0; i < pRes->numOfBins; ++i) { for (int32_t i = 0; i < pRes->numOfBins; ++i) {
int sz; int sz;
if (!pRes->normalized) { if (!pRes->normalized) {
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, pRes->orderedBins[i].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_norm); pRes->orderedBins[i].lower, pRes->orderedBins[i].upper, pRes->orderedBins[i].count);
} }
varDataSetLen(pCtx->pOutput, sz); varDataSetLen(pCtx->pOutput, sz);
pCtx->pOutput += pCtx->outputBytes; pCtx->pOutput += pCtx->outputBytes;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册