mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
Add field CustomType
This commit is contained in:
parent
fe3a755064
commit
12b62de374
@ -106,6 +106,11 @@ public:
|
||||
throw Exception(ErrorCodes::CANNOT_CONVERT_TYPE, "Cannot convert AggregateFunctionStateData to {}", demangle(typeid(T).name()));
|
||||
}
|
||||
|
||||
T operator() (const CustomType &) const
|
||||
{
|
||||
throw Exception(ErrorCodes::CANNOT_CONVERT_TYPE, "Cannot convert CustomType to {}", demangle(typeid(T).name()));
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
requires is_big_int_v<U>
|
||||
T operator() (const U & x) const
|
||||
|
@ -30,8 +30,8 @@ public:
|
||||
String operator() (const DecimalField<Decimal128> & x) const;
|
||||
String operator() (const DecimalField<Decimal256> & x) const;
|
||||
String operator() (const AggregateFunctionStateData & x) const;
|
||||
String operator() (const CustomType & x) const;
|
||||
String operator() (const bool & x) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,7 @@ public:
|
||||
void operator() (const DecimalField<Decimal128> & x) const;
|
||||
void operator() (const DecimalField<Decimal256> & x) const;
|
||||
void operator() (const AggregateFunctionStateData & x) const;
|
||||
void operator() (const CustomType & x) const;
|
||||
void operator() (const bool & x) const;
|
||||
};
|
||||
|
||||
|
@ -31,6 +31,7 @@ public:
|
||||
bool operator() (IPv4 &) const;
|
||||
bool operator() (IPv6 &) const;
|
||||
bool operator() (AggregateFunctionStateData &) const;
|
||||
bool operator() (CustomType &) const;
|
||||
bool operator() (bool &) const;
|
||||
|
||||
template <typename T>
|
||||
|
@ -69,6 +69,7 @@ String FieldVisitorToString::operator() (const IPv4 & x) const { return formatQu
|
||||
String FieldVisitorToString::operator() (const IPv6 & x) const { return formatQuoted(x); }
|
||||
String FieldVisitorToString::operator() (const AggregateFunctionStateData & x) const { return formatQuoted(x.data); }
|
||||
String FieldVisitorToString::operator() (const bool & x) const { return x ? "true" : "false"; }
|
||||
String FieldVisitorToString::operator() (const CustomType & x) const { return x.toString(); }
|
||||
|
||||
String FieldVisitorToString::operator() (const Array & x) const
|
||||
{
|
||||
|
@ -30,6 +30,7 @@ public:
|
||||
String operator() (const DecimalField<Decimal128> & x) const;
|
||||
String operator() (const DecimalField<Decimal256> & x) const;
|
||||
String operator() (const AggregateFunctionStateData & x) const;
|
||||
String operator() (const CustomType & x) const;
|
||||
String operator() (const bool & x) const;
|
||||
};
|
||||
|
||||
|
@ -29,8 +29,8 @@ public:
|
||||
void operator() (const DecimalField<Decimal128> & x, WriteBuffer & buf) const;
|
||||
void operator() (const DecimalField<Decimal256> & x, WriteBuffer & buf) const;
|
||||
void operator() (const AggregateFunctionStateData & x, WriteBuffer & buf) const;
|
||||
void operator() (const CustomType & x, WriteBuffer & buf) const;
|
||||
void operator() (const bool & x, WriteBuffer & buf) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
@ -597,6 +597,7 @@ String fieldTypeToString(Field::Types::Which type)
|
||||
case Field::Types::Which::UUID: return "UUID";
|
||||
case Field::Types::Which::IPv4: return "IPv4";
|
||||
case Field::Types::Which::IPv6: return "IPv6";
|
||||
case Field::Types::Which::CustomType: return "CustomType";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,6 +102,43 @@ struct AggregateFunctionStateData
|
||||
}
|
||||
};
|
||||
|
||||
struct CustomType
|
||||
{
|
||||
struct CustomTypeImpl
|
||||
{
|
||||
virtual ~CustomTypeImpl() = default;
|
||||
virtual const char * getTypeName() const = 0;
|
||||
virtual String toString() const = 0;
|
||||
|
||||
// virtual std::unique_ptr<CustomTypeImpl> clone() const;
|
||||
// virtual std::optional<Types::Which> getBaseTypeIfConvertible() const;
|
||||
// virtual std::optional<Field> tryConvertToBaseType(Types::Which dest_type) const
|
||||
|
||||
bool operator < (const CustomTypeImpl &) const { throwNotImpleneted("<"); }
|
||||
bool operator <= (const CustomTypeImpl &) const { throwNotImpleneted("<="); }
|
||||
bool operator > (const CustomTypeImpl &) const { throwNotImpleneted(">"); }
|
||||
bool operator >= (const CustomTypeImpl &) const { throwNotImpleneted(">="); }
|
||||
bool operator == (const CustomTypeImpl &) const { throwNotImpleneted("=="); }
|
||||
|
||||
[[noreturn]] void throwNotImpleneted(const std::string & op) const
|
||||
{
|
||||
throw Exception(
|
||||
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Operation {} is not implemented for custom type {}", op, getTypeName());
|
||||
}
|
||||
};
|
||||
|
||||
String toString() const { return impl->toString(); }
|
||||
|
||||
bool operator < (const CustomType & rhs) const { return *impl < *rhs.impl; }
|
||||
bool operator <= (const CustomType & rhs) const { return *impl <= *rhs.impl; }
|
||||
bool operator > (const CustomType & rhs) const { return *impl > *rhs.impl; }
|
||||
bool operator >= (const CustomType & rhs) const { return *impl >= *rhs.impl; }
|
||||
bool operator == (const CustomType & rhs) const { return *impl == *rhs.impl; }
|
||||
|
||||
std::shared_ptr<CustomTypeImpl> impl;
|
||||
|
||||
};
|
||||
|
||||
template <typename T> bool decimalEqual(T x, T y, UInt32 x_scale, UInt32 y_scale);
|
||||
template <typename T> bool decimalLess(T x, T y, UInt32 x_scale, UInt32 y_scale);
|
||||
template <typename T> bool decimalLessOrEqual(T x, T y, UInt32 x_scale, UInt32 y_scale);
|
||||
@ -233,6 +270,7 @@ template <> struct NearestFieldTypeImpl<bool> { using Type = UInt64; };
|
||||
template <> struct NearestFieldTypeImpl<Null> { using Type = Null; };
|
||||
|
||||
template <> struct NearestFieldTypeImpl<AggregateFunctionStateData> { using Type = AggregateFunctionStateData; };
|
||||
template <> struct NearestFieldTypeImpl<CustomType> { using Type = CustomType; };
|
||||
|
||||
// For enum types, use the field type that corresponds to their underlying type.
|
||||
template <typename T>
|
||||
@ -297,6 +335,7 @@ public:
|
||||
Object = 29,
|
||||
IPv4 = 30,
|
||||
IPv6 = 31,
|
||||
CustomType = 32,
|
||||
};
|
||||
};
|
||||
|
||||
@ -486,6 +525,7 @@ public:
|
||||
case Types::Decimal128: return get<DecimalField<Decimal128>>() < rhs.get<DecimalField<Decimal128>>();
|
||||
case Types::Decimal256: return get<DecimalField<Decimal256>>() < rhs.get<DecimalField<Decimal256>>();
|
||||
case Types::AggregateFunctionState: return get<AggregateFunctionStateData>() < rhs.get<AggregateFunctionStateData>();
|
||||
case Types::CustomType: return get<CustomType>() < rhs.get<CustomType>();
|
||||
}
|
||||
|
||||
throw Exception(ErrorCodes::BAD_TYPE_OF_FIELD, "Bad type of Field");
|
||||
@ -527,6 +567,7 @@ public:
|
||||
case Types::Decimal128: return get<DecimalField<Decimal128>>() <= rhs.get<DecimalField<Decimal128>>();
|
||||
case Types::Decimal256: return get<DecimalField<Decimal256>>() <= rhs.get<DecimalField<Decimal256>>();
|
||||
case Types::AggregateFunctionState: return get<AggregateFunctionStateData>() <= rhs.get<AggregateFunctionStateData>();
|
||||
case Types::CustomType: return get<CustomType>() <= rhs.get<CustomType>();
|
||||
}
|
||||
|
||||
throw Exception(ErrorCodes::BAD_TYPE_OF_FIELD, "Bad type of Field");
|
||||
@ -572,6 +613,7 @@ public:
|
||||
case Types::Decimal128: return get<DecimalField<Decimal128>>() == rhs.get<DecimalField<Decimal128>>();
|
||||
case Types::Decimal256: return get<DecimalField<Decimal256>>() == rhs.get<DecimalField<Decimal256>>();
|
||||
case Types::AggregateFunctionState: return get<AggregateFunctionStateData>() == rhs.get<AggregateFunctionStateData>();
|
||||
case Types::CustomType: return get<CustomType>() == rhs.get<CustomType>();
|
||||
}
|
||||
|
||||
throw Exception(ErrorCodes::BAD_TYPE_OF_FIELD, "Bad type of Field");
|
||||
@ -615,6 +657,7 @@ public:
|
||||
case Types::Decimal128: return f(field.template get<DecimalField<Decimal128>>());
|
||||
case Types::Decimal256: return f(field.template get<DecimalField<Decimal256>>());
|
||||
case Types::AggregateFunctionState: return f(field.template get<AggregateFunctionStateData>());
|
||||
case Types::CustomType: return f(field.template get<CustomType>());
|
||||
}
|
||||
|
||||
UNREACHABLE();
|
||||
@ -627,7 +670,7 @@ private:
|
||||
std::aligned_union_t<DBMS_MIN_FIELD_SIZE - sizeof(Types::Which),
|
||||
Null, UInt64, UInt128, UInt256, Int64, Int128, Int256, UUID, IPv4, IPv6, Float64, String, Array, Tuple, Map,
|
||||
DecimalField<Decimal32>, DecimalField<Decimal64>, DecimalField<Decimal128>, DecimalField<Decimal256>,
|
||||
AggregateFunctionStateData
|
||||
AggregateFunctionStateData, CustomType
|
||||
> storage;
|
||||
|
||||
Types::Which which;
|
||||
@ -731,6 +774,9 @@ private:
|
||||
case Types::AggregateFunctionState:
|
||||
destroy<AggregateFunctionStateData>();
|
||||
break;
|
||||
case Types::CustomType:
|
||||
destroy<CustomType>();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -774,6 +820,7 @@ template <> struct Field::TypeToEnum<DecimalField<Decimal128>>{ static constexpr
|
||||
template <> struct Field::TypeToEnum<DecimalField<Decimal256>>{ static constexpr Types::Which value = Types::Decimal256; };
|
||||
template <> struct Field::TypeToEnum<DecimalField<DateTime64>>{ static constexpr Types::Which value = Types::Decimal64; };
|
||||
template <> struct Field::TypeToEnum<AggregateFunctionStateData>{ static constexpr Types::Which value = Types::AggregateFunctionState; };
|
||||
template <> struct Field::TypeToEnum<CustomType>{ static constexpr Types::Which value = Types::CustomType; };
|
||||
template <> struct Field::TypeToEnum<bool>{ static constexpr Types::Which value = Types::Bool; };
|
||||
|
||||
template <> struct Field::EnumToType<Field::Types::Null> { using Type = Null; };
|
||||
@ -797,6 +844,7 @@ template <> struct Field::EnumToType<Field::Types::Decimal64> { using Type = Dec
|
||||
template <> struct Field::EnumToType<Field::Types::Decimal128> { using Type = DecimalField<Decimal128>; };
|
||||
template <> struct Field::EnumToType<Field::Types::Decimal256> { using Type = DecimalField<Decimal256>; };
|
||||
template <> struct Field::EnumToType<Field::Types::AggregateFunctionState> { using Type = DecimalField<AggregateFunctionStateData>; };
|
||||
template <> struct Field::EnumToType<Field::Types::CustomType> { using Type = CustomType; };
|
||||
template <> struct Field::EnumToType<Field::Types::Bool> { using Type = UInt64; };
|
||||
|
||||
inline constexpr bool isInt64OrUInt64FieldType(Field::Types::Which t)
|
||||
@ -935,6 +983,10 @@ void readBinary(Object & x, ReadBuffer & buf);
|
||||
|
||||
void writeBinary(const Object & x, WriteBuffer & buf);
|
||||
void writeText(const Object & x, WriteBuffer & buf);
|
||||
|
||||
void writeBinary(const CustomType & x, WriteBuffer & buf);
|
||||
void writeText(const CustomType & x, WriteBuffer & buf);
|
||||
|
||||
[[noreturn]] inline void writeQuoted(const Object &, WriteBuffer &) { throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Cannot write Object quoted."); }
|
||||
|
||||
__attribute__ ((noreturn)) inline void writeText(const AggregateFunctionStateData &, WriteBuffer &)
|
||||
|
@ -191,6 +191,12 @@ DataTypePtr FieldToDataType<on_error>::operator() (const AggregateFunctionStateD
|
||||
return DataTypeFactory::instance().get(name);
|
||||
}
|
||||
|
||||
template <LeastSupertypeOnError on_error>
|
||||
DataTypePtr FieldToDataType<on_error>::operator() (const CustomType &) const
|
||||
{
|
||||
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Not implemented");
|
||||
}
|
||||
|
||||
template <LeastSupertypeOnError on_error>
|
||||
DataTypePtr FieldToDataType<on_error>::operator()(const bool &) const
|
||||
{
|
||||
|
@ -41,6 +41,7 @@ public:
|
||||
DataTypePtr operator() (const DecimalField<Decimal128> & x) const;
|
||||
DataTypePtr operator() (const DecimalField<Decimal256> & x) const;
|
||||
DataTypePtr operator() (const AggregateFunctionStateData & x) const;
|
||||
DataTypePtr operator() (const CustomType & x) const;
|
||||
DataTypePtr operator() (const UInt256 & x) const;
|
||||
DataTypePtr operator() (const Int256 & x) const;
|
||||
DataTypePtr operator() (const bool & x) const;
|
||||
|
Loading…
Reference in New Issue
Block a user