-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: Fix accidental quadratic parquet metadata (#18327)
- Loading branch information
Showing
9 changed files
with
152 additions
and
112 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,52 @@ | ||
use hashbrown::hash_map::RawEntryMut; | ||
use polars_parquet::read::{ColumnChunkMetaData, RowGroupMetaData}; | ||
use polars_utils::aliases::{PlHashMap, PlHashSet}; | ||
use polars_utils::idx_vec::UnitVec; | ||
use polars_utils::unitvec; | ||
|
||
pub(super) struct ColumnToColumnChunkMD<'a> { | ||
partitions: PlHashMap<String, UnitVec<usize>>, | ||
pub metadata: &'a RowGroupMetaData, | ||
} | ||
|
||
impl<'a> ColumnToColumnChunkMD<'a> { | ||
pub(super) fn new(metadata: &'a RowGroupMetaData) -> Self { | ||
Self { | ||
partitions: Default::default(), | ||
metadata, | ||
} | ||
} | ||
|
||
pub(super) fn set_partitions(&mut self, field_names: Option<&PlHashSet<&str>>) { | ||
for (i, ccmd) in self.metadata.columns().iter().enumerate() { | ||
let name = &ccmd.descriptor().path_in_schema[0]; | ||
if field_names | ||
.map(|field_names| field_names.contains(name.as_str())) | ||
.unwrap_or(true) | ||
{ | ||
let entry = self.partitions.raw_entry_mut().from_key(name.as_str()); | ||
|
||
match entry { | ||
RawEntryMut::Vacant(slot) => { | ||
slot.insert(name.to_string(), unitvec![i]); | ||
}, | ||
RawEntryMut::Occupied(mut slot) => { | ||
slot.get_mut().push(i); | ||
}, | ||
}; | ||
} | ||
} | ||
} | ||
|
||
pub(super) fn get_partitions(&self, name: &str) -> UnitVec<&ColumnChunkMetaData> { | ||
debug_assert!( | ||
!self.partitions.is_empty(), | ||
"fields should be partitioned first" | ||
); | ||
let columns = self.metadata.columns(); | ||
self.partitions | ||
.get(name) | ||
.map(|idx| idx.iter().map(|i| &columns[*i]).collect::<UnitVec<_>>()) | ||
.unwrap_or_default() | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
#[cfg(feature = "cloud")] | ||
mod async_impl; | ||
mod metadata; | ||
mod mmap; | ||
mod options; | ||
mod predicates; | ||
|
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
Oops, something went wrong.