Small fixes

This commit is contained in:
alesapin 2020-08-28 13:18:56 +03:00
parent 078b14610d
commit 0896b49533
6 changed files with 57 additions and 25 deletions

View File

@ -273,7 +273,7 @@ void DatabaseOrdinary::alterTable(const Context & context, const StorageID & tab
if (metadata.primary_key.definition_ast)
storage_ast.set(storage_ast.primary_key, metadata.primary_key.definition_ast);
if (metadata.sampling_key.definition_ast && storage_ast.sample_by)
if (metadata.sampling_key.definition_ast)
storage_ast.set(storage_ast.sample_by, metadata.sampling_key.definition_ast);
if (metadata.table_ttl.definition_ast)

View File

@ -1423,6 +1423,11 @@ void MergeTreeData::checkAlterIsPossible(const AlterCommands & commands, const S
}
if (command.type == AlterCommand::MODIFY_SAMPLE_BY)
{
if (!is_custom_partitioned)
throw Exception(
"ALTER MODIFY SAMPLE BY is not supported for default-partitioned tables created with the old syntax",
ErrorCodes::BAD_ARGUMENTS);
checkSampleExpression(new_metadata, getSettings()->compatibility_allow_sampling_expression_not_in_primary_key);
}
if (command.type == AlterCommand::ADD_INDEX && !is_custom_partitioned)

View File

@ -1,2 +0,0 @@
25 0 24 300 25
25 0 24 300 25

View File

@ -1,22 +0,0 @@
DROP TABLE IF EXISTS modify_sample;
SET min_insert_block_size_rows = 0, min_insert_block_size_bytes = 0;
SET max_block_size = 10;
CREATE TABLE modify_sample (d Date DEFAULT '2000-01-01', x UInt8) ENGINE = MergeTree PARTITION BY d ORDER BY x;
INSERT INTO modify_sample (x) SELECT toUInt8(number) AS x FROM system.numbers LIMIT 256;
SELECT count(), min(x), max(x), sum(x), uniqExact(x) FROM modify_sample SAMPLE 0.1; -- { serverError 141 }
ALTER TABLE modify_sample MODIFY SAMPLE BY x;
SELECT count(), min(x), max(x), sum(x), uniqExact(x) FROM modify_sample SAMPLE 0.1;
CREATE TABLE modify_sample_replicated (d Date DEFAULT '2000-01-01', x UInt8) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test_01430', 'modify_sample') PARTITION BY d ORDER BY x;
INSERT INTO modify_sample_replicated (x) SELECT toUInt8(number) AS x FROM system.numbers LIMIT 256;
SELECT count(), min(x), max(x), sum(x), uniqExact(x) FROM modify_sample_replicated SAMPLE 0.1; -- { serverError 141 }
ALTER TABLE modify_sample_replicated MODIFY SAMPLE BY x;
SELECT count(), min(x), max(x), sum(x), uniqExact(x) FROM modify_sample_replicated SAMPLE 0.1;
DROP TABLE modify_sample;

View File

@ -0,0 +1,5 @@
25 0 24 300 25
25 0 24 300 25
25 0 24 300 25
256 0 255 32640 256
256 0 255 32640 256

View File

@ -0,0 +1,46 @@
DROP TABLE IF EXISTS modify_sample;
SET min_insert_block_size_rows = 0, min_insert_block_size_bytes = 0;
SET max_block_size = 10;
CREATE TABLE modify_sample (d Date DEFAULT '2000-01-01', x UInt8) ENGINE = MergeTree PARTITION BY d ORDER BY x;
INSERT INTO modify_sample (x) SELECT toUInt8(number) AS x FROM system.numbers LIMIT 256;
SELECT count(), min(x), max(x), sum(x), uniqExact(x) FROM modify_sample SAMPLE 0.1; -- { serverError 141 }
ALTER TABLE modify_sample MODIFY SAMPLE BY x;
SELECT count(), min(x), max(x), sum(x), uniqExact(x) FROM modify_sample SAMPLE 0.1;
CREATE TABLE modify_sample_replicated (d Date DEFAULT '2000-01-01', x UInt8, y UInt64) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test_01430', 'modify_sample') PARTITION BY d ORDER BY (x, y);
INSERT INTO modify_sample_replicated (x, y) SELECT toUInt8(number) AS x, toUInt64(number) as y FROM system.numbers LIMIT 256;
SELECT count(), min(x), max(x), sum(x), uniqExact(x) FROM modify_sample_replicated SAMPLE 0.1; -- { serverError 141 }
ALTER TABLE modify_sample_replicated MODIFY SAMPLE BY x;
SELECT count(), min(x), max(x), sum(x), uniqExact(x) FROM modify_sample_replicated SAMPLE 0.1;
DETACH TABLE modify_sample_replicated;
ATTACH TABLE modify_sample_replicated;
SELECT count(), min(x), max(x), sum(x), uniqExact(x) FROM modify_sample_replicated SAMPLE 0.1;
ALTER TABLE modify_sample_replicated MODIFY SAMPLE BY d; -- { serverError 36 }
ALTER TABLE modify_sample_replicated MODIFY SAMPLE BY y;
SELECT count(), min(y), max(y), sum(y), uniqExact(y) FROM modify_sample_replicated SAMPLE 0.1;
DETACH TABLE modify_sample_replicated;
ATTACH TABLE modify_sample_replicated;
SELECT count(), min(y), max(y), sum(y), uniqExact(y) FROM modify_sample_replicated SAMPLE 0.1;
CREATE TABLE modify_sample_old (d Date DEFAULT '2000-01-01', x UInt8, y UInt64) ENGINE = MergeTree(d, (x, y), 8192);
ALTER TABLE modify_sample_old MODIFY SAMPLE BY x; -- { serverError 36 }
DROP TABLE modify_sample;
DROP TABLE modify_sample_replicated;
DROP TABLE modify_sample_old;