Skip to content

Commit

Permalink
add postgresql refresh mv keywords support
Browse files Browse the repository at this point in the history
  • Loading branch information
shenQQQ authored and wenshao committed May 7, 2023
1 parent 3d721e0 commit 88a53c0
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,23 @@
public class SQLRefreshMaterializedViewStatement extends SQLStatementImpl {
private SQLExpr name;

private boolean concurrently;

private boolean withNoData;

private boolean withData;

public SQLRefreshMaterializedViewStatement() {
this.setConcurrently(false);
this.setWithData(false);
this.setWithNoData(false);
}

public SQLRefreshMaterializedViewStatement(DbType dbType) {
super(dbType);
this.setConcurrently(false);
this.setWithData(false);
this.setWithNoData(false);
}

@Override
Expand All @@ -53,6 +65,30 @@ public void setName(SQLExpr x) {
this.name = x;
}

public boolean isConcurrently() {
return concurrently;
}

public void setConcurrently(boolean concurrently) {
this.concurrently = concurrently;
}

public boolean isWithNoData() {
return withNoData;
}

public void setWithNoData(boolean withNoData) {
this.withNoData = withNoData;
}

public void setWithData(boolean withData) {
this.withData = withData;
}

public boolean isWithData() {
return withData;
}

@Override
public List<SQLObject> getChildren() {
List<SQLObject> children = new ArrayList<SQLObject>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -926,9 +926,29 @@ public SQLStatement parseRefresh() {

acceptIdentifier("MATERIALIZED");

if (lexer.identifierEquals("CONCURRENTLY")) {
lexer.nextToken();
stmt.setConcurrently(true);
}
accept(Token.VIEW);

stmt.setName(this.exprParser.name());

if (lexer.token() == WITH) {
lexer.nextToken();

if (lexer.token() == IDENTIFIER && "NO".equalsIgnoreCase(lexer.stringVal())) {
lexer.nextToken();
stmt.setWithNoData(true);
}

if (lexer.token() == IDENTIFIER && "DATA".equalsIgnoreCase(lexer.stringVal())) {
lexer.nextToken();
stmt.setWithData(true);
} else {
throw new ParserException("syntax error, expect DATA, actual " + lexer.token() + ", pos " + lexer.pos());
}
}
return stmt;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8560,8 +8560,22 @@ public boolean visit(SQLShowCreateMaterializedViewStatement x) {

@Override
public boolean visit(SQLRefreshMaterializedViewStatement x) {
print0(ucase ? "REFRESH MATERIALIZED VIEW " : "refresh materialized view ");
print0(ucase ? "REFRESH MATERIALIZED" : "refresh materialized");

if (x.isConcurrently()) {
print0(ucase ? " CONCURRENTLY" : " concurrently");
}

print0(ucase ? " VIEW " : " view ");

x.getName().accept(this);

if (x.isWithNoData()) {
print0(ucase ? " WITH NO DATA" : " with no data");
} else if (x.isWithData()) {
print0(ucase ? " WITH DATA" : " with data");
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public void test_14() throws Exception {
exec_test("bvt/parser/postgresql-14.txt");
}

public void test_15() throws Exception {
exec_test("bvt/parser/postgresql-15.txt");
}

public void exec_test(String resource) throws Exception {
System.out.println(resource);
InputStream is = null;
Expand Down
3 changes: 3 additions & 0 deletions core/src/test/resources/bvt/parser/postgresql-15.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
refresh materialized concurrently view v1 with no data
---------------------------
REFRESH MATERIALIZED CONCURRENTLY VIEW v1 WITH NO DATA

0 comments on commit 88a53c0

Please sign in to comment.