2019-12-06 14:37:21 +00:00
|
|
|
#include <Common/config.h>
|
|
|
|
|
|
|
|
#if USE_AWS_S3
|
2019-05-31 10:58:43 +00:00
|
|
|
|
2019-12-06 14:37:21 +00:00
|
|
|
#include <IO/ReadBufferFromS3.h>
|
2019-09-19 10:25:31 +00:00
|
|
|
#include <IO/ReadBufferFromIStream.h>
|
|
|
|
|
2019-05-31 10:58:43 +00:00
|
|
|
#include <common/logger_useful.h>
|
2019-12-03 16:23:24 +00:00
|
|
|
#include <aws/s3/model/GetObjectRequest.h>
|
2019-05-31 10:58:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2019-12-03 16:23:24 +00:00
|
|
|
namespace ErrorCodes
|
2019-05-31 18:14:39 +00:00
|
|
|
{
|
2019-12-03 16:23:24 +00:00
|
|
|
extern const int S3_ERROR;
|
|
|
|
}
|
2019-05-31 18:14:39 +00:00
|
|
|
|
|
|
|
|
2019-12-03 16:23:24 +00:00
|
|
|
ReadBufferFromS3::ReadBufferFromS3(const std::shared_ptr<Aws::S3::S3Client> & client_ptr,
|
|
|
|
const String & bucket,
|
|
|
|
const String & key,
|
|
|
|
size_t buffer_size_): ReadBuffer(nullptr, 0)
|
|
|
|
{
|
|
|
|
Aws::S3::Model::GetObjectRequest req;
|
|
|
|
req.SetBucket(bucket);
|
|
|
|
req.SetKey(key);
|
2019-05-31 18:14:39 +00:00
|
|
|
|
2019-12-03 16:23:24 +00:00
|
|
|
Aws::S3::Model::GetObjectOutcome outcome = client_ptr->GetObject(req);
|
2019-05-31 18:14:39 +00:00
|
|
|
|
2019-12-03 16:23:24 +00:00
|
|
|
if (outcome.IsSuccess()) {
|
|
|
|
read_result = outcome.GetResultWithOwnership();
|
|
|
|
impl = std::make_unique<ReadBufferFromIStream>(read_result.GetBody(), buffer_size_);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw Exception(outcome.GetError().GetMessage(), ErrorCodes::S3_ERROR);
|
2019-05-31 18:14:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-01 21:18:20 +00:00
|
|
|
bool ReadBufferFromS3::nextImpl()
|
2019-05-31 18:14:39 +00:00
|
|
|
{
|
|
|
|
if (!impl->next())
|
|
|
|
return false;
|
|
|
|
internal_buffer = impl->buffer();
|
|
|
|
working_buffer = internal_buffer;
|
|
|
|
return true;
|
|
|
|
}
|
2019-05-31 10:58:43 +00:00
|
|
|
}
|
2019-12-06 14:37:21 +00:00
|
|
|
|
|
|
|
#endif
|