Skip to content

Commit

Permalink
Rename project to select
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-hui committed May 21, 2024
1 parent bb16ca1 commit 424cf8b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import com.google.cloud.firestore.pipeline.FindNearest
import com.google.cloud.firestore.pipeline.Function
import com.google.cloud.firestore.pipeline.Limit
import com.google.cloud.firestore.pipeline.Offset
import com.google.cloud.firestore.pipeline.Project
import com.google.cloud.firestore.pipeline.Projectable
import com.google.cloud.firestore.pipeline.Select
import com.google.cloud.firestore.pipeline.Selectable
import com.google.cloud.firestore.pipeline.Sort
import com.google.cloud.firestore.pipeline.Sort.Ordering
import com.google.cloud.firestore.pipeline.Stage
Expand Down Expand Up @@ -173,9 +173,9 @@ class Pipeline private constructor(private val stages: List<Stage>, private val
}
}

private fun projectablesToMap(vararg projectables: Projectable): Map<String, Expr> {
private fun projectablesToMap(vararg selectables: Selectable): Map<String, Expr> {
val projMap = mutableMapOf<String, Expr>()
for (proj in projectables) {
for (proj in selectables) {
when (proj) {
is Field -> projMap[proj.field] = proj
is AggregatorTarget -> projMap[proj.fieldName] = proj.accumulator
Expand All @@ -185,12 +185,12 @@ class Pipeline private constructor(private val stages: List<Stage>, private val
return projMap
}

fun addFields(vararg fields: Projectable): Pipeline {
fun addFields(vararg fields: Selectable): Pipeline {
return Pipeline(stages.plus(AddFields(projectablesToMap(*fields))), name)
}

fun select(vararg projections: Projectable): Pipeline {
return Pipeline(stages.plus(Project(projectablesToMap(*projections))), name)
fun select(vararg projections: Selectable): Pipeline {
return Pipeline(stages.plus(Select(projectablesToMap(*projections))), name)
}

fun <T> filter(condition: T): Pipeline where T : Expr, T : Function.FilterCondition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import com.google.cloud.Timestamp;
import com.google.cloud.firestore.Query.QueryOptions.Builder;
import com.google.cloud.firestore.pipeline.Field;
import com.google.cloud.firestore.pipeline.Projectable;
import com.google.cloud.firestore.pipeline.Selectable;
import com.google.cloud.firestore.pipeline.Sort.Density;
import com.google.cloud.firestore.pipeline.Sort.Ordering;
import com.google.cloud.firestore.pipeline.Sort.Truncation;
Expand Down Expand Up @@ -1993,7 +1993,7 @@ public Pipeline toPipeline() {
ppl.select(
this.options.getFieldProjections().stream()
.map(fieldReference -> Field.of(fieldReference.getFieldPath()))
.toArray(Projectable[]::new));
.toArray(Selectable[]::new));
}

// Orders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ internal fun exprToValue(expr: Expr): Value {
}
}

interface Projectable
interface Selectable

internal class ExprWithAlias internal constructor(val alias: String, val expr: Expr) : Projectable
internal class ExprWithAlias internal constructor(val alias: String, val expr: Expr) : Selectable

interface Expr {
// Infix functions returning Function subclasses
Expand Down Expand Up @@ -146,7 +146,7 @@ interface Expr {
return Ordering(this, Direction.DESCENDING)
}

fun asAlias(alias: String): Projectable {
fun asAlias(alias: String): Selectable {
return ExprWithAlias(alias, this)
}
}
Expand Down Expand Up @@ -252,7 +252,7 @@ data class Field internal constructor(
internal val field: String,
private var pipeline: Pipeline? = null
) :
Expr, Projectable {
Expr, Selectable {
companion object {
const val DOCUMENT_ID: String = "__path__"

Expand All @@ -272,7 +272,7 @@ data class Field internal constructor(
}
}

data class Fields internal constructor(internal val fs: List<Field>? = null) : Expr, Projectable {
data class Fields internal constructor(internal val fs: List<Field>? = null) : Expr, Selectable {
companion object {
@JvmStatic
fun of(f1: String, vararg f: String): Fields {
Expand All @@ -291,7 +291,7 @@ internal constructor(
internal val accumulator: Function.Accumulator,
internal val fieldName: String,
override var distinct: Boolean,
) : Projectable, Function.Accumulator
) : Selectable, Function.Accumulator

open class Function(val name: String, val params: List<Expr>) : Expr {
interface FilterCondition : Expr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ internal data class Documents(internal val documents: List<String>) : Stage {
}
}

internal data class Project(internal val projections: Map<String, Expr>) : Stage {
val name = "project"
internal data class Select(internal val projections: Map<String, Expr>) : Stage {
val name = "select"
}

internal data class AddFields(internal val fields: Map<String, Expr>) : Stage {
Expand Down Expand Up @@ -205,7 +205,7 @@ internal fun toStageProto(stage: Stage): com.google.firestore.v1.Pipeline.Stage
.setName(stage.name)
.addAllArgs(stage.documents.map { Value.newBuilder().setReferenceValue(it).build() })
.build()
is Project ->
is Select ->
com.google.firestore.v1.Pipeline.Stage.newBuilder()
.setName(stage.name)
.addArgs(encodeValue(stage.projections))
Expand Down

0 comments on commit 424cf8b

Please sign in to comment.