Skip to content

[Bug]: ParquetIO failing to read with specified schema #27234

Open

Description

@vilas1999

What happened?

Reading from parquet file is failing with following exception

java.lang.ArrayIndexOutOfBoundsException: 3
org.apache.beam.sdk.Pipeline$PipelineExecutionException: java.lang.ArrayIndexOutOfBoundsException: 3
    at org.apache.beam.runners.direct.DirectRunner$DirectPipelineResult.waitUntilFinish(DirectRunner.java:371)
    at org.apache.beam.runners.direct.DirectRunner$DirectPipelineResult.waitUntilFinish(DirectRunner.java:339)
    at org.apache.beam.runners.direct.DirectRunner.run(DirectRunner.java:219)
    at org.apache.beam.runners.direct.DirectRunner.run(DirectRunner.java:67)

I'm trying to read a parquet file in Apache beam using following code snippet

String path = "pathToFile";
Schema schema = ReflectData.get().getSchema(EntityClass.class)

PCollection<GenericRecord> records = pipeline.apply("read a file", ParquetIO.read(schema).from(path));

pipeline.run().waitUntilFinish();

The above code is failing to read the after adding new fields to the java class.

Previous java class:

@With
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ParametersAreNonnullByDefault
@DefaultSchema(JavaBeanSchema.class)
public class EntityClass {
    
    private String firstName;
    
    private String middleName;
    
}    

Unable to read after making this change to the java class

@With
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ParametersAreNonnullByDefault
@DefaultSchema(JavaBeanSchema.class)
public class EntityClass {

    private String firstName;

    private String middleName;

    @Nullable
    @org.apache.avro.reflect.Nullable
    private String lastName;
}

The schema generated from reflection seems to be fine.

{
    "type": "record",
    "name": "EntityClass",
    "namespace": "com.test.entityclass",
    "fields": [{
        "name": "firstName",
        "type": "string"
    }, {
        "name": "middleName",
        "type": "string"
    }, {
        "name": "lastName",
        "type": ["null", "string"],
        "default": null
    }]
}

When trying to debug, in ParquetIO.java#L797 the here is still picked up from parquet file instead of the specified schema.

However, when trying to use AvroReader outside Beam, specifying the schema in AvroParquetSupport is required to support schema change as shown below:

AvroReadSupport.setAvroReadSchema(conf, NEW_SCHEMA);

try (ParquetReader<GenericRecord> reader = AvroParquetReader.<GenericRecord>builder(dataFile)
                .withConf(conf)
                .build()) {

GenericRecord genericRecord;
while ((genericRecord = reader.read()) != null) {
     //System.out.println(genericRecord.getSchema());
     T result = apply((GenericRecord) genericRecord.get("payload"), clazz);
     resultFiles.add(result);
   }
}

Specifying the schema in AvroReadSupport could be a potential solution if this is a genuine bug.

Issue Priority

Priority: 2 (default / most bugs should be filed as P2)

Issue Components

  • Component: Python SDK
  • Component: Java SDK
  • Component: Go SDK
  • Component: Typescript SDK
  • Component: IO connector
  • Component: Beam examples
  • Component: Beam playground
  • Component: Beam katas
  • Component: Website
  • Component: Spark Runner
  • Component: Flink Runner
  • Component: Samza Runner
  • Component: Twister2 Runner
  • Component: Hazelcast Jet Runner
  • Component: Google Cloud Dataflow Runner

Activity

  1. changed the title [-][Bug]: [/-] [+][Bug]: ParquetIO failing to read with specified schema[/+] on Jun 23, 2023
  2. mxtymoshyk commented on Sep 29, 2026

    @mxtymoshyk
    Contributor

    .take-issue

  3. added 6 commits that reference this issue on Oct 1, 2026
    29b05c2
    fcd6608
    5c16656
    092e2ca
    f92c677
    5b759bf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions