You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/07/18 14:26:29 UTC

[GitHub] [arrow-datafusion] tustvold commented on a diff in pull request #2936: Add streaming JSON and CSV reading, `NewlineDelimitedStream' (#2935)

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


##########
datafusion/core/src/physical_plan/file_format/delimited_stream.rs:
##########
@@ -0,0 +1,215 @@
+// 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.
+
+use crate::error::{DataFusionError, Result};
+use bytes::Bytes;
+use futures::{Stream, StreamExt};
+use std::collections::VecDeque;
+
+/// The ASCII encoding of `"`
+const QUOTE: u8 = 34;
+
+/// The ASCII encoding of `\n`
+const NEWLINE: u8 = 10;
+
+/// The ASCII encoding of `\`
+const ESCAPE: u8 = 92;
+
+/// [`LineDelimiter`] is provided with a stream of [`Bytes`] and returns an iterator
+/// of [`Bytes`] containing a whole number of new line delimited records
+#[derive(Debug, Default)]
+struct LineDelimiter {
+    /// Complete chunks of [`Bytes`]
+    complete: VecDeque<Bytes>,
+    /// Remainder bytes that form the next record
+    remainder: Vec<u8>,

Review Comment:
   I think the copy is unavoidable as the nature of the remainder, is you need to take data from two separate `Bytes`. It should only be a single "line" though, and so should be relatively minor from a performance standpoint



-- 
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-unsubscribe@arrow.apache.org

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