1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-08 14:22:09 +03:00

Merge remote-tracking branch 'upstream/develop' into S3-project

This commit is contained in:
Patrick LeBlanc
2019-04-09 10:28:31 -05:00
165 changed files with 5599 additions and 2429 deletions

View File

@@ -800,8 +800,7 @@ checkPackages()
echo "** Run MariaDB ColumnStore Dependent Package Check"
echo ""
declare -a CENTOS_PKG=("expect" "perl" "perl-DBI" "openssl" "zlib" "file" "libaio" "rsync" "snappy" "net-tools" "numactl-libs")
declare -a CENTOS_PKG=("expect" "perl" "perl-DBI" "openssl" "zlib" "file" "libaio" "rsync" "jemalloc" "snappy" "net-tools" "numactl-libs")
declare -a CENTOS_PKG_NOT=("mariadb-libs")
if [ "$OS" == "centos6" ] || [ "$OS" == "centos7" ]; then
@@ -920,8 +919,7 @@ checkPackages()
fi
fi
declare -a SUSE_PKG=("boost-devel" "expect" "perl" "perl-DBI" "openssl" "file" "libaio1" "rsync" "libsnappy1" "net-tools" "libnuma1")
declare -a SUSE_PKG=("boost-devel" "expect" "perl" "perl-DBI" "openssl" "file" "libaio1" "rsync" "jemalloc" "libsnappy1" "net-tools" "libnuma1")
declare -a SUSE_PKG_NOT=("mariadb" , "libmariadb18")
if [ "$OS" == "suse12" ]; then
@@ -1012,7 +1010,7 @@ checkPackages()
fi
fi
declare -a UBUNTU_PKG=("libboost-all-dev" "expect" "libdbi-perl" "perl" "openssl" "file" "libreadline-dev" "rsync" "libsnappy1V5" "net-tools" "libnuma1" )
declare -a UBUNTU_PKG=("libboost-all-dev" "expect" "libdbi-perl" "perl" "openssl" "file" "libreadline-dev" "rsync" "libjemalloc1" "libsnappy1V5" "net-tools" "libnuma1")
declare -a UBUNTU_PKG_NOT=("mariadb-server" "libmariadb18")
if [ "$OS" == "ubuntu16" ] || [ "$OS" == "ubuntu18" ]; then
@@ -1129,8 +1127,7 @@ checkPackages()
fi
fi
declare -a DEBIAN_PKG=("libboost-all-dev" "expect" "libdbi-perl" "perl" "openssl" "file" "libreadline-dev" "rsync" "libsnappy1" "net-tools" "libnuma1")
declare -a DEBIAN_PKG=("libboost-all-dev" "expect" "libdbi-perl" "perl" "openssl" "file" "libreadline-dev" "rsync" "libjemalloc1" "libsnappy1" "net-tools" "libnuma1")
declare -a DEBIAN_PKG_NOT=("libmariadb18" "mariadb-server")
if [ "$OS" == "debian8" ]; then
@@ -1247,8 +1244,7 @@ checkPackages()
fi
fi
declare -a DEBIAN9_PKG=("libboost-all-dev" "expect" "libdbi-perl" "perl" "openssl" "file" "libreadline5" "rsync" "libsnappy1V5" "net-tools" "libaio1" "libnuma1")
declare -a DEBIAN9_PKG=("libboost-all-dev" "expect" "libdbi-perl" "perl" "openssl" "file" "libreadline5" "rsync" "libjemalloc1" "libsnappy1V5" "net-tools" "libaio1")
declare -a DEBIAN9_PKG_NOT=("libmariadb18" "mariadb-server")
if [ "$OS" == "debian9" ]; then

View File

@@ -8,7 +8,8 @@ set(common_LIB_SRCS
poolallocator.cpp
cgroupconfigurator.cpp
MonitorProcMem.cpp
nullvaluemanip.cpp)
nullvaluemanip.cpp
threadnaming.cpp)
add_library(common SHARED ${common_LIB_SRCS})

View File

@@ -203,6 +203,7 @@
<F N="crashtrace.cpp"/>
<F N="fixedallocator.cpp"/>
<F N="MonitorProcMem.cpp"/>
<F N="nullvaluemanip.cpp"/>
<F N="poolallocator.cpp"/>
</Folder>
<Folder
@@ -213,6 +214,7 @@
<F N="fixedallocator.h"/>
<F N="hasher.h"/>
<F N="MonitorProcMem.h"/>
<F N="nullvaluemanip.h"/>
<F N="poolallocator.h"/>
<F N="simpleallocator.h"/>
<F N="stlpoolallocator.h"/>

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -122,9 +123,6 @@ uint64_t getNullValue(CalpontSystemCatalog::ColDataType t, uint32_t colWidth)
case CalpontSystemCatalog::UBIGINT:
return joblist::UBIGINTNULL;
case CalpontSystemCatalog::LONGDOUBLE:
return -1; // no NULL value for long double yet, this is a nan.
case CalpontSystemCatalog::VARBINARY:
default:
ostringstream os;
@@ -233,7 +231,7 @@ int64_t getSignedNullValue(CalpontSystemCatalog::ColDataType t, uint32_t colWidt
return (int64_t)joblist::UBIGINTNULL;
case CalpontSystemCatalog::LONGDOUBLE:
return -1; // no NULL value for long double yet, this is a nan.
return (int64_t)joblist::LONGDOUBLENULL;
case CalpontSystemCatalog::VARBINARY:
default:

View File

@@ -0,0 +1,26 @@
/* Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of
the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
#include <sys/prctl.h>
namespace utils
{
void setThreadName(const char *threadName)
{
prctl(PR_SET_NAME, threadName, 0, 0, 0);
}
} // end of namespace

View File

@@ -0,0 +1,24 @@
/* Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of
the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
#ifndef H_SETTHREADNAME
#define H_SETTHREADNAME
namespace utils
{
void setThreadName(const char *threadName);
} // end of namespace
#endif

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -330,6 +331,19 @@ int64_t number_int_value(const string& data,
break;
case CalpontSystemCatalog::MEDINT:
if (intVal < MIN_MEDINT)
{
intVal = MIN_MEDINT;
pushwarning = true;
}
else if (intVal > MAX_MEDINT)
{
intVal = MAX_MEDINT;
pushwarning = true;
}
break;
case CalpontSystemCatalog::INT:
if (intVal < MIN_INT)
{
@@ -559,6 +573,14 @@ uint64_t number_uint_value(const string& data,
break;
case CalpontSystemCatalog::UMEDINT:
if (uintVal > MAX_UMEDINT)
{
uintVal = MAX_UMEDINT;
pushwarning = true;
}
break;
case CalpontSystemCatalog::UINT:
if (uintVal > MAX_UINT)
{
@@ -871,7 +893,7 @@ bool mysql_str_to_datetime( const string& input, DateTime& output, bool& isDate
bool mysql_str_to_time( const string& input, Time& output, long decimals )
{
int32_t datesepct = 0;
// int32_t datesepct = 0;
uint32_t dtend = 0;
bool isNeg = false;
@@ -2995,6 +3017,7 @@ CalpontSystemCatalog::ColType DataConvert::convertUnionColType(vector<CalpontSys
case CalpontSystemCatalog::DOUBLE:
case CalpontSystemCatalog::UFLOAT:
case CalpontSystemCatalog::UDOUBLE:
case CalpontSystemCatalog::LONGDOUBLE:
default:
break;
}
@@ -3022,6 +3045,7 @@ CalpontSystemCatalog::ColType DataConvert::convertUnionColType(vector<CalpontSys
case CalpontSystemCatalog::UDECIMAL:
case CalpontSystemCatalog::UFLOAT:
case CalpontSystemCatalog::UDOUBLE:
case CalpontSystemCatalog::LONGDOUBLE:
unionedType.colDataType = CalpontSystemCatalog::CHAR;
unionedType.scale = 0;
unionedType.colWidth = 20;
@@ -3070,6 +3094,7 @@ CalpontSystemCatalog::ColType DataConvert::convertUnionColType(vector<CalpontSys
case CalpontSystemCatalog::UFLOAT:
case CalpontSystemCatalog::UDOUBLE:
case CalpontSystemCatalog::TIME:
case CalpontSystemCatalog::LONGDOUBLE:
unionedType.colDataType = CalpontSystemCatalog::CHAR;
unionedType.scale = 0;
unionedType.colWidth = 26;
@@ -3159,6 +3184,64 @@ CalpontSystemCatalog::ColType DataConvert::convertUnionColType(vector<CalpontSys
break;
}
case CalpontSystemCatalog::LONGDOUBLE:
{
switch (unionedType.colDataType)
{
case CalpontSystemCatalog::DATE:
unionedType.colDataType = CalpontSystemCatalog::CHAR;
unionedType.scale = 0;
unionedType.colWidth = 20;
break;
case CalpontSystemCatalog::DATETIME:
unionedType.colDataType = CalpontSystemCatalog::CHAR;
unionedType.scale = 0;
unionedType.colWidth = 26;
break;
case CalpontSystemCatalog::CHAR:
if (unionedType.colWidth < 20)
unionedType.colWidth = 20;
break;
case CalpontSystemCatalog::VARCHAR:
if (unionedType.colWidth < 21)
unionedType.colWidth = 21;
break;
case CalpontSystemCatalog::TINYINT:
case CalpontSystemCatalog::SMALLINT:
case CalpontSystemCatalog::MEDINT:
case CalpontSystemCatalog::INT:
case CalpontSystemCatalog::BIGINT:
case CalpontSystemCatalog::DECIMAL:
case CalpontSystemCatalog::FLOAT:
case CalpontSystemCatalog::DOUBLE:
case CalpontSystemCatalog::UTINYINT:
case CalpontSystemCatalog::USMALLINT:
case CalpontSystemCatalog::UMEDINT:
case CalpontSystemCatalog::UINT:
case CalpontSystemCatalog::UBIGINT:
case CalpontSystemCatalog::UDECIMAL:
case CalpontSystemCatalog::UFLOAT:
case CalpontSystemCatalog::UDOUBLE:
case CalpontSystemCatalog::LONGDOUBLE:
unionedType.colDataType = CalpontSystemCatalog::LONGDOUBLE;
unionedType.scale = (types[i].scale > unionedType.scale) ? types[i].scale : unionedType.scale;
unionedType.colWidth = sizeof(long double);
unionedType.precision = -1;
break;
default:
break;
}
break;
}
case CalpontSystemCatalog::CHAR:
case CalpontSystemCatalog::VARCHAR:
{
@@ -3180,6 +3263,7 @@ CalpontSystemCatalog::ColType DataConvert::convertUnionColType(vector<CalpontSys
case CalpontSystemCatalog::UDECIMAL:
case CalpontSystemCatalog::UFLOAT:
case CalpontSystemCatalog::UDOUBLE:
case CalpontSystemCatalog::LONGDOUBLE:
unionedType.scale = 0;
unionedType.colWidth = (types[i].colWidth > 20) ? types[i].colWidth : 20;
break;

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -78,6 +79,14 @@ double Func_abs::getDoubleVal(Row& row,
return fabs(parm[0]->data()->getDoubleVal(row, isNull));
}
long double Func_abs::getLongDoubleVal(Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType&)
{
return fabsl(parm[0]->data()->getLongDoubleVal(row, isNull));
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -196,6 +197,24 @@ inline bool getBool(rowgroup::Row& row,
numericLE(val, pm[2]->data()->getDoubleVal(row, isNull));
}
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
long double val = pm[0]->data()->getLongDoubleVal(row, isNull);
if (notBetween)
{
if (!numericGE(val, pm[1]->data()->getLongDoubleVal(row, isNull)) && !isNull)
return true;
isNull = false;
return (!numericLE(val, pm[2]->data()->getLongDoubleVal(row, isNull)) && !isNull);
}
return !isNull &&
numericGE(val, pm[1]->data()->getLongDoubleVal(row, isNull)) &&
numericLE(val, pm[2]->data()->getLongDoubleVal(row, isNull));
}
case execplan::CalpontSystemCatalog::DECIMAL:
case execplan::CalpontSystemCatalog::UDECIMAL:
{

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -243,6 +244,27 @@ inline uint64_t simple_case_cmp(Row& row,
break;
}
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
long double ev = parm[n]->data()->getLongDoubleVal(row, isNull);
if (isNull)
break;
for (i = 1; i <= whereCount; i++)
{
if (ev == parm[i]->data()->getLongDoubleVal(row, isNull) && !isNull)
{
foundIt = true;
break;
}
else
isNull = false;
}
break;
}
default:
{
std::ostringstream oss;
@@ -510,6 +532,19 @@ double Func_simple_case::getDoubleVal(Row& row,
return parm[i]->data()->getDoubleVal(row, isNull);
}
long double Func_simple_case::getLongDoubleVal(Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& operationColType)
{
uint64_t i = simple_case_cmp(row, parm, isNull, operationColType);
if (isNull)
return doubleNullVal();
return parm[i]->data()->getLongDoubleVal(row, isNull);
}
int32_t Func_simple_case::getDateIntVal(rowgroup::Row& row,
FunctionParm& parm,
@@ -649,6 +684,19 @@ double Func_searched_case::getDoubleVal(Row& row,
return parm[i]->data()->getDoubleVal(row, isNull);
}
long double Func_searched_case::getLongDoubleVal(Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType&)
{
uint64_t i = searched_case_cmp(row, parm, isNull);
if (isNull)
return longDoubleNullVal();
return parm[i]->data()->getLongDoubleVal(row, isNull);
}
int32_t Func_searched_case::getDateIntVal(rowgroup::Row& row,
FunctionParm& parm,

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -139,6 +140,26 @@ int64_t Func_cast_signed::getIntVal(Row& row,
}
break;
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
long double value = parm[0]->data()->getLongDoubleVal(row, isNull);
if (value > 0)
value += 0.5;
else if (value < 0)
value -= 0.5;
int64_t ret = (int64_t) value;
if (value > (long double) numeric_limits<int64_t>::max())
ret = numeric_limits<int64_t>::max();
else if (value < (long double) (numeric_limits<int64_t>::min() + 2))
ret = numeric_limits<int64_t>::min() + 2; // IDB min for bigint
return ret;
}
break;
case execplan::CalpontSystemCatalog::VARCHAR:
case execplan::CalpontSystemCatalog::CHAR:
case execplan::CalpontSystemCatalog::TEXT:
@@ -266,6 +287,26 @@ uint64_t Func_cast_unsigned::getUintVal(Row& row,
}
break;
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
long double value = parm[0]->data()->getLongDoubleVal(row, isNull);
if (value > 0)
value += 0.5;
else if (value < 0)
value -= 0.5;
uint64_t ret = (uint64_t) value;
if (value > (long double) numeric_limits<uint64_t>::max() - 2)
ret = numeric_limits<int64_t>::max();
else if (value < 0)
ret = 0;
return ret;
}
break;
case execplan::CalpontSystemCatalog::VARCHAR:
case execplan::CalpontSystemCatalog::CHAR:
case execplan::CalpontSystemCatalog::TEXT:
@@ -391,6 +432,12 @@ string Func_cast_char::getStrVal(Row& row,
}
break;
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
return helpers::longDoubleToString(parm[0]->data()->getLongDoubleVal(row, isNull)).substr(0, length);
}
break;
case execplan::CalpontSystemCatalog::FLOAT:
case execplan::CalpontSystemCatalog::UFLOAT:
{
@@ -526,6 +573,17 @@ double Func_cast_date::getDoubleVal(Row& row,
operationColType);
}
long double Func_cast_date::getLongDoubleVal(Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& operationColType)
{
return (long double) Func_cast_date::getDatetimeIntVal(row,
parm,
isNull,
operationColType);
}
int32_t Func_cast_date::getDateIntVal(rowgroup::Row& row,
FunctionParm& parm,
@@ -795,6 +853,17 @@ double Func_cast_datetime::getDoubleVal(Row& row,
operationColType);
}
long double Func_cast_datetime::getLongDoubleVal(Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& operationColType)
{
return (long double) Func_cast_datetime::getDatetimeIntVal(row,
parm,
isNull,
operationColType);
}
int64_t Func_cast_datetime::getDatetimeIntVal(rowgroup::Row& row,
FunctionParm& parm,
bool& isNull,
@@ -1099,6 +1168,26 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row,
}
break;
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
long double value = parm[0]->data()->getLongDoubleVal(row, isNull);
if (value > 0)
decimal.value = (int64_t) (value * helpers::powerOf10_c[decimals] + 0.5);
else if (value < 0)
decimal.value = (int64_t) (value * helpers::powerOf10_c[decimals] - 0.5);
else
decimal.value = 0;
decimal.scale = decimals;
if ( value > max_number_decimal )
decimal.value = max_number_decimal;
else if ( value < -max_number_decimal )
decimal.value = -max_number_decimal;
}
break;
case execplan::CalpontSystemCatalog::DECIMAL:
case execplan::CalpontSystemCatalog::UDECIMAL:
{
@@ -1426,6 +1515,12 @@ double Func_cast_double::getDoubleVal(Row& row,
}
break;
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
dblval = static_cast<double>(parm[0]->data()->getLongDoubleVal(row, isNull));
}
break;
case execplan::CalpontSystemCatalog::DECIMAL:
case execplan::CalpontSystemCatalog::UDECIMAL:
{

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -123,6 +124,12 @@ int64_t Func_ceil::getIntVal(Row& row,
}
break;
case CalpontSystemCatalog::LONGDOUBLE:
{
ret = (int64_t) ceill(parm[0]->data()->getLongDoubleVal(row, isNull));
}
break;
case CalpontSystemCatalog::VARCHAR:
case CalpontSystemCatalog::CHAR:
case CalpontSystemCatalog::TEXT:
@@ -213,6 +220,12 @@ uint64_t Func_ceil::getUintVal(Row& row,
}
break;
case CalpontSystemCatalog::LONGDOUBLE:
{
ret = (uint64_t) ceill(parm[0]->data()->getLongDoubleVal(row, isNull));
}
break;
case CalpontSystemCatalog::VARCHAR:
case CalpontSystemCatalog::CHAR:
case CalpontSystemCatalog::TEXT:
@@ -287,6 +300,52 @@ double Func_ceil::getDoubleVal(Row& row,
if (!isNull)
ret = ceil(strtod(str.c_str(), 0));
}
else if (op_ct.colDataType == CalpontSystemCatalog::LONGDOUBLE)
{
ret = (double)ceill(parm[0]->data()->getLongDoubleVal(row, isNull));
}
else
{
if (isUnsigned(op_ct.colDataType))
{
ret = (double) getUintVal(row, parm, isNull, op_ct);
}
else
{
ret = (double) getIntVal(row, parm, isNull, op_ct);
}
}
return ret;
}
long double Func_ceil::getLongDoubleVal(Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& op_ct)
{
long double ret = 0.0;
if (op_ct.colDataType == CalpontSystemCatalog::LONGDOUBLE)
{
ret = ceill(parm[0]->data()->getLongDoubleVal(row, isNull));
}
else if (op_ct.colDataType == CalpontSystemCatalog::DOUBLE ||
op_ct.colDataType == CalpontSystemCatalog::UDOUBLE ||
op_ct.colDataType == CalpontSystemCatalog::FLOAT ||
op_ct.colDataType == CalpontSystemCatalog::UFLOAT)
{
ret = ceil(parm[0]->data()->getDoubleVal(row, isNull));
}
else if (op_ct.colDataType == CalpontSystemCatalog::VARCHAR ||
op_ct.colDataType == CalpontSystemCatalog::CHAR ||
op_ct.colDataType == CalpontSystemCatalog::TEXT)
{
const string& str = parm[0]->data()->getStrVal(row, isNull);
if (!isNull)
ret = ceil(strtod(str.c_str(), 0));
}
else
{
if (isUnsigned(op_ct.colDataType))
@@ -328,6 +387,18 @@ string Func_ceil::getStrVal(Row& row,
*d = '\0';
}
else if (op_ct.colDataType == CalpontSystemCatalog::LONGDOUBLE)
{
snprintf(tmp, 511, "%Lf", getLongDoubleVal(row, parm, isNull, op_ct));
// remove the decimals in the oss string.
char* d = tmp;
while ((*d != '.') && (*d != '\0'))
d++;
*d = '\0';
}
else if (isUnsigned(op_ct.colDataType))
{
#ifndef __LP64__

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -188,6 +189,31 @@ double Func_coalesce::getDoubleVal(rowgroup::Row& row,
}
long double Func_coalesce::getLongDoubleVal(rowgroup::Row& row,
FunctionParm& parm,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& ct)
{
long double d = 0.0;
for (uint32_t i = 0; i < parm.size(); i++)
{
d = parm[i]->data()->getLongDoubleVal(row, isNull);
if (isNull)
{
isNull = false;
continue;
}
return d;
}
isNull = true;
return d;
}
execplan::IDB_Decimal Func_coalesce::getDecimalVal(rowgroup::Row& row,
FunctionParm& parm,
bool& isNull,

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -81,6 +82,38 @@ double Func_exp::getDoubleVal(Row& row,
return ret;
}
long double Func_exp::getLongDoubleVal(Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType&)
{
// null value is indicated by isNull
long double x = parm[0]->data()->getLongDoubleVal(row, isNull);
long double ret = 0.0;
if (!isNull)
{
errno = 0;
ret = expl(x);
if (errno == ERANGE) // display NULL for out range value
{
if (x > 0)
{
isNull = true;
Message::Args args;
args.add("exp");
args.add((double)x);
unsigned errcode = ERR_FUNC_OUT_OF_RANGE_RESULT;
throw IDBExcept(IDBErrorInfo::instance()->errorMsg(errcode, args), errcode);
}
else
ret = 0.0;
}
}
return ret;
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -118,6 +119,12 @@ int64_t Func_floor::getIntVal(Row& row,
}
break;
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
ret = (int64_t) floorl(parm[0]->data()->getLongDoubleVal(row, isNull));
}
break;
case execplan::CalpontSystemCatalog::VARCHAR:
case execplan::CalpontSystemCatalog::CHAR:
case execplan::CalpontSystemCatalog::TEXT:
@@ -216,6 +223,12 @@ uint64_t Func_floor::getUintVal(Row& row,
}
break;
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
ret = (uint64_t) floorl(parm[0]->data()->getLongDoubleVal(row, isNull));
}
break;
case execplan::CalpontSystemCatalog::VARCHAR:
case execplan::CalpontSystemCatalog::CHAR:
case execplan::CalpontSystemCatalog::TEXT:
@@ -286,6 +299,10 @@ double Func_floor::getDoubleVal(Row& row,
{
ret = floor(parm[0]->data()->getDoubleVal(row, isNull));
}
else if (op_ct.colDataType == CalpontSystemCatalog::LONGDOUBLE)
{
ret = floorl(parm[0]->data()->getLongDoubleVal(row, isNull));
}
else if (op_ct.colDataType == CalpontSystemCatalog::VARCHAR ||
op_ct.colDataType == CalpontSystemCatalog::CHAR ||
op_ct.colDataType == CalpontSystemCatalog::TEXT)
@@ -303,6 +320,38 @@ double Func_floor::getDoubleVal(Row& row,
return ret;
}
long double Func_floor::getLongDoubleVal(Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& op_ct)
{
long double ret = 0.0;
if (op_ct.colDataType == CalpontSystemCatalog::LONGDOUBLE ||
op_ct.colDataType == CalpontSystemCatalog::FLOAT)
{
ret = floor(parm[0]->data()->getDoubleVal(row, isNull));
}
else if (op_ct.colDataType == CalpontSystemCatalog::LONGDOUBLE)
{
ret = floorl(parm[0]->data()->getLongDoubleVal(row, isNull));
}
else if (op_ct.colDataType == CalpontSystemCatalog::VARCHAR ||
op_ct.colDataType == CalpontSystemCatalog::CHAR ||
op_ct.colDataType == CalpontSystemCatalog::TEXT)
{
const string& str = parm[0]->data()->getStrVal(row, isNull);
if (!isNull)
ret = floor(strtod(str.c_str(), 0));
}
else
{
ret = (long double) getIntVal(row, parm, isNull, op_ct);
}
return ret;
}
string Func_floor::getStrVal(Row& row,
FunctionParm& parm,
@@ -329,6 +378,18 @@ string Func_floor::getStrVal(Row& row,
*d = '\0';
}
if (op_ct.colDataType == CalpontSystemCatalog::LONGDOUBLE)
{
snprintf(tmp, 511, "%Lf", getLongDoubleVal(row, parm, isNull, op_ct));
// remove the decimals in the oss string.
char* d = tmp;
while ((*d != '.') && (*d != '\0'))
d++;
*d = '\0';
}
else if (isUnsigned(op_ct.colDataType))
{
#ifndef __LP64__

View File

@@ -1,5 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2016 MariaDB Corporaton
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -209,6 +209,14 @@ double Func_from_unixtime::getDoubleVal(rowgroup::Row& row,
return (double) atoi(getStrVal(row, parm, isNull, ct).c_str());
}
long double Func_from_unixtime::getLongDoubleVal(rowgroup::Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& ct)
{
return (long double) getDoubleVal(row, parm, isNull, ct);
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -121,6 +122,26 @@ double Func_greatest::getDoubleVal(rowgroup::Row& row,
return (double) greatestStr;
}
long double Func_greatest::getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
long double str = fp[0]->data()->getLongDoubleVal(row, isNull);
long double greatestStr = str;
for (uint32_t i = 1; i < fp.size(); i++)
{
long double str1 = fp[i]->data()->getLongDoubleVal(row, isNull);
if ( greatestStr < str1 )
greatestStr = str1;
}
return greatestStr;
}
std::string Func_greatest::getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -103,6 +104,21 @@ string Func_hex::getStrVal(rowgroup::Row& row,
break;
}
case CalpontSystemCatalog::LONGDOUBLE:
{
char buf[256];
long double val = parm[0]->data()->getLongDoubleVal(row, isNull);
#ifdef _MSC_VER
sprintf(buf, "%llA", val);
#else
sprintf(buf, "%LA", val);
#endif
retval = buf;
break;
}
case CalpontSystemCatalog::VARBINARY:
case CalpontSystemCatalog::BLOB:
{

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -61,6 +62,9 @@ bool boolVal(SPTP& parm, Row& row)
case CalpontSystemCatalog::UDOUBLE:
ret = (parm->data()->getDoubleVal(row, isNull) != 0);
case CalpontSystemCatalog::LONGDOUBLE:
ret = (parm->data()->getLongDoubleVal(row, isNull) != 0);
case CalpontSystemCatalog::DECIMAL:
case CalpontSystemCatalog::UDECIMAL:
ret = (parm->data()->getDecimalVal(row, isNull).value != 0);
@@ -188,6 +192,21 @@ double Func_if::getDoubleVal(Row& row,
}
}
long double Func_if::getLongDoubleVal(Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType&)
{
if (boolVal(parm[0], row))
{
return parm[1]->data()->getLongDoubleVal(row, isNull);
}
else
{
return parm[2]->data()->getLongDoubleVal(row, isNull);
}
}
int32_t Func_if::getDateIntVal(Row& row,
FunctionParm& parm,

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -129,6 +130,25 @@ double Func_ifnull::getDoubleVal(Row& row,
return r;
}
long double Func_ifnull::getLongDoubleVal(Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType&)
{
if (isNull)
return 0.0;
long double r = parm[0]->data()->getLongDoubleVal(row, isNull);
if (isNull)
{
isNull = false;
return parm[1]->data()->getLongDoubleVal(row, isNull);
}
return r;
}
int32_t Func_ifnull::getDateIntVal(Row& row,
FunctionParm& parm,

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -203,6 +204,27 @@ inline bool getBoolForIn(rowgroup::Row& row,
return false;
}
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
long double val = pm[0]->data()->getLongDoubleVal(row, isNull);
if (isNull)
return false;
for (uint32_t i = 1; i < pm.size(); i++)
{
isNull = false;
if ( val == pm[i]->data()->getLongDoubleVal(row, isNull) && !isNull )
return true;
if (isNull && isNotIn)
return true; // will be reversed to false by the caller
}
return false;
}
case execplan::CalpontSystemCatalog::DECIMAL:
case execplan::CalpontSystemCatalog::UDECIMAL:
{

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -74,6 +75,10 @@ bool Func_isnull::getBoolVal(Row& row,
parm[0]->data()->getStrVal(row, isNull);
break;
case CalpontSystemCatalog::LONGDOUBLE:
parm[0]->data()->getLongDoubleVal(row, isNull);
break;
default:
parm[0]->data()->getIntVal(row, isNull);
}

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -100,6 +101,26 @@ double Func_least::getDoubleVal(rowgroup::Row& row,
return (double) leastStr;
}
long double Func_least::getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
long double str = fp[0]->data()->getLongDoubleVal(row, isNull);
long double leastStr = str;
for (uint32_t i = 1; i < fp.size(); i++)
{
long double str1 = fp[i]->data()->getLongDoubleVal(row, isNull);
if ( leastStr > str1 )
leastStr = str1;
}
return leastStr;
}
std::string Func_least::getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,

View File

@@ -20,7 +20,7 @@
*
*
****************************************************************************/
#include "errorids.h"
#include <string>
using namespace std;
@@ -39,6 +39,9 @@ using namespace joblist;
namespace funcexp
{
const string Func_lpad::fPad = " ";
CalpontSystemCatalog::ColType Func_lpad::operationType(FunctionParm& fp, CalpontSystemCatalog::ColType& resultType)
{
// operation type is not used by this functor
@@ -114,17 +117,33 @@ std::string Func_lpad::getStrVal(rowgroup::Row& row,
}
break;
case execplan::CalpontSystemCatalog::CHAR:
case execplan::CalpontSystemCatalog::VARCHAR:
{
const string& strval = fp[1]->data()->getStrVal(row, isNull);
len = strtol(strval.c_str(), NULL, 10);
break;
}
default:
{
len = fp[1]->data()->getIntVal(row, isNull);
std::ostringstream oss;
oss << "lpad parameter 2 must be numeric, not " << execplan::colDataTypeToString(fp[1]->data()->resultType().colDataType);
throw logging::IDBExcept(oss.str(), logging::ERR_DATATYPE_NOT_SUPPORT);
}
}
if (len < 1)
return "";
// MCOL-2182 As of MariaDB 10.3 the third parameter - pad characters - is optional
// The pad characters.
const string& pad = fp[2]->data()->getStrVal(row, isNull);
const string* pad = &fPad;
if (fp.size() > 2)
{
pad = &fp[2]->data()->getStrVal(row, isNull);
}
if (isNull)
return "";
@@ -172,11 +191,11 @@ std::string Func_lpad::getStrVal(rowgroup::Row& row,
// This is the case where there's room to pad.
// Convert the pad string to wide
padwclen = pad.length(); // A guess to start.
padwclen = pad->length(); // A guess to start.
size_t padbufsize = (padwclen + 1) * sizeof(wchar_t);
wchar_t* wcpad = (wchar_t*)alloca(padbufsize);
// padwclen+1 is for giving count for the terminating null
size_t padlen = utf8::idb_mbstowcs(wcpad, pad.c_str(), padwclen + 1);
size_t padlen = utf8::idb_mbstowcs(wcpad, pad->c_str(), padwclen + 1);
// How many chars do we need?
size_t padspace = len - strSize;

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -1523,6 +1524,26 @@ string Func_format::getStrVal(Row& row,
}
break;
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
long double rawValue = parm[0]->data()->getLongDoubleVal(row, isNull);
// roundup
if (scale < 0) scale = 0;
if (rawValue >= 0)
rawValue += 0.5 / pow(10.0, scale);
else
rawValue -= 0.5 / pow(10.0, scale);
// double's can be *really* long to print out. Max mysql
// is e308 so allow for 308 + 36 decimal places minimum.
char buf[384];
snprintf(buf, 384, "%0.36Lf", rawValue);
value = buf;
}
break;
default:
{
std::ostringstream oss;

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -142,6 +143,14 @@ double Func_mod::getDoubleVal(Row& row,
}
break;
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
long double value = parm[0]->data()->getLongDoubleVal(row, isNull);
mod = (double)fmodl(value, div);
}
break;
case execplan::CalpontSystemCatalog::FLOAT:
case execplan::CalpontSystemCatalog::UFLOAT:
{
@@ -181,6 +190,110 @@ double Func_mod::getDoubleVal(Row& row,
return mod;
}
long double Func_mod::getLongDoubleVal(Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& operationColType)
{
if ( parm.size() < 2 )
{
isNull = true;
return 0;
}
int64_t div = parm[1]->data()->getIntVal(row, isNull);
if ( div == 0 )
{
isNull = true;
return 0;
}
long double mod = 0;
switch (parm[0]->data()->resultType().colDataType)
{
case execplan::CalpontSystemCatalog::BIGINT:
case execplan::CalpontSystemCatalog::INT:
case execplan::CalpontSystemCatalog::MEDINT:
case execplan::CalpontSystemCatalog::TINYINT:
case execplan::CalpontSystemCatalog::SMALLINT:
{
int64_t value = parm[0]->data()->getIntVal(row, isNull);
mod = value % div;
}
break;
case execplan::CalpontSystemCatalog::UBIGINT:
case execplan::CalpontSystemCatalog::UINT:
case execplan::CalpontSystemCatalog::UMEDINT:
case execplan::CalpontSystemCatalog::UTINYINT:
case execplan::CalpontSystemCatalog::USMALLINT:
{
uint64_t udiv = parm[1]->data()->getIntVal(row, isNull);
uint64_t uvalue = parm[0]->data()->getUintVal(row, isNull);
mod = uvalue % udiv;
}
break;
case execplan::CalpontSystemCatalog::DOUBLE:
case execplan::CalpontSystemCatalog::UDOUBLE:
{
double value = parm[0]->data()->getDoubleVal(row, isNull);
mod = fmod(value, div);
}
break;
case execplan::CalpontSystemCatalog::FLOAT:
case execplan::CalpontSystemCatalog::UFLOAT:
{
float value = parm[0]->data()->getFloatVal(row, isNull);
mod = fmod(value, div);
}
break;
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
long double value = parm[0]->data()->getLongDoubleVal(row, isNull);
mod = fmodl(value, div);
}
break;
case execplan::CalpontSystemCatalog::DECIMAL:
case execplan::CalpontSystemCatalog::UDECIMAL:
{
IDB_Decimal d = parm[0]->data()->getDecimalVal(row, isNull);
int64_t value = d.value / helpers::power(d.scale);
mod = value % div;
}
break;
case execplan::CalpontSystemCatalog::CHAR:
case execplan::CalpontSystemCatalog::VARCHAR:
case execplan::CalpontSystemCatalog::TEXT:
{
double value = parm[0]->data()->getDoubleVal(row, isNull);
mod = fmod(value, div);
break;
}
default:
{
std::ostringstream oss;
oss << "mod: datatype of " << execplan::colDataTypeToString(parm[0]->data()->resultType().colDataType);
throw logging::IDBExcept(oss.str(), ERR_DATATYPE_NOT_SUPPORT);
}
}
return mod;
}
int64_t Func_mod::getIntVal(Row& row,
FunctionParm& parm,
bool& isNull,
@@ -250,6 +363,14 @@ int64_t Func_mod::getIntVal(Row& row,
}
break;
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
long double value = parm[0]->data()->getLongDoubleVal(row, isNull);
mod = fmodl(value, div);
}
break;
case execplan::CalpontSystemCatalog::DECIMAL:
case execplan::CalpontSystemCatalog::UDECIMAL:
{
@@ -340,6 +461,14 @@ uint64_t Func_mod::getUIntVal(Row& row,
}
break;
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
long double value = parm[0]->data()->getLongDoubleVal(row, isNull);
mod = fmodl(value, div);
}
break;
case execplan::CalpontSystemCatalog::DECIMAL:
case execplan::CalpontSystemCatalog::UDECIMAL:
{
@@ -387,6 +516,10 @@ std::string Func_mod::getStrVal(Row& row,
return intToString(getIntVal(row, fp, isNull, op_ct));
break;
case execplan::CalpontSystemCatalog::LONGDOUBLE:
return longDoubleToString(getLongDoubleVal(row, fp, isNull, op_ct));
break;
default:
return doubleToString(getDoubleVal(row, fp, isNull, op_ct));
break;

View File

@@ -1,5 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2016 MariaDB Corporaton
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -579,6 +579,109 @@ double Func_nullif::getDoubleVal(rowgroup::Row& row,
break;
}
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
exp2 = (double)parm[1]->data()->getLongDoubleVal(row, isNull);
if (isNull)
{
isNull = false;
return exp1;
}
break;
}
case execplan::CalpontSystemCatalog::DATE:
{
exp2 = parm[1]->data()->getDateIntVal(row, isNull);
if (isNull)
{
isNull = false;
return exp1;
}
break;
}
break;
case execplan::CalpontSystemCatalog::TIME:
case execplan::CalpontSystemCatalog::DATETIME:
{
exp2 = parm[1]->data()->getDatetimeIntVal(row, isNull);
if (isNull)
{
isNull = false;
return exp1;
}
break;
}
default:
{
isNull = true;
}
}
if ( exp1 == exp2 )
{
isNull = true;
return 0;
}
return exp1;
}
long double Func_nullif::getLongDoubleVal(rowgroup::Row& row,
FunctionParm& parm,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
long double exp1 = parm[0]->data()->getLongDoubleVal(row, isNull);
long double exp2 = 0;
switch (parm[1]->data()->resultType().colDataType)
{
case execplan::CalpontSystemCatalog::BIGINT:
case execplan::CalpontSystemCatalog::INT:
case execplan::CalpontSystemCatalog::MEDINT:
case execplan::CalpontSystemCatalog::TINYINT:
case execplan::CalpontSystemCatalog::SMALLINT:
case execplan::CalpontSystemCatalog::DOUBLE:
case execplan::CalpontSystemCatalog::FLOAT:
case execplan::CalpontSystemCatalog::DECIMAL:
case execplan::CalpontSystemCatalog::VARCHAR:
case execplan::CalpontSystemCatalog::CHAR:
case execplan::CalpontSystemCatalog::TEXT:
{
exp2 = parm[1]->data()->getDoubleVal(row, isNull);
if (isNull)
{
isNull = false;
return exp1;
}
break;
}
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
exp2 = parm[1]->data()->getLongDoubleVal(row, isNull);
if (isNull)
{
isNull = false;
return exp1;
}
break;
}
case execplan::CalpontSystemCatalog::DATE:
{
exp2 = parm[1]->data()->getDateIntVal(row, isNull);

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -89,6 +90,44 @@ double Func_pow::getDoubleVal(Row& row,
return 0.0;
}
long double Func_pow::getLongDoubleVal(Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType&)
{
// null value is indicated by isNull
long double base = parm[0]->data()->getLongDoubleVal(row, isNull);
if (!isNull)
{
// Should this be long double? Not sure on usage.
double exponent = parm[1]->data()->getDoubleVal(row, isNull);
if (!isNull)
{
errno = 0;
long double x = powl(base, (long double)exponent);
// @bug3490, 4461, rule out domain error, pole error and overflow range error.
if (!isfinite(x))
{
isNull = true;
Message::Args args;
args.add("pow");
args.add((double)base);
args.add(exponent);
unsigned errcode = ERR_FUNC_OUT_OF_RANGE_RESULT;
throw IDBExcept(IDBErrorInfo::instance()->errorMsg(errcode, args), errcode);
}
return x;
}
}
return 0.0;
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -45,7 +46,9 @@ namespace
using namespace funcexp;
inline void decimalPlaceDouble(FunctionParm& fp, int64_t& s, double& p, Row& row, bool& isNull)
// P should either be double or long double
template <typename P>
inline void decimalPlaceDouble(FunctionParm& fp, int64_t& s, P& p, Row& row, bool& isNull)
{
s = fp[1]->data()->getIntVal(row, isNull);
int64_t d = s;
@@ -60,9 +63,9 @@ inline void decimalPlaceDouble(FunctionParm& fp, int64_t& s, double& p, Row& row
r *= 10;
if (d >= 0)
p = (double) r;
p = (P) r;
else
p = 1.0 / ((double) r);
p = 1.0 / ((P) r);
}
}
@@ -200,6 +203,67 @@ double Func_round::getDoubleVal(Row& row,
return d;
}
long double Func_round::getLongDoubleVal(Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& op_ct)
{
if (execplan::CalpontSystemCatalog::LONGDOUBLE == op_ct.colDataType)
{
int64_t d = 0;
long double p = 1;
if (parm.size() > 1) // round(X, D)
decimalPlaceDouble(parm, d, p, row, isNull);
if (isNull)
return 0.0;
long double x = parm[0]->data()->getLongDoubleVal(row, isNull);
if (!isNull)
{
x *= p;
if (x >= 0)
x = floor(x + 0.5);
else
x = ceil(x - 0.5);
if (p != 0.0)
x /= p;
else
x = 0.0;
}
return x;
}
if (isUnsigned(op_ct.colDataType))
{
return getUintVal(row, parm, isNull, op_ct);
}
IDB_Decimal x = getDecimalVal(row, parm, isNull, op_ct);
if (isNull)
return 0.0;
double d = x.value;
if (x.scale > 0)
{
while (x.scale-- > 0)
d /= 10.0;
}
else
{
while (x.scale++ < 0)
d *= 10.0;
}
return d;
}
IDB_Decimal Func_round::getDecimalVal(Row& row,
FunctionParm& parm,
@@ -330,6 +394,34 @@ IDB_Decimal Func_round::getDecimalVal(Row& row,
}
break;
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
int64_t s = 0;
long double p = 1;
if (parm.size() > 1) // round(X, D)
decimalPlaceDouble(parm, s, p, row, isNull);
if (isNull)
break;
long double x = parm[0]->data()->getDoubleVal(row, isNull);
if (!isNull)
{
x *= p;
if (x >= 0)
x = floor(x + 0.5);
else
x = ceil(x - 0.5);
decimal.value = (int64_t) x;
decimal.scale = s;
}
}
break;
case execplan::CalpontSystemCatalog::DATE:
{
int32_t s = 0;

View File

@@ -20,7 +20,7 @@
*
*
****************************************************************************/
#include "errorids.h"
#include <string>
using namespace std;
@@ -39,6 +39,8 @@ using namespace joblist;
namespace funcexp
{
const string Func_rpad::fPad = " ";
CalpontSystemCatalog::ColType Func_rpad::operationType(FunctionParm& fp, CalpontSystemCatalog::ColType& resultType)
{
// operation type is not used by this functor
@@ -114,9 +116,19 @@ std::string Func_rpad::getStrVal(rowgroup::Row& row,
}
break;
case execplan::CalpontSystemCatalog::CHAR:
case execplan::CalpontSystemCatalog::VARCHAR:
{
const string& strval = fp[1]->data()->getStrVal(row, isNull);
len = strtol(strval.c_str(), NULL, 10);
break;
}
default:
{
len = fp[1]->data()->getIntVal(row, isNull);
std::ostringstream oss;
oss << "lpad parameter 2 must be numeric, not " << execplan::colDataTypeToString(fp[1]->data()->resultType().colDataType);
throw logging::IDBExcept(oss.str(), logging::ERR_DATATYPE_NOT_SUPPORT);
}
}
@@ -124,7 +136,12 @@ std::string Func_rpad::getStrVal(rowgroup::Row& row,
return "";
// The pad characters.
const string& pad = fp[2]->data()->getStrVal(row, isNull);
// MCOL-2182 As of MariaDB 10.3 the third parameter - pad characters - is optional
const string* pad = &fPad;
if (fp.size() > 2)
{
pad = &fp[2]->data()->getStrVal(row, isNull);
}
if (isNull)
return "";
@@ -172,10 +189,10 @@ std::string Func_rpad::getStrVal(rowgroup::Row& row,
// This is the case where there's room to pad.
// Convert the pad string to wide
padwclen = pad.length(); // A guess to start.
padwclen = pad->length(); // A guess to start.
int padbufsize = (padwclen + 1) * sizeof(wchar_t);
wchar_t* wcpad = (wchar_t*)alloca(padbufsize);
size_t padlen = utf8::idb_mbstowcs(wcpad, pad.c_str(), padwclen + 1);
size_t padlen = utf8::idb_mbstowcs(wcpad, pad->c_str(), padwclen + 1);
// How many chars do we need?
unsigned int padspace = len - strSize;

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -69,9 +70,10 @@ std::string Func_substring_index::getStrVal(rowgroup::Row& row,
if ( count == 0 )
return "";
size_t end = strlen(str.c_str());
// To avoid comparison b/w int64_t and size_t
int64_t end = strlen(str.c_str()) & 0x7fffffffffffffff;
if ( count > (int64_t) end )
if ( count > end )
return str;
if (( count < 0 ) && ((count * -1) > end))
@@ -83,7 +85,7 @@ std::string Func_substring_index::getStrVal(rowgroup::Row& row,
{
int pointer = 0;
for ( int i = 0 ; i < count ; i ++ )
for ( int64_t i = 0 ; i < count ; i ++ )
{
string::size_type pos = str.find(delim, pointer);
@@ -102,13 +104,13 @@ std::string Func_substring_index::getStrVal(rowgroup::Row& row,
int pointer = end;
int start = 0;
for ( int i = 0 ; i < count ; i ++ )
for ( int64_t i = 0 ; i < count ; i ++ )
{
string::size_type pos = str.rfind(delim, pointer);
if (pos != string::npos)
{
if ( count > (int64_t) end )
if ( count > end )
return "";
pointer = pos - 1;

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -42,7 +43,9 @@ namespace
using namespace funcexp;
inline void decimalPlaceDouble(FunctionParm& fp, int64_t& s, double& p, Row& row, bool& isNull)
// P should be double or long double
template <typename P>
inline void decimalPlaceDouble(FunctionParm& fp, int64_t& s, P& p, Row& row, bool& isNull)
{
s = fp[1]->data()->getIntVal(row, isNull);
int64_t d = s;
@@ -57,9 +60,9 @@ inline void decimalPlaceDouble(FunctionParm& fp, int64_t& s, double& p, Row& row
r *= 10;
if (d >= 0)
p = (double) r;
p = (P) r;
else
p = 1.0 / ((double) r);
p = 1.0 / ((P) r);
}
}
@@ -223,6 +226,60 @@ double Func_truncate::getDoubleVal(Row& row,
return d;
}
long double Func_truncate::getLongDoubleVal(Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& op_ct)
{
if (execplan::CalpontSystemCatalog::LONGDOUBLE == op_ct.colDataType)
{
int64_t d = 0;
long double p = 1;
decimalPlaceDouble(parm, d, p, row, isNull);
if (isNull)
return 0.0;
long double x = parm[0]->data()->getLongDoubleVal(row, isNull);
if (!isNull)
{
x *= p;
if (x > 0)
x = floor(x);
else
x = ceil(x);
if (p != 0.0)
x /= p;
else
x = 0.0;
}
return x;
}
IDB_Decimal x = getDecimalVal(row, parm, isNull, op_ct);
if (isNull)
return 0.0;
double d = x.value;
if (x.scale > 0)
{
while (x.scale-- > 0)
d /= 10.0;
}
else
{
while (x.scale++ < 0)
d *= 10.0;
}
return d;
}
IDB_Decimal Func_truncate::getDecimalVal(Row& row,
FunctionParm& parm,
@@ -325,6 +382,26 @@ IDB_Decimal Func_truncate::getDecimalVal(Row& row,
}
break;
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
int64_t s = 0;
long double p = 1;
decimalPlaceDouble(parm, s, p, row, isNull);
if (isNull)
break;
long double x = parm[0]->data()->getLongDoubleVal(row, isNull);
if (!isNull)
{
x *= p;
decimal.value = (int64_t) x;
decimal.scale = s;
}
}
break;
case execplan::CalpontSystemCatalog::DATE:
{
int32_t s = 0;

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -439,6 +440,18 @@ void FuncExp::evaluate(rowgroup::Row& row, std::vector<execplan::SRCP>& expressi
break;
}
case CalpontSystemCatalog::LONGDOUBLE:
{
long double val = expression[i]->getLongDoubleVal(row, isNull);
if (isNull)
row.setLongDoubleField(LONGDOUBLENULL, expression[i]->outputIndex());
else
row.setLongDoubleField(val, expression[i]->outputIndex());
break;
}
case CalpontSystemCatalog::DECIMAL:
case CalpontSystemCatalog::UDECIMAL:
{

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -751,6 +752,16 @@ string doubleToString(double d)
return buf;
}
inline
string longDoubleToString(long double ld)
{
// long double's can be *really* long to print out. Max mysql
// is e308 so allow for 308 + 36 decimal places minimum.
char buf[384];
snprintf(buf, 384, "%Lf", ld);
return buf;
}
//@bug6146, remove duplicate function with incorrect impl. Use the DataConvert::decimalToString()
//string decimalToString( execplan::IDB_Decimal x, int p )

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -60,6 +61,7 @@ void Func::init()
double* dp = reinterpret_cast<double*>(&dni);
fDoubleNullVal = *dp;
fDoubleNullVal = joblist::LONGDOUBLENULL;
}
@@ -341,6 +343,11 @@ string Func::doubleToString(double d)
return helpers::doubleToString(d);
}
string Func::longDoubleToString(long double ld)
{
return helpers::longDoubleToString(ld);
}
} // namespace funcexp
// vim:ts=4 sw=4:

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -90,6 +91,11 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct) = 0;
virtual long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct) = 0;
virtual std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
@@ -152,6 +158,11 @@ public:
{
return fDoubleNullVal;
}
const long double longDoubleNullVal() const
{
return fLongDoubleNullVal;
}
protected:
virtual uint32_t stringToDate(std::string);
@@ -164,6 +175,7 @@ protected:
virtual std::string intToString(int64_t);
virtual std::string doubleToString(double);
virtual std::string longDoubleToString(long double);
virtual int64_t nowDatetime();
virtual int64_t addTime(DateTime& dt1, dataconvert::Time& dt2);
@@ -180,6 +192,7 @@ private:
float fFloatNullVal;
double fDoubleNullVal;
long double fLongDoubleNullVal;
};

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -85,6 +86,11 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
@@ -137,6 +143,11 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
@@ -185,6 +196,11 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
@@ -232,6 +248,11 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
@@ -289,6 +310,11 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
@@ -337,6 +363,11 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
@@ -384,6 +415,11 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
@@ -456,6 +492,11 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
execplan::IDB_Decimal getDecimalVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,

View File

@@ -64,6 +64,14 @@ public:
return (getBoolVal(row, fp, isNull, op_ct) ? 1.0 : 0.0);
}
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
return (getBoolVal(row, fp, isNull, op_ct) ? 1.0 : 0.0);
}
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -57,6 +58,14 @@ public:
return (double) getIntVal(row, fp, isNull, op_ct);
}
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
return (long double) getIntVal(row, fp, isNull, op_ct);
}
/*
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
@@ -196,6 +205,11 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
@@ -238,6 +252,11 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
@@ -423,6 +442,11 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -58,6 +59,14 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
return (long double)getDoubleVal(row, fp, isNull, op_ct);
}
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -55,6 +56,14 @@ public:
return ((double) getIntVal(row, fp, isNull, op_ct));
}
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
return ((long double) getIntVal(row, fp, isNull, op_ct));
}
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -57,12 +58,14 @@ public:
{
return ((uint64_t) getDoubleVal(row, fp, isNull, op_ct));
}
/*
double getDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct) = 0;
*/
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
return ((long double) getDoubleVal(row, fp, isNull, op_ct));
}
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
@@ -99,6 +102,11 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
execplan::IDB_Decimal getDecimalVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
@@ -120,6 +128,11 @@ public:
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
};
@@ -137,6 +150,11 @@ public:
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
};
@@ -165,6 +183,11 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
execplan::IDB_Decimal getDecimalVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
@@ -202,6 +225,11 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
@@ -239,6 +267,11 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
@@ -271,6 +304,11 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
@@ -350,6 +388,11 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
execplan::IDB_Decimal getDecimalVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -57,6 +58,14 @@ public:
return strtod(getStrVal(row, fp, isNull, op_ct).c_str(), NULL);
}
long double getLongDoubleVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct)
{
return strtold(getStrVal(row, fp, isNull, op_ct).c_str(), NULL);
}
#if 0
std::string getStrVal(rowgroup::Row& row,
FunctionParm& fp,
@@ -105,12 +114,16 @@ protected:
// Bug3788, use the shorter of fixed or scientific notation for floating point values.
// [ the default format in treenode.h is fixed-point notation ]
char buf[20];
double floatVal;
int exponent;
double base;
long double floatVal;
int64_t exponent;
long double base;
switch (fp->data()->resultType().colDataType)
{
case execplan::CalpontSystemCatalog::LONGDOUBLE:
floatVal = fp->data()->getLongDoubleVal(row, isNull);
break;
case execplan::CalpontSystemCatalog::DOUBLE:
floatVal = fp->data()->getDoubleVal(row, isNull);
break;
@@ -125,19 +138,19 @@ protected:
break;
}
exponent = (int)floor(log10( fabs(floatVal)));
exponent = (int)floor(log10( fabsl(floatVal)));
base = floatVal * pow(10, -1.0 * exponent);
if (isnan(exponent) || isnan(base))
{
snprintf(buf, 20, "%f", floatVal);
snprintf(buf, 20, "%Lf", floatVal);
fFloatStr = execplan::removeTrailing0(buf, 20);
}
else
{
snprintf(buf, 20, "%.5f", base);
snprintf(buf, 20, "%.5Lf", base);
fFloatStr = execplan::removeTrailing0(buf, 20);
snprintf(buf, 20, "e%02d", exponent);
snprintf(buf, 20, "e%02ld", exponent);
fFloatStr += buf;
}
@@ -312,6 +325,7 @@ public:
*/
class Func_lpad : public Func_Str
{
static const string fPad;
public:
Func_lpad() : Func_Str("lpad") {}
virtual ~Func_lpad() {}
@@ -329,6 +343,7 @@ public:
*/
class Func_rpad : public Func_Str
{
static const string fPad;
public:
Func_rpad() : Func_Str("rpad") {}
virtual ~Func_rpad() {}

View File

@@ -1,5 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2018 MariaDB Corporation
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -118,7 +118,6 @@ JoinPartition::JoinPartition(const JoinPartition& jp, bool splitMode) :
totalBytesWritten(0), maxLargeSize(0), maxSmallSize(0),
nextSmallOffset(0), nextLargeOffset(0)
{
config::Config* config = config::Config::makeConfig();
boost::posix_time::ptime t;
ostringstream os;

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -45,7 +46,14 @@ TupleJoiner::TupleJoiner(
smallRG(smallInput), largeRG(largeInput), joinAlg(INSERTING), joinType(jt),
threadCount(1), typelessJoin(false), bSignedUnsignedJoin(false), uniqueLimit(100), finished(false)
{
if (smallRG.usesStringTable())
if (smallRG.getColTypes()[smallJoinColumn] == CalpontSystemCatalog::LONGDOUBLE)
{
STLPoolAllocator<pair<const long double, Row::Pointer> > alloc(64 * 1024 * 1024 + 1);
_pool = alloc.getPoolAllocator();
ld.reset(new ldhash_t(10, hasher(), ldhash_t::key_equal(), alloc));
}
else if (smallRG.usesStringTable())
{
STLPoolAllocator<pair<const int64_t, Row::Pointer> > alloc(64 * 1024 * 1024 + 1);
_pool = alloc.getPoolAllocator();
@@ -131,8 +139,14 @@ TupleJoiner::TupleJoiner(
if (keyLength > 65536)
keyLength = 65536;
}
else if (smallRG.getColTypes()[smallKeyColumns[i]] == CalpontSystemCatalog::LONGDOUBLE)
{
keyLength += sizeof(long double);
}
else
{
keyLength += 8;
}
// Set bSignedUnsignedJoin if one or more join columns are signed to unsigned compares.
if (smallRG.isUnsigned(smallKeyColumns[i]) != largeRG.isUnsigned(largeKeyColumns[i]))
@@ -198,9 +212,20 @@ void TupleJoiner::insert(Row& r, bool zeroTheRid)
{
if (typelessJoin)
{
ht->insert(pair<TypelessData, Row::Pointer>
(makeTypelessKey(r, smallKeyColumns, keyLength, &storedKeyAlloc),
r.getPointer()));
TypelessData td = makeTypelessKey(r, smallKeyColumns, keyLength, &storedKeyAlloc,
largeRG, largeKeyColumns);
if (td.len > 0)
{
ht->insert(pair<TypelessData, Row::Pointer>(td, r.getPointer()));
}
}
else if (r.getColType(smallKeyColumns[0]) == execplan::CalpontSystemCatalog::LONGDOUBLE)
{
long double smallKey = r.getLongDoubleField(smallKeyColumns[0]);
if (UNLIKELY(smallKey == joblist::LONGDOUBLENULL))
ld->insert(pair<long double, Row::Pointer>(joblist::LONGDOUBLENULL, r.getPointer()));
else
ld->insert(pair<long double, Row::Pointer>(smallKey, r.getPointer()));
}
else if (!smallRG.usesStringTable())
{
@@ -260,9 +285,16 @@ void TupleJoiner::match(rowgroup::Row& largeSideRow, uint32_t largeRowIndex, uin
thIterator it;
pair<thIterator, thIterator> range;
largeKey = makeTypelessKey(largeSideRow, largeKeyColumns, keyLength, &tmpKeyAlloc[threadID]);
it = ht->find(largeKey);
largeKey = makeTypelessKey(largeSideRow, largeKeyColumns, keyLength, &tmpKeyAlloc[threadID], smallRG, smallKeyColumns);
if (largeKey.len > 0)
{
it = ht->find(largeKey);
}
else
{
return;
}
if (it == ht->end() && !(joinType & (LARGEOUTER | MATCHNULLS)))
return;
@@ -271,6 +303,28 @@ void TupleJoiner::match(rowgroup::Row& largeSideRow, uint32_t largeRowIndex, uin
for (; range.first != range.second; ++range.first)
matches->push_back(range.first->second);
}
else if (largeSideRow.getColType(largeKeyColumns[0]) == CalpontSystemCatalog::LONGDOUBLE
&& ld)
{
// This is a compare of two long double
long double largeKey;
ldIterator it;
pair<ldIterator, ldIterator> range;
Row r;
largeKey = largeSideRow.getLongDoubleField(largeKeyColumns[0]);
it = ld->find(largeKey);
if (it == ld->end() && !(joinType & (LARGEOUTER | MATCHNULLS)))
return;
range = ld->equal_range(largeKey);
for (; range.first != range.second; ++range.first)
{
matches->push_back(range.first->second);
}
}
else if (!smallRG.usesStringTable())
{
int64_t largeKey;
@@ -278,7 +332,11 @@ void TupleJoiner::match(rowgroup::Row& largeSideRow, uint32_t largeRowIndex, uin
pair<iterator, iterator> range;
Row r;
if (largeSideRow.isUnsigned(largeKeyColumns[0]))
if (largeSideRow.getColType(largeKeyColumns[0]) == CalpontSystemCatalog::LONGDOUBLE)
{
largeKey = (int64_t)largeSideRow.getLongDoubleField(largeKeyColumns[0]);
}
else if (largeSideRow.isUnsigned(largeKeyColumns[0]))
{
largeKey = (int64_t)largeSideRow.getUintField(largeKeyColumns[0]);
}
@@ -287,19 +345,41 @@ void TupleJoiner::match(rowgroup::Row& largeSideRow, uint32_t largeRowIndex, uin
largeKey = largeSideRow.getIntField(largeKeyColumns[0]);
}
it = h->find(largeKey);
if (it == end() && !(joinType & (LARGEOUTER | MATCHNULLS)))
return;
range = h->equal_range(largeKey);
//smallRG.initRow(&r);
for (; range.first != range.second; ++range.first)
if (ld)
{
//r.setData(range.first->second);
//cerr << "matched small side row: " << r.toString() << endl;
matches->push_back(range.first->second);
// Compare against long double
ldIterator it;
pair<ldIterator, ldIterator> range;
long double ldKey = largeKey;
// ldKey = 6920;
it = ld->find(ldKey);
if (it == ld->end() && !(joinType & (LARGEOUTER | MATCHNULLS)))
return;
range = ld->equal_range(ldKey);
for (; range.first != range.second; ++range.first)
{
matches->push_back(range.first->second);
}
}
else
{
it = h->find(largeKey);
if (it == h->end() && !(joinType & (LARGEOUTER | MATCHNULLS)))
return;
range = h->equal_range(largeKey);
//smallRG.initRow(&r);
for (; range.first != range.second; ++range.first)
{
//r.setData(range.first->second);
//cerr << "matched small side row: " << r.toString() << endl;
matches->push_back(range.first->second);
}
}
}
else
@@ -335,7 +415,14 @@ void TupleJoiner::match(rowgroup::Row& largeSideRow, uint32_t largeRowIndex, uin
if (UNLIKELY(inUM() && (joinType & MATCHNULLS) && !isNull && !typelessJoin))
{
if (!smallRG.usesStringTable())
if (smallRG.getColType(largeKeyColumns[0]) == CalpontSystemCatalog::LONGDOUBLE)
{
pair<ldIterator, ldIterator> range = ld->equal_range(joblist::LONGDOUBLENULL);
for (; range.first != range.second; ++range.first)
matches->push_back(range.first->second);
}
else if (!smallRG.usesStringTable())
{
pair<iterator, iterator> range = h->equal_range(getJoinNullValue());
@@ -357,7 +444,14 @@ void TupleJoiner::match(rowgroup::Row& largeSideRow, uint32_t largeRowIndex, uin
{
if (!typelessJoin)
{
if (!smallRG.usesStringTable())
if (smallRG.getColType(smallKeyColumns[0]) == CalpontSystemCatalog::LONGDOUBLE)
{
ldIterator it;
for (it = ld->begin(); it != ld->end(); ++it)
matches->push_back(it->second);
}
else if (!smallRG.usesStringTable())
{
iterator it;
@@ -410,6 +504,7 @@ void TupleJoiner::doneInserting()
tr1::unordered_set<int64_t>::iterator uit;
sthash_t::iterator sthit;
hash_t::iterator hit;
ldhash_t::iterator ldit;
typelesshash_t::iterator thit;
uint32_t i, pmpos = 0, rowCount;
Row smallRow;
@@ -425,6 +520,8 @@ void TupleJoiner::doneInserting()
pmpos = 0;
else if (typelessJoin)
thit = ht->begin();
else if (smallRG.getColType(smallKeyColumns[0]) == CalpontSystemCatalog::LONGDOUBLE)
ldit = ld->begin();
else if (!smallRG.usesStringTable())
hit = h->begin();
else
@@ -439,6 +536,11 @@ void TupleJoiner::doneInserting()
smallRow.setPointer(thit->second);
++thit;
}
else if (smallRG.getColType(smallKeyColumns[col]) == CalpontSystemCatalog::LONGDOUBLE)
{
smallRow.setPointer(ldit->second);
++ldit;
}
else if (!smallRG.usesStringTable())
{
smallRow.setPointer(hit->second);
@@ -450,6 +552,25 @@ void TupleJoiner::doneInserting()
++sthit;
}
if (smallRow.getColType(smallKeyColumns[col]) == CalpontSystemCatalog::LONGDOUBLE)
{
double dval = (double)roundl(smallRow.getLongDoubleField(smallKeyColumns[col]));
switch (largeRG.getColType(largeKeyColumns[col]))
{
case CalpontSystemCatalog::DOUBLE:
case CalpontSystemCatalog::UDOUBLE:
case CalpontSystemCatalog::FLOAT:
case CalpontSystemCatalog::UFLOAT:
{
uniquer.insert(*(int64_t*)&dval);
}
default:
{
uniquer.insert((int64_t)dval);
}
}
}
else
if (smallRow.isUnsigned(smallKeyColumns[col]))
{
uniquer.insert((int64_t)smallRow.getUintField(smallKeyColumns[col]));
@@ -614,11 +735,23 @@ void TupleJoiner::getUnmarkedRows(vector<Row::Pointer>* out)
out->push_back(it->second);
}
}
else if (smallRG.getColType(smallKeyColumns[0]) == CalpontSystemCatalog::LONGDOUBLE)
{
ldIterator it;
for (it = ld->begin(); it != ld->end(); ++it)
{
smallR.setPointer(it->second);
if (!smallR.isMarked())
out->push_back(it->second);
}
}
else if (!smallRG.usesStringTable())
{
iterator it;
for (it = begin(); it != end(); ++it)
for (it = h->begin(); it != h->end(); ++it)
{
smallR.setPointer(it->second);
@@ -670,8 +803,9 @@ void TupleJoiner::updateCPData(const Row& r)
for (col = 0; col < smallKeyColumns.size(); col++)
{
// if (r.getColumnWidth(smallKeyColumns[col]) > 8)
if (r.isLongString(smallKeyColumns[col]))
continue;
continue;
int64_t& min = cpValues[col][0], &max = cpValues[col][1];
@@ -693,7 +827,29 @@ void TupleJoiner::updateCPData(const Row& r)
}
else if (r.isUnsigned(smallKeyColumns[col]))
{
uint64_t uval = r.getUintField(smallKeyColumns[col]);
uint64_t uval;
if (r.getColType(smallKeyColumns[col]) == CalpontSystemCatalog::LONGDOUBLE)
{
double dval = (double)roundl(r.getLongDoubleField(smallKeyColumns[col]));
switch (largeRG.getColType(largeKeyColumns[col]))
{
case CalpontSystemCatalog::DOUBLE:
case CalpontSystemCatalog::UDOUBLE:
case CalpontSystemCatalog::FLOAT:
case CalpontSystemCatalog::UFLOAT:
{
uval = *(uint64_t*)&dval;
}
default:
{
uval = (uint64_t)dval;
}
}
}
else
{
uval = r.getUintField(smallKeyColumns[col]);
}
if (uval > static_cast<uint64_t>(max))
max = static_cast<int64_t>(uval);
@@ -703,7 +859,29 @@ void TupleJoiner::updateCPData(const Row& r)
}
else
{
int64_t val = r.getIntField(smallKeyColumns[col]);
int64_t val;
if (r.getColType(smallKeyColumns[col]) == CalpontSystemCatalog::LONGDOUBLE)
{
double dval = (double)roundl(r.getLongDoubleField(smallKeyColumns[col]));
switch (largeRG.getColType(largeKeyColumns[col]))
{
case CalpontSystemCatalog::DOUBLE:
case CalpontSystemCatalog::UDOUBLE:
case CalpontSystemCatalog::FLOAT:
case CalpontSystemCatalog::UFLOAT:
{
val = *(int64_t*)&dval;
}
default:
{
val = (int64_t)dval;
}
}
}
else
{
val = r.getIntField(smallKeyColumns[col]);
}
if (val > max)
max = val;
@@ -720,6 +898,8 @@ size_t TupleJoiner::size() const
{
if (UNLIKELY(typelessJoin))
return ht->size();
else if (smallRG.getColType(smallKeyColumns[0]) == CalpontSystemCatalog::LONGDOUBLE)
return ld->size();
else if (!smallRG.usesStringTable())
return h->size();
else
@@ -768,20 +948,18 @@ TypelessData makeTypelessKey(const Row& r, const vector<uint32_t>& keyCols,
ret.data[off++] = 0;
}
else if (r.isUnsigned(keyCols[i]))
{
if (off + 8 > keylen)
goto toolong;
*((uint64_t*) &ret.data[off]) = r.getUintField(keyCols[i]);
off += 8;
}
else
{
if (off + 8 > keylen)
goto toolong;
if (r.isUnsigned(keyCols[i]))
{
*((uint64_t*) &ret.data[off]) = r.getUintField(keyCols[i]);
}
else
{
*((int64_t*) &ret.data[off]) = r.getIntField(keyCols[i]);
}
*((int64_t*) &ret.data[off]) = r.getIntField(keyCols[i]);
off += 8;
}
}
@@ -795,7 +973,132 @@ toolong:
return ret;
}
TypelessData makeTypelessKey(const Row& r, const vector<uint32_t>& keyCols, PoolAllocator* fa)
TypelessData makeTypelessKey(const Row& r, const vector<uint32_t>& keyCols,
uint32_t keylen, FixedAllocator* fa,
const rowgroup::RowGroup& otherSideRG, const std::vector<uint32_t>& otherKeyCols)
{
TypelessData ret;
uint32_t off = 0, i, j;
execplan::CalpontSystemCatalog::ColDataType type;
ret.data = (uint8_t*) fa->allocate();
for (i = 0; i < keyCols.size(); i++)
{
type = r.getColTypes()[keyCols[i]];
if (type == CalpontSystemCatalog::VARCHAR ||
type == CalpontSystemCatalog::CHAR ||
type == CalpontSystemCatalog::TEXT)
{
// this is a string, copy a normalized version
const uint8_t* str = r.getStringPointer(keyCols[i]);
uint32_t width = r.getStringLength(keyCols[i]);
if (width > 65536)
{
throw runtime_error("Cannot join strings greater than 64KB");
}
for (j = 0; j < width && str[j] != 0; j++)
{
if (off >= keylen)
goto toolong;
ret.data[off++] = str[j];
}
if (off >= keylen)
goto toolong;
ret.data[off++] = 0;
}
else if (r.getColType(keyCols[i]) == CalpontSystemCatalog::LONGDOUBLE)
{
if (off + sizeof(long double) > keylen)
goto toolong;
// Small side is a long double. Since CS can't store larger than DOUBLE,
// we need to convert to whatever type large side is -- double or int64
long double keyld = r.getLongDoubleField(keyCols[i]);
switch (otherSideRG.getColType(otherKeyCols[i]))
{
case CalpontSystemCatalog::DOUBLE:
case CalpontSystemCatalog::UDOUBLE:
case CalpontSystemCatalog::FLOAT:
case CalpontSystemCatalog::UFLOAT:
{
if (off + 8 > keylen)
goto toolong;
if (keyld > MAX_DOUBLE || keyld < MIN_DOUBLE)
{
ret.len = 0;
return ret;
}
else
{
double d = (double)keyld;
*((int64_t*) &ret.data[off]) = *(int64_t*)&d;
}
break;
}
case CalpontSystemCatalog::LONGDOUBLE:
{
if (off + sizeof(long double) > keylen)
goto toolong;
*((long double*) &ret.data[off]) = keyld;
off += sizeof(long double);
break;
}
default:
{
if (off + 8 > keylen)
goto toolong;
if (r.isUnsigned(keyCols[i]) && keyld > MAX_UBIGINT)
{
ret.len = 0;
return ret;
}
else if (keyld > MAX_BIGINT || keyld < MIN_BIGINT)
{
ret.len = 0;
return ret;
}
else
{
*((int64_t*) &ret.data[off]) = (int64_t)keyld;
off += 8;
}
break;
}
}
}
else if (r.isUnsigned(keyCols[i]))
{
if (off + 8 > keylen)
goto toolong;
*((uint64_t*) &ret.data[off]) = r.getUintField(keyCols[i]);
off += 8;
}
else
{
if (off + 8 > keylen)
goto toolong;
*((int64_t*) &ret.data[off]) = r.getIntField(keyCols[i]);
off += 8;
}
}
ret.len = off;
fa->truncateBy(keylen - off);
return ret;
toolong:
fa->truncateBy(keylen);
ret.len = 0;
return ret;
}
TypelessData makeTypelessKey(const Row& r, const vector<uint32_t>& keyCols, PoolAllocator* fa,
const rowgroup::RowGroup& otherSideRG, const std::vector<uint32_t>& otherKeyCols)
{
TypelessData ret;
uint32_t off = 0, i, j;
@@ -808,7 +1111,12 @@ TypelessData makeTypelessKey(const Row& r, const vector<uint32_t>& keyCols, Pool
{
type = r.getColTypes()[keyCols[i]];
if (r.isCharType(keyCols[i]))
if (r.getColType(keyCols[i]) == CalpontSystemCatalog::LONGDOUBLE
&& otherSideRG.getColType(otherKeyCols[i]) == CalpontSystemCatalog::LONGDOUBLE)
{
keylen += sizeof(long double);
}
else if (r.isCharType(keyCols[i]))
keylen += r.getStringLength(keyCols[i]) + 1;
else
keylen += 8;
@@ -838,17 +1146,66 @@ TypelessData makeTypelessKey(const Row& r, const vector<uint32_t>& keyCols, Pool
ret.data[off++] = 0;
}
else if (type == CalpontSystemCatalog::LONGDOUBLE)
{
// Small side is a long double. Since CS can't store larger than DOUBLE,
// we need to convert to whatever type large side is -- double or int64
long double keyld = r.getLongDoubleField(keyCols[i]);
switch (otherSideRG.getColType(otherKeyCols[i]))
{
case CalpontSystemCatalog::DOUBLE:
case CalpontSystemCatalog::UDOUBLE:
case CalpontSystemCatalog::FLOAT:
case CalpontSystemCatalog::UFLOAT:
{
if (keyld > MAX_DOUBLE || keyld < MIN_DOUBLE)
{
ret.len = 0;
return ret;
}
else
{
double d = (double)keyld;
*((int64_t*) &ret.data[off]) = *(int64_t*)&d;
off += 8;
}
break;
}
case CalpontSystemCatalog::LONGDOUBLE:
{
*((long double*) &ret.data[off]) = keyld;
off += sizeof(long double);
break;
}
default:
{
if (r.isUnsigned(keyCols[i]) && keyld > MAX_UBIGINT)
{
ret.len = 0;
return ret;
}
else if (keyld > MAX_BIGINT || keyld < MIN_BIGINT)
{
ret.len = 0;
return ret;
}
else
{
*((int64_t*) &ret.data[off]) = (int64_t)keyld;
off += 8;
}
break;
}
}
}
else if (r.isUnsigned(keyCols[i]))
{
*((uint64_t*)&ret.data[off]) = r.getUintField(keyCols[i]);
off += 8;
}
else
{
if (r.isUnsigned(keyCols[i]))
{
*((uint64_t*)&ret.data[off]) = r.getUintField(keyCols[i]);
}
else
{
*((int64_t*)&ret.data[off]) = r.getIntField(keyCols[i]);
}
*((int64_t*)&ret.data[off]) = r.getIntField(keyCols[i]);
off += 8;
}
}
@@ -881,25 +1238,29 @@ uint64_t getHashOfTypelessKey(const Row& r, const vector<uint32_t>& keyCols, uin
ret = hasher((const char*) str, len, ret);
/*
for (uint32_t j = 0; j < width && str[j] != 0; j++)
ret.data[off++] = str[j];
ret.data[off++] = str[j];
*/
ret = hasher(&nullChar, 1, ret);
width += len + 1;
}
else if (r.getColType(keyCols[i]) == CalpontSystemCatalog::LONGDOUBLE)
{
long double tmp = r.getLongDoubleField(keyCols[i]);
ret = hasher((char*) &tmp, sizeof(long double), ret);
width += sizeof(long double);
}
else
if (r.isUnsigned(keyCols[i]))
{
tmp = r.getUintField(keyCols[i]);
ret = hasher((char*) &tmp, 8, ret);
width += 8;
}
else
{
tmp = r.getIntField(keyCols[i]);
ret = hasher((char*) &tmp, 8, ret);
width += 8;
if (r.isUnsigned(keyCols[i]))
{
tmp = r.getUintField(keyCols[i]);
ret = hasher((char*) &tmp, 8, ret);
}
else
{
tmp = r.getIntField(keyCols[i]);
ret = hasher((char*) &tmp, 8, ret);
}
}
}

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -78,14 +79,30 @@ inline bool TypelessData::operator==(const TypelessData& t) const
return (memcmp(data, t.data, len) == 0);
}
// Comparator for long double in the hash
class LongDoubleEq
{
public:
LongDoubleEq(){};
inline bool operator()(const long double& pos1, const long double& pos2) const
{
return pos1 == pos2;
}
};
/* This function makes the keys for string & compound joins. The length of the
* key is limited by keylen. Keys that are longer are assigned a length of 0 on return,
* signifying that it shouldn't match anything.
*/
extern TypelessData makeTypelessKey(const rowgroup::Row&,
const std::vector<uint32_t>&, uint32_t keylen, utils::FixedAllocator* fa);
// MCOL-1822 SUM/AVG as long double: pass in RG and col so we can determine type conversion
extern TypelessData makeTypelessKey(const rowgroup::Row&,
const std::vector<uint32_t>&, utils::PoolAllocator* fa);
const std::vector<uint32_t>&, uint32_t keylen, utils::FixedAllocator* fa,
const rowgroup::RowGroup&, const std::vector<uint32_t>&);
extern TypelessData makeTypelessKey(const rowgroup::Row&,
const std::vector<uint32_t>&, utils::PoolAllocator* fa,
const rowgroup::RowGroup&, const std::vector<uint32_t>&);
extern uint64_t getHashOfTypelessKey(const rowgroup::Row&, const std::vector<uint32_t>&,
uint32_t seed = 0);
@@ -99,10 +116,26 @@ public:
{
return fHasher((char*) &val, 8);
}
inline size_t operator()(uint64_t val) const
{
return fHasher((char*) &val, 8);
}
inline size_t operator()(const TypelessData& e) const
{
return fHasher((char*) e.data, e.len);
}
inline size_t operator()(long double val) const
{
if (sizeof(long double) == 8) // Probably just MSC, but you never know.
{
return fHasher((char*) &val, sizeof(long double));
}
else
{
// For Linux x86_64, long double is stored in 128 bits, but only 80 are significant
return fHasher((char*) &val, 10);
}
}
private:
utils::Hasher fHasher;
@@ -300,29 +333,24 @@ private:
utils::STLPoolAllocator<std::pair<const int64_t, rowgroup::Row::Pointer> > > sthash_t;
typedef std::tr1::unordered_multimap<TypelessData, rowgroup::Row::Pointer, hasher, std::equal_to<TypelessData>,
utils::STLPoolAllocator<std::pair<const TypelessData, rowgroup::Row::Pointer> > > typelesshash_t;
// MCOL-1822 Add support for Long Double AVG/SUM small side
typedef std::tr1::unordered_multimap<long double, rowgroup::Row::Pointer, hasher, LongDoubleEq,
utils::STLPoolAllocator<std::pair<const long double, rowgroup::Row::Pointer> > > ldhash_t;
typedef hash_t::iterator iterator;
typedef typelesshash_t::iterator thIterator;
typedef ldhash_t::iterator ldIterator;
TupleJoiner();
TupleJoiner(const TupleJoiner&);
TupleJoiner& operator=(const TupleJoiner&);
iterator begin()
{
return h->begin();
}
iterator end()
{
return h->end();
}
rowgroup::RGData smallNullMemory;
boost::scoped_ptr<hash_t> h; // used for UM joins on ints
boost::scoped_ptr<sthash_t> sth; // used for UM join on ints where the backing table uses a string table
boost::scoped_ptr<ldhash_t> ld; // used for UM join on long double
std::vector<rowgroup::Row::Pointer> rows; // used for PM join
/* This struct is rough. The BPP-JL stores the parsed results for

View File

@@ -1,6 +1,6 @@
/*
Copyright (c) 2017, MariaDB
Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -636,6 +636,18 @@ ByteStream& ByteStream::operator<<(const double d)
return *this;
}
ByteStream& ByteStream::operator<<(const long double d)
{
int sz = sizeof(long double);
if (fBuf == 0 || (fCurInPtr - fBuf + sz > fMaxLen + ISSOverhead))
growBuf(fMaxLen + BlockSize);
*((long double*) fCurInPtr) = d;
fCurInPtr += sz;
return *this;
}
ByteStream& ByteStream::operator>>(float& f)
{
peek(f);
@@ -648,6 +660,12 @@ ByteStream& ByteStream::operator>>(double& d)
fCurOutPtr += sizeof(double);
return *this;
}
ByteStream& ByteStream::operator>>(long double& d)
{
peek(d);
fCurOutPtr += sizeof(long double);
return *this;
}
void ByteStream::peek(float& f) const
{
if (length() < sizeof(float))
@@ -663,6 +681,14 @@ void ByteStream::peek(double& d) const
d = *((double*) fCurOutPtr);
}
void ByteStream::peek(long double& d) const
{
if (length() < sizeof(long double))
throw underflow_error("ByteStream>int64_t: not enough data in stream to fill datatype");
d = *((long double*) fCurOutPtr);
}
}//namespace messageqcpp

View File

@@ -1,6 +1,6 @@
/*
Copyright (c) 2017, MariaDB
Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporaton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -153,6 +153,11 @@ public:
* whatever the native byte order is.
*/
EXPORT ByteStream& operator<<(const double d);
/**
* push a long double onto the end of the stream. The byte
* order is whatever the native byte order is.
*/
EXPORT ByteStream& operator<<(const long double d);
/**
* push a std::string onto the end of the stream.
*/
@@ -212,6 +217,11 @@ public:
* order is whatever the native byte order is.
*/
EXPORT ByteStream& operator>>(double& d);
/**
* extract a long double from the front of the stream. The byte
* order is whatever the native byte order is.
*/
EXPORT ByteStream& operator>>(long double& d);
/**
* extract a std::string from the front of the stream.
*/
@@ -277,6 +287,11 @@ public:
* order is whatever the native byte order is.
*/
EXPORT void peek(double& f) const;
/**
* Peek at a long double from the front of the stream. The byte
* order is whatever the native byte order is.
*/
EXPORT void peek(long double& f) const;
/**
* Peek at a std::string from the front of the stream.
*/

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
/*
Copyright (c) 2017, MariaDB
Copyright (C) 2014 InfiniDB, Inc.
Copyright (c) 2019 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -612,14 +612,15 @@ protected:
virtual void attachGroupConcatAg();
virtual void updateEntry(const Row& row);
virtual void doMinMaxSum(const Row&, int64_t, int64_t, int);
virtual void doMinMax(const Row&, int64_t, int64_t, int);
virtual void doSum(const Row&, int64_t, int64_t, int);
virtual void doAvg(const Row&, int64_t, int64_t, int64_t);
virtual void doStatistics(const Row&, int64_t, int64_t, int64_t);
virtual void doBitOp(const Row&, int64_t, int64_t, int);
virtual void doUDAF(const Row&, int64_t, int64_t, int64_t, uint64_t& funcColsIdx);
virtual bool countSpecial(const RowGroup* pRG)
{
fRow.setIntField<8>(fRow.getIntField<8>(0) + pRG->getRowCount(), 0);
fRow.setUintField<8>(fRow.getUintField<8>(0) + pRG->getRowCount(), 0);
return true;
}
@@ -642,13 +643,9 @@ protected:
inline void updateUintMinMax(uint64_t val1, uint64_t val2, int64_t col, int func);
inline void updateCharMinMax(uint64_t val1, uint64_t val2, int64_t col, int func);
inline void updateDoubleMinMax(double val1, double val2, int64_t col, int func);
inline void updateLongDoubleMinMax(long double val1, long double val2, int64_t col, int func);
inline void updateFloatMinMax(float val1, float val2, int64_t col, int func);
inline void updateStringMinMax(std::string val1, std::string val2, int64_t col, int func);
inline void updateIntSum(int64_t val1, int64_t val2, int64_t col);
inline void updateUintSum(uint64_t val1, uint64_t val2, int64_t col);
inline void updateDoubleSum(double val1, double val2, int64_t col);
inline void updateFloatSum(float val1, float val2, int64_t col);
std::vector<SP_ROWAGG_GRPBY_t> fGroupByCols;
std::vector<SP_ROWAGG_FUNC_t> fFunctionCols;
RowAggMap_t* fAggMapPtr;
@@ -711,6 +708,7 @@ protected:
static const static_any::any& ullTypeId;
static const static_any::any& floatTypeId;
static const static_any::any& doubleTypeId;
static const static_any::any& longdoubleTypeId;
static const static_any::any& strTypeId;
};

View File

@@ -1,6 +1,6 @@
/*
Copyright (c) 2017, MariaDB
Copyright (C) 2014 InfiniDB, Inc.
Copyright (c) 2019 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -702,6 +702,9 @@ void Row::initToNull()
*((uint64_t*) &data[offsets[i]]) = joblist::DOUBLENULL;
break;
case CalpontSystemCatalog::LONGDOUBLE:
*((long double*) &data[offsets[i]]) = joblist::LONGDOUBLENULL;
case CalpontSystemCatalog::DATETIME:
*((uint64_t*) &data[offsets[i]]) = joblist::DATETIMENULL;
break;
@@ -804,13 +807,6 @@ void Row::initToNull()
*((uint64_t*) &data[offsets[i]]) = joblist::UBIGINTNULL;
break;
case CalpontSystemCatalog::LONGDOUBLE:
{
// no NULL value for long double yet, this is a nan.
memset(&data[offsets[i]], 0xFF, getColumnWidth(i));
break;
}
default:
ostringstream os;
os << "Row::initToNull(): got bad column type (" << types[i] <<
@@ -956,7 +952,7 @@ bool Row::isNullValue(uint32_t colIndex) const
return (*((uint64_t*) &data[offsets[colIndex]]) == joblist::UBIGINTNULL);
case CalpontSystemCatalog::LONGDOUBLE:
// return false; // no NULL value for long double yet
return (*((long double*) &data[offsets[colIndex]]) == joblist::LONGDOUBLENULL);
break;
default:

View File

@@ -1,6 +1,6 @@
/*
Copyright (c) 2017, MariaDB
Copyright (C) 2014 InfiniDB, Inc.
Copyright (c) 2019 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -330,6 +330,7 @@ public:
template<int len> inline int64_t getIntField(uint32_t colIndex) const;
inline int64_t getIntField(uint32_t colIndex) const;
template<int len> inline bool equals(uint64_t val, uint32_t colIndex) const;
inline bool equals(long double val, uint32_t colIndex) const;
inline bool equals(const std::string& val, uint32_t colIndex) const;
inline double getDoubleField(uint32_t colIndex) const;
@@ -616,6 +617,11 @@ inline bool Row::equals(uint64_t val, uint32_t colIndex) const
}
}
inline bool Row::equals(long double val, uint32_t colIndex) const
{
return *((long double*) &data[offsets[colIndex]]) == val;
}
inline bool Row::equals(const std::string& val, uint32_t colIndex) const
{
if (inStringTable(colIndex))
@@ -1030,6 +1036,11 @@ inline void Row::setFloatField(float val, uint32_t colIndex)
inline void Row::setLongDoubleField(long double val, uint32_t colIndex)
{
if (sizeof(long double) == 16)
{
// zero out the unused portion as there may be garbage there.
*((uint64_t*)&val+1) &= 0x000000000000FFFFULL;
}
*((long double*) &data[offsets[colIndex]]) = val;
}

8
utils/udfsdk/docs/README Normal file
View File

@@ -0,0 +1,8 @@
To Build PDF:
<as root>
[root@me docs]# sphinx-build -b latex source build
[root@me docs]# cd build
[root@me docs]# make
The UDAF.pdf file will be in the build directory

68
utils/udfsdk/docs/build/Makefile vendored Normal file
View File

@@ -0,0 +1,68 @@
# Makefile for Sphinx LaTeX output
ALLDOCS = $(basename $(wildcard *.tex))
ALLPDF = $(addsuffix .pdf,$(ALLDOCS))
ALLDVI = $(addsuffix .dvi,$(ALLDOCS))
ALLXDV =
ALLPS = $(addsuffix .ps,$(ALLDOCS))
ALLIMGS = $(wildcard *.png *.gif *.jpg *.jpeg)
# Prefix for archive names
ARCHIVEPREFIX =
# Additional LaTeX options (passed via variables in latexmkrc/latexmkjarc file)
export LATEXOPTS =
# Additional latexmk options
LATEXMKOPTS =
# format: pdf or dvi (used only by archive targets)
FMT = pdf
LATEX = latexmk -dvi
PDFLATEX = latexmk -pdf -dvi- -ps-
%.png %.gif %.jpg %.jpeg: FORCE_MAKE
extractbb '$@'
%.dvi: %.tex FORCE_MAKE
$(LATEX) $(LATEXMKOPTS) '$<'
%.ps: %.dvi
dvips '$<'
%.pdf: %.tex FORCE_MAKE
$(PDFLATEX) $(LATEXMKOPTS) '$<'
all: $(ALLPDF)
all-dvi: $(ALLDVI)
all-ps: $(ALLPS)
all-pdf: $(ALLPDF)
zip: all-$(FMT)
mkdir $(ARCHIVEPREFIX)docs-$(FMT)
cp $(ALLPDF) $(ARCHIVEPREFIX)docs-$(FMT)
zip -q -r -9 $(ARCHIVEPREFIX)docs-$(FMT).zip $(ARCHIVEPREFIX)docs-$(FMT)
rm -r $(ARCHIVEPREFIX)docs-$(FMT)
tar: all-$(FMT)
mkdir $(ARCHIVEPREFIX)docs-$(FMT)
cp $(ALLPDF) $(ARCHIVEPREFIX)docs-$(FMT)
tar cf $(ARCHIVEPREFIX)docs-$(FMT).tar $(ARCHIVEPREFIX)docs-$(FMT)
rm -r $(ARCHIVEPREFIX)docs-$(FMT)
gz: tar
gzip -9 < $(ARCHIVEPREFIX)docs-$(FMT).tar > $(ARCHIVEPREFIX)docs-$(FMT).tar.gz
bz2: tar
bzip2 -9 -k $(ARCHIVEPREFIX)docs-$(FMT).tar
xz: tar
xz -9 -k $(ARCHIVEPREFIX)docs-$(FMT).tar
clean:
rm -f *.log *.ind *.aux *.toc *.syn *.idx *.out *.ilg *.pla *.ps *.tar *.tar.gz *.tar.bz2 *.tar.xz $(ALLPDF) $(ALLDVI) $(ALLXDV) *.fls *.fdb_latexmk
.PHONY: all all-pdf all-dvi all-ps clean zip tar gz bz2 xz
.PHONY: FORCE_MAKE

View File

@@ -5,5 +5,6 @@ Version History
| Version | Date | Changes |
+=========+============+=============================+
| 1.1.0α | 2017-08-25 | - First alpha release |
+---------+------------+-----------------------------+
| 1.2.0α | 2016-05-18 | - Add multi parm support |
+---------+------------+-----------------------------+

View File

@@ -49,7 +49,7 @@ master_doc = 'index'
# General information about the project.
project = u'UDAF'
copyright = u'2017, MariaDB Corporation'
copyright = u'2019, MariaDB Corporation'
author = u'MariaDB Corporation'
# The version info for the project you're documenting, acts as replacement for
@@ -57,9 +57,9 @@ author = u'MariaDB Corporation'
# built documents.
#
# The short X.Y version.
version = u'1.1'
version = u'1.2'
# The full version, including alpha/beta/rc tags.
release = u'1.1'
release = u'1.2'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.

View File

@@ -34,3 +34,24 @@ The UDAFMap is where we tell the system about our function. For Columnstore 1.2,
return fm;
}
An alternative method added for 1.2 is to put the following in your .cpp file.
replace "median" with the name of your function:
::
class Add_median_ToUDAFMap
{
public:
Add_median_ToUDAFMap()
{
UDAFMap::getMap()["median"] = new median();
}
};
static Add_median_ToUDAFMap addToMap;
This defines an object whose constructor adds the entry to the UDAFMap. The
static declaration instatiates an object at runtime, thus adding the entry
at startup.

View File

@@ -77,7 +77,7 @@ The serialize method leverages Columnstore's :ref:`ByteStream <bytestream>` clas
For MEDIAN, serialize() iterates over the set and streams the values to the :ref:`ByteStream <bytestream>` and unserialze unstreams them back into the set:
.. literalinclude:: ../../../median.cpp
:lines: 290-305
:lines: 194-208
:language: cpp
.. rubric:: createUserData()
@@ -93,6 +93,6 @@ This function may be called many times from different modules. Do not expect you
The implementation of the createUserData() method() in MEDIAN:
.. literalinclude:: ../../../median.cpp
:lines: 283-288
:lines: 187-192
:language: cpp

0
utils/udfsdk/docs/source/usage/sourcefile.rst Executable file → Normal file
View File

View File

@@ -1,5 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2016 MariaDB Corporaton
Copyright (c) 2019 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -201,6 +201,14 @@ double MCS_add::getDoubleVal(Row& row,
return 0;
}
long double MCS_add::getLongDoubleVal(Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& op_ct)
{
return getDoubleVal(row, parm, isNull, op_ct);
}
float MCS_add::getFloatVal(Row& row,
FunctionParm& parm,
bool& isNull,
@@ -349,6 +357,14 @@ double MCS_isnull::getDoubleVal(Row& row,
return (getBoolVal(row, parm, isNull, op_ct) ? 1 : 0);
}
long double MCS_isnull::getLongDoubleVal(Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& op_ct)
{
return (getBoolVal(row, parm, isNull, op_ct) ? 1 : 0);
}
float MCS_isnull::getFloatVal(Row& row,
FunctionParm& parm,
bool& isNull,

View File

@@ -1,5 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2016 MariaDB Corporaton
Copyright (c) 2019 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -170,6 +170,14 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
/**
* Returns a long double result of this function.
*/
virtual long double getLongDoubleVal(rowgroup::Row& row,
funcexp::FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
/**
* Returns a float result of this function.
*/
@@ -266,6 +274,14 @@ public:
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
/**
* Returns a double result of this function.
*/
virtual long double getLongDoubleVal(rowgroup::Row& row,
funcexp::FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType& op_ct);
/**
* Returns a float result of this function.
*/

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (c) 2019 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -313,6 +314,20 @@ void FrameBoundExpressionRange<T>::validate()
break;
}
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
long double tmp = this->fRow.getLongDoubleField(this->fIndex[1]);
this->fIsZero = (tmp == 0.0);
if (tmp < 0)
{
invalid = true;
oss << tmp;
}
break;
}
case execplan::CalpontSystemCatalog::FLOAT:
case execplan::CalpontSystemCatalog::UFLOAT:
{

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2019 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -19,7 +20,6 @@
#include <iostream>
//#define NDEBUG
#include <cassert>
#include <string>
#include <stack>
@@ -174,7 +174,6 @@ int DoubleCompare::operator()(IdbCompare* l, Row::Pointer r1, Row::Pointer r2)
return ret;
}
int FloatCompare::operator()(IdbCompare* l, Row::Pointer r1, Row::Pointer r2)
{
l->row1().setData(r1);
@@ -206,6 +205,37 @@ int FloatCompare::operator()(IdbCompare* l, Row::Pointer r1, Row::Pointer r2)
return ret;
}
int LongDoubleCompare::operator()(IdbCompare* l, Row::Pointer r1, Row::Pointer r2)
{
l->row1().setData(r1);
l->row2().setData(r2);
bool b1 = l->row1().isNullValue(fSpec.fIndex);
bool b2 = l->row2().isNullValue(fSpec.fIndex);
int ret = 0;
if (b1 == true || b2 == true)
{
if (b1 == false && b2 == true)
ret = fSpec.fNf;
else if (b1 == true && b2 == false)
ret = -fSpec.fNf;
}
else
{
long double v1 = l->row1().getLongDoubleField(fSpec.fIndex);
long double v2 = l->row2().getLongDoubleField(fSpec.fIndex);
if (v1 > v2)
ret = fSpec.fAsc;
else if (v1 < v2)
ret = -fSpec.fAsc;
}
return ret;
}
bool CompareRule::less(Row::Pointer r1, Row::Pointer r2)
{
@@ -279,6 +309,13 @@ void CompareRule::compileRules(const std::vector<IdbSortSpec>& spec, const rowgr
break;
}
case CalpontSystemCatalog::LONGDOUBLE:
{
Compare* c = new LongDoubleCompare(*i);
fCompares.push_back(c);
break;
}
case CalpontSystemCatalog::DATE:
case CalpontSystemCatalog::DATETIME:
case CalpontSystemCatalog::TIME:
@@ -442,6 +479,12 @@ bool EqualCompData::operator()(Row::Pointer a, Row::Pointer b)
break;
}
case CalpontSystemCatalog::LONGDOUBLE:
{
eq = (fRow1.getLongDoubleField(*i) == fRow2.getLongDoubleField(*i));
break;
}
default:
{
eq = false;
@@ -463,7 +506,6 @@ uint64_t IdbOrderBy::Hasher::operator()(const Row::Pointer& p) const
row.setPointer(p);
// MCOL-1829 Row::h uses colcount as an array idx down a callstack.
uint64_t ret = row.hash();
//cout << "hash(): returning " << ret << " for row: " << row.toString() << endl;
return ret;
}
@@ -472,11 +514,8 @@ bool IdbOrderBy::Eq::operator()(const Row::Pointer& d1, const Row::Pointer& d2)
Row& r1 = ts->row1, &r2 = ts->row2;
r1.setPointer(d1);
r2.setPointer(d2);
// MCOL-1829 Row::equals uses 2nd argument as container size boundary
// so it must be column count - 1.
bool ret = r1.equals(r2, colCount - 1);
//cout << "equals(): returning " << (int) ret << " for r1: " << r1.toString() << " r2: " << r2.toString()
// << endl;
// MCOL-1829 Row::equals uses 2nd argument as key columns container size boundary
bool ret = r1.equals(r2, colCount);
return ret;
}

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (c) 2019 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -119,6 +120,14 @@ public:
int operator()(IdbCompare*, rowgroup::Row::Pointer, rowgroup::Row::Pointer);
};
class LongDoubleCompare : public Compare
{
public:
LongDoubleCompare(const IdbSortSpec& spec) : Compare(spec) {}
int operator()(IdbCompare*, rowgroup::Row::Pointer, rowgroup::Row::Pointer);
};
class FloatCompare : public Compare
{

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (c) 2019 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -90,6 +91,12 @@ boost::shared_ptr<WindowFunctionType> WF_lead_lag<T>::makeFunction(int id, const
break;
}
case CalpontSystemCatalog::LONGDOUBLE:
{
func.reset(new WF_lead_lag<long double>(id, name));
break;
}
case CalpontSystemCatalog::FLOAT:
case CalpontSystemCatalog::UFLOAT:
{

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (c) 2019 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -96,6 +97,12 @@ boost::shared_ptr<WindowFunctionType> WF_min_max<T>::makeFunction(int id, const
break;
}
case CalpontSystemCatalog::LONGDOUBLE:
{
func.reset(new WF_min_max<long double>(id, name));
break;
}
default:
{
func.reset(new WF_min_max<string>(id, name));

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (c) 2019 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -97,6 +98,12 @@ boost::shared_ptr<WindowFunctionType> WF_nth_value<T>::makeFunction(int id, cons
break;
}
case CalpontSystemCatalog::LONGDOUBLE:
{
func.reset(new WF_nth_value<long double>(id, name));
break;
}
default:
{
func.reset(new WF_nth_value<string>(id, name));

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (c) 2019 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -102,6 +103,12 @@ boost::shared_ptr<WindowFunctionType> WF_percentile<T>::makeFunction(int id, con
break;
}
case CalpontSystemCatalog::LONGDOUBLE:
{
func.reset(new WF_percentile<long double>(id, name));
break;
}
default:
{
if (id == WF__PERCENTILE_DISC)
@@ -145,6 +152,12 @@ boost::shared_ptr<WindowFunctionType> WF_percentile<T>::makeFunction(int id, con
break;
}
case CalpontSystemCatalog::LONGDOUBLE:
{
func.reset(new WF_percentile<long double>(id, name));
break;
}
default:
{
string errStr = name + "(" + colType2String[ct] + ")";

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (c) 2019 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -96,6 +97,12 @@ boost::shared_ptr<WindowFunctionType> WF_stats<T>::makeFunction(int id, const st
break;
}
case CalpontSystemCatalog::LONGDOUBLE:
{
func.reset(new WF_stats<long double>(id, name));
break;
}
default:
{
string errStr = name + "(" + colType2String[ct] + ")";

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (c) 2019 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -49,10 +50,10 @@ using namespace joblist;
#include "wf_sum_avg.h"
#if 0
namespace
{
template<typename T>
void checkSumLimit(T sum, T val)
{
@@ -102,14 +103,12 @@ void checkSumLimit<uint64_t>(uint64_t sum, uint64_t val)
}
template<typename T>
T calculateAvg(T sum, uint64_t count, int s)
template<>
long double calculateAvg(long double sum, uint64_t count, int s)
{
T avg = ((long double) sum) / count;
return avg;
return sum / count;
}
long double avgWithLimit(long double sum, uint64_t count, int scale, long double u, long double l)
{
long double factor = pow(10.0, scale);
@@ -149,8 +148,8 @@ uint64_t calculateAvg<uint64_t>(uint64_t sum, uint64_t count, int scale)
return t;
}
}
#endif
namespace windowfunction
{
@@ -159,7 +158,6 @@ template<typename T>
boost::shared_ptr<WindowFunctionType> WF_sum_avg<T>::makeFunction(int id, const string& name, int ct)
{
boost::shared_ptr<WindowFunctionType> func;
switch (ct)
{
case CalpontSystemCatalog::TINYINT:
@@ -198,6 +196,11 @@ boost::shared_ptr<WindowFunctionType> WF_sum_avg<T>::makeFunction(int id, const
break;
}
case CalpontSystemCatalog::LONGDOUBLE:
{
func.reset(new WF_sum_avg<long double>(id, name));
break;
}
default:
{
string errStr = name + "(" + colType2String[ct] + ")";
@@ -248,7 +251,7 @@ void WF_sum_avg<T>::operator()(int64_t b, int64_t e, int64_t c)
e = c;
uint64_t colIn = fFieldIndex[1];
int scale = fRow.getScale(colOut) - fRow.getScale(colIn);
double scale = fRow.getScale(colIn);
for (int64_t i = b; i <= e; i++)
{
@@ -262,11 +265,16 @@ void WF_sum_avg<T>::operator()(int64_t b, int64_t e, int64_t c)
T valIn;
getValue(colIn, valIn);
checkSumLimit(fSum, valIn);
// checkSumLimit(fSum, valIn);
if ((!fDistinct) || (fSet.find(valIn) == fSet.end()))
{
fSum += valIn;
long double val = valIn;
if (scale)
{
val /= pow(10.0, scale);
}
fSum += val;
fCount++;
if (fDistinct)
@@ -275,10 +283,12 @@ void WF_sum_avg<T>::operator()(int64_t b, int64_t e, int64_t c)
}
if ((fCount > 0) && (fFunctionId == WF__AVG || fFunctionId == WF__AVG_DISTINCT))
fAvg = (T) calculateAvg(fSum, fCount, scale);
{
fAvg = fSum / fCount;
}
}
T* v = NULL;
long double* v = NULL;
if (fCount > 0)
{

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (c) 2019 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -47,8 +48,8 @@ public:
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
protected:
T fAvg;
T fSum;
long double fAvg;
long double fSum;
uint64_t fCount;
bool fDistinct;
std::set<T> fSet;

View File

@@ -1,5 +1,5 @@
/************************************************************************************
Copyright (C) 2017 MariaDB Corporation AB
Copyright (c) 2019 MariaDB Corporation
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -398,6 +398,48 @@ bool WF_udaf::dropValues(int64_t b, int64_t e)
break;
}
case CalpontSystemCatalog::LONGDOUBLE:
{
double valIn;
if (cc)
{
valIn = cc->getLongDoubleVal(fRow, isNull);
}
else
{
getValue(colIn, valIn);
}
// Check for distinct, if turned on.
// Currently, distinct only works on the first parameter.
if (k == 0)
{
if (fDistinct)
{
DistinctMap::iterator distinct;
distinct = fDistinctMap.find(valIn);
if (distinct != fDistinctMap.end())
{
// This is a duplicate: decrement the count
--(*distinct).second;
if ((*distinct).second > 0) // still more of these
{
bSkipIt = true;
continue;
}
else
{
fDistinctMap.erase(distinct);
}
}
}
}
datum.columnData = valIn;
break;
}
case CalpontSystemCatalog::CHAR:
case CalpontSystemCatalog::VARCHAR:
case CalpontSystemCatalog::VARBINARY:
@@ -515,6 +557,7 @@ void WF_udaf::SetUDAFValue(static_any::any& valOut, int64_t colOut,
uint64_t uintOut = 0;
float floatOut = 0.0;
double doubleOut = 0.0;
long double longdoubleOut = 0.0;
ostringstream oss;
std::string strOut;
@@ -588,12 +631,14 @@ void WF_udaf::SetUDAFValue(static_any::any& valOut, int64_t colOut,
{
floatOut = valOut.cast<float>();
doubleOut = floatOut;
longdoubleOut = floatOut;
intOut = uintOut = floatOut;
oss << floatOut;
}
else if (valOut.compatible(doubleTypeId))
{
doubleOut = valOut.cast<double>();
longdoubleOut = doubleOut;
floatOut = (float)doubleOut;
uintOut = (uint64_t)doubleOut;
intOut = (int64_t)doubleOut;
@@ -607,6 +652,7 @@ void WF_udaf::SetUDAFValue(static_any::any& valOut, int64_t colOut,
intOut = atol(strOut.c_str());
uintOut = strtoul(strOut.c_str(), NULL, 10);
doubleOut = strtod(strOut.c_str(), NULL);
longdoubleOut = doubleOut;
floatOut = (float)doubleOut;
}
else
@@ -676,6 +722,17 @@ void WF_udaf::SetUDAFValue(static_any::any& valOut, int64_t colOut,
}
break;
case execplan::CalpontSystemCatalog::LONGDOUBLE:
if (valOut.empty())
{
setValue(colDataType, b, e, c, (long double*)NULL);
}
else
{
setValue(colDataType, b, e, c, &longdoubleOut);
}
break;
case execplan::CalpontSystemCatalog::CHAR:
case execplan::CalpontSystemCatalog::VARCHAR:
case execplan::CalpontSystemCatalog::TEXT:
@@ -971,6 +1028,38 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
break;
}
case CalpontSystemCatalog::LONGDOUBLE:
{
long double valIn;
if (cc)
{
valIn = cc->getLongDoubleVal(fRow, isNull);
}
else
{
getValue(colIn, valIn);
}
// Check for distinct, if turned on.
// Currently, distinct only works on the first parameter.
if (k == 0 && fDistinct)
{
std::pair<static_any::any, uint64_t> val = make_pair(valIn, 1);
std::pair<DistinctMap::iterator, bool> distinct;
distinct = fDistinctMap.insert(val);
if (distinct.second == false)
{
++(*distinct.first).second;
bSkipIt = true;
continue;
}
}
datum.columnData = valIn;
break;
}
case CalpontSystemCatalog::CHAR:
case CalpontSystemCatalog::VARCHAR:
case CalpontSystemCatalog::VARBINARY:

View File

@@ -1,6 +1,6 @@
/*
Copyright (c) 2017, MariaDB
Copyright (C) 2014 InfiniDB, Inc.
Copyright (c) 2019 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -290,6 +290,16 @@ template<> void WindowFunctionType::getValue<float>(uint64_t i, float& t, CDT* c
}
}
template<> void WindowFunctionType::getValue<long double>(uint64_t i, long double& t, CDT* cdt)
{
t = fRow.getLongDoubleField(i);
if (cdt)
{
*cdt = execplan::CalpontSystemCatalog::LONGDOUBLE;
}
}
template<> void WindowFunctionType::getValue<string>(uint64_t i, string& t, CDT* cdt)
{
t = fRow.getStringField(i);
@@ -320,6 +330,11 @@ template<> void WindowFunctionType::setValue<float>(uint64_t i, float& t)
fRow.setFloatField(t, i);
}
template<> void WindowFunctionType::setValue<long double>(uint64_t i, long double& t)
{
fRow.setLongDoubleField(t, i);
}
template<> void WindowFunctionType::setValue<string>(uint64_t i, string& t)
{
fRow.setStringField(t, i);
@@ -406,6 +421,14 @@ void WindowFunctionType::setValue(int ct, int64_t b, int64_t e, int64_t c, T* v)
setValue(i, fv);
break;
}
case CalpontSystemCatalog::LONGDOUBLE:
{
long double dv = *v;
setValue(i, dv);
break;
}
default:
{
setValue(i, *v);
@@ -480,6 +503,16 @@ void WindowFunctionType::implicit2T(uint64_t i, T& t, int s)
break;
}
case CalpontSystemCatalog::LONGDOUBLE:
{
if (s == 0)
t = (T) fRow.getLongDoubleField(i);
else
t = (T) (fRow.getLongDoubleField(i) * IDB_pow[s]); // s is scale, [0, 18]
break;
}
case CalpontSystemCatalog::CHAR:
case CalpontSystemCatalog::VARCHAR:
default:
@@ -523,6 +556,12 @@ void WindowFunctionType::getConstValue<double>(ConstantColumn* cc, double& t, bo
t = cc->getDoubleVal(fRow, b);
}
template<>
void WindowFunctionType::getConstValue<long double>(ConstantColumn* cc, long double& t, bool& b)
{
t = cc->getLongDoubleVal(fRow, b);
}
template<>
void WindowFunctionType::getConstValue<float>(ConstantColumn* cc, float& t, bool& b)
{
@@ -539,11 +578,13 @@ template void WindowFunctionType::implicit2T<int64_t>(uint64_t, int64_t&, int);
template void WindowFunctionType::implicit2T<uint64_t>(uint64_t, uint64_t&, int);
template void WindowFunctionType::implicit2T<float>(uint64_t, float&, int);
template void WindowFunctionType::implicit2T<double>(uint64_t, double&, int);
template void WindowFunctionType::implicit2T<long double>(uint64_t, long double&, int);
template void WindowFunctionType::setValue<int64_t>(int, int64_t, int64_t, int64_t, int64_t*);
template void WindowFunctionType::setValue<uint64_t>(int, int64_t, int64_t, int64_t, uint64_t*);
template void WindowFunctionType::setValue<float>(int, int64_t, int64_t, int64_t, float*);
template void WindowFunctionType::setValue<double>(int, int64_t, int64_t, int64_t, double*);
template void WindowFunctionType::setValue<long double>(int, int64_t, int64_t, int64_t, long double*);
void* WindowFunctionType::getNullValueByType(int ct, int pos)
{
@@ -557,6 +598,7 @@ void* WindowFunctionType::getNullValueByType(int ct, int pos)
static uint64_t utinyIntNull = joblist::UTINYINTNULL;
static uint64_t floatNull = joblist::FLOATNULL;
static uint64_t doubleNull = joblist::DOUBLENULL;
static long double longDoubleNull= joblist::LONGDOUBLENULL;
static uint64_t dateNull = joblist::DATENULL;
static uint64_t datetimeNull = joblist::DATETIMENULL;
static uint64_t timeNull = joblist::TIMENULL;
@@ -691,6 +733,9 @@ void* WindowFunctionType::getNullValueByType(int ct, int pos)
break;
case CalpontSystemCatalog::LONGDOUBLE:
v = &longDoubleNull;
break;
case CalpontSystemCatalog::VARBINARY:
default:
std::ostringstream oss;

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (c) 2019 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -223,6 +224,10 @@ protected:
{
return fRow.getDoubleField(i);
}
long double getLongDoubleValue(uint64_t i)
{
return fRow.getLongDoubleField(i);
}
void setIntValue(int64_t i, int64_t v)
{
fRow.setIntField(v, i);
@@ -231,7 +236,10 @@ protected:
{
fRow.setDoubleField(v, i);
}
void setLongDoubleValue(int64_t i, long double v)
{
fRow.setLongDoubleField(v, i);
}
// for string table
rowgroup::Row::Pointer getPointer(joblist::RowPosition& r)