Search in sources :

Example 1 with Date

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

the class ITQueryTest method bindDateArray.

@Test
public void bindDateArray() {
    Date d1 = Date.parseDate("2016-09-18");
    Date d2 = Date.parseDate("2016-09-19");
    Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").toDateArray(Arrays.asList(d1, d2, null)), Type.array(Type.date()));
    assertThat(row.isNull(0)).isFalse();
    assertThat(row.getDateList(0)).containsExactly(d1, d2, null).inOrder();
}
Also used : Date(com.google.cloud.Date) Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 2 with Date

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

the class ITQueryTest method bindDateArrayEmpty.

@Test
public void bindDateArrayEmpty() {
    Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").toDateArray(Arrays.<Date>asList()), Type.array(Type.date()));
    assertThat(row.isNull(0)).isFalse();
    assertThat(row.getDateList(0)).containsExactly();
}
Also used : Date(com.google.cloud.Date) Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 3 with Date

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

the class ITWriteTest method writeDate.

@Test
public void writeDate() {
    Date date = Date.parseDate("2016-09-15");
    write(baseInsert().set("DateValue").to(date).build());
    Struct row = readLastRow("DateValue");
    assertThat(row.isNull(0)).isFalse();
    assertThat(row.getDate(0)).isEqualTo(date);
}
Also used : Date(com.google.cloud.Date) Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 4 with Date

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

the class ITQueryTest method bindDateNull.

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

Example 5 with Date

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

Aggregations

Date (com.google.cloud.Date)10 Test (org.junit.Test)9 IntegrationTest (com.google.cloud.spanner.IntegrationTest)6 Struct (com.google.cloud.spanner.Struct)6 Timestamp (com.google.cloud.Timestamp)3 ByteArray (com.google.cloud.ByteArray)1 Mutation (com.google.cloud.spanner.Mutation)1 EqualsTester (com.google.common.testing.EqualsTester)1 KeyPart (org.apache.beam.sdk.io.gcp.spanner.SpannerSchema.KeyPart)1