[StorageMerge] check that underlying tables support sampling

This commit is contained in:
Ivan Lezhankin 2019-05-21 16:04:34 +03:00
parent a08fee57b7
commit 28bddf9a4a
3 changed files with 44 additions and 0 deletions

View File

@ -41,6 +41,7 @@ namespace ErrorCodes
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
extern const int NO_SUCH_COLUMN_IN_TABLE; extern const int NO_SUCH_COLUMN_IN_TABLE;
extern const int BLOCKS_HAVE_DIFFERENT_STRUCTURE; extern const int BLOCKS_HAVE_DIFFERENT_STRUCTURE;
extern const int SAMPLING_NOT_SUPPORTED;
} }
@ -218,6 +219,7 @@ BlockInputStreams StorageMerge::read(
query_info.query, has_table_virtual_column, true, context.getCurrentQueryId()); query_info.query, has_table_virtual_column, true, context.getCurrentQueryId());
if (selected_tables.empty()) if (selected_tables.empty())
/// FIXME: do we support sampling in this case?
return createSourceStreams( return createSourceStreams(
query_info, processed_stage, max_block_size, header, {}, {}, real_column_names, modified_context, 0, has_table_virtual_column); query_info, processed_stage, max_block_size, header, {}, {}, real_column_names, modified_context, 0, has_table_virtual_column);
@ -234,6 +236,10 @@ BlockInputStreams StorageMerge::read(
StoragePtr storage = it->first; StoragePtr storage = it->first;
TableStructureReadLockHolder struct_lock = it->second; TableStructureReadLockHolder struct_lock = it->second;
/// If sampling requested, then check that table supports it.
if (query_info.query->as<ASTSelectQuery>()->sample_size() && !storage->supportsSampling())
throw Exception("Illegal SAMPLE: table doesn't support sampling", ErrorCodes::SAMPLING_NOT_SUPPORTED);
BlockInputStreams source_streams; BlockInputStreams source_streams;
if (current_streams) if (current_streams)

View File

@ -0,0 +1,20 @@
494
331
576
709
903
378
498
102
861
97
494
331
576
709
903
378
498
102
861
97

View File

@ -0,0 +1,18 @@
DROP TABLE IF EXISTS test.numbers1;
DROP TABLE IF EXISTS test.numbers2;
CREATE TABLE test.numbers1 ENGINE = Memory AS SELECT number FROM numbers(1000);
CREATE TABLE test.numbers2 ENGINE = Memory AS SELECT number FROM numbers(1000);
SELECT * FROM merge(test, '^numbers\\d+$') SAMPLE 0.1; -- { serverError 141 }
DROP TABLE test.numbers1;
DROP TABLE test.numbers2;
CREATE TABLE test.numbers1 ENGINE = MergeTree ORDER BY intHash32(number) SAMPLE BY intHash32(number) AS SELECT number FROM numbers(1000);
CREATE TABLE test.numbers2 ENGINE = MergeTree ORDER BY intHash32(number) SAMPLE BY intHash32(number) AS SELECT number FROM numbers(1000);
SELECT * FROM merge(test, '^numbers\\d+$') SAMPLE 0.01;
DROP TABLE test.numbers1;
DROP TABLE test.numbers2;