mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
validate type of arguments for minmax secondary index
This commit is contained in:
parent
f68d7f9412
commit
9a4dbc843a
@ -15,6 +15,7 @@ namespace DB
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int LOGICAL_ERROR;
|
||||
extern const int BAD_ARGUMENTS;
|
||||
}
|
||||
|
||||
|
||||
@ -217,7 +218,20 @@ MergeTreeIndexPtr minmaxIndexCreator(
|
||||
return std::make_shared<MergeTreeIndexMinMax>(index);
|
||||
}
|
||||
|
||||
void minmaxIndexValidator(const IndexDescription & /* index */, bool /* attach */)
|
||||
void minmaxIndexValidator(const IndexDescription & index, bool attach)
|
||||
{
|
||||
if (attach)
|
||||
return;
|
||||
|
||||
for (const auto & column : index.sample_block)
|
||||
{
|
||||
if (!column.type->isComparable())
|
||||
{
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS,
|
||||
"Data type of argument for minmax index must be comparable, got {} type for column {} instead",
|
||||
column.type->getName(), column.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
1
|
||||
5 10
|
||||
6 11
|
||||
7 12
|
||||
8 13
|
||||
9 14
|
@ -0,0 +1,36 @@
|
||||
DROP TABLE IF EXISTS t_index_agg_func;
|
||||
|
||||
CREATE TABLE t_index_agg_func
|
||||
(
|
||||
id UInt64,
|
||||
v AggregateFunction(avg, UInt64),
|
||||
INDEX idx_v v TYPE minmax GRANULARITY 1
|
||||
)
|
||||
ENGINE = AggregatingMergeTree ORDER BY id
|
||||
SETTINGS index_granularity = 4; -- { serverError BAD_ARGUMENTS }
|
||||
|
||||
CREATE TABLE t_index_agg_func
|
||||
(
|
||||
id UInt64,
|
||||
v AggregateFunction(avg, UInt64),
|
||||
)
|
||||
ENGINE = AggregatingMergeTree ORDER BY id
|
||||
SETTINGS index_granularity = 4;
|
||||
|
||||
ALTER TABLE t_index_agg_func ADD INDEX idx_v v TYPE minmax GRANULARITY 1; -- { serverError BAD_ARGUMENTS }
|
||||
|
||||
ALTER TABLE t_index_agg_func ADD INDEX idx_v finalizeAggregation(v) TYPE minmax GRANULARITY 1;
|
||||
|
||||
INSERT INTO t_index_agg_func SELECT number % 10, initializeAggregation('avgState', toUInt64(number % 20)) FROM numbers(1000);
|
||||
INSERT INTO t_index_agg_func SELECT number % 10, initializeAggregation('avgState', toUInt64(number % 20)) FROM numbers(1000, 1000);
|
||||
|
||||
OPTIMIZE TABLE t_index_agg_func FINAL;
|
||||
|
||||
SELECT count() FROM system.parts WHERE table = 't_index_agg_func' AND database = currentDatabase() AND active;
|
||||
|
||||
SET force_data_skipping_indices = 'idx_v';
|
||||
SET use_skip_indexes_if_final = 1;
|
||||
|
||||
SELECT id, finalizeAggregation(v) AS vv FROM t_index_agg_func FINAL WHERE vv >= 10 ORDER BY id;
|
||||
|
||||
DROP TABLE t_index_agg_func;
|
Loading…
Reference in New Issue
Block a user