Skip to content

Commit cd21b27

Browse files
authored
Merge branch 'main' into grpc_metrics_poc
2 parents e147597 + c5a2045 commit cd21b27

File tree

16 files changed

+354
-95
lines changed

16 files changed

+354
-95
lines changed

.kokoro/build.sh

+7-4
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ integration)
9898
-Dclirr.skip=true \
9999
-Denforcer.skip=true \
100100
-Dmaven.main.skip=true \
101-
-Dspanner.gce.config.project_id=gcloud-devel \
102-
-Dspanner.testenv.instance=projects/gcloud-devel/instances/java-client-integration-tests \
101+
-Dspanner.gce.config.server_url=https://staging-wrenchworks.sandbox.googleapis.com \
102+
-Dspanner.gce.config.project_id=span-cloud-testing \
103+
-Dspanner.testenv.instance=projects/span-cloud-testing/instances/java-client-integration-tests \
103104
-fae \
104105
verify
105106
RETURN_CODE=$?
@@ -113,6 +114,7 @@ integration-directpath-enabled)
113114
-Dclirr.skip=true \
114115
-Denforcer.skip=true \
115116
-Dmaven.main.skip=true \
117+
-Dspanner.gce.config.server_url=https://staging-wrenchworks.sandbox.googleapis.com \
116118
-Dspanner.testenv.instance=projects/span-cloud-testing/instances/spanner-java-client-directpath \
117119
-Dspanner.gce.config.project_id=span-cloud-testing \
118120
-fae \
@@ -128,8 +130,9 @@ integration-multiplexed-sessions-enabled)
128130
-Dclirr.skip=true \
129131
-Denforcer.skip=true \
130132
-Dmaven.main.skip=true \
131-
-Dspanner.gce.config.project_id=gcloud-devel \
132-
-Dspanner.testenv.instance=projects/gcloud-devel/instances/java-client-integration-tests-multiplexed-sessions \
133+
-Dspanner.gce.config.server_url=https://staging-wrenchworks.sandbox.googleapis.com \
134+
-Dspanner.gce.config.project_id=span-cloud-testing \
135+
-Dspanner.testenv.instance=projects/span-cloud-testing/instances/java-client-integration-tests-multiplexed-sessions \
133136
-fae \
134137
verify
135138
RETURN_CODE=$?

.kokoro/presubmit/integration-directpath-enabled.cfg

-11
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@ env_vars: {
1111
value: "integration-directpath-enabled"
1212
}
1313

14-
# TODO: remove this after we've migrated all tests and scripts
15-
env_vars: {
16-
key: "GCLOUD_PROJECT"
17-
value: "gcloud-devel"
18-
}
19-
20-
env_vars: {
21-
key: "GOOGLE_CLOUD_PROJECT"
22-
value: "gcloud-devel"
23-
}
24-
2514
env_vars: {
2615
key: "GOOGLE_APPLICATION_CREDENTIALS"
2716
value: "secret_manager/java-client-testing"

.kokoro/presubmit/integration-multiplexed-sessions-enabled.cfg

+2-13
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,14 @@ env_vars: {
1111
value: "integration-multiplexed-sessions-enabled"
1212
}
1313

14-
# TODO: remove this after we've migrated all tests and scripts
15-
env_vars: {
16-
key: "GCLOUD_PROJECT"
17-
value: "gcloud-devel"
18-
}
19-
20-
env_vars: {
21-
key: "GOOGLE_CLOUD_PROJECT"
22-
value: "gcloud-devel"
23-
}
24-
2514
env_vars: {
2615
key: "GOOGLE_APPLICATION_CREDENTIALS"
27-
value: "secret_manager/java-it-service-account"
16+
value: "secret_manager/java-client-testing"
2817
}
2918

3019
env_vars: {
3120
key: "SECRET_MANAGER_KEYS"
32-
value: "java-it-service-account"
21+
value: "java-client-testing"
3322
}
3423

3524
env_vars: {

.kokoro/presubmit/integration.cfg

+2-14
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,12 @@ env_vars: {
1111
value: "integration"
1212
}
1313

14-
# TODO: remove this after we've migrated all tests and scripts
15-
env_vars: {
16-
key: "GCLOUD_PROJECT"
17-
value: "gcloud-devel"
18-
}
19-
20-
env_vars: {
21-
key: "GOOGLE_CLOUD_PROJECT"
22-
value: "gcloud-devel"
23-
}
24-
2514
env_vars: {
2615
key: "GOOGLE_APPLICATION_CREDENTIALS"
27-
value: "secret_manager/java-it-service-account"
16+
value: "secret_manager/java-client-testing"
2817
}
2918

3019
env_vars: {
3120
key: "SECRET_MANAGER_KEYS"
32-
value: "java-it-service-account"
21+
value: "java-client-testing"
3322
}
34-

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file:
1919
<dependency>
2020
<groupId>com.google.cloud</groupId>
2121
<artifactId>libraries-bom</artifactId>
22-
<version>26.54.0</version>
22+
<version>26.57.0</version>
2323
<type>pom</type>
2424
<scope>import</scope>
2525
</dependency>
@@ -525,6 +525,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-spanner/tree/
525525
| Create Sequence Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateSequenceSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateSequenceSample.java) |
526526
| Create Table With Foreign Key Delete Cascade Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateTableWithForeignKeyDeleteCascadeSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateTableWithForeignKeyDeleteCascadeSample.java) |
527527
| Custom Timeout And Retry Settings Example | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CustomTimeoutAndRetrySettingsExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CustomTimeoutAndRetrySettingsExample.java) |
528+
| Database Add Split Points Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/DatabaseAddSplitPointsSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/DatabaseAddSplitPointsSample.java) |
528529
| Delete Backup Schedule Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/DeleteBackupScheduleSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/DeleteBackupScheduleSample.java) |
529530
| Delete Instance Config Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/DeleteInstanceConfigSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/DeleteInstanceConfigSample.java) |
530531
| Delete Using Dml Returning Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/DeleteUsingDmlReturningSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/DeleteUsingDmlReturningSample.java) |

google-cloud-spanner/clirr-ignored-differences.xml

+18-1
Original file line numberDiff line numberDiff line change
@@ -935,4 +935,21 @@
935935
<field>VALID_PROPERTIES</field>
936936
</difference>
937937

938-
</differences>
938+
<!-- Remove supportsExplain() from the parser -->
939+
<difference>
940+
<differenceType>7002</differenceType>
941+
<className>com/google/cloud/spanner/connection/AbstractStatementParser</className>
942+
<method>boolean supportsExplain()</method>
943+
</difference>
944+
<difference>
945+
<differenceType>7002</differenceType>
946+
<className>com/google/cloud/spanner/connection/PostgreSQLStatementParser</className>
947+
<method>boolean supportsExplain()</method>
948+
</difference>
949+
<difference>
950+
<differenceType>7002</differenceType>
951+
<className>com/google/cloud/spanner/connection/SpannerStatementParser</className>
952+
<method>boolean supportsExplain()</method>
953+
</difference>
954+
955+
</differences>

google-cloud-spanner/pom.xml

+13
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,19 @@
521521
</execution>
522522
</executions>
523523
</plugin>
524+
<plugin>
525+
<groupId>org.apache.maven.plugins</groupId>
526+
<artifactId>maven-compiler-plugin</artifactId>
527+
<configuration>
528+
<annotationProcessorPaths>
529+
<path>
530+
<groupId>org.openjdk.jmh</groupId>
531+
<artifactId>jmh-generator-annprocess</artifactId>
532+
<version>1.37</version>
533+
</path>
534+
</annotationProcessorPaths>
535+
</configuration>
536+
</plugin>
524537
</plugins>
525538
</build>
526539
</profile>

google-cloud-spanner/src/main/java/com/google/cloud/spanner/Statement.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.google.cloud.spanner.ReadContext.QueryAnalyzeMode;
2323
import com.google.common.base.Preconditions;
24+
import com.google.common.collect.ImmutableMap;
2425
import com.google.spanner.v1.ExecuteSqlRequest.QueryOptions;
2526
import java.io.Serializable;
2627
import java.util.Collections;
@@ -140,7 +141,7 @@ Builder handle(Value value) {
140141

141142
/** Creates a {@code Statement} with the given SQL text {@code sql}. */
142143
public static Statement of(String sql) {
143-
return newBuilder(sql).build();
144+
return new Statement(sql, ImmutableMap.of(), /*queryOptions=*/ null);
144145
}
145146

146147
/** Creates a new statement builder with the SQL text {@code sql}. */

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

+27-23
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.google.cloud.spanner.connection.UnitOfWork.CallType;
3232
import com.google.common.annotations.VisibleForTesting;
3333
import com.google.common.base.Preconditions;
34+
import com.google.common.base.Splitter;
3435
import com.google.common.cache.Cache;
3536
import com.google.common.cache.CacheBuilder;
3637
import com.google.common.cache.CacheStats;
@@ -41,6 +42,7 @@
4142
import java.util.Collection;
4243
import java.util.Collections;
4344
import java.util.HashMap;
45+
import java.util.Iterator;
4446
import java.util.Map;
4547
import java.util.Objects;
4648
import java.util.Set;
@@ -511,7 +513,7 @@ ParsedStatement parse(Statement statement, QueryOptions defaultQueryOptions) {
511513
return parsedStatement.copy(statement, defaultQueryOptions);
512514
}
513515

514-
private ParsedStatement internalParse(Statement statement, QueryOptions defaultQueryOptions) {
516+
ParsedStatement internalParse(Statement statement, QueryOptions defaultQueryOptions) {
515517
StatementHintParser statementHintParser =
516518
new StatementHintParser(getDialect(), statement.getSql());
517519
ReadQueryUpdateTransactionOption[] optionsFromHints = EMPTY_OPTIONS;
@@ -521,16 +523,21 @@ private ParsedStatement internalParse(Statement statement, QueryOptions defaultQ
521523
statement.toBuilder().replace(statementHintParser.getSqlWithoutClientSideHints()).build();
522524
optionsFromHints = convertHintsToOptions(statementHintParser.getClientSideStatementHints());
523525
}
526+
// TODO: Qualify statements without removing comments first.
524527
String sql = removeCommentsAndTrim(statement.getSql());
525528
ClientSideStatementImpl client = parseClientSideStatement(sql);
526529
if (client != null) {
527530
return ParsedStatement.clientSideStatement(client, statement, sql);
528-
} else if (isQuery(sql)) {
529-
return ParsedStatement.query(statement, sql, defaultQueryOptions, optionsFromHints);
530-
} else if (isUpdateStatement(sql)) {
531-
return ParsedStatement.update(statement, sql, checkReturningClause(sql), optionsFromHints);
532-
} else if (isDdlStatement(sql)) {
533-
return ParsedStatement.ddl(statement, sql);
531+
} else {
532+
String sqlWithoutHints =
533+
!sql.isEmpty() && sql.charAt(0) == '@' ? removeStatementHint(sql) : sql;
534+
if (isQuery(sqlWithoutHints)) {
535+
return ParsedStatement.query(statement, sql, defaultQueryOptions, optionsFromHints);
536+
} else if (isUpdateStatement(sqlWithoutHints)) {
537+
return ParsedStatement.update(statement, sql, checkReturningClause(sql), optionsFromHints);
538+
} else if (isDdlStatement(sqlWithoutHints)) {
539+
return ParsedStatement.ddl(statement, sql);
540+
}
534541
}
535542
return ParsedStatement.unknown(statement, sql);
536543
}
@@ -610,20 +617,16 @@ public boolean isUpdateStatement(String sql) {
610617
return statementStartsWith(sql, dmlStatements);
611618
}
612619

613-
protected abstract boolean supportsExplain();
614-
615620
private boolean statementStartsWith(String sql, Iterable<String> checkStatements) {
616621
Preconditions.checkNotNull(sql);
617-
String[] tokens = sql.split("\\s+", 2);
618-
int checkIndex = 0;
619-
if (supportsExplain() && tokens[0].equalsIgnoreCase("EXPLAIN")) {
620-
checkIndex = 1;
621-
}
622-
if (tokens.length > checkIndex) {
623-
for (String check : checkStatements) {
624-
if (tokens[checkIndex].equalsIgnoreCase(check)) {
625-
return true;
626-
}
622+
Iterator<String> tokens = Splitter.onPattern("\\s+").split(sql).iterator();
623+
if (!tokens.hasNext()) {
624+
return false;
625+
}
626+
String token = tokens.next();
627+
for (String check : checkStatements) {
628+
if (token.equalsIgnoreCase(check)) {
629+
return true;
627630
}
628631
}
629632
return false;
@@ -929,7 +932,8 @@ int skipQuoted(
929932
appendIfNotNull(result, startQuote);
930933
appendIfNotNull(result, startQuote);
931934
}
932-
while (currentIndex < sql.length()) {
935+
int length = sql.length();
936+
while (currentIndex < length) {
933937
char currentChar = sql.charAt(currentIndex);
934938
if (currentChar == startQuote) {
935939
if (supportsDollarQuotedStrings() && currentChar == DOLLAR) {
@@ -940,7 +944,7 @@ int skipQuoted(
940944
return currentIndex + tag.length() + 2;
941945
}
942946
} else if (supportsEscapeQuoteWithQuote()
943-
&& sql.length() > currentIndex + 1
947+
&& length > currentIndex + 1
944948
&& sql.charAt(currentIndex + 1) == startQuote) {
945949
// This is an escaped quote (e.g. 'foo''bar')
946950
appendIfNotNull(result, currentChar);
@@ -949,7 +953,7 @@ int skipQuoted(
949953
continue;
950954
} else if (isTripleQuoted) {
951955
// Check if this is the end of the triple-quoted string.
952-
if (sql.length() > currentIndex + 2
956+
if (length > currentIndex + 2
953957
&& sql.charAt(currentIndex + 1) == startQuote
954958
&& sql.charAt(currentIndex + 2) == startQuote) {
955959
appendIfNotNull(result, currentChar);
@@ -963,7 +967,7 @@ int skipQuoted(
963967
}
964968
} else if (supportsBackslashEscape()
965969
&& currentChar == BACKSLASH
966-
&& sql.length() > currentIndex + 1
970+
&& length > currentIndex + 1
967971
&& sql.charAt(currentIndex + 1) == startQuote) {
968972
// This is an escaped quote (e.g. 'foo\'bar').
969973
// Note that in raw strings, the \ officially does not start an escape sequence, but the

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

+8-16
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,6 @@ Dialect getDialect() {
4646
return Dialect.POSTGRESQL;
4747
}
4848

49-
/**
50-
* Indicates whether the parser supports the {@code EXPLAIN} clause. The PostgreSQL parser does
51-
* not support it.
52-
*/
53-
@Override
54-
protected boolean supportsExplain() {
55-
return false;
56-
}
57-
5849
@Override
5950
boolean supportsNestedComments() {
6051
return true;
@@ -125,7 +116,8 @@ String removeCommentsAndTrimInternal(String sql) {
125116
int multiLineCommentStartIdx = -1;
126117
StringBuilder res = new StringBuilder(sql.length());
127118
int index = 0;
128-
while (index < sql.length()) {
119+
int length = sql.length();
120+
while (index < length) {
129121
char c = sql.charAt(index);
130122
if (isInSingleLineComment) {
131123
if (c == '\n') {
@@ -134,34 +126,34 @@ String removeCommentsAndTrimInternal(String sql) {
134126
res.append(c);
135127
}
136128
} else if (multiLineCommentLevel > 0) {
137-
if (sql.length() > index + 1 && c == ASTERISK && sql.charAt(index + 1) == SLASH) {
129+
if (length > index + 1 && c == ASTERISK && sql.charAt(index + 1) == SLASH) {
138130
multiLineCommentLevel--;
139131
if (multiLineCommentLevel == 0) {
140-
if (!whitespaceBeforeOrAfterMultiLineComment && (sql.length() > index + 2)) {
132+
if (!whitespaceBeforeOrAfterMultiLineComment && (length > index + 2)) {
141133
whitespaceBeforeOrAfterMultiLineComment =
142134
Character.isWhitespace(sql.charAt(index + 2));
143135
}
144136
// If the multiline comment does not have any whitespace before or after it, and it is
145137
// neither at the start nor at the end of SQL string, append an extra space.
146138
if (!whitespaceBeforeOrAfterMultiLineComment
147139
&& (multiLineCommentStartIdx != 0)
148-
&& (index != sql.length() - 2)) {
140+
&& (index != length - 2)) {
149141
res.append(' ');
150142
}
151143
}
152144
index++;
153-
} else if (sql.length() > index + 1 && c == SLASH && sql.charAt(index + 1) == ASTERISK) {
145+
} else if (length > index + 1 && c == SLASH && sql.charAt(index + 1) == ASTERISK) {
154146
multiLineCommentLevel++;
155147
index++;
156148
}
157149
} else {
158150
// Check for -- which indicates the start of a single-line comment.
159-
if (sql.length() > index + 1 && c == HYPHEN && sql.charAt(index + 1) == HYPHEN) {
151+
if (length > index + 1 && c == HYPHEN && sql.charAt(index + 1) == HYPHEN) {
160152
// This is a single line comment.
161153
isInSingleLineComment = true;
162154
index += 2;
163155
continue;
164-
} else if (sql.length() > index + 1 && c == SLASH && sql.charAt(index + 1) == ASTERISK) {
156+
} else if (length > index + 1 && c == SLASH && sql.charAt(index + 1) == ASTERISK) {
165157
multiLineCommentLevel++;
166158
if (index >= 1) {
167159
whitespaceBeforeOrAfterMultiLineComment = Character.isWhitespace(sql.charAt(index - 1));

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

-9
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,6 @@ Dialect getDialect() {
4646
return Dialect.GOOGLE_STANDARD_SQL;
4747
}
4848

49-
/**
50-
* Indicates whether the parser supports the {@code EXPLAIN} clause. The Spanner parser does
51-
* support it.
52-
*/
53-
@Override
54-
protected boolean supportsExplain() {
55-
return true;
56-
}
57-
5849
@Override
5950
boolean supportsNestedComments() {
6051
return false;

0 commit comments

Comments
 (0)