You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
MCOL-523 Add UDAF and UDAnF SDK
This commit is contained in:
223
utils/common/any.hpp
Executable file
223
utils/common/any.hpp
Executable file
@ -0,0 +1,223 @@
|
||||
#pragma once
|
||||
/*
|
||||
* (C) Copyright Christopher Diggins 2005-2011
|
||||
* (C) Copyright Pablo Aguilar 2005
|
||||
* (C) Copyright Kevlin Henney 2001
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE_1_0.txt or copy at
|
||||
* http://www.boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace static_any
|
||||
{
|
||||
namespace anyimpl
|
||||
{
|
||||
|
||||
struct bad_any_cast
|
||||
{
|
||||
};
|
||||
|
||||
struct empty_any
|
||||
{
|
||||
};
|
||||
|
||||
struct base_any_policy
|
||||
{
|
||||
virtual void static_delete(void** x) = 0;
|
||||
virtual void copy_from_value(void const* src, void** dest) = 0;
|
||||
virtual void clone(void* const* src, void** dest) = 0;
|
||||
virtual void move(void* const* src, void** dest) = 0;
|
||||
virtual void* get_value(void** src) = 0;
|
||||
virtual size_t get_size() = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct typed_base_any_policy : base_any_policy
|
||||
{
|
||||
virtual size_t get_size() { return sizeof(T); }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct small_any_policy : typed_base_any_policy<T>
|
||||
{
|
||||
virtual void static_delete(void** x) { }
|
||||
virtual void copy_from_value(void const* src, void** dest)
|
||||
{ new(dest) T(*reinterpret_cast<T const*>(src)); }
|
||||
virtual void clone(void* const* src, void** dest) { *dest = *src; }
|
||||
virtual void move(void* const* src, void** dest) { *dest = *src; }
|
||||
virtual void* get_value(void** src) { return reinterpret_cast<void*>(src); }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct big_any_policy : typed_base_any_policy<T>
|
||||
{
|
||||
virtual void static_delete(void** x) { if (*x)
|
||||
delete(*reinterpret_cast<T**>(x)); *x = NULL; }
|
||||
virtual void copy_from_value(void const* src, void** dest) {
|
||||
*dest = new T(*reinterpret_cast<T const*>(src)); }
|
||||
virtual void clone(void* const* src, void** dest) {
|
||||
*dest = new T(**reinterpret_cast<T* const*>(src)); }
|
||||
virtual void move(void* const* src, void** dest) {
|
||||
(*reinterpret_cast<T**>(dest))->~T();
|
||||
**reinterpret_cast<T**>(dest) = **reinterpret_cast<T* const*>(src); }
|
||||
virtual void* get_value(void** src) { return *src; }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct choose_policy
|
||||
{
|
||||
typedef big_any_policy<T> type;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct choose_policy<T*>
|
||||
{
|
||||
typedef small_any_policy<T*> type;
|
||||
};
|
||||
|
||||
struct any;
|
||||
|
||||
/// Choosing the policy for an any type is illegal, but should never happen.
|
||||
/// This is designed to throw a compiler error.
|
||||
template<>
|
||||
struct choose_policy<any>
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
/// Specializations for small types.
|
||||
#define SMALL_POLICY(TYPE) template<> struct \
|
||||
choose_policy<TYPE> { typedef small_any_policy<TYPE> type; };
|
||||
|
||||
SMALL_POLICY(char);
|
||||
SMALL_POLICY(signed char);
|
||||
SMALL_POLICY(unsigned char);
|
||||
SMALL_POLICY(signed short);
|
||||
SMALL_POLICY(unsigned short);
|
||||
SMALL_POLICY(signed int);
|
||||
SMALL_POLICY(unsigned int);
|
||||
SMALL_POLICY(signed long);
|
||||
SMALL_POLICY(unsigned long);
|
||||
SMALL_POLICY(signed long long);
|
||||
SMALL_POLICY(unsigned long long);
|
||||
SMALL_POLICY(float);
|
||||
SMALL_POLICY(double);
|
||||
SMALL_POLICY(bool);
|
||||
SMALL_POLICY(std::string);
|
||||
|
||||
#undef SMALL_POLICY
|
||||
|
||||
/// This function will return a different policy for each type.
|
||||
template<typename T>
|
||||
base_any_policy* get_policy()
|
||||
{
|
||||
static typename choose_policy<T>::type policy;
|
||||
return &policy;
|
||||
};
|
||||
}
|
||||
|
||||
class any
|
||||
{
|
||||
private:
|
||||
// fields
|
||||
anyimpl::base_any_policy* policy;
|
||||
void* object;
|
||||
|
||||
public:
|
||||
/// Initializing constructor.
|
||||
template <typename T>
|
||||
any(const T& x)
|
||||
: policy(anyimpl::get_policy<anyimpl::empty_any>()), object(NULL)
|
||||
{
|
||||
assign(x);
|
||||
}
|
||||
|
||||
/// Empty constructor.
|
||||
any()
|
||||
: policy(anyimpl::get_policy<anyimpl::empty_any>()), object(NULL)
|
||||
{ }
|
||||
|
||||
/// Special initializing constructor for string literals.
|
||||
any(const char* x)
|
||||
: policy(anyimpl::get_policy<anyimpl::empty_any>()), object(NULL)
|
||||
{
|
||||
assign(x);
|
||||
}
|
||||
|
||||
/// Copy constructor.
|
||||
any(const any& x)
|
||||
: policy(anyimpl::get_policy<anyimpl::empty_any>()), object(NULL)
|
||||
{
|
||||
assign(x);
|
||||
}
|
||||
|
||||
/// Destructor.
|
||||
~any() {
|
||||
policy->static_delete(&object);
|
||||
}
|
||||
|
||||
/// Assignment function from another any.
|
||||
any& assign(const any& x) {
|
||||
reset();
|
||||
policy = x.policy;
|
||||
policy->clone(&x.object, &object);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Assignment function.
|
||||
template <typename T>
|
||||
any& assign(const T& x) {
|
||||
reset();
|
||||
policy = anyimpl::get_policy<T>();
|
||||
policy->copy_from_value(&x, &object);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Assignment operator.
|
||||
template<typename T>
|
||||
any& operator=(const T& x) {
|
||||
return assign(x);
|
||||
}
|
||||
|
||||
/// Assignment operator, specialed for literal strings.
|
||||
/// They have types like const char [6] which don't work as expected.
|
||||
any& operator=(const char* x) {
|
||||
return assign(x);
|
||||
}
|
||||
|
||||
/// Utility functions
|
||||
any& swap(any& x) {
|
||||
std::swap(policy, x.policy);
|
||||
std::swap(object, x.object);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Cast operator. You can only cast to the original type.
|
||||
template<typename T>
|
||||
T& cast() {
|
||||
if (policy != anyimpl::get_policy<T>())
|
||||
throw anyimpl::bad_any_cast();
|
||||
T* r = reinterpret_cast<T*>(policy->get_value(&object));
|
||||
return *r;
|
||||
}
|
||||
|
||||
/// Returns true if the any contains no value.
|
||||
bool empty() const {
|
||||
return policy == anyimpl::get_policy<anyimpl::empty_any>();
|
||||
}
|
||||
|
||||
/// Frees any allocated memory, and sets the value to NULL.
|
||||
void reset() {
|
||||
policy->static_delete(&object);
|
||||
policy = anyimpl::get_policy<anyimpl::empty_any>();
|
||||
}
|
||||
|
||||
/// Returns true if the two types are the same.
|
||||
bool compatible(const any& x) const {
|
||||
return policy == x.policy;
|
||||
}
|
||||
};
|
||||
}
|
459
utils/common/common.vpj
Normal file → Executable file
459
utils/common/common.vpj
Normal file → Executable file
@ -1,232 +1,233 @@
|
||||
<!DOCTYPE Project SYSTEM "http://www.slickedit.com/dtd/vse/10.0/vpj.dtd">
|
||||
<Project
|
||||
Version="10.0"
|
||||
VendorName="SlickEdit"
|
||||
TemplateName="GNU C/C++"
|
||||
WorkingDir=".">
|
||||
<Config
|
||||
Name="Debug"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdcommon.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -g -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -g -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Config
|
||||
Name="Release"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdcommon.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Files>
|
||||
<Folder
|
||||
Name="Source Files"
|
||||
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d">
|
||||
<F N="fixedallocator.cpp"/>
|
||||
<F N="MonitorProcMem.cpp"/>
|
||||
<F N="poolallocator.cpp"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Header Files"
|
||||
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if">
|
||||
<F N="fixedallocator.h"/>
|
||||
<F N="hasher.h"/>
|
||||
<F N="MonitorProcMem.h"/>
|
||||
<F N="poolallocator.h"/>
|
||||
<F N="simpleallocator.h"/>
|
||||
<F N="stlpoolallocator.h"/>
|
||||
<F N="syncstream.h"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Resource Files"
|
||||
Filters="*.ico;*.cur;*.dlg"/>
|
||||
<Folder
|
||||
Name="Bitmaps"
|
||||
Filters="*.bmp"/>
|
||||
<Folder
|
||||
Name="Other Files"
|
||||
Filters="">
|
||||
<F
|
||||
N="Makefile"
|
||||
Type="Makefile"/>
|
||||
</Folder>
|
||||
</Files>
|
||||
Version="10.0"
|
||||
VendorName="SlickEdit"
|
||||
TemplateName="GNU C/C++"
|
||||
WorkingDir=".">
|
||||
<Config
|
||||
Name="Debug"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdcommon.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -g -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -g -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Config
|
||||
Name="Release"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdcommon.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Files>
|
||||
<Folder
|
||||
Name="Source Files"
|
||||
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d">
|
||||
<F N="fixedallocator.cpp"/>
|
||||
<F N="MonitorProcMem.cpp"/>
|
||||
<F N="poolallocator.cpp"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Header Files"
|
||||
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if">
|
||||
<F N="any.hpp"/>
|
||||
<F N="fixedallocator.h"/>
|
||||
<F N="hasher.h"/>
|
||||
<F N="MonitorProcMem.h"/>
|
||||
<F N="poolallocator.h"/>
|
||||
<F N="simpleallocator.h"/>
|
||||
<F N="stlpoolallocator.h"/>
|
||||
<F N="syncstream.h"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Resource Files"
|
||||
Filters="*.ico;*.cur;*.dlg"/>
|
||||
<Folder
|
||||
Name="Bitmaps"
|
||||
Filters="*.bmp"/>
|
||||
<Folder
|
||||
Name="Other Files"
|
||||
Filters="">
|
||||
<F
|
||||
N="Makefile"
|
||||
Type="Makefile"/>
|
||||
</Folder>
|
||||
</Files>
|
||||
</Project>
|
||||
|
@ -34,7 +34,7 @@ namespace funcexp
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Return input argument type.
|
||||
// See IDB_add in udfsdk.h for explanation of this function.
|
||||
// See mcs_add in udfsdk.h for explanation of this function.
|
||||
//------------------------------------------------------------------------------
|
||||
execplan::CalpontSystemCatalog::ColType Func_inet_aton::operationType(
|
||||
FunctionParm& fp,
|
||||
|
@ -54,7 +54,7 @@ namespace funcexp
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Return input argument type.
|
||||
// See IDB_add in udfsdk.h for explanation of this function.
|
||||
// See mcs_add in udfsdk.h for explanation of this function.
|
||||
//------------------------------------------------------------------------------
|
||||
execplan::CalpontSystemCatalog::ColType Func_inet_ntoa::operationType(
|
||||
FunctionParm& fp,
|
||||
|
12
utils/funcexp/func_lpad.cpp
Normal file → Executable file
12
utils/funcexp/func_lpad.cpp
Normal file → Executable file
@ -63,7 +63,7 @@ std::string Func_lpad::getStrVal(rowgroup::Row& row,
|
||||
const string& tstr = fp[0]->data()->getStrVal(row, isNull);
|
||||
|
||||
// The result length in number of characters
|
||||
int len = 0;
|
||||
size_t len = 0;
|
||||
switch (fp[1]->data()->resultType().colDataType)
|
||||
{
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
@ -129,16 +129,16 @@ std::string Func_lpad::getStrVal(rowgroup::Row& row,
|
||||
// determine the size of buffer to allocate, we can be sure the wide
|
||||
// char string won't be longer than
|
||||
strwclen = tstr.length(); // a guess to start with. This will be >= to the real count.
|
||||
int alen = len;
|
||||
size_t alen = len;
|
||||
if(strwclen > len)
|
||||
alen = strwclen;
|
||||
int bufsize = (alen+1) * sizeof(wchar_t);
|
||||
size_t bufsize = (alen+1) * sizeof(wchar_t);
|
||||
|
||||
// Convert to wide characters. Do all further work in wide characters
|
||||
wchar_t* wcbuf = (wchar_t*)alloca(bufsize);
|
||||
strwclen = utf8::idb_mbstowcs(wcbuf, tstr.c_str(), strwclen+1);
|
||||
|
||||
unsigned int strSize = strwclen; // The number of significant characters
|
||||
size_t strSize = strwclen; // The number of significant characters
|
||||
const wchar_t* pWChar = wcbuf;
|
||||
for (i = 0; *pWChar != '\0' && i < strwclen; ++pWChar, ++i)
|
||||
{
|
||||
@ -165,13 +165,13 @@ std::string Func_lpad::getStrVal(rowgroup::Row& row,
|
||||
|
||||
// Convert the pad string to wide
|
||||
padwclen = pad.length(); // A guess to start.
|
||||
int padbufsize = (padwclen+1) * sizeof(wchar_t);
|
||||
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);
|
||||
|
||||
// How many chars do we need?
|
||||
unsigned int padspace = len - strSize;
|
||||
size_t padspace = len - strSize;
|
||||
|
||||
// Shift the contents of wcbuf to the right.
|
||||
wchar_t* startofstr = wcbuf + padspace;
|
||||
|
2
utils/funcexp/func_rpad.cpp
Normal file → Executable file
2
utils/funcexp/func_rpad.cpp
Normal file → Executable file
@ -63,7 +63,7 @@ std::string Func_rpad::getStrVal(rowgroup::Row& row,
|
||||
const string& tstr = fp[0]->data()->getStrVal(row, isNull);
|
||||
|
||||
// The result length in number of characters
|
||||
int len = 0;
|
||||
size_t len = 0;
|
||||
switch (fp[1]->data()->resultType().colDataType)
|
||||
{
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
|
658
utils/funcexp/funcexp.vpj
Normal file → Executable file
658
utils/funcexp/funcexp.vpj
Normal file → Executable file
@ -1,332 +1,332 @@
|
||||
<!DOCTYPE Project SYSTEM "http://www.slickedit.com/dtd/vse/10.0/vpj.dtd">
|
||||
<Project
|
||||
Version="10.0"
|
||||
VendorName="SlickEdit"
|
||||
TemplateName="GNU C/C++"
|
||||
WorkingDir=".">
|
||||
<Config
|
||||
Name="Debug"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdfuncexp.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -g -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -g -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Config
|
||||
Name="Release"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdfuncexp.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Files>
|
||||
<Folder
|
||||
Name="Source Files"
|
||||
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d">
|
||||
<F N="func_abs.cpp"/>
|
||||
<F N="func_add_time.cpp"/>
|
||||
<F N="func_ascii.cpp"/>
|
||||
<F N="func_between.cpp"/>
|
||||
<F N="func_bitand.cpp"/>
|
||||
<F N="func_bitwise.cpp"/>
|
||||
<F N="func_case.cpp"/>
|
||||
<F N="func_cast.cpp"/>
|
||||
<F N="func_ceil.cpp"/>
|
||||
<F N="func_char.cpp"/>
|
||||
<F N="func_char_length.cpp"/>
|
||||
<F N="func_coalesce.cpp"/>
|
||||
<F N="func_concat.cpp"/>
|
||||
<F N="func_concat_ws.cpp"/>
|
||||
<F N="func_conv.cpp"/>
|
||||
<F N="func_crc32.cpp"/>
|
||||
<F N="func_date.cpp"/>
|
||||
<F N="func_date_add.cpp"/>
|
||||
<F N="func_date_format.cpp"/>
|
||||
<F N="func_day.cpp"/>
|
||||
<F N="func_dayname.cpp"/>
|
||||
<F N="func_dayofweek.cpp"/>
|
||||
<F N="func_dayofyear.cpp"/>
|
||||
<F N="func_div.cpp"/>
|
||||
<F N="func_elt.cpp"/>
|
||||
<F N="func_exp.cpp"/>
|
||||
<F N="func_extract.cpp"/>
|
||||
<F N="func_find_in_set.cpp"/>
|
||||
<F N="func_floor.cpp"/>
|
||||
<F N="func_from_days.cpp"/>
|
||||
<F N="func_from_unixtime.cpp"/>
|
||||
<F N="func_get_format.cpp"/>
|
||||
<F N="func_greatest.cpp"/>
|
||||
<F N="func_hex.cpp"/>
|
||||
<F N="func_hour.cpp"/>
|
||||
<F N="func_if.cpp"/>
|
||||
<F N="func_ifnull.cpp"/>
|
||||
<F N="func_in.cpp"/>
|
||||
<F N="func_inet_aton.cpp"/>
|
||||
<F N="func_inet_ntoa.cpp"/>
|
||||
<F N="func_insert.cpp"/>
|
||||
<F N="func_instr.cpp"/>
|
||||
<F N="func_isnull.cpp"/>
|
||||
<F N="func_last_day.cpp"/>
|
||||
<F N="func_lcase.cpp"/>
|
||||
<F N="func_least.cpp"/>
|
||||
<F N="func_left.cpp"/>
|
||||
<F N="func_length.cpp"/>
|
||||
<F N="func_lpad.cpp"/>
|
||||
<F N="func_ltrim.cpp"/>
|
||||
<F N="func_makedate.cpp"/>
|
||||
<F N="func_maketime.cpp"/>
|
||||
<F N="func_math.cpp"/>
|
||||
<F N="func_md5.cpp"/>
|
||||
<F N="func_microsecond.cpp"/>
|
||||
<F N="func_minute.cpp"/>
|
||||
<F N="func_mod.cpp"/>
|
||||
<F N="func_month.cpp"/>
|
||||
<F N="func_monthname.cpp"/>
|
||||
<F N="func_nullif.cpp"/>
|
||||
<F N="func_period_add.cpp"/>
|
||||
<F N="func_period_diff.cpp"/>
|
||||
<F N="func_pow.cpp"/>
|
||||
<F N="func_quarter.cpp"/>
|
||||
<F N="func_rand.cpp"/>
|
||||
<F N="func_regexp.cpp"/>
|
||||
<F N="func_repeat.cpp"/>
|
||||
<F N="func_replace.cpp"/>
|
||||
<F N="func_reverse.cpp"/>
|
||||
<F N="func_right.cpp"/>
|
||||
<F N="func_round.cpp"/>
|
||||
<F N="func_rpad.cpp"/>
|
||||
<F N="func_rtrim.cpp"/>
|
||||
<F N="func_sec_to_time.cpp"/>
|
||||
<F N="func_second.cpp"/>
|
||||
<F N="func_sha.cpp"/>
|
||||
<F N="func_sign.cpp"/>
|
||||
<F N="func_str_to_date.cpp"/>
|
||||
<F N="func_strcmp.cpp"/>
|
||||
<F N="func_substr.cpp"/>
|
||||
<F N="func_substring_index.cpp"/>
|
||||
<F N="func_sysdate.cpp"/>
|
||||
<F N="func_time.cpp"/>
|
||||
<F N="func_time_format.cpp"/>
|
||||
<F N="func_time_to_sec.cpp"/>
|
||||
<F N="func_timediff.cpp"/>
|
||||
<F N="func_timestampdiff.cpp"/>
|
||||
<F N="func_to_days.cpp"/>
|
||||
<F N="func_trim.cpp"/>
|
||||
<F N="func_truncate.cpp"/>
|
||||
<F N="func_ucase.cpp"/>
|
||||
<F N="func_unhex.cpp"/>
|
||||
<F N="func_unix_timestamp.cpp"/>
|
||||
<F N="func_week.cpp"/>
|
||||
<F N="func_weekday.cpp"/>
|
||||
<F N="func_year.cpp"/>
|
||||
<F N="func_yearweek.cpp"/>
|
||||
<F N="funcexp.cpp"/>
|
||||
<F N="funcexpwrapper.cpp"/>
|
||||
<F N="functor.cpp"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Header Files"
|
||||
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if">
|
||||
<F N="funcexp.h"/>
|
||||
<F N="funcexpwrapper.h"/>
|
||||
<F N="funchelpers.h"/>
|
||||
<F N="functor.h"/>
|
||||
<F N="functor_all.h"/>
|
||||
<F N="functor_bool.h"/>
|
||||
<F N="functor_dtm.h"/>
|
||||
<F N="functor_export.h"/>
|
||||
<F N="functor_int.h"/>
|
||||
<F N="functor_real.h"/>
|
||||
<F N="functor_str.h"/>
|
||||
<F N="sha.h"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Resource Files"
|
||||
Filters="*.ico;*.cur;*.dlg"/>
|
||||
<Folder
|
||||
Name="Bitmaps"
|
||||
Filters="*.bmp"/>
|
||||
<Folder
|
||||
Name="Other Files"
|
||||
Filters="">
|
||||
<F
|
||||
N="Makefile"
|
||||
Type="Makefile"/>
|
||||
</Folder>
|
||||
</Files>
|
||||
Version="10.0"
|
||||
VendorName="SlickEdit"
|
||||
TemplateName="GNU C/C++"
|
||||
WorkingDir=".">
|
||||
<Config
|
||||
Name="Debug"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdfuncexp.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -g -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -g -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Config
|
||||
Name="Release"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdfuncexp.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw"
|
||||
ClearProcessBuffer="1">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Files>
|
||||
<Folder
|
||||
Name="Source Files"
|
||||
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d">
|
||||
<F N="func_abs.cpp"/>
|
||||
<F N="func_add_time.cpp"/>
|
||||
<F N="func_ascii.cpp"/>
|
||||
<F N="func_between.cpp"/>
|
||||
<F N="func_bitand.cpp"/>
|
||||
<F N="func_bitwise.cpp"/>
|
||||
<F N="func_case.cpp"/>
|
||||
<F N="func_cast.cpp"/>
|
||||
<F N="func_ceil.cpp"/>
|
||||
<F N="func_char.cpp"/>
|
||||
<F N="func_char_length.cpp"/>
|
||||
<F N="func_coalesce.cpp"/>
|
||||
<F N="func_concat.cpp"/>
|
||||
<F N="func_concat_ws.cpp"/>
|
||||
<F N="func_conv.cpp"/>
|
||||
<F N="func_crc32.cpp"/>
|
||||
<F N="func_date.cpp"/>
|
||||
<F N="func_date_add.cpp"/>
|
||||
<F N="func_date_format.cpp"/>
|
||||
<F N="func_day.cpp"/>
|
||||
<F N="func_dayname.cpp"/>
|
||||
<F N="func_dayofweek.cpp"/>
|
||||
<F N="func_dayofyear.cpp"/>
|
||||
<F N="func_div.cpp"/>
|
||||
<F N="func_elt.cpp"/>
|
||||
<F N="func_exp.cpp"/>
|
||||
<F N="func_extract.cpp"/>
|
||||
<F N="func_find_in_set.cpp"/>
|
||||
<F N="func_floor.cpp"/>
|
||||
<F N="func_from_days.cpp"/>
|
||||
<F N="func_from_unixtime.cpp"/>
|
||||
<F N="func_get_format.cpp"/>
|
||||
<F N="func_greatest.cpp"/>
|
||||
<F N="func_hex.cpp"/>
|
||||
<F N="func_hour.cpp"/>
|
||||
<F N="func_if.cpp"/>
|
||||
<F N="func_ifnull.cpp"/>
|
||||
<F N="func_in.cpp"/>
|
||||
<F N="func_inet_aton.cpp"/>
|
||||
<F N="func_inet_ntoa.cpp"/>
|
||||
<F N="func_insert.cpp"/>
|
||||
<F N="func_instr.cpp"/>
|
||||
<F N="func_isnull.cpp"/>
|
||||
<F N="func_last_day.cpp"/>
|
||||
<F N="func_lcase.cpp"/>
|
||||
<F N="func_least.cpp"/>
|
||||
<F N="func_left.cpp"/>
|
||||
<F N="func_length.cpp"/>
|
||||
<F N="func_lpad.cpp"/>
|
||||
<F N="func_ltrim.cpp"/>
|
||||
<F N="func_makedate.cpp"/>
|
||||
<F N="func_maketime.cpp"/>
|
||||
<F N="func_math.cpp"/>
|
||||
<F N="func_md5.cpp"/>
|
||||
<F N="func_microsecond.cpp"/>
|
||||
<F N="func_minute.cpp"/>
|
||||
<F N="func_mod.cpp"/>
|
||||
<F N="func_month.cpp"/>
|
||||
<F N="func_monthname.cpp"/>
|
||||
<F N="func_nullif.cpp"/>
|
||||
<F N="func_period_add.cpp"/>
|
||||
<F N="func_period_diff.cpp"/>
|
||||
<F N="func_pow.cpp"/>
|
||||
<F N="func_quarter.cpp"/>
|
||||
<F N="func_rand.cpp"/>
|
||||
<F N="func_regexp.cpp"/>
|
||||
<F N="func_repeat.cpp"/>
|
||||
<F N="func_replace.cpp"/>
|
||||
<F N="func_reverse.cpp"/>
|
||||
<F N="func_right.cpp"/>
|
||||
<F N="func_round.cpp"/>
|
||||
<F N="func_rpad.cpp"/>
|
||||
<F N="func_rtrim.cpp"/>
|
||||
<F N="func_sec_to_time.cpp"/>
|
||||
<F N="func_second.cpp"/>
|
||||
<F N="func_sha.cpp"/>
|
||||
<F N="func_sign.cpp"/>
|
||||
<F N="func_str_to_date.cpp"/>
|
||||
<F N="func_strcmp.cpp"/>
|
||||
<F N="func_substr.cpp"/>
|
||||
<F N="func_substring_index.cpp"/>
|
||||
<F N="func_sysdate.cpp"/>
|
||||
<F N="func_time.cpp"/>
|
||||
<F N="func_time_format.cpp"/>
|
||||
<F N="func_time_to_sec.cpp"/>
|
||||
<F N="func_timediff.cpp"/>
|
||||
<F N="func_timestampdiff.cpp"/>
|
||||
<F N="func_to_days.cpp"/>
|
||||
<F N="func_trim.cpp"/>
|
||||
<F N="func_truncate.cpp"/>
|
||||
<F N="func_ucase.cpp"/>
|
||||
<F N="func_unhex.cpp"/>
|
||||
<F N="func_unix_timestamp.cpp"/>
|
||||
<F N="func_week.cpp"/>
|
||||
<F N="func_weekday.cpp"/>
|
||||
<F N="func_year.cpp"/>
|
||||
<F N="func_yearweek.cpp"/>
|
||||
<F N="funcexp.cpp"/>
|
||||
<F N="funcexpwrapper.cpp"/>
|
||||
<F N="functor.cpp"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Header Files"
|
||||
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if">
|
||||
<F N="funcexp.h"/>
|
||||
<F N="funcexpwrapper.h"/>
|
||||
<F N="funchelpers.h"/>
|
||||
<F N="functor.h"/>
|
||||
<F N="functor_all.h"/>
|
||||
<F N="functor_bool.h"/>
|
||||
<F N="functor_dtm.h"/>
|
||||
<F N="functor_export.h"/>
|
||||
<F N="functor_int.h"/>
|
||||
<F N="functor_real.h"/>
|
||||
<F N="functor_str.h"/>
|
||||
<F N="sha.h"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Resource Files"
|
||||
Filters="*.ico;*.cur;*.dlg"/>
|
||||
<Folder
|
||||
Name="Bitmaps"
|
||||
Filters="*.bmp"/>
|
||||
<Folder
|
||||
Name="Other Files"
|
||||
Filters="">
|
||||
<F
|
||||
N="Makefile"
|
||||
Type="Makefile"/>
|
||||
</Folder>
|
||||
</Files>
|
||||
</Project>
|
||||
|
@ -182,7 +182,7 @@ public:
|
||||
Func_isnull():fIsNotNull(false) {}
|
||||
Func_isnull(bool isnotnull) : fIsNotNull(isnotnull) {}
|
||||
/*
|
||||
* Destructor. IDB_add does not need to do anything here to clean up.
|
||||
* Destructor. isnull does not need to do anything here to clean up.
|
||||
*/
|
||||
virtual ~Func_isnull() {}
|
||||
|
||||
|
9
utils/loggingcpp/ErrorMessage.txt
Normal file → Executable file
9
utils/loggingcpp/ErrorMessage.txt
Normal file → Executable file
@ -148,6 +148,7 @@
|
||||
5001 ERR_FUNC_NON_IMPLEMENT %1%:%2% is not implemented.
|
||||
5002 ERR_PSEUDOCOL_IDB_ONLY Pseudo column function '%1%' is only supported in Columnstore.
|
||||
5003 ERR_PSEUDOCOL_WRONG_ARG Argument of pseudo column function '%1%' is invalid.
|
||||
5004 ERR_WINDOW_FUNC_ONLY User defined function %1% may only be used with the OVER clause.
|
||||
|
||||
# DBRM Errors
|
||||
6001 ERR_NETWORK DBRM encountered a network error, check the controllernode.
|
||||
@ -195,4 +196,10 @@
|
||||
9027 ERR_WF_ARG_OUT_OF_RANGE Argument '%1%' is out of range.
|
||||
9028 ERR_WF_NOT_ALLOWED Window functions are not allowed in %1%.
|
||||
9029 ERR_WF_IDB_ONLY Window function are only supported for Columnstore tables.
|
||||
9030 ERR_WF_DATA_SET_TOO_BIG Window function data set exceeds memory limit.
|
||||
9030 ERR_WF_DATA_SET_TOO_BIG Window function data set exceeds memory limit.
|
||||
9031 ERR_WF_UDANF_ERROR User Defined Window function: %1%.
|
||||
9032 ERR_WF_UDANF_NOT_ALLOWED User Defined Function %1% used with an OVER clause.
|
||||
9033 ERR_WF_UDANF_ORDER_REQUIRED User Defined Function %1% without an ORDER BY clause in the OVER clause.
|
||||
9034 ERR_WF_UDANF_ORDER_NOT_ALLOWED User Defined Function %1% with an ORDER BY clause in the OVER clause.
|
||||
9035 ERR_WF_UDANF_FRAME_REQUIRED User Defined Function %1% without a FRAME clause in the OVER clause.
|
||||
9036 ERR_WF_UDANF_FRAME_NOT_ALLOWED User Defined Function %1% with a FRAME clause in the OVER clause.
|
||||
|
470
utils/loggingcpp/loggingcpp.vpj
Normal file → Executable file
470
utils/loggingcpp/loggingcpp.vpj
Normal file → Executable file
@ -1,238 +1,238 @@
|
||||
<!DOCTYPE Project SYSTEM "http://www.slickedit.com/dtd/vse/10.0/vpj.dtd">
|
||||
<Project
|
||||
Version="10.0"
|
||||
VendorName="SlickEdit"
|
||||
TemplateName="GNU C/C++"
|
||||
WorkingDir=".">
|
||||
<Config
|
||||
Name="Debug"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdloggingcpp.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -g -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -g -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Config
|
||||
Name="Release"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdloggingcpp.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Files>
|
||||
<Folder
|
||||
Name="Source Files"
|
||||
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d">
|
||||
<F N="errorcodes.cpp"/>
|
||||
<F N="idberrorinfo.cpp"/>
|
||||
<F N="logger.cpp"/>
|
||||
<F N="message.cpp"/>
|
||||
<F N="messagelog.cpp"/>
|
||||
<F N="sqllogger.cpp"/>
|
||||
<F N="stopwatch.cpp"/>
|
||||
<F N="tdriver.cpp"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Header Files"
|
||||
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if">
|
||||
<F N="errorcodes.h"/>
|
||||
<F N="errorids.h"/>
|
||||
<F N="exceptclasses.h"/>
|
||||
<F N="idberrorinfo.h"/>
|
||||
<F N="logger.h"/>
|
||||
<F N="loggingid.h"/>
|
||||
<F N="messageids.h"/>
|
||||
<F N="messagelog.h"/>
|
||||
<F N="messageobj.h"/>
|
||||
<F N="sqllogger.h"/>
|
||||
<F N="stopwatch.h"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Resource Files"
|
||||
Filters="*.ico;*.cur;*.dlg"/>
|
||||
<Folder
|
||||
Name="Bitmaps"
|
||||
Filters="*.bmp"/>
|
||||
<Folder
|
||||
Name="Other Files"
|
||||
Filters="">
|
||||
<F N="ErrorMessage.txt"/>
|
||||
<F
|
||||
N="Makefile"
|
||||
Type="Makefile"/>
|
||||
<F N="MessageFile.txt"/>
|
||||
<F N="SubsystemIDs.txt"/>
|
||||
</Folder>
|
||||
</Files>
|
||||
Version="10.0"
|
||||
VendorName="SlickEdit"
|
||||
TemplateName="GNU C/C++"
|
||||
WorkingDir=".">
|
||||
<Config
|
||||
Name="Debug"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdloggingcpp.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -g -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -g -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Config
|
||||
Name="Release"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdloggingcpp.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Files>
|
||||
<Folder
|
||||
Name="Source Files"
|
||||
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d">
|
||||
<F N="errorcodes.cpp"/>
|
||||
<F N="idberrorinfo.cpp"/>
|
||||
<F N="logger.cpp"/>
|
||||
<F N="message.cpp"/>
|
||||
<F N="messagelog.cpp"/>
|
||||
<F N="sqllogger.cpp"/>
|
||||
<F N="stopwatch.cpp"/>
|
||||
<F N="tdriver.cpp"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Header Files"
|
||||
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if">
|
||||
<F N="errorcodes.h"/>
|
||||
<F N="errorids.h"/>
|
||||
<F N="exceptclasses.h"/>
|
||||
<F N="idberrorinfo.h"/>
|
||||
<F N="logger.h"/>
|
||||
<F N="loggingid.h"/>
|
||||
<F N="messageids.h"/>
|
||||
<F N="messagelog.h"/>
|
||||
<F N="messageobj.h"/>
|
||||
<F N="sqllogger.h"/>
|
||||
<F N="stopwatch.h"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Resource Files"
|
||||
Filters="*.ico;*.cur;*.dlg"/>
|
||||
<Folder
|
||||
Name="Bitmaps"
|
||||
Filters="*.bmp"/>
|
||||
<Folder
|
||||
Name="Other Files"
|
||||
Filters="">
|
||||
<F N="ErrorMessage.txt"/>
|
||||
<F
|
||||
N="Makefile"
|
||||
Type="Makefile"/>
|
||||
<F N="MessageFile.txt"/>
|
||||
<F N="SubsystemIDs.txt"/>
|
||||
</Folder>
|
||||
</Files>
|
||||
</Project>
|
||||
|
48
utils/messageqcpp/bytestream.cpp
Normal file → Executable file
48
utils/messageqcpp/bytestream.cpp
Normal file → Executable file
@ -588,5 +588,53 @@ void ByteStream::peek(uuid& u) const
|
||||
memcpy(&u.data[0], fCurOutPtr, uuids::uuid::static_size());
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator<<(const float f)
|
||||
{
|
||||
int sz = sizeof(float);
|
||||
if (fBuf == 0 || (fCurInPtr - fBuf + sz > fMaxLen + ISSOverhead))
|
||||
growBuf(fMaxLen + BlockSize);
|
||||
*((float *) fCurInPtr) = f;
|
||||
fCurInPtr += sz;
|
||||
|
||||
return *this;
|
||||
}
|
||||
ByteStream& ByteStream::operator<<(const double d)
|
||||
{
|
||||
int sz = sizeof(double);
|
||||
if (fBuf == 0 || (fCurInPtr - fBuf + sz > fMaxLen + ISSOverhead))
|
||||
growBuf(fMaxLen + BlockSize);
|
||||
*((double *) fCurInPtr) = d;
|
||||
fCurInPtr += sz;
|
||||
|
||||
return *this;
|
||||
}
|
||||
ByteStream& ByteStream::operator>>(float& f)
|
||||
{
|
||||
peek(f);
|
||||
fCurOutPtr += sizeof(float);
|
||||
return *this;
|
||||
}
|
||||
ByteStream& ByteStream::operator>>(double& d)
|
||||
{
|
||||
peek(d);
|
||||
fCurOutPtr += sizeof(double);
|
||||
return *this;
|
||||
}
|
||||
void ByteStream::peek(float& f) const
|
||||
{
|
||||
if (length() < sizeof(float))
|
||||
throw underflow_error("ByteStream>int64_t: not enough data in stream to fill datatype");
|
||||
|
||||
f = *((float *) fCurOutPtr);
|
||||
}
|
||||
void ByteStream::peek(double& d) const
|
||||
{
|
||||
if (length() < sizeof(double))
|
||||
throw underflow_error("ByteStream>int64_t: not enough data in stream to fill datatype");
|
||||
|
||||
d = *((double *) fCurOutPtr);
|
||||
}
|
||||
|
||||
|
||||
}//namespace messageqcpp
|
||||
|
||||
|
30
utils/messageqcpp/bytestream.h
Normal file → Executable file
30
utils/messageqcpp/bytestream.h
Normal file → Executable file
@ -144,6 +144,16 @@ public:
|
||||
* push an uint64_t onto the end of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT ByteStream& operator<<(const uint64_t o);
|
||||
/**
|
||||
* push an float onto the end of the stream. The byte order is
|
||||
* whatever the native byte order is.
|
||||
*/
|
||||
EXPORT ByteStream& operator<<(const float f);
|
||||
/**
|
||||
* push an double onto the end of the stream. The byte order is
|
||||
* whatever the native byte order is.
|
||||
*/
|
||||
EXPORT ByteStream& operator<<(const double d);
|
||||
/**
|
||||
* push a std::string onto the end of the stream.
|
||||
*/
|
||||
@ -193,6 +203,16 @@ public:
|
||||
* extract an uint64_t from the front of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT ByteStream& operator>>(uint64_t& o);
|
||||
/**
|
||||
* extract a float from the front of the stream. The byte
|
||||
* order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT ByteStream& operator>>(float& f);
|
||||
/**
|
||||
* extract a double from the front of the stream. The byte
|
||||
* order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT ByteStream& operator>>(double& d);
|
||||
/**
|
||||
* extract a std::string from the front of the stream.
|
||||
*/
|
||||
@ -248,6 +268,16 @@ public:
|
||||
* Peek at an uint64_t from the front of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT void peek(uint64_t& o) const;
|
||||
/**
|
||||
* Peek at a float from the front of the stream. The byte order
|
||||
* is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT void peek(float& f) const;
|
||||
/**
|
||||
* Peek at a double from the front of the stream. The byte
|
||||
* order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT void peek(double& f) const;
|
||||
/**
|
||||
* Peek at a std::string from the front of the stream.
|
||||
*/
|
||||
|
462
utils/messageqcpp/messageqcpp.vpj
Normal file → Executable file
462
utils/messageqcpp/messageqcpp.vpj
Normal file → Executable file
@ -1,234 +1,234 @@
|
||||
<!DOCTYPE Project SYSTEM "http://www.slickedit.com/dtd/vse/10.0/vpj.dtd">
|
||||
<Project
|
||||
Version="10.0"
|
||||
VendorName="SlickEdit"
|
||||
TemplateName="GNU C/C++"
|
||||
WorkingDir=".">
|
||||
<Config
|
||||
Name="Debug"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdmessageqcpp.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -g -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -g -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Config
|
||||
Name="Release"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdmessageqcpp.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Files>
|
||||
<Folder
|
||||
Name="Source Files"
|
||||
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d">
|
||||
<F N="bytestream.cpp"/>
|
||||
<F N="compressed_iss.cpp"/>
|
||||
<F N="inetstreamsocket.cpp"/>
|
||||
<F N="iosocket.cpp"/>
|
||||
<F N="messagequeue.cpp"/>
|
||||
<F N="socketparms.cpp"/>
|
||||
<F N="tdriver.cpp"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Header Files"
|
||||
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if">
|
||||
<F N="bytestream.h"/>
|
||||
<F N="clientsocket.h"/>
|
||||
<F N="compressed_iss.h"/>
|
||||
<F N="inetstreamsocket.h"/>
|
||||
<F N="iosocket.h"/>
|
||||
<F N="messagequeue.h"/>
|
||||
<F N="serializeable.h"/>
|
||||
<F N="serversocket.h"/>
|
||||
<F N="socket.h"/>
|
||||
<F N="socketclosed.h"/>
|
||||
<F N="socketparms.h"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Resource Files"
|
||||
Filters="*.ico;*.cur;*.dlg"/>
|
||||
<Folder
|
||||
Name="Bitmaps"
|
||||
Filters="*.bmp"/>
|
||||
<Folder
|
||||
Name="Other Files"
|
||||
Filters="">
|
||||
<F
|
||||
N="Makefile"
|
||||
Type="Makefile"/>
|
||||
</Folder>
|
||||
</Files>
|
||||
Version="10.0"
|
||||
VendorName="SlickEdit"
|
||||
TemplateName="GNU C/C++"
|
||||
WorkingDir=".">
|
||||
<Config
|
||||
Name="Debug"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdmessageqcpp.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -g -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -g -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Config
|
||||
Name="Release"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdmessageqcpp.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Files>
|
||||
<Folder
|
||||
Name="Source Files"
|
||||
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d">
|
||||
<F N="bytestream.cpp"/>
|
||||
<F N="compressed_iss.cpp"/>
|
||||
<F N="inetstreamsocket.cpp"/>
|
||||
<F N="iosocket.cpp"/>
|
||||
<F N="messagequeue.cpp"/>
|
||||
<F N="socketparms.cpp"/>
|
||||
<F N="tdriver.cpp"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Header Files"
|
||||
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if">
|
||||
<F N="bytestream.h"/>
|
||||
<F N="clientsocket.h"/>
|
||||
<F N="compressed_iss.h"/>
|
||||
<F N="inetstreamsocket.h"/>
|
||||
<F N="iosocket.h"/>
|
||||
<F N="messagequeue.h"/>
|
||||
<F N="serializeable.h"/>
|
||||
<F N="serversocket.h"/>
|
||||
<F N="socket.h"/>
|
||||
<F N="socketclosed.h"/>
|
||||
<F N="socketparms.h"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Resource Files"
|
||||
Filters="*.ico;*.cur;*.dlg"/>
|
||||
<Folder
|
||||
Name="Bitmaps"
|
||||
Filters="*.bmp"/>
|
||||
<Folder
|
||||
Name="Other Files"
|
||||
Filters="">
|
||||
<F
|
||||
N="Makefile"
|
||||
Type="Makefile"/>
|
||||
</Folder>
|
||||
</Files>
|
||||
</Project>
|
||||
|
744
utils/rowgroup/rowaggregation.cpp
Normal file → Executable file
744
utils/rowgroup/rowaggregation.cpp
Normal file → Executable file
@ -28,7 +28,7 @@
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <limits>
|
||||
|
||||
#include <typeinfo>
|
||||
#include "joblisttypes.h"
|
||||
#include "resourcemanager.h"
|
||||
#include "groupconcat.h"
|
||||
@ -459,7 +459,6 @@ inline void RowAggregation::updateFloatSum(float val1, float val2, int64_t col)
|
||||
fRow.setFloatField(val1 + val2, col);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Verify if the column value is NULL
|
||||
// row(in) - Row to be included in aggregation.
|
||||
@ -721,6 +720,41 @@ void RowAggregation::setJoinRowGroups(vector<RowGroup> *pSmallSideRG, RowGroup *
|
||||
(*fSmallSideRGs)[i].initRow(&rowSmalls[i]);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// For UDAF, we need to sometimes start a new context.
|
||||
//
|
||||
// This will be called any number of times by each of the batchprimitiveprocessor
|
||||
// threads on the PM and by multple threads on the UM. It must remain
|
||||
// thread safe.
|
||||
//------------------------------------------------------------------------------
|
||||
void RowAggregation::resetUDAF(uint64_t funcColID)
|
||||
{
|
||||
// Get the UDAF class pointer and store in the row definition object.
|
||||
RowUDAFFunctionCol* rowUDAF = dynamic_cast<RowUDAFFunctionCol*>(fFunctionCols[funcColID].get());
|
||||
|
||||
// resetUDAF needs to be re-entrant. Since we're modifying the context object
|
||||
// by creating a new userData, we need a local copy. The copy constructor
|
||||
// doesn't copy userData.
|
||||
mcsv1sdk::mcsv1Context rgContext(rowUDAF->fUDAFContext);
|
||||
|
||||
// Call the user reset for the group userData. Since, at this point,
|
||||
// context's userData will be NULL, reset will generate a new one.
|
||||
mcsv1sdk::mcsv1_UDAF::ReturnCode rc;
|
||||
rc = rgContext.getFunction()->reset(&rgContext);
|
||||
if (rc == mcsv1sdk::mcsv1_UDAF::ERROR)
|
||||
{
|
||||
rowUDAF->bInterrupted = true;
|
||||
throw logging::QueryDataExcept(rgContext.getErrorMessage(), logging::aggregateFuncErr);
|
||||
}
|
||||
|
||||
fRow.setUserDataStore(fRowGroupOut->getRGData()->getUserDataStore());
|
||||
fRow.setUserData(rgContext,
|
||||
rgContext.getUserDataSP(),
|
||||
rgContext.getUserDataSize(),
|
||||
rowUDAF->fAuxColumnIndex);
|
||||
|
||||
rgContext.setUserData(NULL); // Prevents calling deleteUserData on the context.
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Initilalize the data members to meaningful values, setup the hashmap.
|
||||
@ -780,7 +814,7 @@ void RowAggregation::initialize()
|
||||
//------------------------------------------------------------------------------
|
||||
// Reset the working data to aggregate next logical block
|
||||
//------------------------------------------------------------------------------
|
||||
void RowAggregation::reset()
|
||||
void RowAggregation::aggReset()
|
||||
{
|
||||
fTotalRowCount = 0;
|
||||
fMaxTotalRowCount = AGG_ROWGROUP_SIZE;
|
||||
@ -798,15 +832,23 @@ void RowAggregation::reset()
|
||||
delete fAggMapPtr;
|
||||
fAggMapPtr = new RowAggMap_t(10, *fHasher, *fEq, *fAlloc);
|
||||
}
|
||||
|
||||
fResultDataVec.clear();
|
||||
fResultDataVec.push_back(fRowGroupOut->getRGData());
|
||||
|
||||
// For UDAF, reset the data
|
||||
for (uint64_t i = 0; i < fFunctionCols.size(); i++)
|
||||
{
|
||||
if (fFunctionCols[i]->fAggFunction == ROWAGG_UDAF)
|
||||
{
|
||||
resetUDAF(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RowAggregationUM::reset()
|
||||
void RowAggregationUM::aggReset()
|
||||
{
|
||||
RowAggregation::reset();
|
||||
RowAggregation::aggReset();
|
||||
|
||||
if (fKeyOnHeap)
|
||||
{
|
||||
@ -843,6 +885,15 @@ void RowAggregationUM::aggregateRowWithRemap(Row& row)
|
||||
attachGroupConcatAg();
|
||||
inserted.first->second = RowPosition(fResultDataVec.size()-1, fRowGroupOut->getRowCount()-1);
|
||||
|
||||
// If there's UDAF involved, reset the user data.
|
||||
for (uint64_t i = 0; i < fFunctionCols.size(); i++)
|
||||
{
|
||||
if (fFunctionCols[i]->fAggFunction == ROWAGG_UDAF)
|
||||
{
|
||||
resetUDAF(i);
|
||||
}
|
||||
}
|
||||
|
||||
// replace the key value with an equivalent copy, yes this is OK
|
||||
const_cast<RowPosition &>((inserted.first->first)) = pos;
|
||||
}
|
||||
@ -893,6 +944,16 @@ void RowAggregation::aggregateRow(Row& row)
|
||||
// replace the key value with an equivalent copy, yes this is OK
|
||||
const_cast<RowPosition &>(*(inserted.first)) =
|
||||
RowPosition(fResultDataVec.size() - 1, fRowGroupOut->getRowCount() - 1);
|
||||
|
||||
// If there's UDAF involved, reset the user data.
|
||||
for (uint64_t i = 0; i < fFunctionCols.size(); i++)
|
||||
{
|
||||
if (fFunctionCols[i]->fAggFunction == ROWAGG_UDAF)
|
||||
{
|
||||
resetUDAF(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
//fRow.setData(*(inserted.first));
|
||||
@ -1065,6 +1126,8 @@ void RowAggregation::makeAggFieldsNull(Row& row)
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
case execplan::CalpontSystemCatalog::VARBINARY:
|
||||
case execplan::CalpontSystemCatalog::BLOB:
|
||||
{
|
||||
int colWidth = fRowGroupOut->getColumnWidth(colOut);
|
||||
if (colWidth <= 8)
|
||||
@ -1386,7 +1449,7 @@ void RowAggregation::serialize(messageqcpp::ByteStream& bs) const
|
||||
bs << functionCount;
|
||||
|
||||
for (uint64_t i = 0; i < functionCount; i++)
|
||||
bs << *(fFunctionCols[i].get());
|
||||
fFunctionCols[i]->serialize(bs);
|
||||
}
|
||||
|
||||
|
||||
@ -1415,9 +1478,18 @@ void RowAggregation::deserialize(messageqcpp::ByteStream& bs)
|
||||
|
||||
for (uint64_t i = 0; i < functionCount; i++)
|
||||
{
|
||||
SP_ROWAGG_FUNC_t funct(
|
||||
new RowAggFunctionCol(ROWAGG_FUNCT_UNDEFINE, ROWAGG_FUNCT_UNDEFINE, 0, 0));
|
||||
bs >> *(funct.get());
|
||||
uint8_t funcType;
|
||||
bs.peek(funcType);
|
||||
SP_ROWAGG_FUNC_t funct;
|
||||
if (funcType == ROWAGG_UDAF)
|
||||
{
|
||||
funct.reset(new RowUDAFFunctionCol(0, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
funct.reset(new RowAggFunctionCol(ROWAGG_FUNCT_UNDEFINE, ROWAGG_FUNCT_UNDEFINE, 0, 0));
|
||||
}
|
||||
funct->deserialize(bs);
|
||||
fFunctionCols.push_back(funct);
|
||||
}
|
||||
}
|
||||
@ -1477,6 +1549,20 @@ void RowAggregation::updateEntry(const Row& rowIn)
|
||||
case ROWAGG_GROUP_CONCAT:
|
||||
break;
|
||||
|
||||
case ROWAGG_UDAF:
|
||||
{
|
||||
RowUDAFFunctionCol* rowUDAF = dynamic_cast<RowUDAFFunctionCol*>(fFunctionCols[i].get());
|
||||
if (rowUDAF)
|
||||
{
|
||||
doUDAF(rowIn, colIn, colOut, colOut + 1, rowUDAF);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw logic_error("(3)A UDAF function is called but there's no RowUDAFFunctionCol");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
@ -1729,6 +1815,113 @@ void RowAggregation::doStatistics(const Row& rowIn, int64_t colIn, int64_t colOu
|
||||
fRow.setLongDoubleField(fRow.getLongDoubleField(colAux+1) + valIn*valIn, colAux+1);
|
||||
}
|
||||
|
||||
void RowAggregation::doUDAF(const Row& rowIn, int64_t colIn, int64_t colOut, int64_t colAux,
|
||||
RowUDAFFunctionCol* rowUDAF)
|
||||
{
|
||||
std::vector<mcsv1sdk::ColumnDatum> valsIn;
|
||||
execplan::CalpontSystemCatalog::ColDataType colDataType = fRowGroupIn.getColTypes()[colIn];
|
||||
std::vector<uint32_t> dataFlags;
|
||||
|
||||
// Get the context for this rowGroup. Make a copy so we're thread safe.
|
||||
mcsv1sdk::mcsv1Context rgContext(rowUDAF->fUDAFContext);
|
||||
|
||||
// Turn on NULL flags
|
||||
std::vector<uint32_t> flags;
|
||||
uint32_t flag = 0;
|
||||
if (isNull(&fRowGroupIn, rowIn, colIn) == true)
|
||||
{
|
||||
if (rgContext.getRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS))
|
||||
{
|
||||
return;
|
||||
}
|
||||
flag |= mcsv1sdk::PARAM_IS_NULL;
|
||||
}
|
||||
flags.push_back(flag);
|
||||
rgContext.setDataFlags(&flags);
|
||||
|
||||
mcsv1sdk::ColumnDatum datum;
|
||||
|
||||
switch (colDataType)
|
||||
{
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
datum.dataType = execplan::CalpontSystemCatalog::BIGINT;
|
||||
datum.columnData = rowIn.getIntField(colIn);
|
||||
datum.scale = fRowGroupIn.getScale()[colIn];
|
||||
datum.precision = fRowGroupIn.getPrecision()[colIn];
|
||||
break;
|
||||
}
|
||||
case execplan::CalpontSystemCatalog::UTINYINT:
|
||||
case execplan::CalpontSystemCatalog::USMALLINT:
|
||||
case execplan::CalpontSystemCatalog::UMEDINT:
|
||||
case execplan::CalpontSystemCatalog::UINT:
|
||||
case execplan::CalpontSystemCatalog::UBIGINT:
|
||||
{
|
||||
datum.dataType = execplan::CalpontSystemCatalog::UBIGINT;
|
||||
datum.columnData = rowIn.getUintField(colIn);
|
||||
break;
|
||||
}
|
||||
case execplan::CalpontSystemCatalog::DOUBLE:
|
||||
case execplan::CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
datum.dataType = execplan::CalpontSystemCatalog::DOUBLE;
|
||||
datum.columnData = rowIn.getDoubleField(colIn);
|
||||
break;
|
||||
}
|
||||
case execplan::CalpontSystemCatalog::FLOAT:
|
||||
case execplan::CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
datum.dataType = execplan::CalpontSystemCatalog::FLOAT;
|
||||
datum.columnData = rowIn.getFloatField(colIn);
|
||||
break;
|
||||
}
|
||||
case execplan::CalpontSystemCatalog::DATE:
|
||||
case execplan::CalpontSystemCatalog::DATETIME:
|
||||
{
|
||||
datum.dataType = execplan::CalpontSystemCatalog::UBIGINT;
|
||||
datum.columnData = rowIn.getUintField(colIn);
|
||||
break;
|
||||
}
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
case execplan::CalpontSystemCatalog::VARBINARY:
|
||||
case execplan::CalpontSystemCatalog::CLOB:
|
||||
case execplan::CalpontSystemCatalog::BLOB:
|
||||
{
|
||||
datum.dataType = colDataType;
|
||||
datum.columnData = rowIn.getStringField(colIn);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "RowAggregation " << rgContext.getName() <<
|
||||
": No logic for data type: " << colDataType;
|
||||
throw logging::QueryDataExcept(errmsg.str(), logging::aggregateFuncErr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
valsIn.push_back(datum);
|
||||
|
||||
// The intermediate values are stored in userData referenced by colAux.
|
||||
rgContext.setUserData(fRow.getUserData(colAux));
|
||||
|
||||
mcsv1sdk::mcsv1_UDAF::ReturnCode rc;
|
||||
rc = rgContext.getFunction()->nextValue(&rgContext, valsIn);
|
||||
rgContext.setUserData(NULL);
|
||||
if (rc == mcsv1sdk::mcsv1_UDAF::ERROR)
|
||||
{
|
||||
rowUDAF->bInterrupted = true;
|
||||
throw logging::QueryDataExcept(rgContext.getErrorMessage(), logging::aggregateFuncErr);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Allocate a new data array for the output RowGroup
|
||||
@ -1781,7 +1974,6 @@ void RowAggregation::loadEmptySet(messageqcpp::ByteStream& bs)
|
||||
fEmptyRowGroup.serializeRGData(bs);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Row Aggregation constructor used on UM
|
||||
// For one-phase case, from projected RG to final aggregated RG
|
||||
@ -1790,10 +1982,11 @@ RowAggregationUM::RowAggregationUM(const vector<SP_ROWAGG_GRPBY_t>& rowAggGroupB
|
||||
const vector<SP_ROWAGG_FUNC_t>& rowAggFunctionCols,
|
||||
joblist::ResourceManager *r, boost::shared_ptr<int64_t> sessionLimit) :
|
||||
RowAggregation(rowAggGroupByCols, rowAggFunctionCols), fHasAvg(false), fKeyOnHeap(false),
|
||||
fHasStatsFunc(false), fTotalMemUsage(0), fRm(r), fSessionMemLimit(sessionLimit),
|
||||
fLastMemUsage(0), fNextRGIndex(0)
|
||||
fHasStatsFunc(false), fHasUDAF(false),fTotalMemUsage(0), fRm(r),
|
||||
fSessionMemLimit(sessionLimit), fLastMemUsage(0), fNextRGIndex(0)
|
||||
{
|
||||
// Check if there are any avg functions.
|
||||
// Check if there are any avg, stats or UDAF functions.
|
||||
// These flags are used in finalize.
|
||||
for (uint64_t i = 0; i < fFunctionCols.size(); i++)
|
||||
{
|
||||
if (fFunctionCols[i]->fAggFunction == ROWAGG_AVG ||
|
||||
@ -1801,6 +1994,8 @@ RowAggregationUM::RowAggregationUM(const vector<SP_ROWAGG_GRPBY_t>& rowAggGroupB
|
||||
fHasAvg = true;
|
||||
else if (fFunctionCols[i]->fAggFunction == ROWAGG_STATS)
|
||||
fHasStatsFunc = true;
|
||||
else if (fFunctionCols[i]->fAggFunction == ROWAGG_UDAF)
|
||||
fHasUDAF = true;
|
||||
}
|
||||
|
||||
// Check if all groupby column selected
|
||||
@ -1904,6 +2099,11 @@ void RowAggregationUM::finalize()
|
||||
calculateStatisticsFunctions();
|
||||
}
|
||||
|
||||
if (fHasUDAF)
|
||||
{
|
||||
calculateUDAFColumns();
|
||||
}
|
||||
|
||||
if (fGroupConcat.size() > 0)
|
||||
setGroupConcatString();
|
||||
|
||||
@ -1950,6 +2150,7 @@ void RowAggregationUM::updateEntry(const Row& rowIn)
|
||||
{
|
||||
int64_t colIn = fFunctionCols[i]->fInputColumnIndex;
|
||||
int64_t colOut = fFunctionCols[i]->fOutputColumnIndex;
|
||||
int64_t colAux = fFunctionCols[i]->fAuxColumnIndex;
|
||||
|
||||
switch (fFunctionCols[i]->fAggFunction)
|
||||
{
|
||||
@ -1971,14 +2172,12 @@ void RowAggregationUM::updateEntry(const Row& rowIn)
|
||||
// The sum and count on UM may not be put next to each other:
|
||||
// use colOut to store the sum;
|
||||
// use colAux to store the count.
|
||||
int64_t colAux = fFunctionCols[i]->fAuxColumnIndex;
|
||||
doAvg(rowIn, colIn, colOut, colAux);
|
||||
break;
|
||||
}
|
||||
|
||||
case ROWAGG_STATS:
|
||||
{
|
||||
int64_t colAux = fFunctionCols[i]->fAuxColumnIndex;
|
||||
doStatistics(rowIn, colIn, colOut, colAux);
|
||||
break;
|
||||
}
|
||||
@ -2004,6 +2203,20 @@ void RowAggregationUM::updateEntry(const Row& rowIn)
|
||||
case ROWAGG_CONSTANT:
|
||||
break;
|
||||
|
||||
case ROWAGG_UDAF:
|
||||
{
|
||||
RowUDAFFunctionCol* rowUDAF = dynamic_cast<RowUDAFFunctionCol*>(fFunctionCols[i].get());
|
||||
if (rowUDAF)
|
||||
{
|
||||
doUDAF(rowIn, colIn, colOut, colAux, rowUDAF);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw logic_error("(5)A UDAF function is called but there's no RowUDAFFunctionCol");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
// need a exception to show the value
|
||||
@ -2143,6 +2356,251 @@ void RowAggregationUM::calculateAvgColumns()
|
||||
}
|
||||
}
|
||||
|
||||
// Sets the value from valOut into column colOut, performing any conversions.
|
||||
void RowAggregationUM::SetUDAFValue(static_any::any& valOut, int64_t colOut)
|
||||
{
|
||||
static const static_any::any& charTypeId = (char)1;
|
||||
static const static_any::any& scharTypeId = (signed char)1;
|
||||
static const static_any::any& shortTypeId = (short)1;
|
||||
static const static_any::any& intTypeId = (int)1;
|
||||
static const static_any::any& longTypeId = (long)1;
|
||||
static const static_any::any& llTypeId = (long long)1;
|
||||
static const static_any::any& ucharTypeId = (unsigned char)1;
|
||||
static const static_any::any& ushortTypeId = (unsigned short)1;
|
||||
static const static_any::any& uintTypeId = (unsigned int)1;
|
||||
static const static_any::any& ulongTypeId = (unsigned long)1;
|
||||
static const static_any::any& ullTypeId = (unsigned long long)1;
|
||||
static const static_any::any& floatTypeId = (float)1;
|
||||
static const static_any::any& doubleTypeId = (double)1;
|
||||
static const std::string typeStr("");
|
||||
static const static_any::any& strTypeId = typeStr;
|
||||
|
||||
execplan::CalpontSystemCatalog::ColDataType colDataType = fRowGroupOut->getColTypes()[colOut];
|
||||
if (valOut.empty())
|
||||
{
|
||||
// Fields are initialized to NULL, which is what we want for empty;
|
||||
return;
|
||||
}
|
||||
|
||||
// This may seem a bit convoluted. Users shouldn't return a type
|
||||
// that they didn't set in mcsv1_UDAF::init(), but this
|
||||
// handles whatever return type is given and casts
|
||||
// it to whatever they said to return.
|
||||
int64_t intOut = 0;
|
||||
uint64_t uintOut = 0;
|
||||
float floatOut = 0.0;
|
||||
double doubleOut = 0.0;
|
||||
ostringstream oss;
|
||||
std::string strOut;
|
||||
|
||||
if (valOut.compatible(charTypeId))
|
||||
{
|
||||
uintOut = intOut = valOut.cast<char>();
|
||||
floatOut = intOut;
|
||||
oss << intOut;
|
||||
}
|
||||
else if (valOut.compatible(scharTypeId))
|
||||
{
|
||||
uintOut = intOut = valOut.cast<signed char>();
|
||||
floatOut = intOut;
|
||||
oss << intOut;
|
||||
}
|
||||
else if (valOut.compatible(shortTypeId))
|
||||
{
|
||||
uintOut = intOut = valOut.cast<short>();
|
||||
floatOut = intOut;
|
||||
oss << intOut;
|
||||
}
|
||||
else if (valOut.compatible(intTypeId))
|
||||
{
|
||||
uintOut = intOut = valOut.cast<int>();
|
||||
floatOut = intOut;
|
||||
oss << intOut;
|
||||
}
|
||||
else if (valOut.compatible(longTypeId))
|
||||
{
|
||||
uintOut = intOut = valOut.cast<long>();
|
||||
floatOut = intOut;
|
||||
oss << intOut;
|
||||
}
|
||||
else if (valOut.compatible(llTypeId))
|
||||
{
|
||||
uintOut = intOut = valOut.cast<long long>();
|
||||
floatOut = intOut;
|
||||
oss << intOut;
|
||||
}
|
||||
else if (valOut.compatible(ucharTypeId))
|
||||
{
|
||||
intOut = uintOut = valOut.cast<unsigned char>();
|
||||
floatOut = uintOut;
|
||||
oss << uintOut;
|
||||
}
|
||||
else if (valOut.compatible(ushortTypeId))
|
||||
{
|
||||
intOut = uintOut = valOut.cast<unsigned short>();
|
||||
floatOut = uintOut;
|
||||
oss << uintOut;
|
||||
}
|
||||
else if (valOut.compatible(uintTypeId))
|
||||
{
|
||||
intOut = uintOut = valOut.cast<unsigned int>();
|
||||
floatOut = uintOut;
|
||||
oss << uintOut;
|
||||
}
|
||||
else if (valOut.compatible(ulongTypeId))
|
||||
{
|
||||
intOut = uintOut = valOut.cast<unsigned long>();
|
||||
floatOut = uintOut;
|
||||
oss << uintOut;
|
||||
}
|
||||
else if (valOut.compatible(ullTypeId))
|
||||
{
|
||||
intOut = uintOut = valOut.cast<unsigned long long>();
|
||||
floatOut = uintOut;
|
||||
oss << uintOut;
|
||||
}
|
||||
else if (valOut.compatible(floatTypeId))
|
||||
{
|
||||
floatOut = valOut.cast<float>();
|
||||
doubleOut = floatOut;
|
||||
intOut = uintOut = floatOut;
|
||||
oss << floatOut;
|
||||
}
|
||||
else if (valOut.compatible(doubleTypeId))
|
||||
{
|
||||
doubleOut = valOut.cast<double>();
|
||||
floatOut = (float)doubleOut;
|
||||
uintOut = (uint64_t)doubleOut;
|
||||
intOut = (int64_t)doubleOut;
|
||||
oss << doubleOut;
|
||||
}
|
||||
|
||||
if (valOut.compatible(strTypeId))
|
||||
{
|
||||
std::string strOut = valOut.cast<std::string>();
|
||||
// Convert the string to numeric type, just in case.
|
||||
intOut = atol(strOut.c_str());
|
||||
uintOut = strtoul(strOut.c_str(), NULL, 10);
|
||||
doubleOut = strtod(strOut.c_str(), NULL);
|
||||
floatOut = (float)doubleOut;
|
||||
}
|
||||
else
|
||||
{
|
||||
strOut = oss.str();
|
||||
}
|
||||
|
||||
switch (colDataType)
|
||||
{
|
||||
case execplan::CalpontSystemCatalog::BIT:
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
fRow.setIntField<1>(intOut, colOut);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
fRow.setIntField<2>(intOut, colOut);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
fRow.setIntField<4>(intOut, colOut);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
fRow.setIntField<8>(intOut, colOut);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::UTINYINT:
|
||||
fRow.setUintField<1>(uintOut, colOut);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::USMALLINT:
|
||||
case execplan::CalpontSystemCatalog::UMEDINT:
|
||||
fRow.setUintField<2>(uintOut, colOut);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::UINT:
|
||||
fRow.setUintField<4>(uintOut, colOut);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::UBIGINT:
|
||||
fRow.setUintField<8>(uintOut, colOut);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::DATE:
|
||||
case execplan::CalpontSystemCatalog::DATETIME:
|
||||
|
||||
fRow.setUintField<8>(uintOut, colOut);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::FLOAT:
|
||||
case execplan::CalpontSystemCatalog::UFLOAT:
|
||||
fRow.setFloatField(floatOut, colOut);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::DOUBLE:
|
||||
case execplan::CalpontSystemCatalog::UDOUBLE:
|
||||
fRow.setDoubleField(doubleOut, colOut);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
fRow.setStringField(strOut, colOut);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::VARBINARY:
|
||||
case execplan::CalpontSystemCatalog::CLOB:
|
||||
case execplan::CalpontSystemCatalog::BLOB:
|
||||
fRow.setVarBinaryField(strOut, colOut);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "RowAggregation: No logic for data type: " << colDataType;
|
||||
throw logging::QueryDataExcept(errmsg.str(), logging::aggregateFuncErr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// For each rowgroup, calculate the final value.
|
||||
//------------------------------------------------------------------------------
|
||||
void RowAggregationUM::calculateUDAFColumns()
|
||||
{
|
||||
RowUDAFFunctionCol* rowUDAF = NULL;
|
||||
static_any::any valOut;
|
||||
|
||||
|
||||
for (uint64_t i = 0; i < fFunctionCols.size(); i++)
|
||||
{
|
||||
if (fFunctionCols[i]->fAggFunction != ROWAGG_UDAF)
|
||||
continue;
|
||||
|
||||
rowUDAF = dynamic_cast<RowUDAFFunctionCol*>(fFunctionCols[i].get());
|
||||
mcsv1sdk::mcsv1Context rgContext(rowUDAF->fUDAFContext);
|
||||
|
||||
int64_t colOut = rowUDAF->fOutputColumnIndex;
|
||||
int64_t colAux = rowUDAF->fAuxColumnIndex;
|
||||
|
||||
// At this point, each row is an aggregated GROUP BY.
|
||||
for (uint64_t j = 0; j < fRowGroupOut->getRowCount(); j++)
|
||||
{
|
||||
// Get the user data from the row and evaluate.
|
||||
fRowGroupOut->getRow(j, &fRow);
|
||||
|
||||
// Turn the NULL flag off. We can't know NULL at this point
|
||||
rgContext.setDataFlags(NULL);
|
||||
|
||||
// The intermediate values are stored in colAux.
|
||||
rgContext.setUserData(fRow.getUserData(colAux));
|
||||
// Call the UDAF evaluate function
|
||||
mcsv1sdk::mcsv1_UDAF::ReturnCode rc;
|
||||
rc = rgContext.getFunction()->evaluate(&rgContext, valOut);
|
||||
rgContext.setUserData(NULL);
|
||||
if (rc == mcsv1sdk::mcsv1_UDAF::ERROR)
|
||||
{
|
||||
rowUDAF->bInterrupted = true;
|
||||
throw logging::QueryDataExcept(rgContext.getErrorMessage(), logging::aggregateFuncErr);
|
||||
}
|
||||
|
||||
// Set the returned value into the output row
|
||||
SetUDAFValue(valOut, colOut);
|
||||
}
|
||||
rgContext.setUserData(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// After all PM rowgroups received, calculate the statistics.
|
||||
@ -2222,7 +2680,6 @@ void RowAggregationUM::calculateStatisticsFunctions()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Fix the duplicate function columns -- same function same column id repeated
|
||||
//------------------------------------------------------------------------------
|
||||
@ -2248,7 +2705,6 @@ void RowAggregationUM::fixDuplicates(RowAggFunctionType funct)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Evaluate the functions and expressions
|
||||
//------------------------------------------------------------------------------
|
||||
@ -2262,7 +2718,6 @@ void RowAggregationUM::evaluateExpression()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Calculate the aggregate(constant) columns
|
||||
//------------------------------------------------------------------------------
|
||||
@ -2395,6 +2850,58 @@ void RowAggregationUM::doNullConstantAggregate(const ConstantAggData& aggData, u
|
||||
}
|
||||
break;
|
||||
|
||||
case ROWAGG_UDAF:
|
||||
{
|
||||
int64_t rowCnt = 0;
|
||||
// For a NULL constant, call nextValue with NULL and then evaluate.
|
||||
bool bInterrupted = false;
|
||||
mcsv1sdk::mcsv1Context context;
|
||||
context.setRowCnt(rowCnt);
|
||||
context.setInterrupted(bInterrupted);
|
||||
context.createUserData();
|
||||
mcsv1sdk::mcsv1_UDAF::ReturnCode rc;
|
||||
std::vector<mcsv1sdk::ColumnDatum> valsIn;
|
||||
|
||||
// Call a reset, then nextValue, then execute. This will evaluate
|
||||
// the UDAF for the constant.
|
||||
rc = context.getFunction()->reset(&context);
|
||||
if (rc == mcsv1sdk::mcsv1_UDAF::ERROR)
|
||||
{
|
||||
context.setInterrupted(true);
|
||||
throw logging::QueryDataExcept(context.getErrorMessage(), logging::aggregateFuncErr);
|
||||
}
|
||||
|
||||
// Turn the NULL and CONSTANT flags on.
|
||||
std::vector<uint32_t> flags;
|
||||
uint32_t flag = mcsv1sdk::PARAM_IS_NULL | mcsv1sdk::PARAM_IS_CONSTANT;
|
||||
flags.push_back(flag);
|
||||
context.setDataFlags(&flags);
|
||||
|
||||
// Create a dummy datum
|
||||
mcsv1sdk::ColumnDatum datum;
|
||||
datum.dataType = execplan::CalpontSystemCatalog::BIGINT;
|
||||
datum.columnData = 0;
|
||||
valsIn.push_back(datum);
|
||||
|
||||
rc = context.getFunction()->nextValue(&context, valsIn);
|
||||
if (rc == mcsv1sdk::mcsv1_UDAF::ERROR)
|
||||
{
|
||||
context.setInterrupted(true);
|
||||
throw logging::QueryDataExcept(context.getErrorMessage(), logging::aggregateFuncErr);
|
||||
}
|
||||
static_any::any valOut;
|
||||
rc = context.getFunction()->evaluate(&context, valOut);
|
||||
if (rc == mcsv1sdk::mcsv1_UDAF::ERROR)
|
||||
{
|
||||
context.setInterrupted(true);
|
||||
throw logging::QueryDataExcept(context.getErrorMessage(), logging::aggregateFuncErr);
|
||||
}
|
||||
// Set the returned value into the output row
|
||||
SetUDAFValue(valOut, colOut);
|
||||
context.setDataFlags(NULL);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
fRow.setStringField("", colOut);
|
||||
@ -2674,6 +3181,133 @@ void RowAggregationUM::doNotNullConstantAggregate(const ConstantAggData& aggData
|
||||
}
|
||||
break;
|
||||
|
||||
case ROWAGG_UDAF:
|
||||
{
|
||||
int64_t rowCnt = 0;
|
||||
bool bInterrupted = false;
|
||||
mcsv1sdk::mcsv1Context context;
|
||||
context.setRowCnt(rowCnt);
|
||||
context.setInterrupted(bInterrupted);
|
||||
// Try the complex data initiation. If not implemented, use the simple,
|
||||
context.createUserData();
|
||||
mcsv1sdk::mcsv1_UDAF::ReturnCode rc;
|
||||
std::vector<mcsv1sdk::ColumnDatum> valsIn;
|
||||
|
||||
// Call a reset, then nextValue, then execute. This will evaluate
|
||||
// the UDAF for the constant.
|
||||
rc = context.getFunction()->reset(&context);
|
||||
if (rc == mcsv1sdk::mcsv1_UDAF::ERROR)
|
||||
{
|
||||
context.setInterrupted(true);
|
||||
throw logging::QueryDataExcept(context.getErrorMessage(), logging::aggregateFuncErr);
|
||||
}
|
||||
|
||||
// Turn the CONSTANT flags on.
|
||||
std::vector<uint32_t> flags;
|
||||
uint32_t flag = mcsv1sdk::PARAM_IS_CONSTANT;
|
||||
flags.push_back(flag);
|
||||
context.setDataFlags(&flags);
|
||||
|
||||
// Create a datum item for sending to UDAF
|
||||
mcsv1sdk::ColumnDatum datum;
|
||||
datum.dataType = (CalpontSystemCatalog::ColDataType)colDataType;
|
||||
|
||||
switch (colDataType)
|
||||
{
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
{
|
||||
datum.columnData = strtol(aggData.fConstValue.c_str(), 0, 10);
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::UTINYINT:
|
||||
case execplan::CalpontSystemCatalog::USMALLINT:
|
||||
case execplan::CalpontSystemCatalog::UMEDINT:
|
||||
case execplan::CalpontSystemCatalog::UINT:
|
||||
case execplan::CalpontSystemCatalog::UBIGINT:
|
||||
{
|
||||
datum.columnData = strtoul(aggData.fConstValue.c_str(), 0, 10);
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
double dbl = strtod(aggData.fConstValue.c_str(), 0);
|
||||
double scale = pow(10.0, (double) fRowGroupOut->getScale()[i]);
|
||||
datum.columnData = (int64_t)(scale*dbl);
|
||||
datum.scale = scale;
|
||||
datum.precision = fRowGroupOut->getPrecision()[i];
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DOUBLE:
|
||||
case execplan::CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
datum.columnData = strtod(aggData.fConstValue.c_str(), 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::FLOAT:
|
||||
case execplan::CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
datum.columnData = strtod(aggData.fConstValue.c_str(), 0);
|
||||
#else
|
||||
datum.columnData = strtof(aggData.fConstValue.c_str(), 0);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DATE:
|
||||
{
|
||||
datum.columnData = DataConvert::stringToDate(aggData.fConstValue);
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::DATETIME:
|
||||
{
|
||||
datum.columnData = DataConvert::stringToDatetime(aggData.fConstValue);
|
||||
}
|
||||
break;
|
||||
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
case execplan::CalpontSystemCatalog::VARBINARY:
|
||||
case execplan::CalpontSystemCatalog::BLOB:
|
||||
default:
|
||||
{
|
||||
datum.columnData = aggData.fConstValue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
valsIn.push_back(datum);
|
||||
rc = context.getFunction()->nextValue(&context, valsIn);
|
||||
if (rc == mcsv1sdk::mcsv1_UDAF::ERROR)
|
||||
{
|
||||
context.setInterrupted(true);
|
||||
throw logging::QueryDataExcept(context.getErrorMessage(), logging::aggregateFuncErr);
|
||||
}
|
||||
|
||||
static_any::any valOut;
|
||||
rc = context.getFunction()->evaluate(&context, valOut);
|
||||
if (rc == mcsv1sdk::mcsv1_UDAF::ERROR)
|
||||
{
|
||||
context.setInterrupted(true);
|
||||
throw logging::QueryDataExcept(context.getErrorMessage(), logging::aggregateFuncErr);
|
||||
}
|
||||
// Set the returned value into the output row
|
||||
SetUDAFValue(valOut, colOut);
|
||||
context.setDataFlags(NULL);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
fRow.setStringField(aggData.fConstValue, colOut);
|
||||
@ -2823,6 +3457,7 @@ void RowAggregationUMP2::updateEntry(const Row& rowIn)
|
||||
{
|
||||
int64_t colIn = fFunctionCols[i]->fInputColumnIndex;
|
||||
int64_t colOut = fFunctionCols[i]->fOutputColumnIndex;
|
||||
int64_t colAux = fFunctionCols[i]->fAuxColumnIndex;
|
||||
|
||||
switch (fFunctionCols[i]->fAggFunction)
|
||||
{
|
||||
@ -2845,14 +3480,12 @@ void RowAggregationUMP2::updateEntry(const Row& rowIn)
|
||||
// The sum and count on UM may not be put next to each other:
|
||||
// use colOut to store the sum;
|
||||
// use colAux to store the count.
|
||||
int64_t colAux = fFunctionCols[i]->fAuxColumnIndex;
|
||||
doAvg(rowIn, colIn, colOut, colAux);
|
||||
break;
|
||||
}
|
||||
|
||||
case ROWAGG_STATS:
|
||||
{
|
||||
int64_t colAux = fFunctionCols[i]->fAuxColumnIndex;
|
||||
doStatistics(rowIn, colIn, colOut, colAux);
|
||||
break;
|
||||
}
|
||||
@ -2878,6 +3511,20 @@ void RowAggregationUMP2::updateEntry(const Row& rowIn)
|
||||
case ROWAGG_CONSTANT:
|
||||
break;
|
||||
|
||||
case ROWAGG_UDAF:
|
||||
{
|
||||
RowUDAFFunctionCol* rowUDAF = dynamic_cast<RowUDAFFunctionCol*>(fFunctionCols[i].get());
|
||||
if (rowUDAF)
|
||||
{
|
||||
doUDAF(rowIn, colIn, colOut, colAux, rowUDAF);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw logic_error("(6)A UDAF function is called but there's no RowUDAFFunctionCol");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
@ -3050,6 +3697,43 @@ void RowAggregationUMP2::doBitOp(const Row& rowIn, int64_t colIn, int64_t colOut
|
||||
fRow.setUintField(valIn ^ valOut, colOut);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Subaggregate the UDAF. This calls subaggregate for each partially
|
||||
// aggregated row returned by the PM
|
||||
// rowIn(in) - Row to be included in aggregation.
|
||||
// colIn(in) - column in the input row group
|
||||
// colOut(in) - column in the output row group
|
||||
// colAux(in) - Where the UDAF userdata resides
|
||||
// rowUDAF(in) - pointer to the RowUDAFFunctionCol for this UDAF instance
|
||||
//------------------------------------------------------------------------------
|
||||
void RowAggregationUMP2::doUDAF(const Row& rowIn, int64_t colIn, int64_t colOut, int64_t colAux,
|
||||
RowUDAFFunctionCol* rowUDAF)
|
||||
{
|
||||
static_any::any valOut;
|
||||
mcsv1sdk::mcsv1Context rgContext(rowUDAF->fUDAFContext);
|
||||
|
||||
// Turn on NULL flags
|
||||
std::vector<uint32_t> flags;
|
||||
uint32_t flag = 0;
|
||||
if (isNull(&fRowGroupIn, rowIn, colIn) == true)
|
||||
flag |= mcsv1sdk::PARAM_IS_NULL;
|
||||
flags.push_back(flag);
|
||||
rgContext.setDataFlags(&flags);
|
||||
|
||||
// The intermediate values are stored in colAux.
|
||||
rgContext.setUserData(fRow.getUserData(colAux));
|
||||
|
||||
// Call the UDAF subEvaluate method
|
||||
mcsv1sdk::mcsv1_UDAF::ReturnCode rc;
|
||||
rc = rgContext.getFunction()->subEvaluate(&rgContext, rowIn.getUserData(colIn+1).get());
|
||||
rgContext.setUserData(NULL);
|
||||
if (rc == mcsv1sdk::mcsv1_UDAF::ERROR)
|
||||
{
|
||||
rowUDAF->bInterrupted = true;
|
||||
throw logging::QueryDataExcept(rgContext.getErrorMessage(), logging::aggregateFuncErr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
@ -3163,6 +3847,7 @@ void RowAggregationDistinct::updateEntry(const Row& rowIn)
|
||||
{
|
||||
int64_t colIn = fFunctionCols[i]->fInputColumnIndex;
|
||||
int64_t colOut = fFunctionCols[i]->fOutputColumnIndex;
|
||||
int64_t colAux = fFunctionCols[i]->fAuxColumnIndex;
|
||||
|
||||
switch (fFunctionCols[i]->fAggFunction)
|
||||
{
|
||||
@ -3192,7 +3877,6 @@ void RowAggregationDistinct::updateEntry(const Row& rowIn)
|
||||
// The sum and count on UM may not be put next to each other:
|
||||
// use colOut to store the sum;
|
||||
// use colAux to store the count.
|
||||
int64_t colAux = fFunctionCols[i]->fAuxColumnIndex;
|
||||
doAvg(rowIn, colIn, colOut, colAux);
|
||||
break;
|
||||
}
|
||||
@ -3202,14 +3886,12 @@ void RowAggregationDistinct::updateEntry(const Row& rowIn)
|
||||
// The sum and count on UM may not be put next to each other:
|
||||
// use colOut to store the sum;
|
||||
// use colAux to store the count.
|
||||
int64_t colAux = fFunctionCols[i]->fAuxColumnIndex;
|
||||
RowAggregation::doAvg(rowIn, colIn, colOut, colAux);
|
||||
break;
|
||||
}
|
||||
|
||||
case ROWAGG_STATS:
|
||||
{
|
||||
int64_t colAux = fFunctionCols[i]->fAuxColumnIndex;
|
||||
doStatistics(rowIn, colIn, colOut, colAux);
|
||||
break;
|
||||
}
|
||||
@ -3235,6 +3917,20 @@ void RowAggregationDistinct::updateEntry(const Row& rowIn)
|
||||
case ROWAGG_CONSTANT:
|
||||
break;
|
||||
|
||||
case ROWAGG_UDAF:
|
||||
{
|
||||
RowUDAFFunctionCol* rowUDAF = dynamic_cast<RowUDAFFunctionCol*>(fFunctionCols[i].get());
|
||||
if (rowUDAF)
|
||||
{
|
||||
doUDAF(rowIn, colIn, colOut, colAux, rowUDAF);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw logic_error("(7)A UDAF function is called but there's no RowUDAFFunctionCol");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
|
104
utils/rowgroup/rowaggregation.h
Normal file → Executable file
104
utils/rowgroup/rowaggregation.h
Normal file → Executable file
@ -49,6 +49,7 @@
|
||||
#include "hasher.h"
|
||||
#include "stlpoolallocator.h"
|
||||
#include "returnedcolumn.h"
|
||||
#include "mcsv1_udaf.h"
|
||||
|
||||
// To do: move code that depends on joblist to a proper subsystem.
|
||||
namespace joblist
|
||||
@ -64,6 +65,7 @@ struct RowPosition
|
||||
{
|
||||
uint64_t group:48;
|
||||
uint64_t row:16;
|
||||
|
||||
static const uint64_t MSB = 0x800000000000ULL; //48th bit is set
|
||||
inline RowPosition(uint64_t g, uint64_t r) : group(g), row(r) { }
|
||||
inline RowPosition() { }
|
||||
@ -105,6 +107,9 @@ enum RowAggFunctionType
|
||||
// Constant
|
||||
ROWAGG_CONSTANT,
|
||||
|
||||
// User Defined Aggregate Function
|
||||
ROWAGG_UDAF,
|
||||
|
||||
// internal function type to avoid duplicate the work
|
||||
// handling ROWAGG_COUNT_NO_OP, ROWAGG_DUP_FUNCT and ROWAGG_DUP_AVG is a little different
|
||||
// ROWAGG_COUNT_NO_OP : count done by AVG, no need to copy
|
||||
@ -169,7 +174,10 @@ struct RowAggFunctionCol
|
||||
int32_t inputColIndex, int32_t outputColIndex, int32_t auxColIndex = -1) :
|
||||
fAggFunction(aggFunction), fStatsFunction(stats), fInputColumnIndex(inputColIndex),
|
||||
fOutputColumnIndex(outputColIndex), fAuxColumnIndex(auxColIndex) {}
|
||||
~RowAggFunctionCol() {}
|
||||
virtual ~RowAggFunctionCol() {}
|
||||
|
||||
virtual void serialize(messageqcpp::ByteStream& bs) const;
|
||||
virtual void deserialize(messageqcpp::ByteStream& bs);
|
||||
|
||||
RowAggFunctionType fAggFunction; // aggregate function
|
||||
// statistics function stores ROWAGG_STATS in fAggFunction and real function in fStatsFunction
|
||||
@ -178,24 +186,86 @@ struct RowAggFunctionCol
|
||||
uint32_t fInputColumnIndex;
|
||||
uint32_t fOutputColumnIndex;
|
||||
|
||||
// fAuxColumnIndex is used in 3 cases:
|
||||
// fAuxColumnIndex is used in 4 cases:
|
||||
// 1. for AVG - point to the count column, the fInputColumnIndex is for sum
|
||||
// 2. for statistics function - point to sum(x), +1 is sum(x**2)
|
||||
// 3. for duplicate - point to the real aggretate column to be copied from
|
||||
// 3. for UDAF - contain the context user data as binary
|
||||
// 4. for duplicate - point to the real aggretate column to be copied from
|
||||
// Set only on UM, the fAuxColumnIndex is defaulted to fOutputColumnIndex+1 on PM.
|
||||
uint32_t fAuxColumnIndex;
|
||||
};
|
||||
|
||||
inline messageqcpp::ByteStream& operator<<(messageqcpp::ByteStream& b, RowAggFunctionCol& o)
|
||||
{ return (b << (uint8_t)o.fAggFunction << o.fInputColumnIndex << o.fOutputColumnIndex); }
|
||||
inline messageqcpp::ByteStream& operator>>(messageqcpp::ByteStream& b, RowAggFunctionCol& o)
|
||||
{ return (b >> (uint8_t&)o.fAggFunction >> o.fInputColumnIndex >> o.fOutputColumnIndex); }
|
||||
|
||||
struct RowUDAFFunctionCol : public RowAggFunctionCol
|
||||
{
|
||||
RowUDAFFunctionCol(mcsv1sdk::mcsv1Context& context, int32_t inputColIndex,
|
||||
int32_t outputColIndex, int32_t auxColIndex = -1) :
|
||||
RowAggFunctionCol(ROWAGG_UDAF, ROWAGG_FUNCT_UNDEFINE,
|
||||
inputColIndex, outputColIndex, auxColIndex),
|
||||
fUDAFContext(context), bInterrupted(false)
|
||||
{
|
||||
fUDAFContext.setInterrupted(&bInterrupted);
|
||||
}
|
||||
|
||||
RowUDAFFunctionCol(int32_t inputColIndex,
|
||||
int32_t outputColIndex, int32_t auxColIndex = -1) :
|
||||
RowAggFunctionCol(ROWAGG_UDAF, ROWAGG_FUNCT_UNDEFINE,
|
||||
inputColIndex, outputColIndex, auxColIndex),
|
||||
bInterrupted(false)
|
||||
{}
|
||||
RowUDAFFunctionCol(const RowUDAFFunctionCol& rhs) : RowAggFunctionCol(ROWAGG_UDAF, ROWAGG_FUNCT_UNDEFINE,
|
||||
rhs.fInputColumnIndex, rhs.fOutputColumnIndex, rhs.fAuxColumnIndex), fUDAFContext(rhs.fUDAFContext)
|
||||
{}
|
||||
|
||||
virtual ~RowUDAFFunctionCol() {}
|
||||
|
||||
virtual void serialize(messageqcpp::ByteStream& bs) const;
|
||||
virtual void deserialize(messageqcpp::ByteStream& bs);
|
||||
|
||||
mcsv1sdk::mcsv1Context fUDAFContext; // The UDAF context
|
||||
bool bInterrupted; // Shared by all the threads
|
||||
};
|
||||
|
||||
inline void RowAggFunctionCol::serialize(messageqcpp::ByteStream& bs) const
|
||||
{
|
||||
bs << (uint8_t)fAggFunction;
|
||||
bs << fInputColumnIndex;
|
||||
bs << fOutputColumnIndex;
|
||||
}
|
||||
|
||||
inline void RowAggFunctionCol::deserialize(messageqcpp::ByteStream& bs)
|
||||
{
|
||||
bs >> (uint8_t&)fAggFunction;
|
||||
bs >> fInputColumnIndex;
|
||||
bs >> fOutputColumnIndex;
|
||||
}
|
||||
|
||||
inline void RowUDAFFunctionCol::serialize(messageqcpp::ByteStream& bs) const
|
||||
{
|
||||
RowAggFunctionCol::serialize(bs);
|
||||
fUDAFContext.serialize(bs);
|
||||
}
|
||||
|
||||
inline void RowUDAFFunctionCol::deserialize(messageqcpp::ByteStream& bs)
|
||||
{
|
||||
// This deserialize is called when the function gets to PrimProc.
|
||||
// reset is called because we're starting a new sub-evaluate cycle.
|
||||
RowAggFunctionCol::deserialize(bs);
|
||||
fUDAFContext.unserialize(bs);
|
||||
fUDAFContext.setInterrupted(&bInterrupted);
|
||||
mcsv1sdk::mcsv1_UDAF::ReturnCode rc;
|
||||
rc = fUDAFContext.getFunction()->reset(&fUDAFContext);
|
||||
if (rc == mcsv1sdk::mcsv1_UDAF::ERROR)
|
||||
{
|
||||
bInterrupted = true;
|
||||
throw logging::QueryDataExcept(fUDAFContext.getErrorMessage(), logging::aggregateFuncErr);
|
||||
}
|
||||
}
|
||||
|
||||
struct ConstantAggData
|
||||
{
|
||||
std::string fConstValue;
|
||||
std::string fUDAFName; // If a UDAF is called with constant.
|
||||
RowAggFunctionType fOp;
|
||||
bool fIsNull;
|
||||
|
||||
@ -205,6 +275,10 @@ struct ConstantAggData
|
||||
ConstantAggData(const std::string& v, RowAggFunctionType f, bool n) :
|
||||
fConstValue(v), fOp(f), fIsNull(n)
|
||||
{}
|
||||
|
||||
ConstantAggData(const std::string& v, const std::string u, RowAggFunctionType f, bool n) :
|
||||
fConstValue(v), fUDAFName(u), fOp(f), fIsNull(n)
|
||||
{}
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<RowAggGroupByCol> SP_ROWAGG_GRPBY_t;
|
||||
@ -377,7 +451,7 @@ class RowAggregation : public messageqcpp::Serializeable
|
||||
|
||||
/** @brief reset RowAggregation outputRowGroup and hashMap
|
||||
*/
|
||||
virtual void reset();
|
||||
virtual void aggReset();
|
||||
|
||||
/** @brief Define content of data to be aggregated and its aggregated output.
|
||||
*
|
||||
@ -470,12 +544,15 @@ class RowAggregation : public messageqcpp::Serializeable
|
||||
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, RowUDAFFunctionCol* rowUDAF);
|
||||
virtual bool countSpecial(const RowGroup* pRG)
|
||||
{ fRow.setIntField<8>(fRow.getIntField<8>(0) + pRG->getRowCount(), 0); return true; }
|
||||
|
||||
virtual bool newRowGroup();
|
||||
virtual void clearAggMap() { if (fAggMapPtr) fAggMapPtr->clear(); }
|
||||
|
||||
void resetUDAF(uint64_t funcColID);
|
||||
|
||||
inline bool isNull(const RowGroup* pRowGroup, const Row& row, int64_t col);
|
||||
inline void makeAggFieldsNull(Row& row);
|
||||
inline void copyNullRow(Row& row) { copyRow(fNullRow, &row); }
|
||||
@ -537,7 +614,6 @@ class RowAggregation : public messageqcpp::Serializeable
|
||||
friend class AggComparator;
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/** @brief derived Class that aggregates multi-rowgroups on UM
|
||||
* One-phase case: aggregate from projected RG to final aggregated RG.
|
||||
@ -602,7 +678,7 @@ class RowAggregationUM : public RowAggregation
|
||||
|
||||
void aggregateRow(Row &);
|
||||
//void initialize();
|
||||
virtual void reset();
|
||||
virtual void aggReset();
|
||||
|
||||
void setInputOutput(const RowGroup& pRowGroupIn, RowGroup* pRowGroupOut);
|
||||
|
||||
@ -628,6 +704,12 @@ class RowAggregationUM : public RowAggregation
|
||||
// calculate the statistics function all rows received. UM only function.
|
||||
void calculateStatisticsFunctions();
|
||||
|
||||
// Sets the value from valOut into column colOut, performing any conversions.
|
||||
void SetUDAFValue(static_any::any& valOut, int64_t colOut);
|
||||
|
||||
// calculate the UDAF function all rows received. UM only function.
|
||||
void calculateUDAFColumns();
|
||||
|
||||
// fix duplicates. UM only function.
|
||||
void fixDuplicates(RowAggFunctionType funct);
|
||||
|
||||
@ -646,6 +728,7 @@ class RowAggregationUM : public RowAggregation
|
||||
bool fHasAvg;
|
||||
bool fKeyOnHeap;
|
||||
bool fHasStatsFunc;
|
||||
bool fHasUDAF;
|
||||
|
||||
boost::shared_ptr<RowAggregation> fDistinctAggregator;
|
||||
|
||||
@ -715,6 +798,7 @@ class RowAggregationUMP2 : public RowAggregationUM
|
||||
void doStatistics(const Row&, int64_t, int64_t, int64_t);
|
||||
void doGroupConcat(const Row&, int64_t, int64_t);
|
||||
void doBitOp(const Row&, int64_t, int64_t, int);
|
||||
void doUDAF(const Row&, int64_t, int64_t, int64_t, RowUDAFFunctionCol* rowUDAF);
|
||||
bool countSpecial(const RowGroup* pRG) { return false; }
|
||||
};
|
||||
|
||||
|
175
utils/rowgroup/rowgroup.cpp
Normal file → Executable file
175
utils/rowgroup/rowgroup.cpp
Normal file → Executable file
@ -38,7 +38,6 @@
|
||||
using namespace std;
|
||||
|
||||
#include <boost/shared_array.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
using namespace boost;
|
||||
|
||||
#include "bytestream.h"
|
||||
@ -113,7 +112,6 @@ uint32_t StringStore::storeString(const uint8_t *data, uint32_t len)
|
||||
void StringStore::serialize(ByteStream &bs) const
|
||||
{
|
||||
uint32_t i;
|
||||
std::string empty_str;
|
||||
|
||||
bs << (uint32_t) mem.size();
|
||||
bs << (uint8_t) empty;
|
||||
@ -126,30 +124,25 @@ void StringStore::serialize(ByteStream &bs) const
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t StringStore::deserialize(ByteStream &bs)
|
||||
void StringStore::deserialize(ByteStream &bs)
|
||||
{
|
||||
uint32_t i;
|
||||
uint32_t count;
|
||||
uint32_t size;
|
||||
std::string buf;
|
||||
uint8_t tmp8;
|
||||
uint32_t ret = 0;
|
||||
|
||||
//mem.clear();
|
||||
bs >> count;
|
||||
mem.reserve(count);
|
||||
bs >> tmp8;
|
||||
empty = (bool) tmp8;
|
||||
ret += 5;
|
||||
for (i = 0; i < count; i++) {
|
||||
//cout << "deserializing " << size << " bytes\n";
|
||||
bs >> buf;
|
||||
shared_ptr<std::string> newString(new std::string(buf.c_str()));
|
||||
mem.push_back(newString);
|
||||
//bs.advance(size);
|
||||
ret += (size + 4);
|
||||
}
|
||||
return ret;
|
||||
return;
|
||||
}
|
||||
|
||||
void StringStore::clear()
|
||||
@ -159,6 +152,106 @@ void StringStore::clear()
|
||||
empty = true;
|
||||
}
|
||||
|
||||
UserDataStore::UserDataStore() : fUseUserDataMutex(false)
|
||||
{
|
||||
}
|
||||
|
||||
UserDataStore::~UserDataStore()
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t UserDataStore::storeUserData(mcsv1sdk::mcsv1Context& context,
|
||||
boost::shared_ptr<mcsv1sdk::UserData> data,
|
||||
uint32_t len)
|
||||
{
|
||||
uint32_t ret = 0;
|
||||
if (len == 0 || data == NULL)
|
||||
{
|
||||
return numeric_limits<uint32_t>::max();
|
||||
}
|
||||
|
||||
boost::mutex::scoped_lock lk(fMutex, defer_lock);
|
||||
if (fUseUserDataMutex)
|
||||
lk.lock();
|
||||
StoreData storeData;
|
||||
storeData.length = len;
|
||||
storeData.functionName = context.getName();
|
||||
storeData.userData = data;
|
||||
vStoreData.push_back(storeData);
|
||||
|
||||
ret = vStoreData.size();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
boost::shared_ptr<mcsv1sdk::UserData> UserDataStore::getUserData(uint32_t off) const
|
||||
{
|
||||
if (off == std::numeric_limits<uint32_t>::max())
|
||||
return boost::shared_ptr<mcsv1sdk::UserData>();
|
||||
|
||||
if ((vStoreData.size() < off) || off == 0)
|
||||
return boost::shared_ptr<mcsv1sdk::UserData>();
|
||||
|
||||
return vStoreData[off-1].userData;
|
||||
}
|
||||
|
||||
|
||||
void UserDataStore::serialize(ByteStream &bs) const
|
||||
{
|
||||
size_t i;
|
||||
|
||||
bs << (uint32_t) vStoreData.size();
|
||||
for (i = 0; i < vStoreData.size(); ++i)
|
||||
{
|
||||
const StoreData& storeData = vStoreData[i];
|
||||
bs << storeData.length;
|
||||
bs << storeData.functionName;
|
||||
storeData.userData->serialize(bs);
|
||||
}
|
||||
}
|
||||
|
||||
void UserDataStore::deserialize(ByteStream &bs)
|
||||
{
|
||||
size_t i;
|
||||
uint32_t cnt;
|
||||
bs >> cnt;
|
||||
|
||||
// vStoreData.clear();
|
||||
vStoreData.resize(cnt);
|
||||
|
||||
for (i = 0; i < cnt; i++)
|
||||
{
|
||||
bs >> vStoreData[i].length;
|
||||
bs >> vStoreData[i].functionName;
|
||||
|
||||
// We don't have easy access to the context here, so we do our own lookup
|
||||
if (vStoreData[i].functionName.length() == 0)
|
||||
{
|
||||
throw std::logic_error("UserDataStore::deserialize: has empty name");
|
||||
}
|
||||
mcsv1sdk::UDAF_MAP::iterator funcIter = mcsv1sdk::UDAFMap::getMap().find(vStoreData[i].functionName);
|
||||
if (funcIter == mcsv1sdk::UDAFMap::getMap().end())
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "UserDataStore::deserialize: " << vStoreData[i].functionName << " is undefined";
|
||||
throw std::logic_error(errmsg.str());
|
||||
}
|
||||
|
||||
mcsv1sdk::mcsv1_UDAF::ReturnCode rc;
|
||||
mcsv1sdk::UserData* userData = NULL;
|
||||
rc = funcIter->second->createUserData(userData, vStoreData[i].length);
|
||||
if (rc != mcsv1sdk::mcsv1_UDAF::SUCCESS)
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "UserDataStore::deserialize: " << vStoreData[i].functionName << " createUserData failed(" << rc << ")";
|
||||
throw std::logic_error(errmsg.str());
|
||||
}
|
||||
userData->unserialize(bs);
|
||||
vStoreData[i].userData = boost::shared_ptr<mcsv1sdk::UserData>(userData);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//uint32_t rgDataCount = 0;
|
||||
|
||||
RGData::RGData()
|
||||
@ -222,7 +315,7 @@ void RGData::reinit(const RowGroup &rg)
|
||||
reinit(rg, 8192);
|
||||
}
|
||||
|
||||
RGData::RGData(const RGData &r) : rowData(r.rowData), strings(r.strings)
|
||||
RGData::RGData(const RGData &r) : rowData(r.rowData), strings(r.strings), userDataStore(r.userDataStore)
|
||||
{
|
||||
//cout << "rgdata++ = " << __sync_add_and_fetch(&rgDataCount, 1) << endl;
|
||||
}
|
||||
@ -244,49 +337,47 @@ void RGData::serialize(ByteStream &bs, uint32_t amount) const
|
||||
}
|
||||
else
|
||||
bs << (uint8_t) 0;
|
||||
if (userDataStore)
|
||||
{
|
||||
bs << (uint8_t) 1;
|
||||
userDataStore->serialize(bs);
|
||||
}
|
||||
else
|
||||
bs << (uint8_t) 0;
|
||||
}
|
||||
|
||||
uint32_t RGData::deserialize(ByteStream &bs, bool hasLenField)
|
||||
void RGData::deserialize(ByteStream &bs, bool hasLenField)
|
||||
{
|
||||
uint32_t amount, sig;
|
||||
uint8_t *buf;
|
||||
uint8_t tmp8;
|
||||
uint32_t ret = 0;
|
||||
|
||||
bs.peek(sig);
|
||||
if (sig == RGDATA_SIG) {
|
||||
bs >> sig;
|
||||
bs >> amount;
|
||||
ret += 8;
|
||||
rowData.reset(new uint8_t[amount]);
|
||||
buf = bs.buf();
|
||||
memcpy(rowData.get(), buf, amount);
|
||||
bs.advance(amount);
|
||||
bs >> tmp8;
|
||||
ret += amount + 1;
|
||||
if (tmp8) {
|
||||
strings.reset(new StringStore());
|
||||
ret += strings->deserialize(bs);
|
||||
strings->deserialize(bs);
|
||||
}
|
||||
else
|
||||
strings.reset();
|
||||
}
|
||||
// crude backward compat. Remove after conversions are finished.
|
||||
else {
|
||||
if (hasLenField) {
|
||||
bs >> amount;
|
||||
ret += 4;
|
||||
// UDAF user data
|
||||
bs >> tmp8;
|
||||
if (tmp8) {
|
||||
userDataStore.reset(new UserDataStore());
|
||||
userDataStore->deserialize(bs);
|
||||
}
|
||||
else
|
||||
amount = bs.length();
|
||||
rowData.reset(new uint8_t[amount]);
|
||||
strings.reset();
|
||||
buf = bs.buf();
|
||||
memcpy(rowData.get(), buf, amount);
|
||||
bs.advance(amount);
|
||||
ret += amount;
|
||||
userDataStore.reset();
|
||||
}
|
||||
return ret;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void RGData::clear()
|
||||
@ -295,14 +386,25 @@ void RGData::clear()
|
||||
strings.reset();
|
||||
}
|
||||
|
||||
Row::Row() : data(NULL), strings(NULL) { }
|
||||
// UserDataStore is only used for UDAF.
|
||||
// Just in time construction because most of the time we don't need one.
|
||||
UserDataStore* RGData::getUserDataStore()
|
||||
{
|
||||
if (!userDataStore)
|
||||
{
|
||||
userDataStore.reset(new UserDataStore);
|
||||
}
|
||||
return userDataStore.get();
|
||||
}
|
||||
|
||||
Row::Row() : data(NULL), strings(NULL), userDataStore(NULL) { }
|
||||
|
||||
Row::Row(const Row &r) : columnCount(r.columnCount), baseRid(r.baseRid),
|
||||
oldOffsets(r.oldOffsets), stOffsets(r.stOffsets),
|
||||
offsets(r.offsets), colWidths(r.colWidths), types(r.types), data(r.data),
|
||||
scale(r.scale), precision(r.precision), strings(r.strings),
|
||||
useStringTable(r.useStringTable), hasLongStringField(r.hasLongStringField),
|
||||
sTableThreshold(r.sTableThreshold), forceInline(r.forceInline)
|
||||
sTableThreshold(r.sTableThreshold), forceInline(r.forceInline), userDataStore(NULL)
|
||||
{ }
|
||||
|
||||
Row::~Row() { }
|
||||
@ -623,9 +725,10 @@ bool Row::isNullValue(uint32_t colIndex) const
|
||||
break;
|
||||
default: {
|
||||
ostringstream os;
|
||||
os << "Row::isNullValue(): got bad column type (" << types[colIndex] <<
|
||||
"). Width=" << getColumnWidth(colIndex) << endl;
|
||||
os << toString() << endl;
|
||||
os << "Row::isNullValue(): got bad column type (";
|
||||
os << types[colIndex];
|
||||
os << "). Width=";
|
||||
os << getColumnWidth(colIndex) << endl;
|
||||
throw logic_error(os.str());
|
||||
}
|
||||
}
|
||||
@ -884,7 +987,9 @@ RowGroup & RowGroup::operator=(const RowGroup &r)
|
||||
return *this;
|
||||
}
|
||||
|
||||
RowGroup::~RowGroup() { }
|
||||
RowGroup::~RowGroup()
|
||||
{
|
||||
}
|
||||
|
||||
void RowGroup::resetRowGroup(uint64_t rid)
|
||||
{
|
||||
|
110
utils/rowgroup/rowgroup.h
Normal file → Executable file
110
utils/rowgroup/rowgroup.h
Normal file → Executable file
@ -38,6 +38,7 @@
|
||||
#include <stdexcept>
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/shared_array.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <cmath>
|
||||
@ -56,6 +57,7 @@
|
||||
#include "bytestream.h"
|
||||
#include "calpontsystemcatalog.h"
|
||||
#include "exceptclasses.h"
|
||||
#include "mcsv1_udaf.h"
|
||||
|
||||
#include "branchpred.h"
|
||||
|
||||
@ -106,25 +108,74 @@ public:
|
||||
void clear();
|
||||
|
||||
void serialize(messageqcpp::ByteStream &) const;
|
||||
uint32_t deserialize(messageqcpp::ByteStream &);
|
||||
void deserialize(messageqcpp::ByteStream &);
|
||||
|
||||
//@bug6065, make StringStore::storeString() thread safe
|
||||
void useStoreStringMutex(bool b) { fUseStoreStringMutex = b; }
|
||||
bool useStoreStringMutex() const { return fUseStoreStringMutex; }
|
||||
|
||||
private:
|
||||
std::string empty_str;
|
||||
|
||||
StringStore(const StringStore &);
|
||||
StringStore & operator=(const StringStore &);
|
||||
static const uint32_t CHUNK_SIZE = 64*1024; // allocators like powers of 2
|
||||
|
||||
// This is an overlay b/c the underlying data needs to be any size,
|
||||
// and alloc'd in one chunk. data can't be a sepatate dynamic chunk.
|
||||
// and alloc'd in one chunk. data can't be a separate dynamic chunk.
|
||||
|
||||
std::vector<boost::shared_ptr<std::string> > mem;
|
||||
bool empty;
|
||||
bool fUseStoreStringMutex; //@bug6065, make StringStore::storeString() thread safe
|
||||
boost::mutex fMutex;
|
||||
};
|
||||
|
||||
// Where we store user data for UDA(n)F
|
||||
class UserDataStore
|
||||
{
|
||||
// length represents the fixed portion length of userData.
|
||||
// There may be variable length data in containers or other
|
||||
// user created structures.
|
||||
struct StoreData
|
||||
{
|
||||
int32_t length;
|
||||
std::string functionName;
|
||||
boost::shared_ptr<mcsv1sdk::UserData> userData;
|
||||
StoreData() : length(0) { }
|
||||
StoreData(const StoreData& rhs)
|
||||
{
|
||||
length = rhs.length;
|
||||
functionName = rhs.functionName;
|
||||
userData = rhs.userData;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
UserDataStore();
|
||||
virtual ~UserDataStore();
|
||||
|
||||
void serialize(messageqcpp::ByteStream &) const;
|
||||
void deserialize(messageqcpp::ByteStream &);
|
||||
|
||||
//Set to make UserDataStore thread safe
|
||||
void useUserDataMutex(bool b) { fUseUserDataMutex = b; }
|
||||
bool useUserDataMutex() const { return fUseUserDataMutex; }
|
||||
|
||||
// Returns the offset
|
||||
uint32_t storeUserData(mcsv1sdk::mcsv1Context& context,
|
||||
boost::shared_ptr<mcsv1sdk::UserData> data,
|
||||
uint32_t length);
|
||||
|
||||
boost::shared_ptr<mcsv1sdk::UserData> getUserData(uint32_t offset) const;
|
||||
|
||||
private:
|
||||
UserDataStore(const UserDataStore &);
|
||||
UserDataStore & operator=(const UserDataStore &);
|
||||
|
||||
std::vector<StoreData> vStoreData;
|
||||
|
||||
bool fUseUserDataMutex;
|
||||
boost::mutex fMutex;
|
||||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@ -152,7 +203,7 @@ public:
|
||||
// the 'hasLengthField' is there b/c PM aggregation (and possibly others) currently sends
|
||||
// inline data with a length field. Once that's converted to string table format, that
|
||||
// option can go away.
|
||||
uint32_t deserialize(messageqcpp::ByteStream &, bool hasLengthField=false); // returns the # of bytes read
|
||||
void deserialize(messageqcpp::ByteStream &, bool hasLengthField=false); // returns the # of bytes read
|
||||
|
||||
inline uint64_t getStringTableMemUsage();
|
||||
void clear();
|
||||
@ -169,9 +220,14 @@ public:
|
||||
void useStoreStringMutex(bool b) { if (strings) strings->useStoreStringMutex(b); }
|
||||
bool useStoreStringMutex() const { return (strings ? (strings->useStoreStringMutex()) : false); }
|
||||
|
||||
UserDataStore* getUserDataStore();
|
||||
// make UserDataStore::storeData() thread safe
|
||||
void useUserDataMutex(bool b) { if (userDataStore) userDataStore->useUserDataMutex(b); }
|
||||
bool useUserDataMutex() const { return (userDataStore ? (userDataStore->useUserDataMutex()) : false); }
|
||||
|
||||
boost::shared_array<uint8_t> rowData;
|
||||
boost::shared_ptr<StringStore> strings;
|
||||
|
||||
boost::shared_ptr<UserDataStore> userDataStore;
|
||||
private:
|
||||
//boost::shared_array<uint8_t> rowData;
|
||||
//boost::shared_ptr<StringStore> strings;
|
||||
@ -187,14 +243,17 @@ class Row
|
||||
{
|
||||
public:
|
||||
struct Pointer {
|
||||
inline Pointer() : data(NULL), strings(NULL) { }
|
||||
inline Pointer() : data(NULL), strings(NULL), userDataStore(NULL) { }
|
||||
|
||||
// Pointer(uint8_t*) implicitly makes old code compatible with the string table impl;
|
||||
// make it explicit to identify things that still might need to be changed
|
||||
inline Pointer(uint8_t *d) : data(d), strings(NULL) { }
|
||||
inline Pointer(uint8_t *d, StringStore *s) : data(d), strings(s) { }
|
||||
inline Pointer(uint8_t *d) : data(d), strings(NULL), userDataStore(NULL) { }
|
||||
inline Pointer(uint8_t *d, StringStore *s) : data(d), strings(s), userDataStore(NULL) { }
|
||||
inline Pointer(uint8_t *d, StringStore *s, UserDataStore *u) :
|
||||
data(d), strings(s), userDataStore(u) { }
|
||||
uint8_t *data;
|
||||
StringStore *strings;
|
||||
UserDataStore *userDataStore;
|
||||
};
|
||||
|
||||
Row();
|
||||
@ -290,6 +349,11 @@ class Row
|
||||
inline const uint8_t* getVarBinaryField(uint32_t& len, uint32_t colIndex) const;
|
||||
inline void setVarBinaryField(const uint8_t* val, uint32_t len, uint32_t colIndex);
|
||||
|
||||
inline boost::shared_ptr<mcsv1sdk::UserData> getUserData(uint32_t colIndex) const;
|
||||
inline void setUserData(mcsv1sdk::mcsv1Context& context,
|
||||
boost::shared_ptr<mcsv1sdk::UserData> userData,
|
||||
uint32_t len, uint32_t colIndex);
|
||||
|
||||
uint64_t getNullValue(uint32_t colIndex) const;
|
||||
bool isNullValue(uint32_t colIndex) const;
|
||||
|
||||
@ -332,6 +396,7 @@ class Row
|
||||
inline bool equals(const Row &, uint32_t lastCol) const;
|
||||
inline bool equals(const Row &) const;
|
||||
|
||||
inline void setUserDataStore(UserDataStore* u) {userDataStore = u;}
|
||||
private:
|
||||
uint32_t columnCount;
|
||||
uint64_t baseRid;
|
||||
@ -353,10 +418,12 @@ class Row
|
||||
boost::shared_array<bool> forceInline;
|
||||
inline bool inStringTable(uint32_t col) const;
|
||||
|
||||
UserDataStore* userDataStore; // For UDAF
|
||||
|
||||
friend class RowGroup;
|
||||
};
|
||||
|
||||
inline Row::Pointer Row::getPointer() const { return Pointer(data, strings); }
|
||||
inline Row::Pointer Row::getPointer() const { return Pointer(data, strings, userDataStore); }
|
||||
inline uint8_t * Row::getData() const { return data; }
|
||||
|
||||
inline void Row::setPointer(const Pointer &p)
|
||||
@ -368,6 +435,7 @@ inline void Row::setPointer(const Pointer &p)
|
||||
useStringTable = hasStrings;
|
||||
offsets = (useStringTable ? stOffsets : oldOffsets);
|
||||
}
|
||||
userDataStore = p.userDataStore;
|
||||
}
|
||||
|
||||
inline void Row::setData(const Pointer &p) { setPointer(p); }
|
||||
@ -613,6 +681,15 @@ inline const uint8_t* Row::getVarBinaryField(uint32_t& len, uint32_t colIndex) c
|
||||
}
|
||||
}
|
||||
|
||||
inline boost::shared_ptr<mcsv1sdk::UserData> Row::getUserData(uint32_t colIndex) const
|
||||
{
|
||||
if (!userDataStore)
|
||||
{
|
||||
return boost::shared_ptr<mcsv1sdk::UserData>();
|
||||
}
|
||||
return userDataStore->getUserData(*((uint32_t *) &data[offsets[colIndex]]));
|
||||
}
|
||||
|
||||
inline double Row::getDoubleField(uint32_t colIndex) const
|
||||
{
|
||||
return *((double *) &data[offsets[colIndex]]);
|
||||
@ -783,6 +860,19 @@ inline void Row::setVarBinaryField(const uint8_t *val, uint32_t len, uint32_t co
|
||||
}
|
||||
}
|
||||
|
||||
inline void Row::setUserData(mcsv1sdk::mcsv1Context& context,
|
||||
boost::shared_ptr<mcsv1sdk::UserData> userData,
|
||||
uint32_t len, uint32_t colIndex)
|
||||
{
|
||||
if (!userDataStore)
|
||||
{
|
||||
return;
|
||||
}
|
||||
uint32_t offset = userDataStore->storeUserData(context, userData, len);
|
||||
*((uint32_t *) &data[offsets[colIndex]]) = offset;
|
||||
*((uint32_t *) &data[offsets[colIndex] + 4]) = len;
|
||||
}
|
||||
|
||||
inline void Row::copyField(uint32_t destIndex, uint32_t srcIndex) const
|
||||
{
|
||||
uint32_t n = offsets[destIndex + 1] - offsets[destIndex];
|
||||
@ -1149,6 +1239,7 @@ inline void RowGroup::getRow(uint32_t rowNum, Row *r) const
|
||||
r->baseRid = getBaseRid();
|
||||
r->data = &(data[headerSize + (rowNum * offsets[columnCount])]);
|
||||
r->strings = strings;
|
||||
r->userDataStore = rgData->userDataStore.get();
|
||||
}
|
||||
|
||||
inline void RowGroup::setData(uint8_t *d)
|
||||
@ -1523,13 +1614,14 @@ inline RGData & RGData::operator=(const RGData &r)
|
||||
{
|
||||
rowData = r.rowData;
|
||||
strings = r.strings;
|
||||
userDataStore = r.userDataStore;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void RGData::getRow(uint32_t num, Row *row)
|
||||
{
|
||||
uint32_t size = row->getSize();
|
||||
row->setData(Row::Pointer(&rowData[RowGroup::getHeaderSize() + (num * size)], strings.get()));
|
||||
row->setData(Row::Pointer(&rowData[RowGroup::getHeaderSize() + (num * size)], strings.get(), userDataStore.get()));
|
||||
}
|
||||
|
||||
}
|
||||
|
434
utils/rowgroup/rowgroup.vpj
Normal file → Executable file
434
utils/rowgroup/rowgroup.vpj
Normal file → Executable file
@ -1,220 +1,220 @@
|
||||
<!DOCTYPE Project SYSTEM "http://www.slickedit.com/dtd/vse/10.0/vpj.dtd">
|
||||
<Project
|
||||
Version="10.0"
|
||||
VendorName="SlickEdit"
|
||||
TemplateName="GNU C/C++"
|
||||
WorkingDir=".">
|
||||
<Config
|
||||
Name="Debug"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdrowgroup.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -g -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -g -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Config
|
||||
Name="Release"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdrowgroup.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Files>
|
||||
<Folder
|
||||
Name="Source Files"
|
||||
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d">
|
||||
<F N="rowaggregation.cpp"/>
|
||||
<F N="rowgroup.cpp"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Header Files"
|
||||
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if">
|
||||
<F N="rowaggregation.h"/>
|
||||
<F N="rowgroup.h"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Resource Files"
|
||||
Filters="*.ico;*.cur;*.dlg"/>
|
||||
<Folder
|
||||
Name="Bitmaps"
|
||||
Filters="*.bmp"/>
|
||||
<Folder
|
||||
Name="Other Files"
|
||||
Filters="">
|
||||
<F
|
||||
N="Makefile"
|
||||
Type="Makefile"/>
|
||||
</Folder>
|
||||
</Files>
|
||||
Version="10.0"
|
||||
VendorName="SlickEdit"
|
||||
TemplateName="GNU C/C++"
|
||||
WorkingDir=".">
|
||||
<Config
|
||||
Name="Debug"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdrowgroup.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -g -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -g -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Config
|
||||
Name="Release"
|
||||
Type="gnuc"
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdrowgroup.so"
|
||||
CompilerConfigName="Latest Version">
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
MenuCaption="&Compile"
|
||||
Dialog="_gnuc_options_form Compile"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
OutputExts="*.o"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ -c %xup %defd -o "%bd%n%oe" %i "%f"'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Link"
|
||||
MenuCaption="&Link"
|
||||
ShowOnMenu="Never"
|
||||
Dialog="_gnuc_options_form Link"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveCurrent"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine='g++ %xup -o "%o" %f %libs -shared -fPIC'/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Build"
|
||||
MenuCaption="&Build"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine="make"/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Rebuild"
|
||||
MenuCaption="&Rebuild"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Debug"
|
||||
MenuCaption="&Debug"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="Execute"
|
||||
MenuCaption="E&xecute"
|
||||
Dialog="_gnuc_options_form Run/Debug"
|
||||
BuildFirst="1"
|
||||
CaptureOutputWith="ProcessBuffer"
|
||||
Deletable="0"
|
||||
SaveOption="SaveWorkspaceFiles"
|
||||
RunFromDir="%rw">
|
||||
<Exec CmdLine=""/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="dash"
|
||||
MenuCaption="-"
|
||||
Deletable="0">
|
||||
<Exec/>
|
||||
</Target>
|
||||
<Target
|
||||
Name="GNU C Options"
|
||||
MenuCaption="GNU C &Options..."
|
||||
ShowOnMenu="HideIfNoCmdLine"
|
||||
Deletable="0"
|
||||
SaveOption="SaveNone">
|
||||
<Exec
|
||||
CmdLine="gnucoptions"
|
||||
Type="Slick-C"/>
|
||||
</Target>
|
||||
</Menu>
|
||||
<List Name="GNUC Options">
|
||||
<Item
|
||||
Name="LinkerOutputType"
|
||||
Value="SharedLibrary"/>
|
||||
</List>
|
||||
</Config>
|
||||
<Files>
|
||||
<Folder
|
||||
Name="Source Files"
|
||||
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d">
|
||||
<F N="rowaggregation.cpp"/>
|
||||
<F N="rowgroup.cpp"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Header Files"
|
||||
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if">
|
||||
<F N="rowaggregation.h"/>
|
||||
<F N="rowgroup.h"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Resource Files"
|
||||
Filters="*.ico;*.cur;*.dlg"/>
|
||||
<Folder
|
||||
Name="Bitmaps"
|
||||
Filters="*.bmp"/>
|
||||
<Folder
|
||||
Name="Other Files"
|
||||
Filters="">
|
||||
<F
|
||||
N="Makefile"
|
||||
Type="Makefile"/>
|
||||
</Folder>
|
||||
</Files>
|
||||
</Project>
|
||||
|
4
utils/udfsdk/CMakeLists.txt
Normal file → Executable file
4
utils/udfsdk/CMakeLists.txt
Normal file → Executable file
@ -4,13 +4,13 @@ include_directories( ${ENGINE_COMMON_INCLUDES}
|
||||
|
||||
########### next target ###############
|
||||
|
||||
set(udfsdk_LIB_SRCS udfsdk.cpp)
|
||||
set(udfsdk_LIB_SRCS udfsdk.cpp mcsv1_udaf.cpp allnull.cpp ssq.cpp median.cpp)
|
||||
|
||||
add_definitions(-DMYSQL_DYNAMIC_PLUGIN)
|
||||
|
||||
add_library(udfsdk SHARED ${udfsdk_LIB_SRCS})
|
||||
|
||||
set_target_properties(udfsdk PROPERTIES VERSION 1.0.0 SOVERSION 1)
|
||||
set_target_properties(udfsdk PROPERTIES VERSION 1.1.0 SOVERSION 1)
|
||||
|
||||
install(TARGETS udfsdk DESTINATION ${ENGINE_LIBDIR} COMPONENT libs)
|
||||
|
||||
|
96
utils/udfsdk/allnull.cpp
Executable file
96
utils/udfsdk/allnull.cpp
Executable file
@ -0,0 +1,96 @@
|
||||
/* Copyright (C) 2017 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 <sstream>
|
||||
#include <cstring>
|
||||
#include "allnull.h"
|
||||
#include "bytestream.h"
|
||||
#include "objectreader.h"
|
||||
|
||||
using namespace mcsv1sdk;
|
||||
|
||||
struct allnull_data
|
||||
{
|
||||
uint64_t totalQuantity;
|
||||
uint64_t totalNulls;
|
||||
};
|
||||
|
||||
#define OUT_TYPE int64_t
|
||||
mcsv1_UDAF::ReturnCode allnull::init(mcsv1Context* context,
|
||||
COL_TYPES& colTypes)
|
||||
{
|
||||
context->setUserDataSize(sizeof(allnull_data));
|
||||
if (colTypes.size() < 1)
|
||||
{
|
||||
// The error message will be prepended with
|
||||
// "The storage engine for the table doesn't support "
|
||||
context->setErrorMessage("allnull() with 0 arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
context->setResultType(CalpontSystemCatalog::TINYINT);
|
||||
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
mcsv1_UDAF::ReturnCode allnull::finish(mcsv1Context* context)
|
||||
{
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
mcsv1_UDAF::ReturnCode allnull::reset(mcsv1Context* context)
|
||||
{
|
||||
struct allnull_data* data = (struct allnull_data*)context->getUserData()->data;
|
||||
data->totalQuantity = 0;
|
||||
data->totalNulls = 0;
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
mcsv1_UDAF::ReturnCode allnull::nextValue(mcsv1Context* context,
|
||||
std::vector<ColumnDatum>& valsIn)
|
||||
{
|
||||
struct allnull_data* data = (struct allnull_data*)context->getUserData()->data;
|
||||
|
||||
for (size_t i = 0; i < context->getParameterCount(); i++)
|
||||
{
|
||||
data->totalQuantity++;
|
||||
if (context->isParamNull(0))
|
||||
{
|
||||
data->totalNulls++;
|
||||
}
|
||||
}
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
mcsv1_UDAF::ReturnCode allnull::subEvaluate(mcsv1Context* context, const UserData* userDataIn)
|
||||
{
|
||||
struct allnull_data* outData = (struct allnull_data*)context->getUserData()->data;
|
||||
struct allnull_data* inData = (struct allnull_data*)userDataIn->data;
|
||||
outData->totalQuantity += inData->totalQuantity;
|
||||
outData->totalNulls += inData->totalNulls;
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
mcsv1_UDAF::ReturnCode allnull::evaluate(mcsv1Context* context, static_any::any& valOut)
|
||||
{
|
||||
OUT_TYPE allNull;
|
||||
struct allnull_data* data = (struct allnull_data*)context->getUserData()->data;
|
||||
allNull = data->totalQuantity > 0 && data->totalNulls == data->totalQuantity;
|
||||
valOut = allNull;
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
|
225
utils/udfsdk/allnull.h
Executable file
225
utils/udfsdk/allnull.h
Executable file
@ -0,0 +1,225 @@
|
||||
/* Copyright (C) 2017 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. */
|
||||
|
||||
/***********************************************************************
|
||||
* $Id$
|
||||
*
|
||||
* mcsv1_UDAF.h
|
||||
***********************************************************************/
|
||||
|
||||
/**
|
||||
* Columnstore interface for writing a User Defined Aggregate
|
||||
* Functions (UDAF) and User Defined Analytic Functions (UDAnF)
|
||||
* or a function that can act as either - UDA(n)F
|
||||
*
|
||||
* The basic steps are:
|
||||
*
|
||||
* 1. Create a the UDA(n)F function interface in some .h file.
|
||||
* 2. Create the UDF function implementation in some .cpp file
|
||||
* 3. Create the connector stub (MariaDB UDAF definition) for
|
||||
* this UDF function.
|
||||
* 4. build the dynamic library using all of the source.
|
||||
* 5 Put the library in $COLUMNSTORE_INSTALL/lib of
|
||||
* all modules
|
||||
* 6. restart the Columnstore system.
|
||||
* 7. notify mysqld about the new functions with commands like:
|
||||
*
|
||||
* // An example of xor over a range for UDAF and UDAnF
|
||||
* CREATE AGGREGATE FUNCTION mcs_bit_xor returns BOOL soname
|
||||
* 'libudfsdk.so';
|
||||
*
|
||||
* // An example that only makes sense as a UDAnF
|
||||
* CREATE AGGREGATE FUNCTION mcs_interpolate returns REAL
|
||||
* soname 'libudfsdk.so';
|
||||
*
|
||||
* The UDAF functions may run distributed in the Columnstore
|
||||
* engine. UDAnF do not run distributed.
|
||||
*
|
||||
* UDAF is User Defined Aggregate Function.
|
||||
* UDAnF is User Defined Analytic Function.
|
||||
* UDA(n)F is an acronym for a function that could be either. It
|
||||
* is also used to describe the interface that is used for
|
||||
* either.
|
||||
*/
|
||||
#ifndef HEADER_allnull
|
||||
#define HEADER_allnull
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <boost/any.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#include <unordered_map>
|
||||
#else
|
||||
#include <tr1/unordered_map>
|
||||
#endif
|
||||
|
||||
#include "mcsv1_udaf.h"
|
||||
#include "calpontsystemcatalog.h"
|
||||
#include "windowfunctioncolumn.h"
|
||||
using namespace execplan;
|
||||
|
||||
#if defined(_MSC_VER) && defined(xxxRGNODE_DLLEXPORT)
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define EXPORT
|
||||
#endif
|
||||
|
||||
namespace mcsv1sdk
|
||||
{
|
||||
|
||||
// Override mcsv1_UDAF to build your User Defined Aggregate (UDAF) and/or
|
||||
// User Defined Analytic Function (UDAnF).
|
||||
// These will be singleton classes, so don't put any instance
|
||||
// specific data in here. All instance data is stored in mcsv1Context
|
||||
// passed to each user function and retrieved by the getUserData() method.
|
||||
//
|
||||
// Each API function returns a ReturnCode. If ERROR is returned at any time,
|
||||
// the query is aborted, getInterrupted() will begin to return true and the
|
||||
// message set in config->setErrorMessage() is returned to MariaDB.
|
||||
class allnull : public mcsv1_UDAF
|
||||
{
|
||||
public:
|
||||
// Defaults OK
|
||||
allnull() : mcsv1_UDAF(){};
|
||||
virtual ~allnull(){};
|
||||
|
||||
/**
|
||||
* init()
|
||||
*
|
||||
* Mandatory. Implement this to initialize flags and instance
|
||||
* data. Called once per SQL statement. You can do any sanity
|
||||
* checks here.
|
||||
*
|
||||
* colTypes (in) - A vector of ColDataType defining the
|
||||
* parameters of the UDA(n)F call. These can be used to decide
|
||||
* to override the default return type. If desired, the new
|
||||
* return type can be set by context->setReturnType() and
|
||||
* decimal precision can be set in context->
|
||||
* setResultDecimalCharacteristics.
|
||||
*
|
||||
* Return mcsv1_UDAF::ERROR on any error, such as non-compatible
|
||||
* colTypes or wrong number of arguments. Else return
|
||||
* mcsv1_UDAF::SUCCESS.
|
||||
*/
|
||||
virtual ReturnCode init(mcsv1Context* context,
|
||||
COL_TYPES& colTypes);
|
||||
|
||||
/**
|
||||
* finish()
|
||||
*
|
||||
* Mandatory. Completes the UDA(n)F. Called once per SQL
|
||||
* statement. Do not free any memory allocated by
|
||||
* context->setUserDataSize(). The SDK Framework owns that memory
|
||||
* and will handle that. Often, there is nothing to do here.
|
||||
*/
|
||||
virtual ReturnCode finish(mcsv1Context* context);
|
||||
|
||||
/**
|
||||
* reset()
|
||||
*
|
||||
* Mandatory. Reset the UDA(n)F for a new group, partition or,
|
||||
* in some cases, new Window Frame. Do not free any memory
|
||||
* allocated by context->setUserDataSize(). The SDK Framework owns
|
||||
* that memory and will handle that. Use this opportunity to
|
||||
* reset any variables in context->getUserData() needed for the
|
||||
* next aggregation. May be called multiple times if running in
|
||||
* a ditributed fashion.
|
||||
*
|
||||
* Use this opportunity to initialize the userData.
|
||||
*/
|
||||
virtual ReturnCode reset(mcsv1Context* context);
|
||||
|
||||
/**
|
||||
* nextValue()
|
||||
*
|
||||
* Mandatory. Handle a single row.
|
||||
*
|
||||
* colsIn - A vector of data structure describing the input
|
||||
* data.
|
||||
*
|
||||
* This function is called once for every row in the filtered
|
||||
* result set (before aggregation). It is very important that
|
||||
* this function is efficient.
|
||||
*
|
||||
* If the UDAF is running in a distributed fashion, nextValue
|
||||
* cannot depend on order, as it will only be called for each
|
||||
* row found on the specific PM.
|
||||
*
|
||||
* valsIn (in) - a vector of the parameters from the row.
|
||||
*/
|
||||
virtual ReturnCode nextValue(mcsv1Context* context,
|
||||
std::vector<ColumnDatum>& valsIn);
|
||||
|
||||
/**
|
||||
* subEvaluate()
|
||||
*
|
||||
* Mandatory -- Called if the UDAF is running in a distributed
|
||||
* fashion. Columnstore tries to run all aggregate functions
|
||||
* distributed, depending on context.
|
||||
*
|
||||
* Perform an aggregation on rows partially aggregated by
|
||||
* nextValue. Columnstore calls nextValue for each row on a
|
||||
* given PM for a group (GROUP BY). subEvaluate is called on the
|
||||
* UM to consolodate those values into a single instance of
|
||||
* userData. Keep your aggregated totals in context's userData.
|
||||
* The first time this is called for a group, reset() would have
|
||||
* been called with this version of userData.
|
||||
*
|
||||
* Called for every partial data set in each group in GROUP BY.
|
||||
*
|
||||
* When subEvaluate has been called for all subAggregated data
|
||||
* sets, Evaluate will be called with the same context as here.
|
||||
*
|
||||
* valIn (In) - This is a pointer to a memory block of the size
|
||||
* set in setUserDataSize. It will contain the value of userData
|
||||
* as seen in the last call to NextValue for a given PM.
|
||||
*
|
||||
*/
|
||||
virtual ReturnCode subEvaluate(mcsv1Context* context, const UserData* userDataIn);
|
||||
|
||||
/**
|
||||
* evaluate()
|
||||
*
|
||||
* Mandatory. Get the aggregated value.
|
||||
*
|
||||
* Called for every new group if UDAF GROUP BY, UDAnF partition
|
||||
* or, in some cases, new Window Frame.
|
||||
*
|
||||
* Set the aggregated value into valOut. The datatype is assumed
|
||||
* to be the same as that set in the init() function;
|
||||
*
|
||||
* If the UDAF is running in a distributed fashion, evaluate is
|
||||
* called after a series of subEvaluate calls.
|
||||
*
|
||||
* valOut (out) - Set the aggregated value here. The datatype is
|
||||
* assumed to be the same as that set in the init() function;
|
||||
*
|
||||
* To return a NULL value, don't assign to valOut.
|
||||
*/
|
||||
virtual ReturnCode evaluate(mcsv1Context* context, static_any::any& valOut);
|
||||
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
}; // namespace
|
||||
|
||||
#undef EXPORT
|
||||
|
||||
#endif // HEADER_allnull.h
|
||||
|
258
utils/udfsdk/mcsv1_udaf.cpp
Executable file
258
utils/udfsdk/mcsv1_udaf.cpp
Executable file
@ -0,0 +1,258 @@
|
||||
/* Copyright (C) 2017 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 <sstream>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include "mcsv1_udaf.h"
|
||||
#include "bytestream.h"
|
||||
#include "objectreader.h"
|
||||
|
||||
using namespace mcsv1sdk;
|
||||
/**
|
||||
* All UDA(n)F functions must be registered in the function map.
|
||||
* They will be picked up by the Columnstore modules during
|
||||
* startup.
|
||||
*
|
||||
* This is a temporary kludge until we get the library loader
|
||||
* task complete
|
||||
*/
|
||||
UDAF_MAP UDAFMap::fm;
|
||||
#include "allnull.h"
|
||||
#include "ssq.h"
|
||||
#include "median.h"
|
||||
UDAF_MAP& UDAFMap::getMap()
|
||||
{
|
||||
if (fm.size() > 0)
|
||||
{
|
||||
return fm;
|
||||
}
|
||||
// first: function name
|
||||
// second: Function pointer
|
||||
// please use lower case for the function name. Because the names might be
|
||||
// case-insensitive in MySQL depending on the setting. In such case,
|
||||
// the function names passed to the interface is always in lower case.
|
||||
fm["allnull"] = new allnull();
|
||||
fm["ssq"] = new ssq();
|
||||
fm["median"] = new median();
|
||||
|
||||
return fm;
|
||||
}
|
||||
|
||||
int32_t mcsv1Context::getColWidth()
|
||||
{
|
||||
if (fColWidth > 0)
|
||||
{
|
||||
return fColWidth;
|
||||
}
|
||||
// JIT initialization for types that have a defined size.
|
||||
switch (fResultType)
|
||||
{
|
||||
case CalpontSystemCatalog::BIT:
|
||||
case CalpontSystemCatalog::TINYINT:
|
||||
case CalpontSystemCatalog::UTINYINT:
|
||||
case CalpontSystemCatalog::CHAR:
|
||||
fColWidth = 1;
|
||||
break;
|
||||
case CalpontSystemCatalog::SMALLINT:
|
||||
case CalpontSystemCatalog::USMALLINT:
|
||||
fColWidth = 2;
|
||||
break;
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::FLOAT:
|
||||
case CalpontSystemCatalog::UFLOAT:
|
||||
case CalpontSystemCatalog::DATE:
|
||||
fColWidth = 4;
|
||||
break;
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
case CalpontSystemCatalog::DATETIME:
|
||||
case CalpontSystemCatalog::STRINT:
|
||||
fColWidth = 8;
|
||||
break;
|
||||
case CalpontSystemCatalog::LONGDOUBLE:
|
||||
fColWidth = sizeof(long double);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return fColWidth;
|
||||
}
|
||||
|
||||
bool mcsv1Context::operator==(const mcsv1Context& c) const
|
||||
{
|
||||
// We don't test the per row data fields. They don't determine
|
||||
// if it's the same Context.
|
||||
if (getName() != c.getName()
|
||||
|| fRunFlags != c.fRunFlags
|
||||
|| fContextFlags != c.fContextFlags
|
||||
|| fUserDataSize != c.fUserDataSize
|
||||
|| fResultType != c.fResultType
|
||||
|| fResultscale != c.fResultscale
|
||||
|| fResultPrecision != c.fResultPrecision
|
||||
|| fRowsInPartition != c.fRowsInPartition
|
||||
|| fStartFrame != c.fStartFrame
|
||||
|| fEndFrame != c.fEndFrame
|
||||
|| fStartConstant != c.fStartConstant
|
||||
|| fEndConstant != c.fEndConstant)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mcsv1Context::operator!=(const mcsv1Context& c) const
|
||||
{
|
||||
return (!(*this == c));
|
||||
}
|
||||
|
||||
const std::string mcsv1Context::toString() const
|
||||
{
|
||||
std::ostringstream output;
|
||||
output << "mcsv1Context: " << getName() << std::endl;
|
||||
output << " RunFlags=" << fRunFlags << " ContextFlags=" << fContextFlags << std::endl;
|
||||
output << " UserDataSize=" << fUserDataSize << " ResultType=" << colDataTypeToString(fResultType) << std::endl;
|
||||
output << " Resultscale=" << fResultscale << " ResultPrecision=" << fResultPrecision << std::endl;
|
||||
output << " ErrorMsg=" << errorMsg << std::endl;
|
||||
output << " bInterrupted=" << bInterrupted << " RowsInPartition=" << fRowsInPartition << std::endl;
|
||||
output << " StartFrame=" << fStartFrame << " EndFrame=" << fEndFrame << std::endl;
|
||||
output << " StartConstant=" << fStartConstant << " EndConstant=" << fEndConstant << std::endl;
|
||||
return output.str();
|
||||
}
|
||||
|
||||
mcsv1sdk::mcsv1_UDAF* mcsv1Context::getFunction()
|
||||
{
|
||||
if (func)
|
||||
{
|
||||
return func;
|
||||
}
|
||||
|
||||
// Just in time initialization
|
||||
if (functionName.length() == 0)
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "mcsv1Context::getFunction: " << functionName << " is empty";
|
||||
throw std::logic_error(errmsg.str());
|
||||
}
|
||||
mcsv1sdk::UDAF_MAP::iterator funcIter = mcsv1sdk::UDAFMap::getMap().find(functionName);
|
||||
if (funcIter == mcsv1sdk::UDAFMap::getMap().end())
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "mcsv1Context::getFunction: " << functionName << " is undefined";
|
||||
throw std::logic_error(errmsg.str());
|
||||
}
|
||||
func = funcIter->second;
|
||||
return func;
|
||||
}
|
||||
|
||||
mcsv1sdk::mcsv1_UDAF* mcsv1Context::getFunction() const
|
||||
{
|
||||
return const_cast<mcsv1Context*>(this)->getFunction();
|
||||
}
|
||||
|
||||
void mcsv1Context::createUserData()
|
||||
{
|
||||
// Try the function. If not implemented, create a byte array.
|
||||
UserData* userData = NULL;
|
||||
mcsv1_UDAF::ReturnCode rc = getFunction()->createUserData(userData, fUserDataSize);
|
||||
if (rc == mcsv1_UDAF::ERROR)
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "mcsv1Context::createUserData: " << functionName << errorMsg.c_str();
|
||||
throw std::logic_error(errmsg.str());
|
||||
}
|
||||
setUserData(userData);
|
||||
}
|
||||
|
||||
void mcsv1Context::serialize(messageqcpp::ByteStream& b) const
|
||||
{
|
||||
b.needAtLeast(sizeof(mcsv1Context));
|
||||
b << (ObjectReader::id_t) ObjectReader::MCSV1_CONTEXT;
|
||||
b << functionName;
|
||||
b << fRunFlags;
|
||||
// Dont send context flags, These are set for each call
|
||||
b << fUserDataSize;
|
||||
b << (uint32_t)fResultType;
|
||||
b << fResultscale;
|
||||
b << fResultPrecision;
|
||||
b << errorMsg;
|
||||
// Don't send dataflags. These are set for each call
|
||||
// bInterrupted is set internally.
|
||||
b << fRowsInPartition;
|
||||
b << (uint32_t)fStartFrame;
|
||||
b << (uint32_t)fEndFrame;
|
||||
b << fStartConstant;
|
||||
b << fEndConstant;
|
||||
}
|
||||
|
||||
void mcsv1Context::unserialize(messageqcpp::ByteStream& b)
|
||||
{
|
||||
ObjectReader::checkType(b, ObjectReader::MCSV1_CONTEXT);
|
||||
b >> functionName;
|
||||
b >> fRunFlags;
|
||||
b >> fUserDataSize;
|
||||
uint32_t iResultType;
|
||||
b >> iResultType;
|
||||
fResultType = (CalpontSystemCatalog::ColDataType)iResultType;
|
||||
b >> fResultscale;
|
||||
b >> fResultPrecision;
|
||||
b >> errorMsg;
|
||||
b >> fRowsInPartition;
|
||||
uint32_t frame;
|
||||
b >> frame;
|
||||
fStartFrame = (WF_FRAME)frame;
|
||||
b >> frame;
|
||||
fEndFrame = (WF_FRAME)frame;
|
||||
b >> fStartConstant;
|
||||
b >> fEndConstant;
|
||||
}
|
||||
|
||||
void UserData::serialize(messageqcpp::ByteStream& bs) const
|
||||
{
|
||||
bs << size;
|
||||
bs.append(data, size);
|
||||
}
|
||||
|
||||
void UserData::unserialize(messageqcpp::ByteStream& bs)
|
||||
{
|
||||
bs >> size;
|
||||
memcpy(data, bs.buf(), size);
|
||||
bs.advance(size);
|
||||
}
|
||||
|
||||
const std::string typeStr("");
|
||||
const static_any::any& mcsv1_UDAF::charTypeId = (char)1;
|
||||
const static_any::any& mcsv1_UDAF::scharTypeId = (signed char)1;
|
||||
const static_any::any& mcsv1_UDAF::shortTypeId = (short)1;
|
||||
const static_any::any& mcsv1_UDAF::intTypeId = (int)1;
|
||||
const static_any::any& mcsv1_UDAF::longTypeId = (long)1;
|
||||
const static_any::any& mcsv1_UDAF::llTypeId = (long long)1;
|
||||
const static_any::any& mcsv1_UDAF::ucharTypeId = (unsigned char)1;
|
||||
const static_any::any& mcsv1_UDAF::ushortTypeId = (unsigned short)1;
|
||||
const static_any::any& mcsv1_UDAF::uintTypeId = (unsigned int)1;
|
||||
const static_any::any& mcsv1_UDAF::ulongTypeId = (unsigned long)1;
|
||||
const static_any::any& mcsv1_UDAF::ullTypeId = (unsigned long long)1;
|
||||
const static_any::any& mcsv1_UDAF::floatTypeId = (float)1;
|
||||
const static_any::any& mcsv1_UDAF::doubleTypeId = (double)1;
|
||||
const static_any::any& mcsv1_UDAF::strTypeId = typeStr;
|
||||
|
||||
|
990
utils/udfsdk/mcsv1_udaf.h
Executable file
990
utils/udfsdk/mcsv1_udaf.h
Executable file
@ -0,0 +1,990 @@
|
||||
/* Copyright (C) 2017 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. */
|
||||
|
||||
/***********************************************************************
|
||||
* $Id$
|
||||
*
|
||||
* mcsv1_UDAF.h
|
||||
***********************************************************************/
|
||||
|
||||
/**
|
||||
* Columnstore interface for writing a User Defined Aggregate
|
||||
* Functions (UDAF) and User Defined Analytic Functions (UDAnF)
|
||||
* or a function that can act as either - UDA(n)F
|
||||
*
|
||||
* The basic steps are:
|
||||
*
|
||||
* 1. Create a the UDA(n)F function interface in some .h file.
|
||||
* 2. Create the UDF function implementation in some .cpp file
|
||||
* 3. Create the connector stub (MariaDB UDAF definition) for
|
||||
* this UDF function.
|
||||
* 4. build the dynamic library using all of the source.
|
||||
* 5 Put the library in $COLUMNSTORE_INSTALL/lib of
|
||||
* all modules
|
||||
* 6. restart the Columnstore system.
|
||||
* 7. notify mysqld about the new functions with commands like:
|
||||
*
|
||||
* // An example of xor over a range for UDAF and UDAnF
|
||||
* CREATE AGGREGATE FUNCTION mcs_bit_xor returns BOOL soname
|
||||
* 'libudfsdk.so';
|
||||
*
|
||||
* // An example that only makes sense as a UDAnF
|
||||
* CREATE AGGREGATE FUNCTION mcs_interpolate returns REAL
|
||||
* soname 'libudfsdk.so';
|
||||
*
|
||||
* The UDAF functions may run distributed in the Columnstore
|
||||
* engine. UDAnF do not run distributed.
|
||||
*
|
||||
* UDAF is User Defined Aggregate Function.
|
||||
* UDAnF is User Defined Analytic Function.
|
||||
* UDA(n)F is an acronym for a function that could be either. It
|
||||
* is also used to describe the interface that is used for
|
||||
* either.
|
||||
*/
|
||||
#ifndef HEADER_mcsv1_udaf
|
||||
#define HEADER_mcsv1_udaf
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/any.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#include <unordered_map>
|
||||
#else
|
||||
#include <tr1/unordered_map>
|
||||
#endif
|
||||
#include "any.hpp"
|
||||
#include "calpontsystemcatalog.h"
|
||||
#include "wf_frame.h"
|
||||
|
||||
using namespace execplan;
|
||||
|
||||
#if defined(_MSC_VER) && defined(xxxRGNODE_DLLEXPORT)
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define EXPORT
|
||||
#endif
|
||||
|
||||
namespace mcsv1sdk
|
||||
{
|
||||
/**
|
||||
* A map from name to function object.
|
||||
*
|
||||
* This is temporary until we get the library loading task
|
||||
* complete
|
||||
*
|
||||
* TODO: Remove when library loading is enabled.
|
||||
*/
|
||||
class mcsv1_UDAF;
|
||||
typedef std::tr1::unordered_map<std::string, mcsv1_UDAF*> UDAF_MAP;
|
||||
|
||||
class UDAFMap
|
||||
{
|
||||
public:
|
||||
EXPORT UDAFMap(){};
|
||||
|
||||
EXPORT ~UDAFMap(){};
|
||||
|
||||
static EXPORT UDAF_MAP& getMap();
|
||||
private:
|
||||
static UDAF_MAP fm;
|
||||
};
|
||||
|
||||
/**
|
||||
* A class to hold your user data
|
||||
*
|
||||
* If your UDAF only needs a fixed sized data struct, you need
|
||||
* do nothing with this. Call setUserDataSize in your init
|
||||
* function with the required size and the framework will take
|
||||
* care of it.
|
||||
*
|
||||
* If you need something more or just want to control things,
|
||||
* then override UserData with your data structure and
|
||||
* implement createUserData in your function object to create
|
||||
* your data structure. Your UserData destuctor should take care
|
||||
* of any cleanup you may need (Simple containers clean
|
||||
* themselves up).
|
||||
*/
|
||||
class mcsv1Context;
|
||||
|
||||
struct UserData
|
||||
{
|
||||
UserData() : size(0), data(NULL) {};
|
||||
UserData(size_t sz) {size = sz; data = new uint8_t[sz];}
|
||||
|
||||
virtual ~UserData() { if (data) delete [] data;}
|
||||
|
||||
/**
|
||||
* serialize()
|
||||
*
|
||||
* User data is passed between process. In order to do so, it
|
||||
* must be serialized. Since user data can have sub objects,
|
||||
* containers and the like, it is up to the UDAF to provide the
|
||||
* serialize function. The streaming functionality of
|
||||
* messageqcpp::ByteStream must be used.
|
||||
*
|
||||
* The default streams the size and data buffer to the
|
||||
* ByteStream
|
||||
*/
|
||||
virtual void serialize(messageqcpp::ByteStream& bs) const;
|
||||
|
||||
/**
|
||||
* unserialize()
|
||||
*
|
||||
* User data is passed between process. In order to do so, it
|
||||
* must be unserialized. Since user data can have sub objects,
|
||||
* containers and the like, it is up to the UDAF to provide the
|
||||
* unserialize function. The streaming functionality of
|
||||
* messageqcpp::ByteStream must be used.
|
||||
*
|
||||
* data is the datablock returned by createUserData.
|
||||
*
|
||||
* The default creates the data array and streams into data.
|
||||
*/
|
||||
virtual void unserialize(messageqcpp::ByteStream& bs);
|
||||
|
||||
// The default data store. You may or may not wish to use these fields.
|
||||
uint32_t size;
|
||||
uint8_t* data;
|
||||
private:
|
||||
// For now, copy construction is unwanted
|
||||
UserData(UserData&);
|
||||
};
|
||||
|
||||
// Flags to define the type and limitations of a UDA(n)F
|
||||
// Used in context->fRunFlags
|
||||
static uint64_t UDAF_OVER_REQUIRED __attribute__ ((unused)) = 1; // May only be used as UDAnF
|
||||
static uint64_t UDAF_OVER_ALLOWED __attribute__ ((unused)) = 1 << 1; // May be used as UDAF or UDAnF
|
||||
static uint64_t UDAF_ORDER_REQUIRED __attribute__ ((unused)) = 1 << 2; // If used as UDAnF, ORDER BY is required
|
||||
static uint64_t UDAF_ORDER_ALLOWED __attribute__ ((unused)) = 1 << 3; // If used as UDAnF, ORDER BY is optional
|
||||
static uint64_t UDAF_WINDOWFRAME_REQUIRED __attribute__ ((unused)) = 1 << 4; // If used as UDAnF, a WINDOW FRAME is required
|
||||
static uint64_t UDAF_WINDOWFRAME_ALLOWED __attribute__ ((unused)) = 1 << 5; // If used as UDAnF, a WINDOW FRAME is optional
|
||||
static uint64_t UDAF_MAYBE_NULL __attribute__ ((unused)) = 1 << 6; // If UDA(n)F might return NULL.
|
||||
static uint64_t UDAF_IGNORE_NULLS __attribute__ ((unused)) = 1 << 7; // If UDA(n)F wants NULL rows suppressed.
|
||||
|
||||
// Flags set by the framework to define the context of the call.
|
||||
// User code shouldn't use these directly
|
||||
// used in context->fContextFlags
|
||||
static uint64_t CONTEXT_IS_ANALYTIC __attribute__ ((unused)) = 1; // If called using OVER
|
||||
static uint64_t CONTEXT_HAS_CURRENT_ROW __attribute__ ((unused)) = 1 << 1; // The current window contains the current row.
|
||||
static uint64_t CONTEXT_IS_PM __attribute__ ((unused)) = 1 << 2; // The call was made by the PM
|
||||
|
||||
// Flags that describe the contents of a specific input parameter
|
||||
// These will be set in context->dataFlags for each method call by the framework.
|
||||
// User code shouldn't use these directly
|
||||
static uint64_t PARAM_IS_NULL __attribute__ ((unused)) = 1;
|
||||
static uint64_t PARAM_IS_CONSTANT __attribute__ ((unused)) = 1 << 1;
|
||||
|
||||
// shorthand for the list of columns in the call sent to init()
|
||||
// first is the actual column name and second is the data type in Columnstore.
|
||||
typedef std::vector<std::pair<std::string, CalpontSystemCatalog::ColDataType> >COL_TYPES;
|
||||
|
||||
// This is the context class that is passed to all API callbacks
|
||||
// The framework potentially sets data here for each invocation of
|
||||
// mcsv1_UDAF methods. Access methods are given for data useful to UDA(n)F.
|
||||
// Don't modify anything directly except data retrieved with getUserData().
|
||||
|
||||
// UDA(n)F devlopers should not modify this class. The framework and other UDA(n)F
|
||||
// rely on it being as it was when they were compiled.
|
||||
//
|
||||
// It's probable that future versions of Columnstore will add functionality to
|
||||
// the context. UDA(n)F may need to be re-compiled in this case.
|
||||
class mcsv1Context
|
||||
{
|
||||
public:
|
||||
EXPORT mcsv1Context();
|
||||
EXPORT mcsv1Context(const mcsv1Context& rhs);
|
||||
// The destructor is virtual only in case a version 2 is made derived from v1
|
||||
// to promote backward compatibility.
|
||||
// mcsv1Context should never be subclassed by UDA(n)F developers
|
||||
EXPORT virtual ~mcsv1Context();
|
||||
|
||||
// Set an error message if something goes wrong
|
||||
EXPORT void setErrorMessage(std::string errmsg);
|
||||
|
||||
// Get the previously set error message
|
||||
EXPORT const std::string& getErrorMessage() const;
|
||||
|
||||
// Set the flags as a set. Return the previous flags.
|
||||
EXPORT uint64_t setRunFlags(uint64_t flags);
|
||||
// return the flags
|
||||
EXPORT uint64_t getRunFlags() const;
|
||||
|
||||
// The following set, get, clear and toggle methods can be used to manipulate
|
||||
// multiple flags by ORing them together in the call sequence.
|
||||
// Ex setRunFlag(UDAF_OVER_REQUIRED | UDAF_ORDER_REQUIRED);
|
||||
// sets both flags and returns true if BOTH flags are already set.
|
||||
//
|
||||
// Set a specific flag and return its previous setting
|
||||
EXPORT bool setRunFlag(uint64_t flag);
|
||||
// Get a specific flag
|
||||
EXPORT bool getRunFlag(uint64_t flag);
|
||||
// clear a specific flag and return its previous setting
|
||||
EXPORT bool clearRunFlag(uint64_t flag);
|
||||
// toggle a specific flag and return its previous setting
|
||||
EXPORT bool toggleRunFlag(uint64_t flag);
|
||||
|
||||
// Use these to determine the way your UDA(n)F was called
|
||||
// Valid in all method calls
|
||||
EXPORT bool isAnalytic();
|
||||
EXPORT bool isWindowHasCurrentRow();
|
||||
|
||||
// Determine if the call is made by the UM
|
||||
// This could be because the UDA(n)F is not being distributed
|
||||
// Or it could be during setup or during consolodation of PM values.
|
||||
// valid in all calls
|
||||
EXPORT bool isUM();
|
||||
|
||||
// Determine if the call is made by the PM
|
||||
// This will be during partial aggregation performed on the PM
|
||||
// valid in all calls
|
||||
EXPORT bool isPM();
|
||||
|
||||
// Parameter refinement description accessors
|
||||
// valid in nextValue, dropValue and evaluateCumulative
|
||||
size_t getParameterCount() const;
|
||||
|
||||
// Determine if an input parameter is NULL
|
||||
// valid in nextValue, dropValue and evaluateCumulative
|
||||
EXPORT bool isParamNull(int paramIdx);
|
||||
|
||||
// If a parameter is a constant, the UDA(n)F could presumably optimize its workings.
|
||||
// During the first call to nextValue() or evaluateCumulative().
|
||||
// Is there a better way to determine this?
|
||||
// valid in nextValue, dropValue and evaluateCumulative
|
||||
EXPORT bool isParamConstant(int paramIdx);
|
||||
|
||||
// For getting the result type.
|
||||
EXPORT CalpontSystemCatalog::ColDataType getResultType() const;
|
||||
|
||||
// For getting the decimal characteristics for the return value.
|
||||
// These will be set to the default before init().
|
||||
EXPORT int32_t getScale() const;
|
||||
EXPORT int32_t getPrecision() const;
|
||||
|
||||
// If you want to change the result type
|
||||
// valid in init()
|
||||
EXPORT bool setResultType(CalpontSystemCatalog::ColDataType resultType);
|
||||
|
||||
// For setting the decimal characteristics for the return value.
|
||||
// This only makes sense if the return type is decimal, but should be set
|
||||
// to (0, -1) for other types if the inout is decimal.
|
||||
// valid in init()
|
||||
EXPORT bool setScale(int32_t scale);
|
||||
EXPORT bool setPrecision(int32_t precision);
|
||||
|
||||
// For all types, get the return column width in bytes. Ex. INT will return 4.
|
||||
EXPORT int32_t getColWidth();
|
||||
|
||||
// For non-numric return types, set the return column width. This defaults
|
||||
// to the the length of the input.
|
||||
// valid in init()
|
||||
EXPORT bool setColWidth(int32_t colWidth);
|
||||
|
||||
// If a method is known to take a while, call this periodically to see if something
|
||||
// interupted the processing. If getInterrupted() returns true, then the executing
|
||||
// method should clean up and exit.
|
||||
EXPORT bool getInterrupted() const;
|
||||
|
||||
// Returns the actual number of rows in the partition. If no partitioning, returns 0.
|
||||
// valid in reset()
|
||||
EXPORT uint64_t getRowsInPartition() const;
|
||||
|
||||
// Returns the number of rows in the aggregate. This could be the total number of rows,
|
||||
// the number of rows in the group, or the number of rows in the PM's subaggregate,
|
||||
// depending on the context it was called.
|
||||
// valid in subEvaluate() end evaluate().
|
||||
EXPORT uint64_t getRowCnt() const;
|
||||
|
||||
// Allocate instance specific memory. This should be type cast to a structure overlay
|
||||
// defined by the function. The actual allocatoin occurs in the various modules that
|
||||
// do the aggregation. If the UDAF is being calculated in a distributed fashion, then
|
||||
// multiple instances of this data may be allocated. Calls to the subaggregate functions
|
||||
// do not share a context.
|
||||
// You do not need to worry about freeing this memory. The framework handles all management.
|
||||
// Call this during init()
|
||||
EXPORT void setUserDataSize(int bytes);
|
||||
|
||||
// Call this everywhere except init()
|
||||
EXPORT UserData* getUserData();
|
||||
|
||||
// Many UDAnF need a default Window Frame. If none is set here, the default is
|
||||
// UNBOUNDED PRECEDING to CURRENT ROW.
|
||||
// It's possible to not allow the the WINDOW FRAME phrase in the UDAnF by setting
|
||||
// the UDAF_WINDOWFRAME_REQUIRED and UDAF_WINDOWFRAME_ALLOWED both to false. Columnstore
|
||||
// requires a Window Frame in order to process UDAnF. In this case, the default will
|
||||
// be used for all calls.
|
||||
// Possible values for start frame are
|
||||
// WF_UNBOUNDED_PRECEDING, WF_CURRENT_ROW, WF_PRECEDING or WF_FOLLOWING
|
||||
// possible values for end frame are
|
||||
// WF_CURRENT_ROW, WF_UNBOUNDED_FOLLOWING, WF_PRECEDING or WF_FOLLOWING
|
||||
// If WF_PRECEEdING and/or WF_FOLLOWING, a start or end constant should
|
||||
// be included to say how many preceeding or following is the default
|
||||
// Set this during init()
|
||||
EXPORT bool setDefaultWindowFrame(WF_FRAME defaultStartFrame,
|
||||
WF_FRAME defaultEndFrame,
|
||||
int32_t startConstant = 0, // For WF_PRECEEDING or WF_FOLLOWING
|
||||
int32_t endConstant = 0); // For WF_PRECEEDING or WF_FOLLOWING
|
||||
|
||||
// There may be times you want to know the actual frame set by the caller
|
||||
EXPORT void getStartFrame(WF_FRAME& startFrame, int32_t& startConstant) const;
|
||||
EXPORT void getEndFrame(WF_FRAME& endFrame, int32_t& endConstant) const;
|
||||
|
||||
// Deep Equivalence
|
||||
bool operator==(const mcsv1Context& c) const;
|
||||
bool operator!=(const mcsv1Context& c) const;
|
||||
|
||||
// stream operator for debugging
|
||||
EXPORT const std::string toString() const;
|
||||
|
||||
// Get the name of the function
|
||||
EXPORT const std::string& getName() const;
|
||||
|
||||
EXPORT mcsv1Context& operator=(const mcsv1Context& rhs);
|
||||
EXPORT mcsv1Context& copy(const mcsv1Context& rhs);
|
||||
|
||||
private:
|
||||
|
||||
uint64_t fRunFlags; // Set by the user to define the type of UDA(n)F
|
||||
uint64_t fContextFlags; // Set by the framework to define this specific call.
|
||||
int32_t fUserDataSize;
|
||||
boost::shared_ptr<UserData> fUserData;
|
||||
CalpontSystemCatalog::ColDataType fResultType;
|
||||
int32_t fColWidth; // The length in bytes of the return type
|
||||
int32_t fResultscale; // For scale, the number of digits to the right of the decimal
|
||||
int32_t fResultPrecision; // The max number of digits allowed in the decimal value
|
||||
std::string errorMsg;
|
||||
std::vector<uint32_t>* dataFlags; // one entry for each parameter
|
||||
bool* bInterrupted; // Gets set to true by the Framework if something happens
|
||||
uint64_t fRowsInPartition; // Only valid in reset()
|
||||
int64_t fRowCnt; // The number of rows involved in this aggregate.
|
||||
WF_FRAME fStartFrame; // Is set to default to start, then modified by the actual frame in the call
|
||||
WF_FRAME fEndFrame; // Is set to default to start, then modified by the actual frame in the call
|
||||
int32_t fStartConstant; // for start frame WF_PRECEEDIMG or WF_FOLLOWING
|
||||
int32_t fEndConstant; // for end frame WF_PRECEEDIMG or WF_FOLLOWING
|
||||
std::string functionName;
|
||||
mcsv1sdk::mcsv1_UDAF* func;
|
||||
|
||||
public:
|
||||
// For use by the framework
|
||||
EXPORT void serialize(messageqcpp::ByteStream& b) const;
|
||||
EXPORT void unserialize(messageqcpp::ByteStream& b);
|
||||
EXPORT void createUserData();
|
||||
EXPORT void setUserData(boost::shared_ptr<UserData> userData);
|
||||
EXPORT void setUserData(UserData* userData);
|
||||
EXPORT void setName(std::string name);
|
||||
EXPORT void setContextFlags(uint64_t flags);
|
||||
EXPORT void setContextFlag(uint64_t flag);
|
||||
EXPORT void clearContextFlag(uint64_t flag);
|
||||
EXPORT uint64_t getContextFlags() const;
|
||||
EXPORT uint32_t getUserDataSize() const;
|
||||
EXPORT std::vector<uint32_t>& getDataFlags();
|
||||
EXPORT void setDataFlags(std::vector<uint32_t>* flags);
|
||||
EXPORT void setInterrupted(bool interrupted);
|
||||
EXPORT void setInterrupted(bool* interrupted);
|
||||
EXPORT void setRowCnt(uint64_t cnt);
|
||||
EXPORT mcsv1sdk::mcsv1_UDAF* getFunction();
|
||||
EXPORT mcsv1sdk::mcsv1_UDAF* getFunction() const;
|
||||
EXPORT boost::shared_ptr<UserData> getUserDataSP();
|
||||
};
|
||||
|
||||
// Since aggregate functions can operate on any data type, we use the following structure
|
||||
// to define the input row data. To be type insensiteve, data is stored in type static_any::any.
|
||||
//
|
||||
// To access the data it must be type cast to the correct type using boost::any_cast.
|
||||
// example for int data:
|
||||
//
|
||||
// if (dataType == CalpontSystemCatalog::INT)
|
||||
// int myint = boost::any_cast<int>columnData;
|
||||
//
|
||||
// For multi-paramter aggregations, the colsIn vector of next_value()
|
||||
// contains the ordered set of row parameters.
|
||||
//
|
||||
// For char, varchar, text, varbinary and blob types, columnData will be std::string.
|
||||
struct ColumnDatum
|
||||
{
|
||||
CalpontSystemCatalog::ColDataType dataType; // defined in calpontsystemcatalog.h
|
||||
static_any::any columnData;
|
||||
uint32_t scale; // If dataType is a DECIMAL type
|
||||
uint32_t precision; // If dataType is a DECIMAL type
|
||||
ColumnDatum() : dataType(CalpontSystemCatalog::UNDEFINED), scale(0), precision(-1){};
|
||||
};
|
||||
|
||||
// Override mcsv1_UDAF to build your User Defined Aggregate (UDAF) and/or
|
||||
// User Defined Analytic Function (UDAnF).
|
||||
// These will be singleton classes, so don't put any instance
|
||||
// specific data in here. All instance data is stored in mcsv1Context
|
||||
// passed to each user function and retrieved by the getUserData() method.
|
||||
//
|
||||
// Each API function returns a ReturnCode. If ERROR is returned at any time,
|
||||
// the query is aborted, getInterrupted() will begin to return true and the
|
||||
// message set in config->setErrorMessage() is returned to MariaDB.
|
||||
class mcsv1_UDAF
|
||||
{
|
||||
public:
|
||||
enum ReturnCode
|
||||
{
|
||||
ERROR = 0,
|
||||
SUCCESS = 1,
|
||||
NOT_IMPLEMENTED = 2 // User UDA(n)F shouldn't return this
|
||||
};
|
||||
// Defaults OK
|
||||
mcsv1_UDAF(){};
|
||||
virtual ~mcsv1_UDAF(){};
|
||||
|
||||
/**
|
||||
* init()
|
||||
*
|
||||
* Mandatory. Implement this to initialize flags and instance
|
||||
* data. Called once per SQL statement. You can do any sanity
|
||||
* checks here.
|
||||
*
|
||||
* colTypes (in) - A vector of ColDataType defining the
|
||||
* parameters of the UDA(n)F call. These can be used to decide
|
||||
* to override the default return type. If desired, the new
|
||||
* return type can be set by context->setReturnType() and
|
||||
* decimal scale and precision can be set by context->setScale
|
||||
* and context->setPrecision respectively.
|
||||
*
|
||||
* Return mcsv1_UDAF::ERROR on any error, such as non-compatible
|
||||
* colTypes or wrong number of arguments. Else return
|
||||
* mcsv1_UDAF::SUCCESS.
|
||||
*/
|
||||
virtual ReturnCode init(mcsv1Context* context,
|
||||
COL_TYPES& colTypes) = 0;
|
||||
|
||||
/**
|
||||
* finish()
|
||||
*
|
||||
* Mandatory. Completes the UDA(n)F. Called once per SQL
|
||||
* statement. Do not free any memory allocated by
|
||||
* createUserData(). The SDK Framework owns that memory
|
||||
* and will handle that. Often, there is nothing to do here.
|
||||
*/
|
||||
virtual ReturnCode finish(mcsv1Context* context) = 0;
|
||||
|
||||
/**
|
||||
* reset()
|
||||
*
|
||||
* Mandatory. Reset the UDA(n)F for a new group, partition or,
|
||||
* in some cases, new Window Frame. Do not free any memory
|
||||
* allocated by createUserData(). The SDK Framework owns
|
||||
* that memory and will handle that. Use this opportunity to
|
||||
* reset any variables in context->getUserData() needed for the
|
||||
* next aggregation. May be called multiple times if running in
|
||||
* a ditributed fashion.
|
||||
*
|
||||
* Use this opportunity to initialize the userData.
|
||||
*/
|
||||
virtual ReturnCode reset(mcsv1Context* context) = 0;
|
||||
|
||||
/**
|
||||
* nextValue()
|
||||
*
|
||||
* Mandatory. Handle a single row.
|
||||
*
|
||||
* colsIn - A vector of data structure describing the input
|
||||
* data.
|
||||
*
|
||||
* This function is called once for every row in the filtered
|
||||
* result set (before aggregation). It is very important that
|
||||
* this function is efficient.
|
||||
*
|
||||
* If the UDAF is running in a distributed fashion, nextValue
|
||||
* cannot depend on order, as it will only be called for each
|
||||
* row found on the specific PM.
|
||||
*
|
||||
* valsIn (in) - a vector of the parameters from the row.
|
||||
*/
|
||||
virtual ReturnCode nextValue(mcsv1Context* context,
|
||||
std::vector<ColumnDatum>& valsIn) = 0;
|
||||
|
||||
/**
|
||||
* subEvaluate()
|
||||
*
|
||||
* Mandatory -- Called if the UDAF is running in a distributed
|
||||
* fashion. Columnstore tries to run all aggregate functions
|
||||
* distributed, depending on context.
|
||||
*
|
||||
* Perform an aggregation on rows partially aggregated by
|
||||
* nextValue. Columnstore calls nextValue for each row on a
|
||||
* given PM for a group (GROUP BY). subEvaluate is called on the
|
||||
* UM to consolodate those values into a single instance of
|
||||
* userData. Keep your aggregated totals in context's userData.
|
||||
* The first time this is called for a group, reset() would have
|
||||
* been called with this version of userData.
|
||||
*
|
||||
* Called for every partial data set in each group in GROUP BY.
|
||||
*
|
||||
* When subEvaluate has been called for all subAggregated data
|
||||
* sets, Evaluate will be called with the same context as here.
|
||||
*
|
||||
* valIn (In) - This is a pointer to a UserData class with the
|
||||
* partially aggregated values. It will contain the value of
|
||||
* userData as seen in the last call to NextValue for a given
|
||||
* PM.
|
||||
*
|
||||
*/
|
||||
virtual ReturnCode subEvaluate(mcsv1Context* context, const UserData* userDataIn) = 0;
|
||||
|
||||
/**
|
||||
* evaluate()
|
||||
*
|
||||
* Mandatory. Get the aggregated value.
|
||||
*
|
||||
* Called for every new group if UDAF GROUP BY, UDAnF partition
|
||||
* or, in some cases, new Window Frame.
|
||||
*
|
||||
* Set the aggregated value into valOut. The datatype is assumed
|
||||
* to be the same as that set in the init() function;
|
||||
*
|
||||
* If the UDAF is running in a distributed fashion, evaluate is
|
||||
* called after a series of subEvaluate calls.
|
||||
*
|
||||
* valOut (out) - Set the aggregated value here. The datatype is
|
||||
* assumed to be the same as that set in the init() function;
|
||||
*
|
||||
* To return a NULL value, don't assign to valOut.
|
||||
*/
|
||||
virtual ReturnCode evaluate(mcsv1Context* context, static_any::any& valOut) = 0;
|
||||
|
||||
/**
|
||||
* dropValue()
|
||||
*
|
||||
* Optional -- If defined, the server will call this instead of
|
||||
* reset for UDAnF.
|
||||
*
|
||||
* Don't implement if a UDAnF has one or more of the following:
|
||||
* The UDAnF can't be used with a Window Frame
|
||||
* The UDAnF is not reversable in some way
|
||||
* The UDAnF is not interested in optimal performance
|
||||
*
|
||||
* If not implemented, reset() followed by a series of
|
||||
* nextValue() will be called for each movement of the Window
|
||||
* Frame.
|
||||
*
|
||||
* If implemented, then each movement of the Window Frame will
|
||||
* result in dropValue() being called for each row falling out
|
||||
* of the Frame and nextValue() being called for each new row
|
||||
* coming into the Frame.
|
||||
*
|
||||
* valsDropped (in) - a vector of the parameters from the row
|
||||
* leaving the Frame
|
||||
*
|
||||
* dropValue() will not be called for unbounded/current row type
|
||||
* frames, as those are already optimized.
|
||||
*/
|
||||
virtual ReturnCode dropValue(mcsv1Context* context,
|
||||
std::vector<ColumnDatum>& valsDropped);
|
||||
|
||||
/**
|
||||
* createUserData()
|
||||
*
|
||||
* Optional -- The default is to create a data byte array of
|
||||
* size as set in context->setUserDataSize()
|
||||
*
|
||||
* Create your variable length data structure via
|
||||
* userData = new <UserData_type>
|
||||
*
|
||||
* The data structure may contain references to containers or
|
||||
* pointers to other objects. Remember that for distributed
|
||||
* processing, this may be called multiple times for variaous
|
||||
* computing blocks. At the least, it will be called once per PM
|
||||
* that processes the data, and once more for the UM. For UDAnF,
|
||||
* it may only be called once.
|
||||
*
|
||||
* Set length to the base length of the data structure you
|
||||
* create.
|
||||
*
|
||||
*/
|
||||
virtual ReturnCode createUserData(UserData*& userdata, int32_t& length);
|
||||
|
||||
protected:
|
||||
// These are handy for testing the actual type of static_any
|
||||
static const static_any::any& charTypeId;
|
||||
static const static_any::any& scharTypeId;
|
||||
static const static_any::any& shortTypeId;
|
||||
static const static_any::any& intTypeId;
|
||||
static const static_any::any& longTypeId;
|
||||
static const static_any::any& llTypeId;
|
||||
static const static_any::any& ucharTypeId;
|
||||
static const static_any::any& ushortTypeId;
|
||||
static const static_any::any& uintTypeId;
|
||||
static const static_any::any& ulongTypeId;
|
||||
static const static_any::any& ullTypeId;
|
||||
static const static_any::any& floatTypeId;
|
||||
static const static_any::any& doubleTypeId;
|
||||
static const static_any::any& strTypeId;
|
||||
};
|
||||
|
||||
/***********************************************************************
|
||||
* There is no user modifiable code past this point
|
||||
***********************************************************************/
|
||||
// Function definitions for mcsv1Context
|
||||
inline mcsv1Context::mcsv1Context() :
|
||||
fRunFlags(UDAF_OVER_ALLOWED | UDAF_ORDER_ALLOWED | UDAF_WINDOWFRAME_ALLOWED),
|
||||
fContextFlags(0),
|
||||
fUserDataSize(0),
|
||||
fResultType(CalpontSystemCatalog::UNDEFINED),
|
||||
fColWidth(0),
|
||||
fResultscale(0),
|
||||
fResultPrecision(18),
|
||||
dataFlags(NULL),
|
||||
bInterrupted(NULL),
|
||||
fRowsInPartition(0),
|
||||
fStartFrame(WF_UNBOUNDED_PRECEDING),
|
||||
fEndFrame(WF_CURRENT_ROW),
|
||||
fStartConstant(0),
|
||||
fEndConstant(0),
|
||||
func(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
inline mcsv1Context::mcsv1Context(const mcsv1Context& rhs) :
|
||||
fContextFlags(0),
|
||||
fColWidth(0),
|
||||
dataFlags(NULL),
|
||||
bInterrupted(NULL),
|
||||
func(NULL)
|
||||
{
|
||||
copy(rhs);
|
||||
}
|
||||
|
||||
inline mcsv1Context& mcsv1Context::copy(const mcsv1Context& rhs)
|
||||
{
|
||||
fRunFlags = rhs.getRunFlags();
|
||||
fResultType = rhs.getResultType();
|
||||
fUserDataSize = rhs.getUserDataSize();
|
||||
fResultscale = rhs.getScale();
|
||||
fResultPrecision = rhs.getPrecision();
|
||||
rhs.getStartFrame(fStartFrame, fStartConstant);
|
||||
rhs.getEndFrame(fEndFrame, fEndConstant);
|
||||
functionName = rhs.getName();
|
||||
bInterrupted = rhs.bInterrupted; // Multiple threads will use the same reference
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline mcsv1Context::~mcsv1Context()
|
||||
{
|
||||
}
|
||||
|
||||
inline mcsv1Context& mcsv1Context::operator=(const mcsv1Context& rhs)
|
||||
{
|
||||
fContextFlags = 0;
|
||||
fColWidth = 0;
|
||||
dataFlags = NULL;
|
||||
bInterrupted = NULL;
|
||||
func = NULL;
|
||||
return copy(rhs);
|
||||
}
|
||||
|
||||
inline void mcsv1Context::setErrorMessage(std::string errmsg)
|
||||
{
|
||||
errorMsg = errmsg;
|
||||
}
|
||||
|
||||
inline const std::string& mcsv1Context::getErrorMessage() const
|
||||
{
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
inline uint64_t mcsv1Context::setRunFlags(uint64_t flags)
|
||||
{
|
||||
uint64_t f = fRunFlags;
|
||||
fRunFlags = flags;
|
||||
return f;
|
||||
}
|
||||
|
||||
inline uint64_t mcsv1Context::getRunFlags() const
|
||||
{
|
||||
return fRunFlags;
|
||||
}
|
||||
|
||||
inline bool mcsv1Context::setRunFlag(uint64_t flag)
|
||||
{
|
||||
bool b = fRunFlags & flag;
|
||||
fRunFlags |= flag;
|
||||
return b;
|
||||
}
|
||||
|
||||
inline bool mcsv1Context::getRunFlag(uint64_t flag)
|
||||
{
|
||||
return fRunFlags & flag;
|
||||
}
|
||||
|
||||
inline bool mcsv1Context::clearRunFlag(uint64_t flag)
|
||||
{
|
||||
bool b = fRunFlags & flag;
|
||||
fRunFlags &= ~flag;
|
||||
return b;
|
||||
}
|
||||
|
||||
inline bool mcsv1Context::toggleRunFlag(uint64_t flag)
|
||||
{
|
||||
bool b = fRunFlags & flag;
|
||||
fRunFlags ^= flag;
|
||||
return b;
|
||||
}
|
||||
|
||||
inline bool mcsv1Context::isAnalytic()
|
||||
{
|
||||
return fContextFlags & CONTEXT_IS_ANALYTIC;
|
||||
}
|
||||
|
||||
inline bool mcsv1Context::isWindowHasCurrentRow()
|
||||
{
|
||||
return fContextFlags & CONTEXT_HAS_CURRENT_ROW;
|
||||
}
|
||||
|
||||
inline bool mcsv1Context::isUM()
|
||||
{
|
||||
return !(fContextFlags & CONTEXT_IS_PM);
|
||||
}
|
||||
|
||||
inline bool mcsv1Context::isPM()
|
||||
{
|
||||
return fContextFlags & CONTEXT_IS_PM;
|
||||
}
|
||||
|
||||
inline size_t mcsv1Context::getParameterCount() const
|
||||
{
|
||||
if (dataFlags)
|
||||
return dataFlags->size();
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline bool mcsv1Context::isParamNull(int paramIdx)
|
||||
{
|
||||
if (dataFlags)
|
||||
return (*dataFlags)[paramIdx] & PARAM_IS_NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool mcsv1Context::isParamConstant(int paramIdx)
|
||||
{
|
||||
if (dataFlags)
|
||||
return (*dataFlags)[paramIdx] & PARAM_IS_CONSTANT;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline CalpontSystemCatalog::ColDataType mcsv1Context::getResultType() const
|
||||
{
|
||||
return fResultType;
|
||||
}
|
||||
|
||||
inline bool mcsv1Context::setResultType(CalpontSystemCatalog::ColDataType resultType)
|
||||
{
|
||||
fResultType = resultType;
|
||||
return true; // We may want to sanity check here.
|
||||
}
|
||||
|
||||
inline int32_t mcsv1Context::getScale() const
|
||||
{
|
||||
return fResultscale;
|
||||
}
|
||||
|
||||
inline int32_t mcsv1Context::getPrecision() const
|
||||
{
|
||||
return fResultPrecision;
|
||||
}
|
||||
|
||||
inline bool mcsv1Context::setScale(int32_t scale)
|
||||
{
|
||||
fResultscale = scale;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool mcsv1Context::setPrecision(int32_t precision)
|
||||
{
|
||||
fResultPrecision = precision;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool mcsv1Context::setColWidth(int32_t colWidth)
|
||||
{
|
||||
fColWidth = colWidth;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void mcsv1Context::setInterrupted(bool interrupted)
|
||||
{
|
||||
if (bInterrupted)
|
||||
{
|
||||
*bInterrupted = interrupted;
|
||||
}
|
||||
}
|
||||
|
||||
inline void mcsv1Context::setInterrupted(bool* interrupted)
|
||||
{
|
||||
bInterrupted = interrupted;
|
||||
}
|
||||
|
||||
inline bool mcsv1Context::getInterrupted() const
|
||||
{
|
||||
if (bInterrupted)
|
||||
{
|
||||
return bInterrupted;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline uint64_t mcsv1Context::getRowsInPartition() const
|
||||
{
|
||||
return fRowsInPartition;
|
||||
}
|
||||
|
||||
inline uint64_t mcsv1Context::getRowCnt() const
|
||||
{
|
||||
return fRowCnt;
|
||||
}
|
||||
|
||||
inline void mcsv1Context::setUserDataSize(int bytes)
|
||||
{
|
||||
fUserDataSize = bytes;
|
||||
}
|
||||
|
||||
inline UserData* mcsv1Context::getUserData()
|
||||
{
|
||||
if (!fUserData)
|
||||
{
|
||||
createUserData();
|
||||
}
|
||||
return fUserData.get();
|
||||
}
|
||||
|
||||
inline boost::shared_ptr<UserData> mcsv1Context::getUserDataSP()
|
||||
{
|
||||
if (!fUserData)
|
||||
{
|
||||
createUserData();
|
||||
}
|
||||
return fUserData;
|
||||
}
|
||||
|
||||
inline void mcsv1Context::setUserData(boost::shared_ptr<UserData> userData)
|
||||
{
|
||||
fUserData = userData;
|
||||
}
|
||||
|
||||
inline void mcsv1Context::setUserData(UserData* userData)
|
||||
{
|
||||
if (userData)
|
||||
{
|
||||
fUserData.reset(userData);
|
||||
}
|
||||
else
|
||||
{
|
||||
fUserData.reset();
|
||||
}
|
||||
}
|
||||
|
||||
inline bool mcsv1Context::setDefaultWindowFrame(WF_FRAME defaultStartFrame,
|
||||
WF_FRAME defaultEndFrame,
|
||||
int32_t startConstant,
|
||||
int32_t endConstant)
|
||||
{
|
||||
// TODO: Add sanity checks
|
||||
fStartFrame = defaultStartFrame;
|
||||
fEndFrame = defaultEndFrame;
|
||||
fStartConstant = startConstant;
|
||||
fEndConstant = endConstant;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void mcsv1Context::getStartFrame(WF_FRAME& startFrame, int32_t& startConstant) const
|
||||
{
|
||||
startFrame = fStartFrame;
|
||||
startConstant = fStartConstant;
|
||||
}
|
||||
|
||||
inline void mcsv1Context::getEndFrame(WF_FRAME& endFrame, int32_t& endConstant) const
|
||||
{
|
||||
endFrame = fEndFrame;
|
||||
endConstant = fEndConstant;
|
||||
}
|
||||
|
||||
inline const std::string& mcsv1Context::getName() const
|
||||
{
|
||||
return functionName;
|
||||
}
|
||||
|
||||
inline void mcsv1Context::setName(std::string name)
|
||||
{
|
||||
functionName = name;
|
||||
}
|
||||
|
||||
inline void mcsv1Context::setRowCnt(uint64_t cnt)
|
||||
{
|
||||
fRowCnt = cnt;
|
||||
}
|
||||
|
||||
inline uint64_t mcsv1Context::getContextFlags() const
|
||||
{
|
||||
return fContextFlags;
|
||||
}
|
||||
|
||||
inline void mcsv1Context::setContextFlags(uint64_t flags)
|
||||
{
|
||||
fContextFlags = flags;
|
||||
}
|
||||
|
||||
inline void mcsv1Context::setContextFlag(uint64_t flag)
|
||||
{
|
||||
fContextFlags |= flag;
|
||||
}
|
||||
|
||||
inline void mcsv1Context::clearContextFlag(uint64_t flag)
|
||||
{
|
||||
fContextFlags &= ~flag;
|
||||
}
|
||||
|
||||
inline uint32_t mcsv1Context::getUserDataSize() const
|
||||
{
|
||||
return fUserDataSize;
|
||||
}
|
||||
|
||||
inline std::vector<uint32_t>& mcsv1Context::getDataFlags()
|
||||
{
|
||||
return *dataFlags;
|
||||
}
|
||||
|
||||
inline void mcsv1Context::setDataFlags(std::vector<uint32_t>* flags)
|
||||
{
|
||||
dataFlags = flags;
|
||||
}
|
||||
|
||||
inline mcsv1_UDAF::ReturnCode mcsv1_UDAF::dropValue(mcsv1Context* context,
|
||||
std::vector<ColumnDatum>& valsDropped)
|
||||
{
|
||||
return NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
inline mcsv1_UDAF::ReturnCode mcsv1_UDAF::createUserData(UserData*& userData, int32_t& length)
|
||||
{
|
||||
userData = new UserData(length);
|
||||
userData->size = length;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
}; // namespace mcssdk
|
||||
|
||||
#undef EXPORT
|
||||
|
||||
#endif // HEADER_mcsv1_udaf.h
|
||||
|
314
utils/udfsdk/median.cpp
Executable file
314
utils/udfsdk/median.cpp
Executable file
@ -0,0 +1,314 @@
|
||||
/* Copyright (C) 2017 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 <sstream>
|
||||
#include <cstring>
|
||||
#include <typeinfo>
|
||||
#include "median.h"
|
||||
#include "bytestream.h"
|
||||
#include "objectreader.h"
|
||||
|
||||
using namespace mcsv1sdk;
|
||||
|
||||
mcsv1_UDAF::ReturnCode median::init(mcsv1Context* context,
|
||||
COL_TYPES& colTypes)
|
||||
{
|
||||
if (colTypes.size() < 1)
|
||||
{
|
||||
// The error message will be prepended with
|
||||
// "The storage engine for the table doesn't support "
|
||||
context->setErrorMessage("median() with 0 arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
if (colTypes.size() > 1)
|
||||
{
|
||||
context->setErrorMessage("median() with more than 1 argument");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
|
||||
if (!(isNumeric(colTypes[0].second)))
|
||||
{
|
||||
// The error message will be prepended with
|
||||
// "The storage engine for the table doesn't support "
|
||||
context->setErrorMessage("median() with non-numeric argument");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
context->setColWidth(8);
|
||||
context->setScale(context->getScale()*2);
|
||||
context->setPrecision(19);
|
||||
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
mcsv1_UDAF::ReturnCode median::finish(mcsv1Context* context)
|
||||
{
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
mcsv1_UDAF::ReturnCode median::reset(mcsv1Context* context)
|
||||
{
|
||||
MedianData* data = static_cast<MedianData*>(context->getUserData());
|
||||
data->mData.clear();
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
mcsv1_UDAF::ReturnCode median::nextValue(mcsv1Context* context,
|
||||
std::vector<ColumnDatum>& valsIn)
|
||||
{
|
||||
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>();
|
||||
}
|
||||
|
||||
// For decimal types, we need to move the decimal point.
|
||||
uint32_t scale = valsIn[0].scale;
|
||||
if (val != 0 && scale > 0)
|
||||
{
|
||||
val /= pow(10.0, (double)scale);
|
||||
}
|
||||
data[val]++;
|
||||
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
mcsv1_UDAF::ReturnCode median::subEvaluate(mcsv1Context* context, const UserData* userDataIn)
|
||||
{
|
||||
if (!userDataIn)
|
||||
{
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
MEDIAN_DATA& outData = static_cast<MedianData*>(context->getUserData())->mData;
|
||||
const MEDIAN_DATA& inData = static_cast<const MedianData*>(userDataIn)->mData;
|
||||
MEDIAN_DATA::const_iterator iter = inData.begin();
|
||||
for (; iter != inData.end(); ++iter)
|
||||
{
|
||||
outData[iter->first] += iter->second;
|
||||
}
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
mcsv1_UDAF::ReturnCode median::evaluate(mcsv1Context* context, static_any::any& valOut)
|
||||
{
|
||||
uint64_t cnt1=0, cnt2=0;
|
||||
MEDIAN_DATA& data = static_cast<MedianData*>(context->getUserData())->mData;
|
||||
MEDIAN_DATA::iterator iter(data.begin());
|
||||
MEDIAN_DATA::iterator revfrom(data.end());
|
||||
MEDIAN_DATA::reverse_iterator riter(revfrom);
|
||||
cnt1 += iter->second;
|
||||
cnt2 += riter->second;
|
||||
while (iter->first < riter->first)
|
||||
{
|
||||
while (cnt1 < cnt2 && iter->first < riter->first)
|
||||
{
|
||||
++iter;
|
||||
cnt1 += iter->second;
|
||||
}
|
||||
while (cnt2 < cnt1 &&iter->first < riter->first)
|
||||
{
|
||||
++riter;
|
||||
cnt2 += riter->second;
|
||||
}
|
||||
while (cnt1 == cnt2 && iter->first < riter->first)
|
||||
{
|
||||
++iter;
|
||||
cnt1 += iter->second;
|
||||
if (iter->first > riter->first)
|
||||
{
|
||||
break;
|
||||
}
|
||||
++riter;
|
||||
cnt2 += riter->second;
|
||||
}
|
||||
}
|
||||
valOut = (iter->first + riter->first) / 2;
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
mcsv1_UDAF::ReturnCode median::dropValue(mcsv1Context* context,
|
||||
std::vector<ColumnDatum>& valsDropped)
|
||||
{
|
||||
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>();
|
||||
}
|
||||
|
||||
// For decimal types, we need to move the decimal point.
|
||||
uint32_t scale = valsDropped[0].scale;
|
||||
if (val != 0 && scale > 0)
|
||||
{
|
||||
val /= pow(10.0, (double)scale);
|
||||
}
|
||||
|
||||
data[val]--;
|
||||
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
mcsv1_UDAF::ReturnCode median::createUserData(UserData*& userData, int32_t& length)
|
||||
{
|
||||
userData = new MedianData;
|
||||
length = sizeof(MedianData);
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
void MedianData::serialize(messageqcpp::ByteStream& bs) const
|
||||
{
|
||||
MEDIAN_DATA::const_iterator iter = mData.begin();
|
||||
DATATYPE num;
|
||||
uint32_t cnt;
|
||||
bs << (int32_t)mData.size();
|
||||
for (; iter != mData.end(); ++iter)
|
||||
{
|
||||
num = iter->first;
|
||||
bs << num;
|
||||
cnt = iter->second;
|
||||
bs << cnt;
|
||||
}
|
||||
}
|
||||
|
||||
void MedianData::unserialize(messageqcpp::ByteStream& bs)
|
||||
{
|
||||
mData.clear();
|
||||
int32_t sz;
|
||||
DATATYPE num;
|
||||
uint32_t cnt;
|
||||
bs >> sz;
|
||||
for (int i = 0; i < sz; ++i)
|
||||
{
|
||||
bs >> num;
|
||||
bs >> cnt;
|
||||
mData[num] = cnt;
|
||||
}
|
||||
}
|
||||
|
294
utils/udfsdk/median.h
Executable file
294
utils/udfsdk/median.h
Executable file
@ -0,0 +1,294 @@
|
||||
/* Copyright (C) 2017 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. */
|
||||
|
||||
/***********************************************************************
|
||||
* $Id$
|
||||
*
|
||||
* mcsv1_UDAF.h
|
||||
***********************************************************************/
|
||||
|
||||
/**
|
||||
* Columnstore interface for writing a User Defined Aggregate
|
||||
* Functions (UDAF) and User Defined Analytic Functions (UDAnF)
|
||||
* or a function that can act as either - UDA(n)F
|
||||
*
|
||||
* The basic steps are:
|
||||
*
|
||||
* 1. Create a the UDA(n)F function interface in some .h file.
|
||||
* 2. Create the UDF function implementation in some .cpp file
|
||||
* 3. Create the connector stub (MariaDB UDAF definition) for
|
||||
* this UDF function.
|
||||
* 4. build the dynamic library using all of the source.
|
||||
* 5 Put the library in $COLUMNSTORE_INSTALL/lib of
|
||||
* all modules
|
||||
* 6. restart the Columnstore system.
|
||||
* 7. notify mysqld about the new function:
|
||||
*
|
||||
* CREATE AGGREGATE FUNCTION median returns REAL soname
|
||||
* 'libudf_mysql.so';
|
||||
*
|
||||
* The UDAF functions may run distributed in the Columnstore
|
||||
* engine. UDAnF do not run distributed.
|
||||
*
|
||||
* UDAF is User Defined Aggregate Function.
|
||||
* UDAnF is User Defined Analytic Function.
|
||||
* UDA(n)F is an acronym for a function that could be either. It
|
||||
* is also used to describe the interface that is used for
|
||||
* either.
|
||||
*/
|
||||
#ifndef HEADER_median
|
||||
#define HEADER_median
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <boost/any.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#include <unordered_map>
|
||||
#else
|
||||
#include <tr1/unordered_map>
|
||||
#endif
|
||||
|
||||
#include "mcsv1_udaf.h"
|
||||
#include "calpontsystemcatalog.h"
|
||||
#include "windowfunctioncolumn.h"
|
||||
using namespace execplan;
|
||||
|
||||
#if defined(_MSC_VER) && defined(xxxRGNODE_DLLEXPORT)
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define EXPORT
|
||||
#endif
|
||||
|
||||
namespace mcsv1sdk
|
||||
{
|
||||
|
||||
#define DATATYPE double
|
||||
typedef std::map<DATATYPE, uint32_t> MEDIAN_DATA;
|
||||
|
||||
// Override UserData for data storage
|
||||
struct MedianData : public UserData
|
||||
{
|
||||
MedianData() {};
|
||||
|
||||
virtual ~MedianData(){}
|
||||
|
||||
virtual void serialize(messageqcpp::ByteStream& bs) const;
|
||||
virtual void unserialize(messageqcpp::ByteStream& bs);
|
||||
|
||||
MEDIAN_DATA mData;
|
||||
private:
|
||||
// For now, copy construction is unwanted
|
||||
MedianData(UserData&);
|
||||
};
|
||||
|
||||
// Override mcsv1_UDAF to build your User Defined Aggregate (UDAF) and/or
|
||||
// User Defined Analytic Function (UDAnF).
|
||||
// These will be singleton classes, so don't put any instance
|
||||
// specific data in here. All instance data is stored in mcsv1Context
|
||||
// passed to each user function and retrieved by the getUserData() method.
|
||||
//
|
||||
// Each API function returns a ReturnCode. If ERROR is returned at any time,
|
||||
// the query is aborted, getInterrupted() will begin to return true and the
|
||||
// message set in config->setErrorMessage() is returned to MariaDB.
|
||||
|
||||
// Return the median value of the dataset
|
||||
|
||||
class median : public mcsv1_UDAF
|
||||
{
|
||||
public:
|
||||
// Defaults OK
|
||||
median() : mcsv1_UDAF(){};
|
||||
virtual ~median(){};
|
||||
|
||||
/**
|
||||
* init()
|
||||
*
|
||||
* Mandatory. Implement this to initialize flags and instance
|
||||
* data. Called once per SQL statement. You can do any sanity
|
||||
* checks here.
|
||||
*
|
||||
* colTypes (in) - A vector of ColDataType defining the
|
||||
* parameters of the UDA(n)F call. These can be used to decide
|
||||
* to override the default return type. If desired, the new
|
||||
* return type can be set by context->setReturnType() and
|
||||
* decimal scale and precision can be set by context->setScale
|
||||
* and context->setPrecision respectively.
|
||||
*
|
||||
* Return mcsv1_UDAF::ERROR on any error, such as non-compatible
|
||||
* colTypes or wrong number of arguments. Else return
|
||||
* mcsv1_UDAF::SUCCESS.
|
||||
*/
|
||||
virtual ReturnCode init(mcsv1Context* context,
|
||||
COL_TYPES& colTypes);
|
||||
|
||||
/**
|
||||
* finish()
|
||||
*
|
||||
* Mandatory. Completes the UDA(n)F. Called once per SQL
|
||||
* statement. Do not free any memory allocated by
|
||||
* context->setUserDataSize(). The SDK Framework owns that memory
|
||||
* and will handle that. Often, there is nothing to do here.
|
||||
*/
|
||||
virtual ReturnCode finish(mcsv1Context* context);
|
||||
|
||||
/**
|
||||
* reset()
|
||||
*
|
||||
* Mandatory. Reset the UDA(n)F for a new group, partition or,
|
||||
* in some cases, new Window Frame. Do not free any memory
|
||||
* allocated by context->setUserDataSize(). The SDK Framework owns
|
||||
* that memory and will handle that. Use this opportunity to
|
||||
* reset any variables in context->getUserData() needed for the
|
||||
* next aggregation. May be called multiple times if running in
|
||||
* a ditributed fashion.
|
||||
*
|
||||
* Use this opportunity to initialize the userData.
|
||||
*/
|
||||
virtual ReturnCode reset(mcsv1Context* context);
|
||||
|
||||
/**
|
||||
* nextValue()
|
||||
*
|
||||
* Mandatory. Handle a single row.
|
||||
*
|
||||
* colsIn - A vector of data structure describing the input
|
||||
* data.
|
||||
*
|
||||
* This function is called once for every row in the filtered
|
||||
* result set (before aggregation). It is very important that
|
||||
* this function is efficient.
|
||||
*
|
||||
* If the UDAF is running in a distributed fashion, nextValue
|
||||
* cannot depend on order, as it will only be called for each
|
||||
* row found on the specific PM.
|
||||
*
|
||||
* valsIn (in) - a vector of the parameters from the row.
|
||||
*/
|
||||
virtual ReturnCode nextValue(mcsv1Context* context,
|
||||
std::vector<ColumnDatum>& valsIn);
|
||||
|
||||
/**
|
||||
* subEvaluate()
|
||||
*
|
||||
* Mandatory -- Called if the UDAF is running in a distributed
|
||||
* fashion. Columnstore tries to run all aggregate functions
|
||||
* distributed, depending on context.
|
||||
*
|
||||
* Perform an aggregation on rows partially aggregated by
|
||||
* nextValue. Columnstore calls nextValue for each row on a
|
||||
* given PM for a group (GROUP BY). subEvaluate is called on the
|
||||
* UM to consolodate those values into a single instance of
|
||||
* userData. Keep your aggregated totals in context's userData.
|
||||
* The first time this is called for a group, reset() would have
|
||||
* been called with this version of userData.
|
||||
*
|
||||
* Called for every partial data set in each group in GROUP BY.
|
||||
*
|
||||
* When subEvaluate has been called for all subAggregated data
|
||||
* sets, Evaluate will be called with the same context as here.
|
||||
*
|
||||
* valIn (In) - This is a pointer to a memory block of the size
|
||||
* set in setUserDataSize. It will contain the value of userData
|
||||
* as seen in the last call to NextValue for a given PM.
|
||||
*
|
||||
*/
|
||||
virtual ReturnCode subEvaluate(mcsv1Context* context, const UserData* valIn);
|
||||
|
||||
/**
|
||||
* evaluate()
|
||||
*
|
||||
* Mandatory. Get the aggregated value.
|
||||
*
|
||||
* Called for every new group if UDAF GROUP BY, UDAnF partition
|
||||
* or, in some cases, new Window Frame.
|
||||
*
|
||||
* Set the aggregated value into valOut. The datatype is assumed
|
||||
* to be the same as that set in the init() function;
|
||||
*
|
||||
* If the UDAF is running in a distributed fashion, evaluate is
|
||||
* called after a series of subEvaluate calls.
|
||||
*
|
||||
* valOut (out) - Set the aggregated value here. The datatype is
|
||||
* assumed to be the same as that set in the init() function;
|
||||
*
|
||||
* To return a NULL value, don't assign to valOut.
|
||||
*/
|
||||
virtual ReturnCode evaluate(mcsv1Context* context, static_any::any& valOut);
|
||||
|
||||
/**
|
||||
* dropValue()
|
||||
*
|
||||
* Optional -- If defined, the server will call this instead of
|
||||
* reset for UDAnF.
|
||||
*
|
||||
* Don't implement if a UDAnF has one or more of the following:
|
||||
* The UDAnF can't be used with a Window Frame
|
||||
* The UDAnF is not reversable in some way
|
||||
* The UDAnF is not interested in optimal performance
|
||||
*
|
||||
* If not implemented, reset() followed by a series of
|
||||
* nextValue() will be called for each movement of the Window
|
||||
* Frame.
|
||||
*
|
||||
* If implemented, then each movement of the Window Frame will
|
||||
* result in dropValue() being called for each row falling out
|
||||
* of the Frame and nextValue() being called for each new row
|
||||
* coming into the Frame.
|
||||
*
|
||||
* valsDropped (in) - a vector of the parameters from the row
|
||||
* leaving the Frame
|
||||
*
|
||||
* dropValue() will not be called for unbounded/current row type
|
||||
* frames, as those are already optimized.
|
||||
*/
|
||||
virtual ReturnCode dropValue(mcsv1Context* context,
|
||||
std::vector<ColumnDatum>& valsDropped);
|
||||
|
||||
/**
|
||||
* createUserData()
|
||||
*
|
||||
* Optional -- If defined, the server will call this instead of
|
||||
* createUserData on context.
|
||||
*
|
||||
* Create your variable length data structure via
|
||||
* data = new <datatype>
|
||||
*
|
||||
* The data structure may contain references to containers or
|
||||
* pointers to other objects. Remember that for distributed
|
||||
* processing, this may be called multiple times for variaous
|
||||
* computing blocks. At the least, it will be called once per PM
|
||||
* that processes the data, and once more for the UM. For UDAnF,
|
||||
* it may only be called once.
|
||||
*
|
||||
* Set length to the length of the data structure you create.
|
||||
*
|
||||
* For each call to createUserData(), there will be a
|
||||
* corresponding deleteUserData() where you must clean up. Any
|
||||
* memory leaks are your fault.
|
||||
*
|
||||
*/
|
||||
virtual ReturnCode createUserData(UserData*& data, int32_t& length);
|
||||
protected:
|
||||
};
|
||||
|
||||
}; // namespace
|
||||
|
||||
#undef EXPORT
|
||||
|
||||
#endif // HEADER_median.h
|
||||
|
250
utils/udfsdk/ssq.cpp
Executable file
250
utils/udfsdk/ssq.cpp
Executable file
@ -0,0 +1,250 @@
|
||||
/* Copyright (C) 2017 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 <sstream>
|
||||
#include <cstring>
|
||||
#include <typeinfo>
|
||||
#include "ssq.h"
|
||||
#include "bytestream.h"
|
||||
#include "objectreader.h"
|
||||
|
||||
using namespace mcsv1sdk;
|
||||
#define DATATYPE double
|
||||
|
||||
struct ssq_data
|
||||
{
|
||||
uint64_t scale;
|
||||
DATATYPE sumsq;
|
||||
ssq_data() : scale(0){}
|
||||
};
|
||||
|
||||
#define OUT_TYPE int64_t
|
||||
mcsv1_UDAF::ReturnCode ssq::init(mcsv1Context* context,
|
||||
COL_TYPES& colTypes)
|
||||
{
|
||||
if (colTypes.size() < 1)
|
||||
{
|
||||
// The error message will be prepended with
|
||||
// "The storage engine for the table doesn't support "
|
||||
context->setErrorMessage("ssq() with 0 arguments");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
if (colTypes.size() > 1)
|
||||
{
|
||||
context->setErrorMessage("ssq() with more than 1 argument");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
|
||||
if (!(isNumeric(colTypes[0].second)))
|
||||
{
|
||||
// The error message will be prepended with
|
||||
// "The storage engine for the table doesn't support "
|
||||
context->setErrorMessage("ssq() with non-numeric argument");
|
||||
return mcsv1_UDAF::ERROR;
|
||||
}
|
||||
|
||||
context->setUserDataSize(sizeof(ssq_data));
|
||||
context->setResultType(CalpontSystemCatalog::DOUBLE);
|
||||
context->setColWidth(8);
|
||||
context->setScale(context->getScale()*2);
|
||||
context->setPrecision(19);
|
||||
context->setRunFlag(mcsv1sdk::UDAF_IGNORE_NULLS);
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
mcsv1_UDAF::ReturnCode ssq::finish(mcsv1Context* context)
|
||||
{
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
mcsv1_UDAF::ReturnCode ssq::reset(mcsv1Context* context)
|
||||
{
|
||||
struct ssq_data* data = (struct ssq_data*)context->getUserData()->data;
|
||||
if (data)
|
||||
{
|
||||
data->scale = 0;
|
||||
data->sumsq = 0;
|
||||
}
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
mcsv1_UDAF::ReturnCode ssq::nextValue(mcsv1Context* context,
|
||||
std::vector<ColumnDatum>& valsIn)
|
||||
{
|
||||
static_any::any& valIn = valsIn[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>();
|
||||
}
|
||||
|
||||
// For decimal types, we need to move the decimal point.
|
||||
uint32_t scale = valsIn[0].scale;
|
||||
if (val != 0 && scale > 0)
|
||||
{
|
||||
val /= pow(10.0, (double)scale);
|
||||
}
|
||||
data->sumsq += val*val;
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
mcsv1_UDAF::ReturnCode ssq::subEvaluate(mcsv1Context* context, const UserData* userDataIn)
|
||||
{
|
||||
struct ssq_data* outData = (struct ssq_data*)context->getUserData()->data;
|
||||
struct ssq_data* inData = (struct ssq_data*)userDataIn->data;
|
||||
outData->sumsq += inData->sumsq;
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
mcsv1_UDAF::ReturnCode ssq::evaluate(mcsv1Context* context, static_any::any& valOut)
|
||||
{
|
||||
struct ssq_data* data = (struct ssq_data*)context->getUserData()->data;
|
||||
valOut = data->sumsq;
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
||||
mcsv1_UDAF::ReturnCode ssq::dropValue(mcsv1Context* context,
|
||||
std::vector<ColumnDatum>& valsDropped)
|
||||
{
|
||||
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>();
|
||||
}
|
||||
|
||||
// For decimal types, we need to move the decimal point.
|
||||
uint32_t scale = valsDropped[0].scale;
|
||||
if (val != 0 && scale > 0)
|
||||
{
|
||||
val /= pow(10.0, (double)scale);
|
||||
}
|
||||
data->sumsq -= val*val;
|
||||
return mcsv1_UDAF::SUCCESS;
|
||||
}
|
||||
|
248
utils/udfsdk/ssq.h
Executable file
248
utils/udfsdk/ssq.h
Executable file
@ -0,0 +1,248 @@
|
||||
/* Copyright (C) 2017 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. */
|
||||
|
||||
/***********************************************************************
|
||||
* $Id$
|
||||
*
|
||||
* mcsv1_UDAF.h
|
||||
***********************************************************************/
|
||||
|
||||
/**
|
||||
* Columnstore interface for writing a User Defined Aggregate
|
||||
* Functions (UDAF) and User Defined Analytic Functions (UDAnF)
|
||||
* or a function that can act as either - UDA(n)F
|
||||
*
|
||||
* The basic steps are:
|
||||
*
|
||||
* 1. Create a the UDA(n)F function interface in some .h file.
|
||||
* 2. Create the UDF function implementation in some .cpp file
|
||||
* 3. Create the connector stub (MariaDB UDAF definition) for
|
||||
* this UDF function.
|
||||
* 4. build the dynamic library using all of the source.
|
||||
* 5 Put the library in $COLUMNSTORE_INSTALL/lib of
|
||||
* all modules
|
||||
* 6. restart the Columnstore system.
|
||||
* 7. notify mysqld about the new function:
|
||||
*
|
||||
* CREATE AGGREGATE FUNCTION ssq returns REAL soname
|
||||
* 'libudf_mysql.so';
|
||||
*
|
||||
* The UDAF function will run distributed in the Columnstore
|
||||
* engine. UDAnF do not run distributed.
|
||||
*
|
||||
* UDAF is User Defined Aggregate Function.
|
||||
* UDAnF is User Defined Analytic Function.
|
||||
* UDA(n)F is an acronym for a function that could be either. It
|
||||
* is also used to describe the interface that is used for
|
||||
* either.
|
||||
*/
|
||||
#ifndef HEADER_ssq
|
||||
#define HEADER_ssq
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <boost/any.hpp>
|
||||
#ifdef _MSC_VER
|
||||
#include <unordered_map>
|
||||
#else
|
||||
#include <tr1/unordered_map>
|
||||
#endif
|
||||
|
||||
#include "mcsv1_udaf.h"
|
||||
#include "calpontsystemcatalog.h"
|
||||
#include "windowfunctioncolumn.h"
|
||||
using namespace execplan;
|
||||
|
||||
#if defined(_MSC_VER) && defined(xxxRGNODE_DLLEXPORT)
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define EXPORT
|
||||
#endif
|
||||
|
||||
namespace mcsv1sdk
|
||||
{
|
||||
|
||||
// Override mcsv1_UDAF to build your User Defined Aggregate (UDAF) and/or
|
||||
// User Defined Analytic Function (UDAnF).
|
||||
// These will be singleton classes, so don't put any instance
|
||||
// specific data in here. All instance data is stored in mcsv1Context
|
||||
// passed to each user function and retrieved by the getUserData() method.
|
||||
//
|
||||
// Each API function returns a ReturnCode. If ERROR is returned at any time,
|
||||
// the query is aborted, getInterrupted() will begin to return true and the
|
||||
// message set in config->setErrorMessage() is returned to MariaDB.
|
||||
|
||||
// A simple aggregate to return the sum of squares
|
||||
class ssq : public mcsv1_UDAF
|
||||
{
|
||||
public:
|
||||
// Defaults OK
|
||||
ssq() : mcsv1_UDAF(){};
|
||||
virtual ~ssq(){};
|
||||
|
||||
/**
|
||||
* init()
|
||||
*
|
||||
* Mandatory. Implement this to initialize flags and instance
|
||||
* data. Called once per SQL statement. You can do any sanity
|
||||
* checks here.
|
||||
*
|
||||
* colTypes (in) - A vector of ColDataType defining the
|
||||
* parameters of the UDA(n)F call. These can be used to decide
|
||||
* to override the default return type. If desired, the new
|
||||
* return type can be set by context->setReturnType() and
|
||||
* decimal scale and precision can be set by context->setScale
|
||||
* and context->setPrecision respectively.
|
||||
*
|
||||
* Return mcsv1_UDAF::ERROR on any error, such as non-compatible
|
||||
* colTypes or wrong number of arguments. Else return
|
||||
* mcsv1_UDAF::SUCCESS.
|
||||
*/
|
||||
virtual ReturnCode init(mcsv1Context* context,
|
||||
COL_TYPES& colTypes);
|
||||
|
||||
/**
|
||||
* finish()
|
||||
*
|
||||
* Mandatory. Completes the UDA(n)F. Called once per SQL
|
||||
* statement. Do not free any memory allocated by
|
||||
* context->createUserData(). The SDK Framework owns that memory
|
||||
* and will handle that. Often, there is nothing to do here.
|
||||
*/
|
||||
virtual ReturnCode finish(mcsv1Context* context);
|
||||
|
||||
/**
|
||||
* reset()
|
||||
*
|
||||
* Mandatory. Reset the UDA(n)F for a new group, partition or,
|
||||
* in some cases, new Window Frame. Do not free any memory
|
||||
* allocated by context->createUserData(). The SDK Framework
|
||||
* owns that memory and will handle that. Use this opportunity
|
||||
* to reset any variables in context->getUserData() needed for
|
||||
* the next aggregation. May be called multiple times on
|
||||
* different modules.
|
||||
*/
|
||||
virtual ReturnCode reset(mcsv1Context* context);
|
||||
|
||||
/**
|
||||
* nextValue()
|
||||
*
|
||||
* Mandatory. Handle a single row.
|
||||
*
|
||||
* colsIn - A vector of data structure describing the input
|
||||
* data.
|
||||
*
|
||||
* This function is called once for every row in the filtered
|
||||
* result set (before aggregation). It is very important that
|
||||
* this function is efficient.
|
||||
*
|
||||
* If the UDAF is running in a distributed fashion, nextValue
|
||||
* cannot depend on order, as it will only be called for each
|
||||
* row found on the specific PM.
|
||||
*
|
||||
* valsIn (in) - a vector of the parameters from the row.
|
||||
*/
|
||||
virtual ReturnCode nextValue(mcsv1Context* context,
|
||||
std::vector<ColumnDatum>& valsIn);
|
||||
|
||||
/**
|
||||
* subEvaluate()
|
||||
*
|
||||
* Mandatory -- Called if the UDAF is running in a distributed
|
||||
* fashion. Columnstore tries to run all aggregate functions
|
||||
* distributed, depending on context.
|
||||
*
|
||||
* Perform an aggregation on rows partially aggregated by
|
||||
* nextValue. Columnstore calls nextValue for each row on a
|
||||
* given PM for a group (GROUP BY). subEvaluate is called on the
|
||||
* UM to consolodate those values into a single instance of
|
||||
* userData. Keep your aggregated totals in context's userData.
|
||||
* The first time this is called for a group, reset() would have
|
||||
* been called with this version of userData.
|
||||
*
|
||||
* Called for every partial data set in each group in GROUP BY.
|
||||
*
|
||||
* When subEvaluate has been called for all subAggregated data
|
||||
* sets, Evaluate will be called.
|
||||
*
|
||||
* valIn (In) - This is a pointer to a memory block of the size
|
||||
* set in setUserDataSize. It will contain the value of userData
|
||||
* as seen in the last call to NextValue for a given PM.
|
||||
*
|
||||
*/
|
||||
virtual ReturnCode subEvaluate(mcsv1Context* context, const UserData* userDataIn);
|
||||
|
||||
/**
|
||||
* evaluate()
|
||||
*
|
||||
* Mandatory. Get the aggregated value.
|
||||
*
|
||||
* Called for every new group if UDAF GROUP BY, UDAnF partition
|
||||
* or, in some cases, new Window Frame.
|
||||
*
|
||||
* Set the aggregated value into valOut. The datatype is assumed
|
||||
* to be the same as that set in the init() function;
|
||||
*
|
||||
* If the UDAF is running in a distributed fashion, evaluate is
|
||||
* called after a series of subEvaluate calls.
|
||||
*
|
||||
* valOut (out) - Set the aggregated value here. The datatype is
|
||||
* assumed to be the same as that set in the init() function;
|
||||
*
|
||||
* To return a NULL value, don't assign to valOut.
|
||||
*/
|
||||
virtual ReturnCode evaluate(mcsv1Context* context, static_any::any& valOut);
|
||||
|
||||
/**
|
||||
* dropValue()
|
||||
*
|
||||
* Optional -- If defined, the server will call this instead of
|
||||
* reset for UDAnF.
|
||||
*
|
||||
* Don't implement if a UDAnF has one or more of the following:
|
||||
* The UDAnF can't be used with a Window Frame
|
||||
* The UDAnF is not reversable in some way
|
||||
* The UDAnF is not interested in optimal performance
|
||||
*
|
||||
* If not implemented, reset() followed by a series of
|
||||
* nextValue() will be called for each movement of the Window
|
||||
* Frame.
|
||||
*
|
||||
* If implemented, then each movement of the Window Frame will
|
||||
* result in dropValue() being called for each row falling out
|
||||
* of the Frame and nextValue() being called for each new row
|
||||
* coming into the Frame.
|
||||
*
|
||||
* valsDropped (in) - a vector of the parameters from the row
|
||||
* leaving the Frame
|
||||
*
|
||||
* dropValue() will not be called for unbounded/current row type
|
||||
* frames, as those are already optimized.
|
||||
*/
|
||||
virtual ReturnCode dropValue(mcsv1Context* context,
|
||||
std::vector<ColumnDatum>& valsDropped);
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
}; // namespace
|
||||
|
||||
#undef EXPORT
|
||||
|
||||
#endif // HEADER_ssq.h
|
||||
|
228
utils/udfsdk/udfmysql.cpp
Normal file → Executable file
228
utils/udfsdk/udfmysql.cpp
Normal file → Executable file
@ -168,13 +168,239 @@ void mcs_isnull_deinit(UDF_INIT* initid)
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
__declspec(dllexport)f
|
||||
#endif
|
||||
long long mcs_isnull(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* ALLNULL connector stub
|
||||
*/
|
||||
struct allnull_data
|
||||
{
|
||||
ulonglong totalQuantity;
|
||||
ulonglong totalNulls;
|
||||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
my_bool allnull_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
{
|
||||
struct allnull_data* data;
|
||||
// if (args->arg_count != 1)
|
||||
// {
|
||||
// strcpy(message,"allnull() requires one argument");
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
if (!(data = (struct allnull_data*) malloc(sizeof(struct allnull_data))))
|
||||
{
|
||||
strmov(message,"Couldn't allocate memory");
|
||||
return 1;
|
||||
}
|
||||
data->totalQuantity = 0;
|
||||
data->totalNulls = 0;
|
||||
|
||||
initid->ptr = (char*)data;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void allnull_deinit(UDF_INIT* initid)
|
||||
{
|
||||
free(initid->ptr);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
long long allnull(UDF_INIT* initid, UDF_ARGS* args __attribute__((unused)),
|
||||
char* is_null, char* error __attribute__((unused)))
|
||||
{
|
||||
struct allnull_data* data = (struct allnull_data*)initid->ptr;
|
||||
return data->totalQuantity > 0 && data->totalNulls == data->totalQuantity;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void
|
||||
allnull_clear(UDF_INIT* initid, char* is_null __attribute__((unused)),
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
struct allnull_data* data = (struct allnull_data*)initid->ptr;
|
||||
data->totalQuantity = 0;
|
||||
data->totalNulls = 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void
|
||||
allnull_add(UDF_INIT* initid, UDF_ARGS* args,
|
||||
char* is_null,
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
struct allnull_data* data = (struct allnull_data*)initid->ptr;
|
||||
const char *word=args->args[0];
|
||||
data->totalQuantity++;
|
||||
if (!word)
|
||||
{
|
||||
data->totalNulls++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SSQ connector stub
|
||||
*/
|
||||
struct ssq_data
|
||||
{
|
||||
double sumsq;
|
||||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
my_bool ssq_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
{
|
||||
struct ssq_data* data;
|
||||
if (args->arg_count != 1)
|
||||
{
|
||||
strcpy(message,"ssq() requires one argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(data = (struct ssq_data*) malloc(sizeof(struct ssq_data))))
|
||||
{
|
||||
strmov(message,"Couldn't allocate memory");
|
||||
return 1;
|
||||
}
|
||||
data->sumsq = 0;
|
||||
|
||||
initid->ptr = (char*)data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void ssq_deinit(UDF_INIT* initid)
|
||||
{
|
||||
free(initid->ptr);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void
|
||||
ssq_clear(UDF_INIT* initid, char* is_null __attribute__((unused)),
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
data->sumsq = 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void
|
||||
ssq_add(UDF_INIT* initid, UDF_ARGS* args,
|
||||
char* is_null,
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
double val = cvtArgToDouble(args->arg_type[0], args->args[0]);
|
||||
data->sumsq = val*val;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
long long ssq(UDF_INIT* initid, UDF_ARGS* args __attribute__((unused)),
|
||||
char* is_null, char* error __attribute__((unused)))
|
||||
{
|
||||
struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
return data->sumsq;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
|
||||
/**
|
||||
* MEDIAN connector stub
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
my_bool median_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
|
||||
{
|
||||
if (args->arg_count != 1)
|
||||
{
|
||||
strcpy(message,"median() requires one argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
if (!(data = (struct ssq_data*) malloc(sizeof(struct ssq_data))))
|
||||
{
|
||||
strmov(message,"Couldn't allocate memory");
|
||||
return 1;
|
||||
}
|
||||
data->sumsq = 0;
|
||||
|
||||
initid->ptr = (char*)data;
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void median_deinit(UDF_INIT* initid)
|
||||
{
|
||||
// free(initid->ptr);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void
|
||||
median_clear(UDF_INIT* initid, char* is_null __attribute__((unused)),
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
// struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
// data->sumsq = 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void
|
||||
median_add(UDF_INIT* initid, UDF_ARGS* args,
|
||||
char* is_null,
|
||||
char* message __attribute__((unused)))
|
||||
{
|
||||
// struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
// double val = cvtArgToDouble(args->arg_type[0], args->args[0]);
|
||||
// data->sumsq = val*val;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
long long median(UDF_INIT* initid, UDF_ARGS* args __attribute__((unused)),
|
||||
char* is_null, char* error __attribute__((unused)))
|
||||
{
|
||||
// struct ssq_data* data = (struct ssq_data*)initid->ptr;
|
||||
// return data->sumsq;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
// vim:ts=4 sw=4:
|
||||
|
||||
|
9
utils/udfsdk/udfsdk.vpj
Normal file → Executable file
9
utils/udfsdk/udfsdk.vpj
Normal file → Executable file
@ -202,12 +202,20 @@
|
||||
<Folder
|
||||
Name="Source Files"
|
||||
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d">
|
||||
<F N="allnull.cpp"/>
|
||||
<F N="mcsv1_udaf.cpp"/>
|
||||
<F N="median.cpp"/>
|
||||
<F N="ssq.cpp"/>
|
||||
<F N="udfinfinidb.cpp"/>
|
||||
<F N="udfmysql.cpp"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Header Files"
|
||||
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if">
|
||||
<F N="allnull.h"/>
|
||||
<F N="mcsv1_udaf.h"/>
|
||||
<F N="median.h"/>
|
||||
<F N="ssq.h"/>
|
||||
<F N="udfsdk.h"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
@ -222,6 +230,7 @@
|
||||
<F
|
||||
N="Makefile"
|
||||
Type="Makefile"/>
|
||||
<F N="mcsv1_UDAF_base"/>
|
||||
</Folder>
|
||||
</Files>
|
||||
</Project>
|
||||
|
2
utils/utils.vpj
Normal file → Executable file
2
utils/utils.vpj
Normal file → Executable file
@ -233,6 +233,7 @@
|
||||
<F N="windowfunction/wf_row_number.cpp"/>
|
||||
<F N="windowfunction/wf_stats.cpp"/>
|
||||
<F N="windowfunction/wf_sum_avg.cpp"/>
|
||||
<F N="windowfunction/wf_udaf.cpp"/>
|
||||
<F N="windowfunction/windowframe.cpp"/>
|
||||
<F N="windowfunction/windowfunction.cpp"/>
|
||||
<F N="windowfunction/windowfunctiontype.cpp"/>
|
||||
@ -277,6 +278,7 @@
|
||||
<F N="windowfunction/wf_row_number.h"/>
|
||||
<F N="windowfunction/wf_stats.h"/>
|
||||
<F N="windowfunction/wf_sum_avg.h"/>
|
||||
<F N="windowfunction/wf_udaf.h"/>
|
||||
<F N="windowfunction/windowframe.h"/>
|
||||
<F N="windowfunction/windowfunction.h"/>
|
||||
<F N="windowfunction/windowfunctiontype.h"/>
|
||||
|
3
utils/windowfunction/CMakeLists.txt
Normal file → Executable file
3
utils/windowfunction/CMakeLists.txt
Normal file → Executable file
@ -21,7 +21,8 @@ set(windowfunction_LIB_SRCS
|
||||
wf_ranking.cpp
|
||||
wf_row_number.cpp
|
||||
wf_stats.cpp
|
||||
wf_sum_avg.cpp)
|
||||
wf_sum_avg.cpp
|
||||
wf_udaf.cpp)
|
||||
|
||||
add_library(windowfunction SHARED ${windowfunction_LIB_SRCS})
|
||||
|
||||
|
508
utils/windowfunction/wf_udaf.cpp
Executable file
508
utils/windowfunction/wf_udaf.cpp
Executable file
@ -0,0 +1,508 @@
|
||||
/************************************************************************************
|
||||
Copyright (C) 2017 MariaDB Corporation AB
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not see <http://www.gnu.org/licenses>
|
||||
or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
|
||||
*************************************************************************************/
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
using namespace boost;
|
||||
|
||||
#include "loggingid.h"
|
||||
#include "errorcodes.h"
|
||||
#include "idberrorinfo.h"
|
||||
using namespace logging;
|
||||
|
||||
#include "rowgroup.h"
|
||||
using namespace rowgroup;
|
||||
|
||||
#include "idborderby.h"
|
||||
using namespace ordering;
|
||||
|
||||
#include "joblisttypes.h"
|
||||
#include "calpontsystemcatalog.h"
|
||||
#include "constantcolumn.h"
|
||||
using namespace execplan;
|
||||
|
||||
#include "windowfunctionstep.h"
|
||||
using namespace joblist;
|
||||
|
||||
#include "wf_udaf.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
template<typename T>
|
||||
boost::shared_ptr<WindowFunctionType> WF_udaf<T>::makeFunction(int id, const string& name, int ct, mcsv1sdk::mcsv1Context& context)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func;
|
||||
switch (ct)
|
||||
{
|
||||
case CalpontSystemCatalog::TINYINT:
|
||||
case CalpontSystemCatalog::SMALLINT:
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
func.reset(new WF_udaf<int64_t>(id, name, context));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::UTINYINT:
|
||||
case CalpontSystemCatalog::USMALLINT:
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
func.reset(new WF_udaf<uint64_t>(id, name, context));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
func.reset(new WF_udaf<double>(id, name, context));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::FLOAT:
|
||||
case CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
func.reset(new WF_udaf<float>(id, name, context));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::CHAR:
|
||||
case CalpontSystemCatalog::VARCHAR:
|
||||
case CalpontSystemCatalog::VARBINARY:
|
||||
case CalpontSystemCatalog::TEXT:
|
||||
case CalpontSystemCatalog::BLOB:
|
||||
{
|
||||
func.reset(new WF_udaf<string>(id, name, context));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
string errStr = name + "(" + colType2String[ct] + ")";
|
||||
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_INVALID_PARM_TYPE, errStr);
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_INVALID_PARM_TYPE);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the UDAnF function object
|
||||
WF_udaf* wfUDAF = (WF_udaf*)func.get();
|
||||
mcsv1sdk::mcsv1Context& udafContext = wfUDAF->getContext();
|
||||
udafContext.setInterrupted(wfUDAF->getInterruptedPtr());
|
||||
wfUDAF->resetData();
|
||||
return func;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
WF_udaf<T>::WF_udaf(WF_udaf& rhs) : fUDAFContext(rhs.getContext()),
|
||||
bInterrupted(rhs.getInterrupted()),
|
||||
fDistinct(rhs.getDistinct())
|
||||
{
|
||||
getContext().setInterrupted(getInterruptedPtr());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
WindowFunctionType* WF_udaf<T>::clone() const
|
||||
{
|
||||
return new WF_udaf(*const_cast<WF_udaf*>(this));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void WF_udaf<T>::resetData()
|
||||
{
|
||||
getContext().getFunction()->reset(&getContext());
|
||||
fSet.clear();
|
||||
WindowFunctionType::resetData();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void WF_udaf<T>::parseParms(const std::vector<execplan::SRCP>& parms)
|
||||
{
|
||||
bRespectNulls = true;
|
||||
// parms[1]: respect null | ignore null
|
||||
ConstantColumn* cc = dynamic_cast<ConstantColumn*>(parms[1].get());
|
||||
idbassert(cc != NULL);
|
||||
bool isNull = false; // dummy, harded coded
|
||||
bRespectNulls = (cc->getIntVal(fRow, isNull) > 0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool WF_udaf<T>::dropValues(int64_t b, int64_t e)
|
||||
{
|
||||
if (!bHasDropValue)
|
||||
{
|
||||
// Save work if we discovered dropValue is not implemented in the UDAnF
|
||||
return false;
|
||||
}
|
||||
|
||||
mcsv1sdk::mcsv1_UDAF::ReturnCode rc;
|
||||
uint64_t colOut = fFieldIndex[0];
|
||||
uint64_t colIn = fFieldIndex[1];
|
||||
|
||||
mcsv1sdk::ColumnDatum datum;
|
||||
datum.dataType = fRow.getColType(colIn);
|
||||
datum.scale = fRow.getScale(colIn);
|
||||
datum.precision = fRow.getPrecision(colOut);
|
||||
|
||||
for (int64_t i = b; i < e; i++)
|
||||
{
|
||||
if (i % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
fRow.setData(getPointer(fRowData->at(i)));
|
||||
// Turn on NULL flags
|
||||
std::vector<uint32_t> flags;
|
||||
uint32_t flag = 0;
|
||||
if (fRow.isNullValue(colIn) == true)
|
||||
{
|
||||
if (!bRespectNulls)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
flag |= mcsv1sdk::PARAM_IS_NULL;
|
||||
}
|
||||
flags.push_back(flag);
|
||||
getContext().setDataFlags(&flags);
|
||||
|
||||
T valIn;
|
||||
getValue(colIn, valIn, &datum.dataType);
|
||||
|
||||
// Check for distinct, if turned on.
|
||||
// TODO: when we impliment distinct, we need to revist this.
|
||||
if ((fDistinct) || (fSet.find(valIn) != fSet.end()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
datum.columnData = valIn;
|
||||
|
||||
std::vector<mcsv1sdk::ColumnDatum> valsIn;
|
||||
valsIn.push_back(datum);
|
||||
|
||||
rc = getContext().getFunction()->dropValue(&getContext(), valsIn);
|
||||
if (rc == mcsv1sdk::mcsv1_UDAF::NOT_IMPLEMENTED)
|
||||
{
|
||||
bHasDropValue = false;
|
||||
return false;
|
||||
}
|
||||
if (rc == mcsv1sdk::mcsv1_UDAF::ERROR)
|
||||
{
|
||||
bInterrupted = true;
|
||||
string errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_UDANF_ERROR, getContext().getErrorMessage());
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_UDANF_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Sets the value from valOut into column colOut, performing any conversions.
|
||||
template<typename T>
|
||||
void WF_udaf<T>::SetUDAFValue(static_any::any& valOut, int64_t colOut,
|
||||
int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
static const static_any::any& charTypeId = (char)1;
|
||||
static const static_any::any& scharTypeId = (signed char)1;
|
||||
static const static_any::any& shortTypeId = (short)1;
|
||||
static const static_any::any& intTypeId = (int)1;
|
||||
static const static_any::any& longTypeId = (long)1;
|
||||
static const static_any::any& llTypeId = (long long)1;
|
||||
static const static_any::any& ucharTypeId = (unsigned char)1;
|
||||
static const static_any::any& ushortTypeId = (unsigned short)1;
|
||||
static const static_any::any& uintTypeId = (unsigned int)1;
|
||||
static const static_any::any& ulongTypeId = (unsigned long)1;
|
||||
static const static_any::any& ullTypeId = (unsigned long long)1;
|
||||
static const static_any::any& floatTypeId = (float)1;
|
||||
static const static_any::any& doubleTypeId = (double)1;
|
||||
static const std::string typeStr("");
|
||||
static const static_any::any& strTypeId = typeStr;
|
||||
|
||||
CDT colDataType = fRow.getColType(colOut);
|
||||
if (valOut.empty())
|
||||
{
|
||||
// If valOut is empty, we return NULL
|
||||
T* pv = NULL;
|
||||
setValue(colDataType, b, e, c, pv);
|
||||
fPrev = c;
|
||||
return;
|
||||
}
|
||||
|
||||
// This may seem a bit convoluted. Users shouldn't return a type
|
||||
// that they didn't set in mcsv1_UDAF::init(), but this
|
||||
// handles whatever return type is given and casts
|
||||
// it to whatever they said to return.
|
||||
int64_t intOut = 0;
|
||||
uint64_t uintOut = 0;
|
||||
float floatOut = 0.0;
|
||||
double doubleOut = 0.0;
|
||||
ostringstream oss;
|
||||
std::string strOut;
|
||||
|
||||
if (valOut.compatible(charTypeId))
|
||||
{
|
||||
uintOut = intOut = valOut.cast<char>();
|
||||
floatOut = intOut;
|
||||
oss << intOut;
|
||||
}
|
||||
else if (valOut.compatible(scharTypeId))
|
||||
{
|
||||
uintOut = intOut = valOut.cast<signed char>();
|
||||
floatOut = intOut;
|
||||
oss << intOut;
|
||||
}
|
||||
else if (valOut.compatible(shortTypeId))
|
||||
{
|
||||
uintOut = intOut = valOut.cast<short>();
|
||||
floatOut = intOut;
|
||||
oss << intOut;
|
||||
}
|
||||
else if (valOut.compatible(intTypeId))
|
||||
{
|
||||
uintOut = intOut = valOut.cast<int>();
|
||||
floatOut = intOut;
|
||||
oss << intOut;
|
||||
}
|
||||
else if (valOut.compatible(longTypeId))
|
||||
{
|
||||
uintOut = intOut = valOut.cast<long>();
|
||||
floatOut = intOut;
|
||||
oss << intOut;
|
||||
}
|
||||
else if (valOut.compatible(llTypeId))
|
||||
{
|
||||
uintOut = intOut = valOut.cast<long long>();
|
||||
floatOut = intOut;
|
||||
oss << intOut;
|
||||
}
|
||||
else if (valOut.compatible(ucharTypeId))
|
||||
{
|
||||
intOut = uintOut = valOut.cast<unsigned char>();
|
||||
floatOut = uintOut;
|
||||
oss << uintOut;
|
||||
}
|
||||
else if (valOut.compatible(ushortTypeId))
|
||||
{
|
||||
intOut = uintOut = valOut.cast<unsigned short>();
|
||||
floatOut = uintOut;
|
||||
oss << uintOut;
|
||||
}
|
||||
else if (valOut.compatible(uintTypeId))
|
||||
{
|
||||
intOut = uintOut = valOut.cast<unsigned int>();
|
||||
floatOut = uintOut;
|
||||
oss << uintOut;
|
||||
}
|
||||
else if (valOut.compatible(ulongTypeId))
|
||||
{
|
||||
intOut = uintOut = valOut.cast<unsigned long>();
|
||||
floatOut = uintOut;
|
||||
oss << uintOut;
|
||||
}
|
||||
else if (valOut.compatible(ullTypeId))
|
||||
{
|
||||
intOut = uintOut = valOut.cast<unsigned long long>();
|
||||
floatOut = uintOut;
|
||||
oss << uintOut;
|
||||
}
|
||||
else if (valOut.compatible(floatTypeId))
|
||||
{
|
||||
floatOut = valOut.cast<float>();
|
||||
doubleOut = floatOut;
|
||||
intOut = uintOut = floatOut;
|
||||
oss << floatOut;
|
||||
}
|
||||
else if (valOut.compatible(doubleTypeId))
|
||||
{
|
||||
doubleOut = valOut.cast<double>();
|
||||
floatOut = (float)doubleOut;
|
||||
uintOut = (uint64_t)doubleOut;
|
||||
intOut = (int64_t)doubleOut;
|
||||
oss << doubleOut;
|
||||
}
|
||||
|
||||
if (valOut.compatible(strTypeId))
|
||||
{
|
||||
std::string strOut = valOut.cast<std::string>();
|
||||
// Convert the string to numeric type, just in case.
|
||||
intOut = atol(strOut.c_str());
|
||||
uintOut = strtoul(strOut.c_str(), NULL, 10);
|
||||
doubleOut = strtod(strOut.c_str(), NULL);
|
||||
floatOut = (float)doubleOut;
|
||||
}
|
||||
else
|
||||
{
|
||||
strOut = oss.str();
|
||||
}
|
||||
|
||||
switch (colDataType)
|
||||
{
|
||||
case execplan::CalpontSystemCatalog::BIT:
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
setValue(colDataType, b, e, c, &intOut);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::UTINYINT:
|
||||
case execplan::CalpontSystemCatalog::USMALLINT:
|
||||
case execplan::CalpontSystemCatalog::UMEDINT:
|
||||
case execplan::CalpontSystemCatalog::UINT:
|
||||
case execplan::CalpontSystemCatalog::UBIGINT:
|
||||
case execplan::CalpontSystemCatalog::DATE:
|
||||
case execplan::CalpontSystemCatalog::DATETIME:
|
||||
setValue(colDataType, b, e, c, &uintOut);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::FLOAT:
|
||||
case execplan::CalpontSystemCatalog::UFLOAT:
|
||||
setValue(colDataType, b, e, c, &floatOut);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::DOUBLE:
|
||||
case execplan::CalpontSystemCatalog::UDOUBLE:
|
||||
setValue(colDataType, b, e, c, &doubleOut);
|
||||
break;
|
||||
case execplan::CalpontSystemCatalog::CHAR:
|
||||
case execplan::CalpontSystemCatalog::VARCHAR:
|
||||
case execplan::CalpontSystemCatalog::TEXT:
|
||||
case execplan::CalpontSystemCatalog::VARBINARY:
|
||||
case execplan::CalpontSystemCatalog::CLOB:
|
||||
case execplan::CalpontSystemCatalog::BLOB:
|
||||
setValue(colDataType, b, e, c, &strOut);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "WF_udaf: No logic for data type: " << colDataType;
|
||||
cerr << errmsg.str() << endl;
|
||||
throw runtime_error(errmsg.str().c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void WF_udaf<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
mcsv1sdk::mcsv1_UDAF::ReturnCode rc;
|
||||
uint64_t colOut = fFieldIndex[0];
|
||||
static_any::any valOut;
|
||||
|
||||
if ((fFrameUnit == WF__FRAME_ROWS) ||
|
||||
(fPrev == -1) ||
|
||||
(!fPeer->operator()(getPointer(fRowData->at(c)), getPointer(fRowData->at(fPrev)))))
|
||||
{
|
||||
// for unbounded - current row special handling
|
||||
if (fPrev >= b && fPrev < c)
|
||||
b = c;
|
||||
else if (fPrev <= e && fPrev > c)
|
||||
e = c;
|
||||
|
||||
uint64_t colIn = fFieldIndex[1];
|
||||
|
||||
mcsv1sdk::ColumnDatum datum;
|
||||
datum.dataType = fRow.getColType(colIn);
|
||||
datum.scale = fRow.getScale(colIn);
|
||||
datum.precision = fRow.getPrecision(colOut);
|
||||
|
||||
if (b<=c && c<=e)
|
||||
getContext().setContextFlag(mcsv1sdk::CONTEXT_HAS_CURRENT_ROW);
|
||||
else
|
||||
getContext().clearContextFlag(mcsv1sdk::CONTEXT_HAS_CURRENT_ROW);
|
||||
|
||||
|
||||
for (int64_t i = b; i <= e; i++)
|
||||
{
|
||||
if (i % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
fRow.setData(getPointer(fRowData->at(i)));
|
||||
// Turn on NULL flags
|
||||
std::vector<uint32_t> flags;
|
||||
uint32_t flag = 0;
|
||||
if (fRow.isNullValue(colIn) == true)
|
||||
{
|
||||
if (!bRespectNulls)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
flag |= mcsv1sdk::PARAM_IS_NULL;
|
||||
}
|
||||
flags.push_back(flag);
|
||||
getContext().setDataFlags(&flags);
|
||||
|
||||
T valIn;
|
||||
getValue(colIn, valIn, &datum.dataType);
|
||||
|
||||
// Check for distinct, if turned on.
|
||||
if ((fDistinct) || (fSet.find(valIn) != fSet.end()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fDistinct)
|
||||
fSet.insert(valIn);
|
||||
|
||||
datum.columnData = valIn;
|
||||
|
||||
std::vector<mcsv1sdk::ColumnDatum> valsIn;
|
||||
valsIn.push_back(datum);
|
||||
|
||||
rc = getContext().getFunction()->nextValue(&getContext(), valsIn);
|
||||
if (rc == mcsv1sdk::mcsv1_UDAF::ERROR)
|
||||
{
|
||||
bInterrupted = true;
|
||||
string errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_UDANF_ERROR, getContext().getErrorMessage());
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_UDANF_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
rc = getContext().getFunction()->evaluate(&getContext(), fValOut);
|
||||
if (rc == mcsv1sdk::mcsv1_UDAF::ERROR)
|
||||
{
|
||||
bInterrupted = true;
|
||||
string errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_UDANF_ERROR, getContext().getErrorMessage());
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_UDANF_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
SetUDAFValue(fValOut, colOut, b, e, c);
|
||||
|
||||
fPrev = c;
|
||||
}
|
||||
|
||||
template
|
||||
boost::shared_ptr<WindowFunctionType> WF_udaf<int64_t>::makeFunction(int id, const string& name, int ct, mcsv1sdk::mcsv1Context& context);
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
77
utils/windowfunction/wf_udaf.h
Executable file
77
utils/windowfunction/wf_udaf.h
Executable file
@ -0,0 +1,77 @@
|
||||
/************************************************************************************
|
||||
Copyright (C) 2017 MariaDB Corporation AB
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not see <http://www.gnu.org/licenses>
|
||||
or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
|
||||
*************************************************************************************/
|
||||
|
||||
|
||||
#ifndef UTILS_WF_UDAF_H
|
||||
#define UTILS_WF_UDAF_H
|
||||
|
||||
#include <set>
|
||||
#include "windowfunctiontype.h"
|
||||
#include "mcsv1_udaf.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
// A class to control the execution of User Define Analytic Functions (UDAnF)
|
||||
// as defined by a specialization of mcsv1sdk::mcsv1_UDAF
|
||||
// The template parameter is currently only used to support DISTINCT, as
|
||||
// as that is done via a set<T>
|
||||
template<typename T>
|
||||
class WF_udaf : public WindowFunctionType
|
||||
{
|
||||
public:
|
||||
WF_udaf(int id, const std::string& name, mcsv1sdk::mcsv1Context& context) :
|
||||
WindowFunctionType(id, name), fUDAFContext(context), fDistinct(false), bHasDropValue(true) {}
|
||||
WF_udaf(WF_udaf& rhs);
|
||||
// pure virtual in base
|
||||
void operator()(int64_t b, int64_t e, int64_t c);
|
||||
WindowFunctionType* clone() const;
|
||||
void resetData();
|
||||
void parseParms(const std::vector<execplan::SRCP>&);
|
||||
virtual bool dropValues(int64_t, int64_t);
|
||||
|
||||
mcsv1sdk::mcsv1Context& getContext() {return fUDAFContext;}
|
||||
bool getInterrupted() {return bInterrupted;}
|
||||
bool getInterruptedPtr() {return &bInterrupted;}
|
||||
bool getDistinct() {return fDistinct;}
|
||||
|
||||
protected:
|
||||
void SetUDAFValue(static_any::any& valOut, int64_t colOut, int64_t b, int64_t e, int64_t c);
|
||||
|
||||
mcsv1sdk::mcsv1Context fUDAFContext; // The UDAF context
|
||||
bool bInterrupted; // Shared by all the threads
|
||||
bool fDistinct;
|
||||
bool bRespectNulls; // respect null | ignore null
|
||||
bool bHasDropValue; // Set to false when we discover the UDAnF doesn't implement dropValue.
|
||||
std::set<T> fSet; // To hold distinct values
|
||||
static_any::any fValOut; // The return value
|
||||
|
||||
public:
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int id, const string& name,
|
||||
int ct, mcsv1sdk::mcsv1Context& context);
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // UTILS_WF_UDAF_H
|
||||
|
||||
// vim:ts=4 sw=4:
|
||||
|
30
utils/windowfunction/windowfunction.cpp
Normal file → Executable file
30
utils/windowfunction/windowfunction.cpp
Normal file → Executable file
@ -163,11 +163,35 @@ void WindowFunction::operator()()
|
||||
}
|
||||
else
|
||||
{
|
||||
pair<int64_t, int64_t> w;
|
||||
pair<int64_t, int64_t> prevFrame;
|
||||
int64_t b, e;
|
||||
bool firstTime = true;
|
||||
for (int64_t i = begin; i <= end && !fStep->cancelled(); i++)
|
||||
{
|
||||
pair<int64_t, int64_t> w = fFrame->getWindow(begin, end, i);
|
||||
fFunctionType->resetData();
|
||||
fFunctionType->operator()(w.first, w.second, i);
|
||||
w = fFrame->getWindow(begin, end, i);
|
||||
b = w.first;
|
||||
e = w.second;
|
||||
if (firstTime)
|
||||
{
|
||||
prevFrame = w;
|
||||
}
|
||||
// UDAnF functions may have a dropValue function implemented.
|
||||
// If they do, we can optimize by calling dropValue() for those
|
||||
// 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 (fFunctionType->dropValues(prevFrame.first, w.first))
|
||||
{
|
||||
b = firstTime ? w.first : prevFrame.second+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fFunctionType->resetData();
|
||||
}
|
||||
fFunctionType->operator()(b, e, i);
|
||||
prevFrame = w;
|
||||
firstTime = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
63
utils/windowfunction/windowfunctiontype.cpp
Normal file → Executable file
63
utils/windowfunction/windowfunctiontype.cpp
Normal file → Executable file
@ -58,6 +58,7 @@ using namespace joblist;
|
||||
#include "wf_row_number.h"
|
||||
#include "wf_stats.h"
|
||||
#include "wf_sum_avg.h"
|
||||
#include "wf_udaf.h"
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
@ -137,13 +138,16 @@ map<string, int> WindowFunctionType::windowFunctionId = assign::map_list_of
|
||||
(string("REGR_SXX"), WF__REGR_SXX)
|
||||
(string("REGR_SXY"), WF__REGR_SXY)
|
||||
(string("REGR_SYY"), WF__REGR_SYY)
|
||||
(string("UDAF_FUNC"), WF__UDAF)
|
||||
;
|
||||
|
||||
boost::shared_ptr<WindowFunctionType>
|
||||
WindowFunctionType::makeWindowFunction(const string& name, int ct)
|
||||
WindowFunctionType::makeWindowFunction(const string& name, int ct, WindowFunctionColumn* wc)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> af;
|
||||
int functionId = windowFunctionId[algorithm::to_upper_copy(name)];
|
||||
// The template parameters here are dummies to execute the static makeFunction
|
||||
// which sets the real type based on ct.
|
||||
switch (functionId)
|
||||
{
|
||||
case WF__COUNT_ASTERISK:
|
||||
@ -192,6 +196,9 @@ boost::shared_ptr<WindowFunctionType>
|
||||
case WF__PERCENTILE_DISC:
|
||||
af = WF_percentile<int64_t>::makeFunction(functionId, name, ct);
|
||||
break;
|
||||
case WF__UDAF:
|
||||
af = WF_udaf<int64_t>::makeFunction(functionId, name, ct, wc->getUDAFContext());
|
||||
break;
|
||||
case WF__REGR_SLOPE:
|
||||
case WF__REGR_INTERCEPT:
|
||||
case WF__REGR_COUNT:
|
||||
@ -211,7 +218,6 @@ boost::shared_ptr<WindowFunctionType>
|
||||
return af;
|
||||
}
|
||||
|
||||
|
||||
const string WindowFunctionType::toString() const
|
||||
{
|
||||
ostringstream oss;
|
||||
@ -223,77 +229,81 @@ const string WindowFunctionType::toString() const
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
||||
template<typename T> void WindowFunctionType::getValue(uint64_t i, T& t)
|
||||
template<typename T> void WindowFunctionType::getValue(uint64_t i, T& t, CDT* cdt)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::getValue<int64_t>(uint64_t i, int64_t& t)
|
||||
template<> void WindowFunctionType::getValue<int64_t>(uint64_t i, int64_t& t, CDT* cdt)
|
||||
{
|
||||
t = fRow.getIntField(i);
|
||||
if (cdt)
|
||||
{
|
||||
*cdt = execplan::CalpontSystemCatalog::BIGINT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::getValue<uint64_t>(uint64_t i, uint64_t& t)
|
||||
template<> void WindowFunctionType::getValue<uint64_t>(uint64_t i, uint64_t& t, CDT* cdt)
|
||||
{
|
||||
t = fRow.getUintField(i);
|
||||
if (cdt)
|
||||
{
|
||||
*cdt = execplan::CalpontSystemCatalog::UBIGINT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::getValue<double>(uint64_t i, double& t)
|
||||
template<> void WindowFunctionType::getValue<double>(uint64_t i, double& t, CDT* cdt)
|
||||
{
|
||||
t = fRow.getDoubleField(i);
|
||||
if (cdt)
|
||||
{
|
||||
*cdt = execplan::CalpontSystemCatalog::DOUBLE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::getValue<float>(uint64_t i, float& t)
|
||||
template<> void WindowFunctionType::getValue<float>(uint64_t i, float& t, CDT* cdt)
|
||||
{
|
||||
t = fRow.getFloatField(i);
|
||||
if (cdt)
|
||||
{
|
||||
*cdt = execplan::CalpontSystemCatalog::FLOAT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::getValue<string>(uint64_t i, string& t)
|
||||
template<> void WindowFunctionType::getValue<string>(uint64_t i, string& t, CDT* cdt)
|
||||
{
|
||||
t = fRow.getStringField(i);
|
||||
// By not setting cdt, we let it default to the column's type
|
||||
}
|
||||
|
||||
|
||||
template<typename T> void WindowFunctionType::setValue(uint64_t i, T& t)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::setValue<int64_t>(uint64_t i, int64_t& t)
|
||||
{
|
||||
fRow.setIntField(t, i);
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::setValue<uint64_t>(uint64_t i, uint64_t& t)
|
||||
{
|
||||
fRow.setUintField(t, i);
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::setValue<double>(uint64_t i, double& t)
|
||||
{
|
||||
fRow.setDoubleField(t, i);
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::setValue<float>(uint64_t i, float& t)
|
||||
{
|
||||
fRow.setFloatField(t, i);
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::setValue<string>(uint64_t i, string& t)
|
||||
{
|
||||
fRow.setStringField(t, i);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WindowFunctionType::setValue(int ct, int64_t b, int64_t e, int64_t c, T* v)
|
||||
{
|
||||
@ -314,7 +324,6 @@ void WindowFunctionType::setValue(int ct, int64_t b, int64_t e, int64_t c, T* v)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WindowFunctionType::implicit2T(uint64_t i, T& t, int s)
|
||||
{
|
||||
@ -384,55 +393,47 @@ void WindowFunctionType::implicit2T(uint64_t i, T& t, int s)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
void WindowFunctionType::implicit2T<string>(uint64_t i, string& t, int)
|
||||
{
|
||||
t = fRow.getStringField(i);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WindowFunctionType::getConstValue(ConstantColumn* cc, T& t, bool& b)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
void WindowFunctionType::getConstValue<int64_t>(ConstantColumn* cc, int64_t& t, bool& b)
|
||||
{
|
||||
t = cc->getIntVal(fRow, b);
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
void WindowFunctionType::getConstValue<uint64_t>(ConstantColumn* cc, uint64_t& t, bool& b)
|
||||
{
|
||||
t = cc->getUintVal(fRow, b);
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
void WindowFunctionType::getConstValue<double>(ConstantColumn* cc, double& t, bool& b)
|
||||
{
|
||||
t = cc->getDoubleVal(fRow, b);
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
void WindowFunctionType::getConstValue<float>(ConstantColumn* cc, float& t, bool& b)
|
||||
{
|
||||
t = cc->getFloatVal(fRow, b);
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
void WindowFunctionType::getConstValue<string>(ConstantColumn* cc, string& t, bool& b)
|
||||
{
|
||||
t = cc->getStrVal(fRow, b);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
@ -445,7 +446,6 @@ template void WindowFunctionType::setValue<double>(int, int64_t, int64_t, int64_
|
||||
template void WindowFunctionType::setValue<string>(int, int64_t, int64_t, int64_t, string*);
|
||||
|
||||
|
||||
|
||||
void* WindowFunctionType::getNullValueByType(int ct, int pos)
|
||||
{
|
||||
static uint64_t bigIntNull = joblist::BIGINTNULL;
|
||||
@ -566,7 +566,6 @@ void* WindowFunctionType::getNullValueByType(int ct, int pos)
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
||||
|
11
utils/windowfunction/windowfunctiontype.h
Normal file → Executable file
11
utils/windowfunction/windowfunctiontype.h
Normal file → Executable file
@ -98,8 +98,9 @@ const int WF__REGR_AVGY = 32;
|
||||
const int WF__REGR_SXX = 33;
|
||||
const int WF__REGR_SXY = 34;
|
||||
const int WF__REGR_SYY = 35;
|
||||
const int WF__UDAF = 36;
|
||||
|
||||
|
||||
typedef execplan::CalpontSystemCatalog::ColDataType CDT;
|
||||
|
||||
/** @brief class WindowFunction
|
||||
*
|
||||
@ -129,6 +130,10 @@ public:
|
||||
// @brief virtual parseParms()
|
||||
virtual void parseParms(const std::vector<execplan::SRCP>&) {}
|
||||
|
||||
// @brief virtual dropValues() For UDAnF functions
|
||||
// return false if there's no dropValue() implemented in the function.
|
||||
virtual bool dropValues(int64_t, int64_t) {return false;}
|
||||
|
||||
// @brief virtual display method
|
||||
virtual const std::string toString() const;
|
||||
|
||||
@ -148,14 +153,14 @@ public:
|
||||
void peer(const boost::shared_ptr<ordering::EqualCompData>& p) { fPeer = p; }
|
||||
void setCallback(joblist::WindowFunctionStep* step) { fStep = step; }
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeWindowFunction(const std::string&, int ct);
|
||||
static boost::shared_ptr<WindowFunctionType> makeWindowFunction(const std::string&, int ct, WindowFunctionColumn* wc);
|
||||
|
||||
protected:
|
||||
|
||||
static std::map<std::string, int> windowFunctionId;
|
||||
|
||||
// utility methods
|
||||
template<typename T> void getValue(uint64_t, T&);
|
||||
template<typename T> void getValue(uint64_t, T&, CDT* cdt = NULL);
|
||||
template<typename T> void setValue(int, int64_t, int64_t, int64_t, T* = NULL);
|
||||
template<typename T> void setValue(uint64_t, T&);
|
||||
template<typename T> void implicit2T(uint64_t, T&, int);
|
||||
|
Reference in New Issue
Block a user