use of com.google.cloud.spanner.ReadContext.QueryAnalyzeMode in project java-spanner by googleapis.
the class AbstractConnectionImplTest method testAnalyzeQuery.
private void testAnalyzeQuery(final StatementType type) {
// TODO: add log statements when ANALYZE ... sql statements are supported
try (Connection connection = getConnection()) {
for (QueryAnalyzeMode mode : QueryAnalyzeMode.values()) {
final QueryAnalyzeMode currentMode = mode;
if (type == StatementType.QUERY && isExecuteAllowed(StatementType.QUERY)) {
ResultSet rs = connection.analyzeQuery(getTestStatement(type), currentMode);
assertThat(rs, is(notNullValue()));
while (rs.next()) {
}
assertThat(rs.getStats(), is(notNullValue()));
} else if (type == StatementType.QUERY) {
// it is a query, but queries are not allowed for this connection state
expectSpannerException(type + " should not be allowed", t -> t.analyzeQuery(getTestStatement(type), currentMode), connection, ErrorCode.FAILED_PRECONDITION);
} else {
expectSpannerException(type + " should be an invalid argument", t -> t.analyzeQuery(getTestStatement(type), currentMode), connection, ErrorCode.INVALID_ARGUMENT);
}
}
}
}
use of com.google.cloud.spanner.ReadContext.QueryAnalyzeMode in project java-spanner by googleapis.
the class ITReadOnlySpannerTest method testAnalyzeQuery.
@Test
public void testAnalyzeQuery() {
assumeFalse("analyze query is not supported on the emulator", isUsingEmulator());
try (ITConnection connection = createConnection()) {
for (QueryAnalyzeMode mode : QueryAnalyzeMode.values()) {
try (ResultSet rs = connection.analyzeQuery(Statement.of("SELECT (SELECT COUNT(*) FROM PRIME_NUMBERS)/(SELECT COUNT(*) FROM NUMBERS) AS PRIME_NUMBER_RATIO"), mode)) {
// next has not yet returned false
assertThat(rs.getStats(), is(nullValue()));
while (rs.next()) {
// ignore
}
assertThat(rs.getStats(), is(notNullValue()));
}
}
}
}
Aggregations