Skip to content

Commit

Permalink
[Cpp] Pass path as output argument when BuildFileSystem (#78)
Browse files Browse the repository at this point in the history
Signed-off-by: sunby <[email protected]>
  • Loading branch information
sunby committed Oct 18, 2023
1 parent 3b03ad8 commit bef9bb3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cpp/include/milvus-storage/common/fs_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "result.h"
namespace milvus_storage {

Result<std::shared_ptr<arrow::fs::FileSystem>> BuildFileSystem(const std::string& uri);
Result<std::shared_ptr<arrow::fs::FileSystem>> BuildFileSystem(const std::string& uri, std::string* out_path = nullptr);

std::string UriToPath(const std::string& uri);

Expand Down
10 changes: 6 additions & 4 deletions cpp/src/common/fs_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
#include "common/macro.h"
namespace milvus_storage {

Result<std::shared_ptr<arrow::fs::FileSystem>> BuildFileSystem(const std::string& uri) {
Result<std::shared_ptr<arrow::fs::FileSystem>> BuildFileSystem(const std::string& uri, std::string* out_path) {
arrow::internal::Uri uri_parser;
RETURN_ARROW_NOT_OK(uri_parser.Parse(uri));
auto schema = uri_parser.scheme();
if (schema == "file") {
auto output_path = uri_parser.path();
ASSIGN_OR_RETURN_ARROW_NOT_OK(auto option, arrow::fs::LocalFileSystemOptions::FromUri(uri_parser, &output_path));
if (out_path == nullptr) {
return Status::InvalidArgument("out_path should not be nullptr if schema is file");
}
ASSIGN_OR_RETURN_ARROW_NOT_OK(auto option, arrow::fs::LocalFileSystemOptions::FromUri(uri_parser, out_path));
return std::shared_ptr<arrow::fs::FileSystem>(new arrow::fs::LocalFileSystem(option));
}

Expand All @@ -34,7 +36,7 @@ Result<std::shared_ptr<arrow::fs::FileSystem>> BuildFileSystem(const std::string
}
});
}
ASSIGN_OR_RETURN_ARROW_NOT_OK(auto option, arrow::fs::S3Options::FromUri(uri_parser));
ASSIGN_OR_RETURN_ARROW_NOT_OK(auto option, arrow::fs::S3Options::FromUri(uri_parser, out_path));
ASSIGN_OR_RETURN_ARROW_NOT_OK(auto fs, arrow::fs::S3FileSystem::Make(option));

return std::shared_ptr<arrow::fs::FileSystem>(fs);
Expand Down
6 changes: 2 additions & 4 deletions cpp/src/storage/space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,9 @@ Result<std::unique_ptr<Space>> Space::Open(const std::string& uri, Options optio
std::string path;
std::atomic_int64_t next_manifest_version = 1;

ASSIGN_OR_RETURN_NOT_OK(fs, BuildFileSystem(uri));
arrow::internal::Uri uri_parser;
RETURN_ARROW_NOT_OK(uri_parser.Parse(uri));
path = uri_parser.path();
ASSIGN_OR_RETURN_NOT_OK(fs, BuildFileSystem(uri, &path));

LOG_STORAGE_INFO_ << "Open space: " << path;
RETURN_ARROW_NOT_OK(fs->CreateDir(GetManifestDir(path)));
RETURN_ARROW_NOT_OK(fs->CreateDir(GetScalarDataDir(path)));
RETURN_ARROW_NOT_OK(fs->CreateDir(GetVectorDataDir(path)));
Expand Down
3 changes: 2 additions & 1 deletion cpp/test/multi_files_sequential_reader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ TEST(MultiFilesSeqReaderTest, ReadTest) {
ASSERT_STATUS_OK(pk_builder.Finish(&pk_array));
auto rec_batch = arrow::RecordBatch::Make(arrow_schema, 3, {pk_array});

ASSERT_AND_ASSIGN(auto fs, BuildFileSystem("file:///tmp/"));
std::string path;
ASSERT_AND_ASSIGN(auto fs, BuildFileSystem("file:///tmp/", &path));
ASSERT_AND_ARROW_ASSIGN(auto f1, fs->OpenOutputStream("/tmp/file1"));
ASSERT_AND_ARROW_ASSIGN(auto w1, parquet::arrow::FileWriter::Open(*arrow_schema, arrow::default_memory_pool(), f1));
ASSERT_STATUS_OK(w1->WriteRecordBatch(*rec_batch));
Expand Down

0 comments on commit bef9bb3

Please sign in to comment.