diff --git a/velox/connectors/hive/storage_adapters/abfs/AbfsPath.cpp b/velox/connectors/hive/storage_adapters/abfs/AbfsPath.cpp index b6ba75cbcbfe..66a372cd70a4 100644 --- a/velox/connectors/hive/storage_adapters/abfs/AbfsPath.cpp +++ b/velox/connectors/hive/storage_adapters/abfs/AbfsPath.cpp @@ -14,6 +14,9 @@ * limitations under the License. */ +#include +#include + #include "velox/connectors/hive/storage_adapters/abfs/AbfsPath.h" #include "velox/connectors/hive/storage_adapters/abfs/AbfsUtil.h" @@ -32,9 +35,12 @@ AbfsPath::AbfsPath(std::string_view path) { } auto firstAt = file.find_first_of("@"); - fileSystem_ = file.substr(0, firstAt); + fileSystem_ = Azure::Storage::_internal::UrlEncodePath( + Azure::Core::Url::Decode(std::string(file.substr(0, firstAt)))); auto firstSep = file.find_first_of("/"); - filePath_ = file.substr(firstSep + 1); + filePath_ = Azure::Storage::_internal::UrlEncodePath( + Azure::Core::Url::Decode(std::string(file.substr(firstSep + 1)))); + accountNameWithSuffix_ = file.substr(firstAt + 1, firstSep - firstAt - 1); auto firstDot = accountNameWithSuffix_.find_first_of("."); accountName_ = accountNameWithSuffix_.substr(0, firstDot); @@ -49,6 +55,7 @@ std::string AbfsPath::getUrl(bool withblobSuffix) const { accountNameWithSuffixForUrl.replace(startPos, 3, "blob"); } } + return fmt::format( "{}{}/{}/{}", isHttps_ ? "https://" : "http://", diff --git a/velox/connectors/hive/storage_adapters/abfs/tests/AbfsPathTest.cpp b/velox/connectors/hive/storage_adapters/abfs/tests/AbfsPathTest.cpp new file mode 100644 index 000000000000..33442878d875 --- /dev/null +++ b/velox/connectors/hive/storage_adapters/abfs/tests/AbfsPathTest.cpp @@ -0,0 +1,38 @@ +/* + * 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/AbfsPath.h" +#include "velox/connectors/hive/storage_adapters/abfs/AbfsUtil.h" + +#include "gtest/gtest.h" + +using namespace facebook::velox::filesystems; + +TEST(AbfsPathTest, encodedPath) { + auto abfssAccountWithSpecialCharacters = AbfsPath( + "abfss://testc@test.dfs.core.windows.net/main@dir/brand#51/sub dir/test.txt"); + EXPECT_EQ( + abfssAccountWithSpecialCharacters.accountNameWithSuffix(), + "test.dfs.core.windows.net"); + EXPECT_EQ(abfssAccountWithSpecialCharacters.accountName(), "test"); + EXPECT_EQ(abfssAccountWithSpecialCharacters.fileSystem(), "testc"); + EXPECT_EQ( + abfssAccountWithSpecialCharacters.filePath(), + "main@dir/brand#51/sub dir/test.txt"); + EXPECT_EQ( + abfssAccountWithSpecialCharacters.getUrl(true), + "https://test.blob.core.windows.net/testc/main@dir/brand%2351/sub%20dir/test.txt"); +} diff --git a/velox/connectors/hive/storage_adapters/abfs/tests/CMakeLists.txt b/velox/connectors/hive/storage_adapters/abfs/tests/CMakeLists.txt index c81471db9f68..9365ebc7cc12 100644 --- a/velox/connectors/hive/storage_adapters/abfs/tests/CMakeLists.txt +++ b/velox/connectors/hive/storage_adapters/abfs/tests/CMakeLists.txt @@ -16,6 +16,7 @@ add_executable( velox_abfs_test AbfsFileSystemTest.cpp AbfsUtilTest.cpp + AbfsPathTest.cpp AzureClientProvidersTest.cpp AzureClientProviderFactoriesTest.cpp DynamicSasTokenClientProviderTest.cpp