#pragma once #include #include #include #include #include namespace DB { namespace ErrorCodes { extern const int LOGICAL_ERROR; } /** Lets you get a table function by its name. */ class TableFunctionFactory : public Singleton { private: /// No std::function, for smaller object size and less indirection. using Creator = TableFunctionPtr(*)(); using TableFunctions = std::unordered_map; TableFunctions functions; public: TableFunctionPtr get( const String & name, const Context & context) const; /// Register a table function by its name. template void registerFunction() { if (!functions.emplace(std::string(Function::name), []{ return TableFunctionPtr(std::make_unique()); }).second) throw Exception("TableFunctionFactory: the table function name '" + String(Function::name) + "' is not unique", ErrorCodes::LOGICAL_ERROR); } }; }