Skip to content

Commit 7355e49

Browse files
committed
Cleanup and sync with server function updates
1 parent edc1cc9 commit 7355e49

File tree

11 files changed

+15
-164
lines changed

11 files changed

+15
-164
lines changed

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

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import io.opencensus.trace.AttributeValue;
4545
import io.opencensus.trace.Tracing;
4646
import java.util.ArrayList;
47-
import java.util.Arrays;
4847
import java.util.List;
4948
import java.util.logging.Level;
5049
import java.util.logging.Logger;
@@ -538,47 +537,6 @@ public Pipeline findNearest(
538537
.build());
539538
}
540539

541-
/**
542-
* Sorts the documents from previous stages based on one or more {@link Ordering} criteria.
543-
*
544-
* <p>This stage allows you to order the results of your pipeline. You can specify multiple {@link
545-
* Ordering} instances to sort by multiple fields in ascending or descending order. If documents
546-
* have the same value for a field used for sorting, the next specified ordering will be used. If
547-
* all orderings result in equal comparison, the documents are considered equal, and the order is
548-
* unspecified.
549-
*
550-
* <p>Example:
551-
*
552-
* <pre>{@code
553-
* // Sort books by rating in descending order, and then by title in ascending order for books
554-
* // with the same rating, with density required and truncation disabled.
555-
* firestore.pipeline().collection("books")
556-
* .sort(
557-
* Arrays.asList(Ordering.of("rating").descending(), Ordering.of("title")),
558-
* Sort.Density.REQUIRED,
559-
* Sort.Truncation.DISABLED,
560-
* 10);
561-
* }</pre>
562-
*
563-
* @param orders One or more {@link Ordering} instances specifying the sorting criteria.
564-
* @param density Specifies the index density semantics. See {@link
565-
* com.google.cloud.firestore.pipeline.stages.Sort.Density} for more information on density
566-
* sorting.
567-
* @param truncation Specifies the index truncation semantics. See {@link
568-
* com.google.cloud.firestore.pipeline.stages.Sort.Truncation} for more information on
569-
* truncation options.
570-
* @return A new {@code Pipeline} object with this stage appended to the stage list.
571-
*/
572-
@BetaApi
573-
public Pipeline sort(List<Ordering> orders, Sort.Density density, Sort.Truncation truncation) {
574-
return new Pipeline(
575-
this.db,
576-
ImmutableList.<Stage>builder()
577-
.addAll(stages)
578-
.add(new Sort(orders, density, truncation))
579-
.build());
580-
}
581-
582540
/**
583541
* Sorts the documents from previous stages based on one or more {@link Ordering} criteria.
584542
*
@@ -604,7 +562,8 @@ public Pipeline sort(List<Ordering> orders, Sort.Density density, Sort.Truncatio
604562
*/
605563
@BetaApi
606564
public Pipeline sort(Ordering... orders) {
607-
return sort(Arrays.asList(orders), Sort.Density.UNSPECIFIED, Sort.Truncation.UNSPECIFIED);
565+
return new Pipeline(
566+
this.db, ImmutableList.<Stage>builder().addAll(stages).add(new Sort(orders)).build());
608567
}
609568

610569
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ static FilterCondition toPipelineFilterCondition(FilterInternal f) {
101101
case IS_NAN:
102102
return and(field.exists(), field.isNaN());
103103
case IS_NULL:
104-
return and(field.exists(), field.isNull());
104+
return and(field.exists(), field.eq(null));
105105
case IS_NOT_NAN:
106106
return and(field.exists(), not(field.isNaN()));
107107
case IS_NOT_NULL:
108-
return and(field.exists(), not(field.isNull()));
108+
return and(field.exists(), not(field.eq(null)));
109109
default:
110110
// Handle OPERATOR_UNSPECIFIED and UNRECOGNIZED cases as needed
111111
throw new IllegalArgumentException("Unsupported operator: " + unaryFilter.getOperator());

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
import com.google.cloud.firestore.pipeline.expressions.Field;
4747
import com.google.cloud.firestore.pipeline.expressions.Ordering;
4848
import com.google.cloud.firestore.pipeline.expressions.Selectable;
49-
import com.google.cloud.firestore.pipeline.stages.Sort.Density;
50-
import com.google.cloud.firestore.pipeline.stages.Sort.Truncation;
5149
import com.google.cloud.firestore.v1.FirestoreSettings;
5250
import com.google.common.base.Preconditions;
5351
import com.google.common.collect.ImmutableList;
@@ -2174,7 +2172,7 @@ public Pipeline pipeline() {
21742172
? Field.of(fieldOrder.fieldReference.getFieldPath()).ascending()
21752173
: Field.of(fieldOrder.fieldReference.getFieldPath()).descending())
21762174
.collect(Collectors.toList());
2177-
ppl = ppl.sort(orders, Density.REQUIRED, Truncation.UNSPECIFIED);
2175+
ppl = ppl.sort(orders.toArray(new Ordering[] {}));
21782176
}
21792177

21802178
// Cursors, Limit and Offset

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public final class Constant implements Expr {
1919
private final Object value;
2020

21-
private Constant(Object value) {
21+
Constant(Object value) {
2222
this.value = value;
2323
}
2424

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -671,23 +671,6 @@ default Exists exists() {
671671
return new Exists(this);
672672
}
673673

674-
/**
675-
* Creates an expression that checks if this expression evaluates to null.
676-
*
677-
* <p>Example:
678-
*
679-
* <pre>{@code
680-
* // Check if the 'optionalField' is null
681-
* Field.of("optionalField").isNull();
682-
* }</pre>
683-
*
684-
* @return A new {@code Expr} representing the null check.
685-
*/
686-
@BetaApi
687-
default IsNull isNull() {
688-
return new IsNull(this);
689-
}
690-
691674
// Aggregate Functions
692675

693676
/**

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

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,42 +2000,6 @@ public static IsNaN isNaN(String field) {
20002000
return new IsNaN(Field.of(field));
20012001
}
20022002

2003-
/**
2004-
* Creates an expression that checks if an expression evaluates to null.
2005-
*
2006-
* <p>Example:
2007-
*
2008-
* <pre>{@code
2009-
* // Check if the 'optionalField' is null
2010-
* Function.isNull(Field.of("optionalField"));
2011-
* }</pre>
2012-
*
2013-
* @param expr The expression to check.
2014-
* @return A new {@code Expr} representing the null check.
2015-
*/
2016-
@BetaApi
2017-
public static IsNull isNull(Expr expr) {
2018-
return new IsNull(expr);
2019-
}
2020-
2021-
/**
2022-
* Creates an expression that checks if a field's value is null.
2023-
*
2024-
* <p>Example:
2025-
*
2026-
* <pre>{@code
2027-
* // Check if the 'optionalField' is null
2028-
* Function.isNull("optionalField");
2029-
* }</pre>
2030-
*
2031-
* @param field The name of the field to check.
2032-
* @return A new {@code Expr} representing the null check.
2033-
*/
2034-
@BetaApi
2035-
public static IsNull isNull(String field) {
2036-
return new IsNull(Field.of(field));
2037-
}
2038-
20392003
/**
20402004
* Creates an expression that negates a filter condition.
20412005
*

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
public final class FunctionUtils {
1212
@InternalApi
1313
public static Value exprToValue(Expr expr) {
14-
if (expr instanceof Constant) {
14+
if (expr == null) {
15+
return Constant.of((String) null).toProto();
16+
} else if (expr instanceof Constant) {
1517
return ((Constant) expr).toProto();
1618
} else if (expr instanceof Field) {
1719
return ((Field) expr).toProto();

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

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

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

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@
22

33
import com.google.api.core.InternalApi;
44
import com.google.cloud.firestore.pipeline.expressions.Ordering;
5+
import com.google.common.collect.Lists;
56
import java.util.List;
6-
import java.util.Locale;
77

88
public final class Sort implements Stage {
99

1010
private static final String name = "sort";
1111
private final List<Ordering> orders;
12-
private final Sort.Density density;
13-
private final Sort.Truncation truncation;
1412

1513
@InternalApi
16-
public Sort(List<Ordering> orders, Sort.Density density, Sort.Truncation truncation) {
17-
this.orders = orders;
18-
this.density = density;
19-
this.truncation = truncation;
14+
public Sort(Ordering... orders) {
15+
this.orders = Lists.newArrayList(orders);
2016
}
2117

2218
@InternalApi
@@ -28,40 +24,4 @@ public String getName() {
2824
public List<Ordering> getOrders() {
2925
return orders;
3026
}
31-
32-
@InternalApi
33-
public Sort.Density getDensity() {
34-
if (density != null) {
35-
return density;
36-
}
37-
return Density.UNSPECIFIED;
38-
}
39-
40-
@InternalApi
41-
public Sort.Truncation getTruncation() {
42-
if (truncation != null) {
43-
return truncation;
44-
}
45-
return Truncation.UNSPECIFIED;
46-
}
47-
48-
public enum Density {
49-
UNSPECIFIED,
50-
REQUIRED;
51-
52-
@Override
53-
public String toString() {
54-
return name().toLowerCase(Locale.getDefault());
55-
}
56-
}
57-
58-
public enum Truncation {
59-
UNSPECIFIED,
60-
DISABLED;
61-
62-
@Override
63-
public String toString() {
64-
return name().toLowerCase(Locale.getDefault());
65-
}
66-
}
6727
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ public static com.google.firestore.v1.Pipeline.Stage toStageProto(Stage stage) {
6464
.setName(sortStage.getName())
6565
.addAllArgs(
6666
sortStage.getOrders().stream().map(Ordering::toProto).collect(Collectors.toList()))
67-
.putOptions("density", encodeValue(sortStage.getDensity().toString()))
68-
.putOptions("truncation", encodeValue(sortStage.getTruncation().toString()))
6967
.build();
7068
} else if (stage instanceof Offset) {
7169
Offset offsetStage = (Offset) stage;

0 commit comments

Comments
 (0)