yiyutian1 commented on code in PR #25763: URL: https://github.com/apache/flink/pull/25763#discussion_r1881754173
########## flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/scalar/ToTimestampLtzFunction.java: ########## @@ -0,0 +1,111 @@ +/* + * 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.TimestampData; +import org.apache.flink.table.functions.BuiltInFunctionDefinitions; +import org.apache.flink.table.functions.SpecializedFunction; +import org.apache.flink.util.FlinkRuntimeException; + +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; + +/** + * Implementation of {@link BuiltInFunctionDefinitions#TO_TIMESTAMP_LTZ}. + * + * Supported function signatures: + * TO_TIMESTAMP_LTZ(numeric, precision) -> TIMESTAMP_LTZ(3)</li> + * TO_TIMESTAMP_LTZ(string) -> TIMESTAMP_LTZ(3)</li> + * TO_TIMESTAMP_LTZ(string, format) -> TIMESTAMP_LTZ(3)</li> + * TO_TIMESTAMP_LTZ(string, format, timezone) -> TIMESTAMP_LTZ(3)</li> + * TO_TIMESTAMP_LTZ(numeric) -> TIMESTAMP_LTZ(3)</li> + */ +@Internal +public class ToTimestampLtzFunction extends BuiltInScalarFunction { + + private static final String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss"; + private static final ZoneId UTC = ZoneId.of("UTC"); + + public ToTimestampLtzFunction(SpecializedFunction.SpecializedContext context) { + super(BuiltInFunctionDefinitions.TO_TIMESTAMP_LTZ, context); + } + + public TimestampData eval(Integer epoch, Integer precision) { + if (epoch == null) { + return null; + } + if (precision == 0) { + return TimestampData.fromEpochMillis(epoch * 1000L); Review Comment: Use the built-in function that the existing TO_TIMESTAMP_LTZ function depends on, which takes care of the nanoseconds. -- 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