mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-10-06 00:20:51 +00:00
52 lines
1.1 KiB
C++
52 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <TableFunctions/ITableFunction.h>
|
|
|
|
#include <ext/singleton.h>
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
class Context;
|
|
|
|
|
|
/** Lets you get a table function by its name.
|
|
*/
|
|
class TableFunctionFactory final: public ext::singleton<TableFunctionFactory>
|
|
{
|
|
public:
|
|
using Creator = std::function<TableFunctionPtr()>;
|
|
|
|
/// Register a function by its name.
|
|
/// No locking, you must register all functions before usage of get.
|
|
void registerFunction(const std::string & name, Creator creator);
|
|
|
|
template <typename Function>
|
|
void registerFunction()
|
|
{
|
|
auto creator = [] () -> TableFunctionPtr
|
|
{
|
|
return std::make_shared<Function>();
|
|
};
|
|
registerFunction(Function::name, std::move(creator));
|
|
}
|
|
|
|
/// Throws an exception if not found.
|
|
TableFunctionPtr get(
|
|
const std::string & name,
|
|
const Context & context) const;
|
|
|
|
private:
|
|
using TableFunctions = std::unordered_map<std::string, Creator>;
|
|
|
|
TableFunctions functions;
|
|
};
|
|
|
|
}
|