2014-01-28 16:45:10 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <TableFunctions/ITableFunction.h>
|
2019-07-29 13:50:13 +00:00
|
|
|
#include <Common/IFactoryWithAliases.h>
|
2019-04-03 11:13:22 +00:00
|
|
|
#include <Common/NamePrompter.h>
|
2014-01-28 16:45:10 +00:00
|
|
|
|
2017-08-18 17:06:22 +00:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
2019-08-22 03:24:05 +00:00
|
|
|
#include <boost/noncopyable.hpp>
|
2017-08-18 17:06:22 +00:00
|
|
|
|
2014-01-28 16:45:10 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-08-18 17:06:22 +00:00
|
|
|
class Context;
|
2017-06-10 09:04:31 +00:00
|
|
|
|
2019-07-29 13:50:13 +00:00
|
|
|
using TableFunctionCreator = std::function<TableFunctionPtr()>;
|
2017-06-10 09:04:31 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/** Lets you get a table function by its name.
|
2014-01-28 16:45:10 +00:00
|
|
|
*/
|
2019-08-22 03:24:05 +00:00
|
|
|
class TableFunctionFactory final: private boost::noncopyable, public IFactoryWithAliases<TableFunctionCreator>
|
2014-01-28 16:45:10 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-08-22 03:24:05 +00:00
|
|
|
static TableFunctionFactory & instance();
|
|
|
|
|
2017-08-18 17:06:22 +00:00
|
|
|
/// Register a function by its name.
|
2017-06-13 02:06:53 +00:00
|
|
|
/// No locking, you must register all functions before usage of get.
|
2020-06-14 07:44:02 +00:00
|
|
|
void registerFunction(const std::string & name, Value creator, CaseSensitiveness case_sensitiveness = CaseSensitive);
|
2017-08-18 17:06:22 +00:00
|
|
|
|
2017-06-10 09:04:31 +00:00
|
|
|
template <typename Function>
|
2019-07-29 13:50:13 +00:00
|
|
|
void registerFunction(CaseSensitiveness case_sensitiveness = CaseSensitive)
|
2017-06-10 09:04:31 +00:00
|
|
|
{
|
2018-01-10 00:04:08 +00:00
|
|
|
auto creator = [] () -> TableFunctionPtr
|
|
|
|
{
|
2017-08-18 17:06:22 +00:00
|
|
|
return std::make_shared<Function>();
|
|
|
|
};
|
2019-07-29 13:50:13 +00:00
|
|
|
registerFunction(Function::name, std::move(creator), case_sensitiveness);
|
2017-06-10 09:04:31 +00:00
|
|
|
}
|
2017-08-18 17:06:22 +00:00
|
|
|
|
|
|
|
/// Throws an exception if not found.
|
2020-10-14 12:19:29 +00:00
|
|
|
TableFunctionPtr get(const ASTPtr & ast_function, const Context & context) const;
|
2019-07-29 13:50:13 +00:00
|
|
|
|
|
|
|
/// Returns nullptr if not found.
|
|
|
|
TableFunctionPtr tryGet(const std::string & name, const Context & context) const;
|
2018-07-27 21:33:30 +00:00
|
|
|
|
2018-07-24 13:10:34 +00:00
|
|
|
bool isTableFunctionName(const std::string & name) const;
|
|
|
|
|
2019-07-29 13:50:13 +00:00
|
|
|
private:
|
2020-06-14 07:44:02 +00:00
|
|
|
using TableFunctions = std::unordered_map<std::string, Value>;
|
2017-08-18 17:06:22 +00:00
|
|
|
|
2020-06-14 07:44:02 +00:00
|
|
|
const TableFunctions & getMap() const override { return table_functions; }
|
2019-04-03 11:13:22 +00:00
|
|
|
|
2020-06-14 07:44:02 +00:00
|
|
|
const TableFunctions & getCaseInsensitiveMap() const override { return case_insensitive_table_functions; }
|
2019-07-29 13:50:13 +00:00
|
|
|
|
|
|
|
String getFactoryName() const override { return "TableFunctionFactory"; }
|
|
|
|
|
|
|
|
TableFunctions table_functions;
|
|
|
|
TableFunctions case_insensitive_table_functions;
|
2014-01-28 16:45:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|