be/src/exprs/function/function_ip.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 | | // This file is copied from |
18 | | // https://github.com/ClickHouse/ClickHouse/blob/master/src/Functions/FunctionsCodingIP.cpp |
19 | | // and modified by Doris |
20 | | |
21 | | #pragma once |
22 | | #include <glog/logging.h> |
23 | | |
24 | | #include <cstddef> |
25 | | #include <memory> |
26 | | |
27 | | #include "common/cast_set.h" |
28 | | #include "core/assert_cast.h" |
29 | | #include "core/block/column_with_type_and_name.h" |
30 | | #include "core/column/column.h" |
31 | | #include "core/column/column_const.h" |
32 | | #include "core/column/column_execute_util.h" |
33 | | #include "core/column/column_nullable.h" |
34 | | #include "core/column/column_string.h" |
35 | | #include "core/column/column_struct.h" |
36 | | #include "core/column/column_vector.h" |
37 | | #include "core/data_type/data_type.h" |
38 | | #include "core/data_type/data_type_ipv4.h" |
39 | | #include "core/data_type/data_type_ipv6.h" |
40 | | #include "core/data_type/data_type_nullable.h" |
41 | | #include "core/data_type/data_type_number.h" |
42 | | #include "core/data_type/data_type_string.h" |
43 | | #include "core/data_type/data_type_struct.h" |
44 | | #include "core/field.h" |
45 | | #include "core/types.h" |
46 | | #include "core/value/ip_address_cidr.h" |
47 | | #include "core/value/ipv4_value.h" |
48 | | #include "exec/common/endian.h" |
49 | | #include "exec/common/format_ip.h" |
50 | | #include "exec/common/ipv6_to_binary.h" |
51 | | #include "exprs/function/function.h" |
52 | | #include "exprs/function/function_helpers.h" |
53 | | #include "storage/index/index_reader_helper.h" |
54 | | #include "storage/index/inverted/inverted_index_iterator.h" |
55 | | |
56 | | namespace doris { |
57 | | |
58 | | class FunctionIPv4NumToString : public IFunction { |
59 | | private: |
60 | | template <PrimitiveType ArgPType> |
61 | 31 | Status execute_type(Block& block, const ColumnWithTypeAndName& argument, size_t result) const { |
62 | 31 | using ColumnType = ColumnVector<ArgPType>; |
63 | 31 | const ColumnPtr& column = argument.column; |
64 | | |
65 | 31 | const auto* col = assert_cast<const ColumnType*>(column.get()); |
66 | 31 | const typename ColumnType::Container& vec_in = col->get_data(); |
67 | 31 | auto col_res = ColumnString::create(); |
68 | | |
69 | 31 | ColumnString::Chars& vec_res = col_res->get_chars(); |
70 | 31 | ColumnString::Offsets& offsets_res = col_res->get_offsets(); |
71 | | |
72 | 31 | vec_res.resize(vec_in.size() * |
73 | 31 | (IPV4_MAX_TEXT_LENGTH + 1)); /// the longest value is: 255.255.255.255\0 |
74 | 31 | offsets_res.resize(vec_in.size()); |
75 | 31 | char* begin = reinterpret_cast<char*>(vec_res.data()); |
76 | 31 | char* pos = begin; |
77 | | |
78 | 31 | auto null_map = ColumnUInt8::create(vec_in.size(), 0); |
79 | 31 | size_t src_size = |
80 | 31 | std::min(sizeof(typename PrimitiveTypeTraits<ArgPType>::CppType), (unsigned long)4); |
81 | 445 | for (size_t i = 0; i < vec_in.size(); ++i) { |
82 | 414 | auto value = vec_in[i]; |
83 | 414 | if (value < IPV4_MIN_NUM_VALUE || value > IPV4_MAX_NUM_VALUE) { |
84 | 6 | null_map->get_data()[i] = 1; |
85 | 408 | } else { |
86 | 408 | format_ipv4(reinterpret_cast<const unsigned char*>(&vec_in[i]), src_size, pos); |
87 | 408 | } |
88 | 414 | offsets_res[i] = cast_set<uint32_t>(pos - begin); |
89 | 414 | } |
90 | | |
91 | 31 | vec_res.resize(pos - begin); |
92 | 31 | block.replace_by_position(result, |
93 | 31 | ColumnNullable::create(std::move(col_res), std::move(null_map))); |
94 | 31 | return Status::OK(); |
95 | 31 | } _ZNK5doris23FunctionIPv4NumToString12execute_typeILNS_13PrimitiveTypeE3EEENS_6StatusERNS_5BlockERKNS_21ColumnWithTypeAndNameEm Line | Count | Source | 61 | 5 | Status execute_type(Block& block, const ColumnWithTypeAndName& argument, size_t result) const { | 62 | 5 | using ColumnType = ColumnVector<ArgPType>; | 63 | 5 | const ColumnPtr& column = argument.column; | 64 | | | 65 | 5 | const auto* col = assert_cast<const ColumnType*>(column.get()); | 66 | 5 | const typename ColumnType::Container& vec_in = col->get_data(); | 67 | 5 | auto col_res = ColumnString::create(); | 68 | | | 69 | 5 | ColumnString::Chars& vec_res = col_res->get_chars(); | 70 | 5 | ColumnString::Offsets& offsets_res = col_res->get_offsets(); | 71 | | | 72 | 5 | vec_res.resize(vec_in.size() * | 73 | 5 | (IPV4_MAX_TEXT_LENGTH + 1)); /// the longest value is: 255.255.255.255\0 | 74 | 5 | offsets_res.resize(vec_in.size()); | 75 | 5 | char* begin = reinterpret_cast<char*>(vec_res.data()); | 76 | 5 | char* pos = begin; | 77 | | | 78 | 5 | auto null_map = ColumnUInt8::create(vec_in.size(), 0); | 79 | 5 | size_t src_size = | 80 | 5 | std::min(sizeof(typename PrimitiveTypeTraits<ArgPType>::CppType), (unsigned long)4); | 81 | 10 | for (size_t i = 0; i < vec_in.size(); ++i) { | 82 | 5 | auto value = vec_in[i]; | 83 | 5 | if (value < IPV4_MIN_NUM_VALUE || value > IPV4_MAX_NUM_VALUE) { | 84 | 3 | null_map->get_data()[i] = 1; | 85 | 3 | } else { | 86 | 2 | format_ipv4(reinterpret_cast<const unsigned char*>(&vec_in[i]), src_size, pos); | 87 | 2 | } | 88 | 5 | offsets_res[i] = cast_set<uint32_t>(pos - begin); | 89 | 5 | } | 90 | | | 91 | 5 | vec_res.resize(pos - begin); | 92 | 5 | block.replace_by_position(result, | 93 | 5 | ColumnNullable::create(std::move(col_res), std::move(null_map))); | 94 | 5 | return Status::OK(); | 95 | 5 | } |
Unexecuted instantiation: _ZNK5doris23FunctionIPv4NumToString12execute_typeILNS_13PrimitiveTypeE4EEENS_6StatusERNS_5BlockERKNS_21ColumnWithTypeAndNameEm _ZNK5doris23FunctionIPv4NumToString12execute_typeILNS_13PrimitiveTypeE5EEENS_6StatusERNS_5BlockERKNS_21ColumnWithTypeAndNameEm Line | Count | Source | 61 | 4 | Status execute_type(Block& block, const ColumnWithTypeAndName& argument, size_t result) const { | 62 | 4 | using ColumnType = ColumnVector<ArgPType>; | 63 | 4 | const ColumnPtr& column = argument.column; | 64 | | | 65 | 4 | const auto* col = assert_cast<const ColumnType*>(column.get()); | 66 | 4 | const typename ColumnType::Container& vec_in = col->get_data(); | 67 | 4 | auto col_res = ColumnString::create(); | 68 | | | 69 | 4 | ColumnString::Chars& vec_res = col_res->get_chars(); | 70 | 4 | ColumnString::Offsets& offsets_res = col_res->get_offsets(); | 71 | | | 72 | 4 | vec_res.resize(vec_in.size() * | 73 | 4 | (IPV4_MAX_TEXT_LENGTH + 1)); /// the longest value is: 255.255.255.255\0 | 74 | 4 | offsets_res.resize(vec_in.size()); | 75 | 4 | char* begin = reinterpret_cast<char*>(vec_res.data()); | 76 | 4 | char* pos = begin; | 77 | | | 78 | 4 | auto null_map = ColumnUInt8::create(vec_in.size(), 0); | 79 | 4 | size_t src_size = | 80 | 4 | std::min(sizeof(typename PrimitiveTypeTraits<ArgPType>::CppType), (unsigned long)4); | 81 | 8 | for (size_t i = 0; i < vec_in.size(); ++i) { | 82 | 4 | auto value = vec_in[i]; | 83 | 4 | if (value < IPV4_MIN_NUM_VALUE || value > IPV4_MAX_NUM_VALUE) { | 84 | 0 | null_map->get_data()[i] = 1; | 85 | 4 | } else { | 86 | 4 | format_ipv4(reinterpret_cast<const unsigned char*>(&vec_in[i]), src_size, pos); | 87 | 4 | } | 88 | 4 | offsets_res[i] = cast_set<uint32_t>(pos - begin); | 89 | 4 | } | 90 | | | 91 | 4 | vec_res.resize(pos - begin); | 92 | 4 | block.replace_by_position(result, | 93 | 4 | ColumnNullable::create(std::move(col_res), std::move(null_map))); | 94 | 4 | return Status::OK(); | 95 | 4 | } |
_ZNK5doris23FunctionIPv4NumToString12execute_typeILNS_13PrimitiveTypeE6EEENS_6StatusERNS_5BlockERKNS_21ColumnWithTypeAndNameEm Line | Count | Source | 61 | 22 | Status execute_type(Block& block, const ColumnWithTypeAndName& argument, size_t result) const { | 62 | 22 | using ColumnType = ColumnVector<ArgPType>; | 63 | 22 | const ColumnPtr& column = argument.column; | 64 | | | 65 | 22 | const auto* col = assert_cast<const ColumnType*>(column.get()); | 66 | 22 | const typename ColumnType::Container& vec_in = col->get_data(); | 67 | 22 | auto col_res = ColumnString::create(); | 68 | | | 69 | 22 | ColumnString::Chars& vec_res = col_res->get_chars(); | 70 | 22 | ColumnString::Offsets& offsets_res = col_res->get_offsets(); | 71 | | | 72 | 22 | vec_res.resize(vec_in.size() * | 73 | 22 | (IPV4_MAX_TEXT_LENGTH + 1)); /// the longest value is: 255.255.255.255\0 | 74 | 22 | offsets_res.resize(vec_in.size()); | 75 | 22 | char* begin = reinterpret_cast<char*>(vec_res.data()); | 76 | 22 | char* pos = begin; | 77 | | | 78 | 22 | auto null_map = ColumnUInt8::create(vec_in.size(), 0); | 79 | 22 | size_t src_size = | 80 | 22 | std::min(sizeof(typename PrimitiveTypeTraits<ArgPType>::CppType), (unsigned long)4); | 81 | 427 | for (size_t i = 0; i < vec_in.size(); ++i) { | 82 | 405 | auto value = vec_in[i]; | 83 | 405 | if (value < IPV4_MIN_NUM_VALUE || value > IPV4_MAX_NUM_VALUE) { | 84 | 3 | null_map->get_data()[i] = 1; | 85 | 402 | } else { | 86 | 402 | format_ipv4(reinterpret_cast<const unsigned char*>(&vec_in[i]), src_size, pos); | 87 | 402 | } | 88 | 405 | offsets_res[i] = cast_set<uint32_t>(pos - begin); | 89 | 405 | } | 90 | | | 91 | 22 | vec_res.resize(pos - begin); | 92 | 22 | block.replace_by_position(result, | 93 | 22 | ColumnNullable::create(std::move(col_res), std::move(null_map))); | 94 | 22 | return Status::OK(); | 95 | 22 | } |
|
96 | | |
97 | | public: |
98 | | static constexpr auto name = "ipv4_num_to_string"; |
99 | 33 | static FunctionPtr create() { return std::make_shared<FunctionIPv4NumToString>(); } |
100 | | |
101 | 1 | String get_name() const override { return name; } |
102 | | |
103 | 24 | size_t get_number_of_arguments() const override { return 1; } |
104 | | |
105 | 24 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
106 | 24 | return make_nullable(std::make_shared<DataTypeString>()); |
107 | 24 | } |
108 | | |
109 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
110 | 31 | uint32_t result, size_t input_rows_count) const override { |
111 | 31 | ColumnWithTypeAndName& argument = block.get_by_position(arguments[0]); |
112 | | |
113 | 31 | switch (argument.type->get_primitive_type()) { |
114 | 5 | case PrimitiveType::TYPE_TINYINT: |
115 | 5 | return execute_type<TYPE_TINYINT>(block, argument, result); |
116 | 0 | break; |
117 | 0 | case PrimitiveType::TYPE_SMALLINT: |
118 | 0 | return execute_type<TYPE_SMALLINT>(block, argument, result); |
119 | 0 | break; |
120 | 4 | case PrimitiveType::TYPE_INT: |
121 | 4 | return execute_type<TYPE_INT>(block, argument, result); |
122 | 0 | break; |
123 | 22 | case PrimitiveType::TYPE_BIGINT: |
124 | 22 | return execute_type<TYPE_BIGINT>(block, argument, result); |
125 | 0 | break; |
126 | 0 | default: |
127 | 0 | break; |
128 | 31 | } |
129 | | |
130 | 0 | return Status::InternalError( |
131 | 0 | "Illegal column {} of argument of function {}, expected Int8 or Int16 or Int32 or " |
132 | 0 | "Int64", |
133 | 0 | argument.name, get_name()); |
134 | 31 | } |
135 | | }; |
136 | | |
137 | | /// Since IPExceptionMode means wider scope, we use more specific name here. |
138 | | enum class IPConvertExceptionMode : uint8_t { Throw, Default, Null }; |
139 | | |
140 | 3.44k | static inline bool try_parse_ipv4(const char* begin, const char* end, Int64& result_value) { |
141 | 3.44k | return parse_ipv4_whole(begin, end, reinterpret_cast<unsigned char*>(&result_value)); |
142 | 3.44k | } |
143 | | |
144 | | template <IPConvertExceptionMode exception_mode, typename ToColumn> |
145 | 118 | ColumnPtr convert_to_ipv4(ColumnPtr column, const PaddedPODArray<UInt8>* null_map = nullptr) { |
146 | 118 | const auto* column_string = assert_cast<const ColumnString*>(column.get()); |
147 | | |
148 | 118 | size_t column_size = column_string->size(); |
149 | | |
150 | 118 | ColumnUInt8::MutablePtr col_null_map_to; |
151 | 118 | ColumnUInt8::Container* vec_null_map_to = nullptr; |
152 | | |
153 | 118 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { |
154 | 52 | col_null_map_to = ColumnUInt8::create(column_size, false); |
155 | 52 | vec_null_map_to = &col_null_map_to->get_data(); |
156 | 52 | } |
157 | | |
158 | 118 | auto col_res = ToColumn::create(column_size, 0); |
159 | 118 | auto& vec_res = col_res->get_data(); |
160 | | |
161 | 1.68k | for (size_t i = 0; i < vec_res.size(); ++i) { |
162 | 1.56k | if (null_map && (*null_map)[i]) { |
163 | 17 | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { |
164 | 1 | throw Exception( |
165 | 1 | ErrorCode::INVALID_ARGUMENT, |
166 | 1 | "Null Input, you may consider convert it to a valid default IPv4 value " |
167 | 1 | "like '0.0.0.0' first"); |
168 | 1 | } |
169 | 0 | vec_res[i] = 0; |
170 | 17 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { |
171 | 5 | (*vec_null_map_to)[i] = true; |
172 | 5 | } |
173 | 17 | continue; |
174 | 17 | } |
175 | 1.55k | const auto src = column_string->get_data_at(i); |
176 | 1.55k | bool parse_result = try_parse_ipv4(src.begin(), src.end(), vec_res[i]); |
177 | | |
178 | 1.55k | if (!parse_result) { |
179 | 526 | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { |
180 | 5 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv4 value"); |
181 | 259 | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { |
182 | 259 | vec_res[i] = 0; |
183 | 262 | } else if constexpr (exception_mode == IPConvertExceptionMode::Null) { |
184 | 262 | (*vec_null_map_to)[i] = true; |
185 | 262 | vec_res[i] = 0; |
186 | 262 | } |
187 | 526 | } |
188 | 1.55k | } |
189 | | |
190 | 118 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { |
191 | 52 | return ColumnNullable::create(std::move(col_res), std::move(col_null_map_to)); |
192 | 52 | } |
193 | 0 | return col_res; |
194 | 118 | } _ZN5doris15convert_to_ipv4ILNS_22IPConvertExceptionModeE0ENS_12ColumnVectorILNS_13PrimitiveTypeE6EEEEENS_3COWINS_7IColumnEE13immutable_ptrIS6_EES9_PKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEE Line | Count | Source | 145 | 14 | ColumnPtr convert_to_ipv4(ColumnPtr column, const PaddedPODArray<UInt8>* null_map = nullptr) { | 146 | 14 | const auto* column_string = assert_cast<const ColumnString*>(column.get()); | 147 | | | 148 | 14 | size_t column_size = column_string->size(); | 149 | | | 150 | 14 | ColumnUInt8::MutablePtr col_null_map_to; | 151 | 14 | ColumnUInt8::Container* vec_null_map_to = nullptr; | 152 | | | 153 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 154 | | col_null_map_to = ColumnUInt8::create(column_size, false); | 155 | | vec_null_map_to = &col_null_map_to->get_data(); | 156 | | } | 157 | | | 158 | 14 | auto col_res = ToColumn::create(column_size, 0); | 159 | 14 | auto& vec_res = col_res->get_data(); | 160 | | | 161 | 151 | for (size_t i = 0; i < vec_res.size(); ++i) { | 162 | 137 | if (null_map && (*null_map)[i]) { | 163 | 1 | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 164 | 1 | throw Exception( | 165 | 1 | ErrorCode::INVALID_ARGUMENT, | 166 | 1 | "Null Input, you may consider convert it to a valid default IPv4 value " | 167 | 1 | "like '0.0.0.0' first"); | 168 | 1 | } | 169 | 0 | vec_res[i] = 0; | 170 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 171 | | (*vec_null_map_to)[i] = true; | 172 | | } | 173 | 1 | continue; | 174 | 1 | } | 175 | 136 | const auto src = column_string->get_data_at(i); | 176 | 136 | bool parse_result = try_parse_ipv4(src.begin(), src.end(), vec_res[i]); | 177 | | | 178 | 136 | if (!parse_result) { | 179 | 5 | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 180 | 5 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv4 value"); | 181 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 182 | | vec_res[i] = 0; | 183 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 184 | | (*vec_null_map_to)[i] = true; | 185 | | vec_res[i] = 0; | 186 | | } | 187 | 5 | } | 188 | 136 | } | 189 | | | 190 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 191 | | return ColumnNullable::create(std::move(col_res), std::move(col_null_map_to)); | 192 | | } | 193 | 14 | return col_res; | 194 | 14 | } |
_ZN5doris15convert_to_ipv4ILNS_22IPConvertExceptionModeE1ENS_12ColumnVectorILNS_13PrimitiveTypeE6EEEEENS_3COWINS_7IColumnEE13immutable_ptrIS6_EES9_PKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEE Line | Count | Source | 145 | 52 | ColumnPtr convert_to_ipv4(ColumnPtr column, const PaddedPODArray<UInt8>* null_map = nullptr) { | 146 | 52 | const auto* column_string = assert_cast<const ColumnString*>(column.get()); | 147 | | | 148 | 52 | size_t column_size = column_string->size(); | 149 | | | 150 | 52 | ColumnUInt8::MutablePtr col_null_map_to; | 151 | 52 | ColumnUInt8::Container* vec_null_map_to = nullptr; | 152 | | | 153 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 154 | | col_null_map_to = ColumnUInt8::create(column_size, false); | 155 | | vec_null_map_to = &col_null_map_to->get_data(); | 156 | | } | 157 | | | 158 | 52 | auto col_res = ToColumn::create(column_size, 0); | 159 | 52 | auto& vec_res = col_res->get_data(); | 160 | | | 161 | 958 | for (size_t i = 0; i < vec_res.size(); ++i) { | 162 | 906 | if (null_map && (*null_map)[i]) { | 163 | | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 164 | | throw Exception( | 165 | | ErrorCode::INVALID_ARGUMENT, | 166 | | "Null Input, you may consider convert it to a valid default IPv4 value " | 167 | | "like '0.0.0.0' first"); | 168 | | } | 169 | 11 | vec_res[i] = 0; | 170 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 171 | | (*vec_null_map_to)[i] = true; | 172 | | } | 173 | 11 | continue; | 174 | 11 | } | 175 | 895 | const auto src = column_string->get_data_at(i); | 176 | 895 | bool parse_result = try_parse_ipv4(src.begin(), src.end(), vec_res[i]); | 177 | | | 178 | 895 | if (!parse_result) { | 179 | | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 180 | | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv4 value"); | 181 | 259 | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 182 | 259 | vec_res[i] = 0; | 183 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 184 | | (*vec_null_map_to)[i] = true; | 185 | | vec_res[i] = 0; | 186 | | } | 187 | 259 | } | 188 | 895 | } | 189 | | | 190 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 191 | | return ColumnNullable::create(std::move(col_res), std::move(col_null_map_to)); | 192 | | } | 193 | 52 | return col_res; | 194 | 52 | } |
_ZN5doris15convert_to_ipv4ILNS_22IPConvertExceptionModeE2ENS_12ColumnVectorILNS_13PrimitiveTypeE6EEEEENS_3COWINS_7IColumnEE13immutable_ptrIS6_EES9_PKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEE Line | Count | Source | 145 | 52 | ColumnPtr convert_to_ipv4(ColumnPtr column, const PaddedPODArray<UInt8>* null_map = nullptr) { | 146 | 52 | const auto* column_string = assert_cast<const ColumnString*>(column.get()); | 147 | | | 148 | 52 | size_t column_size = column_string->size(); | 149 | | | 150 | 52 | ColumnUInt8::MutablePtr col_null_map_to; | 151 | 52 | ColumnUInt8::Container* vec_null_map_to = nullptr; | 152 | | | 153 | 52 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 154 | 52 | col_null_map_to = ColumnUInt8::create(column_size, false); | 155 | 52 | vec_null_map_to = &col_null_map_to->get_data(); | 156 | 52 | } | 157 | | | 158 | 52 | auto col_res = ToColumn::create(column_size, 0); | 159 | 52 | auto& vec_res = col_res->get_data(); | 160 | | | 161 | 576 | for (size_t i = 0; i < vec_res.size(); ++i) { | 162 | 524 | if (null_map && (*null_map)[i]) { | 163 | | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 164 | | throw Exception( | 165 | | ErrorCode::INVALID_ARGUMENT, | 166 | | "Null Input, you may consider convert it to a valid default IPv4 value " | 167 | | "like '0.0.0.0' first"); | 168 | | } | 169 | 5 | vec_res[i] = 0; | 170 | 5 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 171 | 5 | (*vec_null_map_to)[i] = true; | 172 | 5 | } | 173 | 5 | continue; | 174 | 5 | } | 175 | 519 | const auto src = column_string->get_data_at(i); | 176 | 519 | bool parse_result = try_parse_ipv4(src.begin(), src.end(), vec_res[i]); | 177 | | | 178 | 519 | if (!parse_result) { | 179 | | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 180 | | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv4 value"); | 181 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 182 | | vec_res[i] = 0; | 183 | 262 | } else if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 184 | 262 | (*vec_null_map_to)[i] = true; | 185 | 262 | vec_res[i] = 0; | 186 | 262 | } | 187 | 262 | } | 188 | 519 | } | 189 | | | 190 | 52 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 191 | 52 | return ColumnNullable::create(std::move(col_res), std::move(col_null_map_to)); | 192 | 52 | } | 193 | 0 | return col_res; | 194 | 52 | } |
|
195 | | |
196 | | template <IPConvertExceptionMode exception_mode> |
197 | | class FunctionIPv4StringToNum : public IFunction { |
198 | | public: |
199 | | static constexpr auto name = exception_mode == IPConvertExceptionMode::Throw |
200 | | ? "ipv4_string_to_num" |
201 | | : (exception_mode == IPConvertExceptionMode::Default |
202 | | ? "ipv4_string_to_num_or_default" |
203 | | : "ipv4_string_to_num_or_null"); |
204 | | |
205 | 78 | static FunctionPtr create() { |
206 | 78 | return std::make_shared<FunctionIPv4StringToNum<exception_mode>>(); |
207 | 78 | } _ZN5doris23FunctionIPv4StringToNumILNS_22IPConvertExceptionModeE0EE6createEv Line | Count | Source | 205 | 18 | static FunctionPtr create() { | 206 | 18 | return std::make_shared<FunctionIPv4StringToNum<exception_mode>>(); | 207 | 18 | } |
_ZN5doris23FunctionIPv4StringToNumILNS_22IPConvertExceptionModeE1EE6createEv Line | Count | Source | 205 | 28 | static FunctionPtr create() { | 206 | 28 | return std::make_shared<FunctionIPv4StringToNum<exception_mode>>(); | 207 | 28 | } |
_ZN5doris23FunctionIPv4StringToNumILNS_22IPConvertExceptionModeE2EE6createEv Line | Count | Source | 205 | 32 | static FunctionPtr create() { | 206 | 32 | return std::make_shared<FunctionIPv4StringToNum<exception_mode>>(); | 207 | 32 | } |
|
208 | | |
209 | 3 | String get_name() const override { return name; }_ZNK5doris23FunctionIPv4StringToNumILNS_22IPConvertExceptionModeE0EE8get_nameB5cxx11Ev Line | Count | Source | 209 | 1 | String get_name() const override { return name; } |
_ZNK5doris23FunctionIPv4StringToNumILNS_22IPConvertExceptionModeE1EE8get_nameB5cxx11Ev Line | Count | Source | 209 | 1 | String get_name() const override { return name; } |
_ZNK5doris23FunctionIPv4StringToNumILNS_22IPConvertExceptionModeE2EE8get_nameB5cxx11Ev Line | Count | Source | 209 | 1 | String get_name() const override { return name; } |
|
210 | | |
211 | 51 | size_t get_number_of_arguments() const override { return 1; }_ZNK5doris23FunctionIPv4StringToNumILNS_22IPConvertExceptionModeE0EE23get_number_of_argumentsEv Line | Count | Source | 211 | 9 | size_t get_number_of_arguments() const override { return 1; } |
_ZNK5doris23FunctionIPv4StringToNumILNS_22IPConvertExceptionModeE1EE23get_number_of_argumentsEv Line | Count | Source | 211 | 19 | size_t get_number_of_arguments() const override { return 1; } |
_ZNK5doris23FunctionIPv4StringToNumILNS_22IPConvertExceptionModeE2EE23get_number_of_argumentsEv Line | Count | Source | 211 | 23 | size_t get_number_of_arguments() const override { return 1; } |
|
212 | | |
213 | 51 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
214 | 51 | auto result_type = std::make_shared<DataTypeInt64>(); |
215 | | |
216 | 51 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { |
217 | 23 | return make_nullable(result_type); |
218 | 23 | } |
219 | | |
220 | 0 | return result_type; |
221 | 51 | } _ZNK5doris23FunctionIPv4StringToNumILNS_22IPConvertExceptionModeE0EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 213 | 9 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 214 | 9 | auto result_type = std::make_shared<DataTypeInt64>(); | 215 | | | 216 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 217 | | return make_nullable(result_type); | 218 | | } | 219 | | | 220 | 9 | return result_type; | 221 | 9 | } |
_ZNK5doris23FunctionIPv4StringToNumILNS_22IPConvertExceptionModeE1EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 213 | 19 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 214 | 19 | auto result_type = std::make_shared<DataTypeInt64>(); | 215 | | | 216 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 217 | | return make_nullable(result_type); | 218 | | } | 219 | | | 220 | 19 | return result_type; | 221 | 19 | } |
_ZNK5doris23FunctionIPv4StringToNumILNS_22IPConvertExceptionModeE2EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 213 | 23 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 214 | 23 | auto result_type = std::make_shared<DataTypeInt64>(); | 215 | | | 216 | 23 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 217 | 23 | return make_nullable(result_type); | 218 | 23 | } | 219 | | | 220 | 0 | return result_type; | 221 | 23 | } |
|
222 | | |
223 | 169 | bool use_default_implementation_for_nulls() const override { return false; }_ZNK5doris23FunctionIPv4StringToNumILNS_22IPConvertExceptionModeE0EE36use_default_implementation_for_nullsEv Line | Count | Source | 223 | 23 | bool use_default_implementation_for_nulls() const override { return false; } |
_ZNK5doris23FunctionIPv4StringToNumILNS_22IPConvertExceptionModeE1EE36use_default_implementation_for_nullsEv Line | Count | Source | 223 | 71 | bool use_default_implementation_for_nulls() const override { return false; } |
_ZNK5doris23FunctionIPv4StringToNumILNS_22IPConvertExceptionModeE2EE36use_default_implementation_for_nullsEv Line | Count | Source | 223 | 75 | bool use_default_implementation_for_nulls() const override { return false; } |
|
224 | | |
225 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
226 | 118 | uint32_t result, size_t input_rows_count) const override { |
227 | 118 | ColumnPtr column = |
228 | 118 | block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); |
229 | 118 | ColumnPtr null_map_column; |
230 | 118 | const NullMap* null_map = nullptr; |
231 | 118 | if (const auto* column_nullable = check_and_get_column<ColumnNullable>(column.get())) { |
232 | 82 | column = column_nullable->get_nested_column_ptr(); |
233 | 82 | null_map_column = column_nullable->get_null_map_column_ptr(); |
234 | 82 | null_map = &column_nullable->get_null_map_data(); |
235 | 82 | } |
236 | | |
237 | 118 | auto col_res = convert_to_ipv4<exception_mode, ColumnInt64>(column, null_map); |
238 | | |
239 | 118 | if (null_map && exception_mode == IPConvertExceptionMode::Null) { |
240 | 40 | block.replace_by_position( |
241 | 40 | result, ColumnNullable::create(std::move(col_res), std::move(null_map_column))); |
242 | 78 | } else { |
243 | 78 | block.replace_by_position(result, std::move(col_res)); |
244 | 78 | } |
245 | 118 | return Status::OK(); |
246 | 118 | } _ZNK5doris23FunctionIPv4StringToNumILNS_22IPConvertExceptionModeE0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 226 | 14 | uint32_t result, size_t input_rows_count) const override { | 227 | 14 | ColumnPtr column = | 228 | 14 | block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); | 229 | 14 | ColumnPtr null_map_column; | 230 | 14 | const NullMap* null_map = nullptr; | 231 | 14 | if (const auto* column_nullable = check_and_get_column<ColumnNullable>(column.get())) { | 232 | 8 | column = column_nullable->get_nested_column_ptr(); | 233 | 8 | null_map_column = column_nullable->get_null_map_column_ptr(); | 234 | 8 | null_map = &column_nullable->get_null_map_data(); | 235 | 8 | } | 236 | | | 237 | 14 | auto col_res = convert_to_ipv4<exception_mode, ColumnInt64>(column, null_map); | 238 | | | 239 | 14 | if (null_map && exception_mode == IPConvertExceptionMode::Null) { | 240 | 0 | block.replace_by_position( | 241 | 0 | result, ColumnNullable::create(std::move(col_res), std::move(null_map_column))); | 242 | 14 | } else { | 243 | 14 | block.replace_by_position(result, std::move(col_res)); | 244 | 14 | } | 245 | 14 | return Status::OK(); | 246 | 14 | } |
_ZNK5doris23FunctionIPv4StringToNumILNS_22IPConvertExceptionModeE1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 226 | 52 | uint32_t result, size_t input_rows_count) const override { | 227 | 52 | ColumnPtr column = | 228 | 52 | block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); | 229 | 52 | ColumnPtr null_map_column; | 230 | 52 | const NullMap* null_map = nullptr; | 231 | 52 | if (const auto* column_nullable = check_and_get_column<ColumnNullable>(column.get())) { | 232 | 34 | column = column_nullable->get_nested_column_ptr(); | 233 | 34 | null_map_column = column_nullable->get_null_map_column_ptr(); | 234 | 34 | null_map = &column_nullable->get_null_map_data(); | 235 | 34 | } | 236 | | | 237 | 52 | auto col_res = convert_to_ipv4<exception_mode, ColumnInt64>(column, null_map); | 238 | | | 239 | 52 | if (null_map && exception_mode == IPConvertExceptionMode::Null) { | 240 | 0 | block.replace_by_position( | 241 | 0 | result, ColumnNullable::create(std::move(col_res), std::move(null_map_column))); | 242 | 52 | } else { | 243 | 52 | block.replace_by_position(result, std::move(col_res)); | 244 | 52 | } | 245 | 52 | return Status::OK(); | 246 | 52 | } |
_ZNK5doris23FunctionIPv4StringToNumILNS_22IPConvertExceptionModeE2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 226 | 52 | uint32_t result, size_t input_rows_count) const override { | 227 | 52 | ColumnPtr column = | 228 | 52 | block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); | 229 | 52 | ColumnPtr null_map_column; | 230 | 52 | const NullMap* null_map = nullptr; | 231 | 52 | if (const auto* column_nullable = check_and_get_column<ColumnNullable>(column.get())) { | 232 | 40 | column = column_nullable->get_nested_column_ptr(); | 233 | 40 | null_map_column = column_nullable->get_null_map_column_ptr(); | 234 | 40 | null_map = &column_nullable->get_null_map_data(); | 235 | 40 | } | 236 | | | 237 | 52 | auto col_res = convert_to_ipv4<exception_mode, ColumnInt64>(column, null_map); | 238 | | | 239 | 52 | if (null_map && exception_mode == IPConvertExceptionMode::Null) { | 240 | 40 | block.replace_by_position( | 241 | 40 | result, ColumnNullable::create(std::move(col_res), std::move(null_map_column))); | 242 | 40 | } else { | 243 | 12 | block.replace_by_position(result, std::move(col_res)); | 244 | 12 | } | 245 | 52 | return Status::OK(); | 246 | 52 | } |
|
247 | | }; |
248 | | |
249 | | template <typename T> |
250 | | void process_ipv6_column(const ColumnPtr& column, size_t input_rows_count, |
251 | | ColumnString::Chars& vec_res, ColumnString::Offsets& offsets_res, |
252 | 94 | ColumnUInt8::MutablePtr& null_map, unsigned char* ipv6_address_data) { |
253 | 94 | auto* begin = reinterpret_cast<char*>(vec_res.data()); |
254 | 94 | auto* pos = begin; |
255 | | |
256 | 94 | const auto* col = assert_cast<const T*>(column.get()); |
257 | | |
258 | 979 | for (size_t i = 0; i < input_rows_count; ++i) { |
259 | 885 | bool is_empty = false; |
260 | | |
261 | 885 | if constexpr (std::is_same_v<T, ColumnIPv6>) { |
262 | 26 | const auto& vec_in = col->get_data(); |
263 | 26 | memcpy(ipv6_address_data, reinterpret_cast<const unsigned char*>(&vec_in[i]), |
264 | 26 | IPV6_BINARY_LENGTH); |
265 | 859 | } else { // ColumnString |
266 | 859 | const auto str_ref = col->get_data_at(i); |
267 | 859 | const char* value = str_ref.data; |
268 | 859 | size_t value_size = str_ref.size; |
269 | | |
270 | 859 | if (value_size > IPV6_BINARY_LENGTH || value == nullptr || value_size == 0) { |
271 | 276 | is_empty = true; |
272 | 583 | } else { |
273 | 583 | memcpy(ipv6_address_data, value, value_size); |
274 | 583 | memset(ipv6_address_data + value_size, 0, IPV6_BINARY_LENGTH - value_size); |
275 | 583 | } |
276 | 859 | } |
277 | | |
278 | 885 | if (is_empty) { |
279 | 276 | null_map->get_data()[i] = 1; |
280 | 609 | } else { |
281 | 609 | if constexpr (std::is_same_v<T, ColumnIPv6>) { |
282 | | // ipv6 is little-endian byte order storage in doris |
283 | | // so parsing ipv6 in little-endian byte order |
284 | 26 | format_ipv6(ipv6_address_data, pos); |
285 | 583 | } else { |
286 | | // 16 bytes ipv6 string is big-endian byte order storage in doris |
287 | | // so transfer to little-endian firstly |
288 | 583 | std::reverse(ipv6_address_data, ipv6_address_data + IPV6_BINARY_LENGTH); |
289 | 583 | format_ipv6(ipv6_address_data, pos); |
290 | 583 | } |
291 | 609 | } |
292 | 885 | offsets_res[i] = cast_set<uint32_t>(pos - begin); |
293 | 885 | } |
294 | 94 | } _ZN5doris19process_ipv6_columnINS_12ColumnVectorILNS_13PrimitiveTypeE37EEEEEvRKNS_3COWINS_7IColumnEE13immutable_ptrIS5_EEmRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNSB_IjLm4096ESE_Lm16ELm15EEERNS6_11mutable_ptrINS1_ILS2_2EEEEEPh Line | Count | Source | 252 | 10 | ColumnUInt8::MutablePtr& null_map, unsigned char* ipv6_address_data) { | 253 | 10 | auto* begin = reinterpret_cast<char*>(vec_res.data()); | 254 | 10 | auto* pos = begin; | 255 | | | 256 | 10 | const auto* col = assert_cast<const T*>(column.get()); | 257 | | | 258 | 36 | for (size_t i = 0; i < input_rows_count; ++i) { | 259 | 26 | bool is_empty = false; | 260 | | | 261 | 26 | if constexpr (std::is_same_v<T, ColumnIPv6>) { | 262 | 26 | const auto& vec_in = col->get_data(); | 263 | 26 | memcpy(ipv6_address_data, reinterpret_cast<const unsigned char*>(&vec_in[i]), | 264 | 26 | IPV6_BINARY_LENGTH); | 265 | | } else { // ColumnString | 266 | | const auto str_ref = col->get_data_at(i); | 267 | | const char* value = str_ref.data; | 268 | | size_t value_size = str_ref.size; | 269 | | | 270 | | if (value_size > IPV6_BINARY_LENGTH || value == nullptr || value_size == 0) { | 271 | | is_empty = true; | 272 | | } else { | 273 | | memcpy(ipv6_address_data, value, value_size); | 274 | | memset(ipv6_address_data + value_size, 0, IPV6_BINARY_LENGTH - value_size); | 275 | | } | 276 | | } | 277 | | | 278 | 26 | if (is_empty) { | 279 | 0 | null_map->get_data()[i] = 1; | 280 | 26 | } else { | 281 | 26 | if constexpr (std::is_same_v<T, ColumnIPv6>) { | 282 | | // ipv6 is little-endian byte order storage in doris | 283 | | // so parsing ipv6 in little-endian byte order | 284 | 26 | format_ipv6(ipv6_address_data, pos); | 285 | | } else { | 286 | | // 16 bytes ipv6 string is big-endian byte order storage in doris | 287 | | // so transfer to little-endian firstly | 288 | | std::reverse(ipv6_address_data, ipv6_address_data + IPV6_BINARY_LENGTH); | 289 | | format_ipv6(ipv6_address_data, pos); | 290 | | } | 291 | 26 | } | 292 | 26 | offsets_res[i] = cast_set<uint32_t>(pos - begin); | 293 | 26 | } | 294 | 10 | } |
_ZN5doris19process_ipv6_columnINS_9ColumnStrIjEEEEvRKNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEmRNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEERNSA_IjLm4096ESD_Lm16ELm15EEERNS5_11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEPh Line | Count | Source | 252 | 84 | ColumnUInt8::MutablePtr& null_map, unsigned char* ipv6_address_data) { | 253 | 84 | auto* begin = reinterpret_cast<char*>(vec_res.data()); | 254 | 84 | auto* pos = begin; | 255 | | | 256 | 84 | const auto* col = assert_cast<const T*>(column.get()); | 257 | | | 258 | 943 | for (size_t i = 0; i < input_rows_count; ++i) { | 259 | 859 | bool is_empty = false; | 260 | | | 261 | | if constexpr (std::is_same_v<T, ColumnIPv6>) { | 262 | | const auto& vec_in = col->get_data(); | 263 | | memcpy(ipv6_address_data, reinterpret_cast<const unsigned char*>(&vec_in[i]), | 264 | | IPV6_BINARY_LENGTH); | 265 | 859 | } else { // ColumnString | 266 | 859 | const auto str_ref = col->get_data_at(i); | 267 | 859 | const char* value = str_ref.data; | 268 | 859 | size_t value_size = str_ref.size; | 269 | | | 270 | 859 | if (value_size > IPV6_BINARY_LENGTH || value == nullptr || value_size == 0) { | 271 | 276 | is_empty = true; | 272 | 583 | } else { | 273 | 583 | memcpy(ipv6_address_data, value, value_size); | 274 | 583 | memset(ipv6_address_data + value_size, 0, IPV6_BINARY_LENGTH - value_size); | 275 | 583 | } | 276 | 859 | } | 277 | | | 278 | 859 | if (is_empty) { | 279 | 276 | null_map->get_data()[i] = 1; | 280 | 583 | } else { | 281 | | if constexpr (std::is_same_v<T, ColumnIPv6>) { | 282 | | // ipv6 is little-endian byte order storage in doris | 283 | | // so parsing ipv6 in little-endian byte order | 284 | | format_ipv6(ipv6_address_data, pos); | 285 | 583 | } else { | 286 | | // 16 bytes ipv6 string is big-endian byte order storage in doris | 287 | | // so transfer to little-endian firstly | 288 | 583 | std::reverse(ipv6_address_data, ipv6_address_data + IPV6_BINARY_LENGTH); | 289 | 583 | format_ipv6(ipv6_address_data, pos); | 290 | 583 | } | 291 | 583 | } | 292 | 859 | offsets_res[i] = cast_set<uint32_t>(pos - begin); | 293 | 859 | } | 294 | 84 | } |
|
295 | | |
296 | | class FunctionIPv6NumToString : public IFunction { |
297 | | public: |
298 | | static constexpr auto name = "ipv6_num_to_string"; |
299 | 69 | static FunctionPtr create() { return std::make_shared<FunctionIPv6NumToString>(); } |
300 | | |
301 | 1 | String get_name() const override { return name; } |
302 | | |
303 | 60 | size_t get_number_of_arguments() const override { return 1; } |
304 | | |
305 | 60 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
306 | 60 | return make_nullable(std::make_shared<DataTypeString>()); |
307 | 60 | } |
308 | | |
309 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
310 | 94 | uint32_t result, size_t input_rows_count) const override { |
311 | 94 | const ColumnPtr& column = block.get_by_position(arguments[0]).column; |
312 | | |
313 | 94 | auto col_res = ColumnString::create(); |
314 | 94 | ColumnString::Chars& vec_res = col_res->get_chars(); |
315 | 94 | ColumnString::Offsets& offsets_res = col_res->get_offsets(); |
316 | 94 | vec_res.resize(input_rows_count * (IPV6_MAX_TEXT_LENGTH + 1)); |
317 | 94 | offsets_res.resize(input_rows_count); |
318 | | |
319 | 94 | auto null_map = ColumnUInt8::create(input_rows_count, 0); |
320 | | |
321 | 94 | unsigned char ipv6_address_data[IPV6_BINARY_LENGTH]; |
322 | | |
323 | 94 | if (check_and_get_column<ColumnIPv6>(column.get())) { |
324 | 10 | process_ipv6_column<ColumnIPv6>(column, input_rows_count, vec_res, offsets_res, |
325 | 10 | null_map, ipv6_address_data); |
326 | 84 | } else { //ColumnString |
327 | 84 | process_ipv6_column<ColumnString>(column, input_rows_count, vec_res, offsets_res, |
328 | 84 | null_map, ipv6_address_data); |
329 | 84 | } |
330 | 94 | vec_res.resize(offsets_res[offsets_res.size() - 1]); |
331 | | |
332 | 94 | block.replace_by_position(result, |
333 | 94 | ColumnNullable::create(std::move(col_res), std::move(null_map))); |
334 | 94 | return Status::OK(); |
335 | 94 | } |
336 | | }; |
337 | | |
338 | | namespace detail { |
339 | | template <IPConvertExceptionMode exception_mode, typename ToColumn = ColumnIPv6, |
340 | | typename StringColumnType> |
341 | | ColumnPtr convert_to_ipv6(const StringColumnType& string_column, |
342 | 195 | const PaddedPODArray<UInt8>* null_map = nullptr) { |
343 | 195 | const size_t column_size = string_column.size(); |
344 | | |
345 | 195 | ColumnUInt8::MutablePtr col_null_map_to; |
346 | 195 | ColumnUInt8::Container* vec_null_map_to = nullptr; |
347 | | |
348 | 195 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { |
349 | 118 | col_null_map_to = ColumnUInt8::create(column_size, false); |
350 | 118 | vec_null_map_to = &col_null_map_to->get_data(); |
351 | 118 | } |
352 | | |
353 | 195 | auto column_create = [](size_t column_size) -> typename ToColumn::MutablePtr { |
354 | 195 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { |
355 | 195 | auto column_string = ColumnString::create(); |
356 | 195 | column_string->get_chars().reserve(column_size * IPV6_BINARY_LENGTH); |
357 | 195 | column_string->get_offsets().reserve(column_size); |
358 | 195 | return column_string; |
359 | | } else { |
360 | | return ColumnIPv6::create(); |
361 | | } |
362 | 195 | }; _ZZN5doris6detail15convert_to_ipv6ILNS_22IPConvertExceptionModeE0ENS_9ColumnStrIjEES4_EENS_3COWINS_7IColumnEE13immutable_ptrIS6_EERKT1_PKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEENKUlmE_clEm Line | Count | Source | 353 | 32 | auto column_create = [](size_t column_size) -> typename ToColumn::MutablePtr { | 354 | 32 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 355 | 32 | auto column_string = ColumnString::create(); | 356 | 32 | column_string->get_chars().reserve(column_size * IPV6_BINARY_LENGTH); | 357 | 32 | column_string->get_offsets().reserve(column_size); | 358 | 32 | return column_string; | 359 | | } else { | 360 | | return ColumnIPv6::create(); | 361 | | } | 362 | 32 | }; |
_ZZN5doris6detail15convert_to_ipv6ILNS_22IPConvertExceptionModeE1ENS_9ColumnStrIjEES4_EENS_3COWINS_7IColumnEE13immutable_ptrIS6_EERKT1_PKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEENKUlmE_clEm Line | Count | Source | 353 | 45 | auto column_create = [](size_t column_size) -> typename ToColumn::MutablePtr { | 354 | 45 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 355 | 45 | auto column_string = ColumnString::create(); | 356 | 45 | column_string->get_chars().reserve(column_size * IPV6_BINARY_LENGTH); | 357 | 45 | column_string->get_offsets().reserve(column_size); | 358 | 45 | return column_string; | 359 | | } else { | 360 | | return ColumnIPv6::create(); | 361 | | } | 362 | 45 | }; |
_ZZN5doris6detail15convert_to_ipv6ILNS_22IPConvertExceptionModeE2ENS_9ColumnStrIjEES4_EENS_3COWINS_7IColumnEE13immutable_ptrIS6_EERKT1_PKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEENKUlmE_clEm Line | Count | Source | 353 | 118 | auto column_create = [](size_t column_size) -> typename ToColumn::MutablePtr { | 354 | 118 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 355 | 118 | auto column_string = ColumnString::create(); | 356 | 118 | column_string->get_chars().reserve(column_size * IPV6_BINARY_LENGTH); | 357 | 118 | column_string->get_offsets().reserve(column_size); | 358 | 118 | return column_string; | 359 | | } else { | 360 | | return ColumnIPv6::create(); | 361 | | } | 362 | 118 | }; |
|
363 | | |
364 | 195 | auto get_vector = [](auto& col_res, size_t col_size) -> decltype(auto) { |
365 | 195 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { |
366 | 195 | auto& vec_res = col_res->get_chars(); |
367 | 195 | vec_res.resize(col_size * IPV6_BINARY_LENGTH); |
368 | 195 | return (vec_res); |
369 | | } else { |
370 | | auto& vec_res = col_res->get_data(); |
371 | | vec_res.resize(col_size); |
372 | | return (vec_res); |
373 | | } |
374 | 195 | }; _ZZN5doris6detail15convert_to_ipv6ILNS_22IPConvertExceptionModeE0ENS_9ColumnStrIjEES4_EENS_3COWINS_7IColumnEE13immutable_ptrIS6_EERKT1_PKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEENKUlRT_mE_clINS7_11mutable_ptrIS4_EEEEDcSL_m Line | Count | Source | 364 | 32 | auto get_vector = [](auto& col_res, size_t col_size) -> decltype(auto) { | 365 | 32 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 366 | 32 | auto& vec_res = col_res->get_chars(); | 367 | 32 | vec_res.resize(col_size * IPV6_BINARY_LENGTH); | 368 | 32 | return (vec_res); | 369 | | } else { | 370 | | auto& vec_res = col_res->get_data(); | 371 | | vec_res.resize(col_size); | 372 | | return (vec_res); | 373 | | } | 374 | 32 | }; |
_ZZN5doris6detail15convert_to_ipv6ILNS_22IPConvertExceptionModeE1ENS_9ColumnStrIjEES4_EENS_3COWINS_7IColumnEE13immutable_ptrIS6_EERKT1_PKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEENKUlRT_mE_clINS7_11mutable_ptrIS4_EEEEDcSL_m Line | Count | Source | 364 | 45 | auto get_vector = [](auto& col_res, size_t col_size) -> decltype(auto) { | 365 | 45 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 366 | 45 | auto& vec_res = col_res->get_chars(); | 367 | 45 | vec_res.resize(col_size * IPV6_BINARY_LENGTH); | 368 | 45 | return (vec_res); | 369 | | } else { | 370 | | auto& vec_res = col_res->get_data(); | 371 | | vec_res.resize(col_size); | 372 | | return (vec_res); | 373 | | } | 374 | 45 | }; |
_ZZN5doris6detail15convert_to_ipv6ILNS_22IPConvertExceptionModeE2ENS_9ColumnStrIjEES4_EENS_3COWINS_7IColumnEE13immutable_ptrIS6_EERKT1_PKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEENKUlRT_mE_clINS7_11mutable_ptrIS4_EEEEDcSL_m Line | Count | Source | 364 | 118 | auto get_vector = [](auto& col_res, size_t col_size) -> decltype(auto) { | 365 | 118 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 366 | 118 | auto& vec_res = col_res->get_chars(); | 367 | 118 | vec_res.resize(col_size * IPV6_BINARY_LENGTH); | 368 | 118 | return (vec_res); | 369 | | } else { | 370 | | auto& vec_res = col_res->get_data(); | 371 | | vec_res.resize(col_size); | 372 | | return (vec_res); | 373 | | } | 374 | 118 | }; |
|
375 | | |
376 | 195 | auto col_res = column_create(column_size); |
377 | 195 | auto& vec_res = get_vector(col_res, column_size); |
378 | | |
379 | 195 | int offset_inc = 1; |
380 | 195 | ColumnString* column_string = nullptr; |
381 | 195 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { |
382 | 195 | offset_inc = IPV6_BINARY_LENGTH; |
383 | 195 | column_string = col_res.get(); |
384 | 195 | } |
385 | | |
386 | 2.11k | for (size_t out_offset = 0, i = 0; i < column_size; out_offset += offset_inc, ++i) { |
387 | 1.93k | const auto src = string_column.get_data_at(i); |
388 | 1.93k | const char* src_value = src.begin(); |
389 | 1.93k | const char* src_end = src.end(); |
390 | 1.93k | auto* res_value = reinterpret_cast<unsigned char*>(&vec_res[out_offset]); |
391 | | |
392 | 1.93k | if (null_map && (*null_map)[i]) { |
393 | 44 | if (exception_mode == IPConvertExceptionMode::Throw) { |
394 | 2 | throw Exception( |
395 | 2 | ErrorCode::INVALID_ARGUMENT, |
396 | 2 | "Null Input, you may consider convert it to a valid default IPv6 value " |
397 | 2 | "like '::' first"); |
398 | 42 | } else if (exception_mode == IPConvertExceptionMode::Default) { |
399 | 24 | std::fill_n(&vec_res[out_offset], offset_inc, 0); |
400 | 24 | } else { |
401 | 18 | std::fill_n(&vec_res[out_offset], offset_inc, 0); |
402 | 18 | (*vec_null_map_to)[i] = true; |
403 | 18 | } |
404 | 42 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { |
405 | 42 | DCHECK(column_string != nullptr); |
406 | 42 | column_string->get_offsets().push_back((i + 1) * IPV6_BINARY_LENGTH); |
407 | 42 | } |
408 | 42 | continue; |
409 | 44 | } |
410 | | |
411 | 1.88k | bool parse_result = false; |
412 | 1.88k | Int64 dummy_result = 0; |
413 | | |
414 | | /// For both cases below: In case of failure, the function parseIPv6 fills vec_res with zero bytes. |
415 | | |
416 | | /// If the source IP address is parsable as an IPv4 address, then transform it into a valid IPv6 address. |
417 | | /// Keeping it simple by just prefixing `::ffff:` to the IPv4 address to represent it as a valid IPv6 address. |
418 | 1.88k | size_t string_length = src.size; |
419 | 1.88k | if (string_length != 0) { |
420 | 1.87k | if (try_parse_ipv4(src_value, src_end, dummy_result)) { |
421 | 57 | map_ipv4_to_ipv6(static_cast<IPv4>(dummy_result), res_value); |
422 | 57 | parse_result = true; |
423 | 1.82k | } else { |
424 | 1.82k | parse_result = parse_ipv6_whole(src_value, src_end, res_value); |
425 | 1.82k | } |
426 | 1.87k | } |
427 | | |
428 | 1.88k | if (parse_result && string_length != 0) { |
429 | 1.04k | if constexpr (std::is_same_v<ToColumn, ColumnString>) { |
430 | | // handling 16 bytes ipv6 string in the big-endian byte order |
431 | | // is aimed at conforming to human reading habits |
432 | 1.04k | std::reverse(res_value, res_value + IPV6_BINARY_LENGTH); |
433 | 1.04k | } |
434 | 1.04k | if constexpr (std::is_same_v<ToColumn, ColumnString>) { |
435 | 1.04k | auto* column_string_res = static_cast<ColumnString*>(col_res.get()); |
436 | 1.04k | std::copy(res_value, res_value + IPV6_BINARY_LENGTH, |
437 | 1.04k | column_string_res->get_chars().begin() + i * IPV6_BINARY_LENGTH); |
438 | 1.04k | column_string_res->get_offsets().push_back((i + 1) * IPV6_BINARY_LENGTH); |
439 | | } else { |
440 | | col_res->insert_data(reinterpret_cast<const char*>(res_value), IPV6_BINARY_LENGTH); |
441 | | } |
442 | 1.04k | } else { |
443 | 841 | if (exception_mode == IPConvertExceptionMode::Throw) { |
444 | 5 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv6 value"); |
445 | 5 | } |
446 | 836 | std::fill_n(&vec_res[out_offset], offset_inc, 0); |
447 | 836 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { |
448 | 836 | auto* column_string_res = static_cast<ColumnString*>(col_res.get()); |
449 | 836 | column_string_res->get_offsets().push_back((i + 1) * IPV6_BINARY_LENGTH); |
450 | 836 | } |
451 | 836 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { |
452 | 629 | (*vec_null_map_to)[i] = true; |
453 | 629 | } |
454 | 836 | } |
455 | 1.88k | } |
456 | | |
457 | 188 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { |
458 | 118 | return ColumnNullable::create(std::move(col_res), std::move(col_null_map_to)); |
459 | 118 | } |
460 | 0 | return col_res; |
461 | 195 | } _ZN5doris6detail15convert_to_ipv6ILNS_22IPConvertExceptionModeE0ENS_9ColumnStrIjEES4_EENS_3COWINS_7IColumnEE13immutable_ptrIS6_EERKT1_PKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEE Line | Count | Source | 342 | 32 | const PaddedPODArray<UInt8>* null_map = nullptr) { | 343 | 32 | const size_t column_size = string_column.size(); | 344 | | | 345 | 32 | ColumnUInt8::MutablePtr col_null_map_to; | 346 | 32 | ColumnUInt8::Container* vec_null_map_to = nullptr; | 347 | | | 348 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 349 | | col_null_map_to = ColumnUInt8::create(column_size, false); | 350 | | vec_null_map_to = &col_null_map_to->get_data(); | 351 | | } | 352 | | | 353 | 32 | auto column_create = [](size_t column_size) -> typename ToColumn::MutablePtr { | 354 | 32 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 355 | 32 | auto column_string = ColumnString::create(); | 356 | 32 | column_string->get_chars().reserve(column_size * IPV6_BINARY_LENGTH); | 357 | 32 | column_string->get_offsets().reserve(column_size); | 358 | 32 | return column_string; | 359 | 32 | } else { | 360 | 32 | return ColumnIPv6::create(); | 361 | 32 | } | 362 | 32 | }; | 363 | | | 364 | 32 | auto get_vector = [](auto& col_res, size_t col_size) -> decltype(auto) { | 365 | 32 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 366 | 32 | auto& vec_res = col_res->get_chars(); | 367 | 32 | vec_res.resize(col_size * IPV6_BINARY_LENGTH); | 368 | 32 | return (vec_res); | 369 | 32 | } else { | 370 | 32 | auto& vec_res = col_res->get_data(); | 371 | 32 | vec_res.resize(col_size); | 372 | 32 | return (vec_res); | 373 | 32 | } | 374 | 32 | }; | 375 | | | 376 | 32 | auto col_res = column_create(column_size); | 377 | 32 | auto& vec_res = get_vector(col_res, column_size); | 378 | | | 379 | 32 | int offset_inc = 1; | 380 | 32 | ColumnString* column_string = nullptr; | 381 | 32 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 382 | 32 | offset_inc = IPV6_BINARY_LENGTH; | 383 | 32 | column_string = col_res.get(); | 384 | 32 | } | 385 | | | 386 | 161 | for (size_t out_offset = 0, i = 0; i < column_size; out_offset += offset_inc, ++i) { | 387 | 136 | const auto src = string_column.get_data_at(i); | 388 | 136 | const char* src_value = src.begin(); | 389 | 136 | const char* src_end = src.end(); | 390 | 136 | auto* res_value = reinterpret_cast<unsigned char*>(&vec_res[out_offset]); | 391 | | | 392 | 136 | if (null_map && (*null_map)[i]) { | 393 | 2 | if (exception_mode == IPConvertExceptionMode::Throw) { | 394 | 2 | throw Exception( | 395 | 2 | ErrorCode::INVALID_ARGUMENT, | 396 | 2 | "Null Input, you may consider convert it to a valid default IPv6 value " | 397 | 2 | "like '::' first"); | 398 | 2 | } else if (exception_mode == IPConvertExceptionMode::Default) { | 399 | 0 | std::fill_n(&vec_res[out_offset], offset_inc, 0); | 400 | 0 | } else { | 401 | 0 | std::fill_n(&vec_res[out_offset], offset_inc, 0); | 402 | 0 | (*vec_null_map_to)[i] = true; | 403 | 0 | } | 404 | 0 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 405 | 0 | DCHECK(column_string != nullptr); | 406 | 0 | column_string->get_offsets().push_back((i + 1) * IPV6_BINARY_LENGTH); | 407 | 0 | } | 408 | 0 | continue; | 409 | 2 | } | 410 | | | 411 | 134 | bool parse_result = false; | 412 | 134 | Int64 dummy_result = 0; | 413 | | | 414 | | /// For both cases below: In case of failure, the function parseIPv6 fills vec_res with zero bytes. | 415 | | | 416 | | /// If the source IP address is parsable as an IPv4 address, then transform it into a valid IPv6 address. | 417 | | /// Keeping it simple by just prefixing `::ffff:` to the IPv4 address to represent it as a valid IPv6 address. | 418 | 134 | size_t string_length = src.size; | 419 | 134 | if (string_length != 0) { | 420 | 134 | if (try_parse_ipv4(src_value, src_end, dummy_result)) { | 421 | 5 | map_ipv4_to_ipv6(static_cast<IPv4>(dummy_result), res_value); | 422 | 5 | parse_result = true; | 423 | 129 | } else { | 424 | 129 | parse_result = parse_ipv6_whole(src_value, src_end, res_value); | 425 | 129 | } | 426 | 134 | } | 427 | | | 428 | 134 | if (parse_result && string_length != 0) { | 429 | 129 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 430 | | // handling 16 bytes ipv6 string in the big-endian byte order | 431 | | // is aimed at conforming to human reading habits | 432 | 129 | std::reverse(res_value, res_value + IPV6_BINARY_LENGTH); | 433 | 129 | } | 434 | 129 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 435 | 129 | auto* column_string_res = static_cast<ColumnString*>(col_res.get()); | 436 | 129 | std::copy(res_value, res_value + IPV6_BINARY_LENGTH, | 437 | 129 | column_string_res->get_chars().begin() + i * IPV6_BINARY_LENGTH); | 438 | 129 | column_string_res->get_offsets().push_back((i + 1) * IPV6_BINARY_LENGTH); | 439 | | } else { | 440 | | col_res->insert_data(reinterpret_cast<const char*>(res_value), IPV6_BINARY_LENGTH); | 441 | | } | 442 | 129 | } else { | 443 | 5 | if (exception_mode == IPConvertExceptionMode::Throw) { | 444 | 5 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv6 value"); | 445 | 5 | } | 446 | 0 | std::fill_n(&vec_res[out_offset], offset_inc, 0); | 447 | 0 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 448 | 0 | auto* column_string_res = static_cast<ColumnString*>(col_res.get()); | 449 | 0 | column_string_res->get_offsets().push_back((i + 1) * IPV6_BINARY_LENGTH); | 450 | 0 | } | 451 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 452 | | (*vec_null_map_to)[i] = true; | 453 | | } | 454 | 0 | } | 455 | 134 | } | 456 | | | 457 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 458 | | return ColumnNullable::create(std::move(col_res), std::move(col_null_map_to)); | 459 | | } | 460 | 25 | return col_res; | 461 | 32 | } |
_ZN5doris6detail15convert_to_ipv6ILNS_22IPConvertExceptionModeE1ENS_9ColumnStrIjEES4_EENS_3COWINS_7IColumnEE13immutable_ptrIS6_EERKT1_PKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEE Line | Count | Source | 342 | 45 | const PaddedPODArray<UInt8>* null_map = nullptr) { | 343 | 45 | const size_t column_size = string_column.size(); | 344 | | | 345 | 45 | ColumnUInt8::MutablePtr col_null_map_to; | 346 | 45 | ColumnUInt8::Container* vec_null_map_to = nullptr; | 347 | | | 348 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 349 | | col_null_map_to = ColumnUInt8::create(column_size, false); | 350 | | vec_null_map_to = &col_null_map_to->get_data(); | 351 | | } | 352 | | | 353 | 45 | auto column_create = [](size_t column_size) -> typename ToColumn::MutablePtr { | 354 | 45 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 355 | 45 | auto column_string = ColumnString::create(); | 356 | 45 | column_string->get_chars().reserve(column_size * IPV6_BINARY_LENGTH); | 357 | 45 | column_string->get_offsets().reserve(column_size); | 358 | 45 | return column_string; | 359 | 45 | } else { | 360 | 45 | return ColumnIPv6::create(); | 361 | 45 | } | 362 | 45 | }; | 363 | | | 364 | 45 | auto get_vector = [](auto& col_res, size_t col_size) -> decltype(auto) { | 365 | 45 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 366 | 45 | auto& vec_res = col_res->get_chars(); | 367 | 45 | vec_res.resize(col_size * IPV6_BINARY_LENGTH); | 368 | 45 | return (vec_res); | 369 | 45 | } else { | 370 | 45 | auto& vec_res = col_res->get_data(); | 371 | 45 | vec_res.resize(col_size); | 372 | 45 | return (vec_res); | 373 | 45 | } | 374 | 45 | }; | 375 | | | 376 | 45 | auto col_res = column_create(column_size); | 377 | 45 | auto& vec_res = get_vector(col_res, column_size); | 378 | | | 379 | 45 | int offset_inc = 1; | 380 | 45 | ColumnString* column_string = nullptr; | 381 | 45 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 382 | 45 | offset_inc = IPV6_BINARY_LENGTH; | 383 | 45 | column_string = col_res.get(); | 384 | 45 | } | 385 | | | 386 | 855 | for (size_t out_offset = 0, i = 0; i < column_size; out_offset += offset_inc, ++i) { | 387 | 810 | const auto src = string_column.get_data_at(i); | 388 | 810 | const char* src_value = src.begin(); | 389 | 810 | const char* src_end = src.end(); | 390 | 810 | auto* res_value = reinterpret_cast<unsigned char*>(&vec_res[out_offset]); | 391 | | | 392 | 810 | if (null_map && (*null_map)[i]) { | 393 | 24 | if (exception_mode == IPConvertExceptionMode::Throw) { | 394 | 0 | throw Exception( | 395 | 0 | ErrorCode::INVALID_ARGUMENT, | 396 | 0 | "Null Input, you may consider convert it to a valid default IPv6 value " | 397 | 0 | "like '::' first"); | 398 | 24 | } else if (exception_mode == IPConvertExceptionMode::Default) { | 399 | 24 | std::fill_n(&vec_res[out_offset], offset_inc, 0); | 400 | 24 | } else { | 401 | 0 | std::fill_n(&vec_res[out_offset], offset_inc, 0); | 402 | 0 | (*vec_null_map_to)[i] = true; | 403 | 0 | } | 404 | 24 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 405 | 24 | DCHECK(column_string != nullptr); | 406 | 24 | column_string->get_offsets().push_back((i + 1) * IPV6_BINARY_LENGTH); | 407 | 24 | } | 408 | 24 | continue; | 409 | 24 | } | 410 | | | 411 | 786 | bool parse_result = false; | 412 | 786 | Int64 dummy_result = 0; | 413 | | | 414 | | /// For both cases below: In case of failure, the function parseIPv6 fills vec_res with zero bytes. | 415 | | | 416 | | /// If the source IP address is parsable as an IPv4 address, then transform it into a valid IPv6 address. | 417 | | /// Keeping it simple by just prefixing `::ffff:` to the IPv4 address to represent it as a valid IPv6 address. | 418 | 786 | size_t string_length = src.size; | 419 | 786 | if (string_length != 0) { | 420 | 786 | if (try_parse_ipv4(src_value, src_end, dummy_result)) { | 421 | 2 | map_ipv4_to_ipv6(static_cast<IPv4>(dummy_result), res_value); | 422 | 2 | parse_result = true; | 423 | 784 | } else { | 424 | 784 | parse_result = parse_ipv6_whole(src_value, src_end, res_value); | 425 | 784 | } | 426 | 786 | } | 427 | | | 428 | 786 | if (parse_result && string_length != 0) { | 429 | 579 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 430 | | // handling 16 bytes ipv6 string in the big-endian byte order | 431 | | // is aimed at conforming to human reading habits | 432 | 579 | std::reverse(res_value, res_value + IPV6_BINARY_LENGTH); | 433 | 579 | } | 434 | 579 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 435 | 579 | auto* column_string_res = static_cast<ColumnString*>(col_res.get()); | 436 | 579 | std::copy(res_value, res_value + IPV6_BINARY_LENGTH, | 437 | 579 | column_string_res->get_chars().begin() + i * IPV6_BINARY_LENGTH); | 438 | 579 | column_string_res->get_offsets().push_back((i + 1) * IPV6_BINARY_LENGTH); | 439 | | } else { | 440 | | col_res->insert_data(reinterpret_cast<const char*>(res_value), IPV6_BINARY_LENGTH); | 441 | | } | 442 | 579 | } else { | 443 | 207 | if (exception_mode == IPConvertExceptionMode::Throw) { | 444 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv6 value"); | 445 | 0 | } | 446 | 207 | std::fill_n(&vec_res[out_offset], offset_inc, 0); | 447 | 207 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 448 | 207 | auto* column_string_res = static_cast<ColumnString*>(col_res.get()); | 449 | 207 | column_string_res->get_offsets().push_back((i + 1) * IPV6_BINARY_LENGTH); | 450 | 207 | } | 451 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 452 | | (*vec_null_map_to)[i] = true; | 453 | | } | 454 | 207 | } | 455 | 786 | } | 456 | | | 457 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 458 | | return ColumnNullable::create(std::move(col_res), std::move(col_null_map_to)); | 459 | | } | 460 | 45 | return col_res; | 461 | 45 | } |
_ZN5doris6detail15convert_to_ipv6ILNS_22IPConvertExceptionModeE2ENS_9ColumnStrIjEES4_EENS_3COWINS_7IColumnEE13immutable_ptrIS6_EERKT1_PKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEE Line | Count | Source | 342 | 118 | const PaddedPODArray<UInt8>* null_map = nullptr) { | 343 | 118 | const size_t column_size = string_column.size(); | 344 | | | 345 | 118 | ColumnUInt8::MutablePtr col_null_map_to; | 346 | 118 | ColumnUInt8::Container* vec_null_map_to = nullptr; | 347 | | | 348 | 118 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 349 | 118 | col_null_map_to = ColumnUInt8::create(column_size, false); | 350 | 118 | vec_null_map_to = &col_null_map_to->get_data(); | 351 | 118 | } | 352 | | | 353 | 118 | auto column_create = [](size_t column_size) -> typename ToColumn::MutablePtr { | 354 | 118 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 355 | 118 | auto column_string = ColumnString::create(); | 356 | 118 | column_string->get_chars().reserve(column_size * IPV6_BINARY_LENGTH); | 357 | 118 | column_string->get_offsets().reserve(column_size); | 358 | 118 | return column_string; | 359 | 118 | } else { | 360 | 118 | return ColumnIPv6::create(); | 361 | 118 | } | 362 | 118 | }; | 363 | | | 364 | 118 | auto get_vector = [](auto& col_res, size_t col_size) -> decltype(auto) { | 365 | 118 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 366 | 118 | auto& vec_res = col_res->get_chars(); | 367 | 118 | vec_res.resize(col_size * IPV6_BINARY_LENGTH); | 368 | 118 | return (vec_res); | 369 | 118 | } else { | 370 | 118 | auto& vec_res = col_res->get_data(); | 371 | 118 | vec_res.resize(col_size); | 372 | 118 | return (vec_res); | 373 | 118 | } | 374 | 118 | }; | 375 | | | 376 | 118 | auto col_res = column_create(column_size); | 377 | 118 | auto& vec_res = get_vector(col_res, column_size); | 378 | | | 379 | 118 | int offset_inc = 1; | 380 | 118 | ColumnString* column_string = nullptr; | 381 | 118 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 382 | 118 | offset_inc = IPV6_BINARY_LENGTH; | 383 | 118 | column_string = col_res.get(); | 384 | 118 | } | 385 | | | 386 | 1.10k | for (size_t out_offset = 0, i = 0; i < column_size; out_offset += offset_inc, ++i) { | 387 | 985 | const auto src = string_column.get_data_at(i); | 388 | 985 | const char* src_value = src.begin(); | 389 | 985 | const char* src_end = src.end(); | 390 | 985 | auto* res_value = reinterpret_cast<unsigned char*>(&vec_res[out_offset]); | 391 | | | 392 | 985 | if (null_map && (*null_map)[i]) { | 393 | 18 | if (exception_mode == IPConvertExceptionMode::Throw) { | 394 | 0 | throw Exception( | 395 | 0 | ErrorCode::INVALID_ARGUMENT, | 396 | 0 | "Null Input, you may consider convert it to a valid default IPv6 value " | 397 | 0 | "like '::' first"); | 398 | 18 | } else if (exception_mode == IPConvertExceptionMode::Default) { | 399 | 0 | std::fill_n(&vec_res[out_offset], offset_inc, 0); | 400 | 18 | } else { | 401 | 18 | std::fill_n(&vec_res[out_offset], offset_inc, 0); | 402 | 18 | (*vec_null_map_to)[i] = true; | 403 | 18 | } | 404 | 18 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 405 | 18 | DCHECK(column_string != nullptr); | 406 | 18 | column_string->get_offsets().push_back((i + 1) * IPV6_BINARY_LENGTH); | 407 | 18 | } | 408 | 18 | continue; | 409 | 18 | } | 410 | | | 411 | 967 | bool parse_result = false; | 412 | 967 | Int64 dummy_result = 0; | 413 | | | 414 | | /// For both cases below: In case of failure, the function parseIPv6 fills vec_res with zero bytes. | 415 | | | 416 | | /// If the source IP address is parsable as an IPv4 address, then transform it into a valid IPv6 address. | 417 | | /// Keeping it simple by just prefixing `::ffff:` to the IPv4 address to represent it as a valid IPv6 address. | 418 | 967 | size_t string_length = src.size; | 419 | 967 | if (string_length != 0) { | 420 | 959 | if (try_parse_ipv4(src_value, src_end, dummy_result)) { | 421 | 50 | map_ipv4_to_ipv6(static_cast<IPv4>(dummy_result), res_value); | 422 | 50 | parse_result = true; | 423 | 909 | } else { | 424 | 909 | parse_result = parse_ipv6_whole(src_value, src_end, res_value); | 425 | 909 | } | 426 | 959 | } | 427 | | | 428 | 967 | if (parse_result && string_length != 0) { | 429 | 338 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 430 | | // handling 16 bytes ipv6 string in the big-endian byte order | 431 | | // is aimed at conforming to human reading habits | 432 | 338 | std::reverse(res_value, res_value + IPV6_BINARY_LENGTH); | 433 | 338 | } | 434 | 338 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 435 | 338 | auto* column_string_res = static_cast<ColumnString*>(col_res.get()); | 436 | 338 | std::copy(res_value, res_value + IPV6_BINARY_LENGTH, | 437 | 338 | column_string_res->get_chars().begin() + i * IPV6_BINARY_LENGTH); | 438 | 338 | column_string_res->get_offsets().push_back((i + 1) * IPV6_BINARY_LENGTH); | 439 | | } else { | 440 | | col_res->insert_data(reinterpret_cast<const char*>(res_value), IPV6_BINARY_LENGTH); | 441 | | } | 442 | 629 | } else { | 443 | 629 | if (exception_mode == IPConvertExceptionMode::Throw) { | 444 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv6 value"); | 445 | 0 | } | 446 | 629 | std::fill_n(&vec_res[out_offset], offset_inc, 0); | 447 | 629 | if constexpr (std::is_same_v<ToColumn, ColumnString>) { | 448 | 629 | auto* column_string_res = static_cast<ColumnString*>(col_res.get()); | 449 | 629 | column_string_res->get_offsets().push_back((i + 1) * IPV6_BINARY_LENGTH); | 450 | 629 | } | 451 | 629 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 452 | 629 | (*vec_null_map_to)[i] = true; | 453 | 629 | } | 454 | 629 | } | 455 | 967 | } | 456 | | | 457 | 118 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 458 | 118 | return ColumnNullable::create(std::move(col_res), std::move(col_null_map_to)); | 459 | 118 | } | 460 | 0 | return col_res; | 461 | 118 | } |
|
462 | | } // namespace detail |
463 | | |
464 | | template <IPConvertExceptionMode exception_mode, typename ToColumn = ColumnIPv6> |
465 | 194 | ColumnPtr convert_to_ipv6(ColumnPtr column, const PaddedPODArray<UInt8>* null_map = nullptr) { |
466 | 194 | const auto* column_input_string = assert_cast<const ColumnString*>(column.get()); |
467 | 194 | auto result = detail::convert_to_ipv6<exception_mode, ToColumn>(*column_input_string, null_map); |
468 | 194 | return result; |
469 | 194 | } _ZN5doris15convert_to_ipv6ILNS_22IPConvertExceptionModeE0ENS_9ColumnStrIjEEEENS_3COWINS_7IColumnEE13immutable_ptrIS5_EES8_PKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEE Line | Count | Source | 465 | 32 | ColumnPtr convert_to_ipv6(ColumnPtr column, const PaddedPODArray<UInt8>* null_map = nullptr) { | 466 | 32 | const auto* column_input_string = assert_cast<const ColumnString*>(column.get()); | 467 | 32 | auto result = detail::convert_to_ipv6<exception_mode, ToColumn>(*column_input_string, null_map); | 468 | 32 | return result; | 469 | 32 | } |
_ZN5doris15convert_to_ipv6ILNS_22IPConvertExceptionModeE1ENS_9ColumnStrIjEEEENS_3COWINS_7IColumnEE13immutable_ptrIS5_EES8_PKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEE Line | Count | Source | 465 | 45 | ColumnPtr convert_to_ipv6(ColumnPtr column, const PaddedPODArray<UInt8>* null_map = nullptr) { | 466 | 45 | const auto* column_input_string = assert_cast<const ColumnString*>(column.get()); | 467 | 45 | auto result = detail::convert_to_ipv6<exception_mode, ToColumn>(*column_input_string, null_map); | 468 | 45 | return result; | 469 | 45 | } |
_ZN5doris15convert_to_ipv6ILNS_22IPConvertExceptionModeE2ENS_9ColumnStrIjEEEENS_3COWINS_7IColumnEE13immutable_ptrIS5_EES8_PKNS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEE Line | Count | Source | 465 | 117 | ColumnPtr convert_to_ipv6(ColumnPtr column, const PaddedPODArray<UInt8>* null_map = nullptr) { | 466 | 117 | const auto* column_input_string = assert_cast<const ColumnString*>(column.get()); | 467 | 117 | auto result = detail::convert_to_ipv6<exception_mode, ToColumn>(*column_input_string, null_map); | 468 | 117 | return result; | 469 | 117 | } |
|
470 | | |
471 | | template <IPConvertExceptionMode exception_mode> |
472 | | class FunctionIPv6StringToNum : public IFunction { |
473 | | public: |
474 | | static constexpr auto name = exception_mode == IPConvertExceptionMode::Throw |
475 | | ? "ipv6_string_to_num" |
476 | | : (exception_mode == IPConvertExceptionMode::Default |
477 | | ? "ipv6_string_to_num_or_default" |
478 | | : "ipv6_string_to_num_or_null"); |
479 | | |
480 | 154 | static FunctionPtr create() { |
481 | 154 | return std::make_shared<FunctionIPv6StringToNum<exception_mode>>(); |
482 | 154 | } _ZN5doris23FunctionIPv6StringToNumILNS_22IPConvertExceptionModeE0EE6createEv Line | Count | Source | 480 | 36 | static FunctionPtr create() { | 481 | 36 | return std::make_shared<FunctionIPv6StringToNum<exception_mode>>(); | 482 | 36 | } |
_ZN5doris23FunctionIPv6StringToNumILNS_22IPConvertExceptionModeE1EE6createEv Line | Count | Source | 480 | 30 | static FunctionPtr create() { | 481 | 30 | return std::make_shared<FunctionIPv6StringToNum<exception_mode>>(); | 482 | 30 | } |
_ZN5doris23FunctionIPv6StringToNumILNS_22IPConvertExceptionModeE2EE6createEv Line | Count | Source | 480 | 88 | static FunctionPtr create() { | 481 | 88 | return std::make_shared<FunctionIPv6StringToNum<exception_mode>>(); | 482 | 88 | } |
|
483 | | |
484 | 3 | String get_name() const override { return name; }_ZNK5doris23FunctionIPv6StringToNumILNS_22IPConvertExceptionModeE0EE8get_nameB5cxx11Ev Line | Count | Source | 484 | 1 | String get_name() const override { return name; } |
_ZNK5doris23FunctionIPv6StringToNumILNS_22IPConvertExceptionModeE1EE8get_nameB5cxx11Ev Line | Count | Source | 484 | 1 | String get_name() const override { return name; } |
_ZNK5doris23FunctionIPv6StringToNumILNS_22IPConvertExceptionModeE2EE8get_nameB5cxx11Ev Line | Count | Source | 484 | 1 | String get_name() const override { return name; } |
|
485 | | |
486 | 127 | size_t get_number_of_arguments() const override { return 1; }_ZNK5doris23FunctionIPv6StringToNumILNS_22IPConvertExceptionModeE0EE23get_number_of_argumentsEv Line | Count | Source | 486 | 27 | size_t get_number_of_arguments() const override { return 1; } |
_ZNK5doris23FunctionIPv6StringToNumILNS_22IPConvertExceptionModeE1EE23get_number_of_argumentsEv Line | Count | Source | 486 | 21 | size_t get_number_of_arguments() const override { return 1; } |
_ZNK5doris23FunctionIPv6StringToNumILNS_22IPConvertExceptionModeE2EE23get_number_of_argumentsEv Line | Count | Source | 486 | 79 | size_t get_number_of_arguments() const override { return 1; } |
|
487 | | |
488 | 321 | bool use_default_implementation_for_nulls() const override { return false; }_ZNK5doris23FunctionIPv6StringToNumILNS_22IPConvertExceptionModeE0EE36use_default_implementation_for_nullsEv Line | Count | Source | 488 | 59 | bool use_default_implementation_for_nulls() const override { return false; } |
_ZNK5doris23FunctionIPv6StringToNumILNS_22IPConvertExceptionModeE1EE36use_default_implementation_for_nullsEv Line | Count | Source | 488 | 65 | bool use_default_implementation_for_nulls() const override { return false; } |
_ZNK5doris23FunctionIPv6StringToNumILNS_22IPConvertExceptionModeE2EE36use_default_implementation_for_nullsEv Line | Count | Source | 488 | 197 | bool use_default_implementation_for_nulls() const override { return false; } |
|
489 | | |
490 | 127 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
491 | 127 | auto result_type = std::make_shared<DataTypeString>(); |
492 | | |
493 | 127 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { |
494 | 79 | return make_nullable(result_type); |
495 | 79 | } |
496 | | |
497 | 0 | return result_type; |
498 | 127 | } _ZNK5doris23FunctionIPv6StringToNumILNS_22IPConvertExceptionModeE0EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 490 | 27 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 491 | 27 | auto result_type = std::make_shared<DataTypeString>(); | 492 | | | 493 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 494 | | return make_nullable(result_type); | 495 | | } | 496 | | | 497 | 27 | return result_type; | 498 | 27 | } |
_ZNK5doris23FunctionIPv6StringToNumILNS_22IPConvertExceptionModeE1EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 490 | 21 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 491 | 21 | auto result_type = std::make_shared<DataTypeString>(); | 492 | | | 493 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 494 | | return make_nullable(result_type); | 495 | | } | 496 | | | 497 | 21 | return result_type; | 498 | 21 | } |
_ZNK5doris23FunctionIPv6StringToNumILNS_22IPConvertExceptionModeE2EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 490 | 79 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 491 | 79 | auto result_type = std::make_shared<DataTypeString>(); | 492 | | | 493 | 79 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 494 | 79 | return make_nullable(result_type); | 495 | 79 | } | 496 | | | 497 | 0 | return result_type; | 498 | 79 | } |
|
499 | | |
500 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
501 | 193 | uint32_t result, size_t input_rows_count) const override { |
502 | 193 | ColumnPtr column = |
503 | 193 | block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); |
504 | 193 | ColumnPtr null_map_column; |
505 | 193 | const NullMap* null_map = nullptr; |
506 | | |
507 | 193 | if (const auto* column_nullable = check_and_get_column<ColumnNullable>(column.get())) { |
508 | 92 | column = column_nullable->get_nested_column_ptr(); |
509 | 92 | null_map_column = column_nullable->get_null_map_column_ptr(); |
510 | 92 | null_map = &column_nullable->get_null_map_data(); |
511 | 92 | } |
512 | | |
513 | 193 | auto col_res = convert_to_ipv6<exception_mode, ColumnString>(column, null_map); |
514 | | |
515 | 193 | if (null_map && exception_mode == IPConvertExceptionMode::Null) { |
516 | 60 | block.replace_by_position( |
517 | 60 | result, ColumnNullable::create(std::move(col_res), std::move(null_map_column))); |
518 | 133 | } else { |
519 | 133 | block.replace_by_position(result, std::move(col_res)); |
520 | 133 | } |
521 | 193 | return Status::OK(); |
522 | 193 | } _ZNK5doris23FunctionIPv6StringToNumILNS_22IPConvertExceptionModeE0EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 501 | 32 | uint32_t result, size_t input_rows_count) const override { | 502 | 32 | ColumnPtr column = | 503 | 32 | block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); | 504 | 32 | ColumnPtr null_map_column; | 505 | 32 | const NullMap* null_map = nullptr; | 506 | | | 507 | 32 | if (const auto* column_nullable = check_and_get_column<ColumnNullable>(column.get())) { | 508 | 10 | column = column_nullable->get_nested_column_ptr(); | 509 | 10 | null_map_column = column_nullable->get_null_map_column_ptr(); | 510 | 10 | null_map = &column_nullable->get_null_map_data(); | 511 | 10 | } | 512 | | | 513 | 32 | auto col_res = convert_to_ipv6<exception_mode, ColumnString>(column, null_map); | 514 | | | 515 | 32 | if (null_map && exception_mode == IPConvertExceptionMode::Null) { | 516 | 0 | block.replace_by_position( | 517 | 0 | result, ColumnNullable::create(std::move(col_res), std::move(null_map_column))); | 518 | 32 | } else { | 519 | 32 | block.replace_by_position(result, std::move(col_res)); | 520 | 32 | } | 521 | 32 | return Status::OK(); | 522 | 32 | } |
_ZNK5doris23FunctionIPv6StringToNumILNS_22IPConvertExceptionModeE1EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 501 | 44 | uint32_t result, size_t input_rows_count) const override { | 502 | 44 | ColumnPtr column = | 503 | 44 | block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); | 504 | 44 | ColumnPtr null_map_column; | 505 | 44 | const NullMap* null_map = nullptr; | 506 | | | 507 | 44 | if (const auto* column_nullable = check_and_get_column<ColumnNullable>(column.get())) { | 508 | 22 | column = column_nullable->get_nested_column_ptr(); | 509 | 22 | null_map_column = column_nullable->get_null_map_column_ptr(); | 510 | 22 | null_map = &column_nullable->get_null_map_data(); | 511 | 22 | } | 512 | | | 513 | 44 | auto col_res = convert_to_ipv6<exception_mode, ColumnString>(column, null_map); | 514 | | | 515 | 44 | if (null_map && exception_mode == IPConvertExceptionMode::Null) { | 516 | 0 | block.replace_by_position( | 517 | 0 | result, ColumnNullable::create(std::move(col_res), std::move(null_map_column))); | 518 | 44 | } else { | 519 | 44 | block.replace_by_position(result, std::move(col_res)); | 520 | 44 | } | 521 | 44 | return Status::OK(); | 522 | 44 | } |
_ZNK5doris23FunctionIPv6StringToNumILNS_22IPConvertExceptionModeE2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 501 | 117 | uint32_t result, size_t input_rows_count) const override { | 502 | 117 | ColumnPtr column = | 503 | 117 | block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); | 504 | 117 | ColumnPtr null_map_column; | 505 | 117 | const NullMap* null_map = nullptr; | 506 | | | 507 | 117 | if (const auto* column_nullable = check_and_get_column<ColumnNullable>(column.get())) { | 508 | 60 | column = column_nullable->get_nested_column_ptr(); | 509 | 60 | null_map_column = column_nullable->get_null_map_column_ptr(); | 510 | 60 | null_map = &column_nullable->get_null_map_data(); | 511 | 60 | } | 512 | | | 513 | 117 | auto col_res = convert_to_ipv6<exception_mode, ColumnString>(column, null_map); | 514 | | | 515 | 117 | if (null_map && exception_mode == IPConvertExceptionMode::Null) { | 516 | 60 | block.replace_by_position( | 517 | 60 | result, ColumnNullable::create(std::move(col_res), std::move(null_map_column))); | 518 | 60 | } else { | 519 | 57 | block.replace_by_position(result, std::move(col_res)); | 520 | 57 | } | 521 | 117 | return Status::OK(); | 522 | 117 | } |
|
523 | | }; |
524 | | |
525 | | template <typename Type> |
526 | | class FunctionIsIPString : public IFunction { |
527 | | static_assert(std::is_same_v<Type, IPv4> || std::is_same_v<Type, IPv6>); |
528 | | |
529 | | public: |
530 | | static constexpr auto name = std::is_same_v<Type, IPv4> ? "is_ipv4_string" : "is_ipv6_string"; |
531 | 58 | static FunctionPtr create() { return std::make_shared<FunctionIsIPString<Type>>(); }_ZN5doris18FunctionIsIPStringIjE6createEv Line | Count | Source | 531 | 28 | static FunctionPtr create() { return std::make_shared<FunctionIsIPString<Type>>(); } |
_ZN5doris18FunctionIsIPStringIoE6createEv Line | Count | Source | 531 | 30 | static FunctionPtr create() { return std::make_shared<FunctionIsIPString<Type>>(); } |
|
532 | | |
533 | 2 | String get_name() const override { return name; }_ZNK5doris18FunctionIsIPStringIjE8get_nameB5cxx11Ev Line | Count | Source | 533 | 1 | String get_name() const override { return name; } |
_ZNK5doris18FunctionIsIPStringIoE8get_nameB5cxx11Ev Line | Count | Source | 533 | 1 | String get_name() const override { return name; } |
|
534 | | |
535 | 40 | size_t get_number_of_arguments() const override { return 1; }_ZNK5doris18FunctionIsIPStringIjE23get_number_of_argumentsEv Line | Count | Source | 535 | 19 | size_t get_number_of_arguments() const override { return 1; } |
_ZNK5doris18FunctionIsIPStringIoE23get_number_of_argumentsEv Line | Count | Source | 535 | 21 | size_t get_number_of_arguments() const override { return 1; } |
|
536 | | |
537 | 40 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
538 | 40 | return std::make_shared<DataTypeUInt8>(); |
539 | 40 | } _ZNK5doris18FunctionIsIPStringIjE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS6_EE Line | Count | Source | 537 | 19 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 538 | 19 | return std::make_shared<DataTypeUInt8>(); | 539 | 19 | } |
_ZNK5doris18FunctionIsIPStringIoE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS6_EE Line | Count | Source | 537 | 21 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 538 | 21 | return std::make_shared<DataTypeUInt8>(); | 539 | 21 | } |
|
540 | | |
541 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
542 | 96 | uint32_t result, size_t input_rows_count) const override { |
543 | 96 | const auto& addr_column_with_type_and_name = block.get_by_position(arguments[0]); |
544 | 96 | const ColumnPtr& addr_column = addr_column_with_type_and_name.column; |
545 | 96 | const auto* str_addr_column = assert_cast<const ColumnString*>(addr_column.get()); |
546 | 96 | auto col_res = ColumnUInt8::create(input_rows_count, 0); |
547 | 96 | auto& col_res_data = col_res->get_data(); |
548 | | |
549 | 1.73k | for (size_t i = 0; i < input_rows_count; ++i) { |
550 | 1.63k | if constexpr (std::is_same_v<Type, IPv4>) { |
551 | 816 | StringRef ipv4_str = str_addr_column->get_data_at(i); |
552 | 816 | if (IPv4Value::is_valid_string(ipv4_str.data, ipv4_str.size)) { |
553 | 203 | col_res_data[i] = 1; |
554 | 203 | } |
555 | 818 | } else { |
556 | 818 | StringRef ipv6_str = str_addr_column->get_data_at(i); |
557 | 818 | if (IPv6Value::is_valid_string(ipv6_str.data, ipv6_str.size)) { |
558 | 202 | col_res_data[i] = 1; |
559 | 202 | } |
560 | 818 | } |
561 | 1.63k | } |
562 | | |
563 | 96 | block.replace_by_position(result, std::move(col_res)); |
564 | 96 | return Status::OK(); |
565 | 96 | } _ZNK5doris18FunctionIsIPStringIjE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 542 | 47 | uint32_t result, size_t input_rows_count) const override { | 543 | 47 | const auto& addr_column_with_type_and_name = block.get_by_position(arguments[0]); | 544 | 47 | const ColumnPtr& addr_column = addr_column_with_type_and_name.column; | 545 | 47 | const auto* str_addr_column = assert_cast<const ColumnString*>(addr_column.get()); | 546 | 47 | auto col_res = ColumnUInt8::create(input_rows_count, 0); | 547 | 47 | auto& col_res_data = col_res->get_data(); | 548 | | | 549 | 863 | for (size_t i = 0; i < input_rows_count; ++i) { | 550 | 816 | if constexpr (std::is_same_v<Type, IPv4>) { | 551 | 816 | StringRef ipv4_str = str_addr_column->get_data_at(i); | 552 | 816 | if (IPv4Value::is_valid_string(ipv4_str.data, ipv4_str.size)) { | 553 | 203 | col_res_data[i] = 1; | 554 | 203 | } | 555 | | } else { | 556 | | StringRef ipv6_str = str_addr_column->get_data_at(i); | 557 | | if (IPv6Value::is_valid_string(ipv6_str.data, ipv6_str.size)) { | 558 | | col_res_data[i] = 1; | 559 | | } | 560 | | } | 561 | 816 | } | 562 | | | 563 | 47 | block.replace_by_position(result, std::move(col_res)); | 564 | 47 | return Status::OK(); | 565 | 47 | } |
_ZNK5doris18FunctionIsIPStringIoE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 542 | 49 | uint32_t result, size_t input_rows_count) const override { | 543 | 49 | const auto& addr_column_with_type_and_name = block.get_by_position(arguments[0]); | 544 | 49 | const ColumnPtr& addr_column = addr_column_with_type_and_name.column; | 545 | 49 | const auto* str_addr_column = assert_cast<const ColumnString*>(addr_column.get()); | 546 | 49 | auto col_res = ColumnUInt8::create(input_rows_count, 0); | 547 | 49 | auto& col_res_data = col_res->get_data(); | 548 | | | 549 | 867 | for (size_t i = 0; i < input_rows_count; ++i) { | 550 | | if constexpr (std::is_same_v<Type, IPv4>) { | 551 | | StringRef ipv4_str = str_addr_column->get_data_at(i); | 552 | | if (IPv4Value::is_valid_string(ipv4_str.data, ipv4_str.size)) { | 553 | | col_res_data[i] = 1; | 554 | | } | 555 | 818 | } else { | 556 | 818 | StringRef ipv6_str = str_addr_column->get_data_at(i); | 557 | 818 | if (IPv6Value::is_valid_string(ipv6_str.data, ipv6_str.size)) { | 558 | 202 | col_res_data[i] = 1; | 559 | 202 | } | 560 | 818 | } | 561 | 818 | } | 562 | | | 563 | 49 | block.replace_by_position(result, std::move(col_res)); | 564 | 49 | return Status::OK(); | 565 | 49 | } |
|
566 | | }; |
567 | | |
568 | | class FunctionIsIPAddressInRange : public IFunction { |
569 | | public: |
570 | | static constexpr auto name = "is_ip_address_in_range"; |
571 | 75 | static FunctionPtr create() { return std::make_shared<FunctionIsIPAddressInRange>(); } |
572 | | |
573 | 1 | String get_name() const override { return name; } |
574 | | |
575 | 66 | size_t get_number_of_arguments() const override { return 2; } |
576 | | |
577 | 66 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
578 | 66 | return std::make_shared<DataTypeUInt8>(); |
579 | 66 | } |
580 | | |
581 | | template <PrimitiveType PT, typename ColumnType> |
582 | | void execute_impl_with_ip(size_t input_rows_count, bool addr_const, bool cidr_const, |
583 | | const ColumnString* str_cidr_column, const ColumnPtr addr_column, |
584 | 17 | ColumnUInt8* col_res) const { |
585 | 17 | auto& col_res_data = col_res->get_data(); |
586 | 17 | const auto& ip_data = assert_cast<const ColumnType*>(addr_column.get())->get_data(); |
587 | 418 | for (size_t i = 0; i < input_rows_count; ++i) { |
588 | 401 | auto addr_idx = index_check_const(i, addr_const); |
589 | 401 | auto cidr_idx = index_check_const(i, cidr_const); |
590 | 401 | auto cidr_data = str_cidr_column->get_data_at(cidr_idx); |
591 | | // cidr_data maybe NULL, But the input column is nested column, so check here avoid throw exception |
592 | 401 | if (cidr_data.data == nullptr || cidr_data.size == 0) { |
593 | 0 | col_res_data[i] = 0; |
594 | 0 | continue; |
595 | 0 | } |
596 | 401 | const auto cidr = parse_ip_with_cidr(cidr_data.to_string_view()); |
597 | 401 | if constexpr (PT == PrimitiveType::TYPE_IPV4) { |
598 | 202 | if (cidr._address.is_v4()) { |
599 | 3 | col_res_data[i] = match_ipv4_subnet(ip_data[addr_idx], cidr._address.as_v4(), |
600 | 3 | cidr._prefix) |
601 | 3 | ? 1 |
602 | 3 | : 0; |
603 | 199 | } else { |
604 | 199 | col_res_data[i] = 0; |
605 | 199 | } |
606 | 202 | } else if constexpr (PT == PrimitiveType::TYPE_IPV6) { |
607 | 199 | if (cidr._address.is_v6()) { |
608 | 199 | col_res_data[i] = match_ipv6_subnet((uint8_t*)(&ip_data[addr_idx]), |
609 | 199 | cidr._address.as_v6(), cidr._prefix) |
610 | 199 | ? 1 |
611 | 199 | : 0; |
612 | 199 | } else { |
613 | 0 | col_res_data[i] = 0; |
614 | 0 | } |
615 | 199 | } |
616 | 401 | } |
617 | 17 | } _ZNK5doris26FunctionIsIPAddressInRange20execute_impl_with_ipILNS_13PrimitiveTypeE36ENS_12ColumnVectorILS2_36EEEEEvmbbPKNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISA_EEPNS3_ILS2_2EEE Line | Count | Source | 584 | 9 | ColumnUInt8* col_res) const { | 585 | 9 | auto& col_res_data = col_res->get_data(); | 586 | 9 | const auto& ip_data = assert_cast<const ColumnType*>(addr_column.get())->get_data(); | 587 | 211 | for (size_t i = 0; i < input_rows_count; ++i) { | 588 | 202 | auto addr_idx = index_check_const(i, addr_const); | 589 | 202 | auto cidr_idx = index_check_const(i, cidr_const); | 590 | 202 | auto cidr_data = str_cidr_column->get_data_at(cidr_idx); | 591 | | // cidr_data maybe NULL, But the input column is nested column, so check here avoid throw exception | 592 | 202 | if (cidr_data.data == nullptr || cidr_data.size == 0) { | 593 | 0 | col_res_data[i] = 0; | 594 | 0 | continue; | 595 | 0 | } | 596 | 202 | const auto cidr = parse_ip_with_cidr(cidr_data.to_string_view()); | 597 | 202 | if constexpr (PT == PrimitiveType::TYPE_IPV4) { | 598 | 202 | if (cidr._address.is_v4()) { | 599 | 3 | col_res_data[i] = match_ipv4_subnet(ip_data[addr_idx], cidr._address.as_v4(), | 600 | 3 | cidr._prefix) | 601 | 3 | ? 1 | 602 | 3 | : 0; | 603 | 199 | } else { | 604 | 199 | col_res_data[i] = 0; | 605 | 199 | } | 606 | | } else if constexpr (PT == PrimitiveType::TYPE_IPV6) { | 607 | | if (cidr._address.is_v6()) { | 608 | | col_res_data[i] = match_ipv6_subnet((uint8_t*)(&ip_data[addr_idx]), | 609 | | cidr._address.as_v6(), cidr._prefix) | 610 | | ? 1 | 611 | | : 0; | 612 | | } else { | 613 | | col_res_data[i] = 0; | 614 | | } | 615 | | } | 616 | 202 | } | 617 | 9 | } |
_ZNK5doris26FunctionIsIPAddressInRange20execute_impl_with_ipILNS_13PrimitiveTypeE37ENS_12ColumnVectorILS2_37EEEEEvmbbPKNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISA_EEPNS3_ILS2_2EEE Line | Count | Source | 584 | 8 | ColumnUInt8* col_res) const { | 585 | 8 | auto& col_res_data = col_res->get_data(); | 586 | 8 | const auto& ip_data = assert_cast<const ColumnType*>(addr_column.get())->get_data(); | 587 | 207 | for (size_t i = 0; i < input_rows_count; ++i) { | 588 | 199 | auto addr_idx = index_check_const(i, addr_const); | 589 | 199 | auto cidr_idx = index_check_const(i, cidr_const); | 590 | 199 | auto cidr_data = str_cidr_column->get_data_at(cidr_idx); | 591 | | // cidr_data maybe NULL, But the input column is nested column, so check here avoid throw exception | 592 | 199 | if (cidr_data.data == nullptr || cidr_data.size == 0) { | 593 | 0 | col_res_data[i] = 0; | 594 | 0 | continue; | 595 | 0 | } | 596 | 199 | const auto cidr = parse_ip_with_cidr(cidr_data.to_string_view()); | 597 | | if constexpr (PT == PrimitiveType::TYPE_IPV4) { | 598 | | if (cidr._address.is_v4()) { | 599 | | col_res_data[i] = match_ipv4_subnet(ip_data[addr_idx], cidr._address.as_v4(), | 600 | | cidr._prefix) | 601 | | ? 1 | 602 | | : 0; | 603 | | } else { | 604 | | col_res_data[i] = 0; | 605 | | } | 606 | 199 | } else if constexpr (PT == PrimitiveType::TYPE_IPV6) { | 607 | 199 | if (cidr._address.is_v6()) { | 608 | 199 | col_res_data[i] = match_ipv6_subnet((uint8_t*)(&ip_data[addr_idx]), | 609 | 199 | cidr._address.as_v6(), cidr._prefix) | 610 | 199 | ? 1 | 611 | 199 | : 0; | 612 | 199 | } else { | 613 | 0 | col_res_data[i] = 0; | 614 | 0 | } | 615 | 199 | } | 616 | 199 | } | 617 | 8 | } |
|
618 | | |
619 | | Status evaluate_inverted_index( |
620 | | const ColumnsWithTypeAndName& arguments, |
621 | | const std::vector<IndexFieldNameAndTypePair>& data_type_with_names, |
622 | | std::vector<segment_v2::IndexIterator*> iterators, uint32_t num_rows, |
623 | | const InvertedIndexAnalyzerCtx* /*analyzer_ctx*/, |
624 | 2 | segment_v2::InvertedIndexResultBitmap& bitmap_result) const override { |
625 | 2 | DCHECK(arguments.size() == 1); |
626 | 2 | DCHECK(data_type_with_names.size() == 1); |
627 | 2 | DCHECK(iterators.size() == 1); |
628 | 2 | auto* iter = iterators[0]; |
629 | 2 | auto data_type_with_name = data_type_with_names[0]; |
630 | 2 | if (iter == nullptr) { |
631 | 0 | return Status::OK(); |
632 | 0 | } |
633 | | |
634 | 2 | if (!segment_v2::IndexReaderHelper::has_bkd_index(iter)) { |
635 | | // Not support only bkd index |
636 | 0 | return Status::Error<ErrorCode::INVERTED_INDEX_EVALUATE_SKIPPED>( |
637 | 0 | "Inverted index evaluate skipped, ip range reader can only support by bkd " |
638 | 0 | "reader"); |
639 | 0 | } |
640 | | // Get the is_ip_address_in_range from the arguments: cidr |
641 | 2 | const auto& cidr_column_with_type_and_name = arguments[0]; |
642 | | // in is_ip_address_in_range param is const Field |
643 | 2 | ColumnPtr arg_column = cidr_column_with_type_and_name.column; |
644 | 2 | DataTypePtr arg_type = cidr_column_with_type_and_name.type; |
645 | 2 | if ((is_column_nullable(*arg_column) && !is_column_const(*remove_nullable(arg_column))) || |
646 | 2 | (!is_column_nullable(*arg_column) && !is_column_const(*arg_column))) { |
647 | | // if not we should skip inverted index and evaluate in expression |
648 | 0 | return Status::Error<ErrorCode::INVERTED_INDEX_EVALUATE_SKIPPED>( |
649 | 0 | "Inverted index evaluate skipped, is_ip_address_in_range only support const " |
650 | 0 | "value"); |
651 | 0 | } |
652 | | // check param type is string |
653 | 2 | if (!is_string_type(arg_type->get_primitive_type())) { |
654 | 0 | return Status::Error<ErrorCode::INVERTED_INDEX_EVALUATE_SKIPPED>( |
655 | 0 | "Inverted index evaluate skipped, is_ip_address_in_range only support string " |
656 | 0 | "type"); |
657 | 0 | } |
658 | | // min && max ip address |
659 | 2 | Field min_ip, max_ip; |
660 | 2 | IPAddressCIDR cidr = parse_ip_with_cidr(arg_column->get_data_at(0)); |
661 | 2 | if (data_type_with_name.second->get_primitive_type() == TYPE_IPV4 && |
662 | 2 | cidr._address.is_v4()) { |
663 | 1 | auto range = apply_cidr_mask(cidr._address.as_v4(), cidr._prefix); |
664 | 1 | min_ip = Field::create_field<TYPE_IPV4>(range.first); |
665 | 1 | max_ip = Field::create_field<TYPE_IPV4>(range.second); |
666 | 1 | } else if (data_type_with_name.second->get_primitive_type() == TYPE_IPV6 && |
667 | 1 | cidr._address.is_v6()) { |
668 | 1 | auto cidr_range_ipv6_col = ColumnIPv6::create(2, 0); |
669 | 1 | auto& cidr_range_ipv6_data = cidr_range_ipv6_col->get_data(); |
670 | 1 | apply_cidr_mask(reinterpret_cast<const char*>(cidr._address.as_v6()), |
671 | 1 | reinterpret_cast<char*>(&cidr_range_ipv6_data[0]), |
672 | 1 | reinterpret_cast<char*>(&cidr_range_ipv6_data[1]), cidr._prefix); |
673 | 1 | min_ip = Field::create_field<TYPE_IPV6>(cidr_range_ipv6_data[0]); |
674 | 1 | max_ip = Field::create_field<TYPE_IPV6>(cidr_range_ipv6_data[1]); |
675 | 1 | } else { |
676 | | // if here param is invalid for current column to calcute min_ip|max_ip we just return |
677 | 0 | return Status::Error<ErrorCode::INVERTED_INDEX_EVALUATE_SKIPPED>( |
678 | 0 | "Inverted index evaluate skipped, data type " + arg_type->get_name() + |
679 | 0 | " can not support this cidr " + arg_column->get_data_at(0).to_string()); |
680 | 0 | } |
681 | | // apply for inverted index |
682 | 2 | std::shared_ptr<roaring::Roaring> null_bitmap = std::make_shared<roaring::Roaring>(); |
683 | 2 | bool has_null = DORIS_TRY(iter->has_null()); |
684 | 2 | segment_v2::InvertedIndexQueryCacheHandle null_bitmap_cache_handle; |
685 | | |
686 | | // >= min ip |
687 | 2 | segment_v2::InvertedIndexParam min_param; |
688 | 2 | min_param.column_name = data_type_with_name.first; |
689 | 2 | min_param.column_type = data_type_with_name.second; |
690 | 2 | min_param.query_type = segment_v2::InvertedIndexQueryType::GREATER_EQUAL_QUERY; |
691 | 2 | min_param.query_value = min_ip; |
692 | 2 | min_param.num_rows = num_rows; |
693 | 2 | min_param.roaring = std::make_shared<roaring::Roaring>(); |
694 | 2 | if (has_null) { |
695 | | // Fetch the NULL bitmap together with the first range query to reuse its index reader. |
696 | 0 | min_param.null_bitmap_cache_handle = &null_bitmap_cache_handle; |
697 | 0 | } |
698 | 2 | RETURN_IF_ERROR(iter->read_from_index(&min_param)); |
699 | 2 | if (has_null) { |
700 | 0 | null_bitmap = null_bitmap_cache_handle.get_bitmap(); |
701 | 0 | } |
702 | | |
703 | | // <= max ip |
704 | 2 | segment_v2::InvertedIndexParam max_param; |
705 | 2 | max_param.column_name = data_type_with_name.first; |
706 | 2 | max_param.column_type = data_type_with_name.second; |
707 | 2 | max_param.query_type = segment_v2::InvertedIndexQueryType::LESS_EQUAL_QUERY; |
708 | 2 | max_param.query_value = max_ip; |
709 | 2 | max_param.num_rows = num_rows; |
710 | 2 | max_param.roaring = std::make_shared<roaring::Roaring>(); |
711 | 2 | RETURN_IF_ERROR(iter->read_from_index(&max_param)); |
712 | | |
713 | 2 | auto result_roaring = std::make_shared<roaring::Roaring>(); |
714 | 2 | *result_roaring = *min_param.roaring & *max_param.roaring; |
715 | | |
716 | 2 | DBUG_EXECUTE_IF("ip.inverted_index_filtered", { |
717 | 2 | auto req_id = DebugPoints::instance()->get_debug_param_or_default<int32_t>( |
718 | 2 | "ip.inverted_index_filtered", "req_id", 0); |
719 | 2 | LOG(INFO) << "execute inverted index req_id: " << req_id |
720 | 2 | << " min: " << min_param.roaring->cardinality() |
721 | 2 | << " max: " << max_param.roaring->cardinality() |
722 | 2 | << " result: " << result_roaring->cardinality(); |
723 | 2 | }); |
724 | 2 | segment_v2::InvertedIndexResultBitmap result(result_roaring, null_bitmap); |
725 | 2 | bitmap_result = result; |
726 | 2 | bitmap_result.mask_out_null(); |
727 | 2 | return Status::OK(); |
728 | 2 | } |
729 | | |
730 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
731 | 91 | uint32_t result, size_t input_rows_count) const override { |
732 | 91 | DBUG_EXECUTE_IF("ip.inverted_index_filtered", { |
733 | 91 | auto req_id = DebugPoints::instance()->get_debug_param_or_default<int32_t>( |
734 | 91 | "ip.inverted_index_filtered", "req_id", 0); |
735 | 91 | return Status::Error<ErrorCode::INTERNAL_ERROR>( |
736 | 91 | "{} has already execute inverted index req_id {} , should not execute expr " |
737 | 91 | "with rows: {}", |
738 | 91 | get_name(), req_id, input_rows_count); |
739 | 91 | }); |
740 | 91 | const auto& addr_column_with_type_and_name = block.get_by_position(arguments[0]); |
741 | 91 | const auto& cidr_column_with_type_and_name = block.get_by_position(arguments[1]); |
742 | 91 | const auto& [addr_column, addr_const] = |
743 | 91 | unpack_if_const(addr_column_with_type_and_name.column); |
744 | 91 | const auto& [cidr_column, cidr_const] = |
745 | 91 | unpack_if_const(cidr_column_with_type_and_name.column); |
746 | | |
747 | 91 | auto col_res = ColumnUInt8::create(input_rows_count, 0); |
748 | 91 | auto& col_res_data = col_res->get_data(); |
749 | | |
750 | 91 | if (addr_column_with_type_and_name.type->get_primitive_type() == TYPE_IPV4) { |
751 | 9 | execute_impl_with_ip<PrimitiveType::TYPE_IPV4, ColumnIPv4>( |
752 | 9 | input_rows_count, addr_const, cidr_const, |
753 | 9 | assert_cast<const ColumnString*>(cidr_column.get()), addr_column, |
754 | 9 | col_res.get()); |
755 | 82 | } else if (addr_column_with_type_and_name.type->get_primitive_type() == TYPE_IPV6) { |
756 | 8 | execute_impl_with_ip<PrimitiveType::TYPE_IPV6, ColumnIPv6>( |
757 | 8 | input_rows_count, addr_const, cidr_const, |
758 | 8 | assert_cast<const ColumnString*>(cidr_column.get()), addr_column, |
759 | 8 | col_res.get()); |
760 | 74 | } else { |
761 | 74 | const auto* str_addr_column = assert_cast<const ColumnString*>(addr_column.get()); |
762 | 74 | const auto* str_cidr_column = assert_cast<const ColumnString*>(cidr_column.get()); |
763 | | |
764 | 240 | for (size_t i = 0; i < input_rows_count; ++i) { |
765 | 166 | auto addr_idx = index_check_const(i, addr_const); |
766 | 166 | auto cidr_idx = index_check_const(i, cidr_const); |
767 | 166 | auto addr_data = str_addr_column->get_data_at(addr_idx); |
768 | 166 | auto cidr_data = str_cidr_column->get_data_at(cidr_idx); |
769 | | // cidr_data maybe NULL, But the input column is nested column, so check here avoid throw exception |
770 | 166 | if (cidr_data.data == nullptr || cidr_data.size == 0) { |
771 | 1 | col_res_data[i] = 0; |
772 | 1 | continue; |
773 | 1 | } |
774 | 165 | const auto addr = IPAddressVariant(addr_data.to_string_view()); |
775 | 165 | const auto cidr = parse_ip_with_cidr(cidr_data.to_string_view()); |
776 | 165 | col_res_data[i] = is_address_in_range(addr, cidr) ? 1 : 0; |
777 | 165 | } |
778 | 74 | } |
779 | | |
780 | 91 | block.replace_by_position(result, std::move(col_res)); |
781 | 91 | return Status::OK(); |
782 | 91 | } |
783 | | }; |
784 | | |
785 | | class FunctionIPv4CIDRToRange : public IFunction { |
786 | | public: |
787 | | static constexpr auto name = "ipv4_cidr_to_range"; |
788 | 21 | static FunctionPtr create() { return std::make_shared<FunctionIPv4CIDRToRange>(); } |
789 | | |
790 | 1 | String get_name() const override { return name; } |
791 | | |
792 | 12 | size_t get_number_of_arguments() const override { return 2; } |
793 | | |
794 | 14 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
795 | 14 | DataTypePtr element = std::make_shared<DataTypeIPv4>(); |
796 | 14 | DataTypePtr result = std::make_shared<DataTypeStruct>(DataTypes {element, element}, |
797 | 14 | Strings {"min", "max"}); |
798 | 14 | if (arguments[0]->is_nullable() || arguments[1]->is_nullable()) { |
799 | 7 | return make_nullable(result); |
800 | 7 | } |
801 | 7 | return result; |
802 | 14 | } |
803 | | |
804 | 45 | bool use_default_implementation_for_nulls() const override { return false; } |
805 | | |
806 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
807 | 35 | uint32_t result, size_t input_rows_count) const override { |
808 | 35 | const auto& ip_argument = block.get_by_position(arguments[0]); |
809 | 35 | const auto& cidr_argument = block.get_by_position(arguments[1]); |
810 | 35 | const auto ip = ColumnView<TYPE_IPV4>::create(ip_argument.column); |
811 | 35 | const auto cidr = ColumnView<TYPE_SMALLINT>::create(cidr_argument.column); |
812 | 35 | const bool result_nullable = block.get_by_position(result).type->is_nullable(); |
813 | | |
814 | 35 | auto col_lower_range_output = ColumnIPv4::create(input_rows_count, 0); |
815 | 35 | auto col_upper_range_output = ColumnIPv4::create(input_rows_count, 0); |
816 | 35 | auto& lower = col_lower_range_output->get_data(); |
817 | 35 | auto& upper = col_upper_range_output->get_data(); |
818 | 35 | ColumnUInt8::MutablePtr null_map; |
819 | 35 | if (result_nullable) { |
820 | 22 | null_map = ColumnUInt8::create(input_rows_count, 0); |
821 | 22 | execute_impl<true>(ip, cidr, input_rows_count, lower, upper, &null_map->get_data()); |
822 | 22 | } else { |
823 | 13 | execute_impl<false>(ip, cidr, input_rows_count, lower, upper, nullptr); |
824 | 13 | } |
825 | | |
826 | 35 | ColumnPtr result_column = ColumnStruct::create( |
827 | 35 | Columns {std::move(col_lower_range_output), std::move(col_upper_range_output)}); |
828 | 35 | if (result_nullable) { |
829 | 22 | result_column = ColumnNullable::create(std::move(result_column), std::move(null_map)); |
830 | 22 | } |
831 | 35 | block.replace_by_position(result, std::move(result_column)); |
832 | 35 | return Status::OK(); |
833 | 35 | } |
834 | | |
835 | | private: |
836 | | template <bool ResultNullable> |
837 | | static void execute_impl(const ColumnView<TYPE_IPV4>& ip, const ColumnView<TYPE_SMALLINT>& cidr, |
838 | | size_t input_rows_count, ColumnIPv4::Container& lower, |
839 | 35 | ColumnIPv4::Container& upper, ColumnUInt8::Container* nulls) { |
840 | 35 | static constexpr UInt8 max_cidr_mask = IPV4_BINARY_LENGTH * 8; |
841 | 480 | for (size_t i = 0; i < input_rows_count; ++i) { |
842 | 430 | if constexpr (ResultNullable) { |
843 | 227 | if (ip.is_null_at(i) || cidr.is_null_at(i)) { |
844 | 15 | (*nulls)[i] = 1; |
845 | 15 | continue; |
846 | 15 | } |
847 | 227 | } |
848 | 212 | const auto prefix = cidr.value_at(i); |
849 | 430 | if (prefix < 0 || prefix > max_cidr_mask) { |
850 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal cidr value '{}'", |
851 | 0 | std::to_string(prefix)); |
852 | 0 | } |
853 | 430 | const auto range = apply_cidr_mask(ip.value_at(i), cast_set<UInt8>(prefix)); |
854 | 430 | lower[i] = range.first; |
855 | 430 | upper[i] = range.second; |
856 | 430 | } |
857 | 35 | } _ZN5doris23FunctionIPv4CIDRToRange12execute_implILb1EEEvRKNS_10ColumnViewILNS_13PrimitiveTypeE36EEERKNS2_ILS3_4EEEmRNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESF_PNSA_IhLm4096ESD_Lm16ELm15EEE Line | Count | Source | 839 | 22 | ColumnIPv4::Container& upper, ColumnUInt8::Container* nulls) { | 840 | 22 | static constexpr UInt8 max_cidr_mask = IPV4_BINARY_LENGTH * 8; | 841 | 264 | for (size_t i = 0; i < input_rows_count; ++i) { | 842 | 227 | if constexpr (ResultNullable) { | 843 | 227 | if (ip.is_null_at(i) || cidr.is_null_at(i)) { | 844 | 15 | (*nulls)[i] = 1; | 845 | 15 | continue; | 846 | 15 | } | 847 | 227 | } | 848 | 212 | const auto prefix = cidr.value_at(i); | 849 | 227 | if (prefix < 0 || prefix > max_cidr_mask) { | 850 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal cidr value '{}'", | 851 | 0 | std::to_string(prefix)); | 852 | 0 | } | 853 | 227 | const auto range = apply_cidr_mask(ip.value_at(i), cast_set<UInt8>(prefix)); | 854 | 227 | lower[i] = range.first; | 855 | 227 | upper[i] = range.second; | 856 | 227 | } | 857 | 22 | } |
_ZN5doris23FunctionIPv4CIDRToRange12execute_implILb0EEEvRKNS_10ColumnViewILNS_13PrimitiveTypeE36EEERKNS2_ILS3_4EEEmRNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESF_PNSA_IhLm4096ESD_Lm16ELm15EEE Line | Count | Source | 839 | 13 | ColumnIPv4::Container& upper, ColumnUInt8::Container* nulls) { | 840 | 13 | static constexpr UInt8 max_cidr_mask = IPV4_BINARY_LENGTH * 8; | 841 | 216 | for (size_t i = 0; i < input_rows_count; ++i) { | 842 | | if constexpr (ResultNullable) { | 843 | | if (ip.is_null_at(i) || cidr.is_null_at(i)) { | 844 | | (*nulls)[i] = 1; | 845 | | continue; | 846 | | } | 847 | | } | 848 | 203 | const auto prefix = cidr.value_at(i); | 849 | 203 | if (prefix < 0 || prefix > max_cidr_mask) { | 850 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal cidr value '{}'", | 851 | 0 | std::to_string(prefix)); | 852 | 0 | } | 853 | 203 | const auto range = apply_cidr_mask(ip.value_at(i), cast_set<UInt8>(prefix)); | 854 | 203 | lower[i] = range.first; | 855 | 203 | upper[i] = range.second; | 856 | 203 | } | 857 | 13 | } |
|
858 | | }; |
859 | | |
860 | | /** |
861 | | * this function accepts two arguments: an IPv6 address and a CIDR mask |
862 | | * IPv6 address can be either ipv6 type or string type as ipv6 string address |
863 | | * FE: PropagateNullable is used to handle nullable columns |
864 | | */ |
865 | | class FunctionIPv6CIDRToRange : public IFunction { |
866 | | public: |
867 | | static constexpr auto name = "ipv6_cidr_to_range"; |
868 | 30 | static FunctionPtr create() { return std::make_shared<FunctionIPv6CIDRToRange>(); } |
869 | | |
870 | 1 | String get_name() const override { return name; } |
871 | | |
872 | 21 | size_t get_number_of_arguments() const override { return 2; } |
873 | | |
874 | 24 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
875 | 24 | DataTypePtr element = std::make_shared<DataTypeIPv6>(); |
876 | 24 | DataTypePtr result = std::make_shared<DataTypeStruct>(DataTypes {element, element}, |
877 | 24 | Strings {"min", "max"}); |
878 | 24 | if (arguments[0]->is_nullable() || arguments[1]->is_nullable()) { |
879 | 19 | return make_nullable(result); |
880 | 19 | } |
881 | 5 | return result; |
882 | 24 | } |
883 | | |
884 | 63 | bool use_default_implementation_for_nulls() const override { return false; } |
885 | | |
886 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
887 | 45 | uint32_t result, size_t input_rows_count) const override { |
888 | 45 | const auto& addr_column_with_type_and_name = block.get_by_position(arguments[0]); |
889 | 45 | const auto& cidr_column_with_type_and_name = block.get_by_position(arguments[1]); |
890 | 45 | const auto cidr = ColumnView<TYPE_SMALLINT>::create(cidr_column_with_type_and_name.column); |
891 | 45 | const auto addr_type = addr_column_with_type_and_name.type->get_primitive_type(); |
892 | 45 | const bool result_nullable = block.get_by_position(result).type->is_nullable(); |
893 | | |
894 | 45 | auto col_res_lower_range = ColumnIPv6::create(input_rows_count, 0); |
895 | 45 | auto col_res_upper_range = ColumnIPv6::create(input_rows_count, 0); |
896 | 45 | auto& vec_res_lower_range = col_res_lower_range->get_data(); |
897 | 45 | auto& vec_res_upper_range = col_res_upper_range->get_data(); |
898 | 45 | ColumnUInt8::MutablePtr null_map; |
899 | 45 | if (result_nullable) { |
900 | 35 | null_map = ColumnUInt8::create(input_rows_count, 0); |
901 | 35 | } |
902 | 45 | if (addr_type == TYPE_IPV6) { |
903 | 30 | const auto addr = ColumnView<TYPE_IPV6>::create(addr_column_with_type_and_name.column); |
904 | 30 | if (result_nullable) { |
905 | 20 | execute_impl<true>(addr, cidr, input_rows_count, vec_res_lower_range, |
906 | 20 | vec_res_upper_range, &null_map->get_data()); |
907 | 20 | } else { |
908 | 10 | execute_impl<false>(addr, cidr, input_rows_count, vec_res_lower_range, |
909 | 10 | vec_res_upper_range, nullptr); |
910 | 10 | } |
911 | 30 | } else if (is_string_type(addr_type)) { |
912 | 15 | const auto addr = |
913 | 15 | ColumnView<TYPE_STRING>::create(addr_column_with_type_and_name.column); |
914 | 15 | if (result_nullable) { |
915 | 15 | execute_impl<true>(addr, cidr, input_rows_count, vec_res_lower_range, |
916 | 15 | vec_res_upper_range, &null_map->get_data()); |
917 | 15 | } else { |
918 | 0 | execute_impl<false>(addr, cidr, input_rows_count, vec_res_lower_range, |
919 | 0 | vec_res_upper_range, nullptr); |
920 | 0 | } |
921 | 15 | } else { |
922 | 0 | return Status::RuntimeError( |
923 | 0 | "Illegal column {} of argument of function {}, Expected IPv6 or String", |
924 | 0 | addr_column_with_type_and_name.column->get_name(), get_name()); |
925 | 0 | } |
926 | | |
927 | 45 | ColumnPtr result_column = ColumnStruct::create( |
928 | 45 | Columns {std::move(col_res_lower_range), std::move(col_res_upper_range)}); |
929 | 45 | if (result_nullable) { |
930 | 30 | result_column = ColumnNullable::create(std::move(result_column), std::move(null_map)); |
931 | 30 | } |
932 | 45 | block.replace_by_position(result, std::move(result_column)); |
933 | 45 | return Status::OK(); |
934 | 45 | } |
935 | | |
936 | | private: |
937 | | template <bool ResultNullable> |
938 | | static void execute_impl(const ColumnView<TYPE_IPV6>& addr, |
939 | | const ColumnView<TYPE_SMALLINT>& cidr, size_t input_rows_count, |
940 | | ColumnIPv6::Container& lower, ColumnIPv6::Container& upper, |
941 | 30 | ColumnUInt8::Container* nulls) { |
942 | 30 | static constexpr UInt8 max_cidr_mask = IPV6_BINARY_LENGTH * 8; |
943 | 479 | for (size_t i = 0; i < input_rows_count; ++i) { |
944 | 427 | if constexpr (ResultNullable) { |
945 | 227 | if (addr.is_null_at(i) || cidr.is_null_at(i)) { |
946 | 22 | (*nulls)[i] = 1; |
947 | 22 | continue; |
948 | 22 | } |
949 | 227 | } |
950 | 205 | const auto prefix = cidr.value_at(i); |
951 | 427 | if (prefix < 0 || prefix > max_cidr_mask) { |
952 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal cidr value '{}'", |
953 | 0 | std::to_string(prefix)); |
954 | 0 | } |
955 | 427 | const auto address = addr.value_at(i); |
956 | 427 | apply_cidr_mask(reinterpret_cast<const char*>(&address), |
957 | 427 | reinterpret_cast<char*>(&lower[i]), reinterpret_cast<char*>(&upper[i]), |
958 | 427 | cast_set<UInt8>(prefix)); |
959 | 427 | } |
960 | 30 | } _ZN5doris23FunctionIPv6CIDRToRange12execute_implILb1EEEvRKNS_10ColumnViewILNS_13PrimitiveTypeE37EEERKNS2_ILS3_4EEEmRNS_8PODArrayIoLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESF_PNSA_IhLm4096ESD_Lm16ELm15EEE Line | Count | Source | 941 | 20 | ColumnUInt8::Container* nulls) { | 942 | 20 | static constexpr UInt8 max_cidr_mask = IPV6_BINARY_LENGTH * 8; | 943 | 269 | for (size_t i = 0; i < input_rows_count; ++i) { | 944 | 227 | if constexpr (ResultNullable) { | 945 | 227 | if (addr.is_null_at(i) || cidr.is_null_at(i)) { | 946 | 22 | (*nulls)[i] = 1; | 947 | 22 | continue; | 948 | 22 | } | 949 | 227 | } | 950 | 205 | const auto prefix = cidr.value_at(i); | 951 | 227 | if (prefix < 0 || prefix > max_cidr_mask) { | 952 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal cidr value '{}'", | 953 | 0 | std::to_string(prefix)); | 954 | 0 | } | 955 | 227 | const auto address = addr.value_at(i); | 956 | 227 | apply_cidr_mask(reinterpret_cast<const char*>(&address), | 957 | 227 | reinterpret_cast<char*>(&lower[i]), reinterpret_cast<char*>(&upper[i]), | 958 | 227 | cast_set<UInt8>(prefix)); | 959 | 227 | } | 960 | 20 | } |
_ZN5doris23FunctionIPv6CIDRToRange12execute_implILb0EEEvRKNS_10ColumnViewILNS_13PrimitiveTypeE37EEERKNS2_ILS3_4EEEmRNS_8PODArrayIoLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESF_PNSA_IhLm4096ESD_Lm16ELm15EEE Line | Count | Source | 941 | 10 | ColumnUInt8::Container* nulls) { | 942 | 10 | static constexpr UInt8 max_cidr_mask = IPV6_BINARY_LENGTH * 8; | 943 | 210 | for (size_t i = 0; i < input_rows_count; ++i) { | 944 | | if constexpr (ResultNullable) { | 945 | | if (addr.is_null_at(i) || cidr.is_null_at(i)) { | 946 | | (*nulls)[i] = 1; | 947 | | continue; | 948 | | } | 949 | | } | 950 | 200 | const auto prefix = cidr.value_at(i); | 951 | 200 | if (prefix < 0 || prefix > max_cidr_mask) { | 952 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal cidr value '{}'", | 953 | 0 | std::to_string(prefix)); | 954 | 0 | } | 955 | 200 | const auto address = addr.value_at(i); | 956 | 200 | apply_cidr_mask(reinterpret_cast<const char*>(&address), | 957 | 200 | reinterpret_cast<char*>(&lower[i]), reinterpret_cast<char*>(&upper[i]), | 958 | 200 | cast_set<UInt8>(prefix)); | 959 | 200 | } | 960 | 10 | } |
|
961 | | |
962 | | template <bool ResultNullable> |
963 | | static void execute_impl(const ColumnView<TYPE_STRING>& addr, |
964 | | const ColumnView<TYPE_SMALLINT>& cidr, size_t input_rows_count, |
965 | | ColumnIPv6::Container& lower, ColumnIPv6::Container& upper, |
966 | 15 | ColumnUInt8::Container* nulls) { |
967 | 15 | static constexpr UInt8 max_cidr_mask = IPV6_BINARY_LENGTH * 8; |
968 | 34 | for (size_t i = 0; i < input_rows_count; ++i) { |
969 | 21 | if constexpr (ResultNullable) { |
970 | 21 | if (addr.is_null_at(i) || cidr.is_null_at(i)) { |
971 | 3 | (*nulls)[i] = 1; |
972 | 3 | continue; |
973 | 3 | } |
974 | 21 | } |
975 | 18 | const auto prefix = cidr.value_at(i); |
976 | 21 | if (prefix < 0 || prefix > max_cidr_mask) { |
977 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal cidr value '{}'", |
978 | 0 | std::to_string(prefix)); |
979 | 0 | } |
980 | 21 | const auto value = addr.value_at(i); |
981 | 21 | if (value.size == 0) { |
982 | 2 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv6 value"); |
983 | 2 | } |
984 | 19 | IPv6 address = 0; |
985 | 19 | Int64 parsed_ipv4 = 0; |
986 | 19 | bool parsed = false; |
987 | 19 | if (try_parse_ipv4(value.begin(), value.end(), parsed_ipv4)) { |
988 | 0 | map_ipv4_to_ipv6(static_cast<IPv4>(parsed_ipv4), |
989 | 0 | reinterpret_cast<UInt8*>(&address)); |
990 | 0 | parsed = true; |
991 | 19 | } else { |
992 | 19 | parsed = parse_ipv6_whole(value.begin(), value.end(), |
993 | 19 | reinterpret_cast<UInt8*>(&address)); |
994 | 19 | } |
995 | 19 | if (!parsed) { |
996 | 3 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv6 value"); |
997 | 3 | } |
998 | 16 | apply_cidr_mask(reinterpret_cast<const char*>(&address), |
999 | 16 | reinterpret_cast<char*>(&lower[i]), reinterpret_cast<char*>(&upper[i]), |
1000 | 16 | cast_set<UInt8>(prefix)); |
1001 | 16 | } |
1002 | 15 | } _ZN5doris23FunctionIPv6CIDRToRange12execute_implILb1EEEvRKNS_10ColumnViewILNS_13PrimitiveTypeE23EEERKNS2_ILS3_4EEEmRNS_8PODArrayIoLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESF_PNSA_IhLm4096ESD_Lm16ELm15EEE Line | Count | Source | 966 | 15 | ColumnUInt8::Container* nulls) { | 967 | 15 | static constexpr UInt8 max_cidr_mask = IPV6_BINARY_LENGTH * 8; | 968 | 34 | for (size_t i = 0; i < input_rows_count; ++i) { | 969 | 21 | if constexpr (ResultNullable) { | 970 | 21 | if (addr.is_null_at(i) || cidr.is_null_at(i)) { | 971 | 3 | (*nulls)[i] = 1; | 972 | 3 | continue; | 973 | 3 | } | 974 | 21 | } | 975 | 18 | const auto prefix = cidr.value_at(i); | 976 | 21 | if (prefix < 0 || prefix > max_cidr_mask) { | 977 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal cidr value '{}'", | 978 | 0 | std::to_string(prefix)); | 979 | 0 | } | 980 | 21 | const auto value = addr.value_at(i); | 981 | 21 | if (value.size == 0) { | 982 | 2 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv6 value"); | 983 | 2 | } | 984 | 19 | IPv6 address = 0; | 985 | 19 | Int64 parsed_ipv4 = 0; | 986 | 19 | bool parsed = false; | 987 | 19 | if (try_parse_ipv4(value.begin(), value.end(), parsed_ipv4)) { | 988 | 0 | map_ipv4_to_ipv6(static_cast<IPv4>(parsed_ipv4), | 989 | 0 | reinterpret_cast<UInt8*>(&address)); | 990 | 0 | parsed = true; | 991 | 19 | } else { | 992 | 19 | parsed = parse_ipv6_whole(value.begin(), value.end(), | 993 | 19 | reinterpret_cast<UInt8*>(&address)); | 994 | 19 | } | 995 | 19 | if (!parsed) { | 996 | 3 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv6 value"); | 997 | 3 | } | 998 | 16 | apply_cidr_mask(reinterpret_cast<const char*>(&address), | 999 | 16 | reinterpret_cast<char*>(&lower[i]), reinterpret_cast<char*>(&upper[i]), | 1000 | 16 | cast_set<UInt8>(prefix)); | 1001 | 16 | } | 1002 | 15 | } |
Unexecuted instantiation: _ZN5doris23FunctionIPv6CIDRToRange12execute_implILb0EEEvRKNS_10ColumnViewILNS_13PrimitiveTypeE23EEERKNS2_ILS3_4EEEmRNS_8PODArrayIoLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEESF_PNSA_IhLm4096ESD_Lm16ELm15EEE |
1003 | | }; |
1004 | | |
1005 | | class FunctionIsIPv4Compat : public IFunction { |
1006 | | public: |
1007 | | static constexpr auto name = "is_ipv4_compat"; |
1008 | 34 | static FunctionPtr create() { return std::make_shared<FunctionIsIPv4Compat>(); } |
1009 | | |
1010 | 1 | String get_name() const override { return name; } |
1011 | | |
1012 | 25 | size_t get_number_of_arguments() const override { return 1; } |
1013 | | |
1014 | 25 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
1015 | 25 | return std::make_shared<DataTypeUInt8>(); |
1016 | 25 | } |
1017 | | |
1018 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
1019 | 25 | uint32_t result, size_t input_rows_count) const override { |
1020 | 25 | const ColumnPtr& column = block.get_by_position(arguments[0]).column; |
1021 | 25 | const auto* col_in = assert_cast<const ColumnString*>(column.get()); |
1022 | | |
1023 | 25 | size_t col_size = col_in->size(); |
1024 | 25 | auto col_res = ColumnUInt8::create(col_size, 0); |
1025 | 25 | auto& col_res_data = col_res->get_data(); |
1026 | | |
1027 | 244 | for (size_t i = 0; i < col_size; ++i) { |
1028 | 219 | const auto address = col_in->get_data_at(i); |
1029 | 219 | if (is_ipv4_compat(address)) { |
1030 | 8 | col_res_data[i] = 1; |
1031 | 8 | } |
1032 | 219 | } |
1033 | | |
1034 | 25 | block.replace_by_position(result, std::move(col_res)); |
1035 | 25 | return Status::OK(); |
1036 | 25 | } |
1037 | | |
1038 | | private: |
1039 | 219 | static bool is_ipv4_compat(const StringRef& address) { |
1040 | 219 | return address.size == IPV6_BINARY_LENGTH && (LittleEndian::Load64(address.data) == 0) && |
1041 | 219 | (LittleEndian::Load32(address.data + 8) == 0) && |
1042 | 219 | (LittleEndian::Load32(address.data + 12) != 0); |
1043 | 219 | } |
1044 | | }; |
1045 | | |
1046 | | class FunctionIsIPv4Mapped : public IFunction { |
1047 | | public: |
1048 | | static constexpr auto name = "is_ipv4_mapped"; |
1049 | 34 | static FunctionPtr create() { return std::make_shared<FunctionIsIPv4Mapped>(); } |
1050 | | |
1051 | 1 | String get_name() const override { return name; } |
1052 | | |
1053 | 25 | size_t get_number_of_arguments() const override { return 1; } |
1054 | | |
1055 | 25 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
1056 | 25 | return std::make_shared<DataTypeUInt8>(); |
1057 | 25 | } |
1058 | | |
1059 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
1060 | 21 | uint32_t result, size_t input_rows_count) const override { |
1061 | 21 | const ColumnPtr& column = block.get_by_position(arguments[0]).column; |
1062 | 21 | const auto* col_in = assert_cast<const ColumnString*>(column.get()); |
1063 | | |
1064 | 21 | size_t col_size = col_in->size(); |
1065 | 21 | auto col_res = ColumnUInt8::create(col_size, 0); |
1066 | 21 | auto& col_res_data = col_res->get_data(); |
1067 | | |
1068 | 236 | for (size_t i = 0; i < col_size; ++i) { |
1069 | 215 | const auto address = col_in->get_data_at(i); |
1070 | 215 | if (is_ipv4_mapped(address)) { |
1071 | 6 | col_res_data[i] = 1; |
1072 | 6 | } |
1073 | 215 | } |
1074 | | |
1075 | 21 | block.replace_by_position(result, std::move(col_res)); |
1076 | 21 | return Status::OK(); |
1077 | 21 | } |
1078 | | |
1079 | | private: |
1080 | 215 | static bool is_ipv4_mapped(const StringRef& address) { |
1081 | 215 | return address.size == IPV6_BINARY_LENGTH && (LittleEndian::Load64(address.data) == 0) && |
1082 | 215 | ((LittleEndian::Load64(address.data + 8) & 0x00000000FFFFFFFFULL) == |
1083 | 10 | 0x00000000FFFF0000ULL); |
1084 | 215 | } |
1085 | | }; |
1086 | | |
1087 | | template <IPConvertExceptionMode exception_mode, PrimitiveType PType> |
1088 | 0 | inline constexpr auto to_ip_func_name() { |
1089 | 0 | if constexpr (PType == TYPE_IPV4) { |
1090 | 0 | return exception_mode == IPConvertExceptionMode::Throw |
1091 | 0 | ? "to_ipv4" |
1092 | 0 | : (exception_mode == IPConvertExceptionMode::Default ? "to_ipv4_or_default" |
1093 | 0 | : "to_ipv4_or_null"); |
1094 | 0 | } else { |
1095 | 0 | return exception_mode == IPConvertExceptionMode::Throw |
1096 | 0 | ? "to_ipv6" |
1097 | 0 | : (exception_mode == IPConvertExceptionMode::Default ? "to_ipv6_or_default" |
1098 | 0 | : "to_ipv6_or_null"); |
1099 | 0 | } |
1100 | 0 | } Unexecuted instantiation: _ZN5doris15to_ip_func_nameILNS_22IPConvertExceptionModeE0ELNS_13PrimitiveTypeE36EEEDav Unexecuted instantiation: _ZN5doris15to_ip_func_nameILNS_22IPConvertExceptionModeE1ELNS_13PrimitiveTypeE36EEEDav Unexecuted instantiation: _ZN5doris15to_ip_func_nameILNS_22IPConvertExceptionModeE2ELNS_13PrimitiveTypeE36EEEDav Unexecuted instantiation: _ZN5doris15to_ip_func_nameILNS_22IPConvertExceptionModeE0ELNS_13PrimitiveTypeE37EEEDav Unexecuted instantiation: _ZN5doris15to_ip_func_nameILNS_22IPConvertExceptionModeE1ELNS_13PrimitiveTypeE37EEEDav Unexecuted instantiation: _ZN5doris15to_ip_func_nameILNS_22IPConvertExceptionModeE2ELNS_13PrimitiveTypeE37EEEDav |
1101 | | |
1102 | | template <IPConvertExceptionMode exception_mode, PrimitiveType PType> |
1103 | | class FunctionToIP : public IFunction { |
1104 | | static_assert(is_ip(PType)); |
1105 | | |
1106 | | public: |
1107 | | static constexpr auto name = to_ip_func_name<exception_mode, PType>(); |
1108 | | |
1109 | 119 | static FunctionPtr create() { return std::make_shared<FunctionToIP<exception_mode, PType>>(); }_ZN5doris12FunctionToIPILNS_22IPConvertExceptionModeE0ELNS_13PrimitiveTypeE36EE6createEv Line | Count | Source | 1109 | 22 | static FunctionPtr create() { return std::make_shared<FunctionToIP<exception_mode, PType>>(); } |
_ZN5doris12FunctionToIPILNS_22IPConvertExceptionModeE1ELNS_13PrimitiveTypeE36EE6createEv Line | Count | Source | 1109 | 18 | static FunctionPtr create() { return std::make_shared<FunctionToIP<exception_mode, PType>>(); } |
_ZN5doris12FunctionToIPILNS_22IPConvertExceptionModeE2ELNS_13PrimitiveTypeE36EE6createEv Line | Count | Source | 1109 | 20 | static FunctionPtr create() { return std::make_shared<FunctionToIP<exception_mode, PType>>(); } |
_ZN5doris12FunctionToIPILNS_22IPConvertExceptionModeE0ELNS_13PrimitiveTypeE37EE6createEv Line | Count | Source | 1109 | 22 | static FunctionPtr create() { return std::make_shared<FunctionToIP<exception_mode, PType>>(); } |
_ZN5doris12FunctionToIPILNS_22IPConvertExceptionModeE1ELNS_13PrimitiveTypeE37EE6createEv Line | Count | Source | 1109 | 18 | static FunctionPtr create() { return std::make_shared<FunctionToIP<exception_mode, PType>>(); } |
_ZN5doris12FunctionToIPILNS_22IPConvertExceptionModeE2ELNS_13PrimitiveTypeE37EE6createEv Line | Count | Source | 1109 | 19 | static FunctionPtr create() { return std::make_shared<FunctionToIP<exception_mode, PType>>(); } |
|
1110 | | |
1111 | 9 | String get_name() const override { return name; }_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE0ELNS_13PrimitiveTypeE36EE8get_nameB5cxx11Ev Line | Count | Source | 1111 | 2 | String get_name() const override { return name; } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE1ELNS_13PrimitiveTypeE36EE8get_nameB5cxx11Ev Line | Count | Source | 1111 | 1 | String get_name() const override { return name; } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE2ELNS_13PrimitiveTypeE36EE8get_nameB5cxx11Ev Line | Count | Source | 1111 | 1 | String get_name() const override { return name; } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE0ELNS_13PrimitiveTypeE37EE8get_nameB5cxx11Ev Line | Count | Source | 1111 | 3 | String get_name() const override { return name; } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE1ELNS_13PrimitiveTypeE37EE8get_nameB5cxx11Ev Line | Count | Source | 1111 | 1 | String get_name() const override { return name; } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE2ELNS_13PrimitiveTypeE37EE8get_nameB5cxx11Ev Line | Count | Source | 1111 | 1 | String get_name() const override { return name; } |
|
1112 | | |
1113 | 65 | size_t get_number_of_arguments() const override { return 1; }_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE0ELNS_13PrimitiveTypeE36EE23get_number_of_argumentsEv Line | Count | Source | 1113 | 13 | size_t get_number_of_arguments() const override { return 1; } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE1ELNS_13PrimitiveTypeE36EE23get_number_of_argumentsEv Line | Count | Source | 1113 | 9 | size_t get_number_of_arguments() const override { return 1; } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE2ELNS_13PrimitiveTypeE36EE23get_number_of_argumentsEv Line | Count | Source | 1113 | 11 | size_t get_number_of_arguments() const override { return 1; } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE0ELNS_13PrimitiveTypeE37EE23get_number_of_argumentsEv Line | Count | Source | 1113 | 13 | size_t get_number_of_arguments() const override { return 1; } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE1ELNS_13PrimitiveTypeE37EE23get_number_of_argumentsEv Line | Count | Source | 1113 | 9 | size_t get_number_of_arguments() const override { return 1; } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE2ELNS_13PrimitiveTypeE37EE23get_number_of_argumentsEv Line | Count | Source | 1113 | 10 | size_t get_number_of_arguments() const override { return 1; } |
|
1114 | | |
1115 | 65 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
1116 | 65 | DataTypePtr result_type; |
1117 | | |
1118 | 65 | if constexpr (PType == TYPE_IPV4) { |
1119 | 33 | result_type = std::make_shared<DataTypeIPv4>(); |
1120 | 33 | } else { |
1121 | 32 | result_type = std::make_shared<DataTypeIPv6>(); |
1122 | 32 | } |
1123 | | |
1124 | 65 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { |
1125 | 21 | return make_nullable(result_type); |
1126 | 44 | } else { |
1127 | 44 | return result_type; |
1128 | 44 | } |
1129 | 65 | } _ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE0ELNS_13PrimitiveTypeE36EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS8_EE Line | Count | Source | 1115 | 13 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 1116 | 13 | DataTypePtr result_type; | 1117 | | | 1118 | 13 | if constexpr (PType == TYPE_IPV4) { | 1119 | 13 | result_type = std::make_shared<DataTypeIPv4>(); | 1120 | | } else { | 1121 | | result_type = std::make_shared<DataTypeIPv6>(); | 1122 | | } | 1123 | | | 1124 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 1125 | | return make_nullable(result_type); | 1126 | 13 | } else { | 1127 | 13 | return result_type; | 1128 | 13 | } | 1129 | 13 | } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE1ELNS_13PrimitiveTypeE36EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS8_EE Line | Count | Source | 1115 | 9 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 1116 | 9 | DataTypePtr result_type; | 1117 | | | 1118 | 9 | if constexpr (PType == TYPE_IPV4) { | 1119 | 9 | result_type = std::make_shared<DataTypeIPv4>(); | 1120 | | } else { | 1121 | | result_type = std::make_shared<DataTypeIPv6>(); | 1122 | | } | 1123 | | | 1124 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 1125 | | return make_nullable(result_type); | 1126 | 9 | } else { | 1127 | 9 | return result_type; | 1128 | 9 | } | 1129 | 9 | } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE2ELNS_13PrimitiveTypeE36EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS8_EE Line | Count | Source | 1115 | 11 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 1116 | 11 | DataTypePtr result_type; | 1117 | | | 1118 | 11 | if constexpr (PType == TYPE_IPV4) { | 1119 | 11 | result_type = std::make_shared<DataTypeIPv4>(); | 1120 | | } else { | 1121 | | result_type = std::make_shared<DataTypeIPv6>(); | 1122 | | } | 1123 | | | 1124 | 11 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 1125 | 11 | return make_nullable(result_type); | 1126 | | } else { | 1127 | | return result_type; | 1128 | | } | 1129 | 11 | } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE0ELNS_13PrimitiveTypeE37EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS8_EE Line | Count | Source | 1115 | 13 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 1116 | 13 | DataTypePtr result_type; | 1117 | | | 1118 | | if constexpr (PType == TYPE_IPV4) { | 1119 | | result_type = std::make_shared<DataTypeIPv4>(); | 1120 | 13 | } else { | 1121 | 13 | result_type = std::make_shared<DataTypeIPv6>(); | 1122 | 13 | } | 1123 | | | 1124 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 1125 | | return make_nullable(result_type); | 1126 | 13 | } else { | 1127 | 13 | return result_type; | 1128 | 13 | } | 1129 | 13 | } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE1ELNS_13PrimitiveTypeE37EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS8_EE Line | Count | Source | 1115 | 9 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 1116 | 9 | DataTypePtr result_type; | 1117 | | | 1118 | | if constexpr (PType == TYPE_IPV4) { | 1119 | | result_type = std::make_shared<DataTypeIPv4>(); | 1120 | 9 | } else { | 1121 | 9 | result_type = std::make_shared<DataTypeIPv6>(); | 1122 | 9 | } | 1123 | | | 1124 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 1125 | | return make_nullable(result_type); | 1126 | 9 | } else { | 1127 | 9 | return result_type; | 1128 | 9 | } | 1129 | 9 | } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE2ELNS_13PrimitiveTypeE37EE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS8_EE Line | Count | Source | 1115 | 10 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 1116 | 10 | DataTypePtr result_type; | 1117 | | | 1118 | | if constexpr (PType == TYPE_IPV4) { | 1119 | | result_type = std::make_shared<DataTypeIPv4>(); | 1120 | 10 | } else { | 1121 | 10 | result_type = std::make_shared<DataTypeIPv6>(); | 1122 | 10 | } | 1123 | | | 1124 | 10 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 1125 | 10 | return make_nullable(result_type); | 1126 | | } else { | 1127 | | return result_type; | 1128 | | } | 1129 | 10 | } |
|
1130 | | |
1131 | 261 | bool use_default_implementation_for_nulls() const override { return false; }_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE0ELNS_13PrimitiveTypeE36EE36use_default_implementation_for_nullsEv Line | Count | Source | 1131 | 33 | bool use_default_implementation_for_nulls() const override { return false; } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE1ELNS_13PrimitiveTypeE36EE36use_default_implementation_for_nullsEv Line | Count | Source | 1131 | 45 | bool use_default_implementation_for_nulls() const override { return false; } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE2ELNS_13PrimitiveTypeE36EE36use_default_implementation_for_nullsEv Line | Count | Source | 1131 | 55 | bool use_default_implementation_for_nulls() const override { return false; } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE0ELNS_13PrimitiveTypeE37EE36use_default_implementation_for_nullsEv Line | Count | Source | 1131 | 33 | bool use_default_implementation_for_nulls() const override { return false; } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE1ELNS_13PrimitiveTypeE37EE36use_default_implementation_for_nullsEv Line | Count | Source | 1131 | 45 | bool use_default_implementation_for_nulls() const override { return false; } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE2ELNS_13PrimitiveTypeE37EE36use_default_implementation_for_nullsEv Line | Count | Source | 1131 | 50 | bool use_default_implementation_for_nulls() const override { return false; } |
|
1132 | | |
1133 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
1134 | 196 | uint32_t result, size_t input_rows_count) const override { |
1135 | 196 | const auto& addr_column_with_type_and_name = block.get_by_position(arguments[0]); |
1136 | 196 | const ColumnPtr& addr_column = addr_column_with_type_and_name.column; |
1137 | 196 | const ColumnString* str_addr_column = nullptr; |
1138 | 196 | const NullMap* addr_null_map = nullptr; |
1139 | | |
1140 | 196 | if (addr_column_with_type_and_name.type->is_nullable()) { |
1141 | 142 | const auto* addr_column_nullable = |
1142 | 142 | assert_cast<const ColumnNullable*>(addr_column.get()); |
1143 | 142 | str_addr_column = assert_cast<const ColumnString*>( |
1144 | 142 | addr_column_nullable->get_nested_column_ptr().get()); |
1145 | 142 | addr_null_map = &addr_column_nullable->get_null_map_data(); |
1146 | 142 | } else { |
1147 | 54 | str_addr_column = assert_cast<const ColumnString*>(addr_column.get()); |
1148 | 54 | } |
1149 | | |
1150 | 196 | auto col_res = ColumnVector<PType>::create(input_rows_count, 0); |
1151 | 196 | auto res_null_map = ColumnUInt8::create(input_rows_count, 0); |
1152 | 196 | auto& col_res_data = col_res->get_data(); |
1153 | 196 | auto& res_null_map_data = res_null_map->get_data(); |
1154 | | |
1155 | 3.74k | for (size_t i = 0; i < input_rows_count; ++i) { |
1156 | 3.50k | if (addr_null_map && (*addr_null_map)[i]) { |
1157 | 54 | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { |
1158 | 3 | throw Exception(ErrorCode::INVALID_ARGUMENT, |
1159 | 3 | "The arguments of function {} must be String, not NULL", |
1160 | 3 | get_name()); |
1161 | 24 | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { |
1162 | 24 | col_res_data[i] = 0; // '0.0.0.0' or '::' |
1163 | 24 | continue; |
1164 | 27 | } else { |
1165 | 27 | res_null_map_data[i] = 1; |
1166 | 27 | continue; |
1167 | 27 | } |
1168 | 54 | } |
1169 | | |
1170 | 1.76k | if constexpr (PType == TYPE_IPV4) { |
1171 | 1.76k | StringRef ipv4_str = str_addr_column->get_data_at(i); |
1172 | 1.76k | IPv4 ipv4_val = 0; |
1173 | 1.76k | if (IPv4Value::from_string(ipv4_val, ipv4_str.data, ipv4_str.size)) { |
1174 | 555 | col_res_data[i] = ipv4_val; |
1175 | 1.20k | } else { |
1176 | 1.20k | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { |
1177 | 3 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv4 value '{}'", |
1178 | 3 | ipv4_str.to_string_view()); |
1179 | 602 | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { |
1180 | 602 | col_res_data[i] = 0; // '0.0.0.0' |
1181 | 604 | } else { |
1182 | 604 | res_null_map_data[i] = 1; |
1183 | 604 | } |
1184 | 1.20k | } |
1185 | 1.76k | } else { |
1186 | 1.73k | StringRef ipv6_str = str_addr_column->get_data_at(i); |
1187 | 1.73k | IPv6 ipv6_val = 0; |
1188 | 1.73k | if (IPv6Value::from_string(ipv6_val, ipv6_str.data, ipv6_str.size)) { |
1189 | 517 | col_res_data[i] = ipv6_val; |
1190 | 1.22k | } else { |
1191 | 1.22k | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { |
1192 | 6 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv6 value '{}'", |
1193 | 6 | ipv6_str.to_string_view()); |
1194 | 607 | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { |
1195 | 607 | col_res_data[i] = 0; // '::' |
1196 | 608 | } else if constexpr (exception_mode == IPConvertExceptionMode::Null) { |
1197 | 608 | res_null_map_data[i] = 1; |
1198 | 608 | } |
1199 | 1.22k | } |
1200 | 1.73k | } |
1201 | 3.50k | } |
1202 | | |
1203 | 207 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { |
1204 | 111 | block.replace_by_position( |
1205 | 111 | result, ColumnNullable::create(std::move(col_res), std::move(res_null_map))); |
1206 | 136 | } else { |
1207 | 136 | block.replace_by_position(result, std::move(col_res)); |
1208 | 136 | } |
1209 | | |
1210 | 207 | return Status::OK(); |
1211 | 196 | } _ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE0ELNS_13PrimitiveTypeE36EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 1134 | 20 | uint32_t result, size_t input_rows_count) const override { | 1135 | 20 | const auto& addr_column_with_type_and_name = block.get_by_position(arguments[0]); | 1136 | 20 | const ColumnPtr& addr_column = addr_column_with_type_and_name.column; | 1137 | 20 | const ColumnString* str_addr_column = nullptr; | 1138 | 20 | const NullMap* addr_null_map = nullptr; | 1139 | | | 1140 | 20 | if (addr_column_with_type_and_name.type->is_nullable()) { | 1141 | 11 | const auto* addr_column_nullable = | 1142 | 11 | assert_cast<const ColumnNullable*>(addr_column.get()); | 1143 | 11 | str_addr_column = assert_cast<const ColumnString*>( | 1144 | 11 | addr_column_nullable->get_nested_column_ptr().get()); | 1145 | 11 | addr_null_map = &addr_column_nullable->get_null_map_data(); | 1146 | 11 | } else { | 1147 | 9 | str_addr_column = assert_cast<const ColumnString*>(addr_column.get()); | 1148 | 9 | } | 1149 | | | 1150 | 20 | auto col_res = ColumnVector<PType>::create(input_rows_count, 0); | 1151 | 20 | auto res_null_map = ColumnUInt8::create(input_rows_count, 0); | 1152 | 20 | auto& col_res_data = col_res->get_data(); | 1153 | 20 | auto& res_null_map_data = res_null_map->get_data(); | 1154 | | | 1155 | 164 | for (size_t i = 0; i < input_rows_count; ++i) { | 1156 | 144 | if (addr_null_map && (*addr_null_map)[i]) { | 1157 | 1 | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 1158 | 1 | throw Exception(ErrorCode::INVALID_ARGUMENT, | 1159 | 1 | "The arguments of function {} must be String, not NULL", | 1160 | 1 | get_name()); | 1161 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 1162 | | col_res_data[i] = 0; // '0.0.0.0' or '::' | 1163 | | continue; | 1164 | | } else { | 1165 | | res_null_map_data[i] = 1; | 1166 | | continue; | 1167 | | } | 1168 | 1 | } | 1169 | | | 1170 | 144 | if constexpr (PType == TYPE_IPV4) { | 1171 | 144 | StringRef ipv4_str = str_addr_column->get_data_at(i); | 1172 | 144 | IPv4 ipv4_val = 0; | 1173 | 144 | if (IPv4Value::from_string(ipv4_val, ipv4_str.data, ipv4_str.size)) { | 1174 | 141 | col_res_data[i] = ipv4_val; | 1175 | 141 | } else { | 1176 | 3 | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 1177 | 3 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv4 value '{}'", | 1178 | 3 | ipv4_str.to_string_view()); | 1179 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 1180 | | col_res_data[i] = 0; // '0.0.0.0' | 1181 | | } else { | 1182 | | res_null_map_data[i] = 1; | 1183 | | } | 1184 | 3 | } | 1185 | | } else { | 1186 | | StringRef ipv6_str = str_addr_column->get_data_at(i); | 1187 | | IPv6 ipv6_val = 0; | 1188 | | if (IPv6Value::from_string(ipv6_val, ipv6_str.data, ipv6_str.size)) { | 1189 | | col_res_data[i] = ipv6_val; | 1190 | | } else { | 1191 | | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 1192 | | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv6 value '{}'", | 1193 | | ipv6_str.to_string_view()); | 1194 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 1195 | | col_res_data[i] = 0; // '::' | 1196 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 1197 | | res_null_map_data[i] = 1; | 1198 | | } | 1199 | | } | 1200 | | } | 1201 | 144 | } | 1202 | | | 1203 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 1204 | | block.replace_by_position( | 1205 | | result, ColumnNullable::create(std::move(col_res), std::move(res_null_map))); | 1206 | 20 | } else { | 1207 | 20 | block.replace_by_position(result, std::move(col_res)); | 1208 | 20 | } | 1209 | | | 1210 | 20 | return Status::OK(); | 1211 | 20 | } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE1ELNS_13PrimitiveTypeE36EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 1134 | 36 | uint32_t result, size_t input_rows_count) const override { | 1135 | 36 | const auto& addr_column_with_type_and_name = block.get_by_position(arguments[0]); | 1136 | 36 | const ColumnPtr& addr_column = addr_column_with_type_and_name.column; | 1137 | 36 | const ColumnString* str_addr_column = nullptr; | 1138 | 36 | const NullMap* addr_null_map = nullptr; | 1139 | | | 1140 | 36 | if (addr_column_with_type_and_name.type->is_nullable()) { | 1141 | 28 | const auto* addr_column_nullable = | 1142 | 28 | assert_cast<const ColumnNullable*>(addr_column.get()); | 1143 | 28 | str_addr_column = assert_cast<const ColumnString*>( | 1144 | 28 | addr_column_nullable->get_nested_column_ptr().get()); | 1145 | 28 | addr_null_map = &addr_column_nullable->get_null_map_data(); | 1146 | 28 | } else { | 1147 | 8 | str_addr_column = assert_cast<const ColumnString*>(addr_column.get()); | 1148 | 8 | } | 1149 | | | 1150 | 36 | auto col_res = ColumnVector<PType>::create(input_rows_count, 0); | 1151 | 36 | auto res_null_map = ColumnUInt8::create(input_rows_count, 0); | 1152 | 36 | auto& col_res_data = col_res->get_data(); | 1153 | 36 | auto& res_null_map_data = res_null_map->get_data(); | 1154 | | | 1155 | 850 | for (size_t i = 0; i < input_rows_count; ++i) { | 1156 | 802 | if (addr_null_map && (*addr_null_map)[i]) { | 1157 | | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 1158 | | throw Exception(ErrorCode::INVALID_ARGUMENT, | 1159 | | "The arguments of function {} must be String, not NULL", | 1160 | | get_name()); | 1161 | 12 | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 1162 | 12 | col_res_data[i] = 0; // '0.0.0.0' or '::' | 1163 | 12 | continue; | 1164 | | } else { | 1165 | | res_null_map_data[i] = 1; | 1166 | | continue; | 1167 | | } | 1168 | 12 | } | 1169 | | | 1170 | 802 | if constexpr (PType == TYPE_IPV4) { | 1171 | 802 | StringRef ipv4_str = str_addr_column->get_data_at(i); | 1172 | 802 | IPv4 ipv4_val = 0; | 1173 | 802 | if (IPv4Value::from_string(ipv4_val, ipv4_str.data, ipv4_str.size)) { | 1174 | 200 | col_res_data[i] = ipv4_val; | 1175 | 602 | } else { | 1176 | | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 1177 | | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv4 value '{}'", | 1178 | | ipv4_str.to_string_view()); | 1179 | 602 | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 1180 | 602 | col_res_data[i] = 0; // '0.0.0.0' | 1181 | | } else { | 1182 | | res_null_map_data[i] = 1; | 1183 | | } | 1184 | 602 | } | 1185 | | } else { | 1186 | | StringRef ipv6_str = str_addr_column->get_data_at(i); | 1187 | | IPv6 ipv6_val = 0; | 1188 | | if (IPv6Value::from_string(ipv6_val, ipv6_str.data, ipv6_str.size)) { | 1189 | | col_res_data[i] = ipv6_val; | 1190 | | } else { | 1191 | | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 1192 | | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv6 value '{}'", | 1193 | | ipv6_str.to_string_view()); | 1194 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 1195 | | col_res_data[i] = 0; // '::' | 1196 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 1197 | | res_null_map_data[i] = 1; | 1198 | | } | 1199 | | } | 1200 | | } | 1201 | 802 | } | 1202 | | | 1203 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 1204 | | block.replace_by_position( | 1205 | | result, ColumnNullable::create(std::move(col_res), std::move(res_null_map))); | 1206 | 48 | } else { | 1207 | 48 | block.replace_by_position(result, std::move(col_res)); | 1208 | 48 | } | 1209 | | | 1210 | 48 | return Status::OK(); | 1211 | 36 | } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE2ELNS_13PrimitiveTypeE36EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 1134 | 44 | uint32_t result, size_t input_rows_count) const override { | 1135 | 44 | const auto& addr_column_with_type_and_name = block.get_by_position(arguments[0]); | 1136 | 44 | const ColumnPtr& addr_column = addr_column_with_type_and_name.column; | 1137 | 44 | const ColumnString* str_addr_column = nullptr; | 1138 | 44 | const NullMap* addr_null_map = nullptr; | 1139 | | | 1140 | 44 | if (addr_column_with_type_and_name.type->is_nullable()) { | 1141 | 36 | const auto* addr_column_nullable = | 1142 | 36 | assert_cast<const ColumnNullable*>(addr_column.get()); | 1143 | 36 | str_addr_column = assert_cast<const ColumnString*>( | 1144 | 36 | addr_column_nullable->get_nested_column_ptr().get()); | 1145 | 36 | addr_null_map = &addr_column_nullable->get_null_map_data(); | 1146 | 36 | } else { | 1147 | 8 | str_addr_column = assert_cast<const ColumnString*>(addr_column.get()); | 1148 | 8 | } | 1149 | | | 1150 | 44 | auto col_res = ColumnVector<PType>::create(input_rows_count, 0); | 1151 | 44 | auto res_null_map = ColumnUInt8::create(input_rows_count, 0); | 1152 | 44 | auto& col_res_data = col_res->get_data(); | 1153 | 44 | auto& res_null_map_data = res_null_map->get_data(); | 1154 | | | 1155 | 876 | for (size_t i = 0; i < input_rows_count; ++i) { | 1156 | 818 | if (addr_null_map && (*addr_null_map)[i]) { | 1157 | | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 1158 | | throw Exception(ErrorCode::INVALID_ARGUMENT, | 1159 | | "The arguments of function {} must be String, not NULL", | 1160 | | get_name()); | 1161 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 1162 | | col_res_data[i] = 0; // '0.0.0.0' or '::' | 1163 | | continue; | 1164 | 14 | } else { | 1165 | 14 | res_null_map_data[i] = 1; | 1166 | 14 | continue; | 1167 | 14 | } | 1168 | 14 | } | 1169 | | | 1170 | 818 | if constexpr (PType == TYPE_IPV4) { | 1171 | 818 | StringRef ipv4_str = str_addr_column->get_data_at(i); | 1172 | 818 | IPv4 ipv4_val = 0; | 1173 | 818 | if (IPv4Value::from_string(ipv4_val, ipv4_str.data, ipv4_str.size)) { | 1174 | 214 | col_res_data[i] = ipv4_val; | 1175 | 604 | } else { | 1176 | | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 1177 | | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv4 value '{}'", | 1178 | | ipv4_str.to_string_view()); | 1179 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 1180 | | col_res_data[i] = 0; // '0.0.0.0' | 1181 | 604 | } else { | 1182 | 604 | res_null_map_data[i] = 1; | 1183 | 604 | } | 1184 | 604 | } | 1185 | | } else { | 1186 | | StringRef ipv6_str = str_addr_column->get_data_at(i); | 1187 | | IPv6 ipv6_val = 0; | 1188 | | if (IPv6Value::from_string(ipv6_val, ipv6_str.data, ipv6_str.size)) { | 1189 | | col_res_data[i] = ipv6_val; | 1190 | | } else { | 1191 | | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 1192 | | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv6 value '{}'", | 1193 | | ipv6_str.to_string_view()); | 1194 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 1195 | | col_res_data[i] = 0; // '::' | 1196 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 1197 | | res_null_map_data[i] = 1; | 1198 | | } | 1199 | | } | 1200 | | } | 1201 | 818 | } | 1202 | | | 1203 | 58 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 1204 | 58 | block.replace_by_position( | 1205 | 58 | result, ColumnNullable::create(std::move(col_res), std::move(res_null_map))); | 1206 | | } else { | 1207 | | block.replace_by_position(result, std::move(col_res)); | 1208 | | } | 1209 | | | 1210 | 58 | return Status::OK(); | 1211 | 44 | } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE0ELNS_13PrimitiveTypeE37EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 1134 | 20 | uint32_t result, size_t input_rows_count) const override { | 1135 | 20 | const auto& addr_column_with_type_and_name = block.get_by_position(arguments[0]); | 1136 | 20 | const ColumnPtr& addr_column = addr_column_with_type_and_name.column; | 1137 | 20 | const ColumnString* str_addr_column = nullptr; | 1138 | 20 | const NullMap* addr_null_map = nullptr; | 1139 | | | 1140 | 20 | if (addr_column_with_type_and_name.type->is_nullable()) { | 1141 | 7 | const auto* addr_column_nullable = | 1142 | 7 | assert_cast<const ColumnNullable*>(addr_column.get()); | 1143 | 7 | str_addr_column = assert_cast<const ColumnString*>( | 1144 | 7 | addr_column_nullable->get_nested_column_ptr().get()); | 1145 | 7 | addr_null_map = &addr_column_nullable->get_null_map_data(); | 1146 | 13 | } else { | 1147 | 13 | str_addr_column = assert_cast<const ColumnString*>(addr_column.get()); | 1148 | 13 | } | 1149 | | | 1150 | 20 | auto col_res = ColumnVector<PType>::create(input_rows_count, 0); | 1151 | 20 | auto res_null_map = ColumnUInt8::create(input_rows_count, 0); | 1152 | 20 | auto& col_res_data = col_res->get_data(); | 1153 | 20 | auto& res_null_map_data = res_null_map->get_data(); | 1154 | | | 1155 | 145 | for (size_t i = 0; i < input_rows_count; ++i) { | 1156 | 125 | if (addr_null_map && (*addr_null_map)[i]) { | 1157 | 2 | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 1158 | 2 | throw Exception(ErrorCode::INVALID_ARGUMENT, | 1159 | 2 | "The arguments of function {} must be String, not NULL", | 1160 | 2 | get_name()); | 1161 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 1162 | | col_res_data[i] = 0; // '0.0.0.0' or '::' | 1163 | | continue; | 1164 | | } else { | 1165 | | res_null_map_data[i] = 1; | 1166 | | continue; | 1167 | | } | 1168 | 2 | } | 1169 | | | 1170 | | if constexpr (PType == TYPE_IPV4) { | 1171 | | StringRef ipv4_str = str_addr_column->get_data_at(i); | 1172 | | IPv4 ipv4_val = 0; | 1173 | | if (IPv4Value::from_string(ipv4_val, ipv4_str.data, ipv4_str.size)) { | 1174 | | col_res_data[i] = ipv4_val; | 1175 | | } else { | 1176 | | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 1177 | | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv4 value '{}'", | 1178 | | ipv4_str.to_string_view()); | 1179 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 1180 | | col_res_data[i] = 0; // '0.0.0.0' | 1181 | | } else { | 1182 | | res_null_map_data[i] = 1; | 1183 | | } | 1184 | | } | 1185 | 125 | } else { | 1186 | 125 | StringRef ipv6_str = str_addr_column->get_data_at(i); | 1187 | 125 | IPv6 ipv6_val = 0; | 1188 | 125 | if (IPv6Value::from_string(ipv6_val, ipv6_str.data, ipv6_str.size)) { | 1189 | 119 | col_res_data[i] = ipv6_val; | 1190 | 119 | } else { | 1191 | 6 | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 1192 | 6 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv6 value '{}'", | 1193 | 6 | ipv6_str.to_string_view()); | 1194 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 1195 | | col_res_data[i] = 0; // '::' | 1196 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 1197 | | res_null_map_data[i] = 1; | 1198 | | } | 1199 | 6 | } | 1200 | 125 | } | 1201 | 125 | } | 1202 | | | 1203 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 1204 | | block.replace_by_position( | 1205 | | result, ColumnNullable::create(std::move(col_res), std::move(res_null_map))); | 1206 | 20 | } else { | 1207 | 20 | block.replace_by_position(result, std::move(col_res)); | 1208 | 20 | } | 1209 | | | 1210 | 20 | return Status::OK(); | 1211 | 20 | } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE1ELNS_13PrimitiveTypeE37EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 1134 | 36 | uint32_t result, size_t input_rows_count) const override { | 1135 | 36 | const auto& addr_column_with_type_and_name = block.get_by_position(arguments[0]); | 1136 | 36 | const ColumnPtr& addr_column = addr_column_with_type_and_name.column; | 1137 | 36 | const ColumnString* str_addr_column = nullptr; | 1138 | 36 | const NullMap* addr_null_map = nullptr; | 1139 | | | 1140 | 36 | if (addr_column_with_type_and_name.type->is_nullable()) { | 1141 | 28 | const auto* addr_column_nullable = | 1142 | 28 | assert_cast<const ColumnNullable*>(addr_column.get()); | 1143 | 28 | str_addr_column = assert_cast<const ColumnString*>( | 1144 | 28 | addr_column_nullable->get_nested_column_ptr().get()); | 1145 | 28 | addr_null_map = &addr_column_nullable->get_null_map_data(); | 1146 | 28 | } else { | 1147 | 8 | str_addr_column = assert_cast<const ColumnString*>(addr_column.get()); | 1148 | 8 | } | 1149 | | | 1150 | 36 | auto col_res = ColumnVector<PType>::create(input_rows_count, 0); | 1151 | 36 | auto res_null_map = ColumnUInt8::create(input_rows_count, 0); | 1152 | 36 | auto& col_res_data = col_res->get_data(); | 1153 | 36 | auto& res_null_map_data = res_null_map->get_data(); | 1154 | | | 1155 | 850 | for (size_t i = 0; i < input_rows_count; ++i) { | 1156 | 802 | if (addr_null_map && (*addr_null_map)[i]) { | 1157 | | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 1158 | | throw Exception(ErrorCode::INVALID_ARGUMENT, | 1159 | | "The arguments of function {} must be String, not NULL", | 1160 | | get_name()); | 1161 | 12 | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 1162 | 12 | col_res_data[i] = 0; // '0.0.0.0' or '::' | 1163 | 12 | continue; | 1164 | | } else { | 1165 | | res_null_map_data[i] = 1; | 1166 | | continue; | 1167 | | } | 1168 | 12 | } | 1169 | | | 1170 | | if constexpr (PType == TYPE_IPV4) { | 1171 | | StringRef ipv4_str = str_addr_column->get_data_at(i); | 1172 | | IPv4 ipv4_val = 0; | 1173 | | if (IPv4Value::from_string(ipv4_val, ipv4_str.data, ipv4_str.size)) { | 1174 | | col_res_data[i] = ipv4_val; | 1175 | | } else { | 1176 | | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 1177 | | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv4 value '{}'", | 1178 | | ipv4_str.to_string_view()); | 1179 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 1180 | | col_res_data[i] = 0; // '0.0.0.0' | 1181 | | } else { | 1182 | | res_null_map_data[i] = 1; | 1183 | | } | 1184 | | } | 1185 | 802 | } else { | 1186 | 802 | StringRef ipv6_str = str_addr_column->get_data_at(i); | 1187 | 802 | IPv6 ipv6_val = 0; | 1188 | 802 | if (IPv6Value::from_string(ipv6_val, ipv6_str.data, ipv6_str.size)) { | 1189 | 195 | col_res_data[i] = ipv6_val; | 1190 | 607 | } else { | 1191 | | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 1192 | | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv6 value '{}'", | 1193 | | ipv6_str.to_string_view()); | 1194 | 607 | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 1195 | 607 | col_res_data[i] = 0; // '::' | 1196 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 1197 | | res_null_map_data[i] = 1; | 1198 | | } | 1199 | 607 | } | 1200 | 802 | } | 1201 | 802 | } | 1202 | | | 1203 | | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 1204 | | block.replace_by_position( | 1205 | | result, ColumnNullable::create(std::move(col_res), std::move(res_null_map))); | 1206 | 48 | } else { | 1207 | 48 | block.replace_by_position(result, std::move(col_res)); | 1208 | 48 | } | 1209 | | | 1210 | 48 | return Status::OK(); | 1211 | 36 | } |
_ZNK5doris12FunctionToIPILNS_22IPConvertExceptionModeE2ELNS_13PrimitiveTypeE37EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 1134 | 40 | uint32_t result, size_t input_rows_count) const override { | 1135 | 40 | const auto& addr_column_with_type_and_name = block.get_by_position(arguments[0]); | 1136 | 40 | const ColumnPtr& addr_column = addr_column_with_type_and_name.column; | 1137 | 40 | const ColumnString* str_addr_column = nullptr; | 1138 | 40 | const NullMap* addr_null_map = nullptr; | 1139 | | | 1140 | 40 | if (addr_column_with_type_and_name.type->is_nullable()) { | 1141 | 32 | const auto* addr_column_nullable = | 1142 | 32 | assert_cast<const ColumnNullable*>(addr_column.get()); | 1143 | 32 | str_addr_column = assert_cast<const ColumnString*>( | 1144 | 32 | addr_column_nullable->get_nested_column_ptr().get()); | 1145 | 32 | addr_null_map = &addr_column_nullable->get_null_map_data(); | 1146 | 32 | } else { | 1147 | 8 | str_addr_column = assert_cast<const ColumnString*>(addr_column.get()); | 1148 | 8 | } | 1149 | | | 1150 | 40 | auto col_res = ColumnVector<PType>::create(input_rows_count, 0); | 1151 | 40 | auto res_null_map = ColumnUInt8::create(input_rows_count, 0); | 1152 | 40 | auto& col_res_data = col_res->get_data(); | 1153 | 40 | auto& res_null_map_data = res_null_map->get_data(); | 1154 | | | 1155 | 864 | for (size_t i = 0; i < input_rows_count; ++i) { | 1156 | 811 | if (addr_null_map && (*addr_null_map)[i]) { | 1157 | | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 1158 | | throw Exception(ErrorCode::INVALID_ARGUMENT, | 1159 | | "The arguments of function {} must be String, not NULL", | 1160 | | get_name()); | 1161 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 1162 | | col_res_data[i] = 0; // '0.0.0.0' or '::' | 1163 | | continue; | 1164 | 13 | } else { | 1165 | 13 | res_null_map_data[i] = 1; | 1166 | 13 | continue; | 1167 | 13 | } | 1168 | 13 | } | 1169 | | | 1170 | | if constexpr (PType == TYPE_IPV4) { | 1171 | | StringRef ipv4_str = str_addr_column->get_data_at(i); | 1172 | | IPv4 ipv4_val = 0; | 1173 | | if (IPv4Value::from_string(ipv4_val, ipv4_str.data, ipv4_str.size)) { | 1174 | | col_res_data[i] = ipv4_val; | 1175 | | } else { | 1176 | | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 1177 | | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv4 value '{}'", | 1178 | | ipv4_str.to_string_view()); | 1179 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 1180 | | col_res_data[i] = 0; // '0.0.0.0' | 1181 | | } else { | 1182 | | res_null_map_data[i] = 1; | 1183 | | } | 1184 | | } | 1185 | 811 | } else { | 1186 | 811 | StringRef ipv6_str = str_addr_column->get_data_at(i); | 1187 | 811 | IPv6 ipv6_val = 0; | 1188 | 811 | if (IPv6Value::from_string(ipv6_val, ipv6_str.data, ipv6_str.size)) { | 1189 | 203 | col_res_data[i] = ipv6_val; | 1190 | 608 | } else { | 1191 | | if constexpr (exception_mode == IPConvertExceptionMode::Throw) { | 1192 | | throw Exception(ErrorCode::INVALID_ARGUMENT, "Invalid IPv6 value '{}'", | 1193 | | ipv6_str.to_string_view()); | 1194 | | } else if constexpr (exception_mode == IPConvertExceptionMode::Default) { | 1195 | | col_res_data[i] = 0; // '::' | 1196 | 608 | } else if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 1197 | 608 | res_null_map_data[i] = 1; | 1198 | 608 | } | 1199 | 608 | } | 1200 | 811 | } | 1201 | 811 | } | 1202 | | | 1203 | 53 | if constexpr (exception_mode == IPConvertExceptionMode::Null) { | 1204 | 53 | block.replace_by_position( | 1205 | 53 | result, ColumnNullable::create(std::move(col_res), std::move(res_null_map))); | 1206 | | } else { | 1207 | | block.replace_by_position(result, std::move(col_res)); | 1208 | | } | 1209 | | | 1210 | 53 | return Status::OK(); | 1211 | 40 | } |
|
1212 | | }; |
1213 | | |
1214 | | class FunctionIPv4ToIPv6 : public IFunction { |
1215 | | public: |
1216 | | static constexpr auto name = "ipv4_to_ipv6"; |
1217 | 16 | static FunctionPtr create() { return std::make_shared<FunctionIPv4ToIPv6>(); } |
1218 | | |
1219 | 1 | String get_name() const override { return name; } |
1220 | | |
1221 | 7 | size_t get_number_of_arguments() const override { return 1; } |
1222 | | |
1223 | 7 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
1224 | 7 | return std::make_shared<DataTypeIPv6>(); |
1225 | 7 | } |
1226 | | |
1227 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
1228 | 14 | uint32_t result, size_t input_rows_count) const override { |
1229 | 14 | const auto& ipv4_column_with_type_and_name = block.get_by_position(arguments[0]); |
1230 | 14 | const auto& [ipv4_column, ipv4_const] = |
1231 | 14 | unpack_if_const(ipv4_column_with_type_and_name.column); |
1232 | 14 | const auto* ipv4_addr_column = assert_cast<const ColumnIPv4*>(ipv4_column.get()); |
1233 | 14 | const auto& ipv4_column_data = ipv4_addr_column->get_data(); |
1234 | 14 | auto col_res = ColumnIPv6::create(input_rows_count, 0); |
1235 | 14 | auto& col_res_data = col_res->get_data(); |
1236 | | |
1237 | 48 | for (size_t i = 0; i < input_rows_count; ++i) { |
1238 | 34 | auto ipv4_idx = index_check_const(i, ipv4_const); |
1239 | 34 | map_ipv4_to_ipv6(ipv4_column_data[ipv4_idx], |
1240 | 34 | reinterpret_cast<UInt8*>(&col_res_data[i])); |
1241 | 34 | } |
1242 | | |
1243 | 14 | block.replace_by_position(result, std::move(col_res)); |
1244 | 14 | return Status::OK(); |
1245 | 14 | } |
1246 | | }; |
1247 | | |
1248 | | class FunctionCutIPv6 : public IFunction { |
1249 | | public: |
1250 | | static constexpr auto name = "cut_ipv6"; |
1251 | 14 | static FunctionPtr create() { return std::make_shared<FunctionCutIPv6>(); } |
1252 | | |
1253 | 1 | String get_name() const override { return name; } |
1254 | | |
1255 | 5 | size_t get_number_of_arguments() const override { return 3; } |
1256 | | |
1257 | 6 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
1258 | 6 | DataTypePtr result = std::make_shared<DataTypeString>(); |
1259 | 6 | if (arguments[0]->is_nullable() || arguments[1]->is_nullable() || |
1260 | 6 | arguments[2]->is_nullable()) { |
1261 | 6 | return make_nullable(result); |
1262 | 6 | } |
1263 | 0 | return result; |
1264 | 6 | } |
1265 | | |
1266 | 16 | bool use_default_implementation_for_nulls() const override { return false; } |
1267 | | |
1268 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
1269 | 12 | uint32_t result, size_t input_rows_count) const override { |
1270 | 12 | const auto& ipv6_column_with_type_and_name = block.get_by_position(arguments[0]); |
1271 | 12 | const auto& bytes_to_cut_for_ipv6_column_with_type_and_name = |
1272 | 12 | block.get_by_position(arguments[1]); |
1273 | 12 | const auto& bytes_to_cut_for_ipv4_column_with_type_and_name = |
1274 | 12 | block.get_by_position(arguments[2]); |
1275 | | |
1276 | 12 | const auto ipv6 = ColumnView<TYPE_IPV6>::create(ipv6_column_with_type_and_name.column); |
1277 | 12 | const auto bytes_to_cut_for_ipv6 = ColumnView<TYPE_TINYINT>::create( |
1278 | 12 | bytes_to_cut_for_ipv6_column_with_type_and_name.column); |
1279 | 12 | const auto bytes_to_cut_for_ipv4 = ColumnView<TYPE_TINYINT>::create( |
1280 | 12 | bytes_to_cut_for_ipv4_column_with_type_and_name.column); |
1281 | | |
1282 | 12 | auto col_res = ColumnString::create(); |
1283 | 12 | ColumnString::Chars& chars_res = col_res->get_chars(); |
1284 | 12 | ColumnString::Offsets& offsets_res = col_res->get_offsets(); |
1285 | 12 | chars_res.resize(input_rows_count * (IPV6_MAX_TEXT_LENGTH + 1)); // + 1 for ending '\0' |
1286 | 12 | offsets_res.resize(input_rows_count); |
1287 | 12 | const bool result_nullable = block.get_by_position(result).type->is_nullable(); |
1288 | 12 | ColumnUInt8::MutablePtr null_map; |
1289 | 12 | if (result_nullable) { |
1290 | 12 | null_map = ColumnUInt8::create(input_rows_count, 0); |
1291 | 12 | } |
1292 | 12 | auto* begin = reinterpret_cast<char*>(chars_res.data()); |
1293 | 12 | auto* pos = begin; |
1294 | | |
1295 | 12 | if (result_nullable) { |
1296 | 12 | execute_impl<true>( |
1297 | 12 | ipv6, bytes_to_cut_for_ipv6, bytes_to_cut_for_ipv4, input_rows_count, |
1298 | 12 | offsets_res, begin, pos, bytes_to_cut_for_ipv6_column_with_type_and_name.type, |
1299 | 12 | bytes_to_cut_for_ipv4_column_with_type_and_name.type, &null_map->get_data()); |
1300 | 12 | } else { |
1301 | 0 | execute_impl<false>(ipv6, bytes_to_cut_for_ipv6, bytes_to_cut_for_ipv4, |
1302 | 0 | input_rows_count, offsets_res, begin, pos, |
1303 | 0 | bytes_to_cut_for_ipv6_column_with_type_and_name.type, |
1304 | 0 | bytes_to_cut_for_ipv4_column_with_type_and_name.type, nullptr); |
1305 | 0 | } |
1306 | | |
1307 | 12 | chars_res.resize(offsets_res[offsets_res.size() - 1]); |
1308 | | |
1309 | 12 | if (result_nullable) { |
1310 | 12 | block.replace_by_position( |
1311 | 12 | result, ColumnNullable::create(std::move(col_res), std::move(null_map))); |
1312 | 12 | } else { |
1313 | 0 | block.replace_by_position(result, std::move(col_res)); |
1314 | 0 | } |
1315 | 12 | return Status::OK(); |
1316 | 12 | } |
1317 | | |
1318 | | private: |
1319 | | template <bool ResultNullable> |
1320 | | void execute_impl(const ColumnView<TYPE_IPV6>& ipv6, |
1321 | | const ColumnView<TYPE_TINYINT>& bytes_to_cut_for_ipv6, |
1322 | | const ColumnView<TYPE_TINYINT>& bytes_to_cut_for_ipv4, |
1323 | | size_t input_rows_count, ColumnString::Offsets& offsets_res, char* begin, |
1324 | | char*& pos, const DataTypePtr& bytes_to_cut_for_ipv6_type, |
1325 | | const DataTypePtr& bytes_to_cut_for_ipv4_type, |
1326 | 12 | ColumnUInt8::Container* nulls) const { |
1327 | 51 | for (size_t i = 0; i < input_rows_count; ++i) { |
1328 | 33 | if constexpr (ResultNullable) { |
1329 | 33 | if (ipv6.is_null_at(i) || bytes_to_cut_for_ipv6.is_null_at(i) || |
1330 | 33 | bytes_to_cut_for_ipv4.is_null_at(i)) { |
1331 | 6 | (*nulls)[i] = 1; |
1332 | 6 | offsets_res[i] = cast_set<uint32_t>(pos - begin); |
1333 | 6 | continue; |
1334 | 6 | } |
1335 | 33 | } |
1336 | | // Convert from Doris little-endian storage before formatting in big-endian order. |
1337 | 27 | auto val_128 = ipv6.value_at(i); |
1338 | 33 | auto* address = reinterpret_cast<unsigned char*>(&val_128); |
1339 | 33 | const Int8 bytes_to_cut_for_ipv6_count = bytes_to_cut_for_ipv6.value_at(i); |
1340 | 33 | const Int8 bytes_to_cut_for_ipv4_count = bytes_to_cut_for_ipv4.value_at(i); |
1341 | | |
1342 | 33 | if (bytes_to_cut_for_ipv6_count > IPV6_BINARY_LENGTH) [[unlikely]] { |
1343 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, |
1344 | 0 | "Illegal value for argument 2 {} of function {}", |
1345 | 0 | bytes_to_cut_for_ipv6_type->get_name(), get_name()); |
1346 | 0 | } |
1347 | 33 | if (bytes_to_cut_for_ipv4_count > IPV6_BINARY_LENGTH) [[unlikely]] { |
1348 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, |
1349 | 0 | "Illegal value for argument 3 {} of function {}", |
1350 | 0 | bytes_to_cut_for_ipv4_type->get_name(), get_name()); |
1351 | 0 | } |
1352 | | |
1353 | 33 | const UInt8 bytes_to_cut_count = is_ipv4_mapped(address) ? bytes_to_cut_for_ipv4_count |
1354 | 33 | : bytes_to_cut_for_ipv6_count; |
1355 | 33 | cut_address(address, pos, bytes_to_cut_count); |
1356 | 33 | offsets_res[i] = cast_set<uint32_t>(pos - begin); |
1357 | 33 | } |
1358 | 12 | } _ZNK5doris15FunctionCutIPv612execute_implILb1EEEvRKNS_10ColumnViewILNS_13PrimitiveTypeE37EEERKNS2_ILS3_3EEES9_mRNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEPcRSG_RKSt10shared_ptrIKNS_9IDataTypeEESN_PNSA_IhLm4096ESD_Lm16ELm15EEE Line | Count | Source | 1326 | 12 | ColumnUInt8::Container* nulls) const { | 1327 | 51 | for (size_t i = 0; i < input_rows_count; ++i) { | 1328 | 33 | if constexpr (ResultNullable) { | 1329 | 33 | if (ipv6.is_null_at(i) || bytes_to_cut_for_ipv6.is_null_at(i) || | 1330 | 33 | bytes_to_cut_for_ipv4.is_null_at(i)) { | 1331 | 6 | (*nulls)[i] = 1; | 1332 | 6 | offsets_res[i] = cast_set<uint32_t>(pos - begin); | 1333 | 6 | continue; | 1334 | 6 | } | 1335 | 33 | } | 1336 | | // Convert from Doris little-endian storage before formatting in big-endian order. | 1337 | 27 | auto val_128 = ipv6.value_at(i); | 1338 | 33 | auto* address = reinterpret_cast<unsigned char*>(&val_128); | 1339 | 33 | const Int8 bytes_to_cut_for_ipv6_count = bytes_to_cut_for_ipv6.value_at(i); | 1340 | 33 | const Int8 bytes_to_cut_for_ipv4_count = bytes_to_cut_for_ipv4.value_at(i); | 1341 | | | 1342 | 33 | if (bytes_to_cut_for_ipv6_count > IPV6_BINARY_LENGTH) [[unlikely]] { | 1343 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, | 1344 | 0 | "Illegal value for argument 2 {} of function {}", | 1345 | 0 | bytes_to_cut_for_ipv6_type->get_name(), get_name()); | 1346 | 0 | } | 1347 | 33 | if (bytes_to_cut_for_ipv4_count > IPV6_BINARY_LENGTH) [[unlikely]] { | 1348 | 0 | throw Exception(ErrorCode::INVALID_ARGUMENT, | 1349 | 0 | "Illegal value for argument 3 {} of function {}", | 1350 | 0 | bytes_to_cut_for_ipv4_type->get_name(), get_name()); | 1351 | 0 | } | 1352 | | | 1353 | 33 | const UInt8 bytes_to_cut_count = is_ipv4_mapped(address) ? bytes_to_cut_for_ipv4_count | 1354 | 33 | : bytes_to_cut_for_ipv6_count; | 1355 | 33 | cut_address(address, pos, bytes_to_cut_count); | 1356 | 33 | offsets_res[i] = cast_set<uint32_t>(pos - begin); | 1357 | 33 | } | 1358 | 12 | } |
Unexecuted instantiation: _ZNK5doris15FunctionCutIPv612execute_implILb0EEEvRKNS_10ColumnViewILNS_13PrimitiveTypeE37EEERKNS2_ILS3_3EEES9_mRNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEPcRSG_RKSt10shared_ptrIKNS_9IDataTypeEESN_PNSA_IhLm4096ESD_Lm16ELm15EEE |
1359 | | |
1360 | 27 | static bool is_ipv4_mapped(const UInt8* address) { |
1361 | 27 | return (LittleEndian::Load64(address + 8) == 0) && |
1362 | 27 | ((LittleEndian::Load64(address) & 0xFFFFFFFF00000000ULL) == 0x0000FFFF00000000ULL); |
1363 | 27 | } |
1364 | | |
1365 | 27 | static void cut_address(unsigned char* address, char*& dst, UInt8 zeroed_tail_bytes_count) { |
1366 | 27 | format_ipv6(address, dst, zeroed_tail_bytes_count); |
1367 | 27 | } |
1368 | | }; |
1369 | | |
1370 | | class FunctionIPv6FromUInt128StringOrNull : public IFunction { |
1371 | | public: |
1372 | | static constexpr auto name = "ipv6_from_uint128_string_or_null"; |
1373 | 11 | static FunctionPtr create() { return std::make_shared<FunctionIPv6FromUInt128StringOrNull>(); } |
1374 | | |
1375 | 1 | String get_name() const override { return name; } |
1376 | | |
1377 | 2 | size_t get_number_of_arguments() const override { return 1; } |
1378 | | |
1379 | 2 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
1380 | 2 | return std::make_shared<DataTypeNullable>(std::make_shared<DataTypeIPv6>()); |
1381 | 2 | } |
1382 | | |
1383 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
1384 | 6 | uint32_t result, size_t input_rows_count) const override { |
1385 | 6 | const auto& ipv6_column_with_type_and_name = block.get_by_position(arguments[0]); |
1386 | 6 | const auto& [ipv6_column, ipv6_const] = |
1387 | 6 | unpack_if_const(ipv6_column_with_type_and_name.column); |
1388 | 6 | const auto* ipv6_addr_column = assert_cast<const ColumnString*>(ipv6_column.get()); |
1389 | | // result is nullable column |
1390 | 6 | auto col_res_nested = ColumnIPv6::create(input_rows_count, 0); |
1391 | 6 | auto col_res_null_map = ColumnUInt8::create(input_rows_count, 1); |
1392 | 6 | auto& col_res_data = col_res_nested->get_data(); |
1393 | 6 | auto& res_null_map_data = col_res_null_map->get_data(); |
1394 | | |
1395 | 216 | for (size_t i = 0; i < input_rows_count; ++i) { |
1396 | 210 | IPv6 ipv6 = 0; |
1397 | 210 | auto ipv6_idx = index_check_const(i, ipv6_const); |
1398 | 210 | StringRef uint128_string = ipv6_addr_column->get_data_at(ipv6_idx); |
1399 | 210 | if (!IPv6Value::from_uint128_string(ipv6, uint128_string.data, uint128_string.size)) { |
1400 | 0 | VLOG_DEBUG << "Invalid uin128 IPv6 value '" << uint128_string.to_string_view() |
1401 | 0 | << "'"; |
1402 | | // we should set null to the result not throw exception for load senior |
1403 | 210 | } else { |
1404 | 210 | col_res_data[i] = ipv6; |
1405 | 210 | res_null_map_data[i] = 0; |
1406 | 210 | } |
1407 | 210 | } |
1408 | | |
1409 | 6 | block.replace_by_position(result, ColumnNullable::create(std::move(col_res_nested), |
1410 | 6 | std::move(col_res_null_map))); |
1411 | 6 | return Status::OK(); |
1412 | 6 | } |
1413 | | }; |
1414 | | |
1415 | | } // namespace doris |