tustvold commented on code in PR #5003:
URL: https://github.com/apache/arrow-rs/pull/5003#discussion_r1376738909


##########
parquet/src/arrow/arrow_writer/mod.rs:
##########
@@ -771,6 +771,13 @@ fn write_leaf(writer: &mut ColumnWriter<'_>, levels: 
&ArrayLevels) -> Result<usi
                         .unwrap();
                     get_decimal_256_array_slice(array, indices)
                 }
+                ArrowDataType::Float16 => {
+                    let array = column
+                        .as_any()
+                        .downcast_ref::<arrow_array::Float16Array>()
+                        .unwrap();

Review Comment:
   ```suggestion
                       let array = column.as_primitive::<Float16Type>();
   ```



##########
parquet/src/arrow/arrow_reader/mod.rs:
##########
@@ -924,6 +925,53 @@ mod tests {
             .unwrap();
     }
 
+    #[test]
+    fn test_float16_roundtrip() -> Result<()> {
+        let schema = Arc::new(Schema::new(vec![Field::new(
+            "float16",
+            ArrowDataType::Float16,
+            true,
+        )]));
+
+        let mut buf = Vec::with_capacity(1024);
+        let mut writer = ArrowWriter::try_new(&mut buf, schema.clone(), None)?;
+
+        let original = RecordBatch::try_new(
+            schema,
+            vec![Arc::new(Float16Array::from_iter_values([
+                f16::EPSILON,
+                f16::INFINITY,
+                f16::MIN,
+                f16::MAX,
+                f16::NAN,
+                f16::INFINITY,
+                f16::NEG_INFINITY,
+                f16::ONE,
+                f16::NEG_ONE,
+                f16::ZERO,
+                f16::NEG_ZERO,
+                f16::E,
+                f16::PI,
+                f16::FRAC_1_PI,
+            ]))],
+        )?;
+
+        writer.write(&original)?;
+        writer.close()?;
+
+        let mut reader = ParquetRecordBatchReader::try_new(Bytes::from(buf), 
1024)?;
+        let ret = reader.next().unwrap()?;
+        assert_eq!(ret, original);
+
+        // Ensure can be downcast to the correct type
+        ret.column(0)
+            .as_any()
+            .downcast_ref::<Float16Array>()
+            .unwrap();

Review Comment:
   ```suggestion
           ret.column(0).as_primitive::<Float16Type>();
   ```



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