forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 17
Added support for s3 tables #1617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
subkanthi
wants to merge
13
commits into
antalya-26.1
Choose a base branch
from
s3table_support
base: antalya-26.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f52a708
Added support for s3 tables
subkanthi dbcf541
Override getTables and tryGetTableMetadata, getTables() since s3table…
subkanthi f035cca
Add retry mechanism
subkanthi 0cb0725
Changed from LOGICAL_ERROR to S3_ERROR
subkanthi 8acaa19
Added support for dropTable, moved signing logic from createReadBuffe…
subkanthi 20c50ee
Removed virtual keyword from sendRequest and ReadWriteBufferFromHTTPPtr
subkanthi 2a8960f
Merge branch 'antalya-26.1' into s3table_support
subkanthi 36c5a78
Addressed PR review comments
subkanthi ec1c9bc
Merge branch 's3table_support' of https://github.com/Altinity/ClickHo…
subkanthi baab723
Replaced hardcoded s3 path with AWS SDK Aws::S3::Endpoint::S3Endpoint…
subkanthi 10c132c
Merge branch 'antalya-26.1' into s3table_support
subkanthi bdfed04
Updated test to check for full urls
subkanthi 1413910
Merge branch 's3table_support' of https://github.com/Altinity/ClickHo…
subkanthi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| #include "config.h" | ||
|
|
||
| #if USE_AVRO && USE_SSL && USE_AWS_S3 | ||
|
|
||
| #include <Databases/DataLake/AWSV4Signer.h> | ||
|
|
||
| #include <Common/Exception.h> | ||
| #include <Poco/Net/HTTPRequest.h> | ||
| #include <Poco/String.h> | ||
|
|
||
| #include <aws/core/auth/signer/AWSAuthV4Signer.h> | ||
| #include <aws/core/http/standard/StandardHttpRequest.h> | ||
| #include <aws/core/http/URI.h> | ||
| #include <aws/core/utils/memory/AWSMemory.h> | ||
|
|
||
| #include <sstream> | ||
| #include <utility> | ||
|
|
||
| namespace DB | ||
| { | ||
| namespace ErrorCodes | ||
| { | ||
| extern const int BAD_ARGUMENTS; | ||
| extern const int S3_ERROR; | ||
| } | ||
| } | ||
|
|
||
| namespace DataLake | ||
| { | ||
| namespace | ||
| { | ||
|
|
||
| Aws::Http::HttpMethod mapPocoMethodToAws(const String & method) | ||
| { | ||
| using Aws::Http::HttpMethod; | ||
| using Poco::Net::HTTPRequest; | ||
|
|
||
| static const std::pair<String, HttpMethod> supported_methods[] = { | ||
| {HTTPRequest::HTTP_GET, HttpMethod::HTTP_GET}, | ||
| {HTTPRequest::HTTP_POST, HttpMethod::HTTP_POST}, | ||
| {HTTPRequest::HTTP_PUT, HttpMethod::HTTP_PUT}, | ||
| {HTTPRequest::HTTP_DELETE, HttpMethod::HTTP_DELETE}, | ||
| {HTTPRequest::HTTP_HEAD, HttpMethod::HTTP_HEAD}, | ||
| {HTTPRequest::HTTP_PATCH, HttpMethod::HTTP_PATCH}, | ||
| }; | ||
|
|
||
| for (const auto & [poco_method, aws_method] : supported_methods) | ||
| if (method == poco_method) | ||
| return aws_method; | ||
|
|
||
| throw DB::Exception(DB::ErrorCodes::BAD_ARGUMENTS, "Unsupported HTTP method for AWS SigV4 signing: {}", method); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| void signRequestWithAWSV4( | ||
| const String & method, | ||
| const Poco::URI & uri, | ||
| const DB::HTTPHeaderEntries & extra_headers, | ||
| const String & payload, | ||
| Aws::Client::AWSAuthV4Signer & signer, | ||
| const String & region, | ||
| const String & service, | ||
| DB::HTTPHeaderEntries & out_headers) | ||
| { | ||
| const Aws::Http::URI aws_uri(uri.toString().c_str()); | ||
| Aws::Http::Standard::StandardHttpRequest request(aws_uri, mapPocoMethodToAws(method)); | ||
|
|
||
| for (const auto & h : extra_headers) | ||
| { | ||
| if (Poco::icompare(h.name, "authorization") == 0) | ||
| continue; | ||
| request.SetHeaderValue(Aws::String(h.name.c_str(), h.name.size()), Aws::String(h.value.c_str(), h.value.size())); | ||
| } | ||
|
|
||
| if (!payload.empty()) | ||
| { | ||
| auto body_stream = Aws::MakeShared<std::stringstream>("AWSV4Signer"); | ||
| body_stream->write(payload.data(), static_cast<std::streamsize>(payload.size())); | ||
| body_stream->seekg(0); | ||
| request.AddContentBody(body_stream); | ||
| } | ||
|
|
||
| static constexpr bool sign_body = true; | ||
| if (!signer.SignRequest(request, region.c_str(), service.c_str(), sign_body)) | ||
| throw DB::Exception(DB::ErrorCodes::S3_ERROR, "AWS SigV4 signing failed"); | ||
|
|
||
| bool has_authorization = false; | ||
| for (const auto & [key, value] : request.GetHeaders()) | ||
| { | ||
| if (Poco::icompare(key, "authorization") == 0 && !value.empty()) | ||
| has_authorization = true; | ||
| } | ||
| if (!has_authorization) | ||
| throw DB::Exception( | ||
| DB::ErrorCodes::BAD_ARGUMENTS, | ||
| "AWS credentials are missing or incomplete; cannot sign S3 Tables REST request"); | ||
|
|
||
| out_headers.clear(); | ||
| for (const auto & [key, value] : request.GetHeaders()) | ||
| { | ||
| if (Poco::icompare(key, "host") == 0) | ||
| continue; | ||
| out_headers.emplace_back(String(key.c_str(), key.size()), String(value.c_str(), value.size())); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #pragma once | ||
|
|
||
| #include "config.h" | ||
|
|
||
| #if USE_AVRO && USE_SSL && USE_AWS_S3 | ||
|
|
||
| #include <Core/Types.h> | ||
| #include <IO/HTTPHeaderEntries.h> | ||
| #include <Poco/URI.h> | ||
|
|
||
| namespace Aws::Client | ||
| { | ||
| class AWSAuthV4Signer; | ||
| } | ||
|
|
||
| namespace DataLake | ||
| { | ||
|
|
||
| /// Sign a Poco-style HTTP request using the AWS SDK's AWSAuthV4Signer. | ||
| /// Builds a temporary Aws::Http::StandardHttpRequest, signs it, then extracts | ||
| /// the resulting headers into out_headers (excluding Host; ReadWriteBufferFromHTTP sets it from the URI). | ||
| void signRequestWithAWSV4( | ||
| const String & method, | ||
| const Poco::URI & uri, | ||
| const DB::HTTPHeaderEntries & extra_headers, | ||
| const String & payload, | ||
| Aws::Client::AWSAuthV4Signer & signer, | ||
| const String & region, | ||
| const String & service, | ||
| DB::HTTPHeaderEntries & out_headers); | ||
|
|
||
| } | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Perhaps name it like
signHeadersas the output of this method is a list of headers and not a request?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The request body is also signed