Myracle commented on code in PR #27483: URL: https://github.com/apache/flink/pull/27483#discussion_r2929778829
########## flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/scalar/InetAtonFunction.java: ########## @@ -0,0 +1,159 @@ +/* + * 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.StringData; +import org.apache.flink.table.functions.BuiltInFunctionDefinitions; +import org.apache.flink.table.functions.SpecializedFunction; + +import javax.annotation.Nullable; + +/** + * Implementation of {@link BuiltInFunctionDefinitions#INET_ATON}. + * + * <p>This function converts an IPv4 address string to its numeric representation. It follows the + * MySQL INET_ATON function behavior, including support for short-form IPv4 addresses. + * + * <p>The conversion formula for a standard IP address A.B.C.D is: A * 256^3 + B * 256^2 + C * 256 + + * D + * + * <p>MySQL-compatible short-form IPv4 addresses are supported: + * + * <ul> + * <li>a.b is interpreted as a.0.0.b + * <li>a.b.c is interpreted as a.b.0.c + * </ul> + * + * <p>Leading zeros in octets are parsed as decimal (consistent with MySQL), not octal. + * + * <p>Note: This function only supports IPv4 addresses. IPv6 addresses are not supported. + * + * <p><b>Implementation Note:</b> This implementation does not use utility classes such as {@code + * com.google.common.net.InetAddresses} or {@code sun.net.util.IPAddressUtil} because: + * + * <ul> + * <li>Guava's {@code InetAddresses.forString()} does not support MySQL-compatible short-form IP + * addresses (e.g., "127.1" interpreted as "127.0.0.1") + * <li>Standard IP parsers may interpret leading zeros as octal (e.g., "010" as 8), while MySQL + * treats them as decimal (e.g., "010" as 10) + * <li>{@code sun.net.util.IPAddressUtil} is a JDK internal API requiring {@code --add-exports}, + * which introduces JDK version compatibility issues + * </ul> Review Comment: Thanks for the suggestion! Agreed — the Implementation Note explaining why we don't use InetAddresses, IPAddressUtil, etc. is more of a design decision rationale than something future readers need in the Javadoc. I've moved it out of the codebase. I've removed the Implementation Note section from both InetAtonFunction.java and InetNtoaFunction.java (which had a similar note). The Javadoc now focuses purely on functional documentation — what the function does, the supported formats, and usage examples. -- 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]
