Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.column.page;

import org.apache.parquet.column.ColumnDescriptor;

/**
* Interface to read dictionary pages for all the columns of a row group
*/
public interface DictionaryPageReadStore {

/**
* Returns a {@link DictionaryPage} for the given column descriptor.
* The dictionary page bytes are uncompressed.
*
* @param descriptor the descriptor of the column
* @return the DictionaryPage for that column, or null if there isn't one
*/
DictionaryPage readDictionaryPage(ColumnDescriptor descriptor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
package org.apache.parquet.filter2.compat;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.parquet.filter2.compat.FilterCompat.Filter;
import org.apache.parquet.filter2.compat.FilterCompat.NoOpFilter;
import org.apache.parquet.filter2.compat.FilterCompat.Visitor;
import org.apache.parquet.filter2.dictionarylevel.DictionaryFilter;
import org.apache.parquet.filter2.predicate.FilterPredicate;
import org.apache.parquet.filter2.predicate.SchemaCompatibilityValidator;
import org.apache.parquet.filter2.statisticslevel.StatisticsFilter;
import org.apache.parquet.hadoop.ParquetFileReader;
import org.apache.parquet.hadoop.metadata.BlockMetaData;
import org.apache.parquet.schema.MessageType;

Expand All @@ -40,15 +43,37 @@
public class RowGroupFilter implements Visitor<List<BlockMetaData>> {
private final List<BlockMetaData> blocks;
private final MessageType schema;
private final List<FilterLevel> levels;
private final ParquetFileReader reader;

public enum FilterLevel {
STATISTICS,
DICTIONARY
}

public static List<BlockMetaData> filterRowGroups(Filter filter, List<BlockMetaData> blocks, MessageType schema) {
checkNotNull(filter, "filter");
return filter.accept(new RowGroupFilter(blocks, schema));
}

public static List<BlockMetaData> filterRowGroups(List<FilterLevel> levels, Filter filter, List<BlockMetaData> blocks, ParquetFileReader reader) {
checkNotNull(filter, "filter");
return filter.accept(new RowGroupFilter(levels, blocks, reader));
}

@Deprecated
private RowGroupFilter(List<BlockMetaData> blocks, MessageType schema) {
this.blocks = checkNotNull(blocks, "blocks");
this.schema = checkNotNull(schema, "schema");
this.levels = Collections.singletonList(FilterLevel.STATISTICS);
this.reader = null;
}

private RowGroupFilter(List<FilterLevel> levels, List<BlockMetaData> blocks, ParquetFileReader reader) {
this.blocks = checkNotNull(blocks, "blocks");
this.reader = checkNotNull(reader, "reader");
this.schema = reader.getFileMetaData().getSchema();
this.levels = levels;
}

@Override
Expand All @@ -61,7 +86,17 @@ public List<BlockMetaData> visit(FilterCompat.FilterPredicateCompat filterPredic
List<BlockMetaData> filteredBlocks = new ArrayList<BlockMetaData>();

for (BlockMetaData block : blocks) {
if (!StatisticsFilter.canDrop(filterPredicate, block.getColumns())) {
boolean drop = false;

if(levels.contains(FilterLevel.STATISTICS)) {
drop = StatisticsFilter.canDrop(filterPredicate, block.getColumns());
}

if(!drop && levels.contains(FilterLevel.DICTIONARY)) {
drop = DictionaryFilter.canDrop(filterPredicate, block.getColumns(), reader.getDictionaryReader(block));
}

if(!drop) {
filteredBlocks.add(block);
}
}
Expand Down
Loading