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 modifyPrimaryKey: 888 indexName = (TObjectName)arg2; 889 break; 890 case switchPartition: 891 newTableName = (TObjectName)arg2; 892 break; 893 case AddConstraintIndex: 894 case AddConstraintPK: 895 case AddConstraintUnique: 896 case AddConstraintFK: 897 if (arg2 instanceof TPTNodeList){ 898 indexCols = (TPTNodeList)arg2; 899 }else{ 900 columnNameList = (TObjectNameList)arg2; 901 } 902 break; 903 case AddConstraintCheck: 904 defaultExpr = (TExpression)arg2; 905 break; 906 case clickhouseDeleteMutation: 907 defaultExpr = (TExpression)arg2; 908 break; 909 case clickhouseDropPartition: 910 case clickhouseDetachPartition: 911 case clickhouseAttachPartition: 912 case clickhouseFreezePartition: 913 case clickhouseUnfreezePartition: 914 partitionExpr = (TParseTreeNode)arg2; 915 break; 916 case setPrivileges: 917 newTableName = (TObjectName)arg2; 918 break; 919 case AddColumn: 920 this.columnDefinitionList = (TColumnDefinitionList)arg2; 921 break; 922 case AlterColumn: 923 this.columnName = (TObjectName)arg2; 924 this.columnName.setDbObjectType(EDbObjectType.column); 925 break; 926 case attachPartition: 927 case detachPartition: 928 partitionName = (TObjectName)arg2; 929 break; 930 case swapWith: 931 newTableName = (TObjectName)arg2; 932 break; 933 case setDataRetentionTimeInDays: 934 break; 935 case setComment: 936 break; 937 case RenameTable: 938 newTableName = (TObjectName)arg2; 939 newTableName.setDbObjectType(EDbObjectType.table); 940 break; 941 case appendFrom: 942 this.sourceTableName = (TObjectName) arg2; 943 break; 944 case AddConstraint: 945 if (arg2 instanceof TConstraint){ 946 this.tableConstraint = (TConstraint) arg2; 947 }else if (arg2 instanceof TConstraintList){ 948 this.constraintList = (TConstraintList) arg2; 949 } 950 break; 951 case mysqlTableOption: 952 this.mySQLTableOption = (TMySQLCreateTableOption)arg2; 953 break; 954 case renameIndex: 955 this.indexName = (TObjectName)arg2; 956 this.indexName.setDbObjectTypeDirectly(EDbObjectType.index); 957 break; 958 case partition: 959 this.tablePartition = (TBaseTablePartition) arg2; 960 break; 961 case addPeriodForClause: 962 this.periodForClause = (TPeriodForClause)arg2; 963 break; 964 default: 965 if (arg2 instanceof TColumnDefinitionList){ 966 this.columnDefinitionList = (TColumnDefinitionList)arg2; 967 }else if (arg2 instanceof TConstraintList){ 968 this.constraintList = (TConstraintList)arg2; 969 }else if (arg2 instanceof TObjectNameList) { 970 971 this.columnNameList = (TObjectNameList)arg2; 972 }else if (arg2 instanceof TDummyList) { 973 TDummyList dlist = (TDummyList)arg2; 974 TDummy dm = null; 975 for(int i=0;i<dlist.size();i++){ 976 dm = dlist.getDummyItem(i); 977 this.getColumnNameList().addObjectName((TObjectName)dm.node1); 978 } 979 980 if ((optionType == EAlterTableOptionType.DropColumn)&&(this.getColumnNameList().size() > 0)){ 981 this.columnName = this.getColumnNameList().getObjectName(0); 982 } 983 } 984 break; 985 986 } 987 988 } 989 990 991 private String comment; 992 993 public String getComment() { 994 return comment; 995 } 996 997 private TExpression commentExpr; 998 999 public TExpression getCommentExpr() { 1000 return commentExpr; 1001 } 1002 1003 public void setNewConstraintName(TObjectName newConstraintName) { 1004 this.newConstraintName = newConstraintName; 1005 } 1006 1007 public void setConstraintName(TDummy pName) { 1008 if (pName == null) return; 1009 if (pName.node1 == null) return; 1010 this.constraintName = (TObjectName)pName.node1; 1011 } 1012 public void setConstraintName(TObjectName constraintName) { 1013 1014 this.constraintName = constraintName; 1015 } 1016 1017 private TColumnDefinition newColumnDef; 1018 1019 /** 1020 * 1021 * @return {@link TColumnDefinition}, valid when {@link #getOptionType()} is: 1022 * <p>{@link EAlterTableOptionType#ChangeColumn} 1023 */ 1024 1025 public TColumnDefinition getNewColumnDef() { 1026 return newColumnDef; 1027 } 1028 1029 /** 1030 * 1031 * valid when {@link #getOptionType()} is: 1032 * <p>{@link EAlterTableOptionType#serde} 1033 * @return serde name 1034 */ 1035 public TObjectName getSerdeName() { 1036 return serdeName; 1037 } 1038 1039 public void init(Object arg1,Object arg2,Object arg3){ 1040 init(arg1); 1041 switch (optionType){ 1042 case AlterColumn: 1043 init(arg1,arg2); 1044 AlterColumnSubType = (EAlterColumnSubType)arg3; 1045 break; 1046 case ChangeColumn: 1047 this.columnName = (TObjectName)arg2; 1048 this.newColumnDef = (TColumnDefinition)arg3; 1049 1050 break; 1051 case serde: 1052 serdeName = (TObjectName)arg2; 1053 tableProperties = (TPTNodeList)arg3; 1054 1055 break; 1056 case exchangePartition: 1057 if ((dbvendor == EDbVendor.dbvoracle) 1058 ||(dbvendor == EDbVendor.dbvgaussdb)||(dbvendor == EDbVendor.dbvgreenplum) 1059 ||(dbvendor == EDbVendor.dbvmysql)){ 1060 partitionName = (TObjectName)arg2; 1061 partitionName.setDbObjectType(EDbObjectType.partition); 1062 }else{ 1063 exchangePartitionSpec = (TPartitionExtensionClause)arg2; 1064 } 1065 1066 newTableName = (TObjectName)arg3; 1067 newTableName.setDbObjectType(EDbObjectType.table); 1068 break; 1069 case RenameColumn: 1070 this.columnName = (TObjectName)arg2; 1071 this.newColumnName = (TObjectName)arg3; 1072 break; 1073 case modifyPrimaryKey: 1074 if (arg2 !=null){ 1075 indexName = (TObjectName)arg2; 1076 } 1077 columnNameList = (TObjectNameList)arg3; 1078 break; 1079 case switchPartition: 1080 newTableName = (TObjectName)arg2; 1081 partitionExpression1 = (TExpression)arg3; 1082 break; 1083 case attachPartition: 1084 partitionName = (TObjectName)arg2; 1085 partitionBoundSpec = (TPartitionBoundSpecSqlNode) arg3; 1086 break; 1087 case reorganizePartition: 1088 nameList = (TObjectNameList) arg2; 1089 partitionDefinitionList = (ArrayList<TPartitionDefinition>)arg3; 1090 break; 1091 case renameIndex: 1092 this.indexName = (TObjectName)arg2; 1093 this.indexName.setDbObjectTypeDirectly(EDbObjectType.index); 1094 this.newIndexName = (TObjectName)arg3; 1095 this.newIndexName.setDbObjectTypeDirectly(EDbObjectType.index); 1096 break; 1097 case clickhouseUpdateMutation: 1098 this.mutationUpdateList = (TResultColumnList)arg2; 1099 this.defaultExpr = (TExpression)arg3; 1100 break; 1101 case clickhouseFetchPartition: 1102 this.partitionExpr = (TParseTreeNode)arg2; 1103 // arg3 is the FROM path string constant 1104 break; 1105 case clickhouseMovePartition: 1106 this.partitionExpr = (TParseTreeNode)arg2; 1107 this.newTableName = (TObjectName)arg3; 1108 this.newTableName.setDbObjectType(EDbObjectType.table); 1109 break; 1110 case clickhouseReplacePartition: 1111 this.partitionExpr = (TParseTreeNode)arg2; 1112 this.sourceTableName = (TObjectName)arg3; 1113 this.sourceTableName.setDbObjectType(EDbObjectType.table); 1114 break; 1115 default: 1116 this.columnName = (TObjectName)arg2; 1117 this.newColumnName = (TObjectName)arg3; 1118 break; 1119 } 1120 } 1121 1122 public void init(Object arg1,Object arg2,Object arg3,Object arg4) { 1123 init(arg1,arg2,arg3); 1124 switch (optionType) { 1125 case switchPartition: 1126 partitionExpression2 = (TExpression)arg4; 1127 break; 1128 case AlterColumn: 1129 switch (AlterColumnSubType){ 1130 case Comment: 1131 this.comment = ((TSourceToken)arg4).toString(); 1132 break; 1133 } 1134 break; 1135 default: 1136 break; 1137 } 1138 } 1139 1140 private ArrayList<TPartitionDefinition> partitionDefinitionList; 1141 1142 public ArrayList<TPartitionDefinition> getPartitionDefinitionList() { 1143 return partitionDefinitionList; 1144 } 1145 1146 //private TPTNodeList <TPartitionExtensionClause> partitionSpecList; 1147 private ArrayList<TPartitionExtensionClause> partitionSpecList; 1148 1149 /** 1150 * Hive, Impala, partition spec list in unarchive clause when option type is {@link EAlterTableOptionType#unArchive}, 1151 * {@link EAlterTableOptionType#archive}. 1152 * <br>partition spec list in touch clause when option type is {@link EAlterTableOptionType#touch}, 1153 * <br>partition spec list in drop clause when option type is {@link EAlterTableOptionType#dropPartitionSpecList}, 1154 * <br>partition spec list in add clause when option type is {@link EAlterTableOptionType#addPartitionSpecList}, 1155 * 1156 * @return partition spec list 1157 */ 1158 public ArrayList<TPartitionExtensionClause> getPartitionSpecList() { 1159 return partitionSpecList; 1160 } 1161 1162 private TPTNodeList <THiveKeyValueProperty> tableProperties; 1163 1164 /** 1165 * Hive, Impala, table properties of SET/UNSET TBLPROPERTIES clause 1166 * when {@link #getOptionType()} is {@link EAlterTableOptionType#setTableProperties} or 1167 * {@link EAlterTableOptionType#unsetTableProperties} 1168 * <br> table properties of SET SERDE clause when {@link #getOptionType()} is {@link EAlterTableOptionType#serde} 1169 * 1170 * @return table properties of SET/UNSET TBLPROPERTIES/SET SERDE clause. 1171 */ 1172 public TPTNodeList<THiveKeyValueProperty> getTableProperties() { 1173 return tableProperties; 1174 } 1175 1176 private THiveTableFileFormat fileFormat; 1177 1178 /** 1179 * Hive,Impala,file format of SET FILEFORMAT clause valid when {@link #getOptionType()} is {@link EAlterTableOptionType#setFileFormat} 1180 * 1181 * @return file format of SET FILEFORMAT 1182 */ 1183 public THiveTableFileFormat getFileFormat() { 1184 return fileFormat; 1185 } 1186 1187 private TObjectName tableLocation; 1188 1189 /** 1190 * Hive,Impala, file location of SET LOCATION clause valid when {@link #getOptionType()} is: 1191 * {@link EAlterTableOptionType#setLocation} 1192 * 1193 * @return file location of SET LOCATION clause 1194 */ 1195 public TObjectName getTableLocation() { 1196 return tableLocation; 1197 } 1198 1199 private TPartitionDefinition partitionDefinition; 1200 1201 public TPartitionDefinition getPartitionDefinition() { 1202 return partitionDefinition; 1203 } 1204 1205 /** 1206 * Hive, Impala, new partition spec in RENAME TO clause 1207 * valid when {@link #getOptionType()} is: 1208 * {@link EAlterTableOptionType#renamePartition} 1209 * 1210 * @return new partition spec in RENAME TO clause 1211 */ 1212 public TPartitionExtensionClause getNewPartitionSpec() { 1213 return newPartitionSpec; 1214 } 1215 1216 1217 private TPartitionExtensionClause newPartitionSpec; 1218 1219 private TConstant numberOfBuckets; 1220 1221 /** 1222 * Hive, Impala, number of buckets of INTO BUCKETS clause 1223 * valid when {@link #getOptionType()} is: 1224 * {@link EAlterTableOptionType#tableBuckets} 1225 * 1226 * @return number of buckets of INTO BUCKETS clause 1227 */ 1228 public TConstant getNumberOfBuckets() { 1229 return numberOfBuckets; 1230 } 1231 1232 private TExpressionList skewedLocations; 1233 1234 /** 1235 * Hive, Impala, skewed location of SET SKEWED LOCATION clause 1236 * valid when {@link #getOptionType()} is: 1237 * {@link EAlterTableOptionType#skewedLocation} 1238 * 1239 * @return skewed location of SET SKEWED LOCATION clause 1240 */ 1241 public TExpressionList getSkewedLocations() { 1242 return skewedLocations; 1243 } 1244 1245 private THiveTableBuckets tableBuckets; 1246 1247 1248 /** 1249 * Hive, Impala, clustered by ... [sorted by ...] into number buckets 1250 * valid when {@link #getOptionType()} is: 1251 * {@link EAlterTableOptionType#clusteredSorted} 1252 * 1253 * @return table buckets 1254 */ 1255 public THiveTableBuckets getTableBuckets() { 1256 return tableBuckets; 1257 } 1258 1259 private TColumnDefinition partitionColumnDef; 1260 1261 /** 1262 * Hive,Impala, column of PARTITION COLUMN ( columnDef ) clause 1263 * valid when {@link #getOptionType()} is: 1264 * {@link EAlterTableOptionType#clusteredSorted} 1265 * 1266 * @return column of PARTITION COLUMN ( columnDef ) clause 1267 */ 1268 public TColumnDefinition getPartitionColumnDef() { 1269 return partitionColumnDef; 1270 } 1271 1272 private THiveTableSkewed tableSkewed; 1273 1274 /** 1275 * Hive, Impala, tableSkewed clause syntax like: SKEWED BY '(' columnNameList ')' ON '(' skewedValueElement ')' 1276 * valid when {@link #getOptionType()} is: 1277 * {@link EAlterTableOptionType#tableSkewed} 1278 * 1279 * @return tableSkewed clause 1280 */ 1281 public THiveTableSkewed getTableSkewed() { 1282 return tableSkewed; 1283 } 1284 1285 /** 1286 * Hive,Impala, partition spec of EXCHANGE partitionSpec WITH TABLE tableName clause. 1287 * valid when {@link #getOptionType()} is: 1288 * {@link EAlterTableOptionType#exchangePartition} 1289 * 1290 * @return partition spec of EXCHANGE partitionSpec WITH TABLE tableName clause. 1291 */ 1292 public TPartitionExtensionClause getExchangePartitionSpec() { 1293 return exchangePartitionSpec; 1294 } 1295 1296 private TPartitionExtensionClause exchangePartitionSpec; 1297 1298 private EAlterTableOptionType optionType = EAlterTableOptionType.Unknown; 1299 1300 1301 public void doParse(TCustomSqlStatement psql, ESqlClause plocation){ 1302 1303 switch (optionType){ 1304 case AddColumn: 1305 getColumnDefinitionList().doParse(psql,plocation); 1306 for(int i=0;i<getColumnDefinitionList().size();i++){ 1307 TColumnDefinition cd = getColumnDefinitionList().getColumn(i); 1308 1309 cd.getColumnName().setLocation(ESqlClause.createTable); 1310 cd.getColumnName().setLinkedColumnDef(cd); 1311 psql.tables.getTable(0).getLinkedColumns().addObjectName(cd.getColumnName()); 1312 cd.getColumnName().setSourceTable(psql.tables.getTable(0)); 1313 1314 } 1315 break; 1316 case ModifyColumn: 1317 if (getColumnDefinitionList() != null){ 1318 getColumnDefinitionList().doParse(psql,plocation); 1319 for(int i=0;i<getColumnDefinitionList().size();i++){ 1320 TColumnDefinition cd = getColumnDefinitionList().getColumn(i); 1321 1322 cd.getColumnName().setLocation(ESqlClause.createTable); 1323 cd.getColumnName().setLinkedColumnDef(cd); 1324 psql.tables.getTable(0).getLinkedColumns().addObjectName(cd.getColumnName()); 1325 cd.getColumnName().setSourceTable(psql.tables.getTable(0)); 1326 1327 } 1328 } 1329 break; 1330 case DropColumn: 1331 for(int i=0;i<getColumnNameList().size();i++){ 1332 TObjectName dropedColumn = getColumnNameList().getObjectName(i); 1333 psql.tables.getTable(0).getLinkedColumns().addObjectName(dropedColumn); 1334 dropedColumn.setSourceTable(psql.tables.getTable(0)); 1335 } 1336 break; 1337 case ChangeColumn: 1338 psql.tables.getTable(0).getLinkedColumns().addObjectName(getColumnName()); 1339 getColumnName().setSourceTable(psql.tables.getTable(0)); 1340 1341 TObjectName newColumn = newColumnDef.getColumnName(); 1342 psql.tables.getTable(0).getLinkedColumns().addObjectName(newColumn); 1343 newColumn.setSourceTable(psql.tables.getTable(0)); 1344 1345 break; 1346 case AddConstraintPK: 1347 case AddConstraintUnique: 1348 if (getIndexCols() != null){ 1349 for(int i=0;i<getIndexCols().size();i++){ 1350 psql.tables.getTable(0).getLinkedColumns().addObjectName(getIndexCols().getElement(i).getColumnName()); 1351 getIndexCols().getElement(i).getColumnName().setSourceTable(psql.tables.getTable(0)); 1352 } 1353 } 1354 else if (getColumnNameList().size() > 0){ 1355 for (int i=0;i<getColumnNameList().size();i++){ 1356 TObjectName columnName = getColumnNameList().getObjectName(i); 1357 psql.tables.getTable(0).getLinkedColumns().addObjectName(columnName); 1358 columnName.setSourceTable(psql.tables.getTable(0)); 1359 } 1360 } 1361 break; 1362 case AddConstraintFK: 1363 if (getIndexCols() != null){ 1364 for(int i=0;i<getIndexCols().size();i++){ 1365 psql.tables.getTable(0).getLinkedColumns().addObjectName(getIndexCols().getElement(i).getColumnName()); 1366 getIndexCols().getElement(i).getColumnName().setSourceTable(psql.tables.getTable(0)); 1367 } 1368 } 1369 else if (getColumnNameList().size() > 0){ 1370 for (int i=0;i<getColumnNameList().size();i++){ 1371 TObjectName columnName = getColumnNameList().getObjectName(i); 1372 psql.tables.getTable(0).getLinkedColumns().addObjectName(columnName); 1373 columnName.setSourceTable(psql.tables.getTable(0)); 1374 } 1375 } 1376 1377 if (referencedObjectName != null){ 1378 referencedObjectName.setDbObjectType(EDbObjectType.table); 1379 referencedTable = psql.analyzeTablename(referencedObjectName); 1380 for(int i=0;i<getReferencedColumnList().size();i++){ 1381 TObjectName refColumn = getReferencedColumnList().getObjectName(i); 1382 referencedTable.getLinkedColumns().addObjectName(refColumn); 1383 refColumn.setSourceTable(referencedTable); 1384 } 1385 1386 } 1387 break; 1388 case RenameTable: 1389 TTable lcTable = new TTable(newTableName); 1390 lcTable.setPropertyFromObjectName(newTableName, ETableEffectType.tetAlterTableRename); 1391 psql.addToTables(lcTable); 1392 break; 1393 case AddConstraint: 1394 if (tableConstraint != null){ 1395 tableConstraint.doParse(psql,ESqlClause.unknown); 1396 }else if (constraintList != null){ 1397 constraintList.doParse(psql,ESqlClause.unknown); 1398 } 1399 break; 1400 } 1401 1402 } 1403 1404 private TExpression retenttionTimeInDays; 1405 1406 public TExpression getRetenttionTimeInDays() { 1407 return retenttionTimeInDays; 1408 } 1409 1410 public void accept(TParseTreeVisitor v) 1411 { 1412 v.preVisit(this); 1413 v.postVisit(this); 1414 } 1415 1416 public void acceptChildren(TParseTreeVisitor v) 1417 { 1418 v.preVisit(this); 1419 switch (optionType){ 1420 case AlterColumn: 1421 columnName.acceptChildren(v); 1422 if (newDataType != null){ 1423 newDataType.acceptChildren(v); 1424 } 1425 break; 1426 case AddColumn: 1427 for(int i=0;i<getColumnDefinitionList().size();i++){ 1428 TColumnDefinition cd = getColumnDefinitionList().getColumn(i); 1429 cd.acceptChildren(v); 1430 } 1431 break; 1432 case ModifyColumn: 1433 if (getColumnDefinitionList() != null){ 1434 for(int i=0;i<getColumnDefinitionList().size();i++){ 1435 TColumnDefinition cd = getColumnDefinitionList().getColumn(i); 1436 cd.acceptChildren(v); 1437 } 1438 } 1439 break; 1440 case DropColumn: 1441 for(int i=0;i<getColumnNameList().size();i++){ 1442 TObjectName dropedColumn = getColumnNameList().getObjectName(i); 1443 dropedColumn.acceptChildren(v); 1444 } 1445 break; 1446 case ChangeColumn: 1447 break; 1448 case AddConstraintPK: 1449 case AddConstraintUnique: 1450 break; 1451 case AddConstraintFK: 1452 break; 1453 case RenameTable: 1454 break; 1455 } 1456 v.postVisit(this); 1457 } 1458 1459 public void setSerdeName(TObjectName serdeName) { 1460 this.serdeName = serdeName; 1461 } 1462 1463 public void setDropRestrictType(EKeyReferenceType dropRestrictType) { 1464 this.dropRestrictType = dropRestrictType; 1465 } 1466 1467 public void setColumnDefinitionList(TColumnDefinitionList columnDefinitionList) { 1468 this.columnDefinitionList = columnDefinitionList; 1469 } 1470 1471 public void setConstraintList(TConstraintList constraintList) { 1472 this.constraintList = constraintList; 1473 } 1474 1475 public void setColumnNameList(TObjectNameList columnNameList) { 1476 this.columnNameList = columnNameList; 1477 } 1478 1479 public void setNewColumnName(TObjectName newColumnName) { 1480 this.newColumnName = newColumnName; 1481 } 1482 1483 public void setSchemaName(TObjectName schemaName) { 1484 this.schemaName = schemaName; 1485 } 1486 1487 public void setConstraintNameList(TObjectNameList constraintNameList) { 1488 this.constraintNameList = constraintNameList; 1489 } 1490 1491 public void setPartitionExpression1(TExpression partitionExpression1) { 1492 this.partitionExpression1 = partitionExpression1; 1493 } 1494 1495 public void setPartitionExpression2(TExpression partitionExpression2) { 1496 this.partitionExpression2 = partitionExpression2; 1497 } 1498 1499 public void setNewColumnDef(TColumnDefinition newColumnDef) { 1500 this.newColumnDef = newColumnDef; 1501 } 1502 1503// public void setPartitionSpecList(TPTNodeList<TPartitionExtensionClause> partitionSpecList) { 1504// this.partitionSpecList = partitionSpecList; 1505// } 1506 1507 public void setTableProperties(TPTNodeList<THiveKeyValueProperty> tableProperties) { 1508 this.tableProperties = tableProperties; 1509 } 1510 1511 public void setFileFormat(THiveTableFileFormat fileFormat) { 1512 this.fileFormat = fileFormat; 1513 } 1514 1515 public void setTableLocation(TObjectName tableLocation) { 1516 this.tableLocation = tableLocation; 1517 } 1518 1519 public void setNewPartitionSpec(TPartitionExtensionClause newPartitionSpec) { 1520 this.newPartitionSpec = newPartitionSpec; 1521 } 1522 1523 public void setNumberOfBuckets(TConstant numberOfBuckets) { 1524 this.numberOfBuckets = numberOfBuckets; 1525 } 1526 1527 public void setSkewedLocations(TExpressionList skewedLocations) { 1528 this.skewedLocations = skewedLocations; 1529 } 1530 1531 public void setTableBuckets(THiveTableBuckets tableBuckets) { 1532 this.tableBuckets = tableBuckets; 1533 } 1534 1535 public void setPartitionColumnDef(TColumnDefinition partitionColumnDef) { 1536 this.partitionColumnDef = partitionColumnDef; 1537 } 1538 1539 public void setTableSkewed(THiveTableSkewed tableSkewed) { 1540 this.tableSkewed = tableSkewed; 1541 } 1542 1543 public void setExchangePartitionSpec(TPartitionExtensionClause exchangePartitionSpec) { 1544 this.exchangePartitionSpec = exchangePartitionSpec; 1545 } 1546 1547 public void setOptionType(EAlterTableOptionType optionType) { 1548 this.optionType = optionType; 1549 } 1550}