parent
a5a3b96e58
commit
cbd2d8f8a2
|
@ -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[] = {
|
||||||
.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
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue