Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit a407627

Browse files
committed
Merge branch 'dl/map-expressions' of https://github.com/googleapis/java-firestore into dl/map-expressions
2 parents 4a9ec5b + 9aa27a0 commit a407627

2 files changed

Lines changed: 69 additions & 56 deletions

File tree

google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,9 +1959,9 @@ public static Expression mapRemove(String mapField, String key) {
19591959
* Creates an expression that returns a new map with the specified entries added or updated.
19601960
*
19611961
* <ul>
1962-
* <li>Only performs shallow updates to the map.</li>
1963-
* <li>Setting a value to {@code null} will retain the key with a {@code null} value. To remove a
1964-
* key entirely, use {@code mapRemove}.</li>
1962+
* <li>Only performs shallow updates to the map.
1963+
* <li>Setting a value to {@code null} will retain the key with a {@code null} value. To remove
1964+
* a key entirely, use {@code mapRemove}.
19651965
* </ul>
19661966
*
19671967
* @param mapExpr The expression representing the map.
@@ -1983,11 +1983,11 @@ public static Expression mapSet(
19831983

19841984
/**
19851985
* Creates an expression that returns a new map with the specified entries added or updated.
1986-
*
1986+
*
19871987
* <ul>
1988-
* <li>Only performs shallow updates to the map.</li>
1989-
* <li>Setting a value to {@code null} will retain the key with a {@code null} value. To remove a
1990-
* key entirely, use {@code mapRemove}.</li>
1988+
* <li>Only performs shallow updates to the map.
1989+
* <li>Setting a value to {@code null} will retain the key with a {@code null} value. To remove
1990+
* a key entirely, use {@code mapRemove}.
19911991
* </ul>
19921992
*
19931993
* @param mapField The map field to set entries in.
@@ -2008,11 +2008,11 @@ public static Expression mapSet(
20082008

20092009
/**
20102010
* Creates an expression that returns a new map with the specified entries added or updated.
2011-
*
2011+
*
20122012
* <ul>
2013-
* <li>Only performs shallow updates to the map.</li>
2014-
* <li>Setting a value to {@code null} will retain the key with a {@code null} value. To remove a
2015-
* key entirely, use {@code mapRemove}.</li>
2013+
* <li>Only performs shallow updates to the map.
2014+
* <li>Setting a value to {@code null} will retain the key with a {@code null} value. To remove
2015+
* a key entirely, use {@code mapRemove}.
20162016
* </ul>
20172017
*
20182018
* @param mapField The map field to set entries in.
@@ -2029,11 +2029,11 @@ public static Expression mapSet(
20292029

20302030
/**
20312031
* Creates an expression that returns a new map with the specified entries added or updated.
2032-
*
2032+
*
20332033
* <ul>
2034-
* <li>Only performs shallow updates to the map.</li>
2035-
* <li>Setting a value to {@code null} will retain the key with a {@code null} value. To remove a
2036-
* key entirely, use {@code mapRemove}.</li>
2034+
* <li>Only performs shallow updates to the map.
2035+
* <li>Setting a value to {@code null} will retain the key with a {@code null} value. To remove
2036+
* a key entirely, use {@code mapRemove}.
20372037
* </ul>
20382038
*
20392039
* @param mapField The map field to set entries in.
@@ -2047,7 +2047,7 @@ public static Expression mapSet(
20472047
String mapField, String key, Object value, Object... moreKeyValues) {
20482048
return mapSet(field(mapField), key, value, moreKeyValues);
20492049
}
2050-
2050+
20512051
/**
20522052
* Creates an expression that returns the keys of a map.
20532053
*
@@ -4603,8 +4603,8 @@ public final Expression mapValues() {
46034603
}
46044604

46054605
/**
4606-
* Creates an expression that returns the entries of this map expression as an array of maps, where
4607-
* each map contains a "k" property for the key and a "v" property for the value.
4606+
* Creates an expression that returns the entries of this map expression as an array of maps,
4607+
* where each map contains a "k" property for the key and a "v" property for the value.
46084608
*
46094609
* <p>While the backend generally preserves insertion order, relying on the order of the output
46104610
* array is not guaranteed and should be avoided.

google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.google.cloud.firestore.it;
1818

1919
import static com.google.cloud.firestore.FieldValue.vector;
20-
import static com.google.cloud.firestore.LocalFirestoreHelper.query;
2120
import static com.google.cloud.firestore.it.ITQueryTest.map;
2221
import static com.google.cloud.firestore.it.TestHelper.isRunningAgainstFirestoreEmulator;
2322
import static com.google.cloud.firestore.pipeline.expressions.AggregateFunction.count;
@@ -51,12 +50,8 @@
5150
import static com.google.cloud.firestore.pipeline.expressions.Expression.log;
5251
import static com.google.cloud.firestore.pipeline.expressions.Expression.logicalMaximum;
5352
import 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;
5653
import static com.google.cloud.firestore.pipeline.expressions.Expression.mapMerge;
5754
import 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;
6055
import static com.google.cloud.firestore.pipeline.expressions.Expression.notEqual;
6156
import static com.google.cloud.firestore.pipeline.expressions.Expression.nullValue;
6257
import static com.google.cloud.firestore.pipeline.expressions.Expression.or;
@@ -86,7 +81,6 @@
8681
import com.google.cloud.Timestamp;
8782
import com.google.cloud.firestore.Blob;
8883
import com.google.cloud.firestore.CollectionReference;
89-
import com.google.cloud.firestore.DocumentReference;
9084
import com.google.cloud.firestore.Firestore;
9185
import com.google.cloud.firestore.FirestoreOptions;
9286
import com.google.cloud.firestore.GeoPoint;
@@ -112,7 +106,6 @@
112106
import com.google.common.collect.ImmutableList;
113107
import com.google.common.collect.ImmutableMap;
114108
import com.google.common.collect.Lists;
115-
import java.util.Arrays;
116109
import java.util.Date;
117110
import java.util.HashMap;
118111
import 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

Comments
 (0)