From 08be9349c8a112c4dd08ffc039aa896e6ab97695 Mon Sep 17 00:00:00 2001 From: Stanislav Varganov Date: Tue, 8 Sep 2026 16:53:48 +0300 Subject: [PATCH] test for joins with subqueries --- .../reindexer/connector/NestedJoinTest.java | 65 ++++++++++++++++++- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/src/test/java/ru/rt/restream/reindexer/connector/NestedJoinTest.java b/src/test/java/ru/rt/restream/reindexer/connector/NestedJoinTest.java index 5f75298..a4fb8db 100644 --- a/src/test/java/ru/rt/restream/reindexer/connector/NestedJoinTest.java +++ b/src/test/java/ru/rt/restream/reindexer/connector/NestedJoinTest.java @@ -68,6 +68,60 @@ public void testNestedInnerJoin() { assertThat(booksById.containsKey(1004), is(false)); } + @Test + public void testInnerJoinWithSubQueryInJoin() { + openNamespaces(); + insertFixture(); + + Query moscowLocationIds = db.query(LOCATIONS_NS, Location.class) + .select("id") + .where("city", EQ, "Moscow"); + + Query authors = db.query(AUTHORS_NS, Author.class) + .where("locationId", SET, moscowLocationIds) + .on("authorId", EQ, "id"); + + Map booksById = byId(db.query(BOOKS_NS, Book.class) + .innerJoin(authors, "authors") + .toList()); + + assertThat(booksById.size(), is(2)); + assertBookAuthor(booksById.get(1000), 100, "Author1"); + assertBookAuthor(booksById.get(1002), 100, "Author1"); + assertThat(booksById.containsKey(1001), is(false)); + assertThat(booksById.containsKey(1003), is(false)); + assertThat(booksById.containsKey(1004), is(false)); + } + + @Test + public void testNestedInnerJoinWithSubQueryInNestedJoin() { + openNamespaces(); + insertFixture(); + + Query northernCountryIds = db.query(COUNTRIES_NS, Country.class) + .select("id") + .where("name", EQ, "Northern"); + + Query locations = db.query(LOCATIONS_NS, Location.class) + .where("countryId", SET, northernCountryIds) + .on("locationId", EQ, "id"); + + Query authors = db.query(AUTHORS_NS, Author.class) + .innerJoin(locations, "locations") + .on("authorId", EQ, "id"); + + Map booksById = byId(db.query(BOOKS_NS, Book.class) + .innerJoin(authors, "authors") + .toList()); + + assertThat(booksById.size(), is(2)); + assertAuthorLocation(booksById.get(1000), 100, "Author1", "Moscow"); + assertAuthorLocation(booksById.get(1002), 100, "Author1", "Moscow"); + assertThat(booksById.containsKey(1001), is(false)); + assertThat(booksById.containsKey(1003), is(false)); + assertThat(booksById.containsKey(1004), is(false)); + } + @Test public void testLeftJoinWithNestedInnerJoin() { openNamespaces(); @@ -244,14 +298,19 @@ private void insertFixture() { private static void assertAuthorLocation(Book book, int expectedAuthorId, String expectedAuthorName, String expectedCity) { + assertBookAuthor(book, expectedAuthorId, expectedAuthorName); + Author author = book.authors.get(0); + assertThat(author.locations.size(), is(1)); + assertThat(author.locations.get(0).id, is(author.locationId)); + assertThat(author.locations.get(0).city, is(expectedCity)); + } + + private static void assertBookAuthor(Book book, int expectedAuthorId, String expectedAuthorName) { assertThat(book.authors.size(), is(1)); Author author = book.authors.get(0); assertThat(author.id, is(expectedAuthorId)); assertThat(author.id, is(book.authorId)); assertThat(author.name, is(expectedAuthorName)); - assertThat(author.locations.size(), is(1)); - assertThat(author.locations.get(0).id, is(author.locationId)); - assertThat(author.locations.get(0).city, is(expectedCity)); } private static Map byId(List books) {