@@ -2690,7 +2690,7 @@ public void testQueryAndNLikeOperators() throws Exception {
26902690 @ Override
26912691 public void check (int n , Result result ) throws Exception {
26922692 assertEquals (1 , result .count ());
2693- if (n == 1 )
2693+ if (n == 1 )
26942694 assertEquals ("doc1" , result .getString (0 ));
26952695 else
26962696 assertEquals ("doc2" , result .getString (0 ));
@@ -2709,7 +2709,7 @@ public void check(int n, Result result) throws Exception {
27092709 @ Override
27102710 public void check (int n , Result result ) throws Exception {
27112711 assertEquals (1 , result .count ());
2712- if (n == 1 )
2712+ if (n == 1 )
27132713 assertEquals ("doc1" , result .getString (0 ));
27142714 else
27152715 assertEquals ("doc4" , result .getString (0 ));
@@ -2733,4 +2733,45 @@ public void check(int n, Result result) throws Exception {
27332733 }, true );
27342734 assertEquals (1 , numRows );
27352735 }
2736+
2737+ // https://forums.couchbase.com/t/how-to-implement-an-index-join-clause-in-couchbase-lite-2-0-using-objective-c-api/16246
2738+ // https://github.com/couchbase/couchbase-lite-core/issues/497
2739+ @ Test
2740+ public void testQueryJoinAndSelectAll () throws Exception {
2741+ loadNumbers (100 );
2742+
2743+ final MutableDocument joinme = new MutableDocument ("joinme" );
2744+ joinme .setValue ("theone" , 42 );
2745+ save (joinme );
2746+
2747+ DataSource mainDS = DataSource .database (this .db ).as ("main" );
2748+ DataSource secondaryDS = DataSource .database (this .db ).as ("secondary" );
2749+
2750+ Expression mainPropExpr = Expression .property ("number1" ).from ("main" );
2751+ Expression secondaryExpr = Expression .property ("theone" ).from ("secondary" );
2752+ Expression joinExpr = mainPropExpr .equalTo (secondaryExpr );
2753+ Join join = Join .leftJoin (secondaryDS ).on (joinExpr );
2754+
2755+ SelectResult sr1 = SelectResult .all ().from ("main" );
2756+ SelectResult sr2 = SelectResult .all ().from ("secondary" );
2757+
2758+ Query q = QueryBuilder .select (sr1 , sr2 ).from (mainDS ).join (join );
2759+ assertNotNull (q );
2760+ int numRows = verifyQuery (q , new QueryResult () {
2761+ @ Override
2762+ public void check (int n , Result result ) throws Exception {
2763+ if (n == 41 ) {
2764+ Log .e (TAG , "41: " + result .toMap ().toString ());
2765+ assertEquals (59 , result .getDictionary ("main" ).getInt ("number2" ));
2766+ assertNull (result .getDictionary ("secondary" ));
2767+ }
2768+ if (n == 42 ) {
2769+ Log .e (TAG , "42: " + result .toMap ().toString ());
2770+ assertEquals (58 , result .getDictionary ("main" ).getInt ("number2" ));
2771+ assertEquals (42 , result .getDictionary ("secondary" ).getInt ("theone" ));
2772+ }
2773+ }
2774+ }, true );
2775+ assertEquals (101 , numRows );
2776+ }
27362777}
0 commit comments