2019-01-19 20:17:19 +00:00
|
|
|
#include <Common/config.h>
|
|
|
|
#include <memory>
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
#if USE_HDFS
|
2019-06-05 11:52:39 +00:00
|
|
|
#include <hdfs/hdfs.h>
|
2019-01-19 20:17:19 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
struct HDFSBuilderDeleter
|
|
|
|
{
|
|
|
|
void operator()(hdfsBuilder * builder_ptr)
|
|
|
|
{
|
|
|
|
hdfsFreeBuilder(builder_ptr);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
struct HDFSFsDeleter
|
|
|
|
{
|
|
|
|
void operator()(hdfsFS fs_ptr)
|
|
|
|
{
|
|
|
|
hdfsDisconnect(fs_ptr);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-24 09:51:02 +00:00
|
|
|
struct HDFSFileInfo
|
|
|
|
{
|
|
|
|
hdfsFileInfo * file_info;
|
|
|
|
int length;
|
|
|
|
|
|
|
|
HDFSFileInfo()
|
|
|
|
: file_info(nullptr)
|
|
|
|
, length(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
HDFSFileInfo(const HDFSFileInfo & other) = delete;
|
|
|
|
HDFSFileInfo(HDFSFileInfo && other) = default;
|
|
|
|
HDFSFileInfo & operator=(const HDFSFileInfo & other) = delete;
|
|
|
|
HDFSFileInfo & operator=(HDFSFileInfo && other) = default;
|
|
|
|
|
|
|
|
~HDFSFileInfo()
|
|
|
|
{
|
|
|
|
hdfsFreeFileInfo(file_info, length);
|
|
|
|
}
|
|
|
|
};
|
2019-01-19 20:17:19 +00:00
|
|
|
using HDFSBuilderPtr = std::unique_ptr<hdfsBuilder, detail::HDFSBuilderDeleter>;
|
|
|
|
using HDFSFSPtr = std::unique_ptr<std::remove_pointer_t<hdfsFS>, detail::HDFSFsDeleter>;
|
|
|
|
|
|
|
|
// set read/connect timeout, default value in libhdfs3 is about 1 hour, and too large
|
|
|
|
/// TODO Allow to tune from query Settings.
|
2019-09-05 14:42:17 +00:00
|
|
|
HDFSBuilderPtr createHDFSBuilder(const std::string & hdfs_uri);
|
2019-01-19 20:17:19 +00:00
|
|
|
HDFSFSPtr createHDFSFS(hdfsBuilder * builder);
|
|
|
|
}
|
|
|
|
#endif
|