parAst.h 14.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

16 17
#ifndef _TD_AST_CREATE_FUNCS_H_
#define _TD_AST_CREATE_FUNCS_H_
18

19 20 21 22
#ifdef __cplusplus
extern "C" {
#endif

23
#include "cmdnodes.h"
X
Xiaoyu Wang 已提交
24 25
#include "parToken.h"
#include "parUtil.h"
X
Xiaoyu Wang 已提交
26
#include "parser.h"
X
Xiaoyu Wang 已提交
27
#include "querynodes.h"
28

X
Xiaoyu Wang 已提交
29 30
typedef struct SAstCreateContext {
  SParseContext* pQueryCxt;
X
Xiaoyu Wang 已提交
31 32 33 34
  SMsgBuf        msgBuf;
  bool           notSupport;
  SNode*         pRootNode;
  int16_t        placeholderNo;
X
Xiaoyu Wang 已提交
35
  SArray*        pPlaceholderValues;
36
  int32_t        errCode;
X
Xiaoyu Wang 已提交
37 38
} SAstCreateContext;

39
typedef enum EDatabaseOptionType {
X
Xiaoyu Wang 已提交
40
  DB_OPTION_BUFFER = 1,
41 42
  DB_OPTION_CACHEMODEL,
  DB_OPTION_CACHESIZE,
43 44 45 46 47 48
  DB_OPTION_COMP,
  DB_OPTION_DAYS,
  DB_OPTION_FSYNC,
  DB_OPTION_MAXROWS,
  DB_OPTION_MINROWS,
  DB_OPTION_KEEP,
X
Xiaoyu Wang 已提交
49 50
  DB_OPTION_PAGES,
  DB_OPTION_PAGESIZE,
51
  DB_OPTION_TSDB_PAGESIZE,
52 53
  DB_OPTION_PRECISION,
  DB_OPTION_REPLICA,
X
Xiaoyu Wang 已提交
54
  DB_OPTION_STRICT,
55 56
  DB_OPTION_WAL,
  DB_OPTION_VGROUPS,
57
  DB_OPTION_SINGLE_STABLE,
X
Xiaoyu Wang 已提交
58
  DB_OPTION_RETENTIONS,
X
Xiaoyu Wang 已提交
59 60 61 62
  DB_OPTION_SCHEMALESS,
  DB_OPTION_WAL_RETENTION_PERIOD,
  DB_OPTION_WAL_RETENTION_SIZE,
  DB_OPTION_WAL_ROLL_PERIOD,
63
  DB_OPTION_WAL_SEGMENT_SIZE,
64
  DB_OPTION_STT_TRIGGER,
65 66
  DB_OPTION_TABLE_PREFIX,
  DB_OPTION_TABLE_SUFFIX
67 68 69
} EDatabaseOptionType;

typedef enum ETableOptionType {
X
Xiaoyu Wang 已提交
70
  TABLE_OPTION_COMMENT = 1,
X
Xiaoyu Wang 已提交
71 72
  TABLE_OPTION_MAXDELAY,
  TABLE_OPTION_WATERMARK,
X
Xiaoyu Wang 已提交
73 74
  TABLE_OPTION_ROLLUP,
  TABLE_OPTION_TTL,
75 76
  TABLE_OPTION_SMA,
  TABLE_OPTION_DELETE_MARK
77
} ETableOptionType;
X
Xiaoyu Wang 已提交
78

79
typedef struct SAlterOption {
X
Xiaoyu Wang 已提交
80 81 82
  int32_t    type;
  SToken     val;
  SNodeList* pList;
83 84
} SAlterOption;

85 86
extern SToken nil_token;

87 88
void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt);

89 90 91 92
SNode* createRawExprNode(SAstCreateContext* pCxt, const SToken* pToken, SNode* pNode);
SNode* createRawExprNodeExt(SAstCreateContext* pCxt, const SToken* pStart, const SToken* pEnd, SNode* pNode);
SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode);
SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode);
93

94
SNodeList* createNodeList(SAstCreateContext* pCxt, SNode* pNode);
95
SNodeList* addNodeToList(SAstCreateContext* pCxt, SNodeList* pList, SNode* pNode);
96

X
Xiaoyu Wang 已提交
97
SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pColumnName);
98
SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral);
X
Xiaoyu Wang 已提交
99
SNode* createIdentifierValueNode(SAstCreateContext* pCxt, SToken* pLiteral);
100
SNode* createDurationValueNode(SAstCreateContext* pCxt, const SToken* pLiteral);
X
Xiaoyu Wang 已提交
101
SNode* createDefaultDatabaseCondValue(SAstCreateContext* pCxt);
102
SNode* createPlaceholderValueNode(SAstCreateContext* pCxt, const SToken* pLiteral);
X
Xiaoyu Wang 已提交
103
SNode* setProjectionAlias(SAstCreateContext* pCxt, SNode* pNode, SToken* pAlias);
104
SNode* createLogicConditionNode(SAstCreateContext* pCxt, ELogicConditionType type, SNode* pParam1, SNode* pParam2);
105 106 107 108
SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pLeft, SNode* pRight);
SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight);
SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight);
SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList);
109
SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType dt);
110
SNode* createNodeListNode(SAstCreateContext* pCxt, SNodeList* pList);
X
Xiaoyu Wang 已提交
111
SNode* createNodeListNodeEx(SAstCreateContext* pCxt, SNode* p1, SNode* p2);
X
Xiaoyu Wang 已提交
112
SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTableName, SToken* pTableAlias);
113 114
SNode* createTempTableNode(SAstCreateContext* pCxt, SNode* pSubquery, const SToken* pTableAlias);
SNode* createJoinTableNode(SAstCreateContext* pCxt, EJoinType type, SNode* pLeft, SNode* pRight, SNode* pJoinCond);
115
SNode* createLimitNode(SAstCreateContext* pCxt, const SToken* pLimit, const SToken* pOffset);
116
SNode* createOrderByExprNode(SAstCreateContext* pCxt, SNode* pExpr, EOrder order, ENullOrder nullOrder);
X
Xiaoyu Wang 已提交
117
SNode* createSessionWindowNode(SAstCreateContext* pCxt, SNode* pCol, SNode* pGap);
118
SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr);
X
Xiaoyu Wang 已提交
119
SNode* createEventWindowNode(SAstCreateContext* pCxt, SNode* pStartCond, SNode* pEndCond);
X
Xiaoyu Wang 已提交
120 121
SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding,
                                SNode* pFill);
122
SNode* createFillNode(SAstCreateContext* pCxt, EFillMode mode, SNode* pValues);
123
SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode);
X
Xiaoyu Wang 已提交
124
SNode* createInterpTimeRange(SAstCreateContext* pCxt, SNode* pStart, SNode* pEnd);
X
Xiaoyu Wang 已提交
125 126
SNode* createWhenThenNode(SAstCreateContext* pCxt, SNode* pWhen, SNode* pThen);
SNode* createCaseWhenNode(SAstCreateContext* pCxt, SNode* pCase, SNodeList* pWhenThenList, SNode* pElse);
127 128 129 130 131 132 133 134 135

SNode* addWhereClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pWhere);
SNode* addPartitionByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pPartitionByList);
SNode* addWindowClauseClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pWindow);
SNode* addGroupByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pGroupByList);
SNode* addHavingClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pHaving);
SNode* addOrderByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pOrderByList);
SNode* addSlimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pSlimit);
SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit);
X
Xiaoyu Wang 已提交
136 137 138
SNode* addRangeClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pRange);
SNode* addEveryClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pEvery);
SNode* addFillClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pFill);
139 140
SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable);
SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight);
141

142 143
SDataType createDataType(uint8_t type);
SDataType createVarLenDataType(uint8_t type, const SToken* pLen);
X
Xiaoyu Wang 已提交
144 145 146 147 148 149 150 151

SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt);
SNode* createAlterDatabaseOptions(SAstCreateContext* pCxt);
SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOptionType type, void* pVal);
SNode* setAlterDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption);
SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pDbName, SNode* pOptions);
SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pDbName);
SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* pOptions);
X
Xiaoyu Wang 已提交
152
SNode* createFlushDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName);
153
SNode* createTrimDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, int32_t maxSpeed);
X
Xiaoyu Wang 已提交
154
SNode* createCompactStmt(SAstCreateContext* pCxt, SToken* pDbName);
X
Xiaoyu Wang 已提交
155 156 157 158 159 160
SNode* createDefaultTableOptions(SAstCreateContext* pCxt);
SNode* createAlterTableOptions(SAstCreateContext* pCxt);
SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, void* pVal);
SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType dataType, const SToken* pComment);
SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols,
                             SNodeList* pTags, SNode* pOptions);
X
Xiaoyu Wang 已提交
161
SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable,
X
Xiaoyu Wang 已提交
162
                                  SNodeList* pSpecificTags, SNodeList* pValsOfTags, SNode* pOptions);
163
SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables);
164 165
SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables);
166
SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
X
Xiaoyu Wang 已提交
167
SNode* createAlterTableModifyOptions(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions);
X
Xiaoyu Wang 已提交
168 169 170 171 172 173
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pColName,
                                    SDataType dataType);
SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pColName);
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pOldColName,
                                 SToken* pNewColName);
SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, SToken* pTagName, SNode* pVal);
174
SNode* setAlterSuperTableType(SNode* pStmt);
175
SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName);
176 177 178
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type);
SNode* createShowStmtWithCond(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbName,
                              EOperatorType tableCondType);
179
SNode* createShowCreateDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName);
180
SNode* createShowAliveStmt(SAstCreateContext* pCxt, SNode* pDbName, ENodeType type);
181
SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable);
182
SNode* createShowTableDistributedStmt(SAstCreateContext* pCxt, SNode* pRealTable);
183
SNode* createShowDnodeVariablesStmt(SAstCreateContext* pCxt, SNode* pDnodeId, SNode* pLikePattern);
184
SNode* createShowVnodesStmt(SAstCreateContext* pCxt, SNode* pDnodeId, SNode* pDnodeEndpoint);
185
SNode* createShowTableTagsStmt(SAstCreateContext* pCxt, SNode* pTbName, SNode* pDbName, SNodeList* pTags);
X
Xiaoyu Wang 已提交
186
SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword, int8_t sysinfo);
X
Xiaoyu Wang 已提交
187 188
SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t alterType, const SToken* pVal);
SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName);
189
SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort);
190
SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, bool force);
191
SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig, const SToken* pValue);
192
SNode* createRealTableNodeForIndexName(SAstCreateContext* pCxt, SToken* pDbName, SToken* pIndexName);
X
Xiaoyu Wang 已提交
193
SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SNode* pIndexName,
194
                             SNode* pRealTable, SNodeList* pCols, SNode* pOptions);
195 196
SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding,
                         SNode* pStreamOptions);
X
Xiaoyu Wang 已提交
197
SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pIndexName);
198 199
SNode* createCreateComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId);
SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId);
200 201 202 203 204 205 206
SNode* createCreateTopicStmtUseQuery(SAstCreateContext* pCxt, bool ignoreExists, SToken* pTopicName, SNode* pQuery);
SNode* createCreateTopicStmtUseDb(SAstCreateContext* pCxt, bool ignoreExists, SToken* pTopicName, SToken* pSubDbName,
                                  bool withMeta);
SNode* createCreateTopicStmtUseTable(SAstCreateContext* pCxt, bool ignoreExists, SToken* pTopicName, SNode* pRealTable,
                                     bool withMeta);
SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pTopicName);
SNode* createDropCGroupStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pCGroupId, SToken* pTopicName);
207
SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, const SToken* pValue);
208 209 210 211
SNode* createDefaultExplainOptions(SAstCreateContext* pCxt);
SNode* setExplainVerbose(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal);
SNode* setExplainRatio(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal);
SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions, SNode* pQuery);
212 213
SNode* createDescribeStmt(SAstCreateContext* pCxt, SNode* pRealTable);
SNode* createResetQueryCacheStmt(SAstCreateContext* pCxt);
X
Xiaoyu Wang 已提交
214
SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName,
215
                                const SToken* pLibPath, SDataType dataType, int32_t bufSize, const SToken* pLanguage);
216
SNode* createDropFunctionStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pFuncName);
217
SNode* createStreamOptions(SAstCreateContext* pCxt);
218
SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pStreamName, SNode* pRealTable,
219
                              SNode* pOptions, SNodeList* pTags, SNode* pSubtable, SNode* pQuery, SNodeList* pCols);
220
SNode* createDropStreamStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pStreamName);
221
SNode* createKillStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pId);
X
Xiaoyu Wang 已提交
222
SNode* createKillQueryStmt(SAstCreateContext* pCxt, const SToken* pQueryId);
X
Xiaoyu Wang 已提交
223
SNode* createBalanceVgroupStmt(SAstCreateContext* pCxt);
224 225 226 227
SNode* createMergeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId1, const SToken* pVgId2);
SNode* createRedistributeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId, SNodeList* pDnodes);
SNode* createSplitVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId);
SNode* createSyncdbStmt(SAstCreateContext* pCxt, const SToken* pDbName);
228 229
SNode* createGrantStmt(SAstCreateContext* pCxt, int64_t privileges, SToken* pDbName, SToken* pUserName);
SNode* createRevokeStmt(SAstCreateContext* pCxt, int64_t privileges, SToken* pDbName, SToken* pUserName);
X
Xiaoyu Wang 已提交
230
SNode* createDeleteStmt(SAstCreateContext* pCxt, SNode* pTable, SNode* pWhere);
231
SNode* createInsertStmt(SAstCreateContext* pCxt, SNode* pTable, SNodeList* pCols, SNode* pQuery);
232

233 234 235 236 237
#ifdef __cplusplus
}
#endif

#endif /*_TD_AST_CREATE_FUNCS_H_*/