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

Function length

arrow-string/src/length.rs:56–127  ·  view source on GitHub ↗

Returns an array of Int32/Int64 denoting the length of each value in the array. For list array, length is the number of elements in each list. For string array and binary array, length is the number of bytes of each value. this only accepts ListArray/LargeListArray, StringArray/LargeStringArray/StringViewArray, BinaryArray/LargeBinaryArray, FixedSizeListArray, and ListViewArray/LargeListViewArra

(array: &dyn Array)

Source from the content-addressed store, hash-verified

54/// RunEndEncoded arrays with above arrays as values
55/// * length of null is null.
56pub fn length(array: &dyn Array) -> Result<ArrayRef, ArrowError> {
57 if let Some(d) = array.as_any_dictionary_opt() {
58 let lengths = length(d.values().as_ref())?;
59 return Ok(d.with_values(lengths));
60 }
61 if let Some(ree) = array.as_any_ree_opt() {
62 let lengths = length(ree.values())?;
63 return Ok(ree.with_values(lengths));
64 }
65 match array.data_type() {
66 DataType::List(_) => {
67 let list = array.as_list::<i32>();
68 Ok(length_impl::<Int32Type>(list.offsets(), list.nulls()))
69 }
70 DataType::LargeList(_) => {
71 let list = array.as_list::<i64>();
72 Ok(length_impl::<Int64Type>(list.offsets(), list.nulls()))
73 }
74 DataType::ListView(_) => {
75 let list = array.as_list_view::<i32>();
76 Ok(Arc::new(Int32Array::new(
77 list.sizes().clone(),
78 list.nulls().cloned(),
79 )))
80 }
81 DataType::LargeListView(_) => {
82 let list = array.as_list_view::<i64>();
83 Ok(Arc::new(Int64Array::new(
84 list.sizes().clone(),
85 list.nulls().cloned(),
86 )))
87 }
88 DataType::Utf8 => {
89 let list = array.as_string::<i32>();
90 Ok(length_impl::<Int32Type>(list.offsets(), list.nulls()))
91 }
92 DataType::LargeUtf8 => {
93 let list = array.as_string::<i64>();
94 Ok(length_impl::<Int64Type>(list.offsets(), list.nulls()))
95 }
96 DataType::Utf8View => {
97 let list = array.as_string_view();
98 let v = list.views().iter().map(|v| *v as i32).collect::<Vec<_>>();
99 Ok(Arc::new(PrimitiveArray::<Int32Type>::try_new(
100 v.into(),
101 list.nulls().cloned(),
102 )?))
103 }
104 DataType::Binary => {
105 let list = array.as_binary::<i32>();
106 Ok(length_impl::<Int32Type>(list.offsets(), list.nulls()))
107 }
108 DataType::LargeBinary => {
109 let list = array.as_binary::<i64>();
110 Ok(length_impl::<Int64Type>(list.offsets(), list.nulls()))
111 }
112 DataType::FixedSizeBinary(len) | DataType::FixedSizeList(_, len) => Ok(Arc::new(
113 Int32Array::try_new(vec![*len; array.len()].into(), array.nulls().cloned())?,

Callers 15

bench_lengthFunction · 0.85
length_test_stringFunction · 0.85
length_test_large_stringFunction · 0.85
length_test_string_viewFunction · 0.85
length_test_binary_viewFunction · 0.85
length_null_stringFunction · 0.85
length_null_large_stringFunction · 0.85
length_test_list_viewFunction · 0.85
length_null_list_viewFunction · 0.85
length_offsets_stringFunction · 0.85

Calls 15

try_newFunction · 0.85
as_any_dictionary_optMethod · 0.80
as_any_ree_optMethod · 0.80
sizesMethod · 0.80
as_string_viewMethod · 0.80
viewsMethod · 0.80
as_binary_viewMethod · 0.80
as_refMethod · 0.45
valuesMethod · 0.45
with_valuesMethod · 0.45
data_typeMethod · 0.45
offsetsMethod · 0.45

Tested by 15

length_test_stringFunction · 0.68
length_test_large_stringFunction · 0.68
length_test_string_viewFunction · 0.68
length_test_binary_viewFunction · 0.68
length_null_stringFunction · 0.68
length_null_large_stringFunction · 0.68
length_test_list_viewFunction · 0.68
length_null_list_viewFunction · 0.68
length_offsets_stringFunction · 0.68
length_offsets_binaryFunction · 0.68