Myracle commented on code in PR #27483:
URL: https://github.com/apache/flink/pull/27483#discussion_r2957782217


##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/scalar/InetNtoaFunction.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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_NTOA}.
+ *
+ * <p>This function converts a numeric IPv4 address representation back to its 
string format.
+ *
+ * <p>The conversion extracts each octet from the numeric value using bit 
shifting and masking.
+ *
+ * <p>Note: This function only supports IPv4 addresses. IPv6 addresses are not 
supported.
+ *
+ * <p>Examples:
+ *
+ * <ul>
+ *   <li>INET_NTOA(2130706433) returns '127.0.0.1'
+ *   <li>INET_NTOA(167772161) returns '10.0.0.1'
+ *   <li>INET_NTOA(0) returns '0.0.0.0'
+ * </ul>
+ */
+@Internal
+public class InetNtoaFunction extends BuiltInScalarFunction {
+
+    public InetNtoaFunction(SpecializedFunction.SpecializedContext context) {
+        super(BuiltInFunctionDefinitions.INET_NTOA, context);
+    }
+
+    /**
+     * Converts a numeric IPv4 address representation (Long) to its string 
format.
+     *
+     * @param ipNumber the numeric representation of the IPv4 address
+     * @return the IPv4 address string in dotted-decimal notation, or null if 
input is null or out
+     *     of valid range
+     */
+    public @Nullable StringData eval(@Nullable Long ipNumber) {

Review Comment:
   Fully agree — there's no real need to support negative inputs as valid 
values. In our current implementation, all negative inputs uniformly return 
NULL, which is consistent with MySQL's INET_NTOA(-1) = NULL behavior.
   
   As you pointed out, the only scenario where negative values could arise is 
migrating from MySQL UNSIGNED INT columns, but since INET_ATON already returns 
BIGINT, users should store IP numbers in BIGINT columns from the start, 
avoiding the negative value issue entirely.
   
   So the current behavior is: we accept any integer type 
(TINYINT/SMALLINT/INT/BIGINT) as input, but negative values are treated as 
invalid and return NULL — no special unsigned conversion is performed. This 
keeps the semantics clean and MySQL-compatible.



-- 
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