1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-01 06:46:55 +03:00

Fix makedate() and year() functions

* The year() function did not handle float/double input correctly
* Makedate() did not handle year < 100 conversion
* 0 date was converted to NULL for some functions

In addition makedate did
This commit is contained in:
Andrew Hutchings
2016-09-27 16:11:31 +01:00
parent 03ce5a4936
commit 55844a0f0b
3 changed files with 27 additions and 4 deletions

View File

@ -1900,6 +1900,20 @@ int64_t DataConvert::intToDatetime(int64_t data, bool* date)
{
bool isDate = false;
char buf[21] = {0};
DateTime adaytime;
if (data == 0)
{
adaytime.year = 0;
adaytime.month = 0;
adaytime.day = 0;
adaytime.hour = 0;
adaytime.minute = 0;
adaytime.second = 0;
adaytime.msecond = 0;
if (date)
*date = true;
return *(reinterpret_cast<uint64_t*>(&adaytime));
}
snprintf( buf, 15, "%llu", (long long unsigned int)data);
//string date = buf;
string year, month, day, hour, min, sec, msec;
@ -1964,7 +1978,7 @@ int64_t DataConvert::intToDatetime(int64_t data, bool* date)
default:
return -1;
}
DateTime adaytime;
if (year.empty())
{
// MMDD format. assume current year

View File

@ -78,8 +78,15 @@ uint64_t makedate(rowgroup::Row& row,
isNull = true;
return 0;
}
if (year < 1000 || year > 9999) {
if (year < 70)
{
year = 2000 + year;
}
else if (year < 100)
{
year = 1900 + year;
}
else if (year < 1000 || year > 9999) {
isNull = true;
return 0;
}

View File

@ -75,6 +75,8 @@ int64_t Func_year::getIntVal(rowgroup::Row& row,
case CalpontSystemCatalog::SMALLINT:
case CalpontSystemCatalog::TINYINT:
case CalpontSystemCatalog::INT:
case CalpontSystemCatalog::FLOAT:
case CalpontSystemCatalog::DOUBLE:
val = dataconvert::DataConvert::intToDatetime(parm[0]->data()->getIntVal(row, isNull));
if (val == -1)
{