-
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
Changes from 6 commits
81c3063
1a0875b
e3991ee
05aac07
b8a0f5c
1b646a9
f03d875
4fcd761
5e4647f
894040d
fb0ab5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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,16 @@ public static WriterVersion fromString(String name) { | |
| private final ByteBufferAllocator allocator; | ||
| private final ValuesWriterFactory valuesWriterFactory; | ||
| private final int columnIndexTruncateLength; | ||
| private final boolean enableBloomFilter; | ||
|
|
||
| // The key-value pair represents the column name and its expected distinct number of values in a row group. | ||
| 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 +112,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 +207,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 +234,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 +248,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 +338,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) { | ||
|
||
| 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 | ||
|
|
||
| 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,38 @@ public ColumnWriter getColumnWriter(ColumnDescriptor path) { | |||||
| }; | ||||||
| } | ||||||
|
|
||||||
| abstract ColumnWriterBase createColumnWriter(ColumnDescriptor path, PageWriter pageWriter, ParquetProperties props); | ||||||
| // The Bloom filter is written to a specified bitset instead of pages. So it needs a separated write store abstract. | ||||||
|
||||||
| // The Bloom filter is written to a specified bitset instead of pages. So it needs a separated write store abstract. | |
| // The Bloom filter is written to a specified bitset instead of pages, so it needs a separate write store abstract. |
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.
This block could use some comments.
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?