From aa5ce5281d8ea8f25166e37fe8791f7b5944cb4c Mon Sep 17 00:00:00 2001 From: Judah Rand <17158624+judahrand@users.noreply.github.com> Date: Fri, 22 Sep 2023 16:56:56 +0100 Subject: [PATCH] Use `.column` in tests --- arrow-row/src/lib.rs | 141 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) diff --git a/arrow-row/src/lib.rs b/arrow-row/src/lib.rs index b980d5c0517..2cf9dcb3121 100644 --- a/arrow-row/src/lib.rs +++ b/arrow-row/src/lib.rs @@ -1416,6 +1416,18 @@ mod tests { let rows = converter.convert_columns(&cols).unwrap(); assert_eq!(rows.offsets, &[0, 8, 16, 24, 32, 40, 48, 56]); + assert_eq!( + rows.column_offsets, + &[ + [0, 3, 8], + [0, 3, 8], + [0, 3, 8], + [0, 3, 8], + [0, 3, 8], + [0, 3, 8], + [0, 3, 8], + ] + ); assert_eq!( rows.buffer, &[ @@ -1442,6 +1454,18 @@ mod tests { assert!(rows.row(4) < rows.row(1)); assert!(rows.row(5) < rows.row(4)); + assert!(rows.row(3).column(0) < rows.row(6).column(0)); + assert!(rows.row(0).column(0) < rows.row(1).column(0)); + assert!(rows.row(3).column(0) < rows.row(0).column(0)); + assert!(rows.row(4).column(0) == rows.row(1).column(0)); + assert!(rows.row(5).column(0) == rows.row(4).column(0)); + + assert!(rows.row(3).column(1) > rows.row(6).column(1)); + assert!(rows.row(0).column(1) < rows.row(1).column(1)); + assert!(rows.row(3).column(1) > rows.row(0).column(1)); + assert!(rows.row(4).column(1) < rows.row(1).column(1)); + assert!(rows.row(5).column(1) < rows.row(4).column(1)); + let back = converter.convert_rows(&rows).unwrap(); for (expected, actual) in cols.iter().zip(&back) { assert_eq!(expected, actual); @@ -1471,6 +1495,7 @@ mod tests { let rows = converter.convert_columns(&[Arc::clone(&col)]).unwrap(); for i in 0..rows.num_rows() - 1 { assert!(rows.row(i) < rows.row(i + 1)); + assert!(rows.row(i).column(0) < rows.row(i + 1).column(0)); } let back = converter.convert_rows(&rows).unwrap(); @@ -1503,6 +1528,7 @@ mod tests { let rows = converter.convert_columns(&[Arc::clone(&col)]).unwrap(); for i in 0..rows.num_rows() - 1 { assert!(rows.row(i) < rows.row(i + 1)); + assert!(rows.row(i).column(0) < rows.row(i + 1).column(0)); } let back = converter.convert_rows(&rows).unwrap(); @@ -1523,6 +1549,10 @@ mod tests { assert!(rows.row(2) > rows.row(0)); assert!(rows.row(1) > rows.row(0)); + assert!(rows.row(2).column(0) > rows.row(1).column(0)); + assert!(rows.row(2).column(0) > rows.row(0).column(0)); + assert!(rows.row(1).column(0) > rows.row(0).column(0)); + let cols = converter.convert_rows(&rows).unwrap(); assert_eq!(&cols[0], &col); @@ -1539,6 +1569,9 @@ mod tests { assert!(rows.row(2) < rows.row(1)); assert!(rows.row(2) < rows.row(0)); assert!(rows.row(1) < rows.row(0)); + assert!(rows.row(2).column(0) < rows.row(1).column(0)); + assert!(rows.row(2).column(0) < rows.row(0).column(0)); + assert!(rows.row(1).column(0) < rows.row(0).column(0)); let cols = converter.convert_rows(&rows).unwrap(); assert_eq!(&cols[0], &col); } @@ -1587,6 +1620,7 @@ mod tests { let rows = converter.convert_columns(&[col]).unwrap(); assert_eq!(rows.num_rows(), 10); assert_eq!(rows.row(1).data.len(), 0); + assert_eq!(rows.row(1).column(0).len(), 0); } #[test] @@ -1607,6 +1641,11 @@ mod tests { assert!(rows.row(3) < rows.row(0)); assert!(rows.row(3) < rows.row(1)); + assert!(rows.row(1).column(0) < rows.row(0).column(0)); + assert!(rows.row(2).column(0) < rows.row(4).column(0)); + assert!(rows.row(3).column(0) < rows.row(0).column(0)); + assert!(rows.row(3).column(0) < rows.row(1).column(0)); + let cols = converter.convert_rows(&rows).unwrap(); assert_eq!(&cols[0], &col); @@ -1644,6 +1683,14 @@ mod tests { rows.row(i), rows.row(j) ); + assert!( + rows.row(i).column(0) < rows.row(j).column(0), + "{} < {} - {:?} < {:?}", + i, + j, + rows.row(i).column(0), + rows.row(j).column(0) + ); } } @@ -1670,6 +1717,14 @@ mod tests { rows.row(i), rows.row(j) ); + assert!( + rows.row(i).column(0) > rows.row(j).column(0), + "{} < {} - {:?} < {:?}", + i, + j, + rows.row(i).column(0), + rows.row(j).column(0) + ); } } @@ -1715,6 +1770,15 @@ mod tests { assert_eq!(rows_a.row(1), rows_a.row(6)); assert_eq!(rows_a.row(1), rows_a.row(7)); + assert!(rows_a.row(3).column(0) < rows_a.row(5).column(0)); + assert!(rows_a.row(2).column(0) < rows_a.row(1).column(0)); + assert!(rows_a.row(0).column(0) < rows_a.row(1).column(0)); + assert!(rows_a.row(3).column(0) < rows_a.row(0).column(0)); + + assert_eq!(rows_a.row(1).column(0), rows_a.row(4).column(0)); + assert_eq!(rows_a.row(1).column(0), rows_a.row(6).column(0)); + assert_eq!(rows_a.row(1).column(0), rows_a.row(7).column(0)); + let cols = converter.convert_rows(&rows_a).unwrap(); dictionary_eq(&cols[0], &a); @@ -1729,6 +1793,10 @@ mod tests { assert_eq!(rows_a.row(3), rows_b.row(1)); assert!(rows_b.row(2) < rows_a.row(0)); + assert_eq!(rows_a.row(1).column(0), rows_b.row(0).column(0)); + assert_eq!(rows_a.row(3).column(0), rows_b.row(1).column(0)); + assert!(rows_b.row(2).column(0) < rows_a.row(0).column(0)); + let cols = converter.convert_rows(&rows_b).unwrap(); dictionary_eq(&cols[0], &b); @@ -1747,6 +1815,11 @@ mod tests { assert!(rows_c.row(0) > rows_c.row(1)); assert!(rows_c.row(3) > rows_c.row(0)); + assert!(rows_c.row(3).column(0) > rows_c.row(5).column(0)); + assert!(rows_c.row(2).column(0) > rows_c.row(1).column(0)); + assert!(rows_c.row(0).column(0) > rows_c.row(1).column(0)); + assert!(rows_c.row(3).column(0) > rows_c.row(0).column(0)); + let cols = converter.convert_rows(&rows_c).unwrap(); dictionary_eq(&cols[0], &a); @@ -1765,6 +1838,11 @@ mod tests { assert!(rows_c.row(0) > rows_c.row(1)); assert!(rows_c.row(3) < rows_c.row(0)); + assert!(rows_c.row(3).column(0) < rows_c.row(5).column(0)); + assert!(rows_c.row(2).column(0) > rows_c.row(1).column(0)); + assert!(rows_c.row(0).column(0) > rows_c.row(1).column(0)); + assert!(rows_c.row(3).column(0) < rows_c.row(0).column(0)); + let cols = converter.convert_rows(&rows_c).unwrap(); dictionary_eq(&cols[0], &a); } @@ -1784,6 +1862,7 @@ mod tests { for (a, b) in r1.iter().zip(r1.iter().skip(1)) { assert!(a < b); + assert!(a.column(0) < b.column(0)); } let back = converter.convert_rows(&r1).unwrap(); @@ -1806,6 +1885,11 @@ mod tests { assert_ne!(r1.row(0), r2.row(0)); // Value does not equal null assert_eq!(r1.row(1), r2.row(1)); // Values equal + assert_eq!(r2.row(0).column(0), r2.row(2).column(0)); // Nulls equal + assert!(r2.row(0).column(0) < r2.row(1).column(0)); // Nulls first + assert_ne!(r1.row(0).column(0), r2.row(0).column(0)); // Value does not equal null + assert_eq!(r1.row(1).column(0), r2.row(1).column(0)); // Values equal + let back = converter.convert_rows(&r2).unwrap(); assert_eq!(back.len(), 1); assert_eq!(&back[0], &s2); @@ -1836,6 +1920,12 @@ mod tests { assert!(rows.row(3) < rows.row(2)); assert!(rows.row(6) < rows.row(2)); assert!(rows.row(3) < rows.row(6)); + + assert!(rows.row(0).column(0) < rows.row(1).column(0)); + assert!(rows.row(2).column(0) < rows.row(0).column(0)); + assert!(rows.row(3).column(0) < rows.row(2).column(0)); + assert!(rows.row(6).column(0) < rows.row(2).column(0)); + assert!(rows.row(3).column(0) < rows.row(6).column(0)); } #[test] @@ -1864,6 +1954,11 @@ mod tests { assert_eq!(rows.row(3), rows.row(4)); assert_eq!(rows.row(4), rows.row(5)); assert!(rows.row(3) < rows.row(0)); + + assert_eq!(rows.row(0).column(0), rows.row(1).column(0)); + assert_eq!(rows.row(3).column(0), rows.row(4).column(0)); + assert_eq!(rows.row(4).column(0), rows.row(5).column(0)); + assert!(rows.row(3).column(0) < rows.row(0).column(0)); } #[test] @@ -1927,6 +2022,13 @@ mod tests { assert!(rows.row(5) < rows.row(2)); // [] < [32, 42] assert!(rows.row(3) < rows.row(5)); // null < [] + assert!(rows.row(0).column(0) > rows.row(1).column(0)); // [32, 52, 32] > [32, 52, 12] + assert!(rows.row(2).column(0) < rows.row(1).column(0)); // [32, 42] < [32, 52, 12] + assert!(rows.row(3).column(0) < rows.row(2).column(0)); // null < [32, 42] + assert!(rows.row(4).column(0) < rows.row(2).column(0)); // [32, null] < [32, 42] + assert!(rows.row(5).column(0) < rows.row(2).column(0)); // [] < [32, 42] + assert!(rows.row(3).column(0) < rows.row(5).column(0)); // null < [] + let back = converter.convert_rows(&rows).unwrap(); assert_eq!(back.len(), 1); back[0].to_data().validate_full().unwrap(); @@ -1947,6 +2049,13 @@ mod tests { assert!(rows.row(5) < rows.row(2)); // [] < [32, 42] assert!(rows.row(3) > rows.row(5)); // null > [] + assert!(rows.row(0).column(0) > rows.row(1).column(0)); // [32, 52, 32] > [32, 52, 12] + assert!(rows.row(2).column(0) < rows.row(1).column(0)); // [32, 42] < [32, 52, 12] + assert!(rows.row(3).column(0) > rows.row(2).column(0)); // null > [32, 42] + assert!(rows.row(4).column(0) > rows.row(2).column(0)); // [32, null] > [32, 42] + assert!(rows.row(5).column(0) < rows.row(2).column(0)); // [] < [32, 42] + assert!(rows.row(3).column(0) > rows.row(5).column(0)); // null > [] + let back = converter.convert_rows(&rows).unwrap(); assert_eq!(back.len(), 1); back[0].to_data().validate_full().unwrap(); @@ -1967,6 +2076,13 @@ mod tests { assert!(rows.row(5) > rows.row(2)); // [] > [32, 42] assert!(rows.row(3) > rows.row(5)); // null > [] + assert!(rows.row(0).column(0) < rows.row(1).column(0)); // [32, 52, 32] < [32, 52, 12] + assert!(rows.row(2).column(0) > rows.row(1).column(0)); // [32, 42] > [32, 52, 12] + assert!(rows.row(3).column(0) > rows.row(2).column(0)); // null > [32, 42] + assert!(rows.row(4).column(0) > rows.row(2).column(0)); // [32, null] > [32, 42] + assert!(rows.row(5).column(0) > rows.row(2).column(0)); // [] > [32, 42] + assert!(rows.row(3).column(0) > rows.row(5).column(0)); // null > [] + let back = converter.convert_rows(&rows).unwrap(); assert_eq!(back.len(), 1); back[0].to_data().validate_full().unwrap(); @@ -1987,6 +2103,13 @@ mod tests { assert!(rows.row(5) > rows.row(2)); // [] > [32, 42] assert!(rows.row(3) < rows.row(5)); // null < [] + assert!(rows.row(0).column(0) < rows.row(1).column(0)); // [32, 52, 32] < [32, 52, 12] + assert!(rows.row(2).column(0) > rows.row(1).column(0)); // [32, 42] > [32, 52, 12] + assert!(rows.row(3).column(0) < rows.row(2).column(0)); // null < [32, 42] + assert!(rows.row(4).column(0) < rows.row(2).column(0)); // [32, null] < [32, 42] + assert!(rows.row(5).column(0) > rows.row(2).column(0)); // [] > [32, 42] + assert!(rows.row(3).column(0) < rows.row(5).column(0)); // null < [] + let back = converter.convert_rows(&rows).unwrap(); assert_eq!(back.len(), 1); back[0].to_data().validate_full().unwrap(); @@ -2050,6 +2173,12 @@ mod tests { assert!(rows.row(4) < rows.row(0)); assert!(rows.row(4) > rows.row(1)); + assert!(rows.row(0).column(0) > rows.row(1).column(0)); + assert!(rows.row(1).column(0) > rows.row(2).column(0)); + assert!(rows.row(2).column(0) > rows.row(3).column(0)); + assert!(rows.row(4).column(0) < rows.row(0).column(0)); + assert!(rows.row(4).column(0) > rows.row(1).column(0)); + let back = converter.convert_rows(&rows).unwrap(); assert_eq!(back.len(), 1); back[0].to_data().validate_full().unwrap(); @@ -2069,6 +2198,12 @@ mod tests { assert!(rows.row(4) > rows.row(0)); assert!(rows.row(4) > rows.row(1)); + assert!(rows.row(0).column(0) > rows.row(1).column(0)); + assert!(rows.row(1).column(0) > rows.row(2).column(0)); + assert!(rows.row(2).column(0) > rows.row(3).column(0)); + assert!(rows.row(4).column(0) > rows.row(0).column(0)); + assert!(rows.row(4).column(0) > rows.row(1).column(0)); + let back = converter.convert_rows(&rows).unwrap(); assert_eq!(back.len(), 1); back[0].to_data().validate_full().unwrap(); @@ -2088,6 +2223,12 @@ mod tests { assert!(rows.row(4) > rows.row(0)); assert!(rows.row(4) < rows.row(1)); + assert!(rows.row(0).column(0) < rows.row(1).column(0)); + assert!(rows.row(1).column(0) < rows.row(2).column(0)); + assert!(rows.row(2).column(0) < rows.row(3).column(0)); + assert!(rows.row(4).column(0) > rows.row(0).column(0)); + assert!(rows.row(4).column(0) < rows.row(1).column(0)); + let back = converter.convert_rows(&rows).unwrap(); assert_eq!(back.len(), 1); back[0].to_data().validate_full().unwrap();