| 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
 | #pragma once
#include "clickhouse_config.h"
#if USE_HDFS
#include <mutex>
#include <Databases/IDatabase.h>
#include <Parsers/IAST.h>
#include <Storages/IStorage_fwd.h>
#include <base/types.h>
namespace DB
{
class Context;
/**
  * DatabaseHDFS allows to interact with files stored on the file system.
  * Uses TableFunctionHDFS 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 DatabaseHDFS : public IDatabase, protected WithContext
{
public:
    DatabaseHDFS(const String & name, const String & source_url, 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;
    bool shouldBeEmptyOnDetach() const override { return false; } /// Contains only temporary tables.
    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;
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 getTablePath(const std::string & table_name) const;
private:
    const String source;
    mutable Tables loaded_tables TSA_GUARDED_BY(mutex);
    Poco::Logger * log;
};
}
#endif
 |