alamb commented on code in PR #6990:
URL: https://github.com/apache/arrow-rs/pull/6990#discussion_r1920729763


##########
parquet/src/arrow/arrow_writer/mod.rs:
##########
@@ -3409,4 +3409,30 @@ mod tests {
             "Arrow: Incompatible type. Field 'temperature' has type Float64, 
array has type Int32"
         );
     }
+
+    #[test]
+    // https://github.com/apache/arrow-rs/issues/6988
+    fn test_roundtrip_empty_schema() {
+        // create empty record batch with empty schema
+        let empty_fields: Vec<Field> = vec![];
+        let empty_schema = Arc::new(Schema::new(empty_fields));
+        let empty_batch = RecordBatch::try_new_with_options(
+            empty_schema,
+            vec![],
+            &RecordBatchOptions::default().with_row_count(Some(0)),
+        )
+        .unwrap();
+
+        // write to parquet
+        let mut parquet_bytes: Vec<u8> = Vec::new();
+        let mut writer =
+            ArrowWriter::try_new(&mut parquet_bytes, empty_batch.schema(), 
None).unwrap();
+        writer.write(&empty_batch).unwrap();
+        writer.close().unwrap();
+
+        // read from parquet
+        let bytes = Bytes::from(parquet_bytes);
+        let result = ParquetRecordBatchReaderBuilder::try_new(bytes);
+        result.unwrap();

Review Comment:
   I think we should also 
   1. check that the schema is correctly read back
   2. Verify that the reader works correctly (reading back no batches)
   
   For example, something like:
   
   ```suggestion
           // read from parquet
           let bytes = Bytes::from(parquet_bytes);
           let reader = 
ParquetRecordBatchReaderBuilder::try_new(bytes).unwrap();
           assert_eq!(reader.schema(), &empty_batch.schema());
           let batches: Vec<_> = 
reader.build().unwrap().collect::<ArrowResult<Vec<_>>>().unwrap();
           assert_eq!(batches.len(), 0);
   ```
   
   (I ran this locally and it passed so I think we could also make these 
changes as a follow on PR)



##########
parquet/src/arrow/arrow_writer/mod.rs:
##########
@@ -3409,4 +3409,30 @@ mod tests {
             "Arrow: Incompatible type. Field 'temperature' has type Float64, 
array has type Int32"
         );
     }
+
+    #[test]
+    // https://github.com/apache/arrow-rs/issues/6988
+    fn test_roundtrip_empty_schema() {
+        // create empty record batch with empty schema
+        let empty_fields: Vec<Field> = vec![];
+        let empty_schema = Arc::new(Schema::new(empty_fields));

Review Comment:
   Very minor: you can use `Schema::empty` as well:
   
   ```suggestion
           let empty_schema = Arc::new(Schema::new(empty_fields));
   ```



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