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

Function into_parts

arrow-array/src/array/union_array.rs:1770–1810  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1768
1769 #[test]
1770 fn into_parts() {
1771 let mut builder = UnionBuilder::new_dense();
1772 builder.append::<Int32Type>("a", 1).unwrap();
1773 builder.append::<Int8Type>("b", 2).unwrap();
1774 builder.append::<Int32Type>("a", 3).unwrap();
1775 let dense_union = builder.build().unwrap();
1776
1777 let field = [
1778 &Arc::new(Field::new("a", DataType::Int32, false)),
1779 &Arc::new(Field::new("b", DataType::Int8, false)),
1780 ];
1781 let (union_fields, type_ids, offsets, children) = dense_union.into_parts();
1782 assert_eq!(
1783 union_fields
1784 .iter()
1785 .map(|(_, field)| field)
1786 .collect::<Vec<_>>(),
1787 field
1788 );
1789 assert_eq!(type_ids, [0, 1, 0]);
1790 assert!(offsets.is_some());
1791 assert_eq!(offsets.as_ref().unwrap(), &[0, 0, 1]);
1792
1793 let result = UnionArray::try_new(union_fields, type_ids, offsets, children);
1794 assert!(result.is_ok());
1795 assert_eq!(result.unwrap().len(), 3);
1796
1797 let mut builder = UnionBuilder::new_sparse();
1798 builder.append::<Int32Type>("a", 1).unwrap();
1799 builder.append::<Int8Type>("b", 2).unwrap();
1800 builder.append::<Int32Type>("a", 3).unwrap();
1801 let sparse_union = builder.build().unwrap();
1802
1803 let (union_fields, type_ids, offsets, children) = sparse_union.into_parts();
1804 assert_eq!(type_ids, [0, 1, 0]);
1805 assert!(offsets.is_none());
1806
1807 let result = UnionArray::try_new(union_fields, type_ids, offsets, children);
1808 assert!(result.is_ok());
1809 assert_eq!(result.unwrap().len(), 3);
1810 }
1811
1812 #[test]
1813 fn into_parts_custom_type_ids() {

Callers

nothing calls this directly

Calls 3

try_newFunction · 0.85
buildMethod · 0.45
into_partsMethod · 0.45

Tested by

no test coverage detected