2017-08-18 17:06:22 +00:00
|
|
|
#include <TableFunctions/TableFunctionFactory.h>
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2017-08-18 17:06:22 +00:00
|
|
|
#include <Common/Exception.h>
|
2019-04-03 11:13:22 +00:00
|
|
|
#include <IO/WriteHelpers.h>
|
2014-01-28 16:45:10 +00:00
|
|
|
|
2019-07-30 12:15:02 +00:00
|
|
|
|
2014-01-28 16:45:10 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-01-11 21:46:36 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const int UNKNOWN_FUNCTION;
|
2017-08-18 17:06:22 +00:00
|
|
|
extern const int LOGICAL_ERROR;
|
2016-01-11 21:46:36 +00:00
|
|
|
}
|
|
|
|
|
2014-01-28 16:45:10 +00:00
|
|
|
|
2019-07-29 13:50:13 +00:00
|
|
|
void TableFunctionFactory::registerFunction(const std::string & name, Creator creator, CaseSensitiveness case_sensitiveness)
|
2017-08-18 17:06:22 +00:00
|
|
|
{
|
2019-07-29 13:50:13 +00:00
|
|
|
if (!table_functions.emplace(name, creator).second)
|
2017-08-18 17:06:22 +00:00
|
|
|
throw Exception("TableFunctionFactory: the table function name '" + name + "' is not unique",
|
|
|
|
ErrorCodes::LOGICAL_ERROR);
|
2019-07-29 13:50:13 +00:00
|
|
|
|
|
|
|
if (case_sensitiveness == CaseInsensitive
|
|
|
|
&& !case_insensitive_table_functions.emplace(Poco::toLower(name), creator).second)
|
2019-07-29 16:20:17 +00:00
|
|
|
throw Exception("TableFunctionFactory: the case insensitive table function name '" + name + "' is not unique",
|
2019-07-29 13:50:13 +00:00
|
|
|
ErrorCodes::LOGICAL_ERROR);
|
2017-08-18 17:06:22 +00:00
|
|
|
}
|
|
|
|
|
2014-01-28 16:45:10 +00:00
|
|
|
TableFunctionPtr TableFunctionFactory::get(
|
2017-04-01 07:20:54 +00:00
|
|
|
const std::string & name,
|
|
|
|
const Context & context) const
|
2014-01-28 16:45:10 +00:00
|
|
|
{
|
2019-07-29 13:50:13 +00:00
|
|
|
auto res = tryGet(name, context);
|
|
|
|
if (!res)
|
2019-04-03 11:13:22 +00:00
|
|
|
{
|
|
|
|
auto hints = getHints(name);
|
|
|
|
if (!hints.empty())
|
|
|
|
throw Exception("Unknown table function " + name + ". Maybe you meant: " + toString(hints), ErrorCodes::UNKNOWN_FUNCTION);
|
|
|
|
else
|
|
|
|
throw Exception("Unknown table function " + name, ErrorCodes::UNKNOWN_FUNCTION);
|
|
|
|
}
|
2017-08-18 17:06:22 +00:00
|
|
|
|
2019-07-29 13:50:13 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
TableFunctionPtr TableFunctionFactory::tryGet(
|
|
|
|
const std::string & name_param,
|
|
|
|
const Context &) const
|
|
|
|
{
|
|
|
|
String name = getAliasToOrName(name_param);
|
|
|
|
|
|
|
|
auto it = table_functions.find(name);
|
|
|
|
if (table_functions.end() != it)
|
|
|
|
return it->second();
|
|
|
|
|
|
|
|
it = case_insensitive_table_functions.find(Poco::toLower(name));
|
|
|
|
if (case_insensitive_table_functions.end() != it)
|
|
|
|
return it->second();
|
|
|
|
|
|
|
|
return {};
|
2014-01-28 16:45:10 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 13:10:34 +00:00
|
|
|
bool TableFunctionFactory::isTableFunctionName(const std::string & name) const
|
|
|
|
{
|
2019-07-29 13:50:13 +00:00
|
|
|
return table_functions.count(name);
|
2018-07-24 13:10:34 +00:00
|
|
|
}
|
|
|
|
|
2019-08-22 03:24:05 +00:00
|
|
|
TableFunctionFactory & TableFunctionFactory::instance()
|
|
|
|
{
|
|
|
|
static TableFunctionFactory ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-01-28 16:45:10 +00:00
|
|
|
}
|