#include #include #include namespace DB { /// TODO: Убрать copy-paste из FunctionsConditional.h template struct DataTypeFromFieldTypeOrError { static DataTypePtr getDataType() { return new typename DataTypeFromFieldType::Type; } }; template <> struct DataTypeFromFieldTypeOrError { static DataTypePtr getDataType() { return nullptr; } }; template DataTypePtr getSmallestCommonNumericTypeImpl() { using ResultType = typename NumberTraits::ResultOfIf::Type; auto type_res = DataTypeFromFieldTypeOrError::getDataType(); if (!type_res) throw Exception("Types " + TypeName::get() + " and " + TypeName::get() + " are not upscalable to a common type without loss of precision", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); return type_res; } template DataTypePtr getSmallestCommonNumericTypeLeft(const IDataType & t2) { if (typeid_cast(&t2)) return getSmallestCommonNumericTypeImpl(); if (typeid_cast(&t2)) return getSmallestCommonNumericTypeImpl(); if (typeid_cast(&t2)) return getSmallestCommonNumericTypeImpl(); if (typeid_cast(&t2)) return getSmallestCommonNumericTypeImpl(); if (typeid_cast(&t2)) return getSmallestCommonNumericTypeImpl(); if (typeid_cast(&t2)) return getSmallestCommonNumericTypeImpl(); if (typeid_cast(&t2)) return getSmallestCommonNumericTypeImpl(); if (typeid_cast(&t2)) return getSmallestCommonNumericTypeImpl(); if (typeid_cast(&t2)) return getSmallestCommonNumericTypeImpl(); if (typeid_cast(&t2)) return getSmallestCommonNumericTypeImpl(); throw Exception("Logical error: not a numeric type passed to function getSmallestCommonNumericType", ErrorCodes::LOGICAL_ERROR); } DataTypePtr getSmallestCommonNumericType(const IDataType & t1, const IDataType & t2) { if (typeid_cast(&t1)) return getSmallestCommonNumericTypeLeft(t2); if (typeid_cast(&t1)) return getSmallestCommonNumericTypeLeft(t2); if (typeid_cast(&t1)) return getSmallestCommonNumericTypeLeft(t2); if (typeid_cast(&t1)) return getSmallestCommonNumericTypeLeft(t2); if (typeid_cast(&t1)) return getSmallestCommonNumericTypeLeft(t2); if (typeid_cast(&t1)) return getSmallestCommonNumericTypeLeft(t2); if (typeid_cast(&t1)) return getSmallestCommonNumericTypeLeft(t2); if (typeid_cast(&t1)) return getSmallestCommonNumericTypeLeft(t2); if (typeid_cast(&t1)) return getSmallestCommonNumericTypeLeft(t2); if (typeid_cast(&t1)) return getSmallestCommonNumericTypeLeft(t2); throw Exception("Logical error: not a numeric type passed to function getSmallestCommonNumericType", ErrorCodes::LOGICAL_ERROR); } } namespace DB { void registerFunctionsMiscellaneous(FunctionFactory & factory) { factory.registerFunction(); } }