Skip to content

Commit

Permalink
Add ReadBufferFromFileBase::isRegularLocalFile()
Browse files Browse the repository at this point in the history
  • Loading branch information
al13n321 committed Oct 10, 2023
1 parent 68ce6b9 commit 363171e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/IO/AsynchronousReadBufferFromFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class AsynchronousReadBufferFromFile : public AsynchronousReadBufferFromFileDesc
{
return file_name;
}

bool isRegularLocalFile(size_t * /* out_view_offset */) override { return true; }
};

/** Similar to AsynchronousReadBufferFromFile but also transparently shares open file descriptors.
Expand Down Expand Up @@ -79,6 +81,8 @@ class AsynchronousReadBufferFromFileWithDescriptorsCache : public AsynchronousRe
{
return file_name;
}

bool isRegularLocalFile(size_t * /* out_view_offset */) override { return true; }
};

}
7 changes: 7 additions & 0 deletions src/IO/MMapReadBufferFromFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ std::string MMapReadBufferFromFile::getFileName() const
}


bool MMapReadBufferFromFile::isRegularLocalFile(size_t * out_view_offset)
{
*out_view_offset = mapped.getOffset();
return true;
}


MMapReadBufferFromFile::MMapReadBufferFromFile(const std::string & file_name_, size_t offset, size_t length_)
: file_name(file_name_)
{
Expand Down
2 changes: 2 additions & 0 deletions src/IO/MMapReadBufferFromFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class MMapReadBufferFromFile : public MMapReadBufferFromFileDescriptor

std::string getFileName() const override;

bool isRegularLocalFile(size_t * out_view_offset) override;

private:
int fd = -1;
std::string file_name;
Expand Down
2 changes: 2 additions & 0 deletions src/IO/MMapReadBufferFromFileWithCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class MMapReadBufferFromFileWithCache : public ReadBufferFromFileBase
std::string getFileName() const override;
off_t seek(off_t offset, int whence) override;

bool isRegularLocalFile(size_t * /* out_view_offset */) override { return true; }

private:
MMappedFileCache::MappedPtr mapped;

Expand Down
4 changes: 4 additions & 0 deletions src/IO/ReadBufferFromFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class ReadBufferFromFile : public ReadBufferFromFileDescriptor
}

size_t getFileOffsetOfBufferEnd() const override { return file_offset_of_buffer_end; }

bool isRegularLocalFile(size_t * /* out_view_offset */) override { return true; }
};


Expand Down Expand Up @@ -103,6 +105,8 @@ class ReadBufferFromFilePReadWithDescriptorsCache : public ReadBufferFromFileDes
{
return file_name;
}

bool isRegularLocalFile(size_t * /* out_view_offset */) override { return true; }
};

}
6 changes: 6 additions & 0 deletions src/IO/ReadBufferFromFileBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class ReadBufferFromFileBase : public BufferWithOwnMemory<SeekableReadBuffer>, p

void setProgressCallback(ContextPtr context);

/// Returns true if this file is on local filesystem, and getFileName() is its path.
/// I.e. it can be read using open() or mmap(). If this buffer is a "view" into a subrange of the
/// file, *out_view_offset is set to the start of that subrange, i.e. the difference between actual
/// file offset and what getPosition() returns.
virtual bool isRegularLocalFile(size_t * /* out_view_offset */ = nullptr) { return false; }

protected:
std::optional<size_t> file_size;
ProfileCallback profile_callback;
Expand Down

0 comments on commit 363171e

Please sign in to comment.