Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge branch 'master' into 1684-create-mv-auto-refresh
  • Loading branch information
zaza authored Dec 22, 2022
commit 9e090056df8de140a8cb52b3fe95b1b092e73039
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ public String toString() {
}
sql.append("VIEW ");
sql.append(view);
if (ifNotExists) {
sql.append(" IF NOT EXISTS");
}
if (autoRefresh != AutoRefreshOption.NONE) {
sql.append(" AUTO REFRESH ").append(autoRefresh.name());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public void deParse(CreateView createView) {
buffer.append("MATERIALIZED ");
}
buffer.append("VIEW ").append(createView.getView().getFullyQualifiedName());

if (createView.isIfNotExists()) {
buffer.append(" IF NOT EXISTS");
}
if (createView.getAutoRefresh() != AutoRefreshOption.NONE) {
buffer.append(" AUTO REFRESH ").append(createView.getAutoRefresh().name());
}
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 @@ -5491,6 +5491,7 @@ CreateView CreateView():
[ <K_MATERIALIZED> { createView.setMaterialized(true);} ]
<K_VIEW> view=Table() { createView.setView(view); }
[LOOKAHEAD(3) <K_AUTO> <K_REFRESH> (tk=<K_YES> | tk=<K_NO>) { createView.setAutoRefresh(AutoRefreshOption.valueOf(tk.image)); } ]
[LOOKAHEAD(3) <K_IF> <K_NOT> <K_EXISTS> {createView.setIfNotExists(true);}]
[ columnNames = ColumnsNamesList() { createView.setColumnNames(columnNames); } ]
<K_AS>
select=SelectWithWithItems( ) { createView.setSelect(select); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import static org.junit.jupiter.api.Assertions.assertFalse;

import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

public class CreateViewTest {
Expand Down Expand Up @@ -183,4 +185,19 @@ public void testCreateViewAutoRefreshFails() throws JSQLParserException {
.hasMessageStartingWith("Encountered unexpected token");
}

@Test
public void testCreateViewIfNotExists() throws JSQLParserException {
String stmt = "CREATE VIEW myview IF NOT EXISTS AS SELECT * FROM mytab";
CreateView createView = (CreateView) assertSqlCanBeParsedAndDeparsed(stmt);
assertTrue(createView.isIfNotExists());
}

@Test
public void testCreateMaterializedViewIfNotExists() throws JSQLParserException {
String stmt = "CREATE MATERIALIZED VIEW myview IF NOT EXISTS AS SELECT * FROM mytab";
CreateView createView = (CreateView) assertSqlCanBeParsedAndDeparsed(stmt);
assertTrue(createView.isMaterialized());
assertTrue(createView.isIfNotExists());
}

}
You are viewing a condensed version of this merge commit. You can view the full changes here.