Skip to content

Commit b18ed44

Browse files
David Kegleysunchao
authored andcommitted
ARROW-7768: [Rust] Implement TryClone and Length for Cursor<Vec<u8>>
Closes #6376 from dbkegley/arrow-7768 and squashes the following commits: 9cc2c00 <David Kegley> implement TryClone and Length for Cursor<Vec<u8>>, fix test Authored-by: David Kegley <kegs@b23.io> Signed-off-by: Chao Sun <sunchao@apache.org>
1 parent 41fbee4 commit b18ed44

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

rust/parquet/src/file/reader.rs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ impl<'a> TryClone for Cursor<&'a [u8]> {
136136
}
137137
}
138138

139+
impl Length for Cursor<Vec<u8>> {
140+
fn len(&self) -> u64 {
141+
self.get_ref().len() as u64
142+
}
143+
}
144+
145+
impl TryClone for Cursor<Vec<u8>> {
146+
fn try_clone(&self) -> Result<Self> {
147+
Ok(self.clone())
148+
}
149+
}
150+
139151
/// ParquetReader is the interface which needs to be fulfilled to be able to parse a
140152
/// parquet source.
141153
pub trait ParquetReader: Read + Seek + Length + TryClone {}
@@ -660,22 +672,23 @@ mod tests {
660672
);
661673
}
662674

663-
// #[test]
664-
// fn test_cursor_and_file_has_the_same_behaviour() {
665-
// let path = get_test_path("alltypes_plain.parquet");
666-
// let buffer = include_bytes!(path);
667-
// let cursor = Cursor::new(buffer.as_ref());
675+
#[test]
676+
fn test_cursor_and_file_has_the_same_behaviour() {
677+
let mut buf: Vec<u8> = Vec::new();
678+
get_test_file("alltypes_plain.parquet")
679+
.read_to_end(&mut buf)
680+
.unwrap();
681+
let cursor = Cursor::new(buf);
682+
let read_from_cursor = SerializedFileReader::new(cursor).unwrap();
668683

669-
// let read_from_file =
670-
// SerializedFileReader::new(File::open("testdata/alltypes_plain.parquet").
671-
// unwrap()) .unwrap();
672-
// let read_from_cursor = SerializedFileReader::new(cursor).unwrap();
684+
let test_file = get_test_file("alltypes_plain.parquet");
685+
let read_from_file = SerializedFileReader::new(test_file).unwrap();
673686

674-
// let file_iter = read_from_file.get_row_iter(None).unwrap();
675-
// let cursor_iter = read_from_cursor.get_row_iter(None).unwrap();
687+
let file_iter = read_from_file.get_row_iter(None).unwrap();
688+
let cursor_iter = read_from_cursor.get_row_iter(None).unwrap();
676689

677-
// assert!(file_iter.eq(cursor_iter));
678-
// }
690+
assert!(file_iter.eq(cursor_iter));
691+
}
679692

680693
#[test]
681694
fn test_file_reader_metadata_corrupt_footer() {

0 commit comments

Comments
 (0)