Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
747152a
Fixes #1684: Support CREATE MATERIALIZED VIEW with AUTO REFRESH
zaza Dec 11, 2022
9e09005
Merge branch 'master' into 1684-create-mv-auto-refresh
zaza Dec 22, 2022
ea4477b
Reduce cyclomatic complexity in CreateView.toString
zaza Jan 8, 2023
b5321d6
Enhanced Keywords
manticore-projects Oct 18, 2021
5fae2f5
Fix incorrect tests
manticore-projects Oct 18, 2021
f49e828
Define Reserved Keywords explicitly
manticore-projects Oct 24, 2021
86f337d
Fix test resources
manticore-projects Oct 24, 2021
2d51a82
Adjust Gradle to JUnit 5
manticore-projects Nov 22, 2021
232aff6
Do not mark SpeedTest for concurrent execution
manticore-projects Nov 24, 2021
3ba5410
Remove unused imports
manticore-projects Nov 28, 2021
e960a35
Adjust Gradle to JUnit 5
manticore-projects Nov 22, 2021
67f7951
Do not mark SpeedTest for concurrent execution
manticore-projects Nov 24, 2021
a016be0
Remove unused imports
manticore-projects Nov 28, 2021
2ef6637
Sphinx Documentation
manticore-projects Sep 2, 2022
57193b8
doc: request for `Conventional Commit` messages
manticore-projects Sep 6, 2022
b94b2cc
feat: make important Classes Serializable
manticore-projects Sep 15, 2022
02202c5
chore: Make Serializable
manticore-projects Oct 14, 2022
a3ca325
doc: Better integration of the RR diagrams
manticore-projects Jan 7, 2023
fcb5ab1
Merge
manticore-projects Jan 7, 2023
c57c427
feat: Oracle Alternative Quoting
manticore-projects Jan 29, 2023
2aec1f6
style: Appease PMD/Codacy
manticore-projects Jan 29, 2023
1c8d8da
feat: CREATE VIEW ... REFRESH AUTO...
manticore-projects Jan 30, 2023
b707b23
doc: fix the issue template
manticore-projects Feb 1, 2023
46314c4
Update issue templates
manticore-projects Feb 1, 2023
4aeafbc
Update issue templates
manticore-projects Feb 1, 2023
b081484
feat: Support more Statement Separators
manticore-projects Feb 2, 2023
5885e1c
Merge remote-tracking branch 'origin/master'
manticore-projects Feb 13, 2023
581d97a
Merge branch 'master' of https://github.com/JSQLParser/JSqlParser
manticore-projects Feb 24, 2023
0979b2e
feat: FETCH uses EXPRESSION
manticore-projects Mar 7, 2023
ed17f87
style: apply Spotless
manticore-projects Mar 7, 2023
96808d2
test: commit missing test
manticore-projects Mar 7, 2023
2ecfd49
feat: Unicode CJK Unified Ideographs (Unicode block)
manticore-projects Mar 7, 2023
ec542cf
feat: Unicode CJK Unified Ideographs (Unicode block)
manticore-projects Mar 8, 2023
25043d2
feat: Functions with nested Attributes
manticore-projects Mar 8, 2023
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
Next Next commit
Fixes #1684: Support CREATE MATERIALIZED VIEW with AUTO REFRESH
Support parsing create view statements in Redshift with AUTO REFRESH
option.
  • Loading branch information
zaza committed Dec 11, 2022
commit 747152a9fc1bfd1562391de3dc567c844b0a2e01
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ public static List<String> getReservedKeywords(int restriction) {

, { "NEXTVAL", RESTRICTED_JSQLPARSER }

, { "AUTO", RESTRICTED_JSQLPARSER }
, { "REFRESH", RESTRICTED_JSQLPARSER }
, { "YES", RESTRICTED_JSQLPARSER }
, { "NO", RESTRICTED_JSQLPARSER }

//@todo: Object Names should not start with Hex-Prefix, we shall not find that Token
, { "0x", RESTRICTED_JSQLPARSER }
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement.create.view;

public enum AutoRefreshOption {
NONE,

YES,

NO
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class CreateView implements Statement {
private boolean materialized = false;
private ForceOption force = ForceOption.NONE;
private TemporaryOption temp = TemporaryOption.NONE;
private AutoRefreshOption autoRefresh = AutoRefreshOption.NONE;
private boolean withReadOnly = false;

@Override
Expand Down Expand Up @@ -95,6 +96,14 @@ public void setTemporary(TemporaryOption temp) {
this.temp = temp;
}

public AutoRefreshOption getAutoRefresh() {
return autoRefresh;
}

public void setAutoRefresh(AutoRefreshOption autoRefresh) {
this.autoRefresh = autoRefresh;
}

public boolean isWithReadOnly() {
return withReadOnly;
}
Expand Down Expand Up @@ -129,6 +138,9 @@ public String toString() {
}
sql.append("VIEW ");
sql.append(view);
if (autoRefresh != AutoRefreshOption.NONE) {
sql.append(" AUTO REFRESH ").append(autoRefresh.name());
}
if (columnNames != null) {
sql.append(PlainSelect.getStringList(columnNames, true, true));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import net.sf.jsqlparser.statement.create.view.CreateView;
import net.sf.jsqlparser.statement.create.view.TemporaryOption;
import net.sf.jsqlparser.statement.create.view.AutoRefreshOption;
import net.sf.jsqlparser.statement.select.PlainSelect;
import net.sf.jsqlparser.statement.select.Select;
import net.sf.jsqlparser.statement.select.SelectVisitor;
Expand Down Expand Up @@ -60,6 +61,10 @@ public void deParse(CreateView createView) {
buffer.append("MATERIALIZED ");
}
buffer.append("VIEW ").append(createView.getView().getFullyQualifiedName());

if (createView.getAutoRefresh() != AutoRefreshOption.NONE) {
buffer.append(" AUTO REFRESH ").append(createView.getAutoRefresh().name());
}
if (createView.getColumnNames() != null) {
buffer.append(PlainSelect.getStringList(createView.getColumnNames(), true, true));
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
| <K_AT: "AT">
| <K_ASC:"ASC">
| <K_AUTHORIZATION:"AUTHORIZATION">
| <K_AUTO:"AUTO">
| <K_BEGIN:"BEGIN">
| <K_BETWEEN:"BETWEEN">
| <K_BINARY: "BINARY">
Expand Down Expand Up @@ -345,6 +346,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
| <K_RECYCLEBIN: "RECYCLEBIN">
| <K_RECURSIVE:"RECURSIVE">
| <K_REFERENCES:"REFERENCES">
| <K_REFRESH:"REFRESH">
| <K_REGEXP: "REGEXP">
| <K_RLIKE: "RLIKE">
| <K_REGISTER: "REGISTER">
Expand Down Expand Up @@ -439,6 +441,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
| <K_XMLAGG:"XMLAGG">
| <K_XMLTEXT:"XMLTEXT">
| <K_YAML:"YAML">
| <K_YES:"YES">
| <K_ZONE:"ZONE">
}

Expand Down Expand Up @@ -5406,6 +5409,7 @@ CreateView CreateView():
Table view = null;
Select select = null;
List<String> columnNames = null;
Token tk = null;
}
{
<K_CREATE>
Expand All @@ -5420,6 +5424,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)); } ]
[ 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 @@ -10,14 +10,21 @@
package net.sf.jsqlparser.statement.create;

import java.io.StringReader;

import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.CCJSqlParserManager;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.parser.ParseException;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.create.view.AutoRefreshOption;
import net.sf.jsqlparser.statement.create.view.CreateView;
import net.sf.jsqlparser.statement.select.PlainSelect;
import static net.sf.jsqlparser.test.TestUtils.*;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.junit.jupiter.api.Test;

public class CreateViewTest {
Expand Down Expand Up @@ -121,4 +128,59 @@ public void testCreateTemporaryViewIssue665() throws JSQLParserException {
public void testCreateWithReadOnlyViewIssue838() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE VIEW v14(c1, c2) AS SELECT c1, C2 FROM t1 WITH READ ONLY");
}

@Test
public void testCreateViewAutoRefreshNone() throws JSQLParserException {
String stmt = "CREATE VIEW myview AS SELECT * FROM mytab";
CreateView createView = (CreateView) assertSqlCanBeParsedAndDeparsed(stmt);
assertEquals(createView.getAutoRefresh(), AutoRefreshOption.NONE);
}

@Test
public void testCreateViewAutoRefreshYes() throws JSQLParserException {
String stmt = "CREATE VIEW myview AUTO REFRESH YES AS SELECT * FROM mytab";
CreateView createView = (CreateView) assertSqlCanBeParsedAndDeparsed(stmt);
assertEquals(createView.getAutoRefresh(), AutoRefreshOption.YES);
}

@Test
public void testCreateViewAutoRefreshNo() throws JSQLParserException {
String stmt = "CREATE VIEW myview AUTO REFRESH NO AS SELECT * FROM mytab";
CreateView createView = (CreateView) assertSqlCanBeParsedAndDeparsed(stmt);
assertEquals(createView.getAutoRefresh(), AutoRefreshOption.NO);
}

@Test
public void testCreateViewAutoFails() throws JSQLParserException {
String stmt = "CREATE VIEW myview AUTO AS SELECT * FROM mytab";

ThrowingCallable throwingCallable = () -> CCJSqlParserUtil.parse(stmt);

assertThatThrownBy(throwingCallable).isInstanceOf(JSQLParserException.class)
.hasRootCauseInstanceOf(ParseException.class).rootCause()
.hasMessageStartingWith("Encountered unexpected token");
}

@Test
public void testCreateViewRefreshFails() throws JSQLParserException {
String stmt = "CREATE VIEW myview REFRESH AS SELECT * FROM mytab";

ThrowingCallable throwingCallable = () -> CCJSqlParserUtil.parse(stmt);

assertThatThrownBy(throwingCallable).isInstanceOf(JSQLParserException.class)
.hasRootCauseInstanceOf(ParseException.class).rootCause()
.hasMessageStartingWith("Encountered unexpected token");
}

@Test
public void testCreateViewAutoRefreshFails() throws JSQLParserException {
String stmt = "CREATE VIEW myview AUTO REFRESH AS SELECT * FROM mytab";

ThrowingCallable throwingCallable = () -> CCJSqlParserUtil.parse(stmt);

assertThatThrownBy(throwingCallable).isInstanceOf(JSQLParserException.class)
.hasRootCauseInstanceOf(ParseException.class).rootCause()
.hasMessageStartingWith("Encountered unexpected token");
}

}