Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@

import static org.apache.parquet.hadoop.ParquetFileWriter.Mode.OVERWRITE;
import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT64;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -121,7 +118,9 @@ private int getRowGroupCount(Path path) throws IOException {
public void testReadNextRowGroupReleasesBuffersOfPreviousRowGroup() throws Exception {
Path path = writeMultiRowGroupFile(500);
int expectedRowGroups = getRowGroupCount(path);
assertTrue(expectedRowGroups > 1, "Expected multiple row groups but got " + expectedRowGroups);
assertThat(expectedRowGroups)
.as("Expected multiple row groups but got " + expectedRowGroups)
.isGreaterThan(1);

try (TrackingByteBufferAllocator readAllocator =
TrackingByteBufferAllocator.wrap(new HeapByteBufferAllocator())) {
Expand All @@ -133,10 +132,10 @@ public void testReadNextRowGroupReleasesBuffersOfPreviousRowGroup() throws Excep
PageReadStore pages;
int rowGroupCount = 0;
while ((pages = reader.readNextRowGroup()) != null) {
assertNotNull(pages);
assertThat(pages).isNotNull();
rowGroupCount++;
}
assertEquals(expectedRowGroups, rowGroupCount);
assertThat(rowGroupCount).isEqualTo(expectedRowGroups);
}
// After reader.close(), all buffers including the last row group's should be released.
// readAllocator.close() will throw LeakedByteBufferException if any leak remains.
Expand All @@ -151,7 +150,9 @@ public void testReadNextRowGroupReleasesBuffersOfPreviousRowGroup() throws Excep
public void testCloseReleasesCurrentRowGroupBuffers() throws Exception {
Path path = writeMultiRowGroupFile(500);
int expectedRowGroups = getRowGroupCount(path);
assertTrue(expectedRowGroups > 1, "Expected multiple row groups but got " + expectedRowGroups);
assertThat(expectedRowGroups)
.as("Expected multiple row groups but got " + expectedRowGroups)
.isGreaterThan(1);

try (TrackingByteBufferAllocator readAllocator =
TrackingByteBufferAllocator.wrap(new HeapByteBufferAllocator())) {
Expand All @@ -162,8 +163,8 @@ public void testCloseReleasesCurrentRowGroupBuffers() throws Exception {
try (ParquetFileReader reader = new ParquetFileReader(inputFile, options)) {
// Read only the first row group
PageReadStore pages = reader.readNextRowGroup();
assertNotNull(pages);
assertTrue(pages.getRowCount() > 0);
assertThat(pages).isNotNull();
assertThat(pages.getRowCount()).isPositive();
// Don't read remaining row groups - close should release the current row group's buffers
}
}
Expand All @@ -177,7 +178,9 @@ public void testCloseReleasesCurrentRowGroupBuffers() throws Exception {
public void testReadNextFilteredRowGroupReleasesBuffersWhenNoFilter() throws Exception {
Path path = writeMultiRowGroupFile(500);
int expectedRowGroups = getRowGroupCount(path);
assertTrue(expectedRowGroups > 1, "Expected multiple row groups but got " + expectedRowGroups);
assertThat(expectedRowGroups)
.as("Expected multiple row groups but got " + expectedRowGroups)
.isGreaterThan(1);

try (TrackingByteBufferAllocator readAllocator =
TrackingByteBufferAllocator.wrap(new HeapByteBufferAllocator())) {
Expand All @@ -190,10 +193,10 @@ public void testReadNextFilteredRowGroupReleasesBuffersWhenNoFilter() throws Exc
PageReadStore pages;
int rowGroupCount = 0;
while ((pages = reader.readNextFilteredRowGroup()) != null) {
assertNotNull(pages);
assertThat(pages).isNotNull();
rowGroupCount++;
}
assertEquals(expectedRowGroups, rowGroupCount);
assertThat(rowGroupCount).isEqualTo(expectedRowGroups);
}
}
}
Expand All @@ -207,7 +210,9 @@ public void testReadNextFilteredRowGroupReleasesBuffersWhenNoFilter() throws Exc
public void testReadNextFilteredRowGroupReleasesBuffersWithFilter() throws Exception {
Path path = writeMultiRowGroupFile(500);
int expectedRowGroups = getRowGroupCount(path);
assertTrue(expectedRowGroups > 1, "Expected multiple row groups but got " + expectedRowGroups);
assertThat(expectedRowGroups)
.as("Expected multiple row groups but got " + expectedRowGroups)
.isGreaterThan(1);

try (TrackingByteBufferAllocator readAllocator =
TrackingByteBufferAllocator.wrap(new HeapByteBufferAllocator())) {
Expand All @@ -225,11 +230,11 @@ public void testReadNextFilteredRowGroupReleasesBuffersWithFilter() throws Excep
PageReadStore pages;
int rowGroupCount = 0;
while ((pages = reader.readNextFilteredRowGroup()) != null) {
assertNotNull(pages);
assertThat(pages).isNotNull();
rowGroupCount++;
}
// All row groups should be read since the filter matches everything
assertEquals(expectedRowGroups, rowGroupCount);
assertThat(rowGroupCount).isEqualTo(expectedRowGroups);
}
}
}
Expand All @@ -243,7 +248,9 @@ public void testReadNextFilteredRowGroupReleasesBuffersWithFilter() throws Excep
public void testReadNextFilteredRowGroupWithColumnIndexFilteringReleasesBuffers() throws Exception {
Path path = writeMultiRowGroupFile(500);
int totalRowGroups = getRowGroupCount(path);
assertTrue(totalRowGroups > 1, "Expected multiple row groups but got " + totalRowGroups);
assertThat(totalRowGroups)
.as("Expected multiple row groups but got " + totalRowGroups)
.isGreaterThan(1);

try (TrackingByteBufferAllocator readAllocator =
TrackingByteBufferAllocator.wrap(new HeapByteBufferAllocator())) {
Expand All @@ -262,12 +269,14 @@ public void testReadNextFilteredRowGroupWithColumnIndexFilteringReleasesBuffers(
PageReadStore pages;
int rowGroupCount = 0;
while ((pages = reader.readNextFilteredRowGroup()) != null) {
assertNotNull(pages);
assertTrue(pages.getRowCount() > 0);
assertThat(pages).isNotNull();
assertThat(pages.getRowCount()).isPositive();
rowGroupCount++;
}
// At least some row groups should be returned (those containing id < 10)
assertTrue(rowGroupCount >= 1, "Expected at least 1 row group returned");
assertThat(rowGroupCount)
.as("Expected at least 1 row group returned")
.isGreaterThanOrEqualTo(1);
}
}
}
Expand All @@ -280,7 +289,9 @@ public void testReadNextFilteredRowGroupWithColumnIndexFilteringReleasesBuffers(
public void testPartialReadThenCloseReleasesBuffers() throws Exception {
Path path = writeMultiRowGroupFile(500);
int expectedRowGroups = getRowGroupCount(path);
assertTrue(expectedRowGroups >= 3, "Expected at least 3 row groups but got " + expectedRowGroups);
assertThat(expectedRowGroups)
.as("Expected at least 3 row groups but got " + expectedRowGroups)
.isGreaterThanOrEqualTo(3);

try (TrackingByteBufferAllocator readAllocator =
TrackingByteBufferAllocator.wrap(new HeapByteBufferAllocator())) {
Expand All @@ -291,11 +302,11 @@ public void testPartialReadThenCloseReleasesBuffers() throws Exception {
try (ParquetFileReader reader = new ParquetFileReader(inputFile, options)) {
// Read row group 1
PageReadStore pages = reader.readNextRowGroup();
assertNotNull(pages);
assertThat(pages).isNotNull();

// Read row group 2 (should release row group 1 buffers)
pages = reader.readNextRowGroup();
assertNotNull(pages);
assertThat(pages).isNotNull();

// Close without reading remaining row groups - close() should release row group 2 buffers
}
Expand All @@ -322,8 +333,8 @@ public void testExhaustedReaderNoLeak() throws Exception {
// drain
}
// Additional calls should return null without leaking
assertNull(reader.readNextRowGroup());
assertNull(reader.readNextRowGroup());
assertThat(reader.readNextRowGroup()).isNull();
assertThat(reader.readNextRowGroup()).isNull();
}
}
}
Expand Down
Loading