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 @@ -72,9 +72,18 @@ private static class Writer extends FileIndexWriter {
public Writer(DataType dataType, Options options) {
KeyFactory factory = KeyFactory.create(dataType);
String chunkSize = options.getString(CHUNK_SIZE, factory.defaultChunkSize());
long bytes = MemorySize.parse(chunkSize).getBytes();
// the chunk size becomes an eagerly allocated per-chunk buffer, so it has to fit an
// int. Narrowing it silently substitutes a different size: "2g" becomes negative and
// fails only once the writer allocates, "4g" becomes 0 and "5g" becomes 1g.
if (bytes > Integer.MAX_VALUE) {
throw new IllegalArgumentException(
String.format(
"The '%s' option must not exceed 2147483647 bytes, but was '%s'.",
CHUNK_SIZE, chunkSize));
}
this.converter = factory.createConverter();
this.appender =
new RangeBitmap.Appender(factory, (int) MemorySize.parse(chunkSize).getBytes());
this.appender = new RangeBitmap.Appender(factory, (int) bytes);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,42 @@
import static org.apache.paimon.predicate.SortValue.SortDirection.ASCENDING;
import static org.apache.paimon.predicate.SortValue.SortDirection.DESCENDING;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

/** test for {@link RangeBitmapFileIndex}. */
public class RangeBitmapFileIndexTest {

private static final int ROW_COUNT = 10000;
private static final int BOUND = 1000000;

@Test
public void testChunkSizeBeyondIntRangeRejected() {
VarCharType varCharType = new VarCharType();

// the boundary is the whole guard: one byte past int range is rejected, int range itself
// is accepted. "2g" and "4g" would both only re-test the same comparison
Options justPastIntRange = new Options();
justPastIntRange.setString(RangeBitmapFileIndex.CHUNK_SIZE, "2147483648 bytes");
assertThatThrownBy(
() ->
new RangeBitmapFileIndex(varCharType, justPastIntRange)
.createWriter())
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("chunk-size");

Options atIntRange = new Options();
atIntRange.setString(RangeBitmapFileIndex.CHUNK_SIZE, "2147483647 bytes");
assertThat(new RangeBitmapFileIndex(varCharType, atIntRange).createWriter()).isNotNull();

// a large but in-range chunk size still writes and serializes
Options valid = new Options();
valid.setString(RangeBitmapFileIndex.CHUNK_SIZE, "16mb");
FileIndexWriter writer = new RangeBitmapFileIndex(varCharType, valid).createWriter();
writer.write(BinaryString.fromString("a"));
writer.write(BinaryString.fromString("b"));
assertThat(writer.serializedBytes()).isNotEmpty();
}

@RepeatedTest(10)
public void test() {
String prefix = "hello-";
Expand Down
Loading