You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "dy102 (via GitHub)" <gi...@apache.org> on 2025/04/25 16:32:06 UTC

[PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

dy102 opened a new pull request, #9234:
URL: https://github.com/apache/seatunnel/pull/9234

   Fixes https://github.com/apache/seatunnel/issues/9197
   
   ### Purpose of this pull request
   
   This PR addresses an issue where MaxCompute may treat timestamp values containing `"T"` (e.g., `"2024-04-25T10:15:30"`) as `NULL` during processing.  
   - Remove `"T"` during `LocalDateTime -> String` conversion to produce `"2024-04-25 10:15"` format.  
   
   ### Questions for reviewers
   
   1. In our current implementation, converting external timestamp data into `SeaTunnelRowData` via `LocalDateTime` appears to drop the seconds (and milliseconds).  
   2. However, the issue’s example shows the seconds are preserved.  
      
   While reviewing the existing timestamp handling, I found that LocalDateTime seems to be constructed without preserving the seconds value, even when the original timestamp includes it. I wonder if this is an intended behavior, or if I might have misunderstood the expected input/output format.
   
   
   ### Does this PR introduce _any_ user-facing change?
   
   
   ### How was this patch tested?
   
   A unit test has been added to verify the conversion behavior from TIMESTAMP to STRING format.
   Since the input and output types are different in this scenario (from OdpsType.TIMESTAMP to OdpsType.STRING), an additional helper method testTypeWithDifferentInputAndOutput was created instead of using the existing test methods.
   
   The test checks whether:
   
   A Timestamp value containing the "T" character (e.g., 2025-01-01T00:00:00) is properly converted by removing the "T".
   
   This helps ensure that the logic for converting timestamp values into strings is compatible with MaxCompute's expected format.
   
   
   ### Check list
   
   * [ ] If any new Jar binary package adding in your PR, please add License Notice according
     [New License Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/contribution/new-license.md)
   * [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/seatunnel/tree/dev/docs
   * [ ] If you are contributing the connector code, please check that the following files are updated:
     1. Update [plugin-mapping.properties](https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties) and add new connector information in it
     2. Update the pom file of [seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml)
     3. Add ci label in [label-scope-conf](https://github.com/apache/seatunnel/blob/dev/.github/workflows/labeler/label-scope-conf.yml)
     4. Add e2e testcase in [seatunnel-e2e](https://github.com/apache/seatunnel/tree/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/)
     5. Update connector [plugin_config](https://github.com/apache/seatunnel/blob/dev/config/plugin_config)
   * [ ] Update the [`release-note`](https://github.com/apache/seatunnel/blob/dev/release-note.md).


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "hailin0 (via GitHub)" <gi...@apache.org>.
hailin0 commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2079211634


##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/sink/MaxcomputeSinkFactory.java:
##########
@@ -52,6 +52,8 @@ public OptionRule optionRule() {
                         MaxcomputeSinkOptions.DATA_SAVE_MODE,
                         MaxcomputeSinkOptions.SAVE_MODE_CREATE_TEMPLATE,
                         MaxcomputeSinkOptions.CUSTOM_SQL,
+                        MaxcomputeSinkOptions.LOCAL_DATETIME_FORMAT,
+                        MaxcomputeSinkOptions.OFFSET_DATETIME_FORMAT,

Review Comment:
   update docs



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2083504877


##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/config/MaxcomputeSinkOptions.java:
##########
@@ -46,6 +46,18 @@ public class MaxcomputeSinkOptions extends MaxcomputeBaseOptions {
     public static final Option<String> CUSTOM_SQL =
             Options.key("custom_sql").stringType().noDefaultValue().withDescription("custom_sql");
 
+    public static final Option<String> LOCAL_DATETIME_FORMAT =
+            Options.key("local_datetime_format")
+                    .stringType()
+                    .defaultValue("yyyy-MM-dd HH:mm:ss")
+                    .withDescription("local_datetime_format");
+
+    public static final Option<String> OFFSET_DATETIME_FORMAT =
+            Options.key("offset_datetime_format")
+                    .stringType()
+                    .defaultValue("yyyy-MM-dd HH:mm:ssXXXXX")
+                    .withDescription("offset_datetime_format");
+

Review Comment:
   @Hisoka-X 
   I'm running into CI failures, but I'm having trouble identifying whether they are caused by my changes.
   
   I ran the failing tests locally and found that:
   - Some of them pass on my machine, while others fail.
   - I checked out the `main` branch and ran the same tests, and **the same ones are still failing** there as well.
   
   This makes me wonder if some of the tests might be flaky or already broken on `main`.
   
   If you have any guidance on how I should approach this or if there's something I'm missing, I'd really appreciate the help



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "dy102 (via GitHub)" <gi...@apache.org>.
dy102 commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2061953038


##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/util/MaxcomputeTypeMapper.java:
##########
@@ -272,6 +272,9 @@ private static Object resolveObject2Maxcompute(Object field, TypeInfo typeInfo)
             case CHAR:
                 return new Char((String) field);
             case STRING:

Review Comment:
   Thank you for the suggestion!
   Based on my understanding, the Timestamp value is already converted to LocalDateTime during the SeaTunnelRow mapping process.
   Therefore, the subsequent formatting operation only affects the string output, without impacting the internal precision.
   In this context, I believe an additional conversion here might be redundant. 🙏



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "dy102 (via GitHub)" <gi...@apache.org>.
dy102 commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2062812103


##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/util/MaxcomputeTypeMapper.java:
##########
@@ -272,6 +272,9 @@ private static Object resolveObject2Maxcompute(Object field, TypeInfo typeInfo)
             case CHAR:
                 return new Char((String) field);
             case STRING:
+                if (field instanceof LocalDateTime) {
+                    return field.toString().replace("T", " ");

Review Comment:
   Hi, regarding the time format, should we preserve milliseconds (yyyy-MM-dd HH:mm:ss.SSS), or just keep seconds (yyyy-MM-dd HH:mm:ss) as shown in the issue example? I want to ensure that the output format matches your expectation. Thanks!
   
   



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "dy102 (via GitHub)" <gi...@apache.org>.
dy102 commented on PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#issuecomment-2831997347

   During the rebase process, I mistakenly included commits from a previously merged PR.
   I sincerely apologize for the confusion.
   Kindly note that only the actual intended changes in this PR need to be reviewed. Thank you for your understanding.


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "hailin0 (via GitHub)" <gi...@apache.org>.
hailin0 commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2079209095


##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/util/FormatterContext.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.maxcompute.util;
+
+import java.time.LocalDateTime;
+import java.time.OffsetDateTime;
+import java.time.format.DateTimeFormatter;
+
+public class FormatterContext {
+    private final String localDateTimeFormat;
+    private final String offsetDateTimeFormat;
+
+    public FormatterContext(String localDateTimeFormat, String offsetDateTimeFormat) {
+        this.localDateTimeFormat = localDateTimeFormat;
+        this.offsetDateTimeFormat = offsetDateTimeFormat;

Review Comment:
   ```suggestion
           this.localDateTimeFormatter = DateTimeFormatter.ofPattern(localDateTimeFormat);
           this.offsetDateTimeFormatter = DateTimeFormatter.ofPattern(offsetDateTimeFormat);
   ```



##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/util/FormatterContext.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.maxcompute.util;
+
+import java.time.LocalDateTime;
+import java.time.OffsetDateTime;
+import java.time.format.DateTimeFormatter;
+
+public class FormatterContext {
+    private final String localDateTimeFormat;
+    private final String offsetDateTimeFormat;
+
+    public FormatterContext(String localDateTimeFormat, String offsetDateTimeFormat) {
+        this.localDateTimeFormat = localDateTimeFormat;
+        this.offsetDateTimeFormat = offsetDateTimeFormat;

Review Comment:
   You only need to create the Formatter once



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2104210338


##########
docs/en/connector-v2/sink/Maxcompute.md:
##########
@@ -112,6 +112,26 @@ Option introduction:
 
 When data_save_mode selects CUSTOM_PROCESSING, you should fill in the CUSTOM_SQL parameter. This parameter usually fills in a SQL that can be executed. SQL will be executed before synchronization tasks.
 
+### datetime_format_value[String]

Review Comment:
   Sorry! I missed that you'd already updated it 😅
   I accidentally re-modified the same part.



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2103137344


##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/sink/MaxcomputeWriter.java:
##########
@@ -66,6 +69,15 @@ public MaxcomputeWriter(ReadonlyConfig readonlyConfig, SeaTunnelRowType rowType)
                                 readonlyConfig.get(MaxcomputeSinkOptions.PROJECT),
                                 readonlyConfig.get(MaxcomputeSinkOptions.TABLE_NAME));
             }
+            if (readonlyConfig.getOptional(FormatOptions.DATETIME_FORMAT_VALUE).isPresent()) {
+                this.formatterContext =
+                        new FormatterContext(
+                                readonlyConfig.get(FormatOptions.DATETIME_FORMAT_VALUE));
+            } else {
+                this.formatterContext =
+                        new FormatterContext(readonlyConfig.get(FormatOptions.DATETIME_FORMAT));
+            }

Review Comment:
   Thanks for the detailed suggestions, @Hisoka-X!
   
   I've:
   - Renamed *_VALUE options to align with existing names (e.g., DATE_FORMAT)
   - Marked previous enum-based options as legacy (e.g., DATE_FORMAT_LEGACY)
   - Used the same key for the new string-based option as the legacy one, so we can switch seamlessly later on
   - Removed the format validation logic as suggested
   - Introduced default format in format options
   
   Let me know if there's anything else I should adjust!



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "dy102 (via GitHub)" <gi...@apache.org>.
dy102 commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2062812103


##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/util/MaxcomputeTypeMapper.java:
##########
@@ -272,6 +272,9 @@ private static Object resolveObject2Maxcompute(Object field, TypeInfo typeInfo)
             case CHAR:
                 return new Char((String) field);
             case STRING:
+                if (field instanceof LocalDateTime) {
+                    return field.toString().replace("T", " ");

Review Comment:
   @hailin0 Hi, regarding the time format, should we preserve milliseconds (yyyy-MM-dd HH:mm:ss.SSS), or just keep seconds (yyyy-MM-dd HH:mm:ss) as shown in the issue example? I want to ensure that the output format matches your expectation. Thanks!
   
   



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "hailin0 (via GitHub)" <gi...@apache.org>.
hailin0 commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2067727449


##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/util/MaxcomputeTypeMapper.java:
##########
@@ -272,6 +272,9 @@ private static Object resolveObject2Maxcompute(Object field, TypeInfo typeInfo)
             case CHAR:
                 return new Char((String) field);
             case STRING:
+                if (field instanceof LocalDateTime) {
+                    return field.toString().replace("T", " ");

Review Comment:
   You can use `yyyy-MM-dd HH:mm:ss` by default and then allow users to configure



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "corgy-w (via GitHub)" <gi...@apache.org>.
corgy-w commented on PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#issuecomment-2831781632

   Please open ci according to the [instructions](https://github.com/apache/seatunnel/pull/9234/checks?check_run_id=41171551750)


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2061269988


##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/util/MaxcomputeTypeMapper.java:
##########
@@ -272,6 +272,9 @@ private static Object resolveObject2Maxcompute(Object field, TypeInfo typeInfo)
             case CHAR:
                 return new Char((String) field);
             case STRING:

Review Comment:
   The conversion logic applies only to LocalDateTime instances, but the test passes a Timestamp instance. Consider converting Timestamp values to LocalDateTime (e.g., using toLocalDateTime()) before applying the formatting to ensure consistent behavior.
   ```suggestion
               case STRING:
                   if (field instanceof Timestamp) {
                       field = ((Timestamp) field).toLocalDateTime();
                   }
   ```



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2103137344


##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/sink/MaxcomputeWriter.java:
##########
@@ -66,6 +69,15 @@ public MaxcomputeWriter(ReadonlyConfig readonlyConfig, SeaTunnelRowType rowType)
                                 readonlyConfig.get(MaxcomputeSinkOptions.PROJECT),
                                 readonlyConfig.get(MaxcomputeSinkOptions.TABLE_NAME));
             }
+            if (readonlyConfig.getOptional(FormatOptions.DATETIME_FORMAT_VALUE).isPresent()) {
+                this.formatterContext =
+                        new FormatterContext(
+                                readonlyConfig.get(FormatOptions.DATETIME_FORMAT_VALUE));
+            } else {
+                this.formatterContext =
+                        new FormatterContext(readonlyConfig.get(FormatOptions.DATETIME_FORMAT));
+            }

Review Comment:
   Thanks for the detailed suggestions, @Hisoka-X!
   I've:
   - Renamed *_VALUE options to align with existing names (e.g., DATE_FORMAT)
   - Marked previous enum-based options as legacy (e.g., DATE_FORMAT_LEGACY)
   - Used the same key for the new string-based option as the legacy one, so we can switch seamlessly later on
   - Removed the format validation logic as suggested
   - Introduced default format in format options
   
   Let me know if there's anything else I should adjust!



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2094523285


##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/util/FormatterContext.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.maxcompute.util;
+
+import org.apache.seatunnel.common.exception.CommonError;
+import org.apache.seatunnel.common.utils.DateTimeUtils;
+
+import java.time.LocalDateTime;
+
+public class FormatterContext {
+    private final DateTimeUtils.Formatter localDateTimeFormat;
+
+    public FormatterContext(DateTimeUtils.Formatter localDateTimeFormat) {
+        String format = localDateTimeFormat.getValue();
+        if (format.contains("T")) {
+            throw CommonError.illegalArgument(
+                    format, "MaxCompute does not support datetime format containing 'T'.");
+        }
+        this.localDateTimeFormat = localDateTimeFormat;
+    }
+
+    public boolean isDateTimeType(Object field) {
+        return field instanceof LocalDateTime;
+    }
+
+    public String formatDateTime(Object field) {
+        if (field instanceof LocalDateTime) {
+            return this.format(((LocalDateTime) field));
+        }
+        return String.valueOf(field);

Review Comment:
   Resolved in latest commit. Now throws exception if it is not supported.



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2094522243


##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/sink/MaxcomputeWriter.java:
##########
@@ -66,6 +69,9 @@ public MaxcomputeWriter(ReadonlyConfig readonlyConfig, SeaTunnelRowType rowType)
                                 readonlyConfig.get(MaxcomputeSinkOptions.PROJECT),
                                 readonlyConfig.get(MaxcomputeSinkOptions.TABLE_NAME));
             }
+            this.formatterContext =
+                    new FormatterContext(
+                            readonlyConfig.get(ConnectorCommonOptions.DATETIME_FORMAT));

Review Comment:
   I’ve applied your suggestion: now using DateTimeUtils.parse() for user input and added a String-typed option in FormatOptions to support flexible formats. Let me know if any further changes are needed!



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#issuecomment-2907942334

   Hi @Hisoka-X, I found that the CI is failing, and I tried to investigate the cause.
   
   It seems to fail with the following error:
   
   Caused by: [CIRCULAR REFERENCE: org.apache.seatunnel.connectors.seatunnel.jdbc.exception.JdbcConnectorException: ErrorCode:[JDBC-04], ErrorDescription:[Connector database failed] - unable to open JDBC writer]
    ==> expected: <0> but was: <1>
   Error:  Errors: 
   Error:    JdbcIrisIT » Completion org.testcontainers.containers.ContainerLaunchException...
   
   I'm not sure why this error is happening.  
   Do you happen to know the cause, or have any suggestions on how to fix it?
   
   Thanks in advance!


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2080818768


##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/config/MaxcomputeSinkOptions.java:
##########
@@ -46,6 +46,18 @@ public class MaxcomputeSinkOptions extends MaxcomputeBaseOptions {
     public static final Option<String> CUSTOM_SQL =
             Options.key("custom_sql").stringType().noDefaultValue().withDescription("custom_sql");
 
+    public static final Option<String> LOCAL_DATETIME_FORMAT =
+            Options.key("local_datetime_format")
+                    .stringType()
+                    .defaultValue("yyyy-MM-dd HH:mm:ss")
+                    .withDescription("local_datetime_format");
+
+    public static final Option<String> OFFSET_DATETIME_FORMAT =
+            Options.key("offset_datetime_format")
+                    .stringType()
+                    .defaultValue("yyyy-MM-dd HH:mm:ssXXXXX")
+                    .withDescription("offset_datetime_format");
+

Review Comment:
   We have same option in https://github.com/apache/seatunnel/blob/2cc49039f53d99a94e67b675cacd32ec6d8122e3/seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/config/FileBaseSinkOptions.java#L100-L116. Could you add new common format option in https://github.com/apache/seatunnel/tree/2cc49039f53d99a94e67b675cacd32ec6d8122e3/seatunnel-api/src/main/java/org/apache/seatunnel/api/options/table to make sure all same feature use same option?



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2094523285


##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/util/FormatterContext.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.maxcompute.util;
+
+import org.apache.seatunnel.common.exception.CommonError;
+import org.apache.seatunnel.common.utils.DateTimeUtils;
+
+import java.time.LocalDateTime;
+
+public class FormatterContext {
+    private final DateTimeUtils.Formatter localDateTimeFormat;
+
+    public FormatterContext(DateTimeUtils.Formatter localDateTimeFormat) {
+        String format = localDateTimeFormat.getValue();
+        if (format.contains("T")) {
+            throw CommonError.illegalArgument(
+                    format, "MaxCompute does not support datetime format containing 'T'.");
+        }
+        this.localDateTimeFormat = localDateTimeFormat;
+    }
+
+    public boolean isDateTimeType(Object field) {
+        return field instanceof LocalDateTime;
+    }
+
+    public String formatDateTime(Object field) {
+        if (field instanceof LocalDateTime) {
+            return this.format(((LocalDateTime) field));
+        }
+        return String.valueOf(field);

Review Comment:
   Resolved in latest commit. Now throws exception if formatting is not supported.



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2104197612


##########
docs/en/connector-v2/sink/Maxcompute.md:
##########
@@ -112,6 +112,26 @@ Option introduction:
 
 When data_save_mode selects CUSTOM_PROCESSING, you should fill in the CUSTOM_SQL parameter. This parameter usually fills in a SQL that can be executed. SQL will be executed before synchronization tasks.
 
+### datetime_format_value[String]

Review Comment:
   sorry I forgot it🥲



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#issuecomment-2908352631

   Hi @dybyte , I found iris docker image be removed by iris team. So I create an pr to fix it https://github.com/apache/seatunnel/pull/9360. Thanks for your report!
   
   This issue will not affect the merging of PR


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "hailin0 (via GitHub)" <gi...@apache.org>.
hailin0 commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2062792964


##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/util/MaxcomputeTypeMapper.java:
##########
@@ -272,6 +272,9 @@ private static Object resolveObject2Maxcompute(Object field, TypeInfo typeInfo)
             case CHAR:
                 return new Char((String) field);
             case STRING:
+                if (field instanceof LocalDateTime) {
+                    return field.toString().replace("T", " ");

Review Comment:
   your need to add time format config



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2072417976


##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/util/MaxcomputeTypeMapper.java:
##########
@@ -272,6 +272,9 @@ private static Object resolveObject2Maxcompute(Object field, TypeInfo typeInfo)
             case CHAR:
                 return new Char((String) field);
             case STRING:
+                if (field instanceof LocalDateTime) {
+                    return field.toString().replace("T", " ");

Review Comment:
   Hi @hailin0 , sorry for the delay — I’ve updated the PR according to your feedback from a few days ago.  
   Please take a look when you have time. Thank you!



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2072417976


##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/util/MaxcomputeTypeMapper.java:
##########
@@ -272,6 +272,9 @@ private static Object resolveObject2Maxcompute(Object field, TypeInfo typeInfo)
             case CHAR:
                 return new Char((String) field);
             case STRING:
+                if (field instanceof LocalDateTime) {
+                    return field.toString().replace("T", " ");

Review Comment:
   Hi @hailin0 , sorry for the delay — I’ve updated the PR according to your feedback.  
   Please take a look when you have time. Thank you!



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2103852857


##########
seatunnel-connectors-v2/connector-maxcompute/src/test/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/BasicTypeToOdpsTypeTest.java:
##########
@@ -34,9 +37,18 @@
 import com.aliyun.odps.data.Record;
 import lombok.SneakyThrows;
 
+import java.sql.Timestamp;
 import java.time.LocalDate;
 
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 public class BasicTypeToOdpsTypeTest {
+    public static FormatterContext defaultFormatterContext =

Review Comment:
   Please update test case with default string format value.



##########
docs/en/connector-v2/sink/Maxcompute.md:
##########
@@ -112,6 +112,46 @@ Option introduction:
 
 When data_save_mode selects CUSTOM_PROCESSING, you should fill in the CUSTOM_SQL parameter. This parameter usually fills in a SQL that can be executed. SQL will be executed before synchronization tasks.
 
+### datetime_format[Enum]

Review Comment:
   Please update the docs too.



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2101541177


##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/options/table/FormatOptions.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.seatunnel.api.options.table;
+
+import org.apache.seatunnel.api.configuration.Option;
+import org.apache.seatunnel.api.configuration.Options;
+import org.apache.seatunnel.common.utils.DateTimeUtils;
+import org.apache.seatunnel.common.utils.DateUtils;
+import org.apache.seatunnel.common.utils.TimeUtils;
+
+public interface FormatOptions {
+    Option<DateUtils.Formatter> DATE_FORMAT =
+            Options.key("date_format")
+                    .enumType(DateUtils.Formatter.class)
+                    .defaultValue(DateUtils.Formatter.YYYY_MM_DD)
+                    .withDescription("Date format");
+
+    Option<DateTimeUtils.Formatter> DATETIME_FORMAT =
+            Options.key("datetime_format")
+                    .enumType(DateTimeUtils.Formatter.class)
+                    .defaultValue(DateTimeUtils.Formatter.YYYY_MM_DD_HH_MM_SS)
+                    .withDescription("Datetime format");
+
+    Option<TimeUtils.Formatter> TIME_FORMAT =
+            Options.key("time_format")
+                    .enumType(TimeUtils.Formatter.class)
+                    .defaultValue(TimeUtils.Formatter.HH_MM_SS)
+                    .withDescription("Time format");
+
+    // Not used yet. Reserved for future use to support custom date/time format strings.
+    Option<String> DATE_FORMAT_VALUE =
+            Options.key("date_format_value")

Review Comment:
   ```suggestion
               Options.key("date_format")
   ```
   
   We should use same option name as `DATE_FORMAT`. This way we can switch seamlessly later on.



##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/options/table/FormatOptions.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.seatunnel.api.options.table;
+
+import org.apache.seatunnel.api.configuration.Option;
+import org.apache.seatunnel.api.configuration.Options;
+import org.apache.seatunnel.common.utils.DateTimeUtils;
+import org.apache.seatunnel.common.utils.DateUtils;
+import org.apache.seatunnel.common.utils.TimeUtils;
+
+public interface FormatOptions {
+    Option<DateUtils.Formatter> DATE_FORMAT =

Review Comment:
   ```suggestion
       Option<DateUtils.Formatter> DATE_FORMAT_LEGACY =
   ```



##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/sink/MaxcomputeSinkFactory.java:
##########
@@ -52,6 +53,8 @@ public OptionRule optionRule() {
                         MaxcomputeSinkOptions.DATA_SAVE_MODE,
                         MaxcomputeSinkOptions.SAVE_MODE_CREATE_TEMPLATE,
                         MaxcomputeSinkOptions.CUSTOM_SQL,
+                        FormatOptions.DATETIME_FORMAT,
+                        FormatOptions.DATETIME_FORMAT_VALUE,

Review Comment:
   ```suggestion
                           FormatOptions.DATETIME_FORMAT,
   ```
   Only keep the new format.
   



##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/options/table/FormatOptions.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.seatunnel.api.options.table;
+
+import org.apache.seatunnel.api.configuration.Option;
+import org.apache.seatunnel.api.configuration.Options;
+import org.apache.seatunnel.common.utils.DateTimeUtils;
+import org.apache.seatunnel.common.utils.DateUtils;
+import org.apache.seatunnel.common.utils.TimeUtils;
+
+public interface FormatOptions {
+    Option<DateUtils.Formatter> DATE_FORMAT =
+            Options.key("date_format")
+                    .enumType(DateUtils.Formatter.class)
+                    .defaultValue(DateUtils.Formatter.YYYY_MM_DD)
+                    .withDescription("Date format");
+
+    Option<DateTimeUtils.Formatter> DATETIME_FORMAT =
+            Options.key("datetime_format")
+                    .enumType(DateTimeUtils.Formatter.class)
+                    .defaultValue(DateTimeUtils.Formatter.YYYY_MM_DD_HH_MM_SS)
+                    .withDescription("Datetime format");
+
+    Option<TimeUtils.Formatter> TIME_FORMAT =
+            Options.key("time_format")
+                    .enumType(TimeUtils.Formatter.class)
+                    .defaultValue(TimeUtils.Formatter.HH_MM_SS)
+                    .withDescription("Time format");
+
+    // Not used yet. Reserved for future use to support custom date/time format strings.
+    Option<String> DATE_FORMAT_VALUE =
+            Options.key("date_format_value")
+                    .stringType()
+                    .noDefaultValue()
+                    .withDescription(
+                            "Date format string (e.g. 'yyyy-MM-dd'). "
+                                    + "Must match one of the predefined values in the Formatter enum.");
+
+    Option<String> DATETIME_FORMAT_VALUE =
+            Options.key("datetime_format_value")
+                    .stringType()
+                    .noDefaultValue()
+                    .withDescription(
+                            "Datetime format string (e.g. 'yyyy-MM-dd HH:mm:ss'). "
+                                    + "Must match one of the predefined values in the Formatter enum.");
+
+    // Not used yet. Reserved for future use to support custom date/time format strings.
+    Option<String> TIME_FORMAT_VALUE =

Review Comment:
   ditto



##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/options/table/FormatOptions.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.seatunnel.api.options.table;
+
+import org.apache.seatunnel.api.configuration.Option;
+import org.apache.seatunnel.api.configuration.Options;
+import org.apache.seatunnel.common.utils.DateTimeUtils;
+import org.apache.seatunnel.common.utils.DateUtils;
+import org.apache.seatunnel.common.utils.TimeUtils;
+
+public interface FormatOptions {
+    Option<DateUtils.Formatter> DATE_FORMAT =
+            Options.key("date_format")
+                    .enumType(DateUtils.Formatter.class)
+                    .defaultValue(DateUtils.Formatter.YYYY_MM_DD)
+                    .withDescription("Date format");
+
+    Option<DateTimeUtils.Formatter> DATETIME_FORMAT =
+            Options.key("datetime_format")
+                    .enumType(DateTimeUtils.Formatter.class)
+                    .defaultValue(DateTimeUtils.Formatter.YYYY_MM_DD_HH_MM_SS)
+                    .withDescription("Datetime format");
+
+    Option<TimeUtils.Formatter> TIME_FORMAT =
+            Options.key("time_format")
+                    .enumType(TimeUtils.Formatter.class)
+                    .defaultValue(TimeUtils.Formatter.HH_MM_SS)
+                    .withDescription("Time format");
+
+    // Not used yet. Reserved for future use to support custom date/time format strings.
+    Option<String> DATE_FORMAT_VALUE =

Review Comment:
   ```suggestion
       Option<String> DATE_FORMAT =
   ```



##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/util/FormatterContext.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.maxcompute.util;
+
+import org.apache.seatunnel.common.exception.CommonError;
+import org.apache.seatunnel.common.utils.DateTimeUtils;
+
+import java.time.LocalDateTime;
+
+public class FormatterContext {
+    private final DateTimeUtils.Formatter localDateTimeFormat;
+
+    public FormatterContext(DateTimeUtils.Formatter localDateTimeFormat) {
+        String format = localDateTimeFormat.getValue();
+        validateFormat(format);
+        this.localDateTimeFormat = localDateTimeFormat;
+    }
+
+    public FormatterContext(String localDateTimeFormat) {
+        validateFormat(localDateTimeFormat);
+        this.localDateTimeFormat = DateTimeUtils.Formatter.parse(localDateTimeFormat);
+    }
+
+    public boolean isDateTimeType(Object field) {
+        return field instanceof LocalDateTime;
+    }
+
+    public String formatDateTime(Object field) {
+        if (field instanceof LocalDateTime) {
+            return this.format(((LocalDateTime) field));
+        }
+        throw CommonError.illegalArgument(
+                field.getClass().getName(),
+                "Cannot format the given value: not a LocalDateTime instance.");
+    }
+
+    private void validateFormat(String localDateTimeFormat) {
+        if (localDateTimeFormat.contains("T")) {
+            throw CommonError.illegalArgument(
+                    localDateTimeFormat,
+                    "MaxCompute does not support datetime format containing 'T'.");
+        }
+    }

Review Comment:
   we should not validate the format. If user want the value contains `T`, keep it.



##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/options/table/FormatOptions.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.seatunnel.api.options.table;
+
+import org.apache.seatunnel.api.configuration.Option;
+import org.apache.seatunnel.api.configuration.Options;
+import org.apache.seatunnel.common.utils.DateTimeUtils;
+import org.apache.seatunnel.common.utils.DateUtils;
+import org.apache.seatunnel.common.utils.TimeUtils;
+
+public interface FormatOptions {
+    Option<DateUtils.Formatter> DATE_FORMAT =
+            Options.key("date_format")
+                    .enumType(DateUtils.Formatter.class)
+                    .defaultValue(DateUtils.Formatter.YYYY_MM_DD)
+                    .withDescription("Date format");
+
+    Option<DateTimeUtils.Formatter> DATETIME_FORMAT =
+            Options.key("datetime_format")
+                    .enumType(DateTimeUtils.Formatter.class)
+                    .defaultValue(DateTimeUtils.Formatter.YYYY_MM_DD_HH_MM_SS)
+                    .withDescription("Datetime format");
+
+    Option<TimeUtils.Formatter> TIME_FORMAT =
+            Options.key("time_format")
+                    .enumType(TimeUtils.Formatter.class)
+                    .defaultValue(TimeUtils.Formatter.HH_MM_SS)
+                    .withDescription("Time format");
+
+    // Not used yet. Reserved for future use to support custom date/time format strings.
+    Option<String> DATE_FORMAT_VALUE =
+            Options.key("date_format_value")
+                    .stringType()
+                    .noDefaultValue()
+                    .withDescription(
+                            "Date format string (e.g. 'yyyy-MM-dd'). "
+                                    + "Must match one of the predefined values in the Formatter enum.");
+
+    Option<String> DATETIME_FORMAT_VALUE =

Review Comment:
   ditto



##########
seatunnel-connectors-v2/connector-maxcompute/src/main/java/org/apache/seatunnel/connectors/seatunnel/maxcompute/sink/MaxcomputeWriter.java:
##########
@@ -66,6 +69,15 @@ public MaxcomputeWriter(ReadonlyConfig readonlyConfig, SeaTunnelRowType rowType)
                                 readonlyConfig.get(MaxcomputeSinkOptions.PROJECT),
                                 readonlyConfig.get(MaxcomputeSinkOptions.TABLE_NAME));
             }
+            if (readonlyConfig.getOptional(FormatOptions.DATETIME_FORMAT_VALUE).isPresent()) {
+                this.formatterContext =
+                        new FormatterContext(
+                                readonlyConfig.get(FormatOptions.DATETIME_FORMAT_VALUE));
+            } else {
+                this.formatterContext =
+                        new FormatterContext(readonlyConfig.get(FormatOptions.DATETIME_FORMAT));
+            }

Review Comment:
   we should introduce default format in here when `FormatOptions.DATETIME_FORMAT` is null



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234#discussion_r2104178121


##########
docs/en/connector-v2/sink/Maxcompute.md:
##########
@@ -112,6 +112,26 @@ Option introduction:
 
 When data_save_mode selects CUSTOM_PROCESSING, you should fill in the CUSTOM_SQL parameter. This parameter usually fills in a SQL that can be executed. SQL will be executed before synchronization tasks.
 
+### datetime_format_value[String]

Review Comment:
   ```suggestion
   ### datetime_format[String]
   ```



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improve][Connector-V2] Support maxcompute sink writer with timestamp field type [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X merged PR #9234:
URL: https://github.com/apache/seatunnel/pull/9234


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org