Skip to content

Commit

Permalink
Remove 'make_row', expose a 'Row::new' method instead. (#6763)
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Dedden <[email protected]>

Use `Row::new` also in internal tests.

Signed-off-by: Jonas Dedden <[email protected]>

cargo fmt
  • Loading branch information
jonded94 authored Nov 20, 2024
1 parent e7588bd commit 390f0ba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
49 changes: 24 additions & 25 deletions parquet/src/record/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ pub struct Row {

#[allow(clippy::len_without_is_empty)]
impl Row {
/// Constructs a `Row` from the list of `fields` and returns it.
pub fn new(fields: Vec<(String, Field)>) -> Row {
Row { fields }
}

/// Get the number of fields in this row.
pub fn len(&self) -> usize {
self.fields.len()
Expand Down Expand Up @@ -283,12 +288,6 @@ impl RowAccessor for Row {
row_complex_accessor!(get_map, MapInternal, Map);
}

/// Constructs a `Row` from the list of `fields` and returns it.
#[inline]
pub fn make_row(fields: Vec<(String, Field)>) -> Row {
Row { fields }
}

impl fmt::Display for Row {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{{")?;
Expand Down Expand Up @@ -1386,7 +1385,7 @@ mod tests {
("z".to_string(), Field::Float(3.1)),
("a".to_string(), Field::Str("abc".to_string())),
];
let row = Field::Group(make_row(fields));
let row = Field::Group(Row::new(fields));
assert_eq!(format!("{row}"), "{x: null, Y: 2, z: 3.1, a: \"abc\"}");

let row = Field::ListInternal(make_list(vec![
Expand Down Expand Up @@ -1431,7 +1430,7 @@ mod tests {
assert!(Field::Decimal(Decimal::from_i32(4, 8, 2)).is_primitive());

// complex types
assert!(!Field::Group(make_row(vec![
assert!(!Field::Group(Row::new(vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
("z".to_string(), Field::Float(3.1)),
Expand All @@ -1458,7 +1457,7 @@ mod tests {
#[test]
fn test_row_primitive_field_fmt() {
// Primitives types
let row = make_row(vec![
let row = Row::new(vec![
("00".to_string(), Field::Null),
("01".to_string(), Field::Bool(false)),
("02".to_string(), Field::Byte(3)),
Expand Down Expand Up @@ -1513,10 +1512,10 @@ mod tests {
#[test]
fn test_row_complex_field_fmt() {
// Complex types
let row = make_row(vec![
let row = Row::new(vec![
(
"00".to_string(),
Field::Group(make_row(vec![
Field::Group(Row::new(vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
])),
Expand Down Expand Up @@ -1548,7 +1547,7 @@ mod tests {
#[test]
fn test_row_primitive_accessors() {
// primitives
let row = make_row(vec![
let row = Row::new(vec![
("a".to_string(), Field::Null),
("b".to_string(), Field::Bool(false)),
("c".to_string(), Field::Byte(3)),
Expand Down Expand Up @@ -1590,7 +1589,7 @@ mod tests {
#[test]
fn test_row_primitive_invalid_accessors() {
// primitives
let row = make_row(vec![
let row = Row::new(vec![
("a".to_string(), Field::Null),
("b".to_string(), Field::Bool(false)),
("c".to_string(), Field::Byte(3)),
Expand Down Expand Up @@ -1619,10 +1618,10 @@ mod tests {

#[test]
fn test_row_complex_accessors() {
let row = make_row(vec![
let row = Row::new(vec![
(
"a".to_string(),
Field::Group(make_row(vec![
Field::Group(Row::new(vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
])),
Expand Down Expand Up @@ -1653,10 +1652,10 @@ mod tests {

#[test]
fn test_row_complex_invalid_accessors() {
let row = make_row(vec![
let row = Row::new(vec![
(
"a".to_string(),
Field::Group(make_row(vec![
Field::Group(Row::new(vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
])),
Expand Down Expand Up @@ -1802,7 +1801,7 @@ mod tests {

#[test]
fn test_list_complex_accessors() {
let list = make_list(vec![Field::Group(make_row(vec![
let list = make_list(vec![Field::Group(Row::new(vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
]))]);
Expand All @@ -1826,7 +1825,7 @@ mod tests {

#[test]
fn test_list_complex_invalid_accessors() {
let list = make_list(vec![Field::Group(make_row(vec![
let list = make_list(vec![Field::Group(Row::new(vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
]))]);
Expand Down Expand Up @@ -1961,7 +1960,7 @@ mod tests {
("Y".to_string(), Field::Double(2.2)),
("Z".to_string(), Field::Str("abc".to_string())),
];
let row = Field::Group(make_row(fields));
let row = Field::Group(Row::new(fields));
assert_eq!(
row.to_json_value(),
serde_json::json!({"X": 1, "Y": 2.2, "Z": "abc"})
Expand Down Expand Up @@ -1990,14 +1989,14 @@ mod tests {
#[cfg(test)]
#[allow(clippy::many_single_char_names)]
mod api_tests {
use super::{make_list, make_map, make_row};
use super::{make_list, make_map, Row};
use crate::record::Field;

#[test]
fn test_field_visibility() {
let row = make_row(vec![(
let row = Row::new(vec![(
"a".to_string(),
Field::Group(make_row(vec![
Field::Group(Row::new(vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
])),
Expand All @@ -2009,7 +2008,7 @@ mod api_tests {
match column.1 {
Field::Group(r) => {
assert_eq!(
&make_row(vec![
&Row::new(vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
]),
Expand All @@ -2027,7 +2026,7 @@ mod api_tests {
fn test_list_element_access() {
let expected = vec![
Field::Int(1),
Field::Group(make_row(vec![
Field::Group(Row::new(vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
])),
Expand Down
8 changes: 4 additions & 4 deletions parquet/src/record/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::basic::{ConvertedType, Repetition};
use crate::errors::{ParquetError, Result};
use crate::file::reader::{FileReader, RowGroupReader};
use crate::record::{
api::{make_list, make_map, make_row, Field, Row},
api::{make_list, make_map, Field, Row},
triplet::TripletIter,
};
use crate::schema::types::{ColumnPath, SchemaDescPtr, SchemaDescriptor, Type, TypePtr};
Expand Down Expand Up @@ -399,7 +399,7 @@ impl Reader {
for reader in readers {
fields.push((String::from(reader.field_name()), reader.read_field()?));
}
Ok(make_row(fields))
Ok(Row::new(fields))
}
_ => panic!("Cannot call read() on {self}"),
}
Expand Down Expand Up @@ -434,7 +434,7 @@ impl Reader {
fields.push((String::from(reader.field_name()), Field::Null));
}
}
let row = make_row(fields);
let row = Row::new(fields);
Field::Group(row)
}
Reader::RepeatedReader(_, def_level, rep_level, ref mut reader) => {
Expand Down Expand Up @@ -826,7 +826,7 @@ mod tests {
macro_rules! row {
($($e:tt)*) => {
{
make_row(vec![$($e)*])
Row::new(vec![$($e)*])
}
}
}
Expand Down

0 comments on commit 390f0ba

Please sign in to comment.