1717package com .google .cloud .firestore .it ;
1818
1919import static com .google .cloud .firestore .FieldValue .vector ;
20- import static com .google .cloud .firestore .LocalFirestoreHelper .query ;
2120import static com .google .cloud .firestore .it .ITQueryTest .map ;
2221import static com .google .cloud .firestore .it .TestHelper .isRunningAgainstFirestoreEmulator ;
2322import static com .google .cloud .firestore .pipeline .expressions .AggregateFunction .count ;
5150import static com .google .cloud .firestore .pipeline .expressions .Expression .log ;
5251import static com .google .cloud .firestore .pipeline .expressions .Expression .logicalMaximum ;
5352import static com .google .cloud .firestore .pipeline .expressions .Expression .logicalMinimum ;
54- import static com .google .cloud .firestore .pipeline .expressions .Expression .mapEntries ;
55- import static com .google .cloud .firestore .pipeline .expressions .Expression .mapKeys ;
5653import static com .google .cloud .firestore .pipeline .expressions .Expression .mapMerge ;
5754import static com .google .cloud .firestore .pipeline .expressions .Expression .mapRemove ;
58- import static com .google .cloud .firestore .pipeline .expressions .Expression .mapSet ;
59- import static com .google .cloud .firestore .pipeline .expressions .Expression .mapValues ;
6055import static com .google .cloud .firestore .pipeline .expressions .Expression .notEqual ;
6156import static com .google .cloud .firestore .pipeline .expressions .Expression .nullValue ;
6257import static com .google .cloud .firestore .pipeline .expressions .Expression .or ;
8681import com .google .cloud .Timestamp ;
8782import com .google .cloud .firestore .Blob ;
8883import com .google .cloud .firestore .CollectionReference ;
89- import com .google .cloud .firestore .DocumentReference ;
9084import com .google .cloud .firestore .Firestore ;
9185import com .google .cloud .firestore .FirestoreOptions ;
9286import com .google .cloud .firestore .GeoPoint ;
112106import com .google .common .collect .ImmutableList ;
113107import com .google .common .collect .ImmutableMap ;
114108import com .google .common .collect .Lists ;
115- import java .util .Arrays ;
116109import java .util .Date ;
117110import java .util .HashMap ;
118111import java .util .List ;
@@ -1384,7 +1377,8 @@ public void testMapGet() throws Exception {
13841377 map ("hugoAward" , true , "title" , "The Hitchhiker's Guide to the Galaxy" ),
13851378 map ("hugoAward" , true , "title" , "Dune" )));
13861379 }
1387- @ Test
1380+
1381+ @ Test
13881382 public void testMapSet () throws Exception {
13891383 Map <String , Object > docData = new HashMap <>();
13901384 docData .put ("existingField" , ImmutableMap .of ("foo" , 1L ));
@@ -1400,18 +1394,30 @@ public void testMapSet() throws Exception {
14001394 Expression .mapSet (Expression .map (ImmutableMap .of ()), "a" , 1 ).as ("simple" ),
14011395 Expression .mapSet (Expression .map (ImmutableMap .of ("a" , 1 )), "b" , 2 ).as ("add" ),
14021396 Expression .mapSet (Expression .map (ImmutableMap .of ("a" , 1 )), "a" , 2 ).as ("overwrite" ),
1403- Expression .mapSet (Expression .map (ImmutableMap .of ("a" , 1 , "b" , 2 )), "a" , 3 , "c" , 4 ).as ("multi" ),
1404- Expression .mapSet (Expression .map (ImmutableMap .of ("a" , 1 )), "a" , field ("non_existent" )).as ("remove" ),
1397+ Expression .mapSet (Expression .map (ImmutableMap .of ("a" , 1 , "b" , 2 )), "a" , 3 , "c" , 4 )
1398+ .as ("multi" ),
1399+ Expression .mapSet (
1400+ Expression .map (ImmutableMap .of ("a" , 1 )), "a" , field ("non_existent" ))
1401+ .as ("remove" ),
14051402 Expression .mapSet (Expression .map (ImmutableMap .of ("a" , 1 )), "b" , null ).as ("setNull" ),
1406- Expression .mapSet (Expression .map (ImmutableMap .of ("a" , ImmutableMap .of ("b" , 1 ))), "a.b" , 2 ).as ("setDotted" ),
1403+ Expression .mapSet (
1404+ Expression .map (ImmutableMap .of ("a" , ImmutableMap .of ("b" , 1 ))), "a.b" , 2 )
1405+ .as ("setDotted" ),
14071406 Expression .mapSet (Expression .map (ImmutableMap .of ()), "" , "empty" ).as ("setEmptyKey" ),
1408- Expression .mapSet (Expression .map (ImmutableMap .of ("a" , 1 )), "b" , Expression .add (constant (1 ), constant (2 ))).as ("setExprVal" ),
1409- Expression .mapSet (Expression .map (ImmutableMap .of ()), "obj" , ImmutableMap .of ("hidden" , true )).as ("setNestedMap" ),
1410- Expression .mapSet (Expression .map (ImmutableMap .of ()), "~!@#$%^&*()_+" , "special" ).as ("setSpecialChars" ),
1411-
1407+ Expression .mapSet (
1408+ Expression .map (ImmutableMap .of ("a" , 1 )),
1409+ "b" ,
1410+ Expression .add (constant (1 ), constant (2 )))
1411+ .as ("setExprVal" ),
1412+ Expression .mapSet (
1413+ Expression .map (ImmutableMap .of ()), "obj" , ImmutableMap .of ("hidden" , true ))
1414+ .as ("setNestedMap" ),
1415+ Expression .mapSet (Expression .map (ImmutableMap .of ()), "~!@#$%^&*()_+" , "special" )
1416+ .as ("setSpecialChars" ),
14121417 field ("existingField" ).mapSet ("instanceKey" , 100 ).as ("instanceSetField" ),
1413- Expression .map (ImmutableMap .of ("x" , 1 )).mapSet (constant ("y" ), constant (2 )).as ("instanceSetConstant" )
1414- )
1418+ Expression .map (ImmutableMap .of ("x" , 1 ))
1419+ .mapSet (constant ("y" ), constant (2 ))
1420+ .as ("instanceSetConstant" ))
14151421 .execute ()
14161422 .get ();
14171423
@@ -1426,17 +1432,19 @@ public void testMapSet() throws Exception {
14261432 assertThat ((Map <?, ?>) data .get ("multi" )).containsExactly ("a" , 3L , "b" , 2L , "c" , 4L );
14271433 assertThat ((Map <?, ?>) data .get ("remove" )).isEmpty ();
14281434 assertThat ((Map <?, ?>) data .get ("setNull" )).containsExactly ("a" , 1L , "b" , null );
1429-
1435+
14301436 Map <?, ?> setDotted = (Map <?, ?>) data .get ("setDotted" );
14311437 assertThat (setDotted ).containsEntry ("a.b" , 2L );
14321438 assertThat ((Map <?, ?>) setDotted .get ("a" )).containsExactly ("b" , 1L );
14331439
14341440 assertThat ((Map <?, ?>) data .get ("setEmptyKey" )).containsExactly ("" , "empty" );
14351441 assertThat ((Map <?, ?>) data .get ("setExprVal" )).containsExactly ("a" , 1L , "b" , 3L );
1436- assertThat ((Map <?, ?>) data .get ("setNestedMap" )).isEqualTo (ImmutableMap .of ("obj" , ImmutableMap .of ("hidden" , true )));
1442+ assertThat ((Map <?, ?>) data .get ("setNestedMap" ))
1443+ .isEqualTo (ImmutableMap .of ("obj" , ImmutableMap .of ("hidden" , true )));
14371444 assertThat ((Map <?, ?>) data .get ("setSpecialChars" )).containsExactly ("~!@#$%^&*()_+" , "special" );
14381445
1439- assertThat ((Map <?, ?>) data .get ("instanceSetField" )).containsExactly ("foo" , 1L , "instanceKey" , 100L );
1446+ assertThat ((Map <?, ?>) data .get ("instanceSetField" ))
1447+ .containsExactly ("foo" , 1L , "instanceKey" , 100L );
14401448 assertThat ((Map <?, ?>) data .get ("instanceSetConstant" )).containsExactly ("x" , 1L , "y" , 2L );
14411449 }
14421450
@@ -1455,11 +1463,11 @@ public void testMapKeys() throws Exception {
14551463 Expression .mapKeys ("existingField" ).as ("existingKeys" ),
14561464 Expression .mapKeys (Expression .map (ImmutableMap .of ("a" , 1 , "b" , 2 ))).as ("keys" ),
14571465 Expression .mapKeys (Expression .map (ImmutableMap .of ())).as ("empty_keys" ),
1458- Expression .mapKeys (Expression .map (ImmutableMap .of ("a" , ImmutableMap .of ("nested" , true )))).as ("nested_keys" ),
1459-
1466+ Expression .mapKeys (
1467+ Expression .map (ImmutableMap .of ("a" , ImmutableMap .of ("nested" , true ))))
1468+ .as ("nested_keys" ),
14601469 field ("existingField" ).mapKeys ().as ("instanceExistingKeys" ),
1461- Expression .map (ImmutableMap .of ("x" , 10 , "y" , 20 )).mapKeys ().as ("instanceKeys" )
1462- )
1470+ Expression .map (ImmutableMap .of ("x" , 10 , "y" , 20 )).mapKeys ().as ("instanceKeys" ))
14631471 .execute ()
14641472 .get ();
14651473
@@ -1468,7 +1476,7 @@ public void testMapKeys() throws Exception {
14681476 Map <String , Object > data = resultList .get (0 ).getData ();
14691477
14701478 assertThat ((List <?>) data .get ("existingKeys" )).containsExactly ("foo" );
1471- assertThat ((List <?>) data .get ("keys" )).containsExactly ("a" , "b" );
1479+ assertThat ((List <?>) data .get ("keys" )).containsExactly ("a" , "b" );
14721480 assertThat ((List <?>) data .get ("empty_keys" )).isEmpty ();
14731481 assertThat ((List <?>) data .get ("nested_keys" )).containsExactly ("a" );
14741482
@@ -1491,11 +1499,11 @@ public void testMapValues() throws Exception {
14911499 Expression .mapValues ("existingField" ).as ("existingValues" ),
14921500 Expression .mapValues (Expression .map (ImmutableMap .of ("a" , 1 , "b" , 2 ))).as ("values" ),
14931501 Expression .mapValues (Expression .map (ImmutableMap .of ())).as ("empty_values" ),
1494- Expression .mapValues (Expression .map (ImmutableMap .of ("a" , ImmutableMap .of ("nested" , true )))).as ("nested_values" ),
1495-
1502+ Expression .mapValues (
1503+ Expression .map (ImmutableMap .of ("a" , ImmutableMap .of ("nested" , true ))))
1504+ .as ("nested_values" ),
14961505 field ("existingField" ).mapValues ().as ("instanceExistingValues" ),
1497- Expression .map (ImmutableMap .of ("x" , 10 , "y" , 20 )).mapValues ().as ("instanceValues" )
1498- )
1506+ Expression .map (ImmutableMap .of ("x" , 10 , "y" , 20 )).mapValues ().as ("instanceValues" ))
14991507 .execute ()
15001508 .get ();
15011509
@@ -1506,7 +1514,8 @@ public void testMapValues() throws Exception {
15061514 assertThat ((List <?>) data .get ("existingValues" )).containsExactly (1L );
15071515 assertThat ((List <?>) data .get ("values" )).containsExactly (1L , 2L );
15081516 assertThat ((List <?>) data .get ("empty_values" )).isEmpty ();
1509- assertThat ((List <?>) data .get ("nested_values" )).containsExactly (ImmutableMap .of ("nested" , true ));
1517+ assertThat ((List <?>) data .get ("nested_values" ))
1518+ .containsExactly (ImmutableMap .of ("nested" , true ));
15101519
15111520 assertThat ((List <?>) data .get ("instanceExistingValues" )).containsExactly (1L );
15121521 assertThat ((List <?>) data .get ("instanceValues" )).containsExactly (10L , 20L );
@@ -1525,13 +1534,16 @@ public void testMapEntries() throws Exception {
15251534 .limit (1 )
15261535 .select (
15271536 Expression .mapEntries ("existingField" ).as ("existingEntries" ),
1528- Expression .mapEntries (Expression .map (ImmutableMap .of ("a" , 1 , "b" , 2 ))).as ("entries" ),
1537+ Expression .mapEntries (Expression .map (ImmutableMap .of ("a" , 1 , "b" , 2 )))
1538+ .as ("entries" ),
15291539 Expression .mapEntries (Expression .map (ImmutableMap .of ())).as ("empty_entries" ),
1530- Expression .mapEntries (Expression .map (ImmutableMap .of ("a" , ImmutableMap .of ("nested" , true )))).as ("nested_entries" ),
1531-
1540+ Expression .mapEntries (
1541+ Expression .map (ImmutableMap .of ("a" , ImmutableMap .of ("nested" , true ))))
1542+ .as ("nested_entries" ),
15321543 field ("existingField" ).mapEntries ().as ("instanceExistingEntries" ),
1533- Expression .map (ImmutableMap .of ("x" , 10 , "y" , 20 )).mapEntries ().as ("instanceEntries" )
1534- )
1544+ Expression .map (ImmutableMap .of ("x" , 10 , "y" , 20 ))
1545+ .mapEntries ()
1546+ .as ("instanceEntries" ))
15351547 .execute ()
15361548 .get ();
15371549
@@ -1545,7 +1557,7 @@ public void testMapEntries() throws Exception {
15451557 @ SuppressWarnings ("unchecked" )
15461558 List <Map <String , Object >> entries = (List <Map <String , Object >>) data .get ("entries" );
15471559 assertThat (entries ).hasSize (2 );
1548-
1560+
15491561 // Map entry order is not guaranteed, so we check containment instead of strict ordering
15501562 assertThat (entries ).contains (ImmutableMap .of ("k" , "a" , "v" , 1L ));
15511563 assertThat (entries ).contains (ImmutableMap .of ("k" , "b" , "v" , 2L ));
@@ -1558,11 +1570,13 @@ public void testMapEntries() throws Exception {
15581570 .containsExactly (ImmutableMap .of ("k" , "foo" , "v" , 1L ));
15591571
15601572 @ SuppressWarnings ("unchecked" )
1561- List <Map <String , Object >> instanceEntries = (List <Map <String , Object >>) data .get ("instanceEntries" );
1573+ List <Map <String , Object >> instanceEntries =
1574+ (List <Map <String , Object >>) data .get ("instanceEntries" );
15621575 assertThat (instanceEntries ).hasSize (2 );
15631576 assertThat (instanceEntries ).contains (ImmutableMap .of ("k" , "x" , "v" , 10L ));
15641577 assertThat (instanceEntries ).contains (ImmutableMap .of ("k" , "y" , "v" , 20L ));
15651578 }
1579+
15661580 @ Test
15671581 public void testDataManipulationExpressions () throws Exception {
15681582 List <PipelineResult > results =
@@ -2933,5 +2947,4 @@ public void disallowDuplicateAliasesAcrossStages() {
29332947 });
29342948 assertThat (exception ).hasMessageThat ().contains ("Duplicate alias or field name" );
29352949 }
2936-
29372950}
0 commit comments