1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

Reformat all code to coding standard

This commit is contained in:
Andrew Hutchings
2017-10-26 17:18:17 +01:00
parent 4985f3456e
commit 01446d1e22
1296 changed files with 403852 additions and 353747 deletions

View File

@ -38,161 +38,184 @@ namespace funcexp
CalpontSystemCatalog::ColType Func_time_format::operationType( FunctionParm& fp, CalpontSystemCatalog::ColType& resultType )
{
CalpontSystemCatalog::ColType ct;
ct.colDataType = CalpontSystemCatalog::VARCHAR;
ct.colWidth = 255;
return ct;
CalpontSystemCatalog::ColType ct;
ct.colDataType = CalpontSystemCatalog::VARCHAR;
ct.colWidth = 255;
return ct;
}
string Func_time_format::getStrVal(rowgroup::Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType&)
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType&)
{
// assume 256 is enough. assume not allowing incomplete date
char buf[256];
int64_t val = 0;
uint32_t hour = 0,
min = 0,
sec = 0,
msec = 0;
// assume 256 is enough. assume not allowing incomplete date
char buf[256];
int64_t val = 0;
uint32_t hour = 0,
min = 0,
sec = 0,
msec = 0;
switch (parm[0]->data()->resultType().colDataType)
{
case CalpontSystemCatalog::DATE:
isNull = true;
return "";
break;
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);
msec = (uint32_t)((val & 0xfffff));
break;
case CalpontSystemCatalog::CHAR:
case CalpontSystemCatalog::VARCHAR:
case CalpontSystemCatalog::TEXT:
val = dataconvert::DataConvert::stringToDatetime(parm[0]->data()->getStrVal(row, isNull));
if (val == -1)
{
isNull = true;
return "";
}
else
{
hour = (uint32_t)((val >> 32) & 0x3f);
min = (uint32_t)((val >> 26) & 0x3f);
sec = (uint32_t)((val >> 20) & 0x3f);
msec = (uint32_t)((val & 0xfffff));
}
break;
case CalpontSystemCatalog::BIGINT:
case CalpontSystemCatalog::MEDINT:
case CalpontSystemCatalog::SMALLINT:
case CalpontSystemCatalog::TINYINT:
case CalpontSystemCatalog::INT:
val = dataconvert::DataConvert::intToDatetime(parm[0]->data()->getIntVal(row, isNull));
if (val == -1)
{
isNull = true;
return "";
}
else
{
hour = (uint32_t)((val >> 32) & 0x3f);
min = (uint32_t)((val >> 26) & 0x3f);
sec = (uint32_t)((val >> 20) & 0x3f);
msec = (uint32_t)((val & 0xfffff));
}
break;
case CalpontSystemCatalog::DECIMAL:
if (parm[0]->data()->resultType().scale == 0)
{
val = dataconvert::DataConvert::intToDatetime(parm[0]->data()->getIntVal(row, isNull));
if (val == -1)
{
isNull = true;
return "";
}
else
{
hour = (uint32_t)((val >> 32) & 0x3f);
min = (uint32_t)((val >> 26) & 0x3f);
sec = (uint32_t)((val >> 20) & 0x3f);
msec = (uint32_t)((val & 0xfffff));
}
}
break;
default:
isNull = true;
return "";
}
const string& format = parm[1]->data()->getStrVal(row, isNull);
switch (parm[0]->data()->resultType().colDataType)
{
case CalpontSystemCatalog::DATE:
isNull = true;
return "";
break;
char* ptr = buf;
for (uint32_t i = 0; i < format.length(); i++)
{
if (format[i] != '%')
*ptr++ = format[i];
else
{
i++;
switch (format[i])
{
case 'f':
sprintf(ptr, "%06d", msec);
ptr += 6;
break;
case 'H':
sprintf(ptr, "%02d", hour);
ptr += 2;
break;
case 'h':
case 'I':
sprintf(ptr, "%02d", (hour%24 + 11)%12+1);
ptr += 2;
break;
case 'i': /* minutes */
sprintf(ptr, "%02d", min);
ptr += 2;
break;
case 'k':
sprintf(ptr, "%d", hour);
ptr += (hour >= 10 ? 2 : 1);
break;
case 'l':
sprintf(ptr, "%d", (hour%24 + 11)%12+1);
ptr += ((hour%24 + 11)%12+1 >= 10 ? 2 : 1);
break;
case 'p':
sprintf(ptr, "%s", (hour % 24 < 12 ? "AM" : "PM"));
ptr += 2;
break;
case 'r':
sprintf(ptr, (hour % 24 < 12 ? "%02d:%02d:%02d AM" : "%02d:%02d:%02d PM"),
(hour + 11) % 12 + 1, min, sec);
ptr += 11;
break;
case 'S':
case 's':
sprintf(ptr, "%02d", sec);
ptr += 2;
break;
case 'T':
sprintf (ptr, "%02d:%02d:%02d", hour, min, sec);
ptr += 8;
break;
default:
isNull = true;
return "";
}
}
}
*ptr = 0;
return string(buf);
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);
msec = (uint32_t)((val & 0xfffff));
break;
case CalpontSystemCatalog::CHAR:
case CalpontSystemCatalog::VARCHAR:
case CalpontSystemCatalog::TEXT:
val = dataconvert::DataConvert::stringToDatetime(parm[0]->data()->getStrVal(row, isNull));
if (val == -1)
{
isNull = true;
return "";
}
else
{
hour = (uint32_t)((val >> 32) & 0x3f);
min = (uint32_t)((val >> 26) & 0x3f);
sec = (uint32_t)((val >> 20) & 0x3f);
msec = (uint32_t)((val & 0xfffff));
}
break;
case CalpontSystemCatalog::BIGINT:
case CalpontSystemCatalog::MEDINT:
case CalpontSystemCatalog::SMALLINT:
case CalpontSystemCatalog::TINYINT:
case CalpontSystemCatalog::INT:
val = dataconvert::DataConvert::intToDatetime(parm[0]->data()->getIntVal(row, isNull));
if (val == -1)
{
isNull = true;
return "";
}
else
{
hour = (uint32_t)((val >> 32) & 0x3f);
min = (uint32_t)((val >> 26) & 0x3f);
sec = (uint32_t)((val >> 20) & 0x3f);
msec = (uint32_t)((val & 0xfffff));
}
break;
case CalpontSystemCatalog::DECIMAL:
if (parm[0]->data()->resultType().scale == 0)
{
val = dataconvert::DataConvert::intToDatetime(parm[0]->data()->getIntVal(row, isNull));
if (val == -1)
{
isNull = true;
return "";
}
else
{
hour = (uint32_t)((val >> 32) & 0x3f);
min = (uint32_t)((val >> 26) & 0x3f);
sec = (uint32_t)((val >> 20) & 0x3f);
msec = (uint32_t)((val & 0xfffff));
}
}
break;
default:
isNull = true;
return "";
}
const string& format = parm[1]->data()->getStrVal(row, isNull);
char* ptr = buf;
for (uint32_t i = 0; i < format.length(); i++)
{
if (format[i] != '%')
*ptr++ = format[i];
else
{
i++;
switch (format[i])
{
case 'f':
sprintf(ptr, "%06d", msec);
ptr += 6;
break;
case 'H':
sprintf(ptr, "%02d", hour);
ptr += 2;
break;
case 'h':
case 'I':
sprintf(ptr, "%02d", (hour % 24 + 11) % 12 + 1);
ptr += 2;
break;
case 'i': /* minutes */
sprintf(ptr, "%02d", min);
ptr += 2;
break;
case 'k':
sprintf(ptr, "%d", hour);
ptr += (hour >= 10 ? 2 : 1);
break;
case 'l':
sprintf(ptr, "%d", (hour % 24 + 11) % 12 + 1);
ptr += ((hour % 24 + 11) % 12 + 1 >= 10 ? 2 : 1);
break;
case 'p':
sprintf(ptr, "%s", (hour % 24 < 12 ? "AM" : "PM"));
ptr += 2;
break;
case 'r':
sprintf(ptr, (hour % 24 < 12 ? "%02d:%02d:%02d AM" : "%02d:%02d:%02d PM"),
(hour + 11) % 12 + 1, min, sec);
ptr += 11;
break;
case 'S':
case 's':
sprintf(ptr, "%02d", sec);
ptr += 2;
break;
case 'T':
sprintf (ptr, "%02d:%02d:%02d", hour, min, sec);
ptr += 8;
break;
default:
isNull = true;
return "";
}
}
}
*ptr = 0;
return string(buf);
}