ClickHouse/src/Interpreters/NullableUtils.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.7 KiB
C++
Raw Normal View History

#include <Common/assert_cast.h>
#include <Interpreters/NullableUtils.h>
2017-03-29 11:33:07 +00:00
namespace DB
{
ColumnPtr extractNestedColumnsAndNullMap(ColumnRawPtrs & key_columns, ConstNullMapPtr & null_map)
2017-03-29 11:33:07 +00:00
{
2019-07-03 19:06:34 +00:00
ColumnPtr null_map_holder;
2017-03-29 11:33:07 +00:00
if (key_columns.size() == 1)
{
auto & column = key_columns[0];
2020-04-22 06:01:33 +00:00
if (const auto * column_nullable = checkAndGetColumn<ColumnNullable>(*column))
2019-06-26 17:20:33 +00:00
{
2019-07-03 19:06:34 +00:00
null_map_holder = column_nullable->getNullMapColumnPtr();
2019-06-26 17:20:33 +00:00
null_map = &column_nullable->getNullMapData();
column = &column_nullable->getNestedColumn();
}
2017-03-29 11:33:07 +00:00
}
else
{
for (auto & column : key_columns)
{
2020-04-22 06:01:33 +00:00
if (const auto * column_nullable = checkAndGetColumn<ColumnNullable>(*column))
2017-03-29 11:33:07 +00:00
{
2019-06-26 17:20:33 +00:00
column = &column_nullable->getNestedColumn();
2017-03-29 11:33:07 +00:00
if (!null_map_holder)
{
2019-06-26 17:20:33 +00:00
null_map_holder = column_nullable->getNullMapColumnPtr();
2017-03-29 11:33:07 +00:00
}
else
{
2020-05-14 08:30:18 +00:00
MutableColumnPtr mutable_null_map_holder = IColumn::mutate(std::move(null_map_holder));
PaddedPODArray<UInt8> & mutable_null_map = assert_cast<ColumnUInt8 &>(*mutable_null_map_holder).getData();
2019-06-26 17:20:33 +00:00
const PaddedPODArray<UInt8> & other_null_map = column_nullable->getNullMapData();
for (size_t i = 0, size = mutable_null_map.size(); i < size; ++i)
mutable_null_map[i] |= other_null_map[i];
null_map_holder = std::move(mutable_null_map_holder);
2017-03-29 11:33:07 +00:00
}
}
}
null_map = null_map_holder ? &assert_cast<const ColumnUInt8 &>(*null_map_holder).getData() : nullptr;
2017-03-29 11:33:07 +00:00
}
2019-07-03 19:06:34 +00:00
return null_map_holder;
2017-03-29 11:33:07 +00:00
}
}