From 79dea08451c00938ae384634066300c4cebba886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Thu, 6 Nov 2025 14:51:12 +0100 Subject: [PATCH] chore: add CALL keyword to list of query keywords --- .../connection/AbstractStatementParser.java | 2 +- .../cloud/spanner/connection/CallTest.java | 65 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/CallTest.java diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractStatementParser.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractStatementParser.java index 698534844ea..4bf6609110f 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractStatementParser.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractStatementParser.java @@ -109,7 +109,7 @@ public static AbstractStatementParser getInstance(Dialect dialect) { static final Set ddlStatements = ImmutableSet.of("CREATE", "DROP", "ALTER", "ANALYZE", "GRANT", "REVOKE", "RENAME"); static final Set selectStatements = - ImmutableSet.of("SELECT", "WITH", "SHOW", "FROM", "GRAPH"); + ImmutableSet.of("SELECT", "WITH", "SHOW", "FROM", "GRAPH", "CALL"); static final Set SELECT_STATEMENTS_ALLOWING_PRECEDING_BRACKETS = ImmutableSet.of("SELECT", "FROM"); static final Set dmlStatements = ImmutableSet.of("INSERT", "UPDATE", "DELETE"); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/CallTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/CallTest.java new file mode 100644 index 00000000000..5a46d4cd58f --- /dev/null +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/CallTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.spanner.connection; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import com.google.cloud.spanner.MockSpannerServiceImpl; +import com.google.cloud.spanner.ResultSet; +import com.google.cloud.spanner.Statement; +import com.google.spanner.v1.ResultSetMetadata; +import com.google.spanner.v1.StructType; +import com.google.spanner.v1.StructType.Field; +import com.google.spanner.v1.Type; +import com.google.spanner.v1.TypeCode; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class CallTest extends AbstractMockServerTest { + + @Test + public void testCancelQuery() { + // 'CALL' should be recognized as a valid query keyword. + Statement statement = Statement.of("call cancel_query('1234')"); + mockSpanner.putStatementResult( + MockSpannerServiceImpl.StatementResult.query( + statement, + com.google.spanner.v1.ResultSet.newBuilder() + .setMetadata( + ResultSetMetadata.newBuilder() + .setRowType( + StructType.newBuilder() + .addFields( + Field.newBuilder() + .setName("call_result_tvf") + .setType(Type.newBuilder().setCode(TypeCode.BOOL).build()) + .build()) + .build()) + .build()) + .build())); + + try (Connection connection = createConnection()) { + try (ResultSet resultSet = connection.executeQuery(statement)) { + assertFalse(resultSet.next()); + assertEquals(1, resultSet.getColumnCount()); + } + } + } +}