25
25
import com .google .api .gax .rpc .ResponseObserver ;
26
26
import com .google .api .gax .rpc .StreamController ;
27
27
import com .google .cloud .Timestamp ;
28
+ import com .google .cloud .firestore .pipeline .stages .AggregateOptions ;
29
+ import com .google .cloud .firestore .pipeline .stages .PipelineOptions ;
30
+ import com .google .cloud .firestore .pipeline .stages .GenericOptions ;
28
31
import com .google .cloud .firestore .pipeline .expressions .Accumulator ;
29
32
import com .google .cloud .firestore .pipeline .expressions .Expr ;
30
33
import com .google .cloud .firestore .pipeline .expressions .ExprWithAlias ;
44
47
import com .google .cloud .firestore .pipeline .stages .RemoveFields ;
45
48
import com .google .cloud .firestore .pipeline .stages .Replace ;
46
49
import com .google .cloud .firestore .pipeline .stages .Sample ;
47
- import com .google .cloud .firestore .pipeline .stages .SampleOptions ;
48
50
import com .google .cloud .firestore .pipeline .stages .Select ;
49
51
import com .google .cloud .firestore .pipeline .stages .Sort ;
50
52
import com .google .cloud .firestore .pipeline .stages .Stage ;
69
71
import java .util .List ;
70
72
import java .util .logging .Level ;
71
73
import java .util .logging .Logger ;
74
+ import javax .annotation .Nonnull ;
72
75
import javax .annotation .Nullable ;
73
76
74
77
/**
@@ -502,12 +505,10 @@ public Pipeline distinct(Selectable... selectables) {
502
505
* <pre>{@code
503
506
* // Find books with similar "topicVectors" to the given targetVector
504
507
* firestore.pipeline().collection("books")
505
- * .findNearest("topicVectors", targetVector, FindNearest.DistanceMeasure.cosine(),
506
- * FindNearestOptions
507
- * .builder()
508
- * .limit(10)
509
- * .distanceField("distance")
510
- * .build());
508
+ * .findNearest("topicVectors", targetVector, FindNearest.DistanceMeasure.COSINE,
509
+ * FindNearestOptions.DEFAULT
510
+ * .withLimit(10)
511
+ * .withDistanceField("distance"));
511
512
* }</pre>
512
513
*
513
514
* @param fieldName The name of the field containing the vector data. This field should store
@@ -540,12 +541,11 @@ public Pipeline findNearest(
540
541
* <pre>{@code
541
542
* // Find books with similar "topicVectors" to the given targetVector
542
543
* firestore.pipeline().collection("books")
543
- * .findNearest(Field.of("topicVectors"), targetVector, FindNearest.DistanceMeasure.cosine(),
544
- * FindNearestOptions
545
- * .builder()
546
- * .limit(10)
547
- * .distanceField("distance")
548
- * .build());
544
+ * .findNearest(
545
+ * FindNearest.of(Field.of("topicVectors"), targetVector, FindNearest.DistanceMeasure.COSINE),
546
+ * FindNearestOptions.DEFAULT
547
+ * .withLimit(10)
548
+ * .withDistanceField("distance"));
549
549
* }</pre>
550
550
*
551
551
* @param property The expression that evaluates to a vector value using the stage inputs.
@@ -590,7 +590,7 @@ public Pipeline findNearest(
590
590
*/
591
591
@ BetaApi
592
592
public Pipeline sort (Ordering ... orders ) {
593
- return append (new Sort (orders ));
593
+ return append (new Sort (ImmutableList . copyOf ( orders ) ));
594
594
}
595
595
596
596
/**
@@ -683,8 +683,7 @@ public Pipeline replace(Selectable field) {
683
683
*/
684
684
@ BetaApi
685
685
public Pipeline sample (int limit ) {
686
- SampleOptions options = SampleOptions .docLimit (limit );
687
- return sample (options );
686
+ return sample (Sample .withDocLimit (limit ));
688
687
}
689
688
690
689
/**
@@ -698,19 +697,19 @@ public Pipeline sample(int limit) {
698
697
* <pre>{@code
699
698
* // Sample 10 books, if available.
700
699
* firestore.pipeline().collection("books")
701
- * .sample(SampleOptions.docLimit (10));
700
+ * .sample(Sample.withDocLimit (10));
702
701
*
703
702
* // Sample 50% of books.
704
703
* firestore.pipeline().collection("books")
705
- * .sample(SampleOptions.percentage (0.5));
704
+ * .sample(Sample.withPercentage (0.5));
706
705
* }</pre>
707
706
*
708
- * @param options The {@code SampleOptions } specifies how sampling is performed.
707
+ * @param sample The {@code Sample } specifies how sampling is performed.
709
708
* @return A new {@code Pipeline} object with this stage appended to the stage list.
710
709
*/
711
710
@ BetaApi
712
- public Pipeline sample (SampleOptions options ) {
713
- return append (new Sample ( options ) );
711
+ public Pipeline sample (Sample sample ) {
712
+ return append (sample );
714
713
}
715
714
716
715
/**
@@ -756,21 +755,21 @@ public Pipeline union(Pipeline other) {
756
755
*
757
756
* // Emit a book document for each tag of the book.
758
757
* firestore.pipeline().collection("books")
759
- * .unnest("tags");
758
+ * .unnest("tags", "tag" );
760
759
*
761
760
* // Output:
762
- * // { "title": "The Hitchhiker's Guide to the Galaxy", "tags ": "comedy", ... }
763
- * // { "title": "The Hitchhiker's Guide to the Galaxy", "tags ": "space", ... }
764
- * // { "title": "The Hitchhiker's Guide to the Galaxy", "tags ": "adventure", ... }
761
+ * // { "title": "The Hitchhiker's Guide to the Galaxy", "tag ": "comedy", ... }
762
+ * // { "title": "The Hitchhiker's Guide to the Galaxy", "tag ": "space", ... }
763
+ * // { "title": "The Hitchhiker's Guide to the Galaxy", "tag ": "adventure", ... }
765
764
* }</pre>
766
765
*
767
766
* @param fieldName The name of the field containing the array.
768
767
* @return A new {@code Pipeline} object with this stage appended to the stage list.
769
768
*/
770
769
@ BetaApi
771
- public Pipeline unnest (String fieldName ) {
770
+ public Pipeline unnest (String fieldName , String alias ) {
772
771
// return unnest(Field.of(fieldName));
773
- return append (new Unnest (Field .of (fieldName )));
772
+ return append (new Unnest (Field .of (fieldName ), alias ));
774
773
}
775
774
776
775
// /**
@@ -829,22 +828,22 @@ public Pipeline unnest(String fieldName) {
829
828
*
830
829
* // Emit a book document for each tag of the book.
831
830
* firestore.pipeline().collection("books")
832
- * .unnest("tags", UnnestOptions.indexField ("tagIndex"));
831
+ * .unnest("tags", "tag", Unnest.Options.DEFAULT.withIndexField ("tagIndex"));
833
832
*
834
833
* // Output:
835
- * // { "title": "The Hitchhiker's Guide to the Galaxy", "tagIndex": 0, "tags ": "comedy", ... }
836
- * // { "title": "The Hitchhiker's Guide to the Galaxy", "tagIndex": 1, "tags ": "space", ... }
837
- * // { "title": "The Hitchhiker's Guide to the Galaxy", "tagIndex": 2, "tags ": "adventure", ... }
834
+ * // { "title": "The Hitchhiker's Guide to the Galaxy", "tagIndex": 0, "tag ": "comedy", ... }
835
+ * // { "title": "The Hitchhiker's Guide to the Galaxy", "tagIndex": 1, "tag ": "space", ... }
836
+ * // { "title": "The Hitchhiker's Guide to the Galaxy", "tagIndex": 2, "tag ": "adventure", ... }
838
837
* }</pre>
839
838
*
840
839
* @param fieldName The name of the field containing the array.
841
840
* @param options The {@code UnnestOptions} options.
842
841
* @return A new {@code Pipeline} object with this stage appended to the stage list.
843
842
*/
844
843
@ BetaApi
845
- public Pipeline unnest (String fieldName , UnnestOptions options ) {
844
+ public Pipeline unnest (String fieldName , String alias , UnnestOptions options ) {
846
845
// return unnest(Field.of(fieldName), options);
847
- return append (new Unnest (Field .of (fieldName ), options ));
846
+ return append (new Unnest (Field .of (fieldName ), alias , options ));
848
847
}
849
848
850
849
// /**
@@ -905,12 +904,13 @@ public Pipeline unnest(String fieldName, UnnestOptions options) {
905
904
*
906
905
* @param name The unique name of the generic stage to add.
907
906
* @param params A map of parameters to configure the generic stage's behavior.
907
+ * @param optionalParams Named optional parameters to configure the generic stage's behavior.
908
908
* @return A new {@code Pipeline} object with this stage appended to the stage list.
909
909
*/
910
910
@ BetaApi
911
- public Pipeline genericStage (String name , List <Object > params ) {
911
+ public Pipeline genericStage (String name , List <Object > params , GenericOptions optionalParams ) {
912
912
// Implementation for genericStage (add the GenericStage if needed)
913
- return append (new GenericStage (name , params )); // Assuming GenericStage takes a list of params
913
+ return append (new GenericStage (name , params , optionalParams )); // Assuming GenericStage takes a list of params
914
914
}
915
915
916
916
/**
@@ -946,7 +946,12 @@ public Pipeline genericStage(String name, List<Object> params) {
946
946
*/
947
947
@ BetaApi
948
948
public ApiFuture <List <PipelineResult >> execute () {
949
- return execute ((ByteString ) null , (com .google .protobuf .Timestamp ) null );
949
+ return execute (PipelineOptions .DEFAULT , (ByteString ) null , (com .google .protobuf .Timestamp ) null );
950
+ }
951
+
952
+ @ BetaApi
953
+ public ApiFuture <List <PipelineResult >> execute (PipelineOptions options ) {
954
+ return execute (options , (ByteString ) null , (com .google .protobuf .Timestamp ) null );
950
955
}
951
956
952
957
/**
@@ -996,7 +1001,7 @@ public ApiFuture<List<PipelineResult>> execute() {
996
1001
*/
997
1002
@ BetaApi
998
1003
public void execute (ApiStreamObserver <PipelineResult > observer ) {
999
- executeInternal (null , null , observer );
1004
+ executeInternal (PipelineOptions . DEFAULT , null , null , observer );
1000
1005
}
1001
1006
1002
1007
// @BetaApi
@@ -1016,10 +1021,13 @@ public void execute(ApiStreamObserver<PipelineResult> observer) {
1016
1021
// }
1017
1022
1018
1023
ApiFuture <List <PipelineResult >> execute (
1019
- @ Nullable final ByteString transactionId , @ Nullable com .google .protobuf .Timestamp readTime ) {
1024
+ @ Nonnull PipelineOptions options ,
1025
+ @ Nullable final ByteString transactionId ,
1026
+ @ Nullable com .google .protobuf .Timestamp readTime ) {
1020
1027
SettableApiFuture <List <PipelineResult >> futureResult = SettableApiFuture .create ();
1021
1028
1022
1029
executeInternal (
1030
+ options ,
1023
1031
transactionId ,
1024
1032
readTime ,
1025
1033
new PipelineResultObserver () {
@@ -1045,13 +1053,17 @@ public void onError(Throwable t) {
1045
1053
}
1046
1054
1047
1055
void executeInternal (
1056
+ @ Nonnull PipelineOptions options ,
1048
1057
@ Nullable final ByteString transactionId ,
1049
1058
@ Nullable com .google .protobuf .Timestamp readTime ,
1050
1059
ApiStreamObserver <PipelineResult > observer ) {
1051
1060
ExecutePipelineRequest .Builder request =
1052
1061
ExecutePipelineRequest .newBuilder ()
1053
1062
.setDatabase (rpcContext .getDatabaseName ())
1054
- .setStructuredPipeline (StructuredPipeline .newBuilder ().setPipeline (toProto ()).build ());
1063
+ .setStructuredPipeline (StructuredPipeline .newBuilder ()
1064
+ .setPipeline (toProto ())
1065
+ .putAllOptions (StageUtils .toMap (options ))
1066
+ .build ());
1055
1067
1056
1068
if (transactionId != null ) {
1057
1069
request .setTransaction (transactionId );
@@ -1164,18 +1176,18 @@ public void onComplete() {
1164
1176
1165
1177
rpcContext .streamRequest (request , observer , rpcContext .getClient ().executePipelineCallable ());
1166
1178
}
1167
- }
1168
1179
1169
- @ InternalExtensionOnly
1170
- abstract class PipelineResultObserver implements ApiStreamObserver <PipelineResult > {
1171
- private Timestamp executionTime ; // Remove optional since Java doesn't have it
1180
+ @ InternalExtensionOnly
1181
+ static abstract class PipelineResultObserver implements ApiStreamObserver <PipelineResult > {
1182
+ private Timestamp executionTime ; // Remove optional since Java doesn't have it
1172
1183
1173
- public void onCompleted (Timestamp executionTime ) {
1174
- this .executionTime = executionTime ;
1175
- this .onCompleted ();
1176
- }
1184
+ public void onCompleted (Timestamp executionTime ) {
1185
+ this .executionTime = executionTime ;
1186
+ this .onCompleted ();
1187
+ }
1177
1188
1178
- public Timestamp getExecutionTime () { // Add getter for executionTime
1179
- return executionTime ;
1189
+ public Timestamp getExecutionTime () { // Add getter for executionTime
1190
+ return executionTime ;
1191
+ }
1180
1192
}
1181
1193
}
0 commit comments