Skip to content

Commit 41283c8

Browse files
committed
Options Fixes
1 parent af162c0 commit 41283c8

File tree

2 files changed

+18
-82
lines changed

2 files changed

+18
-82
lines changed

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

Lines changed: 7 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,21 @@ internal constructor(internal val options: InternalOptions) {
120120
fun with(key: String, value: Field): T = with(key, value.toProto())
121121

122122
/**
123-
* Specify [GenericOptions] object
123+
* Specify [RawOptions] object
124124
*
125125
* @param key The option key
126-
* @param value The [GenericOptions] object
126+
* @param value The [RawOptions] object
127127
* @return A new options object.
128128
*/
129-
fun with(key: String, value: GenericOptions): T = with(key, value.options)
129+
fun with(key: String, value: RawOptions): T = with(key, value.options)
130130
}
131131

132-
class GenericOptions private constructor(options: InternalOptions) :
133-
AbstractOptions<GenericOptions>(options) {
134-
override fun self(options: InternalOptions) = GenericOptions(options)
132+
class RawOptions private constructor(options: InternalOptions) :
133+
AbstractOptions<RawOptions>(options) {
134+
override fun self(options: InternalOptions) = RawOptions(options)
135135

136136
companion object {
137-
@JvmField val DEFAULT: GenericOptions = GenericOptions(InternalOptions.EMPTY)
137+
@JvmField val DEFAULT: RawOptions = RawOptions(InternalOptions.EMPTY)
138138
}
139139
}
140140

@@ -154,72 +154,10 @@ class PipelineOptions private constructor(options: InternalOptions) :
154154
}
155155

156156
fun withIndexMode(indexMode: IndexMode): PipelineOptions = with("index_mode", indexMode.value)
157-
158-
fun withExplainOptions(options: ExplainOptions): PipelineOptions =
159-
with("explain_options", options.options)
160157
}
161158

162159
class RealtimePipelineOptions private constructor(options: InternalOptions) :
163160
AbstractOptions<RealtimePipelineOptions>(options) {
164161

165162
override fun self(options: InternalOptions) = RealtimePipelineOptions(options)
166163
}
167-
168-
class ExplainOptions private constructor(options: InternalOptions) :
169-
AbstractOptions<ExplainOptions>(options) {
170-
override fun self(options: InternalOptions) = ExplainOptions(options)
171-
172-
companion object {
173-
@JvmField val DEFAULT = ExplainOptions(InternalOptions.EMPTY)
174-
}
175-
176-
fun withMode(value: ExplainMode) = with("mode", value.value)
177-
178-
fun withOutputFormat(value: OutputFormat) = with("output_format", value.value)
179-
180-
fun withVerbosity(value: Verbosity) = with("verbosity", value.value)
181-
182-
fun withIndexRecommendation(value: Boolean) = with("index_recommendation", value)
183-
184-
fun withProfiles(value: Profiles) = with("profiles", value.value)
185-
186-
fun withRedact(value: Boolean) = with("redact", value)
187-
188-
class ExplainMode private constructor(internal val value: String) {
189-
companion object {
190-
@JvmField val EXECUTE = ExplainMode("execute")
191-
192-
@JvmField val EXPLAIN = ExplainMode("explain")
193-
194-
@JvmField val ANALYZE = ExplainMode("analyze")
195-
}
196-
}
197-
198-
class OutputFormat private constructor(internal val value: String) {
199-
companion object {
200-
@JvmField val TEXT = OutputFormat("text")
201-
202-
@JvmField val JSON = OutputFormat("json")
203-
204-
@JvmField val STRUCT = OutputFormat("struct")
205-
}
206-
}
207-
208-
class Verbosity private constructor(internal val value: String) {
209-
companion object {
210-
@JvmField val SUMMARY_ONLY = Verbosity("summary_only")
211-
212-
@JvmField val EXECUTION_TREE = Verbosity("execution_tree")
213-
}
214-
}
215-
216-
class Profiles private constructor(internal val value: String) {
217-
companion object {
218-
@JvmField val LATENCY = Profiles("latency")
219-
220-
@JvmField val RECORDS_COUNT = Profiles("records_count")
221-
222-
@JvmField val BYTES_THROUGHPUT = Profiles("bytes_throughput")
223-
}
224-
}
225-
}

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ import kotlinx.coroutines.flow.drop
3333
import kotlinx.coroutines.flow.emptyFlow
3434
import kotlinx.coroutines.flow.filter
3535
import kotlinx.coroutines.flow.flow
36-
import kotlinx.coroutines.flow.forEach
3736
import kotlinx.coroutines.flow.map
38-
import kotlinx.coroutines.flow.skip
3937
import kotlinx.coroutines.flow.take
4038
import kotlinx.coroutines.flow.toList
4139

@@ -54,7 +52,7 @@ sealed class Stage<T : Stage<T>>(
5452

5553
internal abstract fun self(options: InternalOptions): T
5654

57-
protected fun with(key: String, value: Value): T = self(options.with(key, value))
55+
protected fun withOption(key: String, value: Value): T = self(options.with(key, value))
5856

5957
/**
6058
* Specify named [String] parameter
@@ -63,7 +61,7 @@ sealed class Stage<T : Stage<T>>(
6361
* @param value The [String] value of parameter
6462
* @return New stage with named parameter.
6563
*/
66-
fun with(key: String, value: String): T = with(key, Values.encodeValue(value))
64+
fun withOption(key: String, value: String): T = withOption(key, Values.encodeValue(value))
6765

6866
/**
6967
* Specify named [Boolean] parameter
@@ -72,7 +70,7 @@ sealed class Stage<T : Stage<T>>(
7270
* @param value The [Boolean] value of parameter
7371
* @return New stage with named parameter.
7472
*/
75-
fun with(key: String, value: Boolean): T = with(key, Values.encodeValue(value))
73+
fun withOption(key: String, value: Boolean): T = withOption(key, Values.encodeValue(value))
7674

7775
/**
7876
* Specify named [Long] parameter
@@ -81,7 +79,7 @@ sealed class Stage<T : Stage<T>>(
8179
* @param value The [Long] value of parameter
8280
* @return New stage with named parameter.
8381
*/
84-
fun with(key: String, value: Long): T = with(key, Values.encodeValue(value))
82+
fun withOption(key: String, value: Long): T = withOption(key, Values.encodeValue(value))
8583

8684
/**
8785
* Specify named [Double] parameter
@@ -90,7 +88,7 @@ sealed class Stage<T : Stage<T>>(
9088
* @param value The [Double] value of parameter
9189
* @return New stage with named parameter.
9290
*/
93-
fun with(key: String, value: Double): T = with(key, Values.encodeValue(value))
91+
fun withOption(key: String, value: Double): T = withOption(key, Values.encodeValue(value))
9492

9593
/**
9694
* Specify named [Field] parameter
@@ -99,7 +97,7 @@ sealed class Stage<T : Stage<T>>(
9997
* @param value The [Field] value of parameter
10098
* @return New stage with named parameter.
10199
*/
102-
fun with(key: String, value: Field): T = with(key, value.toProto())
100+
fun withOption(key: String, value: Field): T = withOption(key, value.toProto())
103101

104102
internal open fun evaluate(
105103
context: EvaluationContext,
@@ -232,7 +230,7 @@ internal constructor(
232230
}
233231
}
234232

235-
fun withForceIndex(value: String) = with("force_index", value)
233+
fun withForceIndex(value: String) = withOption("force_index", value)
236234

237235
override fun evaluate(
238236
context: EvaluationContext,
@@ -276,7 +274,7 @@ private constructor(private val collectionId: String, options: InternalOptions)
276274
}
277275
}
278276

279-
fun withForceIndex(value: String) = with("force_index", value)
277+
fun withForceIndex(value: String) = withOption("force_index", value)
280278
}
281279

282280
internal class DocumentsSource
@@ -508,7 +506,7 @@ internal constructor(
508506
* @param limit must be a positive integer.
509507
* @return [FindNearestStage] with specified [limit].
510508
*/
511-
fun withLimit(limit: Long): FindNearestStage = with("limit", limit)
509+
fun withLimit(limit: Long): FindNearestStage = withOption("limit", limit)
512510

513511
/**
514512
* Add a field containing the distance to the result.
@@ -517,7 +515,7 @@ internal constructor(
517515
* @return [FindNearestStage] with specified [distanceField].
518516
*/
519517
fun withDistanceField(distanceField: Field): FindNearestStage =
520-
with("distance_field", distanceField)
518+
withOption("distance_field", distanceField)
521519

522520
/**
523521
* Add a field containing the distance to the result.
@@ -825,5 +823,5 @@ internal constructor(
825823
* @param indexField The field name of index field.
826824
* @return [SampleStage] that includes specified index field.
827825
*/
828-
fun withIndexField(indexField: String): UnnestStage = with("index_field", indexField)
826+
fun withIndexField(indexField: String): UnnestStage = withOption("index_field", indexField)
829827
}

0 commit comments

Comments
 (0)