2017-04-01 09:19:00 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <Common/Exception.h>
|
2012-12-18 20:06:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-01-12 02:21:15 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const int UNKNOWN_FUNCTION;
|
2016-01-12 02:21:15 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 00:57:20 +00:00
|
|
|
FunctionFactory::FunctionFactory()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-18 20:06:36 +00:00
|
|
|
FunctionPtr FunctionFactory::get(
|
2017-04-01 07:20:54 +00:00
|
|
|
const std::string & name,
|
|
|
|
const Context & context) const
|
2015-11-29 08:06:29 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
auto res = tryGet(name, context);
|
|
|
|
if (!res)
|
|
|
|
throw Exception("Unknown function " + name, ErrorCodes::UNKNOWN_FUNCTION);
|
|
|
|
return res;
|
2015-11-29 08:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FunctionPtr FunctionFactory::tryGet(
|
2017-04-01 07:20:54 +00:00
|
|
|
const std::string & name,
|
|
|
|
const Context & context) const
|
2012-12-18 20:06:36 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
auto it = functions.find(name);
|
|
|
|
if (functions.end() != it)
|
|
|
|
return it->second(context);
|
|
|
|
else
|
|
|
|
return {};
|
2012-12-18 20:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|