ISSUES-957 fix not work when materialized columns with buff table

This commit is contained in:
zhang2014 2018-01-01 19:54:14 +08:00
parent 005f6b96fa
commit 6fe64aa346
8 changed files with 45 additions and 9 deletions

View File

@ -13,9 +13,12 @@ namespace ErrorCodes
void ProhibitColumnsBlockOutputStream::write(const Block & block)
{
for (const auto & column : columns)
if (block.has(column.name))
throw Exception{"Cannot insert column " + column.name, ErrorCodes::ILLEGAL_COLUMN};
if(allow_materialized)
{
for (const auto & column : columns)
if (block.has(column.name))
throw Exception{"Cannot insert column " + column.name, ErrorCodes::ILLEGAL_COLUMN};
}
output->write(block);
}

View File

@ -11,8 +11,8 @@ namespace DB
class ProhibitColumnsBlockOutputStream : public IBlockOutputStream
{
public:
ProhibitColumnsBlockOutputStream(const BlockOutputStreamPtr & output, const NamesAndTypesList & columns)
: output{output}, columns{columns}
ProhibitColumnsBlockOutputStream(const BlockOutputStreamPtr & output, const NamesAndTypesList & columns, bool allow_materialized)
: output{output}, columns{columns}, allow_materialized{allow_materialized}
{
}
@ -26,6 +26,7 @@ private:
BlockOutputStreamPtr output;
NamesAndTypesList columns;
bool allow_materialized;
};
}

View File

@ -570,7 +570,7 @@ BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create)
query_ptr)),
/// @note shouldn't these two contexts be session contexts in case of temporary table?
columns.columns, columns.column_defaults, context, static_cast<bool>(context.getSettingsRef().strict_insert_defaults)),
columns.materialized_columns);
columns.materialized_columns, static_cast<bool>(context.getSettingsRef().insert_allow_materialized_columns));
BlockIO io;
io.in_sample = as_select_sample;

View File

@ -118,7 +118,8 @@ BlockIO InterpreterInsertQuery::execute()
out = std::make_shared<AddingDefaultBlockOutputStream>(
out, required_columns, table->column_defaults, context, static_cast<bool>(context.getSettingsRef().strict_insert_defaults));
out = std::make_shared<ProhibitColumnsBlockOutputStream>(out, table->materialized_columns);
out = std::make_shared<ProhibitColumnsBlockOutputStream>(
out, table->materialized_columns, static_cast<bool>(context.getSettingsRef().insert_allow_materialized_columns));
out = std::make_shared<SquashingBlockOutputStream>(
out, context.getSettingsRef().min_insert_block_size_rows, context.getSettingsRef().min_insert_block_size_bytes);

View File

@ -300,7 +300,8 @@ struct Settings
/* Timeout for flushing data from streaming storages. */ \
M(SettingMilliseconds, stream_flush_interval_ms, DEFAULT_QUERY_LOG_FLUSH_INTERVAL_MILLISECONDS, "Timeout for flushing data from streaming storages.") \
/* Schema identifier (used by schema-based formats) */ \
M(SettingString, format_schema, "", "Schema identifier (used by schema-based formats)")
M(SettingString, format_schema, "", "Schema identifier (used by schema-based formats)") \
M(SettingBool, insert_allow_materialized_columns, 0, "If setting is enabled, require materialized columns for the INSERT query.")
/// Possible limits for query execution.

View File

@ -527,7 +527,8 @@ void StorageBuffer::writeBlockToDestination(const Block & block, StoragePtr tabl
/** We will insert columns that are the intersection set of columns of the buffer table and the subordinate table.
* This will support some of the cases (but not all) when the table structure does not match.
*/
Block structure_of_destination_table = table->getSampleBlock();
bool allow_materialized = static_cast<bool>(context.getSettingsRef().insert_allow_materialized_columns);
Block structure_of_destination_table = allow_materialized ? table->getSampleBlock() : table->getSampleBlockNonMaterialized();
Names columns_intersection;
columns_intersection.reserve(block.columns());
for (size_t i : ext::range(0, structure_of_destination_table.columns()))

View File

@ -0,0 +1,9 @@
1 2
2 3
3 4
4 5
1 2
2 3
3 4
4 5
5 6

View File

@ -0,0 +1,20 @@
DROP TABLE IF EXISTS test.nums;
DROP TABLE IF EXISTS test.nums_buf;
CREATE TABLE test.nums ( n UInt64, m UInt64 MATERIALIZED n+1 ) ENGINE = Log;
CREATE TABLE test.nums_buf AS test.nums ENGINE = Buffer(test, nums, 1, 10, 100, 1, 3, 10000000, 100000000);
INSERT INTO test.nums_buf (n) VALUES (1);
INSERT INTO test.nums_buf (n) VALUES (2);
INSERT INTO test.nums_buf (n) VALUES (3);
INSERT INTO test.nums_buf (n) VALUES (4);
INSERT INTO test.nums_buf (n) VALUES (5);
SELECT n,m FROM test.nums ORDER BY n;
SELECT n,m FROM test.nums_buf ORDER BY n;
DROP TABLE IF EXISTS test.nums;
DROP TABLE IF EXISTS test.nums_buf;