github-actions[bot] commented on code in PR #31214: URL: https://github.com/apache/doris/pull/31214#discussion_r1497114662
########## be/src/io/fs/hdfs_file_system.cpp: ########## @@ -261,7 +262,37 @@ Status HdfsFileSystem::file_size_impl(const Path& path, int64_t* file_size) cons return Status::OK(); } -Status HdfsFileSystem::list_impl(const Path& path, bool only_file, std::vector<FileInfo>* files, +struct HdfsFsListGenerator final : public FsListGenerator { +public: + HdfsFsListGenerator(int numEntries, hdfsFileInfo* hdfs_file_info, bool only_file) + : numEntries(numEntries), hdfs_file_info(hdfs_file_info), only_file(only_file) {} + ~HdfsFsListGenerator() override { hdfsFreeFileInfo(hdfs_file_info, numEntries); } Review Comment: warning: use '= default' to define a trivial destructor [modernize-use-equals-default] ```cpp ~HdfsFsListGenerator() override { hdfsFreeFileInfo(hdfs_file_info, numEntries); } ^ ``` ########## be/src/io/fs/file_system.h: ########## @@ -64,6 +65,43 @@ struct FileInfo { bool is_file; }; +struct FsListGenerator { + FsListGenerator() = default; + virtual ~FsListGenerator() = default; + + virtual Status init() = 0; + + Result<FileInfo> next() { + generateNext(); + if (st.ok()) { + return std::move(file_info); + } + return ResultError(std::move(st)); + } + + Status files(std::vector<FileInfo>* files) { Review Comment: warning: method 'files' can be made const [readability-make-member-function-const] ```suggestion Status files(std::vector<FileInfo>* files) const { ``` ########## be/src/io/fs/s3_file_system.cpp: ########## @@ -312,7 +312,71 @@ Status S3FileSystem::file_size_impl(const Path& file, int64_t* file_size) const return Status::OK(); } -Status S3FileSystem::list_impl(const Path& dir, bool only_file, std::vector<FileInfo>* files, +struct S3FsListGenerator final : public FsListGenerator { +public: + S3FsListGenerator(std::shared_ptr<Aws::S3::S3Client> client, + Aws::S3::Model::ListObjectsV2Request request, bool only_file, + std::string_view prefix, std::string full_path) + : client(std::move(client)), + request(std::move(request)), + only_file(only_file), + prefix(prefix), + full_path(std::move(full_path)) {} + ~S3FsListGenerator() override = default; + + bool has_next() const override { + return !is_trucated && iter != outcome.GetResult().GetContents().end(); + } + + Status init() override { return Status::OK(); } + +private: + void generateNext() override { + while (!is_trucated && iter != outcome.GetResult().GetContents().end()) { + for (; iter != outcome.GetResult().GetContents().end(); iter++) { + const auto& obj = *iter; + std::string key = obj.GetKey(); + bool is_dir = (key.back() == '/'); + if (only_file && is_dir) { + continue; + } + file_info.file_name = obj.GetKey().substr(prefix.size()); + file_info.file_size = obj.GetSize(); + file_info.is_file = !is_dir; + return; + } + get_list_outcome(); + } + } + + void get_list_outcome() { Review Comment: warning: method 'get_list_outcome' can be made const [readability-make-member-function-const] ```suggestion void get_list_outcome() const { ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org