From 55844a0f0bfd52afa78012af6801187727dafe12 Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Tue, 27 Sep 2016 16:11:31 +0100 Subject: [PATCH] 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 --- utils/dataconvert/dataconvert.cpp | 16 +++++++++++++++- utils/funcexp/func_makedate.cpp | 11 +++++++++-- utils/funcexp/func_year.cpp | 4 +++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/utils/dataconvert/dataconvert.cpp b/utils/dataconvert/dataconvert.cpp index 473282595..327a21ba3 100644 --- a/utils/dataconvert/dataconvert.cpp +++ b/utils/dataconvert/dataconvert.cpp @@ -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(&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 diff --git a/utils/funcexp/func_makedate.cpp b/utils/funcexp/func_makedate.cpp index 610238357..99b09af91 100644 --- a/utils/funcexp/func_makedate.cpp +++ b/utils/funcexp/func_makedate.cpp @@ -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; } diff --git a/utils/funcexp/func_year.cpp b/utils/funcexp/func_year.cpp index ff8de701d..f5179d576 100644 --- a/utils/funcexp/func_year.cpp +++ b/utils/funcexp/func_year.cpp @@ -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) { @@ -85,7 +87,7 @@ int64_t Func_year::getIntVal(rowgroup::Row& row, { return (unsigned)((val >> 48) & 0xffff); } - break; + break; case CalpontSystemCatalog::DECIMAL: if (parm[0]->data()->resultType().scale == 0) {