Refactoring: Un-inline some error handling methods

This commit is contained in:
Robert Schulze 2022-09-30 09:05:34 +00:00
parent 8e727d4fbc
commit d726ca3212
No known key found for this signature in database
GPG Key ID: 26703B55FB13728A
3 changed files with 80 additions and 65 deletions

View File

@ -0,0 +1,26 @@
#include <Functions/DateTimeTransforms.h>
namespace DB
{
namespace ErrorCodes
{
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
}
void throwDateIsNotSupported(const char * name)
{
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type Date of argument for function {}", name);
}
void throwDateTimeIsNotSupported(const char * name)
{
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type DateTime of argument for function {}", name);
}
void throwDate32IsNotSupported(const char * name)
{
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type Date32 of argument for function {}", name);
}
}

View File

@ -36,20 +36,9 @@ namespace ErrorCodes
* factor-transformation F is "round to the nearest month" (2015-02-03 -> 2015-02-01).
*/
static inline UInt32 dateIsNotSupported(const char * name)
{
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type Date of argument for function {}", name);
}
static inline UInt32 dateTimeIsNotSupported(const char * name)
{
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type DateTime of argument for function {}", name);
}
static inline Int64 date32IsNotSupported(const char * name)
{
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type Date32 of argument for function {}", name);
}
[[noreturn]] void throwDateIsNotSupported(const char * name);
[[noreturn]] void throwDateTimeIsNotSupported(const char * name);
[[noreturn]] void throwDate32IsNotSupported(const char * name);
/// This factor transformation will say that the function is monotone everywhere.
struct ZeroTransform
@ -335,11 +324,11 @@ struct ToTimeImpl
}
static inline UInt32 execute(Int32, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline UInt32 execute(UInt16, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
using FactorTransform = ToDateImpl;
@ -362,11 +351,11 @@ struct ToStartOfMinuteImpl
}
static inline UInt32 execute(Int32, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline UInt32 execute(UInt16, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline DecimalUtils::DecimalComponents<DateTime64> executeExtendedResult(const DecimalUtils::DecimalComponents<DateTime64> & t, const DateLUTImpl & time_zone)
{
@ -374,7 +363,7 @@ struct ToStartOfMinuteImpl
}
static inline Int64 executeExtendedResult(Int32, const DateLUTImpl &)
{
return date32IsNotSupported(name);
throwDate32IsNotSupported(name);
}
using FactorTransform = ZeroTransform;
@ -409,11 +398,11 @@ struct ToStartOfSecondImpl
}
static inline UInt32 execute(Int32, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline UInt32 execute(UInt16, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
using FactorTransform = ZeroTransform;
@ -456,11 +445,11 @@ struct ToStartOfMillisecondImpl
}
static inline UInt32 execute(Int32, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline UInt32 execute(UInt16, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
using FactorTransform = ZeroTransform;
@ -499,11 +488,11 @@ struct ToStartOfMicrosecondImpl
}
static inline UInt32 execute(Int32, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline UInt32 execute(UInt16, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
using FactorTransform = ZeroTransform;
@ -536,11 +525,11 @@ struct ToStartOfNanosecondImpl
}
static inline UInt32 execute(Int32, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline UInt32 execute(UInt16, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
using FactorTransform = ZeroTransform;
@ -560,11 +549,11 @@ struct ToStartOfFiveMinutesImpl
}
static inline UInt32 execute(Int32, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline UInt32 execute(UInt16, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline DecimalUtils::DecimalComponents<DateTime64> executeExtendedResult(const DecimalUtils::DecimalComponents<DateTime64> & t, const DateLUTImpl & time_zone)
{
@ -572,7 +561,7 @@ struct ToStartOfFiveMinutesImpl
}
static inline Int64 executeExtendedResult(Int32, const DateLUTImpl &)
{
return date32IsNotSupported(name);
throwDate32IsNotSupported(name);
}
using FactorTransform = ZeroTransform;
@ -592,11 +581,11 @@ struct ToStartOfTenMinutesImpl
}
static inline UInt32 execute(Int32, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline UInt32 execute(UInt16, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline DecimalUtils::DecimalComponents<DateTime64> executeExtendedResult(const DecimalUtils::DecimalComponents<DateTime64> & t, const DateLUTImpl & time_zone)
{
@ -604,7 +593,7 @@ struct ToStartOfTenMinutesImpl
}
static inline Int64 executeExtendedResult(Int32, const DateLUTImpl &)
{
return date32IsNotSupported(name);
throwDate32IsNotSupported(name);
}
using FactorTransform = ZeroTransform;
@ -624,11 +613,11 @@ struct ToStartOfFifteenMinutesImpl
}
static inline UInt32 execute(Int32, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline UInt32 execute(UInt16, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline DecimalUtils::DecimalComponents<DateTime64> executeExtendedResult(const DecimalUtils::DecimalComponents<DateTime64> & t, const DateLUTImpl & time_zone)
{
@ -636,7 +625,7 @@ struct ToStartOfFifteenMinutesImpl
}
static inline Int64 executeExtendedResult(Int32, const DateLUTImpl &)
{
return date32IsNotSupported(name);
throwDate32IsNotSupported(name);
}
using FactorTransform = ZeroTransform;
@ -659,12 +648,12 @@ struct TimeSlotImpl
static inline UInt32 execute(Int32, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline UInt32 execute(UInt16, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline DecimalUtils::DecimalComponents<DateTime64> executeExtendedResult(const DecimalUtils::DecimalComponents<DateTime64> & t, const DateLUTImpl &)
@ -676,7 +665,7 @@ struct TimeSlotImpl
static inline Int64 executeExtendedResult(Int32, const DateLUTImpl &)
{
return date32IsNotSupported(name);
throwDate32IsNotSupported(name);
}
using FactorTransform = ZeroTransform;
@ -701,12 +690,12 @@ struct ToStartOfHourImpl
static inline UInt32 execute(Int32, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline UInt32 execute(UInt16, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline DecimalUtils::DecimalComponents<DateTime64> executeExtendedResult(const DecimalUtils::DecimalComponents<DateTime64> & t, const DateLUTImpl & time_zone)
@ -716,7 +705,7 @@ struct ToStartOfHourImpl
static inline Int64 executeExtendedResult(Int32, const DateLUTImpl &)
{
return date32IsNotSupported(name);
throwDate32IsNotSupported(name);
}
using FactorTransform = ZeroTransform;
@ -880,11 +869,11 @@ struct ToHourImpl
}
static inline UInt8 execute(Int32, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline UInt8 execute(UInt16, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
using FactorTransform = ToDateImpl;
@ -906,12 +895,12 @@ struct TimezoneOffsetImpl
static inline time_t execute(Int32, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline time_t execute(UInt16, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
using FactorTransform = ToTimeImpl;
@ -931,11 +920,11 @@ struct ToMinuteImpl
}
static inline UInt8 execute(Int32, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline UInt8 execute(UInt16, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
using FactorTransform = ToStartOfHourImpl;
@ -955,11 +944,11 @@ struct ToSecondImpl
}
static inline UInt8 execute(Int32, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
static inline UInt8 execute(UInt16, const DateLUTImpl &)
{
return dateIsNotSupported(name);
throwDateTimeIsNotSupported(name);
}
using FactorTransform = ToStartOfMinuteImpl;

View File

@ -155,9 +155,9 @@ namespace
template <>
struct Transform<IntervalKind::Hour>
{
static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64) { return dateIsNotSupported(function_name); }
static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64) { throwDateIsNotSupported(function_name); }
static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64) { return dateIsNotSupported(function_name); }
static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64) { throwDateIsNotSupported(function_name); }
static UInt32 execute(UInt32 t, Int64 hours, const DateLUTImpl & time_zone, Int64)
{
@ -173,9 +173,9 @@ namespace
template <>
struct Transform<IntervalKind::Minute>
{
static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64) { return dateIsNotSupported(function_name); }
static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64) { throwDateIsNotSupported(function_name); }
static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64) { return dateIsNotSupported(function_name); }
static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64) { throwDateIsNotSupported(function_name); }
static UInt32 execute(UInt32 t, Int64 minutes, const DateLUTImpl & time_zone, Int64)
{
@ -191,9 +191,9 @@ namespace
template <>
struct Transform<IntervalKind::Second>
{
static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64) { return dateIsNotSupported(function_name); }
static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64) { throwDateIsNotSupported(function_name); }
static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64) { return dateIsNotSupported(function_name); }
static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64) { throwDateIsNotSupported(function_name); }
static UInt32 execute(UInt32 t, Int64 seconds, const DateLUTImpl & time_zone, Int64)
{
@ -209,11 +209,11 @@ namespace
template <>
struct Transform<IntervalKind::Millisecond>
{
static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64) { return dateIsNotSupported(function_name); }
static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64) { throwDateIsNotSupported(function_name); }
static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64) { return dateIsNotSupported(function_name); }
static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64) { throwDateIsNotSupported(function_name); }
static UInt32 execute(UInt32, Int64, const DateLUTImpl &, Int64) { return dateTimeIsNotSupported(function_name); }
static UInt32 execute(UInt32, Int64, const DateLUTImpl &, Int64) { throwDateTimeIsNotSupported(function_name); }
static Int64 execute(Int64 t, Int64 milliseconds, const DateLUTImpl &, Int64 scale_multiplier)
{
@ -246,11 +246,11 @@ namespace
template <>
struct Transform<IntervalKind::Microsecond>
{
static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64) { return dateIsNotSupported(function_name); }
static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64) { throwDateIsNotSupported(function_name); }
static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64) { return dateIsNotSupported(function_name); }
static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64) { throwDateIsNotSupported(function_name); }
static UInt32 execute(UInt32, Int64, const DateLUTImpl &, Int64) { return dateTimeIsNotSupported(function_name); }
static UInt32 execute(UInt32, Int64, const DateLUTImpl &, Int64) { throwDateTimeIsNotSupported(function_name); }
static Int64 execute(Int64 t, Int64 microseconds, const DateLUTImpl &, Int64 scale_multiplier)
{
@ -283,11 +283,11 @@ namespace
template <>
struct Transform<IntervalKind::Nanosecond>
{
static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64) { return dateIsNotSupported(function_name); }
static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64) { throwDateIsNotSupported(function_name); }
static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64) { return dateIsNotSupported(function_name); }
static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64) { throwDateIsNotSupported(function_name); }
static UInt32 execute(UInt32, Int64, const DateLUTImpl &, Int64) { return dateTimeIsNotSupported(function_name); }
static UInt32 execute(UInt32, Int64, const DateLUTImpl &, Int64) { throwDateTimeIsNotSupported(function_name); }
static Int64 execute(Int64 t, Int64 nanoseconds, const DateLUTImpl &, Int64 scale_multiplier)
{