2016-07-05 16:23:37 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/Columns/IColumn.h>
|
|
|
|
#include <DB/Columns/ColumnsNumber.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-08-10 19:12:29 +00:00
|
|
|
using NullValuesByteMap = PaddedPODArray<UInt8>;
|
|
|
|
|
2016-08-16 13:31:42 +00:00
|
|
|
/// Class that specifies nullable columns. A nullable column represents
|
|
|
|
/// a column, which may have any type, provided with the possibility of
|
|
|
|
/// storing NULL values. For this purpose, a ColumNullable object stores
|
|
|
|
/// an ordinary column along with a special column, namely a byte map,
|
|
|
|
/// whose type is ColumnUInt8. The latter column indicates whether the
|
|
|
|
/// value of a given row is a NULL or not. Such a design is preferred
|
|
|
|
/// over a bitmap because columns are usually stored on disk as compressed
|
|
|
|
/// files. In this regard, using a bitmap instead of a byte map would
|
|
|
|
/// greatly complicate the implementation with little to no benefits.
|
2016-07-05 16:23:37 +00:00
|
|
|
class ColumnNullable final : public IColumn
|
|
|
|
{
|
|
|
|
public:
|
2016-08-16 22:40:05 +00:00
|
|
|
ColumnNullable(ColumnPtr nested_column_, ColumnPtr null_map_);
|
2016-08-17 16:31:00 +00:00
|
|
|
std::string getName() const override { return "ColumnNullable(" + nested_column->getName() + ")"; }
|
|
|
|
bool isNumeric() const override { return nested_column->isNumeric(); }
|
2016-08-18 15:58:46 +00:00
|
|
|
bool isNumericNotNullable() const override { return false; }
|
2016-08-17 16:31:00 +00:00
|
|
|
bool isConst() const override { return nested_column->isConst(); }
|
|
|
|
bool isFixed() const override { return nested_column->isFixed(); }
|
|
|
|
bool isNullable() const override { return true; }
|
2016-07-05 16:23:37 +00:00
|
|
|
ColumnPtr cloneResized(size_t size) const override;
|
2016-08-17 16:31:00 +00:00
|
|
|
size_t size() const override { return nested_column->size(); }
|
|
|
|
bool isNullAt(size_t n) const { return static_cast<const ColumnUInt8 &>(*null_map).getData()[n] != 0;}
|
2016-07-05 16:23:37 +00:00
|
|
|
Field operator[](size_t n) const override;
|
|
|
|
void get(size_t n, Field & res) const override;
|
2016-08-17 16:31:00 +00:00
|
|
|
UInt64 get64(size_t n) const override { return nested_column->get64(n); }
|
2016-07-05 16:23:37 +00:00
|
|
|
StringRef getDataAt(size_t n) const override;
|
|
|
|
void insertData(const char * pos, size_t length) override;
|
|
|
|
StringRef serializeValueIntoArena(size_t n, Arena & arena, char const *& begin) const override;
|
|
|
|
const char * deserializeAndInsertFromArena(const char * pos) override;
|
|
|
|
void insertRangeFrom(const IColumn & src, size_t start, size_t length) override;;
|
|
|
|
void insert(const Field & x) override;
|
2017-01-17 20:47:37 +00:00
|
|
|
void insertFrom(const IColumn & src, size_t n) override;
|
2017-01-30 05:22:49 +00:00
|
|
|
|
|
|
|
void insertDefault() override
|
|
|
|
{
|
|
|
|
nested_column->insertDefault();
|
|
|
|
getNullMap().push_back(1);
|
|
|
|
}
|
|
|
|
|
2016-07-05 16:23:37 +00:00
|
|
|
void popBack(size_t n) override;
|
|
|
|
ColumnPtr filter(const Filter & filt, ssize_t result_size_hint) const override;
|
|
|
|
ColumnPtr permute(const Permutation & perm, size_t limit) const override;
|
2016-08-16 11:26:17 +00:00
|
|
|
int compareAt(size_t n, size_t m, const IColumn & rhs_, int null_direction_hint) const override;
|
2017-03-12 12:56:59 +00:00
|
|
|
void getPermutation(bool reverse, size_t limit, int null_direction_hint, Permutation & res) const override;
|
2016-07-05 16:23:37 +00:00
|
|
|
void reserve(size_t n) override;
|
|
|
|
size_t byteSize() const override;
|
2017-01-17 20:54:32 +00:00
|
|
|
size_t allocatedSize() const override;
|
2016-07-05 16:23:37 +00:00
|
|
|
ColumnPtr replicate(const Offsets_t & replicate_offsets) const override;
|
|
|
|
ColumnPtr convertToFullColumnIfConst() const override;
|
2016-07-11 10:09:16 +00:00
|
|
|
void updateHashWithValue(size_t n, SipHash & hash) const override;
|
2016-08-10 19:12:29 +00:00
|
|
|
void getExtremes(Field & min, Field & max) const override;
|
2016-07-05 16:23:37 +00:00
|
|
|
|
2017-02-11 20:20:57 +00:00
|
|
|
Columns scatter(ColumnIndex num_columns, const Selector & selector) const override
|
|
|
|
{
|
|
|
|
return scatterImpl<ColumnNullable>(num_columns, selector);
|
|
|
|
}
|
|
|
|
|
2016-08-16 13:31:42 +00:00
|
|
|
/// Return the column that represents values.
|
2016-08-17 16:31:00 +00:00
|
|
|
ColumnPtr & getNestedColumn() { return nested_column; }
|
|
|
|
const ColumnPtr & getNestedColumn() const { return nested_column; }
|
2016-08-16 13:31:42 +00:00
|
|
|
|
|
|
|
/// Return the column that represents the byte map.
|
2016-12-30 05:13:14 +00:00
|
|
|
ColumnPtr & getNullMapColumn() { return null_map; }
|
|
|
|
const ColumnPtr & getNullMapColumn() const { return null_map; }
|
|
|
|
|
|
|
|
ColumnUInt8 & getNullMapConcreteColumn() { return static_cast<ColumnUInt8 &>(*null_map); }
|
|
|
|
const ColumnUInt8 & getNullMapConcreteColumn() const { return static_cast<const ColumnUInt8 &>(*null_map); }
|
|
|
|
|
|
|
|
ColumnUInt8::Container_t & getNullMap() { return getNullMapConcreteColumn().getData(); }
|
|
|
|
const ColumnUInt8::Container_t & getNullMap() const { return getNullMapConcreteColumn().getData(); }
|
2016-07-05 16:23:37 +00:00
|
|
|
|
2016-08-16 13:31:42 +00:00
|
|
|
/// Apply the null byte map of a specified nullable column onto the
|
|
|
|
/// null byte map of the current column by performing an element-wise OR
|
|
|
|
/// between both byte maps. This method is used to determine the null byte
|
|
|
|
/// map of the result column of a function taking one or more nullable
|
|
|
|
/// columns.
|
|
|
|
void applyNullValuesByteMap(const ColumnNullable & other);
|
2017-03-07 20:42:01 +00:00
|
|
|
void applyNullValuesByteMap(const ColumnUInt8 & map);
|
2017-03-07 20:52:09 +00:00
|
|
|
void applyNegatedNullValuesByteMap(const ColumnUInt8 & map);
|
2016-07-05 16:23:37 +00:00
|
|
|
|
|
|
|
private:
|
2016-07-07 10:33:12 +00:00
|
|
|
ColumnPtr nested_column;
|
|
|
|
ColumnPtr null_map;
|
2017-03-07 20:52:09 +00:00
|
|
|
|
|
|
|
template <bool negative>
|
|
|
|
void applyNullValuesByteMapImpl(const ColumnUInt8 & map);
|
2016-07-05 16:23:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|