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.mysql.visitor.statement.type;
19  
20  import org.apache.shardingsphere.sql.parser.api.ASTNode;
21  import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DALStatementVisitor;
22  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser;
23  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.AlterResourceGroupContext;
24  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.AnalyzeTableContext;
25  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.BinaryLogFileIndexNumberContext;
26  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.BinlogContext;
27  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CacheIndexContext;
28  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CacheTableIndexListContext;
29  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ChangeMasterToContext;
30  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ChangeReplicationSourceToContext;
31  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ChannelOptionContext;
32  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CheckTableContext;
33  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ChecksumTableContext;
34  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CloneActionContext;
35  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CloneContext;
36  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CloneInstanceContext;
37  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CreateLoadableFunctionContext;
38  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CreateResourceGroupContext;
39  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.DelimiterContext;
40  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.DropResourceGroupContext;
41  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ExplainContext;
42  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ExplainableStatementContext;
43  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.FlushContext;
44  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.FromDatabaseContext;
45  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.FromTableContext;
46  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.HelpContext;
47  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.IndexNameContext;
48  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.InstallComponentContext;
49  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.InstallPluginContext;
50  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.KillContext;
51  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.LoadIndexInfoContext;
52  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.LoadTableIndexListContext;
53  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.OptimizeTableContext;
54  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.OptionTypeContext;
55  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.OptionValueContext;
56  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.OptionValueListContext;
57  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.OptionValueNoOptionTypeContext;
58  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.PartitionListContext;
59  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.PartitionNameContext;
60  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.RepairTableContext;
61  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ResetOptionContext;
62  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ResetPersistContext;
63  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ResetStatementContext;
64  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.RestartContext;
65  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.SetCharacterContext;
66  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.SetResourceGroupContext;
67  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.SetVariableContext;
68  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowBinaryLogsContext;
69  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowBinlogEventsContext;
70  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCharacterSetContext;
71  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCharsetContext;
72  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCollationContext;
73  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowColumnsContext;
74  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCreateDatabaseContext;
75  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCreateEventContext;
76  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCreateFunctionContext;
77  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCreateProcedureContext;
78  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCreateTableContext;
79  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCreateTriggerContext;
80  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCreateUserContext;
81  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowCreateViewContext;
82  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowDatabasesContext;
83  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowEngineContext;
84  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowEnginesContext;
85  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowErrorsContext;
86  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowEventsContext;
87  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowFilterContext;
88  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowFunctionCodeContext;
89  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowFunctionStatusContext;
90  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowGrantsContext;
91  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowIndexContext;
92  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowLikeContext;
93  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowMasterStatusContext;
94  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowOpenTablesContext;
95  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowPluginsContext;
96  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowPrivilegesContext;
97  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowProcedureCodeContext;
98  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowProcedureStatusContext;
99  import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowProcesslistContext;
100 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowProfileContext;
101 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowProfilesContext;
102 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowRelaylogEventContext;
103 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowReplicaStatusContext;
104 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowReplicasContext;
105 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowSlaveHostsContext;
106 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowSlaveStatusContext;
107 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowStatusContext;
108 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowTableStatusContext;
109 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowTablesContext;
110 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowTriggersContext;
111 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowVariablesContext;
112 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowWarningsContext;
113 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowWhereClauseContext;
114 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShutdownContext;
115 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.StartSlaveContext;
116 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.StopSlaveContext;
117 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.TablesOptionContext;
118 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.UninstallComponentContext;
119 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.UninstallPluginContext;
120 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.UseContext;
121 import org.apache.shardingsphere.sql.parser.mysql.visitor.statement.MySQLStatementVisitor;
122 import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.CacheTableIndexSegment;
123 import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.CloneActionSegment;
124 import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.CloneInstanceSegment;
125 import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.FromDatabaseSegment;
126 import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.FromTableSegment;
127 import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.LoadTableIndexSegment;
128 import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.PartitionDefinitionSegment;
129 import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.PartitionSegment;
130 import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ResetMasterOptionSegment;
131 import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ResetOptionSegment;
132 import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ResetSlaveOptionSegment;
133 import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ShowFilterSegment;
134 import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ShowLikeSegment;
135 import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.VariableAssignSegment;
136 import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.VariableSegment;
137 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
138 import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
139 import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment;
140 import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.FunctionSegment;
141 import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.pagination.limit.LimitSegment;
142 import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment;
143 import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DatabaseSegment;
144 import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
145 import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
146 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.AnalyzeTableStatement;
147 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.ExplainStatement;
148 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.SetStatement;
149 import org.apache.shardingsphere.sql.parser.statement.core.value.collection.CollectionValue;
150 import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
151 import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.NumberLiteralValue;
152 import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.StringLiteralValue;
153 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLCloneStatement;
154 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLCreateLoadableFunctionStatement;
155 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLDelimiterStatement;
156 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLFlushStatement;
157 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLHelpStatement;
158 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLKillStatement;
159 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLOptimizeTableStatement;
160 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLResetPersistStatement;
161 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLResetStatement;
162 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLRestartStatement;
163 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLShutdownStatement;
164 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLUseStatement;
165 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.component.MySQLInstallComponentStatement;
166 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.component.MySQLUninstallComponentStatement;
167 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.index.MySQLCacheIndexStatement;
168 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.index.MySQLLoadIndexInfoStatement;
169 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.plugin.MySQLInstallPluginStatement;
170 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.plugin.MySQLShowPluginsStatement;
171 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.plugin.MySQLUninstallPluginStatement;
172 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.binlog.MySQLBinlogStatement;
173 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.binlog.MySQLShowBinaryLogsStatement;
174 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.binlog.MySQLShowBinlogEventsStatement;
175 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.opertation.MySQLChangeMasterStatement;
176 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.opertation.MySQLChangeReplicationSourceToStatement;
177 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.opertation.MySQLStartReplicaStatement;
178 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.opertation.MySQLStartSlaveStatement;
179 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.opertation.MySQLStopSlaveStatement;
180 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowMasterStatusStatement;
181 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowRelayLogEventsStatement;
182 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowReplicaStatusStatement;
183 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowReplicasStatement;
184 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowSlaveHostsStatement;
185 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowSlaveStatusStatement;
186 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.replication.show.MySQLShowStatusStatement;
187 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLAlterResourceGroupStatement;
188 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLCreateResourceGroupStatement;
189 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLDropResourceGroupStatement;
190 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.resource.MySQLSetResourceGroupStatement;
191 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.MySQLShowOtherStatement;
192 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.character.MySQLShowCharacterSetStatement;
193 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.character.MySQLShowCollationStatement;
194 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.column.MySQLDescribeStatement;
195 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.column.MySQLShowColumnsStatement;
196 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.database.MySQLShowCreateDatabaseStatement;
197 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.database.MySQLShowDatabasesStatement;
198 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.engine.MySQLShowEngineStatement;
199 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.error.MySQLShowErrorsStatement;
200 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.error.MySQLShowWarningsStatement;
201 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.event.MySQLShowCreateEventStatement;
202 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.event.MySQLShowEventsStatement;
203 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.function.MySQLShowCreateFunctionStatement;
204 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.function.MySQLShowFunctionCodeStatement;
205 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.function.MySQLShowFunctionStatusStatement;
206 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.index.MySQLShowIndexStatement;
207 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.privilege.MySQLShowCreateUserStatement;
208 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.privilege.MySQLShowGrantsStatement;
209 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.privilege.MySQLShowPrivilegesStatement;
210 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.procedure.MySQLShowCreateProcedureStatement;
211 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.procedure.MySQLShowProcedureCodeStatement;
212 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.procedure.MySQLShowProcedureStatusStatement;
213 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.process.MySQLShowProcessListStatement;
214 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.profile.MySQLShowProfileStatement;
215 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.profile.MySQLShowProfilesStatement;
216 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.table.MySQLShowCreateTableStatement;
217 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.table.MySQLShowOpenTablesStatement;
218 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.table.MySQLShowTableStatusStatement;
219 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.table.MySQLShowTablesStatement;
220 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.trigger.MySQLShowCreateTriggerStatement;
221 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.trigger.MySQLShowTriggersStatement;
222 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.variable.MySQLShowVariablesStatement;
223 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.view.MySQLShowCreateViewStatement;
224 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.table.MySQLCheckTableStatement;
225 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.table.MySQLChecksumTableStatement;
226 import org.apache.shardingsphere.sql.parser.statement.mysql.dal.table.MySQLRepairTableStatement;
227 
228 import java.util.Collection;
229 import java.util.Collections;
230 import java.util.LinkedList;
231 import java.util.List;
232 import java.util.Optional;
233 import java.util.stream.Collectors;
234 
235 /**
236  * DAL statement visitor for MySQL.
237  */
238 public final class MySQLDALStatementVisitor extends MySQLStatementVisitor implements DALStatementVisitor {
239     
240     @Override
241     public ASTNode visitUninstallPlugin(final UninstallPluginContext ctx) {
242         return new MySQLUninstallPluginStatement(((IdentifierValue) visit(ctx.pluginName())).getValue());
243     }
244     
245     @Override
246     public ASTNode visitShowCreateDatabase(final ShowCreateDatabaseContext ctx) {
247         return new MySQLShowCreateDatabaseStatement(((DatabaseSegment) visit(ctx.databaseName())).getIdentifier().getValue());
248     }
249     
250     @Override
251     public ASTNode visitShowBinaryLogs(final ShowBinaryLogsContext ctx) {
252         return new MySQLShowBinaryLogsStatement();
253     }
254     
255     @Override
256     public ASTNode visitShowStatus(final ShowStatusContext ctx) {
257         MySQLShowStatusStatement result = new MySQLShowStatusStatement(null == ctx.showFilter() ? null : (ShowFilterSegment) visit(ctx.showFilter()));
258         result.addParameterMarkers(getParameterMarkerSegments());
259         return result;
260     }
261     
262     @Override
263     public ASTNode visitShowCreateView(final ShowCreateViewContext ctx) {
264         return new MySQLShowCreateViewStatement(null);
265     }
266     
267     @Override
268     public ASTNode visitShowEngines(final ShowEnginesContext ctx) {
269         return new MySQLShowOtherStatement();
270     }
271     
272     @Override
273     public ASTNode visitShowEngine(final ShowEngineContext ctx) {
274         return new MySQLShowEngineStatement(ctx.engineRef().getText());
275     }
276     
277     @Override
278     public ASTNode visitShowCharset(final ShowCharsetContext ctx) {
279         return new MySQLShowOtherStatement();
280     }
281     
282     @Override
283     public ASTNode visitShowCreateEvent(final ShowCreateEventContext ctx) {
284         return new MySQLShowCreateEventStatement(((IdentifierValue) visit(ctx.eventName())).getValue());
285     }
286     
287     @Override
288     public ASTNode visitShowCreateFunction(final ShowCreateFunctionContext ctx) {
289         return new MySQLShowCreateFunctionStatement(((FunctionSegment) visit(ctx.functionName())).getFunctionName());
290     }
291     
292     @Override
293     public ASTNode visitShowCreateProcedure(final ShowCreateProcedureContext ctx) {
294         return new MySQLShowCreateProcedureStatement(((IdentifierValue) visit(ctx.procedureName())).getValue());
295     }
296     
297     @Override
298     public ASTNode visitShowBinlogEvents(final ShowBinlogEventsContext ctx) {
299         return new MySQLShowBinlogEventsStatement(null == ctx.logName() ? null : ctx.logName().getText(), null == ctx.limitClause() ? null : (LimitSegment) visit(ctx.limitClause()));
300     }
301     
302     @Override
303     public ASTNode visitShowErrors(final ShowErrorsContext ctx) {
304         return new MySQLShowErrorsStatement(null == ctx.limitClause() ? null : (LimitSegment) visit(ctx.limitClause()));
305     }
306     
307     @Override
308     public ASTNode visitShowWarnings(final ShowWarningsContext ctx) {
309         return new MySQLShowWarningsStatement(null == ctx.limitClause() ? null : (LimitSegment) visit(ctx.limitClause()));
310     }
311     
312     @Override
313     public ASTNode visitResetStatement(final ResetStatementContext ctx) {
314         ResetPersistContext persistContext = ctx.resetPersist();
315         return null == persistContext
316                 ? new MySQLResetStatement(
317                         ctx.resetOption().stream().filter(each -> null != each.MASTER() || null != each.SLAVE()).map(each -> (ResetOptionSegment) visit(each)).collect(Collectors.toList()))
318                 : visit(persistContext);
319     }
320     
321     @Override
322     public ASTNode visitResetPersist(final ResetPersistContext ctx) {
323         return new MySQLResetPersistStatement(null != ctx.ifExists(), null == ctx.identifier() ? null : new IdentifierValue(ctx.identifier().getText()));
324     }
325     
326     @Override
327     public ASTNode visitResetOption(final ResetOptionContext ctx) {
328         if (null != ctx.MASTER()) {
329             ResetMasterOptionSegment result = new ResetMasterOptionSegment();
330             if (null != ctx.binaryLogFileIndexNumber()) {
331                 result.setBinaryLogFileIndexNumber(((NumberLiteralValue) visit(ctx.binaryLogFileIndexNumber())).getValue().longValue());
332             }
333             result.setStartIndex(ctx.start.getStartIndex());
334             result.setStopIndex(ctx.stop.getStopIndex());
335             return result;
336         }
337         ResetSlaveOptionSegment result = new ResetSlaveOptionSegment();
338         if (null != ctx.ALL()) {
339             result.setAll(true);
340         }
341         if (null != ctx.channelOption()) {
342             result.setChannelOption(((StringLiteralValue) visit(ctx.channelOption())).getValue());
343         }
344         result.setStartIndex(ctx.start.getStartIndex());
345         result.setStopIndex(ctx.stop.getStopIndex());
346         return result;
347     }
348     
349     @Override
350     public ASTNode visitChannelOption(final ChannelOptionContext ctx) {
351         return visit(ctx.string_());
352     }
353     
354     @Override
355     public ASTNode visitBinaryLogFileIndexNumber(final BinaryLogFileIndexNumberContext ctx) {
356         return new NumberLiteralValue(ctx.getText());
357     }
358     
359     @Override
360     public ASTNode visitShowReplicas(final ShowReplicasContext ctx) {
361         return new MySQLShowReplicasStatement();
362     }
363     
364     @SuppressWarnings("unchecked")
365     @Override
366     public ASTNode visitRepairTable(final RepairTableContext ctx) {
367         return new MySQLRepairTableStatement(((CollectionValue<SimpleTableSegment>) visit(ctx.tableList())).getValue());
368     }
369     
370     @SuppressWarnings("unchecked")
371     @Override
372     public ASTNode visitAnalyzeTable(final AnalyzeTableContext ctx) {
373         return new AnalyzeTableStatement(((CollectionValue<SimpleTableSegment>) visit(ctx.tableList())).getValue());
374     }
375     
376     @Override
377     public ASTNode visitCacheIndex(final CacheIndexContext ctx) {
378         IdentifierValue name = null == ctx.DEFAULT() ? (IdentifierValue) visit(ctx.identifier()) : new IdentifierValue(ctx.DEFAULT().getText());
379         Collection<CacheTableIndexSegment> tableIndexes = null == ctx.cacheTableIndexList()
380                 ? Collections.emptyList()
381                 : ctx.cacheTableIndexList().stream().map(each -> (CacheTableIndexSegment) visit(each)).collect(Collectors.toList());
382         PartitionDefinitionSegment partitionDefinition = null == ctx.partitionList()
383                 ? null
384                 : new PartitionDefinitionSegment(ctx.tableName().getStart().getStartIndex(), ctx.partitionList().getStop().getStopIndex(),
385                         (SimpleTableSegment) visit(ctx.tableName()), ((CollectionValue<PartitionSegment>) visit(ctx.partitionList())).getValue());
386         return new MySQLCacheIndexStatement(name, tableIndexes, partitionDefinition);
387     }
388     
389     @Override
390     public ASTNode visitCacheTableIndexList(final CacheTableIndexListContext ctx) {
391         CacheTableIndexSegment result = new CacheTableIndexSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (SimpleTableSegment) visit(ctx.tableName()));
392         for (IndexNameContext each : ctx.indexName()) {
393             result.getIndexes().add((IndexSegment) visitIndexName(each));
394         }
395         return result;
396     }
397     
398     @Override
399     public ASTNode visitPartitionList(final PartitionListContext ctx) {
400         CollectionValue<PartitionSegment> result = new CollectionValue<>();
401         for (PartitionNameContext each : ctx.partitionName()) {
402             result.getValue().add((PartitionSegment) visit(each));
403         }
404         return result;
405     }
406     
407     @Override
408     public ASTNode visitPartitionName(final PartitionNameContext ctx) {
409         return new PartitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (IdentifierValue) visit(ctx.identifier()));
410     }
411     
412     @Override
413     public ASTNode visitChecksumTable(final ChecksumTableContext ctx) {
414         return new MySQLChecksumTableStatement(((CollectionValue<SimpleTableSegment>) visit(ctx.tableList())).getValue());
415     }
416     
417     @Override
418     public ASTNode visitFlush(final FlushContext ctx) {
419         if (null != ctx.tablesOption()) {
420             return visit(ctx.tablesOption());
421         }
422         return new MySQLFlushStatement(Collections.emptyList(), false);
423     }
424     
425     @Override
426     public ASTNode visitTablesOption(final TablesOptionContext ctx) {
427         return new MySQLFlushStatement(ctx.tableName().stream().map(each -> (SimpleTableSegment) visit(each)).collect(Collectors.toList()), true);
428     }
429     
430     @Override
431     public ASTNode visitKill(final KillContext ctx) {
432         return new MySQLKillStatement(null == ctx.AT_() ? ctx.IDENTIFIER_().getText() : ctx.AT_().getText() + ctx.IDENTIFIER_().getText(), getScope(ctx));
433     }
434     
435     private String getScope(final KillContext ctx) {
436         if (null != ctx.QUERY()) {
437             return ctx.QUERY().getText();
438         }
439         if (null != ctx.CONNECTION()) {
440             return ctx.CONNECTION().getText();
441         }
442         return null;
443     }
444     
445     @Override
446     public ASTNode visitLoadIndexInfo(final LoadIndexInfoContext ctx) {
447         return new MySQLLoadIndexInfoStatement(ctx.loadTableIndexList().stream().map(each -> (LoadTableIndexSegment) visit(each)).collect(Collectors.toList()));
448     }
449     
450     @Override
451     public ASTNode visitLoadTableIndexList(final LoadTableIndexListContext ctx) {
452         LoadTableIndexSegment result = new LoadTableIndexSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (SimpleTableSegment) visit(ctx.tableName()));
453         if (null != ctx.indexName()) {
454             for (IndexNameContext each : ctx.indexName()) {
455                 result.getIndexes().add((IndexSegment) visitIndexName(each));
456             }
457         }
458         if (null != ctx.partitionList()) {
459             result.getPartitions().addAll(((CollectionValue<PartitionSegment>) visit(ctx.partitionList())).getValue());
460         }
461         return result;
462     }
463     
464     @Override
465     public ASTNode visitInstallPlugin(final InstallPluginContext ctx) {
466         return new MySQLInstallPluginStatement(((IdentifierValue) visit(ctx.pluginName())).getValue());
467     }
468     
469     @Override
470     public ASTNode visitClone(final CloneContext ctx) {
471         return new MySQLCloneStatement((CloneActionSegment) visit(ctx.cloneAction()));
472     }
473     
474     @Override
475     public ASTNode visitCloneAction(final CloneActionContext ctx) {
476         CloneActionSegment result = new CloneActionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
477         if (null != ctx.cloneInstance()) {
478             CloneInstanceContext cloneInstance = ctx.cloneInstance();
479             CloneInstanceSegment cloneInstanceSegment = new CloneInstanceSegment(cloneInstance.start.getStartIndex(), cloneInstance.stop.getStopIndex());
480             cloneInstanceSegment.setUsername(((StringLiteralValue) visitUsername(cloneInstance.username())).getValue());
481             cloneInstanceSegment.setHostname(((StringLiteralValue) visit(cloneInstance.hostname())).getValue());
482             cloneInstanceSegment.setPort(new NumberLiteralValue(cloneInstance.port().NUMBER_().getText()).getValue().intValue());
483             cloneInstanceSegment.setPassword(((StringLiteralValue) visit(ctx.string_())).getValue());
484             if (null != ctx.SSL() && null == ctx.NO()) {
485                 cloneInstanceSegment.setSslRequired(true);
486             }
487             result.setCloneInstance(cloneInstanceSegment);
488         }
489         if (null != ctx.cloneDir()) {
490             result.setCloneDir(((StringLiteralValue) visit(ctx.cloneDir())).getValue());
491         }
492         return result;
493     }
494     
495     @SuppressWarnings("unchecked")
496     @Override
497     public ASTNode visitOptimizeTable(final OptimizeTableContext ctx) {
498         return new MySQLOptimizeTableStatement(((CollectionValue<SimpleTableSegment>) visit(ctx.tableList())).getValue());
499     }
500     
501     @Override
502     public ASTNode visitUse(final UseContext ctx) {
503         return new MySQLUseStatement(((DatabaseSegment) visit(ctx.databaseName())).getIdentifier().getValue());
504     }
505     
506     @Override
507     public ASTNode visitExplain(final ExplainContext ctx) {
508         return null == ctx.tableName()
509                 ? new ExplainStatement(getExplainableSQLStatement(ctx).orElse(null))
510                 : new MySQLDescribeStatement((SimpleTableSegment) visit(ctx.tableName()), getColumnWildcard(ctx));
511     }
512     
513     private Optional<SQLStatement> getExplainableSQLStatement(final ExplainContext ctx) {
514         if (null != ctx.explainableStatement()) {
515             return Optional.of((SQLStatement) visit(ctx.explainableStatement()));
516         }
517         if (null != ctx.select()) {
518             return Optional.of((SQLStatement) visit(ctx.select()));
519         }
520         if (null != ctx.delete()) {
521             return Optional.of((SQLStatement) visit(ctx.delete()));
522         }
523         if (null != ctx.update()) {
524             return Optional.of((SQLStatement) visit(ctx.update()));
525         }
526         if (null != ctx.insert()) {
527             return Optional.of((SQLStatement) visit(ctx.insert()));
528         }
529         return Optional.empty();
530     }
531     
532     private ColumnSegment getColumnWildcard(final ExplainContext ctx) {
533         if (null != ctx.columnRef()) {
534             return (ColumnSegment) visit(ctx.columnRef());
535         }
536         if (null != ctx.textString()) {
537             return (ColumnSegment) visit(ctx.textString());
538         }
539         return null;
540     }
541     
542     @Override
543     public ASTNode visitExplainableStatement(final ExplainableStatementContext ctx) {
544         if (null != ctx.select()) {
545             return visit(ctx.select());
546         }
547         if (null != ctx.delete()) {
548             return visit(ctx.delete());
549         }
550         if (null != ctx.insert()) {
551             return visit(ctx.insert());
552         }
553         if (null != ctx.replace()) {
554             return visit(ctx.replace());
555         }
556         return visit(ctx.update());
557     }
558     
559     @Override
560     public ASTNode visitShowProcedureCode(final ShowProcedureCodeContext ctx) {
561         return new MySQLShowProcedureCodeStatement((FunctionSegment) visit(ctx.functionName()));
562     }
563     
564     @Override
565     public ASTNode visitShowProfile(final ShowProfileContext ctx) {
566         return new MySQLShowProfileStatement(null == ctx.limitClause() ? null : (LimitSegment) visit(ctx.limitClause()));
567     }
568     
569     @Override
570     public ASTNode visitShowProfiles(final ShowProfilesContext ctx) {
571         return new MySQLShowProfilesStatement();
572     }
573     
574     @Override
575     public ASTNode visitShowDatabases(final ShowDatabasesContext ctx) {
576         MySQLShowDatabasesStatement result = new MySQLShowDatabasesStatement(null == ctx.showFilter() ? null : (ShowFilterSegment) visit(ctx.showFilter()));
577         result.addParameterMarkers(getParameterMarkerSegments());
578         return result;
579     }
580     
581     @Override
582     public ASTNode visitShowEvents(final ShowEventsContext ctx) {
583         MySQLShowEventsStatement result = new MySQLShowEventsStatement(
584                 null == ctx.fromDatabase() ? null : (FromDatabaseSegment) visit(ctx.fromDatabase()), null == ctx.showFilter() ? null : (ShowFilterSegment) visit(ctx.showFilter()));
585         result.addParameterMarkers(getParameterMarkerSegments());
586         return result;
587     }
588     
589     @Override
590     public ASTNode visitShowTables(final ShowTablesContext ctx) {
591         MySQLShowTablesStatement result = new MySQLShowTablesStatement(null == ctx.fromDatabase() ? null : (FromDatabaseSegment) visit(ctx.fromDatabase()),
592                 null == ctx.showFilter() ? null : (ShowFilterSegment) visit(ctx.showFilter()), null != ctx.FULL());
593         result.addParameterMarkers(getParameterMarkerSegments());
594         return result;
595     }
596     
597     @Override
598     public ASTNode visitShowTriggers(final ShowTriggersContext ctx) {
599         MySQLShowTriggersStatement result = new MySQLShowTriggersStatement(
600                 null == ctx.fromDatabase() ? null : (FromDatabaseSegment) visit(ctx.fromDatabase()), null == ctx.showFilter() ? null : (ShowFilterSegment) visit(ctx.showFilter()));
601         result.addParameterMarkers(getParameterMarkerSegments());
602         return result;
603     }
604     
605     @Override
606     public ASTNode visitShowWhereClause(final ShowWhereClauseContext ctx) {
607         return new WhereSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ExpressionSegment) visit(ctx.expr()));
608     }
609     
610     @Override
611     public ASTNode visitShowTableStatus(final ShowTableStatusContext ctx) {
612         MySQLShowTableStatusStatement result = new MySQLShowTableStatusStatement(
613                 null == ctx.fromDatabase() ? null : (FromDatabaseSegment) visit(ctx.fromDatabase()), null == ctx.showFilter() ? null : (ShowFilterSegment) visit(ctx.showFilter()));
614         result.addParameterMarkers(getParameterMarkerSegments());
615         return result;
616     }
617     
618     @Override
619     public ASTNode visitShowColumns(final ShowColumnsContext ctx) {
620         MySQLShowColumnsStatement result = new MySQLShowColumnsStatement(null == ctx.fromTable() ? null : ((FromTableSegment) visit(ctx.fromTable())).getTable(),
621                 null == ctx.fromDatabase() ? null : (FromDatabaseSegment) visit(ctx.fromDatabase()), null == ctx.showFilter() ? null : (ShowFilterSegment) visit(ctx.showFilter()));
622         result.addParameterMarkers(getParameterMarkerSegments());
623         return result;
624     }
625     
626     @Override
627     public ASTNode visitShowFilter(final ShowFilterContext ctx) {
628         ShowFilterSegment result = new ShowFilterSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex());
629         if (null != ctx.showLike()) {
630             result.setLike((ShowLikeSegment) visit(ctx.showLike()));
631         }
632         if (null != ctx.showWhereClause()) {
633             result.setWhere((WhereSegment) visit(ctx.showWhereClause()));
634         }
635         return result;
636     }
637     
638     @Override
639     public ASTNode visitShowIndex(final ShowIndexContext ctx) {
640         return new MySQLShowIndexStatement(null == ctx.fromTable() ? null : ((FromTableSegment) visitFromTable(ctx.fromTable())).getTable(),
641                 null == ctx.fromDatabase() ? null : (FromDatabaseSegment) visit(ctx.fromDatabase()));
642     }
643     
644     @Override
645     public ASTNode visitShowCreateTable(final ShowCreateTableContext ctx) {
646         return new MySQLShowCreateTableStatement((SimpleTableSegment) visit(ctx.tableName()));
647     }
648     
649     @Override
650     public ASTNode visitShowCreateTrigger(final ShowCreateTriggerContext ctx) {
651         return new MySQLShowCreateTriggerStatement(((IdentifierValue) visit(ctx.triggerName())).getValue());
652     }
653     
654     @Override
655     public ASTNode visitShowRelaylogEvent(final ShowRelaylogEventContext ctx) {
656         return new MySQLShowRelayLogEventsStatement(null == ctx.logName() ? null : ((StringLiteralValue) visit(ctx.logName().stringLiterals())).getValue(),
657                 null == ctx.limitClause() ? null : (LimitSegment) visit(ctx.limitClause()), null == ctx.channelName() ? null : ((IdentifierValue) visit(ctx.channelName())).getValue());
658     }
659     
660     @Override
661     public ASTNode visitShowFunctionCode(final ShowFunctionCodeContext ctx) {
662         return new MySQLShowFunctionCodeStatement(((FunctionSegment) visit(ctx.functionName())).getFunctionName());
663     }
664     
665     @Override
666     public ASTNode visitShowGrants(final ShowGrantsContext ctx) {
667         return new MySQLShowGrantsStatement();
668     }
669     
670     @Override
671     public ASTNode visitShowMasterStatus(final ShowMasterStatusContext ctx) {
672         return new MySQLShowMasterStatusStatement();
673     }
674     
675     @Override
676     public ASTNode visitShowSlaveHosts(final ShowSlaveHostsContext ctx) {
677         return new MySQLShowSlaveHostsStatement();
678     }
679     
680     @Override
681     public ASTNode visitShowReplicaStatus(final ShowReplicaStatusContext ctx) {
682         return new MySQLShowReplicaStatusStatement(null == ctx.channelName() ? null : ((IdentifierValue) visit(ctx.channelName())).getValue());
683     }
684     
685     @Override
686     public ASTNode visitShowSlaveStatus(final ShowSlaveStatusContext ctx) {
687         return new MySQLShowSlaveStatusStatement(null == ctx.channelName() ? null : ((IdentifierValue) visit(ctx.channelName())).getValue());
688     }
689     
690     @Override
691     public ASTNode visitCreateResourceGroup(final CreateResourceGroupContext ctx) {
692         return new MySQLCreateResourceGroupStatement(((IdentifierValue) visit(ctx.groupName())).getValue());
693     }
694     
695     @Override
696     public ASTNode visitBinlog(final BinlogContext ctx) {
697         return new MySQLBinlogStatement(((StringLiteralValue) visit(ctx.stringLiterals())).getValue());
698     }
699     
700     @Override
701     public ASTNode visitFromTable(final FromTableContext ctx) {
702         FromTableSegment result = new FromTableSegment();
703         result.setTable((SimpleTableSegment) visit(ctx.tableName()));
704         return result;
705     }
706     
707     @Override
708     public ASTNode visitShowVariables(final ShowVariablesContext ctx) {
709         MySQLShowVariablesStatement result = new MySQLShowVariablesStatement(null == ctx.showFilter() ? null : (ShowFilterSegment) visit(ctx.showFilter()));
710         result.addParameterMarkers(getParameterMarkerSegments());
711         return result;
712     }
713     
714     @Override
715     public ASTNode visitShowCharacterSet(final ShowCharacterSetContext ctx) {
716         MySQLShowCharacterSetStatement result = new MySQLShowCharacterSetStatement(null == ctx.showFilter() ? null : (ShowFilterSegment) visit(ctx.showFilter()));
717         result.addParameterMarkers(getParameterMarkerSegments());
718         return result;
719     }
720     
721     @Override
722     public ASTNode visitShowCollation(final ShowCollationContext ctx) {
723         MySQLShowCollationStatement result = new MySQLShowCollationStatement(null == ctx.showFilter() ? null : (ShowFilterSegment) visit(ctx.showFilter()));
724         result.addParameterMarkers(getParameterMarkerSegments());
725         return result;
726     }
727     
728     @Override
729     public ASTNode visitShowFunctionStatus(final ShowFunctionStatusContext ctx) {
730         MySQLShowFunctionStatusStatement result = new MySQLShowFunctionStatusStatement(null == ctx.showFilter() ? null : (ShowFilterSegment) visit(ctx.showFilter()));
731         result.addParameterMarkers(getParameterMarkerSegments());
732         return result;
733     }
734     
735     @Override
736     public ASTNode visitShowProcedureStatus(final ShowProcedureStatusContext ctx) {
737         MySQLShowProcedureStatusStatement result = new MySQLShowProcedureStatusStatement(null == ctx.showFilter() ? null : (ShowFilterSegment) visit(ctx.showFilter()));
738         result.addParameterMarkers(getParameterMarkerSegments());
739         return result;
740     }
741     
742     @Override
743     public ASTNode visitShowOpenTables(final ShowOpenTablesContext ctx) {
744         MySQLShowOpenTablesStatement result = new MySQLShowOpenTablesStatement(
745                 null == ctx.fromDatabase() ? null : (FromDatabaseSegment) visit(ctx.fromDatabase()), null == ctx.showFilter() ? null : (ShowFilterSegment) visit(ctx.showFilter()));
746         result.addParameterMarkers(getParameterMarkerSegments());
747         return result;
748     }
749     
750     @Override
751     public ASTNode visitShowPlugins(final ShowPluginsContext ctx) {
752         return new MySQLShowPluginsStatement();
753     }
754     
755     @Override
756     public ASTNode visitShowPrivileges(final ShowPrivilegesContext ctx) {
757         return new MySQLShowPrivilegesStatement();
758     }
759     
760     @Override
761     public ASTNode visitShutdown(final ShutdownContext ctx) {
762         return new MySQLShutdownStatement();
763     }
764     
765     @Override
766     public ASTNode visitShowProcesslist(final ShowProcesslistContext ctx) {
767         return new MySQLShowProcessListStatement(null != ctx.FULL());
768     }
769     
770     @Override
771     public ASTNode visitShowCreateUser(final ShowCreateUserContext ctx) {
772         return new MySQLShowCreateUserStatement(((IdentifierValue) visit(ctx.username())).getValue());
773     }
774     
775     @Override
776     public ASTNode visitSetVariable(final SetVariableContext ctx) {
777         return new SetStatement(getVariableAssigns(ctx.optionValueList()));
778     }
779     
780     private List<VariableAssignSegment> getVariableAssigns(final OptionValueListContext ctx) {
781         List<VariableAssignSegment> result = new LinkedList<>();
782         result.add(null == ctx.optionValueNoOptionType() ? getVariableAssignSegment(ctx) : getVariableAssignSegment(ctx.optionValueNoOptionType()));
783         for (OptionValueContext each : ctx.optionValue()) {
784             result.add(getVariableAssignSegment(each));
785         }
786         return result;
787     }
788     
789     private VariableAssignSegment getVariableAssignSegment(final OptionValueContext ctx) {
790         if (null != ctx.optionValueNoOptionType()) {
791             return getVariableAssignSegment(ctx.optionValueNoOptionType());
792         }
793         VariableSegment variable = new VariableSegment(
794                 ctx.internalVariableName().start.getStartIndex(), ctx.internalVariableName().stop.getStopIndex(), ctx.internalVariableName().getText(), ctx.optionType().getText());
795         return new VariableAssignSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), variable, ctx.setExprOrDefault().getText());
796     }
797     
798     private VariableAssignSegment getVariableAssignSegment(final OptionValueListContext ctx) {
799         VariableSegment variable = new VariableSegment(
800                 ctx.internalVariableName().start.getStartIndex(), ctx.internalVariableName().stop.getStopIndex(), ctx.internalVariableName().getText(), ctx.optionType().getText());
801         return new VariableAssignSegment(ctx.start.getStartIndex(), ctx.setExprOrDefault().stop.getStopIndex(), variable, ctx.setExprOrDefault().getText());
802     }
803     
804     private VariableAssignSegment getVariableAssignSegment(final OptionValueNoOptionTypeContext ctx) {
805         return new VariableAssignSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), getVariableSegment(ctx), getAssignValue(ctx));
806     }
807     
808     private VariableSegment getVariableSegment(final OptionValueNoOptionTypeContext ctx) {
809         if (null != ctx.NAMES()) {
810             // TODO Consider setting all three system variables: character_set_client, character_set_results, character_set_connection
811             return new VariableSegment(ctx.NAMES().getSymbol().getStartIndex(), ctx.NAMES().getSymbol().getStopIndex(), "character_set_client");
812         }
813         if (null != ctx.internalVariableName()) {
814             return new VariableSegment(ctx.internalVariableName().start.getStartIndex(), ctx.internalVariableName().stop.getStopIndex(), ctx.internalVariableName().getText());
815         }
816         if (null != ctx.userVariable()) {
817             return new VariableSegment(ctx.userVariable().start.getStartIndex(), ctx.userVariable().stop.getStopIndex(), ctx.userVariable().getText());
818         }
819         if (null != ctx.setSystemVariable()) {
820             VariableSegment result = new VariableSegment(
821                     ctx.setSystemVariable().start.getStartIndex(), ctx.setSystemVariable().stop.getStopIndex(), ctx.setSystemVariable().internalVariableName().getText());
822             OptionTypeContext optionType = ctx.setSystemVariable().optionType();
823             result.setScope(null == optionType ? "SESSION" : optionType.getText());
824             return result;
825         }
826         return null;
827     }
828     
829     private String getAssignValue(final OptionValueNoOptionTypeContext ctx) {
830         if (null != ctx.NAMES()) {
831             return ctx.charsetName().getText();
832         } else if (null != ctx.internalVariableName()) {
833             return ctx.setExprOrDefault().getText();
834         } else if (null != ctx.userVariable()) {
835             return ctx.expr().getText();
836         } else if (null != ctx.setSystemVariable()) {
837             return ctx.setExprOrDefault().getText();
838         }
839         return null;
840     }
841     
842     @Override
843     public ASTNode visitSetCharacter(final SetCharacterContext ctx) {
844         int startIndex = null == ctx.CHARSET() ? ctx.CHARACTER().getSymbol().getStartIndex() : ctx.CHARSET().getSymbol().getStartIndex();
845         int stopIndex = null == ctx.CHARSET() ? ctx.SET(1).getSymbol().getStopIndex() : ctx.CHARSET().getSymbol().getStopIndex();
846         // TODO Consider setting all three system variables: character_set_client, character_set_results, character_set_connection
847         String variableName = (null == ctx.CHARSET()) ? "character_set_client" : ctx.CHARSET().getText();
848         VariableSegment variable = new VariableSegment(startIndex, stopIndex, variableName);
849         String assignValue = (null == ctx.DEFAULT()) ? ctx.charsetName().getText() : ctx.DEFAULT().getText();
850         return new SetStatement(Collections.singletonList(new VariableAssignSegment(startIndex, stopIndex, variable, assignValue)));
851     }
852     
853     @Override
854     public ASTNode visitFromDatabase(final FromDatabaseContext ctx) {
855         return new FromDatabaseSegment(ctx.getStart().getStartIndex(), (DatabaseSegment) visit(ctx.databaseName()));
856     }
857     
858     @Override
859     public ASTNode visitShowLike(final ShowLikeContext ctx) {
860         StringLiteralValue literalValue = (StringLiteralValue) visit(ctx.stringLiterals());
861         return new ShowLikeSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), literalValue.getValue());
862     }
863     
864     @Override
865     public ASTNode visitCreateLoadableFunction(final CreateLoadableFunctionContext ctx) {
866         return new MySQLCreateLoadableFunctionStatement();
867     }
868     
869     @Override
870     public ASTNode visitInstallComponent(final InstallComponentContext ctx) {
871         return new MySQLInstallComponentStatement(ctx.componentName().stream().map(each -> ((StringLiteralValue) visit(each.string_())).getValue()).collect(Collectors.toList()));
872     }
873     
874     @Override
875     public ASTNode visitUninstallComponent(final UninstallComponentContext ctx) {
876         return new MySQLUninstallComponentStatement(ctx.componentName().stream().map(each -> ((StringLiteralValue) visit(each.string_())).getValue()).collect(Collectors.toList()));
877     }
878     
879     @Override
880     public ASTNode visitRestart(final RestartContext ctx) {
881         return new MySQLRestartStatement();
882     }
883     
884     @Override
885     public ASTNode visitSetResourceGroup(final SetResourceGroupContext ctx) {
886         return new MySQLSetResourceGroupStatement(((IdentifierValue) visit(ctx.groupName())).getValue());
887     }
888     
889     @Override
890     public ASTNode visitCheckTable(final CheckTableContext ctx) {
891         return new MySQLCheckTableStatement(((CollectionValue<SimpleTableSegment>) visit(ctx.tableList())).getValue());
892     }
893     
894     @Override
895     public ASTNode visitDropResourceGroup(final DropResourceGroupContext ctx) {
896         return new MySQLDropResourceGroupStatement(((IdentifierValue) visit(ctx.groupName())).getValue());
897     }
898     
899     @Override
900     public ASTNode visitAlterResourceGroup(final AlterResourceGroupContext ctx) {
901         return new MySQLAlterResourceGroupStatement(((IdentifierValue) visit(ctx.groupName())).getValue());
902     }
903     
904     @Override
905     public ASTNode visitChangeMasterTo(final ChangeMasterToContext ctx) {
906         return new MySQLChangeMasterStatement();
907     }
908     
909     @Override
910     public ASTNode visitStartSlave(final StartSlaveContext ctx) {
911         return new MySQLStartSlaveStatement();
912     }
913     
914     @Override
915     public ASTNode visitStopSlave(final StopSlaveContext ctx) {
916         return new MySQLStopSlaveStatement();
917     }
918     
919     @Override
920     public ASTNode visitChangeReplicationSourceTo(final ChangeReplicationSourceToContext ctx) {
921         return new MySQLChangeReplicationSourceToStatement();
922     }
923     
924     @Override
925     public ASTNode visitStartReplica(final MySQLStatementParser.StartReplicaContext ctx) {
926         return new MySQLStartReplicaStatement();
927     }
928     
929     @Override
930     public ASTNode visitDelimiter(final DelimiterContext ctx) {
931         return new MySQLDelimiterStatement(ctx.delimiterName().getText());
932     }
933     
934     @Override
935     public ASTNode visitHelp(final HelpContext ctx) {
936         return new MySQLHelpStatement(ctx.textOrIdentifier().getText());
937     }
938 }