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_inet_aton.cpp 3923 2013-06-19 21:43:06Z bwilkinson $
*
*
****************************************************************************/
* $Id: func_inet_aton.cpp 3923 2013-06-19 21:43:06Z bwilkinson $
*
*
****************************************************************************/
#include "functor_real.h"
@ -31,68 +31,62 @@
namespace funcexp
{
//------------------------------------------------------------------------------
// Return input argument type.
// See mcs_add in udfsdk.h for explanation of this function.
//------------------------------------------------------------------------------
execplan::CalpontSystemCatalog::ColType Func_inet_aton::operationType(
FunctionParm& fp,
execplan::CalpontSystemCatalog::ColType& resultType)
FunctionParm& fp, execplan::CalpontSystemCatalog::ColType& resultType)
{
return fp[0]->data()->resultType(); // input type
return fp[0]->data()->resultType(); // input type
}
//------------------------------------------------------------------------------
// Return IP address as a long long int value.
// SELECT ... WHERE inet_aton(ipstring) = 11111111 will call getIntVal()
//------------------------------------------------------------------------------
int64_t Func_inet_aton::getIntVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
int64_t Func_inet_aton::getIntVal(rowgroup::Row& row, FunctionParm& fp, bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
// std::cout << "In Func_inet_aton::getIntVal" << std::endl;
// std::cout << "In Func_inet_aton::getIntVal" << std::endl;
int64_t iValue = joblist::NULL_INT64;
int64_t iValue = joblist::NULL_INT64;
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
if (!isNull)
{
int64_t iVal = convertAton(sValue, isNull);
if (!isNull)
{
int64_t iVal = convertAton( sValue, isNull );
iValue = iVal;
}
if (!isNull)
iValue = iVal;
}
return iValue;
return iValue;
}
//------------------------------------------------------------------------------
// Return IP address as a double value.
// SELECT ... WHERE inet_aton(ipstring) = '11111111' will call getDoubleVal()
//------------------------------------------------------------------------------
double Func_inet_aton::getDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
double Func_inet_aton::getDoubleVal(rowgroup::Row& row, FunctionParm& fp, bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
// std::cout << "In Func_inet_aton::getDoubleVal" << std::endl;
// std::cout << "In Func_inet_aton::getDoubleVal" << std::endl;
double dValue = doubleNullVal();
double dValue = doubleNullVal();
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
if (!isNull)
{
int64_t iValue = convertAton(sValue, isNull);
if (!isNull)
{
int64_t iValue = convertAton( sValue, isNull );
dValue = iValue;
}
if (!isNull)
dValue = iValue;
}
return dValue;
return dValue;
}
//------------------------------------------------------------------------------
@ -103,21 +97,19 @@ double Func_inet_aton::getDoubleVal(rowgroup::Row& row,
// a syntactically valid one.
// Don't know if this function will ever be called.
//------------------------------------------------------------------------------
std::string Func_inet_aton::getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
std::string Func_inet_aton::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
// std::cout << "In Func_inet_aton::getStrVal" << std::endl;
// std::cout << "In Func_inet_aton::getStrVal" << std::endl;
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
if (!isNull)
{
convertAton( sValue, isNull ); // ignore return value
}
if (!isNull)
{
convertAton(sValue, isNull); // ignore return value
}
return sValue;
return sValue;
}
//------------------------------------------------------------------------------
@ -125,63 +117,59 @@ std::string Func_inet_aton::getStrVal(rowgroup::Row& row,
// getBoolVal() makes no sense for inet_aton() but we will implement anyway.
// Don't know if this function will ever be called.
//------------------------------------------------------------------------------
bool Func_inet_aton::getBoolVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
bool Func_inet_aton::getBoolVal(rowgroup::Row& row, FunctionParm& fp, bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
bool bValue = false;
bool bValue = false;
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
if (!isNull)
{
int64_t iVal = convertAton( sValue, isNull );
if (!isNull)
{
int64_t iVal = convertAton(sValue, isNull);
if ((!isNull) && (iVal != 0))
bValue = true;
}
if ((!isNull) && (iVal != 0))
bValue = true;
}
return bValue;
return bValue;
}
//------------------------------------------------------------------------------
// Return IP address as a decimal value.
// SELECT ... WHERE inet_aton(ipstring) = 11111111. will call getDecimalVal()
//------------------------------------------------------------------------------
execplan::IDB_Decimal Func_inet_aton::getDecimalVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
execplan::IDB_Decimal Func_inet_aton::getDecimalVal(rowgroup::Row& row, FunctionParm& fp, bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
execplan::CalpontSystemCatalog::ColType colType = fp[0]->data()->resultType();
execplan::CalpontSystemCatalog::ColType colType = fp[0]->data()->resultType();
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
if (!datatypes::Decimal::isWideDecimalTypeByPrecision(colType.precision))
if (!datatypes::Decimal::isWideDecimalTypeByPrecision(colType.precision))
{
if (!isNull)
{
if (!isNull)
{
int64_t iValue = convertAton( sValue, isNull );
int64_t iValue = convertAton(sValue, isNull);
if (!isNull)
return execplan::IDB_Decimal( iValue, colType.scale, colType.precision );
}
return execplan::IDB_Decimal( joblist::NULL_INT64, colType.scale, colType.precision );
if (!isNull)
return execplan::IDB_Decimal(iValue, colType.scale, colType.precision);
}
else
return execplan::IDB_Decimal(joblist::NULL_INT64, colType.scale, colType.precision);
}
else
{
if (!isNull)
{
if (!isNull)
{
int64_t iValue = convertAton( sValue, isNull );
int64_t iValue = convertAton(sValue, isNull);
if (!isNull)
return execplan::IDB_Decimal( 0, colType.scale, colType.precision, (int128_t) iValue );
}
return execplan::IDB_Decimal( 0, colType.scale, colType.precision, datatypes::Decimal128Null );
if (!isNull)
return execplan::IDB_Decimal(0, colType.scale, colType.precision, (int128_t)iValue);
}
return execplan::IDB_Decimal(0, colType.scale, colType.precision, datatypes::Decimal128Null);
}
}
//------------------------------------------------------------------------------
@ -189,24 +177,22 @@ execplan::IDB_Decimal Func_inet_aton::getDecimalVal(rowgroup::Row& row,
// getDateIntVal() makes no sense for inet_aton() but we will implement anyway.
// Don't know if this function will ever be called.
//------------------------------------------------------------------------------
int32_t Func_inet_aton::getDateIntVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
int32_t Func_inet_aton::getDateIntVal(rowgroup::Row& row, FunctionParm& fp, bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
int32_t iValue = joblist::DATENULL;
int32_t iValue = joblist::DATENULL;
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
if (!isNull)
{
int64_t iVal = convertAton(sValue, isNull);
if (!isNull)
{
int64_t iVal = convertAton( sValue, isNull );
iValue = iVal;
}
if (!isNull)
iValue = iVal;
}
return iValue;
return iValue;
}
//------------------------------------------------------------------------------
@ -215,64 +201,58 @@ int32_t Func_inet_aton::getDateIntVal(rowgroup::Row& row,
// anyway.
// Don't know if this function will ever be called.
//------------------------------------------------------------------------------
int64_t Func_inet_aton::getDatetimeIntVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
int64_t Func_inet_aton::getDatetimeIntVal(rowgroup::Row& row, FunctionParm& fp, bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
int64_t iValue = joblist::DATETIMENULL;
int64_t iValue = joblist::DATETIMENULL;
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
if (!isNull)
{
int64_t iVal = convertAton(sValue, isNull);
if (!isNull)
{
int64_t iVal = convertAton( sValue, isNull );
iValue = iVal;
}
if (!isNull)
iValue = iVal;
}
return iValue;
return iValue;
}
int64_t Func_inet_aton::getTimestampIntVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
int64_t Func_inet_aton::getTimestampIntVal(rowgroup::Row& row, FunctionParm& fp, bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
int64_t iValue = joblist::TIMESTAMPNULL;
int64_t iValue = joblist::TIMESTAMPNULL;
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
if (!isNull)
{
int64_t iVal = convertAton(sValue, isNull);
if (!isNull)
{
int64_t iVal = convertAton( sValue, isNull );
iValue = iVal;
}
if (!isNull)
iValue = iVal;
}
return iValue;
return iValue;
}
int64_t Func_inet_aton::getTimeIntVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
int64_t Func_inet_aton::getTimeIntVal(rowgroup::Row& row, FunctionParm& fp, bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
int64_t iValue = joblist::TIMENULL;
int64_t iValue = joblist::TIMENULL;
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
const std::string& sValue = fp[0]->data()->getStrVal(row, isNull);
if (!isNull)
{
int64_t iVal = convertAton(sValue, isNull);
if (!isNull)
{
int64_t iVal = convertAton( sValue, isNull );
iValue = iVal;
}
if (!isNull)
iValue = iVal;
}
return iValue;
return iValue;
}
//------------------------------------------------------------------------------
@ -280,83 +260,79 @@ int64_t Func_inet_aton::getTimeIntVal(rowgroup::Row& row,
// isNull is set to true if the IP address string has invalid content.
// Source code based on MySQL source (Item_func_inet_aton() in item_func.cc).
//------------------------------------------------------------------------------
int64_t Func_inet_aton::convertAton(
const std::string& ipString,
bool& isNull )
int64_t Func_inet_aton::convertAton(const std::string& ipString, bool& isNull)
{
char c = '.';
int dot_count = 0;
unsigned int byte_result = 0;
unsigned long long result = 0;
char c = '.';
int dot_count = 0;
unsigned int byte_result = 0;
unsigned long long result = 0;
const char* p = ipString.c_str();
const char* end = p + ipString.length();
const char* p = ipString.c_str();
const char* end = p + ipString.length();
// Loop through bytes in the IP address string
while (p < end)
// Loop through bytes in the IP address string
while (p < end)
{
c = *p++;
int digit = (int)(c - '0'); // Assume ascii
if (digit >= 0 && digit <= 9)
{
c = *p++;
// Add the next digit from the string to byte_result
if ((byte_result = byte_result * 10 + digit) > 255)
{
// Wrong address
isNull = true;
return 0;
}
}
// Detect end of one portion of the IP address.
// Shift current result over 8 bits, and add next byte (byte_result)
else if (c == '.')
{
dot_count++;
result = (result << 8) + (unsigned long long)byte_result;
byte_result = 0;
}
// Exit loop if/when we encounter end of string for fixed length column,
// that is padded with '\0' at the end.
else if (c == '\0')
{
break;
}
else
{
// Invalid character
isNull = true;
return 0;
}
}
int digit = (int) (c - '0'); // Assume ascii
if (c != '.') // IP number can't end on '.'
{
//
// Handle short-forms addresses according to standard. Examples:
// 127 -> 0.0.0.127
// 127.1 -> 127.0.0.1
// 127.2.1 -> 127.2.0.1
//
switch (dot_count)
{
case 1: result <<= 8; /* Fall through */
if (digit >= 0 && digit <= 9)
{
// Add the next digit from the string to byte_result
if ((byte_result = byte_result * 10 + digit) > 255)
{
// Wrong address
isNull = true;
return 0;
}
}
// Detect end of one portion of the IP address.
// Shift current result over 8 bits, and add next byte (byte_result)
else if (c == '.')
{
dot_count++;
result = (result << 8) + (unsigned long long) byte_result;
byte_result = 0;
}
// Exit loop if/when we encounter end of string for fixed length column,
// that is padded with '\0' at the end.
else if (c == '\0')
{
break;
}
else
{
// Invalid character
isNull = true;
return 0;
}
case 2: result <<= 8; /* Fall through */
}
if (c != '.') // IP number can't end on '.'
{
//
// Handle short-forms addresses according to standard. Examples:
// 127 -> 0.0.0.127
// 127.1 -> 127.0.0.1
// 127.2.1 -> 127.2.0.1
//
switch (dot_count)
{
case 1:
result <<= 8; /* Fall through */
// std::cout << "aton: " <<
// (result << 8) + (unsigned long long) byte_result << std::endl;
case 2:
result <<= 8; /* Fall through */
}
return (result << 8) + (unsigned long long)byte_result;
}
// std::cout << "aton: " <<
// (result << 8) + (unsigned long long) byte_result << std::endl;
return (result << 8) + (unsigned long long) byte_result;
}
// Invalid IP address ended in '.'
isNull = true;
return 0;
// Invalid IP address ended in '.'
isNull = true;
return 0;
}
}
} // namespace funcexp