Merge pull request #62901 from KevinyhZou/fix_fromUnixTimestamp_beyond_uint32

Fix fromUnixtimestamp in joda syntax while the input value beyond UInt32
This commit is contained in:
Yarik Briukhovetskyi 2024-04-26 11:31:24 +00:00 committed by GitHub
commit 819b5aab55
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 63 additions and 19 deletions

View File

@ -1169,7 +1169,10 @@ struct ToStartOfHourImpl
struct ToYearImpl struct ToYearImpl
{ {
static constexpr auto name = "toYear"; static constexpr auto name = "toYear";
static UInt16 execute(UInt64 t, const DateLUTImpl & time_zone)
{
return time_zone.toYear(t);
}
static UInt16 execute(Int64 t, const DateLUTImpl & time_zone) static UInt16 execute(Int64 t, const DateLUTImpl & time_zone)
{ {
return time_zone.toYear(t); return time_zone.toYear(t);
@ -1217,7 +1220,10 @@ struct ToWeekYearImpl
static constexpr auto name = "toWeekYear"; static constexpr auto name = "toWeekYear";
static constexpr Int8 week_mode = 3; static constexpr Int8 week_mode = 3;
static UInt16 execute(UInt64 t, const DateLUTImpl & time_zone)
{
return time_zone.toYearWeek(t, week_mode).first;
}
static UInt16 execute(Int64 t, const DateLUTImpl & time_zone) static UInt16 execute(Int64 t, const DateLUTImpl & time_zone)
{ {
return time_zone.toYearWeek(t, week_mode).first; return time_zone.toYearWeek(t, week_mode).first;
@ -1241,7 +1247,10 @@ struct ToWeekYearImpl
struct ToWeekOfWeekYearImpl struct ToWeekOfWeekYearImpl
{ {
static constexpr auto name = "toWeekOfWeekYear"; static constexpr auto name = "toWeekOfWeekYear";
static UInt16 execute(UInt64 t, const DateLUTImpl & time_zone)
{
return time_zone.toISOWeek(t);
}
static UInt16 execute(Int64 t, const DateLUTImpl & time_zone) static UInt16 execute(Int64 t, const DateLUTImpl & time_zone)
{ {
return time_zone.toISOWeek(t); return time_zone.toISOWeek(t);
@ -1265,7 +1274,10 @@ struct ToWeekOfWeekYearImpl
struct ToQuarterImpl struct ToQuarterImpl
{ {
static constexpr auto name = "toQuarter"; static constexpr auto name = "toQuarter";
static UInt8 execute(UInt64 t, const DateLUTImpl & time_zone)
{
return time_zone.toQuarter(t);
}
static UInt8 execute(Int64 t, const DateLUTImpl & time_zone) static UInt8 execute(Int64 t, const DateLUTImpl & time_zone)
{ {
return time_zone.toQuarter(t); return time_zone.toQuarter(t);
@ -1290,7 +1302,10 @@ struct ToQuarterImpl
struct ToMonthImpl struct ToMonthImpl
{ {
static constexpr auto name = "toMonth"; static constexpr auto name = "toMonth";
static UInt8 execute(UInt64 t, const DateLUTImpl & time_zone)
{
return time_zone.toMonth(t);
}
static UInt8 execute(Int64 t, const DateLUTImpl & time_zone) static UInt8 execute(Int64 t, const DateLUTImpl & time_zone)
{ {
return time_zone.toMonth(t); return time_zone.toMonth(t);
@ -1315,7 +1330,10 @@ struct ToMonthImpl
struct ToDayOfMonthImpl struct ToDayOfMonthImpl
{ {
static constexpr auto name = "toDayOfMonth"; static constexpr auto name = "toDayOfMonth";
static UInt8 execute(UInt64 t, const DateLUTImpl & time_zone)
{
return time_zone.toDayOfMonth(t);
}
static UInt8 execute(Int64 t, const DateLUTImpl & time_zone) static UInt8 execute(Int64 t, const DateLUTImpl & time_zone)
{ {
return time_zone.toDayOfMonth(t); return time_zone.toDayOfMonth(t);
@ -1341,7 +1359,10 @@ struct ToDayOfWeekImpl
{ {
static constexpr auto name = "toDayOfWeek"; static constexpr auto name = "toDayOfWeek";
static constexpr bool value_may_be_string = true; static constexpr bool value_may_be_string = true;
static UInt8 execute(UInt64 t, UInt8 mode, const DateLUTImpl & time_zone)
{
return time_zone.toDayOfWeek(t, mode);
}
static UInt8 execute(Int64 t, UInt8 mode, const DateLUTImpl & time_zone) static UInt8 execute(Int64 t, UInt8 mode, const DateLUTImpl & time_zone)
{ {
return time_zone.toDayOfWeek(t, mode); return time_zone.toDayOfWeek(t, mode);
@ -1365,7 +1386,10 @@ struct ToDayOfWeekImpl
struct ToDayOfYearImpl struct ToDayOfYearImpl
{ {
static constexpr auto name = "toDayOfYear"; static constexpr auto name = "toDayOfYear";
static UInt16 execute(UInt64 t, const DateLUTImpl & time_zone)
{
return time_zone.toDayOfYear(t);
}
static UInt16 execute(Int64 t, const DateLUTImpl & time_zone) static UInt16 execute(Int64 t, const DateLUTImpl & time_zone)
{ {
return time_zone.toDayOfYear(t); return time_zone.toDayOfYear(t);
@ -1421,7 +1445,10 @@ public:
struct ToHourImpl struct ToHourImpl
{ {
static constexpr auto name = "toHour"; static constexpr auto name = "toHour";
static UInt8 execute(UInt64 t, const DateLUTImpl & time_zone)
{
return time_zone.toHour(t);
}
static UInt8 execute(Int64 t, const DateLUTImpl & time_zone) static UInt8 execute(Int64 t, const DateLUTImpl & time_zone)
{ {
return time_zone.toHour(t); return time_zone.toHour(t);
@ -1446,7 +1473,10 @@ struct ToHourImpl
struct TimezoneOffsetImpl struct TimezoneOffsetImpl
{ {
static constexpr auto name = "timezoneOffset"; static constexpr auto name = "timezoneOffset";
static time_t execute(UInt64 t, const DateLUTImpl & time_zone)
{
return time_zone.timezoneOffset(t);
}
static time_t execute(Int64 t, const DateLUTImpl & time_zone) static time_t execute(Int64 t, const DateLUTImpl & time_zone)
{ {
return time_zone.timezoneOffset(t); return time_zone.timezoneOffset(t);
@ -1474,7 +1504,10 @@ struct TimezoneOffsetImpl
struct ToMinuteImpl struct ToMinuteImpl
{ {
static constexpr auto name = "toMinute"; static constexpr auto name = "toMinute";
static UInt8 execute(UInt64 t, const DateLUTImpl & time_zone)
{
return time_zone.toMinute(t);
}
static UInt8 execute(Int64 t, const DateLUTImpl & time_zone) static UInt8 execute(Int64 t, const DateLUTImpl & time_zone)
{ {
return time_zone.toMinute(t); return time_zone.toMinute(t);
@ -1499,7 +1532,10 @@ struct ToMinuteImpl
struct ToSecondImpl struct ToSecondImpl
{ {
static constexpr auto name = "toSecond"; static constexpr auto name = "toSecond";
static UInt8 execute(UInt64 t, const DateLUTImpl & time_zone)
{
return time_zone.toSecond(t);
}
static UInt8 execute(Int64 t, const DateLUTImpl & time_zone) static UInt8 execute(Int64 t, const DateLUTImpl & time_zone)
{ {
return time_zone.toSecond(t); return time_zone.toSecond(t);
@ -1550,7 +1586,10 @@ struct ToMillisecondImpl
struct ToISOYearImpl struct ToISOYearImpl
{ {
static constexpr auto name = "toISOYear"; static constexpr auto name = "toISOYear";
static UInt16 execute(UInt64 t, const DateLUTImpl & time_zone)
{
return time_zone.toISOYear(time_zone.toDayNum(t));
}
static UInt16 execute(Int64 t, const DateLUTImpl & time_zone) static UInt16 execute(Int64 t, const DateLUTImpl & time_zone)
{ {
return time_zone.toISOYear(time_zone.toDayNum(t)); return time_zone.toISOYear(time_zone.toDayNum(t));
@ -1607,7 +1646,10 @@ struct ToStartOfISOYearImpl
struct ToISOWeekImpl struct ToISOWeekImpl
{ {
static constexpr auto name = "toISOWeek"; static constexpr auto name = "toISOWeek";
static UInt8 execute(UInt64 t, const DateLUTImpl & time_zone)
{
return time_zone.toISOWeek(time_zone.toDayNum(t));
}
static UInt8 execute(Int64 t, const DateLUTImpl & time_zone) static UInt8 execute(Int64 t, const DateLUTImpl & time_zone)
{ {
return time_zone.toISOWeek(time_zone.toDayNum(t)); return time_zone.toISOWeek(time_zone.toDayNum(t));

View File

@ -62,8 +62,8 @@ template <> struct InstructionValueTypeMap<DataTypeInt16> { using Instructi
template <> struct InstructionValueTypeMap<DataTypeUInt16> { using InstructionValueType = UInt32; }; template <> struct InstructionValueTypeMap<DataTypeUInt16> { using InstructionValueType = UInt32; };
template <> struct InstructionValueTypeMap<DataTypeInt32> { using InstructionValueType = UInt32; }; template <> struct InstructionValueTypeMap<DataTypeInt32> { using InstructionValueType = UInt32; };
template <> struct InstructionValueTypeMap<DataTypeUInt32> { using InstructionValueType = UInt32; }; template <> struct InstructionValueTypeMap<DataTypeUInt32> { using InstructionValueType = UInt32; };
template <> struct InstructionValueTypeMap<DataTypeInt64> { using InstructionValueType = UInt32; }; template <> struct InstructionValueTypeMap<DataTypeInt64> { using InstructionValueType = Int64; };
template <> struct InstructionValueTypeMap<DataTypeUInt64> { using InstructionValueType = UInt32; }; template <> struct InstructionValueTypeMap<DataTypeUInt64> { using InstructionValueType = UInt64; };
template <> struct InstructionValueTypeMap<DataTypeDate> { using InstructionValueType = UInt16; }; template <> struct InstructionValueTypeMap<DataTypeDate> { using InstructionValueType = UInt16; };
template <> struct InstructionValueTypeMap<DataTypeDate32> { using InstructionValueType = Int32; }; template <> struct InstructionValueTypeMap<DataTypeDate32> { using InstructionValueType = Int32; };
template <> struct InstructionValueTypeMap<DataTypeDateTime> { using InstructionValueType = UInt32; }; template <> struct InstructionValueTypeMap<DataTypeDateTime> { using InstructionValueType = UInt32; };
@ -1017,7 +1017,7 @@ public:
else else
{ {
for (auto & instruction : instructions) for (auto & instruction : instructions)
instruction.perform(pos, static_cast<UInt32>(vec[i]), 0, 0, *time_zone); instruction.perform(pos, static_cast<T>(vec[i]), 0, 0, *time_zone);
} }
*pos++ = '\0'; *pos++ = '\0';
@ -1073,7 +1073,7 @@ public:
{ {
/// DateTime/DateTime64 --> insert instruction /// DateTime/DateTime64 --> insert instruction
/// Other types cannot provide the requested data --> write out template /// Other types cannot provide the requested data --> write out template
if constexpr (is_any_of<T, UInt32, Int64>) if constexpr (is_any_of<T, UInt32, Int64, UInt64>)
{ {
Instruction<T> instruction; Instruction<T> instruction;
instruction.setMysqlFunc(std::move(func)); instruction.setMysqlFunc(std::move(func));
@ -1539,7 +1539,7 @@ public:
/// If the argument was DateTime, add instruction for printing. If it was date, just append default literal /// If the argument was DateTime, add instruction for printing. If it was date, just append default literal
auto add_instruction = [&]([[maybe_unused]] typename Instruction<T>::FuncJoda && func, [[maybe_unused]] const String & default_literal) auto add_instruction = [&]([[maybe_unused]] typename Instruction<T>::FuncJoda && func, [[maybe_unused]] const String & default_literal)
{ {
if constexpr (is_any_of<T, UInt32, Int64>) if constexpr (is_any_of<T, UInt32, Int64, UInt64>)
{ {
Instruction<T> instruction; Instruction<T> instruction;
instruction.setJodaFunc(std::move(func)); instruction.setJodaFunc(std::move(func));

View File

@ -0,0 +1 @@
2295-03-20 00:03:16

View File

@ -0,0 +1 @@
select fromUnixTimestampInJodaSyntax(10262736196, 'YYYY-MM-dd HH:mm:ss', 'Asia/Shanghai');