fix build

This commit is contained in:
Nikolai Kochetov 2018-04-17 15:41:16 +03:00
parent d97e7362db
commit cdc8bbea7e

View File

@ -55,14 +55,11 @@ class ColumnUnique final : public COWPtrHelper<IColumnUnique, ColumnUnique<Colum
private: private:
explicit ColumnUnique(MutableColumnPtr && holder); explicit ColumnUnique(MutableColumnPtr && holder);
explicit ColumnUnique(const DataTypePtr & type) : is_nullable(type->isNullable()) explicit ColumnUnique(const DataTypePtr & type);
{
column_holder = removeNullable(type)->createColumn()->cloneResized(numSpecialValues());
}
ColumnUnique(const ColumnUnique & other) : column_holder(other.column_holder), is_nullable(other.is_nullable) {} ColumnUnique(const ColumnUnique & other) : column_holder(other.column_holder), is_nullable(other.is_nullable) {}
public: public:
const ColumnPtr & getNestedColumn() const override { return column_holder; } const ColumnPtr & getNestedColumn() const override;
size_t uniqueInsert(const Field & x) override; size_t uniqueInsert(const Field & x) override;
size_t uniqueInsertFrom(const IColumn & src, size_t n) override; size_t uniqueInsertFrom(const IColumn & src, size_t n) override;
ColumnPtr uniqueInsertRangeFrom(const IColumn & src, size_t start, size_t length) override; ColumnPtr uniqueInsertRangeFrom(const IColumn & src, size_t start, size_t length) override;
@ -133,6 +130,11 @@ private:
using IndexMapType = HashMap<StringRefWrapper<ColumnType>, IndexType, StringRefHash>; using IndexMapType = HashMap<StringRefWrapper<ColumnType>, IndexType, StringRefHash>;
ColumnPtr column_holder; ColumnPtr column_holder;
/// For DataTypeNullable, nullptr otherwise.
ColumnPtr nullable_column;
NullMap * nullable_column_map = nullptr;
/// Lazy initialized. /// Lazy initialized.
std::unique_ptr<IndexMapType> index; std::unique_ptr<IndexMapType> index;
@ -147,17 +149,45 @@ private:
}; };
template <typename ColumnType, typename IndexType>
ColumnUnique<ColumnType, IndexType>::ColumnUnique(const DataTypePtr & type) : is_nullable(type->isNullable())
{
if (is_nullable)
{
nullable_column = type->createColumn()->cloneResized(numSpecialValues());
auto & column_nullable = static_cast<ColumnNullable &>(nullable_column->assumeMutableRef());
column_holder = column_nullable.getNestedColumnPtr();
nullable_column_map = &column_nullable.getNullMapData();
(*nullable_column_map)[1] = 0;
}
else
column_holder = type->createColumn()->cloneResized(numSpecialValues());
}
template <typename ColumnType, typename IndexType> template <typename ColumnType, typename IndexType>
ColumnUnique<ColumnType, IndexType>::ColumnUnique(MutableColumnPtr && holder) : column_holder(std::move(holder)) ColumnUnique<ColumnType, IndexType>::ColumnUnique(MutableColumnPtr && holder) : column_holder(std::move(holder))
{ {
if (column_holder->isColumnNullable()) if (column_holder->isColumnNullable())
{ {
auto column_nullable = static_cast<const ColumnNullable *>(column_holder.get()); nullable_column = std::move(column_holder);
column_holder = column_nullable->getNestedColumnPtr(); auto & column_nullable = static_cast<ColumnNullable &>(nullable_column->assumeMutableRef());
column_holder = column_nullable.getNestedColumnPtr();
nullable_column_map = &column_nullable.getNullMapData();
is_nullable = true; is_nullable = true;
} }
} }
template <typename ColumnType, typename IndexType>
const ColumnPtr& ColumnUnique<ColumnType, IndexType>::getNestedColumn() const
{
if (is_nullable)
{
nullable_column_map->resize_fill(column_holder->size());
return nullable_column;
}
return column_holder;
}
template <typename ColumnType, typename IndexType> template <typename ColumnType, typename IndexType>
size_t ColumnUnique<ColumnType, IndexType>::getNullValueIndex() const size_t ColumnUnique<ColumnType, IndexType>::getNullValueIndex() const
{ {
@ -320,10 +350,10 @@ ColumnPtr ColumnUnique<ColumnType, IndexType>::uniqueInsertRangeFrom(const IColu
{ {
auto row = start + i; auto row = start + i;
if (column->compareAt(getDefaultValueIndex(), row, *src_column, 1) == 0) if (null_map && (*null_map)[row])
positions[i] = getDefaultValueIndex();
else if (null_map && (*null_map)[row])
positions[i] = getNullValueIndex(); positions[i] = getNullValueIndex();
else if (column->compareAt(getDefaultValueIndex(), row, *src_column, 1) == 0)
positions[i] = getDefaultValueIndex();
else else
{ {
auto it = index->find(StringRefWrapper<ColumnType>(src_column, row)); auto it = index->find(StringRefWrapper<ColumnType>(src_column, row));