From 12952d64f87bdef0354627e1dc533bbf95b0dcd3 Mon Sep 17 00:00:00 2001 From: Minjae Lee Date: Thu, 14 Nov 2024 10:05:19 +0900 Subject: [PATCH] Fix issue 2106: Add parsing functionality for MySQL ADD PARTITION and DROP PARTITION clauses in ALTER TABLE statements(2) (#2108) * feat MySQL Alter add partition * fix PartitionDefinition to Serializable * add Engine variable to MySQL partition definition * fix: Update parser to correctly handle ENGINE token and pass existing CREATE TABLE tests * feat mysql alter drop partition * refactor truncate partition * fix codacy * fix: add LOOKAHEADs Signed-off-by: Andreas Reichel * doc: mention running `gradle check` Signed-off-by: Andreas Reichel * style: add license header Signed-off-by: Andreas Reichel --------- Signed-off-by: Andreas Reichel Co-authored-by: mj-db Co-authored-by: Andreas Reichel --- .../statement/alter/AlterExpression.java | 28 +++----- .../statement/alter/AlterOperation.java | 2 +- .../create/table/PartitionDefinition.java | 21 +++++- .../net/sf/jsqlparser/parser/JSqlParserCC.jjt | 46 +++++++++++-- src/site/sphinx/contribution.rst | 17 ++++- src/site/sphinx/unsupported.rst | 12 ---- .../jsqlparser/statement/alter/AlterTest.java | 69 +++++++++++++++++++ 7 files changed, 158 insertions(+), 37 deletions(-) diff --git a/src/main/java/net/sf/jsqlparser/statement/alter/AlterExpression.java b/src/main/java/net/sf/jsqlparser/statement/alter/AlterExpression.java index 97cbd209a..38bed4b7a 100644 --- a/src/main/java/net/sf/jsqlparser/statement/alter/AlterExpression.java +++ b/src/main/java/net/sf/jsqlparser/statement/alter/AlterExpression.java @@ -49,6 +49,7 @@ public class AlterExpression implements Serializable { private boolean uk; private boolean useEqual; + private List partitions; private List partitionDefinitions; private List constraints; private List parameters; @@ -63,8 +64,6 @@ public class AlterExpression implements Serializable { private boolean useBrackets = false; - private String truncatePartitionName = null; - private boolean useIfNotExists = false; public Index getOldIndex() { @@ -433,19 +432,6 @@ 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; - } - public boolean isUseIfNotExists() { return useIfNotExists; } @@ -499,8 +485,8 @@ public String toString() { // 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); + && partitions != null) { + b.append("TRUNCATE PARTITION ").append(PlainSelect.getStringList(partitions)); } else { if (operation == AlterOperation.COMMENT_WITH_EQUAL_SIGN) { b.append("COMMENT =").append(" "); @@ -784,6 +770,14 @@ public AlterExpression addConstraints(Collection cons return this.withConstraints(collection); } + public List getPartitions() { + return partitions; + } + + public void setPartitions(List partitions) { + this.partitions = partitions; + } + public List getPartitionDefinitions() { return partitionDefinitions; } diff --git a/src/main/java/net/sf/jsqlparser/statement/alter/AlterOperation.java b/src/main/java/net/sf/jsqlparser/statement/alter/AlterOperation.java index d34775398..f7cd0a4a3 100644 --- a/src/main/java/net/sf/jsqlparser/statement/alter/AlterOperation.java +++ b/src/main/java/net/sf/jsqlparser/statement/alter/AlterOperation.java @@ -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, CONVERT, ALGORITHM, RENAME, RENAME_TABLE, RENAME_INDEX, RENAME_KEY, RENAME_CONSTRAINT, COMMENT, COMMENT_WITH_EQUAL_SIGN, UNSPECIFIC, ADD_PARTITION, TRUNCATE_PARTITION, LOCK; + ADD, ALTER, DROP, DROP_PRIMARY_KEY, DROP_UNIQUE, DROP_FOREIGN_KEY, MODIFY, CHANGE, CONVERT, ALGORITHM, RENAME, RENAME_TABLE, RENAME_INDEX, RENAME_KEY, RENAME_CONSTRAINT, COMMENT, COMMENT_WITH_EQUAL_SIGN, UNSPECIFIC, ADD_PARTITION, DROP_PARTITION, TRUNCATE_PARTITION, LOCK; public static AlterOperation from(String operation) { return Enum.valueOf(AlterOperation.class, operation.toUpperCase()); diff --git a/src/main/java/net/sf/jsqlparser/statement/create/table/PartitionDefinition.java b/src/main/java/net/sf/jsqlparser/statement/create/table/PartitionDefinition.java index d7a873c47..a79f242ed 100644 --- a/src/main/java/net/sf/jsqlparser/statement/create/table/PartitionDefinition.java +++ b/src/main/java/net/sf/jsqlparser/statement/create/table/PartitionDefinition.java @@ -1,3 +1,12 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2024 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ package net.sf.jsqlparser.statement.create.table; import java.io.Serializable; @@ -7,12 +16,14 @@ public class PartitionDefinition implements Serializable { private String partitionName; private String partitionOperation; private List values; + private String storageEngine; public PartitionDefinition(String partitionName, String partitionOperation, - List values) { + List values, String storageEngine) { this.partitionName = partitionName; this.partitionOperation = partitionOperation; this.values = values; + this.storageEngine = storageEngine; } public String getPartitionName() { @@ -38,4 +49,12 @@ public List getValues() { public void setValues(List values) { this.values = values; } + + public String getStorageEngine() { + return storageEngine; + } + + public void setStorageEngine(String storageEngine) { + this.storageEngine = storageEngine; + } } diff --git a/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt b/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt index 062930cac..51b111cfb 100644 --- a/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt +++ b/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt @@ -245,6 +245,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */ | | | +| | | | @@ -2021,7 +2022,7 @@ String RelObjectNameWithoutValue() : { Token tk = null; } { ( tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= - | tk="ACTION" | tk="ACTIVE" | tk="ADD" | tk="ADVANCE" | tk="ADVISE" | tk="AGAINST" | tk="ALGORITHM" | tk="ALTER" | tk="ANALYZE" | tk="APPLY" | tk="APPROXIMATE" | tk="ARCHIVE" | tk="ARRAY" | tk="ASC" | tk="AT" | tk="AUTHORIZATION" | tk="AUTO" | tk="BASE64" | tk="BEGIN" | tk="BERNOULLI" | tk="BINARY" | tk="BIT" | tk="BLOCK" | tk="BROWSE" | tk="BUFFERS" | tk="BY" | tk="BYTE" | tk="BYTES" | tk="CACHE" | tk="CALL" | tk="CASCADE" | tk="CASE" | tk="CAST" | tk="CHANGE" | tk="CHANGES" | tk="CHAR" | tk="CHARACTER" | tk="CHECKPOINT" | tk="CLOSE" | tk="COLLATE" | tk="COLUMN" | tk="COLUMNS" | tk="COMMENT" | tk="COMMIT" | tk="CONCURRENTLY" | tk="CONFLICT" | tk="CONSTRAINTS" | tk="CONVERT" | tk="COSTS" | tk="COUNT" | tk="CS" | tk="CYCLE" | tk="DATA" | tk="DATABASE" | tk="DATETIME" | tk="DBA_RECYCLEBIN" | tk="DDL" | tk="DECLARE" | tk="DEFERRABLE" | tk="DELAYED" | tk="DELETE" | tk="DESC" | tk="DESCRIBE" | tk="DISABLE" | tk="DISCONNECT" | tk="DIV" | tk="DML" | tk="DO" | tk="DOMAIN" | tk="DROP" | tk="DUMP" | tk="DUPLICATE" | tk="ELEMENTS" | tk="EMIT" | tk="ENABLE" | tk="END" | tk="ERROR" | tk="ESCAPE" | tk="EXCLUDE" | tk="EXEC" | tk="EXECUTE" | tk="EXPLAIN" | tk="EXPLICIT" | tk="EXTENDED" | tk="EXTRACT" | tk="FALSE" | tk="FILTER" | tk="FIRST" | tk="FLUSH" | tk="FN" | tk="FOLLOWING" | tk="FORMAT" | tk="FULLTEXT" | tk="FUNCTION" | tk="GRANT" | tk="GROUP_CONCAT" | tk="GUARD" | tk="HASH" | tk="HIGH_PRIORITY" | tk="HISTORY" | tk="HOPPING" | tk="INCLUDE" | tk="INCLUDE_NULL_VALUES" | tk="INCREMENT" | tk="INDEX" | tk="INSERT" | tk="INTERLEAVE" | tk="INTERPRET" | tk="INVALIDATE" | tk="ISNULL" | tk="JSON" | tk="JSON_ARRAY" | tk="JSON_ARRAYAGG" | tk="JSON_OBJECT" | tk="JSON_OBJECTAGG" | tk="KEEP" | tk="KEY" | tk="KEYS" | tk="LAST" | tk="LEADING" | tk="LESS" | tk="LINK" | tk="LOCAL" | tk="LOCK" | tk="LOCKED" | tk="LOG" | tk="LONGTEXT" | tk="LOOP" | tk="LOW_PRIORITY" | tk="MATCH" | tk="MATCHED" | tk="MATERIALIZED" | tk="MAX" | tk="MAXVALUE" | tk="MEDIUMTEXT" | tk="MEMBER" | tk="MERGE" | tk="MIN" | tk="MINVALUE" | tk="MODIFY" | tk="MOVEMENT" | tk="NEXT" | tk="NO" | tk="NOCACHE" | tk="NOKEEP" | tk="NOLOCK" | tk="NOMAXVALUE" | tk="NOMINVALUE" | tk="NOORDER" | tk="NOTHING" | tk="NOTNULL" | tk="NOVALIDATE" | tk="NOWAIT" | tk="NULLS" | tk="OF" | tk="OFF" | tk="OPEN" | tk="OVER" | tk="OVERFLOW" | tk="OVERLAPS" | tk="PARALLEL" | tk="PARENT" | tk="PARTITION" | tk="PATH" | tk="PERCENT" | tk="PLACING" | tk="PLAN" | tk="PRECEDING" | tk="PRIMARY" | tk="PURGE" | tk="QUERY" | tk="QUICK" | tk="QUIESCE" | tk="RANGE" | tk="RAW" | tk="READ" | tk="RECURSIVE" | tk="RECYCLEBIN" | tk="REFERENCES" | tk="REFRESH" | tk="REGEXP" | tk="REGEXP_LIKE" | tk="REGISTER" | tk="REMOTE" | tk="RENAME" | tk="REPEATABLE" | tk="REPLACE" | tk="RESET" | tk="RESPECT" | tk="RESTART" | tk="RESTRICT" | tk="RESTRICTED" | tk="RESUMABLE" | tk="RESUME" | tk="RETURN" | tk="RLIKE" | tk="ROLLBACK" | tk="ROLLUP" | tk="ROOT" | tk="ROW" | tk="ROWS" | tk="RR" | tk="RS" | tk="SAFE_CAST" | tk="SAVEPOINT" | tk="SCHEMA" | tk="SECURE" | tk="SEED" | tk="SEPARATOR" | tk="SEQUENCE" | tk="SESSION" | tk="SETS" | tk="SHARE" | tk="SHOW" | tk="SHUTDOWN" | tk="SIBLINGS" | tk="SIGNED" | tk="SIMILAR" | tk="SIZE" | tk="SKIP" | tk="STORED" | tk="STRING" | tk="STRUCT" | tk="SUMMARIZE" | tk="SUSPEND" | tk="SWITCH" | tk="SYNONYM" | tk="SYSTEM" | tk="TABLE" | tk="TABLESPACE" | tk="TEMP" | tk="TEMPORARY" | tk="TEXT" | tk="THAN" | tk="THEN" | tk="TIMEOUT" | tk="TIMESTAMPTZ" | tk="TIMEZONE" | tk="TINYTEXT" | tk="TO" | tk="TRIGGER" | tk="TRUE" | tk="TRUNCATE" | tk="TRY_CAST" | tk="TUMBLING" | tk="TYPE" | tk="UNLOGGED" | tk="UNQIESCE" | tk="UNSIGNED" | tk="UPDATE" | tk="UPSERT" | tk="UR" | tk="USER" | tk="VALIDATE" | tk="VERBOSE" | tk="VIEW" | tk="VOLATILE" | tk="WAIT" | tk="WITHIN" | tk="WITHOUT" | tk="WITHOUT_ARRAY_WRAPPER" | tk="WORK" | tk="XML" | tk="XMLAGG" | tk="XMLDATA" | tk="XMLSCHEMA" | tk="XMLTEXT" | tk="XSINIL" | tk="YAML" | tk="YES" | tk="ZONE" ) + | tk="ACTION" | tk="ACTIVE" | tk="ADD" | tk="ADVANCE" | tk="ADVISE" | tk="AGAINST" | tk="ALGORITHM" | tk="ALTER" | tk="ANALYZE" | tk="APPLY" | tk="APPROXIMATE" | tk="ARCHIVE" | tk="ARRAY" | tk="ASC" | tk="AT" | tk="AUTHORIZATION" | tk="AUTO" | tk="BASE64" | tk="BEGIN" | tk="BERNOULLI" | tk="BINARY" | tk="BIT" | tk="BLOCK" | tk="BROWSE" | tk="BUFFERS" | tk="BY" | tk="BYTE" | tk="BYTES" | tk="CACHE" | tk="CALL" | tk="CASCADE" | tk="CASE" | tk="CAST" | tk="CHANGE" | tk="CHANGES" | tk="CHAR" | tk="CHARACTER" | tk="CHECKPOINT" | tk="CLOSE" | tk="COLLATE" | tk="COLUMN" | tk="COLUMNS" | tk="COMMENT" | tk="COMMIT" | tk="CONCURRENTLY" | tk="CONFLICT" | tk="CONSTRAINTS" | tk="CONVERT" | tk="COSTS" | tk="COUNT" | tk="CS" | tk="CYCLE" | tk="DATA" | tk="DATABASE" | tk="DATETIME" | tk="DBA_RECYCLEBIN" | tk="DDL" | tk="DECLARE" | tk="DEFERRABLE" | tk="DELAYED" | tk="DELETE" | tk="DESC" | tk="DESCRIBE" | tk="DISABLE" | tk="DISCONNECT" | tk="DIV" | tk="DML" | tk="DO" | tk="DOMAIN" | tk="DROP" | tk="DUMP" | tk="DUPLICATE" | tk="ELEMENTS" | tk="EMIT" | tk="ENABLE" | tk="END" | tk="ENGINE" | tk="ERROR" | tk="ESCAPE" | tk="EXCLUDE" | tk="EXEC" | tk="EXECUTE" | tk="EXPLAIN" | tk="EXPLICIT" | tk="EXTENDED" | tk="EXTRACT" | tk="FALSE" | tk="FILTER" | tk="FIRST" | tk="FLUSH" | tk="FN" | tk="FOLLOWING" | tk="FORMAT" | tk="FULLTEXT" | tk="FUNCTION" | tk="GRANT" | tk="GROUP_CONCAT" | tk="GUARD" | tk="HASH" | tk="HIGH_PRIORITY" | tk="HISTORY" | tk="HOPPING" | tk="INCLUDE" | tk="INCLUDE_NULL_VALUES" | tk="INCREMENT" | tk="INDEX" | tk="INSERT" | tk="INTERLEAVE" | tk="INTERPRET" | tk="INVALIDATE" | tk="ISNULL" | tk="JSON" | tk="JSON_ARRAY" | tk="JSON_ARRAYAGG" | tk="JSON_OBJECT" | tk="JSON_OBJECTAGG" | tk="KEEP" | tk="KEY" | tk="KEYS" | tk="LAST" | tk="LEADING" | tk="LESS" | tk="LINK" | tk="LOCAL" | tk="LOCK" | tk="LOCKED" | tk="LOG" | tk="LONGTEXT" | tk="LOOP" | tk="LOW_PRIORITY" | tk="MATCH" | tk="MATCHED" | tk="MATERIALIZED" | tk="MAX" | tk="MAXVALUE" | tk="MEDIUMTEXT" | tk="MEMBER" | tk="MERGE" | tk="MIN" | tk="MINVALUE" | tk="MODIFY" | tk="MOVEMENT" | tk="NEXT" | tk="NO" | tk="NOCACHE" | tk="NOKEEP" | tk="NOLOCK" | tk="NOMAXVALUE" | tk="NOMINVALUE" | tk="NOORDER" | tk="NOTHING" | tk="NOTNULL" | tk="NOVALIDATE" | tk="NOWAIT" | tk="NULLS" | tk="OF" | tk="OFF" | tk="OPEN" | tk="OVER" | tk="OVERFLOW" | tk="OVERLAPS" | tk="PARALLEL" | tk="PARENT" | tk="PARTITION" | tk="PATH" | tk="PERCENT" | tk="PLACING" | tk="PLAN" | tk="PRECEDING" | tk="PRIMARY" | tk="PURGE" | tk="QUERY" | tk="QUICK" | tk="QUIESCE" | tk="RANGE" | tk="RAW" | tk="READ" | tk="RECURSIVE" | tk="RECYCLEBIN" | tk="REFERENCES" | tk="REFRESH" | tk="REGEXP" | tk="REGEXP_LIKE" | tk="REGISTER" | tk="REMOTE" | tk="RENAME" | tk="REPEATABLE" | tk="REPLACE" | tk="RESET" | tk="RESPECT" | tk="RESTART" | tk="RESTRICT" | tk="RESTRICTED" | tk="RESUMABLE" | tk="RESUME" | tk="RETURN" | tk="RLIKE" | tk="ROLLBACK" | tk="ROLLUP" | tk="ROOT" | tk="ROW" | tk="ROWS" | tk="RR" | tk="RS" | tk="SAFE_CAST" | tk="SAVEPOINT" | tk="SCHEMA" | tk="SECURE" | tk="SEED" | tk="SEPARATOR" | tk="SEQUENCE" | tk="SESSION" | tk="SETS" | tk="SHARE" | tk="SHOW" | tk="SHUTDOWN" | tk="SIBLINGS" | tk="SIGNED" | tk="SIMILAR" | tk="SIZE" | tk="SKIP" | tk="STORED" | tk="STRING" | tk="STRUCT" | tk="SUMMARIZE" | tk="SUSPEND" | tk="SWITCH" | tk="SYNONYM" | tk="SYSTEM" | tk="TABLE" | tk="TABLESPACE" | tk="TEMP" | tk="TEMPORARY" | tk="TEXT" | tk="THAN" | tk="THEN" | tk="TIMEOUT" | tk="TIMESTAMPTZ" | tk="TIMEZONE" | tk="TINYTEXT" | tk="TO" | tk="TRIGGER" | tk="TRUE" | tk="TRUNCATE" | tk="TRY_CAST" | tk="TUMBLING" | tk="TYPE" | tk="UNLOGGED" | tk="UNQIESCE" | tk="UNSIGNED" | tk="UPDATE" | tk="UPSERT" | tk="UR" | tk="USER" | tk="VALIDATE" | tk="VERBOSE" | tk="VIEW" | tk="VOLATILE" | tk="WAIT" | tk="WITHIN" | tk="WITHOUT" | tk="WITHOUT_ARRAY_WRAPPER" | tk="WORK" | tk="XML" | tk="XMLAGG" | tk="XMLDATA" | tk="XMLSCHEMA" | tk="XMLTEXT" | tk="XSINIL" | tk="YAML" | tk="YES" | tk="ZONE" ) { return tk.image; } } @@ -6695,6 +6696,7 @@ List CreateParameter(): | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk = | tk = + | tk= | tk="=" ) { param.add(tk.image); } @@ -7022,6 +7024,7 @@ List PartitionDefinitions(): PartitionDefinition partitionDef = null; String partitionName = null; String partitionOperation = null; + String storageEngine = null; } { "(" @@ -7044,8 +7047,9 @@ List PartitionDefinitions(): partitionOperation = "VALUES LESS THAN"; } ) + [ "ENGINE" "=" tk= { storageEngine = tk.image; } ] { - partitionDef = new PartitionDefinition(partitionName, partitionOperation, values); + partitionDef = new PartitionDefinition(partitionName, partitionOperation, values, storageEngine); partitionDefinitions.add(partitionDef); } [ "," ] @@ -7056,6 +7060,26 @@ List PartitionDefinitions(): } } + +List PartitionNamesList() : +{ + Token tk; + List partitionNames = new ArrayList(); +} +{ + tk = { + partitionNames.add(tk.image); + } + ( + LOOKAHEAD(2) "," tk = { + partitionNames.add(tk.image); + } + )* + { + return partitionNames; + } +} + /** * This production needs refactoring to multiple smaller productions. The target class should * be splitted as well. @@ -7077,6 +7101,7 @@ AlterExpression AlterExpression(): AlterExpression.ColumnDropNotNull alterExpressionColumnDropNotNull = null; AlterExpression.ColumnDropDefault alterExpressionColumnDropDefault = null; ReferentialAction.Action action = null; + List partitions = null; List partitionDefinition = null; String truncatePartitionName = null; @@ -7120,9 +7145,8 @@ AlterExpression AlterExpression(): sk3=RelObjectName() tk= { alterExp.withColumnName(sk3).withCommentText(tk.image); } ) | - ( + LOOKAHEAD(3) ( { - System.out.println("test _ Partition"); alterExp.setOperation(AlterOperation.ADD_PARTITION); } partitionDefinition=PartitionDefinitions() { @@ -7292,6 +7316,15 @@ AlterExpression AlterExpression(): | { alterExp.setOperation(AlterOperation.DROP); } ( + ( + { + alterExp.setOperation(AlterOperation.DROP_PARTITION); + } + partitions=PartitionNamesList() { + alterExp.setPartitions(partitions); + } + ) + | ( ( // we use the PK Columns Field instead of the Column Field @@ -7403,7 +7436,10 @@ AlterExpression AlterExpression(): } ) | - LOOKAHEAD(2) { alterExp.setOperation(AlterOperation.TRUNCATE_PARTITION); } truncatePartitionName = RelObjectName() { alterExp.setTruncatePartitionName(truncatePartitionName); } + LOOKAHEAD(2) { alterExp.setOperation(AlterOperation.TRUNCATE_PARTITION); } + partitions=PartitionNamesList() { + alterExp.setPartitions(partitions); + } | tokens = captureRest() { alterExp.setOperation(AlterOperation.UNSPECIFIC); diff --git a/src/site/sphinx/contribution.rst b/src/site/sphinx/contribution.rst index c001f8eb5..65fd49e4d 100644 --- a/src/site/sphinx/contribution.rst +++ b/src/site/sphinx/contribution.rst @@ -61,7 +61,22 @@ The JSQLParser is generated by ``JavaCC`` based on the provided Grammar. The Gra * The complete test suite must succeed. 5) Add the description of the new feature to the ``README.md`` file, section `Extensions`. - 6) Build the package with ``Maven`` and ensure, all checks do pass (PMD and CheckStyle and Code Formatting). + 6) Build the package with ``Gradle`` and ensure, all checks do pass (PMD and CheckStyle and Code Formatting). + .. tab:: Gradle + + .. code-block:: shell + :caption: Gradle `check` Task + + gradle check + + .. tab:: Maven + + .. code-block:: shell + :caption: Maven `verify` Task + + mvn verify + + 7) Create your `GitHub Pull Request `_ Manage Reserved Keywords ------------------------------ diff --git a/src/site/sphinx/unsupported.rst b/src/site/sphinx/unsupported.rst index b6489a84a..b0ad1bc0c 100644 --- a/src/site/sphinx/unsupported.rst +++ b/src/site/sphinx/unsupported.rst @@ -5,14 +5,6 @@ Unsupported Grammar of various RDBMS *JSQLParser* is a RDBMS agnostic parser with a certain focus on SQL:2016 Standard compliant Queries and the "Big Four" (Oracle, MS SQL Server, Postgres, MySQL/MariaDB). We would like to recommend writing portable, standard compliant SQL in general. -- Postgres Implicit cast is not supported. - - .. code-block:: java - - SELECT date '2022-12-31'; - SELECT double precision 1; - - - Oracle PL/SQL blocks are not support. .. code-block:: sql @@ -40,10 +32,6 @@ We would like to recommend writing portable, standard compliant SQL in general. While *JSQLParser* provides a lot of generic support for DDL statements, it is possible that certain RDBMS specific syntax (especially about indices, encodings, compression) won't be supported. -- `JSON` or `XML` specific syntax and functions - - While *JSQLParser* provides a lot of generic support for `JSON` or `XML` processing, it is possible that certain RDBMS specific syntax or functions won't be supported. - - Interval Operators Anything like `DAY HOUR MINUTE SECOND [TO HOUR MINUTE SECOND]` is not supported.: diff --git a/src/test/java/net/sf/jsqlparser/statement/alter/AlterTest.java b/src/test/java/net/sf/jsqlparser/statement/alter/AlterTest.java index d5edbf938..79a11def2 100644 --- a/src/test/java/net/sf/jsqlparser/statement/alter/AlterTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/alter/AlterTest.java @@ -1206,4 +1206,73 @@ public void testIssue2106AlterTableAddPartition3() throws JSQLParserException { assertEquals("VALUES LESS THAN", partitions.get(1).getPartitionOperation()); assertEquals(Collections.singletonList("MAXVALUE"), partitions.get(1).getValues()); } + + @Test + public void testIssue2106AlterTableAddPartitionCodeTransaction() throws JSQLParserException { + String sql = + "ALTER TABLE `code_transaction` ADD PARTITION (PARTITION p202108 VALUES LESS THAN ('20210901') ENGINE = InnoDB);"; + Statement stmt = CCJSqlParserUtil.parse(sql); + assertTrue(stmt instanceof Alter); + Alter alter = (Alter) stmt; + List alterExpressions = alter.getAlterExpressions(); + assertNotNull(alterExpressions); + assertEquals(1, alterExpressions.size()); + + AlterExpression partitionExp = alterExpressions.get(0); + assertEquals(AlterOperation.ADD_PARTITION, partitionExp.getOperation()); + List partitions = partitionExp.getPartitionDefinitions(); + assertNotNull(partitions); + assertEquals(1, partitions.size()); + + assertEquals("p202108", partitions.get(0).getPartitionName()); + assertEquals("VALUES LESS THAN", partitions.get(0).getPartitionOperation()); + assertEquals(Collections.singletonList("'20210901'"), partitions.get(0).getValues()); + assertEquals("InnoDB", partitions.get(0).getStorageEngine()); + } + + @Test + public void testIssue2106AlterTableDropPartition() throws JSQLParserException { + String sql = + "ALTER TABLE dkpg_payment_details DROP PARTITION p202007, p202008, p202009, p202010"; + Statement stmt = CCJSqlParserUtil.parse(sql); + assertTrue(stmt instanceof Alter); + Alter alter = (Alter) stmt; + List alterExpressions = alter.getAlterExpressions(); + assertNotNull(alterExpressions); + assertEquals(1, alterExpressions.size()); + + AlterExpression partitionExp = alterExpressions.get(0); + assertEquals(AlterOperation.DROP_PARTITION, partitionExp.getOperation()); + List partitionNames = partitionExp.getPartitions(); + assertNotNull(partitionNames); + assertEquals(4, partitionNames.size()); + + assertEquals("p202007", partitionNames.get(0)); + assertEquals("p202008", partitionNames.get(1)); + assertEquals("p202009", partitionNames.get(2)); + assertEquals("p202010", partitionNames.get(3)); + } + + @Test + public void testIssue2106AlterTableTruncatePartition() throws JSQLParserException { + String sql = + "ALTER TABLE dkpg_payments TRUNCATE PARTITION p201701, p201707, p201801, p201807"; + Statement stmt = CCJSqlParserUtil.parse(sql); + assertTrue(stmt instanceof Alter); + Alter alter = (Alter) stmt; + List alterExpressions = alter.getAlterExpressions(); + assertNotNull(alterExpressions); + assertEquals(1, alterExpressions.size()); + + AlterExpression partitionExp = alterExpressions.get(0); + assertEquals(AlterOperation.TRUNCATE_PARTITION, partitionExp.getOperation()); + List partitionNames = partitionExp.getPartitions(); + assertNotNull(partitionNames); + assertEquals(4, partitionNames.size()); + + assertEquals("p201701", partitionNames.get(0)); + assertEquals("p201707", partitionNames.get(1)); + assertEquals("p201801", partitionNames.get(2)); + assertEquals("p201807", partitionNames.get(3)); + } }