forked from jorgecarleitao/parquet2
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved typing to reduce clones and use of unwraps (jorgecarleitao#106)
- Loading branch information
1 parent
b6c952f
commit 4aed8f4
Showing
32 changed files
with
285 additions
and
450 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 |
---|---|---|
|
@@ -2,3 +2,4 @@ target | |
Cargo.lock | ||
.idea | ||
venv | ||
fixtures/ |
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 |
---|---|---|
@@ -1,78 +1,43 @@ | ||
use crate::schema::types::{ParquetType, PhysicalType}; | ||
use crate::schema::types::{ParquetType, PrimitiveType}; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub struct Descriptor { | ||
/// The [`PrimitiveType`] of this column | ||
pub primitive_type: PrimitiveType, | ||
|
||
/// The maximum definition level | ||
pub max_def_level: i16, | ||
|
||
/// The maximum repetition level | ||
pub max_rep_level: i16, | ||
} | ||
|
||
/// A descriptor for leaf-level primitive columns. | ||
/// This encapsulates information such as definition and repetition levels and is used to | ||
/// re-assemble nested data. | ||
#[derive(Debug, PartialEq, Clone)] | ||
pub struct ColumnDescriptor { | ||
// The "leaf" primitive type of this column | ||
primitive_type: ParquetType, | ||
|
||
// The maximum definition level for this column | ||
max_def_level: i16, | ||
|
||
// The maximum repetition level for this column | ||
max_rep_level: i16, | ||
// The descriptor this columns' leaf. | ||
pub descriptor: Descriptor, | ||
|
||
// The path of this column. For instance, "a.b.c.d". | ||
path_in_schema: Vec<String>, | ||
pub path_in_schema: Vec<String>, | ||
|
||
base_type: ParquetType, | ||
/// The [`ParquetType`] this descriptor is a leaf of | ||
pub base_type: ParquetType, | ||
} | ||
|
||
impl ColumnDescriptor { | ||
/// Creates new descriptor for leaf-level column. | ||
pub fn new( | ||
primitive_type: ParquetType, | ||
max_def_level: i16, | ||
max_rep_level: i16, | ||
descriptor: Descriptor, | ||
path_in_schema: Vec<String>, | ||
base_type: ParquetType, | ||
) -> Self { | ||
Self { | ||
primitive_type, | ||
max_def_level, | ||
max_rep_level, | ||
descriptor, | ||
path_in_schema, | ||
base_type, | ||
} | ||
} | ||
|
||
/// Returns maximum definition level for this column. | ||
pub fn max_def_level(&self) -> i16 { | ||
self.max_def_level | ||
} | ||
|
||
/// Returns maximum repetition level for this column. | ||
pub fn max_rep_level(&self) -> i16 { | ||
self.max_rep_level | ||
} | ||
|
||
pub fn path_in_schema(&self) -> &[String] { | ||
&self.path_in_schema | ||
} | ||
|
||
pub fn base_type(&self) -> &ParquetType { | ||
&self.base_type | ||
} | ||
|
||
/// Returns self type [`ParquetType`] for this leaf column. | ||
pub fn type_(&self) -> &ParquetType { | ||
&self.primitive_type | ||
} | ||
|
||
/// Returns self type [`PhysicalType`] for this leaf column. | ||
/// # Panic | ||
/// This function panics if the corresponding [`ParquetType`] is not a primitive type | ||
pub fn physical_type(&self) -> &PhysicalType { | ||
match &self.primitive_type { | ||
ParquetType::PrimitiveType { physical_type, .. } => physical_type, | ||
_ => unreachable!(""), | ||
} | ||
} | ||
|
||
/// Returns column name. | ||
pub fn name(&self) -> &str { | ||
self.primitive_type.name() | ||
} | ||
} |
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.