ClickHouse/src/Storages/examples/async_read_buffer_from_hdfs.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

37 lines
1.2 KiB
C++
Raw Normal View History

2022-04-20 08:24:18 +00:00
#include <memory>
#include <string>
2022-06-07 01:58:29 +00:00
#include <filesystem>
2022-04-20 08:24:18 +00:00
#include <IO/WriteHelpers.h>
#include <IO/copyData.h>
#include <IO/WriteBufferFromString.h>
2022-06-07 01:58:29 +00:00
#include <Disks/ObjectStorages/IObjectStorage.h>
2022-04-20 08:24:18 +00:00
#include <Interpreters/Context.h>
#include <Common/Config/ConfigProcessor.h>
#include <Storages/HDFS/AsynchronousReadBufferFromHDFS.h>
int main()
{
using namespace DB;
2022-06-07 01:58:29 +00:00
namespace fs = std::filesystem;
2022-04-21 09:27:41 +00:00
String config_path = "/path/to/config/file";
2022-04-20 08:24:18 +00:00
ConfigProcessor config_processor(config_path, false, true);
config_processor.setConfigPath(fs::path(config_path).parent_path());
auto loaded_config = config_processor.loadConfig(false);
auto * config = loaded_config.configuration.duplicate();
2022-04-21 09:27:41 +00:00
String hdfs_namenode_url = "hdfs://namenode:port/";
String path = "/path/to/hdfs/file";
2022-07-23 17:00:52 +00:00
ReadSettings settings = {};
auto in = std::make_unique<ReadBufferFromHDFS>(hdfs_namenode_url, path, *config, settings);
2022-09-07 15:44:29 +00:00
auto & reader = IObjectStorage::getThreadPoolReader();
2022-04-20 08:24:18 +00:00
AsynchronousReadBufferFromHDFS buf(reader, {}, std::move(in));
String output;
WriteBufferFromString out(output);
copyData(buf, out);
std::cout << "output:" << output << std::endl;
return 0;
}