use of com.google.spanner.v1.ResultSetStats in project google-cloud-java by GoogleCloudPlatform.
the class GrpcResultSetTest method statsUnavailableError.
@Test
public void statsUnavailableError() {
ResultSetStats stats = ResultSetStats.newBuilder().build();
consumer.onPartialResultSet(PartialResultSet.newBuilder().setMetadata(makeMetadata(Type.struct(new ArrayList<Type.StructField>()))).setChunkedValue(false).setStats(stats).build());
resultSet = resultSetWithMode(QueryMode.PROFILE);
consumer.onCompleted();
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("ResultSetStats requested before consuming the entire ResultSet");
resultSet.getStats();
}
use of com.google.spanner.v1.ResultSetStats in project google-cloud-java by GoogleCloudPlatform.
the class GrpcResultSetTest method profileResultInFinalResultSet.
@Test
public void profileResultInFinalResultSet() {
Map<String, com.google.protobuf.Value> statsMap = ImmutableMap.of("f1", Value.string("").toProto(), "f2", Value.string("").toProto());
ResultSetStats stats = ResultSetStats.newBuilder().setQueryPlan(QueryPlan.newBuilder().build()).setQueryStats(com.google.protobuf.Struct.newBuilder().putAllFields(statsMap).build()).build();
ArrayList<Type.StructField> dataType = new ArrayList<>();
dataType.add(Type.StructField.of("data", Type.string()));
consumer.onPartialResultSet(PartialResultSet.newBuilder().setMetadata(makeMetadata(Type.struct(dataType))).addValues(Value.string("d1").toProto()).setChunkedValue(false).setStats(stats).build());
resultSet = resultSetWithMode(QueryMode.PROFILE);
consumer.onCompleted();
assertThat(resultSet.next()).isTrue();
assertThat(resultSet.next()).isFalse();
ResultSetStats receivedStats = resultSet.getStats();
assertThat(stats).isEqualTo(receivedStats);
resultSet.close();
}
use of com.google.spanner.v1.ResultSetStats in project google-cloud-java by GoogleCloudPlatform.
the class ITQueryTest method analyzePlan.
@Test
public void analyzePlan() {
Statement statement = Statement.of("SELECT 1 AS column UNION ALL SELECT 2");
ResultSet resultSet = statement.analyzeQuery(client.singleUse(TimestampBound.strong()), QueryAnalyzeMode.PLAN);
assertThat(resultSet.next()).isFalse();
assertThat(resultSet.getType()).isEqualTo(Type.struct(StructField.of("column", Type.int64())));
ResultSetStats receivedStats = resultSet.getStats();
assertThat(receivedStats).isNotNull();
assertThat(receivedStats.hasQueryPlan()).isTrue();
assertThat(receivedStats.hasQueryStats()).isFalse();
}
use of com.google.spanner.v1.ResultSetStats in project google-cloud-java by GoogleCloudPlatform.
the class ITQueryTest method analyzeProfile.
@Test
public void analyzeProfile() {
Statement statement = Statement.of("SELECT 1 AS column UNION ALL SELECT 2 AS column ORDER BY column");
ResultSet resultSet = statement.analyzeQuery(client.singleUse(TimestampBound.strong()), QueryAnalyzeMode.PROFILE);
assertThat(resultSet.next()).isTrue();
assertThat(resultSet.getType()).isEqualTo(Type.struct(StructField.of("column", Type.int64())));
assertThat(resultSet.getLong(0)).isEqualTo(1);
assertThat(resultSet.next()).isTrue();
assertThat(resultSet.getLong(0)).isEqualTo(2);
assertThat(resultSet.next()).isFalse();
ResultSetStats receivedStats = resultSet.getStats();
assertThat(receivedStats).isNotNull();
assertThat(receivedStats.hasQueryPlan()).isTrue();
assertThat(receivedStats.hasQueryStats()).isTrue();
}
use of com.google.spanner.v1.ResultSetStats in project google-cloud-java by GoogleCloudPlatform.
the class GrpcResultSetTest method planResult.
@Test
public void planResult() {
ResultSetStats stats = ResultSetStats.newBuilder().setQueryPlan(QueryPlan.newBuilder().build()).build();
consumer.onPartialResultSet(PartialResultSet.newBuilder().setMetadata(makeMetadata(Type.struct(new ArrayList<Type.StructField>()))).setChunkedValue(false).setStats(stats).build());
resultSet = resultSetWithMode(QueryMode.PLAN);
consumer.onCompleted();
assertThat(resultSet.next()).isFalse();
ResultSetStats receivedStats = resultSet.getStats();
assertThat(stats).isEqualTo(receivedStats);
resultSet.close();
}
Aggregations