未验证 提交 77c9414d 编写于 作者: G Ganlin Zhao 提交者: GitHub

Merge pull request #14955 from taosdata/feat/agg_client_api

feat(query): add percentile/apercentile scalar version
...@@ -104,6 +104,9 @@ int32_t maxScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam * ...@@ -104,6 +104,9 @@ int32_t maxScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *
int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
int32_t stddevScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t stddevScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
int32_t percentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
int32_t apercentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
int32_t spreadScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -2034,6 +2034,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { ...@@ -2034,6 +2034,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.getEnvFunc = getPercentileFuncEnv, .getEnvFunc = getPercentileFuncEnv,
.initFunc = percentileFunctionSetup, .initFunc = percentileFunctionSetup,
.processFunc = percentileFunction, .processFunc = percentileFunction,
.sprocessFunc = percentileScalarFunction,
.finalizeFunc = percentileFinalize, .finalizeFunc = percentileFinalize,
.invertFunc = NULL, .invertFunc = NULL,
.combineFunc = NULL, .combineFunc = NULL,
...@@ -2046,6 +2047,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { ...@@ -2046,6 +2047,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.getEnvFunc = getApercentileFuncEnv, .getEnvFunc = getApercentileFuncEnv,
.initFunc = apercentileFunctionSetup, .initFunc = apercentileFunctionSetup,
.processFunc = apercentileFunction, .processFunc = apercentileFunction,
.sprocessFunc = apercentileScalarFunction,
.finalizeFunc = apercentileFinalize, .finalizeFunc = apercentileFinalize,
.invertFunc = NULL, .invertFunc = NULL,
.combineFunc = apercentileCombine, .combineFunc = apercentileCombine,
...@@ -2113,6 +2115,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { ...@@ -2113,6 +2115,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.getEnvFunc = getSpreadFuncEnv, .getEnvFunc = getSpreadFuncEnv,
.initFunc = spreadFunctionSetup, .initFunc = spreadFunctionSetup,
.processFunc = spreadFunction, .processFunc = spreadFunction,
.sprocessFunc = spreadScalarFunction,
.finalizeFunc = spreadFinalize, .finalizeFunc = spreadFinalize,
.invertFunc = NULL, .invertFunc = NULL,
.combineFunc = spreadCombine, .combineFunc = spreadCombine,
......
...@@ -1167,7 +1167,11 @@ static int32_t translateRepeatScanFunc(STranslateContext* pCxt, SFunctionNode* p ...@@ -1167,7 +1167,11 @@ static int32_t translateRepeatScanFunc(STranslateContext* pCxt, SFunctionNode* p
if (!fmIsRepeatScanFunc(pFunc->funcId)) { if (!fmIsRepeatScanFunc(pFunc->funcId)) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (isSelectStmt(pCxt->pCurrStmt) && NULL != ((SSelectStmt*)pCxt->pCurrStmt)->pFromTable) { if (isSelectStmt(pCxt->pCurrStmt)) {
//select percentile() without from clause is also valid
if (NULL == ((SSelectStmt*)pCxt->pCurrStmt)->pFromTable) {
return TSDB_CODE_SUCCESS;
}
SNode* pTable = ((SSelectStmt*)pCxt->pCurrStmt)->pFromTable; SNode* pTable = ((SSelectStmt*)pCxt->pCurrStmt)->pFromTable;
if (QUERY_NODE_REAL_TABLE == nodeType(pTable) && if (QUERY_NODE_REAL_TABLE == nodeType(pTable) &&
(TSDB_CHILD_TABLE == ((SRealTableNode*)pTable)->pMeta->tableType || (TSDB_CHILD_TABLE == ((SRealTableNode*)pTable)->pMeta->tableType ||
......
...@@ -700,7 +700,7 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) { ...@@ -700,7 +700,7 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) {
EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
SFunctionNode *node = (SFunctionNode *)*pNode; SFunctionNode *node = (SFunctionNode *)*pNode;
SNode* tnode = NULL; SNode* tnode = NULL;
if (!fmIsScalarFunc(node->funcId)) { if (!fmIsScalarFunc(node->funcId) && (!ctx->dual)) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
......
...@@ -2307,3 +2307,76 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa ...@@ -2307,3 +2307,76 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
pOutput->numOfRows = 1; pOutput->numOfRows = 1;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t percentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput);
double val;
bool hasNull = false;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) {
hasNull = true;
break;
}
char *in = pInputData->pData;
GET_TYPED_DATA(val, double, type, in);
}
if (hasNull) {
colDataAppendNULL(pOutputData, 0);
} else {
colDataAppend(pOutputData, 0, (char *)&val, false);
}
pOutput->numOfRows = 1;
return TSDB_CODE_SUCCESS;
}
int32_t apercentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
return percentileScalarFunction(pInput, inputNum, pOutput);
}
int32_t spreadScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
SColumnInfoData *pInputData = pInput->columnData;
SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput);
double min, max;
SET_DOUBLE_VAL(&min, DBL_MAX);
SET_DOUBLE_VAL(&max, -DBL_MAX);
bool hasNull = false;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_s(pInputData, i)) {
hasNull = true;
break;
}
char *in = pInputData->pData;
double val = 0;
GET_TYPED_DATA(val, double, type, in);
if (val < GET_DOUBLE_VAL(&min)) {
SET_DOUBLE_VAL(&min, val);
}
if (val > GET_DOUBLE_VAL(&max)) {
SET_DOUBLE_VAL(&max, val);
}
}
if (hasNull) {
colDataAppendNULL(pOutputData, 0);
} else {
double result = max - min;
colDataAppend(pOutputData, 0, (char *)&result, false);
}
pOutput->numOfRows = 1;
return TSDB_CODE_SUCCESS;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册