MCPcopy Create free account
hub / github.com/apache/arrow-rs / into_builder

Method into_builder

arrow-data/src/transform/mod.rs:777–833  ·  view source on GitHub ↗

Consume self and returns the in progress array as [`ArrayDataBuilder`]. This is useful for extending the default behavior of MutableArrayData.

(self)

Source from the content-addressed store, hash-verified

775 ///
776 /// This is useful for extending the default behavior of MutableArrayData.
777 pub fn into_builder(self) -> ArrayDataBuilder {
778 let data = self.data;
779
780 let buffers = match data.data_type {
781 DataType::Null
782 | DataType::Struct(_)
783 | DataType::FixedSizeList(_, _)
784 | DataType::RunEndEncoded(_, _) => {
785 vec![]
786 }
787 DataType::BinaryView | DataType::Utf8View => {
788 let mut b = self.variadic_data_buffers;
789 b.insert(0, data.buffer1.into());
790 b
791 }
792 DataType::Utf8
793 | DataType::Binary
794 | DataType::LargeUtf8
795 | DataType::LargeBinary
796 | DataType::ListView(_)
797 | DataType::LargeListView(_) => {
798 vec![data.buffer1.into(), data.buffer2.into()]
799 }
800 DataType::Union(_, mode) => {
801 match mode {
802 // Based on Union's DataTypeLayout
803 UnionMode::Sparse => vec![data.buffer1.into()],
804 UnionMode::Dense => vec![data.buffer1.into(), data.buffer2.into()],
805 }
806 }
807 _ => vec![data.buffer1.into()],
808 };
809
810 let child_data = match data.data_type {
811 DataType::Dictionary(_, _) => vec![self.dictionary.unwrap()],
812 _ => data.child_data.into_iter().map(|x| x.freeze()).collect(),
813 };
814
815 let nulls = match data.data_type {
816 // RunEndEncoded, Null, and Union arrays cannot have top-level null bitmasks
817 DataType::RunEndEncoded(_, _) | DataType::Null | DataType::Union(_, _) => None,
818 _ => data
819 .null_buffer
820 .map(|nulls| {
821 let bools = BooleanBuffer::new(nulls.into(), 0, data.len);
822 unsafe { NullBuffer::new_unchecked(bools, data.null_count) }
823 })
824 .filter(|n| n.null_count() > 0),
825 };
826
827 ArrayDataBuilder::new(data.data_type)
828 .offset(0)
829 .len(data.len)
830 .nulls(nulls)
831 .buffers(buffers)
832 .child_data(child_data)
833 }
834}

Callers 1

freezeMethod · 0.45

Calls 11

collectMethod · 0.80
freezeMethod · 0.80
filterMethod · 0.80
child_dataMethod · 0.80
insertMethod · 0.45
into_iterMethod · 0.45
null_countMethod · 0.45
buffersMethod · 0.45
nullsMethod · 0.45
lenMethod · 0.45
offsetMethod · 0.45

Tested by

no test coverage detected