You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "tustvold (via GitHub)" <gi...@apache.org> on 2023/05/22 14:25:21 UTC

[GitHub] [arrow-rs] tustvold opened a new pull request, #4259: Extract IPC ArrayReader struct

tustvold opened a new pull request, #4259:
URL: https://github.com/apache/arrow-rs/pull/4259

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Relates to #4255
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   Whilst investigating #4255 I realised this code has naturally grown to the point of it now being quite hard to follow. This is the first of what will probably be a series of PRs to 
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking change` label.
   -->
   


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


[GitHub] [arrow-rs] viirya commented on a diff in pull request #4259: Extract IPC ArrayReader struct

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #4259:
URL: https://github.com/apache/arrow-rs/pull/4259#discussion_r1201092414


##########
arrow-ipc/src/reader.rs:
##########
@@ -628,14 +395,108 @@ fn create_dictionary_array(
     }
 }
 
+/// State for decoding arrays from an encoded [`RecordBatch`]
+struct ArrayReader<'a> {
+    /// Decoded dictionaries indexed by dictionary id
+    dictionaries_by_id: &'a HashMap<i64, ArrayRef>,
+    /// Optional compression codec
+    compression: Option<CompressionCodec>,
+    /// The format version
+    version: MetadataVersion,
+    /// The raw data buffer
+    data: &'a Buffer,
+    /// The fields comprising this array
+    nodes: VectorIter<'a, FieldNode>,
+    /// The buffers comprising this array
+    buffers: VectorIter<'a, crate::Buffer>,
+}
+
+impl<'a> ArrayReader<'a> {
+    fn next_buffer(&mut self) -> Result<Buffer, ArrowError> {
+        read_buffer(self.buffers.next().unwrap(), &self.data, self.compression)
+    }
+
+    fn skip_buffer(&mut self) {
+        self.buffers.next().unwrap();
+    }
+
+    fn next_node(&mut self, field: &Field) -> Result<&'a FieldNode, ArrowError> {
+        self.nodes.next().ok_or_else(|| {
+            ArrowError::IoError(format!(
+                "Invalid data for schema. {} refers to node not found in schema",
+                field
+            ))
+        })
+    }
+
+    fn skip_node(&mut self, field: &Field) -> Result<(), ArrowError> {

Review Comment:
   I feel original name `skip_field` is more proper because it skips both buffer and node, but okay for `skip_node`.



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


[GitHub] [arrow-rs] viirya commented on a diff in pull request #4259: Extract IPC ArrayReader struct

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #4259:
URL: https://github.com/apache/arrow-rs/pull/4259#discussion_r1201092414


##########
arrow-ipc/src/reader.rs:
##########
@@ -628,14 +395,108 @@ fn create_dictionary_array(
     }
 }
 
+/// State for decoding arrays from an encoded [`RecordBatch`]
+struct ArrayReader<'a> {
+    /// Decoded dictionaries indexed by dictionary id
+    dictionaries_by_id: &'a HashMap<i64, ArrayRef>,
+    /// Optional compression codec
+    compression: Option<CompressionCodec>,
+    /// The format version
+    version: MetadataVersion,
+    /// The raw data buffer
+    data: &'a Buffer,
+    /// The fields comprising this array
+    nodes: VectorIter<'a, FieldNode>,
+    /// The buffers comprising this array
+    buffers: VectorIter<'a, crate::Buffer>,
+}
+
+impl<'a> ArrayReader<'a> {
+    fn next_buffer(&mut self) -> Result<Buffer, ArrowError> {
+        read_buffer(self.buffers.next().unwrap(), &self.data, self.compression)
+    }
+
+    fn skip_buffer(&mut self) {
+        self.buffers.next().unwrap();
+    }
+
+    fn next_node(&mut self, field: &Field) -> Result<&'a FieldNode, ArrowError> {
+        self.nodes.next().ok_or_else(|| {
+            ArrowError::IoError(format!(
+                "Invalid data for schema. {} refers to node not found in schema",
+                field
+            ))
+        })
+    }
+
+    fn skip_node(&mut self, field: &Field) -> Result<(), ArrowError> {

Review Comment:
   I feel original name `skip_field` is more proper, but okay for `skip_node`.



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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4259: Extract IPC ArrayReader struct

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4259:
URL: https://github.com/apache/arrow-rs/pull/4259#discussion_r1200593962


##########
arrow-ipc/src/reader.rs:
##########
@@ -628,14 +395,108 @@ fn create_dictionary_array(
     }
 }
 
+/// State for decoding arrays from an encoded [`RecordBatch`]
+struct ArrayReader<'a> {
+    /// Decoded dictionaries indexed by dictionary id
+    dictionaries_by_id: &'a HashMap<i64, ArrayRef>,
+    /// Optional compression codec
+    compression: Option<CompressionCodec>,
+    /// The format version
+    version: MetadataVersion,
+    /// The raw data buffer
+    data: &'a Buffer,
+    /// The fields comprising this array
+    nodes: VectorIter<'a, FieldNode>,
+    /// The buffers comprising this array
+    buffers: VectorIter<'a, crate::Buffer>,
+}
+
+impl<'a> ArrayReader<'a> {
+    fn next_buffer(&mut self) -> Result<Buffer, ArrowError> {
+        read_buffer(self.buffers.next().unwrap(), &self.data, self.compression)
+    }
+
+    fn skip_buffer(&mut self) {
+        self.buffers.next().unwrap();
+    }
+
+    fn next_node(&mut self, field: &Field) -> Result<&'a FieldNode, ArrowError> {
+        self.nodes.next().ok_or_else(|| {
+            ArrowError::IoError(format!(
+                "Invalid data for schema. {} refers to node not found in schema",
+                field
+            ))
+        })
+    }
+
+    fn skip_node(&mut self, field: &Field) -> Result<(), ArrowError> {

Review Comment:
   This moved from skip_field



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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4259: Extract IPC ArrayReader struct

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4259:
URL: https://github.com/apache/arrow-rs/pull/4259#discussion_r1200593185


##########
arrow-ipc/src/reader.rs:
##########
@@ -334,125 +205,21 @@ fn create_array(
                 .offset(0)
                 .build()
                 .unwrap();
-            node_index += 1;
             // no buffer increases
-            make_array(data)
-        }
-        _ => {
-            if nodes.len() <= node_index {
-                return Err(ArrowError::IoError(format!(
-                    "Invalid data for schema. {} refers to node index {} but only {} in schema",
-                    field, node_index, nodes.len()
-                )));
-            }
-            let array = create_primitive_array(
-                nodes.get(node_index),
-                data_type,
-                &[
-                    read_buffer(buffers.get(buffer_index), data, compression_codec)?,
-                    read_buffer(buffers.get(buffer_index + 1), data, compression_codec)?,
-                ],
-            )?;
-            node_index += 1;
-            buffer_index += 2;
-            array
-        }
-    };
-    Ok((array, node_index, buffer_index))
-}
-
-/// Skip fields based on data types to advance `node_index` and `buffer_index`.
-/// This function should be called when doing projection in fn `read_record_batch`.
-/// The advancement logic references fn `create_array`.
-fn skip_field(

Review Comment:
   This logic is moved into skip_node



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


[GitHub] [arrow-rs] viirya commented on pull request #4259: Extract IPC ArrayReader struct

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on PR #4259:
URL: https://github.com/apache/arrow-rs/pull/4259#issuecomment-1557674406

   I'll review this soon.


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


[GitHub] [arrow-rs] tustvold merged pull request #4259: Extract IPC ArrayReader struct

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold merged PR #4259:
URL: https://github.com/apache/arrow-rs/pull/4259


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