apache / apache/parquet-java

NPE in ParquetInputFormat.getSplits when no .parquet files exist

Open
#1,821 2 comments 0 reactions 0 assignees View on GitHub
Component: Parquet Priority: Major Type: bug
Dominant language
Java
Stars
3.1k
Forks
1.6k
Avg merge
3d 12h
Merged PRs (30d)
33

Description

```Java
JavaSparkContext context = ...
JavaRDD rdd1 = context.parallelize(ImmutableList. of());
SQLContext sqlContext = new SQLContext(context);
StructType schema = DataTypes.createStructType(ImmutableList.of(DataTypes.createStructField("col1", DataTypes.StringType, true)));
DataFrame df = sqlContext.createDataFrame(rdd1, schema);
String url = "file:///tmp/emptyRDD";
df.saveAsParquetFile(url);

Configuration configuration = SparkHadoopUtil.get().newConfiguration(context.getConf());
JobConf jobConf = new JobConf(configuration);
ParquetInputFormat.setReadSupportClass(jobConf, RowReadSupport.class);
FileInputFormat.setInputPaths(jobConf, url);
JavaRDD rdd2 = context.newAPIHadoopRDD(
jobConf, ParquetInputFormat.class, Void.class, Row.class).values();
rdd2.count();

df = sqlContext.createDataFrame(rdd2, schema);
url = "file:///tmp/emptyRDD2";
df.saveAsParquetFile(url);

FileInputFormat.setInputPaths(jobConf, url);
JavaRDD rdd3 = context.newAPIHadoopRDD(
jobConf, ParquetInputFormat.class, Void.class, Row.class).values();
rdd3.count();
```

The NPE happens here:
```Java
java.lang.NullPointerException
at parquet.hadoop.ParquetInputFormat.getSplits(ParquetInputFormat.java:263)
at parquet.hadoop.ParquetInputFormat.getSplits(ParquetInputFormat.java:245)
at org.apache.spark.rdd.NewHadoopRDD.getPartitions(NewHadoopRDD.scala:95)
```

This stems from ParquetFileWriter.getGlobalMetaData returning null when there are no footers to read.

**Reporter**: [Paul Nepywoda](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=pnepywoda)

**Note**: *This issue was originally created as [PARQUET-294](https://issues.apache.org/jira/browse/PARQUET-294). Please see the [migration documentation](https://issues.apache.org/jira/browse/PARQUET-2502) for further details.*

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with ParquetInputFormat.getSplits and trace how ParquetFileWriter.getGlobalMetaData is handled when no footers are found. Reproduce the provided empty-RDD sequence and verify that both rdd2.count() and rdd3.count() complete without a NullPointerException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
data-engineering
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.