forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTableFunctionFactory.h
68 lines (49 loc) · 2.1 KB
/
TableFunctionFactory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once
#include <TableFunctions/ITableFunction.h>
#include <Common/IFactoryWithAliases.h>
#include <Common/NamePrompter.h>
#include <Common/Documentation.h>
#include <functional>
#include <memory>
#include <string>
#include <unordered_map>
#include <boost/noncopyable.hpp>
namespace DB
{
class Context;
using TableFunctionCreator = std::function<TableFunctionPtr()>;
using TableFunctionFactoryData = std::pair<TableFunctionCreator, Documentation>;
/** Lets you get a table function by its name.
*/
class TableFunctionFactory final: private boost::noncopyable, public IFactoryWithAliases<TableFunctionFactoryData>
{
public:
static TableFunctionFactory & instance();
/// Register a function by its name.
/// No locking, you must register all functions before usage of get.
void registerFunction(
const std::string & name,
TableFunctionCreator creator,
Documentation doc = {},
CaseSensitiveness case_sensitiveness = CaseSensitive);
template <typename Function>
void registerFunction(Documentation doc = {}, CaseSensitiveness case_sensitiveness = CaseSensitive)
{
auto creator = []() -> TableFunctionPtr { return std::make_shared<Function>(); };
registerFunction(Function::name, std::move(creator), std::move(doc), case_sensitiveness);
}
/// Throws an exception if not found.
TableFunctionPtr get(const ASTPtr & ast_function, ContextPtr context) const;
/// Returns nullptr if not found.
TableFunctionPtr tryGet(const std::string & name, ContextPtr context) const;
Documentation getDocumentation(const std::string & name) const;
bool isTableFunctionName(const std::string & name) const;
private:
using TableFunctions = std::unordered_map<std::string, Value>;
const TableFunctions & getMap() const override { return table_functions; }
const TableFunctions & getCaseInsensitiveMap() const override { return case_insensitive_table_functions; }
String getFactoryName() const override { return "TableFunctionFactory"; }
TableFunctions table_functions;
TableFunctions case_insensitive_table_functions;
};
}