-
Notifications
You must be signed in to change notification settings - Fork 3k
Orc: Support row group bloom filters #5313
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
5 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
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
149 changes: 149 additions & 0 deletions
149
orc/src/test/java/org/apache/iceberg/orc/TestBloomFilter.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,149 @@ | ||
| /* | ||
| * 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.iceberg.orc; | ||
|
|
||
| import static org.apache.iceberg.types.Types.NestedField.required; | ||
|
|
||
| import java.io.File; | ||
| import java.lang.reflect.Field; | ||
| import java.lang.reflect.Method; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.iceberg.Files; | ||
| import org.apache.iceberg.Schema; | ||
| import org.apache.iceberg.data.GenericRecord; | ||
| import org.apache.iceberg.data.Record; | ||
| import org.apache.iceberg.data.orc.GenericOrcWriter; | ||
| import org.apache.iceberg.io.FileAppender; | ||
| import org.apache.iceberg.io.OutputFile; | ||
| import org.apache.iceberg.types.Types; | ||
| import org.apache.orc.OrcFile; | ||
| import org.apache.orc.OrcProto; | ||
| import org.apache.orc.Reader; | ||
| import org.apache.orc.StripeInformation; | ||
| import org.apache.orc.TypeDescription; | ||
| import org.apache.orc.impl.OrcIndex; | ||
| import org.apache.orc.impl.RecordReaderImpl; | ||
| import org.apache.orc.impl.WriterImpl; | ||
| import org.junit.Assert; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.rules.TemporaryFolder; | ||
|
|
||
| public class TestBloomFilter { | ||
| private static final Schema DATA_SCHEMA = | ||
| new Schema( | ||
| required(100, "id", Types.LongType.get()), | ||
| required(101, "name", Types.StringType.get()), | ||
| required(102, "price", Types.DoubleType.get())); | ||
|
|
||
| @Rule public TemporaryFolder temp = new TemporaryFolder(); | ||
|
|
||
| @Test | ||
| public void testWriteOption() throws Exception { | ||
| File testFile = temp.newFile(); | ||
| Assert.assertTrue("Delete should succeed", testFile.delete()); | ||
|
|
||
| OutputFile outFile = Files.localOutput(testFile); | ||
| try (FileAppender<Record> writer = | ||
| ORC.write(outFile) | ||
| .createWriterFunc(GenericOrcWriter::buildWriter) | ||
| .schema(DATA_SCHEMA) | ||
| .set("write.orc.bloom.filter.columns", "id,name") | ||
| .set("write.orc.bloom.filter.fpp", "0.04") | ||
| .build()) { | ||
|
|
||
| Class clazzOrcFileAppender = Class.forName("org.apache.iceberg.orc.OrcFileAppender"); | ||
| Field writerField = clazzOrcFileAppender.getDeclaredField("writer"); | ||
| writerField.setAccessible(true); | ||
| WriterImpl orcWriter = (WriterImpl) writerField.get(writer); | ||
|
|
||
| Class clazzWriterImpl = Class.forName("org.apache.orc.impl.WriterImpl"); | ||
| Field bloomFilterColumnsField = clazzWriterImpl.getDeclaredField("bloomFilterColumns"); | ||
| Field bloomFilterFppField = clazzWriterImpl.getDeclaredField("bloomFilterFpp"); | ||
| bloomFilterColumnsField.setAccessible(true); | ||
| bloomFilterFppField.setAccessible(true); | ||
| boolean[] bloomFilterColumns = (boolean[]) bloomFilterColumnsField.get(orcWriter); | ||
| double bloomFilterFpp = (double) bloomFilterFppField.get(orcWriter); | ||
|
|
||
| // Validate whether the bloom filters are set in ORC SDK or not | ||
| Assert.assertTrue(bloomFilterColumns[1]); | ||
| Assert.assertTrue(bloomFilterColumns[2]); | ||
| Assert.assertEquals(0.04, bloomFilterFpp, 1e-15); | ||
|
|
||
| Record recordTemplate = GenericRecord.create(DATA_SCHEMA); | ||
| Record record1 = recordTemplate.copy("id", 1L, "name", "foo", "price", 1.0); | ||
| Record record2 = recordTemplate.copy("id", 2L, "name", "bar", "price", 2.0); | ||
| writer.add(record1); | ||
| writer.add(record2); | ||
| } | ||
|
|
||
| Class clazzFileDump = Class.forName("org.apache.orc.tools.FileDump"); | ||
| Method getFormattedBloomFilters = | ||
| clazzFileDump.getDeclaredMethod( | ||
| "getFormattedBloomFilters", | ||
| int.class, | ||
| OrcIndex.class, | ||
| OrcFile.WriterVersion.class, | ||
| TypeDescription.Category.class, | ||
| OrcProto.ColumnEncoding.class); | ||
| getFormattedBloomFilters.setAccessible(true); | ||
|
|
||
| try (Reader reader = | ||
| OrcFile.createReader( | ||
| new Path(outFile.location()), new OrcFile.ReaderOptions(new Configuration())); ) { | ||
| boolean[] readCols = new boolean[] {false, true, true, false}; | ||
| RecordReaderImpl rows = (RecordReaderImpl) reader.rows(); | ||
| OrcIndex indices = rows.readRowIndex(0, null, readCols); | ||
| StripeInformation stripe = reader.getStripes().get(0); | ||
| OrcProto.StripeFooter footer = rows.readStripeFooter(stripe); | ||
|
|
||
| String bloomFilterString = | ||
| (String) | ||
| getFormattedBloomFilters.invoke( | ||
| null, | ||
| 1, | ||
| indices, | ||
| reader.getWriterVersion(), | ||
| reader.getSchema().findSubtype(1).getCategory(), | ||
| footer.getColumns(1)); | ||
|
|
||
| // Validate whether the bloom filters are written ORC files or not | ||
| Assert.assertTrue(bloomFilterString.contains("Bloom filters for column")); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testInvalidFppOption() throws Exception { | ||
| File testFile = temp.newFile(); | ||
| Assert.assertTrue("Delete should succeed", testFile.delete()); | ||
|
|
||
| try (FileAppender<Record> writer = | ||
| ORC.write(Files.localOutput(testFile)) | ||
| .createWriterFunc(GenericOrcWriter::buildWriter) | ||
| .schema(DATA_SCHEMA) | ||
| .set("write.orc.bloom.filter.columns", "id,name") | ||
| .set("write.orc.bloom.filter.fpp", "-1") | ||
| .build()) { | ||
| Assert.fail("Expected exception"); | ||
| } catch (IllegalArgumentException e) { | ||
| Assert.assertTrue(e.getMessage().contains("Bloom filter fpp must be > 0.0 and < 1.0")); | ||
| } | ||
| } | ||
| } |
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.