Skip to content

Support DROP MATERIALIZED VIEW statements #1711

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 1 commit into from
Jan 12, 2023
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
18 changes: 17 additions & 1 deletion src/main/java/net/sf/jsqlparser/statement/drop/Drop.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Drop implements Statement {
private List<String> parameters;
private Map<String, List<String>> typeToParameters = new HashMap<>();
private boolean ifExists = false;
private boolean materialized = false;

@Override
public void accept(StatementVisitor statementVisitor) {
Expand Down Expand Up @@ -66,6 +67,14 @@ public void setIfExists(boolean ifExists) {
this.ifExists = ifExists;
}

public boolean isMaterialized() {
return materialized;
}

public void setMaterialized(boolean materialized) {
this.materialized = materialized;
}

public Map<String, List<String>> getTypeToParameters() {
return typeToParameters;
}
Expand All @@ -76,7 +85,9 @@ public void setTypeToParameters(Map<String, List<String>> typeToParameters) {

@Override
public String toString() {
String sql = "DROP " + type + " "
String sql = "DROP "
+ (materialized ? "MATERIALIZED " : "")
+ type + " "
+ (ifExists ? "IF EXISTS " : "") + name.toString();

if (type.equals("FUNCTION")) {
Expand Down Expand Up @@ -106,6 +117,11 @@ public Drop withIfExists(boolean ifExists) {
return this;
}

public Drop withMaterialized(boolean materialized) {
this.setMaterialized(materialized);
return this;
}

public Drop withType(String type) {
this.setType(type);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public DropDeParser(StringBuilder buffer) {
@Override
public void deParse(Drop drop) {
buffer.append("DROP ");
if (drop.isMaterialized()) {
buffer.append("MATERIALIZED ");
}
buffer.append(drop.getType());
if (drop.isIfExists()) {
buffer.append(" IF EXISTS");
Expand Down
1 change: 1 addition & 0 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -5698,6 +5698,7 @@ Drop Drop():
}
{
<K_DROP>
[ <K_MATERIALIZED> { drop.setMaterialized(true);} ]
(
tk=<S_IDENTIFIER>
|
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/net/sf/jsqlparser/statement/drop/DropTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public void testDropViewIssue545_2() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("DROP VIEW IF EXISTS myview");
}

@Test
public void testDropMaterializedView() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("DROP MATERIALIZED VIEW myview");
}

@Test
public void testDropSchemaIssue855() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("DROP SCHEMA myschema");
Expand Down