[td-1206]
This commit is contained in:
parent
50e73ebbce
commit
f3c92ad39b
|
@ -2422,24 +2422,14 @@ static void top_bottom_func_finalizer(SQLFunctionCtx *pCtx) {
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
static bool percentile_function_setup(SQLFunctionCtx *pCtx) {
|
static bool percentile_function_setup(SQLFunctionCtx *pCtx) {
|
||||||
const int32_t MAX_AVAILABLE_BUFFER_SIZE = 1 << 20; // 1MB
|
|
||||||
const int32_t NUMOFCOLS = 1;
|
|
||||||
|
|
||||||
if (!function_setup(pCtx)) {
|
if (!function_setup(pCtx)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SResultInfo *pResInfo = GET_RES_INFO(pCtx);
|
SResultInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||||
SSchema field[1] = { { (uint8_t)pCtx->inputType, "dummyCol", 0, pCtx->inputBytes } };
|
|
||||||
|
|
||||||
SColumnModel *pModel = createColumnModel(field, 1, 1000);
|
|
||||||
int32_t orderIdx = 0;
|
|
||||||
|
|
||||||
// tOrderDesc object
|
|
||||||
tOrderDescriptor *pDesc = tOrderDesCreate(&orderIdx, NUMOFCOLS, pModel, TSDB_ORDER_DESC);
|
|
||||||
|
|
||||||
((SPercentileInfo *)(pResInfo->interResultBuf))->pMemBucket =
|
((SPercentileInfo *)(pResInfo->interResultBuf))->pMemBucket =
|
||||||
tMemBucketCreate(1024, MAX_AVAILABLE_BUFFER_SIZE, pCtx->inputBytes, pCtx->inputType, pDesc);
|
tMemBucketCreate(pCtx->inputBytes, pCtx->inputType);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2485,15 +2475,13 @@ static void percentile_finalizer(SQLFunctionCtx *pCtx) {
|
||||||
SResultInfo *pResInfo = GET_RES_INFO(pCtx);
|
SResultInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||||
tMemBucket * pMemBucket = ((SPercentileInfo *)pResInfo->interResultBuf)->pMemBucket;
|
tMemBucket * pMemBucket = ((SPercentileInfo *)pResInfo->interResultBuf)->pMemBucket;
|
||||||
|
|
||||||
if (pMemBucket->numOfElems > 0) { // check for null
|
if (pMemBucket->total > 0) { // check for null
|
||||||
*(double *)pCtx->aOutputBuf = getPercentile(pMemBucket, v);
|
*(double *)pCtx->aOutputBuf = getPercentile(pMemBucket, v);
|
||||||
} else {
|
} else {
|
||||||
setNull(pCtx->aOutputBuf, pCtx->outputType, pCtx->outputBytes);
|
setNull(pCtx->aOutputBuf, pCtx->outputType, pCtx->outputBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
tOrderDescDestroy(pMemBucket->pOrderDesc);
|
|
||||||
tMemBucketDestroy(pMemBucket);
|
tMemBucketDestroy(pMemBucket);
|
||||||
|
|
||||||
doFinalizer(pCtx);
|
doFinalizer(pCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
#define TDENGINE_QPERCENTILE_H
|
#define TDENGINE_QPERCENTILE_H
|
||||||
|
|
||||||
#include "qExtbuffer.h"
|
#include "qExtbuffer.h"
|
||||||
|
#include "qResultbuf.h"
|
||||||
|
#include "qTsbuf.h"
|
||||||
|
|
||||||
typedef struct MinMaxEntry {
|
typedef struct MinMaxEntry {
|
||||||
union {
|
union {
|
||||||
|
@ -31,47 +33,43 @@ typedef struct MinMaxEntry {
|
||||||
};
|
};
|
||||||
} MinMaxEntry;
|
} MinMaxEntry;
|
||||||
|
|
||||||
typedef struct tMemBucketSegment {
|
typedef struct {
|
||||||
int32_t numOfSlots;
|
int32_t size;
|
||||||
MinMaxEntry * pBoundingEntries;
|
int32_t pageId;
|
||||||
tExtMemBuffer **pBuffer;
|
tFilePage *data;
|
||||||
} tMemBucketSegment;
|
} SSlotInfo;
|
||||||
|
|
||||||
|
typedef struct tMemBucketSlot {
|
||||||
|
SSlotInfo info;
|
||||||
|
MinMaxEntry range;
|
||||||
|
} tMemBucketSlot;
|
||||||
|
|
||||||
|
struct tMemBucket;
|
||||||
|
typedef int32_t (*__perc_hash_func_t)(struct tMemBucket *pBucket, const void *value);
|
||||||
|
|
||||||
typedef struct tMemBucket {
|
typedef struct tMemBucket {
|
||||||
int16_t numOfSegs;
|
int16_t numOfSlots;
|
||||||
int16_t nTotalSlots;
|
int16_t type;
|
||||||
int16_t nSlotsOfSeg;
|
int16_t bytes;
|
||||||
int16_t dataType;
|
int32_t total;
|
||||||
|
int32_t elemPerPage; // number of elements for each object
|
||||||
|
int32_t maxCapacity; // maximum allowed number of elements that can be sort directly to get the result
|
||||||
|
int32_t bufPageSize; // disk page size
|
||||||
|
MinMaxEntry range; // value range
|
||||||
|
int32_t times; // count that has been checked for deciding the correct data value buckets.
|
||||||
|
__compar_fn_t comparFn;
|
||||||
|
|
||||||
int16_t nElemSize;
|
tMemBucketSlot *pSlots;
|
||||||
int32_t numOfElems;
|
SDiskbasedResultBuf *pBuffer;
|
||||||
|
__perc_hash_func_t hashFunc;
|
||||||
int32_t nTotalBufferSize;
|
|
||||||
int32_t maxElemsCapacity;
|
|
||||||
|
|
||||||
int32_t pageSize;
|
|
||||||
int16_t numOfTotalPages;
|
|
||||||
int16_t numOfAvailPages; /* remain available buffer pages */
|
|
||||||
|
|
||||||
tMemBucketSegment *pSegs;
|
|
||||||
tOrderDescriptor * pOrderDesc;
|
|
||||||
|
|
||||||
MinMaxEntry nRange;
|
|
||||||
|
|
||||||
void (*HashFunc)(struct tMemBucket *pBucket, void *value, int16_t *segIdx, int16_t *slotIdx);
|
|
||||||
} tMemBucket;
|
} tMemBucket;
|
||||||
|
|
||||||
tMemBucket *tMemBucketCreate(int32_t totalSlots, int32_t nBufferSize, int16_t nElemSize, int16_t dataType,
|
tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType);
|
||||||
tOrderDescriptor *pDesc);
|
|
||||||
|
|
||||||
void tMemBucketDestroy(tMemBucket *pBucket);
|
void tMemBucketDestroy(tMemBucket *pBucket);
|
||||||
|
|
||||||
void tMemBucketPut(tMemBucket *pBucket, void *data, int32_t numOfRows);
|
void tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size);
|
||||||
|
|
||||||
double getPercentile(tMemBucket *pMemBucket, double percent);
|
double getPercentile(tMemBucket *pMemBucket, double percent);
|
||||||
|
|
||||||
void tBucketIntHash(tMemBucket *pBucket, void *value, int16_t *segIdx, int16_t *slotIdx);
|
|
||||||
|
|
||||||
void tBucketDoubleHash(tMemBucket *pBucket, void *value, int16_t *segIdx, int16_t *slotIdx);
|
|
||||||
|
|
||||||
#endif // TDENGINE_QPERCENTILE_H
|
#endif // TDENGINE_QPERCENTILE_H
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue