JingsongLi commented on code in PR #1447:
URL: https://github.com/apache/paimon-rust/pull/1447#discussion_r4662643512


##########
crates/paimon/src/table/format_table_defaults.rs:
##########
@@ -406,29 +285,117 @@ fn cast_default(
                 *sorted,
             )?))
         }
-        DataType::Multiset(_) => Err(cast_error(
-            "Java does not support casting a string default to MULTISET",
-        )),
-        DataType::Vector(_) => Err(cast_error(
-            "Java does not support casting a string default to VECTOR",
-        )),
-        DataType::Variant(_) => Err(cast_error(
-            "Java does not support casting a string default to VARIANT",
-        )),
-        DataType::Blob(_) => Err(arrow_schema::ArrowError::CastError(
-            "Java does not support casting a string default to BLOB".into(),
-        )),
-        _ => arrow_cast::cast(&StringArray::from(vec![text]), 
arrow_field.data_type()),
+        _ => cast_scalar_default(data_type, text, arrow_field.data_type(), 
parsing),
     }
 }
 
-fn numeric_default(text: &str) -> bool {
+fn cast_scalar_default(
+    data_type: &DataType,
+    text: &str,
+    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.
+        let legacy = match data_type {
+            DataType::Timestamp(typ) => cast_legacy_timestamp(text, 
typ.precision(), arrow_type),
+            DataType::LocalZonedTimestamp(typ) => {
+                cast_legacy_local_zoned_timestamp(text, typ.precision(), 
arrow_type)
+            }
+            DataType::Date(_) | DataType::Time(_) if is_unsigned_integer(text) 
=> {
+                return cast_java_scalar_default(data_type, text);
+            }
+            DataType::Boolean(_)
+            | DataType::Decimal(_)
+            | DataType::Float(_)
+            | DataType::Double(_)
+            | DataType::Date(_)
+            | DataType::Time(_)
+            | DataType::Geometry(_)
+            | DataType::Geography(_) => {
+                arrow_cast::cast(&StringArray::from(vec![text]), arrow_type)
+            }
+            _ => return cast_java_scalar_default(data_type, text),
+        };
+        if let Some(value) = legacy.ok().filter(|value| !value.is_null(0)) {

Review Comment:
   **[P1] Make new `TIME` defaults agree across Rust and Java**
   
   I reproduced this with `FileSystemCatalog` and a Parquet Format Table. I 
changed a column from `STRING DEFAULT '00:00:00.0005'` to `TIME(3)`, then wrote 
a row with `NULL` in that column. The ALTER published schema version 1, and 
Rust read `00:00:00.000` back from Parquet. On the same literal, Java’s 
`DefaultValueUtils.convertDefaultValue(TIME(3), ...)` returned `1` ms 
(`00:00:00.001`).
   
   DDL validates the retained default with the Java-compatible parser, but this 
branch gives the legacy Arrow result precedence for all stored defaults, 
including the one just published by ALTER. Could we canonicalize new or 
type-changed defaults before persisting them so both writers apply the same 
value? Another option is to reject a definition when the two parsers disagree. 
Either approach can preserve the interpretation of existing definitions. Please 
add a regression that checks the Parquet value after ALTER, or verifies that a 
rejected ALTER leaves the schema version unchanged.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to