Skip to content

Commit 6ff8cc4

Browse files
heilheadHarryET
andauthored
Support for Arc<str> in ParquetRecordWriter derive macro (#8973)
# Which issue does this PR close? - Closes #8972. # Rationale for this change See #8972 for more info. # What changes are included in this PR? Updates the derive macro implementation to include string serialization from `Arc<str>`. # Are these changes tested? Yes. I've updated `parquet_derive_test` to include writing `Arc<str>`. And we've been using our fork with these changes in production for ~3 years. # Are there any user-facing changes? Not sure, probably not? --------- Co-authored-by: Harry Bairstow <h.bairstow22@gmail.com>
1 parent 2d89500 commit 6ff8cc4

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

parquet_derive/src/parquet_field.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ impl Type {
643643
}
644644
"f32" => BasicType::FLOAT,
645645
"f64" => BasicType::DOUBLE,
646-
"String" | "str" => BasicType::BYTE_ARRAY,
646+
"String" | "str" | "Arc < str >" => BasicType::BYTE_ARRAY,
647647
"Uuid" => BasicType::FIXED_LEN_BYTE_ARRAY,
648648
f => unimplemented!("{} currently is not supported", f),
649649
}
@@ -733,7 +733,7 @@ impl Type {
733733
"NaiveDate" => quote! { Some(LogicalType::Date) },
734734
"NaiveDateTime" => quote! { None },
735735
"f32" | "f64" => quote! { None },
736-
"String" | "str" => quote! { Some(LogicalType::String) },
736+
"String" | "str" | "Arc < str >" => quote! { Some(LogicalType::String) },
737737
"Uuid" => quote! { Some(LogicalType::Uuid) },
738738
f => unimplemented!("{} currently is not supported", f),
739739
}

parquet_derive_test/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@
2323
#![allow(clippy::approx_constant)]
2424

2525
use parquet_derive::{ParquetRecordReader, ParquetRecordWriter};
26+
use std::sync::Arc;
2627

2728
#[derive(ParquetRecordWriter)]
2829
struct ACompleteRecord<'a> {
2930
pub a_bool: bool,
3031
pub a_str: &'a str,
3132
pub a_string: String,
3233
pub a_borrowed_string: &'a String,
34+
pub a_arc_str: Arc<str>,
3335
pub maybe_a_str: Option<&'a str>,
3436
pub maybe_a_string: Option<String>,
37+
pub maybe_a_arc_str: Option<Arc<str>>,
3538
pub i16: i16,
3639
pub i32: i32,
3740
pub u64: u64,
@@ -130,8 +133,10 @@ mod tests {
130133
REQUIRED BINARY a_str (STRING);
131134
REQUIRED BINARY a_string (STRING);
132135
REQUIRED BINARY a_borrowed_string (STRING);
136+
REQUIRED BINARY a_arc_str (STRING);
133137
OPTIONAL BINARY maybe_a_str (STRING);
134138
OPTIONAL BINARY maybe_a_string (STRING);
139+
OPTIONAL BINARY maybe_a_arc_str (STRING);
135140
REQUIRED INT32 i16 (INTEGER(16,true));
136141
REQUIRED INT32 i32;
137142
REQUIRED INT64 u64 (INTEGER(64,false));
@@ -159,8 +164,10 @@ mod tests {
159164

160165
let a_str = "hello mother".to_owned();
161166
let a_borrowed_string = "cool news".to_owned();
167+
let a_arc_str: Arc<str> = "hello arc".into();
162168
let maybe_a_string = Some("it's true, I'm a string".to_owned());
163169
let maybe_a_str = Some(&a_str[..]);
170+
let maybe_a_arc_str = Some(a_arc_str.clone());
164171
let borrowed_byte_vec = vec![0x68, 0x69, 0x70];
165172
let borrowed_maybe_byte_vec = Some(vec![0x71, 0x72]);
166173
let borrowed_maybe_borrowed_byte_vec = Some(&borrowed_byte_vec[..]);
@@ -170,8 +177,10 @@ mod tests {
170177
a_str: &a_str[..],
171178
a_string: "hello father".into(),
172179
a_borrowed_string: &a_borrowed_string,
180+
a_arc_str,
173181
maybe_a_str: Some(&a_str[..]),
174182
maybe_a_string: Some(a_str.clone()),
183+
maybe_a_arc_str,
175184
i16: -45,
176185
i32: 456,
177186
u64: 4563424,

0 commit comments

Comments
 (0)