ClickHouse/dbms/src/Interpreters/NullableUtils.cpp

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
{
2019-07-03 19:06:34 +00:00
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;
if (key_columns.size() == 1)
{
auto & column = key_columns[0];
2019-06-27 18:50:20 +00:00
if (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();
}
}
else
{
for (auto & column : key_columns)
{
2019-06-27 18:50:20 +00:00
if (auto * column_nullable = checkAndGetColumn<ColumnNullable>(*column))
{
2019-06-26 17:20:33 +00:00
column = &column_nullable->getNestedColumn();
if (!null_map_holder)
{
2019-06-26 17:20:33 +00:00
null_map_holder = column_nullable->getNullMapColumnPtr();
}
else
{
2018-03-20 10:58:16 +00:00
MutableColumnPtr mutable_null_map_holder = (*std::move(null_map_holder)).mutate();
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);
}
}
}
null_map = null_map_holder ? &assert_cast<const ColumnUInt8 &>(*null_map_holder).getData() : nullptr;
}
2019-07-03 19:06:34 +00:00
return null_map_holder;
2017-03-29 11:33:07 +00:00
}
}