2018-03-29 14:04:24 +00:00
|
|
|
#pragma once
|
|
|
|
#include <DataTypes/IDataType.h>
|
2018-06-07 18:14:37 +00:00
|
|
|
#include <Columns/IColumnUnique.h>
|
2018-03-14 10:47:13 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-09-27 15:55:22 +00:00
|
|
|
class DataTypeLowCardinality : public IDataType
|
2018-03-29 14:04:24 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
DataTypePtr dictionary_type;
|
|
|
|
|
|
|
|
public:
|
2018-09-27 15:55:22 +00:00
|
|
|
DataTypeLowCardinality(DataTypePtr dictionary_type_);
|
2018-03-29 14:04:24 +00:00
|
|
|
|
|
|
|
const DataTypePtr & getDictionaryType() const { return dictionary_type; }
|
|
|
|
|
2018-12-13 13:41:47 +00:00
|
|
|
String doGetName() const override
|
2018-03-29 14:04:24 +00:00
|
|
|
{
|
2018-08-07 18:57:16 +00:00
|
|
|
return "LowCardinality(" + dictionary_type->getName() + ")";
|
2018-03-29 14:04:24 +00:00
|
|
|
}
|
2018-08-07 18:57:16 +00:00
|
|
|
const char * getFamilyName() const override { return "LowCardinality"; }
|
2018-09-07 14:37:26 +00:00
|
|
|
TypeIndex getTypeId() const override { return TypeIndex::LowCardinality; }
|
2018-03-29 14:04:24 +00:00
|
|
|
|
2018-06-07 18:14:37 +00:00
|
|
|
void enumerateStreams(const StreamCallback & callback, SubstreamPath & path) const override;
|
|
|
|
|
|
|
|
void serializeBinaryBulkStatePrefix(
|
|
|
|
SerializeBinaryBulkSettings & settings,
|
|
|
|
SerializeBinaryBulkStatePtr & state) const override;
|
|
|
|
|
|
|
|
void serializeBinaryBulkStateSuffix(
|
|
|
|
SerializeBinaryBulkSettings & settings,
|
|
|
|
SerializeBinaryBulkStatePtr & state) const override;
|
|
|
|
|
|
|
|
void deserializeBinaryBulkStatePrefix(
|
|
|
|
DeserializeBinaryBulkSettings & settings,
|
|
|
|
DeserializeBinaryBulkStatePtr & state) const override;
|
2018-03-29 14:04:24 +00:00
|
|
|
|
|
|
|
void serializeBinaryBulkWithMultipleStreams(
|
|
|
|
const IColumn & column,
|
|
|
|
size_t offset,
|
2019-02-19 00:41:24 +00:00
|
|
|
size_t limit,
|
2018-06-07 18:14:37 +00:00
|
|
|
SerializeBinaryBulkSettings & settings,
|
|
|
|
SerializeBinaryBulkStatePtr & state) const override;
|
2018-05-21 16:21:15 +00:00
|
|
|
|
2018-03-29 14:04:24 +00:00
|
|
|
void deserializeBinaryBulkWithMultipleStreams(
|
|
|
|
IColumn & column,
|
2019-02-19 00:41:24 +00:00
|
|
|
size_t limit,
|
2018-06-07 18:14:37 +00:00
|
|
|
DeserializeBinaryBulkSettings & settings,
|
|
|
|
DeserializeBinaryBulkStatePtr & state) const override;
|
2018-03-29 14:04:24 +00:00
|
|
|
|
2018-05-03 14:53:35 +00:00
|
|
|
void serializeBinary(const Field & field, WriteBuffer & ostr) const override;
|
|
|
|
void deserializeBinary(Field & field, ReadBuffer & istr) const override;
|
2019-09-20 14:45:25 +00:00
|
|
|
void serializeBinary(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override;
|
|
|
|
void deserializeBinary(IColumn & column, ReadBuffer & istr) const override;
|
|
|
|
void serializeTextEscaped(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const override;
|
|
|
|
void deserializeTextEscaped(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const override;
|
|
|
|
void serializeTextQuoted(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const override;
|
|
|
|
void deserializeTextQuoted(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const override;
|
|
|
|
void deserializeWholeText(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const override;
|
|
|
|
void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const override;
|
|
|
|
void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const override;
|
|
|
|
void serializeText(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const override;
|
|
|
|
void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const override;
|
|
|
|
void deserializeTextJSON(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const override;
|
|
|
|
void serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const override;
|
|
|
|
void serializeProtobuf(const IColumn & column, size_t row_num, ProtobufWriter & protobuf, size_t & value_index) const override;
|
2019-02-19 20:01:31 +00:00
|
|
|
void deserializeProtobuf(IColumn & column, ProtobufReader & protobuf, bool allow_add_row, bool & row_added) const override;
|
|
|
|
|
2018-05-03 14:53:35 +00:00
|
|
|
MutableColumnPtr createColumn() const override;
|
2018-03-29 14:04:24 +00:00
|
|
|
|
2019-10-04 17:46:36 +00:00
|
|
|
Field getDefault() const override;
|
2018-03-29 14:04:24 +00:00
|
|
|
|
2018-05-03 14:53:35 +00:00
|
|
|
bool equals(const IDataType & rhs) const override;
|
2018-03-14 10:47:13 +00:00
|
|
|
|
2018-03-29 14:04:24 +00:00
|
|
|
bool isParametric() const override { return true; }
|
|
|
|
bool haveSubtypes() const override { return true; }
|
|
|
|
bool cannotBeStoredInTables() const override { return dictionary_type->cannotBeStoredInTables(); }
|
|
|
|
bool shouldAlignRightInPrettyFormats() const override { return dictionary_type->shouldAlignRightInPrettyFormats(); }
|
|
|
|
bool textCanContainOnlyValidUTF8() const override { return dictionary_type->textCanContainOnlyValidUTF8(); }
|
|
|
|
bool isComparable() const override { return dictionary_type->isComparable(); }
|
|
|
|
bool canBeComparedWithCollation() const override { return dictionary_type->canBeComparedWithCollation(); }
|
|
|
|
bool canBeUsedAsVersion() const override { return dictionary_type->canBeUsedAsVersion(); }
|
2018-08-26 00:44:23 +00:00
|
|
|
bool isSummable() const override { return dictionary_type->isSummable(); }
|
|
|
|
bool canBeUsedInBitOperations() const override { return dictionary_type->canBeUsedInBitOperations(); }
|
|
|
|
bool canBeUsedInBooleanContext() const override { return dictionary_type->canBeUsedInBooleanContext(); }
|
2018-03-29 14:04:24 +00:00
|
|
|
bool isValueRepresentedByNumber() const override { return dictionary_type->isValueRepresentedByNumber(); }
|
|
|
|
bool isValueRepresentedByInteger() const override { return dictionary_type->isValueRepresentedByInteger(); }
|
|
|
|
bool isValueUnambiguouslyRepresentedInContiguousMemoryRegion() const override { return true; }
|
|
|
|
bool haveMaximumSizeOfValue() const override { return dictionary_type->haveMaximumSizeOfValue(); }
|
|
|
|
size_t getMaximumSizeOfValueInMemory() const override { return dictionary_type->getMaximumSizeOfValueInMemory(); }
|
|
|
|
size_t getSizeOfValueInMemory() const override { return dictionary_type->getSizeOfValueInMemory(); }
|
|
|
|
bool isCategorial() const override { return false; }
|
|
|
|
bool isNullable() const override { return false; }
|
|
|
|
bool onlyNull() const override { return false; }
|
2018-09-27 15:55:22 +00:00
|
|
|
bool lowCardinality() const override { return true; }
|
2018-05-03 14:53:35 +00:00
|
|
|
|
2018-07-09 18:19:03 +00:00
|
|
|
static MutableColumnUniquePtr createColumnUnique(const IDataType & keys_type);
|
|
|
|
static MutableColumnUniquePtr createColumnUnique(const IDataType & keys_type, MutableColumnPtr && keys);
|
2018-06-07 18:14:37 +00:00
|
|
|
|
2018-05-03 14:53:35 +00:00
|
|
|
private:
|
|
|
|
|
2019-02-19 20:01:31 +00:00
|
|
|
template <typename ... Params>
|
|
|
|
using SerializeFunctionPtr = void (IDataType::*)(const IColumn &, size_t, Params ...) const;
|
2018-05-03 14:53:35 +00:00
|
|
|
|
2019-02-19 20:01:31 +00:00
|
|
|
template <typename... Params, typename... Args>
|
|
|
|
void serializeImpl(const IColumn & column, size_t row_num, SerializeFunctionPtr<Params...> func, Args &&... args) const;
|
2018-05-03 14:53:35 +00:00
|
|
|
|
2019-02-19 20:01:31 +00:00
|
|
|
template <typename ... Params>
|
|
|
|
using DeserializeFunctionPtr = void (IDataType::*)(IColumn &, Params ...) const;
|
2018-05-03 14:53:35 +00:00
|
|
|
|
2019-02-19 20:01:31 +00:00
|
|
|
template <typename ... Params, typename... Args>
|
|
|
|
void deserializeImpl(IColumn & column, DeserializeFunctionPtr<Params...> func, Args &&... args) const;
|
2018-05-03 14:53:35 +00:00
|
|
|
|
2018-07-09 18:19:03 +00:00
|
|
|
template <typename Creator>
|
|
|
|
static MutableColumnUniquePtr createColumnUniqueImpl(const IDataType & keys_type, const Creator & creator);
|
2018-03-29 14:04:24 +00:00
|
|
|
};
|
2018-03-14 10:47:13 +00:00
|
|
|
|
2018-09-27 15:55:22 +00:00
|
|
|
/// Returns dictionary type if type is DataTypeLowCardinality, type otherwise.
|
2018-08-21 14:53:51 +00:00
|
|
|
DataTypePtr removeLowCardinality(const DataTypePtr & type);
|
|
|
|
|
2018-12-06 11:24:07 +00:00
|
|
|
/// Remove LowCardinality recursively from all nested types.
|
|
|
|
DataTypePtr recursiveRemoveLowCardinality(const DataTypePtr & type);
|
|
|
|
|
|
|
|
/// Remove LowCardinality recursively from all nested columns.
|
|
|
|
ColumnPtr recursiveRemoveLowCardinality(const ColumnPtr & column);
|
|
|
|
|
|
|
|
/// Convert column of type from_type to type to_type by converting nested LowCardinality columns.
|
2019-11-26 09:59:31 +00:00
|
|
|
ColumnPtr recursiveTypeConversion(const ColumnPtr & column, const DataTypePtr & from_type, const DataTypePtr & to_type);
|
2018-12-06 11:24:07 +00:00
|
|
|
|
2018-03-14 10:47:13 +00:00
|
|
|
}
|