Skip to content

Commit 685bb09

Browse files
authored
chore: add CALL keyword to list of query keywords (googleapis#4196)
1 parent 9cdba74 commit 685bb09

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractStatementParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public static AbstractStatementParser getInstance(Dialect dialect) {
109109
static final Set<String> ddlStatements =
110110
ImmutableSet.of("CREATE", "DROP", "ALTER", "ANALYZE", "GRANT", "REVOKE", "RENAME");
111111
static final Set<String> selectStatements =
112-
ImmutableSet.of("SELECT", "WITH", "SHOW", "FROM", "GRAPH");
112+
ImmutableSet.of("SELECT", "WITH", "SHOW", "FROM", "GRAPH", "CALL");
113113
static final Set<String> SELECT_STATEMENTS_ALLOWING_PRECEDING_BRACKETS =
114114
ImmutableSet.of("SELECT", "FROM");
115115
static final Set<String> dmlStatements = ImmutableSet.of("INSERT", "UPDATE", "DELETE");
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.spanner.connection;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
21+
22+
import com.google.cloud.spanner.MockSpannerServiceImpl;
23+
import com.google.cloud.spanner.ResultSet;
24+
import com.google.cloud.spanner.Statement;
25+
import com.google.spanner.v1.ResultSetMetadata;
26+
import com.google.spanner.v1.StructType;
27+
import com.google.spanner.v1.StructType.Field;
28+
import com.google.spanner.v1.Type;
29+
import com.google.spanner.v1.TypeCode;
30+
import org.junit.Test;
31+
import org.junit.runner.RunWith;
32+
import org.junit.runners.JUnit4;
33+
34+
@RunWith(JUnit4.class)
35+
public class CallTest extends AbstractMockServerTest {
36+
37+
@Test
38+
public void testCancelQuery() {
39+
// 'CALL' should be recognized as a valid query keyword.
40+
Statement statement = Statement.of("call cancel_query('1234')");
41+
mockSpanner.putStatementResult(
42+
MockSpannerServiceImpl.StatementResult.query(
43+
statement,
44+
com.google.spanner.v1.ResultSet.newBuilder()
45+
.setMetadata(
46+
ResultSetMetadata.newBuilder()
47+
.setRowType(
48+
StructType.newBuilder()
49+
.addFields(
50+
Field.newBuilder()
51+
.setName("call_result_tvf")
52+
.setType(Type.newBuilder().setCode(TypeCode.BOOL).build())
53+
.build())
54+
.build())
55+
.build())
56+
.build()));
57+
58+
try (Connection connection = createConnection()) {
59+
try (ResultSet resultSet = connection.executeQuery(statement)) {
60+
assertFalse(resultSet.next());
61+
assertEquals(1, resultSet.getColumnCount());
62+
}
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)