alamb commented on a change in pull request #1138:
URL: https://github.com/apache/arrow-datafusion/pull/1138#discussion_r732651297



##########
File path: datafusion/src/physical_plan/file_format/file_stream.rs
##########
@@ -0,0 +1,274 @@
+// 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.
+
+//! A generic stream over file format readers that can be used by
+//! any file format that read its files from start to end.
+//!
+//! Note: Most traits here need to be marked `Sync + Send` to be
+//! compliant with the `SendableRecordBatchStream` trait.
+
+use crate::{
+    datasource::{object_store::ObjectStore, PartitionedFile},
+    error::Result as DataFusionResult,
+    physical_plan::RecordBatchStream,
+};
+use arrow::{
+    datatypes::SchemaRef,
+    error::{ArrowError, Result as ArrowResult},
+    record_batch::RecordBatch,
+};
+use futures::Stream;
+use std::{
+    io::Read,
+    iter,
+    pin::Pin,
+    sync::Arc,
+    task::{Context, Poll},
+};
+
+pub type FileIter =
+    Box<dyn Iterator<Item = DataFusionResult<Box<dyn Read + Send + Sync>>> + 
Send + Sync>;
+pub type BatchIter = Box<dyn Iterator<Item = ArrowResult<RecordBatch>> + Send 
+ Sync>;
+
+/// A stream that iterates record batch by record batch, file over file.
+pub struct FileStream<F>
+where
+    F: FnMut(Box<dyn Read + Send + Sync>, &Option<usize>) -> BatchIter

Review comment:
       I guess I was imagining that the configuration / file format differences 
would handled by some closure for each format that would take a file reader and 
produce an appropriate `BatchIterator`
   
   Or put another way, it might be possible to move the code that loops over 
each `Read` (aka File) and returned a `BatchIterator` into the different 
formats (Csv, Avro, etc)
   
   However, this would make the formats somewhat more complicated, so it would 
be a tradeoff.
   
   I think what you have here is good and I think giving the closure a name 
makes the code more readable 👍 




-- 
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]


Reply via email to