functionMgt.h 4.6 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 29 30 31 32 33 34 35 36 37 38 39
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,
40
  FUNCTION_TYPE_LEASTSQUARES,
41 42
  FUNCTION_TYPE_SUM,
  FUNCTION_TYPE_TWA,
G
Ganlin Zhao 已提交
43
  FUNCTION_TYPE_HISTOGRAM,
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

  // 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,

  // math function
  FUNCTION_TYPE_ABS = 1000,
  FUNCTION_TYPE_LOG,
  FUNCTION_TYPE_POW,
63 64 65
  FUNCTION_TYPE_SQRT,
  FUNCTION_TYPE_CEIL,
  FUNCTION_TYPE_FLOOR,
66
  FUNCTION_TYPE_ROUND,
67

68
  FUNCTION_TYPE_SIN,
69
  FUNCTION_TYPE_COS,
70
  FUNCTION_TYPE_TAN,
71 72 73
  FUNCTION_TYPE_ASIN,
  FUNCTION_TYPE_ACOS,
  FUNCTION_TYPE_ATAN,
74 75

  // string function
G
Ganlin Zhao 已提交
76 77
  FUNCTION_TYPE_LENGTH = 1500,
  FUNCTION_TYPE_CHAR_LENGTH,
78 79
  FUNCTION_TYPE_CONCAT,
  FUNCTION_TYPE_CONCAT_WS,
G
Ganlin Zhao 已提交
80 81 82 83 84
  FUNCTION_TYPE_LOWER,
  FUNCTION_TYPE_UPPER,
  FUNCTION_TYPE_LTRIM,
  FUNCTION_TYPE_RTRIM,
  FUNCTION_TYPE_SUBSTR,
85 86 87 88

  // conversion function
  FUNCTION_TYPE_CAST = 2000,
  FUNCTION_TYPE_TO_ISO8601,
89
  FUNCTION_TYPE_TO_UNIXTIMESTAMP,
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
  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,
  FUNCTION_TYPE_SERVER_SERSION,
  FUNCTION_TYPE_SERVER_STATUS,
  FUNCTION_TYPE_CURRENT_USER,
105 106 107 108 109 110 111 112 113
  FUNCTION_TYPE_USER,

  // pseudo column function
  FUNCTION_TYPE_ROWTS = 3500,
  FUNCTION_TYPE_TBNAME,
  FUNCTION_TYPE_QSTARTTS,
  FUNCTION_TYPE_QENDTS,
  FUNCTION_TYPE_WSTARTTS,
  FUNCTION_TYPE_WENDTS,
114 115
  FUNCTION_TYPE_WDURATION,

116 117 118
  // internal function
  FUNCTION_TYPE_SELECT_VALUE,

119 120
  // user defined funcion
  FUNCTION_TYPE_UDF = 10000
121 122
} EFunctionType;

H
Haojun Liao 已提交
123
struct SqlFunctionCtx;
124 125
struct SResultRowEntryInfo;
struct STimeWindow;
D
dapan1121 已提交
126
struct SCatalog;
127

D
dapan1121 已提交
128
typedef struct SFmGetFuncInfoParam {
D
dapan1121 已提交
129
  struct SCatalog* pCtg;
130 131 132 133
  void*            pRpc;
  const SEpSet*    pMgmtEps;
  char*            pErrBuf;
  int32_t          errBufLen;
D
dapan1121 已提交
134 135
} SFmGetFuncInfoParam;

136 137
int32_t fmFuncMgtInit();

X
Xiaoyu Wang 已提交
138 139
void fmFuncMgtDestroy();

140
int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, SFunctionNode* pFunc);
141

142
bool fmIsAggFunc(int32_t funcId);
143 144
bool fmIsScalarFunc(int32_t funcId);
bool fmIsNonstandardSQLFunc(int32_t funcId);
145
bool fmIsStringFunc(int32_t funcId);
146
bool fmIsDatetimeFunc(int32_t funcId);
147
bool fmIsSelectFunc(int32_t funcId);
148 149
bool fmIsTimelineFunc(int32_t funcId);
bool fmIsTimeorderFunc(int32_t funcId);
X
Xiaoyu Wang 已提交
150
bool fmIsPseudoColumnFunc(int32_t funcId);
151
bool fmIsScanPseudoColumnFunc(int32_t funcId);
152 153
bool fmIsWindowPseudoColumnFunc(int32_t funcId);
bool fmIsWindowClauseFunc(int32_t funcId);
154 155
bool fmIsSpecialDataRequiredFunc(int32_t funcId);
bool fmIsDynamicScanOptimizedFunc(int32_t funcId);
156
bool fmIsMultiResFunc(int32_t funcId);
157
bool fmIsUserDefinedFunc(int32_t funcId);
158

159
typedef enum EFuncDataRequired {
160 161 162 163
  FUNC_DATA_REQUIRED_DATA_LOAD = 1,
  FUNC_DATA_REQUIRED_STATIS_LOAD,
  FUNC_DATA_REQUIRED_NOT_LOAD,
  FUNC_DATA_REQUIRED_FILTEROUT,
164 165 166
} EFuncDataRequired;

EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
167

D
dapan1121 已提交
168 169
int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet);
int32_t fmGetScalarFuncExecFuncs(int32_t funcId, SScalarFuncExecFuncs* pFpSet);
170
int32_t fmGetUdafExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet);
5
54liuyao 已提交
171 172 173
int32_t fmSetInvertFunc(int32_t funcId, SFuncExecFuncs* pFpSet);
int32_t fmSetNormalFunc(int32_t funcId, SFuncExecFuncs* pFpSet);
bool fmIsInvertible(int32_t funcId);
174 175 176 177 178 179

#ifdef __cplusplus
}
#endif

#endif  // _TD_FUNCTION_MGT_H_