1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shardingsphere.sql.parser.opengauss.visitor.statement.type;
19
20 import org.apache.shardingsphere.sql.parser.api.ASTNode;
21 import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DDLStatementVisitor;
22 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AbsoluteCountContext;
23 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AddColumnSpecificationContext;
24 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AddConstraintSpecificationContext;
25 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AllContext;
26 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterAggregateContext;
27 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterConversionContext;
28 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterDefaultPrivilegesContext;
29 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterDefinitionClauseContext;
30 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterDirectoryContext;
31 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterDomainContext;
32 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterExtensionContext;
33 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterForeignTableContext;
34 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterFunctionContext;
35 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterGroupContext;
36 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterIndexContext;
37 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterLanguageContext;
38 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterMaterializedViewContext;
39 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterPackageContext;
40 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterProcedureContext;
41 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterRenameViewContext;
42 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterRuleContext;
43 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterSchemaContext;
44 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterSequenceContext;
45 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterSynonymContext;
46 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterTableActionContext;
47 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterTableContext;
48 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterTablespaceContext;
49 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterTextSearchDictionaryContext;
50 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterTextSearchParserContext;
51 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterTextSearchTemplateContext;
52 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterTypeContext;
53 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterViewContext;
54 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.BackwardAllContext;
55 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.BackwardContext;
56 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.BackwardCountContext;
57 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CloseContext;
58 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.ColumnConstraintContext;
59 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.ColumnDefinitionContext;
60 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CommentContext;
61 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CountContext;
62 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateAggregateContext;
63 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateCastContext;
64 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateConversionContext;
65 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateDatabaseContext;
66 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateDefinitionClauseContext;
67 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateDefinitionContext;
68 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateDirectoryContext;
69 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateDomainContext;
70 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateExtensionContext;
71 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateFunctionContext;
72 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateIndexContext;
73 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateLanguageContext;
74 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateProcedureContext;
75 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreatePublicationContext;
76 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateRuleContext;
77 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateSchemaContext;
78 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateSequenceContext;
79 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateSynonymContext;
80 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateTableContext;
81 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateTablespaceContext;
82 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateTextSearchContext;
83 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateTypeContext;
84 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateViewContext;
85 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CursorContext;
86 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CursorNameContext;
87 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DeallocateContext;
88 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DeclareContext;
89 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropCastContext;
90 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropColumnSpecificationContext;
91 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropConstraintSpecificationContext;
92 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropConversionContext;
93 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropDatabaseContext;
94 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropDirectoryContext;
95 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropDomainContext;
96 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropExtensionContext;
97 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropFunctionContext;
98 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropIndexContext;
99 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropLanguageContext;
100 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropProcedureContext;
101 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropPublicationContext;
102 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropRuleContext;
103 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropSchemaContext;
104 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropSequenceContext;
105 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropServerContext;
106 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropSynonymContext;
107 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropTableContext;
108 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropTablespaceContext;
109 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropTypeContext;
110 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropViewContext;
111 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.FetchContext;
112 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.FirstContext;
113 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.ForwardAllContext;
114 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.ForwardContext;
115 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.ForwardCountContext;
116 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.FuncArgExprContext;
117 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.FunctionExprWindowlessContext;
118 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.IndexElemContext;
119 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.IndexNameContext;
120 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.IndexNamesContext;
121 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.IndexParamsContext;
122 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.LastContext;
123 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.ModifyColumnSpecificationContext;
124 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.ModifyConstraintSpecificationContext;
125 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.MoveContext;
126 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.NameContext;
127 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.NameListContext;
128 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.NextContext;
129 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.PrepareContext;
130 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.PriorContext;
131 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.RelativeCountContext;
132 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.RenameColumnSpecificationContext;
133 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.RenameTableSpecificationContext;
134 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.TableConstraintContext;
135 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.TableConstraintUsingIndexContext;
136 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.TableNameClauseContext;
137 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.TableNamesClauseContext;
138 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.TruncateTableContext;
139 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.ValidateConstraintSpecificationContext;
140 import org.apache.shardingsphere.sql.parser.opengauss.visitor.statement.OpenGaussStatementVisitor;
141 import org.apache.shardingsphere.sql.parser.sql.common.enums.DirectionType;
142 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.AlterDefinitionSegment;
143 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.CreateDefinitionSegment;
144 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.ColumnDefinitionSegment;
145 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.AddColumnDefinitionSegment;
146 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.DropColumnDefinitionSegment;
147 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.ModifyColumnDefinitionSegment;
148 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.RenameColumnSegment;
149 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintDefinitionSegment;
150 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintSegment;
151 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.AddConstraintDefinitionSegment;
152 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.DropConstraintDefinitionSegment;
153 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.ModifyConstraintDefinitionSegment;
154 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.ValidateConstraintDefinitionSegment;
155 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.cursor.CursorNameSegment;
156 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.cursor.DirectionSegment;
157 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment;
158 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
159 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.table.RenameTableDefinitionSegment;
160 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
161 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
162 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.FunctionSegment;
163 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DataTypeSegment;
164 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.NameSegment;
165 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
166 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
167 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
168 import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DeleteStatement;
169 import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
170 import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
171 import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.UpdateStatement;
172 import org.apache.shardingsphere.sql.parser.sql.common.value.collection.CollectionValue;
173 import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
174 import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.NumberLiteralValue;
175 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterAggregateStatement;
176 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterConversionStatement;
177 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterDefaultPrivilegesStatement;
178 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterDirectoryStatement;
179 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterDomainStatement;
180 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterExtensionStatement;
181 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterForeignTableStatement;
182 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterFunctionStatement;
183 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterGroupStatement;
184 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterIndexStatement;
185 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterLanguageStatement;
186 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterMaterializedViewStatement;
187 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterPackageStatement;
188 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterProcedureStatement;
189 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterRuleStatement;
190 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterSchemaStatement;
191 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterSequenceStatement;
192 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterSynonymStatement;
193 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterTableStatement;
194 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterTablespaceStatement;
195 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterTextSearchStatement;
196 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterTypeStatement;
197 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterViewStatement;
198 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCloseStatement;
199 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCommentStatement;
200 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateAggregateStatement;
201 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateCastStatement;
202 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateConversionStatement;
203 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateDatabaseStatement;
204 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateDirectoryStatement;
205 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateDomainStatement;
206 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateExtensionStatement;
207 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateFunctionStatement;
208 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateIndexStatement;
209 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateLanguageStatement;
210 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateProcedureStatement;
211 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreatePublicationStatement;
212 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateRuleStatement;
213 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateSchemaStatement;
214 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateSequenceStatement;
215 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateSynonymStatement;
216 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateTableStatement;
217 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateTablespaceStatement;
218 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateTextSearchStatement;
219 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateTypeStatement;
220 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateViewStatement;
221 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCursorStatement;
222 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDeallocateStatement;
223 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDeclareStatement;
224 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropCastStatement;
225 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropConversionStatement;
226 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropDatabaseStatement;
227 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropDirectoryStatement;
228 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropDomainStatement;
229 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropExtensionStatement;
230 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropFunctionStatement;
231 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropIndexStatement;
232 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropLanguageStatement;
233 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropProcedureStatement;
234 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropPublicationStatement;
235 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropRuleStatement;
236 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropSchemaStatement;
237 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropSequenceStatement;
238 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropServerStatement;
239 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropSynonymStatement;
240 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropTableStatement;
241 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropTablespaceStatement;
242 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropTypeStatement;
243 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussDropViewStatement;
244 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussFetchStatement;
245 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussMoveStatement;
246 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussPrepareStatement;
247 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussTruncateStatement;
248
249 import java.util.ArrayList;
250 import java.util.Collection;
251 import java.util.Collections;
252 import java.util.Iterator;
253 import java.util.LinkedList;
254 import java.util.Optional;
255 import java.util.stream.Collectors;
256
257
258
259
260 public final class OpenGaussDDLStatementVisitor extends OpenGaussStatementVisitor implements DDLStatementVisitor {
261
262 @SuppressWarnings("unchecked")
263 @Override
264 public ASTNode visitCreateTable(final CreateTableContext ctx) {
265 OpenGaussCreateTableStatement result = new OpenGaussCreateTableStatement(null != ctx.ifNotExists());
266 result.setTable((SimpleTableSegment) visit(ctx.tableName()));
267 if (null != ctx.createDefinitionClause()) {
268 CollectionValue<CreateDefinitionSegment> createDefinitions = (CollectionValue<CreateDefinitionSegment>) visit(ctx.createDefinitionClause());
269 for (CreateDefinitionSegment each : createDefinitions.getValue()) {
270 if (each instanceof ColumnDefinitionSegment) {
271 result.getColumnDefinitions().add((ColumnDefinitionSegment) each);
272 } else if (each instanceof ConstraintDefinitionSegment) {
273 result.getConstraintDefinitions().add((ConstraintDefinitionSegment) each);
274 }
275 }
276 }
277 return result;
278 }
279
280 @Override
281 public ASTNode visitCreateDefinitionClause(final CreateDefinitionClauseContext ctx) {
282 CollectionValue<CreateDefinitionSegment> result = new CollectionValue<>();
283 for (CreateDefinitionContext each : ctx.createDefinition()) {
284 if (null != each.columnDefinition()) {
285 result.getValue().add((ColumnDefinitionSegment) visit(each.columnDefinition()));
286 }
287 if (null != each.tableConstraint()) {
288 result.getValue().add((ConstraintDefinitionSegment) visit(each.tableConstraint()));
289 }
290 }
291 return result;
292 }
293
294 @SuppressWarnings("unchecked")
295 @Override
296 public ASTNode visitAlterTable(final AlterTableContext ctx) {
297 OpenGaussAlterTableStatement result = new OpenGaussAlterTableStatement();
298 result.setTable((SimpleTableSegment) visit(ctx.tableNameClause().tableName()));
299 if (null != ctx.alterDefinitionClause()) {
300 for (AlterDefinitionSegment each : ((CollectionValue<AlterDefinitionSegment>) visit(ctx.alterDefinitionClause())).getValue()) {
301 if (each instanceof AddColumnDefinitionSegment) {
302 result.getAddColumnDefinitions().add((AddColumnDefinitionSegment) each);
303 } else if (each instanceof ModifyColumnDefinitionSegment) {
304 result.getModifyColumnDefinitions().add((ModifyColumnDefinitionSegment) each);
305 } else if (each instanceof DropColumnDefinitionSegment) {
306 result.getDropColumnDefinitions().add((DropColumnDefinitionSegment) each);
307 } else if (each instanceof AddConstraintDefinitionSegment) {
308 result.getAddConstraintDefinitions().add((AddConstraintDefinitionSegment) each);
309 } else if (each instanceof ValidateConstraintDefinitionSegment) {
310 result.getValidateConstraintDefinitions().add((ValidateConstraintDefinitionSegment) each);
311 } else if (each instanceof ModifyConstraintDefinitionSegment) {
312 result.getModifyConstraintDefinitions().add((ModifyConstraintDefinitionSegment) each);
313 } else if (each instanceof DropConstraintDefinitionSegment) {
314 result.getDropConstraintDefinitions().add((DropConstraintDefinitionSegment) each);
315 } else if (each instanceof RenameTableDefinitionSegment) {
316 result.setRenameTable(((RenameTableDefinitionSegment) each).getRenameTable());
317 } else if (each instanceof RenameColumnSegment) {
318 result.getRenameColumnDefinitions().add((RenameColumnSegment) each);
319 }
320 }
321 }
322 return result;
323 }
324
325 @Override
326 public ASTNode visitAlterAggregate(final AlterAggregateContext ctx) {
327 return new OpenGaussAlterAggregateStatement();
328 }
329
330 @Override
331 public ASTNode visitAlterDefaultPrivileges(final AlterDefaultPrivilegesContext ctx) {
332 return new OpenGaussAlterDefaultPrivilegesStatement();
333 }
334
335 @Override
336 public ASTNode visitAlterDefinitionClause(final AlterDefinitionClauseContext ctx) {
337 CollectionValue<AlterDefinitionSegment> result = new CollectionValue<>();
338 if (null != ctx.alterTableActions()) {
339 result.getValue().addAll(ctx.alterTableActions().alterTableAction().stream().flatMap(each -> getAlterDefinitionSegments(each).stream()).collect(Collectors.toList()));
340 }
341 if (null != ctx.renameColumnSpecification()) {
342 result.getValue().add((RenameColumnSegment) visit(ctx.renameColumnSpecification()));
343 }
344 if (null != ctx.renameTableSpecification()) {
345 result.getValue().add((RenameTableDefinitionSegment) visit(ctx.renameTableSpecification()));
346 }
347 return result;
348 }
349
350 @SuppressWarnings("unchecked")
351 private Collection<AlterDefinitionSegment> getAlterDefinitionSegments(final AlterTableActionContext ctx) {
352 Collection<AlterDefinitionSegment> result = new LinkedList<>();
353 if (null != ctx.addColumnSpecification()) {
354 result.addAll(((CollectionValue<AddColumnDefinitionSegment>) visit(ctx.addColumnSpecification())).getValue());
355 }
356 if (null != ctx.addConstraintSpecification() && null != ctx.addConstraintSpecification().tableConstraint()) {
357 result.add((AddConstraintDefinitionSegment) visit(ctx.addConstraintSpecification()));
358 }
359 if (null != ctx.validateConstraintSpecification()) {
360 result.add((ValidateConstraintDefinitionSegment) visit(ctx.validateConstraintSpecification()));
361 }
362 if (null != ctx.modifyColumnSpecification()) {
363 result.add((ModifyColumnDefinitionSegment) visit(ctx.modifyColumnSpecification()));
364 }
365 if (null != ctx.modifyConstraintSpecification()) {
366 result.add((ModifyConstraintDefinitionSegment) visit(ctx.modifyConstraintSpecification()));
367 }
368 if (null != ctx.dropColumnSpecification()) {
369 result.add((DropColumnDefinitionSegment) visit(ctx.dropColumnSpecification()));
370 }
371 if (null != ctx.dropConstraintSpecification()) {
372 result.add((DropConstraintDefinitionSegment) visit(ctx.dropConstraintSpecification()));
373 }
374 return result;
375 }
376
377 @Override
378 public ASTNode visitAlterForeignTable(final AlterForeignTableContext ctx) {
379 return new OpenGaussAlterForeignTableStatement();
380 }
381
382 @Override
383 public ASTNode visitAlterGroup(final AlterGroupContext ctx) {
384 return new OpenGaussAlterGroupStatement();
385 }
386
387 @Override
388 public ASTNode visitAlterPackage(final AlterPackageContext ctx) {
389 return new OpenGaussAlterPackageStatement();
390 }
391
392 @Override
393 public ASTNode visitAlterMaterializedView(final AlterMaterializedViewContext ctx) {
394 return new OpenGaussAlterMaterializedViewStatement();
395 }
396
397 @Override
398 public ASTNode visitAddConstraintSpecification(final AddConstraintSpecificationContext ctx) {
399 return new AddConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ConstraintDefinitionSegment) visit(ctx.tableConstraint()));
400 }
401
402 @Override
403 public ASTNode visitValidateConstraintSpecification(final ValidateConstraintSpecificationContext ctx) {
404 return new ValidateConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ConstraintSegment) visit(ctx.constraintName()));
405 }
406
407 @Override
408 public ASTNode visitModifyConstraintSpecification(final ModifyConstraintSpecificationContext ctx) {
409 return new ModifyConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ConstraintSegment) visit(ctx.constraintName()));
410 }
411
412 @Override
413 public ASTNode visitDropConstraintSpecification(final DropConstraintSpecificationContext ctx) {
414 return new DropConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ConstraintSegment) visit(ctx.constraintName()));
415 }
416
417 @Override
418 public ASTNode visitAlterDomain(final AlterDomainContext ctx) {
419 return new OpenGaussAlterDomainStatement();
420 }
421
422 @Override
423 public ASTNode visitRenameTableSpecification(final RenameTableSpecificationContext ctx) {
424 RenameTableDefinitionSegment result = new RenameTableDefinitionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
425 TableNameSegment tableName = new TableNameSegment(ctx.identifier().start.getStartIndex(), ctx.identifier().stop.getStopIndex(), (IdentifierValue) visit(ctx.identifier()));
426 result.setRenameTable(new SimpleTableSegment(tableName));
427 return result;
428 }
429
430 @Override
431 public ASTNode visitAddColumnSpecification(final AddColumnSpecificationContext ctx) {
432 CollectionValue<AddColumnDefinitionSegment> result = new CollectionValue<>();
433 ColumnDefinitionContext columnDefinition = ctx.columnDefinition();
434 if (null != columnDefinition) {
435 AddColumnDefinitionSegment addColumnDefinition = new AddColumnDefinitionSegment(
436 ctx.columnDefinition().getStart().getStartIndex(), columnDefinition.getStop().getStopIndex(), Collections.singleton((ColumnDefinitionSegment) visit(columnDefinition)));
437 result.getValue().add(addColumnDefinition);
438 }
439 return result;
440 }
441
442 @Override
443 public ASTNode visitColumnDefinition(final ColumnDefinitionContext ctx) {
444 ColumnSegment column = (ColumnSegment) visit(ctx.columnName());
445 DataTypeSegment dataType = (DataTypeSegment) visit(ctx.dataType());
446 boolean isPrimaryKey = ctx.columnConstraint().stream().anyMatch(each -> null != each.columnConstraintOption() && null != each.columnConstraintOption().primaryKey());
447
448 ColumnDefinitionSegment result = new ColumnDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), column, dataType, isPrimaryKey, false);
449 for (ColumnConstraintContext each : ctx.columnConstraint()) {
450 if (null != each.columnConstraintOption().tableName()) {
451 result.getReferencedTables().add((SimpleTableSegment) visit(each.columnConstraintOption().tableName()));
452 }
453 }
454 return result;
455 }
456
457 @Override
458 public ASTNode visitTableConstraintUsingIndex(final TableConstraintUsingIndexContext ctx) {
459 ConstraintDefinitionSegment result = new ConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex());
460 if (null != ctx.constraintName()) {
461 result.setConstraintName((ConstraintSegment) visit(ctx.constraintName()));
462 }
463 if (null != ctx.indexName()) {
464 result.setIndexName((IndexSegment) visit(ctx.indexName()));
465 }
466 return result;
467 }
468
469 @SuppressWarnings("unchecked")
470 @Override
471 public ASTNode visitTableConstraint(final TableConstraintContext ctx) {
472 ConstraintDefinitionSegment result = new ConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex());
473 if (null != ctx.constraintClause()) {
474 result.setConstraintName((ConstraintSegment) visit(ctx.constraintClause().constraintName()));
475 }
476 if (null != ctx.tableConstraintOption().primaryKey()) {
477 result.getPrimaryKeyColumns().addAll(((CollectionValue<ColumnSegment>) visit(ctx.tableConstraintOption().columnNames(0))).getValue());
478 }
479 if (null != ctx.tableConstraintOption().FOREIGN()) {
480 result.setReferencedTable((SimpleTableSegment) visit(ctx.tableConstraintOption().tableName()));
481 }
482 return result;
483 }
484
485 @Override
486 public ASTNode visitModifyColumnSpecification(final ModifyColumnSpecificationContext ctx) {
487
488 ColumnSegment column = (ColumnSegment) visit(ctx.modifyColumn().columnName());
489 DataTypeSegment dataType = null == ctx.dataType() ? null : (DataTypeSegment) visit(ctx.dataType());
490 ColumnDefinitionSegment columnDefinition = new ColumnDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), column, dataType, false, false);
491 return new ModifyColumnDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), columnDefinition);
492 }
493
494 @Override
495 public ASTNode visitDropColumnSpecification(final DropColumnSpecificationContext ctx) {
496 return new DropColumnDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), Collections.singleton((ColumnSegment) visit(ctx.columnName())));
497 }
498
499 @Override
500 public ASTNode visitRenameColumnSpecification(final RenameColumnSpecificationContext ctx) {
501 return new RenameColumnSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ColumnSegment) visit(ctx.columnName(0)), (ColumnSegment) visit(ctx.columnName(1)));
502 }
503
504 @SuppressWarnings("unchecked")
505 @Override
506 public ASTNode visitDropTable(final DropTableContext ctx) {
507 boolean containsCascade = null != ctx.dropTableOpt() && null != ctx.dropTableOpt().CASCADE();
508 OpenGaussDropTableStatement result = new OpenGaussDropTableStatement(null != ctx.ifExists(), containsCascade);
509 result.getTables().addAll(((CollectionValue<SimpleTableSegment>) visit(ctx.tableNames())).getValue());
510 return result;
511 }
512
513 @SuppressWarnings("unchecked")
514 @Override
515 public ASTNode visitTruncateTable(final TruncateTableContext ctx) {
516 OpenGaussTruncateStatement result = new OpenGaussTruncateStatement();
517 result.getTables().addAll(((CollectionValue<SimpleTableSegment>) visit(ctx.tableNamesClause())).getValue());
518 return result;
519 }
520
521 @SuppressWarnings("unchecked")
522 @Override
523 public ASTNode visitCreateIndex(final CreateIndexContext ctx) {
524 OpenGaussCreateIndexStatement result = new OpenGaussCreateIndexStatement(null != ctx.ifNotExists());
525 result.setTable((SimpleTableSegment) visit(ctx.tableName()));
526 result.getColumns().addAll(((CollectionValue<ColumnSegment>) visit(ctx.indexParams())).getValue());
527 if (null == ctx.indexName()) {
528 result.setGeneratedIndexStartIndex(ctx.ON().getSymbol().getStartIndex() - 1);
529 } else {
530 result.setIndex((IndexSegment) visit(ctx.indexName()));
531 }
532 return result;
533 }
534
535 @Override
536 public ASTNode visitIndexParams(final IndexParamsContext ctx) {
537 CollectionValue<ColumnSegment> result = new CollectionValue<>();
538 for (IndexElemContext each : ctx.indexElem()) {
539 if (null != each.colId()) {
540 result.getValue().add(new ColumnSegment(each.colId().start.getStartIndex(), each.colId().stop.getStopIndex(), new IdentifierValue(each.colId().getText())));
541 }
542 if (null != each.functionExprWindowless()) {
543 FunctionSegment functionSegment = (FunctionSegment) visit(each.functionExprWindowless());
544 functionSegment.getParameters().forEach(param -> {
545 if (param instanceof ColumnSegment) {
546 result.getValue().add((ColumnSegment) param);
547 }
548 });
549 }
550 }
551 return result;
552 }
553
554 @Override
555 public ASTNode visitFunctionExprWindowless(final FunctionExprWindowlessContext ctx) {
556 FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.funcApplication().funcName().getText(), getOriginalText(ctx));
557 result.getParameters().addAll(getExpressions(ctx.funcApplication().funcArgList().funcArgExpr()));
558 return result;
559 }
560
561 private Collection<ExpressionSegment> getExpressions(final Collection<FuncArgExprContext> aExprContexts) {
562 if (null == aExprContexts) {
563 return Collections.emptyList();
564 }
565 Collection<ExpressionSegment> result = new ArrayList<>(aExprContexts.size());
566 for (FuncArgExprContext each : aExprContexts) {
567 result.add((ExpressionSegment) visit(each.aExpr()));
568 }
569 return result;
570 }
571
572 @Override
573 public ASTNode visitAlterIndex(final AlterIndexContext ctx) {
574 OpenGaussAlterIndexStatement result = new OpenGaussAlterIndexStatement();
575 result.setIndex(createIndexSegment((SimpleTableSegment) visit(ctx.qualifiedName())));
576 if (null != ctx.alterIndexDefinitionClause().renameIndexSpecification()) {
577 result.setRenameIndex((IndexSegment) visit(ctx.alterIndexDefinitionClause().renameIndexSpecification().indexName()));
578 }
579 return result;
580 }
581
582 private IndexSegment createIndexSegment(final SimpleTableSegment tableSegment) {
583 IndexNameSegment indexName = new IndexNameSegment(tableSegment.getTableName().getStartIndex(), tableSegment.getTableName().getStopIndex(), tableSegment.getTableName().getIdentifier());
584 IndexSegment result = new IndexSegment(tableSegment.getStartIndex(), tableSegment.getStopIndex(), indexName);
585 tableSegment.getOwner().ifPresent(result::setOwner);
586 return result;
587 }
588
589 @SuppressWarnings("unchecked")
590 @Override
591 public ASTNode visitDropIndex(final DropIndexContext ctx) {
592 OpenGaussDropIndexStatement result = new OpenGaussDropIndexStatement(null != ctx.ifExists());
593 result.getIndexes().addAll(createIndexSegments(((CollectionValue<SimpleTableSegment>) visit(ctx.qualifiedNameList())).getValue()));
594 return result;
595 }
596
597 private Collection<IndexSegment> createIndexSegments(final Collection<SimpleTableSegment> tableSegments) {
598 Collection<IndexSegment> result = new LinkedList<>();
599 for (SimpleTableSegment each : tableSegments) {
600 result.add(createIndexSegment(each));
601 }
602 return result;
603 }
604
605 @Override
606 public ASTNode visitIndexNames(final IndexNamesContext ctx) {
607 CollectionValue<IndexSegment> result = new CollectionValue<>();
608 for (IndexNameContext each : ctx.indexName()) {
609 result.getValue().add((IndexSegment) visit(each));
610 }
611 return result;
612 }
613
614 @Override
615 public ASTNode visitTableNameClause(final TableNameClauseContext ctx) {
616 return visit(ctx.tableName());
617 }
618
619 @Override
620 public ASTNode visitTableNamesClause(final TableNamesClauseContext ctx) {
621 Collection<SimpleTableSegment> tableSegments = new LinkedList<>();
622 for (int i = 0; i < ctx.tableNameClause().size(); i++) {
623 tableSegments.add((SimpleTableSegment) visit(ctx.tableNameClause(i)));
624 }
625 CollectionValue<SimpleTableSegment> result = new CollectionValue<>();
626 result.getValue().addAll(tableSegments);
627 return result;
628 }
629
630 @Override
631 public ASTNode visitAlterFunction(final AlterFunctionContext ctx) {
632 return new OpenGaussAlterFunctionStatement();
633 }
634
635 @Override
636 public ASTNode visitAlterProcedure(final AlterProcedureContext ctx) {
637 return new OpenGaussAlterProcedureStatement();
638 }
639
640 @Override
641 public ASTNode visitCreateFunction(final CreateFunctionContext ctx) {
642 return new OpenGaussCreateFunctionStatement();
643 }
644
645 @Override
646 public ASTNode visitCreateProcedure(final CreateProcedureContext ctx) {
647 return new OpenGaussCreateProcedureStatement();
648 }
649
650 @Override
651 public ASTNode visitDropFunction(final DropFunctionContext ctx) {
652 return new OpenGaussDropFunctionStatement();
653 }
654
655 @SuppressWarnings("unchecked")
656 @Override
657 public ASTNode visitDropView(final DropViewContext ctx) {
658 OpenGaussDropViewStatement result = new OpenGaussDropViewStatement();
659 result.getViews().addAll(((CollectionValue<SimpleTableSegment>) visit(ctx.qualifiedNameList())).getValue());
660 return result;
661 }
662
663 @Override
664 public ASTNode visitCreateView(final CreateViewContext ctx) {
665 OpenGaussCreateViewStatement result = new OpenGaussCreateViewStatement();
666 result.setView((SimpleTableSegment) visit(ctx.qualifiedName()));
667 result.setViewDefinition(getOriginalText(ctx.select()));
668 result.setSelect((SelectStatement) visit(ctx.select()));
669 return result;
670 }
671
672 @Override
673 public ASTNode visitAlterView(final AlterViewContext ctx) {
674 OpenGaussAlterViewStatement result = new OpenGaussAlterViewStatement();
675 result.setView((SimpleTableSegment) visit(ctx.qualifiedName()));
676 if (ctx.alterViewClauses() instanceof AlterRenameViewContext) {
677 NameContext nameContext = ((AlterRenameViewContext) ctx.alterViewClauses()).name();
678 result.setRenameView(
679 new SimpleTableSegment(new TableNameSegment(nameContext.getStart().getStartIndex(), nameContext.getStop().getStopIndex(), (IdentifierValue) visit(nameContext.identifier()))));
680 }
681 return result;
682 }
683
684 @Override
685 public ASTNode visitDropDatabase(final DropDatabaseContext ctx) {
686 OpenGaussDropDatabaseStatement result = new OpenGaussDropDatabaseStatement();
687 result.setDatabaseName(((IdentifierValue) visit(ctx.name())).getValue());
688 result.setIfExists(null != ctx.ifExists());
689 return result;
690 }
691
692 @Override
693 public ASTNode visitDropServer(final DropServerContext ctx) {
694 return new OpenGaussDropServerStatement();
695 }
696
697 @Override
698 public ASTNode visitDropProcedure(final DropProcedureContext ctx) {
699 return new OpenGaussDropProcedureStatement();
700 }
701
702 @Override
703 public ASTNode visitDropPublication(final DropPublicationContext ctx) {
704 return new OpenGaussDropPublicationStatement();
705 }
706
707 @Override
708 public ASTNode visitDropCast(final DropCastContext ctx) {
709 return new OpenGaussDropCastStatement();
710 }
711
712 @Override
713 public ASTNode visitDropRule(final DropRuleContext ctx) {
714 return new OpenGaussDropRuleStatement();
715 }
716
717 @Override
718 public ASTNode visitCreateDatabase(final CreateDatabaseContext ctx) {
719 OpenGaussCreateDatabaseStatement result = new OpenGaussCreateDatabaseStatement();
720 result.setDatabaseName(((IdentifierValue) visit(ctx.name())).getValue());
721 return result;
722 }
723
724 @Override
725 public ASTNode visitCreateSequence(final CreateSequenceContext ctx) {
726 OpenGaussCreateSequenceStatement result = new OpenGaussCreateSequenceStatement();
727 result.setSequenceName(((SimpleTableSegment) visit(ctx.qualifiedName())).getTableName().getIdentifier().getValue());
728 return result;
729 }
730
731 @Override
732 public ASTNode visitAlterSequence(final AlterSequenceContext ctx) {
733 OpenGaussAlterSequenceStatement result = new OpenGaussAlterSequenceStatement();
734 result.setSequenceName(((SimpleTableSegment) visit(ctx.qualifiedName())).getTableName().getIdentifier().getValue());
735 return result;
736 }
737
738 @SuppressWarnings({"unchecked", "rawtypes"})
739 @Override
740 public ASTNode visitDropSequence(final DropSequenceContext ctx) {
741 OpenGaussDropSequenceStatement result = new OpenGaussDropSequenceStatement();
742 result.setSequenceNames(((CollectionValue) visit(ctx.qualifiedNameList())).getValue());
743 return result;
744 }
745
746 @Override
747 public ASTNode visitDropSynonym(final DropSynonymContext ctx) {
748 return new OpenGaussDropSynonymStatement();
749 }
750
751 @Override
752 public ASTNode visitDropType(final DropTypeContext ctx) {
753 return new OpenGaussDropTypeStatement();
754 }
755
756 @Override
757 public ASTNode visitDropDirectory(final DropDirectoryContext ctx) {
758 return new OpenGaussDropDirectoryStatement();
759 }
760
761 @Override
762 public ASTNode visitPrepare(final PrepareContext ctx) {
763 OpenGaussPrepareStatement result = new OpenGaussPrepareStatement();
764 if (null != ctx.preparableStmt().select()) {
765 result.setSelect((SelectStatement) visit(ctx.preparableStmt().select()));
766 }
767 if (null != ctx.preparableStmt().insert()) {
768 result.setInsert((InsertStatement) visit(ctx.preparableStmt().insert()));
769 }
770 if (null != ctx.preparableStmt().update()) {
771 result.setUpdate((UpdateStatement) visit(ctx.preparableStmt().update()));
772 }
773 if (null != ctx.preparableStmt().delete()) {
774 result.setDelete((DeleteStatement) visit(ctx.preparableStmt().delete()));
775 }
776 return result;
777 }
778
779 @Override
780 public ASTNode visitDeallocate(final DeallocateContext ctx) {
781 return new OpenGaussDeallocateStatement();
782 }
783
784 @Override
785 public ASTNode visitCreateSynonym(final CreateSynonymContext ctx) {
786 return new OpenGaussCreateSynonymStatement();
787 }
788
789 @Override
790 public ASTNode visitCreateAggregate(final CreateAggregateContext ctx) {
791 return new OpenGaussCreateAggregateStatement();
792 }
793
794 @Override
795 public ASTNode visitCreatePublication(final CreatePublicationContext ctx) {
796 return new OpenGaussCreatePublicationStatement();
797 }
798
799 @Override
800 public ASTNode visitCreateDirectory(final CreateDirectoryContext ctx) {
801 return new OpenGaussCreateDirectoryStatement();
802 }
803
804 @Override
805 public ASTNode visitCreateTablespace(final CreateTablespaceContext ctx) {
806 return new OpenGaussCreateTablespaceStatement();
807 }
808
809 @Override
810 public ASTNode visitAlterTablespace(final AlterTablespaceContext ctx) {
811 return new OpenGaussAlterTablespaceStatement();
812 }
813
814 @Override
815 public ASTNode visitDropTablespace(final DropTablespaceContext ctx) {
816 return new OpenGaussDropTablespaceStatement();
817 }
818
819 @Override
820 public ASTNode visitDropDomain(final DropDomainContext ctx) {
821 return new OpenGaussDropDomainStatement();
822 }
823
824 @Override
825 public ASTNode visitCreateDomain(final CreateDomainContext ctx) {
826 return new OpenGaussCreateDomainStatement();
827 }
828
829 @Override
830 public ASTNode visitCreateRule(final CreateRuleContext ctx) {
831 return new OpenGaussCreateRuleStatement();
832 }
833
834 @Override
835 public ASTNode visitCreateLanguage(final CreateLanguageContext ctx) {
836 return new OpenGaussCreateLanguageStatement();
837 }
838
839 @Override
840 public ASTNode visitCreateSchema(final CreateSchemaContext ctx) {
841 OpenGaussCreateSchemaStatement result = new OpenGaussCreateSchemaStatement();
842 if (null != ctx.createSchemaClauses().colId()) {
843 result.setSchemaName(new IdentifierValue(ctx.createSchemaClauses().colId().getText()));
844 }
845 if (null != ctx.createSchemaClauses().roleSpec() && null != ctx.createSchemaClauses().roleSpec().identifier()) {
846 result.setUsername((IdentifierValue) visit(ctx.createSchemaClauses().roleSpec().identifier()));
847 }
848 return result;
849 }
850
851 @Override
852 public ASTNode visitAlterSchema(final AlterSchemaContext ctx) {
853 OpenGaussAlterSchemaStatement result = new OpenGaussAlterSchemaStatement();
854 result.setSchemaName((IdentifierValue) visit(ctx.name().get(0)));
855 if (ctx.name().size() > 1) {
856 result.setRenameSchema((IdentifierValue) visit(ctx.name().get(1)));
857 }
858 return result;
859 }
860
861 @SuppressWarnings("unchecked")
862 @Override
863 public ASTNode visitDropSchema(final DropSchemaContext ctx) {
864 OpenGaussDropSchemaStatement result = new OpenGaussDropSchemaStatement();
865 result.getSchemaNames().addAll(((CollectionValue<IdentifierValue>) visit(ctx.nameList())).getValue());
866 result.setContainsCascade(null != ctx.dropBehavior() && null != ctx.dropBehavior().CASCADE());
867 return result;
868 }
869
870 @SuppressWarnings("unchecked")
871 @Override
872 public ASTNode visitNameList(final NameListContext ctx) {
873 CollectionValue<IdentifierValue> result = new CollectionValue<>();
874 if (null != ctx.nameList()) {
875 result.combine((CollectionValue<IdentifierValue>) visit(ctx.nameList()));
876 }
877 if (null != ctx.name()) {
878 result.getValue().add((IdentifierValue) visit(ctx.name()));
879 }
880 return result;
881 }
882
883 @Override
884 public ASTNode visitAlterLanguage(final AlterLanguageContext ctx) {
885 return new OpenGaussAlterLanguageStatement();
886 }
887
888 @Override
889 public ASTNode visitAlterSynonym(final AlterSynonymContext ctx) {
890 return new OpenGaussAlterSynonymStatement();
891 }
892
893 @Override
894 public ASTNode visitAlterDirectory(final AlterDirectoryContext ctx) {
895 return new OpenGaussAlterDirectoryStatement();
896 }
897
898 @Override
899 public ASTNode visitAlterRule(final AlterRuleContext ctx) {
900 return new OpenGaussAlterRuleStatement();
901 }
902
903 @Override
904 public ASTNode visitAlterType(final AlterTypeContext ctx) {
905 return new OpenGaussAlterTypeStatement();
906 }
907
908 @Override
909 public ASTNode visitDropLanguage(final DropLanguageContext ctx) {
910 return new OpenGaussDropLanguageStatement();
911 }
912
913 @Override
914 public ASTNode visitCreateConversion(final CreateConversionContext ctx) {
915 return new OpenGaussCreateConversionStatement();
916 }
917
918 @Override
919 public ASTNode visitCreateCast(final CreateCastContext ctx) {
920 return new OpenGaussCreateCastStatement();
921 }
922
923 @Override
924 public ASTNode visitCreateType(final CreateTypeContext ctx) {
925 return new OpenGaussCreateTypeStatement();
926 }
927
928 @Override
929 public ASTNode visitDropConversion(final DropConversionContext ctx) {
930 return new OpenGaussDropConversionStatement();
931 }
932
933 @Override
934 public ASTNode visitAlterConversion(final AlterConversionContext ctx) {
935 return new OpenGaussAlterConversionStatement();
936 }
937
938 @Override
939 public ASTNode visitCreateTextSearch(final CreateTextSearchContext ctx) {
940 return new OpenGaussCreateTextSearchStatement();
941 }
942
943 @Override
944 public ASTNode visitAlterTextSearchDictionary(final AlterTextSearchDictionaryContext ctx) {
945 return new OpenGaussAlterTextSearchStatement();
946 }
947
948 @Override
949 public ASTNode visitAlterTextSearchTemplate(final AlterTextSearchTemplateContext ctx) {
950 return new OpenGaussAlterTextSearchStatement();
951 }
952
953 @Override
954 public ASTNode visitAlterTextSearchParser(final AlterTextSearchParserContext ctx) {
955 return new OpenGaussAlterTextSearchStatement();
956 }
957
958 @Override
959 public ASTNode visitCreateExtension(final CreateExtensionContext ctx) {
960 return new OpenGaussCreateExtensionStatement();
961 }
962
963 @Override
964 public ASTNode visitAlterExtension(final AlterExtensionContext ctx) {
965 return new OpenGaussAlterExtensionStatement();
966 }
967
968 @Override
969 public ASTNode visitDropExtension(final DropExtensionContext ctx) {
970 return new OpenGaussDropExtensionStatement();
971 }
972
973 @Override
974 public ASTNode visitDeclare(final DeclareContext ctx) {
975 OpenGaussDeclareStatement result = new OpenGaussDeclareStatement();
976 result.setCursorName((CursorNameSegment) visit(ctx.cursorName()));
977 result.setSelect((SelectStatement) visit(ctx.select()));
978 return result;
979 }
980
981 @Override
982 public ASTNode visitComment(final CommentContext ctx) {
983 if (null != ctx.commentClauses().objectTypeAnyName() && null != ctx.commentClauses().objectTypeAnyName().TABLE()) {
984 return commentOnTable(ctx);
985 }
986 if (null != ctx.commentClauses().COLUMN()) {
987 return commentOnColumn(ctx);
988 }
989 return new OpenGaussCommentStatement();
990 }
991
992 @SuppressWarnings("unchecked")
993 private OpenGaussCommentStatement commentOnColumn(final CommentContext ctx) {
994 OpenGaussCommentStatement result = new OpenGaussCommentStatement();
995 Iterator<NameSegment> nameSegmentIterator = ((CollectionValue<NameSegment>) visit(ctx.commentClauses().anyName())).getValue().iterator();
996 Optional<NameSegment> columnName = nameSegmentIterator.hasNext() ? Optional.of(nameSegmentIterator.next()) : Optional.empty();
997 columnName.ifPresent(optional -> result.setColumn(new ColumnSegment(optional.getStartIndex(), optional.getStopIndex(), optional.getIdentifier())));
998 result.setComment(new IdentifierValue(ctx.commentClauses().commentText().getText()));
999 setTableSegment(result, nameSegmentIterator);
1000 return result;
1001 }
1002
1003 @SuppressWarnings("unchecked")
1004 private OpenGaussCommentStatement commentOnTable(final CommentContext ctx) {
1005 OpenGaussCommentStatement result = new OpenGaussCommentStatement();
1006 Iterator<NameSegment> nameSegmentIterator = ((CollectionValue<NameSegment>) visit(ctx.commentClauses().anyName())).getValue().iterator();
1007 result.setComment(new IdentifierValue(ctx.commentClauses().commentText().getText()));
1008 setTableSegment(result, nameSegmentIterator);
1009 return result;
1010 }
1011
1012 private void setTableSegment(final OpenGaussCommentStatement statement, final Iterator<NameSegment> nameSegmentIterator) {
1013 Optional<NameSegment> tableName = nameSegmentIterator.hasNext() ? Optional.of(nameSegmentIterator.next()) : Optional.empty();
1014 tableName.ifPresent(optional -> statement.setTable(new SimpleTableSegment(new TableNameSegment(optional.getStartIndex(), optional.getStopIndex(), optional.getIdentifier()))));
1015 Optional<NameSegment> schemaName = nameSegmentIterator.hasNext() ? Optional.of(nameSegmentIterator.next()) : Optional.empty();
1016 schemaName.ifPresent(optional -> statement.getTable().setOwner(new OwnerSegment(optional.getStartIndex(), optional.getStopIndex(), optional.getIdentifier())));
1017 Optional<NameSegment> databaseName = nameSegmentIterator.hasNext() ? Optional.of(nameSegmentIterator.next()) : Optional.empty();
1018 databaseName.ifPresent(optional -> statement.getTable().getOwner()
1019 .ifPresent(owner -> owner.setOwner(new OwnerSegment(optional.getStartIndex(), optional.getStopIndex(), optional.getIdentifier()))));
1020 }
1021
1022 @Override
1023 public ASTNode visitCursor(final CursorContext ctx) {
1024 OpenGaussCursorStatement result = new OpenGaussCursorStatement();
1025 result.setCursorName((CursorNameSegment) visit(ctx.cursorName()));
1026 result.setSelect((SelectStatement) visit(ctx.select()));
1027 return result;
1028 }
1029
1030 @Override
1031 public ASTNode visitCursorName(final CursorNameContext ctx) {
1032 return new CursorNameSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), (IdentifierValue) visit(ctx.name()));
1033 }
1034
1035 @Override
1036 public ASTNode visitClose(final CloseContext ctx) {
1037 OpenGaussCloseStatement result = new OpenGaussCloseStatement();
1038 if (null != ctx.cursorName()) {
1039 result.setCursorName((CursorNameSegment) visit(ctx.cursorName()));
1040 }
1041 result.setCloseAll(null != ctx.ALL());
1042 return result;
1043 }
1044
1045 @Override
1046 public ASTNode visitMove(final MoveContext ctx) {
1047 OpenGaussMoveStatement result = new OpenGaussMoveStatement();
1048 result.setCursorName((CursorNameSegment) visit(ctx.cursorName()));
1049 if (null != ctx.direction()) {
1050 result.setDirection((DirectionSegment) visit(ctx.direction()));
1051 }
1052 return result;
1053 }
1054
1055 @Override
1056 public ASTNode visitFetch(final FetchContext ctx) {
1057 OpenGaussFetchStatement result = new OpenGaussFetchStatement();
1058 result.setCursorName((CursorNameSegment) visit(ctx.cursorName()));
1059 if (null != ctx.direction()) {
1060 result.setDirection((DirectionSegment) visit(ctx.direction()));
1061 }
1062 return result;
1063 }
1064
1065 @Override
1066 public ASTNode visitNext(final NextContext ctx) {
1067 DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1068 result.setDirectionType(DirectionType.NEXT);
1069 return result;
1070 }
1071
1072 @Override
1073 public ASTNode visitPrior(final PriorContext ctx) {
1074 DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1075 result.setDirectionType(DirectionType.PRIOR);
1076 return result;
1077 }
1078
1079 @Override
1080 public ASTNode visitFirst(final FirstContext ctx) {
1081 DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1082 result.setDirectionType(DirectionType.FIRST);
1083 return result;
1084 }
1085
1086 @Override
1087 public ASTNode visitLast(final LastContext ctx) {
1088 DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1089 result.setDirectionType(DirectionType.LAST);
1090 return result;
1091 }
1092
1093 @Override
1094 public ASTNode visitAbsoluteCount(final AbsoluteCountContext ctx) {
1095 DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1096 result.setDirectionType(DirectionType.ABSOLUTE_COUNT);
1097 result.setCount(((NumberLiteralValue) visit(ctx.signedIconst())).getValue().longValue());
1098 return result;
1099 }
1100
1101 @Override
1102 public ASTNode visitRelativeCount(final RelativeCountContext ctx) {
1103 DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1104 result.setDirectionType(DirectionType.RELATIVE_COUNT);
1105 result.setCount(((NumberLiteralValue) visit(ctx.signedIconst())).getValue().longValue());
1106 return result;
1107 }
1108
1109 @Override
1110 public ASTNode visitCount(final CountContext ctx) {
1111 DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1112 result.setDirectionType(DirectionType.COUNT);
1113 result.setCount(((NumberLiteralValue) visit(ctx.signedIconst())).getValue().longValue());
1114 return result;
1115 }
1116
1117 @Override
1118 public ASTNode visitAll(final AllContext ctx) {
1119 DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1120 result.setDirectionType(DirectionType.ALL);
1121 return result;
1122 }
1123
1124 @Override
1125 public ASTNode visitForward(final ForwardContext ctx) {
1126 DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1127 result.setDirectionType(DirectionType.FORWARD);
1128 return result;
1129 }
1130
1131 @Override
1132 public ASTNode visitForwardCount(final ForwardCountContext ctx) {
1133 DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1134 result.setDirectionType(DirectionType.FORWARD_COUNT);
1135 result.setCount(((NumberLiteralValue) visit(ctx.signedIconst())).getValue().longValue());
1136 return result;
1137 }
1138
1139 @Override
1140 public ASTNode visitForwardAll(final ForwardAllContext ctx) {
1141 DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1142 result.setDirectionType(DirectionType.FORWARD_ALL);
1143 return result;
1144 }
1145
1146 @Override
1147 public ASTNode visitBackward(final BackwardContext ctx) {
1148 DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1149 result.setDirectionType(DirectionType.BACKWARD);
1150 return result;
1151 }
1152
1153 @Override
1154 public ASTNode visitBackwardCount(final BackwardCountContext ctx) {
1155 DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1156 result.setDirectionType(DirectionType.BACKWARD_COUNT);
1157 result.setCount(((NumberLiteralValue) visit(ctx.signedIconst())).getValue().longValue());
1158 return result;
1159 }
1160
1161 @Override
1162 public ASTNode visitBackwardAll(final BackwardAllContext ctx) {
1163 DirectionSegment result = new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
1164 result.setDirectionType(DirectionType.BACKWARD_ALL);
1165 return result;
1166 }
1167 }