adriangb commented on code in PR #9138: URL: https://github.com/apache/arrow-rs/pull/9138#discussion_r2679000625
########## arrow-array/src/heap_size.rs: ########## @@ -0,0 +1,220 @@ +// 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. + +//! [`HeapSize`] implementations for arrow-array types + +use arrow_memory_size::HeapSize; + +use crate::Array; +use crate::types::{ArrowDictionaryKeyType, ArrowPrimitiveType, RunEndIndexType}; +use crate::{ + BinaryArray, BinaryViewArray, BooleanArray, DictionaryArray, FixedSizeBinaryArray, + FixedSizeListArray, LargeBinaryArray, LargeListArray, LargeListViewArray, LargeStringArray, + ListArray, ListViewArray, MapArray, NullArray, PrimitiveArray, RunArray, StringArray, + StringViewArray, StructArray, UnionArray, +}; + +// Note: HeapSize cannot be implemented for ArrayRef (Arc<dyn Array>) here due to +// Rust's orphan rules. Use array.get_buffer_memory_size() directly instead. + +// ============================================================================= +// Primitive and Boolean Arrays +// ============================================================================= + +impl<T: ArrowPrimitiveType> HeapSize for PrimitiveArray<T> { + fn heap_size(&self) -> usize { + self.get_buffer_memory_size() + } +} + +impl HeapSize for BooleanArray { + fn heap_size(&self) -> usize { + self.get_buffer_memory_size() + } +} + +impl HeapSize for NullArray { + fn heap_size(&self) -> usize { + // NullArray has no buffers + 0 + } +} + +// ============================================================================= +// String and Binary Arrays +// ============================================================================= + +impl HeapSize for StringArray { + fn heap_size(&self) -> usize { + self.get_buffer_memory_size() + } +} Review Comment: This could probably be a blanket implementation: ```rust impl<T> HeapSize for T where T: Array ``` -- 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]
