tustvold commented on code in PR #6539:
URL: https://github.com/apache/arrow-rs/pull/6539#discussion_r1795270632
##########
parquet/src/arrow/arrow_reader/mod.rs:
##########
@@ -3077,6 +3077,119 @@ mod tests {
);
}
+ #[test]
+ fn test_read_binary_as_utf8() {
+ let file = write_parquet_from_iter(vec![
+ (
+ "binary_to_utf8",
+ Arc::new(BinaryArray::from(vec![
+ b"one".as_ref(),
+ b"two".as_ref(),
+ b"three".as_ref(),
+ ])) as ArrayRef,
+ ),
+ (
+ "large_binary_to_large_utf8",
+ Arc::new(LargeBinaryArray::from(vec![
+ b"one".as_ref(),
+ b"two".as_ref(),
+ b"three".as_ref(),
+ ])) as ArrayRef,
+ ),
+ (
+ "binary_view_to_utf8_view",
+ Arc::new(BinaryViewArray::from(vec![
+ b"one".as_ref(),
+ b"two".as_ref(),
+ b"three".as_ref(),
+ ])) as ArrayRef,
+ ),
+ ]);
+ let supplied_fields = Fields::from(vec![
+ Field::new("binary_to_utf8", ArrowDataType::Utf8, false),
+ Field::new(
+ "large_binary_to_large_utf8",
+ ArrowDataType::LargeUtf8,
+ false,
+ ),
+ Field::new("binary_view_to_utf8_view", ArrowDataType::Utf8View,
false),
+ ]);
+
+ let options =
ArrowReaderOptions::new().with_schema(Arc::new(Schema::new(supplied_fields)));
+ let mut arrow_reader =
ParquetRecordBatchReaderBuilder::try_new_with_options(
+ file.try_clone().unwrap(),
+ options,
+ )
+ .expect("reader builder with schema")
+ .build()
+ .expect("reader with schema");
+
+ let batch = arrow_reader.next().unwrap().unwrap();
+ assert_eq!(batch.num_columns(), 3);
+ assert_eq!(batch.num_rows(), 3);
+ assert_eq!(
+ batch
+ .column(0)
+ .as_any()
+ .downcast_ref::<StringArray>()
+ .expect("downcast to string")
+ .iter()
Review Comment:
```suggestion
.column(0)
.as_string::<i32>()
.iter()
```
And the same below
--
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]