Skip to content

Commit f3934d8

Browse files
committed
Minor fixes
1 parent 508eb7a commit f3934d8

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import com.google.common.base.Preconditions;
5353
import com.google.common.collect.ImmutableList;
5454
import com.google.common.collect.ImmutableMap;
55-
import com.google.common.collect.Lists;
5655
import com.google.firestore.bundle.BundledQuery;
5756
import com.google.firestore.v1.Cursor;
5857
import com.google.firestore.v1.Document;
@@ -2140,9 +2139,6 @@ public Pipeline pipeline() {
21402139
ppl = ppl.where(toPipelineFilterCondition(f));
21412140
}
21422141

2143-
// Collecting implicit exists fields.
2144-
Set<Exists> exists = new HashSet<>();
2145-
21462142
// Projections
21472143
if (this.options.getFieldProjections() != null
21482144
&& !this.options.getFieldProjections().isEmpty()) {
@@ -2151,15 +2147,25 @@ public Pipeline pipeline() {
21512147
this.options.getFieldProjections().stream()
21522148
.map(fieldReference -> Field.of(fieldReference.getFieldPath()))
21532149
.toArray(Selectable[]::new));
2154-
exists.addAll(
2155-
this.options.getFieldProjections().stream()
2156-
.map(fieldReference -> Field.of(fieldReference.getFieldPath()).exists())
2157-
.collect(Collectors.toList()));
21582150
}
21592151

21602152
// Orders
21612153
List<FieldOrder> normalizedOrderbys = this.createImplicitOrderBy();
21622154
if (normalizedOrderbys != null && !normalizedOrderbys.isEmpty()) {
2155+
// Add exists filters to match Query's implicit orderby semantics.
2156+
List<Exists> exists =
2157+
normalizedOrderbys.stream()
2158+
// .filter(order -> !order.fieldReference.getFieldPath().equals("__name__"))
2159+
.map(order -> Field.of(order.fieldReference.getFieldPath()).exists())
2160+
.collect(Collectors.toList());
2161+
if (exists.size() > 1) {
2162+
ppl =
2163+
ppl.where(
2164+
and(exists.get(0), exists.subList(1, exists.size()).toArray(new Exists[] {})));
2165+
} else if (exists.size() == 1) {
2166+
ppl = ppl.where(exists.get(0));
2167+
}
2168+
21632169
List<Ordering> orders =
21642170
normalizedOrderbys.stream()
21652171
.map(
@@ -2170,24 +2176,6 @@ public Pipeline pipeline() {
21702176
? Ordering.Direction.ASCENDING
21712177
: Ordering.Direction.DESCENDING))
21722178
.collect(Collectors.toList());
2173-
2174-
// Add exists filters to match Query's implicit orderby semantics.
2175-
exists.addAll(
2176-
normalizedOrderbys.stream()
2177-
// .filter(order -> !order.fieldReference.getFieldPath().equals("__name__"))
2178-
.map(order -> Field.of(order.fieldReference.getFieldPath()).exists())
2179-
.collect(Collectors.toList()));
2180-
List<Exists> existsList = Lists.newArrayList(exists);
2181-
if (existsList.size() > 1) {
2182-
ppl =
2183-
ppl.where(
2184-
and(
2185-
existsList.get(0),
2186-
existsList.subList(1, existsList.size()).toArray(new Exists[] {})));
2187-
} else if (exists.size() == 1) {
2188-
ppl = ppl.where(existsList.get(0));
2189-
}
2190-
21912179
ppl = ppl.sort(orders, Density.REQUIRED, Truncation.UNSPECIFIED);
21922180
}
21932181

google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public static com.google.firestore.v1.Pipeline.Stage toStageProto(Stage stage) {
8383
Aggregate aggregateStage = (Aggregate) stage;
8484
return com.google.firestore.v1.Pipeline.Stage.newBuilder()
8585
.setName(aggregateStage.getName())
86-
.addArgs(encodeValue(aggregateStage.getGroups()))
8786
.addArgs(encodeValue(aggregateStage.getAccumulators()))
87+
.addArgs(encodeValue(aggregateStage.getGroups()))
8888
.build();
8989
} else if (stage instanceof Distinct) {
9090
Distinct distinctStage = (Distinct) stage;

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,12 @@ public void testArrayContainsAny() throws Exception {
449449
@Test
450450
public void testArrayContainsAll() throws Exception {
451451
List<PipelineResult> results =
452-
collection.pipeline().where(arrayContainsAll("tags", "adventure", "magic")).execute().get();
452+
collection
453+
.pipeline()
454+
.where(arrayContainsAll("tags", "adventure", "magic"))
455+
.select("title")
456+
.execute()
457+
.get();
453458

454459
assertThat(data(results)).isEqualTo(Lists.newArrayList(map("title", "The Lord of the Rings")));
455460
}
@@ -492,15 +497,14 @@ public void testArrayFilter() throws Exception {
492497
collection
493498
.pipeline()
494499
.select(
495-
arrayFilter(Field.of("tags"), Function.eq(arrayElement(), "")).as("filteredTags"))
500+
arrayFilter(Field.of("tags"), Function.eq(arrayElement(), "comedy"))
501+
.as("filteredTags"))
496502
.limit(1)
497503
.execute()
498504
.get();
499505

500506
assertThat(data(results))
501-
.isEqualTo(
502-
Lists.newArrayList(
503-
map("filteredTags", Lists.newArrayList("comedy", "space", "adventure"))));
507+
.isEqualTo(Lists.newArrayList(map("filteredTags", Lists.newArrayList("comedy"))));
504508
}
505509

506510
@Test
@@ -832,6 +836,14 @@ public void testDistanceFunctions() throws Exception {
832836
.limit(1)
833837
.execute()
834838
.get();
839+
840+
assertThat(data(results))
841+
.isEqualTo(
842+
Lists.newArrayList(
843+
map(
844+
"cosineDistance", 0.02560880430538015,
845+
"dotProductDistance", 0.13,
846+
"euclideanDistance", 0.806225774829855)));
835847
}
836848

837849
@Test

0 commit comments

Comments
 (0)