-
Notifications
You must be signed in to change notification settings - Fork 1.5k
PARQUET-1328: Add Bloom filter reader and writer #521
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
Closed
Closed
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
81c3063
PARQUET-1328: Add Bloom filter reader and writer
1a0875b
Align to parquet-cpp side code and address comments
chenjunjiedada e3991ee
Rebase to latest master
chenjunjiedada 05aac07
Merge branch 'master' into PARQUET-1328
b8a0f5c
Fix conflicts after rebase and merge
chenjunjiedada 1b646a9
address comments
chenjunjiedada f03d875
address comments and fix enum issue
chenjunjiedada 4fcd761
Merge remote-tracking branch 'official/master' into PARQUET-1328
chenjunjiedada 5e4647f
Fix build issue caused by merge
894040d
test build
chenjunjiedada fb0ab5c
update check for Bloom filter reader
chenjunjiedada 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,14 @@ | ||
| /* | ||
| /* | ||
| * 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 | ||
|
|
@@ -35,6 +35,8 @@ | |
| import org.apache.parquet.column.values.factory.ValuesWriterFactory; | ||
| import org.apache.parquet.schema.MessageType; | ||
|
|
||
| import java.util.HashMap; | ||
|
|
||
| /** | ||
| * This class represents all the configurable Parquet properties. | ||
| */ | ||
|
|
@@ -48,6 +50,8 @@ public class ParquetProperties { | |
| public static final int DEFAULT_MINIMUM_RECORD_COUNT_FOR_CHECK = 100; | ||
| public static final int DEFAULT_MAXIMUM_RECORD_COUNT_FOR_CHECK = 10000; | ||
| public static final int DEFAULT_COLUMN_INDEX_TRUNCATE_LENGTH = 64; | ||
| public static final boolean DEFAULT_BLOOM_FILTER_ENABLED = false; | ||
|
|
||
|
|
||
| public static final ValuesWriterFactory DEFAULT_VALUES_WRITER_FACTORY = new DefaultValuesWriterFactory(); | ||
|
|
||
|
|
@@ -85,10 +89,14 @@ public static WriterVersion fromString(String name) { | |
| private final ByteBufferAllocator allocator; | ||
| private final ValuesWriterFactory valuesWriterFactory; | ||
| private final int columnIndexTruncateLength; | ||
| private final boolean enableBloomFilter; | ||
| private final HashMap<String, Long> bloomFilterExpectedDistinctNumbers; | ||
|
|
||
| private ParquetProperties(WriterVersion writerVersion, int pageSize, int dictPageSize, boolean enableDict, int minRowCountForPageSizeCheck, | ||
| int maxRowCountForPageSizeCheck, boolean estimateNextSizeCheck, ByteBufferAllocator allocator, | ||
| ValuesWriterFactory writerFactory, int columnIndexMinMaxTruncateLength) { | ||
| ValuesWriterFactory writerFactory, int columnIndexMinMaxTruncateLength, boolean enableBloomFilter, | ||
| HashMap<String, Long> bloomFilterExpectedDistinctNumber) { | ||
|
|
||
| this.pageSizeThreshold = pageSize; | ||
| this.initialSlabSize = CapacityByteArrayOutputStream | ||
| .initialSlabSizeHeuristic(MIN_SLAB_SIZE, pageSizeThreshold, 10); | ||
|
|
@@ -102,6 +110,9 @@ private ParquetProperties(WriterVersion writerVersion, int pageSize, int dictPag | |
|
|
||
| this.valuesWriterFactory = writerFactory; | ||
| this.columnIndexTruncateLength = columnIndexMinMaxTruncateLength; | ||
|
|
||
| this.enableBloomFilter = enableBloomFilter; | ||
| this.bloomFilterExpectedDistinctNumbers = bloomFilterExpectedDistinctNumber; | ||
| } | ||
|
|
||
| public ValuesWriter newRepetitionLevelWriter(ColumnDescriptor path) { | ||
|
|
@@ -194,6 +205,14 @@ public boolean estimateNextSizeCheck() { | |
| return estimateNextSizeCheck; | ||
| } | ||
|
|
||
| public boolean isBloomFilterEnabled() { | ||
| return enableBloomFilter; | ||
| } | ||
|
|
||
| public HashMap<String, Long> getBloomFilterExpectedDistinctNumbers() { | ||
| return bloomFilterExpectedDistinctNumbers; | ||
| } | ||
|
|
||
| public static Builder builder() { | ||
| return new Builder(); | ||
| } | ||
|
|
@@ -213,6 +232,8 @@ public static class Builder { | |
| private ByteBufferAllocator allocator = new HeapByteBufferAllocator(); | ||
| private ValuesWriterFactory valuesWriterFactory = DEFAULT_VALUES_WRITER_FACTORY; | ||
| private int columnIndexTruncateLength = DEFAULT_COLUMN_INDEX_TRUNCATE_LENGTH; | ||
| private boolean enableBloomFilter = DEFAULT_BLOOM_FILTER_ENABLED; | ||
| private HashMap<String, Long> bloomFilterExpectedDistinctNumbers = new HashMap<>(); | ||
|
|
||
| private Builder() { | ||
| } | ||
|
|
@@ -225,6 +246,8 @@ private Builder(ParquetProperties toCopy) { | |
| this.maxRowCountForPageSizeCheck = toCopy.maxRowCountForPageSizeCheck; | ||
| this.estimateNextSizeCheck = toCopy.estimateNextSizeCheck; | ||
| this.allocator = toCopy.allocator; | ||
| this.enableBloomFilter = toCopy.enableBloomFilter; | ||
| this.bloomFilterExpectedDistinctNumbers = toCopy.bloomFilterExpectedDistinctNumbers; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -313,11 +336,40 @@ public Builder withColumnIndexTruncateLength(int length) { | |
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Set to enable Bloom filter. | ||
| * | ||
| * @param enableBloomFilter a boolean to indicate whether to enable Bloom filter. | ||
| * @return this builder for method chaining. | ||
| */ | ||
| public Builder withBloomFilterEnabled(boolean enableBloomFilter) { | ||
| this.enableBloomFilter = enableBloomFilter; | ||
| return this; | ||
| } | ||
| /** | ||
| * Set Bloom filter info for columns. | ||
| * | ||
| * @param bloomFilterColumnNames the columns to be enabled for Bloom filter | ||
| * @param bloomFilterDistinctNumbers the expected distinct number of values corresponding to columns | ||
| * @return this builder for method chaining | ||
| */ | ||
| public Builder withBloomFilterInfo(String bloomFilterColumnNames, String bloomFilterDistinctNumbers) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has no callers. Why is it needed? Can you add a test for it? |
||
| String[] columnNames = bloomFilterColumnNames.split(","); | ||
| String[] expectedDistinctNumber = bloomFilterDistinctNumbers.split(","); | ||
| Preconditions.checkArgument(columnNames.length == expectedDistinctNumber.length, | ||
| "Column names are not matched to sizes"); | ||
| for (int i = 0; i < columnNames.length; i++) { | ||
| this.bloomFilterExpectedDistinctNumbers.put(columnNames[i], Long.getLong(expectedDistinctNumber[i])); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| public ParquetProperties build() { | ||
| ParquetProperties properties = | ||
| new ParquetProperties(writerVersion, pageSize, dictPageSize, | ||
| enableDict, minRowCountForPageSizeCheck, maxRowCountForPageSizeCheck, | ||
| estimateNextSizeCheck, allocator, valuesWriterFactory, columnIndexTruncateLength); | ||
| estimateNextSizeCheck, allocator, valuesWriterFactory, columnIndexTruncateLength, | ||
| enableBloomFilter, bloomFilterExpectedDistinctNumbers); | ||
| // we pass a constructed but uninitialized factory to ParquetProperties above as currently | ||
| // creation of ValuesWriters is invoked from within ParquetProperties. In the future | ||
| // we'd like to decouple that and won't need to pass an object to properties and then pass the | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -34,6 +34,8 @@ | |
| import org.apache.parquet.column.ParquetProperties; | ||
| import org.apache.parquet.column.page.PageWriteStore; | ||
| import org.apache.parquet.column.page.PageWriter; | ||
| import org.apache.parquet.column.values.bloomfilter.BloomFilterWriteStore; | ||
| import org.apache.parquet.column.values.bloomfilter.BloomFilterWriter; | ||
| import org.apache.parquet.schema.MessageType; | ||
|
|
||
| /** | ||
|
|
@@ -74,7 +76,7 @@ private interface ColumnWriterProvider { | |
| public ColumnWriter getColumnWriter(ColumnDescriptor path) { | ||
| ColumnWriterBase column = columns.get(path); | ||
| if (column == null) { | ||
| column = createColumnWriter(path, pageWriteStore.getPageWriter(path), props); | ||
| column = createColumnWriter(path, pageWriteStore.getPageWriter(path), null, props); | ||
| columns.put(path, column); | ||
| } | ||
| return column; | ||
|
|
@@ -91,7 +93,7 @@ public ColumnWriter getColumnWriter(ColumnDescriptor path) { | |
| Map<ColumnDescriptor, ColumnWriterBase> mcolumns = new TreeMap<>(); | ||
| for (ColumnDescriptor path : schema.getColumns()) { | ||
| PageWriter pageWriter = pageWriteStore.getPageWriter(path); | ||
| mcolumns.put(path, createColumnWriter(path, pageWriter, props)); | ||
| mcolumns.put(path, createColumnWriter(path, pageWriter, null, props)); | ||
| } | ||
| this.columns = unmodifiableMap(mcolumns); | ||
|
|
||
|
|
@@ -105,7 +107,37 @@ public ColumnWriter getColumnWriter(ColumnDescriptor path) { | |
| }; | ||
| } | ||
|
|
||
| abstract ColumnWriterBase createColumnWriter(ColumnDescriptor path, PageWriter pageWriter, ParquetProperties props); | ||
| ColumnWriteStoreBase( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block could use some comments. |
||
| MessageType schema, | ||
| PageWriteStore pageWriteStore, | ||
| BloomFilterWriteStore bloomFilterWriteStore, | ||
| ParquetProperties props) { | ||
| this.props = props; | ||
| this.thresholdTolerance = (long) (props.getPageSizeThreshold() * THRESHOLD_TOLERANCE_RATIO); | ||
| Map<ColumnDescriptor, ColumnWriterBase> mcolumns = new TreeMap<>(); | ||
| for (ColumnDescriptor path : schema.getColumns()) { | ||
| PageWriter pageWriter = pageWriteStore.getPageWriter(path); | ||
| if (props.isBloomFilterEnabled() && props.getBloomFilterExpectedDistinctNumbers() != null) { | ||
| BloomFilterWriter bloomFilterWriter = bloomFilterWriteStore.getBloomFilterWriter(path); | ||
| mcolumns.put(path, createColumnWriter(path, pageWriter, bloomFilterWriter, props)); | ||
| } else { | ||
| mcolumns.put(path, createColumnWriter(path, pageWriter, null, props)); | ||
| } | ||
| } | ||
| this.columns = unmodifiableMap(mcolumns); | ||
|
|
||
| this.rowCountForNextSizeCheck = props.getMinRowCountForPageSizeCheck(); | ||
|
|
||
| columnWriterProvider = new ColumnWriterProvider() { | ||
| @Override | ||
| public ColumnWriter getColumnWriter(ColumnDescriptor path) { | ||
| return columns.get(path); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| abstract ColumnWriterBase createColumnWriter(ColumnDescriptor path, PageWriter pageWriter, | ||
| BloomFilterWriter bloomFilterWriter, ParquetProperties props); | ||
|
|
||
| public ColumnWriter getColumnWriter(ColumnDescriptor path) { | ||
| return columnWriterProvider.getColumnWriter(path); | ||
|
|
||
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
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.
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.
Please say what this is - what do the String keys represent - columns?