Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.6k
PARQUET-41: Add bloom filter #757
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d473d17
PARQUET-1328: Add Bloom filter reader and writer (#587)
chenjunjiedada 96c2fef
PARQUET-1516: Store Bloom filters near to footer (#608)
chenjunjiedada dd7e655
PARQUET-1391: Integrate Bloom filter logic (#619)
chenjunjiedada 21c45ed
Merge branch 'master' into bloom-filter
chenjunjiedada 1fc2733
Merge branch 'master' into bloom-filter
chenjunjiedada ba28686
PARQUET-1660: align Bloom filter implementation with format (#686)
chenjunjiedada 1e44aa4
Merge remote-tracking branch 'apache/master' into bloom-filter
chenjunjiedada e396d15
Merge branch 'master' into bloom-filter
chenjunjiedada 6260ca4
remove some useless changes
chenjunjiedada a67480d
address comments first round
chenjunjiedada 28216ce
address comments second round
chenjunjiedada 1519967
address comments, add unit tests, shade jar
chenjunjiedada 6a8e641
Add xxhash correctness unit test, update shading, upper bound and som…
chenjunjiedada 069cc22
add more unit tests, some minor fixes
chenjunjiedada c16e8e8
minor updates
chenjunjiedada 8f04bb8
minor updates
chenjunjiedada 5a98e78
fix build
chenjunjiedada 373d811
Merge branch 'master' into bloom-filter
gszadovszky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
100 changes: 93 additions & 7 deletions
100 parquet-column/src/main/java/org/apache/parquet/column/ParquetProperties.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 |
|---|---|---|
| @@ -18,20 +18,24 @@ | ||
| */ | ||
| package org.apache.parquet.column; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.Set; | ||
| import org.apache.parquet.Preconditions; | ||
| import org.apache.parquet.bytes.ByteBufferAllocator; | ||
| import org.apache.parquet.bytes.CapacityByteArrayOutputStream; | ||
| import org.apache.parquet.bytes.HeapByteBufferAllocator; | ||
| import static org.apache.parquet.bytes.BytesUtils.getWidthFromMaxInt; | ||
| import java.util.Objects; | ||
| import org.apache.parquet.column.impl.ColumnWriteStoreV1; | ||
| import org.apache.parquet.column.impl.ColumnWriteStoreV2; | ||
| import org.apache.parquet.column.page.PageWriteStore; | ||
| import org.apache.parquet.column.values.ValuesWriter; | ||
| import org.apache.parquet.column.values.bitpacking.DevNullValuesWriter; | ||
| import org.apache.parquet.column.values.bloomfilter.BloomFilterWriteStore; | ||
| import org.apache.parquet.column.values.factory.DefaultValuesWriterFactory; | ||
| import org.apache.parquet.column.values.factory.ValuesWriterFactory; | ||
| import org.apache.parquet.column.values.rle.RunLengthBitPackingHybridEncoder; | ||
| @@ -56,6 +60,7 @@ public class ParquetProperties { | ||
| public static final int DEFAULT_COLUMN_INDEX_TRUNCATE_LENGTH = 64; | ||
| public static final int DEFAULT_STATISTICS_TRUNCATE_LENGTH = Integer.MAX_VALUE; | ||
| public static final int DEFAULT_PAGE_ROW_COUNT_LIMIT = 20_000; | ||
| public static final int DEFAULT_MAX_BLOOM_FILTER_BYTES = 1024 * 1024; | ||
| public static final boolean DEFAULT_PAGE_WRITE_CHECKSUM_ENABLED = true; | ||
| @@ -96,6 +101,11 @@ public static WriterVersion fromString(String name) { | ||
| private final ValuesWriterFactory valuesWriterFactory; | ||
| private final int columnIndexTruncateLength; | ||
| private final int statisticsTruncateLength; | ||
| // The key-value pair represents the column name and its expected distinct number of values in a row group. | ||
| private final Map<String, Long> bloomFilterExpectedDistinctNumbers; | ||
| private final int maxBloomFilterBytes; | ||
| private final List<String> bloomFilterColumns; | ||
| private final int pageRowCountLimit; | ||
| private final boolean pageWriteChecksumEnabled; | ||
| private final boolean enableByteStreamSplit; | ||
| @@ -115,6 +125,9 @@ private ParquetProperties(Builder builder) { | ||
| this.valuesWriterFactory = builder.valuesWriterFactory; | ||
| this.columnIndexTruncateLength = builder.columnIndexTruncateLength; | ||
| this.statisticsTruncateLength = builder.statisticsTruncateLength; | ||
| this.bloomFilterExpectedDistinctNumbers = builder.bloomFilterColumnExpectedNDVs; | ||
| this.bloomFilterColumns = builder.bloomFilterColumns; | ||
| this.maxBloomFilterBytes = builder.maxBloomFilterBytes; | ||
| this.pageRowCountLimit = builder.pageRowCountLimit; | ||
| this.pageWriteChecksumEnabled = builder.pageWriteChecksumEnabled; | ||
| this.enableByteStreamSplit = builder.enableByteStreamSplit; | ||
| @@ -189,11 +202,24 @@ public ByteBufferAllocator getAllocator() { | ||
| public ColumnWriteStore newColumnWriteStore(MessageType schema, | ||
| PageWriteStore pageStore) { | ||
| switch (writerVersion) { | ||
| case PARQUET_1_0: | ||
| return new ColumnWriteStoreV1(schema, pageStore, this); | ||
| case PARQUET_2_0: | ||
| return new ColumnWriteStoreV2(schema, pageStore, this); | ||
| default: | ||
| throw new IllegalArgumentException("unknown version " + writerVersion); | ||
| } | ||
| } | ||
| public ColumnWriteStore newColumnWriteStore(MessageType schema, | ||
| PageWriteStore pageStore, | ||
| BloomFilterWriteStore bloomFilterWriteStore) { | ||
| switch (writerVersion) { | ||
| case PARQUET_1_0: | ||
| return new ColumnWriteStoreV1(schema, pageStore, this); | ||
| return new ColumnWriteStoreV1(schema, pageStore, bloomFilterWriteStore, this); | ||
| case PARQUET_2_0: | ||
| return new ColumnWriteStoreV2(schema, pageStore, this); | ||
| return new ColumnWriteStoreV2(schema, pageStore, bloomFilterWriteStore, this); | ||
| default: | ||
| throw new IllegalArgumentException("unknown version " + writerVersion); | ||
| } | ||
| @@ -231,6 +257,22 @@ public boolean getPageWriteChecksumEnabled() { | ||
| return pageWriteChecksumEnabled; | ||
| } | ||
| public Map<String, Long> getBloomFilterColumnExpectedNDVs() { | ||
| return bloomFilterExpectedDistinctNumbers; | ||
| } | ||
| public Set<String> getBloomFilterColumns() { | ||
| if (bloomFilterColumns != null && bloomFilterColumns.size() > 0){ | ||
| return new HashSet<>(bloomFilterColumns); | ||
| } | ||
| return bloomFilterExpectedDistinctNumbers.keySet(); | ||
gszadovszky marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| public int getMaxBloomFilterBytes() { | ||
| return maxBloomFilterBytes; | ||
| } | ||
| public static Builder builder() { | ||
| return new Builder(); | ||
| } | ||
| @@ -250,6 +292,9 @@ public String toString() { | ||
| + "Max row count for page size check is: " + getMaxRowCountForPageSizeCheck() + '\n' | ||
| + "Truncate length for column indexes is: " + getColumnIndexTruncateLength() + '\n' | ||
| + "Truncate length for statistics min/max is: " + getStatisticsTruncateLength() + '\n' | ||
| + "Bloom filter enabled column names are: " + getBloomFilterColumns() + '\n' | ||
| + "Max Bloom filter size for a column is " + getMaxBloomFilterBytes() + '\n' | ||
| + "Bloom filter enabled column expected number of distinct values are: " + getBloomFilterColumnExpectedNDVs().values() + '\n' | ||
| + "Page row count limit to " + getPageRowCountLimit() + '\n' | ||
| + "Writing page checksums is: " + (getPageWriteChecksumEnabled() ? "on" : "off"); | ||
| } | ||
| @@ -266,6 +311,9 @@ public static class Builder { | ||
| private ValuesWriterFactory valuesWriterFactory = DEFAULT_VALUES_WRITER_FACTORY; | ||
| private int columnIndexTruncateLength = DEFAULT_COLUMN_INDEX_TRUNCATE_LENGTH; | ||
| private int statisticsTruncateLength = DEFAULT_STATISTICS_TRUNCATE_LENGTH; | ||
| private Map<String, Long> bloomFilterColumnExpectedNDVs = new HashMap<>(); | ||
| private int maxBloomFilterBytes = DEFAULT_MAX_BLOOM_FILTER_BYTES; | ||
| private List<String> bloomFilterColumns = new ArrayList<>(); | ||
| private int pageRowCountLimit = DEFAULT_PAGE_ROW_COUNT_LIMIT; | ||
| private boolean pageWriteChecksumEnabled = DEFAULT_PAGE_WRITE_CHECKSUM_ENABLED; | ||
| private boolean enableByteStreamSplit = DEFAULT_IS_BYTE_STREAM_SPLIT_ENABLED; | ||
| @@ -286,6 +334,9 @@ private Builder(ParquetProperties toCopy) { | ||
| this.allocator = toCopy.allocator; | ||
| this.pageRowCountLimit = toCopy.pageRowCountLimit; | ||
| this.pageWriteChecksumEnabled = toCopy.pageWriteChecksumEnabled; | ||
| this.bloomFilterColumnExpectedNDVs = toCopy.bloomFilterExpectedDistinctNumbers; | ||
| this.bloomFilterColumns = toCopy.bloomFilterColumns; | ||
| this.maxBloomFilterBytes = toCopy.maxBloomFilterBytes; | ||
| this.enableByteStreamSplit = toCopy.enableByteStreamSplit; | ||
| } | ||
| @@ -396,6 +447,41 @@ public Builder withStatisticsTruncateLength(int length) { | ||
| return this; | ||
| } | ||
| /** | ||
| * Set max Bloom filter bytes for related columns. | ||
| * | ||
| * @param maxBloomFilterBytes the max bytes of a Bloom filter bitset for a column. | ||
| * @return this builder for method chaining | ||
| */ | ||
| public Builder withMaxBloomFilterBytes(int maxBloomFilterBytes) { | ||
| this.maxBloomFilterBytes = maxBloomFilterBytes; | ||
| return this; | ||
| } | ||
| /** | ||
| * Set Bloom filter column names and expected NDVs. | ||
| * | ||
| * @param columnToNDVMap the columns which has bloom filter enabled. | ||
| * | ||
| * @return this builder for method chaining | ||
| */ | ||
| public Builder withBloomFilterColumnToNDVMap(Map<String, Long> columnToNDVMap) { | ||
| this.bloomFilterColumnExpectedNDVs = columnToNDVMap; | ||
| return this; | ||
| } | ||
| /** | ||
| * Set Bloom filter column names. | ||
| * | ||
| * @param columns the columns which has bloom filter enabled. | ||
| * | ||
| * @return this builder for method chaining | ||
| */ | ||
| public Builder withBloomFilterColumnNames(List<String> columns) { | ||
| this.bloomFilterColumns = columns; | ||
| return this; | ||
| } | ||
| public Builder withPageRowCountLimit(int rowCount) { | ||
| Preconditions.checkArgument(rowCount > 0, "Invalid row count limit for pages: " + rowCount); | ||
| pageRowCountLimit = rowCount; | ||
39 changes: 36 additions & 3 deletions
39 parquet-column/src/main/java/org/apache/parquet/column/impl/ColumnWriteStoreBase.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
13 changes: 11 additions & 2 deletions
13 parquet-column/src/main/java/org/apache/parquet/column/impl/ColumnWriteStoreV1.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
13 changes: 11 additions & 2 deletions
13 parquet-column/src/main/java/org/apache/parquet/column/impl/ColumnWriteStoreV2.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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chenjunjiedada
I'm curious about the maximum default value. Could you please explain why you choose 1 MB?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assume we have a row group with only one column of UUID (36 bytes), according to the formula and FPP = 0.01 we will need about 4MB. I expect that we will have more columns in the real scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chenjunjiedada Thanks for the clarification!