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

MCOL-392 fix negative zero hours

Also fix some functions that were not behaving correctly
This commit is contained in:
Andrew Hutchings
2018-04-30 22:08:10 +01:00
parent 3c090647af
commit dfc351b730
10 changed files with 148 additions and 36 deletions

View File

@ -172,6 +172,8 @@ int64_t Func_bitand::getIntVal(Row& row,
}
hour |= ((time >> 40) & 0xfff);
if ((hour >= 0) && (time >> 63))
hour*= -1;
min = (uint32_t)((time >> 32) & 0xff);
sec = (uint32_t)((time >> 24) & 0xff);
msec = (uint32_t)(time & 0xffffff);

View File

@ -150,6 +150,9 @@ long long timeGet( uint64_t time, IntervalColumn::interval_type unit )
mask = 0xfffffffffffff000;
hour = mask | ((time >> 40) & 0xfff);
if ((hour >= 0) && (time >> 63))
hour*= -1;
// Always positive!
day = abs(hour / 24);

View File

@ -221,7 +221,7 @@ int64_t Func_greatest::getTimeIntVal(rowgroup::Row& row,
int64_t str1 = fp[i]->data()->getTimeIntVal(row, isNull);
int64_t str2 = str1 << 12;
if ( str < str1 )
if ( str < str2 )
{
greatestStr = str1;
str = str2;

View File

@ -128,10 +128,18 @@ int64_t Func_hour::getIntVal(rowgroup::Row& row,
if (isTime)
{
// If negative, mask so it doesn't turn positive
bool isNeg = false;
int64_t mask = 0;
if ((val >> 40) & 0x800)
mask = 0xfffffffffffff000;
if (!mask && (val >> 63))
{
isNeg = true;
}
val = mask | ((val >> 40) & 0xfff);
if (isNeg)
val*= -1;
}
else
{

View File

@ -197,7 +197,7 @@ int64_t Func_least::getTimeIntVal(rowgroup::Row& row,
int64_t str1 = fp[i]->data()->getTimeIntVal(row, isNull);
int64_t str2 = str1 << 12;
if ( str > str1 )
if ( str > str2 )
{
leastStr = str1;
str = str2;

View File

@ -111,6 +111,7 @@ int64_t Func_second::getIntVal(rowgroup::Row& row,
case execplan::CalpontSystemCatalog::TIME:
{
val = parm[0]->data()->getTimeIntVal(row, isNull);
return (uint32_t)((val >> 24) & 0xff);
break;
}

View File

@ -49,12 +49,13 @@ int64_t Func_time_to_sec::getIntVal(rowgroup::Row& row,
CalpontSystemCatalog::ColType& op_ct)
{
// assume 256 is enough. assume not allowing incomplete date
uint32_t hour = 0,
int32_t hour = 0,
min = 0,
sec = 0;
bool bIsNegative = false; // Only set to true if CHAR or VARCHAR with a '-'
int64_t val = 0;
int64_t mask = 0;
dataconvert::Time tval;
switch (parm[0]->data()->resultType().colDataType)
@ -64,9 +65,25 @@ int64_t Func_time_to_sec::getIntVal(rowgroup::Row& row,
case CalpontSystemCatalog::DATETIME:
val = parm[0]->data()->getIntVal(row, isNull);
hour = (uint32_t)((val >> 32) & 0x3f);
min = (uint32_t)((val >> 26) & 0x3f);
sec = (uint32_t)((val >> 20) & 0x3f);
hour = (int32_t)((val >> 32) & 0x3f);
min = (int32_t)((val >> 26) & 0x3f);
sec = (int32_t)((val >> 20) & 0x3f);
break;
case CalpontSystemCatalog::TIME:
val = parm[0]->data()->getTimeIntVal(row, isNull);
// If negative, mask so it doesn't turn positive
if ((val >> 40) & 0x800)
mask = 0xfffffffffffff000;
bIsNegative = val >> 63;
hour = (int32_t)(mask | ((val >> 40) & 0xfff));
if ((hour >= 0) && bIsNegative)
hour*= -1;
else
bIsNegative = false;
min = (int32_t)((val >> 32) & 0xff);
sec = (int32_t)((val >> 24) & 0xff);
break;
case CalpontSystemCatalog::CHAR:
@ -112,9 +129,9 @@ int64_t Func_time_to_sec::getIntVal(rowgroup::Row& row,
}
else
{
hour = (uint32_t)((val >> 32) & 0x3f);
min = (uint32_t)((val >> 26) & 0x3f);
sec = (uint32_t)((val >> 20) & 0x3f);
hour = (int32_t)((val >> 32) & 0x3f);
min = (int32_t)((val >> 26) & 0x3f);
sec = (int32_t)((val >> 20) & 0x3f);
}
break;
@ -131,9 +148,9 @@ int64_t Func_time_to_sec::getIntVal(rowgroup::Row& row,
}
else
{
hour = (uint32_t)((val >> 32) & 0x3f);
min = (uint32_t)((val >> 26) & 0x3f);
sec = (uint32_t)((val >> 20) & 0x3f);
hour = (int32_t)((val >> 32) & 0x3f);
min = (int32_t)((val >> 26) & 0x3f);
sec = (int32_t)((val >> 20) & 0x3f);
}
}