Search in sources :

Example 6 with ResultSetStats

use of com.google.spanner.v1.ResultSetStats in project google-cloud-java by GoogleCloudPlatform.

the class GrpcResultSetTest method profileResultInExtraFinalResultSet.

@Test
public void profileResultInExtraFinalResultSet() {
    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).build());
    consumer.onPartialResultSet(PartialResultSet.newBuilder().setMetadata(makeMetadata(Type.struct(dataType))).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();
}
Also used : ResultSetStats(com.google.spanner.v1.ResultSetStats) NullValue(com.google.protobuf.NullValue) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 7 with ResultSetStats

use of com.google.spanner.v1.ResultSetStats in project google-cloud-java by GoogleCloudPlatform.

the class GrpcResultSetTest method statsNotSupportedError.

@Test
public void statsNotSupportedError() {
    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.NORMAL);
    consumer.onCompleted();
    expectedException.expect(UnsupportedOperationException.class);
    expectedException.expectMessage("ResultSetStats are available only in PLAN and PROFILE execution modes");
    resultSet.getStats();
}
Also used : ResultSetStats(com.google.spanner.v1.ResultSetStats) Test(org.junit.Test)

Aggregations

ResultSetStats (com.google.spanner.v1.ResultSetStats)7 Test (org.junit.Test)7 IntegrationTest (com.google.cloud.spanner.IntegrationTest)2 ResultSet (com.google.cloud.spanner.ResultSet)2 Statement (com.google.cloud.spanner.Statement)2 ByteString (com.google.protobuf.ByteString)2 NullValue (com.google.protobuf.NullValue)2 ArrayList (java.util.ArrayList)2