Skip to content

Commit 21854cc

Browse files
committed
Restore Block.bodyLength to long
Change-Id: I4bae06d5833ffd24f94522ad23ea2dfcc459d86b
1 parent 7c6f7ef commit 21854cc

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

format/File.fbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct Block {
4343

4444
/// Length of the data (this is aligned so there can be a gap between this and
4545
/// the metatdata).
46-
bodyLength: int;
46+
bodyLength: long;
4747
}
4848

4949
root_type Footer;

java/vector/src/main/java/org/apache/arrow/vector/file/ArrowBlock.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public class ArrowBlock implements FBSerializable {
2626

2727
private final long offset;
2828
private final int metadataLength;
29-
private final int bodyLength;
29+
private final long bodyLength;
3030

31-
public ArrowBlock(long offset, int metadataLength, int bodyLength) {
31+
public ArrowBlock(long offset, int metadataLength, long bodyLength) {
3232
super();
3333
this.offset = offset;
3434
this.metadataLength = metadataLength;
@@ -43,7 +43,7 @@ public int getMetadataLength() {
4343
return metadataLength;
4444
}
4545

46-
public int getBodyLength() {
46+
public long getBodyLength() {
4747
return bodyLength;
4848
}
4949

@@ -56,7 +56,7 @@ public int writeTo(FlatBufferBuilder builder) {
5656
public int hashCode() {
5757
final int prime = 31;
5858
int result = 1;
59-
result = prime * result + bodyLength;
59+
result = prime * result + (int) (bodyLength ^ (bodyLength >>> 32));
6060
result = prime * result + metadataLength;
6161
result = prime * result + (int) (offset ^ (offset >>> 32));
6262
return result;

java/vector/src/main/java/org/apache/arrow/vector/stream/MessageSerializer.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public static ArrowBlock serialize(WriteChannel out, ArrowRecordBatch batch)
154154
" != " + startPosition + layout.getSize());
155155
}
156156
}
157-
return new ArrowBlock(batchStart, metadataSize, (int)(out.getCurrentPosition() - bufferStart));
157+
return new ArrowBlock(batchStart, metadataSize, out.getCurrentPosition() - bufferStart);
158158
}
159159

160160
/**
@@ -188,18 +188,23 @@ public static ArrowRecordBatch deserializeRecordBatch(ReadChannel in,
188188
public static ArrowRecordBatch deserializeRecordBatch(ReadChannel in, ArrowBlock block,
189189
BufferAllocator alloc) throws IOException {
190190
long readPosition = in.getCurrentPositiion();
191-
int totalLen = block.getMetadataLength() + block.getBodyLength();
191+
long totalLen = block.getMetadataLength() + block.getBodyLength();
192192
if ((readPosition + block.getMetadataLength()) % 8 != 0) {
193193
// Compute padded size.
194194
totalLen += (8 - (readPosition + block.getMetadataLength()) % 8);
195195
}
196196

197-
ArrowBuf buffer = alloc.buffer(totalLen);
198-
if (in.readFully(buffer, totalLen) != totalLen) {
197+
if (totalLen > Integer.MAX_VALUE) {
198+
throw new IOException("Cannot currently deserialize record batches over 2GB");
199+
}
200+
201+
202+
ArrowBuf buffer = alloc.buffer((int) totalLen);
203+
if (in.readFully(buffer, (int) totalLen) != totalLen) {
199204
throw new IOException("Unexpected end of input trying to read batch.");
200205
}
201206

202-
return deserializeRecordBatch(buffer, readPosition, block.getMetadataLength(), totalLen);
207+
return deserializeRecordBatch(buffer, readPosition, block.getMetadataLength(), (int) totalLen);
203208
}
204209

205210
// Deserializes a record batch. Buffer should start at the RecordBatch and include

0 commit comments

Comments
 (0)