This commit is contained in:
Alexey Milovidov 2015-02-16 21:24:57 +03:00
commit e3903cecc8
2 changed files with 26 additions and 11 deletions

View File

@ -25,7 +25,8 @@ public:
all_mark_ranges(mark_ranges_), remaining_mark_ranges(mark_ranges_),
use_uncompressed_cache(use_uncompressed_cache_),
prewhere_actions(prewhere_actions_), prewhere_column(prewhere_column_),
log(&Logger::get("MergeTreeBlockInputStream"))
log(&Logger::get("MergeTreeBlockInputStream")),
ordered_names{column_names}
{
std::reverse(remaining_mark_ranges.begin(), remaining_mark_ranges.end());
@ -191,7 +192,7 @@ protected:
remaining_mark_ranges.pop_back();
}
progressImpl(Progress(res.rows(), res.bytes()));
pre_reader->fillMissingColumns(res);
pre_reader->fillMissingColumns(res, ordered_names);
/// Вычислим выражение в PREWHERE.
prewhere_actions->execute(res);
@ -294,7 +295,7 @@ protected:
else
throw Exception("Illegal type " + column->getName() + " of column for filter. Must be ColumnUInt8 or ColumnConstUInt8.", ErrorCodes::ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER);
reader->fillMissingColumns(res);
reader->fillMissingColumns(res, ordered_names);
}
while (!remaining_mark_ranges.empty() && !res && !isCancelled());
}
@ -316,7 +317,7 @@ protected:
progressImpl(Progress(res.rows(), res.bytes()));
reader->fillMissingColumns(res);
reader->fillMissingColumns(res, ordered_names);
}
if (remaining_mark_ranges.empty())
@ -354,6 +355,9 @@ private:
bool remove_prewhere_column;
Logger * log;
/// requested column names in specific order as expected by other stages
const Names ordered_names;
};
}

View File

@ -173,7 +173,10 @@ public:
}
if (!minimum_size_column)
throw std::logic_error{"could not find a column of minimum size in MergeTree"};
throw Exception{
"could not find a column of minimum size in MergeTree",
ErrorCodes::LOGICAL_ERROR
};
addStream(minimum_size_column->name, *minimum_size_column->type, all_mark_ranges);
columns.emplace(std::begin(columns), *minimum_size_column);
@ -182,7 +185,7 @@ public:
}
/// Заполняет столбцы, которых нет в блоке, значениями по умолчанию.
void fillMissingColumns(Block & res)
void fillMissingColumns(Block & res, const Names & ordered_names)
{
try
{
@ -259,15 +262,23 @@ public:
columns.erase(std::begin(columns));
}
/// sort columns to ensure consistent order among all block
/// sort columns to ensure consistent order among all blocks
if (should_sort)
{
Block sorted_block;
Block ordered_block;
for (const auto & name_and_type : columns)
sorted_block.insert(res.getByName(name_and_type.name));
for (const auto & name : ordered_names)
if (res.has(name))
ordered_block.insert(res.getByName(name));
std::swap(res, sorted_block);
if (res.columns() != ordered_block.columns())
throw Exception{
"Ordered block has different columns than original one:\n" +
ordered_block.dumpNames() + "\nvs.\n" + res.dumpNames(),
ErrorCodes::LOGICAL_ERROR
};
std::swap(res, ordered_block);
}
else if (added_column)
{