ClickHouse/dbms/TableFunctions/ITableFunction.h

47 lines
1.1 KiB
C++
Raw Normal View History

#pragma once
2019-03-11 14:01:45 +00:00
#include <Parsers/IAST_fwd.h>
#include <Storages/IStorage_fwd.h>
2019-03-11 14:01:45 +00:00
#include <memory>
#include <string>
2019-03-11 14:01:45 +00:00
namespace DB
{
class Context;
2017-04-16 15:00:33 +00:00
/** Interface for table functions.
*
2017-04-16 15:00:33 +00:00
* Table functions are not relevant to other functions.
* The table function can be specified in the FROM section instead of the [db.]Table
* The table function returns a temporary StoragePtr object that is used to execute the query.
*
2017-04-16 15:00:33 +00:00
* Example:
* SELECT count() FROM remote('example01-01-1', merge, hits)
2017-04-16 15:00:33 +00:00
* - go to `example01-01-1`, in `merge` database, `hits` table.
*/
class ITableFunction
{
public:
static inline std::string getDatabaseName() { return "_table_function"; }
2017-04-16 15:00:33 +00:00
/// Get the main function name.
virtual std::string getName() const = 0;
/// Create storage according to the query.
2019-07-18 18:29:49 +00:00
StoragePtr execute(const ASTPtr & ast_function, const Context & context, const std::string & table_name) const;
virtual ~ITableFunction() {}
private:
2019-07-18 18:29:49 +00:00
virtual StoragePtr executeImpl(const ASTPtr & ast_function, const Context & context, const std::string & table_name) const = 0;
};
using TableFunctionPtr = std::shared_ptr<ITableFunction>;
}