aboutsummaryrefslogtreecommitdiff
path: root/icing/schema/section-manager_test.cc
blob: eee78e95b764488ba86c17c3e8963ab2f9ae507f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
// Copyright (C) 2019 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.

#include "icing/schema/section-manager.h"

#include <memory>
#include <string>
#include <string_view>

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "icing/document-builder.h"
#include "icing/file/filesystem.h"
#include "icing/proto/document.pb.h"
#include "icing/proto/schema.pb.h"
#include "icing/schema-builder.h"
#include "icing/schema/schema-type-manager.h"
#include "icing/schema/schema-util.h"
#include "icing/store/dynamic-trie-key-mapper.h"
#include "icing/store/key-mapper.h"
#include "icing/testing/common-matchers.h"
#include "icing/testing/tmp-directory.h"

namespace icing {
namespace lib {

namespace {

using ::testing::ElementsAre;
using ::testing::IsEmpty;
using ::testing::Pointee;
using ::testing::SizeIs;

// type and property names of Email
static constexpr std::string_view kTypeEmail = "Email";
// indexable
static constexpr std::string_view kPropertyRecipientIds = "recipientIds";
static constexpr std::string_view kPropertyRecipients = "recipients";
static constexpr std::string_view kPropertySubject = "subject";
static constexpr std::string_view kPropertyTimestamp = "timestamp";
// non-indexable
static constexpr std::string_view kPropertyAttachment = "attachment";
static constexpr std::string_view kPropertyNonIndexableInteger =
    "nonIndexableInteger";
static constexpr std::string_view kPropertyText = "text";

// type and property names of Conversation
static constexpr std::string_view kTypeConversation = "Conversation";
// indexable
static constexpr std::string_view kPropertyEmails = "emails";
static constexpr std::string_view kPropertyName = "name";

// type and property names of Group
static constexpr std::string_view kTypeGroup = "Group";
// indexable
static constexpr std::string_view kPropertyConversation = "conversation";
static constexpr std::string_view kPropertyGroupName = "groupName";
// nested indexable
static constexpr std::string_view kPropertyNestedConversationName = "name";
static constexpr std::string_view kPropertyNestedConversationEmailRecipientIds =
    "emails.recipientIds";
static constexpr std::string_view kPropertyNestedConversationEmailRecipient =
    "emails.recipients";
static constexpr std::string_view kPropertyNestedConversationEmailSubject =
    "emails.subject";
// nested non-indexable
static constexpr std::string_view kPropertyNestedConversationEmailAttachment =
    "emails.attachment";
// non-existent property path
static constexpr std::string_view kPropertyNestedNonExistent =
    "emails.nonExistentNestedProperty";
static constexpr std::string_view kPropertyNestedNonExistent2 =
    "emails.nonExistentNestedProperty2";

constexpr int64_t kDefaultTimestamp = 1663274901;

PropertyConfigProto CreateRecipientIdsPropertyConfig() {
  return PropertyConfigBuilder()
      .SetName(kPropertyRecipientIds)
      .SetDataTypeInt64(NUMERIC_MATCH_RANGE)
      .SetCardinality(CARDINALITY_REPEATED)
      .Build();
}

PropertyConfigProto CreateRecipientsPropertyConfig() {
  return PropertyConfigBuilder()
      .SetName(kPropertyRecipients)
      .SetDataTypeString(TERM_MATCH_EXACT, TOKENIZER_PLAIN)
      .SetCardinality(CARDINALITY_REPEATED)
      .Build();
}

PropertyConfigProto CreateSubjectPropertyConfig() {
  return PropertyConfigBuilder()
      .SetName(kPropertySubject)
      .SetDataTypeString(TERM_MATCH_EXACT, TOKENIZER_PLAIN)
      .SetCardinality(CARDINALITY_REQUIRED)
      .Build();
}

PropertyConfigProto CreateTimestampPropertyConfig() {
  return PropertyConfigBuilder()
      .SetName(kPropertyTimestamp)
      .SetDataTypeInt64(NUMERIC_MATCH_RANGE)
      .SetCardinality(CARDINALITY_REQUIRED)
      .Build();
}

PropertyConfigProto CreateNamePropertyConfig() {
  return PropertyConfigBuilder()
      .SetName(kPropertyName)
      .SetDataTypeString(TERM_MATCH_EXACT, TOKENIZER_PLAIN)
      .SetCardinality(CARDINALITY_OPTIONAL)
      .Build();
}

PropertyConfigProto CreateAttachmentPropertyConfig() {
  return PropertyConfigBuilder()
      .SetName(kPropertyAttachment)
      .SetDataType(TYPE_BYTES)
      .SetCardinality(CARDINALITY_OPTIONAL)
      .Build();
}

PropertyConfigProto CreateGroupNamePropertyConfig() {
  return PropertyConfigBuilder()
      .SetName(kPropertyGroupName)
      .SetDataTypeString(TERM_MATCH_EXACT, TOKENIZER_PLAIN)
      .SetCardinality(CARDINALITY_OPTIONAL)
      .Build();
}

SchemaTypeConfigProto CreateEmailTypeConfig() {
  return SchemaTypeConfigBuilder()
      .SetType(kTypeEmail)
      .AddProperty(CreateSubjectPropertyConfig())
      .AddProperty(PropertyConfigBuilder()
                       .SetName(kPropertyText)
                       .SetDataTypeString(TERM_MATCH_UNKNOWN, TOKENIZER_NONE)
                       .SetCardinality(CARDINALITY_OPTIONAL))
      .AddProperty(PropertyConfigBuilder()
                       .SetName(kPropertyAttachment)
                       .SetDataType(TYPE_BYTES)
                       .SetCardinality(CARDINALITY_REQUIRED))
      .AddProperty(CreateRecipientsPropertyConfig())
      .AddProperty(CreateRecipientIdsPropertyConfig())
      .AddProperty(CreateTimestampPropertyConfig())
      .AddProperty(PropertyConfigBuilder()
                       .SetName(kPropertyNonIndexableInteger)
                       .SetDataType(TYPE_INT64)
                       .SetCardinality(CARDINALITY_REQUIRED))
      .Build();
}

SchemaTypeConfigProto CreateConversationTypeConfig() {
  return SchemaTypeConfigBuilder()
      .SetType(kTypeConversation)
      .AddProperty(CreateNamePropertyConfig())
      .AddProperty(PropertyConfigBuilder()
                       .SetName(kPropertyEmails)
                       .SetDataTypeDocument(kTypeEmail,
                                            /*index_nested_properties=*/true)
                       .SetCardinality(CARDINALITY_REPEATED))
      .Build();
}

SchemaTypeConfigProto CreateGroupTypeConfig() {
  return SchemaTypeConfigBuilder()
      .SetType(kTypeGroup)
      .AddProperty(CreateGroupNamePropertyConfig())
      .AddProperty(
          PropertyConfigBuilder()
              .SetName(kPropertyConversation)
              .SetDataTypeDocument(
                  kTypeConversation,
                  /*indexable_nested_properties_list=*/
                  {std::string(kPropertyNestedConversationName),
                   std::string(kPropertyNestedConversationEmailRecipientIds),
                   std::string(kPropertyNestedConversationEmailSubject),
                   std::string(kPropertyNestedConversationEmailRecipient),
                   std::string(kPropertyNestedConversationEmailAttachment),
                   std::string(kPropertyNestedNonExistent2),
                   std::string(kPropertyNestedNonExistent),
                   std::string(kPropertyNestedNonExistent)})
              .SetCardinality(CARDINALITY_REPEATED))
      .Build();
}

class SectionManagerTest : public ::testing::Test {
 protected:
  void SetUp() override {
    test_dir_ = GetTestTempDir() + "/icing";

    auto email_type = CreateEmailTypeConfig();
    auto conversation_type = CreateConversationTypeConfig();
    auto group_type = CreateGroupTypeConfig();
    type_config_map_.emplace(email_type.schema_type(), email_type);
    type_config_map_.emplace(conversation_type.schema_type(),
                             conversation_type);
    type_config_map_.emplace(group_type.schema_type(), group_type);

    // DynamicTrieKeyMapper uses 3 internal arrays for bookkeeping. Give each
    // one 128KiB so the total DynamicTrieKeyMapper should get 384KiB
    int key_mapper_size = 3 * 128 * 1024;
    ICING_ASSERT_OK_AND_ASSIGN(schema_type_mapper_,
                               DynamicTrieKeyMapper<SchemaTypeId>::Create(
                                   filesystem_, test_dir_, key_mapper_size));
    ICING_ASSERT_OK(schema_type_mapper_->Put(kTypeEmail, 0));
    ICING_ASSERT_OK(schema_type_mapper_->Put(kTypeConversation, 1));
    ICING_ASSERT_OK(schema_type_mapper_->Put(kTypeGroup, 2));

    email_document_ =
        DocumentBuilder()
            .SetKey("icing", "email/1")
            .SetSchema(std::string(kTypeEmail))
            .AddStringProperty(std::string(kPropertySubject), "the subject")
            .AddStringProperty(std::string(kPropertyText), "the text")
            .AddBytesProperty(std::string(kPropertyAttachment),
                              "attachment bytes")
            .AddStringProperty(std::string(kPropertyRecipients), "recipient1",
                               "recipient2", "recipient3")
            .AddInt64Property(std::string(kPropertyRecipientIds), 1, 2, 3)
            .AddInt64Property(std::string(kPropertyTimestamp),
                              kDefaultTimestamp)
            .AddInt64Property(std::string(kPropertyNonIndexableInteger), 100)
            .Build();

    conversation_document_ =
        DocumentBuilder()
            .SetKey("icing", "conversation/1")
            .SetSchema(std::string(kTypeConversation))
            .AddDocumentProperty(std::string(kPropertyEmails),
                                 DocumentProto(email_document_),
                                 DocumentProto(email_document_))
            .Build();

    group_document_ =
        DocumentBuilder()
            .SetKey("icing", "group/1")
            .SetSchema(std::string(kTypeGroup))
            .AddDocumentProperty(std::string(kPropertyConversation),
                                 DocumentProto(conversation_document_))
            .AddStringProperty(std::string(kPropertyGroupName), "group_name_1")
            .Build();
  }

  void TearDown() override {
    schema_type_mapper_.reset();
    filesystem_.DeleteDirectoryRecursively(test_dir_.c_str());
  }

  Filesystem filesystem_;
  std::string test_dir_;
  SchemaUtil::TypeConfigMap type_config_map_;
  std::unique_ptr<KeyMapper<SchemaTypeId>> schema_type_mapper_;

  DocumentProto email_document_;
  DocumentProto conversation_document_;
  DocumentProto group_document_;
};

TEST_F(SectionManagerTest, ExtractSections) {
  // Use SchemaTypeManager factory method to instantiate SectionManager.
  ICING_ASSERT_OK_AND_ASSIGN(
      std::unique_ptr<SchemaTypeManager> schema_type_manager,
      SchemaTypeManager::Create(type_config_map_, schema_type_mapper_.get()));

  // Extracts all sections from 'Email' document
  ICING_ASSERT_OK_AND_ASSIGN(
      SectionGroup section_group,
      schema_type_manager->section_manager().ExtractSections(email_document_));

  // String sections
  EXPECT_THAT(section_group.string_sections, SizeIs(2));

  EXPECT_THAT(section_group.string_sections[0].metadata,
              EqualsSectionMetadata(/*expected_id=*/1,
                                    /*expected_property_path=*/"recipients",
                                    CreateRecipientsPropertyConfig()));
  EXPECT_THAT(section_group.string_sections[0].content,
              ElementsAre("recipient1", "recipient2", "recipient3"));

  EXPECT_THAT(section_group.string_sections[1].metadata,
              EqualsSectionMetadata(/*expected_id=*/2,
                                    /*expected_property_path=*/"subject",
                                    CreateSubjectPropertyConfig()));
  EXPECT_THAT(section_group.string_sections[1].content,
              ElementsAre("the subject"));

  // Integer sections
  EXPECT_THAT(section_group.integer_sections, SizeIs(2));

  EXPECT_THAT(section_group.integer_sections[0].metadata,
              EqualsSectionMetadata(/*expected_id=*/0,
                                    /*expected_property_path=*/"recipientIds",
                                    CreateRecipientIdsPropertyConfig()));
  EXPECT_THAT(section_group.integer_sections[0].content, ElementsAre(1, 2, 3));

  EXPECT_THAT(section_group.integer_sections[1].metadata,
              EqualsSectionMetadata(/*expected_id=*/3,
                                    /*expected_property_path=*/"timestamp",
                                    CreateTimestampPropertyConfig()));
  EXPECT_THAT(section_group.integer_sections[1].content,
              ElementsAre(kDefaultTimestamp));
}

TEST_F(SectionManagerTest, ExtractSectionsNested) {
  // Use SchemaTypeManager factory method to instantiate SectionManager.
  ICING_ASSERT_OK_AND_ASSIGN(
      std::unique_ptr<SchemaTypeManager> schema_type_manager,
      SchemaTypeManager::Create(type_config_map_, schema_type_mapper_.get()));

  // Extracts all sections from 'Conversation' document
  ICING_ASSERT_OK_AND_ASSIGN(
      SectionGroup section_group,
      schema_type_manager->section_manager().ExtractSections(
          conversation_document_));

  // String sections
  EXPECT_THAT(section_group.string_sections, SizeIs(2));

  EXPECT_THAT(
      section_group.string_sections[0].metadata,
      EqualsSectionMetadata(/*expected_id=*/1,
                            /*expected_property_path=*/"emails.recipients",
                            CreateRecipientsPropertyConfig()));
  EXPECT_THAT(section_group.string_sections[0].content,
              ElementsAre("recipient1", "recipient2", "recipient3",
                          "recipient1", "recipient2", "recipient3"));

  EXPECT_THAT(section_group.string_sections[1].metadata,
              EqualsSectionMetadata(/*expected_id=*/2,
                                    /*expected_property_path=*/"emails.subject",
                                    CreateSubjectPropertyConfig()));
  EXPECT_THAT(section_group.string_sections[1].content,
              ElementsAre("the subject", "the subject"));

  // Integer sections
  EXPECT_THAT(section_group.integer_sections, SizeIs(2));

  EXPECT_THAT(
      section_group.integer_sections[0].metadata,
      EqualsSectionMetadata(/*expected_id=*/0,
                            /*expected_property_path=*/"emails.recipientIds",
                            CreateRecipientIdsPropertyConfig()));
  EXPECT_THAT(section_group.integer_sections[0].content,
              ElementsAre(1, 2, 3, 1, 2, 3));

  EXPECT_THAT(
      section_group.integer_sections[1].metadata,
      EqualsSectionMetadata(/*expected_id=*/3,
                            /*expected_property_path=*/"emails.timestamp",
                            CreateTimestampPropertyConfig()));
  EXPECT_THAT(section_group.integer_sections[1].content,
              ElementsAre(kDefaultTimestamp, kDefaultTimestamp));
}

TEST_F(SectionManagerTest, ExtractSectionsIndexableNestedPropertiesList) {
  // Use SchemaTypeManager factory method to instantiate SectionManager.
  ICING_ASSERT_OK_AND_ASSIGN(
      std::unique_ptr<SchemaTypeManager> schema_type_manager,
      SchemaTypeManager::Create(type_config_map_, schema_type_mapper_.get()));

  // Extracts all sections from 'Group' document
  ICING_ASSERT_OK_AND_ASSIGN(
      SectionGroup section_group,
      schema_type_manager->section_manager().ExtractSections(group_document_));

  // SectionId assignments:
  //    0 -> conversation.emails.attachment (bytes, non-indexable)
  //    1 -> conversation.emails.recipientIds (int64)
  //    2 -> conversation.emails.recipients (string)
  //    3 -> conversation.emails.subject (string)
  //    4 -> conversation.name
  //         (string, but no entry for this in conversation_document_)
  //    5 -> groupName (string)
  //    6 -> conversation.emails.nonExistentNestedProperty
  //         (unknown, non-indexable)
  //    7 -> conversation.emails.nonExistentNestedProperty2
  //         (unknown, non-indexable)
  //
  // SectionId assignment order:
  // - We assign section ids to known (existing) properties first in alphabet
  //  order.
  // - After handling all known properties, we assign section ids to all unknown
  //   (non-existent) properties that are specified in the
  //  indexable_nested_properties_list.
  // - As a result, assignment of the entire section set is not done
  //   alphabetically, but assignment is still deterministic and alphabetical
  //   order is preserved inside the known properties and unknown properties
  //   sets individually.
  //
  // 'conversation.emails.attachment',
  // 'conversation.emails.nonExistentNestedProperty' and
  // 'conversation.emails.nonExistentNestedProperty2' are assigned sectionIds
  // even though they are non-indexable because they appear in 'Group' schema
  // type's indexable_nested_props_list.
  // However 'conversation.emails.attachment' does not exist in section_group
  // (even though the property exists and has a sectionId assignment) as
  // SectionManager::ExtractSections only extracts indexable string and integer
  // section data from a document.

  // String sections
  EXPECT_THAT(section_group.string_sections, SizeIs(3));

  EXPECT_THAT(section_group.string_sections[0].metadata,
              EqualsSectionMetadata(
                  /*expected_id=*/2,
                  /*expected_property_path=*/"conversation.emails.recipients",
                  CreateRecipientsPropertyConfig()));
  EXPECT_THAT(section_group.string_sections[0].content,
              ElementsAre("recipient1", "recipient2", "recipient3",
                          "recipient1", "recipient2", "recipient3"));

  EXPECT_THAT(section_group.string_sections[1].metadata,
              EqualsSectionMetadata(
                  /*expected_id=*/3,
                  /*expected_property_path=*/"conversation.emails.subject",
                  CreateSubjectPropertyConfig()));
  EXPECT_THAT(section_group.string_sections[1].content,
              ElementsAre("the subject", "the subject"));

  EXPECT_THAT(section_group.string_sections[2].metadata,
              EqualsSectionMetadata(
                  /*expected_id=*/5,
                  /*expected_property_path=*/"groupName",
                  CreateGroupNamePropertyConfig()));
  EXPECT_THAT(section_group.string_sections[2].content,
              ElementsAre("group_name_1"));

  // Integer sections
  EXPECT_THAT(section_group.integer_sections, SizeIs(1));

  EXPECT_THAT(section_group.integer_sections[0].metadata,
              EqualsSectionMetadata(
                  /*expected_id=*/1,
                  /*expected_property_path=*/"conversation.emails.recipientIds",
                  CreateRecipientIdsPropertyConfig()));
  EXPECT_THAT(section_group.integer_sections[0].content,
              ElementsAre(1, 2, 3, 1, 2, 3));
}

TEST_F(SectionManagerTest, GetSectionMetadata) {
  // Use SchemaTypeManager factory method to instantiate SectionManager.
  ICING_ASSERT_OK_AND_ASSIGN(
      std::unique_ptr<SchemaTypeManager> schema_type_manager,
      SchemaTypeManager::Create(type_config_map_, schema_type_mapper_.get()));

  // Email (section id -> section property path):
  //   0 -> recipientIds
  //   1 -> recipients
  //   2 -> subject
  //   3 -> timestamp
  EXPECT_THAT(schema_type_manager->section_manager().GetSectionMetadata(
                  /*schema_type_id=*/0, /*section_id=*/0),
              IsOkAndHolds(Pointee(EqualsSectionMetadata(
                  /*expected_id=*/0, /*expected_property_path=*/"recipientIds",
                  CreateRecipientIdsPropertyConfig()))));
  EXPECT_THAT(schema_type_manager->section_manager().GetSectionMetadata(
                  /*schema_type_id=*/0, /*section_id=*/1),
              IsOkAndHolds(Pointee(EqualsSectionMetadata(
                  /*expected_id=*/1, /*expected_property_path=*/"recipients",
                  CreateRecipientsPropertyConfig()))));

  // Conversation (section id -> section property path):
  //   0 -> emails.recipientIds
  //   1 -> emails.recipients
  //   2 -> emails.subject
  //   3 -> emails.timestamp
  //   4 -> name
  EXPECT_THAT(
      schema_type_manager->section_manager().GetSectionMetadata(
          /*schema_type_id=*/1, /*section_id=*/0),
      IsOkAndHolds(Pointee(EqualsSectionMetadata(
          /*expected_id=*/0, /*expected_property_path=*/"emails.recipientIds",
          CreateRecipientIdsPropertyConfig()))));
  EXPECT_THAT(
      schema_type_manager->section_manager().GetSectionMetadata(
          /*schema_type_id=*/1, /*section_id=*/1),
      IsOkAndHolds(Pointee(EqualsSectionMetadata(
          /*expected_id=*/1, /*expected_property_path=*/"emails.recipients",
          CreateRecipientsPropertyConfig()))));
  EXPECT_THAT(
      schema_type_manager->section_manager().GetSectionMetadata(
          /*schema_type_id=*/1, /*section_id=*/2),
      IsOkAndHolds(Pointee(EqualsSectionMetadata(
          /*expected_id=*/2, /*expected_property_path=*/"emails.subject",
          CreateSubjectPropertyConfig()))));
  EXPECT_THAT(
      schema_type_manager->section_manager().GetSectionMetadata(
          /*schema_type_id=*/1, /*section_id=*/3),
      IsOkAndHolds(Pointee(EqualsSectionMetadata(
          /*expected_id=*/3, /*expected_property_path=*/"emails.timestamp",
          CreateTimestampPropertyConfig()))));
  EXPECT_THAT(schema_type_manager->section_manager().GetSectionMetadata(
                  /*schema_type_id=*/1, /*section_id=*/4),
              IsOkAndHolds(Pointee(EqualsSectionMetadata(
                  /*expected_id=*/4, /*expected_property_path=*/"name",
                  CreateNamePropertyConfig()))));

  // Group (section id -> section property path):
  //    0 -> conversation.emails.attachment (non-indexable)
  //    1 -> conversation.emails.recipientIds
  //    2 -> conversation.emails.recipients
  //    3 -> conversation.emails.subject
  //    4 -> conversation.name
  //    5 -> groupName
  //    6 -> conversation.emails.nonExistentNestedProperty (non-indexable)
  //    7 -> conversation.emails.nonExistentNestedProperty2 (non-indexable)
  //
  // SectionId assignment order:
  // - We assign section ids to known (existing) properties first in alphabet
  //  order.
  // - After handling all known properties, we assign section ids to all unknown
  //   (non-existent) properties that are specified in the
  //  indexable_nested_properties_list.
  // - As a result, assignment of the entire section set is not done
  //   alphabetically, but assignment is still deterministic and alphabetical
  //   order is preserved inside the known properties and unknown properties
  //   sets individually.
  EXPECT_THAT(schema_type_manager->section_manager().GetSectionMetadata(
                  /*schema_type_id=*/2, /*section_id=*/0),
              IsOkAndHolds(Pointee(EqualsSectionMetadata(
                  /*expected_id=*/0,
                  /*expected_property_path=*/"conversation.emails.attachment",
                  CreateAttachmentPropertyConfig()))));
  EXPECT_THAT(schema_type_manager->section_manager().GetSectionMetadata(
                  /*schema_type_id=*/2, /*section_id=*/1),
              IsOkAndHolds(Pointee(EqualsSectionMetadata(
                  /*expected_id=*/1,
                  /*expected_property_path=*/"conversation.emails.recipientIds",
                  CreateRecipientIdsPropertyConfig()))));
  EXPECT_THAT(schema_type_manager->section_manager().GetSectionMetadata(
                  /*schema_type_id=*/2, /*section_id=*/2),
              IsOkAndHolds(Pointee(EqualsSectionMetadata(
                  /*expected_id=*/2,
                  /*expected_property_path=*/"conversation.emails.recipients",
                  CreateRecipientsPropertyConfig()))));
  EXPECT_THAT(schema_type_manager->section_manager().GetSectionMetadata(
                  /*schema_type_id=*/2, /*section_id=*/3),
              IsOkAndHolds(Pointee(EqualsSectionMetadata(
                  /*expected_id=*/3,
                  /*expected_property_path=*/"conversation.emails.subject",
                  CreateSubjectPropertyConfig()))));
  EXPECT_THAT(
      schema_type_manager->section_manager().GetSectionMetadata(
          /*schema_type_id=*/2, /*section_id=*/4),
      IsOkAndHolds(Pointee(EqualsSectionMetadata(
          /*expected_id=*/4, /*expected_property_path=*/"conversation.name",
          CreateNamePropertyConfig()))));
  EXPECT_THAT(schema_type_manager->section_manager().GetSectionMetadata(
                  /*schema_type_id=*/2, /*section_id=*/5),
              IsOkAndHolds(Pointee(EqualsSectionMetadata(
                  /*expected_id=*/5, /*expected_property_path=*/"groupName",
                  CreateGroupNamePropertyConfig()))));
  EXPECT_THAT(schema_type_manager->section_manager().GetSectionMetadata(
                  /*schema_type_id=*/2, /*section_id=*/6),
              IsOkAndHolds(Pointee(EqualsSectionMetadata(
                  /*expected_id=*/6,
                  /*expected_property_path=*/
                  "conversation.emails.nonExistentNestedProperty",
                  PropertyConfigBuilder()
                      .SetName("nonExistentNestedProperty")
                      .SetDataType(TYPE_UNKNOWN)
                      .Build()))));
  EXPECT_THAT(schema_type_manager->section_manager().GetSectionMetadata(
                  /*schema_type_id=*/2, /*section_id=*/7),
              IsOkAndHolds(Pointee(EqualsSectionMetadata(
                  /*expected_id=*/7,
                  /*expected_property_path=*/
                  "conversation.emails.nonExistentNestedProperty2",
                  PropertyConfigBuilder()
                      .SetName("nonExistentNestedProperty2")
                      .SetDataType(TYPE_UNKNOWN)
                      .Build()))));
  // Check that no more properties are indexed
  EXPECT_THAT(schema_type_manager->section_manager().GetSectionMetadata(
                  /*schema_type_id=*/2, /*section_id=*/8),
              StatusIs(libtextclassifier3::StatusCode::INVALID_ARGUMENT));
}

TEST_F(SectionManagerTest, GetSectionMetadataInvalidSchemaTypeId) {
  // Use SchemaTypeManager factory method to instantiate SectionManager.
  ICING_ASSERT_OK_AND_ASSIGN(
      std::unique_ptr<SchemaTypeManager> schema_type_manager,
      SchemaTypeManager::Create(type_config_map_, schema_type_mapper_.get()));
  ASSERT_THAT(type_config_map_, SizeIs(3));

  EXPECT_THAT(schema_type_manager->section_manager().GetSectionMetadata(
                  /*schema_type_id=*/-1, /*section_id=*/0),
              StatusIs(libtextclassifier3::StatusCode::INVALID_ARGUMENT));
  EXPECT_THAT(schema_type_manager->section_manager().GetSectionMetadata(
                  /*schema_type_id=*/3, /*section_id=*/0),
              StatusIs(libtextclassifier3::StatusCode::INVALID_ARGUMENT));
}

TEST_F(SectionManagerTest, GetSectionMetadataInvalidSectionId) {
  // Use SchemaTypeManager factory method to instantiate SectionManager.
  ICING_ASSERT_OK_AND_ASSIGN(
      std::unique_ptr<SchemaTypeManager> schema_type_manager,
      SchemaTypeManager::Create(type_config_map_, schema_type_mapper_.get()));

  // Email (section id -> section property path):
  //   0 -> recipientIds
  //   1 -> recipients
  //   2 -> subject
  //   3 -> timestamp
  EXPECT_THAT(schema_type_manager->section_manager().GetSectionMetadata(
                  /*schema_type_id=*/0, /*section_id=*/-1),
              StatusIs(libtextclassifier3::StatusCode::INVALID_ARGUMENT));
  EXPECT_THAT(schema_type_manager->section_manager().GetSectionMetadata(
                  /*schema_type_id=*/0, /*section_id=*/4),
              StatusIs(libtextclassifier3::StatusCode::INVALID_ARGUMENT));

  // Conversation (section id -> section property path):
  //   0 -> emails.recipientIds
  //   1 -> emails.recipients
  //   2 -> emails.subject
  //   3 -> emails.timestamp
  //   4 -> name
  EXPECT_THAT(schema_type_manager->section_manager().GetSectionMetadata(
                  /*schema_type_id=*/1, /*section_id=*/-1),
              StatusIs(libtextclassifier3::StatusCode::INVALID_ARGUMENT));
  EXPECT_THAT(schema_type_manager->section_manager().GetSectionMetadata(
                  /*schema_type_id=*/1, /*section_id=*/5),
              StatusIs(libtextclassifier3::StatusCode::INVALID_ARGUMENT));
}

TEST_F(SectionManagerTest,
       NonStringFieldsWithStringIndexingConfigDontCreateSections) {
  // Create a schema for an empty document.
  SchemaTypeConfigProto empty_type;
  empty_type.set_schema_type("EmptySchema");

  // Create a schema with all the non-string fields
  SchemaTypeConfigProto type_with_non_string_properties;
  type_with_non_string_properties.set_schema_type("Schema");

  // Create an int property with a string_indexing_config
  auto int_property = type_with_non_string_properties.add_properties();
  int_property->set_property_name("int");
  int_property->set_data_type(TYPE_INT64);
  int_property->set_cardinality(CARDINALITY_REQUIRED);
  int_property->mutable_string_indexing_config()->set_term_match_type(
      TERM_MATCH_EXACT);
  int_property->mutable_string_indexing_config()->set_tokenizer_type(
      TOKENIZER_PLAIN);

  // Create a double property with a string_indexing_config
  auto double_property = type_with_non_string_properties.add_properties();
  double_property->set_property_name("double");
  double_property->set_data_type(TYPE_DOUBLE);
  double_property->set_cardinality(CARDINALITY_REQUIRED);
  double_property->mutable_string_indexing_config()->set_term_match_type(
      TERM_MATCH_EXACT);
  double_property->mutable_string_indexing_config()->set_tokenizer_type(
      TOKENIZER_PLAIN);

  // Create a boolean property with a string_indexing_config
  auto boolean_property = type_with_non_string_properties.add_properties();
  boolean_property->set_property_name("boolean");
  boolean_property->set_data_type(TYPE_BOOLEAN);
  boolean_property->set_cardinality(CARDINALITY_REQUIRED);
  boolean_property->mutable_string_indexing_config()->set_term_match_type(
      TERM_MATCH_EXACT);
  boolean_property->mutable_string_indexing_config()->set_tokenizer_type(
      TOKENIZER_PLAIN);

  // Create a bytes property with a string_indexing_config
  auto bytes_property = type_with_non_string_properties.add_properties();
  bytes_property->set_property_name("bytes");
  bytes_property->set_data_type(TYPE_BYTES);
  bytes_property->set_cardinality(CARDINALITY_REQUIRED);
  bytes_property->mutable_string_indexing_config()->set_term_match_type(
      TERM_MATCH_EXACT);
  bytes_property->mutable_string_indexing_config()->set_tokenizer_type(
      TOKENIZER_PLAIN);

  // Create a document property with a string_indexing_config
  auto document_property = type_with_non_string_properties.add_properties();
  document_property->set_property_name("document");
  document_property->set_data_type(TYPE_DOCUMENT);
  document_property->set_schema_type(empty_type.schema_type());
  document_property->set_cardinality(CARDINALITY_REQUIRED);
  document_property->mutable_string_indexing_config()->set_term_match_type(
      TERM_MATCH_EXACT);
  document_property->mutable_string_indexing_config()->set_tokenizer_type(
      TOKENIZER_PLAIN);

  // Setup classes to create the section manager
  SchemaUtil::TypeConfigMap type_config_map;
  type_config_map.emplace(type_with_non_string_properties.schema_type(),
                          type_with_non_string_properties);
  type_config_map.emplace(empty_type.schema_type(), empty_type);

  // DynamicTrieKeyMapper uses 3 internal arrays for bookkeeping. Give each one
  // 128KiB so the total DynamicTrieKeyMapper should get 384KiB
  int key_mapper_size = 3 * 128 * 1024;
  std::string dir = GetTestTempDir() + "/non_string_fields";
  ICING_ASSERT_OK_AND_ASSIGN(
      std::unique_ptr<KeyMapper<SchemaTypeId>> schema_type_mapper,
      DynamicTrieKeyMapper<SchemaTypeId>::Create(filesystem_, dir,
                                                 key_mapper_size));
  ICING_ASSERT_OK(schema_type_mapper->Put(
      type_with_non_string_properties.schema_type(), /*schema_type_id=*/0));
  ICING_ASSERT_OK(schema_type_mapper->Put(empty_type.schema_type(),
                                          /*schema_type_id=*/1));

  // Use SchemaTypeManager factory method to instantiate SectionManager.
  ICING_ASSERT_OK_AND_ASSIGN(
      std::unique_ptr<SchemaTypeManager> schema_type_manager,
      SchemaTypeManager::Create(type_config_map, schema_type_mapper.get()));

  // Create an empty document to be nested
  DocumentProto empty_document = DocumentBuilder()
                                     .SetKey("icing", "uri1")
                                     .SetSchema(empty_type.schema_type())
                                     .Build();

  // Create a document that follows "Schema"
  DocumentProto document =
      DocumentBuilder()
          .SetKey("icing", "uri2")
          .SetSchema(type_with_non_string_properties.schema_type())
          .AddInt64Property("int", 1)
          .AddDoubleProperty("double", 0.2)
          .AddBooleanProperty("boolean", true)
          .AddBytesProperty("bytes", "attachment bytes")
          .AddDocumentProperty("document", empty_document)
          .Build();

  // Extracts sections from 'Schema' document
  ICING_ASSERT_OK_AND_ASSIGN(
      SectionGroup section_group,
      schema_type_manager->section_manager().ExtractSections(document));
  EXPECT_THAT(section_group.string_sections, IsEmpty());
  EXPECT_THAT(section_group.integer_sections, IsEmpty());
}

TEST_F(SectionManagerTest,
       NonIntegerFieldsWithIntegerIndexingConfigDontCreateSections) {
  // Create a schema for an empty document.
  SchemaTypeConfigProto empty_type;
  empty_type.set_schema_type("EmptySchema");

  // Create a schema with all the non-integer fields
  SchemaTypeConfigProto type_with_non_integer_properties;
  type_with_non_integer_properties.set_schema_type("Schema");

  // Create an string property with a integer_indexing_config
  auto string_property = type_with_non_integer_properties.add_properties();
  string_property->set_property_name("string");
  string_property->set_data_type(TYPE_STRING);
  string_property->set_cardinality(CARDINALITY_REQUIRED);
  string_property->mutable_integer_indexing_config()->set_numeric_match_type(
      NUMERIC_MATCH_RANGE);

  // Create a double property with a integer_indexing_config
  auto double_property = type_with_non_integer_properties.add_properties();
  double_property->set_property_name("double");
  double_property->set_data_type(TYPE_DOUBLE);
  double_property->set_cardinality(CARDINALITY_REQUIRED);
  double_property->mutable_integer_indexing_config()->set_numeric_match_type(
      NUMERIC_MATCH_RANGE);

  // Create a boolean property with a integer_indexing_config
  auto boolean_property = type_with_non_integer_properties.add_properties();
  boolean_property->set_property_name("boolean");
  boolean_property->set_data_type(TYPE_BOOLEAN);
  boolean_property->set_cardinality(CARDINALITY_REQUIRED);
  boolean_property->mutable_integer_indexing_config()->set_numeric_match_type(
      NUMERIC_MATCH_RANGE);

  // Create a bytes property with a integer_indexing_config
  auto bytes_property = type_with_non_integer_properties.add_properties();
  bytes_property->set_property_name("bytes");
  bytes_property->set_data_type(TYPE_BYTES);
  bytes_property->set_cardinality(CARDINALITY_REQUIRED);
  bytes_property->mutable_integer_indexing_config()->set_numeric_match_type(
      NUMERIC_MATCH_RANGE);

  // Create a document property with a integer_indexing_config
  auto document_property = type_with_non_integer_properties.add_properties();
  document_property->set_property_name("document");
  document_property->set_data_type(TYPE_DOCUMENT);
  document_property->set_schema_type(empty_type.schema_type());
  document_property->set_cardinality(CARDINALITY_REQUIRED);
  document_property->mutable_integer_indexing_config()->set_numeric_match_type(
      NUMERIC_MATCH_RANGE);

  // Setup classes to create the section manager
  SchemaUtil::TypeConfigMap type_config_map;
  type_config_map.emplace(type_with_non_integer_properties.schema_type(),
                          type_with_non_integer_properties);
  type_config_map.emplace(empty_type.schema_type(), empty_type);

  // DynamicTrieKeyMapper uses 3 internal arrays for bookkeeping. Give each one
  // 128KiB so the total DynamicTrieKeyMapper should get 384KiB
  int key_mapper_size = 3 * 128 * 1024;
  std::string dir = GetTestTempDir() + "/non_integer_fields";
  ICING_ASSERT_OK_AND_ASSIGN(
      std::unique_ptr<KeyMapper<SchemaTypeId>> schema_type_mapper,
      DynamicTrieKeyMapper<SchemaTypeId>::Create(filesystem_, dir,
                                                 key_mapper_size));
  ICING_ASSERT_OK(schema_type_mapper->Put(
      type_with_non_integer_properties.schema_type(), /*schema_type_id=*/0));
  ICING_ASSERT_OK(schema_type_mapper->Put(empty_type.schema_type(),
                                          /*schema_type_id=*/1));

  // Use SchemaTypeManager factory method to instantiate SectionManager.
  ICING_ASSERT_OK_AND_ASSIGN(
      std::unique_ptr<SchemaTypeManager> schema_type_manager,
      SchemaTypeManager::Create(type_config_map, schema_type_mapper.get()));

  // Create an empty document to be nested
  DocumentProto empty_document = DocumentBuilder()
                                     .SetKey("icing", "uri1")
                                     .SetSchema(empty_type.schema_type())
                                     .Build();

  // Create a document that follows "Schema"
  DocumentProto document =
      DocumentBuilder()
          .SetKey("icing", "uri2")
          .SetSchema(type_with_non_integer_properties.schema_type())
          .AddStringProperty("string", "abc")
          .AddDoubleProperty("double", 0.2)
          .AddBooleanProperty("boolean", true)
          .AddBytesProperty("bytes", "attachment bytes")
          .AddDocumentProperty("document", empty_document)
          .Build();

  // Extracts sections from 'Schema' document
  ICING_ASSERT_OK_AND_ASSIGN(
      SectionGroup section_group,
      schema_type_manager->section_manager().ExtractSections(document));
  EXPECT_THAT(section_group.string_sections, IsEmpty());
  EXPECT_THAT(section_group.integer_sections, IsEmpty());
}

TEST_F(SectionManagerTest, AssignSectionsRecursivelyForDocumentFields) {
  // Create the inner schema that the document property is.
  SchemaTypeConfigProto document_type;
  document_type.set_schema_type("DocumentSchema");

  auto string_property = document_type.add_properties();
  string_property->set_property_name("string");
  string_property->set_data_type(TYPE_STRING);
  string_property->set_cardinality(CARDINALITY_REQUIRED);
  string_property->mutable_string_indexing_config()->set_term_match_type(
      TERM_MATCH_EXACT);
  string_property->mutable_string_indexing_config()->set_tokenizer_type(
      TOKENIZER_PLAIN);

  auto integer_property = document_type.add_properties();
  integer_property->set_property_name("integer");
  integer_property->set_data_type(TYPE_INT64);
  integer_property->set_cardinality(CARDINALITY_REQUIRED);
  integer_property->mutable_integer_indexing_config()->set_numeric_match_type(
      NUMERIC_MATCH_RANGE);

  // Create the outer schema which has the document property.
  SchemaTypeConfigProto type;
  type.set_schema_type("Schema");

  auto document_property = type.add_properties();
  document_property->set_property_name("document");
  document_property->set_data_type(TYPE_DOCUMENT);
  document_property->set_schema_type(document_type.schema_type());
  document_property->set_cardinality(CARDINALITY_REQUIRED);

  // Opt into recursing into the document fields.
  document_property->mutable_document_indexing_config()
      ->set_index_nested_properties(true);

  // Create the inner document.
  DocumentProto inner_document = DocumentBuilder()
                                     .SetKey("icing", "uri1")
                                     .SetSchema(document_type.schema_type())
                                     .AddStringProperty("string", "foo")
                                     .AddInt64Property("integer", 123)
                                     .Build();

  // Create the outer document that holds the inner document
  DocumentProto outer_document =
      DocumentBuilder()
          .SetKey("icing", "uri2")
          .SetSchema(type.schema_type())
          .AddDocumentProperty("document", inner_document)
          .Build();

  // Setup classes to create the section manager
  SchemaUtil::TypeConfigMap type_config_map;
  type_config_map.emplace(type.schema_type(), type);
  type_config_map.emplace(document_type.schema_type(), document_type);

  // DynamicTrieKeyMapper uses 3 internal arrays for bookkeeping. Give each one
  // 128KiB so the total DynamicTrieKeyMapper should get 384KiB
  int key_mapper_size = 3 * 128 * 1024;
  std::string dir = GetTestTempDir() + "/recurse_into_document";
  ICING_ASSERT_OK_AND_ASSIGN(
      std::unique_ptr<KeyMapper<SchemaTypeId>> schema_type_mapper,
      DynamicTrieKeyMapper<SchemaTypeId>::Create(filesystem_, dir,
                                                 key_mapper_size));
  int type_schema_type_id = 0;
  int document_type_schema_type_id = 1;
  ICING_ASSERT_OK(
      schema_type_mapper->Put(type.schema_type(), type_schema_type_id));
  ICING_ASSERT_OK(schema_type_mapper->Put(document_type.schema_type(),
                                          document_type_schema_type_id));

  // Use SchemaTypeManager factory method to instantiate SectionManager.
  ICING_ASSERT_OK_AND_ASSIGN(
      std::unique_ptr<SchemaTypeManager> schema_type_manager,
      SchemaTypeManager::Create(type_config_map, schema_type_mapper.get()));

  // Extracts sections from 'Schema' document; there should be the 1 string
  // property and 1 integer property inside the document.
  ICING_ASSERT_OK_AND_ASSIGN(
      SectionGroup section_group,
      schema_type_manager->section_manager().ExtractSections(outer_document));
  EXPECT_THAT(section_group.string_sections, SizeIs(1));
  EXPECT_THAT(section_group.integer_sections, SizeIs(1));
}

TEST_F(SectionManagerTest, DontAssignSectionsRecursivelyForDocumentFields) {
  // Create the inner schema that the document property is.
  SchemaTypeConfigProto document_type;
  document_type.set_schema_type("DocumentSchema");

  auto string_property = document_type.add_properties();
  string_property->set_property_name("string");
  string_property->set_data_type(TYPE_STRING);
  string_property->set_cardinality(CARDINALITY_REQUIRED);
  string_property->mutable_string_indexing_config()->set_term_match_type(
      TERM_MATCH_EXACT);
  string_property->mutable_string_indexing_config()->set_tokenizer_type(
      TOKENIZER_PLAIN);

  auto integer_property = document_type.add_properties();
  integer_property->set_property_name("integer");
  integer_property->set_data_type(TYPE_INT64);
  integer_property->set_cardinality(CARDINALITY_REQUIRED);
  integer_property->mutable_integer_indexing_config()->set_numeric_match_type(
      NUMERIC_MATCH_RANGE);

  // Create the outer schema which has the document property.
  SchemaTypeConfigProto type;
  type.set_schema_type("Schema");

  auto document_property = type.add_properties();
  document_property->set_property_name("document");
  document_property->set_data_type(TYPE_DOCUMENT);
  document_property->set_schema_type(document_type.schema_type());
  document_property->set_cardinality(CARDINALITY_REQUIRED);

  // Opt into recursing into the document fields.
  document_property->mutable_document_indexing_config()
      ->set_index_nested_properties(false);

  // Create the inner document.
  DocumentProto inner_document = DocumentBuilder()
                                     .SetKey("icing", "uri1")
                                     .SetSchema(document_type.schema_type())
                                     .AddStringProperty("string", "foo")
                                     .AddInt64Property("integer", 123)
                                     .Build();

  // Create the outer document that holds the inner document
  DocumentProto outer_document =
      DocumentBuilder()
          .SetKey("icing", "uri2")
          .SetSchema(type.schema_type())
          .AddDocumentProperty("document", inner_document)
          .Build();

  // Setup classes to create the section manager
  SchemaUtil::TypeConfigMap type_config_map;
  type_config_map.emplace(type.schema_type(), type);
  type_config_map.emplace(document_type.schema_type(), document_type);

  // DynamicTrieKeyMapper uses 3 internal arrays for bookkeeping. Give each one
  // 128KiB so the total DynamicTrieKeyMapper should get 384KiB
  int key_mapper_size = 3 * 128 * 1024;
  std::string dir = GetTestTempDir() + "/recurse_into_document";
  ICING_ASSERT_OK_AND_ASSIGN(
      std::unique_ptr<KeyMapper<SchemaTypeId>> schema_type_mapper,
      DynamicTrieKeyMapper<SchemaTypeId>::Create(filesystem_, dir,
                                                 key_mapper_size));
  int type_schema_type_id = 0;
  int document_type_schema_type_id = 1;
  ICING_ASSERT_OK(
      schema_type_mapper->Put(type.schema_type(), type_schema_type_id));
  ICING_ASSERT_OK(schema_type_mapper->Put(document_type.schema_type(),
                                          document_type_schema_type_id));

  // Use SchemaTypeManager factory method to instantiate SectionManager.
  ICING_ASSERT_OK_AND_ASSIGN(
      std::unique_ptr<SchemaTypeManager> schema_type_manager,
      SchemaTypeManager::Create(type_config_map, schema_type_mapper.get()));

  // Extracts sections from 'Schema' document; there won't be any since we
  // didn't recurse into the document to see the inner string property
  ICING_ASSERT_OK_AND_ASSIGN(
      SectionGroup section_group,
      schema_type_manager->section_manager().ExtractSections(outer_document));
  EXPECT_THAT(section_group.string_sections, IsEmpty());
  EXPECT_THAT(section_group.integer_sections, IsEmpty());
}

}  // namespace

}  // namespace lib
}  // namespace icing