2222#include < functional>
2323#include < memory>
2424#include < string>
25+ #include < utility>
2526#include < vector>
2627
2728#include " paimon/result.h"
@@ -151,7 +152,7 @@ class PAIMON_EXPORT BasicFileStatus {
151152 virtual std::string GetPath () const = 0;
152153};
153154
154- // / Extended file status information interface .
155+ // / Extended file status information.
155156// /
156157// / This class extends BasicFileStatus to provide comprehensive file system metadata including file
157158// / size, modification time, and other attributes. It's used for operations that require detailed
@@ -161,21 +162,45 @@ class PAIMON_EXPORT FileStatus {
161162 FileStatus () = default ;
162163 virtual ~FileStatus () = default ;
163164
165+ // / Sentinel returned by `GetModificationTime()` when the modification time is not known.
166+ static constexpr int64_t kUnknownModificationTime = -1 ;
167+
168+ // / Create a file status from caller-supplied metadata.
169+ // / @param path The path of the file or directory.
170+ // / @param length The size of the file in bytes. It may be negative only when the size is
171+ // / unknown.
172+ // / @param is_dir Whether the path represents a directory. Defaults to false.
173+ FileStatus (std::string path, int64_t length, bool is_dir = false )
174+ : path_(std::move(path)), length_(length), is_dir_(is_dir) {}
175+
164176 // / Get the size of the file in bytes.
165177 // / @note For directories, this method is undefined behavior.
166- virtual int64_t GetLen () const = 0;
178+ virtual int64_t GetLen () const {
179+ return length_;
180+ }
167181
168182 // / Check if this entry represents a directory.
169- virtual bool IsDir () const = 0;
183+ virtual bool IsDir () const {
184+ return is_dir_;
185+ }
170186
171187 // / Get the path of this file or directory.
172- virtual std::string GetPath () const = 0;
188+ virtual std::string GetPath () const {
189+ return path_;
190+ }
173191
174192 // / Get the last modification time of the file.
175193 // /
176194 // / @return A long value representing the time the file was last modified, measured in
177195 // / milliseconds since the epoch (UTC January 1, 1970).
178- virtual int64_t GetModificationTime () const = 0;
196+ virtual int64_t GetModificationTime () const {
197+ return kUnknownModificationTime ;
198+ }
199+
200+ private:
201+ std::string path_;
202+ int64_t length_ = -1 ;
203+ bool is_dir_ = false ;
179204};
180205
181206// / Abstract file system interface.
@@ -193,6 +218,24 @@ class PAIMON_EXPORT FileSystem {
193218 // / failure (e.g., file not found, permission denied).
194219 virtual Result<std::unique_ptr<InputStream>> Open (const std::string& path) const = 0;
195220
221+ // / Open an existing regular file for reading with known file metadata.
222+ // / @param file_status The trusted status of the file to open. Its path and length must
223+ // / identify an existing regular file. Its length must be non-negative;
224+ // / zero is valid for an empty file.
225+ // / @return Result containing a unique pointer to `InputStream` on success, or error status on
226+ // / failure (e.g., invalid file size, file not found, permission denied).
227+ // / @note File systems may rely on `file_status` to skip metadata requests. The caller must
228+ // / not expect this method to validate the path, file type, or size. A stale or
229+ // / incorrect status, or a file removed after planning, can cause reads to end early or
230+ // / fail when read instead of failing at open time. Wrapping file systems should forward
231+ // / both `Open` overloads.
232+ virtual Result<std::unique_ptr<InputStream>> Open (const FileStatus& file_status) const {
233+ if (file_status.GetLen () < 0 ) {
234+ return Status::Invalid (" file size must be non-negative" );
235+ }
236+ return Open (file_status.GetPath ());
237+ }
238+
196239 // / Create a new file for writing.
197240 // / @param path The file path to create.
198241 // / @param overwrite If true, overwrite existing file; if false, fail if file exists.
0 commit comments