pitrou commented on code in PR #5080:
URL: https://github.com/apache/arrow-rs/pull/5080#discussion_r1399287863
##########
arrow-integration-testing/src/lib.rs:
##########
@@ -44,7 +50,50 @@ pub struct ArrowFile {
pub batches: Vec<RecordBatch>,
}
-pub fn read_json_file(json_name: &str) -> Result<ArrowFile> {
+// Canonicalize the names of map fields in a schema
+pub fn canonicalize_schema(schema: &Schema) -> Schema {
+ let fields = schema
+ .fields()
+ .iter()
+ .map(|field| match field.data_type() {
+ DataType::Map(child_field, sorted) => match
child_field.data_type() {
+ DataType::Struct(fields) if fields.len() == 2 => {
+ let first_field = fields.get(0).unwrap();
+ let key_field =
+ Arc::new(Field::new("key",
first_field.data_type().clone(), false));
+ let second_field = fields.get(1).unwrap();
+ let value_field = Arc::new(Field::new(
+ "value",
+ second_field.data_type().clone(),
+ second_field.is_nullable(),
+ ));
+
+ let fields = Fields::from([key_field, value_field]);
+ let struct_type = DataType::Struct(fields);
+ let child_field = Field::new("entries", struct_type,
false);
+
+ Arc::new(Field::new(
+ field.name().as_str(),
+ DataType::Map(Arc::new(child_field), *sorted),
+ field.is_nullable(),
+ ))
+ }
+ _ => panic!("The child field of Map type should be Struct type
with 2 fields."),
+ },
+ _ => field.clone(),
+ })
+ .collect::<Fields>();
+
+ Schema::new(fields).with_metadata(schema.metadata().clone())
+}
+
+struct PartialArrowFile {
Review Comment:
Ok, I did the suggested changes.
--
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]