Coverage Report

Created: 2026-03-19 11:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/function/function_math_log.h
Line
Count
Source
1
2
// Licensed to the Apache Software Foundation (ASF) under one
3
// or more contributor license agreements.  See the NOTICE file
4
// distributed with this work for additional information
5
// regarding copyright ownership.  The ASF licenses this file
6
// to you under the Apache License, Version 2.0 (the
7
// "License"); you may not use this file except in compliance
8
// with the License.  You may obtain a copy of the License at
9
//
10
//   http://www.apache.org/licenses/LICENSE-2.0
11
//
12
// Unless required by applicable law or agreed to in writing,
13
// software distributed under the License is distributed on an
14
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
// KIND, either express or implied.  See the License for the
16
// specific language governing permissions and limitations
17
// under the License.
18
19
#pragma once
20
21
#include "core/assert_cast.h"
22
#include "core/data_type/data_type_number.h"
23
#include "core/types.h"
24
#include "exprs/function/function.h"
25
26
namespace doris {
27
28
template <typename Impl>
29
class FunctionMathLog : public IFunction {
30
public:
31
    using IFunction::execute;
32
33
    static constexpr auto name = Impl::name;
34
117
    static FunctionPtr create() { return std::make_shared<FunctionMathLog>(); }
_ZN5doris15FunctionMathLogINS_6ImplLnEE6createEv
Line
Count
Source
34
48
    static FunctionPtr create() { return std::make_shared<FunctionMathLog>(); }
_ZN5doris15FunctionMathLogINS_8ImplLog2EE6createEv
Line
Count
Source
34
32
    static FunctionPtr create() { return std::make_shared<FunctionMathLog>(); }
_ZN5doris15FunctionMathLogINS_9ImplLog10EE6createEv
Line
Count
Source
34
37
    static FunctionPtr create() { return std::make_shared<FunctionMathLog>(); }
35
36
private:
37
6
    String get_name() const override { return name; }
_ZNK5doris15FunctionMathLogINS_6ImplLnEE8get_nameB5cxx11Ev
Line
Count
Source
37
2
    String get_name() const override { return name; }
_ZNK5doris15FunctionMathLogINS_8ImplLog2EE8get_nameB5cxx11Ev
Line
Count
Source
37
2
    String get_name() const override { return name; }
_ZNK5doris15FunctionMathLogINS_9ImplLog10EE8get_nameB5cxx11Ev
Line
Count
Source
37
2
    String get_name() const override { return name; }
38
84
    size_t get_number_of_arguments() const override { return 1; }
_ZNK5doris15FunctionMathLogINS_6ImplLnEE23get_number_of_argumentsEv
Line
Count
Source
38
37
    size_t get_number_of_arguments() const override { return 1; }
_ZNK5doris15FunctionMathLogINS_8ImplLog2EE23get_number_of_argumentsEv
Line
Count
Source
38
21
    size_t get_number_of_arguments() const override { return 1; }
_ZNK5doris15FunctionMathLogINS_9ImplLog10EE23get_number_of_argumentsEv
Line
Count
Source
38
26
    size_t get_number_of_arguments() const override { return 1; }
39
40
84
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
41
84
        return make_nullable(std::make_shared<DataTypeFloat64>());
42
84
    }
_ZNK5doris15FunctionMathLogINS_6ImplLnEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
40
37
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
41
37
        return make_nullable(std::make_shared<DataTypeFloat64>());
42
37
    }
_ZNK5doris15FunctionMathLogINS_8ImplLog2EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
40
21
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
41
21
        return make_nullable(std::make_shared<DataTypeFloat64>());
42
21
    }
_ZNK5doris15FunctionMathLogINS_9ImplLog10EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
40
26
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
41
26
        return make_nullable(std::make_shared<DataTypeFloat64>());
42
26
    }
43
44
    static void execute_in_iterations(const double* src_data, double* dst_data, NullMap& null_map,
45
131
                                      size_t size) {
46
535
        for (size_t i = 0; i < size; i++) {
47
404
            null_map[i] = src_data[i] <= 0;
48
404
            Impl::execute(&src_data[i], &dst_data[i]);
49
404
        }
50
131
    }
_ZN5doris15FunctionMathLogINS_6ImplLnEE21execute_in_iterationsEPKdPdRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEm
Line
Count
Source
45
71
                                      size_t size) {
46
335
        for (size_t i = 0; i < size; i++) {
47
264
            null_map[i] = src_data[i] <= 0;
48
264
            Impl::execute(&src_data[i], &dst_data[i]);
49
264
        }
50
71
    }
_ZN5doris15FunctionMathLogINS_8ImplLog2EE21execute_in_iterationsEPKdPdRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEm
Line
Count
Source
45
25
                                      size_t size) {
46
75
        for (size_t i = 0; i < size; i++) {
47
50
            null_map[i] = src_data[i] <= 0;
48
50
            Impl::execute(&src_data[i], &dst_data[i]);
49
50
        }
50
25
    }
_ZN5doris15FunctionMathLogINS_9ImplLog10EE21execute_in_iterationsEPKdPdRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEm
Line
Count
Source
45
35
                                      size_t size) {
46
125
        for (size_t i = 0; i < size; i++) {
47
90
            null_map[i] = src_data[i] <= 0;
48
90
            Impl::execute(&src_data[i], &dst_data[i]);
49
90
        }
50
35
    }
51
52
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
53
131
                        uint32_t result, size_t input_rows_count) const override {
54
131
        const auto* col =
55
131
                assert_cast<const ColumnFloat64*>(block.get_by_position(arguments[0]).column.get());
56
57
131
        const auto& src_data = col->get_data();
58
131
        const size_t size = src_data.size();
59
60
131
        auto dst = ColumnFloat64::create();
61
131
        auto& dst_data = dst->get_data();
62
131
        dst_data.resize(size);
63
64
131
        auto null_column = ColumnUInt8::create();
65
131
        auto& null_map = null_column->get_data();
66
131
        null_map.resize(size);
67
68
131
        execute_in_iterations(col->get_data().data(), dst_data.data(), null_map, size);
69
70
131
        block.replace_by_position(result,
71
131
                                  ColumnNullable::create(std::move(dst), std::move(null_column)));
72
131
        return Status::OK();
73
131
    }
_ZNK5doris15FunctionMathLogINS_6ImplLnEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
53
71
                        uint32_t result, size_t input_rows_count) const override {
54
71
        const auto* col =
55
71
                assert_cast<const ColumnFloat64*>(block.get_by_position(arguments[0]).column.get());
56
57
71
        const auto& src_data = col->get_data();
58
71
        const size_t size = src_data.size();
59
60
71
        auto dst = ColumnFloat64::create();
61
71
        auto& dst_data = dst->get_data();
62
71
        dst_data.resize(size);
63
64
71
        auto null_column = ColumnUInt8::create();
65
71
        auto& null_map = null_column->get_data();
66
71
        null_map.resize(size);
67
68
71
        execute_in_iterations(col->get_data().data(), dst_data.data(), null_map, size);
69
70
71
        block.replace_by_position(result,
71
71
                                  ColumnNullable::create(std::move(dst), std::move(null_column)));
72
71
        return Status::OK();
73
71
    }
_ZNK5doris15FunctionMathLogINS_8ImplLog2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
53
25
                        uint32_t result, size_t input_rows_count) const override {
54
25
        const auto* col =
55
25
                assert_cast<const ColumnFloat64*>(block.get_by_position(arguments[0]).column.get());
56
57
25
        const auto& src_data = col->get_data();
58
25
        const size_t size = src_data.size();
59
60
25
        auto dst = ColumnFloat64::create();
61
25
        auto& dst_data = dst->get_data();
62
25
        dst_data.resize(size);
63
64
25
        auto null_column = ColumnUInt8::create();
65
25
        auto& null_map = null_column->get_data();
66
25
        null_map.resize(size);
67
68
25
        execute_in_iterations(col->get_data().data(), dst_data.data(), null_map, size);
69
70
25
        block.replace_by_position(result,
71
25
                                  ColumnNullable::create(std::move(dst), std::move(null_column)));
72
25
        return Status::OK();
73
25
    }
_ZNK5doris15FunctionMathLogINS_9ImplLog10EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
53
35
                        uint32_t result, size_t input_rows_count) const override {
54
35
        const auto* col =
55
35
                assert_cast<const ColumnFloat64*>(block.get_by_position(arguments[0]).column.get());
56
57
35
        const auto& src_data = col->get_data();
58
35
        const size_t size = src_data.size();
59
60
35
        auto dst = ColumnFloat64::create();
61
35
        auto& dst_data = dst->get_data();
62
35
        dst_data.resize(size);
63
64
35
        auto null_column = ColumnUInt8::create();
65
35
        auto& null_map = null_column->get_data();
66
35
        null_map.resize(size);
67
68
35
        execute_in_iterations(col->get_data().data(), dst_data.data(), null_map, size);
69
70
35
        block.replace_by_position(result,
71
35
                                  ColumnNullable::create(std::move(dst), std::move(null_column)));
72
35
        return Status::OK();
73
35
    }
74
};
75
76
struct ImplLog10 {
77
    static constexpr auto name = "log10";
78
90
    static void execute(const double* src, double* dst) { *dst = std::log10(*src); }
79
};
80
81
struct ImplLog2 {
82
    static constexpr auto name = "log2";
83
50
    static void execute(const double* src, double* dst) { *dst = std::log2(*src); }
84
};
85
86
struct ImplLn {
87
    static constexpr auto name = "ln";
88
264
    static void execute(const double* src, double* dst) { *dst = std::log(*src); }
89
};
90
91
} // namespace doris