Convert types in Views

This commit is contained in:
Alexey Milovidov 2020-04-13 00:07:11 +03:00
parent 20dcc4decd
commit 983950d4ec
3 changed files with 19 additions and 3 deletions

View File

@ -12,13 +12,12 @@
#include <Storages/StorageView.h> #include <Storages/StorageView.h>
#include <Storages/StorageFactory.h> #include <Storages/StorageFactory.h>
#include <DataStreams/MaterializingBlockInputStream.h>
#include <Common/typeid_cast.h> #include <Common/typeid_cast.h>
#include <Processors/Pipe.h> #include <Processors/Pipe.h>
#include <Processors/Sources/SourceFromInputStream.h> #include <Processors/Sources/SourceFromInputStream.h>
#include <Processors/Transforms/MaterializingTransform.h> #include <Processors/Transforms/MaterializingTransform.h>
#include <Processors/Transforms/ConvertingTransform.h>
namespace DB namespace DB
@ -78,8 +77,15 @@ Pipes StorageView::read(
/// It's expected that the columns read from storage are not constant. /// It's expected that the columns read from storage are not constant.
/// Because method 'getSampleBlockForColumns' is used to obtain a structure of result in InterpreterSelectQuery. /// Because method 'getSampleBlockForColumns' is used to obtain a structure of result in InterpreterSelectQuery.
for (auto & pipe : pipes) for (auto & pipe : pipes)
{
pipe.addSimpleTransform(std::make_shared<MaterializingTransform>(pipe.getHeader())); pipe.addSimpleTransform(std::make_shared<MaterializingTransform>(pipe.getHeader()));
/// And also convert to expected structure.
pipe.addSimpleTransform(std::make_shared<ConvertingTransform>(
pipe.getHeader(), getSampleBlockForColumns(column_names),
ConvertingTransform::MatchColumnsMode::Name, context));
}
return pipes; return pipes;
} }

View File

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

View File

@ -5,7 +5,7 @@ INSERT INTO test.table SELECT * FROM system.numbers LIMIT 10;
DROP TABLE IF EXISTS test.view; DROP TABLE IF EXISTS test.view;
CREATE VIEW test.view (x UInt64) AS SELECT * FROM test.table; CREATE VIEW test.view (x UInt64) AS SELECT * FROM test.table;
SELECT x, any(x) FROM test.view GROUP BY x; SELECT x, any(x) FROM test.view GROUP BY x ORDER BY x;
DROP TABLE test.view; DROP TABLE test.view;
DROP TABLE test.table; DROP TABLE test.table;