Skip to content

Commit 7f0e5d8

Browse files
authored
apacheGH-46982: [C++] Remove Boost dependency from hdfs_test (apache#47200)
### Rationale for this change resolve apache#46982 ### What changes are included in this PR? remove boost dependency from hdfs_test ### Are these changes tested? partially, not tested with hdfs ### Are there any user-facing changes? no * GitHub Issue: apache#46982 Authored-by: egolearner <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
1 parent 6ee27d4 commit 7f0e5d8

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

cpp/src/arrow/io/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ if(ARROW_HDFS)
2828
PREFIX
2929
"arrow-io"
3030
EXTRA_LINK_LIBS
31-
arrow::hadoop
32-
Boost::filesystem
33-
Boost::system)
31+
arrow::hadoop)
3432
endif()
3533

3634
add_arrow_test(memory_test PREFIX "arrow-io")

cpp/src/arrow/io/hdfs_test.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <cstdint>
2020
#include <cstdlib>
2121
#include <cstring>
22+
#include <filesystem>
2223
#include <iostream>
2324
#include <memory>
2425
#include <sstream> // IWYU pragma: keep
@@ -36,11 +37,6 @@
3637
#include "arrow/testing/gtest_util.h"
3738
#include "arrow/testing/util.h"
3839

39-
// boost/filesystem.hpp should be included after
40-
// arrow/util/windows_compatibility.h because boost/filesystem.hpp
41-
// includes windows.h implicitly.
42-
#include <boost/filesystem.hpp> // NOLINT
43-
4440
namespace arrow {
4541
namespace io {
4642

@@ -90,9 +86,12 @@ class TestHadoopFileSystem : public ::testing::Test {
9086

9187
client_ = nullptr;
9288
scratch_dir_ =
93-
boost::filesystem::unique_path(boost::filesystem::temp_directory_path() /
94-
"arrow-hdfs/scratch-%%%%")
95-
.string();
89+
(std::filesystem::temp_directory_path() / "arrow-hdfs/scratch-").string();
90+
int random_size = 4;
91+
scratch_dir_.resize(scratch_dir_.size() + random_size, '%');
92+
random_alnum(
93+
random_size, 0,
94+
reinterpret_cast<uint8_t*>(&scratch_dir_[scratch_dir_.size() - random_size]));
9695

9796
loaded_driver_ = false;
9897

cpp/src/arrow/testing/util.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ void random_ascii(int64_t n, uint32_t seed, uint8_t* out) {
9090
rand_uniform_int(n, seed, static_cast<int32_t>('A'), static_cast<int32_t>('z'), out);
9191
}
9292

93+
void random_alnum(int64_t n, uint32_t seed, uint8_t* out) {
94+
static const char charset[] =
95+
"0123456789"
96+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
97+
"abcdefghijklmnopqrstuvwxyz";
98+
pcg32_fast gen(seed);
99+
std::uniform_int_distribution<uint32_t> d(0, sizeof(charset) - 2);
100+
std::generate(out, out + n, [&d, &gen] { return charset[d(gen)]; });
101+
}
102+
93103
int64_t CountNulls(const std::vector<uint8_t>& valid_bytes) {
94104
return static_cast<int64_t>(std::count(valid_bytes.cbegin(), valid_bytes.cend(), '\0'));
95105
}

cpp/src/arrow/testing/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ ARROW_TESTING_EXPORT void random_bytes(int64_t n, uint32_t seed, uint8_t* out);
6464
ARROW_TESTING_EXPORT std::string random_string(int64_t n, uint32_t seed);
6565
ARROW_TESTING_EXPORT int32_t DecimalSize(int32_t precision);
6666
ARROW_TESTING_EXPORT void random_ascii(int64_t n, uint32_t seed, uint8_t* out);
67+
ARROW_TESTING_EXPORT void random_alnum(int64_t n, uint32_t seed, uint8_t* out);
6768
ARROW_TESTING_EXPORT int64_t CountNulls(const std::vector<uint8_t>& valid_bytes);
6869

6970
ARROW_TESTING_EXPORT Status MakeRandomByteBuffer(int64_t length, MemoryPool* pool,

0 commit comments

Comments
 (0)