2020-11-20 22:47:04 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-09-28 13:29:29 +00:00
|
|
|
#include "config.h"
|
2020-11-20 22:47:04 +00:00
|
|
|
|
|
|
|
#if USE_LIBPQXX
|
|
|
|
#include <Interpreters/Context.h>
|
|
|
|
#include <Storages/IStorage.h>
|
|
|
|
|
2021-09-28 22:17:26 +00:00
|
|
|
namespace Poco
|
|
|
|
{
|
|
|
|
class Logger;
|
|
|
|
}
|
2021-01-11 10:23:44 +00:00
|
|
|
|
2022-12-17 00:30:55 +00:00
|
|
|
namespace postgres
|
|
|
|
{
|
|
|
|
class PoolWithFailover;
|
|
|
|
using PoolWithFailoverPtr = std::shared_ptr<PoolWithFailover>;
|
|
|
|
}
|
|
|
|
|
2020-11-20 22:47:04 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2023-02-20 20:37:38 +00:00
|
|
|
class NamedCollection;
|
2020-11-25 21:06:33 +00:00
|
|
|
|
2022-05-03 06:43:28 +00:00
|
|
|
class StoragePostgreSQL final : public IStorage
|
2020-11-20 22:47:04 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
StoragePostgreSQL(
|
|
|
|
const StorageID & table_id_,
|
2021-05-07 11:18:49 +00:00
|
|
|
postgres::PoolWithFailoverPtr 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-04-23 12:18:23 +00:00
|
|
|
const String & comment,
|
2023-05-19 00:44:27 +00:00
|
|
|
ContextPtr context_,
|
2021-08-24 12:29:42 +00:00
|
|
|
const String & remote_table_schema_ = "",
|
|
|
|
const String & on_conflict = "");
|
2020-11-20 22:47:04 +00:00
|
|
|
|
|
|
|
String getName() const override { return "PostgreSQL"; }
|
|
|
|
|
|
|
|
Pipe read(
|
|
|
|
const Names & column_names,
|
2021-07-09 03:15:41 +00:00
|
|
|
const StorageSnapshotPtr & storage_snapshot,
|
2020-11-20 22:47:04 +00:00
|
|
|
SelectQueryInfo & query_info,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context,
|
2020-11-20 22:47:04 +00:00
|
|
|
QueryProcessingStage::Enum processed_stage,
|
|
|
|
size_t max_block_size,
|
2022-10-07 10:46:45 +00:00
|
|
|
size_t num_streams) override;
|
2020-11-20 22:47:04 +00:00
|
|
|
|
2023-06-07 18:33:08 +00:00
|
|
|
SinkToStoragePtr write(const ASTPtr & query, const StorageMetadataPtr & /*metadata_snapshot*/, ContextPtr context, bool async_insert) override;
|
2020-11-25 14:52:11 +00:00
|
|
|
|
2022-12-17 00:30:55 +00:00
|
|
|
struct Configuration
|
|
|
|
{
|
|
|
|
String host;
|
|
|
|
UInt16 port = 0;
|
|
|
|
String username = "default";
|
|
|
|
String password;
|
|
|
|
String database;
|
|
|
|
String table;
|
|
|
|
String schema;
|
|
|
|
String on_conflict;
|
|
|
|
|
|
|
|
std::vector<std::pair<String, UInt16>> addresses; /// Failover replicas.
|
|
|
|
String addresses_expr;
|
|
|
|
};
|
|
|
|
|
|
|
|
static Configuration getConfiguration(ASTs engine_args, ContextPtr context);
|
2021-09-01 17:59:11 +00:00
|
|
|
|
2023-02-20 20:37:38 +00:00
|
|
|
static Configuration processNamedCollectionResult(const NamedCollection & named_collection, bool require_table = true);
|
|
|
|
|
2023-05-19 00:44:27 +00:00
|
|
|
static ColumnsDescription getTableStructureFromData(
|
|
|
|
const postgres::PoolWithFailoverPtr & pool_,
|
|
|
|
const String & table,
|
|
|
|
const String & schema,
|
|
|
|
const ContextPtr & context_);
|
|
|
|
|
2020-11-20 22:47:04 +00:00
|
|
|
private:
|
|
|
|
String remote_table_name;
|
2021-03-14 10:35:10 +00:00
|
|
|
String remote_table_schema;
|
2021-08-24 12:29:42 +00:00
|
|
|
String on_conflict;
|
2021-03-27 20:14:02 +00:00
|
|
|
postgres::PoolWithFailoverPtr pool;
|
2021-09-28 22:17:26 +00:00
|
|
|
|
|
|
|
Poco::Logger * log;
|
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
|