jecsand838 commented on code in PR #8349:
URL: https://github.com/apache/arrow-rs/pull/8349#discussion_r2365971262


##########
arrow-avro/src/reader/record.rs:
##########
@@ -834,8 +1205,88 @@ impl Decoder {
                 let nanos = (millis as i64) * 1_000_000;
                 builder.append_value(IntervalMonthDayNano::new(months as i32, 
days as i32, nanos));
             }
+            Self::Union(fields, type_ids, offsets, encodings, encoding_counts, 
None) => {
+                let branch = buf.get_long()?;
+                if branch < 0 {
+                    return Err(ArrowError::ParseError(format!(
+                        "Negative union branch index {branch}"
+                    )));
+                }
+                let idx = branch as usize;
+                if idx >= encodings.len() {
+                    return Err(ArrowError::ParseError(format!(
+                        "Union branch index {idx} out of range ({} branches)",
+                        encodings.len()
+                    )));
+                }
+                let type_id = fields
+                    .iter()
+                    .nth(idx)
+                    .map(|(type_id, _)| type_id)
+                    .unwrap_or_else(|| i8::try_from(idx).unwrap_or(0));
+                type_ids.push(type_id);
+                offsets.push(encoding_counts[idx]);
+                encodings[idx].decode(buf)?;
+                encoding_counts[idx] += 1;

Review Comment:
   @scovich So I ended up realizing that we'd need some sort of dedicated 
`UnionDecoder` implementation to fully abstract this cleanly. I was wanting to 
follow-up on that as part of the same future PR. It would be a pretty large 
charge and I want to make sure to develop it in a way that covers sparse 
`Union` types as well.



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