MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / hasKeys

Method hasKeys

src/Dictionaries/IPAddressDictionary.cpp:370–414  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

368}
369
370ColumnUInt8::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
416void IPAddressDictionary::createAttributes()
417{

Callers

nothing calls this directly

Calls 10

validateKeyTypesFunction · 0.85
rangeFunction · 0.85
createFunction · 0.50
ExceptionClass · 0.50
frontMethod · 0.45
sizeMethod · 0.45
getDataMethod · 0.45
getDataTypeMethod · 0.45
dataMethod · 0.45
getDataAtMethod · 0.45

Tested by

no test coverage detected