Search in sources :

Example 1 with ResultSetStats

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();
}
Also used : ResultSetStats(com.google.spanner.v1.ResultSetStats) Test(org.junit.Test)

Example 2 with ResultSetStats

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();
}
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 3 with ResultSetStats

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();
}
Also used : ResultSetStats(com.google.spanner.v1.ResultSetStats) Statement(com.google.cloud.spanner.Statement) ResultSet(com.google.cloud.spanner.ResultSet) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 4 with ResultSetStats

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();
}
Also used : ResultSetStats(com.google.spanner.v1.ResultSetStats) Statement(com.google.cloud.spanner.Statement) ResultSet(com.google.cloud.spanner.ResultSet) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 5 with ResultSetStats

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();
}
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