diff --git a/src/query/inc/tdigest.h b/src/query/inc/tdigest.h index b513317169163f5ce79b03add60395834b33ea8c..625311eaabebec1f3d3b8303f34a361ba0129094 100644 --- a/src/query/inc/tdigest.h +++ b/src/query/inc/tdigest.h @@ -26,6 +26,8 @@ #define M_PI 3.14159265358979323846264338327950288 /* pi */ #endif +#define DOUBLE_MAX 1.79e+308 + #define ADDITION_CENTROID_NUM 2 #define COMPRESSION 400 #define GET_CENTROID(compression) (ceil(compression * M_PI / 2) + 1 + ADDITION_CENTROID_NUM) diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index 23365371ec1d6703dfa62faaedc791497c268afb..4d7edad3e5714b4c0f288d66c38cf2b63d5104fe 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -2442,8 +2442,6 @@ static SAPercentileInfo *getAPerctInfo(SQLFunctionCtx *pCtx) { } else { pInfo = GET_ROWCELL_INTERBUF(pResInfo); } - - buildHistogramInfo(pInfo); return pInfo; } @@ -2572,6 +2570,7 @@ static bool apercentile_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* } SAPercentileInfo *pInfo = getAPerctInfo(pCtx); + buildHistogramInfo(pInfo); char *tmp = (char *)pInfo + sizeof(SAPercentileInfo); pInfo->pHisto = tHistogramCreateFrom(tmp, MAX_HISTOGRAM_BIN); @@ -2588,6 +2587,7 @@ static void apercentile_function(SQLFunctionCtx *pCtx) { SResultRowCellInfo * pResInfo = GET_RES_INFO(pCtx); SAPercentileInfo *pInfo = getAPerctInfo(pCtx); + buildHistogramInfo(pInfo); assert(pInfo->pHisto->elems != NULL); @@ -2631,6 +2631,7 @@ static void apercentile_func_merge(SQLFunctionCtx *pCtx) { } SAPercentileInfo *pOutput = getAPerctInfo(pCtx); + buildHistogramInfo(pOutput); SHistogramInfo *pHisto = pOutput->pHisto; if (pHisto->numOfElems <= 0) { diff --git a/src/query/src/tdigest.c b/src/query/src/tdigest.c index 29ff707bef5c32bc7652340427c375eeaa6577af..fd850fe0cf4e772a21a7fd89c5bea60278620dc6 100644 --- a/src/query/src/tdigest.c +++ b/src/query/src/tdigest.c @@ -56,7 +56,9 @@ TDigest *tdigestNewFrom(void* pBuf, int32_t compression) { t->compression = compression; t->size = (int64_t)GET_CENTROID(compression); t->threshold = (int32_t)GET_THRESHOLD(compression); - t->min = INFINITY; + t->min = DOUBLE_MAX; + t->max = -DOUBLE_MAX; + return t; } @@ -128,7 +130,8 @@ void tdigestCompress(TDigest *t) { memset(args.centroids, 0, (size_t)(sizeof(SCentroid) * t->size)); args.t = t; - args.min = INFINITY; + args.min = DOUBLE_MAX; + args.max = -DOUBLE_MAX; i = 0; j = 0;