Search in sources :

Example 81 with Struct

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

the class ITQueryTest method bindBytes.

@Test
public void bindBytes() {
    Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").to(ByteArray.copyFrom("xyz")), Type.bytes());
    assertThat(row.isNull(0)).isFalse();
    assertThat(row.getBytes(0)).isEqualTo(ByteArray.copyFrom("xyz"));
}
Also used : Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 82 with Struct

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

the class ITQueryTest method bindInt64Null.

@Test
public void bindInt64Null() {
    Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").to((Long) null), Type.int64());
    assertThat(row.isNull(0)).isTrue();
}
Also used : Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 83 with Struct

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

the class ITQueryTest method bindDate.

@Test
public void bindDate() {
    Date d = Date.parseDate("2016-09-18");
    Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").to(d), Type.date());
    assertThat(row.isNull(0)).isFalse();
    assertThat(row.getDate(0)).isEqualTo(d);
}
Also used : Date(com.google.cloud.Date) Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 84 with Struct

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

the class ITQueryTest method arrayOfStructNullElement.

// Not yet supported by the backend.
@Ignore
@Test
public void arrayOfStructNullElement() {
    Type structType = Type.struct(StructField.of("", Type.string()), StructField.of("", Type.int64()));
    Struct row = execute(Statement.of("SELECT ARRAY(SELECT AS STRUCT 'a', 1" + " UNION ALL SELECT CAST (NULL AS STRUCT<string,int64>))"), Type.array(structType));
    assertThat(row.isNull(0)).isFalse();
    List<Struct> value = row.getStructList(0);
    assertThat(value.size()).isEqualTo(2);
    assertThat(value.get(0).getType()).isEqualTo(structType);
    assertThat(value.get(0).getString(0)).isEqualTo("a");
    assertThat(value.get(0).getLong(1)).isEqualTo(1);
    assertThat(value.get(1)).isNull();
}
Also used : Type(com.google.cloud.spanner.Type) Struct(com.google.cloud.spanner.Struct) Ignore(org.junit.Ignore) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 85 with Struct

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

the class ITQueryTest method bindDateArrayNull.

@Test
public void bindDateArrayNull() {
    Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").toDateArray(null), Type.array(Type.date()));
    assertThat(row.isNull(0)).isTrue();
}
Also used : 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