Joseph-Rance commented on code in PR #4773:
URL: https://github.com/apache/arrow-rs/pull/4773#discussion_r1328702870


##########
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 think because I used an `Rc` type here, we don't need to have something 
owning the value referenced. It's possible I have misunderstood how this works, 
though. [The 
documentation](https://doc.rust-lang.org/alloc/rc/#:~:text=%E2%80%98Rc%E2%80%99%20stands%20for%20%E2%80%98Reference%20Counted%E2%80%99.%20The%20type%20Rc%3CT%3E,pointer%20to%20the%20same%20allocation%20in%20the%20heap.)
 says:
   
   > The type [Rc<T>](https://doc.rust-lang.org/alloc/rc/struct.Rc.html) 
provides shared ownership of a value of type T, allocated in the heap. Invoking 
[clone](https://doc.rust-lang.org/core/clone/trait.Clone.html#tymethod.clone) 
on [Rc](https://doc.rust-lang.org/alloc/rc/struct.Rc.html) produces a new 
pointer to the same allocation in the heap. When the last 
[Rc](https://doc.rust-lang.org/alloc/rc/struct.Rc.html) pointer to a given 
allocation is destroyed, the value stored in that allocation (often referred to 
as “inner value”) is also dropped.



##########
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 think because I used an `Rc` type here, we don't need to have something 
owning the value referenced. It's possible I have misunderstood how this works, 
though. [The 
documentation](https://doc.rust-lang.org/alloc/rc/#:~:text=%E2%80%98Rc%E2%80%99%20stands%20for%20%E2%80%98Reference%20Counted%E2%80%99.%20The%20type%20Rc%3CT%3E,pointer%20to%20the%20same%20allocation%20in%20the%20heap.)
 says:
   
   > The type [Rc<T>](https://doc.rust-lang.org/alloc/rc/struct.Rc.html) 
provides shared ownership of a value of type T, allocated in the heap. Invoking 
[clone](https://doc.rust-lang.org/core/clone/trait.Clone.html#tymethod.clone) 
on [Rc](https://doc.rust-lang.org/alloc/rc/struct.Rc.html) produces a new 
pointer to the same allocation in the heap. When the last 
[Rc](https://doc.rust-lang.org/alloc/rc/struct.Rc.html) pointer to a given 
allocation is destroyed, the value stored in that allocation (often referred to 
as “inner value”) is also dropped.



-- 
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]

Reply via email to