Skip to content

Commit 7dd6c23

Browse files
committed
[FIX] remove unsafe functions doing byte operations
1 parent 30e9cd2 commit 7dd6c23

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

parquet-variant-compute/src/variant_array.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
//! [`VariantArray`] implementation
1919
20-
2120
use arrow::array::{Array, ArrayData, ArrayRef, AsArray, StructArray};
2221
use arrow::buffer::NullBuffer;
2322
use arrow_schema::{ArrowError, DataType};
@@ -168,16 +167,6 @@ impl VariantArray {
168167
&self.value_ref
169168
}
170169

171-
/// Get the metadata bytes for a specific index
172-
pub fn metadata_bytes(&self, index: usize) -> &[u8] {
173-
self.metadata_field().as_binary_view().value(index)
174-
}
175-
176-
/// Get the value bytes for a specific index
177-
pub fn value_bytes(&self, index: usize) -> &[u8] {
178-
self.value_field().as_binary_view().value(index)
179-
}
180-
181170
/// Get the field names for an object at the given index
182171
pub fn get_field_names(&self, index: usize) -> Vec<String> {
183172
if index >= self.len() || self.is_null(index) {
@@ -201,7 +190,7 @@ impl VariantArray {
201190
pub fn with_fields_removed(&self, field_names: &[&str]) -> Result<Self, ArrowError> {
202191
use parquet_variant::VariantBuilder;
203192
use std::collections::HashSet;
204-
193+
205194
let fields_to_remove: HashSet<&str> = field_names.iter().copied().collect();
206195
let mut builder = crate::variant_array_builder::VariantArrayBuilder::new(self.len());
207196

@@ -210,19 +199,19 @@ impl VariantArray {
210199
builder.append_null();
211200
} else {
212201
let variant = self.value(i);
213-
202+
214203
// If it's an object, create a new object without the specified fields
215204
if let Some(obj) = variant.as_object() {
216205
let mut variant_builder = VariantBuilder::new();
217206
let mut object_builder = variant_builder.new_object();
218-
207+
219208
// Add all fields except the ones to remove
220209
for (field_name, field_value) in obj.iter() {
221210
if !fields_to_remove.contains(field_name) {
222211
object_builder.insert(field_name, field_value);
223212
}
224213
}
225-
214+
226215
object_builder.finish().unwrap();
227216
let (metadata, value) = variant_builder.finish();
228217
builder.append_variant_buffers(&metadata, &value);

parquet-variant-compute/src/variant_get.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ mod test {
9696

9797
use super::{variant_get, GetOptions};
9898

99-
fn single_variant_get_test(input_json: &str, path: parquet_variant::VariantPath, expected_json: &str) {
99+
fn single_variant_get_test(
100+
input_json: &str,
101+
path: parquet_variant::VariantPath,
102+
expected_json: &str,
103+
) {
100104
// Create input array from JSON string
101105
let input_array_ref: ArrayRef = Arc::new(StringArray::from(vec![Some(input_json)]));
102106
let input_variant_array_ref: ArrayRef =
@@ -138,7 +142,11 @@ mod test {
138142

139143
#[test]
140144
fn get_primitive_variant_list_index() {
141-
single_variant_get_test("[1234, 5678]", parquet_variant::VariantPath::from(0), "1234");
145+
single_variant_get_test(
146+
"[1234, 5678]",
147+
parquet_variant::VariantPath::from(0),
148+
"1234",
149+
);
142150
}
143151

144152
#[test]

parquet-variant/src/builder.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,7 @@ impl ValueBuffer {
305305
///
306306
/// This method will panic if the variant contains duplicate field names in objects
307307
/// when validation is enabled. For a fallible version, use [`ValueBuffer::try_append_variant`]
308-
fn append_variant(
309-
&mut self,
310-
variant: Variant<'_, '_>,
311-
metadata_builder: &mut MetadataBuilder,
312-
) {
308+
fn append_variant(&mut self, variant: Variant<'_, '_>, metadata_builder: &mut MetadataBuilder) {
313309
match variant {
314310
Variant::Null => self.append_null(),
315311
Variant::BooleanTrue => self.append_bool(true),

0 commit comments

Comments
 (0)