Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix mock server ARRAY<BYTES> parameter cast #2344

Merged
merged 2 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ If you are using Maven without BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies:

```Groovy
implementation platform('com.google.cloud:libraries-bom:26.9.0')
implementation platform('com.google.cloud:libraries-bom:26.10.0')

implementation 'com.google.cloud:google-cloud-spanner'
```
If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.cloud:google-cloud-spanner:6.36.1'
implementation 'com.google.cloud:google-cloud-spanner:6.38.0'
```

If you are using SBT, add this to your dependencies:

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.36.1"
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.38.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query - Are these versions manually updated? Or is there an automated way of maintaining this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are automatic updates from the OwlBot (see 9ce2e8b)

```

## Authentication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.google.cloud.spanner.MockSpannerTestUtil.READ_ONE_KEY_VALUE_STATEMENT;
import static com.google.cloud.spanner.MockSpannerTestUtil.READ_TABLE_NAME;
import static com.google.cloud.spanner.MockSpannerTestUtil.SELECT1;
import static com.google.cloud.spanner.MockSpannerTestUtil.SELECT1_RESULTSET;
import static com.google.cloud.spanner.SpannerApiFutures.get;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -2943,6 +2944,24 @@ public void testMetadataUnknownTypes() {
}
}

@Test
public void testStatementWithBytesArrayParameter() {
Statement statement =
Statement.newBuilder("select id from test where b=@p1")
.bind("p1")
.toBytesArray(
ImmutableList.of(ByteArray.copyFrom("test1"), ByteArray.copyFrom("test2")))
.build();
mockSpanner.putStatementResult(StatementResult.query(statement, SELECT1_RESULTSET));
DatabaseClient client =
spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
try (ResultSet resultSet = client.singleUse().executeQuery(statement)) {
assertTrue(resultSet.next());
assertEquals(1L, resultSet.getLong(0));
assertFalse(resultSet.next());
}
}

static void assertAsString(String expected, ResultSet resultSet, int col) {
assertEquals(expected, resultSet.getValue(col).getAsString());
assertEquals(ImmutableList.of(expected), resultSet.getValue(col).getAsStringList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.cloud.ByteArray;
import com.google.cloud.Date;
import com.google.cloud.spanner.AbstractResultSet.GrpcStruct;
import com.google.cloud.spanner.AbstractResultSet.LazyByteArray;
import com.google.cloud.spanner.SessionPool.SessionPoolTransactionContext;
import com.google.cloud.spanner.TransactionRunnerImpl.TransactionContextImpl;
import com.google.common.base.Optional;
Expand Down Expand Up @@ -1362,9 +1363,11 @@ private Statement buildStatement(
builder
.bind(fieldName)
.toBytesArray(
(Iterable<ByteArray>)
GrpcStruct.decodeArrayValue(
com.google.cloud.spanner.Type.bytes(), value.getListValue()));
Iterables.transform(
(Iterable<LazyByteArray>)
GrpcStruct.decodeArrayValue(
com.google.cloud.spanner.Type.bytes(), value.getListValue()),
LazyByteArray::getByteArray));
break;
case DATE:
builder
Expand Down