Skip to content

Commit 45280be

Browse files
committed
Fixes, addition, whitespace.
1 parent 9f9f95a commit 45280be

File tree

10 files changed

+236
-168
lines changed

10 files changed

+236
-168
lines changed

firebase-firestore/api.txt

Lines changed: 40 additions & 26 deletions
Large diffs are not rendered by default.

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/PipelineTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import com.google.firebase.firestore.pipeline.AggregateFunction;
4848
import com.google.firebase.firestore.pipeline.AggregateStage;
4949
import com.google.firebase.firestore.pipeline.Expr;
50-
import com.google.firebase.firestore.pipeline.Stage;
50+
import com.google.firebase.firestore.pipeline.RawStage;
5151
import com.google.firebase.firestore.testutil.IntegrationTestUtil;
5252
import java.util.Collections;
5353
import java.util.LinkedHashMap;
@@ -279,15 +279,14 @@ public void groupAndAccumulateResultsGeneric() {
279279
firestore
280280
.pipeline()
281281
.collection(randomCol)
282-
.addStage(Stage.ofName("where").withArguments(lt(field("published"), 1984)))
283-
.addStage(
284-
Stage.ofName("aggregate")
282+
.rawStage(RawStage.ofName("where").withArguments(lt(field("published"), 1984)))
283+
.rawStage(
284+
RawStage.ofName("aggregate")
285285
.withArguments(
286286
ImmutableMap.of("avgRating", AggregateFunction.avg("rating")),
287287
ImmutableMap.of("genre", field("genre"))))
288-
.addStage(Stage.ofName("where").withArguments(gt("avgRating", 4.3)))
289-
.addStage(
290-
Stage.ofName("sort").withArguments(field("avgRating").descending()))
288+
.rawStage(RawStage.ofName("where").withArguments(gt("avgRating", 4.3)))
289+
.rawStage(RawStage.ofName("sort").withArguments(field("avgRating").descending()))
291290
.execute();
292291
assertThat(waitFor(execute).getResults())
293292
.comparingElementsUsing(DATA_CORRESPONDENCE)

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/QueryToPipelineTest.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -613,40 +613,39 @@ public void testQueriesCanUseArrayContainsAnyFilters() {
613613
FirebaseFirestore db = collection.firestore;
614614

615615
// Search for "array" to contain [42, 43].
616-
Pipeline pipeline = db.pipeline()
617-
.convertFrom(collection.whereArrayContainsAny("array", asList(42L, 43L)));
616+
Pipeline pipeline =
617+
db.pipeline().convertFrom(collection.whereArrayContainsAny("array", asList(42L, 43L)));
618618
PipelineSnapshot snapshot = waitFor(pipeline.execute());
619619
assertEquals(asList(docA, docB, docD, docE), pipelineSnapshotToValues(snapshot));
620620

621621
// With objects.
622-
pipeline = db.pipeline()
623-
.convertFrom(collection.whereArrayContainsAny("array", asList(map("a", 42L))));
622+
pipeline =
623+
db.pipeline().convertFrom(collection.whereArrayContainsAny("array", asList(map("a", 42L))));
624624
snapshot = waitFor(pipeline.execute());
625625
assertEquals(asList(docF), pipelineSnapshotToValues(snapshot));
626626

627627
// With null.
628-
pipeline = db.pipeline()
629-
.convertFrom(collection.whereArrayContainsAny("array", nullList()));
628+
pipeline = db.pipeline().convertFrom(collection.whereArrayContainsAny("array", nullList()));
630629
snapshot = waitFor(pipeline.execute());
631630
assertEquals(new ArrayList<>(), pipelineSnapshotToValues(snapshot));
632631

633632
// With null and a value.
634633
List<Object> inputList = nullList();
635634
inputList.add(43L);
636-
pipeline = db.pipeline()
637-
.convertFrom(collection.whereArrayContainsAny("array", inputList));
635+
pipeline = db.pipeline().convertFrom(collection.whereArrayContainsAny("array", inputList));
638636
snapshot = waitFor(pipeline.execute());
639637
assertEquals(asList(docE), pipelineSnapshotToValues(snapshot));
640638

641639
// With NaN.
642-
pipeline = db.pipeline()
643-
.convertFrom(collection.whereArrayContainsAny("array", asList(Double.NaN)));
640+
pipeline =
641+
db.pipeline().convertFrom(collection.whereArrayContainsAny("array", asList(Double.NaN)));
644642
snapshot = waitFor(pipeline.execute());
645643
assertEquals(new ArrayList<>(), pipelineSnapshotToValues(snapshot));
646644

647645
// With NaN and a value.
648-
pipeline = db.pipeline()
649-
.convertFrom(collection.whereArrayContainsAny("array", asList(Double.NaN, 43L)));
646+
pipeline =
647+
db.pipeline()
648+
.convertFrom(collection.whereArrayContainsAny("array", asList(Double.NaN, 43L)));
650649
snapshot = waitFor(pipeline.execute());
651650
assertEquals(asList(docE), pipelineSnapshotToValues(snapshot));
652651
}

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/testutil/IntegrationTestUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ public static void checkQueryAndPipelineResultsMatch(Query query, String... expe
575575
}
576576
PipelineSnapshot docsFromPipeline;
577577
try {
578-
docsFromPipeline = waitFor(query.getFirestore().pipeline().convertFrom(query).execute());
578+
docsFromPipeline = waitFor(query.getFirestore().pipeline().convertFrom(query).execute());
579579
} catch (Exception e) {
580580
throw new RuntimeException("Pipeline FAILED", e);
581581
}

firebase-firestore/src/main/java/com/google/firebase/firestore/Pipeline.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ import com.google.firebase.firestore.pipeline.ExprWithAlias
3636
import com.google.firebase.firestore.pipeline.Field
3737
import com.google.firebase.firestore.pipeline.FindNearestStage
3838
import com.google.firebase.firestore.pipeline.FunctionExpr
39-
import com.google.firebase.firestore.pipeline.Stage
4039
import com.google.firebase.firestore.pipeline.LimitStage
4140
import com.google.firebase.firestore.pipeline.OffsetStage
4241
import com.google.firebase.firestore.pipeline.Ordering
4342
import com.google.firebase.firestore.pipeline.PipelineOptions
43+
import com.google.firebase.firestore.pipeline.RawStage
4444
import com.google.firebase.firestore.pipeline.RemoveFieldsStage
4545
import com.google.firebase.firestore.pipeline.ReplaceStage
4646
import com.google.firebase.firestore.pipeline.SampleStage
4747
import com.google.firebase.firestore.pipeline.SelectStage
4848
import com.google.firebase.firestore.pipeline.Selectable
4949
import com.google.firebase.firestore.pipeline.SortStage
50-
import com.google.firebase.firestore.pipeline.BaseStage
50+
import com.google.firebase.firestore.pipeline.Stage
5151
import com.google.firebase.firestore.pipeline.UnionStage
5252
import com.google.firebase.firestore.pipeline.UnnestStage
5353
import com.google.firebase.firestore.pipeline.WhereStage
@@ -59,15 +59,15 @@ class Pipeline
5959
internal constructor(
6060
internal val firestore: FirebaseFirestore,
6161
internal val userDataReader: UserDataReader,
62-
private val stages: FluentIterable<BaseStage<*>>
62+
private val stages: FluentIterable<Stage<*>>
6363
) {
6464
internal constructor(
6565
firestore: FirebaseFirestore,
6666
userDataReader: UserDataReader,
67-
stage: BaseStage<*>
67+
stage: Stage<*>
6868
) : this(firestore, userDataReader, FluentIterable.of(stage))
6969

70-
private fun append(stage: BaseStage<*>): Pipeline {
70+
private fun append(stage: Stage<*>): Pipeline {
7171
return Pipeline(firestore, userDataReader, stages.append(stage))
7272
}
7373

@@ -103,17 +103,17 @@ internal constructor(
103103
.build()
104104

105105
/**
106-
* Adds a stage to the pipeline by specifying the stage name as an argument. This does not offer
107-
* any type safety on the stage params and requires the caller to know the order (and optionally
108-
* names) of parameters accepted by the stage.
106+
* Adds a raw stage to the pipeline by specifying the stage name as an argument. This does not
107+
* offer any type safety on the stage params and requires the caller to know the order (and
108+
* optionally names) of parameters accepted by the stage.
109109
*
110110
* This method provides a way to call stages that are supported by the Firestore backend but that
111111
* are not implemented in the SDK version being used.
112112
*
113-
* @param stage An [Stage] object that specifies stage name and parameters.
113+
* @param rawStage An [RawStage] object that specifies stage name and parameters.
114114
* @return A new [Pipeline] object with this stage appended to the stage list.
115115
*/
116-
fun addStage(stage: Stage): Pipeline = append(stage)
116+
fun rawStage(rawStage: RawStage): Pipeline = append(rawStage)
117117

118118
/**
119119
* Adds new fields to outputs from previous stages.

firebase-firestore/src/main/java/com/google/firebase/firestore/core/FieldFilter.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static com.google.firebase.firestore.util.Assert.hardAssert;
2121

2222
import androidx.annotation.NonNull;
23-
2423
import com.google.firebase.firestore.model.Document;
2524
import com.google.firebase.firestore.model.FieldPath;
2625
import com.google.firebase.firestore.model.Values;
@@ -29,7 +28,6 @@
2928
import com.google.firebase.firestore.pipeline.Field;
3029
import com.google.firebase.firestore.util.Assert;
3130
import com.google.firestore.v1.Value;
32-
3331
import java.util.ArrayList;
3432
import java.util.Arrays;
3533
import java.util.Collections;
@@ -219,14 +217,16 @@ BooleanExpr toPipelineExpr() {
219217
return and(exists, x.arrayContainsAny(value.getArrayValue().getValuesList()));
220218
case IN:
221219
return and(exists, x.eqAny(value.getArrayValue().getValuesList()));
222-
case NOT_IN: {
223-
List<Value> list = value.getArrayValue().getValuesList();
224-
if (hasNaN(list)) {
225-
return and(exists, x.notEqAny(filterNaN(list)), ifError(x.isNotNan(), Expr.constant(true)));
226-
} else {
227-
return and(exists, x.notEqAny(list));
220+
case NOT_IN:
221+
{
222+
List<Value> list = value.getArrayValue().getValuesList();
223+
if (hasNaN(list)) {
224+
return and(
225+
exists, x.notEqAny(filterNaN(list)), ifError(x.isNotNan(), Expr.constant(true)));
226+
} else {
227+
return and(exists, x.notEqAny(list));
228+
}
228229
}
229-
}
230230
default:
231231
// Handle OPERATOR_UNSPECIFIED and UNRECOGNIZED cases as needed
232232
throw new IllegalArgumentException("Unsupported operator: " + operator);

firebase-firestore/src/main/java/com/google/firebase/firestore/core/Query.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import com.google.firebase.firestore.pipeline.FunctionExpr;
3838
import com.google.firebase.firestore.pipeline.InternalOptions;
3939
import com.google.firebase.firestore.pipeline.Ordering;
40-
import com.google.firebase.firestore.pipeline.BaseStage;
40+
import com.google.firebase.firestore.pipeline.Stage;
4141
import com.google.firebase.firestore.util.BiFunction;
4242
import com.google.firebase.firestore.util.Function;
4343
import com.google.firebase.firestore.util.IntFunction;
@@ -549,7 +549,8 @@ public Pipeline toPipeline(FirebaseFirestore firestore, UserDataReader userDataR
549549
if (fields.size() == 1) {
550550
p = p.where(fields.get(0).exists());
551551
} else {
552-
BooleanExpr[] conditions = skipFirstToArray(fields, BooleanExpr[]::new, Expr.Companion::exists);
552+
BooleanExpr[] conditions =
553+
skipFirstToArray(fields, BooleanExpr[]::new, Expr.Companion::exists);
553554
p = p.where(and(fields.get(0).exists(), conditions));
554555
}
555556

@@ -587,17 +588,18 @@ private static <T> T[] skipFirstToArray(List<T> list, IntFunction<T[]> generator
587588
int size = list.size();
588589
T[] result = generator.apply(size - 1);
589590
for (int i = 1; i < size; i++) {
590-
result[i-1] = list.get(i);
591+
result[i - 1] = list.get(i);
591592
}
592593
return result;
593594
}
594595

595596
// Many Pipelines require first parameter to be separated out from rest.
596-
private static <T, R> R[] skipFirstToArray(List<T> list, IntFunction<R[]> generator, Function<T, R> map) {
597+
private static <T, R> R[] skipFirstToArray(
598+
List<T> list, IntFunction<R[]> generator, Function<T, R> map) {
597599
int size = list.size();
598600
R[] result = generator.apply(size - 1);
599601
for (int i = 1; i < size; i++) {
600-
result[i-1] = map.apply(list.get(i));
602+
result[i - 1] = map.apply(list.get(i));
601603
}
602604
return result;
603605
}
@@ -621,7 +623,7 @@ private static BooleanExpr whereConditionsFromCursor(
621623
}
622624

623625
@NonNull
624-
private BaseStage<?> pipelineSource(FirebaseFirestore firestore) {
626+
private Stage<?> pipelineSource(FirebaseFirestore firestore) {
625627
if (isDocumentQuery()) {
626628
return new DocumentsSource(path.canonicalString());
627629
} else if (isCollectionGroupQuery()) {

firebase-firestore/src/main/java/com/google/firebase/firestore/model/Values.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -599,14 +599,11 @@ internal object Values {
599599
.build()
600600
}
601601

602-
@JvmField
603-
val TRUE: Value = Value.newBuilder().setBooleanValue(true).build()
602+
@JvmField val TRUE: Value = Value.newBuilder().setBooleanValue(true).build()
604603

605-
@JvmField
606-
val FALSE: Value = Value.newBuilder().setBooleanValue(false).build()
604+
@JvmField val FALSE: Value = Value.newBuilder().setBooleanValue(false).build()
607605

608-
@JvmStatic
609-
fun encodeValue(value: Boolean): Value = if (value) TRUE else FALSE
606+
@JvmStatic fun encodeValue(value: Boolean): Value = if (value) TRUE else FALSE
610607

611608
@JvmStatic
612609
fun encodeValue(geoPoint: GeoPoint): Value =

0 commit comments

Comments
 (0)