Skip to content

Commit fda0aed

Browse files
Fix comments from Internal review (#2935)
* Fix comments from Internal review * Updates from Copybara This PR addresses comments from cl/392912920
1 parent ad22968 commit fda0aed

File tree

6 files changed

+21
-55
lines changed

6 files changed

+21
-55
lines changed

firebase-firestore/firebase-firestore.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ dependencies {
155155
}
156156

157157
compileOnly 'com.google.auto.value:auto-value-annotations:1.6.6'
158-
androidTestAnnotationProcessor 'com.google.auto.value:auto-value:1.6.5'
158+
annotationProcessor 'com.google.auto.value:auto-value:1.6.5'
159159

160160
testImplementation 'junit:junit:4.12'
161161
testImplementation 'androidx.test:core:1.2.0'

firebase-firestore/src/main/java/com/google/firebase/firestore/index/FirestoreIndexValueWriter.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@
2222
import com.google.type.LatLng;
2323
import java.util.Map;
2424

25-
/**
26-
* Firestore index value writer.
27-
*
28-
* <p>See the <a
29-
* href="https://g3doc.corp.google.com/cloud/datastore/g3doc/architecture/spanner/storage_format.md">storage
30-
* format design</a> for details.
31-
*/
25+
/** Firestore index value writer. */
3226
public class FirestoreIndexValueWriter {
3327
// Note: This code is copied from the backend. Code that is not used by Firestore was removed.
3428

29+
// The client SDK only supports references to documents from the same database. We can skip the
30+
// first five segments.
31+
public static final int DOCUMENT_NAME_OFFSET = 5;
32+
3533
public static final int INDEX_TYPE_NULL = 5;
3634
public static final int INDEX_TYPE_BOOLEAN = 10;
3735
public static final int INDEX_TYPE_NAN = 13;
@@ -155,7 +153,7 @@ private void writeIndexEntityRef(String referenceValue, DirectionalIndexByteEnco
155153
ResourcePath path = ResourcePath.fromString(referenceValue);
156154

157155
int numSegments = path.length();
158-
for (int index = 6; index < numSegments; ++index) {
156+
for (int index = DOCUMENT_NAME_OFFSET; index < numSegments; ++index) {
159157
String segment = path.getSegment(index);
160158

161159
writeValueTypeLabel(encoder, INDEX_TYPE_REFERENCE_SEGMENT);

firebase-firestore/src/main/java/com/google/firebase/firestore/index/OrderedCodeReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import static java.lang.Character.MIN_SURROGATE;
2727

2828
/**
29-
* OrderedCodeReader is a minimal-allocation implementation of the reading behavior defined by
30-
* {@link com.google.bigtable.util.OrderedCode}.
29+
* OrderedCodeReader is a minimal-allocation implementation of the reading behavior defined by our
30+
* backend.
3131
*
3232
* <p>This class will throw {@link IllegalArgumentException} on invalid input.
3333
*/

firebase-firestore/src/main/java/com/google/firebase/firestore/index/OrderedCodeWriter.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import java.util.Arrays;
2323

2424
/**
25-
* OrderedCodeWriter is a minimal-allocation implmentation of the writing behavior defined by {@link
26-
* com.google.bigtable.util.OrderedCode}.
25+
* OrderedCodeWriter is a minimal-allocation implmentation of the writing behavior defined by the
26+
* backend.
2727
*/
2828
public class OrderedCodeWriter {
2929
// Note: This code is copied from the backend. Code that is not used by Firestore was removed.
@@ -36,11 +36,7 @@ public class OrderedCodeWriter {
3636
public static final byte INFINITY = (byte) 0xff; // Combined with ESCAPE2
3737
public static final byte FF_BYTE = 0x00; // Combined with ESCAPE2
3838

39-
/**
40-
* These constants are based on {@link
41-
* com.google.storage.megastore.metadata.adapters.DoubleAdapter}, see
42-
* OrderedCodeWriter::writeDoubleAscending for details.
43-
*/
39+
/** These constants are taken from the backend. */
4440
public static final long DOUBLE_SIGN_MASK = 0x8000000000000000L;
4541

4642
public static final long DOUBLE_ALL_BITS = 0xFFFFFFFFFFFFFFFFL;
@@ -225,7 +221,6 @@ public void writeSignedLongDescending(long value) {
225221
}
226222

227223
public void writeDoubleAscending(double val) {
228-
// Based on com.google.storage.megastore.metadata.adapters.DoubleAdapter.
229224
// This particular encoding has the following properties:
230225
// The order matches the IEEE 754 floating-point comparison results with the
231226
// following exceptions:

firebase-firestore/src/main/java/com/google/firebase/firestore/model/FieldIndex.java

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package com.google.firebase.firestore.model;
1616

1717
import androidx.annotation.NonNull;
18+
import com.google.auto.value.AutoValue;
1819
import java.util.ArrayList;
1920
import java.util.Iterator;
2021
import java.util.List;
@@ -33,7 +34,8 @@
3334
public final class FieldIndex implements Iterable<FieldIndex.Segment> {
3435

3536
/** An index component consisting of field path and index type. */
36-
public static final class Segment {
37+
@AutoValue
38+
public abstract static class Segment {
3739
/** The type of the index, e.g. for which type of query it can be used. */
3840
public enum Kind {
3941
/** Ascending index. Can be used for <, <=, ==, >=, >, !=, IN and NOT IN queries. */
@@ -42,44 +44,15 @@ public enum Kind {
4244
CONTAINS
4345
}
4446

45-
private final FieldPath fieldPath;
46-
private final Kind kind;
47-
48-
public Segment(FieldPath fieldPath, Kind kind) {
49-
this.fieldPath = fieldPath;
50-
this.kind = kind;
51-
}
52-
5347
/** The field path of the component. */
54-
public FieldPath getFieldPath() {
55-
return fieldPath;
56-
}
48+
public abstract FieldPath getFieldPath();
5749

5850
/** The indexes sorting order. */
59-
public Kind getKind() {
60-
return kind;
61-
}
62-
63-
@Override
64-
public boolean equals(Object o) {
65-
if (this == o) return true;
66-
if (o == null || getClass() != o.getClass()) return false;
67-
68-
Segment segment = (Segment) o;
69-
if (!fieldPath.equals(segment.fieldPath)) return false;
70-
return kind == segment.kind;
71-
}
72-
73-
@Override
74-
public int hashCode() {
75-
int result = fieldPath.hashCode();
76-
result = 31 * result + kind.hashCode();
77-
return result;
78-
}
51+
public abstract Kind getKind();
7952

8053
@Override
8154
public String toString() {
82-
return String.format("Segment{fieldPath=%s, kind=%s}", fieldPath, kind);
55+
return String.format("Segment{fieldPath=%s, kind=%s}", getFieldPath(), getKind());
8356
}
8457
}
8558

@@ -127,7 +100,7 @@ public Iterator<Segment> iterator() {
127100
/** Returns a new field index with additional index segment. */
128101
public FieldIndex withAddedField(FieldPath fieldPath, Segment.Kind kind) {
129102
List<Segment> newSegments = new ArrayList<>(segments);
130-
newSegments.add(new Segment(fieldPath, kind));
103+
newSegments.add(new AutoValue_FieldIndex_Segment(fieldPath, kind));
131104
return new FieldIndex(collectionId, newSegments);
132105
}
133106

firebase-firestore/src/main/java/com/google/firebase/firestore/model/TargetIndexMatcher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@
8080
* </table>
8181
*/
8282
public class TargetIndexMatcher {
83-
// The collection ID of the query target.
83+
// The collection ID (or collection group) of the query target.
8484
private final String collectionId;
8585

8686
// The list of filters per field. A target can have duplicate filters for a field.
8787
private final Map<FieldPath, List<FieldFilter>> fieldFilterFields = new HashMap<>();
8888

89-
// The list of orderBy fields in the query target.
89+
// The set of orderBy fields in the query target.
9090
private final Set<FieldPath> orderByFields = new HashSet<>();
9191

9292
public TargetIndexMatcher(Target target) {

0 commit comments

Comments
 (0)