diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java index 695051c20..2c512bd65 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java @@ -3583,6 +3583,41 @@ public static Expression type(String fieldName) { return type(field(fieldName)); } + /** + * Creates an expression that checks if the result of an expression is of the given type. + * + *
Supported values for {@code type} are: "null", "array", "boolean", "bytes", "timestamp", + * "geo_point", "number", "int32", "int64", "float64", "decimal128", "map", "reference", "string", + * "vector", "max_key", "min_key", "object_id", "regex", and "request_timestamp". + * + * @param expr The expression to check the type of. + * @param type The type to check for. + * @return A new {@link BooleanExpression} that evaluates to true if the expression's result is of + * the given type, false otherwise. + */ + @BetaApi + public static BooleanExpression isType(Expression expr, String type) { + return new BooleanFunctionExpression("is_type", ImmutableList.of(expr, constant(type))); + } + + /** + * Creates an expression that checks if the value of a field is of the given type. + * + *
Supported values for {@code type} are: "null", "array", "boolean", "bytes", "timestamp", + * "geo_point", "number", "int32", "int64", "float64", "decimal128", "map", "reference", "string", + * "vector", "max_key", "min_key", "object_id", "regex", and "request_timestamp". + * + * @param fieldName The name of the field to check the type of. + * @param type The type to check for. + * @return A new {@link BooleanExpression} that evaluates to true if the expression's result is of + * the given type, false otherwise. + */ + @BetaApi + public static BooleanExpression isType(String fieldName, String type) { + return new BooleanFunctionExpression( + "is_type", ImmutableList.of(field(fieldName), constant(type))); + } + // Numeric Operations /** * Creates an expression that rounds {@code numericExpr} to nearest integer. @@ -5629,4 +5664,20 @@ public final Expression collectionId() { public final Expression type() { return type(this); } + + /** + * Creates an expression that checks if the result of this expression is of the given type. + * + *
Supported values for {@code type} are: "null", "array", "boolean", "bytes", "timestamp",
+ * "geo_point", "number", "int32", "int64", "float64", "decimal128", "map", "reference", "string",
+ * "vector", "max_key", "min_key", "object_id", "regex", and "request_timestamp".
+ *
+ * @param type The type to check for.
+ * @return A new {@link BooleanExpression} that evaluates to true if the expression's result is of
+ * the given type, false otherwise.
+ */
+ @BetaApi
+ public final BooleanExpression isType(String type) {
+ return isType(this, type);
+ }
}
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 e14fa8a94..acdb68c3f 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
@@ -3500,6 +3500,89 @@ public void testType() throws Exception {
"vector"));
}
+ @Test
+ public void testIsType() throws Exception {
+ List