-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve parquet reading performance
~35-40%
(#3821)
* prevent double copy due to mmap and stop early with n_rows * improve parquet reading performance
- Loading branch information
Showing
4 changed files
with
124 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use super::*; | ||
use arrow::datatypes::Field; | ||
use arrow::io::parquet::read::{ | ||
column_iter_to_arrays, ArrayIter, BasicDecompressor, ColumnChunkMetaData, PageReader, | ||
}; | ||
|
||
// TODO! make public in arrow2? | ||
pub(super) fn get_field_columns<'a>( | ||
columns: &'a [ColumnChunkMetaData], | ||
field_name: &str, | ||
) -> Vec<&'a ColumnChunkMetaData> { | ||
columns | ||
.iter() | ||
.filter(|x| x.descriptor().path_in_schema[0] == field_name) | ||
.collect() | ||
} | ||
|
||
/// memory maps all columns that are part of the parquet field `field_name` | ||
pub(super) fn mmap_columns<'a>( | ||
file: &'a [u8], | ||
columns: &'a [ColumnChunkMetaData], | ||
field_name: &str, | ||
) -> Vec<(&'a ColumnChunkMetaData, &'a [u8])> { | ||
get_field_columns(columns, field_name) | ||
.into_iter() | ||
.map(|meta| _mmap_single_column(file, meta)) | ||
.collect() | ||
} | ||
|
||
fn _mmap_single_column<'a>( | ||
file: &'a [u8], | ||
meta: &'a ColumnChunkMetaData, | ||
) -> (&'a ColumnChunkMetaData, &'a [u8]) { | ||
let (start, len) = meta.byte_range(); | ||
let chunk = &file[start as usize..(start + len) as usize]; | ||
(meta, chunk) | ||
} | ||
|
||
// similar to arrow2 serializer, except this accepts a slice instead of a vec. | ||
// this allows use to memory map | ||
pub(super) fn to_deserializer<'a>( | ||
columns: Vec<(&ColumnChunkMetaData, &'a [u8])>, | ||
field: Field, | ||
num_rows: usize, | ||
chunk_size: Option<usize>, | ||
) -> ArrowResult<ArrayIter<'a>> { | ||
let chunk_size = chunk_size.unwrap_or(usize::MAX).min(num_rows); | ||
|
||
let (columns, types): (Vec<_>, Vec<_>) = columns | ||
.into_iter() | ||
.map(|(column_meta, chunk)| { | ||
let pages = PageReader::new( | ||
std::io::Cursor::new(chunk), | ||
column_meta, | ||
std::sync::Arc::new(|_, _| true), | ||
vec![], | ||
); | ||
( | ||
BasicDecompressor::new(pages, vec![]), | ||
&column_meta.descriptor().descriptor.primitive_type, | ||
) | ||
}) | ||
.unzip(); | ||
|
||
column_iter_to_arrays(columns, types, field, Some(chunk_size)) | ||
} |
This file contains 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 |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
//! } | ||
//! ``` | ||
//! | ||
pub(super) mod mmap; | ||
pub mod predicates; | ||
mod read; | ||
mod read_impl; | ||
|
This file contains 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 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