Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add a test for selecting an array of structs #1108

Merged
merged 1 commit into from Apr 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -19,6 +19,9 @@
import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator;
import static com.google.common.truth.Truth.assertThat;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;

Expand Down Expand Up @@ -943,6 +946,36 @@ public void analyzeProfile() {
assertThat(receivedStats.hasQueryStats()).isTrue();
}

@Test
public void testSelectArrayOfStructs() {
try (ResultSet resultSet =
client
.singleUse()
.executeQuery(
Statement.of(
"WITH points AS\n"
+ " (SELECT [1, 5] as point\n"
+ " UNION ALL SELECT [2, 8] as point\n"
+ " UNION ALL SELECT [3, 7] as point\n"
+ " UNION ALL SELECT [4, 1] as point\n"
+ " UNION ALL SELECT [5, 7] as point)\n"
+ "SELECT ARRAY(\n"
+ " SELECT STRUCT(point)\n"
+ " FROM points)\n"
+ " AS coordinates"))) {
assertTrue(resultSet.next());
assertEquals(resultSet.getColumnCount(), 1);
assertThat(resultSet.getStructList(0))
.containsExactly(
Struct.newBuilder().set("point").to(Value.int64Array(new long[] {1L, 5L})).build(),
Struct.newBuilder().set("point").to(Value.int64Array(new long[] {2L, 8L})).build(),
Struct.newBuilder().set("point").to(Value.int64Array(new long[] {3L, 7L})).build(),
Struct.newBuilder().set("point").to(Value.int64Array(new long[] {4L, 1L})).build(),
Struct.newBuilder().set("point").to(Value.int64Array(new long[] {5L, 7L})).build());
assertFalse(resultSet.next());
}
}

private List<Struct> resultRows(Statement statement, Type expectedRowType) {
ArrayList<Struct> results = new ArrayList<>();
ResultSet resultSet = statement.executeQuery(client.singleUse(TimestampBound.strong()));
Expand Down