2020-11-20 22:47:04 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#if !defined(ARCADIA_BUILD)
|
|
|
|
#include "config_core.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USE_LIBPQXX
|
|
|
|
#include <ext/shared_ptr_helper.h>
|
|
|
|
#include <Interpreters/Context.h>
|
|
|
|
#include <Storages/IStorage.h>
|
2020-11-25 14:52:11 +00:00
|
|
|
#include <DataStreams/IBlockOutputStream.h>
|
2021-03-27 19:18:05 +00:00
|
|
|
#include <Storages/PostgreSQL/PostgreSQLPoolWithFailover.h>
|
2021-01-15 19:59:49 +00:00
|
|
|
#include <pqxx/pqxx>
|
2020-11-20 22:47:04 +00:00
|
|
|
|
2021-01-11 10:23:44 +00:00
|
|
|
|
2020-11-20 22:47:04 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2020-11-25 21:06:33 +00:00
|
|
|
|
|
|
|
|
2020-11-20 22:47:04 +00:00
|
|
|
class StoragePostgreSQL final : public ext::shared_ptr_helper<StoragePostgreSQL>, public IStorage
|
|
|
|
{
|
|
|
|
friend struct ext::shared_ptr_helper<StoragePostgreSQL>;
|
|
|
|
public:
|
|
|
|
StoragePostgreSQL(
|
|
|
|
const StorageID & table_id_,
|
2021-03-27 19:18:05 +00:00
|
|
|
const PostgreSQLPoolWithFailover & pool_,
|
2021-03-15 14:37:31 +00:00
|
|
|
const String & remote_table_name_,
|
2020-11-20 22:47:04 +00:00
|
|
|
const ColumnsDescription & columns_,
|
|
|
|
const ConstraintsDescription & constraints_,
|
2021-03-14 10:35:10 +00:00
|
|
|
const Context & context_,
|
|
|
|
const std::string & remote_table_schema_ = "");
|
2020-11-20 22:47:04 +00:00
|
|
|
|
|
|
|
String getName() const override { return "PostgreSQL"; }
|
|
|
|
|
|
|
|
Pipe read(
|
|
|
|
const Names & column_names,
|
|
|
|
const StorageMetadataPtr & /*metadata_snapshot*/,
|
|
|
|
SelectQueryInfo & query_info,
|
|
|
|
const Context & context,
|
|
|
|
QueryProcessingStage::Enum processed_stage,
|
|
|
|
size_t max_block_size,
|
|
|
|
unsigned num_streams) override;
|
|
|
|
|
2020-11-25 14:52:11 +00:00
|
|
|
BlockOutputStreamPtr write(const ASTPtr & query, const StorageMetadataPtr & /*metadata_snapshot*/, const Context & context) override;
|
|
|
|
|
2020-11-20 22:47:04 +00:00
|
|
|
private:
|
2020-11-25 14:52:11 +00:00
|
|
|
friend class PostgreSQLBlockOutputStream;
|
|
|
|
|
2020-11-20 22:47:04 +00:00
|
|
|
String remote_table_name;
|
2021-03-14 10:35:10 +00:00
|
|
|
String remote_table_schema;
|
2020-11-20 22:47:04 +00:00
|
|
|
Context global_context;
|
2021-03-27 19:18:05 +00:00
|
|
|
PostgreSQLPoolWithFailoverPtr pool;
|
2020-11-25 14:52:11 +00:00
|
|
|
};
|
2020-12-21 19:20:56 +00:00
|
|
|
|
2020-11-20 22:47:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|