-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ABFS implementation (#11419)
Summary: Combine AbfsAccount and AbfsConfig in a separate file. Clean up API naming and clarify semantics. Add a new constructor for AbfsWriteFile to specify a client. This is used for testing. Pull Request resolved: #11419 Reviewed By: Yuhta Differential Revision: D66015694 Pulled By: kevinwilfong fbshipit-source-id: 7224aaa1e3cda99c1596546e8050676c635396a5
- Loading branch information
1 parent
ce67924
commit 7d0b84e
Showing
23 changed files
with
500 additions
and
625 deletions.
There are no files selected for viewing
This file contains 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
68 changes: 68 additions & 0 deletions
68
velox/connectors/hive/storage_adapters/abfs/AbfsConfig.cpp
This file contains 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,68 @@ | ||
/* | ||
* 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/hive/storage_adapters/abfs/AbfsConfig.h" | ||
|
||
#include "velox/common/config/Config.h" | ||
#include "velox/connectors/hive/storage_adapters/abfs/AbfsUtil.h" | ||
|
||
namespace facebook::velox::filesystems { | ||
|
||
AbfsConfig::AbfsConfig( | ||
std::string_view path, | ||
const config::ConfigBase& config) { | ||
std::string_view file; | ||
bool isHttps = true; | ||
if (path.find(kAbfssScheme) == 0) { | ||
file = path.substr(kAbfssScheme.size()); | ||
} else if (path.find(kAbfsScheme) == 0) { | ||
file = path.substr(kAbfsScheme.size()); | ||
isHttps = false; | ||
} else { | ||
VELOX_FAIL("Invalid ABFS Path {}", path); | ||
} | ||
|
||
auto firstAt = file.find_first_of("@"); | ||
fileSystem_ = file.substr(0, firstAt); | ||
auto firstSep = file.find_first_of("/"); | ||
filePath_ = file.substr(firstSep + 1); | ||
|
||
auto accountNameWithSuffix = file.substr(firstAt + 1, firstSep - firstAt - 1); | ||
auto firstDot = accountNameWithSuffix.find_first_of("."); | ||
auto accountName = accountNameWithSuffix.substr(0, firstDot); | ||
auto endpointSuffix = accountNameWithSuffix.substr(firstDot + 5); | ||
auto credKey = fmt::format("fs.azure.account.key.{}", accountNameWithSuffix); | ||
std::stringstream ss; | ||
ss << "DefaultEndpointsProtocol=" << (isHttps ? "https" : "http"); | ||
ss << ";AccountName=" << accountName; | ||
|
||
if (config.valueExists(credKey)) { | ||
ss << ";AccountKey=" << config.get<std::string>(credKey).value(); | ||
} else { | ||
VELOX_USER_FAIL("Config {} not found", credKey); | ||
} | ||
|
||
ss << ";EndpointSuffix=" << endpointSuffix; | ||
|
||
if (config.valueExists(kAzureBlobEndpoint)) { | ||
ss << ";BlobEndpoint=" | ||
<< config.get<std::string>(kAzureBlobEndpoint).value(); | ||
} | ||
ss << ";"; | ||
connectionString_ = ss.str(); | ||
} | ||
|
||
} // namespace facebook::velox::filesystems |
This file contains 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,59 @@ | ||
/* | ||
* 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 <folly/hash/Hash.h> | ||
#include <string> | ||
|
||
namespace facebook::velox::config { | ||
class ConfigBase; | ||
} | ||
|
||
namespace facebook::velox::filesystems { | ||
|
||
// This is used to specify the Azurite endpoint in testing. | ||
static std::string kAzureBlobEndpoint{"fs.azure.blob-endpoint"}; | ||
|
||
class AbfsConfig { | ||
public: | ||
explicit AbfsConfig(std::string_view path, const config::ConfigBase& config); | ||
|
||
std::string identity() const { | ||
const auto hash = folly::Hash(); | ||
return std::to_string(hash(connectionString_)); | ||
} | ||
|
||
std::string connectionString() const { | ||
return connectionString_; | ||
} | ||
|
||
std::string fileSystem() const { | ||
return fileSystem_; | ||
} | ||
|
||
std::string filePath() const { | ||
return filePath_; | ||
} | ||
|
||
private: | ||
// Container name is called FileSystem in some Azure API. | ||
std::string fileSystem_; | ||
std::string filePath_; | ||
std::string connectionString_; | ||
}; | ||
|
||
} // namespace facebook::velox::filesystems |
This file contains 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 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 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.