From 658c95244e58f8a9b3db76b161bda94c2982e345 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Wed, 14 Feb 2024 15:52:53 -0500 Subject: [PATCH 01/65] Pipeline operations AST --- google-cloud-firestore/pom.xml | 76 +++++++++++++++ .../com/google/cloud/firestore/Pipeline.kt | 27 ++++++ .../cloud/firestore/pipeline/Expressions.kt | 3 + .../cloud/firestore/pipeline/Operations.kt | 93 +++++++++++++++++++ 4 files changed, 199 insertions(+) create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt diff --git a/google-cloud-firestore/pom.xml b/google-cloud-firestore/pom.xml index 5219d90c1..b065677b3 100644 --- a/google-cloud-firestore/pom.xml +++ b/google-cloud-firestore/pom.xml @@ -16,6 +16,7 @@ google-cloud-firestore + 1.9.22 @@ -173,6 +174,17 @@ 3.14.0 test + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-test + ${kotlin.version} + test + @@ -214,6 +226,70 @@ org.codehaus.mojo flatten-maven-plugin + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + src/main/java + target/generated-sources/annotations + + + + + test-compile + test-compile + + test-compile + + + + src/test/java + target/generated-test-sources/test-annotations + + + + + + 1.8 + + + + org.apache.maven.plugins + maven-compiler-plugin + + + default-compile + none + + + default-testCompile + none + + + compile + compile + + compile + + + + testCompile + test-compile + + testCompile + + + + diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt new file mode 100644 index 000000000..d93016556 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -0,0 +1,27 @@ +package com.google.cloud.firestore + +import com.google.cloud.firestore.pipeline.Collection +import com.google.cloud.firestore.pipeline.CollectionGroup +import com.google.cloud.firestore.pipeline.Operation + +class Pipeline { + private val operations: MutableList = mutableListOf() + + private constructor(collection: Collection) { + operations.add(collection) + } + private constructor(group: CollectionGroup) { + operations.add(group) + } + companion object { + @JvmStatic + fun from(collectionName: String): Pipeline { + return Pipeline(Collection(collectionName)) + } + + @JvmStatic + fun fromCollectionGroup(group: String): Pipeline { + return Pipeline(CollectionGroup(group)) + } + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt new file mode 100644 index 000000000..e76574491 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -0,0 +1,3 @@ +package com.google.cloud.firestore.pipeline + +interface Expr {} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt new file mode 100644 index 000000000..6ef333fec --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt @@ -0,0 +1,93 @@ +package com.google.cloud.firestore.pipeline + +import com.google.cloud.firestore.FieldPath +import com.google.cloud.firestore.Pipeline + +interface Operation {} + +data class Collection(val path: String): Operation +data class CollectionGroup(val path: String): Operation + +data class Project(val projections: Map): Operation +data class AddFields(val additions: Map): Operation +data class RemoveFields(val removals: List): Operation +data class Filter(val condition: Expr): Operation +data class Offset(val offset: Int): Operation +data class Limit(val limit: Int): Operation +data class Union(val pipeline: Pipeline, val distinct: Boolean): Operation + +data class Group(val fields: Map, val accumulators: Map) + +data class FindNearest(val property: FieldPath, + val vector: Array, + val options: FindNearestOptions): Operation { + enum class Similarity { + EUCLIDEAN, + COSINE, + DOT_PRODUCT + } + + data class FindNearestOptions(val similarity: Similarity, val limit: Long, val output: FieldPath) {} +} + +sealed interface JoinCondition { + data class Expression(val expr: Expr): JoinCondition + data class Using(val fields: Set): JoinCondition +} + +data class Join(val type: Type, + val condition: JoinCondition, + val alias: FieldPath, + val otherPipeline: Pipeline, + val otherAlias: FieldPath): Operation { + enum class Type { + CROSS, + INNER, + FULL, + LEFT, + RIGHT + } +} + +data class SemiJoin(val type: Type, + val condition: JoinCondition, + val alias: FieldPath, + val otherPipeline: Pipeline, + val otherAlias: FieldPath): Operation { + enum class Type { + LEFT_SEMI, + RIGHT_SEMI, + LEFT_ANTI_SEMI, + RIGHT_ANTI_SEMI, + } +} + +data class Ordering(val expr: Expr, val dir: Direction = Direction.ASC) { + enum class Direction { + ASC, + DESC + } +} + +data class Sort(val orders: List, + val density: Density = Density.UNSPECIFIED, + val truncation: Truncation = Truncation.UNSPECIFIED): Operation { + enum class Density{ + UNSPECIFIED, + REQUIRED + } + + enum class Truncation { + UNSPECIFIED, + DISABLED + } +} + +data class Unnest(val mode: Mode, val field: FieldPath): Operation { + enum class Mode { + FULL_REPLACE, + MERGE_PREFER_NEST, + MERGE_PREFER_PARENT; + } +} + From 4ab3382463cbc2b7a5f98edc25cecccf28b45cdb Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Thu, 15 Feb 2024 11:26:42 -0500 Subject: [PATCH 02/65] Getting ready for fluent api --- .../com/google/cloud/firestore/Pipeline.kt | 13 ++++ .../cloud/firestore/pipeline/Expressions.kt | 70 ++++++++++++++++++- .../cloud/firestore/pipeline/Operations.kt | 34 +++++---- 3 files changed, 103 insertions(+), 14 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index d93016556..03e11f9d4 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -2,11 +2,15 @@ package com.google.cloud.firestore import com.google.cloud.firestore.pipeline.Collection import com.google.cloud.firestore.pipeline.CollectionGroup +import com.google.cloud.firestore.pipeline.Database import com.google.cloud.firestore.pipeline.Operation class Pipeline { private val operations: MutableList = mutableListOf() + private constructor(db: Database) { + operations.add(db) + } private constructor(collection: Collection) { operations.add(collection) } @@ -23,5 +27,14 @@ class Pipeline { fun fromCollectionGroup(group: String): Pipeline { return Pipeline(CollectionGroup(group)) } + + @JvmStatic + fun entireDatabase(): Pipeline { + return Pipeline(Database()) + } } + + // Fluent API + + } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index e76574491..7535bc789 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -1,3 +1,71 @@ package com.google.cloud.firestore.pipeline -interface Expr {} +import com.google.firestore.v1.Value + +sealed interface Expr { + data class Constant(val value: Value): Expr {} + data class FieldReference(val field: String): Expr {} + + data class ListOfExprs(val exprs: List): Expr {} + + sealed class Function(val name: String, val params: Map?) : Expr { + data class Equal(val left: Expr, val right: Expr) : Function("equal", mapOf("left" to left, "right" to right)) + data class NotEqual(val left: Expr, val right: Expr) : Function("not_equal", mapOf("left" to left, "right" to right)) + data class GreaterThan(val left: Expr, val right: Expr) : Function("greater_than", mapOf("left" to left, "right" to right)) + data class GreaterThanOrEqual(val left: Expr, val right: Expr) : Function("greater_than_equal", mapOf("left" to left, "right" to right)) + data class In(val left: Expr, val others: List) : Function("in", mapOf("left" to left, "others" to ListOfExprs(others))) // For 'in' + data class LessThan(val left: Expr, val right: Expr) : Function("less_than", mapOf("left" to left, "right" to right)) + data class LessThanOrEqual(val left: Expr, val right: Expr) : Function("less_than_equal", mapOf("left" to left, "right" to right)) + data class NotIn(val left: Expr, val others: List) : Function("not_in", mapOf("left" to left, "others" to ListOfExprs(others))) // For 'not in' + data class And(val conditions: List) : Function("and", mapOf("conditions" to ListOfExprs(conditions))) + data class Or(val conditions: List) : Function("or", mapOf("conditions" to ListOfExprs(conditions))) + data class Not(val condition: Expr) : Function("not", mapOf("condition" to condition)) + data class Exists(val current: FieldReference) : Function("exists", mapOf("current" to current)) + + data class MapGet(val map: Expr, val key: String) : Function("map_get", mapOf("map" to map, "key" to Constant(Value.getDefaultInstance().toBuilder().setStringValue(key).build()))) + + data class ArrayContains(val array: Expr, val element: Expr) : Function("array_contains", mapOf("array" to array, "element" to element)) + data class ArrayContainsAny(val array: Expr, val elements: List) : Function("array_contains_any", mapOf("array" to array, "elements" to ListOfExprs(elements))) + data class IsNaN(val value: Expr) : Function("is_nan", mapOf("value" to value)) + data class IsNull(val value: Expr) : Function("is_null", mapOf("value" to value)) + + data class Sum(val value: Expr) : Function("sum", mapOf("value" to value)) + data class Avg(val value: Expr) : Function("avg", mapOf("value" to value)) + data class Count(val value: Expr) : Function("count", mapOf("value" to value)) + + data class CosineDistance(val vector1: Expr, val vector2: Expr) : Function("cosine_distance", mapOf("vector1" to vector1, "vector2" to vector2)) + data class EuclideanDistance(val vector1: Expr, val vector2: Expr) : Function("euclidean_distance", mapOf("vector1" to vector1, "vector2" to vector2)) + data class HasAncestor(val child: Expr, val ancestor: Expr): Function("has_ancestor", mapOf("child" to child, "ancestor" to ancestor)) + data class Raw(val n: String, val ps: Map?): Function(n, ps) + } + + // Infix functions returning Function subclasses + infix fun equal(other: Expr): Function = Function.Equal(this, other) + infix fun notEqual(other: Expr): Function = Function.NotEqual(this, other) + infix fun greaterThan(other: Expr): Function = Function.GreaterThan(this, other) + infix fun greaterThanOrEqual(other: Expr): Function = Function.GreaterThanOrEqual(this, other) + fun inAny(left: Expr, vararg other: Expr): Function = Function.In(left, other.toList()) + infix fun lessThan(other: Expr): Function = Function.LessThan(this, other) + infix fun lessThanOrEqual(other: Expr): Function = Function.LessThanOrEqual(this, other) + fun notInAny(left: Expr, vararg other: Expr): Function = Function.NotIn(left, other.toList()) + infix fun and(other: Expr): Function = Function.And(listOf(this, other)) + fun and(vararg other: Expr): Function = Function.And(listOf(this) + other.toList()) + infix fun or(other: Expr): Function = Function.Or(listOf(this, other)) + fun or(vararg other: Expr): Function = Function.Or(listOf(this) + other.toList()) + fun exists(): Function = Function.Exists(this as FieldReference) + + infix fun mapGet(key: String): Function = Function.MapGet(this, key) + infix fun arrayContains(element: Expr): Function = Function.ArrayContains(this, element) + fun arrayContainsAny(vararg elements: Expr): Function = Function.ArrayContainsAny(this, elements.toList()) + fun isNaN(): Function = Function.IsNaN(this) + fun isNull(): Function = Function.IsNull(this) + infix fun not(other: Expr): Function = Function.Not(this) // Likely use 'this' if 'not' is unary + fun sum(): Function = Function.Sum(this) + fun avg(): Function = Function.Avg(this) + fun count(): Function = Function.Count(this) + infix fun cosineDistance(other: Expr): Function = Function.CosineDistance(this, other) + infix fun euclideanDistance(other: Expr): Function = Function.EuclideanDistance(this, other) + infix fun hasAncestor(ancestor: Expr): Function = Function.HasAncestor(this, ancestor) + + fun function(name: String, params: Map?): Function = Function.Raw(name, params) +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt index 6ef333fec..252ae8373 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt @@ -1,24 +1,32 @@ package com.google.cloud.firestore.pipeline -import com.google.cloud.firestore.FieldPath import com.google.cloud.firestore.Pipeline interface Operation {} +data class Field internal constructor(val path: String) { + companion object { + fun of(path: String): Field { + return Field(path) + } + } +} + +class Database(): Operation data class Collection(val path: String): Operation data class CollectionGroup(val path: String): Operation -data class Project(val projections: Map): Operation -data class AddFields(val additions: Map): Operation -data class RemoveFields(val removals: List): Operation +data class Project(val projections: Map): Operation +data class AddFields(val additions: Map): Operation +data class RemoveFields(val removals: List): Operation data class Filter(val condition: Expr): Operation data class Offset(val offset: Int): Operation data class Limit(val limit: Int): Operation data class Union(val pipeline: Pipeline, val distinct: Boolean): Operation -data class Group(val fields: Map, val accumulators: Map) +data class Group(val fields: Map, val accumulators: Map) -data class FindNearest(val property: FieldPath, +data class FindNearest(val property: Field, val vector: Array, val options: FindNearestOptions): Operation { enum class Similarity { @@ -27,19 +35,19 @@ data class FindNearest(val property: FieldPath, DOT_PRODUCT } - data class FindNearestOptions(val similarity: Similarity, val limit: Long, val output: FieldPath) {} + data class FindNearestOptions(val similarity: Similarity, val limit: Long, val output: Field) {} } sealed interface JoinCondition { data class Expression(val expr: Expr): JoinCondition - data class Using(val fields: Set): JoinCondition + data class Using(val fields: Set): JoinCondition } data class Join(val type: Type, val condition: JoinCondition, - val alias: FieldPath, + val alias: Field, val otherPipeline: Pipeline, - val otherAlias: FieldPath): Operation { + val otherAlias: Field): Operation { enum class Type { CROSS, INNER, @@ -51,9 +59,9 @@ data class Join(val type: Type, data class SemiJoin(val type: Type, val condition: JoinCondition, - val alias: FieldPath, + val alias: Field, val otherPipeline: Pipeline, - val otherAlias: FieldPath): Operation { + val otherAlias: Field): Operation { enum class Type { LEFT_SEMI, RIGHT_SEMI, @@ -83,7 +91,7 @@ data class Sort(val orders: List, } } -data class Unnest(val mode: Mode, val field: FieldPath): Operation { +data class Unnest(val mode: Mode, val field: Field): Operation { enum class Mode { FULL_REPLACE, MERGE_PREFER_NEST, From a3d72341a7d73d014a0d2e94641182ea092bdbf2 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Thu, 15 Feb 2024 13:24:14 -0500 Subject: [PATCH 03/65] Basic fluent --- .../com/google/cloud/firestore/Pipeline.kt | 193 ++++++++++++++++++ .../cloud/firestore/pipeline/Operations.kt | 4 +- 2 files changed, 196 insertions(+), 1 deletion(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 03e11f9d4..873c0d238 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -1,9 +1,27 @@ package com.google.cloud.firestore +import com.google.cloud.firestore.pipeline.AddFields import com.google.cloud.firestore.pipeline.Collection import com.google.cloud.firestore.pipeline.CollectionGroup import com.google.cloud.firestore.pipeline.Database +import com.google.cloud.firestore.pipeline.Expr +import com.google.cloud.firestore.pipeline.Field +import com.google.cloud.firestore.pipeline.Filter +import com.google.cloud.firestore.pipeline.FindNearest +import com.google.cloud.firestore.pipeline.Group +import com.google.cloud.firestore.pipeline.Join +import com.google.cloud.firestore.pipeline.JoinCondition +import com.google.cloud.firestore.pipeline.Limit +import com.google.cloud.firestore.pipeline.Offset import com.google.cloud.firestore.pipeline.Operation +import com.google.cloud.firestore.pipeline.Ordering +import com.google.cloud.firestore.pipeline.Project +import com.google.cloud.firestore.pipeline.RawOperation +import com.google.cloud.firestore.pipeline.RemoveFields +import com.google.cloud.firestore.pipeline.SemiJoin +import com.google.cloud.firestore.pipeline.Sort +import com.google.cloud.firestore.pipeline.Union +import com.google.cloud.firestore.pipeline.Unnest class Pipeline { private val operations: MutableList = mutableListOf() @@ -11,12 +29,15 @@ class Pipeline { private constructor(db: Database) { operations.add(db) } + private constructor(collection: Collection) { operations.add(collection) } + private constructor(group: CollectionGroup) { operations.add(group) } + companion object { @JvmStatic fun from(collectionName: String): Pipeline { @@ -36,5 +57,177 @@ class Pipeline { // Fluent API + fun project(projections: Map): Pipeline { + operations.add(Project(projections)) + return this + } + + fun addFields(additions: Map): Pipeline { + operations.add(AddFields(additions)) + return this + } + + fun removeFields(removals: List): Pipeline { + operations.add(RemoveFields(removals)) + return this + } + + fun filter(condition: Expr): Pipeline { + operations.add(Filter(condition)) + return this + } + + fun offset(offset: Int): Pipeline { + operations.add(Offset(offset)) + return this + } + + fun limit(limit: Int): Pipeline { + operations.add(Limit(limit)) + return this + } + + fun union(pipeline: Pipeline, distinct: Boolean): Pipeline { + operations.add(Union(pipeline, distinct)) + return this + } + + fun group(fields: Map, accumulators: Map): Pipeline { + operations.add(Group(fields, accumulators)) + return this + } + + fun findNearest( + property: Field, + vector: Array, + options: FindNearest.FindNearestOptions + ): Pipeline { + operations.add(FindNearest(property, vector, options)) + return this + } + + fun innerJoin( + condition: JoinCondition, + alias: Field, + otherPipeline: Pipeline, + otherAlias: Field + ): Pipeline { + operations.add(Join(Join.Type.INNER, condition, alias, otherPipeline, otherAlias)) + return this + } + fun crossJoin( + condition: JoinCondition, + alias: Field, + otherPipeline: Pipeline, + otherAlias: Field + ): Pipeline { + operations.add(Join(Join.Type.CROSS, condition, alias, otherPipeline, otherAlias)) + return this + } + + fun fullJoin( + condition: JoinCondition, + alias: Field, + otherPipeline: Pipeline, + otherAlias: Field + ): Pipeline { + operations.add(Join(Join.Type.FULL, condition, alias, otherPipeline, otherAlias)) + return this + } + + fun leftJoin( + condition: JoinCondition, + alias: Field, + otherPipeline: Pipeline, + otherAlias: Field + ): Pipeline { + operations.add(Join(Join.Type.LEFT, condition, alias, otherPipeline, otherAlias)) + return this + } + + fun rightJoin( + condition: JoinCondition, + alias: Field, + otherPipeline: Pipeline, + otherAlias: Field + ): Pipeline { + operations.add(Join(Join.Type.RIGHT, condition, alias, otherPipeline, otherAlias)) + return this + } + + fun leftSemiJoin( + condition: JoinCondition, + alias: Field, + otherPipeline: Pipeline, + otherAlias: Field + ): Pipeline { + operations.add(SemiJoin(SemiJoin.Type.LEFT_SEMI, condition, alias, otherPipeline, otherAlias)) + return this + } + + fun rightSemiJoin( + condition: JoinCondition, + alias: Field, + otherPipeline: Pipeline, + otherAlias: Field + ): Pipeline { + operations.add(SemiJoin(SemiJoin.Type.RIGHT_SEMI, condition, alias, otherPipeline, otherAlias)) + return this + } + + fun leftAntiSemiJoin( + condition: JoinCondition, + alias: Field, + otherPipeline: Pipeline, + otherAlias: Field + ): Pipeline { + operations.add( + SemiJoin( + SemiJoin.Type.LEFT_ANTI_SEMI, + condition, + alias, + otherPipeline, + otherAlias + ) + ) + return this + } + + fun rightAntiSemiJoin( + condition: JoinCondition, + alias: Field, + otherPipeline: Pipeline, + otherAlias: Field + ): Pipeline { + operations.add( + SemiJoin( + SemiJoin.Type.RIGHT_ANTI_SEMI, + condition, + alias, + otherPipeline, + otherAlias + ) + ) + return this + } + + fun sort( + orders: List, + density: Sort.Density = Sort.Density.UNSPECIFIED, + truncation: Sort.Truncation = Sort.Truncation.UNSPECIFIED + ): Pipeline { + operations.add(Sort(orders, density, truncation)) + return this + } + + fun unnest(mode: Unnest.Mode, field: Field): Pipeline { + operations.add(Unnest(mode, field)) + return this + } + + fun rawOperation(name: String, params: Map? = null): Pipeline { + operations.add(RawOperation(name, params)) + return this + } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt index 252ae8373..8a7ef68c8 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt @@ -24,7 +24,7 @@ data class Offset(val offset: Int): Operation data class Limit(val limit: Int): Operation data class Union(val pipeline: Pipeline, val distinct: Boolean): Operation -data class Group(val fields: Map, val accumulators: Map) +data class Group(val fields: Map, val accumulators: Map): Operation data class FindNearest(val property: Field, val vector: Array, @@ -99,3 +99,5 @@ data class Unnest(val mode: Mode, val field: Field): Operation { } } +data class RawOperation(val name: String, val params: Map?): Operation + From a837f62e482d2e3d03fb85265b23f836b20c0854 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Sat, 17 Feb 2024 16:11:28 -0500 Subject: [PATCH 04/65] Joins too --- .../com/google/cloud/firestore/Pipeline.kt | 94 +++++++++++++------ .../cloud/firestore/pipeline/Expressions.kt | 46 +++++---- .../cloud/firestore/pipeline/Operations.kt | 6 +- 3 files changed, 94 insertions(+), 52 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 873c0d238..b4602602e 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -16,26 +16,31 @@ import com.google.cloud.firestore.pipeline.Offset import com.google.cloud.firestore.pipeline.Operation import com.google.cloud.firestore.pipeline.Ordering import com.google.cloud.firestore.pipeline.Project +import com.google.cloud.firestore.pipeline.Projectable import com.google.cloud.firestore.pipeline.RawOperation import com.google.cloud.firestore.pipeline.RemoveFields import com.google.cloud.firestore.pipeline.SemiJoin import com.google.cloud.firestore.pipeline.Sort -import com.google.cloud.firestore.pipeline.Union +import com.google.cloud.firestore.pipeline.UnionWith import com.google.cloud.firestore.pipeline.Unnest class Pipeline { private val operations: MutableList = mutableListOf() + private var name: String private constructor(db: Database) { operations.add(db) + name = "(database)" } private constructor(collection: Collection) { operations.add(collection) + name = collection.path } private constructor(group: CollectionGroup) { operations.add(group) + name = group.path } companion object { @@ -57,22 +62,44 @@ class Pipeline { // Fluent API + fun withName(name: String) { + this.name = name + } + fun project(projections: Map): Pipeline { operations.add(Project(projections)) return this } + // Sugar for project + fun project(vararg fields: Field): Pipeline { + return this + } + + fun project(vararg exprs: Expr.ExprAsAlias): Pipeline { + return this + } + + fun project(vararg projections: Projectable): Pipeline { + return this + } + fun addFields(additions: Map): Pipeline { operations.add(AddFields(additions)) return this } - fun removeFields(removals: List): Pipeline { - operations.add(RemoveFields(removals)) + // Sugar + fun addFields(vararg additions: Expr.ExprAsAlias): Pipeline { return this } - fun filter(condition: Expr): Pipeline { + fun removeFields(vararg removals: Field): Pipeline { + operations.add(RemoveFields(removals.toList())) + return this + } + + fun filter(condition: Expr.Function.ProducingBoolean): Pipeline { operations.add(Filter(condition)) return this } @@ -87,8 +114,8 @@ class Pipeline { return this } - fun union(pipeline: Pipeline, distinct: Boolean): Pipeline { - operations.add(Union(pipeline, distinct)) + fun unionWith(pipeline: Pipeline, distinct: Boolean): Pipeline { + operations.add(UnionWith(pipeline, distinct)) return this } @@ -107,60 +134,60 @@ class Pipeline { } fun innerJoin( - condition: JoinCondition, - alias: Field, otherPipeline: Pipeline, - otherAlias: Field + condition: JoinCondition, + alias: Field = Field.of(this.name), + otherAlias: Field = Field.of(otherPipeline.name) ): Pipeline { operations.add(Join(Join.Type.INNER, condition, alias, otherPipeline, otherAlias)) return this } fun crossJoin( - condition: JoinCondition, - alias: Field, otherPipeline: Pipeline, - otherAlias: Field + condition: JoinCondition, + alias: Field = Field.of(this.name), + otherAlias: Field = Field.of(otherPipeline.name) ): Pipeline { operations.add(Join(Join.Type.CROSS, condition, alias, otherPipeline, otherAlias)) return this } fun fullJoin( - condition: JoinCondition, - alias: Field, otherPipeline: Pipeline, - otherAlias: Field + condition: JoinCondition, + alias: Field = Field.of(this.name), + otherAlias: Field = Field.of(otherPipeline.name) ): Pipeline { operations.add(Join(Join.Type.FULL, condition, alias, otherPipeline, otherAlias)) return this } fun leftJoin( - condition: JoinCondition, - alias: Field, otherPipeline: Pipeline, - otherAlias: Field + condition: JoinCondition, + alias: Field = Field.of(this.name), + otherAlias: Field = Field.of(otherPipeline.name) ): Pipeline { operations.add(Join(Join.Type.LEFT, condition, alias, otherPipeline, otherAlias)) return this } fun rightJoin( - condition: JoinCondition, - alias: Field, otherPipeline: Pipeline, - otherAlias: Field + condition: JoinCondition, + alias: Field = Field.of(this.name), + otherAlias: Field = Field.of(otherPipeline.name) ): Pipeline { operations.add(Join(Join.Type.RIGHT, condition, alias, otherPipeline, otherAlias)) return this } fun leftSemiJoin( - condition: JoinCondition, - alias: Field, otherPipeline: Pipeline, - otherAlias: Field + condition: JoinCondition, + alias: Field = Field.of(this.name), + otherAlias: Field = Field.of(otherPipeline.name) ): Pipeline { operations.add(SemiJoin(SemiJoin.Type.LEFT_SEMI, condition, alias, otherPipeline, otherAlias)) return this @@ -177,10 +204,10 @@ class Pipeline { } fun leftAntiSemiJoin( - condition: JoinCondition, - alias: Field, otherPipeline: Pipeline, - otherAlias: Field + condition: JoinCondition, + alias: Field = Field.of(this.name), + otherAlias: Field = Field.of(otherPipeline.name) ): Pipeline { operations.add( SemiJoin( @@ -195,10 +222,10 @@ class Pipeline { } fun rightAntiSemiJoin( - condition: JoinCondition, - alias: Field, otherPipeline: Pipeline, - otherAlias: Field + condition: JoinCondition, + alias: Field = Field.of(this.name), + otherAlias: Field = Field.of(otherPipeline.name) ): Pipeline { operations.add( SemiJoin( @@ -221,7 +248,12 @@ class Pipeline { return this } - fun unnest(mode: Unnest.Mode, field: Field): Pipeline { + // Sugar + fun sort(vararg orders: Ordering): Pipeline { + return this + } + + fun unnest(field: Field, mode: Unnest.Mode = Unnest.Mode.FULL_REPLACE ): Pipeline { operations.add(Unnest(mode, field)) return this } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index 7535bc789..af56b8bc9 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -2,32 +2,38 @@ package com.google.cloud.firestore.pipeline import com.google.firestore.v1.Value +interface Projectable + + sealed interface Expr { - data class Constant(val value: Value): Expr {} + data class Constant(val value: Value): Expr, Projectable {} data class FieldReference(val field: String): Expr {} data class ListOfExprs(val exprs: List): Expr {} + data class ExprAsAlias(val current: Expr, val alias: String): Expr, Projectable {} + sealed class Function(val name: String, val params: Map?) : Expr { - data class Equal(val left: Expr, val right: Expr) : Function("equal", mapOf("left" to left, "right" to right)) - data class NotEqual(val left: Expr, val right: Expr) : Function("not_equal", mapOf("left" to left, "right" to right)) - data class GreaterThan(val left: Expr, val right: Expr) : Function("greater_than", mapOf("left" to left, "right" to right)) - data class GreaterThanOrEqual(val left: Expr, val right: Expr) : Function("greater_than_equal", mapOf("left" to left, "right" to right)) - data class In(val left: Expr, val others: List) : Function("in", mapOf("left" to left, "others" to ListOfExprs(others))) // For 'in' - data class LessThan(val left: Expr, val right: Expr) : Function("less_than", mapOf("left" to left, "right" to right)) - data class LessThanOrEqual(val left: Expr, val right: Expr) : Function("less_than_equal", mapOf("left" to left, "right" to right)) - data class NotIn(val left: Expr, val others: List) : Function("not_in", mapOf("left" to left, "others" to ListOfExprs(others))) // For 'not in' - data class And(val conditions: List) : Function("and", mapOf("conditions" to ListOfExprs(conditions))) - data class Or(val conditions: List) : Function("or", mapOf("conditions" to ListOfExprs(conditions))) - data class Not(val condition: Expr) : Function("not", mapOf("condition" to condition)) - data class Exists(val current: FieldReference) : Function("exists", mapOf("current" to current)) + interface ProducingBoolean + data class Equal(val left: Expr, val right: Expr) : Function("equal", mapOf("left" to left, "right" to right)), ProducingBoolean + data class NotEqual(val left: Expr, val right: Expr) : Function("not_equal", mapOf("left" to left, "right" to right)), ProducingBoolean + data class GreaterThan(val left: Expr, val right: Expr) : Function("greater_than", mapOf("left" to left, "right" to right)), ProducingBoolean + data class GreaterThanOrEqual(val left: Expr, val right: Expr) : Function("greater_than_equal", mapOf("left" to left, "right" to right)), ProducingBoolean + data class In(val left: Expr, val others: List) : Function("in", mapOf("left" to left, "others" to ListOfExprs(others))), ProducingBoolean // For 'in' + data class LessThan(val left: Expr, val right: Expr) : Function("less_than", mapOf("left" to left, "right" to right)), ProducingBoolean + data class LessThanOrEqual(val left: Expr, val right: Expr) : Function("less_than_equal", mapOf("left" to left, "right" to right)), ProducingBoolean + data class NotIn(val left: Expr, val others: List) : Function("not_in", mapOf("left" to left, "others" to ListOfExprs(others))), ProducingBoolean // For 'not in' + data class And(val conditions: List) : Function("and", mapOf("conditions" to ListOfExprs(conditions))), ProducingBoolean + data class Or(val conditions: List) : Function("or", mapOf("conditions" to ListOfExprs(conditions))), ProducingBoolean + data class Not(val condition: Expr) : Function("not", mapOf("condition" to condition)), ProducingBoolean + data class Exists(val current: FieldReference) : Function("exists", mapOf("current" to current)), ProducingBoolean data class MapGet(val map: Expr, val key: String) : Function("map_get", mapOf("map" to map, "key" to Constant(Value.getDefaultInstance().toBuilder().setStringValue(key).build()))) - data class ArrayContains(val array: Expr, val element: Expr) : Function("array_contains", mapOf("array" to array, "element" to element)) - data class ArrayContainsAny(val array: Expr, val elements: List) : Function("array_contains_any", mapOf("array" to array, "elements" to ListOfExprs(elements))) - data class IsNaN(val value: Expr) : Function("is_nan", mapOf("value" to value)) - data class IsNull(val value: Expr) : Function("is_null", mapOf("value" to value)) + data class ArrayContains(val array: Expr, val element: Expr) : Function("array_contains", mapOf("array" to array, "element" to element)), ProducingBoolean + data class ArrayContainsAny(val array: Expr, val elements: List) : Function("array_contains_any", mapOf("array" to array, "elements" to ListOfExprs(elements))), ProducingBoolean + data class IsNaN(val value: Expr) : Function("is_nan", mapOf("value" to value)), ProducingBoolean + data class IsNull(val value: Expr) : Function("is_null", mapOf("value" to value)), ProducingBoolean data class Sum(val value: Expr) : Function("sum", mapOf("value" to value)) data class Avg(val value: Expr) : Function("avg", mapOf("value" to value)) @@ -35,7 +41,7 @@ sealed interface Expr { data class CosineDistance(val vector1: Expr, val vector2: Expr) : Function("cosine_distance", mapOf("vector1" to vector1, "vector2" to vector2)) data class EuclideanDistance(val vector1: Expr, val vector2: Expr) : Function("euclidean_distance", mapOf("vector1" to vector1, "vector2" to vector2)) - data class HasAncestor(val child: Expr, val ancestor: Expr): Function("has_ancestor", mapOf("child" to child, "ancestor" to ancestor)) + data class HasAncestor(val child: Expr, val ancestor: Expr): Function("has_ancestor", mapOf("child" to child, "ancestor" to ancestor)), ProducingBoolean data class Raw(val n: String, val ps: Map?): Function(n, ps) } @@ -68,4 +74,8 @@ sealed interface Expr { infix fun hasAncestor(ancestor: Expr): Function = Function.HasAncestor(this, ancestor) fun function(name: String, params: Map?): Function = Function.Raw(name, params) + + fun withAlias(alias: String): ExprAsAlias { + return ExprAsAlias(this, alias) + } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt index 8a7ef68c8..40e8d376f 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt @@ -4,7 +4,7 @@ import com.google.cloud.firestore.Pipeline interface Operation {} -data class Field internal constructor(val path: String) { +data class Field internal constructor(val path: String): Projectable { companion object { fun of(path: String): Field { return Field(path) @@ -19,10 +19,10 @@ data class CollectionGroup(val path: String): Operation data class Project(val projections: Map): Operation data class AddFields(val additions: Map): Operation data class RemoveFields(val removals: List): Operation -data class Filter(val condition: Expr): Operation +data class Filter(val condition: Expr.Function.ProducingBoolean): Operation data class Offset(val offset: Int): Operation data class Limit(val limit: Int): Operation -data class Union(val pipeline: Pipeline, val distinct: Boolean): Operation +data class UnionWith(val pipeline: Pipeline, val distinct: Boolean): Operation data class Group(val fields: Map, val accumulators: Map): Operation From c8e7854e4993dcb15e8d1e5ab4fa054d087543be Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Tue, 20 Feb 2024 10:01:17 -0500 Subject: [PATCH 05/65] Some fixups, and group bys --- .../com/google/cloud/firestore/Pipeline.kt | 15 +- .../cloud/firestore/pipeline/Expressions.kt | 235 ++++++++++++++---- .../cloud/firestore/pipeline/Operations.kt | 34 +-- .../cloud/firestore/it/ITPipelineTest.java | 99 ++++++++ .../cloud/firestore/it/PipelineKTTest.kt | 16 ++ 5 files changed, 321 insertions(+), 78 deletions(-) create mode 100644 google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java create mode 100644 google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/PipelineKTTest.kt diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index b4602602e..41f12d52e 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -5,7 +5,8 @@ import com.google.cloud.firestore.pipeline.Collection import com.google.cloud.firestore.pipeline.CollectionGroup import com.google.cloud.firestore.pipeline.Database import com.google.cloud.firestore.pipeline.Expr -import com.google.cloud.firestore.pipeline.Field +import com.google.cloud.firestore.pipeline.Expr.Field +import com.google.cloud.firestore.pipeline.Fields import com.google.cloud.firestore.pipeline.Filter import com.google.cloud.firestore.pipeline.FindNearest import com.google.cloud.firestore.pipeline.Group @@ -99,7 +100,7 @@ class Pipeline { return this } - fun filter(condition: Expr.Function.ProducingBoolean): Pipeline { + fun filter(condition: Expr.Function.FilterCondition): Pipeline { operations.add(Filter(condition)) return this } @@ -124,6 +125,16 @@ class Pipeline { return this } + fun group(by: Fields, vararg accumulators: Expr.AccumulatorTarget): Pipeline { + // operations.add(Group(fields, accumulators)) + return this + } + + fun group(by: Projectable, vararg accumulators: Expr.AccumulatorTarget): Pipeline { + // operations.add(Group(fields, accumulators)) + return this + } + fun findNearest( property: Field, vector: Array, diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index af56b8bc9..85279024d 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -4,78 +4,203 @@ import com.google.firestore.v1.Value interface Projectable +// Convenient class for internal usage +internal data class ListOfExprs(val conditions: List): Expr +internal data class ListOfConditions(val conditions: List): Expr, Expr.Function.FilterCondition {} + +data class Fields(val fs: List) { + companion object { + @JvmStatic + fun of(vararg f: String): Fields { + return Fields(f.map(Expr.Field.Companion::of)) + } + } +} sealed interface Expr { - data class Constant(val value: Value): Expr, Projectable {} - data class FieldReference(val field: String): Expr {} + data class Constant internal constructor(val value: Any): Expr { + companion object { + @JvmStatic + fun of(value: Any): Constant { + return Constant(value) + } + } + } + data class Field(val field: String): Expr, Projectable { + companion object { + @JvmStatic + fun of(path: String): Field { + return Field(path) + } + } + } - data class ListOfExprs(val exprs: List): Expr {} data class ExprAsAlias(val current: Expr, val alias: String): Expr, Projectable {} + data class AccumulatorTarget(val current: Function.Accumulator, val target: String): Expr, Function.Accumulator {} + sealed class Function(val name: String, val params: Map?) : Expr { - interface ProducingBoolean - data class Equal(val left: Expr, val right: Expr) : Function("equal", mapOf("left" to left, "right" to right)), ProducingBoolean - data class NotEqual(val left: Expr, val right: Expr) : Function("not_equal", mapOf("left" to left, "right" to right)), ProducingBoolean - data class GreaterThan(val left: Expr, val right: Expr) : Function("greater_than", mapOf("left" to left, "right" to right)), ProducingBoolean - data class GreaterThanOrEqual(val left: Expr, val right: Expr) : Function("greater_than_equal", mapOf("left" to left, "right" to right)), ProducingBoolean - data class In(val left: Expr, val others: List) : Function("in", mapOf("left" to left, "others" to ListOfExprs(others))), ProducingBoolean // For 'in' - data class LessThan(val left: Expr, val right: Expr) : Function("less_than", mapOf("left" to left, "right" to right)), ProducingBoolean - data class LessThanOrEqual(val left: Expr, val right: Expr) : Function("less_than_equal", mapOf("left" to left, "right" to right)), ProducingBoolean - data class NotIn(val left: Expr, val others: List) : Function("not_in", mapOf("left" to left, "others" to ListOfExprs(others))), ProducingBoolean // For 'not in' - data class And(val conditions: List) : Function("and", mapOf("conditions" to ListOfExprs(conditions))), ProducingBoolean - data class Or(val conditions: List) : Function("or", mapOf("conditions" to ListOfExprs(conditions))), ProducingBoolean - data class Not(val condition: Expr) : Function("not", mapOf("condition" to condition)), ProducingBoolean - data class Exists(val current: FieldReference) : Function("exists", mapOf("current" to current)), ProducingBoolean + interface FilterCondition { + infix fun and(other: FilterCondition)= Function.And(listOf(this, other)) + fun and(vararg other: FilterCondition)= Function.And(listOf(this) + other.toList()) + + // Or and Not are restricted as a companion/static function + // infix fun or(other: Expr)= Function.Or(listOf(this, other)) + // fun or(vararg other: Expr)= Function.Or(listOf(this) + other.toList()) + // infix fun not(other: Expr)= Function.Not(this) + } + + interface Accumulator { + fun toField(target: String) = AccumulatorTarget(this, target) + } + + data class Equal internal constructor(val left: Expr, val right: Expr) : Function("equal", mapOf("left" to left, "right" to right)), FilterCondition + data class NotEqual(val left: Expr, val right: Expr) : Function("not_equal", mapOf("left" to left, "right" to right)), FilterCondition + data class GreaterThan(val left: Expr, val right: Expr) : Function("greater_than", mapOf("left" to left, "right" to right)), FilterCondition + data class GreaterThanOrEqual(val left: Expr, val right: Expr) : Function("greater_than_equal", mapOf("left" to left, "right" to right)), FilterCondition + data class In(val left: Expr, val others: List) : Function("in", mapOf("left" to left, "others" to ListOfExprs(others))), FilterCondition // For 'in' + data class LessThan(val left: Expr, val right: Expr) : Function("less_than", mapOf("left" to left, "right" to right)), FilterCondition + data class LessThanOrEqual(val left: Expr, val right: Expr) : Function("less_than_equal", mapOf("left" to left, "right" to right)), FilterCondition + data class NotIn(val left: Expr, val others: List) : Function("not_in", mapOf("left" to left, "others" to ListOfExprs(others))), FilterCondition // For 'not in' + data class And(val conditions: List) : Function("and", mapOf("conditions" to ListOfConditions(conditions))), FilterCondition + data class Or(val conditions: List) : Function("or", mapOf("conditions" to ListOfConditions(conditions))), FilterCondition + data class Not(val condition: Expr) : Function("not", mapOf("condition" to condition)), FilterCondition + data class Exists(val current: Field) : Function("exists", mapOf("current" to current)), FilterCondition data class MapGet(val map: Expr, val key: String) : Function("map_get", mapOf("map" to map, "key" to Constant(Value.getDefaultInstance().toBuilder().setStringValue(key).build()))) - data class ArrayContains(val array: Expr, val element: Expr) : Function("array_contains", mapOf("array" to array, "element" to element)), ProducingBoolean - data class ArrayContainsAny(val array: Expr, val elements: List) : Function("array_contains_any", mapOf("array" to array, "elements" to ListOfExprs(elements))), ProducingBoolean - data class IsNaN(val value: Expr) : Function("is_nan", mapOf("value" to value)), ProducingBoolean - data class IsNull(val value: Expr) : Function("is_null", mapOf("value" to value)), ProducingBoolean + data class ArrayContains(val array: Expr, val element: Expr) : Function("array_contains", mapOf("array" to array, "element" to element)), FilterCondition + data class ArrayContainsAny(val array: Expr, val elements: List) : Function("array_contains_any", mapOf("array" to array, "elements" to ListOfExprs(elements))), FilterCondition + data class IsNaN(val value: Expr) : Function("is_nan", mapOf("value" to value)), FilterCondition + data class IsNull(val value: Expr) : Function("is_null", mapOf("value" to value)), FilterCondition - data class Sum(val value: Expr) : Function("sum", mapOf("value" to value)) - data class Avg(val value: Expr) : Function("avg", mapOf("value" to value)) - data class Count(val value: Expr) : Function("count", mapOf("value" to value)) + data class Sum(val value: Expr) : Function("sum", mapOf("value" to value)), Accumulator + data class Avg(val value: Expr) : Function("avg", mapOf("value" to value)), Accumulator + data class Count(val value: Expr) : Function("count", mapOf("value" to value)), Accumulator data class CosineDistance(val vector1: Expr, val vector2: Expr) : Function("cosine_distance", mapOf("vector1" to vector1, "vector2" to vector2)) data class EuclideanDistance(val vector1: Expr, val vector2: Expr) : Function("euclidean_distance", mapOf("vector1" to vector1, "vector2" to vector2)) - data class HasAncestor(val child: Expr, val ancestor: Expr): Function("has_ancestor", mapOf("child" to child, "ancestor" to ancestor)), ProducingBoolean + data class HasAncestor(val child: Expr, val ancestor: Expr): Function("has_ancestor", mapOf("child" to child, "ancestor" to ancestor)), FilterCondition data class Raw(val n: String, val ps: Map?): Function(n, ps) } // Infix functions returning Function subclasses - infix fun equal(other: Expr): Function = Function.Equal(this, other) - infix fun notEqual(other: Expr): Function = Function.NotEqual(this, other) - infix fun greaterThan(other: Expr): Function = Function.GreaterThan(this, other) - infix fun greaterThanOrEqual(other: Expr): Function = Function.GreaterThanOrEqual(this, other) - fun inAny(left: Expr, vararg other: Expr): Function = Function.In(left, other.toList()) - infix fun lessThan(other: Expr): Function = Function.LessThan(this, other) - infix fun lessThanOrEqual(other: Expr): Function = Function.LessThanOrEqual(this, other) - fun notInAny(left: Expr, vararg other: Expr): Function = Function.NotIn(left, other.toList()) - infix fun and(other: Expr): Function = Function.And(listOf(this, other)) - fun and(vararg other: Expr): Function = Function.And(listOf(this) + other.toList()) - infix fun or(other: Expr): Function = Function.Or(listOf(this, other)) - fun or(vararg other: Expr): Function = Function.Or(listOf(this) + other.toList()) - fun exists(): Function = Function.Exists(this as FieldReference) - - infix fun mapGet(key: String): Function = Function.MapGet(this, key) - infix fun arrayContains(element: Expr): Function = Function.ArrayContains(this, element) - fun arrayContainsAny(vararg elements: Expr): Function = Function.ArrayContainsAny(this, elements.toList()) - fun isNaN(): Function = Function.IsNaN(this) - fun isNull(): Function = Function.IsNull(this) - infix fun not(other: Expr): Function = Function.Not(this) // Likely use 'this' if 'not' is unary - fun sum(): Function = Function.Sum(this) - fun avg(): Function = Function.Avg(this) - fun count(): Function = Function.Count(this) - infix fun cosineDistance(other: Expr): Function = Function.CosineDistance(this, other) - infix fun euclideanDistance(other: Expr): Function = Function.EuclideanDistance(this, other) - infix fun hasAncestor(ancestor: Expr): Function = Function.HasAncestor(this, ancestor) - - fun function(name: String, params: Map?): Function = Function.Raw(name, params) - - fun withAlias(alias: String): ExprAsAlias { - return ExprAsAlias(this, alias) + infix fun equal(other: Expr) = Function.Equal(this, other) + infix fun notEqual(other: Expr) = Function.NotEqual(this, other) + infix fun greaterThan(other: Expr)= Function.GreaterThan(this, other) + infix fun greaterThanOrEqual(other: Expr)= Function.GreaterThanOrEqual(this, other) + fun inAny(vararg other: Expr)= Function.In(this, other.toList()) + infix fun lessThan(other: Expr)= Function.LessThan(this, other) + infix fun lessThanOrEqual(other: Expr)= Function.LessThanOrEqual(this, other) + fun notInAny(left: Expr, vararg other: Expr)= Function.NotIn(left, other.toList()) + + + fun exists()= Function.Exists(this as Field) + + infix fun mapGet(key: String)= Function.MapGet(this, key) + infix fun arrayContains(element: Expr)= Function.ArrayContains(this, element) + fun arrayContainsAny(vararg elements: Expr)= Function.ArrayContainsAny(this, elements.toList()) + fun isNaN()= Function.IsNaN(this) + fun isNull()= Function.IsNull(this) + fun sum()= Function.Sum(this) + fun avg()= Function.Avg(this) + fun count()= Function.Count(this) + infix fun cosineDistance(other: Expr)= Function.CosineDistance(this, other) + infix fun cosineDistance(other: DoubleArray)= Function.CosineDistance(this, Constant.of(other)) + infix fun euclideanDistance(other: Expr)= Function.EuclideanDistance(this, other) + infix fun euclideanDistance(other: DoubleArray)= Function.EuclideanDistance(this, Constant.of(other)) + infix fun hasAncestor(ancestor: Expr)= Function.HasAncestor(this, ancestor) + + fun asAlias(alias: String): ExprAsAlias = ExprAsAlias(this, alias) + + companion object { + @JvmStatic + fun equal(left: Expr, right: Expr) = Function.Equal(left, right) + + @JvmStatic + fun notEqual(left: Expr, right: Expr)= Function.NotEqual(left, right) + + @JvmStatic + fun greaterThan(left: Expr, right: Expr)= Function.GreaterThan(left, right) + + @JvmStatic + fun greaterThanOrEqual(left: Expr, right: Expr)= Function.GreaterThanOrEqual(left, right) + + @JvmStatic + fun inAny(left: Expr, vararg other: Expr)= Function.In(left, other.toList()) + + @JvmStatic + fun lessThan(left: Expr, right: Expr)= Function.LessThan(left, right) + + @JvmStatic + fun lessThanOrEqual(left: Expr, right: Expr)= Function.LessThanOrEqual(left, right) + + @JvmStatic + fun notInAny(left: Expr, vararg other: Expr)= Function.NotIn(left, other.toList()) + + @JvmStatic + fun and(left: Function.FilterCondition, right: Function.FilterCondition)= Function.And(listOf(left, right)) + + @JvmStatic + fun and(left: Function.FilterCondition, vararg other: Function.FilterCondition)= Function.And(listOf(left) + other.toList()) + + @JvmStatic + fun or(left: Function.FilterCondition, right: Function.FilterCondition)= Function.Or(listOf(left, right)) + + @JvmStatic + fun or(left: Function.FilterCondition, vararg other: Function.FilterCondition)= Function.Or(listOf(left) + other.toList()) + + @JvmStatic + fun exists(expr: Field)= Function.Exists(expr) + + @JvmStatic + fun mapGet(expr: Expr, key: String)= Function.MapGet(expr, key) + + @JvmStatic + fun arrayContains(expr: Expr, element: Expr)= Function.ArrayContains(expr, element) + + @JvmStatic + fun arrayContainsAny(expr: Expr, vararg elements: Expr)= Function.ArrayContainsAny(expr, elements.toList()) + + @JvmStatic + fun isNaN(expr: Expr)= Function.IsNaN(expr) + + @JvmStatic + fun isNull(expr: Expr)= Function.IsNull(expr) + + @JvmStatic + fun not(expr: Expr)= Function.Not(expr) + + @JvmStatic + fun sum(expr: Expr)= Function.Sum(expr) + + @JvmStatic + fun avg(expr: Expr)= Function.Avg(expr) + + @JvmStatic + fun count(expr: Expr)= Function.Count(expr) + + @JvmStatic + fun cosineDistance(expr: Expr, other: Expr)= Function.CosineDistance(expr, other) + + @JvmStatic + fun cosineDistance(expr: Expr, other: DoubleArray)= Function.CosineDistance(expr, Constant.of(other)) + + @JvmStatic + fun euclideanDistance(expr: Expr, other: Expr)= Function.EuclideanDistance(expr, other) + + @JvmStatic + fun euclideanDistance(expr: Expr, other: DoubleArray)= Function.EuclideanDistance(expr, Constant.of(other)) + + @JvmStatic + fun hasAncestor(expr: Expr, ancestor: Expr)= Function.HasAncestor(expr, ancestor) + + @JvmStatic + fun asAlias(expr: Expr, alias: String): ExprAsAlias = ExprAsAlias(expr, alias) + + @JvmStatic + fun function(name: String, params: Map?)= Function.Raw(name, params) } + } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt index 40e8d376f..985a8522f 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt @@ -4,29 +4,21 @@ import com.google.cloud.firestore.Pipeline interface Operation {} -data class Field internal constructor(val path: String): Projectable { - companion object { - fun of(path: String): Field { - return Field(path) - } - } -} - class Database(): Operation data class Collection(val path: String): Operation data class CollectionGroup(val path: String): Operation -data class Project(val projections: Map): Operation -data class AddFields(val additions: Map): Operation -data class RemoveFields(val removals: List): Operation -data class Filter(val condition: Expr.Function.ProducingBoolean): Operation +data class Project(val projections: Map): Operation +data class AddFields(val additions: Map): Operation +data class RemoveFields(val removals: List): Operation +data class Filter(val condition: Expr.Function.FilterCondition): Operation data class Offset(val offset: Int): Operation data class Limit(val limit: Int): Operation data class UnionWith(val pipeline: Pipeline, val distinct: Boolean): Operation -data class Group(val fields: Map, val accumulators: Map): Operation +data class Group(val fields: Map, val accumulators: Map): Operation -data class FindNearest(val property: Field, +data class FindNearest(val property: Expr.Field, val vector: Array, val options: FindNearestOptions): Operation { enum class Similarity { @@ -35,19 +27,19 @@ data class FindNearest(val property: Field, DOT_PRODUCT } - data class FindNearestOptions(val similarity: Similarity, val limit: Long, val output: Field) {} + data class FindNearestOptions(val similarity: Similarity, val limit: Long, val output: Expr.Field) {} } sealed interface JoinCondition { data class Expression(val expr: Expr): JoinCondition - data class Using(val fields: Set): JoinCondition + data class Using(val fields: Set): JoinCondition } data class Join(val type: Type, val condition: JoinCondition, - val alias: Field, + val alias: Expr.Field, val otherPipeline: Pipeline, - val otherAlias: Field): Operation { + val otherAlias: Expr.Field): Operation { enum class Type { CROSS, INNER, @@ -59,9 +51,9 @@ data class Join(val type: Type, data class SemiJoin(val type: Type, val condition: JoinCondition, - val alias: Field, + val alias: Expr.Field, val otherPipeline: Pipeline, - val otherAlias: Field): Operation { + val otherAlias: Expr.Field): Operation { enum class Type { LEFT_SEMI, RIGHT_SEMI, @@ -91,7 +83,7 @@ data class Sort(val orders: List, } } -data class Unnest(val mode: Mode, val field: Field): Operation { +data class Unnest(val mode: Mode, val field: Expr.Field): Operation { enum class Mode { FULL_REPLACE, MERGE_PREFER_NEST, diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java new file mode 100644 index 000000000..5b1d69006 --- /dev/null +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -0,0 +1,99 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.firestore.it; + + +import static com.google.cloud.firestore.pipeline.Expr.avg; +import static com.google.cloud.firestore.pipeline.Expr.not; +import static com.google.cloud.firestore.pipeline.Expr.or; + +import com.google.cloud.firestore.Firestore; +import com.google.cloud.firestore.FirestoreOptions; +import com.google.cloud.firestore.Pipeline; +import com.google.cloud.firestore.pipeline.Expr; +import com.google.cloud.firestore.pipeline.Expr.Constant; +import com.google.cloud.firestore.pipeline.Expr.Field; +import com.google.cloud.firestore.pipeline.Fields; +import org.junit.Before; +import org.junit.Test; + +public class ITPipelineTest { + + protected Firestore firestore; + + @Before + public void before() throws Exception { + firestore = FirestoreOptions.newBuilder().build().getService(); + } + + @Test + public void pipelineWithDb() throws Exception { + Pipeline p = Pipeline.entireDatabase(); + } + + @Test + public void projections() throws Exception { + Pipeline p = Pipeline.from("coll1") + .project( + Field.of("foo"), + Constant.of("emptyValue").asAlias("emptyField"), + Field.of("embedding").cosineDistance(new double[]{1, 2, 3.0}).asAlias("distance") + ); + } + + @Test + public void addRemoveFields() throws Exception { + Pipeline p = Pipeline.from("coll1") + .addFields( + Constant.of("emptyValue").asAlias("emptyField"), + Field.of("embedding").cosineDistance(new double[]{1, 2, 3.0}).asAlias("distance") + ) + .removeFields(Field.of("emptyField")); + } + + @Test + public void filters() throws Exception { + Pipeline p = Pipeline.fromCollectionGroup("coll1") + .filter(Field.of("foo").equal(Constant.of(42))) + .filter(or(Field.of("bar").lessThan(Constant.of(100)), + Constant.of("value").equal(Field.of("key")) + )) + .filter(not(Constant.of(128).inAny(Field.of("f1"), Field.of("f2")))); + } + + @Test + public void inFilters() throws Exception { + Pipeline p = Pipeline.fromCollectionGroup("coll1") + .filter(Field.of("foo").inAny( + Constant.of(42), + Field.of("bar"))); + } + + @Test + public void groupBy() throws Exception { + Pipeline p = Pipeline.from("coll1") + .filter(Field.of("foo").inAny( + Constant.of(42), + Field.of("bar"))) + .group(Fields.of("given_name", "family_name"), + avg(Field.of("score")).toField("avg_score_1")) + // Equivalent but more fluency + .group(Fields.of("given_name", "family_name"), + Field.of("score").avg().toField("avg_score_2")) + ; + } +} diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/PipelineKTTest.kt b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/PipelineKTTest.kt new file mode 100644 index 000000000..db0aac7c5 --- /dev/null +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/PipelineKTTest.kt @@ -0,0 +1,16 @@ +package com.google.cloud.firestore.it + +import com.google.cloud.firestore.Pipeline +import com.google.cloud.firestore.pipeline.Expr +import com.google.cloud.firestore.pipeline.Expr.Companion.equal +import com.google.cloud.firestore.pipeline.Expr.Companion.or +import com.google.cloud.firestore.pipeline.Expr.Field +import com.google.cloud.firestore.pipeline.Expr.Constant + +class PipelineKTTest { + fun pipeline() { + Pipeline.from("test") + .filter(Field.of("foo").equal(Expr.Constant.of(42))) + .filter(or(Field.of("abc").lessThan(Constant.of(100)))) + } +} From c5a01a61fac8e2c094b557e1fea2bbf8807e3b27 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Tue, 20 Feb 2024 11:11:04 -0500 Subject: [PATCH 06/65] joins but nicer --- .../com/google/cloud/firestore/Pipeline.kt | 149 ++++++------------ .../cloud/firestore/pipeline/Expressions.kt | 7 +- .../cloud/firestore/pipeline/Operations.kt | 13 +- .../cloud/firestore/it/ITPipelineTest.java | 32 +++- .../cloud/firestore/it/PipelineKTTest.kt | 16 -- 5 files changed, 79 insertions(+), 138 deletions(-) delete mode 100644 google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/PipelineKTTest.kt diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 41f12d52e..767e5c0c6 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -11,7 +11,6 @@ import com.google.cloud.firestore.pipeline.Filter import com.google.cloud.firestore.pipeline.FindNearest import com.google.cloud.firestore.pipeline.Group import com.google.cloud.firestore.pipeline.Join -import com.google.cloud.firestore.pipeline.JoinCondition import com.google.cloud.firestore.pipeline.Limit import com.google.cloud.firestore.pipeline.Offset import com.google.cloud.firestore.pipeline.Operation @@ -20,13 +19,36 @@ import com.google.cloud.firestore.pipeline.Project import com.google.cloud.firestore.pipeline.Projectable import com.google.cloud.firestore.pipeline.RawOperation import com.google.cloud.firestore.pipeline.RemoveFields -import com.google.cloud.firestore.pipeline.SemiJoin import com.google.cloud.firestore.pipeline.Sort import com.google.cloud.firestore.pipeline.UnionWith import com.google.cloud.firestore.pipeline.Unnest +class GroupingPipeline internal constructor(val p: Pipeline, vararg val by: Projectable) { + fun accumulate(vararg accumulator: Expr.AccumulatorTarget): Pipeline { + // TODO: this.p.operations.add() + return this.p; + } +} + +class JoiningPipeline internal constructor(val left: Pipeline, val right: Pipeline, val join: Join.Type) { + fun on(condition: Expr.Function): Pipeline { + // TODO: this.p.operations.add() + return left; + } + + fun on(vararg field: Field): Pipeline { + // TODO: this.p.operations.add() + return left + } + + fun on(field: Fields): Pipeline { + // TODO: this.p.operations.add() + return left + } +} + class Pipeline { - private val operations: MutableList = mutableListOf() + internal val operations: MutableList = mutableListOf() private var name: String private constructor(db: Database) { @@ -61,6 +83,10 @@ class Pipeline { } } + fun fieldOf(name: String): Field { + return Field(name, this); + } + // Fluent API fun withName(name: String) { @@ -125,19 +151,19 @@ class Pipeline { return this } - fun group(by: Fields, vararg accumulators: Expr.AccumulatorTarget): Pipeline { + fun group(by: Fields): GroupingPipeline{ // operations.add(Group(fields, accumulators)) - return this + return GroupingPipeline(this, /*TODO*/) } - fun group(by: Projectable, vararg accumulators: Expr.AccumulatorTarget): Pipeline { + fun group(by: Projectable): GroupingPipeline{ // operations.add(Group(fields, accumulators)) - return this + return GroupingPipeline(this, /*TODO*/) } fun findNearest( property: Field, - vector: Array, + vector: DoubleArray, options: FindNearest.FindNearestOptions ): Pipeline { operations.add(FindNearest(property, vector, options)) @@ -145,110 +171,23 @@ class Pipeline { } fun innerJoin( - otherPipeline: Pipeline, - condition: JoinCondition, - alias: Field = Field.of(this.name), - otherAlias: Field = Field.of(otherPipeline.name) - ): Pipeline { - operations.add(Join(Join.Type.INNER, condition, alias, otherPipeline, otherAlias)) - return this - } - - fun crossJoin( - otherPipeline: Pipeline, - condition: JoinCondition, - alias: Field = Field.of(this.name), - otherAlias: Field = Field.of(otherPipeline.name) - ): Pipeline { - operations.add(Join(Join.Type.CROSS, condition, alias, otherPipeline, otherAlias)) - return this - } + otherPipeline: Pipeline + ) = JoiningPipeline(this, otherPipeline, Join.Type.INNER) + fun crossJoin(otherPipeline: Pipeline): JoiningPipeline = JoiningPipeline(this, otherPipeline, Join.Type.CROSS) - fun fullJoin( - otherPipeline: Pipeline, - condition: JoinCondition, - alias: Field = Field.of(this.name), - otherAlias: Field = Field.of(otherPipeline.name) - ): Pipeline { - operations.add(Join(Join.Type.FULL, condition, alias, otherPipeline, otherAlias)) - return this - } + fun fullJoin(otherPipeline: Pipeline): JoiningPipeline = JoiningPipeline(this, otherPipeline, Join.Type.FULL) - fun leftJoin( - otherPipeline: Pipeline, - condition: JoinCondition, - alias: Field = Field.of(this.name), - otherAlias: Field = Field.of(otherPipeline.name) - ): Pipeline { - operations.add(Join(Join.Type.LEFT, condition, alias, otherPipeline, otherAlias)) - return this - } + fun leftJoin(otherPipeline: Pipeline): JoiningPipeline = JoiningPipeline(this, otherPipeline, Join.Type.LEFT) - fun rightJoin( - otherPipeline: Pipeline, - condition: JoinCondition, - alias: Field = Field.of(this.name), - otherAlias: Field = Field.of(otherPipeline.name) - ): Pipeline { - operations.add(Join(Join.Type.RIGHT, condition, alias, otherPipeline, otherAlias)) - return this - } + fun rightJoin(otherPipeline: Pipeline): JoiningPipeline = JoiningPipeline(this, otherPipeline, Join.Type.RIGHT) - fun leftSemiJoin( - otherPipeline: Pipeline, - condition: JoinCondition, - alias: Field = Field.of(this.name), - otherAlias: Field = Field.of(otherPipeline.name) - ): Pipeline { - operations.add(SemiJoin(SemiJoin.Type.LEFT_SEMI, condition, alias, otherPipeline, otherAlias)) - return this - } + fun leftSemiJoin(otherPipeline: Pipeline): JoiningPipeline = JoiningPipeline(this, otherPipeline, Join.Type.LEFT_SEMI) - fun rightSemiJoin( - condition: JoinCondition, - alias: Field, - otherPipeline: Pipeline, - otherAlias: Field - ): Pipeline { - operations.add(SemiJoin(SemiJoin.Type.RIGHT_SEMI, condition, alias, otherPipeline, otherAlias)) - return this - } + fun rightSemiJoin(otherPipeline: Pipeline): JoiningPipeline = JoiningPipeline(this, otherPipeline, Join.Type.RIGHT_SEMI) - fun leftAntiSemiJoin( - otherPipeline: Pipeline, - condition: JoinCondition, - alias: Field = Field.of(this.name), - otherAlias: Field = Field.of(otherPipeline.name) - ): Pipeline { - operations.add( - SemiJoin( - SemiJoin.Type.LEFT_ANTI_SEMI, - condition, - alias, - otherPipeline, - otherAlias - ) - ) - return this - } + fun leftAntiSemiJoin(otherPipeline: Pipeline): JoiningPipeline = JoiningPipeline(this, otherPipeline, Join.Type.LEFT_ANTI_SEMI) - fun rightAntiSemiJoin( - otherPipeline: Pipeline, - condition: JoinCondition, - alias: Field = Field.of(this.name), - otherAlias: Field = Field.of(otherPipeline.name) - ): Pipeline { - operations.add( - SemiJoin( - SemiJoin.Type.RIGHT_ANTI_SEMI, - condition, - alias, - otherPipeline, - otherAlias - ) - ) - return this - } + fun rightAntiSemiJoin(otherPipeline: Pipeline): JoiningPipeline = JoiningPipeline(this, otherPipeline, Join.Type.RIGHT_ANTI_SEMI) fun sort( orders: List, diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index 85279024d..f99e0a9d0 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -1,5 +1,6 @@ package com.google.cloud.firestore.pipeline +import com.google.cloud.firestore.Pipeline import com.google.firestore.v1.Value interface Projectable @@ -26,13 +27,17 @@ sealed interface Expr { } } } - data class Field(val field: String): Expr, Projectable { + data class Field(val field: String, var pipeline: Pipeline? = null): Expr, Projectable { companion object { @JvmStatic fun of(path: String): Field { return Field(path) } } + + fun withPrefix(prefix: String): Field { + return this + } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt index 985a8522f..698a5c20b 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt @@ -19,7 +19,7 @@ data class UnionWith(val pipeline: Pipeline, val distinct: Boolean): Operation data class Group(val fields: Map, val accumulators: Map): Operation data class FindNearest(val property: Expr.Field, - val vector: Array, + val vector: DoubleArray, val options: FindNearestOptions): Operation { enum class Similarity { EUCLIDEAN, @@ -45,16 +45,7 @@ data class Join(val type: Type, INNER, FULL, LEFT, - RIGHT - } -} - -data class SemiJoin(val type: Type, - val condition: JoinCondition, - val alias: Expr.Field, - val otherPipeline: Pipeline, - val otherAlias: Expr.Field): Operation { - enum class Type { + RIGHT, LEFT_SEMI, RIGHT_SEMI, LEFT_ANTI_SEMI, diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 5b1d69006..91a3c23d7 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -17,6 +17,7 @@ package com.google.cloud.firestore.it; +import static com.google.cloud.firestore.pipeline.Expr.and; import static com.google.cloud.firestore.pipeline.Expr.avg; import static com.google.cloud.firestore.pipeline.Expr.not; import static com.google.cloud.firestore.pipeline.Expr.or; @@ -28,6 +29,8 @@ import com.google.cloud.firestore.pipeline.Expr.Constant; import com.google.cloud.firestore.pipeline.Expr.Field; import com.google.cloud.firestore.pipeline.Fields; +import com.google.cloud.firestore.pipeline.FindNearest.FindNearestOptions; +import com.google.cloud.firestore.pipeline.FindNearest.Similarity; import org.junit.Before; import org.junit.Test; @@ -89,11 +92,30 @@ public void groupBy() throws Exception { .filter(Field.of("foo").inAny( Constant.of(42), Field.of("bar"))) - .group(Fields.of("given_name", "family_name"), - avg(Field.of("score")).toField("avg_score_1")) + .group(Fields.of("given_name", "family_name")) + .accumulate(avg(Field.of("score")).toField("avg_score_1")) // Equivalent but more fluency - .group(Fields.of("given_name", "family_name"), - Field.of("score").avg().toField("avg_score_2")) - ; + .group(Fields.of("given_name", "family_name")) + .accumulate(Field.of("score").avg().toField("avg_score_2")); + } + + @Test + public void joins() throws Exception { + Pipeline p = Pipeline.from("coll1") + .filter(Field.of("foo").inAny( + Constant.of(42), + Field.of("bar"))); + Pipeline pipe = Pipeline.from("users") + .findNearest(Field.of("embedding"), new double[]{1.0,2.0}, + new FindNearestOptions(Similarity.COSINE, 1000, Field.of("distance"))) + .innerJoin(p) + .on(and( + Field.of("foo").equal(p.fieldOf("bar")), + p.fieldOf("requirement").greaterThan(Field.of("distance")))); + + Pipeline another = Pipeline.from("users") + .innerJoin(p) + .on(Fields.of("foo", "bar")) + .project(Field.of("*").withPrefix("left"), p.fieldOf("*").withPrefix("right")); } } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/PipelineKTTest.kt b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/PipelineKTTest.kt deleted file mode 100644 index db0aac7c5..000000000 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/PipelineKTTest.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.google.cloud.firestore.it - -import com.google.cloud.firestore.Pipeline -import com.google.cloud.firestore.pipeline.Expr -import com.google.cloud.firestore.pipeline.Expr.Companion.equal -import com.google.cloud.firestore.pipeline.Expr.Companion.or -import com.google.cloud.firestore.pipeline.Expr.Field -import com.google.cloud.firestore.pipeline.Expr.Constant - -class PipelineKTTest { - fun pipeline() { - Pipeline.from("test") - .filter(Field.of("foo").equal(Expr.Constant.of(42))) - .filter(or(Field.of("abc").lessThan(Constant.of(100)))) - } -} From 191eb44121c97d16275ce1f1d1a68506467a0ced Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Thu, 22 Feb 2024 12:03:42 -0500 Subject: [PATCH 07/65] address feedback --- .../com/google/cloud/firestore/Pipeline.kt | 78 ++++-- .../cloud/firestore/pipeline/Expressions.kt | 227 +++++++++++------- .../cloud/firestore/pipeline/Operations.kt | 113 ++++++--- .../cloud/firestore/it/ITPipelineTest.java | 49 +++- 4 files changed, 313 insertions(+), 154 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 767e5c0c6..2fde85a0a 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -5,10 +5,12 @@ import com.google.cloud.firestore.pipeline.Collection import com.google.cloud.firestore.pipeline.CollectionGroup import com.google.cloud.firestore.pipeline.Database import com.google.cloud.firestore.pipeline.Expr +import com.google.cloud.firestore.pipeline.Expr.AllFields import com.google.cloud.firestore.pipeline.Expr.Field import com.google.cloud.firestore.pipeline.Fields import com.google.cloud.firestore.pipeline.Filter import com.google.cloud.firestore.pipeline.FindNearest +import com.google.cloud.firestore.pipeline.GenericOperation import com.google.cloud.firestore.pipeline.Group import com.google.cloud.firestore.pipeline.Join import com.google.cloud.firestore.pipeline.Limit @@ -17,23 +19,26 @@ import com.google.cloud.firestore.pipeline.Operation import com.google.cloud.firestore.pipeline.Ordering import com.google.cloud.firestore.pipeline.Project import com.google.cloud.firestore.pipeline.Projectable -import com.google.cloud.firestore.pipeline.RawOperation import com.google.cloud.firestore.pipeline.RemoveFields import com.google.cloud.firestore.pipeline.Sort import com.google.cloud.firestore.pipeline.UnionWith import com.google.cloud.firestore.pipeline.Unnest class GroupingPipeline internal constructor(val p: Pipeline, vararg val by: Projectable) { - fun accumulate(vararg accumulator: Expr.AccumulatorTarget): Pipeline { + fun aggregate(vararg aggregator: Expr.AggregateorTarget): Pipeline { // TODO: this.p.operations.add() - return this.p; + return this.p } } -class JoiningPipeline internal constructor(val left: Pipeline, val right: Pipeline, val join: Join.Type) { +class JoiningPipeline internal constructor( + val left: Pipeline, + val right: Pipeline, + val join: Join.Type +) { fun on(condition: Expr.Function): Pipeline { // TODO: this.p.operations.add() - return left; + return left } fun on(vararg field: Field): Pipeline { @@ -68,7 +73,17 @@ class Pipeline { companion object { @JvmStatic - fun from(collectionName: String): Pipeline { + fun from(source: CollectionReference): Pipeline { + return Pipeline(Collection(source.path)) + } + + @JvmStatic + fun from(source: com.google.cloud.firestore.CollectionGroup): Pipeline { + return Pipeline(CollectionGroup(source.options.collectionId)) + } + + @JvmStatic + fun fromCollection(collectionName: String): Pipeline { return Pipeline(Collection(collectionName)) } @@ -78,13 +93,17 @@ class Pipeline { } @JvmStatic - fun entireDatabase(): Pipeline { + fun fromDatabase(): Pipeline { return Pipeline(Database()) } } fun fieldOf(name: String): Field { - return Field(name, this); + return Field(name, this) + } + + fun fieldOfAll(): AllFields { + return AllFields(this) } // Fluent API @@ -151,14 +170,20 @@ class Pipeline { return this } - fun group(by: Fields): GroupingPipeline{ + fun group(by: Fields): GroupingPipeline { // operations.add(Group(fields, accumulators)) - return GroupingPipeline(this, /*TODO*/) + return GroupingPipeline(this /*TODO*/) } - fun group(by: Projectable): GroupingPipeline{ + fun group(by: Projectable): GroupingPipeline { // operations.add(Group(fields, accumulators)) - return GroupingPipeline(this, /*TODO*/) + return GroupingPipeline(this /*TODO*/) + } + + fun aggregate(vararg aggregator: Expr.AggregateorTarget): Pipeline { + // operations.add(Group()) + // operations.add(aggregator) + return this } fun findNearest( @@ -173,21 +198,30 @@ class Pipeline { fun innerJoin( otherPipeline: Pipeline ) = JoiningPipeline(this, otherPipeline, Join.Type.INNER) - fun crossJoin(otherPipeline: Pipeline): JoiningPipeline = JoiningPipeline(this, otherPipeline, Join.Type.CROSS) - fun fullJoin(otherPipeline: Pipeline): JoiningPipeline = JoiningPipeline(this, otherPipeline, Join.Type.FULL) + fun crossJoin(otherPipeline: Pipeline): JoiningPipeline = + JoiningPipeline(this, otherPipeline, Join.Type.CROSS) + + fun fullJoin(otherPipeline: Pipeline): JoiningPipeline = + JoiningPipeline(this, otherPipeline, Join.Type.FULL) - fun leftJoin(otherPipeline: Pipeline): JoiningPipeline = JoiningPipeline(this, otherPipeline, Join.Type.LEFT) + fun leftJoin(otherPipeline: Pipeline): JoiningPipeline = + JoiningPipeline(this, otherPipeline, Join.Type.LEFT) - fun rightJoin(otherPipeline: Pipeline): JoiningPipeline = JoiningPipeline(this, otherPipeline, Join.Type.RIGHT) + fun rightJoin(otherPipeline: Pipeline): JoiningPipeline = + JoiningPipeline(this, otherPipeline, Join.Type.RIGHT) - fun leftSemiJoin(otherPipeline: Pipeline): JoiningPipeline = JoiningPipeline(this, otherPipeline, Join.Type.LEFT_SEMI) + fun leftSemiJoin(otherPipeline: Pipeline): JoiningPipeline = + JoiningPipeline(this, otherPipeline, Join.Type.LEFT_SEMI) - fun rightSemiJoin(otherPipeline: Pipeline): JoiningPipeline = JoiningPipeline(this, otherPipeline, Join.Type.RIGHT_SEMI) + fun rightSemiJoin(otherPipeline: Pipeline): JoiningPipeline = + JoiningPipeline(this, otherPipeline, Join.Type.RIGHT_SEMI) - fun leftAntiSemiJoin(otherPipeline: Pipeline): JoiningPipeline = JoiningPipeline(this, otherPipeline, Join.Type.LEFT_ANTI_SEMI) + fun leftAntiSemiJoin(otherPipeline: Pipeline): JoiningPipeline = + JoiningPipeline(this, otherPipeline, Join.Type.LEFT_ANTI_SEMI) - fun rightAntiSemiJoin(otherPipeline: Pipeline): JoiningPipeline = JoiningPipeline(this, otherPipeline, Join.Type.RIGHT_ANTI_SEMI) + fun rightAntiSemiJoin(otherPipeline: Pipeline): JoiningPipeline = + JoiningPipeline(this, otherPipeline, Join.Type.RIGHT_ANTI_SEMI) fun sort( orders: List, @@ -203,13 +237,13 @@ class Pipeline { return this } - fun unnest(field: Field, mode: Unnest.Mode = Unnest.Mode.FULL_REPLACE ): Pipeline { + fun unnest(field: Field, mode: Unnest.Mode = Unnest.Mode.FULL_REPLACE): Pipeline { operations.add(Unnest(mode, field)) return this } fun rawOperation(name: String, params: Map? = null): Pipeline { - operations.add(RawOperation(name, params)) + operations.add(GenericOperation(name, params)) return this } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index f99e0a9d0..8fde3349f 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -6,8 +6,9 @@ import com.google.firestore.v1.Value interface Projectable // Convenient class for internal usage -internal data class ListOfExprs(val conditions: List): Expr -internal data class ListOfConditions(val conditions: List): Expr, Expr.Function.FilterCondition {} +internal data class ListOfExprs(val conditions: List) : Expr +internal data class ListOfConditions(val conditions: List) : Expr, + Expr.Function.FilterCondition data class Fields(val fs: List) { companion object { @@ -19,7 +20,7 @@ data class Fields(val fs: List) { } sealed interface Expr { - data class Constant internal constructor(val value: Any): Expr { + data class Constant internal constructor(val value: Any) : Expr { companion object { @JvmStatic fun of(value: Any): Constant { @@ -27,28 +28,38 @@ sealed interface Expr { } } } - data class Field(val field: String, var pipeline: Pipeline? = null): Expr, Projectable { + + data class Field(val field: String, var pipeline: Pipeline? = null) : Expr, Projectable { companion object { @JvmStatic fun of(path: String): Field { return Field(path) } + + @JvmStatic + fun ofAll(): AllFields { + return AllFields() + } } + } + + data class AllFields(var pipeline: Pipeline? = null) : Expr, Projectable { - fun withPrefix(prefix: String): Field { + fun withPrefix(prefix: String): AllFields { return this } } - data class ExprAsAlias(val current: Expr, val alias: String): Expr, Projectable {} + data class ExprAsAlias(val current: Expr, val alias: String) : Expr, Projectable - data class AccumulatorTarget(val current: Function.Accumulator, val target: String): Expr, Function.Accumulator {} + data class AggregateorTarget(val current: Function.Accumulator, val target: String) : Expr, + Function.Accumulator sealed class Function(val name: String, val params: Map?) : Expr { interface FilterCondition { - infix fun and(other: FilterCondition)= Function.And(listOf(this, other)) - fun and(vararg other: FilterCondition)= Function.And(listOf(this) + other.toList()) + infix fun and(other: FilterCondition) = And(listOf(this, other)) + fun and(vararg other: FilterCondition) = And(listOf(this) + other.toList()) // Or and Not are restricted as a companion/static function // infix fun or(other: Expr)= Function.Or(listOf(this, other)) @@ -57,65 +68,110 @@ sealed interface Expr { } interface Accumulator { - fun toField(target: String) = AccumulatorTarget(this, target) + fun toField(target: String) = AggregateorTarget(this, target) } - data class Equal internal constructor(val left: Expr, val right: Expr) : Function("equal", mapOf("left" to left, "right" to right)), FilterCondition - data class NotEqual(val left: Expr, val right: Expr) : Function("not_equal", mapOf("left" to left, "right" to right)), FilterCondition - data class GreaterThan(val left: Expr, val right: Expr) : Function("greater_than", mapOf("left" to left, "right" to right)), FilterCondition - data class GreaterThanOrEqual(val left: Expr, val right: Expr) : Function("greater_than_equal", mapOf("left" to left, "right" to right)), FilterCondition - data class In(val left: Expr, val others: List) : Function("in", mapOf("left" to left, "others" to ListOfExprs(others))), FilterCondition // For 'in' - data class LessThan(val left: Expr, val right: Expr) : Function("less_than", mapOf("left" to left, "right" to right)), FilterCondition - data class LessThanOrEqual(val left: Expr, val right: Expr) : Function("less_than_equal", mapOf("left" to left, "right" to right)), FilterCondition - data class NotIn(val left: Expr, val others: List) : Function("not_in", mapOf("left" to left, "others" to ListOfExprs(others))), FilterCondition // For 'not in' - data class And(val conditions: List) : Function("and", mapOf("conditions" to ListOfConditions(conditions))), FilterCondition - data class Or(val conditions: List) : Function("or", mapOf("conditions" to ListOfConditions(conditions))), FilterCondition - data class Not(val condition: Expr) : Function("not", mapOf("condition" to condition)), FilterCondition - data class Exists(val current: Field) : Function("exists", mapOf("current" to current)), FilterCondition - - data class MapGet(val map: Expr, val key: String) : Function("map_get", mapOf("map" to map, "key" to Constant(Value.getDefaultInstance().toBuilder().setStringValue(key).build()))) - - data class ArrayContains(val array: Expr, val element: Expr) : Function("array_contains", mapOf("array" to array, "element" to element)), FilterCondition - data class ArrayContainsAny(val array: Expr, val elements: List) : Function("array_contains_any", mapOf("array" to array, "elements" to ListOfExprs(elements))), FilterCondition + data class Equal internal constructor(val left: Expr, val right: Expr) : + Function("equal", mapOf("left" to left, "right" to right)), FilterCondition + + data class NotEqual(val left: Expr, val right: Expr) : + Function("not_equal", mapOf("left" to left, "right" to right)), FilterCondition + + data class GreaterThan(val left: Expr, val right: Expr) : + Function("greater_than", mapOf("left" to left, "right" to right)), FilterCondition + + data class GreaterThanOrEqual(val left: Expr, val right: Expr) : + Function("greater_than_equal", mapOf("left" to left, "right" to right)), FilterCondition + + data class In(val left: Expr, val others: List) : + Function("in", mapOf("left" to left, "others" to ListOfExprs(others))), + FilterCondition // For 'in' + + data class LessThan(val left: Expr, val right: Expr) : + Function("less_than", mapOf("left" to left, "right" to right)), FilterCondition + + data class LessThanOrEqual(val left: Expr, val right: Expr) : + Function("less_than_equal", mapOf("left" to left, "right" to right)), FilterCondition + + data class NotIn(val left: Expr, val others: List) : + Function("not_in", mapOf("left" to left, "others" to ListOfExprs(others))), + FilterCondition // For 'not in' + + data class And(val conditions: List) : + Function("and", mapOf("conditions" to ListOfConditions(conditions))), FilterCondition + + data class Or(val conditions: List) : + Function("or", mapOf("conditions" to ListOfConditions(conditions))), FilterCondition + + data class Not(val condition: Expr) : Function("not", mapOf("condition" to condition)), + FilterCondition + + data class Exists(val current: Field) : Function("exists", mapOf("current" to current)), + FilterCondition + + data class MapGet(val map: Expr, val key: String) : Function( + "map_get", + mapOf( + "map" to map, + "key" to Constant(Value.getDefaultInstance().toBuilder().setStringValue(key).build()) + ) + ) + + data class ArrayContains(val array: Expr, val element: Expr) : + Function("array_contains", mapOf("array" to array, "element" to element)), FilterCondition + + data class ArrayContainsAny(val array: Expr, val elements: List) : + Function("array_contains_any", mapOf("array" to array, "elements" to ListOfExprs(elements))), + FilterCondition + data class IsNaN(val value: Expr) : Function("is_nan", mapOf("value" to value)), FilterCondition - data class IsNull(val value: Expr) : Function("is_null", mapOf("value" to value)), FilterCondition + data class IsNull(val value: Expr) : Function("is_null", mapOf("value" to value)), + FilterCondition data class Sum(val value: Expr) : Function("sum", mapOf("value" to value)), Accumulator data class Avg(val value: Expr) : Function("avg", mapOf("value" to value)), Accumulator data class Count(val value: Expr) : Function("count", mapOf("value" to value)), Accumulator - data class CosineDistance(val vector1: Expr, val vector2: Expr) : Function("cosine_distance", mapOf("vector1" to vector1, "vector2" to vector2)) - data class EuclideanDistance(val vector1: Expr, val vector2: Expr) : Function("euclidean_distance", mapOf("vector1" to vector1, "vector2" to vector2)) - data class HasAncestor(val child: Expr, val ancestor: Expr): Function("has_ancestor", mapOf("child" to child, "ancestor" to ancestor)), FilterCondition - data class Raw(val n: String, val ps: Map?): Function(n, ps) + data class CosineDistance(val vector1: Expr, val vector2: Expr) : + Function("cosine_distance", mapOf("vector1" to vector1, "vector2" to vector2)) + + data class EuclideanDistance(val vector1: Expr, val vector2: Expr) : + Function("euclidean_distance", mapOf("vector1" to vector1, "vector2" to vector2)) + + data class HasAncestor(val child: Expr, val ancestor: Expr) : + Function("has_ancestor", mapOf("child" to child, "ancestor" to ancestor)), FilterCondition + + data class Generic(val n: String, val ps: Map?) : Function(n, ps) } // Infix functions returning Function subclasses infix fun equal(other: Expr) = Function.Equal(this, other) infix fun notEqual(other: Expr) = Function.NotEqual(this, other) - infix fun greaterThan(other: Expr)= Function.GreaterThan(this, other) - infix fun greaterThanOrEqual(other: Expr)= Function.GreaterThanOrEqual(this, other) - fun inAny(vararg other: Expr)= Function.In(this, other.toList()) - infix fun lessThan(other: Expr)= Function.LessThan(this, other) - infix fun lessThanOrEqual(other: Expr)= Function.LessThanOrEqual(this, other) - fun notInAny(left: Expr, vararg other: Expr)= Function.NotIn(left, other.toList()) - - - fun exists()= Function.Exists(this as Field) - - infix fun mapGet(key: String)= Function.MapGet(this, key) - infix fun arrayContains(element: Expr)= Function.ArrayContains(this, element) - fun arrayContainsAny(vararg elements: Expr)= Function.ArrayContainsAny(this, elements.toList()) - fun isNaN()= Function.IsNaN(this) - fun isNull()= Function.IsNull(this) - fun sum()= Function.Sum(this) - fun avg()= Function.Avg(this) - fun count()= Function.Count(this) - infix fun cosineDistance(other: Expr)= Function.CosineDistance(this, other) - infix fun cosineDistance(other: DoubleArray)= Function.CosineDistance(this, Constant.of(other)) - infix fun euclideanDistance(other: Expr)= Function.EuclideanDistance(this, other) - infix fun euclideanDistance(other: DoubleArray)= Function.EuclideanDistance(this, Constant.of(other)) - infix fun hasAncestor(ancestor: Expr)= Function.HasAncestor(this, ancestor) + infix fun greaterThan(other: Expr) = Function.GreaterThan(this, other) + infix fun greaterThanOrEqual(other: Expr) = Function.GreaterThanOrEqual(this, other) + fun inAny(vararg other: Expr) = Function.In(this, other.toList()) + infix fun lessThan(other: Expr) = Function.LessThan(this, other) + infix fun lessThanOrEqual(other: Expr) = Function.LessThanOrEqual(this, other) + fun notInAny(left: Expr, vararg other: Expr) = Function.NotIn(left, other.toList()) + + + fun exists() = Function.Exists(this as Field) + + infix fun mapGet(key: String) = Function.MapGet(this, key) + infix fun arrayContains(element: Expr) = Function.ArrayContains(this, element) + fun arrayContainsAny(vararg elements: Expr) = Function.ArrayContainsAny(this, elements.toList()) + fun isNaN() = Function.IsNaN(this) + fun isNull() = Function.IsNull(this) + fun sum() = Function.Sum(this) + fun avg() = Function.Avg(this) + fun count() = Function.Count(this) + infix fun cosineDistance(other: Expr) = Function.CosineDistance(this, other) + infix fun cosineDistance(other: DoubleArray) = Function.CosineDistance(this, Constant.of(other)) + infix fun euclideanDistance(other: Expr) = Function.EuclideanDistance(this, other) + infix fun euclideanDistance(other: DoubleArray) = + Function.EuclideanDistance(this, Constant.of(other)) + + infix fun hasAncestor(ancestor: Expr) = Function.HasAncestor(this, ancestor) fun asAlias(alias: String): ExprAsAlias = ExprAsAlias(this, alias) @@ -124,88 +180,95 @@ sealed interface Expr { fun equal(left: Expr, right: Expr) = Function.Equal(left, right) @JvmStatic - fun notEqual(left: Expr, right: Expr)= Function.NotEqual(left, right) + fun notEqual(left: Expr, right: Expr) = Function.NotEqual(left, right) @JvmStatic - fun greaterThan(left: Expr, right: Expr)= Function.GreaterThan(left, right) + fun greaterThan(left: Expr, right: Expr) = Function.GreaterThan(left, right) @JvmStatic - fun greaterThanOrEqual(left: Expr, right: Expr)= Function.GreaterThanOrEqual(left, right) + fun greaterThanOrEqual(left: Expr, right: Expr) = Function.GreaterThanOrEqual(left, right) @JvmStatic - fun inAny(left: Expr, vararg other: Expr)= Function.In(left, other.toList()) + fun inAny(left: Expr, vararg other: Expr) = Function.In(left, other.toList()) @JvmStatic - fun lessThan(left: Expr, right: Expr)= Function.LessThan(left, right) + fun lessThan(left: Expr, right: Expr) = Function.LessThan(left, right) @JvmStatic - fun lessThanOrEqual(left: Expr, right: Expr)= Function.LessThanOrEqual(left, right) + fun lessThanOrEqual(left: Expr, right: Expr) = Function.LessThanOrEqual(left, right) @JvmStatic - fun notInAny(left: Expr, vararg other: Expr)= Function.NotIn(left, other.toList()) + fun notInAny(left: Expr, vararg other: Expr) = Function.NotIn(left, other.toList()) @JvmStatic - fun and(left: Function.FilterCondition, right: Function.FilterCondition)= Function.And(listOf(left, right)) + fun and(left: Function.FilterCondition, right: Function.FilterCondition) = + Function.And(listOf(left, right)) @JvmStatic - fun and(left: Function.FilterCondition, vararg other: Function.FilterCondition)= Function.And(listOf(left) + other.toList()) + fun and(left: Function.FilterCondition, vararg other: Function.FilterCondition) = + Function.And(listOf(left) + other.toList()) @JvmStatic - fun or(left: Function.FilterCondition, right: Function.FilterCondition)= Function.Or(listOf(left, right)) + fun or(left: Function.FilterCondition, right: Function.FilterCondition) = + Function.Or(listOf(left, right)) @JvmStatic - fun or(left: Function.FilterCondition, vararg other: Function.FilterCondition)= Function.Or(listOf(left) + other.toList()) + fun or(left: Function.FilterCondition, vararg other: Function.FilterCondition) = + Function.Or(listOf(left) + other.toList()) @JvmStatic - fun exists(expr: Field)= Function.Exists(expr) + fun exists(expr: Field) = Function.Exists(expr) @JvmStatic - fun mapGet(expr: Expr, key: String)= Function.MapGet(expr, key) + fun mapGet(expr: Expr, key: String) = Function.MapGet(expr, key) @JvmStatic - fun arrayContains(expr: Expr, element: Expr)= Function.ArrayContains(expr, element) + fun arrayContains(expr: Expr, element: Expr) = Function.ArrayContains(expr, element) @JvmStatic - fun arrayContainsAny(expr: Expr, vararg elements: Expr)= Function.ArrayContainsAny(expr, elements.toList()) + fun arrayContainsAny(expr: Expr, vararg elements: Expr) = + Function.ArrayContainsAny(expr, elements.toList()) @JvmStatic - fun isNaN(expr: Expr)= Function.IsNaN(expr) + fun isNaN(expr: Expr) = Function.IsNaN(expr) @JvmStatic - fun isNull(expr: Expr)= Function.IsNull(expr) + fun isNull(expr: Expr) = Function.IsNull(expr) @JvmStatic - fun not(expr: Expr)= Function.Not(expr) + fun not(expr: Expr) = Function.Not(expr) @JvmStatic - fun sum(expr: Expr)= Function.Sum(expr) + fun sum(expr: Expr) = Function.Sum(expr) @JvmStatic - fun avg(expr: Expr)= Function.Avg(expr) + fun avg(expr: Expr) = Function.Avg(expr) @JvmStatic - fun count(expr: Expr)= Function.Count(expr) + fun count(expr: Expr) = Function.Count(expr) @JvmStatic - fun cosineDistance(expr: Expr, other: Expr)= Function.CosineDistance(expr, other) + fun cosineDistance(expr: Expr, other: Expr) = Function.CosineDistance(expr, other) @JvmStatic - fun cosineDistance(expr: Expr, other: DoubleArray)= Function.CosineDistance(expr, Constant.of(other)) + fun cosineDistance(expr: Expr, other: DoubleArray) = + Function.CosineDistance(expr, Constant.of(other)) @JvmStatic - fun euclideanDistance(expr: Expr, other: Expr)= Function.EuclideanDistance(expr, other) + fun euclideanDistance(expr: Expr, other: Expr) = Function.EuclideanDistance(expr, other) @JvmStatic - fun euclideanDistance(expr: Expr, other: DoubleArray)= Function.EuclideanDistance(expr, Constant.of(other)) + fun euclideanDistance(expr: Expr, other: DoubleArray) = + Function.EuclideanDistance(expr, Constant.of(other)) @JvmStatic - fun hasAncestor(expr: Expr, ancestor: Expr)= Function.HasAncestor(expr, ancestor) + fun hasAncestor(expr: Expr, ancestor: Expr) = Function.HasAncestor(expr, ancestor) @JvmStatic fun asAlias(expr: Expr, alias: String): ExprAsAlias = ExprAsAlias(expr, alias) @JvmStatic - fun function(name: String, params: Map?)= Function.Raw(name, params) + fun function(name: String, params: Map?) = Function.Generic(name, params) } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt index 698a5c20b..663c39314 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt @@ -2,44 +2,69 @@ package com.google.cloud.firestore.pipeline import com.google.cloud.firestore.Pipeline -interface Operation {} - -class Database(): Operation -data class Collection(val path: String): Operation -data class CollectionGroup(val path: String): Operation - -data class Project(val projections: Map): Operation -data class AddFields(val additions: Map): Operation -data class RemoveFields(val removals: List): Operation -data class Filter(val condition: Expr.Function.FilterCondition): Operation -data class Offset(val offset: Int): Operation -data class Limit(val limit: Int): Operation -data class UnionWith(val pipeline: Pipeline, val distinct: Boolean): Operation - -data class Group(val fields: Map, val accumulators: Map): Operation - -data class FindNearest(val property: Expr.Field, - val vector: DoubleArray, - val options: FindNearestOptions): Operation { - enum class Similarity { - EUCLIDEAN, - COSINE, - DOT_PRODUCT +interface Operation + +class Database : Operation +data class Collection(val path: String) : Operation +data class CollectionGroup(val path: String) : Operation + +data class Project(val projections: Map) : Operation +data class AddFields(val additions: Map) : Operation +data class RemoveFields(val removals: List) : Operation +data class Filter(val condition: Expr.Function.FilterCondition) : Operation +data class Offset(val offset: Int) : Operation +data class Limit(val limit: Int) : Operation +data class UnionWith(val pipeline: Pipeline, val distinct: Boolean) : Operation + +data class Group(val fields: Map, val accumulators: Map) : + Operation + +data class FindNearest( + val property: Expr.Field, + val vector: DoubleArray, + val options: FindNearestOptions +) : Operation { + sealed interface Similarity { + data object Euclidean : Similarity + data object Cosine : Similarity + data object DotProduct : Similarity + + class GenericSimilarity(val name: String) : Similarity + + companion object { + @JvmStatic + fun euclidean() = Euclidean + + @JvmStatic + fun cosine() = Cosine + + @JvmStatic + fun dotProduct() = DotProduct + + @JvmStatic + fun generic(name: String) = GenericSimilarity(name) + } } - data class FindNearestOptions(val similarity: Similarity, val limit: Long, val output: Expr.Field) {} + data class FindNearestOptions( + val similarity: Similarity, + val limit: Long, + val output: Expr.Field + ) } sealed interface JoinCondition { - data class Expression(val expr: Expr): JoinCondition - data class Using(val fields: Set): JoinCondition + data class Expression(val expr: Expr) : JoinCondition + data class Using(val fields: Set) : JoinCondition } -data class Join(val type: Type, - val condition: JoinCondition, - val alias: Expr.Field, - val otherPipeline: Pipeline, - val otherAlias: Expr.Field): Operation { +data class Join( + val type: Type, + val condition: JoinCondition, + val alias: Expr.Field, + val otherPipeline: Pipeline, + val otherAlias: Expr.Field +) : Operation { enum class Type { CROSS, INNER, @@ -58,12 +83,26 @@ data class Ordering(val expr: Expr, val dir: Direction = Direction.ASC) { ASC, DESC } + + companion object { + @JvmStatic + fun of(expr: Expr, dir: Direction = Direction.ASC): Ordering { + return Ordering(expr, dir) + } + + @JvmStatic + fun of(expr: Expr): Ordering { + return Ordering(expr, Direction.ASC) + } + } } -data class Sort(val orders: List, - val density: Density = Density.UNSPECIFIED, - val truncation: Truncation = Truncation.UNSPECIFIED): Operation { - enum class Density{ +data class Sort( + val orders: List, + val density: Density = Density.UNSPECIFIED, + val truncation: Truncation = Truncation.UNSPECIFIED +) : Operation { + enum class Density { UNSPECIFIED, REQUIRED } @@ -74,7 +113,7 @@ data class Sort(val orders: List, } } -data class Unnest(val mode: Mode, val field: Expr.Field): Operation { +data class Unnest(val mode: Mode, val field: Expr.Field) : Operation { enum class Mode { FULL_REPLACE, MERGE_PREFER_NEST, @@ -82,5 +121,5 @@ data class Unnest(val mode: Mode, val field: Expr.Field): Operation { } } -data class RawOperation(val name: String, val params: Map?): Operation +data class GenericOperation(val name: String, val params: Map?) : Operation diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 91a3c23d7..61e6819ec 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -19,18 +19,20 @@ import static com.google.cloud.firestore.pipeline.Expr.and; import static com.google.cloud.firestore.pipeline.Expr.avg; +import static com.google.cloud.firestore.pipeline.Expr.cosineDistance; import static com.google.cloud.firestore.pipeline.Expr.not; import static com.google.cloud.firestore.pipeline.Expr.or; import com.google.cloud.firestore.Firestore; import com.google.cloud.firestore.FirestoreOptions; import com.google.cloud.firestore.Pipeline; -import com.google.cloud.firestore.pipeline.Expr; import com.google.cloud.firestore.pipeline.Expr.Constant; import com.google.cloud.firestore.pipeline.Expr.Field; import com.google.cloud.firestore.pipeline.Fields; import com.google.cloud.firestore.pipeline.FindNearest.FindNearestOptions; import com.google.cloud.firestore.pipeline.FindNearest.Similarity; +import com.google.cloud.firestore.pipeline.Ordering; +import com.google.cloud.firestore.pipeline.Ordering.Direction; import org.junit.Before; import org.junit.Test; @@ -45,12 +47,12 @@ public void before() throws Exception { @Test public void pipelineWithDb() throws Exception { - Pipeline p = Pipeline.entireDatabase(); + Pipeline p = Pipeline.fromDatabase(); } @Test public void projections() throws Exception { - Pipeline p = Pipeline.from("coll1") + Pipeline p = Pipeline.fromCollection("coll1") .project( Field.of("foo"), Constant.of("emptyValue").asAlias("emptyField"), @@ -60,7 +62,7 @@ public void projections() throws Exception { @Test public void addRemoveFields() throws Exception { - Pipeline p = Pipeline.from("coll1") + Pipeline p = Pipeline.fromCollection("coll1") .addFields( Constant.of("emptyValue").asAlias("emptyField"), Field.of("embedding").cosineDistance(new double[]{1, 2, 3.0}).asAlias("distance") @@ -88,34 +90,55 @@ public void inFilters() throws Exception { @Test public void groupBy() throws Exception { - Pipeline p = Pipeline.from("coll1") + Pipeline p = Pipeline.fromCollection("coll1") .filter(Field.of("foo").inAny( Constant.of(42), Field.of("bar"))) .group(Fields.of("given_name", "family_name")) - .accumulate(avg(Field.of("score")).toField("avg_score_1")) + .aggregate(avg(Field.of("score")).toField("avg_score_1")) // Equivalent but more fluency .group(Fields.of("given_name", "family_name")) - .accumulate(Field.of("score").avg().toField("avg_score_2")); + .aggregate(Field.of("score").avg().toField("avg_score_2")); + } + + @Test + public void aggregateWithoutGrouping() throws Exception { + Pipeline p = Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny( + Constant.of(42), + Field.of("bar"))) + .aggregate(avg(Field.of("score")).toField("avg_score_1")); } @Test public void joins() throws Exception { - Pipeline p = Pipeline.from("coll1") + Pipeline p = Pipeline.fromCollection("coll1") .filter(Field.of("foo").inAny( Constant.of(42), Field.of("bar"))); - Pipeline pipe = Pipeline.from("users") - .findNearest(Field.of("embedding"), new double[]{1.0,2.0}, - new FindNearestOptions(Similarity.COSINE, 1000, Field.of("distance"))) + Pipeline pipe = Pipeline.fromCollection("users") + .findNearest(Field.of("embedding"), new double[]{1.0, 2.0}, + new FindNearestOptions(Similarity.euclidean(), 1000, Field.of("distance"))) .innerJoin(p) .on(and( Field.of("foo").equal(p.fieldOf("bar")), p.fieldOf("requirement").greaterThan(Field.of("distance")))); - Pipeline another = Pipeline.from("users") + Pipeline another = Pipeline.fromCollection("users") .innerJoin(p) .on(Fields.of("foo", "bar")) - .project(Field.of("*").withPrefix("left"), p.fieldOf("*").withPrefix("right")); + .project(Field.ofAll().withPrefix("left"), p.fieldOfAll().withPrefix("right")); + } + + @Test + public void sorts() throws Exception { + Pipeline p = Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny( + Constant.of(42), + Field.of("bar"))) + .sort(Ordering.of(Field.of("rank")), + Ordering.of(cosineDistance(Field.of("embedding1"), Field.of("embedding2")), + Direction.DESC)) + .limit(100); } } From 27f274896ee534998887bfcc274266a2322d5bec Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Fri, 23 Feb 2024 11:27:54 -0500 Subject: [PATCH 08/65] pagination and others --- .../com/google/cloud/firestore/Firestore.java | 2 + .../google/cloud/firestore/FirestoreImpl.java | 5 +++ .../com/google/cloud/firestore/Pipeline.kt | 43 ++++++++++++++++++- .../cloud/firestore/pipeline/Expressions.kt | 6 +-- .../cloud/firestore/it/ITPipelineTest.java | 17 ++++++++ 5 files changed, 68 insertions(+), 5 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java index 5bbb1164a..48e977892 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java @@ -287,6 +287,8 @@ void getAll( @Nonnull FirestoreBundle.Builder bundleBuilder(@Nonnull String bundleId); + ApiFuture execute(Pipeline pipeline); + /** * Closes the gRPC channels associated with this instance and frees up their resources. This * method blocks until all channels are closed. Once this method is called, this Firestore client diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java index 1fab69e97..bc4f45bf2 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java @@ -408,6 +408,11 @@ public FirestoreBundle.Builder bundleBuilder(@Nullable String bundleId) { return new FirestoreBundle.Builder(id); } + @Override + public ApiFuture execute(Pipeline pipeline) { + return null; + } + /** Returns the name of the Firestore project associated with this client. */ @Override public String getDatabaseName() { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 2fde85a0a..d408f4e2f 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -25,7 +25,7 @@ import com.google.cloud.firestore.pipeline.UnionWith import com.google.cloud.firestore.pipeline.Unnest class GroupingPipeline internal constructor(val p: Pipeline, vararg val by: Projectable) { - fun aggregate(vararg aggregator: Expr.AggregateorTarget): Pipeline { + fun aggregate(vararg aggregator: Expr.AggregatorTarget): Pipeline { // TODO: this.p.operations.add() return this.p } @@ -52,6 +52,36 @@ class JoiningPipeline internal constructor( } } +class PaginatingPipeline internal constructor( + val p: Pipeline, + pageSize: Int, + orders: Array +) { + fun firstPage(): Pipeline { + return this.p + } + + fun page(n:Int): Pipeline { + return this.p + } + + fun startAt(result: PipelineResult): Pipeline { + return this.p + } + + fun startAfter(result: PipelineResult): Pipeline { + return this.p + } + + fun endAt(result: PipelineResult): Pipeline { + return this.p + } + + fun endBefore(result: PipelineResult): Pipeline { + return this.p + } +} + class Pipeline { internal val operations: MutableList = mutableListOf() private var name: String @@ -180,7 +210,7 @@ class Pipeline { return GroupingPipeline(this /*TODO*/) } - fun aggregate(vararg aggregator: Expr.AggregateorTarget): Pipeline { + fun aggregate(vararg aggregator: Expr.AggregatorTarget): Pipeline { // operations.add(Group()) // operations.add(aggregator) return this @@ -242,8 +272,17 @@ class Pipeline { return this } + fun paginate(pageSize: Int, vararg orders: Ordering): PaginatingPipeline { + return PaginatingPipeline(this, pageSize, orders) + } + fun rawOperation(name: String, params: Map? = null): Pipeline { operations.add(GenericOperation(name, params)) return this } } + +// placeholder for now +class PipelineResult { + +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index 8fde3349f..a45d126fd 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -53,8 +53,8 @@ sealed interface Expr { data class ExprAsAlias(val current: Expr, val alias: String) : Expr, Projectable - data class AggregateorTarget(val current: Function.Accumulator, val target: String) : Expr, - Function.Accumulator + data class AggregatorTarget(val current: Function.Accumulator, val target: String) : Expr, + Function.Accumulator sealed class Function(val name: String, val params: Map?) : Expr { interface FilterCondition { @@ -68,7 +68,7 @@ sealed interface Expr { } interface Accumulator { - fun toField(target: String) = AggregateorTarget(this, target) + fun toField(target: String) = AggregatorTarget(this, target) } data class Equal internal constructor(val left: Expr, val right: Expr) : diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 61e6819ec..7aed53e50 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -25,7 +25,9 @@ import com.google.cloud.firestore.Firestore; import com.google.cloud.firestore.FirestoreOptions; +import com.google.cloud.firestore.PaginatingPipeline; import com.google.cloud.firestore.Pipeline; +import com.google.cloud.firestore.PipelineResult; import com.google.cloud.firestore.pipeline.Expr.Constant; import com.google.cloud.firestore.pipeline.Expr.Field; import com.google.cloud.firestore.pipeline.Fields; @@ -141,4 +143,19 @@ public void sorts() throws Exception { Direction.DESC)) .limit(100); } + + @Test + public void pagination() throws Exception { + PaginatingPipeline p = Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny( + Constant.of(42), + Field.of("bar"))) + .paginate(100, Ordering.of(cosineDistance(Field.of("embedding1"), Field.of("embedding2")), + Direction.DESC)); + + PipelineResult result = firestore.execute(p.firstPage()).get(); + PipelineResult second = firestore.execute(p.startAfter(result)).get(); + // potentially expensive but possible + PipelineResult page100 = firestore.execute(p.page(100)).get(); + } } From 55ace39c57464f6b9ec1970548c1613c90e53d65 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Mon, 26 Feb 2024 10:47:16 -0500 Subject: [PATCH 09/65] minor adds --- .../main/java/com/google/cloud/firestore/Pipeline.kt | 11 +++++++++++ .../google/cloud/firestore/pipeline/Expressions.kt | 10 +--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index d408f4e2f..1c4eb16d8 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -1,5 +1,6 @@ package com.google.cloud.firestore +import com.google.api.core.ApiFuture import com.google.cloud.firestore.pipeline.AddFields import com.google.cloud.firestore.pipeline.Collection import com.google.cloud.firestore.pipeline.CollectionGroup @@ -126,6 +127,11 @@ class Pipeline { fun fromDatabase(): Pipeline { return Pipeline(Database()) } + + @JvmStatic + fun fromDocuments(vararg doc:Any): Pipeline { + return Pipeline(Database()) + } } fun fieldOf(name: String): Field { @@ -280,6 +286,11 @@ class Pipeline { operations.add(GenericOperation(name, params)) return this } + + // alternative to db.execute, more fluent. + fun execute(db: Firestore): ApiFuture? { + return null + } } // placeholder for now diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index a45d126fd..c22ed8690 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -57,15 +57,7 @@ sealed interface Expr { Function.Accumulator sealed class Function(val name: String, val params: Map?) : Expr { - interface FilterCondition { - infix fun and(other: FilterCondition) = And(listOf(this, other)) - fun and(vararg other: FilterCondition) = And(listOf(this) + other.toList()) - - // Or and Not are restricted as a companion/static function - // infix fun or(other: Expr)= Function.Or(listOf(this, other)) - // fun or(vararg other: Expr)= Function.Or(listOf(this) + other.toList()) - // infix fun not(other: Expr)= Function.Not(this) - } + interface FilterCondition interface Accumulator { fun toField(target: String) = AggregatorTarget(this, target) From 56c3a41f7ec7d6a8de93a88738f1cde10563da84 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Tue, 27 Feb 2024 10:15:10 -0500 Subject: [PATCH 10/65] adding more sugar to improve brevity --- .../cloud/firestore/pipeline/Expressions.kt | 52 ++++++++++++++++--- .../cloud/firestore/it/ITPipelineTest.java | 22 ++++++++ 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index c22ed8690..e2c25d105 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -10,7 +10,7 @@ internal data class ListOfExprs(val conditions: List) : Expr internal data class ListOfConditions(val conditions: List) : Expr, Expr.Function.FilterCondition -data class Fields(val fs: List) { +data class Fields(val fs: List) : Projectable { companion object { @JvmStatic fun of(vararg f: String): Fields { @@ -23,7 +23,27 @@ sealed interface Expr { data class Constant internal constructor(val value: Any) : Expr { companion object { @JvmStatic - fun of(value: Any): Constant { + fun of(value: String): Constant { + return Constant(value) + } + + @JvmStatic + fun of(value: Number): Constant { + return Constant(value) + } + + @JvmStatic + fun ofArray(value: Iterable): Constant { + return Constant(value) + } + + @JvmStatic + fun ofMap(value: Map): Constant { + return Constant(value) + } + + @JvmStatic + fun ofVector(value: DoubleArray): Constant { return Constant(value) } } @@ -158,10 +178,11 @@ sealed interface Expr { fun avg() = Function.Avg(this) fun count() = Function.Count(this) infix fun cosineDistance(other: Expr) = Function.CosineDistance(this, other) - infix fun cosineDistance(other: DoubleArray) = Function.CosineDistance(this, Constant.of(other)) + infix fun cosineDistance(other: DoubleArray) = + Function.CosineDistance(this, Constant.ofVector(other)) infix fun euclideanDistance(other: Expr) = Function.EuclideanDistance(this, other) infix fun euclideanDistance(other: DoubleArray) = - Function.EuclideanDistance(this, Constant.of(other)) + Function.EuclideanDistance(this, Constant.ofVector(other)) infix fun hasAncestor(ancestor: Expr) = Function.HasAncestor(this, ancestor) @@ -171,6 +192,18 @@ sealed interface Expr { @JvmStatic fun equal(left: Expr, right: Expr) = Function.Equal(left, right) + // sugar, first argument is assumed to be a field. + @JvmStatic + fun equal(left: String, right: Expr) = Function.Equal(Field.of(left), right) + + // sugar, first argument is assumed to be a field, and second argument is assumed to a simple + // scalar constant. + @JvmStatic + fun equal(left: String, right: String) = Function.Equal(Field.of(left), Constant.of(right)) + + @JvmStatic + fun equal(left: String, right: Number) = Function.Equal(Field.of(left), Constant.of(right)) + @JvmStatic fun notEqual(left: Expr, right: Expr) = Function.NotEqual(left, right) @@ -186,6 +219,13 @@ sealed interface Expr { @JvmStatic fun lessThan(left: Expr, right: Expr) = Function.LessThan(left, right) + @JvmStatic + fun lessThan(left: String, right: String) = + Function.LessThan(Field.of(left), Constant.of(right)) + + @JvmStatic + fun lessThan(left: String, right: Number) = + Function.LessThan(Field.of(left), Constant.of(right)) @JvmStatic fun lessThanOrEqual(left: Expr, right: Expr) = Function.LessThanOrEqual(left, right) @@ -244,14 +284,14 @@ sealed interface Expr { @JvmStatic fun cosineDistance(expr: Expr, other: DoubleArray) = - Function.CosineDistance(expr, Constant.of(other)) + Function.CosineDistance(expr, Constant.ofVector(other)) @JvmStatic fun euclideanDistance(expr: Expr, other: Expr) = Function.EuclideanDistance(expr, other) @JvmStatic fun euclideanDistance(expr: Expr, other: DoubleArray) = - Function.EuclideanDistance(expr, Constant.of(other)) + Function.EuclideanDistance(expr, Constant.ofVector(other)) @JvmStatic fun hasAncestor(expr: Expr, ancestor: Expr) = Function.HasAncestor(expr, ancestor) diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 7aed53e50..2878576c2 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -20,6 +20,8 @@ import static com.google.cloud.firestore.pipeline.Expr.and; import static com.google.cloud.firestore.pipeline.Expr.avg; import static com.google.cloud.firestore.pipeline.Expr.cosineDistance; +import static com.google.cloud.firestore.pipeline.Expr.equal; +import static com.google.cloud.firestore.pipeline.Expr.lessThan; import static com.google.cloud.firestore.pipeline.Expr.not; import static com.google.cloud.firestore.pipeline.Expr.or; @@ -60,6 +62,19 @@ public void projections() throws Exception { Constant.of("emptyValue").asAlias("emptyField"), Field.of("embedding").cosineDistance(new double[]{1, 2, 3.0}).asAlias("distance") ); + + // More compact + p = Pipeline.fromCollection("coll1") + .project( + Fields.of("foo", "bar", "baz"), + Constant.of(42).asAlias("emptyField") + ); + p = Pipeline.fromCollection("coll1") + // basically an addField + .project( + Field.ofAll(), + Constant.of(42).asAlias("emptyField") + ); } @Test @@ -80,6 +95,13 @@ public void filters() throws Exception { Constant.of("value").equal(Field.of("key")) )) .filter(not(Constant.of(128).inAny(Field.of("f1"), Field.of("f2")))); + + p = Pipeline.fromCollectionGroup("coll1") + .filter(equal("foo", 42)) + .filter(or(lessThan("bar", 100), + equal("key", Constant.of("value")) + )) + .filter(not(Constant.of(128).inAny(Field.of("f1"), Field.of("f2")))); } @Test From a5a90ab6a376269d1f28adb90ab57f778d92c80f Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Wed, 28 Feb 2024 09:59:37 -0500 Subject: [PATCH 11/65] address some feedback --- .../cloud/firestore/pipeline/Expressions.kt | 1 + .../cloud/firestore/pipeline/Operations.kt | 9 +++++++ .../cloud/firestore/it/ITPipelineTest.java | 26 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index e2c25d105..791d60cea 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -74,6 +74,7 @@ sealed interface Expr { data class ExprAsAlias(val current: Expr, val alias: String) : Expr, Projectable data class AggregatorTarget(val current: Function.Accumulator, val target: String) : Expr, + Projectable, Function.Accumulator sealed class Function(val name: String, val params: Map?) : Expr { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt index 663c39314..4eda29256 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt @@ -94,6 +94,15 @@ data class Ordering(val expr: Expr, val dir: Direction = Direction.ASC) { fun of(expr: Expr): Ordering { return Ordering(expr, Direction.ASC) } + + @JvmStatic + fun ascending(expr: Expr): Ordering { + return Ordering(expr, Direction.ASC) + } + @JvmStatic + fun descending(expr: Expr): Ordering { + return Ordering(expr, Direction.DESC) + } } } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 2878576c2..2e5547245 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -24,6 +24,8 @@ import static com.google.cloud.firestore.pipeline.Expr.lessThan; import static com.google.cloud.firestore.pipeline.Expr.not; import static com.google.cloud.firestore.pipeline.Expr.or; +import static com.google.cloud.firestore.pipeline.Ordering.ascending; +import static com.google.cloud.firestore.pipeline.Ordering.descending; import com.google.cloud.firestore.Firestore; import com.google.cloud.firestore.FirestoreOptions; @@ -164,6 +166,15 @@ public void sorts() throws Exception { Ordering.of(cosineDistance(Field.of("embedding1"), Field.of("embedding2")), Direction.DESC)) .limit(100); + + // equivalent but more concise. + p = Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny( + Constant.of(42), + Field.of("bar"))) + .sort(ascending(Field.of("rank")), + descending(cosineDistance(Field.of("embedding1"), Field.of("embedding2")))) + .limit(100); } @Test @@ -180,4 +191,19 @@ public void pagination() throws Exception { // potentially expensive but possible PipelineResult page100 = firestore.execute(p.page(100)).get(); } + + @Test + public void fluentAllTheWay() throws Exception { + PaginatingPipeline p = Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny( + Constant.of(42), + Field.of("bar"))) + .paginate(100, Ordering.of(cosineDistance(Field.of("embedding1"), Field.of("embedding2")), + Direction.DESC)); + + PipelineResult result = p.firstPage().execute(firestore).get(); + PipelineResult second = p.startAfter(result).execute(firestore).get(); + // potentially expensive but possible + PipelineResult page100 = p.page(100).execute(firestore).get(); + } } From 424ac43aa6595295ed5d7b4605043a064175297d Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Wed, 28 Feb 2024 10:22:46 -0500 Subject: [PATCH 12/65] support fromData --- .../src/main/java/com/google/cloud/firestore/Pipeline.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 1c4eb16d8..6684f0179 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -129,7 +129,12 @@ class Pipeline { } @JvmStatic - fun fromDocuments(vararg doc:Any): Pipeline { + fun fromDocuments(vararg docPath :String): Pipeline { + return Pipeline(Database()) + } + + @JvmStatic + fun fromData(vararg doc: Map>): Pipeline { return Pipeline(Database()) } } From 4d8a20567a5c1eda4a89eb465508eca03f62b3b9 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Thu, 7 Mar 2024 11:13:02 -0500 Subject: [PATCH 13/65] pipeline result basic --- .../com/google/cloud/firestore/Pipeline.kt | 158 +++++++++++++- .../cloud/firestore/it/ITPipelineTest.java | 197 +++++++++--------- 2 files changed, 255 insertions(+), 100 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 6684f0179..8e45f046c 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -1,6 +1,7 @@ package com.google.cloud.firestore import com.google.api.core.ApiFuture +import com.google.cloud.Timestamp import com.google.cloud.firestore.pipeline.AddFields import com.google.cloud.firestore.pipeline.Collection import com.google.cloud.firestore.pipeline.CollectionGroup @@ -24,6 +25,13 @@ import com.google.cloud.firestore.pipeline.RemoveFields import com.google.cloud.firestore.pipeline.Sort import com.google.cloud.firestore.pipeline.UnionWith import com.google.cloud.firestore.pipeline.Unnest +import com.google.common.base.Preconditions +import com.google.firestore.v1.Document +import com.google.firestore.v1.Value +import com.google.firestore.v1.Write +import java.util.Date +import java.util.Objects +import javax.annotation.Nonnull class GroupingPipeline internal constructor(val p: Pipeline, vararg val by: Projectable) { fun aggregate(vararg aggregator: Expr.AggregatorTarget): Pipeline { @@ -298,7 +306,153 @@ class Pipeline { } } -// placeholder for now -class PipelineResult { +data class PipelineResult // Elevated access level for mocking. +internal constructor( + private val rpcContext: FirestoreRpcContext<*>, + val reference: DocumentReference?, + val protoFields: Map?, + val readTime: Timestamp?, + val updateTime: Timestamp?, + val createTime: Timestamp? +) { + val id: String? + get() = reference?.id + + fun valid(): Boolean { + return protoFields != null + } + + val data: Map? + /** + * Returns the fields of the document as a Map or null if the document doesn't exist. Field values + * will be converted to their native Java representation. + * + * @return The fields of the document as a Map or null if the document doesn't exist. + */ + get() { + if (protoFields == null) { + return null + } + + val decodedFields: MutableMap = HashMap() + for ((key, value) in protoFields) { + val decodedValue = UserDataConverter.decodeValue(rpcContext, value) + decodedFields[key] = decodedValue + } + return decodedFields + } + + /** + * Returns the contents of the result converted to a POJO or null if the document doesn't exist. + * + * @param valueType The Java class to create + * @return The contents of the result in an object of type T or null if the document doesn't + * exist. + */ + fun toObject(@Nonnull valueType: Class): T? { + val data = data + return if (data == null) null else CustomClassMapper.convertToCustomClass( + data, valueType, + reference + ) + } + + /** + * Returns whether or not the field exists in the result. Returns false if the result does not + * exist. + * + * @param field the path to the field. + * @return true iff the field exists. + */ + fun contains(field: String): Boolean { + return contains(FieldPath.fromDotSeparatedString(field)) + } + + /** + * Returns whether or not the field exists in the result. Returns false if the result is invalid. + * + * @param fieldPath the path to the field. + * @return true iff the field exists. + */ + fun contains(fieldPath: FieldPath): Boolean { + return this.extractField(fieldPath) != null + } + + fun get(field: String): Any? { + return get(FieldPath.fromDotSeparatedString(field)) + } + + fun get(field: String?, valueType: Class): T? { + return get(FieldPath.fromDotSeparatedString(field), valueType) + } + + fun get(fieldPath: FieldPath): Any? { + val value = extractField(fieldPath) ?: return null + + return UserDataConverter.decodeValue(rpcContext, value) + } + + fun get(fieldPath: FieldPath, valueType: Class): T? { + val data = get(fieldPath) + return if (data == null) null else CustomClassMapper.convertToCustomClass( + data, valueType, + reference + ) + } + + fun extractField(fieldPath: FieldPath): Value? { + var value: Value? = null + + if (protoFields != null) { + val components: Iterator = fieldPath.segments.iterator() + value = protoFields[components.next()] + + while (value != null && components.hasNext()) { + if (value.valueTypeCase != Value.ValueTypeCase.MAP_VALUE) { + return null + } + value = value.mapValue.getFieldsOrDefault(components.next(), null) + } + } + + return value + } + + fun getBoolean(field: String): Boolean? { + return get(field) as Boolean? + } + + fun getDouble(field: String): Double? { + val number = get(field) as Number? + return number?.toDouble() + } + + fun getString(field: String): String? { + return get(field) as String? + } + + fun getLong(field: String): Long? { + val number = get(field) as Number? + return number?.toLong() + } + + fun getDate(field: String): Date? { + val timestamp = getTimestamp(field) + return timestamp?.toDate() + } + + fun getTimestamp(field: String): Timestamp? { + return get(field) as Timestamp? + } + + fun getBlob(field: String): Blob? { + return get(field) as Blob? + } + + fun getGeoPoint(field: String): GeoPoint? { + return get(field) as GeoPoint? + } + val isEmpty: Boolean + get() = protoFields == null || protoFields.isEmpty() } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 2e5547245..ac0b4f5ad 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -16,7 +16,6 @@ package com.google.cloud.firestore.it; - import static com.google.cloud.firestore.pipeline.Expr.and; import static com.google.cloud.firestore.pipeline.Expr.avg; import static com.google.cloud.firestore.pipeline.Expr.cosineDistance; @@ -58,133 +57,133 @@ public void pipelineWithDb() throws Exception { @Test public void projections() throws Exception { - Pipeline p = Pipeline.fromCollection("coll1") - .project( - Field.of("foo"), - Constant.of("emptyValue").asAlias("emptyField"), - Field.of("embedding").cosineDistance(new double[]{1, 2, 3.0}).asAlias("distance") - ); + Pipeline p = + Pipeline.fromCollection("coll1") + .project( + Field.of("foo"), + Constant.of("emptyValue").asAlias("emptyField"), + Field.of("embedding").cosineDistance(new double[] {1, 2, 3.0}).asAlias("distance")); // More compact - p = Pipeline.fromCollection("coll1") - .project( - Fields.of("foo", "bar", "baz"), - Constant.of(42).asAlias("emptyField") - ); - p = Pipeline.fromCollection("coll1") - // basically an addField - .project( - Field.ofAll(), - Constant.of(42).asAlias("emptyField") - ); + p = + Pipeline.fromCollection("coll1") + .project(Fields.of("foo", "bar", "baz"), Constant.of(42).asAlias("emptyField")); + p = + Pipeline.fromCollection("coll1") + // basically an addField + .project(Field.ofAll(), Constant.of(42).asAlias("emptyField")); } @Test public void addRemoveFields() throws Exception { - Pipeline p = Pipeline.fromCollection("coll1") - .addFields( - Constant.of("emptyValue").asAlias("emptyField"), - Field.of("embedding").cosineDistance(new double[]{1, 2, 3.0}).asAlias("distance") - ) - .removeFields(Field.of("emptyField")); + Pipeline p = + Pipeline.fromCollection("coll1") + .addFields( + Constant.of("emptyValue").asAlias("emptyField"), + Field.of("embedding").cosineDistance(new double[] {1, 2, 3.0}).asAlias("distance")) + .removeFields(Field.of("emptyField")); } @Test public void filters() throws Exception { - Pipeline p = Pipeline.fromCollectionGroup("coll1") - .filter(Field.of("foo").equal(Constant.of(42))) - .filter(or(Field.of("bar").lessThan(Constant.of(100)), - Constant.of("value").equal(Field.of("key")) - )) - .filter(not(Constant.of(128).inAny(Field.of("f1"), Field.of("f2")))); - - p = Pipeline.fromCollectionGroup("coll1") - .filter(equal("foo", 42)) - .filter(or(lessThan("bar", 100), - equal("key", Constant.of("value")) - )) - .filter(not(Constant.of(128).inAny(Field.of("f1"), Field.of("f2")))); + Pipeline p = + Pipeline.fromCollectionGroup("coll1") + .filter(Field.of("foo").equal(Constant.of(42))) + .filter( + or( + Field.of("bar").lessThan(Constant.of(100)), + Constant.of("value").equal(Field.of("key")))) + .filter(not(Constant.of(128).inAny(Field.of("f1"), Field.of("f2")))); + + p = + Pipeline.fromCollectionGroup("coll1") + .filter(equal("foo", 42)) + .filter(or(lessThan("bar", 100), equal("key", Constant.of("value")))) + .filter(not(Constant.of(128).inAny(Field.of("f1"), Field.of("f2")))); } @Test public void inFilters() throws Exception { - Pipeline p = Pipeline.fromCollectionGroup("coll1") - .filter(Field.of("foo").inAny( - Constant.of(42), - Field.of("bar"))); + Pipeline p = + Pipeline.fromCollectionGroup("coll1") + .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))); } @Test public void groupBy() throws Exception { - Pipeline p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny( - Constant.of(42), - Field.of("bar"))) - .group(Fields.of("given_name", "family_name")) - .aggregate(avg(Field.of("score")).toField("avg_score_1")) - // Equivalent but more fluency - .group(Fields.of("given_name", "family_name")) - .aggregate(Field.of("score").avg().toField("avg_score_2")); + Pipeline p = + Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) + .group(Fields.of("given_name", "family_name")) + .aggregate(avg(Field.of("score")).toField("avg_score_1")) + // Equivalent but more fluency + .group(Fields.of("given_name", "family_name")) + .aggregate(Field.of("score").avg().toField("avg_score_2")); } @Test public void aggregateWithoutGrouping() throws Exception { - Pipeline p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny( - Constant.of(42), - Field.of("bar"))) - .aggregate(avg(Field.of("score")).toField("avg_score_1")); + Pipeline p = + Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) + .aggregate(avg(Field.of("score")).toField("avg_score_1")); } @Test public void joins() throws Exception { - Pipeline p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny( - Constant.of(42), - Field.of("bar"))); - Pipeline pipe = Pipeline.fromCollection("users") - .findNearest(Field.of("embedding"), new double[]{1.0, 2.0}, - new FindNearestOptions(Similarity.euclidean(), 1000, Field.of("distance"))) - .innerJoin(p) - .on(and( - Field.of("foo").equal(p.fieldOf("bar")), - p.fieldOf("requirement").greaterThan(Field.of("distance")))); - - Pipeline another = Pipeline.fromCollection("users") - .innerJoin(p) - .on(Fields.of("foo", "bar")) - .project(Field.ofAll().withPrefix("left"), p.fieldOfAll().withPrefix("right")); + Pipeline p = + Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))); + Pipeline pipe = + Pipeline.fromCollection("users") + .findNearest( + Field.of("embedding"), + new double[] {1.0, 2.0}, + new FindNearestOptions(Similarity.euclidean(), 1000, Field.of("distance"))) + .innerJoin(p) + .on( + and( + Field.of("foo").equal(p.fieldOf("bar")), + p.fieldOf("requirement").greaterThan(Field.of("distance")))); + + Pipeline another = + Pipeline.fromCollection("users") + .innerJoin(p) + .on(Fields.of("foo", "bar")) + .project(Field.ofAll().withPrefix("left"), p.fieldOfAll().withPrefix("right")); } @Test public void sorts() throws Exception { - Pipeline p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny( - Constant.of(42), - Field.of("bar"))) - .sort(Ordering.of(Field.of("rank")), - Ordering.of(cosineDistance(Field.of("embedding1"), Field.of("embedding2")), - Direction.DESC)) - .limit(100); + Pipeline p = + Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) + .sort( + Ordering.of(Field.of("rank")), + Ordering.of( + cosineDistance(Field.of("embedding1"), Field.of("embedding2")), Direction.DESC)) + .limit(100); // equivalent but more concise. - p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny( - Constant.of(42), - Field.of("bar"))) - .sort(ascending(Field.of("rank")), - descending(cosineDistance(Field.of("embedding1"), Field.of("embedding2")))) - .limit(100); + p = + Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) + .sort( + ascending(Field.of("rank")), + descending(cosineDistance(Field.of("embedding1"), Field.of("embedding2")))) + .limit(100); } @Test public void pagination() throws Exception { - PaginatingPipeline p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny( - Constant.of(42), - Field.of("bar"))) - .paginate(100, Ordering.of(cosineDistance(Field.of("embedding1"), Field.of("embedding2")), - Direction.DESC)); + PaginatingPipeline p = + Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) + .paginate( + 100, + Ordering.of( + cosineDistance(Field.of("embedding1"), Field.of("embedding2")), + Direction.DESC)); PipelineResult result = firestore.execute(p.firstPage()).get(); PipelineResult second = firestore.execute(p.startAfter(result)).get(); @@ -194,12 +193,14 @@ public void pagination() throws Exception { @Test public void fluentAllTheWay() throws Exception { - PaginatingPipeline p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny( - Constant.of(42), - Field.of("bar"))) - .paginate(100, Ordering.of(cosineDistance(Field.of("embedding1"), Field.of("embedding2")), - Direction.DESC)); + PaginatingPipeline p = + Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) + .paginate( + 100, + Ordering.of( + cosineDistance(Field.of("embedding1"), Field.of("embedding2")), + Direction.DESC)); PipelineResult result = p.firstPage().execute(firestore).get(); PipelineResult second = p.startAfter(result).execute(firestore).get(); From 9119b95da6f3912bfc97e7f3bfbdcf4a16aeb831 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Thu, 7 Mar 2024 13:41:15 -0500 Subject: [PATCH 14/65] execute --- .../com/google/cloud/firestore/Pipeline.kt | 168 +----------------- .../google/cloud/firestore/PipelineResult.kt | 159 +++++++++++++++++ 2 files changed, 166 insertions(+), 161 deletions(-) create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 8e45f046c..9a732da0e 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -1,7 +1,8 @@ package com.google.cloud.firestore import com.google.api.core.ApiFuture -import com.google.cloud.Timestamp +import com.google.api.core.ApiFutures +import com.google.api.gax.rpc.ApiStreamObserver import com.google.cloud.firestore.pipeline.AddFields import com.google.cloud.firestore.pipeline.Collection import com.google.cloud.firestore.pipeline.CollectionGroup @@ -25,13 +26,6 @@ import com.google.cloud.firestore.pipeline.RemoveFields import com.google.cloud.firestore.pipeline.Sort import com.google.cloud.firestore.pipeline.UnionWith import com.google.cloud.firestore.pipeline.Unnest -import com.google.common.base.Preconditions -import com.google.firestore.v1.Document -import com.google.firestore.v1.Value -import com.google.firestore.v1.Write -import java.util.Date -import java.util.Objects -import javax.annotation.Nonnull class GroupingPipeline internal constructor(val p: Pipeline, vararg val by: Projectable) { fun aggregate(vararg aggregator: Expr.AggregatorTarget): Pipeline { @@ -295,164 +289,16 @@ class Pipeline { return PaginatingPipeline(this, pageSize, orders) } - fun rawOperation(name: String, params: Map? = null): Pipeline { + fun genericOperation(name: String, params: Map? = null): Pipeline { operations.add(GenericOperation(name, params)) return this } - // alternative to db.execute, more fluent. - fun execute(db: Firestore): ApiFuture? { - return null - } -} - -data class PipelineResult // Elevated access level for mocking. -internal constructor( - private val rpcContext: FirestoreRpcContext<*>, - val reference: DocumentReference?, - val protoFields: Map?, - val readTime: Timestamp?, - val updateTime: Timestamp?, - val createTime: Timestamp? -) { - val id: String? - get() = reference?.id - - fun valid(): Boolean { - return protoFields != null - } - - val data: Map? - /** - * Returns the fields of the document as a Map or null if the document doesn't exist. Field values - * will be converted to their native Java representation. - * - * @return The fields of the document as a Map or null if the document doesn't exist. - */ - get() { - if (protoFields == null) { - return null - } - - val decodedFields: MutableMap = HashMap() - for ((key, value) in protoFields) { - val decodedValue = UserDataConverter.decodeValue(rpcContext, value) - decodedFields[key] = decodedValue - } - return decodedFields - } - - /** - * Returns the contents of the result converted to a POJO or null if the document doesn't exist. - * - * @param valueType The Java class to create - * @return The contents of the result in an object of type T or null if the document doesn't - * exist. - */ - fun toObject(@Nonnull valueType: Class): T? { - val data = data - return if (data == null) null else CustomClassMapper.convertToCustomClass( - data, valueType, - reference - ) + fun execute(db: Firestore): ApiFuture> { + return ApiFutures.immediateFuture(listOf(PipelineResult()).iterator()) } - /** - * Returns whether or not the field exists in the result. Returns false if the result does not - * exist. - * - * @param field the path to the field. - * @return true iff the field exists. - */ - fun contains(field: String): Boolean { - return contains(FieldPath.fromDotSeparatedString(field)) + fun execute(db: Firestore, observer: ApiStreamObserver): Unit { } - - /** - * Returns whether or not the field exists in the result. Returns false if the result is invalid. - * - * @param fieldPath the path to the field. - * @return true iff the field exists. - */ - fun contains(fieldPath: FieldPath): Boolean { - return this.extractField(fieldPath) != null - } - - fun get(field: String): Any? { - return get(FieldPath.fromDotSeparatedString(field)) - } - - fun get(field: String?, valueType: Class): T? { - return get(FieldPath.fromDotSeparatedString(field), valueType) - } - - fun get(fieldPath: FieldPath): Any? { - val value = extractField(fieldPath) ?: return null - - return UserDataConverter.decodeValue(rpcContext, value) - } - - fun get(fieldPath: FieldPath, valueType: Class): T? { - val data = get(fieldPath) - return if (data == null) null else CustomClassMapper.convertToCustomClass( - data, valueType, - reference - ) - } - - fun extractField(fieldPath: FieldPath): Value? { - var value: Value? = null - - if (protoFields != null) { - val components: Iterator = fieldPath.segments.iterator() - value = protoFields[components.next()] - - while (value != null && components.hasNext()) { - if (value.valueTypeCase != Value.ValueTypeCase.MAP_VALUE) { - return null - } - value = value.mapValue.getFieldsOrDefault(components.next(), null) - } - } - - return value - } - - fun getBoolean(field: String): Boolean? { - return get(field) as Boolean? - } - - fun getDouble(field: String): Double? { - val number = get(field) as Number? - return number?.toDouble() - } - - fun getString(field: String): String? { - return get(field) as String? - } - - fun getLong(field: String): Long? { - val number = get(field) as Number? - return number?.toLong() - } - - fun getDate(field: String): Date? { - val timestamp = getTimestamp(field) - return timestamp?.toDate() - } - - fun getTimestamp(field: String): Timestamp? { - return get(field) as Timestamp? - } - - fun getBlob(field: String): Blob? { - return get(field) as Blob? - } - - fun getGeoPoint(field: String): GeoPoint? { - return get(field) as GeoPoint? - } - - val isEmpty: Boolean - get() = protoFields == null || protoFields.isEmpty() } + diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt new file mode 100644 index 000000000..6dae35e11 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt @@ -0,0 +1,159 @@ +package com.google.cloud.firestore + +import com.google.cloud.Timestamp +import com.google.firestore.v1.Value +import java.util.Date +import javax.annotation.Nonnull + +data class PipelineResult // Elevated access level for mocking. +internal constructor( + private val rpcContext: FirestoreRpcContext<*>?, + val reference: DocumentReference?, + val protoFields: Map?, + val readTime: Timestamp?, + val updateTime: Timestamp?, + val createTime: Timestamp? +) { + constructor() : this(null, null, null, null, null, null) + + val id: String? + get() = reference?.id + + fun valid(): Boolean { + return protoFields != null + } + + val data: Map? + /** + * Returns the fields of the document as a Map or null if the document doesn't exist. Field values + * will be converted to their native Java representation. + * + * @return The fields of the document as a Map or null if the document doesn't exist. + */ + get() { + if (protoFields == null) { + return null + } + + val decodedFields: MutableMap = HashMap() + for ((key, value) in protoFields) { + val decodedValue = UserDataConverter.decodeValue(rpcContext, value) + decodedFields[key] = decodedValue + } + return decodedFields + } + + /** + * Returns the contents of the result converted to a POJO or null if the document doesn't exist. + * + * @param valueType The Java class to create + * @return The contents of the result in an object of type T or null if the document doesn't + * exist. + */ + fun toObject(@Nonnull valueType: Class): T? { + val data = data + return if (data == null) null else CustomClassMapper.convertToCustomClass( + data, valueType, + reference + ) + } + + /** + * Returns whether or not the field exists in the result. Returns false if the result does not + * exist. + * + * @param field the path to the field. + * @return true iff the field exists. + */ + fun contains(field: String): Boolean { + return contains(FieldPath.fromDotSeparatedString(field)) + } + + /** + * Returns whether or not the field exists in the result. Returns false if the result is invalid. + * + * @param fieldPath the path to the field. + * @return true iff the field exists. + */ + fun contains(fieldPath: FieldPath): Boolean { + return this.extractField(fieldPath) != null + } + + fun get(field: String): Any? { + return get(FieldPath.fromDotSeparatedString(field)) + } + + fun get(field: String?, valueType: Class): T? { + return get(FieldPath.fromDotSeparatedString(field), valueType) + } + + fun get(fieldPath: FieldPath): Any? { + val value = extractField(fieldPath) ?: return null + + return UserDataConverter.decodeValue(rpcContext, value) + } + + fun get(fieldPath: FieldPath, valueType: Class): T? { + val data = get(fieldPath) + return if (data == null) null else CustomClassMapper.convertToCustomClass( + data, valueType, + reference + ) + } + + fun extractField(fieldPath: FieldPath): Value? { + var value: Value? = null + + if (protoFields != null) { + val components: Iterator = fieldPath.segments.iterator() + value = protoFields[components.next()] + + while (value != null && components.hasNext()) { + if (value.valueTypeCase != Value.ValueTypeCase.MAP_VALUE) { + return null + } + value = value.mapValue.getFieldsOrDefault(components.next(), null) + } + } + + return value + } + + fun getBoolean(field: String): Boolean? { + return get(field) as Boolean? + } + + fun getDouble(field: String): Double? { + val number = get(field) as Number? + return number?.toDouble() + } + + fun getString(field: String): String? { + return get(field) as String? + } + + fun getLong(field: String): Long? { + val number = get(field) as Number? + return number?.toLong() + } + + fun getDate(field: String): Date? { + val timestamp = getTimestamp(field) + return timestamp?.toDate() + } + + fun getTimestamp(field: String): Timestamp? { + return get(field) as Timestamp? + } + + fun getBlob(field: String): Blob? { + return get(field) as Blob? + } + + fun getGeoPoint(field: String): GeoPoint? { + return get(field) as GeoPoint? + } + + val isEmpty: Boolean + get() = protoFields == null || protoFields.isEmpty() +} From 3aa73de8069f7b24b1c2bbaf753089a80c7e2b33 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Mon, 11 Mar 2024 11:42:52 -0400 Subject: [PATCH 15/65] fixing compilation error and add some high level comments --- .../com/google/cloud/firestore/Firestore.java | 3 +- .../google/cloud/firestore/FirestoreImpl.java | 3 +- .../com/google/cloud/firestore/Pipeline.kt | 31 +++++++++++++++++++ .../cloud/firestore/it/ITPipelineTest.java | 13 ++++---- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java index 48e977892..1b925057d 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java @@ -24,6 +24,7 @@ import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import kotlin.collections.Iterator; /** Represents a Firestore Database and is the entry point for all Firestore operations */ @InternalExtensionOnly @@ -287,7 +288,7 @@ void getAll( @Nonnull FirestoreBundle.Builder bundleBuilder(@Nonnull String bundleId); - ApiFuture execute(Pipeline pipeline); + ApiFuture> execute(Pipeline pipeline); /** * Closes the gRPC channels associated with this instance and frees up their resources. This diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java index bc4f45bf2..e1ff9d964 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java @@ -48,6 +48,7 @@ import java.util.Random; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import kotlin.collections.Iterator; import org.threeten.bp.Duration; /** @@ -409,7 +410,7 @@ public FirestoreBundle.Builder bundleBuilder(@Nullable String bundleId) { } @Override - public ApiFuture execute(Pipeline pipeline) { + public ApiFuture> execute(Pipeline pipeline) { return null; } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 9a732da0e..48a7da3b3 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -85,6 +85,37 @@ class PaginatingPipeline internal constructor( } } +/** + * The Pipeline class provides a flexible and expressive framework for building complex data transformation + * and query pipelines for Firestore. + * + * A pipeline takes data sources such as Firestore collections, collection groups, or even in-memory data, and + * applies a series of operations that are chained together, each operation takes the output from the last + * operation (or the data source) and produces an output for the next operation (or as the final output of the pipeline). + * + * Usage Examples: + * + * **1. Projecting Specific Fields and Renaming:** + * ```java + * Pipeline pipeline = Pipeline.fromCollection("users") + * // Select 'name' and 'email' fields, create 'userAge' which is renamed from field 'age'. + * .project(Fields.of("name", "email"), Field.of("age").asAlias("userAge")) + * ``` + * + * **2. Filtering and Sorting:** + * ```java + * Pipeline pipeline = Pipeline.fromCollectionGroup("reviews") + * .filter(Field.of("rating").greaterThan(Expr.Constant.of(3))) // High ratings + * .sort(Ordering.of("timestamp").descending()); + * ``` + * + * **3. Aggregation with Grouping:** + * ```java + * Pipeline pipeline = Pipeline.fromCollection("orders") + * .group(Field.of("customerId")) + * .aggregate(count(Field.of("orderId")).asAlias("orderCount")); + * ``` + */ class Pipeline { internal val operations: MutableList = mutableListOf() private var name: String diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index ac0b4f5ad..7ab2af51e 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -38,6 +38,7 @@ import com.google.cloud.firestore.pipeline.FindNearest.Similarity; import com.google.cloud.firestore.pipeline.Ordering; import com.google.cloud.firestore.pipeline.Ordering.Direction; +import java.util.Iterator; import org.junit.Before; import org.junit.Test; @@ -185,10 +186,10 @@ public void pagination() throws Exception { cosineDistance(Field.of("embedding1"), Field.of("embedding2")), Direction.DESC)); - PipelineResult result = firestore.execute(p.firstPage()).get(); - PipelineResult second = firestore.execute(p.startAfter(result)).get(); + Iterator result = firestore.execute(p.firstPage()).get(); + Iterator second = firestore.execute(p.startAfter(result.next())).get(); // potentially expensive but possible - PipelineResult page100 = firestore.execute(p.page(100)).get(); + Iterator page100 = firestore.execute(p.page(100)).get(); } @Test @@ -202,9 +203,9 @@ public void fluentAllTheWay() throws Exception { cosineDistance(Field.of("embedding1"), Field.of("embedding2")), Direction.DESC)); - PipelineResult result = p.firstPage().execute(firestore).get(); - PipelineResult second = p.startAfter(result).execute(firestore).get(); + Iterator result = p.firstPage().execute(firestore).get(); + Iterator second = p.startAfter(result.next()).execute(firestore).get(); // potentially expensive but possible - PipelineResult page100 = p.page(100).execute(firestore).get(); + Iterator page100 = p.page(100).execute(firestore).get(); } } From b5837916cb7114f4d7f2e8c52bf1e2cd682d5779 Mon Sep 17 00:00:00 2001 From: wuandy Date: Mon, 11 Mar 2024 18:55:39 +0000 Subject: [PATCH 16/65] setup nix for idx --- .idx/.gitignore | 2 ++ .idx/dev.nix | 17 +++++++++++++++++ .vscode/settings.json | 3 +++ 3 files changed, 22 insertions(+) create mode 100644 .idx/.gitignore create mode 100644 .idx/dev.nix create mode 100644 .vscode/settings.json diff --git a/.idx/.gitignore b/.idx/.gitignore new file mode 100644 index 000000000..96be05fb6 --- /dev/null +++ b/.idx/.gitignore @@ -0,0 +1,2 @@ + +gc/ diff --git a/.idx/dev.nix b/.idx/dev.nix new file mode 100644 index 000000000..90de3c080 --- /dev/null +++ b/.idx/dev.nix @@ -0,0 +1,17 @@ +{ pkgs, ... }: { + + # Which nixpkgs channel to use. + channel = "stable-23.11"; # or "unstable" + + # Use https://search.nixos.org/packages to find packages + packages = [ + pkgs.jdk11 # Or jdk8, jdk17, etc. - match your project's requirements + pkgs.maven + pkgs.kotlin + ]; + + # Sets environment variables in the workspace + env = { + SOME_ENV_VAR = "hello"; + }; +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..7b016a89f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.compile.nullAnalysis.mode": "automatic" +} \ No newline at end of file From 7216745f7733719ebfff30b1e141cba130b525cc Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Mon, 11 Mar 2024 14:57:24 -0400 Subject: [PATCH 17/65] tweaks --- .../src/main/java/com/google/cloud/firestore/Pipeline.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 48a7da3b3..6816412bf 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -93,6 +93,9 @@ class PaginatingPipeline internal constructor( * applies a series of operations that are chained together, each operation takes the output from the last * operation (or the data source) and produces an output for the next operation (or as the final output of the pipeline). * + * NOTE: the chained operations are not a prescription of exactly how Firestore will execute the pipeline, + * instead Firestore only guarantee the result is the same as if the chained operations are executed in order. + * * Usage Examples: * * **1. Projecting Specific Fields and Renaming:** From c46601f96f870b876174d8a15c908dc1e510c1b8 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Thu, 7 Mar 2024 11:13:02 -0500 Subject: [PATCH 18/65] pipeline result basic --- .../com/google/cloud/firestore/Pipeline.kt | 158 +++++++++++++- .../cloud/firestore/it/ITPipelineTest.java | 197 +++++++++--------- 2 files changed, 255 insertions(+), 100 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 6684f0179..8e45f046c 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -1,6 +1,7 @@ package com.google.cloud.firestore import com.google.api.core.ApiFuture +import com.google.cloud.Timestamp import com.google.cloud.firestore.pipeline.AddFields import com.google.cloud.firestore.pipeline.Collection import com.google.cloud.firestore.pipeline.CollectionGroup @@ -24,6 +25,13 @@ import com.google.cloud.firestore.pipeline.RemoveFields import com.google.cloud.firestore.pipeline.Sort import com.google.cloud.firestore.pipeline.UnionWith import com.google.cloud.firestore.pipeline.Unnest +import com.google.common.base.Preconditions +import com.google.firestore.v1.Document +import com.google.firestore.v1.Value +import com.google.firestore.v1.Write +import java.util.Date +import java.util.Objects +import javax.annotation.Nonnull class GroupingPipeline internal constructor(val p: Pipeline, vararg val by: Projectable) { fun aggregate(vararg aggregator: Expr.AggregatorTarget): Pipeline { @@ -298,7 +306,153 @@ class Pipeline { } } -// placeholder for now -class PipelineResult { +data class PipelineResult // Elevated access level for mocking. +internal constructor( + private val rpcContext: FirestoreRpcContext<*>, + val reference: DocumentReference?, + val protoFields: Map?, + val readTime: Timestamp?, + val updateTime: Timestamp?, + val createTime: Timestamp? +) { + val id: String? + get() = reference?.id + + fun valid(): Boolean { + return protoFields != null + } + + val data: Map? + /** + * Returns the fields of the document as a Map or null if the document doesn't exist. Field values + * will be converted to their native Java representation. + * + * @return The fields of the document as a Map or null if the document doesn't exist. + */ + get() { + if (protoFields == null) { + return null + } + + val decodedFields: MutableMap = HashMap() + for ((key, value) in protoFields) { + val decodedValue = UserDataConverter.decodeValue(rpcContext, value) + decodedFields[key] = decodedValue + } + return decodedFields + } + + /** + * Returns the contents of the result converted to a POJO or null if the document doesn't exist. + * + * @param valueType The Java class to create + * @return The contents of the result in an object of type T or null if the document doesn't + * exist. + */ + fun toObject(@Nonnull valueType: Class): T? { + val data = data + return if (data == null) null else CustomClassMapper.convertToCustomClass( + data, valueType, + reference + ) + } + + /** + * Returns whether or not the field exists in the result. Returns false if the result does not + * exist. + * + * @param field the path to the field. + * @return true iff the field exists. + */ + fun contains(field: String): Boolean { + return contains(FieldPath.fromDotSeparatedString(field)) + } + + /** + * Returns whether or not the field exists in the result. Returns false if the result is invalid. + * + * @param fieldPath the path to the field. + * @return true iff the field exists. + */ + fun contains(fieldPath: FieldPath): Boolean { + return this.extractField(fieldPath) != null + } + + fun get(field: String): Any? { + return get(FieldPath.fromDotSeparatedString(field)) + } + + fun get(field: String?, valueType: Class): T? { + return get(FieldPath.fromDotSeparatedString(field), valueType) + } + + fun get(fieldPath: FieldPath): Any? { + val value = extractField(fieldPath) ?: return null + + return UserDataConverter.decodeValue(rpcContext, value) + } + + fun get(fieldPath: FieldPath, valueType: Class): T? { + val data = get(fieldPath) + return if (data == null) null else CustomClassMapper.convertToCustomClass( + data, valueType, + reference + ) + } + + fun extractField(fieldPath: FieldPath): Value? { + var value: Value? = null + + if (protoFields != null) { + val components: Iterator = fieldPath.segments.iterator() + value = protoFields[components.next()] + + while (value != null && components.hasNext()) { + if (value.valueTypeCase != Value.ValueTypeCase.MAP_VALUE) { + return null + } + value = value.mapValue.getFieldsOrDefault(components.next(), null) + } + } + + return value + } + + fun getBoolean(field: String): Boolean? { + return get(field) as Boolean? + } + + fun getDouble(field: String): Double? { + val number = get(field) as Number? + return number?.toDouble() + } + + fun getString(field: String): String? { + return get(field) as String? + } + + fun getLong(field: String): Long? { + val number = get(field) as Number? + return number?.toLong() + } + + fun getDate(field: String): Date? { + val timestamp = getTimestamp(field) + return timestamp?.toDate() + } + + fun getTimestamp(field: String): Timestamp? { + return get(field) as Timestamp? + } + + fun getBlob(field: String): Blob? { + return get(field) as Blob? + } + + fun getGeoPoint(field: String): GeoPoint? { + return get(field) as GeoPoint? + } + val isEmpty: Boolean + get() = protoFields == null || protoFields.isEmpty() } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 2e5547245..ac0b4f5ad 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -16,7 +16,6 @@ package com.google.cloud.firestore.it; - import static com.google.cloud.firestore.pipeline.Expr.and; import static com.google.cloud.firestore.pipeline.Expr.avg; import static com.google.cloud.firestore.pipeline.Expr.cosineDistance; @@ -58,133 +57,133 @@ public void pipelineWithDb() throws Exception { @Test public void projections() throws Exception { - Pipeline p = Pipeline.fromCollection("coll1") - .project( - Field.of("foo"), - Constant.of("emptyValue").asAlias("emptyField"), - Field.of("embedding").cosineDistance(new double[]{1, 2, 3.0}).asAlias("distance") - ); + Pipeline p = + Pipeline.fromCollection("coll1") + .project( + Field.of("foo"), + Constant.of("emptyValue").asAlias("emptyField"), + Field.of("embedding").cosineDistance(new double[] {1, 2, 3.0}).asAlias("distance")); // More compact - p = Pipeline.fromCollection("coll1") - .project( - Fields.of("foo", "bar", "baz"), - Constant.of(42).asAlias("emptyField") - ); - p = Pipeline.fromCollection("coll1") - // basically an addField - .project( - Field.ofAll(), - Constant.of(42).asAlias("emptyField") - ); + p = + Pipeline.fromCollection("coll1") + .project(Fields.of("foo", "bar", "baz"), Constant.of(42).asAlias("emptyField")); + p = + Pipeline.fromCollection("coll1") + // basically an addField + .project(Field.ofAll(), Constant.of(42).asAlias("emptyField")); } @Test public void addRemoveFields() throws Exception { - Pipeline p = Pipeline.fromCollection("coll1") - .addFields( - Constant.of("emptyValue").asAlias("emptyField"), - Field.of("embedding").cosineDistance(new double[]{1, 2, 3.0}).asAlias("distance") - ) - .removeFields(Field.of("emptyField")); + Pipeline p = + Pipeline.fromCollection("coll1") + .addFields( + Constant.of("emptyValue").asAlias("emptyField"), + Field.of("embedding").cosineDistance(new double[] {1, 2, 3.0}).asAlias("distance")) + .removeFields(Field.of("emptyField")); } @Test public void filters() throws Exception { - Pipeline p = Pipeline.fromCollectionGroup("coll1") - .filter(Field.of("foo").equal(Constant.of(42))) - .filter(or(Field.of("bar").lessThan(Constant.of(100)), - Constant.of("value").equal(Field.of("key")) - )) - .filter(not(Constant.of(128).inAny(Field.of("f1"), Field.of("f2")))); - - p = Pipeline.fromCollectionGroup("coll1") - .filter(equal("foo", 42)) - .filter(or(lessThan("bar", 100), - equal("key", Constant.of("value")) - )) - .filter(not(Constant.of(128).inAny(Field.of("f1"), Field.of("f2")))); + Pipeline p = + Pipeline.fromCollectionGroup("coll1") + .filter(Field.of("foo").equal(Constant.of(42))) + .filter( + or( + Field.of("bar").lessThan(Constant.of(100)), + Constant.of("value").equal(Field.of("key")))) + .filter(not(Constant.of(128).inAny(Field.of("f1"), Field.of("f2")))); + + p = + Pipeline.fromCollectionGroup("coll1") + .filter(equal("foo", 42)) + .filter(or(lessThan("bar", 100), equal("key", Constant.of("value")))) + .filter(not(Constant.of(128).inAny(Field.of("f1"), Field.of("f2")))); } @Test public void inFilters() throws Exception { - Pipeline p = Pipeline.fromCollectionGroup("coll1") - .filter(Field.of("foo").inAny( - Constant.of(42), - Field.of("bar"))); + Pipeline p = + Pipeline.fromCollectionGroup("coll1") + .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))); } @Test public void groupBy() throws Exception { - Pipeline p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny( - Constant.of(42), - Field.of("bar"))) - .group(Fields.of("given_name", "family_name")) - .aggregate(avg(Field.of("score")).toField("avg_score_1")) - // Equivalent but more fluency - .group(Fields.of("given_name", "family_name")) - .aggregate(Field.of("score").avg().toField("avg_score_2")); + Pipeline p = + Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) + .group(Fields.of("given_name", "family_name")) + .aggregate(avg(Field.of("score")).toField("avg_score_1")) + // Equivalent but more fluency + .group(Fields.of("given_name", "family_name")) + .aggregate(Field.of("score").avg().toField("avg_score_2")); } @Test public void aggregateWithoutGrouping() throws Exception { - Pipeline p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny( - Constant.of(42), - Field.of("bar"))) - .aggregate(avg(Field.of("score")).toField("avg_score_1")); + Pipeline p = + Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) + .aggregate(avg(Field.of("score")).toField("avg_score_1")); } @Test public void joins() throws Exception { - Pipeline p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny( - Constant.of(42), - Field.of("bar"))); - Pipeline pipe = Pipeline.fromCollection("users") - .findNearest(Field.of("embedding"), new double[]{1.0, 2.0}, - new FindNearestOptions(Similarity.euclidean(), 1000, Field.of("distance"))) - .innerJoin(p) - .on(and( - Field.of("foo").equal(p.fieldOf("bar")), - p.fieldOf("requirement").greaterThan(Field.of("distance")))); - - Pipeline another = Pipeline.fromCollection("users") - .innerJoin(p) - .on(Fields.of("foo", "bar")) - .project(Field.ofAll().withPrefix("left"), p.fieldOfAll().withPrefix("right")); + Pipeline p = + Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))); + Pipeline pipe = + Pipeline.fromCollection("users") + .findNearest( + Field.of("embedding"), + new double[] {1.0, 2.0}, + new FindNearestOptions(Similarity.euclidean(), 1000, Field.of("distance"))) + .innerJoin(p) + .on( + and( + Field.of("foo").equal(p.fieldOf("bar")), + p.fieldOf("requirement").greaterThan(Field.of("distance")))); + + Pipeline another = + Pipeline.fromCollection("users") + .innerJoin(p) + .on(Fields.of("foo", "bar")) + .project(Field.ofAll().withPrefix("left"), p.fieldOfAll().withPrefix("right")); } @Test public void sorts() throws Exception { - Pipeline p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny( - Constant.of(42), - Field.of("bar"))) - .sort(Ordering.of(Field.of("rank")), - Ordering.of(cosineDistance(Field.of("embedding1"), Field.of("embedding2")), - Direction.DESC)) - .limit(100); + Pipeline p = + Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) + .sort( + Ordering.of(Field.of("rank")), + Ordering.of( + cosineDistance(Field.of("embedding1"), Field.of("embedding2")), Direction.DESC)) + .limit(100); // equivalent but more concise. - p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny( - Constant.of(42), - Field.of("bar"))) - .sort(ascending(Field.of("rank")), - descending(cosineDistance(Field.of("embedding1"), Field.of("embedding2")))) - .limit(100); + p = + Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) + .sort( + ascending(Field.of("rank")), + descending(cosineDistance(Field.of("embedding1"), Field.of("embedding2")))) + .limit(100); } @Test public void pagination() throws Exception { - PaginatingPipeline p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny( - Constant.of(42), - Field.of("bar"))) - .paginate(100, Ordering.of(cosineDistance(Field.of("embedding1"), Field.of("embedding2")), - Direction.DESC)); + PaginatingPipeline p = + Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) + .paginate( + 100, + Ordering.of( + cosineDistance(Field.of("embedding1"), Field.of("embedding2")), + Direction.DESC)); PipelineResult result = firestore.execute(p.firstPage()).get(); PipelineResult second = firestore.execute(p.startAfter(result)).get(); @@ -194,12 +193,14 @@ public void pagination() throws Exception { @Test public void fluentAllTheWay() throws Exception { - PaginatingPipeline p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny( - Constant.of(42), - Field.of("bar"))) - .paginate(100, Ordering.of(cosineDistance(Field.of("embedding1"), Field.of("embedding2")), - Direction.DESC)); + PaginatingPipeline p = + Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) + .paginate( + 100, + Ordering.of( + cosineDistance(Field.of("embedding1"), Field.of("embedding2")), + Direction.DESC)); PipelineResult result = p.firstPage().execute(firestore).get(); PipelineResult second = p.startAfter(result).execute(firestore).get(); From 99e906776ac457412ae3566ac865707e7cb282e2 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Thu, 7 Mar 2024 13:41:15 -0500 Subject: [PATCH 19/65] execute --- .../com/google/cloud/firestore/Pipeline.kt | 168 +----------------- .../google/cloud/firestore/PipelineResult.kt | 159 +++++++++++++++++ 2 files changed, 166 insertions(+), 161 deletions(-) create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 8e45f046c..9a732da0e 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -1,7 +1,8 @@ package com.google.cloud.firestore import com.google.api.core.ApiFuture -import com.google.cloud.Timestamp +import com.google.api.core.ApiFutures +import com.google.api.gax.rpc.ApiStreamObserver import com.google.cloud.firestore.pipeline.AddFields import com.google.cloud.firestore.pipeline.Collection import com.google.cloud.firestore.pipeline.CollectionGroup @@ -25,13 +26,6 @@ import com.google.cloud.firestore.pipeline.RemoveFields import com.google.cloud.firestore.pipeline.Sort import com.google.cloud.firestore.pipeline.UnionWith import com.google.cloud.firestore.pipeline.Unnest -import com.google.common.base.Preconditions -import com.google.firestore.v1.Document -import com.google.firestore.v1.Value -import com.google.firestore.v1.Write -import java.util.Date -import java.util.Objects -import javax.annotation.Nonnull class GroupingPipeline internal constructor(val p: Pipeline, vararg val by: Projectable) { fun aggregate(vararg aggregator: Expr.AggregatorTarget): Pipeline { @@ -295,164 +289,16 @@ class Pipeline { return PaginatingPipeline(this, pageSize, orders) } - fun rawOperation(name: String, params: Map? = null): Pipeline { + fun genericOperation(name: String, params: Map? = null): Pipeline { operations.add(GenericOperation(name, params)) return this } - // alternative to db.execute, more fluent. - fun execute(db: Firestore): ApiFuture? { - return null - } -} - -data class PipelineResult // Elevated access level for mocking. -internal constructor( - private val rpcContext: FirestoreRpcContext<*>, - val reference: DocumentReference?, - val protoFields: Map?, - val readTime: Timestamp?, - val updateTime: Timestamp?, - val createTime: Timestamp? -) { - val id: String? - get() = reference?.id - - fun valid(): Boolean { - return protoFields != null - } - - val data: Map? - /** - * Returns the fields of the document as a Map or null if the document doesn't exist. Field values - * will be converted to their native Java representation. - * - * @return The fields of the document as a Map or null if the document doesn't exist. - */ - get() { - if (protoFields == null) { - return null - } - - val decodedFields: MutableMap = HashMap() - for ((key, value) in protoFields) { - val decodedValue = UserDataConverter.decodeValue(rpcContext, value) - decodedFields[key] = decodedValue - } - return decodedFields - } - - /** - * Returns the contents of the result converted to a POJO or null if the document doesn't exist. - * - * @param valueType The Java class to create - * @return The contents of the result in an object of type T or null if the document doesn't - * exist. - */ - fun toObject(@Nonnull valueType: Class): T? { - val data = data - return if (data == null) null else CustomClassMapper.convertToCustomClass( - data, valueType, - reference - ) + fun execute(db: Firestore): ApiFuture> { + return ApiFutures.immediateFuture(listOf(PipelineResult()).iterator()) } - /** - * Returns whether or not the field exists in the result. Returns false if the result does not - * exist. - * - * @param field the path to the field. - * @return true iff the field exists. - */ - fun contains(field: String): Boolean { - return contains(FieldPath.fromDotSeparatedString(field)) + fun execute(db: Firestore, observer: ApiStreamObserver): Unit { } - - /** - * Returns whether or not the field exists in the result. Returns false if the result is invalid. - * - * @param fieldPath the path to the field. - * @return true iff the field exists. - */ - fun contains(fieldPath: FieldPath): Boolean { - return this.extractField(fieldPath) != null - } - - fun get(field: String): Any? { - return get(FieldPath.fromDotSeparatedString(field)) - } - - fun get(field: String?, valueType: Class): T? { - return get(FieldPath.fromDotSeparatedString(field), valueType) - } - - fun get(fieldPath: FieldPath): Any? { - val value = extractField(fieldPath) ?: return null - - return UserDataConverter.decodeValue(rpcContext, value) - } - - fun get(fieldPath: FieldPath, valueType: Class): T? { - val data = get(fieldPath) - return if (data == null) null else CustomClassMapper.convertToCustomClass( - data, valueType, - reference - ) - } - - fun extractField(fieldPath: FieldPath): Value? { - var value: Value? = null - - if (protoFields != null) { - val components: Iterator = fieldPath.segments.iterator() - value = protoFields[components.next()] - - while (value != null && components.hasNext()) { - if (value.valueTypeCase != Value.ValueTypeCase.MAP_VALUE) { - return null - } - value = value.mapValue.getFieldsOrDefault(components.next(), null) - } - } - - return value - } - - fun getBoolean(field: String): Boolean? { - return get(field) as Boolean? - } - - fun getDouble(field: String): Double? { - val number = get(field) as Number? - return number?.toDouble() - } - - fun getString(field: String): String? { - return get(field) as String? - } - - fun getLong(field: String): Long? { - val number = get(field) as Number? - return number?.toLong() - } - - fun getDate(field: String): Date? { - val timestamp = getTimestamp(field) - return timestamp?.toDate() - } - - fun getTimestamp(field: String): Timestamp? { - return get(field) as Timestamp? - } - - fun getBlob(field: String): Blob? { - return get(field) as Blob? - } - - fun getGeoPoint(field: String): GeoPoint? { - return get(field) as GeoPoint? - } - - val isEmpty: Boolean - get() = protoFields == null || protoFields.isEmpty() } + diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt new file mode 100644 index 000000000..6dae35e11 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt @@ -0,0 +1,159 @@ +package com.google.cloud.firestore + +import com.google.cloud.Timestamp +import com.google.firestore.v1.Value +import java.util.Date +import javax.annotation.Nonnull + +data class PipelineResult // Elevated access level for mocking. +internal constructor( + private val rpcContext: FirestoreRpcContext<*>?, + val reference: DocumentReference?, + val protoFields: Map?, + val readTime: Timestamp?, + val updateTime: Timestamp?, + val createTime: Timestamp? +) { + constructor() : this(null, null, null, null, null, null) + + val id: String? + get() = reference?.id + + fun valid(): Boolean { + return protoFields != null + } + + val data: Map? + /** + * Returns the fields of the document as a Map or null if the document doesn't exist. Field values + * will be converted to their native Java representation. + * + * @return The fields of the document as a Map or null if the document doesn't exist. + */ + get() { + if (protoFields == null) { + return null + } + + val decodedFields: MutableMap = HashMap() + for ((key, value) in protoFields) { + val decodedValue = UserDataConverter.decodeValue(rpcContext, value) + decodedFields[key] = decodedValue + } + return decodedFields + } + + /** + * Returns the contents of the result converted to a POJO or null if the document doesn't exist. + * + * @param valueType The Java class to create + * @return The contents of the result in an object of type T or null if the document doesn't + * exist. + */ + fun toObject(@Nonnull valueType: Class): T? { + val data = data + return if (data == null) null else CustomClassMapper.convertToCustomClass( + data, valueType, + reference + ) + } + + /** + * Returns whether or not the field exists in the result. Returns false if the result does not + * exist. + * + * @param field the path to the field. + * @return true iff the field exists. + */ + fun contains(field: String): Boolean { + return contains(FieldPath.fromDotSeparatedString(field)) + } + + /** + * Returns whether or not the field exists in the result. Returns false if the result is invalid. + * + * @param fieldPath the path to the field. + * @return true iff the field exists. + */ + fun contains(fieldPath: FieldPath): Boolean { + return this.extractField(fieldPath) != null + } + + fun get(field: String): Any? { + return get(FieldPath.fromDotSeparatedString(field)) + } + + fun get(field: String?, valueType: Class): T? { + return get(FieldPath.fromDotSeparatedString(field), valueType) + } + + fun get(fieldPath: FieldPath): Any? { + val value = extractField(fieldPath) ?: return null + + return UserDataConverter.decodeValue(rpcContext, value) + } + + fun get(fieldPath: FieldPath, valueType: Class): T? { + val data = get(fieldPath) + return if (data == null) null else CustomClassMapper.convertToCustomClass( + data, valueType, + reference + ) + } + + fun extractField(fieldPath: FieldPath): Value? { + var value: Value? = null + + if (protoFields != null) { + val components: Iterator = fieldPath.segments.iterator() + value = protoFields[components.next()] + + while (value != null && components.hasNext()) { + if (value.valueTypeCase != Value.ValueTypeCase.MAP_VALUE) { + return null + } + value = value.mapValue.getFieldsOrDefault(components.next(), null) + } + } + + return value + } + + fun getBoolean(field: String): Boolean? { + return get(field) as Boolean? + } + + fun getDouble(field: String): Double? { + val number = get(field) as Number? + return number?.toDouble() + } + + fun getString(field: String): String? { + return get(field) as String? + } + + fun getLong(field: String): Long? { + val number = get(field) as Number? + return number?.toLong() + } + + fun getDate(field: String): Date? { + val timestamp = getTimestamp(field) + return timestamp?.toDate() + } + + fun getTimestamp(field: String): Timestamp? { + return get(field) as Timestamp? + } + + fun getBlob(field: String): Blob? { + return get(field) as Blob? + } + + fun getGeoPoint(field: String): GeoPoint? { + return get(field) as GeoPoint? + } + + val isEmpty: Boolean + get() = protoFields == null || protoFields.isEmpty() +} From f20e409df78c9fffbeb7298f38dfc0da3d934f1f Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Mon, 11 Mar 2024 11:42:52 -0400 Subject: [PATCH 20/65] fixing compilation error and add some high level comments --- .../com/google/cloud/firestore/Firestore.java | 3 +- .../google/cloud/firestore/FirestoreImpl.java | 3 +- .../com/google/cloud/firestore/Pipeline.kt | 31 +++++++++++++++++++ .../cloud/firestore/it/ITPipelineTest.java | 13 ++++---- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java index 48e977892..1b925057d 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java @@ -24,6 +24,7 @@ import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import kotlin.collections.Iterator; /** Represents a Firestore Database and is the entry point for all Firestore operations */ @InternalExtensionOnly @@ -287,7 +288,7 @@ void getAll( @Nonnull FirestoreBundle.Builder bundleBuilder(@Nonnull String bundleId); - ApiFuture execute(Pipeline pipeline); + ApiFuture> execute(Pipeline pipeline); /** * Closes the gRPC channels associated with this instance and frees up their resources. This diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java index bc4f45bf2..e1ff9d964 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java @@ -48,6 +48,7 @@ import java.util.Random; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import kotlin.collections.Iterator; import org.threeten.bp.Duration; /** @@ -409,7 +410,7 @@ public FirestoreBundle.Builder bundleBuilder(@Nullable String bundleId) { } @Override - public ApiFuture execute(Pipeline pipeline) { + public ApiFuture> execute(Pipeline pipeline) { return null; } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 9a732da0e..48a7da3b3 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -85,6 +85,37 @@ class PaginatingPipeline internal constructor( } } +/** + * The Pipeline class provides a flexible and expressive framework for building complex data transformation + * and query pipelines for Firestore. + * + * A pipeline takes data sources such as Firestore collections, collection groups, or even in-memory data, and + * applies a series of operations that are chained together, each operation takes the output from the last + * operation (or the data source) and produces an output for the next operation (or as the final output of the pipeline). + * + * Usage Examples: + * + * **1. Projecting Specific Fields and Renaming:** + * ```java + * Pipeline pipeline = Pipeline.fromCollection("users") + * // Select 'name' and 'email' fields, create 'userAge' which is renamed from field 'age'. + * .project(Fields.of("name", "email"), Field.of("age").asAlias("userAge")) + * ``` + * + * **2. Filtering and Sorting:** + * ```java + * Pipeline pipeline = Pipeline.fromCollectionGroup("reviews") + * .filter(Field.of("rating").greaterThan(Expr.Constant.of(3))) // High ratings + * .sort(Ordering.of("timestamp").descending()); + * ``` + * + * **3. Aggregation with Grouping:** + * ```java + * Pipeline pipeline = Pipeline.fromCollection("orders") + * .group(Field.of("customerId")) + * .aggregate(count(Field.of("orderId")).asAlias("orderCount")); + * ``` + */ class Pipeline { internal val operations: MutableList = mutableListOf() private var name: String diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index ac0b4f5ad..7ab2af51e 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -38,6 +38,7 @@ import com.google.cloud.firestore.pipeline.FindNearest.Similarity; import com.google.cloud.firestore.pipeline.Ordering; import com.google.cloud.firestore.pipeline.Ordering.Direction; +import java.util.Iterator; import org.junit.Before; import org.junit.Test; @@ -185,10 +186,10 @@ public void pagination() throws Exception { cosineDistance(Field.of("embedding1"), Field.of("embedding2")), Direction.DESC)); - PipelineResult result = firestore.execute(p.firstPage()).get(); - PipelineResult second = firestore.execute(p.startAfter(result)).get(); + Iterator result = firestore.execute(p.firstPage()).get(); + Iterator second = firestore.execute(p.startAfter(result.next())).get(); // potentially expensive but possible - PipelineResult page100 = firestore.execute(p.page(100)).get(); + Iterator page100 = firestore.execute(p.page(100)).get(); } @Test @@ -202,9 +203,9 @@ public void fluentAllTheWay() throws Exception { cosineDistance(Field.of("embedding1"), Field.of("embedding2")), Direction.DESC)); - PipelineResult result = p.firstPage().execute(firestore).get(); - PipelineResult second = p.startAfter(result).execute(firestore).get(); + Iterator result = p.firstPage().execute(firestore).get(); + Iterator second = p.startAfter(result.next()).execute(firestore).get(); // potentially expensive but possible - PipelineResult page100 = p.page(100).execute(firestore).get(); + Iterator page100 = p.page(100).execute(firestore).get(); } } From 742d3c4035b3640973712c445d5995a78d7c7cf7 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Mon, 11 Mar 2024 14:57:24 -0400 Subject: [PATCH 21/65] tweaks --- .../src/main/java/com/google/cloud/firestore/Pipeline.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 48a7da3b3..6816412bf 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -93,6 +93,9 @@ class PaginatingPipeline internal constructor( * applies a series of operations that are chained together, each operation takes the output from the last * operation (or the data source) and produces an output for the next operation (or as the final output of the pipeline). * + * NOTE: the chained operations are not a prescription of exactly how Firestore will execute the pipeline, + * instead Firestore only guarantee the result is the same as if the chained operations are executed in order. + * * Usage Examples: * * **1. Projecting Specific Fields and Renaming:** From 7c67e997c119b191c732d55a8d0d22d7c8f94d6e Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Mon, 11 Mar 2024 15:46:03 -0400 Subject: [PATCH 22/65] fix errors --- .../java/com/google/cloud/firestore/pipeline/Expressions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index 791d60cea..a5bee8ace 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -165,7 +165,7 @@ sealed interface Expr { fun inAny(vararg other: Expr) = Function.In(this, other.toList()) infix fun lessThan(other: Expr) = Function.LessThan(this, other) infix fun lessThanOrEqual(other: Expr) = Function.LessThanOrEqual(this, other) - fun notInAny(left: Expr, vararg other: Expr) = Function.NotIn(left, other.toList()) + fun notInAny(vararg other: Expr) = Function.NotIn(this, other.toList()) fun exists() = Function.Exists(this as Field) From ba521a0678b45c9df5065d0b8ebe75e7a21de5ac Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Tue, 12 Mar 2024 10:54:15 -0400 Subject: [PATCH 23/65] fix errors --- .../com/google/cloud/firestore/Firestore.java | 2 +- .../google/cloud/firestore/FirestoreImpl.java | 21 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java index 1b925057d..ac552d80d 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java @@ -21,10 +21,10 @@ import com.google.api.core.InternalExtensionOnly; import com.google.api.gax.rpc.ApiStreamObserver; import com.google.cloud.Service; +import java.util.Iterator; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import kotlin.collections.Iterator; /** Represents a Firestore Database and is the entry point for all Firestore operations */ @InternalExtensionOnly diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java index e1ff9d964..32ef27b6b 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java @@ -18,6 +18,7 @@ import com.google.api.core.ApiClock; import com.google.api.core.ApiFuture; +import com.google.api.core.ApiFutures; import com.google.api.core.NanoClock; import com.google.api.core.SettableApiFuture; import com.google.api.gax.rpc.ApiStreamObserver; @@ -29,6 +30,8 @@ import com.google.api.gax.rpc.StreamController; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.Timestamp; +import com.google.cloud.firestore.Transaction.AsyncFunction; +import com.google.cloud.firestore.Transaction.Function; import com.google.cloud.firestore.spi.v1.FirestoreRpc; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; @@ -43,12 +46,12 @@ import java.security.SecureRandom; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Random; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import kotlin.collections.Iterator; import org.threeten.bp.Duration; /** @@ -365,7 +368,7 @@ public CollectionGroup collectionGroup(@Nonnull final String collectionId) { @Nonnull @Override - public ApiFuture runTransaction(@Nonnull final Transaction.Function updateFunction) { + public ApiFuture runTransaction(@Nonnull final Function updateFunction) { return runAsyncTransaction( new TransactionAsyncAdapter<>(updateFunction), TransactionOptions.create()); } @@ -373,7 +376,7 @@ public ApiFuture runTransaction(@Nonnull final Transaction.Function up @Nonnull @Override public ApiFuture runTransaction( - @Nonnull final Transaction.Function updateFunction, + @Nonnull final Function updateFunction, @Nonnull TransactionOptions transactionOptions) { return runAsyncTransaction(new TransactionAsyncAdapter<>(updateFunction), transactionOptions); } @@ -381,14 +384,14 @@ public ApiFuture runTransaction( @Nonnull @Override public ApiFuture runAsyncTransaction( - @Nonnull final Transaction.AsyncFunction updateFunction) { + @Nonnull final AsyncFunction updateFunction) { return runAsyncTransaction(updateFunction, TransactionOptions.create()); } @Nonnull @Override public ApiFuture runAsyncTransaction( - @Nonnull final Transaction.AsyncFunction updateFunction, + @Nonnull final AsyncFunction updateFunction, @Nonnull TransactionOptions transactionOptions) { TransactionRunner transactionRunner = @@ -411,7 +414,7 @@ public FirestoreBundle.Builder bundleBuilder(@Nullable String bundleId) { @Override public ApiFuture> execute(Pipeline pipeline) { - return null; + return ApiFutures.immediateFuture(null); } /** Returns the name of the Firestore project associated with this client. */ @@ -497,10 +500,10 @@ public void shutdownNow() { closed = true; } - private static class TransactionAsyncAdapter implements Transaction.AsyncFunction { - private final Transaction.Function syncFunction; + private static class TransactionAsyncAdapter implements AsyncFunction { + private final Function syncFunction; - public TransactionAsyncAdapter(Transaction.Function syncFunction) { + public TransactionAsyncAdapter(Function syncFunction) { this.syncFunction = syncFunction; } From 6ae7b13093466b861d1ee7f75d290a34752f38be Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Tue, 12 Mar 2024 16:14:52 -0400 Subject: [PATCH 24/65] Add function composition example. --- .../google/cloud/firestore/FirestoreImpl.java | 6 ++---- .../cloud/firestore/pipeline/Expressions.kt | 16 +++++++++++++++ .../cloud/firestore/it/ITPipelineTest.java | 20 +++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java index 32ef27b6b..618b27d0d 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java @@ -376,15 +376,13 @@ public ApiFuture runTransaction(@Nonnull final Function updateFunction @Nonnull @Override public ApiFuture runTransaction( - @Nonnull final Function updateFunction, - @Nonnull TransactionOptions transactionOptions) { + @Nonnull final Function updateFunction, @Nonnull TransactionOptions transactionOptions) { return runAsyncTransaction(new TransactionAsyncAdapter<>(updateFunction), transactionOptions); } @Nonnull @Override - public ApiFuture runAsyncTransaction( - @Nonnull final AsyncFunction updateFunction) { + public ApiFuture runAsyncTransaction(@Nonnull final AsyncFunction updateFunction) { return runAsyncTransaction(updateFunction, TransactionOptions.create()); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index a5bee8ace..f1ebc6d76 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -145,6 +145,11 @@ sealed interface Expr { data class Avg(val value: Expr) : Function("avg", mapOf("value" to value)), Accumulator data class Count(val value: Expr) : Function("count", mapOf("value" to value)), Accumulator + // String manipulation + data class Concat(val value: List) : Function("concat", mapOf("value" to ListOfExprs(value))) + data class Trim(val value: Expr) : Function("trim", mapOf("value" to value)) + data class ToLower(val value: Expr) : Function("toLower", mapOf("value" to value)) + data class CosineDistance(val vector1: Expr, val vector2: Expr) : Function("cosine_distance", mapOf("vector1" to vector1, "vector2" to vector2)) @@ -178,6 +183,10 @@ sealed interface Expr { fun sum() = Function.Sum(this) fun avg() = Function.Avg(this) fun count() = Function.Count(this) + + fun toLower() = Function.Count(this) + fun trim() = Function.Count(this) + infix fun cosineDistance(other: Expr) = Function.CosineDistance(this, other) infix fun cosineDistance(other: DoubleArray) = Function.CosineDistance(this, Constant.ofVector(other)) @@ -280,6 +289,13 @@ sealed interface Expr { @JvmStatic fun count(expr: Expr) = Function.Count(expr) + @JvmStatic + fun concat(vararg expr: Expr) = Function.Concat(expr.toList()) + @JvmStatic + fun trim(expr: Expr) = Function.Trim(expr) + @JvmStatic + fun toLower(expr: Expr) = Function.ToLower(expr) + @JvmStatic fun cosineDistance(expr: Expr, other: Expr) = Function.CosineDistance(expr, other) diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 7ab2af51e..3c5889e96 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -18,11 +18,14 @@ import static com.google.cloud.firestore.pipeline.Expr.and; import static com.google.cloud.firestore.pipeline.Expr.avg; +import static com.google.cloud.firestore.pipeline.Expr.concat; import static com.google.cloud.firestore.pipeline.Expr.cosineDistance; import static com.google.cloud.firestore.pipeline.Expr.equal; import static com.google.cloud.firestore.pipeline.Expr.lessThan; import static com.google.cloud.firestore.pipeline.Expr.not; import static com.google.cloud.firestore.pipeline.Expr.or; +import static com.google.cloud.firestore.pipeline.Expr.toLower; +import static com.google.cloud.firestore.pipeline.Expr.trim; import static com.google.cloud.firestore.pipeline.Ordering.ascending; import static com.google.cloud.firestore.pipeline.Ordering.descending; @@ -33,6 +36,7 @@ import com.google.cloud.firestore.PipelineResult; import com.google.cloud.firestore.pipeline.Expr.Constant; import com.google.cloud.firestore.pipeline.Expr.Field; +import com.google.cloud.firestore.pipeline.Expr.Function; import com.google.cloud.firestore.pipeline.Fields; import com.google.cloud.firestore.pipeline.FindNearest.FindNearestOptions; import com.google.cloud.firestore.pipeline.FindNearest.Similarity; @@ -208,4 +212,20 @@ public void fluentAllTheWay() throws Exception { // potentially expensive but possible Iterator page100 = p.page(100).execute(firestore).get(); } + + @Test + public void functionComposition() throws Exception { + // A normalized value by joining the first and last name, triming surrounding whitespace and + // convert to lower case + Function normalized = concat(Field.of("first_name"), Constant.of(" "), Field.of("last_name")); + normalized = trim(normalized); + normalized = toLower(normalized); + + Pipeline p = + Pipeline.fromCollection("users") + .filter( + or( + normalized.equal(Constant.of("john smith")), + normalized.equal(Constant.of("alice baker")))); + } } From c1825e0a65a3c2672baa3d68ef575bed7d66fb33 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Wed, 13 Mar 2024 14:28:08 -0400 Subject: [PATCH 25/65] build into a single jar --- google-cloud-firestore/pom.xml | 8 ++++++++ .../com/google/cloud/firestore/pipeline/Expressions.kt | 1 + 2 files changed, 9 insertions(+) diff --git a/google-cloud-firestore/pom.xml b/google-cloud-firestore/pom.xml index b065677b3..8bf510d36 100644 --- a/google-cloud-firestore/pom.xml +++ b/google-cloud-firestore/pom.xml @@ -262,6 +262,14 @@ 1.8 + + maven-assembly-plugin + + + jar-with-dependencies + + + org.apache.maven.plugins maven-compiler-plugin diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index f1ebc6d76..c8bb8ed90 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -184,6 +184,7 @@ sealed interface Expr { fun avg() = Function.Avg(this) fun count() = Function.Count(this) + fun concatWith(vararg expr: Expr) = Function.Concat(listOf(this) + expr.toList()) fun toLower() = Function.Count(this) fun trim() = Function.Count(this) From 0fe5faa26e082129357183ab2f227cf1e5895e49 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Fri, 15 Mar 2024 11:42:33 -0400 Subject: [PATCH 26/65] better aliasing for joins --- .../main/java/com/google/cloud/firestore/Pipeline.kt | 9 --------- .../com/google/cloud/firestore/pipeline/Expressions.kt | 10 ++++++++++ .../com/google/cloud/firestore/it/ITPipelineTest.java | 7 ++++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 6816412bf..cb79fed2e 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -174,15 +174,6 @@ class Pipeline { return Pipeline(Database()) } } - - fun fieldOf(name: String): Field { - return Field(name, this) - } - - fun fieldOfAll(): AllFields { - return AllFields(this) - } - // Fluent API fun withName(name: String) { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index c8bb8ed90..fe15b7eb1 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -60,6 +60,16 @@ sealed interface Expr { fun ofAll(): AllFields { return AllFields() } + + @JvmStatic + fun fromPipeline(pipeline: Pipeline, path: String): Field { + return Field(path) + } + + @JvmStatic + fun allFromPipeline(pipeline: Pipeline): AllFields { + return AllFields() + } } } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 3c5889e96..681ef3ba5 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -148,14 +148,15 @@ public void joins() throws Exception { .innerJoin(p) .on( and( - Field.of("foo").equal(p.fieldOf("bar")), - p.fieldOf("requirement").greaterThan(Field.of("distance")))); + Field.of("foo").equal(Field.fromPipeline(p, "bar")), + Field.fromPipeline(p, "requirement").greaterThan(Field.of("distance")))); Pipeline another = Pipeline.fromCollection("users") .innerJoin(p) .on(Fields.of("foo", "bar")) - .project(Field.ofAll().withPrefix("left"), p.fieldOfAll().withPrefix("right")); + .project( + Field.ofAll().withPrefix("left"), Field.allFromPipeline(p).withPrefix("right")); } @Test From 7ab3099212cc8ec145d41a7590e3db0885285150 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Mon, 18 Mar 2024 15:57:41 -0400 Subject: [PATCH 27/65] add stuff to support challenges --- .../com/google/cloud/firestore/Pipeline.kt | 13 +++-- .../cloud/firestore/pipeline/Expressions.kt | 52 +++++++++++++------ .../cloud/firestore/pipeline/Operations.kt | 4 +- .../cloud/firestore/it/ITPipelineTest.java | 1 + 4 files changed, 50 insertions(+), 20 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index cb79fed2e..6f5925c39 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -8,7 +8,6 @@ import com.google.cloud.firestore.pipeline.Collection import com.google.cloud.firestore.pipeline.CollectionGroup import com.google.cloud.firestore.pipeline.Database import com.google.cloud.firestore.pipeline.Expr -import com.google.cloud.firestore.pipeline.Expr.AllFields import com.google.cloud.firestore.pipeline.Expr.Field import com.google.cloud.firestore.pipeline.Fields import com.google.cloud.firestore.pipeline.Filter @@ -25,7 +24,8 @@ import com.google.cloud.firestore.pipeline.Projectable import com.google.cloud.firestore.pipeline.RemoveFields import com.google.cloud.firestore.pipeline.Sort import com.google.cloud.firestore.pipeline.UnionWith -import com.google.cloud.firestore.pipeline.Unnest +import com.google.cloud.firestore.pipeline.UnnestArray +import com.google.cloud.firestore.pipeline.UnnestMap class GroupingPipeline internal constructor(val p: Pipeline, vararg val by: Projectable) { fun aggregate(vararg aggregator: Expr.AggregatorTarget): Pipeline { @@ -305,8 +305,13 @@ class Pipeline { return this } - fun unnest(field: Field, mode: Unnest.Mode = Unnest.Mode.FULL_REPLACE): Pipeline { - operations.add(Unnest(mode, field)) + fun unnestMap(field: Field, mode: UnnestMap.Mode = UnnestMap.Mode.FULL_REPLACE): Pipeline { + operations.add(UnnestMap(mode, field)) + return this + } + + fun unnestArray(field: Field): Pipeline { + operations.add(UnnestArray(field)) return this } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index fe15b7eb1..4e538a2d8 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -32,6 +32,11 @@ sealed interface Expr { return Constant(value) } + @JvmStatic + fun of(value: Any): Constant { + return Constant(value) + } + @JvmStatic fun ofArray(value: Iterable): Constant { return Constant(value) @@ -51,6 +56,8 @@ sealed interface Expr { data class Field(val field: String, var pipeline: Pipeline? = null) : Expr, Projectable { companion object { + const val DOCUMENT_ID: String = "__path__" + @JvmStatic fun of(path: String): Field { return Field(path) @@ -83,15 +90,24 @@ sealed interface Expr { data class ExprAsAlias(val current: Expr, val alias: String) : Expr, Projectable - data class AggregatorTarget(val current: Function.Accumulator, val target: String) : Expr, - Projectable, - Function.Accumulator + data class AggregatorTarget(val current: Function.Accumulator, val target: String, + override var distinct: Boolean + ) : Expr, + Projectable, + Function.Accumulator sealed class Function(val name: String, val params: Map?) : Expr { interface FilterCondition interface Accumulator { - fun toField(target: String) = AggregatorTarget(this, target) + var distinct: Boolean + + fun distinct(on: Boolean): Accumulator { + this.distinct = on + return this + } + + fun toField(target: String) = AggregatorTarget(this, target, this.distinct) } data class Equal internal constructor(val left: Expr, val right: Expr) : @@ -151,14 +167,15 @@ sealed interface Expr { data class IsNull(val value: Expr) : Function("is_null", mapOf("value" to value)), FilterCondition - data class Sum(val value: Expr) : Function("sum", mapOf("value" to value)), Accumulator - data class Avg(val value: Expr) : Function("avg", mapOf("value" to value)), Accumulator - data class Count(val value: Expr) : Function("count", mapOf("value" to value)), Accumulator + data class Sum(val value: Expr, override var distinct: Boolean) : Function("sum", mapOf("value" to value)), Accumulator + data class Avg(val value: Expr, override var distinct: Boolean) : Function("avg", mapOf("value" to value)), Accumulator + data class Count(val value: Expr, override var distinct: Boolean) : Function("count", mapOf("value" to value)), Accumulator // String manipulation data class Concat(val value: List) : Function("concat", mapOf("value" to ListOfExprs(value))) data class Trim(val value: Expr) : Function("trim", mapOf("value" to value)) data class ToLower(val value: Expr) : Function("toLower", mapOf("value" to value)) + data class StartWith(val value: Expr, val query: Expr) : Function("startWith", mapOf("value" to value)), FilterCondition data class CosineDistance(val vector1: Expr, val vector2: Expr) : Function("cosine_distance", mapOf("vector1" to vector1, "vector2" to vector2)) @@ -190,13 +207,15 @@ sealed interface Expr { fun arrayContainsAny(vararg elements: Expr) = Function.ArrayContainsAny(this, elements.toList()) fun isNaN() = Function.IsNaN(this) fun isNull() = Function.IsNull(this) - fun sum() = Function.Sum(this) - fun avg() = Function.Avg(this) - fun count() = Function.Count(this) + fun sum() = Function.Sum(this, false) + fun avg() = Function.Avg(this, false) + fun count() = Function.Count(this, false) fun concatWith(vararg expr: Expr) = Function.Concat(listOf(this) + expr.toList()) - fun toLower() = Function.Count(this) - fun trim() = Function.Count(this) + fun toLower() = Function.ToLower(this) + fun trim() = Function.Trim(this) + + fun startsWith(expr: Expr) = Function.StartWith(this, expr) infix fun cosineDistance(other: Expr) = Function.CosineDistance(this, other) infix fun cosineDistance(other: DoubleArray) = @@ -292,13 +311,13 @@ sealed interface Expr { fun not(expr: Expr) = Function.Not(expr) @JvmStatic - fun sum(expr: Expr) = Function.Sum(expr) + fun sum(expr: Expr) = Function.Sum(expr, false) @JvmStatic - fun avg(expr: Expr) = Function.Avg(expr) + fun avg(expr: Expr) = Function.Avg(expr, false) @JvmStatic - fun count(expr: Expr) = Function.Count(expr) + fun count(expr: Expr) = Function.Count(expr, false) @JvmStatic fun concat(vararg expr: Expr) = Function.Concat(expr.toList()) @@ -307,6 +326,9 @@ sealed interface Expr { @JvmStatic fun toLower(expr: Expr) = Function.ToLower(expr) + @JvmStatic + fun startWith(left: Expr, right: Expr) = Function.StartWith(left, right) + @JvmStatic fun cosineDistance(expr: Expr, other: Expr) = Function.CosineDistance(expr, other) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt index 4eda29256..ec22a250b 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt @@ -122,7 +122,7 @@ data class Sort( } } -data class Unnest(val mode: Mode, val field: Expr.Field) : Operation { +data class UnnestMap(val mode: Mode, val field: Expr.Field) : Operation { enum class Mode { FULL_REPLACE, MERGE_PREFER_NEST, @@ -130,5 +130,7 @@ data class Unnest(val mode: Mode, val field: Expr.Field) : Operation { } } +data class UnnestArray(val field: Expr.Field) : Operation + data class GenericOperation(val name: String, val params: Map?) : Operation diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 681ef3ba5..da6c6710b 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -64,6 +64,7 @@ public void pipelineWithDb() throws Exception { public void projections() throws Exception { Pipeline p = Pipeline.fromCollection("coll1") + .unnestMap(Field.of("foo")) .project( Field.of("foo"), Constant.of("emptyValue").asAlias("emptyField"), From 57f0b745cd619af993c2bcabb9d95316fd681fdf Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Mon, 8 Apr 2024 10:47:42 -0400 Subject: [PATCH 28/65] edits --- .../src/main/java/com/google/cloud/firestore/Pipeline.kt | 1 + .../test/java/com/google/cloud/firestore/it/ITPipelineTest.java | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 6f5925c39..5309c4f21 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -305,6 +305,7 @@ class Pipeline { return this } + @JvmOverloads fun unnestMap(field: Field, mode: UnnestMap.Mode = UnnestMap.Mode.FULL_REPLACE): Pipeline { operations.add(UnnestMap(mode, field)) return this diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index da6c6710b..681ef3ba5 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -64,7 +64,6 @@ public void pipelineWithDb() throws Exception { public void projections() throws Exception { Pipeline p = Pipeline.fromCollection("coll1") - .unnestMap(Field.of("foo")) .project( Field.of("foo"), Constant.of("emptyValue").asAlias("emptyField"), From 0629026d27782bf824955d8ad8b55bc55f20aee2 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Tue, 9 Apr 2024 14:47:52 -0400 Subject: [PATCH 29/65] Initial PP pipeline api --- .../com/google/cloud/firestore/Pipeline.kt | 186 +------ .../google/cloud/firestore/PipelineResult.kt | 3 +- .../cloud/firestore/pipeline/Expressions.kt | 509 ++++++++++-------- .../cloud/firestore/pipeline/Operations.kt | 136 ----- .../google/cloud/firestore/pipeline/Stages.kt | 93 ++++ .../cloud/firestore/it/ITPipelineTest.java | 104 +--- .../proto/google/firestore/v1/document.proto | 113 ++++ .../proto/google/firestore/v1/firestore.proto | 86 +++ .../proto/google/firestore/v1/pipeline.proto | 26 + 9 files changed, 633 insertions(+), 623 deletions(-) delete mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt create mode 100644 proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/pipeline.proto diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 5309c4f21..7c5a39cf7 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -3,57 +3,20 @@ package com.google.cloud.firestore import com.google.api.core.ApiFuture import com.google.api.core.ApiFutures import com.google.api.gax.rpc.ApiStreamObserver -import com.google.cloud.firestore.pipeline.AddFields +import com.google.cloud.firestore.pipeline.AggregatorTarget import com.google.cloud.firestore.pipeline.Collection import com.google.cloud.firestore.pipeline.CollectionGroup -import com.google.cloud.firestore.pipeline.Database -import com.google.cloud.firestore.pipeline.Expr -import com.google.cloud.firestore.pipeline.Expr.Field -import com.google.cloud.firestore.pipeline.Fields +import com.google.cloud.firestore.pipeline.Field import com.google.cloud.firestore.pipeline.Filter import com.google.cloud.firestore.pipeline.FindNearest -import com.google.cloud.firestore.pipeline.GenericOperation -import com.google.cloud.firestore.pipeline.Group -import com.google.cloud.firestore.pipeline.Join +import com.google.cloud.firestore.pipeline.Function +import com.google.cloud.firestore.pipeline.GenericStage import com.google.cloud.firestore.pipeline.Limit import com.google.cloud.firestore.pipeline.Offset -import com.google.cloud.firestore.pipeline.Operation import com.google.cloud.firestore.pipeline.Ordering -import com.google.cloud.firestore.pipeline.Project import com.google.cloud.firestore.pipeline.Projectable -import com.google.cloud.firestore.pipeline.RemoveFields import com.google.cloud.firestore.pipeline.Sort -import com.google.cloud.firestore.pipeline.UnionWith -import com.google.cloud.firestore.pipeline.UnnestArray -import com.google.cloud.firestore.pipeline.UnnestMap - -class GroupingPipeline internal constructor(val p: Pipeline, vararg val by: Projectable) { - fun aggregate(vararg aggregator: Expr.AggregatorTarget): Pipeline { - // TODO: this.p.operations.add() - return this.p - } -} - -class JoiningPipeline internal constructor( - val left: Pipeline, - val right: Pipeline, - val join: Join.Type -) { - fun on(condition: Expr.Function): Pipeline { - // TODO: this.p.operations.add() - return left - } - - fun on(vararg field: Field): Pipeline { - // TODO: this.p.operations.add() - return left - } - - fun on(field: Fields): Pipeline { - // TODO: this.p.operations.add() - return left - } -} +import com.google.cloud.firestore.pipeline.Stage class PaginatingPipeline internal constructor( val p: Pipeline, @@ -64,10 +27,6 @@ class PaginatingPipeline internal constructor( return this.p } - fun page(n:Int): Pipeline { - return this.p - } - fun startAt(result: PipelineResult): Pipeline { return this.p } @@ -120,21 +79,16 @@ class PaginatingPipeline internal constructor( * ``` */ class Pipeline { - internal val operations: MutableList = mutableListOf() + private val stages: MutableList = mutableListOf() private var name: String - private constructor(db: Database) { - operations.add(db) - name = "(database)" - } - private constructor(collection: Collection) { - operations.add(collection) + stages.add(collection) name = collection.path } private constructor(group: CollectionGroup) { - operations.add(group) + stages.add(group) name = group.path } @@ -158,97 +112,28 @@ class Pipeline { fun fromCollectionGroup(group: String): Pipeline { return Pipeline(CollectionGroup(group)) } - - @JvmStatic - fun fromDatabase(): Pipeline { - return Pipeline(Database()) - } - - @JvmStatic - fun fromDocuments(vararg docPath :String): Pipeline { - return Pipeline(Database()) - } - - @JvmStatic - fun fromData(vararg doc: Map>): Pipeline { - return Pipeline(Database()) - } - } - // Fluent API - - fun withName(name: String) { - this.name = name - } - - fun project(projections: Map): Pipeline { - operations.add(Project(projections)) - return this - } - - // Sugar for project - fun project(vararg fields: Field): Pipeline { - return this - } - - fun project(vararg exprs: Expr.ExprAsAlias): Pipeline { - return this } fun project(vararg projections: Projectable): Pipeline { return this } - fun addFields(additions: Map): Pipeline { - operations.add(AddFields(additions)) - return this - } - - // Sugar - fun addFields(vararg additions: Expr.ExprAsAlias): Pipeline { - return this - } - - fun removeFields(vararg removals: Field): Pipeline { - operations.add(RemoveFields(removals.toList())) - return this - } - - fun filter(condition: Expr.Function.FilterCondition): Pipeline { - operations.add(Filter(condition)) + fun filter(condition: Function.FilterCondition): Pipeline { + stages.add(Filter(condition)) return this } fun offset(offset: Int): Pipeline { - operations.add(Offset(offset)) + stages.add(Offset(offset)) return this } fun limit(limit: Int): Pipeline { - operations.add(Limit(limit)) - return this - } - - fun unionWith(pipeline: Pipeline, distinct: Boolean): Pipeline { - operations.add(UnionWith(pipeline, distinct)) + stages.add(Limit(limit)) return this } - fun group(fields: Map, accumulators: Map): Pipeline { - operations.add(Group(fields, accumulators)) - return this - } - - fun group(by: Fields): GroupingPipeline { - // operations.add(Group(fields, accumulators)) - return GroupingPipeline(this /*TODO*/) - } - - fun group(by: Projectable): GroupingPipeline { - // operations.add(Group(fields, accumulators)) - return GroupingPipeline(this /*TODO*/) - } - - fun aggregate(vararg aggregator: Expr.AggregatorTarget): Pipeline { + fun aggregate(vararg aggregator: AggregatorTarget): Pipeline { // operations.add(Group()) // operations.add(aggregator) return this @@ -259,44 +144,16 @@ class Pipeline { vector: DoubleArray, options: FindNearest.FindNearestOptions ): Pipeline { - operations.add(FindNearest(property, vector, options)) + stages.add(FindNearest(property, vector, options)) return this } - fun innerJoin( - otherPipeline: Pipeline - ) = JoiningPipeline(this, otherPipeline, Join.Type.INNER) - - fun crossJoin(otherPipeline: Pipeline): JoiningPipeline = - JoiningPipeline(this, otherPipeline, Join.Type.CROSS) - - fun fullJoin(otherPipeline: Pipeline): JoiningPipeline = - JoiningPipeline(this, otherPipeline, Join.Type.FULL) - - fun leftJoin(otherPipeline: Pipeline): JoiningPipeline = - JoiningPipeline(this, otherPipeline, Join.Type.LEFT) - - fun rightJoin(otherPipeline: Pipeline): JoiningPipeline = - JoiningPipeline(this, otherPipeline, Join.Type.RIGHT) - - fun leftSemiJoin(otherPipeline: Pipeline): JoiningPipeline = - JoiningPipeline(this, otherPipeline, Join.Type.LEFT_SEMI) - - fun rightSemiJoin(otherPipeline: Pipeline): JoiningPipeline = - JoiningPipeline(this, otherPipeline, Join.Type.RIGHT_SEMI) - - fun leftAntiSemiJoin(otherPipeline: Pipeline): JoiningPipeline = - JoiningPipeline(this, otherPipeline, Join.Type.LEFT_ANTI_SEMI) - - fun rightAntiSemiJoin(otherPipeline: Pipeline): JoiningPipeline = - JoiningPipeline(this, otherPipeline, Join.Type.RIGHT_ANTI_SEMI) - fun sort( orders: List, density: Sort.Density = Sort.Density.UNSPECIFIED, truncation: Sort.Truncation = Sort.Truncation.UNSPECIFIED ): Pipeline { - operations.add(Sort(orders, density, truncation)) + stages.add(Sort(orders, density, truncation)) return this } @@ -305,23 +162,12 @@ class Pipeline { return this } - @JvmOverloads - fun unnestMap(field: Field, mode: UnnestMap.Mode = UnnestMap.Mode.FULL_REPLACE): Pipeline { - operations.add(UnnestMap(mode, field)) - return this - } - - fun unnestArray(field: Field): Pipeline { - operations.add(UnnestArray(field)) - return this - } - fun paginate(pageSize: Int, vararg orders: Ordering): PaginatingPipeline { return PaginatingPipeline(this, pageSize, orders) } fun genericOperation(name: String, params: Map? = null): Pipeline { - operations.add(GenericOperation(name, params)) + stages.add(GenericStage(name, params)) return this } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt index 6dae35e11..9bf617c74 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt @@ -5,8 +5,7 @@ import com.google.firestore.v1.Value import java.util.Date import javax.annotation.Nonnull -data class PipelineResult // Elevated access level for mocking. -internal constructor( +data class PipelineResult internal constructor( private val rpcContext: FirestoreRpcContext<*>?, val reference: DocumentReference?, val protoFields: Map?, diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index 4e538a2d8..56fc06462 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -1,356 +1,417 @@ package com.google.cloud.firestore.pipeline import com.google.cloud.firestore.Pipeline +import com.google.cloud.firestore.pipeline.Function.ArrayContains +import com.google.cloud.firestore.pipeline.Function.ArrayContainsAny +import com.google.cloud.firestore.pipeline.Function.Avg +import com.google.cloud.firestore.pipeline.Function.CosineDistance +import com.google.cloud.firestore.pipeline.Function.Count +import com.google.cloud.firestore.pipeline.Function.DotProductDistance +import com.google.cloud.firestore.pipeline.Function.Equal +import com.google.cloud.firestore.pipeline.Function.EuclideanDistance +import com.google.cloud.firestore.pipeline.Function.GreaterThan +import com.google.cloud.firestore.pipeline.Function.GreaterThanOrEqual +import com.google.cloud.firestore.pipeline.Function.In +import com.google.cloud.firestore.pipeline.Function.IsNaN +import com.google.cloud.firestore.pipeline.Function.IsNull +import com.google.cloud.firestore.pipeline.Function.LessThan +import com.google.cloud.firestore.pipeline.Function.LessThanOrEqual +import com.google.cloud.firestore.pipeline.Function.MapGet +import com.google.cloud.firestore.pipeline.Function.NotEqual +import com.google.cloud.firestore.pipeline.Function.NotIn +import com.google.cloud.firestore.pipeline.Function.Sum import com.google.firestore.v1.Value -interface Projectable +sealed interface Projectable + +sealed interface Expr { + // Infix functions returning Function subclasses + infix fun equal(other: Expr) = Equal(this, other) + infix fun equal(other: Number) = Equal(this, Constant.of(other)) + infix fun equal(other: String) = Equal(this, Constant.of(other)) + infix fun equal(other: Any) = Equal(this, Constant.of(other)) + infix fun notEqual(other: Expr) = NotEqual(this, other) + infix fun notEqual(other: Number) = NotEqual(this, Constant.of(other)) + infix fun notEqual(other: String) = NotEqual(this, Constant.of(other)) + infix fun notEqual(other: Any) = NotEqual(this, Constant.of(other)) + infix fun greaterThan(other: Expr) = GreaterThan(this, other) + infix fun greaterThan(other: Number) = GreaterThan(this, Constant.of(other)) + infix fun greaterThan(other: String) = GreaterThan(this, Constant.of(other)) + infix fun greaterThan(other: Any) = GreaterThan(this, Constant.of(other)) + infix fun greaterThanOrEqual(other: Expr) = GreaterThanOrEqual(this, other) + infix fun greaterThanOrEqual(other: Number) = GreaterThanOrEqual(this, Constant.of(other)) + infix fun greaterThanOrEqual(other: String) = GreaterThanOrEqual(this, Constant.of(other)) + infix fun greaterThanOrEqual(other: Any) = GreaterThanOrEqual(this, Constant.of(other)) + infix fun lessThan(other: Expr) = LessThan(this, other) + infix fun lessThan(other: Number) = LessThan(this, Constant.of(other)) + infix fun lessThan(other: String) = LessThan(this, Constant.of(other)) + infix fun lessThan(other: Any) = LessThan(this, Constant.of(other)) + infix fun lessThanOrEqual(other: Expr) = LessThanOrEqual(this, other) + infix fun lessThanOrEqual(other: Number) = LessThanOrEqual(this, Constant.of(other)) + infix fun lessThanOrEqual(other: String) = LessThanOrEqual(this, Constant.of(other)) + infix fun lessThanOrEqual(other: Any) = LessThanOrEqual(this, Constant.of(other)) + fun inAny(vararg other: Expr) = In(this, other.toList()) + fun notInAny(vararg other: Expr) = NotIn(this, other.toList()) + + infix fun mapGet(key: String) = MapGet(this, key) + + infix fun arrayContains(element: Expr) = ArrayContains(this, element) + infix fun arrayContains(element: Number) = ArrayContains(this, Constant.of(element)) + infix fun arrayContains(element: String) = ArrayContains(this, Constant.of(element)) + infix fun arrayContains(element: Any) = ArrayContains(this, Constant.of(element)) + fun arrayContainsAny(vararg elements: Expr) = ArrayContainsAny(this, elements.toList()) + fun isNaN() = IsNaN(this) + fun isNull() = IsNull(this) + fun sum() = Sum(this, false) + fun avg() = Avg(this, false) + fun count() = Count(this, false) + + infix fun cosineDistance(other: Expr) = CosineDistance(this, other) + infix fun cosineDistance(other: DoubleArray) = + CosineDistance(this, Constant.ofVector(other)) + + infix fun euclideanDistance(other: Expr) = EuclideanDistance(this, other) + infix fun euclideanDistance(other: DoubleArray) = + EuclideanDistance(this, Constant.ofVector(other)) + + infix fun dotProductDistance(other: Expr) = DotProductDistance(this, other) + infix fun dotProductDistance(other: DoubleArray) = + DotProductDistance(this, Constant.ofVector(other)) + + fun asAlias(alias: String): Projectable = ExprAsAlias(this, alias) +} // Convenient class for internal usage internal data class ListOfExprs(val conditions: List) : Expr -internal data class ListOfConditions(val conditions: List) : Expr, - Expr.Function.FilterCondition - -data class Fields(val fs: List) : Projectable { +internal data class ListOfConditions(val conditions: List) : Expr, + Function.FilterCondition +data class Constant internal constructor(val value: Any) : Expr { companion object { @JvmStatic - fun of(vararg f: String): Fields { - return Fields(f.map(Expr.Field.Companion::of)) + fun of(value: String): Constant { + return Constant(value) + } + + @JvmStatic + fun of(value: Number): Constant { + return Constant(value) + } + + @JvmStatic + fun of(value: Any): Constant { + return Constant(value) + } + + @JvmStatic + fun ofArray(value: Iterable): Constant { + return Constant(value) + } + + @JvmStatic + fun ofMap(value: Map): Constant { + return Constant(value) + } + + @JvmStatic + fun ofVector(value: DoubleArray): Constant { + return Constant(value) } } } -sealed interface Expr { - data class Constant internal constructor(val value: Any) : Expr { - companion object { - @JvmStatic - fun of(value: String): Constant { - return Constant(value) - } - - @JvmStatic - fun of(value: Number): Constant { - return Constant(value) - } - - @JvmStatic - fun of(value: Any): Constant { - return Constant(value) - } - - @JvmStatic - fun ofArray(value: Iterable): Constant { - return Constant(value) - } - - @JvmStatic - fun ofMap(value: Map): Constant { - return Constant(value) - } - - @JvmStatic - fun ofVector(value: DoubleArray): Constant { - return Constant(value) - } +data class Field internal constructor(val field: String, var pipeline: Pipeline? = null) : Expr, + Projectable { + companion object { + const val DOCUMENT_ID: String = "__path__" + + @JvmStatic + fun of(path: String): Field { + return Field(path) } } - data class Field(val field: String, var pipeline: Pipeline? = null) : Expr, Projectable { - companion object { - const val DOCUMENT_ID: String = "__path__" - - @JvmStatic - fun of(path: String): Field { - return Field(path) - } - - @JvmStatic - fun ofAll(): AllFields { - return AllFields() - } - - @JvmStatic - fun fromPipeline(pipeline: Pipeline, path: String): Field { - return Field(path) - } - - @JvmStatic - fun allFromPipeline(pipeline: Pipeline): AllFields { - return AllFields() - } + fun exists() = Function.Exists(this) +} + +data class Fields internal constructor(val fs: List? = null) : Expr, Projectable { + companion object { + @JvmStatic + fun of(f1: String, vararg f: String): Fields { + return Fields(listOf(Field.of(f1)) + f.map(Field.Companion::of)) + } + + @JvmStatic + fun ofAll(): Fields { + return Fields(null) } } +} + +internal data class ExprAsAlias(val current: Expr, val alias: String) : Expr, Projectable + +data class AggregatorTarget internal constructor( + val current: Function.Accumulator, val target: String, + override var distinct: Boolean +) : Expr, + Projectable, + Function.Accumulator + +sealed class Function(val name: String, val params: Map?) : Expr { + interface FilterCondition - data class AllFields(var pipeline: Pipeline? = null) : Expr, Projectable { + interface Accumulator { + var distinct: Boolean - fun withPrefix(prefix: String): AllFields { + fun distinct(on: Boolean): Accumulator { + this.distinct = on return this } + + fun toField(target: String) = AggregatorTarget(this, target, this.distinct) } + data class Equal internal constructor(val left: Expr, val right: Expr) : + Function("equal", mapOf("left" to left, "right" to right)), FilterCondition - data class ExprAsAlias(val current: Expr, val alias: String) : Expr, Projectable + data class NotEqual(val left: Expr, val right: Expr) : + Function("not_equal", mapOf("left" to left, "right" to right)), FilterCondition - data class AggregatorTarget(val current: Function.Accumulator, val target: String, - override var distinct: Boolean - ) : Expr, - Projectable, - Function.Accumulator + data class GreaterThan(val left: Expr, val right: Expr) : + Function("greater_than", mapOf("left" to left, "right" to right)), FilterCondition - sealed class Function(val name: String, val params: Map?) : Expr { - interface FilterCondition + data class GreaterThanOrEqual(val left: Expr, val right: Expr) : + Function("greater_than_equal", mapOf("left" to left, "right" to right)), FilterCondition - interface Accumulator { - var distinct: Boolean + data class In(val left: Expr, val others: List) : + Function("in", mapOf("left" to left, "others" to ListOfExprs(others))), + FilterCondition // For 'in' - fun distinct(on: Boolean): Accumulator { - this.distinct = on - return this - } + data class LessThan(val left: Expr, val right: Expr) : + Function("less_than", mapOf("left" to left, "right" to right)), FilterCondition - fun toField(target: String) = AggregatorTarget(this, target, this.distinct) - } + data class LessThanOrEqual(val left: Expr, val right: Expr) : + Function("less_than_equal", mapOf("left" to left, "right" to right)), FilterCondition - data class Equal internal constructor(val left: Expr, val right: Expr) : - Function("equal", mapOf("left" to left, "right" to right)), FilterCondition + data class NotIn(val left: Expr, val others: List) : + Function("not_in", mapOf("left" to left, "others" to ListOfExprs(others))), + FilterCondition // For 'not in' - data class NotEqual(val left: Expr, val right: Expr) : - Function("not_equal", mapOf("left" to left, "right" to right)), FilterCondition + data class And(val conditions: List) : + Function("and", mapOf("conditions" to ListOfConditions(conditions))), FilterCondition - data class GreaterThan(val left: Expr, val right: Expr) : - Function("greater_than", mapOf("left" to left, "right" to right)), FilterCondition + data class Or(val conditions: List) : + Function("or", mapOf("conditions" to ListOfConditions(conditions))), FilterCondition - data class GreaterThanOrEqual(val left: Expr, val right: Expr) : - Function("greater_than_equal", mapOf("left" to left, "right" to right)), FilterCondition + data class Not(val condition: Expr) : Function("not", mapOf("condition" to condition)), + FilterCondition - data class In(val left: Expr, val others: List) : - Function("in", mapOf("left" to left, "others" to ListOfExprs(others))), - FilterCondition // For 'in' + data class Exists(val current: Field) : Function("exists", mapOf("current" to current)), + FilterCondition - data class LessThan(val left: Expr, val right: Expr) : - Function("less_than", mapOf("left" to left, "right" to right)), FilterCondition + data class MapGet(val map: Expr, val key: String) : Function( + "map_get", + mapOf( + "map" to map, + "key" to Constant(Value.getDefaultInstance().toBuilder().setStringValue(key).build()) + ) + ) - data class LessThanOrEqual(val left: Expr, val right: Expr) : - Function("less_than_equal", mapOf("left" to left, "right" to right)), FilterCondition + data class ArrayContains(val array: Expr, val element: Expr) : + Function("array_contains", mapOf("array" to array, "element" to element)), FilterCondition - data class NotIn(val left: Expr, val others: List) : - Function("not_in", mapOf("left" to left, "others" to ListOfExprs(others))), - FilterCondition // For 'not in' + data class ArrayContainsAny(val array: Expr, val elements: List) : + Function("array_contains_any", mapOf("array" to array, "elements" to ListOfExprs(elements))), + FilterCondition - data class And(val conditions: List) : - Function("and", mapOf("conditions" to ListOfConditions(conditions))), FilterCondition + data class IsNaN(val value: Expr) : Function("is_nan", mapOf("value" to value)), FilterCondition + data class IsNull(val value: Expr) : Function("is_null", mapOf("value" to value)), + FilterCondition - data class Or(val conditions: List) : - Function("or", mapOf("conditions" to ListOfConditions(conditions))), FilterCondition + data class Sum(val value: Expr, override var distinct: Boolean) : + Function("sum", mapOf("value" to value)), Accumulator - data class Not(val condition: Expr) : Function("not", mapOf("condition" to condition)), - FilterCondition + data class Avg(val value: Expr, override var distinct: Boolean) : + Function("avg", mapOf("value" to value)), Accumulator - data class Exists(val current: Field) : Function("exists", mapOf("current" to current)), - FilterCondition + data class Count(val value: Expr, override var distinct: Boolean) : + Function("count", mapOf("value" to value)), Accumulator - data class MapGet(val map: Expr, val key: String) : Function( - "map_get", - mapOf( - "map" to map, - "key" to Constant(Value.getDefaultInstance().toBuilder().setStringValue(key).build()) - ) - ) + data class CosineDistance(val vector1: Expr, val vector2: Expr) : + Function("cosine_distance", mapOf("vector1" to vector1, "vector2" to vector2)) - data class ArrayContains(val array: Expr, val element: Expr) : - Function("array_contains", mapOf("array" to array, "element" to element)), FilterCondition + data class DotProductDistance(val vector1: Expr, val vector2: Expr) : + Function("dot_product_distance", mapOf("vector1" to vector1, "vector2" to vector2)) - data class ArrayContainsAny(val array: Expr, val elements: List) : - Function("array_contains_any", mapOf("array" to array, "elements" to ListOfExprs(elements))), - FilterCondition + data class EuclideanDistance(val vector1: Expr, val vector2: Expr) : + Function("euclidean_distance", mapOf("vector1" to vector1, "vector2" to vector2)) - data class IsNaN(val value: Expr) : Function("is_nan", mapOf("value" to value)), FilterCondition - data class IsNull(val value: Expr) : Function("is_null", mapOf("value" to value)), - FilterCondition + data class Generic(val n: String, val ps: Map?) : Function(n, ps) - data class Sum(val value: Expr, override var distinct: Boolean) : Function("sum", mapOf("value" to value)), Accumulator - data class Avg(val value: Expr, override var distinct: Boolean) : Function("avg", mapOf("value" to value)), Accumulator - data class Count(val value: Expr, override var distinct: Boolean) : Function("count", mapOf("value" to value)), Accumulator - // String manipulation - data class Concat(val value: List) : Function("concat", mapOf("value" to ListOfExprs(value))) - data class Trim(val value: Expr) : Function("trim", mapOf("value" to value)) - data class ToLower(val value: Expr) : Function("toLower", mapOf("value" to value)) - data class StartWith(val value: Expr, val query: Expr) : Function("startWith", mapOf("value" to value)), FilterCondition + companion object { + @JvmStatic + fun equal(left: Expr, right: Expr) = Equal(left, right) - data class CosineDistance(val vector1: Expr, val vector2: Expr) : - Function("cosine_distance", mapOf("vector1" to vector1, "vector2" to vector2)) + @JvmStatic + fun equal(left: Expr, right: String) = Equal(left, Constant.of(right)) - data class EuclideanDistance(val vector1: Expr, val vector2: Expr) : - Function("euclidean_distance", mapOf("vector1" to vector1, "vector2" to vector2)) + @JvmStatic + fun equal(left: Expr, right: Number) = Equal(left, Constant.of(right)) - data class HasAncestor(val child: Expr, val ancestor: Expr) : - Function("has_ancestor", mapOf("child" to child, "ancestor" to ancestor)), FilterCondition + @JvmStatic + fun equal(left: Expr, right: Any) = Equal(left, Constant.of(right)) - data class Generic(val n: String, val ps: Map?) : Function(n, ps) - } + @JvmStatic + fun notEqual(left: Expr, right: Expr) = NotEqual(left, right) - // Infix functions returning Function subclasses - infix fun equal(other: Expr) = Function.Equal(this, other) - infix fun notEqual(other: Expr) = Function.NotEqual(this, other) - infix fun greaterThan(other: Expr) = Function.GreaterThan(this, other) - infix fun greaterThanOrEqual(other: Expr) = Function.GreaterThanOrEqual(this, other) - fun inAny(vararg other: Expr) = Function.In(this, other.toList()) - infix fun lessThan(other: Expr) = Function.LessThan(this, other) - infix fun lessThanOrEqual(other: Expr) = Function.LessThanOrEqual(this, other) - fun notInAny(vararg other: Expr) = Function.NotIn(this, other.toList()) - - - fun exists() = Function.Exists(this as Field) - - infix fun mapGet(key: String) = Function.MapGet(this, key) - infix fun arrayContains(element: Expr) = Function.ArrayContains(this, element) - fun arrayContainsAny(vararg elements: Expr) = Function.ArrayContainsAny(this, elements.toList()) - fun isNaN() = Function.IsNaN(this) - fun isNull() = Function.IsNull(this) - fun sum() = Function.Sum(this, false) - fun avg() = Function.Avg(this, false) - fun count() = Function.Count(this, false) - - fun concatWith(vararg expr: Expr) = Function.Concat(listOf(this) + expr.toList()) - fun toLower() = Function.ToLower(this) - fun trim() = Function.Trim(this) - - fun startsWith(expr: Expr) = Function.StartWith(this, expr) - - infix fun cosineDistance(other: Expr) = Function.CosineDistance(this, other) - infix fun cosineDistance(other: DoubleArray) = - Function.CosineDistance(this, Constant.ofVector(other)) - infix fun euclideanDistance(other: Expr) = Function.EuclideanDistance(this, other) - infix fun euclideanDistance(other: DoubleArray) = - Function.EuclideanDistance(this, Constant.ofVector(other)) + @JvmStatic + fun notEqual(left: Expr, right: String) = NotEqual(left, Constant.of(right)) - infix fun hasAncestor(ancestor: Expr) = Function.HasAncestor(this, ancestor) + @JvmStatic + fun notEqual(left: Expr, right: Number) = NotEqual(left, Constant.of(right)) - fun asAlias(alias: String): ExprAsAlias = ExprAsAlias(this, alias) + @JvmStatic + fun notEqual(left: Expr, right: Any) = NotEqual(left, Constant.of(right)) - companion object { @JvmStatic - fun equal(left: Expr, right: Expr) = Function.Equal(left, right) + fun greaterThan(left: Expr, right: Expr) = GreaterThan(left, right) - // sugar, first argument is assumed to be a field. @JvmStatic - fun equal(left: String, right: Expr) = Function.Equal(Field.of(left), right) + fun greaterThan(left: Expr, right: String) = + GreaterThan(left, Constant.of(right)) - // sugar, first argument is assumed to be a field, and second argument is assumed to a simple - // scalar constant. @JvmStatic - fun equal(left: String, right: String) = Function.Equal(Field.of(left), Constant.of(right)) + fun greaterThan(left: Expr, right: Number) = + GreaterThan(left, Constant.of(right)) @JvmStatic - fun equal(left: String, right: Number) = Function.Equal(Field.of(left), Constant.of(right)) + fun greaterThan(left: Expr, right: Any) = + GreaterThan(left, Constant.of(right)) @JvmStatic - fun notEqual(left: Expr, right: Expr) = Function.NotEqual(left, right) + fun greaterThanOrEqual(left: Expr, right: Expr) = GreaterThanOrEqual(left, right) @JvmStatic - fun greaterThan(left: Expr, right: Expr) = Function.GreaterThan(left, right) + fun greaterThanOrEqual(left: Expr, right: String) = GreaterThanOrEqual(left, Constant.of(right)) @JvmStatic - fun greaterThanOrEqual(left: Expr, right: Expr) = Function.GreaterThanOrEqual(left, right) + fun greaterThanOrEqual(left: Expr, right: Number) = GreaterThanOrEqual(left, Constant.of(right)) @JvmStatic - fun inAny(left: Expr, vararg other: Expr) = Function.In(left, other.toList()) + fun greaterThanOrEqual(left: Expr, right: Any) = GreaterThanOrEqual(left, Constant.of(right)) @JvmStatic - fun lessThan(left: Expr, right: Expr) = Function.LessThan(left, right) + fun lessThan(left: Expr, right: Expr) = LessThan(left, right) @JvmStatic - fun lessThan(left: String, right: String) = - Function.LessThan(Field.of(left), Constant.of(right)) + fun lessThan(left: Expr, right: String) = LessThan(left, Constant.of(right)) @JvmStatic - fun lessThan(left: String, right: Number) = - Function.LessThan(Field.of(left), Constant.of(right)) + fun lessThan(left: Expr, right: Number) = LessThan(left, Constant.of(right)) + @JvmStatic - fun lessThanOrEqual(left: Expr, right: Expr) = Function.LessThanOrEqual(left, right) + fun lessThan(left: Expr, right: Any) = LessThan(left, Constant.of(right)) @JvmStatic - fun notInAny(left: Expr, vararg other: Expr) = Function.NotIn(left, other.toList()) + fun lessThanOrEqual(left: Expr, right: Expr) = LessThanOrEqual(left, right) @JvmStatic - fun and(left: Function.FilterCondition, right: Function.FilterCondition) = - Function.And(listOf(left, right)) + fun lessThanOrEqual(left: Expr, right: String) = LessThanOrEqual(left, Constant.of(right)) @JvmStatic - fun and(left: Function.FilterCondition, vararg other: Function.FilterCondition) = - Function.And(listOf(left) + other.toList()) + fun lessThanOrEqual(left: Expr, right: Number) = LessThanOrEqual(left, Constant.of(right)) @JvmStatic - fun or(left: Function.FilterCondition, right: Function.FilterCondition) = - Function.Or(listOf(left, right)) + fun lessThanOrEqual(left: Expr, right: Any) = LessThanOrEqual(left, Constant.of(right)) @JvmStatic - fun or(left: Function.FilterCondition, vararg other: Function.FilterCondition) = - Function.Or(listOf(left) + other.toList()) + fun inAny(left: Expr, values: List) = In(left, values) @JvmStatic - fun exists(expr: Field) = Function.Exists(expr) + fun notInAny(left: Expr, values: List) = NotIn(left, values) @JvmStatic - fun mapGet(expr: Expr, key: String) = Function.MapGet(expr, key) + fun and(left: FilterCondition, right: FilterCondition) = + And(listOf(left, right)) @JvmStatic - fun arrayContains(expr: Expr, element: Expr) = Function.ArrayContains(expr, element) + fun and(left: FilterCondition, vararg other: FilterCondition) = + And(listOf(left) + other.toList()) @JvmStatic - fun arrayContainsAny(expr: Expr, vararg elements: Expr) = - Function.ArrayContainsAny(expr, elements.toList()) + fun or(left: FilterCondition, right: FilterCondition) = + Or(listOf(left, right)) + + @JvmStatic + fun or(left: FilterCondition, vararg other: FilterCondition) = + Or(listOf(left) + other.toList()) + + @JvmStatic + fun exists(expr: Field) = Exists(expr) @JvmStatic - fun isNaN(expr: Expr) = Function.IsNaN(expr) + fun mapGet(expr: Expr, key: String) = MapGet(expr, key) @JvmStatic - fun isNull(expr: Expr) = Function.IsNull(expr) + fun arrayContains(expr: Expr, element: Expr) = ArrayContains(expr, element) @JvmStatic - fun not(expr: Expr) = Function.Not(expr) + fun arrayContains(expr: Expr, element: Number) = ArrayContains(expr, Constant.of(element)) @JvmStatic - fun sum(expr: Expr) = Function.Sum(expr, false) + fun arrayContains(expr: Expr, element: String) = ArrayContains(expr, Constant.of(element)) @JvmStatic - fun avg(expr: Expr) = Function.Avg(expr, false) + fun arrayContains(expr: Expr, element: Any) = ArrayContains(expr, Constant.of(element)) @JvmStatic - fun count(expr: Expr) = Function.Count(expr, false) + fun arrayContainsAny(expr: Expr, vararg elements: Expr) = + ArrayContainsAny(expr, elements.toList()) @JvmStatic - fun concat(vararg expr: Expr) = Function.Concat(expr.toList()) + fun isNaN(expr: Expr) = IsNaN(expr) + @JvmStatic - fun trim(expr: Expr) = Function.Trim(expr) + fun isNull(expr: Expr) = IsNull(expr) + @JvmStatic - fun toLower(expr: Expr) = Function.ToLower(expr) + fun not(expr: Expr) = Not(expr) @JvmStatic - fun startWith(left: Expr, right: Expr) = Function.StartWith(left, right) + fun sum(expr: Expr) = Sum(expr, false) @JvmStatic - fun cosineDistance(expr: Expr, other: Expr) = Function.CosineDistance(expr, other) + fun avg(expr: Expr) = Avg(expr, false) + + @JvmStatic + fun count(expr: Expr) = Count(expr, false) + + @JvmStatic + fun cosineDistance(expr: Expr, other: Expr) = CosineDistance(expr, other) @JvmStatic fun cosineDistance(expr: Expr, other: DoubleArray) = - Function.CosineDistance(expr, Constant.ofVector(other)) + CosineDistance(expr, Constant.ofVector(other)) @JvmStatic - fun euclideanDistance(expr: Expr, other: Expr) = Function.EuclideanDistance(expr, other) + fun dotProductDistance(expr: Expr, other: Expr) = CosineDistance(expr, other) @JvmStatic - fun euclideanDistance(expr: Expr, other: DoubleArray) = - Function.EuclideanDistance(expr, Constant.ofVector(other)) + fun dotProductDistance(expr: Expr, other: DoubleArray) = + CosineDistance(expr, Constant.ofVector(other)) @JvmStatic - fun hasAncestor(expr: Expr, ancestor: Expr) = Function.HasAncestor(expr, ancestor) + fun euclideanDistance(expr: Expr, other: Expr) = EuclideanDistance(expr, other) @JvmStatic - fun asAlias(expr: Expr, alias: String): ExprAsAlias = ExprAsAlias(expr, alias) + fun euclideanDistance(expr: Expr, other: DoubleArray) = + EuclideanDistance(expr, Constant.ofVector(other)) @JvmStatic - fun function(name: String, params: Map?) = Function.Generic(name, params) - } + fun asAlias(expr: Expr, alias: String): Projectable = ExprAsAlias(expr, alias) + @JvmStatic + fun function(name: String, params: Map?) = Generic(name, params) + } } + diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt deleted file mode 100644 index ec22a250b..000000000 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Operations.kt +++ /dev/null @@ -1,136 +0,0 @@ -package com.google.cloud.firestore.pipeline - -import com.google.cloud.firestore.Pipeline - -interface Operation - -class Database : Operation -data class Collection(val path: String) : Operation -data class CollectionGroup(val path: String) : Operation - -data class Project(val projections: Map) : Operation -data class AddFields(val additions: Map) : Operation -data class RemoveFields(val removals: List) : Operation -data class Filter(val condition: Expr.Function.FilterCondition) : Operation -data class Offset(val offset: Int) : Operation -data class Limit(val limit: Int) : Operation -data class UnionWith(val pipeline: Pipeline, val distinct: Boolean) : Operation - -data class Group(val fields: Map, val accumulators: Map) : - Operation - -data class FindNearest( - val property: Expr.Field, - val vector: DoubleArray, - val options: FindNearestOptions -) : Operation { - sealed interface Similarity { - data object Euclidean : Similarity - data object Cosine : Similarity - data object DotProduct : Similarity - - class GenericSimilarity(val name: String) : Similarity - - companion object { - @JvmStatic - fun euclidean() = Euclidean - - @JvmStatic - fun cosine() = Cosine - - @JvmStatic - fun dotProduct() = DotProduct - - @JvmStatic - fun generic(name: String) = GenericSimilarity(name) - } - } - - data class FindNearestOptions( - val similarity: Similarity, - val limit: Long, - val output: Expr.Field - ) -} - -sealed interface JoinCondition { - data class Expression(val expr: Expr) : JoinCondition - data class Using(val fields: Set) : JoinCondition -} - -data class Join( - val type: Type, - val condition: JoinCondition, - val alias: Expr.Field, - val otherPipeline: Pipeline, - val otherAlias: Expr.Field -) : Operation { - enum class Type { - CROSS, - INNER, - FULL, - LEFT, - RIGHT, - LEFT_SEMI, - RIGHT_SEMI, - LEFT_ANTI_SEMI, - RIGHT_ANTI_SEMI, - } -} - -data class Ordering(val expr: Expr, val dir: Direction = Direction.ASC) { - enum class Direction { - ASC, - DESC - } - - companion object { - @JvmStatic - fun of(expr: Expr, dir: Direction = Direction.ASC): Ordering { - return Ordering(expr, dir) - } - - @JvmStatic - fun of(expr: Expr): Ordering { - return Ordering(expr, Direction.ASC) - } - - @JvmStatic - fun ascending(expr: Expr): Ordering { - return Ordering(expr, Direction.ASC) - } - @JvmStatic - fun descending(expr: Expr): Ordering { - return Ordering(expr, Direction.DESC) - } - } -} - -data class Sort( - val orders: List, - val density: Density = Density.UNSPECIFIED, - val truncation: Truncation = Truncation.UNSPECIFIED -) : Operation { - enum class Density { - UNSPECIFIED, - REQUIRED - } - - enum class Truncation { - UNSPECIFIED, - DISABLED - } -} - -data class UnnestMap(val mode: Mode, val field: Expr.Field) : Operation { - enum class Mode { - FULL_REPLACE, - MERGE_PREFER_NEST, - MERGE_PREFER_PARENT; - } -} - -data class UnnestArray(val field: Expr.Field) : Operation - -data class GenericOperation(val name: String, val params: Map?) : Operation - diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt new file mode 100644 index 000000000..9044f192a --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt @@ -0,0 +1,93 @@ +package com.google.cloud.firestore.pipeline + +interface Stage + +internal data class Collection(val path: String) : Stage +internal data class CollectionGroup(val path: String) : Stage + +internal data class Project(val projections: Map) : Stage +internal data class Filter(val condition: Function.FilterCondition) : Stage +internal data class Offset(val offset: Int) : Stage +internal data class Limit(val limit: Int) : Stage + +data class FindNearest internal constructor( + val property: Field, + val vector: DoubleArray, + val options: FindNearestOptions +) : Stage { + sealed interface Similarity { + data object Euclidean : Similarity + data object Cosine : Similarity + data object DotProduct : Similarity + + class GenericSimilarity(val name: String) : Similarity + + companion object { + @JvmStatic + fun euclidean() = Euclidean + + @JvmStatic + fun cosine() = Cosine + + @JvmStatic + fun dotProduct() = DotProduct + + @JvmStatic + fun generic(name: String) = GenericSimilarity(name) + } + } + + data class FindNearestOptions( + val similarity: Similarity, + val limit: Long, + val output: Field? = null + ) +} + +data class Ordering internal constructor(val expr: Expr, val dir: Direction = Direction.ASC) { + enum class Direction { + ASC, + DESC + } + + companion object { + @JvmStatic + fun of(expr: Expr, dir: Direction = Direction.ASC): Ordering { + return Ordering(expr, dir) + } + + @JvmStatic + fun of(expr: Expr): Ordering { + return Ordering(expr, Direction.ASC) + } + + @JvmStatic + fun ascending(expr: Expr): Ordering { + return Ordering(expr, Direction.ASC) + } + + @JvmStatic + fun descending(expr: Expr): Ordering { + return Ordering(expr, Direction.DESC) + } + } +} + +data class Sort internal constructor( + val orders: List, + val density: Density = Density.UNSPECIFIED, + val truncation: Truncation = Truncation.UNSPECIFIED +) : Stage { + enum class Density { + UNSPECIFIED, + REQUIRED + } + + enum class Truncation { + UNSPECIFIED, + DISABLED + } +} + +data class GenericStage(val name: String, val params: Map?) : Stage + diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 681ef3ba5..2a894c021 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -16,16 +16,12 @@ package com.google.cloud.firestore.it; -import static com.google.cloud.firestore.pipeline.Expr.and; -import static com.google.cloud.firestore.pipeline.Expr.avg; -import static com.google.cloud.firestore.pipeline.Expr.concat; -import static com.google.cloud.firestore.pipeline.Expr.cosineDistance; -import static com.google.cloud.firestore.pipeline.Expr.equal; -import static com.google.cloud.firestore.pipeline.Expr.lessThan; -import static com.google.cloud.firestore.pipeline.Expr.not; -import static com.google.cloud.firestore.pipeline.Expr.or; -import static com.google.cloud.firestore.pipeline.Expr.toLower; -import static com.google.cloud.firestore.pipeline.Expr.trim; +import static com.google.cloud.firestore.pipeline.Function.avg; +import static com.google.cloud.firestore.pipeline.Function.cosineDistance; +import static com.google.cloud.firestore.pipeline.Function.equal; +import static com.google.cloud.firestore.pipeline.Function.lessThan; +import static com.google.cloud.firestore.pipeline.Function.not; +import static com.google.cloud.firestore.pipeline.Function.or; import static com.google.cloud.firestore.pipeline.Ordering.ascending; import static com.google.cloud.firestore.pipeline.Ordering.descending; @@ -34,12 +30,9 @@ import com.google.cloud.firestore.PaginatingPipeline; import com.google.cloud.firestore.Pipeline; import com.google.cloud.firestore.PipelineResult; -import com.google.cloud.firestore.pipeline.Expr.Constant; -import com.google.cloud.firestore.pipeline.Expr.Field; -import com.google.cloud.firestore.pipeline.Expr.Function; +import com.google.cloud.firestore.pipeline.Constant; +import com.google.cloud.firestore.pipeline.Field; import com.google.cloud.firestore.pipeline.Fields; -import com.google.cloud.firestore.pipeline.FindNearest.FindNearestOptions; -import com.google.cloud.firestore.pipeline.FindNearest.Similarity; import com.google.cloud.firestore.pipeline.Ordering; import com.google.cloud.firestore.pipeline.Ordering.Direction; import java.util.Iterator; @@ -55,11 +48,6 @@ public void before() throws Exception { firestore = FirestoreOptions.newBuilder().build().getService(); } - @Test - public void pipelineWithDb() throws Exception { - Pipeline p = Pipeline.fromDatabase(); - } - @Test public void projections() throws Exception { Pipeline p = @@ -67,7 +55,7 @@ public void projections() throws Exception { .project( Field.of("foo"), Constant.of("emptyValue").asAlias("emptyField"), - Field.of("embedding").cosineDistance(new double[] {1, 2, 3.0}).asAlias("distance")); + Field.of("embedding").cosineDistance(new double[]{1, 2, 3.0}).asAlias("distance")); // More compact p = @@ -76,17 +64,7 @@ public void projections() throws Exception { p = Pipeline.fromCollection("coll1") // basically an addField - .project(Field.ofAll(), Constant.of(42).asAlias("emptyField")); - } - - @Test - public void addRemoveFields() throws Exception { - Pipeline p = - Pipeline.fromCollection("coll1") - .addFields( - Constant.of("emptyValue").asAlias("emptyField"), - Field.of("embedding").cosineDistance(new double[] {1, 2, 3.0}).asAlias("distance")) - .removeFields(Field.of("emptyField")); + .project(Fields.ofAll(), Constant.of(42).asAlias("emptyField")); } @Test @@ -102,8 +80,9 @@ public void filters() throws Exception { p = Pipeline.fromCollectionGroup("coll1") - .filter(equal("foo", 42)) - .filter(or(lessThan("bar", 100), equal("key", Constant.of("value")))) + .filter(equal(Field.of("foo"), 42)) + .filter( + or(lessThan(Field.of("bar"), 100), equal(Field.of("key"), Constant.of("value")))) .filter(not(Constant.of(128).inAny(Field.of("f1"), Field.of("f2")))); } @@ -114,18 +93,6 @@ public void inFilters() throws Exception { .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))); } - @Test - public void groupBy() throws Exception { - Pipeline p = - Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) - .group(Fields.of("given_name", "family_name")) - .aggregate(avg(Field.of("score")).toField("avg_score_1")) - // Equivalent but more fluency - .group(Fields.of("given_name", "family_name")) - .aggregate(Field.of("score").avg().toField("avg_score_2")); - } - @Test public void aggregateWithoutGrouping() throws Exception { Pipeline p = @@ -134,31 +101,6 @@ public void aggregateWithoutGrouping() throws Exception { .aggregate(avg(Field.of("score")).toField("avg_score_1")); } - @Test - public void joins() throws Exception { - Pipeline p = - Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))); - Pipeline pipe = - Pipeline.fromCollection("users") - .findNearest( - Field.of("embedding"), - new double[] {1.0, 2.0}, - new FindNearestOptions(Similarity.euclidean(), 1000, Field.of("distance"))) - .innerJoin(p) - .on( - and( - Field.of("foo").equal(Field.fromPipeline(p, "bar")), - Field.fromPipeline(p, "requirement").greaterThan(Field.of("distance")))); - - Pipeline another = - Pipeline.fromCollection("users") - .innerJoin(p) - .on(Fields.of("foo", "bar")) - .project( - Field.ofAll().withPrefix("left"), Field.allFromPipeline(p).withPrefix("right")); - } - @Test public void sorts() throws Exception { Pipeline p = @@ -193,8 +135,6 @@ public void pagination() throws Exception { Iterator result = firestore.execute(p.firstPage()).get(); Iterator second = firestore.execute(p.startAfter(result.next())).get(); - // potentially expensive but possible - Iterator page100 = firestore.execute(p.page(100)).get(); } @Test @@ -210,23 +150,5 @@ public void fluentAllTheWay() throws Exception { Iterator result = p.firstPage().execute(firestore).get(); Iterator second = p.startAfter(result.next()).execute(firestore).get(); - // potentially expensive but possible - Iterator page100 = p.page(100).execute(firestore).get(); - } - - @Test - public void functionComposition() throws Exception { - // A normalized value by joining the first and last name, triming surrounding whitespace and - // convert to lower case - Function normalized = concat(Field.of("first_name"), Constant.of(" "), Field.of("last_name")); - normalized = trim(normalized); - normalized = toLower(normalized); - - Pipeline p = - Pipeline.fromCollection("users") - .filter( - or( - normalized.equal(Constant.of("john smith")), - normalized.equal(Constant.of("alice baker")))); } } diff --git a/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/document.proto b/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/document.proto index a8764a1a2..1ccc93a10 100644 --- a/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/document.proto +++ b/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/document.proto @@ -128,6 +128,50 @@ message Value { // A map value. MapValue map_value = 6; + + + // Value which references a field. + // + // This is considered relative (vs absolute) since it only refers to a field + // and not a field within a particular document. + // + // **Requires:** + // + // * Must follow [field reference][FieldReference.field_path] limitations. + // + // * Not allowed to be used when writing documents. + // + // (-- NOTE(batchik): long term, there is no reason this type should not be + // allowed to be used on the write path. --) + string field_reference_value = 19; + + // A value that represents an unevaluated expression. + // + // **Requires:** + // + // * Not allowed to be used when writing documents. + // + // (-- NOTE(batchik): similar to above, there is no reason to not allow + // storing expressions into the database, just no plan to support in + // the near term. + // + // This would actually be an interesting way to represent user-defined + // functions or more expressive rules-based systems. --) + Function function_value = 20; + + // A value that represents an unevaluated pipeline. + // + // **Requires:** + // + // * Not allowed to be used when writing documents. + // + // (-- NOTE(batchik): similar to above, there is no reason to not allow + // storing expressions into the database, just no plan to support in + // the near term. + // + // This would actually be an interesting way to represent user-defined + // functions or more expressive rules-based systems. --) + Pipeline pipeline_value = 21; } } @@ -147,3 +191,72 @@ message MapValue { // not exceed 1,500 bytes and cannot be empty. map fields = 1; } + +// Represents an unevaluated scalar expression. +// +// For example, the expression `like(user_name, "%alice%")` is represented as: +// +// ``` +// name: "like" +// args { field_reference: "user_name" } +// args { string_value: "%alice%" } +// ``` +// +// (-- api-linter: core::0123::resource-annotation=disabled +// aip.dev/not-precedent: this is not a One Platform API resource. --) +message Function { + // The name of the function to evaluate. + // + // **Requires:** + // + // * must be in snake case (lower case with underscore separator). + // + string name = 1; + + // Ordered list of arguments the given function expects. + repeated Value args = 2; + + // Optional named arguments that certain functions may support. + map options = 3; +} + +// A Firestore query represented as an ordered list of operations / stages. +message Pipeline { + // A single operation within a pipeline. + // + // A stage is made up of a unique name, and a list of arguments. The exact + // number of arguments & types is dependent on the stage type. + // + // To give an example, the stage `filter(state = "MD")` would be encoded as: + // + // ``` + // name: "filter" + // args { + // function_value { + // name: "eq" + // args { field_reference_value: "state" } + // args { string_value: "MD" } + // } + // } + // ``` + // + // See public documentation for the full list. + message Stage { + // The name of the stage to evaluate. + // + // **Requires:** + // + // * must be in snake case (lower case with underscore separator). + // + string name = 1; + + // Ordered list of arguments the given stage expects. + repeated Value args = 2; + + // Optional named arguments that certain functions may support. + map options = 3; + } + + // Ordered list of stages to evaluate. + repeated Stage stages = 1; +} diff --git a/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/firestore.proto b/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/firestore.proto index 3b843eed5..c7dbf0c65 100644 --- a/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/firestore.proto +++ b/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/firestore.proto @@ -22,6 +22,7 @@ import "google/api/field_behavior.proto"; import "google/firestore/v1/aggregation_result.proto"; import "google/firestore/v1/common.proto"; import "google/firestore/v1/document.proto"; +import "google/firestore/v1/pipeline.proto"; import "google/firestore/v1/query.proto"; import "google/firestore/v1/write.proto"; import "google/protobuf/empty.proto"; @@ -139,6 +140,15 @@ service Firestore { }; } + // Executes a pipeline query. + rpc ExecutePipeline(ExecutePipelineRequest) + returns (stream ExecutePipelineResponse) { + option (google.api.http) = { + post: "/v1beta1/{database=projects/*/databases/*}:executePipeline" + body: "*" + }; + } + // Runs an aggregation query. // // Rather than producing [Document][google.firestore.v1.Document] results like @@ -614,6 +624,82 @@ message RunQueryResponse { } } +// The request for [Firestore.ExecutePipeline][]. +message ExecutePipelineRequest { + // Database identifier, in the form `projects/{project}/databases/{database}`. + string database = 1 [ + (google.api.field_behavior) = REQUIRED + ]; + + oneof pipeline_type { + // A pipelined operation. + StructuredPipeline structured_pipeline = 2; + } + + // Optional consistency arguments, defaults to strong consistency. + oneof consistency_selector { + // Run the query within an already active transaction. + // + // The value here is the opaque transaction ID to execute the query in. + bytes transaction = 5; + + // Execute the pipeline in a new transaction. + // + // The identifier of the newly created transaction will be returned in the + // first response on the stream. This defaults to a read-only transaction. + TransactionOptions new_transaction = 6; + + // Execute the pipeline in a snapshot transaction at the given time. + // + // This must be a microsecond precision timestamp within the past one hour, + // or if Point-in-Time Recovery is enabled, can additionally be a whole + // minute timestamp within the past 7 days. + google.protobuf.Timestamp read_time = 7; + } + + // Explain / analyze options for the pipeline. + // ExplainOptions explain_options = 8 [(google.api.field_behavior) = OPTIONAL]; +} + +// The response for [Firestore.Execute][]. +message ExecutePipelineResponse { + // Newly created transaction identifier. + // + // This field is only specified on the first response from the server when + // the request specified [ExecuteRequest.new_transaction][]. + bytes transaction = 1; + + // An ordered batch of results returned executing a pipeline. + // + // The batch size is variable, and can even be zero for when only a partial + // progress message is returned. + // + // The fields present in the returned documents are only those that were + // explicitly requested in the pipeline, this include those like + // [`__name__`][Document.name] & [`__update_time__`][Document.update_time]. + // This is explicitly a divergence from `Firestore.RunQuery` / + // `Firestore.GetDocument` RPCs which always return such fields even when they + // are not specified in the [`mask`][DocumentMask]. + repeated Document results = 2; + + // The time at which the document(s) were read. + // + // This may be monotonically increasing; in this case, the previous documents + // in the result stream are guaranteed not to have changed between their + // `execution_time` and this one. + // + // If the query returns no results, a response with `execution_time` and no + // `results` will be sent, and this represents the time at which the operation + // was run. + google.protobuf.Timestamp execution_time = 3; + + // Query explain metrics. + // + // Set on the last response when [ExecutePipelineRequest.explain_options][] + // was specified on the request. + // ExplainMetrics explain_metrics = 4; +} + // The request for // [Firestore.RunAggregationQuery][google.firestore.v1.Firestore.RunAggregationQuery]. message RunAggregationQueryRequest { diff --git a/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/pipeline.proto b/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/pipeline.proto new file mode 100644 index 000000000..20f0c17be --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/pipeline.proto @@ -0,0 +1,26 @@ + +syntax = "proto3"; +package google.firestore.v1; +import "google/firestore/v1/document.proto"; +option csharp_namespace = "Google.Cloud.Firestore.V1"; +option php_namespace = "Google\\Cloud\\Firestore\\V1"; +option ruby_package = "Google::Cloud::Firestore::V1"; +option java_multiple_files = true; +option java_package = "com.google.firestore.v1"; +option java_outer_classname = "PipelineProto"; +option objc_class_prefix = "GCFS"; +// A Firestore query represented as an ordered list of operations / stages. +// +// This is considered the top-level function which plans & executes a query. +// It is logically equivalent to `query(stages, options)`, but prevents the +// client from having to build a function wrapper. +message StructuredPipeline { + // The pipeline query to execute. + Pipeline pipeline = 1; + // Optional query-level arguments. + // + // (-- Think query statement hints. --) + // + // (-- TODO(batchik): define the api contract of using an unsupported hint --) + map options = 2; +} From a557d4dc01f10c0ca54c21e23ef5210c0438ff73 Mon Sep 17 00:00:00 2001 From: wu-hui Date: Fri, 12 Apr 2024 18:47:15 +0000 Subject: [PATCH 30/65] pull in proto change and regenerate --- README.md | 8 +- .../firestore/v1/FirestoreAdminClient.java | 1228 ++++++- .../firestore/v1/FirestoreAdminSettings.java | 130 +- .../cloud/firestore/v1/gapic_metadata.json | 27 + .../cloud/firestore/v1/package-info.java | 2 +- .../firestore/v1/stub/FirestoreAdminStub.java | 58 +- .../v1/stub/FirestoreAdminStubSettings.java | 298 +- .../GrpcFirestoreAdminCallableFactory.java | 2 +- .../v1/stub/GrpcFirestoreAdminStub.java | 307 +- ...HttpJsonFirestoreAdminCallableFactory.java | 6 +- .../v1/stub/HttpJsonFirestoreAdminStub.java | 572 ++- .../reflect-config.json | 360 ++ .../v1/FirestoreAdminClientHttpJsonTest.java | 779 ++++- .../v1/FirestoreAdminClientTest.java | 686 +++- .../firestore/v1/MockFirestoreAdmin.java | 2 +- .../firestore/v1/MockFirestoreAdminImpl.java | 203 +- .../cloud/firestore/v1/MockLocations.java | 2 +- .../cloud/firestore/v1/MockLocationsImpl.java | 2 +- .../cloud/firestore/v1/FirestoreClient.java | 42 +- .../cloud/firestore/v1/FirestoreSettings.java | 19 +- .../cloud/firestore/v1/gapic_metadata.json | 3 + .../cloud/firestore/v1/package-info.java | 2 +- .../firestore/v1/stub/FirestoreStub.java | 9 +- .../v1/stub/FirestoreStubSettings.java | 34 +- .../v1/stub/GrpcFirestoreCallableFactory.java | 2 +- .../firestore/v1/stub/GrpcFirestoreStub.java | 37 +- .../HttpJsonFirestoreCallableFactory.java | 6 +- .../v1/stub/HttpJsonFirestoreStub.java | 67 +- .../reflect-config.json | 207 ++ .../cloud/firestore/it/ITPipelineTest.java | 2 +- .../v1/FirestoreClientHttpJsonTest.java | 13 +- .../firestore/v1/FirestoreClientTest.java | 50 +- .../cloud/firestore/v1/MockFirestore.java | 2 +- .../cloud/firestore/v1/MockFirestoreImpl.java | 25 +- .../cloud/firestore/v1/MockLocations.java | 2 +- .../cloud/firestore/v1/MockLocationsImpl.java | 2 +- .../admin/v1/FirestoreAdminGrpc.java | 1195 ++++++- .../google/firestore/v1/FirestoreGrpc.java | 118 +- .../com/google/firestore/admin/v1/Backup.java | 3067 +++++++++++++++++ .../google/firestore/admin/v1/BackupName.java | 223 ++ .../firestore/admin/v1/BackupOrBuilder.java | 276 ++ .../firestore/admin/v1/BackupProto.java | 111 + .../firestore/admin/v1/BackupSchedule.java | 2256 ++++++++++++ .../admin/v1/BackupScheduleName.java | 227 ++ .../admin/v1/BackupScheduleOrBuilder.java | 264 ++ .../admin/v1/CollectionGroupName.java | 2 +- .../admin/v1/CreateBackupScheduleRequest.java | 962 ++++++ .../CreateBackupScheduleRequestOrBuilder.java | 100 + .../firestore/admin/v1/DailyRecurrence.java | 435 +++ .../admin/v1/DailyRecurrenceOrBuilder.java | 25 + .../firestore/admin/v1/DatabaseName.java | 2 +- .../firestore/admin/v1/DatabaseProto.java | 88 +- .../admin/v1/DeleteBackupRequest.java | 655 ++++ .../v1/DeleteBackupRequestOrBuilder.java | 59 + .../admin/v1/DeleteBackupScheduleRequest.java | 661 ++++ .../DeleteBackupScheduleRequestOrBuilder.java | 61 + .../google/firestore/admin/v1/FieldName.java | 2 +- .../google/firestore/admin/v1/FieldProto.java | 42 +- .../admin/v1/FirestoreAdminProto.java | 513 ++- .../firestore/admin/v1/GetBackupRequest.java | 654 ++++ .../admin/v1/GetBackupRequestOrBuilder.java | 59 + .../admin/v1/GetBackupScheduleRequest.java | 663 ++++ .../v1/GetBackupScheduleRequestOrBuilder.java | 61 + .../com/google/firestore/admin/v1/Index.java | 1869 +++++++++- .../google/firestore/admin/v1/IndexName.java | 2 +- .../google/firestore/admin/v1/IndexProto.java | 100 +- .../admin/v1/ListBackupSchedulesRequest.java | 656 ++++ .../ListBackupSchedulesRequestOrBuilder.java | 59 + .../admin/v1/ListBackupSchedulesResponse.java | 950 +++++ .../ListBackupSchedulesResponseOrBuilder.java | 78 + .../admin/v1/ListBackupsRequest.java | 676 ++++ .../admin/v1/ListBackupsRequestOrBuilder.java | 65 + .../admin/v1/ListBackupsResponse.java | 1279 +++++++ .../v1/ListBackupsResponseOrBuilder.java | 148 + .../firestore/admin/v1/LocationName.java | 192 ++ .../firestore/admin/v1/OperationProto.java | 52 +- .../firestore/admin/v1/ProjectName.java | 2 +- .../admin/v1/RestoreDatabaseMetadata.java | 1764 ++++++++++ .../v1/RestoreDatabaseMetadataOrBuilder.java | 206 ++ .../admin/v1/RestoreDatabaseRequest.java | 1103 ++++++ .../v1/RestoreDatabaseRequestOrBuilder.java | 133 + .../firestore/admin/v1/ScheduleProto.java | 131 + .../admin/v1/UpdateBackupScheduleRequest.java | 1015 ++++++ .../UpdateBackupScheduleRequestOrBuilder.java | 102 + .../firestore/admin/v1/WeeklyRecurrence.java | 606 ++++ .../admin/v1/WeeklyRecurrenceOrBuilder.java | 55 + .../google/firestore/admin/v1/backup.proto | 107 + .../firestore/admin/v1/firestore_admin.proto | 275 ++ .../google/firestore/admin/v1/index.proto | 24 + .../google/firestore/admin/v1/operation.proto | 48 +- .../google/firestore/admin/v1/schedule.proto | 93 + .../google/firestore/v1/DocumentProto.java | 104 +- .../firestore/v1/ExecutePipelineRequest.java | 1898 ++++++++++ .../v1/ExecutePipelineRequestOrBuilder.java | 211 ++ .../firestore/v1/ExecutePipelineResponse.java | 1647 +++++++++ .../v1/ExecutePipelineResponseOrBuilder.java | 202 ++ .../google/firestore/v1/ExecutionStats.java | 1305 +++++++ .../firestore/v1/ExecutionStatsOrBuilder.java | 156 + .../google/firestore/v1/ExplainMetrics.java | 1014 ++++++ .../firestore/v1/ExplainMetricsOrBuilder.java | 102 + .../google/firestore/v1/ExplainOptions.java | 557 +++ .../firestore/v1/ExplainOptionsOrBuilder.java | 45 + .../google/firestore/v1/FirestoreProto.java | 546 +-- .../com/google/firestore/v1/Function.java | 1558 +++++++++ .../firestore/v1/FunctionOrBuilder.java | 168 + .../com/google/firestore/v1/Pipeline.java | 2640 ++++++++++++++ .../firestore/v1/PipelineOrBuilder.java | 78 + .../google/firestore/v1/PipelineProto.java | 87 + .../com/google/firestore/v1/PlanSummary.java | 1019 ++++++ .../firestore/v1/PlanSummaryOrBuilder.java | 97 + .../firestore/v1/QueryProfileProto.java | 128 + .../com/google/firestore/v1/QueryProto.java | 162 +- .../firestore/v1/StructuredPipeline.java | 1177 +++++++ .../v1/StructuredPipelineOrBuilder.java | 139 + .../google/firestore/v1/StructuredQuery.java | 2229 ++++++++++++ .../v1/StructuredQueryOrBuilder.java | 53 + .../java/com/google/firestore/v1/Value.java | 1190 +++++++ .../google/firestore/v1/ValueOrBuilder.java | 209 ++ .../proto/google/firestore/v1/document.proto | 1 + .../proto/google/firestore/v1/pipeline.proto | 1 + .../proto/google/firestore/v1/query.proto | 52 + .../google/firestore/v1/query_profile.proto | 92 + 122 files changed, 47874 insertions(+), 760 deletions(-) create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/Backup.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupName.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupOrBuilder.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupProto.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupSchedule.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupScheduleName.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupScheduleOrBuilder.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/CreateBackupScheduleRequest.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/CreateBackupScheduleRequestOrBuilder.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DailyRecurrence.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DailyRecurrenceOrBuilder.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DeleteBackupRequest.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DeleteBackupRequestOrBuilder.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DeleteBackupScheduleRequest.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DeleteBackupScheduleRequestOrBuilder.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/GetBackupRequest.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/GetBackupRequestOrBuilder.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/GetBackupScheduleRequest.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/GetBackupScheduleRequestOrBuilder.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupSchedulesRequest.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupSchedulesRequestOrBuilder.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupSchedulesResponse.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupSchedulesResponseOrBuilder.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupsRequest.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupsRequestOrBuilder.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupsResponse.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupsResponseOrBuilder.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/LocationName.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/RestoreDatabaseMetadata.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/RestoreDatabaseMetadataOrBuilder.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/RestoreDatabaseRequest.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/RestoreDatabaseRequestOrBuilder.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ScheduleProto.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/UpdateBackupScheduleRequest.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/UpdateBackupScheduleRequestOrBuilder.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/WeeklyRecurrence.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/WeeklyRecurrenceOrBuilder.java create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/backup.proto create mode 100644 proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/schedule.proto create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutePipelineRequest.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutePipelineRequestOrBuilder.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutePipelineResponse.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutePipelineResponseOrBuilder.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutionStats.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutionStatsOrBuilder.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExplainMetrics.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExplainMetricsOrBuilder.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExplainOptions.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExplainOptionsOrBuilder.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/Function.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/FunctionOrBuilder.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/Pipeline.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/PipelineOrBuilder.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/PipelineProto.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/PlanSummary.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/PlanSummaryOrBuilder.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/QueryProfileProto.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/StructuredPipeline.java create mode 100644 proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/StructuredPipelineOrBuilder.java create mode 100644 proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/query_profile.proto diff --git a/README.md b/README.md index 01a437f4c..050eb8250 100644 --- a/README.md +++ b/README.md @@ -50,20 +50,20 @@ If you are using Maven without the BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies: ```Groovy -implementation platform('com.google.cloud:libraries-bom:26.31.0') +implementation platform('com.google.cloud:libraries-bom:26.37.0') implementation 'com.google.cloud:google-cloud-firestore' ``` If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-firestore:3.16.1' +implementation 'com.google.cloud:google-cloud-firestore:3.20.0' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-firestore" % "3.16.1" +libraryDependencies += "com.google.cloud" % "google-cloud-firestore" % "3.20.0" ``` @@ -222,7 +222,7 @@ Java is a registered trademark of Oracle and/or its affiliates. [kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-firestore/java11.html [stability-image]: https://img.shields.io/badge/stability-stable-green [maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-firestore.svg -[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-firestore/3.16.1 +[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-firestore/3.20.0 [authentication]: https://github.com/googleapis/google-cloud-java#authentication [auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes [predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles diff --git a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminClient.java b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminClient.java index 49ceb63c4..c1f9108d3 100644 --- a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminClient.java +++ b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,12 +31,19 @@ import com.google.cloud.firestore.v1.stub.FirestoreAdminStub; import com.google.cloud.firestore.v1.stub.FirestoreAdminStubSettings; import com.google.common.util.concurrent.MoreExecutors; +import com.google.firestore.admin.v1.Backup; +import com.google.firestore.admin.v1.BackupName; +import com.google.firestore.admin.v1.BackupSchedule; +import com.google.firestore.admin.v1.BackupScheduleName; import com.google.firestore.admin.v1.CollectionGroupName; +import com.google.firestore.admin.v1.CreateBackupScheduleRequest; import com.google.firestore.admin.v1.CreateDatabaseMetadata; import com.google.firestore.admin.v1.CreateDatabaseRequest; import com.google.firestore.admin.v1.CreateIndexRequest; import com.google.firestore.admin.v1.Database; import com.google.firestore.admin.v1.DatabaseName; +import com.google.firestore.admin.v1.DeleteBackupRequest; +import com.google.firestore.admin.v1.DeleteBackupScheduleRequest; import com.google.firestore.admin.v1.DeleteDatabaseMetadata; import com.google.firestore.admin.v1.DeleteDatabaseRequest; import com.google.firestore.admin.v1.DeleteIndexRequest; @@ -46,6 +53,8 @@ import com.google.firestore.admin.v1.Field; import com.google.firestore.admin.v1.FieldName; import com.google.firestore.admin.v1.FieldOperationMetadata; +import com.google.firestore.admin.v1.GetBackupRequest; +import com.google.firestore.admin.v1.GetBackupScheduleRequest; import com.google.firestore.admin.v1.GetDatabaseRequest; import com.google.firestore.admin.v1.GetFieldRequest; import com.google.firestore.admin.v1.GetIndexRequest; @@ -54,13 +63,21 @@ import com.google.firestore.admin.v1.Index; import com.google.firestore.admin.v1.IndexName; import com.google.firestore.admin.v1.IndexOperationMetadata; +import com.google.firestore.admin.v1.ListBackupSchedulesRequest; +import com.google.firestore.admin.v1.ListBackupSchedulesResponse; +import com.google.firestore.admin.v1.ListBackupsRequest; +import com.google.firestore.admin.v1.ListBackupsResponse; import com.google.firestore.admin.v1.ListDatabasesRequest; import com.google.firestore.admin.v1.ListDatabasesResponse; import com.google.firestore.admin.v1.ListFieldsRequest; import com.google.firestore.admin.v1.ListFieldsResponse; import com.google.firestore.admin.v1.ListIndexesRequest; import com.google.firestore.admin.v1.ListIndexesResponse; +import com.google.firestore.admin.v1.LocationName; import com.google.firestore.admin.v1.ProjectName; +import com.google.firestore.admin.v1.RestoreDatabaseMetadata; +import com.google.firestore.admin.v1.RestoreDatabaseRequest; +import com.google.firestore.admin.v1.UpdateBackupScheduleRequest; import com.google.firestore.admin.v1.UpdateDatabaseMetadata; import com.google.firestore.admin.v1.UpdateDatabaseRequest; import com.google.firestore.admin.v1.UpdateFieldRequest; @@ -403,6 +420,174 @@ * * * + * + *

GetBackup + *

Gets information about a backup. + * + *

Request object method variants only take one parameter, a request object, which must be constructed before the call.

+ *
    + *
  • getBackup(GetBackupRequest request) + *

+ *

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

+ *
    + *
  • getBackup(BackupName name) + *

  • getBackup(String name) + *

+ *

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

+ *
    + *
  • getBackupCallable() + *

+ * + * + * + *

ListBackups + *

Lists all the backups. + * + *

Request object method variants only take one parameter, a request object, which must be constructed before the call.

+ *
    + *
  • listBackups(ListBackupsRequest request) + *

+ *

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

+ *
    + *
  • listBackups(LocationName parent) + *

  • listBackups(String parent) + *

+ *

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

+ *
    + *
  • listBackupsCallable() + *

+ * + * + * + *

DeleteBackup + *

Deletes a backup. + * + *

Request object method variants only take one parameter, a request object, which must be constructed before the call.

+ *
    + *
  • deleteBackup(DeleteBackupRequest request) + *

+ *

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

+ *
    + *
  • deleteBackup(BackupName name) + *

  • deleteBackup(String name) + *

+ *

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

+ *
    + *
  • deleteBackupCallable() + *

+ * + * + * + *

RestoreDatabase + *

Creates a new database by restoring from an existing backup. + *

The new database must be in the same cloud region or multi-region location as the existing backup. This behaves similar to [FirestoreAdmin.CreateDatabase][google.firestore.admin.v1.CreateDatabase] except instead of creating a new empty database, a new database is created with the database type, index configuration, and documents from an existing backup. + *

The [long-running operation][google.longrunning.Operation] can be used to track the progress of the restore, with the Operation's [metadata][google.longrunning.Operation.metadata] field type being the [RestoreDatabaseMetadata][google.firestore.admin.v1.RestoreDatabaseMetadata]. The [response][google.longrunning.Operation.response] type is the [Database][google.firestore.admin.v1.Database] if the restore was successful. The new database is not readable or writeable until the LRO has completed. + * + *

Request object method variants only take one parameter, a request object, which must be constructed before the call.

+ *
    + *
  • restoreDatabaseAsync(RestoreDatabaseRequest request) + *

+ *

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

+ *
    + *
  • restoreDatabaseOperationCallable() + *

  • restoreDatabaseCallable() + *

+ * + * + * + *

CreateBackupSchedule + *

Creates a backup schedule on a database. At most two backup schedules can be configured on a database, one daily backup schedule and one weekly backup schedule. + * + *

Request object method variants only take one parameter, a request object, which must be constructed before the call.

+ *
    + *
  • createBackupSchedule(CreateBackupScheduleRequest request) + *

+ *

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

+ *
    + *
  • createBackupSchedule(DatabaseName parent, BackupSchedule backupSchedule) + *

  • createBackupSchedule(String parent, BackupSchedule backupSchedule) + *

+ *

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

+ *
    + *
  • createBackupScheduleCallable() + *

+ * + * + * + *

GetBackupSchedule + *

Gets information about a backup schedule. + * + *

Request object method variants only take one parameter, a request object, which must be constructed before the call.

+ *
    + *
  • getBackupSchedule(GetBackupScheduleRequest request) + *

+ *

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

+ *
    + *
  • getBackupSchedule(BackupScheduleName name) + *

  • getBackupSchedule(String name) + *

+ *

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

+ *
    + *
  • getBackupScheduleCallable() + *

+ * + * + * + *

ListBackupSchedules + *

List backup schedules. + * + *

Request object method variants only take one parameter, a request object, which must be constructed before the call.

+ *
    + *
  • listBackupSchedules(ListBackupSchedulesRequest request) + *

+ *

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

+ *
    + *
  • listBackupSchedules(DatabaseName parent) + *

  • listBackupSchedules(String parent) + *

+ *

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

+ *
    + *
  • listBackupSchedulesCallable() + *

+ * + * + * + *

UpdateBackupSchedule + *

Updates a backup schedule. + * + *

Request object method variants only take one parameter, a request object, which must be constructed before the call.

+ *
    + *
  • updateBackupSchedule(UpdateBackupScheduleRequest request) + *

+ *

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

+ *
    + *
  • updateBackupSchedule(BackupSchedule backupSchedule, FieldMask updateMask) + *

+ *

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

+ *
    + *
  • updateBackupScheduleCallable() + *

+ * + * + * + *

DeleteBackupSchedule + *

Deletes a backup schedule. + * + *

Request object method variants only take one parameter, a request object, which must be constructed before the call.

+ *
    + *
  • deleteBackupSchedule(DeleteBackupScheduleRequest request) + *

+ *

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

+ *
    + *
  • deleteBackupSchedule(BackupScheduleName name) + *

  • deleteBackupSchedule(String name) + *

+ *

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

+ *
    + *
  • deleteBackupScheduleCallable() + *

+ * + * * * *

See the individual methods for example code. @@ -2584,6 +2769,1047 @@ public final UnaryCallable deleteDatabaseCalla return stub.deleteDatabaseCallable(); } + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Gets information about a backup. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   BackupName name = BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]");
+   *   Backup response = firestoreAdminClient.getBackup(name);
+   * }
+   * }
+ * + * @param name Required. Name of the backup to fetch. + *

Format is `projects/{project}/locations/{location}/backups/{backup}`. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Backup getBackup(BackupName name) { + GetBackupRequest request = + GetBackupRequest.newBuilder().setName(name == null ? null : name.toString()).build(); + return getBackup(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Gets information about a backup. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   String name = BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]").toString();
+   *   Backup response = firestoreAdminClient.getBackup(name);
+   * }
+   * }
+ * + * @param name Required. Name of the backup to fetch. + *

Format is `projects/{project}/locations/{location}/backups/{backup}`. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Backup getBackup(String name) { + GetBackupRequest request = GetBackupRequest.newBuilder().setName(name).build(); + return getBackup(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Gets information about a backup. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   GetBackupRequest request =
+   *       GetBackupRequest.newBuilder()
+   *           .setName(BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]").toString())
+   *           .build();
+   *   Backup response = firestoreAdminClient.getBackup(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Backup getBackup(GetBackupRequest request) { + return getBackupCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Gets information about a backup. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   GetBackupRequest request =
+   *       GetBackupRequest.newBuilder()
+   *           .setName(BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]").toString())
+   *           .build();
+   *   ApiFuture future = firestoreAdminClient.getBackupCallable().futureCall(request);
+   *   // Do something.
+   *   Backup response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable getBackupCallable() { + return stub.getBackupCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists all the backups. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+   *   ListBackupsResponse response = firestoreAdminClient.listBackups(parent);
+   * }
+   * }
+ * + * @param parent Required. The location to list backups from. + *

Format is `projects/{project}/locations/{location}`. Use `{location} = '-'` to list + * backups from all locations for the given project. This allows listing backups from a single + * location or from all locations. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListBackupsResponse listBackups(LocationName parent) { + ListBackupsRequest request = + ListBackupsRequest.newBuilder() + .setParent(parent == null ? null : parent.toString()) + .build(); + return listBackups(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists all the backups. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
+   *   ListBackupsResponse response = firestoreAdminClient.listBackups(parent);
+   * }
+   * }
+ * + * @param parent Required. The location to list backups from. + *

Format is `projects/{project}/locations/{location}`. Use `{location} = '-'` to list + * backups from all locations for the given project. This allows listing backups from a single + * location or from all locations. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListBackupsResponse listBackups(String parent) { + ListBackupsRequest request = ListBackupsRequest.newBuilder().setParent(parent).build(); + return listBackups(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists all the backups. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   ListBackupsRequest request =
+   *       ListBackupsRequest.newBuilder()
+   *           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
+   *           .build();
+   *   ListBackupsResponse response = firestoreAdminClient.listBackups(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListBackupsResponse listBackups(ListBackupsRequest request) { + return listBackupsCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists all the backups. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   ListBackupsRequest request =
+   *       ListBackupsRequest.newBuilder()
+   *           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
+   *           .build();
+   *   ApiFuture future =
+   *       firestoreAdminClient.listBackupsCallable().futureCall(request);
+   *   // Do something.
+   *   ListBackupsResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable listBackupsCallable() { + return stub.listBackupsCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a backup. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   BackupName name = BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]");
+   *   firestoreAdminClient.deleteBackup(name);
+   * }
+   * }
+ * + * @param name Required. Name of the backup to delete. + *

format is `projects/{project}/locations/{location}/backups/{backup}`. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteBackup(BackupName name) { + DeleteBackupRequest request = + DeleteBackupRequest.newBuilder().setName(name == null ? null : name.toString()).build(); + deleteBackup(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a backup. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   String name = BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]").toString();
+   *   firestoreAdminClient.deleteBackup(name);
+   * }
+   * }
+ * + * @param name Required. Name of the backup to delete. + *

format is `projects/{project}/locations/{location}/backups/{backup}`. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteBackup(String name) { + DeleteBackupRequest request = DeleteBackupRequest.newBuilder().setName(name).build(); + deleteBackup(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a backup. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   DeleteBackupRequest request =
+   *       DeleteBackupRequest.newBuilder()
+   *           .setName(BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]").toString())
+   *           .build();
+   *   firestoreAdminClient.deleteBackup(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteBackup(DeleteBackupRequest request) { + deleteBackupCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a backup. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   DeleteBackupRequest request =
+   *       DeleteBackupRequest.newBuilder()
+   *           .setName(BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]").toString())
+   *           .build();
+   *   ApiFuture future = firestoreAdminClient.deleteBackupCallable().futureCall(request);
+   *   // Do something.
+   *   future.get();
+   * }
+   * }
+ */ + public final UnaryCallable deleteBackupCallable() { + return stub.deleteBackupCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a new database by restoring from an existing backup. + * + *

The new database must be in the same cloud region or multi-region location as the existing + * backup. This behaves similar to + * [FirestoreAdmin.CreateDatabase][google.firestore.admin.v1.CreateDatabase] except instead of + * creating a new empty database, a new database is created with the database type, index + * configuration, and documents from an existing backup. + * + *

The [long-running operation][google.longrunning.Operation] can be used to track the progress + * of the restore, with the Operation's [metadata][google.longrunning.Operation.metadata] field + * type being the [RestoreDatabaseMetadata][google.firestore.admin.v1.RestoreDatabaseMetadata]. + * The [response][google.longrunning.Operation.response] type is the + * [Database][google.firestore.admin.v1.Database] if the restore was successful. The new database + * is not readable or writeable until the LRO has completed. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   RestoreDatabaseRequest request =
+   *       RestoreDatabaseRequest.newBuilder()
+   *           .setParent(ProjectName.of("[PROJECT]").toString())
+   *           .setDatabaseId("databaseId1688905718")
+   *           .setBackup(BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]").toString())
+   *           .build();
+   *   Database response = firestoreAdminClient.restoreDatabaseAsync(request).get();
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture restoreDatabaseAsync( + RestoreDatabaseRequest request) { + return restoreDatabaseOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a new database by restoring from an existing backup. + * + *

The new database must be in the same cloud region or multi-region location as the existing + * backup. This behaves similar to + * [FirestoreAdmin.CreateDatabase][google.firestore.admin.v1.CreateDatabase] except instead of + * creating a new empty database, a new database is created with the database type, index + * configuration, and documents from an existing backup. + * + *

The [long-running operation][google.longrunning.Operation] can be used to track the progress + * of the restore, with the Operation's [metadata][google.longrunning.Operation.metadata] field + * type being the [RestoreDatabaseMetadata][google.firestore.admin.v1.RestoreDatabaseMetadata]. + * The [response][google.longrunning.Operation.response] type is the + * [Database][google.firestore.admin.v1.Database] if the restore was successful. The new database + * is not readable or writeable until the LRO has completed. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   RestoreDatabaseRequest request =
+   *       RestoreDatabaseRequest.newBuilder()
+   *           .setParent(ProjectName.of("[PROJECT]").toString())
+   *           .setDatabaseId("databaseId1688905718")
+   *           .setBackup(BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]").toString())
+   *           .build();
+   *   OperationFuture future =
+   *       firestoreAdminClient.restoreDatabaseOperationCallable().futureCall(request);
+   *   // Do something.
+   *   Database response = future.get();
+   * }
+   * }
+ */ + public final OperationCallable + restoreDatabaseOperationCallable() { + return stub.restoreDatabaseOperationCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a new database by restoring from an existing backup. + * + *

The new database must be in the same cloud region or multi-region location as the existing + * backup. This behaves similar to + * [FirestoreAdmin.CreateDatabase][google.firestore.admin.v1.CreateDatabase] except instead of + * creating a new empty database, a new database is created with the database type, index + * configuration, and documents from an existing backup. + * + *

The [long-running operation][google.longrunning.Operation] can be used to track the progress + * of the restore, with the Operation's [metadata][google.longrunning.Operation.metadata] field + * type being the [RestoreDatabaseMetadata][google.firestore.admin.v1.RestoreDatabaseMetadata]. + * The [response][google.longrunning.Operation.response] type is the + * [Database][google.firestore.admin.v1.Database] if the restore was successful. The new database + * is not readable or writeable until the LRO has completed. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   RestoreDatabaseRequest request =
+   *       RestoreDatabaseRequest.newBuilder()
+   *           .setParent(ProjectName.of("[PROJECT]").toString())
+   *           .setDatabaseId("databaseId1688905718")
+   *           .setBackup(BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]").toString())
+   *           .build();
+   *   ApiFuture future =
+   *       firestoreAdminClient.restoreDatabaseCallable().futureCall(request);
+   *   // Do something.
+   *   Operation response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable restoreDatabaseCallable() { + return stub.restoreDatabaseCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a backup schedule on a database. At most two backup schedules can be configured on a + * database, one daily backup schedule and one weekly backup schedule. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   DatabaseName parent = DatabaseName.of("[PROJECT]", "[DATABASE]");
+   *   BackupSchedule backupSchedule = BackupSchedule.newBuilder().build();
+   *   BackupSchedule response = firestoreAdminClient.createBackupSchedule(parent, backupSchedule);
+   * }
+   * }
+ * + * @param parent Required. The parent database. + *

Format `projects/{project}/databases/{database}` + * @param backupSchedule Required. The backup schedule to create. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final BackupSchedule createBackupSchedule( + DatabaseName parent, BackupSchedule backupSchedule) { + CreateBackupScheduleRequest request = + CreateBackupScheduleRequest.newBuilder() + .setParent(parent == null ? null : parent.toString()) + .setBackupSchedule(backupSchedule) + .build(); + return createBackupSchedule(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a backup schedule on a database. At most two backup schedules can be configured on a + * database, one daily backup schedule and one weekly backup schedule. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   String parent = DatabaseName.of("[PROJECT]", "[DATABASE]").toString();
+   *   BackupSchedule backupSchedule = BackupSchedule.newBuilder().build();
+   *   BackupSchedule response = firestoreAdminClient.createBackupSchedule(parent, backupSchedule);
+   * }
+   * }
+ * + * @param parent Required. The parent database. + *

Format `projects/{project}/databases/{database}` + * @param backupSchedule Required. The backup schedule to create. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final BackupSchedule createBackupSchedule(String parent, BackupSchedule backupSchedule) { + CreateBackupScheduleRequest request = + CreateBackupScheduleRequest.newBuilder() + .setParent(parent) + .setBackupSchedule(backupSchedule) + .build(); + return createBackupSchedule(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a backup schedule on a database. At most two backup schedules can be configured on a + * database, one daily backup schedule and one weekly backup schedule. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   CreateBackupScheduleRequest request =
+   *       CreateBackupScheduleRequest.newBuilder()
+   *           .setParent(DatabaseName.of("[PROJECT]", "[DATABASE]").toString())
+   *           .setBackupSchedule(BackupSchedule.newBuilder().build())
+   *           .build();
+   *   BackupSchedule response = firestoreAdminClient.createBackupSchedule(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final BackupSchedule createBackupSchedule(CreateBackupScheduleRequest request) { + return createBackupScheduleCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a backup schedule on a database. At most two backup schedules can be configured on a + * database, one daily backup schedule and one weekly backup schedule. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   CreateBackupScheduleRequest request =
+   *       CreateBackupScheduleRequest.newBuilder()
+   *           .setParent(DatabaseName.of("[PROJECT]", "[DATABASE]").toString())
+   *           .setBackupSchedule(BackupSchedule.newBuilder().build())
+   *           .build();
+   *   ApiFuture future =
+   *       firestoreAdminClient.createBackupScheduleCallable().futureCall(request);
+   *   // Do something.
+   *   BackupSchedule response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable + createBackupScheduleCallable() { + return stub.createBackupScheduleCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Gets information about a backup schedule. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   BackupScheduleName name =
+   *       BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]");
+   *   BackupSchedule response = firestoreAdminClient.getBackupSchedule(name);
+   * }
+   * }
+ * + * @param name Required. The name of the backup schedule. + *

Format `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}` + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final BackupSchedule getBackupSchedule(BackupScheduleName name) { + GetBackupScheduleRequest request = + GetBackupScheduleRequest.newBuilder() + .setName(name == null ? null : name.toString()) + .build(); + return getBackupSchedule(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Gets information about a backup schedule. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   String name =
+   *       BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]").toString();
+   *   BackupSchedule response = firestoreAdminClient.getBackupSchedule(name);
+   * }
+   * }
+ * + * @param name Required. The name of the backup schedule. + *

Format `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}` + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final BackupSchedule getBackupSchedule(String name) { + GetBackupScheduleRequest request = GetBackupScheduleRequest.newBuilder().setName(name).build(); + return getBackupSchedule(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Gets information about a backup schedule. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   GetBackupScheduleRequest request =
+   *       GetBackupScheduleRequest.newBuilder()
+   *           .setName(
+   *               BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]").toString())
+   *           .build();
+   *   BackupSchedule response = firestoreAdminClient.getBackupSchedule(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final BackupSchedule getBackupSchedule(GetBackupScheduleRequest request) { + return getBackupScheduleCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Gets information about a backup schedule. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   GetBackupScheduleRequest request =
+   *       GetBackupScheduleRequest.newBuilder()
+   *           .setName(
+   *               BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]").toString())
+   *           .build();
+   *   ApiFuture future =
+   *       firestoreAdminClient.getBackupScheduleCallable().futureCall(request);
+   *   // Do something.
+   *   BackupSchedule response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable getBackupScheduleCallable() { + return stub.getBackupScheduleCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * List backup schedules. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   DatabaseName parent = DatabaseName.of("[PROJECT]", "[DATABASE]");
+   *   ListBackupSchedulesResponse response = firestoreAdminClient.listBackupSchedules(parent);
+   * }
+   * }
+ * + * @param parent Required. The parent database. + *

Format is `projects/{project}/databases/{database}`. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListBackupSchedulesResponse listBackupSchedules(DatabaseName parent) { + ListBackupSchedulesRequest request = + ListBackupSchedulesRequest.newBuilder() + .setParent(parent == null ? null : parent.toString()) + .build(); + return listBackupSchedules(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * List backup schedules. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   String parent = DatabaseName.of("[PROJECT]", "[DATABASE]").toString();
+   *   ListBackupSchedulesResponse response = firestoreAdminClient.listBackupSchedules(parent);
+   * }
+   * }
+ * + * @param parent Required. The parent database. + *

Format is `projects/{project}/databases/{database}`. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListBackupSchedulesResponse listBackupSchedules(String parent) { + ListBackupSchedulesRequest request = + ListBackupSchedulesRequest.newBuilder().setParent(parent).build(); + return listBackupSchedules(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * List backup schedules. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   ListBackupSchedulesRequest request =
+   *       ListBackupSchedulesRequest.newBuilder()
+   *           .setParent(DatabaseName.of("[PROJECT]", "[DATABASE]").toString())
+   *           .build();
+   *   ListBackupSchedulesResponse response = firestoreAdminClient.listBackupSchedules(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListBackupSchedulesResponse listBackupSchedules(ListBackupSchedulesRequest request) { + return listBackupSchedulesCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * List backup schedules. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   ListBackupSchedulesRequest request =
+   *       ListBackupSchedulesRequest.newBuilder()
+   *           .setParent(DatabaseName.of("[PROJECT]", "[DATABASE]").toString())
+   *           .build();
+   *   ApiFuture future =
+   *       firestoreAdminClient.listBackupSchedulesCallable().futureCall(request);
+   *   // Do something.
+   *   ListBackupSchedulesResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable + listBackupSchedulesCallable() { + return stub.listBackupSchedulesCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Updates a backup schedule. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   BackupSchedule backupSchedule = BackupSchedule.newBuilder().build();
+   *   FieldMask updateMask = FieldMask.newBuilder().build();
+   *   BackupSchedule response =
+   *       firestoreAdminClient.updateBackupSchedule(backupSchedule, updateMask);
+   * }
+   * }
+ * + * @param backupSchedule Required. The backup schedule to update. + * @param updateMask The list of fields to be updated. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final BackupSchedule updateBackupSchedule( + BackupSchedule backupSchedule, FieldMask updateMask) { + UpdateBackupScheduleRequest request = + UpdateBackupScheduleRequest.newBuilder() + .setBackupSchedule(backupSchedule) + .setUpdateMask(updateMask) + .build(); + return updateBackupSchedule(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Updates a backup schedule. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   UpdateBackupScheduleRequest request =
+   *       UpdateBackupScheduleRequest.newBuilder()
+   *           .setBackupSchedule(BackupSchedule.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   BackupSchedule response = firestoreAdminClient.updateBackupSchedule(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final BackupSchedule updateBackupSchedule(UpdateBackupScheduleRequest request) { + return updateBackupScheduleCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Updates a backup schedule. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   UpdateBackupScheduleRequest request =
+   *       UpdateBackupScheduleRequest.newBuilder()
+   *           .setBackupSchedule(BackupSchedule.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   ApiFuture future =
+   *       firestoreAdminClient.updateBackupScheduleCallable().futureCall(request);
+   *   // Do something.
+   *   BackupSchedule response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable + updateBackupScheduleCallable() { + return stub.updateBackupScheduleCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a backup schedule. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   BackupScheduleName name =
+   *       BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]");
+   *   firestoreAdminClient.deleteBackupSchedule(name);
+   * }
+   * }
+ * + * @param name Required. The name of the backup schedule. + *

Format `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}` + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteBackupSchedule(BackupScheduleName name) { + DeleteBackupScheduleRequest request = + DeleteBackupScheduleRequest.newBuilder() + .setName(name == null ? null : name.toString()) + .build(); + deleteBackupSchedule(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a backup schedule. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   String name =
+   *       BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]").toString();
+   *   firestoreAdminClient.deleteBackupSchedule(name);
+   * }
+   * }
+ * + * @param name Required. The name of the backup schedule. + *

Format `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}` + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteBackupSchedule(String name) { + DeleteBackupScheduleRequest request = + DeleteBackupScheduleRequest.newBuilder().setName(name).build(); + deleteBackupSchedule(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a backup schedule. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   DeleteBackupScheduleRequest request =
+   *       DeleteBackupScheduleRequest.newBuilder()
+   *           .setName(
+   *               BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]").toString())
+   *           .build();
+   *   firestoreAdminClient.deleteBackupSchedule(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteBackupSchedule(DeleteBackupScheduleRequest request) { + deleteBackupScheduleCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a backup schedule. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
+   *   DeleteBackupScheduleRequest request =
+   *       DeleteBackupScheduleRequest.newBuilder()
+   *           .setName(
+   *               BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]").toString())
+   *           .build();
+   *   ApiFuture future =
+   *       firestoreAdminClient.deleteBackupScheduleCallable().futureCall(request);
+   *   // Do something.
+   *   future.get();
+   * }
+   * }
+ */ + public final UnaryCallable deleteBackupScheduleCallable() { + return stub.deleteBackupScheduleCallable(); + } + @Override public final void close() { stub.close(); diff --git a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminSettings.java b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminSettings.java index cd4f0a14e..476ccec67 100644 --- a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminSettings.java +++ b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminSettings.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,10 +33,15 @@ import com.google.api.gax.rpc.TransportChannelProvider; import com.google.api.gax.rpc.UnaryCallSettings; import com.google.cloud.firestore.v1.stub.FirestoreAdminStubSettings; +import com.google.firestore.admin.v1.Backup; +import com.google.firestore.admin.v1.BackupSchedule; +import com.google.firestore.admin.v1.CreateBackupScheduleRequest; import com.google.firestore.admin.v1.CreateDatabaseMetadata; import com.google.firestore.admin.v1.CreateDatabaseRequest; import com.google.firestore.admin.v1.CreateIndexRequest; import com.google.firestore.admin.v1.Database; +import com.google.firestore.admin.v1.DeleteBackupRequest; +import com.google.firestore.admin.v1.DeleteBackupScheduleRequest; import com.google.firestore.admin.v1.DeleteDatabaseMetadata; import com.google.firestore.admin.v1.DeleteDatabaseRequest; import com.google.firestore.admin.v1.DeleteIndexRequest; @@ -45,6 +50,8 @@ import com.google.firestore.admin.v1.ExportDocumentsResponse; import com.google.firestore.admin.v1.Field; import com.google.firestore.admin.v1.FieldOperationMetadata; +import com.google.firestore.admin.v1.GetBackupRequest; +import com.google.firestore.admin.v1.GetBackupScheduleRequest; import com.google.firestore.admin.v1.GetDatabaseRequest; import com.google.firestore.admin.v1.GetFieldRequest; import com.google.firestore.admin.v1.GetIndexRequest; @@ -52,12 +59,19 @@ import com.google.firestore.admin.v1.ImportDocumentsRequest; import com.google.firestore.admin.v1.Index; import com.google.firestore.admin.v1.IndexOperationMetadata; +import com.google.firestore.admin.v1.ListBackupSchedulesRequest; +import com.google.firestore.admin.v1.ListBackupSchedulesResponse; +import com.google.firestore.admin.v1.ListBackupsRequest; +import com.google.firestore.admin.v1.ListBackupsResponse; import com.google.firestore.admin.v1.ListDatabasesRequest; import com.google.firestore.admin.v1.ListDatabasesResponse; import com.google.firestore.admin.v1.ListFieldsRequest; import com.google.firestore.admin.v1.ListFieldsResponse; import com.google.firestore.admin.v1.ListIndexesRequest; import com.google.firestore.admin.v1.ListIndexesResponse; +import com.google.firestore.admin.v1.RestoreDatabaseMetadata; +import com.google.firestore.admin.v1.RestoreDatabaseRequest; +import com.google.firestore.admin.v1.UpdateBackupScheduleRequest; import com.google.firestore.admin.v1.UpdateDatabaseMetadata; import com.google.firestore.admin.v1.UpdateDatabaseRequest; import com.google.firestore.admin.v1.UpdateFieldRequest; @@ -222,6 +236,60 @@ public UnaryCallSettings deleteDatabaseSetting return ((FirestoreAdminStubSettings) getStubSettings()).deleteDatabaseOperationSettings(); } + /** Returns the object with the settings used for calls to getBackup. */ + public UnaryCallSettings getBackupSettings() { + return ((FirestoreAdminStubSettings) getStubSettings()).getBackupSettings(); + } + + /** Returns the object with the settings used for calls to listBackups. */ + public UnaryCallSettings listBackupsSettings() { + return ((FirestoreAdminStubSettings) getStubSettings()).listBackupsSettings(); + } + + /** Returns the object with the settings used for calls to deleteBackup. */ + public UnaryCallSettings deleteBackupSettings() { + return ((FirestoreAdminStubSettings) getStubSettings()).deleteBackupSettings(); + } + + /** Returns the object with the settings used for calls to restoreDatabase. */ + public UnaryCallSettings restoreDatabaseSettings() { + return ((FirestoreAdminStubSettings) getStubSettings()).restoreDatabaseSettings(); + } + + /** Returns the object with the settings used for calls to restoreDatabase. */ + public OperationCallSettings + restoreDatabaseOperationSettings() { + return ((FirestoreAdminStubSettings) getStubSettings()).restoreDatabaseOperationSettings(); + } + + /** Returns the object with the settings used for calls to createBackupSchedule. */ + public UnaryCallSettings + createBackupScheduleSettings() { + return ((FirestoreAdminStubSettings) getStubSettings()).createBackupScheduleSettings(); + } + + /** Returns the object with the settings used for calls to getBackupSchedule. */ + public UnaryCallSettings getBackupScheduleSettings() { + return ((FirestoreAdminStubSettings) getStubSettings()).getBackupScheduleSettings(); + } + + /** Returns the object with the settings used for calls to listBackupSchedules. */ + public UnaryCallSettings + listBackupSchedulesSettings() { + return ((FirestoreAdminStubSettings) getStubSettings()).listBackupSchedulesSettings(); + } + + /** Returns the object with the settings used for calls to updateBackupSchedule. */ + public UnaryCallSettings + updateBackupScheduleSettings() { + return ((FirestoreAdminStubSettings) getStubSettings()).updateBackupScheduleSettings(); + } + + /** Returns the object with the settings used for calls to deleteBackupSchedule. */ + public UnaryCallSettings deleteBackupScheduleSettings() { + return ((FirestoreAdminStubSettings) getStubSettings()).deleteBackupScheduleSettings(); + } + public static final FirestoreAdminSettings create(FirestoreAdminStubSettings stub) throws IOException { return new FirestoreAdminSettings.Builder(stub.toBuilder()).build(); @@ -263,7 +331,6 @@ public static TransportChannelProvider defaultTransportChannelProvider() { return FirestoreAdminStubSettings.defaultTransportChannelProvider(); } - @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { return FirestoreAdminStubSettings.defaultApiClientHeaderProviderBuilder(); } @@ -274,7 +341,6 @@ public static Builder newBuilder() { } /** Returns a new REST builder for this class. */ - @BetaApi public static Builder newHttpJsonBuilder() { return Builder.createHttpJsonDefault(); } @@ -316,7 +382,6 @@ private static Builder createDefault() { return new Builder(FirestoreAdminStubSettings.newBuilder()); } - @BetaApi private static Builder createHttpJsonDefault() { return new Builder(FirestoreAdminStubSettings.newHttpJsonBuilder()); } @@ -454,6 +519,63 @@ public UnaryCallSettings.Builder deleteDatabas return getStubSettingsBuilder().deleteDatabaseOperationSettings(); } + /** Returns the builder for the settings used for calls to getBackup. */ + public UnaryCallSettings.Builder getBackupSettings() { + return getStubSettingsBuilder().getBackupSettings(); + } + + /** Returns the builder for the settings used for calls to listBackups. */ + public UnaryCallSettings.Builder + listBackupsSettings() { + return getStubSettingsBuilder().listBackupsSettings(); + } + + /** Returns the builder for the settings used for calls to deleteBackup. */ + public UnaryCallSettings.Builder deleteBackupSettings() { + return getStubSettingsBuilder().deleteBackupSettings(); + } + + /** Returns the builder for the settings used for calls to restoreDatabase. */ + public UnaryCallSettings.Builder restoreDatabaseSettings() { + return getStubSettingsBuilder().restoreDatabaseSettings(); + } + + /** Returns the builder for the settings used for calls to restoreDatabase. */ + public OperationCallSettings.Builder + restoreDatabaseOperationSettings() { + return getStubSettingsBuilder().restoreDatabaseOperationSettings(); + } + + /** Returns the builder for the settings used for calls to createBackupSchedule. */ + public UnaryCallSettings.Builder + createBackupScheduleSettings() { + return getStubSettingsBuilder().createBackupScheduleSettings(); + } + + /** Returns the builder for the settings used for calls to getBackupSchedule. */ + public UnaryCallSettings.Builder + getBackupScheduleSettings() { + return getStubSettingsBuilder().getBackupScheduleSettings(); + } + + /** Returns the builder for the settings used for calls to listBackupSchedules. */ + public UnaryCallSettings.Builder + listBackupSchedulesSettings() { + return getStubSettingsBuilder().listBackupSchedulesSettings(); + } + + /** Returns the builder for the settings used for calls to updateBackupSchedule. */ + public UnaryCallSettings.Builder + updateBackupScheduleSettings() { + return getStubSettingsBuilder().updateBackupScheduleSettings(); + } + + /** Returns the builder for the settings used for calls to deleteBackupSchedule. */ + public UnaryCallSettings.Builder + deleteBackupScheduleSettings() { + return getStubSettingsBuilder().deleteBackupScheduleSettings(); + } + @Override public FirestoreAdminSettings build() throws IOException { return new FirestoreAdminSettings(this); diff --git a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/gapic_metadata.json b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/gapic_metadata.json index aaa8b74b8..727ba40b1 100644 --- a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/gapic_metadata.json +++ b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/gapic_metadata.json @@ -10,12 +10,21 @@ "grpc": { "libraryClient": "FirestoreAdminClient", "rpcs": { + "CreateBackupSchedule": { + "methods": ["createBackupSchedule", "createBackupSchedule", "createBackupSchedule", "createBackupScheduleCallable"] + }, "CreateDatabase": { "methods": ["createDatabaseAsync", "createDatabaseAsync", "createDatabaseAsync", "createDatabaseOperationCallable", "createDatabaseCallable"] }, "CreateIndex": { "methods": ["createIndexAsync", "createIndexAsync", "createIndexAsync", "createIndexOperationCallable", "createIndexCallable"] }, + "DeleteBackup": { + "methods": ["deleteBackup", "deleteBackup", "deleteBackup", "deleteBackupCallable"] + }, + "DeleteBackupSchedule": { + "methods": ["deleteBackupSchedule", "deleteBackupSchedule", "deleteBackupSchedule", "deleteBackupScheduleCallable"] + }, "DeleteDatabase": { "methods": ["deleteDatabaseAsync", "deleteDatabaseAsync", "deleteDatabaseAsync", "deleteDatabaseOperationCallable", "deleteDatabaseCallable"] }, @@ -25,6 +34,12 @@ "ExportDocuments": { "methods": ["exportDocumentsAsync", "exportDocumentsAsync", "exportDocumentsAsync", "exportDocumentsOperationCallable", "exportDocumentsCallable"] }, + "GetBackup": { + "methods": ["getBackup", "getBackup", "getBackup", "getBackupCallable"] + }, + "GetBackupSchedule": { + "methods": ["getBackupSchedule", "getBackupSchedule", "getBackupSchedule", "getBackupScheduleCallable"] + }, "GetDatabase": { "methods": ["getDatabase", "getDatabase", "getDatabase", "getDatabaseCallable"] }, @@ -37,6 +52,12 @@ "ImportDocuments": { "methods": ["importDocumentsAsync", "importDocumentsAsync", "importDocumentsAsync", "importDocumentsOperationCallable", "importDocumentsCallable"] }, + "ListBackupSchedules": { + "methods": ["listBackupSchedules", "listBackupSchedules", "listBackupSchedules", "listBackupSchedulesCallable"] + }, + "ListBackups": { + "methods": ["listBackups", "listBackups", "listBackups", "listBackupsCallable"] + }, "ListDatabases": { "methods": ["listDatabases", "listDatabases", "listDatabases", "listDatabasesCallable"] }, @@ -46,6 +67,12 @@ "ListIndexes": { "methods": ["listIndexes", "listIndexes", "listIndexes", "listIndexesPagedCallable", "listIndexesCallable"] }, + "RestoreDatabase": { + "methods": ["restoreDatabaseAsync", "restoreDatabaseOperationCallable", "restoreDatabaseCallable"] + }, + "UpdateBackupSchedule": { + "methods": ["updateBackupSchedule", "updateBackupSchedule", "updateBackupScheduleCallable"] + }, "UpdateDatabase": { "methods": ["updateDatabaseAsync", "updateDatabaseAsync", "updateDatabaseOperationCallable", "updateDatabaseCallable"] }, diff --git a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/package-info.java b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/package-info.java index aded2d748..8aa41ba08 100644 --- a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/package-info.java +++ b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreAdminStub.java b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreAdminStub.java index dc8279df5..26db1092a 100644 --- a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreAdminStub.java +++ b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreAdminStub.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,10 +22,15 @@ import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.rpc.OperationCallable; import com.google.api.gax.rpc.UnaryCallable; +import com.google.firestore.admin.v1.Backup; +import com.google.firestore.admin.v1.BackupSchedule; +import com.google.firestore.admin.v1.CreateBackupScheduleRequest; import com.google.firestore.admin.v1.CreateDatabaseMetadata; import com.google.firestore.admin.v1.CreateDatabaseRequest; import com.google.firestore.admin.v1.CreateIndexRequest; import com.google.firestore.admin.v1.Database; +import com.google.firestore.admin.v1.DeleteBackupRequest; +import com.google.firestore.admin.v1.DeleteBackupScheduleRequest; import com.google.firestore.admin.v1.DeleteDatabaseMetadata; import com.google.firestore.admin.v1.DeleteDatabaseRequest; import com.google.firestore.admin.v1.DeleteIndexRequest; @@ -34,6 +39,8 @@ import com.google.firestore.admin.v1.ExportDocumentsResponse; import com.google.firestore.admin.v1.Field; import com.google.firestore.admin.v1.FieldOperationMetadata; +import com.google.firestore.admin.v1.GetBackupRequest; +import com.google.firestore.admin.v1.GetBackupScheduleRequest; import com.google.firestore.admin.v1.GetDatabaseRequest; import com.google.firestore.admin.v1.GetFieldRequest; import com.google.firestore.admin.v1.GetIndexRequest; @@ -41,12 +48,19 @@ import com.google.firestore.admin.v1.ImportDocumentsRequest; import com.google.firestore.admin.v1.Index; import com.google.firestore.admin.v1.IndexOperationMetadata; +import com.google.firestore.admin.v1.ListBackupSchedulesRequest; +import com.google.firestore.admin.v1.ListBackupSchedulesResponse; +import com.google.firestore.admin.v1.ListBackupsRequest; +import com.google.firestore.admin.v1.ListBackupsResponse; import com.google.firestore.admin.v1.ListDatabasesRequest; import com.google.firestore.admin.v1.ListDatabasesResponse; import com.google.firestore.admin.v1.ListFieldsRequest; import com.google.firestore.admin.v1.ListFieldsResponse; import com.google.firestore.admin.v1.ListIndexesRequest; import com.google.firestore.admin.v1.ListIndexesResponse; +import com.google.firestore.admin.v1.RestoreDatabaseMetadata; +import com.google.firestore.admin.v1.RestoreDatabaseRequest; +import com.google.firestore.admin.v1.UpdateBackupScheduleRequest; import com.google.firestore.admin.v1.UpdateDatabaseMetadata; import com.google.firestore.admin.v1.UpdateDatabaseRequest; import com.google.firestore.admin.v1.UpdateFieldRequest; @@ -171,6 +185,48 @@ public UnaryCallable deleteDatabaseCallable() throw new UnsupportedOperationException("Not implemented: deleteDatabaseCallable()"); } + public UnaryCallable getBackupCallable() { + throw new UnsupportedOperationException("Not implemented: getBackupCallable()"); + } + + public UnaryCallable listBackupsCallable() { + throw new UnsupportedOperationException("Not implemented: listBackupsCallable()"); + } + + public UnaryCallable deleteBackupCallable() { + throw new UnsupportedOperationException("Not implemented: deleteBackupCallable()"); + } + + public OperationCallable + restoreDatabaseOperationCallable() { + throw new UnsupportedOperationException("Not implemented: restoreDatabaseOperationCallable()"); + } + + public UnaryCallable restoreDatabaseCallable() { + throw new UnsupportedOperationException("Not implemented: restoreDatabaseCallable()"); + } + + public UnaryCallable createBackupScheduleCallable() { + throw new UnsupportedOperationException("Not implemented: createBackupScheduleCallable()"); + } + + public UnaryCallable getBackupScheduleCallable() { + throw new UnsupportedOperationException("Not implemented: getBackupScheduleCallable()"); + } + + public UnaryCallable + listBackupSchedulesCallable() { + throw new UnsupportedOperationException("Not implemented: listBackupSchedulesCallable()"); + } + + public UnaryCallable updateBackupScheduleCallable() { + throw new UnsupportedOperationException("Not implemented: updateBackupScheduleCallable()"); + } + + public UnaryCallable deleteBackupScheduleCallable() { + throw new UnsupportedOperationException("Not implemented: deleteBackupScheduleCallable()"); + } + @Override public abstract void close(); } diff --git a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreAdminStubSettings.java b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreAdminStubSettings.java index e7416e878..fbcf2bc14 100644 --- a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreAdminStubSettings.java +++ b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreAdminStubSettings.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,10 +52,15 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; +import com.google.firestore.admin.v1.Backup; +import com.google.firestore.admin.v1.BackupSchedule; +import com.google.firestore.admin.v1.CreateBackupScheduleRequest; import com.google.firestore.admin.v1.CreateDatabaseMetadata; import com.google.firestore.admin.v1.CreateDatabaseRequest; import com.google.firestore.admin.v1.CreateIndexRequest; import com.google.firestore.admin.v1.Database; +import com.google.firestore.admin.v1.DeleteBackupRequest; +import com.google.firestore.admin.v1.DeleteBackupScheduleRequest; import com.google.firestore.admin.v1.DeleteDatabaseMetadata; import com.google.firestore.admin.v1.DeleteDatabaseRequest; import com.google.firestore.admin.v1.DeleteIndexRequest; @@ -64,6 +69,8 @@ import com.google.firestore.admin.v1.ExportDocumentsResponse; import com.google.firestore.admin.v1.Field; import com.google.firestore.admin.v1.FieldOperationMetadata; +import com.google.firestore.admin.v1.GetBackupRequest; +import com.google.firestore.admin.v1.GetBackupScheduleRequest; import com.google.firestore.admin.v1.GetDatabaseRequest; import com.google.firestore.admin.v1.GetFieldRequest; import com.google.firestore.admin.v1.GetIndexRequest; @@ -71,12 +78,19 @@ import com.google.firestore.admin.v1.ImportDocumentsRequest; import com.google.firestore.admin.v1.Index; import com.google.firestore.admin.v1.IndexOperationMetadata; +import com.google.firestore.admin.v1.ListBackupSchedulesRequest; +import com.google.firestore.admin.v1.ListBackupSchedulesResponse; +import com.google.firestore.admin.v1.ListBackupsRequest; +import com.google.firestore.admin.v1.ListBackupsResponse; import com.google.firestore.admin.v1.ListDatabasesRequest; import com.google.firestore.admin.v1.ListDatabasesResponse; import com.google.firestore.admin.v1.ListFieldsRequest; import com.google.firestore.admin.v1.ListFieldsResponse; import com.google.firestore.admin.v1.ListIndexesRequest; import com.google.firestore.admin.v1.ListIndexesResponse; +import com.google.firestore.admin.v1.RestoreDatabaseMetadata; +import com.google.firestore.admin.v1.RestoreDatabaseRequest; +import com.google.firestore.admin.v1.UpdateBackupScheduleRequest; import com.google.firestore.admin.v1.UpdateDatabaseMetadata; import com.google.firestore.admin.v1.UpdateDatabaseRequest; import com.google.firestore.admin.v1.UpdateFieldRequest; @@ -165,6 +179,21 @@ public class FirestoreAdminStubSettings extends StubSettings deleteDatabaseSettings; private final OperationCallSettings deleteDatabaseOperationSettings; + private final UnaryCallSettings getBackupSettings; + private final UnaryCallSettings listBackupsSettings; + private final UnaryCallSettings deleteBackupSettings; + private final UnaryCallSettings restoreDatabaseSettings; + private final OperationCallSettings + restoreDatabaseOperationSettings; + private final UnaryCallSettings + createBackupScheduleSettings; + private final UnaryCallSettings + getBackupScheduleSettings; + private final UnaryCallSettings + listBackupSchedulesSettings; + private final UnaryCallSettings + updateBackupScheduleSettings; + private final UnaryCallSettings deleteBackupScheduleSettings; private static final PagedListDescriptor LIST_INDEXES_PAGE_STR_DESC = @@ -387,6 +416,60 @@ public UnaryCallSettings deleteDatabaseSetting return deleteDatabaseOperationSettings; } + /** Returns the object with the settings used for calls to getBackup. */ + public UnaryCallSettings getBackupSettings() { + return getBackupSettings; + } + + /** Returns the object with the settings used for calls to listBackups. */ + public UnaryCallSettings listBackupsSettings() { + return listBackupsSettings; + } + + /** Returns the object with the settings used for calls to deleteBackup. */ + public UnaryCallSettings deleteBackupSettings() { + return deleteBackupSettings; + } + + /** Returns the object with the settings used for calls to restoreDatabase. */ + public UnaryCallSettings restoreDatabaseSettings() { + return restoreDatabaseSettings; + } + + /** Returns the object with the settings used for calls to restoreDatabase. */ + public OperationCallSettings + restoreDatabaseOperationSettings() { + return restoreDatabaseOperationSettings; + } + + /** Returns the object with the settings used for calls to createBackupSchedule. */ + public UnaryCallSettings + createBackupScheduleSettings() { + return createBackupScheduleSettings; + } + + /** Returns the object with the settings used for calls to getBackupSchedule. */ + public UnaryCallSettings getBackupScheduleSettings() { + return getBackupScheduleSettings; + } + + /** Returns the object with the settings used for calls to listBackupSchedules. */ + public UnaryCallSettings + listBackupSchedulesSettings() { + return listBackupSchedulesSettings; + } + + /** Returns the object with the settings used for calls to updateBackupSchedule. */ + public UnaryCallSettings + updateBackupScheduleSettings() { + return updateBackupScheduleSettings; + } + + /** Returns the object with the settings used for calls to deleteBackupSchedule. */ + public UnaryCallSettings deleteBackupScheduleSettings() { + return deleteBackupScheduleSettings; + } + public FirestoreAdminStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() @@ -462,7 +545,6 @@ public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } - @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( @@ -471,7 +553,6 @@ public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProvider GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( @@ -529,6 +610,16 @@ protected FirestoreAdminStubSettings(Builder settingsBuilder) throws IOException updateDatabaseOperationSettings = settingsBuilder.updateDatabaseOperationSettings().build(); deleteDatabaseSettings = settingsBuilder.deleteDatabaseSettings().build(); deleteDatabaseOperationSettings = settingsBuilder.deleteDatabaseOperationSettings().build(); + getBackupSettings = settingsBuilder.getBackupSettings().build(); + listBackupsSettings = settingsBuilder.listBackupsSettings().build(); + deleteBackupSettings = settingsBuilder.deleteBackupSettings().build(); + restoreDatabaseSettings = settingsBuilder.restoreDatabaseSettings().build(); + restoreDatabaseOperationSettings = settingsBuilder.restoreDatabaseOperationSettings().build(); + createBackupScheduleSettings = settingsBuilder.createBackupScheduleSettings().build(); + getBackupScheduleSettings = settingsBuilder.getBackupScheduleSettings().build(); + listBackupSchedulesSettings = settingsBuilder.listBackupSchedulesSettings().build(); + updateBackupScheduleSettings = settingsBuilder.updateBackupScheduleSettings().build(); + deleteBackupScheduleSettings = settingsBuilder.deleteBackupScheduleSettings().build(); } /** Builder for FirestoreAdminStubSettings. */ @@ -577,6 +668,25 @@ public static class Builder extends StubSettings.Builder deleteDatabaseOperationSettings; + private final UnaryCallSettings.Builder getBackupSettings; + private final UnaryCallSettings.Builder + listBackupsSettings; + private final UnaryCallSettings.Builder deleteBackupSettings; + private final UnaryCallSettings.Builder + restoreDatabaseSettings; + private final OperationCallSettings.Builder< + RestoreDatabaseRequest, Database, RestoreDatabaseMetadata> + restoreDatabaseOperationSettings; + private final UnaryCallSettings.Builder + createBackupScheduleSettings; + private final UnaryCallSettings.Builder + getBackupScheduleSettings; + private final UnaryCallSettings.Builder + listBackupSchedulesSettings; + private final UnaryCallSettings.Builder + updateBackupScheduleSettings; + private final UnaryCallSettings.Builder + deleteBackupScheduleSettings; private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; @@ -653,6 +763,16 @@ protected Builder(ClientContext clientContext) { updateDatabaseOperationSettings = OperationCallSettings.newBuilder(); deleteDatabaseSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); deleteDatabaseOperationSettings = OperationCallSettings.newBuilder(); + getBackupSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + listBackupsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + deleteBackupSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + restoreDatabaseSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + restoreDatabaseOperationSettings = OperationCallSettings.newBuilder(); + createBackupScheduleSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + getBackupScheduleSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + listBackupSchedulesSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + updateBackupScheduleSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + deleteBackupScheduleSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); unaryMethodSettingsBuilders = ImmutableList.>of( @@ -669,7 +789,16 @@ protected Builder(ClientContext clientContext) { getDatabaseSettings, listDatabasesSettings, updateDatabaseSettings, - deleteDatabaseSettings); + deleteDatabaseSettings, + getBackupSettings, + listBackupsSettings, + deleteBackupSettings, + restoreDatabaseSettings, + createBackupScheduleSettings, + getBackupScheduleSettings, + listBackupSchedulesSettings, + updateBackupScheduleSettings, + deleteBackupScheduleSettings); initDefaults(this); } @@ -697,6 +826,16 @@ protected Builder(FirestoreAdminStubSettings settings) { updateDatabaseOperationSettings = settings.updateDatabaseOperationSettings.toBuilder(); deleteDatabaseSettings = settings.deleteDatabaseSettings.toBuilder(); deleteDatabaseOperationSettings = settings.deleteDatabaseOperationSettings.toBuilder(); + getBackupSettings = settings.getBackupSettings.toBuilder(); + listBackupsSettings = settings.listBackupsSettings.toBuilder(); + deleteBackupSettings = settings.deleteBackupSettings.toBuilder(); + restoreDatabaseSettings = settings.restoreDatabaseSettings.toBuilder(); + restoreDatabaseOperationSettings = settings.restoreDatabaseOperationSettings.toBuilder(); + createBackupScheduleSettings = settings.createBackupScheduleSettings.toBuilder(); + getBackupScheduleSettings = settings.getBackupScheduleSettings.toBuilder(); + listBackupSchedulesSettings = settings.listBackupSchedulesSettings.toBuilder(); + updateBackupScheduleSettings = settings.updateBackupScheduleSettings.toBuilder(); + deleteBackupScheduleSettings = settings.deleteBackupScheduleSettings.toBuilder(); unaryMethodSettingsBuilders = ImmutableList.>of( @@ -713,7 +852,16 @@ protected Builder(FirestoreAdminStubSettings settings) { getDatabaseSettings, listDatabasesSettings, updateDatabaseSettings, - deleteDatabaseSettings); + deleteDatabaseSettings, + getBackupSettings, + listBackupsSettings, + deleteBackupSettings, + restoreDatabaseSettings, + createBackupScheduleSettings, + getBackupScheduleSettings, + listBackupSchedulesSettings, + updateBackupScheduleSettings, + deleteBackupScheduleSettings); } private static Builder createDefault() { @@ -811,6 +959,51 @@ private static Builder initDefaults(Builder builder) { .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + builder + .getBackupSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .listBackupsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .deleteBackupSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .restoreDatabaseSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .createBackupScheduleSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .getBackupScheduleSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .listBackupSchedulesSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .updateBackupScheduleSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .deleteBackupScheduleSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + builder .createIndexOperationSettings() .setInitialCallSettings( @@ -977,6 +1170,30 @@ private static Builder initDefaults(Builder builder) { .setTotalTimeout(Duration.ofMillis(300000L)) .build())); + builder + .restoreDatabaseOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")) + .build()) + .setResponseTransformer( + ProtoOperationTransformers.ResponseTransformer.create(Database.class)) + .setMetadataTransformer( + ProtoOperationTransformers.MetadataTransformer.create(RestoreDatabaseMetadata.class)) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(5000L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(45000L)) + .setInitialRpcTimeout(Duration.ZERO) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) + .setTotalTimeout(Duration.ofMillis(300000L)) + .build())); + return builder; } @@ -1001,8 +1218,6 @@ public UnaryCallSettings.Builder createIndexSetti } /** Returns the builder for the settings used for calls to createIndex. */ - @BetaApi( - "The surface for use by generated code is not stable yet and may change in the future.") public OperationCallSettings.Builder createIndexOperationSettings() { return createIndexOperationSettings; @@ -1036,8 +1251,6 @@ public UnaryCallSettings.Builder updateFieldSetti } /** Returns the builder for the settings used for calls to updateField. */ - @BetaApi( - "The surface for use by generated code is not stable yet and may change in the future.") public OperationCallSettings.Builder updateFieldOperationSettings() { return updateFieldOperationSettings; @@ -1055,8 +1268,6 @@ public UnaryCallSettings.Builder exportDocume } /** Returns the builder for the settings used for calls to exportDocuments. */ - @BetaApi( - "The surface for use by generated code is not stable yet and may change in the future.") public OperationCallSettings.Builder< ExportDocumentsRequest, ExportDocumentsResponse, ExportDocumentsMetadata> exportDocumentsOperationSettings() { @@ -1069,8 +1280,6 @@ public UnaryCallSettings.Builder importDocume } /** Returns the builder for the settings used for calls to importDocuments. */ - @BetaApi( - "The surface for use by generated code is not stable yet and may change in the future.") public OperationCallSettings.Builder importDocumentsOperationSettings() { return importDocumentsOperationSettings; @@ -1082,8 +1291,6 @@ public UnaryCallSettings.Builder createDatabas } /** Returns the builder for the settings used for calls to createDatabase. */ - @BetaApi( - "The surface for use by generated code is not stable yet and may change in the future.") public OperationCallSettings.Builder createDatabaseOperationSettings() { return createDatabaseOperationSettings; @@ -1106,8 +1313,6 @@ public UnaryCallSettings.Builder updateDatabas } /** Returns the builder for the settings used for calls to updateDatabase. */ - @BetaApi( - "The surface for use by generated code is not stable yet and may change in the future.") public OperationCallSettings.Builder updateDatabaseOperationSettings() { return updateDatabaseOperationSettings; @@ -1119,13 +1324,68 @@ public UnaryCallSettings.Builder deleteDatabas } /** Returns the builder for the settings used for calls to deleteDatabase. */ - @BetaApi( - "The surface for use by generated code is not stable yet and may change in the future.") public OperationCallSettings.Builder deleteDatabaseOperationSettings() { return deleteDatabaseOperationSettings; } + /** Returns the builder for the settings used for calls to getBackup. */ + public UnaryCallSettings.Builder getBackupSettings() { + return getBackupSettings; + } + + /** Returns the builder for the settings used for calls to listBackups. */ + public UnaryCallSettings.Builder + listBackupsSettings() { + return listBackupsSettings; + } + + /** Returns the builder for the settings used for calls to deleteBackup. */ + public UnaryCallSettings.Builder deleteBackupSettings() { + return deleteBackupSettings; + } + + /** Returns the builder for the settings used for calls to restoreDatabase. */ + public UnaryCallSettings.Builder restoreDatabaseSettings() { + return restoreDatabaseSettings; + } + + /** Returns the builder for the settings used for calls to restoreDatabase. */ + public OperationCallSettings.Builder + restoreDatabaseOperationSettings() { + return restoreDatabaseOperationSettings; + } + + /** Returns the builder for the settings used for calls to createBackupSchedule. */ + public UnaryCallSettings.Builder + createBackupScheduleSettings() { + return createBackupScheduleSettings; + } + + /** Returns the builder for the settings used for calls to getBackupSchedule. */ + public UnaryCallSettings.Builder + getBackupScheduleSettings() { + return getBackupScheduleSettings; + } + + /** Returns the builder for the settings used for calls to listBackupSchedules. */ + public UnaryCallSettings.Builder + listBackupSchedulesSettings() { + return listBackupSchedulesSettings; + } + + /** Returns the builder for the settings used for calls to updateBackupSchedule. */ + public UnaryCallSettings.Builder + updateBackupScheduleSettings() { + return updateBackupScheduleSettings; + } + + /** Returns the builder for the settings used for calls to deleteBackupSchedule. */ + public UnaryCallSettings.Builder + deleteBackupScheduleSettings() { + return deleteBackupScheduleSettings; + } + /** Returns the endpoint set by the user or the the service's default endpoint. */ @Override public String getEndpoint() { diff --git a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/GrpcFirestoreAdminCallableFactory.java b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/GrpcFirestoreAdminCallableFactory.java index 7b4c53954..e25d62192 100644 --- a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/GrpcFirestoreAdminCallableFactory.java +++ b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/GrpcFirestoreAdminCallableFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/GrpcFirestoreAdminStub.java b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/GrpcFirestoreAdminStub.java index 54fdfbd6e..d0a883dc1 100644 --- a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/GrpcFirestoreAdminStub.java +++ b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/GrpcFirestoreAdminStub.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,10 +27,15 @@ import com.google.api.gax.rpc.OperationCallable; import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; +import com.google.firestore.admin.v1.Backup; +import com.google.firestore.admin.v1.BackupSchedule; +import com.google.firestore.admin.v1.CreateBackupScheduleRequest; import com.google.firestore.admin.v1.CreateDatabaseMetadata; import com.google.firestore.admin.v1.CreateDatabaseRequest; import com.google.firestore.admin.v1.CreateIndexRequest; import com.google.firestore.admin.v1.Database; +import com.google.firestore.admin.v1.DeleteBackupRequest; +import com.google.firestore.admin.v1.DeleteBackupScheduleRequest; import com.google.firestore.admin.v1.DeleteDatabaseMetadata; import com.google.firestore.admin.v1.DeleteDatabaseRequest; import com.google.firestore.admin.v1.DeleteIndexRequest; @@ -39,6 +44,8 @@ import com.google.firestore.admin.v1.ExportDocumentsResponse; import com.google.firestore.admin.v1.Field; import com.google.firestore.admin.v1.FieldOperationMetadata; +import com.google.firestore.admin.v1.GetBackupRequest; +import com.google.firestore.admin.v1.GetBackupScheduleRequest; import com.google.firestore.admin.v1.GetDatabaseRequest; import com.google.firestore.admin.v1.GetFieldRequest; import com.google.firestore.admin.v1.GetIndexRequest; @@ -46,12 +53,19 @@ import com.google.firestore.admin.v1.ImportDocumentsRequest; import com.google.firestore.admin.v1.Index; import com.google.firestore.admin.v1.IndexOperationMetadata; +import com.google.firestore.admin.v1.ListBackupSchedulesRequest; +import com.google.firestore.admin.v1.ListBackupSchedulesResponse; +import com.google.firestore.admin.v1.ListBackupsRequest; +import com.google.firestore.admin.v1.ListBackupsResponse; import com.google.firestore.admin.v1.ListDatabasesRequest; import com.google.firestore.admin.v1.ListDatabasesResponse; import com.google.firestore.admin.v1.ListFieldsRequest; import com.google.firestore.admin.v1.ListFieldsResponse; import com.google.firestore.admin.v1.ListIndexesRequest; import com.google.firestore.admin.v1.ListIndexesResponse; +import com.google.firestore.admin.v1.RestoreDatabaseMetadata; +import com.google.firestore.admin.v1.RestoreDatabaseRequest; +import com.google.firestore.admin.v1.UpdateBackupScheduleRequest; import com.google.firestore.admin.v1.UpdateDatabaseMetadata; import com.google.firestore.admin.v1.UpdateDatabaseRequest; import com.google.firestore.admin.v1.UpdateFieldRequest; @@ -200,6 +214,93 @@ public class GrpcFirestoreAdminStub extends FirestoreAdminStub { .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) .build(); + private static final MethodDescriptor getBackupMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/GetBackup") + .setRequestMarshaller(ProtoUtils.marshaller(GetBackupRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Backup.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + listBackupsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/ListBackups") + .setRequestMarshaller(ProtoUtils.marshaller(ListBackupsRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(ListBackupsResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor deleteBackupMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/DeleteBackup") + .setRequestMarshaller(ProtoUtils.marshaller(DeleteBackupRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + restoreDatabaseMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/RestoreDatabase") + .setRequestMarshaller( + ProtoUtils.marshaller(RestoreDatabaseRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + createBackupScheduleMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/CreateBackupSchedule") + .setRequestMarshaller( + ProtoUtils.marshaller(CreateBackupScheduleRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(BackupSchedule.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + getBackupScheduleMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/GetBackupSchedule") + .setRequestMarshaller( + ProtoUtils.marshaller(GetBackupScheduleRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(BackupSchedule.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + listBackupSchedulesMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/ListBackupSchedules") + .setRequestMarshaller( + ProtoUtils.marshaller(ListBackupSchedulesRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(ListBackupSchedulesResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + updateBackupScheduleMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/UpdateBackupSchedule") + .setRequestMarshaller( + ProtoUtils.marshaller(UpdateBackupScheduleRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(BackupSchedule.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + deleteBackupScheduleMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/DeleteBackupSchedule") + .setRequestMarshaller( + ProtoUtils.marshaller(DeleteBackupScheduleRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + private final UnaryCallable createIndexCallable; private final OperationCallable createIndexOperationCallable; @@ -232,6 +333,20 @@ public class GrpcFirestoreAdminStub extends FirestoreAdminStub { private final UnaryCallable deleteDatabaseCallable; private final OperationCallable deleteDatabaseOperationCallable; + private final UnaryCallable getBackupCallable; + private final UnaryCallable listBackupsCallable; + private final UnaryCallable deleteBackupCallable; + private final UnaryCallable restoreDatabaseCallable; + private final OperationCallable + restoreDatabaseOperationCallable; + private final UnaryCallable + createBackupScheduleCallable; + private final UnaryCallable getBackupScheduleCallable; + private final UnaryCallable + listBackupSchedulesCallable; + private final UnaryCallable + updateBackupScheduleCallable; + private final UnaryCallable deleteBackupScheduleCallable; private final BackgroundResource backgroundResources; private final GrpcOperationsStub operationsStub; @@ -417,6 +532,101 @@ protected GrpcFirestoreAdminStub( return builder.build(); }) .build(); + GrpcCallSettings getBackupTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getBackupMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) + .build(); + GrpcCallSettings listBackupsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(listBackupsMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) + .build(); + GrpcCallSettings deleteBackupTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(deleteBackupMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) + .build(); + GrpcCallSettings restoreDatabaseTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(restoreDatabaseMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) + .build(); + GrpcCallSettings + createBackupScheduleTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(createBackupScheduleMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) + .build(); + GrpcCallSettings getBackupScheduleTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getBackupScheduleMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) + .build(); + GrpcCallSettings + listBackupSchedulesTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(listBackupSchedulesMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) + .build(); + GrpcCallSettings + updateBackupScheduleTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(updateBackupScheduleMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( + "backup_schedule.name", + String.valueOf(request.getBackupSchedule().getName())); + return builder.build(); + }) + .build(); + GrpcCallSettings deleteBackupScheduleTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(deleteBackupScheduleMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) + .build(); this.createIndexCallable = callableFactory.createUnaryCallable( @@ -508,6 +718,49 @@ protected GrpcFirestoreAdminStub( settings.deleteDatabaseOperationSettings(), clientContext, operationsStub); + this.getBackupCallable = + callableFactory.createUnaryCallable( + getBackupTransportSettings, settings.getBackupSettings(), clientContext); + this.listBackupsCallable = + callableFactory.createUnaryCallable( + listBackupsTransportSettings, settings.listBackupsSettings(), clientContext); + this.deleteBackupCallable = + callableFactory.createUnaryCallable( + deleteBackupTransportSettings, settings.deleteBackupSettings(), clientContext); + this.restoreDatabaseCallable = + callableFactory.createUnaryCallable( + restoreDatabaseTransportSettings, settings.restoreDatabaseSettings(), clientContext); + this.restoreDatabaseOperationCallable = + callableFactory.createOperationCallable( + restoreDatabaseTransportSettings, + settings.restoreDatabaseOperationSettings(), + clientContext, + operationsStub); + this.createBackupScheduleCallable = + callableFactory.createUnaryCallable( + createBackupScheduleTransportSettings, + settings.createBackupScheduleSettings(), + clientContext); + this.getBackupScheduleCallable = + callableFactory.createUnaryCallable( + getBackupScheduleTransportSettings, + settings.getBackupScheduleSettings(), + clientContext); + this.listBackupSchedulesCallable = + callableFactory.createUnaryCallable( + listBackupSchedulesTransportSettings, + settings.listBackupSchedulesSettings(), + clientContext); + this.updateBackupScheduleCallable = + callableFactory.createUnaryCallable( + updateBackupScheduleTransportSettings, + settings.updateBackupScheduleSettings(), + clientContext); + this.deleteBackupScheduleCallable = + callableFactory.createUnaryCallable( + deleteBackupScheduleTransportSettings, + settings.deleteBackupScheduleSettings(), + clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); @@ -639,6 +892,58 @@ public UnaryCallable deleteDatabaseCallable() return deleteDatabaseOperationCallable; } + @Override + public UnaryCallable getBackupCallable() { + return getBackupCallable; + } + + @Override + public UnaryCallable listBackupsCallable() { + return listBackupsCallable; + } + + @Override + public UnaryCallable deleteBackupCallable() { + return deleteBackupCallable; + } + + @Override + public UnaryCallable restoreDatabaseCallable() { + return restoreDatabaseCallable; + } + + @Override + public OperationCallable + restoreDatabaseOperationCallable() { + return restoreDatabaseOperationCallable; + } + + @Override + public UnaryCallable createBackupScheduleCallable() { + return createBackupScheduleCallable; + } + + @Override + public UnaryCallable getBackupScheduleCallable() { + return getBackupScheduleCallable; + } + + @Override + public UnaryCallable + listBackupSchedulesCallable() { + return listBackupSchedulesCallable; + } + + @Override + public UnaryCallable updateBackupScheduleCallable() { + return updateBackupScheduleCallable; + } + + @Override + public UnaryCallable deleteBackupScheduleCallable() { + return deleteBackupScheduleCallable; + } + @Override public final void close() { try { diff --git a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreAdminCallableFactory.java b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreAdminCallableFactory.java index 6f8d4ecf6..1364aabb3 100644 --- a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreAdminCallableFactory.java +++ b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreAdminCallableFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package com.google.cloud.firestore.v1.stub; -import com.google.api.core.BetaApi; import com.google.api.gax.httpjson.HttpJsonCallSettings; import com.google.api.gax.httpjson.HttpJsonCallableFactory; import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; @@ -41,7 +40,6 @@ *

This class is for advanced usage. */ @Generated("by gapic-generator-java") -@BetaApi public class HttpJsonFirestoreAdminCallableFactory implements HttpJsonStubCallableFactory { @@ -73,8 +71,6 @@ public UnaryCallable createBatchingCa httpJsonCallSettings, callSettings, clientContext); } - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") @Override public OperationCallable createOperationCallable( diff --git a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreAdminStub.java b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreAdminStub.java index 7cbf5aecd..e81b9b65d 100644 --- a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreAdminStub.java +++ b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreAdminStub.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import static com.google.cloud.firestore.v1.FirestoreAdminClient.ListIndexesPagedResponse; import com.google.api.HttpRule; -import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; @@ -37,10 +36,15 @@ import com.google.api.gax.rpc.RequestParamsBuilder; import com.google.api.gax.rpc.UnaryCallable; import com.google.common.collect.ImmutableMap; +import com.google.firestore.admin.v1.Backup; +import com.google.firestore.admin.v1.BackupSchedule; +import com.google.firestore.admin.v1.CreateBackupScheduleRequest; import com.google.firestore.admin.v1.CreateDatabaseMetadata; import com.google.firestore.admin.v1.CreateDatabaseRequest; import com.google.firestore.admin.v1.CreateIndexRequest; import com.google.firestore.admin.v1.Database; +import com.google.firestore.admin.v1.DeleteBackupRequest; +import com.google.firestore.admin.v1.DeleteBackupScheduleRequest; import com.google.firestore.admin.v1.DeleteDatabaseMetadata; import com.google.firestore.admin.v1.DeleteDatabaseRequest; import com.google.firestore.admin.v1.DeleteIndexRequest; @@ -49,6 +53,8 @@ import com.google.firestore.admin.v1.ExportDocumentsResponse; import com.google.firestore.admin.v1.Field; import com.google.firestore.admin.v1.FieldOperationMetadata; +import com.google.firestore.admin.v1.GetBackupRequest; +import com.google.firestore.admin.v1.GetBackupScheduleRequest; import com.google.firestore.admin.v1.GetDatabaseRequest; import com.google.firestore.admin.v1.GetFieldRequest; import com.google.firestore.admin.v1.GetIndexRequest; @@ -56,12 +62,19 @@ import com.google.firestore.admin.v1.ImportDocumentsRequest; import com.google.firestore.admin.v1.Index; import com.google.firestore.admin.v1.IndexOperationMetadata; +import com.google.firestore.admin.v1.ListBackupSchedulesRequest; +import com.google.firestore.admin.v1.ListBackupSchedulesResponse; +import com.google.firestore.admin.v1.ListBackupsRequest; +import com.google.firestore.admin.v1.ListBackupsResponse; import com.google.firestore.admin.v1.ListDatabasesRequest; import com.google.firestore.admin.v1.ListDatabasesResponse; import com.google.firestore.admin.v1.ListFieldsRequest; import com.google.firestore.admin.v1.ListFieldsResponse; import com.google.firestore.admin.v1.ListIndexesRequest; import com.google.firestore.admin.v1.ListIndexesResponse; +import com.google.firestore.admin.v1.RestoreDatabaseMetadata; +import com.google.firestore.admin.v1.RestoreDatabaseRequest; +import com.google.firestore.admin.v1.UpdateBackupScheduleRequest; import com.google.firestore.admin.v1.UpdateDatabaseMetadata; import com.google.firestore.admin.v1.UpdateDatabaseRequest; import com.google.firestore.admin.v1.UpdateFieldRequest; @@ -83,22 +96,22 @@ *

This class is for advanced usage and reflects the underlying API directly. */ @Generated("by gapic-generator-java") -@BetaApi public class HttpJsonFirestoreAdminStub extends FirestoreAdminStub { private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder() .add(ExportDocumentsResponse.getDescriptor()) - .add(UpdateDatabaseMetadata.getDescriptor()) .add(Field.getDescriptor()) - .add(Empty.getDescriptor()) + .add(RestoreDatabaseMetadata.getDescriptor()) .add(ImportDocumentsMetadata.getDescriptor()) .add(Database.getDescriptor()) + .add(FieldOperationMetadata.getDescriptor()) + .add(DeleteDatabaseMetadata.getDescriptor()) + .add(UpdateDatabaseMetadata.getDescriptor()) + .add(Empty.getDescriptor()) .add(Index.getDescriptor()) .add(CreateDatabaseMetadata.getDescriptor()) - .add(FieldOperationMetadata.getDescriptor()) .add(ExportDocumentsMetadata.getDescriptor()) .add(IndexOperationMetadata.getDescriptor()) - .add(DeleteDatabaseMetadata.getDescriptor()) .build(); private static final ApiMethodDescriptor @@ -625,6 +638,327 @@ public class HttpJsonFirestoreAdminStub extends FirestoreAdminStub { HttpJsonOperationSnapshot.create(response)) .build(); + private static final ApiMethodDescriptor getBackupMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/GetBackup") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/backups/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Backup.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listBackupsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/ListBackups") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/backups", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListBackupsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteBackupMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/DeleteBackup") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/backups/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + restoreDatabaseMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/RestoreDatabase") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*}/databases:restore", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearParent().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (RestoreDatabaseRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + createBackupScheduleMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/CreateBackupSchedule") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/databases/*}/backupSchedules", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("backupSchedule", request.getBackupSchedule(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(BackupSchedule.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getBackupScheduleMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/GetBackupSchedule") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/databases/*/backupSchedules/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(BackupSchedule.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listBackupSchedulesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/ListBackupSchedules") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/databases/*}/backupSchedules", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListBackupSchedulesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + updateBackupScheduleMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/UpdateBackupSchedule") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{backupSchedule.name=projects/*/databases/*/backupSchedules/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, + "backupSchedule.name", + request.getBackupSchedule().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("backupSchedule", request.getBackupSchedule(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(BackupSchedule.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteBackupScheduleMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/DeleteBackupSchedule") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/databases/*/backupSchedules/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + private final UnaryCallable createIndexCallable; private final OperationCallable createIndexOperationCallable; @@ -657,6 +991,20 @@ public class HttpJsonFirestoreAdminStub extends FirestoreAdminStub { private final UnaryCallable deleteDatabaseCallable; private final OperationCallable deleteDatabaseOperationCallable; + private final UnaryCallable getBackupCallable; + private final UnaryCallable listBackupsCallable; + private final UnaryCallable deleteBackupCallable; + private final UnaryCallable restoreDatabaseCallable; + private final OperationCallable + restoreDatabaseOperationCallable; + private final UnaryCallable + createBackupScheduleCallable; + private final UnaryCallable getBackupScheduleCallable; + private final UnaryCallable + listBackupSchedulesCallable; + private final UnaryCallable + updateBackupScheduleCallable; + private final UnaryCallable deleteBackupScheduleCallable; private final BackgroundResource backgroundResources; private final HttpJsonOperationsStub httpJsonOperationsStub; @@ -883,6 +1231,112 @@ protected HttpJsonFirestoreAdminStub( return builder.build(); }) .build(); + HttpJsonCallSettings getBackupTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getBackupMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings listBackupsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listBackupsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings deleteBackupTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteBackupMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings restoreDatabaseTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(restoreDatabaseMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings + createBackupScheduleTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createBackupScheduleMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings + getBackupScheduleTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getBackupScheduleMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings + listBackupSchedulesTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(listBackupSchedulesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("parent", String.valueOf(request.getParent())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings + updateBackupScheduleTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateBackupScheduleMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( + "backup_schedule.name", + String.valueOf(request.getBackupSchedule().getName())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings deleteBackupScheduleTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteBackupScheduleMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("name", String.valueOf(request.getName())); + return builder.build(); + }) + .build(); this.createIndexCallable = callableFactory.createUnaryCallable( @@ -974,6 +1428,49 @@ protected HttpJsonFirestoreAdminStub( settings.deleteDatabaseOperationSettings(), clientContext, httpJsonOperationsStub); + this.getBackupCallable = + callableFactory.createUnaryCallable( + getBackupTransportSettings, settings.getBackupSettings(), clientContext); + this.listBackupsCallable = + callableFactory.createUnaryCallable( + listBackupsTransportSettings, settings.listBackupsSettings(), clientContext); + this.deleteBackupCallable = + callableFactory.createUnaryCallable( + deleteBackupTransportSettings, settings.deleteBackupSettings(), clientContext); + this.restoreDatabaseCallable = + callableFactory.createUnaryCallable( + restoreDatabaseTransportSettings, settings.restoreDatabaseSettings(), clientContext); + this.restoreDatabaseOperationCallable = + callableFactory.createOperationCallable( + restoreDatabaseTransportSettings, + settings.restoreDatabaseOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.createBackupScheduleCallable = + callableFactory.createUnaryCallable( + createBackupScheduleTransportSettings, + settings.createBackupScheduleSettings(), + clientContext); + this.getBackupScheduleCallable = + callableFactory.createUnaryCallable( + getBackupScheduleTransportSettings, + settings.getBackupScheduleSettings(), + clientContext); + this.listBackupSchedulesCallable = + callableFactory.createUnaryCallable( + listBackupSchedulesTransportSettings, + settings.listBackupSchedulesSettings(), + clientContext); + this.updateBackupScheduleCallable = + callableFactory.createUnaryCallable( + updateBackupScheduleTransportSettings, + settings.updateBackupScheduleSettings(), + clientContext); + this.deleteBackupScheduleCallable = + callableFactory.createUnaryCallable( + deleteBackupScheduleTransportSettings, + settings.deleteBackupScheduleSettings(), + clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); @@ -996,6 +1493,15 @@ public static List getMethodDescriptors() { methodDescriptors.add(listDatabasesMethodDescriptor); methodDescriptors.add(updateDatabaseMethodDescriptor); methodDescriptors.add(deleteDatabaseMethodDescriptor); + methodDescriptors.add(getBackupMethodDescriptor); + methodDescriptors.add(listBackupsMethodDescriptor); + methodDescriptors.add(deleteBackupMethodDescriptor); + methodDescriptors.add(restoreDatabaseMethodDescriptor); + methodDescriptors.add(createBackupScheduleMethodDescriptor); + methodDescriptors.add(getBackupScheduleMethodDescriptor); + methodDescriptors.add(listBackupSchedulesMethodDescriptor); + methodDescriptors.add(updateBackupScheduleMethodDescriptor); + methodDescriptors.add(deleteBackupScheduleMethodDescriptor); return methodDescriptors; } @@ -1125,6 +1631,58 @@ public UnaryCallable deleteDatabaseCallable() return deleteDatabaseOperationCallable; } + @Override + public UnaryCallable getBackupCallable() { + return getBackupCallable; + } + + @Override + public UnaryCallable listBackupsCallable() { + return listBackupsCallable; + } + + @Override + public UnaryCallable deleteBackupCallable() { + return deleteBackupCallable; + } + + @Override + public UnaryCallable restoreDatabaseCallable() { + return restoreDatabaseCallable; + } + + @Override + public OperationCallable + restoreDatabaseOperationCallable() { + return restoreDatabaseOperationCallable; + } + + @Override + public UnaryCallable createBackupScheduleCallable() { + return createBackupScheduleCallable; + } + + @Override + public UnaryCallable getBackupScheduleCallable() { + return getBackupScheduleCallable; + } + + @Override + public UnaryCallable + listBackupSchedulesCallable() { + return listBackupSchedulesCallable; + } + + @Override + public UnaryCallable updateBackupScheduleCallable() { + return updateBackupScheduleCallable; + } + + @Override + public UnaryCallable deleteBackupScheduleCallable() { + return deleteBackupScheduleCallable; + } + @Override public final void close() { try { diff --git a/google-cloud-firestore-admin/src/main/resources/META-INF/native-image/com.google.cloud.firestore.v1/reflect-config.json b/google-cloud-firestore-admin/src/main/resources/META-INF/native-image/com.google.cloud.firestore.v1/reflect-config.json index e3b6a2e3c..4898cf2e6 100644 --- a/google-cloud-firestore-admin/src/main/resources/META-INF/native-image/com.google.cloud.firestore.v1/reflect-config.json +++ b/google-cloud-firestore-admin/src/main/resources/META-INF/native-image/com.google.cloud.firestore.v1/reflect-config.json @@ -449,6 +449,87 @@ "allDeclaredClasses": true, "allPublicClasses": true }, + { + "name": "com.google.firestore.admin.v1.Backup", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.Backup$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.Backup$State", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.Backup$Stats", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.Backup$Stats$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.BackupSchedule", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.BackupSchedule$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.CreateBackupScheduleRequest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.CreateBackupScheduleRequest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, { "name": "com.google.firestore.admin.v1.CreateDatabaseMetadata", "queryAllDeclaredConstructors": true, @@ -503,6 +584,24 @@ "allDeclaredClasses": true, "allPublicClasses": true }, + { + "name": "com.google.firestore.admin.v1.DailyRecurrence", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.DailyRecurrence$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, { "name": "com.google.firestore.admin.v1.Database", "queryAllDeclaredConstructors": true, @@ -566,6 +665,42 @@ "allDeclaredClasses": true, "allPublicClasses": true }, + { + "name": "com.google.firestore.admin.v1.DeleteBackupRequest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.DeleteBackupRequest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.DeleteBackupScheduleRequest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.DeleteBackupScheduleRequest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, { "name": "com.google.firestore.admin.v1.DeleteDatabaseMetadata", "queryAllDeclaredConstructors": true, @@ -809,6 +944,42 @@ "allDeclaredClasses": true, "allPublicClasses": true }, + { + "name": "com.google.firestore.admin.v1.GetBackupRequest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.GetBackupRequest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.GetBackupScheduleRequest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.GetBackupScheduleRequest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, { "name": "com.google.firestore.admin.v1.GetDatabaseRequest", "queryAllDeclaredConstructors": true, @@ -962,6 +1133,42 @@ "allDeclaredClasses": true, "allPublicClasses": true }, + { + "name": "com.google.firestore.admin.v1.Index$IndexField$VectorConfig", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.Index$IndexField$VectorConfig$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.Index$IndexField$VectorConfig$FlatIndex", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.Index$IndexField$VectorConfig$FlatIndex$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, { "name": "com.google.firestore.admin.v1.Index$QueryScope", "queryAllDeclaredConstructors": true, @@ -998,6 +1205,78 @@ "allDeclaredClasses": true, "allPublicClasses": true }, + { + "name": "com.google.firestore.admin.v1.ListBackupSchedulesRequest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.ListBackupSchedulesRequest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.ListBackupSchedulesResponse", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.ListBackupSchedulesResponse$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.ListBackupsRequest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.ListBackupsRequest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.ListBackupsResponse", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.ListBackupsResponse$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, { "name": "com.google.firestore.admin.v1.ListDatabasesRequest", "queryAllDeclaredConstructors": true, @@ -1151,6 +1430,60 @@ "allDeclaredClasses": true, "allPublicClasses": true }, + { + "name": "com.google.firestore.admin.v1.RestoreDatabaseMetadata", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.RestoreDatabaseMetadata$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.RestoreDatabaseRequest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.RestoreDatabaseRequest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.UpdateBackupScheduleRequest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.UpdateBackupScheduleRequest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, { "name": "com.google.firestore.admin.v1.UpdateDatabaseMetadata", "queryAllDeclaredConstructors": true, @@ -1205,6 +1538,24 @@ "allDeclaredClasses": true, "allPublicClasses": true }, + { + "name": "com.google.firestore.admin.v1.WeeklyRecurrence", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.admin.v1.WeeklyRecurrence$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, { "name": "com.google.longrunning.CancelOperationRequest", "queryAllDeclaredConstructors": true, @@ -2185,5 +2536,14 @@ "allPublicMethods": true, "allDeclaredClasses": true, "allPublicClasses": true + }, + { + "name": "com.google.type.DayOfWeek", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true } ] \ No newline at end of file diff --git a/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientHttpJsonTest.java b/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientHttpJsonTest.java index d5009b330..dee30271d 100644 --- a/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientHttpJsonTest.java +++ b/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientHttpJsonTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,10 @@ import com.google.api.gax.rpc.testing.FakeStatusCode; import com.google.cloud.firestore.v1.stub.HttpJsonFirestoreAdminStub; import com.google.common.collect.Lists; +import com.google.firestore.admin.v1.Backup; +import com.google.firestore.admin.v1.BackupName; +import com.google.firestore.admin.v1.BackupSchedule; +import com.google.firestore.admin.v1.BackupScheduleName; import com.google.firestore.admin.v1.CollectionGroupName; import com.google.firestore.admin.v1.Database; import com.google.firestore.admin.v1.DatabaseName; @@ -38,10 +42,14 @@ import com.google.firestore.admin.v1.FieldName; import com.google.firestore.admin.v1.Index; import com.google.firestore.admin.v1.IndexName; +import com.google.firestore.admin.v1.ListBackupSchedulesResponse; +import com.google.firestore.admin.v1.ListBackupsResponse; import com.google.firestore.admin.v1.ListDatabasesResponse; import com.google.firestore.admin.v1.ListFieldsResponse; import com.google.firestore.admin.v1.ListIndexesResponse; +import com.google.firestore.admin.v1.LocationName; import com.google.firestore.admin.v1.ProjectName; +import com.google.firestore.admin.v1.RestoreDatabaseRequest; import com.google.longrunning.Operation; import com.google.protobuf.Any; import com.google.protobuf.Duration; @@ -1433,4 +1441,773 @@ public void deleteDatabaseExceptionTest2() throws Exception { } catch (ExecutionException e) { } } + + @Test + public void getBackupTest() throws Exception { + Backup expectedResponse = + Backup.newBuilder() + .setName(BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]").toString()) + .setDatabase(DatabaseName.of("[PROJECT]", "[DATABASE]").toString()) + .setDatabaseUid("databaseUid816481493") + .setSnapshotTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setStats(Backup.Stats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + BackupName name = BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]"); + + Backup actualResponse = client.getBackup(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getBackupExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BackupName name = BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]"); + client.getBackup(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getBackupTest2() throws Exception { + Backup expectedResponse = + Backup.newBuilder() + .setName(BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]").toString()) + .setDatabase(DatabaseName.of("[PROJECT]", "[DATABASE]").toString()) + .setDatabaseUid("databaseUid816481493") + .setSnapshotTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setStats(Backup.Stats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-1607/locations/location-1607/backups/backup-1607"; + + Backup actualResponse = client.getBackup(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getBackupExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-1607/locations/location-1607/backups/backup-1607"; + client.getBackup(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBackupsTest() throws Exception { + ListBackupsResponse expectedResponse = + ListBackupsResponse.newBuilder() + .addAllBackups(new ArrayList()) + .addAllUnreachable(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListBackupsResponse actualResponse = client.listBackups(parent); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listBackupsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listBackups(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBackupsTest2() throws Exception { + ListBackupsResponse expectedResponse = + ListBackupsResponse.newBuilder() + .addAllBackups(new ArrayList()) + .addAllUnreachable(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListBackupsResponse actualResponse = client.listBackups(parent); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listBackupsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + client.listBackups(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteBackupTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + BackupName name = BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]"); + + client.deleteBackup(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteBackupExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BackupName name = BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]"); + client.deleteBackup(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteBackupTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-1607/locations/location-1607/backups/backup-1607"; + + client.deleteBackup(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteBackupExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-1607/locations/location-1607/backups/backup-1607"; + client.deleteBackup(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void restoreDatabaseTest() throws Exception { + Database expectedResponse = + Database.newBuilder() + .setName(DatabaseName.of("[PROJECT]", "[DATABASE]").toString()) + .setUid("uid115792") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setLocationId("locationId1541836720") + .setVersionRetentionPeriod(Duration.newBuilder().build()) + .setEarliestVersionTime(Timestamp.newBuilder().build()) + .setKeyPrefix("keyPrefix-2076395055") + .setEtag("etag3123477") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("restoreDatabaseTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + RestoreDatabaseRequest request = + RestoreDatabaseRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setDatabaseId("databaseId1688905718") + .setBackup(BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]").toString()) + .build(); + + Database actualResponse = client.restoreDatabaseAsync(request).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void restoreDatabaseExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RestoreDatabaseRequest request = + RestoreDatabaseRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setDatabaseId("databaseId1688905718") + .setBackup(BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]").toString()) + .build(); + client.restoreDatabaseAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createBackupScheduleTest() throws Exception { + BackupSchedule expectedResponse = + BackupSchedule.newBuilder() + .setName( + BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRetention(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + DatabaseName parent = DatabaseName.of("[PROJECT]", "[DATABASE]"); + BackupSchedule backupSchedule = BackupSchedule.newBuilder().build(); + + BackupSchedule actualResponse = client.createBackupSchedule(parent, backupSchedule); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createBackupScheduleExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + DatabaseName parent = DatabaseName.of("[PROJECT]", "[DATABASE]"); + BackupSchedule backupSchedule = BackupSchedule.newBuilder().build(); + client.createBackupSchedule(parent, backupSchedule); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBackupScheduleTest2() throws Exception { + BackupSchedule expectedResponse = + BackupSchedule.newBuilder() + .setName( + BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRetention(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-9821/databases/database-9821"; + BackupSchedule backupSchedule = BackupSchedule.newBuilder().build(); + + BackupSchedule actualResponse = client.createBackupSchedule(parent, backupSchedule); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createBackupScheduleExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-9821/databases/database-9821"; + BackupSchedule backupSchedule = BackupSchedule.newBuilder().build(); + client.createBackupSchedule(parent, backupSchedule); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getBackupScheduleTest() throws Exception { + BackupSchedule expectedResponse = + BackupSchedule.newBuilder() + .setName( + BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRetention(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + BackupScheduleName name = BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]"); + + BackupSchedule actualResponse = client.getBackupSchedule(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getBackupScheduleExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BackupScheduleName name = + BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]"); + client.getBackupSchedule(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getBackupScheduleTest2() throws Exception { + BackupSchedule expectedResponse = + BackupSchedule.newBuilder() + .setName( + BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRetention(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-3270/databases/database-3270/backupSchedules/backupSchedule-3270"; + + BackupSchedule actualResponse = client.getBackupSchedule(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getBackupScheduleExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-3270/databases/database-3270/backupSchedules/backupSchedule-3270"; + client.getBackupSchedule(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBackupSchedulesTest() throws Exception { + ListBackupSchedulesResponse expectedResponse = + ListBackupSchedulesResponse.newBuilder() + .addAllBackupSchedules(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + DatabaseName parent = DatabaseName.of("[PROJECT]", "[DATABASE]"); + + ListBackupSchedulesResponse actualResponse = client.listBackupSchedules(parent); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listBackupSchedulesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + DatabaseName parent = DatabaseName.of("[PROJECT]", "[DATABASE]"); + client.listBackupSchedules(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBackupSchedulesTest2() throws Exception { + ListBackupSchedulesResponse expectedResponse = + ListBackupSchedulesResponse.newBuilder() + .addAllBackupSchedules(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-9821/databases/database-9821"; + + ListBackupSchedulesResponse actualResponse = client.listBackupSchedules(parent); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listBackupSchedulesExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-9821/databases/database-9821"; + client.listBackupSchedules(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateBackupScheduleTest() throws Exception { + BackupSchedule expectedResponse = + BackupSchedule.newBuilder() + .setName( + BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRetention(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + BackupSchedule backupSchedule = + BackupSchedule.newBuilder() + .setName( + BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRetention(Duration.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + BackupSchedule actualResponse = client.updateBackupSchedule(backupSchedule, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateBackupScheduleExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BackupSchedule backupSchedule = + BackupSchedule.newBuilder() + .setName( + BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRetention(Duration.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateBackupSchedule(backupSchedule, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteBackupScheduleTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + BackupScheduleName name = BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]"); + + client.deleteBackupSchedule(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteBackupScheduleExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BackupScheduleName name = + BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]"); + client.deleteBackupSchedule(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteBackupScheduleTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-3270/databases/database-3270/backupSchedules/backupSchedule-3270"; + + client.deleteBackupSchedule(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteBackupScheduleExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-3270/databases/database-3270/backupSchedules/backupSchedule-3270"; + client.deleteBackupSchedule(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } } diff --git a/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientTest.java b/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientTest.java index 10081fa8c..5aebfcf41 100644 --- a/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientTest.java +++ b/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,30 +28,46 @@ import com.google.api.gax.rpc.InvalidArgumentException; import com.google.api.gax.rpc.StatusCode; import com.google.common.collect.Lists; +import com.google.firestore.admin.v1.Backup; +import com.google.firestore.admin.v1.BackupName; +import com.google.firestore.admin.v1.BackupSchedule; +import com.google.firestore.admin.v1.BackupScheduleName; import com.google.firestore.admin.v1.CollectionGroupName; +import com.google.firestore.admin.v1.CreateBackupScheduleRequest; import com.google.firestore.admin.v1.CreateDatabaseRequest; import com.google.firestore.admin.v1.CreateIndexRequest; import com.google.firestore.admin.v1.Database; import com.google.firestore.admin.v1.DatabaseName; +import com.google.firestore.admin.v1.DeleteBackupRequest; +import com.google.firestore.admin.v1.DeleteBackupScheduleRequest; import com.google.firestore.admin.v1.DeleteDatabaseRequest; import com.google.firestore.admin.v1.DeleteIndexRequest; import com.google.firestore.admin.v1.ExportDocumentsRequest; import com.google.firestore.admin.v1.ExportDocumentsResponse; import com.google.firestore.admin.v1.Field; import com.google.firestore.admin.v1.FieldName; +import com.google.firestore.admin.v1.GetBackupRequest; +import com.google.firestore.admin.v1.GetBackupScheduleRequest; import com.google.firestore.admin.v1.GetDatabaseRequest; import com.google.firestore.admin.v1.GetFieldRequest; import com.google.firestore.admin.v1.GetIndexRequest; import com.google.firestore.admin.v1.ImportDocumentsRequest; import com.google.firestore.admin.v1.Index; import com.google.firestore.admin.v1.IndexName; +import com.google.firestore.admin.v1.ListBackupSchedulesRequest; +import com.google.firestore.admin.v1.ListBackupSchedulesResponse; +import com.google.firestore.admin.v1.ListBackupsRequest; +import com.google.firestore.admin.v1.ListBackupsResponse; import com.google.firestore.admin.v1.ListDatabasesRequest; import com.google.firestore.admin.v1.ListDatabasesResponse; import com.google.firestore.admin.v1.ListFieldsRequest; import com.google.firestore.admin.v1.ListFieldsResponse; import com.google.firestore.admin.v1.ListIndexesRequest; import com.google.firestore.admin.v1.ListIndexesResponse; +import com.google.firestore.admin.v1.LocationName; import com.google.firestore.admin.v1.ProjectName; +import com.google.firestore.admin.v1.RestoreDatabaseRequest; +import com.google.firestore.admin.v1.UpdateBackupScheduleRequest; import com.google.firestore.admin.v1.UpdateDatabaseRequest; import com.google.firestore.admin.v1.UpdateFieldRequest; import com.google.longrunning.Operation; @@ -1296,4 +1312,672 @@ public void deleteDatabaseExceptionTest2() throws Exception { Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } + + @Test + public void getBackupTest() throws Exception { + Backup expectedResponse = + Backup.newBuilder() + .setName(BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]").toString()) + .setDatabase(DatabaseName.of("[PROJECT]", "[DATABASE]").toString()) + .setDatabaseUid("databaseUid816481493") + .setSnapshotTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setStats(Backup.Stats.newBuilder().build()) + .build(); + mockFirestoreAdmin.addResponse(expectedResponse); + + BackupName name = BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]"); + + Backup actualResponse = client.getBackup(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockFirestoreAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetBackupRequest actualRequest = ((GetBackupRequest) actualRequests.get(0)); + + Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getBackupExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockFirestoreAdmin.addException(exception); + + try { + BackupName name = BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]"); + client.getBackup(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getBackupTest2() throws Exception { + Backup expectedResponse = + Backup.newBuilder() + .setName(BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]").toString()) + .setDatabase(DatabaseName.of("[PROJECT]", "[DATABASE]").toString()) + .setDatabaseUid("databaseUid816481493") + .setSnapshotTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setStats(Backup.Stats.newBuilder().build()) + .build(); + mockFirestoreAdmin.addResponse(expectedResponse); + + String name = "name3373707"; + + Backup actualResponse = client.getBackup(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockFirestoreAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetBackupRequest actualRequest = ((GetBackupRequest) actualRequests.get(0)); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getBackupExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockFirestoreAdmin.addException(exception); + + try { + String name = "name3373707"; + client.getBackup(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBackupsTest() throws Exception { + ListBackupsResponse expectedResponse = + ListBackupsResponse.newBuilder() + .addAllBackups(new ArrayList()) + .addAllUnreachable(new ArrayList()) + .build(); + mockFirestoreAdmin.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListBackupsResponse actualResponse = client.listBackups(parent); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockFirestoreAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListBackupsRequest actualRequest = ((ListBackupsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listBackupsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockFirestoreAdmin.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listBackups(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBackupsTest2() throws Exception { + ListBackupsResponse expectedResponse = + ListBackupsResponse.newBuilder() + .addAllBackups(new ArrayList()) + .addAllUnreachable(new ArrayList()) + .build(); + mockFirestoreAdmin.addResponse(expectedResponse); + + String parent = "parent-995424086"; + + ListBackupsResponse actualResponse = client.listBackups(parent); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockFirestoreAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListBackupsRequest actualRequest = ((ListBackupsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listBackupsExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockFirestoreAdmin.addException(exception); + + try { + String parent = "parent-995424086"; + client.listBackups(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteBackupTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockFirestoreAdmin.addResponse(expectedResponse); + + BackupName name = BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]"); + + client.deleteBackup(name); + + List actualRequests = mockFirestoreAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteBackupRequest actualRequest = ((DeleteBackupRequest) actualRequests.get(0)); + + Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteBackupExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockFirestoreAdmin.addException(exception); + + try { + BackupName name = BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]"); + client.deleteBackup(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteBackupTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockFirestoreAdmin.addResponse(expectedResponse); + + String name = "name3373707"; + + client.deleteBackup(name); + + List actualRequests = mockFirestoreAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteBackupRequest actualRequest = ((DeleteBackupRequest) actualRequests.get(0)); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteBackupExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockFirestoreAdmin.addException(exception); + + try { + String name = "name3373707"; + client.deleteBackup(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void restoreDatabaseTest() throws Exception { + Database expectedResponse = + Database.newBuilder() + .setName(DatabaseName.of("[PROJECT]", "[DATABASE]").toString()) + .setUid("uid115792") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setLocationId("locationId1541836720") + .setVersionRetentionPeriod(Duration.newBuilder().build()) + .setEarliestVersionTime(Timestamp.newBuilder().build()) + .setKeyPrefix("keyPrefix-2076395055") + .setEtag("etag3123477") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("restoreDatabaseTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockFirestoreAdmin.addResponse(resultOperation); + + RestoreDatabaseRequest request = + RestoreDatabaseRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setDatabaseId("databaseId1688905718") + .setBackup(BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]").toString()) + .build(); + + Database actualResponse = client.restoreDatabaseAsync(request).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockFirestoreAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + RestoreDatabaseRequest actualRequest = ((RestoreDatabaseRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getParent(), actualRequest.getParent()); + Assert.assertEquals(request.getDatabaseId(), actualRequest.getDatabaseId()); + Assert.assertEquals(request.getBackup(), actualRequest.getBackup()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void restoreDatabaseExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockFirestoreAdmin.addException(exception); + + try { + RestoreDatabaseRequest request = + RestoreDatabaseRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setDatabaseId("databaseId1688905718") + .setBackup(BackupName.of("[PROJECT]", "[LOCATION]", "[BACKUP]").toString()) + .build(); + client.restoreDatabaseAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + public void createBackupScheduleTest() throws Exception { + BackupSchedule expectedResponse = + BackupSchedule.newBuilder() + .setName( + BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRetention(Duration.newBuilder().build()) + .build(); + mockFirestoreAdmin.addResponse(expectedResponse); + + DatabaseName parent = DatabaseName.of("[PROJECT]", "[DATABASE]"); + BackupSchedule backupSchedule = BackupSchedule.newBuilder().build(); + + BackupSchedule actualResponse = client.createBackupSchedule(parent, backupSchedule); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockFirestoreAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateBackupScheduleRequest actualRequest = + ((CreateBackupScheduleRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(backupSchedule, actualRequest.getBackupSchedule()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createBackupScheduleExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockFirestoreAdmin.addException(exception); + + try { + DatabaseName parent = DatabaseName.of("[PROJECT]", "[DATABASE]"); + BackupSchedule backupSchedule = BackupSchedule.newBuilder().build(); + client.createBackupSchedule(parent, backupSchedule); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBackupScheduleTest2() throws Exception { + BackupSchedule expectedResponse = + BackupSchedule.newBuilder() + .setName( + BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRetention(Duration.newBuilder().build()) + .build(); + mockFirestoreAdmin.addResponse(expectedResponse); + + String parent = "parent-995424086"; + BackupSchedule backupSchedule = BackupSchedule.newBuilder().build(); + + BackupSchedule actualResponse = client.createBackupSchedule(parent, backupSchedule); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockFirestoreAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateBackupScheduleRequest actualRequest = + ((CreateBackupScheduleRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertEquals(backupSchedule, actualRequest.getBackupSchedule()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createBackupScheduleExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockFirestoreAdmin.addException(exception); + + try { + String parent = "parent-995424086"; + BackupSchedule backupSchedule = BackupSchedule.newBuilder().build(); + client.createBackupSchedule(parent, backupSchedule); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getBackupScheduleTest() throws Exception { + BackupSchedule expectedResponse = + BackupSchedule.newBuilder() + .setName( + BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRetention(Duration.newBuilder().build()) + .build(); + mockFirestoreAdmin.addResponse(expectedResponse); + + BackupScheduleName name = BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]"); + + BackupSchedule actualResponse = client.getBackupSchedule(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockFirestoreAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetBackupScheduleRequest actualRequest = ((GetBackupScheduleRequest) actualRequests.get(0)); + + Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getBackupScheduleExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockFirestoreAdmin.addException(exception); + + try { + BackupScheduleName name = + BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]"); + client.getBackupSchedule(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getBackupScheduleTest2() throws Exception { + BackupSchedule expectedResponse = + BackupSchedule.newBuilder() + .setName( + BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRetention(Duration.newBuilder().build()) + .build(); + mockFirestoreAdmin.addResponse(expectedResponse); + + String name = "name3373707"; + + BackupSchedule actualResponse = client.getBackupSchedule(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockFirestoreAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetBackupScheduleRequest actualRequest = ((GetBackupScheduleRequest) actualRequests.get(0)); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getBackupScheduleExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockFirestoreAdmin.addException(exception); + + try { + String name = "name3373707"; + client.getBackupSchedule(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBackupSchedulesTest() throws Exception { + ListBackupSchedulesResponse expectedResponse = + ListBackupSchedulesResponse.newBuilder() + .addAllBackupSchedules(new ArrayList()) + .build(); + mockFirestoreAdmin.addResponse(expectedResponse); + + DatabaseName parent = DatabaseName.of("[PROJECT]", "[DATABASE]"); + + ListBackupSchedulesResponse actualResponse = client.listBackupSchedules(parent); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockFirestoreAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListBackupSchedulesRequest actualRequest = ((ListBackupSchedulesRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listBackupSchedulesExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockFirestoreAdmin.addException(exception); + + try { + DatabaseName parent = DatabaseName.of("[PROJECT]", "[DATABASE]"); + client.listBackupSchedules(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBackupSchedulesTest2() throws Exception { + ListBackupSchedulesResponse expectedResponse = + ListBackupSchedulesResponse.newBuilder() + .addAllBackupSchedules(new ArrayList()) + .build(); + mockFirestoreAdmin.addResponse(expectedResponse); + + String parent = "parent-995424086"; + + ListBackupSchedulesResponse actualResponse = client.listBackupSchedules(parent); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockFirestoreAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListBackupSchedulesRequest actualRequest = ((ListBackupSchedulesRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listBackupSchedulesExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockFirestoreAdmin.addException(exception); + + try { + String parent = "parent-995424086"; + client.listBackupSchedules(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateBackupScheduleTest() throws Exception { + BackupSchedule expectedResponse = + BackupSchedule.newBuilder() + .setName( + BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRetention(Duration.newBuilder().build()) + .build(); + mockFirestoreAdmin.addResponse(expectedResponse); + + BackupSchedule backupSchedule = BackupSchedule.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + BackupSchedule actualResponse = client.updateBackupSchedule(backupSchedule, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockFirestoreAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpdateBackupScheduleRequest actualRequest = + ((UpdateBackupScheduleRequest) actualRequests.get(0)); + + Assert.assertEquals(backupSchedule, actualRequest.getBackupSchedule()); + Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void updateBackupScheduleExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockFirestoreAdmin.addException(exception); + + try { + BackupSchedule backupSchedule = BackupSchedule.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateBackupSchedule(backupSchedule, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteBackupScheduleTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockFirestoreAdmin.addResponse(expectedResponse); + + BackupScheduleName name = BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]"); + + client.deleteBackupSchedule(name); + + List actualRequests = mockFirestoreAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteBackupScheduleRequest actualRequest = + ((DeleteBackupScheduleRequest) actualRequests.get(0)); + + Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteBackupScheduleExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockFirestoreAdmin.addException(exception); + + try { + BackupScheduleName name = + BackupScheduleName.of("[PROJECT]", "[DATABASE]", "[BACKUP_SCHEDULE]"); + client.deleteBackupSchedule(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteBackupScheduleTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockFirestoreAdmin.addResponse(expectedResponse); + + String name = "name3373707"; + + client.deleteBackupSchedule(name); + + List actualRequests = mockFirestoreAdmin.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteBackupScheduleRequest actualRequest = + ((DeleteBackupScheduleRequest) actualRequests.get(0)); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteBackupScheduleExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockFirestoreAdmin.addException(exception); + + try { + String name = "name3373707"; + client.deleteBackupSchedule(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } } diff --git a/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/MockFirestoreAdmin.java b/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/MockFirestoreAdmin.java index 08eb8501a..531ec17c0 100644 --- a/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/MockFirestoreAdmin.java +++ b/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/MockFirestoreAdmin.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/MockFirestoreAdminImpl.java b/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/MockFirestoreAdminImpl.java index f35d442c4..02c02f8af 100644 --- a/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/MockFirestoreAdminImpl.java +++ b/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/MockFirestoreAdminImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,25 +17,38 @@ package com.google.cloud.firestore.v1; import com.google.api.core.BetaApi; +import com.google.firestore.admin.v1.Backup; +import com.google.firestore.admin.v1.BackupSchedule; +import com.google.firestore.admin.v1.CreateBackupScheduleRequest; import com.google.firestore.admin.v1.CreateDatabaseRequest; import com.google.firestore.admin.v1.CreateIndexRequest; import com.google.firestore.admin.v1.Database; +import com.google.firestore.admin.v1.DeleteBackupRequest; +import com.google.firestore.admin.v1.DeleteBackupScheduleRequest; import com.google.firestore.admin.v1.DeleteDatabaseRequest; import com.google.firestore.admin.v1.DeleteIndexRequest; import com.google.firestore.admin.v1.ExportDocumentsRequest; import com.google.firestore.admin.v1.Field; import com.google.firestore.admin.v1.FirestoreAdminGrpc.FirestoreAdminImplBase; +import com.google.firestore.admin.v1.GetBackupRequest; +import com.google.firestore.admin.v1.GetBackupScheduleRequest; import com.google.firestore.admin.v1.GetDatabaseRequest; import com.google.firestore.admin.v1.GetFieldRequest; import com.google.firestore.admin.v1.GetIndexRequest; import com.google.firestore.admin.v1.ImportDocumentsRequest; import com.google.firestore.admin.v1.Index; +import com.google.firestore.admin.v1.ListBackupSchedulesRequest; +import com.google.firestore.admin.v1.ListBackupSchedulesResponse; +import com.google.firestore.admin.v1.ListBackupsRequest; +import com.google.firestore.admin.v1.ListBackupsResponse; import com.google.firestore.admin.v1.ListDatabasesRequest; import com.google.firestore.admin.v1.ListDatabasesResponse; import com.google.firestore.admin.v1.ListFieldsRequest; import com.google.firestore.admin.v1.ListFieldsResponse; import com.google.firestore.admin.v1.ListIndexesRequest; import com.google.firestore.admin.v1.ListIndexesResponse; +import com.google.firestore.admin.v1.RestoreDatabaseRequest; +import com.google.firestore.admin.v1.UpdateBackupScheduleRequest; import com.google.firestore.admin.v1.UpdateDatabaseRequest; import com.google.firestore.admin.v1.UpdateFieldRequest; import com.google.longrunning.Operation; @@ -367,4 +380,192 @@ public void deleteDatabase( Exception.class.getName()))); } } + + @Override + public void getBackup(GetBackupRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Backup) { + requests.add(request); + responseObserver.onNext(((Backup) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetBackup, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Backup.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void listBackups( + ListBackupsRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof ListBackupsResponse) { + requests.add(request); + responseObserver.onNext(((ListBackupsResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListBackups, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + ListBackupsResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void deleteBackup(DeleteBackupRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Empty) { + requests.add(request); + responseObserver.onNext(((Empty) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method DeleteBackup, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Empty.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void restoreDatabase( + RestoreDatabaseRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Operation) { + requests.add(request); + responseObserver.onNext(((Operation) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method RestoreDatabase, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Operation.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void createBackupSchedule( + CreateBackupScheduleRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof BackupSchedule) { + requests.add(request); + responseObserver.onNext(((BackupSchedule) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method CreateBackupSchedule, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + BackupSchedule.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void getBackupSchedule( + GetBackupScheduleRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof BackupSchedule) { + requests.add(request); + responseObserver.onNext(((BackupSchedule) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetBackupSchedule, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + BackupSchedule.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void listBackupSchedules( + ListBackupSchedulesRequest request, + StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof ListBackupSchedulesResponse) { + requests.add(request); + responseObserver.onNext(((ListBackupSchedulesResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListBackupSchedules, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + ListBackupSchedulesResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void updateBackupSchedule( + UpdateBackupScheduleRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof BackupSchedule) { + requests.add(request); + responseObserver.onNext(((BackupSchedule) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method UpdateBackupSchedule, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + BackupSchedule.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void deleteBackupSchedule( + DeleteBackupScheduleRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Empty) { + requests.add(request); + responseObserver.onNext(((Empty) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method DeleteBackupSchedule, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Empty.class.getName(), + Exception.class.getName()))); + } + } } diff --git a/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/MockLocations.java b/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/MockLocations.java index f9e50dc16..10cecbc88 100644 --- a/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/MockLocations.java +++ b/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/MockLocations.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/MockLocationsImpl.java b/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/MockLocationsImpl.java index 6e823521a..6e12a2e8d 100644 --- a/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/MockLocationsImpl.java +++ b/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/MockLocationsImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/FirestoreClient.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/FirestoreClient.java index 5ba54936e..9cef38b6d 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/FirestoreClient.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/FirestoreClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,6 +42,8 @@ import com.google.firestore.v1.DeleteDocumentRequest; import com.google.firestore.v1.Document; import com.google.firestore.v1.DocumentMask; +import com.google.firestore.v1.ExecutePipelineRequest; +import com.google.firestore.v1.ExecutePipelineResponse; import com.google.firestore.v1.GetDocumentRequest; import com.google.firestore.v1.ListCollectionIdsRequest; import com.google.firestore.v1.ListCollectionIdsResponse; @@ -247,6 +249,16 @@ * * * + *

ExecutePipeline + *

Executes a pipeline query. + * + *

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

+ *
    + *
  • executePipelineCallable() + *

+ * + * + * *

RunAggregationQuery *

Runs an aggregation query. *

Rather than producing [Document][google.firestore.v1.Document] results like [Firestore.RunQuery][google.firestore.v1.Firestore.RunQuery], this API allows running an aggregation to produce a series of [AggregationResult][google.firestore.v1.AggregationResult] server-side. @@ -1119,6 +1131,34 @@ public final ServerStreamingCallable runQuery return stub.runQueryCallable(); } + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Executes a pipeline query. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (FirestoreClient firestoreClient = FirestoreClient.create()) {
+   *   ExecutePipelineRequest request =
+   *       ExecutePipelineRequest.newBuilder().setDatabase("database1789464955").build();
+   *   ServerStream stream =
+   *       firestoreClient.executePipelineCallable().call(request);
+   *   for (ExecutePipelineResponse response : stream) {
+   *     // Do something when a response is received.
+   *   }
+   * }
+   * }
+ */ + public final ServerStreamingCallable + executePipelineCallable() { + return stub.executePipelineCallable(); + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Runs an aggregation query. diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/FirestoreSettings.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/FirestoreSettings.java index c5d57c5cd..687b81a60 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/FirestoreSettings.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/FirestoreSettings.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,6 +46,8 @@ import com.google.firestore.v1.CreateDocumentRequest; import com.google.firestore.v1.DeleteDocumentRequest; import com.google.firestore.v1.Document; +import com.google.firestore.v1.ExecutePipelineRequest; +import com.google.firestore.v1.ExecutePipelineResponse; import com.google.firestore.v1.GetDocumentRequest; import com.google.firestore.v1.ListCollectionIdsRequest; import com.google.firestore.v1.ListCollectionIdsResponse; @@ -155,6 +157,12 @@ public ServerStreamingCallSettings runQuerySe return ((FirestoreStubSettings) getStubSettings()).runQuerySettings(); } + /** Returns the object with the settings used for calls to executePipeline. */ + public ServerStreamingCallSettings + executePipelineSettings() { + return ((FirestoreStubSettings) getStubSettings()).executePipelineSettings(); + } + /** Returns the object with the settings used for calls to runAggregationQuery. */ public ServerStreamingCallSettings runAggregationQuerySettings() { @@ -235,7 +243,6 @@ public static TransportChannelProvider defaultTransportChannelProvider() { return FirestoreStubSettings.defaultTransportChannelProvider(); } - @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { return FirestoreStubSettings.defaultApiClientHeaderProviderBuilder(); } @@ -246,7 +253,6 @@ public static Builder newBuilder() { } /** Returns a new REST builder for this class. */ - @BetaApi public static Builder newHttpJsonBuilder() { return Builder.createHttpJsonDefault(); } @@ -288,7 +294,6 @@ private static Builder createDefault() { return new Builder(FirestoreStubSettings.newBuilder()); } - @BetaApi private static Builder createHttpJsonDefault() { return new Builder(FirestoreStubSettings.newHttpJsonBuilder()); } @@ -359,6 +364,12 @@ public UnaryCallSettings.Builder rollbackSettings() { return getStubSettingsBuilder().runQuerySettings(); } + /** Returns the builder for the settings used for calls to executePipeline. */ + public ServerStreamingCallSettings.Builder + executePipelineSettings() { + return getStubSettingsBuilder().executePipelineSettings(); + } + /** Returns the builder for the settings used for calls to runAggregationQuery. */ public ServerStreamingCallSettings.Builder< RunAggregationQueryRequest, RunAggregationQueryResponse> diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/gapic_metadata.json b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/gapic_metadata.json index 05f7e5a5f..44b5ecb1d 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/gapic_metadata.json +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/gapic_metadata.json @@ -28,6 +28,9 @@ "DeleteDocument": { "methods": ["deleteDocument", "deleteDocument", "deleteDocumentCallable"] }, + "ExecutePipeline": { + "methods": ["executePipelineCallable"] + }, "GetDocument": { "methods": ["getDocument", "getDocumentCallable"] }, diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/package-info.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/package-info.java index 77ab24dd0..b935957ba 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/package-info.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreStub.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreStub.java index 0b3e92eb7..f79ecb994 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreStub.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreStub.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +35,8 @@ import com.google.firestore.v1.CreateDocumentRequest; import com.google.firestore.v1.DeleteDocumentRequest; import com.google.firestore.v1.Document; +import com.google.firestore.v1.ExecutePipelineRequest; +import com.google.firestore.v1.ExecutePipelineResponse; import com.google.firestore.v1.GetDocumentRequest; import com.google.firestore.v1.ListCollectionIdsRequest; import com.google.firestore.v1.ListCollectionIdsResponse; @@ -107,6 +109,11 @@ public ServerStreamingCallable runQueryCallab throw new UnsupportedOperationException("Not implemented: runQueryCallable()"); } + public ServerStreamingCallable + executePipelineCallable() { + throw new UnsupportedOperationException("Not implemented: executePipelineCallable()"); + } + public ServerStreamingCallable runAggregationQueryCallable() { throw new UnsupportedOperationException("Not implemented: runAggregationQueryCallable()"); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreStubSettings.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreStubSettings.java index f34ce9361..a92595290 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreStubSettings.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreStubSettings.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,6 +63,8 @@ import com.google.firestore.v1.Cursor; import com.google.firestore.v1.DeleteDocumentRequest; import com.google.firestore.v1.Document; +import com.google.firestore.v1.ExecutePipelineRequest; +import com.google.firestore.v1.ExecutePipelineResponse; import com.google.firestore.v1.GetDocumentRequest; import com.google.firestore.v1.ListCollectionIdsRequest; import com.google.firestore.v1.ListCollectionIdsResponse; @@ -144,6 +146,8 @@ public class FirestoreStubSettings extends StubSettings { private final UnaryCallSettings commitSettings; private final UnaryCallSettings rollbackSettings; private final ServerStreamingCallSettings runQuerySettings; + private final ServerStreamingCallSettings + executePipelineSettings; private final ServerStreamingCallSettings runAggregationQuerySettings; private final PagedCallSettings< @@ -370,6 +374,12 @@ public ServerStreamingCallSettings runQuerySe return runQuerySettings; } + /** Returns the object with the settings used for calls to executePipeline. */ + public ServerStreamingCallSettings + executePipelineSettings() { + return executePipelineSettings; + } + /** Returns the object with the settings used for calls to runAggregationQuery. */ public ServerStreamingCallSettings runAggregationQuerySettings() { @@ -485,7 +495,6 @@ public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } - @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(FirestoreStubSettings.class)) @@ -493,7 +502,6 @@ public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProvider GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(FirestoreStubSettings.class)) @@ -538,6 +546,7 @@ protected FirestoreStubSettings(Builder settingsBuilder) throws IOException { commitSettings = settingsBuilder.commitSettings().build(); rollbackSettings = settingsBuilder.rollbackSettings().build(); runQuerySettings = settingsBuilder.runQuerySettings().build(); + executePipelineSettings = settingsBuilder.executePipelineSettings().build(); runAggregationQuerySettings = settingsBuilder.runAggregationQuerySettings().build(); partitionQuerySettings = settingsBuilder.partitionQuerySettings().build(); writeSettings = settingsBuilder.writeSettings().build(); @@ -565,6 +574,9 @@ public static class Builder extends StubSettings.Builder rollbackSettings; private final ServerStreamingCallSettings.Builder runQuerySettings; + private final ServerStreamingCallSettings.Builder< + ExecutePipelineRequest, ExecutePipelineResponse> + executePipelineSettings; private final ServerStreamingCallSettings.Builder< RunAggregationQueryRequest, RunAggregationQueryResponse> runAggregationQuerySettings; @@ -606,6 +618,7 @@ public static class Builder extends StubSettings.BuildernewArrayList())); definitions.put( "no_retry_3_codes", ImmutableSet.copyOf(Lists.newArrayList())); definitions.put( @@ -664,6 +677,8 @@ public static class Builder extends StubSettings.Builder rollbackSettings() { return runQuerySettings; } + /** Returns the builder for the settings used for calls to executePipeline. */ + public ServerStreamingCallSettings.Builder + executePipelineSettings() { + return executePipelineSettings; + } + /** Returns the builder for the settings used for calls to runAggregationQuery. */ public ServerStreamingCallSettings.Builder< RunAggregationQueryRequest, RunAggregationQueryResponse> diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/GrpcFirestoreCallableFactory.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/GrpcFirestoreCallableFactory.java index 2c1cd24a4..388351bac 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/GrpcFirestoreCallableFactory.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/GrpcFirestoreCallableFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/GrpcFirestoreStub.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/GrpcFirestoreStub.java index 0be133886..03808fdb0 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/GrpcFirestoreStub.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/GrpcFirestoreStub.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,6 +40,8 @@ import com.google.firestore.v1.CreateDocumentRequest; import com.google.firestore.v1.DeleteDocumentRequest; import com.google.firestore.v1.Document; +import com.google.firestore.v1.ExecutePipelineRequest; +import com.google.firestore.v1.ExecutePipelineResponse; import com.google.firestore.v1.GetDocumentRequest; import com.google.firestore.v1.ListCollectionIdsRequest; import com.google.firestore.v1.ListCollectionIdsResponse; @@ -159,6 +161,17 @@ public class GrpcFirestoreStub extends FirestoreStub { .setResponseMarshaller(ProtoUtils.marshaller(RunQueryResponse.getDefaultInstance())) .build(); + private static final MethodDescriptor + executePipelineMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.SERVER_STREAMING) + .setFullMethodName("google.firestore.v1.Firestore/ExecutePipeline") + .setRequestMarshaller( + ProtoUtils.marshaller(ExecutePipelineRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(ExecutePipelineResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor runAggregationQueryMethodDescriptor = MethodDescriptor.newBuilder() @@ -240,6 +253,8 @@ public class GrpcFirestoreStub extends FirestoreStub { private final UnaryCallable commitCallable; private final UnaryCallable rollbackCallable; private final ServerStreamingCallable runQueryCallable; + private final ServerStreamingCallable + executePipelineCallable; private final ServerStreamingCallable runAggregationQueryCallable; private final UnaryCallable partitionQueryCallable; @@ -388,6 +403,17 @@ protected GrpcFirestoreStub( return builder.build(); }) .build(); + GrpcCallSettings + executePipelineTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(executePipelineMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("database", String.valueOf(request.getDatabase())); + return builder.build(); + }) + .build(); GrpcCallSettings runAggregationQueryTransportSettings = GrpcCallSettings.newBuilder() @@ -495,6 +521,9 @@ protected GrpcFirestoreStub( this.runQueryCallable = callableFactory.createServerStreamingCallable( runQueryTransportSettings, settings.runQuerySettings(), clientContext); + this.executePipelineCallable = + callableFactory.createServerStreamingCallable( + executePipelineTransportSettings, settings.executePipelineSettings(), clientContext); this.runAggregationQueryCallable = callableFactory.createServerStreamingCallable( runAggregationQueryTransportSettings, @@ -590,6 +619,12 @@ public ServerStreamingCallable runQueryCallab return runQueryCallable; } + @Override + public ServerStreamingCallable + executePipelineCallable() { + return executePipelineCallable; + } + @Override public ServerStreamingCallable runAggregationQueryCallable() { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreCallableFactory.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreCallableFactory.java index 78400d382..c123bc7d0 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreCallableFactory.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreCallableFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package com.google.cloud.firestore.v1.stub; -import com.google.api.core.BetaApi; import com.google.api.gax.httpjson.HttpJsonCallSettings; import com.google.api.gax.httpjson.HttpJsonCallableFactory; import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; @@ -41,7 +40,6 @@ *

This class is for advanced usage. */ @Generated("by gapic-generator-java") -@BetaApi public class HttpJsonFirestoreCallableFactory implements HttpJsonStubCallableFactory { @@ -73,8 +71,6 @@ public UnaryCallable createBatchingCa httpJsonCallSettings, callSettings, clientContext); } - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") @Override public OperationCallable createOperationCallable( diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreStub.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreStub.java index 9d8ad9cfa..9b7ebafe8 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreStub.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreStub.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import static com.google.cloud.firestore.v1.FirestoreClient.ListDocumentsPagedResponse; import static com.google.cloud.firestore.v1.FirestoreClient.PartitionQueryPagedResponse; -import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; @@ -46,6 +45,8 @@ import com.google.firestore.v1.CreateDocumentRequest; import com.google.firestore.v1.DeleteDocumentRequest; import com.google.firestore.v1.Document; +import com.google.firestore.v1.ExecutePipelineRequest; +import com.google.firestore.v1.ExecutePipelineResponse; import com.google.firestore.v1.GetDocumentRequest; import com.google.firestore.v1.ListCollectionIdsRequest; import com.google.firestore.v1.ListCollectionIdsResponse; @@ -80,7 +81,6 @@ *

This class is for advanced usage and reflects the underlying API directly. */ @Generated("by gapic-generator-java") -@BetaApi public class HttpJsonFirestoreStub extends FirestoreStub { private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); @@ -432,6 +432,43 @@ public class HttpJsonFirestoreStub extends FirestoreStub { .build()) .build(); + private static final ApiMethodDescriptor + executePipelineMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.firestore.v1.Firestore/ExecutePipeline") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.SERVER_STREAMING) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{database=projects/*/databases/*}:executePipeline", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "database", request.getDatabase()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearDatabase().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ExecutePipelineResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + private static final ApiMethodDescriptor runAggregationQueryMethodDescriptor = ApiMethodDescriptor.newBuilder() @@ -640,6 +677,8 @@ public class HttpJsonFirestoreStub extends FirestoreStub { private final UnaryCallable commitCallable; private final UnaryCallable rollbackCallable; private final ServerStreamingCallable runQueryCallable; + private final ServerStreamingCallable + executePipelineCallable; private final ServerStreamingCallable runAggregationQueryCallable; private final UnaryCallable partitionQueryCallable; @@ -796,6 +835,18 @@ protected HttpJsonFirestoreStub( return builder.build(); }) .build(); + HttpJsonCallSettings + executePipelineTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(executePipelineMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("database", String.valueOf(request.getDatabase())); + return builder.build(); + }) + .build(); HttpJsonCallSettings runAggregationQueryTransportSettings = HttpJsonCallSettings @@ -889,6 +940,9 @@ protected HttpJsonFirestoreStub( this.runQueryCallable = callableFactory.createServerStreamingCallable( runQueryTransportSettings, settings.runQuerySettings(), clientContext); + this.executePipelineCallable = + callableFactory.createServerStreamingCallable( + executePipelineTransportSettings, settings.executePipelineSettings(), clientContext); this.runAggregationQueryCallable = callableFactory.createServerStreamingCallable( runAggregationQueryTransportSettings, @@ -933,6 +987,7 @@ public static List getMethodDescriptors() { methodDescriptors.add(commitMethodDescriptor); methodDescriptors.add(rollbackMethodDescriptor); methodDescriptors.add(runQueryMethodDescriptor); + methodDescriptors.add(executePipelineMethodDescriptor); methodDescriptors.add(runAggregationQueryMethodDescriptor); methodDescriptors.add(partitionQueryMethodDescriptor); methodDescriptors.add(listCollectionIdsMethodDescriptor); @@ -994,6 +1049,12 @@ public ServerStreamingCallable runQueryCallab return runQueryCallable; } + @Override + public ServerStreamingCallable + executePipelineCallable() { + return executePipelineCallable; + } + @Override public ServerStreamingCallable runAggregationQueryCallable() { diff --git a/google-cloud-firestore/src/main/resources/META-INF/native-image/com.google.cloud.firestore.v1/reflect-config.json b/google-cloud-firestore/src/main/resources/META-INF/native-image/com.google.cloud.firestore.v1/reflect-config.json index 3ac840905..d7f0fd007 100644 --- a/google-cloud-firestore/src/main/resources/META-INF/native-image/com.google.cloud.firestore.v1/reflect-config.json +++ b/google-cloud-firestore/src/main/resources/META-INF/native-image/com.google.cloud.firestore.v1/reflect-config.json @@ -854,6 +854,60 @@ "allDeclaredClasses": true, "allPublicClasses": true }, + { + "name": "com.google.firestore.v1.ExecutePipelineRequest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.v1.ExecutePipelineRequest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.v1.ExecutePipelineResponse", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.v1.ExecutePipelineResponse$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.v1.ExecutionStats", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.v1.ExecutionStats$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, { "name": "com.google.firestore.v1.ExistenceFilter", "queryAllDeclaredConstructors": true, @@ -872,6 +926,60 @@ "allDeclaredClasses": true, "allPublicClasses": true }, + { + "name": "com.google.firestore.v1.ExplainMetrics", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.v1.ExplainMetrics$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.v1.ExplainOptions", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.v1.ExplainOptions$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.v1.Function", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.v1.Function$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, { "name": "com.google.firestore.v1.GetDocumentRequest", "queryAllDeclaredConstructors": true, @@ -1052,6 +1160,60 @@ "allDeclaredClasses": true, "allPublicClasses": true }, + { + "name": "com.google.firestore.v1.Pipeline", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.v1.Pipeline$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.v1.Pipeline$Stage", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.v1.Pipeline$Stage$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.v1.PlanSummary", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.v1.PlanSummary$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, { "name": "com.google.firestore.v1.Precondition", "queryAllDeclaredConstructors": true, @@ -1250,6 +1412,24 @@ "allDeclaredClasses": true, "allPublicClasses": true }, + { + "name": "com.google.firestore.v1.StructuredPipeline", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.v1.StructuredPipeline$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, { "name": "com.google.firestore.v1.StructuredQuery", "queryAllDeclaredConstructors": true, @@ -1385,6 +1565,33 @@ "allDeclaredClasses": true, "allPublicClasses": true }, + { + "name": "com.google.firestore.v1.StructuredQuery$FindNearest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.v1.StructuredQuery$FindNearest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.firestore.v1.StructuredQuery$FindNearest$DistanceMeasure", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, { "name": "com.google.firestore.v1.StructuredQuery$Order", "queryAllDeclaredConstructors": true, diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 2a894c021..393273237 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -55,7 +55,7 @@ public void projections() throws Exception { .project( Field.of("foo"), Constant.of("emptyValue").asAlias("emptyField"), - Field.of("embedding").cosineDistance(new double[]{1, 2, 3.0}).asAlias("distance")); + Field.of("embedding").cosineDistance(new double[] {1, 2, 3.0}).asAlias("distance")); // More compact p = diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/FirestoreClientHttpJsonTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/FirestoreClientHttpJsonTest.java index c92717d30..605cf0663 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/FirestoreClientHttpJsonTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/FirestoreClientHttpJsonTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -483,6 +483,17 @@ public void runQueryExceptionTest() throws Exception { mockService.addException(exception); } + @Test + public void executePipelineTest() throws Exception {} + + @Test + public void executePipelineExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + } + @Test public void runAggregationQueryTest() throws Exception {} diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/FirestoreClientTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/FirestoreClientTest.java index a0c3ecd53..97400f5ad 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/FirestoreClientTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/FirestoreClientTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,6 +47,8 @@ import com.google.firestore.v1.DeleteDocumentRequest; import com.google.firestore.v1.Document; import com.google.firestore.v1.DocumentMask; +import com.google.firestore.v1.ExecutePipelineRequest; +import com.google.firestore.v1.ExecutePipelineResponse; import com.google.firestore.v1.GetDocumentRequest; import com.google.firestore.v1.ListCollectionIdsRequest; import com.google.firestore.v1.ListCollectionIdsResponse; @@ -540,6 +542,52 @@ public void runQueryExceptionTest() throws Exception { } } + @Test + public void executePipelineTest() throws Exception { + ExecutePipelineResponse expectedResponse = + ExecutePipelineResponse.newBuilder() + .setTransaction(ByteString.EMPTY) + .addAllResults(new ArrayList()) + .setExecutionTime(Timestamp.newBuilder().build()) + .build(); + mockFirestore.addResponse(expectedResponse); + ExecutePipelineRequest request = + ExecutePipelineRequest.newBuilder().setDatabase("database1789464955").build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + ServerStreamingCallable callable = + client.executePipelineCallable(); + callable.serverStreamingCall(request, responseObserver); + + List actualResponses = responseObserver.future().get(); + Assert.assertEquals(1, actualResponses.size()); + Assert.assertEquals(expectedResponse, actualResponses.get(0)); + } + + @Test + public void executePipelineExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockFirestore.addException(exception); + ExecutePipelineRequest request = + ExecutePipelineRequest.newBuilder().setDatabase("database1789464955").build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + ServerStreamingCallable callable = + client.executePipelineCallable(); + callable.serverStreamingCall(request, responseObserver); + + try { + List actualResponses = responseObserver.future().get(); + Assert.fail("No exception thrown"); + } catch (ExecutionException e) { + Assert.assertTrue(e.getCause() instanceof InvalidArgumentException); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + @Test public void runAggregationQueryTest() throws Exception { RunAggregationQueryResponse expectedResponse = diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/MockFirestore.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/MockFirestore.java index 055cb5c60..9086a9deb 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/MockFirestore.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/MockFirestore.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/MockFirestoreImpl.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/MockFirestoreImpl.java index 1fb428f82..31eba7263 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/MockFirestoreImpl.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/MockFirestoreImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,8 @@ import com.google.firestore.v1.CreateDocumentRequest; import com.google.firestore.v1.DeleteDocumentRequest; import com.google.firestore.v1.Document; +import com.google.firestore.v1.ExecutePipelineRequest; +import com.google.firestore.v1.ExecutePipelineResponse; import com.google.firestore.v1.FirestoreGrpc.FirestoreImplBase; import com.google.firestore.v1.GetDocumentRequest; import com.google.firestore.v1.ListCollectionIdsRequest; @@ -273,6 +275,27 @@ public void runQuery(RunQueryRequest request, StreamObserver r } } + @Override + public void executePipeline( + ExecutePipelineRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof ExecutePipelineResponse) { + requests.add(request); + responseObserver.onNext(((ExecutePipelineResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ExecutePipeline, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + ExecutePipelineResponse.class.getName(), + Exception.class.getName()))); + } + } + @Override public void runAggregationQuery( RunAggregationQueryRequest request, diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/MockLocations.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/MockLocations.java index f9e50dc16..10cecbc88 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/MockLocations.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/MockLocations.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/MockLocationsImpl.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/MockLocationsImpl.java index 6e823521a..6e12a2e8d 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/MockLocationsImpl.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/v1/MockLocationsImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/grpc-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/FirestoreAdminGrpc.java b/grpc-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/FirestoreAdminGrpc.java index 97073f14b..69add7236 100644 --- a/grpc-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/FirestoreAdminGrpc.java +++ b/grpc-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/FirestoreAdminGrpc.java @@ -662,6 +662,419 @@ private FirestoreAdminGrpc() {} return getDeleteDatabaseMethod; } + private static volatile io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.GetBackupRequest, com.google.firestore.admin.v1.Backup> + getGetBackupMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "GetBackup", + requestType = com.google.firestore.admin.v1.GetBackupRequest.class, + responseType = com.google.firestore.admin.v1.Backup.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.GetBackupRequest, com.google.firestore.admin.v1.Backup> + getGetBackupMethod() { + io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.GetBackupRequest, com.google.firestore.admin.v1.Backup> + getGetBackupMethod; + if ((getGetBackupMethod = FirestoreAdminGrpc.getGetBackupMethod) == null) { + synchronized (FirestoreAdminGrpc.class) { + if ((getGetBackupMethod = FirestoreAdminGrpc.getGetBackupMethod) == null) { + FirestoreAdminGrpc.getGetBackupMethod = + getGetBackupMethod = + io.grpc.MethodDescriptor + . + newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "GetBackup")) + .setSampledToLocalTracing(true) + .setRequestMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.firestore.admin.v1.GetBackupRequest.getDefaultInstance())) + .setResponseMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.firestore.admin.v1.Backup.getDefaultInstance())) + .setSchemaDescriptor(new FirestoreAdminMethodDescriptorSupplier("GetBackup")) + .build(); + } + } + } + return getGetBackupMethod; + } + + private static volatile io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.ListBackupsRequest, + com.google.firestore.admin.v1.ListBackupsResponse> + getListBackupsMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "ListBackups", + requestType = com.google.firestore.admin.v1.ListBackupsRequest.class, + responseType = com.google.firestore.admin.v1.ListBackupsResponse.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.ListBackupsRequest, + com.google.firestore.admin.v1.ListBackupsResponse> + getListBackupsMethod() { + io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.ListBackupsRequest, + com.google.firestore.admin.v1.ListBackupsResponse> + getListBackupsMethod; + if ((getListBackupsMethod = FirestoreAdminGrpc.getListBackupsMethod) == null) { + synchronized (FirestoreAdminGrpc.class) { + if ((getListBackupsMethod = FirestoreAdminGrpc.getListBackupsMethod) == null) { + FirestoreAdminGrpc.getListBackupsMethod = + getListBackupsMethod = + io.grpc.MethodDescriptor + . + newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "ListBackups")) + .setSampledToLocalTracing(true) + .setRequestMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.firestore.admin.v1.ListBackupsRequest + .getDefaultInstance())) + .setResponseMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.firestore.admin.v1.ListBackupsResponse + .getDefaultInstance())) + .setSchemaDescriptor( + new FirestoreAdminMethodDescriptorSupplier("ListBackups")) + .build(); + } + } + } + return getListBackupsMethod; + } + + private static volatile io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.DeleteBackupRequest, com.google.protobuf.Empty> + getDeleteBackupMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "DeleteBackup", + requestType = com.google.firestore.admin.v1.DeleteBackupRequest.class, + responseType = com.google.protobuf.Empty.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.DeleteBackupRequest, com.google.protobuf.Empty> + getDeleteBackupMethod() { + io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.DeleteBackupRequest, com.google.protobuf.Empty> + getDeleteBackupMethod; + if ((getDeleteBackupMethod = FirestoreAdminGrpc.getDeleteBackupMethod) == null) { + synchronized (FirestoreAdminGrpc.class) { + if ((getDeleteBackupMethod = FirestoreAdminGrpc.getDeleteBackupMethod) == null) { + FirestoreAdminGrpc.getDeleteBackupMethod = + getDeleteBackupMethod = + io.grpc.MethodDescriptor + . + newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "DeleteBackup")) + .setSampledToLocalTracing(true) + .setRequestMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.firestore.admin.v1.DeleteBackupRequest + .getDefaultInstance())) + .setResponseMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.protobuf.Empty.getDefaultInstance())) + .setSchemaDescriptor( + new FirestoreAdminMethodDescriptorSupplier("DeleteBackup")) + .build(); + } + } + } + return getDeleteBackupMethod; + } + + private static volatile io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.RestoreDatabaseRequest, com.google.longrunning.Operation> + getRestoreDatabaseMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "RestoreDatabase", + requestType = com.google.firestore.admin.v1.RestoreDatabaseRequest.class, + responseType = com.google.longrunning.Operation.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.RestoreDatabaseRequest, com.google.longrunning.Operation> + getRestoreDatabaseMethod() { + io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.RestoreDatabaseRequest, com.google.longrunning.Operation> + getRestoreDatabaseMethod; + if ((getRestoreDatabaseMethod = FirestoreAdminGrpc.getRestoreDatabaseMethod) == null) { + synchronized (FirestoreAdminGrpc.class) { + if ((getRestoreDatabaseMethod = FirestoreAdminGrpc.getRestoreDatabaseMethod) == null) { + FirestoreAdminGrpc.getRestoreDatabaseMethod = + getRestoreDatabaseMethod = + io.grpc.MethodDescriptor + . + newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "RestoreDatabase")) + .setSampledToLocalTracing(true) + .setRequestMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.firestore.admin.v1.RestoreDatabaseRequest + .getDefaultInstance())) + .setResponseMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.longrunning.Operation.getDefaultInstance())) + .setSchemaDescriptor( + new FirestoreAdminMethodDescriptorSupplier("RestoreDatabase")) + .build(); + } + } + } + return getRestoreDatabaseMethod; + } + + private static volatile io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.CreateBackupScheduleRequest, + com.google.firestore.admin.v1.BackupSchedule> + getCreateBackupScheduleMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "CreateBackupSchedule", + requestType = com.google.firestore.admin.v1.CreateBackupScheduleRequest.class, + responseType = com.google.firestore.admin.v1.BackupSchedule.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.CreateBackupScheduleRequest, + com.google.firestore.admin.v1.BackupSchedule> + getCreateBackupScheduleMethod() { + io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.CreateBackupScheduleRequest, + com.google.firestore.admin.v1.BackupSchedule> + getCreateBackupScheduleMethod; + if ((getCreateBackupScheduleMethod = FirestoreAdminGrpc.getCreateBackupScheduleMethod) + == null) { + synchronized (FirestoreAdminGrpc.class) { + if ((getCreateBackupScheduleMethod = FirestoreAdminGrpc.getCreateBackupScheduleMethod) + == null) { + FirestoreAdminGrpc.getCreateBackupScheduleMethod = + getCreateBackupScheduleMethod = + io.grpc.MethodDescriptor + . + newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName( + generateFullMethodName(SERVICE_NAME, "CreateBackupSchedule")) + .setSampledToLocalTracing(true) + .setRequestMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.firestore.admin.v1.CreateBackupScheduleRequest + .getDefaultInstance())) + .setResponseMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.firestore.admin.v1.BackupSchedule.getDefaultInstance())) + .setSchemaDescriptor( + new FirestoreAdminMethodDescriptorSupplier("CreateBackupSchedule")) + .build(); + } + } + } + return getCreateBackupScheduleMethod; + } + + private static volatile io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.GetBackupScheduleRequest, + com.google.firestore.admin.v1.BackupSchedule> + getGetBackupScheduleMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "GetBackupSchedule", + requestType = com.google.firestore.admin.v1.GetBackupScheduleRequest.class, + responseType = com.google.firestore.admin.v1.BackupSchedule.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.GetBackupScheduleRequest, + com.google.firestore.admin.v1.BackupSchedule> + getGetBackupScheduleMethod() { + io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.GetBackupScheduleRequest, + com.google.firestore.admin.v1.BackupSchedule> + getGetBackupScheduleMethod; + if ((getGetBackupScheduleMethod = FirestoreAdminGrpc.getGetBackupScheduleMethod) == null) { + synchronized (FirestoreAdminGrpc.class) { + if ((getGetBackupScheduleMethod = FirestoreAdminGrpc.getGetBackupScheduleMethod) == null) { + FirestoreAdminGrpc.getGetBackupScheduleMethod = + getGetBackupScheduleMethod = + io.grpc.MethodDescriptor + . + newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "GetBackupSchedule")) + .setSampledToLocalTracing(true) + .setRequestMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.firestore.admin.v1.GetBackupScheduleRequest + .getDefaultInstance())) + .setResponseMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.firestore.admin.v1.BackupSchedule.getDefaultInstance())) + .setSchemaDescriptor( + new FirestoreAdminMethodDescriptorSupplier("GetBackupSchedule")) + .build(); + } + } + } + return getGetBackupScheduleMethod; + } + + private static volatile io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.ListBackupSchedulesRequest, + com.google.firestore.admin.v1.ListBackupSchedulesResponse> + getListBackupSchedulesMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "ListBackupSchedules", + requestType = com.google.firestore.admin.v1.ListBackupSchedulesRequest.class, + responseType = com.google.firestore.admin.v1.ListBackupSchedulesResponse.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.ListBackupSchedulesRequest, + com.google.firestore.admin.v1.ListBackupSchedulesResponse> + getListBackupSchedulesMethod() { + io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.ListBackupSchedulesRequest, + com.google.firestore.admin.v1.ListBackupSchedulesResponse> + getListBackupSchedulesMethod; + if ((getListBackupSchedulesMethod = FirestoreAdminGrpc.getListBackupSchedulesMethod) == null) { + synchronized (FirestoreAdminGrpc.class) { + if ((getListBackupSchedulesMethod = FirestoreAdminGrpc.getListBackupSchedulesMethod) + == null) { + FirestoreAdminGrpc.getListBackupSchedulesMethod = + getListBackupSchedulesMethod = + io.grpc.MethodDescriptor + . + newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName( + generateFullMethodName(SERVICE_NAME, "ListBackupSchedules")) + .setSampledToLocalTracing(true) + .setRequestMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.firestore.admin.v1.ListBackupSchedulesRequest + .getDefaultInstance())) + .setResponseMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.firestore.admin.v1.ListBackupSchedulesResponse + .getDefaultInstance())) + .setSchemaDescriptor( + new FirestoreAdminMethodDescriptorSupplier("ListBackupSchedules")) + .build(); + } + } + } + return getListBackupSchedulesMethod; + } + + private static volatile io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.UpdateBackupScheduleRequest, + com.google.firestore.admin.v1.BackupSchedule> + getUpdateBackupScheduleMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "UpdateBackupSchedule", + requestType = com.google.firestore.admin.v1.UpdateBackupScheduleRequest.class, + responseType = com.google.firestore.admin.v1.BackupSchedule.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.UpdateBackupScheduleRequest, + com.google.firestore.admin.v1.BackupSchedule> + getUpdateBackupScheduleMethod() { + io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.UpdateBackupScheduleRequest, + com.google.firestore.admin.v1.BackupSchedule> + getUpdateBackupScheduleMethod; + if ((getUpdateBackupScheduleMethod = FirestoreAdminGrpc.getUpdateBackupScheduleMethod) + == null) { + synchronized (FirestoreAdminGrpc.class) { + if ((getUpdateBackupScheduleMethod = FirestoreAdminGrpc.getUpdateBackupScheduleMethod) + == null) { + FirestoreAdminGrpc.getUpdateBackupScheduleMethod = + getUpdateBackupScheduleMethod = + io.grpc.MethodDescriptor + . + newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName( + generateFullMethodName(SERVICE_NAME, "UpdateBackupSchedule")) + .setSampledToLocalTracing(true) + .setRequestMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.firestore.admin.v1.UpdateBackupScheduleRequest + .getDefaultInstance())) + .setResponseMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.firestore.admin.v1.BackupSchedule.getDefaultInstance())) + .setSchemaDescriptor( + new FirestoreAdminMethodDescriptorSupplier("UpdateBackupSchedule")) + .build(); + } + } + } + return getUpdateBackupScheduleMethod; + } + + private static volatile io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.DeleteBackupScheduleRequest, com.google.protobuf.Empty> + getDeleteBackupScheduleMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "DeleteBackupSchedule", + requestType = com.google.firestore.admin.v1.DeleteBackupScheduleRequest.class, + responseType = com.google.protobuf.Empty.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.DeleteBackupScheduleRequest, com.google.protobuf.Empty> + getDeleteBackupScheduleMethod() { + io.grpc.MethodDescriptor< + com.google.firestore.admin.v1.DeleteBackupScheduleRequest, com.google.protobuf.Empty> + getDeleteBackupScheduleMethod; + if ((getDeleteBackupScheduleMethod = FirestoreAdminGrpc.getDeleteBackupScheduleMethod) + == null) { + synchronized (FirestoreAdminGrpc.class) { + if ((getDeleteBackupScheduleMethod = FirestoreAdminGrpc.getDeleteBackupScheduleMethod) + == null) { + FirestoreAdminGrpc.getDeleteBackupScheduleMethod = + getDeleteBackupScheduleMethod = + io.grpc.MethodDescriptor + . + newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName( + generateFullMethodName(SERVICE_NAME, "DeleteBackupSchedule")) + .setSampledToLocalTracing(true) + .setRequestMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.firestore.admin.v1.DeleteBackupScheduleRequest + .getDefaultInstance())) + .setResponseMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.protobuf.Empty.getDefaultInstance())) + .setSchemaDescriptor( + new FirestoreAdminMethodDescriptorSupplier("DeleteBackupSchedule")) + .build(); + } + } + } + return getDeleteBackupScheduleMethod; + } + /** Creates a new async stub that supports all call types for the service */ public static FirestoreAdminStub newStub(io.grpc.Channel channel) { io.grpc.stub.AbstractStub.StubFactory factory = @@ -963,6 +1376,152 @@ default void deleteDatabase( io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall( getDeleteDatabaseMethod(), responseObserver); } + + /** + * + * + *

+     * Gets information about a backup.
+     * 
+ */ + default void getBackup( + com.google.firestore.admin.v1.GetBackupRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getGetBackupMethod(), responseObserver); + } + + /** + * + * + *
+     * Lists all the backups.
+     * 
+ */ + default void listBackups( + com.google.firestore.admin.v1.ListBackupsRequest request, + io.grpc.stub.StreamObserver + responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall( + getListBackupsMethod(), responseObserver); + } + + /** + * + * + *
+     * Deletes a backup.
+     * 
+ */ + default void deleteBackup( + com.google.firestore.admin.v1.DeleteBackupRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall( + getDeleteBackupMethod(), responseObserver); + } + + /** + * + * + *
+     * Creates a new database by restoring from an existing backup.
+     * The new database must be in the same cloud region or multi-region location
+     * as the existing backup. This behaves similar to
+     * [FirestoreAdmin.CreateDatabase][google.firestore.admin.v1.CreateDatabase]
+     * except instead of creating a new empty database, a new database is created
+     * with the database type, index configuration, and documents from an existing
+     * backup.
+     * The [long-running operation][google.longrunning.Operation] can be used to
+     * track the progress of the restore, with the Operation's
+     * [metadata][google.longrunning.Operation.metadata] field type being the
+     * [RestoreDatabaseMetadata][google.firestore.admin.v1.RestoreDatabaseMetadata].
+     * The [response][google.longrunning.Operation.response] type is the
+     * [Database][google.firestore.admin.v1.Database] if the restore was
+     * successful. The new database is not readable or writeable until the LRO has
+     * completed.
+     * 
+ */ + default void restoreDatabase( + com.google.firestore.admin.v1.RestoreDatabaseRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall( + getRestoreDatabaseMethod(), responseObserver); + } + + /** + * + * + *
+     * Creates a backup schedule on a database.
+     * At most two backup schedules can be configured on a database, one daily
+     * backup schedule and one weekly backup schedule.
+     * 
+ */ + default void createBackupSchedule( + com.google.firestore.admin.v1.CreateBackupScheduleRequest request, + io.grpc.stub.StreamObserver + responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall( + getCreateBackupScheduleMethod(), responseObserver); + } + + /** + * + * + *
+     * Gets information about a backup schedule.
+     * 
+ */ + default void getBackupSchedule( + com.google.firestore.admin.v1.GetBackupScheduleRequest request, + io.grpc.stub.StreamObserver + responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall( + getGetBackupScheduleMethod(), responseObserver); + } + + /** + * + * + *
+     * List backup schedules.
+     * 
+ */ + default void listBackupSchedules( + com.google.firestore.admin.v1.ListBackupSchedulesRequest request, + io.grpc.stub.StreamObserver + responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall( + getListBackupSchedulesMethod(), responseObserver); + } + + /** + * + * + *
+     * Updates a backup schedule.
+     * 
+ */ + default void updateBackupSchedule( + com.google.firestore.admin.v1.UpdateBackupScheduleRequest request, + io.grpc.stub.StreamObserver + responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall( + getUpdateBackupScheduleMethod(), responseObserver); + } + + /** + * + * + *
+     * Deletes a backup schedule.
+     * 
+ */ + default void deleteBackupSchedule( + com.google.firestore.admin.v1.DeleteBackupScheduleRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall( + getDeleteBackupScheduleMethod(), responseObserver); + } } /** @@ -1185,11 +1744,159 @@ public void listFields( * https://cloud.google.com/firestore/docs/manage-data/export-import * */ - public void exportDocuments( - com.google.firestore.admin.v1.ExportDocumentsRequest request, - io.grpc.stub.StreamObserver responseObserver) { + public void exportDocuments( + com.google.firestore.admin.v1.ExportDocumentsRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getExportDocumentsMethod(), getCallOptions()), + request, + responseObserver); + } + + /** + * + * + *
+     * Imports documents into Google Cloud Firestore. Existing documents with the
+     * same name are overwritten. The import occurs in the background and its
+     * progress can be monitored and managed via the Operation resource that is
+     * created. If an ImportDocuments operation is cancelled, it is possible
+     * that a subset of the data has already been imported to Cloud Firestore.
+     * 
+ */ + public void importDocuments( + com.google.firestore.admin.v1.ImportDocumentsRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getImportDocumentsMethod(), getCallOptions()), + request, + responseObserver); + } + + /** + * + * + *
+     * Create a database.
+     * 
+ */ + public void createDatabase( + com.google.firestore.admin.v1.CreateDatabaseRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getCreateDatabaseMethod(), getCallOptions()), + request, + responseObserver); + } + + /** + * + * + *
+     * Gets information about a database.
+     * 
+ */ + public void getDatabase( + com.google.firestore.admin.v1.GetDatabaseRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getGetDatabaseMethod(), getCallOptions()), + request, + responseObserver); + } + + /** + * + * + *
+     * List all the databases in the project.
+     * 
+ */ + public void listDatabases( + com.google.firestore.admin.v1.ListDatabasesRequest request, + io.grpc.stub.StreamObserver + responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getListDatabasesMethod(), getCallOptions()), + request, + responseObserver); + } + + /** + * + * + *
+     * Updates a database.
+     * 
+ */ + public void updateDatabase( + com.google.firestore.admin.v1.UpdateDatabaseRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getUpdateDatabaseMethod(), getCallOptions()), + request, + responseObserver); + } + + /** + * + * + *
+     * Deletes a database.
+     * 
+ */ + public void deleteDatabase( + com.google.firestore.admin.v1.DeleteDatabaseRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getDeleteDatabaseMethod(), getCallOptions()), + request, + responseObserver); + } + + /** + * + * + *
+     * Gets information about a backup.
+     * 
+ */ + public void getBackup( + com.google.firestore.admin.v1.GetBackupRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getGetBackupMethod(), getCallOptions()), request, responseObserver); + } + + /** + * + * + *
+     * Lists all the backups.
+     * 
+ */ + public void listBackups( + com.google.firestore.admin.v1.ListBackupsRequest request, + io.grpc.stub.StreamObserver + responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getListBackupsMethod(), getCallOptions()), + request, + responseObserver); + } + + /** + * + * + *
+     * Deletes a backup.
+     * 
+ */ + public void deleteBackup( + com.google.firestore.admin.v1.DeleteBackupRequest request, + io.grpc.stub.StreamObserver responseObserver) { io.grpc.stub.ClientCalls.asyncUnaryCall( - getChannel().newCall(getExportDocumentsMethod(), getCallOptions()), + getChannel().newCall(getDeleteBackupMethod(), getCallOptions()), request, responseObserver); } @@ -1198,18 +1905,28 @@ public void exportDocuments( * * *
-     * Imports documents into Google Cloud Firestore. Existing documents with the
-     * same name are overwritten. The import occurs in the background and its
-     * progress can be monitored and managed via the Operation resource that is
-     * created. If an ImportDocuments operation is cancelled, it is possible
-     * that a subset of the data has already been imported to Cloud Firestore.
+     * Creates a new database by restoring from an existing backup.
+     * The new database must be in the same cloud region or multi-region location
+     * as the existing backup. This behaves similar to
+     * [FirestoreAdmin.CreateDatabase][google.firestore.admin.v1.CreateDatabase]
+     * except instead of creating a new empty database, a new database is created
+     * with the database type, index configuration, and documents from an existing
+     * backup.
+     * The [long-running operation][google.longrunning.Operation] can be used to
+     * track the progress of the restore, with the Operation's
+     * [metadata][google.longrunning.Operation.metadata] field type being the
+     * [RestoreDatabaseMetadata][google.firestore.admin.v1.RestoreDatabaseMetadata].
+     * The [response][google.longrunning.Operation.response] type is the
+     * [Database][google.firestore.admin.v1.Database] if the restore was
+     * successful. The new database is not readable or writeable until the LRO has
+     * completed.
      * 
*/ - public void importDocuments( - com.google.firestore.admin.v1.ImportDocumentsRequest request, + public void restoreDatabase( + com.google.firestore.admin.v1.RestoreDatabaseRequest request, io.grpc.stub.StreamObserver responseObserver) { io.grpc.stub.ClientCalls.asyncUnaryCall( - getChannel().newCall(getImportDocumentsMethod(), getCallOptions()), + getChannel().newCall(getRestoreDatabaseMethod(), getCallOptions()), request, responseObserver); } @@ -1218,14 +1935,17 @@ public void importDocuments( * * *
-     * Create a database.
+     * Creates a backup schedule on a database.
+     * At most two backup schedules can be configured on a database, one daily
+     * backup schedule and one weekly backup schedule.
      * 
*/ - public void createDatabase( - com.google.firestore.admin.v1.CreateDatabaseRequest request, - io.grpc.stub.StreamObserver responseObserver) { + public void createBackupSchedule( + com.google.firestore.admin.v1.CreateBackupScheduleRequest request, + io.grpc.stub.StreamObserver + responseObserver) { io.grpc.stub.ClientCalls.asyncUnaryCall( - getChannel().newCall(getCreateDatabaseMethod(), getCallOptions()), + getChannel().newCall(getCreateBackupScheduleMethod(), getCallOptions()), request, responseObserver); } @@ -1234,14 +1954,15 @@ public void createDatabase( * * *
-     * Gets information about a database.
+     * Gets information about a backup schedule.
      * 
*/ - public void getDatabase( - com.google.firestore.admin.v1.GetDatabaseRequest request, - io.grpc.stub.StreamObserver responseObserver) { + public void getBackupSchedule( + com.google.firestore.admin.v1.GetBackupScheduleRequest request, + io.grpc.stub.StreamObserver + responseObserver) { io.grpc.stub.ClientCalls.asyncUnaryCall( - getChannel().newCall(getGetDatabaseMethod(), getCallOptions()), + getChannel().newCall(getGetBackupScheduleMethod(), getCallOptions()), request, responseObserver); } @@ -1250,15 +1971,15 @@ public void getDatabase( * * *
-     * List all the databases in the project.
+     * List backup schedules.
      * 
*/ - public void listDatabases( - com.google.firestore.admin.v1.ListDatabasesRequest request, - io.grpc.stub.StreamObserver + public void listBackupSchedules( + com.google.firestore.admin.v1.ListBackupSchedulesRequest request, + io.grpc.stub.StreamObserver responseObserver) { io.grpc.stub.ClientCalls.asyncUnaryCall( - getChannel().newCall(getListDatabasesMethod(), getCallOptions()), + getChannel().newCall(getListBackupSchedulesMethod(), getCallOptions()), request, responseObserver); } @@ -1267,14 +1988,15 @@ public void listDatabases( * * *
-     * Updates a database.
+     * Updates a backup schedule.
      * 
*/ - public void updateDatabase( - com.google.firestore.admin.v1.UpdateDatabaseRequest request, - io.grpc.stub.StreamObserver responseObserver) { + public void updateBackupSchedule( + com.google.firestore.admin.v1.UpdateBackupScheduleRequest request, + io.grpc.stub.StreamObserver + responseObserver) { io.grpc.stub.ClientCalls.asyncUnaryCall( - getChannel().newCall(getUpdateDatabaseMethod(), getCallOptions()), + getChannel().newCall(getUpdateBackupScheduleMethod(), getCallOptions()), request, responseObserver); } @@ -1283,14 +2005,14 @@ public void updateDatabase( * * *
-     * Deletes a database.
+     * Deletes a backup schedule.
      * 
*/ - public void deleteDatabase( - com.google.firestore.admin.v1.DeleteDatabaseRequest request, - io.grpc.stub.StreamObserver responseObserver) { + public void deleteBackupSchedule( + com.google.firestore.admin.v1.DeleteBackupScheduleRequest request, + io.grpc.stub.StreamObserver responseObserver) { io.grpc.stub.ClientCalls.asyncUnaryCall( - getChannel().newCall(getDeleteDatabaseMethod(), getCallOptions()), + getChannel().newCall(getDeleteBackupScheduleMethod(), getCallOptions()), request, responseObserver); } @@ -1552,6 +2274,139 @@ public com.google.longrunning.Operation deleteDatabase( return io.grpc.stub.ClientCalls.blockingUnaryCall( getChannel(), getDeleteDatabaseMethod(), getCallOptions(), request); } + + /** + * + * + *
+     * Gets information about a backup.
+     * 
+ */ + public com.google.firestore.admin.v1.Backup getBackup( + com.google.firestore.admin.v1.GetBackupRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getGetBackupMethod(), getCallOptions(), request); + } + + /** + * + * + *
+     * Lists all the backups.
+     * 
+ */ + public com.google.firestore.admin.v1.ListBackupsResponse listBackups( + com.google.firestore.admin.v1.ListBackupsRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getListBackupsMethod(), getCallOptions(), request); + } + + /** + * + * + *
+     * Deletes a backup.
+     * 
+ */ + public com.google.protobuf.Empty deleteBackup( + com.google.firestore.admin.v1.DeleteBackupRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getDeleteBackupMethod(), getCallOptions(), request); + } + + /** + * + * + *
+     * Creates a new database by restoring from an existing backup.
+     * The new database must be in the same cloud region or multi-region location
+     * as the existing backup. This behaves similar to
+     * [FirestoreAdmin.CreateDatabase][google.firestore.admin.v1.CreateDatabase]
+     * except instead of creating a new empty database, a new database is created
+     * with the database type, index configuration, and documents from an existing
+     * backup.
+     * The [long-running operation][google.longrunning.Operation] can be used to
+     * track the progress of the restore, with the Operation's
+     * [metadata][google.longrunning.Operation.metadata] field type being the
+     * [RestoreDatabaseMetadata][google.firestore.admin.v1.RestoreDatabaseMetadata].
+     * The [response][google.longrunning.Operation.response] type is the
+     * [Database][google.firestore.admin.v1.Database] if the restore was
+     * successful. The new database is not readable or writeable until the LRO has
+     * completed.
+     * 
+ */ + public com.google.longrunning.Operation restoreDatabase( + com.google.firestore.admin.v1.RestoreDatabaseRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getRestoreDatabaseMethod(), getCallOptions(), request); + } + + /** + * + * + *
+     * Creates a backup schedule on a database.
+     * At most two backup schedules can be configured on a database, one daily
+     * backup schedule and one weekly backup schedule.
+     * 
+ */ + public com.google.firestore.admin.v1.BackupSchedule createBackupSchedule( + com.google.firestore.admin.v1.CreateBackupScheduleRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getCreateBackupScheduleMethod(), getCallOptions(), request); + } + + /** + * + * + *
+     * Gets information about a backup schedule.
+     * 
+ */ + public com.google.firestore.admin.v1.BackupSchedule getBackupSchedule( + com.google.firestore.admin.v1.GetBackupScheduleRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getGetBackupScheduleMethod(), getCallOptions(), request); + } + + /** + * + * + *
+     * List backup schedules.
+     * 
+ */ + public com.google.firestore.admin.v1.ListBackupSchedulesResponse listBackupSchedules( + com.google.firestore.admin.v1.ListBackupSchedulesRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getListBackupSchedulesMethod(), getCallOptions(), request); + } + + /** + * + * + *
+     * Updates a backup schedule.
+     * 
+ */ + public com.google.firestore.admin.v1.BackupSchedule updateBackupSchedule( + com.google.firestore.admin.v1.UpdateBackupScheduleRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getUpdateBackupScheduleMethod(), getCallOptions(), request); + } + + /** + * + * + *
+     * Deletes a backup schedule.
+     * 
+ */ + public com.google.protobuf.Empty deleteBackupSchedule( + com.google.firestore.admin.v1.DeleteBackupScheduleRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getDeleteBackupScheduleMethod(), getCallOptions(), request); + } } /** @@ -1814,6 +2669,144 @@ protected FirestoreAdminFutureStub build( return io.grpc.stub.ClientCalls.futureUnaryCall( getChannel().newCall(getDeleteDatabaseMethod(), getCallOptions()), request); } + + /** + * + * + *
+     * Gets information about a backup.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture + getBackup(com.google.firestore.admin.v1.GetBackupRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getGetBackupMethod(), getCallOptions()), request); + } + + /** + * + * + *
+     * Lists all the backups.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture< + com.google.firestore.admin.v1.ListBackupsResponse> + listBackups(com.google.firestore.admin.v1.ListBackupsRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getListBackupsMethod(), getCallOptions()), request); + } + + /** + * + * + *
+     * Deletes a backup.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture + deleteBackup(com.google.firestore.admin.v1.DeleteBackupRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getDeleteBackupMethod(), getCallOptions()), request); + } + + /** + * + * + *
+     * Creates a new database by restoring from an existing backup.
+     * The new database must be in the same cloud region or multi-region location
+     * as the existing backup. This behaves similar to
+     * [FirestoreAdmin.CreateDatabase][google.firestore.admin.v1.CreateDatabase]
+     * except instead of creating a new empty database, a new database is created
+     * with the database type, index configuration, and documents from an existing
+     * backup.
+     * The [long-running operation][google.longrunning.Operation] can be used to
+     * track the progress of the restore, with the Operation's
+     * [metadata][google.longrunning.Operation.metadata] field type being the
+     * [RestoreDatabaseMetadata][google.firestore.admin.v1.RestoreDatabaseMetadata].
+     * The [response][google.longrunning.Operation.response] type is the
+     * [Database][google.firestore.admin.v1.Database] if the restore was
+     * successful. The new database is not readable or writeable until the LRO has
+     * completed.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture + restoreDatabase(com.google.firestore.admin.v1.RestoreDatabaseRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getRestoreDatabaseMethod(), getCallOptions()), request); + } + + /** + * + * + *
+     * Creates a backup schedule on a database.
+     * At most two backup schedules can be configured on a database, one daily
+     * backup schedule and one weekly backup schedule.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture< + com.google.firestore.admin.v1.BackupSchedule> + createBackupSchedule(com.google.firestore.admin.v1.CreateBackupScheduleRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getCreateBackupScheduleMethod(), getCallOptions()), request); + } + + /** + * + * + *
+     * Gets information about a backup schedule.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture< + com.google.firestore.admin.v1.BackupSchedule> + getBackupSchedule(com.google.firestore.admin.v1.GetBackupScheduleRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getGetBackupScheduleMethod(), getCallOptions()), request); + } + + /** + * + * + *
+     * List backup schedules.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture< + com.google.firestore.admin.v1.ListBackupSchedulesResponse> + listBackupSchedules(com.google.firestore.admin.v1.ListBackupSchedulesRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getListBackupSchedulesMethod(), getCallOptions()), request); + } + + /** + * + * + *
+     * Updates a backup schedule.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture< + com.google.firestore.admin.v1.BackupSchedule> + updateBackupSchedule(com.google.firestore.admin.v1.UpdateBackupScheduleRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getUpdateBackupScheduleMethod(), getCallOptions()), request); + } + + /** + * + * + *
+     * Deletes a backup schedule.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture + deleteBackupSchedule(com.google.firestore.admin.v1.DeleteBackupScheduleRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getDeleteBackupScheduleMethod(), getCallOptions()), request); + } } private static final int METHODID_CREATE_INDEX = 0; @@ -1830,6 +2823,15 @@ protected FirestoreAdminFutureStub build( private static final int METHODID_LIST_DATABASES = 11; private static final int METHODID_UPDATE_DATABASE = 12; private static final int METHODID_DELETE_DATABASE = 13; + private static final int METHODID_GET_BACKUP = 14; + private static final int METHODID_LIST_BACKUPS = 15; + private static final int METHODID_DELETE_BACKUP = 16; + private static final int METHODID_RESTORE_DATABASE = 17; + private static final int METHODID_CREATE_BACKUP_SCHEDULE = 18; + private static final int METHODID_GET_BACKUP_SCHEDULE = 19; + private static final int METHODID_LIST_BACKUP_SCHEDULES = 20; + private static final int METHODID_UPDATE_BACKUP_SCHEDULE = 21; + private static final int METHODID_DELETE_BACKUP_SCHEDULE = 22; private static final class MethodHandlers implements io.grpc.stub.ServerCalls.UnaryMethod, @@ -1922,6 +2924,57 @@ public void invoke(Req request, io.grpc.stub.StreamObserver responseObserv (com.google.firestore.admin.v1.DeleteDatabaseRequest) request, (io.grpc.stub.StreamObserver) responseObserver); break; + case METHODID_GET_BACKUP: + serviceImpl.getBackup( + (com.google.firestore.admin.v1.GetBackupRequest) request, + (io.grpc.stub.StreamObserver) responseObserver); + break; + case METHODID_LIST_BACKUPS: + serviceImpl.listBackups( + (com.google.firestore.admin.v1.ListBackupsRequest) request, + (io.grpc.stub.StreamObserver) + responseObserver); + break; + case METHODID_DELETE_BACKUP: + serviceImpl.deleteBackup( + (com.google.firestore.admin.v1.DeleteBackupRequest) request, + (io.grpc.stub.StreamObserver) responseObserver); + break; + case METHODID_RESTORE_DATABASE: + serviceImpl.restoreDatabase( + (com.google.firestore.admin.v1.RestoreDatabaseRequest) request, + (io.grpc.stub.StreamObserver) responseObserver); + break; + case METHODID_CREATE_BACKUP_SCHEDULE: + serviceImpl.createBackupSchedule( + (com.google.firestore.admin.v1.CreateBackupScheduleRequest) request, + (io.grpc.stub.StreamObserver) + responseObserver); + break; + case METHODID_GET_BACKUP_SCHEDULE: + serviceImpl.getBackupSchedule( + (com.google.firestore.admin.v1.GetBackupScheduleRequest) request, + (io.grpc.stub.StreamObserver) + responseObserver); + break; + case METHODID_LIST_BACKUP_SCHEDULES: + serviceImpl.listBackupSchedules( + (com.google.firestore.admin.v1.ListBackupSchedulesRequest) request, + (io.grpc.stub.StreamObserver< + com.google.firestore.admin.v1.ListBackupSchedulesResponse>) + responseObserver); + break; + case METHODID_UPDATE_BACKUP_SCHEDULE: + serviceImpl.updateBackupSchedule( + (com.google.firestore.admin.v1.UpdateBackupScheduleRequest) request, + (io.grpc.stub.StreamObserver) + responseObserver); + break; + case METHODID_DELETE_BACKUP_SCHEDULE: + serviceImpl.deleteBackupSchedule( + (com.google.firestore.admin.v1.DeleteBackupScheduleRequest) request, + (io.grpc.stub.StreamObserver) responseObserver); + break; default: throw new AssertionError(); } @@ -2027,6 +3080,65 @@ public static final io.grpc.ServerServiceDefinition bindService(AsyncService ser new MethodHandlers< com.google.firestore.admin.v1.DeleteDatabaseRequest, com.google.longrunning.Operation>(service, METHODID_DELETE_DATABASE))) + .addMethod( + getGetBackupMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.firestore.admin.v1.GetBackupRequest, + com.google.firestore.admin.v1.Backup>(service, METHODID_GET_BACKUP))) + .addMethod( + getListBackupsMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.firestore.admin.v1.ListBackupsRequest, + com.google.firestore.admin.v1.ListBackupsResponse>( + service, METHODID_LIST_BACKUPS))) + .addMethod( + getDeleteBackupMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.firestore.admin.v1.DeleteBackupRequest, com.google.protobuf.Empty>( + service, METHODID_DELETE_BACKUP))) + .addMethod( + getRestoreDatabaseMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.firestore.admin.v1.RestoreDatabaseRequest, + com.google.longrunning.Operation>(service, METHODID_RESTORE_DATABASE))) + .addMethod( + getCreateBackupScheduleMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.firestore.admin.v1.CreateBackupScheduleRequest, + com.google.firestore.admin.v1.BackupSchedule>( + service, METHODID_CREATE_BACKUP_SCHEDULE))) + .addMethod( + getGetBackupScheduleMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.firestore.admin.v1.GetBackupScheduleRequest, + com.google.firestore.admin.v1.BackupSchedule>( + service, METHODID_GET_BACKUP_SCHEDULE))) + .addMethod( + getListBackupSchedulesMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.firestore.admin.v1.ListBackupSchedulesRequest, + com.google.firestore.admin.v1.ListBackupSchedulesResponse>( + service, METHODID_LIST_BACKUP_SCHEDULES))) + .addMethod( + getUpdateBackupScheduleMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.firestore.admin.v1.UpdateBackupScheduleRequest, + com.google.firestore.admin.v1.BackupSchedule>( + service, METHODID_UPDATE_BACKUP_SCHEDULE))) + .addMethod( + getDeleteBackupScheduleMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.firestore.admin.v1.DeleteBackupScheduleRequest, + com.google.protobuf.Empty>(service, METHODID_DELETE_BACKUP_SCHEDULE))) .build(); } @@ -2092,6 +3204,15 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() { .addMethod(getListDatabasesMethod()) .addMethod(getUpdateDatabaseMethod()) .addMethod(getDeleteDatabaseMethod()) + .addMethod(getGetBackupMethod()) + .addMethod(getListBackupsMethod()) + .addMethod(getDeleteBackupMethod()) + .addMethod(getRestoreDatabaseMethod()) + .addMethod(getCreateBackupScheduleMethod()) + .addMethod(getGetBackupScheduleMethod()) + .addMethod(getListBackupSchedulesMethod()) + .addMethod(getUpdateBackupScheduleMethod()) + .addMethod(getDeleteBackupScheduleMethod()) .build(); } } diff --git a/grpc-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/FirestoreGrpc.java b/grpc-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/FirestoreGrpc.java index 24bd52f05..ecdbe1c13 100644 --- a/grpc-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/FirestoreGrpc.java +++ b/grpc-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/FirestoreGrpc.java @@ -421,6 +421,50 @@ private FirestoreGrpc() {} return getRunQueryMethod; } + private static volatile io.grpc.MethodDescriptor< + com.google.firestore.v1.ExecutePipelineRequest, + com.google.firestore.v1.ExecutePipelineResponse> + getExecutePipelineMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "ExecutePipeline", + requestType = com.google.firestore.v1.ExecutePipelineRequest.class, + responseType = com.google.firestore.v1.ExecutePipelineResponse.class, + methodType = io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING) + public static io.grpc.MethodDescriptor< + com.google.firestore.v1.ExecutePipelineRequest, + com.google.firestore.v1.ExecutePipelineResponse> + getExecutePipelineMethod() { + io.grpc.MethodDescriptor< + com.google.firestore.v1.ExecutePipelineRequest, + com.google.firestore.v1.ExecutePipelineResponse> + getExecutePipelineMethod; + if ((getExecutePipelineMethod = FirestoreGrpc.getExecutePipelineMethod) == null) { + synchronized (FirestoreGrpc.class) { + if ((getExecutePipelineMethod = FirestoreGrpc.getExecutePipelineMethod) == null) { + FirestoreGrpc.getExecutePipelineMethod = + getExecutePipelineMethod = + io.grpc.MethodDescriptor + . + newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "ExecutePipeline")) + .setSampledToLocalTracing(true) + .setRequestMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.firestore.v1.ExecutePipelineRequest.getDefaultInstance())) + .setResponseMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.firestore.v1.ExecutePipelineResponse.getDefaultInstance())) + .setSchemaDescriptor(new FirestoreMethodDescriptorSupplier("ExecutePipeline")) + .build(); + } + } + } + return getExecutePipelineMethod; + } + private static volatile io.grpc.MethodDescriptor< com.google.firestore.v1.RunAggregationQueryRequest, com.google.firestore.v1.RunAggregationQueryResponse> @@ -906,6 +950,21 @@ default void runQuery( io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getRunQueryMethod(), responseObserver); } + /** + * + * + *
+     * Executes a pipeline query.
+     * 
+ */ + default void executePipeline( + com.google.firestore.v1.ExecutePipelineRequest request, + io.grpc.stub.StreamObserver + responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall( + getExecutePipelineMethod(), responseObserver); + } + /** * * @@ -1212,6 +1271,23 @@ public void runQuery( getChannel().newCall(getRunQueryMethod(), getCallOptions()), request, responseObserver); } + /** + * + * + *
+     * Executes a pipeline query.
+     * 
+ */ + public void executePipeline( + com.google.firestore.v1.ExecutePipelineRequest request, + io.grpc.stub.StreamObserver + responseObserver) { + io.grpc.stub.ClientCalls.asyncServerStreamingCall( + getChannel().newCall(getExecutePipelineMethod(), getCallOptions()), + request, + responseObserver); + } + /** * * @@ -1483,6 +1559,19 @@ public java.util.Iterator runQuery( getChannel(), getRunQueryMethod(), getCallOptions(), request); } + /** + * + * + *
+     * Executes a pipeline query.
+     * 
+ */ + public java.util.Iterator executePipeline( + com.google.firestore.v1.ExecutePipelineRequest request) { + return io.grpc.stub.ClientCalls.blockingServerStreamingCall( + getChannel(), getExecutePipelineMethod(), getCallOptions(), request); + } + /** * * @@ -1759,13 +1848,14 @@ public com.google.common.util.concurrent.ListenableFuture implements io.grpc.stub.ServerCalls.UnaryMethod, @@ -1834,6 +1924,12 @@ public void invoke(Req request, io.grpc.stub.StreamObserver responseObserv (io.grpc.stub.StreamObserver) responseObserver); break; + case METHODID_EXECUTE_PIPELINE: + serviceImpl.executePipeline( + (com.google.firestore.v1.ExecutePipelineRequest) request, + (io.grpc.stub.StreamObserver) + responseObserver); + break; case METHODID_RUN_AGGREGATION_QUERY: serviceImpl.runAggregationQuery( (com.google.firestore.v1.RunAggregationQueryRequest) request, @@ -1948,6 +2044,13 @@ public static final io.grpc.ServerServiceDefinition bindService(AsyncService ser new MethodHandlers< com.google.firestore.v1.RunQueryRequest, com.google.firestore.v1.RunQueryResponse>(service, METHODID_RUN_QUERY))) + .addMethod( + getExecutePipelineMethod(), + io.grpc.stub.ServerCalls.asyncServerStreamingCall( + new MethodHandlers< + com.google.firestore.v1.ExecutePipelineRequest, + com.google.firestore.v1.ExecutePipelineResponse>( + service, METHODID_EXECUTE_PIPELINE))) .addMethod( getRunAggregationQueryMethod(), io.grpc.stub.ServerCalls.asyncServerStreamingCall( @@ -2053,6 +2156,7 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() { .addMethod(getCommitMethod()) .addMethod(getRollbackMethod()) .addMethod(getRunQueryMethod()) + .addMethod(getExecutePipelineMethod()) .addMethod(getRunAggregationQueryMethod()) .addMethod(getPartitionQueryMethod()) .addMethod(getWriteMethod()) diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/Backup.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/Backup.java new file mode 100644 index 000000000..25a0b809b --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/Backup.java @@ -0,0 +1,3067 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/backup.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +/** + * + * + *
+ * A Backup of a Cloud Firestore Database.
+ *
+ * The backup contains all documents and index configurations for the given
+ * database at a specific point in time.
+ * 
+ * + * Protobuf type {@code google.firestore.admin.v1.Backup} + */ +public final class Backup extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.Backup) + BackupOrBuilder { + private static final long serialVersionUID = 0L; + // Use Backup.newBuilder() to construct. + private Backup(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private Backup() { + name_ = ""; + database_ = ""; + databaseUid_ = ""; + state_ = 0; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new Backup(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.BackupProto + .internal_static_google_firestore_admin_v1_Backup_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.BackupProto + .internal_static_google_firestore_admin_v1_Backup_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.Backup.class, + com.google.firestore.admin.v1.Backup.Builder.class); + } + + /** + * + * + *
+   * Indicate the current state of the backup.
+   * 
+ * + * Protobuf enum {@code google.firestore.admin.v1.Backup.State} + */ + public enum State implements com.google.protobuf.ProtocolMessageEnum { + /** + * + * + *
+     * The state is unspecified.
+     * 
+ * + * STATE_UNSPECIFIED = 0; + */ + STATE_UNSPECIFIED(0), + /** + * + * + *
+     * The pending backup is still being created. Operations on the
+     * backup will be rejected in this state.
+     * 
+ * + * CREATING = 1; + */ + CREATING(1), + /** + * + * + *
+     * The backup is complete and ready to use.
+     * 
+ * + * READY = 2; + */ + READY(2), + /** + * + * + *
+     * The backup is not available at this moment.
+     * 
+ * + * NOT_AVAILABLE = 3; + */ + NOT_AVAILABLE(3), + UNRECOGNIZED(-1), + ; + + /** + * + * + *
+     * The state is unspecified.
+     * 
+ * + * STATE_UNSPECIFIED = 0; + */ + public static final int STATE_UNSPECIFIED_VALUE = 0; + /** + * + * + *
+     * The pending backup is still being created. Operations on the
+     * backup will be rejected in this state.
+     * 
+ * + * CREATING = 1; + */ + public static final int CREATING_VALUE = 1; + /** + * + * + *
+     * The backup is complete and ready to use.
+     * 
+ * + * READY = 2; + */ + public static final int READY_VALUE = 2; + /** + * + * + *
+     * The backup is not available at this moment.
+     * 
+ * + * NOT_AVAILABLE = 3; + */ + public static final int NOT_AVAILABLE_VALUE = 3; + + public final int getNumber() { + if (this == UNRECOGNIZED) { + throw new java.lang.IllegalArgumentException( + "Can't get the number of an unknown enum value."); + } + return value; + } + + /** + * @param value The numeric wire value of the corresponding enum entry. + * @return The enum associated with the given numeric wire value. + * @deprecated Use {@link #forNumber(int)} instead. + */ + @java.lang.Deprecated + public static State valueOf(int value) { + return forNumber(value); + } + + /** + * @param value The numeric wire value of the corresponding enum entry. + * @return The enum associated with the given numeric wire value. + */ + public static State forNumber(int value) { + switch (value) { + case 0: + return STATE_UNSPECIFIED; + case 1: + return CREATING; + case 2: + return READY; + case 3: + return NOT_AVAILABLE; + default: + return null; + } + } + + public static com.google.protobuf.Internal.EnumLiteMap internalGetValueMap() { + return internalValueMap; + } + + private static final com.google.protobuf.Internal.EnumLiteMap internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + public State findValueByNumber(int number) { + return State.forNumber(number); + } + }; + + public final com.google.protobuf.Descriptors.EnumValueDescriptor getValueDescriptor() { + if (this == UNRECOGNIZED) { + throw new java.lang.IllegalStateException( + "Can't get the descriptor of an unrecognized enum value."); + } + return getDescriptor().getValues().get(ordinal()); + } + + public final com.google.protobuf.Descriptors.EnumDescriptor getDescriptorForType() { + return getDescriptor(); + } + + public static final com.google.protobuf.Descriptors.EnumDescriptor getDescriptor() { + return com.google.firestore.admin.v1.Backup.getDescriptor().getEnumTypes().get(0); + } + + private static final State[] VALUES = values(); + + public static State valueOf(com.google.protobuf.Descriptors.EnumValueDescriptor desc) { + if (desc.getType() != getDescriptor()) { + throw new java.lang.IllegalArgumentException("EnumValueDescriptor is not for this type."); + } + if (desc.getIndex() == -1) { + return UNRECOGNIZED; + } + return VALUES[desc.getIndex()]; + } + + private final int value; + + private State(int value) { + this.value = value; + } + + // @@protoc_insertion_point(enum_scope:google.firestore.admin.v1.Backup.State) + } + + public interface StatsOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.Backup.Stats) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+     * Output only. Summation of the size of all documents and index entries in
+     * the backup, measured in bytes.
+     * 
+ * + * int64 size_bytes = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The sizeBytes. + */ + long getSizeBytes(); + + /** + * + * + *
+     * Output only. The total number of documents contained in the backup.
+     * 
+ * + * int64 document_count = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The documentCount. + */ + long getDocumentCount(); + + /** + * + * + *
+     * Output only. The total number of index entries contained in the backup.
+     * 
+ * + * int64 index_count = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The indexCount. + */ + long getIndexCount(); + } + /** + * + * + *
+   * Backup specific statistics.
+   * 
+ * + * Protobuf type {@code google.firestore.admin.v1.Backup.Stats} + */ + public static final class Stats extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.Backup.Stats) + StatsOrBuilder { + private static final long serialVersionUID = 0L; + // Use Stats.newBuilder() to construct. + private Stats(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private Stats() {} + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new Stats(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.BackupProto + .internal_static_google_firestore_admin_v1_Backup_Stats_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.BackupProto + .internal_static_google_firestore_admin_v1_Backup_Stats_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.Backup.Stats.class, + com.google.firestore.admin.v1.Backup.Stats.Builder.class); + } + + public static final int SIZE_BYTES_FIELD_NUMBER = 1; + private long sizeBytes_ = 0L; + /** + * + * + *
+     * Output only. Summation of the size of all documents and index entries in
+     * the backup, measured in bytes.
+     * 
+ * + * int64 size_bytes = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The sizeBytes. + */ + @java.lang.Override + public long getSizeBytes() { + return sizeBytes_; + } + + public static final int DOCUMENT_COUNT_FIELD_NUMBER = 2; + private long documentCount_ = 0L; + /** + * + * + *
+     * Output only. The total number of documents contained in the backup.
+     * 
+ * + * int64 document_count = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The documentCount. + */ + @java.lang.Override + public long getDocumentCount() { + return documentCount_; + } + + public static final int INDEX_COUNT_FIELD_NUMBER = 3; + private long indexCount_ = 0L; + /** + * + * + *
+     * Output only. The total number of index entries contained in the backup.
+     * 
+ * + * int64 index_count = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The indexCount. + */ + @java.lang.Override + public long getIndexCount() { + return indexCount_; + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (sizeBytes_ != 0L) { + output.writeInt64(1, sizeBytes_); + } + if (documentCount_ != 0L) { + output.writeInt64(2, documentCount_); + } + if (indexCount_ != 0L) { + output.writeInt64(3, indexCount_); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (sizeBytes_ != 0L) { + size += com.google.protobuf.CodedOutputStream.computeInt64Size(1, sizeBytes_); + } + if (documentCount_ != 0L) { + size += com.google.protobuf.CodedOutputStream.computeInt64Size(2, documentCount_); + } + if (indexCount_ != 0L) { + size += com.google.protobuf.CodedOutputStream.computeInt64Size(3, indexCount_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.admin.v1.Backup.Stats)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.Backup.Stats other = + (com.google.firestore.admin.v1.Backup.Stats) obj; + + if (getSizeBytes() != other.getSizeBytes()) return false; + if (getDocumentCount() != other.getDocumentCount()) return false; + if (getIndexCount() != other.getIndexCount()) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + SIZE_BYTES_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong(getSizeBytes()); + hash = (37 * hash) + DOCUMENT_COUNT_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong(getDocumentCount()); + hash = (37 * hash) + INDEX_COUNT_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong(getIndexCount()); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.Backup.Stats parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.Backup.Stats parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Backup.Stats parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.Backup.Stats parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Backup.Stats parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.Backup.Stats parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Backup.Stats parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.Backup.Stats parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Backup.Stats parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.Backup.Stats parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Backup.Stats parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.Backup.Stats parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.admin.v1.Backup.Stats prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+     * Backup specific statistics.
+     * 
+ * + * Protobuf type {@code google.firestore.admin.v1.Backup.Stats} + */ + public static final class Builder + extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.Backup.Stats) + com.google.firestore.admin.v1.Backup.StatsOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.BackupProto + .internal_static_google_firestore_admin_v1_Backup_Stats_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.BackupProto + .internal_static_google_firestore_admin_v1_Backup_Stats_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.Backup.Stats.class, + com.google.firestore.admin.v1.Backup.Stats.Builder.class); + } + + // Construct using com.google.firestore.admin.v1.Backup.Stats.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + sizeBytes_ = 0L; + documentCount_ = 0L; + indexCount_ = 0L; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.BackupProto + .internal_static_google_firestore_admin_v1_Backup_Stats_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.Backup.Stats getDefaultInstanceForType() { + return com.google.firestore.admin.v1.Backup.Stats.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.Backup.Stats build() { + com.google.firestore.admin.v1.Backup.Stats result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.Backup.Stats buildPartial() { + com.google.firestore.admin.v1.Backup.Stats result = + new com.google.firestore.admin.v1.Backup.Stats(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.admin.v1.Backup.Stats result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.sizeBytes_ = sizeBytes_; + } + if (((from_bitField0_ & 0x00000002) != 0)) { + result.documentCount_ = documentCount_; + } + if (((from_bitField0_ & 0x00000004) != 0)) { + result.indexCount_ = indexCount_; + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, + java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.admin.v1.Backup.Stats) { + return mergeFrom((com.google.firestore.admin.v1.Backup.Stats) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.admin.v1.Backup.Stats other) { + if (other == com.google.firestore.admin.v1.Backup.Stats.getDefaultInstance()) return this; + if (other.getSizeBytes() != 0L) { + setSizeBytes(other.getSizeBytes()); + } + if (other.getDocumentCount() != 0L) { + setDocumentCount(other.getDocumentCount()); + } + if (other.getIndexCount() != 0L) { + setIndexCount(other.getIndexCount()); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 8: + { + sizeBytes_ = input.readInt64(); + bitField0_ |= 0x00000001; + break; + } // case 8 + case 16: + { + documentCount_ = input.readInt64(); + bitField0_ |= 0x00000002; + break; + } // case 16 + case 24: + { + indexCount_ = input.readInt64(); + bitField0_ |= 0x00000004; + break; + } // case 24 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private long sizeBytes_; + /** + * + * + *
+       * Output only. Summation of the size of all documents and index entries in
+       * the backup, measured in bytes.
+       * 
+ * + * int64 size_bytes = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The sizeBytes. + */ + @java.lang.Override + public long getSizeBytes() { + return sizeBytes_; + } + /** + * + * + *
+       * Output only. Summation of the size of all documents and index entries in
+       * the backup, measured in bytes.
+       * 
+ * + * int64 size_bytes = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @param value The sizeBytes to set. + * @return This builder for chaining. + */ + public Builder setSizeBytes(long value) { + + sizeBytes_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+       * Output only. Summation of the size of all documents and index entries in
+       * the backup, measured in bytes.
+       * 
+ * + * int64 size_bytes = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return This builder for chaining. + */ + public Builder clearSizeBytes() { + bitField0_ = (bitField0_ & ~0x00000001); + sizeBytes_ = 0L; + onChanged(); + return this; + } + + private long documentCount_; + /** + * + * + *
+       * Output only. The total number of documents contained in the backup.
+       * 
+ * + * int64 document_count = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The documentCount. + */ + @java.lang.Override + public long getDocumentCount() { + return documentCount_; + } + /** + * + * + *
+       * Output only. The total number of documents contained in the backup.
+       * 
+ * + * int64 document_count = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @param value The documentCount to set. + * @return This builder for chaining. + */ + public Builder setDocumentCount(long value) { + + documentCount_ = value; + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+       * Output only. The total number of documents contained in the backup.
+       * 
+ * + * int64 document_count = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return This builder for chaining. + */ + public Builder clearDocumentCount() { + bitField0_ = (bitField0_ & ~0x00000002); + documentCount_ = 0L; + onChanged(); + return this; + } + + private long indexCount_; + /** + * + * + *
+       * Output only. The total number of index entries contained in the backup.
+       * 
+ * + * int64 index_count = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The indexCount. + */ + @java.lang.Override + public long getIndexCount() { + return indexCount_; + } + /** + * + * + *
+       * Output only. The total number of index entries contained in the backup.
+       * 
+ * + * int64 index_count = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @param value The indexCount to set. + * @return This builder for chaining. + */ + public Builder setIndexCount(long value) { + + indexCount_ = value; + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + /** + * + * + *
+       * Output only. The total number of index entries contained in the backup.
+       * 
+ * + * int64 index_count = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return This builder for chaining. + */ + public Builder clearIndexCount() { + bitField0_ = (bitField0_ & ~0x00000004); + indexCount_ = 0L; + onChanged(); + return this; + } + + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.Backup.Stats) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.Backup.Stats) + private static final com.google.firestore.admin.v1.Backup.Stats DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.admin.v1.Backup.Stats(); + } + + public static com.google.firestore.admin.v1.Backup.Stats getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public Stats parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException() + .setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.Backup.Stats getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + } + + private int bitField0_; + public static final int NAME_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile java.lang.Object name_ = ""; + /** + * + * + *
+   * Output only. The unique resource name of the Backup.
+   *
+   * Format is `projects/{project}/locations/{location}/backups/{backup}`.
+   * 
+ * + * string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } + } + /** + * + * + *
+   * Output only. The unique resource name of the Backup.
+   *
+   * Format is `projects/{project}/locations/{location}/backups/{backup}`.
+   * 
+ * + * string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int DATABASE_FIELD_NUMBER = 2; + + @SuppressWarnings("serial") + private volatile java.lang.Object database_ = ""; + /** + * + * + *
+   * Output only. Name of the Firestore database that the backup is from.
+   *
+   * Format is `projects/{project}/databases/{database}`.
+   * 
+ * + * + * string database = 2 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { ... } + * + * + * @return The database. + */ + @java.lang.Override + public java.lang.String getDatabase() { + java.lang.Object ref = database_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + database_ = s; + return s; + } + } + /** + * + * + *
+   * Output only. Name of the Firestore database that the backup is from.
+   *
+   * Format is `projects/{project}/databases/{database}`.
+   * 
+ * + * + * string database = 2 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for database. + */ + @java.lang.Override + public com.google.protobuf.ByteString getDatabaseBytes() { + java.lang.Object ref = database_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + database_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int DATABASE_UID_FIELD_NUMBER = 7; + + @SuppressWarnings("serial") + private volatile java.lang.Object databaseUid_ = ""; + /** + * + * + *
+   * Output only. The system-generated UUID4 for the Firestore database that the
+   * backup is from.
+   * 
+ * + * string database_uid = 7 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The databaseUid. + */ + @java.lang.Override + public java.lang.String getDatabaseUid() { + java.lang.Object ref = databaseUid_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + databaseUid_ = s; + return s; + } + } + /** + * + * + *
+   * Output only. The system-generated UUID4 for the Firestore database that the
+   * backup is from.
+   * 
+ * + * string database_uid = 7 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The bytes for databaseUid. + */ + @java.lang.Override + public com.google.protobuf.ByteString getDatabaseUidBytes() { + java.lang.Object ref = databaseUid_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + databaseUid_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int SNAPSHOT_TIME_FIELD_NUMBER = 3; + private com.google.protobuf.Timestamp snapshotTime_; + /** + * + * + *
+   * Output only. The backup contains an externally consistent copy of the
+   * database at this time.
+   * 
+ * + * + * .google.protobuf.Timestamp snapshot_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return Whether the snapshotTime field is set. + */ + @java.lang.Override + public boolean hasSnapshotTime() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * + * + *
+   * Output only. The backup contains an externally consistent copy of the
+   * database at this time.
+   * 
+ * + * + * .google.protobuf.Timestamp snapshot_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The snapshotTime. + */ + @java.lang.Override + public com.google.protobuf.Timestamp getSnapshotTime() { + return snapshotTime_ == null + ? com.google.protobuf.Timestamp.getDefaultInstance() + : snapshotTime_; + } + /** + * + * + *
+   * Output only. The backup contains an externally consistent copy of the
+   * database at this time.
+   * 
+ * + * + * .google.protobuf.Timestamp snapshot_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + @java.lang.Override + public com.google.protobuf.TimestampOrBuilder getSnapshotTimeOrBuilder() { + return snapshotTime_ == null + ? com.google.protobuf.Timestamp.getDefaultInstance() + : snapshotTime_; + } + + public static final int EXPIRE_TIME_FIELD_NUMBER = 4; + private com.google.protobuf.Timestamp expireTime_; + /** + * + * + *
+   * Output only. The timestamp at which this backup expires.
+   * 
+ * + * .google.protobuf.Timestamp expire_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return Whether the expireTime field is set. + */ + @java.lang.Override + public boolean hasExpireTime() { + return ((bitField0_ & 0x00000002) != 0); + } + /** + * + * + *
+   * Output only. The timestamp at which this backup expires.
+   * 
+ * + * .google.protobuf.Timestamp expire_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The expireTime. + */ + @java.lang.Override + public com.google.protobuf.Timestamp getExpireTime() { + return expireTime_ == null ? com.google.protobuf.Timestamp.getDefaultInstance() : expireTime_; + } + /** + * + * + *
+   * Output only. The timestamp at which this backup expires.
+   * 
+ * + * .google.protobuf.Timestamp expire_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + @java.lang.Override + public com.google.protobuf.TimestampOrBuilder getExpireTimeOrBuilder() { + return expireTime_ == null ? com.google.protobuf.Timestamp.getDefaultInstance() : expireTime_; + } + + public static final int STATS_FIELD_NUMBER = 6; + private com.google.firestore.admin.v1.Backup.Stats stats_; + /** + * + * + *
+   * Output only. Statistics about the backup.
+   *
+   * This data only becomes available after the backup is fully materialized to
+   * secondary storage. This field will be empty till then.
+   * 
+ * + * + * .google.firestore.admin.v1.Backup.Stats stats = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return Whether the stats field is set. + */ + @java.lang.Override + public boolean hasStats() { + return ((bitField0_ & 0x00000004) != 0); + } + /** + * + * + *
+   * Output only. Statistics about the backup.
+   *
+   * This data only becomes available after the backup is fully materialized to
+   * secondary storage. This field will be empty till then.
+   * 
+ * + * + * .google.firestore.admin.v1.Backup.Stats stats = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The stats. + */ + @java.lang.Override + public com.google.firestore.admin.v1.Backup.Stats getStats() { + return stats_ == null + ? com.google.firestore.admin.v1.Backup.Stats.getDefaultInstance() + : stats_; + } + /** + * + * + *
+   * Output only. Statistics about the backup.
+   *
+   * This data only becomes available after the backup is fully materialized to
+   * secondary storage. This field will be empty till then.
+   * 
+ * + * + * .google.firestore.admin.v1.Backup.Stats stats = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + @java.lang.Override + public com.google.firestore.admin.v1.Backup.StatsOrBuilder getStatsOrBuilder() { + return stats_ == null + ? com.google.firestore.admin.v1.Backup.Stats.getDefaultInstance() + : stats_; + } + + public static final int STATE_FIELD_NUMBER = 8; + private int state_ = 0; + /** + * + * + *
+   * Output only. The current state of the backup.
+   * 
+ * + * + * .google.firestore.admin.v1.Backup.State state = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The enum numeric value on the wire for state. + */ + @java.lang.Override + public int getStateValue() { + return state_; + } + /** + * + * + *
+   * Output only. The current state of the backup.
+   * 
+ * + * + * .google.firestore.admin.v1.Backup.State state = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The state. + */ + @java.lang.Override + public com.google.firestore.admin.v1.Backup.State getState() { + com.google.firestore.admin.v1.Backup.State result = + com.google.firestore.admin.v1.Backup.State.forNumber(state_); + return result == null ? com.google.firestore.admin.v1.Backup.State.UNRECOGNIZED : result; + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(database_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 2, database_); + } + if (((bitField0_ & 0x00000001) != 0)) { + output.writeMessage(3, getSnapshotTime()); + } + if (((bitField0_ & 0x00000002) != 0)) { + output.writeMessage(4, getExpireTime()); + } + if (((bitField0_ & 0x00000004) != 0)) { + output.writeMessage(6, getStats()); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(databaseUid_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 7, databaseUid_); + } + if (state_ != com.google.firestore.admin.v1.Backup.State.STATE_UNSPECIFIED.getNumber()) { + output.writeEnum(8, state_); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(database_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, database_); + } + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(3, getSnapshotTime()); + } + if (((bitField0_ & 0x00000002) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(4, getExpireTime()); + } + if (((bitField0_ & 0x00000004) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(6, getStats()); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(databaseUid_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(7, databaseUid_); + } + if (state_ != com.google.firestore.admin.v1.Backup.State.STATE_UNSPECIFIED.getNumber()) { + size += com.google.protobuf.CodedOutputStream.computeEnumSize(8, state_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.admin.v1.Backup)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.Backup other = (com.google.firestore.admin.v1.Backup) obj; + + if (!getName().equals(other.getName())) return false; + if (!getDatabase().equals(other.getDatabase())) return false; + if (!getDatabaseUid().equals(other.getDatabaseUid())) return false; + if (hasSnapshotTime() != other.hasSnapshotTime()) return false; + if (hasSnapshotTime()) { + if (!getSnapshotTime().equals(other.getSnapshotTime())) return false; + } + if (hasExpireTime() != other.hasExpireTime()) return false; + if (hasExpireTime()) { + if (!getExpireTime().equals(other.getExpireTime())) return false; + } + if (hasStats() != other.hasStats()) return false; + if (hasStats()) { + if (!getStats().equals(other.getStats())) return false; + } + if (state_ != other.state_) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + NAME_FIELD_NUMBER; + hash = (53 * hash) + getName().hashCode(); + hash = (37 * hash) + DATABASE_FIELD_NUMBER; + hash = (53 * hash) + getDatabase().hashCode(); + hash = (37 * hash) + DATABASE_UID_FIELD_NUMBER; + hash = (53 * hash) + getDatabaseUid().hashCode(); + if (hasSnapshotTime()) { + hash = (37 * hash) + SNAPSHOT_TIME_FIELD_NUMBER; + hash = (53 * hash) + getSnapshotTime().hashCode(); + } + if (hasExpireTime()) { + hash = (37 * hash) + EXPIRE_TIME_FIELD_NUMBER; + hash = (53 * hash) + getExpireTime().hashCode(); + } + if (hasStats()) { + hash = (37 * hash) + STATS_FIELD_NUMBER; + hash = (53 * hash) + getStats().hashCode(); + } + hash = (37 * hash) + STATE_FIELD_NUMBER; + hash = (53 * hash) + state_; + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.Backup parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.Backup parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Backup parseFrom(com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.Backup parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Backup parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.Backup parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Backup parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.Backup parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Backup parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.Backup parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Backup parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.Backup parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.admin.v1.Backup prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * A Backup of a Cloud Firestore Database.
+   *
+   * The backup contains all documents and index configurations for the given
+   * database at a specific point in time.
+   * 
+ * + * Protobuf type {@code google.firestore.admin.v1.Backup} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.Backup) + com.google.firestore.admin.v1.BackupOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.BackupProto + .internal_static_google_firestore_admin_v1_Backup_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.BackupProto + .internal_static_google_firestore_admin_v1_Backup_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.Backup.class, + com.google.firestore.admin.v1.Backup.Builder.class); + } + + // Construct using com.google.firestore.admin.v1.Backup.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) { + getSnapshotTimeFieldBuilder(); + getExpireTimeFieldBuilder(); + getStatsFieldBuilder(); + } + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + name_ = ""; + database_ = ""; + databaseUid_ = ""; + snapshotTime_ = null; + if (snapshotTimeBuilder_ != null) { + snapshotTimeBuilder_.dispose(); + snapshotTimeBuilder_ = null; + } + expireTime_ = null; + if (expireTimeBuilder_ != null) { + expireTimeBuilder_.dispose(); + expireTimeBuilder_ = null; + } + stats_ = null; + if (statsBuilder_ != null) { + statsBuilder_.dispose(); + statsBuilder_ = null; + } + state_ = 0; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.BackupProto + .internal_static_google_firestore_admin_v1_Backup_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.Backup getDefaultInstanceForType() { + return com.google.firestore.admin.v1.Backup.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.Backup build() { + com.google.firestore.admin.v1.Backup result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.Backup buildPartial() { + com.google.firestore.admin.v1.Backup result = new com.google.firestore.admin.v1.Backup(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.admin.v1.Backup result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.name_ = name_; + } + if (((from_bitField0_ & 0x00000002) != 0)) { + result.database_ = database_; + } + if (((from_bitField0_ & 0x00000004) != 0)) { + result.databaseUid_ = databaseUid_; + } + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000008) != 0)) { + result.snapshotTime_ = + snapshotTimeBuilder_ == null ? snapshotTime_ : snapshotTimeBuilder_.build(); + to_bitField0_ |= 0x00000001; + } + if (((from_bitField0_ & 0x00000010) != 0)) { + result.expireTime_ = expireTimeBuilder_ == null ? expireTime_ : expireTimeBuilder_.build(); + to_bitField0_ |= 0x00000002; + } + if (((from_bitField0_ & 0x00000020) != 0)) { + result.stats_ = statsBuilder_ == null ? stats_ : statsBuilder_.build(); + to_bitField0_ |= 0x00000004; + } + if (((from_bitField0_ & 0x00000040) != 0)) { + result.state_ = state_; + } + result.bitField0_ |= to_bitField0_; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.admin.v1.Backup) { + return mergeFrom((com.google.firestore.admin.v1.Backup) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.admin.v1.Backup other) { + if (other == com.google.firestore.admin.v1.Backup.getDefaultInstance()) return this; + if (!other.getName().isEmpty()) { + name_ = other.name_; + bitField0_ |= 0x00000001; + onChanged(); + } + if (!other.getDatabase().isEmpty()) { + database_ = other.database_; + bitField0_ |= 0x00000002; + onChanged(); + } + if (!other.getDatabaseUid().isEmpty()) { + databaseUid_ = other.databaseUid_; + bitField0_ |= 0x00000004; + onChanged(); + } + if (other.hasSnapshotTime()) { + mergeSnapshotTime(other.getSnapshotTime()); + } + if (other.hasExpireTime()) { + mergeExpireTime(other.getExpireTime()); + } + if (other.hasStats()) { + mergeStats(other.getStats()); + } + if (other.state_ != 0) { + setStateValue(other.getStateValue()); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + name_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: + { + database_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000002; + break; + } // case 18 + case 26: + { + input.readMessage(getSnapshotTimeFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000008; + break; + } // case 26 + case 34: + { + input.readMessage(getExpireTimeFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000010; + break; + } // case 34 + case 50: + { + input.readMessage(getStatsFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000020; + break; + } // case 50 + case 58: + { + databaseUid_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000004; + break; + } // case 58 + case 64: + { + state_ = input.readEnum(); + bitField0_ |= 0x00000040; + break; + } // case 64 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private java.lang.Object name_ = ""; + /** + * + * + *
+     * Output only. The unique resource name of the Backup.
+     *
+     * Format is `projects/{project}/locations/{location}/backups/{backup}`.
+     * 
+ * + * string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The name. + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * Output only. The unique resource name of the Backup.
+     *
+     * Format is `projects/{project}/locations/{location}/backups/{backup}`.
+     * 
+ * + * string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The bytes for name. + */ + public com.google.protobuf.ByteString getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * Output only. The unique resource name of the Backup.
+     *
+     * Format is `projects/{project}/locations/{location}/backups/{backup}`.
+     * 
+ * + * string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The unique resource name of the Backup.
+     *
+     * Format is `projects/{project}/locations/{location}/backups/{backup}`.
+     * 
+ * + * string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return This builder for chaining. + */ + public Builder clearName() { + name_ = getDefaultInstance().getName(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The unique resource name of the Backup.
+     *
+     * Format is `projects/{project}/locations/{location}/backups/{backup}`.
+     * 
+ * + * string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + private java.lang.Object database_ = ""; + /** + * + * + *
+     * Output only. Name of the Firestore database that the backup is from.
+     *
+     * Format is `projects/{project}/databases/{database}`.
+     * 
+ * + * + * string database = 2 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { ... } + * + * + * @return The database. + */ + public java.lang.String getDatabase() { + java.lang.Object ref = database_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + database_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * Output only. Name of the Firestore database that the backup is from.
+     *
+     * Format is `projects/{project}/databases/{database}`.
+     * 
+ * + * + * string database = 2 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for database. + */ + public com.google.protobuf.ByteString getDatabaseBytes() { + java.lang.Object ref = database_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + database_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * Output only. Name of the Firestore database that the backup is from.
+     *
+     * Format is `projects/{project}/databases/{database}`.
+     * 
+ * + * + * string database = 2 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { ... } + * + * + * @param value The database to set. + * @return This builder for chaining. + */ + public Builder setDatabase(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + database_ = value; + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. Name of the Firestore database that the backup is from.
+     *
+     * Format is `projects/{project}/databases/{database}`.
+     * 
+ * + * + * string database = 2 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { ... } + * + * + * @return This builder for chaining. + */ + public Builder clearDatabase() { + database_ = getDefaultInstance().getDatabase(); + bitField0_ = (bitField0_ & ~0x00000002); + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. Name of the Firestore database that the backup is from.
+     *
+     * Format is `projects/{project}/databases/{database}`.
+     * 
+ * + * + * string database = 2 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { ... } + * + * + * @param value The bytes for database to set. + * @return This builder for chaining. + */ + public Builder setDatabaseBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + database_ = value; + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + + private java.lang.Object databaseUid_ = ""; + /** + * + * + *
+     * Output only. The system-generated UUID4 for the Firestore database that the
+     * backup is from.
+     * 
+ * + * string database_uid = 7 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The databaseUid. + */ + public java.lang.String getDatabaseUid() { + java.lang.Object ref = databaseUid_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + databaseUid_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * Output only. The system-generated UUID4 for the Firestore database that the
+     * backup is from.
+     * 
+ * + * string database_uid = 7 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The bytes for databaseUid. + */ + public com.google.protobuf.ByteString getDatabaseUidBytes() { + java.lang.Object ref = databaseUid_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + databaseUid_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * Output only. The system-generated UUID4 for the Firestore database that the
+     * backup is from.
+     * 
+ * + * string database_uid = 7 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @param value The databaseUid to set. + * @return This builder for chaining. + */ + public Builder setDatabaseUid(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + databaseUid_ = value; + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The system-generated UUID4 for the Firestore database that the
+     * backup is from.
+     * 
+ * + * string database_uid = 7 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return This builder for chaining. + */ + public Builder clearDatabaseUid() { + databaseUid_ = getDefaultInstance().getDatabaseUid(); + bitField0_ = (bitField0_ & ~0x00000004); + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The system-generated UUID4 for the Firestore database that the
+     * backup is from.
+     * 
+ * + * string database_uid = 7 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @param value The bytes for databaseUid to set. + * @return This builder for chaining. + */ + public Builder setDatabaseUidBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + databaseUid_ = value; + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + + private com.google.protobuf.Timestamp snapshotTime_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder> + snapshotTimeBuilder_; + /** + * + * + *
+     * Output only. The backup contains an externally consistent copy of the
+     * database at this time.
+     * 
+ * + * + * .google.protobuf.Timestamp snapshot_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return Whether the snapshotTime field is set. + */ + public boolean hasSnapshotTime() { + return ((bitField0_ & 0x00000008) != 0); + } + /** + * + * + *
+     * Output only. The backup contains an externally consistent copy of the
+     * database at this time.
+     * 
+ * + * + * .google.protobuf.Timestamp snapshot_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The snapshotTime. + */ + public com.google.protobuf.Timestamp getSnapshotTime() { + if (snapshotTimeBuilder_ == null) { + return snapshotTime_ == null + ? com.google.protobuf.Timestamp.getDefaultInstance() + : snapshotTime_; + } else { + return snapshotTimeBuilder_.getMessage(); + } + } + /** + * + * + *
+     * Output only. The backup contains an externally consistent copy of the
+     * database at this time.
+     * 
+ * + * + * .google.protobuf.Timestamp snapshot_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder setSnapshotTime(com.google.protobuf.Timestamp value) { + if (snapshotTimeBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + snapshotTime_ = value; + } else { + snapshotTimeBuilder_.setMessage(value); + } + bitField0_ |= 0x00000008; + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The backup contains an externally consistent copy of the
+     * database at this time.
+     * 
+ * + * + * .google.protobuf.Timestamp snapshot_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder setSnapshotTime(com.google.protobuf.Timestamp.Builder builderForValue) { + if (snapshotTimeBuilder_ == null) { + snapshotTime_ = builderForValue.build(); + } else { + snapshotTimeBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000008; + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The backup contains an externally consistent copy of the
+     * database at this time.
+     * 
+ * + * + * .google.protobuf.Timestamp snapshot_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder mergeSnapshotTime(com.google.protobuf.Timestamp value) { + if (snapshotTimeBuilder_ == null) { + if (((bitField0_ & 0x00000008) != 0) + && snapshotTime_ != null + && snapshotTime_ != com.google.protobuf.Timestamp.getDefaultInstance()) { + getSnapshotTimeBuilder().mergeFrom(value); + } else { + snapshotTime_ = value; + } + } else { + snapshotTimeBuilder_.mergeFrom(value); + } + if (snapshotTime_ != null) { + bitField0_ |= 0x00000008; + onChanged(); + } + return this; + } + /** + * + * + *
+     * Output only. The backup contains an externally consistent copy of the
+     * database at this time.
+     * 
+ * + * + * .google.protobuf.Timestamp snapshot_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder clearSnapshotTime() { + bitField0_ = (bitField0_ & ~0x00000008); + snapshotTime_ = null; + if (snapshotTimeBuilder_ != null) { + snapshotTimeBuilder_.dispose(); + snapshotTimeBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The backup contains an externally consistent copy of the
+     * database at this time.
+     * 
+ * + * + * .google.protobuf.Timestamp snapshot_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public com.google.protobuf.Timestamp.Builder getSnapshotTimeBuilder() { + bitField0_ |= 0x00000008; + onChanged(); + return getSnapshotTimeFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * Output only. The backup contains an externally consistent copy of the
+     * database at this time.
+     * 
+ * + * + * .google.protobuf.Timestamp snapshot_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public com.google.protobuf.TimestampOrBuilder getSnapshotTimeOrBuilder() { + if (snapshotTimeBuilder_ != null) { + return snapshotTimeBuilder_.getMessageOrBuilder(); + } else { + return snapshotTime_ == null + ? com.google.protobuf.Timestamp.getDefaultInstance() + : snapshotTime_; + } + } + /** + * + * + *
+     * Output only. The backup contains an externally consistent copy of the
+     * database at this time.
+     * 
+ * + * + * .google.protobuf.Timestamp snapshot_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder> + getSnapshotTimeFieldBuilder() { + if (snapshotTimeBuilder_ == null) { + snapshotTimeBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder>( + getSnapshotTime(), getParentForChildren(), isClean()); + snapshotTime_ = null; + } + return snapshotTimeBuilder_; + } + + private com.google.protobuf.Timestamp expireTime_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder> + expireTimeBuilder_; + /** + * + * + *
+     * Output only. The timestamp at which this backup expires.
+     * 
+ * + * + * .google.protobuf.Timestamp expire_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return Whether the expireTime field is set. + */ + public boolean hasExpireTime() { + return ((bitField0_ & 0x00000010) != 0); + } + /** + * + * + *
+     * Output only. The timestamp at which this backup expires.
+     * 
+ * + * + * .google.protobuf.Timestamp expire_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The expireTime. + */ + public com.google.protobuf.Timestamp getExpireTime() { + if (expireTimeBuilder_ == null) { + return expireTime_ == null + ? com.google.protobuf.Timestamp.getDefaultInstance() + : expireTime_; + } else { + return expireTimeBuilder_.getMessage(); + } + } + /** + * + * + *
+     * Output only. The timestamp at which this backup expires.
+     * 
+ * + * + * .google.protobuf.Timestamp expire_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder setExpireTime(com.google.protobuf.Timestamp value) { + if (expireTimeBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + expireTime_ = value; + } else { + expireTimeBuilder_.setMessage(value); + } + bitField0_ |= 0x00000010; + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The timestamp at which this backup expires.
+     * 
+ * + * + * .google.protobuf.Timestamp expire_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder setExpireTime(com.google.protobuf.Timestamp.Builder builderForValue) { + if (expireTimeBuilder_ == null) { + expireTime_ = builderForValue.build(); + } else { + expireTimeBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000010; + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The timestamp at which this backup expires.
+     * 
+ * + * + * .google.protobuf.Timestamp expire_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder mergeExpireTime(com.google.protobuf.Timestamp value) { + if (expireTimeBuilder_ == null) { + if (((bitField0_ & 0x00000010) != 0) + && expireTime_ != null + && expireTime_ != com.google.protobuf.Timestamp.getDefaultInstance()) { + getExpireTimeBuilder().mergeFrom(value); + } else { + expireTime_ = value; + } + } else { + expireTimeBuilder_.mergeFrom(value); + } + if (expireTime_ != null) { + bitField0_ |= 0x00000010; + onChanged(); + } + return this; + } + /** + * + * + *
+     * Output only. The timestamp at which this backup expires.
+     * 
+ * + * + * .google.protobuf.Timestamp expire_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder clearExpireTime() { + bitField0_ = (bitField0_ & ~0x00000010); + expireTime_ = null; + if (expireTimeBuilder_ != null) { + expireTimeBuilder_.dispose(); + expireTimeBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The timestamp at which this backup expires.
+     * 
+ * + * + * .google.protobuf.Timestamp expire_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public com.google.protobuf.Timestamp.Builder getExpireTimeBuilder() { + bitField0_ |= 0x00000010; + onChanged(); + return getExpireTimeFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * Output only. The timestamp at which this backup expires.
+     * 
+ * + * + * .google.protobuf.Timestamp expire_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public com.google.protobuf.TimestampOrBuilder getExpireTimeOrBuilder() { + if (expireTimeBuilder_ != null) { + return expireTimeBuilder_.getMessageOrBuilder(); + } else { + return expireTime_ == null + ? com.google.protobuf.Timestamp.getDefaultInstance() + : expireTime_; + } + } + /** + * + * + *
+     * Output only. The timestamp at which this backup expires.
+     * 
+ * + * + * .google.protobuf.Timestamp expire_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder> + getExpireTimeFieldBuilder() { + if (expireTimeBuilder_ == null) { + expireTimeBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder>( + getExpireTime(), getParentForChildren(), isClean()); + expireTime_ = null; + } + return expireTimeBuilder_; + } + + private com.google.firestore.admin.v1.Backup.Stats stats_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.Backup.Stats, + com.google.firestore.admin.v1.Backup.Stats.Builder, + com.google.firestore.admin.v1.Backup.StatsOrBuilder> + statsBuilder_; + /** + * + * + *
+     * Output only. Statistics about the backup.
+     *
+     * This data only becomes available after the backup is fully materialized to
+     * secondary storage. This field will be empty till then.
+     * 
+ * + * + * .google.firestore.admin.v1.Backup.Stats stats = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return Whether the stats field is set. + */ + public boolean hasStats() { + return ((bitField0_ & 0x00000020) != 0); + } + /** + * + * + *
+     * Output only. Statistics about the backup.
+     *
+     * This data only becomes available after the backup is fully materialized to
+     * secondary storage. This field will be empty till then.
+     * 
+ * + * + * .google.firestore.admin.v1.Backup.Stats stats = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The stats. + */ + public com.google.firestore.admin.v1.Backup.Stats getStats() { + if (statsBuilder_ == null) { + return stats_ == null + ? com.google.firestore.admin.v1.Backup.Stats.getDefaultInstance() + : stats_; + } else { + return statsBuilder_.getMessage(); + } + } + /** + * + * + *
+     * Output only. Statistics about the backup.
+     *
+     * This data only becomes available after the backup is fully materialized to
+     * secondary storage. This field will be empty till then.
+     * 
+ * + * + * .google.firestore.admin.v1.Backup.Stats stats = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder setStats(com.google.firestore.admin.v1.Backup.Stats value) { + if (statsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + stats_ = value; + } else { + statsBuilder_.setMessage(value); + } + bitField0_ |= 0x00000020; + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. Statistics about the backup.
+     *
+     * This data only becomes available after the backup is fully materialized to
+     * secondary storage. This field will be empty till then.
+     * 
+ * + * + * .google.firestore.admin.v1.Backup.Stats stats = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder setStats(com.google.firestore.admin.v1.Backup.Stats.Builder builderForValue) { + if (statsBuilder_ == null) { + stats_ = builderForValue.build(); + } else { + statsBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000020; + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. Statistics about the backup.
+     *
+     * This data only becomes available after the backup is fully materialized to
+     * secondary storage. This field will be empty till then.
+     * 
+ * + * + * .google.firestore.admin.v1.Backup.Stats stats = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder mergeStats(com.google.firestore.admin.v1.Backup.Stats value) { + if (statsBuilder_ == null) { + if (((bitField0_ & 0x00000020) != 0) + && stats_ != null + && stats_ != com.google.firestore.admin.v1.Backup.Stats.getDefaultInstance()) { + getStatsBuilder().mergeFrom(value); + } else { + stats_ = value; + } + } else { + statsBuilder_.mergeFrom(value); + } + if (stats_ != null) { + bitField0_ |= 0x00000020; + onChanged(); + } + return this; + } + /** + * + * + *
+     * Output only. Statistics about the backup.
+     *
+     * This data only becomes available after the backup is fully materialized to
+     * secondary storage. This field will be empty till then.
+     * 
+ * + * + * .google.firestore.admin.v1.Backup.Stats stats = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder clearStats() { + bitField0_ = (bitField0_ & ~0x00000020); + stats_ = null; + if (statsBuilder_ != null) { + statsBuilder_.dispose(); + statsBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. Statistics about the backup.
+     *
+     * This data only becomes available after the backup is fully materialized to
+     * secondary storage. This field will be empty till then.
+     * 
+ * + * + * .google.firestore.admin.v1.Backup.Stats stats = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public com.google.firestore.admin.v1.Backup.Stats.Builder getStatsBuilder() { + bitField0_ |= 0x00000020; + onChanged(); + return getStatsFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * Output only. Statistics about the backup.
+     *
+     * This data only becomes available after the backup is fully materialized to
+     * secondary storage. This field will be empty till then.
+     * 
+ * + * + * .google.firestore.admin.v1.Backup.Stats stats = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public com.google.firestore.admin.v1.Backup.StatsOrBuilder getStatsOrBuilder() { + if (statsBuilder_ != null) { + return statsBuilder_.getMessageOrBuilder(); + } else { + return stats_ == null + ? com.google.firestore.admin.v1.Backup.Stats.getDefaultInstance() + : stats_; + } + } + /** + * + * + *
+     * Output only. Statistics about the backup.
+     *
+     * This data only becomes available after the backup is fully materialized to
+     * secondary storage. This field will be empty till then.
+     * 
+ * + * + * .google.firestore.admin.v1.Backup.Stats stats = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.Backup.Stats, + com.google.firestore.admin.v1.Backup.Stats.Builder, + com.google.firestore.admin.v1.Backup.StatsOrBuilder> + getStatsFieldBuilder() { + if (statsBuilder_ == null) { + statsBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.Backup.Stats, + com.google.firestore.admin.v1.Backup.Stats.Builder, + com.google.firestore.admin.v1.Backup.StatsOrBuilder>( + getStats(), getParentForChildren(), isClean()); + stats_ = null; + } + return statsBuilder_; + } + + private int state_ = 0; + /** + * + * + *
+     * Output only. The current state of the backup.
+     * 
+ * + * + * .google.firestore.admin.v1.Backup.State state = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The enum numeric value on the wire for state. + */ + @java.lang.Override + public int getStateValue() { + return state_; + } + /** + * + * + *
+     * Output only. The current state of the backup.
+     * 
+ * + * + * .google.firestore.admin.v1.Backup.State state = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @param value The enum numeric value on the wire for state to set. + * @return This builder for chaining. + */ + public Builder setStateValue(int value) { + state_ = value; + bitField0_ |= 0x00000040; + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The current state of the backup.
+     * 
+ * + * + * .google.firestore.admin.v1.Backup.State state = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The state. + */ + @java.lang.Override + public com.google.firestore.admin.v1.Backup.State getState() { + com.google.firestore.admin.v1.Backup.State result = + com.google.firestore.admin.v1.Backup.State.forNumber(state_); + return result == null ? com.google.firestore.admin.v1.Backup.State.UNRECOGNIZED : result; + } + /** + * + * + *
+     * Output only. The current state of the backup.
+     * 
+ * + * + * .google.firestore.admin.v1.Backup.State state = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @param value The state to set. + * @return This builder for chaining. + */ + public Builder setState(com.google.firestore.admin.v1.Backup.State value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000040; + state_ = value.getNumber(); + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The current state of the backup.
+     * 
+ * + * + * .google.firestore.admin.v1.Backup.State state = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return This builder for chaining. + */ + public Builder clearState() { + bitField0_ = (bitField0_ & ~0x00000040); + state_ = 0; + onChanged(); + return this; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.Backup) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.Backup) + private static final com.google.firestore.admin.v1.Backup DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.admin.v1.Backup(); + } + + public static com.google.firestore.admin.v1.Backup getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public Backup parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.Backup getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupName.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupName.java new file mode 100644 index 000000000..76cdb3473 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupName.java @@ -0,0 +1,223 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.firestore.admin.v1; + +import com.google.api.pathtemplate.PathTemplate; +import com.google.api.resourcenames.ResourceName; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +@Generated("by gapic-generator-java") +public class BackupName implements ResourceName { + private static final PathTemplate PROJECT_LOCATION_BACKUP = + PathTemplate.createWithoutUrlEncoding( + "projects/{project}/locations/{location}/backups/{backup}"); + private volatile Map fieldValuesMap; + private final String project; + private final String location; + private final String backup; + + @Deprecated + protected BackupName() { + project = null; + location = null; + backup = null; + } + + private BackupName(Builder builder) { + project = Preconditions.checkNotNull(builder.getProject()); + location = Preconditions.checkNotNull(builder.getLocation()); + backup = Preconditions.checkNotNull(builder.getBackup()); + } + + public String getProject() { + return project; + } + + public String getLocation() { + return location; + } + + public String getBackup() { + return backup; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + public static BackupName of(String project, String location, String backup) { + return newBuilder().setProject(project).setLocation(location).setBackup(backup).build(); + } + + public static String format(String project, String location, String backup) { + return newBuilder() + .setProject(project) + .setLocation(location) + .setBackup(backup) + .build() + .toString(); + } + + public static BackupName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + Map matchMap = + PROJECT_LOCATION_BACKUP.validatedMatch( + formattedString, "BackupName.parse: formattedString not in valid format"); + return of(matchMap.get("project"), matchMap.get("location"), matchMap.get("backup")); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList<>(values.size()); + for (BackupName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return PROJECT_LOCATION_BACKUP.matches(formattedString); + } + + @Override + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + if (project != null) { + fieldMapBuilder.put("project", project); + } + if (location != null) { + fieldMapBuilder.put("location", location); + } + if (backup != null) { + fieldMapBuilder.put("backup", backup); + } + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return PROJECT_LOCATION_BACKUP.instantiate( + "project", project, "location", location, "backup", backup); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o != null && getClass() == o.getClass()) { + BackupName that = ((BackupName) o); + return Objects.equals(this.project, that.project) + && Objects.equals(this.location, that.location) + && Objects.equals(this.backup, that.backup); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= Objects.hashCode(project); + h *= 1000003; + h ^= Objects.hashCode(location); + h *= 1000003; + h ^= Objects.hashCode(backup); + return h; + } + + /** Builder for projects/{project}/locations/{location}/backups/{backup}. */ + public static class Builder { + private String project; + private String location; + private String backup; + + protected Builder() {} + + public String getProject() { + return project; + } + + public String getLocation() { + return location; + } + + public String getBackup() { + return backup; + } + + public Builder setProject(String project) { + this.project = project; + return this; + } + + public Builder setLocation(String location) { + this.location = location; + return this; + } + + public Builder setBackup(String backup) { + this.backup = backup; + return this; + } + + private Builder(BackupName backupName) { + this.project = backupName.project; + this.location = backupName.location; + this.backup = backupName.backup; + } + + public BackupName build() { + return new BackupName(this); + } + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupOrBuilder.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupOrBuilder.java new file mode 100644 index 000000000..8da642d41 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupOrBuilder.java @@ -0,0 +1,276 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/backup.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +public interface BackupOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.Backup) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * Output only. The unique resource name of the Backup.
+   *
+   * Format is `projects/{project}/locations/{location}/backups/{backup}`.
+   * 
+ * + * string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The name. + */ + java.lang.String getName(); + /** + * + * + *
+   * Output only. The unique resource name of the Backup.
+   *
+   * Format is `projects/{project}/locations/{location}/backups/{backup}`.
+   * 
+ * + * string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The bytes for name. + */ + com.google.protobuf.ByteString getNameBytes(); + + /** + * + * + *
+   * Output only. Name of the Firestore database that the backup is from.
+   *
+   * Format is `projects/{project}/databases/{database}`.
+   * 
+ * + * + * string database = 2 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { ... } + * + * + * @return The database. + */ + java.lang.String getDatabase(); + /** + * + * + *
+   * Output only. Name of the Firestore database that the backup is from.
+   *
+   * Format is `projects/{project}/databases/{database}`.
+   * 
+ * + * + * string database = 2 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for database. + */ + com.google.protobuf.ByteString getDatabaseBytes(); + + /** + * + * + *
+   * Output only. The system-generated UUID4 for the Firestore database that the
+   * backup is from.
+   * 
+ * + * string database_uid = 7 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The databaseUid. + */ + java.lang.String getDatabaseUid(); + /** + * + * + *
+   * Output only. The system-generated UUID4 for the Firestore database that the
+   * backup is from.
+   * 
+ * + * string database_uid = 7 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The bytes for databaseUid. + */ + com.google.protobuf.ByteString getDatabaseUidBytes(); + + /** + * + * + *
+   * Output only. The backup contains an externally consistent copy of the
+   * database at this time.
+   * 
+ * + * + * .google.protobuf.Timestamp snapshot_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return Whether the snapshotTime field is set. + */ + boolean hasSnapshotTime(); + /** + * + * + *
+   * Output only. The backup contains an externally consistent copy of the
+   * database at this time.
+   * 
+ * + * + * .google.protobuf.Timestamp snapshot_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The snapshotTime. + */ + com.google.protobuf.Timestamp getSnapshotTime(); + /** + * + * + *
+   * Output only. The backup contains an externally consistent copy of the
+   * database at this time.
+   * 
+ * + * + * .google.protobuf.Timestamp snapshot_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + com.google.protobuf.TimestampOrBuilder getSnapshotTimeOrBuilder(); + + /** + * + * + *
+   * Output only. The timestamp at which this backup expires.
+   * 
+ * + * .google.protobuf.Timestamp expire_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return Whether the expireTime field is set. + */ + boolean hasExpireTime(); + /** + * + * + *
+   * Output only. The timestamp at which this backup expires.
+   * 
+ * + * .google.protobuf.Timestamp expire_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The expireTime. + */ + com.google.protobuf.Timestamp getExpireTime(); + /** + * + * + *
+   * Output only. The timestamp at which this backup expires.
+   * 
+ * + * .google.protobuf.Timestamp expire_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + com.google.protobuf.TimestampOrBuilder getExpireTimeOrBuilder(); + + /** + * + * + *
+   * Output only. Statistics about the backup.
+   *
+   * This data only becomes available after the backup is fully materialized to
+   * secondary storage. This field will be empty till then.
+   * 
+ * + * + * .google.firestore.admin.v1.Backup.Stats stats = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return Whether the stats field is set. + */ + boolean hasStats(); + /** + * + * + *
+   * Output only. Statistics about the backup.
+   *
+   * This data only becomes available after the backup is fully materialized to
+   * secondary storage. This field will be empty till then.
+   * 
+ * + * + * .google.firestore.admin.v1.Backup.Stats stats = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The stats. + */ + com.google.firestore.admin.v1.Backup.Stats getStats(); + /** + * + * + *
+   * Output only. Statistics about the backup.
+   *
+   * This data only becomes available after the backup is fully materialized to
+   * secondary storage. This field will be empty till then.
+   * 
+ * + * + * .google.firestore.admin.v1.Backup.Stats stats = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + com.google.firestore.admin.v1.Backup.StatsOrBuilder getStatsOrBuilder(); + + /** + * + * + *
+   * Output only. The current state of the backup.
+   * 
+ * + * + * .google.firestore.admin.v1.Backup.State state = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The enum numeric value on the wire for state. + */ + int getStateValue(); + /** + * + * + *
+   * Output only. The current state of the backup.
+   * 
+ * + * + * .google.firestore.admin.v1.Backup.State state = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The state. + */ + com.google.firestore.admin.v1.Backup.State getState(); +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupProto.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupProto.java new file mode 100644 index 000000000..deab8154c --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupProto.java @@ -0,0 +1,111 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/backup.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +public final class BackupProto { + private BackupProto() {} + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistryLite registry) {} + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions((com.google.protobuf.ExtensionRegistryLite) registry); + } + + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_Backup_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_Backup_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_Backup_Stats_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_Backup_Stats_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + return descriptor; + } + + private static com.google.protobuf.Descriptors.FileDescriptor descriptor; + + static { + java.lang.String[] descriptorData = { + "\n&google/firestore/admin/v1/backup.proto" + + "\022\031google.firestore.admin.v1\032\037google/api/" + + "field_behavior.proto\032\031google/api/resourc" + + "e.proto\032\037google/protobuf/timestamp.proto" + + "\"\340\004\n\006Backup\022\021\n\004name\030\001 \001(\tB\003\340A\003\022;\n\010databa" + + "se\030\002 \001(\tB)\340A\003\372A#\n!firestore.googleapis.c" + + "om/Database\022\031\n\014database_uid\030\007 \001(\tB\003\340A\003\0226" + + "\n\rsnapshot_time\030\003 \001(\0132\032.google.protobuf." + + "TimestampB\003\340A\003\0224\n\013expire_time\030\004 \001(\0132\032.go" + + "ogle.protobuf.TimestampB\003\340A\003\022;\n\005stats\030\006 " + + "\001(\0132\'.google.firestore.admin.v1.Backup.S" + + "tatsB\003\340A\003\022;\n\005state\030\010 \001(\0162\'.google.firest" + + "ore.admin.v1.Backup.StateB\003\340A\003\032W\n\005Stats\022" + + "\027\n\nsize_bytes\030\001 \001(\003B\003\340A\003\022\033\n\016document_cou" + + "nt\030\002 \001(\003B\003\340A\003\022\030\n\013index_count\030\003 \001(\003B\003\340A\003\"" + + "J\n\005State\022\025\n\021STATE_UNSPECIFIED\020\000\022\014\n\010CREAT" + + "ING\020\001\022\t\n\005READY\020\002\022\021\n\rNOT_AVAILABLE\020\003:^\352A[" + + "\n\037firestore.googleapis.com/Backup\0228proje" + + "cts/{project}/locations/{location}/backu" + + "ps/{backup}B\332\001\n\035com.google.firestore.adm" + + "in.v1B\013BackupProtoP\001Z9cloud.google.com/g" + + "o/firestore/apiv1/admin/adminpb;adminpb\242" + + "\002\004GCFS\252\002\037Google.Cloud.Firestore.Admin.V1" + + "\312\002\037Google\\Cloud\\Firestore\\Admin\\V1\352\002#Goo" + + "gle::Cloud::Firestore::Admin::V1b\006proto3" + }; + descriptor = + com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( + descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + com.google.api.FieldBehaviorProto.getDescriptor(), + com.google.api.ResourceProto.getDescriptor(), + com.google.protobuf.TimestampProto.getDescriptor(), + }); + internal_static_google_firestore_admin_v1_Backup_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_google_firestore_admin_v1_Backup_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_Backup_descriptor, + new java.lang.String[] { + "Name", "Database", "DatabaseUid", "SnapshotTime", "ExpireTime", "Stats", "State", + }); + internal_static_google_firestore_admin_v1_Backup_Stats_descriptor = + internal_static_google_firestore_admin_v1_Backup_descriptor.getNestedTypes().get(0); + internal_static_google_firestore_admin_v1_Backup_Stats_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_Backup_Stats_descriptor, + new java.lang.String[] { + "SizeBytes", "DocumentCount", "IndexCount", + }); + com.google.protobuf.ExtensionRegistry registry = + com.google.protobuf.ExtensionRegistry.newInstance(); + registry.add(com.google.api.FieldBehaviorProto.fieldBehavior); + registry.add(com.google.api.ResourceProto.resource); + registry.add(com.google.api.ResourceProto.resourceReference); + com.google.protobuf.Descriptors.FileDescriptor.internalUpdateFileDescriptor( + descriptor, registry); + com.google.api.FieldBehaviorProto.getDescriptor(); + com.google.api.ResourceProto.getDescriptor(); + com.google.protobuf.TimestampProto.getDescriptor(); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupSchedule.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupSchedule.java new file mode 100644 index 000000000..7c549cea5 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupSchedule.java @@ -0,0 +1,2256 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/schedule.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +/** + * + * + *
+ * A backup schedule for a Cloud Firestore Database.
+ *
+ * This resource is owned by the database it is backing up, and is deleted along
+ * with the database. The actual backups are not though.
+ * 
+ * + * Protobuf type {@code google.firestore.admin.v1.BackupSchedule} + */ +public final class BackupSchedule extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.BackupSchedule) + BackupScheduleOrBuilder { + private static final long serialVersionUID = 0L; + // Use BackupSchedule.newBuilder() to construct. + private BackupSchedule(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private BackupSchedule() { + name_ = ""; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new BackupSchedule(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.ScheduleProto + .internal_static_google_firestore_admin_v1_BackupSchedule_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.ScheduleProto + .internal_static_google_firestore_admin_v1_BackupSchedule_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.BackupSchedule.class, + com.google.firestore.admin.v1.BackupSchedule.Builder.class); + } + + private int bitField0_; + private int recurrenceCase_ = 0; + + @SuppressWarnings("serial") + private java.lang.Object recurrence_; + + public enum RecurrenceCase + implements + com.google.protobuf.Internal.EnumLite, + com.google.protobuf.AbstractMessage.InternalOneOfEnum { + DAILY_RECURRENCE(7), + WEEKLY_RECURRENCE(8), + RECURRENCE_NOT_SET(0); + private final int value; + + private RecurrenceCase(int value) { + this.value = value; + } + /** + * @param value The number of the enum to look for. + * @return The enum associated with the given number. + * @deprecated Use {@link #forNumber(int)} instead. + */ + @java.lang.Deprecated + public static RecurrenceCase valueOf(int value) { + return forNumber(value); + } + + public static RecurrenceCase forNumber(int value) { + switch (value) { + case 7: + return DAILY_RECURRENCE; + case 8: + return WEEKLY_RECURRENCE; + case 0: + return RECURRENCE_NOT_SET; + default: + return null; + } + } + + public int getNumber() { + return this.value; + } + }; + + public RecurrenceCase getRecurrenceCase() { + return RecurrenceCase.forNumber(recurrenceCase_); + } + + public static final int NAME_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile java.lang.Object name_ = ""; + /** + * + * + *
+   * Output only. The unique backup schedule identifier across all locations and
+   * databases for the given project.
+   *
+   * This will be auto-assigned.
+   *
+   * Format is
+   * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+   * 
+ * + * string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } + } + /** + * + * + *
+   * Output only. The unique backup schedule identifier across all locations and
+   * databases for the given project.
+   *
+   * This will be auto-assigned.
+   *
+   * Format is
+   * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+   * 
+ * + * string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int CREATE_TIME_FIELD_NUMBER = 3; + private com.google.protobuf.Timestamp createTime_; + /** + * + * + *
+   * Output only. The timestamp at which this backup schedule was created and
+   * effective since.
+   *
+   * No backups will be created for this schedule before this time.
+   * 
+ * + * .google.protobuf.Timestamp create_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return Whether the createTime field is set. + */ + @java.lang.Override + public boolean hasCreateTime() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * + * + *
+   * Output only. The timestamp at which this backup schedule was created and
+   * effective since.
+   *
+   * No backups will be created for this schedule before this time.
+   * 
+ * + * .google.protobuf.Timestamp create_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The createTime. + */ + @java.lang.Override + public com.google.protobuf.Timestamp getCreateTime() { + return createTime_ == null ? com.google.protobuf.Timestamp.getDefaultInstance() : createTime_; + } + /** + * + * + *
+   * Output only. The timestamp at which this backup schedule was created and
+   * effective since.
+   *
+   * No backups will be created for this schedule before this time.
+   * 
+ * + * .google.protobuf.Timestamp create_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + @java.lang.Override + public com.google.protobuf.TimestampOrBuilder getCreateTimeOrBuilder() { + return createTime_ == null ? com.google.protobuf.Timestamp.getDefaultInstance() : createTime_; + } + + public static final int UPDATE_TIME_FIELD_NUMBER = 10; + private com.google.protobuf.Timestamp updateTime_; + /** + * + * + *
+   * Output only. The timestamp at which this backup schedule was most recently
+   * updated. When a backup schedule is first created, this is the same as
+   * create_time.
+   * 
+ * + * .google.protobuf.Timestamp update_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return Whether the updateTime field is set. + */ + @java.lang.Override + public boolean hasUpdateTime() { + return ((bitField0_ & 0x00000002) != 0); + } + /** + * + * + *
+   * Output only. The timestamp at which this backup schedule was most recently
+   * updated. When a backup schedule is first created, this is the same as
+   * create_time.
+   * 
+ * + * .google.protobuf.Timestamp update_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The updateTime. + */ + @java.lang.Override + public com.google.protobuf.Timestamp getUpdateTime() { + return updateTime_ == null ? com.google.protobuf.Timestamp.getDefaultInstance() : updateTime_; + } + /** + * + * + *
+   * Output only. The timestamp at which this backup schedule was most recently
+   * updated. When a backup schedule is first created, this is the same as
+   * create_time.
+   * 
+ * + * .google.protobuf.Timestamp update_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + @java.lang.Override + public com.google.protobuf.TimestampOrBuilder getUpdateTimeOrBuilder() { + return updateTime_ == null ? com.google.protobuf.Timestamp.getDefaultInstance() : updateTime_; + } + + public static final int RETENTION_FIELD_NUMBER = 6; + private com.google.protobuf.Duration retention_; + /** + * + * + *
+   * At what relative time in the future, compared to its creation time,
+   * the backup should be deleted, e.g. keep backups for 7 days.
+   * 
+ * + * .google.protobuf.Duration retention = 6; + * + * @return Whether the retention field is set. + */ + @java.lang.Override + public boolean hasRetention() { + return ((bitField0_ & 0x00000004) != 0); + } + /** + * + * + *
+   * At what relative time in the future, compared to its creation time,
+   * the backup should be deleted, e.g. keep backups for 7 days.
+   * 
+ * + * .google.protobuf.Duration retention = 6; + * + * @return The retention. + */ + @java.lang.Override + public com.google.protobuf.Duration getRetention() { + return retention_ == null ? com.google.protobuf.Duration.getDefaultInstance() : retention_; + } + /** + * + * + *
+   * At what relative time in the future, compared to its creation time,
+   * the backup should be deleted, e.g. keep backups for 7 days.
+   * 
+ * + * .google.protobuf.Duration retention = 6; + */ + @java.lang.Override + public com.google.protobuf.DurationOrBuilder getRetentionOrBuilder() { + return retention_ == null ? com.google.protobuf.Duration.getDefaultInstance() : retention_; + } + + public static final int DAILY_RECURRENCE_FIELD_NUMBER = 7; + /** + * + * + *
+   * For a schedule that runs daily.
+   * 
+ * + * .google.firestore.admin.v1.DailyRecurrence daily_recurrence = 7; + * + * @return Whether the dailyRecurrence field is set. + */ + @java.lang.Override + public boolean hasDailyRecurrence() { + return recurrenceCase_ == 7; + } + /** + * + * + *
+   * For a schedule that runs daily.
+   * 
+ * + * .google.firestore.admin.v1.DailyRecurrence daily_recurrence = 7; + * + * @return The dailyRecurrence. + */ + @java.lang.Override + public com.google.firestore.admin.v1.DailyRecurrence getDailyRecurrence() { + if (recurrenceCase_ == 7) { + return (com.google.firestore.admin.v1.DailyRecurrence) recurrence_; + } + return com.google.firestore.admin.v1.DailyRecurrence.getDefaultInstance(); + } + /** + * + * + *
+   * For a schedule that runs daily.
+   * 
+ * + * .google.firestore.admin.v1.DailyRecurrence daily_recurrence = 7; + */ + @java.lang.Override + public com.google.firestore.admin.v1.DailyRecurrenceOrBuilder getDailyRecurrenceOrBuilder() { + if (recurrenceCase_ == 7) { + return (com.google.firestore.admin.v1.DailyRecurrence) recurrence_; + } + return com.google.firestore.admin.v1.DailyRecurrence.getDefaultInstance(); + } + + public static final int WEEKLY_RECURRENCE_FIELD_NUMBER = 8; + /** + * + * + *
+   * For a schedule that runs weekly on a specific day.
+   * 
+ * + * .google.firestore.admin.v1.WeeklyRecurrence weekly_recurrence = 8; + * + * @return Whether the weeklyRecurrence field is set. + */ + @java.lang.Override + public boolean hasWeeklyRecurrence() { + return recurrenceCase_ == 8; + } + /** + * + * + *
+   * For a schedule that runs weekly on a specific day.
+   * 
+ * + * .google.firestore.admin.v1.WeeklyRecurrence weekly_recurrence = 8; + * + * @return The weeklyRecurrence. + */ + @java.lang.Override + public com.google.firestore.admin.v1.WeeklyRecurrence getWeeklyRecurrence() { + if (recurrenceCase_ == 8) { + return (com.google.firestore.admin.v1.WeeklyRecurrence) recurrence_; + } + return com.google.firestore.admin.v1.WeeklyRecurrence.getDefaultInstance(); + } + /** + * + * + *
+   * For a schedule that runs weekly on a specific day.
+   * 
+ * + * .google.firestore.admin.v1.WeeklyRecurrence weekly_recurrence = 8; + */ + @java.lang.Override + public com.google.firestore.admin.v1.WeeklyRecurrenceOrBuilder getWeeklyRecurrenceOrBuilder() { + if (recurrenceCase_ == 8) { + return (com.google.firestore.admin.v1.WeeklyRecurrence) recurrence_; + } + return com.google.firestore.admin.v1.WeeklyRecurrence.getDefaultInstance(); + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + } + if (((bitField0_ & 0x00000001) != 0)) { + output.writeMessage(3, getCreateTime()); + } + if (((bitField0_ & 0x00000004) != 0)) { + output.writeMessage(6, getRetention()); + } + if (recurrenceCase_ == 7) { + output.writeMessage(7, (com.google.firestore.admin.v1.DailyRecurrence) recurrence_); + } + if (recurrenceCase_ == 8) { + output.writeMessage(8, (com.google.firestore.admin.v1.WeeklyRecurrence) recurrence_); + } + if (((bitField0_ & 0x00000002) != 0)) { + output.writeMessage(10, getUpdateTime()); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + } + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(3, getCreateTime()); + } + if (((bitField0_ & 0x00000004) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(6, getRetention()); + } + if (recurrenceCase_ == 7) { + size += + com.google.protobuf.CodedOutputStream.computeMessageSize( + 7, (com.google.firestore.admin.v1.DailyRecurrence) recurrence_); + } + if (recurrenceCase_ == 8) { + size += + com.google.protobuf.CodedOutputStream.computeMessageSize( + 8, (com.google.firestore.admin.v1.WeeklyRecurrence) recurrence_); + } + if (((bitField0_ & 0x00000002) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(10, getUpdateTime()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.admin.v1.BackupSchedule)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.BackupSchedule other = + (com.google.firestore.admin.v1.BackupSchedule) obj; + + if (!getName().equals(other.getName())) return false; + if (hasCreateTime() != other.hasCreateTime()) return false; + if (hasCreateTime()) { + if (!getCreateTime().equals(other.getCreateTime())) return false; + } + if (hasUpdateTime() != other.hasUpdateTime()) return false; + if (hasUpdateTime()) { + if (!getUpdateTime().equals(other.getUpdateTime())) return false; + } + if (hasRetention() != other.hasRetention()) return false; + if (hasRetention()) { + if (!getRetention().equals(other.getRetention())) return false; + } + if (!getRecurrenceCase().equals(other.getRecurrenceCase())) return false; + switch (recurrenceCase_) { + case 7: + if (!getDailyRecurrence().equals(other.getDailyRecurrence())) return false; + break; + case 8: + if (!getWeeklyRecurrence().equals(other.getWeeklyRecurrence())) return false; + break; + case 0: + default: + } + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + NAME_FIELD_NUMBER; + hash = (53 * hash) + getName().hashCode(); + if (hasCreateTime()) { + hash = (37 * hash) + CREATE_TIME_FIELD_NUMBER; + hash = (53 * hash) + getCreateTime().hashCode(); + } + if (hasUpdateTime()) { + hash = (37 * hash) + UPDATE_TIME_FIELD_NUMBER; + hash = (53 * hash) + getUpdateTime().hashCode(); + } + if (hasRetention()) { + hash = (37 * hash) + RETENTION_FIELD_NUMBER; + hash = (53 * hash) + getRetention().hashCode(); + } + switch (recurrenceCase_) { + case 7: + hash = (37 * hash) + DAILY_RECURRENCE_FIELD_NUMBER; + hash = (53 * hash) + getDailyRecurrence().hashCode(); + break; + case 8: + hash = (37 * hash) + WEEKLY_RECURRENCE_FIELD_NUMBER; + hash = (53 * hash) + getWeeklyRecurrence().hashCode(); + break; + case 0: + default: + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.BackupSchedule parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.BackupSchedule parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.BackupSchedule parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.BackupSchedule parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.BackupSchedule parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.BackupSchedule parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.BackupSchedule parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.BackupSchedule parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.BackupSchedule parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.BackupSchedule parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.BackupSchedule parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.BackupSchedule parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.admin.v1.BackupSchedule prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * A backup schedule for a Cloud Firestore Database.
+   *
+   * This resource is owned by the database it is backing up, and is deleted along
+   * with the database. The actual backups are not though.
+   * 
+ * + * Protobuf type {@code google.firestore.admin.v1.BackupSchedule} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.BackupSchedule) + com.google.firestore.admin.v1.BackupScheduleOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.ScheduleProto + .internal_static_google_firestore_admin_v1_BackupSchedule_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.ScheduleProto + .internal_static_google_firestore_admin_v1_BackupSchedule_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.BackupSchedule.class, + com.google.firestore.admin.v1.BackupSchedule.Builder.class); + } + + // Construct using com.google.firestore.admin.v1.BackupSchedule.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) { + getCreateTimeFieldBuilder(); + getUpdateTimeFieldBuilder(); + getRetentionFieldBuilder(); + } + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + name_ = ""; + createTime_ = null; + if (createTimeBuilder_ != null) { + createTimeBuilder_.dispose(); + createTimeBuilder_ = null; + } + updateTime_ = null; + if (updateTimeBuilder_ != null) { + updateTimeBuilder_.dispose(); + updateTimeBuilder_ = null; + } + retention_ = null; + if (retentionBuilder_ != null) { + retentionBuilder_.dispose(); + retentionBuilder_ = null; + } + if (dailyRecurrenceBuilder_ != null) { + dailyRecurrenceBuilder_.clear(); + } + if (weeklyRecurrenceBuilder_ != null) { + weeklyRecurrenceBuilder_.clear(); + } + recurrenceCase_ = 0; + recurrence_ = null; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.ScheduleProto + .internal_static_google_firestore_admin_v1_BackupSchedule_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.BackupSchedule getDefaultInstanceForType() { + return com.google.firestore.admin.v1.BackupSchedule.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.BackupSchedule build() { + com.google.firestore.admin.v1.BackupSchedule result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.BackupSchedule buildPartial() { + com.google.firestore.admin.v1.BackupSchedule result = + new com.google.firestore.admin.v1.BackupSchedule(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + buildPartialOneofs(result); + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.admin.v1.BackupSchedule result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.name_ = name_; + } + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000002) != 0)) { + result.createTime_ = createTimeBuilder_ == null ? createTime_ : createTimeBuilder_.build(); + to_bitField0_ |= 0x00000001; + } + if (((from_bitField0_ & 0x00000004) != 0)) { + result.updateTime_ = updateTimeBuilder_ == null ? updateTime_ : updateTimeBuilder_.build(); + to_bitField0_ |= 0x00000002; + } + if (((from_bitField0_ & 0x00000008) != 0)) { + result.retention_ = retentionBuilder_ == null ? retention_ : retentionBuilder_.build(); + to_bitField0_ |= 0x00000004; + } + result.bitField0_ |= to_bitField0_; + } + + private void buildPartialOneofs(com.google.firestore.admin.v1.BackupSchedule result) { + result.recurrenceCase_ = recurrenceCase_; + result.recurrence_ = this.recurrence_; + if (recurrenceCase_ == 7 && dailyRecurrenceBuilder_ != null) { + result.recurrence_ = dailyRecurrenceBuilder_.build(); + } + if (recurrenceCase_ == 8 && weeklyRecurrenceBuilder_ != null) { + result.recurrence_ = weeklyRecurrenceBuilder_.build(); + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.admin.v1.BackupSchedule) { + return mergeFrom((com.google.firestore.admin.v1.BackupSchedule) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.admin.v1.BackupSchedule other) { + if (other == com.google.firestore.admin.v1.BackupSchedule.getDefaultInstance()) return this; + if (!other.getName().isEmpty()) { + name_ = other.name_; + bitField0_ |= 0x00000001; + onChanged(); + } + if (other.hasCreateTime()) { + mergeCreateTime(other.getCreateTime()); + } + if (other.hasUpdateTime()) { + mergeUpdateTime(other.getUpdateTime()); + } + if (other.hasRetention()) { + mergeRetention(other.getRetention()); + } + switch (other.getRecurrenceCase()) { + case DAILY_RECURRENCE: + { + mergeDailyRecurrence(other.getDailyRecurrence()); + break; + } + case WEEKLY_RECURRENCE: + { + mergeWeeklyRecurrence(other.getWeeklyRecurrence()); + break; + } + case RECURRENCE_NOT_SET: + { + break; + } + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + name_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 26: + { + input.readMessage(getCreateTimeFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000002; + break; + } // case 26 + case 50: + { + input.readMessage(getRetentionFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000008; + break; + } // case 50 + case 58: + { + input.readMessage(getDailyRecurrenceFieldBuilder().getBuilder(), extensionRegistry); + recurrenceCase_ = 7; + break; + } // case 58 + case 66: + { + input.readMessage( + getWeeklyRecurrenceFieldBuilder().getBuilder(), extensionRegistry); + recurrenceCase_ = 8; + break; + } // case 66 + case 82: + { + input.readMessage(getUpdateTimeFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000004; + break; + } // case 82 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int recurrenceCase_ = 0; + private java.lang.Object recurrence_; + + public RecurrenceCase getRecurrenceCase() { + return RecurrenceCase.forNumber(recurrenceCase_); + } + + public Builder clearRecurrence() { + recurrenceCase_ = 0; + recurrence_ = null; + onChanged(); + return this; + } + + private int bitField0_; + + private java.lang.Object name_ = ""; + /** + * + * + *
+     * Output only. The unique backup schedule identifier across all locations and
+     * databases for the given project.
+     *
+     * This will be auto-assigned.
+     *
+     * Format is
+     * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+     * 
+ * + * string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The name. + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * Output only. The unique backup schedule identifier across all locations and
+     * databases for the given project.
+     *
+     * This will be auto-assigned.
+     *
+     * Format is
+     * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+     * 
+ * + * string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The bytes for name. + */ + public com.google.protobuf.ByteString getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * Output only. The unique backup schedule identifier across all locations and
+     * databases for the given project.
+     *
+     * This will be auto-assigned.
+     *
+     * Format is
+     * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+     * 
+ * + * string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The unique backup schedule identifier across all locations and
+     * databases for the given project.
+     *
+     * This will be auto-assigned.
+     *
+     * Format is
+     * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+     * 
+ * + * string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return This builder for chaining. + */ + public Builder clearName() { + name_ = getDefaultInstance().getName(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The unique backup schedule identifier across all locations and
+     * databases for the given project.
+     *
+     * This will be auto-assigned.
+     *
+     * Format is
+     * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+     * 
+ * + * string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + private com.google.protobuf.Timestamp createTime_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder> + createTimeBuilder_; + /** + * + * + *
+     * Output only. The timestamp at which this backup schedule was created and
+     * effective since.
+     *
+     * No backups will be created for this schedule before this time.
+     * 
+ * + * + * .google.protobuf.Timestamp create_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return Whether the createTime field is set. + */ + public boolean hasCreateTime() { + return ((bitField0_ & 0x00000002) != 0); + } + /** + * + * + *
+     * Output only. The timestamp at which this backup schedule was created and
+     * effective since.
+     *
+     * No backups will be created for this schedule before this time.
+     * 
+ * + * + * .google.protobuf.Timestamp create_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The createTime. + */ + public com.google.protobuf.Timestamp getCreateTime() { + if (createTimeBuilder_ == null) { + return createTime_ == null + ? com.google.protobuf.Timestamp.getDefaultInstance() + : createTime_; + } else { + return createTimeBuilder_.getMessage(); + } + } + /** + * + * + *
+     * Output only. The timestamp at which this backup schedule was created and
+     * effective since.
+     *
+     * No backups will be created for this schedule before this time.
+     * 
+ * + * + * .google.protobuf.Timestamp create_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder setCreateTime(com.google.protobuf.Timestamp value) { + if (createTimeBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + createTime_ = value; + } else { + createTimeBuilder_.setMessage(value); + } + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The timestamp at which this backup schedule was created and
+     * effective since.
+     *
+     * No backups will be created for this schedule before this time.
+     * 
+ * + * + * .google.protobuf.Timestamp create_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder setCreateTime(com.google.protobuf.Timestamp.Builder builderForValue) { + if (createTimeBuilder_ == null) { + createTime_ = builderForValue.build(); + } else { + createTimeBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The timestamp at which this backup schedule was created and
+     * effective since.
+     *
+     * No backups will be created for this schedule before this time.
+     * 
+ * + * + * .google.protobuf.Timestamp create_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder mergeCreateTime(com.google.protobuf.Timestamp value) { + if (createTimeBuilder_ == null) { + if (((bitField0_ & 0x00000002) != 0) + && createTime_ != null + && createTime_ != com.google.protobuf.Timestamp.getDefaultInstance()) { + getCreateTimeBuilder().mergeFrom(value); + } else { + createTime_ = value; + } + } else { + createTimeBuilder_.mergeFrom(value); + } + if (createTime_ != null) { + bitField0_ |= 0x00000002; + onChanged(); + } + return this; + } + /** + * + * + *
+     * Output only. The timestamp at which this backup schedule was created and
+     * effective since.
+     *
+     * No backups will be created for this schedule before this time.
+     * 
+ * + * + * .google.protobuf.Timestamp create_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder clearCreateTime() { + bitField0_ = (bitField0_ & ~0x00000002); + createTime_ = null; + if (createTimeBuilder_ != null) { + createTimeBuilder_.dispose(); + createTimeBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The timestamp at which this backup schedule was created and
+     * effective since.
+     *
+     * No backups will be created for this schedule before this time.
+     * 
+ * + * + * .google.protobuf.Timestamp create_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public com.google.protobuf.Timestamp.Builder getCreateTimeBuilder() { + bitField0_ |= 0x00000002; + onChanged(); + return getCreateTimeFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * Output only. The timestamp at which this backup schedule was created and
+     * effective since.
+     *
+     * No backups will be created for this schedule before this time.
+     * 
+ * + * + * .google.protobuf.Timestamp create_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public com.google.protobuf.TimestampOrBuilder getCreateTimeOrBuilder() { + if (createTimeBuilder_ != null) { + return createTimeBuilder_.getMessageOrBuilder(); + } else { + return createTime_ == null + ? com.google.protobuf.Timestamp.getDefaultInstance() + : createTime_; + } + } + /** + * + * + *
+     * Output only. The timestamp at which this backup schedule was created and
+     * effective since.
+     *
+     * No backups will be created for this schedule before this time.
+     * 
+ * + * + * .google.protobuf.Timestamp create_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder> + getCreateTimeFieldBuilder() { + if (createTimeBuilder_ == null) { + createTimeBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder>( + getCreateTime(), getParentForChildren(), isClean()); + createTime_ = null; + } + return createTimeBuilder_; + } + + private com.google.protobuf.Timestamp updateTime_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder> + updateTimeBuilder_; + /** + * + * + *
+     * Output only. The timestamp at which this backup schedule was most recently
+     * updated. When a backup schedule is first created, this is the same as
+     * create_time.
+     * 
+ * + * + * .google.protobuf.Timestamp update_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return Whether the updateTime field is set. + */ + public boolean hasUpdateTime() { + return ((bitField0_ & 0x00000004) != 0); + } + /** + * + * + *
+     * Output only. The timestamp at which this backup schedule was most recently
+     * updated. When a backup schedule is first created, this is the same as
+     * create_time.
+     * 
+ * + * + * .google.protobuf.Timestamp update_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The updateTime. + */ + public com.google.protobuf.Timestamp getUpdateTime() { + if (updateTimeBuilder_ == null) { + return updateTime_ == null + ? com.google.protobuf.Timestamp.getDefaultInstance() + : updateTime_; + } else { + return updateTimeBuilder_.getMessage(); + } + } + /** + * + * + *
+     * Output only. The timestamp at which this backup schedule was most recently
+     * updated. When a backup schedule is first created, this is the same as
+     * create_time.
+     * 
+ * + * + * .google.protobuf.Timestamp update_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder setUpdateTime(com.google.protobuf.Timestamp value) { + if (updateTimeBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + updateTime_ = value; + } else { + updateTimeBuilder_.setMessage(value); + } + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The timestamp at which this backup schedule was most recently
+     * updated. When a backup schedule is first created, this is the same as
+     * create_time.
+     * 
+ * + * + * .google.protobuf.Timestamp update_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder setUpdateTime(com.google.protobuf.Timestamp.Builder builderForValue) { + if (updateTimeBuilder_ == null) { + updateTime_ = builderForValue.build(); + } else { + updateTimeBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The timestamp at which this backup schedule was most recently
+     * updated. When a backup schedule is first created, this is the same as
+     * create_time.
+     * 
+ * + * + * .google.protobuf.Timestamp update_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder mergeUpdateTime(com.google.protobuf.Timestamp value) { + if (updateTimeBuilder_ == null) { + if (((bitField0_ & 0x00000004) != 0) + && updateTime_ != null + && updateTime_ != com.google.protobuf.Timestamp.getDefaultInstance()) { + getUpdateTimeBuilder().mergeFrom(value); + } else { + updateTime_ = value; + } + } else { + updateTimeBuilder_.mergeFrom(value); + } + if (updateTime_ != null) { + bitField0_ |= 0x00000004; + onChanged(); + } + return this; + } + /** + * + * + *
+     * Output only. The timestamp at which this backup schedule was most recently
+     * updated. When a backup schedule is first created, this is the same as
+     * create_time.
+     * 
+ * + * + * .google.protobuf.Timestamp update_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public Builder clearUpdateTime() { + bitField0_ = (bitField0_ & ~0x00000004); + updateTime_ = null; + if (updateTimeBuilder_ != null) { + updateTimeBuilder_.dispose(); + updateTimeBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * Output only. The timestamp at which this backup schedule was most recently
+     * updated. When a backup schedule is first created, this is the same as
+     * create_time.
+     * 
+ * + * + * .google.protobuf.Timestamp update_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public com.google.protobuf.Timestamp.Builder getUpdateTimeBuilder() { + bitField0_ |= 0x00000004; + onChanged(); + return getUpdateTimeFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * Output only. The timestamp at which this backup schedule was most recently
+     * updated. When a backup schedule is first created, this is the same as
+     * create_time.
+     * 
+ * + * + * .google.protobuf.Timestamp update_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + public com.google.protobuf.TimestampOrBuilder getUpdateTimeOrBuilder() { + if (updateTimeBuilder_ != null) { + return updateTimeBuilder_.getMessageOrBuilder(); + } else { + return updateTime_ == null + ? com.google.protobuf.Timestamp.getDefaultInstance() + : updateTime_; + } + } + /** + * + * + *
+     * Output only. The timestamp at which this backup schedule was most recently
+     * updated. When a backup schedule is first created, this is the same as
+     * create_time.
+     * 
+ * + * + * .google.protobuf.Timestamp update_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder> + getUpdateTimeFieldBuilder() { + if (updateTimeBuilder_ == null) { + updateTimeBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder>( + getUpdateTime(), getParentForChildren(), isClean()); + updateTime_ = null; + } + return updateTimeBuilder_; + } + + private com.google.protobuf.Duration retention_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Duration, + com.google.protobuf.Duration.Builder, + com.google.protobuf.DurationOrBuilder> + retentionBuilder_; + /** + * + * + *
+     * At what relative time in the future, compared to its creation time,
+     * the backup should be deleted, e.g. keep backups for 7 days.
+     * 
+ * + * .google.protobuf.Duration retention = 6; + * + * @return Whether the retention field is set. + */ + public boolean hasRetention() { + return ((bitField0_ & 0x00000008) != 0); + } + /** + * + * + *
+     * At what relative time in the future, compared to its creation time,
+     * the backup should be deleted, e.g. keep backups for 7 days.
+     * 
+ * + * .google.protobuf.Duration retention = 6; + * + * @return The retention. + */ + public com.google.protobuf.Duration getRetention() { + if (retentionBuilder_ == null) { + return retention_ == null ? com.google.protobuf.Duration.getDefaultInstance() : retention_; + } else { + return retentionBuilder_.getMessage(); + } + } + /** + * + * + *
+     * At what relative time in the future, compared to its creation time,
+     * the backup should be deleted, e.g. keep backups for 7 days.
+     * 
+ * + * .google.protobuf.Duration retention = 6; + */ + public Builder setRetention(com.google.protobuf.Duration value) { + if (retentionBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + retention_ = value; + } else { + retentionBuilder_.setMessage(value); + } + bitField0_ |= 0x00000008; + onChanged(); + return this; + } + /** + * + * + *
+     * At what relative time in the future, compared to its creation time,
+     * the backup should be deleted, e.g. keep backups for 7 days.
+     * 
+ * + * .google.protobuf.Duration retention = 6; + */ + public Builder setRetention(com.google.protobuf.Duration.Builder builderForValue) { + if (retentionBuilder_ == null) { + retention_ = builderForValue.build(); + } else { + retentionBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000008; + onChanged(); + return this; + } + /** + * + * + *
+     * At what relative time in the future, compared to its creation time,
+     * the backup should be deleted, e.g. keep backups for 7 days.
+     * 
+ * + * .google.protobuf.Duration retention = 6; + */ + public Builder mergeRetention(com.google.protobuf.Duration value) { + if (retentionBuilder_ == null) { + if (((bitField0_ & 0x00000008) != 0) + && retention_ != null + && retention_ != com.google.protobuf.Duration.getDefaultInstance()) { + getRetentionBuilder().mergeFrom(value); + } else { + retention_ = value; + } + } else { + retentionBuilder_.mergeFrom(value); + } + if (retention_ != null) { + bitField0_ |= 0x00000008; + onChanged(); + } + return this; + } + /** + * + * + *
+     * At what relative time in the future, compared to its creation time,
+     * the backup should be deleted, e.g. keep backups for 7 days.
+     * 
+ * + * .google.protobuf.Duration retention = 6; + */ + public Builder clearRetention() { + bitField0_ = (bitField0_ & ~0x00000008); + retention_ = null; + if (retentionBuilder_ != null) { + retentionBuilder_.dispose(); + retentionBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * At what relative time in the future, compared to its creation time,
+     * the backup should be deleted, e.g. keep backups for 7 days.
+     * 
+ * + * .google.protobuf.Duration retention = 6; + */ + public com.google.protobuf.Duration.Builder getRetentionBuilder() { + bitField0_ |= 0x00000008; + onChanged(); + return getRetentionFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * At what relative time in the future, compared to its creation time,
+     * the backup should be deleted, e.g. keep backups for 7 days.
+     * 
+ * + * .google.protobuf.Duration retention = 6; + */ + public com.google.protobuf.DurationOrBuilder getRetentionOrBuilder() { + if (retentionBuilder_ != null) { + return retentionBuilder_.getMessageOrBuilder(); + } else { + return retention_ == null ? com.google.protobuf.Duration.getDefaultInstance() : retention_; + } + } + /** + * + * + *
+     * At what relative time in the future, compared to its creation time,
+     * the backup should be deleted, e.g. keep backups for 7 days.
+     * 
+ * + * .google.protobuf.Duration retention = 6; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Duration, + com.google.protobuf.Duration.Builder, + com.google.protobuf.DurationOrBuilder> + getRetentionFieldBuilder() { + if (retentionBuilder_ == null) { + retentionBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Duration, + com.google.protobuf.Duration.Builder, + com.google.protobuf.DurationOrBuilder>( + getRetention(), getParentForChildren(), isClean()); + retention_ = null; + } + return retentionBuilder_; + } + + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.DailyRecurrence, + com.google.firestore.admin.v1.DailyRecurrence.Builder, + com.google.firestore.admin.v1.DailyRecurrenceOrBuilder> + dailyRecurrenceBuilder_; + /** + * + * + *
+     * For a schedule that runs daily.
+     * 
+ * + * .google.firestore.admin.v1.DailyRecurrence daily_recurrence = 7; + * + * @return Whether the dailyRecurrence field is set. + */ + @java.lang.Override + public boolean hasDailyRecurrence() { + return recurrenceCase_ == 7; + } + /** + * + * + *
+     * For a schedule that runs daily.
+     * 
+ * + * .google.firestore.admin.v1.DailyRecurrence daily_recurrence = 7; + * + * @return The dailyRecurrence. + */ + @java.lang.Override + public com.google.firestore.admin.v1.DailyRecurrence getDailyRecurrence() { + if (dailyRecurrenceBuilder_ == null) { + if (recurrenceCase_ == 7) { + return (com.google.firestore.admin.v1.DailyRecurrence) recurrence_; + } + return com.google.firestore.admin.v1.DailyRecurrence.getDefaultInstance(); + } else { + if (recurrenceCase_ == 7) { + return dailyRecurrenceBuilder_.getMessage(); + } + return com.google.firestore.admin.v1.DailyRecurrence.getDefaultInstance(); + } + } + /** + * + * + *
+     * For a schedule that runs daily.
+     * 
+ * + * .google.firestore.admin.v1.DailyRecurrence daily_recurrence = 7; + */ + public Builder setDailyRecurrence(com.google.firestore.admin.v1.DailyRecurrence value) { + if (dailyRecurrenceBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + recurrence_ = value; + onChanged(); + } else { + dailyRecurrenceBuilder_.setMessage(value); + } + recurrenceCase_ = 7; + return this; + } + /** + * + * + *
+     * For a schedule that runs daily.
+     * 
+ * + * .google.firestore.admin.v1.DailyRecurrence daily_recurrence = 7; + */ + public Builder setDailyRecurrence( + com.google.firestore.admin.v1.DailyRecurrence.Builder builderForValue) { + if (dailyRecurrenceBuilder_ == null) { + recurrence_ = builderForValue.build(); + onChanged(); + } else { + dailyRecurrenceBuilder_.setMessage(builderForValue.build()); + } + recurrenceCase_ = 7; + return this; + } + /** + * + * + *
+     * For a schedule that runs daily.
+     * 
+ * + * .google.firestore.admin.v1.DailyRecurrence daily_recurrence = 7; + */ + public Builder mergeDailyRecurrence(com.google.firestore.admin.v1.DailyRecurrence value) { + if (dailyRecurrenceBuilder_ == null) { + if (recurrenceCase_ == 7 + && recurrence_ != com.google.firestore.admin.v1.DailyRecurrence.getDefaultInstance()) { + recurrence_ = + com.google.firestore.admin.v1.DailyRecurrence.newBuilder( + (com.google.firestore.admin.v1.DailyRecurrence) recurrence_) + .mergeFrom(value) + .buildPartial(); + } else { + recurrence_ = value; + } + onChanged(); + } else { + if (recurrenceCase_ == 7) { + dailyRecurrenceBuilder_.mergeFrom(value); + } else { + dailyRecurrenceBuilder_.setMessage(value); + } + } + recurrenceCase_ = 7; + return this; + } + /** + * + * + *
+     * For a schedule that runs daily.
+     * 
+ * + * .google.firestore.admin.v1.DailyRecurrence daily_recurrence = 7; + */ + public Builder clearDailyRecurrence() { + if (dailyRecurrenceBuilder_ == null) { + if (recurrenceCase_ == 7) { + recurrenceCase_ = 0; + recurrence_ = null; + onChanged(); + } + } else { + if (recurrenceCase_ == 7) { + recurrenceCase_ = 0; + recurrence_ = null; + } + dailyRecurrenceBuilder_.clear(); + } + return this; + } + /** + * + * + *
+     * For a schedule that runs daily.
+     * 
+ * + * .google.firestore.admin.v1.DailyRecurrence daily_recurrence = 7; + */ + public com.google.firestore.admin.v1.DailyRecurrence.Builder getDailyRecurrenceBuilder() { + return getDailyRecurrenceFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * For a schedule that runs daily.
+     * 
+ * + * .google.firestore.admin.v1.DailyRecurrence daily_recurrence = 7; + */ + @java.lang.Override + public com.google.firestore.admin.v1.DailyRecurrenceOrBuilder getDailyRecurrenceOrBuilder() { + if ((recurrenceCase_ == 7) && (dailyRecurrenceBuilder_ != null)) { + return dailyRecurrenceBuilder_.getMessageOrBuilder(); + } else { + if (recurrenceCase_ == 7) { + return (com.google.firestore.admin.v1.DailyRecurrence) recurrence_; + } + return com.google.firestore.admin.v1.DailyRecurrence.getDefaultInstance(); + } + } + /** + * + * + *
+     * For a schedule that runs daily.
+     * 
+ * + * .google.firestore.admin.v1.DailyRecurrence daily_recurrence = 7; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.DailyRecurrence, + com.google.firestore.admin.v1.DailyRecurrence.Builder, + com.google.firestore.admin.v1.DailyRecurrenceOrBuilder> + getDailyRecurrenceFieldBuilder() { + if (dailyRecurrenceBuilder_ == null) { + if (!(recurrenceCase_ == 7)) { + recurrence_ = com.google.firestore.admin.v1.DailyRecurrence.getDefaultInstance(); + } + dailyRecurrenceBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.DailyRecurrence, + com.google.firestore.admin.v1.DailyRecurrence.Builder, + com.google.firestore.admin.v1.DailyRecurrenceOrBuilder>( + (com.google.firestore.admin.v1.DailyRecurrence) recurrence_, + getParentForChildren(), + isClean()); + recurrence_ = null; + } + recurrenceCase_ = 7; + onChanged(); + return dailyRecurrenceBuilder_; + } + + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.WeeklyRecurrence, + com.google.firestore.admin.v1.WeeklyRecurrence.Builder, + com.google.firestore.admin.v1.WeeklyRecurrenceOrBuilder> + weeklyRecurrenceBuilder_; + /** + * + * + *
+     * For a schedule that runs weekly on a specific day.
+     * 
+ * + * .google.firestore.admin.v1.WeeklyRecurrence weekly_recurrence = 8; + * + * @return Whether the weeklyRecurrence field is set. + */ + @java.lang.Override + public boolean hasWeeklyRecurrence() { + return recurrenceCase_ == 8; + } + /** + * + * + *
+     * For a schedule that runs weekly on a specific day.
+     * 
+ * + * .google.firestore.admin.v1.WeeklyRecurrence weekly_recurrence = 8; + * + * @return The weeklyRecurrence. + */ + @java.lang.Override + public com.google.firestore.admin.v1.WeeklyRecurrence getWeeklyRecurrence() { + if (weeklyRecurrenceBuilder_ == null) { + if (recurrenceCase_ == 8) { + return (com.google.firestore.admin.v1.WeeklyRecurrence) recurrence_; + } + return com.google.firestore.admin.v1.WeeklyRecurrence.getDefaultInstance(); + } else { + if (recurrenceCase_ == 8) { + return weeklyRecurrenceBuilder_.getMessage(); + } + return com.google.firestore.admin.v1.WeeklyRecurrence.getDefaultInstance(); + } + } + /** + * + * + *
+     * For a schedule that runs weekly on a specific day.
+     * 
+ * + * .google.firestore.admin.v1.WeeklyRecurrence weekly_recurrence = 8; + */ + public Builder setWeeklyRecurrence(com.google.firestore.admin.v1.WeeklyRecurrence value) { + if (weeklyRecurrenceBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + recurrence_ = value; + onChanged(); + } else { + weeklyRecurrenceBuilder_.setMessage(value); + } + recurrenceCase_ = 8; + return this; + } + /** + * + * + *
+     * For a schedule that runs weekly on a specific day.
+     * 
+ * + * .google.firestore.admin.v1.WeeklyRecurrence weekly_recurrence = 8; + */ + public Builder setWeeklyRecurrence( + com.google.firestore.admin.v1.WeeklyRecurrence.Builder builderForValue) { + if (weeklyRecurrenceBuilder_ == null) { + recurrence_ = builderForValue.build(); + onChanged(); + } else { + weeklyRecurrenceBuilder_.setMessage(builderForValue.build()); + } + recurrenceCase_ = 8; + return this; + } + /** + * + * + *
+     * For a schedule that runs weekly on a specific day.
+     * 
+ * + * .google.firestore.admin.v1.WeeklyRecurrence weekly_recurrence = 8; + */ + public Builder mergeWeeklyRecurrence(com.google.firestore.admin.v1.WeeklyRecurrence value) { + if (weeklyRecurrenceBuilder_ == null) { + if (recurrenceCase_ == 8 + && recurrence_ != com.google.firestore.admin.v1.WeeklyRecurrence.getDefaultInstance()) { + recurrence_ = + com.google.firestore.admin.v1.WeeklyRecurrence.newBuilder( + (com.google.firestore.admin.v1.WeeklyRecurrence) recurrence_) + .mergeFrom(value) + .buildPartial(); + } else { + recurrence_ = value; + } + onChanged(); + } else { + if (recurrenceCase_ == 8) { + weeklyRecurrenceBuilder_.mergeFrom(value); + } else { + weeklyRecurrenceBuilder_.setMessage(value); + } + } + recurrenceCase_ = 8; + return this; + } + /** + * + * + *
+     * For a schedule that runs weekly on a specific day.
+     * 
+ * + * .google.firestore.admin.v1.WeeklyRecurrence weekly_recurrence = 8; + */ + public Builder clearWeeklyRecurrence() { + if (weeklyRecurrenceBuilder_ == null) { + if (recurrenceCase_ == 8) { + recurrenceCase_ = 0; + recurrence_ = null; + onChanged(); + } + } else { + if (recurrenceCase_ == 8) { + recurrenceCase_ = 0; + recurrence_ = null; + } + weeklyRecurrenceBuilder_.clear(); + } + return this; + } + /** + * + * + *
+     * For a schedule that runs weekly on a specific day.
+     * 
+ * + * .google.firestore.admin.v1.WeeklyRecurrence weekly_recurrence = 8; + */ + public com.google.firestore.admin.v1.WeeklyRecurrence.Builder getWeeklyRecurrenceBuilder() { + return getWeeklyRecurrenceFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * For a schedule that runs weekly on a specific day.
+     * 
+ * + * .google.firestore.admin.v1.WeeklyRecurrence weekly_recurrence = 8; + */ + @java.lang.Override + public com.google.firestore.admin.v1.WeeklyRecurrenceOrBuilder getWeeklyRecurrenceOrBuilder() { + if ((recurrenceCase_ == 8) && (weeklyRecurrenceBuilder_ != null)) { + return weeklyRecurrenceBuilder_.getMessageOrBuilder(); + } else { + if (recurrenceCase_ == 8) { + return (com.google.firestore.admin.v1.WeeklyRecurrence) recurrence_; + } + return com.google.firestore.admin.v1.WeeklyRecurrence.getDefaultInstance(); + } + } + /** + * + * + *
+     * For a schedule that runs weekly on a specific day.
+     * 
+ * + * .google.firestore.admin.v1.WeeklyRecurrence weekly_recurrence = 8; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.WeeklyRecurrence, + com.google.firestore.admin.v1.WeeklyRecurrence.Builder, + com.google.firestore.admin.v1.WeeklyRecurrenceOrBuilder> + getWeeklyRecurrenceFieldBuilder() { + if (weeklyRecurrenceBuilder_ == null) { + if (!(recurrenceCase_ == 8)) { + recurrence_ = com.google.firestore.admin.v1.WeeklyRecurrence.getDefaultInstance(); + } + weeklyRecurrenceBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.WeeklyRecurrence, + com.google.firestore.admin.v1.WeeklyRecurrence.Builder, + com.google.firestore.admin.v1.WeeklyRecurrenceOrBuilder>( + (com.google.firestore.admin.v1.WeeklyRecurrence) recurrence_, + getParentForChildren(), + isClean()); + recurrence_ = null; + } + recurrenceCase_ = 8; + onChanged(); + return weeklyRecurrenceBuilder_; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.BackupSchedule) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.BackupSchedule) + private static final com.google.firestore.admin.v1.BackupSchedule DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.admin.v1.BackupSchedule(); + } + + public static com.google.firestore.admin.v1.BackupSchedule getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public BackupSchedule parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.BackupSchedule getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupScheduleName.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupScheduleName.java new file mode 100644 index 000000000..def9a8fdf --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupScheduleName.java @@ -0,0 +1,227 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.firestore.admin.v1; + +import com.google.api.pathtemplate.PathTemplate; +import com.google.api.resourcenames.ResourceName; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +@Generated("by gapic-generator-java") +public class BackupScheduleName implements ResourceName { + private static final PathTemplate PROJECT_DATABASE_BACKUP_SCHEDULE = + PathTemplate.createWithoutUrlEncoding( + "projects/{project}/databases/{database}/backupSchedules/{backup_schedule}"); + private volatile Map fieldValuesMap; + private final String project; + private final String database; + private final String backupSchedule; + + @Deprecated + protected BackupScheduleName() { + project = null; + database = null; + backupSchedule = null; + } + + private BackupScheduleName(Builder builder) { + project = Preconditions.checkNotNull(builder.getProject()); + database = Preconditions.checkNotNull(builder.getDatabase()); + backupSchedule = Preconditions.checkNotNull(builder.getBackupSchedule()); + } + + public String getProject() { + return project; + } + + public String getDatabase() { + return database; + } + + public String getBackupSchedule() { + return backupSchedule; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + public static BackupScheduleName of(String project, String database, String backupSchedule) { + return newBuilder() + .setProject(project) + .setDatabase(database) + .setBackupSchedule(backupSchedule) + .build(); + } + + public static String format(String project, String database, String backupSchedule) { + return newBuilder() + .setProject(project) + .setDatabase(database) + .setBackupSchedule(backupSchedule) + .build() + .toString(); + } + + public static BackupScheduleName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + Map matchMap = + PROJECT_DATABASE_BACKUP_SCHEDULE.validatedMatch( + formattedString, "BackupScheduleName.parse: formattedString not in valid format"); + return of(matchMap.get("project"), matchMap.get("database"), matchMap.get("backup_schedule")); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList<>(values.size()); + for (BackupScheduleName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return PROJECT_DATABASE_BACKUP_SCHEDULE.matches(formattedString); + } + + @Override + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + if (project != null) { + fieldMapBuilder.put("project", project); + } + if (database != null) { + fieldMapBuilder.put("database", database); + } + if (backupSchedule != null) { + fieldMapBuilder.put("backup_schedule", backupSchedule); + } + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return PROJECT_DATABASE_BACKUP_SCHEDULE.instantiate( + "project", project, "database", database, "backup_schedule", backupSchedule); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o != null && getClass() == o.getClass()) { + BackupScheduleName that = ((BackupScheduleName) o); + return Objects.equals(this.project, that.project) + && Objects.equals(this.database, that.database) + && Objects.equals(this.backupSchedule, that.backupSchedule); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= Objects.hashCode(project); + h *= 1000003; + h ^= Objects.hashCode(database); + h *= 1000003; + h ^= Objects.hashCode(backupSchedule); + return h; + } + + /** Builder for projects/{project}/databases/{database}/backupSchedules/{backup_schedule}. */ + public static class Builder { + private String project; + private String database; + private String backupSchedule; + + protected Builder() {} + + public String getProject() { + return project; + } + + public String getDatabase() { + return database; + } + + public String getBackupSchedule() { + return backupSchedule; + } + + public Builder setProject(String project) { + this.project = project; + return this; + } + + public Builder setDatabase(String database) { + this.database = database; + return this; + } + + public Builder setBackupSchedule(String backupSchedule) { + this.backupSchedule = backupSchedule; + return this; + } + + private Builder(BackupScheduleName backupScheduleName) { + this.project = backupScheduleName.project; + this.database = backupScheduleName.database; + this.backupSchedule = backupScheduleName.backupSchedule; + } + + public BackupScheduleName build() { + return new BackupScheduleName(this); + } + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupScheduleOrBuilder.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupScheduleOrBuilder.java new file mode 100644 index 000000000..d31b3c5c2 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/BackupScheduleOrBuilder.java @@ -0,0 +1,264 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/schedule.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +public interface BackupScheduleOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.BackupSchedule) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * Output only. The unique backup schedule identifier across all locations and
+   * databases for the given project.
+   *
+   * This will be auto-assigned.
+   *
+   * Format is
+   * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+   * 
+ * + * string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The name. + */ + java.lang.String getName(); + /** + * + * + *
+   * Output only. The unique backup schedule identifier across all locations and
+   * databases for the given project.
+   *
+   * This will be auto-assigned.
+   *
+   * Format is
+   * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+   * 
+ * + * string name = 1 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * @return The bytes for name. + */ + com.google.protobuf.ByteString getNameBytes(); + + /** + * + * + *
+   * Output only. The timestamp at which this backup schedule was created and
+   * effective since.
+   *
+   * No backups will be created for this schedule before this time.
+   * 
+ * + * .google.protobuf.Timestamp create_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return Whether the createTime field is set. + */ + boolean hasCreateTime(); + /** + * + * + *
+   * Output only. The timestamp at which this backup schedule was created and
+   * effective since.
+   *
+   * No backups will be created for this schedule before this time.
+   * 
+ * + * .google.protobuf.Timestamp create_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The createTime. + */ + com.google.protobuf.Timestamp getCreateTime(); + /** + * + * + *
+   * Output only. The timestamp at which this backup schedule was created and
+   * effective since.
+   *
+   * No backups will be created for this schedule before this time.
+   * 
+ * + * .google.protobuf.Timestamp create_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + com.google.protobuf.TimestampOrBuilder getCreateTimeOrBuilder(); + + /** + * + * + *
+   * Output only. The timestamp at which this backup schedule was most recently
+   * updated. When a backup schedule is first created, this is the same as
+   * create_time.
+   * 
+ * + * .google.protobuf.Timestamp update_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return Whether the updateTime field is set. + */ + boolean hasUpdateTime(); + /** + * + * + *
+   * Output only. The timestamp at which this backup schedule was most recently
+   * updated. When a backup schedule is first created, this is the same as
+   * create_time.
+   * 
+ * + * .google.protobuf.Timestamp update_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + * + * @return The updateTime. + */ + com.google.protobuf.Timestamp getUpdateTime(); + /** + * + * + *
+   * Output only. The timestamp at which this backup schedule was most recently
+   * updated. When a backup schedule is first created, this is the same as
+   * create_time.
+   * 
+ * + * .google.protobuf.Timestamp update_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * + */ + com.google.protobuf.TimestampOrBuilder getUpdateTimeOrBuilder(); + + /** + * + * + *
+   * At what relative time in the future, compared to its creation time,
+   * the backup should be deleted, e.g. keep backups for 7 days.
+   * 
+ * + * .google.protobuf.Duration retention = 6; + * + * @return Whether the retention field is set. + */ + boolean hasRetention(); + /** + * + * + *
+   * At what relative time in the future, compared to its creation time,
+   * the backup should be deleted, e.g. keep backups for 7 days.
+   * 
+ * + * .google.protobuf.Duration retention = 6; + * + * @return The retention. + */ + com.google.protobuf.Duration getRetention(); + /** + * + * + *
+   * At what relative time in the future, compared to its creation time,
+   * the backup should be deleted, e.g. keep backups for 7 days.
+   * 
+ * + * .google.protobuf.Duration retention = 6; + */ + com.google.protobuf.DurationOrBuilder getRetentionOrBuilder(); + + /** + * + * + *
+   * For a schedule that runs daily.
+   * 
+ * + * .google.firestore.admin.v1.DailyRecurrence daily_recurrence = 7; + * + * @return Whether the dailyRecurrence field is set. + */ + boolean hasDailyRecurrence(); + /** + * + * + *
+   * For a schedule that runs daily.
+   * 
+ * + * .google.firestore.admin.v1.DailyRecurrence daily_recurrence = 7; + * + * @return The dailyRecurrence. + */ + com.google.firestore.admin.v1.DailyRecurrence getDailyRecurrence(); + /** + * + * + *
+   * For a schedule that runs daily.
+   * 
+ * + * .google.firestore.admin.v1.DailyRecurrence daily_recurrence = 7; + */ + com.google.firestore.admin.v1.DailyRecurrenceOrBuilder getDailyRecurrenceOrBuilder(); + + /** + * + * + *
+   * For a schedule that runs weekly on a specific day.
+   * 
+ * + * .google.firestore.admin.v1.WeeklyRecurrence weekly_recurrence = 8; + * + * @return Whether the weeklyRecurrence field is set. + */ + boolean hasWeeklyRecurrence(); + /** + * + * + *
+   * For a schedule that runs weekly on a specific day.
+   * 
+ * + * .google.firestore.admin.v1.WeeklyRecurrence weekly_recurrence = 8; + * + * @return The weeklyRecurrence. + */ + com.google.firestore.admin.v1.WeeklyRecurrence getWeeklyRecurrence(); + /** + * + * + *
+   * For a schedule that runs weekly on a specific day.
+   * 
+ * + * .google.firestore.admin.v1.WeeklyRecurrence weekly_recurrence = 8; + */ + com.google.firestore.admin.v1.WeeklyRecurrenceOrBuilder getWeeklyRecurrenceOrBuilder(); + + com.google.firestore.admin.v1.BackupSchedule.RecurrenceCase getRecurrenceCase(); +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/CollectionGroupName.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/CollectionGroupName.java index e47a9897e..2f22984f8 100644 --- a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/CollectionGroupName.java +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/CollectionGroupName.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/CreateBackupScheduleRequest.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/CreateBackupScheduleRequest.java new file mode 100644 index 000000000..63dbeb830 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/CreateBackupScheduleRequest.java @@ -0,0 +1,962 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +/** + * + * + *
+ * The request for
+ * [FirestoreAdmin.CreateBackupSchedule][google.firestore.admin.v1.FirestoreAdmin.CreateBackupSchedule].
+ * 
+ * + * Protobuf type {@code google.firestore.admin.v1.CreateBackupScheduleRequest} + */ +public final class CreateBackupScheduleRequest extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.CreateBackupScheduleRequest) + CreateBackupScheduleRequestOrBuilder { + private static final long serialVersionUID = 0L; + // Use CreateBackupScheduleRequest.newBuilder() to construct. + private CreateBackupScheduleRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private CreateBackupScheduleRequest() { + parent_ = ""; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new CreateBackupScheduleRequest(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_CreateBackupScheduleRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_CreateBackupScheduleRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.CreateBackupScheduleRequest.class, + com.google.firestore.admin.v1.CreateBackupScheduleRequest.Builder.class); + } + + private int bitField0_; + public static final int PARENT_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile java.lang.Object parent_ = ""; + /** + * + * + *
+   * Required. The parent database.
+   *
+   *  Format `projects/{project}/databases/{database}`
+   * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The parent. + */ + @java.lang.Override + public java.lang.String getParent() { + java.lang.Object ref = parent_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + parent_ = s; + return s; + } + } + /** + * + * + *
+   * Required. The parent database.
+   *
+   *  Format `projects/{project}/databases/{database}`
+   * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for parent. + */ + @java.lang.Override + public com.google.protobuf.ByteString getParentBytes() { + java.lang.Object ref = parent_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + parent_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int BACKUP_SCHEDULE_FIELD_NUMBER = 2; + private com.google.firestore.admin.v1.BackupSchedule backupSchedule_; + /** + * + * + *
+   * Required. The backup schedule to create.
+   * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return Whether the backupSchedule field is set. + */ + @java.lang.Override + public boolean hasBackupSchedule() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * + * + *
+   * Required. The backup schedule to create.
+   * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The backupSchedule. + */ + @java.lang.Override + public com.google.firestore.admin.v1.BackupSchedule getBackupSchedule() { + return backupSchedule_ == null + ? com.google.firestore.admin.v1.BackupSchedule.getDefaultInstance() + : backupSchedule_; + } + /** + * + * + *
+   * Required. The backup schedule to create.
+   * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 2 [(.google.api.field_behavior) = REQUIRED]; + * + */ + @java.lang.Override + public com.google.firestore.admin.v1.BackupScheduleOrBuilder getBackupScheduleOrBuilder() { + return backupSchedule_ == null + ? com.google.firestore.admin.v1.BackupSchedule.getDefaultInstance() + : backupSchedule_; + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(parent_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, parent_); + } + if (((bitField0_ & 0x00000001) != 0)) { + output.writeMessage(2, getBackupSchedule()); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(parent_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, parent_); + } + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(2, getBackupSchedule()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.admin.v1.CreateBackupScheduleRequest)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.CreateBackupScheduleRequest other = + (com.google.firestore.admin.v1.CreateBackupScheduleRequest) obj; + + if (!getParent().equals(other.getParent())) return false; + if (hasBackupSchedule() != other.hasBackupSchedule()) return false; + if (hasBackupSchedule()) { + if (!getBackupSchedule().equals(other.getBackupSchedule())) return false; + } + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + PARENT_FIELD_NUMBER; + hash = (53 * hash) + getParent().hashCode(); + if (hasBackupSchedule()) { + hash = (37 * hash) + BACKUP_SCHEDULE_FIELD_NUMBER; + hash = (53 * hash) + getBackupSchedule().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.CreateBackupScheduleRequest parseFrom( + java.nio.ByteBuffer data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.CreateBackupScheduleRequest parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.CreateBackupScheduleRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.CreateBackupScheduleRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.CreateBackupScheduleRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.CreateBackupScheduleRequest parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.CreateBackupScheduleRequest parseFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.CreateBackupScheduleRequest parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.CreateBackupScheduleRequest parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.CreateBackupScheduleRequest parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.CreateBackupScheduleRequest parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.CreateBackupScheduleRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder( + com.google.firestore.admin.v1.CreateBackupScheduleRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * The request for
+   * [FirestoreAdmin.CreateBackupSchedule][google.firestore.admin.v1.FirestoreAdmin.CreateBackupSchedule].
+   * 
+ * + * Protobuf type {@code google.firestore.admin.v1.CreateBackupScheduleRequest} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.CreateBackupScheduleRequest) + com.google.firestore.admin.v1.CreateBackupScheduleRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_CreateBackupScheduleRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_CreateBackupScheduleRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.CreateBackupScheduleRequest.class, + com.google.firestore.admin.v1.CreateBackupScheduleRequest.Builder.class); + } + + // Construct using com.google.firestore.admin.v1.CreateBackupScheduleRequest.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) { + getBackupScheduleFieldBuilder(); + } + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + parent_ = ""; + backupSchedule_ = null; + if (backupScheduleBuilder_ != null) { + backupScheduleBuilder_.dispose(); + backupScheduleBuilder_ = null; + } + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_CreateBackupScheduleRequest_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.CreateBackupScheduleRequest getDefaultInstanceForType() { + return com.google.firestore.admin.v1.CreateBackupScheduleRequest.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.CreateBackupScheduleRequest build() { + com.google.firestore.admin.v1.CreateBackupScheduleRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.CreateBackupScheduleRequest buildPartial() { + com.google.firestore.admin.v1.CreateBackupScheduleRequest result = + new com.google.firestore.admin.v1.CreateBackupScheduleRequest(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.admin.v1.CreateBackupScheduleRequest result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.parent_ = parent_; + } + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000002) != 0)) { + result.backupSchedule_ = + backupScheduleBuilder_ == null ? backupSchedule_ : backupScheduleBuilder_.build(); + to_bitField0_ |= 0x00000001; + } + result.bitField0_ |= to_bitField0_; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.admin.v1.CreateBackupScheduleRequest) { + return mergeFrom((com.google.firestore.admin.v1.CreateBackupScheduleRequest) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.admin.v1.CreateBackupScheduleRequest other) { + if (other == com.google.firestore.admin.v1.CreateBackupScheduleRequest.getDefaultInstance()) + return this; + if (!other.getParent().isEmpty()) { + parent_ = other.parent_; + bitField0_ |= 0x00000001; + onChanged(); + } + if (other.hasBackupSchedule()) { + mergeBackupSchedule(other.getBackupSchedule()); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + parent_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: + { + input.readMessage(getBackupScheduleFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000002; + break; + } // case 18 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private java.lang.Object parent_ = ""; + /** + * + * + *
+     * Required. The parent database.
+     *
+     *  Format `projects/{project}/databases/{database}`
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The parent. + */ + public java.lang.String getParent() { + java.lang.Object ref = parent_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + parent_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * Required. The parent database.
+     *
+     *  Format `projects/{project}/databases/{database}`
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for parent. + */ + public com.google.protobuf.ByteString getParentBytes() { + java.lang.Object ref = parent_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + parent_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * Required. The parent database.
+     *
+     *  Format `projects/{project}/databases/{database}`
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @param value The parent to set. + * @return This builder for chaining. + */ + public Builder setParent(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + parent_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The parent database.
+     *
+     *  Format `projects/{project}/databases/{database}`
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return This builder for chaining. + */ + public Builder clearParent() { + parent_ = getDefaultInstance().getParent(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The parent database.
+     *
+     *  Format `projects/{project}/databases/{database}`
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @param value The bytes for parent to set. + * @return This builder for chaining. + */ + public Builder setParentBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + parent_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + private com.google.firestore.admin.v1.BackupSchedule backupSchedule_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.BackupSchedule, + com.google.firestore.admin.v1.BackupSchedule.Builder, + com.google.firestore.admin.v1.BackupScheduleOrBuilder> + backupScheduleBuilder_; + /** + * + * + *
+     * Required. The backup schedule to create.
+     * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return Whether the backupSchedule field is set. + */ + public boolean hasBackupSchedule() { + return ((bitField0_ & 0x00000002) != 0); + } + /** + * + * + *
+     * Required. The backup schedule to create.
+     * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The backupSchedule. + */ + public com.google.firestore.admin.v1.BackupSchedule getBackupSchedule() { + if (backupScheduleBuilder_ == null) { + return backupSchedule_ == null + ? com.google.firestore.admin.v1.BackupSchedule.getDefaultInstance() + : backupSchedule_; + } else { + return backupScheduleBuilder_.getMessage(); + } + } + /** + * + * + *
+     * Required. The backup schedule to create.
+     * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 2 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder setBackupSchedule(com.google.firestore.admin.v1.BackupSchedule value) { + if (backupScheduleBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + backupSchedule_ = value; + } else { + backupScheduleBuilder_.setMessage(value); + } + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The backup schedule to create.
+     * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 2 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder setBackupSchedule( + com.google.firestore.admin.v1.BackupSchedule.Builder builderForValue) { + if (backupScheduleBuilder_ == null) { + backupSchedule_ = builderForValue.build(); + } else { + backupScheduleBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The backup schedule to create.
+     * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 2 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder mergeBackupSchedule(com.google.firestore.admin.v1.BackupSchedule value) { + if (backupScheduleBuilder_ == null) { + if (((bitField0_ & 0x00000002) != 0) + && backupSchedule_ != null + && backupSchedule_ + != com.google.firestore.admin.v1.BackupSchedule.getDefaultInstance()) { + getBackupScheduleBuilder().mergeFrom(value); + } else { + backupSchedule_ = value; + } + } else { + backupScheduleBuilder_.mergeFrom(value); + } + if (backupSchedule_ != null) { + bitField0_ |= 0x00000002; + onChanged(); + } + return this; + } + /** + * + * + *
+     * Required. The backup schedule to create.
+     * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 2 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder clearBackupSchedule() { + bitField0_ = (bitField0_ & ~0x00000002); + backupSchedule_ = null; + if (backupScheduleBuilder_ != null) { + backupScheduleBuilder_.dispose(); + backupScheduleBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The backup schedule to create.
+     * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 2 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public com.google.firestore.admin.v1.BackupSchedule.Builder getBackupScheduleBuilder() { + bitField0_ |= 0x00000002; + onChanged(); + return getBackupScheduleFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * Required. The backup schedule to create.
+     * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 2 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public com.google.firestore.admin.v1.BackupScheduleOrBuilder getBackupScheduleOrBuilder() { + if (backupScheduleBuilder_ != null) { + return backupScheduleBuilder_.getMessageOrBuilder(); + } else { + return backupSchedule_ == null + ? com.google.firestore.admin.v1.BackupSchedule.getDefaultInstance() + : backupSchedule_; + } + } + /** + * + * + *
+     * Required. The backup schedule to create.
+     * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 2 [(.google.api.field_behavior) = REQUIRED]; + * + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.BackupSchedule, + com.google.firestore.admin.v1.BackupSchedule.Builder, + com.google.firestore.admin.v1.BackupScheduleOrBuilder> + getBackupScheduleFieldBuilder() { + if (backupScheduleBuilder_ == null) { + backupScheduleBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.BackupSchedule, + com.google.firestore.admin.v1.BackupSchedule.Builder, + com.google.firestore.admin.v1.BackupScheduleOrBuilder>( + getBackupSchedule(), getParentForChildren(), isClean()); + backupSchedule_ = null; + } + return backupScheduleBuilder_; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.CreateBackupScheduleRequest) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.CreateBackupScheduleRequest) + private static final com.google.firestore.admin.v1.CreateBackupScheduleRequest DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.admin.v1.CreateBackupScheduleRequest(); + } + + public static com.google.firestore.admin.v1.CreateBackupScheduleRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public CreateBackupScheduleRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.CreateBackupScheduleRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/CreateBackupScheduleRequestOrBuilder.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/CreateBackupScheduleRequestOrBuilder.java new file mode 100644 index 000000000..d5402d0e4 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/CreateBackupScheduleRequestOrBuilder.java @@ -0,0 +1,100 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +public interface CreateBackupScheduleRequestOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.CreateBackupScheduleRequest) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * Required. The parent database.
+   *
+   *  Format `projects/{project}/databases/{database}`
+   * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The parent. + */ + java.lang.String getParent(); + /** + * + * + *
+   * Required. The parent database.
+   *
+   *  Format `projects/{project}/databases/{database}`
+   * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for parent. + */ + com.google.protobuf.ByteString getParentBytes(); + + /** + * + * + *
+   * Required. The backup schedule to create.
+   * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return Whether the backupSchedule field is set. + */ + boolean hasBackupSchedule(); + /** + * + * + *
+   * Required. The backup schedule to create.
+   * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The backupSchedule. + */ + com.google.firestore.admin.v1.BackupSchedule getBackupSchedule(); + /** + * + * + *
+   * Required. The backup schedule to create.
+   * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 2 [(.google.api.field_behavior) = REQUIRED]; + * + */ + com.google.firestore.admin.v1.BackupScheduleOrBuilder getBackupScheduleOrBuilder(); +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DailyRecurrence.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DailyRecurrence.java new file mode 100644 index 000000000..8b21cbc67 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DailyRecurrence.java @@ -0,0 +1,435 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/schedule.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +/** + * + * + *
+ * Represents a recurring schedule that runs at a specific time every day.
+ *
+ * The time zone is UTC.
+ * 
+ * + * Protobuf type {@code google.firestore.admin.v1.DailyRecurrence} + */ +public final class DailyRecurrence extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.DailyRecurrence) + DailyRecurrenceOrBuilder { + private static final long serialVersionUID = 0L; + // Use DailyRecurrence.newBuilder() to construct. + private DailyRecurrence(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private DailyRecurrence() {} + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new DailyRecurrence(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.ScheduleProto + .internal_static_google_firestore_admin_v1_DailyRecurrence_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.ScheduleProto + .internal_static_google_firestore_admin_v1_DailyRecurrence_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.DailyRecurrence.class, + com.google.firestore.admin.v1.DailyRecurrence.Builder.class); + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.admin.v1.DailyRecurrence)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.DailyRecurrence other = + (com.google.firestore.admin.v1.DailyRecurrence) obj; + + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.DailyRecurrence parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.DailyRecurrence parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.DailyRecurrence parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.DailyRecurrence parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.DailyRecurrence parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.DailyRecurrence parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.DailyRecurrence parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.DailyRecurrence parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.DailyRecurrence parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.DailyRecurrence parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.DailyRecurrence parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.DailyRecurrence parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.admin.v1.DailyRecurrence prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * Represents a recurring schedule that runs at a specific time every day.
+   *
+   * The time zone is UTC.
+   * 
+ * + * Protobuf type {@code google.firestore.admin.v1.DailyRecurrence} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.DailyRecurrence) + com.google.firestore.admin.v1.DailyRecurrenceOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.ScheduleProto + .internal_static_google_firestore_admin_v1_DailyRecurrence_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.ScheduleProto + .internal_static_google_firestore_admin_v1_DailyRecurrence_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.DailyRecurrence.class, + com.google.firestore.admin.v1.DailyRecurrence.Builder.class); + } + + // Construct using com.google.firestore.admin.v1.DailyRecurrence.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.ScheduleProto + .internal_static_google_firestore_admin_v1_DailyRecurrence_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.DailyRecurrence getDefaultInstanceForType() { + return com.google.firestore.admin.v1.DailyRecurrence.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.DailyRecurrence build() { + com.google.firestore.admin.v1.DailyRecurrence result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.DailyRecurrence buildPartial() { + com.google.firestore.admin.v1.DailyRecurrence result = + new com.google.firestore.admin.v1.DailyRecurrence(this); + onBuilt(); + return result; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.admin.v1.DailyRecurrence) { + return mergeFrom((com.google.firestore.admin.v1.DailyRecurrence) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.admin.v1.DailyRecurrence other) { + if (other == com.google.firestore.admin.v1.DailyRecurrence.getDefaultInstance()) return this; + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.DailyRecurrence) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.DailyRecurrence) + private static final com.google.firestore.admin.v1.DailyRecurrence DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.admin.v1.DailyRecurrence(); + } + + public static com.google.firestore.admin.v1.DailyRecurrence getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public DailyRecurrence parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.DailyRecurrence getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DailyRecurrenceOrBuilder.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DailyRecurrenceOrBuilder.java new file mode 100644 index 000000000..750956a9b --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DailyRecurrenceOrBuilder.java @@ -0,0 +1,25 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/schedule.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +public interface DailyRecurrenceOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.DailyRecurrence) + com.google.protobuf.MessageOrBuilder {} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DatabaseName.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DatabaseName.java index abb5866cd..259990803 100644 --- a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DatabaseName.java +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DatabaseName.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DatabaseProto.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DatabaseProto.java index d3f36bb80..7cd1e2643 100644 --- a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DatabaseProto.java +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DatabaseProto.java @@ -45,50 +45,50 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + "to\022\031google.firestore.admin.v1\032\037google/ap" + "i/field_behavior.proto\032\031google/api/resou" + "rce.proto\032\036google/protobuf/duration.prot" - + "o\032\037google/protobuf/timestamp.proto\"\277\013\n\010D" - + "atabase\022\014\n\004name\030\001 \001(\t\022\021\n\003uid\030\003 \001(\tB\004\342A\001\003" - + "\0225\n\013create_time\030\005 \001(\0132\032.google.protobuf." - + "TimestampB\004\342A\001\003\0225\n\013update_time\030\006 \001(\0132\032.g" - + "oogle.protobuf.TimestampB\004\342A\001\003\022\023\n\013locati" - + "on_id\030\t \001(\t\022>\n\004type\030\n \001(\01620.google.fires" - + "tore.admin.v1.Database.DatabaseType\022M\n\020c" - + "oncurrency_mode\030\017 \001(\01623.google.firestore" - + ".admin.v1.Database.ConcurrencyMode\022A\n\030ve" - + "rsion_retention_period\030\021 \001(\0132\031.google.pr" - + "otobuf.DurationB\004\342A\001\003\022?\n\025earliest_versio" - + "n_time\030\022 \001(\0132\032.google.protobuf.Timestamp" - + "B\004\342A\001\003\022l\n!point_in_time_recovery_enablem" - + "ent\030\025 \001(\0162A.google.firestore.admin.v1.Da" - + "tabase.PointInTimeRecoveryEnablement\022a\n\033" - + "app_engine_integration_mode\030\023 \001(\0162<.goog" - + "le.firestore.admin.v1.Database.AppEngine" - + "IntegrationMode\022\030\n\nkey_prefix\030\024 \001(\tB\004\342A\001" - + "\003\022Z\n\027delete_protection_state\030\026 \001(\01629.goo" - + "gle.firestore.admin.v1.Database.DeletePr" - + "otectionState\022\014\n\004etag\030c \001(\t\"W\n\014DatabaseT" - + "ype\022\035\n\031DATABASE_TYPE_UNSPECIFIED\020\000\022\024\n\020FI" - + "RESTORE_NATIVE\020\001\022\022\n\016DATASTORE_MODE\020\002\"w\n\017" - + "ConcurrencyMode\022 \n\034CONCURRENCY_MODE_UNSP" - + "ECIFIED\020\000\022\016\n\nOPTIMISTIC\020\001\022\017\n\013PESSIMISTIC" - + "\020\002\022!\n\035OPTIMISTIC_WITH_ENTITY_GROUPS\020\003\"\233\001" - + "\n\035PointInTimeRecoveryEnablement\0221\n-POINT" - + "_IN_TIME_RECOVERY_ENABLEMENT_UNSPECIFIED" - + "\020\000\022\"\n\036POINT_IN_TIME_RECOVERY_ENABLED\020\001\022#" - + "\n\037POINT_IN_TIME_RECOVERY_DISABLED\020\002\"b\n\030A" - + "ppEngineIntegrationMode\022+\n\'APP_ENGINE_IN" - + "TEGRATION_MODE_UNSPECIFIED\020\000\022\013\n\007ENABLED\020" - + "\001\022\014\n\010DISABLED\020\002\"\177\n\025DeleteProtectionState" - + "\022\'\n#DELETE_PROTECTION_STATE_UNSPECIFIED\020" - + "\000\022\036\n\032DELETE_PROTECTION_DISABLED\020\001\022\035\n\031DEL" - + "ETE_PROTECTION_ENABLED\020\002:R\352AO\n!firestore" - + ".googleapis.com/Database\022\'projects/{proj" - + "ect}/databases/{database}R\001\001B\334\001\n\035com.goo" - + "gle.firestore.admin.v1B\rDatabaseProtoP\001Z" - + "9cloud.google.com/go/firestore/apiv1/adm" - + "in/adminpb;adminpb\242\002\004GCFS\252\002\037Google.Cloud" - + ".Firestore.Admin.V1\312\002\037Google\\Cloud\\Fires" - + "tore\\Admin\\V1\352\002#Google::Cloud::Firestore" - + "::Admin::V1b\006proto3" + + "o\032\037google/protobuf/timestamp.proto\"\271\013\n\010D" + + "atabase\022\014\n\004name\030\001 \001(\t\022\020\n\003uid\030\003 \001(\tB\003\340A\003\022" + + "4\n\013create_time\030\005 \001(\0132\032.google.protobuf.T" + + "imestampB\003\340A\003\0224\n\013update_time\030\006 \001(\0132\032.goo" + + "gle.protobuf.TimestampB\003\340A\003\022\023\n\013location_" + + "id\030\t \001(\t\022>\n\004type\030\n \001(\01620.google.firestor" + + "e.admin.v1.Database.DatabaseType\022M\n\020conc" + + "urrency_mode\030\017 \001(\01623.google.firestore.ad" + + "min.v1.Database.ConcurrencyMode\022@\n\030versi" + + "on_retention_period\030\021 \001(\0132\031.google.proto" + + "buf.DurationB\003\340A\003\022>\n\025earliest_version_ti" + + "me\030\022 \001(\0132\032.google.protobuf.TimestampB\003\340A" + + "\003\022l\n!point_in_time_recovery_enablement\030\025" + + " \001(\0162A.google.firestore.admin.v1.Databas" + + "e.PointInTimeRecoveryEnablement\022a\n\033app_e" + + "ngine_integration_mode\030\023 \001(\0162<.google.fi" + + "restore.admin.v1.Database.AppEngineInteg" + + "rationMode\022\027\n\nkey_prefix\030\024 \001(\tB\003\340A\003\022Z\n\027d" + + "elete_protection_state\030\026 \001(\01629.google.fi" + + "restore.admin.v1.Database.DeleteProtecti" + + "onState\022\014\n\004etag\030c \001(\t\"W\n\014DatabaseType\022\035\n" + + "\031DATABASE_TYPE_UNSPECIFIED\020\000\022\024\n\020FIRESTOR" + + "E_NATIVE\020\001\022\022\n\016DATASTORE_MODE\020\002\"w\n\017Concur" + + "rencyMode\022 \n\034CONCURRENCY_MODE_UNSPECIFIE" + + "D\020\000\022\016\n\nOPTIMISTIC\020\001\022\017\n\013PESSIMISTIC\020\002\022!\n\035" + + "OPTIMISTIC_WITH_ENTITY_GROUPS\020\003\"\233\001\n\035Poin" + + "tInTimeRecoveryEnablement\0221\n-POINT_IN_TI" + + "ME_RECOVERY_ENABLEMENT_UNSPECIFIED\020\000\022\"\n\036" + + "POINT_IN_TIME_RECOVERY_ENABLED\020\001\022#\n\037POIN" + + "T_IN_TIME_RECOVERY_DISABLED\020\002\"b\n\030AppEngi" + + "neIntegrationMode\022+\n\'APP_ENGINE_INTEGRAT" + + "ION_MODE_UNSPECIFIED\020\000\022\013\n\007ENABLED\020\001\022\014\n\010D" + + "ISABLED\020\002\"\177\n\025DeleteProtectionState\022\'\n#DE" + + "LETE_PROTECTION_STATE_UNSPECIFIED\020\000\022\036\n\032D" + + "ELETE_PROTECTION_DISABLED\020\001\022\035\n\031DELETE_PR" + + "OTECTION_ENABLED\020\002:R\352AO\n!firestore.googl" + + "eapis.com/Database\022\'projects/{project}/d" + + "atabases/{database}R\001\001B\334\001\n\035com.google.fi" + + "restore.admin.v1B\rDatabaseProtoP\001Z9cloud" + + ".google.com/go/firestore/apiv1/admin/adm" + + "inpb;adminpb\242\002\004GCFS\252\002\037Google.Cloud.Fires" + + "tore.Admin.V1\312\002\037Google\\Cloud\\Firestore\\A" + + "dmin\\V1\352\002#Google::Cloud::Firestore::Admi" + + "n::V1b\006proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DeleteBackupRequest.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DeleteBackupRequest.java new file mode 100644 index 000000000..e4643bb90 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DeleteBackupRequest.java @@ -0,0 +1,655 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +/** + * + * + *
+ * The request for
+ * [FirestoreAdmin.DeleteBackup][google.firestore.admin.v1.FirestoreAdmin.DeleteBackup].
+ * 
+ * + * Protobuf type {@code google.firestore.admin.v1.DeleteBackupRequest} + */ +public final class DeleteBackupRequest extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.DeleteBackupRequest) + DeleteBackupRequestOrBuilder { + private static final long serialVersionUID = 0L; + // Use DeleteBackupRequest.newBuilder() to construct. + private DeleteBackupRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private DeleteBackupRequest() { + name_ = ""; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new DeleteBackupRequest(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_DeleteBackupRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_DeleteBackupRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.DeleteBackupRequest.class, + com.google.firestore.admin.v1.DeleteBackupRequest.Builder.class); + } + + public static final int NAME_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile java.lang.Object name_ = ""; + /** + * + * + *
+   * Required. Name of the backup to delete.
+   *
+   * format is `projects/{project}/locations/{location}/backups/{backup}`.
+   * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } + } + /** + * + * + *
+   * Required. Name of the backup to delete.
+   *
+   * format is `projects/{project}/locations/{location}/backups/{backup}`.
+   * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.admin.v1.DeleteBackupRequest)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.DeleteBackupRequest other = + (com.google.firestore.admin.v1.DeleteBackupRequest) obj; + + if (!getName().equals(other.getName())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + NAME_FIELD_NUMBER; + hash = (53 * hash) + getName().hashCode(); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.DeleteBackupRequest parseFrom( + java.nio.ByteBuffer data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.DeleteBackupRequest parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.DeleteBackupRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.DeleteBackupRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.DeleteBackupRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.DeleteBackupRequest parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.DeleteBackupRequest parseFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.DeleteBackupRequest parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.DeleteBackupRequest parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.DeleteBackupRequest parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.DeleteBackupRequest parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.DeleteBackupRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.admin.v1.DeleteBackupRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * The request for
+   * [FirestoreAdmin.DeleteBackup][google.firestore.admin.v1.FirestoreAdmin.DeleteBackup].
+   * 
+ * + * Protobuf type {@code google.firestore.admin.v1.DeleteBackupRequest} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.DeleteBackupRequest) + com.google.firestore.admin.v1.DeleteBackupRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_DeleteBackupRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_DeleteBackupRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.DeleteBackupRequest.class, + com.google.firestore.admin.v1.DeleteBackupRequest.Builder.class); + } + + // Construct using com.google.firestore.admin.v1.DeleteBackupRequest.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + name_ = ""; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_DeleteBackupRequest_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.DeleteBackupRequest getDefaultInstanceForType() { + return com.google.firestore.admin.v1.DeleteBackupRequest.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.DeleteBackupRequest build() { + com.google.firestore.admin.v1.DeleteBackupRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.DeleteBackupRequest buildPartial() { + com.google.firestore.admin.v1.DeleteBackupRequest result = + new com.google.firestore.admin.v1.DeleteBackupRequest(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.admin.v1.DeleteBackupRequest result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.name_ = name_; + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.admin.v1.DeleteBackupRequest) { + return mergeFrom((com.google.firestore.admin.v1.DeleteBackupRequest) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.admin.v1.DeleteBackupRequest other) { + if (other == com.google.firestore.admin.v1.DeleteBackupRequest.getDefaultInstance()) + return this; + if (!other.getName().isEmpty()) { + name_ = other.name_; + bitField0_ |= 0x00000001; + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + name_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private java.lang.Object name_ = ""; + /** + * + * + *
+     * Required. Name of the backup to delete.
+     *
+     * format is `projects/{project}/locations/{location}/backups/{backup}`.
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The name. + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * Required. Name of the backup to delete.
+     *
+     * format is `projects/{project}/locations/{location}/backups/{backup}`.
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for name. + */ + public com.google.protobuf.ByteString getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * Required. Name of the backup to delete.
+     *
+     * format is `projects/{project}/locations/{location}/backups/{backup}`.
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * Required. Name of the backup to delete.
+     *
+     * format is `projects/{project}/locations/{location}/backups/{backup}`.
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return This builder for chaining. + */ + public Builder clearName() { + name_ = getDefaultInstance().getName(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + /** + * + * + *
+     * Required. Name of the backup to delete.
+     *
+     * format is `projects/{project}/locations/{location}/backups/{backup}`.
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.DeleteBackupRequest) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.DeleteBackupRequest) + private static final com.google.firestore.admin.v1.DeleteBackupRequest DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.admin.v1.DeleteBackupRequest(); + } + + public static com.google.firestore.admin.v1.DeleteBackupRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public DeleteBackupRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.DeleteBackupRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DeleteBackupRequestOrBuilder.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DeleteBackupRequestOrBuilder.java new file mode 100644 index 000000000..40dcbef62 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DeleteBackupRequestOrBuilder.java @@ -0,0 +1,59 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +public interface DeleteBackupRequestOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.DeleteBackupRequest) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * Required. Name of the backup to delete.
+   *
+   * format is `projects/{project}/locations/{location}/backups/{backup}`.
+   * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The name. + */ + java.lang.String getName(); + /** + * + * + *
+   * Required. Name of the backup to delete.
+   *
+   * format is `projects/{project}/locations/{location}/backups/{backup}`.
+   * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for name. + */ + com.google.protobuf.ByteString getNameBytes(); +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DeleteBackupScheduleRequest.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DeleteBackupScheduleRequest.java new file mode 100644 index 000000000..b17dc9415 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DeleteBackupScheduleRequest.java @@ -0,0 +1,661 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +/** + * + * + *
+ * The request for [FirestoreAdmin.DeleteBackupSchedules][].
+ * 
+ * + * Protobuf type {@code google.firestore.admin.v1.DeleteBackupScheduleRequest} + */ +public final class DeleteBackupScheduleRequest extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.DeleteBackupScheduleRequest) + DeleteBackupScheduleRequestOrBuilder { + private static final long serialVersionUID = 0L; + // Use DeleteBackupScheduleRequest.newBuilder() to construct. + private DeleteBackupScheduleRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private DeleteBackupScheduleRequest() { + name_ = ""; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new DeleteBackupScheduleRequest(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_DeleteBackupScheduleRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_DeleteBackupScheduleRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.DeleteBackupScheduleRequest.class, + com.google.firestore.admin.v1.DeleteBackupScheduleRequest.Builder.class); + } + + public static final int NAME_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile java.lang.Object name_ = ""; + /** + * + * + *
+   * Required. The name of the backup schedule.
+   *
+   * Format
+   * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+   * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } + } + /** + * + * + *
+   * Required. The name of the backup schedule.
+   *
+   * Format
+   * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+   * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.admin.v1.DeleteBackupScheduleRequest)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.DeleteBackupScheduleRequest other = + (com.google.firestore.admin.v1.DeleteBackupScheduleRequest) obj; + + if (!getName().equals(other.getName())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + NAME_FIELD_NUMBER; + hash = (53 * hash) + getName().hashCode(); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.DeleteBackupScheduleRequest parseFrom( + java.nio.ByteBuffer data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.DeleteBackupScheduleRequest parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.DeleteBackupScheduleRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.DeleteBackupScheduleRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.DeleteBackupScheduleRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.DeleteBackupScheduleRequest parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.DeleteBackupScheduleRequest parseFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.DeleteBackupScheduleRequest parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.DeleteBackupScheduleRequest parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.DeleteBackupScheduleRequest parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.DeleteBackupScheduleRequest parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.DeleteBackupScheduleRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder( + com.google.firestore.admin.v1.DeleteBackupScheduleRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * The request for [FirestoreAdmin.DeleteBackupSchedules][].
+   * 
+ * + * Protobuf type {@code google.firestore.admin.v1.DeleteBackupScheduleRequest} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.DeleteBackupScheduleRequest) + com.google.firestore.admin.v1.DeleteBackupScheduleRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_DeleteBackupScheduleRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_DeleteBackupScheduleRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.DeleteBackupScheduleRequest.class, + com.google.firestore.admin.v1.DeleteBackupScheduleRequest.Builder.class); + } + + // Construct using com.google.firestore.admin.v1.DeleteBackupScheduleRequest.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + name_ = ""; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_DeleteBackupScheduleRequest_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.DeleteBackupScheduleRequest getDefaultInstanceForType() { + return com.google.firestore.admin.v1.DeleteBackupScheduleRequest.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.DeleteBackupScheduleRequest build() { + com.google.firestore.admin.v1.DeleteBackupScheduleRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.DeleteBackupScheduleRequest buildPartial() { + com.google.firestore.admin.v1.DeleteBackupScheduleRequest result = + new com.google.firestore.admin.v1.DeleteBackupScheduleRequest(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.admin.v1.DeleteBackupScheduleRequest result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.name_ = name_; + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.admin.v1.DeleteBackupScheduleRequest) { + return mergeFrom((com.google.firestore.admin.v1.DeleteBackupScheduleRequest) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.admin.v1.DeleteBackupScheduleRequest other) { + if (other == com.google.firestore.admin.v1.DeleteBackupScheduleRequest.getDefaultInstance()) + return this; + if (!other.getName().isEmpty()) { + name_ = other.name_; + bitField0_ |= 0x00000001; + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + name_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private java.lang.Object name_ = ""; + /** + * + * + *
+     * Required. The name of the backup schedule.
+     *
+     * Format
+     * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The name. + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * Required. The name of the backup schedule.
+     *
+     * Format
+     * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for name. + */ + public com.google.protobuf.ByteString getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * Required. The name of the backup schedule.
+     *
+     * Format
+     * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The name of the backup schedule.
+     *
+     * Format
+     * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return This builder for chaining. + */ + public Builder clearName() { + name_ = getDefaultInstance().getName(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The name of the backup schedule.
+     *
+     * Format
+     * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.DeleteBackupScheduleRequest) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.DeleteBackupScheduleRequest) + private static final com.google.firestore.admin.v1.DeleteBackupScheduleRequest DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.admin.v1.DeleteBackupScheduleRequest(); + } + + public static com.google.firestore.admin.v1.DeleteBackupScheduleRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public DeleteBackupScheduleRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.DeleteBackupScheduleRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DeleteBackupScheduleRequestOrBuilder.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DeleteBackupScheduleRequestOrBuilder.java new file mode 100644 index 000000000..3844da9fd --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/DeleteBackupScheduleRequestOrBuilder.java @@ -0,0 +1,61 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +public interface DeleteBackupScheduleRequestOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.DeleteBackupScheduleRequest) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * Required. The name of the backup schedule.
+   *
+   * Format
+   * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+   * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The name. + */ + java.lang.String getName(); + /** + * + * + *
+   * Required. The name of the backup schedule.
+   *
+   * Format
+   * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+   * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for name. + */ + com.google.protobuf.ByteString getNameBytes(); +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/FieldName.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/FieldName.java index 88ac00009..d66a39319 100644 --- a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/FieldName.java +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/FieldName.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/FieldProto.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/FieldProto.java index aacd40e4a..d3f999dbd 100644 --- a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/FieldProto.java +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/FieldProto.java @@ -53,27 +53,27 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + "\031google.firestore.admin.v1\032\037google/api/f" + "ield_behavior.proto\032\031google/api/resource" + ".proto\032%google/firestore/admin/v1/index." - + "proto\"\307\004\n\005Field\022\022\n\004name\030\001 \001(\tB\004\342A\001\002\022B\n\014i" - + "ndex_config\030\002 \001(\0132,.google.firestore.adm" - + "in.v1.Field.IndexConfig\022>\n\nttl_config\030\003 " - + "\001(\0132*.google.firestore.admin.v1.Field.Tt" - + "lConfig\032\211\001\n\013IndexConfig\0221\n\007indexes\030\001 \003(\013" - + "2 .google.firestore.admin.v1.Index\022\034\n\024us" - + "es_ancestor_config\030\002 \001(\010\022\026\n\016ancestor_fie" - + "ld\030\003 \001(\t\022\021\n\treverting\030\004 \001(\010\032\236\001\n\tTtlConfi" - + "g\022E\n\005state\030\001 \001(\01620.google.firestore.admi" - + "n.v1.Field.TtlConfig.StateB\004\342A\001\003\"J\n\005Stat" - + "e\022\025\n\021STATE_UNSPECIFIED\020\000\022\014\n\010CREATING\020\001\022\n" - + "\n\006ACTIVE\020\002\022\020\n\014NEEDS_REPAIR\020\003:y\352Av\n\036fires" - + "tore.googleapis.com/Field\022Tprojects/{pro" - + "ject}/databases/{database}/collectionGro" - + "ups/{collection}/fields/{field}B\331\001\n\035com." - + "google.firestore.admin.v1B\nFieldProtoP\001Z" - + "9cloud.google.com/go/firestore/apiv1/adm" - + "in/adminpb;adminpb\242\002\004GCFS\252\002\037Google.Cloud" - + ".Firestore.Admin.V1\312\002\037Google\\Cloud\\Fires" - + "tore\\Admin\\V1\352\002#Google::Cloud::Firestore" - + "::Admin::V1b\006proto3" + + "proto\"\305\004\n\005Field\022\021\n\004name\030\001 \001(\tB\003\340A\002\022B\n\014in" + + "dex_config\030\002 \001(\0132,.google.firestore.admi" + + "n.v1.Field.IndexConfig\022>\n\nttl_config\030\003 \001" + + "(\0132*.google.firestore.admin.v1.Field.Ttl" + + "Config\032\211\001\n\013IndexConfig\0221\n\007indexes\030\001 \003(\0132" + + " .google.firestore.admin.v1.Index\022\034\n\024use" + + "s_ancestor_config\030\002 \001(\010\022\026\n\016ancestor_fiel" + + "d\030\003 \001(\t\022\021\n\treverting\030\004 \001(\010\032\235\001\n\tTtlConfig" + + "\022D\n\005state\030\001 \001(\01620.google.firestore.admin" + + ".v1.Field.TtlConfig.StateB\003\340A\003\"J\n\005State\022" + + "\025\n\021STATE_UNSPECIFIED\020\000\022\014\n\010CREATING\020\001\022\n\n\006" + + "ACTIVE\020\002\022\020\n\014NEEDS_REPAIR\020\003:y\352Av\n\036firesto" + + "re.googleapis.com/Field\022Tprojects/{proje" + + "ct}/databases/{database}/collectionGroup" + + "s/{collection}/fields/{field}B\331\001\n\035com.go" + + "ogle.firestore.admin.v1B\nFieldProtoP\001Z9c" + + "loud.google.com/go/firestore/apiv1/admin" + + "/adminpb;adminpb\242\002\004GCFS\252\002\037Google.Cloud.F" + + "irestore.Admin.V1\312\002\037Google\\Cloud\\Firesto" + + "re\\Admin\\V1\352\002#Google::Cloud::Firestore::" + + "Admin::V1b\006proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/FirestoreAdminProto.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/FirestoreAdminProto.java index 72ccb2c98..224144533 100644 --- a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/FirestoreAdminProto.java +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/FirestoreAdminProto.java @@ -64,6 +64,30 @@ public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry r internal_static_google_firestore_admin_v1_DeleteDatabaseMetadata_descriptor; static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_google_firestore_admin_v1_DeleteDatabaseMetadata_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_CreateBackupScheduleRequest_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_CreateBackupScheduleRequest_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_GetBackupScheduleRequest_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_GetBackupScheduleRequest_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_UpdateBackupScheduleRequest_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_UpdateBackupScheduleRequest_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_ListBackupSchedulesRequest_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_ListBackupSchedulesRequest_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_ListBackupSchedulesResponse_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_ListBackupSchedulesResponse_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_DeleteBackupScheduleRequest_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_DeleteBackupScheduleRequest_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_firestore_admin_v1_CreateIndexRequest_descriptor; static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable @@ -108,6 +132,26 @@ public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry r internal_static_google_firestore_admin_v1_ImportDocumentsRequest_descriptor; static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_google_firestore_admin_v1_ImportDocumentsRequest_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_GetBackupRequest_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_GetBackupRequest_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_ListBackupsRequest_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_ListBackupsRequest_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_ListBackupsResponse_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_ListBackupsResponse_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_DeleteBackupRequest_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_DeleteBackupRequest_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_RestoreDatabaseRequest_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_RestoreDatabaseRequest_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { return descriptor; @@ -121,149 +165,224 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + "min.proto\022\031google.firestore.admin.v1\032\034go" + "ogle/api/annotations.proto\032\027google/api/c" + "lient.proto\032\037google/api/field_behavior.p" - + "roto\032\031google/api/resource.proto\032(google/" + + "roto\032\031google/api/resource.proto\032&google/" + + "firestore/admin/v1/backup.proto\032(google/" + "firestore/admin/v1/database.proto\032%googl" + "e/firestore/admin/v1/field.proto\032%google" + "/firestore/admin/v1/index.proto\032)google/" - + "firestore/admin/v1/operation.proto\032#goog" - + "le/longrunning/operations.proto\032\033google/" - + "protobuf/empty.proto\032 google/protobuf/fi" - + "eld_mask.proto\032\037google/protobuf/timestam" - + "p.proto\"R\n\024ListDatabasesRequest\022:\n\006paren" - + "t\030\001 \001(\tB*\342A\001\002\372A#\022!firestore.googleapis.c" - + "om/Database\"\253\001\n\025CreateDatabaseRequest\022:\n" - + "\006parent\030\001 \001(\tB*\342A\001\002\372A#\022!firestore.google" - + "apis.com/Database\022;\n\010database\030\002 \001(\0132#.go" - + "ogle.firestore.admin.v1.DatabaseB\004\342A\001\002\022\031" - + "\n\013database_id\030\003 \001(\tB\004\342A\001\002\"\030\n\026CreateDatab" - + "aseMetadata\"d\n\025ListDatabasesResponse\0226\n\t" - + "databases\030\001 \003(\0132#.google.firestore.admin" - + ".v1.Database\022\023\n\013unreachable\030\003 \003(\t\"N\n\022Get" - + "DatabaseRequest\0228\n\004name\030\001 \001(\tB*\342A\001\002\372A#\n!" - + "firestore.googleapis.com/Database\"\205\001\n\025Up" - + "dateDatabaseRequest\022;\n\010database\030\001 \001(\0132#." - + "google.firestore.admin.v1.DatabaseB\004\342A\001\002" - + "\022/\n\013update_mask\030\002 \001(\0132\032.google.protobuf." - + "FieldMask\"\030\n\026UpdateDatabaseMetadata\"_\n\025D" - + "eleteDatabaseRequest\0228\n\004name\030\001 \001(\tB*\342A\001\002" - + "\372A#\n!firestore.googleapis.com/Database\022\014" - + "\n\004etag\030\003 \001(\t\"\030\n\026DeleteDatabaseMetadata\"\216" - + "\001\n\022CreateIndexRequest\022A\n\006parent\030\001 \001(\tB1\342" - + "A\001\002\372A*\n(firestore.googleapis.com/Collect" - + "ionGroup\0225\n\005index\030\002 \001(\0132 .google.firesto" - + "re.admin.v1.IndexB\004\342A\001\002\"\216\001\n\022ListIndexesR" - + "equest\022A\n\006parent\030\001 \001(\tB1\342A\001\002\372A*\n(firesto" - + "re.googleapis.com/CollectionGroup\022\016\n\006fil" - + "ter\030\002 \001(\t\022\021\n\tpage_size\030\003 \001(\005\022\022\n\npage_tok" - + "en\030\004 \001(\t\"a\n\023ListIndexesResponse\0221\n\007index" - + "es\030\001 \003(\0132 .google.firestore.admin.v1.Ind" - + "ex\022\027\n\017next_page_token\030\002 \001(\t\"H\n\017GetIndexR" - + "equest\0225\n\004name\030\001 \001(\tB\'\342A\001\002\372A \n\036firestore" - + ".googleapis.com/Index\"K\n\022DeleteIndexRequ" - + "est\0225\n\004name\030\001 \001(\tB\'\342A\001\002\372A \n\036firestore.go" - + "ogleapis.com/Index\"|\n\022UpdateFieldRequest" - + "\0225\n\005field\030\001 \001(\0132 .google.firestore.admin" - + ".v1.FieldB\004\342A\001\002\022/\n\013update_mask\030\002 \001(\0132\032.g" - + "oogle.protobuf.FieldMask\"H\n\017GetFieldRequ" - + "est\0225\n\004name\030\001 \001(\tB\'\342A\001\002\372A \n\036firestore.go" - + "ogleapis.com/Field\"\215\001\n\021ListFieldsRequest" - + "\022A\n\006parent\030\001 \001(\tB1\342A\001\002\372A*\n(firestore.goo" - + "gleapis.com/CollectionGroup\022\016\n\006filter\030\002 " - + "\001(\t\022\021\n\tpage_size\030\003 \001(\005\022\022\n\npage_token\030\004 \001" - + "(\t\"_\n\022ListFieldsResponse\0220\n\006fields\030\001 \003(\013" - + "2 .google.firestore.admin.v1.Field\022\027\n\017ne" - + "xt_page_token\030\002 \001(\t\"\317\001\n\026ExportDocumentsR" - + "equest\0228\n\004name\030\001 \001(\tB*\342A\001\002\372A#\n!firestore" - + ".googleapis.com/Database\022\026\n\016collection_i" - + "ds\030\002 \003(\t\022\031\n\021output_uri_prefix\030\003 \001(\t\022\025\n\rn" - + "amespace_ids\030\004 \003(\t\0221\n\rsnapshot_time\030\005 \001(" - + "\0132\032.google.protobuf.Timestamp\"\233\001\n\026Import" - + "DocumentsRequest\0228\n\004name\030\001 \001(\tB*\342A\001\002\372A#\n" - + "!firestore.googleapis.com/Database\022\026\n\016co" - + "llection_ids\030\002 \003(\t\022\030\n\020input_uri_prefix\030\003" - + " \001(\t\022\025\n\rnamespace_ids\030\004 \003(\t2\251\026\n\016Firestor" - + "eAdmin\022\333\001\n\013CreateIndex\022-.google.firestor" - + "e.admin.v1.CreateIndexRequest\032\035.google.l" - + "ongrunning.Operation\"~\312A\037\n\005Index\022\026IndexO" - + "perationMetadata\332A\014parent,index\202\323\344\223\002G\">/" - + "v1/{parent=projects/*/databases/*/collec" - + "tionGroups/*}/indexes:\005index\022\275\001\n\013ListInd" - + "exes\022-.google.firestore.admin.v1.ListInd" - + "exesRequest\032..google.firestore.admin.v1." - + "ListIndexesResponse\"O\332A\006parent\202\323\344\223\002@\022>/v" - + "1/{parent=projects/*/databases/*/collect" - + "ionGroups/*}/indexes\022\247\001\n\010GetIndex\022*.goog" - + "le.firestore.admin.v1.GetIndexRequest\032 ." - + "google.firestore.admin.v1.Index\"M\332A\004name" - + "\202\323\344\223\002@\022>/v1/{name=projects/*/databases/*" - + "/collectionGroups/*/indexes/*}\022\243\001\n\013Delet" - + "eIndex\022-.google.firestore.admin.v1.Delet" - + "eIndexRequest\032\026.google.protobuf.Empty\"M\332" - + "A\004name\202\323\344\223\002@*>/v1/{name=projects/*/datab" - + "ases/*/collectionGroups/*/indexes/*}\022\246\001\n" - + "\010GetField\022*.google.firestore.admin.v1.Ge" - + "tFieldRequest\032 .google.firestore.admin.v" - + "1.Field\"L\332A\004name\202\323\344\223\002?\022=/v1/{name=projec" - + "ts/*/databases/*/collectionGroups/*/fiel" - + "ds/*}\022\331\001\n\013UpdateField\022-.google.firestore" - + ".admin.v1.UpdateFieldRequest\032\035.google.lo" - + "ngrunning.Operation\"|\312A\037\n\005Field\022\026FieldOp" - + "erationMetadata\332A\005field\202\323\344\223\002L2C/v1/{fiel" - + "d.name=projects/*/databases/*/collection" - + "Groups/*/fields/*}:\005field\022\271\001\n\nListFields" - + "\022,.google.firestore.admin.v1.ListFieldsR" - + "equest\032-.google.firestore.admin.v1.ListF" - + "ieldsResponse\"N\332A\006parent\202\323\344\223\002?\022=/v1/{par" - + "ent=projects/*/databases/*/collectionGro" - + "ups/*}/fields\022\335\001\n\017ExportDocuments\0221.goog" - + "le.firestore.admin.v1.ExportDocumentsReq" - + "uest\032\035.google.longrunning.Operation\"x\312A2" - + "\n\027ExportDocumentsResponse\022\027ExportDocumen" - + "tsMetadata\332A\004name\202\323\344\223\0026\"1/v1/{name=proje" - + "cts/*/databases/*}:exportDocuments:\001*\022\333\001" - + "\n\017ImportDocuments\0221.google.firestore.adm" - + "in.v1.ImportDocumentsRequest\032\035.google.lo" - + "ngrunning.Operation\"v\312A0\n\025google.protobu" - + "f.Empty\022\027ImportDocumentsMetadata\332A\004name\202" - + "\323\344\223\0026\"1/v1/{name=projects/*/databases/*}" - + ":importDocuments:\001*\022\331\001\n\016CreateDatabase\0220" - + ".google.firestore.admin.v1.CreateDatabas" - + "eRequest\032\035.google.longrunning.Operation\"" - + "v\312A\"\n\010Database\022\026CreateDatabaseMetadata\332A" - + "\033parent,database,database_id\202\323\344\223\002-\"!/v1/" - + "{parent=projects/*}/databases:\010database\022" - + "\223\001\n\013GetDatabase\022-.google.firestore.admin" - + ".v1.GetDatabaseRequest\032#.google.firestor" - + "e.admin.v1.Database\"0\332A\004name\202\323\344\223\002#\022!/v1/" - + "{name=projects/*/databases/*}\022\246\001\n\rListDa" - + "tabases\022/.google.firestore.admin.v1.List" - + "DatabasesRequest\0320.google.firestore.admi" - + "n.v1.ListDatabasesResponse\"2\332A\006parent\202\323\344" - + "\223\002#\022!/v1/{parent=projects/*}/databases\022\333" - + "\001\n\016UpdateDatabase\0220.google.firestore.adm" - + "in.v1.UpdateDatabaseRequest\032\035.google.lon" - + "grunning.Operation\"x\312A\"\n\010Database\022\026Updat" - + "eDatabaseMetadata\332A\024database,update_mask" - + "\202\323\344\223\00262*/v1/{database.name=projects/*/da" - + "tabases/*}:\010database\022\270\001\n\016DeleteDatabase\022" - + "0.google.firestore.admin.v1.DeleteDataba" - + "seRequest\032\035.google.longrunning.Operation" - + "\"U\312A\"\n\010Database\022\026DeleteDatabaseMetadata\332" - + "A\004name\202\323\344\223\002#*!/v1/{name=projects/*/datab" - + "ases/*}\032v\312A\030firestore.googleapis.com\322AXh" - + "ttps://www.googleapis.com/auth/cloud-pla" - + "tform,https://www.googleapis.com/auth/da" - + "tastoreB\245\003\n\035com.google.firestore.admin.v" - + "1B\023FirestoreAdminProtoP\001Z9cloud.google.c" - + "om/go/firestore/apiv1/admin/adminpb;admi" - + "npb\242\002\004GCFS\252\002\037Google.Cloud.Firestore.Admi" - + "n.V1\312\002\037Google\\Cloud\\Firestore\\Admin\\V1\352\002" - + "#Google::Cloud::Firestore::Admin::V1\352AL\n" - + "!firestore.googleapis.com/Location\022\'proj" - + "ects/{project}/locations/{location}\352Aq\n(" - + "firestore.googleapis.com/CollectionGroup" - + "\022Eprojects/{project}/databases/{database" - + "}/collectionGroups/{collection}b\006proto3" + + "firestore/admin/v1/operation.proto\032(goog" + + "le/firestore/admin/v1/schedule.proto\032#go" + + "ogle/longrunning/operations.proto\032\033googl" + + "e/protobuf/empty.proto\032 google/protobuf/" + + "field_mask.proto\032\037google/protobuf/timest" + + "amp.proto\"Q\n\024ListDatabasesRequest\0229\n\006par" + + "ent\030\001 \001(\tB)\340A\002\372A#\022!firestore.googleapis." + + "com/Database\"\250\001\n\025CreateDatabaseRequest\0229" + + "\n\006parent\030\001 \001(\tB)\340A\002\372A#\022!firestore.google" + + "apis.com/Database\022:\n\010database\030\002 \001(\0132#.go" + + "ogle.firestore.admin.v1.DatabaseB\003\340A\002\022\030\n" + + "\013database_id\030\003 \001(\tB\003\340A\002\"\030\n\026CreateDatabas" + + "eMetadata\"d\n\025ListDatabasesResponse\0226\n\tda" + + "tabases\030\001 \003(\0132#.google.firestore.admin.v" + + "1.Database\022\023\n\013unreachable\030\003 \003(\t\"M\n\022GetDa" + + "tabaseRequest\0227\n\004name\030\001 \001(\tB)\340A\002\372A#\n!fir" + + "estore.googleapis.com/Database\"\204\001\n\025Updat" + + "eDatabaseRequest\022:\n\010database\030\001 \001(\0132#.goo" + + "gle.firestore.admin.v1.DatabaseB\003\340A\002\022/\n\013" + + "update_mask\030\002 \001(\0132\032.google.protobuf.Fiel" + + "dMask\"\030\n\026UpdateDatabaseMetadata\"^\n\025Delet" + + "eDatabaseRequest\0227\n\004name\030\001 \001(\tB)\340A\002\372A#\n!" + + "firestore.googleapis.com/Database\022\014\n\004eta" + + "g\030\003 \001(\t\"\030\n\026DeleteDatabaseMetadata\"\241\001\n\033Cr" + + "eateBackupScheduleRequest\0229\n\006parent\030\001 \001(" + + "\tB)\340A\002\372A#\n!firestore.googleapis.com/Data" + + "base\022G\n\017backup_schedule\030\002 \001(\0132).google.f" + + "irestore.admin.v1.BackupScheduleB\003\340A\002\"Y\n" + + "\030GetBackupScheduleRequest\022=\n\004name\030\001 \001(\tB" + + "/\340A\002\372A)\n\'firestore.googleapis.com/Backup" + + "Schedule\"\227\001\n\033UpdateBackupScheduleRequest" + + "\022G\n\017backup_schedule\030\001 \001(\0132).google.fires" + + "tore.admin.v1.BackupScheduleB\003\340A\002\022/\n\013upd" + + "ate_mask\030\002 \001(\0132\032.google.protobuf.FieldMa" + + "sk\"W\n\032ListBackupSchedulesRequest\0229\n\006pare" + + "nt\030\001 \001(\tB)\340A\002\372A#\n!firestore.googleapis.c" + + "om/Database\"b\n\033ListBackupSchedulesRespon" + + "se\022C\n\020backup_schedules\030\001 \003(\0132).google.fi" + + "restore.admin.v1.BackupSchedule\"\\\n\033Delet" + + "eBackupScheduleRequest\022=\n\004name\030\001 \001(\tB/\340A" + + "\002\372A)\n\'firestore.googleapis.com/BackupSch" + + "edule\"\214\001\n\022CreateIndexRequest\022@\n\006parent\030\001" + + " \001(\tB0\340A\002\372A*\n(firestore.googleapis.com/C" + + "ollectionGroup\0224\n\005index\030\002 \001(\0132 .google.f" + + "irestore.admin.v1.IndexB\003\340A\002\"\215\001\n\022ListInd" + + "exesRequest\022@\n\006parent\030\001 \001(\tB0\340A\002\372A*\n(fir" + + "estore.googleapis.com/CollectionGroup\022\016\n" + + "\006filter\030\002 \001(\t\022\021\n\tpage_size\030\003 \001(\005\022\022\n\npage" + + "_token\030\004 \001(\t\"a\n\023ListIndexesResponse\0221\n\007i" + + "ndexes\030\001 \003(\0132 .google.firestore.admin.v1" + + ".Index\022\027\n\017next_page_token\030\002 \001(\t\"G\n\017GetIn" + + "dexRequest\0224\n\004name\030\001 \001(\tB&\340A\002\372A \n\036firest" + + "ore.googleapis.com/Index\"J\n\022DeleteIndexR" + + "equest\0224\n\004name\030\001 \001(\tB&\340A\002\372A \n\036firestore." + + "googleapis.com/Index\"{\n\022UpdateFieldReque" + + "st\0224\n\005field\030\001 \001(\0132 .google.firestore.adm" + + "in.v1.FieldB\003\340A\002\022/\n\013update_mask\030\002 \001(\0132\032." + + "google.protobuf.FieldMask\"G\n\017GetFieldReq" + + "uest\0224\n\004name\030\001 \001(\tB&\340A\002\372A \n\036firestore.go" + + "ogleapis.com/Field\"\214\001\n\021ListFieldsRequest" + + "\022@\n\006parent\030\001 \001(\tB0\340A\002\372A*\n(firestore.goog" + + "leapis.com/CollectionGroup\022\016\n\006filter\030\002 \001" + + "(\t\022\021\n\tpage_size\030\003 \001(\005\022\022\n\npage_token\030\004 \001(" + + "\t\"_\n\022ListFieldsResponse\0220\n\006fields\030\001 \003(\0132" + + " .google.firestore.admin.v1.Field\022\027\n\017nex" + + "t_page_token\030\002 \001(\t\"\316\001\n\026ExportDocumentsRe" + + "quest\0227\n\004name\030\001 \001(\tB)\340A\002\372A#\n!firestore.g" + + "oogleapis.com/Database\022\026\n\016collection_ids" + + "\030\002 \003(\t\022\031\n\021output_uri_prefix\030\003 \001(\t\022\025\n\rnam" + + "espace_ids\030\004 \003(\t\0221\n\rsnapshot_time\030\005 \001(\0132" + + "\032.google.protobuf.Timestamp\"\232\001\n\026ImportDo" + + "cumentsRequest\0227\n\004name\030\001 \001(\tB)\340A\002\372A#\n!fi" + + "restore.googleapis.com/Database\022\026\n\016colle" + + "ction_ids\030\002 \003(\t\022\030\n\020input_uri_prefix\030\003 \001(" + + "\t\022\025\n\rnamespace_ids\030\004 \003(\t\"I\n\020GetBackupReq" + + "uest\0225\n\004name\030\001 \001(\tB\'\340A\002\372A!\n\037firestore.go" + + "ogleapis.com/Backup\"O\n\022ListBackupsReques" + + "t\0229\n\006parent\030\001 \001(\tB)\340A\002\372A#\n!firestore.goo" + + "gleapis.com/Location\"^\n\023ListBackupsRespo" + + "nse\0222\n\007backups\030\001 \003(\0132!.google.firestore." + + "admin.v1.Backup\022\023\n\013unreachable\030\003 \003(\t\"L\n\023" + + "DeleteBackupRequest\0225\n\004name\030\001 \001(\tB\'\340A\002\372A" + + "!\n\037firestore.googleapis.com/Backup\"\246\001\n\026R" + + "estoreDatabaseRequest\0229\n\006parent\030\001 \001(\tB)\340" + + "A\002\372A#\022!firestore.googleapis.com/Database" + + "\022\030\n\013database_id\030\002 \001(\tB\003\340A\002\0227\n\006backup\030\003 \001" + + "(\tB\'\340A\002\372A!\n\037firestore.googleapis.com/Bac" + + "kup2\326#\n\016FirestoreAdmin\022\333\001\n\013CreateIndex\022-" + + ".google.firestore.admin.v1.CreateIndexRe" + + "quest\032\035.google.longrunning.Operation\"~\312A" + + "\037\n\005Index\022\026IndexOperationMetadata\332A\014paren" + + "t,index\202\323\344\223\002G\">/v1/{parent=projects/*/da" + + "tabases/*/collectionGroups/*}/indexes:\005i" + + "ndex\022\275\001\n\013ListIndexes\022-.google.firestore." + + "admin.v1.ListIndexesRequest\032..google.fir" + + "estore.admin.v1.ListIndexesResponse\"O\332A\006" + + "parent\202\323\344\223\002@\022>/v1/{parent=projects/*/dat" + + "abases/*/collectionGroups/*}/indexes\022\247\001\n" + + "\010GetIndex\022*.google.firestore.admin.v1.Ge" + + "tIndexRequest\032 .google.firestore.admin.v" + + "1.Index\"M\332A\004name\202\323\344\223\002@\022>/v1/{name=projec" + + "ts/*/databases/*/collectionGroups/*/inde" + + "xes/*}\022\243\001\n\013DeleteIndex\022-.google.firestor" + + "e.admin.v1.DeleteIndexRequest\032\026.google.p" + + "rotobuf.Empty\"M\332A\004name\202\323\344\223\002@*>/v1/{name=" + + "projects/*/databases/*/collectionGroups/" + + "*/indexes/*}\022\246\001\n\010GetField\022*.google.fires" + + "tore.admin.v1.GetFieldRequest\032 .google.f" + + "irestore.admin.v1.Field\"L\332A\004name\202\323\344\223\002?\022=" + + "/v1/{name=projects/*/databases/*/collect" + + "ionGroups/*/fields/*}\022\331\001\n\013UpdateField\022-." + + "google.firestore.admin.v1.UpdateFieldReq" + + "uest\032\035.google.longrunning.Operation\"|\312A\037" + + "\n\005Field\022\026FieldOperationMetadata\332A\005field\202" + + "\323\344\223\002L2C/v1/{field.name=projects/*/databa" + + "ses/*/collectionGroups/*/fields/*}:\005fiel" + + "d\022\271\001\n\nListFields\022,.google.firestore.admi" + + "n.v1.ListFieldsRequest\032-.google.firestor" + + "e.admin.v1.ListFieldsResponse\"N\332A\006parent" + + "\202\323\344\223\002?\022=/v1/{parent=projects/*/databases" + + "/*/collectionGroups/*}/fields\022\335\001\n\017Export" + + "Documents\0221.google.firestore.admin.v1.Ex" + + "portDocumentsRequest\032\035.google.longrunnin" + + "g.Operation\"x\312A2\n\027ExportDocumentsRespons" + + "e\022\027ExportDocumentsMetadata\332A\004name\202\323\344\223\0026\"" + + "1/v1/{name=projects/*/databases/*}:expor" + + "tDocuments:\001*\022\333\001\n\017ImportDocuments\0221.goog" + + "le.firestore.admin.v1.ImportDocumentsReq" + + "uest\032\035.google.longrunning.Operation\"v\312A0" + + "\n\025google.protobuf.Empty\022\027ImportDocuments" + + "Metadata\332A\004name\202\323\344\223\0026\"1/v1/{name=project" + + "s/*/databases/*}:importDocuments:\001*\022\331\001\n\016" + + "CreateDatabase\0220.google.firestore.admin." + + "v1.CreateDatabaseRequest\032\035.google.longru" + + "nning.Operation\"v\312A\"\n\010Database\022\026CreateDa" + + "tabaseMetadata\332A\033parent,database,databas" + + "e_id\202\323\344\223\002-\"!/v1/{parent=projects/*}/data" + + "bases:\010database\022\223\001\n\013GetDatabase\022-.google" + + ".firestore.admin.v1.GetDatabaseRequest\032#" + + ".google.firestore.admin.v1.Database\"0\332A\004" + + "name\202\323\344\223\002#\022!/v1/{name=projects/*/databas" + + "es/*}\022\246\001\n\rListDatabases\022/.google.firesto" + + "re.admin.v1.ListDatabasesRequest\0320.googl" + + "e.firestore.admin.v1.ListDatabasesRespon" + + "se\"2\332A\006parent\202\323\344\223\002#\022!/v1/{parent=project" + + "s/*}/databases\022\333\001\n\016UpdateDatabase\0220.goog" + + "le.firestore.admin.v1.UpdateDatabaseRequ" + + "est\032\035.google.longrunning.Operation\"x\312A\"\n" + + "\010Database\022\026UpdateDatabaseMetadata\332A\024data" + + "base,update_mask\202\323\344\223\00262*/v1/{database.na" + + "me=projects/*/databases/*}:\010database\022\270\001\n" + + "\016DeleteDatabase\0220.google.firestore.admin" + + ".v1.DeleteDatabaseRequest\032\035.google.longr" + + "unning.Operation\"U\312A\"\n\010Database\022\026DeleteD" + + "atabaseMetadata\332A\004name\202\323\344\223\002#*!/v1/{name=" + + "projects/*/databases/*}\022\227\001\n\tGetBackup\022+." + + "google.firestore.admin.v1.GetBackupReque" + + "st\032!.google.firestore.admin.v1.Backup\":\332" + + "A\004name\202\323\344\223\002-\022+/v1/{name=projects/*/locat" + + "ions/*/backups/*}\022\252\001\n\013ListBackups\022-.goog" + + "le.firestore.admin.v1.ListBackupsRequest" + + "\032..google.firestore.admin.v1.ListBackups" + + "Response\"<\332A\006parent\202\323\344\223\002-\022+/v1/{parent=p" + + "rojects/*/locations/*}/backups\022\222\001\n\014Delet" + + "eBackup\022..google.firestore.admin.v1.Dele" + + "teBackupRequest\032\026.google.protobuf.Empty\"" + + ":\332A\004name\202\323\344\223\002-*+/v1/{name=projects/*/loc" + + "ations/*/backups/*}\022\277\001\n\017RestoreDatabase\022" + + "1.google.firestore.admin.v1.RestoreDatab" + + "aseRequest\032\035.google.longrunning.Operatio" + + "n\"Z\312A#\n\010Database\022\027RestoreDatabaseMetadat" + + "a\202\323\344\223\002.\")/v1/{parent=projects/*}/databas" + + "es:restore:\001*\022\340\001\n\024CreateBackupSchedule\0226" + + ".google.firestore.admin.v1.CreateBackupS" + + "cheduleRequest\032).google.firestore.admin." + + "v1.BackupSchedule\"e\332A\026parent,backup_sche" + + "dule\202\323\344\223\002F\"3/v1/{parent=projects/*/datab" + + "ases/*}/backupSchedules:\017backup_schedule" + + "\022\267\001\n\021GetBackupSchedule\0223.google.firestor" + + "e.admin.v1.GetBackupScheduleRequest\032).go" + + "ogle.firestore.admin.v1.BackupSchedule\"B" + + "\332A\004name\202\323\344\223\0025\0223/v1/{name=projects/*/data" + + "bases/*/backupSchedules/*}\022\312\001\n\023ListBacku" + + "pSchedules\0225.google.firestore.admin.v1.L" + + "istBackupSchedulesRequest\0326.google.fires" + + "tore.admin.v1.ListBackupSchedulesRespons" + + "e\"D\332A\006parent\202\323\344\223\0025\0223/v1/{parent=projects" + + "/*/databases/*}/backupSchedules\022\365\001\n\024Upda" + + "teBackupSchedule\0226.google.firestore.admi" + + "n.v1.UpdateBackupScheduleRequest\032).googl" + + "e.firestore.admin.v1.BackupSchedule\"z\332A\033" + + "backup_schedule,update_mask\202\323\344\223\002V2C/v1/{" + + "backup_schedule.name=projects/*/database" + + "s/*/backupSchedules/*}:\017backup_schedule\022" + + "\252\001\n\024DeleteBackupSchedule\0226.google.firest" + + "ore.admin.v1.DeleteBackupScheduleRequest" + + "\032\026.google.protobuf.Empty\"B\332A\004name\202\323\344\223\0025*" + + "3/v1/{name=projects/*/databases/*/backup" + + "Schedules/*}\032v\312A\030firestore.googleapis.co" + + "m\322AXhttps://www.googleapis.com/auth/clou" + + "d-platform,https://www.googleapis.com/au" + + "th/datastoreB\245\003\n\035com.google.firestore.ad" + + "min.v1B\023FirestoreAdminProtoP\001Z9cloud.goo" + + "gle.com/go/firestore/apiv1/admin/adminpb" + + ";adminpb\242\002\004GCFS\252\002\037Google.Cloud.Firestore" + + ".Admin.V1\312\002\037Google\\Cloud\\Firestore\\Admin" + + "\\V1\352\002#Google::Cloud::Firestore::Admin::V" + + "1\352AL\n!firestore.googleapis.com/Location\022" + + "\'projects/{project}/locations/{location}" + + "\352Aq\n(firestore.googleapis.com/Collection" + + "Group\022Eprojects/{project}/databases/{dat" + + "abase}/collectionGroups/{collection}b\006pr" + + "oto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( @@ -273,10 +392,12 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { com.google.api.ClientProto.getDescriptor(), com.google.api.FieldBehaviorProto.getDescriptor(), com.google.api.ResourceProto.getDescriptor(), + com.google.firestore.admin.v1.BackupProto.getDescriptor(), com.google.firestore.admin.v1.DatabaseProto.getDescriptor(), com.google.firestore.admin.v1.FieldProto.getDescriptor(), com.google.firestore.admin.v1.IndexProto.getDescriptor(), com.google.firestore.admin.v1.OperationProto.getDescriptor(), + com.google.firestore.admin.v1.ScheduleProto.getDescriptor(), com.google.longrunning.OperationsProto.getDescriptor(), com.google.protobuf.EmptyProto.getDescriptor(), com.google.protobuf.FieldMaskProto.getDescriptor(), @@ -348,8 +469,56 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_firestore_admin_v1_DeleteDatabaseMetadata_descriptor, new java.lang.String[] {}); - internal_static_google_firestore_admin_v1_CreateIndexRequest_descriptor = + internal_static_google_firestore_admin_v1_CreateBackupScheduleRequest_descriptor = getDescriptor().getMessageTypes().get(9); + internal_static_google_firestore_admin_v1_CreateBackupScheduleRequest_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_CreateBackupScheduleRequest_descriptor, + new java.lang.String[] { + "Parent", "BackupSchedule", + }); + internal_static_google_firestore_admin_v1_GetBackupScheduleRequest_descriptor = + getDescriptor().getMessageTypes().get(10); + internal_static_google_firestore_admin_v1_GetBackupScheduleRequest_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_GetBackupScheduleRequest_descriptor, + new java.lang.String[] { + "Name", + }); + internal_static_google_firestore_admin_v1_UpdateBackupScheduleRequest_descriptor = + getDescriptor().getMessageTypes().get(11); + internal_static_google_firestore_admin_v1_UpdateBackupScheduleRequest_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_UpdateBackupScheduleRequest_descriptor, + new java.lang.String[] { + "BackupSchedule", "UpdateMask", + }); + internal_static_google_firestore_admin_v1_ListBackupSchedulesRequest_descriptor = + getDescriptor().getMessageTypes().get(12); + internal_static_google_firestore_admin_v1_ListBackupSchedulesRequest_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_ListBackupSchedulesRequest_descriptor, + new java.lang.String[] { + "Parent", + }); + internal_static_google_firestore_admin_v1_ListBackupSchedulesResponse_descriptor = + getDescriptor().getMessageTypes().get(13); + internal_static_google_firestore_admin_v1_ListBackupSchedulesResponse_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_ListBackupSchedulesResponse_descriptor, + new java.lang.String[] { + "BackupSchedules", + }); + internal_static_google_firestore_admin_v1_DeleteBackupScheduleRequest_descriptor = + getDescriptor().getMessageTypes().get(14); + internal_static_google_firestore_admin_v1_DeleteBackupScheduleRequest_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_DeleteBackupScheduleRequest_descriptor, + new java.lang.String[] { + "Name", + }); + internal_static_google_firestore_admin_v1_CreateIndexRequest_descriptor = + getDescriptor().getMessageTypes().get(15); internal_static_google_firestore_admin_v1_CreateIndexRequest_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_firestore_admin_v1_CreateIndexRequest_descriptor, @@ -357,7 +526,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { "Parent", "Index", }); internal_static_google_firestore_admin_v1_ListIndexesRequest_descriptor = - getDescriptor().getMessageTypes().get(10); + getDescriptor().getMessageTypes().get(16); internal_static_google_firestore_admin_v1_ListIndexesRequest_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_firestore_admin_v1_ListIndexesRequest_descriptor, @@ -365,7 +534,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { "Parent", "Filter", "PageSize", "PageToken", }); internal_static_google_firestore_admin_v1_ListIndexesResponse_descriptor = - getDescriptor().getMessageTypes().get(11); + getDescriptor().getMessageTypes().get(17); internal_static_google_firestore_admin_v1_ListIndexesResponse_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_firestore_admin_v1_ListIndexesResponse_descriptor, @@ -373,7 +542,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { "Indexes", "NextPageToken", }); internal_static_google_firestore_admin_v1_GetIndexRequest_descriptor = - getDescriptor().getMessageTypes().get(12); + getDescriptor().getMessageTypes().get(18); internal_static_google_firestore_admin_v1_GetIndexRequest_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_firestore_admin_v1_GetIndexRequest_descriptor, @@ -381,7 +550,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { "Name", }); internal_static_google_firestore_admin_v1_DeleteIndexRequest_descriptor = - getDescriptor().getMessageTypes().get(13); + getDescriptor().getMessageTypes().get(19); internal_static_google_firestore_admin_v1_DeleteIndexRequest_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_firestore_admin_v1_DeleteIndexRequest_descriptor, @@ -389,7 +558,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { "Name", }); internal_static_google_firestore_admin_v1_UpdateFieldRequest_descriptor = - getDescriptor().getMessageTypes().get(14); + getDescriptor().getMessageTypes().get(20); internal_static_google_firestore_admin_v1_UpdateFieldRequest_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_firestore_admin_v1_UpdateFieldRequest_descriptor, @@ -397,7 +566,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { "Field", "UpdateMask", }); internal_static_google_firestore_admin_v1_GetFieldRequest_descriptor = - getDescriptor().getMessageTypes().get(15); + getDescriptor().getMessageTypes().get(21); internal_static_google_firestore_admin_v1_GetFieldRequest_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_firestore_admin_v1_GetFieldRequest_descriptor, @@ -405,7 +574,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { "Name", }); internal_static_google_firestore_admin_v1_ListFieldsRequest_descriptor = - getDescriptor().getMessageTypes().get(16); + getDescriptor().getMessageTypes().get(22); internal_static_google_firestore_admin_v1_ListFieldsRequest_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_firestore_admin_v1_ListFieldsRequest_descriptor, @@ -413,7 +582,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { "Parent", "Filter", "PageSize", "PageToken", }); internal_static_google_firestore_admin_v1_ListFieldsResponse_descriptor = - getDescriptor().getMessageTypes().get(17); + getDescriptor().getMessageTypes().get(23); internal_static_google_firestore_admin_v1_ListFieldsResponse_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_firestore_admin_v1_ListFieldsResponse_descriptor, @@ -421,7 +590,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { "Fields", "NextPageToken", }); internal_static_google_firestore_admin_v1_ExportDocumentsRequest_descriptor = - getDescriptor().getMessageTypes().get(18); + getDescriptor().getMessageTypes().get(24); internal_static_google_firestore_admin_v1_ExportDocumentsRequest_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_firestore_admin_v1_ExportDocumentsRequest_descriptor, @@ -429,13 +598,53 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { "Name", "CollectionIds", "OutputUriPrefix", "NamespaceIds", "SnapshotTime", }); internal_static_google_firestore_admin_v1_ImportDocumentsRequest_descriptor = - getDescriptor().getMessageTypes().get(19); + getDescriptor().getMessageTypes().get(25); internal_static_google_firestore_admin_v1_ImportDocumentsRequest_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_firestore_admin_v1_ImportDocumentsRequest_descriptor, new java.lang.String[] { "Name", "CollectionIds", "InputUriPrefix", "NamespaceIds", }); + internal_static_google_firestore_admin_v1_GetBackupRequest_descriptor = + getDescriptor().getMessageTypes().get(26); + internal_static_google_firestore_admin_v1_GetBackupRequest_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_GetBackupRequest_descriptor, + new java.lang.String[] { + "Name", + }); + internal_static_google_firestore_admin_v1_ListBackupsRequest_descriptor = + getDescriptor().getMessageTypes().get(27); + internal_static_google_firestore_admin_v1_ListBackupsRequest_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_ListBackupsRequest_descriptor, + new java.lang.String[] { + "Parent", + }); + internal_static_google_firestore_admin_v1_ListBackupsResponse_descriptor = + getDescriptor().getMessageTypes().get(28); + internal_static_google_firestore_admin_v1_ListBackupsResponse_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_ListBackupsResponse_descriptor, + new java.lang.String[] { + "Backups", "Unreachable", + }); + internal_static_google_firestore_admin_v1_DeleteBackupRequest_descriptor = + getDescriptor().getMessageTypes().get(29); + internal_static_google_firestore_admin_v1_DeleteBackupRequest_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_DeleteBackupRequest_descriptor, + new java.lang.String[] { + "Name", + }); + internal_static_google_firestore_admin_v1_RestoreDatabaseRequest_descriptor = + getDescriptor().getMessageTypes().get(30); + internal_static_google_firestore_admin_v1_RestoreDatabaseRequest_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_RestoreDatabaseRequest_descriptor, + new java.lang.String[] { + "Parent", "DatabaseId", "Backup", + }); com.google.protobuf.ExtensionRegistry registry = com.google.protobuf.ExtensionRegistry.newInstance(); registry.add(com.google.api.ClientProto.defaultHost); @@ -452,10 +661,12 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { com.google.api.ClientProto.getDescriptor(); com.google.api.FieldBehaviorProto.getDescriptor(); com.google.api.ResourceProto.getDescriptor(); + com.google.firestore.admin.v1.BackupProto.getDescriptor(); com.google.firestore.admin.v1.DatabaseProto.getDescriptor(); com.google.firestore.admin.v1.FieldProto.getDescriptor(); com.google.firestore.admin.v1.IndexProto.getDescriptor(); com.google.firestore.admin.v1.OperationProto.getDescriptor(); + com.google.firestore.admin.v1.ScheduleProto.getDescriptor(); com.google.longrunning.OperationsProto.getDescriptor(); com.google.protobuf.EmptyProto.getDescriptor(); com.google.protobuf.FieldMaskProto.getDescriptor(); diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/GetBackupRequest.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/GetBackupRequest.java new file mode 100644 index 000000000..bc3a04431 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/GetBackupRequest.java @@ -0,0 +1,654 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +/** + * + * + *
+ * The request for
+ * [FirestoreAdmin.GetBackup][google.firestore.admin.v1.FirestoreAdmin.GetBackup].
+ * 
+ * + * Protobuf type {@code google.firestore.admin.v1.GetBackupRequest} + */ +public final class GetBackupRequest extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.GetBackupRequest) + GetBackupRequestOrBuilder { + private static final long serialVersionUID = 0L; + // Use GetBackupRequest.newBuilder() to construct. + private GetBackupRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private GetBackupRequest() { + name_ = ""; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new GetBackupRequest(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_GetBackupRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_GetBackupRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.GetBackupRequest.class, + com.google.firestore.admin.v1.GetBackupRequest.Builder.class); + } + + public static final int NAME_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile java.lang.Object name_ = ""; + /** + * + * + *
+   * Required. Name of the backup to fetch.
+   *
+   * Format is `projects/{project}/locations/{location}/backups/{backup}`.
+   * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } + } + /** + * + * + *
+   * Required. Name of the backup to fetch.
+   *
+   * Format is `projects/{project}/locations/{location}/backups/{backup}`.
+   * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.admin.v1.GetBackupRequest)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.GetBackupRequest other = + (com.google.firestore.admin.v1.GetBackupRequest) obj; + + if (!getName().equals(other.getName())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + NAME_FIELD_NUMBER; + hash = (53 * hash) + getName().hashCode(); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.GetBackupRequest parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.GetBackupRequest parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.GetBackupRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.GetBackupRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.GetBackupRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.GetBackupRequest parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.GetBackupRequest parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.GetBackupRequest parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.GetBackupRequest parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.GetBackupRequest parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.GetBackupRequest parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.GetBackupRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.admin.v1.GetBackupRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * The request for
+   * [FirestoreAdmin.GetBackup][google.firestore.admin.v1.FirestoreAdmin.GetBackup].
+   * 
+ * + * Protobuf type {@code google.firestore.admin.v1.GetBackupRequest} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.GetBackupRequest) + com.google.firestore.admin.v1.GetBackupRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_GetBackupRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_GetBackupRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.GetBackupRequest.class, + com.google.firestore.admin.v1.GetBackupRequest.Builder.class); + } + + // Construct using com.google.firestore.admin.v1.GetBackupRequest.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + name_ = ""; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_GetBackupRequest_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.GetBackupRequest getDefaultInstanceForType() { + return com.google.firestore.admin.v1.GetBackupRequest.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.GetBackupRequest build() { + com.google.firestore.admin.v1.GetBackupRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.GetBackupRequest buildPartial() { + com.google.firestore.admin.v1.GetBackupRequest result = + new com.google.firestore.admin.v1.GetBackupRequest(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.admin.v1.GetBackupRequest result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.name_ = name_; + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.admin.v1.GetBackupRequest) { + return mergeFrom((com.google.firestore.admin.v1.GetBackupRequest) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.admin.v1.GetBackupRequest other) { + if (other == com.google.firestore.admin.v1.GetBackupRequest.getDefaultInstance()) return this; + if (!other.getName().isEmpty()) { + name_ = other.name_; + bitField0_ |= 0x00000001; + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + name_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private java.lang.Object name_ = ""; + /** + * + * + *
+     * Required. Name of the backup to fetch.
+     *
+     * Format is `projects/{project}/locations/{location}/backups/{backup}`.
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The name. + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * Required. Name of the backup to fetch.
+     *
+     * Format is `projects/{project}/locations/{location}/backups/{backup}`.
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for name. + */ + public com.google.protobuf.ByteString getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * Required. Name of the backup to fetch.
+     *
+     * Format is `projects/{project}/locations/{location}/backups/{backup}`.
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * Required. Name of the backup to fetch.
+     *
+     * Format is `projects/{project}/locations/{location}/backups/{backup}`.
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return This builder for chaining. + */ + public Builder clearName() { + name_ = getDefaultInstance().getName(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + /** + * + * + *
+     * Required. Name of the backup to fetch.
+     *
+     * Format is `projects/{project}/locations/{location}/backups/{backup}`.
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.GetBackupRequest) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.GetBackupRequest) + private static final com.google.firestore.admin.v1.GetBackupRequest DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.admin.v1.GetBackupRequest(); + } + + public static com.google.firestore.admin.v1.GetBackupRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public GetBackupRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.GetBackupRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/GetBackupRequestOrBuilder.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/GetBackupRequestOrBuilder.java new file mode 100644 index 000000000..541b353aa --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/GetBackupRequestOrBuilder.java @@ -0,0 +1,59 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +public interface GetBackupRequestOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.GetBackupRequest) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * Required. Name of the backup to fetch.
+   *
+   * Format is `projects/{project}/locations/{location}/backups/{backup}`.
+   * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The name. + */ + java.lang.String getName(); + /** + * + * + *
+   * Required. Name of the backup to fetch.
+   *
+   * Format is `projects/{project}/locations/{location}/backups/{backup}`.
+   * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for name. + */ + com.google.protobuf.ByteString getNameBytes(); +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/GetBackupScheduleRequest.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/GetBackupScheduleRequest.java new file mode 100644 index 000000000..466569f11 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/GetBackupScheduleRequest.java @@ -0,0 +1,663 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +/** + * + * + *
+ * The request for
+ * [FirestoreAdmin.GetBackupSchedule][google.firestore.admin.v1.FirestoreAdmin.GetBackupSchedule].
+ * 
+ * + * Protobuf type {@code google.firestore.admin.v1.GetBackupScheduleRequest} + */ +public final class GetBackupScheduleRequest extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.GetBackupScheduleRequest) + GetBackupScheduleRequestOrBuilder { + private static final long serialVersionUID = 0L; + // Use GetBackupScheduleRequest.newBuilder() to construct. + private GetBackupScheduleRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private GetBackupScheduleRequest() { + name_ = ""; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new GetBackupScheduleRequest(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_GetBackupScheduleRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_GetBackupScheduleRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.GetBackupScheduleRequest.class, + com.google.firestore.admin.v1.GetBackupScheduleRequest.Builder.class); + } + + public static final int NAME_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile java.lang.Object name_ = ""; + /** + * + * + *
+   * Required. The name of the backup schedule.
+   *
+   * Format
+   * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+   * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } + } + /** + * + * + *
+   * Required. The name of the backup schedule.
+   *
+   * Format
+   * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+   * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.admin.v1.GetBackupScheduleRequest)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.GetBackupScheduleRequest other = + (com.google.firestore.admin.v1.GetBackupScheduleRequest) obj; + + if (!getName().equals(other.getName())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + NAME_FIELD_NUMBER; + hash = (53 * hash) + getName().hashCode(); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.GetBackupScheduleRequest parseFrom( + java.nio.ByteBuffer data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.GetBackupScheduleRequest parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.GetBackupScheduleRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.GetBackupScheduleRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.GetBackupScheduleRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.GetBackupScheduleRequest parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.GetBackupScheduleRequest parseFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.GetBackupScheduleRequest parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.GetBackupScheduleRequest parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.GetBackupScheduleRequest parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.GetBackupScheduleRequest parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.GetBackupScheduleRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder( + com.google.firestore.admin.v1.GetBackupScheduleRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * The request for
+   * [FirestoreAdmin.GetBackupSchedule][google.firestore.admin.v1.FirestoreAdmin.GetBackupSchedule].
+   * 
+ * + * Protobuf type {@code google.firestore.admin.v1.GetBackupScheduleRequest} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.GetBackupScheduleRequest) + com.google.firestore.admin.v1.GetBackupScheduleRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_GetBackupScheduleRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_GetBackupScheduleRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.GetBackupScheduleRequest.class, + com.google.firestore.admin.v1.GetBackupScheduleRequest.Builder.class); + } + + // Construct using com.google.firestore.admin.v1.GetBackupScheduleRequest.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + name_ = ""; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_GetBackupScheduleRequest_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.GetBackupScheduleRequest getDefaultInstanceForType() { + return com.google.firestore.admin.v1.GetBackupScheduleRequest.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.GetBackupScheduleRequest build() { + com.google.firestore.admin.v1.GetBackupScheduleRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.GetBackupScheduleRequest buildPartial() { + com.google.firestore.admin.v1.GetBackupScheduleRequest result = + new com.google.firestore.admin.v1.GetBackupScheduleRequest(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.admin.v1.GetBackupScheduleRequest result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.name_ = name_; + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.admin.v1.GetBackupScheduleRequest) { + return mergeFrom((com.google.firestore.admin.v1.GetBackupScheduleRequest) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.admin.v1.GetBackupScheduleRequest other) { + if (other == com.google.firestore.admin.v1.GetBackupScheduleRequest.getDefaultInstance()) + return this; + if (!other.getName().isEmpty()) { + name_ = other.name_; + bitField0_ |= 0x00000001; + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + name_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private java.lang.Object name_ = ""; + /** + * + * + *
+     * Required. The name of the backup schedule.
+     *
+     * Format
+     * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The name. + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * Required. The name of the backup schedule.
+     *
+     * Format
+     * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for name. + */ + public com.google.protobuf.ByteString getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * Required. The name of the backup schedule.
+     *
+     * Format
+     * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The name of the backup schedule.
+     *
+     * Format
+     * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return This builder for chaining. + */ + public Builder clearName() { + name_ = getDefaultInstance().getName(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The name of the backup schedule.
+     *
+     * Format
+     * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+     * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.GetBackupScheduleRequest) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.GetBackupScheduleRequest) + private static final com.google.firestore.admin.v1.GetBackupScheduleRequest DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.admin.v1.GetBackupScheduleRequest(); + } + + public static com.google.firestore.admin.v1.GetBackupScheduleRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public GetBackupScheduleRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.GetBackupScheduleRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/GetBackupScheduleRequestOrBuilder.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/GetBackupScheduleRequestOrBuilder.java new file mode 100644 index 000000000..d75c69e10 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/GetBackupScheduleRequestOrBuilder.java @@ -0,0 +1,61 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +public interface GetBackupScheduleRequestOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.GetBackupScheduleRequest) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * Required. The name of the backup schedule.
+   *
+   * Format
+   * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+   * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The name. + */ + java.lang.String getName(); + /** + * + * + *
+   * Required. The name of the backup schedule.
+   *
+   * Format
+   * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}`
+   * 
+ * + * + * string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for name. + */ + com.google.protobuf.ByteString getNameBytes(); +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/Index.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/Index.java index e977935be..ce0374de8 100644 --- a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/Index.java +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/Index.java @@ -713,6 +713,44 @@ public interface IndexFieldOrBuilder */ com.google.firestore.admin.v1.Index.IndexField.ArrayConfig getArrayConfig(); + /** + * + * + *
+     * Indicates that this field supports nearest neighbors and distance
+     * operations on vector.
+     * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig vector_config = 4; + * + * @return Whether the vectorConfig field is set. + */ + boolean hasVectorConfig(); + /** + * + * + *
+     * Indicates that this field supports nearest neighbors and distance
+     * operations on vector.
+     * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig vector_config = 4; + * + * @return The vectorConfig. + */ + com.google.firestore.admin.v1.Index.IndexField.VectorConfig getVectorConfig(); + /** + * + * + *
+     * Indicates that this field supports nearest neighbors and distance
+     * operations on vector.
+     * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig vector_config = 4; + */ + com.google.firestore.admin.v1.Index.IndexField.VectorConfigOrBuilder getVectorConfigOrBuilder(); + com.google.firestore.admin.v1.Index.IndexField.ValueModeCase getValueModeCase(); } /** @@ -1003,54 +1041,1499 @@ public static ArrayConfig forNumber(int value) { default: return null; } - } - - public static com.google.protobuf.Internal.EnumLiteMap internalGetValueMap() { - return internalValueMap; - } + } + + public static com.google.protobuf.Internal.EnumLiteMap internalGetValueMap() { + return internalValueMap; + } + + private static final com.google.protobuf.Internal.EnumLiteMap internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + public ArrayConfig findValueByNumber(int number) { + return ArrayConfig.forNumber(number); + } + }; + + public final com.google.protobuf.Descriptors.EnumValueDescriptor getValueDescriptor() { + if (this == UNRECOGNIZED) { + throw new java.lang.IllegalStateException( + "Can't get the descriptor of an unrecognized enum value."); + } + return getDescriptor().getValues().get(ordinal()); + } + + public final com.google.protobuf.Descriptors.EnumDescriptor getDescriptorForType() { + return getDescriptor(); + } + + public static final com.google.protobuf.Descriptors.EnumDescriptor getDescriptor() { + return com.google.firestore.admin.v1.Index.IndexField.getDescriptor().getEnumTypes().get(1); + } + + private static final ArrayConfig[] VALUES = values(); + + public static ArrayConfig valueOf(com.google.protobuf.Descriptors.EnumValueDescriptor desc) { + if (desc.getType() != getDescriptor()) { + throw new java.lang.IllegalArgumentException("EnumValueDescriptor is not for this type."); + } + if (desc.getIndex() == -1) { + return UNRECOGNIZED; + } + return VALUES[desc.getIndex()]; + } + + private final int value; + + private ArrayConfig(int value) { + this.value = value; + } + + // @@protoc_insertion_point(enum_scope:google.firestore.admin.v1.Index.IndexField.ArrayConfig) + } + + public interface VectorConfigOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.Index.IndexField.VectorConfig) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+       * Required. The vector dimension this configuration applies to.
+       *
+       * The resulting index will only include vectors of this dimension, and
+       * can be used for vector search with the same dimension.
+       * 
+ * + * int32 dimension = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * @return The dimension. + */ + int getDimension(); + + /** + * + * + *
+       * Indicates the vector index is a flat index.
+       * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex flat = 2; + * + * @return Whether the flat field is set. + */ + boolean hasFlat(); + /** + * + * + *
+       * Indicates the vector index is a flat index.
+       * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex flat = 2; + * + * @return The flat. + */ + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex getFlat(); + /** + * + * + *
+       * Indicates the vector index is a flat index.
+       * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex flat = 2; + */ + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndexOrBuilder + getFlatOrBuilder(); + + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.TypeCase getTypeCase(); + } + /** + * + * + *
+     * The index configuration to support vector search operations
+     * 
+ * + * Protobuf type {@code google.firestore.admin.v1.Index.IndexField.VectorConfig} + */ + public static final class VectorConfig extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.Index.IndexField.VectorConfig) + VectorConfigOrBuilder { + private static final long serialVersionUID = 0L; + // Use VectorConfig.newBuilder() to construct. + private VectorConfig(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private VectorConfig() {} + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new VectorConfig(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.IndexProto + .internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.IndexProto + .internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.class, + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.Builder.class); + } + + public interface FlatIndexOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex) + com.google.protobuf.MessageOrBuilder {} + /** + * + * + *
+       * An index that stores vectors in a flat data structure, and supports
+       * exhaustive search.
+       * 
+ * + * Protobuf type {@code google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex} + */ + public static final class FlatIndex extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex) + FlatIndexOrBuilder { + private static final long serialVersionUID = 0L; + // Use FlatIndex.newBuilder() to construct. + private FlatIndex(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private FlatIndex() {} + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new FlatIndex(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.IndexProto + .internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_FlatIndex_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.IndexProto + .internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_FlatIndex_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex.class, + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex.Builder + .class); + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj + instanceof com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex other = + (com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex) obj; + + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + parseFrom(com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + parseFrom(byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + parseFrom(java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + parseFrom(com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder( + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+         * An index that stores vectors in a flat data structure, and supports
+         * exhaustive search.
+         * 
+ * + * Protobuf type {@code google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex} + */ + public static final class Builder + extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex) + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndexOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.IndexProto + .internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_FlatIndex_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.IndexProto + .internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_FlatIndex_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex.class, + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex.Builder + .class); + } + + // Construct using + // com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.IndexProto + .internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_FlatIndex_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + getDefaultInstanceForType() { + return com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + .getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex build() { + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex result = + buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + buildPartial() { + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex result = + new com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex(this); + onBuilt(); + return result; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, + java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other + instanceof com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex) { + return mergeFrom( + (com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom( + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex other) { + if (other + == com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + .getDefaultInstance()) return this; + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex) + private static final com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = + new com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex(); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public FlatIndex parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException() + .setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + } + + private int typeCase_ = 0; + + @SuppressWarnings("serial") + private java.lang.Object type_; + + public enum TypeCase + implements + com.google.protobuf.Internal.EnumLite, + com.google.protobuf.AbstractMessage.InternalOneOfEnum { + FLAT(2), + TYPE_NOT_SET(0); + private final int value; + + private TypeCase(int value) { + this.value = value; + } + /** + * @param value The number of the enum to look for. + * @return The enum associated with the given number. + * @deprecated Use {@link #forNumber(int)} instead. + */ + @java.lang.Deprecated + public static TypeCase valueOf(int value) { + return forNumber(value); + } + + public static TypeCase forNumber(int value) { + switch (value) { + case 2: + return FLAT; + case 0: + return TYPE_NOT_SET; + default: + return null; + } + } + + public int getNumber() { + return this.value; + } + }; + + public TypeCase getTypeCase() { + return TypeCase.forNumber(typeCase_); + } + + public static final int DIMENSION_FIELD_NUMBER = 1; + private int dimension_ = 0; + /** + * + * + *
+       * Required. The vector dimension this configuration applies to.
+       *
+       * The resulting index will only include vectors of this dimension, and
+       * can be used for vector search with the same dimension.
+       * 
+ * + * int32 dimension = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * @return The dimension. + */ + @java.lang.Override + public int getDimension() { + return dimension_; + } + + public static final int FLAT_FIELD_NUMBER = 2; + /** + * + * + *
+       * Indicates the vector index is a flat index.
+       * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex flat = 2; + * + * @return Whether the flat field is set. + */ + @java.lang.Override + public boolean hasFlat() { + return typeCase_ == 2; + } + /** + * + * + *
+       * Indicates the vector index is a flat index.
+       * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex flat = 2; + * + * @return The flat. + */ + @java.lang.Override + public com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex getFlat() { + if (typeCase_ == 2) { + return (com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex) type_; + } + return com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + .getDefaultInstance(); + } + /** + * + * + *
+       * Indicates the vector index is a flat index.
+       * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex flat = 2; + */ + @java.lang.Override + public com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndexOrBuilder + getFlatOrBuilder() { + if (typeCase_ == 2) { + return (com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex) type_; + } + return com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + .getDefaultInstance(); + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (dimension_ != 0) { + output.writeInt32(1, dimension_); + } + if (typeCase_ == 2) { + output.writeMessage( + 2, (com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex) type_); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (dimension_ != 0) { + size += com.google.protobuf.CodedOutputStream.computeInt32Size(1, dimension_); + } + if (typeCase_ == 2) { + size += + com.google.protobuf.CodedOutputStream.computeMessageSize( + 2, (com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex) type_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.admin.v1.Index.IndexField.VectorConfig)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.Index.IndexField.VectorConfig other = + (com.google.firestore.admin.v1.Index.IndexField.VectorConfig) obj; + + if (getDimension() != other.getDimension()) return false; + if (!getTypeCase().equals(other.getTypeCase())) return false; + switch (typeCase_) { + case 2: + if (!getFlat().equals(other.getFlat())) return false; + break; + case 0: + default: + } + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + DIMENSION_FIELD_NUMBER; + hash = (53 * hash) + getDimension(); + switch (typeCase_) { + case 2: + hash = (37 * hash) + FLAT_FIELD_NUMBER; + hash = (53 * hash) + getFlat().hashCode(); + break; + case 0: + default: + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig parseFrom( + java.nio.ByteBuffer data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig parseFrom( + byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig parseFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder( + com.google.firestore.admin.v1.Index.IndexField.VectorConfig prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+       * The index configuration to support vector search operations
+       * 
+ * + * Protobuf type {@code google.firestore.admin.v1.Index.IndexField.VectorConfig} + */ + public static final class Builder + extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.Index.IndexField.VectorConfig) + com.google.firestore.admin.v1.Index.IndexField.VectorConfigOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.IndexProto + .internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.IndexProto + .internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.class, + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.Builder.class); + } + + // Construct using com.google.firestore.admin.v1.Index.IndexField.VectorConfig.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + dimension_ = 0; + if (flatBuilder_ != null) { + flatBuilder_.clear(); + } + typeCase_ = 0; + type_ = null; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.IndexProto + .internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.Index.IndexField.VectorConfig + getDefaultInstanceForType() { + return com.google.firestore.admin.v1.Index.IndexField.VectorConfig.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.Index.IndexField.VectorConfig build() { + com.google.firestore.admin.v1.Index.IndexField.VectorConfig result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.Index.IndexField.VectorConfig buildPartial() { + com.google.firestore.admin.v1.Index.IndexField.VectorConfig result = + new com.google.firestore.admin.v1.Index.IndexField.VectorConfig(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + buildPartialOneofs(result); + onBuilt(); + return result; + } + + private void buildPartial0( + com.google.firestore.admin.v1.Index.IndexField.VectorConfig result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.dimension_ = dimension_; + } + } + + private void buildPartialOneofs( + com.google.firestore.admin.v1.Index.IndexField.VectorConfig result) { + result.typeCase_ = typeCase_; + result.type_ = this.type_; + if (typeCase_ == 2 && flatBuilder_ != null) { + result.type_ = flatBuilder_.build(); + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, + java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.admin.v1.Index.IndexField.VectorConfig) { + return mergeFrom((com.google.firestore.admin.v1.Index.IndexField.VectorConfig) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom( + com.google.firestore.admin.v1.Index.IndexField.VectorConfig other) { + if (other + == com.google.firestore.admin.v1.Index.IndexField.VectorConfig.getDefaultInstance()) + return this; + if (other.getDimension() != 0) { + setDimension(other.getDimension()); + } + switch (other.getTypeCase()) { + case FLAT: + { + mergeFlat(other.getFlat()); + break; + } + case TYPE_NOT_SET: + { + break; + } + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 8: + { + dimension_ = input.readInt32(); + bitField0_ |= 0x00000001; + break; + } // case 8 + case 18: + { + input.readMessage(getFlatFieldBuilder().getBuilder(), extensionRegistry); + typeCase_ = 2; + break; + } // case 18 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } - private static final com.google.protobuf.Internal.EnumLiteMap internalValueMap = - new com.google.protobuf.Internal.EnumLiteMap() { - public ArrayConfig findValueByNumber(int number) { - return ArrayConfig.forNumber(number); - } - }; + private int typeCase_ = 0; + private java.lang.Object type_; - public final com.google.protobuf.Descriptors.EnumValueDescriptor getValueDescriptor() { - if (this == UNRECOGNIZED) { - throw new java.lang.IllegalStateException( - "Can't get the descriptor of an unrecognized enum value."); + public TypeCase getTypeCase() { + return TypeCase.forNumber(typeCase_); } - return getDescriptor().getValues().get(ordinal()); - } - public final com.google.protobuf.Descriptors.EnumDescriptor getDescriptorForType() { - return getDescriptor(); - } + public Builder clearType() { + typeCase_ = 0; + type_ = null; + onChanged(); + return this; + } - public static final com.google.protobuf.Descriptors.EnumDescriptor getDescriptor() { - return com.google.firestore.admin.v1.Index.IndexField.getDescriptor().getEnumTypes().get(1); - } + private int bitField0_; + + private int dimension_; + /** + * + * + *
+         * Required. The vector dimension this configuration applies to.
+         *
+         * The resulting index will only include vectors of this dimension, and
+         * can be used for vector search with the same dimension.
+         * 
+ * + * int32 dimension = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * @return The dimension. + */ + @java.lang.Override + public int getDimension() { + return dimension_; + } + /** + * + * + *
+         * Required. The vector dimension this configuration applies to.
+         *
+         * The resulting index will only include vectors of this dimension, and
+         * can be used for vector search with the same dimension.
+         * 
+ * + * int32 dimension = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * @param value The dimension to set. + * @return This builder for chaining. + */ + public Builder setDimension(int value) { + + dimension_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+         * Required. The vector dimension this configuration applies to.
+         *
+         * The resulting index will only include vectors of this dimension, and
+         * can be used for vector search with the same dimension.
+         * 
+ * + * int32 dimension = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * @return This builder for chaining. + */ + public Builder clearDimension() { + bitField0_ = (bitField0_ & ~0x00000001); + dimension_ = 0; + onChanged(); + return this; + } - private static final ArrayConfig[] VALUES = values(); + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex, + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex.Builder, + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndexOrBuilder> + flatBuilder_; + /** + * + * + *
+         * Indicates the vector index is a flat index.
+         * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex flat = 2; + * + * @return Whether the flat field is set. + */ + @java.lang.Override + public boolean hasFlat() { + return typeCase_ == 2; + } + /** + * + * + *
+         * Indicates the vector index is a flat index.
+         * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex flat = 2; + * + * @return The flat. + */ + @java.lang.Override + public com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex getFlat() { + if (flatBuilder_ == null) { + if (typeCase_ == 2) { + return (com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex) type_; + } + return com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + .getDefaultInstance(); + } else { + if (typeCase_ == 2) { + return flatBuilder_.getMessage(); + } + return com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + .getDefaultInstance(); + } + } + /** + * + * + *
+         * Indicates the vector index is a flat index.
+         * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex flat = 2; + */ + public Builder setFlat( + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex value) { + if (flatBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + type_ = value; + onChanged(); + } else { + flatBuilder_.setMessage(value); + } + typeCase_ = 2; + return this; + } + /** + * + * + *
+         * Indicates the vector index is a flat index.
+         * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex flat = 2; + */ + public Builder setFlat( + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex.Builder + builderForValue) { + if (flatBuilder_ == null) { + type_ = builderForValue.build(); + onChanged(); + } else { + flatBuilder_.setMessage(builderForValue.build()); + } + typeCase_ = 2; + return this; + } + /** + * + * + *
+         * Indicates the vector index is a flat index.
+         * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex flat = 2; + */ + public Builder mergeFlat( + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex value) { + if (flatBuilder_ == null) { + if (typeCase_ == 2 + && type_ + != com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + .getDefaultInstance()) { + type_ = + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex.newBuilder( + (com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex) + type_) + .mergeFrom(value) + .buildPartial(); + } else { + type_ = value; + } + onChanged(); + } else { + if (typeCase_ == 2) { + flatBuilder_.mergeFrom(value); + } else { + flatBuilder_.setMessage(value); + } + } + typeCase_ = 2; + return this; + } + /** + * + * + *
+         * Indicates the vector index is a flat index.
+         * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex flat = 2; + */ + public Builder clearFlat() { + if (flatBuilder_ == null) { + if (typeCase_ == 2) { + typeCase_ = 0; + type_ = null; + onChanged(); + } + } else { + if (typeCase_ == 2) { + typeCase_ = 0; + type_ = null; + } + flatBuilder_.clear(); + } + return this; + } + /** + * + * + *
+         * Indicates the vector index is a flat index.
+         * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex flat = 2; + */ + public com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex.Builder + getFlatBuilder() { + return getFlatFieldBuilder().getBuilder(); + } + /** + * + * + *
+         * Indicates the vector index is a flat index.
+         * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex flat = 2; + */ + @java.lang.Override + public com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndexOrBuilder + getFlatOrBuilder() { + if ((typeCase_ == 2) && (flatBuilder_ != null)) { + return flatBuilder_.getMessageOrBuilder(); + } else { + if (typeCase_ == 2) { + return (com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex) type_; + } + return com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + .getDefaultInstance(); + } + } + /** + * + * + *
+         * Indicates the vector index is a flat index.
+         * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex flat = 2; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex, + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex.Builder, + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndexOrBuilder> + getFlatFieldBuilder() { + if (flatBuilder_ == null) { + if (!(typeCase_ == 2)) { + type_ = + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + .getDefaultInstance(); + } + flatBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex, + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex.Builder, + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndexOrBuilder>( + (com.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex) type_, + getParentForChildren(), + isClean()); + type_ = null; + } + typeCase_ = 2; + onChanged(); + return flatBuilder_; + } - public static ArrayConfig valueOf(com.google.protobuf.Descriptors.EnumValueDescriptor desc) { - if (desc.getType() != getDescriptor()) { - throw new java.lang.IllegalArgumentException("EnumValueDescriptor is not for this type."); + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); } - if (desc.getIndex() == -1) { - return UNRECOGNIZED; + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); } - return VALUES[desc.getIndex()]; - } - private final int value; + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.Index.IndexField.VectorConfig) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.Index.IndexField.VectorConfig) + private static final com.google.firestore.admin.v1.Index.IndexField.VectorConfig + DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.admin.v1.Index.IndexField.VectorConfig(); + } + + public static com.google.firestore.admin.v1.Index.IndexField.VectorConfig + getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public VectorConfig parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException() + .setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; - private ArrayConfig(int value) { - this.value = value; + public static com.google.protobuf.Parser parser() { + return PARSER; } - // @@protoc_insertion_point(enum_scope:google.firestore.admin.v1.Index.IndexField.ArrayConfig) + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.Index.IndexField.VectorConfig + getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } } private int valueModeCase_ = 0; @@ -1064,6 +2547,7 @@ public enum ValueModeCase com.google.protobuf.AbstractMessage.InternalOneOfEnum { ORDER(2), ARRAY_CONFIG(3), + VECTOR_CONFIG(4), VALUEMODE_NOT_SET(0); private final int value; @@ -1086,6 +2570,8 @@ public static ValueModeCase forNumber(int value) { return ORDER; case 3: return ARRAY_CONFIG; + case 4: + return VECTOR_CONFIG; case 0: return VALUEMODE_NOT_SET; default: @@ -1270,6 +2756,61 @@ public com.google.firestore.admin.v1.Index.IndexField.ArrayConfig getArrayConfig return com.google.firestore.admin.v1.Index.IndexField.ArrayConfig.ARRAY_CONFIG_UNSPECIFIED; } + public static final int VECTOR_CONFIG_FIELD_NUMBER = 4; + /** + * + * + *
+     * Indicates that this field supports nearest neighbors and distance
+     * operations on vector.
+     * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig vector_config = 4; + * + * @return Whether the vectorConfig field is set. + */ + @java.lang.Override + public boolean hasVectorConfig() { + return valueModeCase_ == 4; + } + /** + * + * + *
+     * Indicates that this field supports nearest neighbors and distance
+     * operations on vector.
+     * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig vector_config = 4; + * + * @return The vectorConfig. + */ + @java.lang.Override + public com.google.firestore.admin.v1.Index.IndexField.VectorConfig getVectorConfig() { + if (valueModeCase_ == 4) { + return (com.google.firestore.admin.v1.Index.IndexField.VectorConfig) valueMode_; + } + return com.google.firestore.admin.v1.Index.IndexField.VectorConfig.getDefaultInstance(); + } + /** + * + * + *
+     * Indicates that this field supports nearest neighbors and distance
+     * operations on vector.
+     * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig vector_config = 4; + */ + @java.lang.Override + public com.google.firestore.admin.v1.Index.IndexField.VectorConfigOrBuilder + getVectorConfigOrBuilder() { + if (valueModeCase_ == 4) { + return (com.google.firestore.admin.v1.Index.IndexField.VectorConfig) valueMode_; + } + return com.google.firestore.admin.v1.Index.IndexField.VectorConfig.getDefaultInstance(); + } + private byte memoizedIsInitialized = -1; @java.lang.Override @@ -1293,6 +2834,10 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io if (valueModeCase_ == 3) { output.writeEnum(3, ((java.lang.Integer) valueMode_)); } + if (valueModeCase_ == 4) { + output.writeMessage( + 4, (com.google.firestore.admin.v1.Index.IndexField.VectorConfig) valueMode_); + } getUnknownFields().writeTo(output); } @@ -1315,6 +2860,11 @@ public int getSerializedSize() { com.google.protobuf.CodedOutputStream.computeEnumSize( 3, ((java.lang.Integer) valueMode_)); } + if (valueModeCase_ == 4) { + size += + com.google.protobuf.CodedOutputStream.computeMessageSize( + 4, (com.google.firestore.admin.v1.Index.IndexField.VectorConfig) valueMode_); + } size += getUnknownFields().getSerializedSize(); memoizedSize = size; return size; @@ -1340,6 +2890,9 @@ public boolean equals(final java.lang.Object obj) { case 3: if (getArrayConfigValue() != other.getArrayConfigValue()) return false; break; + case 4: + if (!getVectorConfig().equals(other.getVectorConfig())) return false; + break; case 0: default: } @@ -1365,6 +2918,10 @@ public int hashCode() { hash = (37 * hash) + ARRAY_CONFIG_FIELD_NUMBER; hash = (53 * hash) + getArrayConfigValue(); break; + case 4: + hash = (37 * hash) + VECTOR_CONFIG_FIELD_NUMBER; + hash = (53 * hash) + getVectorConfig().hashCode(); + break; case 0: default: } @@ -1512,6 +3069,9 @@ public Builder clear() { super.clear(); bitField0_ = 0; fieldPath_ = ""; + if (vectorConfigBuilder_ != null) { + vectorConfigBuilder_.clear(); + } valueModeCase_ = 0; valueMode_ = null; return this; @@ -1559,6 +3119,9 @@ private void buildPartial0(com.google.firestore.admin.v1.Index.IndexField result private void buildPartialOneofs(com.google.firestore.admin.v1.Index.IndexField result) { result.valueModeCase_ = valueModeCase_; result.valueMode_ = this.valueMode_; + if (valueModeCase_ == 4 && vectorConfigBuilder_ != null) { + result.valueMode_ = vectorConfigBuilder_.build(); + } } @java.lang.Override @@ -1625,6 +3188,11 @@ public Builder mergeFrom(com.google.firestore.admin.v1.Index.IndexField other) { setArrayConfigValue(other.getArrayConfigValue()); break; } + case VECTOR_CONFIG: + { + mergeVectorConfig(other.getVectorConfig()); + break; + } case VALUEMODE_NOT_SET: { break; @@ -1676,6 +3244,12 @@ public Builder mergeFrom( valueMode_ = rawValue; break; } // case 24 + case 34: + { + input.readMessage(getVectorConfigFieldBuilder().getBuilder(), extensionRegistry); + valueModeCase_ = 4; + break; + } // case 34 default: { if (!super.parseUnknownField(input, extensionRegistry, tag)) { @@ -2062,6 +3636,231 @@ public Builder clearArrayConfig() { return this; } + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.Index.IndexField.VectorConfig, + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.Builder, + com.google.firestore.admin.v1.Index.IndexField.VectorConfigOrBuilder> + vectorConfigBuilder_; + /** + * + * + *
+       * Indicates that this field supports nearest neighbors and distance
+       * operations on vector.
+       * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig vector_config = 4; + * + * @return Whether the vectorConfig field is set. + */ + @java.lang.Override + public boolean hasVectorConfig() { + return valueModeCase_ == 4; + } + /** + * + * + *
+       * Indicates that this field supports nearest neighbors and distance
+       * operations on vector.
+       * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig vector_config = 4; + * + * @return The vectorConfig. + */ + @java.lang.Override + public com.google.firestore.admin.v1.Index.IndexField.VectorConfig getVectorConfig() { + if (vectorConfigBuilder_ == null) { + if (valueModeCase_ == 4) { + return (com.google.firestore.admin.v1.Index.IndexField.VectorConfig) valueMode_; + } + return com.google.firestore.admin.v1.Index.IndexField.VectorConfig.getDefaultInstance(); + } else { + if (valueModeCase_ == 4) { + return vectorConfigBuilder_.getMessage(); + } + return com.google.firestore.admin.v1.Index.IndexField.VectorConfig.getDefaultInstance(); + } + } + /** + * + * + *
+       * Indicates that this field supports nearest neighbors and distance
+       * operations on vector.
+       * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig vector_config = 4; + */ + public Builder setVectorConfig( + com.google.firestore.admin.v1.Index.IndexField.VectorConfig value) { + if (vectorConfigBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + valueMode_ = value; + onChanged(); + } else { + vectorConfigBuilder_.setMessage(value); + } + valueModeCase_ = 4; + return this; + } + /** + * + * + *
+       * Indicates that this field supports nearest neighbors and distance
+       * operations on vector.
+       * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig vector_config = 4; + */ + public Builder setVectorConfig( + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.Builder builderForValue) { + if (vectorConfigBuilder_ == null) { + valueMode_ = builderForValue.build(); + onChanged(); + } else { + vectorConfigBuilder_.setMessage(builderForValue.build()); + } + valueModeCase_ = 4; + return this; + } + /** + * + * + *
+       * Indicates that this field supports nearest neighbors and distance
+       * operations on vector.
+       * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig vector_config = 4; + */ + public Builder mergeVectorConfig( + com.google.firestore.admin.v1.Index.IndexField.VectorConfig value) { + if (vectorConfigBuilder_ == null) { + if (valueModeCase_ == 4 + && valueMode_ + != com.google.firestore.admin.v1.Index.IndexField.VectorConfig + .getDefaultInstance()) { + valueMode_ = + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.newBuilder( + (com.google.firestore.admin.v1.Index.IndexField.VectorConfig) valueMode_) + .mergeFrom(value) + .buildPartial(); + } else { + valueMode_ = value; + } + onChanged(); + } else { + if (valueModeCase_ == 4) { + vectorConfigBuilder_.mergeFrom(value); + } else { + vectorConfigBuilder_.setMessage(value); + } + } + valueModeCase_ = 4; + return this; + } + /** + * + * + *
+       * Indicates that this field supports nearest neighbors and distance
+       * operations on vector.
+       * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig vector_config = 4; + */ + public Builder clearVectorConfig() { + if (vectorConfigBuilder_ == null) { + if (valueModeCase_ == 4) { + valueModeCase_ = 0; + valueMode_ = null; + onChanged(); + } + } else { + if (valueModeCase_ == 4) { + valueModeCase_ = 0; + valueMode_ = null; + } + vectorConfigBuilder_.clear(); + } + return this; + } + /** + * + * + *
+       * Indicates that this field supports nearest neighbors and distance
+       * operations on vector.
+       * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig vector_config = 4; + */ + public com.google.firestore.admin.v1.Index.IndexField.VectorConfig.Builder + getVectorConfigBuilder() { + return getVectorConfigFieldBuilder().getBuilder(); + } + /** + * + * + *
+       * Indicates that this field supports nearest neighbors and distance
+       * operations on vector.
+       * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig vector_config = 4; + */ + @java.lang.Override + public com.google.firestore.admin.v1.Index.IndexField.VectorConfigOrBuilder + getVectorConfigOrBuilder() { + if ((valueModeCase_ == 4) && (vectorConfigBuilder_ != null)) { + return vectorConfigBuilder_.getMessageOrBuilder(); + } else { + if (valueModeCase_ == 4) { + return (com.google.firestore.admin.v1.Index.IndexField.VectorConfig) valueMode_; + } + return com.google.firestore.admin.v1.Index.IndexField.VectorConfig.getDefaultInstance(); + } + } + /** + * + * + *
+       * Indicates that this field supports nearest neighbors and distance
+       * operations on vector.
+       * 
+ * + * .google.firestore.admin.v1.Index.IndexField.VectorConfig vector_config = 4; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.Index.IndexField.VectorConfig, + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.Builder, + com.google.firestore.admin.v1.Index.IndexField.VectorConfigOrBuilder> + getVectorConfigFieldBuilder() { + if (vectorConfigBuilder_ == null) { + if (!(valueModeCase_ == 4)) { + valueMode_ = + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.getDefaultInstance(); + } + vectorConfigBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.Index.IndexField.VectorConfig, + com.google.firestore.admin.v1.Index.IndexField.VectorConfig.Builder, + com.google.firestore.admin.v1.Index.IndexField.VectorConfigOrBuilder>( + (com.google.firestore.admin.v1.Index.IndexField.VectorConfig) valueMode_, + getParentForChildren(), + isClean()); + valueMode_ = null; + } + valueModeCase_ = 4; + onChanged(); + return vectorConfigBuilder_; + } + @java.lang.Override public final Builder setUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/IndexName.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/IndexName.java index 27bdd835d..efbbc0f38 100644 --- a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/IndexName.java +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/IndexName.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/IndexProto.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/IndexProto.java index 3affdd640..ccc2c0808 100644 --- a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/IndexProto.java +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/IndexProto.java @@ -36,6 +36,14 @@ public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry r internal_static_google_firestore_admin_v1_Index_IndexField_descriptor; static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_google_firestore_admin_v1_Index_IndexField_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_FlatIndex_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_FlatIndex_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { return descriptor; @@ -46,42 +54,50 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { static { java.lang.String[] descriptorData = { "\n%google/firestore/admin/v1/index.proto\022" - + "\031google.firestore.admin.v1\032\031google/api/r" - + "esource.proto\"\254\007\n\005Index\022\014\n\004name\030\001 \001(\t\022@\n" - + "\013query_scope\030\002 \001(\0162+.google.firestore.ad" - + "min.v1.Index.QueryScope\022<\n\tapi_scope\030\005 \001" - + "(\0162).google.firestore.admin.v1.Index.Api" - + "Scope\022;\n\006fields\030\003 \003(\0132+.google.firestore" - + ".admin.v1.Index.IndexField\0225\n\005state\030\004 \001(" - + "\0162&.google.firestore.admin.v1.Index.Stat" - + "e\032\275\002\n\nIndexField\022\022\n\nfield_path\030\001 \001(\t\022B\n\005" - + "order\030\002 \001(\01621.google.firestore.admin.v1." - + "Index.IndexField.OrderH\000\022O\n\014array_config" - + "\030\003 \001(\01627.google.firestore.admin.v1.Index" - + ".IndexField.ArrayConfigH\000\"=\n\005Order\022\025\n\021OR" - + "DER_UNSPECIFIED\020\000\022\r\n\tASCENDING\020\001\022\016\n\nDESC" - + "ENDING\020\002\"9\n\013ArrayConfig\022\034\n\030ARRAY_CONFIG_" - + "UNSPECIFIED\020\000\022\014\n\010CONTAINS\020\001B\014\n\nvalue_mod" - + "e\"i\n\nQueryScope\022\033\n\027QUERY_SCOPE_UNSPECIFI" - + "ED\020\000\022\016\n\nCOLLECTION\020\001\022\024\n\020COLLECTION_GROUP" - + "\020\002\022\030\n\024COLLECTION_RECURSIVE\020\003\"/\n\010ApiScope" - + "\022\013\n\007ANY_API\020\000\022\026\n\022DATASTORE_MODE_API\020\001\"I\n" - + "\005State\022\025\n\021STATE_UNSPECIFIED\020\000\022\014\n\010CREATIN" - + "G\020\001\022\t\n\005READY\020\002\022\020\n\014NEEDS_REPAIR\020\003:z\352Aw\n\036f" - + "irestore.googleapis.com/Index\022Uprojects/" - + "{project}/databases/{database}/collectio" - + "nGroups/{collection}/indexes/{index}B\331\001\n" - + "\035com.google.firestore.admin.v1B\nIndexPro" - + "toP\001Z9cloud.google.com/go/firestore/apiv" - + "1/admin/adminpb;adminpb\242\002\004GCFS\252\002\037Google." - + "Cloud.Firestore.Admin.V1\312\002\037Google\\Cloud\\" - + "Firestore\\Admin\\V1\352\002#Google::Cloud::Fire" - + "store::Admin::V1b\006proto3" + + "\031google.firestore.admin.v1\032\037google/api/f" + + "ield_behavior.proto\032\031google/api/resource" + + ".proto\"\221\t\n\005Index\022\014\n\004name\030\001 \001(\t\022@\n\013query_" + + "scope\030\002 \001(\0162+.google.firestore.admin.v1." + + "Index.QueryScope\022<\n\tapi_scope\030\005 \001(\0162).go" + + "ogle.firestore.admin.v1.Index.ApiScope\022;" + + "\n\006fields\030\003 \003(\0132+.google.firestore.admin." + + "v1.Index.IndexField\0225\n\005state\030\004 \001(\0162&.goo" + + "gle.firestore.admin.v1.Index.State\032\242\004\n\nI" + + "ndexField\022\022\n\nfield_path\030\001 \001(\t\022B\n\005order\030\002" + + " \001(\01621.google.firestore.admin.v1.Index.I" + + "ndexField.OrderH\000\022O\n\014array_config\030\003 \001(\0162" + + "7.google.firestore.admin.v1.Index.IndexF" + + "ield.ArrayConfigH\000\022Q\n\rvector_config\030\004 \001(" + + "\01328.google.firestore.admin.v1.Index.Inde" + + "xField.VectorConfigH\000\032\217\001\n\014VectorConfig\022\026" + + "\n\tdimension\030\001 \001(\005B\003\340A\002\022R\n\004flat\030\002 \001(\0132B.g" + + "oogle.firestore.admin.v1.Index.IndexFiel" + + "d.VectorConfig.FlatIndexH\000\032\013\n\tFlatIndexB" + + "\006\n\004type\"=\n\005Order\022\025\n\021ORDER_UNSPECIFIED\020\000\022" + + "\r\n\tASCENDING\020\001\022\016\n\nDESCENDING\020\002\"9\n\013ArrayC" + + "onfig\022\034\n\030ARRAY_CONFIG_UNSPECIFIED\020\000\022\014\n\010C" + + "ONTAINS\020\001B\014\n\nvalue_mode\"i\n\nQueryScope\022\033\n" + + "\027QUERY_SCOPE_UNSPECIFIED\020\000\022\016\n\nCOLLECTION" + + "\020\001\022\024\n\020COLLECTION_GROUP\020\002\022\030\n\024COLLECTION_R" + + "ECURSIVE\020\003\"/\n\010ApiScope\022\013\n\007ANY_API\020\000\022\026\n\022D" + + "ATASTORE_MODE_API\020\001\"I\n\005State\022\025\n\021STATE_UN" + + "SPECIFIED\020\000\022\014\n\010CREATING\020\001\022\t\n\005READY\020\002\022\020\n\014" + + "NEEDS_REPAIR\020\003:z\352Aw\n\036firestore.googleapi" + + "s.com/Index\022Uprojects/{project}/database" + + "s/{database}/collectionGroups/{collectio" + + "n}/indexes/{index}B\331\001\n\035com.google.firest" + + "ore.admin.v1B\nIndexProtoP\001Z9cloud.google" + + ".com/go/firestore/apiv1/admin/adminpb;ad" + + "minpb\242\002\004GCFS\252\002\037Google.Cloud.Firestore.Ad" + + "min.V1\312\002\037Google\\Cloud\\Firestore\\Admin\\V1" + + "\352\002#Google::Cloud::Firestore::Admin::V1b\006" + + "proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] { + com.google.api.FieldBehaviorProto.getDescriptor(), com.google.api.ResourceProto.getDescriptor(), }); internal_static_google_firestore_admin_v1_Index_descriptor = @@ -98,13 +114,33 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_firestore_admin_v1_Index_IndexField_descriptor, new java.lang.String[] { - "FieldPath", "Order", "ArrayConfig", "ValueMode", + "FieldPath", "Order", "ArrayConfig", "VectorConfig", "ValueMode", }); + internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_descriptor = + internal_static_google_firestore_admin_v1_Index_IndexField_descriptor + .getNestedTypes() + .get(0); + internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_descriptor, + new java.lang.String[] { + "Dimension", "Flat", "Type", + }); + internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_FlatIndex_descriptor = + internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_descriptor + .getNestedTypes() + .get(0); + internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_FlatIndex_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_Index_IndexField_VectorConfig_FlatIndex_descriptor, + new java.lang.String[] {}); com.google.protobuf.ExtensionRegistry registry = com.google.protobuf.ExtensionRegistry.newInstance(); + registry.add(com.google.api.FieldBehaviorProto.fieldBehavior); registry.add(com.google.api.ResourceProto.resource); com.google.protobuf.Descriptors.FileDescriptor.internalUpdateFileDescriptor( descriptor, registry); + com.google.api.FieldBehaviorProto.getDescriptor(); com.google.api.ResourceProto.getDescriptor(); } diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupSchedulesRequest.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupSchedulesRequest.java new file mode 100644 index 000000000..c8f38c04c --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupSchedulesRequest.java @@ -0,0 +1,656 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +/** + * + * + *
+ * The request for
+ * [FirestoreAdmin.ListBackupSchedules][google.firestore.admin.v1.FirestoreAdmin.ListBackupSchedules].
+ * 
+ * + * Protobuf type {@code google.firestore.admin.v1.ListBackupSchedulesRequest} + */ +public final class ListBackupSchedulesRequest extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.ListBackupSchedulesRequest) + ListBackupSchedulesRequestOrBuilder { + private static final long serialVersionUID = 0L; + // Use ListBackupSchedulesRequest.newBuilder() to construct. + private ListBackupSchedulesRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private ListBackupSchedulesRequest() { + parent_ = ""; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new ListBackupSchedulesRequest(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupSchedulesRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupSchedulesRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.ListBackupSchedulesRequest.class, + com.google.firestore.admin.v1.ListBackupSchedulesRequest.Builder.class); + } + + public static final int PARENT_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile java.lang.Object parent_ = ""; + /** + * + * + *
+   * Required. The parent database.
+   *
+   * Format is `projects/{project}/databases/{database}`.
+   * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The parent. + */ + @java.lang.Override + public java.lang.String getParent() { + java.lang.Object ref = parent_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + parent_ = s; + return s; + } + } + /** + * + * + *
+   * Required. The parent database.
+   *
+   * Format is `projects/{project}/databases/{database}`.
+   * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for parent. + */ + @java.lang.Override + public com.google.protobuf.ByteString getParentBytes() { + java.lang.Object ref = parent_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + parent_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(parent_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, parent_); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(parent_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, parent_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.admin.v1.ListBackupSchedulesRequest)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.ListBackupSchedulesRequest other = + (com.google.firestore.admin.v1.ListBackupSchedulesRequest) obj; + + if (!getParent().equals(other.getParent())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + PARENT_FIELD_NUMBER; + hash = (53 * hash) + getParent().hashCode(); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesRequest parseFrom( + java.nio.ByteBuffer data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesRequest parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesRequest parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesRequest parseFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesRequest parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesRequest parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesRequest parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesRequest parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder( + com.google.firestore.admin.v1.ListBackupSchedulesRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * The request for
+   * [FirestoreAdmin.ListBackupSchedules][google.firestore.admin.v1.FirestoreAdmin.ListBackupSchedules].
+   * 
+ * + * Protobuf type {@code google.firestore.admin.v1.ListBackupSchedulesRequest} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.ListBackupSchedulesRequest) + com.google.firestore.admin.v1.ListBackupSchedulesRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupSchedulesRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupSchedulesRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.ListBackupSchedulesRequest.class, + com.google.firestore.admin.v1.ListBackupSchedulesRequest.Builder.class); + } + + // Construct using com.google.firestore.admin.v1.ListBackupSchedulesRequest.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + parent_ = ""; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupSchedulesRequest_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.ListBackupSchedulesRequest getDefaultInstanceForType() { + return com.google.firestore.admin.v1.ListBackupSchedulesRequest.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.ListBackupSchedulesRequest build() { + com.google.firestore.admin.v1.ListBackupSchedulesRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.ListBackupSchedulesRequest buildPartial() { + com.google.firestore.admin.v1.ListBackupSchedulesRequest result = + new com.google.firestore.admin.v1.ListBackupSchedulesRequest(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.admin.v1.ListBackupSchedulesRequest result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.parent_ = parent_; + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.admin.v1.ListBackupSchedulesRequest) { + return mergeFrom((com.google.firestore.admin.v1.ListBackupSchedulesRequest) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.admin.v1.ListBackupSchedulesRequest other) { + if (other == com.google.firestore.admin.v1.ListBackupSchedulesRequest.getDefaultInstance()) + return this; + if (!other.getParent().isEmpty()) { + parent_ = other.parent_; + bitField0_ |= 0x00000001; + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + parent_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private java.lang.Object parent_ = ""; + /** + * + * + *
+     * Required. The parent database.
+     *
+     * Format is `projects/{project}/databases/{database}`.
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The parent. + */ + public java.lang.String getParent() { + java.lang.Object ref = parent_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + parent_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * Required. The parent database.
+     *
+     * Format is `projects/{project}/databases/{database}`.
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for parent. + */ + public com.google.protobuf.ByteString getParentBytes() { + java.lang.Object ref = parent_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + parent_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * Required. The parent database.
+     *
+     * Format is `projects/{project}/databases/{database}`.
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @param value The parent to set. + * @return This builder for chaining. + */ + public Builder setParent(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + parent_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The parent database.
+     *
+     * Format is `projects/{project}/databases/{database}`.
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return This builder for chaining. + */ + public Builder clearParent() { + parent_ = getDefaultInstance().getParent(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The parent database.
+     *
+     * Format is `projects/{project}/databases/{database}`.
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @param value The bytes for parent to set. + * @return This builder for chaining. + */ + public Builder setParentBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + parent_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.ListBackupSchedulesRequest) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.ListBackupSchedulesRequest) + private static final com.google.firestore.admin.v1.ListBackupSchedulesRequest DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.admin.v1.ListBackupSchedulesRequest(); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public ListBackupSchedulesRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.ListBackupSchedulesRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupSchedulesRequestOrBuilder.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupSchedulesRequestOrBuilder.java new file mode 100644 index 000000000..c2d083160 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupSchedulesRequestOrBuilder.java @@ -0,0 +1,59 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +public interface ListBackupSchedulesRequestOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.ListBackupSchedulesRequest) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * Required. The parent database.
+   *
+   * Format is `projects/{project}/databases/{database}`.
+   * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The parent. + */ + java.lang.String getParent(); + /** + * + * + *
+   * Required. The parent database.
+   *
+   * Format is `projects/{project}/databases/{database}`.
+   * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for parent. + */ + com.google.protobuf.ByteString getParentBytes(); +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupSchedulesResponse.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupSchedulesResponse.java new file mode 100644 index 000000000..ea2ac8418 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupSchedulesResponse.java @@ -0,0 +1,950 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +/** + * + * + *
+ * The response for
+ * [FirestoreAdmin.ListBackupSchedules][google.firestore.admin.v1.FirestoreAdmin.ListBackupSchedules].
+ * 
+ * + * Protobuf type {@code google.firestore.admin.v1.ListBackupSchedulesResponse} + */ +public final class ListBackupSchedulesResponse extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.ListBackupSchedulesResponse) + ListBackupSchedulesResponseOrBuilder { + private static final long serialVersionUID = 0L; + // Use ListBackupSchedulesResponse.newBuilder() to construct. + private ListBackupSchedulesResponse(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private ListBackupSchedulesResponse() { + backupSchedules_ = java.util.Collections.emptyList(); + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new ListBackupSchedulesResponse(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupSchedulesResponse_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupSchedulesResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.ListBackupSchedulesResponse.class, + com.google.firestore.admin.v1.ListBackupSchedulesResponse.Builder.class); + } + + public static final int BACKUP_SCHEDULES_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private java.util.List backupSchedules_; + /** + * + * + *
+   * List of all backup schedules.
+   * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + @java.lang.Override + public java.util.List getBackupSchedulesList() { + return backupSchedules_; + } + /** + * + * + *
+   * List of all backup schedules.
+   * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + @java.lang.Override + public java.util.List + getBackupSchedulesOrBuilderList() { + return backupSchedules_; + } + /** + * + * + *
+   * List of all backup schedules.
+   * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + @java.lang.Override + public int getBackupSchedulesCount() { + return backupSchedules_.size(); + } + /** + * + * + *
+   * List of all backup schedules.
+   * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + @java.lang.Override + public com.google.firestore.admin.v1.BackupSchedule getBackupSchedules(int index) { + return backupSchedules_.get(index); + } + /** + * + * + *
+   * List of all backup schedules.
+   * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + @java.lang.Override + public com.google.firestore.admin.v1.BackupScheduleOrBuilder getBackupSchedulesOrBuilder( + int index) { + return backupSchedules_.get(index); + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + for (int i = 0; i < backupSchedules_.size(); i++) { + output.writeMessage(1, backupSchedules_.get(i)); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + for (int i = 0; i < backupSchedules_.size(); i++) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(1, backupSchedules_.get(i)); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.admin.v1.ListBackupSchedulesResponse)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.ListBackupSchedulesResponse other = + (com.google.firestore.admin.v1.ListBackupSchedulesResponse) obj; + + if (!getBackupSchedulesList().equals(other.getBackupSchedulesList())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (getBackupSchedulesCount() > 0) { + hash = (37 * hash) + BACKUP_SCHEDULES_FIELD_NUMBER; + hash = (53 * hash) + getBackupSchedulesList().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesResponse parseFrom( + java.nio.ByteBuffer data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesResponse parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesResponse parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesResponse parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesResponse parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesResponse parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesResponse parseFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesResponse parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesResponse parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesResponse parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesResponse parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesResponse parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder( + com.google.firestore.admin.v1.ListBackupSchedulesResponse prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * The response for
+   * [FirestoreAdmin.ListBackupSchedules][google.firestore.admin.v1.FirestoreAdmin.ListBackupSchedules].
+   * 
+ * + * Protobuf type {@code google.firestore.admin.v1.ListBackupSchedulesResponse} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.ListBackupSchedulesResponse) + com.google.firestore.admin.v1.ListBackupSchedulesResponseOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupSchedulesResponse_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupSchedulesResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.ListBackupSchedulesResponse.class, + com.google.firestore.admin.v1.ListBackupSchedulesResponse.Builder.class); + } + + // Construct using com.google.firestore.admin.v1.ListBackupSchedulesResponse.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + if (backupSchedulesBuilder_ == null) { + backupSchedules_ = java.util.Collections.emptyList(); + } else { + backupSchedules_ = null; + backupSchedulesBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000001); + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupSchedulesResponse_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.ListBackupSchedulesResponse getDefaultInstanceForType() { + return com.google.firestore.admin.v1.ListBackupSchedulesResponse.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.ListBackupSchedulesResponse build() { + com.google.firestore.admin.v1.ListBackupSchedulesResponse result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.ListBackupSchedulesResponse buildPartial() { + com.google.firestore.admin.v1.ListBackupSchedulesResponse result = + new com.google.firestore.admin.v1.ListBackupSchedulesResponse(this); + buildPartialRepeatedFields(result); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartialRepeatedFields( + com.google.firestore.admin.v1.ListBackupSchedulesResponse result) { + if (backupSchedulesBuilder_ == null) { + if (((bitField0_ & 0x00000001) != 0)) { + backupSchedules_ = java.util.Collections.unmodifiableList(backupSchedules_); + bitField0_ = (bitField0_ & ~0x00000001); + } + result.backupSchedules_ = backupSchedules_; + } else { + result.backupSchedules_ = backupSchedulesBuilder_.build(); + } + } + + private void buildPartial0(com.google.firestore.admin.v1.ListBackupSchedulesResponse result) { + int from_bitField0_ = bitField0_; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.admin.v1.ListBackupSchedulesResponse) { + return mergeFrom((com.google.firestore.admin.v1.ListBackupSchedulesResponse) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.admin.v1.ListBackupSchedulesResponse other) { + if (other == com.google.firestore.admin.v1.ListBackupSchedulesResponse.getDefaultInstance()) + return this; + if (backupSchedulesBuilder_ == null) { + if (!other.backupSchedules_.isEmpty()) { + if (backupSchedules_.isEmpty()) { + backupSchedules_ = other.backupSchedules_; + bitField0_ = (bitField0_ & ~0x00000001); + } else { + ensureBackupSchedulesIsMutable(); + backupSchedules_.addAll(other.backupSchedules_); + } + onChanged(); + } + } else { + if (!other.backupSchedules_.isEmpty()) { + if (backupSchedulesBuilder_.isEmpty()) { + backupSchedulesBuilder_.dispose(); + backupSchedulesBuilder_ = null; + backupSchedules_ = other.backupSchedules_; + bitField0_ = (bitField0_ & ~0x00000001); + backupSchedulesBuilder_ = + com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders + ? getBackupSchedulesFieldBuilder() + : null; + } else { + backupSchedulesBuilder_.addAllMessages(other.backupSchedules_); + } + } + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + com.google.firestore.admin.v1.BackupSchedule m = + input.readMessage( + com.google.firestore.admin.v1.BackupSchedule.parser(), extensionRegistry); + if (backupSchedulesBuilder_ == null) { + ensureBackupSchedulesIsMutable(); + backupSchedules_.add(m); + } else { + backupSchedulesBuilder_.addMessage(m); + } + break; + } // case 10 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private java.util.List backupSchedules_ = + java.util.Collections.emptyList(); + + private void ensureBackupSchedulesIsMutable() { + if (!((bitField0_ & 0x00000001) != 0)) { + backupSchedules_ = + new java.util.ArrayList(backupSchedules_); + bitField0_ |= 0x00000001; + } + } + + private com.google.protobuf.RepeatedFieldBuilderV3< + com.google.firestore.admin.v1.BackupSchedule, + com.google.firestore.admin.v1.BackupSchedule.Builder, + com.google.firestore.admin.v1.BackupScheduleOrBuilder> + backupSchedulesBuilder_; + + /** + * + * + *
+     * List of all backup schedules.
+     * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + public java.util.List getBackupSchedulesList() { + if (backupSchedulesBuilder_ == null) { + return java.util.Collections.unmodifiableList(backupSchedules_); + } else { + return backupSchedulesBuilder_.getMessageList(); + } + } + /** + * + * + *
+     * List of all backup schedules.
+     * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + public int getBackupSchedulesCount() { + if (backupSchedulesBuilder_ == null) { + return backupSchedules_.size(); + } else { + return backupSchedulesBuilder_.getCount(); + } + } + /** + * + * + *
+     * List of all backup schedules.
+     * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + public com.google.firestore.admin.v1.BackupSchedule getBackupSchedules(int index) { + if (backupSchedulesBuilder_ == null) { + return backupSchedules_.get(index); + } else { + return backupSchedulesBuilder_.getMessage(index); + } + } + /** + * + * + *
+     * List of all backup schedules.
+     * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + public Builder setBackupSchedules( + int index, com.google.firestore.admin.v1.BackupSchedule value) { + if (backupSchedulesBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureBackupSchedulesIsMutable(); + backupSchedules_.set(index, value); + onChanged(); + } else { + backupSchedulesBuilder_.setMessage(index, value); + } + return this; + } + /** + * + * + *
+     * List of all backup schedules.
+     * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + public Builder setBackupSchedules( + int index, com.google.firestore.admin.v1.BackupSchedule.Builder builderForValue) { + if (backupSchedulesBuilder_ == null) { + ensureBackupSchedulesIsMutable(); + backupSchedules_.set(index, builderForValue.build()); + onChanged(); + } else { + backupSchedulesBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + /** + * + * + *
+     * List of all backup schedules.
+     * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + public Builder addBackupSchedules(com.google.firestore.admin.v1.BackupSchedule value) { + if (backupSchedulesBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureBackupSchedulesIsMutable(); + backupSchedules_.add(value); + onChanged(); + } else { + backupSchedulesBuilder_.addMessage(value); + } + return this; + } + /** + * + * + *
+     * List of all backup schedules.
+     * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + public Builder addBackupSchedules( + int index, com.google.firestore.admin.v1.BackupSchedule value) { + if (backupSchedulesBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureBackupSchedulesIsMutable(); + backupSchedules_.add(index, value); + onChanged(); + } else { + backupSchedulesBuilder_.addMessage(index, value); + } + return this; + } + /** + * + * + *
+     * List of all backup schedules.
+     * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + public Builder addBackupSchedules( + com.google.firestore.admin.v1.BackupSchedule.Builder builderForValue) { + if (backupSchedulesBuilder_ == null) { + ensureBackupSchedulesIsMutable(); + backupSchedules_.add(builderForValue.build()); + onChanged(); + } else { + backupSchedulesBuilder_.addMessage(builderForValue.build()); + } + return this; + } + /** + * + * + *
+     * List of all backup schedules.
+     * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + public Builder addBackupSchedules( + int index, com.google.firestore.admin.v1.BackupSchedule.Builder builderForValue) { + if (backupSchedulesBuilder_ == null) { + ensureBackupSchedulesIsMutable(); + backupSchedules_.add(index, builderForValue.build()); + onChanged(); + } else { + backupSchedulesBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + /** + * + * + *
+     * List of all backup schedules.
+     * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + public Builder addAllBackupSchedules( + java.lang.Iterable values) { + if (backupSchedulesBuilder_ == null) { + ensureBackupSchedulesIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll(values, backupSchedules_); + onChanged(); + } else { + backupSchedulesBuilder_.addAllMessages(values); + } + return this; + } + /** + * + * + *
+     * List of all backup schedules.
+     * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + public Builder clearBackupSchedules() { + if (backupSchedulesBuilder_ == null) { + backupSchedules_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + } else { + backupSchedulesBuilder_.clear(); + } + return this; + } + /** + * + * + *
+     * List of all backup schedules.
+     * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + public Builder removeBackupSchedules(int index) { + if (backupSchedulesBuilder_ == null) { + ensureBackupSchedulesIsMutable(); + backupSchedules_.remove(index); + onChanged(); + } else { + backupSchedulesBuilder_.remove(index); + } + return this; + } + /** + * + * + *
+     * List of all backup schedules.
+     * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + public com.google.firestore.admin.v1.BackupSchedule.Builder getBackupSchedulesBuilder( + int index) { + return getBackupSchedulesFieldBuilder().getBuilder(index); + } + /** + * + * + *
+     * List of all backup schedules.
+     * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + public com.google.firestore.admin.v1.BackupScheduleOrBuilder getBackupSchedulesOrBuilder( + int index) { + if (backupSchedulesBuilder_ == null) { + return backupSchedules_.get(index); + } else { + return backupSchedulesBuilder_.getMessageOrBuilder(index); + } + } + /** + * + * + *
+     * List of all backup schedules.
+     * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + public java.util.List + getBackupSchedulesOrBuilderList() { + if (backupSchedulesBuilder_ != null) { + return backupSchedulesBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(backupSchedules_); + } + } + /** + * + * + *
+     * List of all backup schedules.
+     * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + public com.google.firestore.admin.v1.BackupSchedule.Builder addBackupSchedulesBuilder() { + return getBackupSchedulesFieldBuilder() + .addBuilder(com.google.firestore.admin.v1.BackupSchedule.getDefaultInstance()); + } + /** + * + * + *
+     * List of all backup schedules.
+     * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + public com.google.firestore.admin.v1.BackupSchedule.Builder addBackupSchedulesBuilder( + int index) { + return getBackupSchedulesFieldBuilder() + .addBuilder(index, com.google.firestore.admin.v1.BackupSchedule.getDefaultInstance()); + } + /** + * + * + *
+     * List of all backup schedules.
+     * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + public java.util.List + getBackupSchedulesBuilderList() { + return getBackupSchedulesFieldBuilder().getBuilderList(); + } + + private com.google.protobuf.RepeatedFieldBuilderV3< + com.google.firestore.admin.v1.BackupSchedule, + com.google.firestore.admin.v1.BackupSchedule.Builder, + com.google.firestore.admin.v1.BackupScheduleOrBuilder> + getBackupSchedulesFieldBuilder() { + if (backupSchedulesBuilder_ == null) { + backupSchedulesBuilder_ = + new com.google.protobuf.RepeatedFieldBuilderV3< + com.google.firestore.admin.v1.BackupSchedule, + com.google.firestore.admin.v1.BackupSchedule.Builder, + com.google.firestore.admin.v1.BackupScheduleOrBuilder>( + backupSchedules_, + ((bitField0_ & 0x00000001) != 0), + getParentForChildren(), + isClean()); + backupSchedules_ = null; + } + return backupSchedulesBuilder_; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.ListBackupSchedulesResponse) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.ListBackupSchedulesResponse) + private static final com.google.firestore.admin.v1.ListBackupSchedulesResponse DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.admin.v1.ListBackupSchedulesResponse(); + } + + public static com.google.firestore.admin.v1.ListBackupSchedulesResponse getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public ListBackupSchedulesResponse parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.ListBackupSchedulesResponse getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupSchedulesResponseOrBuilder.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupSchedulesResponseOrBuilder.java new file mode 100644 index 000000000..eea1e95de --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupSchedulesResponseOrBuilder.java @@ -0,0 +1,78 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +public interface ListBackupSchedulesResponseOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.ListBackupSchedulesResponse) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * List of all backup schedules.
+   * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + java.util.List getBackupSchedulesList(); + /** + * + * + *
+   * List of all backup schedules.
+   * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + com.google.firestore.admin.v1.BackupSchedule getBackupSchedules(int index); + /** + * + * + *
+   * List of all backup schedules.
+   * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + int getBackupSchedulesCount(); + /** + * + * + *
+   * List of all backup schedules.
+   * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + java.util.List + getBackupSchedulesOrBuilderList(); + /** + * + * + *
+   * List of all backup schedules.
+   * 
+ * + * repeated .google.firestore.admin.v1.BackupSchedule backup_schedules = 1; + */ + com.google.firestore.admin.v1.BackupScheduleOrBuilder getBackupSchedulesOrBuilder(int index); +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupsRequest.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupsRequest.java new file mode 100644 index 000000000..63727c091 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupsRequest.java @@ -0,0 +1,676 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +/** + * + * + *
+ * The request for
+ * [FirestoreAdmin.ListBackups][google.firestore.admin.v1.FirestoreAdmin.ListBackups].
+ * 
+ * + * Protobuf type {@code google.firestore.admin.v1.ListBackupsRequest} + */ +public final class ListBackupsRequest extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.ListBackupsRequest) + ListBackupsRequestOrBuilder { + private static final long serialVersionUID = 0L; + // Use ListBackupsRequest.newBuilder() to construct. + private ListBackupsRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private ListBackupsRequest() { + parent_ = ""; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new ListBackupsRequest(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupsRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupsRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.ListBackupsRequest.class, + com.google.firestore.admin.v1.ListBackupsRequest.Builder.class); + } + + public static final int PARENT_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile java.lang.Object parent_ = ""; + /** + * + * + *
+   * Required. The location to list backups from.
+   *
+   * Format is `projects/{project}/locations/{location}`.
+   * Use `{location} = '-'` to list backups from all locations for the given
+   * project. This allows listing backups from a single location or from all
+   * locations.
+   * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The parent. + */ + @java.lang.Override + public java.lang.String getParent() { + java.lang.Object ref = parent_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + parent_ = s; + return s; + } + } + /** + * + * + *
+   * Required. The location to list backups from.
+   *
+   * Format is `projects/{project}/locations/{location}`.
+   * Use `{location} = '-'` to list backups from all locations for the given
+   * project. This allows listing backups from a single location or from all
+   * locations.
+   * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for parent. + */ + @java.lang.Override + public com.google.protobuf.ByteString getParentBytes() { + java.lang.Object ref = parent_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + parent_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(parent_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, parent_); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(parent_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, parent_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.admin.v1.ListBackupsRequest)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.ListBackupsRequest other = + (com.google.firestore.admin.v1.ListBackupsRequest) obj; + + if (!getParent().equals(other.getParent())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + PARENT_FIELD_NUMBER; + hash = (53 * hash) + getParent().hashCode(); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.ListBackupsRequest parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.ListBackupsRequest parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupsRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.ListBackupsRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupsRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.ListBackupsRequest parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupsRequest parseFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.ListBackupsRequest parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupsRequest parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.ListBackupsRequest parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupsRequest parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.ListBackupsRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.admin.v1.ListBackupsRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * The request for
+   * [FirestoreAdmin.ListBackups][google.firestore.admin.v1.FirestoreAdmin.ListBackups].
+   * 
+ * + * Protobuf type {@code google.firestore.admin.v1.ListBackupsRequest} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.ListBackupsRequest) + com.google.firestore.admin.v1.ListBackupsRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupsRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupsRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.ListBackupsRequest.class, + com.google.firestore.admin.v1.ListBackupsRequest.Builder.class); + } + + // Construct using com.google.firestore.admin.v1.ListBackupsRequest.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + parent_ = ""; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupsRequest_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.ListBackupsRequest getDefaultInstanceForType() { + return com.google.firestore.admin.v1.ListBackupsRequest.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.ListBackupsRequest build() { + com.google.firestore.admin.v1.ListBackupsRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.ListBackupsRequest buildPartial() { + com.google.firestore.admin.v1.ListBackupsRequest result = + new com.google.firestore.admin.v1.ListBackupsRequest(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.admin.v1.ListBackupsRequest result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.parent_ = parent_; + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.admin.v1.ListBackupsRequest) { + return mergeFrom((com.google.firestore.admin.v1.ListBackupsRequest) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.admin.v1.ListBackupsRequest other) { + if (other == com.google.firestore.admin.v1.ListBackupsRequest.getDefaultInstance()) + return this; + if (!other.getParent().isEmpty()) { + parent_ = other.parent_; + bitField0_ |= 0x00000001; + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + parent_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private java.lang.Object parent_ = ""; + /** + * + * + *
+     * Required. The location to list backups from.
+     *
+     * Format is `projects/{project}/locations/{location}`.
+     * Use `{location} = '-'` to list backups from all locations for the given
+     * project. This allows listing backups from a single location or from all
+     * locations.
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The parent. + */ + public java.lang.String getParent() { + java.lang.Object ref = parent_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + parent_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * Required. The location to list backups from.
+     *
+     * Format is `projects/{project}/locations/{location}`.
+     * Use `{location} = '-'` to list backups from all locations for the given
+     * project. This allows listing backups from a single location or from all
+     * locations.
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for parent. + */ + public com.google.protobuf.ByteString getParentBytes() { + java.lang.Object ref = parent_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + parent_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * Required. The location to list backups from.
+     *
+     * Format is `projects/{project}/locations/{location}`.
+     * Use `{location} = '-'` to list backups from all locations for the given
+     * project. This allows listing backups from a single location or from all
+     * locations.
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @param value The parent to set. + * @return This builder for chaining. + */ + public Builder setParent(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + parent_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The location to list backups from.
+     *
+     * Format is `projects/{project}/locations/{location}`.
+     * Use `{location} = '-'` to list backups from all locations for the given
+     * project. This allows listing backups from a single location or from all
+     * locations.
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return This builder for chaining. + */ + public Builder clearParent() { + parent_ = getDefaultInstance().getParent(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The location to list backups from.
+     *
+     * Format is `projects/{project}/locations/{location}`.
+     * Use `{location} = '-'` to list backups from all locations for the given
+     * project. This allows listing backups from a single location or from all
+     * locations.
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @param value The bytes for parent to set. + * @return This builder for chaining. + */ + public Builder setParentBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + parent_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.ListBackupsRequest) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.ListBackupsRequest) + private static final com.google.firestore.admin.v1.ListBackupsRequest DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.admin.v1.ListBackupsRequest(); + } + + public static com.google.firestore.admin.v1.ListBackupsRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public ListBackupsRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.ListBackupsRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupsRequestOrBuilder.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupsRequestOrBuilder.java new file mode 100644 index 000000000..2945d5c15 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupsRequestOrBuilder.java @@ -0,0 +1,65 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +public interface ListBackupsRequestOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.ListBackupsRequest) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * Required. The location to list backups from.
+   *
+   * Format is `projects/{project}/locations/{location}`.
+   * Use `{location} = '-'` to list backups from all locations for the given
+   * project. This allows listing backups from a single location or from all
+   * locations.
+   * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The parent. + */ + java.lang.String getParent(); + /** + * + * + *
+   * Required. The location to list backups from.
+   *
+   * Format is `projects/{project}/locations/{location}`.
+   * Use `{location} = '-'` to list backups from all locations for the given
+   * project. This allows listing backups from a single location or from all
+   * locations.
+   * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for parent. + */ + com.google.protobuf.ByteString getParentBytes(); +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupsResponse.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupsResponse.java new file mode 100644 index 000000000..728d020c9 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupsResponse.java @@ -0,0 +1,1279 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +/** + * + * + *
+ * The response for
+ * [FirestoreAdmin.ListBackups][google.firestore.admin.v1.FirestoreAdmin.ListBackups].
+ * 
+ * + * Protobuf type {@code google.firestore.admin.v1.ListBackupsResponse} + */ +public final class ListBackupsResponse extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.ListBackupsResponse) + ListBackupsResponseOrBuilder { + private static final long serialVersionUID = 0L; + // Use ListBackupsResponse.newBuilder() to construct. + private ListBackupsResponse(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private ListBackupsResponse() { + backups_ = java.util.Collections.emptyList(); + unreachable_ = com.google.protobuf.LazyStringArrayList.emptyList(); + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new ListBackupsResponse(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupsResponse_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupsResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.ListBackupsResponse.class, + com.google.firestore.admin.v1.ListBackupsResponse.Builder.class); + } + + public static final int BACKUPS_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private java.util.List backups_; + /** + * + * + *
+   * List of all backups for the project.
+   * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + @java.lang.Override + public java.util.List getBackupsList() { + return backups_; + } + /** + * + * + *
+   * List of all backups for the project.
+   * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + @java.lang.Override + public java.util.List + getBackupsOrBuilderList() { + return backups_; + } + /** + * + * + *
+   * List of all backups for the project.
+   * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + @java.lang.Override + public int getBackupsCount() { + return backups_.size(); + } + /** + * + * + *
+   * List of all backups for the project.
+   * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + @java.lang.Override + public com.google.firestore.admin.v1.Backup getBackups(int index) { + return backups_.get(index); + } + /** + * + * + *
+   * List of all backups for the project.
+   * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + @java.lang.Override + public com.google.firestore.admin.v1.BackupOrBuilder getBackupsOrBuilder(int index) { + return backups_.get(index); + } + + public static final int UNREACHABLE_FIELD_NUMBER = 3; + + @SuppressWarnings("serial") + private com.google.protobuf.LazyStringArrayList unreachable_ = + com.google.protobuf.LazyStringArrayList.emptyList(); + /** + * + * + *
+   * List of locations that existing backups were not able to be fetched from.
+   *
+   * Instead of failing the entire requests when a single location is
+   * unreachable, this response returns a partial result set and list of
+   * locations unable to be reached here. The request can be retried against a
+   * single location to get a concrete error.
+   * 
+ * + * repeated string unreachable = 3; + * + * @return A list containing the unreachable. + */ + public com.google.protobuf.ProtocolStringList getUnreachableList() { + return unreachable_; + } + /** + * + * + *
+   * List of locations that existing backups were not able to be fetched from.
+   *
+   * Instead of failing the entire requests when a single location is
+   * unreachable, this response returns a partial result set and list of
+   * locations unable to be reached here. The request can be retried against a
+   * single location to get a concrete error.
+   * 
+ * + * repeated string unreachable = 3; + * + * @return The count of unreachable. + */ + public int getUnreachableCount() { + return unreachable_.size(); + } + /** + * + * + *
+   * List of locations that existing backups were not able to be fetched from.
+   *
+   * Instead of failing the entire requests when a single location is
+   * unreachable, this response returns a partial result set and list of
+   * locations unable to be reached here. The request can be retried against a
+   * single location to get a concrete error.
+   * 
+ * + * repeated string unreachable = 3; + * + * @param index The index of the element to return. + * @return The unreachable at the given index. + */ + public java.lang.String getUnreachable(int index) { + return unreachable_.get(index); + } + /** + * + * + *
+   * List of locations that existing backups were not able to be fetched from.
+   *
+   * Instead of failing the entire requests when a single location is
+   * unreachable, this response returns a partial result set and list of
+   * locations unable to be reached here. The request can be retried against a
+   * single location to get a concrete error.
+   * 
+ * + * repeated string unreachable = 3; + * + * @param index The index of the value to return. + * @return The bytes of the unreachable at the given index. + */ + public com.google.protobuf.ByteString getUnreachableBytes(int index) { + return unreachable_.getByteString(index); + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + for (int i = 0; i < backups_.size(); i++) { + output.writeMessage(1, backups_.get(i)); + } + for (int i = 0; i < unreachable_.size(); i++) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 3, unreachable_.getRaw(i)); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + for (int i = 0; i < backups_.size(); i++) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(1, backups_.get(i)); + } + { + int dataSize = 0; + for (int i = 0; i < unreachable_.size(); i++) { + dataSize += computeStringSizeNoTag(unreachable_.getRaw(i)); + } + size += dataSize; + size += 1 * getUnreachableList().size(); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.admin.v1.ListBackupsResponse)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.ListBackupsResponse other = + (com.google.firestore.admin.v1.ListBackupsResponse) obj; + + if (!getBackupsList().equals(other.getBackupsList())) return false; + if (!getUnreachableList().equals(other.getUnreachableList())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (getBackupsCount() > 0) { + hash = (37 * hash) + BACKUPS_FIELD_NUMBER; + hash = (53 * hash) + getBackupsList().hashCode(); + } + if (getUnreachableCount() > 0) { + hash = (37 * hash) + UNREACHABLE_FIELD_NUMBER; + hash = (53 * hash) + getUnreachableList().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.ListBackupsResponse parseFrom( + java.nio.ByteBuffer data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.ListBackupsResponse parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupsResponse parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.ListBackupsResponse parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupsResponse parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.ListBackupsResponse parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupsResponse parseFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.ListBackupsResponse parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupsResponse parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.ListBackupsResponse parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.ListBackupsResponse parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.ListBackupsResponse parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.admin.v1.ListBackupsResponse prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * The response for
+   * [FirestoreAdmin.ListBackups][google.firestore.admin.v1.FirestoreAdmin.ListBackups].
+   * 
+ * + * Protobuf type {@code google.firestore.admin.v1.ListBackupsResponse} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.ListBackupsResponse) + com.google.firestore.admin.v1.ListBackupsResponseOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupsResponse_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupsResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.ListBackupsResponse.class, + com.google.firestore.admin.v1.ListBackupsResponse.Builder.class); + } + + // Construct using com.google.firestore.admin.v1.ListBackupsResponse.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + if (backupsBuilder_ == null) { + backups_ = java.util.Collections.emptyList(); + } else { + backups_ = null; + backupsBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000001); + unreachable_ = com.google.protobuf.LazyStringArrayList.emptyList(); + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_ListBackupsResponse_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.ListBackupsResponse getDefaultInstanceForType() { + return com.google.firestore.admin.v1.ListBackupsResponse.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.ListBackupsResponse build() { + com.google.firestore.admin.v1.ListBackupsResponse result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.ListBackupsResponse buildPartial() { + com.google.firestore.admin.v1.ListBackupsResponse result = + new com.google.firestore.admin.v1.ListBackupsResponse(this); + buildPartialRepeatedFields(result); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartialRepeatedFields( + com.google.firestore.admin.v1.ListBackupsResponse result) { + if (backupsBuilder_ == null) { + if (((bitField0_ & 0x00000001) != 0)) { + backups_ = java.util.Collections.unmodifiableList(backups_); + bitField0_ = (bitField0_ & ~0x00000001); + } + result.backups_ = backups_; + } else { + result.backups_ = backupsBuilder_.build(); + } + } + + private void buildPartial0(com.google.firestore.admin.v1.ListBackupsResponse result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000002) != 0)) { + unreachable_.makeImmutable(); + result.unreachable_ = unreachable_; + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.admin.v1.ListBackupsResponse) { + return mergeFrom((com.google.firestore.admin.v1.ListBackupsResponse) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.admin.v1.ListBackupsResponse other) { + if (other == com.google.firestore.admin.v1.ListBackupsResponse.getDefaultInstance()) + return this; + if (backupsBuilder_ == null) { + if (!other.backups_.isEmpty()) { + if (backups_.isEmpty()) { + backups_ = other.backups_; + bitField0_ = (bitField0_ & ~0x00000001); + } else { + ensureBackupsIsMutable(); + backups_.addAll(other.backups_); + } + onChanged(); + } + } else { + if (!other.backups_.isEmpty()) { + if (backupsBuilder_.isEmpty()) { + backupsBuilder_.dispose(); + backupsBuilder_ = null; + backups_ = other.backups_; + bitField0_ = (bitField0_ & ~0x00000001); + backupsBuilder_ = + com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders + ? getBackupsFieldBuilder() + : null; + } else { + backupsBuilder_.addAllMessages(other.backups_); + } + } + } + if (!other.unreachable_.isEmpty()) { + if (unreachable_.isEmpty()) { + unreachable_ = other.unreachable_; + bitField0_ |= 0x00000002; + } else { + ensureUnreachableIsMutable(); + unreachable_.addAll(other.unreachable_); + } + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + com.google.firestore.admin.v1.Backup m = + input.readMessage( + com.google.firestore.admin.v1.Backup.parser(), extensionRegistry); + if (backupsBuilder_ == null) { + ensureBackupsIsMutable(); + backups_.add(m); + } else { + backupsBuilder_.addMessage(m); + } + break; + } // case 10 + case 26: + { + java.lang.String s = input.readStringRequireUtf8(); + ensureUnreachableIsMutable(); + unreachable_.add(s); + break; + } // case 26 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private java.util.List backups_ = + java.util.Collections.emptyList(); + + private void ensureBackupsIsMutable() { + if (!((bitField0_ & 0x00000001) != 0)) { + backups_ = new java.util.ArrayList(backups_); + bitField0_ |= 0x00000001; + } + } + + private com.google.protobuf.RepeatedFieldBuilderV3< + com.google.firestore.admin.v1.Backup, + com.google.firestore.admin.v1.Backup.Builder, + com.google.firestore.admin.v1.BackupOrBuilder> + backupsBuilder_; + + /** + * + * + *
+     * List of all backups for the project.
+     * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + public java.util.List getBackupsList() { + if (backupsBuilder_ == null) { + return java.util.Collections.unmodifiableList(backups_); + } else { + return backupsBuilder_.getMessageList(); + } + } + /** + * + * + *
+     * List of all backups for the project.
+     * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + public int getBackupsCount() { + if (backupsBuilder_ == null) { + return backups_.size(); + } else { + return backupsBuilder_.getCount(); + } + } + /** + * + * + *
+     * List of all backups for the project.
+     * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + public com.google.firestore.admin.v1.Backup getBackups(int index) { + if (backupsBuilder_ == null) { + return backups_.get(index); + } else { + return backupsBuilder_.getMessage(index); + } + } + /** + * + * + *
+     * List of all backups for the project.
+     * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + public Builder setBackups(int index, com.google.firestore.admin.v1.Backup value) { + if (backupsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureBackupsIsMutable(); + backups_.set(index, value); + onChanged(); + } else { + backupsBuilder_.setMessage(index, value); + } + return this; + } + /** + * + * + *
+     * List of all backups for the project.
+     * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + public Builder setBackups( + int index, com.google.firestore.admin.v1.Backup.Builder builderForValue) { + if (backupsBuilder_ == null) { + ensureBackupsIsMutable(); + backups_.set(index, builderForValue.build()); + onChanged(); + } else { + backupsBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + /** + * + * + *
+     * List of all backups for the project.
+     * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + public Builder addBackups(com.google.firestore.admin.v1.Backup value) { + if (backupsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureBackupsIsMutable(); + backups_.add(value); + onChanged(); + } else { + backupsBuilder_.addMessage(value); + } + return this; + } + /** + * + * + *
+     * List of all backups for the project.
+     * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + public Builder addBackups(int index, com.google.firestore.admin.v1.Backup value) { + if (backupsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureBackupsIsMutable(); + backups_.add(index, value); + onChanged(); + } else { + backupsBuilder_.addMessage(index, value); + } + return this; + } + /** + * + * + *
+     * List of all backups for the project.
+     * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + public Builder addBackups(com.google.firestore.admin.v1.Backup.Builder builderForValue) { + if (backupsBuilder_ == null) { + ensureBackupsIsMutable(); + backups_.add(builderForValue.build()); + onChanged(); + } else { + backupsBuilder_.addMessage(builderForValue.build()); + } + return this; + } + /** + * + * + *
+     * List of all backups for the project.
+     * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + public Builder addBackups( + int index, com.google.firestore.admin.v1.Backup.Builder builderForValue) { + if (backupsBuilder_ == null) { + ensureBackupsIsMutable(); + backups_.add(index, builderForValue.build()); + onChanged(); + } else { + backupsBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + /** + * + * + *
+     * List of all backups for the project.
+     * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + public Builder addAllBackups( + java.lang.Iterable values) { + if (backupsBuilder_ == null) { + ensureBackupsIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll(values, backups_); + onChanged(); + } else { + backupsBuilder_.addAllMessages(values); + } + return this; + } + /** + * + * + *
+     * List of all backups for the project.
+     * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + public Builder clearBackups() { + if (backupsBuilder_ == null) { + backups_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + } else { + backupsBuilder_.clear(); + } + return this; + } + /** + * + * + *
+     * List of all backups for the project.
+     * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + public Builder removeBackups(int index) { + if (backupsBuilder_ == null) { + ensureBackupsIsMutable(); + backups_.remove(index); + onChanged(); + } else { + backupsBuilder_.remove(index); + } + return this; + } + /** + * + * + *
+     * List of all backups for the project.
+     * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + public com.google.firestore.admin.v1.Backup.Builder getBackupsBuilder(int index) { + return getBackupsFieldBuilder().getBuilder(index); + } + /** + * + * + *
+     * List of all backups for the project.
+     * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + public com.google.firestore.admin.v1.BackupOrBuilder getBackupsOrBuilder(int index) { + if (backupsBuilder_ == null) { + return backups_.get(index); + } else { + return backupsBuilder_.getMessageOrBuilder(index); + } + } + /** + * + * + *
+     * List of all backups for the project.
+     * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + public java.util.List + getBackupsOrBuilderList() { + if (backupsBuilder_ != null) { + return backupsBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(backups_); + } + } + /** + * + * + *
+     * List of all backups for the project.
+     * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + public com.google.firestore.admin.v1.Backup.Builder addBackupsBuilder() { + return getBackupsFieldBuilder() + .addBuilder(com.google.firestore.admin.v1.Backup.getDefaultInstance()); + } + /** + * + * + *
+     * List of all backups for the project.
+     * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + public com.google.firestore.admin.v1.Backup.Builder addBackupsBuilder(int index) { + return getBackupsFieldBuilder() + .addBuilder(index, com.google.firestore.admin.v1.Backup.getDefaultInstance()); + } + /** + * + * + *
+     * List of all backups for the project.
+     * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + public java.util.List getBackupsBuilderList() { + return getBackupsFieldBuilder().getBuilderList(); + } + + private com.google.protobuf.RepeatedFieldBuilderV3< + com.google.firestore.admin.v1.Backup, + com.google.firestore.admin.v1.Backup.Builder, + com.google.firestore.admin.v1.BackupOrBuilder> + getBackupsFieldBuilder() { + if (backupsBuilder_ == null) { + backupsBuilder_ = + new com.google.protobuf.RepeatedFieldBuilderV3< + com.google.firestore.admin.v1.Backup, + com.google.firestore.admin.v1.Backup.Builder, + com.google.firestore.admin.v1.BackupOrBuilder>( + backups_, ((bitField0_ & 0x00000001) != 0), getParentForChildren(), isClean()); + backups_ = null; + } + return backupsBuilder_; + } + + private com.google.protobuf.LazyStringArrayList unreachable_ = + com.google.protobuf.LazyStringArrayList.emptyList(); + + private void ensureUnreachableIsMutable() { + if (!unreachable_.isModifiable()) { + unreachable_ = new com.google.protobuf.LazyStringArrayList(unreachable_); + } + bitField0_ |= 0x00000002; + } + /** + * + * + *
+     * List of locations that existing backups were not able to be fetched from.
+     *
+     * Instead of failing the entire requests when a single location is
+     * unreachable, this response returns a partial result set and list of
+     * locations unable to be reached here. The request can be retried against a
+     * single location to get a concrete error.
+     * 
+ * + * repeated string unreachable = 3; + * + * @return A list containing the unreachable. + */ + public com.google.protobuf.ProtocolStringList getUnreachableList() { + unreachable_.makeImmutable(); + return unreachable_; + } + /** + * + * + *
+     * List of locations that existing backups were not able to be fetched from.
+     *
+     * Instead of failing the entire requests when a single location is
+     * unreachable, this response returns a partial result set and list of
+     * locations unable to be reached here. The request can be retried against a
+     * single location to get a concrete error.
+     * 
+ * + * repeated string unreachable = 3; + * + * @return The count of unreachable. + */ + public int getUnreachableCount() { + return unreachable_.size(); + } + /** + * + * + *
+     * List of locations that existing backups were not able to be fetched from.
+     *
+     * Instead of failing the entire requests when a single location is
+     * unreachable, this response returns a partial result set and list of
+     * locations unable to be reached here. The request can be retried against a
+     * single location to get a concrete error.
+     * 
+ * + * repeated string unreachable = 3; + * + * @param index The index of the element to return. + * @return The unreachable at the given index. + */ + public java.lang.String getUnreachable(int index) { + return unreachable_.get(index); + } + /** + * + * + *
+     * List of locations that existing backups were not able to be fetched from.
+     *
+     * Instead of failing the entire requests when a single location is
+     * unreachable, this response returns a partial result set and list of
+     * locations unable to be reached here. The request can be retried against a
+     * single location to get a concrete error.
+     * 
+ * + * repeated string unreachable = 3; + * + * @param index The index of the value to return. + * @return The bytes of the unreachable at the given index. + */ + public com.google.protobuf.ByteString getUnreachableBytes(int index) { + return unreachable_.getByteString(index); + } + /** + * + * + *
+     * List of locations that existing backups were not able to be fetched from.
+     *
+     * Instead of failing the entire requests when a single location is
+     * unreachable, this response returns a partial result set and list of
+     * locations unable to be reached here. The request can be retried against a
+     * single location to get a concrete error.
+     * 
+ * + * repeated string unreachable = 3; + * + * @param index The index to set the value at. + * @param value The unreachable to set. + * @return This builder for chaining. + */ + public Builder setUnreachable(int index, java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureUnreachableIsMutable(); + unreachable_.set(index, value); + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+     * List of locations that existing backups were not able to be fetched from.
+     *
+     * Instead of failing the entire requests when a single location is
+     * unreachable, this response returns a partial result set and list of
+     * locations unable to be reached here. The request can be retried against a
+     * single location to get a concrete error.
+     * 
+ * + * repeated string unreachable = 3; + * + * @param value The unreachable to add. + * @return This builder for chaining. + */ + public Builder addUnreachable(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureUnreachableIsMutable(); + unreachable_.add(value); + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+     * List of locations that existing backups were not able to be fetched from.
+     *
+     * Instead of failing the entire requests when a single location is
+     * unreachable, this response returns a partial result set and list of
+     * locations unable to be reached here. The request can be retried against a
+     * single location to get a concrete error.
+     * 
+ * + * repeated string unreachable = 3; + * + * @param values The unreachable to add. + * @return This builder for chaining. + */ + public Builder addAllUnreachable(java.lang.Iterable values) { + ensureUnreachableIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll(values, unreachable_); + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+     * List of locations that existing backups were not able to be fetched from.
+     *
+     * Instead of failing the entire requests when a single location is
+     * unreachable, this response returns a partial result set and list of
+     * locations unable to be reached here. The request can be retried against a
+     * single location to get a concrete error.
+     * 
+ * + * repeated string unreachable = 3; + * + * @return This builder for chaining. + */ + public Builder clearUnreachable() { + unreachable_ = com.google.protobuf.LazyStringArrayList.emptyList(); + bitField0_ = (bitField0_ & ~0x00000002); + ; + onChanged(); + return this; + } + /** + * + * + *
+     * List of locations that existing backups were not able to be fetched from.
+     *
+     * Instead of failing the entire requests when a single location is
+     * unreachable, this response returns a partial result set and list of
+     * locations unable to be reached here. The request can be retried against a
+     * single location to get a concrete error.
+     * 
+ * + * repeated string unreachable = 3; + * + * @param value The bytes of the unreachable to add. + * @return This builder for chaining. + */ + public Builder addUnreachableBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + ensureUnreachableIsMutable(); + unreachable_.add(value); + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.ListBackupsResponse) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.ListBackupsResponse) + private static final com.google.firestore.admin.v1.ListBackupsResponse DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.admin.v1.ListBackupsResponse(); + } + + public static com.google.firestore.admin.v1.ListBackupsResponse getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public ListBackupsResponse parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.ListBackupsResponse getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupsResponseOrBuilder.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupsResponseOrBuilder.java new file mode 100644 index 000000000..9cbfc18a4 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ListBackupsResponseOrBuilder.java @@ -0,0 +1,148 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +public interface ListBackupsResponseOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.ListBackupsResponse) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * List of all backups for the project.
+   * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + java.util.List getBackupsList(); + /** + * + * + *
+   * List of all backups for the project.
+   * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + com.google.firestore.admin.v1.Backup getBackups(int index); + /** + * + * + *
+   * List of all backups for the project.
+   * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + int getBackupsCount(); + /** + * + * + *
+   * List of all backups for the project.
+   * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + java.util.List getBackupsOrBuilderList(); + /** + * + * + *
+   * List of all backups for the project.
+   * 
+ * + * repeated .google.firestore.admin.v1.Backup backups = 1; + */ + com.google.firestore.admin.v1.BackupOrBuilder getBackupsOrBuilder(int index); + + /** + * + * + *
+   * List of locations that existing backups were not able to be fetched from.
+   *
+   * Instead of failing the entire requests when a single location is
+   * unreachable, this response returns a partial result set and list of
+   * locations unable to be reached here. The request can be retried against a
+   * single location to get a concrete error.
+   * 
+ * + * repeated string unreachable = 3; + * + * @return A list containing the unreachable. + */ + java.util.List getUnreachableList(); + /** + * + * + *
+   * List of locations that existing backups were not able to be fetched from.
+   *
+   * Instead of failing the entire requests when a single location is
+   * unreachable, this response returns a partial result set and list of
+   * locations unable to be reached here. The request can be retried against a
+   * single location to get a concrete error.
+   * 
+ * + * repeated string unreachable = 3; + * + * @return The count of unreachable. + */ + int getUnreachableCount(); + /** + * + * + *
+   * List of locations that existing backups were not able to be fetched from.
+   *
+   * Instead of failing the entire requests when a single location is
+   * unreachable, this response returns a partial result set and list of
+   * locations unable to be reached here. The request can be retried against a
+   * single location to get a concrete error.
+   * 
+ * + * repeated string unreachable = 3; + * + * @param index The index of the element to return. + * @return The unreachable at the given index. + */ + java.lang.String getUnreachable(int index); + /** + * + * + *
+   * List of locations that existing backups were not able to be fetched from.
+   *
+   * Instead of failing the entire requests when a single location is
+   * unreachable, this response returns a partial result set and list of
+   * locations unable to be reached here. The request can be retried against a
+   * single location to get a concrete error.
+   * 
+ * + * repeated string unreachable = 3; + * + * @param index The index of the value to return. + * @return The bytes of the unreachable at the given index. + */ + com.google.protobuf.ByteString getUnreachableBytes(int index); +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/LocationName.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/LocationName.java new file mode 100644 index 000000000..3e4c27491 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/LocationName.java @@ -0,0 +1,192 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.firestore.admin.v1; + +import com.google.api.pathtemplate.PathTemplate; +import com.google.api.resourcenames.ResourceName; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +@Generated("by gapic-generator-java") +public class LocationName implements ResourceName { + private static final PathTemplate PROJECT_LOCATION = + PathTemplate.createWithoutUrlEncoding("projects/{project}/locations/{location}"); + private volatile Map fieldValuesMap; + private final String project; + private final String location; + + @Deprecated + protected LocationName() { + project = null; + location = null; + } + + private LocationName(Builder builder) { + project = Preconditions.checkNotNull(builder.getProject()); + location = Preconditions.checkNotNull(builder.getLocation()); + } + + public String getProject() { + return project; + } + + public String getLocation() { + return location; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + public static LocationName of(String project, String location) { + return newBuilder().setProject(project).setLocation(location).build(); + } + + public static String format(String project, String location) { + return newBuilder().setProject(project).setLocation(location).build().toString(); + } + + public static LocationName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + Map matchMap = + PROJECT_LOCATION.validatedMatch( + formattedString, "LocationName.parse: formattedString not in valid format"); + return of(matchMap.get("project"), matchMap.get("location")); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList<>(values.size()); + for (LocationName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return PROJECT_LOCATION.matches(formattedString); + } + + @Override + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + if (project != null) { + fieldMapBuilder.put("project", project); + } + if (location != null) { + fieldMapBuilder.put("location", location); + } + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return PROJECT_LOCATION.instantiate("project", project, "location", location); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o != null && getClass() == o.getClass()) { + LocationName that = ((LocationName) o); + return Objects.equals(this.project, that.project) + && Objects.equals(this.location, that.location); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= Objects.hashCode(project); + h *= 1000003; + h ^= Objects.hashCode(location); + return h; + } + + /** Builder for projects/{project}/locations/{location}. */ + public static class Builder { + private String project; + private String location; + + protected Builder() {} + + public String getProject() { + return project; + } + + public String getLocation() { + return location; + } + + public Builder setProject(String project) { + this.project = project; + return this; + } + + public Builder setLocation(String location) { + this.location = location; + return this; + } + + private Builder(LocationName locationName) { + this.project = locationName.project; + this.location = locationName.location; + } + + public LocationName build() { + return new LocationName(this); + } + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/OperationProto.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/OperationProto.java index 28676b40c..fd5e57b65 100644 --- a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/OperationProto.java +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/OperationProto.java @@ -56,6 +56,10 @@ public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry r internal_static_google_firestore_admin_v1_ExportDocumentsResponse_descriptor; static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_google_firestore_admin_v1_ExportDocumentsResponse_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_RestoreDatabaseMetadata_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_RestoreDatabaseMetadata_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_firestore_admin_v1_Progress_descriptor; static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable @@ -126,18 +130,27 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + "1.Progress\022\026\n\016collection_ids\030\006 \003(\t\022\030\n\020in" + "put_uri_prefix\030\007 \001(\t\022\025\n\rnamespace_ids\030\010 " + "\003(\t\"4\n\027ExportDocumentsResponse\022\031\n\021output" - + "_uri_prefix\030\001 \001(\t\":\n\010Progress\022\026\n\016estimat" - + "ed_work\030\001 \001(\003\022\026\n\016completed_work\030\002 \001(\003*\236\001" - + "\n\016OperationState\022\037\n\033OPERATION_STATE_UNSP" - + "ECIFIED\020\000\022\020\n\014INITIALIZING\020\001\022\016\n\nPROCESSIN" - + "G\020\002\022\016\n\nCANCELLING\020\003\022\016\n\nFINALIZING\020\004\022\016\n\nS" - + "UCCESSFUL\020\005\022\n\n\006FAILED\020\006\022\r\n\tCANCELLED\020\007B\335" - + "\001\n\035com.google.firestore.admin.v1B\016Operat" - + "ionProtoP\001Z9cloud.google.com/go/firestor" - + "e/apiv1/admin/adminpb;adminpb\242\002\004GCFS\252\002\037G" - + "oogle.Cloud.Firestore.Admin.V1\312\002\037Google\\" - + "Cloud\\Firestore\\Admin\\V1\352\002#Google::Cloud" - + "::Firestore::Admin::V1b\006proto3" + + "_uri_prefix\030\001 \001(\t\"\355\002\n\027RestoreDatabaseMet" + + "adata\022.\n\nstart_time\030\001 \001(\0132\032.google.proto" + + "buf.Timestamp\022,\n\010end_time\030\002 \001(\0132\032.google" + + ".protobuf.Timestamp\022B\n\017operation_state\030\003" + + " \001(\0162).google.firestore.admin.v1.Operati" + + "onState\0228\n\010database\030\004 \001(\tB&\372A#\n!firestor" + + "e.googleapis.com/Database\0224\n\006backup\030\005 \001(" + + "\tB$\372A!\n\037firestore.googleapis.com/Backup\022" + + "@\n\023progress_percentage\030\010 \001(\0132#.google.fi" + + "restore.admin.v1.Progress\":\n\010Progress\022\026\n" + + "\016estimated_work\030\001 \001(\003\022\026\n\016completed_work\030" + + "\002 \001(\003*\236\001\n\016OperationState\022\037\n\033OPERATION_ST" + + "ATE_UNSPECIFIED\020\000\022\020\n\014INITIALIZING\020\001\022\016\n\nP" + + "ROCESSING\020\002\022\016\n\nCANCELLING\020\003\022\016\n\nFINALIZIN" + + "G\020\004\022\016\n\nSUCCESSFUL\020\005\022\n\n\006FAILED\020\006\022\r\n\tCANCE" + + "LLED\020\007B\335\001\n\035com.google.firestore.admin.v1" + + "B\016OperationProtoP\001Z9cloud.google.com/go/" + + "firestore/apiv1/admin/adminpb;adminpb\242\002\004" + + "GCFS\252\002\037Google.Cloud.Firestore.Admin.V1\312\002" + + "\037Google\\Cloud\\Firestore\\Admin\\V1\352\002#Googl" + + "e::Cloud::Firestore::Admin::V1b\006proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( @@ -229,14 +242,27 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new java.lang.String[] { "OutputUriPrefix", }); - internal_static_google_firestore_admin_v1_Progress_descriptor = + internal_static_google_firestore_admin_v1_RestoreDatabaseMetadata_descriptor = getDescriptor().getMessageTypes().get(5); + internal_static_google_firestore_admin_v1_RestoreDatabaseMetadata_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_RestoreDatabaseMetadata_descriptor, + new java.lang.String[] { + "StartTime", "EndTime", "OperationState", "Database", "Backup", "ProgressPercentage", + }); + internal_static_google_firestore_admin_v1_Progress_descriptor = + getDescriptor().getMessageTypes().get(6); internal_static_google_firestore_admin_v1_Progress_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_firestore_admin_v1_Progress_descriptor, new java.lang.String[] { "EstimatedWork", "CompletedWork", }); + com.google.protobuf.ExtensionRegistry registry = + com.google.protobuf.ExtensionRegistry.newInstance(); + registry.add(com.google.api.ResourceProto.resourceReference); + com.google.protobuf.Descriptors.FileDescriptor.internalUpdateFileDescriptor( + descriptor, registry); com.google.api.ResourceProto.getDescriptor(); com.google.firestore.admin.v1.IndexProto.getDescriptor(); com.google.protobuf.TimestampProto.getDescriptor(); diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ProjectName.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ProjectName.java index 2a446269a..3d6a8c946 100644 --- a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ProjectName.java +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ProjectName.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/RestoreDatabaseMetadata.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/RestoreDatabaseMetadata.java new file mode 100644 index 000000000..00716f960 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/RestoreDatabaseMetadata.java @@ -0,0 +1,1764 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/operation.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +/** + * + * + *
+ * Metadata for the [long-running operation][google.longrunning.Operation] from
+ * the [RestoreDatabase][google.firestore.admin.v1.RestoreDatabase] request.
+ * 
+ * + * Protobuf type {@code google.firestore.admin.v1.RestoreDatabaseMetadata} + */ +public final class RestoreDatabaseMetadata extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.RestoreDatabaseMetadata) + RestoreDatabaseMetadataOrBuilder { + private static final long serialVersionUID = 0L; + // Use RestoreDatabaseMetadata.newBuilder() to construct. + private RestoreDatabaseMetadata(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private RestoreDatabaseMetadata() { + operationState_ = 0; + database_ = ""; + backup_ = ""; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new RestoreDatabaseMetadata(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.OperationProto + .internal_static_google_firestore_admin_v1_RestoreDatabaseMetadata_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.OperationProto + .internal_static_google_firestore_admin_v1_RestoreDatabaseMetadata_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.RestoreDatabaseMetadata.class, + com.google.firestore.admin.v1.RestoreDatabaseMetadata.Builder.class); + } + + private int bitField0_; + public static final int START_TIME_FIELD_NUMBER = 1; + private com.google.protobuf.Timestamp startTime_; + /** + * + * + *
+   * The time the restore was started.
+   * 
+ * + * .google.protobuf.Timestamp start_time = 1; + * + * @return Whether the startTime field is set. + */ + @java.lang.Override + public boolean hasStartTime() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * + * + *
+   * The time the restore was started.
+   * 
+ * + * .google.protobuf.Timestamp start_time = 1; + * + * @return The startTime. + */ + @java.lang.Override + public com.google.protobuf.Timestamp getStartTime() { + return startTime_ == null ? com.google.protobuf.Timestamp.getDefaultInstance() : startTime_; + } + /** + * + * + *
+   * The time the restore was started.
+   * 
+ * + * .google.protobuf.Timestamp start_time = 1; + */ + @java.lang.Override + public com.google.protobuf.TimestampOrBuilder getStartTimeOrBuilder() { + return startTime_ == null ? com.google.protobuf.Timestamp.getDefaultInstance() : startTime_; + } + + public static final int END_TIME_FIELD_NUMBER = 2; + private com.google.protobuf.Timestamp endTime_; + /** + * + * + *
+   * The time the restore finished, unset for ongoing restores.
+   * 
+ * + * .google.protobuf.Timestamp end_time = 2; + * + * @return Whether the endTime field is set. + */ + @java.lang.Override + public boolean hasEndTime() { + return ((bitField0_ & 0x00000002) != 0); + } + /** + * + * + *
+   * The time the restore finished, unset for ongoing restores.
+   * 
+ * + * .google.protobuf.Timestamp end_time = 2; + * + * @return The endTime. + */ + @java.lang.Override + public com.google.protobuf.Timestamp getEndTime() { + return endTime_ == null ? com.google.protobuf.Timestamp.getDefaultInstance() : endTime_; + } + /** + * + * + *
+   * The time the restore finished, unset for ongoing restores.
+   * 
+ * + * .google.protobuf.Timestamp end_time = 2; + */ + @java.lang.Override + public com.google.protobuf.TimestampOrBuilder getEndTimeOrBuilder() { + return endTime_ == null ? com.google.protobuf.Timestamp.getDefaultInstance() : endTime_; + } + + public static final int OPERATION_STATE_FIELD_NUMBER = 3; + private int operationState_ = 0; + /** + * + * + *
+   * The operation state of the restore.
+   * 
+ * + * .google.firestore.admin.v1.OperationState operation_state = 3; + * + * @return The enum numeric value on the wire for operationState. + */ + @java.lang.Override + public int getOperationStateValue() { + return operationState_; + } + /** + * + * + *
+   * The operation state of the restore.
+   * 
+ * + * .google.firestore.admin.v1.OperationState operation_state = 3; + * + * @return The operationState. + */ + @java.lang.Override + public com.google.firestore.admin.v1.OperationState getOperationState() { + com.google.firestore.admin.v1.OperationState result = + com.google.firestore.admin.v1.OperationState.forNumber(operationState_); + return result == null ? com.google.firestore.admin.v1.OperationState.UNRECOGNIZED : result; + } + + public static final int DATABASE_FIELD_NUMBER = 4; + + @SuppressWarnings("serial") + private volatile java.lang.Object database_ = ""; + /** + * + * + *
+   * The name of the database being restored to.
+   * 
+ * + * string database = 4 [(.google.api.resource_reference) = { ... } + * + * @return The database. + */ + @java.lang.Override + public java.lang.String getDatabase() { + java.lang.Object ref = database_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + database_ = s; + return s; + } + } + /** + * + * + *
+   * The name of the database being restored to.
+   * 
+ * + * string database = 4 [(.google.api.resource_reference) = { ... } + * + * @return The bytes for database. + */ + @java.lang.Override + public com.google.protobuf.ByteString getDatabaseBytes() { + java.lang.Object ref = database_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + database_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int BACKUP_FIELD_NUMBER = 5; + + @SuppressWarnings("serial") + private volatile java.lang.Object backup_ = ""; + /** + * + * + *
+   * The name of the backup restoring from.
+   * 
+ * + * string backup = 5 [(.google.api.resource_reference) = { ... } + * + * @return The backup. + */ + @java.lang.Override + public java.lang.String getBackup() { + java.lang.Object ref = backup_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + backup_ = s; + return s; + } + } + /** + * + * + *
+   * The name of the backup restoring from.
+   * 
+ * + * string backup = 5 [(.google.api.resource_reference) = { ... } + * + * @return The bytes for backup. + */ + @java.lang.Override + public com.google.protobuf.ByteString getBackupBytes() { + java.lang.Object ref = backup_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + backup_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int PROGRESS_PERCENTAGE_FIELD_NUMBER = 8; + private com.google.firestore.admin.v1.Progress progressPercentage_; + /** + * + * + *
+   * How far along the restore is as an estimated percentage of remaining time.
+   * 
+ * + * .google.firestore.admin.v1.Progress progress_percentage = 8; + * + * @return Whether the progressPercentage field is set. + */ + @java.lang.Override + public boolean hasProgressPercentage() { + return ((bitField0_ & 0x00000004) != 0); + } + /** + * + * + *
+   * How far along the restore is as an estimated percentage of remaining time.
+   * 
+ * + * .google.firestore.admin.v1.Progress progress_percentage = 8; + * + * @return The progressPercentage. + */ + @java.lang.Override + public com.google.firestore.admin.v1.Progress getProgressPercentage() { + return progressPercentage_ == null + ? com.google.firestore.admin.v1.Progress.getDefaultInstance() + : progressPercentage_; + } + /** + * + * + *
+   * How far along the restore is as an estimated percentage of remaining time.
+   * 
+ * + * .google.firestore.admin.v1.Progress progress_percentage = 8; + */ + @java.lang.Override + public com.google.firestore.admin.v1.ProgressOrBuilder getProgressPercentageOrBuilder() { + return progressPercentage_ == null + ? com.google.firestore.admin.v1.Progress.getDefaultInstance() + : progressPercentage_; + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (((bitField0_ & 0x00000001) != 0)) { + output.writeMessage(1, getStartTime()); + } + if (((bitField0_ & 0x00000002) != 0)) { + output.writeMessage(2, getEndTime()); + } + if (operationState_ + != com.google.firestore.admin.v1.OperationState.OPERATION_STATE_UNSPECIFIED.getNumber()) { + output.writeEnum(3, operationState_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(database_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 4, database_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(backup_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 5, backup_); + } + if (((bitField0_ & 0x00000004) != 0)) { + output.writeMessage(8, getProgressPercentage()); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(1, getStartTime()); + } + if (((bitField0_ & 0x00000002) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(2, getEndTime()); + } + if (operationState_ + != com.google.firestore.admin.v1.OperationState.OPERATION_STATE_UNSPECIFIED.getNumber()) { + size += com.google.protobuf.CodedOutputStream.computeEnumSize(3, operationState_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(database_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(4, database_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(backup_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(5, backup_); + } + if (((bitField0_ & 0x00000004) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(8, getProgressPercentage()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.admin.v1.RestoreDatabaseMetadata)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.RestoreDatabaseMetadata other = + (com.google.firestore.admin.v1.RestoreDatabaseMetadata) obj; + + if (hasStartTime() != other.hasStartTime()) return false; + if (hasStartTime()) { + if (!getStartTime().equals(other.getStartTime())) return false; + } + if (hasEndTime() != other.hasEndTime()) return false; + if (hasEndTime()) { + if (!getEndTime().equals(other.getEndTime())) return false; + } + if (operationState_ != other.operationState_) return false; + if (!getDatabase().equals(other.getDatabase())) return false; + if (!getBackup().equals(other.getBackup())) return false; + if (hasProgressPercentage() != other.hasProgressPercentage()) return false; + if (hasProgressPercentage()) { + if (!getProgressPercentage().equals(other.getProgressPercentage())) return false; + } + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (hasStartTime()) { + hash = (37 * hash) + START_TIME_FIELD_NUMBER; + hash = (53 * hash) + getStartTime().hashCode(); + } + if (hasEndTime()) { + hash = (37 * hash) + END_TIME_FIELD_NUMBER; + hash = (53 * hash) + getEndTime().hashCode(); + } + hash = (37 * hash) + OPERATION_STATE_FIELD_NUMBER; + hash = (53 * hash) + operationState_; + hash = (37 * hash) + DATABASE_FIELD_NUMBER; + hash = (53 * hash) + getDatabase().hashCode(); + hash = (37 * hash) + BACKUP_FIELD_NUMBER; + hash = (53 * hash) + getBackup().hashCode(); + if (hasProgressPercentage()) { + hash = (37 * hash) + PROGRESS_PERCENTAGE_FIELD_NUMBER; + hash = (53 * hash) + getProgressPercentage().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.RestoreDatabaseMetadata parseFrom( + java.nio.ByteBuffer data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseMetadata parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseMetadata parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseMetadata parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseMetadata parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseMetadata parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseMetadata parseFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseMetadata parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseMetadata parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseMetadata parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseMetadata parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseMetadata parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder( + com.google.firestore.admin.v1.RestoreDatabaseMetadata prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * Metadata for the [long-running operation][google.longrunning.Operation] from
+   * the [RestoreDatabase][google.firestore.admin.v1.RestoreDatabase] request.
+   * 
+ * + * Protobuf type {@code google.firestore.admin.v1.RestoreDatabaseMetadata} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.RestoreDatabaseMetadata) + com.google.firestore.admin.v1.RestoreDatabaseMetadataOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.OperationProto + .internal_static_google_firestore_admin_v1_RestoreDatabaseMetadata_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.OperationProto + .internal_static_google_firestore_admin_v1_RestoreDatabaseMetadata_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.RestoreDatabaseMetadata.class, + com.google.firestore.admin.v1.RestoreDatabaseMetadata.Builder.class); + } + + // Construct using com.google.firestore.admin.v1.RestoreDatabaseMetadata.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) { + getStartTimeFieldBuilder(); + getEndTimeFieldBuilder(); + getProgressPercentageFieldBuilder(); + } + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + startTime_ = null; + if (startTimeBuilder_ != null) { + startTimeBuilder_.dispose(); + startTimeBuilder_ = null; + } + endTime_ = null; + if (endTimeBuilder_ != null) { + endTimeBuilder_.dispose(); + endTimeBuilder_ = null; + } + operationState_ = 0; + database_ = ""; + backup_ = ""; + progressPercentage_ = null; + if (progressPercentageBuilder_ != null) { + progressPercentageBuilder_.dispose(); + progressPercentageBuilder_ = null; + } + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.OperationProto + .internal_static_google_firestore_admin_v1_RestoreDatabaseMetadata_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.RestoreDatabaseMetadata getDefaultInstanceForType() { + return com.google.firestore.admin.v1.RestoreDatabaseMetadata.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.RestoreDatabaseMetadata build() { + com.google.firestore.admin.v1.RestoreDatabaseMetadata result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.RestoreDatabaseMetadata buildPartial() { + com.google.firestore.admin.v1.RestoreDatabaseMetadata result = + new com.google.firestore.admin.v1.RestoreDatabaseMetadata(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.admin.v1.RestoreDatabaseMetadata result) { + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.startTime_ = startTimeBuilder_ == null ? startTime_ : startTimeBuilder_.build(); + to_bitField0_ |= 0x00000001; + } + if (((from_bitField0_ & 0x00000002) != 0)) { + result.endTime_ = endTimeBuilder_ == null ? endTime_ : endTimeBuilder_.build(); + to_bitField0_ |= 0x00000002; + } + if (((from_bitField0_ & 0x00000004) != 0)) { + result.operationState_ = operationState_; + } + if (((from_bitField0_ & 0x00000008) != 0)) { + result.database_ = database_; + } + if (((from_bitField0_ & 0x00000010) != 0)) { + result.backup_ = backup_; + } + if (((from_bitField0_ & 0x00000020) != 0)) { + result.progressPercentage_ = + progressPercentageBuilder_ == null + ? progressPercentage_ + : progressPercentageBuilder_.build(); + to_bitField0_ |= 0x00000004; + } + result.bitField0_ |= to_bitField0_; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.admin.v1.RestoreDatabaseMetadata) { + return mergeFrom((com.google.firestore.admin.v1.RestoreDatabaseMetadata) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.admin.v1.RestoreDatabaseMetadata other) { + if (other == com.google.firestore.admin.v1.RestoreDatabaseMetadata.getDefaultInstance()) + return this; + if (other.hasStartTime()) { + mergeStartTime(other.getStartTime()); + } + if (other.hasEndTime()) { + mergeEndTime(other.getEndTime()); + } + if (other.operationState_ != 0) { + setOperationStateValue(other.getOperationStateValue()); + } + if (!other.getDatabase().isEmpty()) { + database_ = other.database_; + bitField0_ |= 0x00000008; + onChanged(); + } + if (!other.getBackup().isEmpty()) { + backup_ = other.backup_; + bitField0_ |= 0x00000010; + onChanged(); + } + if (other.hasProgressPercentage()) { + mergeProgressPercentage(other.getProgressPercentage()); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + input.readMessage(getStartTimeFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: + { + input.readMessage(getEndTimeFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000002; + break; + } // case 18 + case 24: + { + operationState_ = input.readEnum(); + bitField0_ |= 0x00000004; + break; + } // case 24 + case 34: + { + database_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000008; + break; + } // case 34 + case 42: + { + backup_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000010; + break; + } // case 42 + case 66: + { + input.readMessage( + getProgressPercentageFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000020; + break; + } // case 66 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private com.google.protobuf.Timestamp startTime_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder> + startTimeBuilder_; + /** + * + * + *
+     * The time the restore was started.
+     * 
+ * + * .google.protobuf.Timestamp start_time = 1; + * + * @return Whether the startTime field is set. + */ + public boolean hasStartTime() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * + * + *
+     * The time the restore was started.
+     * 
+ * + * .google.protobuf.Timestamp start_time = 1; + * + * @return The startTime. + */ + public com.google.protobuf.Timestamp getStartTime() { + if (startTimeBuilder_ == null) { + return startTime_ == null ? com.google.protobuf.Timestamp.getDefaultInstance() : startTime_; + } else { + return startTimeBuilder_.getMessage(); + } + } + /** + * + * + *
+     * The time the restore was started.
+     * 
+ * + * .google.protobuf.Timestamp start_time = 1; + */ + public Builder setStartTime(com.google.protobuf.Timestamp value) { + if (startTimeBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + startTime_ = value; + } else { + startTimeBuilder_.setMessage(value); + } + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * The time the restore was started.
+     * 
+ * + * .google.protobuf.Timestamp start_time = 1; + */ + public Builder setStartTime(com.google.protobuf.Timestamp.Builder builderForValue) { + if (startTimeBuilder_ == null) { + startTime_ = builderForValue.build(); + } else { + startTimeBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * The time the restore was started.
+     * 
+ * + * .google.protobuf.Timestamp start_time = 1; + */ + public Builder mergeStartTime(com.google.protobuf.Timestamp value) { + if (startTimeBuilder_ == null) { + if (((bitField0_ & 0x00000001) != 0) + && startTime_ != null + && startTime_ != com.google.protobuf.Timestamp.getDefaultInstance()) { + getStartTimeBuilder().mergeFrom(value); + } else { + startTime_ = value; + } + } else { + startTimeBuilder_.mergeFrom(value); + } + if (startTime_ != null) { + bitField0_ |= 0x00000001; + onChanged(); + } + return this; + } + /** + * + * + *
+     * The time the restore was started.
+     * 
+ * + * .google.protobuf.Timestamp start_time = 1; + */ + public Builder clearStartTime() { + bitField0_ = (bitField0_ & ~0x00000001); + startTime_ = null; + if (startTimeBuilder_ != null) { + startTimeBuilder_.dispose(); + startTimeBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * The time the restore was started.
+     * 
+ * + * .google.protobuf.Timestamp start_time = 1; + */ + public com.google.protobuf.Timestamp.Builder getStartTimeBuilder() { + bitField0_ |= 0x00000001; + onChanged(); + return getStartTimeFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * The time the restore was started.
+     * 
+ * + * .google.protobuf.Timestamp start_time = 1; + */ + public com.google.protobuf.TimestampOrBuilder getStartTimeOrBuilder() { + if (startTimeBuilder_ != null) { + return startTimeBuilder_.getMessageOrBuilder(); + } else { + return startTime_ == null ? com.google.protobuf.Timestamp.getDefaultInstance() : startTime_; + } + } + /** + * + * + *
+     * The time the restore was started.
+     * 
+ * + * .google.protobuf.Timestamp start_time = 1; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder> + getStartTimeFieldBuilder() { + if (startTimeBuilder_ == null) { + startTimeBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder>( + getStartTime(), getParentForChildren(), isClean()); + startTime_ = null; + } + return startTimeBuilder_; + } + + private com.google.protobuf.Timestamp endTime_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder> + endTimeBuilder_; + /** + * + * + *
+     * The time the restore finished, unset for ongoing restores.
+     * 
+ * + * .google.protobuf.Timestamp end_time = 2; + * + * @return Whether the endTime field is set. + */ + public boolean hasEndTime() { + return ((bitField0_ & 0x00000002) != 0); + } + /** + * + * + *
+     * The time the restore finished, unset for ongoing restores.
+     * 
+ * + * .google.protobuf.Timestamp end_time = 2; + * + * @return The endTime. + */ + public com.google.protobuf.Timestamp getEndTime() { + if (endTimeBuilder_ == null) { + return endTime_ == null ? com.google.protobuf.Timestamp.getDefaultInstance() : endTime_; + } else { + return endTimeBuilder_.getMessage(); + } + } + /** + * + * + *
+     * The time the restore finished, unset for ongoing restores.
+     * 
+ * + * .google.protobuf.Timestamp end_time = 2; + */ + public Builder setEndTime(com.google.protobuf.Timestamp value) { + if (endTimeBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + endTime_ = value; + } else { + endTimeBuilder_.setMessage(value); + } + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+     * The time the restore finished, unset for ongoing restores.
+     * 
+ * + * .google.protobuf.Timestamp end_time = 2; + */ + public Builder setEndTime(com.google.protobuf.Timestamp.Builder builderForValue) { + if (endTimeBuilder_ == null) { + endTime_ = builderForValue.build(); + } else { + endTimeBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+     * The time the restore finished, unset for ongoing restores.
+     * 
+ * + * .google.protobuf.Timestamp end_time = 2; + */ + public Builder mergeEndTime(com.google.protobuf.Timestamp value) { + if (endTimeBuilder_ == null) { + if (((bitField0_ & 0x00000002) != 0) + && endTime_ != null + && endTime_ != com.google.protobuf.Timestamp.getDefaultInstance()) { + getEndTimeBuilder().mergeFrom(value); + } else { + endTime_ = value; + } + } else { + endTimeBuilder_.mergeFrom(value); + } + if (endTime_ != null) { + bitField0_ |= 0x00000002; + onChanged(); + } + return this; + } + /** + * + * + *
+     * The time the restore finished, unset for ongoing restores.
+     * 
+ * + * .google.protobuf.Timestamp end_time = 2; + */ + public Builder clearEndTime() { + bitField0_ = (bitField0_ & ~0x00000002); + endTime_ = null; + if (endTimeBuilder_ != null) { + endTimeBuilder_.dispose(); + endTimeBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * The time the restore finished, unset for ongoing restores.
+     * 
+ * + * .google.protobuf.Timestamp end_time = 2; + */ + public com.google.protobuf.Timestamp.Builder getEndTimeBuilder() { + bitField0_ |= 0x00000002; + onChanged(); + return getEndTimeFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * The time the restore finished, unset for ongoing restores.
+     * 
+ * + * .google.protobuf.Timestamp end_time = 2; + */ + public com.google.protobuf.TimestampOrBuilder getEndTimeOrBuilder() { + if (endTimeBuilder_ != null) { + return endTimeBuilder_.getMessageOrBuilder(); + } else { + return endTime_ == null ? com.google.protobuf.Timestamp.getDefaultInstance() : endTime_; + } + } + /** + * + * + *
+     * The time the restore finished, unset for ongoing restores.
+     * 
+ * + * .google.protobuf.Timestamp end_time = 2; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder> + getEndTimeFieldBuilder() { + if (endTimeBuilder_ == null) { + endTimeBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder>( + getEndTime(), getParentForChildren(), isClean()); + endTime_ = null; + } + return endTimeBuilder_; + } + + private int operationState_ = 0; + /** + * + * + *
+     * The operation state of the restore.
+     * 
+ * + * .google.firestore.admin.v1.OperationState operation_state = 3; + * + * @return The enum numeric value on the wire for operationState. + */ + @java.lang.Override + public int getOperationStateValue() { + return operationState_; + } + /** + * + * + *
+     * The operation state of the restore.
+     * 
+ * + * .google.firestore.admin.v1.OperationState operation_state = 3; + * + * @param value The enum numeric value on the wire for operationState to set. + * @return This builder for chaining. + */ + public Builder setOperationStateValue(int value) { + operationState_ = value; + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + /** + * + * + *
+     * The operation state of the restore.
+     * 
+ * + * .google.firestore.admin.v1.OperationState operation_state = 3; + * + * @return The operationState. + */ + @java.lang.Override + public com.google.firestore.admin.v1.OperationState getOperationState() { + com.google.firestore.admin.v1.OperationState result = + com.google.firestore.admin.v1.OperationState.forNumber(operationState_); + return result == null ? com.google.firestore.admin.v1.OperationState.UNRECOGNIZED : result; + } + /** + * + * + *
+     * The operation state of the restore.
+     * 
+ * + * .google.firestore.admin.v1.OperationState operation_state = 3; + * + * @param value The operationState to set. + * @return This builder for chaining. + */ + public Builder setOperationState(com.google.firestore.admin.v1.OperationState value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + operationState_ = value.getNumber(); + onChanged(); + return this; + } + /** + * + * + *
+     * The operation state of the restore.
+     * 
+ * + * .google.firestore.admin.v1.OperationState operation_state = 3; + * + * @return This builder for chaining. + */ + public Builder clearOperationState() { + bitField0_ = (bitField0_ & ~0x00000004); + operationState_ = 0; + onChanged(); + return this; + } + + private java.lang.Object database_ = ""; + /** + * + * + *
+     * The name of the database being restored to.
+     * 
+ * + * string database = 4 [(.google.api.resource_reference) = { ... } + * + * @return The database. + */ + public java.lang.String getDatabase() { + java.lang.Object ref = database_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + database_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * The name of the database being restored to.
+     * 
+ * + * string database = 4 [(.google.api.resource_reference) = { ... } + * + * @return The bytes for database. + */ + public com.google.protobuf.ByteString getDatabaseBytes() { + java.lang.Object ref = database_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + database_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * The name of the database being restored to.
+     * 
+ * + * string database = 4 [(.google.api.resource_reference) = { ... } + * + * @param value The database to set. + * @return This builder for chaining. + */ + public Builder setDatabase(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + database_ = value; + bitField0_ |= 0x00000008; + onChanged(); + return this; + } + /** + * + * + *
+     * The name of the database being restored to.
+     * 
+ * + * string database = 4 [(.google.api.resource_reference) = { ... } + * + * @return This builder for chaining. + */ + public Builder clearDatabase() { + database_ = getDefaultInstance().getDatabase(); + bitField0_ = (bitField0_ & ~0x00000008); + onChanged(); + return this; + } + /** + * + * + *
+     * The name of the database being restored to.
+     * 
+ * + * string database = 4 [(.google.api.resource_reference) = { ... } + * + * @param value The bytes for database to set. + * @return This builder for chaining. + */ + public Builder setDatabaseBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + database_ = value; + bitField0_ |= 0x00000008; + onChanged(); + return this; + } + + private java.lang.Object backup_ = ""; + /** + * + * + *
+     * The name of the backup restoring from.
+     * 
+ * + * string backup = 5 [(.google.api.resource_reference) = { ... } + * + * @return The backup. + */ + public java.lang.String getBackup() { + java.lang.Object ref = backup_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + backup_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * The name of the backup restoring from.
+     * 
+ * + * string backup = 5 [(.google.api.resource_reference) = { ... } + * + * @return The bytes for backup. + */ + public com.google.protobuf.ByteString getBackupBytes() { + java.lang.Object ref = backup_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + backup_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * The name of the backup restoring from.
+     * 
+ * + * string backup = 5 [(.google.api.resource_reference) = { ... } + * + * @param value The backup to set. + * @return This builder for chaining. + */ + public Builder setBackup(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + backup_ = value; + bitField0_ |= 0x00000010; + onChanged(); + return this; + } + /** + * + * + *
+     * The name of the backup restoring from.
+     * 
+ * + * string backup = 5 [(.google.api.resource_reference) = { ... } + * + * @return This builder for chaining. + */ + public Builder clearBackup() { + backup_ = getDefaultInstance().getBackup(); + bitField0_ = (bitField0_ & ~0x00000010); + onChanged(); + return this; + } + /** + * + * + *
+     * The name of the backup restoring from.
+     * 
+ * + * string backup = 5 [(.google.api.resource_reference) = { ... } + * + * @param value The bytes for backup to set. + * @return This builder for chaining. + */ + public Builder setBackupBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + backup_ = value; + bitField0_ |= 0x00000010; + onChanged(); + return this; + } + + private com.google.firestore.admin.v1.Progress progressPercentage_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.Progress, + com.google.firestore.admin.v1.Progress.Builder, + com.google.firestore.admin.v1.ProgressOrBuilder> + progressPercentageBuilder_; + /** + * + * + *
+     * How far along the restore is as an estimated percentage of remaining time.
+     * 
+ * + * .google.firestore.admin.v1.Progress progress_percentage = 8; + * + * @return Whether the progressPercentage field is set. + */ + public boolean hasProgressPercentage() { + return ((bitField0_ & 0x00000020) != 0); + } + /** + * + * + *
+     * How far along the restore is as an estimated percentage of remaining time.
+     * 
+ * + * .google.firestore.admin.v1.Progress progress_percentage = 8; + * + * @return The progressPercentage. + */ + public com.google.firestore.admin.v1.Progress getProgressPercentage() { + if (progressPercentageBuilder_ == null) { + return progressPercentage_ == null + ? com.google.firestore.admin.v1.Progress.getDefaultInstance() + : progressPercentage_; + } else { + return progressPercentageBuilder_.getMessage(); + } + } + /** + * + * + *
+     * How far along the restore is as an estimated percentage of remaining time.
+     * 
+ * + * .google.firestore.admin.v1.Progress progress_percentage = 8; + */ + public Builder setProgressPercentage(com.google.firestore.admin.v1.Progress value) { + if (progressPercentageBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + progressPercentage_ = value; + } else { + progressPercentageBuilder_.setMessage(value); + } + bitField0_ |= 0x00000020; + onChanged(); + return this; + } + /** + * + * + *
+     * How far along the restore is as an estimated percentage of remaining time.
+     * 
+ * + * .google.firestore.admin.v1.Progress progress_percentage = 8; + */ + public Builder setProgressPercentage( + com.google.firestore.admin.v1.Progress.Builder builderForValue) { + if (progressPercentageBuilder_ == null) { + progressPercentage_ = builderForValue.build(); + } else { + progressPercentageBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000020; + onChanged(); + return this; + } + /** + * + * + *
+     * How far along the restore is as an estimated percentage of remaining time.
+     * 
+ * + * .google.firestore.admin.v1.Progress progress_percentage = 8; + */ + public Builder mergeProgressPercentage(com.google.firestore.admin.v1.Progress value) { + if (progressPercentageBuilder_ == null) { + if (((bitField0_ & 0x00000020) != 0) + && progressPercentage_ != null + && progressPercentage_ != com.google.firestore.admin.v1.Progress.getDefaultInstance()) { + getProgressPercentageBuilder().mergeFrom(value); + } else { + progressPercentage_ = value; + } + } else { + progressPercentageBuilder_.mergeFrom(value); + } + if (progressPercentage_ != null) { + bitField0_ |= 0x00000020; + onChanged(); + } + return this; + } + /** + * + * + *
+     * How far along the restore is as an estimated percentage of remaining time.
+     * 
+ * + * .google.firestore.admin.v1.Progress progress_percentage = 8; + */ + public Builder clearProgressPercentage() { + bitField0_ = (bitField0_ & ~0x00000020); + progressPercentage_ = null; + if (progressPercentageBuilder_ != null) { + progressPercentageBuilder_.dispose(); + progressPercentageBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * How far along the restore is as an estimated percentage of remaining time.
+     * 
+ * + * .google.firestore.admin.v1.Progress progress_percentage = 8; + */ + public com.google.firestore.admin.v1.Progress.Builder getProgressPercentageBuilder() { + bitField0_ |= 0x00000020; + onChanged(); + return getProgressPercentageFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * How far along the restore is as an estimated percentage of remaining time.
+     * 
+ * + * .google.firestore.admin.v1.Progress progress_percentage = 8; + */ + public com.google.firestore.admin.v1.ProgressOrBuilder getProgressPercentageOrBuilder() { + if (progressPercentageBuilder_ != null) { + return progressPercentageBuilder_.getMessageOrBuilder(); + } else { + return progressPercentage_ == null + ? com.google.firestore.admin.v1.Progress.getDefaultInstance() + : progressPercentage_; + } + } + /** + * + * + *
+     * How far along the restore is as an estimated percentage of remaining time.
+     * 
+ * + * .google.firestore.admin.v1.Progress progress_percentage = 8; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.Progress, + com.google.firestore.admin.v1.Progress.Builder, + com.google.firestore.admin.v1.ProgressOrBuilder> + getProgressPercentageFieldBuilder() { + if (progressPercentageBuilder_ == null) { + progressPercentageBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.Progress, + com.google.firestore.admin.v1.Progress.Builder, + com.google.firestore.admin.v1.ProgressOrBuilder>( + getProgressPercentage(), getParentForChildren(), isClean()); + progressPercentage_ = null; + } + return progressPercentageBuilder_; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.RestoreDatabaseMetadata) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.RestoreDatabaseMetadata) + private static final com.google.firestore.admin.v1.RestoreDatabaseMetadata DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.admin.v1.RestoreDatabaseMetadata(); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseMetadata getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public RestoreDatabaseMetadata parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.RestoreDatabaseMetadata getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/RestoreDatabaseMetadataOrBuilder.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/RestoreDatabaseMetadataOrBuilder.java new file mode 100644 index 000000000..10131af08 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/RestoreDatabaseMetadataOrBuilder.java @@ -0,0 +1,206 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/operation.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +public interface RestoreDatabaseMetadataOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.RestoreDatabaseMetadata) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * The time the restore was started.
+   * 
+ * + * .google.protobuf.Timestamp start_time = 1; + * + * @return Whether the startTime field is set. + */ + boolean hasStartTime(); + /** + * + * + *
+   * The time the restore was started.
+   * 
+ * + * .google.protobuf.Timestamp start_time = 1; + * + * @return The startTime. + */ + com.google.protobuf.Timestamp getStartTime(); + /** + * + * + *
+   * The time the restore was started.
+   * 
+ * + * .google.protobuf.Timestamp start_time = 1; + */ + com.google.protobuf.TimestampOrBuilder getStartTimeOrBuilder(); + + /** + * + * + *
+   * The time the restore finished, unset for ongoing restores.
+   * 
+ * + * .google.protobuf.Timestamp end_time = 2; + * + * @return Whether the endTime field is set. + */ + boolean hasEndTime(); + /** + * + * + *
+   * The time the restore finished, unset for ongoing restores.
+   * 
+ * + * .google.protobuf.Timestamp end_time = 2; + * + * @return The endTime. + */ + com.google.protobuf.Timestamp getEndTime(); + /** + * + * + *
+   * The time the restore finished, unset for ongoing restores.
+   * 
+ * + * .google.protobuf.Timestamp end_time = 2; + */ + com.google.protobuf.TimestampOrBuilder getEndTimeOrBuilder(); + + /** + * + * + *
+   * The operation state of the restore.
+   * 
+ * + * .google.firestore.admin.v1.OperationState operation_state = 3; + * + * @return The enum numeric value on the wire for operationState. + */ + int getOperationStateValue(); + /** + * + * + *
+   * The operation state of the restore.
+   * 
+ * + * .google.firestore.admin.v1.OperationState operation_state = 3; + * + * @return The operationState. + */ + com.google.firestore.admin.v1.OperationState getOperationState(); + + /** + * + * + *
+   * The name of the database being restored to.
+   * 
+ * + * string database = 4 [(.google.api.resource_reference) = { ... } + * + * @return The database. + */ + java.lang.String getDatabase(); + /** + * + * + *
+   * The name of the database being restored to.
+   * 
+ * + * string database = 4 [(.google.api.resource_reference) = { ... } + * + * @return The bytes for database. + */ + com.google.protobuf.ByteString getDatabaseBytes(); + + /** + * + * + *
+   * The name of the backup restoring from.
+   * 
+ * + * string backup = 5 [(.google.api.resource_reference) = { ... } + * + * @return The backup. + */ + java.lang.String getBackup(); + /** + * + * + *
+   * The name of the backup restoring from.
+   * 
+ * + * string backup = 5 [(.google.api.resource_reference) = { ... } + * + * @return The bytes for backup. + */ + com.google.protobuf.ByteString getBackupBytes(); + + /** + * + * + *
+   * How far along the restore is as an estimated percentage of remaining time.
+   * 
+ * + * .google.firestore.admin.v1.Progress progress_percentage = 8; + * + * @return Whether the progressPercentage field is set. + */ + boolean hasProgressPercentage(); + /** + * + * + *
+   * How far along the restore is as an estimated percentage of remaining time.
+   * 
+ * + * .google.firestore.admin.v1.Progress progress_percentage = 8; + * + * @return The progressPercentage. + */ + com.google.firestore.admin.v1.Progress getProgressPercentage(); + /** + * + * + *
+   * How far along the restore is as an estimated percentage of remaining time.
+   * 
+ * + * .google.firestore.admin.v1.Progress progress_percentage = 8; + */ + com.google.firestore.admin.v1.ProgressOrBuilder getProgressPercentageOrBuilder(); +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/RestoreDatabaseRequest.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/RestoreDatabaseRequest.java new file mode 100644 index 000000000..1f88b08d7 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/RestoreDatabaseRequest.java @@ -0,0 +1,1103 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +/** + * + * + *
+ * The request message for
+ * [FirestoreAdmin.RestoreDatabase][google.firestore.admin.v1.RestoreDatabase].
+ * 
+ * + * Protobuf type {@code google.firestore.admin.v1.RestoreDatabaseRequest} + */ +public final class RestoreDatabaseRequest extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.RestoreDatabaseRequest) + RestoreDatabaseRequestOrBuilder { + private static final long serialVersionUID = 0L; + // Use RestoreDatabaseRequest.newBuilder() to construct. + private RestoreDatabaseRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private RestoreDatabaseRequest() { + parent_ = ""; + databaseId_ = ""; + backup_ = ""; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new RestoreDatabaseRequest(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_RestoreDatabaseRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_RestoreDatabaseRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.RestoreDatabaseRequest.class, + com.google.firestore.admin.v1.RestoreDatabaseRequest.Builder.class); + } + + public static final int PARENT_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile java.lang.Object parent_ = ""; + /** + * + * + *
+   * Required. The project to restore the database in. Format is
+   * `projects/{project_id}`.
+   * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The parent. + */ + @java.lang.Override + public java.lang.String getParent() { + java.lang.Object ref = parent_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + parent_ = s; + return s; + } + } + /** + * + * + *
+   * Required. The project to restore the database in. Format is
+   * `projects/{project_id}`.
+   * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for parent. + */ + @java.lang.Override + public com.google.protobuf.ByteString getParentBytes() { + java.lang.Object ref = parent_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + parent_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int DATABASE_ID_FIELD_NUMBER = 2; + + @SuppressWarnings("serial") + private volatile java.lang.Object databaseId_ = ""; + /** + * + * + *
+   * Required. The ID to use for the database, which will become the final
+   * component of the database's resource name. This database id must not be
+   * associated with an existing database.
+   *
+   * This value should be 4-63 characters. Valid characters are /[a-z][0-9]-/
+   * with first character a letter and the last a letter or a number. Must not
+   * be UUID-like /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/.
+   *
+   * "(default)" database id is also valid.
+   * 
+ * + * string database_id = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * @return The databaseId. + */ + @java.lang.Override + public java.lang.String getDatabaseId() { + java.lang.Object ref = databaseId_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + databaseId_ = s; + return s; + } + } + /** + * + * + *
+   * Required. The ID to use for the database, which will become the final
+   * component of the database's resource name. This database id must not be
+   * associated with an existing database.
+   *
+   * This value should be 4-63 characters. Valid characters are /[a-z][0-9]-/
+   * with first character a letter and the last a letter or a number. Must not
+   * be UUID-like /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/.
+   *
+   * "(default)" database id is also valid.
+   * 
+ * + * string database_id = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * @return The bytes for databaseId. + */ + @java.lang.Override + public com.google.protobuf.ByteString getDatabaseIdBytes() { + java.lang.Object ref = databaseId_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + databaseId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int BACKUP_FIELD_NUMBER = 3; + + @SuppressWarnings("serial") + private volatile java.lang.Object backup_ = ""; + /** + * + * + *
+   * Required. Backup to restore from. Must be from the same project as the
+   * parent.
+   *
+   * Format is: `projects/{project_id}/locations/{location}/backups/{backup}`
+   * 
+ * + * + * string backup = 3 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The backup. + */ + @java.lang.Override + public java.lang.String getBackup() { + java.lang.Object ref = backup_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + backup_ = s; + return s; + } + } + /** + * + * + *
+   * Required. Backup to restore from. Must be from the same project as the
+   * parent.
+   *
+   * Format is: `projects/{project_id}/locations/{location}/backups/{backup}`
+   * 
+ * + * + * string backup = 3 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for backup. + */ + @java.lang.Override + public com.google.protobuf.ByteString getBackupBytes() { + java.lang.Object ref = backup_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + backup_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(parent_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, parent_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(databaseId_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 2, databaseId_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(backup_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 3, backup_); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(parent_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, parent_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(databaseId_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, databaseId_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(backup_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, backup_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.admin.v1.RestoreDatabaseRequest)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.RestoreDatabaseRequest other = + (com.google.firestore.admin.v1.RestoreDatabaseRequest) obj; + + if (!getParent().equals(other.getParent())) return false; + if (!getDatabaseId().equals(other.getDatabaseId())) return false; + if (!getBackup().equals(other.getBackup())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + PARENT_FIELD_NUMBER; + hash = (53 * hash) + getParent().hashCode(); + hash = (37 * hash) + DATABASE_ID_FIELD_NUMBER; + hash = (53 * hash) + getDatabaseId().hashCode(); + hash = (37 * hash) + BACKUP_FIELD_NUMBER; + hash = (53 * hash) + getBackup().hashCode(); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.RestoreDatabaseRequest parseFrom( + java.nio.ByteBuffer data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseRequest parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseRequest parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseRequest parseFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseRequest parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseRequest parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseRequest parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseRequest parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.admin.v1.RestoreDatabaseRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * The request message for
+   * [FirestoreAdmin.RestoreDatabase][google.firestore.admin.v1.RestoreDatabase].
+   * 
+ * + * Protobuf type {@code google.firestore.admin.v1.RestoreDatabaseRequest} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.RestoreDatabaseRequest) + com.google.firestore.admin.v1.RestoreDatabaseRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_RestoreDatabaseRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_RestoreDatabaseRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.RestoreDatabaseRequest.class, + com.google.firestore.admin.v1.RestoreDatabaseRequest.Builder.class); + } + + // Construct using com.google.firestore.admin.v1.RestoreDatabaseRequest.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + parent_ = ""; + databaseId_ = ""; + backup_ = ""; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_RestoreDatabaseRequest_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.RestoreDatabaseRequest getDefaultInstanceForType() { + return com.google.firestore.admin.v1.RestoreDatabaseRequest.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.RestoreDatabaseRequest build() { + com.google.firestore.admin.v1.RestoreDatabaseRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.RestoreDatabaseRequest buildPartial() { + com.google.firestore.admin.v1.RestoreDatabaseRequest result = + new com.google.firestore.admin.v1.RestoreDatabaseRequest(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.admin.v1.RestoreDatabaseRequest result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.parent_ = parent_; + } + if (((from_bitField0_ & 0x00000002) != 0)) { + result.databaseId_ = databaseId_; + } + if (((from_bitField0_ & 0x00000004) != 0)) { + result.backup_ = backup_; + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.admin.v1.RestoreDatabaseRequest) { + return mergeFrom((com.google.firestore.admin.v1.RestoreDatabaseRequest) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.admin.v1.RestoreDatabaseRequest other) { + if (other == com.google.firestore.admin.v1.RestoreDatabaseRequest.getDefaultInstance()) + return this; + if (!other.getParent().isEmpty()) { + parent_ = other.parent_; + bitField0_ |= 0x00000001; + onChanged(); + } + if (!other.getDatabaseId().isEmpty()) { + databaseId_ = other.databaseId_; + bitField0_ |= 0x00000002; + onChanged(); + } + if (!other.getBackup().isEmpty()) { + backup_ = other.backup_; + bitField0_ |= 0x00000004; + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + parent_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: + { + databaseId_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000002; + break; + } // case 18 + case 26: + { + backup_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000004; + break; + } // case 26 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private java.lang.Object parent_ = ""; + /** + * + * + *
+     * Required. The project to restore the database in. Format is
+     * `projects/{project_id}`.
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The parent. + */ + public java.lang.String getParent() { + java.lang.Object ref = parent_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + parent_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * Required. The project to restore the database in. Format is
+     * `projects/{project_id}`.
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for parent. + */ + public com.google.protobuf.ByteString getParentBytes() { + java.lang.Object ref = parent_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + parent_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * Required. The project to restore the database in. Format is
+     * `projects/{project_id}`.
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @param value The parent to set. + * @return This builder for chaining. + */ + public Builder setParent(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + parent_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The project to restore the database in. Format is
+     * `projects/{project_id}`.
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return This builder for chaining. + */ + public Builder clearParent() { + parent_ = getDefaultInstance().getParent(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The project to restore the database in. Format is
+     * `projects/{project_id}`.
+     * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @param value The bytes for parent to set. + * @return This builder for chaining. + */ + public Builder setParentBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + parent_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + private java.lang.Object databaseId_ = ""; + /** + * + * + *
+     * Required. The ID to use for the database, which will become the final
+     * component of the database's resource name. This database id must not be
+     * associated with an existing database.
+     *
+     * This value should be 4-63 characters. Valid characters are /[a-z][0-9]-/
+     * with first character a letter and the last a letter or a number. Must not
+     * be UUID-like /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/.
+     *
+     * "(default)" database id is also valid.
+     * 
+ * + * string database_id = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * @return The databaseId. + */ + public java.lang.String getDatabaseId() { + java.lang.Object ref = databaseId_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + databaseId_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * Required. The ID to use for the database, which will become the final
+     * component of the database's resource name. This database id must not be
+     * associated with an existing database.
+     *
+     * This value should be 4-63 characters. Valid characters are /[a-z][0-9]-/
+     * with first character a letter and the last a letter or a number. Must not
+     * be UUID-like /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/.
+     *
+     * "(default)" database id is also valid.
+     * 
+ * + * string database_id = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * @return The bytes for databaseId. + */ + public com.google.protobuf.ByteString getDatabaseIdBytes() { + java.lang.Object ref = databaseId_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + databaseId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * Required. The ID to use for the database, which will become the final
+     * component of the database's resource name. This database id must not be
+     * associated with an existing database.
+     *
+     * This value should be 4-63 characters. Valid characters are /[a-z][0-9]-/
+     * with first character a letter and the last a letter or a number. Must not
+     * be UUID-like /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/.
+     *
+     * "(default)" database id is also valid.
+     * 
+ * + * string database_id = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * @param value The databaseId to set. + * @return This builder for chaining. + */ + public Builder setDatabaseId(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + databaseId_ = value; + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The ID to use for the database, which will become the final
+     * component of the database's resource name. This database id must not be
+     * associated with an existing database.
+     *
+     * This value should be 4-63 characters. Valid characters are /[a-z][0-9]-/
+     * with first character a letter and the last a letter or a number. Must not
+     * be UUID-like /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/.
+     *
+     * "(default)" database id is also valid.
+     * 
+ * + * string database_id = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * @return This builder for chaining. + */ + public Builder clearDatabaseId() { + databaseId_ = getDefaultInstance().getDatabaseId(); + bitField0_ = (bitField0_ & ~0x00000002); + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The ID to use for the database, which will become the final
+     * component of the database's resource name. This database id must not be
+     * associated with an existing database.
+     *
+     * This value should be 4-63 characters. Valid characters are /[a-z][0-9]-/
+     * with first character a letter and the last a letter or a number. Must not
+     * be UUID-like /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/.
+     *
+     * "(default)" database id is also valid.
+     * 
+ * + * string database_id = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * @param value The bytes for databaseId to set. + * @return This builder for chaining. + */ + public Builder setDatabaseIdBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + databaseId_ = value; + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + + private java.lang.Object backup_ = ""; + /** + * + * + *
+     * Required. Backup to restore from. Must be from the same project as the
+     * parent.
+     *
+     * Format is: `projects/{project_id}/locations/{location}/backups/{backup}`
+     * 
+ * + * + * string backup = 3 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The backup. + */ + public java.lang.String getBackup() { + java.lang.Object ref = backup_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + backup_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * Required. Backup to restore from. Must be from the same project as the
+     * parent.
+     *
+     * Format is: `projects/{project_id}/locations/{location}/backups/{backup}`
+     * 
+ * + * + * string backup = 3 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for backup. + */ + public com.google.protobuf.ByteString getBackupBytes() { + java.lang.Object ref = backup_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + backup_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * Required. Backup to restore from. Must be from the same project as the
+     * parent.
+     *
+     * Format is: `projects/{project_id}/locations/{location}/backups/{backup}`
+     * 
+ * + * + * string backup = 3 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @param value The backup to set. + * @return This builder for chaining. + */ + public Builder setBackup(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + backup_ = value; + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + /** + * + * + *
+     * Required. Backup to restore from. Must be from the same project as the
+     * parent.
+     *
+     * Format is: `projects/{project_id}/locations/{location}/backups/{backup}`
+     * 
+ * + * + * string backup = 3 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return This builder for chaining. + */ + public Builder clearBackup() { + backup_ = getDefaultInstance().getBackup(); + bitField0_ = (bitField0_ & ~0x00000004); + onChanged(); + return this; + } + /** + * + * + *
+     * Required. Backup to restore from. Must be from the same project as the
+     * parent.
+     *
+     * Format is: `projects/{project_id}/locations/{location}/backups/{backup}`
+     * 
+ * + * + * string backup = 3 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @param value The bytes for backup to set. + * @return This builder for chaining. + */ + public Builder setBackupBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + backup_ = value; + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.RestoreDatabaseRequest) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.RestoreDatabaseRequest) + private static final com.google.firestore.admin.v1.RestoreDatabaseRequest DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.admin.v1.RestoreDatabaseRequest(); + } + + public static com.google.firestore.admin.v1.RestoreDatabaseRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public RestoreDatabaseRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.RestoreDatabaseRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/RestoreDatabaseRequestOrBuilder.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/RestoreDatabaseRequestOrBuilder.java new file mode 100644 index 000000000..33d7b0110 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/RestoreDatabaseRequestOrBuilder.java @@ -0,0 +1,133 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +public interface RestoreDatabaseRequestOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.RestoreDatabaseRequest) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * Required. The project to restore the database in. Format is
+   * `projects/{project_id}`.
+   * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The parent. + */ + java.lang.String getParent(); + /** + * + * + *
+   * Required. The project to restore the database in. Format is
+   * `projects/{project_id}`.
+   * 
+ * + * + * string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for parent. + */ + com.google.protobuf.ByteString getParentBytes(); + + /** + * + * + *
+   * Required. The ID to use for the database, which will become the final
+   * component of the database's resource name. This database id must not be
+   * associated with an existing database.
+   *
+   * This value should be 4-63 characters. Valid characters are /[a-z][0-9]-/
+   * with first character a letter and the last a letter or a number. Must not
+   * be UUID-like /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/.
+   *
+   * "(default)" database id is also valid.
+   * 
+ * + * string database_id = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * @return The databaseId. + */ + java.lang.String getDatabaseId(); + /** + * + * + *
+   * Required. The ID to use for the database, which will become the final
+   * component of the database's resource name. This database id must not be
+   * associated with an existing database.
+   *
+   * This value should be 4-63 characters. Valid characters are /[a-z][0-9]-/
+   * with first character a letter and the last a letter or a number. Must not
+   * be UUID-like /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/.
+   *
+   * "(default)" database id is also valid.
+   * 
+ * + * string database_id = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * @return The bytes for databaseId. + */ + com.google.protobuf.ByteString getDatabaseIdBytes(); + + /** + * + * + *
+   * Required. Backup to restore from. Must be from the same project as the
+   * parent.
+   *
+   * Format is: `projects/{project_id}/locations/{location}/backups/{backup}`
+   * 
+ * + * + * string backup = 3 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The backup. + */ + java.lang.String getBackup(); + /** + * + * + *
+   * Required. Backup to restore from. Must be from the same project as the
+   * parent.
+   *
+   * Format is: `projects/{project_id}/locations/{location}/backups/{backup}`
+   * 
+ * + * + * string backup = 3 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { ... } + * + * + * @return The bytes for backup. + */ + com.google.protobuf.ByteString getBackupBytes(); +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ScheduleProto.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ScheduleProto.java new file mode 100644 index 000000000..ddec765b9 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/ScheduleProto.java @@ -0,0 +1,131 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/schedule.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +public final class ScheduleProto { + private ScheduleProto() {} + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistryLite registry) {} + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions((com.google.protobuf.ExtensionRegistryLite) registry); + } + + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_BackupSchedule_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_BackupSchedule_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_DailyRecurrence_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_DailyRecurrence_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_admin_v1_WeeklyRecurrence_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_admin_v1_WeeklyRecurrence_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + return descriptor; + } + + private static com.google.protobuf.Descriptors.FileDescriptor descriptor; + + static { + java.lang.String[] descriptorData = { + "\n(google/firestore/admin/v1/schedule.pro" + + "to\022\031google.firestore.admin.v1\032\037google/ap" + + "i/field_behavior.proto\032\031google/api/resou" + + "rce.proto\032\036google/protobuf/duration.prot" + + "o\032\037google/protobuf/timestamp.proto\032\033goog" + + "le/type/dayofweek.proto\"\326\003\n\016BackupSchedu" + + "le\022\021\n\004name\030\001 \001(\tB\003\340A\003\0224\n\013create_time\030\003 \001" + + "(\0132\032.google.protobuf.TimestampB\003\340A\003\0224\n\013u" + + "pdate_time\030\n \001(\0132\032.google.protobuf.Times" + + "tampB\003\340A\003\022,\n\tretention\030\006 \001(\0132\031.google.pr" + + "otobuf.Duration\022F\n\020daily_recurrence\030\007 \001(" + + "\0132*.google.firestore.admin.v1.DailyRecur" + + "renceH\000\022H\n\021weekly_recurrence\030\010 \001(\0132+.goo" + + "gle.firestore.admin.v1.WeeklyRecurrenceH" + + "\000:w\352At\n\'firestore.googleapis.com/BackupS" + + "chedule\022Iprojects/{project}/databases/{d" + + "atabase}/backupSchedules/{backup_schedul" + + "e}B\014\n\nrecurrence\"\021\n\017DailyRecurrence\"7\n\020W" + + "eeklyRecurrence\022#\n\003day\030\002 \001(\0162\026.google.ty" + + "pe.DayOfWeekB\334\001\n\035com.google.firestore.ad" + + "min.v1B\rScheduleProtoP\001Z9cloud.google.co" + + "m/go/firestore/apiv1/admin/adminpb;admin" + + "pb\242\002\004GCFS\252\002\037Google.Cloud.Firestore.Admin" + + ".V1\312\002\037Google\\Cloud\\Firestore\\Admin\\V1\352\002#" + + "Google::Cloud::Firestore::Admin::V1b\006pro" + + "to3" + }; + descriptor = + com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( + descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + com.google.api.FieldBehaviorProto.getDescriptor(), + com.google.api.ResourceProto.getDescriptor(), + com.google.protobuf.DurationProto.getDescriptor(), + com.google.protobuf.TimestampProto.getDescriptor(), + com.google.type.DayOfWeekProto.getDescriptor(), + }); + internal_static_google_firestore_admin_v1_BackupSchedule_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_google_firestore_admin_v1_BackupSchedule_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_BackupSchedule_descriptor, + new java.lang.String[] { + "Name", + "CreateTime", + "UpdateTime", + "Retention", + "DailyRecurrence", + "WeeklyRecurrence", + "Recurrence", + }); + internal_static_google_firestore_admin_v1_DailyRecurrence_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_google_firestore_admin_v1_DailyRecurrence_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_DailyRecurrence_descriptor, + new java.lang.String[] {}); + internal_static_google_firestore_admin_v1_WeeklyRecurrence_descriptor = + getDescriptor().getMessageTypes().get(2); + internal_static_google_firestore_admin_v1_WeeklyRecurrence_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_admin_v1_WeeklyRecurrence_descriptor, + new java.lang.String[] { + "Day", + }); + com.google.protobuf.ExtensionRegistry registry = + com.google.protobuf.ExtensionRegistry.newInstance(); + registry.add(com.google.api.FieldBehaviorProto.fieldBehavior); + registry.add(com.google.api.ResourceProto.resource); + com.google.protobuf.Descriptors.FileDescriptor.internalUpdateFileDescriptor( + descriptor, registry); + com.google.api.FieldBehaviorProto.getDescriptor(); + com.google.api.ResourceProto.getDescriptor(); + com.google.protobuf.DurationProto.getDescriptor(); + com.google.protobuf.TimestampProto.getDescriptor(); + com.google.type.DayOfWeekProto.getDescriptor(); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/UpdateBackupScheduleRequest.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/UpdateBackupScheduleRequest.java new file mode 100644 index 000000000..e0ef6097a --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/UpdateBackupScheduleRequest.java @@ -0,0 +1,1015 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +/** + * + * + *
+ * The request for
+ * [FirestoreAdmin.UpdateBackupSchedule][google.firestore.admin.v1.FirestoreAdmin.UpdateBackupSchedule].
+ * 
+ * + * Protobuf type {@code google.firestore.admin.v1.UpdateBackupScheduleRequest} + */ +public final class UpdateBackupScheduleRequest extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.UpdateBackupScheduleRequest) + UpdateBackupScheduleRequestOrBuilder { + private static final long serialVersionUID = 0L; + // Use UpdateBackupScheduleRequest.newBuilder() to construct. + private UpdateBackupScheduleRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private UpdateBackupScheduleRequest() {} + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new UpdateBackupScheduleRequest(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_UpdateBackupScheduleRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_UpdateBackupScheduleRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.UpdateBackupScheduleRequest.class, + com.google.firestore.admin.v1.UpdateBackupScheduleRequest.Builder.class); + } + + private int bitField0_; + public static final int BACKUP_SCHEDULE_FIELD_NUMBER = 1; + private com.google.firestore.admin.v1.BackupSchedule backupSchedule_; + /** + * + * + *
+   * Required. The backup schedule to update.
+   * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return Whether the backupSchedule field is set. + */ + @java.lang.Override + public boolean hasBackupSchedule() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * + * + *
+   * Required. The backup schedule to update.
+   * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The backupSchedule. + */ + @java.lang.Override + public com.google.firestore.admin.v1.BackupSchedule getBackupSchedule() { + return backupSchedule_ == null + ? com.google.firestore.admin.v1.BackupSchedule.getDefaultInstance() + : backupSchedule_; + } + /** + * + * + *
+   * Required. The backup schedule to update.
+   * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 1 [(.google.api.field_behavior) = REQUIRED]; + * + */ + @java.lang.Override + public com.google.firestore.admin.v1.BackupScheduleOrBuilder getBackupScheduleOrBuilder() { + return backupSchedule_ == null + ? com.google.firestore.admin.v1.BackupSchedule.getDefaultInstance() + : backupSchedule_; + } + + public static final int UPDATE_MASK_FIELD_NUMBER = 2; + private com.google.protobuf.FieldMask updateMask_; + /** + * + * + *
+   * The list of fields to be updated.
+   * 
+ * + * .google.protobuf.FieldMask update_mask = 2; + * + * @return Whether the updateMask field is set. + */ + @java.lang.Override + public boolean hasUpdateMask() { + return ((bitField0_ & 0x00000002) != 0); + } + /** + * + * + *
+   * The list of fields to be updated.
+   * 
+ * + * .google.protobuf.FieldMask update_mask = 2; + * + * @return The updateMask. + */ + @java.lang.Override + public com.google.protobuf.FieldMask getUpdateMask() { + return updateMask_ == null ? com.google.protobuf.FieldMask.getDefaultInstance() : updateMask_; + } + /** + * + * + *
+   * The list of fields to be updated.
+   * 
+ * + * .google.protobuf.FieldMask update_mask = 2; + */ + @java.lang.Override + public com.google.protobuf.FieldMaskOrBuilder getUpdateMaskOrBuilder() { + return updateMask_ == null ? com.google.protobuf.FieldMask.getDefaultInstance() : updateMask_; + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (((bitField0_ & 0x00000001) != 0)) { + output.writeMessage(1, getBackupSchedule()); + } + if (((bitField0_ & 0x00000002) != 0)) { + output.writeMessage(2, getUpdateMask()); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(1, getBackupSchedule()); + } + if (((bitField0_ & 0x00000002) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(2, getUpdateMask()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.admin.v1.UpdateBackupScheduleRequest)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.UpdateBackupScheduleRequest other = + (com.google.firestore.admin.v1.UpdateBackupScheduleRequest) obj; + + if (hasBackupSchedule() != other.hasBackupSchedule()) return false; + if (hasBackupSchedule()) { + if (!getBackupSchedule().equals(other.getBackupSchedule())) return false; + } + if (hasUpdateMask() != other.hasUpdateMask()) return false; + if (hasUpdateMask()) { + if (!getUpdateMask().equals(other.getUpdateMask())) return false; + } + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (hasBackupSchedule()) { + hash = (37 * hash) + BACKUP_SCHEDULE_FIELD_NUMBER; + hash = (53 * hash) + getBackupSchedule().hashCode(); + } + if (hasUpdateMask()) { + hash = (37 * hash) + UPDATE_MASK_FIELD_NUMBER; + hash = (53 * hash) + getUpdateMask().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.UpdateBackupScheduleRequest parseFrom( + java.nio.ByteBuffer data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.UpdateBackupScheduleRequest parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.UpdateBackupScheduleRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.UpdateBackupScheduleRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.UpdateBackupScheduleRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.UpdateBackupScheduleRequest parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.UpdateBackupScheduleRequest parseFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.UpdateBackupScheduleRequest parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.UpdateBackupScheduleRequest parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.UpdateBackupScheduleRequest parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.UpdateBackupScheduleRequest parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.UpdateBackupScheduleRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder( + com.google.firestore.admin.v1.UpdateBackupScheduleRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * The request for
+   * [FirestoreAdmin.UpdateBackupSchedule][google.firestore.admin.v1.FirestoreAdmin.UpdateBackupSchedule].
+   * 
+ * + * Protobuf type {@code google.firestore.admin.v1.UpdateBackupScheduleRequest} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.UpdateBackupScheduleRequest) + com.google.firestore.admin.v1.UpdateBackupScheduleRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_UpdateBackupScheduleRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_UpdateBackupScheduleRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.UpdateBackupScheduleRequest.class, + com.google.firestore.admin.v1.UpdateBackupScheduleRequest.Builder.class); + } + + // Construct using com.google.firestore.admin.v1.UpdateBackupScheduleRequest.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) { + getBackupScheduleFieldBuilder(); + getUpdateMaskFieldBuilder(); + } + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + backupSchedule_ = null; + if (backupScheduleBuilder_ != null) { + backupScheduleBuilder_.dispose(); + backupScheduleBuilder_ = null; + } + updateMask_ = null; + if (updateMaskBuilder_ != null) { + updateMaskBuilder_.dispose(); + updateMaskBuilder_ = null; + } + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.FirestoreAdminProto + .internal_static_google_firestore_admin_v1_UpdateBackupScheduleRequest_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.UpdateBackupScheduleRequest getDefaultInstanceForType() { + return com.google.firestore.admin.v1.UpdateBackupScheduleRequest.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.UpdateBackupScheduleRequest build() { + com.google.firestore.admin.v1.UpdateBackupScheduleRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.UpdateBackupScheduleRequest buildPartial() { + com.google.firestore.admin.v1.UpdateBackupScheduleRequest result = + new com.google.firestore.admin.v1.UpdateBackupScheduleRequest(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.admin.v1.UpdateBackupScheduleRequest result) { + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.backupSchedule_ = + backupScheduleBuilder_ == null ? backupSchedule_ : backupScheduleBuilder_.build(); + to_bitField0_ |= 0x00000001; + } + if (((from_bitField0_ & 0x00000002) != 0)) { + result.updateMask_ = updateMaskBuilder_ == null ? updateMask_ : updateMaskBuilder_.build(); + to_bitField0_ |= 0x00000002; + } + result.bitField0_ |= to_bitField0_; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.admin.v1.UpdateBackupScheduleRequest) { + return mergeFrom((com.google.firestore.admin.v1.UpdateBackupScheduleRequest) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.admin.v1.UpdateBackupScheduleRequest other) { + if (other == com.google.firestore.admin.v1.UpdateBackupScheduleRequest.getDefaultInstance()) + return this; + if (other.hasBackupSchedule()) { + mergeBackupSchedule(other.getBackupSchedule()); + } + if (other.hasUpdateMask()) { + mergeUpdateMask(other.getUpdateMask()); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + input.readMessage(getBackupScheduleFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: + { + input.readMessage(getUpdateMaskFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000002; + break; + } // case 18 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private com.google.firestore.admin.v1.BackupSchedule backupSchedule_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.BackupSchedule, + com.google.firestore.admin.v1.BackupSchedule.Builder, + com.google.firestore.admin.v1.BackupScheduleOrBuilder> + backupScheduleBuilder_; + /** + * + * + *
+     * Required. The backup schedule to update.
+     * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return Whether the backupSchedule field is set. + */ + public boolean hasBackupSchedule() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * + * + *
+     * Required. The backup schedule to update.
+     * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The backupSchedule. + */ + public com.google.firestore.admin.v1.BackupSchedule getBackupSchedule() { + if (backupScheduleBuilder_ == null) { + return backupSchedule_ == null + ? com.google.firestore.admin.v1.BackupSchedule.getDefaultInstance() + : backupSchedule_; + } else { + return backupScheduleBuilder_.getMessage(); + } + } + /** + * + * + *
+     * Required. The backup schedule to update.
+     * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 1 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder setBackupSchedule(com.google.firestore.admin.v1.BackupSchedule value) { + if (backupScheduleBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + backupSchedule_ = value; + } else { + backupScheduleBuilder_.setMessage(value); + } + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The backup schedule to update.
+     * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 1 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder setBackupSchedule( + com.google.firestore.admin.v1.BackupSchedule.Builder builderForValue) { + if (backupScheduleBuilder_ == null) { + backupSchedule_ = builderForValue.build(); + } else { + backupScheduleBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The backup schedule to update.
+     * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 1 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder mergeBackupSchedule(com.google.firestore.admin.v1.BackupSchedule value) { + if (backupScheduleBuilder_ == null) { + if (((bitField0_ & 0x00000001) != 0) + && backupSchedule_ != null + && backupSchedule_ + != com.google.firestore.admin.v1.BackupSchedule.getDefaultInstance()) { + getBackupScheduleBuilder().mergeFrom(value); + } else { + backupSchedule_ = value; + } + } else { + backupScheduleBuilder_.mergeFrom(value); + } + if (backupSchedule_ != null) { + bitField0_ |= 0x00000001; + onChanged(); + } + return this; + } + /** + * + * + *
+     * Required. The backup schedule to update.
+     * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 1 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder clearBackupSchedule() { + bitField0_ = (bitField0_ & ~0x00000001); + backupSchedule_ = null; + if (backupScheduleBuilder_ != null) { + backupScheduleBuilder_.dispose(); + backupScheduleBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * Required. The backup schedule to update.
+     * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 1 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public com.google.firestore.admin.v1.BackupSchedule.Builder getBackupScheduleBuilder() { + bitField0_ |= 0x00000001; + onChanged(); + return getBackupScheduleFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * Required. The backup schedule to update.
+     * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 1 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public com.google.firestore.admin.v1.BackupScheduleOrBuilder getBackupScheduleOrBuilder() { + if (backupScheduleBuilder_ != null) { + return backupScheduleBuilder_.getMessageOrBuilder(); + } else { + return backupSchedule_ == null + ? com.google.firestore.admin.v1.BackupSchedule.getDefaultInstance() + : backupSchedule_; + } + } + /** + * + * + *
+     * Required. The backup schedule to update.
+     * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 1 [(.google.api.field_behavior) = REQUIRED]; + * + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.BackupSchedule, + com.google.firestore.admin.v1.BackupSchedule.Builder, + com.google.firestore.admin.v1.BackupScheduleOrBuilder> + getBackupScheduleFieldBuilder() { + if (backupScheduleBuilder_ == null) { + backupScheduleBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.admin.v1.BackupSchedule, + com.google.firestore.admin.v1.BackupSchedule.Builder, + com.google.firestore.admin.v1.BackupScheduleOrBuilder>( + getBackupSchedule(), getParentForChildren(), isClean()); + backupSchedule_ = null; + } + return backupScheduleBuilder_; + } + + private com.google.protobuf.FieldMask updateMask_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.FieldMask, + com.google.protobuf.FieldMask.Builder, + com.google.protobuf.FieldMaskOrBuilder> + updateMaskBuilder_; + /** + * + * + *
+     * The list of fields to be updated.
+     * 
+ * + * .google.protobuf.FieldMask update_mask = 2; + * + * @return Whether the updateMask field is set. + */ + public boolean hasUpdateMask() { + return ((bitField0_ & 0x00000002) != 0); + } + /** + * + * + *
+     * The list of fields to be updated.
+     * 
+ * + * .google.protobuf.FieldMask update_mask = 2; + * + * @return The updateMask. + */ + public com.google.protobuf.FieldMask getUpdateMask() { + if (updateMaskBuilder_ == null) { + return updateMask_ == null + ? com.google.protobuf.FieldMask.getDefaultInstance() + : updateMask_; + } else { + return updateMaskBuilder_.getMessage(); + } + } + /** + * + * + *
+     * The list of fields to be updated.
+     * 
+ * + * .google.protobuf.FieldMask update_mask = 2; + */ + public Builder setUpdateMask(com.google.protobuf.FieldMask value) { + if (updateMaskBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + updateMask_ = value; + } else { + updateMaskBuilder_.setMessage(value); + } + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+     * The list of fields to be updated.
+     * 
+ * + * .google.protobuf.FieldMask update_mask = 2; + */ + public Builder setUpdateMask(com.google.protobuf.FieldMask.Builder builderForValue) { + if (updateMaskBuilder_ == null) { + updateMask_ = builderForValue.build(); + } else { + updateMaskBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+     * The list of fields to be updated.
+     * 
+ * + * .google.protobuf.FieldMask update_mask = 2; + */ + public Builder mergeUpdateMask(com.google.protobuf.FieldMask value) { + if (updateMaskBuilder_ == null) { + if (((bitField0_ & 0x00000002) != 0) + && updateMask_ != null + && updateMask_ != com.google.protobuf.FieldMask.getDefaultInstance()) { + getUpdateMaskBuilder().mergeFrom(value); + } else { + updateMask_ = value; + } + } else { + updateMaskBuilder_.mergeFrom(value); + } + if (updateMask_ != null) { + bitField0_ |= 0x00000002; + onChanged(); + } + return this; + } + /** + * + * + *
+     * The list of fields to be updated.
+     * 
+ * + * .google.protobuf.FieldMask update_mask = 2; + */ + public Builder clearUpdateMask() { + bitField0_ = (bitField0_ & ~0x00000002); + updateMask_ = null; + if (updateMaskBuilder_ != null) { + updateMaskBuilder_.dispose(); + updateMaskBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * The list of fields to be updated.
+     * 
+ * + * .google.protobuf.FieldMask update_mask = 2; + */ + public com.google.protobuf.FieldMask.Builder getUpdateMaskBuilder() { + bitField0_ |= 0x00000002; + onChanged(); + return getUpdateMaskFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * The list of fields to be updated.
+     * 
+ * + * .google.protobuf.FieldMask update_mask = 2; + */ + public com.google.protobuf.FieldMaskOrBuilder getUpdateMaskOrBuilder() { + if (updateMaskBuilder_ != null) { + return updateMaskBuilder_.getMessageOrBuilder(); + } else { + return updateMask_ == null + ? com.google.protobuf.FieldMask.getDefaultInstance() + : updateMask_; + } + } + /** + * + * + *
+     * The list of fields to be updated.
+     * 
+ * + * .google.protobuf.FieldMask update_mask = 2; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.FieldMask, + com.google.protobuf.FieldMask.Builder, + com.google.protobuf.FieldMaskOrBuilder> + getUpdateMaskFieldBuilder() { + if (updateMaskBuilder_ == null) { + updateMaskBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.FieldMask, + com.google.protobuf.FieldMask.Builder, + com.google.protobuf.FieldMaskOrBuilder>( + getUpdateMask(), getParentForChildren(), isClean()); + updateMask_ = null; + } + return updateMaskBuilder_; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.UpdateBackupScheduleRequest) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.UpdateBackupScheduleRequest) + private static final com.google.firestore.admin.v1.UpdateBackupScheduleRequest DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.admin.v1.UpdateBackupScheduleRequest(); + } + + public static com.google.firestore.admin.v1.UpdateBackupScheduleRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public UpdateBackupScheduleRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.UpdateBackupScheduleRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/UpdateBackupScheduleRequestOrBuilder.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/UpdateBackupScheduleRequestOrBuilder.java new file mode 100644 index 000000000..07e4d0cb7 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/UpdateBackupScheduleRequestOrBuilder.java @@ -0,0 +1,102 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/firestore_admin.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +public interface UpdateBackupScheduleRequestOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.UpdateBackupScheduleRequest) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * Required. The backup schedule to update.
+   * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return Whether the backupSchedule field is set. + */ + boolean hasBackupSchedule(); + /** + * + * + *
+   * Required. The backup schedule to update.
+   * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The backupSchedule. + */ + com.google.firestore.admin.v1.BackupSchedule getBackupSchedule(); + /** + * + * + *
+   * Required. The backup schedule to update.
+   * 
+ * + * + * .google.firestore.admin.v1.BackupSchedule backup_schedule = 1 [(.google.api.field_behavior) = REQUIRED]; + * + */ + com.google.firestore.admin.v1.BackupScheduleOrBuilder getBackupScheduleOrBuilder(); + + /** + * + * + *
+   * The list of fields to be updated.
+   * 
+ * + * .google.protobuf.FieldMask update_mask = 2; + * + * @return Whether the updateMask field is set. + */ + boolean hasUpdateMask(); + /** + * + * + *
+   * The list of fields to be updated.
+   * 
+ * + * .google.protobuf.FieldMask update_mask = 2; + * + * @return The updateMask. + */ + com.google.protobuf.FieldMask getUpdateMask(); + /** + * + * + *
+   * The list of fields to be updated.
+   * 
+ * + * .google.protobuf.FieldMask update_mask = 2; + */ + com.google.protobuf.FieldMaskOrBuilder getUpdateMaskOrBuilder(); +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/WeeklyRecurrence.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/WeeklyRecurrence.java new file mode 100644 index 000000000..58dcabbaf --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/WeeklyRecurrence.java @@ -0,0 +1,606 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/schedule.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +/** + * + * + *
+ * Represents a recurring schedule that runs on a specified day of the week.
+ *
+ * The time zone is UTC.
+ * 
+ * + * Protobuf type {@code google.firestore.admin.v1.WeeklyRecurrence} + */ +public final class WeeklyRecurrence extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.admin.v1.WeeklyRecurrence) + WeeklyRecurrenceOrBuilder { + private static final long serialVersionUID = 0L; + // Use WeeklyRecurrence.newBuilder() to construct. + private WeeklyRecurrence(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private WeeklyRecurrence() { + day_ = 0; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new WeeklyRecurrence(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.ScheduleProto + .internal_static_google_firestore_admin_v1_WeeklyRecurrence_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.ScheduleProto + .internal_static_google_firestore_admin_v1_WeeklyRecurrence_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.WeeklyRecurrence.class, + com.google.firestore.admin.v1.WeeklyRecurrence.Builder.class); + } + + public static final int DAY_FIELD_NUMBER = 2; + private int day_ = 0; + /** + * + * + *
+   * The day of week to run.
+   *
+   * DAY_OF_WEEK_UNSPECIFIED is not allowed.
+   * 
+ * + * .google.type.DayOfWeek day = 2; + * + * @return The enum numeric value on the wire for day. + */ + @java.lang.Override + public int getDayValue() { + return day_; + } + /** + * + * + *
+   * The day of week to run.
+   *
+   * DAY_OF_WEEK_UNSPECIFIED is not allowed.
+   * 
+ * + * .google.type.DayOfWeek day = 2; + * + * @return The day. + */ + @java.lang.Override + public com.google.type.DayOfWeek getDay() { + com.google.type.DayOfWeek result = com.google.type.DayOfWeek.forNumber(day_); + return result == null ? com.google.type.DayOfWeek.UNRECOGNIZED : result; + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (day_ != com.google.type.DayOfWeek.DAY_OF_WEEK_UNSPECIFIED.getNumber()) { + output.writeEnum(2, day_); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (day_ != com.google.type.DayOfWeek.DAY_OF_WEEK_UNSPECIFIED.getNumber()) { + size += com.google.protobuf.CodedOutputStream.computeEnumSize(2, day_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.admin.v1.WeeklyRecurrence)) { + return super.equals(obj); + } + com.google.firestore.admin.v1.WeeklyRecurrence other = + (com.google.firestore.admin.v1.WeeklyRecurrence) obj; + + if (day_ != other.day_) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + DAY_FIELD_NUMBER; + hash = (53 * hash) + day_; + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.admin.v1.WeeklyRecurrence parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.WeeklyRecurrence parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.WeeklyRecurrence parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.WeeklyRecurrence parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.WeeklyRecurrence parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.admin.v1.WeeklyRecurrence parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.admin.v1.WeeklyRecurrence parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.WeeklyRecurrence parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.WeeklyRecurrence parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.WeeklyRecurrence parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.admin.v1.WeeklyRecurrence parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.admin.v1.WeeklyRecurrence parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.admin.v1.WeeklyRecurrence prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * Represents a recurring schedule that runs on a specified day of the week.
+   *
+   * The time zone is UTC.
+   * 
+ * + * Protobuf type {@code google.firestore.admin.v1.WeeklyRecurrence} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.admin.v1.WeeklyRecurrence) + com.google.firestore.admin.v1.WeeklyRecurrenceOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.admin.v1.ScheduleProto + .internal_static_google_firestore_admin_v1_WeeklyRecurrence_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.admin.v1.ScheduleProto + .internal_static_google_firestore_admin_v1_WeeklyRecurrence_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.admin.v1.WeeklyRecurrence.class, + com.google.firestore.admin.v1.WeeklyRecurrence.Builder.class); + } + + // Construct using com.google.firestore.admin.v1.WeeklyRecurrence.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + day_ = 0; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.admin.v1.ScheduleProto + .internal_static_google_firestore_admin_v1_WeeklyRecurrence_descriptor; + } + + @java.lang.Override + public com.google.firestore.admin.v1.WeeklyRecurrence getDefaultInstanceForType() { + return com.google.firestore.admin.v1.WeeklyRecurrence.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.admin.v1.WeeklyRecurrence build() { + com.google.firestore.admin.v1.WeeklyRecurrence result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.admin.v1.WeeklyRecurrence buildPartial() { + com.google.firestore.admin.v1.WeeklyRecurrence result = + new com.google.firestore.admin.v1.WeeklyRecurrence(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.admin.v1.WeeklyRecurrence result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.day_ = day_; + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.admin.v1.WeeklyRecurrence) { + return mergeFrom((com.google.firestore.admin.v1.WeeklyRecurrence) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.admin.v1.WeeklyRecurrence other) { + if (other == com.google.firestore.admin.v1.WeeklyRecurrence.getDefaultInstance()) return this; + if (other.day_ != 0) { + setDayValue(other.getDayValue()); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 16: + { + day_ = input.readEnum(); + bitField0_ |= 0x00000001; + break; + } // case 16 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private int day_ = 0; + /** + * + * + *
+     * The day of week to run.
+     *
+     * DAY_OF_WEEK_UNSPECIFIED is not allowed.
+     * 
+ * + * .google.type.DayOfWeek day = 2; + * + * @return The enum numeric value on the wire for day. + */ + @java.lang.Override + public int getDayValue() { + return day_; + } + /** + * + * + *
+     * The day of week to run.
+     *
+     * DAY_OF_WEEK_UNSPECIFIED is not allowed.
+     * 
+ * + * .google.type.DayOfWeek day = 2; + * + * @param value The enum numeric value on the wire for day to set. + * @return This builder for chaining. + */ + public Builder setDayValue(int value) { + day_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * The day of week to run.
+     *
+     * DAY_OF_WEEK_UNSPECIFIED is not allowed.
+     * 
+ * + * .google.type.DayOfWeek day = 2; + * + * @return The day. + */ + @java.lang.Override + public com.google.type.DayOfWeek getDay() { + com.google.type.DayOfWeek result = com.google.type.DayOfWeek.forNumber(day_); + return result == null ? com.google.type.DayOfWeek.UNRECOGNIZED : result; + } + /** + * + * + *
+     * The day of week to run.
+     *
+     * DAY_OF_WEEK_UNSPECIFIED is not allowed.
+     * 
+ * + * .google.type.DayOfWeek day = 2; + * + * @param value The day to set. + * @return This builder for chaining. + */ + public Builder setDay(com.google.type.DayOfWeek value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + day_ = value.getNumber(); + onChanged(); + return this; + } + /** + * + * + *
+     * The day of week to run.
+     *
+     * DAY_OF_WEEK_UNSPECIFIED is not allowed.
+     * 
+ * + * .google.type.DayOfWeek day = 2; + * + * @return This builder for chaining. + */ + public Builder clearDay() { + bitField0_ = (bitField0_ & ~0x00000001); + day_ = 0; + onChanged(); + return this; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.admin.v1.WeeklyRecurrence) + } + + // @@protoc_insertion_point(class_scope:google.firestore.admin.v1.WeeklyRecurrence) + private static final com.google.firestore.admin.v1.WeeklyRecurrence DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.admin.v1.WeeklyRecurrence(); + } + + public static com.google.firestore.admin.v1.WeeklyRecurrence getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public WeeklyRecurrence parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.admin.v1.WeeklyRecurrence getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/WeeklyRecurrenceOrBuilder.java b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/WeeklyRecurrenceOrBuilder.java new file mode 100644 index 000000000..668210ab6 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/java/com/google/firestore/admin/v1/WeeklyRecurrenceOrBuilder.java @@ -0,0 +1,55 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/admin/v1/schedule.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.admin.v1; + +public interface WeeklyRecurrenceOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.admin.v1.WeeklyRecurrence) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * The day of week to run.
+   *
+   * DAY_OF_WEEK_UNSPECIFIED is not allowed.
+   * 
+ * + * .google.type.DayOfWeek day = 2; + * + * @return The enum numeric value on the wire for day. + */ + int getDayValue(); + /** + * + * + *
+   * The day of week to run.
+   *
+   * DAY_OF_WEEK_UNSPECIFIED is not allowed.
+   * 
+ * + * .google.type.DayOfWeek day = 2; + * + * @return The day. + */ + com.google.type.DayOfWeek getDay(); +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/backup.proto b/proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/backup.proto new file mode 100644 index 000000000..e01f81ff8 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/backup.proto @@ -0,0 +1,107 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.firestore.admin.v1; + +import "google/api/field_behavior.proto"; +import "google/api/resource.proto"; +import "google/protobuf/timestamp.proto"; + +option csharp_namespace = "Google.Cloud.Firestore.Admin.V1"; +option go_package = "cloud.google.com/go/firestore/apiv1/admin/adminpb;adminpb"; +option java_multiple_files = true; +option java_outer_classname = "BackupProto"; +option java_package = "com.google.firestore.admin.v1"; +option objc_class_prefix = "GCFS"; +option php_namespace = "Google\\Cloud\\Firestore\\Admin\\V1"; +option ruby_package = "Google::Cloud::Firestore::Admin::V1"; + +// A Backup of a Cloud Firestore Database. +// +// The backup contains all documents and index configurations for the given +// database at a specific point in time. +message Backup { + option (google.api.resource) = { + type: "firestore.googleapis.com/Backup" + pattern: "projects/{project}/locations/{location}/backups/{backup}" + }; + + // Backup specific statistics. + message Stats { + // Output only. Summation of the size of all documents and index entries in + // the backup, measured in bytes. + int64 size_bytes = 1 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. The total number of documents contained in the backup. + int64 document_count = 2 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. The total number of index entries contained in the backup. + int64 index_count = 3 [(google.api.field_behavior) = OUTPUT_ONLY]; + } + + // Indicate the current state of the backup. + enum State { + // The state is unspecified. + STATE_UNSPECIFIED = 0; + + // The pending backup is still being created. Operations on the + // backup will be rejected in this state. + CREATING = 1; + + // The backup is complete and ready to use. + READY = 2; + + // The backup is not available at this moment. + NOT_AVAILABLE = 3; + } + + // Output only. The unique resource name of the Backup. + // + // Format is `projects/{project}/locations/{location}/backups/{backup}`. + string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. Name of the Firestore database that the backup is from. + // + // Format is `projects/{project}/databases/{database}`. + string database = 2 [ + (google.api.field_behavior) = OUTPUT_ONLY, + (google.api.resource_reference) = { + type: "firestore.googleapis.com/Database" + } + ]; + + // Output only. The system-generated UUID4 for the Firestore database that the + // backup is from. + string database_uid = 7 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. The backup contains an externally consistent copy of the + // database at this time. + google.protobuf.Timestamp snapshot_time = 3 + [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. The timestamp at which this backup expires. + google.protobuf.Timestamp expire_time = 4 + [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. Statistics about the backup. + // + // This data only becomes available after the backup is fully materialized to + // secondary storage. This field will be empty till then. + Stats stats = 6 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. The current state of the backup. + State state = 8 [(google.api.field_behavior) = OUTPUT_ONLY]; +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/firestore_admin.proto b/proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/firestore_admin.proto index 07cc764b5..a9bfa6ec9 100644 --- a/proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/firestore_admin.proto +++ b/proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/firestore_admin.proto @@ -20,10 +20,12 @@ import "google/api/annotations.proto"; import "google/api/client.proto"; import "google/api/field_behavior.proto"; import "google/api/resource.proto"; +import "google/firestore/admin/v1/backup.proto"; import "google/firestore/admin/v1/database.proto"; import "google/firestore/admin/v1/field.proto"; import "google/firestore/admin/v1/index.proto"; import "google/firestore/admin/v1/operation.proto"; +import "google/firestore/admin/v1/schedule.proto"; import "google/longrunning/operations.proto"; import "google/protobuf/empty.proto"; import "google/protobuf/field_mask.proto"; @@ -271,6 +273,107 @@ service FirestoreAdmin { metadata_type: "DeleteDatabaseMetadata" }; } + + // Gets information about a backup. + rpc GetBackup(GetBackupRequest) returns (Backup) { + option (google.api.http) = { + get: "/v1/{name=projects/*/locations/*/backups/*}" + }; + option (google.api.method_signature) = "name"; + } + + // Lists all the backups. + rpc ListBackups(ListBackupsRequest) returns (ListBackupsResponse) { + option (google.api.http) = { + get: "/v1/{parent=projects/*/locations/*}/backups" + }; + option (google.api.method_signature) = "parent"; + } + + // Deletes a backup. + rpc DeleteBackup(DeleteBackupRequest) returns (google.protobuf.Empty) { + option (google.api.http) = { + delete: "/v1/{name=projects/*/locations/*/backups/*}" + }; + option (google.api.method_signature) = "name"; + } + + // Creates a new database by restoring from an existing backup. + // + // The new database must be in the same cloud region or multi-region location + // as the existing backup. This behaves similar to + // [FirestoreAdmin.CreateDatabase][google.firestore.admin.v1.CreateDatabase] + // except instead of creating a new empty database, a new database is created + // with the database type, index configuration, and documents from an existing + // backup. + // + // The [long-running operation][google.longrunning.Operation] can be used to + // track the progress of the restore, with the Operation's + // [metadata][google.longrunning.Operation.metadata] field type being the + // [RestoreDatabaseMetadata][google.firestore.admin.v1.RestoreDatabaseMetadata]. + // The [response][google.longrunning.Operation.response] type is the + // [Database][google.firestore.admin.v1.Database] if the restore was + // successful. The new database is not readable or writeable until the LRO has + // completed. + rpc RestoreDatabase(RestoreDatabaseRequest) + returns (google.longrunning.Operation) { + option (google.api.http) = { + post: "/v1/{parent=projects/*}/databases:restore" + body: "*" + }; + option (google.longrunning.operation_info) = { + response_type: "Database" + metadata_type: "RestoreDatabaseMetadata" + }; + } + + // Creates a backup schedule on a database. + // At most two backup schedules can be configured on a database, one daily + // backup schedule and one weekly backup schedule. + rpc CreateBackupSchedule(CreateBackupScheduleRequest) + returns (BackupSchedule) { + option (google.api.http) = { + post: "/v1/{parent=projects/*/databases/*}/backupSchedules" + body: "backup_schedule" + }; + option (google.api.method_signature) = "parent,backup_schedule"; + } + + // Gets information about a backup schedule. + rpc GetBackupSchedule(GetBackupScheduleRequest) returns (BackupSchedule) { + option (google.api.http) = { + get: "/v1/{name=projects/*/databases/*/backupSchedules/*}" + }; + option (google.api.method_signature) = "name"; + } + + // List backup schedules. + rpc ListBackupSchedules(ListBackupSchedulesRequest) + returns (ListBackupSchedulesResponse) { + option (google.api.http) = { + get: "/v1/{parent=projects/*/databases/*}/backupSchedules" + }; + option (google.api.method_signature) = "parent"; + } + + // Updates a backup schedule. + rpc UpdateBackupSchedule(UpdateBackupScheduleRequest) + returns (BackupSchedule) { + option (google.api.http) = { + patch: "/v1/{backup_schedule.name=projects/*/databases/*/backupSchedules/*}" + body: "backup_schedule" + }; + option (google.api.method_signature) = "backup_schedule,update_mask"; + } + + // Deletes a backup schedule. + rpc DeleteBackupSchedule(DeleteBackupScheduleRequest) + returns (google.protobuf.Empty) { + option (google.api.http) = { + delete: "/v1/{name=projects/*/databases/*/backupSchedules/*}" + }; + option (google.api.method_signature) = "name"; + } } // A request to list the Firestore Databases in all locations for a project. @@ -378,6 +481,83 @@ message DeleteDatabaseRequest { // Metadata related to the delete database operation. message DeleteDatabaseMetadata {} +// The request for +// [FirestoreAdmin.CreateBackupSchedule][google.firestore.admin.v1.FirestoreAdmin.CreateBackupSchedule]. +message CreateBackupScheduleRequest { + // Required. The parent database. + // + // Format `projects/{project}/databases/{database}` + string parent = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "firestore.googleapis.com/Database" + } + ]; + + // Required. The backup schedule to create. + BackupSchedule backup_schedule = 2 [(google.api.field_behavior) = REQUIRED]; +} + +// The request for +// [FirestoreAdmin.GetBackupSchedule][google.firestore.admin.v1.FirestoreAdmin.GetBackupSchedule]. +message GetBackupScheduleRequest { + // Required. The name of the backup schedule. + // + // Format + // `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}` + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "firestore.googleapis.com/BackupSchedule" + } + ]; +} + +// The request for +// [FirestoreAdmin.UpdateBackupSchedule][google.firestore.admin.v1.FirestoreAdmin.UpdateBackupSchedule]. +message UpdateBackupScheduleRequest { + // Required. The backup schedule to update. + BackupSchedule backup_schedule = 1 [(google.api.field_behavior) = REQUIRED]; + + // The list of fields to be updated. + google.protobuf.FieldMask update_mask = 2; +} + +// The request for +// [FirestoreAdmin.ListBackupSchedules][google.firestore.admin.v1.FirestoreAdmin.ListBackupSchedules]. +message ListBackupSchedulesRequest { + // Required. The parent database. + // + // Format is `projects/{project}/databases/{database}`. + string parent = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "firestore.googleapis.com/Database" + } + ]; +} + +// The response for +// [FirestoreAdmin.ListBackupSchedules][google.firestore.admin.v1.FirestoreAdmin.ListBackupSchedules]. +message ListBackupSchedulesResponse { + // List of all backup schedules. + repeated BackupSchedule backup_schedules = 1; +} + +// The request for [FirestoreAdmin.DeleteBackupSchedules][]. +message DeleteBackupScheduleRequest { + // Required. The name of the backup schedule. + // + // Format + // `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}` + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "firestore.googleapis.com/BackupSchedule" + } + ]; +} + // The request for // [FirestoreAdmin.CreateIndex][google.firestore.admin.v1.FirestoreAdmin.CreateIndex]. message CreateIndexRequest { @@ -587,3 +767,98 @@ message ImportDocumentsRequest { // to include them. Each namespace in this list must be unique. repeated string namespace_ids = 4; } + +// The request for +// [FirestoreAdmin.GetBackup][google.firestore.admin.v1.FirestoreAdmin.GetBackup]. +message GetBackupRequest { + // Required. Name of the backup to fetch. + // + // Format is `projects/{project}/locations/{location}/backups/{backup}`. + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "firestore.googleapis.com/Backup" + } + ]; +} + +// The request for +// [FirestoreAdmin.ListBackups][google.firestore.admin.v1.FirestoreAdmin.ListBackups]. +message ListBackupsRequest { + // Required. The location to list backups from. + // + // Format is `projects/{project}/locations/{location}`. + // Use `{location} = '-'` to list backups from all locations for the given + // project. This allows listing backups from a single location or from all + // locations. + string parent = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "firestore.googleapis.com/Location" + } + ]; +} + +// The response for +// [FirestoreAdmin.ListBackups][google.firestore.admin.v1.FirestoreAdmin.ListBackups]. +message ListBackupsResponse { + // List of all backups for the project. + repeated Backup backups = 1; + + // List of locations that existing backups were not able to be fetched from. + // + // Instead of failing the entire requests when a single location is + // unreachable, this response returns a partial result set and list of + // locations unable to be reached here. The request can be retried against a + // single location to get a concrete error. + repeated string unreachable = 3; +} + +// The request for +// [FirestoreAdmin.DeleteBackup][google.firestore.admin.v1.FirestoreAdmin.DeleteBackup]. +message DeleteBackupRequest { + // Required. Name of the backup to delete. + // + // format is `projects/{project}/locations/{location}/backups/{backup}`. + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "firestore.googleapis.com/Backup" + } + ]; +} + +// The request message for +// [FirestoreAdmin.RestoreDatabase][google.firestore.admin.v1.RestoreDatabase]. +message RestoreDatabaseRequest { + // Required. The project to restore the database in. Format is + // `projects/{project_id}`. + string parent = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + child_type: "firestore.googleapis.com/Database" + } + ]; + + // Required. The ID to use for the database, which will become the final + // component of the database's resource name. This database id must not be + // associated with an existing database. + // + // This value should be 4-63 characters. Valid characters are /[a-z][0-9]-/ + // with first character a letter and the last a letter or a number. Must not + // be UUID-like /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/. + // + // "(default)" database id is also valid. + string database_id = 2 [(google.api.field_behavior) = REQUIRED]; + + // Required. Backup to restore from. Must be from the same project as the + // parent. + // + // Format is: `projects/{project_id}/locations/{location}/backups/{backup}` + string backup = 3 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "firestore.googleapis.com/Backup" + } + ]; +} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/index.proto b/proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/index.proto index 2567da650..add5c3f3f 100644 --- a/proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/index.proto +++ b/proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/index.proto @@ -16,6 +16,7 @@ syntax = "proto3"; package google.firestore.admin.v1; +import "google/api/field_behavior.proto"; import "google/api/resource.proto"; option csharp_namespace = "Google.Cloud.Firestore.Admin.V1"; @@ -92,6 +93,25 @@ message Index { CONTAINS = 1; } + // The index configuration to support vector search operations + message VectorConfig { + // An index that stores vectors in a flat data structure, and supports + // exhaustive search. + message FlatIndex {} + + // Required. The vector dimension this configuration applies to. + // + // The resulting index will only include vectors of this dimension, and + // can be used for vector search with the same dimension. + int32 dimension = 1 [(google.api.field_behavior) = REQUIRED]; + + // The type of index used. + oneof type { + // Indicates the vector index is a flat index. + FlatIndex flat = 2; + } + } + // Can be __name__. // For single field indexes, this must match the name of the field or may // be omitted. @@ -105,6 +125,10 @@ message Index { // Indicates that this field supports operations on `array_value`s. ArrayConfig array_config = 3; + + // Indicates that this field supports nearest neighbors and distance + // operations on vector. + VectorConfig vector_config = 4; } } diff --git a/proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/operation.proto b/proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/operation.proto index 31f63af37..d3d3e43e4 100644 --- a/proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/operation.proto +++ b/proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/operation.proto @@ -200,6 +200,43 @@ message ExportDocumentsResponse { string output_uri_prefix = 1; } +// Metadata for the [long-running operation][google.longrunning.Operation] from +// the [RestoreDatabase][google.firestore.admin.v1.RestoreDatabase] request. +message RestoreDatabaseMetadata { + // The time the restore was started. + google.protobuf.Timestamp start_time = 1; + + // The time the restore finished, unset for ongoing restores. + google.protobuf.Timestamp end_time = 2; + + // The operation state of the restore. + OperationState operation_state = 3; + + // The name of the database being restored to. + string database = 4 [(google.api.resource_reference) = { + type: "firestore.googleapis.com/Database" + }]; + + // The name of the backup restoring from. + string backup = 5 [(google.api.resource_reference) = { + type: "firestore.googleapis.com/Backup" + }]; + + // How far along the restore is as an estimated percentage of remaining time. + Progress progress_percentage = 8; +} + +// Describes the progress of the operation. +// Unit of work is generic and must be interpreted based on where +// [Progress][google.firestore.admin.v1.Progress] is used. +message Progress { + // The amount of work estimated. + int64 estimated_work = 1; + + // The amount of work completed. + int64 completed_work = 2; +} + // Describes the state of the operation. enum OperationState { // Unspecified. @@ -228,14 +265,3 @@ enum OperationState { // google.longrunning.Operations.CancelOperation. CANCELLED = 7; } - -// Describes the progress of the operation. -// Unit of work is generic and must be interpreted based on where -// [Progress][google.firestore.admin.v1.Progress] is used. -message Progress { - // The amount of work estimated. - int64 estimated_work = 1; - - // The amount of work completed. - int64 completed_work = 2; -} diff --git a/proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/schedule.proto b/proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/schedule.proto new file mode 100644 index 000000000..7a45238f0 --- /dev/null +++ b/proto-google-cloud-firestore-admin-v1/src/main/proto/google/firestore/admin/v1/schedule.proto @@ -0,0 +1,93 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.firestore.admin.v1; + +import "google/api/field_behavior.proto"; +import "google/api/resource.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; +import "google/type/dayofweek.proto"; + +option csharp_namespace = "Google.Cloud.Firestore.Admin.V1"; +option go_package = "cloud.google.com/go/firestore/apiv1/admin/adminpb;adminpb"; +option java_multiple_files = true; +option java_outer_classname = "ScheduleProto"; +option java_package = "com.google.firestore.admin.v1"; +option objc_class_prefix = "GCFS"; +option php_namespace = "Google\\Cloud\\Firestore\\Admin\\V1"; +option ruby_package = "Google::Cloud::Firestore::Admin::V1"; + +// A backup schedule for a Cloud Firestore Database. +// +// This resource is owned by the database it is backing up, and is deleted along +// with the database. The actual backups are not though. +message BackupSchedule { + option (google.api.resource) = { + type: "firestore.googleapis.com/BackupSchedule" + pattern: "projects/{project}/databases/{database}/backupSchedules/{backup_schedule}" + }; + + // Output only. The unique backup schedule identifier across all locations and + // databases for the given project. + // + // This will be auto-assigned. + // + // Format is + // `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}` + string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. The timestamp at which this backup schedule was created and + // effective since. + // + // No backups will be created for this schedule before this time. + google.protobuf.Timestamp create_time = 3 + [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. The timestamp at which this backup schedule was most recently + // updated. When a backup schedule is first created, this is the same as + // create_time. + google.protobuf.Timestamp update_time = 10 + [(google.api.field_behavior) = OUTPUT_ONLY]; + + // At what relative time in the future, compared to its creation time, + // the backup should be deleted, e.g. keep backups for 7 days. + google.protobuf.Duration retention = 6; + + // A oneof field to represent when backups will be taken. + oneof recurrence { + // For a schedule that runs daily. + DailyRecurrence daily_recurrence = 7; + + // For a schedule that runs weekly on a specific day. + WeeklyRecurrence weekly_recurrence = 8; + } +} + +// Represents a recurring schedule that runs at a specific time every day. +// +// The time zone is UTC. +message DailyRecurrence {} + +// Represents a recurring schedule that runs on a specified day of the week. +// +// The time zone is UTC. +message WeeklyRecurrence { + // The day of week to run. + // + // DAY_OF_WEEK_UNSPECIFIED is not allowed. + google.type.DayOfWeek day = 2; +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/DocumentProto.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/DocumentProto.java index d797d200b..5261404ec 100644 --- a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/DocumentProto.java +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/DocumentProto.java @@ -52,6 +52,26 @@ public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry r internal_static_google_firestore_v1_MapValue_FieldsEntry_descriptor; static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_google_firestore_v1_MapValue_FieldsEntry_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_v1_Function_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_v1_Function_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_v1_Function_OptionsEntry_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_v1_Function_OptionsEntry_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_v1_Pipeline_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_v1_Pipeline_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_v1_Pipeline_Stage_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_v1_Pipeline_Stage_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_v1_Pipeline_Stage_OptionsEntry_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_v1_Pipeline_Stage_OptionsEntry_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { return descriptor; @@ -71,7 +91,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + "p\022/\n\013update_time\030\004 \001(\0132\032.google.protobuf" + ".Timestamp\032I\n\013FieldsEntry\022\013\n\003key\030\001 \001(\t\022)" + "\n\005value\030\002 \001(\0132\032.google.firestore.v1.Valu" - + "e:\0028\001\"\256\003\n\005Value\0220\n\nnull_value\030\013 \001(\0162\032.go" + + "e:\0028\001\"\301\004\n\005Value\0220\n\nnull_value\030\013 \001(\0162\032.go" + "ogle.protobuf.NullValueH\000\022\027\n\rboolean_val" + "ue\030\001 \001(\010H\000\022\027\n\rinteger_value\030\002 \001(\003H\000\022\026\n\014d" + "ouble_value\030\003 \001(\001H\000\0225\n\017timestamp_value\030\n" @@ -81,18 +101,33 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + "t_value\030\010 \001(\0132\023.google.type.LatLngH\000\0226\n\013" + "array_value\030\t \001(\0132\037.google.firestore.v1." + "ArrayValueH\000\0222\n\tmap_value\030\006 \001(\0132\035.google" - + ".firestore.v1.MapValueH\000B\014\n\nvalue_type\"8" - + "\n\nArrayValue\022*\n\006values\030\001 \003(\0132\032.google.fi" - + "restore.v1.Value\"\220\001\n\010MapValue\0229\n\006fields\030" - + "\001 \003(\0132).google.firestore.v1.MapValue.Fie" - + "ldsEntry\032I\n\013FieldsEntry\022\013\n\003key\030\001 \001(\t\022)\n\005" - + "value\030\002 \001(\0132\032.google.firestore.v1.Value:" - + "\0028\001B\305\001\n\027com.google.firestore.v1B\rDocumen" - + "tProtoP\001Z;cloud.google.com/go/firestore/" - + "apiv1/firestorepb;firestorepb\242\002\004GCFS\252\002\031G" - + "oogle.Cloud.Firestore.V1\312\002\031Google\\Cloud\\" - + "Firestore\\V1\352\002\034Google::Cloud::Firestore:" - + ":V1b\006proto3" + + ".firestore.v1.MapValueH\000\022\037\n\025field_refere" + + "nce_value\030\023 \001(\tH\000\0227\n\016function_value\030\024 \001(" + + "\0132\035.google.firestore.v1.FunctionH\000\0227\n\016pi" + + "peline_value\030\025 \001(\0132\035.google.firestore.v1" + + ".PipelineH\000B\014\n\nvalue_type\"8\n\nArrayValue\022" + + "*\n\006values\030\001 \003(\0132\032.google.firestore.v1.Va" + + "lue\"\220\001\n\010MapValue\0229\n\006fields\030\001 \003(\0132).googl" + + "e.firestore.v1.MapValue.FieldsEntry\032I\n\013F" + + "ieldsEntry\022\013\n\003key\030\001 \001(\t\022)\n\005value\030\002 \001(\0132\032" + + ".google.firestore.v1.Value:\0028\001\"\313\001\n\010Funct" + + "ion\022\014\n\004name\030\001 \001(\t\022(\n\004args\030\002 \003(\0132\032.google" + + ".firestore.v1.Value\022;\n\007options\030\003 \003(\0132*.g" + + "oogle.firestore.v1.Function.OptionsEntry" + + "\032J\n\014OptionsEntry\022\013\n\003key\030\001 \001(\t\022)\n\005value\030\002" + + " \001(\0132\032.google.firestore.v1.Value:\0028\001\"\220\002\n" + + "\010Pipeline\0223\n\006stages\030\001 \003(\0132#.google.fires" + + "tore.v1.Pipeline.Stage\032\316\001\n\005Stage\022\014\n\004name" + + "\030\001 \001(\t\022(\n\004args\030\002 \003(\0132\032.google.firestore." + + "v1.Value\022A\n\007options\030\003 \003(\01320.google.fires" + + "tore.v1.Pipeline.Stage.OptionsEntry\032J\n\014O" + + "ptionsEntry\022\013\n\003key\030\001 \001(\t\022)\n\005value\030\002 \001(\0132" + + "\032.google.firestore.v1.Value:\0028\001B\305\001\n\027com." + + "google.firestore.v1B\rDocumentProtoP\001Z;cl" + + "oud.google.com/go/firestore/apiv1/firest" + + "orepb;firestorepb\242\002\004GCFS\252\002\031Google.Cloud." + + "Firestore.V1\312\002\031Google\\Cloud\\Firestore\\V1" + + "\352\002\034Google::Cloud::Firestore::V1b\006proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( @@ -134,6 +169,9 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { "GeoPointValue", "ArrayValue", "MapValue", + "FieldReferenceValue", + "FunctionValue", + "PipelineValue", "ValueType", }); internal_static_google_firestore_v1_ArrayValue_descriptor = @@ -160,6 +198,46 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new java.lang.String[] { "Key", "Value", }); + internal_static_google_firestore_v1_Function_descriptor = + getDescriptor().getMessageTypes().get(4); + internal_static_google_firestore_v1_Function_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_v1_Function_descriptor, + new java.lang.String[] { + "Name", "Args", "Options", + }); + internal_static_google_firestore_v1_Function_OptionsEntry_descriptor = + internal_static_google_firestore_v1_Function_descriptor.getNestedTypes().get(0); + internal_static_google_firestore_v1_Function_OptionsEntry_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_v1_Function_OptionsEntry_descriptor, + new java.lang.String[] { + "Key", "Value", + }); + internal_static_google_firestore_v1_Pipeline_descriptor = + getDescriptor().getMessageTypes().get(5); + internal_static_google_firestore_v1_Pipeline_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_v1_Pipeline_descriptor, + new java.lang.String[] { + "Stages", + }); + internal_static_google_firestore_v1_Pipeline_Stage_descriptor = + internal_static_google_firestore_v1_Pipeline_descriptor.getNestedTypes().get(0); + internal_static_google_firestore_v1_Pipeline_Stage_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_v1_Pipeline_Stage_descriptor, + new java.lang.String[] { + "Name", "Args", "Options", + }); + internal_static_google_firestore_v1_Pipeline_Stage_OptionsEntry_descriptor = + internal_static_google_firestore_v1_Pipeline_Stage_descriptor.getNestedTypes().get(0); + internal_static_google_firestore_v1_Pipeline_Stage_OptionsEntry_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_v1_Pipeline_Stage_OptionsEntry_descriptor, + new java.lang.String[] { + "Key", "Value", + }); com.google.protobuf.StructProto.getDescriptor(); com.google.protobuf.TimestampProto.getDescriptor(); com.google.type.LatLngProto.getDescriptor(); diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutePipelineRequest.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutePipelineRequest.java new file mode 100644 index 000000000..544c520ff --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutePipelineRequest.java @@ -0,0 +1,1898 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/firestore.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +/** + * + * + *
+ * The request for [Firestore.ExecutePipeline][].
+ * 
+ * + * Protobuf type {@code google.firestore.v1.ExecutePipelineRequest} + */ +public final class ExecutePipelineRequest extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.v1.ExecutePipelineRequest) + ExecutePipelineRequestOrBuilder { + private static final long serialVersionUID = 0L; + // Use ExecutePipelineRequest.newBuilder() to construct. + private ExecutePipelineRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private ExecutePipelineRequest() { + database_ = ""; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new ExecutePipelineRequest(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.FirestoreProto + .internal_static_google_firestore_v1_ExecutePipelineRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.FirestoreProto + .internal_static_google_firestore_v1_ExecutePipelineRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.ExecutePipelineRequest.class, + com.google.firestore.v1.ExecutePipelineRequest.Builder.class); + } + + private int pipelineTypeCase_ = 0; + + @SuppressWarnings("serial") + private java.lang.Object pipelineType_; + + public enum PipelineTypeCase + implements + com.google.protobuf.Internal.EnumLite, + com.google.protobuf.AbstractMessage.InternalOneOfEnum { + STRUCTURED_PIPELINE(2), + PIPELINETYPE_NOT_SET(0); + private final int value; + + private PipelineTypeCase(int value) { + this.value = value; + } + /** + * @param value The number of the enum to look for. + * @return The enum associated with the given number. + * @deprecated Use {@link #forNumber(int)} instead. + */ + @java.lang.Deprecated + public static PipelineTypeCase valueOf(int value) { + return forNumber(value); + } + + public static PipelineTypeCase forNumber(int value) { + switch (value) { + case 2: + return STRUCTURED_PIPELINE; + case 0: + return PIPELINETYPE_NOT_SET; + default: + return null; + } + } + + public int getNumber() { + return this.value; + } + }; + + public PipelineTypeCase getPipelineTypeCase() { + return PipelineTypeCase.forNumber(pipelineTypeCase_); + } + + private int consistencySelectorCase_ = 0; + + @SuppressWarnings("serial") + private java.lang.Object consistencySelector_; + + public enum ConsistencySelectorCase + implements + com.google.protobuf.Internal.EnumLite, + com.google.protobuf.AbstractMessage.InternalOneOfEnum { + TRANSACTION(5), + NEW_TRANSACTION(6), + READ_TIME(7), + CONSISTENCYSELECTOR_NOT_SET(0); + private final int value; + + private ConsistencySelectorCase(int value) { + this.value = value; + } + /** + * @param value The number of the enum to look for. + * @return The enum associated with the given number. + * @deprecated Use {@link #forNumber(int)} instead. + */ + @java.lang.Deprecated + public static ConsistencySelectorCase valueOf(int value) { + return forNumber(value); + } + + public static ConsistencySelectorCase forNumber(int value) { + switch (value) { + case 5: + return TRANSACTION; + case 6: + return NEW_TRANSACTION; + case 7: + return READ_TIME; + case 0: + return CONSISTENCYSELECTOR_NOT_SET; + default: + return null; + } + } + + public int getNumber() { + return this.value; + } + }; + + public ConsistencySelectorCase getConsistencySelectorCase() { + return ConsistencySelectorCase.forNumber(consistencySelectorCase_); + } + + public static final int DATABASE_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile java.lang.Object database_ = ""; + /** + * + * + *
+   * Database identifier, in the form `projects/{project}/databases/{database}`.
+   * 
+ * + * string database = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * @return The database. + */ + @java.lang.Override + public java.lang.String getDatabase() { + java.lang.Object ref = database_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + database_ = s; + return s; + } + } + /** + * + * + *
+   * Database identifier, in the form `projects/{project}/databases/{database}`.
+   * 
+ * + * string database = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * @return The bytes for database. + */ + @java.lang.Override + public com.google.protobuf.ByteString getDatabaseBytes() { + java.lang.Object ref = database_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + database_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int STRUCTURED_PIPELINE_FIELD_NUMBER = 2; + /** + * + * + *
+   * A pipelined operation.
+   * 
+ * + * .google.firestore.v1.StructuredPipeline structured_pipeline = 2; + * + * @return Whether the structuredPipeline field is set. + */ + @java.lang.Override + public boolean hasStructuredPipeline() { + return pipelineTypeCase_ == 2; + } + /** + * + * + *
+   * A pipelined operation.
+   * 
+ * + * .google.firestore.v1.StructuredPipeline structured_pipeline = 2; + * + * @return The structuredPipeline. + */ + @java.lang.Override + public com.google.firestore.v1.StructuredPipeline getStructuredPipeline() { + if (pipelineTypeCase_ == 2) { + return (com.google.firestore.v1.StructuredPipeline) pipelineType_; + } + return com.google.firestore.v1.StructuredPipeline.getDefaultInstance(); + } + /** + * + * + *
+   * A pipelined operation.
+   * 
+ * + * .google.firestore.v1.StructuredPipeline structured_pipeline = 2; + */ + @java.lang.Override + public com.google.firestore.v1.StructuredPipelineOrBuilder getStructuredPipelineOrBuilder() { + if (pipelineTypeCase_ == 2) { + return (com.google.firestore.v1.StructuredPipeline) pipelineType_; + } + return com.google.firestore.v1.StructuredPipeline.getDefaultInstance(); + } + + public static final int TRANSACTION_FIELD_NUMBER = 5; + /** + * + * + *
+   * Run the query within an already active transaction.
+   *
+   * The value here is the opaque transaction ID to execute the query in.
+   * 
+ * + * bytes transaction = 5; + * + * @return Whether the transaction field is set. + */ + @java.lang.Override + public boolean hasTransaction() { + return consistencySelectorCase_ == 5; + } + /** + * + * + *
+   * Run the query within an already active transaction.
+   *
+   * The value here is the opaque transaction ID to execute the query in.
+   * 
+ * + * bytes transaction = 5; + * + * @return The transaction. + */ + @java.lang.Override + public com.google.protobuf.ByteString getTransaction() { + if (consistencySelectorCase_ == 5) { + return (com.google.protobuf.ByteString) consistencySelector_; + } + return com.google.protobuf.ByteString.EMPTY; + } + + public static final int NEW_TRANSACTION_FIELD_NUMBER = 6; + /** + * + * + *
+   * Execute the pipeline in a new transaction.
+   *
+   * The identifier of the newly created transaction will be returned in the
+   * first response on the stream. This defaults to a read-only transaction.
+   * 
+ * + * .google.firestore.v1.TransactionOptions new_transaction = 6; + * + * @return Whether the newTransaction field is set. + */ + @java.lang.Override + public boolean hasNewTransaction() { + return consistencySelectorCase_ == 6; + } + /** + * + * + *
+   * Execute the pipeline in a new transaction.
+   *
+   * The identifier of the newly created transaction will be returned in the
+   * first response on the stream. This defaults to a read-only transaction.
+   * 
+ * + * .google.firestore.v1.TransactionOptions new_transaction = 6; + * + * @return The newTransaction. + */ + @java.lang.Override + public com.google.firestore.v1.TransactionOptions getNewTransaction() { + if (consistencySelectorCase_ == 6) { + return (com.google.firestore.v1.TransactionOptions) consistencySelector_; + } + return com.google.firestore.v1.TransactionOptions.getDefaultInstance(); + } + /** + * + * + *
+   * Execute the pipeline in a new transaction.
+   *
+   * The identifier of the newly created transaction will be returned in the
+   * first response on the stream. This defaults to a read-only transaction.
+   * 
+ * + * .google.firestore.v1.TransactionOptions new_transaction = 6; + */ + @java.lang.Override + public com.google.firestore.v1.TransactionOptionsOrBuilder getNewTransactionOrBuilder() { + if (consistencySelectorCase_ == 6) { + return (com.google.firestore.v1.TransactionOptions) consistencySelector_; + } + return com.google.firestore.v1.TransactionOptions.getDefaultInstance(); + } + + public static final int READ_TIME_FIELD_NUMBER = 7; + /** + * + * + *
+   * Execute the pipeline in a snapshot transaction at the given time.
+   *
+   * This must be a microsecond precision timestamp within the past one hour,
+   * or if Point-in-Time Recovery is enabled, can additionally be a whole
+   * minute timestamp within the past 7 days.
+   * 
+ * + * .google.protobuf.Timestamp read_time = 7; + * + * @return Whether the readTime field is set. + */ + @java.lang.Override + public boolean hasReadTime() { + return consistencySelectorCase_ == 7; + } + /** + * + * + *
+   * Execute the pipeline in a snapshot transaction at the given time.
+   *
+   * This must be a microsecond precision timestamp within the past one hour,
+   * or if Point-in-Time Recovery is enabled, can additionally be a whole
+   * minute timestamp within the past 7 days.
+   * 
+ * + * .google.protobuf.Timestamp read_time = 7; + * + * @return The readTime. + */ + @java.lang.Override + public com.google.protobuf.Timestamp getReadTime() { + if (consistencySelectorCase_ == 7) { + return (com.google.protobuf.Timestamp) consistencySelector_; + } + return com.google.protobuf.Timestamp.getDefaultInstance(); + } + /** + * + * + *
+   * Execute the pipeline in a snapshot transaction at the given time.
+   *
+   * This must be a microsecond precision timestamp within the past one hour,
+   * or if Point-in-Time Recovery is enabled, can additionally be a whole
+   * minute timestamp within the past 7 days.
+   * 
+ * + * .google.protobuf.Timestamp read_time = 7; + */ + @java.lang.Override + public com.google.protobuf.TimestampOrBuilder getReadTimeOrBuilder() { + if (consistencySelectorCase_ == 7) { + return (com.google.protobuf.Timestamp) consistencySelector_; + } + return com.google.protobuf.Timestamp.getDefaultInstance(); + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(database_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, database_); + } + if (pipelineTypeCase_ == 2) { + output.writeMessage(2, (com.google.firestore.v1.StructuredPipeline) pipelineType_); + } + if (consistencySelectorCase_ == 5) { + output.writeBytes(5, (com.google.protobuf.ByteString) consistencySelector_); + } + if (consistencySelectorCase_ == 6) { + output.writeMessage(6, (com.google.firestore.v1.TransactionOptions) consistencySelector_); + } + if (consistencySelectorCase_ == 7) { + output.writeMessage(7, (com.google.protobuf.Timestamp) consistencySelector_); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(database_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, database_); + } + if (pipelineTypeCase_ == 2) { + size += + com.google.protobuf.CodedOutputStream.computeMessageSize( + 2, (com.google.firestore.v1.StructuredPipeline) pipelineType_); + } + if (consistencySelectorCase_ == 5) { + size += + com.google.protobuf.CodedOutputStream.computeBytesSize( + 5, (com.google.protobuf.ByteString) consistencySelector_); + } + if (consistencySelectorCase_ == 6) { + size += + com.google.protobuf.CodedOutputStream.computeMessageSize( + 6, (com.google.firestore.v1.TransactionOptions) consistencySelector_); + } + if (consistencySelectorCase_ == 7) { + size += + com.google.protobuf.CodedOutputStream.computeMessageSize( + 7, (com.google.protobuf.Timestamp) consistencySelector_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.v1.ExecutePipelineRequest)) { + return super.equals(obj); + } + com.google.firestore.v1.ExecutePipelineRequest other = + (com.google.firestore.v1.ExecutePipelineRequest) obj; + + if (!getDatabase().equals(other.getDatabase())) return false; + if (!getPipelineTypeCase().equals(other.getPipelineTypeCase())) return false; + switch (pipelineTypeCase_) { + case 2: + if (!getStructuredPipeline().equals(other.getStructuredPipeline())) return false; + break; + case 0: + default: + } + if (!getConsistencySelectorCase().equals(other.getConsistencySelectorCase())) return false; + switch (consistencySelectorCase_) { + case 5: + if (!getTransaction().equals(other.getTransaction())) return false; + break; + case 6: + if (!getNewTransaction().equals(other.getNewTransaction())) return false; + break; + case 7: + if (!getReadTime().equals(other.getReadTime())) return false; + break; + case 0: + default: + } + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + DATABASE_FIELD_NUMBER; + hash = (53 * hash) + getDatabase().hashCode(); + switch (pipelineTypeCase_) { + case 2: + hash = (37 * hash) + STRUCTURED_PIPELINE_FIELD_NUMBER; + hash = (53 * hash) + getStructuredPipeline().hashCode(); + break; + case 0: + default: + } + switch (consistencySelectorCase_) { + case 5: + hash = (37 * hash) + TRANSACTION_FIELD_NUMBER; + hash = (53 * hash) + getTransaction().hashCode(); + break; + case 6: + hash = (37 * hash) + NEW_TRANSACTION_FIELD_NUMBER; + hash = (53 * hash) + getNewTransaction().hashCode(); + break; + case 7: + hash = (37 * hash) + READ_TIME_FIELD_NUMBER; + hash = (53 * hash) + getReadTime().hashCode(); + break; + case 0: + default: + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.v1.ExecutePipelineRequest parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.ExecutePipelineRequest parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.ExecutePipelineRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.ExecutePipelineRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.ExecutePipelineRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.ExecutePipelineRequest parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.ExecutePipelineRequest parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.ExecutePipelineRequest parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.ExecutePipelineRequest parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.ExecutePipelineRequest parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.ExecutePipelineRequest parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.ExecutePipelineRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.v1.ExecutePipelineRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * The request for [Firestore.ExecutePipeline][].
+   * 
+ * + * Protobuf type {@code google.firestore.v1.ExecutePipelineRequest} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.v1.ExecutePipelineRequest) + com.google.firestore.v1.ExecutePipelineRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.FirestoreProto + .internal_static_google_firestore_v1_ExecutePipelineRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.FirestoreProto + .internal_static_google_firestore_v1_ExecutePipelineRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.ExecutePipelineRequest.class, + com.google.firestore.v1.ExecutePipelineRequest.Builder.class); + } + + // Construct using com.google.firestore.v1.ExecutePipelineRequest.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + database_ = ""; + if (structuredPipelineBuilder_ != null) { + structuredPipelineBuilder_.clear(); + } + if (newTransactionBuilder_ != null) { + newTransactionBuilder_.clear(); + } + if (readTimeBuilder_ != null) { + readTimeBuilder_.clear(); + } + pipelineTypeCase_ = 0; + pipelineType_ = null; + consistencySelectorCase_ = 0; + consistencySelector_ = null; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.v1.FirestoreProto + .internal_static_google_firestore_v1_ExecutePipelineRequest_descriptor; + } + + @java.lang.Override + public com.google.firestore.v1.ExecutePipelineRequest getDefaultInstanceForType() { + return com.google.firestore.v1.ExecutePipelineRequest.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.v1.ExecutePipelineRequest build() { + com.google.firestore.v1.ExecutePipelineRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.v1.ExecutePipelineRequest buildPartial() { + com.google.firestore.v1.ExecutePipelineRequest result = + new com.google.firestore.v1.ExecutePipelineRequest(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + buildPartialOneofs(result); + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.v1.ExecutePipelineRequest result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.database_ = database_; + } + } + + private void buildPartialOneofs(com.google.firestore.v1.ExecutePipelineRequest result) { + result.pipelineTypeCase_ = pipelineTypeCase_; + result.pipelineType_ = this.pipelineType_; + if (pipelineTypeCase_ == 2 && structuredPipelineBuilder_ != null) { + result.pipelineType_ = structuredPipelineBuilder_.build(); + } + result.consistencySelectorCase_ = consistencySelectorCase_; + result.consistencySelector_ = this.consistencySelector_; + if (consistencySelectorCase_ == 6 && newTransactionBuilder_ != null) { + result.consistencySelector_ = newTransactionBuilder_.build(); + } + if (consistencySelectorCase_ == 7 && readTimeBuilder_ != null) { + result.consistencySelector_ = readTimeBuilder_.build(); + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.v1.ExecutePipelineRequest) { + return mergeFrom((com.google.firestore.v1.ExecutePipelineRequest) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.v1.ExecutePipelineRequest other) { + if (other == com.google.firestore.v1.ExecutePipelineRequest.getDefaultInstance()) return this; + if (!other.getDatabase().isEmpty()) { + database_ = other.database_; + bitField0_ |= 0x00000001; + onChanged(); + } + switch (other.getPipelineTypeCase()) { + case STRUCTURED_PIPELINE: + { + mergeStructuredPipeline(other.getStructuredPipeline()); + break; + } + case PIPELINETYPE_NOT_SET: + { + break; + } + } + switch (other.getConsistencySelectorCase()) { + case TRANSACTION: + { + setTransaction(other.getTransaction()); + break; + } + case NEW_TRANSACTION: + { + mergeNewTransaction(other.getNewTransaction()); + break; + } + case READ_TIME: + { + mergeReadTime(other.getReadTime()); + break; + } + case CONSISTENCYSELECTOR_NOT_SET: + { + break; + } + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + database_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: + { + input.readMessage( + getStructuredPipelineFieldBuilder().getBuilder(), extensionRegistry); + pipelineTypeCase_ = 2; + break; + } // case 18 + case 42: + { + consistencySelector_ = input.readBytes(); + consistencySelectorCase_ = 5; + break; + } // case 42 + case 50: + { + input.readMessage(getNewTransactionFieldBuilder().getBuilder(), extensionRegistry); + consistencySelectorCase_ = 6; + break; + } // case 50 + case 58: + { + input.readMessage(getReadTimeFieldBuilder().getBuilder(), extensionRegistry); + consistencySelectorCase_ = 7; + break; + } // case 58 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int pipelineTypeCase_ = 0; + private java.lang.Object pipelineType_; + + public PipelineTypeCase getPipelineTypeCase() { + return PipelineTypeCase.forNumber(pipelineTypeCase_); + } + + public Builder clearPipelineType() { + pipelineTypeCase_ = 0; + pipelineType_ = null; + onChanged(); + return this; + } + + private int consistencySelectorCase_ = 0; + private java.lang.Object consistencySelector_; + + public ConsistencySelectorCase getConsistencySelectorCase() { + return ConsistencySelectorCase.forNumber(consistencySelectorCase_); + } + + public Builder clearConsistencySelector() { + consistencySelectorCase_ = 0; + consistencySelector_ = null; + onChanged(); + return this; + } + + private int bitField0_; + + private java.lang.Object database_ = ""; + /** + * + * + *
+     * Database identifier, in the form `projects/{project}/databases/{database}`.
+     * 
+ * + * string database = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * @return The database. + */ + public java.lang.String getDatabase() { + java.lang.Object ref = database_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + database_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * Database identifier, in the form `projects/{project}/databases/{database}`.
+     * 
+ * + * string database = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * @return The bytes for database. + */ + public com.google.protobuf.ByteString getDatabaseBytes() { + java.lang.Object ref = database_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + database_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * Database identifier, in the form `projects/{project}/databases/{database}`.
+     * 
+ * + * string database = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * @param value The database to set. + * @return This builder for chaining. + */ + public Builder setDatabase(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + database_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * Database identifier, in the form `projects/{project}/databases/{database}`.
+     * 
+ * + * string database = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * @return This builder for chaining. + */ + public Builder clearDatabase() { + database_ = getDefaultInstance().getDatabase(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + /** + * + * + *
+     * Database identifier, in the form `projects/{project}/databases/{database}`.
+     * 
+ * + * string database = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * @param value The bytes for database to set. + * @return This builder for chaining. + */ + public Builder setDatabaseBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + database_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.StructuredPipeline, + com.google.firestore.v1.StructuredPipeline.Builder, + com.google.firestore.v1.StructuredPipelineOrBuilder> + structuredPipelineBuilder_; + /** + * + * + *
+     * A pipelined operation.
+     * 
+ * + * .google.firestore.v1.StructuredPipeline structured_pipeline = 2; + * + * @return Whether the structuredPipeline field is set. + */ + @java.lang.Override + public boolean hasStructuredPipeline() { + return pipelineTypeCase_ == 2; + } + /** + * + * + *
+     * A pipelined operation.
+     * 
+ * + * .google.firestore.v1.StructuredPipeline structured_pipeline = 2; + * + * @return The structuredPipeline. + */ + @java.lang.Override + public com.google.firestore.v1.StructuredPipeline getStructuredPipeline() { + if (structuredPipelineBuilder_ == null) { + if (pipelineTypeCase_ == 2) { + return (com.google.firestore.v1.StructuredPipeline) pipelineType_; + } + return com.google.firestore.v1.StructuredPipeline.getDefaultInstance(); + } else { + if (pipelineTypeCase_ == 2) { + return structuredPipelineBuilder_.getMessage(); + } + return com.google.firestore.v1.StructuredPipeline.getDefaultInstance(); + } + } + /** + * + * + *
+     * A pipelined operation.
+     * 
+ * + * .google.firestore.v1.StructuredPipeline structured_pipeline = 2; + */ + public Builder setStructuredPipeline(com.google.firestore.v1.StructuredPipeline value) { + if (structuredPipelineBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + pipelineType_ = value; + onChanged(); + } else { + structuredPipelineBuilder_.setMessage(value); + } + pipelineTypeCase_ = 2; + return this; + } + /** + * + * + *
+     * A pipelined operation.
+     * 
+ * + * .google.firestore.v1.StructuredPipeline structured_pipeline = 2; + */ + public Builder setStructuredPipeline( + com.google.firestore.v1.StructuredPipeline.Builder builderForValue) { + if (structuredPipelineBuilder_ == null) { + pipelineType_ = builderForValue.build(); + onChanged(); + } else { + structuredPipelineBuilder_.setMessage(builderForValue.build()); + } + pipelineTypeCase_ = 2; + return this; + } + /** + * + * + *
+     * A pipelined operation.
+     * 
+ * + * .google.firestore.v1.StructuredPipeline structured_pipeline = 2; + */ + public Builder mergeStructuredPipeline(com.google.firestore.v1.StructuredPipeline value) { + if (structuredPipelineBuilder_ == null) { + if (pipelineTypeCase_ == 2 + && pipelineType_ != com.google.firestore.v1.StructuredPipeline.getDefaultInstance()) { + pipelineType_ = + com.google.firestore.v1.StructuredPipeline.newBuilder( + (com.google.firestore.v1.StructuredPipeline) pipelineType_) + .mergeFrom(value) + .buildPartial(); + } else { + pipelineType_ = value; + } + onChanged(); + } else { + if (pipelineTypeCase_ == 2) { + structuredPipelineBuilder_.mergeFrom(value); + } else { + structuredPipelineBuilder_.setMessage(value); + } + } + pipelineTypeCase_ = 2; + return this; + } + /** + * + * + *
+     * A pipelined operation.
+     * 
+ * + * .google.firestore.v1.StructuredPipeline structured_pipeline = 2; + */ + public Builder clearStructuredPipeline() { + if (structuredPipelineBuilder_ == null) { + if (pipelineTypeCase_ == 2) { + pipelineTypeCase_ = 0; + pipelineType_ = null; + onChanged(); + } + } else { + if (pipelineTypeCase_ == 2) { + pipelineTypeCase_ = 0; + pipelineType_ = null; + } + structuredPipelineBuilder_.clear(); + } + return this; + } + /** + * + * + *
+     * A pipelined operation.
+     * 
+ * + * .google.firestore.v1.StructuredPipeline structured_pipeline = 2; + */ + public com.google.firestore.v1.StructuredPipeline.Builder getStructuredPipelineBuilder() { + return getStructuredPipelineFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * A pipelined operation.
+     * 
+ * + * .google.firestore.v1.StructuredPipeline structured_pipeline = 2; + */ + @java.lang.Override + public com.google.firestore.v1.StructuredPipelineOrBuilder getStructuredPipelineOrBuilder() { + if ((pipelineTypeCase_ == 2) && (structuredPipelineBuilder_ != null)) { + return structuredPipelineBuilder_.getMessageOrBuilder(); + } else { + if (pipelineTypeCase_ == 2) { + return (com.google.firestore.v1.StructuredPipeline) pipelineType_; + } + return com.google.firestore.v1.StructuredPipeline.getDefaultInstance(); + } + } + /** + * + * + *
+     * A pipelined operation.
+     * 
+ * + * .google.firestore.v1.StructuredPipeline structured_pipeline = 2; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.StructuredPipeline, + com.google.firestore.v1.StructuredPipeline.Builder, + com.google.firestore.v1.StructuredPipelineOrBuilder> + getStructuredPipelineFieldBuilder() { + if (structuredPipelineBuilder_ == null) { + if (!(pipelineTypeCase_ == 2)) { + pipelineType_ = com.google.firestore.v1.StructuredPipeline.getDefaultInstance(); + } + structuredPipelineBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.StructuredPipeline, + com.google.firestore.v1.StructuredPipeline.Builder, + com.google.firestore.v1.StructuredPipelineOrBuilder>( + (com.google.firestore.v1.StructuredPipeline) pipelineType_, + getParentForChildren(), + isClean()); + pipelineType_ = null; + } + pipelineTypeCase_ = 2; + onChanged(); + return structuredPipelineBuilder_; + } + + /** + * + * + *
+     * Run the query within an already active transaction.
+     *
+     * The value here is the opaque transaction ID to execute the query in.
+     * 
+ * + * bytes transaction = 5; + * + * @return Whether the transaction field is set. + */ + public boolean hasTransaction() { + return consistencySelectorCase_ == 5; + } + /** + * + * + *
+     * Run the query within an already active transaction.
+     *
+     * The value here is the opaque transaction ID to execute the query in.
+     * 
+ * + * bytes transaction = 5; + * + * @return The transaction. + */ + public com.google.protobuf.ByteString getTransaction() { + if (consistencySelectorCase_ == 5) { + return (com.google.protobuf.ByteString) consistencySelector_; + } + return com.google.protobuf.ByteString.EMPTY; + } + /** + * + * + *
+     * Run the query within an already active transaction.
+     *
+     * The value here is the opaque transaction ID to execute the query in.
+     * 
+ * + * bytes transaction = 5; + * + * @param value The transaction to set. + * @return This builder for chaining. + */ + public Builder setTransaction(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + consistencySelectorCase_ = 5; + consistencySelector_ = value; + onChanged(); + return this; + } + /** + * + * + *
+     * Run the query within an already active transaction.
+     *
+     * The value here is the opaque transaction ID to execute the query in.
+     * 
+ * + * bytes transaction = 5; + * + * @return This builder for chaining. + */ + public Builder clearTransaction() { + if (consistencySelectorCase_ == 5) { + consistencySelectorCase_ = 0; + consistencySelector_ = null; + onChanged(); + } + return this; + } + + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.TransactionOptions, + com.google.firestore.v1.TransactionOptions.Builder, + com.google.firestore.v1.TransactionOptionsOrBuilder> + newTransactionBuilder_; + /** + * + * + *
+     * Execute the pipeline in a new transaction.
+     *
+     * The identifier of the newly created transaction will be returned in the
+     * first response on the stream. This defaults to a read-only transaction.
+     * 
+ * + * .google.firestore.v1.TransactionOptions new_transaction = 6; + * + * @return Whether the newTransaction field is set. + */ + @java.lang.Override + public boolean hasNewTransaction() { + return consistencySelectorCase_ == 6; + } + /** + * + * + *
+     * Execute the pipeline in a new transaction.
+     *
+     * The identifier of the newly created transaction will be returned in the
+     * first response on the stream. This defaults to a read-only transaction.
+     * 
+ * + * .google.firestore.v1.TransactionOptions new_transaction = 6; + * + * @return The newTransaction. + */ + @java.lang.Override + public com.google.firestore.v1.TransactionOptions getNewTransaction() { + if (newTransactionBuilder_ == null) { + if (consistencySelectorCase_ == 6) { + return (com.google.firestore.v1.TransactionOptions) consistencySelector_; + } + return com.google.firestore.v1.TransactionOptions.getDefaultInstance(); + } else { + if (consistencySelectorCase_ == 6) { + return newTransactionBuilder_.getMessage(); + } + return com.google.firestore.v1.TransactionOptions.getDefaultInstance(); + } + } + /** + * + * + *
+     * Execute the pipeline in a new transaction.
+     *
+     * The identifier of the newly created transaction will be returned in the
+     * first response on the stream. This defaults to a read-only transaction.
+     * 
+ * + * .google.firestore.v1.TransactionOptions new_transaction = 6; + */ + public Builder setNewTransaction(com.google.firestore.v1.TransactionOptions value) { + if (newTransactionBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + consistencySelector_ = value; + onChanged(); + } else { + newTransactionBuilder_.setMessage(value); + } + consistencySelectorCase_ = 6; + return this; + } + /** + * + * + *
+     * Execute the pipeline in a new transaction.
+     *
+     * The identifier of the newly created transaction will be returned in the
+     * first response on the stream. This defaults to a read-only transaction.
+     * 
+ * + * .google.firestore.v1.TransactionOptions new_transaction = 6; + */ + public Builder setNewTransaction( + com.google.firestore.v1.TransactionOptions.Builder builderForValue) { + if (newTransactionBuilder_ == null) { + consistencySelector_ = builderForValue.build(); + onChanged(); + } else { + newTransactionBuilder_.setMessage(builderForValue.build()); + } + consistencySelectorCase_ = 6; + return this; + } + /** + * + * + *
+     * Execute the pipeline in a new transaction.
+     *
+     * The identifier of the newly created transaction will be returned in the
+     * first response on the stream. This defaults to a read-only transaction.
+     * 
+ * + * .google.firestore.v1.TransactionOptions new_transaction = 6; + */ + public Builder mergeNewTransaction(com.google.firestore.v1.TransactionOptions value) { + if (newTransactionBuilder_ == null) { + if (consistencySelectorCase_ == 6 + && consistencySelector_ + != com.google.firestore.v1.TransactionOptions.getDefaultInstance()) { + consistencySelector_ = + com.google.firestore.v1.TransactionOptions.newBuilder( + (com.google.firestore.v1.TransactionOptions) consistencySelector_) + .mergeFrom(value) + .buildPartial(); + } else { + consistencySelector_ = value; + } + onChanged(); + } else { + if (consistencySelectorCase_ == 6) { + newTransactionBuilder_.mergeFrom(value); + } else { + newTransactionBuilder_.setMessage(value); + } + } + consistencySelectorCase_ = 6; + return this; + } + /** + * + * + *
+     * Execute the pipeline in a new transaction.
+     *
+     * The identifier of the newly created transaction will be returned in the
+     * first response on the stream. This defaults to a read-only transaction.
+     * 
+ * + * .google.firestore.v1.TransactionOptions new_transaction = 6; + */ + public Builder clearNewTransaction() { + if (newTransactionBuilder_ == null) { + if (consistencySelectorCase_ == 6) { + consistencySelectorCase_ = 0; + consistencySelector_ = null; + onChanged(); + } + } else { + if (consistencySelectorCase_ == 6) { + consistencySelectorCase_ = 0; + consistencySelector_ = null; + } + newTransactionBuilder_.clear(); + } + return this; + } + /** + * + * + *
+     * Execute the pipeline in a new transaction.
+     *
+     * The identifier of the newly created transaction will be returned in the
+     * first response on the stream. This defaults to a read-only transaction.
+     * 
+ * + * .google.firestore.v1.TransactionOptions new_transaction = 6; + */ + public com.google.firestore.v1.TransactionOptions.Builder getNewTransactionBuilder() { + return getNewTransactionFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * Execute the pipeline in a new transaction.
+     *
+     * The identifier of the newly created transaction will be returned in the
+     * first response on the stream. This defaults to a read-only transaction.
+     * 
+ * + * .google.firestore.v1.TransactionOptions new_transaction = 6; + */ + @java.lang.Override + public com.google.firestore.v1.TransactionOptionsOrBuilder getNewTransactionOrBuilder() { + if ((consistencySelectorCase_ == 6) && (newTransactionBuilder_ != null)) { + return newTransactionBuilder_.getMessageOrBuilder(); + } else { + if (consistencySelectorCase_ == 6) { + return (com.google.firestore.v1.TransactionOptions) consistencySelector_; + } + return com.google.firestore.v1.TransactionOptions.getDefaultInstance(); + } + } + /** + * + * + *
+     * Execute the pipeline in a new transaction.
+     *
+     * The identifier of the newly created transaction will be returned in the
+     * first response on the stream. This defaults to a read-only transaction.
+     * 
+ * + * .google.firestore.v1.TransactionOptions new_transaction = 6; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.TransactionOptions, + com.google.firestore.v1.TransactionOptions.Builder, + com.google.firestore.v1.TransactionOptionsOrBuilder> + getNewTransactionFieldBuilder() { + if (newTransactionBuilder_ == null) { + if (!(consistencySelectorCase_ == 6)) { + consistencySelector_ = com.google.firestore.v1.TransactionOptions.getDefaultInstance(); + } + newTransactionBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.TransactionOptions, + com.google.firestore.v1.TransactionOptions.Builder, + com.google.firestore.v1.TransactionOptionsOrBuilder>( + (com.google.firestore.v1.TransactionOptions) consistencySelector_, + getParentForChildren(), + isClean()); + consistencySelector_ = null; + } + consistencySelectorCase_ = 6; + onChanged(); + return newTransactionBuilder_; + } + + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder> + readTimeBuilder_; + /** + * + * + *
+     * Execute the pipeline in a snapshot transaction at the given time.
+     *
+     * This must be a microsecond precision timestamp within the past one hour,
+     * or if Point-in-Time Recovery is enabled, can additionally be a whole
+     * minute timestamp within the past 7 days.
+     * 
+ * + * .google.protobuf.Timestamp read_time = 7; + * + * @return Whether the readTime field is set. + */ + @java.lang.Override + public boolean hasReadTime() { + return consistencySelectorCase_ == 7; + } + /** + * + * + *
+     * Execute the pipeline in a snapshot transaction at the given time.
+     *
+     * This must be a microsecond precision timestamp within the past one hour,
+     * or if Point-in-Time Recovery is enabled, can additionally be a whole
+     * minute timestamp within the past 7 days.
+     * 
+ * + * .google.protobuf.Timestamp read_time = 7; + * + * @return The readTime. + */ + @java.lang.Override + public com.google.protobuf.Timestamp getReadTime() { + if (readTimeBuilder_ == null) { + if (consistencySelectorCase_ == 7) { + return (com.google.protobuf.Timestamp) consistencySelector_; + } + return com.google.protobuf.Timestamp.getDefaultInstance(); + } else { + if (consistencySelectorCase_ == 7) { + return readTimeBuilder_.getMessage(); + } + return com.google.protobuf.Timestamp.getDefaultInstance(); + } + } + /** + * + * + *
+     * Execute the pipeline in a snapshot transaction at the given time.
+     *
+     * This must be a microsecond precision timestamp within the past one hour,
+     * or if Point-in-Time Recovery is enabled, can additionally be a whole
+     * minute timestamp within the past 7 days.
+     * 
+ * + * .google.protobuf.Timestamp read_time = 7; + */ + public Builder setReadTime(com.google.protobuf.Timestamp value) { + if (readTimeBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + consistencySelector_ = value; + onChanged(); + } else { + readTimeBuilder_.setMessage(value); + } + consistencySelectorCase_ = 7; + return this; + } + /** + * + * + *
+     * Execute the pipeline in a snapshot transaction at the given time.
+     *
+     * This must be a microsecond precision timestamp within the past one hour,
+     * or if Point-in-Time Recovery is enabled, can additionally be a whole
+     * minute timestamp within the past 7 days.
+     * 
+ * + * .google.protobuf.Timestamp read_time = 7; + */ + public Builder setReadTime(com.google.protobuf.Timestamp.Builder builderForValue) { + if (readTimeBuilder_ == null) { + consistencySelector_ = builderForValue.build(); + onChanged(); + } else { + readTimeBuilder_.setMessage(builderForValue.build()); + } + consistencySelectorCase_ = 7; + return this; + } + /** + * + * + *
+     * Execute the pipeline in a snapshot transaction at the given time.
+     *
+     * This must be a microsecond precision timestamp within the past one hour,
+     * or if Point-in-Time Recovery is enabled, can additionally be a whole
+     * minute timestamp within the past 7 days.
+     * 
+ * + * .google.protobuf.Timestamp read_time = 7; + */ + public Builder mergeReadTime(com.google.protobuf.Timestamp value) { + if (readTimeBuilder_ == null) { + if (consistencySelectorCase_ == 7 + && consistencySelector_ != com.google.protobuf.Timestamp.getDefaultInstance()) { + consistencySelector_ = + com.google.protobuf.Timestamp.newBuilder( + (com.google.protobuf.Timestamp) consistencySelector_) + .mergeFrom(value) + .buildPartial(); + } else { + consistencySelector_ = value; + } + onChanged(); + } else { + if (consistencySelectorCase_ == 7) { + readTimeBuilder_.mergeFrom(value); + } else { + readTimeBuilder_.setMessage(value); + } + } + consistencySelectorCase_ = 7; + return this; + } + /** + * + * + *
+     * Execute the pipeline in a snapshot transaction at the given time.
+     *
+     * This must be a microsecond precision timestamp within the past one hour,
+     * or if Point-in-Time Recovery is enabled, can additionally be a whole
+     * minute timestamp within the past 7 days.
+     * 
+ * + * .google.protobuf.Timestamp read_time = 7; + */ + public Builder clearReadTime() { + if (readTimeBuilder_ == null) { + if (consistencySelectorCase_ == 7) { + consistencySelectorCase_ = 0; + consistencySelector_ = null; + onChanged(); + } + } else { + if (consistencySelectorCase_ == 7) { + consistencySelectorCase_ = 0; + consistencySelector_ = null; + } + readTimeBuilder_.clear(); + } + return this; + } + /** + * + * + *
+     * Execute the pipeline in a snapshot transaction at the given time.
+     *
+     * This must be a microsecond precision timestamp within the past one hour,
+     * or if Point-in-Time Recovery is enabled, can additionally be a whole
+     * minute timestamp within the past 7 days.
+     * 
+ * + * .google.protobuf.Timestamp read_time = 7; + */ + public com.google.protobuf.Timestamp.Builder getReadTimeBuilder() { + return getReadTimeFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * Execute the pipeline in a snapshot transaction at the given time.
+     *
+     * This must be a microsecond precision timestamp within the past one hour,
+     * or if Point-in-Time Recovery is enabled, can additionally be a whole
+     * minute timestamp within the past 7 days.
+     * 
+ * + * .google.protobuf.Timestamp read_time = 7; + */ + @java.lang.Override + public com.google.protobuf.TimestampOrBuilder getReadTimeOrBuilder() { + if ((consistencySelectorCase_ == 7) && (readTimeBuilder_ != null)) { + return readTimeBuilder_.getMessageOrBuilder(); + } else { + if (consistencySelectorCase_ == 7) { + return (com.google.protobuf.Timestamp) consistencySelector_; + } + return com.google.protobuf.Timestamp.getDefaultInstance(); + } + } + /** + * + * + *
+     * Execute the pipeline in a snapshot transaction at the given time.
+     *
+     * This must be a microsecond precision timestamp within the past one hour,
+     * or if Point-in-Time Recovery is enabled, can additionally be a whole
+     * minute timestamp within the past 7 days.
+     * 
+ * + * .google.protobuf.Timestamp read_time = 7; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder> + getReadTimeFieldBuilder() { + if (readTimeBuilder_ == null) { + if (!(consistencySelectorCase_ == 7)) { + consistencySelector_ = com.google.protobuf.Timestamp.getDefaultInstance(); + } + readTimeBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder>( + (com.google.protobuf.Timestamp) consistencySelector_, + getParentForChildren(), + isClean()); + consistencySelector_ = null; + } + consistencySelectorCase_ = 7; + onChanged(); + return readTimeBuilder_; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.v1.ExecutePipelineRequest) + } + + // @@protoc_insertion_point(class_scope:google.firestore.v1.ExecutePipelineRequest) + private static final com.google.firestore.v1.ExecutePipelineRequest DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.v1.ExecutePipelineRequest(); + } + + public static com.google.firestore.v1.ExecutePipelineRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public ExecutePipelineRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.v1.ExecutePipelineRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutePipelineRequestOrBuilder.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutePipelineRequestOrBuilder.java new file mode 100644 index 000000000..95a65826b --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutePipelineRequestOrBuilder.java @@ -0,0 +1,211 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/firestore.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +public interface ExecutePipelineRequestOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.v1.ExecutePipelineRequest) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * Database identifier, in the form `projects/{project}/databases/{database}`.
+   * 
+ * + * string database = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * @return The database. + */ + java.lang.String getDatabase(); + /** + * + * + *
+   * Database identifier, in the form `projects/{project}/databases/{database}`.
+   * 
+ * + * string database = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * @return The bytes for database. + */ + com.google.protobuf.ByteString getDatabaseBytes(); + + /** + * + * + *
+   * A pipelined operation.
+   * 
+ * + * .google.firestore.v1.StructuredPipeline structured_pipeline = 2; + * + * @return Whether the structuredPipeline field is set. + */ + boolean hasStructuredPipeline(); + /** + * + * + *
+   * A pipelined operation.
+   * 
+ * + * .google.firestore.v1.StructuredPipeline structured_pipeline = 2; + * + * @return The structuredPipeline. + */ + com.google.firestore.v1.StructuredPipeline getStructuredPipeline(); + /** + * + * + *
+   * A pipelined operation.
+   * 
+ * + * .google.firestore.v1.StructuredPipeline structured_pipeline = 2; + */ + com.google.firestore.v1.StructuredPipelineOrBuilder getStructuredPipelineOrBuilder(); + + /** + * + * + *
+   * Run the query within an already active transaction.
+   *
+   * The value here is the opaque transaction ID to execute the query in.
+   * 
+ * + * bytes transaction = 5; + * + * @return Whether the transaction field is set. + */ + boolean hasTransaction(); + /** + * + * + *
+   * Run the query within an already active transaction.
+   *
+   * The value here is the opaque transaction ID to execute the query in.
+   * 
+ * + * bytes transaction = 5; + * + * @return The transaction. + */ + com.google.protobuf.ByteString getTransaction(); + + /** + * + * + *
+   * Execute the pipeline in a new transaction.
+   *
+   * The identifier of the newly created transaction will be returned in the
+   * first response on the stream. This defaults to a read-only transaction.
+   * 
+ * + * .google.firestore.v1.TransactionOptions new_transaction = 6; + * + * @return Whether the newTransaction field is set. + */ + boolean hasNewTransaction(); + /** + * + * + *
+   * Execute the pipeline in a new transaction.
+   *
+   * The identifier of the newly created transaction will be returned in the
+   * first response on the stream. This defaults to a read-only transaction.
+   * 
+ * + * .google.firestore.v1.TransactionOptions new_transaction = 6; + * + * @return The newTransaction. + */ + com.google.firestore.v1.TransactionOptions getNewTransaction(); + /** + * + * + *
+   * Execute the pipeline in a new transaction.
+   *
+   * The identifier of the newly created transaction will be returned in the
+   * first response on the stream. This defaults to a read-only transaction.
+   * 
+ * + * .google.firestore.v1.TransactionOptions new_transaction = 6; + */ + com.google.firestore.v1.TransactionOptionsOrBuilder getNewTransactionOrBuilder(); + + /** + * + * + *
+   * Execute the pipeline in a snapshot transaction at the given time.
+   *
+   * This must be a microsecond precision timestamp within the past one hour,
+   * or if Point-in-Time Recovery is enabled, can additionally be a whole
+   * minute timestamp within the past 7 days.
+   * 
+ * + * .google.protobuf.Timestamp read_time = 7; + * + * @return Whether the readTime field is set. + */ + boolean hasReadTime(); + /** + * + * + *
+   * Execute the pipeline in a snapshot transaction at the given time.
+   *
+   * This must be a microsecond precision timestamp within the past one hour,
+   * or if Point-in-Time Recovery is enabled, can additionally be a whole
+   * minute timestamp within the past 7 days.
+   * 
+ * + * .google.protobuf.Timestamp read_time = 7; + * + * @return The readTime. + */ + com.google.protobuf.Timestamp getReadTime(); + /** + * + * + *
+   * Execute the pipeline in a snapshot transaction at the given time.
+   *
+   * This must be a microsecond precision timestamp within the past one hour,
+   * or if Point-in-Time Recovery is enabled, can additionally be a whole
+   * minute timestamp within the past 7 days.
+   * 
+ * + * .google.protobuf.Timestamp read_time = 7; + */ + com.google.protobuf.TimestampOrBuilder getReadTimeOrBuilder(); + + com.google.firestore.v1.ExecutePipelineRequest.PipelineTypeCase getPipelineTypeCase(); + + com.google.firestore.v1.ExecutePipelineRequest.ConsistencySelectorCase + getConsistencySelectorCase(); +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutePipelineResponse.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutePipelineResponse.java new file mode 100644 index 000000000..a8408e14e --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutePipelineResponse.java @@ -0,0 +1,1647 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/firestore.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +/** + * + * + *
+ * The response for [Firestore.Execute][].
+ * 
+ * + * Protobuf type {@code google.firestore.v1.ExecutePipelineResponse} + */ +public final class ExecutePipelineResponse extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.v1.ExecutePipelineResponse) + ExecutePipelineResponseOrBuilder { + private static final long serialVersionUID = 0L; + // Use ExecutePipelineResponse.newBuilder() to construct. + private ExecutePipelineResponse(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private ExecutePipelineResponse() { + transaction_ = com.google.protobuf.ByteString.EMPTY; + results_ = java.util.Collections.emptyList(); + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new ExecutePipelineResponse(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.FirestoreProto + .internal_static_google_firestore_v1_ExecutePipelineResponse_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.FirestoreProto + .internal_static_google_firestore_v1_ExecutePipelineResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.ExecutePipelineResponse.class, + com.google.firestore.v1.ExecutePipelineResponse.Builder.class); + } + + private int bitField0_; + public static final int TRANSACTION_FIELD_NUMBER = 1; + private com.google.protobuf.ByteString transaction_ = com.google.protobuf.ByteString.EMPTY; + /** + * + * + *
+   * Newly created transaction identifier.
+   *
+   * This field is only specified on the first response from the server when
+   * the request specified [ExecuteRequest.new_transaction][].
+   * 
+ * + * bytes transaction = 1; + * + * @return The transaction. + */ + @java.lang.Override + public com.google.protobuf.ByteString getTransaction() { + return transaction_; + } + + public static final int RESULTS_FIELD_NUMBER = 2; + + @SuppressWarnings("serial") + private java.util.List results_; + /** + * + * + *
+   * An ordered batch of results returned executing a pipeline.
+   *
+   * The batch size is variable, and can even be zero for when only a partial
+   * progress message is returned.
+   *
+   * The fields present in the returned documents are only those that were
+   * explicitly requested in the pipeline, this include those like
+   * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+   * This is explicitly a divergence from `Firestore.RunQuery` /
+   * `Firestore.GetDocument` RPCs which always return such fields even when they
+   * are not specified in the [`mask`][DocumentMask].
+   * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + @java.lang.Override + public java.util.List getResultsList() { + return results_; + } + /** + * + * + *
+   * An ordered batch of results returned executing a pipeline.
+   *
+   * The batch size is variable, and can even be zero for when only a partial
+   * progress message is returned.
+   *
+   * The fields present in the returned documents are only those that were
+   * explicitly requested in the pipeline, this include those like
+   * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+   * This is explicitly a divergence from `Firestore.RunQuery` /
+   * `Firestore.GetDocument` RPCs which always return such fields even when they
+   * are not specified in the [`mask`][DocumentMask].
+   * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + @java.lang.Override + public java.util.List + getResultsOrBuilderList() { + return results_; + } + /** + * + * + *
+   * An ordered batch of results returned executing a pipeline.
+   *
+   * The batch size is variable, and can even be zero for when only a partial
+   * progress message is returned.
+   *
+   * The fields present in the returned documents are only those that were
+   * explicitly requested in the pipeline, this include those like
+   * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+   * This is explicitly a divergence from `Firestore.RunQuery` /
+   * `Firestore.GetDocument` RPCs which always return such fields even when they
+   * are not specified in the [`mask`][DocumentMask].
+   * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + @java.lang.Override + public int getResultsCount() { + return results_.size(); + } + /** + * + * + *
+   * An ordered batch of results returned executing a pipeline.
+   *
+   * The batch size is variable, and can even be zero for when only a partial
+   * progress message is returned.
+   *
+   * The fields present in the returned documents are only those that were
+   * explicitly requested in the pipeline, this include those like
+   * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+   * This is explicitly a divergence from `Firestore.RunQuery` /
+   * `Firestore.GetDocument` RPCs which always return such fields even when they
+   * are not specified in the [`mask`][DocumentMask].
+   * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + @java.lang.Override + public com.google.firestore.v1.Document getResults(int index) { + return results_.get(index); + } + /** + * + * + *
+   * An ordered batch of results returned executing a pipeline.
+   *
+   * The batch size is variable, and can even be zero for when only a partial
+   * progress message is returned.
+   *
+   * The fields present in the returned documents are only those that were
+   * explicitly requested in the pipeline, this include those like
+   * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+   * This is explicitly a divergence from `Firestore.RunQuery` /
+   * `Firestore.GetDocument` RPCs which always return such fields even when they
+   * are not specified in the [`mask`][DocumentMask].
+   * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + @java.lang.Override + public com.google.firestore.v1.DocumentOrBuilder getResultsOrBuilder(int index) { + return results_.get(index); + } + + public static final int EXECUTION_TIME_FIELD_NUMBER = 3; + private com.google.protobuf.Timestamp executionTime_; + /** + * + * + *
+   * The time at which the document(s) were read.
+   *
+   * This may be monotonically increasing; in this case, the previous documents
+   * in the result stream are guaranteed not to have changed between their
+   * `execution_time` and this one.
+   *
+   * If the query returns no results, a response with `execution_time` and no
+   * `results` will be sent, and this represents the time at which the operation
+   * was run.
+   * 
+ * + * .google.protobuf.Timestamp execution_time = 3; + * + * @return Whether the executionTime field is set. + */ + @java.lang.Override + public boolean hasExecutionTime() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * + * + *
+   * The time at which the document(s) were read.
+   *
+   * This may be monotonically increasing; in this case, the previous documents
+   * in the result stream are guaranteed not to have changed between their
+   * `execution_time` and this one.
+   *
+   * If the query returns no results, a response with `execution_time` and no
+   * `results` will be sent, and this represents the time at which the operation
+   * was run.
+   * 
+ * + * .google.protobuf.Timestamp execution_time = 3; + * + * @return The executionTime. + */ + @java.lang.Override + public com.google.protobuf.Timestamp getExecutionTime() { + return executionTime_ == null + ? com.google.protobuf.Timestamp.getDefaultInstance() + : executionTime_; + } + /** + * + * + *
+   * The time at which the document(s) were read.
+   *
+   * This may be monotonically increasing; in this case, the previous documents
+   * in the result stream are guaranteed not to have changed between their
+   * `execution_time` and this one.
+   *
+   * If the query returns no results, a response with `execution_time` and no
+   * `results` will be sent, and this represents the time at which the operation
+   * was run.
+   * 
+ * + * .google.protobuf.Timestamp execution_time = 3; + */ + @java.lang.Override + public com.google.protobuf.TimestampOrBuilder getExecutionTimeOrBuilder() { + return executionTime_ == null + ? com.google.protobuf.Timestamp.getDefaultInstance() + : executionTime_; + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!transaction_.isEmpty()) { + output.writeBytes(1, transaction_); + } + for (int i = 0; i < results_.size(); i++) { + output.writeMessage(2, results_.get(i)); + } + if (((bitField0_ & 0x00000001) != 0)) { + output.writeMessage(3, getExecutionTime()); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!transaction_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream.computeBytesSize(1, transaction_); + } + for (int i = 0; i < results_.size(); i++) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(2, results_.get(i)); + } + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(3, getExecutionTime()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.v1.ExecutePipelineResponse)) { + return super.equals(obj); + } + com.google.firestore.v1.ExecutePipelineResponse other = + (com.google.firestore.v1.ExecutePipelineResponse) obj; + + if (!getTransaction().equals(other.getTransaction())) return false; + if (!getResultsList().equals(other.getResultsList())) return false; + if (hasExecutionTime() != other.hasExecutionTime()) return false; + if (hasExecutionTime()) { + if (!getExecutionTime().equals(other.getExecutionTime())) return false; + } + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + TRANSACTION_FIELD_NUMBER; + hash = (53 * hash) + getTransaction().hashCode(); + if (getResultsCount() > 0) { + hash = (37 * hash) + RESULTS_FIELD_NUMBER; + hash = (53 * hash) + getResultsList().hashCode(); + } + if (hasExecutionTime()) { + hash = (37 * hash) + EXECUTION_TIME_FIELD_NUMBER; + hash = (53 * hash) + getExecutionTime().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.v1.ExecutePipelineResponse parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.ExecutePipelineResponse parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.ExecutePipelineResponse parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.ExecutePipelineResponse parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.ExecutePipelineResponse parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.ExecutePipelineResponse parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.ExecutePipelineResponse parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.ExecutePipelineResponse parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.ExecutePipelineResponse parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.ExecutePipelineResponse parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.ExecutePipelineResponse parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.ExecutePipelineResponse parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.v1.ExecutePipelineResponse prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * The response for [Firestore.Execute][].
+   * 
+ * + * Protobuf type {@code google.firestore.v1.ExecutePipelineResponse} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.v1.ExecutePipelineResponse) + com.google.firestore.v1.ExecutePipelineResponseOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.FirestoreProto + .internal_static_google_firestore_v1_ExecutePipelineResponse_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.FirestoreProto + .internal_static_google_firestore_v1_ExecutePipelineResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.ExecutePipelineResponse.class, + com.google.firestore.v1.ExecutePipelineResponse.Builder.class); + } + + // Construct using com.google.firestore.v1.ExecutePipelineResponse.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) { + getResultsFieldBuilder(); + getExecutionTimeFieldBuilder(); + } + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + transaction_ = com.google.protobuf.ByteString.EMPTY; + if (resultsBuilder_ == null) { + results_ = java.util.Collections.emptyList(); + } else { + results_ = null; + resultsBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000002); + executionTime_ = null; + if (executionTimeBuilder_ != null) { + executionTimeBuilder_.dispose(); + executionTimeBuilder_ = null; + } + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.v1.FirestoreProto + .internal_static_google_firestore_v1_ExecutePipelineResponse_descriptor; + } + + @java.lang.Override + public com.google.firestore.v1.ExecutePipelineResponse getDefaultInstanceForType() { + return com.google.firestore.v1.ExecutePipelineResponse.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.v1.ExecutePipelineResponse build() { + com.google.firestore.v1.ExecutePipelineResponse result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.v1.ExecutePipelineResponse buildPartial() { + com.google.firestore.v1.ExecutePipelineResponse result = + new com.google.firestore.v1.ExecutePipelineResponse(this); + buildPartialRepeatedFields(result); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartialRepeatedFields( + com.google.firestore.v1.ExecutePipelineResponse result) { + if (resultsBuilder_ == null) { + if (((bitField0_ & 0x00000002) != 0)) { + results_ = java.util.Collections.unmodifiableList(results_); + bitField0_ = (bitField0_ & ~0x00000002); + } + result.results_ = results_; + } else { + result.results_ = resultsBuilder_.build(); + } + } + + private void buildPartial0(com.google.firestore.v1.ExecutePipelineResponse result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.transaction_ = transaction_; + } + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000004) != 0)) { + result.executionTime_ = + executionTimeBuilder_ == null ? executionTime_ : executionTimeBuilder_.build(); + to_bitField0_ |= 0x00000001; + } + result.bitField0_ |= to_bitField0_; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.v1.ExecutePipelineResponse) { + return mergeFrom((com.google.firestore.v1.ExecutePipelineResponse) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.v1.ExecutePipelineResponse other) { + if (other == com.google.firestore.v1.ExecutePipelineResponse.getDefaultInstance()) + return this; + if (other.getTransaction() != com.google.protobuf.ByteString.EMPTY) { + setTransaction(other.getTransaction()); + } + if (resultsBuilder_ == null) { + if (!other.results_.isEmpty()) { + if (results_.isEmpty()) { + results_ = other.results_; + bitField0_ = (bitField0_ & ~0x00000002); + } else { + ensureResultsIsMutable(); + results_.addAll(other.results_); + } + onChanged(); + } + } else { + if (!other.results_.isEmpty()) { + if (resultsBuilder_.isEmpty()) { + resultsBuilder_.dispose(); + resultsBuilder_ = null; + results_ = other.results_; + bitField0_ = (bitField0_ & ~0x00000002); + resultsBuilder_ = + com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders + ? getResultsFieldBuilder() + : null; + } else { + resultsBuilder_.addAllMessages(other.results_); + } + } + } + if (other.hasExecutionTime()) { + mergeExecutionTime(other.getExecutionTime()); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + transaction_ = input.readBytes(); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: + { + com.google.firestore.v1.Document m = + input.readMessage(com.google.firestore.v1.Document.parser(), extensionRegistry); + if (resultsBuilder_ == null) { + ensureResultsIsMutable(); + results_.add(m); + } else { + resultsBuilder_.addMessage(m); + } + break; + } // case 18 + case 26: + { + input.readMessage(getExecutionTimeFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000004; + break; + } // case 26 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private com.google.protobuf.ByteString transaction_ = com.google.protobuf.ByteString.EMPTY; + /** + * + * + *
+     * Newly created transaction identifier.
+     *
+     * This field is only specified on the first response from the server when
+     * the request specified [ExecuteRequest.new_transaction][].
+     * 
+ * + * bytes transaction = 1; + * + * @return The transaction. + */ + @java.lang.Override + public com.google.protobuf.ByteString getTransaction() { + return transaction_; + } + /** + * + * + *
+     * Newly created transaction identifier.
+     *
+     * This field is only specified on the first response from the server when
+     * the request specified [ExecuteRequest.new_transaction][].
+     * 
+ * + * bytes transaction = 1; + * + * @param value The transaction to set. + * @return This builder for chaining. + */ + public Builder setTransaction(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + transaction_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * Newly created transaction identifier.
+     *
+     * This field is only specified on the first response from the server when
+     * the request specified [ExecuteRequest.new_transaction][].
+     * 
+ * + * bytes transaction = 1; + * + * @return This builder for chaining. + */ + public Builder clearTransaction() { + bitField0_ = (bitField0_ & ~0x00000001); + transaction_ = getDefaultInstance().getTransaction(); + onChanged(); + return this; + } + + private java.util.List results_ = + java.util.Collections.emptyList(); + + private void ensureResultsIsMutable() { + if (!((bitField0_ & 0x00000002) != 0)) { + results_ = new java.util.ArrayList(results_); + bitField0_ |= 0x00000002; + } + } + + private com.google.protobuf.RepeatedFieldBuilderV3< + com.google.firestore.v1.Document, + com.google.firestore.v1.Document.Builder, + com.google.firestore.v1.DocumentOrBuilder> + resultsBuilder_; + + /** + * + * + *
+     * An ordered batch of results returned executing a pipeline.
+     *
+     * The batch size is variable, and can even be zero for when only a partial
+     * progress message is returned.
+     *
+     * The fields present in the returned documents are only those that were
+     * explicitly requested in the pipeline, this include those like
+     * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+     * This is explicitly a divergence from `Firestore.RunQuery` /
+     * `Firestore.GetDocument` RPCs which always return such fields even when they
+     * are not specified in the [`mask`][DocumentMask].
+     * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + public java.util.List getResultsList() { + if (resultsBuilder_ == null) { + return java.util.Collections.unmodifiableList(results_); + } else { + return resultsBuilder_.getMessageList(); + } + } + /** + * + * + *
+     * An ordered batch of results returned executing a pipeline.
+     *
+     * The batch size is variable, and can even be zero for when only a partial
+     * progress message is returned.
+     *
+     * The fields present in the returned documents are only those that were
+     * explicitly requested in the pipeline, this include those like
+     * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+     * This is explicitly a divergence from `Firestore.RunQuery` /
+     * `Firestore.GetDocument` RPCs which always return such fields even when they
+     * are not specified in the [`mask`][DocumentMask].
+     * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + public int getResultsCount() { + if (resultsBuilder_ == null) { + return results_.size(); + } else { + return resultsBuilder_.getCount(); + } + } + /** + * + * + *
+     * An ordered batch of results returned executing a pipeline.
+     *
+     * The batch size is variable, and can even be zero for when only a partial
+     * progress message is returned.
+     *
+     * The fields present in the returned documents are only those that were
+     * explicitly requested in the pipeline, this include those like
+     * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+     * This is explicitly a divergence from `Firestore.RunQuery` /
+     * `Firestore.GetDocument` RPCs which always return such fields even when they
+     * are not specified in the [`mask`][DocumentMask].
+     * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + public com.google.firestore.v1.Document getResults(int index) { + if (resultsBuilder_ == null) { + return results_.get(index); + } else { + return resultsBuilder_.getMessage(index); + } + } + /** + * + * + *
+     * An ordered batch of results returned executing a pipeline.
+     *
+     * The batch size is variable, and can even be zero for when only a partial
+     * progress message is returned.
+     *
+     * The fields present in the returned documents are only those that were
+     * explicitly requested in the pipeline, this include those like
+     * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+     * This is explicitly a divergence from `Firestore.RunQuery` /
+     * `Firestore.GetDocument` RPCs which always return such fields even when they
+     * are not specified in the [`mask`][DocumentMask].
+     * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + public Builder setResults(int index, com.google.firestore.v1.Document value) { + if (resultsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureResultsIsMutable(); + results_.set(index, value); + onChanged(); + } else { + resultsBuilder_.setMessage(index, value); + } + return this; + } + /** + * + * + *
+     * An ordered batch of results returned executing a pipeline.
+     *
+     * The batch size is variable, and can even be zero for when only a partial
+     * progress message is returned.
+     *
+     * The fields present in the returned documents are only those that were
+     * explicitly requested in the pipeline, this include those like
+     * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+     * This is explicitly a divergence from `Firestore.RunQuery` /
+     * `Firestore.GetDocument` RPCs which always return such fields even when they
+     * are not specified in the [`mask`][DocumentMask].
+     * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + public Builder setResults(int index, com.google.firestore.v1.Document.Builder builderForValue) { + if (resultsBuilder_ == null) { + ensureResultsIsMutable(); + results_.set(index, builderForValue.build()); + onChanged(); + } else { + resultsBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + /** + * + * + *
+     * An ordered batch of results returned executing a pipeline.
+     *
+     * The batch size is variable, and can even be zero for when only a partial
+     * progress message is returned.
+     *
+     * The fields present in the returned documents are only those that were
+     * explicitly requested in the pipeline, this include those like
+     * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+     * This is explicitly a divergence from `Firestore.RunQuery` /
+     * `Firestore.GetDocument` RPCs which always return such fields even when they
+     * are not specified in the [`mask`][DocumentMask].
+     * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + public Builder addResults(com.google.firestore.v1.Document value) { + if (resultsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureResultsIsMutable(); + results_.add(value); + onChanged(); + } else { + resultsBuilder_.addMessage(value); + } + return this; + } + /** + * + * + *
+     * An ordered batch of results returned executing a pipeline.
+     *
+     * The batch size is variable, and can even be zero for when only a partial
+     * progress message is returned.
+     *
+     * The fields present in the returned documents are only those that were
+     * explicitly requested in the pipeline, this include those like
+     * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+     * This is explicitly a divergence from `Firestore.RunQuery` /
+     * `Firestore.GetDocument` RPCs which always return such fields even when they
+     * are not specified in the [`mask`][DocumentMask].
+     * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + public Builder addResults(int index, com.google.firestore.v1.Document value) { + if (resultsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureResultsIsMutable(); + results_.add(index, value); + onChanged(); + } else { + resultsBuilder_.addMessage(index, value); + } + return this; + } + /** + * + * + *
+     * An ordered batch of results returned executing a pipeline.
+     *
+     * The batch size is variable, and can even be zero for when only a partial
+     * progress message is returned.
+     *
+     * The fields present in the returned documents are only those that were
+     * explicitly requested in the pipeline, this include those like
+     * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+     * This is explicitly a divergence from `Firestore.RunQuery` /
+     * `Firestore.GetDocument` RPCs which always return such fields even when they
+     * are not specified in the [`mask`][DocumentMask].
+     * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + public Builder addResults(com.google.firestore.v1.Document.Builder builderForValue) { + if (resultsBuilder_ == null) { + ensureResultsIsMutable(); + results_.add(builderForValue.build()); + onChanged(); + } else { + resultsBuilder_.addMessage(builderForValue.build()); + } + return this; + } + /** + * + * + *
+     * An ordered batch of results returned executing a pipeline.
+     *
+     * The batch size is variable, and can even be zero for when only a partial
+     * progress message is returned.
+     *
+     * The fields present in the returned documents are only those that were
+     * explicitly requested in the pipeline, this include those like
+     * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+     * This is explicitly a divergence from `Firestore.RunQuery` /
+     * `Firestore.GetDocument` RPCs which always return such fields even when they
+     * are not specified in the [`mask`][DocumentMask].
+     * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + public Builder addResults(int index, com.google.firestore.v1.Document.Builder builderForValue) { + if (resultsBuilder_ == null) { + ensureResultsIsMutable(); + results_.add(index, builderForValue.build()); + onChanged(); + } else { + resultsBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + /** + * + * + *
+     * An ordered batch of results returned executing a pipeline.
+     *
+     * The batch size is variable, and can even be zero for when only a partial
+     * progress message is returned.
+     *
+     * The fields present in the returned documents are only those that were
+     * explicitly requested in the pipeline, this include those like
+     * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+     * This is explicitly a divergence from `Firestore.RunQuery` /
+     * `Firestore.GetDocument` RPCs which always return such fields even when they
+     * are not specified in the [`mask`][DocumentMask].
+     * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + public Builder addAllResults( + java.lang.Iterable values) { + if (resultsBuilder_ == null) { + ensureResultsIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll(values, results_); + onChanged(); + } else { + resultsBuilder_.addAllMessages(values); + } + return this; + } + /** + * + * + *
+     * An ordered batch of results returned executing a pipeline.
+     *
+     * The batch size is variable, and can even be zero for when only a partial
+     * progress message is returned.
+     *
+     * The fields present in the returned documents are only those that were
+     * explicitly requested in the pipeline, this include those like
+     * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+     * This is explicitly a divergence from `Firestore.RunQuery` /
+     * `Firestore.GetDocument` RPCs which always return such fields even when they
+     * are not specified in the [`mask`][DocumentMask].
+     * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + public Builder clearResults() { + if (resultsBuilder_ == null) { + results_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000002); + onChanged(); + } else { + resultsBuilder_.clear(); + } + return this; + } + /** + * + * + *
+     * An ordered batch of results returned executing a pipeline.
+     *
+     * The batch size is variable, and can even be zero for when only a partial
+     * progress message is returned.
+     *
+     * The fields present in the returned documents are only those that were
+     * explicitly requested in the pipeline, this include those like
+     * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+     * This is explicitly a divergence from `Firestore.RunQuery` /
+     * `Firestore.GetDocument` RPCs which always return such fields even when they
+     * are not specified in the [`mask`][DocumentMask].
+     * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + public Builder removeResults(int index) { + if (resultsBuilder_ == null) { + ensureResultsIsMutable(); + results_.remove(index); + onChanged(); + } else { + resultsBuilder_.remove(index); + } + return this; + } + /** + * + * + *
+     * An ordered batch of results returned executing a pipeline.
+     *
+     * The batch size is variable, and can even be zero for when only a partial
+     * progress message is returned.
+     *
+     * The fields present in the returned documents are only those that were
+     * explicitly requested in the pipeline, this include those like
+     * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+     * This is explicitly a divergence from `Firestore.RunQuery` /
+     * `Firestore.GetDocument` RPCs which always return such fields even when they
+     * are not specified in the [`mask`][DocumentMask].
+     * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + public com.google.firestore.v1.Document.Builder getResultsBuilder(int index) { + return getResultsFieldBuilder().getBuilder(index); + } + /** + * + * + *
+     * An ordered batch of results returned executing a pipeline.
+     *
+     * The batch size is variable, and can even be zero for when only a partial
+     * progress message is returned.
+     *
+     * The fields present in the returned documents are only those that were
+     * explicitly requested in the pipeline, this include those like
+     * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+     * This is explicitly a divergence from `Firestore.RunQuery` /
+     * `Firestore.GetDocument` RPCs which always return such fields even when they
+     * are not specified in the [`mask`][DocumentMask].
+     * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + public com.google.firestore.v1.DocumentOrBuilder getResultsOrBuilder(int index) { + if (resultsBuilder_ == null) { + return results_.get(index); + } else { + return resultsBuilder_.getMessageOrBuilder(index); + } + } + /** + * + * + *
+     * An ordered batch of results returned executing a pipeline.
+     *
+     * The batch size is variable, and can even be zero for when only a partial
+     * progress message is returned.
+     *
+     * The fields present in the returned documents are only those that were
+     * explicitly requested in the pipeline, this include those like
+     * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+     * This is explicitly a divergence from `Firestore.RunQuery` /
+     * `Firestore.GetDocument` RPCs which always return such fields even when they
+     * are not specified in the [`mask`][DocumentMask].
+     * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + public java.util.List + getResultsOrBuilderList() { + if (resultsBuilder_ != null) { + return resultsBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(results_); + } + } + /** + * + * + *
+     * An ordered batch of results returned executing a pipeline.
+     *
+     * The batch size is variable, and can even be zero for when only a partial
+     * progress message is returned.
+     *
+     * The fields present in the returned documents are only those that were
+     * explicitly requested in the pipeline, this include those like
+     * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+     * This is explicitly a divergence from `Firestore.RunQuery` /
+     * `Firestore.GetDocument` RPCs which always return such fields even when they
+     * are not specified in the [`mask`][DocumentMask].
+     * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + public com.google.firestore.v1.Document.Builder addResultsBuilder() { + return getResultsFieldBuilder() + .addBuilder(com.google.firestore.v1.Document.getDefaultInstance()); + } + /** + * + * + *
+     * An ordered batch of results returned executing a pipeline.
+     *
+     * The batch size is variable, and can even be zero for when only a partial
+     * progress message is returned.
+     *
+     * The fields present in the returned documents are only those that were
+     * explicitly requested in the pipeline, this include those like
+     * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+     * This is explicitly a divergence from `Firestore.RunQuery` /
+     * `Firestore.GetDocument` RPCs which always return such fields even when they
+     * are not specified in the [`mask`][DocumentMask].
+     * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + public com.google.firestore.v1.Document.Builder addResultsBuilder(int index) { + return getResultsFieldBuilder() + .addBuilder(index, com.google.firestore.v1.Document.getDefaultInstance()); + } + /** + * + * + *
+     * An ordered batch of results returned executing a pipeline.
+     *
+     * The batch size is variable, and can even be zero for when only a partial
+     * progress message is returned.
+     *
+     * The fields present in the returned documents are only those that were
+     * explicitly requested in the pipeline, this include those like
+     * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+     * This is explicitly a divergence from `Firestore.RunQuery` /
+     * `Firestore.GetDocument` RPCs which always return such fields even when they
+     * are not specified in the [`mask`][DocumentMask].
+     * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + public java.util.List getResultsBuilderList() { + return getResultsFieldBuilder().getBuilderList(); + } + + private com.google.protobuf.RepeatedFieldBuilderV3< + com.google.firestore.v1.Document, + com.google.firestore.v1.Document.Builder, + com.google.firestore.v1.DocumentOrBuilder> + getResultsFieldBuilder() { + if (resultsBuilder_ == null) { + resultsBuilder_ = + new com.google.protobuf.RepeatedFieldBuilderV3< + com.google.firestore.v1.Document, + com.google.firestore.v1.Document.Builder, + com.google.firestore.v1.DocumentOrBuilder>( + results_, ((bitField0_ & 0x00000002) != 0), getParentForChildren(), isClean()); + results_ = null; + } + return resultsBuilder_; + } + + private com.google.protobuf.Timestamp executionTime_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder> + executionTimeBuilder_; + /** + * + * + *
+     * The time at which the document(s) were read.
+     *
+     * This may be monotonically increasing; in this case, the previous documents
+     * in the result stream are guaranteed not to have changed between their
+     * `execution_time` and this one.
+     *
+     * If the query returns no results, a response with `execution_time` and no
+     * `results` will be sent, and this represents the time at which the operation
+     * was run.
+     * 
+ * + * .google.protobuf.Timestamp execution_time = 3; + * + * @return Whether the executionTime field is set. + */ + public boolean hasExecutionTime() { + return ((bitField0_ & 0x00000004) != 0); + } + /** + * + * + *
+     * The time at which the document(s) were read.
+     *
+     * This may be monotonically increasing; in this case, the previous documents
+     * in the result stream are guaranteed not to have changed between their
+     * `execution_time` and this one.
+     *
+     * If the query returns no results, a response with `execution_time` and no
+     * `results` will be sent, and this represents the time at which the operation
+     * was run.
+     * 
+ * + * .google.protobuf.Timestamp execution_time = 3; + * + * @return The executionTime. + */ + public com.google.protobuf.Timestamp getExecutionTime() { + if (executionTimeBuilder_ == null) { + return executionTime_ == null + ? com.google.protobuf.Timestamp.getDefaultInstance() + : executionTime_; + } else { + return executionTimeBuilder_.getMessage(); + } + } + /** + * + * + *
+     * The time at which the document(s) were read.
+     *
+     * This may be monotonically increasing; in this case, the previous documents
+     * in the result stream are guaranteed not to have changed between their
+     * `execution_time` and this one.
+     *
+     * If the query returns no results, a response with `execution_time` and no
+     * `results` will be sent, and this represents the time at which the operation
+     * was run.
+     * 
+ * + * .google.protobuf.Timestamp execution_time = 3; + */ + public Builder setExecutionTime(com.google.protobuf.Timestamp value) { + if (executionTimeBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + executionTime_ = value; + } else { + executionTimeBuilder_.setMessage(value); + } + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + /** + * + * + *
+     * The time at which the document(s) were read.
+     *
+     * This may be monotonically increasing; in this case, the previous documents
+     * in the result stream are guaranteed not to have changed between their
+     * `execution_time` and this one.
+     *
+     * If the query returns no results, a response with `execution_time` and no
+     * `results` will be sent, and this represents the time at which the operation
+     * was run.
+     * 
+ * + * .google.protobuf.Timestamp execution_time = 3; + */ + public Builder setExecutionTime(com.google.protobuf.Timestamp.Builder builderForValue) { + if (executionTimeBuilder_ == null) { + executionTime_ = builderForValue.build(); + } else { + executionTimeBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + /** + * + * + *
+     * The time at which the document(s) were read.
+     *
+     * This may be monotonically increasing; in this case, the previous documents
+     * in the result stream are guaranteed not to have changed between their
+     * `execution_time` and this one.
+     *
+     * If the query returns no results, a response with `execution_time` and no
+     * `results` will be sent, and this represents the time at which the operation
+     * was run.
+     * 
+ * + * .google.protobuf.Timestamp execution_time = 3; + */ + public Builder mergeExecutionTime(com.google.protobuf.Timestamp value) { + if (executionTimeBuilder_ == null) { + if (((bitField0_ & 0x00000004) != 0) + && executionTime_ != null + && executionTime_ != com.google.protobuf.Timestamp.getDefaultInstance()) { + getExecutionTimeBuilder().mergeFrom(value); + } else { + executionTime_ = value; + } + } else { + executionTimeBuilder_.mergeFrom(value); + } + if (executionTime_ != null) { + bitField0_ |= 0x00000004; + onChanged(); + } + return this; + } + /** + * + * + *
+     * The time at which the document(s) were read.
+     *
+     * This may be monotonically increasing; in this case, the previous documents
+     * in the result stream are guaranteed not to have changed between their
+     * `execution_time` and this one.
+     *
+     * If the query returns no results, a response with `execution_time` and no
+     * `results` will be sent, and this represents the time at which the operation
+     * was run.
+     * 
+ * + * .google.protobuf.Timestamp execution_time = 3; + */ + public Builder clearExecutionTime() { + bitField0_ = (bitField0_ & ~0x00000004); + executionTime_ = null; + if (executionTimeBuilder_ != null) { + executionTimeBuilder_.dispose(); + executionTimeBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * The time at which the document(s) were read.
+     *
+     * This may be monotonically increasing; in this case, the previous documents
+     * in the result stream are guaranteed not to have changed between their
+     * `execution_time` and this one.
+     *
+     * If the query returns no results, a response with `execution_time` and no
+     * `results` will be sent, and this represents the time at which the operation
+     * was run.
+     * 
+ * + * .google.protobuf.Timestamp execution_time = 3; + */ + public com.google.protobuf.Timestamp.Builder getExecutionTimeBuilder() { + bitField0_ |= 0x00000004; + onChanged(); + return getExecutionTimeFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * The time at which the document(s) were read.
+     *
+     * This may be monotonically increasing; in this case, the previous documents
+     * in the result stream are guaranteed not to have changed between their
+     * `execution_time` and this one.
+     *
+     * If the query returns no results, a response with `execution_time` and no
+     * `results` will be sent, and this represents the time at which the operation
+     * was run.
+     * 
+ * + * .google.protobuf.Timestamp execution_time = 3; + */ + public com.google.protobuf.TimestampOrBuilder getExecutionTimeOrBuilder() { + if (executionTimeBuilder_ != null) { + return executionTimeBuilder_.getMessageOrBuilder(); + } else { + return executionTime_ == null + ? com.google.protobuf.Timestamp.getDefaultInstance() + : executionTime_; + } + } + /** + * + * + *
+     * The time at which the document(s) were read.
+     *
+     * This may be monotonically increasing; in this case, the previous documents
+     * in the result stream are guaranteed not to have changed between their
+     * `execution_time` and this one.
+     *
+     * If the query returns no results, a response with `execution_time` and no
+     * `results` will be sent, and this represents the time at which the operation
+     * was run.
+     * 
+ * + * .google.protobuf.Timestamp execution_time = 3; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder> + getExecutionTimeFieldBuilder() { + if (executionTimeBuilder_ == null) { + executionTimeBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Timestamp, + com.google.protobuf.Timestamp.Builder, + com.google.protobuf.TimestampOrBuilder>( + getExecutionTime(), getParentForChildren(), isClean()); + executionTime_ = null; + } + return executionTimeBuilder_; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.v1.ExecutePipelineResponse) + } + + // @@protoc_insertion_point(class_scope:google.firestore.v1.ExecutePipelineResponse) + private static final com.google.firestore.v1.ExecutePipelineResponse DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.v1.ExecutePipelineResponse(); + } + + public static com.google.firestore.v1.ExecutePipelineResponse getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public ExecutePipelineResponse parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.v1.ExecutePipelineResponse getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutePipelineResponseOrBuilder.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutePipelineResponseOrBuilder.java new file mode 100644 index 000000000..9aec28083 --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutePipelineResponseOrBuilder.java @@ -0,0 +1,202 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/firestore.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +public interface ExecutePipelineResponseOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.v1.ExecutePipelineResponse) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * Newly created transaction identifier.
+   *
+   * This field is only specified on the first response from the server when
+   * the request specified [ExecuteRequest.new_transaction][].
+   * 
+ * + * bytes transaction = 1; + * + * @return The transaction. + */ + com.google.protobuf.ByteString getTransaction(); + + /** + * + * + *
+   * An ordered batch of results returned executing a pipeline.
+   *
+   * The batch size is variable, and can even be zero for when only a partial
+   * progress message is returned.
+   *
+   * The fields present in the returned documents are only those that were
+   * explicitly requested in the pipeline, this include those like
+   * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+   * This is explicitly a divergence from `Firestore.RunQuery` /
+   * `Firestore.GetDocument` RPCs which always return such fields even when they
+   * are not specified in the [`mask`][DocumentMask].
+   * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + java.util.List getResultsList(); + /** + * + * + *
+   * An ordered batch of results returned executing a pipeline.
+   *
+   * The batch size is variable, and can even be zero for when only a partial
+   * progress message is returned.
+   *
+   * The fields present in the returned documents are only those that were
+   * explicitly requested in the pipeline, this include those like
+   * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+   * This is explicitly a divergence from `Firestore.RunQuery` /
+   * `Firestore.GetDocument` RPCs which always return such fields even when they
+   * are not specified in the [`mask`][DocumentMask].
+   * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + com.google.firestore.v1.Document getResults(int index); + /** + * + * + *
+   * An ordered batch of results returned executing a pipeline.
+   *
+   * The batch size is variable, and can even be zero for when only a partial
+   * progress message is returned.
+   *
+   * The fields present in the returned documents are only those that were
+   * explicitly requested in the pipeline, this include those like
+   * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+   * This is explicitly a divergence from `Firestore.RunQuery` /
+   * `Firestore.GetDocument` RPCs which always return such fields even when they
+   * are not specified in the [`mask`][DocumentMask].
+   * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + int getResultsCount(); + /** + * + * + *
+   * An ordered batch of results returned executing a pipeline.
+   *
+   * The batch size is variable, and can even be zero for when only a partial
+   * progress message is returned.
+   *
+   * The fields present in the returned documents are only those that were
+   * explicitly requested in the pipeline, this include those like
+   * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+   * This is explicitly a divergence from `Firestore.RunQuery` /
+   * `Firestore.GetDocument` RPCs which always return such fields even when they
+   * are not specified in the [`mask`][DocumentMask].
+   * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + java.util.List getResultsOrBuilderList(); + /** + * + * + *
+   * An ordered batch of results returned executing a pipeline.
+   *
+   * The batch size is variable, and can even be zero for when only a partial
+   * progress message is returned.
+   *
+   * The fields present in the returned documents are only those that were
+   * explicitly requested in the pipeline, this include those like
+   * [`__name__`][Document.name] & [`__update_time__`][Document.update_time].
+   * This is explicitly a divergence from `Firestore.RunQuery` /
+   * `Firestore.GetDocument` RPCs which always return such fields even when they
+   * are not specified in the [`mask`][DocumentMask].
+   * 
+ * + * repeated .google.firestore.v1.Document results = 2; + */ + com.google.firestore.v1.DocumentOrBuilder getResultsOrBuilder(int index); + + /** + * + * + *
+   * The time at which the document(s) were read.
+   *
+   * This may be monotonically increasing; in this case, the previous documents
+   * in the result stream are guaranteed not to have changed between their
+   * `execution_time` and this one.
+   *
+   * If the query returns no results, a response with `execution_time` and no
+   * `results` will be sent, and this represents the time at which the operation
+   * was run.
+   * 
+ * + * .google.protobuf.Timestamp execution_time = 3; + * + * @return Whether the executionTime field is set. + */ + boolean hasExecutionTime(); + /** + * + * + *
+   * The time at which the document(s) were read.
+   *
+   * This may be monotonically increasing; in this case, the previous documents
+   * in the result stream are guaranteed not to have changed between their
+   * `execution_time` and this one.
+   *
+   * If the query returns no results, a response with `execution_time` and no
+   * `results` will be sent, and this represents the time at which the operation
+   * was run.
+   * 
+ * + * .google.protobuf.Timestamp execution_time = 3; + * + * @return The executionTime. + */ + com.google.protobuf.Timestamp getExecutionTime(); + /** + * + * + *
+   * The time at which the document(s) were read.
+   *
+   * This may be monotonically increasing; in this case, the previous documents
+   * in the result stream are guaranteed not to have changed between their
+   * `execution_time` and this one.
+   *
+   * If the query returns no results, a response with `execution_time` and no
+   * `results` will be sent, and this represents the time at which the operation
+   * was run.
+   * 
+ * + * .google.protobuf.Timestamp execution_time = 3; + */ + com.google.protobuf.TimestampOrBuilder getExecutionTimeOrBuilder(); +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutionStats.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutionStats.java new file mode 100644 index 000000000..3c3fd0a97 --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutionStats.java @@ -0,0 +1,1305 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/query_profile.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +/** + * + * + *
+ * Execution statistics for the query.
+ * 
+ * + * Protobuf type {@code google.firestore.v1.ExecutionStats} + */ +public final class ExecutionStats extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.v1.ExecutionStats) + ExecutionStatsOrBuilder { + private static final long serialVersionUID = 0L; + // Use ExecutionStats.newBuilder() to construct. + private ExecutionStats(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private ExecutionStats() {} + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new ExecutionStats(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_ExecutionStats_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_ExecutionStats_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.ExecutionStats.class, + com.google.firestore.v1.ExecutionStats.Builder.class); + } + + private int bitField0_; + public static final int RESULTS_RETURNED_FIELD_NUMBER = 1; + private long resultsReturned_ = 0L; + /** + * + * + *
+   * Total number of results returned, including documents, projections,
+   * aggregation results, keys.
+   * 
+ * + * int64 results_returned = 1; + * + * @return The resultsReturned. + */ + @java.lang.Override + public long getResultsReturned() { + return resultsReturned_; + } + + public static final int EXECUTION_DURATION_FIELD_NUMBER = 3; + private com.google.protobuf.Duration executionDuration_; + /** + * + * + *
+   * Total time to execute the query in the backend.
+   * 
+ * + * .google.protobuf.Duration execution_duration = 3; + * + * @return Whether the executionDuration field is set. + */ + @java.lang.Override + public boolean hasExecutionDuration() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * + * + *
+   * Total time to execute the query in the backend.
+   * 
+ * + * .google.protobuf.Duration execution_duration = 3; + * + * @return The executionDuration. + */ + @java.lang.Override + public com.google.protobuf.Duration getExecutionDuration() { + return executionDuration_ == null + ? com.google.protobuf.Duration.getDefaultInstance() + : executionDuration_; + } + /** + * + * + *
+   * Total time to execute the query in the backend.
+   * 
+ * + * .google.protobuf.Duration execution_duration = 3; + */ + @java.lang.Override + public com.google.protobuf.DurationOrBuilder getExecutionDurationOrBuilder() { + return executionDuration_ == null + ? com.google.protobuf.Duration.getDefaultInstance() + : executionDuration_; + } + + public static final int READ_OPERATIONS_FIELD_NUMBER = 4; + private long readOperations_ = 0L; + /** + * + * + *
+   * Total billable read operations.
+   * 
+ * + * int64 read_operations = 4; + * + * @return The readOperations. + */ + @java.lang.Override + public long getReadOperations() { + return readOperations_; + } + + public static final int DEBUG_STATS_FIELD_NUMBER = 5; + private com.google.protobuf.Struct debugStats_; + /** + * + * + *
+   * Debugging statistics from the execution of the query. Note that the
+   * debugging stats are subject to change as Firestore evolves. It could
+   * include:
+   *  {
+   *    "indexes_entries_scanned": "1000",
+   *    "documents_scanned": "20",
+   *    "billing_details" : {
+   *       "documents_billable": "20",
+   *       "index_entries_billable": "1000",
+   *       "min_query_cost": "0"
+   *    }
+   *  }
+   * 
+ * + * .google.protobuf.Struct debug_stats = 5; + * + * @return Whether the debugStats field is set. + */ + @java.lang.Override + public boolean hasDebugStats() { + return ((bitField0_ & 0x00000002) != 0); + } + /** + * + * + *
+   * Debugging statistics from the execution of the query. Note that the
+   * debugging stats are subject to change as Firestore evolves. It could
+   * include:
+   *  {
+   *    "indexes_entries_scanned": "1000",
+   *    "documents_scanned": "20",
+   *    "billing_details" : {
+   *       "documents_billable": "20",
+   *       "index_entries_billable": "1000",
+   *       "min_query_cost": "0"
+   *    }
+   *  }
+   * 
+ * + * .google.protobuf.Struct debug_stats = 5; + * + * @return The debugStats. + */ + @java.lang.Override + public com.google.protobuf.Struct getDebugStats() { + return debugStats_ == null ? com.google.protobuf.Struct.getDefaultInstance() : debugStats_; + } + /** + * + * + *
+   * Debugging statistics from the execution of the query. Note that the
+   * debugging stats are subject to change as Firestore evolves. It could
+   * include:
+   *  {
+   *    "indexes_entries_scanned": "1000",
+   *    "documents_scanned": "20",
+   *    "billing_details" : {
+   *       "documents_billable": "20",
+   *       "index_entries_billable": "1000",
+   *       "min_query_cost": "0"
+   *    }
+   *  }
+   * 
+ * + * .google.protobuf.Struct debug_stats = 5; + */ + @java.lang.Override + public com.google.protobuf.StructOrBuilder getDebugStatsOrBuilder() { + return debugStats_ == null ? com.google.protobuf.Struct.getDefaultInstance() : debugStats_; + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (resultsReturned_ != 0L) { + output.writeInt64(1, resultsReturned_); + } + if (((bitField0_ & 0x00000001) != 0)) { + output.writeMessage(3, getExecutionDuration()); + } + if (readOperations_ != 0L) { + output.writeInt64(4, readOperations_); + } + if (((bitField0_ & 0x00000002) != 0)) { + output.writeMessage(5, getDebugStats()); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (resultsReturned_ != 0L) { + size += com.google.protobuf.CodedOutputStream.computeInt64Size(1, resultsReturned_); + } + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(3, getExecutionDuration()); + } + if (readOperations_ != 0L) { + size += com.google.protobuf.CodedOutputStream.computeInt64Size(4, readOperations_); + } + if (((bitField0_ & 0x00000002) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(5, getDebugStats()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.v1.ExecutionStats)) { + return super.equals(obj); + } + com.google.firestore.v1.ExecutionStats other = (com.google.firestore.v1.ExecutionStats) obj; + + if (getResultsReturned() != other.getResultsReturned()) return false; + if (hasExecutionDuration() != other.hasExecutionDuration()) return false; + if (hasExecutionDuration()) { + if (!getExecutionDuration().equals(other.getExecutionDuration())) return false; + } + if (getReadOperations() != other.getReadOperations()) return false; + if (hasDebugStats() != other.hasDebugStats()) return false; + if (hasDebugStats()) { + if (!getDebugStats().equals(other.getDebugStats())) return false; + } + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + RESULTS_RETURNED_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong(getResultsReturned()); + if (hasExecutionDuration()) { + hash = (37 * hash) + EXECUTION_DURATION_FIELD_NUMBER; + hash = (53 * hash) + getExecutionDuration().hashCode(); + } + hash = (37 * hash) + READ_OPERATIONS_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong(getReadOperations()); + if (hasDebugStats()) { + hash = (37 * hash) + DEBUG_STATS_FIELD_NUMBER; + hash = (53 * hash) + getDebugStats().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.v1.ExecutionStats parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.ExecutionStats parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.ExecutionStats parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.ExecutionStats parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.ExecutionStats parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.ExecutionStats parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.ExecutionStats parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.ExecutionStats parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.ExecutionStats parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.ExecutionStats parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.ExecutionStats parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.ExecutionStats parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.v1.ExecutionStats prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * Execution statistics for the query.
+   * 
+ * + * Protobuf type {@code google.firestore.v1.ExecutionStats} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.v1.ExecutionStats) + com.google.firestore.v1.ExecutionStatsOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_ExecutionStats_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_ExecutionStats_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.ExecutionStats.class, + com.google.firestore.v1.ExecutionStats.Builder.class); + } + + // Construct using com.google.firestore.v1.ExecutionStats.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) { + getExecutionDurationFieldBuilder(); + getDebugStatsFieldBuilder(); + } + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + resultsReturned_ = 0L; + executionDuration_ = null; + if (executionDurationBuilder_ != null) { + executionDurationBuilder_.dispose(); + executionDurationBuilder_ = null; + } + readOperations_ = 0L; + debugStats_ = null; + if (debugStatsBuilder_ != null) { + debugStatsBuilder_.dispose(); + debugStatsBuilder_ = null; + } + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_ExecutionStats_descriptor; + } + + @java.lang.Override + public com.google.firestore.v1.ExecutionStats getDefaultInstanceForType() { + return com.google.firestore.v1.ExecutionStats.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.v1.ExecutionStats build() { + com.google.firestore.v1.ExecutionStats result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.v1.ExecutionStats buildPartial() { + com.google.firestore.v1.ExecutionStats result = + new com.google.firestore.v1.ExecutionStats(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.v1.ExecutionStats result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.resultsReturned_ = resultsReturned_; + } + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000002) != 0)) { + result.executionDuration_ = + executionDurationBuilder_ == null + ? executionDuration_ + : executionDurationBuilder_.build(); + to_bitField0_ |= 0x00000001; + } + if (((from_bitField0_ & 0x00000004) != 0)) { + result.readOperations_ = readOperations_; + } + if (((from_bitField0_ & 0x00000008) != 0)) { + result.debugStats_ = debugStatsBuilder_ == null ? debugStats_ : debugStatsBuilder_.build(); + to_bitField0_ |= 0x00000002; + } + result.bitField0_ |= to_bitField0_; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.v1.ExecutionStats) { + return mergeFrom((com.google.firestore.v1.ExecutionStats) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.v1.ExecutionStats other) { + if (other == com.google.firestore.v1.ExecutionStats.getDefaultInstance()) return this; + if (other.getResultsReturned() != 0L) { + setResultsReturned(other.getResultsReturned()); + } + if (other.hasExecutionDuration()) { + mergeExecutionDuration(other.getExecutionDuration()); + } + if (other.getReadOperations() != 0L) { + setReadOperations(other.getReadOperations()); + } + if (other.hasDebugStats()) { + mergeDebugStats(other.getDebugStats()); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 8: + { + resultsReturned_ = input.readInt64(); + bitField0_ |= 0x00000001; + break; + } // case 8 + case 26: + { + input.readMessage( + getExecutionDurationFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000002; + break; + } // case 26 + case 32: + { + readOperations_ = input.readInt64(); + bitField0_ |= 0x00000004; + break; + } // case 32 + case 42: + { + input.readMessage(getDebugStatsFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000008; + break; + } // case 42 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private long resultsReturned_; + /** + * + * + *
+     * Total number of results returned, including documents, projections,
+     * aggregation results, keys.
+     * 
+ * + * int64 results_returned = 1; + * + * @return The resultsReturned. + */ + @java.lang.Override + public long getResultsReturned() { + return resultsReturned_; + } + /** + * + * + *
+     * Total number of results returned, including documents, projections,
+     * aggregation results, keys.
+     * 
+ * + * int64 results_returned = 1; + * + * @param value The resultsReturned to set. + * @return This builder for chaining. + */ + public Builder setResultsReturned(long value) { + + resultsReturned_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * Total number of results returned, including documents, projections,
+     * aggregation results, keys.
+     * 
+ * + * int64 results_returned = 1; + * + * @return This builder for chaining. + */ + public Builder clearResultsReturned() { + bitField0_ = (bitField0_ & ~0x00000001); + resultsReturned_ = 0L; + onChanged(); + return this; + } + + private com.google.protobuf.Duration executionDuration_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Duration, + com.google.protobuf.Duration.Builder, + com.google.protobuf.DurationOrBuilder> + executionDurationBuilder_; + /** + * + * + *
+     * Total time to execute the query in the backend.
+     * 
+ * + * .google.protobuf.Duration execution_duration = 3; + * + * @return Whether the executionDuration field is set. + */ + public boolean hasExecutionDuration() { + return ((bitField0_ & 0x00000002) != 0); + } + /** + * + * + *
+     * Total time to execute the query in the backend.
+     * 
+ * + * .google.protobuf.Duration execution_duration = 3; + * + * @return The executionDuration. + */ + public com.google.protobuf.Duration getExecutionDuration() { + if (executionDurationBuilder_ == null) { + return executionDuration_ == null + ? com.google.protobuf.Duration.getDefaultInstance() + : executionDuration_; + } else { + return executionDurationBuilder_.getMessage(); + } + } + /** + * + * + *
+     * Total time to execute the query in the backend.
+     * 
+ * + * .google.protobuf.Duration execution_duration = 3; + */ + public Builder setExecutionDuration(com.google.protobuf.Duration value) { + if (executionDurationBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + executionDuration_ = value; + } else { + executionDurationBuilder_.setMessage(value); + } + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+     * Total time to execute the query in the backend.
+     * 
+ * + * .google.protobuf.Duration execution_duration = 3; + */ + public Builder setExecutionDuration(com.google.protobuf.Duration.Builder builderForValue) { + if (executionDurationBuilder_ == null) { + executionDuration_ = builderForValue.build(); + } else { + executionDurationBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+     * Total time to execute the query in the backend.
+     * 
+ * + * .google.protobuf.Duration execution_duration = 3; + */ + public Builder mergeExecutionDuration(com.google.protobuf.Duration value) { + if (executionDurationBuilder_ == null) { + if (((bitField0_ & 0x00000002) != 0) + && executionDuration_ != null + && executionDuration_ != com.google.protobuf.Duration.getDefaultInstance()) { + getExecutionDurationBuilder().mergeFrom(value); + } else { + executionDuration_ = value; + } + } else { + executionDurationBuilder_.mergeFrom(value); + } + if (executionDuration_ != null) { + bitField0_ |= 0x00000002; + onChanged(); + } + return this; + } + /** + * + * + *
+     * Total time to execute the query in the backend.
+     * 
+ * + * .google.protobuf.Duration execution_duration = 3; + */ + public Builder clearExecutionDuration() { + bitField0_ = (bitField0_ & ~0x00000002); + executionDuration_ = null; + if (executionDurationBuilder_ != null) { + executionDurationBuilder_.dispose(); + executionDurationBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * Total time to execute the query in the backend.
+     * 
+ * + * .google.protobuf.Duration execution_duration = 3; + */ + public com.google.protobuf.Duration.Builder getExecutionDurationBuilder() { + bitField0_ |= 0x00000002; + onChanged(); + return getExecutionDurationFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * Total time to execute the query in the backend.
+     * 
+ * + * .google.protobuf.Duration execution_duration = 3; + */ + public com.google.protobuf.DurationOrBuilder getExecutionDurationOrBuilder() { + if (executionDurationBuilder_ != null) { + return executionDurationBuilder_.getMessageOrBuilder(); + } else { + return executionDuration_ == null + ? com.google.protobuf.Duration.getDefaultInstance() + : executionDuration_; + } + } + /** + * + * + *
+     * Total time to execute the query in the backend.
+     * 
+ * + * .google.protobuf.Duration execution_duration = 3; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Duration, + com.google.protobuf.Duration.Builder, + com.google.protobuf.DurationOrBuilder> + getExecutionDurationFieldBuilder() { + if (executionDurationBuilder_ == null) { + executionDurationBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Duration, + com.google.protobuf.Duration.Builder, + com.google.protobuf.DurationOrBuilder>( + getExecutionDuration(), getParentForChildren(), isClean()); + executionDuration_ = null; + } + return executionDurationBuilder_; + } + + private long readOperations_; + /** + * + * + *
+     * Total billable read operations.
+     * 
+ * + * int64 read_operations = 4; + * + * @return The readOperations. + */ + @java.lang.Override + public long getReadOperations() { + return readOperations_; + } + /** + * + * + *
+     * Total billable read operations.
+     * 
+ * + * int64 read_operations = 4; + * + * @param value The readOperations to set. + * @return This builder for chaining. + */ + public Builder setReadOperations(long value) { + + readOperations_ = value; + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + /** + * + * + *
+     * Total billable read operations.
+     * 
+ * + * int64 read_operations = 4; + * + * @return This builder for chaining. + */ + public Builder clearReadOperations() { + bitField0_ = (bitField0_ & ~0x00000004); + readOperations_ = 0L; + onChanged(); + return this; + } + + private com.google.protobuf.Struct debugStats_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Struct, + com.google.protobuf.Struct.Builder, + com.google.protobuf.StructOrBuilder> + debugStatsBuilder_; + /** + * + * + *
+     * Debugging statistics from the execution of the query. Note that the
+     * debugging stats are subject to change as Firestore evolves. It could
+     * include:
+     *  {
+     *    "indexes_entries_scanned": "1000",
+     *    "documents_scanned": "20",
+     *    "billing_details" : {
+     *       "documents_billable": "20",
+     *       "index_entries_billable": "1000",
+     *       "min_query_cost": "0"
+     *    }
+     *  }
+     * 
+ * + * .google.protobuf.Struct debug_stats = 5; + * + * @return Whether the debugStats field is set. + */ + public boolean hasDebugStats() { + return ((bitField0_ & 0x00000008) != 0); + } + /** + * + * + *
+     * Debugging statistics from the execution of the query. Note that the
+     * debugging stats are subject to change as Firestore evolves. It could
+     * include:
+     *  {
+     *    "indexes_entries_scanned": "1000",
+     *    "documents_scanned": "20",
+     *    "billing_details" : {
+     *       "documents_billable": "20",
+     *       "index_entries_billable": "1000",
+     *       "min_query_cost": "0"
+     *    }
+     *  }
+     * 
+ * + * .google.protobuf.Struct debug_stats = 5; + * + * @return The debugStats. + */ + public com.google.protobuf.Struct getDebugStats() { + if (debugStatsBuilder_ == null) { + return debugStats_ == null ? com.google.protobuf.Struct.getDefaultInstance() : debugStats_; + } else { + return debugStatsBuilder_.getMessage(); + } + } + /** + * + * + *
+     * Debugging statistics from the execution of the query. Note that the
+     * debugging stats are subject to change as Firestore evolves. It could
+     * include:
+     *  {
+     *    "indexes_entries_scanned": "1000",
+     *    "documents_scanned": "20",
+     *    "billing_details" : {
+     *       "documents_billable": "20",
+     *       "index_entries_billable": "1000",
+     *       "min_query_cost": "0"
+     *    }
+     *  }
+     * 
+ * + * .google.protobuf.Struct debug_stats = 5; + */ + public Builder setDebugStats(com.google.protobuf.Struct value) { + if (debugStatsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + debugStats_ = value; + } else { + debugStatsBuilder_.setMessage(value); + } + bitField0_ |= 0x00000008; + onChanged(); + return this; + } + /** + * + * + *
+     * Debugging statistics from the execution of the query. Note that the
+     * debugging stats are subject to change as Firestore evolves. It could
+     * include:
+     *  {
+     *    "indexes_entries_scanned": "1000",
+     *    "documents_scanned": "20",
+     *    "billing_details" : {
+     *       "documents_billable": "20",
+     *       "index_entries_billable": "1000",
+     *       "min_query_cost": "0"
+     *    }
+     *  }
+     * 
+ * + * .google.protobuf.Struct debug_stats = 5; + */ + public Builder setDebugStats(com.google.protobuf.Struct.Builder builderForValue) { + if (debugStatsBuilder_ == null) { + debugStats_ = builderForValue.build(); + } else { + debugStatsBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000008; + onChanged(); + return this; + } + /** + * + * + *
+     * Debugging statistics from the execution of the query. Note that the
+     * debugging stats are subject to change as Firestore evolves. It could
+     * include:
+     *  {
+     *    "indexes_entries_scanned": "1000",
+     *    "documents_scanned": "20",
+     *    "billing_details" : {
+     *       "documents_billable": "20",
+     *       "index_entries_billable": "1000",
+     *       "min_query_cost": "0"
+     *    }
+     *  }
+     * 
+ * + * .google.protobuf.Struct debug_stats = 5; + */ + public Builder mergeDebugStats(com.google.protobuf.Struct value) { + if (debugStatsBuilder_ == null) { + if (((bitField0_ & 0x00000008) != 0) + && debugStats_ != null + && debugStats_ != com.google.protobuf.Struct.getDefaultInstance()) { + getDebugStatsBuilder().mergeFrom(value); + } else { + debugStats_ = value; + } + } else { + debugStatsBuilder_.mergeFrom(value); + } + if (debugStats_ != null) { + bitField0_ |= 0x00000008; + onChanged(); + } + return this; + } + /** + * + * + *
+     * Debugging statistics from the execution of the query. Note that the
+     * debugging stats are subject to change as Firestore evolves. It could
+     * include:
+     *  {
+     *    "indexes_entries_scanned": "1000",
+     *    "documents_scanned": "20",
+     *    "billing_details" : {
+     *       "documents_billable": "20",
+     *       "index_entries_billable": "1000",
+     *       "min_query_cost": "0"
+     *    }
+     *  }
+     * 
+ * + * .google.protobuf.Struct debug_stats = 5; + */ + public Builder clearDebugStats() { + bitField0_ = (bitField0_ & ~0x00000008); + debugStats_ = null; + if (debugStatsBuilder_ != null) { + debugStatsBuilder_.dispose(); + debugStatsBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * Debugging statistics from the execution of the query. Note that the
+     * debugging stats are subject to change as Firestore evolves. It could
+     * include:
+     *  {
+     *    "indexes_entries_scanned": "1000",
+     *    "documents_scanned": "20",
+     *    "billing_details" : {
+     *       "documents_billable": "20",
+     *       "index_entries_billable": "1000",
+     *       "min_query_cost": "0"
+     *    }
+     *  }
+     * 
+ * + * .google.protobuf.Struct debug_stats = 5; + */ + public com.google.protobuf.Struct.Builder getDebugStatsBuilder() { + bitField0_ |= 0x00000008; + onChanged(); + return getDebugStatsFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * Debugging statistics from the execution of the query. Note that the
+     * debugging stats are subject to change as Firestore evolves. It could
+     * include:
+     *  {
+     *    "indexes_entries_scanned": "1000",
+     *    "documents_scanned": "20",
+     *    "billing_details" : {
+     *       "documents_billable": "20",
+     *       "index_entries_billable": "1000",
+     *       "min_query_cost": "0"
+     *    }
+     *  }
+     * 
+ * + * .google.protobuf.Struct debug_stats = 5; + */ + public com.google.protobuf.StructOrBuilder getDebugStatsOrBuilder() { + if (debugStatsBuilder_ != null) { + return debugStatsBuilder_.getMessageOrBuilder(); + } else { + return debugStats_ == null ? com.google.protobuf.Struct.getDefaultInstance() : debugStats_; + } + } + /** + * + * + *
+     * Debugging statistics from the execution of the query. Note that the
+     * debugging stats are subject to change as Firestore evolves. It could
+     * include:
+     *  {
+     *    "indexes_entries_scanned": "1000",
+     *    "documents_scanned": "20",
+     *    "billing_details" : {
+     *       "documents_billable": "20",
+     *       "index_entries_billable": "1000",
+     *       "min_query_cost": "0"
+     *    }
+     *  }
+     * 
+ * + * .google.protobuf.Struct debug_stats = 5; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Struct, + com.google.protobuf.Struct.Builder, + com.google.protobuf.StructOrBuilder> + getDebugStatsFieldBuilder() { + if (debugStatsBuilder_ == null) { + debugStatsBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Struct, + com.google.protobuf.Struct.Builder, + com.google.protobuf.StructOrBuilder>( + getDebugStats(), getParentForChildren(), isClean()); + debugStats_ = null; + } + return debugStatsBuilder_; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.v1.ExecutionStats) + } + + // @@protoc_insertion_point(class_scope:google.firestore.v1.ExecutionStats) + private static final com.google.firestore.v1.ExecutionStats DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.v1.ExecutionStats(); + } + + public static com.google.firestore.v1.ExecutionStats getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public ExecutionStats parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.v1.ExecutionStats getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutionStatsOrBuilder.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutionStatsOrBuilder.java new file mode 100644 index 000000000..1694bea5f --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExecutionStatsOrBuilder.java @@ -0,0 +1,156 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/query_profile.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +public interface ExecutionStatsOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.v1.ExecutionStats) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * Total number of results returned, including documents, projections,
+   * aggregation results, keys.
+   * 
+ * + * int64 results_returned = 1; + * + * @return The resultsReturned. + */ + long getResultsReturned(); + + /** + * + * + *
+   * Total time to execute the query in the backend.
+   * 
+ * + * .google.protobuf.Duration execution_duration = 3; + * + * @return Whether the executionDuration field is set. + */ + boolean hasExecutionDuration(); + /** + * + * + *
+   * Total time to execute the query in the backend.
+   * 
+ * + * .google.protobuf.Duration execution_duration = 3; + * + * @return The executionDuration. + */ + com.google.protobuf.Duration getExecutionDuration(); + /** + * + * + *
+   * Total time to execute the query in the backend.
+   * 
+ * + * .google.protobuf.Duration execution_duration = 3; + */ + com.google.protobuf.DurationOrBuilder getExecutionDurationOrBuilder(); + + /** + * + * + *
+   * Total billable read operations.
+   * 
+ * + * int64 read_operations = 4; + * + * @return The readOperations. + */ + long getReadOperations(); + + /** + * + * + *
+   * Debugging statistics from the execution of the query. Note that the
+   * debugging stats are subject to change as Firestore evolves. It could
+   * include:
+   *  {
+   *    "indexes_entries_scanned": "1000",
+   *    "documents_scanned": "20",
+   *    "billing_details" : {
+   *       "documents_billable": "20",
+   *       "index_entries_billable": "1000",
+   *       "min_query_cost": "0"
+   *    }
+   *  }
+   * 
+ * + * .google.protobuf.Struct debug_stats = 5; + * + * @return Whether the debugStats field is set. + */ + boolean hasDebugStats(); + /** + * + * + *
+   * Debugging statistics from the execution of the query. Note that the
+   * debugging stats are subject to change as Firestore evolves. It could
+   * include:
+   *  {
+   *    "indexes_entries_scanned": "1000",
+   *    "documents_scanned": "20",
+   *    "billing_details" : {
+   *       "documents_billable": "20",
+   *       "index_entries_billable": "1000",
+   *       "min_query_cost": "0"
+   *    }
+   *  }
+   * 
+ * + * .google.protobuf.Struct debug_stats = 5; + * + * @return The debugStats. + */ + com.google.protobuf.Struct getDebugStats(); + /** + * + * + *
+   * Debugging statistics from the execution of the query. Note that the
+   * debugging stats are subject to change as Firestore evolves. It could
+   * include:
+   *  {
+   *    "indexes_entries_scanned": "1000",
+   *    "documents_scanned": "20",
+   *    "billing_details" : {
+   *       "documents_billable": "20",
+   *       "index_entries_billable": "1000",
+   *       "min_query_cost": "0"
+   *    }
+   *  }
+   * 
+ * + * .google.protobuf.Struct debug_stats = 5; + */ + com.google.protobuf.StructOrBuilder getDebugStatsOrBuilder(); +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExplainMetrics.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExplainMetrics.java new file mode 100644 index 000000000..9f862e933 --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExplainMetrics.java @@ -0,0 +1,1014 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/query_profile.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +/** + * + * + *
+ * Explain metrics for the query.
+ * 
+ * + * Protobuf type {@code google.firestore.v1.ExplainMetrics} + */ +public final class ExplainMetrics extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.v1.ExplainMetrics) + ExplainMetricsOrBuilder { + private static final long serialVersionUID = 0L; + // Use ExplainMetrics.newBuilder() to construct. + private ExplainMetrics(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private ExplainMetrics() {} + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new ExplainMetrics(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_ExplainMetrics_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_ExplainMetrics_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.ExplainMetrics.class, + com.google.firestore.v1.ExplainMetrics.Builder.class); + } + + private int bitField0_; + public static final int PLAN_SUMMARY_FIELD_NUMBER = 1; + private com.google.firestore.v1.PlanSummary planSummary_; + /** + * + * + *
+   * Planning phase information for the query.
+   * 
+ * + * .google.firestore.v1.PlanSummary plan_summary = 1; + * + * @return Whether the planSummary field is set. + */ + @java.lang.Override + public boolean hasPlanSummary() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * + * + *
+   * Planning phase information for the query.
+   * 
+ * + * .google.firestore.v1.PlanSummary plan_summary = 1; + * + * @return The planSummary. + */ + @java.lang.Override + public com.google.firestore.v1.PlanSummary getPlanSummary() { + return planSummary_ == null + ? com.google.firestore.v1.PlanSummary.getDefaultInstance() + : planSummary_; + } + /** + * + * + *
+   * Planning phase information for the query.
+   * 
+ * + * .google.firestore.v1.PlanSummary plan_summary = 1; + */ + @java.lang.Override + public com.google.firestore.v1.PlanSummaryOrBuilder getPlanSummaryOrBuilder() { + return planSummary_ == null + ? com.google.firestore.v1.PlanSummary.getDefaultInstance() + : planSummary_; + } + + public static final int EXECUTION_STATS_FIELD_NUMBER = 2; + private com.google.firestore.v1.ExecutionStats executionStats_; + /** + * + * + *
+   * Aggregated stats from the execution of the query. Only present when
+   * [ExplainOptions.analyze][google.firestore.v1.ExplainOptions.analyze] is set
+   * to true.
+   * 
+ * + * .google.firestore.v1.ExecutionStats execution_stats = 2; + * + * @return Whether the executionStats field is set. + */ + @java.lang.Override + public boolean hasExecutionStats() { + return ((bitField0_ & 0x00000002) != 0); + } + /** + * + * + *
+   * Aggregated stats from the execution of the query. Only present when
+   * [ExplainOptions.analyze][google.firestore.v1.ExplainOptions.analyze] is set
+   * to true.
+   * 
+ * + * .google.firestore.v1.ExecutionStats execution_stats = 2; + * + * @return The executionStats. + */ + @java.lang.Override + public com.google.firestore.v1.ExecutionStats getExecutionStats() { + return executionStats_ == null + ? com.google.firestore.v1.ExecutionStats.getDefaultInstance() + : executionStats_; + } + /** + * + * + *
+   * Aggregated stats from the execution of the query. Only present when
+   * [ExplainOptions.analyze][google.firestore.v1.ExplainOptions.analyze] is set
+   * to true.
+   * 
+ * + * .google.firestore.v1.ExecutionStats execution_stats = 2; + */ + @java.lang.Override + public com.google.firestore.v1.ExecutionStatsOrBuilder getExecutionStatsOrBuilder() { + return executionStats_ == null + ? com.google.firestore.v1.ExecutionStats.getDefaultInstance() + : executionStats_; + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (((bitField0_ & 0x00000001) != 0)) { + output.writeMessage(1, getPlanSummary()); + } + if (((bitField0_ & 0x00000002) != 0)) { + output.writeMessage(2, getExecutionStats()); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(1, getPlanSummary()); + } + if (((bitField0_ & 0x00000002) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(2, getExecutionStats()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.v1.ExplainMetrics)) { + return super.equals(obj); + } + com.google.firestore.v1.ExplainMetrics other = (com.google.firestore.v1.ExplainMetrics) obj; + + if (hasPlanSummary() != other.hasPlanSummary()) return false; + if (hasPlanSummary()) { + if (!getPlanSummary().equals(other.getPlanSummary())) return false; + } + if (hasExecutionStats() != other.hasExecutionStats()) return false; + if (hasExecutionStats()) { + if (!getExecutionStats().equals(other.getExecutionStats())) return false; + } + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (hasPlanSummary()) { + hash = (37 * hash) + PLAN_SUMMARY_FIELD_NUMBER; + hash = (53 * hash) + getPlanSummary().hashCode(); + } + if (hasExecutionStats()) { + hash = (37 * hash) + EXECUTION_STATS_FIELD_NUMBER; + hash = (53 * hash) + getExecutionStats().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.v1.ExplainMetrics parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.ExplainMetrics parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.ExplainMetrics parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.ExplainMetrics parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.ExplainMetrics parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.ExplainMetrics parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.ExplainMetrics parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.ExplainMetrics parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.ExplainMetrics parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.ExplainMetrics parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.ExplainMetrics parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.ExplainMetrics parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.v1.ExplainMetrics prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * Explain metrics for the query.
+   * 
+ * + * Protobuf type {@code google.firestore.v1.ExplainMetrics} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.v1.ExplainMetrics) + com.google.firestore.v1.ExplainMetricsOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_ExplainMetrics_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_ExplainMetrics_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.ExplainMetrics.class, + com.google.firestore.v1.ExplainMetrics.Builder.class); + } + + // Construct using com.google.firestore.v1.ExplainMetrics.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) { + getPlanSummaryFieldBuilder(); + getExecutionStatsFieldBuilder(); + } + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + planSummary_ = null; + if (planSummaryBuilder_ != null) { + planSummaryBuilder_.dispose(); + planSummaryBuilder_ = null; + } + executionStats_ = null; + if (executionStatsBuilder_ != null) { + executionStatsBuilder_.dispose(); + executionStatsBuilder_ = null; + } + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_ExplainMetrics_descriptor; + } + + @java.lang.Override + public com.google.firestore.v1.ExplainMetrics getDefaultInstanceForType() { + return com.google.firestore.v1.ExplainMetrics.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.v1.ExplainMetrics build() { + com.google.firestore.v1.ExplainMetrics result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.v1.ExplainMetrics buildPartial() { + com.google.firestore.v1.ExplainMetrics result = + new com.google.firestore.v1.ExplainMetrics(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.v1.ExplainMetrics result) { + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.planSummary_ = + planSummaryBuilder_ == null ? planSummary_ : planSummaryBuilder_.build(); + to_bitField0_ |= 0x00000001; + } + if (((from_bitField0_ & 0x00000002) != 0)) { + result.executionStats_ = + executionStatsBuilder_ == null ? executionStats_ : executionStatsBuilder_.build(); + to_bitField0_ |= 0x00000002; + } + result.bitField0_ |= to_bitField0_; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.v1.ExplainMetrics) { + return mergeFrom((com.google.firestore.v1.ExplainMetrics) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.v1.ExplainMetrics other) { + if (other == com.google.firestore.v1.ExplainMetrics.getDefaultInstance()) return this; + if (other.hasPlanSummary()) { + mergePlanSummary(other.getPlanSummary()); + } + if (other.hasExecutionStats()) { + mergeExecutionStats(other.getExecutionStats()); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + input.readMessage(getPlanSummaryFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: + { + input.readMessage(getExecutionStatsFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000002; + break; + } // case 18 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private com.google.firestore.v1.PlanSummary planSummary_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.PlanSummary, + com.google.firestore.v1.PlanSummary.Builder, + com.google.firestore.v1.PlanSummaryOrBuilder> + planSummaryBuilder_; + /** + * + * + *
+     * Planning phase information for the query.
+     * 
+ * + * .google.firestore.v1.PlanSummary plan_summary = 1; + * + * @return Whether the planSummary field is set. + */ + public boolean hasPlanSummary() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * + * + *
+     * Planning phase information for the query.
+     * 
+ * + * .google.firestore.v1.PlanSummary plan_summary = 1; + * + * @return The planSummary. + */ + public com.google.firestore.v1.PlanSummary getPlanSummary() { + if (planSummaryBuilder_ == null) { + return planSummary_ == null + ? com.google.firestore.v1.PlanSummary.getDefaultInstance() + : planSummary_; + } else { + return planSummaryBuilder_.getMessage(); + } + } + /** + * + * + *
+     * Planning phase information for the query.
+     * 
+ * + * .google.firestore.v1.PlanSummary plan_summary = 1; + */ + public Builder setPlanSummary(com.google.firestore.v1.PlanSummary value) { + if (planSummaryBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + planSummary_ = value; + } else { + planSummaryBuilder_.setMessage(value); + } + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * Planning phase information for the query.
+     * 
+ * + * .google.firestore.v1.PlanSummary plan_summary = 1; + */ + public Builder setPlanSummary(com.google.firestore.v1.PlanSummary.Builder builderForValue) { + if (planSummaryBuilder_ == null) { + planSummary_ = builderForValue.build(); + } else { + planSummaryBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * Planning phase information for the query.
+     * 
+ * + * .google.firestore.v1.PlanSummary plan_summary = 1; + */ + public Builder mergePlanSummary(com.google.firestore.v1.PlanSummary value) { + if (planSummaryBuilder_ == null) { + if (((bitField0_ & 0x00000001) != 0) + && planSummary_ != null + && planSummary_ != com.google.firestore.v1.PlanSummary.getDefaultInstance()) { + getPlanSummaryBuilder().mergeFrom(value); + } else { + planSummary_ = value; + } + } else { + planSummaryBuilder_.mergeFrom(value); + } + if (planSummary_ != null) { + bitField0_ |= 0x00000001; + onChanged(); + } + return this; + } + /** + * + * + *
+     * Planning phase information for the query.
+     * 
+ * + * .google.firestore.v1.PlanSummary plan_summary = 1; + */ + public Builder clearPlanSummary() { + bitField0_ = (bitField0_ & ~0x00000001); + planSummary_ = null; + if (planSummaryBuilder_ != null) { + planSummaryBuilder_.dispose(); + planSummaryBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * Planning phase information for the query.
+     * 
+ * + * .google.firestore.v1.PlanSummary plan_summary = 1; + */ + public com.google.firestore.v1.PlanSummary.Builder getPlanSummaryBuilder() { + bitField0_ |= 0x00000001; + onChanged(); + return getPlanSummaryFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * Planning phase information for the query.
+     * 
+ * + * .google.firestore.v1.PlanSummary plan_summary = 1; + */ + public com.google.firestore.v1.PlanSummaryOrBuilder getPlanSummaryOrBuilder() { + if (planSummaryBuilder_ != null) { + return planSummaryBuilder_.getMessageOrBuilder(); + } else { + return planSummary_ == null + ? com.google.firestore.v1.PlanSummary.getDefaultInstance() + : planSummary_; + } + } + /** + * + * + *
+     * Planning phase information for the query.
+     * 
+ * + * .google.firestore.v1.PlanSummary plan_summary = 1; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.PlanSummary, + com.google.firestore.v1.PlanSummary.Builder, + com.google.firestore.v1.PlanSummaryOrBuilder> + getPlanSummaryFieldBuilder() { + if (planSummaryBuilder_ == null) { + planSummaryBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.PlanSummary, + com.google.firestore.v1.PlanSummary.Builder, + com.google.firestore.v1.PlanSummaryOrBuilder>( + getPlanSummary(), getParentForChildren(), isClean()); + planSummary_ = null; + } + return planSummaryBuilder_; + } + + private com.google.firestore.v1.ExecutionStats executionStats_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.ExecutionStats, + com.google.firestore.v1.ExecutionStats.Builder, + com.google.firestore.v1.ExecutionStatsOrBuilder> + executionStatsBuilder_; + /** + * + * + *
+     * Aggregated stats from the execution of the query. Only present when
+     * [ExplainOptions.analyze][google.firestore.v1.ExplainOptions.analyze] is set
+     * to true.
+     * 
+ * + * .google.firestore.v1.ExecutionStats execution_stats = 2; + * + * @return Whether the executionStats field is set. + */ + public boolean hasExecutionStats() { + return ((bitField0_ & 0x00000002) != 0); + } + /** + * + * + *
+     * Aggregated stats from the execution of the query. Only present when
+     * [ExplainOptions.analyze][google.firestore.v1.ExplainOptions.analyze] is set
+     * to true.
+     * 
+ * + * .google.firestore.v1.ExecutionStats execution_stats = 2; + * + * @return The executionStats. + */ + public com.google.firestore.v1.ExecutionStats getExecutionStats() { + if (executionStatsBuilder_ == null) { + return executionStats_ == null + ? com.google.firestore.v1.ExecutionStats.getDefaultInstance() + : executionStats_; + } else { + return executionStatsBuilder_.getMessage(); + } + } + /** + * + * + *
+     * Aggregated stats from the execution of the query. Only present when
+     * [ExplainOptions.analyze][google.firestore.v1.ExplainOptions.analyze] is set
+     * to true.
+     * 
+ * + * .google.firestore.v1.ExecutionStats execution_stats = 2; + */ + public Builder setExecutionStats(com.google.firestore.v1.ExecutionStats value) { + if (executionStatsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + executionStats_ = value; + } else { + executionStatsBuilder_.setMessage(value); + } + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+     * Aggregated stats from the execution of the query. Only present when
+     * [ExplainOptions.analyze][google.firestore.v1.ExplainOptions.analyze] is set
+     * to true.
+     * 
+ * + * .google.firestore.v1.ExecutionStats execution_stats = 2; + */ + public Builder setExecutionStats( + com.google.firestore.v1.ExecutionStats.Builder builderForValue) { + if (executionStatsBuilder_ == null) { + executionStats_ = builderForValue.build(); + } else { + executionStatsBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+     * Aggregated stats from the execution of the query. Only present when
+     * [ExplainOptions.analyze][google.firestore.v1.ExplainOptions.analyze] is set
+     * to true.
+     * 
+ * + * .google.firestore.v1.ExecutionStats execution_stats = 2; + */ + public Builder mergeExecutionStats(com.google.firestore.v1.ExecutionStats value) { + if (executionStatsBuilder_ == null) { + if (((bitField0_ & 0x00000002) != 0) + && executionStats_ != null + && executionStats_ != com.google.firestore.v1.ExecutionStats.getDefaultInstance()) { + getExecutionStatsBuilder().mergeFrom(value); + } else { + executionStats_ = value; + } + } else { + executionStatsBuilder_.mergeFrom(value); + } + if (executionStats_ != null) { + bitField0_ |= 0x00000002; + onChanged(); + } + return this; + } + /** + * + * + *
+     * Aggregated stats from the execution of the query. Only present when
+     * [ExplainOptions.analyze][google.firestore.v1.ExplainOptions.analyze] is set
+     * to true.
+     * 
+ * + * .google.firestore.v1.ExecutionStats execution_stats = 2; + */ + public Builder clearExecutionStats() { + bitField0_ = (bitField0_ & ~0x00000002); + executionStats_ = null; + if (executionStatsBuilder_ != null) { + executionStatsBuilder_.dispose(); + executionStatsBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * Aggregated stats from the execution of the query. Only present when
+     * [ExplainOptions.analyze][google.firestore.v1.ExplainOptions.analyze] is set
+     * to true.
+     * 
+ * + * .google.firestore.v1.ExecutionStats execution_stats = 2; + */ + public com.google.firestore.v1.ExecutionStats.Builder getExecutionStatsBuilder() { + bitField0_ |= 0x00000002; + onChanged(); + return getExecutionStatsFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * Aggregated stats from the execution of the query. Only present when
+     * [ExplainOptions.analyze][google.firestore.v1.ExplainOptions.analyze] is set
+     * to true.
+     * 
+ * + * .google.firestore.v1.ExecutionStats execution_stats = 2; + */ + public com.google.firestore.v1.ExecutionStatsOrBuilder getExecutionStatsOrBuilder() { + if (executionStatsBuilder_ != null) { + return executionStatsBuilder_.getMessageOrBuilder(); + } else { + return executionStats_ == null + ? com.google.firestore.v1.ExecutionStats.getDefaultInstance() + : executionStats_; + } + } + /** + * + * + *
+     * Aggregated stats from the execution of the query. Only present when
+     * [ExplainOptions.analyze][google.firestore.v1.ExplainOptions.analyze] is set
+     * to true.
+     * 
+ * + * .google.firestore.v1.ExecutionStats execution_stats = 2; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.ExecutionStats, + com.google.firestore.v1.ExecutionStats.Builder, + com.google.firestore.v1.ExecutionStatsOrBuilder> + getExecutionStatsFieldBuilder() { + if (executionStatsBuilder_ == null) { + executionStatsBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.ExecutionStats, + com.google.firestore.v1.ExecutionStats.Builder, + com.google.firestore.v1.ExecutionStatsOrBuilder>( + getExecutionStats(), getParentForChildren(), isClean()); + executionStats_ = null; + } + return executionStatsBuilder_; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.v1.ExplainMetrics) + } + + // @@protoc_insertion_point(class_scope:google.firestore.v1.ExplainMetrics) + private static final com.google.firestore.v1.ExplainMetrics DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.v1.ExplainMetrics(); + } + + public static com.google.firestore.v1.ExplainMetrics getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public ExplainMetrics parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.v1.ExplainMetrics getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExplainMetricsOrBuilder.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExplainMetricsOrBuilder.java new file mode 100644 index 000000000..ba5a87f0f --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExplainMetricsOrBuilder.java @@ -0,0 +1,102 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/query_profile.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +public interface ExplainMetricsOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.v1.ExplainMetrics) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * Planning phase information for the query.
+   * 
+ * + * .google.firestore.v1.PlanSummary plan_summary = 1; + * + * @return Whether the planSummary field is set. + */ + boolean hasPlanSummary(); + /** + * + * + *
+   * Planning phase information for the query.
+   * 
+ * + * .google.firestore.v1.PlanSummary plan_summary = 1; + * + * @return The planSummary. + */ + com.google.firestore.v1.PlanSummary getPlanSummary(); + /** + * + * + *
+   * Planning phase information for the query.
+   * 
+ * + * .google.firestore.v1.PlanSummary plan_summary = 1; + */ + com.google.firestore.v1.PlanSummaryOrBuilder getPlanSummaryOrBuilder(); + + /** + * + * + *
+   * Aggregated stats from the execution of the query. Only present when
+   * [ExplainOptions.analyze][google.firestore.v1.ExplainOptions.analyze] is set
+   * to true.
+   * 
+ * + * .google.firestore.v1.ExecutionStats execution_stats = 2; + * + * @return Whether the executionStats field is set. + */ + boolean hasExecutionStats(); + /** + * + * + *
+   * Aggregated stats from the execution of the query. Only present when
+   * [ExplainOptions.analyze][google.firestore.v1.ExplainOptions.analyze] is set
+   * to true.
+   * 
+ * + * .google.firestore.v1.ExecutionStats execution_stats = 2; + * + * @return The executionStats. + */ + com.google.firestore.v1.ExecutionStats getExecutionStats(); + /** + * + * + *
+   * Aggregated stats from the execution of the query. Only present when
+   * [ExplainOptions.analyze][google.firestore.v1.ExplainOptions.analyze] is set
+   * to true.
+   * 
+ * + * .google.firestore.v1.ExecutionStats execution_stats = 2; + */ + com.google.firestore.v1.ExecutionStatsOrBuilder getExecutionStatsOrBuilder(); +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExplainOptions.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExplainOptions.java new file mode 100644 index 000000000..82c242b89 --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExplainOptions.java @@ -0,0 +1,557 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/query_profile.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +/** + * + * + *
+ * Explain options for the query.
+ * 
+ * + * Protobuf type {@code google.firestore.v1.ExplainOptions} + */ +public final class ExplainOptions extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.v1.ExplainOptions) + ExplainOptionsOrBuilder { + private static final long serialVersionUID = 0L; + // Use ExplainOptions.newBuilder() to construct. + private ExplainOptions(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private ExplainOptions() {} + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new ExplainOptions(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_ExplainOptions_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_ExplainOptions_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.ExplainOptions.class, + com.google.firestore.v1.ExplainOptions.Builder.class); + } + + public static final int ANALYZE_FIELD_NUMBER = 1; + private boolean analyze_ = false; + /** + * + * + *
+   * Optional. Whether to execute this query.
+   *
+   * When false (the default), the query will be planned, returning only
+   * metrics from the planning stages.
+   *
+   * When true, the query will be planned and executed, returning the full
+   * query results along with both planning and execution stage metrics.
+   * 
+ * + * bool analyze = 1 [(.google.api.field_behavior) = OPTIONAL]; + * + * @return The analyze. + */ + @java.lang.Override + public boolean getAnalyze() { + return analyze_; + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (analyze_ != false) { + output.writeBool(1, analyze_); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (analyze_ != false) { + size += com.google.protobuf.CodedOutputStream.computeBoolSize(1, analyze_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.v1.ExplainOptions)) { + return super.equals(obj); + } + com.google.firestore.v1.ExplainOptions other = (com.google.firestore.v1.ExplainOptions) obj; + + if (getAnalyze() != other.getAnalyze()) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + ANALYZE_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean(getAnalyze()); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.v1.ExplainOptions parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.ExplainOptions parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.ExplainOptions parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.ExplainOptions parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.ExplainOptions parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.ExplainOptions parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.ExplainOptions parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.ExplainOptions parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.ExplainOptions parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.ExplainOptions parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.ExplainOptions parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.ExplainOptions parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.v1.ExplainOptions prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * Explain options for the query.
+   * 
+ * + * Protobuf type {@code google.firestore.v1.ExplainOptions} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.v1.ExplainOptions) + com.google.firestore.v1.ExplainOptionsOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_ExplainOptions_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_ExplainOptions_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.ExplainOptions.class, + com.google.firestore.v1.ExplainOptions.Builder.class); + } + + // Construct using com.google.firestore.v1.ExplainOptions.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + analyze_ = false; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_ExplainOptions_descriptor; + } + + @java.lang.Override + public com.google.firestore.v1.ExplainOptions getDefaultInstanceForType() { + return com.google.firestore.v1.ExplainOptions.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.v1.ExplainOptions build() { + com.google.firestore.v1.ExplainOptions result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.v1.ExplainOptions buildPartial() { + com.google.firestore.v1.ExplainOptions result = + new com.google.firestore.v1.ExplainOptions(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.v1.ExplainOptions result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.analyze_ = analyze_; + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.v1.ExplainOptions) { + return mergeFrom((com.google.firestore.v1.ExplainOptions) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.v1.ExplainOptions other) { + if (other == com.google.firestore.v1.ExplainOptions.getDefaultInstance()) return this; + if (other.getAnalyze() != false) { + setAnalyze(other.getAnalyze()); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 8: + { + analyze_ = input.readBool(); + bitField0_ |= 0x00000001; + break; + } // case 8 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private boolean analyze_; + /** + * + * + *
+     * Optional. Whether to execute this query.
+     *
+     * When false (the default), the query will be planned, returning only
+     * metrics from the planning stages.
+     *
+     * When true, the query will be planned and executed, returning the full
+     * query results along with both planning and execution stage metrics.
+     * 
+ * + * bool analyze = 1 [(.google.api.field_behavior) = OPTIONAL]; + * + * @return The analyze. + */ + @java.lang.Override + public boolean getAnalyze() { + return analyze_; + } + /** + * + * + *
+     * Optional. Whether to execute this query.
+     *
+     * When false (the default), the query will be planned, returning only
+     * metrics from the planning stages.
+     *
+     * When true, the query will be planned and executed, returning the full
+     * query results along with both planning and execution stage metrics.
+     * 
+ * + * bool analyze = 1 [(.google.api.field_behavior) = OPTIONAL]; + * + * @param value The analyze to set. + * @return This builder for chaining. + */ + public Builder setAnalyze(boolean value) { + + analyze_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * Optional. Whether to execute this query.
+     *
+     * When false (the default), the query will be planned, returning only
+     * metrics from the planning stages.
+     *
+     * When true, the query will be planned and executed, returning the full
+     * query results along with both planning and execution stage metrics.
+     * 
+ * + * bool analyze = 1 [(.google.api.field_behavior) = OPTIONAL]; + * + * @return This builder for chaining. + */ + public Builder clearAnalyze() { + bitField0_ = (bitField0_ & ~0x00000001); + analyze_ = false; + onChanged(); + return this; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.v1.ExplainOptions) + } + + // @@protoc_insertion_point(class_scope:google.firestore.v1.ExplainOptions) + private static final com.google.firestore.v1.ExplainOptions DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.v1.ExplainOptions(); + } + + public static com.google.firestore.v1.ExplainOptions getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public ExplainOptions parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.v1.ExplainOptions getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExplainOptionsOrBuilder.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExplainOptionsOrBuilder.java new file mode 100644 index 000000000..2acb95c56 --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ExplainOptionsOrBuilder.java @@ -0,0 +1,45 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/query_profile.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +public interface ExplainOptionsOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.v1.ExplainOptions) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * Optional. Whether to execute this query.
+   *
+   * When false (the default), the query will be planned, returning only
+   * metrics from the planning stages.
+   *
+   * When true, the query will be planned and executed, returning the full
+   * query results along with both planning and execution stage metrics.
+   * 
+ * + * bool analyze = 1 [(.google.api.field_behavior) = OPTIONAL]; + * + * @return The analyze. + */ + boolean getAnalyze(); +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/FirestoreProto.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/FirestoreProto.java index 0b500b3c3..cb7375ccc 100644 --- a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/FirestoreProto.java +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/FirestoreProto.java @@ -88,6 +88,14 @@ public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry r internal_static_google_firestore_v1_RunQueryResponse_descriptor; static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_google_firestore_v1_RunQueryResponse_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_v1_ExecutePipelineRequest_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_v1_ExecutePipelineRequest_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_v1_ExecutePipelineResponse_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_v1_ExecutePipelineResponse_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_firestore_v1_RunAggregationQueryRequest_descriptor; static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable @@ -179,243 +187,259 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + "e/api/field_behavior.proto\032,google/fires" + "tore/v1/aggregation_result.proto\032 google" + "/firestore/v1/common.proto\032\"google/fires" - + "tore/v1/document.proto\032\037google/firestore" - + "/v1/query.proto\032\037google/firestore/v1/wri" - + "te.proto\032\033google/protobuf/empty.proto\032\037g" - + "oogle/protobuf/timestamp.proto\032\036google/p" - + "rotobuf/wrappers.proto\032\027google/rpc/statu" - + "s.proto\"\271\001\n\022GetDocumentRequest\022\022\n\004name\030\001" - + " \001(\tB\004\342A\001\002\022/\n\004mask\030\002 \001(\0132!.google.firest" - + "ore.v1.DocumentMask\022\025\n\013transaction\030\003 \001(\014" - + "H\000\022/\n\tread_time\030\005 \001(\0132\032.google.protobuf." - + "TimestampH\000B\026\n\024consistency_selector\"\301\002\n\024" - + "ListDocumentsRequest\022\024\n\006parent\030\001 \001(\tB\004\342A" - + "\001\002\022\033\n\rcollection_id\030\002 \001(\tB\004\342A\001\001\022\027\n\tpage_" - + "size\030\003 \001(\005B\004\342A\001\001\022\030\n\npage_token\030\004 \001(\tB\004\342A" - + "\001\001\022\026\n\010order_by\030\006 \001(\tB\004\342A\001\001\0225\n\004mask\030\007 \001(\013" - + "2!.google.firestore.v1.DocumentMaskB\004\342A\001" - + "\001\022\025\n\013transaction\030\010 \001(\014H\000\022/\n\tread_time\030\n " - + "\001(\0132\032.google.protobuf.TimestampH\000\022\024\n\014sho" - + "w_missing\030\014 \001(\010B\026\n\024consistency_selector\"" - + "b\n\025ListDocumentsResponse\0220\n\tdocuments\030\001 " - + "\003(\0132\035.google.firestore.v1.Document\022\027\n\017ne" - + "xt_page_token\030\002 \001(\t\"\307\001\n\025CreateDocumentRe" - + "quest\022\024\n\006parent\030\001 \001(\tB\004\342A\001\002\022\033\n\rcollectio" - + "n_id\030\002 \001(\tB\004\342A\001\002\022\023\n\013document_id\030\003 \001(\t\0225\n" - + "\010document\030\004 \001(\0132\035.google.firestore.v1.Do" - + "cumentB\004\342A\001\002\022/\n\004mask\030\005 \001(\0132!.google.fire" - + "store.v1.DocumentMask\"\364\001\n\025UpdateDocument" - + "Request\0225\n\010document\030\001 \001(\0132\035.google.fires" - + "tore.v1.DocumentB\004\342A\001\002\0226\n\013update_mask\030\002 " - + "\001(\0132!.google.firestore.v1.DocumentMask\022/" - + "\n\004mask\030\003 \001(\0132!.google.firestore.v1.Docum" - + "entMask\022;\n\020current_document\030\004 \001(\0132!.goog" - + "le.firestore.v1.Precondition\"h\n\025DeleteDo" - + "cumentRequest\022\022\n\004name\030\001 \001(\tB\004\342A\001\002\022;\n\020cur" - + "rent_document\030\002 \001(\0132!.google.firestore.v" - + "1.Precondition\"\232\002\n\030BatchGetDocumentsRequ" - + "est\022\026\n\010database\030\001 \001(\tB\004\342A\001\002\022\021\n\tdocuments" - + "\030\002 \003(\t\022/\n\004mask\030\003 \001(\0132!.google.firestore." - + "v1.DocumentMask\022\025\n\013transaction\030\004 \001(\014H\000\022B" - + "\n\017new_transaction\030\005 \001(\0132\'.google.firesto" - + "re.v1.TransactionOptionsH\000\022/\n\tread_time\030" - + "\007 \001(\0132\032.google.protobuf.TimestampH\000B\026\n\024c" - + "onsistency_selector\"\254\001\n\031BatchGetDocument" - + "sResponse\022.\n\005found\030\001 \001(\0132\035.google.firest" - + "ore.v1.DocumentH\000\022\021\n\007missing\030\002 \001(\tH\000\022\023\n\013" - + "transaction\030\003 \001(\014\022-\n\tread_time\030\004 \001(\0132\032.g" - + "oogle.protobuf.TimestampB\010\n\006result\"k\n\027Be" - + "ginTransactionRequest\022\026\n\010database\030\001 \001(\tB" - + "\004\342A\001\002\0228\n\007options\030\002 \001(\0132\'.google.firestor" - + "e.v1.TransactionOptions\"/\n\030BeginTransact" - + "ionResponse\022\023\n\013transaction\030\001 \001(\014\"h\n\rComm" - + "itRequest\022\026\n\010database\030\001 \001(\tB\004\342A\001\002\022*\n\006wri" - + "tes\030\002 \003(\0132\032.google.firestore.v1.Write\022\023\n" - + "\013transaction\030\003 \001(\014\"z\n\016CommitResponse\0227\n\r" - + "write_results\030\001 \003(\0132 .google.firestore.v" - + "1.WriteResult\022/\n\013commit_time\030\002 \001(\0132\032.goo" - + "gle.protobuf.Timestamp\"D\n\017RollbackReques" - + "t\022\026\n\010database\030\001 \001(\tB\004\342A\001\002\022\031\n\013transaction" - + "\030\002 \001(\014B\004\342A\001\002\"\233\002\n\017RunQueryRequest\022\024\n\006pare" - + "nt\030\001 \001(\tB\004\342A\001\002\022@\n\020structured_query\030\002 \001(\013" + + "tore/v1/document.proto\032\"google/firestore" + + "/v1/pipeline.proto\032\037google/firestore/v1/" + + "query.proto\032\037google/firestore/v1/write.p" + + "roto\032\033google/protobuf/empty.proto\032\037googl" + + "e/protobuf/timestamp.proto\032\036google/proto" + + "buf/wrappers.proto\032\027google/rpc/status.pr" + + "oto\"\270\001\n\022GetDocumentRequest\022\021\n\004name\030\001 \001(\t" + + "B\003\340A\002\022/\n\004mask\030\002 \001(\0132!.google.firestore.v" + + "1.DocumentMask\022\025\n\013transaction\030\003 \001(\014H\000\022/\n" + + "\tread_time\030\005 \001(\0132\032.google.protobuf.Times" + + "tampH\000B\026\n\024consistency_selector\"\273\002\n\024ListD" + + "ocumentsRequest\022\023\n\006parent\030\001 \001(\tB\003\340A\002\022\032\n\r" + + "collection_id\030\002 \001(\tB\003\340A\001\022\026\n\tpage_size\030\003 " + + "\001(\005B\003\340A\001\022\027\n\npage_token\030\004 \001(\tB\003\340A\001\022\025\n\010ord" + + "er_by\030\006 \001(\tB\003\340A\001\0224\n\004mask\030\007 \001(\0132!.google." + + "firestore.v1.DocumentMaskB\003\340A\001\022\025\n\013transa" + + "ction\030\010 \001(\014H\000\022/\n\tread_time\030\n \001(\0132\032.googl" + + "e.protobuf.TimestampH\000\022\024\n\014show_missing\030\014" + + " \001(\010B\026\n\024consistency_selector\"b\n\025ListDocu" + + "mentsResponse\0220\n\tdocuments\030\001 \003(\0132\035.googl" + + "e.firestore.v1.Document\022\027\n\017next_page_tok" + + "en\030\002 \001(\t\"\304\001\n\025CreateDocumentRequest\022\023\n\006pa" + + "rent\030\001 \001(\tB\003\340A\002\022\032\n\rcollection_id\030\002 \001(\tB\003" + + "\340A\002\022\023\n\013document_id\030\003 \001(\t\0224\n\010document\030\004 \001" + + "(\0132\035.google.firestore.v1.DocumentB\003\340A\002\022/" + + "\n\004mask\030\005 \001(\0132!.google.firestore.v1.Docum" + + "entMask\"\363\001\n\025UpdateDocumentRequest\0224\n\010doc" + + "ument\030\001 \001(\0132\035.google.firestore.v1.Docume" + + "ntB\003\340A\002\0226\n\013update_mask\030\002 \001(\0132!.google.fi" + + "restore.v1.DocumentMask\022/\n\004mask\030\003 \001(\0132!." + + "google.firestore.v1.DocumentMask\022;\n\020curr" + + "ent_document\030\004 \001(\0132!.google.firestore.v1" + + ".Precondition\"g\n\025DeleteDocumentRequest\022\021" + + "\n\004name\030\001 \001(\tB\003\340A\002\022;\n\020current_document\030\002 " + + "\001(\0132!.google.firestore.v1.Precondition\"\231" + + "\002\n\030BatchGetDocumentsRequest\022\025\n\010database\030" + + "\001 \001(\tB\003\340A\002\022\021\n\tdocuments\030\002 \003(\t\022/\n\004mask\030\003 " + + "\001(\0132!.google.firestore.v1.DocumentMask\022\025" + + "\n\013transaction\030\004 \001(\014H\000\022B\n\017new_transaction" + + "\030\005 \001(\0132\'.google.firestore.v1.Transaction" + + "OptionsH\000\022/\n\tread_time\030\007 \001(\0132\032.google.pr" + + "otobuf.TimestampH\000B\026\n\024consistency_select" + + "or\"\254\001\n\031BatchGetDocumentsResponse\022.\n\005foun" + + "d\030\001 \001(\0132\035.google.firestore.v1.DocumentH\000" + + "\022\021\n\007missing\030\002 \001(\tH\000\022\023\n\013transaction\030\003 \001(\014" + + "\022-\n\tread_time\030\004 \001(\0132\032.google.protobuf.Ti" + + "mestampB\010\n\006result\"j\n\027BeginTransactionReq" + + "uest\022\025\n\010database\030\001 \001(\tB\003\340A\002\0228\n\007options\030\002" + + " \001(\0132\'.google.firestore.v1.TransactionOp" + + "tions\"/\n\030BeginTransactionResponse\022\023\n\013tra" + + "nsaction\030\001 \001(\014\"g\n\rCommitRequest\022\025\n\010datab" + + "ase\030\001 \001(\tB\003\340A\002\022*\n\006writes\030\002 \003(\0132\032.google." + + "firestore.v1.Write\022\023\n\013transaction\030\003 \001(\014\"" + + "z\n\016CommitResponse\0227\n\rwrite_results\030\001 \003(\013" + + "2 .google.firestore.v1.WriteResult\022/\n\013co" + + "mmit_time\030\002 \001(\0132\032.google.protobuf.Timest" + + "amp\"B\n\017RollbackRequest\022\025\n\010database\030\001 \001(\t" + + "B\003\340A\002\022\030\n\013transaction\030\002 \001(\014B\003\340A\002\"\232\002\n\017RunQ" + + "ueryRequest\022\023\n\006parent\030\001 \001(\tB\003\340A\002\022@\n\020stru" + + "ctured_query\030\002 \001(\0132$.google.firestore.v1" + + ".StructuredQueryH\000\022\025\n\013transaction\030\005 \001(\014H" + + "\001\022B\n\017new_transaction\030\006 \001(\0132\'.google.fire" + + "store.v1.TransactionOptionsH\001\022/\n\tread_ti" + + "me\030\007 \001(\0132\032.google.protobuf.TimestampH\001B\014" + + "\n\nquery_typeB\026\n\024consistency_selector\"\311\001\n" + + "\020RunQueryResponse\022\023\n\013transaction\030\002 \001(\014\022/" + + "\n\010document\030\001 \001(\0132\035.google.firestore.v1.D" + + "ocument\022-\n\tread_time\030\003 \001(\0132\032.google.prot" + + "obuf.Timestamp\022\027\n\017skipped_results\030\004 \001(\005\022" + + "\016\n\004done\030\006 \001(\010H\000B\027\n\025continuation_selector" + + "\"\254\002\n\026ExecutePipelineRequest\022\025\n\010database\030" + + "\001 \001(\tB\003\340A\002\022F\n\023structured_pipeline\030\002 \001(\0132" + + "\'.google.firestore.v1.StructuredPipeline" + + "H\000\022\025\n\013transaction\030\005 \001(\014H\001\022B\n\017new_transac" + + "tion\030\006 \001(\0132\'.google.firestore.v1.Transac" + + "tionOptionsH\001\022/\n\tread_time\030\007 \001(\0132\032.googl" + + "e.protobuf.TimestampH\001B\017\n\rpipeline_typeB" + + "\026\n\024consistency_selector\"\222\001\n\027ExecutePipel" + + "ineResponse\022\023\n\013transaction\030\001 \001(\014\022.\n\007resu" + + "lts\030\002 \003(\0132\035.google.firestore.v1.Document" + + "\0222\n\016execution_time\030\003 \001(\0132\032.google.protob" + + "uf.Timestamp\"\274\002\n\032RunAggregationQueryRequ" + + "est\022\023\n\006parent\030\001 \001(\tB\003\340A\002\022W\n\034structured_a" + + "ggregation_query\030\002 \001(\0132/.google.firestor" + + "e.v1.StructuredAggregationQueryH\000\022\025\n\013tra" + + "nsaction\030\004 \001(\014H\001\022B\n\017new_transaction\030\005 \001(" + + "\0132\'.google.firestore.v1.TransactionOptio" + + "nsH\001\022/\n\tread_time\030\006 \001(\0132\032.google.protobu" + + "f.TimestampH\001B\014\n\nquery_typeB\026\n\024consisten" + + "cy_selector\"\231\001\n\033RunAggregationQueryRespo" + + "nse\0226\n\006result\030\001 \001(\0132&.google.firestore.v" + + "1.AggregationResult\022\023\n\013transaction\030\002 \001(\014" + + "\022-\n\tread_time\030\003 \001(\0132\032.google.protobuf.Ti" + + "mestamp\"\205\002\n\025PartitionQueryRequest\022\023\n\006par" + + "ent\030\001 \001(\tB\003\340A\002\022@\n\020structured_query\030\002 \001(\013" + "2$.google.firestore.v1.StructuredQueryH\000" - + "\022\025\n\013transaction\030\005 \001(\014H\001\022B\n\017new_transacti" - + "on\030\006 \001(\0132\'.google.firestore.v1.Transacti" - + "onOptionsH\001\022/\n\tread_time\030\007 \001(\0132\032.google." - + "protobuf.TimestampH\001B\014\n\nquery_typeB\026\n\024co" - + "nsistency_selector\"\311\001\n\020RunQueryResponse\022" - + "\023\n\013transaction\030\002 \001(\014\022/\n\010document\030\001 \001(\0132\035" - + ".google.firestore.v1.Document\022-\n\tread_ti" - + "me\030\003 \001(\0132\032.google.protobuf.Timestamp\022\027\n\017" - + "skipped_results\030\004 \001(\005\022\016\n\004done\030\006 \001(\010H\000B\027\n" - + "\025continuation_selector\"\275\002\n\032RunAggregatio" - + "nQueryRequest\022\024\n\006parent\030\001 \001(\tB\004\342A\001\002\022W\n\034s" - + "tructured_aggregation_query\030\002 \001(\0132/.goog" - + "le.firestore.v1.StructuredAggregationQue" - + "ryH\000\022\025\n\013transaction\030\004 \001(\014H\001\022B\n\017new_trans" - + "action\030\005 \001(\0132\'.google.firestore.v1.Trans" - + "actionOptionsH\001\022/\n\tread_time\030\006 \001(\0132\032.goo" - + "gle.protobuf.TimestampH\001B\014\n\nquery_typeB\026" - + "\n\024consistency_selector\"\231\001\n\033RunAggregatio" - + "nQueryResponse\0226\n\006result\030\001 \001(\0132&.google." - + "firestore.v1.AggregationResult\022\023\n\013transa" - + "ction\030\002 \001(\014\022-\n\tread_time\030\003 \001(\0132\032.google." - + "protobuf.Timestamp\"\206\002\n\025PartitionQueryReq" - + "uest\022\024\n\006parent\030\001 \001(\tB\004\342A\001\002\022@\n\020structured" - + "_query\030\002 \001(\0132$.google.firestore.v1.Struc" - + "turedQueryH\000\022\027\n\017partition_count\030\003 \001(\003\022\022\n" - + "\npage_token\030\004 \001(\t\022\021\n\tpage_size\030\005 \001(\005\022/\n\t" - + "read_time\030\006 \001(\0132\032.google.protobuf.Timest" - + "ampH\001B\014\n\nquery_typeB\026\n\024consistency_selec" - + "tor\"b\n\026PartitionQueryResponse\022/\n\npartiti" - + "ons\030\001 \003(\0132\033.google.firestore.v1.Cursor\022\027" - + "\n\017next_page_token\030\002 \001(\t\"\351\001\n\014WriteRequest" - + "\022\026\n\010database\030\001 \001(\tB\004\342A\001\002\022\021\n\tstream_id\030\002 " - + "\001(\t\022*\n\006writes\030\003 \003(\0132\032.google.firestore.v" - + "1.Write\022\024\n\014stream_token\030\004 \001(\014\022=\n\006labels\030" - + "\005 \003(\0132-.google.firestore.v1.WriteRequest" - + ".LabelsEntry\032-\n\013LabelsEntry\022\013\n\003key\030\001 \001(\t" - + "\022\r\n\005value\030\002 \001(\t:\0028\001\"\242\001\n\rWriteResponse\022\021\n" - + "\tstream_id\030\001 \001(\t\022\024\n\014stream_token\030\002 \001(\014\0227" - + "\n\rwrite_results\030\003 \003(\0132 .google.firestore" - + ".v1.WriteResult\022/\n\013commit_time\030\004 \001(\0132\032.g" - + "oogle.protobuf.Timestamp\"\363\001\n\rListenReque" - + "st\022\026\n\010database\030\001 \001(\tB\004\342A\001\002\0221\n\nadd_target" - + "\030\002 \001(\0132\033.google.firestore.v1.TargetH\000\022\027\n" - + "\rremove_target\030\003 \001(\005H\000\022>\n\006labels\030\004 \003(\0132." - + ".google.firestore.v1.ListenRequest.Label" - + "sEntry\032-\n\013LabelsEntry\022\013\n\003key\030\001 \001(\t\022\r\n\005va" - + "lue\030\002 \001(\t:\0028\001B\017\n\rtarget_change\"\325\002\n\016Liste" - + "nResponse\022:\n\rtarget_change\030\002 \001(\0132!.googl" - + "e.firestore.v1.TargetChangeH\000\022>\n\017documen" - + "t_change\030\003 \001(\0132#.google.firestore.v1.Doc" - + "umentChangeH\000\022>\n\017document_delete\030\004 \001(\0132#" - + ".google.firestore.v1.DocumentDeleteH\000\022>\n" - + "\017document_remove\030\006 \001(\0132#.google.firestor" - + "e.v1.DocumentRemoveH\000\0226\n\006filter\030\005 \001(\0132$." - + "google.firestore.v1.ExistenceFilterH\000B\017\n" - + "\rresponse_type\"\326\003\n\006Target\0228\n\005query\030\002 \001(\013" - + "2\'.google.firestore.v1.Target.QueryTarge" - + "tH\000\022@\n\tdocuments\030\003 \001(\0132+.google.firestor" - + "e.v1.Target.DocumentsTargetH\000\022\026\n\014resume_" - + "token\030\004 \001(\014H\001\022/\n\tread_time\030\013 \001(\0132\032.googl" - + "e.protobuf.TimestampH\001\022\021\n\ttarget_id\030\005 \001(" - + "\005\022\014\n\004once\030\006 \001(\010\0223\n\016expected_count\030\014 \001(\0132" - + "\033.google.protobuf.Int32Value\032$\n\017Document" - + "sTarget\022\021\n\tdocuments\030\002 \003(\t\032m\n\013QueryTarge" - + "t\022\016\n\006parent\030\001 \001(\t\022@\n\020structured_query\030\002 " - + "\001(\0132$.google.firestore.v1.StructuredQuer" - + "yH\000B\014\n\nquery_typeB\r\n\013target_typeB\r\n\013resu" - + "me_type\"\252\002\n\014TargetChange\022N\n\022target_chang" - + "e_type\030\001 \001(\01622.google.firestore.v1.Targe" - + "tChange.TargetChangeType\022\022\n\ntarget_ids\030\002" - + " \003(\005\022!\n\005cause\030\003 \001(\0132\022.google.rpc.Status\022" - + "\024\n\014resume_token\030\004 \001(\014\022-\n\tread_time\030\006 \001(\013" - + "2\032.google.protobuf.Timestamp\"N\n\020TargetCh" - + "angeType\022\r\n\tNO_CHANGE\020\000\022\007\n\003ADD\020\001\022\n\n\006REMO" - + "VE\020\002\022\013\n\007CURRENT\020\003\022\t\n\005RESET\020\004\"\240\001\n\030ListCol" - + "lectionIdsRequest\022\024\n\006parent\030\001 \001(\tB\004\342A\001\002\022" - + "\021\n\tpage_size\030\002 \001(\005\022\022\n\npage_token\030\003 \001(\t\022/" - + "\n\tread_time\030\004 \001(\0132\032.google.protobuf.Time" - + "stampH\000B\026\n\024consistency_selector\"L\n\031ListC" - + "ollectionIdsResponse\022\026\n\016collection_ids\030\001" - + " \003(\t\022\027\n\017next_page_token\030\002 \001(\t\"\312\001\n\021BatchW" - + "riteRequest\022\026\n\010database\030\001 \001(\tB\004\342A\001\002\022*\n\006w" - + "rites\030\002 \003(\0132\032.google.firestore.v1.Write\022" - + "B\n\006labels\030\003 \003(\01322.google.firestore.v1.Ba" - + "tchWriteRequest.LabelsEntry\032-\n\013LabelsEnt" - + "ry\022\013\n\003key\030\001 \001(\t\022\r\n\005value\030\002 \001(\t:\0028\001\"q\n\022Ba" - + "tchWriteResponse\0227\n\rwrite_results\030\001 \003(\0132" - + " .google.firestore.v1.WriteResult\022\"\n\006sta" - + "tus\030\002 \003(\0132\022.google.rpc.Status2\332\031\n\tFirest" - + "ore\022\217\001\n\013GetDocument\022\'.google.firestore.v" - + "1.GetDocumentRequest\032\035.google.firestore." - + "v1.Document\"8\202\323\344\223\0022\0220/v1/{name=projects/" - + "*/databases/*/documents/*/**}\022\365\001\n\rListDo" - + "cuments\022).google.firestore.v1.ListDocume" - + "ntsRequest\032*.google.firestore.v1.ListDoc" - + "umentsResponse\"\214\001\202\323\344\223\002\205\001\022B/v1/{parent=pr" - + "ojects/*/databases/*/documents/*/**}/{co" - + "llection_id}Z?\022=/v1/{parent=projects/*/d" - + "atabases/*/documents}/{collection_id}\022\277\001" - + "\n\016UpdateDocument\022*.google.firestore.v1.U" - + "pdateDocumentRequest\032\035.google.firestore." - + "v1.Document\"b\332A\024document,update_mask\202\323\344\223" - + "\002E29/v1/{document.name=projects/*/databa" - + "ses/*/documents/*/**}:\010document\022\225\001\n\016Dele" - + "teDocument\022*.google.firestore.v1.DeleteD" - + "ocumentRequest\032\026.google.protobuf.Empty\"?" - + "\332A\004name\202\323\344\223\0022*0/v1/{name=projects/*/data" - + "bases/*/documents/*/**}\022\271\001\n\021BatchGetDocu" - + "ments\022-.google.firestore.v1.BatchGetDocu" - + "mentsRequest\032..google.firestore.v1.Batch" - + "GetDocumentsResponse\"C\202\323\344\223\002=\"8/v1/{datab" - + "ase=projects/*/databases/*}/documents:ba" - + "tchGet:\001*0\001\022\307\001\n\020BeginTransaction\022,.googl" - + "e.firestore.v1.BeginTransactionRequest\032-" - + ".google.firestore.v1.BeginTransactionRes" - + "ponse\"V\332A\010database\202\323\344\223\002E\"@/v1/{database=" - + "projects/*/databases/*}/documents:beginT" - + "ransaction:\001*\022\246\001\n\006Commit\022\".google.firest" - + "ore.v1.CommitRequest\032#.google.firestore." - + "v1.CommitResponse\"S\332A\017database,writes\202\323\344" + + "\022\027\n\017partition_count\030\003 \001(\003\022\022\n\npage_token\030" + + "\004 \001(\t\022\021\n\tpage_size\030\005 \001(\005\022/\n\tread_time\030\006 " + + "\001(\0132\032.google.protobuf.TimestampH\001B\014\n\nque" + + "ry_typeB\026\n\024consistency_selector\"b\n\026Parti" + + "tionQueryResponse\022/\n\npartitions\030\001 \003(\0132\033." + + "google.firestore.v1.Cursor\022\027\n\017next_page_" + + "token\030\002 \001(\t\"\350\001\n\014WriteRequest\022\025\n\010database" + + "\030\001 \001(\tB\003\340A\002\022\021\n\tstream_id\030\002 \001(\t\022*\n\006writes" + + "\030\003 \003(\0132\032.google.firestore.v1.Write\022\024\n\014st" + + "ream_token\030\004 \001(\014\022=\n\006labels\030\005 \003(\0132-.googl" + + "e.firestore.v1.WriteRequest.LabelsEntry\032" + + "-\n\013LabelsEntry\022\013\n\003key\030\001 \001(\t\022\r\n\005value\030\002 \001" + + "(\t:\0028\001\"\242\001\n\rWriteResponse\022\021\n\tstream_id\030\001 " + + "\001(\t\022\024\n\014stream_token\030\002 \001(\014\0227\n\rwrite_resul" + + "ts\030\003 \003(\0132 .google.firestore.v1.WriteResu" + + "lt\022/\n\013commit_time\030\004 \001(\0132\032.google.protobu" + + "f.Timestamp\"\362\001\n\rListenRequest\022\025\n\010databas" + + "e\030\001 \001(\tB\003\340A\002\0221\n\nadd_target\030\002 \001(\0132\033.googl" + + "e.firestore.v1.TargetH\000\022\027\n\rremove_target" + + "\030\003 \001(\005H\000\022>\n\006labels\030\004 \003(\0132..google.firest" + + "ore.v1.ListenRequest.LabelsEntry\032-\n\013Labe" + + "lsEntry\022\013\n\003key\030\001 \001(\t\022\r\n\005value\030\002 \001(\t:\0028\001B" + + "\017\n\rtarget_change\"\325\002\n\016ListenResponse\022:\n\rt" + + "arget_change\030\002 \001(\0132!.google.firestore.v1" + + ".TargetChangeH\000\022>\n\017document_change\030\003 \001(\013" + + "2#.google.firestore.v1.DocumentChangeH\000\022" + + ">\n\017document_delete\030\004 \001(\0132#.google.firest" + + "ore.v1.DocumentDeleteH\000\022>\n\017document_remo" + + "ve\030\006 \001(\0132#.google.firestore.v1.DocumentR" + + "emoveH\000\0226\n\006filter\030\005 \001(\0132$.google.firesto" + + "re.v1.ExistenceFilterH\000B\017\n\rresponse_type" + + "\"\326\003\n\006Target\0228\n\005query\030\002 \001(\0132\'.google.fire" + + "store.v1.Target.QueryTargetH\000\022@\n\tdocumen" + + "ts\030\003 \001(\0132+.google.firestore.v1.Target.Do" + + "cumentsTargetH\000\022\026\n\014resume_token\030\004 \001(\014H\001\022" + + "/\n\tread_time\030\013 \001(\0132\032.google.protobuf.Tim" + + "estampH\001\022\021\n\ttarget_id\030\005 \001(\005\022\014\n\004once\030\006 \001(" + + "\010\0223\n\016expected_count\030\014 \001(\0132\033.google.proto" + + "buf.Int32Value\032$\n\017DocumentsTarget\022\021\n\tdoc" + + "uments\030\002 \003(\t\032m\n\013QueryTarget\022\016\n\006parent\030\001 " + + "\001(\t\022@\n\020structured_query\030\002 \001(\0132$.google.f" + + "irestore.v1.StructuredQueryH\000B\014\n\nquery_t" + + "ypeB\r\n\013target_typeB\r\n\013resume_type\"\252\002\n\014Ta" + + "rgetChange\022N\n\022target_change_type\030\001 \001(\01622" + + ".google.firestore.v1.TargetChange.Target" + + "ChangeType\022\022\n\ntarget_ids\030\002 \003(\005\022!\n\005cause\030" + + "\003 \001(\0132\022.google.rpc.Status\022\024\n\014resume_toke" + + "n\030\004 \001(\014\022-\n\tread_time\030\006 \001(\0132\032.google.prot" + + "obuf.Timestamp\"N\n\020TargetChangeType\022\r\n\tNO" + + "_CHANGE\020\000\022\007\n\003ADD\020\001\022\n\n\006REMOVE\020\002\022\013\n\007CURREN" + + "T\020\003\022\t\n\005RESET\020\004\"\237\001\n\030ListCollectionIdsRequ" + + "est\022\023\n\006parent\030\001 \001(\tB\003\340A\002\022\021\n\tpage_size\030\002 " + + "\001(\005\022\022\n\npage_token\030\003 \001(\t\022/\n\tread_time\030\004 \001" + + "(\0132\032.google.protobuf.TimestampH\000B\026\n\024cons" + + "istency_selector\"L\n\031ListCollectionIdsRes" + + "ponse\022\026\n\016collection_ids\030\001 \003(\t\022\027\n\017next_pa" + + "ge_token\030\002 \001(\t\"\311\001\n\021BatchWriteRequest\022\025\n\010" + + "database\030\001 \001(\tB\003\340A\002\022*\n\006writes\030\002 \003(\0132\032.go" + + "ogle.firestore.v1.Write\022B\n\006labels\030\003 \003(\0132" + + "2.google.firestore.v1.BatchWriteRequest." + + "LabelsEntry\032-\n\013LabelsEntry\022\013\n\003key\030\001 \001(\t\022" + + "\r\n\005value\030\002 \001(\t:\0028\001\"q\n\022BatchWriteResponse" + + "\0227\n\rwrite_results\030\001 \003(\0132 .google.firesto" + + "re.v1.WriteResult\022\"\n\006status\030\002 \003(\0132\022.goog" + + "le.rpc.Status2\222\033\n\tFirestore\022\217\001\n\013GetDocum" + + "ent\022\'.google.firestore.v1.GetDocumentReq" + + "uest\032\035.google.firestore.v1.Document\"8\202\323\344" + + "\223\0022\0220/v1/{name=projects/*/databases/*/do" + + "cuments/*/**}\022\365\001\n\rListDocuments\022).google" + + ".firestore.v1.ListDocumentsRequest\032*.goo" + + "gle.firestore.v1.ListDocumentsResponse\"\214" + + "\001\202\323\344\223\002\205\001\022B/v1/{parent=projects/*/databas" + + "es/*/documents/*/**}/{collection_id}Z?\022=" + + "/v1/{parent=projects/*/databases/*/docum" + + "ents}/{collection_id}\022\277\001\n\016UpdateDocument" + + "\022*.google.firestore.v1.UpdateDocumentReq" + + "uest\032\035.google.firestore.v1.Document\"b\332A\024" + + "document,update_mask\202\323\344\223\002E29/v1/{documen" + + "t.name=projects/*/databases/*/documents/" + + "*/**}:\010document\022\225\001\n\016DeleteDocument\022*.goo" + + "gle.firestore.v1.DeleteDocumentRequest\032\026" + + ".google.protobuf.Empty\"?\332A\004name\202\323\344\223\0022*0/" + + "v1/{name=projects/*/databases/*/document" + + "s/*/**}\022\271\001\n\021BatchGetDocuments\022-.google.f" + + "irestore.v1.BatchGetDocumentsRequest\032..g" + + "oogle.firestore.v1.BatchGetDocumentsResp" + + "onse\"C\202\323\344\223\002=\"8/v1/{database=projects/*/d" + + "atabases/*}/documents:batchGet:\001*0\001\022\307\001\n\020" + + "BeginTransaction\022,.google.firestore.v1.B" + + "eginTransactionRequest\032-.google.firestor" + + "e.v1.BeginTransactionResponse\"V\332A\010databa" + + "se\202\323\344\223\002E\"@/v1/{database=projects/*/datab" + + "ases/*}/documents:beginTransaction:\001*\022\246\001" + + "\n\006Commit\022\".google.firestore.v1.CommitReq" + + "uest\032#.google.firestore.v1.CommitRespons" + + "e\"S\332A\017database,writes\202\323\344\223\002;\"6/v1/{databa" + + "se=projects/*/databases/*}/documents:com" + + "mit:\001*\022\244\001\n\010Rollback\022$.google.firestore.v" + + "1.RollbackRequest\032\026.google.protobuf.Empt" + + "y\"Z\332A\024database,transaction\202\323\344\223\002=\"8/v1/{d" + + "atabase=projects/*/databases/*}/document" + + "s:rollback:\001*\022\337\001\n\010RunQuery\022$.google.fire" + + "store.v1.RunQueryRequest\032%.google.firest" + + "ore.v1.RunQueryResponse\"\203\001\202\323\344\223\002}\"6/v1/{p" + + "arent=projects/*/databases/*/documents}:" + + "runQuery:\001*Z@\";/v1/{parent=projects/*/da" + + "tabases/*/documents/*/**}:runQuery:\001*0\001\022" + + "\265\001\n\017ExecutePipeline\022+.google.firestore.v" + + "1.ExecutePipelineRequest\032,.google.firest" + + "ore.v1.ExecutePipelineResponse\"E\202\323\344\223\002?\":" + + "/v1beta1/{database=projects/*/databases/" + + "*}:executePipeline:\001*0\001\022\227\002\n\023RunAggregati" + + "onQuery\022/.google.firestore.v1.RunAggrega" + + "tionQueryRequest\0320.google.firestore.v1.R" + + "unAggregationQueryResponse\"\232\001\202\323\344\223\002\223\001\"A/v" + + "1/{parent=projects/*/databases/*/documen" + + "ts}:runAggregationQuery:\001*ZK\"F/v1/{paren" + + "t=projects/*/databases/*/documents/*/**}" + + ":runAggregationQuery:\001*0\001\022\374\001\n\016PartitionQ" + + "uery\022*.google.firestore.v1.PartitionQuer" + + "yRequest\032+.google.firestore.v1.Partition" + + "QueryResponse\"\220\001\202\323\344\223\002\211\001\" + * Represents an unevaluated scalar expression. + * + * For example, the expression `like(user_name, "%alice%")` is represented as: + * + * ``` + * name: "like" + * args { field_reference: "user_name" } + * args { string_value: "%alice%" } + * ``` + * + * (-- api-linter: core::0123::resource-annotation=disabled + * aip.dev/not-precedent: this is not a One Platform API resource. --) + * + * + * Protobuf type {@code google.firestore.v1.Function} + */ +public final class Function extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.v1.Function) + FunctionOrBuilder { + private static final long serialVersionUID = 0L; + // Use Function.newBuilder() to construct. + private Function(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private Function() { + name_ = ""; + args_ = java.util.Collections.emptyList(); + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new Function(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.DocumentProto + .internal_static_google_firestore_v1_Function_descriptor; + } + + @SuppressWarnings({"rawtypes"}) + @java.lang.Override + protected com.google.protobuf.MapFieldReflectionAccessor internalGetMapFieldReflection( + int number) { + switch (number) { + case 3: + return internalGetOptions(); + default: + throw new RuntimeException("Invalid map field number: " + number); + } + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.DocumentProto + .internal_static_google_firestore_v1_Function_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.Function.class, com.google.firestore.v1.Function.Builder.class); + } + + public static final int NAME_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile java.lang.Object name_ = ""; + /** + * + * + *
+   * The name of the function to evaluate.
+   *
+   * **Requires:**
+   *
+   * * must be in snake case (lower case with underscore separator).
+   * 
+ * + * string name = 1; + * + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } + } + /** + * + * + *
+   * The name of the function to evaluate.
+   *
+   * **Requires:**
+   *
+   * * must be in snake case (lower case with underscore separator).
+   * 
+ * + * string name = 1; + * + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int ARGS_FIELD_NUMBER = 2; + + @SuppressWarnings("serial") + private java.util.List args_; + /** + * + * + *
+   * Ordered list of arguments the given function expects.
+   * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + @java.lang.Override + public java.util.List getArgsList() { + return args_; + } + /** + * + * + *
+   * Ordered list of arguments the given function expects.
+   * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + @java.lang.Override + public java.util.List getArgsOrBuilderList() { + return args_; + } + /** + * + * + *
+   * Ordered list of arguments the given function expects.
+   * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + @java.lang.Override + public int getArgsCount() { + return args_.size(); + } + /** + * + * + *
+   * Ordered list of arguments the given function expects.
+   * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + @java.lang.Override + public com.google.firestore.v1.Value getArgs(int index) { + return args_.get(index); + } + /** + * + * + *
+   * Ordered list of arguments the given function expects.
+   * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + @java.lang.Override + public com.google.firestore.v1.ValueOrBuilder getArgsOrBuilder(int index) { + return args_.get(index); + } + + public static final int OPTIONS_FIELD_NUMBER = 3; + + private static final class OptionsDefaultEntryHolder { + static final com.google.protobuf.MapEntry + defaultEntry = + com.google.protobuf.MapEntry + .newDefaultInstance( + com.google.firestore.v1.DocumentProto + .internal_static_google_firestore_v1_Function_OptionsEntry_descriptor, + com.google.protobuf.WireFormat.FieldType.STRING, + "", + com.google.protobuf.WireFormat.FieldType.MESSAGE, + com.google.firestore.v1.Value.getDefaultInstance()); + } + + @SuppressWarnings("serial") + private com.google.protobuf.MapField options_; + + private com.google.protobuf.MapField + internalGetOptions() { + if (options_ == null) { + return com.google.protobuf.MapField.emptyMapField(OptionsDefaultEntryHolder.defaultEntry); + } + return options_; + } + + public int getOptionsCount() { + return internalGetOptions().getMap().size(); + } + /** + * + * + *
+   * Optional named arguments that certain functions may support.
+   * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + @java.lang.Override + public boolean containsOptions(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + return internalGetOptions().getMap().containsKey(key); + } + /** Use {@link #getOptionsMap()} instead. */ + @java.lang.Override + @java.lang.Deprecated + public java.util.Map getOptions() { + return getOptionsMap(); + } + /** + * + * + *
+   * Optional named arguments that certain functions may support.
+   * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + @java.lang.Override + public java.util.Map getOptionsMap() { + return internalGetOptions().getMap(); + } + /** + * + * + *
+   * Optional named arguments that certain functions may support.
+   * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + @java.lang.Override + public /* nullable */ com.google.firestore.v1.Value getOptionsOrDefault( + java.lang.String key, + /* nullable */ + com.google.firestore.v1.Value defaultValue) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = + internalGetOptions().getMap(); + return map.containsKey(key) ? map.get(key) : defaultValue; + } + /** + * + * + *
+   * Optional named arguments that certain functions may support.
+   * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + @java.lang.Override + public com.google.firestore.v1.Value getOptionsOrThrow(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = + internalGetOptions().getMap(); + if (!map.containsKey(key)) { + throw new java.lang.IllegalArgumentException(); + } + return map.get(key); + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + } + for (int i = 0; i < args_.size(); i++) { + output.writeMessage(2, args_.get(i)); + } + com.google.protobuf.GeneratedMessageV3.serializeStringMapTo( + output, internalGetOptions(), OptionsDefaultEntryHolder.defaultEntry, 3); + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + } + for (int i = 0; i < args_.size(); i++) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(2, args_.get(i)); + } + for (java.util.Map.Entry entry : + internalGetOptions().getMap().entrySet()) { + com.google.protobuf.MapEntry options__ = + OptionsDefaultEntryHolder.defaultEntry + .newBuilderForType() + .setKey(entry.getKey()) + .setValue(entry.getValue()) + .build(); + size += com.google.protobuf.CodedOutputStream.computeMessageSize(3, options__); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.v1.Function)) { + return super.equals(obj); + } + com.google.firestore.v1.Function other = (com.google.firestore.v1.Function) obj; + + if (!getName().equals(other.getName())) return false; + if (!getArgsList().equals(other.getArgsList())) return false; + if (!internalGetOptions().equals(other.internalGetOptions())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + NAME_FIELD_NUMBER; + hash = (53 * hash) + getName().hashCode(); + if (getArgsCount() > 0) { + hash = (37 * hash) + ARGS_FIELD_NUMBER; + hash = (53 * hash) + getArgsList().hashCode(); + } + if (!internalGetOptions().getMap().isEmpty()) { + hash = (37 * hash) + OPTIONS_FIELD_NUMBER; + hash = (53 * hash) + internalGetOptions().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.v1.Function parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.Function parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.Function parseFrom(com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.Function parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.Function parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.Function parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.Function parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.Function parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.Function parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.Function parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.Function parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.Function parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.v1.Function prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * Represents an unevaluated scalar expression.
+   *
+   * For example, the expression `like(user_name, "%alice%")` is represented as:
+   *
+   * ```
+   * name: "like"
+   * args { field_reference: "user_name" }
+   * args { string_value: "%alice%" }
+   * ```
+   *
+   * (-- api-linter: core::0123::resource-annotation=disabled
+   *     aip.dev/not-precedent: this is not a One Platform API resource. --)
+   * 
+ * + * Protobuf type {@code google.firestore.v1.Function} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.v1.Function) + com.google.firestore.v1.FunctionOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.DocumentProto + .internal_static_google_firestore_v1_Function_descriptor; + } + + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapFieldReflectionAccessor internalGetMapFieldReflection( + int number) { + switch (number) { + case 3: + return internalGetOptions(); + default: + throw new RuntimeException("Invalid map field number: " + number); + } + } + + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapFieldReflectionAccessor internalGetMutableMapFieldReflection( + int number) { + switch (number) { + case 3: + return internalGetMutableOptions(); + default: + throw new RuntimeException("Invalid map field number: " + number); + } + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.DocumentProto + .internal_static_google_firestore_v1_Function_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.Function.class, + com.google.firestore.v1.Function.Builder.class); + } + + // Construct using com.google.firestore.v1.Function.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + name_ = ""; + if (argsBuilder_ == null) { + args_ = java.util.Collections.emptyList(); + } else { + args_ = null; + argsBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000002); + internalGetMutableOptions().clear(); + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.v1.DocumentProto + .internal_static_google_firestore_v1_Function_descriptor; + } + + @java.lang.Override + public com.google.firestore.v1.Function getDefaultInstanceForType() { + return com.google.firestore.v1.Function.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.v1.Function build() { + com.google.firestore.v1.Function result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.v1.Function buildPartial() { + com.google.firestore.v1.Function result = new com.google.firestore.v1.Function(this); + buildPartialRepeatedFields(result); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartialRepeatedFields(com.google.firestore.v1.Function result) { + if (argsBuilder_ == null) { + if (((bitField0_ & 0x00000002) != 0)) { + args_ = java.util.Collections.unmodifiableList(args_); + bitField0_ = (bitField0_ & ~0x00000002); + } + result.args_ = args_; + } else { + result.args_ = argsBuilder_.build(); + } + } + + private void buildPartial0(com.google.firestore.v1.Function result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.name_ = name_; + } + if (((from_bitField0_ & 0x00000004) != 0)) { + result.options_ = internalGetOptions().build(OptionsDefaultEntryHolder.defaultEntry); + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.v1.Function) { + return mergeFrom((com.google.firestore.v1.Function) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.v1.Function other) { + if (other == com.google.firestore.v1.Function.getDefaultInstance()) return this; + if (!other.getName().isEmpty()) { + name_ = other.name_; + bitField0_ |= 0x00000001; + onChanged(); + } + if (argsBuilder_ == null) { + if (!other.args_.isEmpty()) { + if (args_.isEmpty()) { + args_ = other.args_; + bitField0_ = (bitField0_ & ~0x00000002); + } else { + ensureArgsIsMutable(); + args_.addAll(other.args_); + } + onChanged(); + } + } else { + if (!other.args_.isEmpty()) { + if (argsBuilder_.isEmpty()) { + argsBuilder_.dispose(); + argsBuilder_ = null; + args_ = other.args_; + bitField0_ = (bitField0_ & ~0x00000002); + argsBuilder_ = + com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders + ? getArgsFieldBuilder() + : null; + } else { + argsBuilder_.addAllMessages(other.args_); + } + } + } + internalGetMutableOptions().mergeFrom(other.internalGetOptions()); + bitField0_ |= 0x00000004; + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + name_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: + { + com.google.firestore.v1.Value m = + input.readMessage(com.google.firestore.v1.Value.parser(), extensionRegistry); + if (argsBuilder_ == null) { + ensureArgsIsMutable(); + args_.add(m); + } else { + argsBuilder_.addMessage(m); + } + break; + } // case 18 + case 26: + { + com.google.protobuf.MapEntry + options__ = + input.readMessage( + OptionsDefaultEntryHolder.defaultEntry.getParserForType(), + extensionRegistry); + internalGetMutableOptions() + .ensureBuilderMap() + .put(options__.getKey(), options__.getValue()); + bitField0_ |= 0x00000004; + break; + } // case 26 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private java.lang.Object name_ = ""; + /** + * + * + *
+     * The name of the function to evaluate.
+     *
+     * **Requires:**
+     *
+     * * must be in snake case (lower case with underscore separator).
+     * 
+ * + * string name = 1; + * + * @return The name. + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * The name of the function to evaluate.
+     *
+     * **Requires:**
+     *
+     * * must be in snake case (lower case with underscore separator).
+     * 
+ * + * string name = 1; + * + * @return The bytes for name. + */ + public com.google.protobuf.ByteString getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * The name of the function to evaluate.
+     *
+     * **Requires:**
+     *
+     * * must be in snake case (lower case with underscore separator).
+     * 
+ * + * string name = 1; + * + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * The name of the function to evaluate.
+     *
+     * **Requires:**
+     *
+     * * must be in snake case (lower case with underscore separator).
+     * 
+ * + * string name = 1; + * + * @return This builder for chaining. + */ + public Builder clearName() { + name_ = getDefaultInstance().getName(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + /** + * + * + *
+     * The name of the function to evaluate.
+     *
+     * **Requires:**
+     *
+     * * must be in snake case (lower case with underscore separator).
+     * 
+ * + * string name = 1; + * + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + private java.util.List args_ = java.util.Collections.emptyList(); + + private void ensureArgsIsMutable() { + if (!((bitField0_ & 0x00000002) != 0)) { + args_ = new java.util.ArrayList(args_); + bitField0_ |= 0x00000002; + } + } + + private com.google.protobuf.RepeatedFieldBuilderV3< + com.google.firestore.v1.Value, + com.google.firestore.v1.Value.Builder, + com.google.firestore.v1.ValueOrBuilder> + argsBuilder_; + + /** + * + * + *
+     * Ordered list of arguments the given function expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public java.util.List getArgsList() { + if (argsBuilder_ == null) { + return java.util.Collections.unmodifiableList(args_); + } else { + return argsBuilder_.getMessageList(); + } + } + /** + * + * + *
+     * Ordered list of arguments the given function expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public int getArgsCount() { + if (argsBuilder_ == null) { + return args_.size(); + } else { + return argsBuilder_.getCount(); + } + } + /** + * + * + *
+     * Ordered list of arguments the given function expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public com.google.firestore.v1.Value getArgs(int index) { + if (argsBuilder_ == null) { + return args_.get(index); + } else { + return argsBuilder_.getMessage(index); + } + } + /** + * + * + *
+     * Ordered list of arguments the given function expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public Builder setArgs(int index, com.google.firestore.v1.Value value) { + if (argsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureArgsIsMutable(); + args_.set(index, value); + onChanged(); + } else { + argsBuilder_.setMessage(index, value); + } + return this; + } + /** + * + * + *
+     * Ordered list of arguments the given function expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public Builder setArgs(int index, com.google.firestore.v1.Value.Builder builderForValue) { + if (argsBuilder_ == null) { + ensureArgsIsMutable(); + args_.set(index, builderForValue.build()); + onChanged(); + } else { + argsBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + /** + * + * + *
+     * Ordered list of arguments the given function expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public Builder addArgs(com.google.firestore.v1.Value value) { + if (argsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureArgsIsMutable(); + args_.add(value); + onChanged(); + } else { + argsBuilder_.addMessage(value); + } + return this; + } + /** + * + * + *
+     * Ordered list of arguments the given function expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public Builder addArgs(int index, com.google.firestore.v1.Value value) { + if (argsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureArgsIsMutable(); + args_.add(index, value); + onChanged(); + } else { + argsBuilder_.addMessage(index, value); + } + return this; + } + /** + * + * + *
+     * Ordered list of arguments the given function expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public Builder addArgs(com.google.firestore.v1.Value.Builder builderForValue) { + if (argsBuilder_ == null) { + ensureArgsIsMutable(); + args_.add(builderForValue.build()); + onChanged(); + } else { + argsBuilder_.addMessage(builderForValue.build()); + } + return this; + } + /** + * + * + *
+     * Ordered list of arguments the given function expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public Builder addArgs(int index, com.google.firestore.v1.Value.Builder builderForValue) { + if (argsBuilder_ == null) { + ensureArgsIsMutable(); + args_.add(index, builderForValue.build()); + onChanged(); + } else { + argsBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + /** + * + * + *
+     * Ordered list of arguments the given function expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public Builder addAllArgs(java.lang.Iterable values) { + if (argsBuilder_ == null) { + ensureArgsIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll(values, args_); + onChanged(); + } else { + argsBuilder_.addAllMessages(values); + } + return this; + } + /** + * + * + *
+     * Ordered list of arguments the given function expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public Builder clearArgs() { + if (argsBuilder_ == null) { + args_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000002); + onChanged(); + } else { + argsBuilder_.clear(); + } + return this; + } + /** + * + * + *
+     * Ordered list of arguments the given function expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public Builder removeArgs(int index) { + if (argsBuilder_ == null) { + ensureArgsIsMutable(); + args_.remove(index); + onChanged(); + } else { + argsBuilder_.remove(index); + } + return this; + } + /** + * + * + *
+     * Ordered list of arguments the given function expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public com.google.firestore.v1.Value.Builder getArgsBuilder(int index) { + return getArgsFieldBuilder().getBuilder(index); + } + /** + * + * + *
+     * Ordered list of arguments the given function expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public com.google.firestore.v1.ValueOrBuilder getArgsOrBuilder(int index) { + if (argsBuilder_ == null) { + return args_.get(index); + } else { + return argsBuilder_.getMessageOrBuilder(index); + } + } + /** + * + * + *
+     * Ordered list of arguments the given function expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public java.util.List getArgsOrBuilderList() { + if (argsBuilder_ != null) { + return argsBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(args_); + } + } + /** + * + * + *
+     * Ordered list of arguments the given function expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public com.google.firestore.v1.Value.Builder addArgsBuilder() { + return getArgsFieldBuilder().addBuilder(com.google.firestore.v1.Value.getDefaultInstance()); + } + /** + * + * + *
+     * Ordered list of arguments the given function expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public com.google.firestore.v1.Value.Builder addArgsBuilder(int index) { + return getArgsFieldBuilder() + .addBuilder(index, com.google.firestore.v1.Value.getDefaultInstance()); + } + /** + * + * + *
+     * Ordered list of arguments the given function expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public java.util.List getArgsBuilderList() { + return getArgsFieldBuilder().getBuilderList(); + } + + private com.google.protobuf.RepeatedFieldBuilderV3< + com.google.firestore.v1.Value, + com.google.firestore.v1.Value.Builder, + com.google.firestore.v1.ValueOrBuilder> + getArgsFieldBuilder() { + if (argsBuilder_ == null) { + argsBuilder_ = + new com.google.protobuf.RepeatedFieldBuilderV3< + com.google.firestore.v1.Value, + com.google.firestore.v1.Value.Builder, + com.google.firestore.v1.ValueOrBuilder>( + args_, ((bitField0_ & 0x00000002) != 0), getParentForChildren(), isClean()); + args_ = null; + } + return argsBuilder_; + } + + private static final class OptionsConverter + implements com.google.protobuf.MapFieldBuilder.Converter< + java.lang.String, + com.google.firestore.v1.ValueOrBuilder, + com.google.firestore.v1.Value> { + @java.lang.Override + public com.google.firestore.v1.Value build(com.google.firestore.v1.ValueOrBuilder val) { + if (val instanceof com.google.firestore.v1.Value) { + return (com.google.firestore.v1.Value) val; + } + return ((com.google.firestore.v1.Value.Builder) val).build(); + } + + @java.lang.Override + public com.google.protobuf.MapEntry + defaultEntry() { + return OptionsDefaultEntryHolder.defaultEntry; + } + }; + + private static final OptionsConverter optionsConverter = new OptionsConverter(); + + private com.google.protobuf.MapFieldBuilder< + java.lang.String, + com.google.firestore.v1.ValueOrBuilder, + com.google.firestore.v1.Value, + com.google.firestore.v1.Value.Builder> + options_; + + private com.google.protobuf.MapFieldBuilder< + java.lang.String, + com.google.firestore.v1.ValueOrBuilder, + com.google.firestore.v1.Value, + com.google.firestore.v1.Value.Builder> + internalGetOptions() { + if (options_ == null) { + return new com.google.protobuf.MapFieldBuilder<>(optionsConverter); + } + return options_; + } + + private com.google.protobuf.MapFieldBuilder< + java.lang.String, + com.google.firestore.v1.ValueOrBuilder, + com.google.firestore.v1.Value, + com.google.firestore.v1.Value.Builder> + internalGetMutableOptions() { + if (options_ == null) { + options_ = new com.google.protobuf.MapFieldBuilder<>(optionsConverter); + } + bitField0_ |= 0x00000004; + onChanged(); + return options_; + } + + public int getOptionsCount() { + return internalGetOptions().ensureBuilderMap().size(); + } + /** + * + * + *
+     * Optional named arguments that certain functions may support.
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + @java.lang.Override + public boolean containsOptions(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + return internalGetOptions().ensureBuilderMap().containsKey(key); + } + /** Use {@link #getOptionsMap()} instead. */ + @java.lang.Override + @java.lang.Deprecated + public java.util.Map getOptions() { + return getOptionsMap(); + } + /** + * + * + *
+     * Optional named arguments that certain functions may support.
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + @java.lang.Override + public java.util.Map getOptionsMap() { + return internalGetOptions().getImmutableMap(); + } + /** + * + * + *
+     * Optional named arguments that certain functions may support.
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + @java.lang.Override + public /* nullable */ com.google.firestore.v1.Value getOptionsOrDefault( + java.lang.String key, + /* nullable */ + com.google.firestore.v1.Value defaultValue) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = + internalGetMutableOptions().ensureBuilderMap(); + return map.containsKey(key) ? optionsConverter.build(map.get(key)) : defaultValue; + } + /** + * + * + *
+     * Optional named arguments that certain functions may support.
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + @java.lang.Override + public com.google.firestore.v1.Value getOptionsOrThrow(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = + internalGetMutableOptions().ensureBuilderMap(); + if (!map.containsKey(key)) { + throw new java.lang.IllegalArgumentException(); + } + return optionsConverter.build(map.get(key)); + } + + public Builder clearOptions() { + bitField0_ = (bitField0_ & ~0x00000004); + internalGetMutableOptions().clear(); + return this; + } + /** + * + * + *
+     * Optional named arguments that certain functions may support.
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + public Builder removeOptions(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + internalGetMutableOptions().ensureBuilderMap().remove(key); + return this; + } + /** Use alternate mutation accessors instead. */ + @java.lang.Deprecated + public java.util.Map getMutableOptions() { + bitField0_ |= 0x00000004; + return internalGetMutableOptions().ensureMessageMap(); + } + /** + * + * + *
+     * Optional named arguments that certain functions may support.
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + public Builder putOptions(java.lang.String key, com.google.firestore.v1.Value value) { + if (key == null) { + throw new NullPointerException("map key"); + } + if (value == null) { + throw new NullPointerException("map value"); + } + internalGetMutableOptions().ensureBuilderMap().put(key, value); + bitField0_ |= 0x00000004; + return this; + } + /** + * + * + *
+     * Optional named arguments that certain functions may support.
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + public Builder putAllOptions( + java.util.Map values) { + for (java.util.Map.Entry e : + values.entrySet()) { + if (e.getKey() == null || e.getValue() == null) { + throw new NullPointerException(); + } + } + internalGetMutableOptions().ensureBuilderMap().putAll(values); + bitField0_ |= 0x00000004; + return this; + } + /** + * + * + *
+     * Optional named arguments that certain functions may support.
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + public com.google.firestore.v1.Value.Builder putOptionsBuilderIfAbsent(java.lang.String key) { + java.util.Map builderMap = + internalGetMutableOptions().ensureBuilderMap(); + com.google.firestore.v1.ValueOrBuilder entry = builderMap.get(key); + if (entry == null) { + entry = com.google.firestore.v1.Value.newBuilder(); + builderMap.put(key, entry); + } + if (entry instanceof com.google.firestore.v1.Value) { + entry = ((com.google.firestore.v1.Value) entry).toBuilder(); + builderMap.put(key, entry); + } + return (com.google.firestore.v1.Value.Builder) entry; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.v1.Function) + } + + // @@protoc_insertion_point(class_scope:google.firestore.v1.Function) + private static final com.google.firestore.v1.Function DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.v1.Function(); + } + + public static com.google.firestore.v1.Function getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public Function parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.v1.Function getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/FunctionOrBuilder.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/FunctionOrBuilder.java new file mode 100644 index 000000000..e1ca51940 --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/FunctionOrBuilder.java @@ -0,0 +1,168 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/document.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +public interface FunctionOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.v1.Function) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * The name of the function to evaluate.
+   *
+   * **Requires:**
+   *
+   * * must be in snake case (lower case with underscore separator).
+   * 
+ * + * string name = 1; + * + * @return The name. + */ + java.lang.String getName(); + /** + * + * + *
+   * The name of the function to evaluate.
+   *
+   * **Requires:**
+   *
+   * * must be in snake case (lower case with underscore separator).
+   * 
+ * + * string name = 1; + * + * @return The bytes for name. + */ + com.google.protobuf.ByteString getNameBytes(); + + /** + * + * + *
+   * Ordered list of arguments the given function expects.
+   * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + java.util.List getArgsList(); + /** + * + * + *
+   * Ordered list of arguments the given function expects.
+   * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + com.google.firestore.v1.Value getArgs(int index); + /** + * + * + *
+   * Ordered list of arguments the given function expects.
+   * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + int getArgsCount(); + /** + * + * + *
+   * Ordered list of arguments the given function expects.
+   * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + java.util.List getArgsOrBuilderList(); + /** + * + * + *
+   * Ordered list of arguments the given function expects.
+   * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + com.google.firestore.v1.ValueOrBuilder getArgsOrBuilder(int index); + + /** + * + * + *
+   * Optional named arguments that certain functions may support.
+   * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + int getOptionsCount(); + /** + * + * + *
+   * Optional named arguments that certain functions may support.
+   * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + boolean containsOptions(java.lang.String key); + /** Use {@link #getOptionsMap()} instead. */ + @java.lang.Deprecated + java.util.Map getOptions(); + /** + * + * + *
+   * Optional named arguments that certain functions may support.
+   * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + java.util.Map getOptionsMap(); + /** + * + * + *
+   * Optional named arguments that certain functions may support.
+   * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + /* nullable */ + com.google.firestore.v1.Value getOptionsOrDefault( + java.lang.String key, + /* nullable */ + com.google.firestore.v1.Value defaultValue); + /** + * + * + *
+   * Optional named arguments that certain functions may support.
+   * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + com.google.firestore.v1.Value getOptionsOrThrow(java.lang.String key); +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/Pipeline.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/Pipeline.java new file mode 100644 index 000000000..5be2143a0 --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/Pipeline.java @@ -0,0 +1,2640 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/document.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +/** + * + * + *
+ * A Firestore query represented as an ordered list of operations / stages.
+ * 
+ * + * Protobuf type {@code google.firestore.v1.Pipeline} + */ +public final class Pipeline extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.v1.Pipeline) + PipelineOrBuilder { + private static final long serialVersionUID = 0L; + // Use Pipeline.newBuilder() to construct. + private Pipeline(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private Pipeline() { + stages_ = java.util.Collections.emptyList(); + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new Pipeline(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.DocumentProto + .internal_static_google_firestore_v1_Pipeline_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.DocumentProto + .internal_static_google_firestore_v1_Pipeline_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.Pipeline.class, com.google.firestore.v1.Pipeline.Builder.class); + } + + public interface StageOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.v1.Pipeline.Stage) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+     * The name of the stage to evaluate.
+     *
+     * **Requires:**
+     *
+     * * must be in snake case (lower case with underscore separator).
+     * 
+ * + * string name = 1; + * + * @return The name. + */ + java.lang.String getName(); + /** + * + * + *
+     * The name of the stage to evaluate.
+     *
+     * **Requires:**
+     *
+     * * must be in snake case (lower case with underscore separator).
+     * 
+ * + * string name = 1; + * + * @return The bytes for name. + */ + com.google.protobuf.ByteString getNameBytes(); + + /** + * + * + *
+     * Ordered list of arguments the given stage expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + java.util.List getArgsList(); + /** + * + * + *
+     * Ordered list of arguments the given stage expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + com.google.firestore.v1.Value getArgs(int index); + /** + * + * + *
+     * Ordered list of arguments the given stage expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + int getArgsCount(); + /** + * + * + *
+     * Ordered list of arguments the given stage expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + java.util.List getArgsOrBuilderList(); + /** + * + * + *
+     * Ordered list of arguments the given stage expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + com.google.firestore.v1.ValueOrBuilder getArgsOrBuilder(int index); + + /** + * + * + *
+     * Optional named arguments that certain functions may support.
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + int getOptionsCount(); + /** + * + * + *
+     * Optional named arguments that certain functions may support.
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + boolean containsOptions(java.lang.String key); + /** Use {@link #getOptionsMap()} instead. */ + @java.lang.Deprecated + java.util.Map getOptions(); + /** + * + * + *
+     * Optional named arguments that certain functions may support.
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + java.util.Map getOptionsMap(); + /** + * + * + *
+     * Optional named arguments that certain functions may support.
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + /* nullable */ + com.google.firestore.v1.Value getOptionsOrDefault( + java.lang.String key, + /* nullable */ + com.google.firestore.v1.Value defaultValue); + /** + * + * + *
+     * Optional named arguments that certain functions may support.
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + com.google.firestore.v1.Value getOptionsOrThrow(java.lang.String key); + } + /** + * + * + *
+   * A single operation within a pipeline.
+   *
+   * A stage is made up of a unique name, and a list of arguments. The exact
+   * number of arguments & types is dependent on the stage type.
+   *
+   * To give an example, the stage `filter(state = "MD")` would be encoded as:
+   *
+   * ```
+   * name: "filter"
+   * args {
+   *   function_value {
+   *     name: "eq"
+   *     args { field_reference_value: "state" }
+   *     args { string_value: "MD" }
+   *   }
+   * }
+   * ```
+   *
+   * See public documentation for the full list.
+   * 
+ * + * Protobuf type {@code google.firestore.v1.Pipeline.Stage} + */ + public static final class Stage extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.v1.Pipeline.Stage) + StageOrBuilder { + private static final long serialVersionUID = 0L; + // Use Stage.newBuilder() to construct. + private Stage(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private Stage() { + name_ = ""; + args_ = java.util.Collections.emptyList(); + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new Stage(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.DocumentProto + .internal_static_google_firestore_v1_Pipeline_Stage_descriptor; + } + + @SuppressWarnings({"rawtypes"}) + @java.lang.Override + protected com.google.protobuf.MapFieldReflectionAccessor internalGetMapFieldReflection( + int number) { + switch (number) { + case 3: + return internalGetOptions(); + default: + throw new RuntimeException("Invalid map field number: " + number); + } + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.DocumentProto + .internal_static_google_firestore_v1_Pipeline_Stage_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.Pipeline.Stage.class, + com.google.firestore.v1.Pipeline.Stage.Builder.class); + } + + public static final int NAME_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private volatile java.lang.Object name_ = ""; + /** + * + * + *
+     * The name of the stage to evaluate.
+     *
+     * **Requires:**
+     *
+     * * must be in snake case (lower case with underscore separator).
+     * 
+ * + * string name = 1; + * + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } + } + /** + * + * + *
+     * The name of the stage to evaluate.
+     *
+     * **Requires:**
+     *
+     * * must be in snake case (lower case with underscore separator).
+     * 
+ * + * string name = 1; + * + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int ARGS_FIELD_NUMBER = 2; + + @SuppressWarnings("serial") + private java.util.List args_; + /** + * + * + *
+     * Ordered list of arguments the given stage expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + @java.lang.Override + public java.util.List getArgsList() { + return args_; + } + /** + * + * + *
+     * Ordered list of arguments the given stage expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + @java.lang.Override + public java.util.List getArgsOrBuilderList() { + return args_; + } + /** + * + * + *
+     * Ordered list of arguments the given stage expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + @java.lang.Override + public int getArgsCount() { + return args_.size(); + } + /** + * + * + *
+     * Ordered list of arguments the given stage expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + @java.lang.Override + public com.google.firestore.v1.Value getArgs(int index) { + return args_.get(index); + } + /** + * + * + *
+     * Ordered list of arguments the given stage expects.
+     * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + @java.lang.Override + public com.google.firestore.v1.ValueOrBuilder getArgsOrBuilder(int index) { + return args_.get(index); + } + + public static final int OPTIONS_FIELD_NUMBER = 3; + + private static final class OptionsDefaultEntryHolder { + static final com.google.protobuf.MapEntry + defaultEntry = + com.google.protobuf.MapEntry + .newDefaultInstance( + com.google.firestore.v1.DocumentProto + .internal_static_google_firestore_v1_Pipeline_Stage_OptionsEntry_descriptor, + com.google.protobuf.WireFormat.FieldType.STRING, + "", + com.google.protobuf.WireFormat.FieldType.MESSAGE, + com.google.firestore.v1.Value.getDefaultInstance()); + } + + @SuppressWarnings("serial") + private com.google.protobuf.MapField options_; + + private com.google.protobuf.MapField + internalGetOptions() { + if (options_ == null) { + return com.google.protobuf.MapField.emptyMapField(OptionsDefaultEntryHolder.defaultEntry); + } + return options_; + } + + public int getOptionsCount() { + return internalGetOptions().getMap().size(); + } + /** + * + * + *
+     * Optional named arguments that certain functions may support.
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + @java.lang.Override + public boolean containsOptions(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + return internalGetOptions().getMap().containsKey(key); + } + /** Use {@link #getOptionsMap()} instead. */ + @java.lang.Override + @java.lang.Deprecated + public java.util.Map getOptions() { + return getOptionsMap(); + } + /** + * + * + *
+     * Optional named arguments that certain functions may support.
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + @java.lang.Override + public java.util.Map getOptionsMap() { + return internalGetOptions().getMap(); + } + /** + * + * + *
+     * Optional named arguments that certain functions may support.
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + @java.lang.Override + public /* nullable */ com.google.firestore.v1.Value getOptionsOrDefault( + java.lang.String key, + /* nullable */ + com.google.firestore.v1.Value defaultValue) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = + internalGetOptions().getMap(); + return map.containsKey(key) ? map.get(key) : defaultValue; + } + /** + * + * + *
+     * Optional named arguments that certain functions may support.
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + @java.lang.Override + public com.google.firestore.v1.Value getOptionsOrThrow(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = + internalGetOptions().getMap(); + if (!map.containsKey(key)) { + throw new java.lang.IllegalArgumentException(); + } + return map.get(key); + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + } + for (int i = 0; i < args_.size(); i++) { + output.writeMessage(2, args_.get(i)); + } + com.google.protobuf.GeneratedMessageV3.serializeStringMapTo( + output, internalGetOptions(), OptionsDefaultEntryHolder.defaultEntry, 3); + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + } + for (int i = 0; i < args_.size(); i++) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(2, args_.get(i)); + } + for (java.util.Map.Entry entry : + internalGetOptions().getMap().entrySet()) { + com.google.protobuf.MapEntry options__ = + OptionsDefaultEntryHolder.defaultEntry + .newBuilderForType() + .setKey(entry.getKey()) + .setValue(entry.getValue()) + .build(); + size += com.google.protobuf.CodedOutputStream.computeMessageSize(3, options__); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.v1.Pipeline.Stage)) { + return super.equals(obj); + } + com.google.firestore.v1.Pipeline.Stage other = (com.google.firestore.v1.Pipeline.Stage) obj; + + if (!getName().equals(other.getName())) return false; + if (!getArgsList().equals(other.getArgsList())) return false; + if (!internalGetOptions().equals(other.internalGetOptions())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + NAME_FIELD_NUMBER; + hash = (53 * hash) + getName().hashCode(); + if (getArgsCount() > 0) { + hash = (37 * hash) + ARGS_FIELD_NUMBER; + hash = (53 * hash) + getArgsList().hashCode(); + } + if (!internalGetOptions().getMap().isEmpty()) { + hash = (37 * hash) + OPTIONS_FIELD_NUMBER; + hash = (53 * hash) + internalGetOptions().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.v1.Pipeline.Stage parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.Pipeline.Stage parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.Pipeline.Stage parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.Pipeline.Stage parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.Pipeline.Stage parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.Pipeline.Stage parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.Pipeline.Stage parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.Pipeline.Stage parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.Pipeline.Stage parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.Pipeline.Stage parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.Pipeline.Stage parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.Pipeline.Stage parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.v1.Pipeline.Stage prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+     * A single operation within a pipeline.
+     *
+     * A stage is made up of a unique name, and a list of arguments. The exact
+     * number of arguments & types is dependent on the stage type.
+     *
+     * To give an example, the stage `filter(state = "MD")` would be encoded as:
+     *
+     * ```
+     * name: "filter"
+     * args {
+     *   function_value {
+     *     name: "eq"
+     *     args { field_reference_value: "state" }
+     *     args { string_value: "MD" }
+     *   }
+     * }
+     * ```
+     *
+     * See public documentation for the full list.
+     * 
+ * + * Protobuf type {@code google.firestore.v1.Pipeline.Stage} + */ + public static final class Builder + extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.v1.Pipeline.Stage) + com.google.firestore.v1.Pipeline.StageOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.DocumentProto + .internal_static_google_firestore_v1_Pipeline_Stage_descriptor; + } + + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapFieldReflectionAccessor internalGetMapFieldReflection( + int number) { + switch (number) { + case 3: + return internalGetOptions(); + default: + throw new RuntimeException("Invalid map field number: " + number); + } + } + + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapFieldReflectionAccessor internalGetMutableMapFieldReflection( + int number) { + switch (number) { + case 3: + return internalGetMutableOptions(); + default: + throw new RuntimeException("Invalid map field number: " + number); + } + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.DocumentProto + .internal_static_google_firestore_v1_Pipeline_Stage_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.Pipeline.Stage.class, + com.google.firestore.v1.Pipeline.Stage.Builder.class); + } + + // Construct using com.google.firestore.v1.Pipeline.Stage.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + name_ = ""; + if (argsBuilder_ == null) { + args_ = java.util.Collections.emptyList(); + } else { + args_ = null; + argsBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000002); + internalGetMutableOptions().clear(); + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.v1.DocumentProto + .internal_static_google_firestore_v1_Pipeline_Stage_descriptor; + } + + @java.lang.Override + public com.google.firestore.v1.Pipeline.Stage getDefaultInstanceForType() { + return com.google.firestore.v1.Pipeline.Stage.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.v1.Pipeline.Stage build() { + com.google.firestore.v1.Pipeline.Stage result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.v1.Pipeline.Stage buildPartial() { + com.google.firestore.v1.Pipeline.Stage result = + new com.google.firestore.v1.Pipeline.Stage(this); + buildPartialRepeatedFields(result); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartialRepeatedFields(com.google.firestore.v1.Pipeline.Stage result) { + if (argsBuilder_ == null) { + if (((bitField0_ & 0x00000002) != 0)) { + args_ = java.util.Collections.unmodifiableList(args_); + bitField0_ = (bitField0_ & ~0x00000002); + } + result.args_ = args_; + } else { + result.args_ = argsBuilder_.build(); + } + } + + private void buildPartial0(com.google.firestore.v1.Pipeline.Stage result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.name_ = name_; + } + if (((from_bitField0_ & 0x00000004) != 0)) { + result.options_ = internalGetOptions().build(OptionsDefaultEntryHolder.defaultEntry); + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, + java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.v1.Pipeline.Stage) { + return mergeFrom((com.google.firestore.v1.Pipeline.Stage) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.v1.Pipeline.Stage other) { + if (other == com.google.firestore.v1.Pipeline.Stage.getDefaultInstance()) return this; + if (!other.getName().isEmpty()) { + name_ = other.name_; + bitField0_ |= 0x00000001; + onChanged(); + } + if (argsBuilder_ == null) { + if (!other.args_.isEmpty()) { + if (args_.isEmpty()) { + args_ = other.args_; + bitField0_ = (bitField0_ & ~0x00000002); + } else { + ensureArgsIsMutable(); + args_.addAll(other.args_); + } + onChanged(); + } + } else { + if (!other.args_.isEmpty()) { + if (argsBuilder_.isEmpty()) { + argsBuilder_.dispose(); + argsBuilder_ = null; + args_ = other.args_; + bitField0_ = (bitField0_ & ~0x00000002); + argsBuilder_ = + com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders + ? getArgsFieldBuilder() + : null; + } else { + argsBuilder_.addAllMessages(other.args_); + } + } + } + internalGetMutableOptions().mergeFrom(other.internalGetOptions()); + bitField0_ |= 0x00000004; + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + name_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: + { + com.google.firestore.v1.Value m = + input.readMessage(com.google.firestore.v1.Value.parser(), extensionRegistry); + if (argsBuilder_ == null) { + ensureArgsIsMutable(); + args_.add(m); + } else { + argsBuilder_.addMessage(m); + } + break; + } // case 18 + case 26: + { + com.google.protobuf.MapEntry + options__ = + input.readMessage( + OptionsDefaultEntryHolder.defaultEntry.getParserForType(), + extensionRegistry); + internalGetMutableOptions() + .ensureBuilderMap() + .put(options__.getKey(), options__.getValue()); + bitField0_ |= 0x00000004; + break; + } // case 26 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private java.lang.Object name_ = ""; + /** + * + * + *
+       * The name of the stage to evaluate.
+       *
+       * **Requires:**
+       *
+       * * must be in snake case (lower case with underscore separator).
+       * 
+ * + * string name = 1; + * + * @return The name. + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+       * The name of the stage to evaluate.
+       *
+       * **Requires:**
+       *
+       * * must be in snake case (lower case with underscore separator).
+       * 
+ * + * string name = 1; + * + * @return The bytes for name. + */ + public com.google.protobuf.ByteString getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+       * The name of the stage to evaluate.
+       *
+       * **Requires:**
+       *
+       * * must be in snake case (lower case with underscore separator).
+       * 
+ * + * string name = 1; + * + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+       * The name of the stage to evaluate.
+       *
+       * **Requires:**
+       *
+       * * must be in snake case (lower case with underscore separator).
+       * 
+ * + * string name = 1; + * + * @return This builder for chaining. + */ + public Builder clearName() { + name_ = getDefaultInstance().getName(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + /** + * + * + *
+       * The name of the stage to evaluate.
+       *
+       * **Requires:**
+       *
+       * * must be in snake case (lower case with underscore separator).
+       * 
+ * + * string name = 1; + * + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + name_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + + private java.util.List args_ = + java.util.Collections.emptyList(); + + private void ensureArgsIsMutable() { + if (!((bitField0_ & 0x00000002) != 0)) { + args_ = new java.util.ArrayList(args_); + bitField0_ |= 0x00000002; + } + } + + private com.google.protobuf.RepeatedFieldBuilderV3< + com.google.firestore.v1.Value, + com.google.firestore.v1.Value.Builder, + com.google.firestore.v1.ValueOrBuilder> + argsBuilder_; + + /** + * + * + *
+       * Ordered list of arguments the given stage expects.
+       * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public java.util.List getArgsList() { + if (argsBuilder_ == null) { + return java.util.Collections.unmodifiableList(args_); + } else { + return argsBuilder_.getMessageList(); + } + } + /** + * + * + *
+       * Ordered list of arguments the given stage expects.
+       * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public int getArgsCount() { + if (argsBuilder_ == null) { + return args_.size(); + } else { + return argsBuilder_.getCount(); + } + } + /** + * + * + *
+       * Ordered list of arguments the given stage expects.
+       * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public com.google.firestore.v1.Value getArgs(int index) { + if (argsBuilder_ == null) { + return args_.get(index); + } else { + return argsBuilder_.getMessage(index); + } + } + /** + * + * + *
+       * Ordered list of arguments the given stage expects.
+       * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public Builder setArgs(int index, com.google.firestore.v1.Value value) { + if (argsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureArgsIsMutable(); + args_.set(index, value); + onChanged(); + } else { + argsBuilder_.setMessage(index, value); + } + return this; + } + /** + * + * + *
+       * Ordered list of arguments the given stage expects.
+       * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public Builder setArgs(int index, com.google.firestore.v1.Value.Builder builderForValue) { + if (argsBuilder_ == null) { + ensureArgsIsMutable(); + args_.set(index, builderForValue.build()); + onChanged(); + } else { + argsBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + /** + * + * + *
+       * Ordered list of arguments the given stage expects.
+       * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public Builder addArgs(com.google.firestore.v1.Value value) { + if (argsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureArgsIsMutable(); + args_.add(value); + onChanged(); + } else { + argsBuilder_.addMessage(value); + } + return this; + } + /** + * + * + *
+       * Ordered list of arguments the given stage expects.
+       * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public Builder addArgs(int index, com.google.firestore.v1.Value value) { + if (argsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureArgsIsMutable(); + args_.add(index, value); + onChanged(); + } else { + argsBuilder_.addMessage(index, value); + } + return this; + } + /** + * + * + *
+       * Ordered list of arguments the given stage expects.
+       * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public Builder addArgs(com.google.firestore.v1.Value.Builder builderForValue) { + if (argsBuilder_ == null) { + ensureArgsIsMutable(); + args_.add(builderForValue.build()); + onChanged(); + } else { + argsBuilder_.addMessage(builderForValue.build()); + } + return this; + } + /** + * + * + *
+       * Ordered list of arguments the given stage expects.
+       * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public Builder addArgs(int index, com.google.firestore.v1.Value.Builder builderForValue) { + if (argsBuilder_ == null) { + ensureArgsIsMutable(); + args_.add(index, builderForValue.build()); + onChanged(); + } else { + argsBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + /** + * + * + *
+       * Ordered list of arguments the given stage expects.
+       * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public Builder addAllArgs( + java.lang.Iterable values) { + if (argsBuilder_ == null) { + ensureArgsIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll(values, args_); + onChanged(); + } else { + argsBuilder_.addAllMessages(values); + } + return this; + } + /** + * + * + *
+       * Ordered list of arguments the given stage expects.
+       * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public Builder clearArgs() { + if (argsBuilder_ == null) { + args_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000002); + onChanged(); + } else { + argsBuilder_.clear(); + } + return this; + } + /** + * + * + *
+       * Ordered list of arguments the given stage expects.
+       * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public Builder removeArgs(int index) { + if (argsBuilder_ == null) { + ensureArgsIsMutable(); + args_.remove(index); + onChanged(); + } else { + argsBuilder_.remove(index); + } + return this; + } + /** + * + * + *
+       * Ordered list of arguments the given stage expects.
+       * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public com.google.firestore.v1.Value.Builder getArgsBuilder(int index) { + return getArgsFieldBuilder().getBuilder(index); + } + /** + * + * + *
+       * Ordered list of arguments the given stage expects.
+       * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public com.google.firestore.v1.ValueOrBuilder getArgsOrBuilder(int index) { + if (argsBuilder_ == null) { + return args_.get(index); + } else { + return argsBuilder_.getMessageOrBuilder(index); + } + } + /** + * + * + *
+       * Ordered list of arguments the given stage expects.
+       * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public java.util.List + getArgsOrBuilderList() { + if (argsBuilder_ != null) { + return argsBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(args_); + } + } + /** + * + * + *
+       * Ordered list of arguments the given stage expects.
+       * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public com.google.firestore.v1.Value.Builder addArgsBuilder() { + return getArgsFieldBuilder().addBuilder(com.google.firestore.v1.Value.getDefaultInstance()); + } + /** + * + * + *
+       * Ordered list of arguments the given stage expects.
+       * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public com.google.firestore.v1.Value.Builder addArgsBuilder(int index) { + return getArgsFieldBuilder() + .addBuilder(index, com.google.firestore.v1.Value.getDefaultInstance()); + } + /** + * + * + *
+       * Ordered list of arguments the given stage expects.
+       * 
+ * + * repeated .google.firestore.v1.Value args = 2; + */ + public java.util.List getArgsBuilderList() { + return getArgsFieldBuilder().getBuilderList(); + } + + private com.google.protobuf.RepeatedFieldBuilderV3< + com.google.firestore.v1.Value, + com.google.firestore.v1.Value.Builder, + com.google.firestore.v1.ValueOrBuilder> + getArgsFieldBuilder() { + if (argsBuilder_ == null) { + argsBuilder_ = + new com.google.protobuf.RepeatedFieldBuilderV3< + com.google.firestore.v1.Value, + com.google.firestore.v1.Value.Builder, + com.google.firestore.v1.ValueOrBuilder>( + args_, ((bitField0_ & 0x00000002) != 0), getParentForChildren(), isClean()); + args_ = null; + } + return argsBuilder_; + } + + private static final class OptionsConverter + implements com.google.protobuf.MapFieldBuilder.Converter< + java.lang.String, + com.google.firestore.v1.ValueOrBuilder, + com.google.firestore.v1.Value> { + @java.lang.Override + public com.google.firestore.v1.Value build(com.google.firestore.v1.ValueOrBuilder val) { + if (val instanceof com.google.firestore.v1.Value) { + return (com.google.firestore.v1.Value) val; + } + return ((com.google.firestore.v1.Value.Builder) val).build(); + } + + @java.lang.Override + public com.google.protobuf.MapEntry + defaultEntry() { + return OptionsDefaultEntryHolder.defaultEntry; + } + }; + + private static final OptionsConverter optionsConverter = new OptionsConverter(); + + private com.google.protobuf.MapFieldBuilder< + java.lang.String, + com.google.firestore.v1.ValueOrBuilder, + com.google.firestore.v1.Value, + com.google.firestore.v1.Value.Builder> + options_; + + private com.google.protobuf.MapFieldBuilder< + java.lang.String, + com.google.firestore.v1.ValueOrBuilder, + com.google.firestore.v1.Value, + com.google.firestore.v1.Value.Builder> + internalGetOptions() { + if (options_ == null) { + return new com.google.protobuf.MapFieldBuilder<>(optionsConverter); + } + return options_; + } + + private com.google.protobuf.MapFieldBuilder< + java.lang.String, + com.google.firestore.v1.ValueOrBuilder, + com.google.firestore.v1.Value, + com.google.firestore.v1.Value.Builder> + internalGetMutableOptions() { + if (options_ == null) { + options_ = new com.google.protobuf.MapFieldBuilder<>(optionsConverter); + } + bitField0_ |= 0x00000004; + onChanged(); + return options_; + } + + public int getOptionsCount() { + return internalGetOptions().ensureBuilderMap().size(); + } + /** + * + * + *
+       * Optional named arguments that certain functions may support.
+       * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + @java.lang.Override + public boolean containsOptions(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + return internalGetOptions().ensureBuilderMap().containsKey(key); + } + /** Use {@link #getOptionsMap()} instead. */ + @java.lang.Override + @java.lang.Deprecated + public java.util.Map getOptions() { + return getOptionsMap(); + } + /** + * + * + *
+       * Optional named arguments that certain functions may support.
+       * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + @java.lang.Override + public java.util.Map getOptionsMap() { + return internalGetOptions().getImmutableMap(); + } + /** + * + * + *
+       * Optional named arguments that certain functions may support.
+       * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + @java.lang.Override + public /* nullable */ com.google.firestore.v1.Value getOptionsOrDefault( + java.lang.String key, + /* nullable */ + com.google.firestore.v1.Value defaultValue) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = + internalGetMutableOptions().ensureBuilderMap(); + return map.containsKey(key) ? optionsConverter.build(map.get(key)) : defaultValue; + } + /** + * + * + *
+       * Optional named arguments that certain functions may support.
+       * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + @java.lang.Override + public com.google.firestore.v1.Value getOptionsOrThrow(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = + internalGetMutableOptions().ensureBuilderMap(); + if (!map.containsKey(key)) { + throw new java.lang.IllegalArgumentException(); + } + return optionsConverter.build(map.get(key)); + } + + public Builder clearOptions() { + bitField0_ = (bitField0_ & ~0x00000004); + internalGetMutableOptions().clear(); + return this; + } + /** + * + * + *
+       * Optional named arguments that certain functions may support.
+       * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + public Builder removeOptions(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + internalGetMutableOptions().ensureBuilderMap().remove(key); + return this; + } + /** Use alternate mutation accessors instead. */ + @java.lang.Deprecated + public java.util.Map getMutableOptions() { + bitField0_ |= 0x00000004; + return internalGetMutableOptions().ensureMessageMap(); + } + /** + * + * + *
+       * Optional named arguments that certain functions may support.
+       * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + public Builder putOptions(java.lang.String key, com.google.firestore.v1.Value value) { + if (key == null) { + throw new NullPointerException("map key"); + } + if (value == null) { + throw new NullPointerException("map value"); + } + internalGetMutableOptions().ensureBuilderMap().put(key, value); + bitField0_ |= 0x00000004; + return this; + } + /** + * + * + *
+       * Optional named arguments that certain functions may support.
+       * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + public Builder putAllOptions( + java.util.Map values) { + for (java.util.Map.Entry e : + values.entrySet()) { + if (e.getKey() == null || e.getValue() == null) { + throw new NullPointerException(); + } + } + internalGetMutableOptions().ensureBuilderMap().putAll(values); + bitField0_ |= 0x00000004; + return this; + } + /** + * + * + *
+       * Optional named arguments that certain functions may support.
+       * 
+ * + * map<string, .google.firestore.v1.Value> options = 3; + */ + public com.google.firestore.v1.Value.Builder putOptionsBuilderIfAbsent(java.lang.String key) { + java.util.Map builderMap = + internalGetMutableOptions().ensureBuilderMap(); + com.google.firestore.v1.ValueOrBuilder entry = builderMap.get(key); + if (entry == null) { + entry = com.google.firestore.v1.Value.newBuilder(); + builderMap.put(key, entry); + } + if (entry instanceof com.google.firestore.v1.Value) { + entry = ((com.google.firestore.v1.Value) entry).toBuilder(); + builderMap.put(key, entry); + } + return (com.google.firestore.v1.Value.Builder) entry; + } + + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.v1.Pipeline.Stage) + } + + // @@protoc_insertion_point(class_scope:google.firestore.v1.Pipeline.Stage) + private static final com.google.firestore.v1.Pipeline.Stage DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.v1.Pipeline.Stage(); + } + + public static com.google.firestore.v1.Pipeline.Stage getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public Stage parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException() + .setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.v1.Pipeline.Stage getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + } + + public static final int STAGES_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private java.util.List stages_; + /** + * + * + *
+   * Ordered list of stages to evaluate.
+   * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + @java.lang.Override + public java.util.List getStagesList() { + return stages_; + } + /** + * + * + *
+   * Ordered list of stages to evaluate.
+   * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + @java.lang.Override + public java.util.List + getStagesOrBuilderList() { + return stages_; + } + /** + * + * + *
+   * Ordered list of stages to evaluate.
+   * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + @java.lang.Override + public int getStagesCount() { + return stages_.size(); + } + /** + * + * + *
+   * Ordered list of stages to evaluate.
+   * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + @java.lang.Override + public com.google.firestore.v1.Pipeline.Stage getStages(int index) { + return stages_.get(index); + } + /** + * + * + *
+   * Ordered list of stages to evaluate.
+   * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + @java.lang.Override + public com.google.firestore.v1.Pipeline.StageOrBuilder getStagesOrBuilder(int index) { + return stages_.get(index); + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + for (int i = 0; i < stages_.size(); i++) { + output.writeMessage(1, stages_.get(i)); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + for (int i = 0; i < stages_.size(); i++) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(1, stages_.get(i)); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.v1.Pipeline)) { + return super.equals(obj); + } + com.google.firestore.v1.Pipeline other = (com.google.firestore.v1.Pipeline) obj; + + if (!getStagesList().equals(other.getStagesList())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (getStagesCount() > 0) { + hash = (37 * hash) + STAGES_FIELD_NUMBER; + hash = (53 * hash) + getStagesList().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.v1.Pipeline parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.Pipeline parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.Pipeline parseFrom(com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.Pipeline parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.Pipeline parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.Pipeline parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.Pipeline parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.Pipeline parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.Pipeline parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.Pipeline parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.Pipeline parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.Pipeline parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.v1.Pipeline prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * A Firestore query represented as an ordered list of operations / stages.
+   * 
+ * + * Protobuf type {@code google.firestore.v1.Pipeline} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.v1.Pipeline) + com.google.firestore.v1.PipelineOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.DocumentProto + .internal_static_google_firestore_v1_Pipeline_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.DocumentProto + .internal_static_google_firestore_v1_Pipeline_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.Pipeline.class, + com.google.firestore.v1.Pipeline.Builder.class); + } + + // Construct using com.google.firestore.v1.Pipeline.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + if (stagesBuilder_ == null) { + stages_ = java.util.Collections.emptyList(); + } else { + stages_ = null; + stagesBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000001); + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.v1.DocumentProto + .internal_static_google_firestore_v1_Pipeline_descriptor; + } + + @java.lang.Override + public com.google.firestore.v1.Pipeline getDefaultInstanceForType() { + return com.google.firestore.v1.Pipeline.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.v1.Pipeline build() { + com.google.firestore.v1.Pipeline result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.v1.Pipeline buildPartial() { + com.google.firestore.v1.Pipeline result = new com.google.firestore.v1.Pipeline(this); + buildPartialRepeatedFields(result); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartialRepeatedFields(com.google.firestore.v1.Pipeline result) { + if (stagesBuilder_ == null) { + if (((bitField0_ & 0x00000001) != 0)) { + stages_ = java.util.Collections.unmodifiableList(stages_); + bitField0_ = (bitField0_ & ~0x00000001); + } + result.stages_ = stages_; + } else { + result.stages_ = stagesBuilder_.build(); + } + } + + private void buildPartial0(com.google.firestore.v1.Pipeline result) { + int from_bitField0_ = bitField0_; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.v1.Pipeline) { + return mergeFrom((com.google.firestore.v1.Pipeline) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.v1.Pipeline other) { + if (other == com.google.firestore.v1.Pipeline.getDefaultInstance()) return this; + if (stagesBuilder_ == null) { + if (!other.stages_.isEmpty()) { + if (stages_.isEmpty()) { + stages_ = other.stages_; + bitField0_ = (bitField0_ & ~0x00000001); + } else { + ensureStagesIsMutable(); + stages_.addAll(other.stages_); + } + onChanged(); + } + } else { + if (!other.stages_.isEmpty()) { + if (stagesBuilder_.isEmpty()) { + stagesBuilder_.dispose(); + stagesBuilder_ = null; + stages_ = other.stages_; + bitField0_ = (bitField0_ & ~0x00000001); + stagesBuilder_ = + com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders + ? getStagesFieldBuilder() + : null; + } else { + stagesBuilder_.addAllMessages(other.stages_); + } + } + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + com.google.firestore.v1.Pipeline.Stage m = + input.readMessage( + com.google.firestore.v1.Pipeline.Stage.parser(), extensionRegistry); + if (stagesBuilder_ == null) { + ensureStagesIsMutable(); + stages_.add(m); + } else { + stagesBuilder_.addMessage(m); + } + break; + } // case 10 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private java.util.List stages_ = + java.util.Collections.emptyList(); + + private void ensureStagesIsMutable() { + if (!((bitField0_ & 0x00000001) != 0)) { + stages_ = new java.util.ArrayList(stages_); + bitField0_ |= 0x00000001; + } + } + + private com.google.protobuf.RepeatedFieldBuilderV3< + com.google.firestore.v1.Pipeline.Stage, + com.google.firestore.v1.Pipeline.Stage.Builder, + com.google.firestore.v1.Pipeline.StageOrBuilder> + stagesBuilder_; + + /** + * + * + *
+     * Ordered list of stages to evaluate.
+     * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + public java.util.List getStagesList() { + if (stagesBuilder_ == null) { + return java.util.Collections.unmodifiableList(stages_); + } else { + return stagesBuilder_.getMessageList(); + } + } + /** + * + * + *
+     * Ordered list of stages to evaluate.
+     * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + public int getStagesCount() { + if (stagesBuilder_ == null) { + return stages_.size(); + } else { + return stagesBuilder_.getCount(); + } + } + /** + * + * + *
+     * Ordered list of stages to evaluate.
+     * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + public com.google.firestore.v1.Pipeline.Stage getStages(int index) { + if (stagesBuilder_ == null) { + return stages_.get(index); + } else { + return stagesBuilder_.getMessage(index); + } + } + /** + * + * + *
+     * Ordered list of stages to evaluate.
+     * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + public Builder setStages(int index, com.google.firestore.v1.Pipeline.Stage value) { + if (stagesBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureStagesIsMutable(); + stages_.set(index, value); + onChanged(); + } else { + stagesBuilder_.setMessage(index, value); + } + return this; + } + /** + * + * + *
+     * Ordered list of stages to evaluate.
+     * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + public Builder setStages( + int index, com.google.firestore.v1.Pipeline.Stage.Builder builderForValue) { + if (stagesBuilder_ == null) { + ensureStagesIsMutable(); + stages_.set(index, builderForValue.build()); + onChanged(); + } else { + stagesBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + /** + * + * + *
+     * Ordered list of stages to evaluate.
+     * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + public Builder addStages(com.google.firestore.v1.Pipeline.Stage value) { + if (stagesBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureStagesIsMutable(); + stages_.add(value); + onChanged(); + } else { + stagesBuilder_.addMessage(value); + } + return this; + } + /** + * + * + *
+     * Ordered list of stages to evaluate.
+     * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + public Builder addStages(int index, com.google.firestore.v1.Pipeline.Stage value) { + if (stagesBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureStagesIsMutable(); + stages_.add(index, value); + onChanged(); + } else { + stagesBuilder_.addMessage(index, value); + } + return this; + } + /** + * + * + *
+     * Ordered list of stages to evaluate.
+     * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + public Builder addStages(com.google.firestore.v1.Pipeline.Stage.Builder builderForValue) { + if (stagesBuilder_ == null) { + ensureStagesIsMutable(); + stages_.add(builderForValue.build()); + onChanged(); + } else { + stagesBuilder_.addMessage(builderForValue.build()); + } + return this; + } + /** + * + * + *
+     * Ordered list of stages to evaluate.
+     * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + public Builder addStages( + int index, com.google.firestore.v1.Pipeline.Stage.Builder builderForValue) { + if (stagesBuilder_ == null) { + ensureStagesIsMutable(); + stages_.add(index, builderForValue.build()); + onChanged(); + } else { + stagesBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + /** + * + * + *
+     * Ordered list of stages to evaluate.
+     * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + public Builder addAllStages( + java.lang.Iterable values) { + if (stagesBuilder_ == null) { + ensureStagesIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll(values, stages_); + onChanged(); + } else { + stagesBuilder_.addAllMessages(values); + } + return this; + } + /** + * + * + *
+     * Ordered list of stages to evaluate.
+     * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + public Builder clearStages() { + if (stagesBuilder_ == null) { + stages_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + } else { + stagesBuilder_.clear(); + } + return this; + } + /** + * + * + *
+     * Ordered list of stages to evaluate.
+     * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + public Builder removeStages(int index) { + if (stagesBuilder_ == null) { + ensureStagesIsMutable(); + stages_.remove(index); + onChanged(); + } else { + stagesBuilder_.remove(index); + } + return this; + } + /** + * + * + *
+     * Ordered list of stages to evaluate.
+     * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + public com.google.firestore.v1.Pipeline.Stage.Builder getStagesBuilder(int index) { + return getStagesFieldBuilder().getBuilder(index); + } + /** + * + * + *
+     * Ordered list of stages to evaluate.
+     * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + public com.google.firestore.v1.Pipeline.StageOrBuilder getStagesOrBuilder(int index) { + if (stagesBuilder_ == null) { + return stages_.get(index); + } else { + return stagesBuilder_.getMessageOrBuilder(index); + } + } + /** + * + * + *
+     * Ordered list of stages to evaluate.
+     * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + public java.util.List + getStagesOrBuilderList() { + if (stagesBuilder_ != null) { + return stagesBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(stages_); + } + } + /** + * + * + *
+     * Ordered list of stages to evaluate.
+     * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + public com.google.firestore.v1.Pipeline.Stage.Builder addStagesBuilder() { + return getStagesFieldBuilder() + .addBuilder(com.google.firestore.v1.Pipeline.Stage.getDefaultInstance()); + } + /** + * + * + *
+     * Ordered list of stages to evaluate.
+     * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + public com.google.firestore.v1.Pipeline.Stage.Builder addStagesBuilder(int index) { + return getStagesFieldBuilder() + .addBuilder(index, com.google.firestore.v1.Pipeline.Stage.getDefaultInstance()); + } + /** + * + * + *
+     * Ordered list of stages to evaluate.
+     * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + public java.util.List getStagesBuilderList() { + return getStagesFieldBuilder().getBuilderList(); + } + + private com.google.protobuf.RepeatedFieldBuilderV3< + com.google.firestore.v1.Pipeline.Stage, + com.google.firestore.v1.Pipeline.Stage.Builder, + com.google.firestore.v1.Pipeline.StageOrBuilder> + getStagesFieldBuilder() { + if (stagesBuilder_ == null) { + stagesBuilder_ = + new com.google.protobuf.RepeatedFieldBuilderV3< + com.google.firestore.v1.Pipeline.Stage, + com.google.firestore.v1.Pipeline.Stage.Builder, + com.google.firestore.v1.Pipeline.StageOrBuilder>( + stages_, ((bitField0_ & 0x00000001) != 0), getParentForChildren(), isClean()); + stages_ = null; + } + return stagesBuilder_; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.v1.Pipeline) + } + + // @@protoc_insertion_point(class_scope:google.firestore.v1.Pipeline) + private static final com.google.firestore.v1.Pipeline DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.v1.Pipeline(); + } + + public static com.google.firestore.v1.Pipeline getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public Pipeline parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.v1.Pipeline getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/PipelineOrBuilder.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/PipelineOrBuilder.java new file mode 100644 index 000000000..3373b5e73 --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/PipelineOrBuilder.java @@ -0,0 +1,78 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/document.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +public interface PipelineOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.v1.Pipeline) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * Ordered list of stages to evaluate.
+   * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + java.util.List getStagesList(); + /** + * + * + *
+   * Ordered list of stages to evaluate.
+   * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + com.google.firestore.v1.Pipeline.Stage getStages(int index); + /** + * + * + *
+   * Ordered list of stages to evaluate.
+   * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + int getStagesCount(); + /** + * + * + *
+   * Ordered list of stages to evaluate.
+   * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + java.util.List + getStagesOrBuilderList(); + /** + * + * + *
+   * Ordered list of stages to evaluate.
+   * 
+ * + * repeated .google.firestore.v1.Pipeline.Stage stages = 1; + */ + com.google.firestore.v1.Pipeline.StageOrBuilder getStagesOrBuilder(int index); +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/PipelineProto.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/PipelineProto.java new file mode 100644 index 000000000..816d3fe3f --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/PipelineProto.java @@ -0,0 +1,87 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/pipeline.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +public final class PipelineProto { + private PipelineProto() {} + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistryLite registry) {} + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions((com.google.protobuf.ExtensionRegistryLite) registry); + } + + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_v1_StructuredPipeline_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_v1_StructuredPipeline_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_v1_StructuredPipeline_OptionsEntry_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_v1_StructuredPipeline_OptionsEntry_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + return descriptor; + } + + private static com.google.protobuf.Descriptors.FileDescriptor descriptor; + + static { + java.lang.String[] descriptorData = { + "\n\"google/firestore/v1/pipeline.proto\022\023go" + + "ogle.firestore.v1\032\"google/firestore/v1/d" + + "ocument.proto\"\330\001\n\022StructuredPipeline\022/\n\010" + + "pipeline\030\001 \001(\0132\035.google.firestore.v1.Pip" + + "eline\022E\n\007options\030\002 \003(\01324.google.firestor" + + "e.v1.StructuredPipeline.OptionsEntry\032J\n\014" + + "OptionsEntry\022\013\n\003key\030\001 \001(\t\022)\n\005value\030\002 \001(\013" + + "2\032.google.firestore.v1.Value:\0028\001B\210\001\n\027com" + + ".google.firestore.v1B\rPipelineProtoP\001\242\002\004" + + "GCFS\252\002\031Google.Cloud.Firestore.V1\312\002\031Googl" + + "e\\Cloud\\Firestore\\V1\352\002\034Google::Cloud::Fi" + + "restore::V1b\006proto3" + }; + descriptor = + com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( + descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + com.google.firestore.v1.DocumentProto.getDescriptor(), + }); + internal_static_google_firestore_v1_StructuredPipeline_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_google_firestore_v1_StructuredPipeline_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_v1_StructuredPipeline_descriptor, + new java.lang.String[] { + "Pipeline", "Options", + }); + internal_static_google_firestore_v1_StructuredPipeline_OptionsEntry_descriptor = + internal_static_google_firestore_v1_StructuredPipeline_descriptor.getNestedTypes().get(0); + internal_static_google_firestore_v1_StructuredPipeline_OptionsEntry_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_v1_StructuredPipeline_OptionsEntry_descriptor, + new java.lang.String[] { + "Key", "Value", + }); + com.google.firestore.v1.DocumentProto.getDescriptor(); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/PlanSummary.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/PlanSummary.java new file mode 100644 index 000000000..43bafcd6f --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/PlanSummary.java @@ -0,0 +1,1019 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/query_profile.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +/** + * + * + *
+ * Planning phase information for the query.
+ * 
+ * + * Protobuf type {@code google.firestore.v1.PlanSummary} + */ +public final class PlanSummary extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.v1.PlanSummary) + PlanSummaryOrBuilder { + private static final long serialVersionUID = 0L; + // Use PlanSummary.newBuilder() to construct. + private PlanSummary(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private PlanSummary() { + indexesUsed_ = java.util.Collections.emptyList(); + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new PlanSummary(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_PlanSummary_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_PlanSummary_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.PlanSummary.class, + com.google.firestore.v1.PlanSummary.Builder.class); + } + + public static final int INDEXES_USED_FIELD_NUMBER = 1; + + @SuppressWarnings("serial") + private java.util.List indexesUsed_; + /** + * + * + *
+   * The indexes selected for the query. For example:
+   *  [
+   *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+   *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+   *  ]
+   * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + @java.lang.Override + public java.util.List getIndexesUsedList() { + return indexesUsed_; + } + /** + * + * + *
+   * The indexes selected for the query. For example:
+   *  [
+   *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+   *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+   *  ]
+   * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + @java.lang.Override + public java.util.List + getIndexesUsedOrBuilderList() { + return indexesUsed_; + } + /** + * + * + *
+   * The indexes selected for the query. For example:
+   *  [
+   *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+   *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+   *  ]
+   * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + @java.lang.Override + public int getIndexesUsedCount() { + return indexesUsed_.size(); + } + /** + * + * + *
+   * The indexes selected for the query. For example:
+   *  [
+   *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+   *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+   *  ]
+   * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + @java.lang.Override + public com.google.protobuf.Struct getIndexesUsed(int index) { + return indexesUsed_.get(index); + } + /** + * + * + *
+   * The indexes selected for the query. For example:
+   *  [
+   *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+   *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+   *  ]
+   * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + @java.lang.Override + public com.google.protobuf.StructOrBuilder getIndexesUsedOrBuilder(int index) { + return indexesUsed_.get(index); + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + for (int i = 0; i < indexesUsed_.size(); i++) { + output.writeMessage(1, indexesUsed_.get(i)); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + for (int i = 0; i < indexesUsed_.size(); i++) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(1, indexesUsed_.get(i)); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.v1.PlanSummary)) { + return super.equals(obj); + } + com.google.firestore.v1.PlanSummary other = (com.google.firestore.v1.PlanSummary) obj; + + if (!getIndexesUsedList().equals(other.getIndexesUsedList())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (getIndexesUsedCount() > 0) { + hash = (37 * hash) + INDEXES_USED_FIELD_NUMBER; + hash = (53 * hash) + getIndexesUsedList().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.v1.PlanSummary parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.PlanSummary parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.PlanSummary parseFrom(com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.PlanSummary parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.PlanSummary parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.PlanSummary parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.PlanSummary parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.PlanSummary parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.PlanSummary parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.PlanSummary parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.PlanSummary parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.PlanSummary parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.v1.PlanSummary prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * Planning phase information for the query.
+   * 
+ * + * Protobuf type {@code google.firestore.v1.PlanSummary} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.v1.PlanSummary) + com.google.firestore.v1.PlanSummaryOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_PlanSummary_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_PlanSummary_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.PlanSummary.class, + com.google.firestore.v1.PlanSummary.Builder.class); + } + + // Construct using com.google.firestore.v1.PlanSummary.newBuilder() + private Builder() {} + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + if (indexesUsedBuilder_ == null) { + indexesUsed_ = java.util.Collections.emptyList(); + } else { + indexesUsed_ = null; + indexesUsedBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000001); + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.v1.QueryProfileProto + .internal_static_google_firestore_v1_PlanSummary_descriptor; + } + + @java.lang.Override + public com.google.firestore.v1.PlanSummary getDefaultInstanceForType() { + return com.google.firestore.v1.PlanSummary.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.v1.PlanSummary build() { + com.google.firestore.v1.PlanSummary result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.v1.PlanSummary buildPartial() { + com.google.firestore.v1.PlanSummary result = new com.google.firestore.v1.PlanSummary(this); + buildPartialRepeatedFields(result); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartialRepeatedFields(com.google.firestore.v1.PlanSummary result) { + if (indexesUsedBuilder_ == null) { + if (((bitField0_ & 0x00000001) != 0)) { + indexesUsed_ = java.util.Collections.unmodifiableList(indexesUsed_); + bitField0_ = (bitField0_ & ~0x00000001); + } + result.indexesUsed_ = indexesUsed_; + } else { + result.indexesUsed_ = indexesUsedBuilder_.build(); + } + } + + private void buildPartial0(com.google.firestore.v1.PlanSummary result) { + int from_bitField0_ = bitField0_; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.v1.PlanSummary) { + return mergeFrom((com.google.firestore.v1.PlanSummary) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.v1.PlanSummary other) { + if (other == com.google.firestore.v1.PlanSummary.getDefaultInstance()) return this; + if (indexesUsedBuilder_ == null) { + if (!other.indexesUsed_.isEmpty()) { + if (indexesUsed_.isEmpty()) { + indexesUsed_ = other.indexesUsed_; + bitField0_ = (bitField0_ & ~0x00000001); + } else { + ensureIndexesUsedIsMutable(); + indexesUsed_.addAll(other.indexesUsed_); + } + onChanged(); + } + } else { + if (!other.indexesUsed_.isEmpty()) { + if (indexesUsedBuilder_.isEmpty()) { + indexesUsedBuilder_.dispose(); + indexesUsedBuilder_ = null; + indexesUsed_ = other.indexesUsed_; + bitField0_ = (bitField0_ & ~0x00000001); + indexesUsedBuilder_ = + com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders + ? getIndexesUsedFieldBuilder() + : null; + } else { + indexesUsedBuilder_.addAllMessages(other.indexesUsed_); + } + } + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + com.google.protobuf.Struct m = + input.readMessage(com.google.protobuf.Struct.parser(), extensionRegistry); + if (indexesUsedBuilder_ == null) { + ensureIndexesUsedIsMutable(); + indexesUsed_.add(m); + } else { + indexesUsedBuilder_.addMessage(m); + } + break; + } // case 10 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private java.util.List indexesUsed_ = + java.util.Collections.emptyList(); + + private void ensureIndexesUsedIsMutable() { + if (!((bitField0_ & 0x00000001) != 0)) { + indexesUsed_ = new java.util.ArrayList(indexesUsed_); + bitField0_ |= 0x00000001; + } + } + + private com.google.protobuf.RepeatedFieldBuilderV3< + com.google.protobuf.Struct, + com.google.protobuf.Struct.Builder, + com.google.protobuf.StructOrBuilder> + indexesUsedBuilder_; + + /** + * + * + *
+     * The indexes selected for the query. For example:
+     *  [
+     *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+     *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+     *  ]
+     * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + public java.util.List getIndexesUsedList() { + if (indexesUsedBuilder_ == null) { + return java.util.Collections.unmodifiableList(indexesUsed_); + } else { + return indexesUsedBuilder_.getMessageList(); + } + } + /** + * + * + *
+     * The indexes selected for the query. For example:
+     *  [
+     *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+     *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+     *  ]
+     * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + public int getIndexesUsedCount() { + if (indexesUsedBuilder_ == null) { + return indexesUsed_.size(); + } else { + return indexesUsedBuilder_.getCount(); + } + } + /** + * + * + *
+     * The indexes selected for the query. For example:
+     *  [
+     *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+     *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+     *  ]
+     * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + public com.google.protobuf.Struct getIndexesUsed(int index) { + if (indexesUsedBuilder_ == null) { + return indexesUsed_.get(index); + } else { + return indexesUsedBuilder_.getMessage(index); + } + } + /** + * + * + *
+     * The indexes selected for the query. For example:
+     *  [
+     *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+     *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+     *  ]
+     * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + public Builder setIndexesUsed(int index, com.google.protobuf.Struct value) { + if (indexesUsedBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureIndexesUsedIsMutable(); + indexesUsed_.set(index, value); + onChanged(); + } else { + indexesUsedBuilder_.setMessage(index, value); + } + return this; + } + /** + * + * + *
+     * The indexes selected for the query. For example:
+     *  [
+     *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+     *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+     *  ]
+     * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + public Builder setIndexesUsed(int index, com.google.protobuf.Struct.Builder builderForValue) { + if (indexesUsedBuilder_ == null) { + ensureIndexesUsedIsMutable(); + indexesUsed_.set(index, builderForValue.build()); + onChanged(); + } else { + indexesUsedBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + /** + * + * + *
+     * The indexes selected for the query. For example:
+     *  [
+     *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+     *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+     *  ]
+     * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + public Builder addIndexesUsed(com.google.protobuf.Struct value) { + if (indexesUsedBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureIndexesUsedIsMutable(); + indexesUsed_.add(value); + onChanged(); + } else { + indexesUsedBuilder_.addMessage(value); + } + return this; + } + /** + * + * + *
+     * The indexes selected for the query. For example:
+     *  [
+     *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+     *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+     *  ]
+     * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + public Builder addIndexesUsed(int index, com.google.protobuf.Struct value) { + if (indexesUsedBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureIndexesUsedIsMutable(); + indexesUsed_.add(index, value); + onChanged(); + } else { + indexesUsedBuilder_.addMessage(index, value); + } + return this; + } + /** + * + * + *
+     * The indexes selected for the query. For example:
+     *  [
+     *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+     *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+     *  ]
+     * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + public Builder addIndexesUsed(com.google.protobuf.Struct.Builder builderForValue) { + if (indexesUsedBuilder_ == null) { + ensureIndexesUsedIsMutable(); + indexesUsed_.add(builderForValue.build()); + onChanged(); + } else { + indexesUsedBuilder_.addMessage(builderForValue.build()); + } + return this; + } + /** + * + * + *
+     * The indexes selected for the query. For example:
+     *  [
+     *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+     *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+     *  ]
+     * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + public Builder addIndexesUsed(int index, com.google.protobuf.Struct.Builder builderForValue) { + if (indexesUsedBuilder_ == null) { + ensureIndexesUsedIsMutable(); + indexesUsed_.add(index, builderForValue.build()); + onChanged(); + } else { + indexesUsedBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + /** + * + * + *
+     * The indexes selected for the query. For example:
+     *  [
+     *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+     *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+     *  ]
+     * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + public Builder addAllIndexesUsed( + java.lang.Iterable values) { + if (indexesUsedBuilder_ == null) { + ensureIndexesUsedIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll(values, indexesUsed_); + onChanged(); + } else { + indexesUsedBuilder_.addAllMessages(values); + } + return this; + } + /** + * + * + *
+     * The indexes selected for the query. For example:
+     *  [
+     *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+     *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+     *  ]
+     * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + public Builder clearIndexesUsed() { + if (indexesUsedBuilder_ == null) { + indexesUsed_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + } else { + indexesUsedBuilder_.clear(); + } + return this; + } + /** + * + * + *
+     * The indexes selected for the query. For example:
+     *  [
+     *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+     *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+     *  ]
+     * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + public Builder removeIndexesUsed(int index) { + if (indexesUsedBuilder_ == null) { + ensureIndexesUsedIsMutable(); + indexesUsed_.remove(index); + onChanged(); + } else { + indexesUsedBuilder_.remove(index); + } + return this; + } + /** + * + * + *
+     * The indexes selected for the query. For example:
+     *  [
+     *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+     *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+     *  ]
+     * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + public com.google.protobuf.Struct.Builder getIndexesUsedBuilder(int index) { + return getIndexesUsedFieldBuilder().getBuilder(index); + } + /** + * + * + *
+     * The indexes selected for the query. For example:
+     *  [
+     *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+     *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+     *  ]
+     * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + public com.google.protobuf.StructOrBuilder getIndexesUsedOrBuilder(int index) { + if (indexesUsedBuilder_ == null) { + return indexesUsed_.get(index); + } else { + return indexesUsedBuilder_.getMessageOrBuilder(index); + } + } + /** + * + * + *
+     * The indexes selected for the query. For example:
+     *  [
+     *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+     *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+     *  ]
+     * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + public java.util.List + getIndexesUsedOrBuilderList() { + if (indexesUsedBuilder_ != null) { + return indexesUsedBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(indexesUsed_); + } + } + /** + * + * + *
+     * The indexes selected for the query. For example:
+     *  [
+     *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+     *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+     *  ]
+     * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + public com.google.protobuf.Struct.Builder addIndexesUsedBuilder() { + return getIndexesUsedFieldBuilder() + .addBuilder(com.google.protobuf.Struct.getDefaultInstance()); + } + /** + * + * + *
+     * The indexes selected for the query. For example:
+     *  [
+     *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+     *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+     *  ]
+     * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + public com.google.protobuf.Struct.Builder addIndexesUsedBuilder(int index) { + return getIndexesUsedFieldBuilder() + .addBuilder(index, com.google.protobuf.Struct.getDefaultInstance()); + } + /** + * + * + *
+     * The indexes selected for the query. For example:
+     *  [
+     *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+     *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+     *  ]
+     * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + public java.util.List getIndexesUsedBuilderList() { + return getIndexesUsedFieldBuilder().getBuilderList(); + } + + private com.google.protobuf.RepeatedFieldBuilderV3< + com.google.protobuf.Struct, + com.google.protobuf.Struct.Builder, + com.google.protobuf.StructOrBuilder> + getIndexesUsedFieldBuilder() { + if (indexesUsedBuilder_ == null) { + indexesUsedBuilder_ = + new com.google.protobuf.RepeatedFieldBuilderV3< + com.google.protobuf.Struct, + com.google.protobuf.Struct.Builder, + com.google.protobuf.StructOrBuilder>( + indexesUsed_, ((bitField0_ & 0x00000001) != 0), getParentForChildren(), isClean()); + indexesUsed_ = null; + } + return indexesUsedBuilder_; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.v1.PlanSummary) + } + + // @@protoc_insertion_point(class_scope:google.firestore.v1.PlanSummary) + private static final com.google.firestore.v1.PlanSummary DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.v1.PlanSummary(); + } + + public static com.google.firestore.v1.PlanSummary getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public PlanSummary parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.v1.PlanSummary getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/PlanSummaryOrBuilder.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/PlanSummaryOrBuilder.java new file mode 100644 index 000000000..4f3c0d8f3 --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/PlanSummaryOrBuilder.java @@ -0,0 +1,97 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/query_profile.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +public interface PlanSummaryOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.v1.PlanSummary) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * The indexes selected for the query. For example:
+   *  [
+   *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+   *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+   *  ]
+   * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + java.util.List getIndexesUsedList(); + /** + * + * + *
+   * The indexes selected for the query. For example:
+   *  [
+   *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+   *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+   *  ]
+   * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + com.google.protobuf.Struct getIndexesUsed(int index); + /** + * + * + *
+   * The indexes selected for the query. For example:
+   *  [
+   *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+   *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+   *  ]
+   * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + int getIndexesUsedCount(); + /** + * + * + *
+   * The indexes selected for the query. For example:
+   *  [
+   *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+   *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+   *  ]
+   * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + java.util.List getIndexesUsedOrBuilderList(); + /** + * + * + *
+   * The indexes selected for the query. For example:
+   *  [
+   *    {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"},
+   *    {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"}
+   *  ]
+   * 
+ * + * repeated .google.protobuf.Struct indexes_used = 1; + */ + com.google.protobuf.StructOrBuilder getIndexesUsedOrBuilder(int index); +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/QueryProfileProto.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/QueryProfileProto.java new file mode 100644 index 000000000..e1195e5d7 --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/QueryProfileProto.java @@ -0,0 +1,128 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/query_profile.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +public final class QueryProfileProto { + private QueryProfileProto() {} + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistryLite registry) {} + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions((com.google.protobuf.ExtensionRegistryLite) registry); + } + + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_v1_ExplainOptions_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_v1_ExplainOptions_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_v1_ExplainMetrics_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_v1_ExplainMetrics_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_v1_PlanSummary_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_v1_PlanSummary_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_v1_ExecutionStats_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_v1_ExecutionStats_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + return descriptor; + } + + private static com.google.protobuf.Descriptors.FileDescriptor descriptor; + + static { + java.lang.String[] descriptorData = { + "\n\'google/firestore/v1/query_profile.prot" + + "o\022\023google.firestore.v1\032\037google/api/field" + + "_behavior.proto\032\036google/protobuf/duratio" + + "n.proto\032\034google/protobuf/struct.proto\"&\n" + + "\016ExplainOptions\022\024\n\007analyze\030\001 \001(\010B\003\340A\001\"\206\001" + + "\n\016ExplainMetrics\0226\n\014plan_summary\030\001 \001(\0132 " + + ".google.firestore.v1.PlanSummary\022<\n\017exec" + + "ution_stats\030\002 \001(\0132#.google.firestore.v1." + + "ExecutionStats\"<\n\013PlanSummary\022-\n\014indexes" + + "_used\030\001 \003(\0132\027.google.protobuf.Struct\"\250\001\n" + + "\016ExecutionStats\022\030\n\020results_returned\030\001 \001(" + + "\003\0225\n\022execution_duration\030\003 \001(\0132\031.google.p" + + "rotobuf.Duration\022\027\n\017read_operations\030\004 \001(" + + "\003\022,\n\013debug_stats\030\005 \001(\0132\027.google.protobuf" + + ".StructB\311\001\n\027com.google.firestore.v1B\021Que" + + "ryProfileProtoP\001Z;cloud.google.com/go/fi" + + "restore/apiv1/firestorepb;firestorepb\242\002\004" + + "GCFS\252\002\031Google.Cloud.Firestore.V1\312\002\031Googl" + + "e\\Cloud\\Firestore\\V1\352\002\034Google::Cloud::Fi" + + "restore::V1b\006proto3" + }; + descriptor = + com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( + descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + com.google.api.FieldBehaviorProto.getDescriptor(), + com.google.protobuf.DurationProto.getDescriptor(), + com.google.protobuf.StructProto.getDescriptor(), + }); + internal_static_google_firestore_v1_ExplainOptions_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_google_firestore_v1_ExplainOptions_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_v1_ExplainOptions_descriptor, + new java.lang.String[] { + "Analyze", + }); + internal_static_google_firestore_v1_ExplainMetrics_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_google_firestore_v1_ExplainMetrics_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_v1_ExplainMetrics_descriptor, + new java.lang.String[] { + "PlanSummary", "ExecutionStats", + }); + internal_static_google_firestore_v1_PlanSummary_descriptor = + getDescriptor().getMessageTypes().get(2); + internal_static_google_firestore_v1_PlanSummary_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_v1_PlanSummary_descriptor, + new java.lang.String[] { + "IndexesUsed", + }); + internal_static_google_firestore_v1_ExecutionStats_descriptor = + getDescriptor().getMessageTypes().get(3); + internal_static_google_firestore_v1_ExecutionStats_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_v1_ExecutionStats_descriptor, + new java.lang.String[] { + "ResultsReturned", "ExecutionDuration", "ReadOperations", "DebugStats", + }); + com.google.protobuf.ExtensionRegistry registry = + com.google.protobuf.ExtensionRegistry.newInstance(); + registry.add(com.google.api.FieldBehaviorProto.fieldBehavior); + com.google.protobuf.Descriptors.FileDescriptor.internalUpdateFileDescriptor( + descriptor, registry); + com.google.api.FieldBehaviorProto.getDescriptor(); + com.google.protobuf.DurationProto.getDescriptor(); + com.google.protobuf.StructProto.getDescriptor(); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/QueryProto.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/QueryProto.java index a54bc4ef4..b87474e84 100644 --- a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/QueryProto.java +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/QueryProto.java @@ -64,6 +64,10 @@ public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry r internal_static_google_firestore_v1_StructuredQuery_Projection_descriptor; static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_google_firestore_v1_StructuredQuery_Projection_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_google_firestore_v1_StructuredQuery_FindNearest_descriptor; + static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_google_firestore_v1_StructuredQuery_FindNearest_fieldAccessorTable; static final com.google.protobuf.Descriptors.Descriptor internal_static_google_firestore_v1_StructuredAggregationQuery_descriptor; static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable @@ -100,7 +104,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { "\n\037google/firestore/v1/query.proto\022\023googl" + "e.firestore.v1\032\037google/api/field_behavio" + "r.proto\032\"google/firestore/v1/document.pr" - + "oto\032\036google/protobuf/wrappers.proto\"\276\017\n\017" + + "oto\032\036google/protobuf/wrappers.proto\"\225\023\n\017" + "StructuredQuery\022?\n\006select\030\001 \001(\0132/.google" + ".firestore.v1.StructuredQuery.Projection" + "\022E\n\004from\030\002 \003(\01327.google.firestore.v1.Str" @@ -111,70 +115,82 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + "rt_at\030\007 \001(\0132\033.google.firestore.v1.Cursor" + "\022+\n\006end_at\030\010 \001(\0132\033.google.firestore.v1.C" + "ursor\022\016\n\006offset\030\006 \001(\005\022*\n\005limit\030\005 \001(\0132\033.g" - + "oogle.protobuf.Int32Value\032D\n\022CollectionS" - + "elector\022\025\n\rcollection_id\030\002 \001(\t\022\027\n\017all_de" - + "scendants\030\003 \001(\010\032\375\001\n\006Filter\022P\n\020composite_" - + "filter\030\001 \001(\01324.google.firestore.v1.Struc" - + "turedQuery.CompositeFilterH\000\022H\n\014field_fi" - + "lter\030\002 \001(\01320.google.firestore.v1.Structu" - + "redQuery.FieldFilterH\000\022H\n\014unary_filter\030\003" - + " \001(\01320.google.firestore.v1.StructuredQue" - + "ry.UnaryFilterH\000B\r\n\013filter_type\032\321\001\n\017Comp" - + "ositeFilter\022I\n\002op\030\001 \001(\0162=.google.firesto" - + "re.v1.StructuredQuery.CompositeFilter.Op" - + "erator\022<\n\007filters\030\002 \003(\0132+.google.firesto" - + "re.v1.StructuredQuery.Filter\"5\n\010Operator" - + "\022\030\n\024OPERATOR_UNSPECIFIED\020\000\022\007\n\003AND\020\001\022\006\n\002O" - + "R\020\002\032\230\003\n\013FieldFilter\022B\n\005field\030\001 \001(\01323.goo" - + "gle.firestore.v1.StructuredQuery.FieldRe" - + "ference\022E\n\002op\030\002 \001(\01629.google.firestore.v" - + "1.StructuredQuery.FieldFilter.Operator\022)" - + "\n\005value\030\003 \001(\0132\032.google.firestore.v1.Valu" - + "e\"\322\001\n\010Operator\022\030\n\024OPERATOR_UNSPECIFIED\020\000" - + "\022\r\n\tLESS_THAN\020\001\022\026\n\022LESS_THAN_OR_EQUAL\020\002\022" - + "\020\n\014GREATER_THAN\020\003\022\031\n\025GREATER_THAN_OR_EQU" - + "AL\020\004\022\t\n\005EQUAL\020\005\022\r\n\tNOT_EQUAL\020\006\022\022\n\016ARRAY_" - + "CONTAINS\020\007\022\006\n\002IN\020\010\022\026\n\022ARRAY_CONTAINS_ANY" - + "\020\t\022\n\n\006NOT_IN\020\n\032\212\002\n\013UnaryFilter\022E\n\002op\030\001 \001" - + "(\01629.google.firestore.v1.StructuredQuery" - + ".UnaryFilter.Operator\022D\n\005field\030\002 \001(\01323.g" + + "oogle.protobuf.Int32Value\022K\n\014find_neares" + + "t\030\t \001(\01320.google.firestore.v1.Structured" + + "Query.FindNearestB\003\340A\001\032D\n\022CollectionSele" + + "ctor\022\025\n\rcollection_id\030\002 \001(\t\022\027\n\017all_desce" + + "ndants\030\003 \001(\010\032\375\001\n\006Filter\022P\n\020composite_fil" + + "ter\030\001 \001(\01324.google.firestore.v1.Structur" + + "edQuery.CompositeFilterH\000\022H\n\014field_filte" + + "r\030\002 \001(\01320.google.firestore.v1.Structured" + + "Query.FieldFilterH\000\022H\n\014unary_filter\030\003 \001(" + + "\01320.google.firestore.v1.StructuredQuery." + + "UnaryFilterH\000B\r\n\013filter_type\032\321\001\n\017Composi" + + "teFilter\022I\n\002op\030\001 \001(\0162=.google.firestore." + + "v1.StructuredQuery.CompositeFilter.Opera" + + "tor\022<\n\007filters\030\002 \003(\0132+.google.firestore." + + "v1.StructuredQuery.Filter\"5\n\010Operator\022\030\n" + + "\024OPERATOR_UNSPECIFIED\020\000\022\007\n\003AND\020\001\022\006\n\002OR\020\002" + + "\032\230\003\n\013FieldFilter\022B\n\005field\030\001 \001(\01323.google" + + ".firestore.v1.StructuredQuery.FieldRefer" + + "ence\022E\n\002op\030\002 \001(\01629.google.firestore.v1.S" + + "tructuredQuery.FieldFilter.Operator\022)\n\005v" + + "alue\030\003 \001(\0132\032.google.firestore.v1.Value\"\322" + + "\001\n\010Operator\022\030\n\024OPERATOR_UNSPECIFIED\020\000\022\r\n" + + "\tLESS_THAN\020\001\022\026\n\022LESS_THAN_OR_EQUAL\020\002\022\020\n\014" + + "GREATER_THAN\020\003\022\031\n\025GREATER_THAN_OR_EQUAL\020" + + "\004\022\t\n\005EQUAL\020\005\022\r\n\tNOT_EQUAL\020\006\022\022\n\016ARRAY_CON" + + "TAINS\020\007\022\006\n\002IN\020\010\022\026\n\022ARRAY_CONTAINS_ANY\020\t\022" + + "\n\n\006NOT_IN\020\n\032\212\002\n\013UnaryFilter\022E\n\002op\030\001 \001(\0162" + + "9.google.firestore.v1.StructuredQuery.Un" + + "aryFilter.Operator\022D\n\005field\030\002 \001(\01323.goog" + + "le.firestore.v1.StructuredQuery.FieldRef" + + "erenceH\000\"^\n\010Operator\022\030\n\024OPERATOR_UNSPECI" + + "FIED\020\000\022\n\n\006IS_NAN\020\002\022\013\n\007IS_NULL\020\003\022\016\n\nIS_NO" + + "T_NAN\020\004\022\017\n\013IS_NOT_NULL\020\005B\016\n\014operand_type" + + "\032\216\001\n\005Order\022B\n\005field\030\001 \001(\01323.google.fires" + + "tore.v1.StructuredQuery.FieldReference\022A" + + "\n\tdirection\030\002 \001(\0162..google.firestore.v1." + + "StructuredQuery.Direction\032$\n\016FieldRefere" + + "nce\022\022\n\nfield_path\030\002 \001(\t\032Q\n\nProjection\022C\n" + + "\006fields\030\002 \003(\01323.google.firestore.v1.Stru" + + "cturedQuery.FieldReference\032\207\003\n\013FindNeare" + + "st\022N\n\014vector_field\030\001 \001(\01323.google.firest" + + "ore.v1.StructuredQuery.FieldReferenceB\003\340" + + "A\002\0225\n\014query_vector\030\002 \001(\0132\032.google.firest" + + "ore.v1.ValueB\003\340A\002\022_\n\020distance_measure\030\003 " + + "\001(\0162@.google.firestore.v1.StructuredQuer" + + "y.FindNearest.DistanceMeasureB\003\340A\002\022/\n\005li" + + "mit\030\004 \001(\0132\033.google.protobuf.Int32ValueB\003" + + "\340A\002\"_\n\017DistanceMeasure\022 \n\034DISTANCE_MEASU" + + "RE_UNSPECIFIED\020\000\022\r\n\tEUCLIDEAN\020\001\022\n\n\006COSIN" + + "E\020\002\022\017\n\013DOT_PRODUCT\020\003\"E\n\tDirection\022\031\n\025DIR" + + "ECTION_UNSPECIFIED\020\000\022\r\n\tASCENDING\020\001\022\016\n\nD" + + "ESCENDING\020\002\"\270\005\n\032StructuredAggregationQue" + + "ry\022@\n\020structured_query\030\001 \001(\0132$.google.fi" + + "restore.v1.StructuredQueryH\000\022V\n\014aggregat" + + "ions\030\003 \003(\0132;.google.firestore.v1.Structu" + + "redAggregationQuery.AggregationB\003\340A\001\032\361\003\n" + + "\013Aggregation\022R\n\005count\030\001 \001(\0132A.google.fir" + + "estore.v1.StructuredAggregationQuery.Agg" + + "regation.CountH\000\022N\n\003sum\030\002 \001(\0132?.google.f" + + "irestore.v1.StructuredAggregationQuery.A" + + "ggregation.SumH\000\022N\n\003avg\030\003 \001(\0132?.google.f" + + "irestore.v1.StructuredAggregationQuery.A" + + "ggregation.AvgH\000\022\022\n\005alias\030\007 \001(\tB\003\340A\001\0328\n\005" + + "Count\022/\n\005up_to\030\001 \001(\0132\033.google.protobuf.I" + + "nt64ValueB\003\340A\001\032I\n\003Sum\022B\n\005field\030\001 \001(\01323.g" + "oogle.firestore.v1.StructuredQuery.Field" - + "ReferenceH\000\"^\n\010Operator\022\030\n\024OPERATOR_UNSP" - + "ECIFIED\020\000\022\n\n\006IS_NAN\020\002\022\013\n\007IS_NULL\020\003\022\016\n\nIS" - + "_NOT_NAN\020\004\022\017\n\013IS_NOT_NULL\020\005B\016\n\014operand_t" - + "ype\032\216\001\n\005Order\022B\n\005field\030\001 \001(\01323.google.fi" - + "restore.v1.StructuredQuery.FieldReferenc" - + "e\022A\n\tdirection\030\002 \001(\0162..google.firestore." - + "v1.StructuredQuery.Direction\032$\n\016FieldRef" - + "erence\022\022\n\nfield_path\030\002 \001(\t\032Q\n\nProjection" - + "\022C\n\006fields\030\002 \003(\01323.google.firestore.v1.S" - + "tructuredQuery.FieldReference\"E\n\tDirecti" - + "on\022\031\n\025DIRECTION_UNSPECIFIED\020\000\022\r\n\tASCENDI" - + "NG\020\001\022\016\n\nDESCENDING\020\002\"\273\005\n\032StructuredAggre" - + "gationQuery\022@\n\020structured_query\030\001 \001(\0132$." - + "google.firestore.v1.StructuredQueryH\000\022W\n" - + "\014aggregations\030\003 \003(\0132;.google.firestore.v" - + "1.StructuredAggregationQuery.Aggregation" - + "B\004\342A\001\001\032\363\003\n\013Aggregation\022R\n\005count\030\001 \001(\0132A." - + "google.firestore.v1.StructuredAggregatio" - + "nQuery.Aggregation.CountH\000\022N\n\003sum\030\002 \001(\0132" - + "?.google.firestore.v1.StructuredAggregat" - + "ionQuery.Aggregation.SumH\000\022N\n\003avg\030\003 \001(\0132" - + "?.google.firestore.v1.StructuredAggregat" - + "ionQuery.Aggregation.AvgH\000\022\023\n\005alias\030\007 \001(" - + "\tB\004\342A\001\001\0329\n\005Count\0220\n\005up_to\030\001 \001(\0132\033.google" - + ".protobuf.Int64ValueB\004\342A\001\001\032I\n\003Sum\022B\n\005fie" - + "ld\030\001 \001(\01323.google.firestore.v1.Structure" - + "dQuery.FieldReference\032I\n\003Avg\022B\n\005field\030\001 " - + "\001(\01323.google.firestore.v1.StructuredQuer" - + "y.FieldReferenceB\n\n\010operatorB\014\n\nquery_ty" - + "pe\"D\n\006Cursor\022*\n\006values\030\001 \003(\0132\032.google.fi" - + "restore.v1.Value\022\016\n\006before\030\002 \001(\010B\302\001\n\027com" - + ".google.firestore.v1B\nQueryProtoP\001Z;clou" - + "d.google.com/go/firestore/apiv1/firestor" - + "epb;firestorepb\242\002\004GCFS\252\002\031Google.Cloud.Fi" - + "restore.V1\312\002\031Google\\Cloud\\Firestore\\V1\352\002" - + "\034Google::Cloud::Firestore::V1b\006proto3" + + "Reference\032I\n\003Avg\022B\n\005field\030\001 \001(\01323.google" + + ".firestore.v1.StructuredQuery.FieldRefer" + + "enceB\n\n\010operatorB\014\n\nquery_type\"D\n\006Cursor" + + "\022*\n\006values\030\001 \003(\0132\032.google.firestore.v1.V" + + "alue\022\016\n\006before\030\002 \001(\010B\302\001\n\027com.google.fire" + + "store.v1B\nQueryProtoP\001Z;cloud.google.com" + + "/go/firestore/apiv1/firestorepb;firestor" + + "epb\242\002\004GCFS\252\002\031Google.Cloud.Firestore.V1\312\002" + + "\031Google\\Cloud\\Firestore\\V1\352\002\034Google::Clo" + + "ud::Firestore::V1b\006proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( @@ -190,7 +206,15 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_firestore_v1_StructuredQuery_descriptor, new java.lang.String[] { - "Select", "From", "Where", "OrderBy", "StartAt", "EndAt", "Offset", "Limit", + "Select", + "From", + "Where", + "OrderBy", + "StartAt", + "EndAt", + "Offset", + "Limit", + "FindNearest", }); internal_static_google_firestore_v1_StructuredQuery_CollectionSelector_descriptor = internal_static_google_firestore_v1_StructuredQuery_descriptor.getNestedTypes().get(0); @@ -256,6 +280,14 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { new java.lang.String[] { "Fields", }); + internal_static_google_firestore_v1_StructuredQuery_FindNearest_descriptor = + internal_static_google_firestore_v1_StructuredQuery_descriptor.getNestedTypes().get(8); + internal_static_google_firestore_v1_StructuredQuery_FindNearest_fieldAccessorTable = + new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_google_firestore_v1_StructuredQuery_FindNearest_descriptor, + new java.lang.String[] { + "VectorField", "QueryVector", "DistanceMeasure", "Limit", + }); internal_static_google_firestore_v1_StructuredAggregationQuery_descriptor = getDescriptor().getMessageTypes().get(1); internal_static_google_firestore_v1_StructuredAggregationQuery_fieldAccessorTable = diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/StructuredPipeline.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/StructuredPipeline.java new file mode 100644 index 000000000..860bd4e1c --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/StructuredPipeline.java @@ -0,0 +1,1177 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/pipeline.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +/** + * + * + *
+ * A Firestore query represented as an ordered list of operations / stages.
+ *
+ * This is considered the top-level function which plans & executes a query.
+ * It is logically equivalent to `query(stages, options)`, but prevents the
+ * client from having to build a function wrapper.
+ * 
+ * + * Protobuf type {@code google.firestore.v1.StructuredPipeline} + */ +public final class StructuredPipeline extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.v1.StructuredPipeline) + StructuredPipelineOrBuilder { + private static final long serialVersionUID = 0L; + // Use StructuredPipeline.newBuilder() to construct. + private StructuredPipeline(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private StructuredPipeline() {} + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new StructuredPipeline(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.PipelineProto + .internal_static_google_firestore_v1_StructuredPipeline_descriptor; + } + + @SuppressWarnings({"rawtypes"}) + @java.lang.Override + protected com.google.protobuf.MapFieldReflectionAccessor internalGetMapFieldReflection( + int number) { + switch (number) { + case 2: + return internalGetOptions(); + default: + throw new RuntimeException("Invalid map field number: " + number); + } + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.PipelineProto + .internal_static_google_firestore_v1_StructuredPipeline_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.StructuredPipeline.class, + com.google.firestore.v1.StructuredPipeline.Builder.class); + } + + private int bitField0_; + public static final int PIPELINE_FIELD_NUMBER = 1; + private com.google.firestore.v1.Pipeline pipeline_; + /** + * + * + *
+   * The pipeline query to execute.
+   * 
+ * + * .google.firestore.v1.Pipeline pipeline = 1; + * + * @return Whether the pipeline field is set. + */ + @java.lang.Override + public boolean hasPipeline() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * + * + *
+   * The pipeline query to execute.
+   * 
+ * + * .google.firestore.v1.Pipeline pipeline = 1; + * + * @return The pipeline. + */ + @java.lang.Override + public com.google.firestore.v1.Pipeline getPipeline() { + return pipeline_ == null ? com.google.firestore.v1.Pipeline.getDefaultInstance() : pipeline_; + } + /** + * + * + *
+   * The pipeline query to execute.
+   * 
+ * + * .google.firestore.v1.Pipeline pipeline = 1; + */ + @java.lang.Override + public com.google.firestore.v1.PipelineOrBuilder getPipelineOrBuilder() { + return pipeline_ == null ? com.google.firestore.v1.Pipeline.getDefaultInstance() : pipeline_; + } + + public static final int OPTIONS_FIELD_NUMBER = 2; + + private static final class OptionsDefaultEntryHolder { + static final com.google.protobuf.MapEntry + defaultEntry = + com.google.protobuf.MapEntry + .newDefaultInstance( + com.google.firestore.v1.PipelineProto + .internal_static_google_firestore_v1_StructuredPipeline_OptionsEntry_descriptor, + com.google.protobuf.WireFormat.FieldType.STRING, + "", + com.google.protobuf.WireFormat.FieldType.MESSAGE, + com.google.firestore.v1.Value.getDefaultInstance()); + } + + @SuppressWarnings("serial") + private com.google.protobuf.MapField options_; + + private com.google.protobuf.MapField + internalGetOptions() { + if (options_ == null) { + return com.google.protobuf.MapField.emptyMapField(OptionsDefaultEntryHolder.defaultEntry); + } + return options_; + } + + public int getOptionsCount() { + return internalGetOptions().getMap().size(); + } + /** + * + * + *
+   * Optional query-level arguments.
+   *
+   * (-- Think query statement hints. --)
+   *
+   * (-- TODO(batchik): define the api contract of using an unsupported hint --)
+   * 
+ * + * map<string, .google.firestore.v1.Value> options = 2; + */ + @java.lang.Override + public boolean containsOptions(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + return internalGetOptions().getMap().containsKey(key); + } + /** Use {@link #getOptionsMap()} instead. */ + @java.lang.Override + @java.lang.Deprecated + public java.util.Map getOptions() { + return getOptionsMap(); + } + /** + * + * + *
+   * Optional query-level arguments.
+   *
+   * (-- Think query statement hints. --)
+   *
+   * (-- TODO(batchik): define the api contract of using an unsupported hint --)
+   * 
+ * + * map<string, .google.firestore.v1.Value> options = 2; + */ + @java.lang.Override + public java.util.Map getOptionsMap() { + return internalGetOptions().getMap(); + } + /** + * + * + *
+   * Optional query-level arguments.
+   *
+   * (-- Think query statement hints. --)
+   *
+   * (-- TODO(batchik): define the api contract of using an unsupported hint --)
+   * 
+ * + * map<string, .google.firestore.v1.Value> options = 2; + */ + @java.lang.Override + public /* nullable */ com.google.firestore.v1.Value getOptionsOrDefault( + java.lang.String key, + /* nullable */ + com.google.firestore.v1.Value defaultValue) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = + internalGetOptions().getMap(); + return map.containsKey(key) ? map.get(key) : defaultValue; + } + /** + * + * + *
+   * Optional query-level arguments.
+   *
+   * (-- Think query statement hints. --)
+   *
+   * (-- TODO(batchik): define the api contract of using an unsupported hint --)
+   * 
+ * + * map<string, .google.firestore.v1.Value> options = 2; + */ + @java.lang.Override + public com.google.firestore.v1.Value getOptionsOrThrow(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = + internalGetOptions().getMap(); + if (!map.containsKey(key)) { + throw new java.lang.IllegalArgumentException(); + } + return map.get(key); + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (((bitField0_ & 0x00000001) != 0)) { + output.writeMessage(1, getPipeline()); + } + com.google.protobuf.GeneratedMessageV3.serializeStringMapTo( + output, internalGetOptions(), OptionsDefaultEntryHolder.defaultEntry, 2); + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(1, getPipeline()); + } + for (java.util.Map.Entry entry : + internalGetOptions().getMap().entrySet()) { + com.google.protobuf.MapEntry options__ = + OptionsDefaultEntryHolder.defaultEntry + .newBuilderForType() + .setKey(entry.getKey()) + .setValue(entry.getValue()) + .build(); + size += com.google.protobuf.CodedOutputStream.computeMessageSize(2, options__); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.v1.StructuredPipeline)) { + return super.equals(obj); + } + com.google.firestore.v1.StructuredPipeline other = + (com.google.firestore.v1.StructuredPipeline) obj; + + if (hasPipeline() != other.hasPipeline()) return false; + if (hasPipeline()) { + if (!getPipeline().equals(other.getPipeline())) return false; + } + if (!internalGetOptions().equals(other.internalGetOptions())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (hasPipeline()) { + hash = (37 * hash) + PIPELINE_FIELD_NUMBER; + hash = (53 * hash) + getPipeline().hashCode(); + } + if (!internalGetOptions().getMap().isEmpty()) { + hash = (37 * hash) + OPTIONS_FIELD_NUMBER; + hash = (53 * hash) + internalGetOptions().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.v1.StructuredPipeline parseFrom(java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.StructuredPipeline parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.StructuredPipeline parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.StructuredPipeline parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.StructuredPipeline parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.StructuredPipeline parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.StructuredPipeline parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.StructuredPipeline parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.StructuredPipeline parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.StructuredPipeline parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.StructuredPipeline parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.StructuredPipeline parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.google.firestore.v1.StructuredPipeline prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+   * A Firestore query represented as an ordered list of operations / stages.
+   *
+   * This is considered the top-level function which plans & executes a query.
+   * It is logically equivalent to `query(stages, options)`, but prevents the
+   * client from having to build a function wrapper.
+   * 
+ * + * Protobuf type {@code google.firestore.v1.StructuredPipeline} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.v1.StructuredPipeline) + com.google.firestore.v1.StructuredPipelineOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.PipelineProto + .internal_static_google_firestore_v1_StructuredPipeline_descriptor; + } + + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapFieldReflectionAccessor internalGetMapFieldReflection( + int number) { + switch (number) { + case 2: + return internalGetOptions(); + default: + throw new RuntimeException("Invalid map field number: " + number); + } + } + + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapFieldReflectionAccessor internalGetMutableMapFieldReflection( + int number) { + switch (number) { + case 2: + return internalGetMutableOptions(); + default: + throw new RuntimeException("Invalid map field number: " + number); + } + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.PipelineProto + .internal_static_google_firestore_v1_StructuredPipeline_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.StructuredPipeline.class, + com.google.firestore.v1.StructuredPipeline.Builder.class); + } + + // Construct using com.google.firestore.v1.StructuredPipeline.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) { + getPipelineFieldBuilder(); + } + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + pipeline_ = null; + if (pipelineBuilder_ != null) { + pipelineBuilder_.dispose(); + pipelineBuilder_ = null; + } + internalGetMutableOptions().clear(); + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.v1.PipelineProto + .internal_static_google_firestore_v1_StructuredPipeline_descriptor; + } + + @java.lang.Override + public com.google.firestore.v1.StructuredPipeline getDefaultInstanceForType() { + return com.google.firestore.v1.StructuredPipeline.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.v1.StructuredPipeline build() { + com.google.firestore.v1.StructuredPipeline result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.v1.StructuredPipeline buildPartial() { + com.google.firestore.v1.StructuredPipeline result = + new com.google.firestore.v1.StructuredPipeline(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.v1.StructuredPipeline result) { + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.pipeline_ = pipelineBuilder_ == null ? pipeline_ : pipelineBuilder_.build(); + to_bitField0_ |= 0x00000001; + } + if (((from_bitField0_ & 0x00000002) != 0)) { + result.options_ = internalGetOptions().build(OptionsDefaultEntryHolder.defaultEntry); + } + result.bitField0_ |= to_bitField0_; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.v1.StructuredPipeline) { + return mergeFrom((com.google.firestore.v1.StructuredPipeline) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.v1.StructuredPipeline other) { + if (other == com.google.firestore.v1.StructuredPipeline.getDefaultInstance()) return this; + if (other.hasPipeline()) { + mergePipeline(other.getPipeline()); + } + internalGetMutableOptions().mergeFrom(other.internalGetOptions()); + bitField0_ |= 0x00000002; + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + input.readMessage(getPipelineFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: + { + com.google.protobuf.MapEntry + options__ = + input.readMessage( + OptionsDefaultEntryHolder.defaultEntry.getParserForType(), + extensionRegistry); + internalGetMutableOptions() + .ensureBuilderMap() + .put(options__.getKey(), options__.getValue()); + bitField0_ |= 0x00000002; + break; + } // case 18 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private com.google.firestore.v1.Pipeline pipeline_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.Pipeline, + com.google.firestore.v1.Pipeline.Builder, + com.google.firestore.v1.PipelineOrBuilder> + pipelineBuilder_; + /** + * + * + *
+     * The pipeline query to execute.
+     * 
+ * + * .google.firestore.v1.Pipeline pipeline = 1; + * + * @return Whether the pipeline field is set. + */ + public boolean hasPipeline() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * + * + *
+     * The pipeline query to execute.
+     * 
+ * + * .google.firestore.v1.Pipeline pipeline = 1; + * + * @return The pipeline. + */ + public com.google.firestore.v1.Pipeline getPipeline() { + if (pipelineBuilder_ == null) { + return pipeline_ == null + ? com.google.firestore.v1.Pipeline.getDefaultInstance() + : pipeline_; + } else { + return pipelineBuilder_.getMessage(); + } + } + /** + * + * + *
+     * The pipeline query to execute.
+     * 
+ * + * .google.firestore.v1.Pipeline pipeline = 1; + */ + public Builder setPipeline(com.google.firestore.v1.Pipeline value) { + if (pipelineBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + pipeline_ = value; + } else { + pipelineBuilder_.setMessage(value); + } + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * The pipeline query to execute.
+     * 
+ * + * .google.firestore.v1.Pipeline pipeline = 1; + */ + public Builder setPipeline(com.google.firestore.v1.Pipeline.Builder builderForValue) { + if (pipelineBuilder_ == null) { + pipeline_ = builderForValue.build(); + } else { + pipelineBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+     * The pipeline query to execute.
+     * 
+ * + * .google.firestore.v1.Pipeline pipeline = 1; + */ + public Builder mergePipeline(com.google.firestore.v1.Pipeline value) { + if (pipelineBuilder_ == null) { + if (((bitField0_ & 0x00000001) != 0) + && pipeline_ != null + && pipeline_ != com.google.firestore.v1.Pipeline.getDefaultInstance()) { + getPipelineBuilder().mergeFrom(value); + } else { + pipeline_ = value; + } + } else { + pipelineBuilder_.mergeFrom(value); + } + if (pipeline_ != null) { + bitField0_ |= 0x00000001; + onChanged(); + } + return this; + } + /** + * + * + *
+     * The pipeline query to execute.
+     * 
+ * + * .google.firestore.v1.Pipeline pipeline = 1; + */ + public Builder clearPipeline() { + bitField0_ = (bitField0_ & ~0x00000001); + pipeline_ = null; + if (pipelineBuilder_ != null) { + pipelineBuilder_.dispose(); + pipelineBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * The pipeline query to execute.
+     * 
+ * + * .google.firestore.v1.Pipeline pipeline = 1; + */ + public com.google.firestore.v1.Pipeline.Builder getPipelineBuilder() { + bitField0_ |= 0x00000001; + onChanged(); + return getPipelineFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * The pipeline query to execute.
+     * 
+ * + * .google.firestore.v1.Pipeline pipeline = 1; + */ + public com.google.firestore.v1.PipelineOrBuilder getPipelineOrBuilder() { + if (pipelineBuilder_ != null) { + return pipelineBuilder_.getMessageOrBuilder(); + } else { + return pipeline_ == null + ? com.google.firestore.v1.Pipeline.getDefaultInstance() + : pipeline_; + } + } + /** + * + * + *
+     * The pipeline query to execute.
+     * 
+ * + * .google.firestore.v1.Pipeline pipeline = 1; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.Pipeline, + com.google.firestore.v1.Pipeline.Builder, + com.google.firestore.v1.PipelineOrBuilder> + getPipelineFieldBuilder() { + if (pipelineBuilder_ == null) { + pipelineBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.Pipeline, + com.google.firestore.v1.Pipeline.Builder, + com.google.firestore.v1.PipelineOrBuilder>( + getPipeline(), getParentForChildren(), isClean()); + pipeline_ = null; + } + return pipelineBuilder_; + } + + private static final class OptionsConverter + implements com.google.protobuf.MapFieldBuilder.Converter< + java.lang.String, + com.google.firestore.v1.ValueOrBuilder, + com.google.firestore.v1.Value> { + @java.lang.Override + public com.google.firestore.v1.Value build(com.google.firestore.v1.ValueOrBuilder val) { + if (val instanceof com.google.firestore.v1.Value) { + return (com.google.firestore.v1.Value) val; + } + return ((com.google.firestore.v1.Value.Builder) val).build(); + } + + @java.lang.Override + public com.google.protobuf.MapEntry + defaultEntry() { + return OptionsDefaultEntryHolder.defaultEntry; + } + }; + + private static final OptionsConverter optionsConverter = new OptionsConverter(); + + private com.google.protobuf.MapFieldBuilder< + java.lang.String, + com.google.firestore.v1.ValueOrBuilder, + com.google.firestore.v1.Value, + com.google.firestore.v1.Value.Builder> + options_; + + private com.google.protobuf.MapFieldBuilder< + java.lang.String, + com.google.firestore.v1.ValueOrBuilder, + com.google.firestore.v1.Value, + com.google.firestore.v1.Value.Builder> + internalGetOptions() { + if (options_ == null) { + return new com.google.protobuf.MapFieldBuilder<>(optionsConverter); + } + return options_; + } + + private com.google.protobuf.MapFieldBuilder< + java.lang.String, + com.google.firestore.v1.ValueOrBuilder, + com.google.firestore.v1.Value, + com.google.firestore.v1.Value.Builder> + internalGetMutableOptions() { + if (options_ == null) { + options_ = new com.google.protobuf.MapFieldBuilder<>(optionsConverter); + } + bitField0_ |= 0x00000002; + onChanged(); + return options_; + } + + public int getOptionsCount() { + return internalGetOptions().ensureBuilderMap().size(); + } + /** + * + * + *
+     * Optional query-level arguments.
+     *
+     * (-- Think query statement hints. --)
+     *
+     * (-- TODO(batchik): define the api contract of using an unsupported hint --)
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 2; + */ + @java.lang.Override + public boolean containsOptions(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + return internalGetOptions().ensureBuilderMap().containsKey(key); + } + /** Use {@link #getOptionsMap()} instead. */ + @java.lang.Override + @java.lang.Deprecated + public java.util.Map getOptions() { + return getOptionsMap(); + } + /** + * + * + *
+     * Optional query-level arguments.
+     *
+     * (-- Think query statement hints. --)
+     *
+     * (-- TODO(batchik): define the api contract of using an unsupported hint --)
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 2; + */ + @java.lang.Override + public java.util.Map getOptionsMap() { + return internalGetOptions().getImmutableMap(); + } + /** + * + * + *
+     * Optional query-level arguments.
+     *
+     * (-- Think query statement hints. --)
+     *
+     * (-- TODO(batchik): define the api contract of using an unsupported hint --)
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 2; + */ + @java.lang.Override + public /* nullable */ com.google.firestore.v1.Value getOptionsOrDefault( + java.lang.String key, + /* nullable */ + com.google.firestore.v1.Value defaultValue) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = + internalGetMutableOptions().ensureBuilderMap(); + return map.containsKey(key) ? optionsConverter.build(map.get(key)) : defaultValue; + } + /** + * + * + *
+     * Optional query-level arguments.
+     *
+     * (-- Think query statement hints. --)
+     *
+     * (-- TODO(batchik): define the api contract of using an unsupported hint --)
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 2; + */ + @java.lang.Override + public com.google.firestore.v1.Value getOptionsOrThrow(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + java.util.Map map = + internalGetMutableOptions().ensureBuilderMap(); + if (!map.containsKey(key)) { + throw new java.lang.IllegalArgumentException(); + } + return optionsConverter.build(map.get(key)); + } + + public Builder clearOptions() { + bitField0_ = (bitField0_ & ~0x00000002); + internalGetMutableOptions().clear(); + return this; + } + /** + * + * + *
+     * Optional query-level arguments.
+     *
+     * (-- Think query statement hints. --)
+     *
+     * (-- TODO(batchik): define the api contract of using an unsupported hint --)
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 2; + */ + public Builder removeOptions(java.lang.String key) { + if (key == null) { + throw new NullPointerException("map key"); + } + internalGetMutableOptions().ensureBuilderMap().remove(key); + return this; + } + /** Use alternate mutation accessors instead. */ + @java.lang.Deprecated + public java.util.Map getMutableOptions() { + bitField0_ |= 0x00000002; + return internalGetMutableOptions().ensureMessageMap(); + } + /** + * + * + *
+     * Optional query-level arguments.
+     *
+     * (-- Think query statement hints. --)
+     *
+     * (-- TODO(batchik): define the api contract of using an unsupported hint --)
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 2; + */ + public Builder putOptions(java.lang.String key, com.google.firestore.v1.Value value) { + if (key == null) { + throw new NullPointerException("map key"); + } + if (value == null) { + throw new NullPointerException("map value"); + } + internalGetMutableOptions().ensureBuilderMap().put(key, value); + bitField0_ |= 0x00000002; + return this; + } + /** + * + * + *
+     * Optional query-level arguments.
+     *
+     * (-- Think query statement hints. --)
+     *
+     * (-- TODO(batchik): define the api contract of using an unsupported hint --)
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 2; + */ + public Builder putAllOptions( + java.util.Map values) { + for (java.util.Map.Entry e : + values.entrySet()) { + if (e.getKey() == null || e.getValue() == null) { + throw new NullPointerException(); + } + } + internalGetMutableOptions().ensureBuilderMap().putAll(values); + bitField0_ |= 0x00000002; + return this; + } + /** + * + * + *
+     * Optional query-level arguments.
+     *
+     * (-- Think query statement hints. --)
+     *
+     * (-- TODO(batchik): define the api contract of using an unsupported hint --)
+     * 
+ * + * map<string, .google.firestore.v1.Value> options = 2; + */ + public com.google.firestore.v1.Value.Builder putOptionsBuilderIfAbsent(java.lang.String key) { + java.util.Map builderMap = + internalGetMutableOptions().ensureBuilderMap(); + com.google.firestore.v1.ValueOrBuilder entry = builderMap.get(key); + if (entry == null) { + entry = com.google.firestore.v1.Value.newBuilder(); + builderMap.put(key, entry); + } + if (entry instanceof com.google.firestore.v1.Value) { + entry = ((com.google.firestore.v1.Value) entry).toBuilder(); + builderMap.put(key, entry); + } + return (com.google.firestore.v1.Value.Builder) entry; + } + + @java.lang.Override + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.v1.StructuredPipeline) + } + + // @@protoc_insertion_point(class_scope:google.firestore.v1.StructuredPipeline) + private static final com.google.firestore.v1.StructuredPipeline DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.v1.StructuredPipeline(); + } + + public static com.google.firestore.v1.StructuredPipeline getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public StructuredPipeline parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.v1.StructuredPipeline getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/StructuredPipelineOrBuilder.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/StructuredPipelineOrBuilder.java new file mode 100644 index 000000000..b6e1c59c1 --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/StructuredPipelineOrBuilder.java @@ -0,0 +1,139 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/firestore/v1/pipeline.proto + +// Protobuf Java Version: 3.25.2 +package com.google.firestore.v1; + +public interface StructuredPipelineOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.v1.StructuredPipeline) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+   * The pipeline query to execute.
+   * 
+ * + * .google.firestore.v1.Pipeline pipeline = 1; + * + * @return Whether the pipeline field is set. + */ + boolean hasPipeline(); + /** + * + * + *
+   * The pipeline query to execute.
+   * 
+ * + * .google.firestore.v1.Pipeline pipeline = 1; + * + * @return The pipeline. + */ + com.google.firestore.v1.Pipeline getPipeline(); + /** + * + * + *
+   * The pipeline query to execute.
+   * 
+ * + * .google.firestore.v1.Pipeline pipeline = 1; + */ + com.google.firestore.v1.PipelineOrBuilder getPipelineOrBuilder(); + + /** + * + * + *
+   * Optional query-level arguments.
+   *
+   * (-- Think query statement hints. --)
+   *
+   * (-- TODO(batchik): define the api contract of using an unsupported hint --)
+   * 
+ * + * map<string, .google.firestore.v1.Value> options = 2; + */ + int getOptionsCount(); + /** + * + * + *
+   * Optional query-level arguments.
+   *
+   * (-- Think query statement hints. --)
+   *
+   * (-- TODO(batchik): define the api contract of using an unsupported hint --)
+   * 
+ * + * map<string, .google.firestore.v1.Value> options = 2; + */ + boolean containsOptions(java.lang.String key); + /** Use {@link #getOptionsMap()} instead. */ + @java.lang.Deprecated + java.util.Map getOptions(); + /** + * + * + *
+   * Optional query-level arguments.
+   *
+   * (-- Think query statement hints. --)
+   *
+   * (-- TODO(batchik): define the api contract of using an unsupported hint --)
+   * 
+ * + * map<string, .google.firestore.v1.Value> options = 2; + */ + java.util.Map getOptionsMap(); + /** + * + * + *
+   * Optional query-level arguments.
+   *
+   * (-- Think query statement hints. --)
+   *
+   * (-- TODO(batchik): define the api contract of using an unsupported hint --)
+   * 
+ * + * map<string, .google.firestore.v1.Value> options = 2; + */ + /* nullable */ + com.google.firestore.v1.Value getOptionsOrDefault( + java.lang.String key, + /* nullable */ + com.google.firestore.v1.Value defaultValue); + /** + * + * + *
+   * Optional query-level arguments.
+   *
+   * (-- Think query statement hints. --)
+   *
+   * (-- TODO(batchik): define the api contract of using an unsupported hint --)
+   * 
+ * + * map<string, .google.firestore.v1.Value> options = 2; + */ + com.google.firestore.v1.Value getOptionsOrThrow(java.lang.String key); +} diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/StructuredQuery.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/StructuredQuery.java index 2ebba9c23..0d3f509e8 100644 --- a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/StructuredQuery.java +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/StructuredQuery.java @@ -9559,6 +9559,1892 @@ public com.google.firestore.v1.StructuredQuery.Projection getDefaultInstanceForT } } + public interface FindNearestOrBuilder + extends + // @@protoc_insertion_point(interface_extends:google.firestore.v1.StructuredQuery.FindNearest) + com.google.protobuf.MessageOrBuilder { + + /** + * + * + *
+     * Required. An indexed vector field to search upon. Only documents which
+     * contain vectors whose dimensionality match the query_vector can be
+     * returned.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FieldReference vector_field = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return Whether the vectorField field is set. + */ + boolean hasVectorField(); + /** + * + * + *
+     * Required. An indexed vector field to search upon. Only documents which
+     * contain vectors whose dimensionality match the query_vector can be
+     * returned.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FieldReference vector_field = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The vectorField. + */ + com.google.firestore.v1.StructuredQuery.FieldReference getVectorField(); + /** + * + * + *
+     * Required. An indexed vector field to search upon. Only documents which
+     * contain vectors whose dimensionality match the query_vector can be
+     * returned.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FieldReference vector_field = 1 [(.google.api.field_behavior) = REQUIRED]; + * + */ + com.google.firestore.v1.StructuredQuery.FieldReferenceOrBuilder getVectorFieldOrBuilder(); + + /** + * + * + *
+     * Required. The query vector that we are searching on. Must be a vector of
+     * no more than 2048 dimensions.
+     * 
+ * + * .google.firestore.v1.Value query_vector = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return Whether the queryVector field is set. + */ + boolean hasQueryVector(); + /** + * + * + *
+     * Required. The query vector that we are searching on. Must be a vector of
+     * no more than 2048 dimensions.
+     * 
+ * + * .google.firestore.v1.Value query_vector = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The queryVector. + */ + com.google.firestore.v1.Value getQueryVector(); + /** + * + * + *
+     * Required. The query vector that we are searching on. Must be a vector of
+     * no more than 2048 dimensions.
+     * 
+ * + * .google.firestore.v1.Value query_vector = 2 [(.google.api.field_behavior) = REQUIRED]; + * + */ + com.google.firestore.v1.ValueOrBuilder getQueryVectorOrBuilder(); + + /** + * + * + *
+     * Required. The Distance Measure to use, required.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure distance_measure = 3 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The enum numeric value on the wire for distanceMeasure. + */ + int getDistanceMeasureValue(); + /** + * + * + *
+     * Required. The Distance Measure to use, required.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure distance_measure = 3 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The distanceMeasure. + */ + com.google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure getDistanceMeasure(); + + /** + * + * + *
+     * Required. The number of nearest neighbors to return. Must be a positive
+     * integer of no more than 1000.
+     * 
+ * + * .google.protobuf.Int32Value limit = 4 [(.google.api.field_behavior) = REQUIRED]; + * + * @return Whether the limit field is set. + */ + boolean hasLimit(); + /** + * + * + *
+     * Required. The number of nearest neighbors to return. Must be a positive
+     * integer of no more than 1000.
+     * 
+ * + * .google.protobuf.Int32Value limit = 4 [(.google.api.field_behavior) = REQUIRED]; + * + * @return The limit. + */ + com.google.protobuf.Int32Value getLimit(); + /** + * + * + *
+     * Required. The number of nearest neighbors to return. Must be a positive
+     * integer of no more than 1000.
+     * 
+ * + * .google.protobuf.Int32Value limit = 4 [(.google.api.field_behavior) = REQUIRED]; + */ + com.google.protobuf.Int32ValueOrBuilder getLimitOrBuilder(); + } + /** + * + * + *
+   * Nearest Neighbors search config.
+   * 
+ * + * Protobuf type {@code google.firestore.v1.StructuredQuery.FindNearest} + */ + public static final class FindNearest extends com.google.protobuf.GeneratedMessageV3 + implements + // @@protoc_insertion_point(message_implements:google.firestore.v1.StructuredQuery.FindNearest) + FindNearestOrBuilder { + private static final long serialVersionUID = 0L; + // Use FindNearest.newBuilder() to construct. + private FindNearest(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + + private FindNearest() { + distanceMeasure_ = 0; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance(UnusedPrivateParameter unused) { + return new FindNearest(); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.QueryProto + .internal_static_google_firestore_v1_StructuredQuery_FindNearest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.QueryProto + .internal_static_google_firestore_v1_StructuredQuery_FindNearest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.StructuredQuery.FindNearest.class, + com.google.firestore.v1.StructuredQuery.FindNearest.Builder.class); + } + + /** + * + * + *
+     * The distance measure to use when comparing vectors.
+     * 
+ * + * Protobuf enum {@code google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure} + */ + public enum DistanceMeasure implements com.google.protobuf.ProtocolMessageEnum { + /** + * + * + *
+       * Should not be set.
+       * 
+ * + * DISTANCE_MEASURE_UNSPECIFIED = 0; + */ + DISTANCE_MEASURE_UNSPECIFIED(0), + /** + * + * + *
+       * Measures the EUCLIDEAN distance between the vectors. See
+       * [Euclidean](https://en.wikipedia.org/wiki/Euclidean_distance) to learn
+       * more
+       * 
+ * + * EUCLIDEAN = 1; + */ + EUCLIDEAN(1), + /** + * + * + *
+       * Compares vectors based on the angle between them, which allows you to
+       * measure similarity that isn't based on the vectors magnitude.
+       * We recommend using DOT_PRODUCT with unit normalized vectors instead of
+       * COSINE distance, which is mathematically equivalent with better
+       * performance. See [Cosine
+       * Similarity](https://en.wikipedia.org/wiki/Cosine_similarity) to learn
+       * more.
+       * 
+ * + * COSINE = 2; + */ + COSINE(2), + /** + * + * + *
+       * Similar to cosine but is affected by the magnitude of the vectors. See
+       * [Dot Product](https://en.wikipedia.org/wiki/Dot_product) to learn more.
+       * 
+ * + * DOT_PRODUCT = 3; + */ + DOT_PRODUCT(3), + UNRECOGNIZED(-1), + ; + + /** + * + * + *
+       * Should not be set.
+       * 
+ * + * DISTANCE_MEASURE_UNSPECIFIED = 0; + */ + public static final int DISTANCE_MEASURE_UNSPECIFIED_VALUE = 0; + /** + * + * + *
+       * Measures the EUCLIDEAN distance between the vectors. See
+       * [Euclidean](https://en.wikipedia.org/wiki/Euclidean_distance) to learn
+       * more
+       * 
+ * + * EUCLIDEAN = 1; + */ + public static final int EUCLIDEAN_VALUE = 1; + /** + * + * + *
+       * Compares vectors based on the angle between them, which allows you to
+       * measure similarity that isn't based on the vectors magnitude.
+       * We recommend using DOT_PRODUCT with unit normalized vectors instead of
+       * COSINE distance, which is mathematically equivalent with better
+       * performance. See [Cosine
+       * Similarity](https://en.wikipedia.org/wiki/Cosine_similarity) to learn
+       * more.
+       * 
+ * + * COSINE = 2; + */ + public static final int COSINE_VALUE = 2; + /** + * + * + *
+       * Similar to cosine but is affected by the magnitude of the vectors. See
+       * [Dot Product](https://en.wikipedia.org/wiki/Dot_product) to learn more.
+       * 
+ * + * DOT_PRODUCT = 3; + */ + public static final int DOT_PRODUCT_VALUE = 3; + + public final int getNumber() { + if (this == UNRECOGNIZED) { + throw new java.lang.IllegalArgumentException( + "Can't get the number of an unknown enum value."); + } + return value; + } + + /** + * @param value The numeric wire value of the corresponding enum entry. + * @return The enum associated with the given numeric wire value. + * @deprecated Use {@link #forNumber(int)} instead. + */ + @java.lang.Deprecated + public static DistanceMeasure valueOf(int value) { + return forNumber(value); + } + + /** + * @param value The numeric wire value of the corresponding enum entry. + * @return The enum associated with the given numeric wire value. + */ + public static DistanceMeasure forNumber(int value) { + switch (value) { + case 0: + return DISTANCE_MEASURE_UNSPECIFIED; + case 1: + return EUCLIDEAN; + case 2: + return COSINE; + case 3: + return DOT_PRODUCT; + default: + return null; + } + } + + public static com.google.protobuf.Internal.EnumLiteMap + internalGetValueMap() { + return internalValueMap; + } + + private static final com.google.protobuf.Internal.EnumLiteMap + internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + public DistanceMeasure findValueByNumber(int number) { + return DistanceMeasure.forNumber(number); + } + }; + + public final com.google.protobuf.Descriptors.EnumValueDescriptor getValueDescriptor() { + if (this == UNRECOGNIZED) { + throw new java.lang.IllegalStateException( + "Can't get the descriptor of an unrecognized enum value."); + } + return getDescriptor().getValues().get(ordinal()); + } + + public final com.google.protobuf.Descriptors.EnumDescriptor getDescriptorForType() { + return getDescriptor(); + } + + public static final com.google.protobuf.Descriptors.EnumDescriptor getDescriptor() { + return com.google.firestore.v1.StructuredQuery.FindNearest.getDescriptor() + .getEnumTypes() + .get(0); + } + + private static final DistanceMeasure[] VALUES = values(); + + public static DistanceMeasure valueOf( + com.google.protobuf.Descriptors.EnumValueDescriptor desc) { + if (desc.getType() != getDescriptor()) { + throw new java.lang.IllegalArgumentException("EnumValueDescriptor is not for this type."); + } + if (desc.getIndex() == -1) { + return UNRECOGNIZED; + } + return VALUES[desc.getIndex()]; + } + + private final int value; + + private DistanceMeasure(int value) { + this.value = value; + } + + // @@protoc_insertion_point(enum_scope:google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure) + } + + private int bitField0_; + public static final int VECTOR_FIELD_FIELD_NUMBER = 1; + private com.google.firestore.v1.StructuredQuery.FieldReference vectorField_; + /** + * + * + *
+     * Required. An indexed vector field to search upon. Only documents which
+     * contain vectors whose dimensionality match the query_vector can be
+     * returned.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FieldReference vector_field = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return Whether the vectorField field is set. + */ + @java.lang.Override + public boolean hasVectorField() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * + * + *
+     * Required. An indexed vector field to search upon. Only documents which
+     * contain vectors whose dimensionality match the query_vector can be
+     * returned.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FieldReference vector_field = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The vectorField. + */ + @java.lang.Override + public com.google.firestore.v1.StructuredQuery.FieldReference getVectorField() { + return vectorField_ == null + ? com.google.firestore.v1.StructuredQuery.FieldReference.getDefaultInstance() + : vectorField_; + } + /** + * + * + *
+     * Required. An indexed vector field to search upon. Only documents which
+     * contain vectors whose dimensionality match the query_vector can be
+     * returned.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FieldReference vector_field = 1 [(.google.api.field_behavior) = REQUIRED]; + * + */ + @java.lang.Override + public com.google.firestore.v1.StructuredQuery.FieldReferenceOrBuilder + getVectorFieldOrBuilder() { + return vectorField_ == null + ? com.google.firestore.v1.StructuredQuery.FieldReference.getDefaultInstance() + : vectorField_; + } + + public static final int QUERY_VECTOR_FIELD_NUMBER = 2; + private com.google.firestore.v1.Value queryVector_; + /** + * + * + *
+     * Required. The query vector that we are searching on. Must be a vector of
+     * no more than 2048 dimensions.
+     * 
+ * + * .google.firestore.v1.Value query_vector = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return Whether the queryVector field is set. + */ + @java.lang.Override + public boolean hasQueryVector() { + return ((bitField0_ & 0x00000002) != 0); + } + /** + * + * + *
+     * Required. The query vector that we are searching on. Must be a vector of
+     * no more than 2048 dimensions.
+     * 
+ * + * .google.firestore.v1.Value query_vector = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The queryVector. + */ + @java.lang.Override + public com.google.firestore.v1.Value getQueryVector() { + return queryVector_ == null + ? com.google.firestore.v1.Value.getDefaultInstance() + : queryVector_; + } + /** + * + * + *
+     * Required. The query vector that we are searching on. Must be a vector of
+     * no more than 2048 dimensions.
+     * 
+ * + * .google.firestore.v1.Value query_vector = 2 [(.google.api.field_behavior) = REQUIRED]; + * + */ + @java.lang.Override + public com.google.firestore.v1.ValueOrBuilder getQueryVectorOrBuilder() { + return queryVector_ == null + ? com.google.firestore.v1.Value.getDefaultInstance() + : queryVector_; + } + + public static final int DISTANCE_MEASURE_FIELD_NUMBER = 3; + private int distanceMeasure_ = 0; + /** + * + * + *
+     * Required. The Distance Measure to use, required.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure distance_measure = 3 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The enum numeric value on the wire for distanceMeasure. + */ + @java.lang.Override + public int getDistanceMeasureValue() { + return distanceMeasure_; + } + /** + * + * + *
+     * Required. The Distance Measure to use, required.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure distance_measure = 3 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The distanceMeasure. + */ + @java.lang.Override + public com.google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure + getDistanceMeasure() { + com.google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure result = + com.google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure.forNumber( + distanceMeasure_); + return result == null + ? com.google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure.UNRECOGNIZED + : result; + } + + public static final int LIMIT_FIELD_NUMBER = 4; + private com.google.protobuf.Int32Value limit_; + /** + * + * + *
+     * Required. The number of nearest neighbors to return. Must be a positive
+     * integer of no more than 1000.
+     * 
+ * + * .google.protobuf.Int32Value limit = 4 [(.google.api.field_behavior) = REQUIRED]; + * + * @return Whether the limit field is set. + */ + @java.lang.Override + public boolean hasLimit() { + return ((bitField0_ & 0x00000004) != 0); + } + /** + * + * + *
+     * Required. The number of nearest neighbors to return. Must be a positive
+     * integer of no more than 1000.
+     * 
+ * + * .google.protobuf.Int32Value limit = 4 [(.google.api.field_behavior) = REQUIRED]; + * + * @return The limit. + */ + @java.lang.Override + public com.google.protobuf.Int32Value getLimit() { + return limit_ == null ? com.google.protobuf.Int32Value.getDefaultInstance() : limit_; + } + /** + * + * + *
+     * Required. The number of nearest neighbors to return. Must be a positive
+     * integer of no more than 1000.
+     * 
+ * + * .google.protobuf.Int32Value limit = 4 [(.google.api.field_behavior) = REQUIRED]; + */ + @java.lang.Override + public com.google.protobuf.Int32ValueOrBuilder getLimitOrBuilder() { + return limit_ == null ? com.google.protobuf.Int32Value.getDefaultInstance() : limit_; + } + + private byte memoizedIsInitialized = -1; + + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (((bitField0_ & 0x00000001) != 0)) { + output.writeMessage(1, getVectorField()); + } + if (((bitField0_ & 0x00000002) != 0)) { + output.writeMessage(2, getQueryVector()); + } + if (distanceMeasure_ + != com.google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure + .DISTANCE_MEASURE_UNSPECIFIED + .getNumber()) { + output.writeEnum(3, distanceMeasure_); + } + if (((bitField0_ & 0x00000004) != 0)) { + output.writeMessage(4, getLimit()); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(1, getVectorField()); + } + if (((bitField0_ & 0x00000002) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(2, getQueryVector()); + } + if (distanceMeasure_ + != com.google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure + .DISTANCE_MEASURE_UNSPECIFIED + .getNumber()) { + size += com.google.protobuf.CodedOutputStream.computeEnumSize(3, distanceMeasure_); + } + if (((bitField0_ & 0x00000004) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(4, getLimit()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.google.firestore.v1.StructuredQuery.FindNearest)) { + return super.equals(obj); + } + com.google.firestore.v1.StructuredQuery.FindNearest other = + (com.google.firestore.v1.StructuredQuery.FindNearest) obj; + + if (hasVectorField() != other.hasVectorField()) return false; + if (hasVectorField()) { + if (!getVectorField().equals(other.getVectorField())) return false; + } + if (hasQueryVector() != other.hasQueryVector()) return false; + if (hasQueryVector()) { + if (!getQueryVector().equals(other.getQueryVector())) return false; + } + if (distanceMeasure_ != other.distanceMeasure_) return false; + if (hasLimit() != other.hasLimit()) return false; + if (hasLimit()) { + if (!getLimit().equals(other.getLimit())) return false; + } + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (hasVectorField()) { + hash = (37 * hash) + VECTOR_FIELD_FIELD_NUMBER; + hash = (53 * hash) + getVectorField().hashCode(); + } + if (hasQueryVector()) { + hash = (37 * hash) + QUERY_VECTOR_FIELD_NUMBER; + hash = (53 * hash) + getQueryVector().hashCode(); + } + hash = (37 * hash) + DISTANCE_MEASURE_FIELD_NUMBER; + hash = (53 * hash) + distanceMeasure_; + if (hasLimit()) { + hash = (37 * hash) + LIMIT_FIELD_NUMBER; + hash = (53 * hash) + getLimit().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.google.firestore.v1.StructuredQuery.FindNearest parseFrom( + java.nio.ByteBuffer data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.StructuredQuery.FindNearest parseFrom( + java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.StructuredQuery.FindNearest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.StructuredQuery.FindNearest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.StructuredQuery.FindNearest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.google.firestore.v1.StructuredQuery.FindNearest parseFrom( + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.google.firestore.v1.StructuredQuery.FindNearest parseFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.StructuredQuery.FindNearest parseFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.StructuredQuery.FindNearest parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.StructuredQuery.FindNearest parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( + PARSER, input, extensionRegistry); + } + + public static com.google.firestore.v1.StructuredQuery.FindNearest parseFrom( + com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); + } + + public static com.google.firestore.v1.StructuredQuery.FindNearest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3.parseWithIOException( + PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder( + com.google.firestore.v1.StructuredQuery.FindNearest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * + * + *
+     * Nearest Neighbors search config.
+     * 
+ * + * Protobuf type {@code google.firestore.v1.StructuredQuery.FindNearest} + */ + public static final class Builder + extends com.google.protobuf.GeneratedMessageV3.Builder + implements + // @@protoc_insertion_point(builder_implements:google.firestore.v1.StructuredQuery.FindNearest) + com.google.firestore.v1.StructuredQuery.FindNearestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.firestore.v1.QueryProto + .internal_static_google_firestore_v1_StructuredQuery_FindNearest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.google.firestore.v1.QueryProto + .internal_static_google_firestore_v1_StructuredQuery_FindNearest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.google.firestore.v1.StructuredQuery.FindNearest.class, + com.google.firestore.v1.StructuredQuery.FindNearest.Builder.class); + } + + // Construct using com.google.firestore.v1.StructuredQuery.FindNearest.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) { + getVectorFieldFieldBuilder(); + getQueryVectorFieldBuilder(); + getLimitFieldBuilder(); + } + } + + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + vectorField_ = null; + if (vectorFieldBuilder_ != null) { + vectorFieldBuilder_.dispose(); + vectorFieldBuilder_ = null; + } + queryVector_ = null; + if (queryVectorBuilder_ != null) { + queryVectorBuilder_.dispose(); + queryVectorBuilder_ = null; + } + distanceMeasure_ = 0; + limit_ = null; + if (limitBuilder_ != null) { + limitBuilder_.dispose(); + limitBuilder_ = null; + } + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.firestore.v1.QueryProto + .internal_static_google_firestore_v1_StructuredQuery_FindNearest_descriptor; + } + + @java.lang.Override + public com.google.firestore.v1.StructuredQuery.FindNearest getDefaultInstanceForType() { + return com.google.firestore.v1.StructuredQuery.FindNearest.getDefaultInstance(); + } + + @java.lang.Override + public com.google.firestore.v1.StructuredQuery.FindNearest build() { + com.google.firestore.v1.StructuredQuery.FindNearest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.google.firestore.v1.StructuredQuery.FindNearest buildPartial() { + com.google.firestore.v1.StructuredQuery.FindNearest result = + new com.google.firestore.v1.StructuredQuery.FindNearest(this); + if (bitField0_ != 0) { + buildPartial0(result); + } + onBuilt(); + return result; + } + + private void buildPartial0(com.google.firestore.v1.StructuredQuery.FindNearest result) { + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.vectorField_ = + vectorFieldBuilder_ == null ? vectorField_ : vectorFieldBuilder_.build(); + to_bitField0_ |= 0x00000001; + } + if (((from_bitField0_ & 0x00000002) != 0)) { + result.queryVector_ = + queryVectorBuilder_ == null ? queryVector_ : queryVectorBuilder_.build(); + to_bitField0_ |= 0x00000002; + } + if (((from_bitField0_ & 0x00000004) != 0)) { + result.distanceMeasure_ = distanceMeasure_; + } + if (((from_bitField0_ & 0x00000008) != 0)) { + result.limit_ = limitBuilder_ == null ? limit_ : limitBuilder_.build(); + to_bitField0_ |= 0x00000004; + } + result.bitField0_ |= to_bitField0_; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.setField(field, value); + } + + @java.lang.Override + public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + + @java.lang.Override + public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, + java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { + return super.addRepeatedField(field, value); + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.google.firestore.v1.StructuredQuery.FindNearest) { + return mergeFrom((com.google.firestore.v1.StructuredQuery.FindNearest) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.google.firestore.v1.StructuredQuery.FindNearest other) { + if (other == com.google.firestore.v1.StructuredQuery.FindNearest.getDefaultInstance()) + return this; + if (other.hasVectorField()) { + mergeVectorField(other.getVectorField()); + } + if (other.hasQueryVector()) { + mergeQueryVector(other.getQueryVector()); + } + if (other.distanceMeasure_ != 0) { + setDistanceMeasureValue(other.getDistanceMeasureValue()); + } + if (other.hasLimit()) { + mergeLimit(other.getLimit()); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: + { + input.readMessage(getVectorFieldFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000001; + break; + } // case 10 + case 18: + { + input.readMessage(getQueryVectorFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000002; + break; + } // case 18 + case 24: + { + distanceMeasure_ = input.readEnum(); + bitField0_ |= 0x00000004; + break; + } // case 24 + case 34: + { + input.readMessage(getLimitFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000008; + break; + } // case 34 + default: + { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + private int bitField0_; + + private com.google.firestore.v1.StructuredQuery.FieldReference vectorField_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.StructuredQuery.FieldReference, + com.google.firestore.v1.StructuredQuery.FieldReference.Builder, + com.google.firestore.v1.StructuredQuery.FieldReferenceOrBuilder> + vectorFieldBuilder_; + /** + * + * + *
+       * Required. An indexed vector field to search upon. Only documents which
+       * contain vectors whose dimensionality match the query_vector can be
+       * returned.
+       * 
+ * + * + * .google.firestore.v1.StructuredQuery.FieldReference vector_field = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return Whether the vectorField field is set. + */ + public boolean hasVectorField() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * + * + *
+       * Required. An indexed vector field to search upon. Only documents which
+       * contain vectors whose dimensionality match the query_vector can be
+       * returned.
+       * 
+ * + * + * .google.firestore.v1.StructuredQuery.FieldReference vector_field = 1 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The vectorField. + */ + public com.google.firestore.v1.StructuredQuery.FieldReference getVectorField() { + if (vectorFieldBuilder_ == null) { + return vectorField_ == null + ? com.google.firestore.v1.StructuredQuery.FieldReference.getDefaultInstance() + : vectorField_; + } else { + return vectorFieldBuilder_.getMessage(); + } + } + /** + * + * + *
+       * Required. An indexed vector field to search upon. Only documents which
+       * contain vectors whose dimensionality match the query_vector can be
+       * returned.
+       * 
+ * + * + * .google.firestore.v1.StructuredQuery.FieldReference vector_field = 1 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder setVectorField(com.google.firestore.v1.StructuredQuery.FieldReference value) { + if (vectorFieldBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + vectorField_ = value; + } else { + vectorFieldBuilder_.setMessage(value); + } + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+       * Required. An indexed vector field to search upon. Only documents which
+       * contain vectors whose dimensionality match the query_vector can be
+       * returned.
+       * 
+ * + * + * .google.firestore.v1.StructuredQuery.FieldReference vector_field = 1 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder setVectorField( + com.google.firestore.v1.StructuredQuery.FieldReference.Builder builderForValue) { + if (vectorFieldBuilder_ == null) { + vectorField_ = builderForValue.build(); + } else { + vectorFieldBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * + * + *
+       * Required. An indexed vector field to search upon. Only documents which
+       * contain vectors whose dimensionality match the query_vector can be
+       * returned.
+       * 
+ * + * + * .google.firestore.v1.StructuredQuery.FieldReference vector_field = 1 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder mergeVectorField( + com.google.firestore.v1.StructuredQuery.FieldReference value) { + if (vectorFieldBuilder_ == null) { + if (((bitField0_ & 0x00000001) != 0) + && vectorField_ != null + && vectorField_ + != com.google.firestore.v1.StructuredQuery.FieldReference.getDefaultInstance()) { + getVectorFieldBuilder().mergeFrom(value); + } else { + vectorField_ = value; + } + } else { + vectorFieldBuilder_.mergeFrom(value); + } + if (vectorField_ != null) { + bitField0_ |= 0x00000001; + onChanged(); + } + return this; + } + /** + * + * + *
+       * Required. An indexed vector field to search upon. Only documents which
+       * contain vectors whose dimensionality match the query_vector can be
+       * returned.
+       * 
+ * + * + * .google.firestore.v1.StructuredQuery.FieldReference vector_field = 1 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder clearVectorField() { + bitField0_ = (bitField0_ & ~0x00000001); + vectorField_ = null; + if (vectorFieldBuilder_ != null) { + vectorFieldBuilder_.dispose(); + vectorFieldBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+       * Required. An indexed vector field to search upon. Only documents which
+       * contain vectors whose dimensionality match the query_vector can be
+       * returned.
+       * 
+ * + * + * .google.firestore.v1.StructuredQuery.FieldReference vector_field = 1 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public com.google.firestore.v1.StructuredQuery.FieldReference.Builder + getVectorFieldBuilder() { + bitField0_ |= 0x00000001; + onChanged(); + return getVectorFieldFieldBuilder().getBuilder(); + } + /** + * + * + *
+       * Required. An indexed vector field to search upon. Only documents which
+       * contain vectors whose dimensionality match the query_vector can be
+       * returned.
+       * 
+ * + * + * .google.firestore.v1.StructuredQuery.FieldReference vector_field = 1 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public com.google.firestore.v1.StructuredQuery.FieldReferenceOrBuilder + getVectorFieldOrBuilder() { + if (vectorFieldBuilder_ != null) { + return vectorFieldBuilder_.getMessageOrBuilder(); + } else { + return vectorField_ == null + ? com.google.firestore.v1.StructuredQuery.FieldReference.getDefaultInstance() + : vectorField_; + } + } + /** + * + * + *
+       * Required. An indexed vector field to search upon. Only documents which
+       * contain vectors whose dimensionality match the query_vector can be
+       * returned.
+       * 
+ * + * + * .google.firestore.v1.StructuredQuery.FieldReference vector_field = 1 [(.google.api.field_behavior) = REQUIRED]; + * + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.StructuredQuery.FieldReference, + com.google.firestore.v1.StructuredQuery.FieldReference.Builder, + com.google.firestore.v1.StructuredQuery.FieldReferenceOrBuilder> + getVectorFieldFieldBuilder() { + if (vectorFieldBuilder_ == null) { + vectorFieldBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.StructuredQuery.FieldReference, + com.google.firestore.v1.StructuredQuery.FieldReference.Builder, + com.google.firestore.v1.StructuredQuery.FieldReferenceOrBuilder>( + getVectorField(), getParentForChildren(), isClean()); + vectorField_ = null; + } + return vectorFieldBuilder_; + } + + private com.google.firestore.v1.Value queryVector_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.Value, + com.google.firestore.v1.Value.Builder, + com.google.firestore.v1.ValueOrBuilder> + queryVectorBuilder_; + /** + * + * + *
+       * Required. The query vector that we are searching on. Must be a vector of
+       * no more than 2048 dimensions.
+       * 
+ * + * + * .google.firestore.v1.Value query_vector = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return Whether the queryVector field is set. + */ + public boolean hasQueryVector() { + return ((bitField0_ & 0x00000002) != 0); + } + /** + * + * + *
+       * Required. The query vector that we are searching on. Must be a vector of
+       * no more than 2048 dimensions.
+       * 
+ * + * + * .google.firestore.v1.Value query_vector = 2 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The queryVector. + */ + public com.google.firestore.v1.Value getQueryVector() { + if (queryVectorBuilder_ == null) { + return queryVector_ == null + ? com.google.firestore.v1.Value.getDefaultInstance() + : queryVector_; + } else { + return queryVectorBuilder_.getMessage(); + } + } + /** + * + * + *
+       * Required. The query vector that we are searching on. Must be a vector of
+       * no more than 2048 dimensions.
+       * 
+ * + * + * .google.firestore.v1.Value query_vector = 2 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder setQueryVector(com.google.firestore.v1.Value value) { + if (queryVectorBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + queryVector_ = value; + } else { + queryVectorBuilder_.setMessage(value); + } + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+       * Required. The query vector that we are searching on. Must be a vector of
+       * no more than 2048 dimensions.
+       * 
+ * + * + * .google.firestore.v1.Value query_vector = 2 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder setQueryVector(com.google.firestore.v1.Value.Builder builderForValue) { + if (queryVectorBuilder_ == null) { + queryVector_ = builderForValue.build(); + } else { + queryVectorBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * + * + *
+       * Required. The query vector that we are searching on. Must be a vector of
+       * no more than 2048 dimensions.
+       * 
+ * + * + * .google.firestore.v1.Value query_vector = 2 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder mergeQueryVector(com.google.firestore.v1.Value value) { + if (queryVectorBuilder_ == null) { + if (((bitField0_ & 0x00000002) != 0) + && queryVector_ != null + && queryVector_ != com.google.firestore.v1.Value.getDefaultInstance()) { + getQueryVectorBuilder().mergeFrom(value); + } else { + queryVector_ = value; + } + } else { + queryVectorBuilder_.mergeFrom(value); + } + if (queryVector_ != null) { + bitField0_ |= 0x00000002; + onChanged(); + } + return this; + } + /** + * + * + *
+       * Required. The query vector that we are searching on. Must be a vector of
+       * no more than 2048 dimensions.
+       * 
+ * + * + * .google.firestore.v1.Value query_vector = 2 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder clearQueryVector() { + bitField0_ = (bitField0_ & ~0x00000002); + queryVector_ = null; + if (queryVectorBuilder_ != null) { + queryVectorBuilder_.dispose(); + queryVectorBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+       * Required. The query vector that we are searching on. Must be a vector of
+       * no more than 2048 dimensions.
+       * 
+ * + * + * .google.firestore.v1.Value query_vector = 2 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public com.google.firestore.v1.Value.Builder getQueryVectorBuilder() { + bitField0_ |= 0x00000002; + onChanged(); + return getQueryVectorFieldBuilder().getBuilder(); + } + /** + * + * + *
+       * Required. The query vector that we are searching on. Must be a vector of
+       * no more than 2048 dimensions.
+       * 
+ * + * + * .google.firestore.v1.Value query_vector = 2 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public com.google.firestore.v1.ValueOrBuilder getQueryVectorOrBuilder() { + if (queryVectorBuilder_ != null) { + return queryVectorBuilder_.getMessageOrBuilder(); + } else { + return queryVector_ == null + ? com.google.firestore.v1.Value.getDefaultInstance() + : queryVector_; + } + } + /** + * + * + *
+       * Required. The query vector that we are searching on. Must be a vector of
+       * no more than 2048 dimensions.
+       * 
+ * + * + * .google.firestore.v1.Value query_vector = 2 [(.google.api.field_behavior) = REQUIRED]; + * + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.Value, + com.google.firestore.v1.Value.Builder, + com.google.firestore.v1.ValueOrBuilder> + getQueryVectorFieldBuilder() { + if (queryVectorBuilder_ == null) { + queryVectorBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.Value, + com.google.firestore.v1.Value.Builder, + com.google.firestore.v1.ValueOrBuilder>( + getQueryVector(), getParentForChildren(), isClean()); + queryVector_ = null; + } + return queryVectorBuilder_; + } + + private int distanceMeasure_ = 0; + /** + * + * + *
+       * Required. The Distance Measure to use, required.
+       * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure distance_measure = 3 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The enum numeric value on the wire for distanceMeasure. + */ + @java.lang.Override + public int getDistanceMeasureValue() { + return distanceMeasure_; + } + /** + * + * + *
+       * Required. The Distance Measure to use, required.
+       * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure distance_measure = 3 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @param value The enum numeric value on the wire for distanceMeasure to set. + * @return This builder for chaining. + */ + public Builder setDistanceMeasureValue(int value) { + distanceMeasure_ = value; + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + /** + * + * + *
+       * Required. The Distance Measure to use, required.
+       * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure distance_measure = 3 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The distanceMeasure. + */ + @java.lang.Override + public com.google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure + getDistanceMeasure() { + com.google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure result = + com.google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure.forNumber( + distanceMeasure_); + return result == null + ? com.google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure.UNRECOGNIZED + : result; + } + /** + * + * + *
+       * Required. The Distance Measure to use, required.
+       * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure distance_measure = 3 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @param value The distanceMeasure to set. + * @return This builder for chaining. + */ + public Builder setDistanceMeasure( + com.google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + distanceMeasure_ = value.getNumber(); + onChanged(); + return this; + } + /** + * + * + *
+       * Required. The Distance Measure to use, required.
+       * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure distance_measure = 3 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return This builder for chaining. + */ + public Builder clearDistanceMeasure() { + bitField0_ = (bitField0_ & ~0x00000004); + distanceMeasure_ = 0; + onChanged(); + return this; + } + + private com.google.protobuf.Int32Value limit_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Int32Value, + com.google.protobuf.Int32Value.Builder, + com.google.protobuf.Int32ValueOrBuilder> + limitBuilder_; + /** + * + * + *
+       * Required. The number of nearest neighbors to return. Must be a positive
+       * integer of no more than 1000.
+       * 
+ * + * .google.protobuf.Int32Value limit = 4 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return Whether the limit field is set. + */ + public boolean hasLimit() { + return ((bitField0_ & 0x00000008) != 0); + } + /** + * + * + *
+       * Required. The number of nearest neighbors to return. Must be a positive
+       * integer of no more than 1000.
+       * 
+ * + * .google.protobuf.Int32Value limit = 4 [(.google.api.field_behavior) = REQUIRED]; + * + * + * @return The limit. + */ + public com.google.protobuf.Int32Value getLimit() { + if (limitBuilder_ == null) { + return limit_ == null ? com.google.protobuf.Int32Value.getDefaultInstance() : limit_; + } else { + return limitBuilder_.getMessage(); + } + } + /** + * + * + *
+       * Required. The number of nearest neighbors to return. Must be a positive
+       * integer of no more than 1000.
+       * 
+ * + * .google.protobuf.Int32Value limit = 4 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder setLimit(com.google.protobuf.Int32Value value) { + if (limitBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + limit_ = value; + } else { + limitBuilder_.setMessage(value); + } + bitField0_ |= 0x00000008; + onChanged(); + return this; + } + /** + * + * + *
+       * Required. The number of nearest neighbors to return. Must be a positive
+       * integer of no more than 1000.
+       * 
+ * + * .google.protobuf.Int32Value limit = 4 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder setLimit(com.google.protobuf.Int32Value.Builder builderForValue) { + if (limitBuilder_ == null) { + limit_ = builderForValue.build(); + } else { + limitBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000008; + onChanged(); + return this; + } + /** + * + * + *
+       * Required. The number of nearest neighbors to return. Must be a positive
+       * integer of no more than 1000.
+       * 
+ * + * .google.protobuf.Int32Value limit = 4 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder mergeLimit(com.google.protobuf.Int32Value value) { + if (limitBuilder_ == null) { + if (((bitField0_ & 0x00000008) != 0) + && limit_ != null + && limit_ != com.google.protobuf.Int32Value.getDefaultInstance()) { + getLimitBuilder().mergeFrom(value); + } else { + limit_ = value; + } + } else { + limitBuilder_.mergeFrom(value); + } + if (limit_ != null) { + bitField0_ |= 0x00000008; + onChanged(); + } + return this; + } + /** + * + * + *
+       * Required. The number of nearest neighbors to return. Must be a positive
+       * integer of no more than 1000.
+       * 
+ * + * .google.protobuf.Int32Value limit = 4 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public Builder clearLimit() { + bitField0_ = (bitField0_ & ~0x00000008); + limit_ = null; + if (limitBuilder_ != null) { + limitBuilder_.dispose(); + limitBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+       * Required. The number of nearest neighbors to return. Must be a positive
+       * integer of no more than 1000.
+       * 
+ * + * .google.protobuf.Int32Value limit = 4 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public com.google.protobuf.Int32Value.Builder getLimitBuilder() { + bitField0_ |= 0x00000008; + onChanged(); + return getLimitFieldBuilder().getBuilder(); + } + /** + * + * + *
+       * Required. The number of nearest neighbors to return. Must be a positive
+       * integer of no more than 1000.
+       * 
+ * + * .google.protobuf.Int32Value limit = 4 [(.google.api.field_behavior) = REQUIRED]; + * + */ + public com.google.protobuf.Int32ValueOrBuilder getLimitOrBuilder() { + if (limitBuilder_ != null) { + return limitBuilder_.getMessageOrBuilder(); + } else { + return limit_ == null ? com.google.protobuf.Int32Value.getDefaultInstance() : limit_; + } + } + /** + * + * + *
+       * Required. The number of nearest neighbors to return. Must be a positive
+       * integer of no more than 1000.
+       * 
+ * + * .google.protobuf.Int32Value limit = 4 [(.google.api.field_behavior) = REQUIRED]; + * + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Int32Value, + com.google.protobuf.Int32Value.Builder, + com.google.protobuf.Int32ValueOrBuilder> + getLimitFieldBuilder() { + if (limitBuilder_ == null) { + limitBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.protobuf.Int32Value, + com.google.protobuf.Int32Value.Builder, + com.google.protobuf.Int32ValueOrBuilder>( + getLimit(), getParentForChildren(), isClean()); + limit_ = null; + } + return limitBuilder_; + } + + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + // @@protoc_insertion_point(builder_scope:google.firestore.v1.StructuredQuery.FindNearest) + } + + // @@protoc_insertion_point(class_scope:google.firestore.v1.StructuredQuery.FindNearest) + private static final com.google.firestore.v1.StructuredQuery.FindNearest DEFAULT_INSTANCE; + + static { + DEFAULT_INSTANCE = new com.google.firestore.v1.StructuredQuery.FindNearest(); + } + + public static com.google.firestore.v1.StructuredQuery.FindNearest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + @java.lang.Override + public FindNearest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException() + .setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.google.firestore.v1.StructuredQuery.FindNearest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + } + private int bitField0_; public static final int SELECT_FIELD_NUMBER = 1; private com.google.firestore.v1.StructuredQuery.Projection select_; @@ -10206,6 +12092,74 @@ public com.google.protobuf.Int32ValueOrBuilder getLimitOrBuilder() { return limit_ == null ? com.google.protobuf.Int32Value.getDefaultInstance() : limit_; } + public static final int FIND_NEAREST_FIELD_NUMBER = 9; + private com.google.firestore.v1.StructuredQuery.FindNearest findNearest_; + /** + * + * + *
+   * Optional. A potential Nearest Neighbors Search.
+   *
+   * Applies after all other filters and ordering.
+   *
+   * Finds the closest vector embeddings to the given query vector.
+   * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest find_nearest = 9 [(.google.api.field_behavior) = OPTIONAL]; + * + * + * @return Whether the findNearest field is set. + */ + @java.lang.Override + public boolean hasFindNearest() { + return ((bitField0_ & 0x00000020) != 0); + } + /** + * + * + *
+   * Optional. A potential Nearest Neighbors Search.
+   *
+   * Applies after all other filters and ordering.
+   *
+   * Finds the closest vector embeddings to the given query vector.
+   * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest find_nearest = 9 [(.google.api.field_behavior) = OPTIONAL]; + * + * + * @return The findNearest. + */ + @java.lang.Override + public com.google.firestore.v1.StructuredQuery.FindNearest getFindNearest() { + return findNearest_ == null + ? com.google.firestore.v1.StructuredQuery.FindNearest.getDefaultInstance() + : findNearest_; + } + /** + * + * + *
+   * Optional. A potential Nearest Neighbors Search.
+   *
+   * Applies after all other filters and ordering.
+   *
+   * Finds the closest vector embeddings to the given query vector.
+   * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest find_nearest = 9 [(.google.api.field_behavior) = OPTIONAL]; + * + */ + @java.lang.Override + public com.google.firestore.v1.StructuredQuery.FindNearestOrBuilder getFindNearestOrBuilder() { + return findNearest_ == null + ? com.google.firestore.v1.StructuredQuery.FindNearest.getDefaultInstance() + : findNearest_; + } + private byte memoizedIsInitialized = -1; @java.lang.Override @@ -10244,6 +12198,9 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io if (((bitField0_ & 0x00000008) != 0)) { output.writeMessage(8, getEndAt()); } + if (((bitField0_ & 0x00000020) != 0)) { + output.writeMessage(9, getFindNearest()); + } getUnknownFields().writeTo(output); } @@ -10277,6 +12234,9 @@ public int getSerializedSize() { if (((bitField0_ & 0x00000008) != 0)) { size += com.google.protobuf.CodedOutputStream.computeMessageSize(8, getEndAt()); } + if (((bitField0_ & 0x00000020) != 0)) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(9, getFindNearest()); + } size += getUnknownFields().getSerializedSize(); memoizedSize = size; return size; @@ -10315,6 +12275,10 @@ public boolean equals(final java.lang.Object obj) { if (hasLimit()) { if (!getLimit().equals(other.getLimit())) return false; } + if (hasFindNearest() != other.hasFindNearest()) return false; + if (hasFindNearest()) { + if (!getFindNearest().equals(other.getFindNearest())) return false; + } if (!getUnknownFields().equals(other.getUnknownFields())) return false; return true; } @@ -10356,6 +12320,10 @@ public int hashCode() { hash = (37 * hash) + LIMIT_FIELD_NUMBER; hash = (53 * hash) + getLimit().hashCode(); } + if (hasFindNearest()) { + hash = (37 * hash) + FIND_NEAREST_FIELD_NUMBER; + hash = (53 * hash) + getFindNearest().hashCode(); + } hash = (29 * hash) + getUnknownFields().hashCode(); memoizedHashCode = hash; return hash; @@ -10511,6 +12479,7 @@ private void maybeForceBuilderInitialization() { getStartAtFieldBuilder(); getEndAtFieldBuilder(); getLimitFieldBuilder(); + getFindNearestFieldBuilder(); } } @@ -10558,6 +12527,11 @@ public Builder clear() { limitBuilder_.dispose(); limitBuilder_ = null; } + findNearest_ = null; + if (findNearestBuilder_ != null) { + findNearestBuilder_.dispose(); + findNearestBuilder_ = null; + } return this; } @@ -10640,6 +12614,11 @@ private void buildPartial0(com.google.firestore.v1.StructuredQuery result) { result.limit_ = limitBuilder_ == null ? limit_ : limitBuilder_.build(); to_bitField0_ |= 0x00000010; } + if (((from_bitField0_ & 0x00000100) != 0)) { + result.findNearest_ = + findNearestBuilder_ == null ? findNearest_ : findNearestBuilder_.build(); + to_bitField0_ |= 0x00000020; + } result.bitField0_ |= to_bitField0_; } @@ -10760,6 +12739,9 @@ public Builder mergeFrom(com.google.firestore.v1.StructuredQuery other) { if (other.hasLimit()) { mergeLimit(other.getLimit()); } + if (other.hasFindNearest()) { + mergeFindNearest(other.getFindNearest()); + } this.mergeUnknownFields(other.getUnknownFields()); onChanged(); return this; @@ -10849,6 +12831,12 @@ public Builder mergeFrom( bitField0_ |= 0x00000020; break; } // case 66 + case 74: + { + input.readMessage(getFindNearestFieldBuilder().getBuilder(), extensionRegistry); + bitField0_ |= 0x00000100; + break; + } // case 74 default: { if (!super.parseUnknownField(input, extensionRegistry, tag)) { @@ -13346,6 +15334,247 @@ public com.google.protobuf.Int32ValueOrBuilder getLimitOrBuilder() { return limitBuilder_; } + private com.google.firestore.v1.StructuredQuery.FindNearest findNearest_; + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.StructuredQuery.FindNearest, + com.google.firestore.v1.StructuredQuery.FindNearest.Builder, + com.google.firestore.v1.StructuredQuery.FindNearestOrBuilder> + findNearestBuilder_; + /** + * + * + *
+     * Optional. A potential Nearest Neighbors Search.
+     *
+     * Applies after all other filters and ordering.
+     *
+     * Finds the closest vector embeddings to the given query vector.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest find_nearest = 9 [(.google.api.field_behavior) = OPTIONAL]; + * + * + * @return Whether the findNearest field is set. + */ + public boolean hasFindNearest() { + return ((bitField0_ & 0x00000100) != 0); + } + /** + * + * + *
+     * Optional. A potential Nearest Neighbors Search.
+     *
+     * Applies after all other filters and ordering.
+     *
+     * Finds the closest vector embeddings to the given query vector.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest find_nearest = 9 [(.google.api.field_behavior) = OPTIONAL]; + * + * + * @return The findNearest. + */ + public com.google.firestore.v1.StructuredQuery.FindNearest getFindNearest() { + if (findNearestBuilder_ == null) { + return findNearest_ == null + ? com.google.firestore.v1.StructuredQuery.FindNearest.getDefaultInstance() + : findNearest_; + } else { + return findNearestBuilder_.getMessage(); + } + } + /** + * + * + *
+     * Optional. A potential Nearest Neighbors Search.
+     *
+     * Applies after all other filters and ordering.
+     *
+     * Finds the closest vector embeddings to the given query vector.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest find_nearest = 9 [(.google.api.field_behavior) = OPTIONAL]; + * + */ + public Builder setFindNearest(com.google.firestore.v1.StructuredQuery.FindNearest value) { + if (findNearestBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + findNearest_ = value; + } else { + findNearestBuilder_.setMessage(value); + } + bitField0_ |= 0x00000100; + onChanged(); + return this; + } + /** + * + * + *
+     * Optional. A potential Nearest Neighbors Search.
+     *
+     * Applies after all other filters and ordering.
+     *
+     * Finds the closest vector embeddings to the given query vector.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest find_nearest = 9 [(.google.api.field_behavior) = OPTIONAL]; + * + */ + public Builder setFindNearest( + com.google.firestore.v1.StructuredQuery.FindNearest.Builder builderForValue) { + if (findNearestBuilder_ == null) { + findNearest_ = builderForValue.build(); + } else { + findNearestBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000100; + onChanged(); + return this; + } + /** + * + * + *
+     * Optional. A potential Nearest Neighbors Search.
+     *
+     * Applies after all other filters and ordering.
+     *
+     * Finds the closest vector embeddings to the given query vector.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest find_nearest = 9 [(.google.api.field_behavior) = OPTIONAL]; + * + */ + public Builder mergeFindNearest(com.google.firestore.v1.StructuredQuery.FindNearest value) { + if (findNearestBuilder_ == null) { + if (((bitField0_ & 0x00000100) != 0) + && findNearest_ != null + && findNearest_ + != com.google.firestore.v1.StructuredQuery.FindNearest.getDefaultInstance()) { + getFindNearestBuilder().mergeFrom(value); + } else { + findNearest_ = value; + } + } else { + findNearestBuilder_.mergeFrom(value); + } + if (findNearest_ != null) { + bitField0_ |= 0x00000100; + onChanged(); + } + return this; + } + /** + * + * + *
+     * Optional. A potential Nearest Neighbors Search.
+     *
+     * Applies after all other filters and ordering.
+     *
+     * Finds the closest vector embeddings to the given query vector.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest find_nearest = 9 [(.google.api.field_behavior) = OPTIONAL]; + * + */ + public Builder clearFindNearest() { + bitField0_ = (bitField0_ & ~0x00000100); + findNearest_ = null; + if (findNearestBuilder_ != null) { + findNearestBuilder_.dispose(); + findNearestBuilder_ = null; + } + onChanged(); + return this; + } + /** + * + * + *
+     * Optional. A potential Nearest Neighbors Search.
+     *
+     * Applies after all other filters and ordering.
+     *
+     * Finds the closest vector embeddings to the given query vector.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest find_nearest = 9 [(.google.api.field_behavior) = OPTIONAL]; + * + */ + public com.google.firestore.v1.StructuredQuery.FindNearest.Builder getFindNearestBuilder() { + bitField0_ |= 0x00000100; + onChanged(); + return getFindNearestFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * Optional. A potential Nearest Neighbors Search.
+     *
+     * Applies after all other filters and ordering.
+     *
+     * Finds the closest vector embeddings to the given query vector.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest find_nearest = 9 [(.google.api.field_behavior) = OPTIONAL]; + * + */ + public com.google.firestore.v1.StructuredQuery.FindNearestOrBuilder getFindNearestOrBuilder() { + if (findNearestBuilder_ != null) { + return findNearestBuilder_.getMessageOrBuilder(); + } else { + return findNearest_ == null + ? com.google.firestore.v1.StructuredQuery.FindNearest.getDefaultInstance() + : findNearest_; + } + } + /** + * + * + *
+     * Optional. A potential Nearest Neighbors Search.
+     *
+     * Applies after all other filters and ordering.
+     *
+     * Finds the closest vector embeddings to the given query vector.
+     * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest find_nearest = 9 [(.google.api.field_behavior) = OPTIONAL]; + * + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.StructuredQuery.FindNearest, + com.google.firestore.v1.StructuredQuery.FindNearest.Builder, + com.google.firestore.v1.StructuredQuery.FindNearestOrBuilder> + getFindNearestFieldBuilder() { + if (findNearestBuilder_ == null) { + findNearestBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.StructuredQuery.FindNearest, + com.google.firestore.v1.StructuredQuery.FindNearest.Builder, + com.google.firestore.v1.StructuredQuery.FindNearestOrBuilder>( + getFindNearest(), getParentForChildren(), isClean()); + findNearest_ = null; + } + return findNearestBuilder_; + } + @java.lang.Override public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { return super.setUnknownFields(unknownFields); diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/StructuredQueryOrBuilder.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/StructuredQueryOrBuilder.java index b22f484b5..1fa612379 100644 --- a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/StructuredQueryOrBuilder.java +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/StructuredQueryOrBuilder.java @@ -561,4 +561,57 @@ public interface StructuredQueryOrBuilder * .google.protobuf.Int32Value limit = 5; */ com.google.protobuf.Int32ValueOrBuilder getLimitOrBuilder(); + + /** + * + * + *
+   * Optional. A potential Nearest Neighbors Search.
+   *
+   * Applies after all other filters and ordering.
+   *
+   * Finds the closest vector embeddings to the given query vector.
+   * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest find_nearest = 9 [(.google.api.field_behavior) = OPTIONAL]; + * + * + * @return Whether the findNearest field is set. + */ + boolean hasFindNearest(); + /** + * + * + *
+   * Optional. A potential Nearest Neighbors Search.
+   *
+   * Applies after all other filters and ordering.
+   *
+   * Finds the closest vector embeddings to the given query vector.
+   * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest find_nearest = 9 [(.google.api.field_behavior) = OPTIONAL]; + * + * + * @return The findNearest. + */ + com.google.firestore.v1.StructuredQuery.FindNearest getFindNearest(); + /** + * + * + *
+   * Optional. A potential Nearest Neighbors Search.
+   *
+   * Applies after all other filters and ordering.
+   *
+   * Finds the closest vector embeddings to the given query vector.
+   * 
+ * + * + * .google.firestore.v1.StructuredQuery.FindNearest find_nearest = 9 [(.google.api.field_behavior) = OPTIONAL]; + * + */ + com.google.firestore.v1.StructuredQuery.FindNearestOrBuilder getFindNearestOrBuilder(); } diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/Value.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/Value.java index 5613257ec..7a1fa4b97 100644 --- a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/Value.java +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/Value.java @@ -80,6 +80,9 @@ public enum ValueTypeCase GEO_POINT_VALUE(8), ARRAY_VALUE(9), MAP_VALUE(6), + FIELD_REFERENCE_VALUE(19), + FUNCTION_VALUE(20), + PIPELINE_VALUE(21), VALUETYPE_NOT_SET(0); private final int value; @@ -120,6 +123,12 @@ public static ValueTypeCase forNumber(int value) { return ARRAY_VALUE; case 6: return MAP_VALUE; + case 19: + return FIELD_REFERENCE_VALUE; + case 20: + return FUNCTION_VALUE; + case 21: + return PIPELINE_VALUE; case 0: return VALUETYPE_NOT_SET; default: @@ -711,6 +720,280 @@ public com.google.firestore.v1.MapValueOrBuilder getMapValueOrBuilder() { return com.google.firestore.v1.MapValue.getDefaultInstance(); } + public static final int FIELD_REFERENCE_VALUE_FIELD_NUMBER = 19; + /** + * + * + *
+   * Value which references a field.
+   *
+   * This is considered relative (vs absolute) since it only refers to a field
+   * and not a field within a particular document.
+   *
+   * **Requires:**
+   *
+   * * Must follow [field reference][FieldReference.field_path] limitations.
+   *
+   * * Not allowed to be used when writing documents.
+   *
+   * (-- NOTE(batchik): long term, there is no reason this type should not be
+   *     allowed to be used on the write path. --)
+   * 
+ * + * string field_reference_value = 19; + * + * @return Whether the fieldReferenceValue field is set. + */ + public boolean hasFieldReferenceValue() { + return valueTypeCase_ == 19; + } + /** + * + * + *
+   * Value which references a field.
+   *
+   * This is considered relative (vs absolute) since it only refers to a field
+   * and not a field within a particular document.
+   *
+   * **Requires:**
+   *
+   * * Must follow [field reference][FieldReference.field_path] limitations.
+   *
+   * * Not allowed to be used when writing documents.
+   *
+   * (-- NOTE(batchik): long term, there is no reason this type should not be
+   *     allowed to be used on the write path. --)
+   * 
+ * + * string field_reference_value = 19; + * + * @return The fieldReferenceValue. + */ + public java.lang.String getFieldReferenceValue() { + java.lang.Object ref = ""; + if (valueTypeCase_ == 19) { + ref = valueType_; + } + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (valueTypeCase_ == 19) { + valueType_ = s; + } + return s; + } + } + /** + * + * + *
+   * Value which references a field.
+   *
+   * This is considered relative (vs absolute) since it only refers to a field
+   * and not a field within a particular document.
+   *
+   * **Requires:**
+   *
+   * * Must follow [field reference][FieldReference.field_path] limitations.
+   *
+   * * Not allowed to be used when writing documents.
+   *
+   * (-- NOTE(batchik): long term, there is no reason this type should not be
+   *     allowed to be used on the write path. --)
+   * 
+ * + * string field_reference_value = 19; + * + * @return The bytes for fieldReferenceValue. + */ + public com.google.protobuf.ByteString getFieldReferenceValueBytes() { + java.lang.Object ref = ""; + if (valueTypeCase_ == 19) { + ref = valueType_; + } + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + if (valueTypeCase_ == 19) { + valueType_ = b; + } + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int FUNCTION_VALUE_FIELD_NUMBER = 20; + /** + * + * + *
+   * A value that represents an unevaluated expression.
+   *
+   * **Requires:**
+   *
+   * * Not allowed to be used when writing documents.
+   *
+   * (-- NOTE(batchik): similar to above, there is no reason to not allow
+   *     storing expressions into the database, just no plan to support in
+   *     the near term.
+   *
+   *     This would actually be an interesting way to represent user-defined
+   *     functions or more expressive rules-based systems. --)
+   * 
+ * + * .google.firestore.v1.Function function_value = 20; + * + * @return Whether the functionValue field is set. + */ + @java.lang.Override + public boolean hasFunctionValue() { + return valueTypeCase_ == 20; + } + /** + * + * + *
+   * A value that represents an unevaluated expression.
+   *
+   * **Requires:**
+   *
+   * * Not allowed to be used when writing documents.
+   *
+   * (-- NOTE(batchik): similar to above, there is no reason to not allow
+   *     storing expressions into the database, just no plan to support in
+   *     the near term.
+   *
+   *     This would actually be an interesting way to represent user-defined
+   *     functions or more expressive rules-based systems. --)
+   * 
+ * + * .google.firestore.v1.Function function_value = 20; + * + * @return The functionValue. + */ + @java.lang.Override + public com.google.firestore.v1.Function getFunctionValue() { + if (valueTypeCase_ == 20) { + return (com.google.firestore.v1.Function) valueType_; + } + return com.google.firestore.v1.Function.getDefaultInstance(); + } + /** + * + * + *
+   * A value that represents an unevaluated expression.
+   *
+   * **Requires:**
+   *
+   * * Not allowed to be used when writing documents.
+   *
+   * (-- NOTE(batchik): similar to above, there is no reason to not allow
+   *     storing expressions into the database, just no plan to support in
+   *     the near term.
+   *
+   *     This would actually be an interesting way to represent user-defined
+   *     functions or more expressive rules-based systems. --)
+   * 
+ * + * .google.firestore.v1.Function function_value = 20; + */ + @java.lang.Override + public com.google.firestore.v1.FunctionOrBuilder getFunctionValueOrBuilder() { + if (valueTypeCase_ == 20) { + return (com.google.firestore.v1.Function) valueType_; + } + return com.google.firestore.v1.Function.getDefaultInstance(); + } + + public static final int PIPELINE_VALUE_FIELD_NUMBER = 21; + /** + * + * + *
+   * A value that represents an unevaluated pipeline.
+   *
+   * **Requires:**
+   *
+   * * Not allowed to be used when writing documents.
+   *
+   * (-- NOTE(batchik): similar to above, there is no reason to not allow
+   *     storing expressions into the database, just no plan to support in
+   *     the near term.
+   *
+   *     This would actually be an interesting way to represent user-defined
+   *     functions or more expressive rules-based systems. --)
+   * 
+ * + * .google.firestore.v1.Pipeline pipeline_value = 21; + * + * @return Whether the pipelineValue field is set. + */ + @java.lang.Override + public boolean hasPipelineValue() { + return valueTypeCase_ == 21; + } + /** + * + * + *
+   * A value that represents an unevaluated pipeline.
+   *
+   * **Requires:**
+   *
+   * * Not allowed to be used when writing documents.
+   *
+   * (-- NOTE(batchik): similar to above, there is no reason to not allow
+   *     storing expressions into the database, just no plan to support in
+   *     the near term.
+   *
+   *     This would actually be an interesting way to represent user-defined
+   *     functions or more expressive rules-based systems. --)
+   * 
+ * + * .google.firestore.v1.Pipeline pipeline_value = 21; + * + * @return The pipelineValue. + */ + @java.lang.Override + public com.google.firestore.v1.Pipeline getPipelineValue() { + if (valueTypeCase_ == 21) { + return (com.google.firestore.v1.Pipeline) valueType_; + } + return com.google.firestore.v1.Pipeline.getDefaultInstance(); + } + /** + * + * + *
+   * A value that represents an unevaluated pipeline.
+   *
+   * **Requires:**
+   *
+   * * Not allowed to be used when writing documents.
+   *
+   * (-- NOTE(batchik): similar to above, there is no reason to not allow
+   *     storing expressions into the database, just no plan to support in
+   *     the near term.
+   *
+   *     This would actually be an interesting way to represent user-defined
+   *     functions or more expressive rules-based systems. --)
+   * 
+ * + * .google.firestore.v1.Pipeline pipeline_value = 21; + */ + @java.lang.Override + public com.google.firestore.v1.PipelineOrBuilder getPipelineValueOrBuilder() { + if (valueTypeCase_ == 21) { + return (com.google.firestore.v1.Pipeline) valueType_; + } + return com.google.firestore.v1.Pipeline.getDefaultInstance(); + } + private byte memoizedIsInitialized = -1; @java.lang.Override @@ -758,6 +1041,15 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io if (valueTypeCase_ == 18) { output.writeBytes(18, (com.google.protobuf.ByteString) valueType_); } + if (valueTypeCase_ == 19) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 19, valueType_); + } + if (valueTypeCase_ == 20) { + output.writeMessage(20, (com.google.firestore.v1.Function) valueType_); + } + if (valueTypeCase_ == 21) { + output.writeMessage(21, (com.google.firestore.v1.Pipeline) valueType_); + } getUnknownFields().writeTo(output); } @@ -818,6 +1110,19 @@ public int getSerializedSize() { com.google.protobuf.CodedOutputStream.computeBytesSize( 18, (com.google.protobuf.ByteString) valueType_); } + if (valueTypeCase_ == 19) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(19, valueType_); + } + if (valueTypeCase_ == 20) { + size += + com.google.protobuf.CodedOutputStream.computeMessageSize( + 20, (com.google.firestore.v1.Function) valueType_); + } + if (valueTypeCase_ == 21) { + size += + com.google.protobuf.CodedOutputStream.computeMessageSize( + 21, (com.google.firestore.v1.Pipeline) valueType_); + } size += getUnknownFields().getSerializedSize(); memoizedSize = size; return size; @@ -869,6 +1174,15 @@ public boolean equals(final java.lang.Object obj) { case 6: if (!getMapValue().equals(other.getMapValue())) return false; break; + case 19: + if (!getFieldReferenceValue().equals(other.getFieldReferenceValue())) return false; + break; + case 20: + if (!getFunctionValue().equals(other.getFunctionValue())) return false; + break; + case 21: + if (!getPipelineValue().equals(other.getPipelineValue())) return false; + break; case 0: default: } @@ -931,6 +1245,18 @@ public int hashCode() { hash = (37 * hash) + MAP_VALUE_FIELD_NUMBER; hash = (53 * hash) + getMapValue().hashCode(); break; + case 19: + hash = (37 * hash) + FIELD_REFERENCE_VALUE_FIELD_NUMBER; + hash = (53 * hash) + getFieldReferenceValue().hashCode(); + break; + case 20: + hash = (37 * hash) + FUNCTION_VALUE_FIELD_NUMBER; + hash = (53 * hash) + getFunctionValue().hashCode(); + break; + case 21: + hash = (37 * hash) + PIPELINE_VALUE_FIELD_NUMBER; + hash = (53 * hash) + getPipelineValue().hashCode(); + break; case 0: default: } @@ -1083,6 +1409,12 @@ public Builder clear() { if (mapValueBuilder_ != null) { mapValueBuilder_.clear(); } + if (functionValueBuilder_ != null) { + functionValueBuilder_.clear(); + } + if (pipelineValueBuilder_ != null) { + pipelineValueBuilder_.clear(); + } valueTypeCase_ = 0; valueType_ = null; return this; @@ -1138,6 +1470,12 @@ private void buildPartialOneofs(com.google.firestore.v1.Value result) { if (valueTypeCase_ == 6 && mapValueBuilder_ != null) { result.valueType_ = mapValueBuilder_.build(); } + if (valueTypeCase_ == 20 && functionValueBuilder_ != null) { + result.valueType_ = functionValueBuilder_.build(); + } + if (valueTypeCase_ == 21 && pipelineValueBuilder_ != null) { + result.valueType_ = pipelineValueBuilder_.build(); + } } @java.lang.Override @@ -1245,6 +1583,23 @@ public Builder mergeFrom(com.google.firestore.v1.Value other) { mergeMapValue(other.getMapValue()); break; } + case FIELD_REFERENCE_VALUE: + { + valueTypeCase_ = 19; + valueType_ = other.valueType_; + onChanged(); + break; + } + case FUNCTION_VALUE: + { + mergeFunctionValue(other.getFunctionValue()); + break; + } + case PIPELINE_VALUE: + { + mergePipelineValue(other.getPipelineValue()); + break; + } case VALUETYPE_NOT_SET: { break; @@ -1345,6 +1700,25 @@ public Builder mergeFrom( valueTypeCase_ = 18; break; } // case 146 + case 154: + { + java.lang.String s = input.readStringRequireUtf8(); + valueTypeCase_ = 19; + valueType_ = s; + break; + } // case 154 + case 162: + { + input.readMessage(getFunctionValueFieldBuilder().getBuilder(), extensionRegistry); + valueTypeCase_ = 20; + break; + } // case 162 + case 170: + { + input.readMessage(getPipelineValueFieldBuilder().getBuilder(), extensionRegistry); + valueTypeCase_ = 21; + break; + } // case 170 default: { if (!super.parseUnknownField(input, extensionRegistry, tag)) { @@ -2953,6 +3327,822 @@ public com.google.firestore.v1.MapValueOrBuilder getMapValueOrBuilder() { return mapValueBuilder_; } + /** + * + * + *
+     * Value which references a field.
+     *
+     * This is considered relative (vs absolute) since it only refers to a field
+     * and not a field within a particular document.
+     *
+     * **Requires:**
+     *
+     * * Must follow [field reference][FieldReference.field_path] limitations.
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): long term, there is no reason this type should not be
+     *     allowed to be used on the write path. --)
+     * 
+ * + * string field_reference_value = 19; + * + * @return Whether the fieldReferenceValue field is set. + */ + @java.lang.Override + public boolean hasFieldReferenceValue() { + return valueTypeCase_ == 19; + } + /** + * + * + *
+     * Value which references a field.
+     *
+     * This is considered relative (vs absolute) since it only refers to a field
+     * and not a field within a particular document.
+     *
+     * **Requires:**
+     *
+     * * Must follow [field reference][FieldReference.field_path] limitations.
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): long term, there is no reason this type should not be
+     *     allowed to be used on the write path. --)
+     * 
+ * + * string field_reference_value = 19; + * + * @return The fieldReferenceValue. + */ + @java.lang.Override + public java.lang.String getFieldReferenceValue() { + java.lang.Object ref = ""; + if (valueTypeCase_ == 19) { + ref = valueType_; + } + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (valueTypeCase_ == 19) { + valueType_ = s; + } + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * + * + *
+     * Value which references a field.
+     *
+     * This is considered relative (vs absolute) since it only refers to a field
+     * and not a field within a particular document.
+     *
+     * **Requires:**
+     *
+     * * Must follow [field reference][FieldReference.field_path] limitations.
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): long term, there is no reason this type should not be
+     *     allowed to be used on the write path. --)
+     * 
+ * + * string field_reference_value = 19; + * + * @return The bytes for fieldReferenceValue. + */ + @java.lang.Override + public com.google.protobuf.ByteString getFieldReferenceValueBytes() { + java.lang.Object ref = ""; + if (valueTypeCase_ == 19) { + ref = valueType_; + } + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + if (valueTypeCase_ == 19) { + valueType_ = b; + } + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * + * + *
+     * Value which references a field.
+     *
+     * This is considered relative (vs absolute) since it only refers to a field
+     * and not a field within a particular document.
+     *
+     * **Requires:**
+     *
+     * * Must follow [field reference][FieldReference.field_path] limitations.
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): long term, there is no reason this type should not be
+     *     allowed to be used on the write path. --)
+     * 
+ * + * string field_reference_value = 19; + * + * @param value The fieldReferenceValue to set. + * @return This builder for chaining. + */ + public Builder setFieldReferenceValue(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + valueTypeCase_ = 19; + valueType_ = value; + onChanged(); + return this; + } + /** + * + * + *
+     * Value which references a field.
+     *
+     * This is considered relative (vs absolute) since it only refers to a field
+     * and not a field within a particular document.
+     *
+     * **Requires:**
+     *
+     * * Must follow [field reference][FieldReference.field_path] limitations.
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): long term, there is no reason this type should not be
+     *     allowed to be used on the write path. --)
+     * 
+ * + * string field_reference_value = 19; + * + * @return This builder for chaining. + */ + public Builder clearFieldReferenceValue() { + if (valueTypeCase_ == 19) { + valueTypeCase_ = 0; + valueType_ = null; + onChanged(); + } + return this; + } + /** + * + * + *
+     * Value which references a field.
+     *
+     * This is considered relative (vs absolute) since it only refers to a field
+     * and not a field within a particular document.
+     *
+     * **Requires:**
+     *
+     * * Must follow [field reference][FieldReference.field_path] limitations.
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): long term, there is no reason this type should not be
+     *     allowed to be used on the write path. --)
+     * 
+ * + * string field_reference_value = 19; + * + * @param value The bytes for fieldReferenceValue to set. + * @return This builder for chaining. + */ + public Builder setFieldReferenceValueBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + valueTypeCase_ = 19; + valueType_ = value; + onChanged(); + return this; + } + + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.Function, + com.google.firestore.v1.Function.Builder, + com.google.firestore.v1.FunctionOrBuilder> + functionValueBuilder_; + /** + * + * + *
+     * A value that represents an unevaluated expression.
+     *
+     * **Requires:**
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): similar to above, there is no reason to not allow
+     *     storing expressions into the database, just no plan to support in
+     *     the near term.
+     *
+     *     This would actually be an interesting way to represent user-defined
+     *     functions or more expressive rules-based systems. --)
+     * 
+ * + * .google.firestore.v1.Function function_value = 20; + * + * @return Whether the functionValue field is set. + */ + @java.lang.Override + public boolean hasFunctionValue() { + return valueTypeCase_ == 20; + } + /** + * + * + *
+     * A value that represents an unevaluated expression.
+     *
+     * **Requires:**
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): similar to above, there is no reason to not allow
+     *     storing expressions into the database, just no plan to support in
+     *     the near term.
+     *
+     *     This would actually be an interesting way to represent user-defined
+     *     functions or more expressive rules-based systems. --)
+     * 
+ * + * .google.firestore.v1.Function function_value = 20; + * + * @return The functionValue. + */ + @java.lang.Override + public com.google.firestore.v1.Function getFunctionValue() { + if (functionValueBuilder_ == null) { + if (valueTypeCase_ == 20) { + return (com.google.firestore.v1.Function) valueType_; + } + return com.google.firestore.v1.Function.getDefaultInstance(); + } else { + if (valueTypeCase_ == 20) { + return functionValueBuilder_.getMessage(); + } + return com.google.firestore.v1.Function.getDefaultInstance(); + } + } + /** + * + * + *
+     * A value that represents an unevaluated expression.
+     *
+     * **Requires:**
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): similar to above, there is no reason to not allow
+     *     storing expressions into the database, just no plan to support in
+     *     the near term.
+     *
+     *     This would actually be an interesting way to represent user-defined
+     *     functions or more expressive rules-based systems. --)
+     * 
+ * + * .google.firestore.v1.Function function_value = 20; + */ + public Builder setFunctionValue(com.google.firestore.v1.Function value) { + if (functionValueBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + valueType_ = value; + onChanged(); + } else { + functionValueBuilder_.setMessage(value); + } + valueTypeCase_ = 20; + return this; + } + /** + * + * + *
+     * A value that represents an unevaluated expression.
+     *
+     * **Requires:**
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): similar to above, there is no reason to not allow
+     *     storing expressions into the database, just no plan to support in
+     *     the near term.
+     *
+     *     This would actually be an interesting way to represent user-defined
+     *     functions or more expressive rules-based systems. --)
+     * 
+ * + * .google.firestore.v1.Function function_value = 20; + */ + public Builder setFunctionValue(com.google.firestore.v1.Function.Builder builderForValue) { + if (functionValueBuilder_ == null) { + valueType_ = builderForValue.build(); + onChanged(); + } else { + functionValueBuilder_.setMessage(builderForValue.build()); + } + valueTypeCase_ = 20; + return this; + } + /** + * + * + *
+     * A value that represents an unevaluated expression.
+     *
+     * **Requires:**
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): similar to above, there is no reason to not allow
+     *     storing expressions into the database, just no plan to support in
+     *     the near term.
+     *
+     *     This would actually be an interesting way to represent user-defined
+     *     functions or more expressive rules-based systems. --)
+     * 
+ * + * .google.firestore.v1.Function function_value = 20; + */ + public Builder mergeFunctionValue(com.google.firestore.v1.Function value) { + if (functionValueBuilder_ == null) { + if (valueTypeCase_ == 20 + && valueType_ != com.google.firestore.v1.Function.getDefaultInstance()) { + valueType_ = + com.google.firestore.v1.Function.newBuilder( + (com.google.firestore.v1.Function) valueType_) + .mergeFrom(value) + .buildPartial(); + } else { + valueType_ = value; + } + onChanged(); + } else { + if (valueTypeCase_ == 20) { + functionValueBuilder_.mergeFrom(value); + } else { + functionValueBuilder_.setMessage(value); + } + } + valueTypeCase_ = 20; + return this; + } + /** + * + * + *
+     * A value that represents an unevaluated expression.
+     *
+     * **Requires:**
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): similar to above, there is no reason to not allow
+     *     storing expressions into the database, just no plan to support in
+     *     the near term.
+     *
+     *     This would actually be an interesting way to represent user-defined
+     *     functions or more expressive rules-based systems. --)
+     * 
+ * + * .google.firestore.v1.Function function_value = 20; + */ + public Builder clearFunctionValue() { + if (functionValueBuilder_ == null) { + if (valueTypeCase_ == 20) { + valueTypeCase_ = 0; + valueType_ = null; + onChanged(); + } + } else { + if (valueTypeCase_ == 20) { + valueTypeCase_ = 0; + valueType_ = null; + } + functionValueBuilder_.clear(); + } + return this; + } + /** + * + * + *
+     * A value that represents an unevaluated expression.
+     *
+     * **Requires:**
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): similar to above, there is no reason to not allow
+     *     storing expressions into the database, just no plan to support in
+     *     the near term.
+     *
+     *     This would actually be an interesting way to represent user-defined
+     *     functions or more expressive rules-based systems. --)
+     * 
+ * + * .google.firestore.v1.Function function_value = 20; + */ + public com.google.firestore.v1.Function.Builder getFunctionValueBuilder() { + return getFunctionValueFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * A value that represents an unevaluated expression.
+     *
+     * **Requires:**
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): similar to above, there is no reason to not allow
+     *     storing expressions into the database, just no plan to support in
+     *     the near term.
+     *
+     *     This would actually be an interesting way to represent user-defined
+     *     functions or more expressive rules-based systems. --)
+     * 
+ * + * .google.firestore.v1.Function function_value = 20; + */ + @java.lang.Override + public com.google.firestore.v1.FunctionOrBuilder getFunctionValueOrBuilder() { + if ((valueTypeCase_ == 20) && (functionValueBuilder_ != null)) { + return functionValueBuilder_.getMessageOrBuilder(); + } else { + if (valueTypeCase_ == 20) { + return (com.google.firestore.v1.Function) valueType_; + } + return com.google.firestore.v1.Function.getDefaultInstance(); + } + } + /** + * + * + *
+     * A value that represents an unevaluated expression.
+     *
+     * **Requires:**
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): similar to above, there is no reason to not allow
+     *     storing expressions into the database, just no plan to support in
+     *     the near term.
+     *
+     *     This would actually be an interesting way to represent user-defined
+     *     functions or more expressive rules-based systems. --)
+     * 
+ * + * .google.firestore.v1.Function function_value = 20; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.Function, + com.google.firestore.v1.Function.Builder, + com.google.firestore.v1.FunctionOrBuilder> + getFunctionValueFieldBuilder() { + if (functionValueBuilder_ == null) { + if (!(valueTypeCase_ == 20)) { + valueType_ = com.google.firestore.v1.Function.getDefaultInstance(); + } + functionValueBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.Function, + com.google.firestore.v1.Function.Builder, + com.google.firestore.v1.FunctionOrBuilder>( + (com.google.firestore.v1.Function) valueType_, getParentForChildren(), isClean()); + valueType_ = null; + } + valueTypeCase_ = 20; + onChanged(); + return functionValueBuilder_; + } + + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.Pipeline, + com.google.firestore.v1.Pipeline.Builder, + com.google.firestore.v1.PipelineOrBuilder> + pipelineValueBuilder_; + /** + * + * + *
+     * A value that represents an unevaluated pipeline.
+     *
+     * **Requires:**
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): similar to above, there is no reason to not allow
+     *     storing expressions into the database, just no plan to support in
+     *     the near term.
+     *
+     *     This would actually be an interesting way to represent user-defined
+     *     functions or more expressive rules-based systems. --)
+     * 
+ * + * .google.firestore.v1.Pipeline pipeline_value = 21; + * + * @return Whether the pipelineValue field is set. + */ + @java.lang.Override + public boolean hasPipelineValue() { + return valueTypeCase_ == 21; + } + /** + * + * + *
+     * A value that represents an unevaluated pipeline.
+     *
+     * **Requires:**
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): similar to above, there is no reason to not allow
+     *     storing expressions into the database, just no plan to support in
+     *     the near term.
+     *
+     *     This would actually be an interesting way to represent user-defined
+     *     functions or more expressive rules-based systems. --)
+     * 
+ * + * .google.firestore.v1.Pipeline pipeline_value = 21; + * + * @return The pipelineValue. + */ + @java.lang.Override + public com.google.firestore.v1.Pipeline getPipelineValue() { + if (pipelineValueBuilder_ == null) { + if (valueTypeCase_ == 21) { + return (com.google.firestore.v1.Pipeline) valueType_; + } + return com.google.firestore.v1.Pipeline.getDefaultInstance(); + } else { + if (valueTypeCase_ == 21) { + return pipelineValueBuilder_.getMessage(); + } + return com.google.firestore.v1.Pipeline.getDefaultInstance(); + } + } + /** + * + * + *
+     * A value that represents an unevaluated pipeline.
+     *
+     * **Requires:**
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): similar to above, there is no reason to not allow
+     *     storing expressions into the database, just no plan to support in
+     *     the near term.
+     *
+     *     This would actually be an interesting way to represent user-defined
+     *     functions or more expressive rules-based systems. --)
+     * 
+ * + * .google.firestore.v1.Pipeline pipeline_value = 21; + */ + public Builder setPipelineValue(com.google.firestore.v1.Pipeline value) { + if (pipelineValueBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + valueType_ = value; + onChanged(); + } else { + pipelineValueBuilder_.setMessage(value); + } + valueTypeCase_ = 21; + return this; + } + /** + * + * + *
+     * A value that represents an unevaluated pipeline.
+     *
+     * **Requires:**
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): similar to above, there is no reason to not allow
+     *     storing expressions into the database, just no plan to support in
+     *     the near term.
+     *
+     *     This would actually be an interesting way to represent user-defined
+     *     functions or more expressive rules-based systems. --)
+     * 
+ * + * .google.firestore.v1.Pipeline pipeline_value = 21; + */ + public Builder setPipelineValue(com.google.firestore.v1.Pipeline.Builder builderForValue) { + if (pipelineValueBuilder_ == null) { + valueType_ = builderForValue.build(); + onChanged(); + } else { + pipelineValueBuilder_.setMessage(builderForValue.build()); + } + valueTypeCase_ = 21; + return this; + } + /** + * + * + *
+     * A value that represents an unevaluated pipeline.
+     *
+     * **Requires:**
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): similar to above, there is no reason to not allow
+     *     storing expressions into the database, just no plan to support in
+     *     the near term.
+     *
+     *     This would actually be an interesting way to represent user-defined
+     *     functions or more expressive rules-based systems. --)
+     * 
+ * + * .google.firestore.v1.Pipeline pipeline_value = 21; + */ + public Builder mergePipelineValue(com.google.firestore.v1.Pipeline value) { + if (pipelineValueBuilder_ == null) { + if (valueTypeCase_ == 21 + && valueType_ != com.google.firestore.v1.Pipeline.getDefaultInstance()) { + valueType_ = + com.google.firestore.v1.Pipeline.newBuilder( + (com.google.firestore.v1.Pipeline) valueType_) + .mergeFrom(value) + .buildPartial(); + } else { + valueType_ = value; + } + onChanged(); + } else { + if (valueTypeCase_ == 21) { + pipelineValueBuilder_.mergeFrom(value); + } else { + pipelineValueBuilder_.setMessage(value); + } + } + valueTypeCase_ = 21; + return this; + } + /** + * + * + *
+     * A value that represents an unevaluated pipeline.
+     *
+     * **Requires:**
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): similar to above, there is no reason to not allow
+     *     storing expressions into the database, just no plan to support in
+     *     the near term.
+     *
+     *     This would actually be an interesting way to represent user-defined
+     *     functions or more expressive rules-based systems. --)
+     * 
+ * + * .google.firestore.v1.Pipeline pipeline_value = 21; + */ + public Builder clearPipelineValue() { + if (pipelineValueBuilder_ == null) { + if (valueTypeCase_ == 21) { + valueTypeCase_ = 0; + valueType_ = null; + onChanged(); + } + } else { + if (valueTypeCase_ == 21) { + valueTypeCase_ = 0; + valueType_ = null; + } + pipelineValueBuilder_.clear(); + } + return this; + } + /** + * + * + *
+     * A value that represents an unevaluated pipeline.
+     *
+     * **Requires:**
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): similar to above, there is no reason to not allow
+     *     storing expressions into the database, just no plan to support in
+     *     the near term.
+     *
+     *     This would actually be an interesting way to represent user-defined
+     *     functions or more expressive rules-based systems. --)
+     * 
+ * + * .google.firestore.v1.Pipeline pipeline_value = 21; + */ + public com.google.firestore.v1.Pipeline.Builder getPipelineValueBuilder() { + return getPipelineValueFieldBuilder().getBuilder(); + } + /** + * + * + *
+     * A value that represents an unevaluated pipeline.
+     *
+     * **Requires:**
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): similar to above, there is no reason to not allow
+     *     storing expressions into the database, just no plan to support in
+     *     the near term.
+     *
+     *     This would actually be an interesting way to represent user-defined
+     *     functions or more expressive rules-based systems. --)
+     * 
+ * + * .google.firestore.v1.Pipeline pipeline_value = 21; + */ + @java.lang.Override + public com.google.firestore.v1.PipelineOrBuilder getPipelineValueOrBuilder() { + if ((valueTypeCase_ == 21) && (pipelineValueBuilder_ != null)) { + return pipelineValueBuilder_.getMessageOrBuilder(); + } else { + if (valueTypeCase_ == 21) { + return (com.google.firestore.v1.Pipeline) valueType_; + } + return com.google.firestore.v1.Pipeline.getDefaultInstance(); + } + } + /** + * + * + *
+     * A value that represents an unevaluated pipeline.
+     *
+     * **Requires:**
+     *
+     * * Not allowed to be used when writing documents.
+     *
+     * (-- NOTE(batchik): similar to above, there is no reason to not allow
+     *     storing expressions into the database, just no plan to support in
+     *     the near term.
+     *
+     *     This would actually be an interesting way to represent user-defined
+     *     functions or more expressive rules-based systems. --)
+     * 
+ * + * .google.firestore.v1.Pipeline pipeline_value = 21; + */ + private com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.Pipeline, + com.google.firestore.v1.Pipeline.Builder, + com.google.firestore.v1.PipelineOrBuilder> + getPipelineValueFieldBuilder() { + if (pipelineValueBuilder_ == null) { + if (!(valueTypeCase_ == 21)) { + valueType_ = com.google.firestore.v1.Pipeline.getDefaultInstance(); + } + pipelineValueBuilder_ = + new com.google.protobuf.SingleFieldBuilderV3< + com.google.firestore.v1.Pipeline, + com.google.firestore.v1.Pipeline.Builder, + com.google.firestore.v1.PipelineOrBuilder>( + (com.google.firestore.v1.Pipeline) valueType_, getParentForChildren(), isClean()); + valueType_ = null; + } + valueTypeCase_ = 21; + onChanged(); + return pipelineValueBuilder_; + } + @java.lang.Override public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { return super.setUnknownFields(unknownFields); diff --git a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ValueOrBuilder.java b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ValueOrBuilder.java index 047f6c988..9b553bcd3 100644 --- a/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ValueOrBuilder.java +++ b/proto-google-cloud-firestore-v1/src/main/java/com/google/firestore/v1/ValueOrBuilder.java @@ -414,5 +414,214 @@ public interface ValueOrBuilder */ com.google.firestore.v1.MapValueOrBuilder getMapValueOrBuilder(); + /** + * + * + *
+   * Value which references a field.
+   *
+   * This is considered relative (vs absolute) since it only refers to a field
+   * and not a field within a particular document.
+   *
+   * **Requires:**
+   *
+   * * Must follow [field reference][FieldReference.field_path] limitations.
+   *
+   * * Not allowed to be used when writing documents.
+   *
+   * (-- NOTE(batchik): long term, there is no reason this type should not be
+   *     allowed to be used on the write path. --)
+   * 
+ * + * string field_reference_value = 19; + * + * @return Whether the fieldReferenceValue field is set. + */ + boolean hasFieldReferenceValue(); + /** + * + * + *
+   * Value which references a field.
+   *
+   * This is considered relative (vs absolute) since it only refers to a field
+   * and not a field within a particular document.
+   *
+   * **Requires:**
+   *
+   * * Must follow [field reference][FieldReference.field_path] limitations.
+   *
+   * * Not allowed to be used when writing documents.
+   *
+   * (-- NOTE(batchik): long term, there is no reason this type should not be
+   *     allowed to be used on the write path. --)
+   * 
+ * + * string field_reference_value = 19; + * + * @return The fieldReferenceValue. + */ + java.lang.String getFieldReferenceValue(); + /** + * + * + *
+   * Value which references a field.
+   *
+   * This is considered relative (vs absolute) since it only refers to a field
+   * and not a field within a particular document.
+   *
+   * **Requires:**
+   *
+   * * Must follow [field reference][FieldReference.field_path] limitations.
+   *
+   * * Not allowed to be used when writing documents.
+   *
+   * (-- NOTE(batchik): long term, there is no reason this type should not be
+   *     allowed to be used on the write path. --)
+   * 
+ * + * string field_reference_value = 19; + * + * @return The bytes for fieldReferenceValue. + */ + com.google.protobuf.ByteString getFieldReferenceValueBytes(); + + /** + * + * + *
+   * A value that represents an unevaluated expression.
+   *
+   * **Requires:**
+   *
+   * * Not allowed to be used when writing documents.
+   *
+   * (-- NOTE(batchik): similar to above, there is no reason to not allow
+   *     storing expressions into the database, just no plan to support in
+   *     the near term.
+   *
+   *     This would actually be an interesting way to represent user-defined
+   *     functions or more expressive rules-based systems. --)
+   * 
+ * + * .google.firestore.v1.Function function_value = 20; + * + * @return Whether the functionValue field is set. + */ + boolean hasFunctionValue(); + /** + * + * + *
+   * A value that represents an unevaluated expression.
+   *
+   * **Requires:**
+   *
+   * * Not allowed to be used when writing documents.
+   *
+   * (-- NOTE(batchik): similar to above, there is no reason to not allow
+   *     storing expressions into the database, just no plan to support in
+   *     the near term.
+   *
+   *     This would actually be an interesting way to represent user-defined
+   *     functions or more expressive rules-based systems. --)
+   * 
+ * + * .google.firestore.v1.Function function_value = 20; + * + * @return The functionValue. + */ + com.google.firestore.v1.Function getFunctionValue(); + /** + * + * + *
+   * A value that represents an unevaluated expression.
+   *
+   * **Requires:**
+   *
+   * * Not allowed to be used when writing documents.
+   *
+   * (-- NOTE(batchik): similar to above, there is no reason to not allow
+   *     storing expressions into the database, just no plan to support in
+   *     the near term.
+   *
+   *     This would actually be an interesting way to represent user-defined
+   *     functions or more expressive rules-based systems. --)
+   * 
+ * + * .google.firestore.v1.Function function_value = 20; + */ + com.google.firestore.v1.FunctionOrBuilder getFunctionValueOrBuilder(); + + /** + * + * + *
+   * A value that represents an unevaluated pipeline.
+   *
+   * **Requires:**
+   *
+   * * Not allowed to be used when writing documents.
+   *
+   * (-- NOTE(batchik): similar to above, there is no reason to not allow
+   *     storing expressions into the database, just no plan to support in
+   *     the near term.
+   *
+   *     This would actually be an interesting way to represent user-defined
+   *     functions or more expressive rules-based systems. --)
+   * 
+ * + * .google.firestore.v1.Pipeline pipeline_value = 21; + * + * @return Whether the pipelineValue field is set. + */ + boolean hasPipelineValue(); + /** + * + * + *
+   * A value that represents an unevaluated pipeline.
+   *
+   * **Requires:**
+   *
+   * * Not allowed to be used when writing documents.
+   *
+   * (-- NOTE(batchik): similar to above, there is no reason to not allow
+   *     storing expressions into the database, just no plan to support in
+   *     the near term.
+   *
+   *     This would actually be an interesting way to represent user-defined
+   *     functions or more expressive rules-based systems. --)
+   * 
+ * + * .google.firestore.v1.Pipeline pipeline_value = 21; + * + * @return The pipelineValue. + */ + com.google.firestore.v1.Pipeline getPipelineValue(); + /** + * + * + *
+   * A value that represents an unevaluated pipeline.
+   *
+   * **Requires:**
+   *
+   * * Not allowed to be used when writing documents.
+   *
+   * (-- NOTE(batchik): similar to above, there is no reason to not allow
+   *     storing expressions into the database, just no plan to support in
+   *     the near term.
+   *
+   *     This would actually be an interesting way to represent user-defined
+   *     functions or more expressive rules-based systems. --)
+   * 
+ * + * .google.firestore.v1.Pipeline pipeline_value = 21; + */ + com.google.firestore.v1.PipelineOrBuilder getPipelineValueOrBuilder(); + com.google.firestore.v1.Value.ValueTypeCase getValueTypeCase(); } diff --git a/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/document.proto b/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/document.proto index 1ccc93a10..d2f1f262e 100644 --- a/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/document.proto +++ b/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/document.proto @@ -260,3 +260,4 @@ message Pipeline { // Ordered list of stages to evaluate. repeated Stage stages = 1; } + diff --git a/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/pipeline.proto b/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/pipeline.proto index 20f0c17be..0a198cd6e 100644 --- a/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/pipeline.proto +++ b/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/pipeline.proto @@ -24,3 +24,4 @@ message StructuredPipeline { // (-- TODO(batchik): define the api contract of using an unsupported hint --) map options = 2; } + diff --git a/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/query.proto b/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/query.proto index 09eefa241..68d9d5458 100644 --- a/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/query.proto +++ b/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/query.proto @@ -263,6 +263,51 @@ message StructuredQuery { repeated FieldReference fields = 2; } + // Nearest Neighbors search config. + message FindNearest { + // The distance measure to use when comparing vectors. + enum DistanceMeasure { + // Should not be set. + DISTANCE_MEASURE_UNSPECIFIED = 0; + + // Measures the EUCLIDEAN distance between the vectors. See + // [Euclidean](https://en.wikipedia.org/wiki/Euclidean_distance) to learn + // more + EUCLIDEAN = 1; + + // Compares vectors based on the angle between them, which allows you to + // measure similarity that isn't based on the vectors magnitude. + // We recommend using DOT_PRODUCT with unit normalized vectors instead of + // COSINE distance, which is mathematically equivalent with better + // performance. See [Cosine + // Similarity](https://en.wikipedia.org/wiki/Cosine_similarity) to learn + // more. + COSINE = 2; + + // Similar to cosine but is affected by the magnitude of the vectors. See + // [Dot Product](https://en.wikipedia.org/wiki/Dot_product) to learn more. + DOT_PRODUCT = 3; + } + + // Required. An indexed vector field to search upon. Only documents which + // contain vectors whose dimensionality match the query_vector can be + // returned. + FieldReference vector_field = 1 [(google.api.field_behavior) = REQUIRED]; + + // Required. The query vector that we are searching on. Must be a vector of + // no more than 2048 dimensions. + Value query_vector = 2 [(google.api.field_behavior) = REQUIRED]; + + // Required. The Distance Measure to use, required. + DistanceMeasure distance_measure = 3 + [(google.api.field_behavior) = REQUIRED]; + + // Required. The number of nearest neighbors to return. Must be a positive + // integer of no more than 1000. + google.protobuf.Int32Value limit = 4 + [(google.api.field_behavior) = REQUIRED]; + } + // Optional sub-set of the fields to return. // // This acts as a [DocumentMask][google.firestore.v1.DocumentMask] over the @@ -360,6 +405,13 @@ message StructuredQuery { // // * The value must be greater than or equal to zero if specified. google.protobuf.Int32Value limit = 5; + + // Optional. A potential Nearest Neighbors Search. + // + // Applies after all other filters and ordering. + // + // Finds the closest vector embeddings to the given query vector. + FindNearest find_nearest = 9 [(google.api.field_behavior) = OPTIONAL]; } // Firestore query for running an aggregation over a diff --git a/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/query_profile.proto b/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/query_profile.proto new file mode 100644 index 000000000..931e083b0 --- /dev/null +++ b/proto-google-cloud-firestore-v1/src/main/proto/google/firestore/v1/query_profile.proto @@ -0,0 +1,92 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.firestore.v1; + +import "google/api/field_behavior.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/struct.proto"; + +option csharp_namespace = "Google.Cloud.Firestore.V1"; +option go_package = "cloud.google.com/go/firestore/apiv1/firestorepb;firestorepb"; +option java_multiple_files = true; +option java_outer_classname = "QueryProfileProto"; +option java_package = "com.google.firestore.v1"; +option objc_class_prefix = "GCFS"; +option php_namespace = "Google\\Cloud\\Firestore\\V1"; +option ruby_package = "Google::Cloud::Firestore::V1"; + +// Specification of the Firestore Query Profile fields. + +// Explain options for the query. +message ExplainOptions { + // Optional. Whether to execute this query. + // + // When false (the default), the query will be planned, returning only + // metrics from the planning stages. + // + // When true, the query will be planned and executed, returning the full + // query results along with both planning and execution stage metrics. + bool analyze = 1 [(google.api.field_behavior) = OPTIONAL]; +} + +// Explain metrics for the query. +message ExplainMetrics { + // Planning phase information for the query. + PlanSummary plan_summary = 1; + + // Aggregated stats from the execution of the query. Only present when + // [ExplainOptions.analyze][google.firestore.v1.ExplainOptions.analyze] is set + // to true. + ExecutionStats execution_stats = 2; +} + +// Planning phase information for the query. +message PlanSummary { + // The indexes selected for the query. For example: + // [ + // {"query_scope": "Collection", "properties": "(foo ASC, __name__ ASC)"}, + // {"query_scope": "Collection", "properties": "(bar ASC, __name__ ASC)"} + // ] + repeated google.protobuf.Struct indexes_used = 1; +} + +// Execution statistics for the query. +message ExecutionStats { + // Total number of results returned, including documents, projections, + // aggregation results, keys. + int64 results_returned = 1; + + // Total time to execute the query in the backend. + google.protobuf.Duration execution_duration = 3; + + // Total billable read operations. + int64 read_operations = 4; + + // Debugging statistics from the execution of the query. Note that the + // debugging stats are subject to change as Firestore evolves. It could + // include: + // { + // "indexes_entries_scanned": "1000", + // "documents_scanned": "20", + // "billing_details" : { + // "documents_billable": "20", + // "index_entries_billable": "1000", + // "min_query_cost": "0" + // } + // } + google.protobuf.Struct debug_stats = 5; +} From 336947300aeff4a1e331427465b3c738c7dddef0 Mon Sep 17 00:00:00 2001 From: wu-hui Date: Fri, 12 Apr 2024 18:47:15 +0000 Subject: [PATCH 31/65] pull in proto change and regenerate --- .../com/google/cloud/firestore/Pipeline.kt | 74 ++++++++++----- .../cloud/firestore/UserDataConverter.java | 3 + .../cloud/firestore/pipeline/Expressions.kt | 95 ++++++++++++------- .../google/cloud/firestore/pipeline/Stages.kt | 90 ++++++++++-------- 4 files changed, 168 insertions(+), 94 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 7c5a39cf7..26886ba2c 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -3,25 +3,29 @@ package com.google.cloud.firestore import com.google.api.core.ApiFuture import com.google.api.core.ApiFutures import com.google.api.gax.rpc.ApiStreamObserver +import com.google.cloud.firestore.UserDataConverter.EncodingOptions import com.google.cloud.firestore.pipeline.AggregatorTarget import com.google.cloud.firestore.pipeline.Collection import com.google.cloud.firestore.pipeline.CollectionGroup +import com.google.cloud.firestore.pipeline.Expr +import com.google.cloud.firestore.pipeline.ExprAsAlias import com.google.cloud.firestore.pipeline.Field +import com.google.cloud.firestore.pipeline.Fields import com.google.cloud.firestore.pipeline.Filter import com.google.cloud.firestore.pipeline.FindNearest import com.google.cloud.firestore.pipeline.Function -import com.google.cloud.firestore.pipeline.GenericStage -import com.google.cloud.firestore.pipeline.Limit -import com.google.cloud.firestore.pipeline.Offset -import com.google.cloud.firestore.pipeline.Ordering +import com.google.cloud.firestore.pipeline.Project import com.google.cloud.firestore.pipeline.Projectable import com.google.cloud.firestore.pipeline.Sort +import com.google.cloud.firestore.pipeline.Sort.Ordering import com.google.cloud.firestore.pipeline.Stage +import com.google.cloud.firestore.pipeline.ToProto +import com.google.firestore.v1.Value class PaginatingPipeline internal constructor( val p: Pipeline, pageSize: Int, - orders: Array + orders: Array ) { fun firstPage(): Pipeline { return this.p @@ -78,19 +82,12 @@ class PaginatingPipeline internal constructor( * .aggregate(count(Field.of("orderId")).asAlias("orderCount")); * ``` */ -class Pipeline { - private val stages: MutableList = mutableListOf() - private var name: String +class Pipeline private constructor(private val stages: List, private val name: String): + ToProto { - private constructor(collection: Collection) { - stages.add(collection) - name = collection.path - } + private constructor(collection: Collection) : this(listOf(collection), collection.path) - private constructor(group: CollectionGroup) { - stages.add(group) - name = group.path - } + private constructor(group: CollectionGroup): this(listOf(group), group.path) companion object { @JvmStatic @@ -115,21 +112,27 @@ class Pipeline { } fun project(vararg projections: Projectable): Pipeline { - return this + val projMap = mutableMapOf() + for(proj in projections) { + when (proj){ + is Field -> projMap[proj.field] = proj + is AggregatorTarget -> projMap[proj.target] = proj.current + is ExprAsAlias -> projMap[proj.alias] = proj.current + is Fields -> proj.fs?.forEach { projMap[it.field] = it} + } + } + return Pipeline(stages.plus(Project(projMap)), name) } fun filter(condition: Function.FilterCondition): Pipeline { - stages.add(Filter(condition)) - return this + return Pipeline(stages.plus(Filter(condition)), name) } fun offset(offset: Int): Pipeline { - stages.add(Offset(offset)) return this } fun limit(limit: Int): Pipeline { - stages.add(Limit(limit)) return this } @@ -144,16 +147,14 @@ class Pipeline { vector: DoubleArray, options: FindNearest.FindNearestOptions ): Pipeline { - stages.add(FindNearest(property, vector, options)) return this } fun sort( - orders: List, + orders: List, density: Sort.Density = Sort.Density.UNSPECIFIED, truncation: Sort.Truncation = Sort.Truncation.UNSPECIFIED ): Pipeline { - stages.add(Sort(orders, density, truncation)) return this } @@ -167,7 +168,6 @@ class Pipeline { } fun genericOperation(name: String, params: Map? = null): Pipeline { - stages.add(GenericStage(name, params)) return this } @@ -177,5 +177,29 @@ class Pipeline { fun execute(db: Firestore, observer: ApiStreamObserver): Unit { } + + override fun toProto(): Value { + return Value.newBuilder() + .setPipelineValue(com.google.firestore.v1.Pipeline.newBuilder() + .addAllStages(stages.map { toStageProto(it) }) + ) + .build() + } +} + +internal fun toStageProto(stage: Stage): com.google.firestore.v1.Pipeline.Stage { + return when (stage) { + is Project -> com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName("project") + .addArgs(UserDataConverter.encodeValue(FieldPath.empty(), stage.projections, UserDataConverter.ARGUMENT)) + .build() + is Collection -> com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName("collection") + .addArgs(UserDataConverter.encodeValue(FieldPath.empty(),stage.path, UserDataConverter.ARGUMENT)) + .build() + else -> { + TODO() + } + } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java index 50222fefd..6506b9f2b 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java @@ -17,6 +17,7 @@ package com.google.cloud.firestore; import com.google.cloud.Timestamp; +import com.google.cloud.firestore.pipeline.ToProto; import com.google.common.base.Preconditions; import com.google.firestore.v1.ArrayValue; import com.google.firestore.v1.MapValue; @@ -154,6 +155,8 @@ static Value encodeValue( return Value.newBuilder().setBytesValue(blob.toByteString()).build(); } else if (sanitizedObject instanceof Value) { return (Value) sanitizedObject; + } else if (sanitizedObject instanceof ToProto) { + return ((ToProto) sanitizedObject).toProto(); } else if (sanitizedObject instanceof DocumentReference) { DocumentReference docRef = (DocumentReference) sanitizedObject; return Value.newBuilder().setReferenceValue(docRef.getName()).build(); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index 56fc06462..286e86895 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -22,9 +22,25 @@ import com.google.cloud.firestore.pipeline.Function.NotIn import com.google.cloud.firestore.pipeline.Function.Sum import com.google.firestore.v1.Value +internal interface ToProto { + fun toProto(): Value +} + +internal fun exprToValue(expr: Expr): Value{ + return when(expr) { + is Constant -> expr.toProto() + is Field -> expr.toProto() + is Function -> expr.toProto() + // is ExprAsAlias -> + else -> { + TODO() + } + } +} + sealed interface Projectable -sealed interface Expr { +interface Expr { // Infix functions returning Function subclasses infix fun equal(other: Expr) = Equal(this, other) infix fun equal(other: Number) = Equal(this, Constant.of(other)) @@ -85,7 +101,7 @@ sealed interface Expr { internal data class ListOfExprs(val conditions: List) : Expr internal data class ListOfConditions(val conditions: List) : Expr, Function.FilterCondition -data class Constant internal constructor(val value: Any) : Expr { +data class Constant internal constructor(val value: Any) : Expr, ToProto { companion object { @JvmStatic fun of(value: String): Constant { @@ -117,10 +133,15 @@ data class Constant internal constructor(val value: Any) : Expr { return Constant(value) } } + + override fun toProto(): Value { + return Value.newBuilder().build() + } } data class Field internal constructor(val field: String, var pipeline: Pipeline? = null) : Expr, - Projectable { + Projectable, + ToProto { companion object { const val DOCUMENT_ID: String = "__path__" @@ -131,6 +152,10 @@ data class Field internal constructor(val field: String, var pipeline: Pipeline? } fun exists() = Function.Exists(this) + + override fun toProto(): Value { + return Value.newBuilder().setFieldReferenceValue(field).build() + } } data class Fields internal constructor(val fs: List? = null) : Expr, Projectable { @@ -156,10 +181,10 @@ data class AggregatorTarget internal constructor( Projectable, Function.Accumulator -sealed class Function(val name: String, val params: Map?) : Expr { +sealed class Function(val name: String, val params: List): Expr, ToProto { interface FilterCondition - interface Accumulator { + interface Accumulator: Expr { var distinct: Boolean fun distinct(on: Boolean): Accumulator { @@ -170,82 +195,88 @@ sealed class Function(val name: String, val params: Map?) : Expr { fun toField(target: String) = AggregatorTarget(this, target, this.distinct) } + override fun toProto(): Value { + return Value.newBuilder().setFunctionValue(com.google.firestore.v1.Function.newBuilder() + .setName(name) + .addAllArgs(params.map { exprToValue(it) })).build() + } + data class Equal internal constructor(val left: Expr, val right: Expr) : - Function("equal", mapOf("left" to left, "right" to right)), FilterCondition + Function("equal", listOf(left, right)), FilterCondition data class NotEqual(val left: Expr, val right: Expr) : - Function("not_equal", mapOf("left" to left, "right" to right)), FilterCondition + Function("not_equal", listOf(left, right)), FilterCondition data class GreaterThan(val left: Expr, val right: Expr) : - Function("greater_than", mapOf("left" to left, "right" to right)), FilterCondition + Function("greater_than", listOf(left, right)), FilterCondition data class GreaterThanOrEqual(val left: Expr, val right: Expr) : - Function("greater_than_equal", mapOf("left" to left, "right" to right)), FilterCondition + Function("greater_than_equal", listOf(left, right)), FilterCondition data class In(val left: Expr, val others: List) : - Function("in", mapOf("left" to left, "others" to ListOfExprs(others))), + Function("in", listOf(left, ListOfExprs(others))), FilterCondition // For 'in' data class LessThan(val left: Expr, val right: Expr) : - Function("less_than", mapOf("left" to left, "right" to right)), FilterCondition + Function("less_than", listOf(left, right)), FilterCondition data class LessThanOrEqual(val left: Expr, val right: Expr) : - Function("less_than_equal", mapOf("left" to left, "right" to right)), FilterCondition + Function("less_than_equal", listOf(left, right)), FilterCondition data class NotIn(val left: Expr, val others: List) : - Function("not_in", mapOf("left" to left, "others" to ListOfExprs(others))), + Function("not_in", listOf(left, ListOfExprs(others))), FilterCondition // For 'not in' data class And(val conditions: List) : - Function("and", mapOf("conditions" to ListOfConditions(conditions))), FilterCondition + Function("and", listOf(ListOfConditions(conditions))), FilterCondition data class Or(val conditions: List) : - Function("or", mapOf("conditions" to ListOfConditions(conditions))), FilterCondition + Function("or", listOf(ListOfConditions(conditions))), FilterCondition - data class Not(val condition: Expr) : Function("not", mapOf("condition" to condition)), + data class Not(val condition: Expr) : Function("not", listOf(condition)), FilterCondition - data class Exists(val current: Field) : Function("exists", mapOf("current" to current)), + data class Exists(val current: Field) : Function("exists", listOf(current)), FilterCondition data class MapGet(val map: Expr, val key: String) : Function( "map_get", - mapOf( - "map" to map, - "key" to Constant(Value.getDefaultInstance().toBuilder().setStringValue(key).build()) + listOf( + map, + Constant(Value.getDefaultInstance().toBuilder().setStringValue(key).build()) ) ) data class ArrayContains(val array: Expr, val element: Expr) : - Function("array_contains", mapOf("array" to array, "element" to element)), FilterCondition + Function("array_contains", listOf(array, element)), FilterCondition data class ArrayContainsAny(val array: Expr, val elements: List) : - Function("array_contains_any", mapOf("array" to array, "elements" to ListOfExprs(elements))), + Function("array_contains_any", listOf(array, ListOfExprs(elements))), FilterCondition - data class IsNaN(val value: Expr) : Function("is_nan", mapOf("value" to value)), FilterCondition - data class IsNull(val value: Expr) : Function("is_null", mapOf("value" to value)), + data class IsNaN(val value: Expr) : Function("is_nan", listOf(value)), FilterCondition + data class IsNull(val value: Expr) : Function("is_null", listOf(value)), FilterCondition data class Sum(val value: Expr, override var distinct: Boolean) : - Function("sum", mapOf("value" to value)), Accumulator + Function("sum", listOf(value)), Accumulator data class Avg(val value: Expr, override var distinct: Boolean) : - Function("avg", mapOf("value" to value)), Accumulator + Function("avg", listOf(value)), Accumulator data class Count(val value: Expr, override var distinct: Boolean) : - Function("count", mapOf("value" to value)), Accumulator + Function("count", listOf(value)), Accumulator data class CosineDistance(val vector1: Expr, val vector2: Expr) : - Function("cosine_distance", mapOf("vector1" to vector1, "vector2" to vector2)) + Function("cosine_distance", listOf(vector1, vector2)) data class DotProductDistance(val vector1: Expr, val vector2: Expr) : - Function("dot_product_distance", mapOf("vector1" to vector1, "vector2" to vector2)) + Function("dot_product_distance", listOf(vector1, vector2)) data class EuclideanDistance(val vector1: Expr, val vector2: Expr) : - Function("euclidean_distance", mapOf("vector1" to vector1, "vector2" to vector2)) + Function("euclidean_distance", listOf(vector1, vector2)) - data class Generic(val n: String, val ps: Map?) : Function(n, ps) + data class Generic(val n: String, val ps: List) : Function(n, ps) companion object { @@ -411,7 +442,7 @@ sealed class Function(val name: String, val params: Map?) : Expr { fun asAlias(expr: Expr, alias: String): Projectable = ExprAsAlias(expr, alias) @JvmStatic - fun function(name: String, params: Map?) = Generic(name, params) + fun function(name: String, params: List) = Generic(name, params) } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt index 9044f192a..06e445d01 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt @@ -1,14 +1,29 @@ package com.google.cloud.firestore.pipeline -interface Stage +import com.google.firestore.v1.Pipeline +import com.google.firestore.v1.Value -internal data class Collection(val path: String) : Stage -internal data class CollectionGroup(val path: String) : Stage +internal interface Stage -internal data class Project(val projections: Map) : Stage -internal data class Filter(val condition: Function.FilterCondition) : Stage -internal data class Offset(val offset: Int) : Stage -internal data class Limit(val limit: Int) : Stage +internal data class Collection(val path: String) : Stage { + +} + +internal data class CollectionGroup(val path: String) : Stage { + +} + +internal data class Project(val projections: Map) : Stage { +} + +data class Filter(val condition: Function.FilterCondition) : Stage { +} + +data class Offset(val offset: Int) : Stage { +} + +data class Limit(val limit: Int) : Stage { +} data class FindNearest internal constructor( val property: Field, @@ -42,35 +57,7 @@ data class FindNearest internal constructor( val limit: Long, val output: Field? = null ) -} - -data class Ordering internal constructor(val expr: Expr, val dir: Direction = Direction.ASC) { - enum class Direction { - ASC, - DESC - } - - companion object { - @JvmStatic - fun of(expr: Expr, dir: Direction = Direction.ASC): Ordering { - return Ordering(expr, dir) - } - - @JvmStatic - fun of(expr: Expr): Ordering { - return Ordering(expr, Direction.ASC) - } - @JvmStatic - fun ascending(expr: Expr): Ordering { - return Ordering(expr, Direction.ASC) - } - - @JvmStatic - fun descending(expr: Expr): Ordering { - return Ordering(expr, Direction.DESC) - } - } } data class Sort internal constructor( @@ -87,7 +74,36 @@ data class Sort internal constructor( UNSPECIFIED, DISABLED } -} -data class GenericStage(val name: String, val params: Map?) : Stage + data class Ordering internal constructor(val expr: Expr, val dir: Direction = Direction.ASC) { + enum class Direction { + ASC, + DESC + } + companion object { + @JvmStatic + fun of(expr: Expr, dir: Direction = Direction.ASC): Ordering { + return Ordering(expr, dir) + } + + @JvmStatic + fun of(expr: Expr): Ordering { + return Ordering(expr, Direction.ASC) + } + + @JvmStatic + fun ascending(expr: Expr): Ordering { + return Ordering(expr, Direction.ASC) + } + + @JvmStatic + fun descending(expr: Expr): Ordering { + return Ordering(expr, Direction.DESC) + } + } + } +} + +data class GenericStage(val name: String, val params: Map?) : Stage { +} From 948602782e48ce88c317c72b76f44350f9bb1771 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Wed, 17 Apr 2024 14:52:33 -0400 Subject: [PATCH 32/65] Basic serialization --- .../com/google/cloud/firestore/Pipeline.kt | 263 ++++++++++++++--- .../google/cloud/firestore/PipelineResult.kt | 25 +- .../cloud/firestore/UserDataConverter.java | 8 +- .../cloud/firestore/pipeline/Expressions.kt | 279 +++++++++--------- .../google/cloud/firestore/pipeline/Stages.kt | 243 +++++++++++++-- .../cloud/firestore/spi/v1/FirestoreRpc.java | 6 + .../firestore/spi/v1/GrpcFirestoreRpc.java | 8 + .../cloud/firestore/it/ITPipelineTest.java | 74 +++-- 8 files changed, 655 insertions(+), 251 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 26886ba2c..422a15816 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -1,26 +1,43 @@ package com.google.cloud.firestore import com.google.api.core.ApiFuture -import com.google.api.core.ApiFutures +import com.google.api.core.SettableApiFuture import com.google.api.gax.rpc.ApiStreamObserver -import com.google.cloud.firestore.UserDataConverter.EncodingOptions +import com.google.api.gax.rpc.ResponseObserver +import com.google.api.gax.rpc.StreamController +import com.google.cloud.Timestamp +import com.google.cloud.firestore.pipeline.AddFields +import com.google.cloud.firestore.pipeline.Aggregate import com.google.cloud.firestore.pipeline.AggregatorTarget import com.google.cloud.firestore.pipeline.Collection import com.google.cloud.firestore.pipeline.CollectionGroup +import com.google.cloud.firestore.pipeline.Database +import com.google.cloud.firestore.pipeline.Documents import com.google.cloud.firestore.pipeline.Expr -import com.google.cloud.firestore.pipeline.ExprAsAlias import com.google.cloud.firestore.pipeline.Field import com.google.cloud.firestore.pipeline.Fields import com.google.cloud.firestore.pipeline.Filter 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.Sort import com.google.cloud.firestore.pipeline.Sort.Ordering import com.google.cloud.firestore.pipeline.Stage -import com.google.cloud.firestore.pipeline.ToProto +import com.google.cloud.firestore.pipeline.toStageProto +import com.google.common.base.Preconditions +import com.google.common.collect.ImmutableMap +import com.google.firestore.v1.Document +import com.google.firestore.v1.ExecutePipelineRequest +import com.google.firestore.v1.ExecutePipelineResponse +import com.google.firestore.v1.StructuredPipeline import com.google.firestore.v1.Value +import io.opencensus.trace.AttributeValue +import io.opencensus.trace.Tracing +import java.util.logging.Level +import java.util.logging.Logger class PaginatingPipeline internal constructor( val p: Pipeline, @@ -82,12 +99,15 @@ class PaginatingPipeline internal constructor( * .aggregate(count(Field.of("orderId")).asAlias("orderCount")); * ``` */ -class Pipeline private constructor(private val stages: List, private val name: String): - ToProto { +class Pipeline private constructor(private val stages: List, private val name: String) { - private constructor(collection: Collection) : this(listOf(collection), collection.path) + private constructor(collection: Collection) : this(listOf(collection), collection.relativePath) - private constructor(group: CollectionGroup): this(listOf(group), group.path) + private constructor(group: CollectionGroup) : this(listOf(group), group.collectionId) + + private constructor(db: Database) : this(listOf(db), db.name) + + private constructor(docs: Documents) : this(listOf(docs), docs.name) companion object { @JvmStatic @@ -106,40 +126,60 @@ class Pipeline private constructor(private val stages: List, private val } @JvmStatic - fun fromCollectionGroup(group: String): Pipeline { - return Pipeline(CollectionGroup(group)) + fun fromCollectionGroup(collectionId: String): Pipeline { + Preconditions.checkArgument( + !collectionId.contains("/"), + "Invalid collectionId '%s'. Collection IDs must not contain '/'.", + collectionId + ) + return Pipeline(CollectionGroup(collectionId)) + } + + @JvmStatic + fun fromDatabase(): Pipeline { + return Pipeline(Database()) + } + + @JvmStatic + fun fromDocuments(vararg docs: DocumentReference): Pipeline { + return Pipeline(Documents.of(*docs)) } } - fun project(vararg projections: Projectable): Pipeline { + private fun projectablesToMap(vararg projectables: Projectable): Map { val projMap = mutableMapOf() - for(proj in projections) { - when (proj){ + for (proj in projectables) { + when (proj) { is Field -> projMap[proj.field] = proj - is AggregatorTarget -> projMap[proj.target] = proj.current - is ExprAsAlias -> projMap[proj.alias] = proj.current - is Fields -> proj.fs?.forEach { projMap[it.field] = it} + is AggregatorTarget -> projMap[proj.fieldName] = proj.accumulator + is Fields -> proj.fs?.forEach { projMap[it.field] = it } } } - return Pipeline(stages.plus(Project(projMap)), name) + return projMap + } + + fun addFields(vararg fields: Projectable): Pipeline { + return Pipeline(stages.plus(AddFields(projectablesToMap(*fields))), name) + } + + fun project(vararg projections: Projectable): Pipeline { + return Pipeline(stages.plus(Project(projectablesToMap(*projections))), name) } - fun filter(condition: Function.FilterCondition): Pipeline { + fun filter(condition: T): Pipeline where T : Expr, T:Function.FilterCondition{ return Pipeline(stages.plus(Filter(condition)), name) } fun offset(offset: Int): Pipeline { - return this + return Pipeline(stages.plus(Offset(offset)), name) } fun limit(limit: Int): Pipeline { - return this + return Pipeline(stages.plus(Limit(limit)), name) } - fun aggregate(vararg aggregator: AggregatorTarget): Pipeline { - // operations.add(Group()) - // operations.add(aggregator) - return this + fun aggregate(vararg aggregators: AggregatorTarget): Pipeline { + return Pipeline(stages.plus(Aggregate(*aggregators)), name) } fun findNearest( @@ -171,35 +211,174 @@ class Pipeline private constructor(private val stages: List, private val return this } - fun execute(db: Firestore): ApiFuture> { - return ApiFutures.immediateFuture(listOf(PipelineResult()).iterator()) + fun execute(db: Firestore): ApiFuture> { + when (db) { + is FirestoreImpl -> { + val pipelineValue = toProto() + val request = ExecutePipelineRequest.newBuilder() + .setStructuredPipeline( + StructuredPipeline.newBuilder() + .setPipeline(pipelineValue.pipelineValue).build() + ).build() + + val futureResult = SettableApiFuture.create>() + pipelineInternalStream(db, request, object : PipelineResultObserver() { + val results = mutableListOf() + override fun onCompleted() { + futureResult.set(results) + } + + override fun onNext(result: PipelineResult?) { + results.add(result!!) + } + + override fun onError(t: Throwable?) { + futureResult.setException(t) + } + }) + + return futureResult + } + + else -> { + TODO() + } + } } fun execute(db: Firestore, observer: ApiStreamObserver): Unit { + when (db) { + is FirestoreImpl -> { + val pipelineValue = toProto() + val request = ExecutePipelineRequest.newBuilder() + .setDatabase(db.resourcePath.databaseName.toString()) + .setStructuredPipeline( + StructuredPipeline.newBuilder() + .setPipeline(pipelineValue.pipelineValue).build() + ).build() + + pipelineInternalStream(db, request, object : PipelineResultObserver() { + override fun onCompleted() { + observer.onCompleted() + } + + override fun onNext(result: PipelineResult?) { + observer.onNext(result) + } + + override fun onError(t: Throwable?) { + observer.onError(t) + } + }) + } + + else -> { + TODO() + } + } } - override fun toProto(): Value { + fun toProto(): Value { return Value.newBuilder() - .setPipelineValue(com.google.firestore.v1.Pipeline.newBuilder() - .addAllStages(stages.map { toStageProto(it) }) + .setPipelineValue( + com.google.firestore.v1.Pipeline.newBuilder() + .addAllStages(stages.map { toStageProto(it) }) ) .build() } } -internal fun toStageProto(stage: Stage): com.google.firestore.v1.Pipeline.Stage { - return when (stage) { - is Project -> com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName("project") - .addArgs(UserDataConverter.encodeValue(FieldPath.empty(), stage.projections, UserDataConverter.ARGUMENT)) - .build() - is Collection -> com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName("collection") - .addArgs(UserDataConverter.encodeValue(FieldPath.empty(),stage.path, UserDataConverter.ARGUMENT)) - .build() - else -> { - TODO() - } +internal fun encodeValue(value: Any?): Value? { + return UserDataConverter.encodeValue( + FieldPath.empty(), + value, + UserDataConverter.ARGUMENT + ) +} + +private abstract class PipelineResultObserver + + : ApiStreamObserver { + var executionTime: Timestamp? = null + private set + + fun onCompleted(executionTime: Timestamp?) { + this.executionTime = executionTime + this.onCompleted() } } +private fun pipelineInternalStream( + rpcContext: FirestoreImpl, + request: ExecutePipelineRequest, + resultObserver: PipelineResultObserver +) { + val observer: ResponseObserver = + object : ResponseObserver { + var executionTime: Timestamp? = null + var firstResponse: Boolean = false + var numDocuments: Int = 0 + + // The stream's `onComplete()` could be called more than once, + // this flag makes sure only the first one is actually processed. + var hasCompleted: Boolean = false + + override fun onStart(streamController: StreamController) { + } + + override fun onResponse(response: ExecutePipelineResponse) { + if (!firstResponse) { + firstResponse = true + Tracing.getTracer().currentSpan.addAnnotation("Firestore.Query: First response") + } + if (response.resultsCount > 0) { + numDocuments += response.resultsCount + if (numDocuments % 100 == 0) { + Tracing.getTracer() + .currentSpan + .addAnnotation("Firestore.Query: Received 100 documents") + } + response.resultsList.forEach { doc: Document -> + resultObserver.onNext( + PipelineResult.fromDocument( + rpcContext, + response.executionTime, + doc + ) + ) + } + } + + if (executionTime == null) { + executionTime = Timestamp.fromProto(response.executionTime) + } + } + + override fun onError(throwable: Throwable) { + Tracing.getTracer().currentSpan.addAnnotation("Firestore.Query: Error") + resultObserver.onError(throwable) + } + + override fun onComplete() { + if (hasCompleted) { + return + } + hasCompleted = true + + Tracing.getTracer() + .currentSpan + .addAnnotation( + "Firestore.Query: Completed", + ImmutableMap.of( + "numDocuments", AttributeValue.longAttributeValue(numDocuments.toLong()) + ) + ) + resultObserver.onCompleted(executionTime) + } + } + + Logger.getLogger("Pipeline") + .log(Level.WARNING, "Sending request: $request") + + rpcContext.streamRequest(request, observer, rpcContext.client.executePipelineCallable()) +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt index 9bf617c74..ab184c2c9 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt @@ -1,6 +1,7 @@ package com.google.cloud.firestore import com.google.cloud.Timestamp +import com.google.firestore.v1.Document import com.google.firestore.v1.Value import java.util.Date import javax.annotation.Nonnull @@ -8,13 +9,11 @@ import javax.annotation.Nonnull data class PipelineResult internal constructor( private val rpcContext: FirestoreRpcContext<*>?, val reference: DocumentReference?, - val protoFields: Map?, - val readTime: Timestamp?, + val protoFields: Map, + val readTime: Timestamp, val updateTime: Timestamp?, val createTime: Timestamp? ) { - constructor() : this(null, null, null, null, null, null) - val id: String? get() = reference?.id @@ -154,5 +153,21 @@ data class PipelineResult internal constructor( } val isEmpty: Boolean - get() = protoFields == null || protoFields.isEmpty() + get() = protoFields.isEmpty() + + companion object { + @JvmStatic + internal fun fromDocument( + rpcContext: FirestoreRpcContext<*>?, readTime: com.google.protobuf.Timestamp, document: Document + ): PipelineResult { + return PipelineResult( + rpcContext, + document.name?.let { DocumentReference(rpcContext, ResourcePath.create(it)) }, + document.fieldsMap, + Timestamp.fromProto(readTime), + document.updateTime?.let {Timestamp.fromProto(it)}, + document.createTime?.let {Timestamp.fromProto(it)}, + ) + } + } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java index 6506b9f2b..8f824de71 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java @@ -16,8 +16,10 @@ package com.google.cloud.firestore; +import static com.google.cloud.firestore.pipeline.ExpressionsKt.exprToValue; + import com.google.cloud.Timestamp; -import com.google.cloud.firestore.pipeline.ToProto; +import com.google.cloud.firestore.pipeline.Expr; import com.google.common.base.Preconditions; import com.google.firestore.v1.ArrayValue; import com.google.firestore.v1.MapValue; @@ -153,10 +155,10 @@ static Value encodeValue( } else if (sanitizedObject instanceof Blob) { Blob blob = (Blob) sanitizedObject; return Value.newBuilder().setBytesValue(blob.toByteString()).build(); + } else if (sanitizedObject instanceof Expr) { + return exprToValue((Expr) sanitizedObject); } else if (sanitizedObject instanceof Value) { return (Value) sanitizedObject; - } else if (sanitizedObject instanceof ToProto) { - return ((ToProto) sanitizedObject).toProto(); } else if (sanitizedObject instanceof DocumentReference) { DocumentReference docRef = (DocumentReference) sanitizedObject; return Value.newBuilder().setReferenceValue(docRef.getName()).build(); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index 286e86895..3abecfa5f 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -1,6 +1,7 @@ package com.google.cloud.firestore.pipeline import com.google.cloud.firestore.Pipeline +import com.google.cloud.firestore.encodeValue import com.google.cloud.firestore.pipeline.Function.ArrayContains import com.google.cloud.firestore.pipeline.Function.ArrayContainsAny import com.google.cloud.firestore.pipeline.Function.Avg @@ -16,22 +17,26 @@ import com.google.cloud.firestore.pipeline.Function.IsNaN import com.google.cloud.firestore.pipeline.Function.IsNull import com.google.cloud.firestore.pipeline.Function.LessThan import com.google.cloud.firestore.pipeline.Function.LessThanOrEqual -import com.google.cloud.firestore.pipeline.Function.MapGet import com.google.cloud.firestore.pipeline.Function.NotEqual -import com.google.cloud.firestore.pipeline.Function.NotIn import com.google.cloud.firestore.pipeline.Function.Sum import com.google.firestore.v1.Value - -internal interface ToProto { - fun toProto(): Value -} +import com.google.cloud.Timestamp +import com.google.cloud.firestore.Blob +import com.google.cloud.firestore.DocumentReference +import com.google.cloud.firestore.GeoPoint +import com.google.cloud.firestore.pipeline.Sort.Ordering +import com.google.cloud.firestore.pipeline.Sort.Ordering.Direction +import com.google.firestore.v1.ArrayValue +import java.util.Date internal fun exprToValue(expr: Expr): Value{ return when(expr) { is Constant -> expr.toProto() is Field -> expr.toProto() is Function -> expr.toProto() - // is ExprAsAlias -> + is ListOfExprs -> { + Value.newBuilder().setArrayValue(ArrayValue.newBuilder().addAllValues(expr.conditions.map { exprToValue(it) })).build() + } else -> { TODO() } @@ -43,44 +48,35 @@ sealed interface Projectable interface Expr { // Infix functions returning Function subclasses infix fun equal(other: Expr) = Equal(this, other) - infix fun equal(other: Number) = Equal(this, Constant.of(other)) - infix fun equal(other: String) = Equal(this, Constant.of(other)) infix fun equal(other: Any) = Equal(this, Constant.of(other)) infix fun notEqual(other: Expr) = NotEqual(this, other) - infix fun notEqual(other: Number) = NotEqual(this, Constant.of(other)) - infix fun notEqual(other: String) = NotEqual(this, Constant.of(other)) infix fun notEqual(other: Any) = NotEqual(this, Constant.of(other)) infix fun greaterThan(other: Expr) = GreaterThan(this, other) - infix fun greaterThan(other: Number) = GreaterThan(this, Constant.of(other)) - infix fun greaterThan(other: String) = GreaterThan(this, Constant.of(other)) infix fun greaterThan(other: Any) = GreaterThan(this, Constant.of(other)) infix fun greaterThanOrEqual(other: Expr) = GreaterThanOrEqual(this, other) - infix fun greaterThanOrEqual(other: Number) = GreaterThanOrEqual(this, Constant.of(other)) - infix fun greaterThanOrEqual(other: String) = GreaterThanOrEqual(this, Constant.of(other)) infix fun greaterThanOrEqual(other: Any) = GreaterThanOrEqual(this, Constant.of(other)) infix fun lessThan(other: Expr) = LessThan(this, other) - infix fun lessThan(other: Number) = LessThan(this, Constant.of(other)) - infix fun lessThan(other: String) = LessThan(this, Constant.of(other)) infix fun lessThan(other: Any) = LessThan(this, Constant.of(other)) infix fun lessThanOrEqual(other: Expr) = LessThanOrEqual(this, other) - infix fun lessThanOrEqual(other: Number) = LessThanOrEqual(this, Constant.of(other)) - infix fun lessThanOrEqual(other: String) = LessThanOrEqual(this, Constant.of(other)) infix fun lessThanOrEqual(other: Any) = LessThanOrEqual(this, Constant.of(other)) - fun inAny(vararg other: Expr) = In(this, other.toList()) - fun notInAny(vararg other: Expr) = NotIn(this, other.toList()) - - infix fun mapGet(key: String) = MapGet(this, key) + fun inAny(vararg other: Any) = In(this, other.toList().map { when(it) { + is Expr -> it + else -> Constant.of(it) }}) + fun notInAny(vararg other: Any) = Function.Not(In(this, other.toList().map { when(it) { + is Expr -> it + else -> Constant.of(it) }})) infix fun arrayContains(element: Expr) = ArrayContains(this, element) - infix fun arrayContains(element: Number) = ArrayContains(this, Constant.of(element)) - infix fun arrayContains(element: String) = ArrayContains(this, Constant.of(element)) infix fun arrayContains(element: Any) = ArrayContains(this, Constant.of(element)) fun arrayContainsAny(vararg elements: Expr) = ArrayContainsAny(this, elements.toList()) + fun arrayContainsAny(vararg elements: Any) = ArrayContainsAny(this, elements.toList().map { Constant.of(it) }) fun isNaN() = IsNaN(this) fun isNull() = IsNull(this) fun sum() = Sum(this, false) fun avg() = Avg(this, false) fun count() = Count(this, false) + fun min() = Count(this, false) + fun max() = Count(this, false) infix fun cosineDistance(other: Expr) = CosineDistance(this, other) infix fun cosineDistance(other: DoubleArray) = @@ -94,54 +90,108 @@ interface Expr { infix fun dotProductDistance(other: DoubleArray) = DotProductDistance(this, Constant.ofVector(other)) - fun asAlias(alias: String): Projectable = ExprAsAlias(this, alias) + fun ascending(): Ordering { + return Ordering(this, Direction.ASCENDING) + } + + fun descending(): Ordering { + return Ordering(this, Direction.DESCENDING) + } } // Convenient class for internal usage internal data class ListOfExprs(val conditions: List) : Expr -internal data class ListOfConditions(val conditions: List) : Expr, - Function.FilterCondition -data class Constant internal constructor(val value: Any) : Expr, ToProto { + +data class Constant internal constructor(val value: Any?) : Expr { companion object { @JvmStatic - fun of(value: String): Constant { + fun of(value: String?): Constant { return Constant(value) } @JvmStatic - fun of(value: Number): Constant { + fun of(value: Number?): Constant { return Constant(value) } @JvmStatic - fun of(value: Any): Constant { + fun of(value: Date?): Constant { return Constant(value) } @JvmStatic - fun ofArray(value: Iterable): Constant { + fun of(value: Timestamp?): Constant { return Constant(value) } @JvmStatic - fun ofMap(value: Map): Constant { + fun of(value: Boolean?): Constant { return Constant(value) } @JvmStatic - fun ofVector(value: DoubleArray): Constant { + fun of(value: GeoPoint?): Constant { + return Constant(value) + } + + @JvmStatic + fun of(value: Blob?): Constant { + return Constant(value) + } + + @JvmStatic + fun of(value: DocumentReference?): Constant { + return Constant(value) + } + + @JvmStatic + internal fun of(value: Any?): Constant { + if (value == null) { + return Constant(null) + } + + return when (value) { + is String -> of(value) + is Number -> of(value) + is Date -> of(value) + is Timestamp -> of(value) + is Boolean -> of(value) + is GeoPoint -> of(value) + is Blob -> of(value) + is DocumentReference -> of(value) + else -> TODO("Unknown type: $value") + } + } + + @JvmStatic + fun ofArray(value: Iterable): Constant { + return Constant(value) + } + + @JvmStatic + fun ofArray(value: Array): Constant { + return Constant(value) + } + + @JvmStatic + fun ofMap(value: Map): Constant { return Constant(value) } + + @JvmStatic + fun ofVector(value: DoubleArray): Constant { + // TODO: Vector is really a map, not a list + return Constant(value.asList()) + } } - override fun toProto(): Value { - return Value.newBuilder().build() + fun toProto(): Value { + return encodeValue(value)!! } } data class Field internal constructor(val field: String, var pipeline: Pipeline? = null) : Expr, - Projectable, - ToProto { + Projectable{ companion object { const val DOCUMENT_ID: String = "__path__" @@ -151,9 +201,7 @@ data class Field internal constructor(val field: String, var pipeline: Pipeline? } } - fun exists() = Function.Exists(this) - - override fun toProto(): Value { + fun toProto(): Value { return Value.newBuilder().setFieldReferenceValue(field).build() } } @@ -164,24 +212,16 @@ data class Fields internal constructor(val fs: List? = null) : Expr, Proj fun of(f1: String, vararg f: String): Fields { return Fields(listOf(Field.of(f1)) + f.map(Field.Companion::of)) } - - @JvmStatic - fun ofAll(): Fields { - return Fields(null) - } } } -internal data class ExprAsAlias(val current: Expr, val alias: String) : Expr, Projectable - data class AggregatorTarget internal constructor( - val current: Function.Accumulator, val target: String, + val accumulator: Function.Accumulator, val fieldName: String, override var distinct: Boolean -) : Expr, - Projectable, +) : Projectable, Function.Accumulator -sealed class Function(val name: String, val params: List): Expr, ToProto { +sealed class Function(val name: String, val params: List): Expr { interface FilterCondition interface Accumulator: Expr { @@ -195,58 +235,43 @@ sealed class Function(val name: String, val params: List): Expr, ToProto { fun toField(target: String) = AggregatorTarget(this, target, this.distinct) } - override fun toProto(): Value { + fun toProto(): Value { return Value.newBuilder().setFunctionValue(com.google.firestore.v1.Function.newBuilder() .setName(name) .addAllArgs(params.map { exprToValue(it) })).build() } data class Equal internal constructor(val left: Expr, val right: Expr) : - Function("equal", listOf(left, right)), FilterCondition + Function("eq", listOf(left, right)), FilterCondition data class NotEqual(val left: Expr, val right: Expr) : - Function("not_equal", listOf(left, right)), FilterCondition + Function("neq", listOf(left, right)), FilterCondition data class GreaterThan(val left: Expr, val right: Expr) : - Function("greater_than", listOf(left, right)), FilterCondition + Function("gt", listOf(left, right)), FilterCondition data class GreaterThanOrEqual(val left: Expr, val right: Expr) : - Function("greater_than_equal", listOf(left, right)), FilterCondition - - data class In(val left: Expr, val others: List) : - Function("in", listOf(left, ListOfExprs(others))), - FilterCondition // For 'in' + Function("gte", listOf(left, right)), FilterCondition data class LessThan(val left: Expr, val right: Expr) : - Function("less_than", listOf(left, right)), FilterCondition + Function("lt", listOf(left, right)), FilterCondition data class LessThanOrEqual(val left: Expr, val right: Expr) : - Function("less_than_equal", listOf(left, right)), FilterCondition + Function("lte", listOf(left, right)), FilterCondition - data class NotIn(val left: Expr, val others: List) : - Function("not_in", listOf(left, ListOfExprs(others))), - FilterCondition // For 'not in' + data class In(val left: Expr, val others: List) : + Function("in", listOf(left, ListOfExprs(others))), + FilterCondition // For 'in' - data class And(val conditions: List) : - Function("and", listOf(ListOfConditions(conditions))), FilterCondition + data class And(val conditions: List) : + Function("and", conditions), FilterCondition where T : FilterCondition, T:Expr - data class Or(val conditions: List) : - Function("or", listOf(ListOfConditions(conditions))), FilterCondition + data class Or(val conditions: List) : + Function("or", conditions), FilterCondition where T : FilterCondition, T:Expr data class Not(val condition: Expr) : Function("not", listOf(condition)), FilterCondition - data class Exists(val current: Field) : Function("exists", listOf(current)), - FilterCondition - - data class MapGet(val map: Expr, val key: String) : Function( - "map_get", - listOf( - map, - Constant(Value.getDefaultInstance().toBuilder().setStringValue(key).build()) - ) - ) - data class ArrayContains(val array: Expr, val element: Expr) : Function("array_contains", listOf(array, element)), FilterCondition @@ -266,12 +291,16 @@ sealed class Function(val name: String, val params: List): Expr, ToProto { data class Count(val value: Expr, override var distinct: Boolean) : Function("count", listOf(value)), Accumulator + data class Min(val value: Expr, override var distinct: Boolean) : + Function("min", listOf(value)), Accumulator + data class Max(val value: Expr, override var distinct: Boolean) : + Function("max", listOf(value)), Accumulator data class CosineDistance(val vector1: Expr, val vector2: Expr) : Function("cosine_distance", listOf(vector1, vector2)) data class DotProductDistance(val vector1: Expr, val vector2: Expr) : - Function("dot_product_distance", listOf(vector1, vector2)) + Function("dot_product", listOf(vector1, vector2)) data class EuclideanDistance(val vector1: Expr, val vector2: Expr) : Function("euclidean_distance", listOf(vector1, vector2)) @@ -283,38 +312,18 @@ sealed class Function(val name: String, val params: List): Expr, ToProto { @JvmStatic fun equal(left: Expr, right: Expr) = Equal(left, right) - @JvmStatic - fun equal(left: Expr, right: String) = Equal(left, Constant.of(right)) - - @JvmStatic - fun equal(left: Expr, right: Number) = Equal(left, Constant.of(right)) - @JvmStatic fun equal(left: Expr, right: Any) = Equal(left, Constant.of(right)) @JvmStatic fun notEqual(left: Expr, right: Expr) = NotEqual(left, right) - @JvmStatic - fun notEqual(left: Expr, right: String) = NotEqual(left, Constant.of(right)) - - @JvmStatic - fun notEqual(left: Expr, right: Number) = NotEqual(left, Constant.of(right)) - @JvmStatic fun notEqual(left: Expr, right: Any) = NotEqual(left, Constant.of(right)) @JvmStatic fun greaterThan(left: Expr, right: Expr) = GreaterThan(left, right) - @JvmStatic - fun greaterThan(left: Expr, right: String) = - GreaterThan(left, Constant.of(right)) - - @JvmStatic - fun greaterThan(left: Expr, right: Number) = - GreaterThan(left, Constant.of(right)) - @JvmStatic fun greaterThan(left: Expr, right: Any) = GreaterThan(left, Constant.of(right)) @@ -322,76 +331,55 @@ sealed class Function(val name: String, val params: List): Expr, ToProto { @JvmStatic fun greaterThanOrEqual(left: Expr, right: Expr) = GreaterThanOrEqual(left, right) - @JvmStatic - fun greaterThanOrEqual(left: Expr, right: String) = GreaterThanOrEqual(left, Constant.of(right)) - - @JvmStatic - fun greaterThanOrEqual(left: Expr, right: Number) = GreaterThanOrEqual(left, Constant.of(right)) - @JvmStatic fun greaterThanOrEqual(left: Expr, right: Any) = GreaterThanOrEqual(left, Constant.of(right)) @JvmStatic fun lessThan(left: Expr, right: Expr) = LessThan(left, right) - @JvmStatic - fun lessThan(left: Expr, right: String) = LessThan(left, Constant.of(right)) - - @JvmStatic - fun lessThan(left: Expr, right: Number) = LessThan(left, Constant.of(right)) - @JvmStatic fun lessThan(left: Expr, right: Any) = LessThan(left, Constant.of(right)) @JvmStatic fun lessThanOrEqual(left: Expr, right: Expr) = LessThanOrEqual(left, right) - @JvmStatic - fun lessThanOrEqual(left: Expr, right: String) = LessThanOrEqual(left, Constant.of(right)) - - @JvmStatic - fun lessThanOrEqual(left: Expr, right: Number) = LessThanOrEqual(left, Constant.of(right)) - @JvmStatic fun lessThanOrEqual(left: Expr, right: Any) = LessThanOrEqual(left, Constant.of(right)) @JvmStatic - fun inAny(left: Expr, values: List) = In(left, values) + fun inAny(left: Expr, values: List) = In(left, values.map { + when (it) { + is Expr -> it + else -> Constant.of(it) + } + }) @JvmStatic - fun notInAny(left: Expr, values: List) = NotIn(left, values) + fun notInAny(left: Expr, values: List) = Not(In(left, values.map { + when (it) { + is Expr -> it + else ->Constant.of(it) + }})) @JvmStatic - fun and(left: FilterCondition, right: FilterCondition) = + fun and(left: T, right: T) where T : FilterCondition, T:Expr = And(listOf(left, right)) @JvmStatic - fun and(left: FilterCondition, vararg other: FilterCondition) = + fun and(left: T, vararg other: T) where T : FilterCondition, T:Expr= And(listOf(left) + other.toList()) @JvmStatic - fun or(left: FilterCondition, right: FilterCondition) = + fun or(left: T, right: T) where T : FilterCondition, T:Expr = Or(listOf(left, right)) @JvmStatic - fun or(left: FilterCondition, vararg other: FilterCondition) = + fun or(left: T, vararg other: T) where T : FilterCondition, T:Expr= Or(listOf(left) + other.toList()) - @JvmStatic - fun exists(expr: Field) = Exists(expr) - - @JvmStatic - fun mapGet(expr: Expr, key: String) = MapGet(expr, key) - @JvmStatic fun arrayContains(expr: Expr, element: Expr) = ArrayContains(expr, element) - @JvmStatic - fun arrayContains(expr: Expr, element: Number) = ArrayContains(expr, Constant.of(element)) - - @JvmStatic - fun arrayContains(expr: Expr, element: String) = ArrayContains(expr, Constant.of(element)) - @JvmStatic fun arrayContains(expr: Expr, element: Any) = ArrayContains(expr, Constant.of(element)) @@ -399,6 +387,10 @@ sealed class Function(val name: String, val params: List): Expr, ToProto { fun arrayContainsAny(expr: Expr, vararg elements: Expr) = ArrayContainsAny(expr, elements.toList()) + @JvmStatic + fun arrayContainsAny(expr: Expr, vararg elements: Any) = + ArrayContainsAny(expr, elements.toList().map { Constant.of(it) }) + @JvmStatic fun isNaN(expr: Expr) = IsNaN(expr) @@ -414,6 +406,12 @@ sealed class Function(val name: String, val params: List): Expr, ToProto { @JvmStatic fun avg(expr: Expr) = Avg(expr, false) + @JvmStatic + fun min(expr: Expr) = Sum(expr, false) + + @JvmStatic + fun max(expr: Expr) = Avg(expr, false) + @JvmStatic fun count(expr: Expr) = Count(expr, false) @@ -438,9 +436,6 @@ sealed class Function(val name: String, val params: List): Expr, ToProto { fun euclideanDistance(expr: Expr, other: DoubleArray) = EuclideanDistance(expr, Constant.ofVector(other)) - @JvmStatic - fun asAlias(expr: Expr, alias: String): Projectable = ExprAsAlias(expr, alias) - @JvmStatic fun function(name: String, params: List) = Generic(name, params) } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt index 06e445d01..0ffc10cbe 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt @@ -1,41 +1,88 @@ package com.google.cloud.firestore.pipeline -import com.google.firestore.v1.Pipeline +import com.google.cloud.firestore.DocumentReference +import com.google.cloud.firestore.encodeValue +import com.google.firestore.v1.MapValue import com.google.firestore.v1.Value +import java.util.Locale internal interface Stage -internal data class Collection(val path: String) : Stage { +internal data class Collection(val relativePath: String) : Stage { + val name = "collection" +} +internal data class CollectionGroup(val collectionId: String) : Stage { + val name = "collection_group" } -internal data class CollectionGroup(val path: String) : Stage { +internal class Database: Stage { + val name = "database" +} +internal data class Documents(val documents: List): Stage { + val name = "documents" + companion object { + @JvmStatic + fun of(vararg documents: DocumentReference): Documents { + return Documents(documents.map { it.path }) + } + } } internal data class Project(val projections: Map) : Stage { + val name = "project" +} + +internal data class AddFields(val fields: Map) : Stage { + val name = "add_fields" +} + +internal data class Filter (val condition: T) : Stage where T:Function.FilterCondition, T:Expr { + val name = "filter" } -data class Filter(val condition: Function.FilterCondition) : Stage { +internal class Offset(val offset: Int) : Stage { + val name = "offset" } -data class Offset(val offset: Int) : Stage { +internal class Limit(val limit: Int) : Stage { + val name = "limit" } -data class Limit(val limit: Int) : Stage { +class Aggregate internal constructor( + val groups: Map, + val accumulators: Map +) : Stage { + val name = "aggregate" + + internal constructor(vararg aggregators: AggregatorTarget) : + this(emptyMap(), aggregators.associate { it.fieldName to it.accumulator }) } -data class FindNearest internal constructor( +class FindNearest internal constructor( val property: Field, val vector: DoubleArray, + val distanceMeasure: DistanceMeasure, val options: FindNearestOptions ) : Stage { - sealed interface Similarity { - data object Euclidean : Similarity - data object Cosine : Similarity - data object DotProduct : Similarity + val name = "find_nearest" - class GenericSimilarity(val name: String) : Similarity + sealed interface DistanceMeasure { + data object Euclidean : DistanceMeasure + data object Cosine : DistanceMeasure + data object DotProduct : DistanceMeasure + + class GenericDistanceMeasure(val name: String) : DistanceMeasure + + fun toProtoString(): String{ + return when (this) { + is Euclidean -> "euclidean" + is Cosine -> "cosine" + is DotProduct -> "dot_product" + is GenericDistanceMeasure -> name + } + } companion object { @JvmStatic @@ -48,62 +95,204 @@ data class FindNearest internal constructor( fun dotProduct() = DotProduct @JvmStatic - fun generic(name: String) = GenericSimilarity(name) + fun generic(name: String) = GenericDistanceMeasure(name) } } data class FindNearestOptions( - val similarity: Similarity, - val limit: Long, + val limit: Long?, val output: Field? = null ) - } -data class Sort internal constructor( +class Sort internal constructor( val orders: List, val density: Density = Density.UNSPECIFIED, val truncation: Truncation = Truncation.UNSPECIFIED ) : Stage { + val name = "sort" + enum class Density { UNSPECIFIED, - REQUIRED + REQUIRED; + override fun toString(): String + = name.lowercase(Locale.getDefault()) } enum class Truncation { UNSPECIFIED, - DISABLED + DISABLED; + override fun toString(): String + = name.lowercase(Locale.getDefault()) } - data class Ordering internal constructor(val expr: Expr, val dir: Direction = Direction.ASC) { + class Ordering internal constructor(private val expr: Expr, private val dir: Direction = Direction.ASCENDING) { enum class Direction { - ASC, - DESC + ASCENDING, + DESCENDING; + + override fun toString(): String + = name.lowercase(Locale.getDefault()) + } + + internal fun toProto(): Value { + return Value.newBuilder().setMapValue(MapValue.newBuilder() + .putFields("direction", encodeValue(dir.toString())) + .putFields("expression", encodeValue(expr)) + .build()).build() } companion object { @JvmStatic - fun of(expr: Expr, dir: Direction = Direction.ASC): Ordering { + fun of(expr: Expr, dir: Direction = Direction.ASCENDING): Ordering { return Ordering(expr, dir) } @JvmStatic fun of(expr: Expr): Ordering { - return Ordering(expr, Direction.ASC) + return Ordering(expr, Direction.ASCENDING) } @JvmStatic fun ascending(expr: Expr): Ordering { - return Ordering(expr, Direction.ASC) + return Ordering(expr, Direction.ASCENDING) } @JvmStatic fun descending(expr: Expr): Ordering { - return Ordering(expr, Direction.DESC) + return Ordering(expr, Direction.DESCENDING) } } } } -data class GenericStage(val name: String, val params: Map?) : Stage { +// internal class Pagination(): Stage, GenericStage() + +internal open class GenericStage(val name: String, val params: List) : Stage { +} + +internal fun toStageProto(stage: Stage): com.google.firestore.v1.Pipeline.Stage { + return when (stage) { + is Collection -> com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addArgs( + Value.newBuilder().setReferenceValue(stage.relativePath).build() + ) + .build() + + is CollectionGroup -> com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addArgs( + Value.newBuilder().setReferenceValue("").build() + ) + .addArgs( + encodeValue( + stage.collectionId, + ) + ) + .build() + + is Database -> com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .build() + + is Documents -> com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addAllArgs(stage.documents.map { + Value.newBuilder().setReferenceValue(it).build() + }) + .build() + + is Project -> com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addArgs( + encodeValue( + stage.projections, + ) + ) + .build() + + is AddFields -> com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addArgs( + encodeValue( + stage.fields, + ) + ) + .build() + + is Filter<*> -> com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addArgs( + encodeValue( + stage.condition, + ) + ) + .build() + + is Sort -> com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addAllArgs( + stage.orders.map { it.toProto() } + ) + .putOptions("density", encodeValue(stage.density)) + .putOptions("truncation", encodeValue(stage.truncation)) + .build() + + is Offset -> com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addArgs( + encodeValue( + stage.offset + ) + ) + .build() + + is Limit -> com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addArgs( + encodeValue( + stage.limit + ) + ) + .build() + + is Aggregate -> com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addArgs(encodeValue(stage.groups)) + .addArgs(encodeValue(stage.accumulators)) + .build() + + is FindNearest -> com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addArgs( + encodeValue( + stage.property + ) + ) + .addArgs( + encodeValue( + stage.vector + ) + ) + .addArgs( + encodeValue( + stage.distanceMeasure.toProtoString() + ) + ) + .putOptions("limit", encodeValue(stage.options.limit)) + .putOptions("distance_field", encodeValue(stage.options.output)) + .build() + + is GenericStage -> com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addAllArgs( + stage.params.map { encodeValue(it) } + ) + .build() + + else -> { + TODO() + } + } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/spi/v1/FirestoreRpc.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/spi/v1/FirestoreRpc.java index c2172fafb..5c8dd4572 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/spi/v1/FirestoreRpc.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/spi/v1/FirestoreRpc.java @@ -31,6 +31,8 @@ import com.google.firestore.v1.BeginTransactionResponse; import com.google.firestore.v1.CommitRequest; import com.google.firestore.v1.CommitResponse; +import com.google.firestore.v1.ExecutePipelineRequest; +import com.google.firestore.v1.ExecutePipelineResponse; import com.google.firestore.v1.ListCollectionIdsRequest; import com.google.firestore.v1.ListDocumentsRequest; import com.google.firestore.v1.ListenRequest; @@ -62,6 +64,10 @@ public interface FirestoreRpc extends AutoCloseable, ServiceRpc { /** Runs a query. */ ServerStreamingCallable runQueryCallable(); + /** Executes a pipeline. */ + ServerStreamingCallable + executePipelineCallable(); + /** Runs an aggregation query. */ ServerStreamingCallable runAggregationQueryCallable(); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/spi/v1/GrpcFirestoreRpc.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/spi/v1/GrpcFirestoreRpc.java index 9c606e8ab..0a60c62fd 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/spi/v1/GrpcFirestoreRpc.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/spi/v1/GrpcFirestoreRpc.java @@ -50,6 +50,8 @@ import com.google.firestore.v1.CommitRequest; import com.google.firestore.v1.CommitResponse; import com.google.firestore.v1.DatabaseRootName; +import com.google.firestore.v1.ExecutePipelineRequest; +import com.google.firestore.v1.ExecutePipelineResponse; import com.google.firestore.v1.ListCollectionIdsRequest; import com.google.firestore.v1.ListDocumentsRequest; import com.google.firestore.v1.ListenRequest; @@ -210,6 +212,12 @@ public ServerStreamingCallable runQueryCallab return firestoreStub.runQueryCallable(); } + @Override + public ServerStreamingCallable + executePipelineCallable() { + return firestoreStub.executePipelineCallable(); + } + @Override public ServerStreamingCallable runAggregationQueryCallable() { diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 393273237..891805f7d 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -22,9 +22,10 @@ import static com.google.cloud.firestore.pipeline.Function.lessThan; import static com.google.cloud.firestore.pipeline.Function.not; import static com.google.cloud.firestore.pipeline.Function.or; -import static com.google.cloud.firestore.pipeline.Ordering.ascending; -import static com.google.cloud.firestore.pipeline.Ordering.descending; +import static com.google.cloud.firestore.pipeline.Sort.Ordering.ascending; +import static com.google.cloud.firestore.pipeline.Sort.Ordering.descending; +import com.google.api.core.ApiFuture; import com.google.cloud.firestore.Firestore; import com.google.cloud.firestore.FirestoreOptions; import com.google.cloud.firestore.PaginatingPipeline; @@ -33,9 +34,10 @@ import com.google.cloud.firestore.pipeline.Constant; import com.google.cloud.firestore.pipeline.Field; import com.google.cloud.firestore.pipeline.Fields; -import com.google.cloud.firestore.pipeline.Ordering; -import com.google.cloud.firestore.pipeline.Ordering.Direction; +import com.google.cloud.firestore.pipeline.Sort; +import com.google.cloud.firestore.pipeline.Sort.Ordering.Direction; import java.util.Iterator; +import java.util.List; import org.junit.Before; import org.junit.Test; @@ -50,21 +52,12 @@ public void before() throws Exception { @Test public void projections() throws Exception { - Pipeline p = - Pipeline.fromCollection("coll1") - .project( - Field.of("foo"), - Constant.of("emptyValue").asAlias("emptyField"), - Field.of("embedding").cosineDistance(new double[] {1, 2, 3.0}).asAlias("distance")); + Pipeline p = Pipeline.fromCollection("coll1").project(Field.of("foo")); + ApiFuture> results = p.execute(firestore); // More compact - p = - Pipeline.fromCollection("coll1") - .project(Fields.of("foo", "bar", "baz"), Constant.of(42).asAlias("emptyField")); - p = - Pipeline.fromCollection("coll1") - // basically an addField - .project(Fields.ofAll(), Constant.of(42).asAlias("emptyField")); + p = Pipeline.fromCollection("coll1").project(Fields.of("foo", "bar", "baz")); + results = p.execute(firestore); } @Test @@ -77,6 +70,7 @@ public void filters() throws Exception { Field.of("bar").lessThan(Constant.of(100)), Constant.of("value").equal(Field.of("key")))) .filter(not(Constant.of(128).inAny(Field.of("f1"), Field.of("f2")))); + ApiFuture> results = p.execute(firestore); p = Pipeline.fromCollectionGroup("coll1") @@ -84,6 +78,7 @@ public void filters() throws Exception { .filter( or(lessThan(Field.of("bar"), 100), equal(Field.of("key"), Constant.of("value")))) .filter(not(Constant.of(128).inAny(Field.of("f1"), Field.of("f2")))); + results = p.execute(firestore); } @Test @@ -97,7 +92,7 @@ public void inFilters() throws Exception { public void aggregateWithoutGrouping() throws Exception { Pipeline p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) + .filter(Field.of("foo").inAny(42, Field.of("bar"))) .aggregate(avg(Field.of("score")).toField("avg_score_1")); } @@ -107,9 +102,10 @@ public void sorts() throws Exception { Pipeline.fromCollection("coll1") .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) .sort( - Ordering.of(Field.of("rank")), - Ordering.of( - cosineDistance(Field.of("embedding1"), Field.of("embedding2")), Direction.DESC)) + Field.of("rank").ascending(), + Sort.Ordering.of( + cosineDistance(Field.of("embedding1"), Field.of("embedding2")), + Direction.DESCENDING)) .limit(100); // equivalent but more concise. @@ -128,13 +124,29 @@ public void pagination() throws Exception { Pipeline.fromCollection("coll1") .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) .paginate( - 100, - Ordering.of( - cosineDistance(Field.of("embedding1"), Field.of("embedding2")), - Direction.DESC)); + 100, cosineDistance(Field.of("embedding1"), Field.of("embedding2")).descending()); Iterator result = firestore.execute(p.firstPage()).get(); - Iterator second = firestore.execute(p.startAfter(result.next())).get(); + // Iterator second = firestore.execute(p.startAfter(result.next())).get(); + } + + @Test + public void limit() throws Exception { + Pipeline p = + Pipeline.fromDatabase() + .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) + .limit(10); + + Iterator result = firestore.execute(p).get(); + } + + @Test + public void offset() throws Exception { + Pipeline p = + Pipeline.fromDocuments(firestore.document("foo/bar1"), firestore.document("foo/bar2")) + .offset(1); + + Iterator result = firestore.execute(p).get(); } @Test @@ -143,12 +155,10 @@ public void fluentAllTheWay() throws Exception { Pipeline.fromCollection("coll1") .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) .paginate( - 100, - Ordering.of( - cosineDistance(Field.of("embedding1"), Field.of("embedding2")), - Direction.DESC)); + 100, cosineDistance(Field.of("embedding1"), Field.of("embedding2")).descending()); - Iterator result = p.firstPage().execute(firestore).get(); - Iterator second = p.startAfter(result.next()).execute(firestore).get(); + ApiFuture> result = p.firstPage().execute(firestore); + // List second = + // p.startAfter(result.iterator().next()).execute(firestore).get(); } } From ed2d276e8c6e891f93c5ab1fc2ea4aad18665b5b Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Fri, 26 Apr 2024 10:41:33 -0400 Subject: [PATCH 33/65] query to pipeline --- .../com/google/cloud/firestore/Query.java | 7 +++++ .../google/cloud/firestore/it/ITBaseTest.java | 30 ++++++++++++++++++- .../cloud/firestore/it/ITPipelineTest.java | 16 ++++------ 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index 59ec6f960..1e8e0ee42 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -1955,6 +1955,13 @@ public AggregateQuery aggregate( return new AggregateQuery(this, aggregateFieldList); } + public Pipeline toPipeline() { + Pipeline ppl = Pipeline.fromCollection(this.options.getParentPath().append(this.options.getCollectionId()).getPath()); + for(FilterInternal f: this.options.getFilters()){ + } + return ppl; + } + /** * Returns true if this Query is equal to the provided object. * diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITBaseTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITBaseTest.java index a9f0bfb2f..54292a00f 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITBaseTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITBaseTest.java @@ -19,6 +19,7 @@ import static com.google.cloud.firestore.LocalFirestoreHelper.autoId; import static com.google.cloud.firestore.it.ITQueryTest.map; +import com.google.api.gax.rpc.TransportChannelProvider; import com.google.cloud.firestore.DocumentReference; import com.google.cloud.firestore.Firestore; import com.google.cloud.firestore.FirestoreOptions; @@ -54,7 +55,11 @@ public abstract class ITBaseTest { public void before() throws Exception { FirestoreOptions.Builder optionsBuilder = FirestoreOptions.newBuilder(); - String namedDb = System.getProperty("FIRESTORE_NAMED_DATABASE"); + String dbPropertyName = "FIRESTORE_NAMED_DATABASE"; + String namedDb = System.getProperty(dbPropertyName); + if (namedDb == null) { + namedDb = System.getenv(dbPropertyName); + } if (namedDb != null) { logger.log(Level.INFO, "Integration test using named database " + namedDb); optionsBuilder = optionsBuilder.setDatabaseId(namedDb); @@ -62,7 +67,30 @@ public void before() throws Exception { logger.log(Level.INFO, "Integration test using default database."); } + String targetPropertyName = "FIRESTORE_TARGET_BACKEND"; + String targetBackend = System.getProperty(targetPropertyName); + if (targetBackend == null) { + targetBackend = System.getenv(targetPropertyName); + } + TransportChannelProvider defaultProvider = optionsBuilder.build().getTransportChannelProvider(); + if (targetBackend != null) { + if (targetBackend.equals("PROD")) { + // do nothing to use the default + } else if (targetBackend.equals("QA")) { + optionsBuilder.setChannelProvider( + defaultProvider.withEndpoint("staging-firestore.sandbox.googleapis.com:443")); + } else if (targetBackend.equals("NIGHTLY")) { + optionsBuilder.setChannelProvider( + defaultProvider.withEndpoint("test-firestore.sandbox.googleapis.com:443")); + } else { + throw new IllegalArgumentException("Illegal target backend: " + targetBackend); + } + } + firestoreOptions = optionsBuilder.build(); + logger.log( + Level.INFO, + "Integration test against " + firestoreOptions.getTransportChannelProvider().getEndpoint()); firestore = firestoreOptions.getService(); primeBackend(); } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 891805f7d..3e1b6670b 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -40,24 +40,20 @@ import java.util.List; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; -public class ITPipelineTest { - - protected Firestore firestore; - - @Before - public void before() throws Exception { - firestore = FirestoreOptions.newBuilder().build().getService(); - } +@RunWith(JUnit4.class) +public class ITPipelineTest extends ITBaseTest { @Test public void projections() throws Exception { Pipeline p = Pipeline.fromCollection("coll1").project(Field.of("foo")); - ApiFuture> results = p.execute(firestore); + List results = p.execute(firestore).get(); // More compact p = Pipeline.fromCollection("coll1").project(Fields.of("foo", "bar", "baz")); - results = p.execute(firestore); + results = p.execute(firestore).get(); } @Test From f551073c65c6656843ed84b4933e1ef0a8998d39 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Mon, 29 Apr 2024 10:03:58 -0400 Subject: [PATCH 34/65] e2e tests fine tuning --- .../cloud/firestore/AggregateQuery.java | 11 + .../com/google/cloud/firestore/Firestore.java | 3 - .../google/cloud/firestore/FirestoreImpl.java | 7 - .../com/google/cloud/firestore/Pipeline.kt | 207 +++++---- .../google/cloud/firestore/PipelineResult.kt | 31 +- .../google/cloud/firestore/PipelineUtils.kt | 140 ++++++ .../com/google/cloud/firestore/Query.java | 77 +++- .../cloud/firestore/pipeline/Expressions.kt | 277 +++++++----- .../google/cloud/firestore/pipeline/Stages.kt | 269 +++++------- .../cloud/firestore/it/ITPipelineTest.java | 82 ++-- .../cloud/firestore/it/ITQueryTest.java | 403 ++++++++++++------ 11 files changed, 952 insertions(+), 555 deletions(-) create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.kt diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java index 1613b74dd..08e206240 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java @@ -24,6 +24,7 @@ import com.google.api.gax.rpc.StatusCode; import com.google.api.gax.rpc.StreamController; import com.google.cloud.Timestamp; +import com.google.cloud.firestore.pipeline.AggregatorTarget; import com.google.cloud.firestore.v1.FirestoreSettings; import com.google.firestore.v1.RunAggregationQueryRequest; import com.google.firestore.v1.RunAggregationQueryResponse; @@ -65,6 +66,16 @@ public Query getQuery() { return query; } + @Nonnull + public Pipeline toPipeline() { + return getQuery() + .toPipeline() + .aggregate( + this.aggregateFieldList.stream() + .map(PipelineUtilsKt::toPipelineAggregatorTarget) + .toArray(AggregatorTarget[]::new)); + } + /** * Executes this query. * diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java index ac552d80d..5bbb1164a 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java @@ -21,7 +21,6 @@ import com.google.api.core.InternalExtensionOnly; import com.google.api.gax.rpc.ApiStreamObserver; import com.google.cloud.Service; -import java.util.Iterator; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -288,8 +287,6 @@ void getAll( @Nonnull FirestoreBundle.Builder bundleBuilder(@Nonnull String bundleId); - ApiFuture> execute(Pipeline pipeline); - /** * Closes the gRPC channels associated with this instance and frees up their resources. This * method blocks until all channels are closed. Once this method is called, this Firestore client diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java index 618b27d0d..796d0c165 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java @@ -18,7 +18,6 @@ import com.google.api.core.ApiClock; import com.google.api.core.ApiFuture; -import com.google.api.core.ApiFutures; import com.google.api.core.NanoClock; import com.google.api.core.SettableApiFuture; import com.google.api.gax.rpc.ApiStreamObserver; @@ -46,7 +45,6 @@ import java.security.SecureRandom; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Random; @@ -410,11 +408,6 @@ public FirestoreBundle.Builder bundleBuilder(@Nullable String bundleId) { return new FirestoreBundle.Builder(id); } - @Override - public ApiFuture> execute(Pipeline pipeline) { - return ApiFutures.immediateFuture(null); - } - /** Returns the name of the Firestore project associated with this client. */ @Override public String getDatabaseName() { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 422a15816..4e2682bb7 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -29,6 +29,7 @@ import com.google.cloud.firestore.pipeline.Stage import com.google.cloud.firestore.pipeline.toStageProto import com.google.common.base.Preconditions import com.google.common.collect.ImmutableMap +import com.google.firestore.v1.Cursor import com.google.firestore.v1.Document import com.google.firestore.v1.ExecutePipelineRequest import com.google.firestore.v1.ExecutePipelineResponse @@ -39,46 +40,70 @@ import io.opencensus.trace.Tracing import java.util.logging.Level import java.util.logging.Logger -class PaginatingPipeline internal constructor( - val p: Pipeline, - pageSize: Int, - orders: Array +internal fun setStartCursor(pipeline: PaginatingPipeline, cursor: Cursor): PaginatingPipeline { + return pipeline +} + +internal fun setEndCursor(pipeline: PaginatingPipeline, cursor: Cursor): PaginatingPipeline { + return pipeline +} + +class PaginatingPipeline +internal constructor( + internal val p: Pipeline, + internal val pageSize: Int, + internal val orders: List, + private val offset: Int? = null, + private val startCursor: Cursor? = null, + private val endCursor: Cursor? = null, ) { fun firstPage(): Pipeline { return this.p } - fun startAt(result: PipelineResult): Pipeline { + fun lastPage(): Pipeline { return this.p } - fun startAfter(result: PipelineResult): Pipeline { - return this.p + fun startAt(result: PipelineResult): PaginatingPipeline { + return this } - fun endAt(result: PipelineResult): Pipeline { - return this.p + fun startAfter(result: PipelineResult): PaginatingPipeline { + return this } - fun endBefore(result: PipelineResult): Pipeline { - return this.p + fun endAt(result: PipelineResult): PaginatingPipeline { + return this + } + + fun endBefore(result: PipelineResult): PaginatingPipeline { + return this + } + + // Internal as this is only potentially used when converting Query to Pipeline. + internal fun offset(offset: Int): PaginatingPipeline { + return this } } /** - * The Pipeline class provides a flexible and expressive framework for building complex data transformation - * and query pipelines for Firestore. + * The Pipeline class provides a flexible and expressive framework for building complex data + * transformation and query pipelines for Firestore. * - * A pipeline takes data sources such as Firestore collections, collection groups, or even in-memory data, and - * applies a series of operations that are chained together, each operation takes the output from the last - * operation (or the data source) and produces an output for the next operation (or as the final output of the pipeline). + * A pipeline takes data sources such as Firestore collections, collection groups, or even in-memory + * data, and applies a series of operations that are chained together, each operation takes the + * output from the last operation (or the data source) and produces an output for the next operation + * (or as the final output of the pipeline). * - * NOTE: the chained operations are not a prescription of exactly how Firestore will execute the pipeline, - * instead Firestore only guarantee the result is the same as if the chained operations are executed in order. + * NOTE: the chained operations are not a prescription of exactly how Firestore will execute the + * pipeline, instead Firestore only guarantee the result is the same as if the chained operations + * are executed in order. * * Usage Examples: * * **1. Projecting Specific Fields and Renaming:** + * * ```java * Pipeline pipeline = Pipeline.fromCollection("users") * // Select 'name' and 'email' fields, create 'userAge' which is renamed from field 'age'. @@ -86,6 +111,7 @@ class PaginatingPipeline internal constructor( * ``` * * **2. Filtering and Sorting:** + * * ```java * Pipeline pipeline = Pipeline.fromCollectionGroup("reviews") * .filter(Field.of("rating").greaterThan(Expr.Constant.of(3))) // High ratings @@ -93,6 +119,7 @@ class PaginatingPipeline internal constructor( * ``` * * **3. Aggregation with Grouping:** + * * ```java * Pipeline pipeline = Pipeline.fromCollection("orders") * .group(Field.of("customerId")) @@ -130,7 +157,7 @@ class Pipeline private constructor(private val stages: List, private val Preconditions.checkArgument( !collectionId.contains("/"), "Invalid collectionId '%s'. Collection IDs must not contain '/'.", - collectionId + collectionId, ) return Pipeline(CollectionGroup(collectionId)) } @@ -166,7 +193,7 @@ class Pipeline private constructor(private val stages: List, private val return Pipeline(stages.plus(Project(projectablesToMap(*projections))), name) } - fun filter(condition: T): Pipeline where T : Expr, T:Function.FilterCondition{ + fun filter(condition: T): Pipeline where T : Expr, T : Function.FilterCondition { return Pipeline(stages.plus(Filter(condition)), name) } @@ -185,26 +212,26 @@ class Pipeline private constructor(private val stages: List, private val fun findNearest( property: Field, vector: DoubleArray, - options: FindNearest.FindNearestOptions + options: FindNearest.FindNearestOptions, ): Pipeline { return this } fun sort( - orders: List, + orders: List, density: Sort.Density = Sort.Density.UNSPECIFIED, - truncation: Sort.Truncation = Sort.Truncation.UNSPECIFIED + truncation: Sort.Truncation = Sort.Truncation.UNSPECIFIED, ): Pipeline { - return this + return Pipeline(stages.plus(Sort(orders, density, truncation)), name) } // Sugar fun sort(vararg orders: Ordering): Pipeline { - return this + return this.sort(orders.toList()) } fun paginate(pageSize: Int, vararg orders: Ordering): PaginatingPipeline { - return PaginatingPipeline(this, pageSize, orders) + return PaginatingPipeline(this, pageSize, orders.toList()) } fun genericOperation(name: String, params: Map? = null): Pipeline { @@ -215,31 +242,37 @@ class Pipeline private constructor(private val stages: List, private val when (db) { is FirestoreImpl -> { val pipelineValue = toProto() - val request = ExecutePipelineRequest.newBuilder() - .setStructuredPipeline( - StructuredPipeline.newBuilder() - .setPipeline(pipelineValue.pipelineValue).build() - ).build() + val request = + ExecutePipelineRequest.newBuilder() + .setDatabase(db.resourcePath.databaseName.toString()) + .setStructuredPipeline( + StructuredPipeline.newBuilder().setPipeline(pipelineValue.pipelineValue).build() + ) + .build() val futureResult = SettableApiFuture.create>() - pipelineInternalStream(db, request, object : PipelineResultObserver() { - val results = mutableListOf() - override fun onCompleted() { - futureResult.set(results) - } - - override fun onNext(result: PipelineResult?) { - results.add(result!!) - } - - override fun onError(t: Throwable?) { - futureResult.setException(t) - } - }) + pipelineInternalStream( + db, + request, + object : PipelineResultObserver() { + val results = mutableListOf() + + override fun onCompleted() { + futureResult.set(results) + } + + override fun onNext(result: PipelineResult?) { + results.add(result!!) + } + + override fun onError(t: Throwable?) { + futureResult.setException(t) + } + }, + ) return futureResult } - else -> { TODO() } @@ -250,28 +283,32 @@ class Pipeline private constructor(private val stages: List, private val when (db) { is FirestoreImpl -> { val pipelineValue = toProto() - val request = ExecutePipelineRequest.newBuilder() - .setDatabase(db.resourcePath.databaseName.toString()) - .setStructuredPipeline( - StructuredPipeline.newBuilder() - .setPipeline(pipelineValue.pipelineValue).build() - ).build() - - pipelineInternalStream(db, request, object : PipelineResultObserver() { - override fun onCompleted() { - observer.onCompleted() - } - - override fun onNext(result: PipelineResult?) { - observer.onNext(result) - } - - override fun onError(t: Throwable?) { - observer.onError(t) - } - }) + val request = + ExecutePipelineRequest.newBuilder() + .setDatabase(db.resourcePath.databaseName.toString()) + .setStructuredPipeline( + StructuredPipeline.newBuilder().setPipeline(pipelineValue.pipelineValue).build() + ) + .build() + + pipelineInternalStream( + db, + request, + object : PipelineResultObserver() { + override fun onCompleted() { + observer.onCompleted() + } + + override fun onNext(result: PipelineResult?) { + observer.onNext(result) + } + + override fun onError(t: Throwable?) { + observer.onError(t) + } + }, + ) } - else -> { TODO() } @@ -281,24 +318,17 @@ class Pipeline private constructor(private val stages: List, private val fun toProto(): Value { return Value.newBuilder() .setPipelineValue( - com.google.firestore.v1.Pipeline.newBuilder() - .addAllStages(stages.map { toStageProto(it) }) + com.google.firestore.v1.Pipeline.newBuilder().addAllStages(stages.map { toStageProto(it) }) ) .build() } } internal fun encodeValue(value: Any?): Value? { - return UserDataConverter.encodeValue( - FieldPath.empty(), - value, - UserDataConverter.ARGUMENT - ) + return UserDataConverter.encodeValue(FieldPath.empty(), value, UserDataConverter.ARGUMENT) } -private abstract class PipelineResultObserver - - : ApiStreamObserver { +private abstract class PipelineResultObserver : ApiStreamObserver { var executionTime: Timestamp? = null private set @@ -311,7 +341,7 @@ private abstract class PipelineResultObserver private fun pipelineInternalStream( rpcContext: FirestoreImpl, request: ExecutePipelineRequest, - resultObserver: PipelineResultObserver + resultObserver: PipelineResultObserver, ) { val observer: ResponseObserver = object : ResponseObserver { @@ -323,8 +353,7 @@ private fun pipelineInternalStream( // this flag makes sure only the first one is actually processed. var hasCompleted: Boolean = false - override fun onStart(streamController: StreamController) { - } + override fun onStart(streamController: StreamController) {} override fun onResponse(response: ExecutePipelineResponse) { if (!firstResponse) { @@ -334,17 +363,11 @@ private fun pipelineInternalStream( if (response.resultsCount > 0) { numDocuments += response.resultsCount if (numDocuments % 100 == 0) { - Tracing.getTracer() - .currentSpan - .addAnnotation("Firestore.Query: Received 100 documents") + Tracing.getTracer().currentSpan.addAnnotation("Firestore.Query: Received 100 documents") } response.resultsList.forEach { doc: Document -> resultObserver.onNext( - PipelineResult.fromDocument( - rpcContext, - response.executionTime, - doc - ) + PipelineResult.fromDocument(rpcContext, response.executionTime, doc) ) } } @@ -370,15 +393,15 @@ private fun pipelineInternalStream( .addAnnotation( "Firestore.Query: Completed", ImmutableMap.of( - "numDocuments", AttributeValue.longAttributeValue(numDocuments.toLong()) - ) + "numDocuments", + AttributeValue.longAttributeValue(numDocuments.toLong()), + ), ) resultObserver.onCompleted(executionTime) } } - Logger.getLogger("Pipeline") - .log(Level.WARNING, "Sending request: $request") + Logger.getLogger("Pipeline").log(Level.WARNING, "Sending request: $request") rpcContext.streamRequest(request, observer, rpcContext.client.executePipelineCallable()) } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt index ab184c2c9..fa191001e 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt @@ -6,13 +6,14 @@ import com.google.firestore.v1.Value import java.util.Date import javax.annotation.Nonnull -data class PipelineResult internal constructor( +data class PipelineResult +internal constructor( private val rpcContext: FirestoreRpcContext<*>?, val reference: DocumentReference?, val protoFields: Map, val readTime: Timestamp, val updateTime: Timestamp?, - val createTime: Timestamp? + val createTime: Timestamp?, ) { val id: String? get() = reference?.id @@ -23,8 +24,8 @@ data class PipelineResult internal constructor( val data: Map? /** - * Returns the fields of the document as a Map or null if the document doesn't exist. Field values - * will be converted to their native Java representation. + * Returns the fields of the document as a Map or null if the document doesn't exist. Field + * values will be converted to their native Java representation. * * @return The fields of the document as a Map or null if the document doesn't exist. */ @@ -46,14 +47,12 @@ data class PipelineResult internal constructor( * * @param valueType The Java class to create * @return The contents of the result in an object of type T or null if the document doesn't - * exist. + * exist. */ fun toObject(@Nonnull valueType: Class): T? { val data = data - return if (data == null) null else CustomClassMapper.convertToCustomClass( - data, valueType, - reference - ) + return if (data == null) null + else CustomClassMapper.convertToCustomClass(data, valueType, reference) } /** @@ -93,10 +92,8 @@ data class PipelineResult internal constructor( fun get(fieldPath: FieldPath, valueType: Class): T? { val data = get(fieldPath) - return if (data == null) null else CustomClassMapper.convertToCustomClass( - data, valueType, - reference - ) + return if (data == null) null + else CustomClassMapper.convertToCustomClass(data, valueType, reference) } fun extractField(fieldPath: FieldPath): Value? { @@ -158,15 +155,17 @@ data class PipelineResult internal constructor( companion object { @JvmStatic internal fun fromDocument( - rpcContext: FirestoreRpcContext<*>?, readTime: com.google.protobuf.Timestamp, document: Document + rpcContext: FirestoreRpcContext<*>?, + readTime: com.google.protobuf.Timestamp, + document: Document, ): PipelineResult { return PipelineResult( rpcContext, document.name?.let { DocumentReference(rpcContext, ResourcePath.create(it)) }, document.fieldsMap, Timestamp.fromProto(readTime), - document.updateTime?.let {Timestamp.fromProto(it)}, - document.createTime?.let {Timestamp.fromProto(it)}, + document.updateTime?.let { Timestamp.fromProto(it) }, + document.createTime?.let { Timestamp.fromProto(it) }, ) } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.kt new file mode 100644 index 000000000..397300bf4 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.kt @@ -0,0 +1,140 @@ +package com.google.cloud.firestore + +import com.google.cloud.firestore.Query.ComparisonFilterInternal +import com.google.cloud.firestore.Query.CompositeFilterInternal +import com.google.cloud.firestore.Query.FilterInternal +import com.google.cloud.firestore.Query.LimitType +import com.google.cloud.firestore.Query.UnaryFilterInternal +import com.google.cloud.firestore.pipeline.AggregatorTarget +import com.google.cloud.firestore.pipeline.Constant +import com.google.cloud.firestore.pipeline.Field +import com.google.cloud.firestore.pipeline.Function +import com.google.cloud.firestore.pipeline.Function.Companion.countAll +import com.google.cloud.firestore.pipeline.Function.Companion.not +import com.google.firestore.v1.Cursor +import com.google.firestore.v1.StructuredQuery + +internal fun toPipelineFilterCondition(f: FilterInternal): Function.FilterCondition { + return when (f) { + is ComparisonFilterInternal -> { + when (f.operator) { + StructuredQuery.FieldFilter.Operator.OPERATOR_UNSPECIFIED -> { + TODO() + } + StructuredQuery.FieldFilter.Operator.LESS_THAN -> { + Field.of(f.fieldReference.fieldPath).lessThan(f.value) + } + StructuredQuery.FieldFilter.Operator.LESS_THAN_OR_EQUAL -> { + Field.of(f.fieldReference.fieldPath).lessThanOrEqual(f.value) + } + StructuredQuery.FieldFilter.Operator.GREATER_THAN -> { + Field.of(f.fieldReference.fieldPath).greaterThan(f.value) + } + StructuredQuery.FieldFilter.Operator.GREATER_THAN_OR_EQUAL -> { + Field.of(f.fieldReference.fieldPath).greaterThanOrEqual(f.value) + } + StructuredQuery.FieldFilter.Operator.EQUAL -> { + Field.of(f.fieldReference.fieldPath).equal(f.value) + } + StructuredQuery.FieldFilter.Operator.NOT_EQUAL -> { + not(Field.of(f.fieldReference.fieldPath).equal(f.value)) + } + StructuredQuery.FieldFilter.Operator.ARRAY_CONTAINS -> { + Field.of(f.fieldReference.fieldPath).arrayContains(f.value) + } + StructuredQuery.FieldFilter.Operator.IN -> { + Function.In( + Field.of(f.fieldReference.fieldPath), + f.value?.arrayValue?.valuesList?.map { Constant.of(it) } ?: emptyList(), + ) + } + StructuredQuery.FieldFilter.Operator.ARRAY_CONTAINS_ANY -> { + Function.ArrayContainsAny( + Field.of(f.fieldReference.fieldPath), + f.value?.arrayValue?.valuesList?.map { Constant.of(it) } ?: emptyList(), + ) + } + StructuredQuery.FieldFilter.Operator.NOT_IN -> { + not( + Function.In( + Field.of(f.fieldReference.fieldPath), + f.value?.arrayValue?.valuesList?.map { Constant.of(it) } ?: emptyList(), + ) + ) + } + StructuredQuery.FieldFilter.Operator.UNRECOGNIZED -> { + TODO() + } + } + } + is CompositeFilterInternal -> { + when (f.operator) { + StructuredQuery.CompositeFilter.Operator.OPERATOR_UNSPECIFIED -> { + TODO() + } + StructuredQuery.CompositeFilter.Operator.AND -> { + Function.And(f.filters.map { toPipelineFilterCondition(it) }) + } + StructuredQuery.CompositeFilter.Operator.OR -> { + Function.Or(f.filters.map { toPipelineFilterCondition(it) }) + } + StructuredQuery.CompositeFilter.Operator.UNRECOGNIZED -> { + TODO() + } + } + } + is UnaryFilterInternal -> { + when (f.operator) { + StructuredQuery.UnaryFilter.Operator.IS_NAN -> Field.of(f.fieldReference.fieldPath).isNaN() + StructuredQuery.UnaryFilter.Operator.IS_NULL -> + Field.of(f.fieldReference.fieldPath).isNull() + StructuredQuery.UnaryFilter.Operator.IS_NOT_NAN -> + not(Field.of(f.fieldReference.fieldPath).isNaN()) + StructuredQuery.UnaryFilter.Operator.IS_NOT_NULL -> + not(Field.of(f.fieldReference.fieldPath).isNull()) + StructuredQuery.UnaryFilter.Operator.OPERATOR_UNSPECIFIED -> TODO() + StructuredQuery.UnaryFilter.Operator.UNRECOGNIZED -> TODO() + } + } + else -> { + TODO() + } + } +} + +internal fun toPaginatedPipeline( + pipeline: Pipeline, + start: Cursor?, + end: Cursor?, + limit: Int?, + limitType: LimitType?, + offset: Int?, +): Pipeline { + var paginate: PaginatingPipeline = pipeline.paginate(limit ?: Int.MAX_VALUE) + + start?.let { paginate = setStartCursor(paginate, it) } + end?.let { paginate = setEndCursor(paginate, it) } + offset?.let { paginate = paginate.offset(it) } + + return limitType?.let { + when (it) { + LimitType.First -> paginate.firstPage() + LimitType.Last -> paginate.lastPage() + } + } ?: paginate.firstPage() +} + +internal fun toPipelineAggregatorTarget(f: AggregateField): AggregatorTarget { + return when (f.operator) { + "sum" -> { + Field.of(f.getFieldPath()).sum().toField(f.alias) + } + "count" -> { + countAll().toField(f.alias) + } + "avg" -> { + Field.of(f.getFieldPath()).avg().toField(f.alias) + } + else -> TODO() + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index 1e8e0ee42..0eedf2f69 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -16,6 +16,8 @@ package com.google.cloud.firestore; +import static com.google.cloud.firestore.PipelineUtilsKt.toPaginatedPipeline; +import static com.google.cloud.firestore.PipelineUtilsKt.toPipelineFilterCondition; import static com.google.common.collect.Lists.reverse; import static com.google.firestore.v1.StructuredQuery.FieldFilter.Operator.ARRAY_CONTAINS; import static com.google.firestore.v1.StructuredQuery.FieldFilter.Operator.ARRAY_CONTAINS_ANY; @@ -38,6 +40,11 @@ import com.google.auto.value.AutoValue; 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.Sort.Density; +import com.google.cloud.firestore.pipeline.Sort.Ordering; +import com.google.cloud.firestore.pipeline.Sort.Truncation; import com.google.cloud.firestore.v1.FirestoreSettings; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -54,6 +61,7 @@ import com.google.firestore.v1.StructuredQuery.FieldReference; import com.google.firestore.v1.StructuredQuery.Filter; import com.google.firestore.v1.StructuredQuery.Order; +import com.google.firestore.v1.StructuredQuery.UnaryFilter; import com.google.firestore.v1.Value; import com.google.protobuf.ByteString; import com.google.protobuf.Int32Value; @@ -74,6 +82,7 @@ import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Logger; +import java.util.stream.Collectors; import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.threeten.bp.Duration; @@ -172,6 +181,11 @@ public List getFilters() { return filters; } + @Nonnull + CompositeFilter.Operator getOperator() { + return this.operator; + } + @Nullable @Override public FieldReference getFirstInequalityField() { @@ -237,7 +251,7 @@ public List getFlattenedFilters() { } } - private static class UnaryFilterInternal extends FieldFilterInternal { + static class UnaryFilterInternal extends FieldFilterInternal { private final StructuredQuery.UnaryFilter.Operator operator; @@ -264,6 +278,11 @@ Filter toProto() { return result.build(); } + @Nonnull + UnaryFilter.Operator getOperator() { + return this.operator; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -1955,10 +1974,62 @@ public AggregateQuery aggregate( return new AggregateQuery(this, aggregateFieldList); } + @Nonnull public Pipeline toPipeline() { - Pipeline ppl = Pipeline.fromCollection(this.options.getParentPath().append(this.options.getCollectionId()).getPath()); - for(FilterInternal f: this.options.getFilters()){ + // From + Pipeline ppl = + Pipeline.fromCollection( + this.options.getParentPath().append(this.options.getCollectionId()).getPath()); + + // Filters + for (FilterInternal f : this.options.getFilters()) { + ppl = ppl.filter(toPipelineFilterCondition(f)); + } + + // Projections + if (this.options.getFieldProjections() != null + && !this.options.getFieldProjections().isEmpty()) { + ppl = + ppl.project( + this.options.getFieldProjections().stream() + .map(fieldReference -> Field.of(fieldReference.getFieldPath())) + .toArray(Projectable[]::new)); + } + + // Orders + if (this.options.getFieldOrders() != null && !this.options.getFieldOrders().isEmpty()) { + List orders = + this.options.getFieldOrders().stream() + .map( + fieldOrder -> + Ordering.of( + Field.of(fieldOrder.fieldReference.getFieldPath()), + fieldOrder.direction == Direction.ASCENDING + ? Ordering.Direction.ASCENDING + : Ordering.Direction.DESCENDING)) + .collect(Collectors.toList()); + ppl = ppl.sort(orders, Density.REQUIRED, Truncation.UNSPECIFIED); + } + + // Cursors, Limit and Offset + if (this.options.getStartCursor() != null || this.options.getEndCursor() != null) { + ppl = + toPaginatedPipeline( + ppl, + options.getStartCursor(), + options.getEndCursor(), + options.getLimit(), + options.getLimitType(), + options.getOffset()); + } else { // Limit & Offset without cursors + if (this.options.getOffset() != null) { + ppl = ppl.offset(this.options.getOffset()); + } + if (this.options.getLimit() != null) { + ppl = ppl.limit(this.options.getLimit()); + } } + return ppl; } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index 3abecfa5f..1c3892d5a 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -1,5 +1,9 @@ package com.google.cloud.firestore.pipeline +import com.google.cloud.Timestamp +import com.google.cloud.firestore.Blob +import com.google.cloud.firestore.DocumentReference +import com.google.cloud.firestore.GeoPoint import com.google.cloud.firestore.Pipeline import com.google.cloud.firestore.encodeValue import com.google.cloud.firestore.pipeline.Function.ArrayContains @@ -19,23 +23,23 @@ import com.google.cloud.firestore.pipeline.Function.LessThan import com.google.cloud.firestore.pipeline.Function.LessThanOrEqual import com.google.cloud.firestore.pipeline.Function.NotEqual import com.google.cloud.firestore.pipeline.Function.Sum -import com.google.firestore.v1.Value -import com.google.cloud.Timestamp -import com.google.cloud.firestore.Blob -import com.google.cloud.firestore.DocumentReference -import com.google.cloud.firestore.GeoPoint import com.google.cloud.firestore.pipeline.Sort.Ordering import com.google.cloud.firestore.pipeline.Sort.Ordering.Direction import com.google.firestore.v1.ArrayValue +import com.google.firestore.v1.Value import java.util.Date -internal fun exprToValue(expr: Expr): Value{ - return when(expr) { +internal fun exprToValue(expr: Expr): Value { + return when (expr) { is Constant -> expr.toProto() is Field -> expr.toProto() is Function -> expr.toProto() is ListOfExprs -> { - Value.newBuilder().setArrayValue(ArrayValue.newBuilder().addAllValues(expr.conditions.map { exprToValue(it) })).build() + Value.newBuilder() + .setArrayValue( + ArrayValue.newBuilder().addAllValues(expr.conditions.map { exprToValue(it) }) + ) + .build() } else -> { TODO() @@ -48,45 +52,87 @@ sealed interface Projectable interface Expr { // Infix functions returning Function subclasses infix fun equal(other: Expr) = Equal(this, other) + infix fun equal(other: Any) = Equal(this, Constant.of(other)) + infix fun notEqual(other: Expr) = NotEqual(this, other) + infix fun notEqual(other: Any) = NotEqual(this, Constant.of(other)) + infix fun greaterThan(other: Expr) = GreaterThan(this, other) + infix fun greaterThan(other: Any) = GreaterThan(this, Constant.of(other)) + infix fun greaterThanOrEqual(other: Expr) = GreaterThanOrEqual(this, other) + infix fun greaterThanOrEqual(other: Any) = GreaterThanOrEqual(this, Constant.of(other)) + infix fun lessThan(other: Expr) = LessThan(this, other) + infix fun lessThan(other: Any) = LessThan(this, Constant.of(other)) + infix fun lessThanOrEqual(other: Expr) = LessThanOrEqual(this, other) + infix fun lessThanOrEqual(other: Any) = LessThanOrEqual(this, Constant.of(other)) - fun inAny(vararg other: Any) = In(this, other.toList().map { when(it) { - is Expr -> it - else -> Constant.of(it) }}) - fun notInAny(vararg other: Any) = Function.Not(In(this, other.toList().map { when(it) { - is Expr -> it - else -> Constant.of(it) }})) + + fun inAny(vararg other: Any) = + In( + this, + other.toList().map { + when (it) { + is Expr -> it + else -> Constant.of(it) + } + }, + ) + + fun notInAny(vararg other: Any) = + Function.Not( + In( + this, + other.toList().map { + when (it) { + is Expr -> it + else -> Constant.of(it) + } + }, + ) + ) infix fun arrayContains(element: Expr) = ArrayContains(this, element) + infix fun arrayContains(element: Any) = ArrayContains(this, Constant.of(element)) + fun arrayContainsAny(vararg elements: Expr) = ArrayContainsAny(this, elements.toList()) - fun arrayContainsAny(vararg elements: Any) = ArrayContainsAny(this, elements.toList().map { Constant.of(it) }) + + fun arrayContainsAny(vararg elements: Any) = + ArrayContainsAny(this, elements.toList().map { Constant.of(it) }) + fun isNaN() = IsNaN(this) + fun isNull() = IsNull(this) + fun sum() = Sum(this, false) + fun avg() = Avg(this, false) + fun count() = Count(this, false) + fun min() = Count(this, false) + fun max() = Count(this, false) infix fun cosineDistance(other: Expr) = CosineDistance(this, other) - infix fun cosineDistance(other: DoubleArray) = - CosineDistance(this, Constant.ofVector(other)) + + infix fun cosineDistance(other: DoubleArray) = CosineDistance(this, Constant.ofVector(other)) infix fun euclideanDistance(other: Expr) = EuclideanDistance(this, other) + infix fun euclideanDistance(other: DoubleArray) = EuclideanDistance(this, Constant.ofVector(other)) infix fun dotProductDistance(other: Expr) = DotProductDistance(this, other) + infix fun dotProductDistance(other: DoubleArray) = DotProductDistance(this, Constant.ofVector(other)) @@ -144,6 +190,11 @@ data class Constant internal constructor(val value: Any?) : Expr { return Constant(value) } + @JvmStatic + fun of(value: Value?): Constant { + return Constant(value) + } + @JvmStatic internal fun of(value: Any?): Constant { if (value == null) { @@ -159,22 +210,23 @@ data class Constant internal constructor(val value: Any?) : Expr { is GeoPoint -> of(value) is Blob -> of(value) is DocumentReference -> of(value) + is Value -> of(value) else -> TODO("Unknown type: $value") } } @JvmStatic - fun ofArray(value: Iterable): Constant { + fun ofArray(value: Iterable): Constant { return Constant(value) } @JvmStatic - fun ofArray(value: Array): Constant { + fun ofArray(value: Array): Constant { return Constant(value) } @JvmStatic - fun ofMap(value: Map): Constant { + fun ofMap(value: Map): Constant { return Constant(value) } @@ -190,8 +242,8 @@ data class Constant internal constructor(val value: Any?) : Expr { } } -data class Field internal constructor(val field: String, var pipeline: Pipeline? = null) : Expr, - Projectable{ +data class Field internal constructor(val field: String, var pipeline: Pipeline? = null) : + Expr, Projectable { companion object { const val DOCUMENT_ID: String = "__path__" @@ -199,6 +251,11 @@ data class Field internal constructor(val field: String, var pipeline: Pipeline? fun of(path: String): Field { return Field(path) } + + @JvmStatic + fun ofAll(): Field { + return Field("") + } } fun toProto(): Value { @@ -212,19 +269,25 @@ data class Fields internal constructor(val fs: List? = null) : Expr, Proj fun of(f1: String, vararg f: String): Fields { return Fields(listOf(Field.of(f1)) + f.map(Field.Companion::of)) } + + @JvmStatic + fun ofAll(): Fields { + return Fields(listOf(Field.of(""))) + } } } -data class AggregatorTarget internal constructor( - val accumulator: Function.Accumulator, val fieldName: String, - override var distinct: Boolean -) : Projectable, - Function.Accumulator +data class AggregatorTarget +internal constructor( + val accumulator: Function.Accumulator, + val fieldName: String, + override var distinct: Boolean, +) : Projectable, Function.Accumulator -sealed class Function(val name: String, val params: List): Expr { - interface FilterCondition +sealed class Function(val name: String, val params: List) : Expr { + interface FilterCondition : Expr - interface Accumulator: Expr { + interface Accumulator : Expr { var distinct: Boolean fun distinct(on: Boolean): Accumulator { @@ -236,9 +299,13 @@ sealed class Function(val name: String, val params: List): Expr { } fun toProto(): Value { - return Value.newBuilder().setFunctionValue(com.google.firestore.v1.Function.newBuilder() - .setName(name) - .addAllArgs(params.map { exprToValue(it) })).build() + return Value.newBuilder() + .setFunctionValue( + com.google.firestore.v1.Function.newBuilder() + .setName(name) + .addAllArgs(params.map { exprToValue(it) }) + ) + .build() } data class Equal internal constructor(val left: Expr, val right: Expr) : @@ -260,28 +327,25 @@ sealed class Function(val name: String, val params: List): Expr { Function("lte", listOf(left, right)), FilterCondition data class In(val left: Expr, val others: List) : - Function("in", listOf(left, ListOfExprs(others))), - FilterCondition // For 'in' + Function("in", listOf(left, ListOfExprs(others))), FilterCondition // For 'in' - data class And(val conditions: List) : - Function("and", conditions), FilterCondition where T : FilterCondition, T:Expr + data class And(val conditions: List) : Function("and", conditions), FilterCondition where + T : FilterCondition - data class Or(val conditions: List) : - Function("or", conditions), FilterCondition where T : FilterCondition, T:Expr + data class Or(val conditions: List) : Function("or", conditions), FilterCondition where + T : FilterCondition - data class Not(val condition: Expr) : Function("not", listOf(condition)), - FilterCondition + data class Not(val condition: Expr) : Function("not", listOf(condition)), FilterCondition data class ArrayContains(val array: Expr, val element: Expr) : Function("array_contains", listOf(array, element)), FilterCondition data class ArrayContainsAny(val array: Expr, val elements: List) : - Function("array_contains_any", listOf(array, ListOfExprs(elements))), - FilterCondition + Function("array_contains_any", listOf(array, ListOfExprs(elements))), FilterCondition data class IsNaN(val value: Expr) : Function("is_nan", listOf(value)), FilterCondition - data class IsNull(val value: Expr) : Function("is_null", listOf(value)), - FilterCondition + + data class IsNull(val value: Expr) : Function("is_null", listOf(value)), FilterCondition data class Sum(val value: Expr, override var distinct: Boolean) : Function("sum", listOf(value)), Accumulator @@ -289,10 +353,12 @@ sealed class Function(val name: String, val params: List): Expr { data class Avg(val value: Expr, override var distinct: Boolean) : Function("avg", listOf(value)), Accumulator - data class Count(val value: Expr, override var distinct: Boolean) : - Function("count", listOf(value)), Accumulator + data class Count(val value: Expr?, override var distinct: Boolean) : + Function("count", value?.let { listOf(it) } ?: emptyList()), Accumulator + data class Min(val value: Expr, override var distinct: Boolean) : Function("min", listOf(value)), Accumulator + data class Max(val value: Expr, override var distinct: Boolean) : Function("max", listOf(value)), Accumulator @@ -307,78 +373,74 @@ sealed class Function(val name: String, val params: List): Expr { data class Generic(val n: String, val ps: List) : Function(n, ps) - companion object { - @JvmStatic - fun equal(left: Expr, right: Expr) = Equal(left, right) + @JvmStatic fun equal(left: Expr, right: Expr) = Equal(left, right) - @JvmStatic - fun equal(left: Expr, right: Any) = Equal(left, Constant.of(right)) + @JvmStatic fun equal(left: Expr, right: Any) = Equal(left, Constant.of(right)) - @JvmStatic - fun notEqual(left: Expr, right: Expr) = NotEqual(left, right) + @JvmStatic fun notEqual(left: Expr, right: Expr) = NotEqual(left, right) - @JvmStatic - fun notEqual(left: Expr, right: Any) = NotEqual(left, Constant.of(right)) + @JvmStatic fun notEqual(left: Expr, right: Any) = NotEqual(left, Constant.of(right)) - @JvmStatic - fun greaterThan(left: Expr, right: Expr) = GreaterThan(left, right) + @JvmStatic fun greaterThan(left: Expr, right: Expr) = GreaterThan(left, right) - @JvmStatic - fun greaterThan(left: Expr, right: Any) = - GreaterThan(left, Constant.of(right)) + @JvmStatic fun greaterThan(left: Expr, right: Any) = GreaterThan(left, Constant.of(right)) - @JvmStatic - fun greaterThanOrEqual(left: Expr, right: Expr) = GreaterThanOrEqual(left, right) + @JvmStatic fun greaterThanOrEqual(left: Expr, right: Expr) = GreaterThanOrEqual(left, right) @JvmStatic fun greaterThanOrEqual(left: Expr, right: Any) = GreaterThanOrEqual(left, Constant.of(right)) - @JvmStatic - fun lessThan(left: Expr, right: Expr) = LessThan(left, right) + @JvmStatic fun lessThan(left: Expr, right: Expr) = LessThan(left, right) - @JvmStatic - fun lessThan(left: Expr, right: Any) = LessThan(left, Constant.of(right)) + @JvmStatic fun lessThan(left: Expr, right: Any) = LessThan(left, Constant.of(right)) - @JvmStatic - fun lessThanOrEqual(left: Expr, right: Expr) = LessThanOrEqual(left, right) + @JvmStatic fun lessThanOrEqual(left: Expr, right: Expr) = LessThanOrEqual(left, right) @JvmStatic fun lessThanOrEqual(left: Expr, right: Any) = LessThanOrEqual(left, Constant.of(right)) @JvmStatic - fun inAny(left: Expr, values: List) = In(left, values.map { - when (it) { - is Expr -> it - else -> Constant.of(it) - } - }) + fun inAny(left: Expr, values: List) = + In( + left, + values.map { + when (it) { + is Expr -> it + else -> Constant.of(it) + } + }, + ) @JvmStatic - fun notInAny(left: Expr, values: List) = Not(In(left, values.map { - when (it) { - is Expr -> it - else ->Constant.of(it) - }})) + fun notInAny(left: Expr, values: List) = + Not( + In( + left, + values.map { + when (it) { + is Expr -> it + else -> Constant.of(it) + } + }, + ) + ) @JvmStatic - fun and(left: T, right: T) where T : FilterCondition, T:Expr = - And(listOf(left, right)) + fun and(left: T, right: T) where T : FilterCondition, T : Expr = And(listOf(left, right)) @JvmStatic - fun and(left: T, vararg other: T) where T : FilterCondition, T:Expr= + fun and(left: T, vararg other: T) where T : FilterCondition, T : Expr = And(listOf(left) + other.toList()) @JvmStatic - fun or(left: T, right: T) where T : FilterCondition, T:Expr = - Or(listOf(left, right)) + fun or(left: T, right: T) where T : FilterCondition, T : Expr = Or(listOf(left, right)) @JvmStatic - fun or(left: T, vararg other: T) where T : FilterCondition, T:Expr= + fun or(left: T, vararg other: T) where T : FilterCondition, T : Expr = Or(listOf(left) + other.toList()) - @JvmStatic - fun arrayContains(expr: Expr, element: Expr) = ArrayContains(expr, element) + @JvmStatic fun arrayContains(expr: Expr, element: Expr) = ArrayContains(expr, element) @JvmStatic fun arrayContains(expr: Expr, element: Any) = ArrayContains(expr, Constant.of(element)) @@ -391,53 +453,42 @@ sealed class Function(val name: String, val params: List): Expr { fun arrayContainsAny(expr: Expr, vararg elements: Any) = ArrayContainsAny(expr, elements.toList().map { Constant.of(it) }) - @JvmStatic - fun isNaN(expr: Expr) = IsNaN(expr) + @JvmStatic fun isNaN(expr: Expr) = IsNaN(expr) - @JvmStatic - fun isNull(expr: Expr) = IsNull(expr) + @JvmStatic fun isNull(expr: Expr) = IsNull(expr) - @JvmStatic - fun not(expr: Expr) = Not(expr) + @JvmStatic fun not(expr: Expr) = Not(expr) - @JvmStatic - fun sum(expr: Expr) = Sum(expr, false) + @JvmStatic fun sum(expr: Expr) = Sum(expr, false) - @JvmStatic - fun avg(expr: Expr) = Avg(expr, false) + @JvmStatic fun avg(expr: Expr) = Avg(expr, false) - @JvmStatic - fun min(expr: Expr) = Sum(expr, false) + @JvmStatic fun min(expr: Expr) = Sum(expr, false) - @JvmStatic - fun max(expr: Expr) = Avg(expr, false) + @JvmStatic fun max(expr: Expr) = Avg(expr, false) - @JvmStatic - fun count(expr: Expr) = Count(expr, false) + @JvmStatic fun countAll(expr: Expr) = Count(expr, false) - @JvmStatic - fun cosineDistance(expr: Expr, other: Expr) = CosineDistance(expr, other) + @JvmStatic fun countAll() = Count(null, false) + + @JvmStatic fun cosineDistance(expr: Expr, other: Expr) = CosineDistance(expr, other) @JvmStatic fun cosineDistance(expr: Expr, other: DoubleArray) = CosineDistance(expr, Constant.ofVector(other)) - @JvmStatic - fun dotProductDistance(expr: Expr, other: Expr) = CosineDistance(expr, other) + @JvmStatic fun dotProductDistance(expr: Expr, other: Expr) = CosineDistance(expr, other) @JvmStatic fun dotProductDistance(expr: Expr, other: DoubleArray) = CosineDistance(expr, Constant.ofVector(other)) - @JvmStatic - fun euclideanDistance(expr: Expr, other: Expr) = EuclideanDistance(expr, other) + @JvmStatic fun euclideanDistance(expr: Expr, other: Expr) = EuclideanDistance(expr, other) @JvmStatic fun euclideanDistance(expr: Expr, other: DoubleArray) = EuclideanDistance(expr, Constant.ofVector(other)) - @JvmStatic - fun function(name: String, params: List) = Generic(name, params) + @JvmStatic fun function(name: String, params: List) = Generic(name, params) } } - diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt index 0ffc10cbe..df3a76445 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt @@ -16,16 +16,17 @@ internal data class CollectionGroup(val collectionId: String) : Stage { val name = "collection_group" } -internal class Database: Stage { +internal class Database : Stage { val name = "database" } -internal data class Documents(val documents: List): Stage { +internal data class Documents(val documents: List) : Stage { val name = "documents" + companion object { @JvmStatic fun of(vararg documents: DocumentReference): Documents { - return Documents(documents.map { it.path }) + return Documents(documents.map { "/" + it.path }) } } } @@ -38,7 +39,9 @@ internal data class AddFields(val fields: Map) : Stage { val name = "add_fields" } -internal data class Filter (val condition: T) : Stage where T:Function.FilterCondition, T:Expr { +internal data class Filter(val condition: T) : Stage where +T : Function.FilterCondition, +T : Expr { val name = "filter" } @@ -50,32 +53,37 @@ internal class Limit(val limit: Int) : Stage { val name = "limit" } -class Aggregate internal constructor( +class Aggregate +internal constructor( val groups: Map, - val accumulators: Map + val accumulators: Map, ) : Stage { val name = "aggregate" - internal constructor(vararg aggregators: AggregatorTarget) : - this(emptyMap(), aggregators.associate { it.fieldName to it.accumulator }) + internal constructor( + vararg aggregators: AggregatorTarget + ) : this(emptyMap(), aggregators.associate { it.fieldName to it.accumulator }) } -class FindNearest internal constructor( +class FindNearest +internal constructor( val property: Field, val vector: DoubleArray, val distanceMeasure: DistanceMeasure, - val options: FindNearestOptions + val options: FindNearestOptions, ) : Stage { val name = "find_nearest" sealed interface DistanceMeasure { data object Euclidean : DistanceMeasure + data object Cosine : DistanceMeasure + data object DotProduct : DistanceMeasure class GenericDistanceMeasure(val name: String) : DistanceMeasure - fun toProtoString(): String{ + fun toProtoString(): String { return when (this) { is Euclidean -> "euclidean" is Cosine -> "cosine" @@ -85,61 +93,59 @@ class FindNearest internal constructor( } companion object { - @JvmStatic - fun euclidean() = Euclidean + @JvmStatic fun euclidean() = Euclidean - @JvmStatic - fun cosine() = Cosine + @JvmStatic fun cosine() = Cosine - @JvmStatic - fun dotProduct() = DotProduct + @JvmStatic fun dotProduct() = DotProduct - @JvmStatic - fun generic(name: String) = GenericDistanceMeasure(name) + @JvmStatic fun generic(name: String) = GenericDistanceMeasure(name) } } - data class FindNearestOptions( - val limit: Long?, - val output: Field? = null - ) + data class FindNearestOptions(val limit: Long?, val output: Field? = null) } -class Sort internal constructor( +class Sort +internal constructor( val orders: List, val density: Density = Density.UNSPECIFIED, - val truncation: Truncation = Truncation.UNSPECIFIED + val truncation: Truncation = Truncation.UNSPECIFIED, ) : Stage { val name = "sort" enum class Density { UNSPECIFIED, REQUIRED; - override fun toString(): String - = name.lowercase(Locale.getDefault()) + + override fun toString(): String = name.lowercase(Locale.getDefault()) } enum class Truncation { UNSPECIFIED, DISABLED; - override fun toString(): String - = name.lowercase(Locale.getDefault()) + + override fun toString(): String = name.lowercase(Locale.getDefault()) } - class Ordering internal constructor(private val expr: Expr, private val dir: Direction = Direction.ASCENDING) { + class Ordering + internal constructor(private val expr: Expr, private val dir: Direction = Direction.ASCENDING) { enum class Direction { ASCENDING, DESCENDING; - override fun toString(): String - = name.lowercase(Locale.getDefault()) + override fun toString(): String = name.lowercase(Locale.getDefault()) } internal fun toProto(): Value { - return Value.newBuilder().setMapValue(MapValue.newBuilder() - .putFields("direction", encodeValue(dir.toString())) - .putFields("expression", encodeValue(expr)) - .build()).build() + return Value.newBuilder() + .setMapValue( + MapValue.newBuilder() + .putFields("direction", encodeValue(dir.toString())) + .putFields("expression", encodeValue(expr)) + .build() + ) + .build() } companion object { @@ -168,129 +174,80 @@ class Sort internal constructor( // internal class Pagination(): Stage, GenericStage() -internal open class GenericStage(val name: String, val params: List) : Stage { -} +internal open class GenericStage(val name: String, val params: List) : Stage {} internal fun toStageProto(stage: Stage): com.google.firestore.v1.Pipeline.Stage { return when (stage) { - is Collection -> com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addArgs( - Value.newBuilder().setReferenceValue(stage.relativePath).build() - ) - .build() - - is CollectionGroup -> com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addArgs( - Value.newBuilder().setReferenceValue("").build() - ) - .addArgs( - encodeValue( - stage.collectionId, - ) - ) - .build() - - is Database -> com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .build() - - is Documents -> com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addAllArgs(stage.documents.map { - Value.newBuilder().setReferenceValue(it).build() - }) - .build() - - is Project -> com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addArgs( - encodeValue( - stage.projections, - ) - ) - .build() - - is AddFields -> com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addArgs( - encodeValue( - stage.fields, - ) - ) - .build() - - is Filter<*> -> com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addArgs( - encodeValue( - stage.condition, - ) - ) - .build() - - is Sort -> com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addAllArgs( - stage.orders.map { it.toProto() } - ) - .putOptions("density", encodeValue(stage.density)) - .putOptions("truncation", encodeValue(stage.truncation)) - .build() - - is Offset -> com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addArgs( - encodeValue( - stage.offset - ) - ) - .build() - - is Limit -> com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addArgs( - encodeValue( - stage.limit - ) - ) - .build() - - is Aggregate -> com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addArgs(encodeValue(stage.groups)) - .addArgs(encodeValue(stage.accumulators)) - .build() - - is FindNearest -> com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addArgs( - encodeValue( - stage.property - ) - ) - .addArgs( - encodeValue( - stage.vector - ) - ) - .addArgs( - encodeValue( - stage.distanceMeasure.toProtoString() - ) - ) - .putOptions("limit", encodeValue(stage.options.limit)) - .putOptions("distance_field", encodeValue(stage.options.output)) - .build() - - is GenericStage -> com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addAllArgs( - stage.params.map { encodeValue(it) } - ) - .build() - + is Collection -> + com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addArgs(Value.newBuilder().setReferenceValue("").build()) + .addArgs(Value.newBuilder().setStringValue(stage.relativePath).build()) + .build() + is CollectionGroup -> + com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addArgs(Value.newBuilder().setReferenceValue("").build()) + .addArgs(encodeValue(stage.collectionId)) + .build() + is Database -> com.google.firestore.v1.Pipeline.Stage.newBuilder().setName(stage.name).build() + is Documents -> + com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addAllArgs(stage.documents.map { Value.newBuilder().setReferenceValue(it).build() }) + .build() + is Project -> + com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addArgs(encodeValue(stage.projections)) + .build() + is AddFields -> + com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addArgs(encodeValue(stage.fields)) + .build() + is Filter<*> -> + com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addArgs(encodeValue(stage.condition)) + .build() + is Sort -> + com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addAllArgs(stage.orders.map { it.toProto() }) + .putOptions("density", encodeValue(stage.density.toString())) + .putOptions("truncation", encodeValue(stage.truncation.toString())) + .build() + is Offset -> + com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addArgs(encodeValue(stage.offset)) + .build() + is Limit -> + com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addArgs(encodeValue(stage.limit)) + .build() + is Aggregate -> + com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addArgs(encodeValue(stage.groups)) + .addArgs(encodeValue(stage.accumulators)) + .build() + is FindNearest -> + com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addArgs(encodeValue(stage.property)) + .addArgs(encodeValue(stage.vector)) + .addArgs(encodeValue(stage.distanceMeasure.toProtoString())) + .putOptions("limit", encodeValue(stage.options.limit)) + .putOptions("distance_field", encodeValue(stage.options.output)) + .build() + is GenericStage -> + com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(stage.name) + .addAllArgs(stage.params.map { encodeValue(it) }) + .build() else -> { TODO() } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 3e1b6670b..2494c5dd3 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -16,6 +16,7 @@ package com.google.cloud.firestore.it; +import static com.google.cloud.firestore.it.ITQueryTest.map; import static com.google.cloud.firestore.pipeline.Function.avg; import static com.google.cloud.firestore.pipeline.Function.cosineDistance; import static com.google.cloud.firestore.pipeline.Function.equal; @@ -25,9 +26,8 @@ import static com.google.cloud.firestore.pipeline.Sort.Ordering.ascending; import static com.google.cloud.firestore.pipeline.Sort.Ordering.descending; -import com.google.api.core.ApiFuture; -import com.google.cloud.firestore.Firestore; -import com.google.cloud.firestore.FirestoreOptions; +import com.google.cloud.firestore.CollectionReference; +import com.google.cloud.firestore.LocalFirestoreHelper; import com.google.cloud.firestore.PaginatingPipeline; import com.google.cloud.firestore.Pipeline; import com.google.cloud.firestore.PipelineResult; @@ -36,24 +36,53 @@ import com.google.cloud.firestore.pipeline.Fields; import com.google.cloud.firestore.pipeline.Sort; import com.google.cloud.firestore.pipeline.Sort.Ordering.Direction; -import java.util.Iterator; import java.util.List; -import org.junit.Before; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class ITPipelineTest extends ITBaseTest { + public CollectionReference testCollectionWithDocs(Map> docs) + throws ExecutionException, InterruptedException, TimeoutException { + CollectionReference collection = firestore.collection(LocalFirestoreHelper.autoId()); + for (Map.Entry> doc : docs.entrySet()) { + collection.document(doc.getKey()).set(doc.getValue()).get(5, TimeUnit.SECONDS); + } + return collection; + } + + @Test + public void fromSources() throws Exception { + Map> testDocs = + map( + "doc1", map("a", 1, "b", 0), + "doc2", map("a", 2, "b", 1), + "doc3", map("a", 3, "b", 2), + "doc4", map("a", 1, "b", 3), + "doc5", map("a", 1, "b", 1)); + + CollectionReference collection = testCollectionWithDocs(testDocs); + + Pipeline p = Pipeline.fromCollectionGroup(collection.getId()); + List results = p.execute(firestore).get(); + System.out.println(results.size()); + } @Test public void projections() throws Exception { - Pipeline p = Pipeline.fromCollection("coll1").project(Field.of("foo")); + Pipeline p = Pipeline.fromCollectionGroup("coll1").project(Field.of("foo")); List results = p.execute(firestore).get(); + System.out.println(results.size()); // More compact - p = Pipeline.fromCollection("coll1").project(Fields.of("foo", "bar", "baz")); + p = Pipeline.fromCollectionGroup("coll1").project(Fields.of("foo", "bar", "baz")); results = p.execute(firestore).get(); + System.out.println(results.size()); } @Test @@ -65,65 +94,66 @@ public void filters() throws Exception { or( Field.of("bar").lessThan(Constant.of(100)), Constant.of("value").equal(Field.of("key")))) - .filter(not(Constant.of(128).inAny(Field.of("f1"), Field.of("f2")))); - ApiFuture> results = p.execute(firestore); + .filter(not(Constant.of(128).inAny("f1", "f2"))); + List results = p.execute(firestore).get(); p = Pipeline.fromCollectionGroup("coll1") .filter(equal(Field.of("foo"), 42)) .filter( or(lessThan(Field.of("bar"), 100), equal(Field.of("key"), Constant.of("value")))) - .filter(not(Constant.of(128).inAny(Field.of("f1"), Field.of("f2")))); - results = p.execute(firestore); + .filter(not(Constant.of(128).inAny("f1", "f2"))); + results = p.execute(firestore).get(); } @Test public void inFilters() throws Exception { - Pipeline p = - Pipeline.fromCollectionGroup("coll1") - .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))); + Pipeline p = Pipeline.fromCollectionGroup("coll1").filter(Field.of("foo").inAny(42, "42")); + List results = p.execute(firestore).get(); } @Test public void aggregateWithoutGrouping() throws Exception { Pipeline p = - Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny(42, Field.of("bar"))) + Pipeline.fromDatabase() + .filter(Field.of("foo").inAny(42, "bar")) .aggregate(avg(Field.of("score")).toField("avg_score_1")); + List results = p.execute(firestore).get(); } @Test public void sorts() throws Exception { Pipeline p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) + .filter(Field.of("foo").inAny(42, "42")) .sort( Field.of("rank").ascending(), Sort.Ordering.of( cosineDistance(Field.of("embedding1"), Field.of("embedding2")), Direction.DESCENDING)) .limit(100); + List results = p.execute(firestore).get(); // equivalent but more concise. p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) + .filter(Field.of("foo").inAny(Constant.of(42), Constant.of(false))) .sort( ascending(Field.of("rank")), descending(cosineDistance(Field.of("embedding1"), Field.of("embedding2")))) .limit(100); + results = p.execute(firestore).get(); } @Test public void pagination() throws Exception { PaginatingPipeline p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) + .filter(Field.of("foo").inAny(Constant.of(42), Constant.of("bar"))) .paginate( 100, cosineDistance(Field.of("embedding1"), Field.of("embedding2")).descending()); - Iterator result = firestore.execute(p.firstPage()).get(); - // Iterator second = firestore.execute(p.startAfter(result.next())).get(); + List results = p.firstPage().execute(firestore).get(); } @Test @@ -133,7 +163,7 @@ public void limit() throws Exception { .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) .limit(10); - Iterator result = firestore.execute(p).get(); + List result = p.execute(firestore).get(); } @Test @@ -142,19 +172,17 @@ public void offset() throws Exception { Pipeline.fromDocuments(firestore.document("foo/bar1"), firestore.document("foo/bar2")) .offset(1); - Iterator result = firestore.execute(p).get(); + List result = p.execute(firestore).get(); } @Test public void fluentAllTheWay() throws Exception { PaginatingPipeline p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) + .filter(Field.of("foo").inAny(Constant.of(42), Constant.of("bar"))) .paginate( 100, cosineDistance(Field.of("embedding1"), Field.of("embedding2")).descending()); - ApiFuture> result = p.firstPage().execute(firestore); - // List second = - // p.startAfter(result.iterator().next()).execute(firestore).get(); + List result = p.firstPage().execute(firestore).get(); } } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java index 444d31dd5..3ddd8439b 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java @@ -19,7 +19,6 @@ import static com.google.cloud.firestore.it.TestHelper.isRunningAgainstFirestoreEmulator; import static com.google.common.primitives.Ints.asList; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assume.assumeTrue; import com.google.cloud.firestore.*; import com.google.cloud.firestore.Query.Direction; @@ -28,6 +27,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -66,12 +66,26 @@ public CollectionReference testCollectionWithDocs(Map result = + snapshot.getDocuments().stream() + .map(queryDocumentSnapshot -> queryDocumentSnapshot.getReference().getId()) + .collect(Collectors.toList()); + assertThat(result).isEqualTo(Arrays.asList(docs)); + } + + List pipelineResults = query.toPipeline().execute(query.getFirestore()).get(); List result = - snapshot.getDocuments().stream() - .map(queryDocumentSnapshot -> queryDocumentSnapshot.getReference().getId()) + pipelineResults.stream() + .map(pipelineResult -> Objects.requireNonNull(pipelineResult.getReference()).getId()) .collect(Collectors.toList()); assertThat(result).isEqualTo(Arrays.asList(docs)); } @@ -89,7 +103,7 @@ public void orQueries() throws Exception { CollectionReference collection = testCollectionWithDocs(testDocs); // Two equalities: a==1 || b==1. - checkQuerySnapshotContainsDocuments( + checkResultContainsDocuments( collection.where(Filter.or(Filter.equalTo("a", 1), Filter.equalTo("b", 1))), "doc1", "doc2", @@ -97,7 +111,7 @@ public void orQueries() throws Exception { "doc5"); // (a==1 && b==0) || (a==3 && b==2) - checkQuerySnapshotContainsDocuments( + checkResultContainsDocuments( collection.where( Filter.or( Filter.and(Filter.equalTo("a", 1), Filter.equalTo("b", 0)), @@ -106,7 +120,7 @@ public void orQueries() throws Exception { "doc3"); // a==1 && (b==0 || b==3). - checkQuerySnapshotContainsDocuments( + checkResultContainsDocuments( collection.where( Filter.and( Filter.equalTo("a", 1), Filter.or(Filter.equalTo("b", 0), Filter.equalTo("b", 3)))), @@ -114,7 +128,7 @@ public void orQueries() throws Exception { "doc4"); // (a==2 || b==2) && (a==3 || b==3) - checkQuerySnapshotContainsDocuments( + checkResultContainsDocuments( collection.where( Filter.and( Filter.or(Filter.equalTo("a", 2), Filter.equalTo("b", 2)), @@ -122,16 +136,13 @@ public void orQueries() throws Exception { "doc3"); // Test with limits without orderBy (the __name__ ordering is the tiebreaker). - checkQuerySnapshotContainsDocuments( + checkResultContainsDocuments( collection.where(Filter.or(Filter.equalTo("a", 2), Filter.equalTo("b", 1))).limit(1), "doc2"); } @Test public void orQueriesWithCompositeIndexes() throws Exception { - assumeTrue( - "Skip this test when running against production because these queries require a composite index.", - isRunningAgainstFirestoreEmulator(firestore)); Map> testDocs = map( "doc1", map("a", 1, "b", 0), @@ -143,50 +154,56 @@ public void orQueriesWithCompositeIndexes() throws Exception { CollectionReference collection = testCollectionWithDocs(testDocs); // with one inequality: a>2 || b==1. - checkQuerySnapshotContainsDocuments( + checkResultContainsDocuments( collection.where(Filter.or(Filter.greaterThan("a", 2), Filter.equalTo("b", 1))), + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc5", "doc2", "doc3"); // Test with limits (implicit order by ASC): (a==1) || (b > 0) LIMIT 2 - checkQuerySnapshotContainsDocuments( + checkResultContainsDocuments( collection.where(Filter.or(Filter.equalTo("a", 1), Filter.greaterThan("b", 0))).limit(2), + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc1", "doc2"); // Test with limits (explicit order by): (a==1) || (b > 0) LIMIT_TO_LAST 2 // Note: The public query API does not allow implicit ordering when limitToLast is used. - checkQuerySnapshotContainsDocuments( + checkResultContainsDocuments( collection .where(Filter.or(Filter.equalTo("a", 1), Filter.greaterThan("b", 0))) .limitToLast(2) .orderBy("b"), + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc3", "doc4"); // Test with limits (explicit order by ASC): (a==2) || (b == 1) ORDER BY a LIMIT 1 - checkQuerySnapshotContainsDocuments( + checkResultContainsDocuments( collection .where(Filter.or(Filter.equalTo("a", 2), Filter.equalTo("b", 1))) .limit(1) .orderBy("a"), + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc5"); // Test with limits (explicit order by DESC): (a==2) || (b == 1) ORDER BY a LIMIT_TO_LAST 1 - checkQuerySnapshotContainsDocuments( + checkResultContainsDocuments( collection .where(Filter.or(Filter.equalTo("a", 2), Filter.equalTo("b", 1))) .limitToLast(1) .orderBy("a"), + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2"); // Test with limits (explicit order by DESC): (a==2) || (b == 1) ORDER BY a DESC LIMIT 1 - checkQuerySnapshotContainsDocuments( + checkResultContainsDocuments( collection .where(Filter.or(Filter.equalTo("a", 2), Filter.equalTo("b", 1))) .limit(1) .orderBy("a", Direction.DESCENDING), + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2"); } @@ -207,14 +224,11 @@ public void orQueryDoesNotIncludeDocumentsWithMissingFields() throws Exception { // There's no explicit nor implicit orderBy. Documents with missing 'a' or missing 'b' should be // allowed if the document matches at least one disjunction term. Query query = collection.where(Filter.or(Filter.equalTo("a", 1), Filter.equalTo("b", 1))); - checkQuerySnapshotContainsDocuments(query, "doc1", "doc2", "doc4", "doc5"); + checkResultContainsDocuments(query, "doc1", "doc2", "doc4", "doc5"); } @Test public void orQueryDoesNotIncludeDocumentsWithMissingFields2() throws Exception { - assumeTrue( - "Skip this test when running against production because these queries require a composite index.", - isRunningAgainstFirestoreEmulator(firestore)); Map> testDocs = map( "doc1", map("a", 1, "b", 0), @@ -230,19 +244,30 @@ public void orQueryDoesNotIncludeDocumentsWithMissingFields2() throws Exception // doc2 should not be included because it's missing the field 'a', and we have "orderBy a". Query query1 = collection.where(Filter.or(Filter.equalTo("a", 1), Filter.equalTo("b", 1))).orderBy("a"); - checkQuerySnapshotContainsDocuments(query1, "doc1", "doc4", "doc5"); + checkResultContainsDocuments( + query1, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc1", + "doc4", + "doc5"); // Query: a==1 || b==1 order by b. // doc5 should not be included because it's missing the field 'b', and we have "orderBy b". Query query2 = collection.where(Filter.or(Filter.equalTo("a", 1), Filter.equalTo("b", 1))).orderBy("b"); - checkQuerySnapshotContainsDocuments(query2, "doc1", "doc2", "doc4"); + checkResultContainsDocuments( + query2, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc1", + "doc2", + "doc4"); // Query: a>2 || b==1. // This query has an implicit 'order by a'. // doc2 should not be included because it's missing the field 'a'. Query query3 = collection.where(Filter.or(Filter.greaterThan("a", 2), Filter.equalTo("b", 1))); - checkQuerySnapshotContainsDocuments(query3, "doc3"); + checkResultContainsDocuments( + query3, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc3"); // Query: a>1 || b==1 order by a order by b. // doc6 should not be included because it's missing the field 'b'. @@ -252,7 +277,8 @@ public void orQueryDoesNotIncludeDocumentsWithMissingFields2() throws Exception .where(Filter.or(Filter.greaterThan("a", 1), Filter.equalTo("b", 1))) .orderBy("a") .orderBy("b"); - checkQuerySnapshotContainsDocuments(query4, "doc3"); + checkResultContainsDocuments( + query4, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc3"); } @Test @@ -268,7 +294,7 @@ public void orQueriesWithIn() throws ExecutionException, InterruptedException, T CollectionReference collection = testCollectionWithDocs(testDocs); // a==2 || b in [2,3] - checkQuerySnapshotContainsDocuments( + checkResultContainsDocuments( collection.where(Filter.or(Filter.equalTo("a", 2), Filter.inArray("b", asList(2, 3)))), "doc3", "doc4", @@ -278,9 +304,6 @@ public void orQueriesWithIn() throws ExecutionException, InterruptedException, T @Test public void orQueriesWithNotIn() throws ExecutionException, InterruptedException, TimeoutException { - assumeTrue( - "Skip this test when running against production because it is currently not supported.", - isRunningAgainstFirestoreEmulator(firestore)); Map> testDocs = map( "doc1", map("a", 1, "b", 0), @@ -293,8 +316,9 @@ public void orQueriesWithNotIn() // a==2 || b not-in [2,3] // Has implicit orderBy b. - checkQuerySnapshotContainsDocuments( + checkResultContainsDocuments( collection.where(Filter.or(Filter.equalTo("a", 2), Filter.notInArray("b", asList(2, 3)))), + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc1", "doc2"); } @@ -313,14 +337,14 @@ public void orQueriesWithArrayMembership() CollectionReference collection = testCollectionWithDocs(testDocs); // a==2 || b array-contains 7 - checkQuerySnapshotContainsDocuments( + checkResultContainsDocuments( collection.where(Filter.or(Filter.equalTo("a", 2), Filter.arrayContains("b", 7))), "doc3", "doc4", "doc6"); // a==2 || b array-contains-any [0, 3] - checkQuerySnapshotContainsDocuments( + checkResultContainsDocuments( collection.where( Filter.or(Filter.equalTo("a", 2), Filter.arrayContainsAny("b", asList(0, 3)))), "doc1", @@ -344,35 +368,31 @@ public void testUsingInWithArrayContains() Query query1 = collection.where( Filter.or(Filter.inArray("a", asList(2, 3)), Filter.arrayContains("b", 3))); - checkQuerySnapshotContainsDocuments(query1, "doc3", "doc4", "doc6"); + checkResultContainsDocuments(query1, "doc3", "doc4", "doc6"); Query query2 = collection.where( Filter.and(Filter.inArray("a", asList(2, 3)), Filter.arrayContains("b", 7))); - checkQuerySnapshotContainsDocuments(query2, "doc3"); + checkResultContainsDocuments(query2, "doc3"); Query query3 = collection.where( Filter.or( Filter.inArray("a", asList(2, 3)), Filter.and(Filter.arrayContains("b", 3), Filter.equalTo("a", 1)))); - checkQuerySnapshotContainsDocuments(query3, "doc3", "doc4", "doc6"); + checkResultContainsDocuments(query3, "doc3", "doc4", "doc6"); Query query4 = collection.where( Filter.and( Filter.inArray("a", asList(2, 3)), Filter.or(Filter.arrayContains("b", 7), Filter.equalTo("a", 1)))); - checkQuerySnapshotContainsDocuments(query4, "doc3"); + checkResultContainsDocuments(query4, "doc3"); } @Test public void testOrderByEquality() throws ExecutionException, InterruptedException, TimeoutException { - assumeTrue( - "Skip this test if running against production because order-by-equality is " - + "not supported yet.", - isRunningAgainstFirestoreEmulator(firestore)); Map> testDocs = map( "doc1", map("a", 1, "b", asList(0)), @@ -384,21 +404,21 @@ public void testOrderByEquality() CollectionReference collection = testCollectionWithDocs(testDocs); Query query1 = collection.where(Filter.equalTo("a", 1)).orderBy("a"); - checkQuerySnapshotContainsDocuments(query1, "doc1", "doc4", "doc5"); + checkResultContainsDocuments( + query1, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc1", + "doc4", + "doc5"); Query query2 = collection.where(Filter.inArray("a", asList(2, 3))).orderBy("a"); - checkQuerySnapshotContainsDocuments(query2, "doc6", "doc3"); + checkResultContainsDocuments( + query2, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc6", "doc3"); } /** Multiple Inequality */ @Test public void multipleInequalityOnDifferentFields() throws Exception { - // TODO(MIEQ): Enable this test against production when possible. - assumeTrue( - "Skip this test if running against production because multiple inequality is " - + "not supported yet.", - isRunningAgainstFirestoreEmulator(firestore)); - CollectionReference collection = testCollectionWithDocs( map( @@ -412,7 +432,8 @@ public void multipleInequalityOnDifferentFields() throws Exception { .whereNotEqualTo("key", "a") .whereLessThanOrEqualTo("sort", 2) .whereGreaterThan("v", 2); - checkQuerySnapshotContainsDocuments(query1, "doc3"); + checkResultContainsDocuments( + query1, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc3"); // Duplicate inequality fields Query query2 = @@ -420,7 +441,8 @@ public void multipleInequalityOnDifferentFields() throws Exception { .whereNotEqualTo("key", "a") .whereLessThanOrEqualTo("sort", 2) .whereGreaterThan("sort", 1); - checkQuerySnapshotContainsDocuments(query2, "doc4"); + checkResultContainsDocuments( + query2, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc4"); // With multiple IN Query query3 = @@ -429,7 +451,8 @@ public void multipleInequalityOnDifferentFields() throws Exception { .whereLessThanOrEqualTo("sort", 2) .whereIn("v", asList(2, 3, 4)) .whereIn("sort", asList(2, 3)); - checkQuerySnapshotContainsDocuments(query3, "doc4"); + checkResultContainsDocuments( + query3, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc4"); // With NOT-IN Query query4 = @@ -437,7 +460,8 @@ public void multipleInequalityOnDifferentFields() throws Exception { .whereGreaterThanOrEqualTo("key", "a") .whereLessThanOrEqualTo("sort", 2) .whereNotIn("v", asList(2, 4, 5)); - checkQuerySnapshotContainsDocuments(query4, "doc1", "doc3"); + checkResultContainsDocuments( + query4, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc1", "doc3"); // With orderby Query query5 = @@ -445,7 +469,12 @@ public void multipleInequalityOnDifferentFields() throws Exception { .whereGreaterThanOrEqualTo("key", "a") .whereLessThanOrEqualTo("sort", 2) .orderBy("v", Direction.DESCENDING); - checkQuerySnapshotContainsDocuments(query5, "doc3", "doc4", "doc1"); + checkResultContainsDocuments( + query5, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc3", + "doc4", + "doc1"); // With limit Query query6 = @@ -454,7 +483,8 @@ public void multipleInequalityOnDifferentFields() throws Exception { .whereLessThanOrEqualTo("sort", 2) .orderBy("v", Direction.DESCENDING) .limit(2); - checkQuerySnapshotContainsDocuments(query6, "doc3", "doc4"); + checkResultContainsDocuments( + query6, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc3", "doc4"); // With limitToLast Query query7 = @@ -463,17 +493,12 @@ public void multipleInequalityOnDifferentFields() throws Exception { .whereLessThanOrEqualTo("sort", 2) .orderBy("v", Direction.DESCENDING) .limitToLast(2); - checkQuerySnapshotContainsDocuments(query7, "doc4", "doc1"); + checkResultContainsDocuments( + query7, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc4", "doc1"); } @Test public void multipleInequalityOnSpecialValues() throws Exception { - // TODO(MIEQ): Enable this test against production when possible. - assumeTrue( - "Skip this test if running against production because multiple inequality is " - + "not supported yet.", - isRunningAgainstFirestoreEmulator(firestore)); - CollectionReference collection = testCollectionWithDocs( map( @@ -485,24 +510,20 @@ public void multipleInequalityOnSpecialValues() throws Exception { "doc6", map("key", "f", "sort", 1, "v", 1))); Query query1 = collection.whereNotEqualTo("key", "a").whereLessThanOrEqualTo("sort", 2); - checkQuerySnapshotContainsDocuments(query1, "doc5", "doc6"); + checkResultContainsDocuments( + query1, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc5", "doc6"); Query query2 = collection .whereNotEqualTo("key", "a") .whereLessThanOrEqualTo("sort", 2) .whereLessThanOrEqualTo("v", 1); - checkQuerySnapshotContainsDocuments(query2, "doc6"); + checkResultContainsDocuments( + query2, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc6"); } @Test public void multipleInequalityWithArrayMembership() throws Exception { - // TODO(MIEQ): Enable this test against production when possible. - assumeTrue( - "Skip this test if running against production because multiple inequality is " - + "not supported yet.", - isRunningAgainstFirestoreEmulator(firestore)); - CollectionReference collection = testCollectionWithDocs( map( @@ -526,14 +547,16 @@ public void multipleInequalityWithArrayMembership() throws Exception { .whereNotEqualTo("key", "a") .whereGreaterThanOrEqualTo("sort", 1) .whereArrayContains("v", 0); - checkQuerySnapshotContainsDocuments(query1, "doc2"); + checkResultContainsDocuments( + query1, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2"); Query query2 = collection .whereNotEqualTo("key", "a") .whereGreaterThanOrEqualTo("sort", 1) .whereArrayContainsAny("v", asList(0, 1)); - checkQuerySnapshotContainsDocuments(query2, "doc2", "doc4"); + checkResultContainsDocuments( + query2, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", "doc4"); } private static Map nestedObject(int number) { @@ -554,12 +577,6 @@ private static Map nestedObject(int number) { // result with the query fields normalized in the server. @Test public void multipleInequalityWithNestedField() throws Exception { - // TODO(MIEQ): Enable this test against production when possible. - assumeTrue( - "Skip this test if running against production because multiple inequality is " - + "not supported yet.", - isRunningAgainstFirestoreEmulator(firestore)); - CollectionReference collection = testCollectionWithDocs( map( @@ -577,8 +594,13 @@ public void multipleInequalityWithNestedField() throws Exception { .orderBy("name"); DocumentSnapshot docSnap = collection.document("doc4").get().get(); Query query1WithCursor = query1.startAt(docSnap); - checkQuerySnapshotContainsDocuments(query1, "doc4", "doc1"); - checkQuerySnapshotContainsDocuments(query1WithCursor, "doc4", "doc1"); + checkResultContainsDocuments( + query1, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc4", "doc1"); + checkResultContainsDocuments( + query1WithCursor, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc4", + "doc1"); // ordered by: name desc, field desc, field.dot desc, field\\slash desc, __name__ desc Query query2 = @@ -589,18 +611,13 @@ public void multipleInequalityWithNestedField() throws Exception { .orderBy("name", Direction.DESCENDING); docSnap = collection.document("doc2").get().get(); Query query2WithCursor = query2.startAt(docSnap); - checkQuerySnapshotContainsDocuments(query2, "doc2", "doc3"); - checkQuerySnapshotContainsDocuments(query2WithCursor, "doc2", "doc3"); + checkResultContainsDocuments( + query2, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", "doc3"); + checkResultContainsDocuments(query2WithCursor, "doc2", "doc3"); } @Test public void multipleInequalityWithCompositeFilters() throws Exception { - // TODO(MIEQ): Enable this test against production when possible. - assumeTrue( - "Skip this test if running against production because multiple inequality is " - + "not supported yet.", - isRunningAgainstFirestoreEmulator(firestore)); - CollectionReference collection = testCollectionWithDocs( map( @@ -625,8 +642,20 @@ public void multipleInequalityWithCompositeFilters() throws Exception { Filter.and(Filter.notEqualTo("key", "b"), Filter.greaterThan("v", 4)))); DocumentSnapshot docSnap = collection.document("doc1").get().get(); Query query1WithCursor = query1.startAt(docSnap); - checkQuerySnapshotContainsDocuments(query1, "doc1", "doc6", "doc5", "doc4"); - checkQuerySnapshotContainsDocuments(query1WithCursor, "doc1", "doc6", "doc5", "doc4"); + checkResultContainsDocuments( + query1, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc1", + "doc6", + "doc5", + "doc4"); + checkResultContainsDocuments( + query1WithCursor, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc1", + "doc6", + "doc5", + "doc4"); // Ordered by: 'sort' desc, 'key' asc, 'v' asc, __name__ asc Query query2 = @@ -639,8 +668,20 @@ public void multipleInequalityWithCompositeFilters() throws Exception { .orderBy("key"); docSnap = collection.document("doc5").get().get(); Query query2WithCursor = query2.startAt(docSnap); - checkQuerySnapshotContainsDocuments(query2, "doc5", "doc4", "doc1", "doc6"); - checkQuerySnapshotContainsDocuments(query2WithCursor, "doc5", "doc4", "doc1", "doc6"); + checkResultContainsDocuments( + query2, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc5", + "doc4", + "doc1", + "doc6"); + checkResultContainsDocuments( + query2WithCursor, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc5", + "doc4", + "doc1", + "doc6"); // Implicitly ordered by: 'key' asc, 'sort' asc, 'v' asc, __name__ asc Query query3 = @@ -655,19 +696,18 @@ public void multipleInequalityWithCompositeFilters() throws Exception { Filter.and(Filter.lessThan("key", "b"), Filter.greaterThan("v", 0))))); docSnap = collection.document("doc1").get().get(); Query query3WithCursor = query3.startAt(docSnap); - checkQuerySnapshotContainsDocuments(query3, "doc1", "doc2"); - checkQuerySnapshotContainsDocuments(query3WithCursor, "doc1", "doc2"); + checkResultContainsDocuments( + query3, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc1", "doc2"); + checkResultContainsDocuments( + query3WithCursor, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc1", + "doc2"); } @Test public void multipleInequalityFieldsWillBeImplicitlyOrderedLexicographicallyByServer() throws Exception { - // TODO(MIEQ): Enable this test against production when possible. - assumeTrue( - "Skip this test if running against production because multiple inequality is " - + "not supported yet.", - isRunningAgainstFirestoreEmulator(firestore)); - CollectionReference collection = testCollectionWithDocs( map( @@ -693,8 +733,20 @@ public void multipleInequalityFieldsWillBeImplicitlyOrderedLexicographicallyBySe .whereGreaterThan("sort", 1) .whereIn("v", asList(1, 2, 3, 4)); Query query1WithCursor = query1.startAt(docSnap); - checkQuerySnapshotContainsDocuments(query1, "doc2", "doc4", "doc5", "doc3"); - checkQuerySnapshotContainsDocuments(query1WithCursor, "doc2", "doc4", "doc5", "doc3"); + checkResultContainsDocuments( + query1, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc2", + "doc4", + "doc5", + "doc3"); + checkResultContainsDocuments( + query1WithCursor, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc2", + "doc4", + "doc5", + "doc3"); // Implicitly ordered by: 'key' asc, 'sort' asc, __name__ asc Query query2 = @@ -703,18 +755,24 @@ public void multipleInequalityFieldsWillBeImplicitlyOrderedLexicographicallyBySe .whereNotEqualTo("key", "a") .whereIn("v", asList(1, 2, 3, 4)); Query query2WithCursor = query2.startAt(docSnap); - checkQuerySnapshotContainsDocuments(query2, "doc2", "doc4", "doc5", "doc3"); - checkQuerySnapshotContainsDocuments(query2WithCursor, "doc2", "doc4", "doc5", "doc3"); + checkResultContainsDocuments( + query2, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc2", + "doc4", + "doc5", + "doc3"); + checkResultContainsDocuments( + query2WithCursor, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc2", + "doc4", + "doc5", + "doc3"); } @Test public void multipleInequalityWithMultipleExplicitOrderBy() throws Exception { - // TODO(MIEQ): Enable this test against production when possible. - assumeTrue( - "Skip this test if running against production because multiple inequality is " - + "not supported yet.", - isRunningAgainstFirestoreEmulator(firestore)); - CollectionReference collection = testCollectionWithDocs( map( @@ -737,8 +795,20 @@ public void multipleInequalityWithMultipleExplicitOrderBy() throws Exception { Query query1 = collection.whereGreaterThan("key", "a").whereGreaterThanOrEqualTo("sort", 1).orderBy("v"); Query query1WithCursor = query1.startAt(docSnap); - checkQuerySnapshotContainsDocuments(query1, "doc2", "doc4", "doc3", "doc5"); - checkQuerySnapshotContainsDocuments(query1WithCursor, "doc2", "doc4", "doc3", "doc5"); + checkResultContainsDocuments( + query1, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc2", + "doc4", + "doc3", + "doc5"); + checkResultContainsDocuments( + query1WithCursor, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc2", + "doc4", + "doc3", + "doc5"); // Ordered by: 'v asc, 'sort' asc, 'key' asc, __name__ asc Query query2 = @@ -748,8 +818,20 @@ public void multipleInequalityWithMultipleExplicitOrderBy() throws Exception { .orderBy("v") .orderBy("sort"); Query query2WithCursor = query2.startAt(docSnap); - checkQuerySnapshotContainsDocuments(query2, "doc2", "doc5", "doc4", "doc3"); - checkQuerySnapshotContainsDocuments(query2WithCursor, "doc2", "doc5", "doc4", "doc3"); + checkResultContainsDocuments( + query2, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc2", + "doc5", + "doc4", + "doc3"); + checkResultContainsDocuments( + query2WithCursor, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc2", + "doc5", + "doc4", + "doc3"); docSnap = collection.document("doc5").get().get(); @@ -761,8 +843,20 @@ public void multipleInequalityWithMultipleExplicitOrderBy() throws Exception { .whereGreaterThanOrEqualTo("sort", 1) .orderBy("v", Direction.DESCENDING); Query query3WithCursor = query3.startAt(docSnap); - checkQuerySnapshotContainsDocuments(query3, "doc5", "doc3", "doc4", "doc2"); - checkQuerySnapshotContainsDocuments(query3WithCursor, "doc5", "doc3", "doc4", "doc2"); + checkResultContainsDocuments( + query3, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc5", + "doc3", + "doc4", + "doc2"); + checkResultContainsDocuments( + query3WithCursor, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc5", + "doc3", + "doc4", + "doc2"); // Ordered by: 'v desc, 'sort' asc, 'key' asc, __name__ asc Query query4 = @@ -772,18 +866,24 @@ public void multipleInequalityWithMultipleExplicitOrderBy() throws Exception { .orderBy("v", Direction.DESCENDING) .orderBy("sort"); Query query4WithCursor = query4.startAt(docSnap); - checkQuerySnapshotContainsDocuments(query4, "doc5", "doc4", "doc3", "doc2"); - checkQuerySnapshotContainsDocuments(query4WithCursor, "doc5", "doc4", "doc3", "doc2"); + checkResultContainsDocuments( + query4, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc5", + "doc4", + "doc3", + "doc2"); + checkResultContainsDocuments( + query4WithCursor, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc5", + "doc4", + "doc3", + "doc2"); } @Test public void multipleInequalityFieldsInAggregateQuery() throws Exception { - // TODO(MIEQ): Enable this test against production when possible. - assumeTrue( - "Skip this test if running against production because multiple inequality is " - + "not supported yet.", - isRunningAgainstFirestoreEmulator(firestore)); - CollectionReference collection = testCollectionWithDocs( map( @@ -804,18 +904,15 @@ public void multipleInequalityFieldsInAggregateQuery() throws Exception { .whereGreaterThanOrEqualTo("sort", 1) .orderBy("v") .count(); - assertThat(query.get().get().getCount()).isEqualTo(4); + if (isRunningAgainstFirestoreEmulator(firestore)) { + assertThat(query.get().get().getCount()).isEqualTo(4); + } + assertThat(query.toPipeline().execute(query.getQuery().getFirestore()).get()).isNotEmpty(); // TODO(MIEQ): Add sum and average when they are public. } @Test public void multipleInequalityFieldsWithDocumentKey() throws Exception { - // TODO(MIEQ): Enable this test against production when possible. - assumeTrue( - "Skip this test if running against production because multiple inequality is " - + "not supported yet.", - isRunningAgainstFirestoreEmulator(firestore)); - CollectionReference collection = testCollectionWithDocs( map( @@ -840,8 +937,18 @@ public void multipleInequalityFieldsWithDocumentKey() throws Exception { .whereNotEqualTo("key", "a") .whereLessThan(FieldPath.documentId(), "doc5"); Query query1WithCursor = query1.startAt(docSnap); - checkQuerySnapshotContainsDocuments(query1, "doc2", "doc4", "doc3"); - checkQuerySnapshotContainsDocuments(query1WithCursor, "doc2", "doc4", "doc3"); + checkResultContainsDocuments( + query1, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc2", + "doc4", + "doc3"); + checkResultContainsDocuments( + query1WithCursor, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc2", + "doc4", + "doc3"); // Changing filters order will not affect implicit order. // Implicitly ordered by: 'key' asc, 'sort' asc, __name__ asc @@ -851,8 +958,18 @@ public void multipleInequalityFieldsWithDocumentKey() throws Exception { .whereGreaterThan("sort", 1) .whereNotEqualTo("key", "a"); Query query2WithCursor = query2.startAt(docSnap); - checkQuerySnapshotContainsDocuments(query2, "doc2", "doc4", "doc3"); - checkQuerySnapshotContainsDocuments(query2WithCursor, "doc2", "doc4", "doc3"); + checkResultContainsDocuments( + query2, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc2", + "doc4", + "doc3"); + checkResultContainsDocuments( + query2WithCursor, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc2", + "doc4", + "doc3"); // Ordered by: 'sort' desc, 'key' desc, __name__ desc Query query3 = @@ -862,7 +979,17 @@ public void multipleInequalityFieldsWithDocumentKey() throws Exception { .whereNotEqualTo("key", "a") .orderBy("sort", Direction.DESCENDING); Query query3WithCursor = query3.startAt(docSnap); - checkQuerySnapshotContainsDocuments(query3, "doc2", "doc3", "doc4"); - checkQuerySnapshotContainsDocuments(query3WithCursor, "doc2", "doc3", "doc4"); + checkResultContainsDocuments( + query3, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc2", + "doc3", + "doc4"); + checkResultContainsDocuments( + query3WithCursor, + /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), + "doc2", + "doc3", + "doc4"); } } From 1ceab8ac700fb8dfddc9094538d6a5b1d5e2ae55 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Mon, 6 May 2024 10:25:26 -0400 Subject: [PATCH 35/65] visibility changes --- .../com/google/cloud/firestore/Pipeline.kt | 2 +- .../cloud/firestore/pipeline/Expressions.kt | 69 ++++++++++--------- .../google/cloud/firestore/pipeline/Stages.kt | 41 ++++++----- 3 files changed, 58 insertions(+), 54 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 4e2682bb7..4954bb764 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -315,7 +315,7 @@ class Pipeline private constructor(private val stages: List, private val } } - fun toProto(): Value { + internal fun toProto(): Value { return Value.newBuilder() .setPipelineValue( com.google.firestore.v1.Pipeline.newBuilder().addAllStages(stages.map { toStageProto(it) }) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index 1c3892d5a..95f62d590 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -47,7 +47,7 @@ internal fun exprToValue(expr: Expr): Value { } } -sealed interface Projectable +interface Projectable interface Expr { // Infix functions returning Function subclasses @@ -148,7 +148,7 @@ interface Expr { // Convenient class for internal usage internal data class ListOfExprs(val conditions: List) : Expr -data class Constant internal constructor(val value: Any?) : Expr { +data class Constant internal constructor(private val value: Any?) : Expr { companion object { @JvmStatic fun of(value: String?): Constant { @@ -237,12 +237,15 @@ data class Constant internal constructor(val value: Any?) : Expr { } } - fun toProto(): Value { + internal fun toProto(): Value { return encodeValue(value)!! } } -data class Field internal constructor(val field: String, var pipeline: Pipeline? = null) : +data class Field internal constructor( + internal val field: String, + private var pipeline: Pipeline? = null +) : Expr, Projectable { companion object { const val DOCUMENT_ID: String = "__path__" @@ -258,12 +261,12 @@ data class Field internal constructor(val field: String, var pipeline: Pipeline? } } - fun toProto(): Value { + internal fun toProto(): Value { return Value.newBuilder().setFieldReferenceValue(field).build() } } -data class Fields internal constructor(val fs: List? = null) : Expr, Projectable { +data class Fields internal constructor(internal val fs: List? = null) : Expr, Projectable { companion object { @JvmStatic fun of(f1: String, vararg f: String): Fields { @@ -279,8 +282,8 @@ data class Fields internal constructor(val fs: List? = null) : Expr, Proj data class AggregatorTarget internal constructor( - val accumulator: Function.Accumulator, - val fieldName: String, + internal val accumulator: Function.Accumulator, + internal val fieldName: String, override var distinct: Boolean, ) : Projectable, Function.Accumulator @@ -298,7 +301,7 @@ sealed class Function(val name: String, val params: List) : Expr { fun toField(target: String) = AggregatorTarget(this, target, this.distinct) } - fun toProto(): Value { + internal fun toProto(): Value { return Value.newBuilder() .setFunctionValue( com.google.firestore.v1.Function.newBuilder() @@ -308,70 +311,72 @@ sealed class Function(val name: String, val params: List) : Expr { .build() } - data class Equal internal constructor(val left: Expr, val right: Expr) : + data class Equal internal constructor(private val left: Expr, private val right: Expr) : Function("eq", listOf(left, right)), FilterCondition - data class NotEqual(val left: Expr, val right: Expr) : + data class NotEqual(private val left: Expr, private val right: Expr) : Function("neq", listOf(left, right)), FilterCondition - data class GreaterThan(val left: Expr, val right: Expr) : + data class GreaterThan(private val left: Expr, private val right: Expr) : Function("gt", listOf(left, right)), FilterCondition - data class GreaterThanOrEqual(val left: Expr, val right: Expr) : + data class GreaterThanOrEqual(private val left: Expr, private val right: Expr) : Function("gte", listOf(left, right)), FilterCondition - data class LessThan(val left: Expr, val right: Expr) : + data class LessThan(private val left: Expr, private val right: Expr) : Function("lt", listOf(left, right)), FilterCondition - data class LessThanOrEqual(val left: Expr, val right: Expr) : + data class LessThanOrEqual(private val left: Expr, private val right: Expr) : Function("lte", listOf(left, right)), FilterCondition - data class In(val left: Expr, val others: List) : + data class In(private val left: Expr, private val others: List) : Function("in", listOf(left, ListOfExprs(others))), FilterCondition // For 'in' - data class And(val conditions: List) : Function("and", conditions), FilterCondition where + data class And(private val conditions: List) : Function("and", conditions), + FilterCondition where T : FilterCondition - data class Or(val conditions: List) : Function("or", conditions), FilterCondition where + data class Or(private val conditions: List) : Function("or", conditions), + FilterCondition where T : FilterCondition - data class Not(val condition: Expr) : Function("not", listOf(condition)), FilterCondition + data class Not(private val condition: Expr) : Function("not", listOf(condition)), FilterCondition - data class ArrayContains(val array: Expr, val element: Expr) : + data class ArrayContains(private val array: Expr, private val element: Expr) : Function("array_contains", listOf(array, element)), FilterCondition - data class ArrayContainsAny(val array: Expr, val elements: List) : + data class ArrayContainsAny(private val array: Expr, private val elements: List) : Function("array_contains_any", listOf(array, ListOfExprs(elements))), FilterCondition - data class IsNaN(val value: Expr) : Function("is_nan", listOf(value)), FilterCondition + data class IsNaN(private val value: Expr) : Function("is_nan", listOf(value)), FilterCondition - data class IsNull(val value: Expr) : Function("is_null", listOf(value)), FilterCondition + data class IsNull(private val value: Expr) : Function("is_null", listOf(value)), FilterCondition - data class Sum(val value: Expr, override var distinct: Boolean) : + data class Sum(private val value: Expr, override var distinct: Boolean) : Function("sum", listOf(value)), Accumulator - data class Avg(val value: Expr, override var distinct: Boolean) : + data class Avg(private val value: Expr, override var distinct: Boolean) : Function("avg", listOf(value)), Accumulator - data class Count(val value: Expr?, override var distinct: Boolean) : + data class Count(private val value: Expr?, override var distinct: Boolean) : Function("count", value?.let { listOf(it) } ?: emptyList()), Accumulator - data class Min(val value: Expr, override var distinct: Boolean) : + data class Min(private val value: Expr, override var distinct: Boolean) : Function("min", listOf(value)), Accumulator - data class Max(val value: Expr, override var distinct: Boolean) : + data class Max(private val value: Expr, override var distinct: Boolean) : Function("max", listOf(value)), Accumulator - data class CosineDistance(val vector1: Expr, val vector2: Expr) : + data class CosineDistance(private val vector1: Expr, private val vector2: Expr) : Function("cosine_distance", listOf(vector1, vector2)) - data class DotProductDistance(val vector1: Expr, val vector2: Expr) : + data class DotProductDistance(private val vector1: Expr, private val vector2: Expr) : Function("dot_product", listOf(vector1, vector2)) - data class EuclideanDistance(val vector1: Expr, val vector2: Expr) : + data class EuclideanDistance(private val vector1: Expr, private val vector2: Expr) : Function("euclidean_distance", listOf(vector1, vector2)) - data class Generic(val n: String, val ps: List) : Function(n, ps) + data class Generic(private val n: String, private val ps: List) : Function(n, ps) companion object { @JvmStatic fun equal(left: Expr, right: Expr) = Equal(left, right) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt index df3a76445..433474caa 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt @@ -8,11 +8,11 @@ import java.util.Locale internal interface Stage -internal data class Collection(val relativePath: String) : Stage { +internal data class Collection(internal val relativePath: String) : Stage { val name = "collection" } -internal data class CollectionGroup(val collectionId: String) : Stage { +internal data class CollectionGroup(internal val collectionId: String) : Stage { val name = "collection_group" } @@ -20,7 +20,7 @@ internal class Database : Stage { val name = "database" } -internal data class Documents(val documents: List) : Stage { +internal data class Documents(internal val documents: List) : Stage { val name = "documents" companion object { @@ -31,32 +31,32 @@ internal data class Documents(val documents: List) : Stage { } } -internal data class Project(val projections: Map) : Stage { +internal data class Project(internal val projections: Map) : Stage { val name = "project" } -internal data class AddFields(val fields: Map) : Stage { +internal data class AddFields(internal val fields: Map) : Stage { val name = "add_fields" } -internal data class Filter(val condition: T) : Stage where +internal data class Filter(internal val condition: T) : Stage where T : Function.FilterCondition, T : Expr { val name = "filter" } -internal class Offset(val offset: Int) : Stage { +internal class Offset(internal val offset: Int) : Stage { val name = "offset" } -internal class Limit(val limit: Int) : Stage { +internal class Limit(internal val limit: Int) : Stage { val name = "limit" } class Aggregate internal constructor( - val groups: Map, - val accumulators: Map, + internal val groups: Map, + internal val accumulators: Map, ) : Stage { val name = "aggregate" @@ -67,14 +67,14 @@ internal constructor( class FindNearest internal constructor( - val property: Field, - val vector: DoubleArray, - val distanceMeasure: DistanceMeasure, - val options: FindNearestOptions, + internal val property: Field, + internal val vector: DoubleArray, + internal val distanceMeasure: DistanceMeasure, + internal val options: FindNearestOptions, ) : Stage { val name = "find_nearest" - sealed interface DistanceMeasure { + interface DistanceMeasure { data object Euclidean : DistanceMeasure data object Cosine : DistanceMeasure @@ -89,6 +89,7 @@ internal constructor( is Cosine -> "cosine" is DotProduct -> "dot_product" is GenericDistanceMeasure -> name + else -> throw IllegalArgumentException("Unknown distance measure") } } @@ -108,9 +109,9 @@ internal constructor( class Sort internal constructor( - val orders: List, - val density: Density = Density.UNSPECIFIED, - val truncation: Truncation = Truncation.UNSPECIFIED, + internal val orders: List, + internal val density: Density = Density.UNSPECIFIED, + internal val truncation: Truncation = Truncation.UNSPECIFIED, ) : Stage { val name = "sort" @@ -172,9 +173,7 @@ internal constructor( } } -// internal class Pagination(): Stage, GenericStage() - -internal open class GenericStage(val name: String, val params: List) : Stage {} +internal class GenericStage(internal val name: String, internal val params: List) : Stage {} internal fun toStageProto(stage: Stage): com.google.firestore.v1.Pipeline.Stage { return when (stage) { From df21cf2091942572f1b357611d6ce183fbbfb113 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Tue, 14 May 2024 14:19:08 -0400 Subject: [PATCH 36/65] refactoring --- .../com/google/cloud/firestore/Pipeline.kt | 2 +- .../google/cloud/firestore/PipelineResult.kt | 2 +- .../com/google/cloud/firestore/Query.java | 2 +- .../cloud/firestore/pipeline/Expressions.kt | 70 +++++++++++++------ .../google/cloud/firestore/pipeline/Stages.kt | 7 +- .../cloud/firestore/it/ITPipelineTest.java | 41 +++-------- 6 files changed, 66 insertions(+), 58 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index 4954bb764..cc2c2342b 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -189,7 +189,7 @@ class Pipeline private constructor(private val stages: List, private val return Pipeline(stages.plus(AddFields(projectablesToMap(*fields))), name) } - fun project(vararg projections: Projectable): Pipeline { + fun select(vararg projections: Projectable): Pipeline { return Pipeline(stages.plus(Project(projectablesToMap(*projections))), name) } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt index fa191001e..6cebcfc46 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt @@ -6,7 +6,7 @@ import com.google.firestore.v1.Value import java.util.Date import javax.annotation.Nonnull -data class PipelineResult +class PipelineResult internal constructor( private val rpcContext: FirestoreRpcContext<*>?, val reference: DocumentReference?, diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index 0eedf2f69..914f665b9 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -1990,7 +1990,7 @@ public Pipeline toPipeline() { if (this.options.getFieldProjections() != null && !this.options.getFieldProjections().isEmpty()) { ppl = - ppl.project( + ppl.select( this.options.getFieldProjections().stream() .map(fieldReference -> Field.of(fieldReference.getFieldPath())) .toArray(Projectable[]::new)); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index 95f62d590..9ce8210ef 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -287,7 +287,7 @@ internal constructor( override var distinct: Boolean, ) : Projectable, Function.Accumulator -sealed class Function(val name: String, val params: List) : Expr { +open class Function(val name: String, val params: List) : Expr { interface FilterCondition : Expr interface Accumulator : Expr { @@ -314,69 +314,93 @@ sealed class Function(val name: String, val params: List) : Expr { data class Equal internal constructor(private val left: Expr, private val right: Expr) : Function("eq", listOf(left, right)), FilterCondition - data class NotEqual(private val left: Expr, private val right: Expr) : + data class NotEqual internal constructor(private val left: Expr, private val right: Expr) : Function("neq", listOf(left, right)), FilterCondition - data class GreaterThan(private val left: Expr, private val right: Expr) : + data class GreaterThan internal constructor(private val left: Expr, private val right: Expr) : Function("gt", listOf(left, right)), FilterCondition - data class GreaterThanOrEqual(private val left: Expr, private val right: Expr) : + data class GreaterThanOrEqual internal constructor( + private val left: Expr, + private val right: Expr + ) : Function("gte", listOf(left, right)), FilterCondition - data class LessThan(private val left: Expr, private val right: Expr) : + data class LessThan internal constructor(private val left: Expr, private val right: Expr) : Function("lt", listOf(left, right)), FilterCondition - data class LessThanOrEqual(private val left: Expr, private val right: Expr) : + data class LessThanOrEqual internal constructor(private val left: Expr, private val right: Expr) : Function("lte", listOf(left, right)), FilterCondition - data class In(private val left: Expr, private val others: List) : + data class In internal constructor(private val left: Expr, private val others: List) : Function("in", listOf(left, ListOfExprs(others))), FilterCondition // For 'in' - data class And(private val conditions: List) : Function("and", conditions), + data class And internal constructor(private val conditions: List) : + Function("and", conditions), FilterCondition where T : FilterCondition - data class Or(private val conditions: List) : Function("or", conditions), + data class Or internal constructor(private val conditions: List) : + Function("or", conditions), FilterCondition where T : FilterCondition - data class Not(private val condition: Expr) : Function("not", listOf(condition)), FilterCondition + data class Not internal constructor(private val condition: Expr) : + Function("not", listOf(condition)), FilterCondition - data class ArrayContains(private val array: Expr, private val element: Expr) : + data class ArrayContains internal constructor( + private val array: Expr, + private val element: Expr + ) : Function("array_contains", listOf(array, element)), FilterCondition - data class ArrayContainsAny(private val array: Expr, private val elements: List) : + data class ArrayContainsAny internal constructor( + private val array: Expr, + private val elements: List + ) : Function("array_contains_any", listOf(array, ListOfExprs(elements))), FilterCondition - data class IsNaN(private val value: Expr) : Function("is_nan", listOf(value)), FilterCondition + data class IsNaN internal constructor(private val value: Expr) : + Function("is_nan", listOf(value)), FilterCondition - data class IsNull(private val value: Expr) : Function("is_null", listOf(value)), FilterCondition + data class IsNull internal constructor(private val value: Expr) : + Function("is_null", listOf(value)), FilterCondition - data class Sum(private val value: Expr, override var distinct: Boolean) : + data class Sum internal constructor(private val value: Expr, override var distinct: Boolean) : Function("sum", listOf(value)), Accumulator - data class Avg(private val value: Expr, override var distinct: Boolean) : + data class Avg internal constructor(private val value: Expr, override var distinct: Boolean) : Function("avg", listOf(value)), Accumulator - data class Count(private val value: Expr?, override var distinct: Boolean) : + data class Count internal constructor(private val value: Expr?, override var distinct: Boolean) : Function("count", value?.let { listOf(it) } ?: emptyList()), Accumulator - data class Min(private val value: Expr, override var distinct: Boolean) : + data class Min internal constructor(private val value: Expr, override var distinct: Boolean) : Function("min", listOf(value)), Accumulator - data class Max(private val value: Expr, override var distinct: Boolean) : + data class Max internal constructor(private val value: Expr, override var distinct: Boolean) : Function("max", listOf(value)), Accumulator - data class CosineDistance(private val vector1: Expr, private val vector2: Expr) : + data class CosineDistance internal constructor( + private val vector1: Expr, + private val vector2: Expr + ) : Function("cosine_distance", listOf(vector1, vector2)) - data class DotProductDistance(private val vector1: Expr, private val vector2: Expr) : + data class DotProductDistance internal constructor( + private val vector1: Expr, + private val vector2: Expr + ) : Function("dot_product", listOf(vector1, vector2)) - data class EuclideanDistance(private val vector1: Expr, private val vector2: Expr) : + data class EuclideanDistance internal constructor( + private val vector1: Expr, + private val vector2: Expr + ) : Function("euclidean_distance", listOf(vector1, vector2)) - data class Generic(private val n: String, private val ps: List) : Function(n, ps) + data class Generic internal constructor(private val n: String, private val ps: List) : + Function(n, ps) companion object { @JvmStatic fun equal(left: Expr, right: Expr) = Equal(left, right) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt index 433474caa..43f72d2a9 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt @@ -104,7 +104,12 @@ internal constructor( } } - data class FindNearestOptions(val limit: Long?, val output: Field? = null) + class FindNearestOptions(val limit: Long, val output: Field? = null) { + companion object { + @JvmStatic + fun newInstance(limit: Long, output: Field? = null) = FindNearestOptions(limit, output) + } + } } class Sort diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 2494c5dd3..53b3f2bc7 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -34,8 +34,6 @@ import com.google.cloud.firestore.pipeline.Constant; import com.google.cloud.firestore.pipeline.Field; import com.google.cloud.firestore.pipeline.Fields; -import com.google.cloud.firestore.pipeline.Sort; -import com.google.cloud.firestore.pipeline.Sort.Ordering.Direction; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -75,25 +73,20 @@ public void fromSources() throws Exception { @Test public void projections() throws Exception { - Pipeline p = Pipeline.fromCollectionGroup("coll1").project(Field.of("foo")); + Pipeline p = Pipeline.fromCollectionGroup("coll1").select(Field.of("foo")); List results = p.execute(firestore).get(); System.out.println(results.size()); - // More compact - p = Pipeline.fromCollectionGroup("coll1").project(Fields.of("foo", "bar", "baz")); + p = Pipeline.fromCollectionGroup("coll1").select(Fields.of("foo", "bar", "baz")); results = p.execute(firestore).get(); - System.out.println(results.size()); } @Test public void filters() throws Exception { Pipeline p = Pipeline.fromCollectionGroup("coll1") - .filter(Field.of("foo").equal(Constant.of(42))) - .filter( - or( - Field.of("bar").lessThan(Constant.of(100)), - Constant.of("value").equal(Field.of("key")))) + .filter(Field.of("foo").equal(42)) + .filter(or(Field.of("bar").lessThan(100), Constant.of("value").equal(Field.of("key")))) .filter(not(Constant.of(128).inAny("f1", "f2"))); List results = p.execute(firestore).get(); @@ -128,16 +121,14 @@ public void sorts() throws Exception { .filter(Field.of("foo").inAny(42, "42")) .sort( Field.of("rank").ascending(), - Sort.Ordering.of( - cosineDistance(Field.of("embedding1"), Field.of("embedding2")), - Direction.DESCENDING)) + cosineDistance(Field.of("embedding1"), Field.of("embedding2")).descending()) .limit(100); List results = p.execute(firestore).get(); // equivalent but more concise. p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny(Constant.of(42), Constant.of(false))) + .filter(Field.of("foo").inAny(42, false)) .sort( ascending(Field.of("rank")), descending(cosineDistance(Field.of("embedding1"), Field.of("embedding2")))) @@ -149,19 +140,18 @@ public void sorts() throws Exception { public void pagination() throws Exception { PaginatingPipeline p = Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny(Constant.of(42), Constant.of("bar"))) + .filter(Field.of("foo").inAny(42, "bar")) .paginate( 100, cosineDistance(Field.of("embedding1"), Field.of("embedding2")).descending()); List results = p.firstPage().execute(firestore).get(); + List secondPage = + p.startAfter(results.get(results.size() - 1)).firstPage().execute(firestore).get(); } @Test public void limit() throws Exception { - Pipeline p = - Pipeline.fromDatabase() - .filter(Field.of("foo").inAny(Constant.of(42), Field.of("bar"))) - .limit(10); + Pipeline p = Pipeline.fromDatabase().filter(Field.of("foo").inAny(42, "bar")).limit(10); List result = p.execute(firestore).get(); } @@ -174,15 +164,4 @@ public void offset() throws Exception { List result = p.execute(firestore).get(); } - - @Test - public void fluentAllTheWay() throws Exception { - PaginatingPipeline p = - Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny(Constant.of(42), Constant.of("bar"))) - .paginate( - 100, cosineDistance(Field.of("embedding1"), Field.of("embedding2")).descending()); - - List result = p.firstPage().execute(firestore).get(); - } } From cfea0fda8cc3261fe4cfffe5b5f2f8c604389127 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Thu, 16 May 2024 10:50:55 -0400 Subject: [PATCH 37/65] disable failing tests temparorily --- .../cloud/firestore/it/ITPipelineTest.java | 187 +++++++++--------- .../cloud/firestore/it/ITQueryTest.java | 7 +- 2 files changed, 98 insertions(+), 96 deletions(-) diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 53b3f2bc7..7be2f404d 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -68,100 +68,99 @@ public void fromSources() throws Exception { Pipeline p = Pipeline.fromCollectionGroup(collection.getId()); List results = p.execute(firestore).get(); - System.out.println(results.size()); } - @Test - public void projections() throws Exception { - Pipeline p = Pipeline.fromCollectionGroup("coll1").select(Field.of("foo")); - List results = p.execute(firestore).get(); - System.out.println(results.size()); - - p = Pipeline.fromCollectionGroup("coll1").select(Fields.of("foo", "bar", "baz")); - results = p.execute(firestore).get(); - } - - @Test - public void filters() throws Exception { - Pipeline p = - Pipeline.fromCollectionGroup("coll1") - .filter(Field.of("foo").equal(42)) - .filter(or(Field.of("bar").lessThan(100), Constant.of("value").equal(Field.of("key")))) - .filter(not(Constant.of(128).inAny("f1", "f2"))); - List results = p.execute(firestore).get(); - - p = - Pipeline.fromCollectionGroup("coll1") - .filter(equal(Field.of("foo"), 42)) - .filter( - or(lessThan(Field.of("bar"), 100), equal(Field.of("key"), Constant.of("value")))) - .filter(not(Constant.of(128).inAny("f1", "f2"))); - results = p.execute(firestore).get(); - } - - @Test - public void inFilters() throws Exception { - Pipeline p = Pipeline.fromCollectionGroup("coll1").filter(Field.of("foo").inAny(42, "42")); - List results = p.execute(firestore).get(); - } - - @Test - public void aggregateWithoutGrouping() throws Exception { - Pipeline p = - Pipeline.fromDatabase() - .filter(Field.of("foo").inAny(42, "bar")) - .aggregate(avg(Field.of("score")).toField("avg_score_1")); - List results = p.execute(firestore).get(); - } - - @Test - public void sorts() throws Exception { - Pipeline p = - Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny(42, "42")) - .sort( - Field.of("rank").ascending(), - cosineDistance(Field.of("embedding1"), Field.of("embedding2")).descending()) - .limit(100); - List results = p.execute(firestore).get(); - - // equivalent but more concise. - p = - Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny(42, false)) - .sort( - ascending(Field.of("rank")), - descending(cosineDistance(Field.of("embedding1"), Field.of("embedding2")))) - .limit(100); - results = p.execute(firestore).get(); - } - - @Test - public void pagination() throws Exception { - PaginatingPipeline p = - Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny(42, "bar")) - .paginate( - 100, cosineDistance(Field.of("embedding1"), Field.of("embedding2")).descending()); - - List results = p.firstPage().execute(firestore).get(); - List secondPage = - p.startAfter(results.get(results.size() - 1)).firstPage().execute(firestore).get(); - } - - @Test - public void limit() throws Exception { - Pipeline p = Pipeline.fromDatabase().filter(Field.of("foo").inAny(42, "bar")).limit(10); - - List result = p.execute(firestore).get(); - } - - @Test - public void offset() throws Exception { - Pipeline p = - Pipeline.fromDocuments(firestore.document("foo/bar1"), firestore.document("foo/bar2")) - .offset(1); - - List result = p.execute(firestore).get(); - } + // @Test + // public void projections() throws Exception { + // Pipeline p = Pipeline.fromCollectionGroup("coll1").select(Field.of("foo")); + // List results = p.execute(firestore).get(); + // System.out.println(results.size()); + // + // p = Pipeline.fromCollectionGroup("coll1").select(Fields.of("foo", "bar", "baz")); + // results = p.execute(firestore).get(); + // } + // + // @Test + // public void filters() throws Exception { + // Pipeline p = + // Pipeline.fromCollectionGroup("coll1") + // .filter(Field.of("foo").equal(42)) + // .filter(or(Field.of("bar").lessThan(100), Constant.of("value").equal(Field.of("key")))) + // .filter(not(Constant.of(128).inAny("f1", "f2"))); + // List results = p.execute(firestore).get(); + // + // p = + // Pipeline.fromCollectionGroup("coll1") + // .filter(equal(Field.of("foo"), 42)) + // .filter( + // or(lessThan(Field.of("bar"), 100), equal(Field.of("key"), Constant.of("value")))) + // .filter(not(Constant.of(128).inAny("f1", "f2"))); + // results = p.execute(firestore).get(); + // } + // + // @Test + // public void inFilters() throws Exception { + // Pipeline p = Pipeline.fromCollectionGroup("coll1").filter(Field.of("foo").inAny(42, "42")); + // List results = p.execute(firestore).get(); + // } + // + // @Test + // public void aggregateWithoutGrouping() throws Exception { + // Pipeline p = + // Pipeline.fromDatabase() + // .filter(Field.of("foo").inAny(42, "bar")) + // .aggregate(avg(Field.of("score")).toField("avg_score_1")); + // List results = p.execute(firestore).get(); + // } + // + // @Test + // public void sorts() throws Exception { + // Pipeline p = + // Pipeline.fromCollection("coll1") + // .filter(Field.of("foo").inAny(42, "42")) + // .sort( + // Field.of("rank").ascending(), + // cosineDistance(Field.of("embedding1"), Field.of("embedding2")).descending()) + // .limit(100); + // List results = p.execute(firestore).get(); + // + // // equivalent but more concise. + // p = + // Pipeline.fromCollection("coll1") + // .filter(Field.of("foo").inAny(42, false)) + // .sort( + // ascending(Field.of("rank")), + // descending(cosineDistance(Field.of("embedding1"), Field.of("embedding2")))) + // .limit(100); + // results = p.execute(firestore).get(); + // } + // + // @Test + // public void pagination() throws Exception { + // PaginatingPipeline p = + // Pipeline.fromCollection("coll1") + // .filter(Field.of("foo").inAny(42, "bar")) + // .paginate( + // 100, cosineDistance(Field.of("embedding1"), Field.of("embedding2")).descending()); + // + // List results = p.firstPage().execute(firestore).get(); + // List secondPage = + // p.startAfter(results.get(results.size() - 1)).firstPage().execute(firestore).get(); + // } + // + // @Test + // public void limit() throws Exception { + // Pipeline p = Pipeline.fromDatabase().filter(Field.of("foo").inAny(42, "bar")).limit(10); + // + // List result = p.execute(firestore).get(); + // } + // + // @Test + // public void offset() throws Exception { + // Pipeline p = + // Pipeline.fromDocuments(firestore.document("foo/bar1"), firestore.document("foo/bar2")) + // .offset(1); + // + // List result = p.execute(firestore).get(); + // } } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java index 3ddd8439b..612019996 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java @@ -82,12 +82,15 @@ public static void checkResultContainsDocuments(Query query, boolean pipelineOnl assertThat(result).isEqualTo(Arrays.asList(docs)); } + /* List pipelineResults = query.toPipeline().execute(query.getFirestore()).get(); List result = pipelineResults.stream() .map(pipelineResult -> Objects.requireNonNull(pipelineResult.getReference()).getId()) .collect(Collectors.toList()); assertThat(result).isEqualTo(Arrays.asList(docs)); + + */ } @Test @@ -613,7 +616,7 @@ public void multipleInequalityWithNestedField() throws Exception { Query query2WithCursor = query2.startAt(docSnap); checkResultContainsDocuments( query2, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", "doc3"); - checkResultContainsDocuments(query2WithCursor, "doc2", "doc3"); + // checkResultContainsDocuments(query2WithCursor, "doc2", "doc3"); } @Test @@ -907,7 +910,7 @@ public void multipleInequalityFieldsInAggregateQuery() throws Exception { if (isRunningAgainstFirestoreEmulator(firestore)) { assertThat(query.get().get().getCount()).isEqualTo(4); } - assertThat(query.toPipeline().execute(query.getQuery().getFirestore()).get()).isNotEmpty(); + // assertThat(query.toPipeline().execute(query.getQuery().getFirestore()).get()).isNotEmpty(); // TODO(MIEQ): Add sum and average when they are public. } From c2b077163de56cac298b0698e0239b7d27cab8b7 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Thu, 16 May 2024 14:26:32 -0400 Subject: [PATCH 38/65] Revert "disable failing tests temparorily" This reverts commit cfea0fda8cc3261fe4cfffe5b5f2f8c604389127. --- .../cloud/firestore/it/ITPipelineTest.java | 187 +++++++++--------- .../cloud/firestore/it/ITQueryTest.java | 7 +- 2 files changed, 96 insertions(+), 98 deletions(-) diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 7be2f404d..53b3f2bc7 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -68,99 +68,100 @@ public void fromSources() throws Exception { Pipeline p = Pipeline.fromCollectionGroup(collection.getId()); List results = p.execute(firestore).get(); + System.out.println(results.size()); } - // @Test - // public void projections() throws Exception { - // Pipeline p = Pipeline.fromCollectionGroup("coll1").select(Field.of("foo")); - // List results = p.execute(firestore).get(); - // System.out.println(results.size()); - // - // p = Pipeline.fromCollectionGroup("coll1").select(Fields.of("foo", "bar", "baz")); - // results = p.execute(firestore).get(); - // } - // - // @Test - // public void filters() throws Exception { - // Pipeline p = - // Pipeline.fromCollectionGroup("coll1") - // .filter(Field.of("foo").equal(42)) - // .filter(or(Field.of("bar").lessThan(100), Constant.of("value").equal(Field.of("key")))) - // .filter(not(Constant.of(128).inAny("f1", "f2"))); - // List results = p.execute(firestore).get(); - // - // p = - // Pipeline.fromCollectionGroup("coll1") - // .filter(equal(Field.of("foo"), 42)) - // .filter( - // or(lessThan(Field.of("bar"), 100), equal(Field.of("key"), Constant.of("value")))) - // .filter(not(Constant.of(128).inAny("f1", "f2"))); - // results = p.execute(firestore).get(); - // } - // - // @Test - // public void inFilters() throws Exception { - // Pipeline p = Pipeline.fromCollectionGroup("coll1").filter(Field.of("foo").inAny(42, "42")); - // List results = p.execute(firestore).get(); - // } - // - // @Test - // public void aggregateWithoutGrouping() throws Exception { - // Pipeline p = - // Pipeline.fromDatabase() - // .filter(Field.of("foo").inAny(42, "bar")) - // .aggregate(avg(Field.of("score")).toField("avg_score_1")); - // List results = p.execute(firestore).get(); - // } - // - // @Test - // public void sorts() throws Exception { - // Pipeline p = - // Pipeline.fromCollection("coll1") - // .filter(Field.of("foo").inAny(42, "42")) - // .sort( - // Field.of("rank").ascending(), - // cosineDistance(Field.of("embedding1"), Field.of("embedding2")).descending()) - // .limit(100); - // List results = p.execute(firestore).get(); - // - // // equivalent but more concise. - // p = - // Pipeline.fromCollection("coll1") - // .filter(Field.of("foo").inAny(42, false)) - // .sort( - // ascending(Field.of("rank")), - // descending(cosineDistance(Field.of("embedding1"), Field.of("embedding2")))) - // .limit(100); - // results = p.execute(firestore).get(); - // } - // - // @Test - // public void pagination() throws Exception { - // PaginatingPipeline p = - // Pipeline.fromCollection("coll1") - // .filter(Field.of("foo").inAny(42, "bar")) - // .paginate( - // 100, cosineDistance(Field.of("embedding1"), Field.of("embedding2")).descending()); - // - // List results = p.firstPage().execute(firestore).get(); - // List secondPage = - // p.startAfter(results.get(results.size() - 1)).firstPage().execute(firestore).get(); - // } - // - // @Test - // public void limit() throws Exception { - // Pipeline p = Pipeline.fromDatabase().filter(Field.of("foo").inAny(42, "bar")).limit(10); - // - // List result = p.execute(firestore).get(); - // } - // - // @Test - // public void offset() throws Exception { - // Pipeline p = - // Pipeline.fromDocuments(firestore.document("foo/bar1"), firestore.document("foo/bar2")) - // .offset(1); - // - // List result = p.execute(firestore).get(); - // } + @Test + public void projections() throws Exception { + Pipeline p = Pipeline.fromCollectionGroup("coll1").select(Field.of("foo")); + List results = p.execute(firestore).get(); + System.out.println(results.size()); + + p = Pipeline.fromCollectionGroup("coll1").select(Fields.of("foo", "bar", "baz")); + results = p.execute(firestore).get(); + } + + @Test + public void filters() throws Exception { + Pipeline p = + Pipeline.fromCollectionGroup("coll1") + .filter(Field.of("foo").equal(42)) + .filter(or(Field.of("bar").lessThan(100), Constant.of("value").equal(Field.of("key")))) + .filter(not(Constant.of(128).inAny("f1", "f2"))); + List results = p.execute(firestore).get(); + + p = + Pipeline.fromCollectionGroup("coll1") + .filter(equal(Field.of("foo"), 42)) + .filter( + or(lessThan(Field.of("bar"), 100), equal(Field.of("key"), Constant.of("value")))) + .filter(not(Constant.of(128).inAny("f1", "f2"))); + results = p.execute(firestore).get(); + } + + @Test + public void inFilters() throws Exception { + Pipeline p = Pipeline.fromCollectionGroup("coll1").filter(Field.of("foo").inAny(42, "42")); + List results = p.execute(firestore).get(); + } + + @Test + public void aggregateWithoutGrouping() throws Exception { + Pipeline p = + Pipeline.fromDatabase() + .filter(Field.of("foo").inAny(42, "bar")) + .aggregate(avg(Field.of("score")).toField("avg_score_1")); + List results = p.execute(firestore).get(); + } + + @Test + public void sorts() throws Exception { + Pipeline p = + Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny(42, "42")) + .sort( + Field.of("rank").ascending(), + cosineDistance(Field.of("embedding1"), Field.of("embedding2")).descending()) + .limit(100); + List results = p.execute(firestore).get(); + + // equivalent but more concise. + p = + Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny(42, false)) + .sort( + ascending(Field.of("rank")), + descending(cosineDistance(Field.of("embedding1"), Field.of("embedding2")))) + .limit(100); + results = p.execute(firestore).get(); + } + + @Test + public void pagination() throws Exception { + PaginatingPipeline p = + Pipeline.fromCollection("coll1") + .filter(Field.of("foo").inAny(42, "bar")) + .paginate( + 100, cosineDistance(Field.of("embedding1"), Field.of("embedding2")).descending()); + + List results = p.firstPage().execute(firestore).get(); + List secondPage = + p.startAfter(results.get(results.size() - 1)).firstPage().execute(firestore).get(); + } + + @Test + public void limit() throws Exception { + Pipeline p = Pipeline.fromDatabase().filter(Field.of("foo").inAny(42, "bar")).limit(10); + + List result = p.execute(firestore).get(); + } + + @Test + public void offset() throws Exception { + Pipeline p = + Pipeline.fromDocuments(firestore.document("foo/bar1"), firestore.document("foo/bar2")) + .offset(1); + + List result = p.execute(firestore).get(); + } } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java index 612019996..3ddd8439b 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java @@ -82,15 +82,12 @@ public static void checkResultContainsDocuments(Query query, boolean pipelineOnl assertThat(result).isEqualTo(Arrays.asList(docs)); } - /* List pipelineResults = query.toPipeline().execute(query.getFirestore()).get(); List result = pipelineResults.stream() .map(pipelineResult -> Objects.requireNonNull(pipelineResult.getReference()).getId()) .collect(Collectors.toList()); assertThat(result).isEqualTo(Arrays.asList(docs)); - - */ } @Test @@ -616,7 +613,7 @@ public void multipleInequalityWithNestedField() throws Exception { Query query2WithCursor = query2.startAt(docSnap); checkResultContainsDocuments( query2, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", "doc3"); - // checkResultContainsDocuments(query2WithCursor, "doc2", "doc3"); + checkResultContainsDocuments(query2WithCursor, "doc2", "doc3"); } @Test @@ -910,7 +907,7 @@ public void multipleInequalityFieldsInAggregateQuery() throws Exception { if (isRunningAgainstFirestoreEmulator(firestore)) { assertThat(query.get().get().getCount()).isEqualTo(4); } - // assertThat(query.toPipeline().execute(query.getQuery().getFirestore()).get()).isNotEmpty(); + assertThat(query.toPipeline().execute(query.getQuery().getFirestore()).get()).isNotEmpty(); // TODO(MIEQ): Add sum and average when they are public. } From bb16ca128cec4abdc3718ab65622ce344eb9fc5f Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Tue, 21 May 2024 10:33:09 -0400 Subject: [PATCH 39/65] Fix missing asAlias --- .../com/google/cloud/firestore/pipeline/Expressions.kt | 6 ++++++ .../java/com/google/cloud/firestore/pipeline/Stages.kt | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index 9ce8210ef..5923f487c 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -49,6 +49,8 @@ internal fun exprToValue(expr: Expr): Value { interface Projectable +internal class ExprWithAlias internal constructor(val alias: String, val expr: Expr) : Projectable + interface Expr { // Infix functions returning Function subclasses infix fun equal(other: Expr) = Equal(this, other) @@ -143,6 +145,10 @@ interface Expr { fun descending(): Ordering { return Ordering(this, Direction.DESCENDING) } + + fun asAlias(alias: String): Projectable { + return ExprWithAlias(alias, this) + } } // Convenient class for internal usage diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt index 43f72d2a9..f8f540b10 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt @@ -104,10 +104,15 @@ internal constructor( } } - class FindNearestOptions(val limit: Long, val output: Field? = null) { + class FindNearestOptions internal constructor( + val limit: Long, + val distanceMeasure: DistanceMeasure, + val output: Field? = null + ) { companion object { @JvmStatic - fun newInstance(limit: Long, output: Field? = null) = FindNearestOptions(limit, output) + fun newInstance(limit: Long, distanceMeasure: DistanceMeasure, output: Field? = null) = + FindNearestOptions(limit, distanceMeasure, output) } } } From 424cf8bc6f6564b97e3320df587dcc008a480e74 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Tue, 21 May 2024 10:48:05 -0400 Subject: [PATCH 40/65] Rename project to select --- .../java/com/google/cloud/firestore/Pipeline.kt | 14 +++++++------- .../java/com/google/cloud/firestore/Query.java | 4 ++-- .../google/cloud/firestore/pipeline/Expressions.kt | 12 ++++++------ .../com/google/cloud/firestore/pipeline/Stages.kt | 6 +++--- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index cc2c2342b..aeb3e6709 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -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 @@ -173,9 +173,9 @@ class Pipeline private constructor(private val stages: List, private val } } - private fun projectablesToMap(vararg projectables: Projectable): Map { + private fun projectablesToMap(vararg selectables: Selectable): Map { val projMap = mutableMapOf() - for (proj in projectables) { + for (proj in selectables) { when (proj) { is Field -> projMap[proj.field] = proj is AggregatorTarget -> projMap[proj.fieldName] = proj.accumulator @@ -185,12 +185,12 @@ class Pipeline private constructor(private val stages: List, 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 filter(condition: T): Pipeline where T : Expr, T : Function.FilterCondition { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index 914f665b9..b6f65678c 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -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; @@ -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 diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index 5923f487c..b58941dee 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -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 @@ -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) } } @@ -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__" @@ -272,7 +272,7 @@ data class Field internal constructor( } } -data class Fields internal constructor(internal val fs: List? = null) : Expr, Projectable { +data class Fields internal constructor(internal val fs: List? = null) : Expr, Selectable { companion object { @JvmStatic fun of(f1: String, vararg f: String): Fields { @@ -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 { interface FilterCondition : Expr diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt index f8f540b10..350d1a776 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt @@ -31,8 +31,8 @@ internal data class Documents(internal val documents: List) : Stage { } } -internal data class Project(internal val projections: Map) : Stage { - val name = "project" +internal data class Select(internal val projections: Map) : Stage { + val name = "select" } internal data class AddFields(internal val fields: Map) : Stage { @@ -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)) From 8bc968fe901410c39c22d15ce0c5cee2fa8f978d Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Wed, 22 May 2024 11:25:10 -0400 Subject: [PATCH 41/65] fix countAll --- .../main/java/com/google/cloud/firestore/PipelineUtils.kt | 1 + .../java/com/google/cloud/firestore/pipeline/Expressions.kt | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.kt index 397300bf4..6c9d188bc 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.kt @@ -9,6 +9,7 @@ import com.google.cloud.firestore.pipeline.AggregatorTarget import com.google.cloud.firestore.pipeline.Constant import com.google.cloud.firestore.pipeline.Field import com.google.cloud.firestore.pipeline.Function +import com.google.cloud.firestore.pipeline.Function.Companion.count import com.google.cloud.firestore.pipeline.Function.Companion.countAll import com.google.cloud.firestore.pipeline.Function.Companion.not import com.google.firestore.v1.Cursor diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index b58941dee..2020d3256 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -120,9 +120,9 @@ interface Expr { fun count() = Count(this, false) - fun min() = Count(this, false) + fun min() = Function.Min(this, false) - fun max() = Count(this, false) + fun max() = Function.Max(this, false) infix fun cosineDistance(other: Expr) = CosineDistance(this, other) @@ -502,7 +502,7 @@ open class Function(val name: String, val params: List) : Expr { @JvmStatic fun max(expr: Expr) = Avg(expr, false) - @JvmStatic fun countAll(expr: Expr) = Count(expr, false) + @JvmStatic fun count(expr: Expr) = Count(expr, false) @JvmStatic fun countAll() = Count(null, false) From 8c864f7057f91f3a6838d3c13fa1cdf24fd6b45f Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Mon, 27 May 2024 11:41:07 -0400 Subject: [PATCH 42/65] order normalization and field unify --- .../com/google/cloud/firestore/Pipeline.kt | 4 +- .../google/cloud/firestore/PipelineResult.kt | 17 ++ .../com/google/cloud/firestore/Query.java | 5 +- .../cloud/firestore/pipeline/Expressions.kt | 11 +- .../cloud/firestore/it/ITQueryTest.java | 156 ++++++++++-------- 5 files changed, 117 insertions(+), 76 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt index aeb3e6709..b13f715d8 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt @@ -177,9 +177,9 @@ class Pipeline private constructor(private val stages: List, private val val projMap = mutableMapOf() for (proj in selectables) { when (proj) { - is Field -> projMap[proj.field] = proj + is Field -> projMap[proj.path.encodedPath] = proj is AggregatorTarget -> projMap[proj.fieldName] = proj.accumulator - is Fields -> proj.fs?.forEach { projMap[it.field] = it } + is Fields -> proj.fs?.forEach { projMap[it.path.encodedPath] = it } } } return projMap diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt index 6cebcfc46..c8c09487e 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt @@ -1,6 +1,7 @@ package com.google.cloud.firestore import com.google.cloud.Timestamp +import com.google.cloud.firestore.pipeline.Field import com.google.firestore.v1.Document import com.google.firestore.v1.Value import java.util.Date @@ -76,6 +77,10 @@ internal constructor( return this.extractField(fieldPath) != null } + fun contains(field: Field): Boolean { + return this.extractField(field.path) != null + } + fun get(field: String): Any? { return get(FieldPath.fromDotSeparatedString(field)) } @@ -90,12 +95,20 @@ internal constructor( return UserDataConverter.decodeValue(rpcContext, value) } + fun get(field: Field): Any? { + return get(field.path) + } + fun get(fieldPath: FieldPath, valueType: Class): T? { val data = get(fieldPath) return if (data == null) null else CustomClassMapper.convertToCustomClass(data, valueType, reference) } + fun get(field: Field, valueType: Class): T? { + return get(field.path, valueType) + } + fun extractField(fieldPath: FieldPath): Value? { var value: Value? = null @@ -114,6 +127,10 @@ internal constructor( return value } + fun extractField(field: Field): Value? { + return extractField(field.path) + } + fun getBoolean(field: String): Boolean? { return get(field) as Boolean? } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index b6f65678c..be9bb85b2 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -1997,9 +1997,10 @@ public Pipeline toPipeline() { } // Orders - if (this.options.getFieldOrders() != null && !this.options.getFieldOrders().isEmpty()) { + List normalizedOrderbys = this.createImplicitOrderBy(); + if (normalizedOrderbys != null && !normalizedOrderbys.isEmpty()) { List orders = - this.options.getFieldOrders().stream() + normalizedOrderbys.stream() .map( fieldOrder -> Ordering.of( diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index 2020d3256..91185cf06 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -3,6 +3,7 @@ package com.google.cloud.firestore.pipeline import com.google.cloud.Timestamp import com.google.cloud.firestore.Blob import com.google.cloud.firestore.DocumentReference +import com.google.cloud.firestore.FieldPath import com.google.cloud.firestore.GeoPoint import com.google.cloud.firestore.Pipeline import com.google.cloud.firestore.encodeValue @@ -249,26 +250,26 @@ data class Constant internal constructor(private val value: Any?) : Expr { } data class Field internal constructor( - internal val field: String, + internal val path: FieldPath, private var pipeline: Pipeline? = null ) : Expr, Selectable { companion object { - const val DOCUMENT_ID: String = "__path__" + const val DOCUMENT_ID: String = "__name__" @JvmStatic fun of(path: String): Field { - return Field(path) + return Field(FieldPath.of(path)) } @JvmStatic fun ofAll(): Field { - return Field("") + return Field(FieldPath.of("")) } } internal fun toProto(): Value { - return Value.newBuilder().setFieldReferenceValue(field).build() + return Value.newBuilder().setFieldReferenceValue(path.toString()).build() } } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java index 3ddd8439b..f3ac2cc5e 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java @@ -22,12 +22,14 @@ import com.google.cloud.firestore.*; import com.google.cloud.firestore.Query.Direction; +import com.google.common.collect.Sets; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -66,12 +68,13 @@ public CollectionReference testCollectionWithDocs(Map result = + snapshot.getDocuments().stream() + .map(queryDocumentSnapshot -> queryDocumentSnapshot.getReference().getId()) + .collect(Collectors.toSet()); + assertThat(result).isEqualTo(Sets.newHashSet(docs)); + } + + List pipelineResults = query.toPipeline().execute(query.getFirestore()).get(); + Set result = + pipelineResults.stream() + .map(pipelineResult -> Objects.requireNonNull(pipelineResult.getReference()).getId()) + .collect(Collectors.toSet()); + assertThat(result).isEqualTo(Sets.newHashSet(docs)); + } + @Test public void orQueries() throws Exception { Map> testDocs = @@ -103,7 +125,7 @@ public void orQueries() throws Exception { CollectionReference collection = testCollectionWithDocs(testDocs); // Two equalities: a==1 || b==1. - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( collection.where(Filter.or(Filter.equalTo("a", 1), Filter.equalTo("b", 1))), "doc1", "doc2", @@ -111,7 +133,7 @@ public void orQueries() throws Exception { "doc5"); // (a==1 && b==0) || (a==3 && b==2) - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( collection.where( Filter.or( Filter.and(Filter.equalTo("a", 1), Filter.equalTo("b", 0)), @@ -120,7 +142,7 @@ public void orQueries() throws Exception { "doc3"); // a==1 && (b==0 || b==3). - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( collection.where( Filter.and( Filter.equalTo("a", 1), Filter.or(Filter.equalTo("b", 0), Filter.equalTo("b", 3)))), @@ -128,7 +150,7 @@ public void orQueries() throws Exception { "doc4"); // (a==2 || b==2) && (a==3 || b==3) - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( collection.where( Filter.and( Filter.or(Filter.equalTo("a", 2), Filter.equalTo("b", 2)), @@ -136,7 +158,7 @@ public void orQueries() throws Exception { "doc3"); // Test with limits without orderBy (the __name__ ordering is the tiebreaker). - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( collection.where(Filter.or(Filter.equalTo("a", 2), Filter.equalTo("b", 1))).limit(1), "doc2"); } @@ -162,7 +184,7 @@ public void orQueriesWithCompositeIndexes() throws Exception { "doc3"); // Test with limits (implicit order by ASC): (a==1) || (b > 0) LIMIT 2 - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( collection.where(Filter.or(Filter.equalTo("a", 1), Filter.greaterThan("b", 0))).limit(2), /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc1", @@ -170,7 +192,7 @@ public void orQueriesWithCompositeIndexes() throws Exception { // Test with limits (explicit order by): (a==1) || (b > 0) LIMIT_TO_LAST 2 // Note: The public query API does not allow implicit ordering when limitToLast is used. - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( collection .where(Filter.or(Filter.equalTo("a", 1), Filter.greaterThan("b", 0))) .limitToLast(2) @@ -180,7 +202,7 @@ public void orQueriesWithCompositeIndexes() throws Exception { "doc4"); // Test with limits (explicit order by ASC): (a==2) || (b == 1) ORDER BY a LIMIT 1 - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( collection .where(Filter.or(Filter.equalTo("a", 2), Filter.equalTo("b", 1))) .limit(1) @@ -189,7 +211,7 @@ public void orQueriesWithCompositeIndexes() throws Exception { "doc5"); // Test with limits (explicit order by DESC): (a==2) || (b == 1) ORDER BY a LIMIT_TO_LAST 1 - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( collection .where(Filter.or(Filter.equalTo("a", 2), Filter.equalTo("b", 1))) .limitToLast(1) @@ -198,7 +220,7 @@ public void orQueriesWithCompositeIndexes() throws Exception { "doc2"); // Test with limits (explicit order by DESC): (a==2) || (b == 1) ORDER BY a DESC LIMIT 1 - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( collection .where(Filter.or(Filter.equalTo("a", 2), Filter.equalTo("b", 1))) .limit(1) @@ -224,7 +246,7 @@ public void orQueryDoesNotIncludeDocumentsWithMissingFields() throws Exception { // There's no explicit nor implicit orderBy. Documents with missing 'a' or missing 'b' should be // allowed if the document matches at least one disjunction term. Query query = collection.where(Filter.or(Filter.equalTo("a", 1), Filter.equalTo("b", 1))); - checkResultContainsDocuments(query, "doc1", "doc2", "doc4", "doc5"); + checkResultContainsDocumentsInOrder(query, "doc1", "doc2", "doc4", "doc5"); } @Test @@ -244,7 +266,7 @@ public void orQueryDoesNotIncludeDocumentsWithMissingFields2() throws Exception // doc2 should not be included because it's missing the field 'a', and we have "orderBy a". Query query1 = collection.where(Filter.or(Filter.equalTo("a", 1), Filter.equalTo("b", 1))).orderBy("a"); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query1, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc1", @@ -255,7 +277,7 @@ public void orQueryDoesNotIncludeDocumentsWithMissingFields2() throws Exception // doc5 should not be included because it's missing the field 'b', and we have "orderBy b". Query query2 = collection.where(Filter.or(Filter.equalTo("a", 1), Filter.equalTo("b", 1))).orderBy("b"); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query2, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc1", @@ -266,7 +288,7 @@ public void orQueryDoesNotIncludeDocumentsWithMissingFields2() throws Exception // This query has an implicit 'order by a'. // doc2 should not be included because it's missing the field 'a'. Query query3 = collection.where(Filter.or(Filter.greaterThan("a", 2), Filter.equalTo("b", 1))); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query3, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc3"); // Query: a>1 || b==1 order by a order by b. @@ -277,7 +299,7 @@ public void orQueryDoesNotIncludeDocumentsWithMissingFields2() throws Exception .where(Filter.or(Filter.greaterThan("a", 1), Filter.equalTo("b", 1))) .orderBy("a") .orderBy("b"); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query4, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc3"); } @@ -294,7 +316,7 @@ public void orQueriesWithIn() throws ExecutionException, InterruptedException, T CollectionReference collection = testCollectionWithDocs(testDocs); // a==2 || b in [2,3] - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( collection.where(Filter.or(Filter.equalTo("a", 2), Filter.inArray("b", asList(2, 3)))), "doc3", "doc4", @@ -316,7 +338,7 @@ public void orQueriesWithNotIn() // a==2 || b not-in [2,3] // Has implicit orderBy b. - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( collection.where(Filter.or(Filter.equalTo("a", 2), Filter.notInArray("b", asList(2, 3)))), /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc1", @@ -337,14 +359,14 @@ public void orQueriesWithArrayMembership() CollectionReference collection = testCollectionWithDocs(testDocs); // a==2 || b array-contains 7 - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( collection.where(Filter.or(Filter.equalTo("a", 2), Filter.arrayContains("b", 7))), "doc3", "doc4", "doc6"); // a==2 || b array-contains-any [0, 3] - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( collection.where( Filter.or(Filter.equalTo("a", 2), Filter.arrayContainsAny("b", asList(0, 3)))), "doc1", @@ -368,26 +390,26 @@ public void testUsingInWithArrayContains() Query query1 = collection.where( Filter.or(Filter.inArray("a", asList(2, 3)), Filter.arrayContains("b", 3))); - checkResultContainsDocuments(query1, "doc3", "doc4", "doc6"); + checkResultContainsDocumentsInOrder(query1, "doc3", "doc4", "doc6"); Query query2 = collection.where( Filter.and(Filter.inArray("a", asList(2, 3)), Filter.arrayContains("b", 7))); - checkResultContainsDocuments(query2, "doc3"); + checkResultContainsDocumentsInOrder(query2, "doc3"); Query query3 = collection.where( Filter.or( Filter.inArray("a", asList(2, 3)), Filter.and(Filter.arrayContains("b", 3), Filter.equalTo("a", 1)))); - checkResultContainsDocuments(query3, "doc3", "doc4", "doc6"); + checkResultContainsDocumentsInOrder(query3, "doc3", "doc4", "doc6"); Query query4 = collection.where( Filter.and( Filter.inArray("a", asList(2, 3)), Filter.or(Filter.arrayContains("b", 7), Filter.equalTo("a", 1)))); - checkResultContainsDocuments(query4, "doc3"); + checkResultContainsDocumentsInOrder(query4, "doc3"); } @Test @@ -404,7 +426,7 @@ public void testOrderByEquality() CollectionReference collection = testCollectionWithDocs(testDocs); Query query1 = collection.where(Filter.equalTo("a", 1)).orderBy("a"); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query1, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc1", @@ -412,7 +434,7 @@ public void testOrderByEquality() "doc5"); Query query2 = collection.where(Filter.inArray("a", asList(2, 3))).orderBy("a"); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query2, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc6", "doc3"); } @@ -432,7 +454,7 @@ public void multipleInequalityOnDifferentFields() throws Exception { .whereNotEqualTo("key", "a") .whereLessThanOrEqualTo("sort", 2) .whereGreaterThan("v", 2); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query1, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc3"); // Duplicate inequality fields @@ -441,7 +463,7 @@ public void multipleInequalityOnDifferentFields() throws Exception { .whereNotEqualTo("key", "a") .whereLessThanOrEqualTo("sort", 2) .whereGreaterThan("sort", 1); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query2, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc4"); // With multiple IN @@ -451,7 +473,7 @@ public void multipleInequalityOnDifferentFields() throws Exception { .whereLessThanOrEqualTo("sort", 2) .whereIn("v", asList(2, 3, 4)) .whereIn("sort", asList(2, 3)); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query3, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc4"); // With NOT-IN @@ -460,7 +482,7 @@ public void multipleInequalityOnDifferentFields() throws Exception { .whereGreaterThanOrEqualTo("key", "a") .whereLessThanOrEqualTo("sort", 2) .whereNotIn("v", asList(2, 4, 5)); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query4, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc1", "doc3"); // With orderby @@ -469,7 +491,7 @@ public void multipleInequalityOnDifferentFields() throws Exception { .whereGreaterThanOrEqualTo("key", "a") .whereLessThanOrEqualTo("sort", 2) .orderBy("v", Direction.DESCENDING); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query5, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc3", @@ -483,7 +505,7 @@ public void multipleInequalityOnDifferentFields() throws Exception { .whereLessThanOrEqualTo("sort", 2) .orderBy("v", Direction.DESCENDING) .limit(2); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query6, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc3", "doc4"); // With limitToLast @@ -493,7 +515,7 @@ public void multipleInequalityOnDifferentFields() throws Exception { .whereLessThanOrEqualTo("sort", 2) .orderBy("v", Direction.DESCENDING) .limitToLast(2); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query7, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc4", "doc1"); } @@ -510,7 +532,7 @@ public void multipleInequalityOnSpecialValues() throws Exception { "doc6", map("key", "f", "sort", 1, "v", 1))); Query query1 = collection.whereNotEqualTo("key", "a").whereLessThanOrEqualTo("sort", 2); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query1, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc5", "doc6"); Query query2 = @@ -518,7 +540,7 @@ public void multipleInequalityOnSpecialValues() throws Exception { .whereNotEqualTo("key", "a") .whereLessThanOrEqualTo("sort", 2) .whereLessThanOrEqualTo("v", 1); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query2, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc6"); } @@ -547,7 +569,7 @@ public void multipleInequalityWithArrayMembership() throws Exception { .whereNotEqualTo("key", "a") .whereGreaterThanOrEqualTo("sort", 1) .whereArrayContains("v", 0); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query1, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2"); Query query2 = @@ -555,7 +577,7 @@ public void multipleInequalityWithArrayMembership() throws Exception { .whereNotEqualTo("key", "a") .whereGreaterThanOrEqualTo("sort", 1) .whereArrayContainsAny("v", asList(0, 1)); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query2, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", "doc4"); } @@ -594,9 +616,9 @@ public void multipleInequalityWithNestedField() throws Exception { .orderBy("name"); DocumentSnapshot docSnap = collection.document("doc4").get().get(); Query query1WithCursor = query1.startAt(docSnap); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query1, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc4", "doc1"); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query1WithCursor, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc4", @@ -611,9 +633,9 @@ public void multipleInequalityWithNestedField() throws Exception { .orderBy("name", Direction.DESCENDING); docSnap = collection.document("doc2").get().get(); Query query2WithCursor = query2.startAt(docSnap); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query2, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", "doc3"); - checkResultContainsDocuments(query2WithCursor, "doc2", "doc3"); + checkResultContainsDocumentsInOrder(query2WithCursor, "doc2", "doc3"); } @Test @@ -642,14 +664,14 @@ public void multipleInequalityWithCompositeFilters() throws Exception { Filter.and(Filter.notEqualTo("key", "b"), Filter.greaterThan("v", 4)))); DocumentSnapshot docSnap = collection.document("doc1").get().get(); Query query1WithCursor = query1.startAt(docSnap); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query1, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc1", "doc6", "doc5", "doc4"); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query1WithCursor, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc1", @@ -668,14 +690,14 @@ public void multipleInequalityWithCompositeFilters() throws Exception { .orderBy("key"); docSnap = collection.document("doc5").get().get(); Query query2WithCursor = query2.startAt(docSnap); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query2, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc5", "doc4", "doc1", "doc6"); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query2WithCursor, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc5", @@ -696,9 +718,9 @@ public void multipleInequalityWithCompositeFilters() throws Exception { Filter.and(Filter.lessThan("key", "b"), Filter.greaterThan("v", 0))))); docSnap = collection.document("doc1").get().get(); Query query3WithCursor = query3.startAt(docSnap); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query3, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc1", "doc2"); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query3WithCursor, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc1", @@ -733,14 +755,14 @@ public void multipleInequalityFieldsWillBeImplicitlyOrderedLexicographicallyBySe .whereGreaterThan("sort", 1) .whereIn("v", asList(1, 2, 3, 4)); Query query1WithCursor = query1.startAt(docSnap); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query1, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", "doc4", "doc5", "doc3"); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query1WithCursor, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", @@ -755,14 +777,14 @@ public void multipleInequalityFieldsWillBeImplicitlyOrderedLexicographicallyBySe .whereNotEqualTo("key", "a") .whereIn("v", asList(1, 2, 3, 4)); Query query2WithCursor = query2.startAt(docSnap); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query2, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", "doc4", "doc5", "doc3"); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query2WithCursor, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", @@ -795,14 +817,14 @@ public void multipleInequalityWithMultipleExplicitOrderBy() throws Exception { Query query1 = collection.whereGreaterThan("key", "a").whereGreaterThanOrEqualTo("sort", 1).orderBy("v"); Query query1WithCursor = query1.startAt(docSnap); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query1, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", "doc4", "doc3", "doc5"); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query1WithCursor, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", @@ -818,14 +840,14 @@ public void multipleInequalityWithMultipleExplicitOrderBy() throws Exception { .orderBy("v") .orderBy("sort"); Query query2WithCursor = query2.startAt(docSnap); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query2, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", "doc5", "doc4", "doc3"); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query2WithCursor, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", @@ -843,14 +865,14 @@ public void multipleInequalityWithMultipleExplicitOrderBy() throws Exception { .whereGreaterThanOrEqualTo("sort", 1) .orderBy("v", Direction.DESCENDING); Query query3WithCursor = query3.startAt(docSnap); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query3, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc5", "doc3", "doc4", "doc2"); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query3WithCursor, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc5", @@ -866,14 +888,14 @@ public void multipleInequalityWithMultipleExplicitOrderBy() throws Exception { .orderBy("v", Direction.DESCENDING) .orderBy("sort"); Query query4WithCursor = query4.startAt(docSnap); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query4, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc5", "doc4", "doc3", "doc2"); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query4WithCursor, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc5", @@ -937,13 +959,13 @@ public void multipleInequalityFieldsWithDocumentKey() throws Exception { .whereNotEqualTo("key", "a") .whereLessThan(FieldPath.documentId(), "doc5"); Query query1WithCursor = query1.startAt(docSnap); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query1, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", "doc4", "doc3"); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query1WithCursor, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", @@ -958,13 +980,13 @@ public void multipleInequalityFieldsWithDocumentKey() throws Exception { .whereGreaterThan("sort", 1) .whereNotEqualTo("key", "a"); Query query2WithCursor = query2.startAt(docSnap); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query2, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", "doc4", "doc3"); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query2WithCursor, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", @@ -979,13 +1001,13 @@ public void multipleInequalityFieldsWithDocumentKey() throws Exception { .whereNotEqualTo("key", "a") .orderBy("sort", Direction.DESCENDING); Query query3WithCursor = query3.startAt(docSnap); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query3, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", "doc3", "doc4"); - checkResultContainsDocuments( + checkResultContainsDocumentsInOrder( query3WithCursor, /*pipelineOnly*/ !isRunningAgainstFirestoreEmulator(firestore), "doc2", From a79e8a7c84046277060e0d60de487a1e61ad726e Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 27 May 2024 15:43:52 +0000 Subject: [PATCH 43/65] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 050eb8250..b0b3e92a3 100644 --- a/README.md +++ b/README.md @@ -50,20 +50,20 @@ If you are using Maven without the BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies: ```Groovy -implementation platform('com.google.cloud:libraries-bom:26.37.0') +implementation platform('com.google.cloud:libraries-bom:26.39.0') implementation 'com.google.cloud:google-cloud-firestore' ``` If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-firestore:3.20.0' +implementation 'com.google.cloud:google-cloud-firestore:3.21.3' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-firestore" % "3.20.0" +libraryDependencies += "com.google.cloud" % "google-cloud-firestore" % "3.21.3" ``` @@ -222,7 +222,7 @@ Java is a registered trademark of Oracle and/or its affiliates. [kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-firestore/java11.html [stability-image]: https://img.shields.io/badge/stability-stable-green [maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-firestore.svg -[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-firestore/3.20.0 +[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-firestore/3.21.3 [authentication]: https://github.com/googleapis/google-cloud-java#authentication [auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes [predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles From 93135a8d1542d31b0b1e06c0d94c43acdafb1aed Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Wed, 29 May 2024 14:20:40 -0400 Subject: [PATCH 44/65] Add jvmfile name and string as field heuristics --- CONTRIBUTING.md | 2 +- .../cloud/firestore/AggregateQuery.java | 2 +- .../google/cloud/firestore/PipelineResult.kt | 3 + .../google/cloud/firestore/PipelineUtils.kt | 2 +- .../firestore/{Pipeline.kt => Pipelines.kt} | 15 ++- .../com/google/cloud/firestore/Query.java | 4 +- .../cloud/firestore/UserDataConverter.java | 2 +- .../cloud/firestore/pipeline/Expressions.kt | 113 ++++++++++++++++++ .../google/cloud/firestore/pipeline/Stages.kt | 1 + 9 files changed, 137 insertions(+), 7 deletions(-) rename google-cloud-firestore/src/main/java/com/google/cloud/firestore/{Pipeline.kt => Pipelines.kt} (96%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b65dd279c..4f74815c0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -89,4 +89,4 @@ mvn com.coveo:fmt-maven-plugin:format [1]: https://cloud.google.com/docs/authentication/getting-started#creating_a_service_account [2]: https://maven.apache.org/settings.html#Active_Profiles -[3]: https://github.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md \ No newline at end of file +[3]: https://github.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java index 1d51219a9..5e2c5f673 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java @@ -72,7 +72,7 @@ public Pipeline toPipeline() { .toPipeline() .aggregate( this.aggregateFieldList.stream() - .map(PipelineUtilsKt::toPipelineAggregatorTarget) + .map(PipelineUtils::toPipelineAggregatorTarget) .toArray(AggregatorTarget[]::new)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt index c8c09487e..6df882e09 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt @@ -7,6 +7,9 @@ import com.google.firestore.v1.Value import java.util.Date import javax.annotation.Nonnull +/** + * Result from a {@code Pipeline} execution. + */ class PipelineResult internal constructor( private val rpcContext: FirestoreRpcContext<*>?, diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.kt index 6c9d188bc..e0023f041 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.kt @@ -1,3 +1,4 @@ +@file:JvmName("PipelineUtils") package com.google.cloud.firestore import com.google.cloud.firestore.Query.ComparisonFilterInternal @@ -9,7 +10,6 @@ import com.google.cloud.firestore.pipeline.AggregatorTarget import com.google.cloud.firestore.pipeline.Constant import com.google.cloud.firestore.pipeline.Field import com.google.cloud.firestore.pipeline.Function -import com.google.cloud.firestore.pipeline.Function.Companion.count import com.google.cloud.firestore.pipeline.Function.Companion.countAll import com.google.cloud.firestore.pipeline.Function.Companion.not import com.google.firestore.v1.Cursor diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipelines.kt similarity index 96% rename from google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt rename to google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipelines.kt index b13f715d8..6d4ef8341 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipelines.kt @@ -1,3 +1,4 @@ +@file:JvmName("Pipelines") package com.google.cloud.firestore import com.google.api.core.ApiFuture @@ -185,6 +186,14 @@ class Pipeline private constructor(private val stages: List, private val return projMap } + private fun fieldNamesToMap(vararg fields: String): Map { + val projMap = mutableMapOf() + for (field in fields) { + projMap[field] = Field.of(field) + } + return projMap + } + fun addFields(vararg fields: Selectable): Pipeline { return Pipeline(stages.plus(AddFields(projectablesToMap(*fields))), name) } @@ -193,6 +202,10 @@ class Pipeline private constructor(private val stages: List, private val return Pipeline(stages.plus(Select(projectablesToMap(*projections))), name) } + fun select(vararg fields: String): Pipeline { + return Pipeline(stages.plus(Select(fieldNamesToMap(*fields))), name) + } + fun filter(condition: T): Pipeline where T : Expr, T : Function.FilterCondition { return Pipeline(stages.plus(Filter(condition)), name) } @@ -234,7 +247,7 @@ class Pipeline private constructor(private val stages: List, private val return PaginatingPipeline(this, pageSize, orders.toList()) } - fun genericOperation(name: String, params: Map? = null): Pipeline { + fun genericStage(name: String, params: Map? = null): Pipeline { return this } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index 76dd1a7fb..15ed4cf65 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -16,8 +16,8 @@ package com.google.cloud.firestore; -import static com.google.cloud.firestore.PipelineUtilsKt.toPaginatedPipeline; -import static com.google.cloud.firestore.PipelineUtilsKt.toPipelineFilterCondition; +import static com.google.cloud.firestore.PipelineUtils.toPaginatedPipeline; +import static com.google.cloud.firestore.PipelineUtils.toPipelineFilterCondition; import static com.google.common.collect.Lists.reverse; import static com.google.firestore.v1.StructuredQuery.FieldFilter.Operator.ARRAY_CONTAINS; import static com.google.firestore.v1.StructuredQuery.FieldFilter.Operator.ARRAY_CONTAINS_ANY; diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java index 072274bd6..1f077f756 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java @@ -16,7 +16,7 @@ package com.google.cloud.firestore; -import static com.google.cloud.firestore.pipeline.ExpressionsKt.exprToValue; +import static com.google.cloud.firestore.pipeline.Expressions.exprToValue; import com.google.cloud.Timestamp; import com.google.cloud.firestore.pipeline.Expr; diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt index 91185cf06..b4f6ce449 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt @@ -1,3 +1,4 @@ +@file:JvmName("Expressions") package com.google.cloud.firestore.pipeline import com.google.cloud.Timestamp @@ -414,28 +415,56 @@ open class Function(val name: String, val params: List) : Expr { @JvmStatic fun equal(left: Expr, right: Any) = Equal(left, Constant.of(right)) + @JvmStatic + fun equal(left: String, right: Expr) = Equal(Field.of(left), right) + + @JvmStatic + fun equal(left: String, right: Any) = Equal(Field.of(left), Constant.of(right)) + @JvmStatic fun notEqual(left: Expr, right: Expr) = NotEqual(left, right) @JvmStatic fun notEqual(left: Expr, right: Any) = NotEqual(left, Constant.of(right)) + @JvmStatic fun notEqual(left: String, right: Expr) = NotEqual(Field.of(left), right) + + @JvmStatic fun notEqual(left: String, right: Any) = NotEqual(Field.of(left), Constant.of(right)) + @JvmStatic fun greaterThan(left: Expr, right: Expr) = GreaterThan(left, right) @JvmStatic fun greaterThan(left: Expr, right: Any) = GreaterThan(left, Constant.of(right)) + @JvmStatic fun greaterThan(left: String, right: Expr) = GreaterThan(Field.of(left), right) + + @JvmStatic fun greaterThan(left: String, right: Any) = GreaterThan(Field.of(left), Constant.of(right)) + @JvmStatic fun greaterThanOrEqual(left: Expr, right: Expr) = GreaterThanOrEqual(left, right) @JvmStatic fun greaterThanOrEqual(left: Expr, right: Any) = GreaterThanOrEqual(left, Constant.of(right)) + @JvmStatic fun greaterThanOrEqual(left: String, right: Expr) = GreaterThanOrEqual(Field.of(left), right) + + @JvmStatic + fun greaterThanOrEqual(left: String, right: Any) = GreaterThanOrEqual(Field.of(left), Constant.of(right)) + @JvmStatic fun lessThan(left: Expr, right: Expr) = LessThan(left, right) @JvmStatic fun lessThan(left: Expr, right: Any) = LessThan(left, Constant.of(right)) + @JvmStatic fun lessThan(left: String, right: Expr) = LessThan(Field.of(left), right) + + @JvmStatic fun lessThan(left: String, right: Any) = LessThan(Field.of(left), Constant.of(right)) + @JvmStatic fun lessThanOrEqual(left: Expr, right: Expr) = LessThanOrEqual(left, right) @JvmStatic fun lessThanOrEqual(left: Expr, right: Any) = LessThanOrEqual(left, Constant.of(right)) + @JvmStatic fun lessThanOrEqual(left: String, right: Expr) = LessThanOrEqual(Field.of(left), right) + + @JvmStatic + fun lessThanOrEqual(left: String, right: Any) = LessThanOrEqual(Field.of(left), Constant.of(right)) + @JvmStatic fun inAny(left: Expr, values: List) = In( @@ -448,6 +477,18 @@ open class Function(val name: String, val params: List) : Expr { }, ) + @JvmStatic + fun inAny(left: String, values: List) = + In( + Field.of(left), + values.map { + when (it) { + is Expr -> it + else -> Constant.of(it) + } + }, + ) + @JvmStatic fun notInAny(left: Expr, values: List) = Not( @@ -462,6 +503,21 @@ open class Function(val name: String, val params: List) : Expr { ) ) + @JvmStatic + fun notInAny(left: String, values: List) = + Not( + In( + Field.of(left), + values.map { + when (it) { + is Expr -> it + else -> Constant.of(it) + } + }, + ) + ) + + @JvmStatic fun and(left: T, right: T) where T : FilterCondition, T : Expr = And(listOf(left, right)) @@ -478,9 +534,16 @@ open class Function(val name: String, val params: List) : Expr { @JvmStatic fun arrayContains(expr: Expr, element: Expr) = ArrayContains(expr, element) + @JvmStatic + fun arrayContains(field: String, element: Expr) = ArrayContains(Field.of(field), element) + @JvmStatic fun arrayContains(expr: Expr, element: Any) = ArrayContains(expr, Constant.of(element)) + @JvmStatic + fun arrayContains(field: String, element: Any) = + ArrayContains(Field.of(field), Constant.of(element)) + @JvmStatic fun arrayContainsAny(expr: Expr, vararg elements: Expr) = ArrayContainsAny(expr, elements.toList()) @@ -489,22 +552,51 @@ open class Function(val name: String, val params: List) : Expr { fun arrayContainsAny(expr: Expr, vararg elements: Any) = ArrayContainsAny(expr, elements.toList().map { Constant.of(it) }) + @JvmStatic + fun arrayContainsAny(field: String, vararg elements: Expr) = + ArrayContainsAny(Field.of(field), elements.toList()) + + @JvmStatic + fun arrayContainsAny(field: String, vararg elements: Any) = + ArrayContainsAny(Field.of(field), elements.toList().map { Constant.of(it) }) + @JvmStatic fun isNaN(expr: Expr) = IsNaN(expr) + @JvmStatic + fun isNaN(field: String) = IsNaN(Field.of(field)) + @JvmStatic fun isNull(expr: Expr) = IsNull(expr) + @JvmStatic + fun isNull(field: String) = IsNull(Field.of(field)) + @JvmStatic fun not(expr: Expr) = Not(expr) @JvmStatic fun sum(expr: Expr) = Sum(expr, false) + @JvmStatic + fun sum(field: String) = Sum(Field.of(field), false) + @JvmStatic fun avg(expr: Expr) = Avg(expr, false) + @JvmStatic + fun avg(field: String) = Avg(Field.of(field), false) + @JvmStatic fun min(expr: Expr) = Sum(expr, false) + @JvmStatic + fun min(field: String) = Sum(Field.of(field), false) + @JvmStatic fun max(expr: Expr) = Avg(expr, false) + @JvmStatic + fun max(field: String) = Avg(Field.of(field), false) + @JvmStatic fun count(expr: Expr) = Count(expr, false) + @JvmStatic + fun count(field: String) = Count(Field.of(field), false) + @JvmStatic fun countAll() = Count(null, false) @JvmStatic fun cosineDistance(expr: Expr, other: Expr) = CosineDistance(expr, other) @@ -513,18 +605,39 @@ open class Function(val name: String, val params: List) : Expr { fun cosineDistance(expr: Expr, other: DoubleArray) = CosineDistance(expr, Constant.ofVector(other)) + @JvmStatic + fun cosineDistance(field: String, other: Expr) = CosineDistance(Field.of(field), other) + + @JvmStatic + fun cosineDistance(field: String, other: DoubleArray) = + CosineDistance(Field.of(field), Constant.ofVector(other)) + @JvmStatic fun dotProductDistance(expr: Expr, other: Expr) = CosineDistance(expr, other) @JvmStatic fun dotProductDistance(expr: Expr, other: DoubleArray) = CosineDistance(expr, Constant.ofVector(other)) + @JvmStatic + fun dotProductDistance(field: String, other: Expr) = CosineDistance(Field.of(field), other) + + @JvmStatic + fun dotProductDistance(field: String, other: DoubleArray) = + CosineDistance(Field.of(field), Constant.ofVector(other)) + @JvmStatic fun euclideanDistance(expr: Expr, other: Expr) = EuclideanDistance(expr, other) @JvmStatic fun euclideanDistance(expr: Expr, other: DoubleArray) = EuclideanDistance(expr, Constant.ofVector(other)) + @JvmStatic + fun euclideanDistance(field: String, other: Expr) = EuclideanDistance(Field.of(field), other) + + @JvmStatic + fun euclideanDistance(field: String, other: DoubleArray) = + EuclideanDistance(Field.of(field), Constant.ofVector(other)) + @JvmStatic fun function(name: String, params: List) = Generic(name, params) } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt index 350d1a776..b415b94f6 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt @@ -1,3 +1,4 @@ +@file:JvmName("Stages") package com.google.cloud.firestore.pipeline import com.google.cloud.firestore.DocumentReference From 7c15d5d86c826e3ac824b08f62912ccad967210b Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Thu, 30 May 2024 14:12:25 -0400 Subject: [PATCH 45/65] convert to java --- google-cloud-firestore/pom.xml | 48 -- .../cloud/firestore/AggregateQuery.java | 2 +- .../com/google/cloud/firestore/Pipeline.java | 443 ++++++++++++ .../cloud/firestore/PipelineResult.java | 433 ++++++++++++ .../google/cloud/firestore/PipelineResult.kt | 192 ------ .../google/cloud/firestore/PipelineUtils.java | 181 +++++ .../google/cloud/firestore/PipelineUtils.kt | 141 ---- .../com/google/cloud/firestore/Pipelines.kt | 420 ------------ .../com/google/cloud/firestore/Query.java | 10 +- .../cloud/firestore/UserDataConverter.java | 4 +- .../cloud/firestore/pipeline/Expressions.kt | 643 ------------------ .../pipeline/PaginatingPipeline.java | 75 ++ .../google/cloud/firestore/pipeline/Stages.kt | 265 -------- .../pipeline/expressions/Accumulator.java | 7 + .../expressions/AggregatorTarget.java | 25 + .../firestore/pipeline/expressions/And.java | 11 + .../pipeline/expressions/ArrayContains.java | 9 + .../expressions/ArrayContainsAny.java | 10 + .../firestore/pipeline/expressions/Avg.java | 9 + .../pipeline/expressions/Constant.java | 106 +++ .../pipeline/expressions/CosineDistance.java | 9 + .../firestore/pipeline/expressions/Count.java | 10 + .../expressions/DotProductDistance.java | 9 + .../firestore/pipeline/expressions/Equal.java | 9 + .../expressions/EuclideanDistance.java | 9 + .../firestore/pipeline/expressions/Expr.java | 172 +++++ .../firestore/pipeline/expressions/Field.java | 37 + .../pipeline/expressions/Fields.java | 29 + .../pipeline/expressions/FilterCondition.java | 3 + .../pipeline/expressions/Function.java | 323 +++++++++ .../pipeline/expressions/FunctionUtils.java | 32 + .../pipeline/expressions/Generic.java | 9 + .../pipeline/expressions/GreaterThan.java | 9 + .../expressions/GreaterThanOrEqual.java | 9 + .../firestore/pipeline/expressions/In.java | 10 + .../firestore/pipeline/expressions/IsNaN.java | 9 + .../pipeline/expressions/IsNull.java | 9 + .../pipeline/expressions/LessThan.java | 9 + .../pipeline/expressions/LessThanOrEqual.java | 9 + .../pipeline/expressions/ListOfExprs.java | 19 + .../firestore/pipeline/expressions/Max.java | 9 + .../firestore/pipeline/expressions/Min.java | 9 + .../firestore/pipeline/expressions/Not.java | 9 + .../pipeline/expressions/NotEqual.java | 9 + .../firestore/pipeline/expressions/Or.java | 9 + .../pipeline/expressions/Ordering.java | 65 ++ .../pipeline/expressions/Selectable.java | 3 + .../firestore/pipeline/expressions/Sum.java | 9 + .../firestore/pipeline/stages/AddFields.java | 26 + .../firestore/pipeline/stages/Aggregate.java | 47 ++ .../firestore/pipeline/stages/Collection.java | 29 + .../pipeline/stages/CollectionGroup.java | 24 + .../firestore/pipeline/stages/Database.java | 16 + .../firestore/pipeline/stages/Documents.java | 33 + .../firestore/pipeline/stages/Filter.java | 25 + .../pipeline/stages/FindNearest.java | 135 ++++ .../pipeline/stages/GenericStage.java | 27 + .../firestore/pipeline/stages/Limit.java | 24 + .../firestore/pipeline/stages/Offset.java | 24 + .../firestore/pipeline/stages/Select.java | 26 + .../cloud/firestore/pipeline/stages/Sort.java | 65 ++ .../firestore/pipeline/stages/Stage.java | 5 + .../firestore/pipeline/stages/StageUtils.java | 113 +++ .../cloud/firestore/it/ITPipelineTest.java | 38 +- 64 files changed, 2818 insertions(+), 1729 deletions(-) create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.java delete mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java delete mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.kt delete mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipelines.kt delete mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/PaginatingPipeline.java delete mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Accumulator.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AggregatorTarget.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/And.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContains.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContainsAny.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Avg.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Constant.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CosineDistance.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Count.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/DotProductDistance.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Equal.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/EuclideanDistance.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Fields.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/FilterCondition.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/FunctionUtils.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Generic.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/GreaterThan.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/GreaterThanOrEqual.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/In.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/IsNaN.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/IsNull.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/LessThan.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/LessThanOrEqual.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ListOfExprs.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Max.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Min.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Not.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/NotEqual.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Or.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Ordering.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Selectable.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Sum.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/AddFields.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Collection.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/CollectionGroup.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Database.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Documents.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Filter.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/FindNearest.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/GenericStage.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Limit.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Offset.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Select.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Sort.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Stage.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java diff --git a/google-cloud-firestore/pom.xml b/google-cloud-firestore/pom.xml index 670b93535..076938fd3 100644 --- a/google-cloud-firestore/pom.xml +++ b/google-cloud-firestore/pom.xml @@ -16,7 +16,6 @@ google-cloud-firestore - 1.9.22 @@ -174,17 +173,6 @@ 3.14.0 test - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-test - ${kotlin.version} - test - @@ -226,42 +214,6 @@ org.codehaus.mojo flatten-maven-plugin
- - org.jetbrains.kotlin - kotlin-maven-plugin - ${kotlin.version} - - - compile - compile - - compile - - - - src/main/java - target/generated-sources/annotations - - - - - test-compile - test-compile - - test-compile - - - - src/test/java - target/generated-test-sources/test-annotations - - - - - - 1.8 - - maven-assembly-plugin diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java index 5e2c5f673..f07db983b 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java @@ -24,7 +24,7 @@ import com.google.api.gax.rpc.StatusCode; import com.google.api.gax.rpc.StreamController; import com.google.cloud.Timestamp; -import com.google.cloud.firestore.pipeline.AggregatorTarget; +import com.google.cloud.firestore.pipeline.expressions.AggregatorTarget; import com.google.cloud.firestore.v1.FirestoreSettings; import com.google.common.collect.ImmutableMap; import com.google.firestore.v1.RunAggregationQueryRequest; diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java new file mode 100644 index 000000000..61b369706 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java @@ -0,0 +1,443 @@ +package com.google.cloud.firestore; + +import com.google.api.core.ApiFuture; +import com.google.api.core.SettableApiFuture; +import com.google.api.gax.rpc.ApiStreamObserver; +import com.google.api.gax.rpc.ResponseObserver; +import com.google.api.gax.rpc.StreamController; +import com.google.cloud.Timestamp; +import com.google.cloud.firestore.pipeline.PaginatingPipeline; +import com.google.cloud.firestore.pipeline.expressions.AggregatorTarget; +import com.google.cloud.firestore.pipeline.expressions.Expr; +import com.google.cloud.firestore.pipeline.expressions.Field; +import com.google.cloud.firestore.pipeline.expressions.Fields; +import com.google.cloud.firestore.pipeline.expressions.FilterCondition; +import com.google.cloud.firestore.pipeline.expressions.Ordering; +import com.google.cloud.firestore.pipeline.expressions.Selectable; +import com.google.cloud.firestore.pipeline.stages.AddFields; +import com.google.cloud.firestore.pipeline.stages.Aggregate; +import com.google.cloud.firestore.pipeline.stages.Collection; +import com.google.cloud.firestore.pipeline.stages.CollectionGroup; +import com.google.cloud.firestore.pipeline.stages.Database; +import com.google.cloud.firestore.pipeline.stages.Documents; +import com.google.cloud.firestore.pipeline.stages.FindNearest; +import com.google.cloud.firestore.pipeline.stages.GenericStage; +import com.google.cloud.firestore.pipeline.stages.Limit; +import com.google.cloud.firestore.pipeline.stages.Offset; +import com.google.cloud.firestore.pipeline.stages.Select; +import com.google.cloud.firestore.pipeline.stages.Sort; +import com.google.cloud.firestore.pipeline.stages.Stage; +import com.google.cloud.firestore.pipeline.stages.StageUtils; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; +import com.google.firestore.v1.Document; +import com.google.firestore.v1.ExecutePipelineRequest; +import com.google.firestore.v1.ExecutePipelineResponse; +import com.google.firestore.v1.StructuredPipeline; +import com.google.firestore.v1.Value; +import io.opencensus.trace.AttributeValue; +import io.opencensus.trace.Tracing; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.stream.Collectors; + +/** + * The Pipeline class provides a flexible and expressive framework for building complex data + * transformation and query pipelines for Firestore. + * + *

A pipeline takes data sources such as Firestore collections, collection groups, or even + * in-memory data, and applies a series of operations that are chained together, each operation + * takes the output from the last operation (or the data source) and produces an output for the next + * operation (or as the final output of the pipeline). + * + *

NOTE: the chained operations are not a prescription of exactly how Firestore will execute the + * pipeline, instead Firestore only guarantee the result is the same as if the chained operations + * are executed in order. + * + *

Usage Examples: + * + *

**1. Projecting Specific Fields and Renaming:** + * + *

```java Pipeline pipeline = Pipeline.fromCollection("users") // Select 'name' and 'email' + * fields, create 'userAge' which is renamed from field 'age'. .project(Fields.of("name", "email"), + * Field.of("age").asAlias("userAge")) ``` + * + *

**2. Filtering and Sorting:** + * + *

```java Pipeline pipeline = Pipeline.fromCollectionGroup("reviews") + * .filter(Field.of("rating").greaterThan(Expr.Constant.of(3))) // High ratings + * .sort(Ordering.of("timestamp").descending()); ``` + * + *

**3. Aggregation with Grouping:** + * + *

```java Pipeline pipeline = Pipeline.fromCollection("orders") .group(Field.of("customerId")) + * .aggregate(count(Field.of("orderId")).asAlias("orderCount")); ``` + */ +public final class Pipeline { + private final ImmutableList stages; + private final String name; + + private Pipeline(List stages, String name) { + this.stages = ImmutableList.copyOf(stages); + this.name = name; + } + + private Pipeline(Collection collection) { + this(Lists.newArrayList(collection), collection.getPath()); + } + + private Pipeline(CollectionGroup group) { + this(Lists.newArrayList(group), group.getCollectionId()); + } + + private Pipeline(Database db) { + this(Lists.newArrayList(db), db.getName()); + } + + private Pipeline(Documents docs) { + this(Lists.newArrayList(docs), docs.getName()); + } + + public static Pipeline from(CollectionReference source) { + return new Pipeline(new Collection(source.getPath())); + } + + public static Pipeline from(com.google.cloud.firestore.CollectionGroup source) { + return new Pipeline(new CollectionGroup(source.options.getCollectionId())); + } + + public static Pipeline fromCollection(String collectionName) { + return new Pipeline(new Collection(collectionName)); + } + + public static Pipeline fromCollectionGroup(String collectionId) { + Preconditions.checkArgument( + !collectionId.contains("/"), + "Invalid collectionId '%s'. Collection IDs must not contain '/'.", + collectionId); + return new Pipeline(new CollectionGroup(collectionId)); + } + + public static Pipeline fromDatabase() { + return new Pipeline(new Database()); + } + + public static Pipeline fromDocuments(DocumentReference... docs) { + return new Pipeline(Documents.of(docs)); + } + + private Map projectablesToMap(Selectable... selectables) { + Map projMap = new HashMap<>(); + for (Selectable proj : selectables) { + if (proj instanceof Field) { + Field fieldProj = (Field) proj; + projMap.put(fieldProj.getPath().getEncodedPath(), fieldProj); + } else if (proj instanceof AggregatorTarget) { + AggregatorTarget aggregatorProj = (AggregatorTarget) proj; + projMap.put(aggregatorProj.getFieldName(), aggregatorProj.getAccumulator()); + } else if (proj instanceof Fields) { + Fields fieldsProj = (Fields) proj; + if (fieldsProj.getFields() != null) { + fieldsProj.getFields().forEach(f -> projMap.put(f.getPath().getEncodedPath(), f)); + } + } + } + return projMap; + } + + private Map fieldNamesToMap(String... fields) { + Map projMap = new HashMap<>(); + for (String field : fields) { + projMap.put(field, Field.of(field)); + } + return projMap; + } + + public Pipeline addFields(Selectable... fields) { + return new Pipeline( + ImmutableList.builder() + .addAll(stages) + .add(new AddFields(projectablesToMap(fields))) + .build(), + name); + } + + public Pipeline select(Selectable... projections) { + return new Pipeline( + ImmutableList.builder() + .addAll(stages) + .add(new Select(projectablesToMap(projections))) + .build(), + name); + } + + public Pipeline select(String... fields) { + return new Pipeline( + ImmutableList.builder() + .addAll(stages) + .add(new Select(fieldNamesToMap(fields))) + .build(), + name); + } + + public Pipeline filter(FilterCondition condition) { + return new Pipeline( + ImmutableList.builder() + .addAll(stages) + .add(new com.google.cloud.firestore.pipeline.stages.Filter(condition)) + .build(), + name); + } + + public Pipeline offset(int offset) { + return new Pipeline( + ImmutableList.builder().addAll(stages).add(new Offset(offset)).build(), name); + } + + public Pipeline limit(int limit) { + return new Pipeline( + ImmutableList.builder().addAll(stages).add(new Limit(limit)).build(), name); + } + + public Pipeline aggregate(AggregatorTarget... aggregators) { + return new Pipeline( + ImmutableList.builder().addAll(stages).add(new Aggregate(aggregators)).build(), + name); + } + + public Pipeline findNearest( + String fieldName, double[] vector, FindNearest.FindNearestOptions options) { + return findNearest(Field.of(fieldName), vector, options); + } + + public Pipeline findNearest( + Field property, double[] vector, FindNearest.FindNearestOptions options) { + // Implementation for findNearest (add the FindNearest stage if needed) + return new Pipeline( + ImmutableList.builder() + .addAll(stages) + .add( + new FindNearest( + property, vector, options)) // Assuming FindNearest takes these arguments + .build(), + name); + } + + public Pipeline sort(List orders, Sort.Density density, Sort.Truncation truncation) { + return new Pipeline( + ImmutableList.builder() + .addAll(stages) + .add(new Sort(orders, density, truncation)) + .build(), + name); + } + + // Sugar + public Pipeline sort(Ordering... orders) { + return sort(Arrays.asList(orders), Sort.Density.UNSPECIFIED, Sort.Truncation.UNSPECIFIED); + } + + public PaginatingPipeline paginate(int pageSize, Ordering... orders) { + return new PaginatingPipeline(this, pageSize, Arrays.asList(orders)); + } + + public Pipeline genericStage(String name, Map params) { + // Implementation for genericStage (add the GenericStage if needed) + return new Pipeline( + ImmutableList.builder() + .addAll(stages) + .add( + new GenericStage( + name, + Lists.newArrayList( + params.values()))) // Assuming GenericStage takes a list of params + .build(), + name); + } + + public ApiFuture> execute(Firestore db) { + if (db instanceof FirestoreImpl) { + FirestoreImpl firestoreImpl = (FirestoreImpl) db; + Value pipelineValue = toProto(); + ExecutePipelineRequest request = + ExecutePipelineRequest.newBuilder() + .setDatabase(firestoreImpl.getResourcePath().getDatabaseName().toString()) + .setStructuredPipeline( + StructuredPipeline.newBuilder() + .setPipeline(pipelineValue.getPipelineValue()) + .build()) + .build(); + + SettableApiFuture> futureResult = SettableApiFuture.create(); + + pipelineInternalStream( // Assuming you have this method + firestoreImpl, + request, + new PipelineResultObserver() { + final List results = new ArrayList<>(); + + @Override + public void onCompleted() { + futureResult.set(results); + } + + @Override + public void onNext(PipelineResult result) { + results.add(result); + } + + @Override + public void onError(Throwable t) { + futureResult.setException(t); + } + }); + + return futureResult; + } else { + // Handle unsupported Firestore types + throw new IllegalArgumentException("Unsupported Firestore type"); + } + } + + public void execute(Firestore db, ApiStreamObserver observer) { + if (db instanceof FirestoreImpl) { + FirestoreImpl firestoreImpl = (FirestoreImpl) db; + Value pipelineValue = toProto(); + ExecutePipelineRequest request = + ExecutePipelineRequest.newBuilder() + .setDatabase(firestoreImpl.getResourcePath().getDatabaseName().toString()) + .setStructuredPipeline( + StructuredPipeline.newBuilder() + .setPipeline(pipelineValue.getPipelineValue()) + .build()) + .build(); + + pipelineInternalStream( + firestoreImpl, + request, + new PipelineResultObserver() { + @Override + public void onCompleted() { + observer.onCompleted(); + } + + @Override + public void onNext(PipelineResult result) { + observer.onNext(result); + } + + @Override + public void onError(Throwable t) { + observer.onError(t); + } + }); + } else { + // Handle unsupported Firestore types + throw new IllegalArgumentException("Unsupported Firestore type"); + } + } + + public Value toProto() { + return Value.newBuilder() + .setPipelineValue( + com.google.firestore.v1.Pipeline.newBuilder() + .addAllStages( + stages.stream() + .map(StageUtils::toStageProto) + .collect(Collectors.toList())) // Use the static method + ) + .build(); + } + + private void pipelineInternalStream( + FirestoreImpl rpcContext, + ExecutePipelineRequest request, + PipelineResultObserver resultObserver) { + ResponseObserver observer = + new ResponseObserver() { + Timestamp executionTime = null; + boolean firstResponse = false; + int numDocuments = 0; + boolean hasCompleted = false; + + @Override + public void onStart(StreamController controller) { + // No action needed in onStart + } + + @Override + public void onResponse(ExecutePipelineResponse response) { + if (!firstResponse) { + firstResponse = true; + Tracing.getTracer() + .getCurrentSpan() + .addAnnotation( + "Firestore.Query: First response"); // Assuming Tracing class exists + } + if (response.getResultsCount() > 0) { + numDocuments += response.getResultsCount(); + if (numDocuments % 100 == 0) { + Tracing.getTracer() + .getCurrentSpan() + .addAnnotation("Firestore.Query: Received 100 documents"); + } + for (Document doc : response.getResultsList()) { + resultObserver.onNext( + PipelineResult.fromDocument( + rpcContext, Timestamp.fromProto(response.getExecutionTime()), doc)); + } + } + + if (executionTime == null) { + executionTime = Timestamp.fromProto(response.getExecutionTime()); + } + } + + @Override + public void onError(Throwable throwable) { + Tracing.getTracer().getCurrentSpan().addAnnotation("Firestore.Query: Error"); + resultObserver.onError(throwable); + } + + @Override + public void onComplete() { + if (hasCompleted) { + return; + } + hasCompleted = true; + + Tracing.getTracer() + .getCurrentSpan() + .addAnnotation( + "Firestore.ExecutePipeline: Completed", + ImmutableMap.of( + "numDocuments", AttributeValue.longAttributeValue((long) numDocuments))); + resultObserver.onCompleted(executionTime); + } + }; + + Logger.getLogger("Pipeline").log(Level.WARNING, "Sending request: " + request); + + rpcContext.streamRequest(request, observer, rpcContext.getClient().executePipelineCallable()); + } +} + +abstract class PipelineResultObserver implements ApiStreamObserver { + private Timestamp executionTime; // Remove optional since Java doesn't have it + + public void onCompleted(Timestamp executionTime) { + this.executionTime = executionTime; + this.onCompleted(); + } + + public Timestamp getExecutionTime() { // Add getter for executionTime + return executionTime; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.java new file mode 100644 index 000000000..421d85f7d --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.java @@ -0,0 +1,433 @@ +/* + * Copyright 2017 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.firestore; + +import com.google.api.core.InternalExtensionOnly; +import com.google.cloud.Timestamp; +import com.google.common.base.Preconditions; +import com.google.firestore.v1.Document; +import com.google.firestore.v1.Value; +import com.google.firestore.v1.Write; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * A DocumentSnapshot contains data read from a document in a Firestore database. The data can be + * extracted with the {@link #getData()} or {@link #get(String)} methods. + * + *

If the DocumentSnapshot points to a non-existing document, getData() and its corresponding + * methods will return null. You can always explicitly check for a document's existence by calling + * {@link #exists()}. + * + *

Subclassing Note: Firestore classes are not meant to be subclassed except for use in + * test mocks. Subclassing is not supported in production code and new SDK releases may break code + * that does so. + */ +@InternalExtensionOnly +public final class PipelineResult { + + private final FirestoreRpcContext rpcContext; + @Nullable private final DocumentReference docRef; + @Nullable private final Map fields; + @Nullable private final Timestamp readTime; + @Nullable private final Timestamp updateTime; + @Nullable private final Timestamp createTime; + + PipelineResult( + FirestoreRpcContext rpcContext, + @Nullable DocumentReference docRef, + @Nullable Map fields, + @Nullable Timestamp readTime, + @Nullable Timestamp updateTime, + @Nullable Timestamp createTime) { // Elevated access level for mocking. + this.rpcContext = rpcContext; + this.docRef = docRef; + this.fields = fields; + this.readTime = readTime; + this.updateTime = updateTime; + this.createTime = createTime; + } + + /** + * Returns the ID of the document contained in this snapshot. + * + * @return The id of the document. + */ + @Nonnull + public String getId() { + return docRef.getId(); + } + + static PipelineResult fromDocument( + FirestoreRpcContext rpcContext, Timestamp readTime, Document document) { + return new PipelineResult( + rpcContext, + new DocumentReference(rpcContext, ResourcePath.create(document.getName())), + document.getFieldsMap(), + readTime, + Timestamp.fromProto(document.getUpdateTime()), + Timestamp.fromProto(document.getCreateTime())); + } + + /** + * Returns the time at which this snapshot was read. + * + * @return The read time of this snapshot. + */ + @Nullable + public Timestamp getReadTime() { + return readTime; + } + + /** + * Returns the time at which this document was last updated. Returns null for non-existing + * documents. + * + * @return The last time the document in the snapshot was updated. Null if the document doesn't + * exist. + */ + @Nullable + public Timestamp getUpdateTime() { + return updateTime; + } + + /** + * Returns the time at which this document was created. Returns null for non-existing documents. + * + * @return The last time the document in the snapshot was created. Null if the document doesn't + * exist. + */ + @Nullable + public Timestamp getCreateTime() { + return createTime; + } + + /** + * Returns whether or not the field exists in the document. Returns false if the document does not + * exist. + * + * @return whether the document existed in this snapshot. + */ + public boolean exists() { + return fields != null; + } + + /** + * Returns the fields of the document as a Map or null if the document doesn't exist. Field values + * will be converted to their native Java representation. + * + * @return The fields of the document as a Map or null if the document doesn't exist. + */ + @Nullable + public Map getData() { + if (fields == null) { + return null; + } + + Map decodedFields = new HashMap<>(); + for (Map.Entry entry : fields.entrySet()) { + Object decodedValue = UserDataConverter.decodeValue(rpcContext, entry.getValue()); + decodedFields.put(entry.getKey(), decodedValue); + } + return decodedFields; + } + + /** + * Returns the contents of the document converted to a POJO or null if the document doesn't exist. + * + * @param valueType The Java class to create + * @return The contents of the document in an object of type T or null if the document doesn't + * exist. + */ + @Nullable + public T toObject(@Nonnull Class valueType) { + Map data = getData(); + return data == null ? null : CustomClassMapper.convertToCustomClass(data, valueType, docRef); + } + + /** + * Returns whether or not the field exists in the document. Returns false if the document does not + * exist. + * + * @param field the path to the field. + * @return true iff the field exists. + */ + public boolean contains(@Nonnull String field) { + return contains(FieldPath.fromDotSeparatedString(field)); + } + + /** + * Returns whether or not the field exists in the document. Returns false if the document does not + * exist. + * + * @param fieldPath the path to the field. + * @return true iff the field exists. + */ + public boolean contains(@Nonnull FieldPath fieldPath) { + return this.extractField(fieldPath) != null; + } + + /** + * Returns the value at the field or null if the field doesn't exist. + * + * @param field The path to the field. + * @return The value at the given field or null. + */ + @Nullable + public Object get(@Nonnull String field) { + return get(FieldPath.fromDotSeparatedString(field)); + } + + /** + * Returns the value at the field, converted to a POJO, or null if the field or document doesn't + * exist. + * + * @param field The path to the field + * @param valueType The Java class to convert the field value to. + * @return The value at the given field or null. + */ + @Nullable + public T get(@Nonnull String field, @Nonnull Class valueType) { + return get(FieldPath.fromDotSeparatedString(field), valueType); + } + + /** + * Returns the value at the field or null if the field doesn't exist. + * + * @param fieldPath The path to the field. + * @return The value at the given field or null. + */ + @Nullable + public Object get(@Nonnull FieldPath fieldPath) { + Value value = extractField(fieldPath); + + if (value == null) { + return null; + } + + return UserDataConverter.decodeValue(rpcContext, value); + } + + /** + * Returns the value at the field, converted to a POJO, or null if the field or document doesn't + * exist. + * + * @param fieldPath The path to the field + * @param valueType The Java class to convert the field value to. + * @return The value at the given field or null. + */ + @Nullable + public T get(@Nonnull FieldPath fieldPath, Class valueType) { + Object data = get(fieldPath); + return data == null ? null : CustomClassMapper.convertToCustomClass(data, valueType, docRef); + } + + /** Returns the Value Proto at 'fieldPath'. Returns null if the field was not found. */ + @Nullable + Value extractField(@Nonnull FieldPath fieldPath) { + Value value = null; + + if (fields != null) { + Iterator components = fieldPath.getSegments().iterator(); + value = fields.get(components.next()); + + while (value != null && components.hasNext()) { + if (value.getValueTypeCase() != Value.ValueTypeCase.MAP_VALUE) { + return null; + } + value = value.getMapValue().getFieldsOrDefault(components.next(), null); + } + } + + return value; + } + + /** + * Returns the value of the field as a boolean. + * + * @param field The path to the field. + * @throws RuntimeException if the value is not a Boolean. + * @return The value of the field. + */ + @Nullable + public Boolean getBoolean(@Nonnull String field) { + return (Boolean) get(field); + } + + /** + * Returns the value of the field as a double. + * + * @param field The path to the field. + * @throws RuntimeException if the value is not a Number. + * @return The value of the field. + */ + @Nullable + public Double getDouble(@Nonnull String field) { + Number number = (Number) get(field); + return number == null ? null : number.doubleValue(); + } + + /** + * Returns the value of the field as a String. + * + * @param field The path to the field. + * @throws RuntimeException if the value is not a String. + * @return The value of the field. + */ + @Nullable + public String getString(@Nonnull String field) { + return (String) get(field); + } + + /** + * Returns the value of the field as a long. + * + * @param field The path to the field. + * @throws RuntimeException if the value is not a Number. + * @return The value of the field. + */ + @Nullable + public Long getLong(@Nonnull String field) { + Number number = (Number) get(field); + return number == null ? null : number.longValue(); + } + + /** + * Returns the value of the field as a Date. + * + * @param field The path to the field. + * @throws RuntimeException if the value is not a Date. + * @return The value of the field. + */ + @Nullable + public Date getDate(@Nonnull String field) { + Timestamp timestamp = getTimestamp(field); + return timestamp == null ? null : timestamp.toDate(); + } + + /** + * Returns the value of the field as a {@link Timestamp}. + * + * @param field The path to the field. + * @throws RuntimeException if the value is not a Date. + * @return The value of the field. + */ + @Nullable + public Timestamp getTimestamp(@Nonnull String field) { + return (Timestamp) get(field); + } + + /** + * Returns the value of the field as a Blob. + * + * @param field The path to the field. + * @throws RuntimeException if the value is not a Blob. + * @return The value of the field. + */ + @Nullable + public Blob getBlob(@Nonnull String field) { + return (Blob) get(field); + } + + /** + * Returns the value of the field as a GeoPoint. + * + * @param field The path to the field. + * @throws RuntimeException if the value is not a GeoPoint. + * @return The value of the field. + */ + @Nullable + public GeoPoint getGeoPoint(@Nonnull String field) { + return (GeoPoint) get(field); + } + + /** + * Gets the reference to the document. + * + * @return The reference to the document. + */ + @Nonnull + public DocumentReference getReference() { + return docRef; + } + + /** Checks whether this DocumentSnapshot contains any fields. */ + boolean isEmpty() { + return fields == null || fields.isEmpty(); + } + + Map getProtoFields() { + return fields; + } + + Write.Builder toPb() { + Preconditions.checkState(exists(), "Can't call toDocument() on a document that doesn't exist"); + Write.Builder write = Write.newBuilder(); + Document.Builder document = write.getUpdateBuilder(); + document.setName(docRef.getName()); + document.putAllFields(fields); + return write; + } + + Document.Builder toDocumentPb() { + Preconditions.checkState(exists(), "Can't call toDocument() on a document that doesn't exist"); + Document.Builder document = Document.newBuilder(); + return document + .setName(docRef.getName()) + .putAllFields(fields) + .setCreateTime(createTime.toProto()) + .setUpdateTime(updateTime.toProto()); + } + + /** + * Returns true if the document's data and path in this DocumentSnapshot equals the provided + * snapshot. + * + * @param obj The object to compare against. + * @return Whether this DocumentSnapshot is equal to the provided object. + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || !(obj instanceof PipelineResult)) { + return false; + } + PipelineResult that = (PipelineResult) obj; + return Objects.equals(rpcContext, that.rpcContext) + && Objects.equals(docRef, that.docRef) + && Objects.equals(fields, that.fields); + } + + @Override + public int hashCode() { + return Objects.hash(rpcContext, docRef, fields); + } + + @Override + public String toString() { + return String.format( + "%s{doc=%s, fields=%s, readTime=%s, updateTime=%s, createTime=%s}", + getClass().getSimpleName(), docRef, fields, readTime, updateTime, createTime); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt deleted file mode 100644 index 6df882e09..000000000 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.kt +++ /dev/null @@ -1,192 +0,0 @@ -package com.google.cloud.firestore - -import com.google.cloud.Timestamp -import com.google.cloud.firestore.pipeline.Field -import com.google.firestore.v1.Document -import com.google.firestore.v1.Value -import java.util.Date -import javax.annotation.Nonnull - -/** - * Result from a {@code Pipeline} execution. - */ -class PipelineResult -internal constructor( - private val rpcContext: FirestoreRpcContext<*>?, - val reference: DocumentReference?, - val protoFields: Map, - val readTime: Timestamp, - val updateTime: Timestamp?, - val createTime: Timestamp?, -) { - val id: String? - get() = reference?.id - - fun valid(): Boolean { - return protoFields != null - } - - val data: Map? - /** - * Returns the fields of the document as a Map or null if the document doesn't exist. Field - * values will be converted to their native Java representation. - * - * @return The fields of the document as a Map or null if the document doesn't exist. - */ - get() { - if (protoFields == null) { - return null - } - - val decodedFields: MutableMap = HashMap() - for ((key, value) in protoFields) { - val decodedValue = UserDataConverter.decodeValue(rpcContext, value) - decodedFields[key] = decodedValue - } - return decodedFields - } - - /** - * Returns the contents of the result converted to a POJO or null if the document doesn't exist. - * - * @param valueType The Java class to create - * @return The contents of the result in an object of type T or null if the document doesn't - * exist. - */ - fun toObject(@Nonnull valueType: Class): T? { - val data = data - return if (data == null) null - else CustomClassMapper.convertToCustomClass(data, valueType, reference) - } - - /** - * Returns whether or not the field exists in the result. Returns false if the result does not - * exist. - * - * @param field the path to the field. - * @return true iff the field exists. - */ - fun contains(field: String): Boolean { - return contains(FieldPath.fromDotSeparatedString(field)) - } - - /** - * Returns whether or not the field exists in the result. Returns false if the result is invalid. - * - * @param fieldPath the path to the field. - * @return true iff the field exists. - */ - fun contains(fieldPath: FieldPath): Boolean { - return this.extractField(fieldPath) != null - } - - fun contains(field: Field): Boolean { - return this.extractField(field.path) != null - } - - fun get(field: String): Any? { - return get(FieldPath.fromDotSeparatedString(field)) - } - - fun get(field: String?, valueType: Class): T? { - return get(FieldPath.fromDotSeparatedString(field), valueType) - } - - fun get(fieldPath: FieldPath): Any? { - val value = extractField(fieldPath) ?: return null - - return UserDataConverter.decodeValue(rpcContext, value) - } - - fun get(field: Field): Any? { - return get(field.path) - } - - fun get(fieldPath: FieldPath, valueType: Class): T? { - val data = get(fieldPath) - return if (data == null) null - else CustomClassMapper.convertToCustomClass(data, valueType, reference) - } - - fun get(field: Field, valueType: Class): T? { - return get(field.path, valueType) - } - - fun extractField(fieldPath: FieldPath): Value? { - var value: Value? = null - - if (protoFields != null) { - val components: Iterator = fieldPath.segments.iterator() - value = protoFields[components.next()] - - while (value != null && components.hasNext()) { - if (value.valueTypeCase != Value.ValueTypeCase.MAP_VALUE) { - return null - } - value = value.mapValue.getFieldsOrDefault(components.next(), null) - } - } - - return value - } - - fun extractField(field: Field): Value? { - return extractField(field.path) - } - - fun getBoolean(field: String): Boolean? { - return get(field) as Boolean? - } - - fun getDouble(field: String): Double? { - val number = get(field) as Number? - return number?.toDouble() - } - - fun getString(field: String): String? { - return get(field) as String? - } - - fun getLong(field: String): Long? { - val number = get(field) as Number? - return number?.toLong() - } - - fun getDate(field: String): Date? { - val timestamp = getTimestamp(field) - return timestamp?.toDate() - } - - fun getTimestamp(field: String): Timestamp? { - return get(field) as Timestamp? - } - - fun getBlob(field: String): Blob? { - return get(field) as Blob? - } - - fun getGeoPoint(field: String): GeoPoint? { - return get(field) as GeoPoint? - } - - val isEmpty: Boolean - get() = protoFields.isEmpty() - - companion object { - @JvmStatic - internal fun fromDocument( - rpcContext: FirestoreRpcContext<*>?, - readTime: com.google.protobuf.Timestamp, - document: Document, - ): PipelineResult { - return PipelineResult( - rpcContext, - document.name?.let { DocumentReference(rpcContext, ResourcePath.create(it)) }, - document.fieldsMap, - Timestamp.fromProto(readTime), - document.updateTime?.let { Timestamp.fromProto(it) }, - document.createTime?.let { Timestamp.fromProto(it) }, - ) - } - } -} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java new file mode 100644 index 000000000..d59eb2744 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java @@ -0,0 +1,181 @@ +package com.google.cloud.firestore; + +import static com.google.cloud.firestore.pipeline.expressions.Function.and; +import static com.google.cloud.firestore.pipeline.expressions.Function.arrayContainsAny; +import static com.google.cloud.firestore.pipeline.expressions.Function.countAll; +import static com.google.cloud.firestore.pipeline.expressions.Function.inAny; +import static com.google.cloud.firestore.pipeline.expressions.Function.not; +import static com.google.cloud.firestore.pipeline.expressions.Function.or; + +import com.google.api.core.InternalApi; +import com.google.cloud.firestore.Query.ComparisonFilterInternal; +import com.google.cloud.firestore.Query.CompositeFilterInternal; +import com.google.cloud.firestore.Query.FilterInternal; +import com.google.cloud.firestore.Query.LimitType; +import com.google.cloud.firestore.Query.UnaryFilterInternal; +import com.google.cloud.firestore.pipeline.PaginatingPipeline; +import com.google.cloud.firestore.pipeline.expressions.AggregatorTarget; +import com.google.cloud.firestore.pipeline.expressions.Constant; +import com.google.cloud.firestore.pipeline.expressions.Field; +import com.google.cloud.firestore.pipeline.expressions.FilterCondition; +import com.google.firestore.v1.Cursor; +import com.google.firestore.v1.Value; +import java.util.List; +import java.util.stream.Collectors; + +@InternalApi +public class PipelineUtils { + @InternalApi + public static Value encodeValue(Object value) { + return UserDataConverter.encodeValue(FieldPath.empty(), value, UserDataConverter.ARGUMENT); + } + + @InternalApi + static FilterCondition toPipelineFilterCondition(FilterInternal f) { + if (f instanceof ComparisonFilterInternal) { + ComparisonFilterInternal comparisonFilter = (ComparisonFilterInternal) f; + String fieldPath = comparisonFilter.fieldReference.getFieldPath(); + Value value = comparisonFilter.value; + switch (comparisonFilter.operator) { + case LESS_THAN: + return Field.of(fieldPath).lessThan(value); + case LESS_THAN_OR_EQUAL: + return Field.of(fieldPath).lessThanOrEqual(value); + case GREATER_THAN: + return Field.of(fieldPath).greaterThan(value); + case GREATER_THAN_OR_EQUAL: + return Field.of(fieldPath).greaterThanOrEqual(value); + case EQUAL: + return Field.of(fieldPath).equal(value); + case NOT_EQUAL: + return not(Field.of(fieldPath).equal(value)); + case ARRAY_CONTAINS: + return Field.of(fieldPath).arrayContains(value); + case IN: + List valuesList = value.getArrayValue().getValuesList(); + return inAny( + Field.of(fieldPath), + valuesList.stream().map(Constant::of).collect(Collectors.toList())); + case ARRAY_CONTAINS_ANY: + List valuesListAny = value.getArrayValue().getValuesList(); + return arrayContainsAny( + Field.of(fieldPath), + valuesListAny.stream().map(Constant::of).collect(Collectors.toList())); + case NOT_IN: + List notInValues = value.getArrayValue().getValuesList(); + return not( + inAny( + Field.of(fieldPath), + notInValues.stream().map(Constant::of).collect(Collectors.toList()))); + default: + // Handle OPERATOR_UNSPECIFIED and UNRECOGNIZED cases as needed + throw new IllegalArgumentException("Unsupported operator: " + comparisonFilter.operator); + } + } else if (f instanceof CompositeFilterInternal) { + CompositeFilterInternal compositeFilter = (CompositeFilterInternal) f; + switch (compositeFilter.getOperator()) { + case AND: + List conditions = + compositeFilter.getFilters().stream() + .map(PipelineUtils::toPipelineFilterCondition) + .collect(Collectors.toList()); + return and( + conditions.get(0), + conditions.subList(1, conditions.size()).toArray(new FilterCondition[0])); + case OR: + List orConditions = + compositeFilter.getFilters().stream() + .map(PipelineUtils::toPipelineFilterCondition) + .collect(Collectors.toList()); + return or( + orConditions.get(0), + orConditions.subList(1, orConditions.size()).toArray(new FilterCondition[0])); + default: + // Handle OPERATOR_UNSPECIFIED and UNRECOGNIZED cases as needed + throw new IllegalArgumentException( + "Unsupported operator: " + compositeFilter.getOperator()); + } + } else if (f instanceof UnaryFilterInternal) { + UnaryFilterInternal unaryFilter = (UnaryFilterInternal) f; + String fieldPath = unaryFilter.fieldReference.getFieldPath(); + switch (unaryFilter.getOperator()) { + case IS_NAN: + return Field.of(fieldPath).isNaN(); + case IS_NULL: + return Field.of(fieldPath).isNull(); + case IS_NOT_NAN: + return not(Field.of(fieldPath).isNaN()); + case IS_NOT_NULL: + return not(Field.of(fieldPath).isNull()); + default: + // Handle OPERATOR_UNSPECIFIED and UNRECOGNIZED cases as needed + throw new IllegalArgumentException("Unsupported operator: " + unaryFilter.getOperator()); + } + } else { + // Handle other FilterInternal types as needed + throw new IllegalArgumentException("Unsupported filter type: " + f.getClass().getName()); + } + } + + @InternalApi + static Pipeline toPaginatedPipeline( + Pipeline pipeline, + Cursor start, + Cursor end, + Integer limit, + LimitType limitType, + Integer offset) { + + // Handle null limit, setting a default maximum + int effectiveLimit = (limit != null) ? limit : Integer.MAX_VALUE; + + PaginatingPipeline paginate = pipeline.paginate(effectiveLimit); + + // Apply start and end cursors if present + if (start != null) { + paginate = paginate.withStartCursor(start); + } + if (end != null) { + paginate = paginate.withEndCursor(end); + } + if (offset != null) { + paginate = paginate.offset(offset); + } + + // Handle limitType, defaulting to firstPage + if (limitType != null) { + switch (limitType) { + case First: + return paginate.firstPage(); + case Last: + return paginate.lastPage(); + default: + // Handle other LimitType cases as needed, or throw an exception + throw new IllegalArgumentException("Unsupported limit type: " + limitType); + } + } else { + return paginate.firstPage(); + } + } + + @InternalApi + static AggregatorTarget toPipelineAggregatorTarget(AggregateField f) { + String operator = f.getOperator(); + String fieldPath = f.getFieldPath(); // Assuming you have a method to get FieldPath + + switch (operator) { + case "sum": + return Field.of(fieldPath) + .sum() + .toField(f.getAlias()); // Note: 'toField' is assumed to be a method in your context + + case "count": + return countAll().toField(f.getAlias()); + case "avg": + return Field.of(fieldPath).avg().toField(f.getAlias()); + default: + // Handle the 'else' case appropriately in your Java code + throw new IllegalArgumentException("Unsupported operator: " + operator); + } + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.kt deleted file mode 100644 index e0023f041..000000000 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.kt +++ /dev/null @@ -1,141 +0,0 @@ -@file:JvmName("PipelineUtils") -package com.google.cloud.firestore - -import com.google.cloud.firestore.Query.ComparisonFilterInternal -import com.google.cloud.firestore.Query.CompositeFilterInternal -import com.google.cloud.firestore.Query.FilterInternal -import com.google.cloud.firestore.Query.LimitType -import com.google.cloud.firestore.Query.UnaryFilterInternal -import com.google.cloud.firestore.pipeline.AggregatorTarget -import com.google.cloud.firestore.pipeline.Constant -import com.google.cloud.firestore.pipeline.Field -import com.google.cloud.firestore.pipeline.Function -import com.google.cloud.firestore.pipeline.Function.Companion.countAll -import com.google.cloud.firestore.pipeline.Function.Companion.not -import com.google.firestore.v1.Cursor -import com.google.firestore.v1.StructuredQuery - -internal fun toPipelineFilterCondition(f: FilterInternal): Function.FilterCondition { - return when (f) { - is ComparisonFilterInternal -> { - when (f.operator) { - StructuredQuery.FieldFilter.Operator.OPERATOR_UNSPECIFIED -> { - TODO() - } - StructuredQuery.FieldFilter.Operator.LESS_THAN -> { - Field.of(f.fieldReference.fieldPath).lessThan(f.value) - } - StructuredQuery.FieldFilter.Operator.LESS_THAN_OR_EQUAL -> { - Field.of(f.fieldReference.fieldPath).lessThanOrEqual(f.value) - } - StructuredQuery.FieldFilter.Operator.GREATER_THAN -> { - Field.of(f.fieldReference.fieldPath).greaterThan(f.value) - } - StructuredQuery.FieldFilter.Operator.GREATER_THAN_OR_EQUAL -> { - Field.of(f.fieldReference.fieldPath).greaterThanOrEqual(f.value) - } - StructuredQuery.FieldFilter.Operator.EQUAL -> { - Field.of(f.fieldReference.fieldPath).equal(f.value) - } - StructuredQuery.FieldFilter.Operator.NOT_EQUAL -> { - not(Field.of(f.fieldReference.fieldPath).equal(f.value)) - } - StructuredQuery.FieldFilter.Operator.ARRAY_CONTAINS -> { - Field.of(f.fieldReference.fieldPath).arrayContains(f.value) - } - StructuredQuery.FieldFilter.Operator.IN -> { - Function.In( - Field.of(f.fieldReference.fieldPath), - f.value?.arrayValue?.valuesList?.map { Constant.of(it) } ?: emptyList(), - ) - } - StructuredQuery.FieldFilter.Operator.ARRAY_CONTAINS_ANY -> { - Function.ArrayContainsAny( - Field.of(f.fieldReference.fieldPath), - f.value?.arrayValue?.valuesList?.map { Constant.of(it) } ?: emptyList(), - ) - } - StructuredQuery.FieldFilter.Operator.NOT_IN -> { - not( - Function.In( - Field.of(f.fieldReference.fieldPath), - f.value?.arrayValue?.valuesList?.map { Constant.of(it) } ?: emptyList(), - ) - ) - } - StructuredQuery.FieldFilter.Operator.UNRECOGNIZED -> { - TODO() - } - } - } - is CompositeFilterInternal -> { - when (f.operator) { - StructuredQuery.CompositeFilter.Operator.OPERATOR_UNSPECIFIED -> { - TODO() - } - StructuredQuery.CompositeFilter.Operator.AND -> { - Function.And(f.filters.map { toPipelineFilterCondition(it) }) - } - StructuredQuery.CompositeFilter.Operator.OR -> { - Function.Or(f.filters.map { toPipelineFilterCondition(it) }) - } - StructuredQuery.CompositeFilter.Operator.UNRECOGNIZED -> { - TODO() - } - } - } - is UnaryFilterInternal -> { - when (f.operator) { - StructuredQuery.UnaryFilter.Operator.IS_NAN -> Field.of(f.fieldReference.fieldPath).isNaN() - StructuredQuery.UnaryFilter.Operator.IS_NULL -> - Field.of(f.fieldReference.fieldPath).isNull() - StructuredQuery.UnaryFilter.Operator.IS_NOT_NAN -> - not(Field.of(f.fieldReference.fieldPath).isNaN()) - StructuredQuery.UnaryFilter.Operator.IS_NOT_NULL -> - not(Field.of(f.fieldReference.fieldPath).isNull()) - StructuredQuery.UnaryFilter.Operator.OPERATOR_UNSPECIFIED -> TODO() - StructuredQuery.UnaryFilter.Operator.UNRECOGNIZED -> TODO() - } - } - else -> { - TODO() - } - } -} - -internal fun toPaginatedPipeline( - pipeline: Pipeline, - start: Cursor?, - end: Cursor?, - limit: Int?, - limitType: LimitType?, - offset: Int?, -): Pipeline { - var paginate: PaginatingPipeline = pipeline.paginate(limit ?: Int.MAX_VALUE) - - start?.let { paginate = setStartCursor(paginate, it) } - end?.let { paginate = setEndCursor(paginate, it) } - offset?.let { paginate = paginate.offset(it) } - - return limitType?.let { - when (it) { - LimitType.First -> paginate.firstPage() - LimitType.Last -> paginate.lastPage() - } - } ?: paginate.firstPage() -} - -internal fun toPipelineAggregatorTarget(f: AggregateField): AggregatorTarget { - return when (f.operator) { - "sum" -> { - Field.of(f.getFieldPath()).sum().toField(f.alias) - } - "count" -> { - countAll().toField(f.alias) - } - "avg" -> { - Field.of(f.getFieldPath()).avg().toField(f.alias) - } - else -> TODO() - } -} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipelines.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipelines.kt deleted file mode 100644 index 6d4ef8341..000000000 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipelines.kt +++ /dev/null @@ -1,420 +0,0 @@ -@file:JvmName("Pipelines") -package com.google.cloud.firestore - -import com.google.api.core.ApiFuture -import com.google.api.core.SettableApiFuture -import com.google.api.gax.rpc.ApiStreamObserver -import com.google.api.gax.rpc.ResponseObserver -import com.google.api.gax.rpc.StreamController -import com.google.cloud.Timestamp -import com.google.cloud.firestore.pipeline.AddFields -import com.google.cloud.firestore.pipeline.Aggregate -import com.google.cloud.firestore.pipeline.AggregatorTarget -import com.google.cloud.firestore.pipeline.Collection -import com.google.cloud.firestore.pipeline.CollectionGroup -import com.google.cloud.firestore.pipeline.Database -import com.google.cloud.firestore.pipeline.Documents -import com.google.cloud.firestore.pipeline.Expr -import com.google.cloud.firestore.pipeline.Field -import com.google.cloud.firestore.pipeline.Fields -import com.google.cloud.firestore.pipeline.Filter -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.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 -import com.google.cloud.firestore.pipeline.toStageProto -import com.google.common.base.Preconditions -import com.google.common.collect.ImmutableMap -import com.google.firestore.v1.Cursor -import com.google.firestore.v1.Document -import com.google.firestore.v1.ExecutePipelineRequest -import com.google.firestore.v1.ExecutePipelineResponse -import com.google.firestore.v1.StructuredPipeline -import com.google.firestore.v1.Value -import io.opencensus.trace.AttributeValue -import io.opencensus.trace.Tracing -import java.util.logging.Level -import java.util.logging.Logger - -internal fun setStartCursor(pipeline: PaginatingPipeline, cursor: Cursor): PaginatingPipeline { - return pipeline -} - -internal fun setEndCursor(pipeline: PaginatingPipeline, cursor: Cursor): PaginatingPipeline { - return pipeline -} - -class PaginatingPipeline -internal constructor( - internal val p: Pipeline, - internal val pageSize: Int, - internal val orders: List, - private val offset: Int? = null, - private val startCursor: Cursor? = null, - private val endCursor: Cursor? = null, -) { - fun firstPage(): Pipeline { - return this.p - } - - fun lastPage(): Pipeline { - return this.p - } - - fun startAt(result: PipelineResult): PaginatingPipeline { - return this - } - - fun startAfter(result: PipelineResult): PaginatingPipeline { - return this - } - - fun endAt(result: PipelineResult): PaginatingPipeline { - return this - } - - fun endBefore(result: PipelineResult): PaginatingPipeline { - return this - } - - // Internal as this is only potentially used when converting Query to Pipeline. - internal fun offset(offset: Int): PaginatingPipeline { - return this - } -} - -/** - * The Pipeline class provides a flexible and expressive framework for building complex data - * transformation and query pipelines for Firestore. - * - * A pipeline takes data sources such as Firestore collections, collection groups, or even in-memory - * data, and applies a series of operations that are chained together, each operation takes the - * output from the last operation (or the data source) and produces an output for the next operation - * (or as the final output of the pipeline). - * - * NOTE: the chained operations are not a prescription of exactly how Firestore will execute the - * pipeline, instead Firestore only guarantee the result is the same as if the chained operations - * are executed in order. - * - * Usage Examples: - * - * **1. Projecting Specific Fields and Renaming:** - * - * ```java - * Pipeline pipeline = Pipeline.fromCollection("users") - * // Select 'name' and 'email' fields, create 'userAge' which is renamed from field 'age'. - * .project(Fields.of("name", "email"), Field.of("age").asAlias("userAge")) - * ``` - * - * **2. Filtering and Sorting:** - * - * ```java - * Pipeline pipeline = Pipeline.fromCollectionGroup("reviews") - * .filter(Field.of("rating").greaterThan(Expr.Constant.of(3))) // High ratings - * .sort(Ordering.of("timestamp").descending()); - * ``` - * - * **3. Aggregation with Grouping:** - * - * ```java - * Pipeline pipeline = Pipeline.fromCollection("orders") - * .group(Field.of("customerId")) - * .aggregate(count(Field.of("orderId")).asAlias("orderCount")); - * ``` - */ -class Pipeline private constructor(private val stages: List, private val name: String) { - - private constructor(collection: Collection) : this(listOf(collection), collection.relativePath) - - private constructor(group: CollectionGroup) : this(listOf(group), group.collectionId) - - private constructor(db: Database) : this(listOf(db), db.name) - - private constructor(docs: Documents) : this(listOf(docs), docs.name) - - companion object { - @JvmStatic - fun from(source: CollectionReference): Pipeline { - return Pipeline(Collection(source.path)) - } - - @JvmStatic - fun from(source: com.google.cloud.firestore.CollectionGroup): Pipeline { - return Pipeline(CollectionGroup(source.options.collectionId)) - } - - @JvmStatic - fun fromCollection(collectionName: String): Pipeline { - return Pipeline(Collection(collectionName)) - } - - @JvmStatic - fun fromCollectionGroup(collectionId: String): Pipeline { - Preconditions.checkArgument( - !collectionId.contains("/"), - "Invalid collectionId '%s'. Collection IDs must not contain '/'.", - collectionId, - ) - return Pipeline(CollectionGroup(collectionId)) - } - - @JvmStatic - fun fromDatabase(): Pipeline { - return Pipeline(Database()) - } - - @JvmStatic - fun fromDocuments(vararg docs: DocumentReference): Pipeline { - return Pipeline(Documents.of(*docs)) - } - } - - private fun projectablesToMap(vararg selectables: Selectable): Map { - val projMap = mutableMapOf() - for (proj in selectables) { - when (proj) { - is Field -> projMap[proj.path.encodedPath] = proj - is AggregatorTarget -> projMap[proj.fieldName] = proj.accumulator - is Fields -> proj.fs?.forEach { projMap[it.path.encodedPath] = it } - } - } - return projMap - } - - private fun fieldNamesToMap(vararg fields: String): Map { - val projMap = mutableMapOf() - for (field in fields) { - projMap[field] = Field.of(field) - } - return projMap - } - - fun addFields(vararg fields: Selectable): Pipeline { - return Pipeline(stages.plus(AddFields(projectablesToMap(*fields))), name) - } - - fun select(vararg projections: Selectable): Pipeline { - return Pipeline(stages.plus(Select(projectablesToMap(*projections))), name) - } - - fun select(vararg fields: String): Pipeline { - return Pipeline(stages.plus(Select(fieldNamesToMap(*fields))), name) - } - - fun filter(condition: T): Pipeline where T : Expr, T : Function.FilterCondition { - return Pipeline(stages.plus(Filter(condition)), name) - } - - fun offset(offset: Int): Pipeline { - return Pipeline(stages.plus(Offset(offset)), name) - } - - fun limit(limit: Int): Pipeline { - return Pipeline(stages.plus(Limit(limit)), name) - } - - fun aggregate(vararg aggregators: AggregatorTarget): Pipeline { - return Pipeline(stages.plus(Aggregate(*aggregators)), name) - } - - fun findNearest( - property: Field, - vector: DoubleArray, - options: FindNearest.FindNearestOptions, - ): Pipeline { - return this - } - - fun sort( - orders: List, - density: Sort.Density = Sort.Density.UNSPECIFIED, - truncation: Sort.Truncation = Sort.Truncation.UNSPECIFIED, - ): Pipeline { - return Pipeline(stages.plus(Sort(orders, density, truncation)), name) - } - - // Sugar - fun sort(vararg orders: Ordering): Pipeline { - return this.sort(orders.toList()) - } - - fun paginate(pageSize: Int, vararg orders: Ordering): PaginatingPipeline { - return PaginatingPipeline(this, pageSize, orders.toList()) - } - - fun genericStage(name: String, params: Map? = null): Pipeline { - return this - } - - fun execute(db: Firestore): ApiFuture> { - when (db) { - is FirestoreImpl -> { - val pipelineValue = toProto() - val request = - ExecutePipelineRequest.newBuilder() - .setDatabase(db.resourcePath.databaseName.toString()) - .setStructuredPipeline( - StructuredPipeline.newBuilder().setPipeline(pipelineValue.pipelineValue).build() - ) - .build() - - val futureResult = SettableApiFuture.create>() - pipelineInternalStream( - db, - request, - object : PipelineResultObserver() { - val results = mutableListOf() - - override fun onCompleted() { - futureResult.set(results) - } - - override fun onNext(result: PipelineResult?) { - results.add(result!!) - } - - override fun onError(t: Throwable?) { - futureResult.setException(t) - } - }, - ) - - return futureResult - } - else -> { - TODO() - } - } - } - - fun execute(db: Firestore, observer: ApiStreamObserver): Unit { - when (db) { - is FirestoreImpl -> { - val pipelineValue = toProto() - val request = - ExecutePipelineRequest.newBuilder() - .setDatabase(db.resourcePath.databaseName.toString()) - .setStructuredPipeline( - StructuredPipeline.newBuilder().setPipeline(pipelineValue.pipelineValue).build() - ) - .build() - - pipelineInternalStream( - db, - request, - object : PipelineResultObserver() { - override fun onCompleted() { - observer.onCompleted() - } - - override fun onNext(result: PipelineResult?) { - observer.onNext(result) - } - - override fun onError(t: Throwable?) { - observer.onError(t) - } - }, - ) - } - else -> { - TODO() - } - } - } - - internal fun toProto(): Value { - return Value.newBuilder() - .setPipelineValue( - com.google.firestore.v1.Pipeline.newBuilder().addAllStages(stages.map { toStageProto(it) }) - ) - .build() - } -} - -internal fun encodeValue(value: Any?): Value? { - return UserDataConverter.encodeValue(FieldPath.empty(), value, UserDataConverter.ARGUMENT) -} - -private abstract class PipelineResultObserver : ApiStreamObserver { - var executionTime: Timestamp? = null - private set - - fun onCompleted(executionTime: Timestamp?) { - this.executionTime = executionTime - this.onCompleted() - } -} - -private fun pipelineInternalStream( - rpcContext: FirestoreImpl, - request: ExecutePipelineRequest, - resultObserver: PipelineResultObserver, -) { - val observer: ResponseObserver = - object : ResponseObserver { - var executionTime: Timestamp? = null - var firstResponse: Boolean = false - var numDocuments: Int = 0 - - // The stream's `onComplete()` could be called more than once, - // this flag makes sure only the first one is actually processed. - var hasCompleted: Boolean = false - - override fun onStart(streamController: StreamController) {} - - override fun onResponse(response: ExecutePipelineResponse) { - if (!firstResponse) { - firstResponse = true - Tracing.getTracer().currentSpan.addAnnotation("Firestore.Query: First response") - } - if (response.resultsCount > 0) { - numDocuments += response.resultsCount - if (numDocuments % 100 == 0) { - Tracing.getTracer().currentSpan.addAnnotation("Firestore.Query: Received 100 documents") - } - response.resultsList.forEach { doc: Document -> - resultObserver.onNext( - PipelineResult.fromDocument(rpcContext, response.executionTime, doc) - ) - } - } - - if (executionTime == null) { - executionTime = Timestamp.fromProto(response.executionTime) - } - } - - override fun onError(throwable: Throwable) { - Tracing.getTracer().currentSpan.addAnnotation("Firestore.Query: Error") - resultObserver.onError(throwable) - } - - override fun onComplete() { - if (hasCompleted) { - return - } - hasCompleted = true - - Tracing.getTracer() - .currentSpan - .addAnnotation( - "Firestore.Query: Completed", - ImmutableMap.of( - "numDocuments", - AttributeValue.longAttributeValue(numDocuments.toLong()), - ), - ) - resultObserver.onCompleted(executionTime) - } - } - - Logger.getLogger("Pipeline").log(Level.WARNING, "Sending request: $request") - - rpcContext.streamRequest(request, observer, rpcContext.client.executePipelineCallable()) -} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index 15ed4cf65..d5e217f64 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -40,11 +40,11 @@ import com.google.auto.value.AutoValue; 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.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; +import com.google.cloud.firestore.pipeline.expressions.Field; +import com.google.cloud.firestore.pipeline.expressions.Ordering; +import com.google.cloud.firestore.pipeline.expressions.Selectable; +import com.google.cloud.firestore.pipeline.stages.Sort.Density; +import com.google.cloud.firestore.pipeline.stages.Sort.Truncation; import com.google.cloud.firestore.v1.FirestoreSettings; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java index 1f077f756..bfbddc86f 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java @@ -16,10 +16,10 @@ package com.google.cloud.firestore; -import static com.google.cloud.firestore.pipeline.Expressions.exprToValue; +import static com.google.cloud.firestore.pipeline.expressions.FunctionUtils.exprToValue; import com.google.cloud.Timestamp; -import com.google.cloud.firestore.pipeline.Expr; +import com.google.cloud.firestore.pipeline.expressions.Expr; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Maps; diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt deleted file mode 100644 index b4f6ce449..000000000 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Expressions.kt +++ /dev/null @@ -1,643 +0,0 @@ -@file:JvmName("Expressions") -package com.google.cloud.firestore.pipeline - -import com.google.cloud.Timestamp -import com.google.cloud.firestore.Blob -import com.google.cloud.firestore.DocumentReference -import com.google.cloud.firestore.FieldPath -import com.google.cloud.firestore.GeoPoint -import com.google.cloud.firestore.Pipeline -import com.google.cloud.firestore.encodeValue -import com.google.cloud.firestore.pipeline.Function.ArrayContains -import com.google.cloud.firestore.pipeline.Function.ArrayContainsAny -import com.google.cloud.firestore.pipeline.Function.Avg -import com.google.cloud.firestore.pipeline.Function.CosineDistance -import com.google.cloud.firestore.pipeline.Function.Count -import com.google.cloud.firestore.pipeline.Function.DotProductDistance -import com.google.cloud.firestore.pipeline.Function.Equal -import com.google.cloud.firestore.pipeline.Function.EuclideanDistance -import com.google.cloud.firestore.pipeline.Function.GreaterThan -import com.google.cloud.firestore.pipeline.Function.GreaterThanOrEqual -import com.google.cloud.firestore.pipeline.Function.In -import com.google.cloud.firestore.pipeline.Function.IsNaN -import com.google.cloud.firestore.pipeline.Function.IsNull -import com.google.cloud.firestore.pipeline.Function.LessThan -import com.google.cloud.firestore.pipeline.Function.LessThanOrEqual -import com.google.cloud.firestore.pipeline.Function.NotEqual -import com.google.cloud.firestore.pipeline.Function.Sum -import com.google.cloud.firestore.pipeline.Sort.Ordering -import com.google.cloud.firestore.pipeline.Sort.Ordering.Direction -import com.google.firestore.v1.ArrayValue -import com.google.firestore.v1.Value -import java.util.Date - -internal fun exprToValue(expr: Expr): Value { - return when (expr) { - is Constant -> expr.toProto() - is Field -> expr.toProto() - is Function -> expr.toProto() - is ListOfExprs -> { - Value.newBuilder() - .setArrayValue( - ArrayValue.newBuilder().addAllValues(expr.conditions.map { exprToValue(it) }) - ) - .build() - } - else -> { - TODO() - } - } -} - -interface Selectable - -internal class ExprWithAlias internal constructor(val alias: String, val expr: Expr) : Selectable - -interface Expr { - // Infix functions returning Function subclasses - infix fun equal(other: Expr) = Equal(this, other) - - infix fun equal(other: Any) = Equal(this, Constant.of(other)) - - infix fun notEqual(other: Expr) = NotEqual(this, other) - - infix fun notEqual(other: Any) = NotEqual(this, Constant.of(other)) - - infix fun greaterThan(other: Expr) = GreaterThan(this, other) - - infix fun greaterThan(other: Any) = GreaterThan(this, Constant.of(other)) - - infix fun greaterThanOrEqual(other: Expr) = GreaterThanOrEqual(this, other) - - infix fun greaterThanOrEqual(other: Any) = GreaterThanOrEqual(this, Constant.of(other)) - - infix fun lessThan(other: Expr) = LessThan(this, other) - - infix fun lessThan(other: Any) = LessThan(this, Constant.of(other)) - - infix fun lessThanOrEqual(other: Expr) = LessThanOrEqual(this, other) - - infix fun lessThanOrEqual(other: Any) = LessThanOrEqual(this, Constant.of(other)) - - fun inAny(vararg other: Any) = - In( - this, - other.toList().map { - when (it) { - is Expr -> it - else -> Constant.of(it) - } - }, - ) - - fun notInAny(vararg other: Any) = - Function.Not( - In( - this, - other.toList().map { - when (it) { - is Expr -> it - else -> Constant.of(it) - } - }, - ) - ) - - infix fun arrayContains(element: Expr) = ArrayContains(this, element) - - infix fun arrayContains(element: Any) = ArrayContains(this, Constant.of(element)) - - fun arrayContainsAny(vararg elements: Expr) = ArrayContainsAny(this, elements.toList()) - - fun arrayContainsAny(vararg elements: Any) = - ArrayContainsAny(this, elements.toList().map { Constant.of(it) }) - - fun isNaN() = IsNaN(this) - - fun isNull() = IsNull(this) - - fun sum() = Sum(this, false) - - fun avg() = Avg(this, false) - - fun count() = Count(this, false) - - fun min() = Function.Min(this, false) - - fun max() = Function.Max(this, false) - - infix fun cosineDistance(other: Expr) = CosineDistance(this, other) - - infix fun cosineDistance(other: DoubleArray) = CosineDistance(this, Constant.ofVector(other)) - - infix fun euclideanDistance(other: Expr) = EuclideanDistance(this, other) - - infix fun euclideanDistance(other: DoubleArray) = - EuclideanDistance(this, Constant.ofVector(other)) - - infix fun dotProductDistance(other: Expr) = DotProductDistance(this, other) - - infix fun dotProductDistance(other: DoubleArray) = - DotProductDistance(this, Constant.ofVector(other)) - - fun ascending(): Ordering { - return Ordering(this, Direction.ASCENDING) - } - - fun descending(): Ordering { - return Ordering(this, Direction.DESCENDING) - } - - fun asAlias(alias: String): Selectable { - return ExprWithAlias(alias, this) - } -} - -// Convenient class for internal usage -internal data class ListOfExprs(val conditions: List) : Expr - -data class Constant internal constructor(private val value: Any?) : Expr { - companion object { - @JvmStatic - fun of(value: String?): Constant { - return Constant(value) - } - - @JvmStatic - fun of(value: Number?): Constant { - return Constant(value) - } - - @JvmStatic - fun of(value: Date?): Constant { - return Constant(value) - } - - @JvmStatic - fun of(value: Timestamp?): Constant { - return Constant(value) - } - - @JvmStatic - fun of(value: Boolean?): Constant { - return Constant(value) - } - - @JvmStatic - fun of(value: GeoPoint?): Constant { - return Constant(value) - } - - @JvmStatic - fun of(value: Blob?): Constant { - return Constant(value) - } - - @JvmStatic - fun of(value: DocumentReference?): Constant { - return Constant(value) - } - - @JvmStatic - fun of(value: Value?): Constant { - return Constant(value) - } - - @JvmStatic - internal fun of(value: Any?): Constant { - if (value == null) { - return Constant(null) - } - - return when (value) { - is String -> of(value) - is Number -> of(value) - is Date -> of(value) - is Timestamp -> of(value) - is Boolean -> of(value) - is GeoPoint -> of(value) - is Blob -> of(value) - is DocumentReference -> of(value) - is Value -> of(value) - else -> TODO("Unknown type: $value") - } - } - - @JvmStatic - fun ofArray(value: Iterable): Constant { - return Constant(value) - } - - @JvmStatic - fun ofArray(value: Array): Constant { - return Constant(value) - } - - @JvmStatic - fun ofMap(value: Map): Constant { - return Constant(value) - } - - @JvmStatic - fun ofVector(value: DoubleArray): Constant { - // TODO: Vector is really a map, not a list - return Constant(value.asList()) - } - } - - internal fun toProto(): Value { - return encodeValue(value)!! - } -} - -data class Field internal constructor( - internal val path: FieldPath, - private var pipeline: Pipeline? = null -) : - Expr, Selectable { - companion object { - const val DOCUMENT_ID: String = "__name__" - - @JvmStatic - fun of(path: String): Field { - return Field(FieldPath.of(path)) - } - - @JvmStatic - fun ofAll(): Field { - return Field(FieldPath.of("")) - } - } - - internal fun toProto(): Value { - return Value.newBuilder().setFieldReferenceValue(path.toString()).build() - } -} - -data class Fields internal constructor(internal val fs: List? = null) : Expr, Selectable { - companion object { - @JvmStatic - fun of(f1: String, vararg f: String): Fields { - return Fields(listOf(Field.of(f1)) + f.map(Field.Companion::of)) - } - - @JvmStatic - fun ofAll(): Fields { - return Fields(listOf(Field.of(""))) - } - } -} - -data class AggregatorTarget -internal constructor( - internal val accumulator: Function.Accumulator, - internal val fieldName: String, - override var distinct: Boolean, -) : Selectable, Function.Accumulator - -open class Function(val name: String, val params: List) : Expr { - interface FilterCondition : Expr - - interface Accumulator : Expr { - var distinct: Boolean - - fun distinct(on: Boolean): Accumulator { - this.distinct = on - return this - } - - fun toField(target: String) = AggregatorTarget(this, target, this.distinct) - } - - internal fun toProto(): Value { - return Value.newBuilder() - .setFunctionValue( - com.google.firestore.v1.Function.newBuilder() - .setName(name) - .addAllArgs(params.map { exprToValue(it) }) - ) - .build() - } - - data class Equal internal constructor(private val left: Expr, private val right: Expr) : - Function("eq", listOf(left, right)), FilterCondition - - data class NotEqual internal constructor(private val left: Expr, private val right: Expr) : - Function("neq", listOf(left, right)), FilterCondition - - data class GreaterThan internal constructor(private val left: Expr, private val right: Expr) : - Function("gt", listOf(left, right)), FilterCondition - - data class GreaterThanOrEqual internal constructor( - private val left: Expr, - private val right: Expr - ) : - Function("gte", listOf(left, right)), FilterCondition - - data class LessThan internal constructor(private val left: Expr, private val right: Expr) : - Function("lt", listOf(left, right)), FilterCondition - - data class LessThanOrEqual internal constructor(private val left: Expr, private val right: Expr) : - Function("lte", listOf(left, right)), FilterCondition - - data class In internal constructor(private val left: Expr, private val others: List) : - Function("in", listOf(left, ListOfExprs(others))), FilterCondition // For 'in' - - data class And internal constructor(private val conditions: List) : - Function("and", conditions), - FilterCondition where - T : FilterCondition - - data class Or internal constructor(private val conditions: List) : - Function("or", conditions), - FilterCondition where - T : FilterCondition - - data class Not internal constructor(private val condition: Expr) : - Function("not", listOf(condition)), FilterCondition - - data class ArrayContains internal constructor( - private val array: Expr, - private val element: Expr - ) : - Function("array_contains", listOf(array, element)), FilterCondition - - data class ArrayContainsAny internal constructor( - private val array: Expr, - private val elements: List - ) : - Function("array_contains_any", listOf(array, ListOfExprs(elements))), FilterCondition - - data class IsNaN internal constructor(private val value: Expr) : - Function("is_nan", listOf(value)), FilterCondition - - data class IsNull internal constructor(private val value: Expr) : - Function("is_null", listOf(value)), FilterCondition - - data class Sum internal constructor(private val value: Expr, override var distinct: Boolean) : - Function("sum", listOf(value)), Accumulator - - data class Avg internal constructor(private val value: Expr, override var distinct: Boolean) : - Function("avg", listOf(value)), Accumulator - - data class Count internal constructor(private val value: Expr?, override var distinct: Boolean) : - Function("count", value?.let { listOf(it) } ?: emptyList()), Accumulator - - data class Min internal constructor(private val value: Expr, override var distinct: Boolean) : - Function("min", listOf(value)), Accumulator - - data class Max internal constructor(private val value: Expr, override var distinct: Boolean) : - Function("max", listOf(value)), Accumulator - - data class CosineDistance internal constructor( - private val vector1: Expr, - private val vector2: Expr - ) : - Function("cosine_distance", listOf(vector1, vector2)) - - data class DotProductDistance internal constructor( - private val vector1: Expr, - private val vector2: Expr - ) : - Function("dot_product", listOf(vector1, vector2)) - - data class EuclideanDistance internal constructor( - private val vector1: Expr, - private val vector2: Expr - ) : - Function("euclidean_distance", listOf(vector1, vector2)) - - data class Generic internal constructor(private val n: String, private val ps: List) : - Function(n, ps) - - companion object { - @JvmStatic fun equal(left: Expr, right: Expr) = Equal(left, right) - - @JvmStatic fun equal(left: Expr, right: Any) = Equal(left, Constant.of(right)) - - @JvmStatic - fun equal(left: String, right: Expr) = Equal(Field.of(left), right) - - @JvmStatic - fun equal(left: String, right: Any) = Equal(Field.of(left), Constant.of(right)) - - @JvmStatic fun notEqual(left: Expr, right: Expr) = NotEqual(left, right) - - @JvmStatic fun notEqual(left: Expr, right: Any) = NotEqual(left, Constant.of(right)) - - @JvmStatic fun notEqual(left: String, right: Expr) = NotEqual(Field.of(left), right) - - @JvmStatic fun notEqual(left: String, right: Any) = NotEqual(Field.of(left), Constant.of(right)) - - @JvmStatic fun greaterThan(left: Expr, right: Expr) = GreaterThan(left, right) - - @JvmStatic fun greaterThan(left: Expr, right: Any) = GreaterThan(left, Constant.of(right)) - - @JvmStatic fun greaterThan(left: String, right: Expr) = GreaterThan(Field.of(left), right) - - @JvmStatic fun greaterThan(left: String, right: Any) = GreaterThan(Field.of(left), Constant.of(right)) - - @JvmStatic fun greaterThanOrEqual(left: Expr, right: Expr) = GreaterThanOrEqual(left, right) - - @JvmStatic - fun greaterThanOrEqual(left: Expr, right: Any) = GreaterThanOrEqual(left, Constant.of(right)) - - @JvmStatic fun greaterThanOrEqual(left: String, right: Expr) = GreaterThanOrEqual(Field.of(left), right) - - @JvmStatic - fun greaterThanOrEqual(left: String, right: Any) = GreaterThanOrEqual(Field.of(left), Constant.of(right)) - - @JvmStatic fun lessThan(left: Expr, right: Expr) = LessThan(left, right) - - @JvmStatic fun lessThan(left: Expr, right: Any) = LessThan(left, Constant.of(right)) - - @JvmStatic fun lessThan(left: String, right: Expr) = LessThan(Field.of(left), right) - - @JvmStatic fun lessThan(left: String, right: Any) = LessThan(Field.of(left), Constant.of(right)) - - @JvmStatic fun lessThanOrEqual(left: Expr, right: Expr) = LessThanOrEqual(left, right) - - @JvmStatic - fun lessThanOrEqual(left: Expr, right: Any) = LessThanOrEqual(left, Constant.of(right)) - - @JvmStatic fun lessThanOrEqual(left: String, right: Expr) = LessThanOrEqual(Field.of(left), right) - - @JvmStatic - fun lessThanOrEqual(left: String, right: Any) = LessThanOrEqual(Field.of(left), Constant.of(right)) - - @JvmStatic - fun inAny(left: Expr, values: List) = - In( - left, - values.map { - when (it) { - is Expr -> it - else -> Constant.of(it) - } - }, - ) - - @JvmStatic - fun inAny(left: String, values: List) = - In( - Field.of(left), - values.map { - when (it) { - is Expr -> it - else -> Constant.of(it) - } - }, - ) - - @JvmStatic - fun notInAny(left: Expr, values: List) = - Not( - In( - left, - values.map { - when (it) { - is Expr -> it - else -> Constant.of(it) - } - }, - ) - ) - - @JvmStatic - fun notInAny(left: String, values: List) = - Not( - In( - Field.of(left), - values.map { - when (it) { - is Expr -> it - else -> Constant.of(it) - } - }, - ) - ) - - - @JvmStatic - fun and(left: T, right: T) where T : FilterCondition, T : Expr = And(listOf(left, right)) - - @JvmStatic - fun and(left: T, vararg other: T) where T : FilterCondition, T : Expr = - And(listOf(left) + other.toList()) - - @JvmStatic - fun or(left: T, right: T) where T : FilterCondition, T : Expr = Or(listOf(left, right)) - - @JvmStatic - fun or(left: T, vararg other: T) where T : FilterCondition, T : Expr = - Or(listOf(left) + other.toList()) - - @JvmStatic fun arrayContains(expr: Expr, element: Expr) = ArrayContains(expr, element) - - @JvmStatic - fun arrayContains(field: String, element: Expr) = ArrayContains(Field.of(field), element) - - @JvmStatic - fun arrayContains(expr: Expr, element: Any) = ArrayContains(expr, Constant.of(element)) - - @JvmStatic - fun arrayContains(field: String, element: Any) = - ArrayContains(Field.of(field), Constant.of(element)) - - @JvmStatic - fun arrayContainsAny(expr: Expr, vararg elements: Expr) = - ArrayContainsAny(expr, elements.toList()) - - @JvmStatic - fun arrayContainsAny(expr: Expr, vararg elements: Any) = - ArrayContainsAny(expr, elements.toList().map { Constant.of(it) }) - - @JvmStatic - fun arrayContainsAny(field: String, vararg elements: Expr) = - ArrayContainsAny(Field.of(field), elements.toList()) - - @JvmStatic - fun arrayContainsAny(field: String, vararg elements: Any) = - ArrayContainsAny(Field.of(field), elements.toList().map { Constant.of(it) }) - - @JvmStatic fun isNaN(expr: Expr) = IsNaN(expr) - - @JvmStatic - fun isNaN(field: String) = IsNaN(Field.of(field)) - - @JvmStatic fun isNull(expr: Expr) = IsNull(expr) - - @JvmStatic - fun isNull(field: String) = IsNull(Field.of(field)) - - @JvmStatic fun not(expr: Expr) = Not(expr) - - @JvmStatic fun sum(expr: Expr) = Sum(expr, false) - - @JvmStatic - fun sum(field: String) = Sum(Field.of(field), false) - - @JvmStatic fun avg(expr: Expr) = Avg(expr, false) - - @JvmStatic - fun avg(field: String) = Avg(Field.of(field), false) - - @JvmStatic fun min(expr: Expr) = Sum(expr, false) - - @JvmStatic - fun min(field: String) = Sum(Field.of(field), false) - - @JvmStatic fun max(expr: Expr) = Avg(expr, false) - - @JvmStatic - fun max(field: String) = Avg(Field.of(field), false) - - @JvmStatic fun count(expr: Expr) = Count(expr, false) - - @JvmStatic - fun count(field: String) = Count(Field.of(field), false) - - @JvmStatic fun countAll() = Count(null, false) - - @JvmStatic fun cosineDistance(expr: Expr, other: Expr) = CosineDistance(expr, other) - - @JvmStatic - fun cosineDistance(expr: Expr, other: DoubleArray) = - CosineDistance(expr, Constant.ofVector(other)) - - @JvmStatic - fun cosineDistance(field: String, other: Expr) = CosineDistance(Field.of(field), other) - - @JvmStatic - fun cosineDistance(field: String, other: DoubleArray) = - CosineDistance(Field.of(field), Constant.ofVector(other)) - - @JvmStatic fun dotProductDistance(expr: Expr, other: Expr) = CosineDistance(expr, other) - - @JvmStatic - fun dotProductDistance(expr: Expr, other: DoubleArray) = - CosineDistance(expr, Constant.ofVector(other)) - - @JvmStatic - fun dotProductDistance(field: String, other: Expr) = CosineDistance(Field.of(field), other) - - @JvmStatic - fun dotProductDistance(field: String, other: DoubleArray) = - CosineDistance(Field.of(field), Constant.ofVector(other)) - - @JvmStatic fun euclideanDistance(expr: Expr, other: Expr) = EuclideanDistance(expr, other) - - @JvmStatic - fun euclideanDistance(expr: Expr, other: DoubleArray) = - EuclideanDistance(expr, Constant.ofVector(other)) - - @JvmStatic - fun euclideanDistance(field: String, other: Expr) = EuclideanDistance(Field.of(field), other) - - @JvmStatic - fun euclideanDistance(field: String, other: DoubleArray) = - EuclideanDistance(Field.of(field), Constant.ofVector(other)) - - @JvmStatic fun function(name: String, params: List) = Generic(name, params) - } -} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/PaginatingPipeline.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/PaginatingPipeline.java new file mode 100644 index 000000000..e6289808b --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/PaginatingPipeline.java @@ -0,0 +1,75 @@ +package com.google.cloud.firestore.pipeline; + +import com.google.cloud.firestore.Pipeline; +import com.google.cloud.firestore.PipelineResult; +import com.google.cloud.firestore.pipeline.expressions.Ordering; +import com.google.firestore.v1.Cursor; +import java.util.List; + +public class PaginatingPipeline { + private final Pipeline p; + private final int pageSize; + private final List orders; + private final Integer offset; + private final Cursor startCursor; + private final Cursor endCursor; + + public PaginatingPipeline(Pipeline p, int pageSize, List orders) { + this(p, pageSize, orders, null, null, null); + } + + private PaginatingPipeline( + Pipeline p, + int pageSize, + List orders, + Integer offset, + Cursor startCursor, + Cursor endCursor) { + this.p = p; + this.pageSize = pageSize; + this.orders = orders; + this.offset = offset; + this.startCursor = startCursor; + this.endCursor = endCursor; + } + + public Pipeline firstPage() { + return this.p; + } + + public Pipeline lastPage() { + return this.p; + } + + public PaginatingPipeline startAt(PipelineResult result) { + return this; + } + + public PaginatingPipeline startAfter(PipelineResult result) { + return this; + } + + public PaginatingPipeline endAt(PipelineResult result) { + return this; + } + + public PaginatingPipeline endBefore(PipelineResult result) { + return this; + } + + public PaginatingPipeline offset(int offset) { + return this; + } + + public PaginatingPipeline limit(int limit) { + return this; + } + + public PaginatingPipeline withStartCursor(Cursor cursor) { + return this; + } + + public PaginatingPipeline withEndCursor(Cursor cursor) { + return this; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt deleted file mode 100644 index b415b94f6..000000000 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/Stages.kt +++ /dev/null @@ -1,265 +0,0 @@ -@file:JvmName("Stages") -package com.google.cloud.firestore.pipeline - -import com.google.cloud.firestore.DocumentReference -import com.google.cloud.firestore.encodeValue -import com.google.firestore.v1.MapValue -import com.google.firestore.v1.Value -import java.util.Locale - -internal interface Stage - -internal data class Collection(internal val relativePath: String) : Stage { - val name = "collection" -} - -internal data class CollectionGroup(internal val collectionId: String) : Stage { - val name = "collection_group" -} - -internal class Database : Stage { - val name = "database" -} - -internal data class Documents(internal val documents: List) : Stage { - val name = "documents" - - companion object { - @JvmStatic - fun of(vararg documents: DocumentReference): Documents { - return Documents(documents.map { "/" + it.path }) - } - } -} - -internal data class Select(internal val projections: Map) : Stage { - val name = "select" -} - -internal data class AddFields(internal val fields: Map) : Stage { - val name = "add_fields" -} - -internal data class Filter(internal val condition: T) : Stage where -T : Function.FilterCondition, -T : Expr { - val name = "filter" -} - -internal class Offset(internal val offset: Int) : Stage { - val name = "offset" -} - -internal class Limit(internal val limit: Int) : Stage { - val name = "limit" -} - -class Aggregate -internal constructor( - internal val groups: Map, - internal val accumulators: Map, -) : Stage { - val name = "aggregate" - - internal constructor( - vararg aggregators: AggregatorTarget - ) : this(emptyMap(), aggregators.associate { it.fieldName to it.accumulator }) -} - -class FindNearest -internal constructor( - internal val property: Field, - internal val vector: DoubleArray, - internal val distanceMeasure: DistanceMeasure, - internal val options: FindNearestOptions, -) : Stage { - val name = "find_nearest" - - interface DistanceMeasure { - data object Euclidean : DistanceMeasure - - data object Cosine : DistanceMeasure - - data object DotProduct : DistanceMeasure - - class GenericDistanceMeasure(val name: String) : DistanceMeasure - - fun toProtoString(): String { - return when (this) { - is Euclidean -> "euclidean" - is Cosine -> "cosine" - is DotProduct -> "dot_product" - is GenericDistanceMeasure -> name - else -> throw IllegalArgumentException("Unknown distance measure") - } - } - - companion object { - @JvmStatic fun euclidean() = Euclidean - - @JvmStatic fun cosine() = Cosine - - @JvmStatic fun dotProduct() = DotProduct - - @JvmStatic fun generic(name: String) = GenericDistanceMeasure(name) - } - } - - class FindNearestOptions internal constructor( - val limit: Long, - val distanceMeasure: DistanceMeasure, - val output: Field? = null - ) { - companion object { - @JvmStatic - fun newInstance(limit: Long, distanceMeasure: DistanceMeasure, output: Field? = null) = - FindNearestOptions(limit, distanceMeasure, output) - } - } -} - -class Sort -internal constructor( - internal val orders: List, - internal val density: Density = Density.UNSPECIFIED, - internal val truncation: Truncation = Truncation.UNSPECIFIED, -) : Stage { - val name = "sort" - - enum class Density { - UNSPECIFIED, - REQUIRED; - - override fun toString(): String = name.lowercase(Locale.getDefault()) - } - - enum class Truncation { - UNSPECIFIED, - DISABLED; - - override fun toString(): String = name.lowercase(Locale.getDefault()) - } - - class Ordering - internal constructor(private val expr: Expr, private val dir: Direction = Direction.ASCENDING) { - enum class Direction { - ASCENDING, - DESCENDING; - - override fun toString(): String = name.lowercase(Locale.getDefault()) - } - - internal fun toProto(): Value { - return Value.newBuilder() - .setMapValue( - MapValue.newBuilder() - .putFields("direction", encodeValue(dir.toString())) - .putFields("expression", encodeValue(expr)) - .build() - ) - .build() - } - - companion object { - @JvmStatic - fun of(expr: Expr, dir: Direction = Direction.ASCENDING): Ordering { - return Ordering(expr, dir) - } - - @JvmStatic - fun of(expr: Expr): Ordering { - return Ordering(expr, Direction.ASCENDING) - } - - @JvmStatic - fun ascending(expr: Expr): Ordering { - return Ordering(expr, Direction.ASCENDING) - } - - @JvmStatic - fun descending(expr: Expr): Ordering { - return Ordering(expr, Direction.DESCENDING) - } - } - } -} - -internal class GenericStage(internal val name: String, internal val params: List) : Stage {} - -internal fun toStageProto(stage: Stage): com.google.firestore.v1.Pipeline.Stage { - return when (stage) { - is Collection -> - com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addArgs(Value.newBuilder().setReferenceValue("").build()) - .addArgs(Value.newBuilder().setStringValue(stage.relativePath).build()) - .build() - is CollectionGroup -> - com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addArgs(Value.newBuilder().setReferenceValue("").build()) - .addArgs(encodeValue(stage.collectionId)) - .build() - is Database -> com.google.firestore.v1.Pipeline.Stage.newBuilder().setName(stage.name).build() - is Documents -> - com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addAllArgs(stage.documents.map { Value.newBuilder().setReferenceValue(it).build() }) - .build() - is Select -> - com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addArgs(encodeValue(stage.projections)) - .build() - is AddFields -> - com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addArgs(encodeValue(stage.fields)) - .build() - is Filter<*> -> - com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addArgs(encodeValue(stage.condition)) - .build() - is Sort -> - com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addAllArgs(stage.orders.map { it.toProto() }) - .putOptions("density", encodeValue(stage.density.toString())) - .putOptions("truncation", encodeValue(stage.truncation.toString())) - .build() - is Offset -> - com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addArgs(encodeValue(stage.offset)) - .build() - is Limit -> - com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addArgs(encodeValue(stage.limit)) - .build() - is Aggregate -> - com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addArgs(encodeValue(stage.groups)) - .addArgs(encodeValue(stage.accumulators)) - .build() - is FindNearest -> - com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addArgs(encodeValue(stage.property)) - .addArgs(encodeValue(stage.vector)) - .addArgs(encodeValue(stage.distanceMeasure.toProtoString())) - .putOptions("limit", encodeValue(stage.options.limit)) - .putOptions("distance_field", encodeValue(stage.options.output)) - .build() - is GenericStage -> - com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(stage.name) - .addAllArgs(stage.params.map { encodeValue(it) }) - .build() - else -> { - TODO() - } - } -} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Accumulator.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Accumulator.java new file mode 100644 index 000000000..9c517392c --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Accumulator.java @@ -0,0 +1,7 @@ +package com.google.cloud.firestore.pipeline.expressions; + +public interface Accumulator extends Expr { + default AggregatorTarget toField(String fieldName) { + return new AggregatorTarget(this, fieldName, false); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AggregatorTarget.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AggregatorTarget.java new file mode 100644 index 000000000..d8aa4d43d --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AggregatorTarget.java @@ -0,0 +1,25 @@ +package com.google.cloud.firestore.pipeline.expressions; + +public final class AggregatorTarget implements Selectable, Accumulator { + private final Accumulator accumulator; + private final String fieldName; + + AggregatorTarget(Accumulator accumulator, String fieldName, boolean distinct) { + this.accumulator = accumulator; + this.fieldName = fieldName; + } + + // Getters (for accumulator, fieldName, and distinct) + public Accumulator getAccumulator() { + return accumulator; + } + + public String getFieldName() { + return fieldName; + } + + @Override + public AggregatorTarget toField(String fieldName) { + return null; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/And.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/And.java new file mode 100644 index 000000000..4831fccbd --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/And.java @@ -0,0 +1,11 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.api.core.InternalApi; +import java.util.List; + +public final class And extends Function implements FilterCondition { + @InternalApi + And(List conditions) { + super("and", conditions); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContains.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContains.java new file mode 100644 index 000000000..0d03f5184 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContains.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class ArrayContains extends Function implements FilterCondition { + ArrayContains(Expr array, Expr element) { + super("array_contains", Lists.newArrayList(array, element)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContainsAny.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContainsAny.java new file mode 100644 index 000000000..0520e26d8 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContainsAny.java @@ -0,0 +1,10 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; +import java.util.List; + +public final class ArrayContainsAny extends Function implements FilterCondition { + ArrayContainsAny(Expr array, List elements) { + super("array_contains_any", Lists.newArrayList(array, new ListOfExprs(elements))); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Avg.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Avg.java new file mode 100644 index 000000000..d83560bcc --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Avg.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class Avg extends Function implements Accumulator { + Avg(Expr value, boolean distinct) { + super("avg", Lists.newArrayList(value)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Constant.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Constant.java new file mode 100644 index 000000000..58aa62957 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Constant.java @@ -0,0 +1,106 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import static com.google.cloud.firestore.PipelineUtils.encodeValue; + +import com.google.cloud.Timestamp; +import com.google.cloud.firestore.Blob; +import com.google.cloud.firestore.DocumentReference; +import com.google.cloud.firestore.GeoPoint; +import com.google.firestore.v1.Value; +import java.util.Arrays; +import java.util.Date; +import java.util.Map; +import java.util.stream.Collectors; + +public final class Constant implements Expr { + private final Object value; + + private Constant(Object value) { + this.value = value; + } + + public static Constant of(String value) { + return new Constant(value); + } + + public static Constant of(Number value) { + return new Constant(value); + } + + public static Constant of(Date value) { + return new Constant(value); + } + + public static Constant of(Timestamp value) { + return new Constant(value); + } + + public static Constant of(Boolean value) { + return new Constant(value); + } + + public static Constant of(GeoPoint value) { + return new Constant(value); + } + + public static Constant of(Blob value) { + return new Constant(value); + } + + public static Constant of(DocumentReference value) { + return new Constant(value); + } + + public static Constant of(Value value) { + return new Constant(value); + } + + static Constant of(Object value) { + if (value == null) { + return new Constant(null); + } + + if (value instanceof String) { + return of((String) value); + } else if (value instanceof Number) { + return of((Number) value); + } else if (value instanceof Date) { + return of((Date) value); + } else if (value instanceof Timestamp) { + return of((Timestamp) value); + } else if (value instanceof Boolean) { + return of((Boolean) value); + } else if (value instanceof GeoPoint) { + return of((GeoPoint) value); + } else if (value instanceof Blob) { + return of((Blob) value); + } else if (value instanceof DocumentReference) { + return of((DocumentReference) value); + } else if (value instanceof Value) { + return of((Value) value); + } else { + throw new IllegalArgumentException("Unknown type: " + value); + } + } + + public static Constant ofArray(Iterable value) { + return new Constant(value); + } + + public static Constant ofArray(T[] value) { + return new Constant(Arrays.asList(value)); // Convert array to list + } + + public static Constant ofMap(Map value) { + return new Constant(value); + } + + public static Constant ofVector(double[] value) { + // Convert double array to List + return new Constant(Arrays.stream(value).boxed().collect(Collectors.toList())); + } + + public Value toProto() { + return encodeValue(value); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CosineDistance.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CosineDistance.java new file mode 100644 index 000000000..7767eab30 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CosineDistance.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class CosineDistance extends Function { + CosineDistance(Expr vector1, Expr vector2) { + super("cosine_distance", Lists.newArrayList(vector1, vector2)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Count.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Count.java new file mode 100644 index 000000000..a16129498 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Count.java @@ -0,0 +1,10 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; +import java.util.Collections; + +public final class Count extends Function implements Accumulator { + Count(Expr value, boolean distinct) { + super("count", (value != null) ? Lists.newArrayList(value) : Collections.emptyList()); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/DotProductDistance.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/DotProductDistance.java new file mode 100644 index 000000000..d88aeb342 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/DotProductDistance.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class DotProductDistance extends Function { + DotProductDistance(Expr vector1, Expr vector2) { + super("dot_product", Lists.newArrayList(vector1, vector2)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Equal.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Equal.java new file mode 100644 index 000000000..e9820e9f9 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Equal.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class Equal extends Function implements FilterCondition { + Equal(Expr left, Expr right) { + super("eq", Lists.newArrayList(left, right)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/EuclideanDistance.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/EuclideanDistance.java new file mode 100644 index 000000000..8ee207f66 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/EuclideanDistance.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class EuclideanDistance extends Function { + EuclideanDistance(Expr vector1, Expr vector2) { + super("euclidean_distance", Lists.newArrayList(vector1, vector2)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java new file mode 100644 index 000000000..b65c98247 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java @@ -0,0 +1,172 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.api.core.InternalApi; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public interface Expr { + default Equal equal(Expr expr) { + return new Equal(this, expr); + } + + default Equal equal(Object other) { + return new Equal(this, Constant.of(other)); + } + + default NotEqual notEqual(Expr other) { + return new NotEqual(this, other); + } + + default NotEqual notEqual(Object other) { + return new NotEqual(this, Constant.of(other)); + } + + default GreaterThan greaterThan(Expr other) { + return new GreaterThan(this, other); + } + + default GreaterThan greaterThan(Object other) { + return new GreaterThan(this, Constant.of(other)); + } + + default GreaterThanOrEqual greaterThanOrEqual(Expr other) { + return new GreaterThanOrEqual(this, other); + } + + default GreaterThanOrEqual greaterThanOrEqual(Object other) { + return new GreaterThanOrEqual(this, Constant.of(other)); + } + + default LessThan lessThan(Expr other) { + return new LessThan(this, other); + } + + default LessThan lessThan(Object other) { + return new LessThan(this, Constant.of(other)); + } + + default LessThanOrEqual lessThanOrEqual(Expr other) { + return new LessThanOrEqual(this, other); + } + + default LessThanOrEqual lessThanOrEqual(Object other) { + return new LessThanOrEqual(this, Constant.of(other)); + } + + default In inAny(Object... other) { + List othersAsExpr = + Arrays.stream(other) + .map(obj -> (obj instanceof Expr) ? (Expr) obj : Constant.of(obj)) + .collect(Collectors.toList()); + return new In(this, othersAsExpr); + } + + default Not notInAny(Object... other) { + return new Not(inAny(other)); + } + + default ArrayContains arrayContains(Expr element) { + return new ArrayContains(this, element); + } + + default ArrayContains arrayContains(Object element) { + return new ArrayContains(this, Constant.of(element)); + } + + default ArrayContainsAny arrayContainsAny(Expr... elements) { + return new ArrayContainsAny(this, Arrays.asList(elements)); + } + + default ArrayContainsAny arrayContainsAny(Object... elements) { + return new ArrayContainsAny( + this, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + } + + default IsNaN isNaN() { + return new IsNaN(this); + } + + default IsNull isNull() { + return new IsNull(this); + } + + default Sum sum() { + return new Sum(this, false); + } + + default Avg avg() { + return new Avg(this, false); + } + + default Count count() { + return new Count(this, false); + } + + default Min min() { + return new Min(this, false); + } + + default Max max() { + return new Max(this, false); + } + + default CosineDistance cosineDistance(Expr other) { + return new CosineDistance(this, other); + } + + default CosineDistance cosineDistance(double[] other) { + return new CosineDistance(this, Constant.ofVector(other)); + } + + default EuclideanDistance euclideanDistance(Expr other) { + return new EuclideanDistance(this, other); + } + + default EuclideanDistance euclideanDistance(double[] other) { + return new EuclideanDistance(this, Constant.ofVector(other)); + } + + default DotProductDistance dotProductDistance(Expr other) { + return new DotProductDistance(this, other); + } + + default DotProductDistance dotProductDistance(double[] other) { + return new DotProductDistance(this, Constant.ofVector(other)); + } + + default Ordering ascending() { + return Ordering.ascending(this); + } + + default Ordering descending() { + return Ordering.descending(this); + } + + default Selectable asAlias(String alias) { + return new ExprWithAlias(this, alias); + } +} + +@InternalApi +final class ExprWithAlias implements Selectable { + + private final String alias; + private final Expr expr; + + @InternalApi + ExprWithAlias(Expr expr, String alias) { + this.expr = expr; + this.alias = alias; + } + + @InternalApi + String getAlias() { + return alias; + } + + @InternalApi + Expr getExpr() { + return expr; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java new file mode 100644 index 000000000..27a1fdd3a --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java @@ -0,0 +1,37 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.cloud.firestore.FieldPath; +import com.google.cloud.firestore.Pipeline; +import com.google.firestore.v1.Value; +import javax.annotation.Nullable; + +public final class Field implements Expr, Selectable { + public static final String DOCUMENT_ID = "__name__"; + private final FieldPath path; + @Nullable private Pipeline pipeline; // Nullable + + private Field(FieldPath path) { + this.path = path; + } + + public static Field of(String path) { + return new Field(FieldPath.of(path)); + } + + public static Field ofAll() { + return new Field(FieldPath.of("")); + } + + public Value toProto() { + return Value.newBuilder().setFieldReferenceValue(path.toString()).build(); + } + + // Getters + public FieldPath getPath() { + return path; + } + + public Pipeline getPipeline() { + return pipeline; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Fields.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Fields.java new file mode 100644 index 000000000..7cb6cda2f --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Fields.java @@ -0,0 +1,29 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public final class Fields implements Expr, Selectable { + private final List fields; + + private Fields(List fs) { + this.fields = fs; + } + + public static Fields of(String f1, String... f) { + List fields = Arrays.stream(f).map(Field::of).collect(Collectors.toList()); + fields.add(0, Field.of(f1)); // Add f1 at the beginning + return new Fields(fields); + } + + public static Fields ofAll() { + return new Fields(Collections.singletonList(Field.of(""))); + } + + // Getters + public List getFields() { + return fields; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/FilterCondition.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/FilterCondition.java new file mode 100644 index 000000000..f182e4d30 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/FilterCondition.java @@ -0,0 +1,3 @@ +package com.google.cloud.firestore.pipeline.expressions; + +public interface FilterCondition extends Expr {} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java new file mode 100644 index 000000000..6cdfcea01 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java @@ -0,0 +1,323 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; +import com.google.firestore.v1.Value; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public class Function implements Expr { + private final String name; + private final List params; + + protected Function(String name, List params) { + this.name = name; + this.params = Collections.unmodifiableList(params); + } + + Value toProto() { + return Value.newBuilder() + .setFunctionValue( + com.google.firestore.v1.Function.newBuilder() + .setName(this.name) + .addAllArgs( + this.params.stream() + .map(FunctionUtils::exprToValue) + .collect(Collectors.toList()))) + .build(); + } + + public static Equal equal(Expr left, Expr right) { + return new Equal(left, right); + } + + public static Equal equal(Expr left, Object right) { + return new Equal(left, Constant.of(right)); + } + + public static Equal equal(String left, Expr right) { + return new Equal(Field.of(left), right); + } + + public static Equal equal(String left, Object right) { + return new Equal(Field.of(left), Constant.of(right)); + } + + public static NotEqual notEqual(Expr left, Expr right) { + return new NotEqual(left, right); + } + + public static NotEqual notEqual(Expr left, Object right) { + return new NotEqual(left, Constant.of(right)); + } + + public static NotEqual notEqual(String left, Expr right) { + return new NotEqual(Field.of(left), right); + } + + public static NotEqual notEqual(String left, Object right) { + return new NotEqual(Field.of(left), Constant.of(right)); + } + + public static GreaterThan greaterThan(Expr left, Expr right) { + return new GreaterThan(left, right); + } + + public static GreaterThan greaterThan(Expr left, Object right) { + return new GreaterThan(left, Constant.of(right)); + } + + public static GreaterThan greaterThan(String left, Expr right) { + return new GreaterThan(Field.of(left), right); + } + + public static GreaterThan greaterThan(String left, Object right) { + return new GreaterThan(Field.of(left), Constant.of(right)); + } + + public static GreaterThanOrEqual greaterThanOrEqual(Expr left, Expr right) { + return new GreaterThanOrEqual(left, right); + } + + public static GreaterThanOrEqual greaterThanOrEqual(Expr left, Object right) { + return new GreaterThanOrEqual(left, Constant.of(right)); + } + + public static GreaterThanOrEqual greaterThanOrEqual(String left, Expr right) { + return new GreaterThanOrEqual(Field.of(left), right); + } + + public static GreaterThanOrEqual greaterThanOrEqual(String left, Object right) { + return new GreaterThanOrEqual(Field.of(left), Constant.of(right)); + } + + public static LessThan lessThan(Expr left, Expr right) { + return new LessThan(left, right); + } + + public static LessThan lessThan(Expr left, Object right) { + return new LessThan(left, Constant.of(right)); + } + + public static LessThan lessThan(String left, Expr right) { + return new LessThan(Field.of(left), right); + } + + public static LessThan lessThan(String left, Object right) { + return new LessThan(Field.of(left), Constant.of(right)); + } + + public static LessThanOrEqual lessThanOrEqual(Expr left, Expr right) { + return new LessThanOrEqual(left, right); + } + + public static LessThanOrEqual lessThanOrEqual(Expr left, Object right) { + return new LessThanOrEqual(left, Constant.of(right)); + } + + public static LessThanOrEqual lessThanOrEqual(String left, Expr right) { + return new LessThanOrEqual(Field.of(left), right); + } + + public static LessThanOrEqual lessThanOrEqual(String left, Object right) { + return new LessThanOrEqual(Field.of(left), Constant.of(right)); + } + + public static In inAny(Expr left, List values) { + List othersAsExpr = + values.stream() + .map(obj -> (obj instanceof Expr) ? (Expr) obj : Constant.of(obj)) + .collect(Collectors.toList()); + return new In(left, othersAsExpr); + } + + public static In inAny(String left, List values) { + return inAny(Field.of(left), values); + } + + public static Not notInAny(Expr left, List values) { + return new Not(inAny(left, values)); + } + + public static Not notInAny(String left, List values) { + return new Not(inAny(Field.of(left), values)); + } + + public static And and(FilterCondition left, FilterCondition right) { + return new And(Lists.newArrayList(left, right)); + } + + public static And and(FilterCondition left, FilterCondition... other) { + List conditions = Lists.newArrayList(left); + conditions.addAll(Arrays.asList(other)); + return new And(conditions); + } + + public static Or or(FilterCondition left, FilterCondition right) { + return new Or(Lists.newArrayList(left, right)); + } + + public static Or or(FilterCondition left, FilterCondition... other) { + List conditions = Lists.newArrayList(left); + conditions.addAll(Arrays.asList(other)); + return new Or(conditions); + } + + // File: FunctionUtils.java (or similar) + + // ... other static methods ... + + public static ArrayContains arrayContains(Expr expr, Expr element) { + return new ArrayContains(expr, element); + } + + public static ArrayContains arrayContains(String field, Expr element) { + return new ArrayContains(Field.of(field), element); + } + + public static ArrayContains arrayContains(Expr expr, Object element) { + return new ArrayContains(expr, Constant.of(element)); + } + + public static ArrayContains arrayContains(String field, Object element) { + return new ArrayContains(Field.of(field), Constant.of(element)); + } + + public static ArrayContainsAny arrayContainsAny(Expr expr, Expr... elements) { + return new ArrayContainsAny(expr, Arrays.asList(elements)); + } + + public static ArrayContainsAny arrayContainsAny(Expr expr, Object... elements) { + return new ArrayContainsAny( + expr, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + } + + public static ArrayContainsAny arrayContainsAny(String field, Expr... elements) { + return new ArrayContainsAny(Field.of(field), Arrays.asList(elements)); + } + + public static ArrayContainsAny arrayContainsAny(String field, Object... elements) { + return new ArrayContainsAny( + Field.of(field), Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + } + + public static IsNaN isNaN(Expr expr) { + return new IsNaN(expr); + } + + public static IsNaN isNaN(String field) { + return new IsNaN(Field.of(field)); + } + + public static IsNull isNull(Expr expr) { + return new IsNull(expr); + } + + public static IsNull isNull(String field) { + return new IsNull(Field.of(field)); + } + + public static Not not(Expr expr) { + return new Not(expr); + } + + public static Sum sum(Expr expr) { + return new Sum(expr, false); + } + + public static Sum sum(String field) { + return new Sum(Field.of(field), false); + } + + public static Avg avg(Expr expr) { + return new Avg(expr, false); + } + + public static Avg avg(String field) { + return new Avg(Field.of(field), false); + } + + // Note: There seems to be a typo in the Kotlin code. + // `min` and `max` are calling `Sum` and `Avg` constructors respectively + public static Min min(Expr expr) { + return new Min(expr, false); // Corrected constructor call + } + + public static Min min(String field) { + return new Min(Field.of(field), false); // Corrected constructor call + } + + public static Max max(Expr expr) { + return new Max(expr, false); // Corrected constructor call + } + + public static Max max(String field) { + return new Max(Field.of(field), false); // Corrected constructor call + } + + public static Count count(Expr expr) { + return new Count(expr, false); + } + + public static Count count(String field) { + return new Count(Field.of(field), false); + } + + public static Count countAll() { + return new Count(null, false); + } + + public static CosineDistance cosineDistance(Expr expr, Expr other) { + return new CosineDistance(expr, other); + } + + public static CosineDistance cosineDistance(Expr expr, double[] other) { + return new CosineDistance(expr, Constant.ofVector(other)); + } + + public static CosineDistance cosineDistance(String field, Expr other) { + return new CosineDistance(Field.of(field), other); + } + + public static CosineDistance cosineDistance(String field, double[] other) { + return new CosineDistance(Field.of(field), Constant.ofVector(other)); + } + + // Typo in original code: dotProductDistance should return DotProductDistance objects + public static DotProductDistance dotProductDistance(Expr expr, Expr other) { + return new DotProductDistance(expr, other); + } + + public static DotProductDistance dotProductDistance(Expr expr, double[] other) { + return new DotProductDistance(expr, Constant.ofVector(other)); + } + + public static DotProductDistance dotProductDistance(String field, Expr other) { + return new DotProductDistance(Field.of(field), other); + } + + public static DotProductDistance dotProductDistance(String field, double[] other) { + return new DotProductDistance(Field.of(field), Constant.ofVector(other)); + } + + public static EuclideanDistance euclideanDistance(Expr expr, Expr other) { + return new EuclideanDistance(expr, other); + } + + public static EuclideanDistance euclideanDistance(Expr expr, double[] other) { + return new EuclideanDistance(expr, Constant.ofVector(other)); + } + + public static EuclideanDistance euclideanDistance(String field, Expr other) { + return new EuclideanDistance(Field.of(field), other); + } + + public static EuclideanDistance euclideanDistance(String field, double[] other) { + return new EuclideanDistance(Field.of(field), Constant.ofVector(other)); + } + + public static Generic function(String name, List params) { + return new Generic(name, params); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/FunctionUtils.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/FunctionUtils.java new file mode 100644 index 000000000..1345f87c5 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/FunctionUtils.java @@ -0,0 +1,32 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.api.core.InternalApi; +import com.google.firestore.v1.ArrayValue; +import com.google.firestore.v1.Value; +import java.util.stream.Collectors; + +@InternalApi +public final class FunctionUtils { + @InternalApi + public static Value exprToValue(Expr expr) { + if (expr instanceof Constant) { + return ((Constant) expr).toProto(); + } else if (expr instanceof Field) { + return ((Field) expr).toProto(); + } else if (expr instanceof Function) { + return ((Function) expr).toProto(); + } else if (expr instanceof ListOfExprs) { + ListOfExprs listOfExprs = (ListOfExprs) expr; + return Value.newBuilder() + .setArrayValue( + ArrayValue.newBuilder() + .addAllValues( + listOfExprs.getConditions().stream() + .map(FunctionUtils::exprToValue) + .collect(Collectors.toList()))) + .build(); + } else { + throw new IllegalArgumentException("Unsupported expression type: " + expr.getClass()); + } + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Generic.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Generic.java new file mode 100644 index 000000000..ea0df3862 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Generic.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import java.util.List; + +public final class Generic extends Function { + Generic(String name, List params) { + super(name, params); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/GreaterThan.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/GreaterThan.java new file mode 100644 index 000000000..97d846687 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/GreaterThan.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class GreaterThan extends Function implements FilterCondition { + GreaterThan(Expr left, Expr right) { + super("gt", Lists.newArrayList(left, right)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/GreaterThanOrEqual.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/GreaterThanOrEqual.java new file mode 100644 index 000000000..67e031d8f --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/GreaterThanOrEqual.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class GreaterThanOrEqual extends Function implements FilterCondition { + GreaterThanOrEqual(Expr left, Expr right) { + super("gte", Lists.newArrayList(left, right)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/In.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/In.java new file mode 100644 index 000000000..043939b52 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/In.java @@ -0,0 +1,10 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; +import java.util.List; + +public final class In extends Function implements FilterCondition { + In(Expr left, List others) { + super("in", Lists.newArrayList(left, new ListOfExprs(others))); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/IsNaN.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/IsNaN.java new file mode 100644 index 000000000..7db82b161 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/IsNaN.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class IsNaN extends Function implements FilterCondition { + IsNaN(Expr value) { + super("is_nan", Lists.newArrayList(value)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/IsNull.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/IsNull.java new file mode 100644 index 000000000..60f3cebf1 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/IsNull.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class IsNull extends Function implements FilterCondition { + IsNull(Expr value) { + super("is_null", Lists.newArrayList(value)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/LessThan.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/LessThan.java new file mode 100644 index 000000000..71b541988 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/LessThan.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class LessThan extends Function implements FilterCondition { + LessThan(Expr left, Expr right) { + super("lt", Lists.newArrayList(left, right)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/LessThanOrEqual.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/LessThanOrEqual.java new file mode 100644 index 000000000..3b7f76330 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/LessThanOrEqual.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class LessThanOrEqual extends Function implements FilterCondition { + LessThanOrEqual(Expr left, Expr right) { + super("lte", Lists.newArrayList(left, right)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ListOfExprs.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ListOfExprs.java new file mode 100644 index 000000000..f444a7c5d --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ListOfExprs.java @@ -0,0 +1,19 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.api.core.InternalApi; +import com.google.common.collect.ImmutableList; +import java.util.List; + +@InternalApi +public final class ListOfExprs implements Expr { + private final ImmutableList conditions; + + @InternalApi + ListOfExprs(List list) { + this.conditions = ImmutableList.copyOf(list); + } + + public List getConditions() { + return conditions; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Max.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Max.java new file mode 100644 index 000000000..4c3fa9ad9 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Max.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class Max extends Function implements Accumulator { + Max(Expr value, boolean distinct) { + super("max", Lists.newArrayList(value)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Min.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Min.java new file mode 100644 index 000000000..933574626 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Min.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class Min extends Function implements Accumulator { + Min(Expr value, boolean distinct) { + super("min", Lists.newArrayList(value)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Not.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Not.java new file mode 100644 index 000000000..04feb0132 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Not.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class Not extends Function implements FilterCondition { + Not(Expr condition) { + super("not", Lists.newArrayList(condition)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/NotEqual.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/NotEqual.java new file mode 100644 index 000000000..6a0967899 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/NotEqual.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class NotEqual extends Function implements FilterCondition { + NotEqual(Expr left, Expr right) { + super("neq", Lists.newArrayList(left, right)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Or.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Or.java new file mode 100644 index 000000000..1ece0bef9 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Or.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import java.util.List; + +public final class Or extends Function implements FilterCondition { + Or(List conditions) { + super("or", conditions); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Ordering.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Ordering.java new file mode 100644 index 000000000..307eafc22 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Ordering.java @@ -0,0 +1,65 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import static com.google.cloud.firestore.PipelineUtils.encodeValue; + +import com.google.api.core.InternalApi; +import com.google.firestore.v1.MapValue; +import com.google.firestore.v1.Value; +import java.util.Locale; + +public final class Ordering { + + private final Expr expr; + private Ordering.Direction dir = Ordering.Direction.ASCENDING; + + private Ordering(Expr expr, Ordering.Direction dir) { + this.expr = expr; + this.dir = dir; + } + + public enum Direction { + ASCENDING, + DESCENDING; + + @Override + public String toString() { + return name().toLowerCase(Locale.getDefault()); + } + } + + @InternalApi + public Value toProto() { + return Value.newBuilder() + .setMapValue( + MapValue.newBuilder() + .putFields("direction", encodeValue(dir.toString())) + .putFields("expression", encodeValue(expr)) + .build()) + .build(); + } + + public static Ordering of(Expr expr, Ordering.Direction dir) { + return new Ordering(expr, dir); + } + + public static Ordering of(Expr expr) { + return new Ordering(expr, Direction.ASCENDING); + } + + public static Ordering ascending(Expr expr) { + return new Ordering(expr, Direction.ASCENDING); + } + + public static Ordering descending(Expr expr) { + return new Ordering(expr, Direction.DESCENDING); + } + + // Getters + public Expr getExpr() { + return expr; + } + + public Ordering.Direction getDir() { + return dir; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Selectable.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Selectable.java new file mode 100644 index 000000000..1eba7fc80 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Selectable.java @@ -0,0 +1,3 @@ +package com.google.cloud.firestore.pipeline.expressions; + +public interface Selectable {} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Sum.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Sum.java new file mode 100644 index 000000000..7b700205e --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Sum.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class Sum extends Function implements Accumulator { + Sum(Expr value, boolean distinct) { + super("sum", Lists.newArrayList(value)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/AddFields.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/AddFields.java new file mode 100644 index 000000000..fe2c0d335 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/AddFields.java @@ -0,0 +1,26 @@ +package com.google.cloud.firestore.pipeline.stages; + +import com.google.api.core.InternalApi; +import com.google.cloud.firestore.pipeline.expressions.Expr; +import java.util.Map; + +@InternalApi +public final class AddFields implements Stage { + + private static final String name = "add_fields"; + private final Map fields; + + @InternalApi + public AddFields(Map fields) { + this.fields = fields; + } + + public Map getFields() { + return fields; + } + + @Override + public String getName() { + return name; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java new file mode 100644 index 000000000..817536289 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java @@ -0,0 +1,47 @@ +package com.google.cloud.firestore.pipeline.stages; + +import com.google.api.core.InternalApi; +import com.google.cloud.firestore.pipeline.expressions.Accumulator; +import com.google.cloud.firestore.pipeline.expressions.AggregatorTarget; +import com.google.cloud.firestore.pipeline.expressions.Expr; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; +import java.util.stream.Collectors; + +@InternalApi +public final class Aggregate implements Stage { + + private static final String name = "aggregate"; + private final Map groups; + private final Map accumulators; + + @InternalApi + Aggregate(Map groups, Map accumulators) { + this.groups = groups; + this.accumulators = accumulators; + } + + @InternalApi + public Aggregate(AggregatorTarget... aggregators) { + this( + Collections.emptyMap(), + Arrays.stream(aggregators) + .collect( + Collectors.toMap( + AggregatorTarget::getFieldName, AggregatorTarget::getAccumulator))); + } + + public Map getGroups() { + return groups; + } + + public Map getAccumulators() { + return accumulators; + } + + @Override + public String getName() { + return name; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Collection.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Collection.java new file mode 100644 index 000000000..c876c2ac0 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Collection.java @@ -0,0 +1,29 @@ +package com.google.cloud.firestore.pipeline.stages; + +import com.google.api.core.InternalApi; +import javax.annotation.Nonnull; + +@InternalApi +public final class Collection implements Stage { + + private static final String name = "collection"; + @Nonnull private final String path; + + @InternalApi + public Collection(@Nonnull String path) { + if (!path.startsWith("/")) { + this.path = "/" + path; + } else { + this.path = path; + } + } + + public String getPath() { + return path; + } + + @Override + public String getName() { + return name; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/CollectionGroup.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/CollectionGroup.java new file mode 100644 index 000000000..cd1789a80 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/CollectionGroup.java @@ -0,0 +1,24 @@ +package com.google.cloud.firestore.pipeline.stages; + +import com.google.api.core.InternalApi; + +@InternalApi +public final class CollectionGroup implements Stage { + + private static final String name = "collection_group"; + private final String collectionId; + + @InternalApi + public CollectionGroup(String collectionId) { + this.collectionId = collectionId; + } + + public String getCollectionId() { + return collectionId; + } + + @Override + public String getName() { + return name; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Database.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Database.java new file mode 100644 index 000000000..027077ac1 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Database.java @@ -0,0 +1,16 @@ +package com.google.cloud.firestore.pipeline.stages; + +import com.google.api.core.InternalApi; + +@InternalApi +public final class Database implements Stage { + private static final String name = "database"; + + @InternalApi + public Database() {} + + @Override + public String getName() { + return name; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Documents.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Documents.java new file mode 100644 index 000000000..be05c6578 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Documents.java @@ -0,0 +1,33 @@ +package com.google.cloud.firestore.pipeline.stages; + +import com.google.api.core.InternalApi; +import com.google.cloud.firestore.DocumentReference; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +@InternalApi +public final class Documents implements Stage { + + private static final String name = "documents"; + private List documents; + + @InternalApi + Documents(List documents) { + this.documents = documents; + } + + public static Documents of(DocumentReference... documents) { + return new Documents( + Arrays.stream(documents).map(doc -> "/" + doc.getPath()).collect(Collectors.toList())); + } + + public List getDocuments() { + return documents; + } + + @Override + public String getName() { + return name; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Filter.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Filter.java new file mode 100644 index 000000000..9b6d6c883 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Filter.java @@ -0,0 +1,25 @@ +package com.google.cloud.firestore.pipeline.stages; + +import com.google.api.core.InternalApi; +import com.google.cloud.firestore.pipeline.expressions.FilterCondition; + +@InternalApi +public final class Filter implements Stage { + + private static final String name = "filter"; + private final FilterCondition condition; + + @InternalApi + public Filter(FilterCondition condition) { + this.condition = condition; + } + + public FilterCondition getCondition() { + return condition; + } + + @Override + public String getName() { + return name; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/FindNearest.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/FindNearest.java new file mode 100644 index 000000000..a3257f9ac --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/FindNearest.java @@ -0,0 +1,135 @@ +package com.google.cloud.firestore.pipeline.stages; + +import com.google.api.core.InternalApi; +import com.google.cloud.firestore.pipeline.expressions.Field; + +@InternalApi +public final class FindNearest implements Stage { + + private static final String name = "find_nearest"; + private final Field property; + private final double[] vector; + private final FindNearest.FindNearestOptions options; + + @InternalApi + public FindNearest(Field property, double[] vector, FindNearest.FindNearestOptions options) { + this.property = property; + this.vector = vector; + this.options = options; + } + + @Override + public String getName() { + return name; + } + + public Field getProperty() { + return property; + } + + public double[] getVector() { + return vector; + } + + public FindNearestOptions getOptions() { + return options; + } + + // Nested interfaces and classes + public interface DistanceMeasure { + + enum Type { + EUCLIDEAN, + COSINE, + DOT_PRODUCT + } + + static FindNearest.DistanceMeasure euclidean() { + return new FindNearest.EuclideanDistanceMeasure(); + } + + static FindNearest.DistanceMeasure cosine() { + return new FindNearest.CosineDistanceMeasure(); + } + + static FindNearest.DistanceMeasure dotProduct() { + return new FindNearest.DotProductDistanceMeasure(); + } + + static FindNearest.DistanceMeasure generic(String name) { + return new FindNearest.GenericDistanceMeasure(name); + } + + @InternalApi + String toProtoString(); + } + + static class EuclideanDistanceMeasure implements FindNearest.DistanceMeasure { + + @Override + public String toProtoString() { + return "euclidean"; + } + } + + static class CosineDistanceMeasure implements FindNearest.DistanceMeasure { + + @Override + public String toProtoString() { + return "cosine"; + } + } + + static class DotProductDistanceMeasure implements FindNearest.DistanceMeasure { + + @Override + public String toProtoString() { + return "dot_product"; + } + } + + static class GenericDistanceMeasure implements FindNearest.DistanceMeasure { + + String name; + + public GenericDistanceMeasure(String name) { + this.name = name; + } + + @Override + public String toProtoString() { + return name; + } + } + + public static class FindNearestOptions { + + private final Long limit; + private final FindNearest.DistanceMeasure distanceMeasure; + private final Field output; + + private FindNearestOptions( + Long limit, FindNearest.DistanceMeasure distanceMeasure, Field output) { + this.limit = limit; + this.distanceMeasure = distanceMeasure; + this.output = output; + } + + public static FindNearest.FindNearestOptions newInstance( + long limit, FindNearest.DistanceMeasure distanceMeasure, Field output) { + return new FindNearest.FindNearestOptions(limit, distanceMeasure, output); + } + + public Long getLimit() { + return limit; + } + + public DistanceMeasure getDistanceMeasure() { + return distanceMeasure; + } + + public Field getOutput() { + return output; + } + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/GenericStage.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/GenericStage.java new file mode 100644 index 000000000..33d677db1 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/GenericStage.java @@ -0,0 +1,27 @@ +package com.google.cloud.firestore.pipeline.stages; + +import com.google.api.core.InternalApi; +import java.util.List; + +@InternalApi +public final class GenericStage implements Stage { + + private final String name; + private List params; + + @InternalApi + public GenericStage(String name, List params) { + this.name = name; + this.params = params; + } + + @Override + public String getName() { + return name; + } + + @InternalApi + public List getParams() { + return params; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Limit.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Limit.java new file mode 100644 index 000000000..b7021b494 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Limit.java @@ -0,0 +1,24 @@ +package com.google.cloud.firestore.pipeline.stages; + +import com.google.api.core.InternalApi; + +@InternalApi +public final class Limit implements Stage { + + private static final String name = "limit"; + private int limit; + + @InternalApi + public Limit(int limit) { + this.limit = limit; + } + + public int getLimit() { + return limit; + } + + @Override + public String getName() { + return name; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Offset.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Offset.java new file mode 100644 index 000000000..e6350bf9b --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Offset.java @@ -0,0 +1,24 @@ +package com.google.cloud.firestore.pipeline.stages; + +import com.google.api.core.InternalApi; + +@InternalApi +public final class Offset implements Stage { + + private static final String name = "offset"; + private final int offset; + + @InternalApi + public Offset(int offset) { + this.offset = offset; + } + + public int getOffset() { + return offset; + } + + @Override + public String getName() { + return name; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Select.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Select.java new file mode 100644 index 000000000..6d4c47ab5 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Select.java @@ -0,0 +1,26 @@ +package com.google.cloud.firestore.pipeline.stages; + +import com.google.api.core.InternalApi; +import com.google.cloud.firestore.pipeline.expressions.Expr; +import java.util.Map; + +@InternalApi +public final class Select implements Stage { + + private static final String name = "select"; + private final Map projections; + + @InternalApi + public Select(Map projections) { + this.projections = projections; + } + + public Map getProjections() { + return projections; + } + + @Override + public String getName() { + return name; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Sort.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Sort.java new file mode 100644 index 000000000..3cec1a214 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Sort.java @@ -0,0 +1,65 @@ +package com.google.cloud.firestore.pipeline.stages; + +import com.google.api.core.InternalApi; +import com.google.cloud.firestore.pipeline.expressions.Ordering; +import java.util.List; +import java.util.Locale; + +@InternalApi +public final class Sort implements Stage { + + private static final String name = "sort"; + private final List orders; + private final Sort.Density density; + private final Sort.Truncation truncation; + + @InternalApi + public Sort(List orders, Sort.Density density, Sort.Truncation truncation) { + this.orders = orders; + this.density = density; + this.truncation = truncation; + } + + // Getters + public String getName() { + return name; + } + + public List getOrders() { + return orders; + } + + public Sort.Density getDensity() { + if (density != null) { + return density; + } + return Density.UNSPECIFIED; + } + + public Sort.Truncation getTruncation() { + if (truncation != null) { + return truncation; + } + return Truncation.UNSPECIFIED; + } + + public enum Density { + UNSPECIFIED, + REQUIRED; + + @Override + public String toString() { + return name().toLowerCase(Locale.getDefault()); + } + } + + public enum Truncation { + UNSPECIFIED, + DISABLED; + + @Override + public String toString() { + return name().toLowerCase(Locale.getDefault()); + } + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Stage.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Stage.java new file mode 100644 index 000000000..8acf7f182 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Stage.java @@ -0,0 +1,5 @@ +package com.google.cloud.firestore.pipeline.stages; + +public interface Stage { + String getName(); +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java new file mode 100644 index 000000000..871c4698d --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java @@ -0,0 +1,113 @@ +package com.google.cloud.firestore.pipeline.stages; + +import static com.google.cloud.firestore.PipelineUtils.encodeValue; + +import com.google.api.core.InternalApi; +import com.google.cloud.firestore.PipelineUtils; +import com.google.cloud.firestore.pipeline.expressions.Ordering; +import com.google.firestore.v1.Value; +import java.util.stream.Collectors; + +@InternalApi +public final class StageUtils { + @InternalApi + public static com.google.firestore.v1.Pipeline.Stage toStageProto(Stage stage) { + + if (stage instanceof Collection) { + Collection collectionStage = (Collection) stage; + return com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(collectionStage.getName()) + .addArgs(Value.newBuilder().setReferenceValue(collectionStage.getPath()).build()) + .build(); + } else if (stage instanceof CollectionGroup) { + CollectionGroup collectionGroupStage = (CollectionGroup) stage; + return com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(collectionGroupStage.getName()) + .addArgs(Value.newBuilder().setReferenceValue("").build()) + .addArgs(encodeValue(collectionGroupStage.getCollectionId())) + .build(); + } else if (stage instanceof Database) { + Database databaseStage = (Database) stage; + return com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(databaseStage.getName()) + .build(); + } else if (stage instanceof Documents) { + Documents documentsStage = (Documents) stage; + return com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(documentsStage.getName()) + .addAllArgs( + documentsStage.getDocuments().stream() + .map(doc -> Value.newBuilder().setReferenceValue(doc).build()) + .collect(Collectors.toList())) + .build(); + } else if (stage instanceof Select) { + Select selectStage = (Select) stage; + return com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(selectStage.getName()) + .addArgs(encodeValue(selectStage.getProjections())) + .build(); + } else if (stage instanceof AddFields) { + AddFields addFieldsStage = (AddFields) stage; + return com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(addFieldsStage.getName()) + .addArgs(encodeValue(addFieldsStage.getFields())) + .build(); + } else if (stage instanceof Filter) { + Filter filterStage = (Filter) stage; // Use wildcard for generic type + return com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(filterStage.getName()) + .addArgs(encodeValue(filterStage.getCondition())) + .build(); + } else if (stage instanceof Sort) { + Sort sortStage = (Sort) stage; + return com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(sortStage.getName()) + .addAllArgs( + sortStage.getOrders().stream().map(Ordering::toProto).collect(Collectors.toList())) + .putOptions("density", encodeValue(sortStage.getDensity().toString())) + .putOptions("truncation", encodeValue(sortStage.getTruncation().toString())) + .build(); + } else if (stage instanceof Offset) { + Offset offsetStage = (Offset) stage; + return com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(offsetStage.getName()) + .addArgs(encodeValue(offsetStage.getOffset())) + .build(); + } else if (stage instanceof Limit) { + Limit limitStage = (Limit) stage; + return com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(limitStage.getName()) + .addArgs(encodeValue(limitStage.getLimit())) + .build(); + } else if (stage instanceof Aggregate) { + Aggregate aggregateStage = (Aggregate) stage; + return com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(aggregateStage.getName()) + .addArgs(encodeValue(aggregateStage.getGroups())) + .addArgs(encodeValue(aggregateStage.getAccumulators())) + .build(); + } else if (stage instanceof FindNearest) { + FindNearest findNearestStage = (FindNearest) stage; + return com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(findNearestStage.getName()) + .addArgs(encodeValue(findNearestStage.getProperty())) + .addArgs(encodeValue(findNearestStage.getVector())) + .addArgs(encodeValue(findNearestStage.getOptions().getDistanceMeasure().toProtoString())) + .putOptions("limit", encodeValue(findNearestStage.getOptions().getLimit())) + .putOptions("distance_field", encodeValue(findNearestStage.getOptions().getOutput())) + .build(); + } else if (stage instanceof GenericStage) { + GenericStage genericStage = (GenericStage) stage; + return com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(genericStage.getName()) + .addAllArgs( + genericStage.getParams().stream() + .map(PipelineUtils::encodeValue) + .collect(Collectors.toList())) + .build(); + } else { + // Handle the else case appropriately (e.g., throw an exception) + throw new IllegalArgumentException("Unknown stage type: " + stage.getClass()); + } + } +} diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 53b3f2bc7..2a4a09b89 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -17,23 +17,25 @@ package com.google.cloud.firestore.it; import static com.google.cloud.firestore.it.ITQueryTest.map; -import static com.google.cloud.firestore.pipeline.Function.avg; -import static com.google.cloud.firestore.pipeline.Function.cosineDistance; -import static com.google.cloud.firestore.pipeline.Function.equal; -import static com.google.cloud.firestore.pipeline.Function.lessThan; -import static com.google.cloud.firestore.pipeline.Function.not; -import static com.google.cloud.firestore.pipeline.Function.or; -import static com.google.cloud.firestore.pipeline.Sort.Ordering.ascending; -import static com.google.cloud.firestore.pipeline.Sort.Ordering.descending; +import static com.google.cloud.firestore.pipeline.expressions.Function.avg; +import static com.google.cloud.firestore.pipeline.expressions.Function.cosineDistance; +import static com.google.cloud.firestore.pipeline.expressions.Function.equal; +import static com.google.cloud.firestore.pipeline.expressions.Function.lessThan; +import static com.google.cloud.firestore.pipeline.expressions.Function.not; +import static com.google.cloud.firestore.pipeline.expressions.Function.or; +import static com.google.cloud.firestore.pipeline.expressions.Ordering.ascending; +import static com.google.cloud.firestore.pipeline.expressions.Ordering.descending; import com.google.cloud.firestore.CollectionReference; import com.google.cloud.firestore.LocalFirestoreHelper; -import com.google.cloud.firestore.PaginatingPipeline; import com.google.cloud.firestore.Pipeline; import com.google.cloud.firestore.PipelineResult; -import com.google.cloud.firestore.pipeline.Constant; -import com.google.cloud.firestore.pipeline.Field; -import com.google.cloud.firestore.pipeline.Fields; +import com.google.cloud.firestore.pipeline.PaginatingPipeline; +import com.google.cloud.firestore.pipeline.expressions.Constant; +import com.google.cloud.firestore.pipeline.expressions.Field; +import com.google.cloud.firestore.pipeline.expressions.Fields; +import com.google.cloud.firestore.pipeline.stages.FindNearest.DistanceMeasure; +import com.google.cloud.firestore.pipeline.stages.FindNearest.FindNearestOptions; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -105,6 +107,18 @@ public void inFilters() throws Exception { List results = p.execute(firestore).get(); } + @Test + public void findNearest() throws Exception { + Pipeline p = Pipeline.fromCollectionGroup("coll1").filter(Field.of("foo").inAny(42, "42")); + List results = + p.findNearest( + Field.of("embedding1"), + new double[] {}, + FindNearestOptions.newInstance(10, DistanceMeasure.cosine(), Field.of("distance"))) + .execute(firestore) + .get(); + } + @Test public void aggregateWithoutGrouping() throws Exception { Pipeline p = From 42cc0e5e00556d30778e67f10caae044a824c8cc Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Tue, 11 Jun 2024 12:09:36 -0400 Subject: [PATCH 46/65] Tweaks --- .../cloud/firestore/pipeline/expressions/Constant.java | 9 ++++++--- .../cloud/firestore/pipeline/expressions/Function.java | 4 ++-- .../cloud/firestore/pipeline/expressions/Generic.java | 9 --------- 3 files changed, 8 insertions(+), 14 deletions(-) delete mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Generic.java diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Constant.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Constant.java index 58aa62957..f9ae4b4dc 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Constant.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Constant.java @@ -2,6 +2,7 @@ import static com.google.cloud.firestore.PipelineUtils.encodeValue; +import com.google.api.core.InternalApi; import com.google.cloud.Timestamp; import com.google.cloud.firestore.Blob; import com.google.cloud.firestore.DocumentReference; @@ -51,10 +52,12 @@ public static Constant of(DocumentReference value) { return new Constant(value); } + @InternalApi public static Constant of(Value value) { return new Constant(value); } + @InternalApi static Constant of(Object value) { if (value == null) { return new Constant(null); @@ -83,15 +86,15 @@ static Constant of(Object value) { } } - public static Constant ofArray(Iterable value) { + public static Constant of(Iterable value) { return new Constant(value); } - public static Constant ofArray(T[] value) { + public static Constant of(T[] value) { return new Constant(Arrays.asList(value)); // Convert array to list } - public static Constant ofMap(Map value) { + public static Constant of(Map value) { return new Constant(value); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java index 6cdfcea01..bf469ba0b 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java @@ -317,7 +317,7 @@ public static EuclideanDistance euclideanDistance(String field, double[] other) return new EuclideanDistance(Field.of(field), Constant.ofVector(other)); } - public static Generic function(String name, List params) { - return new Generic(name, params); + public static Function function(String name, List params) { + return new Function(name, params); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Generic.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Generic.java deleted file mode 100644 index ea0df3862..000000000 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Generic.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.google.cloud.firestore.pipeline.expressions; - -import java.util.List; - -public final class Generic extends Function { - Generic(String name, List params) { - super(name, params); - } -} From b27c5b8d1bd13c1f809bc46539d785942e20761a Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Fri, 14 Jun 2024 14:15:52 -0400 Subject: [PATCH 47/65] Tweaks --- .../com/google/cloud/firestore/Pipeline.java | 48 ++++++------------- .../com/google/cloud/firestore/Query.java | 6 ++- .../expressions/AggregatorTarget.java | 7 +-- .../pipeline/expressions/Function.java | 8 +--- 4 files changed, 21 insertions(+), 48 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java index 61b369706..864133e28 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java @@ -82,35 +82,25 @@ */ public final class Pipeline { private final ImmutableList stages; - private final String name; - private Pipeline(List stages, String name) { + private Pipeline(List stages) { this.stages = ImmutableList.copyOf(stages); - this.name = name; } private Pipeline(Collection collection) { - this(Lists.newArrayList(collection), collection.getPath()); + this(Lists.newArrayList(collection)); } private Pipeline(CollectionGroup group) { - this(Lists.newArrayList(group), group.getCollectionId()); + this(Lists.newArrayList(group)); } private Pipeline(Database db) { - this(Lists.newArrayList(db), db.getName()); + this(Lists.newArrayList(db)); } private Pipeline(Documents docs) { - this(Lists.newArrayList(docs), docs.getName()); - } - - public static Pipeline from(CollectionReference source) { - return new Pipeline(new Collection(source.getPath())); - } - - public static Pipeline from(com.google.cloud.firestore.CollectionGroup source) { - return new Pipeline(new CollectionGroup(source.options.getCollectionId())); + this(Lists.newArrayList(docs)); } public static Pipeline fromCollection(String collectionName) { @@ -165,8 +155,7 @@ public Pipeline addFields(Selectable... fields) { ImmutableList.builder() .addAll(stages) .add(new AddFields(projectablesToMap(fields))) - .build(), - name); + .build()); } public Pipeline select(Selectable... projections) { @@ -174,8 +163,7 @@ public Pipeline select(Selectable... projections) { ImmutableList.builder() .addAll(stages) .add(new Select(projectablesToMap(projections))) - .build(), - name); + .build()); } public Pipeline select(String... fields) { @@ -183,8 +171,7 @@ public Pipeline select(String... fields) { ImmutableList.builder() .addAll(stages) .add(new Select(fieldNamesToMap(fields))) - .build(), - name); + .build()); } public Pipeline filter(FilterCondition condition) { @@ -192,24 +179,22 @@ public Pipeline filter(FilterCondition condition) { ImmutableList.builder() .addAll(stages) .add(new com.google.cloud.firestore.pipeline.stages.Filter(condition)) - .build(), - name); + .build()); } public Pipeline offset(int offset) { return new Pipeline( - ImmutableList.builder().addAll(stages).add(new Offset(offset)).build(), name); + ImmutableList.builder().addAll(stages).add(new Offset(offset)).build()); } public Pipeline limit(int limit) { return new Pipeline( - ImmutableList.builder().addAll(stages).add(new Limit(limit)).build(), name); + ImmutableList.builder().addAll(stages).add(new Limit(limit)).build()); } public Pipeline aggregate(AggregatorTarget... aggregators) { return new Pipeline( - ImmutableList.builder().addAll(stages).add(new Aggregate(aggregators)).build(), - name); + ImmutableList.builder().addAll(stages).add(new Aggregate(aggregators)).build()); } public Pipeline findNearest( @@ -226,8 +211,7 @@ public Pipeline findNearest( .add( new FindNearest( property, vector, options)) // Assuming FindNearest takes these arguments - .build(), - name); + .build()); } public Pipeline sort(List orders, Sort.Density density, Sort.Truncation truncation) { @@ -235,8 +219,7 @@ public Pipeline sort(List orders, Sort.Density density, Sort.Truncatio ImmutableList.builder() .addAll(stages) .add(new Sort(orders, density, truncation)) - .build(), - name); + .build()); } // Sugar @@ -258,8 +241,7 @@ public Pipeline genericStage(String name, Map params) { name, Lists.newArrayList( params.values()))) // Assuming GenericStage takes a list of params - .build(), - name); + .build()); } public ApiFuture> execute(Firestore db) { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index d5e217f64..cd1e44818 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -2122,8 +2122,10 @@ public AggregateQuery aggregate( @Nonnull public Pipeline toPipeline() { // From - Pipeline ppl = - Pipeline.fromCollection( + Pipeline ppl = this.options.getAllDescendants() ? + Pipeline.fromCollectionGroup( + this.options.getCollectionId()) + : Pipeline.fromCollection( this.options.getParentPath().append(this.options.getCollectionId()).getPath()); // Filters diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AggregatorTarget.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AggregatorTarget.java index d8aa4d43d..295f948b9 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AggregatorTarget.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AggregatorTarget.java @@ -1,6 +1,6 @@ package com.google.cloud.firestore.pipeline.expressions; -public final class AggregatorTarget implements Selectable, Accumulator { +public final class AggregatorTarget implements Selectable{ private final Accumulator accumulator; private final String fieldName; @@ -17,9 +17,4 @@ public Accumulator getAccumulator() { public String getFieldName() { return fieldName; } - - @Override - public AggregatorTarget toField(String fieldName) { - return null; - } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java index bf469ba0b..a93e42bb0 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java @@ -164,10 +164,6 @@ public static Or or(FilterCondition left, FilterCondition... other) { return new Or(conditions); } - // File: FunctionUtils.java (or similar) - - // ... other static methods ... - public static ArrayContains arrayContains(Expr expr, Expr element) { return new ArrayContains(expr, element); } @@ -218,7 +214,7 @@ public static IsNull isNull(String field) { return new IsNull(Field.of(field)); } - public static Not not(Expr expr) { + public static Not not(FilterCondition expr) { return new Not(expr); } @@ -238,8 +234,6 @@ public static Avg avg(String field) { return new Avg(Field.of(field), false); } - // Note: There seems to be a typo in the Kotlin code. - // `min` and `max` are calling `Sum` and `Avg` constructors respectively public static Min min(Expr expr) { return new Min(expr, false); // Corrected constructor call } From 392dd843143632d931080ac390f4bf493615e738 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Wed, 26 Jun 2024 10:54:09 -0400 Subject: [PATCH 48/65] minor fixes --- .../java/com/google/cloud/firestore/PipelineUtils.java | 4 ++-- .../main/java/com/google/cloud/firestore/Query.java | 2 +- .../cloud/firestore/pipeline/stages/FindNearest.java | 10 +++++----- .../cloud/firestore/pipeline/stages/StageUtils.java | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java index d59eb2744..198931cc5 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java @@ -161,13 +161,13 @@ static Pipeline toPaginatedPipeline( @InternalApi static AggregatorTarget toPipelineAggregatorTarget(AggregateField f) { String operator = f.getOperator(); - String fieldPath = f.getFieldPath(); // Assuming you have a method to get FieldPath + String fieldPath = f.getFieldPath(); switch (operator) { case "sum": return Field.of(fieldPath) .sum() - .toField(f.getAlias()); // Note: 'toField' is assumed to be a method in your context + .toField(f.getAlias()); case "count": return countAll().toField(f.getAlias()); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index cd1e44818..9e5c8e4af 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -2160,7 +2160,7 @@ public Pipeline toPipeline() { } // Cursors, Limit and Offset - if (this.options.getStartCursor() != null || this.options.getEndCursor() != null) { + if (this.options.getStartCursor() != null || this.options.getEndCursor() != null || this.options.getLimitType() == LimitType.Last) { ppl = toPaginatedPipeline( ppl, diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/FindNearest.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/FindNearest.java index a3257f9ac..cdf872a8c 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/FindNearest.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/FindNearest.java @@ -106,13 +106,13 @@ public static class FindNearestOptions { private final Long limit; private final FindNearest.DistanceMeasure distanceMeasure; - private final Field output; + private final Field distanceField; private FindNearestOptions( - Long limit, FindNearest.DistanceMeasure distanceMeasure, Field output) { + Long limit, FindNearest.DistanceMeasure distanceMeasure, Field distanceField) { this.limit = limit; this.distanceMeasure = distanceMeasure; - this.output = output; + this.distanceField = distanceField; } public static FindNearest.FindNearestOptions newInstance( @@ -128,8 +128,8 @@ public DistanceMeasure getDistanceMeasure() { return distanceMeasure; } - public Field getOutput() { - return output; + public Field getDistanceField() { + return distanceField; } } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java index 871c4698d..66008a4d5 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java @@ -94,7 +94,7 @@ public static com.google.firestore.v1.Pipeline.Stage toStageProto(Stage stage) { .addArgs(encodeValue(findNearestStage.getVector())) .addArgs(encodeValue(findNearestStage.getOptions().getDistanceMeasure().toProtoString())) .putOptions("limit", encodeValue(findNearestStage.getOptions().getLimit())) - .putOptions("distance_field", encodeValue(findNearestStage.getOptions().getOutput())) + .putOptions("distance_field", encodeValue(findNearestStage.getOptions().getDistanceField())) .build(); } else if (stage instanceof GenericStage) { GenericStage genericStage = (GenericStage) stage; From 2568d6a4c23d237c4a9eb6377e2e5b819c5551f3 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Wed, 3 Jul 2024 10:31:20 -0400 Subject: [PATCH 49/65] add missing functions --- .../firestore/AggregateQuerySnapshot.java | 6 + .../com/google/cloud/firestore/FieldPath.java | 4 +- .../com/google/cloud/firestore/Pipeline.java | 4 + .../cloud/firestore/PipelineResult.java | 4 +- .../google/cloud/firestore/PipelineUtils.java | 21 +- .../com/google/cloud/firestore/Query.java | 31 +- .../firestore/pipeline/expressions/Add.java | 11 + .../expressions/AggregatorTarget.java | 2 +- .../pipeline/expressions/ArrayConcat.java | 10 + .../expressions/ArrayContainsAll.java | 10 + .../pipeline/expressions/ArrayElement.java | 9 + .../pipeline/expressions/ArrayFilter.java | 9 + .../pipeline/expressions/ArrayLength.java | 9 + .../pipeline/expressions/ArrayTransform.java | 9 + .../pipeline/expressions/CollectionId.java | 12 + .../pipeline/expressions/CountIf.java | 10 + .../pipeline/expressions/Divide.java | 11 + .../pipeline/expressions/Exists.java | 9 + .../firestore/pipeline/expressions/Expr.java | 118 ++- .../pipeline/expressions/ExprWithAlias.java | 26 + .../firestore/pipeline/expressions/Field.java | 9 +- .../pipeline/expressions/Function.java | 241 ++++++ .../firestore/pipeline/expressions/If.java | 9 + .../pipeline/expressions/Length.java | 9 + .../firestore/pipeline/expressions/Like.java | 11 + .../pipeline/expressions/MapGet.java | 9 + .../pipeline/expressions/Multiply.java | 11 + .../pipeline/expressions/Parent.java | 12 + .../pipeline/expressions/RegexContains.java | 11 + .../pipeline/expressions/StrConcat.java | 10 + .../pipeline/expressions/Subtract.java | 11 + .../pipeline/expressions/ToLowercase.java | 9 + .../pipeline/expressions/ToUppercase.java | 9 + .../firestore/pipeline/expressions/Trim.java | 9 + .../firestore/pipeline/expressions/Xor.java | 9 + .../firestore/pipeline/stages/Select.java | 2 +- .../firestore/pipeline/stages/StageUtils.java | 3 +- .../com/google/cloud/firestore/TestUtil.java | 24 + .../cloud/firestore/it/ITPipelineTest.java | 753 +++++++++++++++--- .../firestore/it/ITQueryAggregationsTest.java | 255 +++--- 40 files changed, 1494 insertions(+), 247 deletions(-) create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Add.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayConcat.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContainsAll.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayElement.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayFilter.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayLength.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayTransform.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CollectionId.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CountIf.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Divide.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Exists.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ExprWithAlias.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/If.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Length.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Like.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/MapGet.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Multiply.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Parent.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/RegexContains.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/StrConcat.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Subtract.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToLowercase.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToUppercase.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Trim.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Xor.java create mode 100644 google-cloud-firestore/src/test/java/com/google/cloud/firestore/TestUtil.java diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuerySnapshot.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuerySnapshot.java index ff7b99906..be98e61d2 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuerySnapshot.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuerySnapshot.java @@ -16,6 +16,7 @@ package com.google.cloud.firestore; +import com.google.api.core.InternalApi; import com.google.api.core.InternalExtensionOnly; import com.google.cloud.Timestamp; import com.google.firestore.v1.Value; @@ -189,4 +190,9 @@ public boolean equals(Object object) { public int hashCode() { return Objects.hash(query, data); } + + @InternalApi + Map getData() { + return data; + } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FieldPath.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FieldPath.java index e6939c445..c5b9a8173 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FieldPath.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FieldPath.java @@ -16,6 +16,7 @@ package com.google.cloud.firestore; +import com.google.api.core.InternalApi; import com.google.auto.value.AutoValue; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -79,7 +80,8 @@ static boolean isDocumentId(String path) { } /** Returns a field path from a dot separated string. Does not support escaping. */ - static FieldPath fromDotSeparatedString(String field) { + @InternalApi + public static FieldPath fromDotSeparatedString(String field) { if (PROHIBITED_CHARACTERS.matcher(field).matches()) { throw new IllegalArgumentException("Use FieldPath.of() for field names containing '˜*/[]'."); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java index 864133e28..a8df73985 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java @@ -9,6 +9,7 @@ import com.google.cloud.firestore.pipeline.PaginatingPipeline; import com.google.cloud.firestore.pipeline.expressions.AggregatorTarget; import com.google.cloud.firestore.pipeline.expressions.Expr; +import com.google.cloud.firestore.pipeline.expressions.ExprWithAlias; import com.google.cloud.firestore.pipeline.expressions.Field; import com.google.cloud.firestore.pipeline.expressions.Fields; import com.google.cloud.firestore.pipeline.expressions.FilterCondition; @@ -137,6 +138,9 @@ private Map projectablesToMap(Selectable... selectables) { if (fieldsProj.getFields() != null) { fieldsProj.getFields().forEach(f -> projMap.put(f.getPath().getEncodedPath(), f)); } + } else if (proj instanceof ExprWithAlias) { + ExprWithAlias exprWithAlias = (ExprWithAlias) proj; + projMap.put(exprWithAlias.getAlias(), exprWithAlias.getExpr()); } } return projMap; diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.java index 421d85f7d..b54d9e36e 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.java @@ -81,7 +81,9 @@ static PipelineResult fromDocument( FirestoreRpcContext rpcContext, Timestamp readTime, Document document) { return new PipelineResult( rpcContext, - new DocumentReference(rpcContext, ResourcePath.create(document.getName())), + document.getName().isEmpty() + ? null + : new DocumentReference(rpcContext, ResourcePath.create(document.getName())), document.getFieldsMap(), readTime, Timestamp.fromProto(document.getUpdateTime()), diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java index 198931cc5..0987f34e4 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java @@ -15,9 +15,9 @@ import com.google.cloud.firestore.Query.UnaryFilterInternal; import com.google.cloud.firestore.pipeline.PaginatingPipeline; import com.google.cloud.firestore.pipeline.expressions.AggregatorTarget; -import com.google.cloud.firestore.pipeline.expressions.Constant; import com.google.cloud.firestore.pipeline.expressions.Field; import com.google.cloud.firestore.pipeline.expressions.FilterCondition; +import com.google.common.collect.Lists; import com.google.firestore.v1.Cursor; import com.google.firestore.v1.Value; import java.util.List; @@ -53,20 +53,13 @@ static FilterCondition toPipelineFilterCondition(FilterInternal f) { return Field.of(fieldPath).arrayContains(value); case IN: List valuesList = value.getArrayValue().getValuesList(); - return inAny( - Field.of(fieldPath), - valuesList.stream().map(Constant::of).collect(Collectors.toList())); + return inAny(Field.of(fieldPath), Lists.newArrayList(valuesList)); case ARRAY_CONTAINS_ANY: List valuesListAny = value.getArrayValue().getValuesList(); - return arrayContainsAny( - Field.of(fieldPath), - valuesListAny.stream().map(Constant::of).collect(Collectors.toList())); + return arrayContainsAny(Field.of(fieldPath), valuesListAny.toArray()); case NOT_IN: List notInValues = value.getArrayValue().getValuesList(); - return not( - inAny( - Field.of(fieldPath), - notInValues.stream().map(Constant::of).collect(Collectors.toList()))); + return not(inAny(Field.of(fieldPath), Lists.newArrayList(notInValues))); default: // Handle OPERATOR_UNSPECIFIED and UNRECOGNIZED cases as needed throw new IllegalArgumentException("Unsupported operator: " + comparisonFilter.operator); @@ -165,13 +158,11 @@ static AggregatorTarget toPipelineAggregatorTarget(AggregateField f) { switch (operator) { case "sum": - return Field.of(fieldPath) - .sum() - .toField(f.getAlias()); + return Field.of(fieldPath).sum().toField(f.getAlias()); case "count": return countAll().toField(f.getAlias()); - case "avg": + case "average": return Field.of(fieldPath).avg().toField(f.getAlias()); default: // Handle the 'else' case appropriately in your Java code diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index 9e5c8e4af..554589359 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -18,6 +18,7 @@ import static com.google.cloud.firestore.PipelineUtils.toPaginatedPipeline; import static com.google.cloud.firestore.PipelineUtils.toPipelineFilterCondition; +import static com.google.cloud.firestore.pipeline.expressions.Function.and; import static com.google.common.collect.Lists.reverse; import static com.google.firestore.v1.StructuredQuery.FieldFilter.Operator.ARRAY_CONTAINS; import static com.google.firestore.v1.StructuredQuery.FieldFilter.Operator.ARRAY_CONTAINS_ANY; @@ -40,6 +41,7 @@ import com.google.auto.value.AutoValue; import com.google.cloud.Timestamp; import com.google.cloud.firestore.Query.QueryOptions.Builder; +import com.google.cloud.firestore.pipeline.expressions.Exists; import com.google.cloud.firestore.pipeline.expressions.Field; import com.google.cloud.firestore.pipeline.expressions.Ordering; import com.google.cloud.firestore.pipeline.expressions.Selectable; @@ -2122,11 +2124,11 @@ public AggregateQuery aggregate( @Nonnull public Pipeline toPipeline() { // From - Pipeline ppl = this.options.getAllDescendants() ? - Pipeline.fromCollectionGroup( - this.options.getCollectionId()) - : Pipeline.fromCollection( - this.options.getParentPath().append(this.options.getCollectionId()).getPath()); + Pipeline ppl = + this.options.getAllDescendants() + ? Pipeline.fromCollectionGroup(this.options.getCollectionId()) + : Pipeline.fromCollection( + this.options.getParentPath().append(this.options.getCollectionId()).getPath()); // Filters for (FilterInternal f : this.options.getFilters()) { @@ -2156,11 +2158,28 @@ public Pipeline toPipeline() { ? Ordering.Direction.ASCENDING : Ordering.Direction.DESCENDING)) .collect(Collectors.toList()); + + // Add exists filters to match Query's implicit orderby semantics. + List exists = + normalizedOrderbys.stream() + // .filter(order -> !order.fieldReference.getFieldPath().equals("__name__")) + .map(order -> Field.of(order.fieldReference.getFieldPath()).exists()) + .collect(Collectors.toList()); + if (exists.size() > 1) { + ppl = + ppl.filter( + and(exists.get(0), exists.subList(1, exists.size()).toArray(new Exists[] {}))); + } else if (exists.size() == 1) { + ppl = ppl.filter(exists.get(0)); + } + ppl = ppl.sort(orders, Density.REQUIRED, Truncation.UNSPECIFIED); } // Cursors, Limit and Offset - if (this.options.getStartCursor() != null || this.options.getEndCursor() != null || this.options.getLimitType() == LimitType.Last) { + if (this.options.getStartCursor() != null + || this.options.getEndCursor() != null + || this.options.getLimitType() == LimitType.Last) { ppl = toPaginatedPipeline( ppl, diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Add.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Add.java new file mode 100644 index 000000000..1d73fbafc --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Add.java @@ -0,0 +1,11 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.api.core.InternalApi; +import com.google.common.collect.Lists; + +public final class Add extends Function { + @InternalApi + Add(Expr left, Expr right) { + super("add", Lists.newArrayList(left, right)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AggregatorTarget.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AggregatorTarget.java index 295f948b9..80dedbccb 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AggregatorTarget.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AggregatorTarget.java @@ -1,6 +1,6 @@ package com.google.cloud.firestore.pipeline.expressions; -public final class AggregatorTarget implements Selectable{ +public final class AggregatorTarget implements Selectable { private final Accumulator accumulator; private final String fieldName; diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayConcat.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayConcat.java new file mode 100644 index 000000000..20fd90f9f --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayConcat.java @@ -0,0 +1,10 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; +import java.util.List; + +public final class ArrayConcat extends Function { + ArrayConcat(Expr array, List rest) { + super("array_concat", Lists.newArrayList(array, new ListOfExprs(rest))); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContainsAll.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContainsAll.java new file mode 100644 index 000000000..3f193c2f4 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContainsAll.java @@ -0,0 +1,10 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; +import java.util.List; + +public final class ArrayContainsAll extends Function implements FilterCondition { + ArrayContainsAll(Expr array, List elements) { + super("array_contains_all", Lists.newArrayList(array, new ListOfExprs(elements))); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayElement.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayElement.java new file mode 100644 index 000000000..664dbb17c --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayElement.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public class ArrayElement extends Function { + ArrayElement() { + super("array_element", Lists.newArrayList()); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayFilter.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayFilter.java new file mode 100644 index 000000000..376bcff8e --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayFilter.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class ArrayFilter extends Function { + ArrayFilter(Expr array, FilterCondition filter) { + super("array_filter", Lists.newArrayList(array, filter)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayLength.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayLength.java new file mode 100644 index 000000000..8cbc08d6f --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayLength.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class ArrayLength extends Function { + ArrayLength(Expr array) { + super("array_length", Lists.newArrayList(array)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayTransform.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayTransform.java new file mode 100644 index 000000000..d9c5f218e --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayTransform.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class ArrayTransform extends Function { + ArrayTransform(Expr array, Function transform) { + super("array_transform", Lists.newArrayList(array, transform)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CollectionId.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CollectionId.java new file mode 100644 index 000000000..aa8ee3701 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CollectionId.java @@ -0,0 +1,12 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.api.core.InternalApi; +import com.google.common.collect.Lists; + +public final class CollectionId extends Function { + + @InternalApi + CollectionId(Expr value) { + super("collection_id", Lists.newArrayList(value)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CountIf.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CountIf.java new file mode 100644 index 000000000..d31851eed --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CountIf.java @@ -0,0 +1,10 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; +import java.util.Collections; + +public final class CountIf extends Function implements Accumulator { + CountIf(Expr value, boolean distinct) { + super("count_if", (value != null) ? Lists.newArrayList(value) : Collections.emptyList()); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Divide.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Divide.java new file mode 100644 index 000000000..3f70f55ce --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Divide.java @@ -0,0 +1,11 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.api.core.InternalApi; +import com.google.common.collect.Lists; + +public final class Divide extends Function { + @InternalApi + Divide(Expr left, Expr right) { + super("divide", Lists.newArrayList(left, right)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Exists.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Exists.java new file mode 100644 index 000000000..ad64a9b9a --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Exists.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class Exists extends Function implements FilterCondition { + Exists(Field field) { + super("exists", Lists.newArrayList(field)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java index b65c98247..5a69b821d 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java @@ -1,11 +1,42 @@ package com.google.cloud.firestore.pipeline.expressions; -import com.google.api.core.InternalApi; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public interface Expr { + default Add add(Expr other) { + return new Add(this, other); + } + + default Add add(Object other) { + return new Add(this, Constant.of(other)); + } + + default Subtract subtract(Expr other) { + return new Subtract(this, other); + } + + default Subtract subtract(Object other) { + return new Subtract(this, Constant.of(other)); + } + + default Multiply multiply(Expr other) { + return new Multiply(this, other); + } + + default Multiply multiply(Object other) { + return new Multiply(this, Constant.of(other)); + } + + default Divide divide(Expr other) { + return new Divide(this, other); + } + + default Divide divide(Object other) { + return new Divide(this, Constant.of(other)); + } + default Equal equal(Expr expr) { return new Equal(this, expr); } @@ -66,6 +97,15 @@ default Not notInAny(Object... other) { return new Not(inAny(other)); } + default ArrayConcat arrayConcat(Expr... elements) { + return new ArrayConcat(this, Arrays.asList(elements)); + } + + default ArrayConcat arrayConcat(Object... elements) { + return new ArrayConcat( + this, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + } + default ArrayContains arrayContains(Expr element) { return new ArrayContains(this, element); } @@ -74,6 +114,15 @@ default ArrayContains arrayContains(Object element) { return new ArrayContains(this, Constant.of(element)); } + default ArrayContainsAll arrayContainsAll(Expr... elements) { + return new ArrayContainsAll(this, Arrays.asList(elements)); + } + + default ArrayContainsAll arrayContainsAll(Object... elements) { + return new ArrayContainsAll( + this, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + } + default ArrayContainsAny arrayContainsAny(Expr... elements) { return new ArrayContainsAny(this, Arrays.asList(elements)); } @@ -83,6 +132,18 @@ default ArrayContainsAny arrayContainsAny(Object... elements) { this, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); } + default ArrayFilter arrayFilter(FilterCondition filter) { + return new ArrayFilter(this, filter); + } + + default ArrayLength arrayLength() { + return new ArrayLength(this); + } + + default ArrayTransform arrayTransform(Function transform) { + return new ArrayTransform(this, transform); + } + default IsNaN isNaN() { return new IsNaN(this); } @@ -111,6 +172,38 @@ default Max max() { return new Max(this, false); } + default Length length() { + return new Length(this); + } + + default Like like(String pattern) { + return new Like(this, Constant.of(pattern)); + } + + default RegexContains regexContains(String regex) { + return new RegexContains(this, Constant.of(regex)); + } + + default StrConcat strConcat(List elements) { + return new StrConcat(this, elements); + } + + default ToLowercase toLowercase() { + return new ToLowercase(this); + } + + default ToUppercase toUppercase() { + return new ToUppercase(this); + } + + default Trim trim() { + return new Trim(this); + } + + default MapGet mapGet(String key) { + return new MapGet(this, key); + } + default CosineDistance cosineDistance(Expr other) { return new CosineDistance(this, other); } @@ -147,26 +240,3 @@ default Selectable asAlias(String alias) { return new ExprWithAlias(this, alias); } } - -@InternalApi -final class ExprWithAlias implements Selectable { - - private final String alias; - private final Expr expr; - - @InternalApi - ExprWithAlias(Expr expr, String alias) { - this.expr = expr; - this.alias = alias; - } - - @InternalApi - String getAlias() { - return alias; - } - - @InternalApi - Expr getExpr() { - return expr; - } -} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ExprWithAlias.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ExprWithAlias.java new file mode 100644 index 000000000..7b0c8c8a7 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ExprWithAlias.java @@ -0,0 +1,26 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.api.core.InternalApi; + +@InternalApi +public final class ExprWithAlias implements Selectable { + + private final String alias; + private final Expr expr; + + @InternalApi + ExprWithAlias(Expr expr, String alias) { + this.expr = expr; + this.alias = alias; + } + + @InternalApi + public String getAlias() { + return alias; + } + + @InternalApi + public Expr getExpr() { + return expr; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java index 27a1fdd3a..c1541a8cb 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java @@ -15,7 +15,10 @@ private Field(FieldPath path) { } public static Field of(String path) { - return new Field(FieldPath.of(path)); + if (path.equals(DOCUMENT_ID)) { + return new Field(FieldPath.of("__path__")); + } + return new Field(FieldPath.fromDotSeparatedString(path)); } public static Field ofAll() { @@ -26,6 +29,10 @@ public Value toProto() { return Value.newBuilder().setFieldReferenceValue(path.toString()).build(); } + public Exists exists() { + return new Exists(this); + } + // Getters public FieldPath getPath() { return path; diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java index a93e42bb0..bba0c11a0 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java @@ -1,5 +1,6 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.cloud.firestore.DocumentReference; import com.google.common.collect.Lists; import com.google.firestore.v1.Value; import java.util.Arrays; @@ -28,6 +29,86 @@ Value toProto() { .build(); } + public static CollectionId collectionId(String path) { + return new CollectionId(Constant.of(path)); + } + + public static CollectionId collectionId(DocumentReference ref) { + return new CollectionId(Constant.of(ref.getPath())); + } + + public static Parent parent(String path) { + return new Parent(Constant.of(path)); + } + + public static Parent parent(DocumentReference ref) { + return new Parent(Constant.of(ref.getPath())); + } + + public static Add add(Expr left, Expr right) { + return new Add(left, right); + } + + public static Add add(Expr left, Object right) { + return new Add(left, Constant.of(right)); + } + + public static Add add(String left, Expr right) { + return new Add(Field.of(left), right); + } + + public static Add add(String left, Object right) { + return new Add(Field.of(left), Constant.of(right)); + } + + public static Subtract subtract(Expr left, Expr right) { + return new Subtract(left, right); + } + + public static Subtract subtract(Expr left, Object right) { + return new Subtract(left, Constant.of(right)); + } + + public static Subtract subtract(String left, Expr right) { + return new Subtract(Field.of(left), right); + } + + public static Subtract subtract(String left, Object right) { + return new Subtract(Field.of(left), Constant.of(right)); + } + + public static Multiply multiply(Expr left, Expr right) { + return new Multiply(left, right); + } + + public static Multiply multiply(Expr left, Object right) { + return new Multiply(left, Constant.of(right)); + } + + public static Multiply multiply(String left, Expr right) { + return new Multiply(Field.of(left), right); + } + + public static Multiply multiply(String left, Object right) { + return new Multiply(Field.of(left), Constant.of(right)); + } + + public static Divide divide(Expr left, Expr right) { + return new Divide(left, right); + } + + public static Divide divide(Expr left, Object right) { + return new Divide(left, Constant.of(right)); + } + + public static Divide divide(String left, Expr right) { + return new Divide(Field.of(left), right); + } + + public static Divide divide(String left, Object right) { + return new Divide(Field.of(left), Constant.of(right)); + } + public static Equal equal(Expr left, Expr right) { return new Equal(left, right); } @@ -124,6 +205,14 @@ public static LessThanOrEqual lessThanOrEqual(String left, Object right) { return new LessThanOrEqual(Field.of(left), Constant.of(right)); } + public static Exists exists(String field) { + return new Exists(Field.of(field)); + } + + public static Exists exists(Field field) { + return new Exists(field); + } + public static In inAny(Expr left, List values) { List othersAsExpr = values.stream() @@ -164,6 +253,42 @@ public static Or or(FilterCondition left, FilterCondition... other) { return new Or(conditions); } + public static Xor xor(FilterCondition left, FilterCondition right) { + return new Xor(Lists.newArrayList(left, right)); + } + + public static Xor xor(FilterCondition left, FilterCondition... other) { + List conditions = Lists.newArrayList(left); + conditions.addAll(Arrays.asList(other)); + return new Xor(conditions); + } + + public static If ifThen(FilterCondition condition, Expr thenExpr) { + return new If(condition, thenExpr, null); + } + + public static If ifThenElse(FilterCondition condition, Expr thenExpr, Expr elseExpr) { + return new If(condition, thenExpr, elseExpr); + } + + public static ArrayConcat arrayConcat(Expr expr, Expr... elements) { + return new ArrayConcat(expr, Arrays.asList(elements)); + } + + public static ArrayConcat arrayConcat(Expr expr, Object... elements) { + return new ArrayConcat( + expr, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + } + + public static ArrayConcat arrayConcat(String field, Expr... elements) { + return new ArrayConcat(Field.of(field), Arrays.asList(elements)); + } + + public static ArrayConcat arrayConcat(String field, Object... elements) { + return new ArrayConcat( + Field.of(field), Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + } + public static ArrayContains arrayContains(Expr expr, Expr element) { return new ArrayContains(expr, element); } @@ -180,6 +305,24 @@ public static ArrayContains arrayContains(String field, Object element) { return new ArrayContains(Field.of(field), Constant.of(element)); } + public static ArrayContainsAll arrayContainsAll(Expr expr, Expr... elements) { + return new ArrayContainsAll(expr, Arrays.asList(elements)); + } + + public static ArrayContainsAll arrayContainsAll(Expr expr, Object... elements) { + return new ArrayContainsAll( + expr, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + } + + public static ArrayContainsAll arrayContainsAll(String field, Expr... elements) { + return new ArrayContainsAll(Field.of(field), Arrays.asList(elements)); + } + + public static ArrayContainsAll arrayContainsAll(String field, Object... elements) { + return new ArrayContainsAll( + Field.of(field), Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + } + public static ArrayContainsAny arrayContainsAny(Expr expr, Expr... elements) { return new ArrayContainsAny(expr, Arrays.asList(elements)); } @@ -198,6 +341,96 @@ public static ArrayContainsAny arrayContainsAny(String field, Object... elements Field.of(field), Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); } + public static ArrayFilter arrayFilter(Expr expr, FilterCondition filter) { + return new ArrayFilter(expr, filter); + } + + public static ArrayFilter arrayFilter(String field, FilterCondition filter) { + return new ArrayFilter(Field.of(field), filter); + } + + public static ArrayLength arrayLength(Expr expr) { + return new ArrayLength(expr); + } + + public static ArrayLength arrayLength(String field) { + return new ArrayLength(Field.of(field)); + } + + public static ArrayTransform arrayTransform(Expr expr, Function transform) { + return new ArrayTransform(expr, transform); + } + + public static ArrayTransform arrayTransform(String field, Function transform) { + return new ArrayTransform(Field.of(field), transform); + } + + public static Length length(Expr expr) { + return new Length(expr); + } + + public static Length length(String field) { + return new Length(Field.of(field)); + } + + public static Like like(Expr expr, String pattern) { + return new Like(expr, Constant.of(pattern)); + } + + public static Like like(String field, String pattern) { + return new Like(Field.of(field), Constant.of(pattern)); + } + + public static RegexContains regexContains(Expr expr, String pattern) { + return new RegexContains(expr, Constant.of(pattern)); + } + + public static RegexContains regexContains(String field, String pattern) { + return new RegexContains(Field.of(field), Constant.of(pattern)); + } + + public static StrConcat strConcat(Expr expr, Expr... elements) { + return new StrConcat(expr, Arrays.asList(elements)); + } + + public static StrConcat strConcat(Expr expr, Object... elements) { + return new StrConcat( + expr, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + } + + public static StrConcat strConcat(String field, Expr... elements) { + return new StrConcat(Field.of(field), Arrays.asList(elements)); + } + + public static StrConcat strConcat(String field, Object... elements) { + return new StrConcat( + Field.of(field), Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + } + + public static ToLowercase toLowercase(Expr expr) { + return new ToLowercase(expr); + } + + public static ToLowercase toLowercase(String field) { + return new ToLowercase(Field.of(field)); + } + + public static ToUppercase toUppercase(Expr expr) { + return new ToUppercase(expr); + } + + public static ToUppercase toUppercase(String field) { + return new ToUppercase(Field.of(field)); + } + + public static Trim trim(Expr expr) { + return new Trim(expr); + } + + public static Trim trim(String field) { + return new Trim(Field.of(field)); + } + public static IsNaN isNaN(Expr expr) { return new IsNaN(expr); } @@ -258,6 +491,10 @@ public static Count count(String field) { return new Count(Field.of(field), false); } + public static CountIf countIf(FilterCondition condition) { + return new CountIf(condition, false); + } + public static Count countAll() { return new Count(null, false); } @@ -311,6 +548,10 @@ public static EuclideanDistance euclideanDistance(String field, double[] other) return new EuclideanDistance(Field.of(field), Constant.ofVector(other)); } + public static ArrayElement arrayElement() { + return new ArrayElement(); + } + public static Function function(String name, List params) { return new Function(name, params); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/If.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/If.java new file mode 100644 index 000000000..8c7a35d11 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/If.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class If extends Function implements FilterCondition { + If(FilterCondition condition, Expr trueExpr, Expr falseExpr) { + super("if", Lists.newArrayList(condition, trueExpr, falseExpr)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Length.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Length.java new file mode 100644 index 000000000..a82f10452 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Length.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class Length extends Function { + Length(Expr expr) { + super("length", Lists.newArrayList(expr)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Like.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Like.java new file mode 100644 index 000000000..1c9d1f87e --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Like.java @@ -0,0 +1,11 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.api.core.InternalApi; +import com.google.common.collect.Lists; + +public final class Like extends Function implements FilterCondition { + @InternalApi + Like(Expr expr, Expr pattern) { + super("like", Lists.newArrayList(expr, pattern)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/MapGet.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/MapGet.java new file mode 100644 index 000000000..98a1c09f6 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/MapGet.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class MapGet extends Function { + MapGet(Expr map, String name) { + super("map_get", Lists.newArrayList(map, Constant.of(name))); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Multiply.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Multiply.java new file mode 100644 index 000000000..003861fc5 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Multiply.java @@ -0,0 +1,11 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.api.core.InternalApi; +import com.google.common.collect.Lists; + +public final class Multiply extends Function { + @InternalApi + Multiply(Expr left, Expr right) { + super("multiply", Lists.newArrayList(left, right)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Parent.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Parent.java new file mode 100644 index 000000000..0168047a7 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Parent.java @@ -0,0 +1,12 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.api.core.InternalApi; +import com.google.common.collect.Lists; + +public final class Parent extends Function { + + @InternalApi + Parent(Expr value) { + super("parent", Lists.newArrayList(value)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/RegexContains.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/RegexContains.java new file mode 100644 index 000000000..ac0fcfa7e --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/RegexContains.java @@ -0,0 +1,11 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.api.core.InternalApi; +import com.google.common.collect.Lists; + +public final class RegexContains extends Function implements FilterCondition { + @InternalApi + RegexContains(Expr expr, Expr regex) { + super("regex_contains", Lists.newArrayList(expr, regex)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/StrConcat.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/StrConcat.java new file mode 100644 index 000000000..5d1a80e08 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/StrConcat.java @@ -0,0 +1,10 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; +import java.util.List; + +public final class StrConcat extends Function { + StrConcat(Expr first, List exprs) { + super("str_concat", Lists.newArrayList(first, new ListOfExprs(exprs))); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Subtract.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Subtract.java new file mode 100644 index 000000000..15e513103 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Subtract.java @@ -0,0 +1,11 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.api.core.InternalApi; +import com.google.common.collect.Lists; + +public final class Subtract extends Function { + @InternalApi + Subtract(Expr left, Expr right) { + super("subtract", Lists.newArrayList(left, right)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToLowercase.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToLowercase.java new file mode 100644 index 000000000..e4e6c29ac --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToLowercase.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class ToLowercase extends Function { + ToLowercase(Expr expr) { + super("to_lowercase", Lists.newArrayList(expr)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToUppercase.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToUppercase.java new file mode 100644 index 000000000..3d3cdab8b --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToUppercase.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class ToUppercase extends Function { + ToUppercase(Expr expr) { + super("to_uppercase", Lists.newArrayList(expr)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Trim.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Trim.java new file mode 100644 index 000000000..37fa9e372 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Trim.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class Trim extends Function { + Trim(Expr expr) { + super("trim", Lists.newArrayList(expr)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Xor.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Xor.java new file mode 100644 index 000000000..01a698d56 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Xor.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import java.util.List; + +public final class Xor extends Function implements FilterCondition { + Xor(List conditions) { + super("xor", conditions); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Select.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Select.java index 6d4c47ab5..b34d66dcc 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Select.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Select.java @@ -7,7 +7,7 @@ @InternalApi public final class Select implements Stage { - private static final String name = "select"; + private static final String name = "project"; private final Map projections; @InternalApi diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java index 66008a4d5..ba4493d57 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java @@ -94,7 +94,8 @@ public static com.google.firestore.v1.Pipeline.Stage toStageProto(Stage stage) { .addArgs(encodeValue(findNearestStage.getVector())) .addArgs(encodeValue(findNearestStage.getOptions().getDistanceMeasure().toProtoString())) .putOptions("limit", encodeValue(findNearestStage.getOptions().getLimit())) - .putOptions("distance_field", encodeValue(findNearestStage.getOptions().getDistanceField())) + .putOptions( + "distance_field", encodeValue(findNearestStage.getOptions().getDistanceField())) .build(); } else if (stage instanceof GenericStage) { GenericStage genericStage = (GenericStage) stage; diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/TestUtil.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/TestUtil.java new file mode 100644 index 000000000..92a53ce8f --- /dev/null +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/TestUtil.java @@ -0,0 +1,24 @@ +package com.google.cloud.firestore; + +import com.google.firestore.v1.Value; +import java.util.HashMap; +import java.util.Map; + +public final class TestUtil { + public static Map getAggregateSnapshotData(AggregateQuerySnapshot snapshot) { + Map result = new HashMap<>(); + for (Map.Entry entry : snapshot.getData().entrySet()) { + if (entry.getValue().hasIntegerValue()) { + result.put(entry.getKey(), entry.getValue().getIntegerValue()); + } else if (entry.getValue().hasDoubleValue()) { + result.put(entry.getKey(), entry.getValue().getDoubleValue()); + } else if (entry.getValue().hasNullValue()) { + result.put(entry.getKey(), null); + } else { + throw new IllegalArgumentException("AggregateSnapshot has unrecognized value type"); + } + } + + return result; + } +} diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 2a4a09b89..e05788cb6 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -17,36 +17,53 @@ package com.google.cloud.firestore.it; import static com.google.cloud.firestore.it.ITQueryTest.map; +import static com.google.cloud.firestore.pipeline.expressions.Function.add; +import static com.google.cloud.firestore.pipeline.expressions.Function.and; +import static com.google.cloud.firestore.pipeline.expressions.Function.arrayContains; +import static com.google.cloud.firestore.pipeline.expressions.Function.arrayContainsAll; +import static com.google.cloud.firestore.pipeline.expressions.Function.arrayContainsAny; +import static com.google.cloud.firestore.pipeline.expressions.Function.arrayElement; +import static com.google.cloud.firestore.pipeline.expressions.Function.arrayFilter; +import static com.google.cloud.firestore.pipeline.expressions.Function.arrayTransform; import static com.google.cloud.firestore.pipeline.expressions.Function.avg; +import static com.google.cloud.firestore.pipeline.expressions.Function.collectionId; import static com.google.cloud.firestore.pipeline.expressions.Function.cosineDistance; +import static com.google.cloud.firestore.pipeline.expressions.Function.countAll; +import static com.google.cloud.firestore.pipeline.expressions.Function.dotProductDistance; import static com.google.cloud.firestore.pipeline.expressions.Function.equal; +import static com.google.cloud.firestore.pipeline.expressions.Function.euclideanDistance; +import static com.google.cloud.firestore.pipeline.expressions.Function.greaterThan; +import static com.google.cloud.firestore.pipeline.expressions.Function.isNull; import static com.google.cloud.firestore.pipeline.expressions.Function.lessThan; import static com.google.cloud.firestore.pipeline.expressions.Function.not; +import static com.google.cloud.firestore.pipeline.expressions.Function.notEqual; import static com.google.cloud.firestore.pipeline.expressions.Function.or; -import static com.google.cloud.firestore.pipeline.expressions.Ordering.ascending; -import static com.google.cloud.firestore.pipeline.expressions.Ordering.descending; +import static com.google.cloud.firestore.pipeline.expressions.Function.parent; +import static com.google.cloud.firestore.pipeline.expressions.Function.strConcat; +import static com.google.cloud.firestore.pipeline.expressions.Function.subtract; +import static com.google.common.truth.Truth.assertThat; import com.google.cloud.firestore.CollectionReference; import com.google.cloud.firestore.LocalFirestoreHelper; -import com.google.cloud.firestore.Pipeline; import com.google.cloud.firestore.PipelineResult; -import com.google.cloud.firestore.pipeline.PaginatingPipeline; import com.google.cloud.firestore.pipeline.expressions.Constant; import com.google.cloud.firestore.pipeline.expressions.Field; -import com.google.cloud.firestore.pipeline.expressions.Fields; -import com.google.cloud.firestore.pipeline.stages.FindNearest.DistanceMeasure; -import com.google.cloud.firestore.pipeline.stages.FindNearest.FindNearestOptions; +import com.google.common.collect.Lists; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class ITPipelineTest extends ITBaseTest { + private CollectionReference collection; + public CollectionReference testCollectionWithDocs(Map> docs) throws ExecutionException, InterruptedException, TimeoutException { CollectionReference collection = firestore.collection(LocalFirestoreHelper.autoId()); @@ -56,126 +73,684 @@ public CollectionReference testCollectionWithDocs(Map> testDocs = + List> data(List results) { + return results.stream().map(PipelineResult::getData).collect(Collectors.toList()); + } + + @Before + public void setup() throws Exception { + if (collection != null) { + return; + } + + Map> bookDocs = map( - "doc1", map("a", 1, "b", 0), - "doc2", map("a", 2, "b", 1), - "doc3", map("a", 3, "b", 2), - "doc4", map("a", 1, "b", 3), - "doc5", map("a", 1, "b", 1)); + "book1", + map( + "title", + "The Hitchhiker's Guide to the Galaxy", + "author", + "Douglas Adams", + "genre", + "Science Fiction", + "published", + 1979, + "rating", + 4.2, + "tags", + Lists.newArrayList("comedy", "space", "adventure"), + "awards", + map("hugo", true, "nebula", false)), + "book2", + map( + "title", + "Pride and Prejudice", + "author", + "Jane Austen", + "genre", + "Romance", + "published", + 1813, + "rating", + 4.5, + "tags", + Lists.newArrayList("classic", "social commentary", "love"), + "awards", + map("none", true)), + "book3", + map( + "title", + "One Hundred Years of Solitude", + "author", + "Gabriel García Márquez", + "genre", + "Magical Realism", + "published", + 1967, + "rating", + 4.3, + "tags", + Lists.newArrayList("family", "history", "fantasy"), + "awards", + map("nobel", true, "nebula", false)), + "book4", + map( + "title", + "The Lord of the Rings", + "author", + "J.R.R. Tolkien", + "genre", + "Fantasy", + "published", + 1954, + "rating", + 4.7, + "tags", + Lists.newArrayList("adventure", "magic", "epic"), + "awards", + map("hugo", false, "nebula", false)), + "book5", + map( + "title", + "The Handmaid's Tale", + "author", + "Margaret Atwood", + "genre", + "Dystopian", + "published", + 1985, + "rating", + 4.1, + "tags", + Lists.newArrayList("feminism", "totalitarianism", "resistance"), + "awards", + map("arthur c. clarke", true, "booker prize", false)), + "book6", + map( + "title", + "Crime and Punishment", + "author", + "Fyodor Dostoevsky", + "genre", + "Psychological Thriller", + "published", + 1866, + "rating", + 4.3, + "tags", + Lists.newArrayList("philosophy", "crime", "redemption"), + "awards", + map("none", true)), + "book7", + map( + "title", + "To Kill a Mockingbird", + "author", + "Harper Lee", + "genre", + "Southern Gothic", + "published", + 1960, + "rating", + 4.2, + "tags", + Lists.newArrayList("racism", "injustice", "coming-of-age"), + "awards", + map("pulitzer", true)), + "book8", + map( + "title", + "1984", + "author", + "George Orwell", + "genre", + "Dystopian", + "published", + 1949, + "rating", + 4.2, + "tags", + Lists.newArrayList("surveillance", "totalitarianism", "propaganda"), + "awards", + map("prometheus", true)), + "book9", + map( + "title", + "The Great Gatsby", + "author", + "F. Scott Fitzgerald", + "genre", + "Modernist", + "published", + 1925, + "rating", + 4.0, + "tags", + Lists.newArrayList("wealth", "american dream", "love"), + "awards", + map("none", true)), + "book10", + map( + "title", + "Dune", + "author", + "Frank Herbert", + "genre", + "Science Fiction", + "published", + 1965, + "rating", + 4.6, + "tags", + Lists.newArrayList("politics", "desert", "ecology"), + "awards", + map("hugo", true, "nebula", true))); + collection = testCollectionWithDocs(bookDocs); + } - CollectionReference collection = testCollectionWithDocs(testDocs); + @Test + public void fromCollectionThenAggregate() throws Exception { + List results = + collection.toPipeline().aggregate(countAll().toField("count")).execute(firestore).get(); + assertThat(data(results)).isEqualTo(Lists.newArrayList(map("count", 10L))); + + results = + collection + .toPipeline() + .filter(equal("genre", "Science Fiction")) + .aggregate( + countAll().toField("count"), + avg("rating").toField("avg_rating"), + Field.of("rating").max().toField("max_rating")) + .execute(firestore) + .get(); + assertThat(data(results)) + .isEqualTo(Lists.newArrayList(map("count", 2L, "avg_rating", 4.4, "max_rating", 4.6))); + } - Pipeline p = Pipeline.fromCollectionGroup(collection.getId()); - List results = p.execute(firestore).get(); - System.out.println(results.size()); + @Test + public void testMinMax() throws Exception { + List results = + collection + .toPipeline() + .aggregate( + countAll().toField("count"), + Field.of("rating").max().toField("max_rating"), + Field.of("published").min().toField("min_published")) + .execute(firestore) + .get(); + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map( + "count", 10L, + "max_rating", 4.7, + "min_published", 1813L))); } @Test - public void projections() throws Exception { - Pipeline p = Pipeline.fromCollectionGroup("coll1").select(Field.of("foo")); - List results = p.execute(firestore).get(); - System.out.println(results.size()); + public void selectSpecificFields() throws Exception { + List results = + collection + .toPipeline() + .select("title", "author") + .sort(Field.of("author").ascending()) + .execute(firestore) + .get(); - p = Pipeline.fromCollectionGroup("coll1").select(Fields.of("foo", "bar", "baz")); - results = p.execute(firestore).get(); + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map("title", "The Hitchhiker's Guide to the Galaxy", "author", "Douglas Adams"), + map("title", "The Great Gatsby", "author", "F. Scott Fitzgerald"), + map("title", "Dune", "author", "Frank Herbert"), + map("title", "Crime and Punishment", "author", "Fyodor Dostoevsky"), + map("title", "One Hundred Years of Solitude", "author", "Gabriel García Márquez"), + map("title", "1984", "author", "George Orwell"), + map("title", "To Kill a Mockingbird", "author", "Harper Lee"), + map("title", "The Lord of the Rings", "author", "J.R.R. Tolkien"), + map("title", "Pride and Prejudice", "author", "Jane Austen"), + map("title", "The Handmaid's Tale", "author", "Margaret Atwood"))); } @Test - public void filters() throws Exception { - Pipeline p = - Pipeline.fromCollectionGroup("coll1") - .filter(Field.of("foo").equal(42)) - .filter(or(Field.of("bar").lessThan(100), Constant.of("value").equal(Field.of("key")))) - .filter(not(Constant.of(128).inAny("f1", "f2"))); - List results = p.execute(firestore).get(); + public void filterByMultipleConditions() throws Exception { + List results = + collection + .toPipeline() + .filter(and(greaterThan("rating", 4.5), equal("genre", "Science Fiction"))) + .execute(firestore) + .get(); - p = - Pipeline.fromCollectionGroup("coll1") - .filter(equal(Field.of("foo"), 42)) - .filter( - or(lessThan(Field.of("bar"), 100), equal(Field.of("key"), Constant.of("value")))) - .filter(not(Constant.of(128).inAny("f1", "f2"))); - results = p.execute(firestore).get(); + // It's Dune + assertThat(data(results)) + .isEqualTo(Lists.newArrayList(collection.document("book10").get().get().getData())); + assertThat(results.get(0).getReference()).isEqualTo(collection.document("book10")); } @Test - public void inFilters() throws Exception { - Pipeline p = Pipeline.fromCollectionGroup("coll1").filter(Field.of("foo").inAny(42, "42")); - List results = p.execute(firestore).get(); + public void filterByOrCondition() throws Exception { + List results = + collection + .toPipeline() + .filter(or(equal("genre", "Romance"), equal("genre", "Dystopian"))) + .select("title") + .execute(firestore) + .get(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map("title", "Pride and Prejudice"), + map("title", "The Handmaid's Tale"), + map("title", "1984"))); } @Test - public void findNearest() throws Exception { - Pipeline p = Pipeline.fromCollectionGroup("coll1").filter(Field.of("foo").inAny(42, "42")); + public void testPipelineWithOffsetAndLimit() throws Exception { List results = - p.findNearest( - Field.of("embedding1"), - new double[] {}, - FindNearestOptions.newInstance(10, DistanceMeasure.cosine(), Field.of("distance"))) + collection + .toPipeline() + .sort(Field.of("author").ascending()) + .offset(5) + .limit(3) + .select("title", "author") .execute(firestore) .get(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map("title", "1984", "author", "George Orwell"), + map("title", "To Kill a Mockingbird", "author", "Harper Lee"), + map("title", "The Lord of the Rings", "author", "J.R.R. Tolkien"))); } @Test - public void aggregateWithoutGrouping() throws Exception { - Pipeline p = - Pipeline.fromDatabase() - .filter(Field.of("foo").inAny(42, "bar")) - .aggregate(avg(Field.of("score")).toField("avg_score_1")); - List results = p.execute(firestore).get(); + public void testArrayContains() throws Exception { + List results = + collection.toPipeline().filter(arrayContains("tags", "comedy")).execute(firestore).get(); + assertThat(data(results)) + // The Hitchhiker's Guide to the Galaxy + .isEqualTo(Lists.newArrayList(collection.document("book1").get().get().getData())); } @Test - public void sorts() throws Exception { - Pipeline p = - Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny(42, "42")) - .sort( - Field.of("rank").ascending(), - cosineDistance(Field.of("embedding1"), Field.of("embedding2")).descending()) - .limit(100); - List results = p.execute(firestore).get(); + public void testArrayContainsAny() throws Exception { + List results = + collection + .toPipeline() + .filter(arrayContainsAny("tags", "comedy", "classic")) + .select("title") + .execute(firestore) + .get(); - // equivalent but more concise. - p = - Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny(42, false)) - .sort( - ascending(Field.of("rank")), - descending(cosineDistance(Field.of("embedding1"), Field.of("embedding2")))) - .limit(100); - results = p.execute(firestore).get(); + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map("title", "The Hitchhiker's Guide to the Galaxy"), + map("title", "Pride and Prejudice"))); } @Test - public void pagination() throws Exception { - PaginatingPipeline p = - Pipeline.fromCollection("coll1") - .filter(Field.of("foo").inAny(42, "bar")) - .paginate( - 100, cosineDistance(Field.of("embedding1"), Field.of("embedding2")).descending()); + public void testArrayContainsAll() throws Exception { + List results = + collection + .toPipeline() + .filter(arrayContainsAll("tags", "adventure", "magic")) + .execute(firestore) + .get(); - List results = p.firstPage().execute(firestore).get(); - List secondPage = - p.startAfter(results.get(results.size() - 1)).firstPage().execute(firestore).get(); + assertThat(data(results)).isEqualTo(Lists.newArrayList(map("title", "The Lord of the Rings"))); } @Test - public void limit() throws Exception { - Pipeline p = Pipeline.fromDatabase().filter(Field.of("foo").inAny(42, "bar")).limit(10); + public void testArrayLength() throws Exception { + List results = + collection + .toPipeline() + .select(Field.of("tags").arrayLength().asAlias("tagsCount")) + .filter(equal("tagsCount", 3)) + .execute(firestore) + .get(); - List result = p.execute(firestore).get(); + // All documents have 3 tags in the test dataset + assertThat(data(results)).hasSize(10); } @Test - public void offset() throws Exception { - Pipeline p = - Pipeline.fromDocuments(firestore.document("foo/bar1"), firestore.document("foo/bar2")) - .offset(1); + public void testArrayConcat() throws Exception { + List results = + collection + .toPipeline() + .select(Field.of("tags").arrayConcat("newTag1", "newTag2").asAlias("modifiedTags")) + .limit(1) + .execute(firestore) + .get(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map( + "modifiedTags", + Lists.newArrayList("comedy", "space", "adventure", "newTag1", "newTag2")))); + } + + @Test + public void testArrayFilter() throws Exception { + List results = + collection + .toPipeline() + .select( + arrayFilter(Field.of("tags"), equal(arrayElement(), "")).asAlias("filteredTags")) + .limit(1) + .execute(firestore) + .get(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map("filteredTags", Lists.newArrayList("comedy", "space", "adventure")))); + } + + @Test + public void testArrayTransform() throws Exception { + List results = + collection + .toPipeline() + .select( + arrayTransform(Field.of("tags"), strConcat(arrayElement(), "transformed")) + .asAlias("transformedTags")) + .limit(1) + .execute(firestore) + .get(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map( + "transformedTags", + Lists.newArrayList( + "comedytransformed", "spacetransformed", "adventuretransformed")))); + } + + @Test + public void testStrConcat() throws Exception { + List results = + collection + .toPipeline() + .select(strConcat(Field.of("author"), " - ", Field.of("title")).asAlias("bookInfo")) + .limit(1) + .execute(firestore) + .get(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map("bookInfo", "Douglas Adams - The Hitchhiker's Guide to the Galaxy"))); + } + + @Test + public void testLength() throws Exception { + List results = + collection + .toPipeline() + .select(Field.of("title").length().asAlias("titleLength"), Field.of("title")) + .filter(greaterThan("titleLength", 20)) + .execute(firestore) + .get(); + + assertThat(data(results)) + .isEqualTo(Lists.newArrayList(map("titleLength", 32L), map("titleLength", 27L))); + } + + @Test + public void testToLowercase() throws Exception { + List results = + collection + .toPipeline() + .select(Field.of("title").toLowercase().asAlias("lowercaseTitle")) + .limit(1) + .execute(firestore) + .get(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList(map("lowercaseTitle", "the hitchhiker's guide to the galaxy"))); + } + + @Test + public void testToUppercase() throws Exception { + List results = + collection + .toPipeline() + .select(Field.of("author").toUppercase().asAlias("uppercaseAuthor")) + .limit(1) + .execute(firestore) + .get(); + + assertThat(data(results)) + .isEqualTo(Lists.newArrayList(map("uppercaseAuthor", "DOUGLAS ADAMS"))); + } + + @Test + public void testTrim() throws Exception { + List results = + collection + .toPipeline() + .addFields( + strConcat(Constant.of(" "), Field.of("title"), Constant.of(" ")) + .asAlias("spacedTitle")) + .select(Field.of("spacedTitle").trim().asAlias("trimmedTitle"), Field.of("spacedTitle")) + .limit(1) + .execute(firestore) + .get(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map( + "spacedTitle", " The Hitchhiker's Guide to the Galaxy ", + "trimmedTitle", "The Hitchhiker's Guide to the Galaxy"))); + } + + @Test + public void testLike() throws Exception { + List results = + collection + .toPipeline() + .filter(Field.of("title").like("%Guide%")) + .select("title") + .execute(firestore) + .get(); + + assertThat(data(results)) + .isEqualTo(Lists.newArrayList(map("title", "The Hitchhiker's Guide to the Galaxy"))); + } + + @Test + public void testRegexContains() throws Exception { + // Find titles that contain either "the" or "of" (case-insensitive) + List results = + collection + .toPipeline() + .filter(Field.of("title").regexContains(".*(?i)(the|of).*")) + .execute(firestore) + .get(); + + assertThat(data(results)).hasSize(5); + } + + @Test + public void testArithmeticOperations() throws Exception { + List results = + collection + .toPipeline() + .select( + add(Field.of("rating"), 1).asAlias("ratingPlusOne"), + subtract(Field.of("published"), 1900).asAlias("yearsSince1900"), + Field.of("rating").multiply(10).asAlias("ratingTimesTen"), + Field.of("rating").divide(2).asAlias("ratingDividedByTwo")) + .limit(1) + .execute(firestore) + .get(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map( + "ratingPlusOne", + 5.2, + "yearsSince1900", + 79L, + "ratingTimesTen", + 42.0, + "ratingDividedByTwo", + 2.1))); + } + + @Test + public void testComparisonOperators() throws Exception { + List results = + collection + .toPipeline() + .filter( + and( + greaterThan("rating", 4.2), + Field.of("rating").lessThanOrEqual(4.5), + notEqual("genre", "Science Fiction"))) + .select("rating", "title") + .sort(Field.of("title").ascending()) + .execute(firestore) + .get(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map("rating", 4.3, "title", "Crime and Punishment"), + map("rating", 4.3, "title", "One Hundred Years of Solitude"), + map("rating", 4.5, "title", "Pride and Prejudice"))); + } + + @Test + public void testLogicalOperators() throws Exception { + List results = + collection + .toPipeline() + .filter( + or( + and(greaterThan("rating", 4.5), equal("genre", "Science Fiction")), + lessThan("published", 1900))) + .select("title") + .sort(Field.of("title").ascending()) + .execute(firestore) + .get(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map("title", "Crime and Punishment"), + map("title", "Dune"), + map("title", "Pride and Prejudice"))); + } + + @Test + public void testChecks() throws Exception { + List results = + collection + .toPipeline() + .filter(not(Field.of("rating").isNaN())) // Filter out any documents with NaN rating + .select( + isNull("rating").asAlias("ratingIsNull"), + not(Field.of("rating").isNaN()).asAlias("ratingIsNotNaN")) + .limit(1) + .execute(firestore) + .get(); + + assertThat(data(results)) + .isEqualTo(Lists.newArrayList(map("ratingIsNull", false, "ratingIsNotNaN", true))); + } + + @Test + public void testMapGet() throws Exception { + List results = + collection + .toPipeline() + .select(Field.of("awards").mapGet("hugo").asAlias("hugoAward"), Field.of("title")) + .filter(equal("hugoAward", true)) + .execute(firestore) + .get(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map("hugoAward", true, "title", "The Hitchhiker's Guide to the Galaxy"), + map("hugoAward", true, "title", "Dune"))); + } + + @Test + public void testParent() throws Exception { + List results = + collection + .toPipeline() + .select( + parent(collection.document("chile").collection("subCollection").getPath()) + .asAlias("parent")) + .limit(1) + .execute(firestore) + .get(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList(map("parent", "projects/projectId/databases/(default)/documents"))); + } + + @Test + public void testCollectionId() throws Exception { + List results = + collection + .toPipeline() + .select(collectionId(collection.document("chile")).asAlias("collectionId")) + .limit(1) + .execute(firestore) + .get(); + + assertThat(data(results)).isEqualTo(Lists.newArrayList(map("collectionId", "books"))); + } + + @Test + public void testDistanceFunctions() throws Exception { + double[] sourceVector = {0.1, 0.1}; + double[] targetVector = {0.5, 0.8}; + List results = + collection + .toPipeline() + .select( + cosineDistance(Constant.ofVector(sourceVector), targetVector) + .asAlias("cosineDistance"), + dotProductDistance(Constant.ofVector(sourceVector), targetVector) + .asAlias("dotProductDistance"), + euclideanDistance(Constant.ofVector(sourceVector), targetVector) + .asAlias("euclideanDistance")) + .limit(1) + .execute(firestore) + .get(); + } + + @Test + public void testNestedFields() throws Exception { + List results = + collection + .toPipeline() + .filter(equal("awards.hugo", true)) + .select("title", "awards.hugo") + .execute(firestore) + .get(); - List result = p.execute(firestore).get(); + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map("title", "The Hitchhiker's Guide to the Galaxy", "awards.hugo", true), + map("title", "Dune", "awards.hugo", true))); } } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryAggregationsTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryAggregationsTest.java index 7659d4656..6a90f4f81 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryAggregationsTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryAggregationsTest.java @@ -30,6 +30,7 @@ import com.google.api.core.ApiFuture; import com.google.cloud.firestore.*; +import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; import org.junit.Ignore; @@ -56,6 +57,19 @@ private CollectionReference testCollectionWithDocs(Map pipelineResults = + query.toPipeline().execute(query.getQuery().getFirestore()).get(); + assertThat(pipelineResults).hasSize(1); + assertThat(pipelineResults.get(0).getData()) + .isEqualTo(TestUtil.getAggregateSnapshotData(snapshot)); + + return snapshot; + } + public static void writeAllDocs( CollectionReference collection, Map> docs) throws InterruptedException { @@ -74,7 +88,8 @@ public static void writeAllDocs( @Test public void canRunCountUsingAggregationMethod() throws Exception { CollectionReference collection = testCollectionWithDocs(testDocs1); - AggregateQuerySnapshot snapshot = collection.aggregate(AggregateField.count()).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(AggregateField.count())); assertThat(snapshot.getCount()).isEqualTo(2); } @@ -92,10 +107,10 @@ public void allowsAliasesForLongestFieldNames() throws Exception { CollectionReference collection = testCollectionWithDocs(testDocs); AggregateQuerySnapshot snapshot = - collection.aggregate(AggregateField.sum(longestField)).get().get(); + verifyPipelineReturnsSameResult(collection.aggregate(AggregateField.sum(longestField))); assertThat(snapshot.get(AggregateField.sum(longestField))).isEqualTo(6); AggregateQuerySnapshot snapshot2 = - collection.aggregate(AggregateField.average(longestField)).get().get(); + verifyPipelineReturnsSameResult(collection.aggregate(AggregateField.average(longestField))); assertThat(snapshot2.get(AggregateField.average(longestField))).isEqualTo(3.0); } @@ -134,14 +149,16 @@ public void aggregateErrorMessageIfIndexIsMissing() throws Exception { @Test public void canRunSumQuery() throws Exception { CollectionReference collection = testCollectionWithDocs(testDocs1); - AggregateQuerySnapshot snapshot = collection.aggregate(sum("pages")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(sum("pages"))); assertThat(snapshot.get(sum("pages"))).isEqualTo(150); } @Test public void canRunAverageQuery() throws Exception { CollectionReference collection = testCollectionWithDocs(testDocs1); - AggregateQuerySnapshot snapshot = collection.aggregate(average("pages")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(average("pages"))); assertThat(snapshot.get(average("pages"))).isEqualTo(75.0); } @@ -149,7 +166,8 @@ public void canRunAverageQuery() throws Exception { public void canGetMultipleAggregationsInTheSameQuery() throws Exception { CollectionReference collection = testCollectionWithDocs(testDocs1); AggregateQuerySnapshot snapshot = - collection.aggregate(sum("pages"), average("pages"), AggregateField.count()).get().get(); + verifyPipelineReturnsSameResult( + collection.aggregate(sum("pages"), average("pages"), AggregateField.count())); assertThat(snapshot.get(sum("pages"))).isEqualTo(150); assertThat(snapshot.get(average("pages"))).isEqualTo(75.0); assertThat(snapshot.get(AggregateField.count())).isEqualTo(2); @@ -159,7 +177,8 @@ public void canGetMultipleAggregationsInTheSameQuery() throws Exception { public void getCorrectTypeForSumLong() throws Exception { Map> testDocs = map("a", map("foo", 100), "b", map("foo", 100)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(sum("foo")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(sum("foo"))); Object sum = snapshot.get(sum("foo")); assertThat(sum instanceof Long).isTrue(); } @@ -168,7 +187,8 @@ public void getCorrectTypeForSumLong() throws Exception { public void getCorrectTypeForSumDouble() throws Exception { Map> testDocs = map("a", map("foo", 100.5), "b", map("foo", 100)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(sum("foo")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(sum("foo"))); Object sum = snapshot.get(sum("foo")); assertThat(sum instanceof Double).isTrue(); } @@ -178,7 +198,8 @@ public void getCorrectTypeForSumNaN() throws Exception { Map> testDocs = map("a", map("foo", 100.5), "b", map("foo", Double.NaN)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(sum("foo")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(sum("foo"))); Object sum = snapshot.get(sum("foo")); assertThat(sum instanceof Double).isTrue(); assertThat(sum.equals(Double.NaN)); @@ -187,7 +208,8 @@ public void getCorrectTypeForSumNaN() throws Exception { @Test public void getCorrectTypeForAverageDouble() throws Exception { CollectionReference collection = testCollectionWithDocs(testDocs1); - AggregateQuerySnapshot snapshot = collection.aggregate(average("pages")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(average("pages"))); Object average = snapshot.get((AggregateField) average("pages")); assertThat(average instanceof Double).isTrue(); } @@ -197,7 +219,8 @@ public void getCorrectTypeForAverageNaN() throws Exception { Map> testDocs = map("a", map("foo", 100.5), "b", map("foo", Double.NaN)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(average("foo")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(average("foo"))); Object sum = snapshot.get(average("foo")); assertThat(sum instanceof Double).isTrue(); assertThat(sum.equals(Double.NaN)); @@ -206,7 +229,8 @@ public void getCorrectTypeForAverageNaN() throws Exception { @Test public void getCorrectTypeForAverageNull() throws Exception { CollectionReference collection = testCollection(); - AggregateQuerySnapshot snapshot = collection.aggregate(average("bar")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(average("bar"))); Object sum = snapshot.get(average("bar")); assertThat(sum == null).isTrue(); } @@ -222,7 +246,8 @@ public void canPerformMaxAggregations() throws Exception { AggregateField f3 = AggregateField.count(); AggregateField f4 = sum("foo"); AggregateField f5 = sum("bar"); - AggregateQuerySnapshot snapshot = collection.aggregate(f1, f2, f3, f4, f5).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(f1, f2, f3, f4, f5)); assertThat(snapshot.get(f1)).isEqualTo(150); assertThat(snapshot.get(f2)).isEqualTo(75.0); assertThat(snapshot.get(f3)).isEqualTo(2); @@ -289,7 +314,8 @@ public void aggregateQueriesSupportCollectionGroups() throws Exception { .set(data)); CollectionGroup collectionGroup = firestore.collectionGroup(collectionGroupId); AggregateQuerySnapshot snapshot = - collectionGroup.aggregate(AggregateField.count(), sum("x"), average("x")).get().get(); + verifyPipelineReturnsSameResult( + collectionGroup.aggregate(AggregateField.count(), sum("x"), average("x"))); assertThat(snapshot.get(AggregateField.count())).isEqualTo(2); assertThat(snapshot.get(sum("x"))).isEqualTo(4); assertThat(snapshot.get(average("x"))).isEqualTo(2); @@ -312,10 +338,9 @@ public void performsAggregationsOnDocumentsWithAllAggregatedFields() throws Exce map("author", "authorD", "title", "titleD", "pages", 50)); CollectionReference collection = testCollectionWithDocs(testDocs); AggregateQuerySnapshot snapshot = - collection - .aggregate(sum("pages"), average("pages"), average("year"), AggregateField.count()) - .get() - .get(); + verifyPipelineReturnsSameResult( + collection.aggregate( + sum("pages"), average("pages"), average("year"), AggregateField.count())); assertThat(snapshot.get(sum("pages"))).isEqualTo(300); assertThat(snapshot.get(average("pages"))).isEqualTo(100); assertThat(snapshot.get(average("year"))).isEqualTo(2007); @@ -353,7 +378,8 @@ public void performsAggregationsWhenNaNExistsForSomeFieldValues() throws Excepti 0)); CollectionReference collection = testCollectionWithDocs(testDocs); AggregateQuerySnapshot snapshot = - collection.aggregate(sum("rating"), sum("pages"), average("year")).get().get(); + verifyPipelineReturnsSameResult( + collection.aggregate(sum("rating"), sum("pages"), average("year"))); assertThat(snapshot.get(sum("rating"))).isEqualTo(Double.NaN); assertThat(snapshot.get(sum("pages"))).isEqualTo(300); assertThat(snapshot.get(average("year"))).isEqualTo(2000); @@ -362,7 +388,8 @@ public void performsAggregationsWhenNaNExistsForSomeFieldValues() throws Excepti @Test public void throwsAnErrorWhenGettingTheResultOfAnUnrequestedAggregation() throws Exception { CollectionReference collection = testCollectionWithDocs(testDocs1); - AggregateQuerySnapshot snapshot = collection.aggregate(sum("pages")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(sum("pages"))); Exception exception = null; try { snapshot.get(average("pages")); @@ -406,16 +433,15 @@ public void performsAggregationWhenUsingInOperator() throws Exception { 0)); CollectionReference collection = testCollectionWithDocs(testDocs); AggregateQuerySnapshot snapshot = - collection - .whereIn("rating", asList(5, 3)) - .aggregate( - sum("rating"), - average("rating"), - sum("pages"), - average("pages"), - AggregateField.count()) - .get() - .get(); + verifyPipelineReturnsSameResult( + collection + .whereIn("rating", asList(5, 3)) + .aggregate( + sum("rating"), + average("rating"), + sum("pages"), + average("pages"), + AggregateField.count())); assertThat(snapshot.get(sum("rating"))).isEqualTo(8); assertThat(snapshot.get(average("rating"))).isEqualTo(4); assertThat(snapshot.get(sum("pages"))).isEqualTo(200); @@ -464,16 +490,15 @@ public void performsAggregationWhenUsingArrayContainsAnyOperator() throws Except asList(0))); CollectionReference collection = testCollectionWithDocs(testDocs); AggregateQuerySnapshot snapshot = - collection - .whereArrayContainsAny("rating", asList(5, 3)) - .aggregate( - sum("rating"), - average("rating"), - sum("pages"), - average("pages"), - AggregateField.count()) - .get() - .get(); + verifyPipelineReturnsSameResult( + collection + .whereArrayContainsAny("rating", asList(5, 3)) + .aggregate( + sum("rating"), + average("rating"), + sum("pages"), + average("pages"), + AggregateField.count())); assertThat(snapshot.get(sum("rating"))).isEqualTo(0); assertThat(snapshot.get(average("rating"))).isEqualTo(null); assertThat(snapshot.get(sum("pages"))).isEqualTo(200); @@ -503,10 +528,9 @@ public void performsAggregationsOnNestedMapValues() throws Exception { map("pages", 50, "rating", map("critic", 4, "user", 4)))); CollectionReference collection = testCollectionWithDocs(testDocs); AggregateQuerySnapshot snapshot = - collection - .aggregate(sum("metadata.pages"), average("metadata.pages"), AggregateField.count()) - .get() - .get(); + verifyPipelineReturnsSameResult( + collection.aggregate( + sum("metadata.pages"), average("metadata.pages"), AggregateField.count())); assertThat(snapshot.get(sum("metadata.pages"))).isEqualTo(150); assertThat(snapshot.get(average("metadata.pages"))).isEqualTo(75); assertThat(snapshot.get(AggregateField.count())).isEqualTo(2); @@ -520,7 +544,8 @@ public void performsSumThatResultsInFloat() throws Exception { "b", map("author", "authorB", "title", "titleB", "rating", 4.5), "c", map("author", "authorC", "title", "titleC", "rating", 3)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(sum("rating")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(sum("rating"))); Object sum = snapshot.get(sum("rating")); assertThat(sum instanceof Double).isTrue(); assertThat(sum).isEqualTo(12.5); @@ -534,7 +559,8 @@ public void performsSumOfIntsAndFloatsThatResultsInInt() throws Exception { "b", map("author", "authorB", "title", "titleB", "rating", 4.5), "c", map("author", "authorC", "title", "titleC", "rating", 3.5)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(sum("rating")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(sum("rating"))); Object sum = snapshot.get(sum("rating")); assertThat(sum instanceof Double).isTrue(); assertThat(sum).isEqualTo(13.0); @@ -576,7 +602,8 @@ public void performsSumThatIsNegative() throws Exception { "c", map("author", "authorC", "title", "titleC", "rating", -101), "d", map("author", "authorD", "title", "titleD", "rating", -10000)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(sum("rating")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(sum("rating"))); assertThat(snapshot.get(sum("rating"))).isEqualTo(-10101); } @@ -587,7 +614,8 @@ public void performsSumThatIsPositiveInfinity() throws Exception { "a", map("author", "authorA", "title", "titleA", "rating", Double.MAX_VALUE), "b", map("author", "authorB", "title", "titleB", "rating", Double.MAX_VALUE)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(sum("rating")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(sum("rating"))); Object sum = snapshot.get(sum("rating")); assertThat(sum instanceof Double).isTrue(); assertThat(sum).isEqualTo(Double.POSITIVE_INFINITY); @@ -602,7 +630,8 @@ public void performsSumThatIsNegativeInfinity() throws Exception { "a", map("author", "authorA", "title", "titleA", "rating", -Double.MAX_VALUE), "b", map("author", "authorB", "title", "titleB", "rating", -Double.MAX_VALUE)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(sum("rating")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(sum("rating"))); Object sum = snapshot.get(sum("rating")); assertThat(sum instanceof Double).isTrue(); assertThat(sum).isEqualTo(Double.NEGATIVE_INFINITY); @@ -638,7 +667,8 @@ public void performsSumThatIncludesNaN() throws Exception { "c", map("author", "authorC", "title", "titleC", "rating", Double.NaN), "d", map("author", "authorD", "title", "titleD", "rating", 0)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(sum("rating")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(sum("rating"))); assertThat(snapshot.get(sum("rating"))).isEqualTo(Double.NaN); } @@ -646,7 +676,8 @@ public void performsSumThatIncludesNaN() throws Exception { public void performsSumOverResultSetOfZeroDocuments() throws Exception { CollectionReference collection = testCollectionWithDocs(testDocs1); AggregateQuerySnapshot snapshot = - collection.whereGreaterThan("pages", 200).aggregate(sum("pages")).get().get(); + verifyPipelineReturnsSameResult( + collection.whereGreaterThan("pages", 200).aggregate(sum("pages"))); assertThat(snapshot.get(sum("pages"))).isEqualTo(0); } @@ -660,7 +691,8 @@ public void performsSumOnlyOnNumericFields() throws Exception { "d", map("author", "authorD", "title", "titleD", "rating", 1)); CollectionReference collection = testCollectionWithDocs(testDocs); AggregateQuerySnapshot snapshot = - collection.aggregate(sum("rating"), AggregateField.count()).get().get(); + verifyPipelineReturnsSameResult( + collection.aggregate(sum("rating"), AggregateField.count())); assertThat(snapshot.get(sum("rating"))).isEqualTo(10); assertThat(snapshot.get(AggregateField.count())).isEqualTo(4); } @@ -670,7 +702,8 @@ public void performsSumOfMinIEEE754() throws Exception { Map> testDocs = map("a", map("author", "authorA", "title", "titleA", "rating", Double.MIN_VALUE)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(sum("rating")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(sum("rating"))); assertThat(snapshot.get(sum("rating"))).isEqualTo(Double.MIN_VALUE); } @@ -682,7 +715,8 @@ public void performsAverageOfIntsThatResultsInAnInt() throws Exception { "b", map("author", "authorB", "title", "titleB", "rating", 5), "c", map("author", "authorC", "title", "titleC", "rating", 0)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(average("rating")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(average("rating"))); assertThat(snapshot.get(average("rating"))).isEqualTo(5); assertThat(snapshot.getLong(average("rating"))).isEqualTo(5L); assertThat(snapshot.getDouble(average("rating"))).isEqualTo(5.0); @@ -695,7 +729,8 @@ public void performsAverageOfFloatsThatResultsInAnInt() throws Exception { "a", map("author", "authorA", "title", "titleA", "rating", 10.5), "b", map("author", "authorB", "title", "titleB", "rating", 9.5)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(average("rating")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(average("rating"))); assertThat(snapshot.get(average("rating")) instanceof Double).isTrue(); assertThat(snapshot.get(average("rating"))).isEqualTo(10); assertThat(snapshot.getLong(average("rating"))).isEqualTo(10L); @@ -710,7 +745,8 @@ public void performsAverageOfFloatsAndIntsThatResultsInAnInt() throws Exception "b", map("author", "authorB", "title", "titleB", "rating", 9.5), "c", map("author", "authorC", "title", "titleC", "rating", 10.5)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(average("rating")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(average("rating"))); assertThat(snapshot.get(average("rating"))).isEqualTo(10); assertThat(snapshot.getLong(average("rating"))).isEqualTo(10L); assertThat(snapshot.getDouble(average("rating"))).isEqualTo(10.0); @@ -724,7 +760,8 @@ public void performsAverageOfFloatsThatResultsInAFloat() throws Exception { "b", map("author", "authorB", "title", "titleB", "rating", 4.5), "c", map("author", "authorC", "title", "titleC", "rating", 3.5)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(average("rating")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(average("rating"))); assertThat(snapshot.get(average("rating"))).isEqualTo(4.5); assertThat(snapshot.getDouble(average("rating"))).isEqualTo(4.5); assertThat(snapshot.getLong(average("rating"))).isEqualTo(4L); @@ -738,7 +775,8 @@ public void performsAverageOfFloatsAndIntsThatResultsInAFloat() throws Exception "b", map("author", "authorB", "title", "titleB", "rating", 9), "c", map("author", "authorC", "title", "titleC", "rating", 10)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(average("rating")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(average("rating"))); assertThat(snapshot.get(average("rating"))).isEqualTo(27.6 / 3); assertThat(snapshot.getDouble(average("rating"))).isEqualTo(27.6 / 3); assertThat(snapshot.getLong(average("rating"))).isEqualTo(9L); @@ -751,7 +789,8 @@ public void performsAverageOfIntsThatResultsInAFloat() throws Exception { "a", map("author", "authorA", "title", "titleA", "rating", 10), "b", map("author", "authorB", "title", "titleB", "rating", 9)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(average("rating")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(average("rating"))); assertThat(snapshot.get(average("rating"))).isEqualTo(9.5); assertThat(snapshot.getDouble(average("rating"))).isEqualTo(9.5d); assertThat(snapshot.getLong(average("rating"))).isEqualTo(9L); @@ -764,7 +803,8 @@ public void performsAverageCausingUnderflow() throws Exception { "a", map("author", "authorA", "title", "titleA", "rating", Double.MIN_VALUE), "b", map("author", "authorB", "title", "titleB", "rating", 0)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(average("rating")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(average("rating"))); assertThat(snapshot.get(average("rating"))).isEqualTo(0); assertThat(snapshot.getDouble(average("rating"))).isEqualTo(0.0d); assertThat(snapshot.getLong(average("rating"))).isEqualTo(0L); @@ -775,7 +815,8 @@ public void performsAverageOfMinIEEE754() throws Exception { Map> testDocs = map("a", map("author", "authorA", "title", "titleA", "rating", Double.MIN_VALUE)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(average("rating")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(average("rating"))); assertThat(snapshot.get(average("rating"))).isEqualTo(Double.MIN_VALUE); assertThat(snapshot.getDouble(average("rating"))).isEqualTo(Double.MIN_VALUE); assertThat(snapshot.getLong(average("rating"))).isEqualTo(0); @@ -790,7 +831,8 @@ public void performsAverageThatCouldOverflowIEEE754DuringAccumulation() throws E "b", map("author", "authorB", "title", "titleB", "rating", Double.MAX_VALUE)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(average("rating")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(average("rating"))); assertThat(snapshot.get(average("rating"))).isEqualTo(Double.POSITIVE_INFINITY); assertThat(snapshot.getDouble(average("rating"))).isEqualTo(Double.POSITIVE_INFINITY); assertThat(snapshot.getLong(average("rating"))).isEqualTo(Long.MAX_VALUE); @@ -809,7 +851,8 @@ public void performsAverageThatIncludesNaN() throws Exception { "d", map("author", "authorD", "title", "titleD", "rating", 0)); CollectionReference collection = testCollectionWithDocs(testDocs); - AggregateQuerySnapshot snapshot = collection.aggregate(average("rating")).get().get(); + AggregateQuerySnapshot snapshot = + verifyPipelineReturnsSameResult(collection.aggregate(average("rating"))); assertThat(snapshot.get(average("rating"))).isEqualTo(Double.NaN); assertThat(snapshot.getDouble(average("rating"))).isEqualTo(Double.NaN); assertThat(snapshot.getLong(average("rating"))).isEqualTo(0L); @@ -819,7 +862,8 @@ public void performsAverageThatIncludesNaN() throws Exception { public void performsAverageOverResultSetOfZeroDocuments() throws Exception { CollectionReference collection = testCollectionWithDocs(testDocs1); AggregateQuerySnapshot snapshot = - collection.whereGreaterThan("pages", 200).aggregate(average("pages")).get().get(); + verifyPipelineReturnsSameResult( + collection.whereGreaterThan("pages", 200).aggregate(average("pages"))); assertThat(snapshot.get(average("pages"))).isEqualTo(null); assertThat(snapshot.getDouble(average("pages"))).isEqualTo(null); assertThat(snapshot.getLong(average("pages"))).isEqualTo(null); @@ -835,7 +879,8 @@ public void performsAverageOnlyOnNumericFields() throws Exception { "d", map("author", "authorD", "title", "titleD", "rating", 6)); CollectionReference collection = testCollectionWithDocs(testDocs); AggregateQuerySnapshot snapshot = - collection.aggregate(average("rating"), AggregateField.count()).get().get(); + verifyPipelineReturnsSameResult( + collection.aggregate(average("rating"), AggregateField.count())); assertThat(snapshot.get(average("rating"))).isEqualTo(5); assertThat(snapshot.get(AggregateField.count())).isEqualTo(4); } @@ -854,39 +899,35 @@ public void aggregatesWithDocumentReferenceCursors() throws Exception { CollectionReference collection = testCollectionWithDocs(testDocs); AggregateQuerySnapshot snapshot = - collection - .orderBy(FieldPath.documentId()) - .startAfter(collection.document("c")) - .aggregate(sum("num")) - .get() - .get(); + verifyPipelineReturnsSameResult( + collection + .orderBy(FieldPath.documentId()) + .startAfter(collection.document("c")) + .aggregate(sum("num"))); assertThat(snapshot.get(sum("num"))).isEqualTo(9); snapshot = - collection - .orderBy(FieldPath.documentId()) - .startAt(collection.document("c")) - .aggregate(sum("num")) - .get() - .get(); + verifyPipelineReturnsSameResult( + collection + .orderBy(FieldPath.documentId()) + .startAt(collection.document("c")) + .aggregate(sum("num"))); assertThat(snapshot.get(sum("num"))).isEqualTo(12); snapshot = - collection - .orderBy(FieldPath.documentId()) - .endBefore(collection.document("c")) - .aggregate(sum("num")) - .get() - .get(); + verifyPipelineReturnsSameResult( + collection + .orderBy(FieldPath.documentId()) + .endBefore(collection.document("c")) + .aggregate(sum("num"))); assertThat(snapshot.get(sum("num"))).isEqualTo(3); snapshot = - collection - .orderBy(FieldPath.documentId()) - .endAt(collection.document("c")) - .aggregate(sum("num")) - .get() - .get(); + verifyPipelineReturnsSameResult( + collection + .orderBy(FieldPath.documentId()) + .endAt(collection.document("c")) + .aggregate(sum("num"))); assertThat(snapshot.get(sum("num"))).isEqualTo(6); } @@ -902,7 +943,7 @@ CollectionReference addTwoDocsForCursorTesting() throws InterruptedException { public void aggregateWithNoFilterNoOrderByNoCursor() throws Exception { CollectionReference collection = addTwoDocsForCursorTesting(); AggregateQuery query = collection.aggregate(sum("num")); - AggregateQuerySnapshot snapshot = query.get().get(); + AggregateQuerySnapshot snapshot = verifyPipelineReturnsSameResult(query); assertThat(snapshot.get(sum("num"))).isEqualTo(12); } @@ -910,7 +951,7 @@ public void aggregateWithNoFilterNoOrderByNoCursor() throws Exception { public void aggregateWithEqualityFilterNoOrderByNoCursor() throws Exception { CollectionReference collection = addTwoDocsForCursorTesting(); AggregateQuery query = collection.whereEqualTo("num", 5).aggregate(sum("num")); - AggregateQuerySnapshot snapshot = query.get().get(); + AggregateQuerySnapshot snapshot = verifyPipelineReturnsSameResult(query); assertThat(snapshot.get(sum("num"))).isEqualTo(5); } @@ -918,7 +959,7 @@ public void aggregateWithEqualityFilterNoOrderByNoCursor() throws Exception { public void aggregateWithInequalityFilterNoOrderByNoCursor() throws Exception { CollectionReference collection = addTwoDocsForCursorTesting(); AggregateQuery query = collection.whereGreaterThan("num", 5).aggregate(sum("num")); - AggregateQuerySnapshot snapshot = query.get().get(); + AggregateQuerySnapshot snapshot = verifyPipelineReturnsSameResult(query); assertThat(snapshot.get(sum("num"))).isEqualTo(7); } @@ -926,7 +967,7 @@ public void aggregateWithInequalityFilterNoOrderByNoCursor() throws Exception { public void aggregateWithNoFilterExplicitOrderByNoCursor() throws Exception { CollectionReference collection = addTwoDocsForCursorTesting(); AggregateQuery query = collection.orderBy("num").aggregate(sum("num")); - AggregateQuerySnapshot snapshot = query.get().get(); + AggregateQuerySnapshot snapshot = verifyPipelineReturnsSameResult(query); assertThat(snapshot.get(sum("num"))).isEqualTo(12); } @@ -934,7 +975,7 @@ public void aggregateWithNoFilterExplicitOrderByNoCursor() throws Exception { public void aggregateWithEqualityFilterExplicitOrderByNoCursor() throws Exception { CollectionReference collection = addTwoDocsForCursorTesting(); AggregateQuery query = collection.whereEqualTo("num", 5).orderBy("num").aggregate(sum("num")); - AggregateQuerySnapshot snapshot = query.get().get(); + AggregateQuerySnapshot snapshot = verifyPipelineReturnsSameResult(query); assertThat(snapshot.get(sum("num"))).isEqualTo(5); } @@ -943,7 +984,7 @@ public void aggregateWithInequalityFilterExplicitOrderByNoCursor() throws Except CollectionReference collection = addTwoDocsForCursorTesting(); AggregateQuery query = collection.whereGreaterThan("num", 5).orderBy("num").aggregate(sum("num")); - AggregateQuerySnapshot snapshot = query.get().get(); + AggregateQuerySnapshot snapshot = verifyPipelineReturnsSameResult(query); assertThat(snapshot.get(sum("num"))).isEqualTo(7); } @@ -951,7 +992,7 @@ public void aggregateWithInequalityFilterExplicitOrderByNoCursor() throws Except public void aggregateNoFilterExplicitOrderByFieldValueCursor() throws Exception { CollectionReference collection = addTwoDocsForCursorTesting(); AggregateQuery query = collection.orderBy("num").startAfter(5).aggregate(sum("num")); - AggregateQuerySnapshot snapshot = query.get().get(); + AggregateQuerySnapshot snapshot = verifyPipelineReturnsSameResult(query); assertThat(snapshot.get(sum("num"))).isEqualTo(7); } @@ -965,7 +1006,7 @@ public void aggregateNoFilterExplicitOrderByDocumentReferenceCursor() throws Exc .orderBy(FieldPath.documentId()) .startAfter(collection.document("a")) .aggregate(sum("num")); - AggregateQuerySnapshot snapshot = query.get().get(); + AggregateQuerySnapshot snapshot = verifyPipelineReturnsSameResult(query); assertThat(snapshot.get(sum("num"))).isEqualTo(7); } @@ -975,7 +1016,7 @@ public void aggregateNoFilterExplicitOrderByDocumentReferenceCursor() throws Exc public void aggregateNoFilterNoOrderByDocumentReferenceCursor() throws Exception { CollectionReference collection = addTwoDocsForCursorTesting(); AggregateQuery query = collection.startAfter(collection.document("a")).aggregate(sum("num")); - AggregateQuerySnapshot snapshot = query.get().get(); + AggregateQuerySnapshot snapshot = verifyPipelineReturnsSameResult(query); assertThat(snapshot.get(sum("num"))).isEqualTo(7); } @@ -986,7 +1027,7 @@ public void aggregateNoFilterExplicitOrderByDocumentSnapshotCursor() throws Exce CollectionReference collection = addTwoDocsForCursorTesting(); DocumentSnapshot docSnapshot = collection.document("a").get().get(); AggregateQuery query = collection.orderBy("foo").startAfter(docSnapshot).aggregate(sum("num")); - AggregateQuerySnapshot snapshot = query.get().get(); + AggregateQuerySnapshot snapshot = verifyPipelineReturnsSameResult(query); assertThat(snapshot.get(sum("num"))).isEqualTo(7); } @@ -996,7 +1037,7 @@ public void aggregateNoFilterExplicitOrderByDocumentSnapshotCursor2() throws Exc CollectionReference collection = addTwoDocsForCursorTesting(); DocumentSnapshot docSnapshot = collection.document("a").get().get(); AggregateQuery query = collection.orderBy("num").startAfter(docSnapshot).aggregate(sum("num")); - AggregateQuerySnapshot snapshot = query.get().get(); + AggregateQuerySnapshot snapshot = verifyPipelineReturnsSameResult(query); assertThat(snapshot.get(sum("num"))).isEqualTo(7); } @@ -1005,7 +1046,7 @@ public void aggregateEqualityFilterExplicitOrderByFieldValueCursor() throws Exce CollectionReference collection = addTwoDocsForCursorTesting(); AggregateQuery query = collection.whereEqualTo("num", 5).orderBy("num").startAt(5).aggregate(sum("num")); - AggregateQuerySnapshot snapshot = query.get().get(); + AggregateQuerySnapshot snapshot = verifyPipelineReturnsSameResult(query); assertThat(snapshot.get(sum("num"))).isEqualTo(5); } @@ -1014,7 +1055,7 @@ public void aggregateInequalityFilterExplicitOrderByFieldValueCursor() throws Ex CollectionReference collection = addTwoDocsForCursorTesting(); AggregateQuery query = collection.whereGreaterThan("num", 5).orderBy("num").startAt(6).aggregate(sum("num")); - AggregateQuerySnapshot snapshot = query.get().get(); + AggregateQuerySnapshot snapshot = verifyPipelineReturnsSameResult(query); assertThat(snapshot.get(sum("num"))).isEqualTo(7); } @@ -1029,7 +1070,7 @@ public void aggregateEqualityFilterExplicitOrderByDocumentReferenceCursor() thro .orderBy(FieldPath.documentId()) .startAfter(collection.document("a")) .aggregate(sum("num")); - AggregateQuerySnapshot snapshot = query.get().get(); + AggregateQuerySnapshot snapshot = verifyPipelineReturnsSameResult(query); assertThat(snapshot.get(sum("num"))).isEqualTo(7); } @@ -1044,7 +1085,7 @@ public void aggregateInequalityFilterExplicitOrderByDocumentReferenceCursor() th .orderBy(FieldPath.documentId()) .startAfter(5, collection.document("a")) .aggregate(sum("num")); - AggregateQuerySnapshot snapshot = query.get().get(); + AggregateQuerySnapshot snapshot = verifyPipelineReturnsSameResult(query); assertThat(snapshot.get(sum("num"))).isEqualTo(7); } @@ -1056,7 +1097,7 @@ public void aggregateEqualityFilterNoOrderByDocumentSnapshotReference() throws E DocumentSnapshot docSnapshot = collection.document("a").get().get(); AggregateQuery query = collection.whereEqualTo("num", 7).startAfter(docSnapshot).aggregate(sum("num")); - AggregateQuerySnapshot snapshot = query.get().get(); + AggregateQuerySnapshot snapshot = verifyPipelineReturnsSameResult(query); assertThat(snapshot.get(sum("num"))).isEqualTo(7); } @@ -1067,7 +1108,7 @@ public void aggregateInequalityFilterNoOrderByDocumentSnapshotReference() throws DocumentSnapshot docSnapshot = collection.document("a").get().get(); AggregateQuery query = collection.whereGreaterThan("num", 0).startAfter(docSnapshot).aggregate(sum("num")); - AggregateQuerySnapshot snapshot = query.get().get(); + AggregateQuerySnapshot snapshot = verifyPipelineReturnsSameResult(query); assertThat(snapshot.get(sum("num"))).isEqualTo(7); } @@ -1079,7 +1120,7 @@ public void aggregateInequalityFilterNoOrderByDocumentSnapshotReference2() throw DocumentSnapshot docSnapshot = collection.document("a").get().get(); AggregateQuery query = collection.whereGreaterThan("foo", 0).startAfter(docSnapshot).aggregate(sum("num")); - AggregateQuerySnapshot snapshot = query.get().get(); + AggregateQuerySnapshot snapshot = verifyPipelineReturnsSameResult(query); assertThat(snapshot.get(sum("num"))).isEqualTo(7); } From 478c46c28a91e9e9a9f2868e3715bff89862be26 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Tue, 16 Jul 2024 15:40:42 -0400 Subject: [PATCH 50/65] Function and stage renames --- .../cloud/firestore/AggregateQuery.java | 4 +- .../com/google/cloud/firestore/Firestore.java | 2 + .../google/cloud/firestore/FirestoreImpl.java | 8 ++ .../com/google/cloud/firestore/Pipeline.java | 37 +---- .../cloud/firestore/PipelineSource.java | 35 +++++ .../google/cloud/firestore/PipelineUtils.java | 12 +- .../com/google/cloud/firestore/Query.java | 15 +- .../expressions/{Equal.java => Eq.java} | 4 +- .../firestore/pipeline/expressions/Expr.java | 52 +++---- .../pipeline/expressions/Function.java | 104 +++++++------- .../expressions/{GreaterThan.java => Gt.java} | 4 +- .../{GreaterThanOrEqual.java => Gte.java} | 4 +- .../expressions/{LessThan.java => Lt.java} | 4 +- .../{LessThanOrEqual.java => Lte.java} | 4 +- .../expressions/{NotEqual.java => Neq.java} | 4 +- .../pipeline/expressions/RegexMatch.java | 11 ++ .../firestore/pipeline/stages/StageUtils.java | 8 +- .../stages/{Filter.java => Where.java} | 4 +- .../cloud/firestore/it/ITPipelineTest.java | 132 ++++++++++-------- .../firestore/it/ITQueryAggregationsTest.java | 2 +- .../cloud/firestore/it/ITQueryTest.java | 6 +- 21 files changed, 260 insertions(+), 196 deletions(-) create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java rename google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/{Equal.java => Eq.java} (59%) rename google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/{GreaterThan.java => Gt.java} (57%) rename google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/{GreaterThanOrEqual.java => Gte.java} (54%) rename google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/{LessThan.java => Lt.java} (58%) rename google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/{LessThanOrEqual.java => Lte.java} (55%) rename google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/{NotEqual.java => Neq.java} (58%) create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/RegexMatch.java rename google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/{Filter.java => Where.java} (83%) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java index f07db983b..7a0bff3db 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java @@ -67,9 +67,9 @@ public Query getQuery() { } @Nonnull - public Pipeline toPipeline() { + public Pipeline pipeline() { return getQuery() - .toPipeline() + .pipeline() .aggregate( this.aggregateFieldList.stream() .map(PipelineUtils::toPipelineAggregatorTarget) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java index 5bbb1164a..7f5bc54b5 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java @@ -66,6 +66,8 @@ public interface Firestore extends Service, AutoCloseable { */ CollectionGroup collectionGroup(@Nonnull String collectionId); + PipelineSource pipeline(); + /** * Executes the given updateFunction and then attempts to commit the changes applied within the * transaction. If any document read within the transaction has changed, the updateFunction will diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java index 03e3cf891..279347d42 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java @@ -18,6 +18,7 @@ import com.google.api.core.ApiClock; import com.google.api.core.ApiFuture; +import com.google.api.core.BetaApi; import com.google.api.core.NanoClock; import com.google.api.core.SettableApiFuture; import com.google.api.gax.rpc.ApiStreamObserver; @@ -385,6 +386,13 @@ public CollectionGroup collectionGroup(@Nonnull final String collectionId) { return new CollectionGroup(this, collectionId); } + @Nonnull + @Override + @BetaApi + public PipelineSource pipeline() { + return new PipelineSource(); + } + @Nonnull @Override public ApiFuture runTransaction(@Nonnull final Function updateFunction) { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java index a8df73985..7eb6075c8 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java @@ -29,7 +29,7 @@ import com.google.cloud.firestore.pipeline.stages.Sort; import com.google.cloud.firestore.pipeline.stages.Stage; import com.google.cloud.firestore.pipeline.stages.StageUtils; -import com.google.common.base.Preconditions; +import com.google.cloud.firestore.pipeline.stages.Where; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; @@ -88,42 +88,22 @@ private Pipeline(List stages) { this.stages = ImmutableList.copyOf(stages); } - private Pipeline(Collection collection) { + Pipeline(Collection collection) { this(Lists.newArrayList(collection)); } - private Pipeline(CollectionGroup group) { + Pipeline(CollectionGroup group) { this(Lists.newArrayList(group)); } - private Pipeline(Database db) { + Pipeline(Database db) { this(Lists.newArrayList(db)); } - private Pipeline(Documents docs) { + Pipeline(Documents docs) { this(Lists.newArrayList(docs)); } - public static Pipeline fromCollection(String collectionName) { - return new Pipeline(new Collection(collectionName)); - } - - public static Pipeline fromCollectionGroup(String collectionId) { - Preconditions.checkArgument( - !collectionId.contains("/"), - "Invalid collectionId '%s'. Collection IDs must not contain '/'.", - collectionId); - return new Pipeline(new CollectionGroup(collectionId)); - } - - public static Pipeline fromDatabase() { - return new Pipeline(new Database()); - } - - public static Pipeline fromDocuments(DocumentReference... docs) { - return new Pipeline(Documents.of(docs)); - } - private Map projectablesToMap(Selectable... selectables) { Map projMap = new HashMap<>(); for (Selectable proj : selectables) { @@ -178,12 +158,9 @@ public Pipeline select(String... fields) { .build()); } - public Pipeline filter(FilterCondition condition) { + public Pipeline where(FilterCondition condition) { return new Pipeline( - ImmutableList.builder() - .addAll(stages) - .add(new com.google.cloud.firestore.pipeline.stages.Filter(condition)) - .build()); + ImmutableList.builder().addAll(stages).add(new Where(condition)).build()); } public Pipeline offset(int offset) { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java new file mode 100644 index 000000000..add5067b9 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java @@ -0,0 +1,35 @@ +package com.google.cloud.firestore; + +import com.google.cloud.firestore.pipeline.stages.Collection; +import com.google.cloud.firestore.pipeline.stages.CollectionGroup; +import com.google.cloud.firestore.pipeline.stages.Database; +import com.google.cloud.firestore.pipeline.stages.Documents; +import com.google.common.base.Preconditions; +import javax.annotation.Nonnull; + +public class PipelineSource { + + @Nonnull + public Pipeline collection(@Nonnull String path) { + return new Pipeline(new Collection(path)); + } + + @Nonnull + public Pipeline collectionGroup(@Nonnull String collectionId) { + Preconditions.checkArgument( + !collectionId.contains("/"), + "Invalid collectionId '%s'. Collection IDs must not contain '/'.", + collectionId); + return new Pipeline(new CollectionGroup(collectionId)); + } + + @Nonnull + public Pipeline database() { + return new Pipeline(new Database()); + } + + @Nonnull + public Pipeline documents(DocumentReference... docs) { + return new Pipeline(Documents.of(docs)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java index 0987f34e4..f5b9cce73 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java @@ -38,17 +38,17 @@ static FilterCondition toPipelineFilterCondition(FilterInternal f) { Value value = comparisonFilter.value; switch (comparisonFilter.operator) { case LESS_THAN: - return Field.of(fieldPath).lessThan(value); + return Field.of(fieldPath).lt(value); case LESS_THAN_OR_EQUAL: - return Field.of(fieldPath).lessThanOrEqual(value); + return Field.of(fieldPath).lte(value); case GREATER_THAN: - return Field.of(fieldPath).greaterThan(value); + return Field.of(fieldPath).gt(value); case GREATER_THAN_OR_EQUAL: - return Field.of(fieldPath).greaterThanOrEqual(value); + return Field.of(fieldPath).gte(value); case EQUAL: - return Field.of(fieldPath).equal(value); + return Field.of(fieldPath).eq(value); case NOT_EQUAL: - return not(Field.of(fieldPath).equal(value)); + return not(Field.of(fieldPath).eq(value)); case ARRAY_CONTAINS: return Field.of(fieldPath).arrayContains(value); case IN: diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index 554589359..541a4d903 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -2122,17 +2122,18 @@ public AggregateQuery aggregate( } @Nonnull - public Pipeline toPipeline() { + public Pipeline pipeline() { // From Pipeline ppl = this.options.getAllDescendants() - ? Pipeline.fromCollectionGroup(this.options.getCollectionId()) - : Pipeline.fromCollection( - this.options.getParentPath().append(this.options.getCollectionId()).getPath()); + ? new PipelineSource().collectionGroup(this.options.getCollectionId()) + : new PipelineSource() + .collection( + this.options.getParentPath().append(this.options.getCollectionId()).getPath()); // Filters for (FilterInternal f : this.options.getFilters()) { - ppl = ppl.filter(toPipelineFilterCondition(f)); + ppl = ppl.where(toPipelineFilterCondition(f)); } // Projections @@ -2167,10 +2168,10 @@ public Pipeline toPipeline() { .collect(Collectors.toList()); if (exists.size() > 1) { ppl = - ppl.filter( + ppl.where( and(exists.get(0), exists.subList(1, exists.size()).toArray(new Exists[] {}))); } else if (exists.size() == 1) { - ppl = ppl.filter(exists.get(0)); + ppl = ppl.where(exists.get(0)); } ppl = ppl.sort(orders, Density.REQUIRED, Truncation.UNSPECIFIED); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Equal.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Eq.java similarity index 59% rename from google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Equal.java rename to google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Eq.java index e9820e9f9..48db0bd95 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Equal.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Eq.java @@ -2,8 +2,8 @@ import com.google.common.collect.Lists; -public final class Equal extends Function implements FilterCondition { - Equal(Expr left, Expr right) { +public final class Eq extends Function implements FilterCondition { + Eq(Expr left, Expr right) { super("eq", Lists.newArrayList(left, right)); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java index 5a69b821d..43475069e 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java @@ -37,52 +37,52 @@ default Divide divide(Object other) { return new Divide(this, Constant.of(other)); } - default Equal equal(Expr expr) { - return new Equal(this, expr); + default Eq eq(Expr expr) { + return new Eq(this, expr); } - default Equal equal(Object other) { - return new Equal(this, Constant.of(other)); + default Eq eq(Object other) { + return new Eq(this, Constant.of(other)); } - default NotEqual notEqual(Expr other) { - return new NotEqual(this, other); + default Neq neq(Expr other) { + return new Neq(this, other); } - default NotEqual notEqual(Object other) { - return new NotEqual(this, Constant.of(other)); + default Neq neq(Object other) { + return new Neq(this, Constant.of(other)); } - default GreaterThan greaterThan(Expr other) { - return new GreaterThan(this, other); + default Gt gt(Expr other) { + return new Gt(this, other); } - default GreaterThan greaterThan(Object other) { - return new GreaterThan(this, Constant.of(other)); + default Gt gt(Object other) { + return new Gt(this, Constant.of(other)); } - default GreaterThanOrEqual greaterThanOrEqual(Expr other) { - return new GreaterThanOrEqual(this, other); + default Gte gte(Expr other) { + return new Gte(this, other); } - default GreaterThanOrEqual greaterThanOrEqual(Object other) { - return new GreaterThanOrEqual(this, Constant.of(other)); + default Gte gte(Object other) { + return new Gte(this, Constant.of(other)); } - default LessThan lessThan(Expr other) { - return new LessThan(this, other); + default Lt lt(Expr other) { + return new Lt(this, other); } - default LessThan lessThan(Object other) { - return new LessThan(this, Constant.of(other)); + default Lt lt(Object other) { + return new Lt(this, Constant.of(other)); } - default LessThanOrEqual lessThanOrEqual(Expr other) { - return new LessThanOrEqual(this, other); + default Lte lte(Expr other) { + return new Lte(this, other); } - default LessThanOrEqual lessThanOrEqual(Object other) { - return new LessThanOrEqual(this, Constant.of(other)); + default Lte lte(Object other) { + return new Lte(this, Constant.of(other)); } default In inAny(Object... other) { @@ -184,6 +184,10 @@ default RegexContains regexContains(String regex) { return new RegexContains(this, Constant.of(regex)); } + default RegexMatch regexMatches(String regex) { + return new RegexMatch(this, Constant.of(regex)); + } + default StrConcat strConcat(List elements) { return new StrConcat(this, elements); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java index bba0c11a0..f0bd8d658 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java @@ -109,100 +109,100 @@ public static Divide divide(String left, Object right) { return new Divide(Field.of(left), Constant.of(right)); } - public static Equal equal(Expr left, Expr right) { - return new Equal(left, right); + public static Eq eq(Expr left, Expr right) { + return new Eq(left, right); } - public static Equal equal(Expr left, Object right) { - return new Equal(left, Constant.of(right)); + public static Eq eq(Expr left, Object right) { + return new Eq(left, Constant.of(right)); } - public static Equal equal(String left, Expr right) { - return new Equal(Field.of(left), right); + public static Eq eq(String left, Expr right) { + return new Eq(Field.of(left), right); } - public static Equal equal(String left, Object right) { - return new Equal(Field.of(left), Constant.of(right)); + public static Eq eq(String left, Object right) { + return new Eq(Field.of(left), Constant.of(right)); } - public static NotEqual notEqual(Expr left, Expr right) { - return new NotEqual(left, right); + public static Neq neq(Expr left, Expr right) { + return new Neq(left, right); } - public static NotEqual notEqual(Expr left, Object right) { - return new NotEqual(left, Constant.of(right)); + public static Neq neq(Expr left, Object right) { + return new Neq(left, Constant.of(right)); } - public static NotEqual notEqual(String left, Expr right) { - return new NotEqual(Field.of(left), right); + public static Neq neq(String left, Expr right) { + return new Neq(Field.of(left), right); } - public static NotEqual notEqual(String left, Object right) { - return new NotEqual(Field.of(left), Constant.of(right)); + public static Neq neq(String left, Object right) { + return new Neq(Field.of(left), Constant.of(right)); } - public static GreaterThan greaterThan(Expr left, Expr right) { - return new GreaterThan(left, right); + public static Gt gt(Expr left, Expr right) { + return new Gt(left, right); } - public static GreaterThan greaterThan(Expr left, Object right) { - return new GreaterThan(left, Constant.of(right)); + public static Gt gt(Expr left, Object right) { + return new Gt(left, Constant.of(right)); } - public static GreaterThan greaterThan(String left, Expr right) { - return new GreaterThan(Field.of(left), right); + public static Gt gt(String left, Expr right) { + return new Gt(Field.of(left), right); } - public static GreaterThan greaterThan(String left, Object right) { - return new GreaterThan(Field.of(left), Constant.of(right)); + public static Gt gt(String left, Object right) { + return new Gt(Field.of(left), Constant.of(right)); } - public static GreaterThanOrEqual greaterThanOrEqual(Expr left, Expr right) { - return new GreaterThanOrEqual(left, right); + public static Gte gte(Expr left, Expr right) { + return new Gte(left, right); } - public static GreaterThanOrEqual greaterThanOrEqual(Expr left, Object right) { - return new GreaterThanOrEqual(left, Constant.of(right)); + public static Gte gte(Expr left, Object right) { + return new Gte(left, Constant.of(right)); } - public static GreaterThanOrEqual greaterThanOrEqual(String left, Expr right) { - return new GreaterThanOrEqual(Field.of(left), right); + public static Gte gte(String left, Expr right) { + return new Gte(Field.of(left), right); } - public static GreaterThanOrEqual greaterThanOrEqual(String left, Object right) { - return new GreaterThanOrEqual(Field.of(left), Constant.of(right)); + public static Gte gte(String left, Object right) { + return new Gte(Field.of(left), Constant.of(right)); } - public static LessThan lessThan(Expr left, Expr right) { - return new LessThan(left, right); + public static Lt lt(Expr left, Expr right) { + return new Lt(left, right); } - public static LessThan lessThan(Expr left, Object right) { - return new LessThan(left, Constant.of(right)); + public static Lt lt(Expr left, Object right) { + return new Lt(left, Constant.of(right)); } - public static LessThan lessThan(String left, Expr right) { - return new LessThan(Field.of(left), right); + public static Lt lt(String left, Expr right) { + return new Lt(Field.of(left), right); } - public static LessThan lessThan(String left, Object right) { - return new LessThan(Field.of(left), Constant.of(right)); + public static Lt lt(String left, Object right) { + return new Lt(Field.of(left), Constant.of(right)); } - public static LessThanOrEqual lessThanOrEqual(Expr left, Expr right) { - return new LessThanOrEqual(left, right); + public static Lte lte(Expr left, Expr right) { + return new Lte(left, right); } - public static LessThanOrEqual lessThanOrEqual(Expr left, Object right) { - return new LessThanOrEqual(left, Constant.of(right)); + public static Lte lte(Expr left, Object right) { + return new Lte(left, Constant.of(right)); } - public static LessThanOrEqual lessThanOrEqual(String left, Expr right) { - return new LessThanOrEqual(Field.of(left), right); + public static Lte lte(String left, Expr right) { + return new Lte(Field.of(left), right); } - public static LessThanOrEqual lessThanOrEqual(String left, Object right) { - return new LessThanOrEqual(Field.of(left), Constant.of(right)); + public static Lte lte(String left, Object right) { + return new Lte(Field.of(left), Constant.of(right)); } public static Exists exists(String field) { @@ -389,6 +389,14 @@ public static RegexContains regexContains(String field, String pattern) { return new RegexContains(Field.of(field), Constant.of(pattern)); } + public static RegexMatch regexMatch(Expr expr, String pattern) { + return new RegexMatch(expr, Constant.of(pattern)); + } + + public static RegexMatch regexMatch(String field, String pattern) { + return new RegexMatch(Field.of(field), Constant.of(pattern)); + } + public static StrConcat strConcat(Expr expr, Expr... elements) { return new StrConcat(expr, Arrays.asList(elements)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/GreaterThan.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Gt.java similarity index 57% rename from google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/GreaterThan.java rename to google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Gt.java index 97d846687..6e81c4bb5 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/GreaterThan.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Gt.java @@ -2,8 +2,8 @@ import com.google.common.collect.Lists; -public final class GreaterThan extends Function implements FilterCondition { - GreaterThan(Expr left, Expr right) { +public final class Gt extends Function implements FilterCondition { + Gt(Expr left, Expr right) { super("gt", Lists.newArrayList(left, right)); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/GreaterThanOrEqual.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Gte.java similarity index 54% rename from google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/GreaterThanOrEqual.java rename to google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Gte.java index 67e031d8f..bca7689ee 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/GreaterThanOrEqual.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Gte.java @@ -2,8 +2,8 @@ import com.google.common.collect.Lists; -public final class GreaterThanOrEqual extends Function implements FilterCondition { - GreaterThanOrEqual(Expr left, Expr right) { +public final class Gte extends Function implements FilterCondition { + Gte(Expr left, Expr right) { super("gte", Lists.newArrayList(left, right)); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/LessThan.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Lt.java similarity index 58% rename from google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/LessThan.java rename to google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Lt.java index 71b541988..86d2e4a34 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/LessThan.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Lt.java @@ -2,8 +2,8 @@ import com.google.common.collect.Lists; -public final class LessThan extends Function implements FilterCondition { - LessThan(Expr left, Expr right) { +public final class Lt extends Function implements FilterCondition { + Lt(Expr left, Expr right) { super("lt", Lists.newArrayList(left, right)); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/LessThanOrEqual.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Lte.java similarity index 55% rename from google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/LessThanOrEqual.java rename to google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Lte.java index 3b7f76330..a0c8d1ae7 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/LessThanOrEqual.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Lte.java @@ -2,8 +2,8 @@ import com.google.common.collect.Lists; -public final class LessThanOrEqual extends Function implements FilterCondition { - LessThanOrEqual(Expr left, Expr right) { +public final class Lte extends Function implements FilterCondition { + Lte(Expr left, Expr right) { super("lte", Lists.newArrayList(left, right)); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/NotEqual.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Neq.java similarity index 58% rename from google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/NotEqual.java rename to google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Neq.java index 6a0967899..86a91a058 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/NotEqual.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Neq.java @@ -2,8 +2,8 @@ import com.google.common.collect.Lists; -public final class NotEqual extends Function implements FilterCondition { - NotEqual(Expr left, Expr right) { +public final class Neq extends Function implements FilterCondition { + Neq(Expr left, Expr right) { super("neq", Lists.newArrayList(left, right)); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/RegexMatch.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/RegexMatch.java new file mode 100644 index 000000000..b01476644 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/RegexMatch.java @@ -0,0 +1,11 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.api.core.InternalApi; +import com.google.common.collect.Lists; + +public final class RegexMatch extends Function implements FilterCondition { + @InternalApi + RegexMatch(Expr expr, Expr regex) { + super("regex_match", Lists.newArrayList(expr, regex)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java index ba4493d57..41e85b516 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java @@ -52,11 +52,11 @@ public static com.google.firestore.v1.Pipeline.Stage toStageProto(Stage stage) { .setName(addFieldsStage.getName()) .addArgs(encodeValue(addFieldsStage.getFields())) .build(); - } else if (stage instanceof Filter) { - Filter filterStage = (Filter) stage; // Use wildcard for generic type + } else if (stage instanceof Where) { + Where whereStage = (Where) stage; // Use wildcard for generic type return com.google.firestore.v1.Pipeline.Stage.newBuilder() - .setName(filterStage.getName()) - .addArgs(encodeValue(filterStage.getCondition())) + .setName(whereStage.getName()) + .addArgs(encodeValue(whereStage.getCondition())) .build(); } else if (stage instanceof Sort) { Sort sortStage = (Sort) stage; diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Filter.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Where.java similarity index 83% rename from google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Filter.java rename to google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Where.java index 9b6d6c883..7befd7a60 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Filter.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Where.java @@ -4,13 +4,13 @@ import com.google.cloud.firestore.pipeline.expressions.FilterCondition; @InternalApi -public final class Filter implements Stage { +public final class Where implements Stage { private static final String name = "filter"; private final FilterCondition condition; @InternalApi - public Filter(FilterCondition condition) { + public Where(FilterCondition condition) { this.condition = condition; } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index e05788cb6..6f3494895 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -30,13 +30,13 @@ import static com.google.cloud.firestore.pipeline.expressions.Function.cosineDistance; import static com.google.cloud.firestore.pipeline.expressions.Function.countAll; import static com.google.cloud.firestore.pipeline.expressions.Function.dotProductDistance; -import static com.google.cloud.firestore.pipeline.expressions.Function.equal; +import static com.google.cloud.firestore.pipeline.expressions.Function.eq; import static com.google.cloud.firestore.pipeline.expressions.Function.euclideanDistance; -import static com.google.cloud.firestore.pipeline.expressions.Function.greaterThan; +import static com.google.cloud.firestore.pipeline.expressions.Function.gt; import static com.google.cloud.firestore.pipeline.expressions.Function.isNull; -import static com.google.cloud.firestore.pipeline.expressions.Function.lessThan; +import static com.google.cloud.firestore.pipeline.expressions.Function.lt; +import static com.google.cloud.firestore.pipeline.expressions.Function.neq; import static com.google.cloud.firestore.pipeline.expressions.Function.not; -import static com.google.cloud.firestore.pipeline.expressions.Function.notEqual; import static com.google.cloud.firestore.pipeline.expressions.Function.or; import static com.google.cloud.firestore.pipeline.expressions.Function.parent; import static com.google.cloud.firestore.pipeline.expressions.Function.strConcat; @@ -48,6 +48,7 @@ import com.google.cloud.firestore.PipelineResult; import com.google.cloud.firestore.pipeline.expressions.Constant; import com.google.cloud.firestore.pipeline.expressions.Field; +import com.google.cloud.firestore.pipeline.expressions.Function; import com.google.common.collect.Lists; import java.util.List; import java.util.Map; @@ -251,13 +252,18 @@ public void setup() throws Exception { @Test public void fromCollectionThenAggregate() throws Exception { List results = - collection.toPipeline().aggregate(countAll().toField("count")).execute(firestore).get(); + firestore + .pipeline() + .collection(collection.getPath()) + .aggregate(countAll().toField("count")) + .execute(firestore) + .get(); assertThat(data(results)).isEqualTo(Lists.newArrayList(map("count", 10L))); results = collection - .toPipeline() - .filter(equal("genre", "Science Fiction")) + .pipeline() + .where(eq("genre", "Science Fiction")) .aggregate( countAll().toField("count"), avg("rating").toField("avg_rating"), @@ -272,7 +278,7 @@ public void fromCollectionThenAggregate() throws Exception { public void testMinMax() throws Exception { List results = collection - .toPipeline() + .pipeline() .aggregate( countAll().toField("count"), Field.of("rating").max().toField("max_rating"), @@ -292,7 +298,7 @@ public void testMinMax() throws Exception { public void selectSpecificFields() throws Exception { List results = collection - .toPipeline() + .pipeline() .select("title", "author") .sort(Field.of("author").ascending()) .execute(firestore) @@ -314,11 +320,11 @@ public void selectSpecificFields() throws Exception { } @Test - public void filterByMultipleConditions() throws Exception { + public void whereByMultipleConditions() throws Exception { List results = collection - .toPipeline() - .filter(and(greaterThan("rating", 4.5), equal("genre", "Science Fiction"))) + .pipeline() + .where(and(gt("rating", 4.5), eq("genre", "Science Fiction"))) .execute(firestore) .get(); @@ -329,11 +335,11 @@ public void filterByMultipleConditions() throws Exception { } @Test - public void filterByOrCondition() throws Exception { + public void whereByOrCondition() throws Exception { List results = collection - .toPipeline() - .filter(or(equal("genre", "Romance"), equal("genre", "Dystopian"))) + .pipeline() + .where(or(eq("genre", "Romance"), eq("genre", "Dystopian"))) .select("title") .execute(firestore) .get(); @@ -350,7 +356,7 @@ public void filterByOrCondition() throws Exception { public void testPipelineWithOffsetAndLimit() throws Exception { List results = collection - .toPipeline() + .pipeline() .sort(Field.of("author").ascending()) .offset(5) .limit(3) @@ -369,7 +375,7 @@ public void testPipelineWithOffsetAndLimit() throws Exception { @Test public void testArrayContains() throws Exception { List results = - collection.toPipeline().filter(arrayContains("tags", "comedy")).execute(firestore).get(); + collection.pipeline().where(arrayContains("tags", "comedy")).execute(firestore).get(); assertThat(data(results)) // The Hitchhiker's Guide to the Galaxy .isEqualTo(Lists.newArrayList(collection.document("book1").get().get().getData())); @@ -379,8 +385,8 @@ public void testArrayContains() throws Exception { public void testArrayContainsAny() throws Exception { List results = collection - .toPipeline() - .filter(arrayContainsAny("tags", "comedy", "classic")) + .pipeline() + .where(arrayContainsAny("tags", "comedy", "classic")) .select("title") .execute(firestore) .get(); @@ -396,8 +402,8 @@ public void testArrayContainsAny() throws Exception { public void testArrayContainsAll() throws Exception { List results = collection - .toPipeline() - .filter(arrayContainsAll("tags", "adventure", "magic")) + .pipeline() + .where(arrayContainsAll("tags", "adventure", "magic")) .execute(firestore) .get(); @@ -408,9 +414,9 @@ public void testArrayContainsAll() throws Exception { public void testArrayLength() throws Exception { List results = collection - .toPipeline() + .pipeline() .select(Field.of("tags").arrayLength().asAlias("tagsCount")) - .filter(equal("tagsCount", 3)) + .where(eq("tagsCount", 3)) .execute(firestore) .get(); @@ -422,7 +428,7 @@ public void testArrayLength() throws Exception { public void testArrayConcat() throws Exception { List results = collection - .toPipeline() + .pipeline() .select(Field.of("tags").arrayConcat("newTag1", "newTag2").asAlias("modifiedTags")) .limit(1) .execute(firestore) @@ -440,9 +446,10 @@ public void testArrayConcat() throws Exception { public void testArrayFilter() throws Exception { List results = collection - .toPipeline() + .pipeline() .select( - arrayFilter(Field.of("tags"), equal(arrayElement(), "")).asAlias("filteredTags")) + arrayFilter(Field.of("tags"), Function.eq(arrayElement(), "")) + .asAlias("filteredTags")) .limit(1) .execute(firestore) .get(); @@ -457,7 +464,7 @@ public void testArrayFilter() throws Exception { public void testArrayTransform() throws Exception { List results = collection - .toPipeline() + .pipeline() .select( arrayTransform(Field.of("tags"), strConcat(arrayElement(), "transformed")) .asAlias("transformedTags")) @@ -478,7 +485,7 @@ public void testArrayTransform() throws Exception { public void testStrConcat() throws Exception { List results = collection - .toPipeline() + .pipeline() .select(strConcat(Field.of("author"), " - ", Field.of("title")).asAlias("bookInfo")) .limit(1) .execute(firestore) @@ -494,9 +501,9 @@ public void testStrConcat() throws Exception { public void testLength() throws Exception { List results = collection - .toPipeline() + .pipeline() .select(Field.of("title").length().asAlias("titleLength"), Field.of("title")) - .filter(greaterThan("titleLength", 20)) + .where(gt("titleLength", 20)) .execute(firestore) .get(); @@ -508,7 +515,7 @@ public void testLength() throws Exception { public void testToLowercase() throws Exception { List results = collection - .toPipeline() + .pipeline() .select(Field.of("title").toLowercase().asAlias("lowercaseTitle")) .limit(1) .execute(firestore) @@ -523,7 +530,7 @@ public void testToLowercase() throws Exception { public void testToUppercase() throws Exception { List results = collection - .toPipeline() + .pipeline() .select(Field.of("author").toUppercase().asAlias("uppercaseAuthor")) .limit(1) .execute(firestore) @@ -537,7 +544,7 @@ public void testToUppercase() throws Exception { public void testTrim() throws Exception { List results = collection - .toPipeline() + .pipeline() .addFields( strConcat(Constant.of(" "), Field.of("title"), Constant.of(" ")) .asAlias("spacedTitle")) @@ -558,8 +565,8 @@ public void testTrim() throws Exception { public void testLike() throws Exception { List results = collection - .toPipeline() - .filter(Field.of("title").like("%Guide%")) + .pipeline() + .where(Field.of("title").like("%Guide%")) .select("title") .execute(firestore) .get(); @@ -573,8 +580,21 @@ public void testRegexContains() throws Exception { // Find titles that contain either "the" or "of" (case-insensitive) List results = collection - .toPipeline() - .filter(Field.of("title").regexContains(".*(?i)(the|of).*")) + .pipeline() + .where(Field.of("title").regexContains("(?i)(the|of)")) + .execute(firestore) + .get(); + + assertThat(data(results)).hasSize(5); + } + + @Test + public void testRegexMatches() throws Exception { + // Find titles that contain either "the" or "of" (case-insensitive) + List results = + collection + .pipeline() + .where(Function.regexMatch("title", ".*(?i)(the|of).*")) .execute(firestore) .get(); @@ -585,7 +605,7 @@ public void testRegexContains() throws Exception { public void testArithmeticOperations() throws Exception { List results = collection - .toPipeline() + .pipeline() .select( add(Field.of("rating"), 1).asAlias("ratingPlusOne"), subtract(Field.of("published"), 1900).asAlias("yearsSince1900"), @@ -613,12 +633,12 @@ public void testArithmeticOperations() throws Exception { public void testComparisonOperators() throws Exception { List results = collection - .toPipeline() - .filter( + .pipeline() + .where( and( - greaterThan("rating", 4.2), - Field.of("rating").lessThanOrEqual(4.5), - notEqual("genre", "Science Fiction"))) + gt("rating", 4.2), + Field.of("rating").lte(4.5), + neq("genre", "Science Fiction"))) .select("rating", "title") .sort(Field.of("title").ascending()) .execute(firestore) @@ -636,11 +656,9 @@ public void testComparisonOperators() throws Exception { public void testLogicalOperators() throws Exception { List results = collection - .toPipeline() - .filter( - or( - and(greaterThan("rating", 4.5), equal("genre", "Science Fiction")), - lessThan("published", 1900))) + .pipeline() + .where( + or(and(gt("rating", 4.5), eq("genre", "Science Fiction")), lt("published", 1900))) .select("title") .sort(Field.of("title").ascending()) .execute(firestore) @@ -658,8 +676,8 @@ public void testLogicalOperators() throws Exception { public void testChecks() throws Exception { List results = collection - .toPipeline() - .filter(not(Field.of("rating").isNaN())) // Filter out any documents with NaN rating + .pipeline() + .where(not(Field.of("rating").isNaN())) // Filter out any documents with NaN rating .select( isNull("rating").asAlias("ratingIsNull"), not(Field.of("rating").isNaN()).asAlias("ratingIsNotNaN")) @@ -675,9 +693,9 @@ public void testChecks() throws Exception { public void testMapGet() throws Exception { List results = collection - .toPipeline() + .pipeline() .select(Field.of("awards").mapGet("hugo").asAlias("hugoAward"), Field.of("title")) - .filter(equal("hugoAward", true)) + .where(eq("hugoAward", true)) .execute(firestore) .get(); @@ -692,7 +710,7 @@ public void testMapGet() throws Exception { public void testParent() throws Exception { List results = collection - .toPipeline() + .pipeline() .select( parent(collection.document("chile").collection("subCollection").getPath()) .asAlias("parent")) @@ -709,7 +727,7 @@ public void testParent() throws Exception { public void testCollectionId() throws Exception { List results = collection - .toPipeline() + .pipeline() .select(collectionId(collection.document("chile")).asAlias("collectionId")) .limit(1) .execute(firestore) @@ -724,7 +742,7 @@ public void testDistanceFunctions() throws Exception { double[] targetVector = {0.5, 0.8}; List results = collection - .toPipeline() + .pipeline() .select( cosineDistance(Constant.ofVector(sourceVector), targetVector) .asAlias("cosineDistance"), @@ -741,8 +759,8 @@ public void testDistanceFunctions() throws Exception { public void testNestedFields() throws Exception { List results = collection - .toPipeline() - .filter(equal("awards.hugo", true)) + .pipeline() + .where(eq("awards.hugo", true)) .select("title", "awards.hugo") .execute(firestore) .get(); diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryAggregationsTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryAggregationsTest.java index 6a90f4f81..5232862bc 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryAggregationsTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryAggregationsTest.java @@ -62,7 +62,7 @@ public static AggregateQuerySnapshot verifyPipelineReturnsSameResult(AggregateQu AggregateQuerySnapshot snapshot = query.get().get(); List pipelineResults = - query.toPipeline().execute(query.getQuery().getFirestore()).get(); + query.pipeline().execute(query.getQuery().getFirestore()).get(); assertThat(pipelineResults).hasSize(1); assertThat(pipelineResults.get(0).getData()) .isEqualTo(TestUtil.getAggregateSnapshotData(snapshot)); diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java index f3ac2cc5e..34161fa70 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java @@ -85,7 +85,7 @@ public static void checkResultContainsDocumentsInOrder( assertThat(result).isEqualTo(Arrays.asList(docs)); } - List pipelineResults = query.toPipeline().execute(query.getFirestore()).get(); + List pipelineResults = query.pipeline().execute(query.getFirestore()).get(); List result = pipelineResults.stream() .map(pipelineResult -> Objects.requireNonNull(pipelineResult.getReference()).getId()) @@ -104,7 +104,7 @@ public static void checkResultContainsDocuments(Query query, boolean pipelineOnl assertThat(result).isEqualTo(Sets.newHashSet(docs)); } - List pipelineResults = query.toPipeline().execute(query.getFirestore()).get(); + List pipelineResults = query.pipeline().execute(query.getFirestore()).get(); Set result = pipelineResults.stream() .map(pipelineResult -> Objects.requireNonNull(pipelineResult.getReference()).getId()) @@ -929,7 +929,7 @@ public void multipleInequalityFieldsInAggregateQuery() throws Exception { if (isRunningAgainstFirestoreEmulator(firestore)) { assertThat(query.get().get().getCount()).isEqualTo(4); } - assertThat(query.toPipeline().execute(query.getQuery().getFirestore()).get()).isNotEmpty(); + assertThat(query.pipeline().execute(query.getQuery().getFirestore()).get()).isNotEmpty(); // TODO(MIEQ): Add sum and average when they are public. } From 12d4f29403d9e6abc579f834aabcc5b1bd8197bc Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Wed, 17 Jul 2024 12:59:22 -0400 Subject: [PATCH 51/65] Add annotations. --- .../cloud/firestore/AggregateQuery.java | 6 +- .../com/google/cloud/firestore/Pipeline.java | 29 +++- .../cloud/firestore/PipelineResult.java | 25 ++++ .../cloud/firestore/PipelineSource.java | 6 + .../google/cloud/firestore/PipelineUtils.java | 4 +- .../com/google/cloud/firestore/Query.java | 2 + .../pipeline/expressions/Accumulator.java | 8 +- ...atorTarget.java => AccumulatorTarget.java} | 11 +- .../firestore/pipeline/expressions/Add.java | 2 + .../firestore/pipeline/expressions/And.java | 2 + .../pipeline/expressions/ArrayConcat.java | 4 + .../pipeline/expressions/ArrayContains.java | 4 + .../expressions/ArrayContainsAll.java | 4 + .../expressions/ArrayContainsAny.java | 4 + .../pipeline/expressions/ArrayElement.java | 4 + .../pipeline/expressions/ArrayFilter.java | 4 + .../pipeline/expressions/ArrayLength.java | 4 + .../pipeline/expressions/ArrayTransform.java | 4 + .../firestore/pipeline/expressions/Avg.java | 4 + .../pipeline/expressions/CollectionId.java | 2 + .../pipeline/expressions/Constant.java | 17 ++- .../pipeline/expressions/CosineDistance.java | 4 + .../firestore/pipeline/expressions/Count.java | 4 + .../pipeline/expressions/CountIf.java | 4 + .../pipeline/expressions/Divide.java | 2 + .../expressions/DotProductDistance.java | 4 + .../firestore/pipeline/expressions/Eq.java | 4 + .../expressions/EuclideanDistance.java | 4 + .../pipeline/expressions/Exists.java | 4 + .../firestore/pipeline/expressions/Expr.java | 60 ++++++++ .../firestore/pipeline/expressions/Field.java | 10 +- .../pipeline/expressions/Fields.java | 7 +- .../pipeline/expressions/FilterCondition.java | 3 + .../pipeline/expressions/Function.java | 134 +++++++++++++++++- .../firestore/pipeline/expressions/Gt.java | 4 + .../firestore/pipeline/expressions/Gte.java | 4 + .../firestore/pipeline/expressions/If.java | 4 + .../firestore/pipeline/expressions/In.java | 4 + .../firestore/pipeline/expressions/IsNaN.java | 4 + .../pipeline/expressions/IsNull.java | 4 + .../pipeline/expressions/Length.java | 4 + .../firestore/pipeline/expressions/Like.java | 2 + .../pipeline/expressions/ListOfExprs.java | 1 + .../firestore/pipeline/expressions/Lt.java | 4 + .../firestore/pipeline/expressions/Lte.java | 4 + .../pipeline/expressions/MapGet.java | 4 + .../firestore/pipeline/expressions/Max.java | 4 + .../firestore/pipeline/expressions/Min.java | 4 + .../pipeline/expressions/Multiply.java | 2 + .../firestore/pipeline/expressions/Neq.java | 4 + .../firestore/pipeline/expressions/Not.java | 4 + .../firestore/pipeline/expressions/Or.java | 4 + .../pipeline/expressions/Ordering.java | 10 +- .../pipeline/expressions/Parent.java | 2 + .../pipeline/expressions/RegexContains.java | 2 + .../pipeline/expressions/RegexMatch.java | 2 + .../pipeline/expressions/Selectable.java | 3 + .../pipeline/expressions/StrConcat.java | 4 + .../pipeline/expressions/Subtract.java | 2 + .../firestore/pipeline/expressions/Sum.java | 4 + .../pipeline/expressions/ToLowercase.java | 4 + .../pipeline/expressions/ToUppercase.java | 4 + .../firestore/pipeline/expressions/Trim.java | 4 + .../firestore/pipeline/expressions/Xor.java | 4 + .../firestore/pipeline/stages/AddFields.java | 1 + .../firestore/pipeline/stages/Aggregate.java | 8 +- .../firestore/pipeline/stages/Collection.java | 1 + .../pipeline/stages/CollectionGroup.java | 1 + .../firestore/pipeline/stages/Documents.java | 2 + .../pipeline/stages/FindNearest.java | 9 +- .../pipeline/stages/GenericStage.java | 1 + .../firestore/pipeline/stages/Limit.java | 2 + .../firestore/pipeline/stages/Offset.java | 2 + .../firestore/pipeline/stages/Select.java | 2 + .../cloud/firestore/pipeline/stages/Sort.java | 6 +- .../firestore/pipeline/stages/Where.java | 1 + 76 files changed, 516 insertions(+), 24 deletions(-) rename google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/{AggregatorTarget.java => AccumulatorTarget.java} (58%) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java index 7a0bff3db..253afdbbc 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java @@ -17,6 +17,7 @@ package com.google.cloud.firestore; import com.google.api.core.ApiFuture; +import com.google.api.core.BetaApi; import com.google.api.core.InternalExtensionOnly; import com.google.api.core.SettableApiFuture; import com.google.api.gax.rpc.ResponseObserver; @@ -24,7 +25,7 @@ import com.google.api.gax.rpc.StatusCode; import com.google.api.gax.rpc.StreamController; import com.google.cloud.Timestamp; -import com.google.cloud.firestore.pipeline.expressions.AggregatorTarget; +import com.google.cloud.firestore.pipeline.expressions.AccumulatorTarget; import com.google.cloud.firestore.v1.FirestoreSettings; import com.google.common.collect.ImmutableMap; import com.google.firestore.v1.RunAggregationQueryRequest; @@ -67,13 +68,14 @@ public Query getQuery() { } @Nonnull + @BetaApi public Pipeline pipeline() { return getQuery() .pipeline() .aggregate( this.aggregateFieldList.stream() .map(PipelineUtils::toPipelineAggregatorTarget) - .toArray(AggregatorTarget[]::new)); + .toArray(AccumulatorTarget[]::new)); } /** diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java index 7eb6075c8..a73ea3b1c 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java @@ -1,13 +1,15 @@ package com.google.cloud.firestore; import com.google.api.core.ApiFuture; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalExtensionOnly; import com.google.api.core.SettableApiFuture; import com.google.api.gax.rpc.ApiStreamObserver; import com.google.api.gax.rpc.ResponseObserver; import com.google.api.gax.rpc.StreamController; import com.google.cloud.Timestamp; import com.google.cloud.firestore.pipeline.PaginatingPipeline; -import com.google.cloud.firestore.pipeline.expressions.AggregatorTarget; +import com.google.cloud.firestore.pipeline.expressions.AccumulatorTarget; import com.google.cloud.firestore.pipeline.expressions.Expr; import com.google.cloud.firestore.pipeline.expressions.ExprWithAlias; import com.google.cloud.firestore.pipeline.expressions.Field; @@ -81,6 +83,7 @@ *

```java Pipeline pipeline = Pipeline.fromCollection("orders") .group(Field.of("customerId")) * .aggregate(count(Field.of("orderId")).asAlias("orderCount")); ``` */ +@BetaApi public final class Pipeline { private final ImmutableList stages; @@ -110,8 +113,8 @@ private Map projectablesToMap(Selectable... selectables) { if (proj instanceof Field) { Field fieldProj = (Field) proj; projMap.put(fieldProj.getPath().getEncodedPath(), fieldProj); - } else if (proj instanceof AggregatorTarget) { - AggregatorTarget aggregatorProj = (AggregatorTarget) proj; + } else if (proj instanceof AccumulatorTarget) { + AccumulatorTarget aggregatorProj = (AccumulatorTarget) proj; projMap.put(aggregatorProj.getFieldName(), aggregatorProj.getAccumulator()); } else if (proj instanceof Fields) { Fields fieldsProj = (Fields) proj; @@ -134,6 +137,7 @@ private Map fieldNamesToMap(String... fields) { return projMap; } + @BetaApi public Pipeline addFields(Selectable... fields) { return new Pipeline( ImmutableList.builder() @@ -142,6 +146,7 @@ public Pipeline addFields(Selectable... fields) { .build()); } + @BetaApi public Pipeline select(Selectable... projections) { return new Pipeline( ImmutableList.builder() @@ -150,6 +155,7 @@ public Pipeline select(Selectable... projections) { .build()); } + @BetaApi public Pipeline select(String... fields) { return new Pipeline( ImmutableList.builder() @@ -158,31 +164,37 @@ public Pipeline select(String... fields) { .build()); } + @BetaApi public Pipeline where(FilterCondition condition) { return new Pipeline( ImmutableList.builder().addAll(stages).add(new Where(condition)).build()); } + @BetaApi public Pipeline offset(int offset) { return new Pipeline( ImmutableList.builder().addAll(stages).add(new Offset(offset)).build()); } + @BetaApi public Pipeline limit(int limit) { return new Pipeline( ImmutableList.builder().addAll(stages).add(new Limit(limit)).build()); } - public Pipeline aggregate(AggregatorTarget... aggregators) { + @BetaApi + public Pipeline aggregate(AccumulatorTarget... aggregators) { return new Pipeline( ImmutableList.builder().addAll(stages).add(new Aggregate(aggregators)).build()); } + @BetaApi public Pipeline findNearest( String fieldName, double[] vector, FindNearest.FindNearestOptions options) { return findNearest(Field.of(fieldName), vector, options); } + @BetaApi public Pipeline findNearest( Field property, double[] vector, FindNearest.FindNearestOptions options) { // Implementation for findNearest (add the FindNearest stage if needed) @@ -195,6 +207,7 @@ public Pipeline findNearest( .build()); } + @BetaApi public Pipeline sort(List orders, Sort.Density density, Sort.Truncation truncation) { return new Pipeline( ImmutableList.builder() @@ -204,14 +217,17 @@ public Pipeline sort(List orders, Sort.Density density, Sort.Truncatio } // Sugar + @BetaApi public Pipeline sort(Ordering... orders) { return sort(Arrays.asList(orders), Sort.Density.UNSPECIFIED, Sort.Truncation.UNSPECIFIED); } + @BetaApi public PaginatingPipeline paginate(int pageSize, Ordering... orders) { return new PaginatingPipeline(this, pageSize, Arrays.asList(orders)); } + @BetaApi public Pipeline genericStage(String name, Map params) { // Implementation for genericStage (add the GenericStage if needed) return new Pipeline( @@ -225,6 +241,7 @@ public Pipeline genericStage(String name, Map params) { .build()); } + @BetaApi public ApiFuture> execute(Firestore db) { if (db instanceof FirestoreImpl) { FirestoreImpl firestoreImpl = (FirestoreImpl) db; @@ -269,6 +286,7 @@ public void onError(Throwable t) { } } + @BetaApi public void execute(Firestore db, ApiStreamObserver observer) { if (db instanceof FirestoreImpl) { FirestoreImpl firestoreImpl = (FirestoreImpl) db; @@ -307,7 +325,7 @@ public void onError(Throwable t) { } } - public Value toProto() { + private Value toProto() { return Value.newBuilder() .setPipelineValue( com.google.firestore.v1.Pipeline.newBuilder() @@ -392,6 +410,7 @@ public void onComplete() { } } +@InternalExtensionOnly abstract class PipelineResultObserver implements ApiStreamObserver { private Timestamp executionTime; // Remove optional since Java doesn't have it diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.java index b54d9e36e..05647d580 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.java @@ -16,6 +16,7 @@ package com.google.cloud.firestore; +import com.google.api.core.BetaApi; import com.google.api.core.InternalExtensionOnly; import com.google.cloud.Timestamp; import com.google.common.base.Preconditions; @@ -43,6 +44,7 @@ * that does so. */ @InternalExtensionOnly +@BetaApi public final class PipelineResult { private final FirestoreRpcContext rpcContext; @@ -73,6 +75,7 @@ public final class PipelineResult { * @return The id of the document. */ @Nonnull + @BetaApi public String getId() { return docRef.getId(); } @@ -96,6 +99,7 @@ static PipelineResult fromDocument( * @return The read time of this snapshot. */ @Nullable + @BetaApi public Timestamp getReadTime() { return readTime; } @@ -108,6 +112,7 @@ public Timestamp getReadTime() { * exist. */ @Nullable + @BetaApi public Timestamp getUpdateTime() { return updateTime; } @@ -119,6 +124,7 @@ public Timestamp getUpdateTime() { * exist. */ @Nullable + @BetaApi public Timestamp getCreateTime() { return createTime; } @@ -129,6 +135,7 @@ public Timestamp getCreateTime() { * * @return whether the document existed in this snapshot. */ + @BetaApi public boolean exists() { return fields != null; } @@ -140,6 +147,7 @@ public boolean exists() { * @return The fields of the document as a Map or null if the document doesn't exist. */ @Nullable + @BetaApi public Map getData() { if (fields == null) { return null; @@ -161,6 +169,7 @@ public Map getData() { * exist. */ @Nullable + @BetaApi public T toObject(@Nonnull Class valueType) { Map data = getData(); return data == null ? null : CustomClassMapper.convertToCustomClass(data, valueType, docRef); @@ -173,6 +182,7 @@ public T toObject(@Nonnull Class valueType) { * @param field the path to the field. * @return true iff the field exists. */ + @BetaApi public boolean contains(@Nonnull String field) { return contains(FieldPath.fromDotSeparatedString(field)); } @@ -184,6 +194,7 @@ public boolean contains(@Nonnull String field) { * @param fieldPath the path to the field. * @return true iff the field exists. */ + @BetaApi public boolean contains(@Nonnull FieldPath fieldPath) { return this.extractField(fieldPath) != null; } @@ -195,6 +206,7 @@ public boolean contains(@Nonnull FieldPath fieldPath) { * @return The value at the given field or null. */ @Nullable + @BetaApi public Object get(@Nonnull String field) { return get(FieldPath.fromDotSeparatedString(field)); } @@ -208,6 +220,7 @@ public Object get(@Nonnull String field) { * @return The value at the given field or null. */ @Nullable + @BetaApi public T get(@Nonnull String field, @Nonnull Class valueType) { return get(FieldPath.fromDotSeparatedString(field), valueType); } @@ -219,6 +232,7 @@ public T get(@Nonnull String field, @Nonnull Class valueType) { * @return The value at the given field or null. */ @Nullable + @BetaApi public Object get(@Nonnull FieldPath fieldPath) { Value value = extractField(fieldPath); @@ -238,6 +252,7 @@ public Object get(@Nonnull FieldPath fieldPath) { * @return The value at the given field or null. */ @Nullable + @BetaApi public T get(@Nonnull FieldPath fieldPath, Class valueType) { Object data = get(fieldPath); return data == null ? null : CustomClassMapper.convertToCustomClass(data, valueType, docRef); @@ -271,6 +286,7 @@ Value extractField(@Nonnull FieldPath fieldPath) { * @return The value of the field. */ @Nullable + @BetaApi public Boolean getBoolean(@Nonnull String field) { return (Boolean) get(field); } @@ -283,6 +299,7 @@ public Boolean getBoolean(@Nonnull String field) { * @return The value of the field. */ @Nullable + @BetaApi public Double getDouble(@Nonnull String field) { Number number = (Number) get(field); return number == null ? null : number.doubleValue(); @@ -296,6 +313,7 @@ public Double getDouble(@Nonnull String field) { * @return The value of the field. */ @Nullable + @BetaApi public String getString(@Nonnull String field) { return (String) get(field); } @@ -308,6 +326,7 @@ public String getString(@Nonnull String field) { * @return The value of the field. */ @Nullable + @BetaApi public Long getLong(@Nonnull String field) { Number number = (Number) get(field); return number == null ? null : number.longValue(); @@ -321,6 +340,7 @@ public Long getLong(@Nonnull String field) { * @return The value of the field. */ @Nullable + @BetaApi public Date getDate(@Nonnull String field) { Timestamp timestamp = getTimestamp(field); return timestamp == null ? null : timestamp.toDate(); @@ -334,6 +354,7 @@ public Date getDate(@Nonnull String field) { * @return The value of the field. */ @Nullable + @BetaApi public Timestamp getTimestamp(@Nonnull String field) { return (Timestamp) get(field); } @@ -346,6 +367,7 @@ public Timestamp getTimestamp(@Nonnull String field) { * @return The value of the field. */ @Nullable + @BetaApi public Blob getBlob(@Nonnull String field) { return (Blob) get(field); } @@ -358,6 +380,7 @@ public Blob getBlob(@Nonnull String field) { * @return The value of the field. */ @Nullable + @BetaApi public GeoPoint getGeoPoint(@Nonnull String field) { return (GeoPoint) get(field); } @@ -368,6 +391,7 @@ public GeoPoint getGeoPoint(@Nonnull String field) { * @return The reference to the document. */ @Nonnull + @BetaApi public DocumentReference getReference() { return docRef; } @@ -408,6 +432,7 @@ Document.Builder toDocumentPb() { * @return Whether this DocumentSnapshot is equal to the provided object. */ @Override + @BetaApi public boolean equals(Object obj) { if (this == obj) { return true; diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java index add5067b9..5f4a7a67d 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java @@ -1,5 +1,6 @@ package com.google.cloud.firestore; +import com.google.api.core.BetaApi; import com.google.cloud.firestore.pipeline.stages.Collection; import com.google.cloud.firestore.pipeline.stages.CollectionGroup; import com.google.cloud.firestore.pipeline.stages.Database; @@ -7,14 +8,17 @@ import com.google.common.base.Preconditions; import javax.annotation.Nonnull; +@BetaApi public class PipelineSource { @Nonnull + @BetaApi public Pipeline collection(@Nonnull String path) { return new Pipeline(new Collection(path)); } @Nonnull + @BetaApi public Pipeline collectionGroup(@Nonnull String collectionId) { Preconditions.checkArgument( !collectionId.contains("/"), @@ -24,11 +28,13 @@ public Pipeline collectionGroup(@Nonnull String collectionId) { } @Nonnull + @BetaApi public Pipeline database() { return new Pipeline(new Database()); } @Nonnull + @BetaApi public Pipeline documents(DocumentReference... docs) { return new Pipeline(Documents.of(docs)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java index f5b9cce73..83b5d7cdc 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java @@ -14,7 +14,7 @@ import com.google.cloud.firestore.Query.LimitType; import com.google.cloud.firestore.Query.UnaryFilterInternal; import com.google.cloud.firestore.pipeline.PaginatingPipeline; -import com.google.cloud.firestore.pipeline.expressions.AggregatorTarget; +import com.google.cloud.firestore.pipeline.expressions.AccumulatorTarget; import com.google.cloud.firestore.pipeline.expressions.Field; import com.google.cloud.firestore.pipeline.expressions.FilterCondition; import com.google.common.collect.Lists; @@ -152,7 +152,7 @@ static Pipeline toPaginatedPipeline( } @InternalApi - static AggregatorTarget toPipelineAggregatorTarget(AggregateField f) { + static AccumulatorTarget toPipelineAggregatorTarget(AggregateField f) { String operator = f.getOperator(); String fieldPath = f.getFieldPath(); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index 541a4d903..32b8d8bdd 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -32,6 +32,7 @@ import static com.google.firestore.v1.StructuredQuery.FieldFilter.Operator.NOT_IN; import com.google.api.core.ApiFuture; +import com.google.api.core.BetaApi; import com.google.api.core.InternalExtensionOnly; import com.google.api.core.SettableApiFuture; import com.google.api.gax.rpc.ApiStreamObserver; @@ -2122,6 +2123,7 @@ public AggregateQuery aggregate( } @Nonnull + @BetaApi public Pipeline pipeline() { // From Pipeline ppl = diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Accumulator.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Accumulator.java index 9c517392c..d663a86e5 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Accumulator.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Accumulator.java @@ -1,7 +1,11 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; + +@BetaApi public interface Accumulator extends Expr { - default AggregatorTarget toField(String fieldName) { - return new AggregatorTarget(this, fieldName, false); + @BetaApi + default AccumulatorTarget toField(String fieldName) { + return new AccumulatorTarget(this, fieldName, false); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AggregatorTarget.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AccumulatorTarget.java similarity index 58% rename from google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AggregatorTarget.java rename to google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AccumulatorTarget.java index 80dedbccb..fce6184af 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AggregatorTarget.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AccumulatorTarget.java @@ -1,19 +1,26 @@ package com.google.cloud.firestore.pipeline.expressions; -public final class AggregatorTarget implements Selectable { +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; + +@BetaApi +public final class AccumulatorTarget implements Selectable { private final Accumulator accumulator; private final String fieldName; - AggregatorTarget(Accumulator accumulator, String fieldName, boolean distinct) { + @InternalApi + AccumulatorTarget(Accumulator accumulator, String fieldName, boolean distinct) { this.accumulator = accumulator; this.fieldName = fieldName; } // Getters (for accumulator, fieldName, and distinct) + @InternalApi public Accumulator getAccumulator() { return accumulator; } + @InternalApi public String getFieldName() { return fieldName; } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Add.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Add.java index 1d73fbafc..e2768b7d5 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Add.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Add.java @@ -1,8 +1,10 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Add extends Function { @InternalApi Add(Expr left, Expr right) { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/And.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/And.java index 4831fccbd..296fb532a 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/And.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/And.java @@ -1,8 +1,10 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import java.util.List; +@BetaApi public final class And extends Function implements FilterCondition { @InternalApi And(List conditions) { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayConcat.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayConcat.java index 20fd90f9f..0f5f8774d 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayConcat.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayConcat.java @@ -1,9 +1,13 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; import java.util.List; +@BetaApi public final class ArrayConcat extends Function { + @InternalApi ArrayConcat(Expr array, List rest) { super("array_concat", Lists.newArrayList(array, new ListOfExprs(rest))); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContains.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContains.java index 0d03f5184..99fc5754b 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContains.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContains.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class ArrayContains extends Function implements FilterCondition { + @InternalApi ArrayContains(Expr array, Expr element) { super("array_contains", Lists.newArrayList(array, element)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContainsAll.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContainsAll.java index 3f193c2f4..b011081a4 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContainsAll.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContainsAll.java @@ -1,9 +1,13 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; import java.util.List; +@BetaApi public final class ArrayContainsAll extends Function implements FilterCondition { + @InternalApi ArrayContainsAll(Expr array, List elements) { super("array_contains_all", Lists.newArrayList(array, new ListOfExprs(elements))); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContainsAny.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContainsAny.java index 0520e26d8..fb7e40d7b 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContainsAny.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayContainsAny.java @@ -1,9 +1,13 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; import java.util.List; +@BetaApi public final class ArrayContainsAny extends Function implements FilterCondition { + @InternalApi ArrayContainsAny(Expr array, List elements) { super("array_contains_any", Lists.newArrayList(array, new ListOfExprs(elements))); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayElement.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayElement.java index 664dbb17c..903e528f7 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayElement.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayElement.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public class ArrayElement extends Function { + @InternalApi ArrayElement() { super("array_element", Lists.newArrayList()); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayFilter.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayFilter.java index 376bcff8e..d367f7412 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayFilter.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayFilter.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class ArrayFilter extends Function { + @InternalApi ArrayFilter(Expr array, FilterCondition filter) { super("array_filter", Lists.newArrayList(array, filter)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayLength.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayLength.java index 8cbc08d6f..d9232457b 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayLength.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayLength.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class ArrayLength extends Function { + @InternalApi ArrayLength(Expr array) { super("array_length", Lists.newArrayList(array)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayTransform.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayTransform.java index d9c5f218e..3278e8f84 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayTransform.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayTransform.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class ArrayTransform extends Function { + @InternalApi ArrayTransform(Expr array, Function transform) { super("array_transform", Lists.newArrayList(array, transform)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Avg.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Avg.java index d83560bcc..355236076 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Avg.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Avg.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Avg extends Function implements Accumulator { + @InternalApi Avg(Expr value, boolean distinct) { super("avg", Lists.newArrayList(value)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CollectionId.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CollectionId.java index aa8ee3701..e05066ad3 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CollectionId.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CollectionId.java @@ -1,8 +1,10 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class CollectionId extends Function { @InternalApi diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Constant.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Constant.java index f9ae4b4dc..d6d0d4bcd 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Constant.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Constant.java @@ -2,6 +2,7 @@ import static com.google.cloud.firestore.PipelineUtils.encodeValue; +import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.cloud.Timestamp; import com.google.cloud.firestore.Blob; @@ -13,6 +14,7 @@ import java.util.Map; import java.util.stream.Collectors; +@BetaApi public final class Constant implements Expr { private final Object value; @@ -20,34 +22,42 @@ private Constant(Object value) { this.value = value; } + @BetaApi public static Constant of(String value) { return new Constant(value); } + @BetaApi public static Constant of(Number value) { return new Constant(value); } + @BetaApi public static Constant of(Date value) { return new Constant(value); } + @BetaApi public static Constant of(Timestamp value) { return new Constant(value); } + @BetaApi public static Constant of(Boolean value) { return new Constant(value); } + @BetaApi public static Constant of(GeoPoint value) { return new Constant(value); } + @BetaApi public static Constant of(Blob value) { return new Constant(value); } + @BetaApi public static Constant of(DocumentReference value) { return new Constant(value); } @@ -57,7 +67,7 @@ public static Constant of(Value value) { return new Constant(value); } - @InternalApi + @BetaApi static Constant of(Object value) { if (value == null) { return new Constant(null); @@ -86,23 +96,28 @@ static Constant of(Object value) { } } + @BetaApi public static Constant of(Iterable value) { return new Constant(value); } + @BetaApi public static Constant of(T[] value) { return new Constant(Arrays.asList(value)); // Convert array to list } + @BetaApi public static Constant of(Map value) { return new Constant(value); } + @BetaApi public static Constant ofVector(double[] value) { // Convert double array to List return new Constant(Arrays.stream(value).boxed().collect(Collectors.toList())); } + @InternalApi public Value toProto() { return encodeValue(value); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CosineDistance.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CosineDistance.java index 7767eab30..adec5b369 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CosineDistance.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CosineDistance.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class CosineDistance extends Function { + @InternalApi CosineDistance(Expr vector1, Expr vector2) { super("cosine_distance", Lists.newArrayList(vector1, vector2)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Count.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Count.java index a16129498..4c2cfc827 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Count.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Count.java @@ -1,9 +1,13 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; import java.util.Collections; +@BetaApi public final class Count extends Function implements Accumulator { + @InternalApi Count(Expr value, boolean distinct) { super("count", (value != null) ? Lists.newArrayList(value) : Collections.emptyList()); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CountIf.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CountIf.java index d31851eed..5db4c1dd7 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CountIf.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/CountIf.java @@ -1,9 +1,13 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; import java.util.Collections; +@BetaApi public final class CountIf extends Function implements Accumulator { + @InternalApi CountIf(Expr value, boolean distinct) { super("count_if", (value != null) ? Lists.newArrayList(value) : Collections.emptyList()); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Divide.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Divide.java index 3f70f55ce..f99f1c8b3 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Divide.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Divide.java @@ -1,8 +1,10 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Divide extends Function { @InternalApi Divide(Expr left, Expr right) { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/DotProductDistance.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/DotProductDistance.java index d88aeb342..8fefb863c 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/DotProductDistance.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/DotProductDistance.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class DotProductDistance extends Function { + @InternalApi DotProductDistance(Expr vector1, Expr vector2) { super("dot_product", Lists.newArrayList(vector1, vector2)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Eq.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Eq.java index 48db0bd95..4c86da7a5 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Eq.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Eq.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Eq extends Function implements FilterCondition { + @InternalApi Eq(Expr left, Expr right) { super("eq", Lists.newArrayList(left, right)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/EuclideanDistance.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/EuclideanDistance.java index 8ee207f66..1fd0808dd 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/EuclideanDistance.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/EuclideanDistance.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class EuclideanDistance extends Function { + @InternalApi EuclideanDistance(Expr vector1, Expr vector2) { super("euclidean_distance", Lists.newArrayList(vector1, vector2)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Exists.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Exists.java index ad64a9b9a..d2c04f04b 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Exists.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Exists.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Exists extends Function implements FilterCondition { + @InternalApi Exists(Field field) { super("exists", Lists.newArrayList(field)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java index 43475069e..b2012ae91 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java @@ -1,90 +1,113 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +@BetaApi public interface Expr { + @BetaApi default Add add(Expr other) { return new Add(this, other); } + @BetaApi default Add add(Object other) { return new Add(this, Constant.of(other)); } + @BetaApi default Subtract subtract(Expr other) { return new Subtract(this, other); } + @BetaApi default Subtract subtract(Object other) { return new Subtract(this, Constant.of(other)); } + @BetaApi default Multiply multiply(Expr other) { return new Multiply(this, other); } + @BetaApi default Multiply multiply(Object other) { return new Multiply(this, Constant.of(other)); } + @BetaApi default Divide divide(Expr other) { return new Divide(this, other); } + @BetaApi default Divide divide(Object other) { return new Divide(this, Constant.of(other)); } + @BetaApi default Eq eq(Expr expr) { return new Eq(this, expr); } + @BetaApi default Eq eq(Object other) { return new Eq(this, Constant.of(other)); } + @BetaApi default Neq neq(Expr other) { return new Neq(this, other); } + @BetaApi default Neq neq(Object other) { return new Neq(this, Constant.of(other)); } + @BetaApi default Gt gt(Expr other) { return new Gt(this, other); } + @BetaApi default Gt gt(Object other) { return new Gt(this, Constant.of(other)); } + @BetaApi default Gte gte(Expr other) { return new Gte(this, other); } + @BetaApi default Gte gte(Object other) { return new Gte(this, Constant.of(other)); } + @BetaApi default Lt lt(Expr other) { return new Lt(this, other); } + @BetaApi default Lt lt(Object other) { return new Lt(this, Constant.of(other)); } + @BetaApi default Lte lte(Expr other) { return new Lte(this, other); } + @BetaApi default Lte lte(Object other) { return new Lte(this, Constant.of(other)); } + @BetaApi default In inAny(Object... other) { List othersAsExpr = Arrays.stream(other) @@ -93,153 +116,190 @@ default In inAny(Object... other) { return new In(this, othersAsExpr); } + @BetaApi default Not notInAny(Object... other) { return new Not(inAny(other)); } + @BetaApi default ArrayConcat arrayConcat(Expr... elements) { return new ArrayConcat(this, Arrays.asList(elements)); } + @BetaApi default ArrayConcat arrayConcat(Object... elements) { return new ArrayConcat( this, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); } + @BetaApi default ArrayContains arrayContains(Expr element) { return new ArrayContains(this, element); } + @BetaApi default ArrayContains arrayContains(Object element) { return new ArrayContains(this, Constant.of(element)); } + @BetaApi default ArrayContainsAll arrayContainsAll(Expr... elements) { return new ArrayContainsAll(this, Arrays.asList(elements)); } + @BetaApi default ArrayContainsAll arrayContainsAll(Object... elements) { return new ArrayContainsAll( this, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); } + @BetaApi default ArrayContainsAny arrayContainsAny(Expr... elements) { return new ArrayContainsAny(this, Arrays.asList(elements)); } + @BetaApi default ArrayContainsAny arrayContainsAny(Object... elements) { return new ArrayContainsAny( this, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); } + @BetaApi default ArrayFilter arrayFilter(FilterCondition filter) { return new ArrayFilter(this, filter); } + @BetaApi default ArrayLength arrayLength() { return new ArrayLength(this); } + @BetaApi default ArrayTransform arrayTransform(Function transform) { return new ArrayTransform(this, transform); } + @BetaApi default IsNaN isNaN() { return new IsNaN(this); } + @BetaApi default IsNull isNull() { return new IsNull(this); } + @BetaApi default Sum sum() { return new Sum(this, false); } + @BetaApi default Avg avg() { return new Avg(this, false); } + @BetaApi default Count count() { return new Count(this, false); } + @BetaApi default Min min() { return new Min(this, false); } + @BetaApi default Max max() { return new Max(this, false); } + @BetaApi default Length length() { return new Length(this); } + @BetaApi default Like like(String pattern) { return new Like(this, Constant.of(pattern)); } + @BetaApi default RegexContains regexContains(String regex) { return new RegexContains(this, Constant.of(regex)); } + @BetaApi default RegexMatch regexMatches(String regex) { return new RegexMatch(this, Constant.of(regex)); } + @BetaApi default StrConcat strConcat(List elements) { return new StrConcat(this, elements); } + @BetaApi default ToLowercase toLowercase() { return new ToLowercase(this); } + @BetaApi default ToUppercase toUppercase() { return new ToUppercase(this); } + @BetaApi default Trim trim() { return new Trim(this); } + @BetaApi default MapGet mapGet(String key) { return new MapGet(this, key); } + @BetaApi default CosineDistance cosineDistance(Expr other) { return new CosineDistance(this, other); } + @BetaApi default CosineDistance cosineDistance(double[] other) { return new CosineDistance(this, Constant.ofVector(other)); } + @BetaApi default EuclideanDistance euclideanDistance(Expr other) { return new EuclideanDistance(this, other); } + @BetaApi default EuclideanDistance euclideanDistance(double[] other) { return new EuclideanDistance(this, Constant.ofVector(other)); } + @BetaApi default DotProductDistance dotProductDistance(Expr other) { return new DotProductDistance(this, other); } + @BetaApi default DotProductDistance dotProductDistance(double[] other) { return new DotProductDistance(this, Constant.ofVector(other)); } + @BetaApi default Ordering ascending() { return Ordering.ascending(this); } + @BetaApi default Ordering descending() { return Ordering.descending(this); } + @BetaApi default Selectable asAlias(String alias) { return new ExprWithAlias(this, alias); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java index c1541a8cb..c5137e055 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java @@ -1,10 +1,13 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.cloud.firestore.FieldPath; import com.google.cloud.firestore.Pipeline; import com.google.firestore.v1.Value; import javax.annotation.Nullable; +@BetaApi public final class Field implements Expr, Selectable { public static final String DOCUMENT_ID = "__name__"; private final FieldPath path; @@ -14,6 +17,7 @@ private Field(FieldPath path) { this.path = path; } + @BetaApi public static Field of(String path) { if (path.equals(DOCUMENT_ID)) { return new Field(FieldPath.of("__path__")); @@ -21,23 +25,27 @@ public static Field of(String path) { return new Field(FieldPath.fromDotSeparatedString(path)); } + @BetaApi public static Field ofAll() { return new Field(FieldPath.of("")); } + @InternalApi public Value toProto() { return Value.newBuilder().setFieldReferenceValue(path.toString()).build(); } + @BetaApi public Exists exists() { return new Exists(this); } - // Getters + @InternalApi public FieldPath getPath() { return path; } + @InternalApi public Pipeline getPipeline() { return pipeline; } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Fields.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Fields.java index 7cb6cda2f..862944f36 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Fields.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Fields.java @@ -1,10 +1,13 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +@BetaApi public final class Fields implements Expr, Selectable { private final List fields; @@ -12,17 +15,19 @@ private Fields(List fs) { this.fields = fs; } + @BetaApi public static Fields of(String f1, String... f) { List fields = Arrays.stream(f).map(Field::of).collect(Collectors.toList()); fields.add(0, Field.of(f1)); // Add f1 at the beginning return new Fields(fields); } + @BetaApi public static Fields ofAll() { return new Fields(Collections.singletonList(Field.of(""))); } - // Getters + @InternalApi public List getFields() { return fields; } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/FilterCondition.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/FilterCondition.java index f182e4d30..00eb128b4 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/FilterCondition.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/FilterCondition.java @@ -1,3 +1,6 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; + +@BetaApi public interface FilterCondition extends Expr {} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java index f0bd8d658..8b38481e8 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java @@ -1,5 +1,7 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.cloud.firestore.DocumentReference; import com.google.common.collect.Lists; import com.google.firestore.v1.Value; @@ -8,6 +10,7 @@ import java.util.List; import java.util.stream.Collectors; +@BetaApi public class Function implements Expr { private final String name; private final List params; @@ -17,6 +20,7 @@ protected Function(String name, List params) { this.params = Collections.unmodifiableList(params); } + @InternalApi Value toProto() { return Value.newBuilder() .setFunctionValue( @@ -29,190 +33,237 @@ Value toProto() { .build(); } + @BetaApi public static CollectionId collectionId(String path) { return new CollectionId(Constant.of(path)); } + @BetaApi public static CollectionId collectionId(DocumentReference ref) { return new CollectionId(Constant.of(ref.getPath())); } + @BetaApi public static Parent parent(String path) { return new Parent(Constant.of(path)); } + @BetaApi public static Parent parent(DocumentReference ref) { return new Parent(Constant.of(ref.getPath())); } + @BetaApi public static Add add(Expr left, Expr right) { return new Add(left, right); } + @BetaApi public static Add add(Expr left, Object right) { return new Add(left, Constant.of(right)); } + @BetaApi public static Add add(String left, Expr right) { return new Add(Field.of(left), right); } + @BetaApi public static Add add(String left, Object right) { return new Add(Field.of(left), Constant.of(right)); } + @BetaApi public static Subtract subtract(Expr left, Expr right) { return new Subtract(left, right); } + @BetaApi public static Subtract subtract(Expr left, Object right) { return new Subtract(left, Constant.of(right)); } + @BetaApi public static Subtract subtract(String left, Expr right) { return new Subtract(Field.of(left), right); } + @BetaApi public static Subtract subtract(String left, Object right) { return new Subtract(Field.of(left), Constant.of(right)); } + @BetaApi public static Multiply multiply(Expr left, Expr right) { return new Multiply(left, right); } + @BetaApi public static Multiply multiply(Expr left, Object right) { return new Multiply(left, Constant.of(right)); } + @BetaApi public static Multiply multiply(String left, Expr right) { return new Multiply(Field.of(left), right); } + @BetaApi public static Multiply multiply(String left, Object right) { return new Multiply(Field.of(left), Constant.of(right)); } + @BetaApi public static Divide divide(Expr left, Expr right) { return new Divide(left, right); } + @BetaApi public static Divide divide(Expr left, Object right) { return new Divide(left, Constant.of(right)); } + @BetaApi public static Divide divide(String left, Expr right) { return new Divide(Field.of(left), right); } + @BetaApi public static Divide divide(String left, Object right) { return new Divide(Field.of(left), Constant.of(right)); } + @BetaApi public static Eq eq(Expr left, Expr right) { return new Eq(left, right); } + @BetaApi public static Eq eq(Expr left, Object right) { return new Eq(left, Constant.of(right)); } + @BetaApi public static Eq eq(String left, Expr right) { return new Eq(Field.of(left), right); } + @BetaApi public static Eq eq(String left, Object right) { return new Eq(Field.of(left), Constant.of(right)); } + @BetaApi public static Neq neq(Expr left, Expr right) { return new Neq(left, right); } + @BetaApi public static Neq neq(Expr left, Object right) { return new Neq(left, Constant.of(right)); } + @BetaApi public static Neq neq(String left, Expr right) { return new Neq(Field.of(left), right); } + @BetaApi public static Neq neq(String left, Object right) { return new Neq(Field.of(left), Constant.of(right)); } + @BetaApi public static Gt gt(Expr left, Expr right) { return new Gt(left, right); } + @BetaApi public static Gt gt(Expr left, Object right) { return new Gt(left, Constant.of(right)); } + @BetaApi public static Gt gt(String left, Expr right) { return new Gt(Field.of(left), right); } + @BetaApi public static Gt gt(String left, Object right) { return new Gt(Field.of(left), Constant.of(right)); } + @BetaApi public static Gte gte(Expr left, Expr right) { return new Gte(left, right); } + @BetaApi public static Gte gte(Expr left, Object right) { return new Gte(left, Constant.of(right)); } + @BetaApi public static Gte gte(String left, Expr right) { return new Gte(Field.of(left), right); } + @BetaApi public static Gte gte(String left, Object right) { return new Gte(Field.of(left), Constant.of(right)); } + @BetaApi public static Lt lt(Expr left, Expr right) { return new Lt(left, right); } + @BetaApi public static Lt lt(Expr left, Object right) { return new Lt(left, Constant.of(right)); } + @BetaApi public static Lt lt(String left, Expr right) { return new Lt(Field.of(left), right); } + @BetaApi public static Lt lt(String left, Object right) { return new Lt(Field.of(left), Constant.of(right)); } + @BetaApi public static Lte lte(Expr left, Expr right) { return new Lte(left, right); } + @BetaApi public static Lte lte(Expr left, Object right) { return new Lte(left, Constant.of(right)); } + @BetaApi public static Lte lte(String left, Expr right) { return new Lte(Field.of(left), right); } + @BetaApi public static Lte lte(String left, Object right) { return new Lte(Field.of(left), Constant.of(right)); } + @BetaApi public static Exists exists(String field) { return new Exists(Field.of(field)); } + @BetaApi public static Exists exists(Field field) { return new Exists(field); } + @BetaApi public static In inAny(Expr left, List values) { List othersAsExpr = values.stream() @@ -221,345 +272,426 @@ public static In inAny(Expr left, List values) { return new In(left, othersAsExpr); } + @BetaApi public static In inAny(String left, List values) { return inAny(Field.of(left), values); } + @BetaApi public static Not notInAny(Expr left, List values) { return new Not(inAny(left, values)); } + @BetaApi public static Not notInAny(String left, List values) { return new Not(inAny(Field.of(left), values)); } + @BetaApi public static And and(FilterCondition left, FilterCondition right) { return new And(Lists.newArrayList(left, right)); } + @BetaApi public static And and(FilterCondition left, FilterCondition... other) { List conditions = Lists.newArrayList(left); conditions.addAll(Arrays.asList(other)); return new And(conditions); } + @BetaApi public static Or or(FilterCondition left, FilterCondition right) { return new Or(Lists.newArrayList(left, right)); } + @BetaApi public static Or or(FilterCondition left, FilterCondition... other) { List conditions = Lists.newArrayList(left); conditions.addAll(Arrays.asList(other)); return new Or(conditions); } + @BetaApi public static Xor xor(FilterCondition left, FilterCondition right) { return new Xor(Lists.newArrayList(left, right)); } + @BetaApi public static Xor xor(FilterCondition left, FilterCondition... other) { List conditions = Lists.newArrayList(left); conditions.addAll(Arrays.asList(other)); return new Xor(conditions); } + @BetaApi public static If ifThen(FilterCondition condition, Expr thenExpr) { return new If(condition, thenExpr, null); } + @BetaApi public static If ifThenElse(FilterCondition condition, Expr thenExpr, Expr elseExpr) { return new If(condition, thenExpr, elseExpr); } + @BetaApi public static ArrayConcat arrayConcat(Expr expr, Expr... elements) { return new ArrayConcat(expr, Arrays.asList(elements)); } + @BetaApi public static ArrayConcat arrayConcat(Expr expr, Object... elements) { return new ArrayConcat( expr, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); } + @BetaApi public static ArrayConcat arrayConcat(String field, Expr... elements) { return new ArrayConcat(Field.of(field), Arrays.asList(elements)); } + @BetaApi public static ArrayConcat arrayConcat(String field, Object... elements) { return new ArrayConcat( Field.of(field), Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); } + @BetaApi public static ArrayContains arrayContains(Expr expr, Expr element) { return new ArrayContains(expr, element); } + @BetaApi public static ArrayContains arrayContains(String field, Expr element) { return new ArrayContains(Field.of(field), element); } + @BetaApi public static ArrayContains arrayContains(Expr expr, Object element) { return new ArrayContains(expr, Constant.of(element)); } + @BetaApi public static ArrayContains arrayContains(String field, Object element) { return new ArrayContains(Field.of(field), Constant.of(element)); } + @BetaApi public static ArrayContainsAll arrayContainsAll(Expr expr, Expr... elements) { return new ArrayContainsAll(expr, Arrays.asList(elements)); } + @BetaApi public static ArrayContainsAll arrayContainsAll(Expr expr, Object... elements) { return new ArrayContainsAll( expr, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); } + @BetaApi public static ArrayContainsAll arrayContainsAll(String field, Expr... elements) { return new ArrayContainsAll(Field.of(field), Arrays.asList(elements)); } + @BetaApi public static ArrayContainsAll arrayContainsAll(String field, Object... elements) { return new ArrayContainsAll( Field.of(field), Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); } + @BetaApi public static ArrayContainsAny arrayContainsAny(Expr expr, Expr... elements) { return new ArrayContainsAny(expr, Arrays.asList(elements)); } + @BetaApi public static ArrayContainsAny arrayContainsAny(Expr expr, Object... elements) { return new ArrayContainsAny( expr, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); } + @BetaApi public static ArrayContainsAny arrayContainsAny(String field, Expr... elements) { return new ArrayContainsAny(Field.of(field), Arrays.asList(elements)); } + @BetaApi public static ArrayContainsAny arrayContainsAny(String field, Object... elements) { return new ArrayContainsAny( Field.of(field), Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); } + @BetaApi public static ArrayFilter arrayFilter(Expr expr, FilterCondition filter) { return new ArrayFilter(expr, filter); } + @BetaApi public static ArrayFilter arrayFilter(String field, FilterCondition filter) { return new ArrayFilter(Field.of(field), filter); } + @BetaApi public static ArrayLength arrayLength(Expr expr) { return new ArrayLength(expr); } + @BetaApi public static ArrayLength arrayLength(String field) { return new ArrayLength(Field.of(field)); } + @BetaApi public static ArrayTransform arrayTransform(Expr expr, Function transform) { return new ArrayTransform(expr, transform); } + @BetaApi public static ArrayTransform arrayTransform(String field, Function transform) { return new ArrayTransform(Field.of(field), transform); } + @BetaApi public static Length length(Expr expr) { return new Length(expr); } + @BetaApi public static Length length(String field) { return new Length(Field.of(field)); } + @BetaApi public static Like like(Expr expr, String pattern) { return new Like(expr, Constant.of(pattern)); } + @BetaApi public static Like like(String field, String pattern) { return new Like(Field.of(field), Constant.of(pattern)); } + @BetaApi public static RegexContains regexContains(Expr expr, String pattern) { return new RegexContains(expr, Constant.of(pattern)); } + @BetaApi public static RegexContains regexContains(String field, String pattern) { return new RegexContains(Field.of(field), Constant.of(pattern)); } + @BetaApi public static RegexMatch regexMatch(Expr expr, String pattern) { return new RegexMatch(expr, Constant.of(pattern)); } + @BetaApi public static RegexMatch regexMatch(String field, String pattern) { return new RegexMatch(Field.of(field), Constant.of(pattern)); } + @BetaApi public static StrConcat strConcat(Expr expr, Expr... elements) { return new StrConcat(expr, Arrays.asList(elements)); } + @BetaApi public static StrConcat strConcat(Expr expr, Object... elements) { return new StrConcat( expr, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); } + @BetaApi public static StrConcat strConcat(String field, Expr... elements) { return new StrConcat(Field.of(field), Arrays.asList(elements)); } + @BetaApi public static StrConcat strConcat(String field, Object... elements) { return new StrConcat( Field.of(field), Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); } + @BetaApi public static ToLowercase toLowercase(Expr expr) { return new ToLowercase(expr); } + @BetaApi public static ToLowercase toLowercase(String field) { return new ToLowercase(Field.of(field)); } + @BetaApi public static ToUppercase toUppercase(Expr expr) { return new ToUppercase(expr); } + @BetaApi public static ToUppercase toUppercase(String field) { return new ToUppercase(Field.of(field)); } + @BetaApi public static Trim trim(Expr expr) { return new Trim(expr); } + @BetaApi public static Trim trim(String field) { return new Trim(Field.of(field)); } + @BetaApi public static IsNaN isNaN(Expr expr) { return new IsNaN(expr); } + @BetaApi public static IsNaN isNaN(String field) { return new IsNaN(Field.of(field)); } + @BetaApi public static IsNull isNull(Expr expr) { return new IsNull(expr); } + @BetaApi public static IsNull isNull(String field) { return new IsNull(Field.of(field)); } + @BetaApi public static Not not(FilterCondition expr) { return new Not(expr); } + @BetaApi public static Sum sum(Expr expr) { return new Sum(expr, false); } + @BetaApi public static Sum sum(String field) { return new Sum(Field.of(field), false); } + @BetaApi public static Avg avg(Expr expr) { return new Avg(expr, false); } + @BetaApi public static Avg avg(String field) { return new Avg(Field.of(field), false); } + @BetaApi public static Min min(Expr expr) { return new Min(expr, false); // Corrected constructor call } + @BetaApi public static Min min(String field) { return new Min(Field.of(field), false); // Corrected constructor call } + @BetaApi public static Max max(Expr expr) { return new Max(expr, false); // Corrected constructor call } + @BetaApi public static Max max(String field) { return new Max(Field.of(field), false); // Corrected constructor call } + @BetaApi public static Count count(Expr expr) { return new Count(expr, false); } + @BetaApi public static Count count(String field) { return new Count(Field.of(field), false); } + @BetaApi public static CountIf countIf(FilterCondition condition) { return new CountIf(condition, false); } + @BetaApi public static Count countAll() { return new Count(null, false); } + @BetaApi public static CosineDistance cosineDistance(Expr expr, Expr other) { return new CosineDistance(expr, other); } + @BetaApi public static CosineDistance cosineDistance(Expr expr, double[] other) { return new CosineDistance(expr, Constant.ofVector(other)); } + @BetaApi public static CosineDistance cosineDistance(String field, Expr other) { return new CosineDistance(Field.of(field), other); } + @BetaApi public static CosineDistance cosineDistance(String field, double[] other) { return new CosineDistance(Field.of(field), Constant.ofVector(other)); } - // Typo in original code: dotProductDistance should return DotProductDistance objects + @BetaApi public static DotProductDistance dotProductDistance(Expr expr, Expr other) { return new DotProductDistance(expr, other); } + @BetaApi public static DotProductDistance dotProductDistance(Expr expr, double[] other) { return new DotProductDistance(expr, Constant.ofVector(other)); } + @BetaApi public static DotProductDistance dotProductDistance(String field, Expr other) { return new DotProductDistance(Field.of(field), other); } + @BetaApi public static DotProductDistance dotProductDistance(String field, double[] other) { return new DotProductDistance(Field.of(field), Constant.ofVector(other)); } + @BetaApi public static EuclideanDistance euclideanDistance(Expr expr, Expr other) { return new EuclideanDistance(expr, other); } + @BetaApi public static EuclideanDistance euclideanDistance(Expr expr, double[] other) { return new EuclideanDistance(expr, Constant.ofVector(other)); } + @BetaApi public static EuclideanDistance euclideanDistance(String field, Expr other) { return new EuclideanDistance(Field.of(field), other); } + @BetaApi public static EuclideanDistance euclideanDistance(String field, double[] other) { return new EuclideanDistance(Field.of(field), Constant.ofVector(other)); } + @BetaApi public static ArrayElement arrayElement() { return new ArrayElement(); } + @BetaApi public static Function function(String name, List params) { return new Function(name, params); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Gt.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Gt.java index 6e81c4bb5..94fa72715 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Gt.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Gt.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Gt extends Function implements FilterCondition { + @InternalApi Gt(Expr left, Expr right) { super("gt", Lists.newArrayList(left, right)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Gte.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Gte.java index bca7689ee..763b376c0 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Gte.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Gte.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Gte extends Function implements FilterCondition { + @InternalApi Gte(Expr left, Expr right) { super("gte", Lists.newArrayList(left, right)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/If.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/If.java index 8c7a35d11..ba48a4afe 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/If.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/If.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class If extends Function implements FilterCondition { + @InternalApi If(FilterCondition condition, Expr trueExpr, Expr falseExpr) { super("if", Lists.newArrayList(condition, trueExpr, falseExpr)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/In.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/In.java index 043939b52..6d5f4559f 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/In.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/In.java @@ -1,9 +1,13 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; import java.util.List; +@BetaApi public final class In extends Function implements FilterCondition { + @InternalApi In(Expr left, List others) { super("in", Lists.newArrayList(left, new ListOfExprs(others))); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/IsNaN.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/IsNaN.java index 7db82b161..39216b0a2 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/IsNaN.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/IsNaN.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class IsNaN extends Function implements FilterCondition { + @InternalApi IsNaN(Expr value) { super("is_nan", Lists.newArrayList(value)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/IsNull.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/IsNull.java index 60f3cebf1..a84023223 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/IsNull.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/IsNull.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class IsNull extends Function implements FilterCondition { + @InternalApi IsNull(Expr value) { super("is_null", Lists.newArrayList(value)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Length.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Length.java index a82f10452..cf410a558 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Length.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Length.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Length extends Function { + @InternalApi Length(Expr expr) { super("length", Lists.newArrayList(expr)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Like.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Like.java index 1c9d1f87e..8476f9cca 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Like.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Like.java @@ -1,8 +1,10 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Like extends Function implements FilterCondition { @InternalApi Like(Expr expr, Expr pattern) { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ListOfExprs.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ListOfExprs.java index f444a7c5d..c52810b98 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ListOfExprs.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ListOfExprs.java @@ -13,6 +13,7 @@ public final class ListOfExprs implements Expr { this.conditions = ImmutableList.copyOf(list); } + @InternalApi public List getConditions() { return conditions; } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Lt.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Lt.java index 86d2e4a34..d07078cf9 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Lt.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Lt.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Lt extends Function implements FilterCondition { + @InternalApi Lt(Expr left, Expr right) { super("lt", Lists.newArrayList(left, right)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Lte.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Lte.java index a0c8d1ae7..4e0416379 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Lte.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Lte.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Lte extends Function implements FilterCondition { + @InternalApi Lte(Expr left, Expr right) { super("lte", Lists.newArrayList(left, right)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/MapGet.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/MapGet.java index 98a1c09f6..eab5163e3 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/MapGet.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/MapGet.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class MapGet extends Function { + @InternalApi MapGet(Expr map, String name) { super("map_get", Lists.newArrayList(map, Constant.of(name))); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Max.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Max.java index 4c3fa9ad9..e15b6548a 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Max.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Max.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Max extends Function implements Accumulator { + @InternalApi Max(Expr value, boolean distinct) { super("max", Lists.newArrayList(value)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Min.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Min.java index 933574626..fe3443c3a 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Min.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Min.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Min extends Function implements Accumulator { + @InternalApi Min(Expr value, boolean distinct) { super("min", Lists.newArrayList(value)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Multiply.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Multiply.java index 003861fc5..c353385e8 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Multiply.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Multiply.java @@ -1,8 +1,10 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Multiply extends Function { @InternalApi Multiply(Expr left, Expr right) { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Neq.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Neq.java index 86a91a058..39e2ca042 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Neq.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Neq.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Neq extends Function implements FilterCondition { + @InternalApi Neq(Expr left, Expr right) { super("neq", Lists.newArrayList(left, right)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Not.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Not.java index 04feb0132..0d8afb3e6 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Not.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Not.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Not extends Function implements FilterCondition { + @InternalApi Not(Expr condition) { super("not", Lists.newArrayList(condition)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Or.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Or.java index 1ece0bef9..e99628a58 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Or.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Or.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import java.util.List; +@BetaApi public final class Or extends Function implements FilterCondition { + @InternalApi Or(List conditions) { super("or", conditions); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Ordering.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Ordering.java index 307eafc22..3232ed725 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Ordering.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Ordering.java @@ -2,11 +2,13 @@ import static com.google.cloud.firestore.PipelineUtils.encodeValue; +import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.firestore.v1.MapValue; import com.google.firestore.v1.Value; import java.util.Locale; +@BetaApi public final class Ordering { private final Expr expr; @@ -17,6 +19,7 @@ private Ordering(Expr expr, Ordering.Direction dir) { this.dir = dir; } + @BetaApi public enum Direction { ASCENDING, DESCENDING; @@ -38,27 +41,32 @@ public Value toProto() { .build(); } + @BetaApi public static Ordering of(Expr expr, Ordering.Direction dir) { return new Ordering(expr, dir); } + @BetaApi public static Ordering of(Expr expr) { return new Ordering(expr, Direction.ASCENDING); } + @BetaApi public static Ordering ascending(Expr expr) { return new Ordering(expr, Direction.ASCENDING); } + @BetaApi public static Ordering descending(Expr expr) { return new Ordering(expr, Direction.DESCENDING); } - // Getters + @InternalApi public Expr getExpr() { return expr; } + @InternalApi public Ordering.Direction getDir() { return dir; } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Parent.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Parent.java index 0168047a7..3dfa5d752 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Parent.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Parent.java @@ -1,8 +1,10 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Parent extends Function { @InternalApi diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/RegexContains.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/RegexContains.java index ac0fcfa7e..a441be091 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/RegexContains.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/RegexContains.java @@ -1,8 +1,10 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class RegexContains extends Function implements FilterCondition { @InternalApi RegexContains(Expr expr, Expr regex) { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/RegexMatch.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/RegexMatch.java index b01476644..c5221335f 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/RegexMatch.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/RegexMatch.java @@ -1,8 +1,10 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class RegexMatch extends Function implements FilterCondition { @InternalApi RegexMatch(Expr expr, Expr regex) { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Selectable.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Selectable.java index 1eba7fc80..0afbbd434 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Selectable.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Selectable.java @@ -1,3 +1,6 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; + +@BetaApi public interface Selectable {} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/StrConcat.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/StrConcat.java index 5d1a80e08..fa7212988 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/StrConcat.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/StrConcat.java @@ -1,9 +1,13 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; import java.util.List; +@BetaApi public final class StrConcat extends Function { + @InternalApi StrConcat(Expr first, List exprs) { super("str_concat", Lists.newArrayList(first, new ListOfExprs(exprs))); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Subtract.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Subtract.java index 15e513103..ceb353bad 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Subtract.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Subtract.java @@ -1,8 +1,10 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Subtract extends Function { @InternalApi Subtract(Expr left, Expr right) { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Sum.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Sum.java index 7b700205e..df016d9f7 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Sum.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Sum.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Sum extends Function implements Accumulator { + @InternalApi Sum(Expr value, boolean distinct) { super("sum", Lists.newArrayList(value)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToLowercase.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToLowercase.java index e4e6c29ac..0e07aa469 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToLowercase.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToLowercase.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class ToLowercase extends Function { + @InternalApi ToLowercase(Expr expr) { super("to_lowercase", Lists.newArrayList(expr)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToUppercase.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToUppercase.java index 3d3cdab8b..06105f1d2 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToUppercase.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToUppercase.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class ToUppercase extends Function { + @InternalApi ToUppercase(Expr expr) { super("to_uppercase", Lists.newArrayList(expr)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Trim.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Trim.java index 37fa9e372..fe4d461d1 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Trim.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Trim.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.common.collect.Lists; +@BetaApi public final class Trim extends Function { + @InternalApi Trim(Expr expr) { super("trim", Lists.newArrayList(expr)); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Xor.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Xor.java index 01a698d56..5dd5b77bc 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Xor.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Xor.java @@ -1,8 +1,12 @@ package com.google.cloud.firestore.pipeline.expressions; +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import java.util.List; +@BetaApi public final class Xor extends Function implements FilterCondition { + @InternalApi Xor(List conditions) { super("xor", conditions); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/AddFields.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/AddFields.java index fe2c0d335..01b55c8f1 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/AddFields.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/AddFields.java @@ -15,6 +15,7 @@ public AddFields(Map fields) { this.fields = fields; } + @InternalApi public Map getFields() { return fields; } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java index 817536289..6d56fd4c8 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java @@ -2,7 +2,7 @@ import com.google.api.core.InternalApi; import com.google.cloud.firestore.pipeline.expressions.Accumulator; -import com.google.cloud.firestore.pipeline.expressions.AggregatorTarget; +import com.google.cloud.firestore.pipeline.expressions.AccumulatorTarget; import com.google.cloud.firestore.pipeline.expressions.Expr; import java.util.Arrays; import java.util.Collections; @@ -23,19 +23,21 @@ public final class Aggregate implements Stage { } @InternalApi - public Aggregate(AggregatorTarget... aggregators) { + public Aggregate(AccumulatorTarget... aggregators) { this( Collections.emptyMap(), Arrays.stream(aggregators) .collect( Collectors.toMap( - AggregatorTarget::getFieldName, AggregatorTarget::getAccumulator))); + AccumulatorTarget::getFieldName, AccumulatorTarget::getAccumulator))); } + @InternalApi public Map getGroups() { return groups; } + @InternalApi public Map getAccumulators() { return accumulators; } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Collection.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Collection.java index c876c2ac0..3f9e2889f 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Collection.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Collection.java @@ -18,6 +18,7 @@ public Collection(@Nonnull String path) { } } + @InternalApi public String getPath() { return path; } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/CollectionGroup.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/CollectionGroup.java index cd1789a80..c6b2c0b67 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/CollectionGroup.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/CollectionGroup.java @@ -13,6 +13,7 @@ public CollectionGroup(String collectionId) { this.collectionId = collectionId; } + @InternalApi public String getCollectionId() { return collectionId; } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Documents.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Documents.java index be05c6578..8c6b24591 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Documents.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Documents.java @@ -17,11 +17,13 @@ public final class Documents implements Stage { this.documents = documents; } + @InternalApi public static Documents of(DocumentReference... documents) { return new Documents( Arrays.stream(documents).map(doc -> "/" + doc.getPath()).collect(Collectors.toList())); } + @InternalApi public List getDocuments() { return documents; } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/FindNearest.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/FindNearest.java index cdf872a8c..a83ec2055 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/FindNearest.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/FindNearest.java @@ -3,7 +3,6 @@ import com.google.api.core.InternalApi; import com.google.cloud.firestore.pipeline.expressions.Field; -@InternalApi public final class FindNearest implements Stage { private static final String name = "find_nearest"; @@ -19,18 +18,22 @@ public FindNearest(Field property, double[] vector, FindNearest.FindNearestOptio } @Override + @InternalApi public String getName() { return name; } + @InternalApi public Field getProperty() { return property; } + @InternalApi public double[] getVector() { return vector; } + @InternalApi public FindNearestOptions getOptions() { return options; } @@ -67,6 +70,7 @@ static FindNearest.DistanceMeasure generic(String name) { static class EuclideanDistanceMeasure implements FindNearest.DistanceMeasure { @Override + @InternalApi public String toProtoString() { return "euclidean"; } @@ -75,6 +79,7 @@ public String toProtoString() { static class CosineDistanceMeasure implements FindNearest.DistanceMeasure { @Override + @InternalApi public String toProtoString() { return "cosine"; } @@ -83,6 +88,7 @@ public String toProtoString() { static class DotProductDistanceMeasure implements FindNearest.DistanceMeasure { @Override + @InternalApi public String toProtoString() { return "dot_product"; } @@ -97,6 +103,7 @@ public GenericDistanceMeasure(String name) { } @Override + @InternalApi public String toProtoString() { return name; } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/GenericStage.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/GenericStage.java index 33d677db1..6910a87cf 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/GenericStage.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/GenericStage.java @@ -16,6 +16,7 @@ public GenericStage(String name, List params) { } @Override + @InternalApi public String getName() { return name; } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Limit.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Limit.java index b7021b494..b0230ac13 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Limit.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Limit.java @@ -13,11 +13,13 @@ public Limit(int limit) { this.limit = limit; } + @InternalApi public int getLimit() { return limit; } @Override + @InternalApi public String getName() { return name; } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Offset.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Offset.java index e6350bf9b..eeaf2a21e 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Offset.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Offset.java @@ -13,11 +13,13 @@ public Offset(int offset) { this.offset = offset; } + @InternalApi public int getOffset() { return offset; } @Override + @InternalApi public String getName() { return name; } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Select.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Select.java index b34d66dcc..20531a78a 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Select.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Select.java @@ -15,11 +15,13 @@ public Select(Map projections) { this.projections = projections; } + @InternalApi public Map getProjections() { return projections; } @Override + @InternalApi public String getName() { return name; } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Sort.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Sort.java index 3cec1a214..d746e5972 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Sort.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Sort.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Locale; -@InternalApi public final class Sort implements Stage { private static final String name = "sort"; @@ -20,15 +19,17 @@ public Sort(List orders, Sort.Density density, Sort.Truncation truncat this.truncation = truncation; } - // Getters + @InternalApi public String getName() { return name; } + @InternalApi public List getOrders() { return orders; } + @InternalApi public Sort.Density getDensity() { if (density != null) { return density; @@ -36,6 +37,7 @@ public Sort.Density getDensity() { return Density.UNSPECIFIED; } + @InternalApi public Sort.Truncation getTruncation() { if (truncation != null) { return truncation; diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Where.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Where.java index 7befd7a60..a268c99c6 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Where.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Where.java @@ -14,6 +14,7 @@ public Where(FilterCondition condition) { this.condition = condition; } + @InternalApi public FilterCondition getCondition() { return condition; } From 593d39eba5f9bed1c9b8311e23361c96246ed86f Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Thu, 18 Jul 2024 14:58:23 -0400 Subject: [PATCH 52/65] executions, group bys, etc. --- .../google/cloud/firestore/FirestoreImpl.java | 2 +- .../com/google/cloud/firestore/Pipeline.java | 84 ++++----- .../cloud/firestore/PipelineSource.java | 15 +- .../google/cloud/firestore/PipelineUtils.java | 44 ++++- .../com/google/cloud/firestore/Query.java | 4 +- .../pipeline/expressions/Accumulator.java | 3 +- .../firestore/pipeline/expressions/Expr.java | 2 +- .../firestore/pipeline/stages/Aggregate.java | 48 +++-- .../cloud/firestore/it/ITPipelineTest.java | 165 +++++++++++------- .../firestore/it/ITQueryAggregationsTest.java | 2 +- .../cloud/firestore/it/ITQueryTest.java | 6 +- 11 files changed, 234 insertions(+), 141 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java index 279347d42..1290301e4 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java @@ -390,7 +390,7 @@ public CollectionGroup collectionGroup(@Nonnull final String collectionId) { @Override @BetaApi public PipelineSource pipeline() { - return new PipelineSource(); + return new PipelineSource(this); } @Nonnull diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java index a73ea3b1c..7a609030f 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java @@ -10,10 +10,7 @@ import com.google.cloud.Timestamp; import com.google.cloud.firestore.pipeline.PaginatingPipeline; import com.google.cloud.firestore.pipeline.expressions.AccumulatorTarget; -import com.google.cloud.firestore.pipeline.expressions.Expr; -import com.google.cloud.firestore.pipeline.expressions.ExprWithAlias; import com.google.cloud.firestore.pipeline.expressions.Field; -import com.google.cloud.firestore.pipeline.expressions.Fields; import com.google.cloud.firestore.pipeline.expressions.FilterCondition; import com.google.cloud.firestore.pipeline.expressions.Ordering; import com.google.cloud.firestore.pipeline.expressions.Selectable; @@ -44,7 +41,6 @@ import io.opencensus.trace.Tracing; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; @@ -86,106 +82,93 @@ @BetaApi public final class Pipeline { private final ImmutableList stages; + private final Firestore db; - private Pipeline(List stages) { + private Pipeline(Firestore db, List stages) { + this.db = db; this.stages = ImmutableList.copyOf(stages); } - Pipeline(Collection collection) { - this(Lists.newArrayList(collection)); + Pipeline(Firestore db, Collection collection) { + this(db, Lists.newArrayList(collection)); } - Pipeline(CollectionGroup group) { - this(Lists.newArrayList(group)); + Pipeline(Firestore db, CollectionGroup group) { + this(db, Lists.newArrayList(group)); } - Pipeline(Database db) { - this(Lists.newArrayList(db)); + Pipeline(Firestore firestore, Database db) { + this(firestore, Lists.newArrayList(db)); } - Pipeline(Documents docs) { - this(Lists.newArrayList(docs)); - } - - private Map projectablesToMap(Selectable... selectables) { - Map projMap = new HashMap<>(); - for (Selectable proj : selectables) { - if (proj instanceof Field) { - Field fieldProj = (Field) proj; - projMap.put(fieldProj.getPath().getEncodedPath(), fieldProj); - } else if (proj instanceof AccumulatorTarget) { - AccumulatorTarget aggregatorProj = (AccumulatorTarget) proj; - projMap.put(aggregatorProj.getFieldName(), aggregatorProj.getAccumulator()); - } else if (proj instanceof Fields) { - Fields fieldsProj = (Fields) proj; - if (fieldsProj.getFields() != null) { - fieldsProj.getFields().forEach(f -> projMap.put(f.getPath().getEncodedPath(), f)); - } - } else if (proj instanceof ExprWithAlias) { - ExprWithAlias exprWithAlias = (ExprWithAlias) proj; - projMap.put(exprWithAlias.getAlias(), exprWithAlias.getExpr()); - } - } - return projMap; - } - - private Map fieldNamesToMap(String... fields) { - Map projMap = new HashMap<>(); - for (String field : fields) { - projMap.put(field, Field.of(field)); - } - return projMap; + Pipeline(Firestore db, Documents docs) { + this(db, Lists.newArrayList(docs)); } @BetaApi public Pipeline addFields(Selectable... fields) { return new Pipeline( + this.db, ImmutableList.builder() .addAll(stages) - .add(new AddFields(projectablesToMap(fields))) + .add(new AddFields(PipelineUtils.selectablesToMap(fields))) .build()); } @BetaApi public Pipeline select(Selectable... projections) { return new Pipeline( + this.db, ImmutableList.builder() .addAll(stages) - .add(new Select(projectablesToMap(projections))) + .add(new Select(PipelineUtils.selectablesToMap(projections))) .build()); } @BetaApi public Pipeline select(String... fields) { return new Pipeline( + this.db, ImmutableList.builder() .addAll(stages) - .add(new Select(fieldNamesToMap(fields))) + .add(new Select(PipelineUtils.fieldNamesToMap(fields))) .build()); } @BetaApi public Pipeline where(FilterCondition condition) { return new Pipeline( + this.db, ImmutableList.builder().addAll(stages).add(new Where(condition)).build()); } @BetaApi public Pipeline offset(int offset) { return new Pipeline( + this.db, ImmutableList.builder().addAll(stages).add(new Offset(offset)).build()); } @BetaApi public Pipeline limit(int limit) { return new Pipeline( + this.db, ImmutableList.builder().addAll(stages).add(new Limit(limit)).build()); } @BetaApi public Pipeline aggregate(AccumulatorTarget... aggregators) { return new Pipeline( - ImmutableList.builder().addAll(stages).add(new Aggregate(aggregators)).build()); + this.db, + ImmutableList.builder().addAll(stages).add(Aggregate.newInstance().withAccumulators(aggregators)).build()); + } + + @BetaApi + public Pipeline aggregate(Aggregate aggregate) { + return new Pipeline( + this.db, + ImmutableList.builder().addAll(stages) + .add(aggregate).build()); } @BetaApi @@ -199,6 +182,7 @@ public Pipeline findNearest( Field property, double[] vector, FindNearest.FindNearestOptions options) { // Implementation for findNearest (add the FindNearest stage if needed) return new Pipeline( + this.db, ImmutableList.builder() .addAll(stages) .add( @@ -210,6 +194,7 @@ public Pipeline findNearest( @BetaApi public Pipeline sort(List orders, Sort.Density density, Sort.Truncation truncation) { return new Pipeline( + this.db, ImmutableList.builder() .addAll(stages) .add(new Sort(orders, density, truncation)) @@ -231,6 +216,7 @@ public PaginatingPipeline paginate(int pageSize, Ordering... orders) { public Pipeline genericStage(String name, Map params) { // Implementation for genericStage (add the GenericStage if needed) return new Pipeline( + this.db, ImmutableList.builder() .addAll(stages) .add( @@ -242,7 +228,7 @@ public Pipeline genericStage(String name, Map params) { } @BetaApi - public ApiFuture> execute(Firestore db) { + public ApiFuture> execute() { if (db instanceof FirestoreImpl) { FirestoreImpl firestoreImpl = (FirestoreImpl) db; Value pipelineValue = toProto(); @@ -287,7 +273,7 @@ public void onError(Throwable t) { } @BetaApi - public void execute(Firestore db, ApiStreamObserver observer) { + public void execute(ApiStreamObserver observer) { if (db instanceof FirestoreImpl) { FirestoreImpl firestoreImpl = (FirestoreImpl) db; Value pipelineValue = toProto(); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java index 5f4a7a67d..9b5cb9018 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java @@ -1,6 +1,7 @@ package com.google.cloud.firestore; import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.cloud.firestore.pipeline.stages.Collection; import com.google.cloud.firestore.pipeline.stages.CollectionGroup; import com.google.cloud.firestore.pipeline.stages.Database; @@ -10,11 +11,17 @@ @BetaApi public class PipelineSource { + private final Firestore db; + + @InternalApi + PipelineSource(Firestore db){ + this.db = db; + } @Nonnull @BetaApi public Pipeline collection(@Nonnull String path) { - return new Pipeline(new Collection(path)); + return new Pipeline(this.db,new Collection(path)); } @Nonnull @@ -24,18 +31,18 @@ public Pipeline collectionGroup(@Nonnull String collectionId) { !collectionId.contains("/"), "Invalid collectionId '%s'. Collection IDs must not contain '/'.", collectionId); - return new Pipeline(new CollectionGroup(collectionId)); + return new Pipeline(this.db, new CollectionGroup(collectionId)); } @Nonnull @BetaApi public Pipeline database() { - return new Pipeline(new Database()); + return new Pipeline(this.db, new Database()); } @Nonnull @BetaApi public Pipeline documents(DocumentReference... docs) { - return new Pipeline(Documents.of(docs)); + return new Pipeline(this.db, Documents.of(docs)); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java index 83b5d7cdc..a4bf5a2db 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java @@ -15,12 +15,18 @@ import com.google.cloud.firestore.Query.UnaryFilterInternal; import com.google.cloud.firestore.pipeline.PaginatingPipeline; import com.google.cloud.firestore.pipeline.expressions.AccumulatorTarget; +import com.google.cloud.firestore.pipeline.expressions.Expr; +import com.google.cloud.firestore.pipeline.expressions.ExprWithAlias; import com.google.cloud.firestore.pipeline.expressions.Field; +import com.google.cloud.firestore.pipeline.expressions.Fields; import com.google.cloud.firestore.pipeline.expressions.FilterCondition; +import com.google.cloud.firestore.pipeline.expressions.Selectable; import com.google.common.collect.Lists; import com.google.firestore.v1.Cursor; import com.google.firestore.v1.Value; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; @InternalApi @@ -158,15 +164,47 @@ static AccumulatorTarget toPipelineAggregatorTarget(AggregateField f) { switch (operator) { case "sum": - return Field.of(fieldPath).sum().toField(f.getAlias()); + return Field.of(fieldPath).sum().as(f.getAlias()); case "count": - return countAll().toField(f.getAlias()); + return countAll().as(f.getAlias()); case "average": - return Field.of(fieldPath).avg().toField(f.getAlias()); + return Field.of(fieldPath).avg().as(f.getAlias()); default: // Handle the 'else' case appropriately in your Java code throw new IllegalArgumentException("Unsupported operator: " + operator); } } + + @InternalApi + public static Map selectablesToMap(Selectable... selectables) { + Map projMap = new HashMap<>(); + for (Selectable proj : selectables) { + if (proj instanceof Field) { + Field fieldProj = (Field) proj; + projMap.put(fieldProj.getPath().getEncodedPath(), fieldProj); + } else if (proj instanceof AccumulatorTarget) { + AccumulatorTarget aggregatorProj = (AccumulatorTarget) proj; + projMap.put(aggregatorProj.getFieldName(), aggregatorProj.getAccumulator()); + } else if (proj instanceof Fields) { + Fields fieldsProj = (Fields) proj; + if (fieldsProj.getFields() != null) { + fieldsProj.getFields().forEach(f -> projMap.put(f.getPath().getEncodedPath(), f)); + } + } else if (proj instanceof ExprWithAlias) { + ExprWithAlias exprWithAlias = (ExprWithAlias) proj; + projMap.put(exprWithAlias.getAlias(), exprWithAlias.getExpr()); + } + } + return projMap; + } + + @InternalApi + public static Map fieldNamesToMap(String... fields) { + Map projMap = new HashMap<>(); + for (String field : fields) { + projMap.put(field, Field.of(field)); + } + return projMap; + } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index 32b8d8bdd..933ed50db 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -2128,8 +2128,8 @@ public Pipeline pipeline() { // From Pipeline ppl = this.options.getAllDescendants() - ? new PipelineSource().collectionGroup(this.options.getCollectionId()) - : new PipelineSource() + ? new PipelineSource(this.getFirestore()).collectionGroup(this.options.getCollectionId()) + : new PipelineSource(this.getFirestore()) .collection( this.options.getParentPath().append(this.options.getCollectionId()).getPath()); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Accumulator.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Accumulator.java index d663a86e5..c2041d8f4 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Accumulator.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Accumulator.java @@ -5,7 +5,8 @@ @BetaApi public interface Accumulator extends Expr { @BetaApi - default AccumulatorTarget toField(String fieldName) { + @Override + default AccumulatorTarget as(String fieldName) { return new AccumulatorTarget(this, fieldName, false); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java index b2012ae91..016ecc59b 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java @@ -300,7 +300,7 @@ default Ordering descending() { } @BetaApi - default Selectable asAlias(String alias) { + default Selectable as(String alias) { return new ExprWithAlias(this, alias); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java index 6d56fd4c8..e47611efb 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java @@ -1,44 +1,62 @@ package com.google.cloud.firestore.pipeline.stages; +import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; +import com.google.cloud.firestore.PipelineUtils; import com.google.cloud.firestore.pipeline.expressions.Accumulator; import com.google.cloud.firestore.pipeline.expressions.AccumulatorTarget; import com.google.cloud.firestore.pipeline.expressions.Expr; +import com.google.cloud.firestore.pipeline.expressions.Selectable; import java.util.Arrays; import java.util.Collections; import java.util.Map; import java.util.stream.Collectors; -@InternalApi +@BetaApi public final class Aggregate implements Stage { private static final String name = "aggregate"; private final Map groups; private final Map accumulators; - @InternalApi - Aggregate(Map groups, Map accumulators) { - this.groups = groups; - this.accumulators = accumulators; + @BetaApi + public static Aggregate newInstance(){ + return new Aggregate(Collections.emptyMap(), Collections.emptyMap()); } - @InternalApi - public Aggregate(AccumulatorTarget... aggregators) { - this( - Collections.emptyMap(), - Arrays.stream(aggregators) - .collect( - Collectors.toMap( - AccumulatorTarget::getFieldName, AccumulatorTarget::getAccumulator))); + @BetaApi + public Aggregate withGroups(String... fields){ + return new Aggregate( + PipelineUtils.fieldNamesToMap(fields), + this.accumulators); + } + + @BetaApi + public Aggregate withGroups(Selectable... selectables){ + return new Aggregate( + PipelineUtils.selectablesToMap(selectables), this.accumulators); + } + + @BetaApi + public Aggregate withAccumulators(AccumulatorTarget... aggregators){ + return new Aggregate(this.groups, Arrays.stream(aggregators) + .collect( + Collectors.toMap( + AccumulatorTarget::getFieldName, AccumulatorTarget::getAccumulator))); + } + + private Aggregate(Map groups, Map accumulators) { + this.groups = groups; + this.accumulators = accumulators; } @InternalApi - public Map getGroups() { + Map getGroups() { return groups; } @InternalApi - public Map getAccumulators() { + Map getAccumulators() { return accumulators; } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 6f3494895..b74e953dd 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -49,6 +49,7 @@ import com.google.cloud.firestore.pipeline.expressions.Constant; import com.google.cloud.firestore.pipeline.expressions.Field; import com.google.cloud.firestore.pipeline.expressions.Function; +import com.google.cloud.firestore.pipeline.stages.Aggregate; import com.google.common.collect.Lists; import java.util.List; import java.util.Map; @@ -250,13 +251,13 @@ public void setup() throws Exception { } @Test - public void fromCollectionThenAggregate() throws Exception { + public void testAggregates() throws Exception { List results = firestore .pipeline() .collection(collection.getPath()) - .aggregate(countAll().toField("count")) - .execute(firestore) + .aggregate(countAll().as("count")) + .execute() .get(); assertThat(data(results)).isEqualTo(Lists.newArrayList(map("count", 10L))); @@ -265,25 +266,67 @@ public void fromCollectionThenAggregate() throws Exception { .pipeline() .where(eq("genre", "Science Fiction")) .aggregate( - countAll().toField("count"), - avg("rating").toField("avg_rating"), - Field.of("rating").max().toField("max_rating")) - .execute(firestore) + countAll().as("count"), + avg("rating").as("avg_rating"), + Field.of("rating").max().as("max_rating")) + .execute() .get(); assertThat(data(results)) .isEqualTo(Lists.newArrayList(map("count", 2L, "avg_rating", 4.4, "max_rating", 4.6))); } + @Test + public void testGroupBys() throws Exception { + List results = + collection + .pipeline() + .where(lt("published", 1900)) + .aggregate( + Aggregate + .newInstance() + .withGroups("genre")) + .execute() + .get(); + assertThat(data(results)) + .containsExactly( + map("genre", "Romance"), + map("genre", "Psychological Thriller") + ); + } + + @Test + public void testGroupBysAndAggregate() throws Exception { + List results = + collection + .pipeline() + .where(lt("published", 1984)) + .aggregate( + Aggregate + .newInstance() + .withGroups("genre") + .withAccumulators(avg("rating").as("avg_rating")) + ) + .where(gt("avg_rating", 4.3)) + .execute() + .get(); + assertThat(data(results)) + .containsExactly( + map("avg_rating", 4.7, "genre", "Fantasy"), + map("avg_rating", 4.5, "genre", "Romance"), + map("avg_rating", 4.4, "genre", "Science Fiction") + ); + } + @Test public void testMinMax() throws Exception { List results = collection .pipeline() .aggregate( - countAll().toField("count"), - Field.of("rating").max().toField("max_rating"), - Field.of("published").min().toField("min_published")) - .execute(firestore) + countAll().as("count"), + Field.of("rating").max().as("max_rating"), + Field.of("published").min().as("min_published")) + .execute() .get(); assertThat(data(results)) .isEqualTo( @@ -301,7 +344,7 @@ public void selectSpecificFields() throws Exception { .pipeline() .select("title", "author") .sort(Field.of("author").ascending()) - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -325,7 +368,7 @@ public void whereByMultipleConditions() throws Exception { collection .pipeline() .where(and(gt("rating", 4.5), eq("genre", "Science Fiction"))) - .execute(firestore) + .execute() .get(); // It's Dune @@ -341,7 +384,7 @@ public void whereByOrCondition() throws Exception { .pipeline() .where(or(eq("genre", "Romance"), eq("genre", "Dystopian"))) .select("title") - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -361,7 +404,7 @@ public void testPipelineWithOffsetAndLimit() throws Exception { .offset(5) .limit(3) .select("title", "author") - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -375,7 +418,7 @@ public void testPipelineWithOffsetAndLimit() throws Exception { @Test public void testArrayContains() throws Exception { List results = - collection.pipeline().where(arrayContains("tags", "comedy")).execute(firestore).get(); + collection.pipeline().where(arrayContains("tags", "comedy")).execute().get(); assertThat(data(results)) // The Hitchhiker's Guide to the Galaxy .isEqualTo(Lists.newArrayList(collection.document("book1").get().get().getData())); @@ -388,7 +431,7 @@ public void testArrayContainsAny() throws Exception { .pipeline() .where(arrayContainsAny("tags", "comedy", "classic")) .select("title") - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -404,7 +447,7 @@ public void testArrayContainsAll() throws Exception { collection .pipeline() .where(arrayContainsAll("tags", "adventure", "magic")) - .execute(firestore) + .execute() .get(); assertThat(data(results)).isEqualTo(Lists.newArrayList(map("title", "The Lord of the Rings"))); @@ -415,9 +458,9 @@ public void testArrayLength() throws Exception { List results = collection .pipeline() - .select(Field.of("tags").arrayLength().asAlias("tagsCount")) + .select(Field.of("tags").arrayLength().as("tagsCount")) .where(eq("tagsCount", 3)) - .execute(firestore) + .execute() .get(); // All documents have 3 tags in the test dataset @@ -429,9 +472,9 @@ public void testArrayConcat() throws Exception { List results = collection .pipeline() - .select(Field.of("tags").arrayConcat("newTag1", "newTag2").asAlias("modifiedTags")) + .select(Field.of("tags").arrayConcat("newTag1", "newTag2").as("modifiedTags")) .limit(1) - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -449,9 +492,9 @@ public void testArrayFilter() throws Exception { .pipeline() .select( arrayFilter(Field.of("tags"), Function.eq(arrayElement(), "")) - .asAlias("filteredTags")) + .as("filteredTags")) .limit(1) - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -467,9 +510,9 @@ public void testArrayTransform() throws Exception { .pipeline() .select( arrayTransform(Field.of("tags"), strConcat(arrayElement(), "transformed")) - .asAlias("transformedTags")) + .as("transformedTags")) .limit(1) - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -486,9 +529,9 @@ public void testStrConcat() throws Exception { List results = collection .pipeline() - .select(strConcat(Field.of("author"), " - ", Field.of("title")).asAlias("bookInfo")) + .select(strConcat(Field.of("author"), " - ", Field.of("title")).as("bookInfo")) .limit(1) - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -502,9 +545,9 @@ public void testLength() throws Exception { List results = collection .pipeline() - .select(Field.of("title").length().asAlias("titleLength"), Field.of("title")) + .select(Field.of("title").length().as("titleLength"), Field.of("title")) .where(gt("titleLength", 20)) - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -516,9 +559,9 @@ public void testToLowercase() throws Exception { List results = collection .pipeline() - .select(Field.of("title").toLowercase().asAlias("lowercaseTitle")) + .select(Field.of("title").toLowercase().as("lowercaseTitle")) .limit(1) - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -531,9 +574,9 @@ public void testToUppercase() throws Exception { List results = collection .pipeline() - .select(Field.of("author").toUppercase().asAlias("uppercaseAuthor")) + .select(Field.of("author").toUppercase().as("uppercaseAuthor")) .limit(1) - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -547,10 +590,10 @@ public void testTrim() throws Exception { .pipeline() .addFields( strConcat(Constant.of(" "), Field.of("title"), Constant.of(" ")) - .asAlias("spacedTitle")) - .select(Field.of("spacedTitle").trim().asAlias("trimmedTitle"), Field.of("spacedTitle")) + .as("spacedTitle")) + .select(Field.of("spacedTitle").trim().as("trimmedTitle"), Field.of("spacedTitle")) .limit(1) - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -568,7 +611,7 @@ public void testLike() throws Exception { .pipeline() .where(Field.of("title").like("%Guide%")) .select("title") - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -582,7 +625,7 @@ public void testRegexContains() throws Exception { collection .pipeline() .where(Field.of("title").regexContains("(?i)(the|of)")) - .execute(firestore) + .execute() .get(); assertThat(data(results)).hasSize(5); @@ -595,7 +638,7 @@ public void testRegexMatches() throws Exception { collection .pipeline() .where(Function.regexMatch("title", ".*(?i)(the|of).*")) - .execute(firestore) + .execute() .get(); assertThat(data(results)).hasSize(5); @@ -607,12 +650,12 @@ public void testArithmeticOperations() throws Exception { collection .pipeline() .select( - add(Field.of("rating"), 1).asAlias("ratingPlusOne"), - subtract(Field.of("published"), 1900).asAlias("yearsSince1900"), - Field.of("rating").multiply(10).asAlias("ratingTimesTen"), - Field.of("rating").divide(2).asAlias("ratingDividedByTwo")) + add(Field.of("rating"), 1).as("ratingPlusOne"), + subtract(Field.of("published"), 1900).as("yearsSince1900"), + Field.of("rating").multiply(10).as("ratingTimesTen"), + Field.of("rating").divide(2).as("ratingDividedByTwo")) .limit(1) - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -641,7 +684,7 @@ public void testComparisonOperators() throws Exception { neq("genre", "Science Fiction"))) .select("rating", "title") .sort(Field.of("title").ascending()) - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -661,7 +704,7 @@ public void testLogicalOperators() throws Exception { or(and(gt("rating", 4.5), eq("genre", "Science Fiction")), lt("published", 1900))) .select("title") .sort(Field.of("title").ascending()) - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -679,10 +722,10 @@ public void testChecks() throws Exception { .pipeline() .where(not(Field.of("rating").isNaN())) // Filter out any documents with NaN rating .select( - isNull("rating").asAlias("ratingIsNull"), - not(Field.of("rating").isNaN()).asAlias("ratingIsNotNaN")) + isNull("rating").as("ratingIsNull"), + not(Field.of("rating").isNaN()).as("ratingIsNotNaN")) .limit(1) - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -694,9 +737,9 @@ public void testMapGet() throws Exception { List results = collection .pipeline() - .select(Field.of("awards").mapGet("hugo").asAlias("hugoAward"), Field.of("title")) + .select(Field.of("awards").mapGet("hugo").as("hugoAward"), Field.of("title")) .where(eq("hugoAward", true)) - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -713,9 +756,9 @@ public void testParent() throws Exception { .pipeline() .select( parent(collection.document("chile").collection("subCollection").getPath()) - .asAlias("parent")) + .as("parent")) .limit(1) - .execute(firestore) + .execute() .get(); assertThat(data(results)) @@ -728,9 +771,9 @@ public void testCollectionId() throws Exception { List results = collection .pipeline() - .select(collectionId(collection.document("chile")).asAlias("collectionId")) + .select(collectionId(collection.document("chile")).as("collectionId")) .limit(1) - .execute(firestore) + .execute() .get(); assertThat(data(results)).isEqualTo(Lists.newArrayList(map("collectionId", "books"))); @@ -745,13 +788,13 @@ public void testDistanceFunctions() throws Exception { .pipeline() .select( cosineDistance(Constant.ofVector(sourceVector), targetVector) - .asAlias("cosineDistance"), + .as("cosineDistance"), dotProductDistance(Constant.ofVector(sourceVector), targetVector) - .asAlias("dotProductDistance"), + .as("dotProductDistance"), euclideanDistance(Constant.ofVector(sourceVector), targetVector) - .asAlias("euclideanDistance")) + .as("euclideanDistance")) .limit(1) - .execute(firestore) + .execute() .get(); } @@ -762,7 +805,7 @@ public void testNestedFields() throws Exception { .pipeline() .where(eq("awards.hugo", true)) .select("title", "awards.hugo") - .execute(firestore) + .execute() .get(); assertThat(data(results)) diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryAggregationsTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryAggregationsTest.java index 5232862bc..8b9bff5fd 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryAggregationsTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryAggregationsTest.java @@ -62,7 +62,7 @@ public static AggregateQuerySnapshot verifyPipelineReturnsSameResult(AggregateQu AggregateQuerySnapshot snapshot = query.get().get(); List pipelineResults = - query.pipeline().execute(query.getQuery().getFirestore()).get(); + query.pipeline().execute().get(); assertThat(pipelineResults).hasSize(1); assertThat(pipelineResults.get(0).getData()) .isEqualTo(TestUtil.getAggregateSnapshotData(snapshot)); diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java index 34161fa70..164b7c8d4 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryTest.java @@ -85,7 +85,7 @@ public static void checkResultContainsDocumentsInOrder( assertThat(result).isEqualTo(Arrays.asList(docs)); } - List pipelineResults = query.pipeline().execute(query.getFirestore()).get(); + List pipelineResults = query.pipeline().execute().get(); List result = pipelineResults.stream() .map(pipelineResult -> Objects.requireNonNull(pipelineResult.getReference()).getId()) @@ -104,7 +104,7 @@ public static void checkResultContainsDocuments(Query query, boolean pipelineOnl assertThat(result).isEqualTo(Sets.newHashSet(docs)); } - List pipelineResults = query.pipeline().execute(query.getFirestore()).get(); + List pipelineResults = query.pipeline().execute().get(); Set result = pipelineResults.stream() .map(pipelineResult -> Objects.requireNonNull(pipelineResult.getReference()).getId()) @@ -929,7 +929,7 @@ public void multipleInequalityFieldsInAggregateQuery() throws Exception { if (isRunningAgainstFirestoreEmulator(firestore)) { assertThat(query.get().get().getCount()).isEqualTo(4); } - assertThat(query.pipeline().execute(query.getQuery().getFirestore()).get()).isNotEmpty(); + assertThat(query.pipeline().execute().get()).isNotEmpty(); // TODO(MIEQ): Add sum and average when they are public. } From a1a6076cb8c6d990c24f936d4589f87f1222ba00 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Fri, 19 Jul 2024 10:33:26 -0400 Subject: [PATCH 53/65] Fixes --- .../com/google/cloud/firestore/Pipeline.java | 18 +++++----- .../cloud/firestore/PipelineSource.java | 4 +-- .../com/google/cloud/firestore/Query.java | 3 +- .../pipeline/expressions/ArrayConcat.java | 2 +- .../firestore/pipeline/expressions/Expr.java | 18 ++++------ .../pipeline/expressions/Function.java | 26 ++++++-------- .../pipeline/expressions/FunctionUtils.java | 9 +++++ .../pipeline/expressions/StrConcat.java | 2 +- .../firestore/pipeline/stages/Aggregate.java | 25 +++++++------- .../cloud/firestore/it/ITPipelineTest.java | 34 +++++-------------- .../firestore/it/ITQueryAggregationsTest.java | 3 +- 11 files changed, 61 insertions(+), 83 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java index 7a609030f..8bbb7311d 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java @@ -138,37 +138,35 @@ public Pipeline select(String... fields) { @BetaApi public Pipeline where(FilterCondition condition) { return new Pipeline( - this.db, - ImmutableList.builder().addAll(stages).add(new Where(condition)).build()); + this.db, ImmutableList.builder().addAll(stages).add(new Where(condition)).build()); } @BetaApi public Pipeline offset(int offset) { return new Pipeline( - this.db, - ImmutableList.builder().addAll(stages).add(new Offset(offset)).build()); + this.db, ImmutableList.builder().addAll(stages).add(new Offset(offset)).build()); } @BetaApi public Pipeline limit(int limit) { return new Pipeline( - this.db, - ImmutableList.builder().addAll(stages).add(new Limit(limit)).build()); + this.db, ImmutableList.builder().addAll(stages).add(new Limit(limit)).build()); } @BetaApi public Pipeline aggregate(AccumulatorTarget... aggregators) { return new Pipeline( this.db, - ImmutableList.builder().addAll(stages).add(Aggregate.newInstance().withAccumulators(aggregators)).build()); + ImmutableList.builder() + .addAll(stages) + .add(Aggregate.newInstance().withAccumulators(aggregators)) + .build()); } @BetaApi public Pipeline aggregate(Aggregate aggregate) { return new Pipeline( - this.db, - ImmutableList.builder().addAll(stages) - .add(aggregate).build()); + this.db, ImmutableList.builder().addAll(stages).add(aggregate).build()); } @BetaApi diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java index 9b5cb9018..6fdf6a142 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java @@ -14,14 +14,14 @@ public class PipelineSource { private final Firestore db; @InternalApi - PipelineSource(Firestore db){ + PipelineSource(Firestore db) { this.db = db; } @Nonnull @BetaApi public Pipeline collection(@Nonnull String path) { - return new Pipeline(this.db,new Collection(path)); + return new Pipeline(this.db, new Collection(path)); } @Nonnull diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index 933ed50db..d6839f75c 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -2128,7 +2128,8 @@ public Pipeline pipeline() { // From Pipeline ppl = this.options.getAllDescendants() - ? new PipelineSource(this.getFirestore()).collectionGroup(this.options.getCollectionId()) + ? new PipelineSource(this.getFirestore()) + .collectionGroup(this.options.getCollectionId()) : new PipelineSource(this.getFirestore()) .collection( this.options.getParentPath().append(this.options.getCollectionId()).getPath()); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayConcat.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayConcat.java index 0f5f8774d..945832c36 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayConcat.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ArrayConcat.java @@ -9,6 +9,6 @@ public final class ArrayConcat extends Function { @InternalApi ArrayConcat(Expr array, List rest) { - super("array_concat", Lists.newArrayList(array, new ListOfExprs(rest))); + super("array_concat", Lists.asList(array, rest.toArray(new Expr[] {}))); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java index 016ecc59b..e3cc255af 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java @@ -1,9 +1,10 @@ package com.google.cloud.firestore.pipeline.expressions; +import static com.google.cloud.firestore.pipeline.expressions.FunctionUtils.toExprList; + import com.google.api.core.BetaApi; import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; @BetaApi public interface Expr { @@ -109,11 +110,7 @@ default Lte lte(Object other) { @BetaApi default In inAny(Object... other) { - List othersAsExpr = - Arrays.stream(other) - .map(obj -> (obj instanceof Expr) ? (Expr) obj : Constant.of(obj)) - .collect(Collectors.toList()); - return new In(this, othersAsExpr); + return new In(this, toExprList(other)); } @BetaApi @@ -128,8 +125,7 @@ default ArrayConcat arrayConcat(Expr... elements) { @BetaApi default ArrayConcat arrayConcat(Object... elements) { - return new ArrayConcat( - this, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + return new ArrayConcat(this, toExprList(elements)); } @BetaApi @@ -149,8 +145,7 @@ default ArrayContainsAll arrayContainsAll(Expr... elements) { @BetaApi default ArrayContainsAll arrayContainsAll(Object... elements) { - return new ArrayContainsAll( - this, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + return new ArrayContainsAll(this, toExprList(elements)); } @BetaApi @@ -160,8 +155,7 @@ default ArrayContainsAny arrayContainsAny(Expr... elements) { @BetaApi default ArrayContainsAny arrayContainsAny(Object... elements) { - return new ArrayContainsAny( - this, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + return new ArrayContainsAny(this, toExprList(elements)); } @BetaApi diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java index 8b38481e8..b04827e8f 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java @@ -1,5 +1,7 @@ package com.google.cloud.firestore.pipeline.expressions; +import static com.google.cloud.firestore.pipeline.expressions.FunctionUtils.toExprList; + import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.cloud.firestore.DocumentReference; @@ -340,8 +342,7 @@ public static ArrayConcat arrayConcat(Expr expr, Expr... elements) { @BetaApi public static ArrayConcat arrayConcat(Expr expr, Object... elements) { - return new ArrayConcat( - expr, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + return new ArrayConcat(expr, toExprList(elements)); } @BetaApi @@ -351,8 +352,7 @@ public static ArrayConcat arrayConcat(String field, Expr... elements) { @BetaApi public static ArrayConcat arrayConcat(String field, Object... elements) { - return new ArrayConcat( - Field.of(field), Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + return new ArrayConcat(Field.of(field), toExprList(elements)); } @BetaApi @@ -382,8 +382,7 @@ public static ArrayContainsAll arrayContainsAll(Expr expr, Expr... elements) { @BetaApi public static ArrayContainsAll arrayContainsAll(Expr expr, Object... elements) { - return new ArrayContainsAll( - expr, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + return new ArrayContainsAll(expr, toExprList(elements)); } @BetaApi @@ -393,8 +392,7 @@ public static ArrayContainsAll arrayContainsAll(String field, Expr... elements) @BetaApi public static ArrayContainsAll arrayContainsAll(String field, Object... elements) { - return new ArrayContainsAll( - Field.of(field), Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + return new ArrayContainsAll(Field.of(field), toExprList(elements)); } @BetaApi @@ -404,8 +402,7 @@ public static ArrayContainsAny arrayContainsAny(Expr expr, Expr... elements) { @BetaApi public static ArrayContainsAny arrayContainsAny(Expr expr, Object... elements) { - return new ArrayContainsAny( - expr, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + return new ArrayContainsAny(expr, toExprList(elements)); } @BetaApi @@ -415,8 +412,7 @@ public static ArrayContainsAny arrayContainsAny(String field, Expr... elements) @BetaApi public static ArrayContainsAny arrayContainsAny(String field, Object... elements) { - return new ArrayContainsAny( - Field.of(field), Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + return new ArrayContainsAny(Field.of(field), toExprList(elements)); } @BetaApi @@ -496,8 +492,7 @@ public static StrConcat strConcat(Expr expr, Expr... elements) { @BetaApi public static StrConcat strConcat(Expr expr, Object... elements) { - return new StrConcat( - expr, Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + return new StrConcat(expr, toExprList(elements)); } @BetaApi @@ -507,8 +502,7 @@ public static StrConcat strConcat(String field, Expr... elements) { @BetaApi public static StrConcat strConcat(String field, Object... elements) { - return new StrConcat( - Field.of(field), Arrays.stream(elements).map(Constant::of).collect(Collectors.toList())); + return new StrConcat(Field.of(field), toExprList(elements)); } @BetaApi diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/FunctionUtils.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/FunctionUtils.java index 1345f87c5..12b6adcd8 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/FunctionUtils.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/FunctionUtils.java @@ -3,6 +3,8 @@ import com.google.api.core.InternalApi; import com.google.firestore.v1.ArrayValue; import com.google.firestore.v1.Value; +import java.util.Arrays; +import java.util.List; import java.util.stream.Collectors; @InternalApi @@ -29,4 +31,11 @@ public static Value exprToValue(Expr expr) { throw new IllegalArgumentException("Unsupported expression type: " + expr.getClass()); } } + + @InternalApi + static List toExprList(Object[] other) { + return Arrays.stream(other) + .map(obj -> (obj instanceof Expr) ? (Expr) obj : Constant.of(obj)) + .collect(Collectors.toList()); + } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/StrConcat.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/StrConcat.java index fa7212988..e3f9ca75a 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/StrConcat.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/StrConcat.java @@ -9,6 +9,6 @@ public final class StrConcat extends Function { @InternalApi StrConcat(Expr first, List exprs) { - super("str_concat", Lists.newArrayList(first, new ListOfExprs(exprs))); + super("str_concat", Lists.asList(first, exprs.toArray(new Expr[] {}))); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java index e47611efb..59621cb64 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java @@ -20,29 +20,28 @@ public final class Aggregate implements Stage { private final Map accumulators; @BetaApi - public static Aggregate newInstance(){ + public static Aggregate newInstance() { return new Aggregate(Collections.emptyMap(), Collections.emptyMap()); } @BetaApi - public Aggregate withGroups(String... fields){ - return new Aggregate( - PipelineUtils.fieldNamesToMap(fields), - this.accumulators); + public Aggregate withGroups(String... fields) { + return new Aggregate(PipelineUtils.fieldNamesToMap(fields), this.accumulators); } @BetaApi - public Aggregate withGroups(Selectable... selectables){ - return new Aggregate( - PipelineUtils.selectablesToMap(selectables), this.accumulators); + public Aggregate withGroups(Selectable... selectables) { + return new Aggregate(PipelineUtils.selectablesToMap(selectables), this.accumulators); } @BetaApi - public Aggregate withAccumulators(AccumulatorTarget... aggregators){ - return new Aggregate(this.groups, Arrays.stream(aggregators) - .collect( - Collectors.toMap( - AccumulatorTarget::getFieldName, AccumulatorTarget::getAccumulator))); + public Aggregate withAccumulators(AccumulatorTarget... aggregators) { + return new Aggregate( + this.groups, + Arrays.stream(aggregators) + .collect( + Collectors.toMap( + AccumulatorTarget::getFieldName, AccumulatorTarget::getAccumulator))); } private Aggregate(Map groups, Map accumulators) { diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index b74e953dd..034625955 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -281,17 +281,11 @@ public void testGroupBys() throws Exception { collection .pipeline() .where(lt("published", 1900)) - .aggregate( - Aggregate - .newInstance() - .withGroups("genre")) + .aggregate(Aggregate.newInstance().withGroups("genre")) .execute() .get(); assertThat(data(results)) - .containsExactly( - map("genre", "Romance"), - map("genre", "Psychological Thriller") - ); + .containsExactly(map("genre", "Romance"), map("genre", "Psychological Thriller")); } @Test @@ -301,11 +295,9 @@ public void testGroupBysAndAggregate() throws Exception { .pipeline() .where(lt("published", 1984)) .aggregate( - Aggregate - .newInstance() + Aggregate.newInstance() .withGroups("genre") - .withAccumulators(avg("rating").as("avg_rating")) - ) + .withAccumulators(avg("rating").as("avg_rating"))) .where(gt("avg_rating", 4.3)) .execute() .get(); @@ -313,8 +305,7 @@ public void testGroupBysAndAggregate() throws Exception { .containsExactly( map("avg_rating", 4.7, "genre", "Fantasy"), map("avg_rating", 4.5, "genre", "Romance"), - map("avg_rating", 4.4, "genre", "Science Fiction") - ); + map("avg_rating", 4.4, "genre", "Science Fiction")); } @Test @@ -444,11 +435,7 @@ public void testArrayContainsAny() throws Exception { @Test public void testArrayContainsAll() throws Exception { List results = - collection - .pipeline() - .where(arrayContainsAll("tags", "adventure", "magic")) - .execute() - .get(); + collection.pipeline().where(arrayContainsAll("tags", "adventure", "magic")).execute().get(); assertThat(data(results)).isEqualTo(Lists.newArrayList(map("title", "The Lord of the Rings"))); } @@ -491,8 +478,7 @@ public void testArrayFilter() throws Exception { collection .pipeline() .select( - arrayFilter(Field.of("tags"), Function.eq(arrayElement(), "")) - .as("filteredTags")) + arrayFilter(Field.of("tags"), Function.eq(arrayElement(), "")).as("filteredTags")) .limit(1) .execute() .get(); @@ -589,8 +575,7 @@ public void testTrim() throws Exception { collection .pipeline() .addFields( - strConcat(Constant.of(" "), Field.of("title"), Constant.of(" ")) - .as("spacedTitle")) + strConcat(Constant.of(" "), Field.of("title"), Constant.of(" ")).as("spacedTitle")) .select(Field.of("spacedTitle").trim().as("trimmedTitle"), Field.of("spacedTitle")) .limit(1) .execute() @@ -787,8 +772,7 @@ public void testDistanceFunctions() throws Exception { collection .pipeline() .select( - cosineDistance(Constant.ofVector(sourceVector), targetVector) - .as("cosineDistance"), + cosineDistance(Constant.ofVector(sourceVector), targetVector).as("cosineDistance"), dotProductDistance(Constant.ofVector(sourceVector), targetVector) .as("dotProductDistance"), euclideanDistance(Constant.ofVector(sourceVector), targetVector) diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryAggregationsTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryAggregationsTest.java index 8b9bff5fd..259ba585f 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryAggregationsTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITQueryAggregationsTest.java @@ -61,8 +61,7 @@ public static AggregateQuerySnapshot verifyPipelineReturnsSameResult(AggregateQu throws ExecutionException, InterruptedException { AggregateQuerySnapshot snapshot = query.get().get(); - List pipelineResults = - query.pipeline().execute().get(); + List pipelineResults = query.pipeline().execute().get(); assertThat(pipelineResults).hasSize(1); assertThat(pipelineResults.get(0).getData()) .isEqualTo(TestUtil.getAggregateSnapshotData(snapshot)); From 64622b1a63f79e0a2369a120ed28bc2c66354c2c Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Fri, 19 Jul 2024 15:04:13 -0400 Subject: [PATCH 54/65] startsWith and endsWith --- .../com/google/cloud/firestore/Pipeline.java | 3 +- .../pipeline/expressions/EndsWith.java | 13 +++++++ .../firestore/pipeline/expressions/Expr.java | 20 ++++++++++ .../pipeline/expressions/Function.java | 30 ++++++++++++++ .../pipeline/expressions/StartsWith.java | 13 +++++++ .../cloud/firestore/it/ITPipelineTest.java | 39 +++++++++++++++++++ 6 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/EndsWith.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/StartsWith.java diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java index 8bbb7311d..f75092247 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java @@ -81,6 +81,7 @@ */ @BetaApi public final class Pipeline { + private static Logger logger = Logger.getLogger(Pipeline.class.getName()); private final ImmutableList stages; private final Firestore db; @@ -388,7 +389,7 @@ public void onComplete() { } }; - Logger.getLogger("Pipeline").log(Level.WARNING, "Sending request: " + request); + logger.log(Level.INFO, "Sending pipeline request: " + request.getStructuredPipeline()); rpcContext.streamRequest(request, observer, rpcContext.getClient().executePipelineCallable()); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/EndsWith.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/EndsWith.java new file mode 100644 index 000000000..b2608bfa2 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/EndsWith.java @@ -0,0 +1,13 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.common.collect.Lists; + +@BetaApi +public final class EndsWith extends Function implements FilterCondition { + @InternalApi + EndsWith(Expr expr, Expr postfix) { + super("ends_with", Lists.newArrayList(expr, postfix)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java index e3cc255af..6b5541adc 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java @@ -228,6 +228,26 @@ default RegexMatch regexMatches(String regex) { return new RegexMatch(this, Constant.of(regex)); } + @BetaApi + default StartsWith startsWith(String prefix) { + return new StartsWith(this, Constant.of(prefix)); + } + + @BetaApi + default StartsWith startsWith(Expr prefix) { + return new StartsWith(this, prefix); + } + + @BetaApi + default EndsWith endsWith(String postfix) { + return new EndsWith(this, Constant.of(postfix)); + } + + @BetaApi + default EndsWith endsWith(Expr postfix) { + return new EndsWith(this, postfix); + } + @BetaApi default StrConcat strConcat(List elements) { return new StrConcat(this, elements); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java index b04827e8f..827536dce 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java @@ -485,6 +485,36 @@ public static RegexMatch regexMatch(String field, String pattern) { return new RegexMatch(Field.of(field), Constant.of(pattern)); } + @BetaApi + public static StartsWith startsWith(String field, String prefix) { + return new StartsWith(Field.of(field), Constant.of(prefix)); + } + + @BetaApi + public static StartsWith startsWith(String field, Expr prefix) { + return new StartsWith(Field.of(field), prefix); + } + + @BetaApi + public static StartsWith startsWith(Expr expr, Expr prefix) { + return new StartsWith(expr, prefix); + } + + @BetaApi + public static EndsWith endsWith(String field, String prefix) { + return new EndsWith(Field.of(field), Constant.of(prefix)); + } + + @BetaApi + public static EndsWith endsWith(String field, Expr prefix) { + return new EndsWith(Field.of(field), prefix); + } + + @BetaApi + public static EndsWith endsWith(Expr expr, Expr prefix) { + return new EndsWith(expr, prefix); + } + @BetaApi public static StrConcat strConcat(Expr expr, Expr... elements) { return new StrConcat(expr, Arrays.asList(elements)); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/StartsWith.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/StartsWith.java new file mode 100644 index 000000000..b35fbd064 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/StartsWith.java @@ -0,0 +1,13 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.common.collect.Lists; + +@BetaApi +public final class StartsWith extends Function implements FilterCondition { + @InternalApi + StartsWith(Expr expr, Expr prefix) { + super("starts_with", Lists.newArrayList(expr, prefix)); + } +} diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 034625955..91a740ac2 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -30,6 +30,7 @@ import static com.google.cloud.firestore.pipeline.expressions.Function.cosineDistance; import static com.google.cloud.firestore.pipeline.expressions.Function.countAll; import static com.google.cloud.firestore.pipeline.expressions.Function.dotProductDistance; +import static com.google.cloud.firestore.pipeline.expressions.Function.endsWith; import static com.google.cloud.firestore.pipeline.expressions.Function.eq; import static com.google.cloud.firestore.pipeline.expressions.Function.euclideanDistance; import static com.google.cloud.firestore.pipeline.expressions.Function.gt; @@ -39,6 +40,7 @@ import static com.google.cloud.firestore.pipeline.expressions.Function.not; import static com.google.cloud.firestore.pipeline.expressions.Function.or; import static com.google.cloud.firestore.pipeline.expressions.Function.parent; +import static com.google.cloud.firestore.pipeline.expressions.Function.startsWith; import static com.google.cloud.firestore.pipeline.expressions.Function.strConcat; import static com.google.cloud.firestore.pipeline.expressions.Function.subtract; import static com.google.common.truth.Truth.assertThat; @@ -526,6 +528,43 @@ public void testStrConcat() throws Exception { map("bookInfo", "Douglas Adams - The Hitchhiker's Guide to the Galaxy"))); } + @Test + public void testStartsWith() throws Exception { + List results = + collection.pipeline() + .where(startsWith("title", "The")) + .select("title") + .sort(Field.of("title").ascending()) + .execute().get(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map("title", "The Great Gatsby"), + map("title", "The Handmaid's Tale"), + map("title", "The Hitchhiker's Guide to the Galaxy"), + map("title", "The Lord of the Rings") + )); + } + + @Test + public void testEndsWith() throws Exception { + List results = + collection + .pipeline() + .where(endsWith(Field.of("title"), Constant.of("y"))) + .select("title") + .sort(Field.of("title").descending()) + .execute() + .get(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map("title", "The Hitchhiker's Guide to the Galaxy"), + map("title", "The Great Gatsby"))); + } + @Test public void testLength() throws Exception { List results = From 8165ce47e7b7bf136d6a1c52611b743e5c3b5085 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Mon, 22 Jul 2024 10:25:15 -0400 Subject: [PATCH 55/65] no Fields.ofAll --- .../google/cloud/firestore/pipeline/expressions/Field.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java index c5137e055..7d1515b97 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java @@ -25,11 +25,6 @@ public static Field of(String path) { return new Field(FieldPath.fromDotSeparatedString(path)); } - @BetaApi - public static Field ofAll() { - return new Field(FieldPath.of("")); - } - @InternalApi public Value toProto() { return Value.newBuilder().setFieldReferenceValue(path.toString()).build(); From 29fcb1dd8e17b83811901dd8dbdce5f115a3e337 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Mon, 22 Jul 2024 15:07:47 -0400 Subject: [PATCH 56/65] Add Distinct --- .../com/google/cloud/firestore/Pipeline.java | 25 ++++++++++++-- .../firestore/pipeline/stages/Aggregate.java | 16 ++++----- .../firestore/pipeline/stages/Distinct.java | 28 ++++++++++++++++ .../firestore/pipeline/stages/StageUtils.java | 6 ++++ .../cloud/firestore/it/ITPipelineTest.java | 33 +++++++++++++------ 5 files changed, 88 insertions(+), 20 deletions(-) create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Distinct.java diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java index f75092247..4b757bbe8 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java @@ -19,6 +19,7 @@ import com.google.cloud.firestore.pipeline.stages.Collection; import com.google.cloud.firestore.pipeline.stages.CollectionGroup; import com.google.cloud.firestore.pipeline.stages.Database; +import com.google.cloud.firestore.pipeline.stages.Distinct; import com.google.cloud.firestore.pipeline.stages.Documents; import com.google.cloud.firestore.pipeline.stages.FindNearest; import com.google.cloud.firestore.pipeline.stages.GenericStage; @@ -155,12 +156,12 @@ public Pipeline limit(int limit) { } @BetaApi - public Pipeline aggregate(AccumulatorTarget... aggregators) { + public Pipeline aggregate(AccumulatorTarget... accumulators) { return new Pipeline( this.db, ImmutableList.builder() .addAll(stages) - .add(Aggregate.newInstance().withAccumulators(aggregators)) + .add(Aggregate.withAccumulators(accumulators)) .build()); } @@ -170,6 +171,26 @@ public Pipeline aggregate(Aggregate aggregate) { this.db, ImmutableList.builder().addAll(stages).add(aggregate).build()); } + @BetaApi + public Pipeline distinct(String... fields) { + return new Pipeline( + this.db, + ImmutableList.builder() + .addAll(stages) + .add(new Distinct(PipelineUtils.fieldNamesToMap(fields))) + .build()); + } + + @BetaApi + public Pipeline distinct(Selectable... selectables) { + return new Pipeline( + this.db, + ImmutableList.builder() + .addAll(stages) + .add(new Distinct(PipelineUtils.selectablesToMap(selectables))) + .build()); + } + @BetaApi public Pipeline findNearest( String fieldName, double[] vector, FindNearest.FindNearestOptions options) { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java index 59621cb64..5e4e5d83f 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java @@ -19,11 +19,6 @@ public final class Aggregate implements Stage { private final Map groups; private final Map accumulators; - @BetaApi - public static Aggregate newInstance() { - return new Aggregate(Collections.emptyMap(), Collections.emptyMap()); - } - @BetaApi public Aggregate withGroups(String... fields) { return new Aggregate(PipelineUtils.fieldNamesToMap(fields), this.accumulators); @@ -35,10 +30,15 @@ public Aggregate withGroups(Selectable... selectables) { } @BetaApi - public Aggregate withAccumulators(AccumulatorTarget... aggregators) { + public static Aggregate withAccumulators(AccumulatorTarget... accumulators) { + if (accumulators.length == 0) { + throw new IllegalArgumentException( + "Must specify at least one accumulator for aggregate() stage. There is a distinct() stage if only distinct group values are needed."); + } + return new Aggregate( - this.groups, - Arrays.stream(aggregators) + Collections.emptyMap(), + Arrays.stream(accumulators) .collect( Collectors.toMap( AccumulatorTarget::getFieldName, AccumulatorTarget::getAccumulator))); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Distinct.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Distinct.java new file mode 100644 index 000000000..d41127b81 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Distinct.java @@ -0,0 +1,28 @@ +package com.google.cloud.firestore.pipeline.stages; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.cloud.firestore.pipeline.expressions.Expr; +import java.util.Map; + +@BetaApi +public final class Distinct implements Stage { + + private static final String name = "distinct"; + private final Map groups; + + @InternalApi + public Distinct(Map groups) { + this.groups = groups; + } + + @InternalApi + Map getGroups() { + return groups; + } + + @Override + public String getName() { + return name; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java index 41e85b516..5aef5fea7 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java @@ -86,6 +86,12 @@ public static com.google.firestore.v1.Pipeline.Stage toStageProto(Stage stage) { .addArgs(encodeValue(aggregateStage.getGroups())) .addArgs(encodeValue(aggregateStage.getAccumulators())) .build(); + } else if (stage instanceof Distinct) { + Distinct distinctStage = (Distinct) stage; + return com.google.firestore.v1.Pipeline.Stage.newBuilder() + .setName(distinctStage.getName()) + .addArgs(encodeValue(distinctStage.getGroups())) + .build(); } else if (stage instanceof FindNearest) { FindNearest findNearestStage = (FindNearest) stage; return com.google.firestore.v1.Pipeline.Stage.newBuilder() diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 91a740ac2..9a066c8bb 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -44,6 +44,7 @@ import static com.google.cloud.firestore.pipeline.expressions.Function.strConcat; import static com.google.cloud.firestore.pipeline.expressions.Function.subtract; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertThrows; import com.google.cloud.firestore.CollectionReference; import com.google.cloud.firestore.LocalFirestoreHelper; @@ -278,16 +279,29 @@ public void testAggregates() throws Exception { } @Test - public void testGroupBys() throws Exception { + public void testGroupBysWithoutAccumulators() throws Exception { + assertThrows( + IllegalArgumentException.class, + () -> { + collection + .pipeline() + .where(lt("published", 1900)) + .aggregate(Aggregate.withAccumulators().withGroups("genre")); + }); + } + + @Test + public void testDistinct() throws Exception { List results = collection .pipeline() .where(lt("published", 1900)) - .aggregate(Aggregate.newInstance().withGroups("genre")) + .distinct(Field.of("genre").toLowercase().as("lower_genre")) .execute() .get(); assertThat(data(results)) - .containsExactly(map("genre", "Romance"), map("genre", "Psychological Thriller")); + .containsExactly( + map("lower_genre", "romance"), map("lower_genre", "psychological thriller")); } @Test @@ -297,9 +311,7 @@ public void testGroupBysAndAggregate() throws Exception { .pipeline() .where(lt("published", 1984)) .aggregate( - Aggregate.newInstance() - .withGroups("genre") - .withAccumulators(avg("rating").as("avg_rating"))) + Aggregate.withAccumulators(avg("rating").as("avg_rating")).withGroups("genre")) .where(gt("avg_rating", 4.3)) .execute() .get(); @@ -531,11 +543,13 @@ public void testStrConcat() throws Exception { @Test public void testStartsWith() throws Exception { List results = - collection.pipeline() + collection + .pipeline() .where(startsWith("title", "The")) .select("title") .sort(Field.of("title").ascending()) - .execute().get(); + .execute() + .get(); assertThat(data(results)) .isEqualTo( @@ -543,8 +557,7 @@ public void testStartsWith() throws Exception { map("title", "The Great Gatsby"), map("title", "The Handmaid's Tale"), map("title", "The Hitchhiker's Guide to the Galaxy"), - map("title", "The Lord of the Rings") - )); + map("title", "The Lord of the Rings"))); } @Test From 0c69e9f5e0830665ad1d35cc12c50701d82519c8 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Tue, 23 Jul 2024 10:59:01 -0400 Subject: [PATCH 57/65] Renames --- .../java/com/google/cloud/firestore/pipeline/stages/Select.java | 2 +- .../java/com/google/cloud/firestore/pipeline/stages/Where.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Select.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Select.java index 20531a78a..1dcf88955 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Select.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Select.java @@ -7,7 +7,7 @@ @InternalApi public final class Select implements Stage { - private static final String name = "project"; + private static final String name = "select"; private final Map projections; @InternalApi diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Where.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Where.java index a268c99c6..49451bb3e 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Where.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Where.java @@ -6,7 +6,7 @@ @InternalApi public final class Where implements Stage { - private static final String name = "filter"; + private static final String name = "where"; private final FilterCondition condition; @InternalApi From 7ed3d953d91ef88a192a4089351bab774c04d21a Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Tue, 4 Jun 2024 13:36:30 -0400 Subject: [PATCH 58/65] String functions, groups and joins --- .../firestore/pipeline/GroupingPipeline.java | 21 ++++++++++ .../firestore/pipeline/JoiningPipeline.java | 36 ++++++++++++++++ .../pipeline/expressions/Concat.java | 9 ++++ .../pipeline/expressions/ToLower.java | 9 ++++ .../pipeline/expressions/ToUpper.java | 9 ++++ .../cloud/firestore/pipeline/stages/Join.java | 41 +++++++++++++++++++ .../pipeline/stages/JoinCondition.java | 32 +++++++++++++++ .../pipeline/stages/UnnestArray.java | 25 +++++++++++ 8 files changed, 182 insertions(+) create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/GroupingPipeline.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/JoiningPipeline.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Concat.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToLower.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToUpper.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Join.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/JoinCondition.java create mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/UnnestArray.java diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/GroupingPipeline.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/GroupingPipeline.java new file mode 100644 index 000000000..54a41c880 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/GroupingPipeline.java @@ -0,0 +1,21 @@ +package com.google.cloud.firestore.pipeline; + +import com.google.cloud.firestore.Pipeline; +import com.google.cloud.firestore.pipeline.expressions.AggregatorTarget; +import com.google.cloud.firestore.pipeline.expressions.Selectable; +import java.util.List; + +public class GroupingPipeline { + private final Pipeline p; + private final List by; + + public GroupingPipeline(Pipeline p, List by) { + this.p = p; + this.by = by; + } + + public Pipeline aggregate(AggregatorTarget... aggregator) { + // TODO: Implement actual aggregation logic + return this.p; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/JoiningPipeline.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/JoiningPipeline.java new file mode 100644 index 000000000..8d82385ba --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/JoiningPipeline.java @@ -0,0 +1,36 @@ +package com.google.cloud.firestore.pipeline; + +import com.google.cloud.firestore.Pipeline; +import com.google.cloud.firestore.pipeline.expressions.Field; +import com.google.cloud.firestore.pipeline.expressions.Fields; +import com.google.cloud.firestore.pipeline.expressions.FilterCondition; +import com.google.cloud.firestore.pipeline.stages.Join; + +public class JoiningPipeline { + private final Pipeline left; + private final Pipeline right; + private final Join.Type join; + private String leftPrefix = null; + private String rightPrefix = null; + + public JoiningPipeline(Pipeline left, Pipeline right, Join.Type join) { + this.left = left; + this.right = right; + this.join = join; + } + + public Pipeline on(FilterCondition condition) { + // TODO: Implement actual join condition logic + return left; + } + + public Pipeline using(Field... field) { + // TODO: Implement actual join condition logic + return left; + } + + public Pipeline using(Fields field) { + // TODO: Implement actual join condition logic + return left; + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Concat.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Concat.java new file mode 100644 index 000000000..283cedca5 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Concat.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import java.util.List; + +public final class Concat extends Function { + Concat(List exprs) { + super("concat", exprs); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToLower.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToLower.java new file mode 100644 index 000000000..6013eeb15 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToLower.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class ToLower extends Function { + ToLower(Expr expr) { + super("to_lower", Lists.newArrayList(expr)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToUpper.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToUpper.java new file mode 100644 index 000000000..9e0bffee7 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ToUpper.java @@ -0,0 +1,9 @@ +package com.google.cloud.firestore.pipeline.expressions; + +import com.google.common.collect.Lists; + +public final class ToUpper extends Function { + ToUpper(Expr expr) { + super("to_upper", Lists.newArrayList(expr)); + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Join.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Join.java new file mode 100644 index 000000000..7f073ab37 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Join.java @@ -0,0 +1,41 @@ +package com.google.cloud.firestore.pipeline.stages; + +import com.google.api.core.InternalApi; +import com.google.cloud.firestore.Pipeline; +import com.google.cloud.firestore.pipeline.expressions.Field; + +@InternalApi +public class Join implements Stage { + private final Type type; + private final JoinCondition condition; + private final Field alias; + private final Pipeline otherPipeline; + private final Field otherAlias; + + @InternalApi + public Join( + Type type, JoinCondition condition, Field alias, Pipeline otherPipeline, Field otherAlias) { + this.type = type; + this.condition = condition; + this.alias = alias; + this.otherPipeline = otherPipeline; + this.otherAlias = otherAlias; + } + + @Override + public String getName() { + return "join"; + } + + public enum Type { + CROSS, + INNER, + FULL, + LEFT, + RIGHT, + LEFT_SEMI, + RIGHT_SEMI, + LEFT_ANTI_SEMI, + RIGHT_ANTI_SEMI + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/JoinCondition.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/JoinCondition.java new file mode 100644 index 000000000..ef2057575 --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/JoinCondition.java @@ -0,0 +1,32 @@ +package com.google.cloud.firestore.pipeline.stages; + +import com.google.cloud.firestore.pipeline.expressions.Expr; +import com.google.cloud.firestore.pipeline.expressions.Field; +import java.util.Set; + +public interface JoinCondition { + + class Expression implements JoinCondition { + private final Expr expr; + + public Expression(Expr expr) { + this.expr = expr; + } + + public Expr getExpr() { + return expr; + } + } + + class Using implements JoinCondition { + private final Set fields; + + public Using(Set fields) { + this.fields = fields; + } + + public Set getFields() { + return fields; + } + } +} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/UnnestArray.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/UnnestArray.java new file mode 100644 index 000000000..6d7526adb --- /dev/null +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/UnnestArray.java @@ -0,0 +1,25 @@ +package com.google.cloud.firestore.pipeline.stages; + +import com.google.api.core.InternalApi; +import com.google.cloud.firestore.pipeline.expressions.Field; + +@InternalApi +public final class UnnestArray implements Stage { + + private static final String name = "unnest_array"; + private final Field field; + + @InternalApi + public UnnestArray(Field arrayField) { + this.field = arrayField; + } + + public Field getField() { + return field; + } + + @Override + public String getName() { + return name; + } +} From f143e22e04156e1ebdfdee9de2a8304ed3236bf7 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Fri, 19 Jul 2024 10:47:11 -0400 Subject: [PATCH 59/65] unnestarray and others --- .../com/google/cloud/firestore/Pipeline.java | 12 +++++++ .../firestore/pipeline/GroupingPipeline.java | 21 ----------- .../firestore/pipeline/JoiningPipeline.java | 36 ------------------- .../cloud/firestore/pipeline/stages/Join.java | 32 +++++++++++++++-- 4 files changed, 41 insertions(+), 60 deletions(-) delete mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/GroupingPipeline.java delete mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/JoiningPipeline.java diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java index 4b757bbe8..d536c20a1 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java @@ -10,6 +10,7 @@ import com.google.cloud.Timestamp; import com.google.cloud.firestore.pipeline.PaginatingPipeline; import com.google.cloud.firestore.pipeline.expressions.AccumulatorTarget; +import com.google.cloud.firestore.pipeline.expressions.Expr; import com.google.cloud.firestore.pipeline.expressions.Field; import com.google.cloud.firestore.pipeline.expressions.FilterCondition; import com.google.cloud.firestore.pipeline.expressions.Ordering; @@ -23,6 +24,7 @@ import com.google.cloud.firestore.pipeline.stages.Documents; import com.google.cloud.firestore.pipeline.stages.FindNearest; import com.google.cloud.firestore.pipeline.stages.GenericStage; +import com.google.cloud.firestore.pipeline.stages.Join; import com.google.cloud.firestore.pipeline.stages.Limit; import com.google.cloud.firestore.pipeline.stages.Offset; import com.google.cloud.firestore.pipeline.stages.Select; @@ -232,6 +234,16 @@ public PaginatingPipeline paginate(int pageSize, Ordering... orders) { return new PaginatingPipeline(this, pageSize, Arrays.asList(orders)); } + @BetaApi + public Pipeline join(Join join) { + return new Pipeline(this.db, ImmutableList.builder().addAll(stages).add(join).build()); + } + + @BetaApi + public Pipeline unnestArray(Expr expr) { + return new Pipeline(this.db, ImmutableList.builder().addAll(stages) /*.add()*/.build()); + } + @BetaApi public Pipeline genericStage(String name, Map params) { // Implementation for genericStage (add the GenericStage if needed) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/GroupingPipeline.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/GroupingPipeline.java deleted file mode 100644 index 54a41c880..000000000 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/GroupingPipeline.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.google.cloud.firestore.pipeline; - -import com.google.cloud.firestore.Pipeline; -import com.google.cloud.firestore.pipeline.expressions.AggregatorTarget; -import com.google.cloud.firestore.pipeline.expressions.Selectable; -import java.util.List; - -public class GroupingPipeline { - private final Pipeline p; - private final List by; - - public GroupingPipeline(Pipeline p, List by) { - this.p = p; - this.by = by; - } - - public Pipeline aggregate(AggregatorTarget... aggregator) { - // TODO: Implement actual aggregation logic - return this.p; - } -} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/JoiningPipeline.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/JoiningPipeline.java deleted file mode 100644 index 8d82385ba..000000000 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/JoiningPipeline.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.google.cloud.firestore.pipeline; - -import com.google.cloud.firestore.Pipeline; -import com.google.cloud.firestore.pipeline.expressions.Field; -import com.google.cloud.firestore.pipeline.expressions.Fields; -import com.google.cloud.firestore.pipeline.expressions.FilterCondition; -import com.google.cloud.firestore.pipeline.stages.Join; - -public class JoiningPipeline { - private final Pipeline left; - private final Pipeline right; - private final Join.Type join; - private String leftPrefix = null; - private String rightPrefix = null; - - public JoiningPipeline(Pipeline left, Pipeline right, Join.Type join) { - this.left = left; - this.right = right; - this.join = join; - } - - public Pipeline on(FilterCondition condition) { - // TODO: Implement actual join condition logic - return left; - } - - public Pipeline using(Field... field) { - // TODO: Implement actual join condition logic - return left; - } - - public Pipeline using(Fields field) { - // TODO: Implement actual join condition logic - return left; - } -} diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Join.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Join.java index 7f073ab37..a954f4e2f 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Join.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Join.java @@ -1,10 +1,11 @@ package com.google.cloud.firestore.pipeline.stages; +import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.cloud.firestore.Pipeline; import com.google.cloud.firestore.pipeline.expressions.Field; -@InternalApi +@BetaApi public class Join implements Stage { private final Type type; private final JoinCondition condition; @@ -13,8 +14,7 @@ public class Join implements Stage { private final Field otherAlias; @InternalApi - public Join( - Type type, JoinCondition condition, Field alias, Pipeline otherPipeline, Field otherAlias) { + Join(Type type, JoinCondition condition, Field alias, Pipeline otherPipeline, Field otherAlias) { this.type = type; this.condition = condition; this.alias = alias; @@ -22,11 +22,37 @@ public Join( this.otherAlias = otherAlias; } + @BetaApi + public static Join with(Pipeline other, Type type) { + return new Join(type, null, null, null, null); + } + + @BetaApi + public Join onCondition(JoinCondition condition) { + return new Join(this.type, condition, this.alias, this.otherPipeline, this.otherAlias); + } + + @BetaApi + public Join onFields(String... fields) { + return new Join(this.type, condition, this.alias, this.otherPipeline, this.otherAlias); + } + + @BetaApi + public Join withThisAlias(String alias) { + return new Join(this.type, condition, this.alias, this.otherPipeline, this.otherAlias); + } + + @BetaApi + public Join withOtherAlias(String alias) { + return new Join(this.type, condition, this.alias, this.otherPipeline, this.otherAlias); + } + @Override public String getName() { return "join"; } + @InternalApi public enum Type { CROSS, INNER, From 660b9f4c78cb25f19c192d9dcd122ac3f5658560 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Fri, 19 Jul 2024 15:20:35 -0400 Subject: [PATCH 60/65] fix joins --- .../cloud/firestore/pipeline/stages/Join.java | 7 ++-- .../pipeline/stages/JoinCondition.java | 32 ------------------- 2 files changed, 4 insertions(+), 35 deletions(-) delete mode 100644 google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/JoinCondition.java diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Join.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Join.java index a954f4e2f..5da7fa824 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Join.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Join.java @@ -4,17 +4,18 @@ import com.google.api.core.InternalApi; import com.google.cloud.firestore.Pipeline; import com.google.cloud.firestore.pipeline.expressions.Field; +import com.google.cloud.firestore.pipeline.expressions.FilterCondition; @BetaApi public class Join implements Stage { private final Type type; - private final JoinCondition condition; + private final FilterCondition condition; private final Field alias; private final Pipeline otherPipeline; private final Field otherAlias; @InternalApi - Join(Type type, JoinCondition condition, Field alias, Pipeline otherPipeline, Field otherAlias) { + Join(Type type, FilterCondition condition, Field alias, Pipeline otherPipeline, Field otherAlias) { this.type = type; this.condition = condition; this.alias = alias; @@ -28,7 +29,7 @@ public static Join with(Pipeline other, Type type) { } @BetaApi - public Join onCondition(JoinCondition condition) { + public Join onCondition(FilterCondition condition) { return new Join(this.type, condition, this.alias, this.otherPipeline, this.otherAlias); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/JoinCondition.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/JoinCondition.java deleted file mode 100644 index ef2057575..000000000 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/JoinCondition.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.google.cloud.firestore.pipeline.stages; - -import com.google.cloud.firestore.pipeline.expressions.Expr; -import com.google.cloud.firestore.pipeline.expressions.Field; -import java.util.Set; - -public interface JoinCondition { - - class Expression implements JoinCondition { - private final Expr expr; - - public Expression(Expr expr) { - this.expr = expr; - } - - public Expr getExpr() { - return expr; - } - } - - class Using implements JoinCondition { - private final Set fields; - - public Using(Set fields) { - this.fields = fields; - } - - public Set getFields() { - return fields; - } - } -} From 2dfeb3d4ff9af7005a56185b3cf270bfeac069aa Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Mon, 22 Jul 2024 10:29:06 -0400 Subject: [PATCH 61/65] Fix field --- .../cloud/firestore/pipeline/expressions/Field.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java index 7d1515b97..39c64eb47 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java @@ -17,6 +17,11 @@ private Field(FieldPath path) { this.path = path; } + private Field(Pipeline pipeline, FieldPath path) { + this.pipeline = pipeline; + this.path = path; + } + @BetaApi public static Field of(String path) { if (path.equals(DOCUMENT_ID)) { @@ -25,6 +30,14 @@ public static Field of(String path) { return new Field(FieldPath.fromDotSeparatedString(path)); } + @BetaApi + public static Field of(Pipeline pipeline, String path) { + if (path.equals(DOCUMENT_ID)) { + return new Field(pipeline, FieldPath.of("__path__")); + } + return new Field(pipeline, FieldPath.fromDotSeparatedString(path)); + } + @InternalApi public Value toProto() { return Value.newBuilder().setFieldReferenceValue(path.toString()).build(); From 508eb7a92a235411711e30f8025af3b1050e2736 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Thu, 25 Jul 2024 11:20:04 -0400 Subject: [PATCH 62/65] Add exists to toPipeline() --- .../google/cloud/firestore/PipelineUtils.java | 32 +++++++++---------- .../com/google/cloud/firestore/Query.java | 21 +++++++++--- .../pipeline/expressions/Exists.java | 4 +-- .../firestore/pipeline/expressions/Expr.java | 5 +++ .../firestore/pipeline/expressions/Field.java | 19 +++++++++-- .../pipeline/expressions/Function.java | 20 +++++++++++- 6 files changed, 74 insertions(+), 27 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java index a4bf5a2db..828b2e2f4 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java @@ -40,32 +40,32 @@ public static Value encodeValue(Object value) { static FilterCondition toPipelineFilterCondition(FilterInternal f) { if (f instanceof ComparisonFilterInternal) { ComparisonFilterInternal comparisonFilter = (ComparisonFilterInternal) f; - String fieldPath = comparisonFilter.fieldReference.getFieldPath(); + Field field = Field.of(comparisonFilter.fieldReference.getFieldPath()); Value value = comparisonFilter.value; switch (comparisonFilter.operator) { case LESS_THAN: - return Field.of(fieldPath).lt(value); + return and(field.exists(), field.lt(value)); case LESS_THAN_OR_EQUAL: - return Field.of(fieldPath).lte(value); + return and(field.exists(), field.lte(value)); case GREATER_THAN: - return Field.of(fieldPath).gt(value); + return and(field.exists(), field.gt(value)); case GREATER_THAN_OR_EQUAL: - return Field.of(fieldPath).gte(value); + return and(field.exists(), field.gte(value)); case EQUAL: - return Field.of(fieldPath).eq(value); + return and(field.exists(), field.eq(value)); case NOT_EQUAL: - return not(Field.of(fieldPath).eq(value)); + return and(field.exists(), not(field.eq(value))); case ARRAY_CONTAINS: - return Field.of(fieldPath).arrayContains(value); + return and(field.exists(), field.arrayContains(value)); case IN: List valuesList = value.getArrayValue().getValuesList(); - return inAny(Field.of(fieldPath), Lists.newArrayList(valuesList)); + return and(field.exists(), inAny(field, Lists.newArrayList(valuesList))); case ARRAY_CONTAINS_ANY: List valuesListAny = value.getArrayValue().getValuesList(); - return arrayContainsAny(Field.of(fieldPath), valuesListAny.toArray()); + return and(field.exists(), arrayContainsAny(field, valuesListAny.toArray())); case NOT_IN: List notInValues = value.getArrayValue().getValuesList(); - return not(inAny(Field.of(fieldPath), Lists.newArrayList(notInValues))); + return and(field.exists(), not(inAny(field, Lists.newArrayList(notInValues)))); default: // Handle OPERATOR_UNSPECIFIED and UNRECOGNIZED cases as needed throw new IllegalArgumentException("Unsupported operator: " + comparisonFilter.operator); @@ -96,16 +96,16 @@ static FilterCondition toPipelineFilterCondition(FilterInternal f) { } } else if (f instanceof UnaryFilterInternal) { UnaryFilterInternal unaryFilter = (UnaryFilterInternal) f; - String fieldPath = unaryFilter.fieldReference.getFieldPath(); + Field field = Field.of(unaryFilter.fieldReference.getFieldPath()); switch (unaryFilter.getOperator()) { case IS_NAN: - return Field.of(fieldPath).isNaN(); + return and(field.exists(), field.isNaN()); case IS_NULL: - return Field.of(fieldPath).isNull(); + return and(field.exists(), field.isNull()); case IS_NOT_NAN: - return not(Field.of(fieldPath).isNaN()); + return and(field.exists(), not(field.isNaN())); case IS_NOT_NULL: - return not(Field.of(fieldPath).isNull()); + return and(field.exists(), not(field.isNull())); default: // Handle OPERATOR_UNSPECIFIED and UNRECOGNIZED cases as needed throw new IllegalArgumentException("Unsupported operator: " + unaryFilter.getOperator()); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index d6839f75c..dfd952b6c 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -52,6 +52,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; import com.google.firestore.bundle.BundledQuery; import com.google.firestore.v1.Cursor; import com.google.firestore.v1.Document; @@ -2139,6 +2140,9 @@ public Pipeline pipeline() { ppl = ppl.where(toPipelineFilterCondition(f)); } + // Collecting implicit exists fields. + Set exists = new HashSet<>(); + // Projections if (this.options.getFieldProjections() != null && !this.options.getFieldProjections().isEmpty()) { @@ -2147,6 +2151,10 @@ public Pipeline pipeline() { this.options.getFieldProjections().stream() .map(fieldReference -> Field.of(fieldReference.getFieldPath())) .toArray(Selectable[]::new)); + exists.addAll( + this.options.getFieldProjections().stream() + .map(fieldReference -> Field.of(fieldReference.getFieldPath()).exists()) + .collect(Collectors.toList())); } // Orders @@ -2164,17 +2172,20 @@ public Pipeline pipeline() { .collect(Collectors.toList()); // Add exists filters to match Query's implicit orderby semantics. - List exists = + exists.addAll( normalizedOrderbys.stream() // .filter(order -> !order.fieldReference.getFieldPath().equals("__name__")) .map(order -> Field.of(order.fieldReference.getFieldPath()).exists()) - .collect(Collectors.toList()); - if (exists.size() > 1) { + .collect(Collectors.toList())); + List existsList = Lists.newArrayList(exists); + if (existsList.size() > 1) { ppl = ppl.where( - and(exists.get(0), exists.subList(1, exists.size()).toArray(new Exists[] {}))); + and( + existsList.get(0), + existsList.subList(1, existsList.size()).toArray(new Exists[] {}))); } else if (exists.size() == 1) { - ppl = ppl.where(exists.get(0)); + ppl = ppl.where(existsList.get(0)); } ppl = ppl.sort(orders, Density.REQUIRED, Truncation.UNSPECIFIED); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Exists.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Exists.java index d2c04f04b..44a573926 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Exists.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Exists.java @@ -7,7 +7,7 @@ @BetaApi public final class Exists extends Function implements FilterCondition { @InternalApi - Exists(Field field) { - super("exists", Lists.newArrayList(field)); + Exists(Expr expr) { + super("exists", Lists.newArrayList(expr)); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java index 6b5541adc..12820d14e 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java @@ -178,6 +178,11 @@ default IsNaN isNaN() { return new IsNaN(this); } + @BetaApi + default Exists exists() { + return new Exists(this); + } + @BetaApi default IsNull isNull() { return new IsNull(this); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java index 7d1515b97..10f4775b6 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Field.java @@ -4,6 +4,7 @@ import com.google.api.core.InternalApi; import com.google.cloud.firestore.FieldPath; import com.google.cloud.firestore.Pipeline; +import com.google.common.base.Objects; import com.google.firestore.v1.Value; import javax.annotation.Nullable; @@ -30,9 +31,21 @@ public Value toProto() { return Value.newBuilder().setFieldReferenceValue(path.toString()).build(); } - @BetaApi - public Exists exists() { - return new Exists(this); + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Field field = (Field) o; + return Objects.equal(path, field.path) && Objects.equal(pipeline, field.pipeline); + } + + @Override + public int hashCode() { + return Objects.hashCode(path, pipeline); } @InternalApi diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java index 827536dce..96f0ca0c3 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Function.java @@ -5,6 +5,7 @@ import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.cloud.firestore.DocumentReference; +import com.google.common.base.Objects; import com.google.common.collect.Lists; import com.google.firestore.v1.Value; import java.util.Arrays; @@ -261,7 +262,7 @@ public static Exists exists(String field) { } @BetaApi - public static Exists exists(Field field) { + public static Exists exists(Expr field) { return new Exists(field); } @@ -719,4 +720,21 @@ public static ArrayElement arrayElement() { public static Function function(String name, List params) { return new Function(name, params); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Function function = (Function) o; + return Objects.equal(name, function.name) && Objects.equal(params, function.params); + } + + @Override + public int hashCode() { + return Objects.hashCode(name, params); + } } From f3934d81bb073717b9c2b2a213b6a2ef84d3f827 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Tue, 30 Jul 2024 11:46:39 -0400 Subject: [PATCH 63/65] Minor fixes --- .../com/google/cloud/firestore/Query.java | 40 +++++++------------ .../firestore/pipeline/stages/StageUtils.java | 2 +- .../cloud/firestore/it/ITPipelineTest.java | 22 +++++++--- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index dfd952b6c..9f7b12197 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -52,7 +52,6 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; import com.google.firestore.bundle.BundledQuery; import com.google.firestore.v1.Cursor; import com.google.firestore.v1.Document; @@ -2140,9 +2139,6 @@ public Pipeline pipeline() { ppl = ppl.where(toPipelineFilterCondition(f)); } - // Collecting implicit exists fields. - Set exists = new HashSet<>(); - // Projections if (this.options.getFieldProjections() != null && !this.options.getFieldProjections().isEmpty()) { @@ -2151,15 +2147,25 @@ public Pipeline pipeline() { this.options.getFieldProjections().stream() .map(fieldReference -> Field.of(fieldReference.getFieldPath())) .toArray(Selectable[]::new)); - exists.addAll( - this.options.getFieldProjections().stream() - .map(fieldReference -> Field.of(fieldReference.getFieldPath()).exists()) - .collect(Collectors.toList())); } // Orders List normalizedOrderbys = this.createImplicitOrderBy(); if (normalizedOrderbys != null && !normalizedOrderbys.isEmpty()) { + // Add exists filters to match Query's implicit orderby semantics. + List exists = + normalizedOrderbys.stream() + // .filter(order -> !order.fieldReference.getFieldPath().equals("__name__")) + .map(order -> Field.of(order.fieldReference.getFieldPath()).exists()) + .collect(Collectors.toList()); + if (exists.size() > 1) { + ppl = + ppl.where( + and(exists.get(0), exists.subList(1, exists.size()).toArray(new Exists[] {}))); + } else if (exists.size() == 1) { + ppl = ppl.where(exists.get(0)); + } + List orders = normalizedOrderbys.stream() .map( @@ -2170,24 +2176,6 @@ public Pipeline pipeline() { ? Ordering.Direction.ASCENDING : Ordering.Direction.DESCENDING)) .collect(Collectors.toList()); - - // Add exists filters to match Query's implicit orderby semantics. - exists.addAll( - normalizedOrderbys.stream() - // .filter(order -> !order.fieldReference.getFieldPath().equals("__name__")) - .map(order -> Field.of(order.fieldReference.getFieldPath()).exists()) - .collect(Collectors.toList())); - List existsList = Lists.newArrayList(exists); - if (existsList.size() > 1) { - ppl = - ppl.where( - and( - existsList.get(0), - existsList.subList(1, existsList.size()).toArray(new Exists[] {}))); - } else if (exists.size() == 1) { - ppl = ppl.where(existsList.get(0)); - } - ppl = ppl.sort(orders, Density.REQUIRED, Truncation.UNSPECIFIED); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java index 5aef5fea7..6d4bd3f9b 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/StageUtils.java @@ -83,8 +83,8 @@ public static com.google.firestore.v1.Pipeline.Stage toStageProto(Stage stage) { Aggregate aggregateStage = (Aggregate) stage; return com.google.firestore.v1.Pipeline.Stage.newBuilder() .setName(aggregateStage.getName()) - .addArgs(encodeValue(aggregateStage.getGroups())) .addArgs(encodeValue(aggregateStage.getAccumulators())) + .addArgs(encodeValue(aggregateStage.getGroups())) .build(); } else if (stage instanceof Distinct) { Distinct distinctStage = (Distinct) stage; diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java index 9a066c8bb..4e6dfa2b8 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java @@ -449,7 +449,12 @@ public void testArrayContainsAny() throws Exception { @Test public void testArrayContainsAll() throws Exception { List results = - collection.pipeline().where(arrayContainsAll("tags", "adventure", "magic")).execute().get(); + collection + .pipeline() + .where(arrayContainsAll("tags", "adventure", "magic")) + .select("title") + .execute() + .get(); assertThat(data(results)).isEqualTo(Lists.newArrayList(map("title", "The Lord of the Rings"))); } @@ -492,15 +497,14 @@ public void testArrayFilter() throws Exception { collection .pipeline() .select( - arrayFilter(Field.of("tags"), Function.eq(arrayElement(), "")).as("filteredTags")) + arrayFilter(Field.of("tags"), Function.eq(arrayElement(), "comedy")) + .as("filteredTags")) .limit(1) .execute() .get(); assertThat(data(results)) - .isEqualTo( - Lists.newArrayList( - map("filteredTags", Lists.newArrayList("comedy", "space", "adventure")))); + .isEqualTo(Lists.newArrayList(map("filteredTags", Lists.newArrayList("comedy")))); } @Test @@ -832,6 +836,14 @@ public void testDistanceFunctions() throws Exception { .limit(1) .execute() .get(); + + assertThat(data(results)) + .isEqualTo( + Lists.newArrayList( + map( + "cosineDistance", 0.02560880430538015, + "dotProductDistance", 0.13, + "euclideanDistance", 0.806225774829855))); } @Test From a5f852ba34224101501b93258a595e56fc6131d8 Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Tue, 30 Jul 2024 12:22:10 -0400 Subject: [PATCH 64/65] Delete AccumulatorTarget --- .../java/com/google/cloud/firestore/AggregateQuery.java | 4 ++-- .../main/java/com/google/cloud/firestore/Pipeline.java | 5 +++-- .../java/com/google/cloud/firestore/PipelineUtils.java | 3 ++- .../cloud/firestore/pipeline/expressions/Accumulator.java | 4 ++-- .../firestore/pipeline/expressions/ExprWithAlias.java | 8 ++++---- .../google/cloud/firestore/pipeline/stages/Aggregate.java | 8 +++----- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java index 253afdbbc..25bbcc059 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/AggregateQuery.java @@ -25,7 +25,7 @@ import com.google.api.gax.rpc.StatusCode; import com.google.api.gax.rpc.StreamController; import com.google.cloud.Timestamp; -import com.google.cloud.firestore.pipeline.expressions.AccumulatorTarget; +import com.google.cloud.firestore.pipeline.expressions.ExprWithAlias; import com.google.cloud.firestore.v1.FirestoreSettings; import com.google.common.collect.ImmutableMap; import com.google.firestore.v1.RunAggregationQueryRequest; @@ -75,7 +75,7 @@ public Pipeline pipeline() { .aggregate( this.aggregateFieldList.stream() .map(PipelineUtils::toPipelineAggregatorTarget) - .toArray(AccumulatorTarget[]::new)); + .toArray(ExprWithAlias[]::new)); } /** diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java index 4b757bbe8..24c1c1f03 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java @@ -9,7 +9,8 @@ import com.google.api.gax.rpc.StreamController; import com.google.cloud.Timestamp; import com.google.cloud.firestore.pipeline.PaginatingPipeline; -import com.google.cloud.firestore.pipeline.expressions.AccumulatorTarget; +import com.google.cloud.firestore.pipeline.expressions.Accumulator; +import com.google.cloud.firestore.pipeline.expressions.ExprWithAlias; import com.google.cloud.firestore.pipeline.expressions.Field; import com.google.cloud.firestore.pipeline.expressions.FilterCondition; import com.google.cloud.firestore.pipeline.expressions.Ordering; @@ -156,7 +157,7 @@ public Pipeline limit(int limit) { } @BetaApi - public Pipeline aggregate(AccumulatorTarget... accumulators) { + public Pipeline aggregate(ExprWithAlias... accumulators) { return new Pipeline( this.db, ImmutableList.builder() diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java index 828b2e2f4..649c28a56 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java @@ -14,6 +14,7 @@ import com.google.cloud.firestore.Query.LimitType; import com.google.cloud.firestore.Query.UnaryFilterInternal; import com.google.cloud.firestore.pipeline.PaginatingPipeline; +import com.google.cloud.firestore.pipeline.expressions.Accumulator; import com.google.cloud.firestore.pipeline.expressions.AccumulatorTarget; import com.google.cloud.firestore.pipeline.expressions.Expr; import com.google.cloud.firestore.pipeline.expressions.ExprWithAlias; @@ -158,7 +159,7 @@ static Pipeline toPaginatedPipeline( } @InternalApi - static AccumulatorTarget toPipelineAggregatorTarget(AggregateField f) { + static ExprWithAlias toPipelineAggregatorTarget(AggregateField f) { String operator = f.getOperator(); String fieldPath = f.getFieldPath(); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Accumulator.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Accumulator.java index c2041d8f4..e851d28e3 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Accumulator.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Accumulator.java @@ -6,7 +6,7 @@ public interface Accumulator extends Expr { @BetaApi @Override - default AccumulatorTarget as(String fieldName) { - return new AccumulatorTarget(this, fieldName, false); + default ExprWithAlias as(String fieldName) { + return new ExprWithAlias<>(this, fieldName); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ExprWithAlias.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ExprWithAlias.java index 7b0c8c8a7..48802af5a 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ExprWithAlias.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/ExprWithAlias.java @@ -3,13 +3,13 @@ import com.google.api.core.InternalApi; @InternalApi -public final class ExprWithAlias implements Selectable { +public final class ExprWithAlias implements Selectable { private final String alias; - private final Expr expr; + private final T expr; @InternalApi - ExprWithAlias(Expr expr, String alias) { + ExprWithAlias(T expr, String alias) { this.expr = expr; this.alias = alias; } @@ -20,7 +20,7 @@ public String getAlias() { } @InternalApi - public Expr getExpr() { + public T getExpr() { return expr; } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java index 5e4e5d83f..d3e9459ea 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Aggregate.java @@ -4,8 +4,8 @@ import com.google.api.core.InternalApi; import com.google.cloud.firestore.PipelineUtils; import com.google.cloud.firestore.pipeline.expressions.Accumulator; -import com.google.cloud.firestore.pipeline.expressions.AccumulatorTarget; import com.google.cloud.firestore.pipeline.expressions.Expr; +import com.google.cloud.firestore.pipeline.expressions.ExprWithAlias; import com.google.cloud.firestore.pipeline.expressions.Selectable; import java.util.Arrays; import java.util.Collections; @@ -30,7 +30,7 @@ public Aggregate withGroups(Selectable... selectables) { } @BetaApi - public static Aggregate withAccumulators(AccumulatorTarget... accumulators) { + public static Aggregate withAccumulators(ExprWithAlias... accumulators) { if (accumulators.length == 0) { throw new IllegalArgumentException( "Must specify at least one accumulator for aggregate() stage. There is a distinct() stage if only distinct group values are needed."); @@ -39,9 +39,7 @@ public static Aggregate withAccumulators(AccumulatorTarget... accumulators) { return new Aggregate( Collections.emptyMap(), Arrays.stream(accumulators) - .collect( - Collectors.toMap( - AccumulatorTarget::getFieldName, AccumulatorTarget::getAccumulator))); + .collect(Collectors.toMap(ExprWithAlias::getAlias, ExprWithAlias::getExpr))); } private Aggregate(Map groups, Map accumulators) { From 841cafc64b9a46ded30904d81ea04299a524194f Mon Sep 17 00:00:00 2001 From: Wu-Hui Date: Fri, 2 Aug 2024 14:17:42 -0400 Subject: [PATCH 65/65] Add public docs 1. --- .../com/google/cloud/firestore/Pipeline.java | 543 +++++++++- .../cloud/firestore/PipelineResult.java | 66 +- .../cloud/firestore/PipelineSource.java | 50 + .../google/cloud/firestore/PipelineUtils.java | 34 +- .../com/google/cloud/firestore/Query.java | 8 +- .../firestore/pipeline/expressions/Expr.java | 940 +++++++++++++++++- .../pipeline/expressions/Ordering.java | 10 - .../pipeline/stages/FindNearest.java | 31 +- .../cloud/firestore/pipeline/stages/Join.java | 3 +- 9 files changed, 1540 insertions(+), 145 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java index 24c1c1f03..bdbfbb747 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java @@ -2,17 +2,19 @@ import com.google.api.core.ApiFuture; import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; import com.google.api.core.InternalExtensionOnly; import com.google.api.core.SettableApiFuture; import com.google.api.gax.rpc.ApiStreamObserver; import com.google.api.gax.rpc.ResponseObserver; import com.google.api.gax.rpc.StreamController; import com.google.cloud.Timestamp; -import com.google.cloud.firestore.pipeline.PaginatingPipeline; import com.google.cloud.firestore.pipeline.expressions.Accumulator; +import com.google.cloud.firestore.pipeline.expressions.Expr; import com.google.cloud.firestore.pipeline.expressions.ExprWithAlias; import com.google.cloud.firestore.pipeline.expressions.Field; import com.google.cloud.firestore.pipeline.expressions.FilterCondition; +import com.google.cloud.firestore.pipeline.expressions.Function; import com.google.cloud.firestore.pipeline.expressions.Ordering; import com.google.cloud.firestore.pipeline.expressions.Selectable; import com.google.cloud.firestore.pipeline.stages.AddFields; @@ -44,7 +46,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; @@ -53,33 +54,51 @@ * The Pipeline class provides a flexible and expressive framework for building complex data * transformation and query pipelines for Firestore. * - *

A pipeline takes data sources such as Firestore collections, collection groups, or even - * in-memory data, and applies a series of operations that are chained together, each operation - * takes the output from the last operation (or the data source) and produces an output for the next - * operation (or as the final output of the pipeline). + *

A pipeline takes data sources, such as Firestore collections or collection groups, and applies + * a series of stages that are chained together. Each stage takes the output from the previous stage + * (or the data source) and produces an output for the next stage (or as the final output of the + * pipeline). * - *

NOTE: the chained operations are not a prescription of exactly how Firestore will execute the - * pipeline, instead Firestore only guarantee the result is the same as if the chained operations - * are executed in order. + *

Expressions from {@link com.google.cloud.firestore.pipeline.expressions} can be used within + * each stages to filter and transform data through the stage. * - *

Usage Examples: - * - *

**1. Projecting Specific Fields and Renaming:** + *

NOTE: The chained stages do not prescribe exactly how Firestore will execute the pipeline. + * Instead, Firestore only guarantees that the result is the same as if the chained stages were + * executed in order. * - *

```java Pipeline pipeline = Pipeline.fromCollection("users") // Select 'name' and 'email' - * fields, create 'userAge' which is renamed from field 'age'. .project(Fields.of("name", "email"), - * Field.of("age").asAlias("userAge")) ``` + *

Usage Examples: * - *

**2. Filtering and Sorting:** + *

{@code
+ * Firestore firestore; // A valid firestore instance.
  *
- * 

```java Pipeline pipeline = Pipeline.fromCollectionGroup("reviews") - * .filter(Field.of("rating").greaterThan(Expr.Constant.of(3))) // High ratings - * .sort(Ordering.of("timestamp").descending()); ``` + * // Example 1: Select specific fields and rename 'rating' to 'bookRating' + * List results1 = firestore.pipeline() + * .collection("books") + * .select("title", "author", Field.of("rating").as("bookRating")) + * .execute() + * .get(); * - *

**3. Aggregation with Grouping:** + * // Example 2: Filter documents where 'genre' is "Science Fiction" and 'published' is after 1950 + * List results2 = firestore.pipeline() + * .collection("books") + * .where(and(eq("genre", "Science Fiction"), gt("published", 1950))) + * .execute() + * .get(); + * // Same as above but using methods on expressions as opposed to static functions. + * results2 = firestore.pipeline() + * .collection("books") + * .where(and(Field.of("genre").eq("Science Fiction"), Field.of("published").gt(1950))) + * .execute() + * .get(); * - *

```java Pipeline pipeline = Pipeline.fromCollection("orders") .group(Field.of("customerId")) - * .aggregate(count(Field.of("orderId")).asAlias("orderCount")); ``` + * // Example 3: Calculate the average rating of books published after 1980 + * List results3 = firestore.pipeline() + * .collection("books") + * .where(gt("published", 1980)) + * .aggregate(avg("rating").as("averageRating")) + * .execute() + * .get(); + * }

*/ @BetaApi public final class Pipeline { @@ -92,22 +111,55 @@ private Pipeline(Firestore db, List stages) { this.stages = ImmutableList.copyOf(stages); } + @InternalApi Pipeline(Firestore db, Collection collection) { this(db, Lists.newArrayList(collection)); } + @InternalApi Pipeline(Firestore db, CollectionGroup group) { this(db, Lists.newArrayList(group)); } + @InternalApi Pipeline(Firestore firestore, Database db) { this(firestore, Lists.newArrayList(db)); } + @InternalApi Pipeline(Firestore db, Documents docs) { this(db, Lists.newArrayList(docs)); } + /** + * Adds new fields to outputs from previous stages. + * + *

This stage allows you to compute values on-the-fly based on existing data from previous + * stages or constants. You can use this to create new fields or overwrite existing ones (if there + * is name overlaps). + * + *

The added fields are defined using {@link Selectable} expressions, which can be: + * + *

    + *
  • {@link Field}: References an existing document field. + *
  • {@link Function}: Performs a calculation using functions like `add`, `multiply` with + * assigned aliases using {@link + * com.google.cloud.firestore.pipeline.expressions.Expr#as(String)}. + *
+ * + *

Example: + * + *

{@code
+   * firestore.pipeline().collection("books")
+   *   .addFields(
+   *     Field.of("rating").as("bookRating"), // Rename 'rating' to 'bookRating'
+   *     add(5, Field.of("quantity")).as("totalCost")  // Calculate 'totalCost'
+   *   );
+   * }
+ * + * @param fields The fields to add to the documents, specified as {@link Selectable} expressions. + * @return A new Pipeline object with this stage appended to the stage list. + */ @BetaApi public Pipeline addFields(Selectable... fields) { return new Pipeline( @@ -118,16 +170,66 @@ public Pipeline addFields(Selectable... fields) { .build()); } + /** + * Selects or creates a set of fields from the outputs of previous stages. + * + *

The selected fields are defined using {@link Selectable} expressions, which can be: + * + *

    + *
  • {@link Field}: References an existing document field. + *
  • {@link Function}: Represents the result of a function with an assigned alias name using + * {@link com.google.cloud.firestore.pipeline.expressions.Expr#as(String)} + *
+ * + *

If no selections are provided, the output of this stage is empty. Use {@link + * com.google.cloud.firestore.Pipeline#addFields(Selectable...)} instead if only additions are + * desired. + * + *

Example: + * + *

{@code
+   * firestore.pipeline().collection("books")
+   *   .select(
+   *     Field.of("name"),
+   *     Field.of("address").toUppercase().as("upperAddress"),
+   *   );
+   * }
+ * + * @param selections The fields to include in the output documents, specified as {@link + * Selectable} expressions. + * @return A new Pipeline object with this stage appended to the stage list. + */ @BetaApi - public Pipeline select(Selectable... projections) { + public Pipeline select(Selectable... selections) { return new Pipeline( this.db, ImmutableList.builder() .addAll(stages) - .add(new Select(PipelineUtils.selectablesToMap(projections))) + .add(new Select(PipelineUtils.selectablesToMap(selections))) .build()); } + /** + * Selects a set of fields from the outputs of previous stages. + * + *

If no selections are provided, the output of this stage is empty. Use {@link + * com.google.cloud.firestore.Pipeline#addFields(Selectable...)} instead if only additions are + * desired. + * + *

Example: + * + *

{@code
+   * firestore.collection("books")
+   *   .select("name", "address");
+   *
+   * // The above is a shorthand of this:
+   * firestore.pipeline().collection("books")
+   *    .select(Field.of("name"), Field.of("address"));
+   * }
+ * + * @param fields The name of the fields to include in the output documents. + * @return A new Pipeline object with this stage appended to the stage list. + */ @BetaApi public Pipeline select(String... fields) { return new Pipeline( @@ -138,24 +240,122 @@ public Pipeline select(String... fields) { .build()); } + /** + * Filters the documents from previous stages to only include those matching the specified {@link + * FilterCondition}. + * + *

This stage allows you to apply conditions to the data, similar to a "WHERE" clause in SQL. + * You can filter documents based on their field values, using implementions of {@link + * FilterCondition}, typically including but not limited to: + * + *

    + *
  • field comparators: {@link Function#eq}, {@link Function#lt} (less than), {@link + * Function#gt} (greater than), etc. + *
  • logical operators: {@link Function#and}, {@link Function#or}, {@link Function#not}, etc. + *
  • advanced functions: {@link Function#regexMatch(String, String)}, {@link + * Function#arrayContains(Expr, Expr)}, etc. + *
+ * + *

Example: + * + *

{@code
+   * firestore.pipeline().collection("books")
+   *   .where(
+   *     and(
+   *         gt("rating", 4.0),   // Filter for ratings greater than 4.0
+   *         Field.of("genre").eq("Science Fiction") // Equivalent to gt("genre", "Science Fiction")
+   *     )
+   *   );
+   * }
+ * + * @param condition The {@link FilterCondition} to apply. + * @return A new Pipeline object with this stage appended to the stage list. + */ @BetaApi public Pipeline where(FilterCondition condition) { return new Pipeline( this.db, ImmutableList.builder().addAll(stages).add(new Where(condition)).build()); } + /** + * Skips the first `offset` number of documents from the results of previous stages. + * + *

This stage is useful for implementing pagination in your pipelines, allowing you to retrieve + * results in chunks. It is typically used in conjunction with {@link #limit(int)} to control the + * size of each page. + * + *

Example: + * + *

{@code
+   * // Retrieve the second page of 20 results
+   * firestore.pipeline().collection("books")
+   *     .sort(Field.of("published").descending())
+   *     .offset(20)  // Skip the first 20 results
+   *     .limit(20);   // Take the next 20 results
+   * }
+ * + * @param offset The number of documents to skip. + * @return A new Pipeline object with this stage appended to the stage list. + */ @BetaApi public Pipeline offset(int offset) { return new Pipeline( this.db, ImmutableList.builder().addAll(stages).add(new Offset(offset)).build()); } + /** + * Limits the maximum number of documents returned by previous stages to `limit`. + * + *

This stage is particularly useful when you want to retrieve a controlled subset of data from + * a potentially large result set. It's often used for: + * + *

    + *
  • **Pagination:** In combination with {@link #offset(int)} to retrieve specific pages of + * results. + *
  • **Limiting Data Retrieval:** To prevent excessive data transfer and improve performance, + * especially when dealing with large collections. + *
+ * + *

Example: + * + *

{@code
+   * // Limit the results to the top 10 highest-rated books
+   * firestore.pipeline().collection("books")
+   *     .sort(Field.of("rating").descending())
+   *     .limit(10);
+   * }
+ * + * @param limit The maximum number of documents to return. + * @return A new Pipeline object with this stage appended to the stage list. + */ @BetaApi public Pipeline limit(int limit) { return new Pipeline( this.db, ImmutableList.builder().addAll(stages).add(new Limit(limit)).build()); } + /** + * Performs aggregation operations on the documents from previous stages. + * + *

This stage allows you to calculate aggregate values over a set of documents. You define the + * aggregations to perform using {@link ExprWithAlias} expressions which are typically results of + * calling {@link Expr#as(String)} on {@link Accumulator} instances. + * + *

Example: + * + *

{@code
+   * // Calculate the average rating and the total number of books
+   * firestore.pipeline().collection("books")
+   *     .aggregate(
+   *         Field.of("rating").avg().as("averageRating"),
+   *         countAll().as("totalBooks")
+   *     );
+   * }
+ * + * @param accumulators The {@link ExprWithAlias} expressions, each wrapping an {@link Accumulator} + * and provide a name for the accumulated results. + * @return A new Pipeline object with this stage appended to the stage list. + */ @BetaApi public Pipeline aggregate(ExprWithAlias... accumulators) { return new Pipeline( @@ -166,12 +366,61 @@ public Pipeline aggregate(ExprWithAlias... accumulators) { .build()); } + /** + * Performs optionally grouped aggregation operations on the documents from previous stages. + * + *

This stage allows you to calculate aggregate values over a set of documents, optionally + * grouped by one or more fields or functions. You can specify: + * + *

    + *
  • **Grouping Fields or Functions:** One or more fields or functions to group the documents + * by. For each distinct combination of values in these fields, a separate group is created. + * If no grouping fields are provided, a single group containing all documents is used. Not + * specifying groups is the same as putting the entire inputs into one group. + *
  • **Accumulators:** One or more accumulation operations to perform within each group. These + * are defined using {@link ExprWithAlias} expressions, which are typically created by + * calling {@link Expr#as(String)} on {@link Accumulator} instances. Each aggregation + * calculates a value (e.g., sum, average, count) based on the documents within its group. + *
+ * + *

Example: + * + *

{@code
+   * // Calculate the average rating for each genre.
+   * firestore.pipeline().collection("books")
+   *   .aggregate(
+   *     Aggregate
+   *       .withAccumulators(avg("rating").as("avg_rating"))
+   *       .withGroups("genre"));
+   * }
+ * + * @param aggregate An {@link Aggregate} object that specifies the grouping fields (if any) and + * the aggregation operations to perform. + * @return A new {@code Pipeline} object with this stage appended to the stage list. + */ @BetaApi public Pipeline aggregate(Aggregate aggregate) { return new Pipeline( this.db, ImmutableList.builder().addAll(stages).add(aggregate).build()); } + /** + * Returns a set of distinct field values from the inputs to this stage. + * + *

This stage run through the results from previous stages to include only results with unique + * combinations of values for the specified fields and produce these fields as the output. + * + *

Example: + * + *

{@code
+   * // Get a list of unique genres.
+   * firestore.pipeline().collection("books")
+   *     .distinct("genre");
+   * }
+ * + * @param fields The fields to consider when determining distinct values. + * @return A new {@code Pipeline} object with this stage appended to the stage list. + */ @BetaApi public Pipeline distinct(String... fields) { return new Pipeline( @@ -182,6 +431,33 @@ public Pipeline distinct(String... fields) { .build()); } + /** + * Returns a set of distinct {@link Expr} values from the inputs to this stage. + * + *

This stage run through the results from previous stages to include only results with unique + * combinations of {@link Expr} values ({@link Field}, {@link Function}, etc). + * + *

The parameters to this stage are defined using {@link Selectable} expressions, which can be: + * + *

    + *
  • {@link Field}: References an existing document field. + *
  • {@link Function}: Represents the result of a function with an assigned alias name using + * {@link com.google.cloud.firestore.pipeline.expressions.Expr#as(String)} + *
+ * + *

Example: + * + *

{@code
+   * // Get a list of unique author names in uppercase and genre combinations.
+   * firestore.pipeline().collection("books")
+   *     .distinct(toUppercase(Field.of("author")).as("authorName"), Field.of("genre"))
+   *     .select("authorName");
+   * }
+ * + * @param selectables The {@link Selectable} expressions to consider when determining distinct + * value combinations. + * @return A new {@code Pipeline} object with this stage appended to the stage list. + */ @BetaApi public Pipeline distinct(Selectable... selectables) { return new Pipeline( @@ -192,15 +468,65 @@ public Pipeline distinct(Selectable... selectables) { .build()); } + /** + * Performs vector distance (similarity) search with given parameters to the stage inputs. + * + *

This stage adds a "nearest neighbor search" capability to your pipelines. Given a field that + * stores vectors and a target vector, this stage will identify and return the inputs whose vector + * field is closest to the target vector, using the parameters specified in `options`. + * + *

Example: + * + *

{@code
+   * // Find books with similar "topicVectors" to the given targetVector
+   * firestore.pipeline().collection("books")
+   *     .findNearest("topicVectors", targetVector,
+   *        FindNearestOptions
+   *          .withLimitAndMeasure(10, DistanceMeasure.cosine())
+   *          .withOutputField("distance"));
+   * }
+ * + * @param fieldName The name of the field containing the vector data. This field should store + * {@link VectorValue}. + * @param vector The target vector to compare against. + * @param options Configuration options for the nearest neighbor search, such as the distance + * metric to use. + * @return A new {@code Pipeline} object with this stage appended to the stage list. + */ @BetaApi public Pipeline findNearest( String fieldName, double[] vector, FindNearest.FindNearestOptions options) { return findNearest(Field.of(fieldName), vector, options); } + /** + * Performs vector distance (similarity) search with given parameters to the stage inputs. + * + *

This stage adds a "nearest neighbor search" capability to your pipelines. Given an + * expression that evaluates to a vector and a target vector, this stage will identify and return + * the inputs whose vector expression is closest to the target vector, using the parameters + * specified in `options`. + * + *

Example: + * + *

{@code
+   * // Find books with similar "topicVectors" to the given targetVector
+   * firestore.pipeline().collection("books")
+   *     .findNearest(Field.of("topicVectors"), targetVector,
+   *        FindNearestOptions
+   *          .withLimitAndMeasure(10, DistanceMeasure.cosine())
+   *          .withOutputField("distance"));
+   * }
+ * + * @param property The expression that evaluates to a vector value using the stage inputs. + * @param vector The target vector to compare against. + * @param options Configuration options for the nearest neighbor search, such as the distance + * metric to use. + * @return A new {@code Pipeline} object with this stage appended to the stage list. + */ @BetaApi public Pipeline findNearest( - Field property, double[] vector, FindNearest.FindNearestOptions options) { + Expr property, double[] vector, FindNearest.FindNearestOptions options) { // Implementation for findNearest (add the FindNearest stage if needed) return new Pipeline( this.db, @@ -212,6 +538,37 @@ public Pipeline findNearest( .build()); } + /** + * Sorts the documents from previous stages based on one or more {@link Ordering} criteria. + * + *

This stage allows you to order the results of your pipeline. You can specify multiple {@link + * Ordering} instances to sort by multiple fields in ascending or descending order. If documents + * have the same value for a field used for sorting, the next specified ordering will be used. If + * all orderings result in equal comparison, the documents are considered equal, and the order is + * unspecified. + * + *

Example: + * + *

{@code
+   * // Sort books by rating in descending order, and then by title in ascending order for books
+   * // with the same rating, with density required and truncation disabled.
+   * firestore.pipeline().collection("books")
+   *     .sort(
+   *         Arrays.asList(Ordering.of("rating").descending(), Ordering.of("title")),
+   *         Sort.Density.REQUIRED,
+   *         Sort.Truncation.DISABLED,
+   *         10);
+   * }
+ * + * @param orders One or more {@link Ordering} instances specifying the sorting criteria. + * @param density Specifies the index density semantics. See {@link + * com.google.cloud.firestore.pipeline.stages.Sort.Density} for more information on density + * sorting. + * @param truncation Specifies the index truncation semantics. See {@link + * com.google.cloud.firestore.pipeline.stages.Sort.Truncation} for more information on + * truncation options. + * @return A new {@code Pipeline} object with this stage appended to the stage list. + */ @BetaApi public Pipeline sort(List orders, Sort.Density density, Sort.Truncation truncation) { return new Pipeline( @@ -222,32 +579,99 @@ public Pipeline sort(List orders, Sort.Density density, Sort.Truncatio .build()); } - // Sugar + /** + * Sorts the documents from previous stages based on one or more {@link Ordering} criteria. + * + *

This stage allows you to order the results of your pipeline. You can specify multiple {@link + * Ordering} instances to sort by multiple fields in ascending or descending order. If documents + * have the same value for a field used for sorting, the next specified ordering will be used. If + * all orderings result in equal comparison, the documents are considered equal and the order is + * unspecified. + * + *

Example: + * + *

{@code
+   * // Sort books by rating in descending order, and then by title in ascending order for books with the same rating
+   * firestore.pipeline().collection("books")
+   *     .sort(
+   *         Ordering.of("rating").descending(),
+   *         Ordering.of("title")  // Ascending order is the default
+   *     );
+   * }
+ * + * @param orders One or more {@link Ordering} instances specifying the sorting criteria. + * @return A new {@code Pipeline} object with this stage appended to the stage list. + */ @BetaApi public Pipeline sort(Ordering... orders) { return sort(Arrays.asList(orders), Sort.Density.UNSPECIFIED, Sort.Truncation.UNSPECIFIED); } + /** + * Adds a generic stage to the pipeline. + * + *

This method provides a flexible way to extend the pipeline's functionality by adding custom + * stages. Each generic stage is defined by a unique `name` and a set of `params` that control its + * behavior. + * + *

Example (Assuming there is no "where" stage available in SDK): + * + *

{@code
+   * // Assume we don't have a built-in "where" stage
+   * Map whereParams = new HashMap<>();
+   * whereParams.put("condition", Field.of("published").lt(1900));
+   *
+   * firestore.pipeline().collection("books")
+   *     .genericStage("where", Lists.newArrayList(Field.of("published").lt(1900))) // Custom "where" stage
+   *     .select("title", "author");
+   * }
+ * + * @param name The unique name of the generic stage to add. + * @param params A map of parameters to configure the generic stage's behavior. + * @return A new {@code Pipeline} object with this stage appended to the stage list. + */ @BetaApi - public PaginatingPipeline paginate(int pageSize, Ordering... orders) { - return new PaginatingPipeline(this, pageSize, Arrays.asList(orders)); - } - - @BetaApi - public Pipeline genericStage(String name, Map params) { + public Pipeline genericStage(String name, List params) { // Implementation for genericStage (add the GenericStage if needed) return new Pipeline( this.db, ImmutableList.builder() .addAll(stages) - .add( - new GenericStage( - name, - Lists.newArrayList( - params.values()))) // Assuming GenericStage takes a list of params + .add(new GenericStage(name, params)) // Assuming GenericStage takes a list of params .build()); } + /** + * Executes this pipeline and returns a future to represent the asynchronous operation. + * + *

The returned {@link ApiFuture} can be used to track the progress of the pipeline execution + * and retrieve the results (or handle any errors) asynchronously. + * + *

The pipeline results are returned as a list of {@link PipelineResult} objects. Each {@link + * PipelineResult} typically represents a single key/value map that has passed through all the + * stages of the pipeline, however this might differ depends on the stages involved in the + * pipeline. For example: + * + *

    + *
  • If there are no stages or only transformation stages, each {@link PipelineResult} + * represents a single document. + *
  • If there is an aggregation, only a single {@link PipelineResult} is returned, + * representing the aggregated results over the entire dataset . + *
  • If there is an aggregation stage with grouping, each {@link PipelineResult} represents a + * distinct group and its associated aggregated values. + *
+ * + *

Example: + * + *

{@code
+   * ApiFuture> futureResults = firestore.pipeline().collection("books")
+   *     .where(gt("rating", 4.5))
+   *     .select("title", "author", "rating")
+   *     .execute();
+   * }
+ * + * @return An {@link ApiFuture} representing the asynchronous pipeline execution. + */ @BetaApi public ApiFuture> execute() { if (db instanceof FirestoreImpl) { @@ -293,6 +717,51 @@ public void onError(Throwable t) { } } + /** + * Executes this pipeline, providing results to the given {@link ApiStreamObserver} as they become + * available. + * + *

This method allows you to process pipeline results in a streaming fashion, rather than + * waiting for the entire pipeline execution to complete. The provided {@link ApiStreamObserver} + * will receive: + * + *

    + *
  • **onNext(PipelineResult):** Called for each {@link PipelineResult} produced by the + * pipeline. Each {@link PipelineResult} typically represents a single key/value map that + * has passed through all the stages. However, the exact structure might differ based on the + * stages involved in the pipeline (as described in {@link #execute()}). + *
  • **onError(Throwable):** Called if an error occurs during pipeline execution. + *
  • **onCompleted():** Called when the pipeline has finished processing all documents. + *
+ * + *

Example: + * + *

{@code
+   * firestore.pipeline().collection("books")
+   *     .where(gt("rating", 4.5))
+   *     .select("title", "author", "rating")
+   *     .execute(new ApiStreamObserver() {
+   *         @Override
+   *         public void onNext(PipelineResult result) {
+   *             // Process each result as it arrives
+   *             System.out.println(result.getData());
+   *         }
+   *
+   *         @Override
+   *         public void onError(Throwable t) {
+   *             // Handle errors during execution
+   *             t.printStackTrace();
+   *         }
+   *
+   *         @Override
+   *         public void onCompleted() {
+   *             System.out.println("Pipeline execution completed.");
+   *         }
+   *     });
+   * }
+ * + * @param observer The {@link ApiStreamObserver} to receive pipeline results and events. + */ @BetaApi public void execute(ApiStreamObserver observer) { if (db instanceof FirestoreImpl) { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.java index 05647d580..e99190b41 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineResult.java @@ -32,12 +32,11 @@ import javax.annotation.Nullable; /** - * A DocumentSnapshot contains data read from a document in a Firestore database. The data can be - * extracted with the {@link #getData()} or {@link #get(String)} methods. + * A PipelineResult contains data read from a Firestore Pipeline. The data can be extracted with the + * {@link #getData()} or {@link #get(String)} methods. * - *

If the DocumentSnapshot points to a non-existing document, getData() and its corresponding - * methods will return null. You can always explicitly check for a document's existence by calling - * {@link #exists()}. + *

If the PipelineResult represents a non-document result, getReference() will return a null + * value. * *

Subclassing Note: Firestore classes are not meant to be subclassed except for use in * test mocks. Subclassing is not supported in production code and new SDK releases may break code @@ -50,7 +49,7 @@ public final class PipelineResult { private final FirestoreRpcContext rpcContext; @Nullable private final DocumentReference docRef; @Nullable private final Map fields; - @Nullable private final Timestamp readTime; + @Nonnull private final Timestamp executionTime; @Nullable private final Timestamp updateTime; @Nullable private final Timestamp createTime; @@ -58,23 +57,22 @@ public final class PipelineResult { FirestoreRpcContext rpcContext, @Nullable DocumentReference docRef, @Nullable Map fields, - @Nullable Timestamp readTime, + @Nonnull Timestamp executionTime, @Nullable Timestamp updateTime, @Nullable Timestamp createTime) { // Elevated access level for mocking. this.rpcContext = rpcContext; this.docRef = docRef; this.fields = fields; - this.readTime = readTime; + this.executionTime = executionTime; this.updateTime = updateTime; this.createTime = createTime; } /** - * Returns the ID of the document contained in this snapshot. - * - * @return The id of the document. + * Returns the ID of the document represented by this result. Returns null if this result is not + * corresponding to a Firestore document. */ - @Nonnull + @Nullable @BetaApi public String getId() { return docRef.getId(); @@ -93,23 +91,16 @@ static PipelineResult fromDocument( Timestamp.fromProto(document.getCreateTime())); } - /** - * Returns the time at which this snapshot was read. - * - * @return The read time of this snapshot. - */ + /** Returns the time at which the pipeline producing this result is executed. */ @Nullable @BetaApi - public Timestamp getReadTime() { - return readTime; + public Timestamp getExecutionTime() { + return executionTime; } /** - * Returns the time at which this document was last updated. Returns null for non-existing - * documents. - * - * @return The last time the document in the snapshot was updated. Null if the document doesn't - * exist. + * Returns the time at which this document was last updated. Returns null if this result is not + * corresponding to a Firestore document. */ @Nullable @BetaApi @@ -118,10 +109,8 @@ public Timestamp getUpdateTime() { } /** - * Returns the time at which this document was created. Returns null for non-existing documents. - * - * @return The last time the document in the snapshot was created. Null if the document doesn't - * exist. + * Returns the time at which this document was created. Returns null if this result is not + * corresponding to a Firestore document. */ @Nullable @BetaApi @@ -141,12 +130,12 @@ public boolean exists() { } /** - * Returns the fields of the document as a Map or null if the document doesn't exist. Field values + * Returns the fields of the result as a Map or null if the result doesn't exist. Field values * will be converted to their native Java representation. * - * @return The fields of the document as a Map or null if the document doesn't exist. + * @return The fields of the document as a Map or null if the result doesn't exist. */ - @Nullable + @Nonnull @BetaApi public Map getData() { if (fields == null) { @@ -162,10 +151,10 @@ public Map getData() { } /** - * Returns the contents of the document converted to a POJO or null if the document doesn't exist. + * Returns the contents of the document converted to a POJO or null if the result doesn't exist. * * @param valueType The Java class to create - * @return The contents of the document in an object of type T or null if the document doesn't + * @return The contents of the document in an object of type T or null if the result doesn't * exist. */ @Nullable @@ -176,7 +165,7 @@ public T toObject(@Nonnull Class valueType) { } /** - * Returns whether or not the field exists in the document. Returns false if the document does not + * Returns whether or not the field exists in the document. Returns false if the result does not * exist. * * @param field the path to the field. @@ -188,7 +177,7 @@ public boolean contains(@Nonnull String field) { } /** - * Returns whether or not the field exists in the document. Returns false if the document does not + * Returns whether or not the field exists in the document. Returns false if the result does not * exist. * * @param fieldPath the path to the field. @@ -212,7 +201,7 @@ public Object get(@Nonnull String field) { } /** - * Returns the value at the field, converted to a POJO, or null if the field or document doesn't + * Returns the value at the field, converted to a POJO, or null if the field or result doesn't * exist. * * @param field The path to the field @@ -244,7 +233,7 @@ public Object get(@Nonnull FieldPath fieldPath) { } /** - * Returns the value at the field, converted to a POJO, or null if the field or document doesn't + * Returns the value at the field, converted to a POJO, or null if the field or result doesn't * exist. * * @param fieldPath The path to the field @@ -390,7 +379,6 @@ public GeoPoint getGeoPoint(@Nonnull String field) { * * @return The reference to the document. */ - @Nonnull @BetaApi public DocumentReference getReference() { return docRef; @@ -455,6 +443,6 @@ public int hashCode() { public String toString() { return String.format( "%s{doc=%s, fields=%s, readTime=%s, updateTime=%s, createTime=%s}", - getClass().getSimpleName(), docRef, fields, readTime, updateTime, createTime); + getClass().getSimpleName(), docRef, fields, executionTime, updateTime, createTime); } } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java index 6fdf6a142..740de02d1 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java @@ -9,6 +9,25 @@ import com.google.common.base.Preconditions; import javax.annotation.Nonnull; +/** + * A factory for creating {@link Pipeline} instances, which provide a framework for building data + * transformation and query pipelines for Firestore. + * + *

Start by calling {@link Firestore#pipeline()} to obtain an instance of {@code PipelineSource}. + * From there, you can use the provided methods (like {@link #collection(String)}) to specify the + * data source for your pipeline. + * + *

This class is typically used to start building Firestore pipelines. It allows you to define + * the initial data source for a pipeline. + * + *

Example Usage: + * + *

{@code
+ * firestore.pipeline() // Get a PipelineSource instance
+ *   .collection("users") // Create a pipeline that operates on a collection
+ *   .select("name"); // Add stages to the pipeline
+ * }
+ */ @BetaApi public class PipelineSource { private final Firestore db; @@ -18,12 +37,28 @@ public class PipelineSource { this.db = db; } + /** + * Creates a new {@link Pipeline} that operates on the specified Firestore collection. + * + * @param path The path to the Firestore collection (e.g., "users"). + * @return A new {@code Pipeline} instance targeting the specified collection. + */ @Nonnull @BetaApi public Pipeline collection(@Nonnull String path) { return new Pipeline(this.db, new Collection(path)); } + /** + * Creates a new {@link Pipeline} that operates on all documents in a collection group. + * + *

A collection group consists of all collections with the same ID. For example, if you have + * collections named "users" under different documents, you can query them together using a + * collection group query. + * + * @param collectionId The ID of the collection group. + * @return A new {@code Pipeline} instance targeting the specified collection group. + */ @Nonnull @BetaApi public Pipeline collectionGroup(@Nonnull String collectionId) { @@ -34,12 +69,27 @@ public Pipeline collectionGroup(@Nonnull String collectionId) { return new Pipeline(this.db, new CollectionGroup(collectionId)); } + /** + * Creates a new {@link Pipeline} that operates on all documents in the Firestore database. + * + *

Use this method with caution as it can lead to very large result sets. It is usually only + * useful at development stage. + * + * @return A new {@code Pipeline} instance targeting all documents in the database. + */ @Nonnull @BetaApi public Pipeline database() { return new Pipeline(this.db, new Database()); } + /** + * Creates a new {@link Pipeline} that operates on a specific set of Firestore documents. + * + * @param docs The {@link DocumentReference} instances representing the documents to include in + * the pipeline. + * @return A new {@code Pipeline} instance targeting the specified documents. + */ @Nonnull @BetaApi public Pipeline documents(DocumentReference... docs) { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java index 649c28a56..21b916e0c 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineUtils.java @@ -13,7 +13,6 @@ import com.google.cloud.firestore.Query.FilterInternal; import com.google.cloud.firestore.Query.LimitType; import com.google.cloud.firestore.Query.UnaryFilterInternal; -import com.google.cloud.firestore.pipeline.PaginatingPipeline; import com.google.cloud.firestore.pipeline.expressions.Accumulator; import com.google.cloud.firestore.pipeline.expressions.AccumulatorTarget; import com.google.cloud.firestore.pipeline.expressions.Expr; @@ -125,37 +124,8 @@ static Pipeline toPaginatedPipeline( Integer limit, LimitType limitType, Integer offset) { - - // Handle null limit, setting a default maximum - int effectiveLimit = (limit != null) ? limit : Integer.MAX_VALUE; - - PaginatingPipeline paginate = pipeline.paginate(effectiveLimit); - - // Apply start and end cursors if present - if (start != null) { - paginate = paginate.withStartCursor(start); - } - if (end != null) { - paginate = paginate.withEndCursor(end); - } - if (offset != null) { - paginate = paginate.offset(offset); - } - - // Handle limitType, defaulting to firstPage - if (limitType != null) { - switch (limitType) { - case First: - return paginate.firstPage(); - case Last: - return paginate.lastPage(); - default: - // Handle other LimitType cases as needed, or throw an exception - throw new IllegalArgumentException("Unsupported limit type: " + limitType); - } - } else { - return paginate.firstPage(); - } + throw new UnsupportedOperationException( + "Converting to pagination pipeline is not support yet."); } @InternalApi diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index 9f7b12197..600848d9b 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -2170,11 +2170,9 @@ public Pipeline pipeline() { normalizedOrderbys.stream() .map( fieldOrder -> - Ordering.of( - Field.of(fieldOrder.fieldReference.getFieldPath()), - fieldOrder.direction == Direction.ASCENDING - ? Ordering.Direction.ASCENDING - : Ordering.Direction.DESCENDING)) + fieldOrder.direction == Direction.ASCENDING + ? Field.of(fieldOrder.fieldReference.getFieldPath()).ascending() + : Field.of(fieldOrder.fieldReference.getFieldPath()).descending()) .collect(Collectors.toList()); ppl = ppl.sort(orders, Density.REQUIRED, Truncation.UNSPECIFIED); } diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java index 12820d14e..a9aac6c34 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expr.java @@ -4,320 +4,1236 @@ import com.google.api.core.BetaApi; import java.util.Arrays; -import java.util.List; +/** + * Represents an expression that can be evaluated to a value within the execution of a {@link + * com.google.cloud.firestore.Pipeline}. + * + *

Expressions are the building blocks for creating complex queries and transformations in + * Firestore pipelines. They can represent: + * + *

    + *
  • **Field references:** Access values from document fields. + *
  • **Literals:** Represent constant values (strings, numbers, booleans). + *
  • **Function calls:** Apply functions to one or more expressions. + *
  • **Aggregations:** Calculate aggregate values (e.g., sum, average) over a set of documents. + *
+ * + *

The `Expr` interface provides a fluent API for building expressions. You can chain together + * method calls to create complex expressions. + */ @BetaApi public interface Expr { + + // Arithmetic Operators + + /** + * Creates an expression that adds this expression to another expression. + * + *

Example: + * + *

{@code
+   * // Add the value of the 'quantity' field and the 'reserve' field.
+   * Field.of("quantity").add(Field.of("reserve"));
+   * }
+ * + * @param other The expression to add to this expression. + * @return A new {@code Expr} representing the addition operation. + */ @BetaApi default Add add(Expr other) { return new Add(this, other); } + /** + * Creates an expression that adds this expression to a constant value. + * + *

Example: + * + *

{@code
+   * // Add 5 to the value of the 'age' field
+   * Field.of("age").add(5);
+   * }
+ * + * @param other The constant value to add. + * @return A new {@code Expr} representing the addition operation. + */ @BetaApi default Add add(Object other) { return new Add(this, Constant.of(other)); } + /** + * Creates an expression that subtracts another expression from this expression. + * + *

Example: + * + *

{@code
+   * // Subtract the 'discount' field from the 'price' field
+   * Field.of("price").subtract(Field.of("discount"));
+   * }
+ * + * @param other The expression to subtract from this expression. + * @return A new {@code Expr} representing the subtraction operation. + */ @BetaApi default Subtract subtract(Expr other) { return new Subtract(this, other); } + /** + * Creates an expression that subtracts a constant value from this expression. + * + *

Example: + * + *

{@code
+   * // Subtract 20 from the value of the 'total' field
+   * Field.of("total").subtract(20);
+   * }
+ * + * @param other The constant value to subtract. + * @return A new {@code Expr} representing the subtraction operation. + */ @BetaApi default Subtract subtract(Object other) { return new Subtract(this, Constant.of(other)); } + /** + * Creates an expression that multiplies this expression by another expression. + * + *

Example: + * + *

{@code
+   * // Multiply the 'quantity' field by the 'price' field
+   * Field.of("quantity").multiply(Field.of("price"));
+   * }
+ * + * @param other The expression to multiply by. + * @return A new {@code Expr} representing the multiplication operation. + */ @BetaApi default Multiply multiply(Expr other) { return new Multiply(this, other); } + /** + * Creates an expression that multiplies this expression by a constant value. + * + *

Example: + * + *

{@code
+   * // Multiply the 'value' field by 2
+   * Field.of("value").multiply(2);
+   * }
+ * + * @param other The constant value to multiply by. + * @return A new {@code Expr} representing the multiplication operation. + */ @BetaApi default Multiply multiply(Object other) { return new Multiply(this, Constant.of(other)); } + /** + * Creates an expression that divides this expression by another expression. + * + *

Example: + * + *

{@code
+   * // Divide the 'total' field by the 'count' field
+   * Field.of("total").divide(Field.of("count"));
+   * }
+ * + * @param other The expression to divide by. + * @return A new {@code Expr} representing the division operation. + */ @BetaApi default Divide divide(Expr other) { return new Divide(this, other); } + /** + * Creates an expression that divides this expression by a constant value. + * + *

Example: + * + *

{@code
+   * // Divide the 'value' field by 10
+   * Field.of("value").divide(10);
+   * }
+ * + * @param other The constant value to divide by. + * @return A new {@code Expr} representing the division operation. + */ @BetaApi default Divide divide(Object other) { return new Divide(this, Constant.of(other)); } + // Comparison Operators + + /** + * Creates an expression that checks if this expression is equal to another expression. + * + *

Example: + * + *

{@code
+   * // Check if the 'age' field is equal to 21
+   * Field.of("age").eq(21);
+   * }
+ * + * @param other The expression to compare for equality. + * @return A new {@code Expr} representing the equality comparison. + */ @BetaApi - default Eq eq(Expr expr) { - return new Eq(this, expr); + default Eq eq(Expr other) { + return new Eq(this, other); } + /** + * Creates an expression that checks if this expression is equal to a constant value. + * + *

Example: + * + *

{@code
+   * // Check if the 'city' field is equal to "London"
+   * Field.of("city").eq("London");
+   * }
+ * + * @param other The constant value to compare for equality. + * @return A new {@code Expr} representing the equality comparison. + */ @BetaApi default Eq eq(Object other) { return new Eq(this, Constant.of(other)); } + /** + * Creates an expression that checks if this expression is not equal to another expression. + * + *

Example: + * + *

{@code
+   * // Check if the 'status' field is not equal to "completed"
+   * Field.of("status").neq("completed");
+   * }
+ * + * @param other The expression to compare for inequality. + * @return A new {@code Expr} representing the inequality comparison. + */ @BetaApi default Neq neq(Expr other) { return new Neq(this, other); } + /** + * Creates an expression that checks if this expression is not equal to a constant value. + * + *

Example: + * + *

{@code
+   * // Check if the 'country' field is not equal to "USA"
+   * Field.of("country").neq("USA");
+   * }
+ * + * @param other The constant value to compare for inequality. + * @return A new {@code Expr} representing the inequality comparison. + */ @BetaApi default Neq neq(Object other) { return new Neq(this, Constant.of(other)); } + /** + * Creates an expression that checks if this expression is greater than another expression. + * + *

Example: + * + *

{@code
+   * // Check if the 'age' field is greater than the 'limit' field
+   * Field.of("age").gt(Field.of("limit"));
+   * }
+ * + * @param other The expression to compare for greater than. + * @return A new {@code Expr} representing the greater than comparison. + */ @BetaApi default Gt gt(Expr other) { return new Gt(this, other); } + /** + * Creates an expression that checks if this expression is greater than a constant value. + * + *

Example: + * + *

{@code
+   * // Check if the 'price' field is greater than 100
+   * Field.of("price").gt(100);
+   * }
+ * + * @param other The constant value to compare for greater than. + * @return A new {@code Expr} representing the greater than comparison. + */ @BetaApi default Gt gt(Object other) { return new Gt(this, Constant.of(other)); } + /** + * Creates an expression that checks if this expression is greater than or equal to another + * expression. + * + *

Example: + * + *

{@code
+   * // Check if the 'quantity' field is greater than or equal to field 'requirement' plus 1
+   * Field.of("quantity").gte(Field.of('requirement').add(1));
+   * }
+ * + * @param other The expression to compare for greater than or equal to. + * @return A new {@code Expr} representing the greater than or equal to comparison. + */ @BetaApi default Gte gte(Expr other) { return new Gte(this, other); } + /** + * Creates an expression that checks if this expression is greater than or equal to a constant + * value. + * + *

Example: + * + *

{@code
+   * // Check if the 'score' field is greater than or equal to 80
+   * Field.of("score").gte(80);
+   * }
+ * + * @param other The constant value to compare for greater than or equal to. + * @return A new {@code Expr} representing the greater than or equal to comparison. + */ @BetaApi default Gte gte(Object other) { return new Gte(this, Constant.of(other)); } + /** + * Creates an expression that checks if this expression is less than another expression. + * + *

Example: + * + *

{@code
+   * // Check if the 'age' field is less than 'limit'
+   * Field.of("age").lt(Field.of('limit'));
+   * }
+ * + * @param other The expression to compare for less than. + * @return A new {@code Expr} representing the less than comparison. + */ @BetaApi default Lt lt(Expr other) { return new Lt(this, other); } + /** + * Creates an expression that checks if this expression is less than a constant value. + * + *

Example: + * + *

{@code
+   * // Check if the 'price' field is less than 50
+   * Field.of("price").lt(50);
+   * }
+ * + * @param other The constant value to compare for less than. + * @return A new {@code Expr} representing the less than comparison. + */ @BetaApi default Lt lt(Object other) { return new Lt(this, Constant.of(other)); } + /** + * Creates an expression that checks if this expression is less than or equal to another + * expression. + * + *

Example: + * + *

{@code
+   * // Check if the 'quantity' field is less than or equal to 20
+   * Field.of("quantity").lte(Constant.of(20));
+   * }
+ * + * @param other The expression to compare for less than or equal to. + * @return A new {@code Expr} representing the less than or equal to comparison. + */ @BetaApi default Lte lte(Expr other) { return new Lte(this, other); } + /** + * Creates an expression that checks if this expression is less than or equal to a constant value. + * + *

Example: + * + *

{@code
+   * // Check if the 'score' field is less than or equal to 70
+   * Field.of("score").lte(70);
+   * }
+ * + * @param other The constant value to compare for less than or equal to. + * @return A new {@code Expr} representing the less than or equal to comparison. + */ @BetaApi default Lte lte(Object other) { return new Lte(this, Constant.of(other)); } + // IN operator + /** + * Creates an expression that checks if this expression is equal to any of the provided values or + * expressions. + * + *

Example: + * + *

{@code
+   * // Check if the 'category' field is either "Electronics" or value of field 'primaryType'
+   * Field.of("category").in("Electronics", Field.of("primaryType"));
+   * }
+ * + * @param other The values or expressions to check against. + * @return A new {@code Expr} representing the 'IN' comparison. + */ @BetaApi default In inAny(Object... other) { return new In(this, toExprList(other)); } + /** + * Creates an expression that checks if this expression is not equal to any of the provided values + * or expressions. + * + *

Example: + * + *

{@code
+   * // Check if the 'status' field is neither "pending" nor "cancelled"
+   * Field.of("status").notIn("pending", "cancelled");
+   * }
+ * + * @param other The values or expressions to check against. + * @return A new {@code Expr} representing the 'NOT IN' comparison. + */ @BetaApi default Not notInAny(Object... other) { return new Not(inAny(other)); } + // Array Functions + + /** + * Creates an expression that concatenates an array expression with one or more other arrays. + * + *

Example: + * + *

{@code
+   * // Combine the 'items' array with another array field.
+   * Field.of("items").arrayConcat(Field.of("otherItems"));
+   * }
+ * + * @param elements The array expressions to concatenate. + * @return A new {@code Expr} representing the concatenated array. + */ @BetaApi default ArrayConcat arrayConcat(Expr... elements) { return new ArrayConcat(this, Arrays.asList(elements)); } + /** + * Creates an expression that concatenates an array expression with one or more other arrays. + * + *

Example: + * + *

{@code
+   * // Combine the 'tags' array with a new array and an array field
+   * Field.of("tags").arrayConcat(Arrays.asList("newTag1", "newTag2"), Field.of("otherTag"));
+   * }
+ * + * @param elements The array expressions or values to concatenate. + * @return A new {@code Expr} representing the concatenated array. + */ @BetaApi default ArrayConcat arrayConcat(Object... elements) { return new ArrayConcat(this, toExprList(elements)); } + /** + * Creates an expression that checks if an array contains a specific element. + * + *

Example: + * + *

{@code
+   * // Check if the 'sizes' array contains the value from the 'selectedSize' field
+   * Field.of("sizes").arrayContains(Field.of("selectedSize"));
+   * }
+ * + * @param element The element to search for in the array. + * @return A new {@code Expr} representing the 'array_contains' comparison. + */ @BetaApi default ArrayContains arrayContains(Expr element) { return new ArrayContains(this, element); } + /** + * Creates an expression that checks if an array contains a specific value. + * + *

Example: + * + *

{@code
+   * // Check if the 'colors' array contains "red"
+   * Field.of("colors").arrayContains("red");
+   * }
+ * + * @param element The element to search for in the array. + * @return A new {@code Expr} representing the 'array_contains' comparison. + */ @BetaApi default ArrayContains arrayContains(Object element) { return new ArrayContains(this, Constant.of(element)); } + /** + * Creates an expression that checks if an array contains all the specified elements. + * + *

Example: + * + *

{@code
+   * // Check if the 'tags' array contains both "news" and "sports"
+   * Field.of("tags").arrayContainsAll(Field.of("tag1"), Field.of("tag2"));
+   * }
+ * + * @param elements The elements to check for in the array. + * @return A new {@code Expr} representing the 'array_contains_all' comparison. + */ @BetaApi default ArrayContainsAll arrayContainsAll(Expr... elements) { return new ArrayContainsAll(this, Arrays.asList(elements)); } + /** + * Creates an expression that checks if an array contains all the specified elements. + * + *

Example: + * + *

{@code
+   * // Check if the 'tags' array contains both of the values from field 'tag1' and "tag2"
+   * Field.of("tags").arrayContainsAll(Field.of("tag1"), Field.of("tag2"));
+   * }
+ * + * @param elements The elements to check for in the array. + * @return A new {@code Expr} representing the 'array_contains_all' comparison. + */ @BetaApi default ArrayContainsAll arrayContainsAll(Object... elements) { return new ArrayContainsAll(this, toExprList(elements)); } + /** + * Creates an expression that checks if an array contains any of the specified elements. + * + *

Example: + * + *

{@code
+   * // Check if the 'categories' array contains either values from field "cate1" or "cate2"
+   * Field.of("categories").arrayContainsAny(Field.of("cate1"), Field.of("cate2"));
+   * }
+ * + * @param elements The elements to check for in the array. + * @return A new {@code Expr} representing the 'array_contains_any' comparison. + */ @BetaApi default ArrayContainsAny arrayContainsAny(Expr... elements) { return new ArrayContainsAny(this, Arrays.asList(elements)); } + /** + * Creates an expression that checks if an array contains any of the specified elements. + * + *

Example: + * + *

{@code
+   * // Check if the 'groups' array contains either the value from the 'userGroup' field
+   * // or the value "guest"
+   * Field.of("groups").arrayContainsAny(Field.of("userGroup"), "guest");
+   * }
+ * + * @param elements The elements to check for in the array. + * @return A new {@code Expr} representing the 'array_contains_any' comparison. + */ @BetaApi default ArrayContainsAny arrayContainsAny(Object... elements) { return new ArrayContainsAny(this, toExprList(elements)); } + /** + * Creates an expression that filters elements from an array using the given {@link + * FilterCondition} and returns the filtered elements as a new array. + * + *

Example: + * + *

{@code
+   * // Get items from the 'inventoryPrices' array where the array item is greater than 0
+   * // Note we use {@link Function#arrayElement} to represent array elements to construct a
+   * // filtering condition.
+   * Field.of("inventoryPrices").arrayFilter(arrayElement().gt(0));
+   * }
+ * + * @param filter The {@link FilterCondition} to apply to the array elements. + * @return A new {@code Expr} representing the filtered array. + */ @BetaApi default ArrayFilter arrayFilter(FilterCondition filter) { return new ArrayFilter(this, filter); } + /** + * Creates an expression that calculates the length of an array. + * + *

Example: + * + *

{@code
+   * // Get the number of items in the 'cart' array
+   * Field.of("cart").arrayLength();
+   * }
+ * + * @return A new {@code Expr} representing the length of the array. + */ @BetaApi default ArrayLength arrayLength() { return new ArrayLength(this); } + /** + * Creates an expression that applies a transformation function to each element in an array and + * returns the new array as the result of the evaluation. + * + *

Example: + * + *

{@code
+   * // Convert all strings in the 'names' array to uppercase
+   * Field.of("names").arrayTransform(arrayElement().toUppercase());
+   * }
+ * + * @param transform The {@link Function} to apply to each array element. + * @return A new {@code Expr} representing the transformed array. + */ @BetaApi default ArrayTransform arrayTransform(Function transform) { return new ArrayTransform(this, transform); } + // Other Functions + + /** + * Creates an expression that checks if this expression evaluates to 'NaN' (Not a Number). + * + *

Example: + * + *

{@code
+   * // Check if the result of a calculation is NaN
+   * Field.of("value").divide(0).isNaN();
+   * }
+ * + * @return A new {@code Expr} representing the 'isNaN' check. + */ @BetaApi default IsNaN isNaN() { return new IsNaN(this); } + /** + * Creates an expression that checks if a field exists in the document. + * + *

Example: + * + *

{@code
+   * // Check if the document has a field named "phoneNumber"
+   * Field.of("phoneNumber").exists();
+   * }
+ * + * @return A new {@code Expr} representing the 'exists' check. + */ @BetaApi default Exists exists() { return new Exists(this); } + /** + * Creates an expression that checks if this expression evaluates to null. + * + *

Example: + * + *

{@code
+   * // Check if the 'optionalField' is null
+   * Field.of("optionalField").isNull();
+   * }
+ * + * @return A new {@code Expr} representing the null check. + */ @BetaApi default IsNull isNull() { return new IsNull(this); } + // Aggregate Functions + + /** + * Creates an aggregation that calculates the sum of a numeric field across multiple stage inputs. + * + *

Example: + * + *

{@code
+   * // Calculate the total revenue from a set of orders
+   * Field.of("orderAmount").sum().as("totalRevenue");
+   * }
+ * + * @return A new {@code Accumulator} representing the 'sum' aggregation. + */ @BetaApi default Sum sum() { return new Sum(this, false); } + /** + * Creates an aggregation that calculates the average (mean) of a numeric field across multiple + * stage inputs. + * + *

Example: + * + *

{@code
+   * // Calculate the average age of users
+   * Field.of("age").avg().as("averageAge");
+   * }
+ * + * @return A new {@code Accumulator} representing the 'avg' aggregation. + */ @BetaApi default Avg avg() { return new Avg(this, false); } + /** + * Creates an aggregation that counts the number of stage inputs with valid evaluations of the + * expression or field. + * + *

Example: + * + *

{@code
+   * // Count the total number of products
+   * Field.of("productId").count().as("totalProducts");
+   * }
+ * + * @return A new {@code Accumulator} representing the 'count' aggregation. + */ @BetaApi default Count count() { return new Count(this, false); } + /** + * Creates an aggregation that finds the minimum value of a field across multiple stage inputs. + * + *

Example: + * + *

{@code
+   * // Find the lowest price of all products
+   * Field.of("price").min().as("lowestPrice");
+   * }
+ * + * @return A new {@code Accumulator} representing the 'min' aggregation. + */ @BetaApi default Min min() { return new Min(this, false); } + /** + * Creates an aggregation that finds the maximum value of a field across multiple stage inputs. + * + *

Example: + * + *

{@code
+   * // Find the highest score in a leaderboard
+   * Field.of("score").max().as("highestScore");
+   * }
+ * + * @return A new {@code Accumulator} representing the 'max' aggregation. + */ @BetaApi default Max max() { return new Max(this, false); } + // String Functions + + /** + * Creates an expression that calculates the length of a string. + * + *

Example: + * + *

{@code
+   * // Get the length of the 'name' field
+   * Field.of("name").length();
+   * }
+ * + * @return A new {@code Expr} representing the length of the string. + */ @BetaApi default Length length() { return new Length(this); } + /** + * Creates an expression that performs a case-sensitive string comparison. + * + *

Example: + * + *

{@code
+   * // Check if the 'title' field contains the word "guide" (case-sensitive)
+   * Field.of("title").like("%guide%");
+   * }
+ * + * @param pattern The pattern to search for. You can use "%" as a wildcard character. + * @return A new {@code Expr} representing the 'like' comparison. + */ @BetaApi default Like like(String pattern) { return new Like(this, Constant.of(pattern)); } + /** + * Creates an expression that checks if a string contains a specified regular expression as a + * substring. + * + *

Example: + * + *

{@code
+   * // Check if the 'description' field contains "example" (case-insensitive)
+   * Field.of("description").regexContains("(?i)example");
+   * }
+ * + * @param regex The regular expression to use for the search. + * @return A new {@code Expr} representing the 'contains' comparison. + */ @BetaApi default RegexContains regexContains(String regex) { return new RegexContains(this, Constant.of(regex)); } + /** + * Creates an expression that checks if a string contains a specified regular expression as a + * substring. + * + *

Example: + * + *

{@code
+   * // Check if the 'description' field contains the regular expression stored in field 'regex'
+   * Field.of("description").regexContains(Field.of("regex"));
+   * }
+ * + * @param regex The regular expression to use for the search. + * @return A new {@code Expr} representing the 'contains' comparison. + */ + @BetaApi + default RegexContains regexContains(Expr regex) { + return new RegexContains(this, regex); + } + + /** + * Creates an expression that checks if a string matches a specified regular expression. + * + *

Example: + * + *

{@code
+   * // Check if the 'email' field matches a valid email pattern
+   * Field.of("email").regexMatches("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}");
+   * }
+ * + * @param regex The regular expression to use for the match. + * @return A new {@code Expr} representing the regular expression match. + */ @BetaApi default RegexMatch regexMatches(String regex) { return new RegexMatch(this, Constant.of(regex)); } + /** + * Creates an expression that checks if a string matches a specified regular expression. + * + *

Example: + * + *

{@code
+   * // Check if the 'email' field matches a regular expression stored in field 'regex'
+   * Field.of("email").regexMatches(Field.of("regex"));
+   * }
+ * + * @param regex The regular expression to use for the match. + * @return A new {@code Expr} representing the regular expression match. + */ + @BetaApi + default RegexMatch regexMatches(Expr regex) { + return new RegexMatch(this, regex); + } + + /** + * Creates an expression that checks if a string starts with a given prefix. + * + *

Example: + * + *

{@code
+   * // Check if the 'name' field starts with "Mr."
+   * Field.of("name").startsWith("Mr.");
+   * }
+ * + * @param prefix The prefix to check for. + * @return A new {@code Expr} representing the 'starts with' comparison. + */ @BetaApi default StartsWith startsWith(String prefix) { return new StartsWith(this, Constant.of(prefix)); } + /** + * Creates an expression that checks if a string starts with a given prefix (represented as an + * expression). + * + *

Example: + * + *

{@code
+   * // Check if the 'fullName' field starts with the value of the 'firstName' field
+   * Field.of("fullName").startsWith(Field.of("firstName"));
+   * }
+ * + * @param prefix The prefix expression to check for. + * @return A new {@code Expr} representing the 'starts with' comparison. + */ @BetaApi default StartsWith startsWith(Expr prefix) { return new StartsWith(this, prefix); } + /** + * Creates an expression that checks if a string ends with a given postfix. + * + *

Example: + * + *

{@code
+   * // Check if the 'filename' field ends with ".txt"
+   * Field.of("filename").endsWith(".txt");
+   * }
+ * + * @param postfix The postfix to check for. + * @return A new {@code Expr} representing the 'ends with' comparison. + */ @BetaApi default EndsWith endsWith(String postfix) { return new EndsWith(this, Constant.of(postfix)); } + /** + * Creates an expression that checks if a string ends with a given postfix (represented as an + * expression). + * + *

Example: + * + *

{@code
+   * // Check if the 'url' field ends with the value of the 'extension' field
+   * Field.of("url").endsWith(Field.of("extension"));
+   * }
+ * + * @param postfix The postfix expression to check for. + * @return A new {@code Expr} representing the 'ends with' comparison. + */ @BetaApi default EndsWith endsWith(Expr postfix) { return new EndsWith(this, postfix); } + /** + * Creates an expression that concatenates string expressions together. + * + *

Example: + * + *

{@code
+   * // Combine the 'firstName', " ", and 'lastName' fields into a single string
+   * Field.of("firstName").strConcat(Constant.of(" "), Field.of("lastName"));
+   * }
+ * + * @param elements The expressions (typically strings) to concatenate. + * @return A new {@code Expr} representing the concatenated string. + */ + @BetaApi + default StrConcat strConcat(Expr... elements) { + return new StrConcat(this, Arrays.asList(elements)); + } + + /** + * Creates an expression that concatenates string functions, fields or constants together. + * + *

Example: + * + *

{@code
+   * // Combine the 'firstName', " ", and 'lastName' fields into a single string
+   * Field.of("firstName").strConcat(" ", Field.of("lastName"));
+   * }
+ * + * @param elements The expressions (typically strings) to concatenate. + * @return A new {@code Expr} representing the concatenated string. + */ @BetaApi - default StrConcat strConcat(List elements) { - return new StrConcat(this, elements); + default StrConcat strConcat(Object... elements) { + return new StrConcat(this, toExprList(elements)); } + /** + * Creates an expression that converts a string to lowercase. + * + *

Example: + * + *

{@code
+   * // Convert the 'name' field to lowercase
+   * Field.of("name").toLowerCase();
+   * }
+ * + * @return A new {@code Expr} representing the lowercase string. + */ @BetaApi default ToLowercase toLowercase() { return new ToLowercase(this); } + /** + * Creates an expression that converts a string to uppercase. + * + *

Example: + * + *

{@code
+   * // Convert the 'title' field to uppercase
+   * Field.of("title").toUpperCase();
+   * }
+ * + * @return A new {@code Expr} representing the uppercase string. + */ @BetaApi default ToUppercase toUppercase() { return new ToUppercase(this); } + /** + * Creates an expression that removes leading and trailing whitespace from a string. + * + *

Example: + * + *

{@code
+   * // Trim whitespace from the 'userInput' field
+   * Field.of("userInput").trim();
+   * }
+ * + * @return A new {@code Expr} representing the trimmed string. + */ @BetaApi default Trim trim() { return new Trim(this); } + /** + * Accesses a value from a map (object) field using the provided key. + * + *

Example: + * + *

{@code
+   * // Get the 'city' value from
+   * // the 'address' map field
+   * Field.of("address").mapGet("city");
+   * }
+ * + * @param key The key to access in the map. + * @return A new {@code Expr} representing the value associated with the given key in the map. + */ @BetaApi default MapGet mapGet(String key) { return new MapGet(this, key); } + /** + * Calculates the cosine distance between two vectors. + * + *

Example: + * + *

{@code
+   * // Calculate the cosine distance between the 'userVector' field and the 'itemVector' field
+   * Field.of("userVector").cosineDistance(Field.of("itemVector"));
+   * }
+ * + * @param other The other vector (represented as an Expr) to compare against. + * @return A new {@code Expr} representing the cosine distance between the two vectors. + */ @BetaApi default CosineDistance cosineDistance(Expr other) { return new CosineDistance(this, other); } + /** + * Calculates the Cosine distance between two vectors. + * + *

Example: + * + *

{@code
+   * // Calculate the Cosine distance between the 'location' field and a target location
+   * Field.of("location").cosineDistance(new double[] {37.7749, -122.4194});
+   * }
+ * + * @param other The other vector (as an array of doubles) to compare against. + * @return A new {@code Expr} representing the Cosine distance between the two vectors. + */ @BetaApi default CosineDistance cosineDistance(double[] other) { return new CosineDistance(this, Constant.ofVector(other)); } - @BetaApi - default EuclideanDistance euclideanDistance(Expr other) { - return new EuclideanDistance(this, other); - } - + /** + * Calculates the Euclidean distance between two vectors. + * + *

Example: + * + *

{@code
+   * // Calculate the Euclidean distance between the 'location' field and a target location
+   * Field.of("location").euclideanDistance(new double[] {37.7749, -122.4194});
+   * }
+ * + * @param other The other vector (as an array of doubles) to compare against. + * @return A new {@code Expr} representing the Euclidean distance between the two vectors. + */ @BetaApi default EuclideanDistance euclideanDistance(double[] other) { return new EuclideanDistance(this, Constant.ofVector(other)); } + /** + * Calculates the Euclidean distance between two vectors. + * + *

Example: + * + *

{@code
+   * // Calculate the Euclidean distance between two vector fields: 'pointA' and 'pointB'
+   * Field.of("pointA").euclideanDistance(Field.of("pointB"));
+   * }
+ * + * @param other The other vector (represented as an Expr) to compare against. + * @return A new {@code Expr} representing the Euclidean distance between the two vectors. + */ @BetaApi - default DotProductDistance dotProductDistance(Expr other) { - return new DotProductDistance(this, other); + default EuclideanDistance euclideanDistance(Expr other) { + return new EuclideanDistance(this, other); } + /** + * Calculates the dot product distance between two vectors. + * + *

Example: + * + *

{@code
+   * // Calculate the dot product distance between a feature vector and a target vector
+   * Field.of("features").dotProductDistance(new double[] {0.5, 0.8, 0.2});
+   * }
+ * + * @param other The other vector (as an array of doubles) to compare against. + * @return A new {@code Expr} representing the dot product distance between the two vectors. + */ @BetaApi default DotProductDistance dotProductDistance(double[] other) { return new DotProductDistance(this, Constant.ofVector(other)); } + /** + * Calculates the dot product distance between two vectors. + * + *

Example: + * + *

{@code
+   * // Calculate the dot product distance between two document vectors: 'docVector1' and 'docVector2'
+   * Field.of("docVector1").dotProductDistance(Field.of("docVector2"));
+   * }
+ * + * @param other The other vector (represented as an Expr) to compare against. + * @return A new {@code Expr} representing the dot product distance between the two vectors. + */ + @BetaApi + default DotProductDistance dotProductDistance(Expr other) { + return new DotProductDistance(this, other); + } + + // Ordering + + /** + * Creates an {@link Ordering} that sorts documents in ascending order based on this expression. + * + *

Example: + * + *

{@code
+   * // Sort documents by the 'name' field in ascending order
+   * firestore.pipeline().collection("users")
+   *   .sort(Field.of("name").ascending());
+   * }
+ * + * @return A new {@code Ordering} for ascending sorting. + */ @BetaApi default Ordering ascending() { return Ordering.ascending(this); } + /** + * Creates an {@link Ordering} that sorts documents in descending order based on this expression. + * + *

Example: + * + *

{@code
+   * // Sort documents by the 'createdAt' field in descending order
+   * firestore.pipeline().collection("users")
+   *   .sort(Field.of("createdAt").descending());
+   * }
+ * + * @return A new {@code Ordering} for descending sorting. + */ @BetaApi default Ordering descending() { return Ordering.descending(this); } + // Alias + + /** + * Assigns an alias to this expression. + * + *

Aliases are useful for renaming fields in the output of a stage or for giving meaningful + * names to calculated values. + * + *

Example: + * + *

{@code
+   * // Calculate the total price and assign it the alias "totalPrice" and add it to the output.
+   * firestore.pipeline().collection("items")
+   *   .addFields(Field.of("price").multiply(Field.of("quantity")).as("totalPrice"));
+   * }
+ * + * @param alias The alias to assign to this expression. + * @return A new {@code Selectable} (typically an {@link ExprWithAlias}) that wraps this + * expression and associates it with the provided alias. + */ @BetaApi default Selectable as(String alias) { return new ExprWithAlias(this, alias); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Ordering.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Ordering.java index 3232ed725..c5547c2ad 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Ordering.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Ordering.java @@ -41,16 +41,6 @@ public Value toProto() { .build(); } - @BetaApi - public static Ordering of(Expr expr, Ordering.Direction dir) { - return new Ordering(expr, dir); - } - - @BetaApi - public static Ordering of(Expr expr) { - return new Ordering(expr, Direction.ASCENDING); - } - @BetaApi public static Ordering ascending(Expr expr) { return new Ordering(expr, Direction.ASCENDING); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/FindNearest.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/FindNearest.java index a83ec2055..ab444c67c 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/FindNearest.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/FindNearest.java @@ -1,17 +1,19 @@ package com.google.cloud.firestore.pipeline.stages; import com.google.api.core.InternalApi; +import com.google.cloud.firestore.pipeline.expressions.Expr; import com.google.cloud.firestore.pipeline.expressions.Field; +import javax.annotation.Nullable; public final class FindNearest implements Stage { private static final String name = "find_nearest"; - private final Field property; + private final Expr property; private final double[] vector; private final FindNearest.FindNearestOptions options; @InternalApi - public FindNearest(Field property, double[] vector, FindNearest.FindNearestOptions options) { + public FindNearest(Expr property, double[] vector, FindNearest.FindNearestOptions options) { this.property = property; this.vector = vector; this.options = options; @@ -24,7 +26,7 @@ public String getName() { } @InternalApi - public Field getProperty() { + public Expr getProperty() { return property; } @@ -113,18 +115,29 @@ public static class FindNearestOptions { private final Long limit; private final FindNearest.DistanceMeasure distanceMeasure; - private final Field distanceField; + + @Nullable private final Field distanceField; + + private FindNearestOptions(Long limit, FindNearest.DistanceMeasure distanceMeasure) { + this.limit = limit; + this.distanceMeasure = distanceMeasure; + this.distanceField = null; + } private FindNearestOptions( - Long limit, FindNearest.DistanceMeasure distanceMeasure, Field distanceField) { + Long limit, FindNearest.DistanceMeasure distanceMeasure, Field field) { this.limit = limit; this.distanceMeasure = distanceMeasure; - this.distanceField = distanceField; + this.distanceField = field; + } + + public static FindNearest.FindNearestOptions withLimitAndMeasure( + long limit, FindNearest.DistanceMeasure distanceMeasure) { + return new FindNearest.FindNearestOptions(limit, distanceMeasure); } - public static FindNearest.FindNearestOptions newInstance( - long limit, FindNearest.DistanceMeasure distanceMeasure, Field output) { - return new FindNearest.FindNearestOptions(limit, distanceMeasure, output); + public FindNearest.FindNearestOptions withDistanceField(String name) { + return new FindNearest.FindNearestOptions(limit, distanceMeasure, Field.of(name)); } public Long getLimit() { diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Join.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Join.java index 5da7fa824..6d9581ca5 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Join.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/Join.java @@ -15,7 +15,8 @@ public class Join implements Stage { private final Field otherAlias; @InternalApi - Join(Type type, FilterCondition condition, Field alias, Pipeline otherPipeline, Field otherAlias) { + Join( + Type type, FilterCondition condition, Field alias, Pipeline otherPipeline, Field otherAlias) { this.type = type; this.condition = condition; this.alias = alias;