Joseph-Rance commented on code in PR #4773:
URL: https://github.com/apache/arrow-rs/pull/4773#discussion_r1330380234
##########
parquet_derive/src/parquet_field.rs:
##########
@@ -354,6 +428,50 @@ impl Field {
}
}
+ fn copied_direct_fields(&self) -> proc_macro2::TokenStream {
+ let field_name = &self.ident;
+ let is_a_byte_buf = self.is_a_byte_buf;
+ let is_a_timestamp =
+ self.third_party_type == Some(ThirdPartyType::ChronoNaiveDateTime);
+ let is_a_date = self.third_party_type ==
Some(ThirdPartyType::ChronoNaiveDate);
+ let is_a_uuid = self.third_party_type == Some(ThirdPartyType::Uuid);
+
+ let value = if is_a_timestamp {
+ quote! {
::chrono::naive::NaiveDateTime::from_timestamp_millis(vals[i]).unwrap() }
+ } else if is_a_date {
+ quote! {
::chrono::naive::NaiveDate::from_num_days_from_ce_opt(vals[i]
+ + ((::chrono::naive::NaiveDate::from_ymd_opt(1970, 1, 1).unwrap()
+ - ::chrono::naive::NaiveDate::from_ymd_opt(0, 12,
31).unwrap()).num_days()) as i32).unwrap() }
+ } else if is_a_uuid {
+ quote! {
::uuid::Uuid::parse_str(vals[i].data().convert()).unwrap() }
+ } else if is_a_byte_buf {
+ quote! { vals[i].data().convert() }
+ } else {
+ quote! { vals[i].convert() }
+ };
+
+ // The below code would support references in field types, but it
prevents the compiler
Review Comment:
I wrote the below code to get the `Rc<str>`, but then I still can't get a
normal reference from this. I guess that's what you were saying here?
```rust
Type::Reference(_, ref first_type) => match **first_type {
Type::TypePath(_) => match self.ty.last_part().as_str() {
"String" => quote! {
std::rc::Rc::<String>::new(String::from(std::str::from_utf8(vals[i].data()).expect("invalid
UTF-8 sequence")))
},
"str" => quote! {
std::rc::Rc::<str>::from(std::str::from_utf8(vals[i].data()).expect("invalid
UTF-8 sequence"))
},
f => unimplemented!("Unsupported: {:#?}", f),
},
Type::Slice(_) => quote! { std::rc::Rc::<str>::from(vals[i].data()) },
ref f => unimplemented!("Unsupported: {:#?}", f),
},
```
In that case I guess we can't support returning references
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]