be/src/exprs/function/function_string_digest.cpp
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 | | #include <cstddef> |
19 | | #include <string_view> |
20 | | |
21 | | #include "common/status.h" |
22 | | #include "core/assert_cast.h" |
23 | | #include "core/block/block.h" |
24 | | #include "core/block/column_numbers.h" |
25 | | #include "core/column/column_string.h" |
26 | | #include "core/column/column_varbinary.h" |
27 | | #include "core/column/column_vector.h" |
28 | | #include "core/data_type/data_type_string.h" |
29 | | #include "core/string_ref.h" |
30 | | #include "exec/common/stringop_substring.h" |
31 | | #include "exprs/function/function.h" |
32 | | #include "exprs/function/simple_function_factory.h" |
33 | | #include "exprs/function_context.h" |
34 | | #include "util/md5.h" |
35 | | #include "util/sha.h" |
36 | | #include "util/sm3.h" |
37 | | |
38 | | namespace doris { |
39 | | #include "common/compile_check_avoid_begin.h" |
40 | | |
41 | | struct SM3Sum { |
42 | | static constexpr auto name = "sm3sum"; |
43 | | using ObjectData = SM3Digest; |
44 | | }; |
45 | | |
46 | | struct MD5Sum { |
47 | | static constexpr auto name = "md5sum"; |
48 | | using ObjectData = Md5Digest; |
49 | | }; |
50 | | |
51 | | template <typename Impl> |
52 | | class FunctionStringDigestMulti : public IFunction { |
53 | | public: |
54 | | static constexpr auto name = Impl::name; |
55 | 274 | static FunctionPtr create() { return std::make_shared<FunctionStringDigestMulti>(); }_ZN5doris25FunctionStringDigestMultiINS_6SM3SumEE6createEv Line | Count | Source | 55 | 131 | static FunctionPtr create() { return std::make_shared<FunctionStringDigestMulti>(); } |
_ZN5doris25FunctionStringDigestMultiINS_6MD5SumEE6createEv Line | Count | Source | 55 | 143 | static FunctionPtr create() { return std::make_shared<FunctionStringDigestMulti>(); } |
|
56 | 0 | String get_name() const override { return name; }Unexecuted instantiation: _ZNK5doris25FunctionStringDigestMultiINS_6SM3SumEE8get_nameB5cxx11Ev Unexecuted instantiation: _ZNK5doris25FunctionStringDigestMultiINS_6MD5SumEE8get_nameB5cxx11Ev |
57 | 0 | size_t get_number_of_arguments() const override { return 0; }Unexecuted instantiation: _ZNK5doris25FunctionStringDigestMultiINS_6SM3SumEE23get_number_of_argumentsEv Unexecuted instantiation: _ZNK5doris25FunctionStringDigestMultiINS_6MD5SumEE23get_number_of_argumentsEv |
58 | 262 | bool is_variadic() const override { return true; }_ZNK5doris25FunctionStringDigestMultiINS_6SM3SumEE11is_variadicEv Line | Count | Source | 58 | 125 | bool is_variadic() const override { return true; } |
_ZNK5doris25FunctionStringDigestMultiINS_6MD5SumEE11is_variadicEv Line | Count | Source | 58 | 137 | bool is_variadic() const override { return true; } |
|
59 | | |
60 | 260 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
61 | 260 | return std::make_shared<DataTypeString>(); |
62 | 260 | } _ZNK5doris25FunctionStringDigestMultiINS_6SM3SumEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 60 | 124 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 61 | 124 | return std::make_shared<DataTypeString>(); | 62 | 124 | } |
_ZNK5doris25FunctionStringDigestMultiINS_6MD5SumEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 60 | 136 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 61 | 136 | return std::make_shared<DataTypeString>(); | 62 | 136 | } |
|
63 | | |
64 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
65 | 264 | uint32_t result, size_t input_rows_count) const override { |
66 | 264 | DCHECK_GE(arguments.size(), 1); |
67 | | |
68 | 264 | auto res = ColumnString::create(); |
69 | 264 | auto& res_data = res->get_chars(); |
70 | 264 | auto& res_offset = res->get_offsets(); |
71 | 264 | res_offset.resize(input_rows_count); |
72 | | |
73 | 264 | std::vector<ColumnPtr> argument_columns(arguments.size()); |
74 | 264 | std::vector<uint8_t> is_const(arguments.size(), 0); |
75 | 763 | for (size_t i = 0; i < arguments.size(); ++i) { |
76 | 499 | std::tie(argument_columns[i], is_const[i]) = |
77 | 499 | unpack_if_const(block.get_by_position(arguments[i]).column); |
78 | 499 | } |
79 | | |
80 | 264 | if (check_and_get_column<ColumnString>(argument_columns[0].get())) { |
81 | 177 | vector_execute<ColumnString>(block, input_rows_count, argument_columns, is_const, |
82 | 177 | res_data, res_offset); |
83 | 177 | } else if (check_and_get_column<ColumnVarbinary>(argument_columns[0].get())) { |
84 | 88 | vector_execute<ColumnVarbinary>(block, input_rows_count, argument_columns, is_const, |
85 | 88 | res_data, res_offset); |
86 | 18.4E | } else { |
87 | 18.4E | return Status::RuntimeError("Illegal column {} of argument of function {}", |
88 | 18.4E | argument_columns[0]->get_name(), get_name()); |
89 | 18.4E | } |
90 | | |
91 | 265 | block.replace_by_position(result, std::move(res)); |
92 | 265 | return Status::OK(); |
93 | 264 | } _ZNK5doris25FunctionStringDigestMultiINS_6SM3SumEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 65 | 123 | uint32_t result, size_t input_rows_count) const override { | 66 | 123 | DCHECK_GE(arguments.size(), 1); | 67 | | | 68 | 123 | auto res = ColumnString::create(); | 69 | 123 | auto& res_data = res->get_chars(); | 70 | 123 | auto& res_offset = res->get_offsets(); | 71 | 123 | res_offset.resize(input_rows_count); | 72 | | | 73 | 123 | std::vector<ColumnPtr> argument_columns(arguments.size()); | 74 | 123 | std::vector<uint8_t> is_const(arguments.size(), 0); | 75 | 364 | for (size_t i = 0; i < arguments.size(); ++i) { | 76 | 241 | std::tie(argument_columns[i], is_const[i]) = | 77 | 241 | unpack_if_const(block.get_by_position(arguments[i]).column); | 78 | 241 | } | 79 | | | 80 | 123 | if (check_and_get_column<ColumnString>(argument_columns[0].get())) { | 81 | 80 | vector_execute<ColumnString>(block, input_rows_count, argument_columns, is_const, | 82 | 80 | res_data, res_offset); | 83 | 80 | } else if (check_and_get_column<ColumnVarbinary>(argument_columns[0].get())) { | 84 | 44 | vector_execute<ColumnVarbinary>(block, input_rows_count, argument_columns, is_const, | 85 | 44 | res_data, res_offset); | 86 | 18.4E | } else { | 87 | 18.4E | return Status::RuntimeError("Illegal column {} of argument of function {}", | 88 | 18.4E | argument_columns[0]->get_name(), get_name()); | 89 | 18.4E | } | 90 | | | 91 | 124 | block.replace_by_position(result, std::move(res)); | 92 | 124 | return Status::OK(); | 93 | 123 | } |
_ZNK5doris25FunctionStringDigestMultiINS_6MD5SumEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 65 | 141 | uint32_t result, size_t input_rows_count) const override { | 66 | 141 | DCHECK_GE(arguments.size(), 1); | 67 | | | 68 | 141 | auto res = ColumnString::create(); | 69 | 141 | auto& res_data = res->get_chars(); | 70 | 141 | auto& res_offset = res->get_offsets(); | 71 | 141 | res_offset.resize(input_rows_count); | 72 | | | 73 | 141 | std::vector<ColumnPtr> argument_columns(arguments.size()); | 74 | 141 | std::vector<uint8_t> is_const(arguments.size(), 0); | 75 | 399 | for (size_t i = 0; i < arguments.size(); ++i) { | 76 | 258 | std::tie(argument_columns[i], is_const[i]) = | 77 | 258 | unpack_if_const(block.get_by_position(arguments[i]).column); | 78 | 258 | } | 79 | | | 80 | 141 | if (check_and_get_column<ColumnString>(argument_columns[0].get())) { | 81 | 97 | vector_execute<ColumnString>(block, input_rows_count, argument_columns, is_const, | 82 | 97 | res_data, res_offset); | 83 | 97 | } else if (check_and_get_column<ColumnVarbinary>(argument_columns[0].get())) { | 84 | 44 | vector_execute<ColumnVarbinary>(block, input_rows_count, argument_columns, is_const, | 85 | 44 | res_data, res_offset); | 86 | 44 | } else { | 87 | 0 | return Status::RuntimeError("Illegal column {} of argument of function {}", | 88 | 0 | argument_columns[0]->get_name(), get_name()); | 89 | 0 | } | 90 | | | 91 | 141 | block.replace_by_position(result, std::move(res)); | 92 | 141 | return Status::OK(); | 93 | 141 | } |
|
94 | | |
95 | | private: |
96 | | template <typename ColumnType> |
97 | | void vector_execute(Block& block, size_t input_rows_count, |
98 | | const std::vector<ColumnPtr>& argument_columns, |
99 | | const std::vector<uint8_t>& is_const, ColumnString::Chars& res_data, |
100 | 265 | ColumnString::Offsets& res_offset) const { |
101 | 265 | using ObjectData = typename Impl::ObjectData; |
102 | 785 | for (size_t i = 0; i < input_rows_count; ++i) { |
103 | 520 | ObjectData digest; |
104 | 1.37k | for (size_t j = 0; j < argument_columns.size(); ++j) { |
105 | 854 | const auto* col = assert_cast<const ColumnType*>(argument_columns[j].get()); |
106 | 854 | StringRef data_ref = col->get_data_at(is_const[j] ? 0 : i); |
107 | 854 | if (data_ref.size < 1) { |
108 | 155 | continue; |
109 | 155 | } |
110 | 699 | digest.update(data_ref.data, data_ref.size); |
111 | 699 | } |
112 | 520 | digest.digest(); |
113 | 520 | StringOP::push_value_string(std::string_view(digest.hex().c_str(), digest.hex().size()), |
114 | 520 | i, res_data, res_offset); |
115 | 520 | } |
116 | 265 | } _ZNK5doris25FunctionStringDigestMultiINS_6SM3SumEE14vector_executeINS_9ColumnStrIjEEEEvRNS_5BlockEmRKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrISA_EESaISD_EERKS8_IhSaIhEERNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNSM_IjLm4096ESP_Lm16ELm15EEE Line | Count | Source | 100 | 80 | ColumnString::Offsets& res_offset) const { | 101 | 80 | using ObjectData = typename Impl::ObjectData; | 102 | 257 | for (size_t i = 0; i < input_rows_count; ++i) { | 103 | 177 | ObjectData digest; | 104 | 438 | for (size_t j = 0; j < argument_columns.size(); ++j) { | 105 | 261 | const auto* col = assert_cast<const ColumnType*>(argument_columns[j].get()); | 106 | 261 | StringRef data_ref = col->get_data_at(is_const[j] ? 0 : i); | 107 | 261 | if (data_ref.size < 1) { | 108 | 38 | continue; | 109 | 38 | } | 110 | 223 | digest.update(data_ref.data, data_ref.size); | 111 | 223 | } | 112 | 177 | digest.digest(); | 113 | 177 | StringOP::push_value_string(std::string_view(digest.hex().c_str(), digest.hex().size()), | 114 | 177 | i, res_data, res_offset); | 115 | 177 | } | 116 | 80 | } |
_ZNK5doris25FunctionStringDigestMultiINS_6SM3SumEE14vector_executeINS_15ColumnVarbinaryEEEvRNS_5BlockEmRKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS9_EESaISC_EERKS7_IhSaIhEERNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNSL_IjLm4096ESO_Lm16ELm15EEE Line | Count | Source | 100 | 44 | ColumnString::Offsets& res_offset) const { | 101 | 44 | using ObjectData = typename Impl::ObjectData; | 102 | 117 | for (size_t i = 0; i < input_rows_count; ++i) { | 103 | 73 | ObjectData digest; | 104 | 229 | for (size_t j = 0; j < argument_columns.size(); ++j) { | 105 | 156 | const auto* col = assert_cast<const ColumnType*>(argument_columns[j].get()); | 106 | 156 | StringRef data_ref = col->get_data_at(is_const[j] ? 0 : i); | 107 | 156 | if (data_ref.size < 1) { | 108 | 38 | continue; | 109 | 38 | } | 110 | 118 | digest.update(data_ref.data, data_ref.size); | 111 | 118 | } | 112 | 73 | digest.digest(); | 113 | 73 | StringOP::push_value_string(std::string_view(digest.hex().c_str(), digest.hex().size()), | 114 | 73 | i, res_data, res_offset); | 115 | 73 | } | 116 | 44 | } |
_ZNK5doris25FunctionStringDigestMultiINS_6MD5SumEE14vector_executeINS_9ColumnStrIjEEEEvRNS_5BlockEmRKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrISA_EESaISD_EERKS8_IhSaIhEERNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNSM_IjLm4096ESP_Lm16ELm15EEE Line | Count | Source | 100 | 97 | ColumnString::Offsets& res_offset) const { | 101 | 97 | using ObjectData = typename Impl::ObjectData; | 102 | 294 | for (size_t i = 0; i < input_rows_count; ++i) { | 103 | 197 | ObjectData digest; | 104 | 478 | for (size_t j = 0; j < argument_columns.size(); ++j) { | 105 | 281 | const auto* col = assert_cast<const ColumnType*>(argument_columns[j].get()); | 106 | 281 | StringRef data_ref = col->get_data_at(is_const[j] ? 0 : i); | 107 | 281 | if (data_ref.size < 1) { | 108 | 41 | continue; | 109 | 41 | } | 110 | 240 | digest.update(data_ref.data, data_ref.size); | 111 | 240 | } | 112 | 197 | digest.digest(); | 113 | 197 | StringOP::push_value_string(std::string_view(digest.hex().c_str(), digest.hex().size()), | 114 | 197 | i, res_data, res_offset); | 115 | 197 | } | 116 | 97 | } |
_ZNK5doris25FunctionStringDigestMultiINS_6MD5SumEE14vector_executeINS_15ColumnVarbinaryEEEvRNS_5BlockEmRKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS9_EESaISC_EERKS7_IhSaIhEERNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNSL_IjLm4096ESO_Lm16ELm15EEE Line | Count | Source | 100 | 44 | ColumnString::Offsets& res_offset) const { | 101 | 44 | using ObjectData = typename Impl::ObjectData; | 102 | 117 | for (size_t i = 0; i < input_rows_count; ++i) { | 103 | 73 | ObjectData digest; | 104 | 229 | for (size_t j = 0; j < argument_columns.size(); ++j) { | 105 | 156 | const auto* col = assert_cast<const ColumnType*>(argument_columns[j].get()); | 106 | 156 | StringRef data_ref = col->get_data_at(is_const[j] ? 0 : i); | 107 | 156 | if (data_ref.size < 1) { | 108 | 38 | continue; | 109 | 38 | } | 110 | 118 | digest.update(data_ref.data, data_ref.size); | 111 | 118 | } | 112 | 73 | digest.digest(); | 113 | 73 | StringOP::push_value_string(std::string_view(digest.hex().c_str(), digest.hex().size()), | 114 | 73 | i, res_data, res_offset); | 115 | 73 | } | 116 | 44 | } |
|
117 | | }; |
118 | | |
119 | | class FunctionStringDigestSHA1 : public IFunction { |
120 | | public: |
121 | | static constexpr auto name = "sha1"; |
122 | 26 | static FunctionPtr create() { return std::make_shared<FunctionStringDigestSHA1>(); } |
123 | 0 | String get_name() const override { return name; } |
124 | 0 | size_t get_number_of_arguments() const override { return 1; } |
125 | 20 | bool is_variadic() const override { return true; } |
126 | | |
127 | 19 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
128 | 19 | return std::make_shared<DataTypeString>(); |
129 | 19 | } |
130 | | |
131 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
132 | 18 | uint32_t result, size_t input_rows_count) const override { |
133 | 18 | DCHECK_EQ(arguments.size(), 1); |
134 | 18 | ColumnPtr data_col = block.get_by_position(arguments[0]).column; |
135 | | |
136 | 18 | auto res_col = ColumnString::create(); |
137 | 18 | auto& res_data = res_col->get_chars(); |
138 | 18 | auto& res_offset = res_col->get_offsets(); |
139 | 18 | res_offset.resize(input_rows_count); |
140 | 18 | if (const auto* str_col = check_and_get_column<ColumnString>(data_col.get())) { |
141 | 11 | vector_execute(str_col, input_rows_count, res_data, res_offset); |
142 | 11 | } else if (const auto* vb_col = check_and_get_column<ColumnVarbinary>(data_col.get())) { |
143 | 7 | vector_execute(vb_col, input_rows_count, res_data, res_offset); |
144 | 7 | } else { |
145 | 0 | return Status::RuntimeError("Illegal column {} of argument of function {}", |
146 | 0 | data_col->get_name(), get_name()); |
147 | 0 | } |
148 | | |
149 | 18 | block.replace_by_position(result, std::move(res_col)); |
150 | 18 | return Status::OK(); |
151 | 18 | } |
152 | | |
153 | | private: |
154 | | template <typename ColumnType> |
155 | | void vector_execute(const ColumnType* col, size_t input_rows_count, |
156 | 18 | ColumnString::Chars& res_data, ColumnString::Offsets& res_offset) const { |
157 | 18 | SHA1Digest digest; |
158 | 61 | for (size_t i = 0; i < input_rows_count; ++i) { |
159 | 43 | StringRef data_ref = col->get_data_at(i); |
160 | 43 | digest.reset(data_ref.data, data_ref.size); |
161 | 43 | std::string_view ans = digest.digest(); |
162 | | |
163 | 43 | StringOP::push_value_string(ans, i, res_data, res_offset); |
164 | 43 | } |
165 | 18 | } _ZNK5doris24FunctionStringDigestSHA114vector_executeINS_9ColumnStrIjEEEEvPKT_mRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNS7_IjLm4096ESA_Lm16ELm15EEE Line | Count | Source | 156 | 11 | ColumnString::Chars& res_data, ColumnString::Offsets& res_offset) const { | 157 | 11 | SHA1Digest digest; | 158 | 35 | for (size_t i = 0; i < input_rows_count; ++i) { | 159 | 24 | StringRef data_ref = col->get_data_at(i); | 160 | 24 | digest.reset(data_ref.data, data_ref.size); | 161 | 24 | std::string_view ans = digest.digest(); | 162 | | | 163 | 24 | StringOP::push_value_string(ans, i, res_data, res_offset); | 164 | 24 | } | 165 | 11 | } |
_ZNK5doris24FunctionStringDigestSHA114vector_executeINS_15ColumnVarbinaryEEEvPKT_mRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNS6_IjLm4096ES9_Lm16ELm15EEE Line | Count | Source | 156 | 7 | ColumnString::Chars& res_data, ColumnString::Offsets& res_offset) const { | 157 | 7 | SHA1Digest digest; | 158 | 26 | for (size_t i = 0; i < input_rows_count; ++i) { | 159 | 19 | StringRef data_ref = col->get_data_at(i); | 160 | 19 | digest.reset(data_ref.data, data_ref.size); | 161 | 19 | std::string_view ans = digest.digest(); | 162 | | | 163 | 19 | StringOP::push_value_string(ans, i, res_data, res_offset); | 164 | 19 | } | 165 | 7 | } |
|
166 | | }; |
167 | | |
168 | | class FunctionStringDigestSHA2 : public IFunction { |
169 | | public: |
170 | | static constexpr auto name = "sha2"; |
171 | 28 | static FunctionPtr create() { return std::make_shared<FunctionStringDigestSHA2>(); } |
172 | 0 | String get_name() const override { return name; } |
173 | 0 | size_t get_number_of_arguments() const override { return 2; } |
174 | 22 | bool is_variadic() const override { return true; } |
175 | | |
176 | 21 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
177 | 21 | return std::make_shared<DataTypeString>(); |
178 | 21 | } |
179 | | |
180 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
181 | 22 | uint32_t result, size_t input_rows_count) const override { |
182 | 22 | DCHECK(!is_column_const(*block.get_by_position(arguments[0]).column)); |
183 | | |
184 | 22 | ColumnPtr data_col = block.get_by_position(arguments[0]).column; |
185 | | |
186 | 22 | [[maybe_unused]] const auto& [right_column, right_const] = |
187 | 22 | unpack_if_const(block.get_by_position(arguments[1]).column); |
188 | 22 | auto digest_length = assert_cast<const ColumnInt32*>(right_column.get())->get_data()[0]; |
189 | | |
190 | 22 | auto res_col = ColumnString::create(); |
191 | 22 | auto& res_data = res_col->get_chars(); |
192 | 22 | auto& res_offset = res_col->get_offsets(); |
193 | 22 | res_offset.resize(input_rows_count); |
194 | | |
195 | 22 | if (digest_length == 224) { |
196 | 5 | execute_base<SHA224Digest>(data_col, input_rows_count, res_data, res_offset); |
197 | 17 | } else if (digest_length == 256) { |
198 | 6 | execute_base<SHA256Digest>(data_col, input_rows_count, res_data, res_offset); |
199 | 11 | } else if (digest_length == 384) { |
200 | 5 | execute_base<SHA384Digest>(data_col, input_rows_count, res_data, res_offset); |
201 | 6 | } else if (digest_length == 512) { |
202 | 6 | execute_base<SHA512Digest>(data_col, input_rows_count, res_data, res_offset); |
203 | 6 | } else { |
204 | 0 | return Status::InvalidArgument( |
205 | 0 | "sha2's digest length only support 224/256/384/512 but meet {}", digest_length); |
206 | 0 | } |
207 | | |
208 | 22 | block.replace_by_position(result, std::move(res_col)); |
209 | 22 | return Status::OK(); |
210 | 22 | } |
211 | | |
212 | | private: |
213 | | template <typename T> |
214 | | void execute_base(ColumnPtr data_col, int input_rows_count, ColumnString::Chars& res_data, |
215 | 22 | ColumnString::Offsets& res_offset) const { |
216 | 22 | if (const auto* str_col = check_and_get_column<ColumnString>(data_col.get())) { |
217 | 22 | vector_execute<T>(str_col, input_rows_count, res_data, res_offset); |
218 | 22 | } else if (const auto* vb_col = check_and_get_column<ColumnVarbinary>(data_col.get())) { |
219 | 0 | vector_execute<T>(vb_col, input_rows_count, res_data, res_offset); |
220 | 0 | } else { |
221 | 0 | throw Exception(ErrorCode::RUNTIME_ERROR, |
222 | 0 | "Illegal column {} of argument of function {}", data_col->get_name(), |
223 | 0 | get_name()); |
224 | 0 | } |
225 | 22 | } _ZNK5doris24FunctionStringDigestSHA212execute_baseINS_12SHA224DigestEEEvNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEiRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNS8_IjLm4096ESB_Lm16ELm15EEE Line | Count | Source | 215 | 5 | ColumnString::Offsets& res_offset) const { | 216 | 5 | if (const auto* str_col = check_and_get_column<ColumnString>(data_col.get())) { | 217 | 5 | vector_execute<T>(str_col, input_rows_count, res_data, res_offset); | 218 | 5 | } else if (const auto* vb_col = check_and_get_column<ColumnVarbinary>(data_col.get())) { | 219 | 0 | vector_execute<T>(vb_col, input_rows_count, res_data, res_offset); | 220 | 0 | } else { | 221 | 0 | throw Exception(ErrorCode::RUNTIME_ERROR, | 222 | 0 | "Illegal column {} of argument of function {}", data_col->get_name(), | 223 | 0 | get_name()); | 224 | 0 | } | 225 | 5 | } |
_ZNK5doris24FunctionStringDigestSHA212execute_baseINS_12SHA256DigestEEEvNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEiRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNS8_IjLm4096ESB_Lm16ELm15EEE Line | Count | Source | 215 | 6 | ColumnString::Offsets& res_offset) const { | 216 | 6 | if (const auto* str_col = check_and_get_column<ColumnString>(data_col.get())) { | 217 | 6 | vector_execute<T>(str_col, input_rows_count, res_data, res_offset); | 218 | 6 | } else if (const auto* vb_col = check_and_get_column<ColumnVarbinary>(data_col.get())) { | 219 | 0 | vector_execute<T>(vb_col, input_rows_count, res_data, res_offset); | 220 | 0 | } else { | 221 | 0 | throw Exception(ErrorCode::RUNTIME_ERROR, | 222 | 0 | "Illegal column {} of argument of function {}", data_col->get_name(), | 223 | 0 | get_name()); | 224 | 0 | } | 225 | 6 | } |
_ZNK5doris24FunctionStringDigestSHA212execute_baseINS_12SHA384DigestEEEvNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEiRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNS8_IjLm4096ESB_Lm16ELm15EEE Line | Count | Source | 215 | 5 | ColumnString::Offsets& res_offset) const { | 216 | 5 | if (const auto* str_col = check_and_get_column<ColumnString>(data_col.get())) { | 217 | 5 | vector_execute<T>(str_col, input_rows_count, res_data, res_offset); | 218 | 5 | } else if (const auto* vb_col = check_and_get_column<ColumnVarbinary>(data_col.get())) { | 219 | 0 | vector_execute<T>(vb_col, input_rows_count, res_data, res_offset); | 220 | 0 | } else { | 221 | 0 | throw Exception(ErrorCode::RUNTIME_ERROR, | 222 | 0 | "Illegal column {} of argument of function {}", data_col->get_name(), | 223 | 0 | get_name()); | 224 | 0 | } | 225 | 5 | } |
_ZNK5doris24FunctionStringDigestSHA212execute_baseINS_12SHA512DigestEEEvNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEiRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNS8_IjLm4096ESB_Lm16ELm15EEE Line | Count | Source | 215 | 6 | ColumnString::Offsets& res_offset) const { | 216 | 6 | if (const auto* str_col = check_and_get_column<ColumnString>(data_col.get())) { | 217 | 6 | vector_execute<T>(str_col, input_rows_count, res_data, res_offset); | 218 | 6 | } else if (const auto* vb_col = check_and_get_column<ColumnVarbinary>(data_col.get())) { | 219 | 0 | vector_execute<T>(vb_col, input_rows_count, res_data, res_offset); | 220 | 0 | } else { | 221 | 0 | throw Exception(ErrorCode::RUNTIME_ERROR, | 222 | 0 | "Illegal column {} of argument of function {}", data_col->get_name(), | 223 | 0 | get_name()); | 224 | 0 | } | 225 | 6 | } |
|
226 | | |
227 | | template <typename DigestType, typename ColumnType> |
228 | | void vector_execute(const ColumnType* col, size_t input_rows_count, |
229 | 22 | ColumnString::Chars& res_data, ColumnString::Offsets& res_offset) const { |
230 | 22 | DigestType digest; |
231 | 110 | for (size_t i = 0; i < input_rows_count; ++i) { |
232 | 88 | StringRef data_ref = col->get_data_at(i); |
233 | 88 | digest.reset(data_ref.data, data_ref.size); |
234 | 88 | std::string_view ans = digest.digest(); |
235 | | |
236 | 88 | StringOP::push_value_string(ans, i, res_data, res_offset); |
237 | 88 | } |
238 | 22 | } _ZNK5doris24FunctionStringDigestSHA214vector_executeINS_12SHA224DigestENS_9ColumnStrIjEEEEvPKT0_mRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNS8_IjLm4096ESB_Lm16ELm15EEE Line | Count | Source | 229 | 5 | ColumnString::Chars& res_data, ColumnString::Offsets& res_offset) const { | 230 | 5 | DigestType digest; | 231 | 26 | for (size_t i = 0; i < input_rows_count; ++i) { | 232 | 21 | StringRef data_ref = col->get_data_at(i); | 233 | 21 | digest.reset(data_ref.data, data_ref.size); | 234 | 21 | std::string_view ans = digest.digest(); | 235 | | | 236 | 21 | StringOP::push_value_string(ans, i, res_data, res_offset); | 237 | 21 | } | 238 | 5 | } |
Unexecuted instantiation: _ZNK5doris24FunctionStringDigestSHA214vector_executeINS_12SHA224DigestENS_15ColumnVarbinaryEEEvPKT0_mRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNS7_IjLm4096ESA_Lm16ELm15EEE _ZNK5doris24FunctionStringDigestSHA214vector_executeINS_12SHA256DigestENS_9ColumnStrIjEEEEvPKT0_mRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNS8_IjLm4096ESB_Lm16ELm15EEE Line | Count | Source | 229 | 6 | ColumnString::Chars& res_data, ColumnString::Offsets& res_offset) const { | 230 | 6 | DigestType digest; | 231 | 29 | for (size_t i = 0; i < input_rows_count; ++i) { | 232 | 23 | StringRef data_ref = col->get_data_at(i); | 233 | 23 | digest.reset(data_ref.data, data_ref.size); | 234 | 23 | std::string_view ans = digest.digest(); | 235 | | | 236 | 23 | StringOP::push_value_string(ans, i, res_data, res_offset); | 237 | 23 | } | 238 | 6 | } |
Unexecuted instantiation: _ZNK5doris24FunctionStringDigestSHA214vector_executeINS_12SHA256DigestENS_15ColumnVarbinaryEEEvPKT0_mRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNS7_IjLm4096ESA_Lm16ELm15EEE _ZNK5doris24FunctionStringDigestSHA214vector_executeINS_12SHA384DigestENS_9ColumnStrIjEEEEvPKT0_mRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNS8_IjLm4096ESB_Lm16ELm15EEE Line | Count | Source | 229 | 5 | ColumnString::Chars& res_data, ColumnString::Offsets& res_offset) const { | 230 | 5 | DigestType digest; | 231 | 26 | for (size_t i = 0; i < input_rows_count; ++i) { | 232 | 21 | StringRef data_ref = col->get_data_at(i); | 233 | 21 | digest.reset(data_ref.data, data_ref.size); | 234 | 21 | std::string_view ans = digest.digest(); | 235 | | | 236 | 21 | StringOP::push_value_string(ans, i, res_data, res_offset); | 237 | 21 | } | 238 | 5 | } |
Unexecuted instantiation: _ZNK5doris24FunctionStringDigestSHA214vector_executeINS_12SHA384DigestENS_15ColumnVarbinaryEEEvPKT0_mRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNS7_IjLm4096ESA_Lm16ELm15EEE _ZNK5doris24FunctionStringDigestSHA214vector_executeINS_12SHA512DigestENS_9ColumnStrIjEEEEvPKT0_mRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNS8_IjLm4096ESB_Lm16ELm15EEE Line | Count | Source | 229 | 6 | ColumnString::Chars& res_data, ColumnString::Offsets& res_offset) const { | 230 | 6 | DigestType digest; | 231 | 29 | for (size_t i = 0; i < input_rows_count; ++i) { | 232 | 23 | StringRef data_ref = col->get_data_at(i); | 233 | 23 | digest.reset(data_ref.data, data_ref.size); | 234 | 23 | std::string_view ans = digest.digest(); | 235 | | | 236 | 23 | StringOP::push_value_string(ans, i, res_data, res_offset); | 237 | 23 | } | 238 | 6 | } |
Unexecuted instantiation: _ZNK5doris24FunctionStringDigestSHA214vector_executeINS_12SHA512DigestENS_15ColumnVarbinaryEEEvPKT0_mRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNS7_IjLm4096ESA_Lm16ELm15EEE |
239 | | }; |
240 | | |
241 | 6 | void register_function_string_digest(SimpleFunctionFactory& factory) { |
242 | 6 | factory.register_function<FunctionStringDigestMulti<SM3Sum>>(); |
243 | 6 | factory.register_function<FunctionStringDigestMulti<MD5Sum>>(); |
244 | 6 | factory.register_function<FunctionStringDigestSHA1>(); |
245 | 6 | factory.register_function<FunctionStringDigestSHA2>(); |
246 | | |
247 | 6 | factory.register_alias(FunctionStringDigestMulti<MD5Sum>::name, "md5"); |
248 | 6 | factory.register_alias(FunctionStringDigestMulti<SM3Sum>::name, "sm3"); |
249 | 6 | factory.register_alias(FunctionStringDigestSHA1::name, "sha"); |
250 | 6 | } |
251 | | |
252 | | #include "common/compile_check_avoid_end.h" |
253 | | } // namespace doris |