1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

bug(priproc) make last_day type a bit more accurate

This fixes discrepance with the server, which assigns DATE type to
last_day()'s result.

Now we also assigns DATE result type and, also, use proper
dataconvert::Day data structure to return date.

Tests agree with InnoDB.

Also, this patch includes test for MCOL-5669, to show we fixed it.
This commit is contained in:
Leonid Fedorov
2024-03-18 14:30:54 +00:00
committed by Sergey Zefirov
parent 7b0a04270f
commit a1e64d4cb0
6 changed files with 280 additions and 6 deletions

View File

@ -4388,6 +4388,13 @@ ReturnedColumn* buildFunctionColumn(Item_func* ifp, gp_walk_info& gwi, bool& non
ct.colWidth = 8; ct.colWidth = 8;
fc->resultType(ct); fc->resultType(ct);
} }
if (funcName == "last_day")
{
CalpontSystemCatalog::ColType ct;
ct.colDataType = CalpontSystemCatalog::DATE;
ct.colWidth = 4;
fc->resultType(ct);
}
#if 0 #if 0

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,18 @@
DROP DATABASE IF EXISTS mcol_5670;
CREATE DATABASE mcol_5670;
USE mcol_5670;
create table my_colstore_tab(`yyyymmdd` date DEFAULT NULL) engine=COLUMNSTORE;
insert into my_colstore_tab values(date('2024-03-18'));
insert into my_colstore_tab values(date(date('2024-03-18')-interval 1 year));
select day(s.yyyymmdd) as OK_1, last_day(s.yyyymmdd) as OK_2, day(last_day(s.yyyymmdd)) as OK_3 from my_colstore_tab s;
OK_1 OK_2 OK_3
18 2024-03-31 31
18 2023-03-31 31
create table my_colstore_tab2(`yyyymmdd` datetime DEFAULT NULL) engine=COLUMNSTORE;
insert into my_colstore_tab2 values('2024-03-18 13:40:31');
insert into my_colstore_tab2 values('2024-03-18 13:40:31'-interval 1 year);
select day(s.yyyymmdd) as OK_1, last_day(s.yyyymmdd) as OK_2, day(last_day(s.yyyymmdd)) as OK_3 from my_colstore_tab2 s;
OK_1 OK_2 OK_3
18 2024-03-31 31
18 2023-03-31 31
DROP DATABASE mcol_5670;

View File

@ -0,0 +1,21 @@
--source ../include/have_columnstore.inc
--disable_warnings
DROP DATABASE IF EXISTS mcol_5670;
--enable_warnings
CREATE DATABASE mcol_5670;
USE mcol_5670;
# using lastday with DATE type
create table my_colstore_tab(`yyyymmdd` date DEFAULT NULL) engine=COLUMNSTORE;
insert into my_colstore_tab values(date('2024-03-18'));
insert into my_colstore_tab values(date(date('2024-03-18')-interval 1 year));
select day(s.yyyymmdd) as OK_1, last_day(s.yyyymmdd) as OK_2, day(last_day(s.yyyymmdd)) as OK_3 from my_colstore_tab s;
# using lastday with DATETIME type
create table my_colstore_tab2(`yyyymmdd` datetime DEFAULT NULL) engine=COLUMNSTORE;
insert into my_colstore_tab2 values('2024-03-18 13:40:31');
insert into my_colstore_tab2 values('2024-03-18 13:40:31'-interval 1 year);
select day(s.yyyymmdd) as OK_1, last_day(s.yyyymmdd) as OK_2, day(last_day(s.yyyymmdd)) as OK_3 from my_colstore_tab2 s;
DROP DATABASE mcol_5670;

View File

@ -163,6 +163,12 @@ int64_t Func_last_day::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& i
uint32_t lastday = day; uint32_t lastday = day;
if (month < 1 || month > 12)
{
isNull = true;
return -1;
}
if (isLeapYear(year) && (month == 2)) if (isLeapYear(year) && (month == 2))
{ {
lastday = 29; lastday = 29;
@ -182,16 +188,13 @@ int64_t Func_last_day::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool& i
return -1; return -1;
} }
dataconvert::DateTime aDay; dataconvert::Date aDay;
aDay.year = year; aDay.year = year;
aDay.month = month; aDay.month = month;
aDay.day = lastday; aDay.day = lastday;
aDay.hour = 0; val = *(reinterpret_cast<uint32_t*>(&aDay));
aDay.minute = 0;
aDay.second = 0;
aDay.msecond = 0;
val = *(reinterpret_cast<uint64_t*>(&aDay));
return val; return val;
} }
} // namespace funcexp } // namespace funcexp