Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VQ exploration #13448

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d9e2ba6
Stub VectorValue
MarkDuckworth Jul 18, 2024
3ad498a
Porting VectorValue implementation.
MarkDuckworth Jul 22, 2024
0725ad0
VectorValue tests and fixes.
MarkDuckworth Jul 25, 2024
1d69177
Cleanup
MarkDuckworth Jul 25, 2024
1263747
cleanup
MarkDuckworth Jul 25, 2024
707c9f8
Formatting
MarkDuckworth Jul 25, 2024
a0c596e
PR feedback on codable.
MarkDuckworth Jul 29, 2024
ca625e9
formatting
MarkDuckworth Jul 29, 2024
190ea8c
PR comments c++
MarkDuckworth Jul 29, 2024
5f0b01b
Fixes based on PR feedback.
MarkDuckworth Jul 29, 2024
e0fadea
API reference doc comments.
MarkDuckworth Jul 29, 2024
e95e913
Merge branch 'main' of github.com:firebase/firebase-ios-sdk into mark…
MarkDuckworth Jul 29, 2024
ece38eb
Fix copyright header
MarkDuckworth Jul 29, 2024
c1abeb2
Update CHANGELOG.md
MarkDuckworth Jul 29, 2024
7f2aa72
Header ordering
MarkDuckworth Jul 29, 2024
7373969
Merge branch 'markduckworth/vector-type' of github.com:firebase/fireb…
MarkDuckworth Jul 29, 2024
9fc9c7b
Update Firestore/CHANGELOG.md
MarkDuckworth Aug 1, 2024
d8123e5
VQ exploration
MarkDuckworth Aug 2, 2024
15e9e0a
Merge branch 'main' of github.com:firebase/firebase-ios-sdk into mark…
MarkDuckworth Aug 6, 2024
9b88f03
Peer review updates
MarkDuckworth Aug 6, 2024
5f89b41
Merge branch 'main' of github.com:firebase/firebase-ios-sdk into mark…
MarkDuckworth Aug 6, 2024
7b4ff08
Message rename to match API design
MarkDuckworth Aug 6, 2024
7c91869
Fix comment
MarkDuckworth Aug 6, 2024
070136c
Fix CI issues
MarkDuckworth Aug 7, 2024
d749fc7
Update run_firestore_emulator.sh to 1.19.7
MarkDuckworth Aug 7, 2024
0fda84e
Code cleanup
MarkDuckworth Aug 8, 2024
72b55e2
Merge branch 'markduckworth/vector-type' of github.com:firebase/fireb…
MarkDuckworth Aug 8, 2024
f7578f2
Merge branch 'markduckworth/vector-type' into markduckworth/vq
MarkDuckworth Aug 8, 2024
07a6409
Refined Swift API
MarkDuckworth Aug 8, 2024
d9eea7a
another example
MarkDuckworth Aug 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions FirebaseFirestoreInternal/FirebaseFirestore/FIRDistanceMeasure.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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.

#import <FirebaseFirestoreInternal/FIRDistanceMeasure.h>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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.

#import <FirebaseFirestoreInternal/FIRFindNearestOptions.h>
15 changes: 15 additions & 0 deletions FirebaseFirestoreInternal/FirebaseFirestore/FIRVectorSource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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.

#import <FirebaseFirestoreInternal/FIRVectorValue.h>
15 changes: 15 additions & 0 deletions FirebaseFirestoreInternal/FirebaseFirestore/FIRVectorValue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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.

#import <FirebaseFirestoreInternal/FIRVectorValue.h>
3 changes: 3 additions & 0 deletions Firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 11.1.0
- [feature] Add `VectorValue` type support.

# 11.0.0
- [removed] **Breaking change**: The deprecated `FirebaseFirestoreSwift` module
has been removed. See
Expand Down
14 changes: 11 additions & 3 deletions Firestore/Example/Firestore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,9 @@
EF79998EBE4C72B97AB1880E /* value_util_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 40F9D09063A07F710811A84F /* value_util_test.cc */; };
EF8C005DC4BEA6256D1DBC6F /* user_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = CCC9BD953F121B9E29F9AA42 /* user_test.cc */; };
EFD682178A87513A5F1AEFD9 /* memory_query_engine_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 8EF6A33BC2D84233C355F1D0 /* memory_query_engine_test.cc */; };
EFF22EAA2C5060A4009A369B /* VectorIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFF22EA92C5060A4009A369B /* VectorIntegrationTests.swift */; };
EFF22EAB2C5060A4009A369B /* VectorIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFF22EA92C5060A4009A369B /* VectorIntegrationTests.swift */; };
EFF22EAC2C5060A4009A369B /* VectorIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFF22EA92C5060A4009A369B /* VectorIntegrationTests.swift */; };
F05B277F16BDE6A47FE0F943 /* local_serializer_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = F8043813A5D16963EC02B182 /* local_serializer_test.cc */; };
F08DA55D31E44CB5B9170CCE /* limbo_spec_test.json in Resources */ = {isa = PBXBuildFile; fileRef = 54DA129E1F315EE100DD57A1 /* limbo_spec_test.json */; };
F091532DEE529255FB008E25 /* snapshot_version_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = ABA495B9202B7E79008A7851 /* snapshot_version_test.cc */; };
Expand Down Expand Up @@ -1687,7 +1690,7 @@
132E32997D781B896672D30A /* reference_set_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = reference_set_test.cc; sourceTree = "<group>"; };
166CE73C03AB4366AAC5201C /* leveldb_index_manager_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = leveldb_index_manager_test.cc; sourceTree = "<group>"; };
1A7D48A017ECB54FD381D126 /* Validation_BloomFilterTest_MD5_5000_1_membership_test_result.json */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.json; name = Validation_BloomFilterTest_MD5_5000_1_membership_test_result.json; path = bloom_filter_golden_test_data/Validation_BloomFilterTest_MD5_5000_1_membership_test_result.json; sourceTree = "<group>"; };
1A8141230C7E3986EACEF0B6 /* thread_safe_memoizer_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; path = thread_safe_memoizer_test.cc; sourceTree = "<group>"; };
1A8141230C7E3986EACEF0B6 /* thread_safe_memoizer_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = thread_safe_memoizer_test.cc; sourceTree = "<group>"; };
1B342370EAE3AA02393E33EB /* cc_compilation_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; name = cc_compilation_test.cc; path = api/cc_compilation_test.cc; sourceTree = "<group>"; };
1B9F95EC29FAD3F100EEC075 /* FIRAggregateQueryUnitTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FIRAggregateQueryUnitTests.mm; sourceTree = "<group>"; };
1C01D8CE367C56BB2624E299 /* index.pb.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = index.pb.h; path = admin/index.pb.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1744,7 +1747,7 @@
4BD051DBE754950FEAC7A446 /* Validation_BloomFilterTest_MD5_500_01_bloom_filter_proto.json */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.json; name = Validation_BloomFilterTest_MD5_500_01_bloom_filter_proto.json; path = bloom_filter_golden_test_data/Validation_BloomFilterTest_MD5_500_01_bloom_filter_proto.json; sourceTree = "<group>"; };
4C73C0CC6F62A90D8573F383 /* string_apple_benchmark.mm */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.objcpp; path = string_apple_benchmark.mm; sourceTree = "<group>"; };
4D65F6E69993611D47DC8E7C /* SnapshotListenerSourceTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = SnapshotListenerSourceTests.swift; sourceTree = "<group>"; };
4D9E51DA7A275D8B1CAEAEB2 /* listen_source_spec_test.json */ = {isa = PBXFileReference; includeInIndex = 1; path = listen_source_spec_test.json; sourceTree = "<group>"; };
4D9E51DA7A275D8B1CAEAEB2 /* listen_source_spec_test.json */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.json; path = listen_source_spec_test.json; sourceTree = "<group>"; };
4F5B96F3ABCD2CA901DB1CD4 /* bundle_builder.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = bundle_builder.cc; sourceTree = "<group>"; };
526D755F65AC676234F57125 /* target_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = target_test.cc; sourceTree = "<group>"; };
52756B7624904C36FBB56000 /* fake_target_metadata_provider.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = fake_target_metadata_provider.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1898,7 +1901,7 @@
62E54B832A9E910A003347C8 /* IndexingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IndexingTests.swift; sourceTree = "<group>"; };
63136A2371C0C013EC7A540C /* target_index_matcher_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = target_index_matcher_test.cc; sourceTree = "<group>"; };
64AA92CFA356A2360F3C5646 /* filesystem_testing.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = filesystem_testing.h; sourceTree = "<group>"; };
65AF0AB593C3AD81A1F1A57E /* FIRCompositeIndexQueryTests.mm */ = {isa = PBXFileReference; includeInIndex = 1; path = FIRCompositeIndexQueryTests.mm; sourceTree = "<group>"; };
65AF0AB593C3AD81A1F1A57E /* FIRCompositeIndexQueryTests.mm */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.objcpp; path = FIRCompositeIndexQueryTests.mm; sourceTree = "<group>"; };
67786C62C76A740AEDBD8CD3 /* FSTTestingHooks.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = FSTTestingHooks.h; sourceTree = "<group>"; };
69E6C311558EC77729A16CF1 /* Pods-Firestore_Example_iOS-Firestore_SwiftTests_iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Example_iOS-Firestore_SwiftTests_iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Example_iOS-Firestore_SwiftTests_iOS/Pods-Firestore_Example_iOS-Firestore_SwiftTests_iOS.debug.xcconfig"; sourceTree = "<group>"; };
6A7A30A2DB3367E08939E789 /* bloom_filter.pb.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = bloom_filter.pb.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2083,6 +2086,7 @@
EF6C285029E462A200A7D4F1 /* FIRAggregateTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FIRAggregateTests.mm; sourceTree = "<group>"; };
EF6C286C29E6D22200A7D4F1 /* AggregationIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AggregationIntegrationTests.swift; sourceTree = "<group>"; };
EF83ACD5E1E9F25845A9ACED /* leveldb_migrations_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = leveldb_migrations_test.cc; sourceTree = "<group>"; };
EFF22EA92C5060A4009A369B /* VectorIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VectorIntegrationTests.swift; sourceTree = "<group>"; };
F02F734F272C3C70D1307076 /* filter_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = filter_test.cc; sourceTree = "<group>"; };
F119BDDF2F06B3C0883B8297 /* firebase_app_check_credentials_provider_test.mm */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.objcpp; name = firebase_app_check_credentials_provider_test.mm; path = credentials/firebase_app_check_credentials_provider_test.mm; sourceTree = "<group>"; };
F354C0FE92645B56A6C6FD44 /* Pods-Firestore_IntegrationTests_iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_IntegrationTests_iOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_IntegrationTests_iOS/Pods-Firestore_IntegrationTests_iOS.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2226,6 +2230,7 @@
62E54B832A9E910A003347C8 /* IndexingTests.swift */,
621D620928F9CE7400D2FA26 /* QueryIntegrationTests.swift */,
4D65F6E69993611D47DC8E7C /* SnapshotListenerSourceTests.swift */,
EFF22EA92C5060A4009A369B /* VectorIntegrationTests.swift */,
);
path = Integration;
sourceTree = "<group>";
Expand Down Expand Up @@ -4581,6 +4586,7 @@
62E54B862A9E910B003347C8 /* IndexingTests.swift in Sources */,
621D620C28F9CE7400D2FA26 /* QueryIntegrationTests.swift in Sources */,
1CFBD4563960D8A20C4679A3 /* SnapshotListenerSourceTests.swift in Sources */,
EFF22EAC2C5060A4009A369B /* VectorIntegrationTests.swift in Sources */,
4D42E5C756229C08560DD731 /* XCTestCase+Await.mm in Sources */,
09BE8C01EC33D1FD82262D5D /* aggregate_query_test.cc in Sources */,
0EC3921AE220410F7394729B /* aggregation_result.pb.cc in Sources */,
Expand Down Expand Up @@ -4821,6 +4827,7 @@
62E54B852A9E910B003347C8 /* IndexingTests.swift in Sources */,
621D620B28F9CE7400D2FA26 /* QueryIntegrationTests.swift in Sources */,
A0BC30D482B0ABD1A3A24CDC /* SnapshotListenerSourceTests.swift in Sources */,
EFF22EAB2C5060A4009A369B /* VectorIntegrationTests.swift in Sources */,
736C4E82689F1CA1859C4A3F /* XCTestCase+Await.mm in Sources */,
412BE974741729A6683C386F /* aggregate_query_test.cc in Sources */,
DF983A9C1FBF758AF3AF110D /* aggregation_result.pb.cc in Sources */,
Expand Down Expand Up @@ -5307,6 +5314,7 @@
62E54B842A9E910B003347C8 /* IndexingTests.swift in Sources */,
621D620A28F9CE7400D2FA26 /* QueryIntegrationTests.swift in Sources */,
B00F8D1819EE20C45B660940 /* SnapshotListenerSourceTests.swift in Sources */,
EFF22EAA2C5060A4009A369B /* VectorIntegrationTests.swift in Sources */,
5492E0442021457E00B64F25 /* XCTestCase+Await.mm in Sources */,
B04E4FE20930384DF3A402F9 /* aggregate_query_test.cc in Sources */,
1A3D8028303B45FCBB21CAD3 /* aggregation_result.pb.cc in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
enableASanStackUseAfterReturn = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
enableASanStackUseAfterReturn = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6003F5AD195388D20070C39A"
BuildableName = "Firestore_Tests_iOS.xctest"
BlueprintName = "Firestore_Tests_iOS"
ReferencedContainer = "container:Firestore.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -40,17 +49,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6003F5AD195388D20070C39A"
BuildableName = "Firestore_Tests_iOS.xctest"
BlueprintName = "Firestore_Tests_iOS"
ReferencedContainer = "container:Firestore.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -71,8 +69,6 @@
ReferencedContainer = "container:Firestore.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
5 changes: 5 additions & 0 deletions Firestore/Source/API/FIRFieldValue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#import "Firestore/Source/API/FIRFieldValue+Internal.h"
#import "Firestore/Source/Public/FirebaseFirestore/FIRVectorValue.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -176,6 +177,10 @@ + (instancetype)fieldValueForIntegerIncrement:(int64_t)l {
return [[FSTNumericIncrementFieldValue alloc] initWithOperand:@(l)];
}

+ (nonnull FIRVectorValue *)vectorWithArray:(nonnull NSArray<NSNumber *> *)array {
return [[FIRVectorValue alloc] initWithArray:array];
}

@end

NS_ASSUME_NONNULL_END
52 changes: 52 additions & 0 deletions Firestore/Source/API/FIRVectorValue.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.
*/

#import <Foundation/Foundation.h>

#include <vector>

#include "Firestore/Source/Public/FirebaseFirestore/FIRVectorValue.h"

NS_ASSUME_NONNULL_BEGIN

@implementation FIRVectorValue

@synthesize array = _internalValue;

- (instancetype)initWithArray:(NSArray<NSNumber *> *)array {
if (self = [super init]) {
_internalValue = [NSArray arrayWithArray:array];
}
return self;
}

- (BOOL)isEqual:(nullable id)object {
if (self == object) {
return YES;
}

if (![object isKindOfClass:[FIRVectorValue class]]) {
return NO;
}

FIRVectorValue *otherVector = ((FIRVectorValue *)object);

return [self.array isEqualToArray:otherVector.array];
}

@end

NS_ASSUME_NONNULL_END
41 changes: 40 additions & 1 deletion Firestore/Source/API/FSTUserDataReader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#import "Firestore/Source/API/FSTUserDataReader.h"

#import "FIRGeoPoint.h"
#import "FIRVectorValue.h"

#import "Firestore/Source/API/FIRDocumentReference+Internal.h"
#import "Firestore/Source/API/FIRFieldPath+Internal.h"
Expand Down Expand Up @@ -341,6 +342,42 @@ - (ParsedUpdateData)parsedUpdateData:(id)input {
return std::move(result);
}

- (Message<google_firestore_v1_Value>)parseVectorValue:(FIRVectorValue *)vectorValue
context:(ParseContext &&)context {
__block Message<google_firestore_v1_Value> result;
result->which_value_type = google_firestore_v1_Value_map_value_tag;
result->map_value = {};

result->map_value.fields_count = 2;
result->map_value.fields = nanopb::MakeArray<google_firestore_v1_MapValue_FieldsEntry>(2);

result->map_value.fields[0].key = nanopb::CopyBytesArray(model::kTypeValueFieldKey);
result->map_value.fields[0].value = *[self encodeStringValue:MakeString(@"__vector__")].release();

NSArray<NSNumber *> *vectorArray = vectorValue.array;

__block Message<google_firestore_v1_Value> arrayMessage;
arrayMessage->which_value_type = google_firestore_v1_Value_array_value_tag;
arrayMessage->array_value.values_count = CheckedSize([vectorArray count]);
arrayMessage->array_value.values =
nanopb::MakeArray<google_firestore_v1_Value>(arrayMessage->array_value.values_count);

[vectorArray enumerateObjectsUsingBlock:^(id entry, NSUInteger idx, BOOL *) {
if (![entry isKindOfClass:[NSNumber class]]) {
ThrowInvalidArgument("VectorValues must only contain numeric values.",
context.FieldDescription());
}

// Vector values must always use Double encoding
arrayMessage->array_value.values[idx] = *[self encodeDouble:[entry doubleValue]].release();
}];

result->map_value.fields[1].key = nanopb::CopyBytesArray(model::kVectorValueFieldKey);
result->map_value.fields[1].value = *arrayMessage.release();

return std::move(result);
}

- (Message<google_firestore_v1_Value>)parseArray:(NSArray<id> *)array
context:(ParseContext &&)context {
__block Message<google_firestore_v1_Value> result;
Expand Down Expand Up @@ -529,7 +566,9 @@ - (void)parseSentinelFieldValue:(FIRFieldValue *)fieldValue context:(ParseContex
_databaseID.database_id(), context.FieldDescription());
}
return [self encodeReference:_databaseID key:reference.key];

} else if ([input isKindOfClass:[FIRVectorValue class]]) {
FIRVectorValue *vector = input;
return [self parseVectorValue:vector context:std::move(context)];
} else {
ThrowInvalidArgument("Unsupported type: %s%s", NSStringFromClass([input class]),
context.FieldDescription());
Expand Down
Loading
Loading