jecsand838 commented on code in PR #8274: URL: https://github.com/apache/arrow-rs/pull/8274#discussion_r2322688001
########## arrow-avro/src/writer/encoder.rs: ########## @@ -84,48 +85,211 @@ fn write_bool<W: Write + ?Sized>(writer: &mut W, v: bool) -> Result<(), ArrowErr /// - Null-first (default): null => 0, value => 1 /// - Null-second (Impala): value => 0, null => 1 #[inline] -fn write_optional_branch<W: Write + ?Sized>( +fn write_optional_index<W: Write + ?Sized>( writer: &mut W, is_null: bool, - impala_mode: bool, + order: Nullability, ) -> Result<(), ArrowError> { - let branch = if impala_mode == is_null { 1 } else { 0 }; - write_int(writer, branch) + // For NullFirst: null => 0x00, value => 0x02 + // For NullSecond: value => 0x00, null => 0x02 + let byte = match order { + Nullability::NullFirst => { + if is_null { + 0x00 + } else { + 0x02 + } + } + Nullability::NullSecond => { + if is_null { + 0x02 + } else { + 0x00 + } + } Review Comment: I like that third approach. Also @nathaniel-d-ef recommended adding a constant for `0x00` and `0x02` to improve readability. -- 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