forked from facebookincubator/velox
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(clp-connector): Add config to support searching archives from S3. #21
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
Merged
anlowee
merged 17 commits into
y-scope:presto-0.293-clp-connector
from
anlowee:xwei/s3-config
Aug 12, 2025
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7f56b8b
WIP
anlowee e1f1933
Init
anlowee 0e1aded
Format
anlowee 07b1488
Add config parse unit test
anlowee 32c31fb
Format
anlowee 2a27297
Address coderabbitai comments
anlowee ccce2d6
Address coderabbitai comments to add a environment guard in unit test
anlowee 1f10099
Fix unit tests
anlowee 69aac77
Merge branch 'presto-0.293-clp-connector' into xwei/s3-config
anlowee 2cc2e52
Apply suggestions from code review
anlowee a23915b
Fix unit tests
anlowee e1275a4
Merge branch 'xwei/s3-config' of github.com:anlowee/velox into xwei/s…
anlowee a3f155d
Address comments
anlowee 44caed7
Address coderabbitai comment
anlowee bc60f10
Add docs
anlowee 7e62d41
Fix the bug that when the storage-type is FS the s3-auth-provider is …
anlowee 838ab7f
Address some of coderabbitai comments
anlowee 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
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
56 changes: 56 additions & 0 deletions
56
velox/connectors/clp/search_lib/ClpPackageS3AuthProvider.cpp
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,56 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "velox/connectors/clp/search_lib/ClpPackageS3AuthProvider.h" | ||
#include "velox/common/base/Exceptions.h" | ||
#include "velox/common/config/Config.h" | ||
|
||
namespace facebook::velox::connector::clp { | ||
|
||
std::string ClpPackageS3AuthProvider::constructS3Url( | ||
std::string_view splitPath) { | ||
VELOX_CHECK(!splitPath.empty(), "splitPath cannot be empty"); | ||
return fmt::format("{}/{}", this->endPoint_, splitPath); | ||
} | ||
|
||
bool ClpPackageS3AuthProvider::exportAuthEnvironmentVariables() { | ||
this->endPoint_ = config_->get<std::string>(kEndPoint, ""); | ||
VELOX_CHECK( | ||
!this->endPoint_.empty(), fmt::format("{} cannot be empty", kEndPoint)); | ||
if ('/' == this->endPoint_.back()) { | ||
this->endPoint_.pop_back(); | ||
} | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
auto accessKeyId = config_->get<std::string>(kAccessKeyId, ""); | ||
auto secretAccessKey = config_->get<std::string>(kSecretAccessKey, ""); | ||
auto sessionToken = config_->get<std::string>(kSessionToken, ""); | ||
VELOX_CHECK( | ||
!accessKeyId.empty(), fmt::format("{} cannot be empty", kAccessKeyId)); | ||
VELOX_CHECK( | ||
!secretAccessKey.empty(), | ||
fmt::format("{} cannot be empty", kSecretAccessKey)); | ||
setEnvironmentVariable(kEnvAwsAccessKeyId, accessKeyId); | ||
setEnvironmentVariable(kEnvAwsSecretAccessKey, secretAccessKey); | ||
if (!sessionToken.empty()) { | ||
setEnvironmentVariable(kEnvAwsSessionToken, sessionToken); | ||
} else { | ||
unsetEnvironmentVariable(kEnvAwsSessionToken); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} // namespace facebook::velox::connector::clp |
50 changes: 50 additions & 0 deletions
50
velox/connectors/clp/search_lib/ClpPackageS3AuthProvider.h
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,50 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "velox/connectors/clp/search_lib/ClpS3AuthProviderBase.h" | ||
|
||
namespace facebook::velox::config { | ||
class ConfigBase; | ||
} // namespace facebook::velox::config | ||
anlowee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
namespace facebook::velox::connector::clp { | ||
|
||
class ClpPackageS3AuthProvider : public ClpS3AuthProviderBase { | ||
public: | ||
explicit ClpPackageS3AuthProvider( | ||
std::shared_ptr<const config::ConfigBase> config) | ||
: ClpS3AuthProviderBase(config) {} | ||
|
||
static constexpr const char* kAccessKeyId = "clp.s3-access-key-id"; | ||
static constexpr const char* kEndPoint = "clp.s3-end-point"; | ||
static constexpr const char* kSecretAccessKey = "clp.s3-secret-access-key"; | ||
static constexpr const char* kSessionToken = "clp.s3-session-token"; | ||
|
||
static constexpr const char* kEnvAwsAccessKeyId = "AWS_ACCESS_KEY_ID"; | ||
static constexpr const char* kEnvAwsSecretAccessKey = "AWS_SECRET_ACCESS_KEY"; | ||
static constexpr const char* kEnvAwsSessionToken = "AWS_SESSION_TOKEN"; | ||
anlowee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
std::string constructS3Url(std::string_view splitPath) override; | ||
|
||
bool exportAuthEnvironmentVariables() override; | ||
|
||
private: | ||
std::string endPoint_; | ||
}; | ||
|
||
} // namespace facebook::velox::connector::clp |
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,73 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <cstdlib> | ||
#include <cstring> | ||
|
||
#include "velox/common/base/Exceptions.h" | ||
#include "velox/connectors/clp/search_lib/ClpS3AuthProviderBase.h" | ||
|
||
namespace facebook::velox::config { | ||
class ConfigBase; | ||
} // namespace facebook::velox::config | ||
|
||
namespace facebook::velox::connector::clp { | ||
|
||
void ClpS3AuthProviderBase::setEnvironmentVariable( | ||
std::string_view key, | ||
std::string_view value) { | ||
int err{0}; | ||
const auto keyStr = std::string(key); | ||
const auto* keyCStr = keyStr.c_str(); | ||
const auto valueStr = std::string(value); | ||
const auto* valueCStr = valueStr.c_str(); | ||
#ifdef _WIN32 | ||
// Windows version | ||
err = _putenv_s(keyCStr, valueCStr); | ||
#elif defined(__unix__) || defined(__APPLE__) | ||
// Unix/macOS version | ||
err = setenv(keyCStr, valueCStr, 1); | ||
#else | ||
VELOX_UNSUPPORTED("Unsupported OS"); | ||
#endif | ||
VELOX_CHECK_EQ(0, err); | ||
|
||
// Sanity check | ||
auto valueForCheck = std::getenv(keyCStr); | ||
VELOX_CHECK_EQ(0, std::strcmp(valueCStr, valueForCheck)); | ||
} | ||
|
||
void ClpS3AuthProviderBase::unsetEnvironmentVariable(std::string_view key) { | ||
int err{0}; | ||
const auto keyStr = std::string(key); | ||
const auto* keyCStr = keyStr.c_str(); | ||
#ifdef _WIN32 | ||
// Windows version | ||
err = _putenv(fmt::format("{}=", keyCStr)); | ||
#elif defined(__unix__) || defined(__APPLE__) | ||
// Unix/macOS version | ||
err = unsetenv(keyCStr); | ||
#else | ||
VELOX_UNSUPPORTED("Unsupported OS"); | ||
#endif | ||
VELOX_CHECK_EQ(0, err); | ||
|
||
// Sanity check | ||
auto valueForCheck = std::getenv(keyCStr); | ||
VELOX_CHECK_NULL(valueForCheck); | ||
} | ||
|
||
} // namespace facebook::velox::connector::clp |
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.
Uh oh!
There was an error while loading. Please reload this page.