Skip to content

Commit d02d85e

Browse files
committed
[FIX] fix pr review suggestions
1 parent 0cae3ab commit d02d85e

File tree

7 files changed

+600
-943
lines changed

7 files changed

+600
-943
lines changed

parquet-variant-compute/src/variant_array.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,21 @@ impl VariantArray {
179179
/// Note: Does not do deep validation of the [`Variant`], so it is up to the
180180
/// caller to ensure that the metadata and value were constructed correctly.
181181
pub fn value(&self, index: usize) -> Variant<'_, '_> {
182-
match &self.shredding_state {
183-
ShreddingState::Unshredded { value } => {
182+
match (self.shredding_state.value_field(), self.shredding_state.typed_value_field()) {
183+
(Some(value), None) => {
184+
// Unshredded case
184185
Variant::new(self.metadata.value(index), value.value(index))
185186
}
186-
ShreddingState::PerfectlyShredded { typed_value, .. } => {
187+
(None, Some(typed_value)) => {
188+
// PerfectlyShredded case
187189
if typed_value.is_null(index) {
188190
Variant::Null
189191
} else {
190192
typed_value_to_variant(typed_value, index)
191193
}
192194
}
193-
ShreddingState::ImperfectlyShredded { value, typed_value } => {
195+
(Some(value), Some(typed_value)) => {
196+
// ImperfectlyShredded case
194197
if typed_value.is_null(index) {
195198
Variant::new(self.metadata.value(index), value.value(index))
196199
} else {
@@ -256,7 +259,7 @@ impl VariantArray {
256259
/// additional fields), or NULL (`v:a` was an object containing only the single expected field `b`).
257260
///
258261
/// Finally, `v.typed_value.a.typed_value.b.value` is either NULL (`v:a.b` was an integer) or else a
259-
/// variant value.
262+
/// variant value (which could be `Variant::Null`).
260263
#[derive(Debug)]
261264
pub struct ShreddedVariantFieldArray {
262265
/// Reference to the underlying StructArray
@@ -361,7 +364,10 @@ impl Array for ShreddedVariantFieldArray {
361364
}
362365

363366
fn nulls(&self) -> Option<&NullBuffer> {
364-
self.inner.nulls()
367+
// According to the shredding spec, ShreddedVariantFieldArray should be
368+
// physically non-nullable - SQL NULL is inferred by both value and
369+
// typed_value being physically NULL
370+
None
365371
}
366372

367373
fn get_buffer_memory_size(&self) -> usize {
@@ -451,6 +457,8 @@ impl ShreddingState {
451457
ShreddingState::PartiallyShredded { metadata, .. } => metadata,
452458
ShreddingState::AllNull { metadata } => metadata,
453459
}
460+
461+
Ok(Self { value, typed_value })
454462
}
455463

456464
/// Return a reference to the value field, if present
@@ -506,7 +514,7 @@ impl ShreddingState {
506514
///
507515
/// TODO: move to arrow crate
508516
#[derive(Debug, Default, Clone)]
509-
pub struct StructArrayBuilder {
517+
pub(crate) struct StructArrayBuilder {
510518
fields: Vec<FieldRef>,
511519
arrays: Vec<ArrayRef>,
512520
nulls: Option<NullBuffer>,

0 commit comments

Comments
 (0)