// Copyright (C) 2019-2020 Zilliz. All rights reserved. // // 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 "utils/Json.h" #include "query/PlanImpl.h" #include "segcore/SegmentGrowing.h" #include #include "query/generated/ExecPlanNodeVisitor.h" #include "segcore/SegmentGrowingImpl.h" #include "query/generated/ExecExprVisitor.h" #include "query/SearchOnGrowing.h" #include "query/SearchOnSealed.h" namespace milvus::query { #if 1 namespace impl { // THIS CONTAINS EXTRA BODY FOR VISITOR // WILL BE USED BY GENERATOR UNDER suvlim/core_gen/ class ExecPlanNodeVisitor : PlanNodeVisitor { public: using RetType = QueryResult; ExecPlanNodeVisitor(const segcore::SegmentInterface& segment, Timestamp timestamp, const PlaceholderGroup& placeholder_group) : segment_(segment), timestamp_(timestamp), placeholder_group_(placeholder_group) { } // using RetType = nlohmann::json; RetType get_moved_result(PlanNode& node) { assert(!ret_.has_value()); node.accept(*this); assert(ret_.has_value()); auto ret = std::move(ret_).value(); ret_ = std::nullopt; return ret; } private: template void VectorVisitorImpl(VectorPlanNode& node); private: // std::optional ret_; const segcore::SegmentInterface& segment_; Timestamp timestamp_; const PlaceholderGroup& placeholder_group_; std::optional ret_; }; } // namespace impl #endif template void ExecPlanNodeVisitor::VectorVisitorImpl(VectorPlanNode& node) { // TODO: optimize here, remove the dynamic cast assert(!ret_.has_value()); auto segment = dynamic_cast(&segment_); AssertInfo(segment, "support SegmentSmallIndex Only"); RetType ret; auto& ph = placeholder_group_.at(0); auto src_data = ph.get_blob>(); auto num_queries = ph.num_of_queries_; aligned_vector bitset_holder; BitsetView view; // TODO: add API to unify row_count auto row_count = segment->get_row_count(); if (node.predicate_.has_value()) { ExecExprVisitor::RetType expr_ret = ExecExprVisitor(*segment, row_count).call_child(*node.predicate_.value()); bitset_holder = AssembleNegBitset(expr_ret); view = BitsetView(bitset_holder.data(), bitset_holder.size() * 8); } segment->vector_search(row_count, node.query_info_, src_data, num_queries, view, ret); ret_ = ret; } void ExecPlanNodeVisitor::visit(FloatVectorANNS& node) { VectorVisitorImpl(node); } void ExecPlanNodeVisitor::visit(BinaryVectorANNS& node) { VectorVisitorImpl(node); } } // namespace milvus::query