Skip to content

Commit

Permalink
Use Row::new also in internal tests.
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 d44f10c commit 69e0a9d
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions parquet/src/record/api.rs
Original file line number Diff line number Diff line change
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(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,12 +1431,12 @@ mod tests {
assert!(Field::Decimal(Decimal::from_i32(4, 8, 2)).is_primitive());

// complex types
assert!(!Field::Group(Row{fields: 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)),
("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 = Row{fields: vec![
let row = Row::new(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 = Row{fields: vec![
let row = Row::new(vec![
(
"00".to_string(),
Field::Group(Row{fields: vec![
Field::Group(Row::new(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 = Row{fields: vec![
let row = Row::new(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 = Row{fields: vec![
let row = Row::new(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 = Row{fields: vec![
let row = Row::new(vec![
(
"a".to_string(),
Field::Group(Row{fields: vec![
Field::Group(Row::new(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 = Row{fields: vec![
let row = Row::new(vec![
(
"a".to_string(),
Field::Group(Row{fields: vec![
Field::Group(Row::new(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(Row{fields: vec![
let list = make_list(vec![Field::Group(Row::new(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(Row{fields: vec![
let list = make_list(vec![Field::Group(Row::new(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(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 @@ -1995,24 +1995,24 @@ mod api_tests {

#[test]
fn test_field_visibility() {
let row = Row{fields: vec![(
let row = Row::new(vec![(
"a".to_string(),
Field::Group(Row{fields: vec![
Field::Group(Row::new(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!(
&Row{fields: vec![
&Row::new(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(Row{fields: vec![
Field::Group(Row::new(vec![
("x".to_string(), Field::Null),
("Y".to_string(), Field::Int(2)),
]}),
])),
];

let list = make_list(expected.clone());
Expand Down

0 comments on commit 69e0a9d

Please sign in to comment.