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


##########
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
+            }
+        }
+    };
+    writer
+        .write_all(&[byte])
+        .map_err(|e| ArrowError::IoError(format!("write union branch: {e}"), 
e))
 }
 
-/// Encode a `RecordBatch` in Avro binary format using **default options**.
-pub fn encode_record_batch<W: Write>(batch: &RecordBatch, out: &mut W) -> 
Result<(), ArrowError> {
-    encode_record_batch_with_options(batch, out, &EncoderOptions::default())
+/// Per‑site encoder plan for a field. This mirrors Avro structure so nested
+/// optional branch order can be honored exactly as declared by the schema.
+#[derive(Debug, Clone)]
+enum FieldPlan {

Review Comment:
   @scovich I have additional plans for maps, enums, decimals, etc on another 
branch. I just removed them from this PR to reduce the size.



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