@@ -710,9 +710,11 @@ - (id)initWithPercentage:(double)percentage {
710
710
- (std::shared_ptr<api::Stage>)cppStageWithReader : (FSTUserDataReader *)reader {
711
711
if (!isUserDataRead) {
712
712
if ([type isEqualToString: @" count" ]) {
713
- cpp_sample = std::make_shared<Sample>(" count" , _count, 0 );
713
+ cpp_sample =
714
+ std::make_shared<Sample>(Sample::SampleMode (Sample::SampleMode::DOCUMENTS), _count, 0 );
714
715
} else {
715
- cpp_sample = std::make_shared<Sample>(" percentage" , 0 , _percentage);
716
+ cpp_sample =
717
+ std::make_shared<Sample>(Sample::SampleMode (Sample::SampleMode::PERCENT), 0 , _percentage);
716
718
}
717
719
}
718
720
@@ -750,30 +752,35 @@ - (id)initWithOther:(FIRPipelineBridge *)other {
750
752
751
753
@implementation FIRUnnestStageBridge {
752
754
FIRExprBridge *_field;
753
- NSString *_Nullable _indexField;
755
+ FIRExprBridge *_Nullable _index_field;
756
+ FIRExprBridge *_alias;
754
757
Boolean isUserDataRead;
755
758
std::shared_ptr<Unnest> cpp_unnest;
756
759
}
757
760
758
- - (id )initWithField : (FIRExprBridge *)field indexField : (NSString *_Nullable)indexField {
761
+ - (id )initWithField : (FIRExprBridge *)field
762
+ alias : (FIRExprBridge *)alias
763
+ indexField : (FIRExprBridge *_Nullable)index_field {
759
764
self = [super init ];
760
765
if (self) {
761
766
_field = field;
762
- _indexField = indexField;
767
+ _alias = alias;
768
+ _index_field = index_field;
763
769
isUserDataRead = NO ;
764
770
}
765
771
return self;
766
772
}
767
773
768
774
- (std::shared_ptr<api::Stage>)cppStageWithReader : (FSTUserDataReader *)reader {
769
775
if (!isUserDataRead) {
770
- absl::optional<std::string > cpp_index_field;
771
- if (_indexField != nil ) {
772
- cpp_index_field = MakeString (_indexField) ;
776
+ absl::optional<std::shared_ptr<Expr> > cpp_index_field;
777
+ if (_index_field != nil ) {
778
+ cpp_index_field = [_index_field cppExprWithReader: reader] ;
773
779
} else {
774
780
cpp_index_field = absl::nullopt;
775
781
}
776
- cpp_unnest = std::make_shared<Unnest>([_field cppExprWithReader: reader], cpp_index_field);
782
+ cpp_unnest = std::make_shared<Unnest>([_field cppExprWithReader: reader],
783
+ [_alias cppExprWithReader: reader], cpp_index_field);
777
784
}
778
785
779
786
isUserDataRead = YES ;
@@ -784,14 +791,14 @@ - (id)initWithField:(FIRExprBridge *)field indexField:(NSString *_Nullable)index
784
791
785
792
@implementation FIRRawStageBridge {
786
793
NSString *_name;
787
- NSArray <FIRExprBridge * > *_params;
794
+ NSArray <id > *_params;
788
795
NSDictionary <NSString *, FIRExprBridge *> *_Nullable _options;
789
796
Boolean isUserDataRead;
790
797
std::shared_ptr<RawStage> cpp_generic_stage;
791
798
}
792
799
793
800
- (id )initWithName : (NSString *)name
794
- params : (NSArray <FIRExprBridge * > *)params
801
+ params : (NSArray <id > *)params
795
802
options : (NSDictionary <NSString *, FIRExprBridge *> *_Nullable)options {
796
803
self = [super init ];
797
804
if (self) {
@@ -803,12 +810,51 @@ - (id)initWithName:(NSString *)name
803
810
return self;
804
811
}
805
812
813
+ - (firebase::firestore::google_firestore_v1_Value)convertIdToV1Value : (id )value
814
+ reader : (FSTUserDataReader *)reader {
815
+ if ([value isKindOfClass: [FIRExprBridge class ]]) {
816
+ return [((FIRExprBridge *)value) cppExprWithReader: reader]->to_proto ();
817
+ } else if ([value isKindOfClass: [FIRAggregateFunctionBridge class ]]) {
818
+ return [((FIRAggregateFunctionBridge *)value) cppExprWithReader: reader]->to_proto ();
819
+ } else if ([value isKindOfClass: [NSDictionary class ]]) {
820
+ NSDictionary <NSString *, id > *dictionary = (NSDictionary <NSString *, id > *)value;
821
+
822
+ std::unordered_map<std::string, firebase::firestore::google_firestore_v1_Value> cpp_dictionary;
823
+ for (NSString *key in dictionary) {
824
+ if ([dictionary[key] isKindOfClass: [FIRExprBridge class ]]) {
825
+ cpp_dictionary[MakeString (key)] =
826
+ [((FIRExprBridge *)dictionary[key]) cppExprWithReader: reader]->to_proto ();
827
+ } else if ([dictionary[key] isKindOfClass: [FIRAggregateFunctionBridge class ]]) {
828
+ cpp_dictionary[MakeString (key)] =
829
+ [((FIRAggregateFunctionBridge *)dictionary[key]) cppExprWithReader: reader]->to_proto ();
830
+ } else {
831
+ ThrowInvalidArgument (
832
+ " Dictionary value must be an FIRExprBridge or FIRAggregateFunctionBridge." );
833
+ }
834
+ }
835
+
836
+ firebase::firestore::google_firestore_v1_Value result;
837
+ result.which_value_type = google_firestore_v1_Value_map_value_tag;
838
+
839
+ nanopb::SetRepeatedField (
840
+ &result.map_value .fields , &result.map_value .fields_count , cpp_dictionary,
841
+ [](const std::pair<std::string, firebase::firestore::google_firestore_v1_Value> &entry) {
842
+ return firebase::firestore::_google_firestore_v1_MapValue_FieldsEntry{
843
+ nanopb::MakeBytesArray (entry.first ), entry.second };
844
+ });
845
+ return result;
846
+ } else {
847
+ ThrowInvalidArgument (" Invalid value to convert to google_firestore_v1_Value." );
848
+ }
849
+ }
850
+
806
851
- (std::shared_ptr<api::Stage>)cppStageWithReader : (FSTUserDataReader *)reader {
807
852
if (!isUserDataRead) {
808
- std::vector<std::shared_ptr<Expr> > cpp_params;
809
- for (FIRExprBridge * param in _params) {
810
- cpp_params.push_back ([param cppExprWithReader : reader]);
853
+ std::vector<firebase::firestore::google_firestore_v1_Value > cpp_params;
854
+ for (id param in _params) {
855
+ cpp_params.push_back ([self convertIdToV1Value: param reader : reader]);
811
856
}
857
+
812
858
std::unordered_map<std::string, std::shared_ptr<Expr>> cpp_options;
813
859
if (_options) {
814
860
for (NSString *key in _options) {
@@ -928,7 +974,9 @@ - (id)initWithCppResult:(api::PipelineResult)result db:(std::shared_ptr<api::Fir
928
974
FSTUserDataWriter *dataWriter =
929
975
[[FSTUserDataWriter alloc ] initWithFirestore: _db
930
976
serverTimestampBehavior: serverTimestampBehavior];
931
- return [dataWriter convertedValue: *data];
977
+ NSDictionary <NSString *, id > *dictionary = [dataWriter convertedValue: *data];
978
+ NSLog (@" Dictionary contents: %@ " , dictionary);
979
+ return dictionary;
932
980
}
933
981
934
982
- (nullable id )get : (id )field {
@@ -959,35 +1007,41 @@ - (nullable id)get:(id)field
959
1007
@implementation FIRPipelineBridge {
960
1008
NSArray <FIRStageBridge *> *_stages;
961
1009
FIRFirestore *firestore;
1010
+ Boolean isUserDataRead;
962
1011
std::shared_ptr<Pipeline> cpp_pipeline;
963
1012
}
964
1013
965
1014
- (id )initWithStages : (NSArray <FIRStageBridge *> *)stages db : (FIRFirestore *)db {
966
1015
_stages = stages;
967
1016
firestore = db;
1017
+ isUserDataRead = NO ;
968
1018
return [super init ];
969
1019
}
970
1020
971
1021
- (void )executeWithCompletion : (void (^)(__FIRPipelineSnapshotBridge *_Nullable result,
972
1022
NSError *_Nullable error))completion {
973
- std::vector<std::shared_ptr<firebase::firestore::api::Stage>> cpp_stages;
974
- for (FIRStageBridge *stage in _stages) {
975
- cpp_stages.push_back ([stage cppStageWithReader: firestore.dataReader]);
976
- }
977
- cpp_pipeline = std::make_shared<Pipeline>(cpp_stages, firestore.wrapped );
978
-
979
- cpp_pipeline->execute ([completion](StatusOr<api::PipelineSnapshot> maybe_value) {
980
- if (maybe_value.ok ()) {
981
- __FIRPipelineSnapshotBridge *bridge = [[__FIRPipelineSnapshotBridge alloc ]
982
- initWithCppSnapshot: std: :move (maybe_value).ValueOrDie ()];
983
- completion (bridge, nil );
984
- } else {
985
- completion (nil , MakeNSError (std::move (maybe_value).status ()));
986
- }
987
- });
1023
+ [self cppPipelineWithReader: firestore.dataReader]->execute (
1024
+ [completion](StatusOr<api::PipelineSnapshot> maybe_value) {
1025
+ if (maybe_value.ok ()) {
1026
+ __FIRPipelineSnapshotBridge *bridge = [[__FIRPipelineSnapshotBridge alloc ]
1027
+ initWithCppSnapshot: std: :move (maybe_value).ValueOrDie ()];
1028
+ completion (bridge, nil );
1029
+ } else {
1030
+ completion (nil , MakeNSError (std::move (maybe_value).status ()));
1031
+ }
1032
+ });
988
1033
}
989
1034
990
1035
- (std::shared_ptr<api::Pipeline>)cppPipelineWithReader : (FSTUserDataReader *)reader {
1036
+ if (!isUserDataRead) {
1037
+ std::vector<std::shared_ptr<firebase::firestore::api::Stage>> cpp_stages;
1038
+ for (FIRStageBridge *stage in _stages) {
1039
+ cpp_stages.push_back ([stage cppStageWithReader: firestore.dataReader]);
1040
+ }
1041
+ cpp_pipeline = std::make_shared<Pipeline>(cpp_stages, firestore.wrapped );
1042
+ }
1043
+
1044
+ isUserDataRead = YES ;
991
1045
return cpp_pipeline;
992
1046
}
993
1047
0 commit comments