Skip to content

Commit 5993dff

Browse files
authored
Migrate parquet-variant to Rust 2024 (#8510)
# Which issue does this PR close? - Contribute to #6827 # Rationale for this change Splitting up #8227. # What changes are included in this PR? Migrate `parquet-variant` to Rust 2024 # Are these changes tested? CI # Are there any user-facing changes? Yes
1 parent ba22a21 commit 5993dff

File tree

10 files changed

+156
-72
lines changed

10 files changed

+156
-72
lines changed

parquet-variant/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ repository = { workspace = true }
2727
authors = { workspace = true }
2828
keywords = ["arrow", "parquet", "variant"]
2929
readme = "README.md"
30-
edition = { workspace = true }
30+
edition = "2024"
3131
rust-version = { workspace = true }
3232

3333
[dependencies]

parquet-variant/benches/variant_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ use criterion::*;
2121

2222
use parquet_variant::{Variant, VariantBuilder};
2323
use rand::{
24-
distr::{uniform::SampleUniform, Alphanumeric},
25-
rngs::StdRng,
2624
Rng, SeedableRng,
25+
distr::{Alphanumeric, uniform::SampleUniform},
26+
rngs::StdRng,
2727
};
2828
use std::{hint, ops::Range};
2929

parquet-variant/src/builder.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// under the License.
1717
use crate::decoder::{VariantBasicType, VariantPrimitiveType};
1818
use crate::{
19-
ShortString, Variant, VariantDecimal16, VariantDecimal4, VariantDecimal8, VariantList,
19+
ShortString, Variant, VariantDecimal4, VariantDecimal8, VariantDecimal16, VariantList,
2020
VariantMetadata, VariantObject,
2121
};
2222
use arrow_schema::ArrowError;
@@ -3403,10 +3403,12 @@ mod tests {
34033403
// This should fail because "unknown_field" is not in the metadata
34043404
let result = obj.try_insert("unknown_field", "value");
34053405
assert!(result.is_err());
3406-
assert!(result
3407-
.unwrap_err()
3408-
.to_string()
3409-
.contains("Field name 'unknown_field' not found"));
3406+
assert!(
3407+
result
3408+
.unwrap_err()
3409+
.to_string()
3410+
.contains("Field name 'unknown_field' not found")
3411+
);
34103412
}
34113413
}
34123414

parquet-variant/src/decoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
// KIND, either express or implied. See the License for the
1515
// specific language governing permissions and limitations
1616
// under the License.
17+
use crate::ShortString;
1718
use crate::utils::{
1819
array_from_slice, overflow_error, slice_from_slice_at_offset, string_from_slice,
1920
};
20-
use crate::ShortString;
2121

2222
use arrow_schema::ArrowError;
2323
use chrono::{DateTime, Duration, NaiveDate, NaiveDateTime, NaiveTime, Utc};
@@ -143,7 +143,7 @@ impl OffsetSizeBytes {
143143
_ => {
144144
return Err(ArrowError::InvalidArgumentError(
145145
"offset_size_minus_one must be 0–3".to_string(),
146-
))
146+
));
147147
}
148148
};
149149
Ok(result)

parquet-variant/src/variant.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
pub use self::decimal::{VariantDecimal16, VariantDecimal4, VariantDecimal8};
18+
pub use self::decimal::{VariantDecimal4, VariantDecimal8, VariantDecimal16};
1919
pub use self::list::VariantList;
20-
pub use self::metadata::{VariantMetadata, EMPTY_VARIANT_METADATA, EMPTY_VARIANT_METADATA_BYTES};
20+
pub use self::metadata::{EMPTY_VARIANT_METADATA, EMPTY_VARIANT_METADATA_BYTES, VariantMetadata};
2121
pub use self::object::VariantObject;
2222

2323
// Publically export types used in the API
2424
pub use half::f16;
2525
pub use uuid::Uuid;
2626

2727
use crate::decoder::{
28-
self, get_basic_type, get_primitive_type, VariantBasicType, VariantPrimitiveType,
28+
self, VariantBasicType, VariantPrimitiveType, get_basic_type, get_primitive_type,
2929
};
3030
use crate::path::{VariantPath, VariantPathElement};
3131
use crate::utils::{first_byte_from_slice, fits_precision, slice_from_slice};

parquet-variant/src/variant/decimal.rs

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -285,20 +285,24 @@ mod tests {
285285
decimal4_too_large.is_err(),
286286
"Decimal4 precision overflow should fail"
287287
);
288-
assert!(decimal4_too_large
289-
.unwrap_err()
290-
.to_string()
291-
.contains("wider than max precision"));
288+
assert!(
289+
decimal4_too_large
290+
.unwrap_err()
291+
.to_string()
292+
.contains("wider than max precision")
293+
);
292294

293295
let decimal4_too_small = VariantDecimal4::try_new(-1_000_000_000_i32, 2);
294296
assert!(
295297
decimal4_too_small.is_err(),
296298
"Decimal4 precision underflow should fail"
297299
);
298-
assert!(decimal4_too_small
299-
.unwrap_err()
300-
.to_string()
301-
.contains("wider than max precision"));
300+
assert!(
301+
decimal4_too_small
302+
.unwrap_err()
303+
.to_string()
304+
.contains("wider than max precision")
305+
);
302306

303307
// Test valid edge cases for Decimal4
304308
let decimal4_max_valid = VariantDecimal4::try_new(999_999_999_i32, 2);
@@ -319,20 +323,24 @@ mod tests {
319323
decimal8_too_large.is_err(),
320324
"Decimal8 precision overflow should fail"
321325
);
322-
assert!(decimal8_too_large
323-
.unwrap_err()
324-
.to_string()
325-
.contains("wider than max precision"));
326+
assert!(
327+
decimal8_too_large
328+
.unwrap_err()
329+
.to_string()
330+
.contains("wider than max precision")
331+
);
326332

327333
let decimal8_too_small = VariantDecimal8::try_new(-1_000_000_000_000_000_000_i64, 2);
328334
assert!(
329335
decimal8_too_small.is_err(),
330336
"Decimal8 precision underflow should fail"
331337
);
332-
assert!(decimal8_too_small
333-
.unwrap_err()
334-
.to_string()
335-
.contains("wider than max precision"));
338+
assert!(
339+
decimal8_too_small
340+
.unwrap_err()
341+
.to_string()
342+
.contains("wider than max precision")
343+
);
336344

337345
// Test valid edge cases for Decimal8
338346
let decimal8_max_valid = VariantDecimal8::try_new(999_999_999_999_999_999_i64, 2);
@@ -354,21 +362,25 @@ mod tests {
354362
decimal16_too_large.is_err(),
355363
"Decimal16 precision overflow should fail"
356364
);
357-
assert!(decimal16_too_large
358-
.unwrap_err()
359-
.to_string()
360-
.contains("wider than max precision"));
365+
assert!(
366+
decimal16_too_large
367+
.unwrap_err()
368+
.to_string()
369+
.contains("wider than max precision")
370+
);
361371

362372
let decimal16_too_small =
363373
VariantDecimal16::try_new(-100000000000000000000000000000000000000_i128, 2);
364374
assert!(
365375
decimal16_too_small.is_err(),
366376
"Decimal16 precision underflow should fail"
367377
);
368-
assert!(decimal16_too_small
369-
.unwrap_err()
370-
.to_string()
371-
.contains("wider than max precision"));
378+
assert!(
379+
decimal16_too_small
380+
.unwrap_err()
381+
.to_string()
382+
.contains("wider than max precision")
383+
);
372384

373385
// Test valid edge cases for Decimal16
374386
let decimal16_max_valid =
@@ -394,10 +406,12 @@ mod tests {
394406
decimal4_invalid_scale.is_err(),
395407
"Decimal4 with scale > 9 should fail"
396408
);
397-
assert!(decimal4_invalid_scale
398-
.unwrap_err()
399-
.to_string()
400-
.contains("larger than max precision"));
409+
assert!(
410+
decimal4_invalid_scale
411+
.unwrap_err()
412+
.to_string()
413+
.contains("larger than max precision")
414+
);
401415

402416
let decimal4_invalid_scale_large = VariantDecimal4::try_new(123_i32, 20);
403417
assert!(
@@ -418,10 +432,12 @@ mod tests {
418432
decimal8_invalid_scale.is_err(),
419433
"Decimal8 with scale > 18 should fail"
420434
);
421-
assert!(decimal8_invalid_scale
422-
.unwrap_err()
423-
.to_string()
424-
.contains("larger than max precision"));
435+
assert!(
436+
decimal8_invalid_scale
437+
.unwrap_err()
438+
.to_string()
439+
.contains("larger than max precision")
440+
);
425441

426442
let decimal8_invalid_scale_large = VariantDecimal8::try_new(123_i64, 25);
427443
assert!(
@@ -442,10 +458,12 @@ mod tests {
442458
decimal16_invalid_scale.is_err(),
443459
"Decimal16 with scale > 38 should fail"
444460
);
445-
assert!(decimal16_invalid_scale
446-
.unwrap_err()
447-
.to_string()
448-
.contains("larger than max precision"));
461+
assert!(
462+
decimal16_invalid_scale
463+
.unwrap_err()
464+
.to_string()
465+
.contains("larger than max precision")
466+
);
449467

450468
let decimal16_invalid_scale_large = VariantDecimal16::try_new(123_i128, 50);
451469
assert!(

parquet-variant/src/variant/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// KIND, either express or implied. See the License for the
1515
// specific language governing permissions and limitations
1616
// under the License.
17-
use crate::decoder::{map_bytes_to_offsets, OffsetSizeBytes};
17+
use crate::decoder::{OffsetSizeBytes, map_bytes_to_offsets};
1818
use crate::utils::{
1919
first_byte_from_slice, overflow_error, slice_from_slice, slice_from_slice_at_offset,
2020
};

parquet-variant/src/variant/metadata.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use crate::decoder::{map_bytes_to_offsets, OffsetSizeBytes};
18+
use crate::decoder::{OffsetSizeBytes, map_bytes_to_offsets};
1919
use crate::utils::{
2020
first_byte_from_slice, overflow_error, slice_from_slice, string_from_slice,
2121
try_binary_search_range_by,
@@ -285,14 +285,13 @@ impl<'m> VariantMetadata<'m> {
285285
let mut current_offset = offsets.next().unwrap_or(0);
286286
let mut prev_value: Option<&str> = None;
287287
for next_offset in offsets {
288-
let current_value =
289-
value_buffer
290-
.get(current_offset..next_offset)
291-
.ok_or_else(|| {
292-
ArrowError::InvalidArgumentError(format!(
288+
let current_value = value_buffer.get(current_offset..next_offset).ok_or_else(
289+
|| {
290+
ArrowError::InvalidArgumentError(format!(
293291
"range {current_offset}..{next_offset} is invalid or out of bounds"
294292
))
295-
})?;
293+
},
294+
)?;
296295

297296
if let Some(prev_val) = prev_value {
298297
if current_value <= prev_val {

parquet-variant/src/variant/object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use crate::decoder::{map_bytes_to_offsets, OffsetSizeBytes};
18+
use crate::decoder::{OffsetSizeBytes, map_bytes_to_offsets};
1919
use crate::utils::{
2020
first_byte_from_slice, overflow_error, slice_from_slice, try_binary_search_range_by,
2121
};

0 commit comments

Comments
 (0)