Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit f1c656b

Browse files
Merge branch 'main' into markduckworth/search
2 parents 5ae808d + 1d23f18 commit f1c656b

2 files changed

Lines changed: 468 additions & 0 deletions

File tree

google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2707,6 +2707,196 @@ public static Expression arrayReverse(String arrayFieldName) {
27072707
return arrayReverse(field(arrayFieldName));
27082708
}
27092709

2710+
/**
2711+
* Filters an array expression based on a predicate.
2712+
*
2713+
* @param array The expression representing the array to filter.
2714+
* @param alias The alias for the current element in the filter expression.
2715+
* @param filter The predicate boolean expression used to filter the elements.
2716+
* @return A new {@link Expression} representing the filtered array.
2717+
*/
2718+
@BetaApi
2719+
public static Expression arrayFilter(Expression array, String alias, BooleanExpression filter) {
2720+
return new FunctionExpression("array_filter", ImmutableList.of(array, constant(alias), filter));
2721+
}
2722+
2723+
/**
2724+
* Filters an array field based on a predicate.
2725+
*
2726+
* @param arrayFieldName The field name of the array to filter.
2727+
* @param alias The alias for the current element in the filter expression.
2728+
* @param filter The predicate boolean expression used to filter the elements.
2729+
* @return A new {@link Expression} representing the filtered array.
2730+
*/
2731+
@BetaApi
2732+
public static Expression arrayFilter(
2733+
String arrayFieldName, String alias, BooleanExpression filter) {
2734+
return arrayFilter(field(arrayFieldName), alias, filter);
2735+
}
2736+
2737+
/**
2738+
* Creates an expression that applies a provided transformation to each element in an array.
2739+
*
2740+
* @param array The expression representing the array to transform.
2741+
* @param elementAlias The alias for the current element in the transform expression.
2742+
* @param transform The expression used to transform the elements.
2743+
* @return A new {@link Expression} representing the transformed array.
2744+
*/
2745+
@BetaApi
2746+
public static Expression arrayTransform(
2747+
Expression array, String elementAlias, Expression transform) {
2748+
return new FunctionExpression(
2749+
"array_transform", ImmutableList.of(array, constant(elementAlias), transform));
2750+
}
2751+
2752+
/**
2753+
* Creates an expression that applies a provided transformation to each element in an array.
2754+
*
2755+
* @param arrayFieldName The field name of the array to transform.
2756+
* @param elementAlias The alias for the current element in the transform expression.
2757+
* @param transform The expression used to transform the elements.
2758+
* @return A new {@link Expression} representing the transformed array.
2759+
*/
2760+
@BetaApi
2761+
public static Expression arrayTransform(
2762+
String arrayFieldName, String elementAlias, Expression transform) {
2763+
return arrayTransform(field(arrayFieldName), elementAlias, transform);
2764+
}
2765+
2766+
/**
2767+
* Creates an expression that applies a provided transformation to each element in an array,
2768+
* providing the element's index to the transformation expression.
2769+
*
2770+
* @param array The expression representing the array to transform.
2771+
* @param elementAlias The alias for the current element in the transform expression.
2772+
* @param indexAlias The alias for the current index.
2773+
* @param transform The expression used to transform the elements.
2774+
* @return A new {@link Expression} representing the transformed array.
2775+
*/
2776+
@BetaApi
2777+
public static Expression arrayTransformWithIndex(
2778+
Expression array, String elementAlias, String indexAlias, Expression transform) {
2779+
return new FunctionExpression(
2780+
"array_transform",
2781+
ImmutableList.of(array, constant(elementAlias), constant(indexAlias), transform));
2782+
}
2783+
2784+
/**
2785+
* Creates an expression that applies a provided transformation to each element in an array,
2786+
* providing the element's index to the transformation expression.
2787+
*
2788+
* @param arrayFieldName The field name of the array to transform.
2789+
* @param elementAlias The alias for the current element in the transform expression.
2790+
* @param indexAlias The alias for the current index.
2791+
* @param transform The expression used to transform the elements.
2792+
* @return A new {@link Expression} representing the transformed array.
2793+
*/
2794+
@BetaApi
2795+
public static Expression arrayTransformWithIndex(
2796+
String arrayFieldName, String elementAlias, String indexAlias, Expression transform) {
2797+
return arrayTransformWithIndex(field(arrayFieldName), elementAlias, indexAlias, transform);
2798+
}
2799+
2800+
/**
2801+
* Creates an expression that returns a slice of an array.
2802+
*
2803+
* @param array The expression representing the array to slice.
2804+
* @param offset The starting index.
2805+
* @param length The number of elements to return.
2806+
* @return A new {@link Expression} representing the array slice.
2807+
*/
2808+
@BetaApi
2809+
public static Expression arraySlice(Expression array, Expression offset, Expression length) {
2810+
return new FunctionExpression("array_slice", ImmutableList.of(array, offset, length));
2811+
}
2812+
2813+
/**
2814+
* Creates an expression that returns a slice of an array.
2815+
*
2816+
* @param array The expression representing the array to slice.
2817+
* @param offset The starting index.
2818+
* @param length The number of elements to return.
2819+
* @return A new {@link Expression} representing the array slice.
2820+
*/
2821+
@BetaApi
2822+
public static Expression arraySlice(Expression array, int offset, int length) {
2823+
return arraySlice(array, constant(offset), constant(length));
2824+
}
2825+
2826+
/**
2827+
* Creates an expression that returns a slice of an array.
2828+
*
2829+
* @param arrayFieldName The field name of the array to slice.
2830+
* @param offset The starting index.
2831+
* @param length The number of elements to return.
2832+
* @return A new {@link Expression} representing the array slice.
2833+
*/
2834+
@BetaApi
2835+
public static Expression arraySlice(String arrayFieldName, int offset, int length) {
2836+
return arraySlice(field(arrayFieldName), constant(offset), constant(length));
2837+
}
2838+
2839+
/**
2840+
* Creates an expression that returns a slice of an array.
2841+
*
2842+
* @param arrayFieldName The field name of the array to slice.
2843+
* @param offset The starting index.
2844+
* @param length The number of elements to return.
2845+
* @return A new {@link Expression} representing the array slice.
2846+
*/
2847+
@BetaApi
2848+
public static Expression arraySlice(String arrayFieldName, Expression offset, Expression length) {
2849+
return arraySlice(field(arrayFieldName), offset, length);
2850+
}
2851+
2852+
/**
2853+
* Creates an expression that returns a slice of an array to its end.
2854+
*
2855+
* @param array The expression representing the array to slice.
2856+
* @param offset The expression representing the starting index.
2857+
* @return A new {@link Expression} representing the array slice.
2858+
*/
2859+
@BetaApi
2860+
public static Expression arraySliceToEnd(Expression array, Expression offset) {
2861+
return new FunctionExpression("array_slice", ImmutableList.of(array, offset));
2862+
}
2863+
2864+
/**
2865+
* Creates an expression that returns a slice of an array to its end.
2866+
*
2867+
* @param array The expression representing the array to slice.
2868+
* @param offset The starting index.
2869+
* @return A new {@link Expression} representing the array slice.
2870+
*/
2871+
@BetaApi
2872+
public static Expression arraySliceToEnd(Expression array, int offset) {
2873+
return arraySliceToEnd(array, constant(offset));
2874+
}
2875+
2876+
/**
2877+
* Creates an expression that returns a slice of an array to its end.
2878+
*
2879+
* @param arrayFieldName The field name of the array to slice.
2880+
* @param offset The starting index.
2881+
* @return A new {@link Expression} representing the array slice.
2882+
*/
2883+
@BetaApi
2884+
public static Expression arraySliceToEnd(String arrayFieldName, int offset) {
2885+
return arraySliceToEnd(field(arrayFieldName), constant(offset));
2886+
}
2887+
2888+
/**
2889+
* Creates an expression that returns a slice of an array to its end.
2890+
*
2891+
* @param arrayFieldName The field name of the array to slice.
2892+
* @param offset The expression representing the starting index.
2893+
* @return A new {@link Expression} representing the array slice.
2894+
*/
2895+
@BetaApi
2896+
public static Expression arraySliceToEnd(String arrayFieldName, Expression offset) {
2897+
return arraySliceToEnd(field(arrayFieldName), offset);
2898+
}
2899+
27102900
/**
27112901
* Creates an expression that checks if an array contains a specified element.
27122902
*
@@ -6777,6 +6967,91 @@ public final Expression arrayReverse() {
67776967
return arrayReverse(this);
67786968
}
67796969

6970+
/**
6971+
* Filters this array based on a predicate.
6972+
*
6973+
* @param alias The alias for the current element in the filter expression.
6974+
* @param filter The predicate boolean expression used to filter the elements.
6975+
* @return A new {@link Expression} representing the filtered array.
6976+
*/
6977+
@BetaApi
6978+
public final Expression arrayFilter(String alias, BooleanExpression filter) {
6979+
return arrayFilter(this, alias, filter);
6980+
}
6981+
6982+
/**
6983+
* Creates an expression that applies a provided transformation to each element in an array.
6984+
*
6985+
* @param elementAlias The alias for the current element in the transform expression.
6986+
* @param transform The expression used to transform the elements.
6987+
* @return A new {@link Expression} representing the transformed array.
6988+
*/
6989+
@BetaApi
6990+
public final Expression arrayTransform(String elementAlias, Expression transform) {
6991+
return arrayTransform(this, elementAlias, transform);
6992+
}
6993+
6994+
/**
6995+
* Creates an expression that applies a provided transformation to each element in an array,
6996+
* providing the element's index to the transformation expression.
6997+
*
6998+
* @param elementAlias The alias for the current element in the transform expression.
6999+
* @param indexAlias The alias for the current index.
7000+
* @param transform The expression used to transform the elements.
7001+
* @return A new {@link Expression} representing the transformed array.
7002+
*/
7003+
@BetaApi
7004+
public final Expression arrayTransformWithIndex(
7005+
String elementAlias, String indexAlias, Expression transform) {
7006+
return arrayTransformWithIndex(this, elementAlias, indexAlias, transform);
7007+
}
7008+
7009+
/**
7010+
* Returns a slice of this array.
7011+
*
7012+
* @param offset The starting index.
7013+
* @param length The number of elements to return.
7014+
* @return A new {@link Expression} representing the array slice.
7015+
*/
7016+
@BetaApi
7017+
public final Expression arraySlice(int offset, int length) {
7018+
return arraySlice(this, offset, length);
7019+
}
7020+
7021+
/**
7022+
* Returns a slice of this array.
7023+
*
7024+
* @param offset The starting index expressed as an Expression.
7025+
* @param length The number of elements to return expressed as an Expression.
7026+
* @return A new {@link Expression} representing the array slice.
7027+
*/
7028+
@BetaApi
7029+
public final Expression arraySlice(Expression offset, Expression length) {
7030+
return arraySlice(this, offset, length);
7031+
}
7032+
7033+
/**
7034+
* Returns a slice of this array to its end.
7035+
*
7036+
* @param offset The starting index.
7037+
* @return A new {@link Expression} representing the array slice.
7038+
*/
7039+
@BetaApi
7040+
public final Expression arraySliceToEnd(int offset) {
7041+
return arraySliceToEnd(this, offset);
7042+
}
7043+
7044+
/**
7045+
* Returns a slice of this array to its end.
7046+
*
7047+
* @param offset The starting index expressed as an Expression.
7048+
* @return A new {@link Expression} representing the array slice.
7049+
*/
7050+
@BetaApi
7051+
public final Expression arraySliceToEnd(Expression offset) {
7052+
return arraySliceToEnd(this, offset);
7053+
}
7054+
67807055
/**
67817056
* Creates an expression that checks if array contains a specific {@code element}.
67827057
*

0 commit comments

Comments
 (0)