diff --git a/dbms/src/Interpreters/BloomFilterHash.h b/dbms/src/Interpreters/BloomFilterHash.h index bd1100c7c68..816f27cd909 100644 --- a/dbms/src/Interpreters/BloomFilterHash.h +++ b/dbms/src/Interpreters/BloomFilterHash.h @@ -85,8 +85,15 @@ struct BloomFilterHash throw Exception("Unexpected type " + data_type->getName() + " of bloom filter index.", ErrorCodes::LOGICAL_ERROR); const auto & offsets = array_col->getOffsets(); - size_t offset = (pos == 0) ? 0 : offsets[pos - 1]; - limit = std::max(array_col->getData().size() - offset, limit); + limit = offsets[pos + limit - 1] - ((pos == 0) ? 0 : offsets[pos - 1]); + + if (limit == 0) + { + auto index_column = ColumnUInt64::create(1); + ColumnUInt64::Container & index_column_vec = index_column->getData(); + index_column_vec[0] = 0; + return index_column; + } } const ColumnPtr actual_col = BloomFilter::getPrimitiveColumn(column); diff --git a/dbms/tests/queries/0_stateless/01045_bloom_filter_null_array.reference b/dbms/tests/queries/0_stateless/01045_bloom_filter_null_array.reference new file mode 100644 index 00000000000..019468dc91b --- /dev/null +++ b/dbms/tests/queries/0_stateless/01045_bloom_filter_null_array.reference @@ -0,0 +1,5 @@ +7 +1 +2 +1 +0 diff --git a/dbms/tests/queries/0_stateless/01045_bloom_filter_null_array.sql b/dbms/tests/queries/0_stateless/01045_bloom_filter_null_array.sql new file mode 100644 index 00000000000..bf97e6be838 --- /dev/null +++ b/dbms/tests/queries/0_stateless/01045_bloom_filter_null_array.sql @@ -0,0 +1,18 @@ +SET allow_experimental_data_skipping_indices = 1; + + +DROP TABLE IF EXISTS test.bloom_filter_null_array; + +CREATE TABLE test.bloom_filter_null_array (v Array(LowCardinality(Nullable(String))), INDEX idx v TYPE bloom_filter(0.1) GRANULARITY 1) ENGINE = MergeTree() ORDER BY v; + +INSERT INTO test.bloom_filter_null_array VALUES ([]); +INSERT INTO test.bloom_filter_null_array VALUES (['1', '2']) ([]) ([]); +INSERT INTO test.bloom_filter_null_array VALUES ([]) ([]) (['2', '3']); + +SELECT COUNT() FROM test.bloom_filter_null_array; +SELECT COUNT() FROM test.bloom_filter_null_array WHERE has(v, '1'); +SELECT COUNT() FROM test.bloom_filter_null_array WHERE has(v, '2'); +SELECT COUNT() FROM test.bloom_filter_null_array WHERE has(v, '3'); +SELECT COUNT() FROM test.bloom_filter_null_array WHERE has(v, '4'); + +DROP TABLE IF EXISTS test.bloom_filter_null_array;