Coverage Report

Created: 2026-03-14 20:54

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
27
namespace doris::segment_v2 {
28
29
// Forward declaration
30
struct ReaderEntry;
31
32
// Result of analyzer key matching operation.
33
// Contains candidate readers that match the requested analyzer key.
34
struct AnalyzerMatchResult {
35
    // Pointers to matching reader entries. Valid only within the scope of
36
    // the InvertedIndexIterator that owns the entries.
37
    std::vector<const ReaderEntry*> candidates;
38
39
    // True if fallback strategy was used (no exact match found)
40
    bool used_fallback = false;
41
42
    // Convenience methods
43
22
    bool empty() const { return candidates.empty(); }
44
7
    size_t size() const { return candidates.size(); }
45
};
46
47
// Utility class for matching analyzer keys against reader entries.
48
// Stateless - all methods are static.
49
//
50
// Matching strategy:
51
// 1. If key is empty (user did not specify), return all readers for query-type-based selection
52
// 2. If key is non-empty (user specified), try exact match
53
// 3. If explicit key with no match, return empty (caller decides whether to bypass)
54
class AnalyzerKeyMatcher {
55
public:
56
    // Match analyzer key against reader entries.
57
    // @param analyzer_key: Normalized analyzer key (lowercase, or empty for auto-select)
58
    // @param entries: Available reader entries
59
    // @param key_index: Index mapping analyzer_key -> entry indices
60
    // @return MatchResult with candidates and fallback flag
61
    static AnalyzerMatchResult match(
62
            std::string_view analyzer_key, const std::vector<ReaderEntry>& entries,
63
            const std::unordered_map<std::string, std::vector<size_t>>& key_index);
64
65
    // Check if analyzer key is explicitly specified by user.
66
    // Empty string means "user did not specify" (auto-select mode).
67
    // Non-empty means "user wrote USING ANALYZER xxx".
68
28
    static bool is_explicit(std::string_view key) { return !key.empty(); }
69
70
    // Check if fallback (returning all readers) is allowed for this key.
71
    // Only empty key (user did not specify) allows fallback.
72
25
    static bool allows_fallback(std::string_view key) { return key.empty(); }
73
};
74
75
} // namespace doris::segment_v2