Coverage Report

Created: 2026-03-16 21:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/score_runtime.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 <gen_cpp/Exprs_types.h>
21
22
#include <optional>
23
24
#include "exprs/vexpr_context.h"
25
#include "exprs/virtual_slot_ref.h"
26
27
namespace doris {
28
#include "common/compile_check_begin.h"
29
30
class ScoreRuntime {
31
    ENABLE_FACTORY_CREATOR(ScoreRuntime);
32
33
public:
34
    // Score range filtering info for predicates like score() > 0.5
35
    struct ScoreRangeInfo {
36
        TExprOpcode::type op;
37
        double threshold;
38
    };
39
40
    ScoreRuntime(VExprContextSPtr order_by_expr_ctx, bool asc, size_t limit)
41
16
            : _order_by_expr_ctx(std::move(order_by_expr_ctx)), _asc(asc), _limit(limit) {};
42
43
3
    Status prepare(RuntimeState* state, const RowDescriptor& row_desc) {
44
3
        RETURN_IF_ERROR(_order_by_expr_ctx->prepare(state, row_desc));
45
3
        RETURN_IF_ERROR(_order_by_expr_ctx->open(state));
46
3
        auto vir_slot_ref = std::dynamic_pointer_cast<VirtualSlotRef>(_order_by_expr_ctx->root());
47
3
        DCHECK(vir_slot_ref != nullptr);
48
3
        if (vir_slot_ref == nullptr) {
49
0
            return Status::InternalError(
50
0
                    "root of order by expr of score topn must be a VirtualSlotRef, got\n{}",
51
0
                    _order_by_expr_ctx->root()->debug_string());
52
0
        }
53
3
        DCHECK(vir_slot_ref->column_id() >= 0);
54
3
        _dest_column_idx = vir_slot_ref->column_id();
55
3
        return Status::OK();
56
3
    }
57
58
3
    size_t get_dest_column_idx() const { return _dest_column_idx; }
59
60
3
    bool is_asc() const { return _asc; }
61
4
    size_t get_limit() const { return _limit; }
62
63
    // Score range filtering methods
64
9
    void set_score_range_info(TExprOpcode::type op, double threshold) {
65
9
        _score_range_info = ScoreRangeInfo {.op = op, .threshold = threshold};
66
9
    }
67
68
19
    const std::optional<ScoreRangeInfo>& get_score_range_info() const { return _score_range_info; }
69
70
9
    bool has_score_range_filter() const { return _score_range_info.has_value(); }
71
72
private:
73
    VExprContextSPtr _order_by_expr_ctx;
74
    const bool _asc = false;
75
    const size_t _limit = 0;
76
77
    std::string _name = "score_runtime";
78
    size_t _dest_column_idx = -1;
79
80
    // Score range filtering info (e.g., score() > 0.5)
81
    std::optional<ScoreRangeInfo> _score_range_info;
82
};
83
using ScoreRuntimeSPtr = std::shared_ptr<ScoreRuntime>;
84
85
#include "common/compile_check_end.h"
86
} // namespace doris