mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-17 13:13:36 +00:00
dbms: cleanup [#METR-19266]
This commit is contained in:
parent
4ae075c7b9
commit
821f1e6482
@ -20,8 +20,7 @@ using NullValuesByteMap = PaddedPODArray<UInt8>;
|
||||
class ColumnNullable final : public IColumn
|
||||
{
|
||||
public:
|
||||
ColumnNullable(ColumnPtr nested_column_);
|
||||
ColumnNullable(ColumnPtr nested_column_, bool fill_with_nulls);
|
||||
ColumnNullable(ColumnPtr nested_column_, ColumnPtr null_map_);
|
||||
std::string getName() const override;
|
||||
bool isNumeric() const override;
|
||||
bool isConst() const override;
|
||||
|
@ -42,7 +42,10 @@ UInt64 ColumnConst<Null>::get64(size_t n) const
|
||||
template <>
|
||||
ColumnPtr ColumnConst<Null>::convertToFullColumn() const
|
||||
{
|
||||
return std::make_shared<ColumnNullable>(std::make_shared<ColumnUInt8>(size(), 0), true);
|
||||
/// We basically create a column whose rows have NULL values.
|
||||
ColumnPtr full_col = std::make_shared<ColumnUInt8>(size(), 0);
|
||||
ColumnPtr null_map = std::make_shared<ColumnUInt8>(size(), 1);
|
||||
return std::make_shared<ColumnNullable>(full_col, null_map);
|
||||
}
|
||||
|
||||
template <> ColumnPtr ColumnConst<String>::convertToFullColumn() const
|
||||
|
@ -10,25 +10,13 @@ extern const int LOGICAL_ERROR;
|
||||
|
||||
}
|
||||
|
||||
ColumnNullable::ColumnNullable(ColumnPtr nested_column_)
|
||||
: nested_column{nested_column_}
|
||||
ColumnNullable::ColumnNullable(ColumnPtr nested_column_, ColumnPtr null_map_)
|
||||
: nested_column{nested_column_}, null_map{null_map_}
|
||||
{
|
||||
if (nested_column->isNullable())
|
||||
throw Exception{"A nullable column cannot contain another nullable column", ErrorCodes::LOGICAL_ERROR};
|
||||
}
|
||||
|
||||
ColumnNullable::ColumnNullable(ColumnPtr nested_column_, bool fill_with_nulls)
|
||||
: nested_column{nested_column_},
|
||||
null_map{std::make_shared<ColumnUInt8>()}
|
||||
{
|
||||
if (nested_column->isNullable())
|
||||
throw Exception{"A nullable column cannot contain another nullable column", ErrorCodes::LOGICAL_ERROR};
|
||||
|
||||
size_t n = nested_column->size();
|
||||
if (n > 0)
|
||||
getNullMapContent().getData().resize_fill(n, (fill_with_nulls ? 1 : 0));
|
||||
}
|
||||
|
||||
std::string ColumnNullable::getName() const
|
||||
{
|
||||
return "ColumnNullable(" + nested_column->getName() + ")";
|
||||
@ -59,11 +47,7 @@ ColumnPtr ColumnNullable::convertToFullColumnIfConst() const
|
||||
ColumnPtr new_col_holder;
|
||||
|
||||
if (auto full_col = nested_column->convertToFullColumnIfConst())
|
||||
{
|
||||
new_col_holder = std::make_shared<ColumnNullable>(full_col);
|
||||
ColumnNullable & new_col = static_cast<ColumnNullable &>(*new_col_holder);
|
||||
new_col.null_map = null_map;
|
||||
}
|
||||
new_col_holder = std::make_shared<ColumnNullable>(full_col, null_map);
|
||||
|
||||
return new_col_holder;
|
||||
}
|
||||
@ -78,10 +62,9 @@ void ColumnNullable::updateHashWithValue(size_t n, SipHash & hash) const
|
||||
|
||||
ColumnPtr ColumnNullable::cloneResized(size_t size) const
|
||||
{
|
||||
ColumnPtr new_col_holder = std::make_shared<ColumnNullable>(nested_column->cloneResized(size));
|
||||
auto & new_col = static_cast<ColumnNullable &>(*new_col_holder);
|
||||
new_col.null_map = getNullMapContent().cloneResized(size);
|
||||
return new_col_holder;
|
||||
ColumnPtr new_nested_col = nested_column->cloneResized(size);
|
||||
ColumnPtr new_null_map = getNullMapContent().cloneResized(size);
|
||||
return std::make_shared<ColumnNullable>(new_nested_col, new_null_map);
|
||||
}
|
||||
|
||||
size_t ColumnNullable::size() const
|
||||
@ -185,20 +168,16 @@ void ColumnNullable::popBack(size_t n)
|
||||
|
||||
ColumnPtr ColumnNullable::filter(const Filter & filt, ssize_t result_size_hint) const
|
||||
{
|
||||
ColumnPtr new_data = nested_column->filter(filt, result_size_hint);
|
||||
ColumnPtr filtered_col_holder = std::make_shared<ColumnNullable>(new_data);
|
||||
ColumnNullable & filtered_col = static_cast<ColumnNullable &>(*filtered_col_holder);
|
||||
filtered_col.null_map = getNullMapContent().filter(filt, result_size_hint);
|
||||
return filtered_col_holder;
|
||||
ColumnPtr filtered_data = nested_column->filter(filt, result_size_hint);
|
||||
ColumnPtr filtered_null_map = getNullMapContent().filter(filt, result_size_hint);
|
||||
return std::make_shared<ColumnNullable>(filtered_data, filtered_null_map);
|
||||
}
|
||||
|
||||
ColumnPtr ColumnNullable::permute(const Permutation & perm, size_t limit) const
|
||||
{
|
||||
ColumnPtr new_data = nested_column->permute(perm, limit);
|
||||
ColumnPtr permuted_col_holder = std::make_shared<ColumnNullable>(new_data);
|
||||
ColumnNullable & permuted_col = static_cast<ColumnNullable &>(*permuted_col_holder);
|
||||
permuted_col.null_map = getNullMapContent().permute(perm, limit);
|
||||
return permuted_col_holder;
|
||||
ColumnPtr permuted_data = nested_column->permute(perm, limit);
|
||||
ColumnPtr permuted_null_map = getNullMapContent().permute(perm, limit);
|
||||
return std::make_shared<ColumnNullable>(permuted_data, permuted_null_map);
|
||||
}
|
||||
|
||||
int ColumnNullable::compareAt(size_t n, size_t m, const IColumn & rhs_, int null_direction_hint) const
|
||||
@ -381,10 +360,9 @@ void ColumnNullable::getExtremes(Field & min, Field & max) const
|
||||
|
||||
ColumnPtr ColumnNullable::replicate(const Offsets_t & offsets) const
|
||||
{
|
||||
ColumnPtr replicated_col_holder = std::make_shared<ColumnNullable>(nested_column->replicate(offsets));
|
||||
ColumnNullable & replicated_col = static_cast<ColumnNullable &>(*replicated_col_holder);
|
||||
replicated_col.null_map = getNullMapContent().replicate(offsets);
|
||||
return replicated_col_holder;
|
||||
ColumnPtr replicated_data = nested_column->replicate(offsets);
|
||||
ColumnPtr replicated_null_map = getNullMapContent().replicate(offsets);
|
||||
return std::make_shared<ColumnNullable>(replicated_data, replicated_null_map);
|
||||
}
|
||||
|
||||
ColumnPtr & ColumnNullable::getNestedColumn()
|
||||
|
@ -289,18 +289,14 @@ void DataTypeNullable::serializeTextXML(const IColumn & column, size_t row_num,
|
||||
|
||||
ColumnPtr DataTypeNullable::createColumn() const
|
||||
{
|
||||
ColumnPtr new_col_holder = std::make_shared<ColumnNullable>(nested_data_type->createColumn());
|
||||
ColumnNullable & nullable_col = static_cast<ColumnNullable &>(*new_col_holder);
|
||||
nullable_col.getNullValuesByteMap() = std::make_shared<ColumnUInt8>();
|
||||
return new_col_holder;
|
||||
ColumnPtr new_col = nested_data_type->createColumn();
|
||||
return std::make_shared<ColumnNullable>(new_col, std::make_shared<ColumnUInt8>());
|
||||
}
|
||||
|
||||
ColumnPtr DataTypeNullable::createConstColumn(size_t size, const Field & field) const
|
||||
{
|
||||
ColumnPtr new_col_holder = std::make_shared<ColumnNullable>(nested_data_type->createConstColumn(size, field));
|
||||
ColumnNullable & nullable_col = static_cast<ColumnNullable &>(*new_col_holder);
|
||||
nullable_col.getNullValuesByteMap() = std::make_shared<ColumnUInt8>(size);
|
||||
return new_col_holder;
|
||||
ColumnPtr new_col = nested_data_type->createConstColumn(size, field);
|
||||
return std::make_shared<ColumnNullable>(new_col, std::make_shared<ColumnUInt8>(size));
|
||||
}
|
||||
|
||||
Field DataTypeNullable::getDefault() const
|
||||
|
@ -181,7 +181,8 @@ void FunctionMultiIf::executeImpl(Block & block, const ColumnNumbers & args, siz
|
||||
Block block_with_nested_cols = createBlockWithNestedColumns(block, args_to_transform);
|
||||
|
||||
/// Append a column that tracks, for each result of multiIf, the index
|
||||
/// of the originating column.
|
||||
/// of the originating column. UInt16 is enough for 65536 columns.
|
||||
/// A table with such a big number of columns is highly unlikely to appear.
|
||||
ColumnWithTypeAndName elem;
|
||||
elem.type = std::make_shared<DataTypeUInt16>();
|
||||
|
||||
@ -202,19 +203,15 @@ void FunctionMultiIf::executeImpl(Block & block, const ColumnNumbers & args, siz
|
||||
return;
|
||||
}
|
||||
|
||||
dest_col.column = std::make_shared<ColumnNullable>(source_col.column);
|
||||
|
||||
/// Setup the null byte map of the result column by using the branch tracker column values.
|
||||
ColumnPtr tracker_holder = block_with_nested_cols.unsafeGetByPosition(tracker).column;
|
||||
ColumnNullable & nullable_col = static_cast<ColumnNullable &>(*dest_col.column);
|
||||
ColumnPtr null_map;
|
||||
|
||||
if (auto col = typeid_cast<ColumnConstUInt16 *>(tracker_holder.get()))
|
||||
{
|
||||
auto pos = col->getData();
|
||||
const IColumn & origin = *block.unsafeGetByPosition(pos).column;
|
||||
|
||||
ColumnPtr null_map;
|
||||
|
||||
if (origin.isNull())
|
||||
null_map = std::make_shared<ColumnUInt8>(row_count, 1);
|
||||
else if (origin.isNullable())
|
||||
@ -224,8 +221,6 @@ void FunctionMultiIf::executeImpl(Block & block, const ColumnNumbers & args, siz
|
||||
}
|
||||
else
|
||||
null_map = std::make_shared<ColumnUInt8>(row_count, 0);
|
||||
|
||||
nullable_col.getNullValuesByteMap() = null_map;
|
||||
}
|
||||
else if (auto col = typeid_cast<ColumnUInt16 *>(tracker_holder.get()))
|
||||
{
|
||||
@ -250,9 +245,8 @@ void FunctionMultiIf::executeImpl(Block & block, const ColumnNumbers & args, siz
|
||||
null_cols_map[arg] = is_null ? 1 : 0;
|
||||
}
|
||||
|
||||
auto null_map = std::make_shared<ColumnUInt8>(row_count);
|
||||
nullable_col.getNullValuesByteMap() = null_map;
|
||||
auto & null_map_data = null_map->getData();
|
||||
null_map = std::make_shared<ColumnUInt8>(row_count);
|
||||
auto & null_map_data = static_cast<ColumnUInt8 &>(*null_map).getData();
|
||||
|
||||
const auto & data = col->getData();
|
||||
for (size_t row = 0; row < row_count; ++row)
|
||||
@ -276,6 +270,9 @@ void FunctionMultiIf::executeImpl(Block & block, const ColumnNumbers & args, siz
|
||||
}
|
||||
else
|
||||
throw Exception{"Internal error", ErrorCodes::LOGICAL_ERROR};
|
||||
|
||||
/// Store the result.
|
||||
dest_col.column = std::make_shared<ColumnNullable>(source_col.column, null_map);
|
||||
}
|
||||
catch (const Conditional::CondException & ex)
|
||||
{
|
||||
|
@ -337,14 +337,15 @@ void IFunction::postProcessResult(Strategy strategy, Block & block, const Block
|
||||
}
|
||||
else if (strategy == PROCESS_NULLABLE_COLUMNS)
|
||||
{
|
||||
/// Initialize the result column.
|
||||
const ColumnWithTypeAndName & source_col = processed_block.getByPosition(result);
|
||||
ColumnWithTypeAndName & dest_col = block.getByPosition(result);
|
||||
dest_col.column = std::make_shared<ColumnNullable>(source_col.column);
|
||||
|
||||
/// Make a null map for the result.
|
||||
ColumnNullable & nullable_col = static_cast<ColumnNullable &>(*dest_col.column);
|
||||
nullable_col.getNullValuesByteMap() = std::make_shared<ColumnUInt8>(dest_col.column->size(), 0);
|
||||
/// Initialize the result column.
|
||||
ColumnPtr null_map = std::make_shared<ColumnUInt8>(block.rowsInFirstColumn(), 0);
|
||||
dest_col.column = std::make_shared<ColumnNullable>(source_col.column, null_map);
|
||||
|
||||
/// Deduce the null map of the result from the null maps of the
|
||||
/// nullable columns.
|
||||
createNullValuesByteMap(block, args, result);
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user