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


##########
datafusion/core/src/physical_plan/file_format/csv.rs:
##########
@@ -224,20 +240,38 @@ impl FileOpener for CsvOpener {
             match config.object_store.get(file_meta.location()).await? {
                 GetResult::File(file, _) => {
                     let decoder = file_compression_type.convert_read(file)?;
-                    Ok(futures::stream::iter(config.open(decoder, 
true)).boxed())
+                    Ok(futures::stream::iter(config.open(decoder)).boxed())
                 }
                 GetResult::Stream(s) => {
-                    let mut first_chunk = true;
-                    let s = s.map_err(Into::<DataFusionError>::into);
-                    let decoder = file_compression_type.convert_stream(s)?;
-                    Ok(newline_delimited_stream(decoder)
-                        .map_ok(move |bytes| {
-                            let reader = config.open(bytes.reader(), 
first_chunk);
-                            first_chunk = false;
-                            futures::stream::iter(reader)
-                        })
-                        .try_flatten()
-                        .boxed())
+                    let mut decoder = config.builder().build_decoder();
+                    let s = s.map_err(DataFusionError::from);
+                    let mut input = 
file_compression_type.convert_stream(s)?.fuse();
+                    let mut buffered = Bytes::new();
+
+                    let s = futures::stream::poll_fn(move |cx| {
+                        loop {
+                            if buffered.is_empty() {
+                                buffered = match 
ready!(input.poll_next_unpin(cx)) {
+                                    Some(Ok(b)) => b,
+                                    Some(Err(e)) => {
+                                        return Poll::Ready(Some(Err(e.into())))
+                                    }
+                                    None => break,
+                                };
+                            }
+                            let decoded = match 
decoder.decode(buffered.as_ref()) {
+                                // Note: the decoder needs to be called with 
an empty
+                                // array to delimt the final record

Review Comment:
   You are quite correct, I'm investigating how this is working...



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to