1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#pragma once
#include "clickhouse_config.h"
#if USE_AWS_S3
#include <mutex>
#include <Databases/IDatabase.h>
#include <Parsers/IAST.h>
#include <Storages/IStorage_fwd.h>
#include <base/types.h>
namespace DB
{
class Context;
/**
* DatabaseS3 provides access to data stored in S3.
* Uses TableFunctionS3 to implicitly load file when a user requests the table,
* and provides read-only access to the data in the file.
* Tables are cached inside the database for quick access.
*/
class DatabaseS3 : public IDatabase, protected WithContext
{
public:
struct Configuration
{
std::string url_prefix;
bool no_sign_request = false;
std::optional<std::string> access_key_id;
std::optional<std::string> secret_access_key;
};
DatabaseS3(const String & name, const Configuration& config, ContextPtr context);
String getEngineName() const override { return "S3"; }
bool isTableExist(const String & name, ContextPtr context) const override;
StoragePtr getTable(const String & name, ContextPtr context) const override;
StoragePtr tryGetTable(const String & name, ContextPtr context) const override;
// Contains only temporary tables
bool shouldBeEmptyOnDetach() const override { return false; }
bool empty() const override;
bool isReadOnly() const override { return true; }
ASTPtr getCreateDatabaseQuery() const override;
void shutdown() override;
std::vector<std::pair<ASTPtr, StoragePtr>> getTablesForBackup(const FilterByNameFunction &, const ContextPtr &) const override;
DatabaseTablesIteratorPtr getTablesIterator(ContextPtr, const FilterByNameFunction &) const override;
static Configuration parseArguments(ASTs engine_args, ContextPtr context);
protected:
StoragePtr getTableImpl(const String & name, ContextPtr context) const;
void addTable(const std::string & table_name, StoragePtr table_storage) const;
bool checkUrl(const std::string & url, ContextPtr context_, bool throw_on_error) const;
std::string getFullUrl(const std::string & name) const;
private:
const Configuration config;
mutable Tables loaded_tables TSA_GUARDED_BY(mutex);
Poco::Logger * log;
};
}
#endif
|