| 368 | } |
| 369 | |
| 370 | ColumnUInt8::Ptr IPAddressDictionary::hasKeys(const Columns & key_columns, const DataTypes & key_types) const |
| 371 | { |
| 372 | validateKeyTypes(key_types); |
| 373 | |
| 374 | const auto & first_column = key_columns.front(); |
| 375 | const size_t rows = first_column->size(); |
| 376 | |
| 377 | auto result = ColumnUInt8::create(rows); |
| 378 | auto & out = result->getData(); |
| 379 | |
| 380 | size_t keys_found = 0; |
| 381 | |
| 382 | TypeIndex type_id = first_column->getDataType(); |
| 383 | |
| 384 | if (type_id == TypeIndex::IPv4 || type_id == TypeIndex::UInt32) |
| 385 | { |
| 386 | uint8_t addrv6_buf[IPV6_BINARY_LENGTH]; |
| 387 | for (const auto i : collections::range(0, rows)) |
| 388 | { |
| 389 | auto addrv4 = *reinterpret_cast<const UInt32 *>(first_column->getDataAt(i).data()); |
| 390 | auto found = tryLookupIPv4(addrv4, addrv6_buf); |
| 391 | out[i] = (found != ipNotFound()); |
| 392 | keys_found += out[i]; |
| 393 | } |
| 394 | } |
| 395 | else if (type_id == TypeIndex::IPv6 || type_id == TypeIndex::FixedString) |
| 396 | { |
| 397 | for (const auto i : collections::range(0, rows)) |
| 398 | { |
| 399 | auto addr = first_column->getDataAt(i); |
| 400 | if (addr.size() != IPV6_BINARY_LENGTH) |
| 401 | throw Exception(ErrorCodes::TYPE_MISMATCH, "Expected key FixedString(16)"); |
| 402 | auto found = tryLookupIPv6(reinterpret_cast<const uint8_t *>(addr.data())); |
| 403 | out[i] = (found != ipNotFound()); |
| 404 | keys_found += out[i]; |
| 405 | } |
| 406 | } |
| 407 | else |
| 408 | throw Exception(ErrorCodes::TYPE_MISMATCH, "Expected key to be IPv4 (or UInt32) or IPv6 (or FixedString(16))"); |
| 409 | |
| 410 | query_count.fetch_add(rows, std::memory_order_relaxed); |
| 411 | found_count.fetch_add(keys_found, std::memory_order_relaxed); |
| 412 | |
| 413 | return result; |
| 414 | } |
| 415 | |
| 416 | void IPAddressDictionary::createAttributes() |
| 417 | { |
nothing calls this directly
no test coverage detected