Skip to content

Commit 1af682d

Browse files
authored
Support DROP MATERIALIZED VIEW statements (#1711)
1 parent f922e0d commit 1af682d

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

src/main/java/net/sf/jsqlparser/statement/drop/Drop.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class Drop implements Statement {
2828
private List<String> parameters;
2929
private Map<String, List<String>> typeToParameters = new HashMap<>();
3030
private boolean ifExists = false;
31+
private boolean materialized = false;
3132

3233
@Override
3334
public void accept(StatementVisitor statementVisitor) {
@@ -66,6 +67,14 @@ public void setIfExists(boolean ifExists) {
6667
this.ifExists = ifExists;
6768
}
6869

70+
public boolean isMaterialized() {
71+
return materialized;
72+
}
73+
74+
public void setMaterialized(boolean materialized) {
75+
this.materialized = materialized;
76+
}
77+
6978
public Map<String, List<String>> getTypeToParameters() {
7079
return typeToParameters;
7180
}
@@ -76,7 +85,9 @@ public void setTypeToParameters(Map<String, List<String>> typeToParameters) {
7685

7786
@Override
7887
public String toString() {
79-
String sql = "DROP " + type + " "
88+
String sql = "DROP "
89+
+ (materialized ? "MATERIALIZED " : "")
90+
+ type + " "
8091
+ (ifExists ? "IF EXISTS " : "") + name.toString();
8192

8293
if (type.equals("FUNCTION")) {
@@ -106,6 +117,11 @@ public Drop withIfExists(boolean ifExists) {
106117
return this;
107118
}
108119

120+
public Drop withMaterialized(boolean materialized) {
121+
this.setMaterialized(materialized);
122+
return this;
123+
}
124+
109125
public Drop withType(String type) {
110126
this.setType(type);
111127
return this;

src/main/java/net/sf/jsqlparser/util/deparser/DropDeParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public DropDeParser(StringBuilder buffer) {
2121
@Override
2222
public void deParse(Drop drop) {
2323
buffer.append("DROP ");
24+
if (drop.isMaterialized()) {
25+
buffer.append("MATERIALIZED ");
26+
}
2427
buffer.append(drop.getType());
2528
if (drop.isIfExists()) {
2629
buffer.append(" IF EXISTS");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5771,6 +5771,7 @@ Drop Drop():
57715771
}
57725772
{
57735773
<K_DROP>
5774+
[ <K_MATERIALIZED> { drop.setMaterialized(true);} ]
57745775
(
57755776
tk=<S_IDENTIFIER>
57765777
|

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ public void testDropViewIssue545_2() throws JSQLParserException {
8787
assertSqlCanBeParsedAndDeparsed("DROP VIEW IF EXISTS myview");
8888
}
8989

90+
@Test
91+
public void testDropMaterializedView() throws JSQLParserException {
92+
assertSqlCanBeParsedAndDeparsed("DROP MATERIALIZED VIEW myview");
93+
}
94+
9095
@Test
9196
public void testDropSchemaIssue855() throws JSQLParserException {
9297
assertSqlCanBeParsedAndDeparsed("DROP SCHEMA myschema");

0 commit comments

Comments
 (0)