File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed
main/java/com/google/cloud/spanner/jdbc
java/com/google/cloud/spanner/jdbc
resources/com/google/cloud/spanner/jdbc Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -161,7 +161,7 @@ ClientSideStatement getClientSideStatement() {
161161 }
162162
163163 private final Set <String > ddlStatements = ImmutableSet .of ("CREATE" , "DROP" , "ALTER" );
164- private final Set <String > selectStatements = ImmutableSet .of ("SELECT" );
164+ private final Set <String > selectStatements = ImmutableSet .of ("SELECT" , "WITH" );
165165 private final Set <String > dmlStatements = ImmutableSet .of ("INSERT" , "UPDATE" , "DELETE" );
166166 private final Set <ClientSideStatementImpl > statements ;
167167
Original file line number Diff line number Diff line change @@ -266,6 +266,27 @@ public void testIsQuery() {
266266 assertTrue (parser .isQuery ("select * from foo" ));
267267 assertFalse (parser .isQuery ("INSERT INTO FOO (ID, NAME) SELECT ID+1, NAME FROM FOO" ));
268268
269+ assertTrue (
270+ parser .isQuery (
271+ "WITH subQ1 AS (SELECT SchoolID FROM Roster),\n "
272+ + " subQ2 AS (SELECT OpponentID FROM PlayerStats)\n "
273+ + "SELECT * FROM subQ1\n "
274+ + "UNION ALL\n "
275+ + "SELECT * FROM subQ2" ));
276+ assertTrue (
277+ parser .isQuery (
278+ "with subQ1 AS (SELECT SchoolID FROM Roster),\n "
279+ + " subQ2 AS (SELECT OpponentID FROM PlayerStats)\n "
280+ + "select * FROM subQ1\n "
281+ + "UNION ALL\n "
282+ + "SELECT * FROM subQ2" ));
283+ assertTrue (
284+ parser
285+ .parse (
286+ Statement .of (
287+ "-- this is a comment\n with foo as (select * from bar)\n select * from foo" ))
288+ .isQuery ());
289+
269290 assertTrue (parser .parse (Statement .of ("-- this is a comment\n select * from foo" )).isQuery ());
270291 assertTrue (
271292 parser
@@ -310,6 +331,13 @@ public void testQueryHints() {
310331 assertTrue (
311332 parser .isQuery (
312333 "@{JOIN_METHOD=HASH_JOIN}\n /* Multi line comment\n with more comments\n */SELECT * FROM PersonsTable" ));
334+ assertTrue (
335+ parser .isQuery (
336+ "@{JOIN_METHOD=HASH_JOIN} WITH subQ1 AS (SELECT SchoolID FROM Roster),\n "
337+ + " subQ2 AS (SELECT OpponentID FROM PlayerStats)\n "
338+ + "SELECT * FROM subQ1\n "
339+ + "UNION ALL\n "
340+ + "SELECT * FROM subQ2" ));
313341
314342 // Invalid query hints.
315343 assertFalse (parser .isQuery ("@{JOIN_METHOD=HASH_JOIN SELECT * FROM PersonsTable" ));
Original file line number Diff line number Diff line change @@ -668,3 +668,8 @@ WHERE SingerId=2;
668668SELECT COUNT (* ) AS ACTUAL, 0 AS EXPECTED
669669FROM Songs
670670WHERE SingerId= 2 ;
671+
672+ @EXPECT RESULT_SET
673+ WITH Song2 AS (SELECT * FROM Songs WHERE SingerId= 2 )
674+ SELECT COUNT (* ) AS ACTUAL, 0 AS EXPECTED
675+ FROM Song2;
You can’t perform that action at this time.
0 commit comments