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

clang format apply

This commit is contained in:
Leonid Fedorov
2022-01-21 16:43:49 +00:00
parent 6b6411229f
commit 04752ec546
1376 changed files with 393460 additions and 412662 deletions

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/****************************************************************************
* $Id: func_time_format.cpp 2477 2011-04-01 16:07:35Z rdempsey $
*
*
****************************************************************************/
* $Id: func_time_format.cpp 2477 2011-04-01 16:07:35Z rdempsey $
*
*
****************************************************************************/
#include <cstdlib>
#include <string>
@ -35,208 +35,198 @@ using namespace execplan;
namespace funcexp
{
CalpontSystemCatalog::ColType Func_time_format::operationType( FunctionParm& fp, CalpontSystemCatalog::ColType& resultType )
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,
string Func_time_format::getStrVal(rowgroup::Row& row, 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)
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 execplan::CalpontSystemCatalog::TIMESTAMP:
{
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 execplan::CalpontSystemCatalog::TIMESTAMP:
{
dataconvert::TimeStamp timestamp(parm[0]->data()->getIntVal(row, isNull));
int64_t seconds = timestamp.second;
dataconvert::MySQLTime m_time;
dataconvert::gmtSecToMySQLTime(seconds, m_time, timeZone());
hour = m_time.hour;
min = m_time.minute;
sec = m_time.second;
msec = timestamp.msecond;
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:
case CalpontSystemCatalog::UDECIMAL:
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));
}
}
else
{
isNull = true;
return "";
}
break;
default:
isNull = true;
return "";
dataconvert::TimeStamp timestamp(parm[0]->data()->getIntVal(row, isNull));
int64_t seconds = timestamp.second;
dataconvert::MySQLTime m_time;
dataconvert::gmtSecToMySQLTime(seconds, m_time, timeZone());
hour = m_time.hour;
min = m_time.minute;
sec = m_time.second;
msec = timestamp.msecond;
break;
}
const string& format = parm[1]->data()->getStrVal(row, isNull);
case CalpontSystemCatalog::CHAR:
case CalpontSystemCatalog::VARCHAR:
case CalpontSystemCatalog::TEXT:
val = dataconvert::DataConvert::stringToDatetime(parm[0]->data()->getStrVal(row, isNull));
char* ptr = buf;
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));
}
for (uint32_t i = 0; i < format.length(); i++)
{
if (format[i] != '%')
*ptr++ = format[i];
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:
case CalpontSystemCatalog::UDECIMAL:
if (parm[0]->data()->resultType().scale == 0)
{
val = dataconvert::DataConvert::intToDatetime(parm[0]->data()->getIntVal(row, isNull));
if (val == -1)
{
isNull = true;
return "";
}
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 "";
}
hour = (uint32_t)((val >> 32) & 0x3f);
min = (uint32_t)((val >> 26) & 0x3f);
sec = (uint32_t)((val >> 20) & 0x3f);
msec = (uint32_t)((val & 0xfffff));
}
}
}
else
{
isNull = true;
return "";
}
*ptr = 0;
return string(buf);
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);
}
} // namespace funcexp
} // namespace funcexp
// vim:ts=4 sw=4: