提交 84765ff6 编写于 作者: G Ganlin Zhao

refactor code

上级 9102c7a4
...@@ -517,14 +517,14 @@ static int32_t translatePercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t ...@@ -517,14 +517,14 @@ static int32_t translatePercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t
return invaildFuncParaValueErrMsg(pErrBuf, len, pFunc->functionName); return invaildFuncParaValueErrMsg(pErrBuf, len, pFunc->functionName);
} }
uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, i))->resType.type; uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, i))->resType.type;
if (!IS_SIGNED_NUMERIC_TYPE(paraType) && !IS_UNSIGNED_NUMERIC_TYPE(paraType)) { if (!IS_NUMERIC_TYPE(paraType)) {
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
} }
} }
// set result type // set result type
if (numOfParams > 2) { if (numOfParams > 2) {
pFunc->node.resType = (SDataType){.bytes = 128, .type = TSDB_DATA_TYPE_VARCHAR}; pFunc->node.resType = (SDataType){.bytes = 512, .type = TSDB_DATA_TYPE_VARCHAR};
} else { } else {
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE}; pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE};
} }
......
...@@ -1661,63 +1661,62 @@ int32_t percentileFunction(SqlFunctionCtx* pCtx) { ...@@ -1661,63 +1661,62 @@ int32_t percentileFunction(SqlFunctionCtx* pCtx) {
} }
int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
if (pCtx->numOfParams > 2) { SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
SPercentileInfo* ppInfo = (SPercentileInfo*)GET_ROWCELL_INTERBUF(pResInfo);
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); int32_t code = 0;
SPercentileInfo* ppInfo = (SPercentileInfo*)GET_ROWCELL_INTERBUF(pResInfo); double v = 0;
tMemBucket* pMemBucket = ppInfo->pMemBucket; tMemBucket* pMemBucket = ppInfo->pMemBucket;
if (pMemBucket == NULL || pMemBucket->total == 0) { // check for null if (pMemBucket == NULL || pMemBucket->total == 0) { // check for null
return TSDB_CODE_FAILED; code = TSDB_CODE_FAILED;
} goto _fin_error;
}
if (pCtx->numOfParams > 2) {
char buf[512] = {0}; char buf[512] = {0};
size_t len = 0; size_t len = 0;
for (int32_t i = 1; i < pCtx->numOfParams; ++i) { for (int32_t i = 1; i < pCtx->numOfParams; ++i) {
SVariant* pVal = &pCtx->param[i].param; SVariant* pVal = &pCtx->param[i].param;
double v = 0;
GET_TYPED_DATA(v, double, pVal->nType, &pVal->i); GET_TYPED_DATA(v, double, pVal->nType, &pVal->i);
int32_t code = getPercentile(pMemBucket, v, &ppInfo->result); int32_t code = getPercentile(pMemBucket, v, &ppInfo->result);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return code; goto _fin_error;
} }
len += snprintf(varDataVal(buf) + len, sizeof(buf) - VARSTR_HEADER_SIZE - len, "%.6lf; ", ppInfo->result); len += snprintf(varDataVal(buf) + len, sizeof(buf) - VARSTR_HEADER_SIZE - len, "%.6lf; ", ppInfo->result);
} }
tMemBucketDestroy(pMemBucket);
int32_t slotId = pCtx->pExpr->base.resSchema.slotId; int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
varDataSetLen(buf, len); varDataSetLen(buf, len);
colDataAppend(pCol, pBlock->info.rows, buf, false); colDataAppend(pCol, pBlock->info.rows, buf, false);
tMemBucketDestroy(pMemBucket);
return pResInfo->numOfRes; return pResInfo->numOfRes;
} else { } else {
SVariant* pVal = &pCtx->param[1].param; SVariant* pVal = &pCtx->param[1].param;
int32_t code = 0;
double v = 0;
GET_TYPED_DATA(v, double, pVal->nType, &pVal->i); GET_TYPED_DATA(v, double, pVal->nType, &pVal->i);
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); code = getPercentile(pMemBucket, v, &ppInfo->result);
SPercentileInfo* ppInfo = (SPercentileInfo*)GET_ROWCELL_INTERBUF(pResInfo); if (code != TSDB_CODE_SUCCESS) {
goto _fin_error;
tMemBucket* pMemBucket = ppInfo->pMemBucket;
if (pMemBucket != NULL && pMemBucket->total > 0) { // check for null
code = getPercentile(pMemBucket, v, &ppInfo->result);
} }
tMemBucketDestroy(pMemBucket); tMemBucketDestroy(pMemBucket);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
return functionFinalize(pCtx, pBlock); return functionFinalize(pCtx, pBlock);
} }
_fin_error:
tMemBucketDestroy(pMemBucket);
return code;
} }
bool getApercentileFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { bool getApercentileFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册