| 140 | } |
| 141 | |
| 142 | static void validateKeyTypes(const DataTypes & key_types) |
| 143 | { |
| 144 | if (key_types.empty() || key_types.size() > 2) |
| 145 | throw Exception(ErrorCodes::TYPE_MISMATCH, "Expected a single IP address or IP with mask"); |
| 146 | |
| 147 | TypeIndex type_id = key_types[0]->getTypeId(); |
| 148 | const auto * key_string = typeid_cast<const DataTypeFixedString *>(key_types[0].get()); |
| 149 | |
| 150 | if (type_id != TypeIndex::IPv4 && type_id != TypeIndex::UInt32 && type_id != TypeIndex::IPv6 && !(key_string && key_string->getN() == IPV6_BINARY_LENGTH)) |
| 151 | throw Exception(ErrorCodes::TYPE_MISMATCH, |
| 152 | "Key does not match, expected either IPv4 (or UInt32) or IPv6 (or FixedString(16))"); |
| 153 | |
| 154 | if (key_types.size() > 1) |
| 155 | { |
| 156 | const auto * mask_col_type = typeid_cast<const DataTypeUInt8 *>(key_types[1].get()); |
| 157 | if (mask_col_type == nullptr) |
| 158 | throw Exception(ErrorCodes::TYPE_MISMATCH, "Mask do not match, expected UInt8"); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | template <typename T, typename Comp> |
| 163 | size_t sortAndUnique(VectorWithMemoryTracking<T> & vec, Comp comp) |