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


##########
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 {

Review Comment:
   fixed in 
[9f2dd9f](https://github.com/apache/arrow-rs/pull/4773/commits/9f2dd9f901462b6221bc7ba9fab04343c85469b6)



##########
parquet_derive/src/parquet_field.rs:
##########
@@ -223,6 +223,80 @@ impl Field {
         }
     }
 
+    /// Takes the parsed field of the struct and emits a valid
+    /// column reader snippet. Should match exactly what you
+    /// would write by hand.
+    ///
+    /// Can only generate writers for basic structs, for example:
+    ///
+    /// struct Record {
+    ///   a_bool: bool
+    /// }
+    ///
+    /// but not
+    ///
+    /// struct UnsupportedNestedRecord {
+    ///   a_property: bool,
+    ///   nested_record: Record
+    /// }
+    ///
+    /// because this parsing logic is not sophisticated enough for definition
+    /// levels beyond 2.
+    ///
+    /// `Option` types and references not supported
+    pub fn reader_snippet(&self) -> proc_macro2::TokenStream {
+        use parquet::basic::Type as BasicType;
+
+        let ident = &self.ident;
+        let column_reader = self.ty.column_reader();
+        let parquet_type = self.ty.physical_type_as_rust();
+
+        let default_type = match self.ty.physical_type() {
+            BasicType::BYTE_ARRAY | BasicType::FIXED_LEN_BYTE_ARRAY => {
+                quote! { parquet::data_type::ByteArray::new() }
+            }
+            BasicType::BOOLEAN => quote! { false },
+            BasicType::FLOAT | BasicType::DOUBLE => quote! { 0. },
+            BasicType::INT32 | BasicType::INT64 | BasicType::INT96 => quote! { 
0 },
+        };
+
+        let write_batch_expr = quote! {
+            let mut vals_vec = Vec::new();
+            vals_vec.resize(max_records, #default_type);
+            let mut vals: &mut [#parquet_type] = vals_vec.as_mut_slice();
+            if let #column_reader(mut typed) = column_reader {
+                typed.read_records(max_records, None, None, vals)?;
+            } else {
+                panic!("Schema and struct disagree on type for {}", 
stringify!{#ident});
+            }
+        };
+
+        let vals_writer = match &self.ty {

Review Comment:
   fixed in 
[9f2dd9f](https://github.com/apache/arrow-rs/pull/4773/commits/9f2dd9f901462b6221bc7ba9fab04343c85469b6)



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