2018-10-19 12:02:31 +00:00
|
|
|
#include <DataStreams/processConstants.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
void removeConstantsFromBlock(Block & block)
|
|
|
|
{
|
|
|
|
size_t columns = block.columns();
|
|
|
|
size_t i = 0;
|
|
|
|
while (i < columns)
|
|
|
|
{
|
2019-07-08 13:00:54 +00:00
|
|
|
if (block.getByPosition(i).column && isColumnConst(*block.getByPosition(i).column))
|
2018-10-19 12:02:31 +00:00
|
|
|
{
|
|
|
|
block.erase(i);
|
|
|
|
--columns;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void removeConstantsFromSortDescription(const Block & header, SortDescription & description)
|
|
|
|
{
|
2019-02-26 18:40:08 +00:00
|
|
|
/// Note: This code is not correct if column description contains column numbers instead of column names.
|
|
|
|
/// Hopefully, everywhere where it is used, column description contains names.
|
2018-10-19 12:02:31 +00:00
|
|
|
description.erase(std::remove_if(description.begin(), description.end(),
|
|
|
|
[&](const SortColumnDescription & elem)
|
|
|
|
{
|
2019-02-26 18:40:08 +00:00
|
|
|
auto & column = !elem.column_name.empty() ? header.getByName(elem.column_name)
|
|
|
|
: header.safeGetByPosition(elem.column_number);
|
2019-07-08 13:07:46 +00:00
|
|
|
return column.column && isColumnConst(*column.column);
|
2018-10-19 12:02:31 +00:00
|
|
|
}), description.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void enrichBlockWithConstants(Block & block, const Block & header)
|
|
|
|
{
|
|
|
|
size_t rows = block.rows();
|
|
|
|
size_t columns = header.columns();
|
|
|
|
|
|
|
|
for (size_t i = 0; i < columns; ++i)
|
|
|
|
{
|
|
|
|
const auto & col_type_name = header.getByPosition(i);
|
2019-07-08 13:07:46 +00:00
|
|
|
if (col_type_name.column && isColumnConst(*col_type_name.column))
|
2018-10-19 12:02:31 +00:00
|
|
|
block.insert(i, {col_type_name.column->cloneResized(rows), col_type_name.type, col_type_name.name});
|
|
|
|
}
|
|
|
|
}
|
2018-10-19 13:04:50 +00:00
|
|
|
}
|