001package gudusoft.gsqlparser.nodes;
002
003import gudusoft.gsqlparser.*;
004import gudusoft.gsqlparser.nodes.hive.THiveKeyValueProperty;
005import gudusoft.gsqlparser.nodes.hive.THiveTableBuckets;
006import gudusoft.gsqlparser.nodes.hive.THiveTableFileFormat;
007import gudusoft.gsqlparser.nodes.hive.THiveTableSkewed;
008import gudusoft.gsqlparser.nodes.mysql.TMySQLIndexOption;
009import gudusoft.gsqlparser.nodes.postgresql.TPartitionBoundSpecSqlNode;
010import gudusoft.gsqlparser.nodes.mssql.TPeriodForClause;
011
012import java.util.ArrayList;
013
014/**
015 *  Type of alter table option, {@link #getOptionType()} returns the type of various option:
016 *  <br>
017 *  <p>Column</p>
018 *  <ul>
019 *      <li>{@link EAlterTableOptionType#AddColumn}, check {@link #getColumnDefinitionList()} for newly added columns</li>
020 *      <li>{@link EAlterTableOptionType#AlterColumn}, alter column option, {@link #getColumnName()} returns the column name.
021 *      <br>check {@link #getAlterColumnSubType()} for the subtype of alter column option.
022 *      <ul>
023 *          <li>{@link EAlterColumnSubType#SetDefault}, {@link #getDefaultExpr()} returns default expression</li>
024 *          <li>{@link EAlterColumnSubType#DropDefault}</li>
025 *          <li>{@link EAlterColumnSubType#DropNotNull}</li>
026 *          <li>{@link EAlterColumnSubType#SetNotNull}</li>
027 *          <li>{@link EAlterColumnSubType#SetStatistics}, {@link #getStatisticsValue} returns the statistics value</li>
028 *          <li>{@link EAlterColumnSubType#SetOptions}, {@link #getAttributeOptions} returns the set options</li>
029 *          <li>{@link EAlterColumnSubType#ResetOptions}, {@link #getAttributeOptions} returns the reset options</li>
030 *          <li>{@link EAlterColumnSubType#SetStorage}, {@link #getStorageName} retuns the storage name</li>
031 *          <li>{@link EAlterColumnSubType#SetDataType}, {@link #getNewDataType returns the data type name}</li>
032 *      </ul>
033 *      </li>
034 *      <li>{@link EAlterTableOptionType#ChangeColumn}, MySQL,Hive,Impala change column clause, {@link #getColumnName() old column name},{@link #getNewColumnDef() new column definition}</li>
035 *      <li>{@link EAlterTableOptionType#DropColumn}, check {@link #getColumnNameList()} for dropped columns. {@link #getDropRestrictType()} returns drop restrict type if any.</li>
036 *      <li>{@link EAlterTableOptionType#ModifyColumn}, check {@link #getColumnDefinitionList()} for modified columns</li>
037 *      <li>{@link EAlterTableOptionType#RenameColumn}, rename {@link #getColumnName() old name} to {@link #getNewColumnName() new name}</li>
038 *      <li>{@link EAlterTableOptionType#SetUnUsedColumn}, check {@link #getColumnNameList()} for unused column. Oracle set unused column.</li>
039 *      <li>{@link EAlterTableOptionType#DropUnUsedColumn}, Oracle drop unused columns</li>
040 *      <li>{@link EAlterTableOptionType#DropColumnsContinue}, Oracle drop columns continue</li>
041 *</ul>
042 * <p>Constraint</p>
043 * <ul>
044 *      <li>{@link EAlterTableOptionType#AddConstraint}, check {@link #getConstraintList()} for newly added table level constraints</li>
045 *      <li>{@link EAlterTableOptionType#AddConstraintPK}, {@link #getColumnNameList() primary key column list}. MySQL, {@link #getConstraintName()} returns the constraint name</li>
046 *      <li>{@link EAlterTableOptionType#AddConstraintUnique}, {@link #getColumnNameList() unique key column list}. MyQL,{@link #getConstraintName()} returns the constraint name</li>
047 *      <li>{@link EAlterTableOptionType#AddConstraintFK}, {@link #getColumnNameList() unique key column list},
048 *          {@link #getConstraintName() [constraint name]},
049 *          {@link #getReferencedObjectName() [referenced table name]},
050 *          {@link #getReferencedColumnList() [referenced column list]},MySQL</li>
051 *      <li>{@link EAlterTableOptionType#AddConstraintIndex}, check {@link #getColumnNameList() index column list},
052 *          {@link #getConstraintName() [constraint name]},{@link #getMySQLIndexStorageType() [index storage type]} MySQL add index constraint</li>
053 *      <li>{@link EAlterTableOptionType#DropConstraint}, {@link #getConstraintNameList() constraint name list}, {@link #getDropRestrictType() [drop restrict type]}, Oracle/DB2/Greenplum drop constraint. </li>
054 *      <li>{@link EAlterTableOptionType#AlterConstraintFK}, DB2 alter foreign key. </li>
055 *      <li>{@link EAlterTableOptionType#AlterConstraintCheck}, {@link #getConstraintName() check constraint name }, DB2 alter check constraint. </li>
056 *      <li>{@link EAlterTableOptionType#DropConstraintIndex}, {@link #getConstraintName() constriant name}, MySQL drop index </li>
057 *      <li>{@link EAlterTableOptionType#DropConstraintKey}, {@link #getConstraintName() constriant name}, MySQL drop index </li>
058 *      <li>{@link EAlterTableOptionType#DropConstraintPK}, Oracle/DB2/MySQL drop primary key. </li>
059 *      <li>{@link EAlterTableOptionType#DropConstraintFK},{@link #getConstraintName() [constriant name]}, DB2/MySQL drop foreign key. </li>
060 *      <li>{@link EAlterTableOptionType#DropConstraintUnique}, In Oracle, get {@link #getColumnNameList() unique column list}, In DB2, get {@link #getConstraintName() constraint name}. </li>
061 *      <li>{@link EAlterTableOptionType#DropConstraintCheck}, {@link #getConstraintName() check constraint name}, DB2 drop check constraint. </li>
062 *      <li>{@link EAlterTableOptionType#ModifyConstraint}, check {@link #getConstraintName() constraint name} </li>
063 *      <li>{@link EAlterTableOptionType#RenameConstraint}, rename {@link #getConstraintName() old name} to {@link #getNewConstraintName() new name} </li>
064 *      <li>{@link EAlterTableOptionType#ValidateConstraint},  {@link #getConstraintName() constraint name}, greenplum/postgresql</li>
065 *</ul>
066 * <p>Enable/disable</p>
067 * <ul>
068 *       <li>{@link EAlterTableOptionType#enableTrigger}, {@link #getTriggerName() trigger name}, greenplum/postgresql. </li>
069 *       <li>{@link EAlterTableOptionType#enableAlwaysTrigger}, {@link #getTriggerName() trigger name}, greenplum/postgresql. </li>
070 *       <li>{@link EAlterTableOptionType#enableReplicaTrigger}, {@link #getTriggerName() trigger name}, greenplum/postgresql. </li>
071 *       <li>{@link EAlterTableOptionType#disableTrigger}, {@link #getTriggerName() trigger name}, greenplum/postgresql. </li>
072 *       <li>{@link EAlterTableOptionType#enableRule}, {@link #getRuleName() rule name}, greenplum/postgresql. </li>
073 *       <li>{@link EAlterTableOptionType#enableAlwaysRule}, {@link #getRuleName() rule name}, greenplum/postgresql. </li>
074 *       <li>{@link EAlterTableOptionType#enableReplicaRule}, {@link #getRuleName() rule name}, greenplum/postgresql. </li>
075 *       <li>{@link EAlterTableOptionType#disableRule}, {@link #getRuleName() rule name}, greenplum. </li>
076 * </ul>
077 * <p>Others</p>
078 * <ul>
079 *       <li>{@link EAlterTableOptionType#RenameTable}, {@link #getNewTableName() new table name} </li>
080 *       <li>{@link EAlterTableOptionType#inherit}, {@link #getParentTable() parent table}, greenplum/postgresql. </li>
081 *       <li>{@link EAlterTableOptionType#noInherit}, {@link #getParentTable() parent table}, greenplum/postgresql. </li>
082 *
083 *       <li>{@link EAlterTableOptionType#ofAnyType}, {@link #getAnyTypeName() type name}, greenplum/postgresql. </li>
084 *
085 *       <li>{@link EAlterTableOptionType#ownerTo}, {@link #getNewOwnerName() owner name}, greenplum/postgresql. </li>
086 *       <li>{@link EAlterTableOptionType#setTablespace}, {@link #getNewTablespaceName() tablespace name}, greenplum/postgresql. </li>
087 *
088 *        <li>{@link EAlterTableOptionType#setSchema}, {@link #getSchemaName() schema name}, greenplum. </li>
089 *        <li>{@link EAlterTableOptionType#clusterOn}, {@link #getIndexName() index name}, postgresql. </li>
090 *
091 *  </ul>
092 */
093public class TAlterTableOption extends TParseTreeNode {
094
095    private TPeriodForClause periodForClause;
096
097    public TPeriodForClause getPeriodForClause() {
098        return periodForClause;
099    }
100
101    public void setPeriodForClause(TPeriodForClause periodForClause) {
102        this.periodForClause = periodForClause;
103    }
104
105    public static EAlterTableOptionType getAlterTableOptionTypeByToken(TSourceToken st){
106        if (st == null) return EAlterTableOptionType.RenameTable;
107        if (st.toString().equalsIgnoreCase("index")) return EAlterTableOptionType.renameIndex;
108        if (st.toString().equalsIgnoreCase("key")) return EAlterTableOptionType.renameIndex;
109
110        return EAlterTableOptionType.Unknown;
111    }
112    private TBaseTablePartition tablePartition;
113
114    public TBaseTablePartition getTablePartition() {
115        return tablePartition;
116    }
117
118    public void adjustOptionByToken(TSourceToken st){
119        if (st == null) return;
120
121        switch (getOptionType()){
122            case AddConstraintIndex:
123                if (st.tokencode == TBaseType.rrw_unique){
124                    setOptionType(EAlterTableOptionType.AddConstraintUnique);
125                }
126                break;
127        }
128    }
129    public TMySQLCreateTableOption getMySQLTableOption() {
130        return mySQLTableOption;
131    }
132
133    private  TMySQLCreateTableOption mySQLTableOption;
134
135    public void setPartitionBoundSpec(TPartitionBoundSpecSqlNode partitionBoundSpec) {
136        this.partitionBoundSpec = partitionBoundSpec;
137    }
138
139    public TPartitionBoundSpecSqlNode getPartitionBoundSpec() {
140        return partitionBoundSpec;
141    }
142
143    /**
144     * postgresql PartitionBoundSpec
145     * https://www.postgresql.org/docs/current/sql-createtable.html
146     */
147    private TPartitionBoundSpecSqlNode partitionBoundSpec;
148
149    public static final int COLUMN_POSITION_NONE = 0;
150    public static final int COLUMN_POSITION_FIRST = 1;
151    public static final int COLUMN_POSITION_AFTER = 2;
152
153    private int columnPosition = COLUMN_POSITION_NONE;
154    private TObjectName afterColumnName;
155
156    public TObjectName getAfterColumnName() {
157        return afterColumnName;
158    }
159
160    public int getColumnPosition() {
161        return columnPosition;
162    }
163
164    public void setColumnPosition(TDummy node){
165        if (node == null) return;
166        if (node.node1 != null){
167            this.columnPosition = COLUMN_POSITION_AFTER;
168            this.afterColumnName = (TObjectName)node.node1;
169        }else{
170            this.columnPosition = COLUMN_POSITION_FIRST;
171        }
172    }
173
174    private EAlterColumnSubType AlterColumnSubType = EAlterColumnSubType.unknown;
175
176    /**
177     * subtype of alter column.
178     * @return subtype of alter column.
179     */
180    public EAlterColumnSubType getAlterColumnSubType() {
181        return AlterColumnSubType;
182    }
183
184    private TPTNodeList <TMySQLIndexOption> indexOptionList;
185
186    public void setIndexOptionList(TPTNodeList<TMySQLIndexOption> indexOptionList) {
187        this.indexOptionList = indexOptionList;
188    }
189
190    /**
191     * MySQL, index options
192     * @return index options
193     */
194    public TPTNodeList<TMySQLIndexOption> getIndexOptionList() {
195
196        return indexOptionList;
197    }
198
199    private TPTNodeList <TColumnWithSortOrder > indexCols;
200
201    public void setIndexCols(TPTNodeList<TColumnWithSortOrder > indexCols) {
202        this.indexCols = indexCols;
203    }
204
205    /**
206     * MySQL, column list of foreign key
207     *
208     *
209     * @return column list of foreign key
210     */
211    public TPTNodeList<TColumnWithSortOrder > getIndexCols() {
212
213        return indexCols;
214    }
215
216    private TObjectName serdeName;
217
218    private TResultColumnList mutationUpdateList;
219
220    /**
221     * ClickHouse ALTER TABLE ... UPDATE set list.
222     * Valid when {@link #getOptionType()} is {@link EAlterTableOptionType#clickhouseUpdateMutation}.
223     * @return the SET column assignment list
224     */
225    public TResultColumnList getMutationUpdateList() {
226        return mutationUpdateList;
227    }
228
229    /**
230     * ClickHouse ALTER TABLE ... DELETE WHERE / UPDATE ... WHERE condition.
231     * Valid when {@link #getOptionType()} is {@link EAlterTableOptionType#clickhouseDeleteMutation}
232     * or {@link EAlterTableOptionType#clickhouseUpdateMutation}.
233     * @return the WHERE condition expression
234     */
235    public TExpression getMutationWhereCondition() {
236        return defaultExpr;
237    }
238
239    private TParseTreeNode partitionExpr;
240
241    /**
242     * ClickHouse ALTER TABLE partition expression.
243     * Valid when {@link #getOptionType()} is one of the clickhouse partition operations
244     * (e.g., {@link EAlterTableOptionType#clickhouseDetachPartition},
245     * {@link EAlterTableOptionType#clickhouseAttachPartition}, etc.).
246     * @return the partition expression node (integer, string, identifier, or tuple)
247     */
248    public TParseTreeNode getPartitionExpr() {
249        return partitionExpr;
250    }
251
252    private EKeyReferenceType dropRestrictType = EKeyReferenceType.no_action;
253
254    public void setDropRestrictType(TSourceToken st) {
255        if (st == null) return;
256
257        if (st.tokencode == TBaseType.rrw_cascade ){
258            this.dropRestrictType = EKeyReferenceType.cascade;
259        }else if (st.tokencode == TBaseType.rrw_restrict){
260            this.dropRestrictType = EKeyReferenceType.restrict;
261        }
262
263    }
264
265    /**
266     * drop restrict type such as: cascade, restrict
267     * @return drop restrict type such as: cascade, restrict
268     */
269    public EKeyReferenceType getDropRestrictType() {
270
271        return dropRestrictType;
272    }
273
274    /**
275     * Type of this alter table option
276     * @return Type of this alter table option
277     */
278    public EAlterTableOptionType getOptionType() {
279        return optionType;
280    }
281
282    /**
283     * referenced table in foreign key clause
284     * @return referenced table in foreign key clause
285     */
286    public TTable getReferencedTable() {
287        return referencedTable;
288    }
289
290    private TTable referencedTable = null;
291
292    private TObjectName partitionName;
293
294
295    /**
296     * partition name in PostgreSQL attached partition clause.
297     *
298     * @return partition name
299     */
300    public TObjectName getPartitionName() {
301        return partitionName;
302    }
303
304    private TColumnDefinitionList columnDefinitionList = null;
305    private TConstraintList constraintList = null;
306    private TObjectNameList columnNameList = null;
307    private TObjectName columnName = null;
308    private TObjectName newColumnName = null;
309    private TObjectName constraintName = null;
310    private TObjectName newConstraintName = null;
311    private TObjectName referencedObjectName = null;
312    private TObjectNameList referencedColumnList = null;
313    private TObjectName newTableName = null;
314    private TExpression defaultExpr = null;
315    private TConstant statisticsValue = null;
316    private ArrayList<TAttributeOption> attributeOptions;
317    private TObjectName storageName = null;
318    private TTypeName   newDataType = null;
319    private TObjectName newCollation = null;
320    private TExpression usingExpr = null;
321    private TConstraint tableConstraint = null;
322    private TObjectName indexName = null;
323    private TObjectName triggerName = null;
324    private TObjectName ruleName = null;
325    private TObjectName parentTable = null;
326    private TObjectName anyTypeName = null;
327    private TObjectName newOwnerName = null;
328    private TObjectName newTablespaceName = null;
329    private TObjectName schemaName = null;
330    private TObjectNameList constraintNameList = null;
331    private TExpression partitionExpression1 = null;
332
333    private TObjectName sourceTableName = null;
334
335    /**
336     * redshift alter table... append from source table
337     * @return redshift alter table... append from source table
338     */
339    public TObjectName getSourceTableName() {
340        return sourceTableName;
341    }
342
343    /**
344     * SQL Server, target_partition_number_expression in switch partition clause
345     * @return
346     */
347    public TExpression getPartitionExpression2() {
348        return partitionExpression2;
349    }
350
351    /**
352     * SQL Server, source_partition_number_expression in switch partition clause
353     * @return source_partition_number_expression
354     */
355    public TExpression getPartitionExpression1() {
356        return partitionExpression1;
357    }
358
359    private TExpression partitionExpression2 = null;
360
361    /**
362     * constraint name list when option type is: {@link EAlterTableOptionType#DropConstraint}
363     *
364     * @return constraint name list
365     */
366    public TObjectNameList getConstraintNameList() {
367        return constraintNameList;
368    }
369
370    /**
371     * Greenplum, Schema name when option type is {@link EAlterTableOptionType#setSchema}
372     *
373     * @return schema name
374     */
375    public TObjectName getSchemaName() {
376        return schemaName;
377    }
378
379    public void setNewTablespaceName(TObjectName newTablespaceName) {
380        this.newTablespaceName = newTablespaceName;
381    }
382
383    /**
384    * Greenplum, Postgresql, Snowflake, tablespace name when option type is {@link EAlterTableOptionType#setTablespace}
385     *
386    * @return tablespace name
387    */
388    public TObjectName getNewTablespaceName() {
389
390        return newTablespaceName;
391    }
392
393    public void setNewOwnerName(TObjectName newOwnerName) {
394        this.newOwnerName = newOwnerName;
395    }
396
397    /**
398    * owner name or roleId when option type is {@link EAlterTableOptionType#ownerTo}
399     *
400    * @return owner name or role id
401    */
402    public TObjectName getNewOwnerName() {
403
404        return newOwnerName;
405    }
406
407    public void setAnyTypeName(TObjectName anyTypeName) {
408        this.anyTypeName = anyTypeName;
409    }
410
411     /**
412     * Greenplum, Postgresql,Snowflake, any name when option type is {@link EAlterTableOptionType#ofAnyType}
413      *
414     * @return any name
415     */
416    public TObjectName getAnyTypeName() {
417
418        return anyTypeName;
419    }
420
421    public void setParentTable(TObjectName parentTable) {
422        this.parentTable = parentTable;
423    }
424
425     /**
426     * Greenplum, Postgresql,Snowflake, parent table when option type is {@link EAlterTableOptionType#inherit} or
427      * {@link EAlterTableOptionType#noInherit}
428      *
429     * @return  parent table
430     */
431    public TObjectName getParentTable() {
432
433        return parentTable;
434    }
435
436    public void setRuleName(TObjectName ruleName) {
437        this.ruleName = ruleName;
438    }
439
440    /**
441     * Greenplum, Postgresql,Snowflake, rule name when option type is {@link EAlterTableOptionType#enableRule} or
442     * {@link EAlterTableOptionType#enableAlwaysRule} or  {@link EAlterTableOptionType#enableReplicaRule} or
443     * {@link EAlterTableOptionType#disableRule}
444     *
445     * @return rule name
446     */
447    public TObjectName getRuleName() {
448
449        return ruleName;
450    }
451
452    public void setTriggerName(TObjectName triggerName) {
453        this.triggerName = triggerName;
454    }
455
456
457    /**
458     * Greenplum, Postgresql,Snowflake, trigger name when option type is {@link EAlterTableOptionType#enableTrigger} or
459     * {@link EAlterTableOptionType#enableAlwaysTrigger} or  {@link EAlterTableOptionType#enableReplicaTrigger} or
460     * {@link EAlterTableOptionType#disableTrigger}
461     *
462     * @return trigger name
463     */
464    public TObjectName getTriggerName() {
465
466        return triggerName;
467    }
468
469    public void setIndexName(TObjectName indexName) {
470        this.indexName = indexName;
471    }
472
473    /**
474     * Greenplum, Postgresql, Snowflake, index name when option type is {@link EAlterTableOptionType#clusterOn}
475     *
476     * @return index name
477     */
478    public TObjectName getIndexName() {
479
480        return indexName;
481    }
482
483    private TObjectName newIndexName;
484
485    public TObjectName getNewIndexName() {
486        return newIndexName;
487    }
488
489    public void setTableConstraint(TConstraint tableConstraint) {
490        this.tableConstraint = tableConstraint;
491    }
492
493    /**
494     * table constraint when option type is {@link EAlterTableOptionType#AddConstraint}
495     *
496     * @return table constraint
497     */
498    public TConstraint getTableConstraint() {
499
500        return tableConstraint;
501    }
502
503    public void setUsingExpr(TExpression usingExpr) {
504        this.usingExpr = usingExpr;
505    }
506
507    /**
508     * using expr when option type is {@link gudusoft.gsqlparser.EAlterTableOptionType#AlterColumn} and subtype is {@link EAlterColumnSubType#SetDataType}
509     *
510     * @return using expr
511     */
512    public TExpression getUsingExpr() {
513        return usingExpr;
514    }
515
516    public void setNewCollation(TObjectName newCollation) {
517        this.newCollation = newCollation;
518    }
519
520    /**
521     * new collation when option type is {@link gudusoft.gsqlparser.EAlterTableOptionType#AlterColumn} and subtype is {@link EAlterColumnSubType#SetDataType}
522     *
523     * @return new collation
524     */
525    public TObjectName getNewCollation() {
526
527        return newCollation;
528    }
529
530    public void setNewDataType(TTypeName newDataType) {
531        this.newDataType = newDataType;
532    }
533
534    /**
535     * new data type when option type is {@link gudusoft.gsqlparser.EAlterTableOptionType#AlterColumn} and subtype is {@link EAlterColumnSubType#SetDataType}
536     *
537     * @return new data type
538     */
539    public TTypeName getNewDataType() {
540
541        return newDataType;
542    }
543
544    public void setStorageName(TObjectName storageName) {
545        this.storageName = storageName;
546    }
547
548    /**
549     * storage name when option type is {@link gudusoft.gsqlparser.EAlterTableOptionType#AlterColumn} and subtype is {@link EAlterColumnSubType#SetStorage}
550     *
551     * @return storage name
552     */
553    public TObjectName getStorageName() {
554
555        return storageName;
556    }
557
558    public void setAttributeOptions(ArrayList<TAttributeOption> attributeOptions) {
559        this.attributeOptions = attributeOptions;
560    }
561
562    /**
563     * Greenplum,PostgreSQL,Snowflake, set/reset options when option type is {@link gudusoft.gsqlparser.EAlterTableOptionType#AlterColumn} and subtype is {@link EAlterColumnSubType#SetOptions}
564     * or {@link EAlterColumnSubType#ResetOptions}
565     *
566     * @return set/reset options
567     */
568    public ArrayList<TAttributeOption> getAttributeOptions() {
569
570        return attributeOptions;
571    }
572
573    public void setStatisticsValue(TConstant statisticsValue) {
574        this.statisticsValue = statisticsValue;
575    }
576
577    /**
578     * Greenplum,PostgreSQL,Snowflake, statistics value when option type is {@link gudusoft.gsqlparser.EAlterTableOptionType#AlterColumn} and subtype is {@link EAlterColumnSubType#SetStatistics}
579     *
580     * @return statistcs value
581     */
582    public TConstant getStatisticsValue() {
583
584        return statisticsValue;
585    }
586
587    public void setDefaultExpr(TExpression defaultExpr) {
588        this.defaultExpr = defaultExpr;
589    }
590
591    /**
592     * MySQL, PostgreSQL, expression in set default clause of alter column.
593     *
594     * @return expression in set default clause of alter column.
595     */
596    public TExpression getDefaultExpr() {
597
598        return defaultExpr;
599    }
600
601    private TMySQLIndexStorageType mySQLIndexStorageType = null;
602    private TSourceToken mySQLIndexTypeToken = null;
603
604    public void setMySQLIndexTypeToken(TSourceToken mySQLIndexTypeToken) {
605        this.mySQLIndexTypeToken = mySQLIndexTypeToken;
606
607        if (mySQLIndexTypeToken == null) return;
608
609        switch (getOptionType()){
610            case AddConstraintIndex:
611                if (mySQLIndexTypeToken.tokencode == TBaseType.rrw_unique){
612                    setOptionType(EAlterTableOptionType.AddConstraintUnique);
613                }
614                break;
615        }
616    }
617
618    /**
619     * MySQL, unique, fulltext or spatial keyword used in add key/index clause when option type is {@link EAlterTableOptionType#AddConstraintIndex}
620     *
621     * @return unique, fulltext or spatial keyword
622     */
623    public TSourceToken getMySQLIndexTypeToken() {
624
625        return mySQLIndexTypeToken;
626    }
627
628    public void setMySQLIndexStorageType(TMySQLIndexStorageType mySQLIndexStorageType) {
629        this.mySQLIndexStorageType = mySQLIndexStorageType;
630    }
631
632    /**
633     * @deprecated As of v1.7.2.4. use {@link #getIndexOptionList()} instead.
634     * @return index storage type
635     */
636    public TMySQLIndexStorageType getMySQLIndexStorageType() {
637
638        return mySQLIndexStorageType;
639    }
640
641    /**
642     * set new table name when option type is {@link EAlterTableOptionType#RenameTable }
643     *
644     * @param newTableName the new table name
645     */
646    public void setNewTableName(TObjectName newTableName) {
647        this.newTableName = newTableName;
648        this.newTableName.setDbObjectType(EDbObjectType.table);
649    }
650
651    /**
652     * new table name is valid when option type is one of the following values:
653     * <ul>
654     *     <li>{@link EAlterTableOptionType#RenameTable}, new table in rename to clause</li>
655     *     <li>{@link EAlterTableOptionType#setPrivileges}, Netezza, table name in set privileges to clause </li>
656     *     <li>{@link EAlterTableOptionType#exchangePartition},Hive, Impala, table name in exchange partition with table clause </li>
657     *     <li>{@link EAlterTableOptionType#switchPartition}, SQL Server, Openedge, table name of switch partition to target_table clause </li>
658     * </ul>
659     *
660     * @return new table name
661     */
662    public TObjectName getNewTableName() {
663
664        return newTableName;
665    }
666
667    public void setReferencedColumnList(TObjectNameList referencedColumnList) {
668        this.referencedColumnList = referencedColumnList;
669    }
670
671    public void setReferencedObjectName(TObjectName referencedObjectName) {
672        this.referencedObjectName = referencedObjectName;
673    }
674
675    public void setColumnName(TObjectName columnName) {
676        this.columnName = columnName;
677    }
678
679    /**
680     * List of {@link TConstraint} in add constraint clause, valid when {@link #getOptionType()} is {@link EAlterTableOptionType#AddConstraint}
681     *
682     * @return constraint list
683     */
684    public TConstraintList getConstraintList() {
685        return constraintList;
686    }
687
688    private TObjectNameList nameList = null;
689
690    public TObjectNameList getNameList() {
691        if (this.nameList == null){
692
693            this.nameList = new TObjectNameList();
694        }
695        return nameList;
696    }
697
698    /**
699     * List of {@link TObjectNameList}, valid when {@link #getOptionType()} is:
700     * <p>{@link EAlterTableOptionType#SetUnUsedColumn}
701     * <p>{@link EAlterTableOptionType#DropColumn}
702     * <p>{@link EAlterTableOptionType#AddConstraintIndex}, columns of an index
703     * <p>{@link EAlterTableOptionType#AddConstraintPK}, columns of primary key
704     * <p>{@link EAlterTableOptionType#AddConstraintUnique}, columns of unique key
705     * <p>{@link EAlterTableOptionType#AddConstraintFK}, columns of foreign key
706     * <p>{@link EAlterTableOptionType#DropConstraintUnique}, available in Oracle
707     * @return column name list
708     */
709    public TObjectNameList getColumnNameList() {
710        if (this.columnNameList == null){
711
712            this.columnNameList = new TObjectNameList();
713        }
714        return columnNameList;
715    }
716
717    /**
718     * List of {@link TColumnDefinitionList}, valid when {@link #getOptionType()} is:
719     * <p>{@link EAlterTableOptionType#AddColumn}
720     * <p>{@link EAlterTableOptionType#ModifyColumn}
721     *
722     * @return column definition list
723     */
724    public TColumnDefinitionList getColumnDefinitionList() {
725        return columnDefinitionList;
726    }
727
728    /**
729     * valid when {@link #getOptionType()} is:
730     * <p>{@link EAlterTableOptionType#AlterColumn}
731     * <p>{@link EAlterTableOptionType#RenameColumn}
732     * <p>{@link EAlterTableOptionType#ChangeColumn}
733     *
734     * <p>{@link EAlterTableOptionType#AddConstraintIndex}, index name, optional
735     * @return column name
736     */
737    public TObjectName getColumnName() {
738        return columnName;
739    }
740
741    /**
742     *valid when {@link #getOptionType()} is:
743     * <p>{@link EAlterTableOptionType#AddConstraintPK}, optional
744     * <p>{@link EAlterTableOptionType#AddConstraintUnique}, optional
745     * <p>{@link EAlterTableOptionType#AddConstraintFK}, optional
746     * <p>{@link EAlterTableOptionType#ModifyConstraint}
747     * <p>{@link EAlterTableOptionType#RenameConstraint}
748     * <p>{@link EAlterTableOptionType#DropConstraintFK}
749     * <p>{@link EAlterTableOptionType#DropConstraintUnique}, available in DB2
750     * <p>{@link EAlterTableOptionType#DropConstraintCheck}, available in DB2
751     * <p>{@link EAlterTableOptionType#DropConstraintIndex}, available in DB2
752     * <p>{@link EAlterTableOptionType#DropConstraintKey}, available in DB2
753     * <p>{@link EAlterTableOptionType#AlterConstraintFK}, available in DB2
754     * <p>{@link EAlterTableOptionType#AlterConstraintCheck}, available in DB2
755     * @return constraint name
756     */
757    public TObjectName getConstraintName() {
758        return constraintName;
759    }
760
761    /**
762     * new column name valid when {@link #getOptionType()} is {@link EAlterTableOptionType#RenameColumn}
763     *
764     * @return new column name
765     */
766    public TObjectName getNewColumnName() {
767        return newColumnName;
768    }
769
770    /**
771     * new constraint name valid when {@link #getOptionType()} is {@link EAlterTableOptionType#RenameConstraint}
772     *
773     * @return new constraint name
774     */
775    public TObjectName getNewConstraintName() {
776        return newConstraintName;
777    }
778
779    /**
780     * MySQL, referenced column list in foreign key clause.
781     *
782     * @return referenced column list in foreign key clause.
783     */
784    public TObjectNameList getReferencedColumnList() {
785        return referencedColumnList;
786    }
787
788    /**
789     * referenced table in foreign key clause. Please use {@link #getReferencedTable} instead.
790     *
791     * @return referenced table in foreign key clause
792     */
793    public TObjectName getReferencedObjectName() {
794        return referencedObjectName;
795    }
796
797    public void init(Object arg1){
798        this.optionType = (EAlterTableOptionType)arg1;
799    }
800
801    public void init(Object arg1,Object arg2){
802        init(arg1);
803        switch (optionType){
804            case dropPartitionSpecList:
805            case addPartitionSpecList:
806            case touch:
807            case archive:
808            case unArchive:
809            case setPartitionLocation:
810                this.partitionSpecList = (ArrayList<TPartitionExtensionClause>)arg2;
811                break;
812            case setTableProperties:
813            case unsetTableProperties:
814                this.tableProperties = (TPTNodeList)arg2;
815                break;
816            case setFileFormat:
817                this.fileFormat = (THiveTableFileFormat)arg2;
818                break;
819            case setLocation:
820                this.tableLocation = (TObjectName)arg2;
821                break;
822            case serde:
823                serdeName = (TObjectName)arg2;
824                break;
825            case renamePartition:
826            case addPartition:
827            case dropPartition:
828                if (arg2 instanceof TObjectNameList){
829                    nameList = (TObjectNameList) arg2;
830                }
831                else if (arg2 instanceof TPartitionExtensionClause){
832                    newPartitionSpec= (TPartitionExtensionClause)arg2;
833                }
834                else if (arg2 instanceof ArrayList){
835                    partitionDefinitionList = (ArrayList<TPartitionDefinition>)arg2;
836                }
837                else{
838                    partitionSpecList = (ArrayList<TPartitionExtensionClause>)arg2;
839                    newPartitionSpec = partitionSpecList.get(0);
840                }
841
842                break;
843            case rebuildPartition:
844            case optimizePartition:
845            case repairPartition:
846            case analyzePartition:
847            case checkPartition:
848            case discardPartition:
849            case importPartition:
850            case truncatePartition:
851                nameList = (TObjectNameList) arg2;
852                break;
853            case dropCheck:
854                break;
855            case dropConstraint:
856                break;
857            case alterConstraint:
858                break;
859            case alterCheck:
860                break;
861            case coalescePartition:
862                break;
863            case tableBuckets:
864                numberOfBuckets = (TConstant)arg2;
865                break;
866            case skewedLocation:
867                skewedLocations = (TExpressionList)arg2;
868                break;
869            case clusteredSorted:
870                tableBuckets    = (THiveTableBuckets)arg2;
871                break;
872            case partitionColumn:
873                partitionColumnDef = (TColumnDefinition)arg2;
874                break;
875            case tableSkewed:
876                tableSkewed = (THiveTableSkewed)arg2;
877                break;
878            case setSchema:
879                schemaName = (TObjectName)arg2;
880                break;
881            case DropConstraint:
882                constraintNameList = (TObjectNameList)arg2;
883                if (constraintList != null){
884                    constraintName = constraintNameList.getObjectName(0);
885                }
886                break;
887            case CheckConstraint:
888            case NocheckConstraint:
889                constraintNameList = (TObjectNameList)arg2;
890                if (constraintNameList != null && constraintNameList.size() > 0){
891                    constraintName = constraintNameList.getObjectName(0);
892                }
893                break;
894            case modifyPrimaryKey:
895                indexName = (TObjectName)arg2;
896                break;
897            case switchPartition:
898                newTableName = (TObjectName)arg2;
899                break;
900            case AddConstraintIndex:
901            case AddConstraintPK:
902            case AddConstraintUnique:
903            case AddConstraintFK:
904                if (arg2 instanceof TPTNodeList){
905                    indexCols = (TPTNodeList)arg2;
906                }else{
907                    columnNameList = (TObjectNameList)arg2;
908                }
909                break;
910            case AddConstraintCheck:
911                defaultExpr = (TExpression)arg2;
912                break;
913            case clickhouseDeleteMutation:
914                defaultExpr = (TExpression)arg2;
915                break;
916            case clickhouseDropPartition:
917            case clickhouseDetachPartition:
918            case clickhouseAttachPartition:
919            case clickhouseFreezePartition:
920            case clickhouseUnfreezePartition:
921                partitionExpr = (TParseTreeNode)arg2;
922                break;
923            case setPrivileges:
924                newTableName = (TObjectName)arg2;
925                break;
926            case AddColumn:
927                this.columnDefinitionList = (TColumnDefinitionList)arg2;
928                break;
929            case AlterColumn:
930                this.columnName = (TObjectName)arg2;
931                this.columnName.setDbObjectType(EDbObjectType.column);
932                break;
933            case attachPartition:
934            case detachPartition:
935                partitionName = (TObjectName)arg2;
936                break;
937            case swapWith:
938                newTableName = (TObjectName)arg2;
939                break;
940            case setDataRetentionTimeInDays:
941                break;
942            case setComment:
943                break;
944            case RenameTable:
945                newTableName = (TObjectName)arg2;
946                newTableName.setDbObjectType(EDbObjectType.table);
947                break;
948            case appendFrom:
949                this.sourceTableName = (TObjectName) arg2;
950                break;
951            case AddConstraint:
952                if (arg2 instanceof TConstraint){
953                    this.tableConstraint = (TConstraint) arg2;
954                }else if (arg2 instanceof TConstraintList){
955                    this.constraintList  = (TConstraintList) arg2;
956                }
957                break;
958            case mysqlTableOption:
959                this.mySQLTableOption = (TMySQLCreateTableOption)arg2;
960                break;
961            case renameIndex:
962                this.indexName = (TObjectName)arg2;
963                this.indexName.setDbObjectTypeDirectly(EDbObjectType.index);
964                break;
965            case partition:
966                this.tablePartition = (TBaseTablePartition) arg2;
967                break;
968            case addPeriodForClause:
969                this.periodForClause = (TPeriodForClause)arg2;
970                break;
971            default:
972                if (arg2 instanceof TColumnDefinitionList){
973                   this.columnDefinitionList = (TColumnDefinitionList)arg2;
974                }else if (arg2 instanceof TConstraintList){
975                   this.constraintList = (TConstraintList)arg2;
976                }else if (arg2 instanceof TObjectNameList) {
977
978                   this.columnNameList = (TObjectNameList)arg2;
979                }else if (arg2 instanceof TDummyList) {
980                   TDummyList dlist = (TDummyList)arg2;
981                    TDummy dm = null;
982                   for(int i=0;i<dlist.size();i++){
983                       dm = dlist.getDummyItem(i);
984                       this.getColumnNameList().addObjectName((TObjectName)dm.node1);
985                   }
986
987                   if ((optionType == EAlterTableOptionType.DropColumn)&&(this.getColumnNameList().size() > 0)){
988                       this.columnName = this.getColumnNameList().getObjectName(0);
989                   }
990                }
991                break;
992
993        }
994
995     }
996
997
998    private String comment;
999
1000    public String getComment() {
1001        return comment;
1002    }
1003
1004    private TExpression commentExpr;
1005
1006    public TExpression getCommentExpr() {
1007        return commentExpr;
1008    }
1009
1010    public void setNewConstraintName(TObjectName newConstraintName) {
1011        this.newConstraintName = newConstraintName;
1012    }
1013
1014    public void setConstraintName(TDummy pName) {
1015        if (pName == null) return;
1016        if (pName.node1 == null) return;
1017        this.constraintName = (TObjectName)pName.node1;
1018    }
1019    public void setConstraintName(TObjectName constraintName) {
1020
1021        this.constraintName = constraintName;
1022    }
1023
1024    private TColumnDefinition newColumnDef;
1025
1026    /**
1027     *
1028     * @return {@link TColumnDefinition}, valid when {@link #getOptionType()} is:
1029     * <p>{@link EAlterTableOptionType#ChangeColumn}
1030     */
1031
1032    public TColumnDefinition getNewColumnDef() {
1033        return newColumnDef;
1034    }
1035
1036    /**
1037     *
1038     * valid when {@link #getOptionType()} is:
1039     * <p>{@link EAlterTableOptionType#serde}
1040     * @return serde name
1041     */
1042    public TObjectName getSerdeName() {
1043        return serdeName;
1044    }
1045
1046    public void init(Object arg1,Object arg2,Object arg3){
1047        init(arg1);
1048        switch (optionType){
1049            case AlterColumn:
1050                init(arg1,arg2);
1051                AlterColumnSubType = (EAlterColumnSubType)arg3;
1052                break;
1053            case ChangeColumn:
1054                this.columnName = (TObjectName)arg2;
1055                this.newColumnDef = (TColumnDefinition)arg3;
1056
1057                break;
1058            case serde:
1059                serdeName  = (TObjectName)arg2;
1060                tableProperties = (TPTNodeList)arg3;
1061
1062                break;
1063            case exchangePartition:
1064                if ((dbvendor == EDbVendor.dbvoracle)
1065                        ||(dbvendor == EDbVendor.dbvgaussdb)||(dbvendor == EDbVendor.dbvedb)||(dbvendor == EDbVendor.dbvgreenplum)
1066                        ||(dbvendor == EDbVendor.dbvmysql)){
1067                    partitionName = (TObjectName)arg2;
1068                    partitionName.setDbObjectType(EDbObjectType.partition);
1069                }else{
1070                    exchangePartitionSpec = (TPartitionExtensionClause)arg2;
1071                }
1072
1073                newTableName = (TObjectName)arg3;
1074                newTableName.setDbObjectType(EDbObjectType.table);
1075                break;
1076            case RenameColumn:
1077                this.columnName = (TObjectName)arg2;
1078                this.newColumnName = (TObjectName)arg3;
1079                break;
1080            case modifyPrimaryKey:
1081                if (arg2 !=null){
1082                    indexName = (TObjectName)arg2;
1083                }
1084                columnNameList = (TObjectNameList)arg3;
1085                break;
1086            case switchPartition:
1087                newTableName = (TObjectName)arg2;
1088                partitionExpression1 = (TExpression)arg3;
1089                break;
1090            case attachPartition:
1091                partitionName = (TObjectName)arg2;
1092                partitionBoundSpec = (TPartitionBoundSpecSqlNode) arg3;
1093                break;
1094            case reorganizePartition:
1095                nameList = (TObjectNameList) arg2;
1096                partitionDefinitionList = (ArrayList<TPartitionDefinition>)arg3;
1097                break;
1098            case renameIndex:
1099                this.indexName = (TObjectName)arg2;
1100                this.indexName.setDbObjectTypeDirectly(EDbObjectType.index);
1101                this.newIndexName  = (TObjectName)arg3;
1102                this.newIndexName.setDbObjectTypeDirectly(EDbObjectType.index);
1103                break;
1104            case clickhouseUpdateMutation:
1105                this.mutationUpdateList = (TResultColumnList)arg2;
1106                this.defaultExpr = (TExpression)arg3;
1107                break;
1108            case clickhouseFetchPartition:
1109                this.partitionExpr = (TParseTreeNode)arg2;
1110                // arg3 is the FROM path string constant
1111                break;
1112            case clickhouseMovePartition:
1113                this.partitionExpr = (TParseTreeNode)arg2;
1114                this.newTableName = (TObjectName)arg3;
1115                this.newTableName.setDbObjectType(EDbObjectType.table);
1116                break;
1117            case clickhouseReplacePartition:
1118                this.partitionExpr = (TParseTreeNode)arg2;
1119                this.sourceTableName = (TObjectName)arg3;
1120                this.sourceTableName.setDbObjectType(EDbObjectType.table);
1121                break;
1122            default:
1123                this.columnName = (TObjectName)arg2;
1124                this.newColumnName = (TObjectName)arg3;
1125                break;
1126        }
1127    }
1128
1129    public void init(Object arg1,Object arg2,Object arg3,Object arg4) {
1130        init(arg1,arg2,arg3);
1131        switch (optionType) {
1132            case switchPartition:
1133                partitionExpression2 = (TExpression)arg4;
1134                break;
1135            case AlterColumn:
1136                switch (AlterColumnSubType){
1137                    case Comment:
1138                        this.comment = ((TSourceToken)arg4).toString();
1139                        break;
1140                }
1141                break;
1142            default:
1143                break;
1144        }
1145    }
1146
1147    private ArrayList<TPartitionDefinition> partitionDefinitionList;
1148
1149    public ArrayList<TPartitionDefinition> getPartitionDefinitionList() {
1150        return partitionDefinitionList;
1151    }
1152
1153    //private TPTNodeList <TPartitionExtensionClause> partitionSpecList;
1154    private ArrayList<TPartitionExtensionClause> partitionSpecList;
1155
1156    /**
1157     * Hive, Impala, partition spec list in unarchive clause when option type is {@link EAlterTableOptionType#unArchive},
1158     * {@link EAlterTableOptionType#archive}.
1159     * <br>partition spec list in touch clause when option type is {@link EAlterTableOptionType#touch},
1160     * <br>partition spec list in drop clause when option type is {@link EAlterTableOptionType#dropPartitionSpecList},
1161     * <br>partition spec list in add clause when option type is {@link EAlterTableOptionType#addPartitionSpecList},
1162     *
1163     * @return    partition spec list
1164     */
1165    public ArrayList<TPartitionExtensionClause> getPartitionSpecList() {
1166        return partitionSpecList;
1167    }
1168
1169    private TPTNodeList <THiveKeyValueProperty> tableProperties;
1170
1171    /**
1172     * Hive, Impala, table properties of SET/UNSET TBLPROPERTIES clause
1173     * when {@link #getOptionType()} is {@link EAlterTableOptionType#setTableProperties} or
1174     * {@link EAlterTableOptionType#unsetTableProperties}
1175     * <br> table properties of SET SERDE clause when {@link #getOptionType()} is {@link EAlterTableOptionType#serde}
1176     *
1177     * @return  table properties of SET/UNSET TBLPROPERTIES/SET SERDE clause.
1178     */
1179    public TPTNodeList<THiveKeyValueProperty> getTableProperties() {
1180        return tableProperties;
1181    }
1182
1183    private THiveTableFileFormat fileFormat;
1184
1185    /**
1186     * Hive,Impala,file format of SET FILEFORMAT clause valid when {@link #getOptionType()} is {@link EAlterTableOptionType#setFileFormat}
1187     *
1188     * @return      file format of SET FILEFORMAT
1189     */
1190    public THiveTableFileFormat getFileFormat() {
1191        return fileFormat;
1192    }
1193
1194    private TObjectName tableLocation;
1195
1196    /**
1197     * Hive,Impala,  file location of SET LOCATION clause valid when {@link #getOptionType()} is:
1198     * {@link EAlterTableOptionType#setLocation}
1199     *
1200     * @return   file location of SET LOCATION clause
1201     */
1202    public TObjectName getTableLocation() {
1203        return tableLocation;
1204    }
1205
1206    private TPartitionDefinition partitionDefinition;
1207
1208    public TPartitionDefinition getPartitionDefinition() {
1209        return partitionDefinition;
1210    }
1211
1212    /**
1213     * Hive, Impala, new partition spec in RENAME TO clause
1214     * valid when {@link #getOptionType()} is:
1215     * {@link EAlterTableOptionType#renamePartition}
1216     *
1217     * @return  new partition spec in RENAME TO clause
1218     */
1219    public TPartitionExtensionClause getNewPartitionSpec() {
1220        return newPartitionSpec;
1221    }
1222
1223
1224    private TPartitionExtensionClause newPartitionSpec;
1225
1226    private TConstant numberOfBuckets;
1227
1228    /**
1229     * Hive, Impala, number of buckets of INTO BUCKETS clause
1230     * valid when {@link #getOptionType()} is:
1231     * {@link EAlterTableOptionType#tableBuckets}
1232     *
1233     * @return  number of buckets of INTO BUCKETS clause
1234     */
1235    public TConstant getNumberOfBuckets() {
1236        return numberOfBuckets;
1237    }
1238
1239    private TExpressionList skewedLocations;
1240
1241    /**
1242     * Hive, Impala, skewed location of SET SKEWED LOCATION clause
1243     * valid when {@link #getOptionType()} is:
1244     * {@link EAlterTableOptionType#skewedLocation}
1245     *
1246     * @return  skewed location of SET SKEWED LOCATION clause
1247     */
1248    public TExpressionList getSkewedLocations() {
1249        return skewedLocations;
1250    }
1251
1252    private THiveTableBuckets tableBuckets;
1253
1254
1255    /**
1256     * Hive, Impala, clustered by ... [sorted by ...] into number buckets
1257     * valid when {@link #getOptionType()} is:
1258     * {@link EAlterTableOptionType#clusteredSorted}
1259     *
1260     * @return    table buckets
1261     */
1262    public THiveTableBuckets getTableBuckets() {
1263        return tableBuckets;
1264    }
1265
1266    private TColumnDefinition partitionColumnDef;
1267
1268    /**
1269     * Hive,Impala, column of  PARTITION COLUMN ( columnDef ) clause
1270     * valid when {@link #getOptionType()} is:
1271     * {@link EAlterTableOptionType#clusteredSorted}
1272     *
1273     * @return  column of  PARTITION COLUMN ( columnDef ) clause
1274     */
1275    public TColumnDefinition getPartitionColumnDef() {
1276        return partitionColumnDef;
1277    }
1278
1279    private THiveTableSkewed     tableSkewed;
1280
1281    /**
1282     * Hive, Impala,   tableSkewed clause syntax like: SKEWED BY '(' columnNameList ')' ON '(' skewedValueElement ')'
1283     * valid when {@link #getOptionType()} is:
1284     * {@link EAlterTableOptionType#tableSkewed}
1285     *
1286     * @return         tableSkewed clause
1287     */
1288    public THiveTableSkewed getTableSkewed() {
1289        return tableSkewed;
1290    }
1291
1292    /**
1293     * Hive,Impala, partition spec of EXCHANGE partitionSpec WITH TABLE tableName clause.
1294     * valid when {@link #getOptionType()} is:
1295     * {@link EAlterTableOptionType#exchangePartition}
1296     *
1297     * @return     partition spec of EXCHANGE partitionSpec WITH TABLE tableName clause.
1298     */
1299    public TPartitionExtensionClause getExchangePartitionSpec() {
1300        return exchangePartitionSpec;
1301    }
1302
1303    private TPartitionExtensionClause exchangePartitionSpec;
1304
1305    private EAlterTableOptionType optionType = EAlterTableOptionType.Unknown;
1306
1307
1308    public void doParse(TCustomSqlStatement psql, ESqlClause plocation){
1309
1310        switch (optionType){
1311            case AddColumn:
1312                getColumnDefinitionList().doParse(psql,plocation);
1313                for(int i=0;i<getColumnDefinitionList().size();i++){
1314                    TColumnDefinition cd = getColumnDefinitionList().getColumn(i);
1315
1316                    cd.getColumnName().setLocation(ESqlClause.createTable);
1317                    cd.getColumnName().setLinkedColumnDef(cd);
1318                    psql.tables.getTable(0).getLinkedColumns().addObjectName(cd.getColumnName());
1319                    cd.getColumnName().setSourceTable(psql.tables.getTable(0));
1320
1321                }
1322                break;
1323            case ModifyColumn:
1324                if (getColumnDefinitionList() != null){
1325                    getColumnDefinitionList().doParse(psql,plocation);
1326                    for(int i=0;i<getColumnDefinitionList().size();i++){
1327                        TColumnDefinition cd = getColumnDefinitionList().getColumn(i);
1328
1329                        cd.getColumnName().setLocation(ESqlClause.createTable);
1330                        cd.getColumnName().setLinkedColumnDef(cd);
1331                        psql.tables.getTable(0).getLinkedColumns().addObjectName(cd.getColumnName());
1332                        cd.getColumnName().setSourceTable(psql.tables.getTable(0));
1333
1334                    }
1335                }
1336                break;
1337            case DropColumn:
1338                for(int i=0;i<getColumnNameList().size();i++){
1339                    TObjectName dropedColumn = getColumnNameList().getObjectName(i);
1340                    psql.tables.getTable(0).getLinkedColumns().addObjectName(dropedColumn);
1341                    dropedColumn.setSourceTable(psql.tables.getTable(0));
1342                }
1343                break;
1344            case ChangeColumn:
1345                psql.tables.getTable(0).getLinkedColumns().addObjectName(getColumnName());
1346                getColumnName().setSourceTable(psql.tables.getTable(0));
1347
1348                TObjectName newColumn = newColumnDef.getColumnName();
1349                psql.tables.getTable(0).getLinkedColumns().addObjectName(newColumn);
1350                newColumn.setSourceTable(psql.tables.getTable(0));
1351
1352                break;
1353            case AddConstraintPK:
1354            case AddConstraintUnique:
1355                if (getIndexCols() != null){
1356                    for(int i=0;i<getIndexCols().size();i++){
1357                        psql.tables.getTable(0).getLinkedColumns().addObjectName(getIndexCols().getElement(i).getColumnName());
1358                        getIndexCols().getElement(i).getColumnName().setSourceTable(psql.tables.getTable(0));
1359                    }
1360                }
1361                else if (getColumnNameList().size() > 0){
1362                    for (int i=0;i<getColumnNameList().size();i++){
1363                        TObjectName columnName = getColumnNameList().getObjectName(i);
1364                        psql.tables.getTable(0).getLinkedColumns().addObjectName(columnName);
1365                        columnName.setSourceTable(psql.tables.getTable(0));
1366                    }
1367                }
1368                break;
1369            case AddConstraintFK:
1370                if (getIndexCols() != null){
1371                    for(int i=0;i<getIndexCols().size();i++){
1372                        psql.tables.getTable(0).getLinkedColumns().addObjectName(getIndexCols().getElement(i).getColumnName());
1373                        getIndexCols().getElement(i).getColumnName().setSourceTable(psql.tables.getTable(0));
1374                    }
1375                }
1376                else if (getColumnNameList().size() > 0){
1377                    for (int i=0;i<getColumnNameList().size();i++){
1378                        TObjectName columnName = getColumnNameList().getObjectName(i);
1379                        psql.tables.getTable(0).getLinkedColumns().addObjectName(columnName);
1380                        columnName.setSourceTable(psql.tables.getTable(0));
1381                    }
1382                }
1383
1384                if (referencedObjectName != null){
1385                    referencedObjectName.setDbObjectType(EDbObjectType.table);
1386                    referencedTable = psql.analyzeTablename(referencedObjectName);
1387                    if (getReferencedColumnList() != null) {
1388                        for (int i = 0; i < getReferencedColumnList().size(); i++) {
1389                            TObjectName refColumn = getReferencedColumnList().getObjectName(i);
1390                            referencedTable.getLinkedColumns().addObjectName(refColumn);
1391                            refColumn.setSourceTable(referencedTable);
1392                        }
1393                    }
1394
1395                }
1396                break;
1397            case RenameTable:
1398                TTable lcTable = new TTable(newTableName);
1399                lcTable.setPropertyFromObjectName(newTableName, ETableEffectType.tetAlterTableRename);
1400                psql.addToTables(lcTable);
1401                break;
1402            case AddConstraint:
1403                if (tableConstraint != null){
1404                    tableConstraint.doParse(psql,ESqlClause.unknown);
1405                }else if (constraintList != null){
1406                    constraintList.doParse(psql,ESqlClause.unknown);
1407                }
1408                break;
1409        }
1410
1411    }
1412
1413    private TExpression retenttionTimeInDays;
1414
1415    public TExpression getRetenttionTimeInDays() {
1416        return retenttionTimeInDays;
1417    }
1418
1419    public void accept(TParseTreeVisitor v)
1420    {
1421        v.preVisit(this);
1422        v.postVisit(this);
1423    }
1424
1425    public void acceptChildren(TParseTreeVisitor v)
1426    {
1427        v.preVisit(this);
1428        switch (optionType){
1429            case AlterColumn:
1430                columnName.acceptChildren(v);
1431                if (newDataType != null){
1432                    newDataType.acceptChildren(v);
1433                }
1434                break;
1435            case AddColumn:
1436                for(int i=0;i<getColumnDefinitionList().size();i++){
1437                    TColumnDefinition cd = getColumnDefinitionList().getColumn(i);
1438                    cd.acceptChildren(v);
1439                }
1440                break;
1441            case ModifyColumn:
1442                if (getColumnDefinitionList() != null){
1443                    for(int i=0;i<getColumnDefinitionList().size();i++){
1444                        TColumnDefinition cd = getColumnDefinitionList().getColumn(i);
1445                        cd.acceptChildren(v);
1446                    }
1447                }
1448                break;
1449            case DropColumn:
1450                for(int i=0;i<getColumnNameList().size();i++){
1451                    TObjectName dropedColumn = getColumnNameList().getObjectName(i);
1452                    dropedColumn.acceptChildren(v);
1453                }
1454                break;
1455            case ChangeColumn:
1456                break;
1457            case AddConstraintPK:
1458            case AddConstraintUnique:
1459                break;
1460            case AddConstraintFK:
1461                break;
1462            case RenameTable:
1463                break;
1464        }
1465        v.postVisit(this);
1466    }
1467
1468    public void setSerdeName(TObjectName serdeName) {
1469        this.serdeName = serdeName;
1470    }
1471
1472    public void setDropRestrictType(EKeyReferenceType dropRestrictType) {
1473        this.dropRestrictType = dropRestrictType;
1474    }
1475
1476    public void setColumnDefinitionList(TColumnDefinitionList columnDefinitionList) {
1477        this.columnDefinitionList = columnDefinitionList;
1478    }
1479
1480    public void setConstraintList(TConstraintList constraintList) {
1481        this.constraintList = constraintList;
1482    }
1483
1484    public void setColumnNameList(TObjectNameList columnNameList) {
1485        this.columnNameList = columnNameList;
1486    }
1487
1488    public void setNewColumnName(TObjectName newColumnName) {
1489        this.newColumnName = newColumnName;
1490    }
1491
1492    public void setSchemaName(TObjectName schemaName) {
1493        this.schemaName = schemaName;
1494    }
1495
1496    public void setConstraintNameList(TObjectNameList constraintNameList) {
1497        this.constraintNameList = constraintNameList;
1498    }
1499
1500    public void setPartitionExpression1(TExpression partitionExpression1) {
1501        this.partitionExpression1 = partitionExpression1;
1502    }
1503
1504    public void setPartitionExpression2(TExpression partitionExpression2) {
1505        this.partitionExpression2 = partitionExpression2;
1506    }
1507
1508    public void setNewColumnDef(TColumnDefinition newColumnDef) {
1509        this.newColumnDef = newColumnDef;
1510    }
1511
1512//    public void setPartitionSpecList(TPTNodeList<TPartitionExtensionClause> partitionSpecList) {
1513//        this.partitionSpecList = partitionSpecList;
1514//    }
1515
1516    public void setTableProperties(TPTNodeList<THiveKeyValueProperty> tableProperties) {
1517        this.tableProperties = tableProperties;
1518    }
1519
1520    public void setFileFormat(THiveTableFileFormat fileFormat) {
1521        this.fileFormat = fileFormat;
1522    }
1523
1524    public void setTableLocation(TObjectName tableLocation) {
1525        this.tableLocation = tableLocation;
1526    }
1527
1528    public void setNewPartitionSpec(TPartitionExtensionClause newPartitionSpec) {
1529        this.newPartitionSpec = newPartitionSpec;
1530    }
1531
1532    public void setNumberOfBuckets(TConstant numberOfBuckets) {
1533        this.numberOfBuckets = numberOfBuckets;
1534    }
1535
1536    public void setSkewedLocations(TExpressionList skewedLocations) {
1537        this.skewedLocations = skewedLocations;
1538    }
1539
1540    public void setTableBuckets(THiveTableBuckets tableBuckets) {
1541        this.tableBuckets = tableBuckets;
1542    }
1543
1544    public void setPartitionColumnDef(TColumnDefinition partitionColumnDef) {
1545        this.partitionColumnDef = partitionColumnDef;
1546    }
1547
1548    public void setTableSkewed(THiveTableSkewed tableSkewed) {
1549        this.tableSkewed = tableSkewed;
1550    }
1551
1552    public void setExchangePartitionSpec(TPartitionExtensionClause exchangePartitionSpec) {
1553        this.exchangePartitionSpec = exchangePartitionSpec;
1554    }
1555
1556    public void setOptionType(EAlterTableOptionType optionType) {
1557        this.optionType = optionType;
1558    }
1559}