Skip to content

Commit

Permalink
Implement assert_magic for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mcheshkov committed Sep 5, 2024
1 parent 8016e84 commit 5a34d7e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions parquet/src/file/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,10 @@ impl<T: Write + Position> PageWriter for SerializedPageWriter<T> {
mod tests {
use super::*;

#[cfg(not(target_os = "windows"))]
use std::os::unix::fs::FileExt;
#[cfg(target_os = "windows")]
use std::os::windows::fs::FileExt;
use std::{
fs::File,
io::{Cursor, SeekFrom},
Expand Down Expand Up @@ -1264,6 +1267,7 @@ mod tests {
assert_eq!(to_thrift(left.statistics()), to_thrift(right.statistics()));
}

#[cfg(not(target_os = "windows"))]
fn assert_magic(file: &mut File, expected: [u8; 4]) {
let length = file.len();
// Of course the file has to be larger than just 8, but we're just sanity-checking when checking the magic.
Expand All @@ -1276,6 +1280,23 @@ mod tests {
assert_eq!(buf, expected);
}

#[cfg(target_os = "windows")]
fn assert_magic(file: &mut File, expected: [u8; 4]) {
let length = file.len();
// Of course the file has to be larger than just 8, but we're just sanity-checking when checking the magic.
assert!(length >= 8);

let original_position = file.stream_position();

let mut buf = [0xCDu8, 0xCD, 0xCD, 0xCD];
file.seek_read(&mut buf[..], 0).unwrap();
assert_eq!(buf, expected);
file.seek_read(&mut buf[..], length - 4).unwrap();
assert_eq!(buf, expected);

file.seek(SeekFrom::Start(original_position)).unwrap();
}

/// File write-read roundtrip.
/// `data` consists of arrays of values for each row group.
fn test_file_roundtrip(mut file: File, data: Vec<Vec<i32>>) {
Expand Down

0 comments on commit 5a34d7e

Please sign in to comment.