Fixed bloom_filter bug that counting error for Array(Nullable(String)).

This commit is contained in:
philip.han 2019-12-13 18:38:03 +09:00
parent 9534eb32a0
commit fe7ae014d8
3 changed files with 32 additions and 2 deletions

View File

@ -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);

View File

@ -0,0 +1,5 @@
7
1
2
1
0

View File

@ -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;