-
Notifications
You must be signed in to change notification settings - Fork 1.5k
PARQUET-1391: Integrate Bloom filter logic #619
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
34 changes: 0 additions & 34 deletions
34
...lumn/src/main/java/org/apache/parquet/column/values/bloomfilter/BloomFilterReadStore.java
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
...-column/src/main/java/org/apache/parquet/column/values/bloomfilter/BloomFilterReader.java
This file was deleted.
Oops, something went wrong.
150 changes: 150 additions & 0 deletions
150
...uet-hadoop/src/main/java/org/apache/parquet/filter2/BloomFilterLevel/BloomFilterImpl.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,150 @@ | ||
| /* | ||
| * 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.parquet.filter2.BloomFilterLevel; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import org.apache.parquet.column.values.bloomfilter.BloomFilter; | ||
| import org.apache.parquet.filter2.predicate.FilterPredicate; | ||
| import org.apache.parquet.filter2.predicate.Operators; | ||
| import org.apache.parquet.filter2.predicate.UserDefinedPredicate; | ||
| import org.apache.parquet.hadoop.BloomFilterReader; | ||
| import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData; | ||
| import org.apache.parquet.hadoop.metadata.ColumnPath; | ||
|
|
||
| import static org.apache.parquet.Preconditions.checkNotNull; | ||
|
|
||
| public class BloomFilterImpl implements FilterPredicate.Visitor<Boolean>{ | ||
| private static final Logger LOG = LoggerFactory.getLogger(BloomFilterImpl.class); | ||
| private static final boolean BLOCK_MIGHT_MATCH = false; | ||
| private static final boolean BLOCK_CANNOT_MATCH = true; | ||
|
|
||
| private final Map<ColumnPath, ColumnChunkMetaData> columns = new HashMap<ColumnPath, ColumnChunkMetaData>(); | ||
|
|
||
| public static boolean canDrop(FilterPredicate pred, List<ColumnChunkMetaData> columns, BloomFilterReader bloomFilterReader) { | ||
| checkNotNull(pred, "pred"); | ||
| checkNotNull(columns, "columns"); | ||
| return pred.accept(new BloomFilterImpl(columns, bloomFilterReader)); | ||
| } | ||
|
|
||
| private BloomFilterImpl(List<ColumnChunkMetaData> columnsList, BloomFilterReader bloomFilterReader) { | ||
| for (ColumnChunkMetaData chunk : columnsList) { | ||
| columns.put(chunk.getPath(), chunk); | ||
| } | ||
|
|
||
| this.bloomFilterReader = bloomFilterReader; | ||
| } | ||
|
|
||
| private BloomFilterReader bloomFilterReader; | ||
|
|
||
| private ColumnChunkMetaData getColumnChunk(ColumnPath columnPath) { | ||
| return columns.get(columnPath); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends Comparable<T>> Boolean visit(Operators.Eq<T> eq) { | ||
| T value = eq.getValue(); | ||
|
|
||
| if (value == null) { | ||
| // the bloom filter bitset contains only non-null values so isn't helpful. this | ||
| // could check the column stats, but the StatisticsFilter is responsible | ||
| return BLOCK_MIGHT_MATCH; | ||
| } | ||
|
|
||
| Operators.Column<T> filterColumn = eq.getColumn(); | ||
| ColumnChunkMetaData meta = getColumnChunk(filterColumn.getColumnPath()); | ||
| if (meta == null) { | ||
| // the column isn't in this file so all values are null, but the value | ||
| // must be non-null because of the above check. | ||
| return BLOCK_CANNOT_MATCH; | ||
| } | ||
|
|
||
| try { | ||
| BloomFilter bloomFilter = bloomFilterReader.readBloomFilter(meta); | ||
| if (bloomFilter != null && !bloomFilter.findHash(bloomFilter.hash(value))) { | ||
| return BLOCK_CANNOT_MATCH; | ||
| } | ||
| } catch (RuntimeException e) { | ||
| LOG.warn(e.getMessage()); | ||
| return BLOCK_MIGHT_MATCH; | ||
| } | ||
|
|
||
| return BLOCK_MIGHT_MATCH; | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends Comparable<T>> Boolean visit(Operators.NotEq<T> notEq) { | ||
| return BLOCK_MIGHT_MATCH; | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends Comparable<T>> Boolean visit(Operators.Lt<T> lt) { | ||
| return BLOCK_MIGHT_MATCH; | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends Comparable<T>> Boolean visit(Operators.LtEq<T> ltEq) { | ||
| return BLOCK_MIGHT_MATCH; | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends Comparable<T>> Boolean visit(Operators.Gt<T> gt) { | ||
| return BLOCK_MIGHT_MATCH; | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends Comparable<T>> Boolean visit(Operators.GtEq<T> gtEq) { | ||
| return BLOCK_MIGHT_MATCH; | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean visit(Operators.And and) { | ||
| return and.getLeft().accept(this) || and.getRight().accept(this); | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean visit(Operators.Or or) { | ||
| return or.getLeft().accept(this) && or.getRight().accept(this); | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean visit(Operators.Not not) { | ||
| throw new IllegalArgumentException( | ||
| "This predicate contains a not! Did you forget to run this predicate through LogicalInverseRewriter? " + not); | ||
| } | ||
|
|
||
| private <T extends Comparable<T>, U extends UserDefinedPredicate<T>> Boolean visit(Operators.UserDefined<T, U> ud, boolean inverted) { | ||
| return BLOCK_MIGHT_MATCH; | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends Comparable<T>, U extends UserDefinedPredicate<T>> Boolean visit(Operators.UserDefined<T, U> udp) { | ||
| return visit(udp, false); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends Comparable<T>, U extends UserDefinedPredicate<T>> Boolean visit(Operators.LogicalNotUserDefined<T, U> udp) { | ||
| return visit(udp.getUserDefined(), true); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.