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

fix: backend now supports optimizer version for DML #252

Merged
merged 8 commits into from Jun 10, 2020
Expand Up @@ -107,8 +107,7 @@ public void executeQuery() {

@Test
public void executeUpdate() {
// Query optimizer version is ignored for DML statements by the backend, but setting it does not
// cause an error.
// Optimizer version 1 should work.
assertThat(
client
.readWriteTransaction()
Expand Down Expand Up @@ -150,35 +149,38 @@ public Long run(TransactionContext transaction) throws Exception {
}))
.isEqualTo(1L);

// Version '100000' is an invalid value, but is ignored by the backend.
assertThat(
client
.readWriteTransaction()
.run(
new TransactionCallable<Long>() {
@Override
public Long run(TransactionContext transaction) throws Exception {
return transaction.executeUpdate(
Statement.newBuilder("INSERT INTO TEST (ID, NAME) VALUES (@id, @name)")
.bind("id")
.to(3L)
.bind("name")
.to("Three")
.withQueryOptions(
QueryOptions.newBuilder().setOptimizerVersion("10000").build())
.build());
}
}))
.isEqualTo(1L);
// Version '100000' is an invalid value and should cause an error.
try {
client
.readWriteTransaction()
.run(
new TransactionCallable<Long>() {
@Override
public Long run(TransactionContext transaction) throws Exception {
return transaction.executeUpdate(
Statement.newBuilder("INSERT INTO TEST (ID, NAME) VALUES (@id, @name)")
.bind("id")
.to(3L)
.bind("name")
.to("Three")
.withQueryOptions(
QueryOptions.newBuilder().setOptimizerVersion("100000").build())
.build());
}
});
fail("missing expected exception");
} catch (SpannerException e) {
assertThat(e.getErrorCode()).isEqualTo(ErrorCode.INVALID_ARGUMENT);
assertThat(e.getMessage()).contains("Query optimizer version: 100000 is not supported");
}

// Verify that query options are ignored with Partitioned DML as well, and that all the above
// DML INSERT statements succeeded.
// Setting an optimizer version for PDML should also be allowed.
assertThat(
client.executePartitionedUpdate(
Statement.newBuilder("UPDATE TEST SET NAME='updated' WHERE 1=1")
.withQueryOptions(QueryOptions.newBuilder().setOptimizerVersion("1").build())
.build()))
.isEqualTo(3L);
.isEqualTo(2L);
}

@Test
Expand Down