2014-01-28 16:45:10 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-03-11 14:01:45 +00:00
|
|
|
#include <Parsers/IAST_fwd.h>
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <Storages/IStorage_fwd.h>
|
2019-03-11 14:01:45 +00:00
|
|
|
|
2017-01-21 04:24:28 +00:00
|
|
|
#include <memory>
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <string>
|
2014-01-28 16:45:10 +00:00
|
|
|
|
2019-03-11 14:01:45 +00:00
|
|
|
|
2014-01-28 16:45:10 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-01-21 04:24:28 +00:00
|
|
|
class Context;
|
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/** Interface for table functions.
|
2014-01-28 16:45:10 +00:00
|
|
|
*
|
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.
|
2014-01-28 16:45:10 +00:00
|
|
|
*
|
2017-04-16 15:00:33 +00:00
|
|
|
* Example:
|
2014-01-28 16:45:10 +00:00
|
|
|
* 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.
|
2014-01-28 16:45:10 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
class ITableFunction
|
|
|
|
{
|
|
|
|
public:
|
2019-07-09 15:40:21 +00:00
|
|
|
static inline std::string getDatabaseName() { return "_table_function"; }
|
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// Get the main function name.
|
2017-04-01 07:20:54 +00:00
|
|
|
virtual std::string getName() const = 0;
|
2014-01-28 16:45:10 +00:00
|
|
|
|
2018-03-02 05:03:28 +00:00
|
|
|
/// 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;
|
2014-02-23 00:37:25 +00:00
|
|
|
|
2018-06-03 17:43:56 +00:00
|
|
|
virtual ~ITableFunction() {}
|
2018-03-02 05:03:28 +00:00
|
|
|
|
|
|
|
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;
|
2014-01-28 16:45:10 +00:00
|
|
|
};
|
|
|
|
|
2016-05-28 10:15:36 +00:00
|
|
|
using TableFunctionPtr = std::shared_ptr<ITableFunction>;
|
2014-01-28 16:45:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|