|
9 | 9 | */
|
10 | 10 | package net.sf.jsqlparser.statement.alter;
|
11 | 11 |
|
| 12 | +import java.util.stream.Collectors; |
12 | 13 | import net.sf.jsqlparser.expression.Expression;
|
13 | 14 | import net.sf.jsqlparser.statement.ReferentialAction;
|
14 | 15 | import net.sf.jsqlparser.statement.ReferentialAction.Action;
|
@@ -79,6 +80,11 @@ public class AlterExpression implements Serializable {
|
79 | 80 | private String partitionType;
|
80 | 81 | private Expression partitionExpression;
|
81 | 82 | private List<String> partitionColumns;
|
| 83 | + private int coalescePartitionNumber; |
| 84 | + |
| 85 | + private String exchangePartitionTableName; |
| 86 | + private boolean exchangePartitionWithValidation; |
| 87 | + private boolean exchangePartitionWithoutValidation; |
82 | 88 |
|
83 | 89 |
|
84 | 90 | public Index getOldIndex() {
|
@@ -524,6 +530,38 @@ public List<String> getPartitionColumns() {
|
524 | 530 | return partitionColumns;
|
525 | 531 | }
|
526 | 532 |
|
| 533 | + public void setExchangePartitionTableName(String exchangePartitionTableName) { |
| 534 | + this.exchangePartitionTableName = exchangePartitionTableName; |
| 535 | + } |
| 536 | + |
| 537 | + public String getExchangePartitionTableName() { |
| 538 | + return exchangePartitionTableName; |
| 539 | + } |
| 540 | + |
| 541 | + public void setCoalescePartitionNumber(int coalescePartitionNumber) { |
| 542 | + this.coalescePartitionNumber = coalescePartitionNumber; |
| 543 | + } |
| 544 | + |
| 545 | + public int getCoalescePartitionNumber() { |
| 546 | + return coalescePartitionNumber; |
| 547 | + } |
| 548 | + |
| 549 | + public void setExchangePartitionWithValidation(boolean exchangePartitionWithValidation) { |
| 550 | + this.exchangePartitionWithValidation = exchangePartitionWithValidation; |
| 551 | + } |
| 552 | + |
| 553 | + public boolean isExchangePartitionWithValidation() { |
| 554 | + return exchangePartitionWithValidation; |
| 555 | + } |
| 556 | + |
| 557 | + public void setExchangePartitionWithoutValidation(boolean exchangePartitionWithoutValidation) { |
| 558 | + this.exchangePartitionWithoutValidation = exchangePartitionWithoutValidation; |
| 559 | + } |
| 560 | + |
| 561 | + public boolean isExchangePartitionWithoutValidation() { |
| 562 | + return exchangePartitionWithoutValidation; |
| 563 | + } |
| 564 | + |
527 | 565 | @Override
|
528 | 566 | @SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity",
|
529 | 567 | "PMD.ExcessiveMethodLength", "PMD.SwitchStmtsShouldHaveDefault"})
|
@@ -628,31 +666,63 @@ public String toString() {
|
628 | 666 | && !pkColumns.isEmpty()) {
|
629 | 667 | // Oracle Multi Column Drop
|
630 | 668 | b.append("DROP (").append(PlainSelect.getStringList(pkColumns)).append(')');
|
| 669 | + } else if (operation == AlterOperation.DISCARD_PARTITION && partitions != null) { |
| 670 | + b.append("DISCARD PARTITION ").append(PlainSelect.getStringList(partitions)); |
| 671 | + if (tableOption != null) { |
| 672 | + b.append(" ").append(tableOption); |
| 673 | + } |
| 674 | + } else if (operation == AlterOperation.IMPORT_PARTITION) { |
| 675 | + b.append("IMPORT PARTITION ").append(PlainSelect.getStringList(partitions)); |
| 676 | + if (tableOption != null) { |
| 677 | + b.append(" ").append(tableOption); |
| 678 | + } |
631 | 679 | } else if (operation == AlterOperation.TRUNCATE_PARTITION
|
632 | 680 | && partitions != null) {
|
633 | 681 | b.append("TRUNCATE PARTITION ").append(PlainSelect.getStringList(partitions));
|
| 682 | + } else if (operation == AlterOperation.COALESCE_PARTITION) { |
| 683 | + b.append("COALESCE PARTITION ").append(coalescePartitionNumber); |
| 684 | + } else if (operation == AlterOperation.REORGANIZE_PARTITION |
| 685 | + && partitions != null |
| 686 | + && partitionDefinitions != null) { |
| 687 | + b.append("REORGANIZE PARTITION ") |
| 688 | + .append(PlainSelect.getStringList(partitions)) |
| 689 | + .append(" INTO (") |
| 690 | + .append(partitionDefinitions.stream() |
| 691 | + .map(PartitionDefinition::toString) |
| 692 | + .collect(Collectors.joining(", "))) |
| 693 | + .append(")"); |
| 694 | + } else if (operation == AlterOperation.EXCHANGE_PARTITION) { |
| 695 | + b.append("EXCHANGE PARTITION "); |
| 696 | + b.append(partitions.get(0)).append(" WITH TABLE ").append(exchangePartitionTableName); |
| 697 | + if (exchangePartitionWithValidation) { |
| 698 | + b.append(" WITH VALIDATION "); |
| 699 | + } else if (exchangePartitionWithoutValidation) { |
| 700 | + b.append(" WITHOUT VALIDATION "); |
| 701 | + } |
| 702 | + } else if (operation == AlterOperation.ANALYZE_PARTITION && partitions != null) { |
| 703 | + b.append("ANALYZE PARTITION ").append(PlainSelect.getStringList(partitions)); |
| 704 | + } else if (operation == AlterOperation.CHECK_PARTITION && partitions != null) { |
| 705 | + b.append("CHECK PARTITION ").append(PlainSelect.getStringList(partitions)); |
| 706 | + } else if (operation == AlterOperation.OPTIMIZE_PARTITION && partitions != null) { |
| 707 | + b.append("OPTIMIZE PARTITION ").append(PlainSelect.getStringList(partitions)); |
| 708 | + } else if (operation == AlterOperation.REBUILD_PARTITION && partitions != null) { |
| 709 | + b.append("REBUILD PARTITION ").append(PlainSelect.getStringList(partitions)); |
| 710 | + } else if (operation == AlterOperation.REPAIR_PARTITION && partitions != null) { |
| 711 | + b.append("REPAIR PARTITION ").append(PlainSelect.getStringList(partitions)); |
| 712 | + } else if (operation == AlterOperation.REMOVE_PARTITIONING) { |
| 713 | + b.append("REMOVE PARTITIONING"); |
634 | 714 | } else if (operation == AlterOperation.PARTITION_BY) {
|
635 | 715 | b.append("PARTITION BY ").append(partitionType).append(" ");
|
636 | 716 | if (partitionExpression != null) {
|
637 | 717 | b.append("(").append(partitionExpression).append(") ");
|
638 | 718 | } else if (partitionColumns != null && !partitionColumns.isEmpty()) {
|
639 | 719 | b.append("COLUMNS(").append(String.join(", ", partitionColumns)).append(") ");
|
640 | 720 | }
|
641 |
| - b.append("("); |
642 |
| - for (int i = 0; i < partitionDefinitions.size(); i++) { |
643 |
| - PartitionDefinition partition = partitionDefinitions.get(i); |
644 |
| - b.append("PARTITION ").append(partition.getPartitionName()) |
645 |
| - .append(" ").append(partition.getPartitionOperation()) |
646 |
| - .append(" (").append(PlainSelect.getStringList(partition.getValues())) |
647 |
| - .append(")"); |
648 |
| - if (partition.getStorageEngine() != null) { |
649 |
| - b.append(" ENGINE = ").append(partition.getStorageEngine()); |
650 |
| - } |
651 |
| - if (i < partitionDefinitions.size() - 1) { |
652 |
| - b.append(", "); |
653 |
| - } |
654 |
| - } |
655 |
| - b.append(")"); |
| 721 | + |
| 722 | + b.append("(").append(partitionDefinitions.stream() |
| 723 | + .map(PartitionDefinition::toString) |
| 724 | + .collect(Collectors.joining(", "))) |
| 725 | + .append(")"); |
656 | 726 | } else {
|
657 | 727 | if (operation == AlterOperation.COMMENT_WITH_EQUAL_SIGN) {
|
658 | 728 | b.append("COMMENT =").append(" ");
|
|
0 commit comments