viirya commented on code in PR #3909:
URL: https://github.com/apache/arrow-rs/pull/3909#discussion_r1145295299


##########
arrow-array/src/array/primitive_array.rs:
##########
@@ -251,19 +251,58 @@ pub struct PrimitiveArray<T: ArrowPrimitiveType> {
     /// Underlying ArrayData
     data: ArrayData,
     /// Values data
-    raw_values: ScalarBuffer<T::Native>,
+    values: ScalarBuffer<T::Native>,
 }
 
 impl<T: ArrowPrimitiveType> Clone for PrimitiveArray<T> {
     fn clone(&self) -> Self {
         Self {
             data: self.data.clone(),
-            raw_values: self.raw_values.clone(),
+            values: self.values.clone(),
         }
     }
 }
 
 impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
+    /// Create a new [`PrimitiveArray`] from the provided data_type, values, 
nulls
+    ///
+    /// # Panics
+    ///
+    /// Panics if:
+    /// - `values.len() != nulls.len()`
+    /// - `!Self::is_compatible(data_type)`
+    pub fn new(
+        data_type: DataType,
+        values: ScalarBuffer<T::Native>,
+        nulls: Option<NullBuffer>,
+    ) -> Self {
+        Self::assert_compatible(&data_type);
+        if let Some(n) = nulls.as_ref() {
+            assert_eq!(values.len(), n.len());
+        }
+
+        // TODO: Don't store ArrayData inside arrays (#3880)
+        let data = unsafe {
+            ArrayData::builder(data_type)
+                .len(values.len())
+                .nulls(nulls)
+                .buffers(vec![values.inner().clone()])
+                .build_unchecked()
+        };
+
+        Self { data, values }
+    }
+
+    /// Asserts that `data_type` is compatible with `Self`
+    fn assert_compatible(data_type: &DataType) {
+        assert!(
+            Self::is_compatible(data_type),
+            "PrimitiveArray expected ArrayData with type {} got {}",

Review Comment:
   ```suggestion
               "PrimitiveArray expected ScalarBuffer with type {} got {}",
   ```



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