Merge pull request #33832 from kitaisreal/type-id-name-fix

TypeId better naming
This commit is contained in:
Maksim Kita 2022-01-21 11:36:02 +01:00 committed by GitHub
commit c68fe35b2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 28 deletions

View File

@ -87,7 +87,7 @@ private:
public:
const char * getFamilyName() const override { return TypeName<T>.data(); }
TypeIndex getDataType() const override { return TypeId<T>; }
TypeIndex getDataType() const override { return TypeToTypeIndex<T>; }
bool isNumeric() const override { return false; }
bool canBeInsideNullable() const override { return true; }

View File

@ -238,7 +238,7 @@ public:
}
const char * getFamilyName() const override { return TypeName<T>.data(); }
TypeIndex getDataType() const override { return TypeId<T>; }
TypeIndex getDataType() const override { return TypeToTypeIndex<T>; }
MutableColumnPtr cloneResized(size_t size) const override;

View File

@ -10,12 +10,12 @@ namespace DB
* Returns TypeIndex::Nothing if type was not present in TypeIndex;
* Returns TypeIndex element otherwise.
*
* @example TypeId<UInt8> == TypeIndex::UInt8
* @example TypeId<MySuperType> == TypeIndex::Nothing
* @example TypeToTypeIndex<UInt8> == TypeIndex::UInt8
* @example TypeToTypeIndex<MySuperType> == TypeIndex::Nothing
*/
template <class T> inline constexpr TypeIndex TypeId = TypeIndex::Nothing;
template <class T> inline constexpr TypeIndex TypeToTypeIndex = TypeIndex::Nothing;
template <TypeIndex index> struct ReverseTypeIdT : std::false_type {};
template <TypeIndex index> struct TypeIndexToTypeHelper : std::false_type {};
/**
* Obtain real type from TypeIndex if possible.
@ -23,14 +23,14 @@ template <TypeIndex index> struct ReverseTypeIdT : std::false_type {};
* Returns a type alias if is corresponds to TypeIndex value.
* Yields a compiler error otherwise.
*
* @example ReverseTypeId<TypeIndex::UInt8> == UInt8
* @example TypeIndexToType<TypeIndex::UInt8> == UInt8
*/
template <TypeIndex index> using ReverseTypeId = typename ReverseTypeIdT<index>::T;
template <TypeIndex index> constexpr bool HasReverseTypeId = ReverseTypeIdT<index>::value;
template <TypeIndex index> using TypeIndexToType = typename TypeIndexToTypeHelper<index>::T;
template <TypeIndex index> constexpr bool TypeIndexHasType = TypeIndexToTypeHelper<index>::value;
#define TYPEID_MAP(_A) \
template <> inline constexpr TypeIndex TypeId<_A> = TypeIndex::_A; \
template <> struct ReverseTypeIdT<TypeIndex::_A> : std::true_type { using T = _A; };
template <> inline constexpr TypeIndex TypeToTypeIndex<_A> = TypeIndex::_A; \
template <> struct TypeIndexToTypeHelper<TypeIndex::_A> : std::true_type { using T = _A; };
TYPEID_MAP(UInt8)
TYPEID_MAP(UInt16)
@ -58,4 +58,7 @@ TYPEID_MAP(String)
struct Array;
TYPEID_MAP(Array)
#undef TYPEID_MAP
}

View File

@ -1,14 +1,15 @@
#pragma once
#include <Columns/ColumnDecimal.h>
#include <Core/DecimalFunctions.h>
#include <DataTypes/IDataType.h>
#include <DataTypes/DataTypesNumber.h>
#include <Interpreters/Context_fwd.h>
#include <cmath>
#include <type_traits>
#include <Core/TypeId.h>
#include <Core/DecimalFunctions.h>
#include <Columns/ColumnDecimal.h>
#include <DataTypes/IDataType.h>
#include <DataTypes/DataTypesNumber.h>
#include <Interpreters/Context_fwd.h>
namespace DB
{
@ -59,7 +60,7 @@ class DataTypeDecimalBase : public IDataType
public:
using FieldType = T;
using ColumnType = ColumnDecimal<T>;
static constexpr auto type_id = TypeId<T>;
static constexpr auto type_id = TypeToTypeIndex<T>;
static constexpr bool is_parametric = true;
@ -75,7 +76,7 @@ public:
throw Exception("Scale " + std::to_string(scale) + " is out of bounds", ErrorCodes::ARGUMENT_OUT_OF_BOUND);
}
TypeIndex getTypeId() const override { return TypeId<T>; }
TypeIndex getTypeId() const override { return TypeToTypeIndex<T>; }
Field getDefault() const override;
MutableColumnPtr createColumn() const override;

View File

@ -1,5 +1,6 @@
#pragma once
#include <Core/TypeId.h>
#include <DataTypes/IDataType.h>
#include <DataTypes/Serializations/SerializationNumber.h>
@ -20,13 +21,13 @@ class DataTypeNumberBase : public IDataType
public:
static constexpr bool is_parametric = false;
static constexpr auto family_name = TypeName<T>;
static constexpr auto type_id = TypeId<T>;
static constexpr auto type_id = TypeToTypeIndex<T>;
using FieldType = T;
using ColumnType = ColumnVector<T>;
const char * getFamilyName() const override { return TypeName<T>.data(); }
TypeIndex getTypeId() const override { return TypeId<T>; }
TypeIndex getTypeId() const override { return TypeToTypeIndex<T>; }
Field getDefault() const override;

View File

@ -38,7 +38,7 @@ public:
const char * getFamilyName() const override { return family_name; }
std::string doGetName() const override;
TypeIndex getTypeId() const override { return TypeId<T>; }
TypeIndex getTypeId() const override { return TypeToTypeIndex<T>; }
bool canBePromoted() const override { return true; }
DataTypePtr promoteNumericType() const override;

View File

@ -1,14 +1,15 @@
#pragma once
#include <memory>
#include <Common/COW.h>
#include <boost/noncopyable.hpp>
#include <Core/Names.h>
#include <Core/TypeId.h>
#include <Common/COW.h>
#include <DataTypes/DataTypeCustom.h>
#include <DataTypes/Serializations/ISerialization.h>
#include <DataTypes/Serializations/SerializationInfo.h>
namespace DB
{
@ -475,7 +476,7 @@ template <typename T, typename DataType>
inline bool isColumnedAsDecimalT(const DataType & data_type)
{
const WhichDataType which(data_type);
return (which.isDecimal() || which.isDateTime64()) && which.idx == TypeId<T>;
return (which.isDecimal() || which.isDateTime64()) && which.idx == TypeToTypeIndex<T>;
}
template <typename T>

View File

@ -7,12 +7,14 @@
#include <Poco/Util/AbstractConfiguration.h>
#include <base/EnumReflection.h>
#include <Core/Field.h>
#include <Core/TypeId.h>
#include <IO/ReadBufferFromString.h>
#include <DataTypes/IDataType.h>
#include <Interpreters/IExternalLoadable.h>
#include <base/EnumReflection.h>
#include <Core/TypeId.h>
#if defined(__GNUC__)
/// GCC mistakenly warns about the names in enum class.
@ -26,7 +28,7 @@ using TypeIndexUnderlying = magic_enum::underlying_type_t<TypeIndex>;
// We need to be able to map TypeIndex -> AttributeUnderlyingType and AttributeUnderlyingType -> real type
// The first can be done by defining AttributeUnderlyingType enum values to TypeIndex values and then performing
// a enum_cast.
// The second can be achieved by using ReverseTypeId
// The second can be achieved by using TypeIndexToType
#define map_item(__T) __T = static_cast<TypeIndexUnderlying>(TypeIndex::__T)
enum class AttributeUnderlyingType : TypeIndexUnderlying
@ -73,7 +75,7 @@ template <AttributeUnderlyingType type>
struct DictionaryAttributeType
{
/// Converts @c type to it underlying type e.g. AttributeUnderlyingType::UInt8 -> UInt8
using AttributeType = ReverseTypeId<
using AttributeType = TypeIndexToType<
static_cast<TypeIndex>(
static_cast<TypeIndexUnderlying>(type))>;
};