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

JingsongLi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-rust.git


The following commit(s) were added to refs/heads/main by this push:
     new 5de28de3 [core] Align column defaults with Java writers (#1505)
5de28de3 is described below

commit 5de28de34e710bcd03f2028d93f330e1dd8d6589
Author: Jingsong Lee <[email protected]>
AuthorDate: Mon Nov 23 16:41:47 2026 +0800

    [core] Align column defaults with Java writers (#1505)
---
 .../datafusion/tests/pk_delete_tests.rs            |  66 +++++
 crates/paimon/src/catalog/filesystem.rs            | 122 ++++++++-
 crates/paimon/src/spec/schema.rs                   |   8 +-
 ...format_table_defaults.rs => column_defaults.rs} | 275 ++++++++++++---------
 crates/paimon/src/table/format_table_writer.rs     |   6 +-
 crates/paimon/src/table/mod.rs                     |   4 +-
 crates/paimon/src/table/row_kind_generator.rs      |  23 +-
 crates/paimon/src/table/table_upsert.rs            |  37 ++-
 crates/paimon/src/table/table_write.rs             |  93 ++++++-
 crates/paimon/src/table/table_write_input.rs       |   1 +
 docs/src/getting-started.md                        |  12 +-
 11 files changed, 504 insertions(+), 143 deletions(-)

diff --git a/crates/integrations/datafusion/tests/pk_delete_tests.rs 
b/crates/integrations/datafusion/tests/pk_delete_tests.rs
index 327bfeef..4ec62f81 100644
--- a/crates/integrations/datafusion/tests/pk_delete_tests.rs
+++ b/crates/integrations/datafusion/tests/pk_delete_tests.rs
@@ -456,6 +456,72 @@ async fn 
primary_key_delete_preserves_partition_and_composite_key() {
     }
 }
 
+#[tokio::test]
+async fn primary_key_mutations_preserve_stored_nulls_with_defaults() {
+    use datafusion::arrow::array::{Int32Array, RecordBatch};
+    use paimon::spec::{DataType, IntType, Schema};
+
+    let (_tmp, catalog) = create_test_env();
+    let ctx = create_sql_context(Arc::clone(&catalog)).await;
+    exec(&ctx, "CREATE SCHEMA paimon.test_db").await;
+    let id = Identifier::new("test_db", "t");
+    let int = DataType::Int(IntType::new());
+    let schema = Schema::builder()
+        .column("id", int.clone())
+        .column("v", int)
+        .primary_key(["id"])
+        .option("primary-key.nullable", "true")
+        .option("bucket", "2")
+        .option("write-only", "true")
+        .build()
+        .unwrap();
+    catalog.create_table(&id, schema, false).await.unwrap();
+    let table = catalog.get_table(&id).await.unwrap();
+    let batch = RecordBatch::try_new(
+        
paimon::arrow::build_target_arrow_schema(table.schema().fields()).unwrap(),
+        vec![
+            Arc::new(Int32Array::from(vec![None, Some(42)])),
+            Arc::new(Int32Array::from(vec![1, 2])),
+        ],
+    )
+    .unwrap();
+    let builder = table.new_write_builder();
+    let mut writer = builder.new_write().unwrap();
+    writer.write_arrow_batch(&batch).await.unwrap();
+    let messages = writer.prepare_commit().await.unwrap();
+    builder.new_commit().commit(messages).await.unwrap();
+    writer.close().await;
+
+    // Reopen a schema whose defaults were added after the NULL key was 
written.
+    let mut schema = serde_json::to_value(table.schema()).unwrap();
+    schema["fields"][0]["defaultValue"] = serde_json::json!("42");
+    schema["fields"][1]["defaultValue"] = serde_json::json!("99");
+    table
+        .file_io()
+        .new_output(&table.schema_manager().schema_path(0))
+        .unwrap()
+        .write(serde_json::to_vec(&schema).unwrap().into())
+        .await
+        .unwrap();
+    assert_eq!(
+        dml_count(
+            &ctx,
+            "UPDATE paimon.test_db.t SET v = NULL WHERE id IS NULL"
+        )
+        .await,
+        1
+    );
+    assert_eq!(
+        dml_count(
+            &ctx,
+            "DELETE FROM paimon.test_db.t WHERE id IS NULL AND v IS NULL"
+        )
+        .await,
+        1
+    );
+    assert_eq!(rows(&ctx).await, vec![(42, Some(2))]);
+}
+
 #[tokio::test]
 async fn 
primary_key_delete_preserves_sequence_fields_and_allows_later_upserts() {
     for (order, older, newer) in [("ascending", 99, 101), ("descending", 101, 
99)] {
diff --git a/crates/paimon/src/catalog/filesystem.rs 
b/crates/paimon/src/catalog/filesystem.rs
index f7bad957..826d341b 100644
--- a/crates/paimon/src/catalog/filesystem.rs
+++ b/crates/paimon/src/catalog/filesystem.rs
@@ -2495,7 +2495,7 @@ mod tests {
             (&string, &double, "'0x1.8p1'", true),
             (&string, &double, "'inf'", false),
             (&string, &timestamp, "'2026-01-02T00:00:00+08:00'", false),
-            (&string, &time, "'00:00:00.0005'", false),
+            (&string, &time, "'00:00:00.0005'", true),
             (&string, &time, "'00:00:00.001'", true),
         ] {
             let catalog = create_memory_catalog();
@@ -2556,6 +2556,126 @@ mod tests {
         }
     }
 
+    #[tokio::test]
+    async fn writers_apply_java_defaults_after_alter() {
+        use arrow_array::{Int32Array, RecordBatch, Time32MillisecondArray};
+        use futures::TryStreamExt;
+
+        let int = DataType::Int(IntType::new());
+        let time = DataType::Time(crate::spec::TimeType::new(3).unwrap());
+        for (table_type, source, target, literal, input, expected) in [
+            (
+                "table",
+                DataType::BigInt(crate::spec::BigIntType::new()),
+                int,
+                "42",
+                Arc::new(Int32Array::from(vec![None, Some(7)])) as 
arrow_array::ArrayRef,
+                Arc::new(Int32Array::from(vec![42, 7])) as 
arrow_array::ArrayRef,
+            ),
+            (
+                "format-table",
+                DataType::VarChar(VarCharType::string_type()),
+                time,
+                "'00:00:00.0005'",
+                Arc::new(Time32MillisecondArray::from(vec![None, Some(7)])),
+                Arc::new(Time32MillisecondArray::from(vec![1, 7])),
+            ),
+        ] {
+            let catalog = create_memory_catalog();
+            let creation = Schema::builder()
+                .field(
+                    DataField::new(0, "value".into(), source)
+                        .with_default_value(Some(literal.into())),
+                )
+                .option("type", table_type)
+                .option("file.format", "parquet")
+                .option("write-only", "true")
+                .build()
+                .unwrap();
+            let id = setup_table(&catalog, creation).await;
+            catalog
+                .alter_table(
+                    &id,
+                    vec![SchemaChange::update_column_type("value".into(), 
target)],
+                    false,
+                )
+                .await
+                .unwrap();
+            let table = catalog.get_table(&id).await.unwrap();
+            assert_eq!(table.schema().id(), 1);
+            assert_eq!(table.schema().fields()[0].default_value(), 
Some(literal));
+            let batch = RecordBatch::try_new(
+                
crate::arrow::build_target_arrow_schema(table.schema().fields()).unwrap(),
+                vec![input],
+            )
+            .unwrap();
+            let builder = table.new_write_builder();
+            let mut writer = builder.new_write().unwrap();
+            writer.write_arrow_batch(&batch).await.unwrap();
+            let messages = writer.prepare_commit().await.unwrap();
+            builder.new_commit().commit(messages).await.unwrap();
+            writer.close().await;
+
+            let reader = table.new_read_builder();
+            let plan = reader.new_scan().plan().await.unwrap();
+            let batches = reader
+                .new_read()
+                .unwrap()
+                .to_arrow(plan.splits())
+                .unwrap()
+                .try_collect::<Vec<_>>()
+                .await
+                .unwrap();
+            assert_eq!(batches.len(), 1);
+            assert_eq!(batches[0].column(0).as_ref(), expected.as_ref());
+        }
+    }
+
+    #[tokio::test]
+    async fn native_defaults_route_projected_writes_to_the_default_partition() 
{
+        use arrow_array::{Int32Array, RecordBatch};
+
+        let catalog = create_memory_catalog();
+        let int = DataType::Int(IntType::new());
+        let schema = Schema::builder()
+            .column("id", int.clone())
+            .field(DataField::new(1, "pt".into(), 
int).with_default_value(Some("42".into())))
+            .partition_keys(["pt"])
+            .option("bucket", "1")
+            .option("bucket-key", "id")
+            .build()
+            .unwrap();
+        let id = setup_table(&catalog, schema).await;
+        let table = catalog.get_table(&id).await.unwrap();
+        let schema = 
crate::arrow::build_target_arrow_schema(table.schema().fields()).unwrap();
+        let batch = RecordBatch::try_new(
+            schema,
+            vec![
+                Arc::new(Int32Array::from(vec![1])),
+                Arc::new(Int32Array::from(vec![None])),
+            ],
+        )
+        .unwrap();
+        for bucket in [None, Some(0)] {
+            let builder = table.new_write_builder();
+            let mut writer = builder.new_write().unwrap();
+            writer.with_write_type(vec!["id".into()]).unwrap();
+            writer
+                .write_arrow(std::slice::from_ref(&batch), bucket)
+                .await
+                .unwrap();
+            let messages = writer.prepare_commit().await.unwrap();
+            assert_eq!(messages.len(), 1);
+            let partition =
+                
crate::spec::BinaryRow::from_serialized_bytes(&messages[0].partition).unwrap();
+            assert_eq!(partition.get_int(0).unwrap(), 42);
+            assert_eq!(messages[0].bucket, 0);
+            assert_eq!(messages[0].new_files[0].write_cols, 
Some(vec!["id".into()]));
+            builder.new_commit().commit(messages).await.unwrap();
+            writer.close().await;
+        }
+    }
+
     #[tokio::test]
     async fn create_rejects_unchecked_generated_columns_before_publication() {
         let catalog = create_memory_catalog();
diff --git a/crates/paimon/src/spec/schema.rs b/crates/paimon/src/spec/schema.rs
index 6e48c4d7..6d9e94f8 100644
--- a/crates/paimon/src/spec/schema.rs
+++ b/crates/paimon/src/spec/schema.rs
@@ -730,10 +730,7 @@ impl TableSchema {
                     if updated.default_value().is_some()
                         && 
!old.data_type().equals_ignore_nullable(updated.data_type())
                     {
-                        crate::table::validate_default_value(
-                            &updated,
-                            self.core_options().is_format_table(),
-                        )?;
+                        crate::table::validate_default_value(&updated)?;
                     }
                     fields[idx] = updated;
                 }
@@ -1474,7 +1471,6 @@ impl Schema {
     }
 
     pub(crate) fn validate_fields_for_create(&self) -> crate::Result<()> {
-        let is_format_table = 
CoreOptions::new(self.options()).is_format_table();
         for field in self.fields() {
             if field.generation_expression().is_some() {
                 return Err(crate::Error::Unsupported {
@@ -1485,7 +1481,7 @@ impl Schema {
                 });
             }
             
super::generated_column::validate_no_nested_generated_columns(field.data_type())?;
-            crate::table::validate_default_value(field, is_format_table)?;
+            crate::table::validate_default_value(field)?;
         }
         Ok(())
     }
diff --git a/crates/paimon/src/table/format_table_defaults.rs 
b/crates/paimon/src/table/column_defaults.rs
similarity index 86%
rename from crates/paimon/src/table/format_table_defaults.rs
rename to crates/paimon/src/table/column_defaults.rs
index 98a0768f..026c5f80 100644
--- a/crates/paimon/src/table/format_table_defaults.rs
+++ b/crates/paimon/src/table/column_defaults.rs
@@ -15,10 +15,9 @@
 // specific language governing permissions and limitations
 // under the License.
 
-//! Apply schema defaults to nullable Format Table input columns. Java's
-//! `DefaultValueRow` wraps the row after nullability validation and before
-//! partition extraction, so partition and file columns share this behavior.
+//! Parse and apply column defaults using Java's `DefaultValueRow` rules.
 
+use std::collections::HashMap;
 use std::sync::Arc;
 
 use arrow_array::{
@@ -36,23 +35,23 @@ use crate::{Error, Result};
 
 #[derive(Clone, Copy)]
 enum DefaultParsing {
-    Stored,
-    NewDefinition,
+    Legacy,
+    Java,
 }
 
 impl DefaultParsing {
     fn trim(self, text: &str) -> &str {
         match self {
-            Self::Stored => text.trim(),
-            Self::NewDefinition => text.trim_matches(|ch| ch <= ' '),
+            Self::Legacy => text.trim(),
+            Self::Java => text.trim_matches(|ch| ch <= ' '),
         }
     }
 
     fn is_token_whitespace(self, ch: char) -> bool {
         match self {
-            Self::Stored => ch.is_whitespace(),
+            Self::Legacy => ch.is_whitespace(),
             // Java TokenSplitter uses Character.isWhitespace, which preserves 
nonbreaking spaces.
-            Self::NewDefinition => {
+            Self::Java => {
                 matches!(ch, '\u{001c}'..='\u{001f}')
                     || ch.is_whitespace()
                         && !matches!(ch, '\u{0085}' | '\u{00a0}' | '\u{2007}' 
| '\u{202f}')
@@ -61,60 +60,90 @@ impl DefaultParsing {
     }
 }
 
-pub(super) struct FormatTableDefaults {
-    values: Vec<Option<ArrayRef>>,
+#[derive(Default)]
+pub(super) struct ColumnDefaults {
+    values: HashMap<String, ArrayRef>,
 }
 
-impl FormatTableDefaults {
-    pub(super) fn new(fields: &[DataField], schema: &ArrowSchema) -> 
Result<Self> {
-        let values = fields
-            .iter()
-            .enumerate()
-            .map(|(index, field)| {
-                field
-                    .default_value()
-                    .map(|text| {
-                        parse_default(field, text, schema.field(index), 
DefaultParsing::Stored)
-                    })
-                    .transpose()
-            })
-            .collect::<Result<Vec<_>>>()?;
+impl ColumnDefaults {
+    pub(super) fn new(
+        fields: &[DataField],
+        schema: &ArrowSchema,
+        is_format_table: bool,
+    ) -> Result<Self> {
+        let mut values = HashMap::new();
+        for (index, field) in fields.iter().enumerate() {
+            let Some(text) = field.default_value() else {
+                continue;
+            };
+            let arrow_field = schema.field(index);
+            let value = match parse_default(field, text, arrow_field, 
DefaultParsing::Java) {
+                Ok(value) => value,
+                // Older Rust Format Tables may already use literals that Java 
rejects.
+                Err(_) if is_format_table => {
+                    parse_default(field, text, arrow_field, 
DefaultParsing::Legacy)?
+                }
+                // Older Rust native writers ignored defaults. An invalid 
stored
+                // literal must not prevent those tables from accepting writes.
+                Err(_) => continue,
+            };
+            values.insert(field.name().to_owned(), value);
+        }
         Ok(Self { values })
     }
 
+    pub(super) fn string_value(&self, name: &str) -> Option<&str> {
+        self.values
+            .get(name)?
+            .as_any()
+            .downcast_ref::<StringArray>()
+            .map(|value| value.value(0))
+    }
+
     pub(super) fn apply(&self, batch: &RecordBatch) -> Result<RecordBatch> {
-        if !self
-            .values
-            .iter()
-            .enumerate()
-            .any(|(index, value)| value.is_some() && 
batch.column(index).null_count() > 0)
+        self.apply_to_rows(batch, |_| true)
+    }
+
+    pub(super) fn apply_to_rows(
+        &self,
+        batch: &RecordBatch,
+        should_fill: impl Fn(usize) -> bool,
+    ) -> Result<RecordBatch> {
+        let fields = batch.schema_ref().fields();
+        if self.values.is_empty()
+            || !fields.iter().zip(batch.columns()).any(|(field, input)| {
+                input.null_count() > 0 && 
self.values.contains_key(field.name())
+            })
         {
             return Ok(batch.clone());
         }
         let columns = batch
             .columns()
             .iter()
-            .enumerate()
-            .map(|(index, input)| {
-                let Some(value) = &self.values[index] else {
+            .zip(fields)
+            .map(|(input, field)| {
+                let Some(value) = self.values.get(field.name()) else {
                     return Ok(input.clone());
                 };
                 if input.null_count() == 0 {
                     return Ok(input.clone());
                 }
+                let present = arrow_array::BooleanArray::from_iter(
+                    (0..input.len()).map(|row| Some(!input.is_null(row) || 
!should_fill(row))),
+                );
+                if present.false_count() == 0 {
+                    return Ok(input.clone());
+                }
                 let positions = arrow_array::UInt32Array::from(vec![0_u32; 
batch.num_rows()]);
                 let repeated = arrow_select::take::take(value.as_ref(), 
&positions, None).map_err(
                     |source| Error::DataInvalid {
-                        message: format!("Cannot repeat Format Table default 
for column {index}"),
+                        message: format!("Cannot repeat default for column 
'{}'", field.name()),
                         source: Some(Box::new(source)),
                     },
                 )?;
-                let present = arrow_array::BooleanArray::from_iter(
-                    (0..input.len()).map(|row| Some(!input.is_null(row))),
-                );
                 arrow_select::zip::zip(&present, input, 
&repeated).map_err(|source| {
                     Error::DataInvalid {
-                        message: format!("Cannot apply Format Table default 
for column {index}"),
+                        message: format!("Cannot apply default for column 
'{}'", field.name()),
                         source: Some(Box::new(source)),
                     }
                 })
@@ -122,33 +151,19 @@ impl FormatTableDefaults {
             .collect::<Result<Vec<_>>>()?;
         RecordBatch::try_new(Arc::clone(&batch.schema()), 
columns).map_err(|source| {
             Error::DataInvalid {
-                message: "Cannot assemble Format Table row with 
defaults".into(),
+                message: "Cannot assemble batch with column defaults".into(),
                 source: Some(Box::new(source)),
             }
         })
     }
 }
 
-pub(crate) fn validate_default_value(field: &DataField, is_format_table: bool) 
-> Result<()> {
+pub(crate) fn validate_default_value(field: &DataField) -> Result<()> {
     let Some(text) = field.default_value() else {
         return Ok(());
     };
     let arrow_field = crate::arrow::paimon_type_to_arrow_field(field.name(), 
field.data_type())?;
-    let java_value = parse_default(field, text, &arrow_field, 
DefaultParsing::NewDefinition)?;
-    if is_format_table {
-        let writer_value = parse_default(field, text, &arrow_field, 
DefaultParsing::Stored)?;
-        if java_value.to_data() != writer_value.to_data() {
-            return Err(Error::DataInvalid {
-                message: format!(
-                    "Unsupported default value '{text}' for column '{}' of 
type {}: Java and Rust Format Table writers interpret it differently",
-                    field.name(),
-                    field.data_type()
-                ),
-                source: None,
-            });
-        }
-    }
-    Ok(())
+    parse_default(field, text, &arrow_field, DefaultParsing::Java).map(|_| ())
 }
 
 fn parse_default(
@@ -165,7 +180,7 @@ fn parse_default(
         ),
         source,
     };
-    if matches!(parsing, DefaultParsing::NewDefinition)
+    if matches!(parsing, DefaultParsing::Java)
         && (text == "'" || !supports_string_default(data_type))
     {
         return Err(invalid(None));
@@ -292,12 +307,19 @@ fn cast_default(
             };
             let mut keys: Vec<ArrayRef> = Vec::with_capacity(pairs.len());
             let mut values: Vec<ArrayRef> = Vec::with_capacity(pairs.len());
+            // Java's HashMap compares byte[] keys by reference, even when a
+            // cast produces identical bytes for multiple input keys.
+            let preserve_binary_keys = matches!(parsing, DefaultParsing::Java)
+                && matches!(typ.key_type(), DataType::Binary(_) | 
DataType::VarBinary(_));
             for (key_token, value_token) in &pairs {
                 let key = cast_token(typ.key_type(), key_token, 
&entry_fields[0], parsing)?;
                 let value = cast_token(typ.value_type(), value_token, 
&entry_fields[1], parsing)?;
-                // Java builds a HashMap, so a later entry replaces an earlier
-                // value with the same cast key.
-                if let Some(index) = keys.iter().position(|old| old.to_data() 
== key.to_data()) {
+                let existing = if preserve_binary_keys {
+                    None
+                } else {
+                    keys.iter().position(|old| old.to_data() == key.to_data())
+                };
+                if let Some(index) = existing {
                     values[index] = value;
                 } else {
                     keys.push(key);
@@ -331,9 +353,8 @@ fn cast_scalar_default(
     arrow_type: &ArrowDataType,
     parsing: DefaultParsing,
 ) -> std::result::Result<ArrayRef, ArrowError> {
-    if matches!(parsing, DefaultParsing::Stored) {
-        // Schema files carry no parser version. Preserve the original result
-        // when available and use the Java parser when legacy parsing fails.
+    if matches!(parsing, DefaultParsing::Legacy) {
+        // Reproduce the historical Rust result for literals Java rejects.
         let legacy = match data_type {
             DataType::Timestamp(typ) => cast_legacy_timestamp(text, 
typ.precision(), arrow_type),
             DataType::LocalZonedTimestamp(typ) => {
@@ -501,8 +522,8 @@ fn literal_content<'a>(
                 return None;
             }
             let tail = match parsing {
-                DefaultParsing::Stored => tail.trim_start(),
-                DefaultParsing::NewDefinition => {
+                DefaultParsing::Legacy => tail.trim_start(),
+                DefaultParsing::Java => {
                     tail.trim_start_matches(|ch| matches!(ch, '\t'..='\r' | ' 
'))
                 }
             };
@@ -510,7 +531,7 @@ fn literal_content<'a>(
         })
         // Java's collection cast rules match the body with a non-DOTALL regex.
         .filter(|body| {
-            matches!(parsing, DefaultParsing::Stored)
+            matches!(parsing, DefaultParsing::Legacy)
                 || !body.contains(['\n', '\r', '\u{0085}', '\u{2028}', 
'\u{2029}'])
         })
         .ok_or_else(|| cast_error(format!("Invalid {function} default: 
{text}")))?;
@@ -695,7 +716,7 @@ mod tests {
     fn replaces_only_nulls_in_partition_and_data_columns() {
         let fields = fields();
         let schema = build_target_arrow_schema(&fields).unwrap();
-        let defaults = FormatTableDefaults::new(&fields, &schema).unwrap();
+        let defaults = ColumnDefaults::new(&fields, &schema, true).unwrap();
         let input = RecordBatch::try_new(
             schema,
             vec![
@@ -745,7 +766,7 @@ mod tests {
             .clone()
             .with_default_value(Some("'not a number'".into()));
         let schema = build_target_arrow_schema(&fields).unwrap();
-        assert!(FormatTableDefaults::new(&fields, &schema)
+        assert!(ColumnDefaults::new(&fields, &schema, true)
             .err()
             .unwrap()
             .to_string()
@@ -768,7 +789,7 @@ mod tests {
                 .with_default_value(Some("-9223372036854775808.9".into())),
         ];
         let schema = build_target_arrow_schema(&fields).unwrap();
-        let defaults = FormatTableDefaults::new(&fields, &schema).unwrap();
+        let defaults = ColumnDefaults::new(&fields, &schema, true).unwrap();
         let input = RecordBatch::try_new(
             schema.clone(),
             schema
@@ -833,7 +854,7 @@ mod tests {
                     .with_default_value(Some(text.into()))];
             let schema = build_target_arrow_schema(&fields).unwrap();
             assert!(
-                FormatTableDefaults::new(&fields, &schema).is_err(),
+                ColumnDefaults::new(&fields, &schema, true).is_err(),
                 "{text}"
             );
         }
@@ -843,7 +864,7 @@ mod tests {
     fn no_nulls_passes_input_through() {
         let fields = fields();
         let schema = build_target_arrow_schema(&fields).unwrap();
-        let defaults = FormatTableDefaults::new(&fields, &schema).unwrap();
+        let defaults = ColumnDefaults::new(&fields, &schema, true).unwrap();
         let input = RecordBatch::try_new(
             schema,
             vec![
@@ -876,7 +897,7 @@ mod tests {
                 .with_default_value(Some("'00:01:02.9995+01:30'".into())),
         ];
         let schema = build_target_arrow_schema(&fields).unwrap();
-        let defaults = FormatTableDefaults::new(&fields, &schema).unwrap();
+        let defaults = ColumnDefaults::new(&fields, &schema, true).unwrap();
         let amount = Decimal128Array::from(vec![None])
             .with_precision_and_scale(10, 2)
             .unwrap();
@@ -922,18 +943,13 @@ mod tests {
         ] {
             let field = 
fields[3].clone().with_default_value(Some(literal.into()));
             assert_eq!(
-                validate_default_value(&field, false).is_ok(),
+                validate_default_value(&field).is_ok(),
                 java_millis.is_some(),
                 "{literal}"
             );
-            assert_eq!(
-                validate_default_value(&field, true).is_ok(),
-                java_millis == Some(stored_millis),
-                "{literal}"
-            );
             for (parsing, expected) in [
-                (DefaultParsing::Stored, Some(stored_millis)),
-                (DefaultParsing::NewDefinition, java_millis),
+                (DefaultParsing::Legacy, Some(stored_millis)),
+                (DefaultParsing::Java, java_millis),
             ] {
                 let millis = parse_default(&field, literal, 
input.schema_ref().field(3), parsing)
                     .ok()
@@ -980,7 +996,7 @@ mod tests {
             .with_default_value(Some("'猫'".into())),
         ];
         let schema = build_target_arrow_schema(&fields).unwrap();
-        let defaults = FormatTableDefaults::new(&fields, &schema).unwrap();
+        let defaults = ColumnDefaults::new(&fields, &schema, true).unwrap();
         let input = RecordBatch::try_new(
             schema,
             vec![
@@ -1030,12 +1046,12 @@ mod tests {
         );
 
         let apostrophe = 
fields[1].clone().with_default_value(Some("'".into()));
-        assert!(validate_default_value(&apostrophe, true).is_err());
+        assert!(validate_default_value(&apostrophe).is_err());
         let stored = parse_default(
             &apostrophe,
             "'",
             actual.schema().field(1),
-            DefaultParsing::Stored,
+            DefaultParsing::Legacy,
         )
         .unwrap();
         assert_eq!(
@@ -1070,7 +1086,7 @@ mod tests {
             .with_default_value(Some("-123456".into())),
         ];
         let schema = build_target_arrow_schema(&fields).unwrap();
-        let defaults = FormatTableDefaults::new(&fields, &schema).unwrap();
+        let defaults = ColumnDefaults::new(&fields, &schema, true).unwrap();
         let input = RecordBatch::try_new(
             schema,
             vec![
@@ -1146,7 +1162,7 @@ mod tests {
             let field = DataField::new(0, "value".into(), data_type)
                 .with_default_value(Some(default.into()));
             assert!(
-                validate_default_value(&field, true).is_err(),
+                validate_default_value(&field).is_err(),
                 "{}",
                 field.data_type()
             );
@@ -1164,7 +1180,7 @@ mod tests {
         )
         .with_default_value(Some("'2025-01-02 03:04:05.123456'".into()))];
         let schema = build_target_arrow_schema(&fields).unwrap();
-        let defaults = FormatTableDefaults::new(&fields, &schema).unwrap();
+        let defaults = ColumnDefaults::new(&fields, &schema, true).unwrap();
         let input = RecordBatch::try_new(
             schema,
             vec![Arc::new(
@@ -1205,7 +1221,7 @@ mod tests {
         )
         .with_default_value(Some("'[1,2]'".into()))];
         let schema = build_target_arrow_schema(&fields).unwrap();
-        let defaults = FormatTableDefaults::new(&fields, &schema).unwrap();
+        let defaults = ColumnDefaults::new(&fields, &schema, true).unwrap();
         let empty = arrow_array::new_null_array(schema.field(0).data_type(), 
1);
         let input = RecordBatch::try_new(schema, vec![empty]).unwrap();
         let actual = defaults.apply(&input).unwrap();
@@ -1230,7 +1246,7 @@ mod tests {
         )
         .with_default_value(Some("'1970-01-01 00:00:00.123456'".into()))];
         let schema = build_target_arrow_schema(&fields).unwrap();
-        let defaults = FormatTableDefaults::new(&fields, &schema).unwrap();
+        let defaults = ColumnDefaults::new(&fields, &schema, true).unwrap();
         let input = RecordBatch::try_new(
             schema,
             vec![Arc::new(TimestampMillisecondArray::from(vec![None]))],
@@ -1269,7 +1285,7 @@ mod tests {
                 field.data_type(),
                 "1970-01-01 00:00:00.123456789",
                 schema.field(0),
-                DefaultParsing::Stored,
+                DefaultParsing::Legacy,
             )
             .unwrap();
             let actual = match precision {
@@ -1313,13 +1329,11 @@ mod tests {
                 DataType::VarChar(VarCharType::string_type()),
             )),
         )
-        .with_default_value(Some("'[null, \"null\", \"a,b\"]'".into()));
+        .with_default_value(Some("'[null, \"null\", \"a,b\", 
\u{00a0}c]'".into()));
         let fields = [nested, labels];
         let schema = build_target_arrow_schema(&fields).unwrap();
-        let defaults = FormatTableDefaults::new(&fields, &schema).unwrap();
-        let nested = defaults.values[0]
-            .as_ref()
-            .unwrap()
+        let defaults = ColumnDefaults::new(&fields, &schema, true).unwrap();
+        let nested = defaults.values["nested"]
             .as_any()
             .downcast_ref::<ListArray>()
             .unwrap();
@@ -1345,9 +1359,7 @@ mod tests {
                 .collect::<Vec<_>>(),
             vec![Some(3), None]
         );
-        let labels = defaults.values[1]
-            .as_ref()
-            .unwrap()
+        let labels = defaults.values["labels"]
             .as_any()
             .downcast_ref::<ListArray>()
             .unwrap();
@@ -1355,7 +1367,7 @@ mod tests {
         let values = values.as_any().downcast_ref::<StringArray>().unwrap();
         assert_eq!(
             values.iter().collect::<Vec<_>>(),
-            vec![None, Some("null"), Some("a,b")]
+            vec![None, Some("null"), Some("a,b"), Some("\u{00a0}c")]
         );
     }
 
@@ -1393,7 +1405,7 @@ mod tests {
             .with_default_value(Some("'STRUCT(\"a,b\", [1,2])'".into())),
         ];
         let schema = build_target_arrow_schema(&fields).unwrap();
-        let defaults = FormatTableDefaults::new(&fields, &schema).unwrap();
+        let defaults = ColumnDefaults::new(&fields, &schema, true).unwrap();
         let input = RecordBatch::try_new(
             schema.clone(),
             schema
@@ -1456,7 +1468,7 @@ mod tests {
             fields[0].data_type(),
             "MAP(a, 1, a, 2)",
             schema.field(0),
-            DefaultParsing::NewDefinition,
+            DefaultParsing::Java,
         )
         .unwrap();
         let map = value.as_any().downcast_ref::<MapArray>().unwrap();
@@ -1472,7 +1484,45 @@ mod tests {
     }
 
     #[test]
-    fn collection_defaults_validate_java_syntax_and_preserve_stored_values() {
+    fn binary_map_defaults_keep_all_java_entries() {
+        use crate::spec::{IntType, MapType, VarBinaryType};
+        use arrow_array::{BinaryArray, Int32Array};
+
+        let fields = [DataField::new(
+            0,
+            "lookup".into(),
+            DataType::Map(MapType::new(
+                DataType::VarBinary(VarBinaryType::new(8).unwrap()),
+                DataType::Int(IntType::new()),
+            )),
+        )
+        .with_default_value(Some("'{key -> 1, key -> 2}'".into()))];
+        let schema = build_target_arrow_schema(&fields).unwrap();
+        let defaults = ColumnDefaults::new(&fields, &schema, true).unwrap();
+        let batch = RecordBatch::try_new(
+            schema.clone(),
+            vec![arrow_array::new_null_array(schema.field(0).data_type(), 1)],
+        )
+        .unwrap();
+        let filled = defaults.apply(&batch).unwrap();
+        let map = filled
+            .column(0)
+            .as_any()
+            .downcast_ref::<MapArray>()
+            .unwrap();
+        let keys = map.keys().as_any().downcast_ref::<BinaryArray>().unwrap();
+        assert_eq!(
+            keys.iter().collect::<Vec<_>>(),
+            vec![Some(b"key".as_slice()); 2]
+        );
+        let values = 
map.values().as_any().downcast_ref::<Int32Array>().unwrap();
+        let mut values = values.values().to_vec();
+        values.sort_unstable();
+        assert_eq!(values, vec![1, 2]);
+    }
+
+    #[test]
+    fn collection_defaults_validate_java_syntax_and_keep_legacy_fallback() {
         use crate::spec::{ArrayType, IntType, MapType, RowType};
 
         let int = DataType::Int(IntType::new());
@@ -1481,33 +1531,28 @@ mod tests {
         let labels = DataType::Array(ArrayType::new(string.clone()));
         let lookup = DataType::Map(MapType::new(string, int.clone()));
         let row = DataType::Row(RowType::new(vec![DataField::new(1, 
"id".into(), int)]));
-        for (data_type, literal, writable, valid_in_java, 
valid_for_format_table) in [
-            (&numbers, "'[1, bad]'", false, false, false),
-            (&numbers, "'[1,\n2]'", true, false, false),
-            (&lookup, "'MAP(a,\n1)'", true, false, false),
-            (&row, "'STRUCT(\n1)'", true, false, false),
-            (&numbers, "'ARRAY\n(1, 2)'", true, true, true),
-            (&labels, "'[a, \u{00a0}b]'", true, true, false),
-            (&lookup, "'{a -> 1, \u{00a0}b -> 2}'", true, true, false),
+        for (data_type, literal, writable, valid_in_java) in [
+            (&numbers, "'[1, bad]'", false, false),
+            (&numbers, "'[1,\n2]'", true, false),
+            (&lookup, "'MAP(a,\n1)'", true, false),
+            (&row, "'STRUCT(\n1)'", true, false),
+            (&numbers, "'ARRAY\n(1, 2)'", true, true),
+            (&labels, "'[a, \u{00a0}b]'", true, true),
+            (&lookup, "'{a -> 1, \u{00a0}b -> 2}'", true, true),
         ] {
             let fields = [DataField::new(0, "value".into(), data_type.clone())
                 .with_default_value(Some(literal.into()))];
             let schema = build_target_arrow_schema(&fields).unwrap();
             assert_eq!(
-                FormatTableDefaults::new(&fields, &schema).is_ok(),
+                ColumnDefaults::new(&fields, &schema, true).is_ok(),
                 writable,
                 "{literal:?}"
             );
             assert_eq!(
-                validate_default_value(&fields[0], false).is_ok(),
+                validate_default_value(&fields[0]).is_ok(),
                 valid_in_java,
                 "{literal:?}"
             );
-            assert_eq!(
-                validate_default_value(&fields[0], true).is_ok(),
-                valid_for_format_table,
-                "{literal:?}"
-            );
         }
     }
 }
diff --git a/crates/paimon/src/table/format_table_writer.rs 
b/crates/paimon/src/table/format_table_writer.rs
index aaf8dfc9..803b7161 100644
--- a/crates/paimon/src/table/format_table_writer.rs
+++ b/crates/paimon/src/table/format_table_writer.rs
@@ -25,9 +25,9 @@ use std::sync::Arc;
 use arrow_array::RecordBatch;
 use arrow_schema::{Field, Schema as ArrowSchema};
 
+use super::column_defaults::ColumnDefaults;
 use super::commit_message::{CommitMessage, FormatFileCommit};
 use super::format_partition::FormatTablePartitionPaths;
-use super::format_table_defaults::FormatTableDefaults;
 use super::format_table_scan::supported_format_table_extension;
 use super::table_write::take_rows;
 use super::Table;
@@ -58,7 +58,7 @@ struct PartitionWriter {
 pub(crate) struct FormatTableWriter {
     table: Table,
     full_schema: Arc<ArrowSchema>,
-    defaults: FormatTableDefaults,
+    defaults: ColumnDefaults,
     file_schema: Arc<ArrowSchema>,
     file_fields: Vec<DataField>,
     partition_indices: Vec<usize>,
@@ -106,7 +106,7 @@ impl FormatTableWriter {
             }
         }
         let full_schema = build_target_arrow_schema(schema.fields())?;
-        let defaults = FormatTableDefaults::new(schema.fields(), 
&full_schema)?;
+        let defaults = ColumnDefaults::new(schema.fields(), &full_schema, 
true)?;
         let partition_indices = schema
             .partition_keys()
             .iter()
diff --git a/crates/paimon/src/table/mod.rs b/crates/paimon/src/table/mod.rs
index cc6c761b..d9098d06 100644
--- a/crates/paimon/src/table/mod.rs
+++ b/crates/paimon/src/table/mod.rs
@@ -44,6 +44,7 @@ mod bucket_router;
 mod centroid_bitmap;
 mod centroid_index;
 mod chunk_shuffle;
+mod column_defaults;
 mod commit_callback;
 mod commit_message;
 mod compact;
@@ -71,7 +72,6 @@ mod format_partition_stats;
 mod format_partition_truncate;
 mod format_read_builder;
 mod format_table_commit;
-mod format_table_defaults;
 mod format_table_read;
 mod format_table_scan;
 #[cfg(test)]
@@ -217,6 +217,7 @@ pub use 
batch_vector_search_builder::BatchVectorSearchBuilder;
 pub use blob_resolver::{BlobReader, BlobStream};
 pub use branch_manager::BranchManager;
 pub use bucket_router::BucketRouter;
+pub(crate) use column_defaults::validate_default_value;
 pub use commit_callback::{CommitCallback, CommitCallbackContext};
 pub use commit_message::{CommitMessage, COMMIT_MESSAGE_SERIALIZER_VERSION};
 pub use compact::{
@@ -236,7 +237,6 @@ pub use format_partition::{
 };
 pub use format_partition_stats::FormatTablePartitionStatsCollector;
 pub use format_partition_truncate::FormatTableTruncator;
-pub(crate) use format_table_defaults::validate_default_value;
 pub use full_text_search_builder::{
     FullTextRead, FullTextScan, FullTextScanPlan, FullTextSearchBuilder,
 };
diff --git a/crates/paimon/src/table/row_kind_generator.rs 
b/crates/paimon/src/table/row_kind_generator.rs
index 9631182a..c4d69b3e 100644
--- a/crates/paimon/src/table/row_kind_generator.rs
+++ b/crates/paimon/src/table/row_kind_generator.rs
@@ -45,7 +45,15 @@ impl RowKindGenerator {
         })
     }
 
-    pub fn generate_batch(&self, batch: &RecordBatch) -> 
crate::Result<Vec<RowKind>> {
+    pub(super) fn field_name(&self) -> &str {
+        &self.field_name
+    }
+
+    pub fn generate_batch(
+        &self,
+        batch: &RecordBatch,
+        default: Option<&str>,
+    ) -> crate::Result<Vec<RowKind>> {
         // with_write_type may reorder the physical columns. Resolve once for
         // the batch, then parse values without a per-row field-name search.
         let col =
@@ -60,6 +68,7 @@ impl RowKindGenerator {
                 })?;
         let parse = |value: Option<&str>| {
             value
+                .or(default)
                 .ok_or_else(|| crate::Error::DataInvalid {
                     message: "Row kind cannot be null.".into(),
                     source: None,
@@ -110,14 +119,18 @@ mod tests {
         let batch = RecordBatch::try_new(
             Arc::new(ArrowSchema::new(vec![
                 Arc::new(ArrowField::new("id", ArrowDataType::Int32, false)),
-                Arc::new(ArrowField::new("op", ArrowDataType::Utf8, false)),
+                Arc::new(ArrowField::new("op", ArrowDataType::Utf8, true)),
             ])),
             vec![
-                Arc::new(arrow_array::Int32Array::from(vec![1])),
-                Arc::new(StringArray::from(vec!["-D"])),
+                Arc::new(arrow_array::Int32Array::from(vec![1, 2])),
+                Arc::new(StringArray::from(vec![Some("-D"), None])),
             ],
         )
         .unwrap();
-        assert_eq!(gen.generate_batch(&batch).unwrap(), vec![RowKind::Delete]);
+        assert!(gen.generate_batch(&batch, None).is_err());
+        assert_eq!(
+            gen.generate_batch(&batch, Some("+I")).unwrap(),
+            vec![RowKind::Delete, RowKind::Insert]
+        );
     }
 }
diff --git a/crates/paimon/src/table/table_upsert.rs 
b/crates/paimon/src/table/table_upsert.rs
index cc32f9c3..eb0fcbc1 100644
--- a/crates/paimon/src/table/table_upsert.rs
+++ b/crates/paimon/src/table/table_upsert.rs
@@ -553,11 +553,14 @@ impl TableUpsert {
                 messages.extend(update.prepare_commit().await?);
             }
             for group in append_groups {
+                // The upsert already matched the supplied keys, including 
NULL.
+                // Preserve those values even when the row is written as an 
insert.
                 let mut append = self
                     .table
                     .new_write_builder()
                     .with_commit_user(self.commit_user.clone())?
-                    .new_write()?;
+                    .new_write()?
+                    .without_column_defaults();
                 
append.with_blob_uri_reader_factory(self.blob_uri_reader_factory.clone())?;
                 append.with_write_type(
                     group[0]
@@ -593,7 +596,7 @@ mod tests {
         BinaryRow, DataEvolutionIndexSourceMeta, DataType as PaimonType, 
IndexManifest,
         TimestampType, VarCharType,
     };
-    use crate::spec::{IntType, Schema as PaimonSchema, TableSchema};
+    use crate::spec::{DataField, IntType, Schema as PaimonSchema, TableSchema};
     use crate::table::TableCommit;
     use arrow_array::{Array, Int32Array, StringArray};
 
@@ -1469,6 +1472,36 @@ mod tests {
         assert_eq!(values_by_row_id(&table).await, vec![(0, 42)]);
     }
 
+    #[tokio::test]
+    async fn upsert_keeps_null_keys_when_the_column_has_a_default() {
+        let int = PaimonType::Int(IntType::new());
+        let schema = PaimonSchema::builder()
+            .field(
+                DataField::new(0, "key".into(), 
int.clone()).with_default_value(Some("42".into())),
+            )
+            .column("value", int)
+            .option("data-evolution.enabled", "true")
+            .option("row-tracking.enabled", "true")
+            .build()
+            .unwrap();
+        let table = Table::new(
+            FileIOBuilder::new("memory").build().unwrap(),
+            Identifier::new("db", "upsert_null_key"),
+            "memory:/upsert_null_key".into(),
+            TableSchema::new(0, &schema),
+            None,
+        );
+        for value in [1, 2] {
+            let source = RecordBatch::try_from_iter([
+                ("key", Arc::new(Int32Array::from(vec![None])) as ArrayRef),
+                ("value", Arc::new(Int32Array::from(vec![value])) as ArrayRef),
+            ])
+            .unwrap();
+            commit_upsert(&table, vec![source], vec!["key".into()]).await;
+        }
+        assert_eq!(values_by_row_id(&table).await, vec![(0, 2)]);
+    }
+
     #[tokio::test]
     async fn upsert_float_keys_keep_arrow_nan_and_signed_zero_identity() {
         use crate::spec::DoubleType;
diff --git a/crates/paimon/src/table/table_write.rs 
b/crates/paimon/src/table/table_write.rs
index fcefe68b..40a25be0 100644
--- a/crates/paimon/src/table/table_write.rs
+++ b/crates/paimon/src/table/table_write.rs
@@ -161,6 +161,7 @@ pub struct TableWrite {
     branch_schema_checked: bool,
     write_schema: Arc<arrow_schema::Schema>,
     write_fields: Vec<DataField>,
+    column_defaults: super::column_defaults::ColumnDefaults,
     written: bool,
     partition_writers: HashMap<PartitionBucketKey, FileWriter>,
     append_write_configs: HashMap<PartitionBucketKey, AppendWriteConfig>,
@@ -232,6 +233,7 @@ impl TableWrite {
             branch_schema_checked: table.is_main_branch() || 
table.rest_env.is_some(),
             write_schema: build_target_arrow_schema(schema.fields())?,
             write_fields: schema.fields().to_vec(),
+            column_defaults: Default::default(),
             written: false,
             partition_writers: HashMap::new(),
             append_write_configs: HashMap::new(),
@@ -297,6 +299,8 @@ impl TableWrite {
         )?;
         crate::spec::map_shredding::validate(schema.fields(), 
schema.options())?;
         let write_schema = build_target_arrow_schema(schema.fields())?;
+        let column_defaults =
+            super::column_defaults::ColumnDefaults::new(schema.fields(), 
&write_schema, false)?;
         let core_options = CoreOptions::new(schema.options());
         let blob_descriptor_fields = core_options.blob_descriptor_fields();
         let blob_view_fields = core_options.blob_view_fields();
@@ -528,6 +532,7 @@ impl TableWrite {
             branch_schema_checked: table.is_main_branch() || 
table.rest_env.is_some(),
             write_schema,
             write_fields: fields.to_vec(),
+            column_defaults,
             written: false,
             partition_writers: HashMap::new(),
             append_write_configs: HashMap::new(),
@@ -641,6 +646,11 @@ impl TableWrite {
         self
     }
 
+    pub(super) fn without_column_defaults(mut self) -> Self {
+        self.column_defaults = Default::default();
+        self
+    }
+
     /// Share write-buffer reservations with other consumers of this operation.
     /// Input batches remain the caller's responsibility; charges here estimate
     /// retained key-value batches and unflushed format-writer input. Call this
@@ -843,6 +853,21 @@ impl TableWrite {
         if batch.num_rows() == 0 {
             return Ok(None);
         }
+        let batch = if self.primary_key_indices.is_empty() {
+            self.column_defaults.apply(&batch)?
+        } else {
+            let kinds = batch
+                .column_by_name(VALUE_KIND_FIELD_NAME)
+                .unwrap()
+                .as_any()
+                .downcast_ref::<Int8Array>()
+                .unwrap();
+            // Changelog updates and retractions already identify a row. 
Applying
+            // a default to a NULL key here could change which row they affect.
+            self.column_defaults.apply_to_rows(&batch, |row| {
+                kinds.is_null(row) || kinds.value(row) == 
RowKind::Insert.to_value()
+            })?
+        };
         if !self.primary_key_indices.is_empty() {
             super::inline_blob::validate_inline_blob_columns(
                 &batch,
@@ -908,7 +933,10 @@ impl TableWrite {
         // Empty arrays check equivalent layouts without examining row values.
         
self.validate_write_batch_schema(&RecordBatch::new_empty(batch.schema()))?;
         let kinds = if let Some(generator) = &self.row_kind_generator {
-            generator.generate_batch(batch)?
+            generator.generate_batch(
+                batch,
+                self.column_defaults.string_value(generator.field_name()),
+            )?
         } else if let Some(column) = 
batch.column_by_name(VALUE_KIND_FIELD_NAME) {
             column
                 .as_any()
@@ -1340,7 +1368,10 @@ impl TableWrite {
         }
 
         let kinds = generator
-            .generate_batch(batch)?
+            .generate_batch(
+                batch,
+                self.column_defaults.string_value(generator.field_name()),
+            )?
             .into_iter()
             .map(|kind| kind.to_value())
             .collect();
@@ -2647,6 +2678,51 @@ pub(in crate::table) mod tests {
         );
     }
 
+    #[tokio::test]
+    async fn primary_key_defaults_apply_only_to_insert_rows_in_a_mixed_batch() 
{
+        let int = DataType::Int(IntType::new());
+        let schema = Schema::builder()
+            .field(DataField::new(0, "id".into(), 
int).with_default_value(Some("42".into())))
+            .primary_key(["id"])
+            .option("primary-key.nullable", "true")
+            .option("bucket", "1")
+            .build()
+            .unwrap();
+        let table = Table::new(
+            test_file_io(),
+            Identifier::new("default", "mixed_default_rows"),
+            "memory:/mixed_default_rows".into(),
+            TableSchema::new(0, &schema),
+            None,
+        );
+        let input = RecordBatch::try_from_iter([
+            ("id", Arc::new(Int32Array::from(vec![None; 5])) as ArrayRef),
+            (
+                VALUE_KIND_FIELD_NAME,
+                Arc::new(Int8Array::from(vec![
+                    Some(RowKind::Insert.to_value()),
+                    Some(RowKind::UpdateBefore.to_value()),
+                    Some(RowKind::UpdateAfter.to_value()),
+                    Some(RowKind::Delete.to_value()),
+                    None,
+                ])) as ArrayRef,
+            ),
+        ])
+        .unwrap();
+        let writer = table.new_write_builder().new_write().unwrap();
+        let actual = writer.normalize_write_batch(&input).unwrap().unwrap();
+        let keys = actual
+            .column(0)
+            .as_any()
+            .downcast_ref::<Int32Array>()
+            .unwrap();
+        assert_eq!(
+            keys,
+            &Int32Array::from(vec![Some(42), None, None, None, Some(42)])
+        );
+        assert_eq!(actual.column(1), input.column(1));
+    }
+
     #[tokio::test]
     async fn 
test_rowkind_field_accepts_table_schema_and_rejects_caller_value_kind() {
         let file_io = test_file_io();
@@ -2655,7 +2731,14 @@ pub(in crate::table) mod tests {
         let schema = Schema::builder()
             .column("id", DataType::Int(IntType::new()))
             .column("value", DataType::Int(IntType::new()))
-            .column("op", DataType::VarChar(VarCharType::string_type()))
+            .field(
+                DataField::new(
+                    2,
+                    "op".into(),
+                    DataType::VarChar(VarCharType::string_type()),
+                )
+                .with_default_value(Some("'+I'".into())),
+            )
             .primary_key(["id"])
             .option("bucket", "1")
             .option("rowkind.field", "op")
@@ -2703,12 +2786,12 @@ pub(in crate::table) mod tests {
             Arc::new(ArrowSchema::new(vec![
                 ArrowField::new("id", ArrowDataType::Int32, false),
                 ArrowField::new("value", ArrowDataType::Int32, false),
-                ArrowField::new("op", ArrowDataType::Utf8, false),
+                ArrowField::new("op", ArrowDataType::Utf8, true),
             ])),
             vec![
                 Arc::new(Int32Array::from(vec![1])),
                 Arc::new(Int32Array::from(vec![10])),
-                Arc::new(StringArray::from(vec!["+I"])),
+                Arc::new(StringArray::from(vec![None::<&str>])),
             ],
         )
         .unwrap();
diff --git a/crates/paimon/src/table/table_write_input.rs 
b/crates/paimon/src/table/table_write_input.rs
index a5987da4..770760c4 100644
--- a/crates/paimon/src/table/table_write_input.rs
+++ b/crates/paimon/src/table/table_write_input.rs
@@ -156,6 +156,7 @@ impl TableWrite {
                 .collect::<Vec<_>>(),
         ));
         let batch = self.normalize_batch_schema(&batch, &schema)?;
+        let batch = self.column_defaults.apply(&batch)?;
         Ok(RoutingInput { batch, fields })
     }
 
diff --git a/docs/src/getting-started.md b/docs/src/getting-started.md
index d6805ecf..62fb750d 100644
--- a/docs/src/getting-started.md
+++ b/docs/src/getting-started.md
@@ -585,10 +585,14 @@ validation. For example, changing `BIGINT DEFAULT 
2147483648` to `INT` fails
 before a Rust catalog publishes a new schema. Java's collection literal syntax
 requires the contents inside the delimiters to fit on one line.
 
-For Format Tables, Rust also rejects defaults such as
-`TIME(3) DEFAULT '00:00:00.0005'` when Java and Rust writers interpret them
-differently. Rust Format Table writers preserve the original interpretation of
-persisted defaults, including timestamp literals with an explicit offset.
+Rust applies column defaults to NULL values on insert before partition and
+bucket routing. The writer uses Java's interpretation
+for valid defaults. For example, `TIME(3) DEFAULT '00:00:00.0005'` writes
+`00:00:00.001`, including on an existing table with that default. A Format
+Table with a persisted default that Java rejects still uses Rust's legacy
+parser. This includes timestamp literals with an explicit offset. Updates and
+retractions in primary-key changelogs preserve the values supplied by the
+caller. Data Evolution upserts preserve the values used for matching.
 
 ## Reading a Table
 

Reply via email to