-
Notifications
You must be signed in to change notification settings - Fork 659
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
Support reading PageIndex from parquet metadata, prepare for skipping pages at reading #1762
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
684b660
Add read options for column index based filtering
Ted-Jiang 90cf78c
try to deserialize pageIndex from parquet
Ted-Jiang 5f3e2f3
unable read pageIndex from parquet and test
Ted-Jiang 847813e
fix fmt
Ted-Jiang 3468a21
remove FixedLenByteIndex use ByteIndex
Ted-Jiang e96e537
Apply suggestions from code review
Ted-Jiang dbbd655
fix comments
Ted-Jiang 0f3b241
use enum instead of trait object
Ted-Jiang d4bbb86
fix and add comment
Ted-Jiang d8bd4ce
use from_le_slice instead of from_ne_slice
Ted-Jiang 1e315d2
use builder option
Ted-Jiang db575cf
remove useless trait
Ted-Jiang 2b5264b
fix from_le_slice
Ted-Jiang File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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,209 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use crate::basic::Type; | ||
use crate::data_type::private::ParquetValueType; | ||
use crate::data_type::Int96; | ||
use crate::errors::ParquetError; | ||
use crate::util::bit_util::from_le_slice; | ||
use parquet_format::{BoundaryOrder, ColumnIndex}; | ||
use std::fmt::Debug; | ||
|
||
/// The statistics in one page | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub struct PageIndex<T> { | ||
/// The minimum value, It is None when all values are null | ||
pub min: Option<T>, | ||
/// The maximum value, It is None when all values are null | ||
pub max: Option<T>, | ||
/// Null values in the page | ||
pub null_count: Option<i64>, | ||
} | ||
|
||
impl<T> PageIndex<T> { | ||
pub fn min(&self) -> Option<&T> { | ||
self.min.as_ref() | ||
} | ||
pub fn max(&self) -> Option<&T> { | ||
self.max.as_ref() | ||
} | ||
pub fn null_count(&self) -> Option<i64> { | ||
self.null_count | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub enum Index { | ||
BOOLEAN(BooleanIndex), | ||
INT32(NativeIndex<i32>), | ||
INT64(NativeIndex<i64>), | ||
INT96(NativeIndex<Int96>), | ||
FLOAT(NativeIndex<f32>), | ||
DOUBLE(NativeIndex<f64>), | ||
BYTE_ARRAY(ByteArrayIndex), | ||
FIXED_LEN_BYTE_ARRAY(ByteArrayIndex), | ||
} | ||
|
||
/// An index of a column of [`Type`] physical representation | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub struct NativeIndex<T: ParquetValueType> { | ||
/// The physical type | ||
pub physical_type: Type, | ||
/// The indexes, one item per page | ||
pub indexes: Vec<PageIndex<T>>, | ||
/// the order | ||
pub boundary_order: BoundaryOrder, | ||
} | ||
|
||
impl<T: ParquetValueType> NativeIndex<T> { | ||
/// Creates a new [`NativeIndex`] | ||
pub(crate) fn try_new( | ||
index: ColumnIndex, | ||
physical_type: Type, | ||
) -> Result<Self, ParquetError> { | ||
let len = index.min_values.len(); | ||
|
||
let null_counts = index | ||
.null_counts | ||
.map(|x| x.into_iter().map(Some).collect::<Vec<_>>()) | ||
.unwrap_or_else(|| vec![None; len]); | ||
|
||
let indexes = index | ||
.min_values | ||
.iter() | ||
.zip(index.max_values.into_iter()) | ||
.zip(index.null_pages.into_iter()) | ||
.zip(null_counts.into_iter()) | ||
.map(|(((min, max), is_null), null_count)| { | ||
let (min, max) = if is_null { | ||
(None, None) | ||
} else { | ||
let min = min.as_slice(); | ||
let max = max.as_slice(); | ||
(Some(from_le_slice::<T>(min)), Some(from_le_slice::<T>(max))) | ||
}; | ||
Ok(PageIndex { | ||
min, | ||
max, | ||
null_count, | ||
}) | ||
}) | ||
.collect::<Result<Vec<_>, ParquetError>>()?; | ||
|
||
Ok(Self { | ||
physical_type, | ||
indexes, | ||
boundary_order: index.boundary_order, | ||
}) | ||
} | ||
} | ||
|
||
/// An index of a column of bytes type | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub struct ByteArrayIndex { | ||
/// The physical type | ||
pub physical_type: Type, | ||
/// The indexes, one item per page | ||
pub indexes: Vec<PageIndex<Vec<u8>>>, | ||
pub boundary_order: BoundaryOrder, | ||
} | ||
|
||
impl ByteArrayIndex { | ||
pub(crate) fn try_new( | ||
index: ColumnIndex, | ||
physical_type: Type, | ||
) -> Result<Self, ParquetError> { | ||
let len = index.min_values.len(); | ||
|
||
let null_counts = index | ||
.null_counts | ||
.map(|x| x.into_iter().map(Some).collect::<Vec<_>>()) | ||
.unwrap_or_else(|| vec![None; len]); | ||
|
||
let indexes = index | ||
.min_values | ||
.into_iter() | ||
.zip(index.max_values.into_iter()) | ||
.zip(index.null_pages.into_iter()) | ||
.zip(null_counts.into_iter()) | ||
.map(|(((min, max), is_null), null_count)| { | ||
let (min, max) = if is_null { | ||
(None, None) | ||
} else { | ||
(Some(min), Some(max)) | ||
}; | ||
Ok(PageIndex { | ||
min, | ||
max, | ||
null_count, | ||
}) | ||
}) | ||
.collect::<Result<Vec<_>, ParquetError>>()?; | ||
|
||
Ok(Self { | ||
physical_type, | ||
indexes, | ||
boundary_order: index.boundary_order, | ||
}) | ||
} | ||
} | ||
|
||
/// An index of a column of boolean physical type | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub struct BooleanIndex { | ||
/// The indexes, one item per page | ||
pub indexes: Vec<PageIndex<bool>>, | ||
pub boundary_order: BoundaryOrder, | ||
} | ||
|
||
impl BooleanIndex { | ||
pub(crate) fn try_new(index: ColumnIndex) -> Result<Self, ParquetError> { | ||
let len = index.min_values.len(); | ||
|
||
let null_counts = index | ||
.null_counts | ||
.map(|x| x.into_iter().map(Some).collect::<Vec<_>>()) | ||
.unwrap_or_else(|| vec![None; len]); | ||
|
||
let indexes = index | ||
.min_values | ||
.into_iter() | ||
.zip(index.max_values.into_iter()) | ||
.zip(index.null_pages.into_iter()) | ||
.zip(null_counts.into_iter()) | ||
.map(|(((min, max), is_null), null_count)| { | ||
let (min, max) = if is_null { | ||
(None, None) | ||
} else { | ||
let min = min[0] != 0; | ||
let max = max[0] == 1; | ||
(Some(min), Some(max)) | ||
}; | ||
Ok(PageIndex { | ||
min, | ||
max, | ||
null_count, | ||
}) | ||
}) | ||
.collect::<Result<Vec<_>, ParquetError>>()?; | ||
|
||
Ok(Self { | ||
indexes, | ||
boundary_order: index.boundary_order, | ||
}) | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CamelCase is generally preferred to shouty case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should align with
Type
arrow-rs/parquet/src/basic.rs
Lines 45 to 53 in 90cf78c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair, I mean to change that but it has been low on my priority list 😅