Skip to content

Commit 729b258

Browse files
authored
[parquet] Adding counting method in thrift_enum macro to support ENCODING_SLOTS (#8663)
# Which issue does this PR close? - Closes [#8662] # Rationale for this change Related to #8607 We need to know how many encoding are support to create a decoder slot. # What changes are included in this PR? Update the `thrift_enum` to know the fields count of enum `Encoding`, and the value is passed to `EncodingMask` And the `ENCODING_SLOTS` # Are these changes tested? 1. Originally I think add a UT can prevent failure after the new encoding are introduced, then I realized the counts are already transferred, the UT is not required, the original tests can already cover the code. # Are there any user-facing changes? No
1 parent 928daa4 commit 729b258

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

parquet/src/basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ pub struct EncodingMask(i32);
741741

742742
impl EncodingMask {
743743
/// Highest valued discriminant in the [`Encoding`] enum
744-
const MAX_ENCODING: i32 = Encoding::BYTE_STREAM_SPLIT as i32;
744+
const MAX_ENCODING: i32 = Encoding::MAX_DISCRIMINANT;
745745
/// A mask consisting of unused bit positions, used for validation. This includes the never
746746
/// used GROUP_VAR_INT encoding value of `1`.
747747
const ALLOWED_MASK: u32 =

parquet/src/column/reader/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub trait ColumnValueDecoder {
138138
///
139139
/// This replaces `HashMap` lookups with direct indexing to avoid hashing overhead in the
140140
/// hot decoding paths.
141-
const ENCODING_SLOTS: usize = Encoding::BYTE_STREAM_SPLIT as usize + 1;
141+
const ENCODING_SLOTS: usize = Encoding::MAX_DISCRIMINANT as usize + 1;
142142

143143
/// An implementation of [`ColumnValueDecoder`] for `[T::T]`
144144
pub struct ColumnValueDecoderImpl<T: DataType> {

parquet/src/parquet_macros.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,35 @@ macro_rules! thrift_enum {
8181
Ok(field_id)
8282
}
8383
}
84+
85+
impl $identifier {
86+
#[allow(deprecated)]
87+
#[doc = "Returns a slice containing every variant of this enum."]
88+
#[allow(dead_code)]
89+
pub const VARIANTS: &'static [Self] = &[
90+
$(Self::$field_name),*
91+
];
92+
93+
#[allow(deprecated)]
94+
const fn max_discriminant_impl() -> i32 {
95+
let values: &[i32] = &[$($field_value),*];
96+
let mut max = values[0];
97+
let mut idx = 1;
98+
while idx < values.len() {
99+
let candidate = values[idx];
100+
if candidate > max {
101+
max = candidate;
102+
}
103+
idx += 1;
104+
}
105+
max
106+
}
107+
108+
#[allow(deprecated)]
109+
#[doc = "Returns the largest discriminant value defined for this enum."]
110+
#[allow(dead_code)]
111+
pub const MAX_DISCRIMINANT: i32 = Self::max_discriminant_impl();
112+
}
84113
}
85114
}
86115

0 commit comments

Comments
 (0)