View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shardingsphere.sql.parser.postgresql.visitor.statement.type;
19  
20  import org.antlr.v4.runtime.ParserRuleContext;
21  import org.antlr.v4.runtime.misc.Interval;
22  import org.apache.shardingsphere.sql.parser.api.ASTNode;
23  import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DDLStatementVisitor;
24  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AbsoluteCountContext;
25  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AddColumnSpecificationContext;
26  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AddConstraintSpecificationContext;
27  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AllContext;
28  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterAggregateContext;
29  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterCollationContext;
30  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterConversionContext;
31  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterDefaultPrivilegesContext;
32  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterDefinitionClauseContext;
33  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterDomainContext;
34  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterExtensionContext;
35  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterForeignDataWrapperContext;
36  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterForeignTableContext;
37  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterFunctionContext;
38  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterGroupContext;
39  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterIndexContext;
40  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterLanguageContext;
41  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterMaterializedViewContext;
42  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterOperatorContext;
43  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterPolicyContext;
44  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterProcedureContext;
45  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterPublicationContext;
46  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterRenameViewContext;
47  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterRoutineContext;
48  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterRuleContext;
49  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterSchemaContext;
50  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterSequenceContext;
51  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterServerContext;
52  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterStatisticsContext;
53  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterSubscriptionContext;
54  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTableActionContext;
55  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTableContext;
56  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTablespaceContext;
57  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTextSearchConfigurationContext;
58  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTextSearchDictionaryContext;
59  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTextSearchParserContext;
60  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTextSearchTemplateContext;
61  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTriggerContext;
62  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTypeContext;
63  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterViewContext;
64  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.BackwardAllContext;
65  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.BackwardContext;
66  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.BackwardCountContext;
67  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CloseContext;
68  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ClusterContext;
69  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ColumnConstraintContext;
70  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ColumnDefinitionContext;
71  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CommentContext;
72  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CountContext;
73  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateAccessMethodContext;
74  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateAggregateContext;
75  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateCastContext;
76  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateCollationContext;
77  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateConversionContext;
78  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateDatabaseContext;
79  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateDefinitionClauseContext;
80  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateDefinitionContext;
81  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateDomainContext;
82  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateEventTriggerContext;
83  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateExtensionContext;
84  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateForeignDataWrapperContext;
85  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateForeignTableContext;
86  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateFunctionContext;
87  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateIndexContext;
88  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateLanguageContext;
89  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateMaterializedViewContext;
90  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateOperatorContext;
91  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreatePolicyContext;
92  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateProcedureContext;
93  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreatePublicationContext;
94  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateRuleContext;
95  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateSchemaContext;
96  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateSequenceContext;
97  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateTableContext;
98  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateTablespaceContext;
99  import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateTextSearchContext;
100 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateTypeContext;
101 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateViewContext;
102 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CursorNameContext;
103 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DeallocateContext;
104 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DeclareContext;
105 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DiscardContext;
106 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropAccessMethodContext;
107 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropAggregateContext;
108 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropCastContext;
109 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropCollationContext;
110 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropColumnSpecificationContext;
111 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropConstraintSpecificationContext;
112 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropConversionContext;
113 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropDatabaseContext;
114 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropDomainContext;
115 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropEventTriggerContext;
116 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropExtensionContext;
117 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropForeignDataWrapperContext;
118 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropForeignTableContext;
119 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropFunctionContext;
120 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropGroupContext;
121 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropIndexContext;
122 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropLanguageContext;
123 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropMaterializedViewContext;
124 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropOperatorClassContext;
125 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropOperatorContext;
126 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropOperatorFamilyContext;
127 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropOwnedContext;
128 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropPolicyContext;
129 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropProcedureContext;
130 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropPublicationContext;
131 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropRoutineContext;
132 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropRuleContext;
133 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropSchemaContext;
134 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropSequenceContext;
135 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropServerContext;
136 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropStatisticsContext;
137 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropSubscriptionContext;
138 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropTableContext;
139 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropTablespaceContext;
140 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropTextSearchContext;
141 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropTriggerContext;
142 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropTypeContext;
143 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropViewContext;
144 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.FetchContext;
145 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.FirstContext;
146 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ForwardAllContext;
147 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ForwardContext;
148 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ForwardCountContext;
149 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.FuncArgExprContext;
150 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.FunctionExprWindowlessContext;
151 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.IndexElemContext;
152 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.IndexNameContext;
153 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.IndexNamesContext;
154 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.IndexParamsContext;
155 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.LastContext;
156 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ListenContext;
157 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ModifyColumnSpecificationContext;
158 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ModifyConstraintSpecificationContext;
159 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.MoveContext;
160 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NameContext;
161 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NameListContext;
162 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NextContext;
163 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NotifyStmtContext;
164 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.OpenContext;
165 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.PrepareContext;
166 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.PriorContext;
167 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.RefreshMatViewStmtContext;
168 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ReindexContext;
169 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.RelativeCountContext;
170 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.RenameColumnSpecificationContext;
171 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.RenameTableSpecificationContext;
172 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.SecurityLabelStmtContext;
173 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.TableConstraintContext;
174 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.TableConstraintUsingIndexContext;
175 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.TableNameClauseContext;
176 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.TableNamesClauseContext;
177 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.TruncateTableContext;
178 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.UnlistenContext;
179 import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ValidateConstraintSpecificationContext;
180 import org.apache.shardingsphere.sql.parser.postgresql.visitor.statement.PostgreSQLStatementVisitor;
181 import org.apache.shardingsphere.sql.parser.statement.core.enums.DirectionType;
182 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.AlterDefinitionSegment;
183 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.CreateDefinitionSegment;
184 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.ColumnDefinitionSegment;
185 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.alter.AddColumnDefinitionSegment;
186 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.alter.DropColumnDefinitionSegment;
187 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.alter.ModifyColumnDefinitionSegment;
188 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.alter.RenameColumnSegment;
189 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.ConstraintDefinitionSegment;
190 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.ConstraintSegment;
191 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.alter.AddConstraintDefinitionSegment;
192 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.alter.DropConstraintDefinitionSegment;
193 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.alter.ModifyConstraintDefinitionSegment;
194 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.alter.ValidateConstraintDefinitionSegment;
195 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.cursor.CursorNameSegment;
196 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.cursor.DirectionSegment;
197 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexNameSegment;
198 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
199 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.table.RenameTableDefinitionSegment;
200 import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
201 import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment;
202 import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.FunctionSegment;
203 import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DataTypeSegment;
204 import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.NameSegment;
205 import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment;
206 import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
207 import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
208 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.CloseStatement;
209 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.CommentStatement;
210 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.CreateCollationStatement;
211 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.DeallocateStatement;
212 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.FetchStatement;
213 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.MoveStatement;
214 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.PrepareStatement;
215 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.TruncateStatement;
216 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.database.CreateDatabaseStatement;
217 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.database.DropDatabaseStatement;
218 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.domain.AlterDomainStatement;
219 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.domain.CreateDomainStatement;
220 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.function.AlterFunctionStatement;
221 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.function.CreateFunctionStatement;
222 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.function.DropFunctionStatement;
223 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index.AlterIndexStatement;
224 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index.CreateIndexStatement;
225 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index.DropIndexStatement;
226 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.operator.AlterOperatorStatement;
227 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.operator.CreateOperatorStatement;
228 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.operator.DropOperatorStatement;
229 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.procedure.AlterProcedureStatement;
230 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.procedure.CreateProcedureStatement;
231 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.procedure.DropProcedureStatement;
232 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.schema.AlterSchemaStatement;
233 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.schema.CreateSchemaStatement;
234 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.schema.DropSchemaStatement;
235 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.sequence.AlterSequenceStatement;
236 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.sequence.CreateSequenceStatement;
237 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.sequence.DropSequenceStatement;
238 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.server.AlterServerStatement;
239 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.server.DropServerStatement;
240 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.AlterTableStatement;
241 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.CreateTableStatement;
242 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.DropTableStatement;
243 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.tablespace.AlterTablespaceStatement;
244 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.tablespace.CreateTablespaceStatement;
245 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.tablespace.DropTablespaceStatement;
246 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.trigger.AlterTriggerStatement;
247 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.trigger.DropTriggerStatement;
248 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.type.AlterTypeStatement;
249 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.type.CreateTypeStatement;
250 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.view.AlterMaterializedViewStatement;
251 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.view.AlterViewStatement;
252 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.view.CreateMaterializedViewStatement;
253 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.view.CreateViewStatement;
254 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.view.DropMaterializedViewStatement;
255 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.view.DropViewStatement;
256 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.view.RefreshMatViewStmtStatement;
257 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.DeleteStatement;
258 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.InsertStatement;
259 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.SelectStatement;
260 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.UpdateStatement;
261 import org.apache.shardingsphere.sql.parser.statement.core.value.collection.CollectionValue;
262 import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
263 import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.NumberLiteralValue;
264 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.PostgreSQLAlterDefaultPrivilegesStatement;
265 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.PostgreSQLClusterStatement;
266 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.PostgreSQLDeclareStatement;
267 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.PostgreSQLDiscardStatement;
268 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.PostgreSQLDropDomainStatement;
269 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.PostgreSQLDropOperatorClassStatement;
270 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.PostgreSQLDropOperatorFamilyStatement;
271 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.PostgreSQLDropOwnedStatement;
272 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.PostgreSQLDropTypeStatement;
273 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.PostgreSQLListenStatement;
274 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.PostgreSQLNotifyStmtStatement;
275 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.PostgreSQLOpenStatement;
276 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.PostgreSQLReindexStatement;
277 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.PostgreSQLSecurityLabelStmtStatement;
278 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.PostgreSQLUnlistenStatement;
279 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.accessmethod.PostgreSQLCreateAccessMethodStatement;
280 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.accessmethod.PostgreSQLDropAccessMethodStatement;
281 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.aggregate.PostgreSQLAlterAggregateStatement;
282 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.aggregate.PostgreSQLCreateAggregateStatement;
283 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.aggregate.PostgreSQLDropAggregateStatement;
284 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.cast.PostgreSQLCreateCastStatement;
285 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.cast.PostgreSQLDropCastStatement;
286 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.collation.PostgreSQLAlterCollationStatement;
287 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.collation.PostgreSQLDropCollationStatement;
288 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.conversion.PostgreSQLAlterConversionStatement;
289 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.conversion.PostgreSQLCreateConversionStatement;
290 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.conversion.PostgreSQLDropConversionStatement;
291 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.event.PostgreSQLCreateEventTriggerStatement;
292 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.event.PostgreSQLDropEventTriggerStatement;
293 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.extension.PostgreSQLAlterExtensionStatement;
294 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.extension.PostgreSQLCreateExtensionStatement;
295 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.extension.PostgreSQLDropExtensionStatement;
296 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.foreigndata.PostgreSQLAlterForeignDataWrapperStatement;
297 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.foreigndata.PostgreSQLCreateForeignDataWrapperStatement;
298 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.foreigndata.PostgreSQLDropForeignDataWrapperStatement;
299 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.foreigntable.PostgreSQLAlterForeignTableStatement;
300 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.foreigntable.PostgreSQLCreateForeignTableStatement;
301 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.foreigntable.PostgreSQLDropForeignTableStatement;
302 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.group.PostgreSQLAlterGroupStatement;
303 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.group.PostgreSQLDropGroupStatement;
304 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.language.PostgreSQLAlterLanguageStatement;
305 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.language.PostgreSQLCreateLanguageStatement;
306 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.language.PostgreSQLDropLanguageStatement;
307 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.policy.PostgreSQLAlterPolicyStatement;
308 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.policy.PostgreSQLCreatePolicyStatement;
309 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.policy.PostgreSQLDropPolicyStatement;
310 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.publication.PostgreSQLAlterPublicationStatement;
311 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.publication.PostgreSQLCreatePublicationStatement;
312 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.publication.PostgreSQLDropPublicationStatement;
313 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.routine.PostgreSQLAlterRoutineStatement;
314 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.routine.PostgreSQLDropRoutineStatement;
315 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.rule.PostgreSQLAlterRuleStatement;
316 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.rule.PostgreSQLCreateRuleStatement;
317 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.rule.PostgreSQLDropRuleStatement;
318 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.statistics.PostgreSQLAlterStatisticsStatement;
319 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.statistics.PostgreSQLDropStatisticsStatement;
320 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.subscription.PostgreSQLAlterSubscriptionStatement;
321 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.subscription.PostgreSQLDropSubscriptionStatement;
322 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.textsearch.PostgreSQLAlterTextSearchStatement;
323 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.textsearch.PostgreSQLCreateTextSearchStatement;
324 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.textsearch.PostgreSQLDropTextSearchStatement;
325 
326 import java.util.ArrayList;
327 import java.util.Collection;
328 import java.util.Collections;
329 import java.util.Iterator;
330 import java.util.LinkedList;
331 import java.util.Optional;
332 import java.util.stream.Collectors;
333 
334 /**
335  * DDL statement visitor for PostgreSQL.
336  */
337 public final class PostgreSQLDDLStatementVisitor extends PostgreSQLStatementVisitor implements DDLStatementVisitor {
338     
339     @SuppressWarnings("unchecked")
340     @Override
341     public ASTNode visitCreateTable(final CreateTableContext ctx) {
342         CreateTableStatement result = new CreateTableStatement();
343         result.setTable((SimpleTableSegment) visit(ctx.tableName()));
344         result.setIfNotExists(null != ctx.ifNotExists());
345         if (null != ctx.createDefinitionClause()) {
346             CollectionValue<CreateDefinitionSegment> createDefinitions = (CollectionValue<CreateDefinitionSegment>) visit(ctx.createDefinitionClause());
347             for (CreateDefinitionSegment each : createDefinitions.getValue()) {
348                 if (each instanceof ColumnDefinitionSegment) {
349                     result.getColumnDefinitions().add((ColumnDefinitionSegment) each);
350                 } else if (each instanceof ConstraintDefinitionSegment) {
351                     result.getConstraintDefinitions().add((ConstraintDefinitionSegment) each);
352                 }
353             }
354         }
355         return result;
356     }
357     
358     @Override
359     public ASTNode visitCreateDefinitionClause(final CreateDefinitionClauseContext ctx) {
360         CollectionValue<CreateDefinitionSegment> result = new CollectionValue<>();
361         for (CreateDefinitionContext each : ctx.createDefinition()) {
362             if (null != each.columnDefinition()) {
363                 result.getValue().add((ColumnDefinitionSegment) visit(each.columnDefinition()));
364             }
365             if (null != each.tableConstraint()) {
366                 result.getValue().add((ConstraintDefinitionSegment) visit(each.tableConstraint()));
367             }
368         }
369         return result;
370     }
371     
372     @SuppressWarnings("unchecked")
373     @Override
374     public ASTNode visitAlterTable(final AlterTableContext ctx) {
375         AlterTableStatement result = new AlterTableStatement();
376         result.setTable((SimpleTableSegment) visit(ctx.tableNameClause().tableName()));
377         if (null != ctx.alterDefinitionClause()) {
378             for (AlterDefinitionSegment each : ((CollectionValue<AlterDefinitionSegment>) visit(ctx.alterDefinitionClause())).getValue()) {
379                 if (each instanceof AddColumnDefinitionSegment) {
380                     result.getAddColumnDefinitions().add((AddColumnDefinitionSegment) each);
381                 } else if (each instanceof ModifyColumnDefinitionSegment) {
382                     result.getModifyColumnDefinitions().add((ModifyColumnDefinitionSegment) each);
383                 } else if (each instanceof DropColumnDefinitionSegment) {
384                     result.getDropColumnDefinitions().add((DropColumnDefinitionSegment) each);
385                 } else if (each instanceof AddConstraintDefinitionSegment) {
386                     result.getAddConstraintDefinitions().add((AddConstraintDefinitionSegment) each);
387                 } else if (each instanceof ValidateConstraintDefinitionSegment) {
388                     result.getValidateConstraintDefinitions().add((ValidateConstraintDefinitionSegment) each);
389                 } else if (each instanceof ModifyConstraintDefinitionSegment) {
390                     result.getModifyConstraintDefinitions().add((ModifyConstraintDefinitionSegment) each);
391                 } else if (each instanceof DropConstraintDefinitionSegment) {
392                     result.getDropConstraintDefinitions().add((DropConstraintDefinitionSegment) each);
393                 } else if (each instanceof RenameTableDefinitionSegment) {
394                     result.setRenameTable(((RenameTableDefinitionSegment) each).getRenameTable());
395                 } else if (each instanceof RenameColumnSegment) {
396                     result.getRenameColumnDefinitions().add((RenameColumnSegment) each);
397                 }
398             }
399         }
400         return result;
401     }
402     
403     @Override
404     public ASTNode visitAlterAggregate(final AlterAggregateContext ctx) {
405         return new PostgreSQLAlterAggregateStatement();
406     }
407     
408     @Override
409     public ASTNode visitAlterCollation(final AlterCollationContext ctx) {
410         return new PostgreSQLAlterCollationStatement();
411     }
412     
413     @Override
414     public ASTNode visitAlterDefaultPrivileges(final AlterDefaultPrivilegesContext ctx) {
415         return new PostgreSQLAlterDefaultPrivilegesStatement();
416     }
417     
418     @Override
419     public ASTNode visitAlterForeignDataWrapper(final AlterForeignDataWrapperContext ctx) {
420         return new PostgreSQLAlterForeignDataWrapperStatement();
421     }
422     
423     @Override
424     public ASTNode visitAlterDefinitionClause(final AlterDefinitionClauseContext ctx) {
425         CollectionValue<AlterDefinitionSegment> result = new CollectionValue<>();
426         if (null != ctx.alterTableActions()) {
427             result.getValue().addAll(ctx.alterTableActions().alterTableAction().stream().flatMap(each -> getAlterDefinitionSegments(each).stream()).collect(Collectors.toList()));
428         }
429         if (null != ctx.renameColumnSpecification()) {
430             result.getValue().add((RenameColumnSegment) visit(ctx.renameColumnSpecification()));
431         }
432         if (null != ctx.renameTableSpecification()) {
433             result.getValue().add((RenameTableDefinitionSegment) visit(ctx.renameTableSpecification()));
434         }
435         return result;
436     }
437     
438     @SuppressWarnings("unchecked")
439     private Collection<AlterDefinitionSegment> getAlterDefinitionSegments(final AlterTableActionContext ctx) {
440         Collection<AlterDefinitionSegment> result = new LinkedList<>();
441         if (null != ctx.addColumnSpecification()) {
442             result.addAll(((CollectionValue<AddColumnDefinitionSegment>) visit(ctx.addColumnSpecification())).getValue());
443         }
444         if (null != ctx.addConstraintSpecification() && null != ctx.addConstraintSpecification().tableConstraint()) {
445             result.add((AddConstraintDefinitionSegment) visit(ctx.addConstraintSpecification()));
446         }
447         if (null != ctx.validateConstraintSpecification()) {
448             result.add((ValidateConstraintDefinitionSegment) visit(ctx.validateConstraintSpecification()));
449         }
450         if (null != ctx.modifyColumnSpecification()) {
451             result.add((ModifyColumnDefinitionSegment) visit(ctx.modifyColumnSpecification()));
452         }
453         if (null != ctx.modifyConstraintSpecification()) {
454             result.add((ModifyConstraintDefinitionSegment) visit(ctx.modifyConstraintSpecification()));
455         }
456         if (null != ctx.dropColumnSpecification()) {
457             result.add((DropColumnDefinitionSegment) visit(ctx.dropColumnSpecification()));
458         }
459         if (null != ctx.dropConstraintSpecification()) {
460             result.add((DropConstraintDefinitionSegment) visit(ctx.dropConstraintSpecification()));
461         }
462         return result;
463     }
464     
465     @Override
466     public ASTNode visitAlterForeignTable(final AlterForeignTableContext ctx) {
467         return new PostgreSQLAlterForeignTableStatement();
468     }
469     
470     @Override
471     public ASTNode visitDropForeignTable(final DropForeignTableContext ctx) {
472         return new PostgreSQLDropForeignTableStatement();
473     }
474     
475     @Override
476     public ASTNode visitAlterGroup(final AlterGroupContext ctx) {
477         return new PostgreSQLAlterGroupStatement();
478     }
479     
480     @Override
481     public ASTNode visitAlterMaterializedView(final AlterMaterializedViewContext ctx) {
482         return new AlterMaterializedViewStatement();
483     }
484     
485     @Override
486     public ASTNode visitAlterOperator(final AlterOperatorContext ctx) {
487         return new AlterOperatorStatement();
488     }
489     
490     @Override
491     public ASTNode visitAddConstraintSpecification(final AddConstraintSpecificationContext ctx) {
492         return new AddConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ConstraintDefinitionSegment) visit(ctx.tableConstraint()));
493     }
494     
495     @Override
496     public ASTNode visitValidateConstraintSpecification(final ValidateConstraintSpecificationContext ctx) {
497         return new ValidateConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ConstraintSegment) visit(ctx.constraintName()));
498     }
499     
500     @Override
501     public ASTNode visitModifyConstraintSpecification(final ModifyConstraintSpecificationContext ctx) {
502         return new ModifyConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ConstraintSegment) visit(ctx.constraintName()));
503     }
504     
505     @Override
506     public ASTNode visitDropConstraintSpecification(final DropConstraintSpecificationContext ctx) {
507         return new DropConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ConstraintSegment) visit(ctx.constraintName()));
508     }
509     
510     @Override
511     public ASTNode visitAlterDomain(final AlterDomainContext ctx) {
512         return new AlterDomainStatement();
513     }
514     
515     @Override
516     public ASTNode visitAlterPolicy(final AlterPolicyContext ctx) {
517         return new PostgreSQLAlterPolicyStatement();
518     }
519     
520     @Override
521     public ASTNode visitAlterPublication(final AlterPublicationContext ctx) {
522         return new PostgreSQLAlterPublicationStatement();
523     }
524     
525     @Override
526     public ASTNode visitAlterSubscription(final AlterSubscriptionContext ctx) {
527         return new PostgreSQLAlterSubscriptionStatement();
528     }
529     
530     @Override
531     public ASTNode visitAlterTrigger(final AlterTriggerContext ctx) {
532         return new AlterTriggerStatement();
533     }
534     
535     @Override
536     public ASTNode visitAlterType(final AlterTypeContext ctx) {
537         return new AlterTypeStatement();
538     }
539     
540     @Override
541     public ASTNode visitRenameTableSpecification(final RenameTableSpecificationContext ctx) {
542         RenameTableDefinitionSegment result = new RenameTableDefinitionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
543         TableNameSegment tableName = new TableNameSegment(ctx.identifier().start.getStartIndex(), ctx.identifier().stop.getStopIndex(), (IdentifierValue) visit(ctx.identifier()));
544         result.setRenameTable(new SimpleTableSegment(tableName));
545         return result;
546     }
547     
548     @Override
549     public ASTNode visitAddColumnSpecification(final AddColumnSpecificationContext ctx) {
550         CollectionValue<AddColumnDefinitionSegment> result = new CollectionValue<>();
551         ColumnDefinitionContext columnDefinition = ctx.columnDefinition();
552         if (null != columnDefinition) {
553             AddColumnDefinitionSegment addColumnDefinition = new AddColumnDefinitionSegment(
554                     ctx.columnDefinition().getStart().getStartIndex(), columnDefinition.getStop().getStopIndex(), Collections.singleton((ColumnDefinitionSegment) visit(columnDefinition)));
555             result.getValue().add(addColumnDefinition);
556         }
557         return result;
558     }
559     
560     @Override
561     public ASTNode visitColumnDefinition(final ColumnDefinitionContext ctx) {
562         ColumnSegment column = (ColumnSegment) visit(ctx.columnName());
563         DataTypeSegment dataType = (DataTypeSegment) visit(ctx.dataType());
564         boolean isPrimaryKey = ctx.columnConstraint().stream().anyMatch(each -> null != each.columnConstraintOption() && null != each.columnConstraintOption().primaryKey());
565         // TODO parse not null
566         ColumnDefinitionSegment result = new ColumnDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), column, dataType, isPrimaryKey, false, getText(ctx));
567         for (ColumnConstraintContext each : ctx.columnConstraint()) {
568             if (null != each.columnConstraintOption().tableName()) {
569                 result.getReferencedTables().add((SimpleTableSegment) visit(each.columnConstraintOption().tableName()));
570             }
571         }
572         return result;
573     }
574     
575     private String getText(final ParserRuleContext ctx) {
576         return ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
577     }
578     
579     @Override
580     public ASTNode visitTableConstraintUsingIndex(final TableConstraintUsingIndexContext ctx) {
581         ConstraintDefinitionSegment result = new ConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex());
582         if (null != ctx.constraintName()) {
583             result.setConstraintName((ConstraintSegment) visit(ctx.constraintName()));
584         }
585         if (null != ctx.indexName()) {
586             result.setIndexName((IndexSegment) visit(ctx.indexName()));
587         }
588         return result;
589     }
590     
591     @SuppressWarnings("unchecked")
592     @Override
593     public ASTNode visitTableConstraint(final TableConstraintContext ctx) {
594         ConstraintDefinitionSegment result = new ConstraintDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex());
595         if (null != ctx.constraintClause()) {
596             result.setConstraintName((ConstraintSegment) visit(ctx.constraintClause().constraintName()));
597         }
598         if (null != ctx.tableConstraintOption().primaryKey()) {
599             result.getPrimaryKeyColumns().addAll(((CollectionValue<ColumnSegment>) visit(ctx.tableConstraintOption().columnNames(0))).getValue());
600         }
601         if (null != ctx.tableConstraintOption().FOREIGN()) {
602             result.setReferencedTable((SimpleTableSegment) visit(ctx.tableConstraintOption().tableName()));
603         }
604         return result;
605     }
606     
607     @Override
608     public ASTNode visitModifyColumnSpecification(final ModifyColumnSpecificationContext ctx) {
609         // TODO visit pk and table ref
610         ColumnSegment column = (ColumnSegment) visit(ctx.modifyColumn().columnName());
611         DataTypeSegment dataType = null == ctx.dataType() ? null : (DataTypeSegment) visit(ctx.dataType());
612         ColumnDefinitionSegment columnDefinition = new ColumnDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), column, dataType, false, false, getText(ctx));
613         return new ModifyColumnDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), columnDefinition);
614     }
615     
616     @Override
617     public ASTNode visitDropColumnSpecification(final DropColumnSpecificationContext ctx) {
618         return new DropColumnDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), Collections.singleton((ColumnSegment) visit(ctx.columnName())));
619     }
620     
621     @Override
622     public ASTNode visitRenameColumnSpecification(final RenameColumnSpecificationContext ctx) {
623         return new RenameColumnSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ColumnSegment) visit(ctx.columnName(0)), (ColumnSegment) visit(ctx.columnName(1)));
624     }
625     
626     @SuppressWarnings("unchecked")
627     @Override
628     public ASTNode visitDropTable(final DropTableContext ctx) {
629         boolean containsCascade = null != ctx.dropTableOpt() && null != ctx.dropTableOpt().CASCADE();
630         DropTableStatement result = new DropTableStatement();
631         result.setIfExists(null != ctx.ifExists());
632         result.setContainsCascade(containsCascade);
633         result.getTables().addAll(((CollectionValue<SimpleTableSegment>) visit(ctx.tableNames())).getValue());
634         return result;
635     }
636     
637     @SuppressWarnings("unchecked")
638     @Override
639     public ASTNode visitTruncateTable(final TruncateTableContext ctx) {
640         return new TruncateStatement(((CollectionValue<SimpleTableSegment>) visit(ctx.tableNamesClause())).getValue());
641     }
642     
643     @Override
644     public ASTNode visitDropPolicy(final DropPolicyContext ctx) {
645         return new PostgreSQLDropPolicyStatement();
646     }
647     
648     @Override
649     public ASTNode visitDropRule(final DropRuleContext ctx) {
650         return new PostgreSQLDropRuleStatement();
651     }
652     
653     @Override
654     public ASTNode visitDropStatistics(final DropStatisticsContext ctx) {
655         return new PostgreSQLDropStatisticsStatement();
656     }
657     
658     @Override
659     public ASTNode visitDropPublication(final DropPublicationContext ctx) {
660         return new PostgreSQLDropPublicationStatement();
661     }
662     
663     @Override
664     public ASTNode visitDropSubscription(final DropSubscriptionContext ctx) {
665         return new PostgreSQLDropSubscriptionStatement();
666     }
667     
668     @SuppressWarnings("unchecked")
669     @Override
670     public ASTNode visitCreateIndex(final CreateIndexContext ctx) {
671         CreateIndexStatement result = new CreateIndexStatement();
672         result.setIfNotExists(null != ctx.ifNotExists());
673         result.setTable((SimpleTableSegment) visit(ctx.tableName()));
674         result.getColumns().addAll(((CollectionValue<ColumnSegment>) visit(ctx.indexParams())).getValue());
675         if (null != ctx.indexName()) {
676             result.setIndex((IndexSegment) visit(ctx.indexName()));
677         } else {
678             result.setGeneratedIndexStartIndex(ctx.ON().getSymbol().getStartIndex() - 1);
679         }
680         return result;
681     }
682     
683     @Override
684     public ASTNode visitIndexParams(final IndexParamsContext ctx) {
685         CollectionValue<ColumnSegment> result = new CollectionValue<>();
686         for (IndexElemContext each : ctx.indexElem()) {
687             if (null != each.colId()) {
688                 result.getValue().add(new ColumnSegment(each.colId().start.getStartIndex(), each.colId().stop.getStopIndex(), new IdentifierValue(each.colId().getText())));
689             }
690             if (null != each.functionExprWindowless()) {
691                 FunctionSegment functionSegment = (FunctionSegment) visit(each.functionExprWindowless());
692                 functionSegment.getParameters().forEach(param -> {
693                     if (param instanceof ColumnSegment) {
694                         result.getValue().add((ColumnSegment) param);
695                     }
696                 });
697             }
698         }
699         return result;
700     }
701     
702     @Override
703     public ASTNode visitFunctionExprWindowless(final FunctionExprWindowlessContext ctx) {
704         FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.funcApplication().funcName().getText(), getOriginalText(ctx));
705         result.getParameters().addAll(getExpressions(ctx.funcApplication().funcArgList().funcArgExpr()));
706         return result;
707     }
708     
709     private Collection<ExpressionSegment> getExpressions(final Collection<FuncArgExprContext> aExprContexts) {
710         if (null == aExprContexts) {
711             return Collections.emptyList();
712         }
713         Collection<ExpressionSegment> result = new ArrayList<>(aExprContexts.size());
714         for (FuncArgExprContext each : aExprContexts) {
715             result.add((ExpressionSegment) visit(each.aExpr()));
716         }
717         return result;
718     }
719     
720     @Override
721     public ASTNode visitAlterIndex(final AlterIndexContext ctx) {
722         AlterIndexStatement result = new AlterIndexStatement();
723         result.setIndex(createIndexSegment((SimpleTableSegment) visit(ctx.qualifiedName())));
724         if (null != ctx.alterIndexDefinitionClause().renameIndexSpecification()) {
725             result.setRenameIndex((IndexSegment) visit(ctx.alterIndexDefinitionClause().renameIndexSpecification().indexName()));
726         }
727         return result;
728     }
729     
730     private IndexSegment createIndexSegment(final SimpleTableSegment tableSegment) {
731         IndexNameSegment indexName = new IndexNameSegment(tableSegment.getTableName().getStartIndex(), tableSegment.getTableName().getStopIndex(), tableSegment.getTableName().getIdentifier());
732         IndexSegment result = new IndexSegment(tableSegment.getStartIndex(), tableSegment.getStopIndex(), indexName);
733         tableSegment.getOwner().ifPresent(result::setOwner);
734         return result;
735     }
736     
737     @SuppressWarnings("unchecked")
738     @Override
739     public ASTNode visitDropIndex(final DropIndexContext ctx) {
740         DropIndexStatement result = new DropIndexStatement();
741         result.setIfExists(null != ctx.ifExists());
742         result.getIndexes().addAll(createIndexSegments(((CollectionValue<SimpleTableSegment>) visit(ctx.qualifiedNameList())).getValue()));
743         return result;
744     }
745     
746     private Collection<IndexSegment> createIndexSegments(final Collection<SimpleTableSegment> tableSegments) {
747         Collection<IndexSegment> result = new LinkedList<>();
748         for (SimpleTableSegment each : tableSegments) {
749             result.add(createIndexSegment(each));
750         }
751         return result;
752     }
753     
754     @Override
755     public ASTNode visitIndexNames(final IndexNamesContext ctx) {
756         CollectionValue<IndexSegment> result = new CollectionValue<>();
757         for (IndexNameContext each : ctx.indexName()) {
758             result.getValue().add((IndexSegment) visit(each));
759         }
760         return result;
761     }
762     
763     @Override
764     public ASTNode visitTableNameClause(final TableNameClauseContext ctx) {
765         return visit(ctx.tableName());
766     }
767     
768     @Override
769     public ASTNode visitTableNamesClause(final TableNamesClauseContext ctx) {
770         Collection<SimpleTableSegment> tableSegments = new LinkedList<>();
771         for (int i = 0; i < ctx.tableNameClause().size(); i++) {
772             tableSegments.add((SimpleTableSegment) visit(ctx.tableNameClause(i)));
773         }
774         CollectionValue<SimpleTableSegment> result = new CollectionValue<>();
775         result.getValue().addAll(tableSegments);
776         return result;
777     }
778     
779     @Override
780     public ASTNode visitAlterFunction(final AlterFunctionContext ctx) {
781         return new AlterFunctionStatement();
782     }
783     
784     @Override
785     public ASTNode visitAlterProcedure(final AlterProcedureContext ctx) {
786         return new AlterProcedureStatement();
787     }
788     
789     @Override
790     public ASTNode visitCreateFunction(final CreateFunctionContext ctx) {
791         return new CreateFunctionStatement();
792     }
793     
794     @Override
795     public ASTNode visitCreateProcedure(final CreateProcedureContext ctx) {
796         return new CreateProcedureStatement();
797     }
798     
799     @Override
800     public ASTNode visitDropFunction(final DropFunctionContext ctx) {
801         return new DropFunctionStatement();
802     }
803     
804     @Override
805     public ASTNode visitDropGroup(final DropGroupContext ctx) {
806         return new PostgreSQLDropGroupStatement();
807     }
808     
809     @SuppressWarnings("unchecked")
810     @Override
811     public ASTNode visitDropView(final DropViewContext ctx) {
812         DropViewStatement result = new DropViewStatement();
813         result.setIfExists(null != ctx.ifExists());
814         result.getViews().addAll(((CollectionValue<SimpleTableSegment>) visit(ctx.qualifiedNameList())).getValue());
815         return result;
816     }
817     
818     @Override
819     public ASTNode visitCreateView(final CreateViewContext ctx) {
820         CreateViewStatement result = new CreateViewStatement();
821         result.setReplaceView(null != ctx.REPLACE());
822         result.setView((SimpleTableSegment) visit(ctx.qualifiedName()));
823         result.setViewDefinition(getOriginalText(ctx.select()));
824         result.setSelect((SelectStatement) visit(ctx.select()));
825         return result;
826     }
827     
828     @Override
829     public ASTNode visitAlterView(final AlterViewContext ctx) {
830         AlterViewStatement result = new AlterViewStatement();
831         result.setView((SimpleTableSegment) visit(ctx.qualifiedName()));
832         if (ctx.alterViewClauses() instanceof AlterRenameViewContext) {
833             NameContext nameContext = ((AlterRenameViewContext) ctx.alterViewClauses()).name();
834             result.setRenameView(new SimpleTableSegment(new TableNameSegment(nameContext.getStart().getStartIndex(),
835                     nameContext.getStop().getStopIndex(), (IdentifierValue) visit(nameContext.identifier()))));
836         }
837         return result;
838     }
839     
840     @Override
841     public ASTNode visitDropDatabase(final DropDatabaseContext ctx) {
842         return new DropDatabaseStatement(((IdentifierValue) visit(ctx.name())).getValue(), null != ctx.ifExists());
843     }
844     
845     @Override
846     public ASTNode visitAlterRoutine(final AlterRoutineContext ctx) {
847         return new PostgreSQLAlterRoutineStatement();
848     }
849     
850     @Override
851     public ASTNode visitAlterRule(final AlterRuleContext ctx) {
852         return new PostgreSQLAlterRuleStatement();
853     }
854     
855     @Override
856     public ASTNode visitDropProcedure(final DropProcedureContext ctx) {
857         return new DropProcedureStatement();
858     }
859     
860     @Override
861     public ASTNode visitDropRoutine(final DropRoutineContext ctx) {
862         return new PostgreSQLDropRoutineStatement();
863     }
864     
865     @Override
866     public ASTNode visitCreateDatabase(final CreateDatabaseContext ctx) {
867         return new CreateDatabaseStatement(((IdentifierValue) visit(ctx.name())).getValue(), false);
868     }
869     
870     @Override
871     public ASTNode visitCreateSequence(final CreateSequenceContext ctx) {
872         return new CreateSequenceStatement(((SimpleTableSegment) visit(ctx.qualifiedName())).getTableName().getIdentifier().getValue());
873     }
874     
875     @Override
876     public ASTNode visitAlterSequence(final AlterSequenceContext ctx) {
877         return new AlterSequenceStatement(((SimpleTableSegment) visit(ctx.qualifiedName())).getTableName().getIdentifier().getValue());
878     }
879     
880     @SuppressWarnings({"unchecked", "rawtypes"})
881     @Override
882     public ASTNode visitDropSequence(final DropSequenceContext ctx) {
883         return new DropSequenceStatement(((CollectionValue) visit(ctx.qualifiedNameList())).getValue());
884     }
885     
886     @Override
887     public ASTNode visitPrepare(final PrepareContext ctx) {
888         PrepareStatement result = new PrepareStatement();
889         if (null != ctx.preparableStmt().select()) {
890             result.setSelect((SelectStatement) visit(ctx.preparableStmt().select()));
891         }
892         if (null != ctx.preparableStmt().insert()) {
893             result.setInsert((InsertStatement) visit(ctx.preparableStmt().insert()));
894         }
895         if (null != ctx.preparableStmt().update()) {
896             result.setUpdate((UpdateStatement) visit(ctx.preparableStmt().update()));
897         }
898         if (null != ctx.preparableStmt().delete()) {
899             result.setDelete((DeleteStatement) visit(ctx.preparableStmt().delete()));
900         }
901         return result;
902     }
903     
904     @Override
905     public ASTNode visitDeallocate(final DeallocateContext ctx) {
906         return new DeallocateStatement();
907     }
908     
909     @Override
910     public ASTNode visitDropCast(final DropCastContext ctx) {
911         return new PostgreSQLDropCastStatement();
912     }
913     
914     @Override
915     public ASTNode visitCreateTablespace(final CreateTablespaceContext ctx) {
916         return new CreateTablespaceStatement();
917     }
918     
919     @Override
920     public ASTNode visitAlterTablespace(final AlterTablespaceContext ctx) {
921         return new AlterTablespaceStatement(null, null);
922     }
923     
924     @Override
925     public ASTNode visitDropTablespace(final DropTablespaceContext ctx) {
926         return new DropTablespaceStatement();
927     }
928     
929     @Override
930     public ASTNode visitDropTextSearch(final DropTextSearchContext ctx) {
931         return new PostgreSQLDropTextSearchStatement();
932     }
933     
934     @Override
935     public ASTNode visitDropDomain(final DropDomainContext ctx) {
936         return new PostgreSQLDropDomainStatement();
937     }
938     
939     @Override
940     public ASTNode visitCreateDomain(final CreateDomainContext ctx) {
941         return new CreateDomainStatement();
942     }
943     
944     @Override
945     public ASTNode visitCreateRule(final CreateRuleContext ctx) {
946         return new PostgreSQLCreateRuleStatement();
947     }
948     
949     @Override
950     public ASTNode visitCreateLanguage(final CreateLanguageContext ctx) {
951         return new PostgreSQLCreateLanguageStatement();
952     }
953     
954     @Override
955     public ASTNode visitCreateSchema(final CreateSchemaContext ctx) {
956         CreateSchemaStatement result = new CreateSchemaStatement();
957         if (null != ctx.createSchemaClauses().colId()) {
958             result.setSchemaName(new IdentifierValue(ctx.createSchemaClauses().colId().getText()));
959         }
960         if (null != ctx.createSchemaClauses().roleSpec() && null != ctx.createSchemaClauses().roleSpec().identifier()) {
961             result.setUsername((IdentifierValue) visit(ctx.createSchemaClauses().roleSpec().identifier()));
962         }
963         return result;
964     }
965     
966     @Override
967     public ASTNode visitAlterSchema(final AlterSchemaContext ctx) {
968         AlterSchemaStatement result = new AlterSchemaStatement();
969         result.setSchemaName((IdentifierValue) visit(ctx.name().get(0)));
970         if (ctx.name().size() > 1) {
971             result.setRenameSchema((IdentifierValue) visit(ctx.name().get(1)));
972         }
973         return result;
974     }
975     
976     @SuppressWarnings("unchecked")
977     @Override
978     public ASTNode visitDropSchema(final DropSchemaContext ctx) {
979         DropSchemaStatement result = new DropSchemaStatement();
980         result.getSchemaNames().addAll(((CollectionValue<IdentifierValue>) visit(ctx.nameList())).getValue());
981         result.setContainsCascade(null != ctx.dropBehavior() && null != ctx.dropBehavior().CASCADE());
982         return result;
983     }
984     
985     @SuppressWarnings("unchecked")
986     @Override
987     public ASTNode visitNameList(final NameListContext ctx) {
988         CollectionValue<IdentifierValue> result = new CollectionValue<>();
989         if (null != ctx.nameList()) {
990             result.combine((CollectionValue<IdentifierValue>) visit(ctx.nameList()));
991         }
992         if (null != ctx.name()) {
993             result.getValue().add((IdentifierValue) visit(ctx.name()));
994         }
995         return result;
996     }
997     
998     @Override
999     public ASTNode visitAlterLanguage(final AlterLanguageContext ctx) {
1000         return new PostgreSQLAlterLanguageStatement();
1001     }
1002     
1003     @Override
1004     public ASTNode visitAlterServer(final AlterServerContext ctx) {
1005         return new AlterServerStatement();
1006     }
1007     
1008     @Override
1009     public ASTNode visitAlterStatistics(final AlterStatisticsContext ctx) {
1010         return new PostgreSQLAlterStatisticsStatement();
1011     }
1012     
1013     @Override
1014     public ASTNode visitDropLanguage(final DropLanguageContext ctx) {
1015         return new PostgreSQLDropLanguageStatement();
1016     }
1017     
1018     @Override
1019     public ASTNode visitCreateConversion(final CreateConversionContext ctx) {
1020         return new PostgreSQLCreateConversionStatement();
1021     }
1022     
1023     @Override
1024     public ASTNode visitCreateType(final CreateTypeContext ctx) {
1025         return new CreateTypeStatement();
1026     }
1027     
1028     @Override
1029     public ASTNode visitDropConversion(final DropConversionContext ctx) {
1030         return new PostgreSQLDropConversionStatement();
1031     }
1032     
1033     @Override
1034     public ASTNode visitAlterConversion(final AlterConversionContext ctx) {
1035         return new PostgreSQLAlterConversionStatement();
1036     }
1037     
1038     @Override
1039     public ASTNode visitCreateTextSearch(final CreateTextSearchContext ctx) {
1040         return new PostgreSQLCreateTextSearchStatement();
1041     }
1042     
1043     @Override
1044     public ASTNode visitAlterTextSearchConfiguration(final AlterTextSearchConfigurationContext ctx) {
1045         return new PostgreSQLAlterTextSearchStatement();
1046     }
1047     
1048     @Override
1049     public ASTNode visitAlterTextSearchDictionary(final AlterTextSearchDictionaryContext ctx) {
1050         return new PostgreSQLAlterTextSearchStatement();
1051     }
1052     
1053     @Override
1054     public ASTNode visitAlterTextSearchTemplate(final AlterTextSearchTemplateContext ctx) {
1055         return new PostgreSQLAlterTextSearchStatement();
1056     }
1057     
1058     @Override
1059     public ASTNode visitAlterTextSearchParser(final AlterTextSearchParserContext ctx) {
1060         return new PostgreSQLAlterTextSearchStatement();
1061     }
1062     
1063     @Override
1064     public ASTNode visitCreateExtension(final CreateExtensionContext ctx) {
1065         return new PostgreSQLCreateExtensionStatement();
1066     }
1067     
1068     @Override
1069     public ASTNode visitAlterExtension(final AlterExtensionContext ctx) {
1070         return new PostgreSQLAlterExtensionStatement();
1071     }
1072     
1073     @Override
1074     public ASTNode visitDropExtension(final DropExtensionContext ctx) {
1075         return new PostgreSQLDropExtensionStatement();
1076     }
1077     
1078     @Override
1079     public ASTNode visitDiscard(final DiscardContext ctx) {
1080         return new PostgreSQLDiscardStatement();
1081     }
1082     
1083     @Override
1084     public ASTNode visitDropOwned(final DropOwnedContext ctx) {
1085         return new PostgreSQLDropOwnedStatement();
1086     }
1087     
1088     @Override
1089     public ASTNode visitDropOperator(final DropOperatorContext ctx) {
1090         return new DropOperatorStatement();
1091     }
1092     
1093     @Override
1094     public ASTNode visitDropMaterializedView(final DropMaterializedViewContext ctx) {
1095         return new DropMaterializedViewStatement();
1096     }
1097     
1098     @Override
1099     public ASTNode visitDropEventTrigger(final DropEventTriggerContext ctx) {
1100         return new PostgreSQLDropEventTriggerStatement();
1101     }
1102     
1103     @Override
1104     public ASTNode visitDropAggregate(final DropAggregateContext ctx) {
1105         return new PostgreSQLDropAggregateStatement();
1106     }
1107     
1108     @Override
1109     public ASTNode visitDropCollation(final DropCollationContext ctx) {
1110         return new PostgreSQLDropCollationStatement();
1111     }
1112     
1113     @Override
1114     public ASTNode visitDropForeignDataWrapper(final DropForeignDataWrapperContext ctx) {
1115         return new PostgreSQLDropForeignDataWrapperStatement();
1116     }
1117     
1118     @Override
1119     public ASTNode visitDropTrigger(final DropTriggerContext ctx) {
1120         return new DropTriggerStatement();
1121     }
1122     
1123     @Override
1124     public ASTNode visitDropType(final DropTypeContext ctx) {
1125         return new PostgreSQLDropTypeStatement();
1126     }
1127     
1128     @Override
1129     public ASTNode visitComment(final CommentContext ctx) {
1130         if (null != ctx.commentClauses().objectTypeAnyName() && null != ctx.commentClauses().objectTypeAnyName().TABLE()) {
1131             return commentOnTable(ctx);
1132         }
1133         if (null != ctx.commentClauses().COLUMN()) {
1134             return commentOnColumn(ctx);
1135         }
1136         if (null != ctx.commentClauses().objectTypeNameOnAnyName()) {
1137             return getTableFromComment(ctx);
1138         }
1139         return new CommentStatement();
1140     }
1141     
1142     @SuppressWarnings("unchecked")
1143     private CommentStatement commentOnColumn(final CommentContext ctx) {
1144         CommentStatement result = new CommentStatement();
1145         Iterator<NameSegment> nameSegmentIterator = ((CollectionValue<NameSegment>) visit(ctx.commentClauses().anyName())).getValue().iterator();
1146         Optional<NameSegment> columnName = nameSegmentIterator.hasNext() ? Optional.of(nameSegmentIterator.next()) : Optional.empty();
1147         columnName.ifPresent(optional -> result.setColumn(new ColumnSegment(optional.getStartIndex(), optional.getStopIndex(), optional.getIdentifier())));
1148         result.setComment(new IdentifierValue(ctx.commentClauses().commentText().getText()));
1149         setTableSegment(result, nameSegmentIterator);
1150         return result;
1151     }
1152     
1153     @SuppressWarnings("unchecked")
1154     private CommentStatement commentOnTable(final CommentContext ctx) {
1155         CommentStatement result = new CommentStatement();
1156         Iterator<NameSegment> nameSegmentIterator = ((CollectionValue<NameSegment>) visit(ctx.commentClauses().anyName())).getValue().iterator();
1157         result.setComment(new IdentifierValue(ctx.commentClauses().commentText().getText()));
1158         setTableSegment(result, nameSegmentIterator);
1159         return result;
1160     }
1161     
1162     private void setTableSegment(final CommentStatement statement, final Iterator<NameSegment> nameSegmentIterator) {
1163         Optional<NameSegment> tableName = nameSegmentIterator.hasNext() ? Optional.of(nameSegmentIterator.next()) : Optional.empty();
1164         tableName.ifPresent(optional -> statement.setTable(new SimpleTableSegment(new TableNameSegment(optional.getStartIndex(), optional.getStopIndex(), optional.getIdentifier()))));
1165         Optional<NameSegment> schemaName = nameSegmentIterator.hasNext() ? Optional.of(nameSegmentIterator.next()) : Optional.empty();
1166         schemaName.ifPresent(optional -> statement.getTable().setOwner(new OwnerSegment(optional.getStartIndex(), optional.getStopIndex(), optional.getIdentifier())));
1167         Optional<NameSegment> databaseName = nameSegmentIterator.hasNext() ? Optional.of(nameSegmentIterator.next()) : Optional.empty();
1168         databaseName.ifPresent(optional -> statement.getTable().getOwner()
1169                 .ifPresent(owner -> owner.setOwner(new OwnerSegment(optional.getStartIndex(), optional.getStopIndex(), optional.getIdentifier()))));
1170     }
1171     
1172     private CommentStatement getTableFromComment(final CommentContext ctx) {
1173         CommentStatement result = new CommentStatement();
1174         result.setTable((SimpleTableSegment) visit(ctx.commentClauses().tableName()));
1175         return result;
1176     }
1177     
1178     @Override
1179     public ASTNode visitDropOperatorClass(final DropOperatorClassContext ctx) {
1180         return new PostgreSQLDropOperatorClassStatement();
1181     }
1182     
1183     @Override
1184     public ASTNode visitDropOperatorFamily(final DropOperatorFamilyContext ctx) {
1185         return new PostgreSQLDropOperatorFamilyStatement();
1186     }
1187     
1188     @Override
1189     public ASTNode visitDropAccessMethod(final DropAccessMethodContext ctx) {
1190         return new PostgreSQLDropAccessMethodStatement();
1191     }
1192     
1193     @Override
1194     public ASTNode visitDropServer(final DropServerContext ctx) {
1195         return new DropServerStatement();
1196     }
1197     
1198     @Override
1199     public ASTNode visitDeclare(final DeclareContext ctx) {
1200         return new PostgreSQLDeclareStatement((CursorNameSegment) visit(ctx.cursorName()), (SelectStatement) visit(ctx.select()));
1201     }
1202     
1203     @Override
1204     public ASTNode visitFetch(final FetchContext ctx) {
1205         return new FetchStatement((CursorNameSegment) visit(ctx.cursorName()), null == ctx.direction() ? null : (DirectionSegment) visit(ctx.direction()));
1206     }
1207     
1208     @Override
1209     public ASTNode visitMove(final MoveContext ctx) {
1210         return new MoveStatement((CursorNameSegment) visit(ctx.cursorName()), null == ctx.direction() ? null : (DirectionSegment) visit(ctx.direction()));
1211     }
1212     
1213     @Override
1214     public ASTNode visitClose(final CloseContext ctx) {
1215         return new CloseStatement(null == ctx.cursorName() ? null : (CursorNameSegment) visit(ctx.cursorName()), null != ctx.ALL());
1216     }
1217     
1218     @Override
1219     public ASTNode visitCursorName(final CursorNameContext ctx) {
1220         return null != ctx.name() ? new CursorNameSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), (IdentifierValue) visit(ctx.name()))
1221                 : new CursorNameSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), (IdentifierValue) visit(ctx.hostVariable()));
1222     }
1223     
1224     @Override
1225     public ASTNode visitCluster(final ClusterContext ctx) {
1226         return new PostgreSQLClusterStatement(null == ctx.tableName() ? null : (SimpleTableSegment) visit(ctx.tableName()),
1227                 null == ctx.clusterIndexSpecification() ? null : (IndexSegment) visit(ctx.clusterIndexSpecification().indexName()));
1228     }
1229     
1230     @Override
1231     public ASTNode visitCreateAccessMethod(final CreateAccessMethodContext ctx) {
1232         return new PostgreSQLCreateAccessMethodStatement();
1233     }
1234     
1235     @Override
1236     public ASTNode visitCreateAggregate(final CreateAggregateContext ctx) {
1237         return new PostgreSQLCreateAggregateStatement();
1238     }
1239     
1240     @Override
1241     public ASTNode visitNext(final NextContext ctx) {
1242         return new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), DirectionType.NEXT);
1243     }
1244     
1245     @Override
1246     public ASTNode visitPrior(final PriorContext ctx) {
1247         return new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), DirectionType.PRIOR);
1248     }
1249     
1250     @Override
1251     public ASTNode visitFirst(final FirstContext ctx) {
1252         return new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), DirectionType.FIRST);
1253     }
1254     
1255     @Override
1256     public ASTNode visitLast(final LastContext ctx) {
1257         return new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), DirectionType.LAST);
1258     }
1259     
1260     @Override
1261     public ASTNode visitAbsoluteCount(final AbsoluteCountContext ctx) {
1262         return new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), DirectionType.ABSOLUTE_COUNT, ((NumberLiteralValue) visit(ctx.signedIconst())).getValue().longValue());
1263     }
1264     
1265     @Override
1266     public ASTNode visitRelativeCount(final RelativeCountContext ctx) {
1267         return new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), DirectionType.RELATIVE_COUNT, ((NumberLiteralValue) visit(ctx.signedIconst())).getValue().longValue());
1268     }
1269     
1270     @Override
1271     public ASTNode visitCount(final CountContext ctx) {
1272         return new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), DirectionType.COUNT, ((NumberLiteralValue) visit(ctx.signedIconst())).getValue().longValue());
1273     }
1274     
1275     @Override
1276     public ASTNode visitAll(final AllContext ctx) {
1277         return new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), DirectionType.ALL);
1278     }
1279     
1280     @Override
1281     public ASTNode visitForward(final ForwardContext ctx) {
1282         return new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), DirectionType.FORWARD);
1283     }
1284     
1285     @Override
1286     public ASTNode visitForwardCount(final ForwardCountContext ctx) {
1287         return new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), DirectionType.FORWARD_COUNT, ((NumberLiteralValue) visit(ctx.signedIconst())).getValue().longValue());
1288     }
1289     
1290     @Override
1291     public ASTNode visitForwardAll(final ForwardAllContext ctx) {
1292         return new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), DirectionType.FORWARD_ALL);
1293     }
1294     
1295     @Override
1296     public ASTNode visitBackward(final BackwardContext ctx) {
1297         return new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), DirectionType.BACKWARD);
1298     }
1299     
1300     @Override
1301     public ASTNode visitBackwardCount(final BackwardCountContext ctx) {
1302         return new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), DirectionType.BACKWARD_COUNT, ((NumberLiteralValue) visit(ctx.signedIconst())).getValue().longValue());
1303     }
1304     
1305     @Override
1306     public ASTNode visitBackwardAll(final BackwardAllContext ctx) {
1307         return new DirectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), DirectionType.BACKWARD_ALL);
1308     }
1309     
1310     @Override
1311     public ASTNode visitCreateCast(final CreateCastContext ctx) {
1312         return new PostgreSQLCreateCastStatement();
1313     }
1314     
1315     @Override
1316     public ASTNode visitListen(final ListenContext ctx) {
1317         return new PostgreSQLListenStatement(ctx.channelName().getText());
1318     }
1319     
1320     @Override
1321     public ASTNode visitUnlisten(final UnlistenContext ctx) {
1322         return new PostgreSQLUnlistenStatement();
1323     }
1324     
1325     @Override
1326     public ASTNode visitNotifyStmt(final NotifyStmtContext ctx) {
1327         return new PostgreSQLNotifyStmtStatement();
1328     }
1329     
1330     @Override
1331     public ASTNode visitCreateCollation(final CreateCollationContext ctx) {
1332         return new CreateCollationStatement();
1333     }
1334     
1335     @Override
1336     public ASTNode visitRefreshMatViewStmt(final RefreshMatViewStmtContext ctx) {
1337         return new RefreshMatViewStmtStatement();
1338     }
1339     
1340     @Override
1341     public ASTNode visitReindex(final ReindexContext ctx) {
1342         return new PostgreSQLReindexStatement();
1343     }
1344     
1345     @Override
1346     public ASTNode visitSecurityLabelStmt(final SecurityLabelStmtContext ctx) {
1347         return new PostgreSQLSecurityLabelStmtStatement();
1348     }
1349     
1350     @Override
1351     public ASTNode visitCreateEventTrigger(final CreateEventTriggerContext ctx) {
1352         return new PostgreSQLCreateEventTriggerStatement();
1353     }
1354     
1355     @Override
1356     public ASTNode visitCreateForeignDataWrapper(final CreateForeignDataWrapperContext ctx) {
1357         return new PostgreSQLCreateForeignDataWrapperStatement();
1358     }
1359     
1360     @Override
1361     public ASTNode visitCreateForeignTable(final CreateForeignTableContext ctx) {
1362         return new PostgreSQLCreateForeignTableStatement();
1363     }
1364     
1365     @Override
1366     public ASTNode visitCreateMaterializedView(final CreateMaterializedViewContext ctx) {
1367         return new CreateMaterializedViewStatement();
1368     }
1369     
1370     @Override
1371     public ASTNode visitCreateOperator(final CreateOperatorContext ctx) {
1372         return new CreateOperatorStatement();
1373     }
1374     
1375     @Override
1376     public ASTNode visitCreatePolicy(final CreatePolicyContext ctx) {
1377         return new PostgreSQLCreatePolicyStatement();
1378     }
1379     
1380     @Override
1381     public ASTNode visitCreatePublication(final CreatePublicationContext ctx) {
1382         return new PostgreSQLCreatePublicationStatement();
1383     }
1384     
1385     @Override
1386     public ASTNode visitOpen(final OpenContext ctx) {
1387         return new PostgreSQLOpenStatement((CursorNameSegment) visit(ctx.cursorName()));
1388     }
1389 }