Merge pull request #5366 from abyss7/storage-merge-sample

Check that underlying tables support sampling for StorageMerge
This commit is contained in:
alexey-milovidov 2019-05-25 15:44:02 +03:00 committed by GitHub
commit 0c38226a25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 NO_SUCH_COLUMN_IN_TABLE;
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());
if (selected_tables.empty())
/// FIXME: do we support sampling in this case?
return createSourceStreams(
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;
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;
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;