Set max year to 2299; Code cleanup; Make working 02245_make_datetime64 test

This commit is contained in:
Roman Vasin 2022-07-15 10:33:52 +00:00
parent 266039ea64
commit 1d0818d9cf
6 changed files with 39 additions and 55 deletions

View File

@ -11,13 +11,10 @@
#define DATE_LUT_MIN_YEAR 1900 /// 1900 since majority of financial organizations consider 1900 as an initial year.
// #define DATE_LUT_MAX_YEAR 2258 /// Last supported year (complete)
#define DATE_LUT_MAX_YEAR 2300 /// Last supported year (complete)
#define DATE_LUT_MAX_YEAR 2299 /// Last supported year (complete)
#define DATE_LUT_YEARS (1 + DATE_LUT_MAX_YEAR - DATE_LUT_MIN_YEAR) /// Number of years in lookup table
// #define DATE_LUT_SIZE 0x20000
#define DATE_LUT_SIZE 0x23C1E
#define DATE_LUT_SIZE 0x23AB1
#define DATE_LUT_MAX (0xFFFFFFFFU - 86400)
#define DATE_LUT_MAX_DAY_NUM 0xFFFF
@ -91,68 +88,58 @@ private:
friend inline LUTIndex operator+(const LUTIndex & index, const T v)
{
return normalizeLUTIndex(index.toUnderType() + UInt32(v));
//return LUTIndex{(index.toUnderType() + UInt32(v)) & date_lut_mask};
}
template <typename T>
friend inline LUTIndex operator+(const T v, const LUTIndex & index)
{
return normalizeLUTIndex(v + index.toUnderType());
//return LUTIndex{(v + index.toUnderType()) & date_lut_mask};
}
friend inline LUTIndex operator+(const LUTIndex & index, const LUTIndex & v)
{
return normalizeLUTIndex(static_cast<UInt32>(index.toUnderType() + v.toUnderType()));
//return LUTIndex{(index.toUnderType() + v.toUnderType()) & date_lut_mask};
}
template <typename T>
friend inline LUTIndex operator-(const LUTIndex & index, const T v)
{
return normalizeLUTIndex(static_cast<Int64>(index.toUnderType() - UInt32(v)));
//return LUTIndex{(index.toUnderType() - UInt32(v)) & date_lut_mask};
}
template <typename T>
friend inline LUTIndex operator-(const T v, const LUTIndex & index)
{
return normalizeLUTIndex(static_cast<Int64>(v - index.toUnderType()));
//return LUTIndex{(v - index.toUnderType()) & date_lut_mask};
}
friend inline LUTIndex operator-(const LUTIndex & index, const LUTIndex & v)
{
return normalizeLUTIndex(static_cast<Int64>(index.toUnderType() - v.toUnderType()));
//return LUTIndex{(index.toUnderType() - v.toUnderType()) & date_lut_mask};
}
template <typename T>
friend inline LUTIndex operator*(const LUTIndex & index, const T v)
{
return normalizeLUTIndex(index.toUnderType() * UInt32(v));
// return LUTIndex{(index.toUnderType() * UInt32(v)) /*& date_lut_mask*/};
}
template <typename T>
friend inline LUTIndex operator*(const T v, const LUTIndex & index)
{
return normalizeLUTIndex(v * index.toUnderType());
// return LUTIndex{(v * index.toUnderType()) /*& date_lut_mask*/};
}
template <typename T>
friend inline LUTIndex operator/(const LUTIndex & index, const T v)
{
return normalizeLUTIndex(index.toUnderType() / UInt32(v));
// return LUTIndex{(index.toUnderType() / UInt32(v)) /*& date_lut_mask*/};
}
template <typename T>
friend inline LUTIndex operator/(const T v, const LUTIndex & index)
{
return normalizeLUTIndex(UInt32(v) / index.toUnderType());
// return LUTIndex{(UInt32(v) / index.toUnderType()) /*& date_lut_mask*/};
}
public:
@ -267,13 +254,11 @@ private:
static inline LUTIndex toLUTIndex(DayNum d)
{
return normalizeLUTIndex(d + daynum_offset_epoch);
// return LUTIndex{(d + daynum_offset_epoch) /*& date_lut_mask*/};
}
static inline LUTIndex toLUTIndex(ExtendedDayNum d)
{
return normalizeLUTIndex(static_cast<UInt32>(d + daynum_offset_epoch));
// return LUTIndex{static_cast<UInt32>(d + daynum_offset_epoch) /*& date_lut_mask*/};
}
inline LUTIndex toLUTIndex(Time t) const
@ -1098,7 +1083,7 @@ public:
auto year_lut_index = (year - DATE_LUT_MIN_YEAR) * 12 + month - 1;
UInt32 index = years_months_lut[year_lut_index].toUnderType() + day_of_month - 1;
/// When date is out of range, default value is DATE_LUT_SIZE - 1 (2283-11-11)
/// When date is out of range, default value is DATE_LUT_SIZE - 1 (2299-12-31)
return LUTIndex{std::min(index, static_cast<UInt32>(DATE_LUT_SIZE - 1))};
}

View File

@ -84,7 +84,7 @@ TEST(DateLUTTest, makeDayNumTest)
EXPECT_EQ(-25567, lut.makeDayNum(1900, 1, 1));
EXPECT_EQ(-16436, lut.makeDayNum(1925, 1, 1));
EXPECT_EQ(0, lut.makeDayNum(1970, 1, 1));
EXPECT_EQ(120894, lut.makeDayNum(2399, 12, 31));
EXPECT_EQ(120894, lut.makeDayNum(2300, 12, 31));
EXPECT_EQ(120894, lut.makeDayNum(2500, 12, 25));
}

View File

@ -539,7 +539,7 @@ template <typename Name> struct ConvertImpl<DataTypeFloat64, DataTypeDateTime, N
const time_t LUT_MIN_TIME = -2208988800l; // 1900-01-01 UTC
const time_t LUT_MAX_TIME = 10413792000l; // 2300-12-31 UTC
const time_t LUT_MAX_TIME = 10382256000l; // 2299-12-31 UTC
/** Conversion of numeric to DateTime64
*/

View File

@ -164,9 +164,8 @@ struct MakeDate32Traits
using ReturnDataType = DataTypeDate32;
using ReturnColumnType = ColumnInt32;
static constexpr auto MIN_YEAR = 1900; //1925;
static constexpr auto MAX_YEAR = 2300; //2283;
// static constexpr auto MAX_DATE = YearMonthDayToSingleInt(MAX_YEAR, 11, 11);
static constexpr auto MIN_YEAR = 1900;
static constexpr auto MAX_YEAR = 2299;
static constexpr auto MAX_DATE = YearMonthDayToSingleInt(MAX_YEAR, 12, 31);
};

View File

@ -8,9 +8,9 @@ DateTime64(3)
DateTime64(6)
DateTime64(7, \'CET\')
DateTime64(7, \'UTC\')
1925-01-01 00:00:00.000000000
1925-01-01 00:00:00.000000000
2283-11-11 23:59:59.99999999
1900-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
2299-12-31 23:59:59.99999999
2262-04-11 23:47:16.854775807
2262-04-11 23:47:16.85477581
1991-08-24 21:04:00
@ -23,10 +23,10 @@ DateTime64(7, \'UTC\')
1991-08-24 21:04:00.0001234
1991-08-24 21:04:00.00001234
1991-08-24 21:04:00.000001234
1925-01-01 00:00:00.000000000
1925-01-01 00:00:00.000000000
1925-01-01 00:00:00.000000000
1925-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1984-01-02 01:00:00.000000000
1984-01-01 01:10:00.000000000
1984-01-01 00:01:10.000000000
@ -37,22 +37,22 @@ DateTime64(7, \'UTC\')
1983-03-02 02:03:04.000000005
1984-03-02 02:03:04.000000005
1983-03-03 02:03:04.000000005
1925-01-01 00:00:00.000000000
1925-01-01 00:00:00.000000000
1925-01-01 00:00:00.000000000
1925-01-01 00:00:00.000000000
1925-01-01 00:00:00.000000000
1925-01-01 00:00:00.000000000
1925-01-01 00:00:00.000000000
1925-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1984-01-01 02:03:04.000000000
1925-01-01 00:00:00.000000000
1925-01-01 00:00:00.000000000
1925-01-01 00:00:00.000000000
1925-01-01 00:00:00.000000000
1925-01-01 00:00:00.000000000
1925-01-01 00:00:00.000000000
1925-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1900-01-01 00:00:00.000000000
1984-01-01 00:00:00.000000000
1984-01-01 00:00:00.000000000
1984-01-01 00:00:00.000000000
@ -61,9 +61,9 @@ DateTime64(7, \'UTC\')
1984-01-01 00:00:00.000000000
1984-01-01 00:00:00.000000000
1984-01-01 00:00:00.000000000
2283-11-11 23:59:59.999
1925-01-01 00:00:00.000
1925-01-01 00:00:00.000
1925-01-01 00:00:00.000
1925-01-01 00:00:00.000
1925-01-01 00:00:00.000
2299-12-31 23:59:59.999
1900-01-01 00:00:00.000
1900-01-01 00:00:00.000
1900-01-01 00:00:00.000
1900-01-01 00:00:00.000
1900-01-01 00:00:00.000

View File

@ -10,10 +10,10 @@ select toTypeName(makeDateTime64(1991, 8, 24, 21, 4, 0, 1234, 6));
select toTypeName(makeDateTime64(1991, 8, 24, 21, 4, 0, 1234, 7, 'CET'));
select toTypeName(cast(makeDateTime64(1991, 8, 24, 21, 4, 0, 1234, 7, 'CET') as DateTime64(7, 'UTC')));
select makeDateTime64(1925, 1, 1, 0, 0, 0, 0, 9, 'UTC');
select makeDateTime64(1924, 12, 31, 23, 59, 59, 999999999, 9, 'UTC');
select makeDateTime64(2283, 11, 11, 23, 59, 59, 99999999, 8, 'UTC');
select makeDateTime64(2283, 11, 11, 23, 59, 59, 999999999, 9, 'UTC'); -- { serverError 407 }
select makeDateTime64(1900, 1, 1, 0, 0, 0, 0, 9, 'UTC');
select makeDateTime64(1899, 12, 31, 23, 59, 59, 999999999, 9, 'UTC');
select makeDateTime64(2299, 12, 31, 23, 59, 59, 99999999, 8, 'UTC');
select makeDateTime64(2299, 12, 31, 23, 59, 59, 999999999, 9, 'UTC'); -- { serverError 407 }
select makeDateTime64(2262, 4, 11, 23, 47, 16, 854775807, 9, 'UTC');
select makeDateTime64(2262, 4, 11, 23, 47, 16, 854775808, 9, 'UTC'); -- { serverError 407 }
select makeDateTime64(2262, 4, 11, 23, 47, 16, 85477581, 8, 'UTC');