jecsand838 commented on code in PR #8349:
URL: https://github.com/apache/arrow-rs/pull/8349#discussion_r2365860001
##########
arrow-avro/src/reader/record.rs:
##########
@@ -214,6 +254,148 @@ struct EnumResolution {
default_index: i32,
}
+#[derive(Debug, Clone, Copy)]
+enum BranchDispatch {
+ NoMatch,
+ ToReader {
+ reader_idx: usize,
+ promotion: Promotion,
+ },
+}
+
+#[derive(Debug)]
+struct UnionResolution {
+ dispatch: Option<Arc<[BranchDispatch]>>,
+ kind: UnionResolvedKind,
+}
+
+#[derive(Debug)]
+enum UnionResolvedKind {
+ Both {
+ reader_type_codes: Arc<[i8]>,
+ },
+ ToSingle {
+ target: Box<Decoder>,
+ },
+ FromSingle {
+ reader_type_codes: Arc<[i8]>,
+ target_reader_index: usize,
+ promotion: Promotion,
+ },
+}
+
+#[derive(Debug, Default)]
+struct UnionResolutionBuilder {
+ fields: Option<UnionFields>,
+ resolved: Option<ResolvedUnion>,
+}
+
+impl UnionResolutionBuilder {
+ #[inline]
+ fn new() -> Self {
+ Self {
+ fields: None,
+ resolved: None,
+ }
+ }
+
+ #[inline]
+ fn with_fields(mut self, fields: UnionFields) -> Self {
+ self.fields = Some(fields);
+ self
+ }
+
+ #[inline]
+ fn with_resolved_union(mut self, resolved_union: &ResolvedUnion) -> Self {
+ self.resolved = Some(resolved_union.clone());
+ self
+ }
+
+ fn build(self) -> Result<UnionResolution, ArrowError> {
+ let info = self.resolved.ok_or_else(|| {
+ ArrowError::InvalidArgumentError(
+ "UnionResolutionBuilder requires resolved_union to be
provided".to_string(),
+ )
+ })?;
+ match (info.writer_is_union, info.reader_is_union) {
Review Comment:
Absolutely. That was on my radar. Not 100% sure why this was happening, but
when attempting to abstract the code last week I kept getting some pretty large
performance hits.
I'll give it another go this evening / tonight and improve the abstraction.
You're 100% right.
--
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]