use of com.google.spanner.v1.ExecuteSqlRequest.QueryOptions in project java-spanner by googleapis.
the class SpannerImplTest method queryOptions.
@Test
public void queryOptions() {
QueryOptions queryOptions = QueryOptions.newBuilder().setOptimizerVersion("2").setOptimizerStatisticsPackage("custom-package").build();
QueryOptions defaultOptions = QueryOptions.getDefaultInstance();
DatabaseId db = DatabaseId.of("p", "i", "d");
DatabaseId otherDb = DatabaseId.of("p", "i", "other");
// Create a SpannerOptions with and without default query options.
SpannerOptions optionsWithQueryOptions = new SpannerOptions.Builder(SpannerOptions.newBuilder().setProjectId("some-project").setCredentials(NoCredentials.getInstance()).build()) {
@Override
QueryOptions getEnvironmentQueryOptions() {
// interfering with the test case.
return QueryOptions.getDefaultInstance();
}
}.setDefaultQueryOptions(db, queryOptions).build();
SpannerOptions optionsWithoutQueryOptions = new SpannerOptions.Builder(SpannerOptions.newBuilder().setProjectId("some-project").setCredentials(NoCredentials.getInstance()).build()) {
@Override
QueryOptions getEnvironmentQueryOptions() {
// interfering with the test case.
return QueryOptions.getDefaultInstance();
}
}.build();
try (SpannerImpl implWithQueryOptions = new SpannerImpl(rpc, optionsWithQueryOptions);
SpannerImpl implWithoutQueryOptions = new SpannerImpl(rpc, optionsWithoutQueryOptions)) {
// Default query options are on a per-database basis, so we should only get the custom options
// for 'db' and not for 'otherDb'.
assertThat(implWithQueryOptions.getDefaultQueryOptions(db)).isEqualTo(queryOptions);
assertThat(implWithQueryOptions.getDefaultQueryOptions(otherDb)).isEqualTo(defaultOptions);
// The other Spanner instance should return default options for both databases.
assertThat(implWithoutQueryOptions.getDefaultQueryOptions(db)).isEqualTo(defaultOptions);
assertThat(implWithoutQueryOptions.getDefaultQueryOptions(otherDb)).isEqualTo(defaultOptions);
}
}
use of com.google.spanner.v1.ExecuteSqlRequest.QueryOptions in project cloud-spanner-r2dbc by GoogleCloudPlatform.
the class SpannerClientLibraryStatementTest method optimizerVersionPassedThroughToQuery.
@Test
void optimizerVersionPassedThroughToQuery() {
QueryOptions queryOptions = QueryOptions.newBuilder().setOptimizerVersion("2").build();
when(this.mockAdapter.getQueryOptions()).thenReturn(queryOptions);
SpannerClientLibraryRow mockRow = mock(SpannerClientLibraryRow.class);
when(this.mockAdapter.runSelectStatement(any())).thenReturn(Flux.just(mockRow));
SpannerClientLibraryStatement statement = new SpannerClientLibraryStatement(this.mockAdapter, "SELECT * from fake");
StepVerifier.create(statement.execute()).expectNextCount(1).verifyComplete();
ArgumentCaptor<Statement> captor = ArgumentCaptor.forClass(Statement.class);
verify(this.mockAdapter).runSelectStatement(captor.capture());
assertEquals("2", captor.getValue().getQueryOptions().getOptimizerVersion());
}
Aggregations