2014-01-28 16:45:10 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <TableFunctions/ITableFunction.h>
|
2020-10-14 12:19:29 +00:00
|
|
|
#include <Interpreters/Cluster.h>
|
|
|
|
#include <Interpreters/StorageID.h>
|
2014-09-23 15:28:21 +00:00
|
|
|
|
2014-01-28 16:45:10 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-05-23 18:44:36 +00:00
|
|
|
/* remote ('address', db, table) - creates a temporary StorageDistributed.
|
2017-04-16 15:00:33 +00:00
|
|
|
* To get the table structure, a DESC TABLE request is made to the remote server.
|
2022-02-28 00:15:37 +00:00
|
|
|
* For example:
|
2017-04-16 15:00:33 +00:00
|
|
|
* SELECT count() FROM remote('example01-01-1', merge, hits) - go to `example01-01-1`, in the merge database, the hits table.
|
2017-08-08 20:58:18 +00:00
|
|
|
* An expression that generates a set of shards and replicas can also be specified as the host name - see below.
|
2022-02-28 00:15:37 +00:00
|
|
|
* Also, there is a cluster version of the function: cluster('existing_cluster_name', 'db', 'table').
|
2014-01-28 16:45:10 +00:00
|
|
|
*/
|
2014-02-23 00:37:25 +00:00
|
|
|
class TableFunctionRemote : public ITableFunction
|
2014-01-28 16:45:10 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-03-12 23:47:20 +00:00
|
|
|
explicit TableFunctionRemote(const std::string & name_, bool secure_ = false);
|
2018-02-12 20:27:14 +00:00
|
|
|
|
2017-06-10 09:04:31 +00:00
|
|
|
std::string getName() const override { return name; }
|
2018-02-12 20:27:14 +00:00
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
ColumnsDescription getActualTableStructure(ContextPtr context) const override;
|
2020-10-14 12:19:29 +00:00
|
|
|
|
|
|
|
bool needStructureConversion() const override { return false; }
|
|
|
|
|
2018-02-12 20:27:14 +00:00
|
|
|
private:
|
2021-12-15 11:30:57 +00:00
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
StoragePtr executeImpl(const ASTPtr & ast_function, ContextPtr context, const std::string & table_name, ColumnsDescription cached_columns) const override;
|
2020-04-06 05:19:40 +00:00
|
|
|
const char * getStorageTypeName() const override { return "Distributed"; }
|
2018-02-12 20:27:14 +00:00
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
void parseArguments(const ASTPtr & ast_function, ContextPtr context) override;
|
2020-10-14 12:19:29 +00:00
|
|
|
|
2018-02-12 20:27:14 +00:00
|
|
|
std::string name;
|
|
|
|
bool is_cluster_function;
|
|
|
|
std::string help_message;
|
2019-01-17 17:55:44 +00:00
|
|
|
bool secure;
|
2020-10-14 12:19:29 +00:00
|
|
|
|
|
|
|
ClusterPtr cluster;
|
|
|
|
StorageID remote_table_id = StorageID::createEmpty();
|
|
|
|
ASTPtr remote_table_function_ptr;
|
2020-12-21 03:19:05 +00:00
|
|
|
ASTPtr sharding_key = nullptr;
|
2014-02-07 15:11:57 +00:00
|
|
|
};
|
2014-01-28 16:45:10 +00:00
|
|
|
|
|
|
|
}
|