Samyak2 commented on code in PR #7919: URL: https://github.com/apache/arrow-rs/pull/7919#discussion_r2207197814
########## parquet-variant/src/variant.rs: ########## @@ -1063,6 +1064,34 @@ impl<'m, 'v> Variant<'m, 'v> { _ => None, } } + + /// Return a new Variant with the path followed. + /// + /// If the path is not found, `None` is returned. + pub fn get_path(&self, path: &VariantPath) -> Option<Variant> { + let mut output = self.clone(); + for element in path.deref() { + match element { + VariantPathElement::Field { name } => { + let Variant::Object(variant_object) = output else { + return None; + }; + let field = variant_object.get(name); + let field = field?; + output = field; + } + VariantPathElement::Index { index } => { + let Variant::List(variant_list) = output else { + return None; + }; + let index = variant_list.get(*index); + let index = index?; + output = index; + } + } Review Comment: That is so much cleaner. Thanks! -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org