Coverage Report

Created: 2026-08-18 15:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/index/analyzer_key_matcher.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include <string>
21
#include <string_view>
22
#include <unordered_map>
23
#include <vector>
24
25
#include "storage/index/inverted/inverted_index_parser.h"
26
#include "storage/index/inverted/inverted_index_reader.h"
27
28
namespace doris::segment_v2 {
29
30
struct ReaderEntry {
31
    InvertedIndexReaderType type;
32
    std::string analyzer_key;
33
    InvertedIndexReaderPtr reader;
34
};
35
36
// Result of analyzer key matching operation.
37
// Contains candidate readers that match the requested analyzer key.
38
struct AnalyzerMatchResult {
39
    // Pointers to matching reader entries. Valid only within the scope of
40
    // the InvertedIndexIterator that owns the entries.
41
    std::vector<const ReaderEntry*> candidates;
42
43
    // True if fallback strategy was used (no exact match found)
44
    bool used_fallback = false;
45
46
    // Convenience methods
47
10
    bool empty() const { return candidates.empty(); }
48
7
    size_t size() const { return candidates.size(); }
49
};
50
51
// Utility class for matching analyzer keys against reader entries.
52
// Stateless - all methods are static.
53
//
54
// Matching strategy:
55
// 1. If key is empty (user did not specify), return all readers for query-type-based selection
56
// 2. If key is non-empty (user specified), try exact match
57
// 3. If explicit key with no match, return empty (caller decides whether to bypass)
58
class AnalyzerKeyMatcher {
59
public:
60
    // Match analyzer key against reader entries.
61
    // @param analyzer_key: Normalized analyzer key (lowercase, or empty for auto-select)
62
    // @param entries: Available reader entries
63
    // @param key_index: Index mapping analyzer_key -> entry indices
64
    // @return MatchResult with candidates and fallback flag
65
    static AnalyzerMatchResult match(
66
            std::string_view analyzer_key, const std::vector<ReaderEntry>& entries,
67
            const std::unordered_map<std::string, std::vector<size_t>>& key_index);
68
69
    // Check if analyzer key is explicitly specified by user.
70
    // Empty string means "user did not specify" (auto-select mode).
71
    // Non-empty means "user wrote USING ANALYZER xxx".
72
6
    static bool is_explicit(std::string_view key) { return !key.empty(); }
73
74
    // Check if fallback (returning all readers) is allowed for this key.
75
    // Only empty key (user did not specify) allows fallback.
76
15
    static bool allows_fallback(std::string_view key) { return key.empty(); }
77
};
78
79
} // namespace doris::segment_v2