edoardo-coronado opened a new issue, #4510:
URL: https://github.com/apache/arrow-rs/issues/4510

   I have written the following code in rust to create a parquet file with two 
columns using parquet 43.0.0:
   
   fn main()
   {
       let vector_length: usize = 4;
       let mut vector1: Vec<i32> = Vec::with_capacity(vector_length);
       let mut vector2: Vec<i64> = Vec::with_capacity(vector_length);
       let mut vector3: Vec<f32> = Vec::with_capacity(vector_length);
       let mut vector4: Vec<f64> = Vec::with_capacity(vector_length);
       let mut rng = rand::thread_rng();
       for _ in 0..vector_length
       {
           let random_number_i32: i32 = rng.gen();
           let random_number_i64: i64 = rng.gen();
           vector1.push(random_number_i32);
           vector2.push(random_number_i64);
       }
   
       let path:&Path = Path::new("./output.parquet");
       let file = fs::File::create(&path).unwrap();
   
       let message_type:&str = "message schema {\
       REQUIRED INT32 col_i32;\
       REQUIRED INT64 col_i64;\
       let schema = Arc::new(parse_message_type(message_type).unwrap());
       
       let props = Arc::new(WriterProperties::builder().build());
   
       let mut writer = SerializedFileWriter::new(file, schema, props).unwrap();
       let mut row_group_writer = writer.next_row_group().unwrap();
   
       if let Some(mut col_writer) = row_group_writer.next_column().unwrap()
       {
           col_writer.typed::<Int32Type>()
                     .write_batch(&vector1, None, None)
                     .unwrap();
           col_writer.close().unwrap()
       }
       if let Some(mut col_writer) = row_group_writer.next_column().unwrap()
       {
           col_writer.typed::<Int64Type>()
                     .write_batch(&vector2, None, None)
                     .unwrap();
           col_writer.close().unwrap()
       }
       row_group_writer.close().unwrap();
       writer.close().unwrap();
   }
   
   Despite it is working, I want to replace the two "if" blocks with while loop 
and a match instruction like this:
   
       while let Some(mut col_writer) = row_group_writer.next_column().unwrap()
       {
           match col_writer
           {
               ColumnWriter::Int32ColumnWriter(ref mut typed) => 
{typed.write_batch(&vector1, None, None).unwrap();}
               ColumnWriter::Int64ColumnWriter(ref mut typed) => 
{typed.write_batch(&vector2, None, None).unwrap();}
               _ => {}
           }
       }
   
   And I get the following error:
   
   error[E0308]: mismatched types
     --> src/main.rs:61:13
      |
   59 |         match col_writer
      |               ---------- this expression has type 
`SerializedColumnWriter<'_>`
   60 |         {
   61 |             ColumnWriter::Int32ColumnWriter(ref mut typed) => 
{typed.write_batch(&vector1, None, None).unwrap();}
      |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 
`SerializedColumnWriter<'_>`, found `ColumnWriter<'_>`
      |
   help: you might have meant to use field `inner` whose type is 
`ColumnWriter<'_>`
      |
   59 |         match col_writer.inner
      |  
   
   I tried to solve it by invoking the inner property, but then I get a second 
error:
   
   error[E0616]: field `inner` of struct `SerializedColumnWriter` is private
     --> src/main.rs:59:26
      |
   59 |         match col_writer.inner
      |                          ^^^^^ private field
   
   Inner is a private property, then my question how can I check and match the 
type of a SerializedColumnWriter in order to chose different writing 
instructions. I know that this ColumnWriter::Int32ColumnWriter(ref mut typed) 
worked with parquet 4.2.0 according to this post in StackOverflow: 
https://stackoverflow.com/questions/67900928/writing-a-vec-of-rows-to-a-parquet-file
 .
   
   I greatly appreciate your help,
   
   Regards
   Edoardo
   


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