Search in sources :

Example 6 with Statement

use of com.google.cloud.spanner.Statement 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 7 with Statement

use of com.google.cloud.spanner.Statement 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)

Aggregations

ResultSet (com.google.cloud.spanner.ResultSet)7 Statement (com.google.cloud.spanner.Statement)7 IntegrationTest (com.google.cloud.spanner.IntegrationTest)4 Test (org.junit.Test)4 Joiner (com.google.common.base.Joiner)2 ResultSetStats (com.google.spanner.v1.ResultSetStats)2 DBException (com.yahoo.ycsb.DBException)2 Database (com.google.cloud.spanner.Database)1 DatabaseClient (com.google.cloud.spanner.DatabaseClient)1 SpannerException (com.google.cloud.spanner.SpannerException)1 TransactionContext (com.google.cloud.spanner.TransactionContext)1 TransactionRunner (com.google.cloud.spanner.TransactionRunner)1 TransactionCallable (com.google.cloud.spanner.TransactionRunner.TransactionCallable)1 ByteIterator (com.yahoo.ycsb.ByteIterator)1 StringByteIterator (com.yahoo.ycsb.StringByteIterator)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 CloudSpannerSQLException (nl.topicus.jdbc.exception.CloudSpannerSQLException)1