yiyutian1 commented on code in PR #25763:
URL: https://github.com/apache/flink/pull/25763#discussion_r1889875236


##########
docs/data/sql_functions.yml:
##########
@@ -679,9 +679,15 @@ temporal:
   - sql: TO_DATE(string1[, string2])
     table: toDate(STRING1[, STRING2])
     description: Converts a date string string1 with format string2 (by 
default 'yyyy-MM-dd') to a date.
-  - sql: TO_TIMESTAMP_LTZ(numeric, precision)
+  - sql: TO_TIMESTAMP_LTZ(numeric[, precision])
     table: toTimestampLtz(NUMERIC, PRECISION)
-    description: "Converts a epoch seconds or epoch milliseconds to a 
TIMESTAMP_LTZ, the valid precision is 0 or 3, the 0 represents 
TO_TIMESTAMP_LTZ(epochSeconds, 0), the 3 represents 
TO_TIMESTAMP_LTZ(epochMilliseconds, 3)."
+    description: Converts an epoch seconds or epoch milliseconds to a 
TIMESTAMP_LTZ, the valid precision is 0 or 3, the 0 represents 
TO_TIMESTAMP_LTZ(epochSeconds, 0), the 3 represents 
TO_TIMESTAMP_LTZ(epochMilliseconds, 3). If no precision is provided, the 
default precision is 3.
+  - sql: TO_TIMESTAMP_LTZ(string1[, string2])
+    table: toTimestampLtz(STRING1[, STRING2])
+    description: Converts a timestamp string string1 with format string2 (by 
default 'yyyy-MM-dd HH:mm:ss.SSS') to a TIMESTAMP_LTZ.
+  - sql: TO_TIMESTAMP_LTZ(string1, string2, string3)
+    table: toTimestampLtz(STRING1, STRING2, STRING3)
+    description: Converts a timestamp string string1 with format string2 to a 
TIMESTAMP_LTZ in time zone string3.

Review Comment:
   Modified. 



##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/scalar/ToTimestampLtzFunction.java:
##########
@@ -0,0 +1,192 @@
+/*
+ * 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.flink.table.runtime.functions.scalar;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.data.DecimalData;
+import org.apache.flink.table.data.StringData;
+import org.apache.flink.table.data.TimestampData;
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions;
+import org.apache.flink.table.functions.SpecializedFunction;
+import org.apache.flink.table.utils.DateTimeUtils;
+
+import javax.annotation.Nullable;
+
+/**
+ * Implementation of {@link BuiltInFunctionDefinitions#TO_TIMESTAMP_LTZ}.
+ *
+ * <p>A function that converts various time formats to TIMESTAMP_LTZ type.
+ *
+ * <p>Supported function signatures:
+ *
+ * <ul>
+ *   <li>{@code TO_TIMESTAMP_LTZ(numeric)} -> TIMESTAMP_LTZ(3) <br>
+ *       Converts numeric epoch time in milliseconds to timestamp with local 
timezone
+ *   <li>{@code TO_TIMESTAMP_LTZ(numeric, precision)} -> 
TIMESTAMP_LTZ(precision) <br>
+ *       Converts numeric epoch time to timestamp with specified precision (0 
as seconds, 3 as
+ *       milliseconds)
+ *   <li>{@code TO_TIMESTAMP_LTZ(timestamp)} -> TIMESTAMP_LTZ(3) <br>
+ *       Parses string timestamp using default format 'yyyy-MM-dd HH:mm:ss'
+ *   <li>{@code TO_TIMESTAMP_LTZ(timestamp, format)} -> TIMESTAMP_LTZ(3) <br>
+ *       Parses string timestamp using input string of format
+ *   <li>{@code TO_TIMESTAMP_LTZ(timestamp, format, timezone)} -> 
TIMESTAMP_LTZ(3) <br>
+ *       Parses string timestamp using input strings of format and timezone
+ * </ul>
+ *
+ * <p>Example:
+ *
+ * <pre>{@code
+ * TO_TIMESTAMP_LTZ('2023-01-01 10:00:00')}  // Parses string using default 
format
+ * TO_TIMESTAMP_LTZ(1234567890123)}  // Converts epoch milliseconds
+ * TO_TIMESTAMP_LTZ(1234567890, 0)     // Converts epoch seconds
+ * TO_TIMESTAMP_LTZ(1234567890123, 3)  // Converts epoch milliseconds
+ * TO_TIMESTAMP_LTZ('2023-01-01 10:00:00')  // Parses string using default 
format
+ * TO_TIMESTAMP_LTZ('2023-01-01T10:00:00', 'yyyy-MM-dd\'T\'HH:mm:ss')} // 
Parses string using input format
+ * TO_TIMESTAMP_LTZ('2023-01-01 10:00:00', 'yyyy-MM-dd HH:mm:ss', 'UTC')} // 
Parses string using input format and timezone
+ * }</pre>
+ */
+@Internal
+public class ToTimestampLtzFunction extends BuiltInScalarFunction {
+
+    private static final int DEFAULT_PRECISION = 3;
+
+    public ToTimestampLtzFunction(SpecializedFunction.SpecializedContext 
context) {
+        super(BuiltInFunctionDefinitions.TO_TIMESTAMP_LTZ, context);
+    }
+
+    public @Nullable TimestampData eval(Integer epoch, Integer precision) {
+        if (epoch == null || precision == null) {
+            return null;
+        }
+
+        return DateTimeUtils.toTimestampData(epoch, precision);
+    }
+
+    public @Nullable TimestampData eval(Long epoch, Integer precision) {
+        if (epoch == null || precision == null) {
+            return null;
+        }
+
+        return DateTimeUtils.toTimestampData(epoch, precision);
+    }
+
+    public @Nullable TimestampData eval(Double epoch, Integer precision) {
+        if (epoch == null || precision == null) {
+            return null;
+        }
+
+        return DateTimeUtils.toTimestampData(epoch, precision);
+    }
+
+    public @Nullable TimestampData eval(Float value, Integer precision) {
+        if (value == null || precision == null) {
+            return null;
+        }
+        return DateTimeUtils.toTimestampData(value.doubleValue(), precision);
+    }
+
+    public @Nullable TimestampData eval(Byte value, Integer precision) {
+        if (value == null || precision == null) {
+            return null;
+        }
+        return DateTimeUtils.toTimestampData(value.longValue(), precision);
+    }
+

Review Comment:
   Modified. 



-- 
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: issues-unsubscr...@flink.apache.org

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

Reply via email to