Skip to content

Commit cc7aa01

Browse files
SheldonKubormjh
and
mjh
authored
support oracle alter table truncate partition (#1954)
* feat: oracle alter table truncate partition * feat: oracle alter table truncate partition * feat: code format * feat: code format --------- Co-authored-by: mjh <[email protected]>
1 parent d9c4449 commit cc7aa01

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

src/main/java/net/sf/jsqlparser/statement/alter/AlterExpression.java

+18
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public class AlterExpression implements Serializable {
6868

6969
private boolean useBrackets = false;
7070

71+
private String truncatePartitionName = null;
72+
7173
public Index getOldIndex() {
7274
return oldIndex;
7375
}
@@ -402,6 +404,19 @@ public void setUk(boolean uk) {
402404
this.uk = uk;
403405
}
404406

407+
public String getTruncatePartitionName() {
408+
return truncatePartitionName;
409+
}
410+
411+
public void setTruncatePartitionName(String truncatePartitionName) {
412+
this.truncatePartitionName = truncatePartitionName;
413+
}
414+
415+
public AlterExpression withTruncatePartitionName(String truncatePartitionName) {
416+
this.truncatePartitionName = truncatePartitionName;
417+
return this;
418+
}
419+
405420
@Override
406421
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity",
407422
"PMD.ExcessiveMethodLength", "PMD.SwitchStmtsShouldHaveDefault"})
@@ -441,6 +456,9 @@ public String toString() {
441456
&& !pkColumns.isEmpty()) {
442457
// Oracle Multi Column Drop
443458
b.append("DROP (").append(PlainSelect.getStringList(pkColumns)).append(')');
459+
} else if (operation == AlterOperation.TRUNCATE_PARTITION
460+
&& truncatePartitionName != null) {
461+
b.append("TRUNCATE PARTITION ").append(truncatePartitionName);
444462
} else {
445463
if (operation == AlterOperation.COMMENT_WITH_EQUAL_SIGN) {
446464
b.append("COMMENT =").append(" ");

src/main/java/net/sf/jsqlparser/statement/alter/AlterOperation.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
package net.sf.jsqlparser.statement.alter;
1111

1212
public enum AlterOperation {
13-
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;
13+
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;
1414

1515
public static AlterOperation from(String operation) {
1616
return Enum.valueOf(AlterOperation.class, operation.toUpperCase());

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

+3
Original file line numberDiff line numberDiff line change
@@ -6255,6 +6255,7 @@ AlterExpression AlterExpression():
62556255
AlterExpression.ColumnDropNotNull alterExpressionColumnDropNotNull = null;
62566256
AlterExpression.ColumnDropDefault alterExpressionColumnDropDefault = null;
62576257
ReferentialAction.Action action = null;
6258+
String truncatePartitionName = null;
62586259

62596260
// for captureRest()
62606261
List<String> tokens = new LinkedList<String>();
@@ -6546,6 +6547,8 @@ AlterExpression AlterExpression():
65466547
}
65476548
)
65486549
|
6550+
LOOKAHEAD(2) <K_TRUNCATE> <K_PARTITION> { alterExp.setOperation(AlterOperation.TRUNCATE_PARTITION); } truncatePartitionName = RelObjectName() { alterExp.setTruncatePartitionName(truncatePartitionName); }
6551+
|
65496552
tokens = captureRest() {
65506553
alterExp.setOperation(AlterOperation.UNSPECIFIC);
65516554
StringBuilder optionalSpecifier = new StringBuilder();

src/test/java/net/sf/jsqlparser/statement/alter/AlterTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -981,4 +981,11 @@ public void testAlterColumnSetCommitTimestamp1() throws JSQLParserException {
981981
assertEquals("UPDATE_DATE_TIME_GMT SET OPTIONS (allow_commit_timestamp=true)",
982982
type.toString());
983983
}
984+
985+
@Test
986+
public void testIssue1890() throws JSQLParserException {
987+
String stmt =
988+
"ALTER TABLE xdmiddle.ft_mid_sop_sms_send_list_daily TRUNCATE PARTITION sum_date";
989+
assertSqlCanBeParsedAndDeparsed(stmt);
990+
}
984991
}

0 commit comments

Comments
 (0)