use of com.google.cloud.spanner.Type 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.Type in project google-cloud-java by GoogleCloudPlatform.
the class ITQueryTest method arrayOfStructEmpty.
@Test
public void arrayOfStructEmpty() {
Type structType = Type.struct(StructField.of("", Type.string()), StructField.of("", Type.int64()));
Struct row = execute(Statement.of("SELECT ARRAY(SELECT AS STRUCT * FROM (SELECT 'a', 1) WHERE 0 = 1)"), Type.array(structType));
assertThat(row.isNull(0)).isFalse();
List<Struct> value = row.getStructList(0);
assertThat(value.size()).isEqualTo(0);
}
use of com.google.cloud.spanner.Type 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();
}
use of com.google.cloud.spanner.Type in project google-cloud-java by GoogleCloudPlatform.
the class ITQueryTest method arrayOfStructNull.
// Not yet supported by the backend.
@Ignore
@Test
public void arrayOfStructNull() {
Type structType = Type.struct(StructField.of("", Type.string()), StructField.of("", Type.int64()));
Struct row = execute(Statement.of("SELECT CAST (NULL AS ARRAY<STRUCT<string,int64>>)"), Type.array(structType));
assertThat(row.isNull(0)).isTrue();
}
Aggregations