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: [email protected]

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

Reply via email to