| 1 | #pragma once |
| 2 | |
| 3 | #include <Parsers/IAST_fwd.h> |
| 4 | #include <Storages/IStorage_fwd.h> |
| 5 | |
| 6 | #include <memory> |
| 7 | #include <string> |
| 8 | |
| 9 | |
| 10 | namespace DB |
| 11 | { |
| 12 | |
| 13 | class Context; |
| 14 | |
| 15 | /** Interface for table functions. |
| 16 | * |
| 17 | * Table functions are not relevant to other functions. |
| 18 | * The table function can be specified in the FROM section instead of the [db.]Table |
| 19 | * The table function returns a temporary StoragePtr object that is used to execute the query. |
| 20 | * |
| 21 | * Example: |
| 22 | * SELECT count() FROM remote('example01-01-1', merge, hits) |
| 23 | * - go to `example01-01-1`, in `merge` database, `hits` table. |
| 24 | */ |
| 25 | |
| 26 | class ITableFunction |
| 27 | { |
| 28 | public: |
| 29 | static inline std::string getDatabaseName() { return "_table_function" ; } |
| 30 | |
| 31 | /// Get the main function name. |
| 32 | virtual std::string getName() const = 0; |
| 33 | |
| 34 | /// Create storage according to the query. |
| 35 | StoragePtr execute(const ASTPtr & ast_function, const Context & context, const std::string & table_name) const; |
| 36 | |
| 37 | virtual ~ITableFunction() {} |
| 38 | |
| 39 | private: |
| 40 | virtual StoragePtr executeImpl(const ASTPtr & ast_function, const Context & context, const std::string & table_name) const = 0; |
| 41 | }; |
| 42 | |
| 43 | using TableFunctionPtr = std::shared_ptr<ITableFunction>; |
| 44 | |
| 45 | |
| 46 | } |
| 47 | |