Skip to content

Commit 9bf3b2f

Browse files
authored
feat(fs): support int64 file IO sizes (alibaba#326)
1 parent 766a498 commit 9bf3b2f

96 files changed

Lines changed: 644 additions & 629 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/paimon/fs/file_system.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class PAIMON_EXPORT InputStream : public Stream {
7373
/// @return Result containing the actual number of bytes read on success, or an error status on
7474
/// failure.
7575
/// @note The stream position advances by the number of bytes actually read.
76-
virtual Result<int32_t> Read(char* buffer, uint32_t size) = 0;
76+
virtual Result<int64_t> Read(char* buffer, int64_t size) = 0;
7777

7878
/// Read data from given position in the stream.
7979
///
@@ -83,7 +83,7 @@ class PAIMON_EXPORT InputStream : public Stream {
8383
/// @param[out] buffer The buffer to store the read content.
8484
/// @param size The number of bytes to read.
8585
/// @param offset The position in the stream to read from.
86-
virtual Result<int32_t> Read(char* buffer, uint32_t size, uint64_t offset) = 0;
86+
virtual Result<int64_t> Read(char* buffer, int64_t size, int64_t offset) = 0;
8787

8888
/// Asynchronously read data from the input stream.
8989
///
@@ -98,7 +98,7 @@ class PAIMON_EXPORT InputStream : public Stream {
9898
/// @param callback The callback function to be invoked upon completion of the read operation.
9999
/// The callback will receive a Status object indicating the success or failure
100100
/// of the read operation.
101-
virtual void ReadAsync(char* buffer, uint32_t size, uint64_t offset,
101+
virtual void ReadAsync(char* buffer, int64_t size, int64_t offset,
102102
std::function<void(Status)>&& callback) = 0;
103103

104104
/// Get an identifier that uniquely identify the underlying content.
@@ -107,7 +107,7 @@ class PAIMON_EXPORT InputStream : public Stream {
107107
virtual Result<std::string> GetUri() const = 0;
108108

109109
/// Get the total length of the file in bytes.
110-
virtual Result<uint64_t> Length() const = 0;
110+
virtual Result<int64_t> Length() const = 0;
111111
};
112112

113113
/// Abstract class for output stream operations.
@@ -121,7 +121,7 @@ class PAIMON_EXPORT OutputStream : public Stream {
121121
/// @return Result containing the actual number of bytes written on success, or an error status
122122
/// on failure.
123123
/// @note The stream position advances by the number of bytes actually written.
124-
virtual Result<int32_t> Write(const char* buffer, uint32_t size) = 0;
124+
virtual Result<int64_t> Write(const char* buffer, int64_t size) = 0;
125125

126126
/// Flush pending data to the disk.
127127
virtual Status Flush() = 0;
@@ -160,7 +160,7 @@ class PAIMON_EXPORT FileStatus {
160160

161161
/// Get the size of the file in bytes.
162162
/// @note For directories, this method is undefined behavior.
163-
virtual uint64_t GetLen() const = 0;
163+
virtual int64_t GetLen() const = 0;
164164

165165
/// Check if this entry represents a directory.
166166
virtual bool IsDir() const = 0;

include/paimon/io/buffered_input_stream.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class PAIMON_EXPORT BufferedInputStream : public InputStream {
4242
/// @param in The underlying input stream to wrap.
4343
/// @param buffer_size Size of the internal buffer in bytes.
4444
/// @param pool Memory pool for buffer allocation.
45-
BufferedInputStream(const std::shared_ptr<InputStream>& in, int32_t buffer_size,
45+
BufferedInputStream(const std::shared_ptr<InputStream>& in, int64_t buffer_size,
4646
MemoryPool* pool);
4747

4848
~BufferedInputStream() noexcept override;
@@ -51,36 +51,36 @@ class PAIMON_EXPORT BufferedInputStream : public InputStream {
5151

5252
Result<int64_t> GetPos() const override;
5353

54-
Result<int32_t> Read(char* buffer, uint32_t size) override;
54+
Result<int64_t> Read(char* buffer, int64_t size) override;
5555

56-
Result<int32_t> Read(char* buffer, uint32_t size, uint64_t offset) override;
56+
Result<int64_t> Read(char* buffer, int64_t size, int64_t offset) override;
5757

58-
void ReadAsync(char* buffer, uint32_t size, uint64_t offset,
58+
void ReadAsync(char* buffer, int64_t size, int64_t offset,
5959
std::function<void(Status)>&& callback) override;
6060

61-
Result<uint64_t> Length() const override;
61+
Result<int64_t> Length() const override;
6262

6363
Status Close() override;
6464

6565
Result<std::string> GetUri() const override;
6666

67-
static constexpr int32_t DEFAULT_BUFFER_SIZE = 8192;
67+
static constexpr int64_t DEFAULT_BUFFER_SIZE = 8192;
6868

6969
private:
7070
/// Fill the internal buffer from the underlying stream.
7171
Status Fill();
7272

7373
/// Internal read implementation.
7474
/// @pre size > 0
75-
Result<int32_t> InnerRead(char* buffer, int32_t size);
75+
Result<int64_t> InnerRead(char* buffer, int64_t size);
7676

7777
/// Validate that the expected number of bytes were read.
78-
Status AssertReadLength(int32_t read_length, int32_t actual_read_length) const;
78+
Status AssertReadLength(int64_t read_length, int64_t actual_read_length) const;
7979

8080
private:
81-
int32_t buffer_size_;
82-
int32_t pos_ = 0;
83-
int32_t count_ = 0;
81+
int64_t buffer_size_;
82+
int64_t pos_ = 0;
83+
int64_t count_ = 0;
8484
std::unique_ptr<Bytes> buffer_;
8585
std::shared_ptr<InputStream> in_;
8686
};

include/paimon/io/byte_array_input_stream.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace paimon {
2929
/// Input stream for memory buffer, inherits from `InputStream`.
3030
class PAIMON_EXPORT ByteArrayInputStream : public InputStream {
3131
public:
32-
ByteArrayInputStream(const char* buffer, uint64_t length);
32+
ByteArrayInputStream(const char* buffer, int64_t length);
3333
~ByteArrayInputStream() override = default;
3434

3535
/// @return The raw data pointer of current pos.
@@ -41,14 +41,14 @@ class PAIMON_EXPORT ByteArrayInputStream : public InputStream {
4141
return position_;
4242
}
4343

44-
Result<int32_t> Read(char* buffer, uint32_t size) override;
44+
Result<int64_t> Read(char* buffer, int64_t size) override;
4545

46-
Result<int32_t> Read(char* buffer, uint32_t size, uint64_t offset) override;
46+
Result<int64_t> Read(char* buffer, int64_t size, int64_t offset) override;
4747

48-
void ReadAsync(char* buffer, uint32_t size, uint64_t offset,
48+
void ReadAsync(char* buffer, int64_t size, int64_t offset,
4949
std::function<void(Status)>&& callback) override;
5050

51-
Result<uint64_t> Length() const override {
51+
Result<int64_t> Length() const override {
5252
return length_;
5353
}
5454

@@ -58,7 +58,7 @@ class PAIMON_EXPORT ByteArrayInputStream : public InputStream {
5858

5959
private:
6060
const char* buffer_;
61-
const uint64_t length_;
61+
const int64_t length_;
6262
int64_t position_;
6363
};
6464
} // namespace paimon

include/paimon/io/data_input_stream.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class PAIMON_EXPORT DataInputStream {
5555
/// Read raw data of specified size from the stream.
5656
/// @param data Buffer to store the read data.
5757
/// @param size Number of bytes to read.
58-
Status Read(char* data, uint32_t size) const;
58+
Status Read(char* data, int64_t size) const;
5959

6060
/// Read string from the stream.
6161
/// @note First read length (int16), then read string bytes.
@@ -65,7 +65,7 @@ class PAIMON_EXPORT DataInputStream {
6565
Result<int64_t> GetPos() const;
6666

6767
/// Get the total length of the underlying input stream.
68-
Result<uint64_t> Length() const;
68+
Result<int64_t> Length() const;
6969

7070
/// Set the byte order for endianness conversion.
7171
/// @param order The byte order to use `PAIMON_BIG_ENDIAN` or `PAIMON_LITTLE_ENDIAN`.
@@ -77,11 +77,11 @@ class PAIMON_EXPORT DataInputStream {
7777
/// Validate that the expected number of bytes were read.
7878
/// @param read_length Expected number of bytes to read.
7979
/// @param actual_read_length Actual number of bytes read.
80-
Status AssertReadLength(int32_t read_length, int32_t actual_read_length) const;
80+
Status AssertReadLength(int64_t read_length, int64_t actual_read_length) const;
8181

8282
/// Check if there are enough bytes available to read.
8383
/// @param need_length Number of bytes needed.
84-
Status AssertBoundary(int32_t need_length) const;
84+
Status AssertBoundary(int64_t need_length) const;
8585

8686
/// Determine if byte swapping is needed based on current byte order and system endianness.
8787
/// @return `true` if byte swapping is required, `false` otherwise.

include/paimon/memory/bytes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class PAIMON_EXPORT Bytes {
7878
/// @param length Number of bytes to allocate.
7979
/// @param pool Memory pool to use for allocation.
8080
/// @return Unique pointer to the newly allocated Bytes object.
81-
static PAIMON_UNIQUE_PTR<Bytes> AllocateBytes(int32_t length, MemoryPool* pool);
81+
static PAIMON_UNIQUE_PTR<Bytes> AllocateBytes(size_t length, MemoryPool* pool);
8282

8383
/// Allocate a new Bytes object from string data.
8484
///

src/paimon/common/data/blob.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,20 @@ Result<std::unique_ptr<InputStream>> Blob::NewInputStream(
9494
PAIMON_ASSIGN_OR_RAISE(std::unique_ptr<InputStream> file,
9595
fs->Open(impl_->GetDescriptor()->Uri()));
9696

97-
return OffsetInputStream::Create(std::move(file), impl_->GetDescriptor()->Length(),
98-
impl_->GetDescriptor()->Offset());
97+
int64_t blob_length = impl_->GetDescriptor()->Length();
98+
int64_t blob_offset = impl_->GetDescriptor()->Offset();
99+
100+
PAIMON_ASSIGN_OR_RAISE(int64_t total_length, file->Length());
101+
if (PAIMON_UNLIKELY(blob_offset > total_length)) {
102+
return Status::Invalid(
103+
fmt::format("offset {} exceed total length {}", blob_offset, total_length));
104+
}
105+
if (blob_length == -1) {
106+
// blob_length == -1 means it's dynamic length, should read to the end
107+
blob_length = total_length - blob_offset;
108+
}
109+
110+
return OffsetInputStream::Create(std::move(file), blob_length, blob_offset, total_length);
99111
}
100112

101113
Result<PAIMON_UNIQUE_PTR<Bytes>> Blob::ToData(const std::shared_ptr<FileSystem>& fs,

src/paimon/common/data/blob_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ TEST_F(BlobTest, TestNewInputStreamWithOffsetAndLength) {
116116
ASSERT_OK_AND_ASSIGN(auto input_stream, blob->NewInputStream(file_system_));
117117
ASSERT_TRUE(input_stream);
118118

119-
ASSERT_OK_AND_ASSIGN(uint64_t length, input_stream->Length());
119+
ASSERT_OK_AND_ASSIGN(int64_t length, input_stream->Length());
120120
ASSERT_EQ(6, length);
121121

122122
// Test reading with offset and length applied
@@ -133,7 +133,7 @@ TEST_F(BlobTest, TestNewInputStreamWithDynamicLength) {
133133
ASSERT_OK_AND_ASSIGN(auto input_stream, blob->NewInputStream(file_system_));
134134
ASSERT_TRUE(input_stream);
135135

136-
ASSERT_OK_AND_ASSIGN(uint64_t length, input_stream->Length());
136+
ASSERT_OK_AND_ASSIGN(int64_t length, input_stream->Length());
137137
ASSERT_EQ(12, length);
138138

139139
// Test reading from offset to end (should read "cdefghijklmn")

src/paimon/common/data/decimal_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ TEST(DecimalTest, TestCompatibleWithJava) {
9797
auto pool = GetDefaultPool();
9898
auto file_system = std::make_unique<LocalFileSystem>();
9999
auto file_name = paimon::test::GetDataDir() + "/decimal_bytes.data";
100-
uint64_t file_length = file_system->GetFileStatus(file_name).value()->GetLen();
100+
int64_t file_length = file_system->GetFileStatus(file_name).value()->GetLen();
101101
ASSERT_GT(file_length, 0);
102102
ASSERT_OK_AND_ASSIGN(auto input_stream, file_system->Open(file_name));
103103
auto data_bytes = Bytes::AllocateBytes(file_length, pool.get());

src/paimon/common/file_index/bitmap/bitmap_file_index_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ TEST_F(BitmapIndexTest, TestHighCardinalityForCompatibility) {
623623
auto file_system = std::make_unique<LocalFileSystem>();
624624
ASSERT_OK_AND_ASSIGN(std::shared_ptr<InputStream> input_stream,
625625
file_system->Open(index_file_name));
626-
ASSERT_OK_AND_ASSIGN(uint64_t length, input_stream->Length());
626+
ASSERT_OK_AND_ASSIGN(int64_t length, input_stream->Length());
627627

628628
BitmapFileIndex file_index({});
629629
ASSERT_OK_AND_ASSIGN(auto reader, file_index.CreateReader(CreateArrowSchema(type).get(),

src/paimon/common/file_index/bloomfilter/bloom_filter_file_index.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Result<std::shared_ptr<FileIndexReader>> BloomFilterFileIndex::CreateReader(
4545

4646
PAIMON_RETURN_NOT_OK(input_stream->Seek(start, SeekOrigin::FS_SEEK_SET));
4747
auto bytes = std::make_shared<Bytes>(length, pool.get());
48-
PAIMON_ASSIGN_OR_RAISE(int32_t actual_read_len,
48+
PAIMON_ASSIGN_OR_RAISE(int64_t actual_read_len,
4949
input_stream->Read(bytes->data(), bytes->size()));
5050
if (static_cast<size_t>(actual_read_len) != bytes->size()) {
5151
return Status::Invalid(

0 commit comments

Comments
 (0)