Search in sources :

Example 36 with Struct

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

the class ITReadTest method indexPointRead.

@Test
public void indexPointRead() {
    Struct row = client.singleUse(TimestampBound.strong()).readRowUsingIndex(TABLE_NAME, INDEX_NAME, Key.of("v1"), ALL_COLUMNS);
    assertThat(row).isNotNull();
    assertThat(row.getString(0)).isEqualTo("k1");
    assertThat(row.getString(1)).isEqualTo("v1");
}
Also used : Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 37 with Struct

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

the class ITReadTest method rowsAreSnapshots.

@Test
public void rowsAreSnapshots() {
    List<Struct> rows = new ArrayList<>();
    ResultSet resultSet = client.singleUse(TimestampBound.strong()).read(TABLE_NAME, KeySet.newBuilder().addKey(Key.of("k2")).addKey(Key.of("k3")).addKey(Key.of("k4")).build(), ALL_COLUMNS);
    while (resultSet.next()) {
        rows.add(resultSet.getCurrentRowAsStruct());
    }
    assertThat(rows.size()).isEqualTo(3);
    assertThat(rows.get(0).getString(0)).isEqualTo("k2");
    assertThat(rows.get(0).getString(1)).isEqualTo("v2");
    assertThat(rows.get(1).getString(0)).isEqualTo("k3");
    assertThat(rows.get(1).getString(1)).isEqualTo("v3");
    assertThat(rows.get(2).getString(0)).isEqualTo("k4");
    assertThat(rows.get(2).getString(1)).isEqualTo("v4");
}
Also used : ArrayList(java.util.ArrayList) ResultSet(com.google.cloud.spanner.ResultSet) Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 38 with Struct

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

the class ITReadTest method pointReadNotFound.

@Test
public void pointReadNotFound() {
    Struct row = client.singleUse(TimestampBound.strong()).readRow(TABLE_NAME, Key.of("k999"), ALL_COLUMNS);
    assertThat(row).isNull();
}
Also used : Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 39 with Struct

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

the class ITQueryTest method bindBoolArrayNull.

@Test
public void bindBoolArrayNull() {
    Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").toBoolArray((boolean[]) null), Type.array(Type.bool()));
    assertThat(row.isNull(0)).isTrue();
}
Also used : Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 40 with Struct

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

the class ITQueryTest method bindTimestamp.

@Test
public void bindTimestamp() {
    Timestamp t = Timestamp.parseTimestamp("2016-09-18T00:00:00Z");
    Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").to(t), Type.timestamp());
    assertThat(row.isNull(0)).isFalse();
    assertThat(row.getTimestamp(0)).isEqualTo(t);
}
Also used : Timestamp(com.google.cloud.Timestamp) Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Aggregations

Struct (com.google.cloud.spanner.Struct)106 IntegrationTest (com.google.cloud.spanner.IntegrationTest)101 Test (org.junit.Test)101 Timestamp (com.google.cloud.Timestamp)9 ReadOnlyTransaction (com.google.cloud.spanner.ReadOnlyTransaction)9 Date (com.google.cloud.Date)6 ByteArray (com.google.cloud.ByteArray)5 TimestampBound (com.google.cloud.spanner.TimestampBound)5 TransactionContext (com.google.cloud.spanner.TransactionContext)4 Type (com.google.cloud.spanner.Type)4 SpannerException (com.google.cloud.spanner.SpannerException)3 SpannerExceptionFactory.newSpannerException (com.google.cloud.spanner.SpannerExceptionFactory.newSpannerException)3 TransactionCallable (com.google.cloud.spanner.TransactionRunner.TransactionCallable)3 AbortedException (com.google.cloud.spanner.AbortedException)2 ResultSet (com.google.cloud.spanner.ResultSet)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Ignore (org.junit.Ignore)2 TransactionRunner (com.google.cloud.spanner.TransactionRunner)1