2019-08-21 02:28:04 +00:00
|
|
|
#include <Common/assert_cast.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/NullableUtils.h>
|
2017-03-29 11:33:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-04-06 13:30:16 +00:00
|
|
|
ColumnPtr extractNestedColumnsAndNullMap(ColumnRawPtrs & key_columns, ConstNullMapPtr & null_map, bool exact_null)
|
2017-03-29 11:33:07 +00:00
|
|
|
{
|
2019-07-03 19:06:34 +00:00
|
|
|
ColumnPtr null_map_holder;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
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();
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (auto & column : key_columns)
|
|
|
|
{
|
2019-06-27 18:50:20 +00:00
|
|
|
if (auto * column_nullable = checkAndGetColumn<ColumnNullable>(*column))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-06-26 17:20:33 +00:00
|
|
|
column = &column_nullable->getNestedColumn();
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
if (!null_map_holder)
|
|
|
|
{
|
2019-06-26 17:20:33 +00:00
|
|
|
null_map_holder = column_nullable->getNullMapColumnPtr();
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-20 10:58:16 +00:00
|
|
|
MutableColumnPtr mutable_null_map_holder = (*std::move(null_map_holder)).mutate();
|
2017-12-15 18:23:05 +00:00
|
|
|
|
2019-08-21 02:28:04 +00:00
|
|
|
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();
|
2017-12-15 18:23:05 +00:00
|
|
|
for (size_t i = 0, size = mutable_null_map.size(); i < size; ++i)
|
2020-04-06 13:30:16 +00:00
|
|
|
{
|
|
|
|
if (exact_null)
|
|
|
|
mutable_null_map[i] &= other_null_map[i];
|
|
|
|
else
|
|
|
|
mutable_null_map[i] |= other_null_map[i];
|
|
|
|
}
|
2017-12-15 18:23:05 +00:00
|
|
|
|
|
|
|
null_map_holder = std::move(mutable_null_map_holder);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-21 02:28:04 +00:00
|
|
|
null_map = null_map_holder ? &assert_cast<const ColumnUInt8 &>(*null_map_holder).getData() : nullptr;
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2019-07-03 19:06:34 +00:00
|
|
|
|
|
|
|
return null_map_holder;
|
2017-03-29 11:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|