Skip to content

Commit 02e6d1c

Browse files
authored
Merge pull request ClickHouse#77271 from Avogar/bloomfilter-array-equals
Fix bloom filter index with Array and not supported functions
2 parents 7b474dd + 21c58f0 commit 02e6d1c

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

src/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,24 @@
11
#include <Storages/MergeTree/MergeTreeIndexBloomFilter.h>
22

3-
#include <Columns/ColumnArray.h>
43
#include <Columns/ColumnConst.h>
5-
#include <Columns/ColumnFixedString.h>
6-
#include <Columns/ColumnNullable.h>
7-
#include <Columns/ColumnString.h>
84
#include <Columns/ColumnTuple.h>
95
#include <Columns/ColumnsNumber.h>
106
#include <Common/FieldAccurateComparison.h>
11-
#include <Common/HashTable/ClearableHashMap.h>
12-
#include <Common/HashTable/Hash.h>
137
#include <DataTypes/DataTypeArray.h>
14-
#include <DataTypes/DataTypeMap.h>
15-
#include <DataTypes/DataTypeNullable.h>
168
#include <DataTypes/DataTypeTuple.h>
17-
#include <DataTypes/DataTypesNumber.h>
189
#include <IO/WriteHelpers.h>
1910
#include <Interpreters/BloomFilterHash.h>
2011
#include <Interpreters/ExpressionAnalyzer.h>
2112
#include <Interpreters/PreparedSets.h>
2213
#include <Interpreters/Set.h>
23-
#include <Interpreters/TreeRewriter.h>
2414
#include <Interpreters/castColumn.h>
2515
#include <Interpreters/convertFieldToType.h>
2616
#include <Interpreters/misc.h>
27-
#include <Parsers/ASTFunction.h>
2817
#include <Parsers/ASTIdentifier.h>
29-
#include <Parsers/ASTLiteral.h>
30-
#include <Parsers/ASTSelectQuery.h>
3118
#include <Parsers/ASTSubquery.h>
3219
#include <Storages/MergeTree/MergeTreeData.h>
3320
#include <Storages/MergeTree/MergeTreeIndexUtils.h>
3421
#include <Storages/MergeTree/RPNBuilder.h>
35-
#include <base/types.h>
3622

3723

3824
namespace DB
@@ -42,7 +28,6 @@ namespace ErrorCodes
4228
{
4329
extern const int BAD_ARGUMENTS;
4430
extern const int ILLEGAL_COLUMN;
45-
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
4631
extern const int INCORRECT_QUERY;
4732
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
4833
extern const int LOGICAL_ERROR;
@@ -488,7 +473,7 @@ bool MergeTreeIndexConditionBloomFilter::traverseTreeIn(
488473
const auto & tuple_data_type = typeid_cast<const DataTypeTuple *>(type.get());
489474

490475
if (tuple_data_type->getElements().size() != key_node_function_arguments_size || tuple_column->getColumns().size() != key_node_function_arguments_size)
491-
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal types of arguments of function {}", function_name);
476+
return false;
492477

493478
bool match_with_subtype = false;
494479
const auto & sub_columns = tuple_column->getColumns();
@@ -675,7 +660,7 @@ bool MergeTreeIndexConditionBloomFilter::traverseTreeEquals(
675660
if (function_name == "has" || function_name == "indexOf")
676661
{
677662
if (!array_type)
678-
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "First argument for function {} must be an array.", function_name);
663+
return false;
679664

680665
/// We can treat `indexOf` function similar to `has`.
681666
/// But it is little more cumbersome, compare: `has(arr, elem)` and `indexOf(arr, elem) != 0`.
@@ -694,10 +679,10 @@ bool MergeTreeIndexConditionBloomFilter::traverseTreeEquals(
694679
else if (function_name == "hasAny" || function_name == "hasAll")
695680
{
696681
if (!array_type)
697-
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "First argument for function {} must be an array.", function_name);
682+
return false;
698683

699684
if (value_field.getType() != Field::Types::Array)
700-
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Second argument for function {} must be an array.", function_name);
685+
return false;
701686

702687
const DataTypePtr actual_type = BloomFilter::getPrimitiveType(array_type->getNestedType());
703688
ColumnPtr column;
@@ -728,8 +713,7 @@ bool MergeTreeIndexConditionBloomFilter::traverseTreeEquals(
728713
else
729714
{
730715
if (array_type)
731-
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
732-
"An array type of bloom_filter supports only has(), indexOf(), and hasAny() functions.");
716+
return false;
733717

734718
out.function = function_name == "equals" ? RPNElement::FUNCTION_EQUALS : RPNElement::FUNCTION_NOT_EQUALS;
735719
const DataTypePtr actual_type = BloomFilter::getPrimitiveType(index_type);
@@ -780,7 +764,7 @@ bool MergeTreeIndexConditionBloomFilter::traverseTreeEquals(
780764
const auto * value_tuple_data_type = typeid_cast<const DataTypeTuple *>(value_type.get());
781765

782766
if (tuple.size() != key_node_function_arguments_size)
783-
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal types of arguments of function {}", function_name);
767+
return false;
784768

785769
bool match_with_subtype = false;
786770
const DataTypes & subtypes = value_tuple_data_type->getElements();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
['s1']
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
create table test (x Array(String), index idx1 x type bloom_filter(0.025)) engine=MergeTree order by tuple();
2+
insert into test values (['s1']);
3+
select * from test where x = ['s1'];
4+

0 commit comments

Comments
 (0)