1*8b6cd535SAndroid Build Coastguard Worker // Copyright (C) 2023 Google LLC 2*8b6cd535SAndroid Build Coastguard Worker // 3*8b6cd535SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); 4*8b6cd535SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License. 5*8b6cd535SAndroid Build Coastguard Worker // You may obtain a copy of the License at 6*8b6cd535SAndroid Build Coastguard Worker // 7*8b6cd535SAndroid Build Coastguard Worker // http://www.apache.org/licenses/LICENSE-2.0 8*8b6cd535SAndroid Build Coastguard Worker // 9*8b6cd535SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software 10*8b6cd535SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, 11*8b6cd535SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*8b6cd535SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and 13*8b6cd535SAndroid Build Coastguard Worker // limitations under the License. 14*8b6cd535SAndroid Build Coastguard Worker 15*8b6cd535SAndroid Build Coastguard Worker #ifndef ICING_JOIN_JOIN_CHILDREN_FETCHER_IMPL_DEPRECATED_H_ 16*8b6cd535SAndroid Build Coastguard Worker #define ICING_JOIN_JOIN_CHILDREN_FETCHER_IMPL_DEPRECATED_H_ 17*8b6cd535SAndroid Build Coastguard Worker 18*8b6cd535SAndroid Build Coastguard Worker #include <memory> 19*8b6cd535SAndroid Build Coastguard Worker #include <unordered_map> 20*8b6cd535SAndroid Build Coastguard Worker #include <utility> 21*8b6cd535SAndroid Build Coastguard Worker #include <vector> 22*8b6cd535SAndroid Build Coastguard Worker 23*8b6cd535SAndroid Build Coastguard Worker #include "icing/text_classifier/lib3/utils/base/statusor.h" 24*8b6cd535SAndroid Build Coastguard Worker #include "icing/join/join-children-fetcher.h" 25*8b6cd535SAndroid Build Coastguard Worker #include "icing/proto/search.pb.h" 26*8b6cd535SAndroid Build Coastguard Worker #include "icing/scoring/scored-document-hit.h" 27*8b6cd535SAndroid Build Coastguard Worker #include "icing/store/document-id.h" 28*8b6cd535SAndroid Build Coastguard Worker 29*8b6cd535SAndroid Build Coastguard Worker namespace icing { 30*8b6cd535SAndroid Build Coastguard Worker namespace lib { 31*8b6cd535SAndroid Build Coastguard Worker 32*8b6cd535SAndroid Build Coastguard Worker // A class that provides the GetChildren method for joins to fetch all children 33*8b6cd535SAndroid Build Coastguard Worker // documents given a parent document id. Only QualifiedIdJoinIndexImplV1 and 34*8b6cd535SAndroid Build Coastguard Worker // QualifiedIdJoinIndexImplV2 will use this class, since we can construct the 35*8b6cd535SAndroid Build Coastguard Worker // map without parent document id available. 36*8b6cd535SAndroid Build Coastguard Worker // 37*8b6cd535SAndroid Build Coastguard Worker // Internally, the class maintains a map for each joinable value type that 38*8b6cd535SAndroid Build Coastguard Worker // groups children according to the joinable values. Currently we only support 39*8b6cd535SAndroid Build Coastguard Worker // QUALIFIED_ID joining, in which the joinable value type is document id. 40*8b6cd535SAndroid Build Coastguard Worker class JoinChildrenFetcherImplDeprecated : public JoinChildrenFetcher { 41*8b6cd535SAndroid Build Coastguard Worker public: 42*8b6cd535SAndroid Build Coastguard Worker // Creates JoinChildrenFetcherImplDeprecated. 43*8b6cd535SAndroid Build Coastguard Worker // 44*8b6cd535SAndroid Build Coastguard Worker // Returns: 45*8b6cd535SAndroid Build Coastguard Worker // - A JoinChildrenFetcherImplDeprecated instance on success. 46*8b6cd535SAndroid Build Coastguard Worker // - UNIMPLEMENTED_ERROR if the join type specified by join_spec is not 47*8b6cd535SAndroid Build Coastguard Worker // supported. 48*8b6cd535SAndroid Build Coastguard Worker static libtextclassifier3::StatusOr< 49*8b6cd535SAndroid Build Coastguard Worker std::unique_ptr<JoinChildrenFetcherImplDeprecated>> 50*8b6cd535SAndroid Build Coastguard Worker Create(const JoinSpecProto& join_spec, 51*8b6cd535SAndroid Build Coastguard Worker std::unordered_map<DocumentId, std::vector<ScoredDocumentHit>>&& 52*8b6cd535SAndroid Build Coastguard Worker map_joinable_qualified_id); 53*8b6cd535SAndroid Build Coastguard Worker 54*8b6cd535SAndroid Build Coastguard Worker ~JoinChildrenFetcherImplDeprecated() override = default; 55*8b6cd535SAndroid Build Coastguard Worker 56*8b6cd535SAndroid Build Coastguard Worker libtextclassifier3::StatusOr<std::vector<ScoredDocumentHit>> GetChildren( 57*8b6cd535SAndroid Build Coastguard Worker DocumentId parent_doc_id) const override; 58*8b6cd535SAndroid Build Coastguard Worker 59*8b6cd535SAndroid Build Coastguard Worker private: JoinChildrenFetcherImplDeprecated(const JoinSpecProto & join_spec,std::unordered_map<DocumentId,std::vector<ScoredDocumentHit>> && map_joinable_qualified_id)60*8b6cd535SAndroid Build Coastguard Worker explicit JoinChildrenFetcherImplDeprecated( 61*8b6cd535SAndroid Build Coastguard Worker const JoinSpecProto& join_spec, 62*8b6cd535SAndroid Build Coastguard Worker std::unordered_map<DocumentId, std::vector<ScoredDocumentHit>>&& 63*8b6cd535SAndroid Build Coastguard Worker map_joinable_qualified_id) 64*8b6cd535SAndroid Build Coastguard Worker : JoinChildrenFetcher(join_spec), 65*8b6cd535SAndroid Build Coastguard Worker map_joinable_qualified_id_(std::move(map_joinable_qualified_id)) {} 66*8b6cd535SAndroid Build Coastguard Worker 67*8b6cd535SAndroid Build Coastguard Worker // The map that groups children by qualified id used to support QualifiedId 68*8b6cd535SAndroid Build Coastguard Worker // joining. The joining type is document id. 69*8b6cd535SAndroid Build Coastguard Worker std::unordered_map<DocumentId, std::vector<ScoredDocumentHit>> 70*8b6cd535SAndroid Build Coastguard Worker map_joinable_qualified_id_; 71*8b6cd535SAndroid Build Coastguard Worker }; 72*8b6cd535SAndroid Build Coastguard Worker 73*8b6cd535SAndroid Build Coastguard Worker } // namespace lib 74*8b6cd535SAndroid Build Coastguard Worker } // namespace icing 75*8b6cd535SAndroid Build Coastguard Worker 76*8b6cd535SAndroid Build Coastguard Worker #endif // ICING_JOIN_JOIN_CHILDREN_FETCHER_IMPL_DEPRECATED_H_ 77