Skip to content

Commit 8c864f7

Browse files
committed
order normalization and field unify
1 parent 8bc968f commit 8c864f7

File tree

5 files changed

+117
-76
lines changed

5 files changed

+117
-76
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ class Pipeline private constructor(private val stages: List<Stage>, private val
177177
val projMap = mutableMapOf<String, Expr>()
178178
for (proj in selectables) {
179179
when (proj) {
180-
is Field -> projMap[proj.field] = proj
180+
is Field -> projMap[proj.path.encodedPath] = proj
181181
is AggregatorTarget -> projMap[proj.fieldName] = proj.accumulator
182-
is Fields -> proj.fs?.forEach { projMap[it.field] = it }
182+
is Fields -> proj.fs?.forEach { projMap[it.path.encodedPath] = it }
183183
}
184184
}
185185
return projMap

google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.google.cloud.firestore
22

33
import com.google.cloud.Timestamp
4+
import com.google.cloud.firestore.pipeline.Field
45
import com.google.firestore.v1.Document
56
import com.google.firestore.v1.Value
67
import java.util.Date
@@ -76,6 +77,10 @@ internal constructor(
7677
return this.extractField(fieldPath) != null
7778
}
7879

80+
fun contains(field: Field): Boolean {
81+
return this.extractField(field.path) != null
82+
}
83+
7984
fun get(field: String): Any? {
8085
return get(FieldPath.fromDotSeparatedString(field))
8186
}
@@ -90,12 +95,20 @@ internal constructor(
9095
return UserDataConverter.decodeValue(rpcContext, value)
9196
}
9297

98+
fun get(field: Field): Any? {
99+
return get(field.path)
100+
}
101+
93102
fun <T> get(fieldPath: FieldPath, valueType: Class<T>): T? {
94103
val data = get(fieldPath)
95104
return if (data == null) null
96105
else CustomClassMapper.convertToCustomClass(data, valueType, reference)
97106
}
98107

108+
fun <T> get(field: Field, valueType: Class<T>): T? {
109+
return get(field.path, valueType)
110+
}
111+
99112
fun extractField(fieldPath: FieldPath): Value? {
100113
var value: Value? = null
101114

@@ -114,6 +127,10 @@ internal constructor(
114127
return value
115128
}
116129

130+
fun extractField(field: Field): Value? {
131+
return extractField(field.path)
132+
}
133+
117134
fun getBoolean(field: String): Boolean? {
118135
return get(field) as Boolean?
119136
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,9 +1997,10 @@ public Pipeline toPipeline() {
19971997
}
19981998

19991999
// Orders
2000-
if (this.options.getFieldOrders() != null && !this.options.getFieldOrders().isEmpty()) {
2000+
List<FieldOrder> normalizedOrderbys = this.createImplicitOrderBy();
2001+
if (normalizedOrderbys != null && !normalizedOrderbys.isEmpty()) {
20012002
List<Ordering> orders =
2002-
this.options.getFieldOrders().stream()
2003+
normalizedOrderbys.stream()
20032004
.map(
20042005
fieldOrder ->
20052006
Ordering.of(

google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.google.cloud.firestore.pipeline
33
import com.google.cloud.Timestamp
44
import com.google.cloud.firestore.Blob
55
import com.google.cloud.firestore.DocumentReference
6+
import com.google.cloud.firestore.FieldPath
67
import com.google.cloud.firestore.GeoPoint
78
import com.google.cloud.firestore.Pipeline
89
import com.google.cloud.firestore.encodeValue
@@ -249,26 +250,26 @@ data class Constant internal constructor(private val value: Any?) : Expr {
249250
}
250251

251252
data class Field internal constructor(
252-
internal val field: String,
253+
internal val path: FieldPath,
253254
private var pipeline: Pipeline? = null
254255
) :
255256
Expr, Selectable {
256257
companion object {
257-
const val DOCUMENT_ID: String = "__path__"
258+
const val DOCUMENT_ID: String = "__name__"
258259

259260
@JvmStatic
260261
fun of(path: String): Field {
261-
return Field(path)
262+
return Field(FieldPath.of(path))
262263
}
263264

264265
@JvmStatic
265266
fun ofAll(): Field {
266-
return Field("")
267+
return Field(FieldPath.of(""))
267268
}
268269
}
269270

270271
internal fun toProto(): Value {
271-
return Value.newBuilder().setFieldReferenceValue(field).build()
272+
return Value.newBuilder().setFieldReferenceValue(path.toString()).build()
272273
}
273274
}
274275

0 commit comments

Comments
 (0)