diff --git a/include/libs/scalar/scalar.h b/include/libs/scalar/scalar.h index d5e9a2e625380bf58cfbdd54db41d5c826dd168b..df3e27225f5fd4827ea93293fb17e1fe7590c204 100644 --- a/include/libs/scalar/scalar.h +++ b/include/libs/scalar/scalar.h @@ -104,6 +104,8 @@ int32_t maxScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam * int32_t avgScalarFunction(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 percentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +int32_t apercentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); #ifdef __cplusplus } diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 6fb808a2e8bdd2b613e92a38c7cb59de263831db..e274146d25369c5dfece1a2481495002c6002c65 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -2034,6 +2034,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .getEnvFunc = getPercentileFuncEnv, .initFunc = percentileFunctionSetup, .processFunc = percentileFunction, + .sprocessFunc = percentileScalarFunction, .finalizeFunc = percentileFinalize, .invertFunc = NULL, .combineFunc = NULL, @@ -2046,6 +2047,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .getEnvFunc = getApercentileFuncEnv, .initFunc = apercentileFunctionSetup, .processFunc = apercentileFunction, + .sprocessFunc = apercentileScalarFunction, .finalizeFunc = apercentileFinalize, .invertFunc = NULL, .combineFunc = apercentileCombine, diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index ba35356a9c8e6cf115ad1df1684caace1741c8dd..8808d17454217c15ff99d5dfabf7f6cd6607a602 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -2307,3 +2307,34 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa pOutput->numOfRows = 1; 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); +}