You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@paimon.apache.org by ho...@apache.org on 2026/05/25 11:41:52 UTC

(paimon-mosaic) branch release-0.1 updated: Fix BPE non-determinism and add comprehensive test suite (#45)

This is an automated email from the ASF dual-hosted git repository.

XiaoHongbo-Hope pushed a commit to branch release-0.1
in repository https://gitbox.apache.org/repos/asf/paimon-mosaic.git


The following commit(s) were added to refs/heads/release-0.1 by this push:
     new 042b62a  Fix BPE non-determinism and add comprehensive test suite (#45)
042b62a is described below

commit 042b62a2d06d9b1f9c14a82050230a9832233462
Author: Jingsong Lee <ji...@gmail.com>
AuthorDate: Mon May 25 14:05:12 2026 +0800

    Fix BPE non-determinism and add comprehensive test suite (#45)
    
    Fix a non-determinism bug in BPE vocabulary builder where HashMap
    iteration order caused different byte output for identical input data
    when column names share common substrings. The fix uses the pair key
    as a deterministic tie-breaker when multiple pairs have equal frequency.
    
    Add 150+ new tests across Rust, Java, and Python covering:
    - Massive data volumes (up to 10M rows, 1000 columns)
    - 20 data pattern varieties (sawtooth, fibonacci, unicode, sparse, etc.)
    - Encoding/compression/projection interactions (30 tests)
    - Determinism and re-roundtrip stability (18 tests)
    - Concurrent multi-threaded reading (5 tests)
    - Binary format byte-level verification (10 tests)
    - Statistics min/max/null_count accuracy (11 tests)
    - Cross-language Rust/Java/Python interoperability (25 tests)
---
 .github/workflows/ci.yml                           |   16 +-
 core/src/bpe.rs                                    |    2 +-
 core/tests/data_patterns_test.rs                   | 1076 ++++++++
 core/tests/determinism_test.rs                     | 1844 ++++++++++++++
 core/tests/encoding_compression_test.rs            | 2678 ++++++++++++++++++++
 core/tests/format_verification_test.rs             | 1547 +++++++++++
 core/tests/interop_read_test.rs                    |  223 ++
 core/tests/interop_write_test.rs                   |  610 +++++
 core/tests/massive_data_test.rs                    | 1164 +++++++++
 .../paimon/mosaic/MosaicComprehensiveTest.java     |  737 ++++++
 .../apache/paimon/mosaic/MosaicInteropTest.java    |  517 ++++
 python/tests/test_comprehensive.py                 |  401 +++
 python/tests/test_interop.py                       |  402 +++
 13 files changed, 11214 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index c75da17..d8db4ed 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -57,7 +57,7 @@ jobs:
       - name: Clippy
         run: cargo clippy --all-targets --workspace -- -D warnings
 
-  build-and-test:
+  rust-test:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v6
@@ -77,7 +77,7 @@ jobs:
         run: cargo build --all-targets
 
       - name: Test
-        run: cargo test
+        run: cargo test -- --skip test_read_java_written_file --skip test_read_python_written_file
 
   cpp-test:
     runs-on: ubuntu-latest
@@ -143,10 +143,16 @@ jobs:
       - name: Build JNI library
         run: cargo build -p paimon-mosaic-jni --release
 
+      - name: Write interop files (Rust)
+        run: cargo test --release -p paimon-mosaic-core --test interop_write_test
+
       - name: Run Java tests
         working-directory: java
         run: mvn test "-DargLine=-Djava.library.path=${{ github.workspace }}/target/release"
 
+      - name: Read Java-written interop file (Rust)
+        run: cargo test --release -p paimon-mosaic-core --test interop_read_test test_read_java_written_file
+
   python-test:
     runs-on: ubuntu-latest
     steps:
@@ -171,6 +177,9 @@ jobs:
       - name: Build FFI library
         run: cargo build --release -p paimon-mosaic-ffi
 
+      - name: Write interop files (Rust)
+        run: cargo test --release -p paimon-mosaic-core --test interop_write_test
+
       - name: Install Python dependencies
         working-directory: python
         run: pip install pyarrow pytest
@@ -180,3 +189,6 @@ jobs:
         run: pytest -v
         env:
           MOSAIC_LIB_PATH: ${{ github.workspace }}/target/release
+
+      - name: Read Python-written interop file (Rust)
+        run: cargo test --release -p paimon-mosaic-core --test interop_read_test test_read_python_written_file
diff --git a/core/src/bpe.rs b/core/src/bpe.rs
index 5147311..d2d8be8 100644
--- a/core/src/bpe.rs
+++ b/core/src/bpe.rs
@@ -41,7 +41,7 @@ pub fn build_vocabulary(names: &[&[u8]]) -> Vec<[u8; 2]> {
             }
         }
 
-        let best = pair_counts.iter().max_by_key(|&(_, &v)| v);
+        let best = pair_counts.iter().max_by_key(|&(&k, &v)| (v, k));
         match best {
             Some((&pair, &count)) if count > 1 => {
                 let left = (pair >> 16) as u16;
diff --git a/core/tests/data_patterns_test.rs b/core/tests/data_patterns_test.rs
new file mode 100644
index 0000000..294ce41
--- /dev/null
+++ b/core/tests/data_patterns_test.rs
@@ -0,0 +1,1076 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Data pattern tests: exercises various shapes of data to stress encoding,
+//! compression, null handling, and roundtrip correctness in the Mosaic format.
+
+#![allow(
+    clippy::approx_constant,
+    clippy::unnecessary_cast,
+    clippy::cloned_ref_to_slice_refs,
+    clippy::needless_range_loop,
+    clippy::manual_is_multiple_of
+)]
+
+use std::io;
+use std::sync::Arc;
+
+use arrow_array::*;
+use arrow_schema::{DataType, Field, Schema, TimeUnit};
+use paimon_mosaic_core::reader::{InputFile, MosaicReader, ReaderAccess};
+use paimon_mosaic_core::writer::{MosaicWriter, OutputFile, WriterOptions};
+
+// ======================== Test Infrastructure ========================
+
+struct MemOutputFile {
+    pub buf: Vec<u8>,
+}
+
+impl MemOutputFile {
+    fn new() -> Self {
+        Self { buf: Vec::new() }
+    }
+}
+
+impl OutputFile for MemOutputFile {
+    fn write(&mut self, data: &[u8]) -> io::Result<()> {
+        self.buf.extend_from_slice(data);
+        Ok(())
+    }
+    fn flush(&mut self) -> io::Result<()> {
+        Ok(())
+    }
+    fn pos(&self) -> u64 {
+        self.buf.len() as u64
+    }
+}
+
+struct ByteArrayInputFile {
+    data: Vec<u8>,
+}
+
+impl InputFile for ByteArrayInputFile {
+    fn read_at(&self, offset: u64, buf: &mut [u8]) -> io::Result<()> {
+        let start = offset as usize;
+        let end = start + buf.len();
+        if end > self.data.len() {
+            return Err(io::Error::new(
+                io::ErrorKind::UnexpectedEof,
+                "read past end",
+            ));
+        }
+        buf.copy_from_slice(&self.data[start..end]);
+        Ok(())
+    }
+}
+
+fn simple_hash(seed: u64, i: usize) -> u64 {
+    let mut x = seed.wrapping_add(i as u64);
+    x ^= x >> 33;
+    x = x.wrapping_mul(0xff51afd7ed558ccd);
+    x ^= x >> 33;
+    x = x.wrapping_mul(0xc4ceb9fe1a85ec53);
+    x ^= x >> 33;
+    x
+}
+
+fn roundtrip(schema: &Schema, batches: &[RecordBatch], options: WriterOptions) -> Vec<RecordBatch> {
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(out, schema, options).unwrap();
+    for batch in batches {
+        writer.write_batch(batch).unwrap();
+    }
+    writer.close().unwrap();
+
+    let data = writer.output().buf.clone();
+    let file_len = data.len() as u64;
+    let input = ByteArrayInputFile { data };
+    let reader = MosaicReader::new(input, file_len).unwrap();
+
+    let mut result = Vec::new();
+    for rg in 0..reader.num_row_groups() {
+        let mut rg_reader = reader.row_group_reader(rg).unwrap();
+        result.push(rg_reader.read_columns().unwrap());
+    }
+    result
+}
+
+fn assert_batches_equal(expected: &[RecordBatch], actual: &[RecordBatch]) {
+    let expected_rows: usize = expected.iter().map(|b| b.num_rows()).sum();
+    let actual_rows: usize = actual.iter().map(|b| b.num_rows()).sum();
+    assert_eq!(expected_rows, actual_rows, "total row count mismatch");
+
+    let mut exp_offset = 0;
+    let mut act_offset = 0;
+    let mut exp_batch_idx = 0;
+    let mut act_batch_idx = 0;
+
+    let num_cols = expected[0].num_columns();
+    let exp_schema = expected[0].schema();
+    let mut row = 0;
+    while row < expected_rows {
+        let exp_batch = &expected[exp_batch_idx];
+        let act_batch = &actual[act_batch_idx];
+        let exp_remaining = exp_batch.num_rows() - exp_offset;
+        let act_remaining = act_batch.num_rows() - act_offset;
+        let chunk = exp_remaining.min(act_remaining);
+
+        for col in 0..num_cols {
+            let col_name = exp_schema.field(col).name();
+            let act_col_idx = act_batch.schema().index_of(col_name).unwrap();
+            let exp_col = exp_batch.column(col).slice(exp_offset, chunk);
+            let act_col = act_batch.column(act_col_idx).slice(act_offset, chunk);
+            assert_eq!(
+                &exp_col,
+                &act_col,
+                "mismatch at column '{}' rows {}..{}",
+                col_name,
+                row,
+                row + chunk
+            );
+        }
+
+        exp_offset += chunk;
+        act_offset += chunk;
+        row += chunk;
+        if exp_offset == exp_batch.num_rows() {
+            exp_batch_idx += 1;
+            exp_offset = 0;
+        }
+        if act_offset == act_batch.num_rows() {
+            act_batch_idx += 1;
+            act_offset = 0;
+        }
+    }
+}
+
+// ======================== 1. Sawtooth Pattern ========================
+
+#[test]
+fn test_sawtooth_pattern() {
+    let num_rows = 500_000;
+    let schema = Schema::new(vec![Field::new("v", DataType::Int32, false)]);
+
+    let vals: Vec<i32> = (0..num_rows).map(|i| (i % 100) as i32).collect();
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int32Array::from(vals))],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!("test_sawtooth_pattern: PASSED ({} rows)", num_rows);
+}
+
+// ======================== 2. Fibonacci-like Values ========================
+
+#[test]
+fn test_fibonacci_like_values() {
+    let num_rows = 100_000;
+    let modulus: i64 = 1_000_000_000;
+    let schema = Schema::new(vec![Field::new("fib", DataType::Int64, false)]);
+
+    let mut fib_vals: Vec<i64> = Vec::with_capacity(num_rows);
+    if num_rows > 0 {
+        fib_vals.push(0);
+    }
+    if num_rows > 1 {
+        fib_vals.push(1);
+    }
+    for i in 2..num_rows {
+        let next = (fib_vals[i - 1] + fib_vals[i - 2]) % modulus;
+        fib_vals.push(next);
+    }
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int64Array::from(fib_vals))],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!("test_fibonacci_like_values: PASSED ({} rows)", num_rows);
+}
+
+// ======================== 3. String Length Distribution ========================
+
+#[test]
+fn test_string_length_distribution() {
+    let num_rows = 200_000;
+    let schema = Schema::new(vec![Field::new("s", DataType::Utf8, false)]);
+
+    let str_vals: Vec<String> = (0..num_rows)
+        .map(|i| {
+            let h = simple_hash(77, i);
+            let pct = h % 100;
+            let len = if pct < 50 {
+                // 50%: 1-10 chars
+                (simple_hash(78, i) % 10 + 1) as usize
+            } else if pct < 80 {
+                // 30%: 10-100 chars
+                (simple_hash(79, i) % 91 + 10) as usize
+            } else if pct < 95 {
+                // 15%: 100-1000 chars
+                (simple_hash(80, i) % 901 + 100) as usize
+            } else {
+                // 5%: 1000-5000 chars
+                (simple_hash(81, i) % 4001 + 1000) as usize
+            };
+            (0..len)
+                .map(|j| (b'a' + (simple_hash(82, i * 5000 + j) % 26) as u8) as char)
+                .collect()
+        })
+        .collect();
+
+    let str_refs: Vec<&str> = str_vals.iter().map(|s| s.as_str()).collect();
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(StringArray::from(str_refs))],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 64 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!(
+        "test_string_length_distribution: PASSED ({} rows)",
+        num_rows
+    );
+}
+
+// ======================== 4. Correlated Null Columns ========================
+
+#[test]
+fn test_correlated_null_columns() {
+    let num_rows = 500_000;
+    let schema = Schema::new(vec![
+        Field::new("col_a", DataType::Int32, true),
+        Field::new("col_b", DataType::Int64, true),
+        Field::new("col_c", DataType::Float64, true),
+    ]);
+
+    let a_vals: Vec<Option<i32>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(10, i) % 5 == 0 {
+                None
+            } else {
+                Some(i as i32)
+            }
+        })
+        .collect();
+
+    // When col_a is null, col_b is always null too
+    let b_vals: Vec<Option<i64>> = (0..num_rows)
+        .map(|i| {
+            if a_vals[i].is_none() || simple_hash(20, i) % 7 == 0 {
+                None
+            } else {
+                Some(i as i64 * 100)
+            }
+        })
+        .collect();
+
+    // col_c is independently nullable
+    let c_vals: Vec<Option<f64>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(30, i) % 4 == 0 {
+                None
+            } else {
+                Some(i as f64 * 0.5)
+            }
+        })
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int32Array::from(a_vals)),
+            Arc::new(Int64Array::from(b_vals)),
+            Arc::new(Float64Array::from(c_vals)),
+        ],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 3,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!("test_correlated_null_columns: PASSED ({} rows)", num_rows);
+}
+
+// ======================== 5. All Extremes Int ========================
+
+#[test]
+fn test_all_extremes_int() {
+    let num_rows = 200_000;
+    let schema = Schema::new(vec![Field::new("v", DataType::Int32, false)]);
+
+    let vals: Vec<i32> = (0..num_rows)
+        .map(|i| {
+            match simple_hash(50, i) % 6 {
+                0 => i32::MIN,
+                1 => i32::MAX,
+                2 => 0,
+                3 => -1,
+                4 => 1,
+                _ => simple_hash(51, i) as i32, // random
+            }
+        })
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int32Array::from(vals))],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!("test_all_extremes_int: PASSED ({} rows)", num_rows);
+}
+
+// ======================== 6. Unicode Strings ========================
+
+#[test]
+fn test_unicode_strings() {
+    let num_rows = 100_000;
+    let schema = Schema::new(vec![Field::new("text", DataType::Utf8, false)]);
+
+    let unicode_fragments: &[&str] = &[
+        "\u{4e2d}\u{6587}\u{6d4b}\u{8bd5}",                 // Chinese
+        "\u{65e5}\u{672c}\u{8a9e}\u{30c6}\u{30b9}\u{30c8}", // Japanese
+        "\u{d55c}\u{ad6d}\u{c5b4}\u{d14c}\u{c2a4}\u{d2b8}", // Korean
+        "\u{0627}\u{0644}\u{0639}\u{0631}\u{0628}\u{064a}\u{0629}", // Arabic
+        "\u{1f600}\u{1f60d}\u{1f680}\u{1f4a5}\u{2764}\u{fe0f}", // Emoji
+        "Hello\u{4e16}\u{754c}\u{d558}\u{c138}\u{c694}",    // Mixed scripts
+        "\u{00e9}\u{00e8}\u{00ea}\u{00eb}\u{00fc}\u{00f6}", // European accents
+        "\u{0410}\u{0411}\u{0412}\u{0413}\u{0414}",         // Cyrillic
+        "\u{0e01}\u{0e02}\u{0e03}\u{0e04}\u{0e05}",         // Thai
+        "\u{05d0}\u{05d1}\u{05d2}\u{05d3}\u{05d4}",         // Hebrew
+    ];
+
+    let str_vals: Vec<String> = (0..num_rows)
+        .map(|i| {
+            let idx = simple_hash(60, i) as usize % unicode_fragments.len();
+            let repeat = (simple_hash(61, i) % 5 + 1) as usize;
+            let base = unicode_fragments[idx];
+            let mut s = String::new();
+            for _ in 0..repeat {
+                s.push_str(base);
+            }
+            // Add some unique suffix to vary cardinality
+            s.push_str(&format!("_{}", i));
+            s
+        })
+        .collect();
+
+    let str_refs: Vec<&str> = str_vals.iter().map(|s| s.as_str()).collect();
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(StringArray::from(str_refs))],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 32 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!("test_unicode_strings: PASSED ({} rows)", num_rows);
+}
+
+// ======================== 7. Zigzag Int Pattern ========================
+
+#[test]
+fn test_zigzag_int_pattern() {
+    let num_rows = 500_000;
+    let schema = Schema::new(vec![Field::new("v", DataType::Int32, false)]);
+
+    // 1,-1,2,-2,3,-3,...
+    let vals: Vec<i32> = (0..num_rows)
+        .map(|i| {
+            let n = (i / 2 + 1) as i32;
+            if i % 2 == 0 {
+                n
+            } else {
+                -n
+            }
+        })
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int32Array::from(vals))],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!("test_zigzag_int_pattern: PASSED ({} rows)", num_rows);
+}
+
+// ======================== 8. Power of Two Values ========================
+
+#[test]
+fn test_power_of_two_values() {
+    let num_rows = 500_000;
+    let schema = Schema::new(vec![Field::new("v", DataType::Int64, false)]);
+
+    // Powers of 2: 1, 2, 4, 8, ..., 2^62, then cycle
+    let num_powers = 63; // 2^0 through 2^62
+    let vals: Vec<i64> = (0..num_rows).map(|i| 1i64 << (i % num_powers)).collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int64Array::from(vals))],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!("test_power_of_two_values: PASSED ({} rows)", num_rows);
+}
+
+// ======================== 9. Sparse Data (99% null) ========================
+
+#[test]
+fn test_sparse_data() {
+    let num_rows = 1_000_000;
+    let schema = Schema::new(vec![
+        Field::new("int_col", DataType::Int64, true),
+        Field::new("str_col", DataType::Utf8, true),
+        Field::new("bin_col", DataType::Binary, true),
+    ]);
+
+    let int_vals: Vec<Option<i64>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(90, i) % 100 == 0 {
+                Some(i as i64)
+            } else {
+                None
+            }
+        })
+        .collect();
+
+    let str_owned: Vec<Option<String>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(91, i) % 100 == 0 {
+                Some(format!("sparse_{}", i))
+            } else {
+                None
+            }
+        })
+        .collect();
+    let str_refs: Vec<Option<&str>> = str_owned.iter().map(|s| s.as_deref()).collect();
+
+    let bin_owned: Vec<Option<Vec<u8>>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(92, i) % 100 == 0 {
+                Some(vec![(i % 256) as u8; 10])
+            } else {
+                None
+            }
+        })
+        .collect();
+    let bin_refs: Vec<Option<&[u8]>> = bin_owned
+        .iter()
+        .map(|b| b.as_ref().map(|v| v.as_slice()))
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int64Array::from(int_vals)),
+            Arc::new(StringArray::from(str_refs)),
+            Arc::new(BinaryArray::from(bin_refs)),
+        ],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 3,
+            row_group_max_size: 32 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!("test_sparse_data: PASSED ({} rows)", num_rows);
+}
+
+// ======================== 10. Dense Data No Nulls ========================
+
+#[test]
+fn test_dense_data_no_nulls() {
+    let num_rows = 500_000;
+    let schema = Schema::new(vec![
+        Field::new("bool_col", DataType::Boolean, false),
+        Field::new("i8_col", DataType::Int8, false),
+        Field::new("i16_col", DataType::Int16, false),
+        Field::new("i32_col", DataType::Int32, false),
+        Field::new("i64_col", DataType::Int64, false),
+        Field::new("f32_col", DataType::Float32, false),
+        Field::new("f64_col", DataType::Float64, false),
+        Field::new("str_col", DataType::Utf8, false),
+        Field::new("bin_col", DataType::Binary, false),
+        Field::new("date_col", DataType::Date32, false),
+        Field::new("time_col", DataType::Time32(TimeUnit::Millisecond), false),
+        Field::new("dec_col", DataType::Decimal128(10, 2), false),
+        Field::new(
+            "ts_col",
+            DataType::Timestamp(TimeUnit::Millisecond, None),
+            false,
+        ),
+    ]);
+
+    let bools: Vec<bool> = (0..num_rows).map(|i| i % 2 == 0).collect();
+    let i8s: Vec<i8> = (0..num_rows).map(|i| (i % 256) as i8).collect();
+    let i16s: Vec<i16> = (0..num_rows).map(|i| (i % 30000) as i16).collect();
+    let i32s: Vec<i32> = (0..num_rows).map(|i| i as i32).collect();
+    let i64s: Vec<i64> = (0..num_rows).map(|i| i as i64 * 1000).collect();
+    let f32s: Vec<f32> = (0..num_rows).map(|i| i as f32 * 0.1).collect();
+    let f64s: Vec<f64> = (0..num_rows).map(|i| i as f64 * 0.001).collect();
+    let str_vals: Vec<String> = (0..num_rows).map(|i| format!("row_{:06}", i)).collect();
+    let str_refs: Vec<&str> = str_vals.iter().map(|s| s.as_str()).collect();
+    let bin_vals: Vec<Vec<u8>> = (0..num_rows).map(|i| vec![(i % 256) as u8; 8]).collect();
+    let bin_refs: Vec<&[u8]> = bin_vals.iter().map(|v| v.as_slice()).collect();
+    let dates: Vec<i32> = (0..num_rows).map(|i| 18000 + (i % 3650) as i32).collect();
+    let times: Vec<i32> = (0..num_rows)
+        .map(|i| (i as i32 % 86_400_000).abs())
+        .collect();
+    let decimals: Vec<i128> = (0..num_rows).map(|i| i as i128 * 100).collect();
+    let timestamps: Vec<i64> = (0..num_rows)
+        .map(|i| 1_700_000_000_000i64 + i as i64)
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(BooleanArray::from(bools)),
+            Arc::new(Int8Array::from(i8s)),
+            Arc::new(Int16Array::from(i16s)),
+            Arc::new(Int32Array::from(i32s)),
+            Arc::new(Int64Array::from(i64s)),
+            Arc::new(Float32Array::from(f32s)),
+            Arc::new(Float64Array::from(f64s)),
+            Arc::new(StringArray::from(str_refs)),
+            Arc::new(BinaryArray::from(bin_refs)),
+            Arc::new(Date32Array::from(dates)),
+            Arc::new(Time32MillisecondArray::from(times)),
+            Arc::new(
+                Decimal128Array::from(decimals)
+                    .with_precision_and_scale(10, 2)
+                    .unwrap(),
+            ),
+            Arc::new(TimestampMillisecondArray::from(timestamps)),
+        ],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 10,
+            row_group_max_size: 32 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!("test_dense_data_no_nulls: PASSED ({} rows)", num_rows);
+}
+
+// ======================== 11. Binary All Zeros ========================
+
+#[test]
+fn test_binary_all_zeros() {
+    let num_rows = 100_000;
+    let schema = Schema::new(vec![Field::new("data", DataType::Binary, false)]);
+
+    let bin_vals: Vec<Vec<u8>> = (0..num_rows)
+        .map(|i| {
+            let len = (simple_hash(100, i) % 64 + 1) as usize;
+            vec![0u8; len]
+        })
+        .collect();
+    let bin_refs: Vec<&[u8]> = bin_vals.iter().map(|v| v.as_slice()).collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(BinaryArray::from(bin_refs))],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!("test_binary_all_zeros: PASSED ({} rows)", num_rows);
+}
+
+// ======================== 12. Binary All 0xFF ========================
+
+#[test]
+fn test_binary_all_0xff() {
+    let num_rows = 100_000;
+    let schema = Schema::new(vec![Field::new("data", DataType::Binary, false)]);
+
+    let bin_vals: Vec<Vec<u8>> = (0..num_rows)
+        .map(|i| {
+            let len = (simple_hash(110, i) % 64 + 1) as usize;
+            vec![0xFFu8; len]
+        })
+        .collect();
+    let bin_refs: Vec<&[u8]> = bin_vals.iter().map(|v| v.as_slice()).collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(BinaryArray::from(bin_refs))],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!("test_binary_all_0xff: PASSED ({} rows)", num_rows);
+}
+
+// ======================== 13. String With Special Chars ========================
+
+#[test]
+fn test_string_with_special_chars() {
+    let num_rows = 100_000;
+    let schema = Schema::new(vec![Field::new("s", DataType::Utf8, false)]);
+
+    let special_chars = ['\0', '\n', '\r', '\t', '\\', '"', '\''];
+
+    let str_vals: Vec<String> = (0..num_rows)
+        .map(|i| {
+            let len = (simple_hash(120, i) % 50 + 1) as usize;
+            (0..len)
+                .map(|j| {
+                    let h = simple_hash(121, i * 50 + j);
+                    if h % 5 == 0 {
+                        special_chars[(h as usize / 5) % special_chars.len()]
+                    } else {
+                        (b'a' + (h % 26) as u8) as char
+                    }
+                })
+                .collect()
+        })
+        .collect();
+
+    let str_refs: Vec<&str> = str_vals.iter().map(|s| s.as_str()).collect();
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(StringArray::from(str_refs))],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!("test_string_with_special_chars: PASSED ({} rows)", num_rows);
+}
+
+// ======================== 14. Decimal Near Overflow ========================
+
+#[test]
+fn test_decimal_near_overflow() {
+    let num_rows = 50_000;
+    let schema = Schema::new(vec![Field::new("dec", DataType::Decimal128(38, 0), true)]);
+
+    let max_decimal38: i128 = 99_999_999_999_999_999_999_999_999_999_999_999_999;
+
+    let vals: Vec<Option<i128>> = (0..num_rows)
+        .map(|i| match simple_hash(130, i) % 7 {
+            0 => None,
+            1 => Some(max_decimal38),
+            2 => Some(-max_decimal38),
+            3 => Some(max_decimal38 - i as i128),
+            4 => Some(-max_decimal38 + i as i128),
+            5 => Some(0),
+            _ => Some((simple_hash(131, i) as i128) * 1_000_000_000_000_000_000),
+        })
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(
+            Decimal128Array::from(vals)
+                .with_precision_and_scale(38, 0)
+                .unwrap(),
+        )],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!("test_decimal_near_overflow: PASSED ({} rows)", num_rows);
+}
+
+// ======================== 15. Timestamp Boundaries ========================
+
+#[test]
+fn test_timestamp_boundaries() {
+    let num_rows = 100_000;
+    let schema = Schema::new(vec![Field::new(
+        "ts",
+        DataType::Timestamp(TimeUnit::Millisecond, None),
+        true,
+    )]);
+
+    let epoch_0: i64 = 0;
+    let year_1970: i64 = 0; // same as epoch 0
+    let year_2000: i64 = 946_684_800_000;
+    let year_2038: i64 = 2_145_916_800_000; // Unix Y2038
+    let year_9999: i64 = 253_402_300_799_000;
+
+    let boundary_vals = [epoch_0, year_1970, year_2000, year_2038, year_9999];
+
+    let vals: Vec<Option<i64>> = (0..num_rows)
+        .map(|i| {
+            let h = simple_hash(140, i);
+            if h % 10 == 0 {
+                None
+            } else if h % 3 == 0 {
+                Some(boundary_vals[(h as usize) % boundary_vals.len()])
+            } else {
+                // Random timestamp between year 2000 and year 2038
+                Some(year_2000 + (h as i64 % (year_2038 - year_2000)))
+            }
+        })
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(TimestampMillisecondArray::from(vals))],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!("test_timestamp_boundaries: PASSED ({} rows)", num_rows);
+}
+
+// ======================== 16. Monotonic Then Random ========================
+
+#[test]
+fn test_monotonic_then_random() {
+    let half = 100_000;
+    let num_rows = half * 2;
+    let schema = Schema::new(vec![Field::new("v", DataType::Int64, false)]);
+
+    // First 100K: monotonically increasing
+    let mut vals: Vec<i64> = (0..half as i64).collect();
+    // Next 100K: random
+    for i in 0..half {
+        vals.push(simple_hash(150, i) as i64);
+    }
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int64Array::from(vals))],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 512 * 1024, // small row groups to force encoding transitions
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!("test_monotonic_then_random: PASSED ({} rows)", num_rows);
+}
+
+// ======================== 17. Single Value Then Varied ========================
+
+#[test]
+fn test_single_value_then_varied() {
+    let half = 250_000;
+    let num_rows = half * 2;
+    let schema = Schema::new(vec![Field::new("v", DataType::Int32, false)]);
+
+    // First 250K: all value 42
+    let mut vals: Vec<i32> = vec![42i32; half];
+    // Next 250K: all different values
+    for i in 0..half {
+        vals.push(i as i32);
+    }
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int32Array::from(vals))],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 512 * 1024, // small to force transitions
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!("test_single_value_then_varied: PASSED ({} rows)", num_rows);
+}
+
+// ======================== 18. Run-Length Encoding Friendly ========================
+
+#[test]
+fn test_run_length_encoding_friendly() {
+    let num_rows = 500_000;
+    let run_length = 1000;
+    let schema = Schema::new(vec![Field::new("v", DataType::Int32, false)]);
+
+    let vals: Vec<i32> = (0..num_rows).map(|i| (i / run_length) as i32).collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int32Array::from(vals))],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!(
+        "test_run_length_encoding_friendly: PASSED ({} rows)",
+        num_rows
+    );
+}
+
+// ======================== 19. High Cardinality Strings ========================
+
+#[test]
+fn test_high_cardinality_strings() {
+    let num_rows = 200_000;
+    let schema = Schema::new(vec![Field::new("uuid", DataType::Utf8, false)]);
+
+    // Generate UUID-like strings: every string is unique
+    let str_vals: Vec<String> = (0..num_rows)
+        .map(|i| {
+            let a = simple_hash(200, i);
+            let b = simple_hash(201, i);
+            let c = simple_hash(202, i);
+            let d = simple_hash(203, i);
+            format!(
+                "{:08x}-{:04x}-{:04x}-{:04x}-{:012x}",
+                (a & 0xFFFFFFFF) as u32,
+                (b & 0xFFFF) as u16,
+                (c & 0xFFFF) as u16,
+                (d & 0xFFFF) as u16,
+                a ^ b ^ c ^ d
+            )
+        })
+        .collect();
+
+    let str_refs: Vec<&str> = str_vals.iter().map(|s| s.as_str()).collect();
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(StringArray::from(str_refs))],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 32 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!("test_high_cardinality_strings: PASSED ({} rows)", num_rows);
+}
+
+// ======================== 20. Low Cardinality With Skew ========================
+
+#[test]
+fn test_low_cardinality_with_skew() {
+    let num_rows = 500_000;
+    let schema = Schema::new(vec![Field::new("category", DataType::Utf8, false)]);
+
+    // 5 distinct values with heavy skew:
+    // 90% "A", 5% "B", 3% "C", 1.5% "D", 0.5% "E"
+    let str_vals: Vec<&str> = (0..num_rows)
+        .map(|i| {
+            let h = simple_hash(210, i) % 1000;
+            if h < 900 {
+                "A"
+            } else if h < 950 {
+                "B"
+            } else if h < 980 {
+                "C"
+            } else if h < 995 {
+                "D"
+            } else {
+                "E"
+            }
+        })
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(StringArray::from(str_vals))],
+    )
+    .unwrap();
+
+    let result = roundtrip(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    assert_batches_equal(&[batch], &result);
+    println!("test_low_cardinality_with_skew: PASSED ({} rows)", num_rows);
+}
diff --git a/core/tests/determinism_test.rs b/core/tests/determinism_test.rs
new file mode 100644
index 0000000..8afc57f
--- /dev/null
+++ b/core/tests/determinism_test.rs
@@ -0,0 +1,1844 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Determinism, idempotency, and re-roundtrip tests for the Mosaic file format.
+//!
+//! These tests verify critical properties for format stability:
+//! - Same input data with same options produces byte-identical output (determinism).
+//! - write -> read -> write -> read cycles produce stable bytes and data (re-roundtrip).
+//! - File metadata (size, footer offsets) is consistent across identical writes.
+
+#![allow(
+    clippy::approx_constant,
+    clippy::unnecessary_cast,
+    clippy::cloned_ref_to_slice_refs,
+    clippy::needless_range_loop,
+    clippy::manual_is_multiple_of
+)]
+
+use std::io;
+use std::sync::Arc;
+
+use arrow_array::*;
+use arrow_schema::{DataType, Field, Schema, TimeUnit};
+use paimon_mosaic_core::reader::{InputFile, MosaicReader, ReaderAccess};
+use paimon_mosaic_core::spec;
+use paimon_mosaic_core::writer::{MosaicWriter, OutputFile, WriterOptions};
+
+// ======================== Test Infrastructure ========================
+
+struct MemOutputFile {
+    pub buf: Vec<u8>,
+}
+
+impl MemOutputFile {
+    fn new() -> Self {
+        Self { buf: Vec::new() }
+    }
+}
+
+impl OutputFile for MemOutputFile {
+    fn write(&mut self, data: &[u8]) -> io::Result<()> {
+        self.buf.extend_from_slice(data);
+        Ok(())
+    }
+    fn flush(&mut self) -> io::Result<()> {
+        Ok(())
+    }
+    fn pos(&self) -> u64 {
+        self.buf.len() as u64
+    }
+}
+
+struct ByteArrayInputFile {
+    data: Vec<u8>,
+}
+
+impl InputFile for ByteArrayInputFile {
+    fn read_at(&self, offset: u64, buf: &mut [u8]) -> io::Result<()> {
+        let start = offset as usize;
+        let end = start + buf.len();
+        if end > self.data.len() {
+            return Err(io::Error::new(
+                io::ErrorKind::UnexpectedEof,
+                "read past end",
+            ));
+        }
+        buf.copy_from_slice(&self.data[start..end]);
+        Ok(())
+    }
+}
+
+fn simple_hash(seed: u64, i: usize) -> u64 {
+    let mut x = seed.wrapping_add(i as u64);
+    x ^= x >> 33;
+    x = x.wrapping_mul(0xff51afd7ed558ccd);
+    x ^= x >> 33;
+    x = x.wrapping_mul(0xc4ceb9fe1a85ec53);
+    x ^= x >> 33;
+    x
+}
+
+fn write_file(schema: &Schema, batches: &[RecordBatch], options: WriterOptions) -> Vec<u8> {
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(out, schema, options).unwrap();
+    for batch in batches {
+        writer.write_batch(batch).unwrap();
+    }
+    writer.close().unwrap();
+    writer.output().buf.clone()
+}
+
+fn read_all(data: &[u8]) -> Vec<RecordBatch> {
+    let input = ByteArrayInputFile {
+        data: data.to_vec(),
+    };
+    let reader = MosaicReader::new(input, data.len() as u64).unwrap();
+    let mut result = Vec::new();
+    for rg in 0..reader.num_row_groups() {
+        let mut rg_reader = reader.row_group_reader(rg).unwrap();
+        result.push(rg_reader.read_columns().unwrap());
+    }
+    result
+}
+
+fn read_projected(data: &[u8], columns: &[usize]) -> Vec<RecordBatch> {
+    let input = ByteArrayInputFile {
+        data: data.to_vec(),
+    };
+    let reader = MosaicReader::new(input, data.len() as u64).unwrap();
+    let mut result = Vec::new();
+    for rg in 0..reader.num_row_groups() {
+        let mut rg_reader = reader.row_group_reader_projected(rg, columns).unwrap();
+        result.push(rg_reader.read_columns().unwrap());
+    }
+    result
+}
+
+fn make_default_options() -> WriterOptions {
+    WriterOptions::default()
+}
+
+/// Compare two sets of batches for logical equality, handling column reordering.
+/// Columns are matched by name. Both sides must have the same total row count
+/// and identical column data when concatenated.
+fn batches_equal_unordered(a: &[RecordBatch], b: &[RecordBatch]) -> bool {
+    let rows_a: usize = a.iter().map(|b| b.num_rows()).sum();
+    let rows_b: usize = b.iter().map(|b| b.num_rows()).sum();
+    if rows_a != rows_b {
+        return false;
+    }
+    if rows_a == 0 {
+        return true;
+    }
+
+    // Get column names from the first batch of each side
+    let schema_a = a[0].schema();
+    let schema_b = b[0].schema();
+
+    // Every column in a must exist in b
+    for field_a in schema_a.fields() {
+        let col_name = field_a.name();
+        if schema_b.index_of(col_name).is_err() {
+            return false;
+        }
+    }
+
+    // Concatenate all arrays for each column from both sides, then compare
+    for field_a in schema_a.fields() {
+        let col_name = field_a.name();
+
+        // Collect column data from a
+        let mut arrays_a: Vec<ArrayRef> = Vec::new();
+        for batch in a {
+            let idx = batch.schema().index_of(col_name).unwrap();
+            arrays_a.push(batch.column(idx).clone());
+        }
+
+        // Collect column data from b
+        let mut arrays_b: Vec<ArrayRef> = Vec::new();
+        for batch in b {
+            let idx = batch.schema().index_of(col_name).unwrap();
+            arrays_b.push(batch.column(idx).clone());
+        }
+
+        // Compare element-by-element
+        let mut offset_a = 0usize;
+        let mut batch_idx_a = 0usize;
+        let mut offset_b = 0usize;
+        let mut batch_idx_b = 0usize;
+
+        let mut row = 0;
+        while row < rows_a {
+            let arr_a = &arrays_a[batch_idx_a];
+            let arr_b = &arrays_b[batch_idx_b];
+            let remaining_a = arr_a.len() - offset_a;
+            let remaining_b = arr_b.len() - offset_b;
+            let chunk = remaining_a.min(remaining_b);
+
+            let slice_a = arr_a.slice(offset_a, chunk);
+            let slice_b = arr_b.slice(offset_b, chunk);
+            if slice_a != slice_b {
+                return false;
+            }
+
+            offset_a += chunk;
+            offset_b += chunk;
+            row += chunk;
+
+            if offset_a == arr_a.len() {
+                batch_idx_a += 1;
+                offset_a = 0;
+            }
+            if offset_b == arr_b.len() {
+                batch_idx_b += 1;
+                offset_b = 0;
+            }
+        }
+    }
+
+    true
+}
+
+/// Write batches -> read -> write -> read -> write -> return stable cycle data.
+///
+/// Since the reader returns columns in sorted order, the first write (with original
+/// schema) may differ from subsequent writes (with sorted schema). We therefore
+/// compare cycle 2 vs cycle 3 for byte-level stability, and cycle 1 vs cycle 2
+/// for logical data equality.
+///
+/// Returns (cycle2_bytes, cycle3_bytes, cycle1_batches, cycle2_batches).
+fn reroundtrip(
+    schema: &Schema,
+    batches: &[RecordBatch],
+    options_fn: fn() -> WriterOptions,
+) -> (Vec<u8>, Vec<u8>, Vec<RecordBatch>, Vec<RecordBatch>) {
+    // Cycle 1: write with original schema
+    let data1 = write_file(schema, batches, options_fn());
+    let batches1 = read_all(&data1);
+    assert!(!batches1.is_empty(), "cycle 1 read produced no batches");
+
+    // Cycle 2: write with sorted schema (from reader)
+    let sorted_schema = batches1[0].schema();
+    let data2 = write_file(&sorted_schema, &batches1, options_fn());
+    let batches2 = read_all(&data2);
+
+    // Cycle 3: write again from cycle 2 read to verify stability
+    let sorted_schema2 = batches2[0].schema();
+    let data3 = write_file(&sorted_schema2, &batches2, options_fn());
+
+    (data2, data3, batches1, batches2)
+}
+
+// ======================== Determinism Tests ========================
+
+#[test]
+fn test_deterministic_int_output() {
+    let schema = Schema::new(vec![
+        Field::new("ax", DataType::Int32, false),
+        Field::new("by", DataType::Int64, false),
+    ]);
+
+    let num_rows = 100_000;
+    let i32_vals: Vec<i32> = (0..num_rows).map(|i| simple_hash(1, i) as i32).collect();
+    let i64_vals: Vec<i64> = (0..num_rows).map(|i| simple_hash(2, i) as i64).collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int32Array::from(i32_vals)),
+            Arc::new(Int64Array::from(i64_vals)),
+        ],
+    )
+    .unwrap();
+
+    let options = || WriterOptions::default();
+
+    let data1 = write_file(&schema, &[batch.clone()], options());
+    let data2 = write_file(&schema, &[batch.clone()], options());
+
+    assert_eq!(
+        data1.len(),
+        data2.len(),
+        "file sizes differ: {} vs {}",
+        data1.len(),
+        data2.len()
+    );
+    assert_eq!(
+        data1, data2,
+        "byte-level mismatch for deterministic int output"
+    );
+
+    println!(
+        "test_deterministic_int_output: PASSED - {} bytes, byte-identical",
+        data1.len()
+    );
+}
+
+#[test]
+fn test_deterministic_string_output() {
+    let schema = Schema::new(vec![
+        Field::new("cx", DataType::Utf8, true),
+        Field::new("dy", DataType::Binary, true),
+    ]);
+
+    let num_rows = 50_000;
+    let str_vals: Vec<Option<String>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(10, i) % 7 == 0 {
+                None
+            } else {
+                let len = (simple_hash(11, i) % 100) as usize + 1;
+                Some(
+                    (0..len)
+                        .map(|j| (b'a' + (simple_hash(12, i * 100 + j) % 26) as u8) as char)
+                        .collect(),
+                )
+            }
+        })
+        .collect();
+    let str_refs: Vec<Option<&str>> = str_vals.iter().map(|s| s.as_deref()).collect();
+
+    let bin_vals: Vec<Option<Vec<u8>>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(20, i) % 9 == 0 {
+                None
+            } else {
+                let len = (simple_hash(21, i) % 64) as usize + 1;
+                Some(
+                    (0..len)
+                        .map(|j| simple_hash(22, i * 64 + j) as u8)
+                        .collect(),
+                )
+            }
+        })
+        .collect();
+    let bin_refs: Vec<Option<&[u8]>> = bin_vals
+        .iter()
+        .map(|v| v.as_ref().map(|x| x.as_slice()))
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(StringArray::from(str_refs)),
+            Arc::new(BinaryArray::from(bin_refs)),
+        ],
+    )
+    .unwrap();
+
+    let options = || WriterOptions::default();
+
+    let data1 = write_file(&schema, &[batch.clone()], options());
+    let data2 = write_file(&schema, &[batch.clone()], options());
+
+    assert_eq!(data1.len(), data2.len(), "file sizes differ");
+    assert_eq!(
+        data1, data2,
+        "byte-level mismatch for deterministic string output"
+    );
+
+    println!(
+        "test_deterministic_string_output: PASSED - {} bytes, byte-identical",
+        data1.len()
+    );
+}
+
+#[test]
+fn test_deterministic_all_types() {
+    let schema = Schema::new(vec![
+        Field::new("a", DataType::Boolean, true),
+        Field::new("b", DataType::Int8, true),
+        Field::new("c", DataType::Int16, true),
+        Field::new("d", DataType::Int32, true),
+        Field::new("e", DataType::Int64, true),
+        Field::new("f", DataType::Float32, true),
+        Field::new("g", DataType::Float64, true),
+        Field::new("h", DataType::Date32, true),
+        Field::new("j", DataType::Time32(TimeUnit::Millisecond), true),
+        Field::new("k", DataType::Utf8, true),
+        Field::new("m", DataType::Binary, true),
+        Field::new("n", DataType::Decimal128(10, 2), true),
+        Field::new("p", DataType::Decimal128(38, 10), true),
+        Field::new("q", DataType::Timestamp(TimeUnit::Millisecond, None), true),
+        Field::new("r", DataType::Timestamp(TimeUnit::Microsecond, None), true),
+        Field::new("s", DataType::Timestamp(TimeUnit::Nanosecond, None), true),
+    ]);
+
+    let num_rows = 50_000;
+
+    let make_batch = || {
+        let bools: Vec<Option<bool>> = (0..num_rows)
+            .map(|i| {
+                if simple_hash(100, i) % 8 == 0 {
+                    None
+                } else {
+                    Some(simple_hash(101, i) % 2 == 0)
+                }
+            })
+            .collect();
+        let i8s: Vec<Option<i8>> = (0..num_rows)
+            .map(|i| {
+                if simple_hash(110, i) % 10 == 0 {
+                    None
+                } else {
+                    Some(simple_hash(111, i) as i8)
+                }
+            })
+            .collect();
+        let i16s: Vec<Option<i16>> = (0..num_rows)
+            .map(|i| {
+                if simple_hash(120, i) % 10 == 0 {
+                    None
+                } else {
+                    Some(simple_hash(121, i) as i16)
+                }
+            })
+            .collect();
+        let i32s: Vec<Option<i32>> = (0..num_rows)
+            .map(|i| {
+                if simple_hash(130, i) % 10 == 0 {
+                    None
+                } else {
+                    Some(simple_hash(131, i) as i32)
+                }
+            })
+            .collect();
+        let i64s: Vec<Option<i64>> = (0..num_rows)
+            .map(|i| {
+                if simple_hash(140, i) % 10 == 0 {
+                    None
+                } else {
+                    Some(simple_hash(141, i) as i64)
+                }
+            })
+            .collect();
+        let f32s: Vec<Option<f32>> = (0..num_rows)
+            .map(|i| {
+                if simple_hash(150, i) % 10 == 0 {
+                    None
+                } else {
+                    Some(simple_hash(151, i) as f32 / 1000.0)
+                }
+            })
+            .collect();
+        let f64s: Vec<Option<f64>> = (0..num_rows)
+            .map(|i| {
+                if simple_hash(160, i) % 10 == 0 {
+                    None
+                } else {
+                    Some(simple_hash(161, i) as f64 / 1000.0)
+                }
+            })
+            .collect();
+        let dates: Vec<Option<i32>> = (0..num_rows)
+            .map(|i| {
+                if simple_hash(170, i) % 10 == 0 {
+                    None
+                } else {
+                    Some((simple_hash(171, i) % 40000) as i32)
+                }
+            })
+            .collect();
+        let times: Vec<Option<i32>> = (0..num_rows)
+            .map(|i| {
+                if simple_hash(180, i) % 10 == 0 {
+                    None
+                } else {
+                    Some((simple_hash(181, i) % 86_400_000) as i32)
+                }
+            })
+            .collect();
+        let strings: Vec<Option<String>> = (0..num_rows)
+            .map(|i| {
+                if simple_hash(190, i) % 8 == 0 {
+                    None
+                } else {
+                    let len = (simple_hash(191, i) % 30) as usize + 1;
+                    Some(
+                        (0..len)
+                            .map(|j| (b'a' + (simple_hash(192, i * 30 + j) % 26) as u8) as char)
+                            .collect(),
+                    )
+                }
+            })
+            .collect();
+        let str_refs: Vec<Option<&str>> = strings.iter().map(|s| s.as_deref()).collect();
+        let bins: Vec<Option<Vec<u8>>> = (0..num_rows)
+            .map(|i| {
+                if simple_hash(200, i) % 8 == 0 {
+                    None
+                } else {
+                    let len = (simple_hash(201, i) % 32) as usize + 1;
+                    Some(
+                        (0..len)
+                            .map(|j| simple_hash(202, i * 32 + j) as u8)
+                            .collect(),
+                    )
+                }
+            })
+            .collect();
+        let bin_refs: Vec<Option<&[u8]>> = bins
+            .iter()
+            .map(|v| v.as_ref().map(|x| x.as_slice()))
+            .collect();
+        let dec_smalls: Vec<Option<i128>> = (0..num_rows)
+            .map(|i| {
+                if simple_hash(210, i) % 10 == 0 {
+                    None
+                } else {
+                    Some((simple_hash(211, i) % 99_999_999) as i128)
+                }
+            })
+            .collect();
+        let dec_larges: Vec<Option<i128>> = (0..num_rows)
+            .map(|i| {
+                if simple_hash(220, i) % 10 == 0 {
+                    None
+                } else {
+                    Some(simple_hash(221, i) as i128 * 1_000_000_000)
+                }
+            })
+            .collect();
+        let ts_ms: Vec<Option<i64>> = (0..num_rows)
+            .map(|i| {
+                if simple_hash(230, i) % 10 == 0 {
+                    None
+                } else {
+                    Some(simple_hash(231, i) as i64)
+                }
+            })
+            .collect();
+        let ts_us: Vec<Option<i64>> = (0..num_rows)
+            .map(|i| {
+                if simple_hash(240, i) % 10 == 0 {
+                    None
+                } else {
+                    Some(simple_hash(241, i) as i64)
+                }
+            })
+            .collect();
+        let ts_ns: Vec<Option<i64>> = (0..num_rows)
+            .map(|i| {
+                if simple_hash(250, i) % 10 == 0 {
+                    None
+                } else {
+                    Some(simple_hash(251, i) as i64)
+                }
+            })
+            .collect();
+
+        RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(BooleanArray::from(bools)),
+                Arc::new(Int8Array::from(i8s)),
+                Arc::new(Int16Array::from(i16s)),
+                Arc::new(Int32Array::from(i32s)),
+                Arc::new(Int64Array::from(i64s)),
+                Arc::new(Float32Array::from(f32s)),
+                Arc::new(Float64Array::from(f64s)),
+                Arc::new(Date32Array::from(dates)),
+                Arc::new(Time32MillisecondArray::from(times)),
+                Arc::new(StringArray::from(str_refs)),
+                Arc::new(BinaryArray::from(bin_refs)),
+                Arc::new(
+                    Decimal128Array::from(dec_smalls)
+                        .with_precision_and_scale(10, 2)
+                        .unwrap(),
+                ),
+                Arc::new(
+                    Decimal128Array::from(dec_larges)
+                        .with_precision_and_scale(38, 10)
+                        .unwrap(),
+                ),
+                Arc::new(TimestampMillisecondArray::from(ts_ms)),
+                Arc::new(TimestampMicrosecondArray::from(ts_us)),
+                Arc::new(TimestampNanosecondArray::from(ts_ns)),
+            ],
+        )
+        .unwrap()
+    };
+
+    let batch = make_batch();
+
+    let options = || WriterOptions::default();
+
+    let data1 = write_file(&schema, &[batch.clone()], options());
+    let data2 = write_file(&schema, &[batch.clone()], options());
+
+    assert_eq!(data1.len(), data2.len(), "file sizes differ");
+    assert_eq!(
+        data1, data2,
+        "byte-level mismatch for all-types deterministic output"
+    );
+
+    println!(
+        "test_deterministic_all_types: PASSED - {} bytes, byte-identical",
+        data1.len()
+    );
+}
+
+#[test]
+fn test_deterministic_with_nulls() {
+    let schema = Schema::new(vec![
+        Field::new("w", DataType::Int32, true),
+        Field::new("x", DataType::Utf8, true),
+        Field::new("y", DataType::Float64, true),
+        Field::new("z", DataType::Binary, true),
+    ]);
+
+    let num_rows = 50_000;
+
+    // Various null patterns: dense nulls, sparse nulls, alternating, runs
+    let i32_vals: Vec<Option<i32>> = (0..num_rows)
+        .map(|i| {
+            // Dense nulls in first quarter
+            if i < num_rows / 4 {
+                if i % 2 == 0 {
+                    None
+                } else {
+                    Some(i as i32)
+                }
+            }
+            // Sparse nulls in second quarter
+            else if i < num_rows / 2 {
+                if i % 100 == 0 {
+                    None
+                } else {
+                    Some(i as i32)
+                }
+            }
+            // Runs of nulls in third quarter
+            else if i < 3 * num_rows / 4 {
+                if (i / 50) % 2 == 0 {
+                    None
+                } else {
+                    Some(i as i32)
+                }
+            }
+            // All non-null in last quarter
+            else {
+                Some(i as i32)
+            }
+        })
+        .collect();
+
+    let str_vals: Vec<Option<String>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(50, i) % 3 == 0 {
+                None
+            } else {
+                Some(format!("val_{}", i))
+            }
+        })
+        .collect();
+    let str_refs: Vec<Option<&str>> = str_vals.iter().map(|s| s.as_deref()).collect();
+
+    let f64_vals: Vec<Option<f64>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(60, i) % 5 == 0 {
+                None
+            } else {
+                Some(i as f64 * 0.01)
+            }
+        })
+        .collect();
+
+    let bin_vals: Vec<Option<Vec<u8>>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(70, i) % 4 == 0 {
+                None
+            } else {
+                Some(vec![(i % 256) as u8; (i % 20) + 1])
+            }
+        })
+        .collect();
+    let bin_refs: Vec<Option<&[u8]>> = bin_vals
+        .iter()
+        .map(|v| v.as_ref().map(|x| x.as_slice()))
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int32Array::from(i32_vals)),
+            Arc::new(StringArray::from(str_refs)),
+            Arc::new(Float64Array::from(f64_vals)),
+            Arc::new(BinaryArray::from(bin_refs)),
+        ],
+    )
+    .unwrap();
+
+    let options = || WriterOptions::default();
+
+    let data1 = write_file(&schema, &[batch.clone()], options());
+    let data2 = write_file(&schema, &[batch.clone()], options());
+
+    assert_eq!(data1.len(), data2.len(), "file sizes differ");
+    assert_eq!(
+        data1, data2,
+        "byte-level mismatch for null-pattern deterministic output"
+    );
+
+    println!(
+        "test_deterministic_with_nulls: PASSED - {} bytes, byte-identical",
+        data1.len()
+    );
+}
+
+#[test]
+fn test_deterministic_with_zstd() {
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("data", DataType::Utf8, true),
+    ]);
+
+    let num_rows = 50_000;
+    let ids: Vec<i64> = (0..num_rows as i64).collect();
+    let strs: Vec<Option<String>> = (0..num_rows)
+        .map(|i| {
+            if i % 10 == 0 {
+                None
+            } else {
+                Some(format!("row_{:08}_data", i))
+            }
+        })
+        .collect();
+    let str_refs: Vec<Option<&str>> = strs.iter().map(|s| s.as_deref()).collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int64Array::from(ids)),
+            Arc::new(StringArray::from(str_refs)),
+        ],
+    )
+    .unwrap();
+
+    let options = || WriterOptions {
+        compression: spec::COMPRESSION_ZSTD,
+        zstd_level: 3,
+        ..Default::default()
+    };
+
+    let data1 = write_file(&schema, &[batch.clone()], options());
+    let data2 = write_file(&schema, &[batch.clone()], options());
+
+    assert_eq!(data1.len(), data2.len(), "file sizes differ with ZSTD");
+    assert_eq!(data1, data2, "byte-level mismatch with ZSTD compression");
+
+    println!(
+        "test_deterministic_with_zstd: PASSED - {} bytes, byte-identical",
+        data1.len()
+    );
+}
+
+#[test]
+fn test_deterministic_with_no_compression() {
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("value", DataType::Int32, true),
+        Field::new("label", DataType::Utf8, false),
+    ]);
+
+    let num_rows = 50_000;
+    let ids: Vec<i64> = (0..num_rows as i64).collect();
+    let vals: Vec<Option<i32>> = (0..num_rows)
+        .map(|i| {
+            if i % 11 == 0 {
+                None
+            } else {
+                Some(simple_hash(42, i) as i32)
+            }
+        })
+        .collect();
+    let labels: Vec<String> = (0..num_rows)
+        .map(|i| format!("label_{}", i % 100))
+        .collect();
+    let label_refs: Vec<&str> = labels.iter().map(|s| s.as_str()).collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int64Array::from(ids)),
+            Arc::new(Int32Array::from(vals)),
+            Arc::new(StringArray::from(label_refs)),
+        ],
+    )
+    .unwrap();
+
+    let options = || WriterOptions {
+        compression: spec::COMPRESSION_NONE,
+        ..Default::default()
+    };
+
+    let data1 = write_file(&schema, &[batch.clone()], options());
+    let data2 = write_file(&schema, &[batch.clone()], options());
+
+    assert_eq!(
+        data1.len(),
+        data2.len(),
+        "file sizes differ with no compression"
+    );
+    assert_eq!(data1, data2, "byte-level mismatch with no compression");
+
+    println!(
+        "test_deterministic_with_no_compression: PASSED - {} bytes, byte-identical",
+        data1.len()
+    );
+}
+
+#[test]
+fn test_deterministic_multiple_row_groups() {
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("data", DataType::Utf8, false),
+    ]);
+
+    let num_rows = 100_000;
+    let batch_size = 1_000;
+    let mut batches = Vec::new();
+
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+        let ids: Vec<i64> = (batch_start..batch_start + count)
+            .map(|i| i as i64)
+            .collect();
+        let strs: Vec<String> = (0..count)
+            .map(|i| format!("row_{:08}_padding_{}", batch_start + i, "x".repeat(50)))
+            .collect();
+        let str_refs: Vec<&str> = strs.iter().map(|s| s.as_str()).collect();
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int64Array::from(ids)),
+                Arc::new(StringArray::from(str_refs)),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    let options = || WriterOptions {
+        num_buckets: 1,
+        row_group_max_size: 64 * 1024, // 64KB to force multiple row groups
+        ..Default::default()
+    };
+
+    // Write 1
+    let out1 = MemOutputFile::new();
+    let mut writer1 = MosaicWriter::new(out1, &schema, options()).unwrap();
+    for batch in &batches {
+        writer1.write_batch(batch).unwrap();
+    }
+    writer1.close().unwrap();
+    let data1 = writer1.output().buf.clone();
+
+    // Write 2
+    let out2 = MemOutputFile::new();
+    let mut writer2 = MosaicWriter::new(out2, &schema, options()).unwrap();
+    for batch in &batches {
+        writer2.write_batch(batch).unwrap();
+    }
+    writer2.close().unwrap();
+    let data2 = writer2.output().buf.clone();
+
+    // Verify multiple row groups were created
+    let input = ByteArrayInputFile {
+        data: data1.clone(),
+    };
+    let reader = MosaicReader::new(input, data1.len() as u64).unwrap();
+    assert!(
+        reader.num_row_groups() > 1,
+        "expected multiple row groups, got {}",
+        reader.num_row_groups()
+    );
+
+    assert_eq!(data1.len(), data2.len(), "file sizes differ");
+    assert_eq!(data1, data2, "byte-level mismatch for multiple row groups");
+
+    println!(
+        "test_deterministic_multiple_row_groups: PASSED - {} bytes, {} row groups, byte-identical",
+        data1.len(),
+        reader.num_row_groups()
+    );
+}
+
+#[test]
+fn test_deterministic_different_batch_splits() {
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("value", DataType::Int32, false),
+    ]);
+
+    let num_rows = 100_000;
+
+    // Generate the same logical data
+    let ids: Vec<i64> = (0..num_rows as i64).collect();
+    let vals: Vec<i32> = (0..num_rows).map(|i| simple_hash(99, i) as i32).collect();
+
+    // Write 1: single big batch
+    let batch_single = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int64Array::from(ids.clone())),
+            Arc::new(Int32Array::from(vals.clone())),
+        ],
+    )
+    .unwrap();
+
+    let options = || WriterOptions {
+        num_buckets: 1,
+        row_group_max_size: 256 * 1024 * 1024, // large enough for single row group
+        ..Default::default()
+    };
+
+    let data_single = write_file(&schema, &[batch_single], options());
+
+    // Write 2: 10 batches of 10K each
+    let mut batches_split = Vec::new();
+    let chunk = num_rows / 10;
+    for c in 0..10 {
+        let start = c * chunk;
+        let end = start + chunk;
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int64Array::from(ids[start..end].to_vec())),
+                Arc::new(Int32Array::from(vals[start..end].to_vec())),
+            ],
+        )
+        .unwrap();
+        batches_split.push(batch);
+    }
+
+    let data_split = write_file(&schema, &batches_split, options());
+
+    // Both should roundtrip correctly (but may or may not be byte-identical
+    // since row group boundaries may differ)
+    let result_single = read_all(&data_single);
+    let result_split = read_all(&data_split);
+
+    assert!(
+        batches_equal_unordered(&result_single, &result_split),
+        "data mismatch between single batch and split batch writes"
+    );
+
+    println!(
+        "test_deterministic_different_batch_splits: PASSED - single: {} bytes, split: {} bytes, data matches",
+        data_single.len(),
+        data_split.len()
+    );
+}
+
+// ======================== Idempotency / Re-roundtrip Tests ========================
+
+#[test]
+fn test_reroundtrip_int_data() {
+    let schema = Schema::new(vec![
+        Field::new("ax", DataType::Int32, false),
+        Field::new("by", DataType::Int64, false),
+    ]);
+
+    let num_rows = 100_000;
+    let i32_vals: Vec<i32> = (0..num_rows).map(|i| simple_hash(1, i) as i32).collect();
+    let i64_vals: Vec<i64> = (0..num_rows).map(|i| simple_hash(2, i) as i64).collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int32Array::from(i32_vals)),
+            Arc::new(Int64Array::from(i64_vals)),
+        ],
+    )
+    .unwrap();
+
+    let (cycle2, cycle3, batches1, batches2) = reroundtrip(&schema, &[batch], make_default_options);
+
+    // Cycle 1 read should equal cycle 2 read (data stability)
+    assert!(
+        batches_equal_unordered(&batches1, &batches2),
+        "re-roundtrip data mismatch for int data"
+    );
+
+    // Cycle 2 bytes should equal cycle 3 bytes (byte-level stability)
+    assert_eq!(
+        cycle2.len(),
+        cycle3.len(),
+        "re-roundtrip file sizes differ: {} vs {}",
+        cycle2.len(),
+        cycle3.len()
+    );
+    assert_eq!(cycle2, cycle3, "re-roundtrip byte mismatch for int data");
+
+    println!(
+        "test_reroundtrip_int_data: PASSED - {} bytes, stable across cycles",
+        cycle2.len()
+    );
+}
+
+#[test]
+fn test_reroundtrip_string_data() {
+    let schema = Schema::new(vec![
+        Field::new("cx", DataType::Utf8, true),
+        Field::new("dy", DataType::Binary, true),
+    ]);
+
+    let num_rows = 50_000;
+    let str_vals: Vec<Option<String>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(30, i) % 7 == 0 {
+                None
+            } else {
+                let len = (simple_hash(31, i) % 50) as usize + 1;
+                Some(
+                    (0..len)
+                        .map(|j| (b'a' + (simple_hash(32, i * 50 + j) % 26) as u8) as char)
+                        .collect(),
+                )
+            }
+        })
+        .collect();
+    let str_refs: Vec<Option<&str>> = str_vals.iter().map(|s| s.as_deref()).collect();
+
+    let bin_vals: Vec<Option<Vec<u8>>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(40, i) % 9 == 0 {
+                None
+            } else {
+                let len = (simple_hash(41, i) % 32) as usize + 1;
+                Some(
+                    (0..len)
+                        .map(|j| simple_hash(42, i * 32 + j) as u8)
+                        .collect(),
+                )
+            }
+        })
+        .collect();
+    let bin_refs: Vec<Option<&[u8]>> = bin_vals
+        .iter()
+        .map(|v| v.as_ref().map(|x| x.as_slice()))
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(StringArray::from(str_refs)),
+            Arc::new(BinaryArray::from(bin_refs)),
+        ],
+    )
+    .unwrap();
+
+    let (cycle2, cycle3, batches1, batches2) = reroundtrip(&schema, &[batch], make_default_options);
+
+    assert!(
+        batches_equal_unordered(&batches1, &batches2),
+        "re-roundtrip data mismatch for string data"
+    );
+    assert_eq!(cycle2, cycle3, "re-roundtrip byte mismatch for string data");
+
+    println!(
+        "test_reroundtrip_string_data: PASSED - {} bytes, stable",
+        cycle2.len()
+    );
+}
+
+#[test]
+fn test_reroundtrip_all_types() {
+    let schema = Schema::new(vec![
+        Field::new("a", DataType::Boolean, true),
+        Field::new("b", DataType::Int8, true),
+        Field::new("c", DataType::Int16, true),
+        Field::new("d", DataType::Int32, true),
+        Field::new("e", DataType::Int64, true),
+        Field::new("f", DataType::Float32, true),
+        Field::new("g", DataType::Float64, true),
+        Field::new("h", DataType::Date32, true),
+        Field::new("j", DataType::Time32(TimeUnit::Millisecond), true),
+        Field::new("k", DataType::Utf8, true),
+        Field::new("m", DataType::Binary, true),
+        Field::new("n", DataType::Decimal128(10, 2), true),
+        Field::new("p", DataType::Decimal128(38, 10), true),
+        Field::new("q", DataType::Timestamp(TimeUnit::Millisecond, None), true),
+        Field::new("r", DataType::Timestamp(TimeUnit::Microsecond, None), true),
+        Field::new("s", DataType::Timestamp(TimeUnit::Nanosecond, None), true),
+    ]);
+
+    let num_rows = 30_000;
+
+    let bools: Vec<Option<bool>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(300, i) % 8 == 0 {
+                None
+            } else {
+                Some(simple_hash(301, i) % 2 == 0)
+            }
+        })
+        .collect();
+    let i8s: Vec<Option<i8>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(310, i) % 10 == 0 {
+                None
+            } else {
+                Some(simple_hash(311, i) as i8)
+            }
+        })
+        .collect();
+    let i16s: Vec<Option<i16>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(320, i) % 10 == 0 {
+                None
+            } else {
+                Some(simple_hash(321, i) as i16)
+            }
+        })
+        .collect();
+    let i32s: Vec<Option<i32>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(330, i) % 10 == 0 {
+                None
+            } else {
+                Some(simple_hash(331, i) as i32)
+            }
+        })
+        .collect();
+    let i64s: Vec<Option<i64>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(340, i) % 10 == 0 {
+                None
+            } else {
+                Some(simple_hash(341, i) as i64)
+            }
+        })
+        .collect();
+    let f32s: Vec<Option<f32>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(350, i) % 10 == 0 {
+                None
+            } else {
+                Some(simple_hash(351, i) as f32 / 1000.0)
+            }
+        })
+        .collect();
+    let f64s: Vec<Option<f64>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(360, i) % 10 == 0 {
+                None
+            } else {
+                Some(simple_hash(361, i) as f64 / 1000.0)
+            }
+        })
+        .collect();
+    let dates: Vec<Option<i32>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(370, i) % 10 == 0 {
+                None
+            } else {
+                Some((simple_hash(371, i) % 40000) as i32)
+            }
+        })
+        .collect();
+    let times: Vec<Option<i32>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(380, i) % 10 == 0 {
+                None
+            } else {
+                Some((simple_hash(381, i) % 86_400_000) as i32)
+            }
+        })
+        .collect();
+    let strings: Vec<Option<String>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(390, i) % 8 == 0 {
+                None
+            } else {
+                let len = (simple_hash(391, i) % 20) as usize + 1;
+                Some(
+                    (0..len)
+                        .map(|j| (b'a' + (simple_hash(392, i * 20 + j) % 26) as u8) as char)
+                        .collect(),
+                )
+            }
+        })
+        .collect();
+    let str_refs: Vec<Option<&str>> = strings.iter().map(|s| s.as_deref()).collect();
+    let bins: Vec<Option<Vec<u8>>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(400, i) % 8 == 0 {
+                None
+            } else {
+                let len = (simple_hash(401, i) % 16) as usize + 1;
+                Some(
+                    (0..len)
+                        .map(|j| simple_hash(402, i * 16 + j) as u8)
+                        .collect(),
+                )
+            }
+        })
+        .collect();
+    let bin_refs: Vec<Option<&[u8]>> = bins
+        .iter()
+        .map(|v| v.as_ref().map(|x| x.as_slice()))
+        .collect();
+    let dec_smalls: Vec<Option<i128>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(410, i) % 10 == 0 {
+                None
+            } else {
+                Some((simple_hash(411, i) % 99_999_999) as i128)
+            }
+        })
+        .collect();
+    let dec_larges: Vec<Option<i128>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(420, i) % 10 == 0 {
+                None
+            } else {
+                Some(simple_hash(421, i) as i128 * 1_000_000_000)
+            }
+        })
+        .collect();
+    let ts_ms: Vec<Option<i64>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(430, i) % 10 == 0 {
+                None
+            } else {
+                Some(simple_hash(431, i) as i64)
+            }
+        })
+        .collect();
+    let ts_us: Vec<Option<i64>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(440, i) % 10 == 0 {
+                None
+            } else {
+                Some(simple_hash(441, i) as i64)
+            }
+        })
+        .collect();
+    let ts_ns: Vec<Option<i64>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(450, i) % 10 == 0 {
+                None
+            } else {
+                Some(simple_hash(451, i) as i64)
+            }
+        })
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(BooleanArray::from(bools)),
+            Arc::new(Int8Array::from(i8s)),
+            Arc::new(Int16Array::from(i16s)),
+            Arc::new(Int32Array::from(i32s)),
+            Arc::new(Int64Array::from(i64s)),
+            Arc::new(Float32Array::from(f32s)),
+            Arc::new(Float64Array::from(f64s)),
+            Arc::new(Date32Array::from(dates)),
+            Arc::new(Time32MillisecondArray::from(times)),
+            Arc::new(StringArray::from(str_refs)),
+            Arc::new(BinaryArray::from(bin_refs)),
+            Arc::new(
+                Decimal128Array::from(dec_smalls)
+                    .with_precision_and_scale(10, 2)
+                    .unwrap(),
+            ),
+            Arc::new(
+                Decimal128Array::from(dec_larges)
+                    .with_precision_and_scale(38, 10)
+                    .unwrap(),
+            ),
+            Arc::new(TimestampMillisecondArray::from(ts_ms)),
+            Arc::new(TimestampMicrosecondArray::from(ts_us)),
+            Arc::new(TimestampNanosecondArray::from(ts_ns)),
+        ],
+    )
+    .unwrap();
+
+    let (cycle2, cycle3, batches1, batches2) = reroundtrip(&schema, &[batch], make_default_options);
+
+    assert!(
+        batches_equal_unordered(&batches1, &batches2),
+        "re-roundtrip data mismatch for all types"
+    );
+    assert_eq!(cycle2, cycle3, "re-roundtrip byte mismatch for all types");
+
+    println!(
+        "test_reroundtrip_all_types: PASSED - {} bytes, stable",
+        cycle2.len()
+    );
+}
+
+#[test]
+fn test_reroundtrip_with_nulls() {
+    let schema = Schema::new(vec![
+        Field::new("w", DataType::Int32, true),
+        Field::new("x", DataType::Utf8, true),
+        Field::new("y", DataType::Float64, true),
+        Field::new("z", DataType::Int64, true),
+    ]);
+
+    let num_rows = 50_000;
+
+    let mostly_null: Vec<Option<i32>> = (0..num_rows)
+        .map(|i| if i % 100 == 0 { Some(i as i32) } else { None })
+        .collect();
+    let half_null: Vec<Option<String>> = (0..num_rows)
+        .map(|i| {
+            if i % 2 == 0 {
+                None
+            } else {
+                Some(format!("val_{}", i))
+            }
+        })
+        .collect();
+    let half_null_refs: Vec<Option<&str>> = half_null.iter().map(|s| s.as_deref()).collect();
+    let rarely_null: Vec<Option<f64>> = (0..num_rows)
+        .map(|i| {
+            if i == 7 || i == 9999 || i == 49999 {
+                None
+            } else {
+                Some(i as f64 * 0.001)
+            }
+        })
+        .collect();
+    let all_null: Vec<Option<i64>> = vec![None; num_rows];
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int32Array::from(mostly_null)),
+            Arc::new(StringArray::from(half_null_refs)),
+            Arc::new(Float64Array::from(rarely_null)),
+            Arc::new(Int64Array::from(all_null)),
+        ],
+    )
+    .unwrap();
+
+    let (cycle2, cycle3, batches1, batches2) = reroundtrip(&schema, &[batch], make_default_options);
+
+    assert!(
+        batches_equal_unordered(&batches1, &batches2),
+        "re-roundtrip data mismatch with nulls"
+    );
+    assert_eq!(cycle2, cycle3, "re-roundtrip byte mismatch with nulls");
+
+    println!(
+        "test_reroundtrip_with_nulls: PASSED - {} bytes, stable",
+        cycle2.len()
+    );
+}
+
+#[test]
+fn test_reroundtrip_multiple_row_groups() {
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("data", DataType::Utf8, false),
+    ]);
+
+    let num_rows = 50_000;
+    let batch_size = 500;
+    let mut batches = Vec::new();
+
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+        let ids: Vec<i64> = (batch_start..batch_start + count)
+            .map(|i| i as i64)
+            .collect();
+        let strs: Vec<String> = (0..count)
+            .map(|i| format!("row_{:08}_pad_{}", batch_start + i, "x".repeat(40)))
+            .collect();
+        let str_refs: Vec<&str> = strs.iter().map(|s| s.as_str()).collect();
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int64Array::from(ids)),
+                Arc::new(StringArray::from(str_refs)),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    let options_fn = || WriterOptions {
+        num_buckets: 1,
+        row_group_max_size: 32 * 1024, // 32KB to force multiple row groups
+        ..Default::default()
+    };
+
+    // First write
+    let out1 = MemOutputFile::new();
+    let mut writer1 = MosaicWriter::new(out1, &schema, options_fn()).unwrap();
+    for batch in &batches {
+        writer1.write_batch(batch).unwrap();
+    }
+    writer1.close().unwrap();
+    let data1 = writer1.output().buf.clone();
+
+    // Read all row groups, concatenate
+    let batches1 = read_all(&data1);
+    let total_rows1: usize = batches1.iter().map(|b| b.num_rows()).sum();
+    assert_eq!(total_rows1, num_rows);
+    assert!(batches1.len() > 1, "expected multiple row groups");
+
+    // Second write from read data
+    let read_schema = batches1[0].schema();
+    let out2 = MemOutputFile::new();
+    let mut writer2 = MosaicWriter::new(out2, &read_schema, options_fn()).unwrap();
+    for batch in &batches1 {
+        writer2.write_batch(batch).unwrap();
+    }
+    writer2.close().unwrap();
+    let data2 = writer2.output().buf.clone();
+
+    // Second read
+    let batches2 = read_all(&data2);
+
+    assert!(
+        batches_equal_unordered(&batches1, &batches2),
+        "re-roundtrip data mismatch for multiple row groups"
+    );
+
+    println!(
+        "test_reroundtrip_multiple_row_groups: PASSED - {} row groups, data matches",
+        batches1.len()
+    );
+}
+
+#[test]
+fn test_reroundtrip_with_projection() {
+    // Write 20 columns
+    let num_cols = 20;
+    let num_rows = 10_000;
+
+    let fields: Vec<Field> = (0..num_cols)
+        .map(|i| Field::new(format!("c{:02}", i), DataType::Int64, true))
+        .collect();
+    let schema = Schema::new(fields);
+
+    let mut arrays: Vec<Arc<dyn Array>> = Vec::new();
+    for col in 0..num_cols {
+        let vals: Vec<Option<i64>> = (0..num_rows)
+            .map(|i| {
+                if simple_hash(500 + col as u64, i) % 10 == 0 {
+                    None
+                } else {
+                    Some(simple_hash(600 + col as u64, i) as i64)
+                }
+            })
+            .collect();
+        arrays.push(Arc::new(Int64Array::from(vals)));
+    }
+
+    let batch = RecordBatch::try_new(Arc::new(schema.clone()), arrays).unwrap();
+
+    let data1 = write_file(&schema, &[batch], WriterOptions::default());
+
+    // Read back with projection (only 5 columns: indices 0, 4, 9, 14, 19)
+    let projected_cols = vec![0, 4, 9, 14, 19];
+    let projected_batches = read_projected(&data1, &projected_cols);
+    assert!(!projected_batches.is_empty());
+
+    let projected_schema = projected_batches[0].schema();
+    assert_eq!(projected_schema.fields().len(), 5);
+
+    // Write the 5 columns
+    let data2 = write_file(
+        &projected_schema,
+        &projected_batches,
+        WriterOptions::default(),
+    );
+
+    // Read again
+    let reread_batches = read_all(&data2);
+
+    assert!(
+        batches_equal_unordered(&projected_batches, &reread_batches),
+        "re-roundtrip with projection: data mismatch"
+    );
+
+    println!("test_reroundtrip_with_projection: PASSED - 20 cols -> 5 projected, roundtrip stable");
+}
+
+#[test]
+fn test_reroundtrip_chain_5_times() {
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("value", DataType::Int32, true),
+        Field::new("label", DataType::Utf8, true),
+        Field::new("score", DataType::Float64, true),
+    ]);
+
+    let num_rows = 20_000;
+    let ids: Vec<i64> = (0..num_rows as i64).collect();
+    let vals: Vec<Option<i32>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(700, i) % 7 == 0 {
+                None
+            } else {
+                Some(simple_hash(701, i) as i32)
+            }
+        })
+        .collect();
+    let labels: Vec<Option<String>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(710, i) % 5 == 0 {
+                None
+            } else {
+                Some(format!("lbl_{}", i % 200))
+            }
+        })
+        .collect();
+    let label_refs: Vec<Option<&str>> = labels.iter().map(|s| s.as_deref()).collect();
+    let scores: Vec<Option<f64>> = (0..num_rows)
+        .map(|i| {
+            if simple_hash(720, i) % 9 == 0 {
+                None
+            } else {
+                Some(simple_hash(721, i) as f64 / 10000.0)
+            }
+        })
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int64Array::from(ids)),
+            Arc::new(Int32Array::from(vals)),
+            Arc::new(StringArray::from(label_refs)),
+            Arc::new(Float64Array::from(scores)),
+        ],
+    )
+    .unwrap();
+
+    let options = || WriterOptions::default();
+
+    // Cycle 0: initial write
+    let mut current_data = write_file(&schema, &[batch], options());
+    let mut current_batches = read_all(&current_data);
+
+    let mut prev_data = current_data.clone();
+
+    // Cycles 1-4
+    for cycle in 1..5 {
+        let read_schema = current_batches[0].schema();
+        current_data = write_file(&read_schema, &current_batches, options());
+        current_batches = read_all(&current_data);
+
+        // Each cycle should produce identical bytes
+        assert_eq!(
+            current_data.len(),
+            prev_data.len(),
+            "cycle {}: file size changed from {} to {}",
+            cycle,
+            prev_data.len(),
+            current_data.len()
+        );
+        assert_eq!(
+            current_data, prev_data,
+            "cycle {}: byte-level mismatch",
+            cycle
+        );
+
+        prev_data = current_data.clone();
+    }
+
+    println!(
+        "test_reroundtrip_chain_5_times: PASSED - {} bytes, stable across 5 cycles",
+        current_data.len()
+    );
+}
+
+// ======================== Output Stability Tests ========================
+
+#[test]
+fn test_output_size_consistent() {
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("value", DataType::Utf8, true),
+        Field::new("count", DataType::Int32, true),
+    ]);
+
+    let num_rows = 30_000;
+    let ids: Vec<i64> = (0..num_rows as i64).collect();
+    let vals: Vec<Option<String>> = (0..num_rows)
+        .map(|i| {
+            if i % 8 == 0 {
+                None
+            } else {
+                Some(format!("item_{:06}", i))
+            }
+        })
+        .collect();
+    let val_refs: Vec<Option<&str>> = vals.iter().map(|s| s.as_deref()).collect();
+    let counts: Vec<Option<i32>> = (0..num_rows)
+        .map(|i| {
+            if i % 12 == 0 {
+                None
+            } else {
+                Some(simple_hash(800, i) as i32)
+            }
+        })
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int64Array::from(ids)),
+            Arc::new(StringArray::from(val_refs)),
+            Arc::new(Int32Array::from(counts)),
+        ],
+    )
+    .unwrap();
+
+    let options = || WriterOptions::default();
+
+    let mut sizes = Vec::new();
+    for _ in 0..10 {
+        let data = write_file(&schema, &[batch.clone()], options());
+        sizes.push(data.len());
+    }
+
+    let first_size = sizes[0];
+    for (i, &size) in sizes.iter().enumerate() {
+        assert_eq!(
+            size, first_size,
+            "write {} produced {} bytes, expected {}",
+            i, size, first_size
+        );
+    }
+
+    println!(
+        "test_output_size_consistent: PASSED - all 10 writes produced exactly {} bytes",
+        first_size
+    );
+}
+
+#[test]
+fn test_footer_position_deterministic() {
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("data", DataType::Utf8, true),
+        Field::new("score", DataType::Float64, false),
+    ]);
+
+    let num_rows = 50_000;
+    let ids: Vec<i64> = (0..num_rows as i64).collect();
+    let strs: Vec<Option<String>> = (0..num_rows)
+        .map(|i| {
+            if i % 6 == 0 {
+                None
+            } else {
+                Some(format!("record_{:08}", i))
+            }
+        })
+        .collect();
+    let str_refs: Vec<Option<&str>> = strs.iter().map(|s| s.as_deref()).collect();
+    let scores: Vec<f64> = (0..num_rows).map(|i| i as f64 * 0.01).collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int64Array::from(ids)),
+            Arc::new(StringArray::from(str_refs)),
+            Arc::new(Float64Array::from(scores)),
+        ],
+    )
+    .unwrap();
+
+    let options = || WriterOptions::default();
+
+    let data1 = write_file(&schema, &[batch.clone()], options());
+    let data2 = write_file(&schema, &[batch.clone()], options());
+
+    // Parse footer from both files (last 32 bytes)
+    let parse_footer = |data: &[u8]| {
+        let len = data.len();
+        let footer = &data[len - spec::FOOTER_SIZE..];
+        let index_offset = u64::from_be_bytes(footer[0..8].try_into().unwrap());
+        let schema_block_offset = u64::from_be_bytes(footer[8..16].try_into().unwrap());
+        let num_buckets = u32::from_be_bytes(footer[16..20].try_into().unwrap());
+        let num_row_groups = u32::from_be_bytes(footer[20..24].try_into().unwrap());
+        let compression = footer[24];
+        let version = footer[25];
+        (
+            index_offset,
+            schema_block_offset,
+            num_buckets,
+            num_row_groups,
+            compression,
+            version,
+        )
+    };
+
+    let footer1 = parse_footer(&data1);
+    let footer2 = parse_footer(&data2);
+
+    assert_eq!(
+        footer1.0, footer2.0,
+        "index_offset differs: {} vs {}",
+        footer1.0, footer2.0
+    );
+    assert_eq!(
+        footer1.1, footer2.1,
+        "schema_block_offset differs: {} vs {}",
+        footer1.1, footer2.1
+    );
+    assert_eq!(
+        footer1.2, footer2.2,
+        "num_buckets differs: {} vs {}",
+        footer1.2, footer2.2
+    );
+    assert_eq!(
+        footer1.3, footer2.3,
+        "num_row_groups differs: {} vs {}",
+        footer1.3, footer2.3
+    );
+    assert_eq!(
+        footer1.4, footer2.4,
+        "compression differs: {} vs {}",
+        footer1.4, footer2.4
+    );
+    assert_eq!(
+        footer1.5, footer2.5,
+        "version differs: {} vs {}",
+        footer1.5, footer2.5
+    );
+
+    println!(
+        "test_footer_position_deterministic: PASSED - index_offset={}, schema_block_offset={}, identical",
+        footer1.0, footer1.1
+    );
+}
+
+// ======================== BPE Determinism Regression Test ========================
+
+/// Regression test for BPE non-determinism when column names share common substrings.
+/// The BPE vocabulary builder uses HashMap for pair counting; when multiple pairs have
+/// equal frequency, the tie must be broken deterministically (by pair key) rather than
+/// relying on HashMap iteration order.
+#[test]
+fn test_deterministic_shared_substring_columns() {
+    let schema = Schema::new(vec![
+        Field::new("engine_coolant_temp", DataType::Int32, true),
+        Field::new("engine_coolant_pressure", DataType::Float64, true),
+        Field::new("engine_oil_temp", DataType::Int32, true),
+        Field::new("engine_oil_pressure", DataType::Float64, true),
+        Field::new("engine_rpm", DataType::Int64, false),
+        Field::new("engine_load", DataType::Float32, true),
+        Field::new("transmission_temp", DataType::Int32, true),
+        Field::new("transmission_pressure", DataType::Float64, true),
+    ]);
+
+    let num_rows = 10_000;
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int32Array::from(
+                (0..num_rows)
+                    .map(|i| if i % 5 == 0 { None } else { Some(i as i32) })
+                    .collect::<Vec<_>>(),
+            )),
+            Arc::new(Float64Array::from(
+                (0..num_rows)
+                    .map(|i| {
+                        if i % 7 == 0 {
+                            None
+                        } else {
+                            Some(i as f64 * 0.1)
+                        }
+                    })
+                    .collect::<Vec<_>>(),
+            )),
+            Arc::new(Int32Array::from(
+                (0..num_rows)
+                    .map(|i| if i % 6 == 0 { None } else { Some(i as i32 * 2) })
+                    .collect::<Vec<_>>(),
+            )),
+            Arc::new(Float64Array::from(
+                (0..num_rows)
+                    .map(|i| {
+                        if i % 8 == 0 {
+                            None
+                        } else {
+                            Some(i as f64 * 0.5)
+                        }
+                    })
+                    .collect::<Vec<_>>(),
+            )),
+            Arc::new(Int64Array::from((0..num_rows as i64).collect::<Vec<_>>())),
+            Arc::new(Float32Array::from(
+                (0..num_rows)
+                    .map(|i| if i % 9 == 0 { None } else { Some(i as f32) })
+                    .collect::<Vec<_>>(),
+            )),
+            Arc::new(Int32Array::from(
+                (0..num_rows)
+                    .map(|i| if i % 4 == 0 { None } else { Some(i as i32 * 3) })
+                    .collect::<Vec<_>>(),
+            )),
+            Arc::new(Float64Array::from(
+                (0..num_rows)
+                    .map(|i| {
+                        if i % 11 == 0 {
+                            None
+                        } else {
+                            Some(i as f64 * 0.3)
+                        }
+                    })
+                    .collect::<Vec<_>>(),
+            )),
+        ],
+    )
+    .unwrap();
+
+    // Write 10 times - all must produce byte-identical output
+    let first = write_file(&schema, &[batch.clone()], WriterOptions::default());
+    for attempt in 1..10 {
+        let again = write_file(&schema, &[batch.clone()], WriterOptions::default());
+        assert_eq!(
+            first.len(),
+            again.len(),
+            "attempt {}: file sizes differ: {} vs {}",
+            attempt,
+            first.len(),
+            again.len()
+        );
+        assert_eq!(
+            first, again,
+            "attempt {}: byte-level mismatch with shared-substring column names",
+            attempt
+        );
+    }
+
+    // Also verify roundtrip correctness
+    let result = read_all(&first);
+    let total_rows: usize = result.iter().map(|b| b.num_rows()).sum();
+    assert_eq!(total_rows, num_rows);
+
+    println!(
+        "test_deterministic_shared_substring_columns: PASSED - {} bytes, 10 writes all byte-identical",
+        first.len()
+    );
+}
diff --git a/core/tests/encoding_compression_test.rs b/core/tests/encoding_compression_test.rs
new file mode 100644
index 0000000..9615bca
--- /dev/null
+++ b/core/tests/encoding_compression_test.rs
@@ -0,0 +1,2678 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Comprehensive tests for encoding strategies, compression behavior,
+//! projection correctness, and writer options interactions.
+
+#![allow(
+    clippy::approx_constant,
+    clippy::unnecessary_cast,
+    clippy::cloned_ref_to_slice_refs,
+    clippy::needless_range_loop,
+    clippy::manual_is_multiple_of
+)]
+
+use std::io;
+use std::sync::Arc;
+
+use arrow_array::*;
+use arrow_schema::{DataType, Field, Schema, TimeUnit};
+use paimon_mosaic_core::reader::{InputFile, MosaicReader, ReaderAccess};
+use paimon_mosaic_core::spec;
+use paimon_mosaic_core::writer::{MosaicWriter, OutputFile, WriterOptions};
+
+// ======================== Test Infrastructure ========================
+
+struct MemOutputFile {
+    pub buf: Vec<u8>,
+}
+
+impl MemOutputFile {
+    fn new() -> Self {
+        Self { buf: Vec::new() }
+    }
+}
+
+impl OutputFile for MemOutputFile {
+    fn write(&mut self, data: &[u8]) -> io::Result<()> {
+        self.buf.extend_from_slice(data);
+        Ok(())
+    }
+    fn flush(&mut self) -> io::Result<()> {
+        Ok(())
+    }
+    fn pos(&self) -> u64 {
+        self.buf.len() as u64
+    }
+}
+
+struct ByteArrayInputFile {
+    data: Vec<u8>,
+}
+
+impl InputFile for ByteArrayInputFile {
+    fn read_at(&self, offset: u64, buf: &mut [u8]) -> io::Result<()> {
+        let start = offset as usize;
+        let end = start + buf.len();
+        if end > self.data.len() {
+            return Err(io::Error::new(
+                io::ErrorKind::UnexpectedEof,
+                "read past end",
+            ));
+        }
+        buf.copy_from_slice(&self.data[start..end]);
+        Ok(())
+    }
+}
+
+fn simple_hash(seed: u64, i: usize) -> u64 {
+    let mut x = seed.wrapping_add(i as u64);
+    x ^= x >> 33;
+    x = x.wrapping_mul(0xff51afd7ed558ccd);
+    x ^= x >> 33;
+    x = x.wrapping_mul(0xc4ceb9fe1a85ec53);
+    x ^= x >> 33;
+    x
+}
+
+fn write_file(schema: &Schema, batches: &[RecordBatch], options: WriterOptions) -> Vec<u8> {
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(out, schema, options).unwrap();
+    for batch in batches {
+        writer.write_batch(batch).unwrap();
+    }
+    writer.close().unwrap();
+    writer.output().buf.clone()
+}
+
+fn read_all(data: &[u8]) -> Vec<RecordBatch> {
+    let input = ByteArrayInputFile {
+        data: data.to_vec(),
+    };
+    let reader = MosaicReader::new(input, data.len() as u64).unwrap();
+    let mut result = Vec::new();
+    for rg in 0..reader.num_row_groups() {
+        let mut rg_reader = reader.row_group_reader(rg).unwrap();
+        result.push(rg_reader.read_columns().unwrap());
+    }
+    result
+}
+
+fn concat_column_i32(batches: &[RecordBatch], col_name: &str) -> Vec<Option<i32>> {
+    let mut out = Vec::new();
+    for batch in batches {
+        let idx = batch.schema().index_of(col_name).unwrap();
+        let arr = batch
+            .column(idx)
+            .as_any()
+            .downcast_ref::<Int32Array>()
+            .unwrap();
+        for i in 0..arr.len() {
+            if arr.is_null(i) {
+                out.push(None);
+            } else {
+                out.push(Some(arr.value(i)));
+            }
+        }
+    }
+    out
+}
+
+fn concat_column_i64(batches: &[RecordBatch], col_name: &str) -> Vec<Option<i64>> {
+    let mut out = Vec::new();
+    for batch in batches {
+        let idx = batch.schema().index_of(col_name).unwrap();
+        let arr = batch
+            .column(idx)
+            .as_any()
+            .downcast_ref::<Int64Array>()
+            .unwrap();
+        for i in 0..arr.len() {
+            if arr.is_null(i) {
+                out.push(None);
+            } else {
+                out.push(Some(arr.value(i)));
+            }
+        }
+    }
+    out
+}
+
+fn concat_column_string(batches: &[RecordBatch], col_name: &str) -> Vec<Option<String>> {
+    let mut out = Vec::new();
+    for batch in batches {
+        let idx = batch.schema().index_of(col_name).unwrap();
+        let arr = batch
+            .column(idx)
+            .as_any()
+            .downcast_ref::<StringArray>()
+            .unwrap();
+        for i in 0..arr.len() {
+            if arr.is_null(i) {
+                out.push(None);
+            } else {
+                out.push(Some(arr.value(i).to_string()));
+            }
+        }
+    }
+    out
+}
+
+fn total_rows(batches: &[RecordBatch]) -> usize {
+    batches.iter().map(|b| b.num_rows()).sum()
+}
+
+fn assert_batches_equal(expected: &[RecordBatch], actual: &[RecordBatch]) {
+    let expected_rows: usize = expected.iter().map(|b| b.num_rows()).sum();
+    let actual_rows: usize = actual.iter().map(|b| b.num_rows()).sum();
+    assert_eq!(expected_rows, actual_rows, "total row count mismatch");
+
+    let mut exp_offset = 0;
+    let mut act_offset = 0;
+    let mut exp_batch_idx = 0;
+    let mut act_batch_idx = 0;
+
+    let num_cols = expected[0].num_columns();
+    let exp_schema = expected[0].schema();
+    let mut row = 0;
+    while row < expected_rows {
+        let exp_batch = &expected[exp_batch_idx];
+        let act_batch = &actual[act_batch_idx];
+        let exp_remaining = exp_batch.num_rows() - exp_offset;
+        let act_remaining = act_batch.num_rows() - act_offset;
+        let chunk = exp_remaining.min(act_remaining);
+
+        for col in 0..num_cols {
+            let col_name = exp_schema.field(col).name();
+            let act_col_idx = act_batch.schema().index_of(col_name).unwrap();
+            let exp_col = exp_batch.column(col).slice(exp_offset, chunk);
+            let act_col = act_batch.column(act_col_idx).slice(act_offset, chunk);
+            assert_eq!(
+                &exp_col,
+                &act_col,
+                "mismatch at column {} rows {}..{}",
+                col_name,
+                row,
+                row + chunk
+            );
+        }
+
+        exp_offset += chunk;
+        act_offset += chunk;
+        row += chunk;
+        if exp_offset == exp_batch.num_rows() {
+            exp_batch_idx += 1;
+            exp_offset = 0;
+        }
+        if act_offset == act_batch.num_rows() {
+            act_batch_idx += 1;
+            act_offset = 0;
+        }
+    }
+}
+
+// ======================== Encoding Tests ========================
+
+// 1. test_const_encoding_all_types
+#[test]
+fn test_const_encoding_all_types() {
+    let num_rows = 100_000;
+
+    // Boolean constant
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Boolean, false)]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(BooleanArray::from(vec![true; num_rows]))],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        assert!(
+            data.len() < 4096,
+            "Boolean const file too large: {} bytes",
+            data.len()
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+    }
+
+    // Int8 constant
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Int8, false)]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(Int8Array::from(vec![42i8; num_rows]))],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        assert!(
+            data.len() < 4096,
+            "Int8 const file too large: {} bytes",
+            data.len()
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+    }
+
+    // Int16 constant
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Int16, false)]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(Int16Array::from(vec![1234i16; num_rows]))],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        assert!(
+            data.len() < 4096,
+            "Int16 const file too large: {} bytes",
+            data.len()
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+    }
+
+    // Int32 constant
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Int32, false)]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(Int32Array::from(vec![99999i32; num_rows]))],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        assert!(
+            data.len() < 4096,
+            "Int32 const file too large: {} bytes",
+            data.len()
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+    }
+
+    // Int64 constant
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Int64, false)]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(Int64Array::from(vec![
+                999_999_999_999i64;
+                num_rows
+            ]))],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        assert!(
+            data.len() < 4096,
+            "Int64 const file too large: {} bytes",
+            data.len()
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+    }
+
+    // Float32 constant
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Float32, false)]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(Float32Array::from(vec![3.14f32; num_rows]))],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        assert!(
+            data.len() < 4096,
+            "Float32 const file too large: {} bytes",
+            data.len()
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+    }
+
+    // Float64 constant
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Float64, false)]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(Float64Array::from(vec![2.71828f64; num_rows]))],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        assert!(
+            data.len() < 4096,
+            "Float64 const file too large: {} bytes",
+            data.len()
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+    }
+
+    // Utf8 constant
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Utf8, false)]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(StringArray::from(vec!["hello_world"; num_rows]))],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        assert!(
+            data.len() < 4096,
+            "Utf8 const file too large: {} bytes",
+            data.len()
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+    }
+
+    // Binary constant
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Binary, false)]);
+        let val: &[u8] = b"constant_binary_value";
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(BinaryArray::from(vec![val; num_rows]))],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        assert!(
+            data.len() < 4096,
+            "Binary const file too large: {} bytes",
+            data.len()
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+    }
+
+    // Date32 constant
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Date32, false)]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(Date32Array::from(vec![19000i32; num_rows]))],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        assert!(
+            data.len() < 4096,
+            "Date32 const file too large: {} bytes",
+            data.len()
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+    }
+
+    // Time32 constant
+    {
+        let schema = Schema::new(vec![Field::new(
+            "v",
+            DataType::Time32(TimeUnit::Millisecond),
+            false,
+        )]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(Time32MillisecondArray::from(vec![
+                3_600_000i32;
+                num_rows
+            ]))],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        assert!(
+            data.len() < 4096,
+            "Time32 const file too large: {} bytes",
+            data.len()
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+    }
+
+    // Decimal128 constant
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Decimal128(10, 2), false)]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(
+                Decimal128Array::from(vec![12345i128; num_rows])
+                    .with_precision_and_scale(10, 2)
+                    .unwrap(),
+            )],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        assert!(
+            data.len() < 4096,
+            "Decimal128 const file too large: {} bytes",
+            data.len()
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+    }
+
+    println!("test_const_encoding_all_types: PASSED - all types produce small const-encoded files");
+}
+
+// 2. test_dict_encoding_boundary_253_254_255_256
+#[test]
+fn test_dict_encoding_boundary_253_254_255_256() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Int32, false)]);
+
+    for num_distinct in [253, 254, 255, 256] {
+        let num_rows = 50_000;
+        let vals: Vec<i32> = (0..num_rows).map(|i| (i % num_distinct) as i32).collect();
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(Int32Array::from(vals.clone()))],
+        )
+        .unwrap();
+
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+
+        let result = read_all(&data);
+        let out_vals: Vec<i32> = result
+            .iter()
+            .flat_map(|b| {
+                let idx = b.schema().index_of("v").unwrap();
+                b.column(idx)
+                    .as_any()
+                    .downcast_ref::<Int32Array>()
+                    .unwrap()
+                    .values()
+                    .iter()
+                    .copied()
+            })
+            .collect();
+        assert_eq!(
+            out_vals, vals,
+            "roundtrip failed for {} distinct values",
+            num_distinct
+        );
+        println!(
+            "  dict boundary {}: file size = {} bytes, roundtrip OK",
+            num_distinct,
+            data.len()
+        );
+    }
+
+    println!("test_dict_encoding_boundary_253_254_255_256: PASSED");
+}
+
+// 3. test_dict_encoding_string_cardinality
+#[test]
+fn test_dict_encoding_string_cardinality() {
+    for num_distinct in [5, 50, 100, 200, 255] {
+        let num_rows = 100_000;
+        let schema = Schema::new(vec![Field::new("v", DataType::Utf8, false)]);
+
+        // Generate distinct string values
+        let distinct_vals: Vec<String> = (0..num_distinct)
+            .map(|i| format!("str_value_{:05}", i))
+            .collect();
+
+        let str_vals: Vec<&str> = (0..num_rows)
+            .map(|i| distinct_vals[i % num_distinct].as_str())
+            .collect();
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(StringArray::from(str_vals.clone()))],
+        )
+        .unwrap();
+
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+
+        let result = read_all(&data);
+        let out_vals = concat_column_string(&result, "v");
+        assert_eq!(out_vals.len(), num_rows);
+        for (i, v) in out_vals.iter().enumerate() {
+            assert_eq!(
+                v.as_deref(),
+                Some(str_vals[i]),
+                "mismatch at row {} for cardinality {}",
+                i,
+                num_distinct
+            );
+        }
+        println!(
+            "  string cardinality {}: file size = {} bytes, roundtrip OK",
+            num_distinct,
+            data.len()
+        );
+    }
+
+    println!("test_dict_encoding_string_cardinality: PASSED");
+}
+
+// 4. test_dict_budget_exceeded
+#[test]
+fn test_dict_budget_exceeded() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Utf8, false)]);
+
+    // Create strings that are each 120+ bytes, with enough distinct values
+    // to blow past max_dict_total_bytes=1024
+    let num_distinct = 20; // 20 * 120 = 2400 bytes > 1024
+    let num_rows = 10_000;
+
+    let distinct_vals: Vec<String> = (0..num_distinct)
+        .map(|i| format!("long_string_value_{:0>100}", i))
+        .collect();
+    let str_vals: Vec<&str> = (0..num_rows)
+        .map(|i| distinct_vals[i % num_distinct].as_str())
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(StringArray::from(str_vals.clone()))],
+    )
+    .unwrap();
+
+    let data = write_file(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 1,
+            max_dict_total_bytes: 1024,
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    // Verify the data still roundtrips correctly (fallback to plain)
+    let result = read_all(&data);
+    let out_vals = concat_column_string(&result, "v");
+    assert_eq!(out_vals.len(), num_rows);
+    for (i, v) in out_vals.iter().enumerate() {
+        assert_eq!(v.as_deref(), Some(str_vals[i]), "mismatch at row {}", i);
+    }
+
+    println!(
+        "test_dict_budget_exceeded: PASSED - file size = {} bytes, data roundtrips",
+        data.len()
+    );
+}
+
+// 5. test_all_null_encoding
+#[test]
+fn test_all_null_encoding() {
+    let num_rows = 100_000;
+
+    // Boolean all null
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Boolean, true)]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(BooleanArray::from(vec![None::<bool>; num_rows]))],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+        // All values should be null
+        for b in &result {
+            let idx = b.schema().index_of("v").unwrap();
+            let arr = b
+                .column(idx)
+                .as_any()
+                .downcast_ref::<BooleanArray>()
+                .unwrap();
+            assert_eq!(arr.null_count(), arr.len());
+        }
+    }
+
+    // Int32 all null
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Int32, true)]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(Int32Array::from(vec![None::<i32>; num_rows]))],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+        for b in &result {
+            let idx = b.schema().index_of("v").unwrap();
+            let arr = b.column(idx).as_any().downcast_ref::<Int32Array>().unwrap();
+            assert_eq!(arr.null_count(), arr.len());
+        }
+    }
+
+    // Int64 all null
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Int64, true)]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(Int64Array::from(vec![None::<i64>; num_rows]))],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+    }
+
+    // Float64 all null
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Float64, true)]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(Float64Array::from(vec![None::<f64>; num_rows]))],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+    }
+
+    // Utf8 all null
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Utf8, true)]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(StringArray::from(vec![None::<&str>; num_rows]))],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+    }
+
+    // Binary all null
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Binary, true)]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(BinaryArray::from(vec![None::<&[u8]>; num_rows]))],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+    }
+
+    // Date32 all null
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Date32, true)]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(Date32Array::from(vec![None::<i32>; num_rows]))],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+    }
+
+    // Decimal128 all null
+    {
+        let schema = Schema::new(vec![Field::new("v", DataType::Decimal128(10, 2), true)]);
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(
+                Decimal128Array::from(vec![None::<i128>; num_rows])
+                    .with_precision_and_scale(10, 2)
+                    .unwrap(),
+            )],
+        )
+        .unwrap();
+        let data = write_file(
+            &schema,
+            &[batch],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        );
+        let result = read_all(&data);
+        assert_eq!(total_rows(&result), num_rows);
+    }
+
+    println!("test_all_null_encoding: PASSED - all types with all null values roundtrip");
+}
+
+// 6. test_encoding_mixed_in_same_file
+#[test]
+fn test_encoding_mixed_in_same_file() {
+    let num_rows = 200_000;
+    let schema = Schema::new(vec![
+        Field::new("const_col", DataType::Int64, false), // CONST: single value
+        Field::new("dict_col", DataType::Utf8, false),   // DICT: few distinct values
+        Field::new("plain_col", DataType::Int64, false), // PLAIN: all unique values
+        Field::new("null_col", DataType::Float64, true), // ALL_NULL
+    ]);
+
+    let batch_size = 50_000;
+    let mut batches = Vec::new();
+
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+
+        let const_vals: Vec<i64> = vec![42i64; count];
+        let dict_vals: Vec<&str> = (0..count)
+            .map(|i| match (batch_start + i) % 5 {
+                0 => "alpha",
+                1 => "beta",
+                2 => "gamma",
+                3 => "delta",
+                _ => "epsilon",
+            })
+            .collect();
+        let plain_vals: Vec<i64> = (batch_start..batch_start + count)
+            .map(|i| i as i64)
+            .collect();
+        let null_vals: Vec<Option<f64>> = vec![None; count];
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int64Array::from(const_vals)),
+                Arc::new(StringArray::from(dict_vals)),
+                Arc::new(Int64Array::from(plain_vals)),
+                Arc::new(Float64Array::from(null_vals)),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    let data = write_file(
+        &schema,
+        &batches,
+        WriterOptions {
+            num_buckets: 1,
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    let result = read_all(&data);
+    assert_batches_equal(&batches, &result);
+
+    println!(
+        "test_encoding_mixed_in_same_file: PASSED - file size = {} bytes, {} row groups",
+        data.len(),
+        result.len()
+    );
+}
+
+// ======================== Compression Tests ========================
+
+// 7. test_no_compression_roundtrip_all_types
+#[test]
+fn test_no_compression_roundtrip_all_types() {
+    let num_rows = 200_000;
+    let batch_size = 50_000;
+    let schema = Schema::new(vec![
+        Field::new("bool_col", DataType::Boolean, true),
+        Field::new("i8_col", DataType::Int8, true),
+        Field::new("i16_col", DataType::Int16, true),
+        Field::new("i32_col", DataType::Int32, true),
+        Field::new("i64_col", DataType::Int64, true),
+        Field::new("f32_col", DataType::Float32, true),
+        Field::new("f64_col", DataType::Float64, true),
+        Field::new("str_col", DataType::Utf8, true),
+        Field::new("bin_col", DataType::Binary, true),
+        Field::new("date_col", DataType::Date32, true),
+        Field::new("time_col", DataType::Time32(TimeUnit::Millisecond), true),
+        Field::new("dec_col", DataType::Decimal128(10, 2), true),
+    ]);
+
+    let mut batches = Vec::new();
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+
+        let bools: Vec<Option<bool>> = (0..count)
+            .map(|i| {
+                if (batch_start + i) % 10 == 0 {
+                    None
+                } else {
+                    Some((batch_start + i) % 2 == 0)
+                }
+            })
+            .collect();
+        let i8s: Vec<Option<i8>> = (0..count)
+            .map(|i| {
+                if (batch_start + i) % 15 == 0 {
+                    None
+                } else {
+                    Some(((batch_start + i) % 256) as i8)
+                }
+            })
+            .collect();
+        let i16s: Vec<Option<i16>> = (0..count)
+            .map(|i| {
+                if (batch_start + i) % 12 == 0 {
+                    None
+                } else {
+                    Some(((batch_start + i) % 30000) as i16)
+                }
+            })
+            .collect();
+        let i32s: Vec<Option<i32>> = (0..count)
+            .map(|i| {
+                if (batch_start + i) % 9 == 0 {
+                    None
+                } else {
+                    Some((batch_start + i) as i32 * 3)
+                }
+            })
+            .collect();
+        let i64s: Vec<Option<i64>> = (0..count)
+            .map(|i| {
+                if (batch_start + i) % 8 == 0 {
+                    None
+                } else {
+                    Some((batch_start + i) as i64 * 1_000_000)
+                }
+            })
+            .collect();
+        let f32s: Vec<Option<f32>> = (0..count)
+            .map(|i| {
+                if (batch_start + i) % 14 == 0 {
+                    None
+                } else {
+                    Some((batch_start + i) as f32 * 0.1)
+                }
+            })
+            .collect();
+        let f64s: Vec<Option<f64>> = (0..count)
+            .map(|i| {
+                if (batch_start + i) % 11 == 0 {
+                    None
+                } else {
+                    Some((batch_start + i) as f64 * 3.14159)
+                }
+            })
+            .collect();
+        let strings: Vec<Option<String>> = (0..count)
+            .map(|i| {
+                if (batch_start + i) % 6 == 0 {
+                    None
+                } else {
+                    Some(format!("row_{:08}", batch_start + i))
+                }
+            })
+            .collect();
+        let str_refs: Vec<Option<&str>> = strings.iter().map(|s| s.as_deref()).collect();
+        let binaries: Vec<Option<Vec<u8>>> = (0..count)
+            .map(|i| {
+                if (batch_start + i) % 7 == 0 {
+                    None
+                } else {
+                    let len = (batch_start + i) % 32 + 1;
+                    Some(
+                        (0..len)
+                            .map(|j| ((batch_start + i + j) % 256) as u8)
+                            .collect(),
+                    )
+                }
+            })
+            .collect();
+        let bin_refs: Vec<Option<&[u8]>> = binaries
+            .iter()
+            .map(|b| b.as_ref().map(|v| v.as_slice()))
+            .collect();
+        let dates: Vec<Option<i32>> = (0..count)
+            .map(|i| {
+                if (batch_start + i) % 20 == 0 {
+                    None
+                } else {
+                    Some(18000 + (batch_start + i) as i32 % 3650)
+                }
+            })
+            .collect();
+        let times: Vec<Option<i32>> = (0..count)
+            .map(|i| {
+                if (batch_start + i) % 25 == 0 {
+                    None
+                } else {
+                    Some(((batch_start + i) as i32 % 86_400_000).abs())
+                }
+            })
+            .collect();
+        let decimals: Vec<Option<i128>> = (0..count)
+            .map(|i| {
+                if (batch_start + i) % 13 == 0 {
+                    None
+                } else {
+                    Some((batch_start + i) as i128 * 100 + 99)
+                }
+            })
+            .collect();
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(BooleanArray::from(bools)),
+                Arc::new(Int8Array::from(i8s)),
+                Arc::new(Int16Array::from(i16s)),
+                Arc::new(Int32Array::from(i32s)),
+                Arc::new(Int64Array::from(i64s)),
+                Arc::new(Float32Array::from(f32s)),
+                Arc::new(Float64Array::from(f64s)),
+                Arc::new(StringArray::from(str_refs)),
+                Arc::new(BinaryArray::from(bin_refs)),
+                Arc::new(Date32Array::from(dates)),
+                Arc::new(Time32MillisecondArray::from(times)),
+                Arc::new(
+                    Decimal128Array::from(decimals)
+                        .with_precision_and_scale(10, 2)
+                        .unwrap(),
+                ),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    let data = write_file(
+        &schema,
+        &batches,
+        WriterOptions {
+            num_buckets: 4,
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    let result = read_all(&data);
+    assert_batches_equal(&batches, &result);
+
+    println!(
+        "test_no_compression_roundtrip_all_types: PASSED - file size = {} bytes",
+        data.len()
+    );
+}
+
+// 8. test_zstd_compression_levels
+#[test]
+fn test_zstd_compression_levels() {
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("data", DataType::Utf8, false),
+    ]);
+
+    let num_rows = 50_000;
+    let ids: Vec<i64> = (0..num_rows as i64).collect();
+    let strs: Vec<String> = (0..num_rows)
+        .map(|i| format!("record_{:08}_padding_{}", i, "x".repeat(20)))
+        .collect();
+    let str_refs: Vec<&str> = strs.iter().map(|s| s.as_str()).collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int64Array::from(ids.clone())),
+            Arc::new(StringArray::from(str_refs)),
+        ],
+    )
+    .unwrap();
+
+    let levels = [1, 3, 7, 15, 22];
+    let mut sizes = Vec::new();
+
+    for &level in &levels {
+        let data = write_file(
+            &schema,
+            &[batch.clone()],
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_ZSTD,
+                zstd_level: level,
+                ..Default::default()
+            },
+        );
+
+        // Verify roundtrip
+        let result = read_all(&data);
+        let out_ids = concat_column_i64(&result, "id");
+        assert_eq!(out_ids.len(), num_rows);
+        for (i, v) in out_ids.iter().enumerate() {
+            assert_eq!(
+                *v,
+                Some(ids[i]),
+                "id mismatch at row {} for level {}",
+                i,
+                level
+            );
+        }
+
+        sizes.push((level, data.len()));
+        println!("  zstd level {}: file size = {} bytes", level, data.len());
+    }
+
+    // Higher levels should generally produce smaller or equal files
+    // (not strictly guaranteed but usually true for this kind of data)
+    println!("test_zstd_compression_levels: PASSED - all levels roundtrip correctly");
+}
+
+// 9. test_compression_highly_compressible
+#[test]
+fn test_compression_highly_compressible() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Int64, false)]);
+
+    let num_rows = 200_000;
+    let vals: Vec<i64> = (0..num_rows as i64).collect();
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int64Array::from(vals.clone()))],
+    )
+    .unwrap();
+
+    let data_none = write_file(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    let data_zstd = write_file(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 1,
+            compression: spec::COMPRESSION_ZSTD,
+            ..Default::default()
+        },
+    );
+
+    // Verify both roundtrip
+    let result_none = read_all(&data_none);
+    let result_zstd = read_all(&data_zstd);
+    assert_eq!(total_rows(&result_none), num_rows);
+    assert_eq!(total_rows(&result_zstd), num_rows);
+
+    let ratio = data_none.len() as f64 / data_zstd.len() as f64;
+    println!(
+        "  NONE: {} bytes, ZSTD: {} bytes, ratio: {:.2}x",
+        data_none.len(),
+        data_zstd.len(),
+        ratio
+    );
+    assert!(
+        ratio > 2.0,
+        "expected compression ratio > 2x for sequential integers, got {:.2}x",
+        ratio
+    );
+
+    println!("test_compression_highly_compressible: PASSED");
+}
+
+// 10. test_compression_incompressible
+#[test]
+fn test_compression_incompressible() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Binary, false)]);
+
+    let num_rows = 10_000;
+    let bin_vals: Vec<Vec<u8>> = (0..num_rows)
+        .map(|i| (0..64).map(|j| simple_hash(42, i * 64 + j) as u8).collect())
+        .collect();
+    let bin_refs: Vec<&[u8]> = bin_vals.iter().map(|v| v.as_slice()).collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(BinaryArray::from(bin_refs))],
+    )
+    .unwrap();
+
+    let data_none = write_file(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    let data_zstd = write_file(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 1,
+            compression: spec::COMPRESSION_ZSTD,
+            ..Default::default()
+        },
+    );
+
+    // Verify both roundtrip
+    let result_none = read_all(&data_none);
+    let result_zstd = read_all(&data_zstd);
+    assert_eq!(total_rows(&result_none), num_rows);
+    assert_eq!(total_rows(&result_zstd), num_rows);
+
+    // ZSTD should not dramatically inflate random data
+    // Allow up to 10% overhead
+    let max_allowed = (data_none.len() as f64 * 1.10) as usize;
+    assert!(
+        data_zstd.len() <= max_allowed,
+        "ZSTD inflated random data too much: NONE={}, ZSTD={}, max_allowed={}",
+        data_none.len(),
+        data_zstd.len(),
+        max_allowed
+    );
+
+    println!(
+        "test_compression_incompressible: PASSED - NONE: {} bytes, ZSTD: {} bytes",
+        data_none.len(),
+        data_zstd.len()
+    );
+}
+
+// 11. test_compression_empty_strings
+#[test]
+fn test_compression_empty_strings() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Utf8, false)]);
+
+    let num_rows = 100_000;
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(StringArray::from(vec![""; num_rows]))],
+    )
+    .unwrap();
+
+    let data = write_file(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 1,
+            compression: spec::COMPRESSION_ZSTD,
+            ..Default::default()
+        },
+    );
+
+    let result = read_all(&data);
+    assert_eq!(total_rows(&result), num_rows);
+
+    // Verify all empty strings come back
+    let out_vals = concat_column_string(&result, "v");
+    for (i, v) in out_vals.iter().enumerate() {
+        assert_eq!(v.as_deref(), Some(""), "row {} not empty string", i);
+    }
+
+    println!(
+        "test_compression_empty_strings: PASSED - file size = {} bytes",
+        data.len()
+    );
+}
+
+// ======================== Projection Tests ========================
+
+// 12. test_projection_single_column_from_100
+#[test]
+fn test_projection_single_column_from_100() {
+    let num_cols = 100;
+    let num_rows = 10_000;
+
+    let fields: Vec<Field> = (0..num_cols)
+        .map(|i| Field::new(format!("col_{:04}", i), DataType::Int32, false))
+        .collect();
+    let schema = Schema::new(fields);
+
+    let mut arrays: Vec<Arc<dyn Array>> = Vec::new();
+    for col in 0..num_cols {
+        let vals: Vec<i32> = (0..num_rows).map(|i| (col * 10000 + i) as i32).collect();
+        arrays.push(Arc::new(Int32Array::from(vals)));
+    }
+
+    let batch = RecordBatch::try_new(Arc::new(schema.clone()), arrays).unwrap();
+    let file_data = write_file(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 10,
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    // Read only column 50
+    let target_col = 50;
+    let input = ByteArrayInputFile {
+        data: file_data.clone(),
+    };
+    let reader = MosaicReader::new(input, file_data.len() as u64).unwrap();
+
+    let mut all_vals: Vec<i32> = Vec::new();
+    for rg in 0..reader.num_row_groups() {
+        let mut rg_reader = reader
+            .row_group_reader_projected(rg, &[target_col])
+            .unwrap();
+        let result = rg_reader.read_columns().unwrap();
+        assert_eq!(result.num_columns(), 1);
+        let col_name = format!("col_{:04}", target_col);
+        let idx = result.schema().index_of(&col_name).unwrap();
+        let arr = result
+            .column(idx)
+            .as_any()
+            .downcast_ref::<Int32Array>()
+            .unwrap();
+        all_vals.extend(arr.values().iter().copied());
+    }
+
+    let expected: Vec<i32> = (0..num_rows)
+        .map(|i| (target_col * 10000 + i) as i32)
+        .collect();
+    assert_eq!(all_vals, expected);
+
+    println!("test_projection_single_column_from_100: PASSED");
+}
+
+// 13. test_projection_last_column
+#[test]
+fn test_projection_last_column() {
+    let num_cols = 50;
+    let num_rows = 10_000;
+
+    let fields: Vec<Field> = (0..num_cols)
+        .map(|i| Field::new(format!("col_{:04}", i), DataType::Int64, false))
+        .collect();
+    let schema = Schema::new(fields);
+
+    let mut arrays: Vec<Arc<dyn Array>> = Vec::new();
+    for col in 0..num_cols {
+        let vals: Vec<i64> = (0..num_rows).map(|i| (col * 100000 + i) as i64).collect();
+        arrays.push(Arc::new(Int64Array::from(vals)));
+    }
+
+    let batch = RecordBatch::try_new(Arc::new(schema.clone()), arrays).unwrap();
+    let file_data = write_file(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 5,
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    // Read only the last column
+    let last_col = num_cols - 1;
+    let input = ByteArrayInputFile {
+        data: file_data.clone(),
+    };
+    let reader = MosaicReader::new(input, file_data.len() as u64).unwrap();
+
+    let mut all_vals: Vec<i64> = Vec::new();
+    for rg in 0..reader.num_row_groups() {
+        let mut rg_reader = reader.row_group_reader_projected(rg, &[last_col]).unwrap();
+        let result = rg_reader.read_columns().unwrap();
+        assert_eq!(result.num_columns(), 1);
+        let col_name = format!("col_{:04}", last_col);
+        let idx = result.schema().index_of(&col_name).unwrap();
+        let arr = result
+            .column(idx)
+            .as_any()
+            .downcast_ref::<Int64Array>()
+            .unwrap();
+        all_vals.extend(arr.values().iter().copied());
+    }
+
+    let expected: Vec<i64> = (0..num_rows)
+        .map(|i| (last_col * 100000 + i) as i64)
+        .collect();
+    assert_eq!(all_vals, expected);
+
+    println!("test_projection_last_column: PASSED");
+}
+
+// 14. test_projection_first_column
+#[test]
+fn test_projection_first_column() {
+    let num_cols = 50;
+    let num_rows = 10_000;
+
+    let fields: Vec<Field> = (0..num_cols)
+        .map(|i| Field::new(format!("col_{:04}", i), DataType::Int64, false))
+        .collect();
+    let schema = Schema::new(fields);
+
+    let mut arrays: Vec<Arc<dyn Array>> = Vec::new();
+    for col in 0..num_cols {
+        let vals: Vec<i64> = (0..num_rows).map(|i| (col * 100000 + i) as i64).collect();
+        arrays.push(Arc::new(Int64Array::from(vals)));
+    }
+
+    let batch = RecordBatch::try_new(Arc::new(schema.clone()), arrays).unwrap();
+    let file_data = write_file(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 5,
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    // Read only the first column
+    let input = ByteArrayInputFile {
+        data: file_data.clone(),
+    };
+    let reader = MosaicReader::new(input, file_data.len() as u64).unwrap();
+
+    let mut all_vals: Vec<i64> = Vec::new();
+    for rg in 0..reader.num_row_groups() {
+        let mut rg_reader = reader.row_group_reader_projected(rg, &[0]).unwrap();
+        let result = rg_reader.read_columns().unwrap();
+        assert_eq!(result.num_columns(), 1);
+        let col_name = "col_0000";
+        let idx = result.schema().index_of(col_name).unwrap();
+        let arr = result
+            .column(idx)
+            .as_any()
+            .downcast_ref::<Int64Array>()
+            .unwrap();
+        all_vals.extend(arr.values().iter().copied());
+    }
+
+    let expected: Vec<i64> = (0..num_rows).map(|i| i as i64).collect();
+    assert_eq!(all_vals, expected);
+
+    println!("test_projection_first_column: PASSED");
+}
+
+// 15. test_projection_reverse_order
+#[test]
+fn test_projection_reverse_order() {
+    let schema = Schema::new(vec![
+        Field::new("a", DataType::Int32, false),
+        Field::new("b", DataType::Int64, false),
+        Field::new("c", DataType::Utf8, false),
+        Field::new("d", DataType::Float64, false),
+    ]);
+
+    let num_rows = 10_000;
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int32Array::from((0..num_rows as i32).collect::<Vec<_>>())),
+            Arc::new(Int64Array::from(
+                (0..num_rows as i64).map(|i| i * 100).collect::<Vec<_>>(),
+            )),
+            Arc::new(StringArray::from(
+                (0..num_rows)
+                    .map(|i| format!("s_{}", i))
+                    .collect::<Vec<_>>(),
+            )),
+            Arc::new(Float64Array::from(
+                (0..num_rows).map(|i| i as f64 * 0.5).collect::<Vec<_>>(),
+            )),
+        ],
+    )
+    .unwrap();
+
+    let file_data = write_file(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 4,
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    // Project in reverse order [3, 2, 1, 0]
+    let input = ByteArrayInputFile {
+        data: file_data.clone(),
+    };
+    let reader = MosaicReader::new(input, file_data.len() as u64).unwrap();
+
+    for rg in 0..reader.num_row_groups() {
+        let mut rg_reader = reader
+            .row_group_reader_projected(rg, &[3, 2, 1, 0])
+            .unwrap();
+        let result = rg_reader.read_columns().unwrap();
+        assert_eq!(result.num_columns(), 4);
+
+        // All four columns should be present
+        assert!(result.schema().index_of("a").is_ok());
+        assert!(result.schema().index_of("b").is_ok());
+        assert!(result.schema().index_of("c").is_ok());
+        assert!(result.schema().index_of("d").is_ok());
+    }
+
+    println!("test_projection_reverse_order: PASSED");
+}
+
+// 16. test_projection_same_column_twice
+#[test]
+fn test_projection_same_column_twice() {
+    let schema = Schema::new(vec![
+        Field::new("a", DataType::Int32, false),
+        Field::new("b", DataType::Int64, false),
+    ]);
+
+    let num_rows = 5_000;
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int32Array::from((0..num_rows as i32).collect::<Vec<_>>())),
+            Arc::new(Int64Array::from((0..num_rows as i64).collect::<Vec<_>>())),
+        ],
+    )
+    .unwrap();
+
+    let file_data = write_file(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 1,
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    let input = ByteArrayInputFile {
+        data: file_data.clone(),
+    };
+    let reader = MosaicReader::new(input, file_data.len() as u64).unwrap();
+
+    // Project [0, 0] - same column twice. The implementation marks projected[0]=true
+    // which deduplicates, so we get the column once. This is implementation-defined behavior.
+    for rg in 0..reader.num_row_groups() {
+        let rg_result = reader.row_group_reader_projected(rg, &[0, 0]);
+        match rg_result {
+            Ok(mut rg_reader) => {
+                let result = rg_reader.read_columns().unwrap();
+                // Should at least contain column "a"
+                assert!(result.schema().index_of("a").is_ok());
+                assert!(result.num_rows() > 0);
+            }
+            Err(_) => {
+                // Some implementations may reject duplicate indices
+                println!("  duplicate projection indices rejected (acceptable)");
+            }
+        }
+    }
+
+    println!("test_projection_same_column_twice: PASSED");
+}
+
+// 17. test_projection_by_name
+#[test]
+fn test_projection_by_name() {
+    let schema = Schema::new(vec![
+        Field::new("alpha", DataType::Int32, false),
+        Field::new("beta", DataType::Utf8, false),
+        Field::new("gamma", DataType::Float64, false),
+        Field::new("delta", DataType::Int64, false),
+    ]);
+
+    let num_rows = 10_000;
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int32Array::from((0..num_rows as i32).collect::<Vec<_>>())),
+            Arc::new(StringArray::from(
+                (0..num_rows)
+                    .map(|i| format!("val_{}", i))
+                    .collect::<Vec<_>>(),
+            )),
+            Arc::new(Float64Array::from(
+                (0..num_rows).map(|i| i as f64).collect::<Vec<_>>(),
+            )),
+            Arc::new(Int64Array::from((0..num_rows as i64).collect::<Vec<_>>())),
+        ],
+    )
+    .unwrap();
+
+    let file_data = write_file(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 4,
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    let input = ByteArrayInputFile {
+        data: file_data.clone(),
+    };
+    let reader = MosaicReader::new(input, file_data.len() as u64).unwrap();
+
+    // Project by names: only "beta" and "delta"
+    for rg in 0..reader.num_row_groups() {
+        let mut rg_reader = reader
+            .row_group_reader_by_names(rg, &["beta", "delta"])
+            .unwrap();
+        let result = rg_reader.read_columns().unwrap();
+        assert_eq!(result.num_columns(), 2);
+        assert!(result.schema().index_of("beta").is_ok());
+        assert!(result.schema().index_of("delta").is_ok());
+    }
+
+    println!("test_projection_by_name: PASSED");
+}
+
+// 18. test_projection_with_all_encodings
+#[test]
+fn test_projection_with_all_encodings() {
+    let num_rows = 50_000;
+    let schema = Schema::new(vec![
+        Field::new("const_col", DataType::Int32, false), // CONST
+        Field::new("dict_col", DataType::Utf8, false),   // DICT
+        Field::new("null_col", DataType::Float64, true), // ALL_NULL
+        Field::new("plain_col", DataType::Int64, false), // PLAIN
+    ]);
+
+    let const_vals: Vec<i32> = vec![42; num_rows];
+    let dict_vals: Vec<&str> = (0..num_rows)
+        .map(|i| match i % 3 {
+            0 => "foo",
+            1 => "bar",
+            _ => "baz",
+        })
+        .collect();
+    let null_vals: Vec<Option<f64>> = vec![None; num_rows];
+    let plain_vals: Vec<i64> = (0..num_rows as i64).collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int32Array::from(const_vals)),
+            Arc::new(StringArray::from(dict_vals)),
+            Arc::new(Float64Array::from(null_vals)),
+            Arc::new(Int64Array::from(plain_vals.clone())),
+        ],
+    )
+    .unwrap();
+
+    let file_data = write_file(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 1,
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    let input = ByteArrayInputFile {
+        data: file_data.clone(),
+    };
+    let reader = MosaicReader::new(input, file_data.len() as u64).unwrap();
+
+    // Project only CONST column
+    for rg in 0..reader.num_row_groups() {
+        let mut rg_reader = reader
+            .row_group_reader_by_names(rg, &["const_col"])
+            .unwrap();
+        let result = rg_reader.read_columns().unwrap();
+        assert_eq!(result.num_columns(), 1);
+        let idx = result.schema().index_of("const_col").unwrap();
+        let arr = result
+            .column(idx)
+            .as_any()
+            .downcast_ref::<Int32Array>()
+            .unwrap();
+        for i in 0..arr.len() {
+            assert_eq!(arr.value(i), 42);
+        }
+    }
+
+    // Project only PLAIN column
+    let input2 = ByteArrayInputFile {
+        data: file_data.clone(),
+    };
+    let reader2 = MosaicReader::new(input2, file_data.len() as u64).unwrap();
+    for rg in 0..reader2.num_row_groups() {
+        let mut rg_reader = reader2
+            .row_group_reader_by_names(rg, &["plain_col"])
+            .unwrap();
+        let result = rg_reader.read_columns().unwrap();
+        assert_eq!(result.num_columns(), 1);
+    }
+
+    // Project CONST + ALL_NULL
+    let input3 = ByteArrayInputFile {
+        data: file_data.clone(),
+    };
+    let reader3 = MosaicReader::new(input3, file_data.len() as u64).unwrap();
+    for rg in 0..reader3.num_row_groups() {
+        let mut rg_reader = reader3
+            .row_group_reader_by_names(rg, &["const_col", "null_col"])
+            .unwrap();
+        let result = rg_reader.read_columns().unwrap();
+        assert_eq!(result.num_columns(), 2);
+    }
+
+    println!("test_projection_with_all_encodings: PASSED");
+}
+
+// 19. test_projection_across_multiple_row_groups
+#[test]
+fn test_projection_across_multiple_row_groups() {
+    let schema = Schema::new(vec![
+        Field::new("a", DataType::Int32, false),
+        Field::new("b", DataType::Utf8, false),
+        Field::new("c", DataType::Int64, false),
+    ]);
+
+    let num_rows = 100_000;
+    let batch_size = 1000;
+    let mut batches = Vec::new();
+
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+
+        let a_vals: Vec<i32> = (batch_start..batch_start + count)
+            .map(|i| i as i32)
+            .collect();
+        let b_vals: Vec<String> = (batch_start..batch_start + count)
+            .map(|i| format!("s_{:06}", i))
+            .collect();
+        let b_refs: Vec<&str> = b_vals.iter().map(|s| s.as_str()).collect();
+        let c_vals: Vec<i64> = (batch_start..batch_start + count)
+            .map(|i| i as i64 * 1000)
+            .collect();
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int32Array::from(a_vals)),
+                Arc::new(StringArray::from(b_refs)),
+                Arc::new(Int64Array::from(c_vals)),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    // Write with small row group size to force many row groups
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 32 * 1024, // 32KB
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    for batch in &batches {
+        writer.write_batch(batch).unwrap();
+    }
+    writer.close().unwrap();
+    let file_data = writer.output().buf.clone();
+
+    let input = ByteArrayInputFile {
+        data: file_data.clone(),
+    };
+    let reader = MosaicReader::new(input, file_data.len() as u64).unwrap();
+
+    assert!(
+        reader.num_row_groups() > 1,
+        "expected multiple row groups, got {}",
+        reader.num_row_groups()
+    );
+
+    // Project different columns for different row groups
+    let mut a_total = 0usize;
+    let mut c_total = 0usize;
+
+    for rg in 0..reader.num_row_groups() {
+        if rg % 2 == 0 {
+            // Even row groups: project "a"
+            let mut rg_reader = reader.row_group_reader_by_names(rg, &["a"]).unwrap();
+            let result = rg_reader.read_columns().unwrap();
+            assert_eq!(result.num_columns(), 1);
+            assert!(result.schema().index_of("a").is_ok());
+            a_total += result.num_rows();
+        } else {
+            // Odd row groups: project "c"
+            let mut rg_reader = reader.row_group_reader_by_names(rg, &["c"]).unwrap();
+            let result = rg_reader.read_columns().unwrap();
+            assert_eq!(result.num_columns(), 1);
+            assert!(result.schema().index_of("c").is_ok());
+            c_total += result.num_rows();
+        }
+    }
+
+    assert_eq!(a_total + c_total, num_rows);
+    println!(
+        "test_projection_across_multiple_row_groups: PASSED - {} row groups, a_rows={}, c_rows={}",
+        reader.num_row_groups(),
+        a_total,
+        c_total
+    );
+}
+
+// ======================== Writer Options Interactions ========================
+
+// 20. test_bucket_count_1
+#[test]
+fn test_bucket_count_1() {
+    let num_rows = 200_000;
+    let schema = Schema::new(vec![
+        Field::new("i32_col", DataType::Int32, true),
+        Field::new("i64_col", DataType::Int64, false),
+        Field::new("str_col", DataType::Utf8, true),
+        Field::new("f64_col", DataType::Float64, false),
+    ]);
+
+    let batch_size = 50_000;
+    let mut batches = Vec::new();
+
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+
+        let i32_vals: Vec<Option<i32>> = (0..count)
+            .map(|i| {
+                if (batch_start + i) % 7 == 0 {
+                    None
+                } else {
+                    Some((batch_start + i) as i32)
+                }
+            })
+            .collect();
+        let i64_vals: Vec<i64> = (0..count).map(|i| (batch_start + i) as i64 * 100).collect();
+        let str_vals: Vec<Option<String>> = (0..count)
+            .map(|i| {
+                if (batch_start + i) % 5 == 0 {
+                    None
+                } else {
+                    Some(format!("val_{}", (batch_start + i) % 50))
+                }
+            })
+            .collect();
+        let str_refs: Vec<Option<&str>> = str_vals.iter().map(|s| s.as_deref()).collect();
+        let f64_vals: Vec<f64> = (0..count)
+            .map(|i| (batch_start + i) as f64 * 0.01)
+            .collect();
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int32Array::from(i32_vals)),
+                Arc::new(Int64Array::from(i64_vals)),
+                Arc::new(StringArray::from(str_refs)),
+                Arc::new(Float64Array::from(f64_vals)),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    let data = write_file(
+        &schema,
+        &batches,
+        WriterOptions {
+            num_buckets: 1,
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    let input = ByteArrayInputFile { data: data.clone() };
+    let reader = MosaicReader::new(input, data.len() as u64).unwrap();
+    assert_eq!(reader.schema().num_buckets, 1);
+
+    let result = read_all(&data);
+    assert_batches_equal(&batches, &result);
+
+    println!(
+        "test_bucket_count_1: PASSED - file size = {} bytes",
+        data.len()
+    );
+}
+
+// 21. test_bucket_count_equals_columns
+#[test]
+fn test_bucket_count_equals_columns() {
+    let num_cols = 10;
+    let num_rows = 10_000;
+
+    let fields: Vec<Field> = (0..num_cols)
+        .map(|i| Field::new(format!("col_{:02}", i), DataType::Int32, false))
+        .collect();
+    let schema = Schema::new(fields);
+
+    let mut arrays: Vec<Arc<dyn Array>> = Vec::new();
+    for col in 0..num_cols {
+        let vals: Vec<i32> = (0..num_rows).map(|i| (col * 10000 + i) as i32).collect();
+        arrays.push(Arc::new(Int32Array::from(vals)));
+    }
+
+    let batch = RecordBatch::try_new(Arc::new(schema.clone()), arrays).unwrap();
+
+    let data = write_file(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: num_cols,
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    let input = ByteArrayInputFile { data: data.clone() };
+    let reader = MosaicReader::new(input, data.len() as u64).unwrap();
+    assert_eq!(reader.schema().num_buckets, num_cols);
+
+    let result = read_all(&data);
+    assert_batches_equal(&[batch], &result);
+
+    println!("test_bucket_count_equals_columns: PASSED");
+}
+
+// 22. test_bucket_count_exceeds_columns
+#[test]
+fn test_bucket_count_exceeds_columns() {
+    let num_cols = 10;
+    let num_rows = 5_000;
+
+    let fields: Vec<Field> = (0..num_cols)
+        .map(|i| Field::new(format!("col_{:02}", i), DataType::Int32, false))
+        .collect();
+    let schema = Schema::new(fields);
+
+    let mut arrays: Vec<Arc<dyn Array>> = Vec::new();
+    for col in 0..num_cols {
+        let vals: Vec<i32> = (0..num_rows).map(|i| (col * 10000 + i) as i32).collect();
+        arrays.push(Arc::new(Int32Array::from(vals)));
+    }
+
+    let batch = RecordBatch::try_new(Arc::new(schema.clone()), arrays).unwrap();
+
+    let data = write_file(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 500, // Way more than 10 columns
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    let input = ByteArrayInputFile { data: data.clone() };
+    let reader = MosaicReader::new(input, data.len() as u64).unwrap();
+    // Should be capped to num_cols
+    assert_eq!(
+        reader.schema().num_buckets,
+        num_cols,
+        "num_buckets should be capped to column count"
+    );
+
+    let result = read_all(&data);
+    assert_batches_equal(&[batch], &result);
+
+    println!("test_bucket_count_exceeds_columns: PASSED");
+}
+
+// 23. test_tiny_row_group_max
+#[test]
+fn test_tiny_row_group_max() {
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("data", DataType::Utf8, false),
+    ]);
+
+    let num_rows = 50_000;
+    let batch_size = 1_000;
+    let mut batches = Vec::new();
+
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+
+        let ids: Vec<i64> = (batch_start..batch_start + count)
+            .map(|i| i as i64)
+            .collect();
+        let strs: Vec<String> = (batch_start..batch_start + count)
+            .map(|i| format!("row_{:06}_pad", i))
+            .collect();
+        let str_refs: Vec<&str> = strs.iter().map(|s| s.as_str()).collect();
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int64Array::from(ids)),
+                Arc::new(StringArray::from(str_refs)),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 1024, // 1KB - very small
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    for batch in &batches {
+        writer.write_batch(batch).unwrap();
+    }
+    writer.close().unwrap();
+    let file_data = writer.output().buf.clone();
+
+    let input = ByteArrayInputFile {
+        data: file_data.clone(),
+    };
+    let reader = MosaicReader::new(input, file_data.len() as u64).unwrap();
+
+    // Should have many row groups due to tiny max size
+    println!(
+        "  tiny row group: {} row groups created",
+        reader.num_row_groups()
+    );
+    assert!(
+        reader.num_row_groups() > 5,
+        "expected many row groups with 1KB max, got {}",
+        reader.num_row_groups()
+    );
+
+    // Verify all data reads back
+    let result = read_all(&file_data);
+    assert_eq!(total_rows(&result), num_rows);
+
+    // Verify data correctness
+    let all_ids = concat_column_i64(&result, "id");
+    for (i, v) in all_ids.iter().enumerate() {
+        assert_eq!(*v, Some(i as i64), "id mismatch at row {}", i);
+    }
+
+    println!("test_tiny_row_group_max: PASSED");
+}
+
+// 24. test_huge_row_group_max
+#[test]
+fn test_huge_row_group_max() {
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("data", DataType::Utf8, false),
+    ]);
+
+    let num_rows = 50_000;
+    let ids: Vec<i64> = (0..num_rows as i64).collect();
+    let strs: Vec<String> = (0..num_rows).map(|i| format!("row_{:06}", i)).collect();
+    let str_refs: Vec<&str> = strs.iter().map(|s| s.as_str()).collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int64Array::from(ids)),
+            Arc::new(StringArray::from(str_refs)),
+        ],
+    )
+    .unwrap();
+
+    let data = write_file(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 1_073_741_824, // 1GB
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    let input = ByteArrayInputFile { data: data.clone() };
+    let reader = MosaicReader::new(input, data.len() as u64).unwrap();
+    assert_eq!(
+        reader.num_row_groups(),
+        1,
+        "expected single row group with 1GB max"
+    );
+
+    let result = read_all(&data);
+    assert_eq!(total_rows(&result), num_rows);
+
+    println!("test_huge_row_group_max: PASSED");
+}
+
+// 25. test_page_size_threshold_small
+#[test]
+fn test_page_size_threshold_small() {
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("data", DataType::Utf8, false),
+    ]);
+
+    let num_rows = 200_000;
+    let batch_size = 50_000;
+    let mut batches = Vec::new();
+
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+
+        let ids: Vec<i64> = (batch_start..batch_start + count)
+            .map(|i| i as i64)
+            .collect();
+        let strs: Vec<String> = (0..count)
+            .map(|i| {
+                let h = simple_hash(99, batch_start + i);
+                format!("data_{:08}_{}", batch_start + i, h % 1000)
+            })
+            .collect();
+        let str_refs: Vec<&str> = strs.iter().map(|s| s.as_str()).collect();
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int64Array::from(ids)),
+                Arc::new(StringArray::from(str_refs)),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    let data = write_file(
+        &schema,
+        &batches,
+        WriterOptions {
+            num_buckets: 1,
+            page_size_threshold: 256, // Very small, forces paged encoding
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    let result = read_all(&data);
+    assert_batches_equal(&batches, &result);
+
+    println!(
+        "test_page_size_threshold_small: PASSED - file size = {} bytes",
+        data.len()
+    );
+}
+
+// 26. test_page_size_threshold_large
+#[test]
+fn test_page_size_threshold_large() {
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("data", DataType::Utf8, false),
+    ]);
+
+    let num_rows = 50_000;
+    let ids: Vec<i64> = (0..num_rows as i64).collect();
+    let strs: Vec<String> = (0..num_rows).map(|i| format!("row_{:08}", i)).collect();
+    let str_refs: Vec<&str> = strs.iter().map(|s| s.as_str()).collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int64Array::from(ids)),
+            Arc::new(StringArray::from(str_refs)),
+        ],
+    )
+    .unwrap();
+
+    let data = write_file(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            num_buckets: 1,
+            page_size_threshold: 1_048_576, // 1MB - monolithic
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    let result = read_all(&data);
+    assert_batches_equal(&[batch], &result);
+
+    println!(
+        "test_page_size_threshold_large: PASSED - file size = {} bytes",
+        data.len()
+    );
+}
+
+// 27. test_stats_all_columns
+#[test]
+fn test_stats_all_columns() {
+    let schema = Schema::new(vec![
+        Field::new("i32_col", DataType::Int32, true),
+        Field::new("i64_col", DataType::Int64, true),
+        Field::new("f64_col", DataType::Float64, true),
+        Field::new("str_col", DataType::Utf8, true),
+        Field::new("date_col", DataType::Date32, true),
+    ]);
+
+    let num_rows = 10_000;
+    let i32_vals: Vec<Option<i32>> = (0..num_rows)
+        .map(|i| {
+            if i % 10 == 0 {
+                None
+            } else {
+                Some(i as i32 - 5000)
+            }
+        })
+        .collect();
+    let i64_vals: Vec<Option<i64>> = (0..num_rows)
+        .map(|i| {
+            if i % 8 == 0 {
+                None
+            } else {
+                Some(i as i64 * 100)
+            }
+        })
+        .collect();
+    let f64_vals: Vec<Option<f64>> = (0..num_rows)
+        .map(|i| {
+            if i % 12 == 0 {
+                None
+            } else {
+                Some(i as f64 * 0.01)
+            }
+        })
+        .collect();
+    let str_owned: Vec<Option<String>> = (0..num_rows)
+        .map(|i| {
+            if i % 5 == 0 {
+                None
+            } else {
+                Some(format!("val_{:04}", i % 100))
+            }
+        })
+        .collect();
+    let str_refs: Vec<Option<&str>> = str_owned.iter().map(|s| s.as_deref()).collect();
+    let date_vals: Vec<Option<i32>> = (0..num_rows)
+        .map(|i| {
+            if i % 15 == 0 {
+                None
+            } else {
+                Some(18000 + i as i32 % 365)
+            }
+        })
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int32Array::from(i32_vals)),
+            Arc::new(Int64Array::from(i64_vals)),
+            Arc::new(Float64Array::from(f64_vals)),
+            Arc::new(StringArray::from(str_refs)),
+            Arc::new(Date32Array::from(date_vals)),
+        ],
+    )
+    .unwrap();
+
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            stats_columns: vec![
+                "i32_col".to_string(),
+                "i64_col".to_string(),
+                "f64_col".to_string(),
+                "str_col".to_string(),
+                "date_col".to_string(),
+            ],
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    writer.write_batch(&batch).unwrap();
+    writer.close().unwrap();
+
+    let data = writer.output().buf.clone();
+    let input = ByteArrayInputFile { data: data.clone() };
+    let reader = MosaicReader::new(input, data.len() as u64).unwrap();
+
+    for rg in 0..reader.num_row_groups() {
+        let stats = reader.row_group_stats(rg).unwrap();
+        assert!(
+            !stats.is_empty(),
+            "rg={}: expected stats for all columns",
+            rg
+        );
+        println!("  rg={}: {} stats entries", rg, stats.len());
+
+        // Verify stats have sensible null counts
+        for stat in stats {
+            // null_count should be non-negative and less than total rows
+            let rg_rows = reader.row_group_num_rows(rg).unwrap();
+            assert!(
+                stat.null_count <= rg_rows,
+                "null_count {} exceeds row count {} for column {}",
+                stat.null_count,
+                rg_rows,
+                stat.column_index
+            );
+        }
+    }
+
+    println!("test_stats_all_columns: PASSED");
+}
+
+// 28. test_stats_subset_columns
+#[test]
+fn test_stats_subset_columns() {
+    let num_cols = 10;
+    let num_rows = 10_000;
+
+    let fields: Vec<Field> = (0..num_cols)
+        .map(|i| Field::new(format!("col_{:02}", i), DataType::Int32, true))
+        .collect();
+    let schema = Schema::new(fields);
+
+    let mut arrays: Vec<Arc<dyn Array>> = Vec::new();
+    for col in 0..num_cols {
+        let vals: Vec<Option<i32>> = (0..num_rows)
+            .map(|i| {
+                if i % (col + 3) == 0 {
+                    None
+                } else {
+                    Some((col * 10000 + i) as i32)
+                }
+            })
+            .collect();
+        arrays.push(Arc::new(Int32Array::from(vals)));
+    }
+
+    let batch = RecordBatch::try_new(Arc::new(schema.clone()), arrays).unwrap();
+
+    // Enable stats for only col_02 and col_07
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            stats_columns: vec!["col_02".to_string(), "col_07".to_string()],
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    writer.write_batch(&batch).unwrap();
+    writer.close().unwrap();
+
+    let data = writer.output().buf.clone();
+    let input = ByteArrayInputFile { data: data.clone() };
+    let reader = MosaicReader::new(input, data.len() as u64).unwrap();
+
+    for rg in 0..reader.num_row_groups() {
+        let stats = reader.row_group_stats(rg).unwrap();
+        // Should have stats for exactly 2 columns
+        assert_eq!(
+            stats.len(),
+            2,
+            "expected stats for 2 columns, got {}",
+            stats.len()
+        );
+    }
+
+    // Also verify the data roundtrips
+    let result = read_all(&data);
+    assert_eq!(total_rows(&result), num_rows);
+
+    println!("test_stats_subset_columns: PASSED");
+}
+
+// ======================== Row Group Boundary Tests ========================
+
+// 29. test_exact_row_group_boundary
+#[test]
+fn test_exact_row_group_boundary() {
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("data", DataType::Utf8, false),
+    ]);
+
+    // Write enough data to hit near the row group boundary.
+    // We use many small batches so the writer can split at batch boundaries.
+    let num_rows = 20_000;
+    let batch_size = 100;
+    let mut batches = Vec::new();
+
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+
+        let ids: Vec<i64> = (batch_start..batch_start + count)
+            .map(|i| i as i64)
+            .collect();
+        // Each row is about 20 bytes of string data
+        let strs: Vec<String> = (0..count)
+            .map(|i| format!("data_{:010}", batch_start + i))
+            .collect();
+        let str_refs: Vec<&str> = strs.iter().map(|s| s.as_str()).collect();
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int64Array::from(ids)),
+                Arc::new(StringArray::from(str_refs)),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    // Use row_group_max_size that creates a boundary somewhere in the middle
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024, // 16KB
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    for batch in &batches {
+        writer.write_batch(batch).unwrap();
+    }
+    writer.close().unwrap();
+    let file_data = writer.output().buf.clone();
+
+    let input = ByteArrayInputFile {
+        data: file_data.clone(),
+    };
+    let reader = MosaicReader::new(input, file_data.len() as u64).unwrap();
+
+    // Verify all data reads back in order
+    let result = read_all(&file_data);
+    let all_ids = concat_column_i64(&result, "id");
+    assert_eq!(all_ids.len(), num_rows);
+    for (i, v) in all_ids.iter().enumerate() {
+        assert_eq!(*v, Some(i as i64), "id mismatch at row {}", i);
+    }
+
+    println!(
+        "test_exact_row_group_boundary: PASSED - {} row groups",
+        reader.num_row_groups()
+    );
+}
+
+// 30. test_data_split_across_many_row_groups
+#[test]
+fn test_data_split_across_many_row_groups() {
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("value", DataType::Int32, false),
+        Field::new("label", DataType::Utf8, false),
+    ]);
+
+    let num_rows = 200_000;
+    let batch_size = 500;
+    let mut batches = Vec::new();
+
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+
+        let ids: Vec<i64> = (batch_start..batch_start + count)
+            .map(|i| i as i64)
+            .collect();
+        let vals: Vec<i32> = (0..count)
+            .map(|i| simple_hash(77, batch_start + i) as i32)
+            .collect();
+        let labels: Vec<String> = (0..count)
+            .map(|i| format!("label_{:08}_{}", batch_start + i, "x".repeat(30)))
+            .collect();
+        let label_refs: Vec<&str> = labels.iter().map(|s| s.as_str()).collect();
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int64Array::from(ids)),
+                Arc::new(Int32Array::from(vals)),
+                Arc::new(StringArray::from(label_refs)),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 8 * 1024, // 8KB - very small to force many row groups
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    for batch in &batches {
+        writer.write_batch(batch).unwrap();
+    }
+    writer.close().unwrap();
+    let file_data = writer.output().buf.clone();
+
+    let input = ByteArrayInputFile {
+        data: file_data.clone(),
+    };
+    let reader = MosaicReader::new(input, file_data.len() as u64).unwrap();
+
+    println!(
+        "  data split: {} row groups created",
+        reader.num_row_groups()
+    );
+    assert!(
+        reader.num_row_groups() >= 50,
+        "expected 50+ row groups with 8KB max, got {}",
+        reader.num_row_groups()
+    );
+
+    // Read all row groups and verify concatenated data
+    let result = read_all(&file_data);
+    let total = total_rows(&result);
+    assert_eq!(total, num_rows, "total rows mismatch");
+
+    // Verify IDs are consecutive
+    let all_ids = concat_column_i64(&result, "id");
+    for (i, v) in all_ids.iter().enumerate() {
+        assert_eq!(*v, Some(i as i64), "id mismatch at row {}", i);
+    }
+
+    // Verify values match expected hash
+    let all_vals = concat_column_i32(&result, "value");
+    for (i, v) in all_vals.iter().enumerate() {
+        let expected = simple_hash(77, i) as i32;
+        assert_eq!(*v, Some(expected), "value mismatch at row {}", i);
+    }
+
+    println!("test_data_split_across_many_row_groups: PASSED");
+}
diff --git a/core/tests/format_verification_test.rs b/core/tests/format_verification_test.rs
new file mode 100644
index 0000000..c276334
--- /dev/null
+++ b/core/tests/format_verification_test.rs
@@ -0,0 +1,1547 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Format verification tests: bit-level footer parsing, statistics accuracy,
+//! and estimated file size checks for the Mosaic columnar format.
+
+#![allow(
+    clippy::approx_constant,
+    clippy::unnecessary_cast,
+    clippy::cloned_ref_to_slice_refs,
+    clippy::needless_range_loop,
+    clippy::manual_is_multiple_of
+)]
+
+use std::io;
+use std::sync::Arc;
+
+use arrow_array::*;
+use arrow_schema::{DataType, Field, Schema};
+use paimon_mosaic_core::reader::{InputFile, MosaicReader, ReaderAccess};
+use paimon_mosaic_core::spec;
+use paimon_mosaic_core::writer::{MosaicWriter, OutputFile, WriterOptions};
+
+// ======================== Test Infrastructure ========================
+
+struct MemOutputFile {
+    pub buf: Vec<u8>,
+}
+
+impl MemOutputFile {
+    fn new() -> Self {
+        Self { buf: Vec::new() }
+    }
+}
+
+impl OutputFile for MemOutputFile {
+    fn write(&mut self, data: &[u8]) -> io::Result<()> {
+        self.buf.extend_from_slice(data);
+        Ok(())
+    }
+    fn flush(&mut self) -> io::Result<()> {
+        Ok(())
+    }
+    fn pos(&self) -> u64 {
+        self.buf.len() as u64
+    }
+}
+
+struct ByteArrayInputFile {
+    data: Vec<u8>,
+}
+
+impl InputFile for ByteArrayInputFile {
+    fn read_at(&self, offset: u64, buf: &mut [u8]) -> io::Result<()> {
+        let start = offset as usize;
+        let end = start + buf.len();
+        if end > self.data.len() {
+            return Err(io::Error::new(
+                io::ErrorKind::UnexpectedEof,
+                "read past end",
+            ));
+        }
+        buf.copy_from_slice(&self.data[start..end]);
+        Ok(())
+    }
+}
+
+fn read_be_u64(data: &[u8], offset: usize) -> u64 {
+    u64::from_be_bytes(data[offset..offset + 8].try_into().unwrap())
+}
+
+fn read_be_u32(data: &[u8], offset: usize) -> u32 {
+    u32::from_be_bytes(data[offset..offset + 4].try_into().unwrap())
+}
+
+/// Write a Mosaic file from a schema and batches, return the raw bytes.
+fn write_file(schema: &Schema, batches: &[RecordBatch], options: WriterOptions) -> Vec<u8> {
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(out, schema, options).unwrap();
+    for batch in batches {
+        writer.write_batch(batch).unwrap();
+    }
+    writer.close().unwrap();
+    writer.output().buf.clone()
+}
+
+/// Open a Mosaic reader over an in-memory byte buffer.
+fn open_reader(data: &[u8]) -> MosaicReader<ByteArrayInputFile> {
+    let input = ByteArrayInputFile {
+        data: data.to_vec(),
+    };
+    MosaicReader::new(input, data.len() as u64).unwrap()
+}
+
+/// Read all row groups from a reader.
+fn read_all(data: &[u8]) -> Vec<RecordBatch> {
+    let reader = open_reader(data);
+    let mut result = Vec::new();
+    for rg in 0..reader.num_row_groups() {
+        let mut rg_reader = reader.row_group_reader(rg).unwrap();
+        result.push(rg_reader.read_columns().unwrap());
+    }
+    result
+}
+
+/// Extract the 32-byte footer from raw file bytes.
+fn extract_footer(data: &[u8]) -> &[u8] {
+    let len = data.len();
+    &data[len - spec::FOOTER_SIZE..]
+}
+
+// ======================== Binary Format Verification Tests ========================
+
+// 1. test_footer_magic_bytes
+#[test]
+fn test_footer_magic_bytes() {
+    let schema = Schema::new(vec![Field::new("a", DataType::Int32, false)]);
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int32Array::from(vec![1, 2, 3]))],
+    )
+    .unwrap();
+    let data = write_file(&schema, &[batch], WriterOptions::default());
+
+    let last_4 = &data[data.len() - 4..];
+    assert_eq!(last_4, b"MOSA", "last 4 bytes must be the MOSA magic");
+    println!("test_footer_magic_bytes: PASSED");
+}
+
+// 2. test_footer_version_byte
+#[test]
+fn test_footer_version_byte() {
+    let schema = Schema::new(vec![Field::new("a", DataType::Int64, false)]);
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int64Array::from(vec![100, 200]))],
+    )
+    .unwrap();
+    let data = write_file(&schema, &[batch], WriterOptions::default());
+
+    // Version byte is at footer[25], which is data[len - 7]
+    let version_byte = data[data.len() - 7];
+    assert_eq!(
+        version_byte,
+        spec::VERSION,
+        "version byte at len-7 must equal spec::VERSION ({})",
+        spec::VERSION
+    );
+    println!(
+        "test_footer_version_byte: PASSED (version={})",
+        version_byte
+    );
+}
+
+// 3. test_footer_size_exactly_32
+#[test]
+fn test_footer_size_exactly_32() {
+    assert_eq!(spec::FOOTER_SIZE, 32, "FOOTER_SIZE constant must be 32");
+
+    let schema = Schema::new(vec![Field::new("x", DataType::Int32, false)]);
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int32Array::from(vec![42]))],
+    )
+    .unwrap();
+    let data = write_file(&schema, &[batch], WriterOptions::default());
+
+    // Verify we can parse the footer region
+    let footer = extract_footer(&data);
+    assert_eq!(footer.len(), 32);
+
+    // Parse fields to verify the region is valid
+    let _index_offset = read_be_u64(footer, 0);
+    let _schema_block_offset = read_be_u64(footer, 8);
+    let _num_buckets = read_be_u32(footer, 16);
+    let _num_row_groups = read_be_u32(footer, 20);
+    let _compression = footer[24];
+    let _version = footer[25];
+    // bytes 26-27 are reserved/padding
+    let magic = &footer[28..32];
+    assert_eq!(magic, b"MOSA");
+
+    println!("test_footer_size_exactly_32: PASSED");
+}
+
+// 4. test_footer_compression_byte
+#[test]
+fn test_footer_compression_byte() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Int64, false)]);
+    let vals: Vec<i64> = (0..1000).collect();
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int64Array::from(vals))],
+    )
+    .unwrap();
+
+    // Write with NONE compression
+    let data_none = write_file(
+        &schema,
+        &[batch.clone()],
+        WriterOptions {
+            compression: spec::COMPRESSION_NONE,
+            num_buckets: 1,
+            ..Default::default()
+        },
+    );
+    let footer_none = extract_footer(&data_none);
+    assert_eq!(
+        footer_none[24],
+        spec::COMPRESSION_NONE,
+        "compression byte for NONE must be {}",
+        spec::COMPRESSION_NONE
+    );
+
+    // Write with ZSTD compression
+    let data_zstd = write_file(
+        &schema,
+        &[batch],
+        WriterOptions {
+            compression: spec::COMPRESSION_ZSTD,
+            num_buckets: 1,
+            ..Default::default()
+        },
+    );
+    let footer_zstd = extract_footer(&data_zstd);
+    assert_eq!(
+        footer_zstd[24],
+        spec::COMPRESSION_ZSTD,
+        "compression byte for ZSTD must be {}",
+        spec::COMPRESSION_ZSTD
+    );
+
+    println!(
+        "test_footer_compression_byte: PASSED (NONE={}, ZSTD={})",
+        footer_none[24], footer_zstd[24]
+    );
+}
+
+// 5. test_footer_offsets_valid
+#[test]
+fn test_footer_offsets_valid() {
+    let schema = Schema::new(vec![
+        Field::new("a", DataType::Int32, false),
+        Field::new("b", DataType::Utf8, true),
+    ]);
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5])),
+            Arc::new(StringArray::from(vec![
+                Some("hello"),
+                None,
+                Some("world"),
+                Some("test"),
+                None,
+            ])),
+        ],
+    )
+    .unwrap();
+    let data = write_file(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 2,
+            ..Default::default()
+        },
+    );
+
+    let file_len = data.len() as u64;
+    let footer = extract_footer(&data);
+    let index_offset = read_be_u64(footer, 0);
+    let schema_block_offset = read_be_u64(footer, 8);
+
+    let footer_start = file_len - spec::FOOTER_SIZE as u64;
+
+    // Both offsets must be within the file before the footer
+    assert!(
+        index_offset <= footer_start,
+        "index_offset ({}) must be <= footer_start ({})",
+        index_offset,
+        footer_start
+    );
+    assert!(
+        schema_block_offset <= footer_start,
+        "schema_block_offset ({}) must be <= footer_start ({})",
+        schema_block_offset,
+        footer_start
+    );
+
+    // The format layout is: data | schema_block | index | footer
+    // So schema_block_offset + 4 <= index_offset <= footer_start
+    assert!(
+        schema_block_offset + 4 <= index_offset,
+        "schema_block_offset+4 ({}) must be <= index_offset ({})",
+        schema_block_offset + 4,
+        index_offset
+    );
+
+    println!(
+        "test_footer_offsets_valid: PASSED (schema_block_offset={}, index_offset={}, footer_start={})",
+        schema_block_offset, index_offset, footer_start
+    );
+}
+
+// 6. test_footer_num_row_groups
+#[test]
+fn test_footer_num_row_groups() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Int64, false)]);
+
+    // Write enough data with a small row_group_max_size to force multiple row groups
+    let batch_size = 5000;
+    let mut batches = Vec::new();
+    for b in 0..10 {
+        let vals: Vec<i64> = ((b * batch_size)..((b + 1) * batch_size))
+            .map(|i| i as i64)
+            .collect();
+        batches.push(
+            RecordBatch::try_new(
+                Arc::new(schema.clone()),
+                vec![Arc::new(Int64Array::from(vals))],
+            )
+            .unwrap(),
+        );
+    }
+
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 8 * 1024, // very small to force multiple row groups
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    for batch in &batches {
+        writer.write_batch(batch).unwrap();
+    }
+    writer.close().unwrap();
+    let data = writer.output().buf.clone();
+
+    // Parse num_row_groups from footer
+    let footer = extract_footer(&data);
+    let num_row_groups_from_footer = read_be_u32(footer, 20) as usize;
+
+    // Compare with reader
+    let reader = open_reader(&data);
+    let num_row_groups_from_reader = reader.num_row_groups();
+
+    assert_eq!(
+        num_row_groups_from_footer, num_row_groups_from_reader,
+        "footer num_row_groups ({}) must match reader.num_row_groups() ({})",
+        num_row_groups_from_footer, num_row_groups_from_reader
+    );
+    assert!(
+        num_row_groups_from_footer > 1,
+        "expected multiple row groups, got {}",
+        num_row_groups_from_footer
+    );
+
+    println!(
+        "test_footer_num_row_groups: PASSED (num_row_groups={})",
+        num_row_groups_from_footer
+    );
+}
+
+// 7. test_footer_num_buckets
+#[test]
+fn test_footer_num_buckets() {
+    let schema = Schema::new(vec![
+        Field::new("a", DataType::Int32, false),
+        Field::new("b", DataType::Int32, false),
+        Field::new("c", DataType::Int32, false),
+        Field::new("d", DataType::Int32, false),
+        Field::new("e", DataType::Int32, false),
+        Field::new("f", DataType::Int32, false),
+        Field::new("g", DataType::Int32, false),
+    ]);
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int32Array::from(vec![1])),
+            Arc::new(Int32Array::from(vec![2])),
+            Arc::new(Int32Array::from(vec![3])),
+            Arc::new(Int32Array::from(vec![4])),
+            Arc::new(Int32Array::from(vec![5])),
+            Arc::new(Int32Array::from(vec![6])),
+            Arc::new(Int32Array::from(vec![7])),
+        ],
+    )
+    .unwrap();
+
+    let data = write_file(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 7,
+            ..Default::default()
+        },
+    );
+
+    let footer = extract_footer(&data);
+    let num_buckets_from_footer = read_be_u32(footer, 16);
+
+    let reader = open_reader(&data);
+    let num_buckets_from_schema = reader.schema().num_buckets;
+
+    assert_eq!(
+        num_buckets_from_footer as usize, num_buckets_from_schema,
+        "footer num_buckets ({}) must match schema num_buckets ({})",
+        num_buckets_from_footer, num_buckets_from_schema
+    );
+    assert_eq!(num_buckets_from_footer, 7, "expected num_buckets=7");
+
+    println!(
+        "test_footer_num_buckets: PASSED (num_buckets={})",
+        num_buckets_from_footer
+    );
+}
+
+// 8. test_schema_block_readable
+#[test]
+fn test_schema_block_readable() {
+    let schema = Schema::new(vec![
+        Field::new("x", DataType::Int64, false),
+        Field::new("y", DataType::Utf8, true),
+    ]);
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int64Array::from(vec![10, 20, 30])),
+            Arc::new(StringArray::from(vec![Some("a"), None, Some("c")])),
+        ],
+    )
+    .unwrap();
+
+    // Use NONE compression so we can more easily inspect the schema block
+    let data = write_file(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 1,
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    );
+
+    let footer = extract_footer(&data);
+    let schema_block_offset = read_be_u64(footer, 8) as usize;
+    let index_offset = read_be_u64(footer, 0) as usize;
+
+    // The schema block starts with a 4-byte uncompressed size (big-endian u32)
+    assert!(
+        schema_block_offset + 4 <= data.len(),
+        "schema_block_offset+4 must be within file"
+    );
+    let uncompressed_size = read_be_u32(&data, schema_block_offset);
+    assert!(
+        uncompressed_size > 0,
+        "schema block uncompressed_size must be > 0"
+    );
+
+    // The schema compressed data is between schema_block_offset+4 and index_offset
+    let schema_compressed_len = index_offset - schema_block_offset - 4;
+    assert!(
+        schema_compressed_len > 0,
+        "schema block compressed data must have length > 0"
+    );
+
+    // For NONE compression, uncompressed_size should equal the compressed length
+    assert_eq!(
+        uncompressed_size as usize, schema_compressed_len,
+        "with NONE compression, uncompressed_size should equal compressed_len"
+    );
+
+    println!(
+        "test_schema_block_readable: PASSED (uncompressed_size={}, compressed_len={})",
+        uncompressed_size, schema_compressed_len
+    );
+}
+
+// 9. test_column_order_alphabetical
+#[test]
+fn test_column_order_alphabetical() {
+    // Write columns in non-alphabetical order
+    let schema = Schema::new(vec![
+        Field::new("zebra", DataType::Int32, false),
+        Field::new("alpha", DataType::Int32, false),
+        Field::new("middle", DataType::Int32, false),
+    ]);
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int32Array::from(vec![30])),
+            Arc::new(Int32Array::from(vec![10])),
+            Arc::new(Int32Array::from(vec![20])),
+        ],
+    )
+    .unwrap();
+
+    let data = write_file(&schema, &[batch], WriterOptions::default());
+    let reader = open_reader(&data);
+
+    // Internal storage order (schema.columns) should be alphabetical
+    let col_names: Vec<&str> = reader
+        .schema()
+        .columns
+        .iter()
+        .map(|c| c.name.as_str())
+        .collect();
+    assert_eq!(
+        col_names,
+        vec!["alpha", "middle", "zebra"],
+        "internal column order must be alphabetical"
+    );
+
+    // original_order provides the mapping from original position to sorted position
+    let original_order = &reader.schema().original_order;
+    assert_eq!(original_order.len(), 3);
+
+    // Read back and verify data is correctly associated with column names
+    let result = read_all(&data);
+    assert_eq!(result.len(), 1);
+
+    // Find each column by name and verify its value
+    let batch_out = &result[0];
+    let alpha_idx = batch_out.schema().index_of("alpha").unwrap();
+    let middle_idx = batch_out.schema().index_of("middle").unwrap();
+    let zebra_idx = batch_out.schema().index_of("zebra").unwrap();
+
+    let alpha_val = batch_out
+        .column(alpha_idx)
+        .as_any()
+        .downcast_ref::<Int32Array>()
+        .unwrap()
+        .value(0);
+    let middle_val = batch_out
+        .column(middle_idx)
+        .as_any()
+        .downcast_ref::<Int32Array>()
+        .unwrap()
+        .value(0);
+    let zebra_val = batch_out
+        .column(zebra_idx)
+        .as_any()
+        .downcast_ref::<Int32Array>()
+        .unwrap()
+        .value(0);
+
+    assert_eq!(alpha_val, 10);
+    assert_eq!(middle_val, 20);
+    assert_eq!(zebra_val, 30);
+
+    println!(
+        "test_column_order_alphabetical: PASSED (order={:?})",
+        col_names
+    );
+}
+
+// 10. test_multiple_files_different_schemas
+#[test]
+fn test_multiple_files_different_schemas() {
+    // File 1: Int32 columns
+    let schema1 = Schema::new(vec![
+        Field::new("id", DataType::Int32, false),
+        Field::new("value", DataType::Int32, true),
+    ]);
+    let batch1 = RecordBatch::try_new(
+        Arc::new(schema1.clone()),
+        vec![
+            Arc::new(Int32Array::from(vec![1, 2])),
+            Arc::new(Int32Array::from(vec![Some(10), None])),
+        ],
+    )
+    .unwrap();
+    let data1 = write_file(&schema1, &[batch1], WriterOptions::default());
+
+    // File 2: String + Float64 columns
+    let schema2 = Schema::new(vec![
+        Field::new("name", DataType::Utf8, false),
+        Field::new("score", DataType::Float64, true),
+    ]);
+    let batch2 = RecordBatch::try_new(
+        Arc::new(schema2.clone()),
+        vec![
+            Arc::new(StringArray::from(vec!["alice", "bob"])),
+            Arc::new(Float64Array::from(vec![Some(95.5), None])),
+        ],
+    )
+    .unwrap();
+    let data2 = write_file(&schema2, &[batch2], WriterOptions::default());
+
+    // File 3: Single Int64 column
+    let schema3 = Schema::new(vec![Field::new("ts", DataType::Int64, false)]);
+    let batch3 = RecordBatch::try_new(
+        Arc::new(schema3.clone()),
+        vec![Arc::new(Int64Array::from(vec![1000, 2000, 3000]))],
+    )
+    .unwrap();
+    let data3 = write_file(&schema3, &[batch3], WriterOptions::default());
+
+    // Each file should have valid magic
+    for (i, data) in [&data1, &data2, &data3].iter().enumerate() {
+        let footer = extract_footer(data);
+        assert_eq!(&footer[28..32], b"MOSA", "file {} bad magic", i);
+        assert_eq!(footer[25], spec::VERSION, "file {} bad version", i);
+    }
+
+    // Schema blocks should be at different offsets (different schemas = different content)
+    let sb1 = read_be_u64(extract_footer(&data1), 8);
+    let sb2 = read_be_u64(extract_footer(&data2), 8);
+    let sb3 = read_be_u64(extract_footer(&data3), 8);
+
+    // All readers should open successfully with correct column counts
+    let reader1 = open_reader(&data1);
+    let reader2 = open_reader(&data2);
+    let reader3 = open_reader(&data3);
+
+    assert_eq!(reader1.schema().columns.len(), 2);
+    assert_eq!(reader2.schema().columns.len(), 2);
+    assert_eq!(reader3.schema().columns.len(), 1);
+
+    println!(
+        "test_multiple_files_different_schemas: PASSED (offsets: {}, {}, {})",
+        sb1, sb2, sb3
+    );
+}
+
+// ======================== Statistics Accuracy Tests ========================
+
+// 11. test_stats_int64_min_max_exact
+#[test]
+fn test_stats_int64_min_max_exact() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Int64, false)]);
+    let num_rows = 100_000;
+
+    let expected_min: i64 = -999_999;
+    let expected_max: i64 = 999_999;
+
+    // Create values that include the known min and max, with lots of values in between
+    let mut vals: Vec<i64> = (0..num_rows)
+        .map(|i| ((i as i64) % 100_000) - 50_000)
+        .collect();
+    vals[0] = expected_min;
+    vals[1] = expected_max;
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int64Array::from(vals))],
+    )
+    .unwrap();
+
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            stats_columns: vec!["v".to_string()],
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    writer.write_batch(&batch).unwrap();
+    writer.close().unwrap();
+    let data = writer.output().buf.clone();
+
+    let reader = open_reader(&data);
+    let stats = reader.row_group_stats(0).unwrap();
+    assert!(!stats.is_empty(), "stats should not be empty");
+
+    let col_stats = &stats[0];
+    assert_eq!(col_stats.null_count, 0);
+    match &col_stats.min {
+        Some(paimon_mosaic_core::values::Value::BigInt(v)) => {
+            assert_eq!(*v, expected_min, "min mismatch: got {}", v);
+        }
+        other => panic!("expected BigInt min, got {:?}", other),
+    }
+    match &col_stats.max {
+        Some(paimon_mosaic_core::values::Value::BigInt(v)) => {
+            assert_eq!(*v, expected_max, "max mismatch: got {}", v);
+        }
+        other => panic!("expected BigInt max, got {:?}", other),
+    }
+
+    println!(
+        "test_stats_int64_min_max_exact: PASSED (min={}, max={})",
+        expected_min, expected_max
+    );
+}
+
+// 12. test_stats_int32_min_max_exact
+#[test]
+fn test_stats_int32_min_max_exact() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Int32, false)]);
+    let num_rows = 100_000;
+
+    let expected_min: i32 = i32::MIN + 1;
+    let expected_max: i32 = i32::MAX - 1;
+
+    let mut vals: Vec<i32> = (0..num_rows).map(|i| (i as i32) - 50_000).collect();
+    vals[10] = expected_min;
+    vals[20] = expected_max;
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int32Array::from(vals))],
+    )
+    .unwrap();
+
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            stats_columns: vec!["v".to_string()],
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    writer.write_batch(&batch).unwrap();
+    writer.close().unwrap();
+    let data = writer.output().buf.clone();
+
+    let reader = open_reader(&data);
+    let stats = reader.row_group_stats(0).unwrap();
+    assert!(!stats.is_empty());
+
+    let col_stats = &stats[0];
+    match &col_stats.min {
+        Some(paimon_mosaic_core::values::Value::Integer(v)) => {
+            assert_eq!(*v, expected_min, "min mismatch");
+        }
+        other => panic!("expected Integer min, got {:?}", other),
+    }
+    match &col_stats.max {
+        Some(paimon_mosaic_core::values::Value::Integer(v)) => {
+            assert_eq!(*v, expected_max, "max mismatch");
+        }
+        other => panic!("expected Integer max, got {:?}", other),
+    }
+
+    println!("test_stats_int32_min_max_exact: PASSED");
+}
+
+// 13. test_stats_float64_min_max_exact
+#[test]
+fn test_stats_float64_min_max_exact() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Float64, false)]);
+
+    let expected_min: f64 = -1234567.89;
+    let expected_max: f64 = 9876543.21;
+
+    let mut vals: Vec<f64> = (0..10_000).map(|i| (i as f64) * 0.01 - 50.0).collect();
+    vals[0] = expected_min;
+    vals[1] = expected_max;
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Float64Array::from(vals))],
+    )
+    .unwrap();
+
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            stats_columns: vec!["v".to_string()],
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    writer.write_batch(&batch).unwrap();
+    writer.close().unwrap();
+    let data = writer.output().buf.clone();
+
+    let reader = open_reader(&data);
+    let stats = reader.row_group_stats(0).unwrap();
+    assert!(!stats.is_empty());
+
+    let col_stats = &stats[0];
+    match &col_stats.min {
+        Some(paimon_mosaic_core::values::Value::Double(v)) => {
+            assert!((*v - expected_min).abs() < 1e-10, "min mismatch: got {}", v);
+        }
+        other => panic!("expected Double min, got {:?}", other),
+    }
+    match &col_stats.max {
+        Some(paimon_mosaic_core::values::Value::Double(v)) => {
+            assert!((*v - expected_max).abs() < 1e-10, "max mismatch: got {}", v);
+        }
+        other => panic!("expected Double max, got {:?}", other),
+    }
+
+    println!("test_stats_float64_min_max_exact: PASSED");
+}
+
+// 14. test_stats_string_min_max_exact
+#[test]
+fn test_stats_string_min_max_exact() {
+    let schema = Schema::new(vec![Field::new("s", DataType::Utf8, false)]);
+
+    // Lexicographic: "aaa" < "mmm" < "zzz"
+    let str_vals: Vec<&str> = vec!["mmm", "zzz", "bbb", "aaa", "xyz", "def"];
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(StringArray::from(str_vals))],
+    )
+    .unwrap();
+
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            stats_columns: vec!["s".to_string()],
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    writer.write_batch(&batch).unwrap();
+    writer.close().unwrap();
+    let data = writer.output().buf.clone();
+
+    let reader = open_reader(&data);
+    let stats = reader.row_group_stats(0).unwrap();
+    assert!(!stats.is_empty());
+
+    let col_stats = &stats[0];
+    match &col_stats.min {
+        Some(paimon_mosaic_core::values::Value::String(v)) => {
+            assert_eq!(
+                v,
+                b"aaa",
+                "min should be 'aaa', got {:?}",
+                std::str::from_utf8(v)
+            );
+        }
+        other => panic!("expected String min, got {:?}", other),
+    }
+    match &col_stats.max {
+        Some(paimon_mosaic_core::values::Value::String(v)) => {
+            assert_eq!(
+                v,
+                b"zzz",
+                "max should be 'zzz', got {:?}",
+                std::str::from_utf8(v)
+            );
+        }
+        other => panic!("expected String max, got {:?}", other),
+    }
+
+    println!("test_stats_string_min_max_exact: PASSED");
+}
+
+// 15. test_stats_null_count_exact
+#[test]
+fn test_stats_null_count_exact() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Int32, true)]);
+
+    // Exactly 300 nulls out of 1000 rows
+    let vals: Vec<Option<i32>> = (0..1000)
+        .map(|i| if i < 300 { None } else { Some(i as i32) })
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int32Array::from(vals))],
+    )
+    .unwrap();
+
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            stats_columns: vec!["v".to_string()],
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    writer.write_batch(&batch).unwrap();
+    writer.close().unwrap();
+    let data = writer.output().buf.clone();
+
+    let reader = open_reader(&data);
+    let stats = reader.row_group_stats(0).unwrap();
+    assert!(!stats.is_empty());
+
+    let col_stats = &stats[0];
+    assert_eq!(
+        col_stats.null_count, 300,
+        "null_count should be exactly 300"
+    );
+
+    println!(
+        "test_stats_null_count_exact: PASSED (null_count={})",
+        col_stats.null_count
+    );
+}
+
+// 16. test_stats_all_null_column
+#[test]
+fn test_stats_all_null_column() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Int64, true)]);
+
+    let num_rows = 500;
+    let vals: Vec<Option<i64>> = vec![None; num_rows];
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int64Array::from(vals))],
+    )
+    .unwrap();
+
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            stats_columns: vec!["v".to_string()],
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    writer.write_batch(&batch).unwrap();
+    writer.close().unwrap();
+    let data = writer.output().buf.clone();
+
+    let reader = open_reader(&data);
+    let stats = reader.row_group_stats(0).unwrap();
+    assert!(!stats.is_empty());
+
+    let col_stats = &stats[0];
+    assert_eq!(
+        col_stats.null_count, num_rows,
+        "null_count should equal num_rows for all-null column"
+    );
+    assert!(
+        col_stats.min.is_none(),
+        "min should be None for all-null column"
+    );
+    assert!(
+        col_stats.max.is_none(),
+        "max should be None for all-null column"
+    );
+
+    println!("test_stats_all_null_column: PASSED");
+}
+
+// 17. test_stats_no_null_column
+#[test]
+fn test_stats_no_null_column() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Int32, false)]);
+
+    let num_rows = 1000;
+    let vals: Vec<i32> = (0..num_rows as i32).collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int32Array::from(vals))],
+    )
+    .unwrap();
+
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            stats_columns: vec!["v".to_string()],
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    writer.write_batch(&batch).unwrap();
+    writer.close().unwrap();
+    let data = writer.output().buf.clone();
+
+    let reader = open_reader(&data);
+    let stats = reader.row_group_stats(0).unwrap();
+    assert!(!stats.is_empty());
+
+    let col_stats = &stats[0];
+    assert_eq!(
+        col_stats.null_count, 0,
+        "null_count should be 0 for no-null column"
+    );
+    assert!(col_stats.min.is_some(), "min should be present");
+    assert!(col_stats.max.is_some(), "max should be present");
+
+    println!("test_stats_no_null_column: PASSED");
+}
+
+// 18. test_stats_across_multiple_row_groups
+#[test]
+fn test_stats_across_multiple_row_groups() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Int64, false)]);
+
+    // Write batches with clearly different value ranges to get per-row-group stats
+    let batch_size = 5000;
+    let mut batches = Vec::new();
+    for b in 0..10 {
+        // Batch b has values in range [b*1_000_000, b*1_000_000 + batch_size)
+        let base = (b as i64) * 1_000_000;
+        let vals: Vec<i64> = (0..batch_size).map(|i| base + i as i64).collect();
+        batches.push(
+            RecordBatch::try_new(
+                Arc::new(schema.clone()),
+                vec![Arc::new(Int64Array::from(vals))],
+            )
+            .unwrap(),
+        );
+    }
+
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 8 * 1024, // small to force multiple row groups
+            stats_columns: vec!["v".to_string()],
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    for batch in &batches {
+        writer.write_batch(batch).unwrap();
+    }
+    writer.close().unwrap();
+    let data = writer.output().buf.clone();
+
+    let reader = open_reader(&data);
+    let num_rg = reader.num_row_groups();
+    assert!(num_rg > 1, "need multiple row groups, got {}", num_rg);
+
+    // Each row group should have independent stats
+    let mut prev_max: Option<i64> = None;
+    for rg in 0..num_rg {
+        let stats = reader.row_group_stats(rg).unwrap();
+        if stats.is_empty() {
+            continue;
+        }
+        let col_stats = &stats[0];
+        if let (Some(min_val), Some(max_val)) = (&col_stats.min, &col_stats.max) {
+            if let (
+                paimon_mosaic_core::values::Value::BigInt(min_v),
+                paimon_mosaic_core::values::Value::BigInt(max_v),
+            ) = (min_val, max_val)
+            {
+                assert!(
+                    min_v <= max_v,
+                    "rg {}: min ({}) > max ({})",
+                    rg,
+                    min_v,
+                    max_v
+                );
+
+                // Verify stats are per-row-group (not global)
+                if let Some(pm) = prev_max {
+                    // The global max grows across row groups, but each row group
+                    // should have its own local min/max, not the global one
+                    // (unless all data happens to be in one row group)
+                    println!("  rg {}: min={}, max={}, prev_max={}", rg, min_v, max_v, pm);
+                }
+                prev_max = Some(*max_v);
+            }
+        }
+    }
+
+    println!(
+        "test_stats_across_multiple_row_groups: PASSED (num_row_groups={})",
+        num_rg
+    );
+}
+
+// 19. test_stats_single_value
+#[test]
+fn test_stats_single_value() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Int64, false)]);
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int64Array::from(vec![42_i64]))],
+    )
+    .unwrap();
+
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            stats_columns: vec!["v".to_string()],
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    writer.write_batch(&batch).unwrap();
+    writer.close().unwrap();
+    let data = writer.output().buf.clone();
+
+    let reader = open_reader(&data);
+    let stats = reader.row_group_stats(0).unwrap();
+    assert!(!stats.is_empty());
+
+    let col_stats = &stats[0];
+    match (&col_stats.min, &col_stats.max) {
+        (
+            Some(paimon_mosaic_core::values::Value::BigInt(min_v)),
+            Some(paimon_mosaic_core::values::Value::BigInt(max_v)),
+        ) => {
+            assert_eq!(*min_v, 42, "min should be 42");
+            assert_eq!(*max_v, 42, "max should be 42");
+            assert_eq!(min_v, max_v, "min must equal max for single value");
+        }
+        other => panic!("expected BigInt min/max, got {:?}", other),
+    }
+
+    println!("test_stats_single_value: PASSED");
+}
+
+// 20. test_stats_negative_values
+#[test]
+fn test_stats_negative_values() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Int64, false)]);
+
+    // All negative values
+    let vals: Vec<i64> = (-10_000..-1).collect();
+    let expected_min = -10_000_i64;
+    let expected_max = -2_i64;
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int64Array::from(vals))],
+    )
+    .unwrap();
+
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            stats_columns: vec!["v".to_string()],
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    writer.write_batch(&batch).unwrap();
+    writer.close().unwrap();
+    let data = writer.output().buf.clone();
+
+    let reader = open_reader(&data);
+    let stats = reader.row_group_stats(0).unwrap();
+    assert!(!stats.is_empty());
+
+    let col_stats = &stats[0];
+    match (&col_stats.min, &col_stats.max) {
+        (
+            Some(paimon_mosaic_core::values::Value::BigInt(min_v)),
+            Some(paimon_mosaic_core::values::Value::BigInt(max_v)),
+        ) => {
+            assert_eq!(*min_v, expected_min, "min mismatch");
+            assert_eq!(*max_v, expected_max, "max mismatch");
+            assert!(*min_v < *max_v, "min should be < max");
+            assert!(*max_v < 0, "max should be < 0 (all negative)");
+        }
+        other => panic!("expected BigInt min/max, got {:?}", other),
+    }
+
+    println!("test_stats_negative_values: PASSED");
+}
+
+// 21. test_stats_disabled_columns
+#[test]
+fn test_stats_disabled_columns() {
+    let schema = Schema::new(vec![
+        Field::new("a", DataType::Int32, false),
+        Field::new("b", DataType::Int64, false),
+        Field::new("c", DataType::Float64, false),
+    ]);
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int32Array::from(vec![1, 2, 3])),
+            Arc::new(Int64Array::from(vec![10, 20, 30])),
+            Arc::new(Float64Array::from(vec![1.1, 2.2, 3.3])),
+        ],
+    )
+    .unwrap();
+
+    // Only enable stats for column "b"
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            stats_columns: vec!["b".to_string()],
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    writer.write_batch(&batch).unwrap();
+    writer.close().unwrap();
+    let data = writer.output().buf.clone();
+
+    let reader = open_reader(&data);
+    let stats = reader.row_group_stats(0).unwrap();
+
+    // Only one column should have stats
+    assert_eq!(stats.len(), 1, "only 1 column should have stats");
+
+    // The stats entry should be for the column that we enabled (internal sorted index of "b")
+    let b_sorted_idx = reader
+        .schema()
+        .columns
+        .iter()
+        .position(|c| c.name == "b")
+        .unwrap();
+    assert_eq!(
+        stats[0].column_index, b_sorted_idx,
+        "stats should be for column 'b'"
+    );
+
+    // Now write with NO stats
+    let out2 = MemOutputFile::new();
+    let mut writer2 = MosaicWriter::new(
+        out2,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            stats_columns: vec![],
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    writer2.write_batch(&batch).unwrap();
+    writer2.close().unwrap();
+    let data2 = writer2.output().buf.clone();
+
+    let reader2 = open_reader(&data2);
+    let stats2 = reader2.row_group_stats(0).unwrap();
+    assert!(
+        stats2.is_empty(),
+        "no stats should be present when disabled"
+    );
+
+    println!("test_stats_disabled_columns: PASSED");
+}
+
+// ======================== Estimated File Size Accuracy Tests ========================
+
+// 22. test_estimated_size_before_any_write
+#[test]
+fn test_estimated_size_before_any_write() {
+    let schema = Schema::new(vec![
+        Field::new("a", DataType::Int32, false),
+        Field::new("b", DataType::Utf8, true),
+    ]);
+
+    let out = MemOutputFile::new();
+    let writer = MosaicWriter::new(out, &schema, WriterOptions::default()).unwrap();
+
+    let estimated = writer.estimated_file_size();
+    // Before any writes, estimated_file_size should be > 0 (at least the 1024 overhead constant)
+    assert!(
+        estimated > 0,
+        "estimated_file_size before any write should be > 0, got {}",
+        estimated
+    );
+
+    println!(
+        "test_estimated_size_before_any_write: PASSED (estimated={})",
+        estimated
+    );
+}
+
+// 23. test_estimated_size_grows_with_data
+#[test]
+fn test_estimated_size_grows_with_data() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Int64, false)]);
+
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            ..Default::default()
+        },
+    )
+    .unwrap();
+
+    let mut prev_estimated = writer.estimated_file_size();
+    let batch_size = 1000;
+
+    for i in 0..20 {
+        let vals: Vec<i64> = ((i * batch_size)..((i + 1) * batch_size))
+            .map(|v| v as i64)
+            .collect();
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![Arc::new(Int64Array::from(vals))],
+        )
+        .unwrap();
+        writer.write_batch(&batch).unwrap();
+
+        let current_estimated = writer.estimated_file_size();
+        assert!(
+            current_estimated >= prev_estimated,
+            "estimated_file_size should monotonically increase: batch {}: prev={}, current={}",
+            i,
+            prev_estimated,
+            current_estimated
+        );
+        prev_estimated = current_estimated;
+    }
+
+    println!(
+        "test_estimated_size_grows_with_data: PASSED (final_estimated={})",
+        prev_estimated
+    );
+}
+
+// 24. test_estimated_size_vs_actual_within_tolerance
+#[test]
+fn test_estimated_size_vs_actual_within_tolerance() {
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("data", DataType::Utf8, true),
+    ]);
+
+    // Use NONE compression to avoid compression ratio distortion
+    for &num_rows in &[1_000usize, 10_000, 100_000, 500_000] {
+        let ids: Vec<i64> = (0..num_rows as i64).collect();
+        let strs: Vec<Option<String>> = (0..num_rows)
+            .map(|i| {
+                if i % 5 == 0 {
+                    None
+                } else {
+                    Some(format!("row_{:08}", i))
+                }
+            })
+            .collect();
+        let str_refs: Vec<Option<&str>> = strs.iter().map(|s| s.as_deref()).collect();
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int64Array::from(ids)),
+                Arc::new(StringArray::from(str_refs)),
+            ],
+        )
+        .unwrap();
+
+        let out = MemOutputFile::new();
+        let mut writer = MosaicWriter::new(
+            out,
+            &schema,
+            WriterOptions {
+                num_buckets: 1,
+                compression: spec::COMPRESSION_NONE,
+                ..Default::default()
+            },
+        )
+        .unwrap();
+        writer.write_batch(&batch).unwrap();
+
+        // Get estimated size just before close
+        let estimated = writer.estimated_file_size();
+        writer.close().unwrap();
+        let actual = writer.output().buf.len() as u64;
+
+        // The estimate includes a constant 1024 overhead plus buffered * compression_ratio.
+        // For small files the 1024 constant dominates. For larger files, the estimate
+        // converges closer to actual. We use a generous tolerance that accounts for the
+        // constant overhead and dict/const encoding effects.
+        let ratio = if estimated > actual {
+            estimated as f64 / actual as f64
+        } else {
+            actual as f64 / estimated as f64
+        };
+
+        // With NONE compression, the estimate should be reasonably close.
+        // Allow up to 5x for small files (dominated by the 1024 constant),
+        // but for larger files (500K rows) it should be tighter.
+        let max_ratio = if num_rows >= 100_000 { 1.5 } else { 5.0 };
+        assert!(
+            ratio <= max_ratio,
+            "num_rows={}: estimated ({}) vs actual ({}) ratio {:.2} exceeds {:.1}",
+            num_rows,
+            estimated,
+            actual,
+            ratio,
+            max_ratio
+        );
+
+        println!(
+            "  num_rows={}: estimated={}, actual={}, ratio={:.3}",
+            num_rows, estimated, actual, ratio
+        );
+    }
+
+    println!("test_estimated_size_vs_actual_within_tolerance: PASSED");
+}
+
+// 25. test_estimated_size_with_compression
+#[test]
+fn test_estimated_size_with_compression() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Int64, false)]);
+    let num_rows = 50_000;
+
+    // Highly compressible: repeated values
+    let vals: Vec<i64> = (0..num_rows).map(|i| (i % 100) as i64).collect();
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int64Array::from(vals.clone()))],
+    )
+    .unwrap();
+
+    // Without compression
+    let out_none = MemOutputFile::new();
+    let mut writer_none = MosaicWriter::new(
+        out_none,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            compression: spec::COMPRESSION_NONE,
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    writer_none.write_batch(&batch).unwrap();
+    let est_none = writer_none.estimated_file_size();
+    writer_none.close().unwrap();
+    let actual_none = writer_none.output().buf.len() as u64;
+
+    // With ZSTD compression
+    let batch_zstd = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int64Array::from(vals))],
+    )
+    .unwrap();
+
+    let out_zstd = MemOutputFile::new();
+    let mut writer_zstd = MosaicWriter::new(
+        out_zstd,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            compression: spec::COMPRESSION_ZSTD,
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    writer_zstd.write_batch(&batch_zstd).unwrap();
+    let est_zstd = writer_zstd.estimated_file_size();
+    writer_zstd.close().unwrap();
+    let actual_zstd = writer_zstd.output().buf.len() as u64;
+
+    // ZSTD actual should be smaller than NONE actual
+    assert!(
+        actual_zstd < actual_none,
+        "ZSTD actual ({}) should be smaller than NONE actual ({})",
+        actual_zstd,
+        actual_none
+    );
+
+    println!(
+        "test_estimated_size_with_compression: PASSED (none: est={} actual={}, zstd: est={} actual={})",
+        est_none, actual_none, est_zstd, actual_zstd
+    );
+}
+
+// 26. test_estimated_size_constant_data
+#[test]
+fn test_estimated_size_constant_data() {
+    let schema = Schema::new(vec![Field::new("v", DataType::Int64, false)]);
+    let num_rows = 100_000;
+
+    // All same value - will use CONST encoding
+    let vals: Vec<i64> = vec![42_i64; num_rows];
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![Arc::new(Int64Array::from(vals))],
+    )
+    .unwrap();
+
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 1,
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    writer.write_batch(&batch).unwrap();
+
+    let estimated = writer.estimated_file_size();
+    // Just verify it doesn't crash and returns a reasonable value
+    assert!(estimated > 0, "estimated should be > 0, got {}", estimated);
+
+    writer.close().unwrap();
+    let actual = writer.output().buf.len() as u64;
+
+    // CONST encoding makes the actual very small; estimated may be much larger.
+    // That's acceptable. Just verify actual is valid.
+    assert!(actual > 0, "actual file size should be > 0");
+    assert!(
+        actual < 2048,
+        "CONST-encoded file should be small, got {}",
+        actual
+    );
+
+    println!(
+        "test_estimated_size_constant_data: PASSED (estimated={}, actual={})",
+        estimated, actual
+    );
+}
diff --git a/core/tests/interop_read_test.rs b/core/tests/interop_read_test.rs
new file mode 100644
index 0000000..83fc492
--- /dev/null
+++ b/core/tests/interop_read_test.rs
@@ -0,0 +1,223 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Interop read tests: reads .mosaic files written by Java and Python,
+//! verifying that Rust can correctly read files produced by other languages.
+
+#![allow(
+    clippy::approx_constant,
+    clippy::needless_range_loop,
+    clippy::unnecessary_cast,
+    clippy::manual_is_multiple_of
+)]
+
+use std::fs;
+use std::io;
+
+use arrow_array::*;
+use paimon_mosaic_core::reader::{InputFile, MosaicReader, ReaderAccess};
+
+const INTEROP_DIR: &str = "/tmp/mosaic_interop";
+
+// ======================== Infrastructure ========================
+
+struct ByteArrayInputFile {
+    data: Vec<u8>,
+}
+
+impl InputFile for ByteArrayInputFile {
+    fn read_at(&self, offset: u64, buf: &mut [u8]) -> io::Result<()> {
+        let start = offset as usize;
+        let end = start + buf.len();
+        if end > self.data.len() {
+            return Err(io::Error::new(
+                io::ErrorKind::UnexpectedEof,
+                "read past end",
+            ));
+        }
+        buf.copy_from_slice(&self.data[start..end]);
+        Ok(())
+    }
+}
+
+fn open_file(filename: &str) -> MosaicReader<ByteArrayInputFile> {
+    let path = format!("{}/{}", INTEROP_DIR, filename);
+    let data = fs::read(&path).unwrap_or_else(|e| {
+        panic!(
+            "Failed to read {}: {}. Did you run the Java/Python interop tests first?",
+            path, e
+        );
+    });
+    let file_len = data.len() as u64;
+    let input = ByteArrayInputFile { data };
+    MosaicReader::new(input, file_len).unwrap()
+}
+
+// ======================== 1. Read java_written.mosaic ========================
+
+#[test]
+fn test_read_java_written_file() {
+    let reader = open_file("java_written.mosaic");
+    let num_rgs = reader.num_row_groups();
+    assert!(num_rgs >= 1, "Expected at least 1 row group");
+
+    let mut total_rows = 0usize;
+    for rg in 0..num_rgs {
+        let mut rg_reader = reader.row_group_reader(rg).unwrap();
+        let batch = rg_reader.read_columns().unwrap();
+
+        let ids = batch
+            .column_by_name("id")
+            .unwrap()
+            .as_any()
+            .downcast_ref::<Int64Array>()
+            .unwrap();
+        let names = batch
+            .column_by_name("name")
+            .unwrap()
+            .as_any()
+            .downcast_ref::<StringArray>()
+            .unwrap();
+        let scores = batch
+            .column_by_name("score")
+            .unwrap()
+            .as_any()
+            .downcast_ref::<Float64Array>()
+            .unwrap();
+
+        for i in 0..batch.num_rows() {
+            let row_idx = total_rows + i;
+            assert_eq!(
+                ids.value(i),
+                row_idx as i64,
+                "id mismatch at row {}",
+                row_idx
+            );
+
+            if row_idx % 3 == 0 {
+                assert!(names.is_null(i), "name should be null at row {}", row_idx);
+            } else {
+                assert!(
+                    !names.is_null(i),
+                    "name should not be null at row {}",
+                    row_idx
+                );
+                assert_eq!(
+                    names.value(i),
+                    format!("java_name_{}", row_idx),
+                    "name mismatch at row {}",
+                    row_idx
+                );
+            }
+
+            assert_eq!(
+                scores.value(i),
+                row_idx as f64 * 2.5,
+                "score mismatch at row {}",
+                row_idx
+            );
+        }
+        total_rows += batch.num_rows();
+    }
+
+    assert_eq!(
+        total_rows, 5000,
+        "Expected 5000 rows from Java-written file"
+    );
+    println!(
+        "test_read_java_written_file: PASSED ({} rows, {} row groups)",
+        total_rows, num_rgs
+    );
+}
+
+// ======================== 2. Read python_written.mosaic ========================
+
+#[test]
+fn test_read_python_written_file() {
+    let reader = open_file("python_written.mosaic");
+    let num_rgs = reader.num_row_groups();
+    assert!(num_rgs >= 1, "Expected at least 1 row group");
+
+    let mut total_rows = 0usize;
+    for rg in 0..num_rgs {
+        let mut rg_reader = reader.row_group_reader(rg).unwrap();
+        let batch = rg_reader.read_columns().unwrap();
+
+        let ids = batch
+            .column_by_name("id")
+            .unwrap()
+            .as_any()
+            .downcast_ref::<Int64Array>()
+            .unwrap();
+        let names = batch
+            .column_by_name("name")
+            .unwrap()
+            .as_any()
+            .downcast_ref::<StringArray>()
+            .unwrap();
+        let scores = batch
+            .column_by_name("score")
+            .unwrap()
+            .as_any()
+            .downcast_ref::<Float64Array>()
+            .unwrap();
+
+        for i in 0..batch.num_rows() {
+            let row_idx = total_rows + i;
+            assert_eq!(
+                ids.value(i),
+                row_idx as i64,
+                "id mismatch at row {}",
+                row_idx
+            );
+
+            if row_idx % 3 == 0 {
+                assert!(names.is_null(i), "name should be null at row {}", row_idx);
+            } else {
+                assert!(
+                    !names.is_null(i),
+                    "name should not be null at row {}",
+                    row_idx
+                );
+                assert_eq!(
+                    names.value(i),
+                    format!("py_name_{}", row_idx),
+                    "name mismatch at row {}",
+                    row_idx
+                );
+            }
+
+            assert!(
+                (scores.value(i) - row_idx as f64 * 2.5).abs() < 1e-9,
+                "score mismatch at row {}: {} != {}",
+                row_idx,
+                scores.value(i),
+                row_idx as f64 * 2.5
+            );
+        }
+        total_rows += batch.num_rows();
+    }
+
+    assert_eq!(
+        total_rows, 5000,
+        "Expected 5000 rows from Python-written file"
+    );
+    println!(
+        "test_read_python_written_file: PASSED ({} rows, {} row groups)",
+        total_rows, num_rgs
+    );
+}
diff --git a/core/tests/interop_write_test.rs b/core/tests/interop_write_test.rs
new file mode 100644
index 0000000..8dd35b7
--- /dev/null
+++ b/core/tests/interop_write_test.rs
@@ -0,0 +1,610 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Interop write tests: writes golden .mosaic files to /tmp/mosaic_interop/
+//! that can be read by Java and Python tests to verify cross-language compatibility.
+
+#![allow(
+    clippy::approx_constant,
+    clippy::needless_range_loop,
+    clippy::unnecessary_cast,
+    clippy::manual_is_multiple_of
+)]
+
+use std::fs;
+use std::io;
+use std::io::Write as IoWrite;
+use std::sync::Arc;
+
+use arrow_array::*;
+use arrow_schema::{DataType, Field, Schema};
+use paimon_mosaic_core::reader::{InputFile, MosaicReader, ReaderAccess};
+use paimon_mosaic_core::writer::{MosaicWriter, OutputFile, WriterOptions};
+
+const INTEROP_DIR: &str = "/tmp/mosaic_interop";
+
+// ======================== Infrastructure ========================
+
+struct MemOutputFile {
+    pub buf: Vec<u8>,
+}
+
+impl MemOutputFile {
+    fn new() -> Self {
+        Self { buf: Vec::new() }
+    }
+}
+
+impl OutputFile for MemOutputFile {
+    fn write(&mut self, data: &[u8]) -> io::Result<()> {
+        self.buf.extend_from_slice(data);
+        Ok(())
+    }
+    fn flush(&mut self) -> io::Result<()> {
+        Ok(())
+    }
+    fn pos(&self) -> u64 {
+        self.buf.len() as u64
+    }
+}
+
+struct ByteArrayInputFile {
+    data: Vec<u8>,
+}
+
+impl InputFile for ByteArrayInputFile {
+    fn read_at(&self, offset: u64, buf: &mut [u8]) -> io::Result<()> {
+        let start = offset as usize;
+        let end = start + buf.len();
+        if end > self.data.len() {
+            return Err(io::Error::new(
+                io::ErrorKind::UnexpectedEof,
+                "read past end",
+            ));
+        }
+        buf.copy_from_slice(&self.data[start..end]);
+        Ok(())
+    }
+}
+
+fn write_and_verify(
+    schema: &Schema,
+    batches: &[RecordBatch],
+    options: WriterOptions,
+    filename: &str,
+) -> Vec<u8> {
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(out, schema, options).unwrap();
+    for batch in batches {
+        writer.write_batch(batch).unwrap();
+    }
+    writer.close().unwrap();
+    let data = writer.output().buf.clone();
+
+    // Verify by reading back in Rust
+    let file_len = data.len() as u64;
+    let input = ByteArrayInputFile { data: data.clone() };
+    let reader = MosaicReader::new(input, file_len).unwrap();
+
+    let expected_rows: usize = batches.iter().map(|b| b.num_rows()).sum();
+    let mut actual_rows: usize = 0;
+    for rg in 0..reader.num_row_groups() {
+        let mut rg_reader = reader.row_group_reader(rg).unwrap();
+        let batch = rg_reader.read_columns().unwrap();
+        actual_rows += batch.num_rows();
+    }
+    assert_eq!(
+        expected_rows, actual_rows,
+        "row count mismatch for {}",
+        filename
+    );
+
+    // Write to disk
+    fs::create_dir_all(INTEROP_DIR).unwrap();
+    let path = format!("{}/{}", INTEROP_DIR, filename);
+    let mut file = fs::File::create(&path).unwrap();
+    file.write_all(&data).unwrap();
+    file.flush().unwrap();
+    println!(
+        "Wrote {} ({} bytes, {} rows)",
+        path,
+        data.len(),
+        expected_rows
+    );
+
+    data
+}
+
+// ======================== 1. int_data.mosaic ========================
+
+#[test]
+fn test_write_int_data() {
+    let num_rows = 10_000;
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("value", DataType::Int32, false),
+    ]);
+
+    let ids: Vec<i64> = (0..num_rows).map(|i| i as i64).collect();
+    let values: Vec<i32> = (0..num_rows).map(|i| (i * 10) as i32).collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int64Array::from(ids)),
+            Arc::new(Int32Array::from(values)),
+        ],
+    )
+    .unwrap();
+
+    write_and_verify(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+        "int_data.mosaic",
+    );
+    println!("test_write_int_data: PASSED");
+}
+
+// ======================== 2. string_data.mosaic ========================
+
+#[test]
+fn test_write_string_data() {
+    let num_rows = 10_000;
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("name", DataType::Utf8, true),
+        Field::new("data", DataType::Binary, true),
+    ]);
+
+    let ids: Vec<i64> = (0..num_rows).map(|i| i as i64).collect();
+    let names: Vec<Option<String>> = (0..num_rows)
+        .map(|i| {
+            if i % 7 == 0 {
+                None
+            } else {
+                Some(format!("name_{}", i))
+            }
+        })
+        .collect();
+    let name_refs: Vec<Option<&str>> = names.iter().map(|s| s.as_deref()).collect();
+
+    let bin_owned: Vec<Option<Vec<u8>>> = (0..num_rows)
+        .map(|i| {
+            if i % 5 == 0 {
+                None
+            } else {
+                Some(format!("bin_{}", i).into_bytes())
+            }
+        })
+        .collect();
+    let bin_refs: Vec<Option<&[u8]>> = bin_owned
+        .iter()
+        .map(|b| b.as_ref().map(|v| v.as_slice()))
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int64Array::from(ids)),
+            Arc::new(StringArray::from(name_refs)),
+            Arc::new(BinaryArray::from(bin_refs)),
+        ],
+    )
+    .unwrap();
+
+    write_and_verify(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+        "string_data.mosaic",
+    );
+    println!("test_write_string_data: PASSED");
+}
+
+// ======================== 3. all_types.mosaic ========================
+
+#[test]
+fn test_write_all_types() {
+    let num_rows = 5_000;
+    let schema = Schema::new(vec![
+        Field::new("f_bool", DataType::Boolean, true),
+        Field::new("f_int8", DataType::Int8, true),
+        Field::new("f_int16", DataType::Int16, true),
+        Field::new("f_int32", DataType::Int32, true),
+        Field::new("f_int64", DataType::Int64, true),
+        Field::new("f_float32", DataType::Float32, true),
+        Field::new("f_float64", DataType::Float64, true),
+        Field::new("f_date32", DataType::Date32, true),
+        Field::new("f_utf8", DataType::Utf8, true),
+        Field::new("f_binary", DataType::Binary, true),
+        Field::new("f_decimal", DataType::Decimal128(10, 2), true),
+    ]);
+
+    let bools: Vec<Option<bool>> = (0..num_rows)
+        .map(|i| if i % 13 == 0 { None } else { Some(i % 2 == 0) })
+        .collect();
+
+    let i8s: Vec<Option<i8>> = (0..num_rows)
+        .map(|i| {
+            if i % 11 == 0 {
+                None
+            } else {
+                Some((i % 256) as i8)
+            }
+        })
+        .collect();
+
+    let i16s: Vec<Option<i16>> = (0..num_rows)
+        .map(|i| {
+            if i % 17 == 0 {
+                None
+            } else {
+                Some((i % 30000) as i16)
+            }
+        })
+        .collect();
+
+    let i32s: Vec<Option<i32>> = (0..num_rows)
+        .map(|i| {
+            if i % 19 == 0 {
+                None
+            } else {
+                Some(i as i32 * 100)
+            }
+        })
+        .collect();
+
+    let i64s: Vec<Option<i64>> = (0..num_rows)
+        .map(|i| {
+            if i % 23 == 0 {
+                None
+            } else {
+                Some(i as i64 * 1000)
+            }
+        })
+        .collect();
+
+    let f32s: Vec<Option<f32>> = (0..num_rows)
+        .map(|i| {
+            if i % 29 == 0 {
+                None
+            } else {
+                Some(i as f32 * 0.1)
+            }
+        })
+        .collect();
+
+    let f64s: Vec<Option<f64>> = (0..num_rows)
+        .map(|i| {
+            if i % 31 == 0 {
+                None
+            } else {
+                Some(i as f64 * 0.001)
+            }
+        })
+        .collect();
+
+    let dates: Vec<Option<i32>> = (0..num_rows)
+        .map(|i| {
+            if i % 37 == 0 {
+                None
+            } else {
+                Some(18000 + (i % 3650) as i32)
+            }
+        })
+        .collect();
+
+    let str_owned: Vec<Option<String>> = (0..num_rows)
+        .map(|i| {
+            if i % 41 == 0 {
+                None
+            } else {
+                Some(format!("str_{}", i))
+            }
+        })
+        .collect();
+    let str_refs: Vec<Option<&str>> = str_owned.iter().map(|s| s.as_deref()).collect();
+
+    let bin_owned: Vec<Option<Vec<u8>>> = (0..num_rows)
+        .map(|i| {
+            if i % 43 == 0 {
+                None
+            } else {
+                Some(vec![(i % 256) as u8; 4])
+            }
+        })
+        .collect();
+    let bin_refs: Vec<Option<&[u8]>> = bin_owned
+        .iter()
+        .map(|b| b.as_ref().map(|v| v.as_slice()))
+        .collect();
+
+    let decimals: Vec<Option<i128>> = (0..num_rows)
+        .map(|i| {
+            if i % 47 == 0 {
+                None
+            } else {
+                Some(i as i128 * 100)
+            }
+        })
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(BooleanArray::from(bools)),
+            Arc::new(Int8Array::from(i8s)),
+            Arc::new(Int16Array::from(i16s)),
+            Arc::new(Int32Array::from(i32s)),
+            Arc::new(Int64Array::from(i64s)),
+            Arc::new(Float32Array::from(f32s)),
+            Arc::new(Float64Array::from(f64s)),
+            Arc::new(Date32Array::from(dates)),
+            Arc::new(StringArray::from(str_refs)),
+            Arc::new(BinaryArray::from(bin_refs)),
+            Arc::new(
+                Decimal128Array::from(decimals)
+                    .with_precision_and_scale(10, 2)
+                    .unwrap(),
+            ),
+        ],
+    )
+    .unwrap();
+
+    write_and_verify(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+        "all_types.mosaic",
+    );
+    println!("test_write_all_types: PASSED");
+}
+
+// ======================== 4. constant_data.mosaic ========================
+
+#[test]
+fn test_write_constant_data() {
+    let num_rows = 10_000;
+    let schema = Schema::new(vec![
+        Field::new("c_int", DataType::Int64, false),
+        Field::new("c_str", DataType::Utf8, false),
+        Field::new("c_float", DataType::Float64, false),
+    ]);
+
+    let ints: Vec<i64> = vec![42i64; num_rows];
+    let strs: Vec<&str> = vec!["constant_value"; num_rows];
+    let floats: Vec<f64> = vec![3.14; num_rows];
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int64Array::from(ints)),
+            Arc::new(StringArray::from(strs)),
+            Arc::new(Float64Array::from(floats)),
+        ],
+    )
+    .unwrap();
+
+    write_and_verify(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+        "constant_data.mosaic",
+    );
+    println!("test_write_constant_data: PASSED");
+}
+
+// ======================== 5. null_heavy.mosaic ========================
+
+#[test]
+fn test_write_null_heavy() {
+    let num_rows = 10_000;
+    let schema = Schema::new(vec![
+        Field::new("n_int64", DataType::Int64, true),
+        Field::new("n_utf8", DataType::Utf8, true),
+        Field::new("n_float64", DataType::Float64, true),
+    ]);
+
+    // 80% nulls
+    let ints: Vec<Option<i64>> = (0..num_rows)
+        .map(|i| if i % 5 != 0 { None } else { Some(i as i64) })
+        .collect();
+
+    let str_owned: Vec<Option<String>> = (0..num_rows)
+        .map(|i| {
+            if i % 5 != 1 {
+                None
+            } else {
+                Some(format!("val_{}", i))
+            }
+        })
+        .collect();
+    let str_refs: Vec<Option<&str>> = str_owned.iter().map(|s| s.as_deref()).collect();
+
+    let floats: Vec<Option<f64>> = (0..num_rows)
+        .map(|i| {
+            if i % 5 != 2 {
+                None
+            } else {
+                Some(i as f64 * 0.5)
+            }
+        })
+        .collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int64Array::from(ints)),
+            Arc::new(StringArray::from(str_refs)),
+            Arc::new(Float64Array::from(floats)),
+        ],
+    )
+    .unwrap();
+
+    write_and_verify(
+        &schema,
+        &[batch],
+        WriterOptions {
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+        "null_heavy.mosaic",
+    );
+    println!("test_write_null_heavy: PASSED");
+}
+
+// ======================== 6. compressed_none.mosaic ========================
+
+#[test]
+fn test_write_compressed_none() {
+    let num_rows = 10_000;
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("value", DataType::Int32, false),
+    ]);
+
+    let ids: Vec<i64> = (0..num_rows).map(|i| i as i64).collect();
+    let values: Vec<i32> = (0..num_rows).map(|i| (i * 10) as i32).collect();
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int64Array::from(ids)),
+            Arc::new(Int32Array::from(values)),
+        ],
+    )
+    .unwrap();
+
+    write_and_verify(
+        &schema,
+        &[batch],
+        WriterOptions {
+            compression: 0, // COMPRESSION_NONE
+            num_buckets: 1,
+            row_group_max_size: 16 * 1024 * 1024,
+            ..Default::default()
+        },
+        "compressed_none.mosaic",
+    );
+    println!("test_write_compressed_none: PASSED");
+}
+
+// ======================== 7. multi_rg.mosaic ========================
+
+#[test]
+fn test_write_multi_rg() {
+    let num_rows = 10_000;
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("value", DataType::Int32, false),
+    ]);
+
+    // Write in small batches to trigger row group flushes with a tiny max size
+    let batch_size = 100;
+    let num_batches = num_rows / batch_size;
+    let mut batches = Vec::new();
+    for b in 0..num_batches {
+        let start = b * batch_size;
+        let ids: Vec<i64> = (start..start + batch_size).map(|i| i as i64).collect();
+        let values: Vec<i32> = (start..start + batch_size)
+            .map(|i| (i * 10) as i32)
+            .collect();
+        batches.push(
+            RecordBatch::try_new(
+                Arc::new(schema.clone()),
+                vec![
+                    Arc::new(Int64Array::from(ids)),
+                    Arc::new(Int32Array::from(values)),
+                ],
+            )
+            .unwrap(),
+        );
+    }
+
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            compression: 0, // No compression to make data larger
+            num_buckets: 1,
+            row_group_max_size: 1024, // Force multiple row groups
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    for batch in &batches {
+        writer.write_batch(batch).unwrap();
+    }
+    writer.close().unwrap();
+    let data = writer.output().buf.clone();
+
+    // Write to disk
+    fs::create_dir_all(INTEROP_DIR).unwrap();
+    let path = format!("{}/multi_rg.mosaic", INTEROP_DIR);
+    let mut file = fs::File::create(&path).unwrap();
+    file.write_all(&data).unwrap();
+    file.flush().unwrap();
+
+    // Verify by reading back
+    let file_len = data.len() as u64;
+    let input = ByteArrayInputFile { data: data.clone() };
+    let reader_verify = MosaicReader::new(input, file_len).unwrap();
+    let mut actual_rows: usize = 0;
+    for rg in 0..reader_verify.num_row_groups() {
+        let mut rg_reader = reader_verify.row_group_reader(rg).unwrap();
+        let rb = rg_reader.read_columns().unwrap();
+        actual_rows += rb.num_rows();
+    }
+    assert_eq!(
+        num_rows, actual_rows,
+        "row count mismatch for multi_rg.mosaic"
+    );
+    println!("Wrote {} ({} bytes, {} rows)", path, data.len(), num_rows);
+
+    // Verify multiple row groups were created
+    let file_len2 = data.len() as u64;
+    let input2 = ByteArrayInputFile { data };
+    let reader = MosaicReader::new(input2, file_len2).unwrap();
+    assert!(
+        reader.num_row_groups() > 1,
+        "Expected multiple row groups, got {}",
+        reader.num_row_groups()
+    );
+    println!(
+        "test_write_multi_rg: PASSED ({} row groups)",
+        reader.num_row_groups()
+    );
+}
diff --git a/core/tests/massive_data_test.rs b/core/tests/massive_data_test.rs
new file mode 100644
index 0000000..ea12d5b
--- /dev/null
+++ b/core/tests/massive_data_test.rs
@@ -0,0 +1,1164 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#![allow(
+    clippy::approx_constant,
+    clippy::unnecessary_cast,
+    clippy::cloned_ref_to_slice_refs,
+    clippy::needless_range_loop,
+    clippy::manual_is_multiple_of
+)]
+
+use std::io;
+use std::sync::Arc;
+
+use arrow_array::*;
+use arrow_schema::{DataType, Field, Schema, TimeUnit};
+use paimon_mosaic_core::reader::{InputFile, MosaicReader, ReaderAccess};
+use paimon_mosaic_core::writer::{MosaicWriter, OutputFile, WriterOptions};
+
+// ======================== Test Infrastructure ========================
+
+struct MemOutputFile {
+    pub buf: Vec<u8>,
+}
+
+impl MemOutputFile {
+    fn new() -> Self {
+        Self { buf: Vec::new() }
+    }
+}
+
+impl OutputFile for MemOutputFile {
+    fn write(&mut self, data: &[u8]) -> io::Result<()> {
+        self.buf.extend_from_slice(data);
+        Ok(())
+    }
+    fn flush(&mut self) -> io::Result<()> {
+        Ok(())
+    }
+    fn pos(&self) -> u64 {
+        self.buf.len() as u64
+    }
+}
+
+struct ByteArrayInputFile {
+    data: Vec<u8>,
+}
+
+impl InputFile for ByteArrayInputFile {
+    fn read_at(&self, offset: u64, buf: &mut [u8]) -> io::Result<()> {
+        let start = offset as usize;
+        let end = start + buf.len();
+        if end > self.data.len() {
+            return Err(io::Error::new(
+                io::ErrorKind::UnexpectedEof,
+                "read past end",
+            ));
+        }
+        buf.copy_from_slice(&self.data[start..end]);
+        Ok(())
+    }
+}
+
+fn simple_hash(seed: u64, i: usize) -> u64 {
+    let mut x = seed.wrapping_add(i as u64);
+    x ^= x >> 33;
+    x = x.wrapping_mul(0xff51afd7ed558ccd);
+    x ^= x >> 33;
+    x = x.wrapping_mul(0xc4ceb9fe1a85ec53);
+    x ^= x >> 33;
+    x
+}
+
+fn roundtrip(schema: &Schema, batches: &[RecordBatch], options: WriterOptions) -> Vec<RecordBatch> {
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(out, schema, options).unwrap();
+    for batch in batches {
+        writer.write_batch(batch).unwrap();
+    }
+    writer.close().unwrap();
+
+    let data = writer.output().buf.clone();
+    let file_len = data.len() as u64;
+    let input = ByteArrayInputFile { data };
+    let reader = MosaicReader::new(input, file_len).unwrap();
+
+    let mut result = Vec::new();
+    for rg in 0..reader.num_row_groups() {
+        let mut rg_reader = reader.row_group_reader(rg).unwrap();
+        result.push(rg_reader.read_columns().unwrap());
+    }
+    result
+}
+
+fn assert_batches_equal(expected: &[RecordBatch], actual: &[RecordBatch]) {
+    let expected_rows: usize = expected.iter().map(|b| b.num_rows()).sum();
+    let actual_rows: usize = actual.iter().map(|b| b.num_rows()).sum();
+    assert_eq!(expected_rows, actual_rows, "total row count mismatch");
+
+    let mut exp_offset = 0;
+    let mut act_offset = 0;
+    let mut exp_batch_idx = 0;
+    let mut act_batch_idx = 0;
+
+    let num_cols = expected[0].num_columns();
+    let exp_schema = expected[0].schema();
+    let mut row = 0;
+    while row < expected_rows {
+        let exp_batch = &expected[exp_batch_idx];
+        let act_batch = &actual[act_batch_idx];
+        let exp_remaining = exp_batch.num_rows() - exp_offset;
+        let act_remaining = act_batch.num_rows() - act_offset;
+        let chunk = exp_remaining.min(act_remaining);
+
+        for col in 0..num_cols {
+            let col_name = exp_schema.field(col).name();
+            let act_col_idx = act_batch.schema().index_of(col_name).unwrap();
+            let exp_col = exp_batch.column(col).slice(exp_offset, chunk);
+            let act_col = act_batch.column(act_col_idx).slice(act_offset, chunk);
+            assert_eq!(
+                &exp_col,
+                &act_col,
+                "mismatch at column {} rows {}..{}",
+                col_name,
+                row,
+                row + chunk
+            );
+        }
+
+        exp_offset += chunk;
+        act_offset += chunk;
+        row += chunk;
+        if exp_offset == exp_batch.num_rows() {
+            exp_batch_idx += 1;
+            exp_offset = 0;
+        }
+        if act_offset == act_batch.num_rows() {
+            act_batch_idx += 1;
+            act_offset = 0;
+        }
+    }
+}
+
+// ======================== Test 1: 10M sequential Int64 ========================
+
+#[test]
+fn test_10_million_int64_sequential() {
+    let num_rows = 10_000_000usize;
+    let batch_size = 500_000usize;
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("value", DataType::Int64, false),
+    ]);
+
+    let mut batches = Vec::new();
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+        let ids: Vec<i64> = (batch_start as i64..(batch_start + count) as i64).collect();
+        let values: Vec<i64> = (0..count)
+            .map(|i| (batch_start + i) as i64 * 7 + 3)
+            .collect();
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int64Array::from(ids)),
+                Arc::new(Int64Array::from(values)),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    println!(
+        "test_10_million_int64_sequential: writing {} rows...",
+        num_rows
+    );
+
+    let result = roundtrip(
+        &schema,
+        &batches,
+        WriterOptions {
+            num_buckets: 10,
+            row_group_max_size: 32 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    println!(
+        "test_10_million_int64_sequential: verifying {} row groups...",
+        result.len()
+    );
+
+    assert_batches_equal(&batches, &result);
+    println!("test_10_million_int64_sequential: PASSED");
+}
+
+// ======================== Test 2: 5M mixed types random ========================
+
+#[test]
+fn test_5_million_mixed_types_random() {
+    let num_rows = 5_000_000usize;
+    let batch_size = 250_000usize;
+    let schema = Schema::new(vec![
+        Field::new("i32_col", DataType::Int32, true),
+        Field::new("i64_col", DataType::Int64, true),
+        Field::new("f64_col", DataType::Float64, true),
+        Field::new("str_col", DataType::Utf8, true),
+        Field::new("bool_col", DataType::Boolean, true),
+        Field::new("bin_col", DataType::Binary, true),
+    ]);
+
+    let mut batches = Vec::new();
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+
+        let i32_vals: Vec<Option<i32>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                let h = simple_hash(1, idx);
+                if h % 11 == 0 {
+                    None
+                } else {
+                    Some(h as i32)
+                }
+            })
+            .collect();
+
+        let i64_vals: Vec<Option<i64>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                let h = simple_hash(2, idx);
+                if h % 13 == 0 {
+                    None
+                } else {
+                    Some(h as i64)
+                }
+            })
+            .collect();
+
+        let f64_vals: Vec<Option<f64>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                let h = simple_hash(3, idx);
+                if h % 9 == 0 {
+                    None
+                } else {
+                    Some(h as f64 / 1000.0)
+                }
+            })
+            .collect();
+
+        let str_vals: Vec<Option<String>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                let h = simple_hash(4, idx);
+                if h % 7 == 0 {
+                    None
+                } else {
+                    let len = (h % 20) as usize + 1;
+                    let s: String = (0..len)
+                        .map(|j| (b'a' + (simple_hash(5, idx * 20 + j) % 26) as u8) as char)
+                        .collect();
+                    Some(s)
+                }
+            })
+            .collect();
+        let str_refs: Vec<Option<&str>> = str_vals.iter().map(|s| s.as_deref()).collect();
+
+        let bool_vals: Vec<Option<bool>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                let h = simple_hash(6, idx);
+                if h % 8 == 0 {
+                    None
+                } else {
+                    Some(h % 2 == 0)
+                }
+            })
+            .collect();
+
+        let bin_vals: Vec<Option<Vec<u8>>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                let h = simple_hash(7, idx);
+                if h % 10 == 0 {
+                    None
+                } else {
+                    let len = (h % 16) as usize + 1;
+                    Some(
+                        (0..len)
+                            .map(|j| simple_hash(8, idx * 16 + j) as u8)
+                            .collect(),
+                    )
+                }
+            })
+            .collect();
+        let bin_refs: Vec<Option<&[u8]>> = bin_vals
+            .iter()
+            .map(|b| b.as_ref().map(|v| v.as_slice()))
+            .collect();
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int32Array::from(i32_vals)),
+                Arc::new(Int64Array::from(i64_vals)),
+                Arc::new(Float64Array::from(f64_vals)),
+                Arc::new(StringArray::from(str_refs)),
+                Arc::new(BooleanArray::from(bool_vals)),
+                Arc::new(BinaryArray::from(bin_refs)),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    println!(
+        "test_5_million_mixed_types_random: writing {} rows...",
+        num_rows
+    );
+
+    let result = roundtrip(
+        &schema,
+        &batches,
+        WriterOptions {
+            num_buckets: 15,
+            row_group_max_size: 32 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    println!(
+        "test_5_million_mixed_types_random: verifying {} row groups...",
+        result.len()
+    );
+
+    assert_batches_equal(&batches, &result);
+    println!("test_5_million_mixed_types_random: PASSED");
+}
+
+// ======================== Test 3: 2M all same value (CONST encoding) ========================
+
+#[test]
+fn test_2_million_all_same_value() {
+    let num_rows = 2_000_000usize;
+    let batch_size = 500_000usize;
+    let schema = Schema::new(vec![
+        Field::new("const_i32", DataType::Int32, false),
+        Field::new("const_i64", DataType::Int64, false),
+        Field::new("const_f64", DataType::Float64, false),
+        Field::new("const_str", DataType::Utf8, false),
+        Field::new("const_bool", DataType::Boolean, false),
+        Field::new("const_bin", DataType::Binary, false),
+    ]);
+
+    let mut batches = Vec::new();
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int32Array::from(vec![42i32; count])),
+                Arc::new(Int64Array::from(vec![999_999_999i64; count])),
+                Arc::new(Float64Array::from(vec![3.14159; count])),
+                Arc::new(StringArray::from(vec!["constant_value"; count])),
+                Arc::new(BooleanArray::from(vec![true; count])),
+                Arc::new(BinaryArray::from(vec![
+                    &[0xDE, 0xAD, 0xBE, 0xEF][..];
+                    count
+                ])),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    println!(
+        "test_2_million_all_same_value: writing {} rows...",
+        num_rows
+    );
+
+    let out = MemOutputFile::new();
+    let mut writer = MosaicWriter::new(
+        out,
+        &schema,
+        WriterOptions {
+            num_buckets: 6,
+            row_group_max_size: 64 * 1024 * 1024,
+            ..Default::default()
+        },
+    )
+    .unwrap();
+    for batch in &batches {
+        writer.write_batch(batch).unwrap();
+    }
+    writer.close().unwrap();
+
+    let data = writer.output().buf.clone();
+    let file_size = data.len();
+    println!(
+        "test_2_million_all_same_value: file size = {} bytes ({} KB) for {} rows",
+        file_size,
+        file_size / 1024,
+        num_rows
+    );
+
+    // CONST encoding should make this extremely small -- well under 1MB
+    assert!(
+        file_size < 1024 * 1024,
+        "file size {} bytes is too large for constant columns (expected < 1MB)",
+        file_size
+    );
+
+    let file_len = data.len() as u64;
+    let input = ByteArrayInputFile { data };
+    let reader = MosaicReader::new(input, file_len).unwrap();
+
+    let mut result = Vec::new();
+    for rg in 0..reader.num_row_groups() {
+        let mut rg_reader = reader.row_group_reader(rg).unwrap();
+        result.push(rg_reader.read_columns().unwrap());
+    }
+
+    assert_batches_equal(&batches, &result);
+    println!("test_2_million_all_same_value: PASSED");
+}
+
+// ======================== Test 4: 1000 columns, 100K rows ========================
+
+#[test]
+fn test_1000_columns_100k_rows() {
+    let num_cols = 1000usize;
+    let num_rows = 100_000usize;
+    let batch_size = 25_000usize;
+
+    let fields: Vec<Field> = (0..num_cols)
+        .map(|i| Field::new(format!("c_{:04}", i), DataType::Int32, true))
+        .collect();
+    let schema = Schema::new(fields);
+
+    let mut batches = Vec::new();
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+
+        let arrays: Vec<Arc<dyn Array>> = (0..num_cols)
+            .map(|col| {
+                let vals: Vec<Option<i32>> = (0..count)
+                    .map(|i| {
+                        let idx = batch_start + i;
+                        let h = simple_hash(col as u64, idx);
+                        if h % 13 == 0 {
+                            None
+                        } else {
+                            Some(h as i32)
+                        }
+                    })
+                    .collect();
+                Arc::new(Int32Array::from(vals)) as Arc<dyn Array>
+            })
+            .collect();
+
+        batches.push(RecordBatch::try_new(Arc::new(schema.clone()), arrays).unwrap());
+    }
+
+    println!(
+        "test_1000_columns_100k_rows: writing {} cols x {} rows...",
+        num_cols, num_rows
+    );
+
+    let result = roundtrip(
+        &schema,
+        &batches,
+        WriterOptions {
+            num_buckets: 100,
+            row_group_max_size: 64 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    println!(
+        "test_1000_columns_100k_rows: verifying {} row groups...",
+        result.len()
+    );
+
+    assert_batches_equal(&batches, &result);
+    println!("test_1000_columns_100k_rows: PASSED");
+}
+
+// ======================== Test 5: 500K rows large strings ========================
+
+#[test]
+fn test_500k_rows_large_strings() {
+    let num_rows = 500_000usize;
+    let batch_size = 50_000usize;
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("big_str", DataType::Utf8, true),
+    ]);
+
+    let mut batches = Vec::new();
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+
+        let ids: Vec<i64> = (batch_start as i64..(batch_start + count) as i64).collect();
+
+        let str_vals: Vec<Option<String>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                let h = simple_hash(10, idx);
+                if h % 20 == 0 {
+                    None
+                } else {
+                    // String length between 100 and 1000
+                    let len = 100 + (h % 901) as usize;
+                    let s: String = (0..len)
+                        .map(|j| (b'A' + (simple_hash(11, idx * 1000 + j) % 26) as u8) as char)
+                        .collect();
+                    Some(s)
+                }
+            })
+            .collect();
+        let str_refs: Vec<Option<&str>> = str_vals.iter().map(|s| s.as_deref()).collect();
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int64Array::from(ids)),
+                Arc::new(StringArray::from(str_refs)),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    println!("test_500k_rows_large_strings: writing {} rows...", num_rows);
+
+    let result = roundtrip(
+        &schema,
+        &batches,
+        WriterOptions {
+            num_buckets: 10,
+            row_group_max_size: 32 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    println!(
+        "test_500k_rows_large_strings: verifying {} row groups...",
+        result.len()
+    );
+
+    assert_batches_equal(&batches, &result);
+    println!("test_500k_rows_large_strings: PASSED");
+}
+
+// ======================== Test 6: Monotonic sequential data ========================
+
+#[test]
+fn test_monotonic_sequential_data() {
+    let num_rows = 3_000_000usize;
+    let batch_size = 300_000usize;
+    let schema = Schema::new(vec![
+        Field::new("seq_i64", DataType::Int64, false),
+        Field::new("seq_f64", DataType::Float64, false),
+        Field::new("seq_date", DataType::Date32, false),
+    ]);
+
+    let mut batches = Vec::new();
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+
+        let i64_vals: Vec<i64> = (0..count)
+            .map(|i| (batch_start + i) as i64 * 3 + 100)
+            .collect();
+        let f64_vals: Vec<f64> = (0..count)
+            .map(|i| (batch_start + i) as f64 * 0.001 + 1.0)
+            .collect();
+        let date_vals: Vec<i32> = (0..count)
+            .map(|i| 18000 + (batch_start + i) as i32)
+            .collect();
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int64Array::from(i64_vals)),
+                Arc::new(Float64Array::from(f64_vals)),
+                Arc::new(Date32Array::from(date_vals)),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    println!(
+        "test_monotonic_sequential_data: writing {} rows...",
+        num_rows
+    );
+
+    let result = roundtrip(
+        &schema,
+        &batches,
+        WriterOptions {
+            num_buckets: 10,
+            row_group_max_size: 32 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    println!(
+        "test_monotonic_sequential_data: verifying {} row groups...",
+        result.len()
+    );
+
+    assert_batches_equal(&batches, &result);
+    println!("test_monotonic_sequential_data: PASSED");
+}
+
+// ======================== Test 7: Repeated pattern data ========================
+
+#[test]
+fn test_repeated_pattern_data() {
+    let num_rows = 2_000_000usize;
+    let batch_size = 250_000usize;
+    let schema = Schema::new(vec![
+        Field::new("pattern_7", DataType::Int32, false),
+        Field::new("pattern_13", DataType::Utf8, false),
+        Field::new("pattern_100", DataType::Int64, false),
+    ]);
+
+    let pattern_13_strs: Vec<String> = (0..13).map(|i| format!("pat_{:02}", i)).collect();
+
+    let mut batches = Vec::new();
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+
+        let p7_vals: Vec<i32> = (0..count)
+            .map(|i| ((batch_start + i) % 7) as i32 * 100 + 10)
+            .collect();
+
+        let p13_vals: Vec<&str> = (0..count)
+            .map(|i| pattern_13_strs[(batch_start + i) % 13].as_str())
+            .collect();
+
+        let p100_vals: Vec<i64> = (0..count)
+            .map(|i| ((batch_start + i) % 100) as i64 * 9999 + 1)
+            .collect();
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int32Array::from(p7_vals)),
+                Arc::new(StringArray::from(p13_vals)),
+                Arc::new(Int64Array::from(p100_vals)),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    println!("test_repeated_pattern_data: writing {} rows...", num_rows);
+
+    let result = roundtrip(
+        &schema,
+        &batches,
+        WriterOptions {
+            num_buckets: 8,
+            row_group_max_size: 32 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    println!(
+        "test_repeated_pattern_data: verifying {} row groups...",
+        result.len()
+    );
+
+    assert_batches_equal(&batches, &result);
+    println!("test_repeated_pattern_data: PASSED");
+}
+
+// ======================== Test 8: Alternating null data ========================
+
+#[test]
+fn test_alternating_null_data() {
+    let num_rows = 1_000_000usize;
+    let batch_size = 200_000usize;
+    let schema = Schema::new(vec![
+        Field::new("every_other", DataType::Int32, true),
+        Field::new("every_3rd", DataType::Int64, true),
+        Field::new("every_5th", DataType::Utf8, true),
+        Field::new("every_10th", DataType::Float64, true),
+        Field::new("every_100th", DataType::Boolean, true),
+    ]);
+
+    let mut batches = Vec::new();
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+
+        let every_other: Vec<Option<i32>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 2 == 0 {
+                    None
+                } else {
+                    Some(idx as i32)
+                }
+            })
+            .collect();
+
+        let every_3rd: Vec<Option<i64>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 3 == 0 {
+                    None
+                } else {
+                    Some(idx as i64 * 7)
+                }
+            })
+            .collect();
+
+        let every_5th_vals: Vec<Option<String>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 5 == 0 {
+                    None
+                } else {
+                    Some(format!("v_{}", idx % 50))
+                }
+            })
+            .collect();
+        let every_5th_refs: Vec<Option<&str>> =
+            every_5th_vals.iter().map(|s| s.as_deref()).collect();
+
+        let every_10th: Vec<Option<f64>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 10 == 0 {
+                    None
+                } else {
+                    Some(idx as f64 * 1.5)
+                }
+            })
+            .collect();
+
+        let every_100th: Vec<Option<bool>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 100 == 0 {
+                    None
+                } else {
+                    Some(idx % 2 == 0)
+                }
+            })
+            .collect();
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int32Array::from(every_other)),
+                Arc::new(Int64Array::from(every_3rd)),
+                Arc::new(StringArray::from(every_5th_refs)),
+                Arc::new(Float64Array::from(every_10th)),
+                Arc::new(BooleanArray::from(every_100th)),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    println!("test_alternating_null_data: writing {} rows...", num_rows);
+
+    let result = roundtrip(
+        &schema,
+        &batches,
+        WriterOptions {
+            num_buckets: 10,
+            row_group_max_size: 32 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    println!(
+        "test_alternating_null_data: verifying {} row groups...",
+        result.len()
+    );
+
+    assert_batches_equal(&batches, &result);
+    println!("test_alternating_null_data: PASSED");
+}
+
+// ======================== Test 9: Massive binary data (~100MB raw) ========================
+
+#[test]
+fn test_massive_binary_data() {
+    let num_rows = 200_000usize;
+    let batch_size = 10_000usize;
+    let schema = Schema::new(vec![
+        Field::new("id", DataType::Int64, false),
+        Field::new("blob", DataType::Binary, true),
+    ]);
+
+    let mut batches = Vec::new();
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+
+        let ids: Vec<i64> = (batch_start as i64..(batch_start + count) as i64).collect();
+
+        let bin_vals: Vec<Option<Vec<u8>>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                let h = simple_hash(20, idx);
+                if h % 25 == 0 {
+                    None
+                } else {
+                    // Average ~500 bytes (range 200-800)
+                    let len = 200 + (h % 601) as usize;
+                    Some(
+                        (0..len)
+                            .map(|j| simple_hash(21, idx * 800 + j) as u8)
+                            .collect(),
+                    )
+                }
+            })
+            .collect();
+        let bin_refs: Vec<Option<&[u8]>> = bin_vals
+            .iter()
+            .map(|b| b.as_ref().map(|v| v.as_slice()))
+            .collect();
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(Int64Array::from(ids)),
+                Arc::new(BinaryArray::from(bin_refs)),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    println!("test_massive_binary_data: writing {} rows...", num_rows);
+
+    let result = roundtrip(
+        &schema,
+        &batches,
+        WriterOptions {
+            num_buckets: 5,
+            row_group_max_size: 32 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    println!(
+        "test_massive_binary_data: verifying {} row groups...",
+        result.len()
+    );
+
+    assert_batches_equal(&batches, &result);
+    println!("test_massive_binary_data: PASSED");
+}
+
+// ======================== Test 10: 10M rows all types ========================
+
+#[test]
+fn test_all_types_10_million() {
+    let num_rows = 10_000_000usize;
+    let batch_size = 500_000usize;
+    let schema = Schema::new(vec![
+        Field::new("bool_col", DataType::Boolean, true),
+        Field::new("i8_col", DataType::Int8, true),
+        Field::new("i16_col", DataType::Int16, true),
+        Field::new("i32_col", DataType::Int32, true),
+        Field::new("i64_col", DataType::Int64, true),
+        Field::new("f32_col", DataType::Float32, true),
+        Field::new("f64_col", DataType::Float64, true),
+        Field::new("date_col", DataType::Date32, true),
+        Field::new("time_col", DataType::Time32(TimeUnit::Millisecond), true),
+        Field::new("str_col", DataType::Utf8, true),
+        Field::new("bin_col", DataType::Binary, true),
+        Field::new("dec_small", DataType::Decimal128(10, 2), true),
+        Field::new("dec_large", DataType::Decimal128(38, 10), true),
+        Field::new(
+            "ts_ms_col",
+            DataType::Timestamp(TimeUnit::Millisecond, None),
+            true,
+        ),
+        Field::new(
+            "ts_us_col",
+            DataType::Timestamp(TimeUnit::Microsecond, None),
+            true,
+        ),
+        Field::new(
+            "ts_ns_col",
+            DataType::Timestamp(TimeUnit::Nanosecond, None),
+            true,
+        ),
+    ]);
+
+    let mut batches = Vec::new();
+    for batch_start in (0..num_rows).step_by(batch_size) {
+        let end = (batch_start + batch_size).min(num_rows);
+        let count = end - batch_start;
+
+        let bools: Vec<Option<bool>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 10 == 0 {
+                    None
+                } else {
+                    Some(idx % 2 == 0)
+                }
+            })
+            .collect();
+
+        let i8s: Vec<Option<i8>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 15 == 0 {
+                    None
+                } else {
+                    Some((idx % 256) as i8)
+                }
+            })
+            .collect();
+
+        let i16s: Vec<Option<i16>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 12 == 0 {
+                    None
+                } else {
+                    Some((idx % 30000) as i16)
+                }
+            })
+            .collect();
+
+        let i32s: Vec<Option<i32>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 9 == 0 {
+                    None
+                } else {
+                    Some(idx as i32 * 3)
+                }
+            })
+            .collect();
+
+        let i64s: Vec<Option<i64>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 8 == 0 {
+                    None
+                } else {
+                    Some(idx as i64 * 1_000_000)
+                }
+            })
+            .collect();
+
+        let f32s: Vec<Option<f32>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 14 == 0 {
+                    None
+                } else {
+                    Some(idx as f32 * 0.1)
+                }
+            })
+            .collect();
+
+        let f64s: Vec<Option<f64>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 11 == 0 {
+                    None
+                } else {
+                    Some(idx as f64 * 3.14159)
+                }
+            })
+            .collect();
+
+        let dates: Vec<Option<i32>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 20 == 0 {
+                    None
+                } else {
+                    Some(18000 + idx as i32 % 3650)
+                }
+            })
+            .collect();
+
+        let times: Vec<Option<i32>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 25 == 0 {
+                    None
+                } else {
+                    Some((idx as i32 % 86_400_000).abs())
+                }
+            })
+            .collect();
+
+        let strings: Vec<Option<String>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 6 == 0 {
+                    None
+                } else {
+                    Some(format!("r_{:08}", idx))
+                }
+            })
+            .collect();
+        let str_refs: Vec<Option<&str>> = strings.iter().map(|s| s.as_deref()).collect();
+
+        let binaries: Vec<Option<Vec<u8>>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 7 == 0 {
+                    None
+                } else {
+                    let len = idx % 32 + 1;
+                    Some((0..len).map(|j| ((idx + j) % 256) as u8).collect())
+                }
+            })
+            .collect();
+        let bin_refs: Vec<Option<&[u8]>> = binaries
+            .iter()
+            .map(|b| b.as_ref().map(|v| v.as_slice()))
+            .collect();
+
+        let dec_small: Vec<Option<i128>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 13 == 0 {
+                    None
+                } else {
+                    Some(idx as i128 * 100 + 99)
+                }
+            })
+            .collect();
+
+        let dec_large: Vec<Option<i128>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 17 == 0 {
+                    None
+                } else {
+                    Some(idx as i128 * 10_000_000_000i128 + 123_456_789)
+                }
+            })
+            .collect();
+
+        let ts_ms: Vec<Option<i64>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 16 == 0 {
+                    None
+                } else {
+                    Some(1_700_000_000_000i64 + idx as i64 * 1000)
+                }
+            })
+            .collect();
+
+        let ts_us: Vec<Option<i64>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 18 == 0 {
+                    None
+                } else {
+                    Some(1_700_000_000_000_000i64 + idx as i64)
+                }
+            })
+            .collect();
+
+        let ts_ns: Vec<Option<i64>> = (0..count)
+            .map(|i| {
+                let idx = batch_start + i;
+                if idx % 21 == 0 {
+                    None
+                } else {
+                    let millis = 1_700_000_000_000i64 + idx as i64;
+                    let nanos = (idx % 1_000_000) as i32;
+                    Some(paimon_mosaic_core::types::millis_nanos_to_ns(millis, nanos).unwrap())
+                }
+            })
+            .collect();
+
+        let batch = RecordBatch::try_new(
+            Arc::new(schema.clone()),
+            vec![
+                Arc::new(BooleanArray::from(bools)),
+                Arc::new(Int8Array::from(i8s)),
+                Arc::new(Int16Array::from(i16s)),
+                Arc::new(Int32Array::from(i32s)),
+                Arc::new(Int64Array::from(i64s)),
+                Arc::new(Float32Array::from(f32s)),
+                Arc::new(Float64Array::from(f64s)),
+                Arc::new(Date32Array::from(dates)),
+                Arc::new(Time32MillisecondArray::from(times)),
+                Arc::new(StringArray::from(str_refs)),
+                Arc::new(BinaryArray::from(bin_refs)),
+                Arc::new(
+                    Decimal128Array::from(dec_small)
+                        .with_precision_and_scale(10, 2)
+                        .unwrap(),
+                ),
+                Arc::new(
+                    Decimal128Array::from(dec_large)
+                        .with_precision_and_scale(38, 10)
+                        .unwrap(),
+                ),
+                Arc::new(TimestampMillisecondArray::from(ts_ms)),
+                Arc::new(TimestampMicrosecondArray::from(ts_us)),
+                Arc::new(TimestampNanosecondArray::from(ts_ns)),
+            ],
+        )
+        .unwrap();
+        batches.push(batch);
+    }
+
+    println!("test_all_types_10_million: writing {} rows...", num_rows);
+
+    let result = roundtrip(
+        &schema,
+        &batches,
+        WriterOptions {
+            num_buckets: 20,
+            row_group_max_size: 64 * 1024 * 1024,
+            ..Default::default()
+        },
+    );
+
+    println!(
+        "test_all_types_10_million: verifying {} row groups...",
+        result.len()
+    );
+
+    assert_batches_equal(&batches, &result);
+    println!("test_all_types_10_million: PASSED");
+}
diff --git a/java/src/test/java/org/apache/paimon/mosaic/MosaicComprehensiveTest.java b/java/src/test/java/org/apache/paimon/mosaic/MosaicComprehensiveTest.java
new file mode 100644
index 0000000..796845f
--- /dev/null
+++ b/java/src/test/java/org/apache/paimon/mosaic/MosaicComprehensiveTest.java
@@ -0,0 +1,737 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.paimon.mosaic;
+
+import java.io.ByteArrayOutputStream;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
+
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.RootAllocator;
+import org.apache.arrow.vector.BigIntVector;
+import org.apache.arrow.vector.BitVector;
+import org.apache.arrow.vector.DecimalVector;
+import org.apache.arrow.vector.Float8Vector;
+import org.apache.arrow.vector.IntVector;
+import org.apache.arrow.vector.VarCharVector;
+import org.apache.arrow.vector.VectorSchemaRoot;
+import org.apache.arrow.vector.types.FloatingPointPrecision;
+import org.apache.arrow.vector.types.pojo.ArrowType;
+import org.apache.arrow.vector.types.pojo.Field;
+import org.apache.arrow.vector.types.pojo.Schema;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class MosaicComprehensiveTest {
+
+    private BufferAllocator allocator;
+
+    @Before
+    public void setUp() {
+        allocator = new RootAllocator();
+    }
+
+    @After
+    public void tearDown() {
+        allocator.close();
+    }
+
+    private byte[] writeToBytes(Schema schema, java.util.function.Consumer<MosaicWriter> writeFn) {
+        return writeToBytes(schema, new WriterOptions(), writeFn);
+    }
+
+    private byte[] writeToBytes(Schema schema, WriterOptions opts, java.util.function.Consumer<MosaicWriter> writeFn) {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        try (MosaicWriter writer = new MosaicWriter(baos, schema, opts, allocator)) {
+            writeFn.accept(writer);
+        }
+        return baos.toByteArray();
+    }
+
+    private MosaicReader readerFromBytes(byte[] data) {
+        InputFile inputFile = (position, buffer, offset, length) -> {
+            System.arraycopy(data, (int) position, buffer, offset, length);
+        };
+        return MosaicReader.open(inputFile, data.length, allocator);
+    }
+
+    // Test 1: Large data roundtrip with 1M rows
+    @Test
+    public void testLargeDataRoundtrip() {
+        Schema arrowSchema = new Schema(Arrays.asList(
+                Field.nullable("id", new ArrowType.Int(64, true)),
+                Field.nullable("name", ArrowType.Utf8.INSTANCE),
+                Field.nullable("score", new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)),
+                Field.nullable("flag", ArrowType.Bool.INSTANCE)
+        ));
+
+        int totalRows = 1_000_000;
+        int batchSize = 50_000;
+
+        byte[] data = writeToBytes(arrowSchema, writer -> {
+            for (int start = 0; start < totalRows; start += batchSize) {
+                int count = Math.min(batchSize, totalRows - start);
+                try (VectorSchemaRoot root = VectorSchemaRoot.create(arrowSchema, allocator)) {
+                    BigIntVector ids = (BigIntVector) root.getVector("id");
+                    VarCharVector names = (VarCharVector) root.getVector("name");
+                    Float8Vector scores = (Float8Vector) root.getVector("score");
+                    BitVector flags = (BitVector) root.getVector("flag");
+
+                    ids.allocateNew(count);
+                    names.allocateNew(count);
+                    scores.allocateNew(count);
+                    flags.allocateNew(count);
+
+                    for (int i = 0; i < count; i++) {
+                        long val = start + i;
+                        ids.set(i, val);
+                        names.setSafe(i, ("row_" + val).getBytes());
+                        scores.set(i, val * 0.001);
+                        flags.set(i, (int) (val % 2));
+                    }
+                    root.setRowCount(count);
+                    writer.write(root);
+                }
+            }
+        });
+
+        assertTrue("File should have data", data.length > 0);
+
+        try (MosaicReader reader = readerFromBytes(data)) {
+            int readRows = 0;
+            for (int rg = 0; rg < reader.numRowGroups(); rg++) {
+                try (VectorSchemaRoot batch = reader.readRowGroup(rg, allocator)) {
+                    BigIntVector ids = (BigIntVector) batch.getVector("id");
+                    VarCharVector names = (VarCharVector) batch.getVector("name");
+                    Float8Vector scores = (Float8Vector) batch.getVector("score");
+                    BitVector flags = (BitVector) batch.getVector("flag");
+
+                    for (int i = 0; i < batch.getRowCount(); i++) {
+                        long id = ids.get(i);
+                        assertEquals("row_" + id, new String(names.get(i)));
+                        assertEquals(id * 0.001, scores.get(i), 1e-9);
+                        assertEquals((int) (id % 2), flags.get(i));
+                    }
+                    readRows += batch.getRowCount();
+                }
+            }
+            assertEquals(totalRows, readRows);
+        }
+    }
+
+    // Test 2: All constant values - should produce small file
+    @Test
+    public void testAllConstantValues() {
+        Schema arrowSchema = new Schema(Arrays.asList(
+                Field.nullable("id", new ArrowType.Int(64, true)),
+                Field.nullable("name", ArrowType.Utf8.INSTANCE),
+                Field.nullable("score", new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)),
+                Field.nullable("flag", ArrowType.Bool.INSTANCE)
+        ));
+
+        int totalRows = 500_000;
+        int batchSize = 50_000;
+
+        byte[] data = writeToBytes(arrowSchema, writer -> {
+            for (int start = 0; start < totalRows; start += batchSize) {
+                int count = Math.min(batchSize, totalRows - start);
+                try (VectorSchemaRoot root = VectorSchemaRoot.create(arrowSchema, allocator)) {
+                    BigIntVector ids = (BigIntVector) root.getVector("id");
+                    VarCharVector names = (VarCharVector) root.getVector("name");
+                    Float8Vector scores = (Float8Vector) root.getVector("score");
+                    BitVector flags = (BitVector) root.getVector("flag");
+
+                    ids.allocateNew(count);
+                    names.allocateNew(count);
+                    scores.allocateNew(count);
+                    flags.allocateNew(count);
+
+                    for (int i = 0; i < count; i++) {
+                        ids.set(i, 42L);
+                        names.setSafe(i, "constant".getBytes());
+                        scores.set(i, 3.14);
+                        flags.set(i, 1);
+                    }
+                    root.setRowCount(count);
+                    writer.write(root);
+                }
+            }
+        });
+
+        // Constant data should compress very well
+        // A naive uncompressed representation would be at least 500K * (8+8+8+1) = ~12.5MB
+        // With compression it should be much smaller
+        assertTrue("Constant data file should be very small (got " + data.length + " bytes)",
+                data.length < 500_000);
+
+        // Verify data reads back correctly
+        try (MosaicReader reader = readerFromBytes(data)) {
+            int readRows = 0;
+            for (int rg = 0; rg < reader.numRowGroups(); rg++) {
+                try (VectorSchemaRoot batch = reader.readRowGroup(rg, allocator)) {
+                    for (int i = 0; i < batch.getRowCount(); i++) {
+                        assertEquals(42L, ((BigIntVector) batch.getVector("id")).get(i));
+                        assertEquals("constant", new String(((VarCharVector) batch.getVector("name")).get(i)));
+                        assertEquals(3.14, ((Float8Vector) batch.getVector("score")).get(i), 1e-9);
+                        assertEquals(1, ((BitVector) batch.getVector("flag")).get(i));
+                    }
+                    readRows += batch.getRowCount();
+                }
+            }
+            assertEquals(totalRows, readRows);
+        }
+    }
+
+    // Test 3: High null rate (95%)
+    @Test
+    public void testHighNullRate() {
+        Schema arrowSchema = new Schema(Arrays.asList(
+                Field.nullable("id", new ArrowType.Int(64, true)),
+                Field.nullable("name", ArrowType.Utf8.INSTANCE),
+                Field.nullable("score", new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE))
+        ));
+
+        int totalRows = 500_000;
+        int batchSize = 50_000;
+        Random rng = new Random(12345);
+
+        byte[] data = writeToBytes(arrowSchema, writer -> {
+            Random localRng = new Random(12345);
+            for (int start = 0; start < totalRows; start += batchSize) {
+                int count = Math.min(batchSize, totalRows - start);
+                try (VectorSchemaRoot root = VectorSchemaRoot.create(arrowSchema, allocator)) {
+                    BigIntVector ids = (BigIntVector) root.getVector("id");
+                    VarCharVector names = (VarCharVector) root.getVector("name");
+                    Float8Vector scores = (Float8Vector) root.getVector("score");
+
+                    ids.allocateNew(count);
+                    names.allocateNew(count);
+                    scores.allocateNew(count);
+
+                    for (int i = 0; i < count; i++) {
+                        long val = start + i;
+                        if (localRng.nextDouble() < 0.95) {
+                            ids.setNull(i);
+                        } else {
+                            ids.set(i, val);
+                        }
+                        if (localRng.nextDouble() < 0.95) {
+                            names.setNull(i);
+                        } else {
+                            names.setSafe(i, ("name_" + val).getBytes());
+                        }
+                        if (localRng.nextDouble() < 0.95) {
+                            scores.setNull(i);
+                        } else {
+                            scores.set(i, val * 0.5);
+                        }
+                    }
+                    root.setRowCount(count);
+                    writer.write(root);
+                }
+            }
+        });
+
+        // Verify roundtrip
+        Random verifyRng = new Random(12345);
+        try (MosaicReader reader = readerFromBytes(data)) {
+            int readRows = 0;
+            for (int rg = 0; rg < reader.numRowGroups(); rg++) {
+                try (VectorSchemaRoot batch = reader.readRowGroup(rg, allocator)) {
+                    BigIntVector ids = (BigIntVector) batch.getVector("id");
+                    VarCharVector names = (VarCharVector) batch.getVector("name");
+                    Float8Vector scores = (Float8Vector) batch.getVector("score");
+
+                    for (int i = 0; i < batch.getRowCount(); i++) {
+                        long val = readRows + i;
+                        boolean idNull = verifyRng.nextDouble() < 0.95;
+                        boolean nameNull = verifyRng.nextDouble() < 0.95;
+                        boolean scoreNull = verifyRng.nextDouble() < 0.95;
+
+                        assertEquals("id null mismatch at row " + val, idNull, ids.isNull(i));
+                        if (!idNull) {
+                            assertEquals(val, ids.get(i));
+                        }
+                        assertEquals("name null mismatch at row " + val, nameNull, names.isNull(i));
+                        if (!nameNull) {
+                            assertEquals("name_" + val, new String(names.get(i)));
+                        }
+                        assertEquals("score null mismatch at row " + val, scoreNull, scores.isNull(i));
+                        if (!scoreNull) {
+                            assertEquals(val * 0.5, scores.get(i), 1e-9);
+                        }
+                    }
+                    readRows += batch.getRowCount();
+                }
+            }
+            assertEquals(totalRows, readRows);
+        }
+    }
+
+    // Test 4: Wide table with 100 columns
+    @Test
+    public void testWideTable() {
+        int numCols = 100;
+        int totalRows = 50_000;
+
+        List<Field> fields = new ArrayList<>();
+        for (int c = 0; c < numCols; c++) {
+            switch (c % 4) {
+                case 0:
+                    fields.add(Field.nullable("col_" + c, new ArrowType.Int(32, true)));
+                    break;
+                case 1:
+                    fields.add(Field.nullable("col_" + c, new ArrowType.Int(64, true)));
+                    break;
+                case 2:
+                    fields.add(Field.nullable("col_" + c, new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)));
+                    break;
+                case 3:
+                    fields.add(Field.nullable("col_" + c, ArrowType.Utf8.INSTANCE));
+                    break;
+            }
+        }
+        Schema arrowSchema = new Schema(fields);
+
+        int batchSize = 10_000;
+        byte[] data = writeToBytes(arrowSchema, writer -> {
+            for (int start = 0; start < totalRows; start += batchSize) {
+                int count = Math.min(batchSize, totalRows - start);
+                try (VectorSchemaRoot root = VectorSchemaRoot.create(arrowSchema, allocator)) {
+                    for (int c = 0; c < numCols; c++) {
+                        switch (c % 4) {
+                            case 0:
+                                IntVector iv = (IntVector) root.getVector(c);
+                                iv.allocateNew(count);
+                                for (int i = 0; i < count; i++) iv.set(i, start + i);
+                                break;
+                            case 1:
+                                BigIntVector bv = (BigIntVector) root.getVector(c);
+                                bv.allocateNew(count);
+                                for (int i = 0; i < count; i++) bv.set(i, (long)(start + i) * 100);
+                                break;
+                            case 2:
+                                Float8Vector fv = (Float8Vector) root.getVector(c);
+                                fv.allocateNew(count);
+                                for (int i = 0; i < count; i++) fv.set(i, (start + i) * 0.1);
+                                break;
+                            case 3:
+                                VarCharVector sv = (VarCharVector) root.getVector(c);
+                                sv.allocateNew(count);
+                                for (int i = 0; i < count; i++) sv.setSafe(i, ("v" + (start + i)).getBytes());
+                                break;
+                        }
+                    }
+                    root.setRowCount(count);
+                    writer.write(root);
+                }
+            }
+        });
+
+        try (MosaicReader reader = readerFromBytes(data)) {
+            assertEquals(numCols, reader.getSchema().getFields().size());
+            int readRows = 0;
+            for (int rg = 0; rg < reader.numRowGroups(); rg++) {
+                try (VectorSchemaRoot batch = reader.readRowGroup(rg, allocator)) {
+                    assertEquals(numCols, batch.getFieldVectors().size());
+                    readRows += batch.getRowCount();
+                }
+            }
+            assertEquals(totalRows, readRows);
+        }
+    }
+
+    // Test 5: Many small writes (10000 batches of 10 rows)
+    @Test
+    public void testManySmallWrites() {
+        Schema arrowSchema = new Schema(Arrays.asList(
+                Field.nullable("id", new ArrowType.Int(32, true)),
+                Field.nullable("val", ArrowType.Utf8.INSTANCE)
+        ));
+
+        int numBatches = 10_000;
+        int batchSize = 10;
+        int totalRows = numBatches * batchSize;
+
+        byte[] data = writeToBytes(arrowSchema, writer -> {
+            for (int b = 0; b < numBatches; b++) {
+                try (VectorSchemaRoot root = VectorSchemaRoot.create(arrowSchema, allocator)) {
+                    IntVector ids = (IntVector) root.getVector("id");
+                    VarCharVector vals = (VarCharVector) root.getVector("val");
+                    ids.allocateNew(batchSize);
+                    vals.allocateNew(batchSize);
+                    for (int i = 0; i < batchSize; i++) {
+                        int row = b * batchSize + i;
+                        ids.set(i, row);
+                        vals.setSafe(i, ("r" + row).getBytes());
+                    }
+                    root.setRowCount(batchSize);
+                    writer.write(root);
+                }
+            }
+        });
+
+        try (MosaicReader reader = readerFromBytes(data)) {
+            int readRows = 0;
+            for (int rg = 0; rg < reader.numRowGroups(); rg++) {
+                try (VectorSchemaRoot batch = reader.readRowGroup(rg, allocator)) {
+                    readRows += batch.getRowCount();
+                }
+            }
+            assertEquals(totalRows, readRows);
+        }
+    }
+
+    // Test 6: Projection with large column count
+    @Test
+    public void testProjectionWithLargeColumnCount() {
+        int numCols = 50;
+        List<Field> fields = new ArrayList<>();
+        for (int c = 0; c < numCols; c++) {
+            fields.add(Field.nullable("col_" + c, new ArrowType.Int(32, true)));
+        }
+        Schema arrowSchema = new Schema(fields);
+
+        int totalRows = 10_000;
+        byte[] data = writeToBytes(arrowSchema, new WriterOptions().numBuckets(2), writer -> {
+            try (VectorSchemaRoot root = VectorSchemaRoot.create(arrowSchema, allocator)) {
+                for (int c = 0; c < numCols; c++) {
+                    IntVector v = (IntVector) root.getVector(c);
+                    v.allocateNew(totalRows);
+                    for (int i = 0; i < totalRows; i++) {
+                        v.set(i, c * 1000 + i);
+                    }
+                }
+                root.setRowCount(totalRows);
+                writer.write(root);
+            }
+        });
+
+        // Project only 3 out of 50 columns
+        try (MosaicReader reader = readerFromBytes(data)) {
+            reader.project(new String[]{"col_0", "col_25", "col_49"});
+            int readRows = 0;
+            for (int rg = 0; rg < reader.numRowGroups(); rg++) {
+                try (VectorSchemaRoot batch = reader.readRowGroup(rg, allocator)) {
+                    assertEquals(3, batch.getFieldVectors().size());
+                    assertEquals("col_0", batch.getVector(0).getName());
+                    assertEquals("col_25", batch.getVector(1).getName());
+                    assertEquals("col_49", batch.getVector(2).getName());
+
+                    IntVector c0 = (IntVector) batch.getVector(0);
+                    IntVector c25 = (IntVector) batch.getVector(1);
+                    IntVector c49 = (IntVector) batch.getVector(2);
+                    for (int i = 0; i < batch.getRowCount(); i++) {
+                        int id = c0.get(i);
+                        // id = 0*1000 + original_i, so original_i = id
+                        assertEquals(25 * 1000 + id, c25.get(i));
+                        assertEquals(49 * 1000 + id, c49.get(i));
+                    }
+                    readRows += batch.getRowCount();
+                }
+            }
+            assertEquals(totalRows, readRows);
+        }
+    }
+
+    // Test 7: Sequential vs random data file size comparison
+    @Test
+    public void testSequentialVsRandomData() {
+        Schema arrowSchema = new Schema(Arrays.asList(
+                Field.nullable("val", new ArrowType.Int(64, true))
+        ));
+
+        int totalRows = 100_000;
+
+        // Sequential data
+        byte[] seqData = writeToBytes(arrowSchema, writer -> {
+            try (VectorSchemaRoot root = VectorSchemaRoot.create(arrowSchema, allocator)) {
+                BigIntVector vals = (BigIntVector) root.getVector("val");
+                vals.allocateNew(totalRows);
+                for (int i = 0; i < totalRows; i++) {
+                    vals.set(i, (long) i);
+                }
+                root.setRowCount(totalRows);
+                writer.write(root);
+            }
+        });
+
+        // Random data
+        Random rng = new Random(42);
+        byte[] randData = writeToBytes(arrowSchema, writer -> {
+            try (VectorSchemaRoot root = VectorSchemaRoot.create(arrowSchema, allocator)) {
+                BigIntVector vals = (BigIntVector) root.getVector("val");
+                vals.allocateNew(totalRows);
+                Random localRng = new Random(42);
+                for (int i = 0; i < totalRows; i++) {
+                    vals.set(i, localRng.nextLong());
+                }
+                root.setRowCount(totalRows);
+                writer.write(root);
+            }
+        });
+
+        // Sequential data should compress better than random data
+        assertTrue("Sequential data (" + seqData.length + " bytes) should be smaller than random data (" +
+                randData.length + " bytes)", seqData.length < randData.length);
+
+        // Verify both roundtrip correctly
+        try (MosaicReader reader = readerFromBytes(seqData)) {
+            int readRows = 0;
+            for (int rg = 0; rg < reader.numRowGroups(); rg++) {
+                try (VectorSchemaRoot batch = reader.readRowGroup(rg, allocator)) {
+                    readRows += batch.getRowCount();
+                }
+            }
+            assertEquals(totalRows, readRows);
+        }
+
+        try (MosaicReader reader = readerFromBytes(randData)) {
+            int readRows = 0;
+            for (int rg = 0; rg < reader.numRowGroups(); rg++) {
+                try (VectorSchemaRoot batch = reader.readRowGroup(rg, allocator)) {
+                    readRows += batch.getRowCount();
+                }
+            }
+            assertEquals(totalRows, readRows);
+        }
+    }
+
+    // Test 8: Multiple row groups roundtrip with small max size
+    @Test
+    public void testMultipleRowGroupsRoundtrip() {
+        Schema arrowSchema = new Schema(Arrays.asList(
+                Field.nullable("id", new ArrowType.Int(32, true)),
+                Field.nullable("data", new ArrowType.Int(64, true)),
+                Field.nullable("text", ArrowType.Utf8.INSTANCE)
+        ));
+
+        WriterOptions opts = new WriterOptions()
+                .compression(0)
+                .numBuckets(1)
+                .rowGroupMaxSize(500);
+
+        int totalRows = 1000;
+        int batchSize = 50;
+
+        byte[] data = writeToBytes(arrowSchema, opts, writer -> {
+            for (int start = 0; start < totalRows; start += batchSize) {
+                int count = Math.min(batchSize, totalRows - start);
+                try (VectorSchemaRoot root = VectorSchemaRoot.create(arrowSchema, allocator)) {
+                    IntVector ids = (IntVector) root.getVector("id");
+                    BigIntVector datas = (BigIntVector) root.getVector("data");
+                    VarCharVector texts = (VarCharVector) root.getVector("text");
+
+                    ids.allocateNew(count);
+                    datas.allocateNew(count);
+                    texts.allocateNew(count);
+
+                    for (int i = 0; i < count; i++) {
+                        int val = start + i;
+                        ids.set(i, val);
+                        datas.set(i, (long) val * 7);
+                        texts.setSafe(i, ("item_" + val).getBytes());
+                    }
+                    root.setRowCount(count);
+                    writer.write(root);
+                }
+            }
+        });
+
+        try (MosaicReader reader = readerFromBytes(data)) {
+            assertTrue("Should have multiple row groups, got " + reader.numRowGroups(),
+                    reader.numRowGroups() > 1);
+
+            int offset = 0;
+            for (int rg = 0; rg < reader.numRowGroups(); rg++) {
+                try (VectorSchemaRoot batch = reader.readRowGroup(rg, allocator)) {
+                    IntVector ids = (IntVector) batch.getVector("id");
+                    BigIntVector datas = (BigIntVector) batch.getVector("data");
+                    VarCharVector texts = (VarCharVector) batch.getVector("text");
+
+                    for (int i = 0; i < batch.getRowCount(); i++) {
+                        int id = ids.get(i);
+                        assertEquals((long) id * 7, datas.get(i));
+                        assertEquals("item_" + id, new String(texts.get(i)));
+                    }
+                    offset += batch.getRowCount();
+                }
+            }
+            assertEquals(totalRows, offset);
+        }
+    }
+
+    // Test 9: Empty string values mixed with non-empty
+    @Test
+    public void testEmptyStringValues() {
+        Schema arrowSchema = new Schema(Arrays.asList(
+                Field.nullable("id", new ArrowType.Int(32, true)),
+                Field.nullable("text", ArrowType.Utf8.INSTANCE)
+        ));
+
+        int totalRows = 100_000;
+
+        byte[] data = writeToBytes(arrowSchema, writer -> {
+            try (VectorSchemaRoot root = VectorSchemaRoot.create(arrowSchema, allocator)) {
+                IntVector ids = (IntVector) root.getVector("id");
+                VarCharVector texts = (VarCharVector) root.getVector("text");
+
+                ids.allocateNew(totalRows);
+                texts.allocateNew(totalRows);
+
+                for (int i = 0; i < totalRows; i++) {
+                    ids.set(i, i);
+                    if (i % 3 == 0) {
+                        texts.setSafe(i, "".getBytes());
+                    } else if (i % 3 == 1) {
+                        texts.setSafe(i, ("value_" + i).getBytes());
+                    } else {
+                        texts.setNull(i);
+                    }
+                }
+                root.setRowCount(totalRows);
+                writer.write(root);
+            }
+        });
+
+        try (MosaicReader reader = readerFromBytes(data)) {
+            int readRows = 0;
+            for (int rg = 0; rg < reader.numRowGroups(); rg++) {
+                try (VectorSchemaRoot batch = reader.readRowGroup(rg, allocator)) {
+                    IntVector ids = (IntVector) batch.getVector("id");
+                    VarCharVector texts = (VarCharVector) batch.getVector("text");
+
+                    for (int i = 0; i < batch.getRowCount(); i++) {
+                        int id = ids.get(i);
+                        if (id % 3 == 0) {
+                            assertFalse(texts.isNull(i));
+                            assertEquals("", new String(texts.get(i)));
+                        } else if (id % 3 == 1) {
+                            assertFalse(texts.isNull(i));
+                            assertEquals("value_" + id, new String(texts.get(i)));
+                        } else {
+                            assertTrue(texts.isNull(i));
+                        }
+                    }
+                    readRows += batch.getRowCount();
+                }
+            }
+            assertEquals(totalRows, readRows);
+        }
+    }
+
+    // Test 10: Decimal precisions
+    @Test
+    public void testDecimalPrecisions() {
+        // Test Decimal128 with precision 10
+        Schema schema10 = new Schema(Arrays.asList(
+                Field.nullable("dec10", new ArrowType.Decimal(10, 2, 128))
+        ));
+
+        int totalRows = 10_000;
+        byte[] data10 = writeToBytes(schema10, writer -> {
+            try (VectorSchemaRoot root = VectorSchemaRoot.create(schema10, allocator)) {
+                DecimalVector dec = (DecimalVector) root.getVector("dec10");
+                dec.allocateNew(totalRows);
+                for (int i = 0; i < totalRows; i++) {
+                    if (i % 10 == 0) {
+                        dec.setNull(i);
+                    } else {
+                        dec.set(i, new BigDecimal(i + ".99"));
+                    }
+                }
+                root.setRowCount(totalRows);
+                writer.write(root);
+            }
+        });
+
+        try (MosaicReader reader = readerFromBytes(data10)) {
+            int readRows = 0;
+            for (int rg = 0; rg < reader.numRowGroups(); rg++) {
+                try (VectorSchemaRoot batch = reader.readRowGroup(rg, allocator)) {
+                    DecimalVector dec = (DecimalVector) batch.getVector("dec10");
+                    for (int i = 0; i < batch.getRowCount(); i++) {
+                        int id = readRows + i;
+                        if (id % 10 == 0) {
+                            assertTrue(dec.isNull(i));
+                        } else {
+                            assertFalse(dec.isNull(i));
+                            BigDecimal expected = new BigDecimal(id + ".99");
+                            assertEquals(expected, dec.getObject(i));
+                        }
+                    }
+                    readRows += batch.getRowCount();
+                }
+            }
+            assertEquals(totalRows, readRows);
+        }
+
+        // Test Decimal128 with precision 38
+        Schema schema38 = new Schema(Arrays.asList(
+                Field.nullable("dec38", new ArrowType.Decimal(38, 10, 128))
+        ));
+
+        byte[] data38 = writeToBytes(schema38, writer -> {
+            try (VectorSchemaRoot root = VectorSchemaRoot.create(schema38, allocator)) {
+                DecimalVector dec = (DecimalVector) root.getVector("dec38");
+                dec.allocateNew(totalRows);
... 1374 lines suppressed ...