tustvold commented on code in PR #8021:
URL: https://github.com/apache/arrow-datafusion/pull/8021#discussion_r1392548594


##########
datafusion/core/src/datasource/stream.rs:
##########
@@ -149,11 +118,55 @@ impl StreamConfig {
         self
     }
 
+    /// Specify whether the file has a header (only applicable for 
[`StreamEncoding::Csv`])
+    pub fn with_header(mut self, header: bool) -> Self {
+        self.header = header;
+        self
+    }
+
     /// Specify an encoding for the stream
     pub fn with_encoding(mut self, encoding: StreamEncoding) -> Self {
         self.encoding = encoding;
         self
     }
+
+    fn reader(&self) -> Result<Box<dyn RecordBatchReader>> {
+        let file = File::open(&self.location)?;
+        let schema = self.schema.clone();
+        match &self.encoding {
+            StreamEncoding::Csv => {
+                let reader = arrow::csv::ReaderBuilder::new(schema)
+                    .with_header(self.header)
+                    .build(file)?;
+
+                Ok(Box::new(reader))
+            }
+            StreamEncoding::Json => {
+                let reader = arrow::json::ReaderBuilder::new(schema)
+                    .build(BufReader::new(file))?;
+
+                Ok(Box::new(reader))
+            }
+        }
+    }
+
+    fn writer(&self) -> Result<Box<dyn RecordBatchWriter>> {
+        match &self.encoding {
+            StreamEncoding::Csv => {
+                let header = self.header && !self.location.exists();

Review Comment:
   I wasn't entirely sure about this, CsvSink currently has the following logic
   
   ```
   let serializer: Box<dyn BatchSerializer> = Box::new(if file_size > 0 {
       CsvSerializer::new()
           .with_builder(inner_clone)
           .with_header(false)
   } else {
       CsvSerializer::new()
           .with_builder(inner_clone)
           .with_header(options_clone.writer_options.header())
   });
   ```
   



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