Skip to content
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

PARQUET-2219: ParquetFileReader skips empty row group #1018

Merged
merged 3 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

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

import org.apache.parquet.ParquetRuntimeException;

public class ParquetEmptyBlockException extends ParquetRuntimeException {
private static final long serialVersionUID = 1L;

public ParquetEmptyBlockException() {
}

public ParquetEmptyBlockException(String message, Throwable cause) {
super(message, cause);
}

public ParquetEmptyBlockException(String message) {
super(message);
}

public ParquetEmptyBlockException(Throwable cause) {
super(cause);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.CRC32;

import org.apache.hadoop.conf.Configuration;
Expand Down Expand Up @@ -927,7 +925,15 @@ public PageReadStore readRowGroup(int blockIndex) throws IOException {
* @return the PageReadStore which can provide PageReaders for each column.
*/
public PageReadStore readNextRowGroup() throws IOException {
ColumnChunkPageReadStore rowGroup = internalReadRowGroup(currentBlock);
ColumnChunkPageReadStore rowGroup = null;
try {
rowGroup = internalReadRowGroup(currentBlock);
} catch (ParquetEmptyBlockException e) {
LOG.warn("Read empty block at index {}", currentBlock);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way to add file path?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the file path to the log. Please take a look again. Thanks!

advanceToNextBlock();
return readNextRowGroup();
}

if (rowGroup == null) {
return null;
}
Expand All @@ -948,7 +954,7 @@ private ColumnChunkPageReadStore internalReadRowGroup(int blockIndex) throws IOE
}
BlockMetaData block = blocks.get(blockIndex);
if (block.getRowCount() == 0) {
throw new RuntimeException("Illegal row group of 0 rows");
throw new ParquetEmptyBlockException("Illegal row group of 0 rows");
}
ColumnChunkPageReadStore rowGroup = new ColumnChunkPageReadStore(block.getRowCount(), block.getRowIndexOffset());
// prepare the list of consecutive parts to read them in one scan
Expand Down Expand Up @@ -1001,7 +1007,7 @@ public PageReadStore readFilteredRowGroup(int blockIndex) throws IOException {

BlockMetaData block = blocks.get(blockIndex);
if (block.getRowCount() == 0) {
throw new RuntimeException("Illegal row group of 0 rows");
throw new ParquetEmptyBlockException("Illegal row group of 0 rows");
}

RowRanges rowRanges = getRowRanges(blockIndex);
Expand Down Expand Up @@ -1038,7 +1044,9 @@ public PageReadStore readNextFilteredRowGroup() throws IOException {
}
BlockMetaData block = blocks.get(currentBlock);
if (block.getRowCount() == 0L) {
throw new RuntimeException("Illegal row group of 0 rows");
// Skip the empty block
advanceToNextBlock();
return readNextFilteredRowGroup();
wgtmac marked this conversation as resolved.
Show resolved Hide resolved
}
RowRanges rowRanges = getRowRanges(currentBlock);
long rowCount = rowRanges.rowCount();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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.hadoop;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.parquet.column.page.PageReadStore;
import org.apache.parquet.hadoop.metadata.ParquetMetadata;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;
import java.net.URISyntaxException;

public class TestParquetReaderEmptyBlock {

private static final Path EMPTY_BLOCK_FILE_1 = createPathFromCP("/test-empty-row-group_1.parquet");

private static final Path EMPTY_BLOCK_FILE_2 = createPathFromCP("/test-empty-row-group_2.parquet");

private static Path createPathFromCP(String path) {
try {
return new Path(TestParquetReaderEmptyBlock.class.getResource(path).toURI());
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}

@Test
public void testReadOnlyEmptyBlock() throws IOException {
Configuration conf = new Configuration();
ParquetMetadata readFooter = ParquetFileReader.readFooter(conf, EMPTY_BLOCK_FILE_1);

// The parquet file contains only one empty row group
Assert.assertEquals(1, readFooter.getBlocks().size());

// The empty block is skipped
try (ParquetFileReader r = new ParquetFileReader(conf, EMPTY_BLOCK_FILE_1, readFooter)) {
Assert.assertNull(r.readNextRowGroup());
}
}

@Test
public void testSkipEmptyBlock() throws IOException {
Configuration conf = new Configuration();
ParquetMetadata readFooter = ParquetFileReader.readFooter(conf, EMPTY_BLOCK_FILE_2);

// The parquet file contains three row groups, the second one is empty
wgtmac marked this conversation as resolved.
Show resolved Hide resolved
Assert.assertEquals(3, readFooter.getBlocks().size());

// Second row group is empty and skipped
try (ParquetFileReader r = new ParquetFileReader(conf, EMPTY_BLOCK_FILE_2, readFooter)) {
PageReadStore pages = null;
pages = r.readNextRowGroup();
Assert.assertNotNull(pages);
Assert.assertEquals(1, pages.getRowCount());

pages = r.readNextRowGroup();
Assert.assertNotNull(pages);
Assert.assertEquals(1, pages.getRowCount());

pages = r.readNextRowGroup();
Assert.assertNull(pages);
}
}

}
Binary file not shown.
Binary file not shown.