Skip to content

Commit ea780f8

Browse files
committed
fixups
1 parent 39c9bd7 commit ea780f8

File tree

11 files changed

+771
-637
lines changed

11 files changed

+771
-637
lines changed

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

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

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
@@ -569,7 +569,7 @@ public static void checkOnlineAndOfflineResultsMatch(Query query, String... expe
569569
public static void checkQueryAndPipelineResultsMatch(Query query, String... expectedDocs) {
570570
QuerySnapshot docsFromQuery = waitFor(query.get(Source.SERVER));
571571
PipelineSnapshot docsFromPipeline =
572-
waitFor(query.getFirestore().pipeline().createFrom(query).execute());
572+
waitFor(query.getFirestore().pipeline().convertFrom(query).execute());
573573

574574
assertEquals(querySnapshotToIds(docsFromQuery), pipelineSnapshotToIds(docsFromPipeline));
575575
List<String> expected = asList(expectedDocs);

firebase-firestore/src/main/java/com/google/firebase/firestore/AggregateField.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414

1515
package com.google.firebase.firestore;
1616

17+
import static com.google.firebase.firestore.pipeline.Expr.field;
18+
1719
import androidx.annotation.NonNull;
1820
import androidx.annotation.Nullable;
1921
import androidx.annotation.RestrictTo;
2022
import com.google.firebase.firestore.pipeline.AggregateFunction;
2123
import com.google.firebase.firestore.pipeline.AggregateWithAlias;
22-
import com.google.firebase.firestore.pipeline.Field;
2324
import java.util.Objects;
2425

2526
/** Represents an aggregation that can be performed by Firestore. */
@@ -218,7 +219,7 @@ private SumAggregateField(@NonNull FieldPath fieldPath) {
218219
@NonNull
219220
@Override
220221
AggregateWithAlias toPipeline() {
221-
return Field.of(getFieldPath()).sum().alias(getAlias());
222+
return field(getFieldPath()).sum().alias(getAlias());
222223
}
223224
}
224225

@@ -231,7 +232,7 @@ private AverageAggregateField(@NonNull FieldPath fieldPath) {
231232
@NonNull
232233
@Override
233234
AggregateWithAlias toPipeline() {
234-
return Field.of(getFieldPath()).avg().alias(getAlias());
235+
return field(getFieldPath()).avg().alias(getAlias());
235236
}
236237
}
237238
}

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.google.common.collect.ImmutableList
2121
import com.google.firebase.Timestamp
2222
import com.google.firebase.firestore.model.DocumentKey
2323
import com.google.firebase.firestore.model.Values
24+
import com.google.firebase.firestore.pipeline.AbstractOptions
2425
import com.google.firebase.firestore.pipeline.AddFieldsStage
2526
import com.google.firebase.firestore.pipeline.AggregateFunction
2627
import com.google.firebase.firestore.pipeline.AggregateStage
@@ -38,9 +39,11 @@ import com.google.firebase.firestore.pipeline.FindNearestStage
3839
import com.google.firebase.firestore.pipeline.FunctionExpr
3940
import com.google.firebase.firestore.pipeline.GenericArg
4041
import com.google.firebase.firestore.pipeline.GenericStage
42+
import com.google.firebase.firestore.pipeline.InternalOptions
4143
import com.google.firebase.firestore.pipeline.LimitStage
4244
import com.google.firebase.firestore.pipeline.OffsetStage
4345
import com.google.firebase.firestore.pipeline.Ordering
46+
import com.google.firebase.firestore.pipeline.PipelineOptions
4447
import com.google.firebase.firestore.pipeline.RemoveFieldsStage
4548
import com.google.firebase.firestore.pipeline.ReplaceStage
4649
import com.google.firebase.firestore.pipeline.SampleStage
@@ -72,17 +75,19 @@ internal constructor(
7275
return Pipeline(firestore, userDataReader, stages.append(stage))
7376
}
7477

75-
fun execute(): Task<PipelineSnapshot> {
78+
fun execute(): Task<PipelineSnapshot> = execute(PipelineOptions.DEFAULT)
79+
80+
fun execute(options: PipelineOptions): Task<PipelineSnapshot> {
7681
val observerTask = ObserverSnapshotTask()
77-
firestore.callClient { call -> call!!.executePipeline(toProto(), observerTask) }
82+
firestore.callClient { call -> call!!.executePipeline(toProto(options), observerTask) }
7883
return observerTask.task
7984
}
8085

8186
internal fun documentReference(key: DocumentKey): DocumentReference {
8287
return DocumentReference(key, firestore)
8388
}
8489

85-
private fun toProto(): ExecutePipelineRequest {
90+
private fun toProto(options: PipelineOptions): ExecutePipelineRequest {
8691
val database = firestore.databaseId
8792
val builder = ExecutePipelineRequest.newBuilder()
8893
builder.database = "projects/${database.projectId}/databases/${database.databaseId}"
@@ -169,7 +174,7 @@ internal constructor(
169174
*/
170175
fun removeFields(field: String, vararg additionalFields: String): Pipeline =
171176
append(
172-
RemoveFieldsStage(arrayOf(Field.of(field), *additionalFields.map(Field::of).toTypedArray()))
177+
RemoveFieldsStage(arrayOf(Expr.field(field), *additionalFields.map(Expr::field).toTypedArray()))
173178
)
174179

175180
/**
@@ -221,7 +226,7 @@ internal constructor(
221226
append(
222227
SelectStage(
223228
arrayOf(
224-
Field.of(fieldName),
229+
Expr.field(fieldName),
225230
*additionalSelections.map(Selectable::toSelectable).toTypedArray()
226231
)
227232
)
@@ -253,10 +258,10 @@ internal constructor(
253258
* You can filter documents based on their field values, using implementations of [BooleanExpr],
254259
* typically including but not limited to:
255260
*
256-
* - field comparators: [FunctionExpr.eq], [FunctionExpr.lt] (less than), [FunctionExpr.gt]
261+
* - field comparators: [Expr.eq], [Expr.lt] (less than), [Expr.gt]
257262
* (greater than), etc.
258-
* - logical operators: [FunctionExpr.and], [FunctionExpr.or], [FunctionExpr.not], etc.
259-
* - advanced functions: [FunctionExpr.regexMatch], [FunctionExpr.arrayContains[], etc.
263+
* - logical operators: [Expr.and], [Expr.or], [Expr.not], etc.
264+
* - advanced functions: [Expr.regexMatch], [Expr.arrayContains], etc.
260265
*
261266
* @param condition The [BooleanExpr] to apply.
262267
* @return A new [Pipeline] object with this stage appended to the stage list.
@@ -336,7 +341,7 @@ internal constructor(
336341
append(
337342
DistinctStage(
338343
arrayOf(
339-
Field.of(groupField),
344+
Expr.field(groupField),
340345
*additionalGroups.map(Selectable::toSelectable).toTypedArray()
341346
)
342347
)
@@ -468,7 +473,7 @@ internal constructor(
468473
* @param field The [String] specifying the field name containing the nested map.
469474
* @return A new [Pipeline] object with this stage appended to the stage list.
470475
*/
471-
fun replace(field: String): Pipeline = replace(Field.of(field))
476+
fun replace(field: String): Pipeline = replace(Expr.field(field))
472477

473478
/**
474479
* Fully overwrites all fields in a document with those coming from a nested map.
@@ -530,7 +535,7 @@ internal constructor(
530535
* @return A new [Pipeline] object with this stage appended to the stage list.
531536
*/
532537
fun unnest(arrayField: String, alias: String): Pipeline =
533-
unnest(Field.of(arrayField).alias(alias))
538+
unnest(Expr.field(arrayField).alias(alias))
534539

535540
/**
536541
* Takes a specified array from the input documents and outputs a document for each element with

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
package com.google.firebase.firestore.core;
1616

17-
import static com.google.firebase.firestore.pipeline.FunctionExpr.and;
17+
import static com.google.firebase.firestore.pipeline.Expr.and;
1818
import static com.google.firebase.firestore.util.Assert.hardAssert;
1919
import static java.lang.Double.isNaN;
2020

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
package com.google.firebase.firestore.core;
1616

17-
import static com.google.firebase.firestore.pipeline.FunctionExpr.and;
18-
import static com.google.firebase.firestore.pipeline.FunctionExpr.or;
17+
import static com.google.firebase.firestore.pipeline.Expr.and;
18+
import static com.google.firebase.firestore.pipeline.Expr.or;
1919
import static com.google.firebase.firestore.util.Assert.hardAssert;
2020

2121
import androidx.annotation.NonNull;
@@ -547,7 +547,7 @@ public Pipeline toPipeline(FirebaseFirestore firestore, UserDataReader userDataR
547547
p = p.where(fields.get(0).exists());
548548
} else {
549549
BooleanExpr[] conditions =
550-
fields.stream().skip(1).map(Expr::exists).toArray(BooleanExpr[]::new);
550+
fields.stream().skip(1).map(Expr.Companion::exists).toArray(BooleanExpr[]::new);
551551
p = p.where(and(fields.get(0).exists(), conditions));
552552
}
553553

@@ -587,7 +587,7 @@ private static BooleanExpr whereConditionsFromCursor(
587587
int last = size - 1;
588588
BooleanExpr condition = cmp.apply(fields.get(last), boundPosition.get(last));
589589
if (bound.isInclusive()) {
590-
condition = or(condition, FunctionExpr.eq(fields.get(last), boundPosition.get(last)));
590+
condition = or(condition, Expr.eq(fields.get(last), boundPosition.get(last)));
591591
}
592592
for (int i = size - 2; i >= 0; i--) {
593593
final Field field = fields.get(i);

firebase-firestore/src/main/java/com/google/firebase/firestore/pipeline/Constant.kt

Lines changed: 0 additions & 182 deletions
This file was deleted.

firebase-firestore/src/main/java/com/google/firebase/firestore/pipeline/aggregates.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class AggregateFunction
2525
private constructor(private val name: String, private val params: Array<out Expr>) {
2626
private constructor(name: String) : this(name, emptyArray())
2727
private constructor(name: String, expr: Expr) : this(name, arrayOf(expr))
28-
private constructor(name: String, fieldName: String) : this(name, Field.of(fieldName))
28+
private constructor(name: String, fieldName: String) : this(name, Expr.field(fieldName))
2929

3030
companion object {
3131

0 commit comments

Comments
 (0)