xushiyan commented on code in PR #302:
URL: https://github.com/apache/hudi-rs/pull/302#discussion_r2041204480


##########
crates/core/src/table/mod.rs:
##########
@@ -474,6 +481,36 @@ impl Table {
     }
 }
 
+/// Formats a timestamp string to `yyyyMMddHHmmSSSSS` format.
+///
+/// The function attempts to parse the input timestamp string (`timestamp`) 
into a `DateTime` object.
+/// It first tries parsing the ISO 8601 format, and if that fails, it tries 
two other formats: `yyyyMMddHHmmSSSSS`
+/// and `yyyyMMddHHmmSS`. If none of the formats match, it returns the 
original input string.
+///
+/// # Arguments
+/// - `timestamp`: The input timestamp string to be formatted.
+///
+/// # Returns
+/// A string formatted as `yyyyMMddHHmmSSSSS`. If the input cannot be parsed, 
the original string is returned.
+fn format_timestamp(timestamp: &str) -> String {
+    if let Ok(datetime) = DateTime::parse_from_rfc3339(timestamp) {
+        return datetime.format("%Y%m%d%H%M%S%3f").to_string();
+    }
+
+    let formats = ["yyyyMMddHHmmSSSSS", "yyyyMMddHHmmSS"];
+    for format in formats.iter() {
+        if let Ok(datetime) = DateTime::parse_from_str(timestamp, format) {
+            return datetime.format("%Y%m%d%H%M%S%3f").to_string();
+        }
+    }
+
+    if timestamp.len() == 10 && timestamp.chars().all(|c| c.is_digit(10) || c 
== '-') {

Review Comment:
   what cases are meant for this check? this checking logic is hard to maintain 
- please use proper pattern matching to improve the case handling



##########
crates/core/src/table/mod.rs:
##########
@@ -474,6 +481,36 @@ impl Table {
     }
 }
 
+/// Formats a timestamp string to `yyyyMMddHHmmSSSSS` format.
+///
+/// The function attempts to parse the input timestamp string (`timestamp`) 
into a `DateTime` object.
+/// It first tries parsing the ISO 8601 format, and if that fails, it tries 
two other formats: `yyyyMMddHHmmSSSSS`
+/// and `yyyyMMddHHmmSS`. If none of the formats match, it returns the 
original input string.
+///
+/// # Arguments
+/// - `timestamp`: The input timestamp string to be formatted.
+///
+/// # Returns
+/// A string formatted as `yyyyMMddHHmmSSSSS`. If the input cannot be parsed, 
the original string is returned.
+fn format_timestamp(timestamp: &str) -> String {

Review Comment:
   i'd expect this returning a Result - if users pass a timestamp str that 
can't be converted to hudi timeline format properly, then the flow should early 
return.
   
   The user-provided timestamp should also conform to timezone config of the 
table - this is by default utc; but it could be configured as `local`.



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