Skip to content

Commit f3e9fae

Browse files
committed
fix
Signed-off-by: Joe Isaacs <[email protected]>
1 parent 981c153 commit f3e9fae

File tree

4 files changed

+39
-31
lines changed

4 files changed

+39
-31
lines changed

vortex-ffi/src/file.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,29 @@ impl vx_file_scan_options {
122122
self.filter_expression_len,
123123
)?;
124124

125-
#[allow(clippy::useless_conversion)] // c_ulong is u32 on Windows, u64 on Unix
125+
// On Windows, c_ulong is u32, so we need to convert to u64
126+
// On Unix, c_ulong is already u64, so we can use it directly
127+
#[cfg(windows)]
126128
let row_range = (self.row_range_end > self.row_range_start)
127-
.then_some(u64::from(self.row_range_start)..u64::from(self.row_range_end));
129+
.then_some(self.row_range_start as u64..self.row_range_end as u64);
130+
#[cfg(not(windows))]
131+
let row_range = (self.row_range_end > self.row_range_start)
132+
.then_some(self.row_range_start..self.row_range_end);
128133

129134
let split_by = (self.split_by_row_count > 0)
130135
.then_some(SplitBy::RowCount(self.split_by_row_count as usize));
131136

132-
#[allow(clippy::useless_conversion)]
137+
#[cfg(windows)]
138+
let row_offset = self.row_offset as u64;
139+
#[cfg(not(windows))]
140+
let row_offset = self.row_offset;
141+
133142
Ok(ScanOptions {
134143
projection_expr,
135144
filter_expr,
136145
split_by,
137146
row_range,
138-
row_offset: u64::from(self.row_offset),
147+
row_offset,
139148
})
140149
}
141150
}

vortex-io/src/file/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod driver;
77
pub mod object_store;
88
mod read;
99
#[cfg(not(target_arch = "wasm32"))]
10-
mod std_file;
10+
pub(crate) mod std_file;
1111

1212
pub(crate) use driver::*;
1313
pub use read::*;

vortex-io/src/file/object_store.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
use std::io;
5-
#[cfg(not(unix))]
6-
use std::io::{Read, Seek};
7-
#[cfg(unix)]
8-
use std::os::unix::fs::FileExt;
95
use std::sync::Arc;
106

117
use async_compat::Compat;
@@ -18,6 +14,8 @@ use vortex_error::{VortexError, VortexResult, vortex_ensure};
1814

1915
use crate::file::IoRequest;
2016
use crate::file::read::{CoalesceWindow, IntoReadSource, ReadSource, ReadSourceRef};
17+
#[cfg(not(target_arch = "wasm32"))]
18+
use crate::file::std_file::read_exact_at;
2119
use crate::runtime::Handle;
2220

2321
const COALESCING_WINDOW: CoalesceWindow = CoalesceWindow {
@@ -137,15 +135,8 @@ impl ReadSource for ObjectStoreIoSource {
137135

138136
handle
139137
.spawn_blocking(move || {
140-
#[cfg(unix)] {
141-
file.read_exact_at(&mut buffer, range.start)?;
142-
Ok::<_, io::Error>(buffer)
143-
}
144-
#[cfg(not(unix))] {
145-
file.seek(io::SeekFrom::Start(range.start))?;
146-
file.read_exact(&mut buffer)?;
147-
Ok::<_, io::Error>(buffer)
148-
}
138+
read_exact_at(&file, &mut buffer, range.start)?;
139+
Ok::<_, io::Error>(buffer)
149140
})
150141
.await
151142
.map_err(io::Error::other)?

vortex-io/src/file/std_file.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
use std::fs::File;
5+
#[cfg(not(unix))]
6+
use std::io::{Read, Seek};
57
#[cfg(unix)]
68
use std::os::unix::fs::FileExt;
7-
#[cfg(windows)]
9+
#[cfg(all(not(unix), windows))]
810
use std::os::windows::fs::FileExt;
911
use std::path::{Path, PathBuf};
1012
use std::sync::Arc;
@@ -18,6 +20,23 @@ use vortex_error::{VortexError, VortexResult};
1820
use crate::file::{CoalesceWindow, IntoReadSource, IoRequest, ReadSource, ReadSourceRef};
1921
use crate::runtime::Handle;
2022

23+
/// Read exactly `buffer.len()` bytes from `file` starting at `offset`.
24+
/// This is a platform-specific helper that uses the most efficient method available.
25+
#[cfg(not(target_arch = "wasm32"))]
26+
pub(crate) fn read_exact_at(file: &File, buffer: &mut [u8], offset: u64) -> std::io::Result<()> {
27+
#[cfg(unix)]
28+
{
29+
file.read_exact_at(buffer, offset)
30+
}
31+
#[cfg(not(unix))]
32+
{
33+
use std::io::SeekFrom;
34+
let mut file_ref = file;
35+
file_ref.seek(SeekFrom::Start(offset))?;
36+
file_ref.read_exact(buffer)
37+
}
38+
}
39+
2140
const COALESCING_WINDOW: CoalesceWindow = CoalesceWindow {
2241
// TODO(ngates): these numbers don't make sense if we're using spawn_blocking..
2342
distance: 8 * 1024, // KB
@@ -86,18 +105,7 @@ impl ReadSource for FileIoSource {
86105
let mut buffer = ByteBufferMut::with_capacity_aligned(len, req.alignment());
87106
unsafe { buffer.set_len(len) };
88107

89-
#[cfg(unix)]
90-
let buffer_res = file.read_exact_at(&mut buffer, offset);
91-
#[cfg(windows)]
92-
let buffer_res = file.seek_read(&mut buffer, offset);
93-
#[cfg(not(any(unix, windows)))]
94-
let buffer_res = {
95-
use std::io::{Read, Seek, SeekFrom};
96-
let mut file_ref = file.as_ref();
97-
file_ref
98-
.seek(SeekFrom::Start(offset))
99-
.and_then(|_| file_ref.read_exact(&mut buffer))
100-
};
108+
let buffer_res = read_exact_at(&file, &mut buffer, offset);
101109

102110
req.resolve(
103111
buffer_res

0 commit comments

Comments
 (0)