mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 09:02:00 +00:00
Reworking fix for missing columns.
This commit is contained in:
parent
78ab3127ce
commit
54c8234379
@ -5,6 +5,7 @@
|
||||
#include <Common/quoteString.h>
|
||||
#include <Parsers/IAST.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
@ -64,18 +65,8 @@ ConvertingBlockInputStream::ConvertingBlockInputStream(
|
||||
throw Exception("Cannot find column " + backQuote(res_elem.name) + " in source stream",
|
||||
ErrorCodes::THERE_IS_NO_COLUMN);
|
||||
break;
|
||||
|
||||
case MatchColumnsMode::NameOrDefault:
|
||||
if (input_header.has(res_elem.name))
|
||||
conversion[result_col_num] = input_header.getPositionByName(res_elem.name);
|
||||
else
|
||||
conversion[result_col_num] = USE_DEFAULT;
|
||||
break;
|
||||
}
|
||||
|
||||
if (conversion[result_col_num] == USE_DEFAULT)
|
||||
continue;
|
||||
|
||||
const auto & src_elem = input_header.getByPosition(conversion[result_col_num]);
|
||||
|
||||
/// Check constants.
|
||||
@ -109,17 +100,8 @@ Block ConvertingBlockInputStream::readImpl()
|
||||
Block res = header.cloneEmpty();
|
||||
for (size_t res_pos = 0, size = conversion.size(); res_pos < size; ++res_pos)
|
||||
{
|
||||
auto & res_elem = res.getByPosition(res_pos);
|
||||
|
||||
if (conversion[res_pos] == USE_DEFAULT)
|
||||
{
|
||||
// Create a column with default values
|
||||
auto column_with_defaults = res_elem.type->createColumn()->cloneResized(src.rows());
|
||||
res_elem.column = std::move(column_with_defaults);
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto & src_elem = src.getByPosition(conversion[res_pos]);
|
||||
auto & res_elem = res.getByPosition(res_pos);
|
||||
|
||||
ColumnPtr converted = castColumnWithDiagnostic(src_elem, res_elem, context);
|
||||
|
||||
@ -132,4 +114,3 @@ Block ConvertingBlockInputStream::readImpl()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -28,9 +28,7 @@ public:
|
||||
/// Require same number of columns in source and result. Match columns by corresponding positions, regardless to names.
|
||||
Position,
|
||||
/// Find columns in source by their names. Allow excessive columns in source.
|
||||
Name,
|
||||
/// Find columns in source by their names if present else use the default. Allow excessive columns in source.
|
||||
NameOrDefault
|
||||
Name
|
||||
};
|
||||
|
||||
ConvertingBlockInputStream(
|
||||
@ -50,7 +48,6 @@ private:
|
||||
|
||||
/// How to construct result block. Position in source block, where to get each column.
|
||||
using Conversion = std::vector<size_t>;
|
||||
const size_t USE_DEFAULT = static_cast<size_t>(-1);
|
||||
Conversion conversion;
|
||||
};
|
||||
|
||||
|
@ -231,8 +231,16 @@ void PushingToViewsBlockOutputStream::process(const Block & block, size_t view_n
|
||||
/// and two-level aggregation is triggered).
|
||||
in = std::make_shared<SquashingBlockInputStream>(
|
||||
in, context.getSettingsRef().min_insert_block_size_rows, context.getSettingsRef().min_insert_block_size_bytes);
|
||||
|
||||
auto view_table = context.getTable(view.table_id);
|
||||
|
||||
if (auto * materialized_view = dynamic_cast<const StorageMaterializedView *>(view_table.get()))
|
||||
{
|
||||
StoragePtr inner_table = materialized_view->getTargetTable();
|
||||
in = std::make_shared<AddingMissedBlockInputStream>(
|
||||
in, view.out->getHeader(), storage->getColumns().getDefaults(), local_context);
|
||||
in, view.out->getHeader(), inner_table->getColumns().getDefaults(), context);
|
||||
}
|
||||
|
||||
in = std::make_shared<ConvertingBlockInputStream>(context, in, view.out->getHeader(), ConvertingBlockInputStream::MatchColumnsMode::Name);
|
||||
}
|
||||
else
|
||||
|
@ -2,7 +2,7 @@
|
||||
1
|
||||
2
|
||||
3
|
||||
1 0
|
||||
1 2
|
||||
1 2
|
||||
2 3
|
||||
3 4
|
||||
|
Loading…
Reference in New Issue
Block a user