-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[common] Introduce BitmapFileIndexMetaV2. #5028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JingsongLi
merged 17 commits into
apache:master
from
hang8929201:bitmap-multi-level-index
Feb 24, 2025
Merged
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
70e8d76
[common] Introduce BitmapFileIndexMetaV2.
494af0b
[common] Introduce BitmapFileIndexMetaV2.
efd3545
[common] Introduce BitmapFileIndexMetaV2.
32e9568
[common] Introduce BitmapFileIndexMetaV2.
313a5e2
[common] Introduce BitmapFileIndexMetaV2.
8279d71
[common] Add BitmapIndexBenchmark.
61815c0
[common] Add BitmapIndexBenchmark.
81eec8e
[common] Add BitmapIndexBenchmark.
ae96b55
[common] Add BitmapIndexBenchmark.
531ab01
[common] Support use byte buffer to deserialize RoaringBitmap in Bitm…
d1daff3
[common] Support use byte buffer to deserialize RoaringBitmap in Bitm…
51d3edd
[common] BitmapFileIndexMetaV2
326b32e
[common] BitmapFileIndexMetaV2
63472e0
[common] binary search
03b5310
[common] find entry.
3f5de5b
[common] Change default bitmap index format version to V1.
35cb8e8
[common] Change default bitmap index format version to V1.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
...cro-benchmarks/src/test/java/org/apache/paimon/benchmark/bitmap/BitmapIndexBenchmark.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.paimon.benchmark.bitmap; | ||
|
|
||
| import org.apache.paimon.benchmark.Benchmark; | ||
| import org.apache.paimon.data.BinaryString; | ||
| import org.apache.paimon.fileindex.FileIndexReader; | ||
| import org.apache.paimon.fileindex.FileIndexResult; | ||
| import org.apache.paimon.fileindex.FileIndexWriter; | ||
| import org.apache.paimon.fileindex.bitmap.BitmapFileIndex; | ||
| import org.apache.paimon.fileindex.bitmap.BitmapIndexResult; | ||
| import org.apache.paimon.fs.local.LocalFileIO; | ||
| import org.apache.paimon.options.Options; | ||
| import org.apache.paimon.predicate.FieldRef; | ||
| import org.apache.paimon.types.DataTypes; | ||
| import org.apache.paimon.utils.RoaringBitmap32; | ||
|
|
||
| import org.apache.commons.io.FileUtils; | ||
| import org.junit.Rule; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.rules.TemporaryFolder; | ||
|
|
||
| import java.io.File; | ||
| import java.io.FileNotFoundException; | ||
|
|
||
| /** Benchmark for {@link BitmapFileIndex}. */ | ||
| public class BitmapIndexBenchmark { | ||
|
|
||
| public static final int ROW_COUNT = 1000000; | ||
|
|
||
| private static final String prefix = "asdfghjkl"; | ||
|
|
||
| @Rule public TemporaryFolder folder = new TemporaryFolder(); | ||
|
|
||
| @Test | ||
| public void testQuery10() throws Exception { | ||
| testQuery(10); | ||
| } | ||
|
|
||
| @Test | ||
| public void testQuery100() throws Exception { | ||
| testQuery(100); | ||
| } | ||
|
|
||
| @Test | ||
| public void testQuery1000() throws Exception { | ||
| testQuery(1000); | ||
| } | ||
|
|
||
| @Test | ||
| public void testQuery10000() throws Exception { | ||
| testQuery(10000); | ||
| } | ||
|
|
||
| @Test | ||
| public void testQuery30000() throws Exception { | ||
| testQuery(30000); | ||
| } | ||
|
|
||
| @Test | ||
| public void testQuery50000() throws Exception { | ||
| testQuery(50000); | ||
| } | ||
|
|
||
| @Test | ||
| public void testQuery80000() throws Exception { | ||
| testQuery(80000); | ||
| } | ||
|
|
||
| @Test | ||
| public void testQuery100000() throws Exception { | ||
| testQuery(100000); | ||
| } | ||
|
|
||
| private void testQuery(int approxCardinality) throws Exception { | ||
|
|
||
| RoaringBitmap32 middleBm = new RoaringBitmap32(); | ||
|
|
||
| Options writeOptions1 = new Options(); | ||
| writeOptions1.setInteger(BitmapFileIndex.VERSION, BitmapFileIndex.VERSION_1); | ||
| FileIndexWriter writer1 = | ||
| new BitmapFileIndex(DataTypes.STRING(), writeOptions1).createWriter(); | ||
|
|
||
| Options writeOptions2 = new Options(); | ||
| writeOptions1.setInteger(BitmapFileIndex.VERSION, BitmapFileIndex.VERSION_2); | ||
| FileIndexWriter writer2 = | ||
| new BitmapFileIndex(DataTypes.STRING(), writeOptions2).createWriter(); | ||
|
|
||
| for (int i = 0; i < ROW_COUNT; i++) { | ||
| int sid = (int) (Math.random() * approxCardinality); | ||
| if (sid == approxCardinality / 2) { | ||
| middleBm.add(i); | ||
| } | ||
| writer1.write(BinaryString.fromString(prefix + sid)); | ||
| writer2.write(BinaryString.fromString(prefix + sid)); | ||
| } | ||
|
|
||
| folder.create(); | ||
|
|
||
| File file1 = folder.newFile("bitmap-index-v1"); | ||
| File file2 = folder.newFile("bitmap-index-v2"); | ||
| FileUtils.writeByteArrayToFile(file1, writer1.serializedBytes()); | ||
| FileUtils.writeByteArrayToFile(file2, writer2.serializedBytes()); | ||
|
|
||
| Benchmark benchmark = | ||
| new Benchmark( | ||
| String.format("bitmap-index-query-benchmark-%d", approxCardinality), | ||
| 100) | ||
| .setNumWarmupIters(1) | ||
| .setOutputPerIteration(true); | ||
|
|
||
| benchmark.addCase("formatV1", 10, () -> query(approxCardinality, file1, "false", "false")); | ||
|
|
||
| benchmark.addCase( | ||
| "formatV1-bitmapByteBuffer", | ||
| 10, | ||
| () -> query(approxCardinality, file1, "false", "true")); | ||
|
|
||
| benchmark.addCase( | ||
| "formatV1-bufferedInput", | ||
| 10, | ||
| () -> query(approxCardinality, file1, "true", "false")); | ||
|
|
||
| benchmark.addCase( | ||
| "formatV1-bufferedInput-bitmapByteBuffer", | ||
| 10, | ||
| () -> query(approxCardinality, file1, "true", "true")); | ||
|
|
||
| benchmark.addCase("format-v2", 10, () -> query(approxCardinality, file2, "false", "false")); | ||
|
|
||
| benchmark.addCase( | ||
| "format-v2-bitmapByteBuffer", | ||
| 10, | ||
| () -> query(approxCardinality, file2, "false", "true")); | ||
|
|
||
| benchmark.addCase( | ||
| "format-v2-bufferedInput", | ||
| 10, | ||
| () -> query(approxCardinality, file2, "true", "false")); | ||
|
|
||
| benchmark.addCase( | ||
| "format-v2-bufferedInput-bitmapByteBuffer", | ||
| 10, | ||
| () -> query(approxCardinality, file2, "true", "true")); | ||
|
|
||
| benchmark.run(); | ||
| } | ||
|
|
||
| private static void query( | ||
| int approxCardinality, | ||
| File file1, | ||
| String enableBufferedInput, | ||
| String enableNextOffsetToSize) { | ||
| try { | ||
| FieldRef fieldRef = new FieldRef(0, "", DataTypes.STRING()); | ||
| Options options = new Options(); | ||
| options.set(BitmapFileIndex.ENABLE_BUFFERED_INPUT, enableBufferedInput); | ||
| options.set(BitmapFileIndex.ENABLE_NEXT_OFFSET_TO_SIZE, enableNextOffsetToSize); | ||
| LocalFileIO.LocalSeekableInputStream localSeekableInputStream = | ||
| new LocalFileIO.LocalSeekableInputStream(file1); | ||
| FileIndexReader reader = | ||
| new BitmapFileIndex(DataTypes.STRING(), options) | ||
| .createReader(localSeekableInputStream, 0, 0); | ||
| FileIndexResult result = | ||
| reader.visitEqual( | ||
| fieldRef, BinaryString.fromString(prefix + (approxCardinality / 2))); | ||
| ((BitmapIndexResult) result).get(); | ||
| } catch (FileNotFoundException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.