enh:[TD-31525] Remove ASSERT in libs/function.
This commit is contained in:
parent
55f7b7d771
commit
5fb431aff4
|
@ -878,6 +878,8 @@ int32_t taosGetErrSize();
|
|||
#define TSDB_CODE_FUNC_INVALID_VALUE_RANGE TAOS_DEF_ERROR_CODE(0, 0x280C)
|
||||
#define TSDB_CODE_FUNC_SETUP_ERROR TAOS_DEF_ERROR_CODE(0, 0x280D)
|
||||
#define TSDB_CODE_FUNC_INVALID_RES_LENGTH TAOS_DEF_ERROR_CODE(0, 0x280E)
|
||||
#define TSDB_CODE_FUNC_HISTOGRAM_ERROR TAOS_DEF_ERROR_CODE(0, 0x280F)
|
||||
#define TSDB_CODE_FUNC_PERCENTILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x2810)
|
||||
|
||||
|
||||
//udf
|
||||
|
|
|
@ -59,7 +59,7 @@ int32_t tHistogramCreate(int32_t numOfEntries, SHistogramInfo** pHisto);
|
|||
SHistogramInfo* tHistogramCreateFrom(void* pBuf, int32_t numOfBins);
|
||||
|
||||
int32_t tHistogramAdd(SHistogramInfo** pHisto, double val);
|
||||
int64_t tHistogramSum(SHistogramInfo* pHisto, double v);
|
||||
int32_t tHistogramSum(SHistogramInfo* pHisto, double v, int64_t *res);
|
||||
|
||||
int32_t tHistogramUniform(SHistogramInfo* pHisto, double* ratio, int32_t num, double** pVal);
|
||||
int32_t tHistogramMerge(SHistogramInfo* pHisto1, SHistogramInfo* pHisto2, int32_t numOfEntries,
|
||||
|
|
|
@ -47,7 +47,7 @@ typedef struct tMemBucketSlot {
|
|||
} tMemBucketSlot;
|
||||
|
||||
struct tMemBucket;
|
||||
typedef int32_t (*__perc_hash_func_t)(struct tMemBucket *pBucket, const void *value);
|
||||
typedef int32_t (*__perc_hash_func_t)(struct tMemBucket *pBucket, const void *value, int32_t *index);
|
||||
|
||||
typedef struct tMemBucket {
|
||||
int16_t numOfSlots;
|
||||
|
|
|
@ -4018,7 +4018,9 @@ int32_t saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock*
|
|||
if (NULL == pColInfo) {
|
||||
return TSDB_CODE_OUT_OF_RANGE;
|
||||
}
|
||||
ASSERT(pColInfo->info.type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
if (pColInfo->info.type != TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
return TSDB_CODE_FUNC_FUNTION_PARA_TYPE;
|
||||
}
|
||||
key.groupId = pSrcBlock->info.id.groupId;
|
||||
key.ts = *(int64_t*)colDataGetData(pColInfo, rowIndex);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
#include "os.h"
|
||||
|
||||
#include "query.h"
|
||||
#include "taosdef.h"
|
||||
#include "thistogram.h"
|
||||
#include "tlosertree.h"
|
||||
|
@ -81,9 +82,9 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
|
|||
|
||||
#if defined(USE_ARRAYLIST)
|
||||
int32_t idx = histoBinarySearch((*pHisto)->elems, (*pHisto)->numOfEntries, val);
|
||||
if (ASSERTS(idx >= 0 && idx <= (*pHisto)->maxEntries && (*pHisto)->elems != NULL, "tHistogramAdd Error, idx:%d, maxEntries:%d, elems:%p",
|
||||
idx, (*pHisto)->maxEntries, (*pHisto)->elems)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
if (idx < 0 || idx > (*pHisto)->maxEntries || (*pHisto)->elems == NULL) {
|
||||
qError("tHistogramAdd Error, idx:%d, maxEntries:%d, elems:%p", idx, (*pHisto)->maxEntries, (*pHisto)->elems);
|
||||
return TSDB_CODE_FUNC_HISTOGRAM_ERROR;
|
||||
}
|
||||
|
||||
if ((*pHisto)->elems[idx].val == val && idx >= 0) {
|
||||
|
@ -95,21 +96,19 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
|
|||
} else { /* insert a new slot */
|
||||
if ((*pHisto)->numOfElems >= 1 && idx < (*pHisto)->numOfEntries) {
|
||||
if (idx > 0) {
|
||||
if (ASSERTS((*pHisto)->elems[idx - 1].val <= val, "tHistogramAdd Error, elems[%d].val:%lf, val:%lf",
|
||||
idx - 1, (*pHisto)->elems[idx - 1].val, val)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
if ((*pHisto)->elems[idx - 1].val > val) {
|
||||
qError("tHistogramAdd Error, elems[%d].val:%lf, val:%lf", idx - 1, (*pHisto)->elems[idx - 1].val, val);
|
||||
return TSDB_CODE_FUNC_HISTOGRAM_ERROR;
|
||||
}
|
||||
} else {
|
||||
if (ASSERTS((*pHisto)->elems[idx].val > val, "tHistogramAdd Error, elems[%d].val:%lf, val:%lf",
|
||||
idx, (*pHisto)->elems[idx].val, val)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
if ((*pHisto)->elems[idx].val <= val) {
|
||||
qError("tHistogramAdd Error, elems[%d].val:%lf, val:%lf", idx, (*pHisto)->elems[idx].val, val);
|
||||
return TSDB_CODE_FUNC_HISTOGRAM_ERROR;
|
||||
}
|
||||
}
|
||||
} else if ((*pHisto)->numOfElems > 0) {
|
||||
if (ASSERTS((*pHisto)->elems[(*pHisto)->numOfEntries].val <= val, "tHistogramAdd Error, elems[%d].val:%lf, val:%lf",
|
||||
(*pHisto)->numOfEntries, (*pHisto)->elems[idx].val, val)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
} else if ((*pHisto)->numOfElems > 0 && (*pHisto)->elems[(*pHisto)->numOfEntries].val > val) {
|
||||
qError("tHistogramAdd Error, elems[%d].val:%lf, val:%lf", (*pHisto)->numOfEntries, (*pHisto)->elems[idx].val, val);
|
||||
return TSDB_CODE_FUNC_HISTOGRAM_ERROR;
|
||||
}
|
||||
|
||||
code = histogramCreateBin(*pHisto, idx, val);
|
||||
|
@ -225,9 +224,9 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
|
|||
|
||||
tSkipListNode* pNext = pNode->pForward[0];
|
||||
SHistBin* pNextEntry = (SHistBin*)pNext->pData;
|
||||
if (ASSERTS(pNextEntry->val - pEntry->val == pEntry->delta, "tHistogramAdd Error, pNextEntry->val:%lf, pEntry->val:%lf, pEntry->delta:%lf",
|
||||
pNextEntry->val, pEntry->val, pEntry->delta)) {
|
||||
return -1;
|
||||
if (pNextEntry->val - pEntry->val != pEntry->delta) {
|
||||
qError("tHistogramAdd Error, pNextEntry->val:%lf, pEntry->val:%lf, pEntry->delta:%lf", pNextEntry->val, pEntry->val, pEntry->delta);
|
||||
return TSDB_CODE_FUNC_HISTOGRAM_ERROR;
|
||||
}
|
||||
|
||||
double newVal = (pEntry->val * pEntry->num + pNextEntry->val * pNextEntry->num) / (pEntry->num + pNextEntry->num);
|
||||
|
@ -278,8 +277,9 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
|
|||
|
||||
} else {
|
||||
SHistBin* pEntry = (SHistBin*)pResNode->pData;
|
||||
if (ASSERTS(pEntry->val == val, "tHistogramAdd Error, pEntry->val:%lf, val:%lf")) {
|
||||
return -1;
|
||||
if (pEntry->val != val) {
|
||||
qError("tHistogramAdd Error, pEntry->val:%lf, val:%lf", pEntry->val, val);
|
||||
return TSDB_CODE_FUNC_HISTOGRAM_ERROR;
|
||||
}
|
||||
pEntry->num += 1;
|
||||
}
|
||||
|
@ -356,9 +356,9 @@ int32_t histogramCreateBin(SHistogramInfo* pHisto, int32_t index, double val) {
|
|||
(void)memmove(&pHisto->elems[index + 1], &pHisto->elems[index], sizeof(SHistBin) * remain);
|
||||
}
|
||||
|
||||
if (ASSERTS(index >= 0 && index <= pHisto->maxEntries, "histogramCreateBin Error, index:%d, maxEntries:%d",
|
||||
index, pHisto->maxEntries)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
if (index < 0 || index > pHisto->maxEntries) {
|
||||
qError("histogramCreateBin Error, index:%d, maxEntries:%d", index, pHisto->maxEntries);
|
||||
return TSDB_CODE_FUNC_HISTOGRAM_ERROR;
|
||||
}
|
||||
|
||||
pHisto->elems[index].num = 1;
|
||||
|
@ -373,9 +373,9 @@ int32_t histogramCreateBin(SHistogramInfo* pHisto, int32_t index, double val) {
|
|||
pHisto->elems[pHisto->maxEntries].num = 0;
|
||||
}
|
||||
#endif
|
||||
if (ASSERTS(pHisto->numOfEntries <= pHisto->maxEntries, "histogramCreateBin Error, numOfEntries:%d, maxEntries:%d",
|
||||
pHisto->numOfEntries, pHisto->maxEntries)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
if (pHisto->numOfEntries > pHisto->maxEntries) {
|
||||
qError("histogramCreateBin Error, numOfEntries:%d, maxEntries:%d", pHisto->numOfEntries, pHisto->maxEntries);
|
||||
return TSDB_CODE_FUNC_HISTOGRAM_ERROR;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -411,8 +411,9 @@ void tHistogramPrint(SHistogramInfo* pHisto) {
|
|||
* Estimated number of points in the interval (−inf,b].
|
||||
* @param pHisto
|
||||
* @param v
|
||||
* @param res
|
||||
*/
|
||||
int64_t tHistogramSum(SHistogramInfo* pHisto, double v) {
|
||||
int32_t tHistogramSum(SHistogramInfo* pHisto, double v, int64_t *res) {
|
||||
#if defined(USE_ARRAYLIST)
|
||||
int32_t slotIdx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, v);
|
||||
if (pHisto->elems[slotIdx].val != v) {
|
||||
|
@ -420,14 +421,18 @@ int64_t tHistogramSum(SHistogramInfo* pHisto, double v) {
|
|||
|
||||
if (slotIdx < 0) {
|
||||
slotIdx = 0;
|
||||
ASSERTS(v <= pHisto->elems[slotIdx].val, "tHistogramSum Error, elems[%d].val:%lf, v:%lf",
|
||||
slotIdx, pHisto->elems[slotIdx].val, v);
|
||||
if (v > pHisto->elems[slotIdx].val) {
|
||||
qError("tHistogramSum Error, elems[%d].val:%lf, v:%lf", slotIdx, pHisto->elems[slotIdx].val, v);
|
||||
return TSDB_CODE_FUNC_HISTOGRAM_ERROR;
|
||||
}
|
||||
} else {
|
||||
ASSERTS(v >= pHisto->elems[slotIdx].val, "tHistogramSum Error, elems[%d].val:%lf, v:%lf",
|
||||
slotIdx, pHisto->elems[slotIdx].val, v);
|
||||
if (slotIdx + 1 < pHisto->numOfEntries) {
|
||||
ASSERTS(v < pHisto->elems[slotIdx + 1].val, "tHistogramSum Error, elems[%d].val:%lf, v:%lf",
|
||||
slotIdx + 1, pHisto->elems[slotIdx + 1].val, v);
|
||||
if (v < pHisto->elems[slotIdx].val) {
|
||||
qError("tHistogramSum Error, elems[%d].val:%lf, v:%lf", slotIdx, pHisto->elems[slotIdx].val, v);
|
||||
return TSDB_CODE_FUNC_HISTOGRAM_ERROR;
|
||||
}
|
||||
if (slotIdx + 1 < pHisto->numOfEntries && v >= pHisto->elems[slotIdx + 1].val) {
|
||||
qError("tHistogramSum Error, elems[%d].val:%lf, v:%lf", slotIdx + 1, pHisto->elems[slotIdx + 1].val, v);
|
||||
return TSDB_CODE_FUNC_HISTOGRAM_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -447,8 +452,9 @@ int64_t tHistogramSum(SHistogramInfo* pHisto, double v) {
|
|||
|
||||
s1 = s1 + m1 / 2;
|
||||
|
||||
return (int64_t)s1;
|
||||
*res = (int64_t)s1;
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tHistogramUniform(SHistogramInfo* pHisto, double* ratio, int32_t num, double** pVal) {
|
||||
|
@ -484,9 +490,11 @@ int32_t tHistogramUniform(SHistogramInfo* pHisto, double* ratio, int32_t num, do
|
|||
j += 1;
|
||||
}
|
||||
|
||||
ASSERTS(total <= numOfElem && total + pHisto->elems[j + 1].num > numOfElem,
|
||||
"tHistogramUniform Error, total:%ld, numOfElem:%ld, elems[%d].num:%ld",
|
||||
total, (int64_t)numOfElem, j + 1, pHisto->elems[j + 1].num);
|
||||
if (total > numOfElem || total + pHisto->elems[j + 1].num <= numOfElem) {
|
||||
qError("tHistogramUniform Error, total:%d, numOfElem:%d, elems[%d].num:%d",
|
||||
(int32_t)total, (int32_t)numOfElem, j + 1, (int32_t)pHisto->elems[j + 1].num);
|
||||
return TSDB_CODE_FUNC_HISTOGRAM_ERROR;
|
||||
}
|
||||
|
||||
double delta = numOfElem - total;
|
||||
if (fabs(delta) < FLT_EPSILON) {
|
||||
|
@ -545,9 +553,10 @@ int32_t tHistogramUniform(SHistogramInfo* pHisto, double* ratio, int32_t num, do
|
|||
j += 1;
|
||||
}
|
||||
|
||||
ASSERTS(total <= numOfElem && total + pEntry->num > numOfElem,
|
||||
"tHistogramUniform Error, total:%d, numOfElem:%d, pEntry->num:%d",
|
||||
total, numOfElem, pEntry->num);
|
||||
if (total > numOfElem || total + pEntry->num <= numOfElem) {
|
||||
qError("tHistogramUniform Error, total:%d, numOfElem:%d, pEntry->num:%d", (int32_t)total, (int32_t)numOfElem, (int32_t)pEntry->num);
|
||||
return TSDB_CODE_FUNC_HISTOGRAM_ERROR;
|
||||
}
|
||||
|
||||
double delta = numOfElem - total;
|
||||
if (fabs(delta) < FLT_EPSILON) {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "query.h"
|
||||
#include "taoserror.h"
|
||||
#include "tcompare.h"
|
||||
#include "tglobal.h"
|
||||
|
@ -107,7 +108,10 @@ static void resetPosInfo(SSlotInfo *pInfo) {
|
|||
}
|
||||
|
||||
int32_t findOnlyResult(tMemBucket *pMemBucket, double *result) {
|
||||
ASSERT(pMemBucket->total == 1);
|
||||
if (pMemBucket->total != 1) {
|
||||
qError("MemBucket:%p, total:%d, but only one element is expected", pMemBucket, pMemBucket->total);
|
||||
return TSDB_CODE_FUNC_PERCENTILE_ERROR;
|
||||
}
|
||||
terrno = 0;
|
||||
|
||||
for (int32_t i = 0; i < pMemBucket->numOfSlots; ++i) {
|
||||
|
@ -120,7 +124,10 @@ int32_t findOnlyResult(tMemBucket *pMemBucket, double *result) {
|
|||
SArray **pList = taosHashGet(pMemBucket->groupPagesMap, &groupId, sizeof(groupId));
|
||||
if (pList != NULL) {
|
||||
SArray *list = *pList;
|
||||
ASSERT(list->size == 1);
|
||||
if (list->size != 1) {
|
||||
qError("list:%p, total list size:%zu, but only one element is expected", list, list->size);
|
||||
return TSDB_CODE_FUNC_PERCENTILE_ERROR;
|
||||
}
|
||||
|
||||
int32_t *pageId = taosArrayGet(list, 0);
|
||||
if (NULL == pageId) {
|
||||
|
@ -130,7 +137,11 @@ int32_t findOnlyResult(tMemBucket *pMemBucket, double *result) {
|
|||
if (pPage == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
ASSERT(pPage->num == 1);
|
||||
if (pPage->num != 1) {
|
||||
qError("page:%p, total num:%d, but only one element is expected", pPage, pPage->num);
|
||||
releaseBufPage(pMemBucket->pBuffer, pPage);
|
||||
return TSDB_CODE_FUNC_PERCENTILE_ERROR;
|
||||
}
|
||||
|
||||
GET_TYPED_DATA(*result, double, pMemBucket->type, pPage->data);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -141,64 +152,69 @@ int32_t findOnlyResult(tMemBucket *pMemBucket, double *result) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tBucketIntHash(tMemBucket *pBucket, const void *value) {
|
||||
int32_t tBucketIntHash(tMemBucket *pBucket, const void *value, int32_t *index) {
|
||||
int64_t v = 0;
|
||||
GET_TYPED_DATA(v, int64_t, pBucket->type, value);
|
||||
|
||||
int32_t index = -1;
|
||||
*index = -1;
|
||||
|
||||
if (v > pBucket->range.dMaxVal || v < pBucket->range.dMinVal) {
|
||||
return index;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// divide the value range into 1024 buckets
|
||||
uint64_t span = pBucket->range.dMaxVal - pBucket->range.dMinVal;
|
||||
if (span < pBucket->numOfSlots) {
|
||||
int64_t delta = v - pBucket->range.dMinVal;
|
||||
index = (delta % pBucket->numOfSlots);
|
||||
*index = (delta % pBucket->numOfSlots);
|
||||
} else {
|
||||
double slotSpan = ((double)span) / pBucket->numOfSlots;
|
||||
uint64_t delta = (uint64_t)(v - pBucket->range.dMinVal);
|
||||
|
||||
index = delta / slotSpan;
|
||||
if (v == pBucket->range.dMaxVal || index == pBucket->numOfSlots) {
|
||||
index -= 1;
|
||||
*index = delta / slotSpan;
|
||||
if (v == pBucket->range.dMaxVal || *index == pBucket->numOfSlots) {
|
||||
*index -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERTS(index >= 0 && index < pBucket->numOfSlots, "tBucketIntHash Error, index:%d, numOfSlots:%d",
|
||||
index, pBucket->numOfSlots);
|
||||
return index;
|
||||
if (*index < 0 || *index >= pBucket->numOfSlots) {
|
||||
qError("tBucketIntHash Error, index:%d, numOfSlots:%d", *index, pBucket->numOfSlots);
|
||||
return TSDB_CODE_FUNC_PERCENTILE_ERROR;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tBucketUintHash(tMemBucket *pBucket, const void *value) {
|
||||
int32_t tBucketUintHash(tMemBucket *pBucket, const void *value, int32_t *index) {
|
||||
int64_t v = 0;
|
||||
GET_TYPED_DATA(v, uint64_t, pBucket->type, value);
|
||||
|
||||
int32_t index = -1;
|
||||
*index = -1;
|
||||
|
||||
if (v > pBucket->range.u64MaxVal || v < pBucket->range.u64MinVal) {
|
||||
return index;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// divide the value range into 1024 buckets
|
||||
uint64_t span = pBucket->range.u64MaxVal - pBucket->range.u64MinVal;
|
||||
if (span < pBucket->numOfSlots) {
|
||||
int64_t delta = v - pBucket->range.u64MinVal;
|
||||
index = (int32_t)(delta % pBucket->numOfSlots);
|
||||
*index = (int32_t)(delta % pBucket->numOfSlots);
|
||||
} else {
|
||||
double slotSpan = (double)span / pBucket->numOfSlots;
|
||||
index = (int32_t)((v - pBucket->range.u64MinVal) / slotSpan);
|
||||
*index = (int32_t)((v - pBucket->range.u64MinVal) / slotSpan);
|
||||
if (v == pBucket->range.u64MaxVal) {
|
||||
index -= 1;
|
||||
*index -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT(index >= 0 && index < pBucket->numOfSlots);
|
||||
return index;
|
||||
if (*index < 0 || *index >= pBucket->numOfSlots) {
|
||||
qError("tBucketUintHash Error, index:%d, numOfSlots:%d", *index, pBucket->numOfSlots);
|
||||
return TSDB_CODE_FUNC_PERCENTILE_ERROR;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tBucketDoubleHash(tMemBucket *pBucket, const void *value) {
|
||||
int32_t tBucketDoubleHash(tMemBucket *pBucket, const void *value, int32_t *index) {
|
||||
double v = 0;
|
||||
if (pBucket->type == TSDB_DATA_TYPE_FLOAT) {
|
||||
v = GET_FLOAT_VAL(value);
|
||||
|
@ -206,27 +222,30 @@ int32_t tBucketDoubleHash(tMemBucket *pBucket, const void *value) {
|
|||
v = GET_DOUBLE_VAL(value);
|
||||
}
|
||||
|
||||
int32_t index = -1;
|
||||
*index = -1;
|
||||
|
||||
if (v > pBucket->range.dMaxVal || v < pBucket->range.dMinVal) {
|
||||
return index;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// divide a range of [dMinVal, dMaxVal] into 1024 buckets
|
||||
double span = pBucket->range.dMaxVal - pBucket->range.dMinVal;
|
||||
if (span < pBucket->numOfSlots) {
|
||||
int32_t delta = (int32_t)(v - pBucket->range.dMinVal);
|
||||
index = (delta % pBucket->numOfSlots);
|
||||
*index = (delta % pBucket->numOfSlots);
|
||||
} else {
|
||||
double slotSpan = span / pBucket->numOfSlots;
|
||||
index = (int32_t)((v - pBucket->range.dMinVal) / slotSpan);
|
||||
*index = (int32_t)((v - pBucket->range.dMinVal) / slotSpan);
|
||||
if (v == pBucket->range.dMaxVal) {
|
||||
index -= 1;
|
||||
*index -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT(index >= 0 && index < pBucket->numOfSlots);
|
||||
return index;
|
||||
if (*index < 0 || *index >= pBucket->numOfSlots) {
|
||||
qError("tBucketDoubleHash Error, index:%d, numOfSlots:%d", *index, pBucket->numOfSlots);
|
||||
return TSDB_CODE_FUNC_PERCENTILE_ERROR;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static __perc_hash_func_t getHashFunc(int32_t type) {
|
||||
|
@ -333,7 +352,7 @@ void tMemBucketDestroy(tMemBucket *pBucket) {
|
|||
taosMemoryFreeClear(pBucket);
|
||||
}
|
||||
|
||||
void tMemBucketUpdateBoundingBox(MinMaxEntry *r, const char *data, int32_t dataType) {
|
||||
int32_t tMemBucketUpdateBoundingBox(MinMaxEntry *r, const char *data, int32_t dataType) {
|
||||
if (IS_SIGNED_NUMERIC_TYPE(dataType)) {
|
||||
int64_t v = 0;
|
||||
GET_TYPED_DATA(v, int64_t, dataType, data);
|
||||
|
@ -368,8 +387,10 @@ void tMemBucketUpdateBoundingBox(MinMaxEntry *r, const char *data, int32_t dataT
|
|||
r->dMaxVal = v;
|
||||
}
|
||||
} else {
|
||||
ASSERT(0);
|
||||
qError("tMemBucketUpdateBoundingBox Error, invalid data type:%d", dataType);
|
||||
return TSDB_CODE_FUNC_PERCENTILE_ERROR;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -378,9 +399,14 @@ void tMemBucketUpdateBoundingBox(MinMaxEntry *r, const char *data, int32_t dataT
|
|||
int32_t tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size) {
|
||||
int32_t count = 0;
|
||||
int32_t bytes = pBucket->bytes;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
char *d = (char *)data + i * bytes;
|
||||
int32_t index = (pBucket->hashFunc)(pBucket, d);
|
||||
int32_t index = -1;
|
||||
code = (pBucket->hashFunc)(pBucket, d, &index);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
if (index < 0) {
|
||||
continue;
|
||||
}
|
||||
|
@ -388,7 +414,10 @@ int32_t tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size) {
|
|||
count += 1;
|
||||
|
||||
tMemBucketSlot *pSlot = &pBucket->pSlots[index];
|
||||
tMemBucketUpdateBoundingBox(&pSlot->range, d, pBucket->type);
|
||||
code = tMemBucketUpdateBoundingBox(&pSlot->range, d, pBucket->type);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
// ensure available memory pages to allocate
|
||||
int32_t groupId = getGroupId(pBucket->numOfSlots, index, pBucket->times);
|
||||
|
@ -396,7 +425,11 @@ int32_t tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size) {
|
|||
|
||||
if (pSlot->info.data == NULL || pSlot->info.data->num >= pBucket->elemPerPage) {
|
||||
if (pSlot->info.data != NULL) {
|
||||
ASSERT(pSlot->info.data->num >= pBucket->elemPerPage && pSlot->info.size > 0);
|
||||
if (pSlot->info.data->num < pBucket->elemPerPage || pSlot->info.size <= 0) {
|
||||
qError("tMemBucketPut failed since wrong pSLot info dataNum : %d, size : %d",
|
||||
pSlot->info.data->num, pSlot->info.size);
|
||||
return TSDB_CODE_FUNC_PERCENTILE_ERROR;
|
||||
}
|
||||
|
||||
// keep the pointer in memory
|
||||
setBufPageDirty(pSlot->info.data, true);
|
||||
|
@ -411,7 +444,7 @@ int32_t tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size) {
|
|||
if (NULL == pPageIdList) {
|
||||
return terrno;
|
||||
}
|
||||
int32_t code = taosHashPut(pBucket->groupPagesMap, &groupId, sizeof(groupId), &pPageIdList, POINTER_BYTES);
|
||||
code = taosHashPut(pBucket->groupPagesMap, &groupId, sizeof(groupId), &pPageIdList, POINTER_BYTES);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
taosArrayDestroy(pPageIdList);
|
||||
return code;
|
||||
|
@ -449,21 +482,23 @@ int32_t tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size) {
|
|||
* j is the last slot of current segment, we need to get the first
|
||||
* slot of the next segment.
|
||||
*/
|
||||
static MinMaxEntry getMinMaxEntryOfNextSlotWithData(tMemBucket *pMemBucket, int32_t slotIdx) {
|
||||
static int32_t getMinMaxEntryOfNextSlotWithData(tMemBucket *pMemBucket, int32_t slotIdx, MinMaxEntry *next) {
|
||||
int32_t j = slotIdx + 1;
|
||||
while (j < pMemBucket->numOfSlots && (pMemBucket->pSlots[j].info.size == 0)) {
|
||||
++j;
|
||||
}
|
||||
|
||||
ASSERT(j < pMemBucket->numOfSlots);
|
||||
return pMemBucket->pSlots[j].range;
|
||||
if (j >= pMemBucket->numOfSlots) {
|
||||
qError("getMinMaxEntryOfNextSlotWithData can not get valid slot, start with slotIdx:%d", slotIdx);
|
||||
return TSDB_CODE_FUNC_PERCENTILE_ERROR;
|
||||
}
|
||||
*next = pMemBucket->pSlots[j].range;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static bool isIdenticalData(tMemBucket *pMemBucket, int32_t index);
|
||||
|
||||
static double getIdenticalDataVal(tMemBucket *pMemBucket, int32_t slotIndex) {
|
||||
ASSERT(isIdenticalData(pMemBucket, slotIndex));
|
||||
|
||||
tMemBucketSlot *pSlot = &pMemBucket->pSlots[slotIndex];
|
||||
|
||||
double finalResult = 0.0;
|
||||
|
@ -494,7 +529,11 @@ int32_t getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction
|
|||
* now, we need to find the minimum value of the next slot for interpolating the percentile value
|
||||
* j is the last slot of current segment, we need to get the first slot of the next segment.
|
||||
*/
|
||||
MinMaxEntry next = getMinMaxEntryOfNextSlotWithData(pMemBucket, i);
|
||||
MinMaxEntry next;
|
||||
int32_t code = getMinMaxEntryOfNextSlotWithData(pMemBucket, i, &next);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
double maxOfThisSlot = 0;
|
||||
double minOfNextSlot = 0;
|
||||
|
@ -509,7 +548,10 @@ int32_t getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction
|
|||
minOfNextSlot = (double)next.dMinVal;
|
||||
}
|
||||
|
||||
ASSERT(minOfNextSlot > maxOfThisSlot);
|
||||
if (minOfNextSlot <= maxOfThisSlot) {
|
||||
qError("getPercentileImpl get minOfNextSlot : %f less equal than maxOfThisSlot : %f", minOfNextSlot, maxOfThisSlot);
|
||||
return TSDB_CODE_FUNC_PERCENTILE_ERROR;
|
||||
}
|
||||
|
||||
*result = (1 - fraction) * maxOfThisSlot + fraction * minOfNextSlot;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
|
|
@ -724,6 +724,8 @@ TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_TIME_UNIT_TOO_SMALL, "Function time unit c
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_INVALID_VALUE_RANGE, "Function got invalid value range")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_SETUP_ERROR, "Function set up failed")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_INVALID_RES_LENGTH, "Function result exceed max length")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_HISTOGRAM_ERROR, "Function failed to calculate histogram")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_PERCENTILE_ERROR, "Function failed to calculate percentile")
|
||||
|
||||
//udf
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_UDF_STOPPING, "udf is stopping")
|
||||
|
|
Loading…
Reference in New Issue