1 // Copyright (C) 2023 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef ICING_SCHEMA_SCHEMA_TYPE_MANAGER_H_ 16 #define ICING_SCHEMA_SCHEMA_TYPE_MANAGER_H_ 17 18 #include <memory> 19 #include <string> 20 #include <unordered_set> 21 #include <vector> 22 23 #include "icing/text_classifier/lib3/utils/base/statusor.h" 24 #include "icing/schema/joinable-property-manager.h" 25 #include "icing/schema/schema-util.h" 26 #include "icing/schema/section-manager.h" 27 #include "icing/store/document-filter-data.h" 28 #include "icing/store/key-mapper.h" 29 30 namespace icing { 31 namespace lib { 32 33 // This class is a wrapper of SectionManager and JoinablePropertyManager. 34 class SchemaTypeManager { 35 public: 36 // Schema type ids are continuous, and so we use a vector instead of an 37 // unordered map for the mappings. 38 using SchemaTypeIdToPropertiesVector = 39 std::vector<std::unordered_set<std::string>>; 40 // Factory function to create a SchemaTypeManager which does not take 41 // ownership of any input components, and all pointers must refer to valid 42 // objects that outlive the created SchemaTypeManager instance. 43 // 44 // Returns: 45 // - A SchemaTypeManager on success 46 // - FAILED_PRECONDITION_ERROR on any null pointer input 47 // - OUT_OF_RANGE_ERROR if # of indexable properties in a single Schema 48 // exceeds the threshold (kTotalNumSections, kTotalNumJoinableProperties) 49 // - INVALID_ARGUMENT_ERROR if type_config_map contains incorrect 50 // information that causes errors (e.g. invalid schema type id, cycle 51 // dependency in nested schema) 52 // - NOT_FOUND_ERROR if any nested schema name is not found in 53 // type_config_map 54 static libtextclassifier3::StatusOr<std::unique_ptr<SchemaTypeManager>> 55 Create(const SchemaUtil::TypeConfigMap& type_config_map, 56 const KeyMapper<SchemaTypeId>* schema_type_mapper); 57 section_manager()58 const SectionManager& section_manager() const { return *section_manager_; } 59 joinable_property_manager()60 const JoinablePropertyManager& joinable_property_manager() const { 61 return *joinable_property_manager_; 62 } 63 64 private: SchemaTypeManager(std::unique_ptr<SectionManager> section_manager,std::unique_ptr<JoinablePropertyManager> joinable_property_manager)65 explicit SchemaTypeManager( 66 std::unique_ptr<SectionManager> section_manager, 67 std::unique_ptr<JoinablePropertyManager> joinable_property_manager) 68 : section_manager_(std::move(section_manager)), 69 joinable_property_manager_(std::move(joinable_property_manager)) {} 70 71 std::unique_ptr<SectionManager> section_manager_; 72 73 std::unique_ptr<JoinablePropertyManager> joinable_property_manager_; 74 }; 75 76 } // namespace lib 77 } // namespace icing 78 79 #endif // ICING_SCHEMA_SCHEMA_TYPE_MANAGER_H_ 80