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/06/07 18:32:26 UTC

[GitHub] [arrow-rs] tustvold opened a new pull request, #4382: Add MapArray constructors

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

   # 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.
   -->
   
   Closes #.
   
   # 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.
   -->
   
   # 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] tustvold merged pull request #4382: Add MapArray constructors and doc example

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


-- 
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 #4382: Add MapArray constructors

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


##########
arrow-array/src/array/list_array.rs:
##########
@@ -103,7 +104,7 @@ impl<OffsetSize: OffsetSizeTrait> GenericListArray<OffsetSize> {
         let len = offsets.len() - 1; // Offsets guaranteed to not be empty
         let end_offset = offsets.last().unwrap().as_usize();
         // don't need to check other values of `offsets` because they are checked
-        // during construction of `OffsetsbBuffer`
+        // during construction of `OffsetsBuffer`

Review Comment:
   ```suggestion
           // during construction of `OffsetBuffer`
   ```



-- 
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 #4382: Add MapArray constructors

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


##########
arrow-array/src/array/map_array.rs:
##########
@@ -19,16 +19,18 @@ use crate::array::{get_offsets, print_long_array};
 use crate::{make_array, Array, ArrayRef, ListArray, StringArray, StructArray};
 use arrow_buffer::{ArrowNativeType, Buffer, NullBuffer, OffsetBuffer, ToByteSlice};
 use arrow_data::{ArrayData, ArrayDataBuilder};
-use arrow_schema::{ArrowError, DataType, Field};
+use arrow_schema::{ArrowError, DataType, Field, FieldRef};
 use std::any::Any;
 use std::sync::Arc;
 
 /// An array of key-value maps
 ///
 /// Keys should always be non-null, but values can be null.
 ///
-/// [MapArray] is physically a [crate::array::ListArray] that has a
-/// [StructArray] with 2 child fields.
+/// [`MapArray`] is physically a [`ListArray`] of key values pairs stored as an `entries`
+/// [`StructArray`] with 2 child fields.
+///
+/// See [`MapBuilder`](crate::builder::MapBuilder) for how to construct a [`MapArray`]

Review Comment:
   I didn't see a compelling reason to duplicate the example already on MapBuilder



-- 
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 #4382: Add MapArray constructors

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


##########
arrow-array/src/array/map_array.rs:
##########
@@ -40,6 +40,106 @@ pub struct MapArray {
 }
 
 impl MapArray {
+    /// Create a new [`MapArray`] from the provided parts
+    ///
+    /// # Errors
+    ///
+    /// Errors if
+    ///
+    /// * `offsets.len() - 1 != nulls.len()`
+    /// * `offsets.last() > entries.len()`
+    /// * `field.is_nullable()`
+    /// * `entries.null_count() != 0`
+    /// * `entries.columns().len() != 2`
+    /// * `field.data_type() != entries.data_type()`
+    pub fn try_new(
+        field: FieldRef,
+        offsets: OffsetBuffer<i32>,
+        entries: StructArray,
+        nulls: Option<NullBuffer>,
+        ordered: bool,
+    ) -> Result<Self, ArrowError> {
+        let len = offsets.len() - 1; // Offsets guaranteed to not be empty
+        let end_offset = offsets.last().unwrap().as_usize();
+        // don't need to check other values of `offsets` because they are checked
+        // during construction of `OffsetsBuffer`

Review Comment:
   ```suggestion
           // during construction of `OffsetBuffer`
   ```



-- 
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 #4382: Add MapArray constructors

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


##########
arrow-array/src/array/map_array.rs:
##########
@@ -40,6 +40,106 @@ pub struct MapArray {
 }
 
 impl MapArray {
+    /// Create a new [`MapArray`] from the provided parts
+    ///
+    /// # Errors
+    ///
+    /// Errors if
+    ///
+    /// * `offsets.len() - 1 != nulls.len()`
+    /// * `offsets.last() > entries.len()`
+    /// * `field.is_nullable()`
+    /// * `entries.null_count() != 0`
+    /// * `entries.columns().len() != 2`
+    /// * `field.data_type() != entries.data_type()`
+    pub fn try_new(
+        field: FieldRef,
+        offsets: OffsetBuffer<i32>,
+        entries: StructArray,
+        nulls: Option<NullBuffer>,
+        ordered: bool,
+    ) -> Result<Self, ArrowError> {
+        let len = offsets.len() - 1; // Offsets guaranteed to not be empty
+        let end_offset = offsets.last().unwrap().as_usize();
+        // don't need to check other values of `offsets` because they are checked
+        // during construction of `OffsetsBuffer`
+        if end_offset > entries.len() {
+            return Err(ArrowError::InvalidArgumentError(format!(
+                "Max offset of {end_offset} exceeds length of entries {}",
+                entries.len()
+            )));
+        }
+
+        if let Some(n) = nulls.as_ref() {
+            if n.len() != len {
+                return Err(ArrowError::InvalidArgumentError(format!(
+                    "Incorrect length of null buffer for MapArray, expected {len} got {}",
+                    n.len(),
+                )));
+            }
+        }
+        if field.is_nullable() || entries.null_count() != 0 {
+            return Err(ArrowError::InvalidArgumentError(
+                "MapArray entries cannot contain be null".to_string(),

Review Comment:
   ```suggestion
                   "MapArray entries cannot contain null".to_string(),
   ```



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