use of com.google.cloud.spanner.Struct in project google-cloud-java by GoogleCloudPlatform.
the class ITQueryTest method simple.
@Test
public void simple() {
Struct row = execute(Statement.of("SELECT 1"), Type.int64());
assertThat(row.getLong(0)).isEqualTo(1);
}
use of com.google.cloud.spanner.Struct in project google-cloud-java by GoogleCloudPlatform.
the class ITQueryTest method bindBytesArrayNull.
@Test
public void bindBytesArrayNull() {
Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").toBytesArray(null), Type.array(Type.bytes()));
assertThat(row.isNull(0)).isTrue();
}
use of com.google.cloud.spanner.Struct in project google-cloud-java by GoogleCloudPlatform.
the class ITQueryTest method arrayOfStruct.
@Test
public void arrayOfStruct() {
Type structType = Type.struct(StructField.of("C1", Type.string()), StructField.of("C2", Type.int64()));
Struct row = execute(Statement.of("SELECT ARRAY(SELECT AS STRUCT C1, C2 " + "FROM (SELECT 'a' AS C1, 1 AS C2 UNION ALL SELECT 'b' AS C1, 2 AS C2) " + "ORDER BY C1 ASC)"), 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).getType()).isEqualTo(structType);
assertThat(value.get(1).getString(0)).isEqualTo("b");
assertThat(value.get(1).getLong(1)).isEqualTo(2);
// Also confirm that an STRUCT<ARRAY<STRUCT>> implements equality correctly with respect to
// a manually constructed Struct.
Struct expectedRow = Struct.newBuilder().add("", Arrays.asList(StructField.of("C1", Type.string()), StructField.of("C2", Type.int64())), Arrays.asList(Struct.newBuilder().set("C1").to("a").set("C2").to(1).build(), Struct.newBuilder().set("C1").to("b").set("C2").to(2).build())).build();
assertThat(row).isEqualTo(expectedRow);
}
use of com.google.cloud.spanner.Struct in project google-cloud-java by GoogleCloudPlatform.
the class ITQueryTest method bindInt64Array.
@Test
public void bindInt64Array() {
Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").toInt64Array(Arrays.asList(null, 1L, 2L)), Type.array(Type.int64()));
assertThat(row.isNull(0)).isFalse();
assertThat(row.getLongList(0)).containsExactly(null, 1L, 2L).inOrder();
}
use of com.google.cloud.spanner.Struct in project google-cloud-java by GoogleCloudPlatform.
the class ITReadTest method indexPointReadNotFound.
@Test
public void indexPointReadNotFound() {
Struct row = client.singleUse(TimestampBound.strong()).readRowUsingIndex(TABLE_NAME, INDEX_NAME, Key.of("v999"), ALL_COLUMNS);
assertThat(row).isNull();
}
Aggregations