Skip to content

support oracle alter table truncate partition #1954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public class AlterExpression implements Serializable {

private boolean useBrackets = false;

private String truncatePartitionName = null;

public Index getOldIndex() {
return oldIndex;
}
Expand Down Expand Up @@ -402,6 +404,19 @@ public void setUk(boolean uk) {
this.uk = uk;
}

public String getTruncatePartitionName() {
return truncatePartitionName;
}

public void setTruncatePartitionName(String truncatePartitionName) {
this.truncatePartitionName = truncatePartitionName;
}

public AlterExpression withTruncatePartitionName(String truncatePartitionName) {
this.truncatePartitionName = truncatePartitionName;
return this;
}

@Override
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity",
"PMD.ExcessiveMethodLength", "PMD.SwitchStmtsShouldHaveDefault"})
Expand Down Expand Up @@ -441,6 +456,9 @@ public String toString() {
&& !pkColumns.isEmpty()) {
// Oracle Multi Column Drop
b.append("DROP (").append(PlainSelect.getStringList(pkColumns)).append(')');
} else if (operation == AlterOperation.TRUNCATE_PARTITION
&& truncatePartitionName != null) {
b.append("TRUNCATE PARTITION ").append(truncatePartitionName);
} else {
if (operation == AlterOperation.COMMENT_WITH_EQUAL_SIGN) {
b.append("COMMENT =").append(" ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
package net.sf.jsqlparser.statement.alter;

public enum AlterOperation {
ADD, ALTER, DROP, DROP_PRIMARY_KEY, DROP_UNIQUE, DROP_FOREIGN_KEY, MODIFY, CHANGE, ALGORITHM, RENAME, RENAME_TABLE, RENAME_INDEX, RENAME_KEY, RENAME_CONSTRAINT, COMMENT, COMMENT_WITH_EQUAL_SIGN, UNSPECIFIC;
ADD, ALTER, DROP, DROP_PRIMARY_KEY, DROP_UNIQUE, DROP_FOREIGN_KEY, MODIFY, CHANGE, ALGORITHM, RENAME, RENAME_TABLE, RENAME_INDEX, RENAME_KEY, RENAME_CONSTRAINT, COMMENT, COMMENT_WITH_EQUAL_SIGN, UNSPECIFIC, TRUNCATE_PARTITION;

public static AlterOperation from(String operation) {
return Enum.valueOf(AlterOperation.class, operation.toUpperCase());
Expand Down
3 changes: 3 additions & 0 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -6252,6 +6252,7 @@ AlterExpression AlterExpression():
AlterExpression.ColumnDropNotNull alterExpressionColumnDropNotNull = null;
AlterExpression.ColumnDropDefault alterExpressionColumnDropDefault = null;
ReferentialAction.Action action = null;
String truncatePartitionName = null;

// for captureRest()
List<String> tokens = new LinkedList<String>();
Expand Down Expand Up @@ -6543,6 +6544,8 @@ AlterExpression AlterExpression():
}
)
|
LOOKAHEAD(2) <K_TRUNCATE> <K_PARTITION> { alterExp.setOperation(AlterOperation.TRUNCATE_PARTITION); } truncatePartitionName = RelObjectName() { alterExp.setTruncatePartitionName(truncatePartitionName); }
|
tokens = captureRest() {
alterExp.setOperation(AlterOperation.UNSPECIFIC);
StringBuilder optionalSpecifier = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -981,4 +981,11 @@ public void testAlterColumnSetCommitTimestamp1() throws JSQLParserException {
assertEquals("UPDATE_DATE_TIME_GMT SET OPTIONS (allow_commit_timestamp=true)",
type.toString());
}

@Test
public void testIssue1890() throws JSQLParserException {
String stmt =
"ALTER TABLE xdmiddle.ft_mid_sop_sms_send_list_daily TRUNCATE PARTITION sum_date";
assertSqlCanBeParsedAndDeparsed(stmt);
}
}