1#pragma once
2
3#include <Common/config.h>
4
5#if USE_AWS_S3
6
7#include <Storages/IStorage.h>
8#include <Poco/URI.h>
9#include <common/logger_useful.h>
10#include <ext/shared_ptr_helper.h>
11
12namespace Aws::S3
13{
14 class S3Client;
15}
16
17namespace DB
18{
19
20/**
21 * This class represents table engine for external S3 urls.
22 * It sends HTTP GET to server when select is called and
23 * HTTP PUT when insert is called.
24 */
25class StorageS3 : public ext::shared_ptr_helper<StorageS3>, public IStorage
26{
27public:
28 StorageS3(const S3::URI & uri,
29 const String & access_key_id,
30 const String & secret_access_key,
31 const String & database_name_,
32 const String & table_name_,
33 const String & format_name_,
34 UInt64 min_upload_part_size_,
35 const ColumnsDescription & columns_,
36 const ConstraintsDescription & constraints_,
37 Context & context_,
38 const String & compression_method_);
39
40 String getName() const override
41 {
42 return "S3";
43 }
44
45 Block getHeaderBlock(const Names & /*column_names*/) const
46 {
47 return getSampleBlock();
48 }
49
50 String getTableName() const override
51 {
52 return table_name;
53 }
54
55 BlockInputStreams read(
56 const Names & column_names,
57 const SelectQueryInfo & query_info,
58 const Context & context,
59 QueryProcessingStage::Enum processed_stage,
60 size_t max_block_size,
61 unsigned num_streams) override;
62
63 BlockOutputStreamPtr write(const ASTPtr & query, const Context & context) override;
64
65 void rename(const String & new_path_to_db, const String & new_database_name, const String & new_table_name, TableStructureWriteLockHolder &) override;
66
67private:
68 S3::URI uri;
69 const Context & context_global;
70
71 String format_name;
72 String database_name;
73 String table_name;
74 UInt64 min_upload_part_size;
75 String compression_method;
76 std::shared_ptr<Aws::S3::S3Client> client;
77};
78
79}
80
81#endif
82