1#include <Common/config.h>
2#include <memory>
3#include <type_traits>
4
5#if USE_HDFS
6#include <hdfs/hdfs.h>
7
8namespace DB
9{
10namespace detail
11{
12struct HDFSBuilderDeleter
13{
14 void operator()(hdfsBuilder * builder_ptr)
15 {
16 hdfsFreeBuilder(builder_ptr);
17 }
18};
19struct HDFSFsDeleter
20{
21 void operator()(hdfsFS fs_ptr)
22 {
23 hdfsDisconnect(fs_ptr);
24 }
25};
26
27}
28
29struct HDFSFileInfo
30{
31 hdfsFileInfo * file_info;
32 int length;
33
34 HDFSFileInfo()
35 : file_info(nullptr)
36 , length(0)
37 {
38 }
39 HDFSFileInfo(const HDFSFileInfo & other) = delete;
40 HDFSFileInfo(HDFSFileInfo && other) = default;
41 HDFSFileInfo & operator=(const HDFSFileInfo & other) = delete;
42 HDFSFileInfo & operator=(HDFSFileInfo && other) = default;
43
44 ~HDFSFileInfo()
45 {
46 hdfsFreeFileInfo(file_info, length);
47 }
48};
49using HDFSBuilderPtr = std::unique_ptr<hdfsBuilder, detail::HDFSBuilderDeleter>;
50using HDFSFSPtr = std::unique_ptr<std::remove_pointer_t<hdfsFS>, detail::HDFSFsDeleter>;
51
52// set read/connect timeout, default value in libhdfs3 is about 1 hour, and too large
53/// TODO Allow to tune from query Settings.
54HDFSBuilderPtr createHDFSBuilder(const std::string & hdfs_uri);
55HDFSFSPtr createHDFSFS(hdfsBuilder * builder);
56}
57#endif
58