ClickHouse/dbms/src/Functions/FunctionFactory.cpp

41 lines
689 B
C++
Raw Normal View History

#include <Functions/FunctionFactory.h>
#include <Common/Exception.h>
namespace DB
{
2016-01-12 02:21:15 +00:00
namespace ErrorCodes
{
extern const int UNKNOWN_FUNCTION;
2016-01-12 02:21:15 +00:00
}
FunctionFactory::FunctionFactory()
{
}
FunctionPtr FunctionFactory::get(
const std::string & name,
const Context & context) const
{
auto res = tryGet(name, context);
if (!res)
throw Exception("Unknown function " + name, ErrorCodes::UNKNOWN_FUNCTION);
return res;
}
FunctionPtr FunctionFactory::tryGet(
const std::string & name,
const Context & context) const
{
auto it = functions.find(name);
if (functions.end() != it)
return it->second(context);
else
return {};
}
}