Skip to content

Commit

Permalink
Remove 'make_row', expose a 'Row::new' method instead.
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Dedden <[email protected]>
  • Loading branch information
jonded94 committed Nov 20, 2024
1 parent e7588bd commit d44f10c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
80 changes: 40 additions & 40 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,11 +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 {
Expand Down Expand Up @@ -1386,7 +1386,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{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,12 +1431,12 @@ 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{fields: vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
("z".to_string(), Field::Float(3.1)),
("a".to_string(), Field::Str("abc".to_string()))
]))
]})
.is_primitive());

assert!(!Field::ListInternal(make_list(vec![
Expand All @@ -1458,7 +1458,7 @@ mod tests {
#[test]
fn test_row_primitive_field_fmt() {
// Primitives types
let row = make_row(vec![
let row = Row{fields: vec![
("00".to_string(), Field::Null),
("01".to_string(), Field::Bool(false)),
("02".to_string(), Field::Byte(3)),
Expand All @@ -1481,7 +1481,7 @@ mod tests {
("16".to_string(), Field::TimestampMicros(1262391174000000)),
("17".to_string(), Field::Decimal(Decimal::from_i32(4, 7, 2))),
("18".to_string(), Field::Float16(f16::PI)),
]);
]};

assert_eq!("null", format!("{}", row.fmt(0)));
assert_eq!("false", format!("{}", row.fmt(1)));
Expand Down Expand Up @@ -1513,13 +1513,13 @@ mod tests {
#[test]
fn test_row_complex_field_fmt() {
// Complex types
let row = make_row(vec![
let row = Row{fields: vec![
(
"00".to_string(),
Field::Group(make_row(vec![
Field::Group(Row{fields: vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
])),
]}),
),
(
"01".to_string(),
Expand All @@ -1538,7 +1538,7 @@ mod tests {
(Field::Int(3), Field::Float(2.3)),
])),
),
]);
]};

assert_eq!("{x: null, Y: 2}", format!("{}", row.fmt(0)));
assert_eq!("[2, 1, null, 12]", format!("{}", row.fmt(1)));
Expand All @@ -1548,7 +1548,7 @@ mod tests {
#[test]
fn test_row_primitive_accessors() {
// primitives
let row = make_row(vec![
let row = Row{fields: vec![
("a".to_string(), Field::Null),
("b".to_string(), Field::Bool(false)),
("c".to_string(), Field::Byte(3)),
Expand All @@ -1568,7 +1568,7 @@ mod tests {
),
("o".to_string(), Field::Decimal(Decimal::from_i32(4, 7, 2))),
("p".to_string(), Field::Float16(f16::from_f32(9.1))),
]);
]};

assert!(!row.get_bool(1).unwrap());
assert_eq!(3, row.get_byte(2).unwrap());
Expand All @@ -1590,7 +1590,7 @@ mod tests {
#[test]
fn test_row_primitive_invalid_accessors() {
// primitives
let row = make_row(vec![
let row = Row{fields: vec![
("a".to_string(), Field::Null),
("b".to_string(), Field::Bool(false)),
("c".to_string(), Field::Byte(3)),
Expand All @@ -1610,7 +1610,7 @@ mod tests {
),
("o".to_string(), Field::Decimal(Decimal::from_i32(4, 7, 2))),
("p".to_string(), Field::Float16(f16::from_f32(9.1))),
]);
]};

for i in 0..row.len() {
assert!(row.get_group(i).is_err());
Expand All @@ -1619,13 +1619,13 @@ mod tests {

#[test]
fn test_row_complex_accessors() {
let row = make_row(vec![
let row = Row{fields: vec![
(
"a".to_string(),
Field::Group(make_row(vec![
Field::Group(Row{fields: vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
])),
]}),
),
(
"b".to_string(),
Expand All @@ -1644,7 +1644,7 @@ mod tests {
(Field::Int(3), Field::Float(2.3)),
])),
),
]);
]};

assert_eq!(2, row.get_group(0).unwrap().len());
assert_eq!(4, row.get_list(1).unwrap().len());
Expand All @@ -1653,13 +1653,13 @@ mod tests {

#[test]
fn test_row_complex_invalid_accessors() {
let row = make_row(vec![
let row = Row{fields: vec![
(
"a".to_string(),
Field::Group(make_row(vec![
Field::Group(Row{fields: vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
])),
]}),
),
(
"b".to_string(),
Expand All @@ -1678,7 +1678,7 @@ mod tests {
(Field::Int(3), Field::Float(2.3)),
])),
),
]);
]};

assert_eq!(
row.get_float(0).unwrap_err().to_string(),
Expand Down Expand Up @@ -1802,10 +1802,10 @@ 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{fields: vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
]))]);
]})]);
assert_eq!(2, list.get_group(0).unwrap().len());

let list = make_list(vec![Field::ListInternal(make_list(vec![
Expand All @@ -1826,10 +1826,10 @@ 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{fields: vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
]))]);
]})]);
assert_eq!(
list.get_float(0).unwrap_err().to_string(),
"Parquet error: Cannot access Group as Float"
Expand Down Expand Up @@ -1961,7 +1961,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{fields});
assert_eq!(
row.to_json_value(),
serde_json::json!({"X": 1, "Y": 2.2, "Z": "abc"})
Expand Down Expand Up @@ -1990,29 +1990,29 @@ 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{fields: vec![(
"a".to_string(),
Field::Group(make_row(vec![
Field::Group(Row{fields: vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
])),
)]);
]}),
)]};

match row.get_column_iter().next() {
Some(column) => {
assert_eq!("a", column.0);
match column.1 {
Field::Group(r) => {
assert_eq!(
&make_row(vec![
&Row{fields: vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
]),
]},
r
);
}
Expand All @@ -2027,10 +2027,10 @@ mod api_tests {
fn test_list_element_access() {
let expected = vec![
Field::Int(1),
Field::Group(make_row(vec![
Field::Group(Row{fields: vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
])),
]}),
];

let list = make_list(expected.clone());
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 d44f10c

Please sign in to comment.