MCPcopy Create free account
hub / github.com/apache/datafusion / compact

Method compact

datafusion/common/src/scalar/mod.rs:4721–4799  ·  view source on GitHub ↗

Compacts the allocation referenced by `self` to the minimum, copying the data if necessary. This can be relevant when `self` is a list or contains a list as a nested value, as a single list holds an Arc to its entire original array buffer.

(&mut self)

Source from the content-addressed store, hash-verified

4719 /// This can be relevant when `self` is a list or contains a list as a nested value, as
4720 /// a single list holds an Arc to its entire original array buffer.
4721 pub fn compact(&mut self) {
4722 // copy_array_data + compact_view_buffers + downcast back, all in one step.
4723 macro_rules! compact_array {
4724 ($arr:expr, $from_type:ty, $($as_method:tt)+) => {
4725 *Arc::make_mut($arr) = ScalarValue::compact_view_buffers(
4726 Arc::new(<$from_type>::from(copy_array_data(&$arr.to_data()))) as ArrayRef,
4727 ).$($as_method)+.clone()
4728 };
4729 }
4730 match self {
4731 ScalarValue::Null
4732 | ScalarValue::Boolean(_)
4733 | ScalarValue::Float16(_)
4734 | ScalarValue::Float32(_)
4735 | ScalarValue::Float64(_)
4736 | ScalarValue::Decimal32(_, _, _)
4737 | ScalarValue::Decimal64(_, _, _)
4738 | ScalarValue::Decimal128(_, _, _)
4739 | ScalarValue::Decimal256(_, _, _)
4740 | ScalarValue::Int8(_)
4741 | ScalarValue::Int16(_)
4742 | ScalarValue::Int32(_)
4743 | ScalarValue::Int64(_)
4744 | ScalarValue::UInt8(_)
4745 | ScalarValue::UInt16(_)
4746 | ScalarValue::UInt32(_)
4747 | ScalarValue::UInt64(_)
4748 | ScalarValue::Date32(_)
4749 | ScalarValue::Date64(_)
4750 | ScalarValue::Time32Second(_)
4751 | ScalarValue::Time32Millisecond(_)
4752 | ScalarValue::Time64Microsecond(_)
4753 | ScalarValue::Time64Nanosecond(_)
4754 | ScalarValue::IntervalYearMonth(_)
4755 | ScalarValue::IntervalDayTime(_)
4756 | ScalarValue::IntervalMonthDayNano(_)
4757 | ScalarValue::DurationSecond(_)
4758 | ScalarValue::DurationMillisecond(_)
4759 | ScalarValue::DurationMicrosecond(_)
4760 | ScalarValue::DurationNanosecond(_)
4761 | ScalarValue::Utf8(_)
4762 | ScalarValue::LargeUtf8(_)
4763 | ScalarValue::Utf8View(_)
4764 | ScalarValue::TimestampSecond(_, _)
4765 | ScalarValue::TimestampMillisecond(_, _)
4766 | ScalarValue::TimestampMicrosecond(_, _)
4767 | ScalarValue::TimestampNanosecond(_, _)
4768 | ScalarValue::Binary(_)
4769 | ScalarValue::FixedSizeBinary(_, _)
4770 | ScalarValue::LargeBinary(_)
4771 | ScalarValue::BinaryView(_) => (),
4772 ScalarValue::FixedSizeList(arr) => {
4773 compact_array!(arr, FixedSizeListArray, as_fixed_size_list())
4774 }
4775 ScalarValue::List(arr) => compact_array!(arr, ListArray, as_list::<i32>()),
4776 ScalarValue::LargeList(arr) => {
4777 compact_array!(arr, LargeListArray, as_list::<i64>())
4778 }

Calls

no outgoing calls