Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #46087 to 23.1: Allow bloom filter for IPv4 and IPv6 #46751

Merged
merged 1 commit into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Interpreters/BloomFilterHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ struct BloomFilterHash
else if (which.isFloat32()) return build_hash_column(getNumberTypeHash<Float64, Float64>(field));
else if (which.isFloat64()) return build_hash_column(getNumberTypeHash<Float64, Float64>(field));
else if (which.isUUID()) return build_hash_column(getNumberTypeHash<UUID, UUID>(field));
else if (which.isIPv4()) return build_hash_column(getNumberTypeHash<IPv4, IPv4>(field));
else if (which.isIPv6()) return build_hash_column(getNumberTypeHash<IPv6, IPv6>(field));
else if (which.isString()) return build_hash_column(getStringTypeHash(field));
else if (which.isFixedString()) return build_hash_column(getFixedStringTypeHash(field, data_type));
else throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unexpected type {} of bloom filter index.", data_type->getName());
Expand Down Expand Up @@ -156,6 +158,8 @@ struct BloomFilterHash
else if (which.isFloat32()) getNumberTypeHash<Float32, is_first>(column, vec, pos);
else if (which.isFloat64()) getNumberTypeHash<Float64, is_first>(column, vec, pos);
else if (which.isUUID()) getNumberTypeHash<UUID, is_first>(column, vec, pos);
else if (which.isIPv4()) getNumberTypeHash<IPv4, is_first>(column, vec, pos);
else if (which.isIPv6()) getNumberTypeHash<IPv6, is_first>(column, vec, pos);
else if (which.isString()) getStringTypeHash<is_first>(column, vec, pos);
else if (which.isFixedString()) getStringTypeHash<is_first>(column, vec, pos);
else throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unexpected type {} of bloom filter index.", data_type->getName());
Expand Down
3 changes: 2 additions & 1 deletion src/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ static void assertIndexColumnsType(const Block & header)
WhichDataType which(actual_type);

if (!which.isUInt() && !which.isInt() && !which.isString() && !which.isFixedString() && !which.isFloat() &&
!which.isDate() && !which.isDateTime() && !which.isDateTime64() && !which.isEnum() && !which.isUUID())
!which.isDate() && !which.isDateTime() && !which.isDateTime64() && !which.isEnum() && !which.isUUID() &&
!which.isIPv4() && !which.isIPv6())
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Unexpected type {} of bloom filter index.", type->getName());
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/queries/0_stateless/02559_ip_types_bloom.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 1.1.1.1 ::1
18 changes: 18 additions & 0 deletions tests/queries/0_stateless/02559_ip_types_bloom.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
DROP TABLE IF EXISTS ip_bloom;

CREATE TABLE ip_bloom
(
`a` UInt32,
`ip4` Nullable(IPv4),
`ip6` Nullable(IPv6),
INDEX x4 ip4 TYPE bloom_filter(0.1) GRANULARITY 3,
INDEX x6 ip6 TYPE bloom_filter(0.1) GRANULARITY 3
)
ENGINE = MergeTree
ORDER BY a;

INSERT INTO ip_bloom VALUES (1, '1.1.1.1', '::1');

SELECT * FROM ip_bloom;

DROP TABLE ip_bloom;