1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-05 16:15:50 +03:00

Merge branch 'develop' into mcol-1607

This commit is contained in:
Patrick LeBlanc
2018-11-27 09:12:18 -06:00
66 changed files with 6901 additions and 7282 deletions

4
README
View File

@@ -1,9 +1,9 @@
This is MariaDB ColumnStore 1.2
MariaDB ColumnStore 1.2 is the development version of MariaDB ColumnStore.
MariaDB ColumnStore 1.2 is the GA version of MariaDB ColumnStore.
It is built by porting InfiniDB 4.6.7 on MariaDB 10.2 and adding entirely
new features not found anywhere else.
MariaDB ColumnStore 1.2 is a pre-release.
MariaDB ColumnStore 1.2 is a GA.
Additional features will be pushed in future releases.
A few things to notice:

View File

@@ -1,10 +1,10 @@
# MariaDB ColumnStore Storage/Execution engine 1.2
MariaDB ColumnStore 1.2 is the development version of MariaDB ColumnStore.
MariaDB ColumnStore 1.2 is the GA version of MariaDB ColumnStore.
It is built by porting InfiniDB 4.6.7 on MariaDB 10.2 and adding entirely
new features not found anywhere else.
# MariaDB ColumnStore 1.2 is a pre-release.
# MariaDB ColumnStore 1.2 is a GA release.
- Do not use pre-releases on production systems.

View File

@@ -233,7 +233,8 @@ WindowFunctionColumn::WindowFunctionColumn( const WindowFunctionColumn& rhs, con
fFunctionName(rhs.functionName()),
fFunctionParms(rhs.functionParms()),
fPartitions (rhs.partitions()),
fOrderBy (rhs.orderBy())
fOrderBy (rhs.orderBy()),
udafContext(rhs.getUDAFContext())
{}
const string WindowFunctionColumn::toString() const

View File

@@ -140,6 +140,10 @@ public:
{
return udafContext;
}
const mcsv1sdk::mcsv1Context& getUDAFContext() const
{
return udafContext;
}
private:
/**

View File

@@ -1161,9 +1161,9 @@ void check_walk(const Item* item, void* arg)
{
case Item::FUNC_ITEM:
{
Item_func* ifp = (Item_func*)item;
const Item_func* ifp = static_cast<const Item_func*>(item);
if ( ifp->functype() != Item_func::EQ_FUNC )
if ( ifp->functype() != Item_func::EQ_FUNC ) // NON-equi JOIN
{
if ( ifp->argument_count() == 2 &&
ifp->arguments()[0]->type() == Item::FIELD_ITEM &&
@@ -1178,11 +1178,36 @@ void check_walk(const Item* item, void* arg)
return;
}
}
else // IN + correlated subquery
{
if ( ifp->functype() == Item_func::NOT_FUNC
&& ifp->arguments()[0]->type() == Item::EXPR_CACHE_ITEM )
{
check_walk(ifp->arguments()[0], arg);
}
}
}
break;
}
case Item::COND_ITEM:
case Item::EXPR_CACHE_ITEM: // IN + correlated subquery
{
const Item_cache_wrapper* icw = static_cast<const Item_cache_wrapper*>(item);
if ( icw->get_orig_item()->type() == Item::FUNC_ITEM )
{
const Item_func *ifp = static_cast<const Item_func*>(icw->get_orig_item());
if ( ifp->argument_count() == 2 &&
( ifp->arguments()[0]->type() == Item::Item::SUBSELECT_ITEM
|| ifp->arguments()[1]->type() == Item::Item::SUBSELECT_ITEM ))
{
*unsupported_feature = true;
return;
}
}
break;
}
case Item::COND_ITEM: // OR in cods is unsupported yet
{
Item_cond* icp = (Item_cond*)item;
if ( is_cond_or(icp) )
@@ -1198,8 +1223,6 @@ void check_walk(const Item* item, void* arg)
}
}
#include <iostream>
/*@brief create_calpont_group_by_handler- Creates handler*/
/***********************************************************
* DESCRIPTION:
@@ -1221,24 +1244,25 @@ static group_by_handler*
create_calpont_group_by_handler(THD* thd, Query* query)
{
ha_calpont_group_by_handler* handler = NULL;
LEX* lex = thd->lex;
SELECT_LEX *select_lex = &lex->select_lex;
// same as thd->lex->current_select
SELECT_LEX *select_lex = query->from->select_lex;
// Create a handler if query is valid. See comments for details.
if ( thd->infinidb_vtable.vtable_state == THD::INFINIDB_DISABLE_VTABLE
&& ( thd->variables.infinidb_vtable_mode == 0
|| thd->variables.infinidb_vtable_mode == 2 )
&& ( query->group_by || thd->lex->select_lex.with_sum_func ) )
&& ( query->group_by || select_lex->with_sum_func ) )
{
bool unsupported_feature = false;
// Impossible HAVING or WHERE
if ( ( select_lex->having && select_lex->having_value == Item::COND_FALSE )
|| ( select_lex->cond_value && select_lex->cond_value == Item::COND_FALSE ) )
if ( ( query->having && select_lex->having_value == Item::COND_FALSE )
|| ( select_lex->cond_count > 0
&& select_lex->cond_value == Item::COND_FALSE ) )
{
unsupported_feature = true;
}
// Unsupported JOIN conditions check.
// Unsupported conditions check.
if ( !unsupported_feature )
{
JOIN *join = select_lex->join;
@@ -1248,7 +1272,7 @@ create_calpont_group_by_handler(THD* thd, Query* query)
icp = reinterpret_cast<Item_cond*>(join->conds);
if ( unsupported_feature == false
&& join->table_count > 1 && icp )
&& icp )
{
icp->traverse_cond(check_walk, &unsupported_feature, Item::POSTFIX);
}
@@ -1265,8 +1289,6 @@ create_calpont_group_by_handler(THD* thd, Query* query)
}
}
std::cerr << "create_calpont_group_by_handler handler " << handler << std::endl;
return handler;
}

View File

@@ -3813,7 +3813,7 @@ FunctionColumn* buildCaseFunction(Item_func* item, gp_walk_info& gwi, bool& nonS
FuncExp* funcexp = FuncExp::instance();
string funcName = "case_simple";
if (strcasecmp(((Item_func_case*)item)->case_type(), "searched") == 0)
if (item->functype() == Item_func::CASE_SEARCHED_FUNC)
{
funcName = "case_searched";
}
@@ -3857,7 +3857,7 @@ FunctionColumn* buildCaseFunction(Item_func* item, gp_walk_info& gwi, bool& nonS
// some cpu cycles trying to build a ReturnedColumn as below.
// Every even numbered arg is a WHEN. In between are the THEN.
// An odd number of args indicates an ELSE residing in the last spot.
if (funcName == "case_searched" &&
if ((item->functype() == Item_func::CASE_SEARCHED_FUNC) &&
(i < arg_offset))
{
// MCOL-1472 Nested CASE with an ISNULL predicate. We don't want the predicate
@@ -8248,13 +8248,11 @@ int cp_get_table_plan(THD* thd, SCSEP& csep, cal_table_info& ti)
int cp_get_group_plan(THD* thd, SCSEP& csep, cal_impl_if::cal_group_info& gi)
{
LEX* lex = thd->lex;
idbassert(lex != 0);
SELECT_LEX select_lex = lex->select_lex;
SELECT_LEX *select_lex = gi.groupByTables->select_lex;
gp_walk_info gwi;
gwi.thd = thd;
int status = getGroupPlan(gwi, select_lex, csep, gi);
int status = getGroupPlan(gwi, *select_lex, csep, gi);
#ifdef DEBUG_WALK_COND
cerr << "---------------- cp_get_group_plan EXECUTION PLAN ----------------" << endl;

View File

@@ -4,12 +4,9 @@
<Project File="tools/configMgt/autoConfigure.vpj"/>
<Project File="utils/batchloader/batchloader.vpj"/>
<Project File="primitives/blockcache/blockcache.vpj"/>
<Project File="utils/boost_idb/boost_idb.vpj"/>
<Project File="versioning/BRM/brm.vpj"/>
<Project File="writeengine/bulk/bulk.vpj"/>
<Project File="utils/cacheutils/cacheutils.vpj"/>
<Project File="oamapps/calpont-console/calpontConsole.vpj"/>
<Project File="oamapps/calpontDB/calpontDBWrite.vpj"/>
<Project File="tools/dbloadxml/colxml.vpj"/>
<Project File="utils/common/common.vpj"/>
<Project File="utils/compress/compress.vpj"/>

View File

@@ -427,12 +427,9 @@
</DBRM_Worker10>
<DBBC>
<!-- The percentage of RAM to use for the disk block cache. Defaults to 70% -->
<!-- Alternatively, this can be specified in absolute terms using
the suffixes 'm' or 'g' to denote size in megabytes or gigabytes.-->
<!-- <NumBlocksPct>70</NumBlocksPct> -->
<!-- If preferred, the user can specify cache size in terms of megabytes.
If both Pct and MB are specified, PrimProc will use Pct. -->
<!-- <NumBlocksInMB>2048</NumBlocksInMB> -->
<!-- <NumThreads>16</NumThreads> --> <!-- 1-256. Default is 16. -->
<NumCaches>1</NumCaches><!-- # of parallel caches to instantiate -->
<IOMTracing>0</IOMTracing>

View File

@@ -419,12 +419,9 @@
</DBRM_Worker10>
<DBBC>
<!-- The percentage of RAM to use for the disk block cache. Defaults to 70% -->
<!-- Alternatively, this can be specified in absolute terms using
the suffixes 'm' or 'g' to denote size in megabytes or gigabytes.-->
<NumBlocksPct>50</NumBlocksPct>
<!-- If preferred, the user can specify cache size in terms of megabytes.
If both Pct and MB are specified, PrimProc will use Pct. -->
<!-- <NumBlocksInMB>2048</NumBlocksInMB> -->
<!-- <NumThreads>16</NumThreads> --> <!-- 1-256. Default is 16. -->
<NumCaches>1</NumCaches><!-- # of parallel caches to instantiate -->
<IOMTracing>0</IOMTracing>

View File

@@ -4,7 +4,7 @@ alias mcsmysql='/usr/local/mariadb/columnstore/mysql/bin/mysql --defaults-extra-
alias ma=/usr/local/mariadb/columnstore/bin/mcsadmin
alias mcsadmin=/usr/local/mariadb/columnstore/bin/mcsadmin
alias cpimport=/usr/local/mariadb/columnstore/bin/cpimport
alias home='cd /usr/local/mariadb/columnstore'
alias mcshome='cd /usr/local/mariadb/columnstore'
alias log='cd /var/log/mariadb/columnstore/'
alias core='cd /var/log/mariadb/columnstore/corefiles'
alias tmsg='tail -f /var/log/messages'
@@ -14,4 +14,4 @@ alias terror='tail -f /var/log/mariadb/columnstore/err.log'
alias twarning='tail -f /var/log/mariadb/columnstore/warning.log'
alias tcrit='tail -f /var/log/mariadb/columnstore/crit.log'
alias dbrm='cd /usr/local/mariadb/columnstore/data1/systemFiles/dbrm'
alias module='cat /usr/local/mariadb/columnstore/local/module'
alias mcsmodule='cat /usr/local/mariadb/columnstore/local/module'

View File

@@ -315,14 +315,6 @@ if [ -z "aws" ]; then
$installdir/bin/MCSgetCredentials.sh >/dev/null 2>&1
fi
#log install message
test -f $installdir/post/functions && . $installdir/post/functions
if [ $user = "root" ]; then
$installdir/bin/cplogger -i 19 "***** MariaDB Columnstore Installed *****"
else
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$installdir/lib $installdir/bin/cplogger -i 19 "***** MariaDB Columnstore Installed *****"
fi
#setup hadoop
hadoop=`which hadoop 2>/dev/null`
if [ -z "$hadoop" ]; then

View File

@@ -11,12 +11,26 @@ prefix=/usr/local
installdir=$prefix/mariadb/columnstore
syslog_conf=nofile
rsyslog7=0
non_root_user=no
user=`whoami 2>/dev/null`
#set default names
groupname=adm
username=syslog
# determine username/groupname
if [ -f /var/log/messages ]; then
username=`stat -c "%U %G" /var/log/messages | awk '{print $1}'`
groupname=`stat -c "%U %G" /var/log/messages | awk '{print $2}'`
fi
if [ -f /var/log/syslog ]; then
username=`stat -c "%U %G" /var/log/syslog | awk '{print $1}'`
groupname=`stat -c "%U %G" /var/log/syslog | awk '{print $2}'`
fi
for arg in "$@"; do
if [ `expr -- "$arg" : '--prefix='` -eq 9 ]; then
prefix="`echo $arg | awk -F= '{print $2}'`"
@@ -28,6 +42,7 @@ for arg in "$@"; do
user="`echo $arg | awk -F= '{print $2}'`"
groupname=$user
username=$user
non_root_user=yes
elif [ `expr -- "$arg" : '--..*'` -ge 3 ]; then
echo "ignoring unknown argument: $arg" 1>&2
elif [ `expr -- "$arg" : '--'` -eq 2 ]; then
@@ -157,12 +172,17 @@ fi
}
makeDir() {
test -d /var/log/mariadb/columnstore || mkdir -p /var/log/mariadb/columnstore >/dev/null 2>&1
if [ ! -d /var/log/mariadb/columnstore ]; then
mkdir -p /var/log/mariadb/columnstore >/dev/null 2>&1
test -d /var/log/mariadb/columnstore/archive || mkdir /var/log/mariadb/columnstore/archive >/dev/null 2>&1
test -d /var/log/mariadb/columnstore/corefiles || mkdir /var/log/mariadb/columnstore/corefiles >/dev/null 2>&1
test -d /var/log/mariadb/columnstore/trace || mkdir /var/log/mariadb/columnstore/trace >/dev/null 2>&1
chmod 777 -R /var/log/mariadb/columnstore
chown $user:$user -R /var/log/mariadb
chown $username:$groupname -R /var/log/mariadb
else
test -d /var/log/mariadb/columnstore/archive || mkdir /var/log/mariadb/columnstore/archive >/dev/null 2>&1
test -d /var/log/mariadb/columnstore/corefiles || mkdir /var/log/mariadb/columnstore/corefiles >/dev/null 2>&1
test -d /var/log/mariadb/columnstore/trace || mkdir /var/log/mariadb/columnstore/trace >/dev/null 2>&1
fi
}
install() {
@@ -170,15 +190,15 @@ makeDir
checkSyslog
if [ ! -z "$syslog_conf" ] ; then
$installdir/bin/setConfig -d Installation SystemLogConfigFile ${syslog_conf} >/dev/null 2>&1
if [ $user != "root" ]; then
chown $user:$user /home/$user/mariadb/columnstore/etc/*
if [ $non_root_user == "yes" ]; then
chown $user:$user $installdir/etc/Columnstore.xml*
fi
rm -f ${syslog_conf}.columnstoreSave
if [ "$syslog_conf" == /etc/rsyslog.d/columnstore.conf ] ||
[ "$syslog_conf" == /etc/rsyslog.d/49-columnstore.conf ]; then
i=1
else
rm -f ${syslog_conf}.columnstoreSave
cp ${syslog_conf} ${syslog_conf}.columnstoreSave >/dev/null 2>&1
sed -i '/# MariaDB/,$d' ${syslog_conf}.columnstoreSave > /dev/null 2>&1
fi
@@ -189,37 +209,47 @@ if [ ! -z "$syslog_conf" ] ; then
# remove older version incase it was installed by previous build
rm -rf /etc/rsyslog.d/columnstore.conf
# determine username/groupname
if [ -f /var/log/messages ]; then
user=`stat -c "%U %G" /var/log/messages | awk '{print $1}'`
group=`stat -c "%U %G" /var/log/messages | awk '{print $2}'`
fi
if [ -f /var/log/syslog ]; then
user=`stat -c "%U %G" /var/log/syslog | awk '{print $1}'`
group=`stat -c "%U %G" /var/log/syslog | awk '{print $2}'`
fi
# set permissions
chown $user:$group -R /var/log/mariadb > /dev/null 2>&1
if [ $rsyslog7 == 1 ]; then
rm -f /etc/rsyslog.d/49-columnstore.conf
cp ${columnstoreSyslogFile7} ${syslog_conf}
sed -i -e s/groupname/$groupname/g ${syslog_conf}
sed -i -e s/username/$username/g ${syslog_conf}
chmod 644 ${syslog_conf}
else
cp ${columnstoreSyslogFile} ${syslog_conf}
fi
fi
restartSyslog
# install Columnstore Log Rotate File
if [ -d /etc/logrotate.d ]; then
cp $installdir/bin/columnstoreLogRotate /etc/logrotate.d/columnstore > /dev/null 2>&1
chmod 644 /etc/logrotate.d/columnstore
restartSyslog
#do the logrotate to start with a fresh log file during install
logrotate -f /etc/logrotate.d/columnstore > /dev/null 2>&1
fi
#log install message and find the least permission that allows logging to work
CHMOD_LIST=("750" "770" "775" "777")
for CHMOD in "${CHMOD_LIST[@]}"; do
chmod $CHMOD /var/log/mariadb
chmod $CHMOD /var/log/mariadb/columnstore
chmod $CHMOD /var/log/mariadb/columnstore/archive
chmod $CHMOD /var/log/mariadb/columnstore/corefiles
chmod $CHMOD /var/log/mariadb/columnstore/trace
test -f $installdir/post/functions && . $installdir/post/functions
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$installdir/lib $installdir/bin/cplogger -i 19 "***** MariaDB Columnstore Installed *****"
if [ -f /var/log/mariadb/columnstore/info.log ]; then
if [ -s /var/log/mariadb/columnstore/info.log ]; then
exit 0
fi
fi
done
fi
}
@@ -233,7 +263,7 @@ if [ ! -z "$syslog_conf" ] ; then
if [ $? -eq 0 ]; then
if [ -f ${syslog_conf}.columnstoreSave ] ; then
#uninstall the syslog for ColumnStore logging
v -f ${syslog_conf} ${syslog_conf}.ColumnStoreBackup
mv -f ${syslog_conf} ${syslog_conf}.ColumnStoreBackup
mv -f ${syslog_conf}.columnstoreSave ${syslog_conf} >/dev/null 2>&1
if [ ! -f ${syslog_conf} ] ; then
cp ${syslog_conf}.ColumnStoreBackup ${syslog_conf}
@@ -252,7 +282,6 @@ if [ ! -z "$syslog_conf" ] ; then
rm -f /etc/logrotate.d/columnstore
restartSyslog
fi
}

View File

@@ -54,6 +54,7 @@
using namespace std;
using namespace oam;
/* MCOL-1844. On an upgrade, the user may have customized options in their old
* myCnf-include-args.text file. Merge it with the packaged version, and then process as we
* have before.
@@ -218,7 +219,7 @@ int main(int argc, char* argv[])
ofstream newFile (mycnfFile.c_str());
//create new file
int fd = open(mycnfFile.c_str(), O_RDWR | O_CREAT, 0666);
int fd = open(mycnfFile.c_str(), O_RDWR|O_CREAT, 0644);
copy(lines.begin(), lines.end(), ostream_iterator<string>(newFile, "\n"));
newFile.close();

View File

@@ -391,7 +391,7 @@ int main(int argc, char* argv[])
int serverQueueSize = 10;
int processorWeight = 8 * 1024;
int processorQueueSize = 10 * 1024;
int BRPBlocksPct = 70;
int64_t BRPBlocksPct = 70;
uint32_t BRPBlocks = 1887437;
int BRPThreads = 16;
int cacheCount = 1;
@@ -503,16 +503,10 @@ int main(int argc, char* argv[])
}
string strBlockPct = cf->getConfig(dbbc, "NumBlocksPct");
string strBlockAbs = cf->getConfig(dbbc, "NumBlocksInMB");
bool usePct = !(strBlockPct.empty()); // which to use. Prefer Pct if both are specified.
if (usePct)
temp = atoi(strBlockPct.c_str());
else
temp = atoi(strBlockAbs.c_str());
#ifdef _MSC_VER
/* TODO: implement handling for NumBlocksInMB */
/* TODO: implement handling for the 'm' or 'g' chars in NumBlocksPct */
if (temp > 0)
BRPBlocksPct = temp;
@@ -532,19 +526,21 @@ int main(int argc, char* argv[])
}
#else
if (usePct)
{
if (temp > 0)
bool absCache = false;
if (temp > 0) {
BRPBlocksPct = temp;
/* MCOL-1847. Did the user specify this as an absolute? */
int len = strBlockPct.length();
if ((strBlockPct[len-1] >= 'a' && strBlockPct[len-1] <= 'z') ||
(strBlockPct[len-1] >= 'A' && strBlockPct[len-1] <= 'Z')) {
absCache = true;
BRPBlocksPct = Config::fromText(strBlockPct);
}
}
if (absCache)
BRPBlocks = BRPBlocksPct / 8192;
else
BRPBlocks = ((BRPBlocksPct / 100.0) * (double) cg.getTotalMemory()) / 8192;
}
else
{
if (temp > 0)
BRPBlocks = temp * 128; // 128 blocks per MB.
else
BRPBlocks = 131072; // 1GB, why not.
}
#endif
#if 0
temp = toInt(cf->getConfig(dbbc, "NumThreads"));

View File

@@ -9176,7 +9176,11 @@ int ProcessManager::getDBRMData(messageqcpp::IOSocket fIos, std::string moduleNa
char line[200];
oldFile.getline(line, 200);
// MCOL-1558. Handle absolute and relative paths.
if (line[0] == '/')
currentDbrmFile = line;
else
currentDbrmFile = DBRMroot.substr(0, DBRMroot.find_last_of('/') + 1) + line;
}
else
{

View File

@@ -334,7 +334,6 @@ checkSSH()
checkRemoteDir()
{
if [ "$USER" != "root" ]; then
# Non-root User directory permissions check
#
@@ -358,7 +357,6 @@ checkRemoteDir()
pass=false
REPORTPASS=false
fi
done
if ! $pass; then
checkContinue

View File

@@ -97,7 +97,7 @@ string Func_concat_ws::getStrVal(Row& row,
string tmp;
for ( uint32_t i = 1 ; i < parm.size() ; i++)
{
string(stringValue(parm[i], row, isNull).c_str(), tmp);
stringValue(parm[i], row, isNull, tmp);
str += tmp;
if (isNull)

View File

@@ -61,8 +61,8 @@ mcsv1_UDAF::ReturnCode corr::init(mcsv1Context* context,
context->setUserDataSize(sizeof(corr_data));
context->setResultType(CalpontSystemCatalog::DOUBLE);
context->setColWidth(8);
context->setScale(colTypes[0].scale + 8);
context->setPrecision(19);
context->setScale(DECIMAL_NOT_SPECIFIED);
context->setPrecision(0);
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
return mcsv1_UDAF::SUCCESS;

View File

@@ -59,8 +59,8 @@ mcsv1_UDAF::ReturnCode covar_pop::init(mcsv1Context* context,
context->setUserDataSize(sizeof(covar_pop_data));
context->setResultType(CalpontSystemCatalog::DOUBLE);
context->setColWidth(8);
context->setScale(colTypes[0].scale + 8);
context->setPrecision(19);
context->setScale(DECIMAL_NOT_SPECIFIED);
context->setPrecision(0);
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
return mcsv1_UDAF::SUCCESS;

View File

@@ -59,8 +59,8 @@ mcsv1_UDAF::ReturnCode covar_samp::init(mcsv1Context* context,
context->setUserDataSize(sizeof(covar_samp_data));
context->setResultType(CalpontSystemCatalog::DOUBLE);
context->setColWidth(8);
context->setScale(colTypes[0].scale + 8);
context->setPrecision(19);
context->setScale(DECIMAL_NOT_SPECIFIED);
context->setPrecision(0);
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
return mcsv1_UDAF::SUCCESS;
@@ -136,7 +136,7 @@ mcsv1_UDAF::ReturnCode covar_samp::evaluate(mcsv1Context* context, static_any::a
{
struct covar_samp_data* data = (struct covar_samp_data*)context->getUserData()->data;
double N = data->cnt;
if (N > 0)
if (N > 1)
{
double sumx = data->sumx;
double sumy = data->sumy;
@@ -145,6 +145,11 @@ mcsv1_UDAF::ReturnCode covar_samp::evaluate(mcsv1Context* context, static_any::a
double covar_samp = (sumxy - ((sumx * sumy) / N)) / (N - 1);
valOut = covar_samp;
}
else
if (N == 1)
{
valOut = 0;
}
return mcsv1_UDAF::SUCCESS;
}

View File

@@ -60,8 +60,8 @@ mcsv1_UDAF::ReturnCode regr_intercept::init(mcsv1Context* context,
context->setUserDataSize(sizeof(regr_intercept_data));
context->setResultType(CalpontSystemCatalog::DOUBLE);
context->setColWidth(8);
context->setScale(colTypes[0].scale + 8);
context->setPrecision(19);
context->setScale(DECIMAL_NOT_SPECIFIED);
context->setPrecision(0);
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
return mcsv1_UDAF::SUCCESS;
@@ -145,12 +145,11 @@ mcsv1_UDAF::ReturnCode regr_intercept::evaluate(mcsv1Context* context, static_an
double sumy = data->sumy;
double sumx2 = data->sumx2;
double sumxy = data->sumxy;
double slope = 0.0;
double variance = (N * sumx2) - (sumx * sumx);
if (variance != 0)
double numerator = sumy * sumx2 - sumx * sumxy;
double var_pop = (N * sumx2) - (sumx * sumx);
if (var_pop != 0)
{
slope = ((N * sumxy) - (sumx * sumy)) / variance;
valOut = (sumy - (slope * sumx)) / N;
valOut = numerator / var_pop;
}
}
return mcsv1_UDAF::SUCCESS;

View File

@@ -61,8 +61,8 @@ mcsv1_UDAF::ReturnCode regr_r2::init(mcsv1Context* context,
context->setUserDataSize(sizeof(regr_r2_data));
context->setResultType(CalpontSystemCatalog::DOUBLE);
context->setColWidth(8);
context->setScale(colTypes[0].scale + 8);
context->setPrecision(19);
context->setScale(DECIMAL_NOT_SPECIFIED);
context->setPrecision(0);
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
return mcsv1_UDAF::SUCCESS;

View File

@@ -60,8 +60,8 @@ mcsv1_UDAF::ReturnCode regr_slope::init(mcsv1Context* context,
context->setUserDataSize(sizeof(regr_slope_data));
context->setResultType(CalpontSystemCatalog::DOUBLE);
context->setColWidth(8);
context->setScale(colTypes[0].scale + 8);
context->setPrecision(19);
context->setScale(DECIMAL_NOT_SPECIFIED);
context->setPrecision(0);
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
return mcsv1_UDAF::SUCCESS;
@@ -141,14 +141,16 @@ mcsv1_UDAF::ReturnCode regr_slope::evaluate(mcsv1Context* context, static_any::a
double N = data->cnt;
if (N > 0)
{
// COVAR_POP(y, x) / VAR_POP(x)
double sumx = data->sumx;
double sumy = data->sumy;
double sumx2 = data->sumx2;
double sumxy = data->sumxy;
double variance = (N * sumx2) - (sumx * sumx);
if (variance != 0)
double covar_pop = N * sumxy - sumx * sumy;
double var_pop = N * sumx2 - sumx * sumx;
if (var_pop != 0)
{
double slope = ((N * sumxy) - (sumx * sumy)) / variance;
double slope = covar_pop / var_pop;
valOut = slope;
}
}

View File

@@ -58,8 +58,8 @@ mcsv1_UDAF::ReturnCode regr_sxx::init(mcsv1Context* context,
context->setUserDataSize(sizeof(regr_sxx_data));
context->setResultType(CalpontSystemCatalog::DOUBLE);
context->setColWidth(8);
context->setScale(colTypes[0].scale + 8);
context->setPrecision(19);
context->setScale(DECIMAL_NOT_SPECIFIED);
context->setPrecision(0);
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
return mcsv1_UDAF::SUCCESS;

View File

@@ -59,8 +59,8 @@ mcsv1_UDAF::ReturnCode regr_sxy::init(mcsv1Context* context,
context->setUserDataSize(sizeof(regr_sxy_data));
context->setResultType(CalpontSystemCatalog::DOUBLE);
context->setColWidth(8);
context->setScale(colTypes[0].scale + 8);
context->setPrecision(19);
context->setScale(DECIMAL_NOT_SPECIFIED);
context->setPrecision(0);
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
return mcsv1_UDAF::SUCCESS;

View File

@@ -58,8 +58,8 @@ mcsv1_UDAF::ReturnCode regr_syy::init(mcsv1Context* context,
context->setUserDataSize(sizeof(regr_syy_data));
context->setResultType(CalpontSystemCatalog::DOUBLE);
context->setColWidth(8);
context->setScale(colTypes[0].scale + 8);
context->setPrecision(19);
context->setScale(DECIMAL_NOT_SPECIFIED);
context->setPrecision(0);
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
return mcsv1_UDAF::SUCCESS;

View File

@@ -581,12 +581,13 @@ extern "C"
double sumy = data->sumy;
double sumx2 = data->sumx2;
double sumxy = data->sumxy;
double slope = 0;
double variance = (N * sumx2) - (sumx * sumx);
if (variance)
{
double slope = ((N * sumxy) - (sumx * sumy)) / variance;
return (sumy - (slope * sumx)) / N;
slope = ((N * sumxy) - (sumx * sumy)) / variance;
}
return (sumy - (slope * sumx)) / N;
}
*is_null = 1;
return 0;

View File

@@ -1673,11 +1673,10 @@ void RowAggregation::updateEntry(const Row& rowIn)
{
for (uint64_t i = 0; i < fFunctionCols.size(); i++)
{
SP_ROWAGG_FUNC_t pFunctionCol = fFunctionCols[i];
int64_t colIn = pFunctionCol->fInputColumnIndex;
int64_t colOut = pFunctionCol->fOutputColumnIndex;
int64_t colIn = fFunctionCols[i]->fInputColumnIndex;
int64_t colOut = fFunctionCols[i]->fOutputColumnIndex;
switch (pFunctionCol->fAggFunction)
switch (fFunctionCols[i]->fAggFunction)
{
case ROWAGG_COUNT_COL_NAME:
@@ -1691,7 +1690,7 @@ void RowAggregation::updateEntry(const Row& rowIn)
case ROWAGG_MIN:
case ROWAGG_MAX:
case ROWAGG_SUM:
doMinMaxSum(rowIn, colIn, colOut, pFunctionCol->fAggFunction);
doMinMaxSum(rowIn, colIn, colOut, fFunctionCols[i]->fAggFunction);
break;
case ROWAGG_AVG:
@@ -1708,7 +1707,7 @@ void RowAggregation::updateEntry(const Row& rowIn)
case ROWAGG_BIT_OR:
case ROWAGG_BIT_XOR:
{
doBitOp(rowIn, colIn, colOut, pFunctionCol->fAggFunction);
doBitOp(rowIn, colIn, colOut, fFunctionCols[i]->fAggFunction);
break;
}
@@ -1731,7 +1730,7 @@ void RowAggregation::updateEntry(const Row& rowIn)
{
std::ostringstream errmsg;
errmsg << "RowAggregation: function (id = " <<
(uint64_t) pFunctionCol->fAggFunction << ") is not supported.";
(uint64_t) fFunctionCols[i]->fAggFunction << ") is not supported.";
cerr << errmsg.str() << endl;
throw logging::QueryDataExcept(errmsg.str(), logging::aggregateFuncErr);
break;
@@ -2015,7 +2014,6 @@ void RowAggregation::doUDAF(const Row& rowIn, int64_t colIn, int64_t colOut,
for (uint32_t i = 0; i < paramCount; ++i)
{
SP_ROWAGG_FUNC_t pFunctionCol = fFunctionCols[funcColsIdx];
mcsv1sdk::ColumnDatum& datum = valsIn[i];
// Turn on NULL flags based on the data
dataFlags[i] = 0;
@@ -2024,9 +2022,9 @@ void RowAggregation::doUDAF(const Row& rowIn, int64_t colIn, int64_t colOut,
// to acces the constant value rather than a row value.
cc = NULL;
if (pFunctionCol->fpConstCol)
if (fFunctionCols[funcColsIdx]->fpConstCol)
{
cc = dynamic_cast<ConstantColumn*>(pFunctionCol->fpConstCol.get());
cc = dynamic_cast<ConstantColumn*>(fFunctionCols[funcColsIdx]->fpConstCol.get());
}
if ((cc && cc->type() == ConstantColumn::NULLDATA)
@@ -2243,9 +2241,8 @@ void RowAggregation::doUDAF(const Row& rowIn, int64_t colIn, int64_t colOut,
&& fFunctionCols[funcColsIdx + 1]->fAggFunction == ROWAGG_MULTI_PARM)
{
++funcColsIdx;
SP_ROWAGG_FUNC_t pFunctionCol = fFunctionCols[funcColsIdx];
colIn = pFunctionCol->fInputColumnIndex;
colOut = pFunctionCol->fOutputColumnIndex;
colIn = fFunctionCols[funcColsIdx]->fInputColumnIndex;
colOut = fFunctionCols[funcColsIdx]->fOutputColumnIndex;
}
else
{

View File

@@ -69,65 +69,13 @@ mcsv1_UDAF::ReturnCode avg_mode::nextValue(mcsv1Context* context, ColumnDatum* v
{
static_any::any& valIn = valsIn[0].columnData;
MODE_DATA& data = static_cast<ModeData*>(context->getUserData())->mData;
DATATYPE val = 0.0;
if (valIn.empty())
{
return mcsv1_UDAF::SUCCESS; // Ought not happen when UDAF_IGNORE_NULLS is on.
}
if (valIn.compatible(charTypeId))
{
val = valIn.cast<char>();
}
else if (valIn.compatible(scharTypeId))
{
val = valIn.cast<signed char>();
}
else if (valIn.compatible(shortTypeId))
{
val = valIn.cast<short>();
}
else if (valIn.compatible(intTypeId))
{
val = valIn.cast<int>();
}
else if (valIn.compatible(longTypeId))
{
val = valIn.cast<long>();
}
else if (valIn.compatible(llTypeId))
{
val = valIn.cast<long long>();
}
else if (valIn.compatible(ucharTypeId))
{
val = valIn.cast<unsigned char>();
}
else if (valIn.compatible(ushortTypeId))
{
val = valIn.cast<unsigned short>();
}
else if (valIn.compatible(uintTypeId))
{
val = valIn.cast<unsigned int>();
}
else if (valIn.compatible(ulongTypeId))
{
val = valIn.cast<unsigned long>();
}
else if (valIn.compatible(ullTypeId))
{
val = valIn.cast<unsigned long long>();
}
else if (valIn.compatible(floatTypeId))
{
val = valIn.cast<float>();
}
else if (valIn.compatible(doubleTypeId))
{
val = valIn.cast<double>();
}
DATATYPE val = convertAnyTo<double>(valIn);
// For decimal types, we need to move the decimal point.
uint32_t scale = valsIn[0].scale;
@@ -190,65 +138,13 @@ mcsv1_UDAF::ReturnCode avg_mode::dropValue(mcsv1Context* context, ColumnDatum* v
{
static_any::any& valIn = valsDropped[0].columnData;
MODE_DATA& data = static_cast<ModeData*>(context->getUserData())->mData;
DATATYPE val = 0.0;
if (valIn.empty())
{
return mcsv1_UDAF::SUCCESS; // Ought not happen when UDAF_IGNORE_NULLS is on.
}
if (valIn.compatible(charTypeId))
{
val = valIn.cast<char>();
}
else if (valIn.compatible(scharTypeId))
{
val = valIn.cast<signed char>();
}
else if (valIn.compatible(shortTypeId))
{
val = valIn.cast<short>();
}
else if (valIn.compatible(intTypeId))
{
val = valIn.cast<int>();
}
else if (valIn.compatible(longTypeId))
{
val = valIn.cast<long>();
}
else if (valIn.compatible(llTypeId))
{
val = valIn.cast<long long>();
}
else if (valIn.compatible(ucharTypeId))
{
val = valIn.cast<unsigned char>();
}
else if (valIn.compatible(ushortTypeId))
{
val = valIn.cast<unsigned short>();
}
else if (valIn.compatible(uintTypeId))
{
val = valIn.cast<unsigned int>();
}
else if (valIn.compatible(ulongTypeId))
{
val = valIn.cast<unsigned long>();
}
else if (valIn.compatible(ullTypeId))
{
val = valIn.cast<unsigned long long>();
}
else if (valIn.compatible(floatTypeId))
{
val = valIn.cast<float>();
}
else if (valIn.compatible(doubleTypeId))
{
val = valIn.cast<double>();
}
DATATYPE val = convertAnyTo<double>(valIn);
// For decimal types, we need to move the decimal point.
uint32_t scale = valsDropped[0].scale;

View File

@@ -75,69 +75,13 @@ mcsv1_UDAF::ReturnCode avgx::nextValue(mcsv1Context* context, ColumnDatum* valsI
{
static_any::any& valIn_x = valsIn[0].columnData;
struct avgx_data* data = (struct avgx_data*)context->getUserData()->data;
DATATYPE val = 0.0;
if (valIn_x.empty())
{
return mcsv1_UDAF::SUCCESS; // Ought not happen when UDAF_IGNORE_NULLS is on.
}
if (valIn_x.compatible(longTypeId))
{
val = valIn_x.cast<long>();
}
else if (valIn_x.compatible(charTypeId))
{
val = valIn_x.cast<char>();
}
else if (valIn_x.compatible(scharTypeId))
{
val = valIn_x.cast<signed char>();
}
else if (valIn_x.compatible(shortTypeId))
{
val = valIn_x.cast<short>();
}
else if (valIn_x.compatible(intTypeId))
{
val = valIn_x.cast<int>();
}
else if (valIn_x.compatible(longTypeId))
{
val = valIn_x.cast<long>();
}
else if (valIn_x.compatible(llTypeId))
{
val = valIn_x.cast<long long>();
}
else if (valIn_x.compatible(ucharTypeId))
{
val = valIn_x.cast<unsigned char>();
}
else if (valIn_x.compatible(ushortTypeId))
{
val = valIn_x.cast<unsigned short>();
}
else if (valIn_x.compatible(uintTypeId))
{
val = valIn_x.cast<unsigned int>();
}
else if (valIn_x.compatible(ulongTypeId))
{
val = valIn_x.cast<unsigned long>();
}
else if (valIn_x.compatible(ullTypeId))
{
val = valIn_x.cast<unsigned long long>();
}
else if (valIn_x.compatible(floatTypeId))
{
val = valIn_x.cast<float>();
}
else if (valIn_x.compatible(doubleTypeId))
{
val = valIn_x.cast<double>();
}
DATATYPE val = convertAnyTo<double>(valIn_x);
// For decimal types, we need to move the decimal point.
uint32_t scale = valsIn[0].scale;
@@ -183,65 +127,13 @@ mcsv1_UDAF::ReturnCode avgx::dropValue(mcsv1Context* context, ColumnDatum* valsD
{
static_any::any& valIn_x = valsDropped[0].columnData;
struct avgx_data* data = (struct avgx_data*)context->getUserData()->data;
DATATYPE val = 0.0;
if (valIn_x.empty())
{
return mcsv1_UDAF::SUCCESS; // Ought not happen when UDAF_IGNORE_NULLS is on.
}
if (valIn_x.compatible(charTypeId))
{
val = valIn_x.cast<char>();
}
else if (valIn_x.compatible(scharTypeId))
{
val = valIn_x.cast<signed char>();
}
else if (valIn_x.compatible(shortTypeId))
{
val = valIn_x.cast<short>();
}
else if (valIn_x.compatible(intTypeId))
{
val = valIn_x.cast<int>();
}
else if (valIn_x.compatible(longTypeId))
{
val = valIn_x.cast<long>();
}
else if (valIn_x.compatible(llTypeId))
{
val = valIn_x.cast<long long>();
}
else if (valIn_x.compatible(ucharTypeId))
{
val = valIn_x.cast<unsigned char>();
}
else if (valIn_x.compatible(ushortTypeId))
{
val = valIn_x.cast<unsigned short>();
}
else if (valIn_x.compatible(uintTypeId))
{
val = valIn_x.cast<unsigned int>();
}
else if (valIn_x.compatible(ulongTypeId))
{
val = valIn_x.cast<unsigned long>();
}
else if (valIn_x.compatible(ullTypeId))
{
val = valIn_x.cast<unsigned long long>();
}
else if (valIn_x.compatible(floatTypeId))
{
val = valIn_x.cast<float>();
}
else if (valIn_x.compatible(doubleTypeId))
{
val = valIn_x.cast<double>();
}
DATATYPE val = convertAnyTo<double>(valIn_x);
// For decimal types, we need to move the decimal point.
uint32_t scale = valsDropped[0].scale;

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

@@ -124,9 +124,9 @@ nextValue()
nextValue() is called from the PM for aggregate usage and the UM for Analytic usage.
valsIn contains a vector of all the parameters from the function call in the SQL query (In Columndtore 1.1, this will always contain exactly one entry).
valsIn contains a vector of all the parameters from the function call in the SQL query.
Depending on your function, you may wish to be able to handle many different types of input. A good way to handle this is to have a series of if..else..if statements comparing the input type and dealing with each separately. For instace, if you want to handle multiple numeric types, you might use::
Depending on your function, you may wish to be able to handle many different types of input. There's a helper template function convertAnyTo() which will convert the input static:any value to the designated type. For Example, if your internal accumulater is of type double, you might use::
static_any::any& valIn = valsDropped[0].columnData;
AVGData& data = static_cast<MedianData*>(context->getUserData())->mData;
@@ -137,21 +137,7 @@ Depending on your function, you may wish to be able to handle many different typ
return mcsv1_UDAF::SUCCESS; // Ought not happen when UDAF_IGNORE_NULLS is on.
}
if (valIn.compatible(charTypeId))
{
val = valIn.cast<char>();
}
else if (valIn.compatible(scharTypeId))
{
val = valIn.cast<signed char>();
}
else if (valIn.compatible(shortTypeId))
{
val = valIn.cast<short>();
}
.
.
.
val = convertAnyTo<double>(valIn);
Once you've gotten your data in a format you like, then do your aggregation. For AVG, you might see::

View File

@@ -69,65 +69,13 @@ mcsv1_UDAF::ReturnCode median::nextValue(mcsv1Context* context, ColumnDatum* val
{
static_any::any& valIn = valsIn[0].columnData;
MEDIAN_DATA& data = static_cast<MedianData*>(context->getUserData())->mData;
DATATYPE val = 0.0;
if (valIn.empty())
{
return mcsv1_UDAF::SUCCESS; // Ought not happen when UDAF_IGNORE_NULLS is on.
}
if (valIn.compatible(charTypeId))
{
val = valIn.cast<char>();
}
else if (valIn.compatible(scharTypeId))
{
val = valIn.cast<signed char>();
}
else if (valIn.compatible(shortTypeId))
{
val = valIn.cast<short>();
}
else if (valIn.compatible(intTypeId))
{
val = valIn.cast<int>();
}
else if (valIn.compatible(longTypeId))
{
val = valIn.cast<long>();
}
else if (valIn.compatible(llTypeId))
{
val = valIn.cast<long long>();
}
else if (valIn.compatible(ucharTypeId))
{
val = valIn.cast<unsigned char>();
}
else if (valIn.compatible(ushortTypeId))
{
val = valIn.cast<unsigned short>();
}
else if (valIn.compatible(uintTypeId))
{
val = valIn.cast<unsigned int>();
}
else if (valIn.compatible(ulongTypeId))
{
val = valIn.cast<unsigned long>();
}
else if (valIn.compatible(ullTypeId))
{
val = valIn.cast<unsigned long long>();
}
else if (valIn.compatible(floatTypeId))
{
val = valIn.cast<float>();
}
else if (valIn.compatible(doubleTypeId))
{
val = valIn.cast<double>();
}
DATATYPE val = convertAnyTo<double>(valIn);
// For decimal types, we need to move the decimal point.
uint32_t scale = valsIn[0].scale;
@@ -215,65 +163,13 @@ mcsv1_UDAF::ReturnCode median::dropValue(mcsv1Context* context, ColumnDatum* val
{
static_any::any& valIn = valsDropped[0].columnData;
MEDIAN_DATA& data = static_cast<MedianData*>(context->getUserData())->mData;
DATATYPE val = 0.0;
if (valIn.empty())
{
return mcsv1_UDAF::SUCCESS; // Ought not happen when UDAF_IGNORE_NULLS is on.
}
if (valIn.compatible(charTypeId))
{
val = valIn.cast<char>();
}
else if (valIn.compatible(scharTypeId))
{
val = valIn.cast<signed char>();
}
else if (valIn.compatible(shortTypeId))
{
val = valIn.cast<short>();
}
else if (valIn.compatible(intTypeId))
{
val = valIn.cast<int>();
}
else if (valIn.compatible(longTypeId))
{
val = valIn.cast<long>();
}
else if (valIn.compatible(llTypeId))
{
val = valIn.cast<long long>();
}
else if (valIn.compatible(ucharTypeId))
{
val = valIn.cast<unsigned char>();
}
else if (valIn.compatible(ushortTypeId))
{
val = valIn.cast<unsigned short>();
}
else if (valIn.compatible(uintTypeId))
{
val = valIn.cast<unsigned int>();
}
else if (valIn.compatible(ulongTypeId))
{
val = valIn.cast<unsigned long>();
}
else if (valIn.compatible(ullTypeId))
{
val = valIn.cast<unsigned long long>();
}
else if (valIn.compatible(floatTypeId))
{
val = valIn.cast<float>();
}
else if (valIn.compatible(doubleTypeId))
{
val = valIn.cast<double>();
}
DATATYPE val = convertAnyTo<double>(valIn);
// For decimal types, we need to move the decimal point.
uint32_t scale = valsDropped[0].scale;

View File

@@ -85,65 +85,13 @@ mcsv1_UDAF::ReturnCode ssq::nextValue(mcsv1Context* context, ColumnDatum* valsIn
{
static_any::any& valIn = valsIn[0].columnData;
struct ssq_data* data = (struct ssq_data*)context->getUserData()->data;
DATATYPE val = 0.0;
if (context->isParamNull(0) || valIn.empty())
{
return mcsv1_UDAF::SUCCESS;
}
if (valIn.compatible(charTypeId))
{
val = valIn.cast<char>();
}
else if (valIn.compatible(scharTypeId))
{
val = valIn.cast<signed char>();
}
else if (valIn.compatible(shortTypeId))
{
val = valIn.cast<short>();
}
else if (valIn.compatible(intTypeId))
{
val = valIn.cast<int>();
}
else if (valIn.compatible(longTypeId))
{
val = valIn.cast<long>();
}
else if (valIn.compatible(llTypeId))
{
val = valIn.cast<long long>();
}
else if (valIn.compatible(ucharTypeId))
{
val = valIn.cast<unsigned char>();
}
else if (valIn.compatible(ushortTypeId))
{
val = valIn.cast<unsigned short>();
}
else if (valIn.compatible(uintTypeId))
{
val = valIn.cast<unsigned int>();
}
else if (valIn.compatible(ulongTypeId))
{
val = valIn.cast<unsigned long>();
}
else if (valIn.compatible(ullTypeId))
{
val = valIn.cast<unsigned long long>();
}
else if (valIn.compatible(floatTypeId))
{
val = valIn.cast<float>();
}
else if (valIn.compatible(doubleTypeId))
{
val = valIn.cast<double>();
}
DATATYPE val = convertAnyTo<double>(valIn);
// For decimal types, we need to move the decimal point.
uint32_t scale = valsIn[0].scale;
@@ -186,65 +134,13 @@ mcsv1_UDAF::ReturnCode ssq::dropValue(mcsv1Context* context, ColumnDatum* valsDr
{
static_any::any& valIn = valsDropped[0].columnData;
struct ssq_data* data = (struct ssq_data*)context->getUserData()->data;
DATATYPE val = 0.0;
if (valIn.empty())
{
return mcsv1_UDAF::SUCCESS; // Ought not happen when UDAF_IGNORE_NULLS is on.
}
if (valIn.compatible(charTypeId))
{
val = valIn.cast<char>();
}
else if (valIn.compatible(scharTypeId))
{
val = valIn.cast<signed char>();
}
else if (valIn.compatible(shortTypeId))
{
val = valIn.cast<short>();
}
else if (valIn.compatible(intTypeId))
{
val = valIn.cast<int>();
}
else if (valIn.compatible(longTypeId))
{
val = valIn.cast<long>();
}
else if (valIn.compatible(llTypeId))
{
val = valIn.cast<long long>();
}
else if (valIn.compatible(ucharTypeId))
{
val = valIn.cast<unsigned char>();
}
else if (valIn.compatible(ushortTypeId))
{
val = valIn.cast<unsigned short>();
}
else if (valIn.compatible(uintTypeId))
{
val = valIn.cast<unsigned int>();
}
else if (valIn.compatible(ulongTypeId))
{
val = valIn.cast<unsigned long>();
}
else if (valIn.compatible(ullTypeId))
{
val = valIn.cast<unsigned long long>();
}
else if (valIn.compatible(floatTypeId))
{
val = valIn.cast<float>();
}
else if (valIn.compatible(doubleTypeId))
{
val = valIn.cast<double>();
}
DATATYPE val = convertAnyTo<double>(valIn);
// For decimal types, we need to move the decimal point.
uint32_t scale = valsDropped[0].scale;

View File

@@ -205,6 +205,7 @@
<F N="allnull.cpp"/>
<F N="avg_mode.cpp"/>
<F N="avgx.cpp"/>
<F N="distinct_count.cpp"/>
<F N="mcsv1_udaf.cpp"/>
<F N="median.cpp"/>
<F N="ssq.cpp"/>
@@ -217,6 +218,7 @@
<F N="allnull.h"/>
<F N="avg_mode.h"/>
<F N="avgx.h"/>
<F N="distinct_count.h"/>
<F N="mcsv1_udaf.h"/>
<F N="median.h"/>
<F N="ssq.h"/>

View File

@@ -481,6 +481,7 @@ bool WF_udaf::dropValues(int64_t b, int64_t e)
}
}
WindowFunctionType::resetData();
return true;
}

View File

@@ -192,20 +192,35 @@ void WindowFunction::operator()()
// values leaving the window and nextValue for those entering, rather
// than a resetData() and then iterating over the entire window.
// Built-in functions may have this functionality added in the future.
// If b > e then the frame is entirely outside of the partition
// and there's no values to drop
if (b <= e)
{
if (!firstTime)
{
if (fFunctionType->dropValues(prevFrame.first, w.first))
{
b = firstTime ? w.first : prevFrame.second + 1;
// Adjust the beginning of the frame for nextValue
// to start where the previous frame left off.
b = prevFrame.second + 1;
}
else
{
// dropValues failed or doesn't exist
// so calculate the entire frame.
fFunctionType->resetData();
}
}
else
{
fFunctionType->resetData();
}
fFunctionType->operator()(b, e, i);
prevFrame = w;
firstTime = false;
}
}
fFunctionType->operator()(b, e, i); // UDAnF: Calls nextValue and evaluate
prevFrame = w;
}
}
}
}
catch (IDBExcept& iex)
@@ -218,7 +233,7 @@ void WindowFunction::operator()()
}
catch (...)
{
fStep->handleException("unknow exception", logging::ERR_EXECUTE_WINDOW_FUNCTION);
fStep->handleException("unknown exception", logging::ERR_EXECUTE_WINDOW_FUNCTION);
}
}

View File

@@ -31,8 +31,6 @@
#include <ctype.h>
#include <cfloat>
#include <boost/algorithm/string/predicate.hpp>
#include "we_bulkload.h"
#include "we_bulkloadbuffer.h"
#include "we_brm.h"
@@ -370,18 +368,11 @@ void BulkLoadBuffer::convert(char* field, int fieldLength,
{
errno = 0;
if (iequals(field, "true"))
{
fVal = 1;
}
else
{
#ifdef _MSC_VER
fVal = (float)strtod( field, 0 );
#else
fVal = strtof( field, 0 );
#endif
}
if (errno == ERANGE)
{
@@ -414,6 +405,11 @@ void BulkLoadBuffer::convert(char* field, int fieldLength,
fVal = minFltSat;
bufStats.satCount++;
}
if ( fVal == 0
&& isTrueWord(const_cast<const char*>(field), fieldLength) )
{
fVal = 1;
}
}
}
@@ -474,14 +470,7 @@ void BulkLoadBuffer::convert(char* field, int fieldLength,
{
errno = 0;
if (iequals(field, "true"))
{
dVal = 1;
}
else
{
dVal = strtod(field, 0);
}
if (errno == ERANGE)
{
@@ -514,6 +503,11 @@ void BulkLoadBuffer::convert(char* field, int fieldLength,
dVal = column.fMinDblSat;
bufStats.satCount++;
}
else if (dVal == 0
&& isTrueWord(const_cast<const char*>(field), fieldLength))
{
dVal = 1;
}
}
}
@@ -629,12 +623,6 @@ void BulkLoadBuffer::convert(char* field, int fieldLength,
}
else
{
if (iequals(field, "true"))
{
strcpy(field, "1");
fieldLength = 1;
}
if ( (column.dataType == CalpontSystemCatalog::DECIMAL ) ||
(column.dataType == CalpontSystemCatalog::UDECIMAL) )
{
@@ -664,6 +652,11 @@ void BulkLoadBuffer::convert(char* field, int fieldLength,
origVal = static_cast<int64_t>(column.fMaxIntSat);
bSatVal = true;
}
else if ( origVal == 0
&& isTrueWord(const_cast<const char*>(field), fieldLength) )
{
origVal = 1;
}
if (bSatVal)
bufStats.satCount++;
@@ -722,14 +715,7 @@ void BulkLoadBuffer::convert(char* field, int fieldLength,
{
errno = 0;
if (iequals(field, "true"))
{
origVal = 1;
}
else
{
origVal = strtoll(field, 0, 10);
}
if (errno == ERANGE)
bSatVal = true;
@@ -747,6 +733,11 @@ void BulkLoadBuffer::convert(char* field, int fieldLength,
origVal = static_cast<int64_t>(column.fMaxIntSat);
bSatVal = true;
}
else if ( origVal == 0
&& isTrueWord(const_cast<const char*>(field), fieldLength) )
{
origVal = 1;
}
if (bSatVal)
bufStats.satCount++;
@@ -805,7 +796,7 @@ void BulkLoadBuffer::convert(char* field, int fieldLength,
}
else
{
if (iequals(field, "true"))
if (isTrueWord(const_cast<const char*>(field), fieldLength))
{
strcpy(field, "1");
fieldLength = 1;
@@ -898,14 +889,7 @@ void BulkLoadBuffer::convert(char* field, int fieldLength,
{
errno = 0;
if (iequals(field, "true"))
{
origVal = 1;
}
else
{
origVal = strtoll(field, 0, 10);
}
if (errno == ERANGE)
bSatVal = true;
@@ -923,6 +907,11 @@ void BulkLoadBuffer::convert(char* field, int fieldLength,
origVal = static_cast<int64_t>(column.fMaxIntSat);
bSatVal = true;
}
else if ( origVal == 0
&& isTrueWord(const_cast<const char*>(field), fieldLength) )
{
origVal = 1;
}
if (bSatVal)
bufStats.satCount++;
@@ -981,7 +970,7 @@ void BulkLoadBuffer::convert(char* field, int fieldLength,
}
else
{
if (iequals(field, "true"))
if (isTrueWord(const_cast<const char*>(field), fieldLength))
{
strcpy(field, "1");
fieldLength = 1;
@@ -1018,6 +1007,7 @@ void BulkLoadBuffer::convert(char* field, int fieldLength,
bSatVal = true;
}
if (bSatVal)
bufStats.satCount++;
@@ -1199,14 +1189,7 @@ void BulkLoadBuffer::convert(char* field, int fieldLength,
{
errno = 0;
if (iequals(field, "true"))
{
ullVal = 1;
}
else
{
ullVal = strtoull(field, 0, 10);
}
if (errno == ERANGE)
bSatVal = true;
@@ -1220,6 +1203,11 @@ void BulkLoadBuffer::convert(char* field, int fieldLength,
ullVal = column.fMaxIntSat;
bSatVal = true;
}
else if ( ullVal == 0
&& isTrueWord(const_cast<const char*>(field), fieldLength) )
{
ullVal = 1;
}
if (bSatVal)
bufStats.satCount++;
@@ -1276,14 +1264,7 @@ void BulkLoadBuffer::convert(char* field, int fieldLength,
{
errno = 0;
if (iequals(field, "true"))
{
origVal = 1;
}
else
{
origVal = strtoll(field, 0, 10);
}
if (errno == ERANGE)
bSatVal = true;
@@ -1301,6 +1282,11 @@ void BulkLoadBuffer::convert(char* field, int fieldLength,
origVal = static_cast<int64_t>(column.fMaxIntSat);
bSatVal = true;
}
else if ( origVal == 0
&& isTrueWord(const_cast<const char*>(field), fieldLength) )
{
origVal = 1;
}
if (bSatVal)
bufStats.satCount++;
@@ -1361,7 +1347,7 @@ void BulkLoadBuffer::convert(char* field, int fieldLength,
}
else
{
if (iequals(field, "true"))
if (isTrueWord(const_cast<const char*>(field), fieldLength))
{
strcpy(field, "1");
fieldLength = 1;

View File

@@ -383,5 +383,14 @@ public:
}
};
inline bool isTrueWord(const char *field, int fieldLength)
{
//return false;
return fieldLength == 4 && ( field[0] == 'T' || field[0] == 't' )
&& ( field[1] == 'R' || field[1] == 'r' )
&& ( field[2] == 'U' || field[2] == 'u' )
&& ( field[3] == 'E' || field[3] == 'e' );
}
}
#endif