Skip to content

Commit

Permalink
add simple materialized view parsing without additional parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
wumpz committed Apr 24, 2013
1 parent a661593 commit fa5daaa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class CreateView implements Statement {
private SelectBody selectBody;
private boolean orReplace = false;
private List<String> columnNames = null;
private boolean materialized = false;

@Override
public void accept(StatementVisitor statementVisitor) {
Expand Down Expand Up @@ -89,12 +90,23 @@ public void setColumnNames(List<String> columnNames) {
this.columnNames = columnNames;
}

public boolean isMaterialized() {
return materialized;
}

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

@Override
public String toString() {
StringBuilder sql = new StringBuilder("CREATE ");
if (isOrReplace()) {
sql.append("OR REPLACE ");
}
if (isMaterialized()) {
sql.append("MATERIALIZED ");
}
sql.append("VIEW ");
sql.append(view);
if (columnNames != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public void deParse(CreateView createView) {
if (createView.isOrReplace()) {
buffer.append("OR REPLACE ");
}
if (createView.isMaterialized()) {
buffer.append("MATERIALIZED ");
}
buffer.append("VIEW ").append(createView.getView().getWholeTableName());
if (createView.getColumnNames() != null) {
buffer.append(PlainSelect.getStringList(createView.getColumnNames(), true, true));
Expand Down
2 changes: 2 additions & 0 deletions src/main/javacc/net/sf/jsqlparser/parser/JSqlParserCC.jj
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
| <K_PARTITION:"PARTITION">
| <K_EXTRACT:"EXTRACT">
| <K_LATERAL:"LATERAL">
| <K_MATERIALIZED:"MATERIALIZED">
}


Expand Down Expand Up @@ -1857,6 +1858,7 @@ CreateView CreateView():
{
<K_CREATE>
[ <K_OR> <K_REPLACE> { createView.setOrReplace(true);} ]
[ <K_MATERIALIZED> { createView.setMaterialized(true);} ]
<K_VIEW> view=Table() { createView.setView(view); }
[ columnNames = ColumnsNamesList() { createView.setColumnNames(columnNames); } ]
<K_AS>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public void testCreateViewUnion() throws JSQLParserException {
String stmt = "CREATE VIEW view1 AS (SELECT a, b FROM testtab) UNION (SELECT b, c FROM testtab2)";
assertSqlCanBeParsedAndDeparsed(stmt);
}

public void testCreateMaterializedView() throws JSQLParserException {
String stmt = "CREATE MATERIALIZED VIEW view1 AS SELECT a, b FROM testtab";
assertSqlCanBeParsedAndDeparsed(stmt);
}

private void assertSqlCanBeParsedAndDeparsed(String statement) throws JSQLParserException {
Statement parsed = parserManager.parse(new StringReader(statement));
Expand Down

0 comments on commit fa5daaa

Please sign in to comment.