vertexclique commented on a change in pull request #8561:
URL: https://github.com/apache/arrow/pull/8561#discussion_r517199502



##########
File path: rust/arrow/src/array/array.rs
##########
@@ -2319,13 +2221,24 @@ impl<T: ArrowPrimitiveType> From<ArrayDataRef> for 
DictionaryArray<T> {
             "DictionaryArray should contain a single child array (values)."
         );
 
-        let raw_values = data.buffers()[0].raw_data();
-        let dtype: &DataType = data.data_type();
-        let values = make_array(data.child_data()[0].clone());
-        if let DataType::Dictionary(_, _) = dtype {
+        if let DataType::Dictionary(key_data_type, _) = data.data_type() {
+            if key_data_type.as_ref() != &T::DATA_TYPE {
+                panic!("DictionaryArray's data type must match.")

Review comment:
       I don't think that unreachable is only for the inconsistent state. But 
we can leave it as panic here. I was also unsure about the user-facing API's 
panicking behavior. Especially in array methods with forced asserts. We should 
prefer Result than direct asserts, but you know... That's also yet another 
topic.

##########
File path: rust/arrow/src/array/array.rs
##########
@@ -2398,30 +2311,23 @@ impl<T: ArrowPrimitiveType> Array for 
DictionaryArray<T> {
 
     /// Returns the total number of bytes of memory occupied by the buffers 
owned by this [DictionaryArray].
     fn get_buffer_memory_size(&self) -> usize {
-        self.data.get_buffer_memory_size() + 
self.values().get_buffer_memory_size()
+        // Since both `keys` and `values` derive (are references from) `data`, 
we only account for `data`.
+        self.data.get_array_memory_size()

Review comment:
       Voila! Yes.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to