提交 cbd2d8f8 编写于 作者: G Ganlin Zhao

fix(query): add spread function scalar version

TD-17344
上级 a5a3b96e
...@@ -106,6 +106,7 @@ int32_t stddevScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara ...@@ -106,6 +106,7 @@ int32_t stddevScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
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 percentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
int32_t apercentileScalarFunction(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
} }
......
...@@ -2115,6 +2115,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { ...@@ -2115,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,
......
...@@ -2338,3 +2338,45 @@ int32_t percentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalar ...@@ -2338,3 +2338,45 @@ int32_t percentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalar
int32_t apercentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t apercentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
return percentileScalarFunction(pInput, inputNum, 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.
先完成此消息的编辑!
想要评论请 注册