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 | 44 | static FunctionPtr create() { return std::make_shared<FunctionMathLog>(); }_ZN5doris15FunctionMathLogINS_6ImplLnEE6createEv Line | Count | Source | 34 | 17 | static FunctionPtr create() { return std::make_shared<FunctionMathLog>(); } |
_ZN5doris15FunctionMathLogINS_8ImplLog2EE6createEv Line | Count | Source | 34 | 12 | static FunctionPtr create() { return std::make_shared<FunctionMathLog>(); } |
_ZN5doris15FunctionMathLogINS_9ImplLog10EE6createEv Line | Count | Source | 34 | 15 | static FunctionPtr create() { return std::make_shared<FunctionMathLog>(); } |
|
35 | | |
36 | | private: |
37 | 3 | String get_name() const override { return name; }_ZNK5doris15FunctionMathLogINS_6ImplLnEE8get_nameB5cxx11Ev Line | Count | Source | 37 | 1 | String get_name() const override { return name; } |
_ZNK5doris15FunctionMathLogINS_8ImplLog2EE8get_nameB5cxx11Ev Line | Count | Source | 37 | 1 | String get_name() const override { return name; } |
_ZNK5doris15FunctionMathLogINS_9ImplLog10EE8get_nameB5cxx11Ev Line | Count | Source | 37 | 1 | String get_name() const override { return name; } |
|
38 | 17 | size_t get_number_of_arguments() const override { return 1; }_ZNK5doris15FunctionMathLogINS_6ImplLnEE23get_number_of_argumentsEv Line | Count | Source | 38 | 8 | size_t get_number_of_arguments() const override { return 1; } |
_ZNK5doris15FunctionMathLogINS_8ImplLog2EE23get_number_of_argumentsEv Line | Count | Source | 38 | 3 | size_t get_number_of_arguments() const override { return 1; } |
_ZNK5doris15FunctionMathLogINS_9ImplLog10EE23get_number_of_argumentsEv Line | Count | Source | 38 | 6 | size_t get_number_of_arguments() const override { return 1; } |
|
39 | | |
40 | 17 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
41 | 17 | return make_nullable(std::make_shared<DataTypeFloat64>()); |
42 | 17 | } _ZNK5doris15FunctionMathLogINS_6ImplLnEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 40 | 8 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 41 | 8 | return make_nullable(std::make_shared<DataTypeFloat64>()); | 42 | 8 | } |
_ZNK5doris15FunctionMathLogINS_8ImplLog2EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 40 | 3 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 41 | 3 | return make_nullable(std::make_shared<DataTypeFloat64>()); | 42 | 3 | } |
_ZNK5doris15FunctionMathLogINS_9ImplLog10EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 40 | 6 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 41 | 6 | return make_nullable(std::make_shared<DataTypeFloat64>()); | 42 | 6 | } |
|
43 | | |
44 | | static void execute_in_iterations(const double* src_data, double* dst_data, NullMap& null_map, |
45 | 76 | size_t size) { |
46 | 424 | for (size_t i = 0; i < size; i++) { |
47 | 348 | null_map[i] = src_data[i] <= 0; |
48 | 348 | Impl::execute(&src_data[i], &dst_data[i]); |
49 | 348 | } |
50 | 76 | } _ZN5doris15FunctionMathLogINS_6ImplLnEE21execute_in_iterationsEPKdPdRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEEm Line | Count | Source | 45 | 45 | size_t size) { | 46 | 294 | for (size_t i = 0; i < size; i++) { | 47 | 249 | null_map[i] = src_data[i] <= 0; | 48 | 249 | Impl::execute(&src_data[i], &dst_data[i]); | 49 | 249 | } | 50 | 45 | } |
_ZN5doris15FunctionMathLogINS_8ImplLog2EE21execute_in_iterationsEPKdPdRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEEm Line | Count | Source | 45 | 9 | size_t size) { | 46 | 39 | for (size_t i = 0; i < size; i++) { | 47 | 30 | null_map[i] = src_data[i] <= 0; | 48 | 30 | Impl::execute(&src_data[i], &dst_data[i]); | 49 | 30 | } | 50 | 9 | } |
_ZN5doris15FunctionMathLogINS_9ImplLog10EE21execute_in_iterationsEPKdPdRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEEm Line | Count | Source | 45 | 22 | size_t size) { | 46 | 91 | for (size_t i = 0; i < size; i++) { | 47 | 69 | null_map[i] = src_data[i] <= 0; | 48 | 69 | Impl::execute(&src_data[i], &dst_data[i]); | 49 | 69 | } | 50 | 22 | } |
|
51 | | |
52 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
53 | 76 | uint32_t result, size_t input_rows_count) const override { |
54 | 76 | const auto* col = |
55 | 76 | assert_cast<const ColumnFloat64*>(block.get_by_position(arguments[0]).column.get()); |
56 | | |
57 | 76 | const auto& src_data = col->get_data(); |
58 | 76 | const size_t size = src_data.size(); |
59 | | |
60 | 76 | auto dst = ColumnFloat64::create(); |
61 | 76 | auto& dst_data = dst->get_data(); |
62 | 76 | dst_data.resize(size); |
63 | | |
64 | 76 | auto null_column = ColumnUInt8::create(); |
65 | 76 | auto& null_map = null_column->get_data(); |
66 | 76 | null_map.resize(size); |
67 | | |
68 | 76 | execute_in_iterations(col->get_data().data(), dst_data.data(), null_map, size); |
69 | | |
70 | 76 | block.replace_by_position(result, |
71 | 76 | ColumnNullable::create(std::move(dst), std::move(null_column))); |
72 | 76 | return Status::OK(); |
73 | 76 | } _ZNK5doris15FunctionMathLogINS_6ImplLnEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 53 | 45 | uint32_t result, size_t input_rows_count) const override { | 54 | 45 | const auto* col = | 55 | 45 | assert_cast<const ColumnFloat64*>(block.get_by_position(arguments[0]).column.get()); | 56 | | | 57 | 45 | const auto& src_data = col->get_data(); | 58 | 45 | const size_t size = src_data.size(); | 59 | | | 60 | 45 | auto dst = ColumnFloat64::create(); | 61 | 45 | auto& dst_data = dst->get_data(); | 62 | 45 | dst_data.resize(size); | 63 | | | 64 | 45 | auto null_column = ColumnUInt8::create(); | 65 | 45 | auto& null_map = null_column->get_data(); | 66 | 45 | null_map.resize(size); | 67 | | | 68 | 45 | execute_in_iterations(col->get_data().data(), dst_data.data(), null_map, size); | 69 | | | 70 | 45 | block.replace_by_position(result, | 71 | 45 | ColumnNullable::create(std::move(dst), std::move(null_column))); | 72 | 45 | return Status::OK(); | 73 | 45 | } |
_ZNK5doris15FunctionMathLogINS_8ImplLog2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 53 | 9 | uint32_t result, size_t input_rows_count) const override { | 54 | 9 | const auto* col = | 55 | 9 | assert_cast<const ColumnFloat64*>(block.get_by_position(arguments[0]).column.get()); | 56 | | | 57 | 9 | const auto& src_data = col->get_data(); | 58 | 9 | const size_t size = src_data.size(); | 59 | | | 60 | 9 | auto dst = ColumnFloat64::create(); | 61 | 9 | auto& dst_data = dst->get_data(); | 62 | 9 | dst_data.resize(size); | 63 | | | 64 | 9 | auto null_column = ColumnUInt8::create(); | 65 | 9 | auto& null_map = null_column->get_data(); | 66 | 9 | null_map.resize(size); | 67 | | | 68 | 9 | execute_in_iterations(col->get_data().data(), dst_data.data(), null_map, size); | 69 | | | 70 | 9 | block.replace_by_position(result, | 71 | 9 | ColumnNullable::create(std::move(dst), std::move(null_column))); | 72 | 9 | return Status::OK(); | 73 | 9 | } |
_ZNK5doris15FunctionMathLogINS_9ImplLog10EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 53 | 22 | uint32_t result, size_t input_rows_count) const override { | 54 | 22 | const auto* col = | 55 | 22 | assert_cast<const ColumnFloat64*>(block.get_by_position(arguments[0]).column.get()); | 56 | | | 57 | 22 | const auto& src_data = col->get_data(); | 58 | 22 | const size_t size = src_data.size(); | 59 | | | 60 | 22 | auto dst = ColumnFloat64::create(); | 61 | 22 | auto& dst_data = dst->get_data(); | 62 | 22 | dst_data.resize(size); | 63 | | | 64 | 22 | auto null_column = ColumnUInt8::create(); | 65 | 22 | auto& null_map = null_column->get_data(); | 66 | 22 | null_map.resize(size); | 67 | | | 68 | 22 | execute_in_iterations(col->get_data().data(), dst_data.data(), null_map, size); | 69 | | | 70 | 22 | block.replace_by_position(result, | 71 | 22 | ColumnNullable::create(std::move(dst), std::move(null_column))); | 72 | 22 | return Status::OK(); | 73 | 22 | } |
|
74 | | }; |
75 | | |
76 | | struct ImplLog10 { |
77 | | static constexpr auto name = "log10"; |
78 | 69 | static void execute(const double* src, double* dst) { *dst = std::log10(*src); } |
79 | | }; |
80 | | |
81 | | struct ImplLog2 { |
82 | | static constexpr auto name = "log2"; |
83 | 30 | static void execute(const double* src, double* dst) { *dst = std::log2(*src); } |
84 | | }; |
85 | | |
86 | | struct ImplLn { |
87 | | static constexpr auto name = "ln"; |
88 | 249 | static void execute(const double* src, double* dst) { *dst = std::log(*src); } |
89 | | }; |
90 | | |
91 | | } // namespace doris |