TDengine/source/libs/function/inc/builtinsimpl.h

264 lines
12 KiB
C
Raw Normal View History

2022-03-09 02:22:53 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_BUILTINSIMPL_H
#define TDENGINE_BUILTINSIMPL_H
#ifdef __cplusplus
extern "C" {
#endif
#include "function.h"
#include "functionMgt.h"
2022-03-09 02:22:53 +00:00
2022-11-10 07:37:18 +00:00
typedef struct SSumRes {
union {
int64_t isum;
uint64_t usum;
double dsum;
};
int16_t type;
2022-11-24 09:24:24 +00:00
int64_t prevTs;
bool isPrevTsSet;
2022-12-29 03:35:46 +00:00
bool overflow; // if overflow is true, dsum to be used for any type;
2022-11-10 07:37:18 +00:00
} SSumRes;
2022-11-10 10:58:10 +00:00
typedef struct SMinmaxResInfo {
bool assign; // assign the first value or not
int64_t v;
STuplePos tuplePos;
STuplePos nullTuplePos;
bool nullTupleSaved;
int16_t type;
} SMinmaxResInfo;
2023-01-04 08:59:55 +00:00
int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc, int32_t* nElems);
int32_t saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos);
2022-11-10 10:58:10 +00:00
int32_t updateTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos);
int32_t loadTupleData(SqlFunctionCtx* pCtx, const STuplePos* pPos, char** value);
2022-11-10 10:58:10 +00:00
int32_t functionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
int32_t functionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
int32_t functionFinalizeWithResultBuf(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, char* finalResult);
2022-05-20 11:34:39 +00:00
int32_t combineFunction(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
2022-03-09 02:22:53 +00:00
EFuncDataRequired countDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
2022-10-13 06:15:42 +00:00
bool getCountFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t countFunction(SqlFunctionCtx* pCtx);
2024-01-12 05:49:32 +00:00
#ifdef BUILD_NO_CALL
2022-10-13 06:15:42 +00:00
int32_t countInvertFunction(SqlFunctionCtx* pCtx);
2024-01-12 05:49:32 +00:00
#endif
2022-03-09 02:22:53 +00:00
EFuncDataRequired statisDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
2022-10-13 06:15:42 +00:00
bool getSumFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t sumFunction(SqlFunctionCtx* pCtx);
2024-01-12 05:49:32 +00:00
#ifdef BUILD_NO_CALL
2022-10-13 06:15:42 +00:00
int32_t sumInvertFunction(SqlFunctionCtx* pCtx);
2024-01-12 05:49:32 +00:00
#endif
2022-10-13 06:15:42 +00:00
int32_t sumCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
2022-03-09 02:22:53 +00:00
int32_t minmaxFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
2022-10-13 06:15:42 +00:00
bool getMinmaxFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
2022-04-04 06:54:39 +00:00
int32_t minFunction(SqlFunctionCtx* pCtx);
2022-10-13 06:15:42 +00:00
int32_t maxFunction(SqlFunctionCtx* pCtx);
int32_t minmaxFunctionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
2022-05-20 11:34:39 +00:00
int32_t minCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
int32_t maxCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
2022-10-13 06:15:42 +00:00
bool getAvgFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t avgFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
2022-04-22 08:56:04 +00:00
int32_t avgFunction(SqlFunctionCtx* pCtx);
2022-06-14 07:15:37 +00:00
int32_t avgFunctionMerge(SqlFunctionCtx* pCtx);
2022-04-25 01:44:39 +00:00
int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
2022-06-14 07:15:37 +00:00
int32_t avgPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
2024-01-12 05:49:32 +00:00
#ifdef BUILD_NO_CALL
2022-05-05 11:50:11 +00:00
int32_t avgInvertFunction(SqlFunctionCtx* pCtx);
2024-01-12 05:49:32 +00:00
#endif
2022-05-20 11:34:39 +00:00
int32_t avgCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
int32_t getAvgInfoSize();
2022-04-22 08:56:04 +00:00
2022-10-13 06:15:42 +00:00
bool getStddevFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t stddevFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
2022-04-04 06:54:39 +00:00
int32_t stddevFunction(SqlFunctionCtx* pCtx);
2022-06-14 09:00:32 +00:00
int32_t stddevFunctionMerge(SqlFunctionCtx* pCtx);
int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
2022-06-14 09:00:32 +00:00
int32_t stddevPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
2024-01-12 05:49:32 +00:00
#ifdef BUILD_NO_CALL
2022-05-05 11:50:11 +00:00
int32_t stddevInvertFunction(SqlFunctionCtx* pCtx);
2024-01-12 05:49:32 +00:00
#endif
2022-05-20 11:34:39 +00:00
int32_t stddevCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
int32_t getStddevInfoSize();
2022-03-21 07:25:13 +00:00
2022-10-13 06:15:42 +00:00
bool getLeastSQRFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t leastSQRFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
2022-05-09 11:37:16 +00:00
int32_t leastSQRFunction(SqlFunctionCtx* pCtx);
int32_t leastSQRFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
2022-06-06 05:23:04 +00:00
int32_t leastSQRCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
2022-05-09 11:37:16 +00:00
2022-10-13 06:15:42 +00:00
bool getPercentileFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t percentileFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
2022-10-13 06:15:42 +00:00
int32_t percentileFunction(SqlFunctionCtx* pCtx);
int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
2022-04-02 08:59:02 +00:00
2022-10-13 06:15:42 +00:00
bool getApercentileFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t apercentileFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
2022-10-13 06:15:42 +00:00
int32_t apercentileFunction(SqlFunctionCtx* pCtx);
2022-06-07 08:54:08 +00:00
int32_t apercentileFunctionMerge(SqlFunctionCtx* pCtx);
2022-05-23 14:48:15 +00:00
int32_t apercentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
int32_t apercentilePartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
int32_t apercentileCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
int32_t getApercentileMaxSize();
2022-05-23 14:48:15 +00:00
2022-10-13 06:15:42 +00:00
bool getDiffFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t diffFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo);
2022-10-13 06:15:42 +00:00
int32_t diffFunction(SqlFunctionCtx* pCtx);
2024-07-04 03:04:59 +00:00
int32_t diffFunctionByRow(SArray* pCtx);
2022-03-11 06:11:34 +00:00
2022-10-13 06:15:42 +00:00
bool getDerivativeFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t derivativeFuncSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo);
2022-10-13 06:15:42 +00:00
int32_t derivativeFunction(SqlFunctionCtx* pCtx);
2022-06-13 11:22:28 +00:00
2022-10-13 06:15:42 +00:00
bool getIrateFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t irateFuncSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo);
2022-10-13 06:15:42 +00:00
int32_t irateFunction(SqlFunctionCtx* pCtx);
2023-08-15 04:59:30 +00:00
int32_t irateFunctionMerge(SqlFunctionCtx* pCtx);
2022-06-22 06:42:05 +00:00
int32_t irateFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
2023-08-15 04:59:30 +00:00
int32_t iratePartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
2024-03-26 01:18:45 +00:00
int32_t getIrateInfoSize(int32_t pkBytes);
2022-06-22 06:42:05 +00:00
2022-07-15 09:34:54 +00:00
int32_t cachedLastRowFunction(SqlFunctionCtx* pCtx);
2022-10-13 06:15:42 +00:00
bool getFirstLastFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t firstFunction(SqlFunctionCtx* pCtx);
int32_t firstFunctionMerge(SqlFunctionCtx* pCtx);
int32_t lastFunction(SqlFunctionCtx* pCtx);
int32_t lastFunctionMerge(SqlFunctionCtx* pCtx);
int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
int32_t firstLastPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
int32_t firstCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
int32_t lastCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
2024-03-15 10:34:41 +00:00
int32_t getFirstLastInfoSize(int32_t resBytes, int32_t pkBytes);
EFuncDataRequired firstDynDataReq(void* pRes, SDataBlockInfo* pBlockInfo);
EFuncDataRequired lastDynDataReq(void* pRes, SDataBlockInfo* pBlockInfo);
2022-03-22 10:17:04 +00:00
2022-10-13 06:15:42 +00:00
int32_t lastRowFunction(SqlFunctionCtx* pCtx);
2022-10-13 06:15:42 +00:00
bool getTopBotFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv);
int32_t topBotFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
2022-10-13 06:15:42 +00:00
int32_t topFunction(SqlFunctionCtx* pCtx);
int32_t bottomFunction(SqlFunctionCtx* pCtx);
int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
int32_t topCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
int32_t bottomCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
2022-06-11 07:44:55 +00:00
int32_t getTopBotInfoSize(int64_t numOfItems);
2022-10-13 06:15:42 +00:00
bool getSpreadFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t spreadFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
int32_t spreadFunction(SqlFunctionCtx* pCtx);
2022-06-08 07:45:32 +00:00
int32_t spreadFunctionMerge(SqlFunctionCtx* pCtx);
int32_t spreadFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
2022-06-08 07:45:32 +00:00
int32_t spreadPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
int32_t getSpreadInfoSize();
int32_t spreadCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
2022-10-13 06:15:42 +00:00
bool getElapsedFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t elapsedFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
2022-05-17 13:22:21 +00:00
int32_t elapsedFunction(SqlFunctionCtx* pCtx);
int32_t elapsedFunctionMerge(SqlFunctionCtx* pCtx);
2022-05-17 13:22:21 +00:00
int32_t elapsedFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
int32_t elapsedPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
int32_t getElapsedInfoSize();
int32_t elapsedCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
2022-05-17 13:22:21 +00:00
2022-10-13 06:15:42 +00:00
bool getHistogramFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t histogramFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
2022-05-06 07:51:18 +00:00
int32_t histogramFunction(SqlFunctionCtx* pCtx);
int32_t histogramFunctionPartial(SqlFunctionCtx* pCtx);
2022-06-08 10:40:16 +00:00
int32_t histogramFunctionMerge(SqlFunctionCtx* pCtx);
2022-05-06 07:51:18 +00:00
int32_t histogramFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
2022-06-08 10:40:16 +00:00
int32_t histogramPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
int32_t getHistogramInfoSize();
int32_t histogramCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
2022-05-06 07:51:18 +00:00
2022-10-13 06:15:42 +00:00
bool getHLLFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
2022-05-17 02:34:59 +00:00
int32_t hllFunction(SqlFunctionCtx* pCtx);
2022-06-09 05:31:33 +00:00
int32_t hllFunctionMerge(SqlFunctionCtx* pCtx);
2022-05-17 02:34:59 +00:00
int32_t hllFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
2022-06-09 05:31:33 +00:00
int32_t hllPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
int32_t getHLLInfoSize();
int32_t hllCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
2022-05-17 02:34:59 +00:00
2022-10-13 06:15:42 +00:00
bool getStateFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t stateFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
2022-05-10 12:32:03 +00:00
int32_t stateCountFunction(SqlFunctionCtx* pCtx);
int32_t stateDurationFunction(SqlFunctionCtx* pCtx);
2022-05-10 12:32:03 +00:00
2022-10-13 06:15:42 +00:00
bool getCsumFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
2022-05-12 06:38:56 +00:00
int32_t csumFunction(SqlFunctionCtx* pCtx);
2022-10-13 06:15:42 +00:00
bool getMavgFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t mavgFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
2022-05-12 12:40:17 +00:00
int32_t mavgFunction(SqlFunctionCtx* pCtx);
2022-10-13 06:15:42 +00:00
bool getSampleFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t sampleFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
2022-05-13 13:13:35 +00:00
int32_t sampleFunction(SqlFunctionCtx* pCtx);
int32_t sampleFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
2022-05-16 03:03:15 +00:00
2022-10-13 06:15:42 +00:00
bool getTailFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t tailFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
2022-05-16 03:03:15 +00:00
int32_t tailFunction(SqlFunctionCtx* pCtx);
2022-10-13 06:15:42 +00:00
bool getUniqueFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t uniqueFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
2022-10-13 06:15:42 +00:00
int32_t uniqueFunction(SqlFunctionCtx* pCtx);
2022-10-13 06:15:42 +00:00
bool getModeFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t modeFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
2022-10-13 06:15:42 +00:00
int32_t modeFunction(SqlFunctionCtx* pCtx);
2022-06-27 07:08:13 +00:00
int32_t modeFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
2022-10-13 06:15:42 +00:00
bool getTwaFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t twaFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
2022-10-13 06:15:42 +00:00
int32_t twaFunction(SqlFunctionCtx* pCtx);
int32_t twaFinalize(struct SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
2022-05-13 13:13:35 +00:00
bool getSelectivityFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t blockDistSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
2022-10-13 06:15:42 +00:00
int32_t blockDistFunction(SqlFunctionCtx* pCtx);
int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
2022-10-13 06:15:42 +00:00
bool getGroupKeyFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t groupKeyFunction(SqlFunctionCtx* pCtx);
2022-06-24 12:26:46 +00:00
int32_t groupKeyFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
2023-03-23 03:18:14 +00:00
int32_t groupKeyCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
2024-07-22 03:19:11 +00:00
int32_t groupConstValueFunction(SqlFunctionCtx* pCtx);
int32_t groupConstValueFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
2022-03-09 02:22:53 +00:00
#ifdef __cplusplus
}
#endif
#endif // TDENGINE_BUILTINSIMPL_H