ExecPlanNodeVisitor.cpp 3.2 KB
Newer Older
F
FluorineDog 已提交
1 2 3 4 5 6 7 8 9 10 11
// 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

12
#include "utils/Json.h"
13
#include "query/PlanImpl.h"
14
#include "segcore/SegmentGrowing.h"
F
FluorineDog 已提交
15
#include <utility>
16
#include "query/generated/ExecPlanNodeVisitor.h"
17
#include "segcore/SegmentGrowingImpl.h"
18
#include "query/generated/ExecExprVisitor.h"
19
#include "query/SearchOnGrowing.h"
20
#include "query/SearchOnSealed.h"
21 22

namespace milvus::query {
23 24 25 26 27 28 29

#if 1
namespace impl {
// THIS CONTAINS EXTRA BODY FOR VISITOR
// WILL BE USED BY GENERATOR UNDER suvlim/core_gen/
class ExecPlanNodeVisitor : PlanNodeVisitor {
 public:
X
XuanYang-cn 已提交
30
    using RetType = QueryResult;
F
FluorineDog 已提交
31
    ExecPlanNodeVisitor(const segcore::SegmentInterface& segment,
32 33
                        Timestamp timestamp,
                        const PlaceholderGroup& placeholder_group)
34
        : segment_(segment), timestamp_(timestamp), placeholder_group_(placeholder_group) {
35 36 37
    }
    // using RetType = nlohmann::json;

38 39
    RetType
    get_moved_result(PlanNode& node) {
40 41 42 43 44 45 46
        assert(!ret_.has_value());
        node.accept(*this);
        assert(ret_.has_value());
        auto ret = std::move(ret_).value();
        ret_ = std::nullopt;
        return ret;
    }
47

48 49 50 51 52
 private:
    template <typename VectorType>
    void
    VectorVisitorImpl(VectorPlanNode& node);

53 54
 private:
    // std::optional<RetType> ret_;
F
FluorineDog 已提交
55
    const segcore::SegmentInterface& segment_;
56
    Timestamp timestamp_;
57
    const PlaceholderGroup& placeholder_group_;
58 59 60 61 62 63

    std::optional<RetType> ret_;
};
}  // namespace impl
#endif

64
template <typename VectorType>
65
void
66
ExecPlanNodeVisitor::VectorVisitorImpl(VectorPlanNode& node) {
67 68
    // TODO: optimize here, remove the dynamic cast
    assert(!ret_.has_value());
F
FluorineDog 已提交
69
    auto segment = dynamic_cast<const segcore::SegmentInternalInterface*>(&segment_);
70 71
    AssertInfo(segment, "support SegmentSmallIndex Only");
    RetType ret;
X
xige-16 已提交
72
    auto& ph = placeholder_group_.at(0);
73
    auto src_data = ph.get_blob<EmbeddedType<VectorType>>();
X
xige-16 已提交
74
    auto num_queries = ph.num_of_queries_;
75

76 77
    aligned_vector<uint8_t> bitset_holder;
    BitsetView view;
78
    // TODO: add API to unify row_count
F
FluorineDog 已提交
79
    auto row_count = segment->get_row_count();
80

81
    if (node.predicate_.has_value()) {
82
        ExecExprVisitor::RetType expr_ret = ExecExprVisitor(*segment, row_count).call_child(*node.predicate_.value());
83
        bitset_holder = AssembleNegBitset(expr_ret);
84
        view = BitsetView(bitset_holder.data(), bitset_holder.size() * 8);
85 86
    }

F
FluorineDog 已提交
87
    segment->vector_search(row_count, node.query_info_, src_data, num_queries, view, ret);
88

89
    ret_ = ret;
90 91
}

92
void
93 94 95
ExecPlanNodeVisitor::visit(FloatVectorANNS& node) {
    VectorVisitorImpl<FloatVector>(node);
}
Y
yukun 已提交
96

97 98 99
void
ExecPlanNodeVisitor::visit(BinaryVectorANNS& node) {
    VectorVisitorImpl<BinaryVector>(node);
100 101 102
}

}  // namespace milvus::query