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