lidavidm commented on code in PR #49897:
URL: https://github.com/apache/arrow/pull/49897#discussion_r3164920167
##########
cpp/src/arrow/io/interfaces.h:
##########
@@ -279,24 +280,56 @@ class ARROW_EXPORT RandomAccessFile : public InputStream,
public Seekable {
///
/// \param[in] position Where to read bytes from
/// \param[in] nbytes The number of bytes to read
+ /// \param[in] allow_short_read Whether to allow reading less than `nbytes`
+ /// \param[out] out The buffer to read bytes into
+ /// \return The number of bytes read, or an error
+ virtual Result<int64_t> ReadAt(int64_t position, int64_t nbytes, bool
allow_short_read,
+ void* out);
+
+ /// \brief Read data from given file position.
+ ///
+ /// Like `ReadAt(position, nbytes, allow_short_read, out)` with
`allow_short_read`
+ /// set to true.
Review Comment:
I wonder if we should deprecate these overloads over time (it feels like it
would be safer to have `allow_short_read` be the opt-in rather than opt-out
behavior at least)
##########
cpp/src/arrow/io/interfaces.cc:
##########
@@ -149,38 +149,73 @@ RandomAccessFile::~RandomAccessFile() = default;
RandomAccessFile::RandomAccessFile() : interface_impl_(new Impl()) {}
+Result<int64_t> RandomAccessFile::ReadAt(int64_t position, int64_t nbytes,
+ bool allow_short_read, void* out) {
+ ARROW_ASSIGN_OR_RAISE(auto real_nbytes, ReadAt(position, nbytes, out));
+ if (!allow_short_read && real_nbytes != nbytes) {
+ return Status::IOError("File too short: expected to be able to read ",
nbytes,
+ " bytes, got ", real_nbytes);
+ }
+ return real_nbytes;
+}
+
Result<int64_t> RandomAccessFile::ReadAt(int64_t position, int64_t nbytes,
void* out) {
std::lock_guard<std::mutex> lock(interface_impl_->lock_);
RETURN_NOT_OK(Seek(position));
return Read(nbytes, out);
}
+Result<std::shared_ptr<Buffer>> RandomAccessFile::ReadAt(int64_t position,
int64_t nbytes,
+ bool
allow_short_read) {
+ ARROW_ASSIGN_OR_RAISE(auto buffer, ReadAt(position, nbytes));
+ // XXX the internal `IoRecordedRandomAccessFile` can return a null buffer
+ if (!allow_short_read && buffer && buffer->size() != nbytes) {
+ return Status::IOError("File too short: expected to be able to read ",
nbytes,
+ " bytes, got ", buffer->size());
+ }
Review Comment:
If the buffer is null and nbytes is > 0 then we should also fail right? Or
is it only possible for nbytes == 0 in the first place?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]