7272import static com .google .cloud .firestore .pipeline .expressions .Expression .notEqual ;
7373import static com .google .cloud .firestore .pipeline .expressions .Expression .nullValue ;
7474import static com .google .cloud .firestore .pipeline .expressions .Expression .or ;
75+ import static com .google .cloud .firestore .pipeline .expressions .Expression .parent ;
7576import static com .google .cloud .firestore .pipeline .expressions .Expression .pow ;
7677import static com .google .cloud .firestore .pipeline .expressions .Expression .rand ;
7778import static com .google .cloud .firestore .pipeline .expressions .Expression .regexMatch ;
109110import com .google .cloud .Timestamp ;
110111import com .google .cloud .firestore .Blob ;
111112import com .google .cloud .firestore .CollectionReference ;
113+ import com .google .cloud .firestore .DocumentReference ;
112114import com .google .cloud .firestore .Firestore ;
113115import com .google .cloud .firestore .FirestoreOptions ;
114116import com .google .cloud .firestore .GeoPoint ;
@@ -2295,7 +2297,7 @@ public void testChecks() throws Exception {
22952297 .select (
22962298 field ("rating" ).equal (nullValue ()).as ("ratingIsNull" ),
22972299 field ("rating" ).equal (Double .NaN ).as ("ratingIsNaN" ),
2298- // arrayGet("title", 0) evaluates to UNSET so it is not an error
2300+ // arrayGet("title", 0) evaluates to ERROR
22992301 arrayGet ("title" , 0 ).isError ().as ("isError" ),
23002302 arrayGet ("title" , 0 ).ifError (constant ("was error" )).as ("ifError" ),
23012303 field ("foo" ).isAbsent ().as ("isAbsent" ),
@@ -2316,7 +2318,9 @@ public void testChecks() throws Exception {
23162318 "ratingIsNaN" ,
23172319 false ,
23182320 "isError" ,
2319- false ,
2321+ true ,
2322+ "ifError" ,
2323+ "was error" ,
23202324 "isAbsent" ,
23212325 true ,
23222326 "titleIsNotNull" ,
@@ -3621,8 +3625,8 @@ public void testNestedFields() throws Exception {
36213625 assertThat (data (results ))
36223626 .isEqualTo (
36233627 Lists .newArrayList (
3624- map ("title" , "The Hitchhiker's Guide to the Galaxy" , "awards. hugo" , true ),
3625- map ("title" , "Dune" , "awards. hugo" , true )));
3628+ map ("title" , "The Hitchhiker's Guide to the Galaxy" , "awards" , map ( " hugo" , true ) ),
3629+ map ("title" , "Dune" , "awards" , map ( " hugo" , true ) )));
36263630 }
36273631
36283632 @ Test
@@ -3645,8 +3649,12 @@ public void testPipelineInTransactions() throws Exception {
36453649 assertThat (data (results ))
36463650 .isEqualTo (
36473651 Lists .newArrayList (
3648- map ("title" , "The Hitchhiker's Guide to the Galaxy" , "awards.hugo" , true ),
3649- map ("title" , "Dune" , "awards.hugo" , true )));
3652+ map (
3653+ "title" ,
3654+ "The Hitchhiker's Guide to the Galaxy" ,
3655+ "awards" ,
3656+ map ("hugo" , true )),
3657+ map ("title" , "Dune" , "awards" , map ("hugo" , true ))));
36503658
36513659 transaction .update (collection .document ("book1" ), map ("foo" , "bar" ));
36523660
@@ -4378,4 +4386,29 @@ public void disallowDuplicateAliasesAcrossStages() {
43784386 });
43794387 assertThat (exception ).hasMessageThat ().contains ("Duplicate alias or field name" );
43804388 }
4389+
4390+ @ Test
4391+ public void testSupportsParent () throws Exception {
4392+ DocumentReference docRef =
4393+ collection .document ("book4" ).collection ("reviews" ).document ("review1" );
4394+
4395+ Pipeline pipeline =
4396+ firestore
4397+ .pipeline ()
4398+ .collection (collection .getPath ())
4399+ .limit (1 )
4400+ .select (
4401+ parent (docRef ).as ("parentRefStatic" ),
4402+ constant (docRef ).parent ().as ("parentRefInstance" ))
4403+ .select (
4404+ field ("parentRefStatic" ).documentId ().as ("parentIdStatic" ),
4405+ field ("parentRefInstance" ).documentId ().as ("parentIdInstance" ));
4406+
4407+ List <PipelineResult > results = pipeline .execute ().get ().getResults ();
4408+ assertThat (results ).hasSize (1 );
4409+ Map <String , Object > data = results .get (0 ).getData ();
4410+
4411+ assertThat (data .get ("parentIdStatic" )).isEqualTo ("book4" );
4412+ assertThat (data .get ("parentIdInstance" )).isEqualTo ("book4" );
4413+ }
43814414}
0 commit comments