| 161 | ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return {1, 2}; } |
| 162 | |
| 163 | ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override |
| 164 | { |
| 165 | const auto & col_type_name = arguments[0]; |
| 166 | const ColumnPtr & column = col_type_name.column; |
| 167 | |
| 168 | const auto & col_ipv6_zeroed_tail_bytes_type = arguments[1]; |
| 169 | const auto & col_ipv6_zeroed_tail_bytes = col_ipv6_zeroed_tail_bytes_type.column; |
| 170 | const auto & col_ipv4_zeroed_tail_bytes_type = arguments[2]; |
| 171 | const auto & col_ipv4_zeroed_tail_bytes = col_ipv4_zeroed_tail_bytes_type.column; |
| 172 | |
| 173 | const auto * col_in_str = checkAndGetColumn<ColumnFixedString>(column.get()); |
| 174 | const auto * col_in_ip = checkAndGetColumn<ColumnIPv6>(column.get()); |
| 175 | |
| 176 | if (!col_in_str && !col_in_ip) |
| 177 | throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of argument of function {}", |
| 178 | arguments[0].column->getName(), getName()); |
| 179 | |
| 180 | if (col_in_str && col_in_str->getN() != IPV6_BINARY_LENGTH) |
| 181 | throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, |
| 182 | "Illegal type {} of column {} argument of function {}, expected FixedString({})", |
| 183 | col_type_name.type->getName(), col_in_str->getName(), |
| 184 | getName(), toString(IPV6_BINARY_LENGTH)); |
| 185 | |
| 186 | const auto * ipv6_zeroed_tail_bytes = checkAndGetColumnConst<ColumnVector<UInt8>>(col_ipv6_zeroed_tail_bytes.get()); |
| 187 | if (!ipv6_zeroed_tail_bytes) |
| 188 | throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type {} of argument 2 of function {}", |
| 189 | col_ipv6_zeroed_tail_bytes_type.type->getName(), getName()); |
| 190 | |
| 191 | UInt8 ipv6_zeroed_tail_bytes_count = ipv6_zeroed_tail_bytes->getValue<UInt8>(); |
| 192 | if (ipv6_zeroed_tail_bytes_count > IPV6_BINARY_LENGTH) |
| 193 | throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal value for argument 2 {} of function {}", |
| 194 | col_ipv6_zeroed_tail_bytes_type.type->getName(), getName()); |
| 195 | |
| 196 | const auto * ipv4_zeroed_tail_bytes = checkAndGetColumnConst<ColumnVector<UInt8>>(col_ipv4_zeroed_tail_bytes.get()); |
| 197 | if (!ipv4_zeroed_tail_bytes) |
| 198 | throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type {} of argument 3 of function {}", |
| 199 | col_ipv4_zeroed_tail_bytes_type.type->getName(), getName()); |
| 200 | |
| 201 | UInt8 ipv4_zeroed_tail_bytes_count = ipv4_zeroed_tail_bytes->getValue<UInt8>(); |
| 202 | if (ipv4_zeroed_tail_bytes_count > IPV6_BINARY_LENGTH) |
| 203 | throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal value for argument 3 {} of function {}", |
| 204 | col_ipv4_zeroed_tail_bytes_type.type->getName(), getName()); |
| 205 | |
| 206 | auto col_res = ColumnString::create(); |
| 207 | ColumnString::Chars & vec_res = col_res->getChars(); |
| 208 | ColumnString::Offsets & offsets_res = col_res->getOffsets(); |
| 209 | vec_res.resize(input_rows_count * (IPV6_MAX_TEXT_LENGTH + 1)); |
| 210 | offsets_res.resize(input_rows_count); |
| 211 | |
| 212 | auto * begin = reinterpret_cast<char *>(vec_res.data()); |
| 213 | auto * pos = begin; |
| 214 | |
| 215 | if (col_in_str) |
| 216 | { |
| 217 | const auto & vec_in = col_in_str->getChars(); |
| 218 | |
| 219 | for (size_t offset = 0, i = 0; i < input_rows_count; offset += IPV6_BINARY_LENGTH, ++i) |
| 220 | { |