2021-03-09 14:10:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DataTypes/IDataType.h>
|
|
|
|
#include <Columns/IColumnUnique.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class DataTypeLowCardinality : public IDataType
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
DataTypePtr dictionary_type;
|
2023-05-31 22:30:26 +00:00
|
|
|
|
2021-03-09 14:10:28 +00:00
|
|
|
|
|
|
|
public:
|
2022-02-05 08:10:28 +00:00
|
|
|
explicit DataTypeLowCardinality(DataTypePtr dictionary_type_);
|
2021-03-09 14:10:28 +00:00
|
|
|
|
|
|
|
const DataTypePtr & getDictionaryType() const { return dictionary_type; }
|
|
|
|
|
|
|
|
String doGetName() const override
|
|
|
|
{
|
|
|
|
return "LowCardinality(" + dictionary_type->getName() + ")";
|
|
|
|
}
|
|
|
|
const char * getFamilyName() const override { return "LowCardinality"; }
|
2023-05-24 12:49:18 +00:00
|
|
|
|
2021-03-09 14:10:28 +00:00
|
|
|
TypeIndex getTypeId() const override { return TypeIndex::LowCardinality; }
|
|
|
|
|
|
|
|
MutableColumnPtr createColumn() const override;
|
|
|
|
|
|
|
|
Field getDefault() const override;
|
|
|
|
|
|
|
|
bool equals(const IDataType & rhs) const override;
|
|
|
|
|
|
|
|
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(); }
|
|
|
|
bool isSummable() const override { return dictionary_type->isSummable(); }
|
|
|
|
bool canBeUsedInBitOperations() const override { return dictionary_type->canBeUsedInBitOperations(); }
|
|
|
|
bool canBeUsedInBooleanContext() const override { return dictionary_type->canBeUsedInBooleanContext(); }
|
|
|
|
bool isValueRepresentedByNumber() const override { return dictionary_type->isValueRepresentedByNumber(); }
|
|
|
|
bool isValueRepresentedByInteger() const override { return dictionary_type->isValueRepresentedByInteger(); }
|
2023-08-02 17:47:42 +00:00
|
|
|
bool isValueRepresentedByUnsignedInteger() const override { return dictionary_type->isValueRepresentedByUnsignedInteger(); }
|
2021-03-09 14:10:28 +00:00
|
|
|
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; }
|
|
|
|
bool lowCardinality() const override { return true; }
|
2021-04-15 02:16:09 +00:00
|
|
|
bool supportsSparseSerialization() const override { return false; }
|
2021-10-14 10:32:49 +00:00
|
|
|
bool isLowCardinalityNullable() const override { return dictionary_type->isNullable(); }
|
2021-03-09 14:10:28 +00:00
|
|
|
|
|
|
|
static MutableColumnUniquePtr createColumnUnique(const IDataType & keys_type);
|
|
|
|
static MutableColumnUniquePtr createColumnUnique(const IDataType & keys_type, MutableColumnPtr && keys);
|
|
|
|
|
|
|
|
private:
|
|
|
|
SerializationPtr doGetDefaultSerialization() const override;
|
|
|
|
|
|
|
|
template <typename ... Params>
|
|
|
|
using SerializeFunctionPtr = void (IDataType::*)(const IColumn &, size_t, Params ...) const;
|
|
|
|
|
|
|
|
template <typename... Params, typename... Args>
|
|
|
|
void serializeImpl(const IColumn & column, size_t row_num, SerializeFunctionPtr<Params...> func, Args &&... args) const;
|
|
|
|
|
|
|
|
template <typename ... Params>
|
|
|
|
using DeserializeFunctionPtr = void (IDataType::*)(IColumn &, Params ...) const;
|
|
|
|
|
|
|
|
template <typename ... Params, typename... Args>
|
|
|
|
void deserializeImpl(IColumn & column, DeserializeFunctionPtr<Params...> func, Args &&... args) const;
|
|
|
|
|
|
|
|
template <typename Creator>
|
|
|
|
static MutableColumnUniquePtr createColumnUniqueImpl(const IDataType & keys_type, const Creator & creator);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Returns dictionary type if type is DataTypeLowCardinality, type otherwise.
|
|
|
|
DataTypePtr removeLowCardinality(const DataTypePtr & type);
|
|
|
|
|
|
|
|
/// 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.
|
2023-02-27 19:28:19 +00:00
|
|
|
ColumnPtr recursiveLowCardinalityTypeConversion(const ColumnPtr & column, const DataTypePtr & from_type, const DataTypePtr & to_type);
|
2021-03-09 14:10:28 +00:00
|
|
|
|
2023-10-10 17:51:09 +00:00
|
|
|
/// Removes LowCardinality and Nullable in a correct order and returns T
|
|
|
|
/// if the type is LowCardinality(T) or LowCardinality(Nullable(T)); type otherwise
|
|
|
|
DataTypePtr removeLowCardinalityAndNullable(const DataTypePtr & type);
|
2021-03-09 14:10:28 +00:00
|
|
|
}
|