Myracle commented on code in PR #27483:
URL: https://github.com/apache/flink/pull/27483#discussion_r2929862940
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/functions/BuiltInFunctionDefinitions.java:
##########
@@ -463,6 +463,43 @@ ANY, and(logical(LogicalTypeRoot.BOOLEAN), LITERAL)
"org.apache.flink.table.runtime.functions.scalar.UrlEncodeFunction")
.build();
+ /**
+ * Converts an IPv4 address string to its numeric representation. Follows
MySQL INET_ATON
+ * behavior.
+ *
+ * <p>Supports MySQL-compatible short-form addresses (a.b, a.b.c) and
treats leading zeros as
+ * decimal.
+ *
+ * <p>Example: INET_ATON('127.0.0.1') returns 2130706433;
INET_ATON('127.1') returns 2130706433
+ */
+ public static final BuiltInFunctionDefinition INET_ATON =
+ BuiltInFunctionDefinition.newBuilder()
+ .name("INET_ATON")
+ .kind(SCALAR)
+
.inputTypeStrategy(sequence(logical(LogicalTypeFamily.CHARACTER_STRING)))
+ .outputTypeStrategy(explicit(BIGINT().nullable()))
+ .runtimeClass(
+
"org.apache.flink.table.runtime.functions.scalar.InetAtonFunction")
+ .build();
+
+ /**
+ * Converts a numeric IPv4 address representation back to its string
format. Follows MySQL
+ * INET_NTOA behavior.
+ *
+ * <p>Accepts BIGINT or INT input. Input must be in valid range [0,
4294967295].
+ *
+ * <p>Example: INET_NTOA(2130706433) returns '127.0.0.1'
+ */
+ public static final BuiltInFunctionDefinition INET_NTOA =
+ BuiltInFunctionDefinition.newBuilder()
+ .name("INET_NTOA")
+ .kind(SCALAR)
+
.inputTypeStrategy(sequence(logical(LogicalTypeFamily.INTEGER_NUMERIC)))
Review Comment:
Thanks for pointing this out!
Great catch — since INET_NTOA accepts
logical(LogicalTypeFamily.INTEGER_NUMERIC), it should handle all integer types
in that family, including SMALLINT and TINYINT. However, Flink's
FamilyArgumentTypeStrategy does not implicitly cast types within the same
family, so SMALLINT (→ Short) and TINYINT (→ Byte) inputs would actually fail
at runtime without explicit eval overloads.
I've made the following changes:
Added eval(Short) and eval(Byte) overloads to InetNtoaFunction.java — these
treat the values as unsigned (via Short.toUnsignedLong() /
Byte.toUnsignedLong()) before delegating to longToIp().
Added inetNtoaSmallintInputTestCases() — tests SMALLINT inputs including
(short) 256 → "0.0.1.0", (short) 0 → "0.0.0.0", (short) -1 → "0.0.255.255"
(unsigned), and null handling.
Added inetNtoaTinyintInputTestCases() — tests TINYINT inputs including
(byte) 127 → "0.0.0.127", (byte) -1 → "0.0.0.255" (unsigned), and null handling.
Please take another look when you get a chance.
--
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]