getChan commented on code in PR #17861:
URL: https://github.com/apache/datafusion/pull/17861#discussion_r2971759286
##########
datafusion/datasource-avro/src/source.rs:
##########
@@ -56,21 +54,16 @@ impl AvroSource {
}
}
- fn open<R: std::io::Read>(&self, reader: R) -> Result<AvroReader<'static,
R>> {
- let file_schema = self.table_schema.file_schema();
- let projection = Some(
- self.projection
- .file_indices
- .iter()
- .map(|&idx| file_schema.field(idx).name().clone())
- .collect::<Vec<_>>(),
- );
- AvroReader::try_new(
- reader,
- &Arc::clone(self.table_schema.file_schema()),
- self.batch_size.expect("Batch size must set before open"),
- projection.as_ref(),
- )
+ fn open<R: std::io::BufRead>(&self, reader: R) -> Result<Reader<R>> {
+ let mut builder = ReaderBuilder::new()
+ .with_batch_size(self.batch_size.expect("Batch size must set
before open"));
+
+ // Avoid pushing an empty projection into arrow-avro.
+ if !self.projection.file_indices.is_empty() {
+ builder =
builder.with_projection(self.projection.file_indices.clone());
+ }
+
+ builder.build(reader).map_err(Into::into)
Review Comment:
To preserve backward compatibility, I addressed this in two parts:
1. Projection remains name-based by remapping the projected logical columns
to writer-schema ordinals before calling `with_projection(...)`.
2. I did not use `with_reader_schema(...)`, since that currently introduces
stricter Avro schema resolution than `main` has today, including record
name/namespace checks such as `writer=record1, reader=topLevelRecord`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]