-
Notifications
You must be signed in to change notification settings - Fork 962
Change Parquet API interaction to use u64
(support files larger than 4GB in WASM)
#7371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
11aa2cb
Change AsyncFileReader trait for u64
alchemist51 fef3719
update metadatafetch trait
alchemist51 917b0e6
Fix lint issue
alchemist51 87e9efc
Merge branch 'main' into change-parquet-usize
kylebarron 6e70d20
fix tests for latest main
kylebarron 2adf76c
Address comments by @mbrobbel from #7252
kylebarron 583dfdf
Merge branch 'main' into kyle/change-parquet-u64
kylebarron c06f60d
Fix compile
kylebarron 494ce40
Revert suffix length back to usize
kylebarron 6eb9484
Use `u64` for `file_size`
kylebarron 16bc64b
address comments
kylebarron 78c165a
fix calculation of metadata_start
etseidl 5742fff
change file_size type to u64
etseidl 2ad9c85
change _sized functions to take u64 file_size
etseidl 176cc31
clippy
etseidl d8b6061
remove some potential panics
etseidl 3cf8d8d
use u64 for page index ranges
etseidl 6664425
Revert change to deprecated method
alamb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,10 +81,10 @@ pub use store::*; | |
/// [`tokio::fs::File`]: https://docs.rs/tokio/latest/tokio/fs/struct.File.html | ||
pub trait AsyncFileReader: Send { | ||
/// Retrieve the bytes in `range` | ||
fn get_bytes(&mut self, range: Range<usize>) -> BoxFuture<'_, Result<Bytes>>; | ||
fn get_bytes(&mut self, range: Range<u64>) -> BoxFuture<'_, Result<Bytes>>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
/// Retrieve multiple byte ranges. The default implementation will call `get_bytes` sequentially | ||
fn get_byte_ranges(&mut self, ranges: Vec<Range<usize>>) -> BoxFuture<'_, Result<Vec<Bytes>>> { | ||
fn get_byte_ranges(&mut self, ranges: Vec<Range<u64>>) -> BoxFuture<'_, Result<Vec<Bytes>>> { | ||
async move { | ||
let mut result = Vec::with_capacity(ranges.len()); | ||
|
||
|
@@ -110,11 +110,11 @@ pub trait AsyncFileReader: Send { | |
|
||
/// This allows Box<dyn AsyncFileReader + '_> to be used as an AsyncFileReader, | ||
impl AsyncFileReader for Box<dyn AsyncFileReader + '_> { | ||
fn get_bytes(&mut self, range: Range<usize>) -> BoxFuture<'_, Result<Bytes>> { | ||
fn get_bytes(&mut self, range: Range<u64>) -> BoxFuture<'_, Result<Bytes>> { | ||
self.as_mut().get_bytes(range) | ||
} | ||
|
||
fn get_byte_ranges(&mut self, ranges: Vec<Range<usize>>) -> BoxFuture<'_, Result<Vec<Bytes>>> { | ||
fn get_byte_ranges(&mut self, ranges: Vec<Range<u64>>) -> BoxFuture<'_, Result<Vec<Bytes>>> { | ||
self.as_mut().get_byte_ranges(ranges) | ||
} | ||
|
||
|
@@ -127,14 +127,14 @@ impl AsyncFileReader for Box<dyn AsyncFileReader + '_> { | |
} | ||
|
||
impl<T: AsyncRead + AsyncSeek + Unpin + Send> AsyncFileReader for T { | ||
fn get_bytes(&mut self, range: Range<usize>) -> BoxFuture<'_, Result<Bytes>> { | ||
fn get_bytes(&mut self, range: Range<u64>) -> BoxFuture<'_, Result<Bytes>> { | ||
async move { | ||
self.seek(SeekFrom::Start(range.start as u64)).await?; | ||
self.seek(SeekFrom::Start(range.start)).await?; | ||
|
||
let to_read = range.end - range.start; | ||
let mut buffer = Vec::with_capacity(to_read); | ||
let read = self.take(to_read as u64).read_to_end(&mut buffer).await?; | ||
if read != to_read { | ||
let mut buffer = Vec::with_capacity(to_read as usize); | ||
kylebarron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let read = self.take(to_read).read_to_end(&mut buffer).await?; | ||
if read as u64 != to_read { | ||
return Err(eof_err!("expected to read {} bytes, got {}", to_read, read)); | ||
} | ||
|
||
|
@@ -441,7 +441,7 @@ impl<T: AsyncFileReader + Send + 'static> ParquetRecordBatchStreamBuilder<T> { | |
let metadata = self.metadata.row_group(row_group_idx); | ||
let column_metadata = metadata.column(column_idx); | ||
|
||
let offset: usize = if let Some(offset) = column_metadata.bloom_filter_offset() { | ||
let offset: u64 = if let Some(offset) = column_metadata.bloom_filter_offset() { | ||
offset | ||
.try_into() | ||
.map_err(|_| ParquetError::General("Bloom filter offset is invalid".to_string()))? | ||
|
@@ -450,16 +450,16 @@ impl<T: AsyncFileReader + Send + 'static> ParquetRecordBatchStreamBuilder<T> { | |
}; | ||
|
||
let buffer = match column_metadata.bloom_filter_length() { | ||
Some(length) => self.input.0.get_bytes(offset..offset + length as usize), | ||
Some(length) => self.input.0.get_bytes(offset..offset + length as u64), | ||
None => self | ||
.input | ||
.0 | ||
.get_bytes(offset..offset + SBBF_HEADER_SIZE_ESTIMATE), | ||
.get_bytes(offset..offset + SBBF_HEADER_SIZE_ESTIMATE as u64), | ||
} | ||
.await?; | ||
|
||
let (header, bitset_offset) = | ||
chunk_read_bloom_filter_header_and_offset(offset as u64, buffer.clone())?; | ||
chunk_read_bloom_filter_header_and_offset(offset, buffer.clone())?; | ||
|
||
match header.algorithm { | ||
BloomFilterAlgorithm::BLOCK(_) => { | ||
|
@@ -478,14 +478,14 @@ impl<T: AsyncFileReader + Send + 'static> ParquetRecordBatchStreamBuilder<T> { | |
} | ||
|
||
let bitset = match column_metadata.bloom_filter_length() { | ||
Some(_) => buffer.slice((bitset_offset as usize - offset)..), | ||
Some(_) => buffer.slice((bitset_offset as usize - offset as usize)..), | ||
kylebarron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
None => { | ||
let bitset_length: usize = header.num_bytes.try_into().map_err(|_| { | ||
let bitset_length: u64 = header.num_bytes.try_into().map_err(|_| { | ||
ParquetError::General("Bloom filter length is invalid".to_string()) | ||
})?; | ||
self.input | ||
.0 | ||
.get_bytes(bitset_offset as usize..bitset_offset as usize + bitset_length) | ||
.get_bytes(bitset_offset..bitset_offset + bitset_length) | ||
.await? | ||
} | ||
}; | ||
|
@@ -897,7 +897,7 @@ impl InMemoryRowGroup<'_> { | |
if let Some((selection, offset_index)) = selection.zip(self.offset_index) { | ||
// If we have a `RowSelection` and an `OffsetIndex` then only fetch pages required for the | ||
// `RowSelection` | ||
let mut page_start_offsets: Vec<Vec<usize>> = vec![]; | ||
let mut page_start_offsets: Vec<Vec<u64>> = vec![]; | ||
|
||
let fetch_ranges = self | ||
.column_chunks | ||
|
@@ -910,11 +910,11 @@ impl InMemoryRowGroup<'_> { | |
.flat_map(|(idx, (_chunk, chunk_meta))| { | ||
// If the first page does not start at the beginning of the column, | ||
// then we need to also fetch a dictionary page. | ||
let mut ranges = vec![]; | ||
let mut ranges: Vec<Range<u64>> = vec![]; | ||
let (start, _len) = chunk_meta.byte_range(); | ||
match offset_index[idx].page_locations.first() { | ||
Some(first) if first.offset as u64 != start => { | ||
ranges.push(start as usize..first.offset as usize); | ||
ranges.push(start..first.offset as u64); | ||
} | ||
_ => (), | ||
} | ||
|
@@ -942,7 +942,11 @@ impl InMemoryRowGroup<'_> { | |
|
||
*chunk = Some(Arc::new(ColumnChunkData::Sparse { | ||
length: metadata.column(idx).byte_range().1 as usize, | ||
data: offsets.into_iter().zip(chunks.into_iter()).collect(), | ||
data: offsets | ||
.into_iter() | ||
.map(|x| x as usize) | ||
.zip(chunks.into_iter()) | ||
.collect(), | ||
})) | ||
} | ||
} | ||
|
@@ -955,7 +959,7 @@ impl InMemoryRowGroup<'_> { | |
.map(|(idx, _chunk)| { | ||
let column = metadata.column(idx); | ||
let (start, length) = column.byte_range(); | ||
start as usize..(start + length) as usize | ||
start..(start + length) | ||
}) | ||
.collect(); | ||
|
||
|
@@ -1125,9 +1129,16 @@ mod tests { | |
} | ||
|
||
impl AsyncFileReader for TestReader { | ||
fn get_bytes(&mut self, range: Range<usize>) -> BoxFuture<'_, Result<Bytes>> { | ||
self.requests.lock().unwrap().push(range.clone()); | ||
futures::future::ready(Ok(self.data.slice(range))).boxed() | ||
fn get_bytes(&mut self, range: Range<u64>) -> BoxFuture<'_, Result<Bytes>> { | ||
let range = range.clone(); | ||
self.requests | ||
.lock() | ||
.unwrap() | ||
.push(range.start as usize..range.end as usize); | ||
futures::future::ready(Ok(self | ||
.data | ||
.slice(range.start as usize..range.end as usize))) | ||
.boxed() | ||
} | ||
|
||
fn get_metadata<'a>( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.