Skip to content

Commit 478c46c

Browse files
committed
Function and stage renames
1 parent 2568d6a commit 478c46c

File tree

21 files changed

+260
-196
lines changed

21 files changed

+260
-196
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ public Query getQuery() {
6767
}
6868

6969
@Nonnull
70-
public Pipeline toPipeline() {
70+
public Pipeline pipeline() {
7171
return getQuery()
72-
.toPipeline()
72+
.pipeline()
7373
.aggregate(
7474
this.aggregateFieldList.stream()
7575
.map(PipelineUtils::toPipelineAggregatorTarget)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public interface Firestore extends Service<FirestoreOptions>, AutoCloseable {
6666
*/
6767
CollectionGroup collectionGroup(@Nonnull String collectionId);
6868

69+
PipelineSource pipeline();
70+
6971
/**
7072
* Executes the given updateFunction and then attempts to commit the changes applied within the
7173
* transaction. If any document read within the transaction has changed, the updateFunction will

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.api.core.ApiClock;
2020
import com.google.api.core.ApiFuture;
21+
import com.google.api.core.BetaApi;
2122
import com.google.api.core.NanoClock;
2223
import com.google.api.core.SettableApiFuture;
2324
import com.google.api.gax.rpc.ApiStreamObserver;
@@ -385,6 +386,13 @@ public CollectionGroup collectionGroup(@Nonnull final String collectionId) {
385386
return new CollectionGroup(this, collectionId);
386387
}
387388

389+
@Nonnull
390+
@Override
391+
@BetaApi
392+
public PipelineSource pipeline() {
393+
return new PipelineSource();
394+
}
395+
388396
@Nonnull
389397
@Override
390398
public <T> ApiFuture<T> runTransaction(@Nonnull final Function<T> updateFunction) {

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

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import com.google.cloud.firestore.pipeline.stages.Sort;
3030
import com.google.cloud.firestore.pipeline.stages.Stage;
3131
import com.google.cloud.firestore.pipeline.stages.StageUtils;
32-
import com.google.common.base.Preconditions;
32+
import com.google.cloud.firestore.pipeline.stages.Where;
3333
import com.google.common.collect.ImmutableList;
3434
import com.google.common.collect.ImmutableMap;
3535
import com.google.common.collect.Lists;
@@ -88,42 +88,22 @@ private Pipeline(List<Stage> stages) {
8888
this.stages = ImmutableList.copyOf(stages);
8989
}
9090

91-
private Pipeline(Collection collection) {
91+
Pipeline(Collection collection) {
9292
this(Lists.newArrayList(collection));
9393
}
9494

95-
private Pipeline(CollectionGroup group) {
95+
Pipeline(CollectionGroup group) {
9696
this(Lists.newArrayList(group));
9797
}
9898

99-
private Pipeline(Database db) {
99+
Pipeline(Database db) {
100100
this(Lists.newArrayList(db));
101101
}
102102

103-
private Pipeline(Documents docs) {
103+
Pipeline(Documents docs) {
104104
this(Lists.newArrayList(docs));
105105
}
106106

107-
public static Pipeline fromCollection(String collectionName) {
108-
return new Pipeline(new Collection(collectionName));
109-
}
110-
111-
public static Pipeline fromCollectionGroup(String collectionId) {
112-
Preconditions.checkArgument(
113-
!collectionId.contains("/"),
114-
"Invalid collectionId '%s'. Collection IDs must not contain '/'.",
115-
collectionId);
116-
return new Pipeline(new CollectionGroup(collectionId));
117-
}
118-
119-
public static Pipeline fromDatabase() {
120-
return new Pipeline(new Database());
121-
}
122-
123-
public static Pipeline fromDocuments(DocumentReference... docs) {
124-
return new Pipeline(Documents.of(docs));
125-
}
126-
127107
private Map<String, Expr> projectablesToMap(Selectable... selectables) {
128108
Map<String, Expr> projMap = new HashMap<>();
129109
for (Selectable proj : selectables) {
@@ -178,12 +158,9 @@ public Pipeline select(String... fields) {
178158
.build());
179159
}
180160

181-
public Pipeline filter(FilterCondition condition) {
161+
public Pipeline where(FilterCondition condition) {
182162
return new Pipeline(
183-
ImmutableList.<Stage>builder()
184-
.addAll(stages)
185-
.add(new com.google.cloud.firestore.pipeline.stages.Filter(condition))
186-
.build());
163+
ImmutableList.<Stage>builder().addAll(stages).add(new Where(condition)).build());
187164
}
188165

189166
public Pipeline offset(int offset) {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.google.cloud.firestore;
2+
3+
import com.google.cloud.firestore.pipeline.stages.Collection;
4+
import com.google.cloud.firestore.pipeline.stages.CollectionGroup;
5+
import com.google.cloud.firestore.pipeline.stages.Database;
6+
import com.google.cloud.firestore.pipeline.stages.Documents;
7+
import com.google.common.base.Preconditions;
8+
import javax.annotation.Nonnull;
9+
10+
public class PipelineSource {
11+
12+
@Nonnull
13+
public Pipeline collection(@Nonnull String path) {
14+
return new Pipeline(new Collection(path));
15+
}
16+
17+
@Nonnull
18+
public Pipeline collectionGroup(@Nonnull String collectionId) {
19+
Preconditions.checkArgument(
20+
!collectionId.contains("/"),
21+
"Invalid collectionId '%s'. Collection IDs must not contain '/'.",
22+
collectionId);
23+
return new Pipeline(new CollectionGroup(collectionId));
24+
}
25+
26+
@Nonnull
27+
public Pipeline database() {
28+
return new Pipeline(new Database());
29+
}
30+
31+
@Nonnull
32+
public Pipeline documents(DocumentReference... docs) {
33+
return new Pipeline(Documents.of(docs));
34+
}
35+
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ static FilterCondition toPipelineFilterCondition(FilterInternal f) {
3838
Value value = comparisonFilter.value;
3939
switch (comparisonFilter.operator) {
4040
case LESS_THAN:
41-
return Field.of(fieldPath).lessThan(value);
41+
return Field.of(fieldPath).lt(value);
4242
case LESS_THAN_OR_EQUAL:
43-
return Field.of(fieldPath).lessThanOrEqual(value);
43+
return Field.of(fieldPath).lte(value);
4444
case GREATER_THAN:
45-
return Field.of(fieldPath).greaterThan(value);
45+
return Field.of(fieldPath).gt(value);
4646
case GREATER_THAN_OR_EQUAL:
47-
return Field.of(fieldPath).greaterThanOrEqual(value);
47+
return Field.of(fieldPath).gte(value);
4848
case EQUAL:
49-
return Field.of(fieldPath).equal(value);
49+
return Field.of(fieldPath).eq(value);
5050
case NOT_EQUAL:
51-
return not(Field.of(fieldPath).equal(value));
51+
return not(Field.of(fieldPath).eq(value));
5252
case ARRAY_CONTAINS:
5353
return Field.of(fieldPath).arrayContains(value);
5454
case IN:

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,17 +2122,18 @@ public AggregateQuery aggregate(
21222122
}
21232123

21242124
@Nonnull
2125-
public Pipeline toPipeline() {
2125+
public Pipeline pipeline() {
21262126
// From
21272127
Pipeline ppl =
21282128
this.options.getAllDescendants()
2129-
? Pipeline.fromCollectionGroup(this.options.getCollectionId())
2130-
: Pipeline.fromCollection(
2131-
this.options.getParentPath().append(this.options.getCollectionId()).getPath());
2129+
? new PipelineSource().collectionGroup(this.options.getCollectionId())
2130+
: new PipelineSource()
2131+
.collection(
2132+
this.options.getParentPath().append(this.options.getCollectionId()).getPath());
21322133

21332134
// Filters
21342135
for (FilterInternal f : this.options.getFilters()) {
2135-
ppl = ppl.filter(toPipelineFilterCondition(f));
2136+
ppl = ppl.where(toPipelineFilterCondition(f));
21362137
}
21372138

21382139
// Projections
@@ -2167,10 +2168,10 @@ public Pipeline toPipeline() {
21672168
.collect(Collectors.toList());
21682169
if (exists.size() > 1) {
21692170
ppl =
2170-
ppl.filter(
2171+
ppl.where(
21712172
and(exists.get(0), exists.subList(1, exists.size()).toArray(new Exists[] {})));
21722173
} else if (exists.size() == 1) {
2173-
ppl = ppl.filter(exists.get(0));
2174+
ppl = ppl.where(exists.get(0));
21742175
}
21752176

21762177
ppl = ppl.sort(orders, Density.REQUIRED, Truncation.UNSPECIFIED);

google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Equal.java renamed to google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Eq.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import com.google.common.collect.Lists;
44

5-
public final class Equal extends Function implements FilterCondition {
6-
Equal(Expr left, Expr right) {
5+
public final class Eq extends Function implements FilterCondition {
6+
Eq(Expr left, Expr right) {
77
super("eq", Lists.newArrayList(left, right));
88
}
99
}

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

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,52 +37,52 @@ default Divide divide(Object other) {
3737
return new Divide(this, Constant.of(other));
3838
}
3939

40-
default Equal equal(Expr expr) {
41-
return new Equal(this, expr);
40+
default Eq eq(Expr expr) {
41+
return new Eq(this, expr);
4242
}
4343

44-
default Equal equal(Object other) {
45-
return new Equal(this, Constant.of(other));
44+
default Eq eq(Object other) {
45+
return new Eq(this, Constant.of(other));
4646
}
4747

48-
default NotEqual notEqual(Expr other) {
49-
return new NotEqual(this, other);
48+
default Neq neq(Expr other) {
49+
return new Neq(this, other);
5050
}
5151

52-
default NotEqual notEqual(Object other) {
53-
return new NotEqual(this, Constant.of(other));
52+
default Neq neq(Object other) {
53+
return new Neq(this, Constant.of(other));
5454
}
5555

56-
default GreaterThan greaterThan(Expr other) {
57-
return new GreaterThan(this, other);
56+
default Gt gt(Expr other) {
57+
return new Gt(this, other);
5858
}
5959

60-
default GreaterThan greaterThan(Object other) {
61-
return new GreaterThan(this, Constant.of(other));
60+
default Gt gt(Object other) {
61+
return new Gt(this, Constant.of(other));
6262
}
6363

64-
default GreaterThanOrEqual greaterThanOrEqual(Expr other) {
65-
return new GreaterThanOrEqual(this, other);
64+
default Gte gte(Expr other) {
65+
return new Gte(this, other);
6666
}
6767

68-
default GreaterThanOrEqual greaterThanOrEqual(Object other) {
69-
return new GreaterThanOrEqual(this, Constant.of(other));
68+
default Gte gte(Object other) {
69+
return new Gte(this, Constant.of(other));
7070
}
7171

72-
default LessThan lessThan(Expr other) {
73-
return new LessThan(this, other);
72+
default Lt lt(Expr other) {
73+
return new Lt(this, other);
7474
}
7575

76-
default LessThan lessThan(Object other) {
77-
return new LessThan(this, Constant.of(other));
76+
default Lt lt(Object other) {
77+
return new Lt(this, Constant.of(other));
7878
}
7979

80-
default LessThanOrEqual lessThanOrEqual(Expr other) {
81-
return new LessThanOrEqual(this, other);
80+
default Lte lte(Expr other) {
81+
return new Lte(this, other);
8282
}
8383

84-
default LessThanOrEqual lessThanOrEqual(Object other) {
85-
return new LessThanOrEqual(this, Constant.of(other));
84+
default Lte lte(Object other) {
85+
return new Lte(this, Constant.of(other));
8686
}
8787

8888
default In inAny(Object... other) {
@@ -184,6 +184,10 @@ default RegexContains regexContains(String regex) {
184184
return new RegexContains(this, Constant.of(regex));
185185
}
186186

187+
default RegexMatch regexMatches(String regex) {
188+
return new RegexMatch(this, Constant.of(regex));
189+
}
190+
187191
default StrConcat strConcat(List<Expr> elements) {
188192
return new StrConcat(this, elements);
189193
}

0 commit comments

Comments
 (0)