Skip to content

Commit 2cf8bfe

Browse files
authored
fix(parser): parse DuckDB DROP MACRO statements (#2954)
1 parent 12f17fb commit 2cf8bfe

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ and missing syntax gets added on demand — [open an issue](https://github.com/J
145145
| **DML** | `INSERT` · `UPDATE` · `UPSERT` · `MERGE` · `DELETE` · `TRUNCATE TABLE` |
146146
| **Oracle RETURNING** | Named output binds (`INTO :name`), JDBC output parameters (`INTO ?`), and `BULK COLLECT INTO` |
147147
| **DDL** | `CREATE …` · `ALTER …` · `DROP …` |
148+
| **DuckDB macro removal** | `DROP MACRO [IF EXISTS] name` · `DROP MACRO TABLE [IF EXISTS] name` |
148149
| **Oracle vector types** | `VECTOR(*, *)` · `VECTOR(*, FLOAT32)` · `VECTOR(3, *)`, including dense and sparse storage formats |
149150
| **PostgreSQL ownership** | `DROP OWNED` · `REASSIGN OWNED` |
150151
| **Two-phase commit** | PostgreSQL `PREPARE TRANSACTION` · `COMMIT PREPARED` · `ROLLBACK PREPARED` · MySQL `XA START`/`END`/`PREPARE`/`COMMIT`/`ROLLBACK`/`RECOVER` |

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25373,6 +25373,8 @@ Drop Drop():
2537325373
|
2537425374
[ <K_PUBLIC> { drop.setPublicSynonym(true); } ] tk=<K_SYNONYM>
2537525375
|
25376+
tk=<K_MACRO> [ LOOKAHEAD(1) <K_TABLE> { multiWordType = "MACRO TABLE"; } ]
25377+
|
2537625378
tk=<K_SEQUENCE>
2537725379
|
2537825380
tk=<K_TRIGGER>

‎src/test/java/net/sf/jsqlparser/statement/drop/DropTest.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
import net.sf.jsqlparser.statement.Statements;
2222
import static net.sf.jsqlparser.test.TestUtils.*;
2323
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
2425
import org.junit.jupiter.api.Test;
26+
import org.junit.jupiter.params.ParameterizedTest;
27+
import org.junit.jupiter.params.provider.ValueSource;
2528

2629
public class DropTest {
2730

@@ -85,6 +88,21 @@ public void testDropIfExists() throws JSQLParserException {
8588
assertEqualsObjectTree(parsed, created);
8689
}
8790

91+
@ParameterizedTest
92+
@ValueSource(strings = {"DROP MACRO simple", "DROP MACRO IF EXISTS main.named",
93+
"DROP MACRO TABLE rows_at", "DROP MACRO TABLE IF EXISTS main.\"user rows\""})
94+
void testDuckDbDropMacroRoundTrip(String statement) throws JSQLParserException {
95+
assertSqlCanBeParsedAndDeparsed(statement);
96+
}
97+
98+
@Test
99+
void testDuckDbDropTableMacroTypeAndName() throws JSQLParserException {
100+
Drop drop = (Drop) CCJSqlParserUtil.parse("DROP MACRO TABLE IF EXISTS main.rows_at");
101+
assertEquals("MACRO TABLE", drop.getType());
102+
assertEquals("main.rows_at", drop.getName().getFullyQualifiedName());
103+
assertTrue(drop.isIfExists());
104+
}
105+
88106
@Test
89107
public void testDropRestrictIssue510() throws JSQLParserException {
90108
String statement = "DROP TABLE TABLE2 RESTRICT";

0 commit comments

Comments
 (0)