Skip to content

Commit

Permalink
ARROW-10800 [Rust] [Parquet] Provide access to the elements of parque…
Browse files Browse the repository at this point in the history
…t::record::{List, Map}

Adds public functions for both List and Map that provide access to their internal vecs via a slice

Closes #8827 from seen/ARROW-10800-expose-elements

Authored-by: Sean Moran <sean.m.moran@gmail.com>
Signed-off-by: Neville Dipale <nevilledips@gmail.com>
  • Loading branch information
seen authored and nevi-me committed Dec 4, 2020
1 parent 1c47c19 commit 63144ad
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion rust/parquet/src/record/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ impl List {
pub fn len(&self) -> usize {
self.elements.len()
}

pub fn elements(&self) -> &[Field] {
self.elements.as_slice()
}
}

/// Constructs a `List` from the list of `fields` and returns it.
Expand Down Expand Up @@ -356,6 +360,10 @@ impl Map {
pub fn len(&self) -> usize {
self.entries.len()
}

pub fn entries(&self) -> &[(Field, Field)] {
self.entries.as_slice()
}
}

/// Constructs a `Map` from the list of `entries` and returns it.
Expand Down Expand Up @@ -1602,7 +1610,7 @@ mod tests {
#[cfg(test)]
#[allow(clippy::approx_constant, clippy::many_single_char_names)]
mod api_tests {
use super::make_row;
use super::{make_list, make_map, make_row};
use crate::record::Field;

#[test]
Expand Down Expand Up @@ -1634,4 +1642,29 @@ mod api_tests {
None => panic!("Expected at least one column"),
}
}

#[test]
fn test_list_element_access() {
let expected = vec![
Field::Int(1),
Field::Group(make_row(vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
])),
];

let list = make_list(expected.clone());
assert_eq!(expected.as_slice(), list.elements());
}

#[test]
fn test_map_entry_access() {
let expected = vec![
(Field::Str("one".to_owned()), Field::Int(1)),
(Field::Str("two".to_owned()), Field::Int(2)),
];

let map = make_map(expected.clone());
assert_eq!(expected.as_slice(), map.entries());
}
}

0 comments on commit 63144ad

Please sign in to comment.