2021-03-09 14:10:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DataTypes/IDataType.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// A nullable data type is an ordinary data type provided with a tag
|
|
|
|
/// indicating that it also contains the NULL value. The following class
|
|
|
|
/// embodies this concept.
|
|
|
|
class DataTypeNullable final : public IDataType
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr bool is_parametric = true;
|
|
|
|
|
|
|
|
explicit DataTypeNullable(const DataTypePtr & nested_data_type_);
|
|
|
|
std::string doGetName() const override { return "Nullable(" + nested_data_type->getName() + ")"; }
|
|
|
|
const char * getFamilyName() const override { return "Nullable"; }
|
|
|
|
TypeIndex getTypeId() const override { return TypeIndex::Nullable; }
|
|
|
|
|
|
|
|
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 nested_data_type->cannotBeStoredInTables(); }
|
|
|
|
bool shouldAlignRightInPrettyFormats() const override { return nested_data_type->shouldAlignRightInPrettyFormats(); }
|
|
|
|
bool textCanContainOnlyValidUTF8() const override { return nested_data_type->textCanContainOnlyValidUTF8(); }
|
|
|
|
bool isComparable() const override { return nested_data_type->isComparable(); }
|
|
|
|
bool canBeComparedWithCollation() const override { return nested_data_type->canBeComparedWithCollation(); }
|
|
|
|
bool canBeUsedAsVersion() const override { return false; }
|
|
|
|
bool isSummable() const override { return nested_data_type->isSummable(); }
|
|
|
|
bool canBeUsedInBooleanContext() const override { return nested_data_type->canBeUsedInBooleanContext() || onlyNull(); }
|
|
|
|
bool haveMaximumSizeOfValue() const override { return nested_data_type->haveMaximumSizeOfValue(); }
|
|
|
|
size_t getMaximumSizeOfValueInMemory() const override { return 1 + nested_data_type->getMaximumSizeOfValueInMemory(); }
|
|
|
|
bool isNullable() const override { return true; }
|
|
|
|
size_t getSizeOfValueInMemory() const override;
|
|
|
|
bool onlyNull() const override;
|
|
|
|
bool canBeInsideLowCardinality() const override { return nested_data_type->canBeInsideLowCardinality(); }
|
2021-12-01 21:34:32 +00:00
|
|
|
bool canBePromoted() const override { return nested_data_type->canBePromoted(); }
|
2021-03-09 14:10:28 +00:00
|
|
|
|
|
|
|
const DataTypePtr & getNestedType() const { return nested_data_type; }
|
|
|
|
private:
|
|
|
|
SerializationPtr doGetDefaultSerialization() const override;
|
|
|
|
|
|
|
|
DataTypePtr nested_data_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
DataTypePtr makeNullable(const DataTypePtr & type);
|
2022-07-07 18:53:20 +00:00
|
|
|
DataTypePtr makeNullableSafe(const DataTypePtr & type);
|
2021-03-09 14:10:28 +00:00
|
|
|
DataTypePtr removeNullable(const DataTypePtr & type);
|
2023-02-08 19:14:28 +00:00
|
|
|
DataTypePtr makeNullableOrLowCardinalityNullable(const DataTypePtr & type);
|
2023-12-19 16:43:30 +00:00
|
|
|
DataTypePtr makeNullableOrLowCardinalityNullableSafe(const DataTypePtr & type);
|
|
|
|
/// Nullable(T) -> T, LowCardinality(Nullable(T)) -> T
|
|
|
|
DataTypePtr removeNullableOrLowCardinalityNullable(const DataTypePtr & type);
|
2021-03-09 14:10:28 +00:00
|
|
|
|
|
|
|
}
|