functionMgt.h 7.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * 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 _TD_FUNCTION_MGT_H_
#define _TD_FUNCTION_MGT_H_

#ifdef __cplusplus
extern "C" {
#endif

D
dapan1121 已提交
23
#include "function.h"
24
#include "querynodes.h"
25

26 27 28
#define FUNC_AGGREGATE_UDF_ID 5001
#define FUNC_SCALAR_UDF_ID    5002

29 30 31 32 33 34 35 36 37 38 39 40 41 42
typedef enum EFunctionType {
  // aggregate function
  FUNCTION_TYPE_APERCENTILE = 1,
  FUNCTION_TYPE_AVG,
  FUNCTION_TYPE_COUNT,
  FUNCTION_TYPE_ELAPSED,
  FUNCTION_TYPE_IRATE,
  FUNCTION_TYPE_LAST_ROW,
  FUNCTION_TYPE_MAX,
  FUNCTION_TYPE_MIN,
  FUNCTION_TYPE_MODE,
  FUNCTION_TYPE_PERCENTILE,
  FUNCTION_TYPE_SPREAD,
  FUNCTION_TYPE_STDDEV,
43
  FUNCTION_TYPE_LEASTSQUARES,
44 45
  FUNCTION_TYPE_SUM,
  FUNCTION_TYPE_TWA,
G
Ganlin Zhao 已提交
46
  FUNCTION_TYPE_HISTOGRAM,
G
Ganlin Zhao 已提交
47
  FUNCTION_TYPE_HYPERLOGLOG,
48 49 50 51 52 53 54 55 56 57 58 59 60 61

  // nonstandard SQL function
  FUNCTION_TYPE_BOTTOM = 500,
  FUNCTION_TYPE_CSUM,
  FUNCTION_TYPE_DERIVATIVE,
  FUNCTION_TYPE_DIFF,
  FUNCTION_TYPE_FIRST,
  FUNCTION_TYPE_INTERP,
  FUNCTION_TYPE_LAST,
  FUNCTION_TYPE_MAVG,
  FUNCTION_TYPE_SAMPLE,
  FUNCTION_TYPE_TAIL,
  FUNCTION_TYPE_TOP,
  FUNCTION_TYPE_UNIQUE,
62 63
  FUNCTION_TYPE_STATE_COUNT,
  FUNCTION_TYPE_STATE_DURATION,
64 65 66 67 68

  // math function
  FUNCTION_TYPE_ABS = 1000,
  FUNCTION_TYPE_LOG,
  FUNCTION_TYPE_POW,
69 70 71
  FUNCTION_TYPE_SQRT,
  FUNCTION_TYPE_CEIL,
  FUNCTION_TYPE_FLOOR,
72
  FUNCTION_TYPE_ROUND,
73

74
  FUNCTION_TYPE_SIN,
75
  FUNCTION_TYPE_COS,
76
  FUNCTION_TYPE_TAN,
77 78 79
  FUNCTION_TYPE_ASIN,
  FUNCTION_TYPE_ACOS,
  FUNCTION_TYPE_ATAN,
80 81

  // string function
G
Ganlin Zhao 已提交
82 83
  FUNCTION_TYPE_LENGTH = 1500,
  FUNCTION_TYPE_CHAR_LENGTH,
84 85
  FUNCTION_TYPE_CONCAT,
  FUNCTION_TYPE_CONCAT_WS,
G
Ganlin Zhao 已提交
86 87 88 89 90
  FUNCTION_TYPE_LOWER,
  FUNCTION_TYPE_UPPER,
  FUNCTION_TYPE_LTRIM,
  FUNCTION_TYPE_RTRIM,
  FUNCTION_TYPE_SUBSTR,
91 92 93 94

  // conversion function
  FUNCTION_TYPE_CAST = 2000,
  FUNCTION_TYPE_TO_ISO8601,
95
  FUNCTION_TYPE_TO_UNIXTIMESTAMP,
96 97 98 99 100 101 102 103 104 105 106 107
  FUNCTION_TYPE_TO_JSON,

  // date and time function
  FUNCTION_TYPE_NOW = 2500,
  FUNCTION_TYPE_TIMEDIFF,
  FUNCTION_TYPE_TIMETRUNCATE,
  FUNCTION_TYPE_TIMEZONE,
  FUNCTION_TYPE_TODAY,

  // system function
  FUNCTION_TYPE_DATABASE = 3000,
  FUNCTION_TYPE_CLIENT_VERSION,
108
  FUNCTION_TYPE_SERVER_VERSION,
109 110
  FUNCTION_TYPE_SERVER_STATUS,
  FUNCTION_TYPE_CURRENT_USER,
111 112 113 114 115
  FUNCTION_TYPE_USER,

  // pseudo column function
  FUNCTION_TYPE_ROWTS = 3500,
  FUNCTION_TYPE_TBNAME,
116 117 118 119 120
  FUNCTION_TYPE_QSTART,
  FUNCTION_TYPE_QEND,
  FUNCTION_TYPE_QDURATION,
  FUNCTION_TYPE_WSTART,
  FUNCTION_TYPE_WEND,
121
  FUNCTION_TYPE_WDURATION,
122
  FUNCTION_TYPE_IROWTS,
123
  FUNCTION_TYPE_ISFILLED,
124
  FUNCTION_TYPE_TAGS,
125

126
  // internal function
127
  FUNCTION_TYPE_SELECT_VALUE = 3750,
128 129
  FUNCTION_TYPE_BLOCK_DIST,       // block distribution aggregate function
  FUNCTION_TYPE_BLOCK_DIST_INFO,  // block distribution pseudo column function
130
  FUNCTION_TYPE_TO_COLUMN,
131
  FUNCTION_TYPE_GROUP_KEY,
132
  FUNCTION_TYPE_CACHE_LAST_ROW,
X
Xiaoyu Wang 已提交
133
  FUNCTION_TYPE_CACHE_LAST,
134
  FUNCTION_TYPE_TABLE_COUNT,
135

136
  // distributed splitting functions
G
Ganlin Zhao 已提交
137
  FUNCTION_TYPE_APERCENTILE_PARTIAL = 4000,
138
  FUNCTION_TYPE_APERCENTILE_MERGE,
139 140
  FUNCTION_TYPE_SPREAD_PARTIAL,
  FUNCTION_TYPE_SPREAD_MERGE,
141 142
  FUNCTION_TYPE_HISTOGRAM_PARTIAL,
  FUNCTION_TYPE_HISTOGRAM_MERGE,
143 144
  FUNCTION_TYPE_HYPERLOGLOG_PARTIAL,
  FUNCTION_TYPE_HYPERLOGLOG_MERGE,
145 146
  FUNCTION_TYPE_ELAPSED_PARTIAL,
  FUNCTION_TYPE_ELAPSED_MERGE,
147

G
Ganlin Zhao 已提交
148 149
  FUNCTION_TYPE_TOP_PARTIAL,
  FUNCTION_TYPE_TOP_MERGE,
150 151
  FUNCTION_TYPE_BOTTOM_PARTIAL,
  FUNCTION_TYPE_BOTTOM_MERGE,
152 153
  FUNCTION_TYPE_FIRST_PARTIAL,
  FUNCTION_TYPE_FIRST_MERGE,
G
Ganlin Zhao 已提交
154 155
  FUNCTION_TYPE_LAST_PARTIAL,
  FUNCTION_TYPE_LAST_MERGE,
156 157
  FUNCTION_TYPE_AVG_PARTIAL,
  FUNCTION_TYPE_AVG_MERGE,
158 159
  FUNCTION_TYPE_STDDEV_PARTIAL,
  FUNCTION_TYPE_STDDEV_MERGE,
160

D
Dingle Zhang 已提交
161 162 163 164 165 166 167 168 169 170 171
  // geometry functions
  FUNCTION_TYPE_GEOM_FROM_TEXT = 4250,
  FUNCTION_TYPE_AS_TEXT,
  FUNCTION_TYPE_MAKE_POINT,
  FUNCTION_TYPE_INTERSECTS,
  FUNCTION_TYPE_EQUALS,
  FUNCTION_TYPE_TOUCHES,
  FUNCTION_TYPE_COVERS,
  FUNCTION_TYPE_CONTAINS,
  FUNCTION_TYPE_CONTAINS_PROPERLY,

172 173
  // user defined funcion
  FUNCTION_TYPE_UDF = 10000
174 175
} EFunctionType;

176 177 178 179 180 181 182
typedef enum EFuncReturnRows {
  FUNC_RETURN_ROWS_NORMAL = 1,
  FUNC_RETURN_ROWS_INDEFINITE,
  FUNC_RETURN_ROWS_N,
  FUNC_RETURN_ROWS_N_MINUS_1
} EFuncReturnRows;

H
Haojun Liao 已提交
183
struct SqlFunctionCtx;
184 185
struct SResultRowEntryInfo;
struct STimeWindow;
D
dapan1121 已提交
186

187 188
int32_t fmFuncMgtInit();

X
Xiaoyu Wang 已提交
189 190
void fmFuncMgtDestroy();

191
int32_t fmGetFuncInfo(SFunctionNode* pFunc, char* pMsg, int32_t msgLen);
192

193 194
EFuncReturnRows fmGetFuncReturnRows(SFunctionNode* pFunc);

X
Xiaoyu Wang 已提交
195 196
bool          fmIsBuiltinFunc(const char* pFunc);
EFunctionType fmGetFuncType(const char* pFunc);
197

198
bool fmIsAggFunc(int32_t funcId);
199
bool fmIsScalarFunc(int32_t funcId);
X
Xiaoyu Wang 已提交
200 201
bool fmIsVectorFunc(int32_t funcId);
bool fmIsIndefiniteRowsFunc(int32_t funcId);
202
bool fmIsStringFunc(int32_t funcId);
203
bool fmIsDateTimeFunc(int32_t funcId);
204
bool fmIsSelectFunc(int32_t funcId);
205 206
bool fmIsTimelineFunc(int32_t funcId);
bool fmIsTimeorderFunc(int32_t funcId);
X
Xiaoyu Wang 已提交
207
bool fmIsPseudoColumnFunc(int32_t funcId);
208
bool fmIsScanPseudoColumnFunc(int32_t funcId);
209 210
bool fmIsWindowPseudoColumnFunc(int32_t funcId);
bool fmIsWindowClauseFunc(int32_t funcId);
211 212
bool fmIsSpecialDataRequiredFunc(int32_t funcId);
bool fmIsDynamicScanOptimizedFunc(int32_t funcId);
213
bool fmIsMultiResFunc(int32_t funcId);
X
Xiaoyu Wang 已提交
214
bool fmIsRepeatScanFunc(int32_t funcId);
215
bool fmIsUserDefinedFunc(int32_t funcId);
X
Xiaoyu Wang 已提交
216
bool fmIsDistExecFunc(int32_t funcId);
X
Xiaoyu Wang 已提交
217
bool fmIsForbidFillFunc(int32_t funcId);
X
Xiaoyu Wang 已提交
218
bool fmIsForbidStreamFunc(int32_t funcId);
G
Ganlin Zhao 已提交
219
bool fmIsForbidSysTableFunc(int32_t funcId);
H
Haojun Liao 已提交
220
bool fmIsIntervalInterpoFunc(int32_t funcId);
X
Xiaoyu Wang 已提交
221
bool fmIsInterpFunc(int32_t funcId);
X
Xiaoyu Wang 已提交
222
bool fmIsLastRowFunc(int32_t funcId);
223
bool fmIsNotNullOutputFunc(int32_t funcId);
224
bool fmIsSelectValueFunc(int32_t funcId);
225
bool fmIsSystemInfoFunc(int32_t funcId);
226
bool fmIsImplicitTsFunc(int32_t funcId);
227
bool fmIsClientPseudoColumnFunc(int32_t funcId);
228
bool fmIsMultiRowsFunc(int32_t funcId);
229
bool fmIsKeepOrderFunc(int32_t funcId);
230
bool fmIsCumulativeFunc(int32_t funcId);
231
bool fmIsInterpPseudoColumnFunc(int32_t funcId);
X
Xiaoyu Wang 已提交
232
bool fmIsGroupKeyFunc(int32_t funcId);
233
bool fmIsBlockDistFunc(int32_t funcId);
X
Xiaoyu Wang 已提交
234

X
Xiaoyu Wang 已提交
235 236
void getLastCacheDataType(SDataType* pType);

X
Xiaoyu Wang 已提交
237
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMergeFunc);
238

239
typedef enum EFuncDataRequired {
240
  FUNC_DATA_REQUIRED_DATA_LOAD = 1,
H
Haojun Liao 已提交
241
  FUNC_DATA_REQUIRED_SMA_LOAD,
242 243
  FUNC_DATA_REQUIRED_NOT_LOAD,
  FUNC_DATA_REQUIRED_FILTEROUT,
244
  FUNC_DATA_REQUIRED_ALL_FILTEROUT,
245 246 247
} EFuncDataRequired;

EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
248
EFuncDataRequired fmFuncDynDataRequired(int32_t funcId, void* pRes, STimeWindow* pTimeWindow);
249

D
dapan1121 已提交
250 251
int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet);
int32_t fmGetScalarFuncExecFuncs(int32_t funcId, SScalarFuncExecFuncs* pFpSet);
252
int32_t fmGetUdafExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet);
5
54liuyao 已提交
253 254
int32_t fmSetInvertFunc(int32_t funcId, SFuncExecFuncs* pFpSet);
int32_t fmSetNormalFunc(int32_t funcId, SFuncExecFuncs* pFpSet);
X
Xiaoyu Wang 已提交
255
bool    fmIsInvertible(int32_t funcId);
5
54liuyao 已提交
256
char*   fmGetFuncName(int32_t funcId);
257 258 259 260 261 262

#ifdef __cplusplus
}
#endif

#endif  // _TD_FUNCTION_MGT_H_