[SPARK-57926][SQL] Add IPv4 address functions: inet_aton, inet_ntoa, try_inet_aton#57328
Open
jiangxt2 wants to merge 1 commit into
Open
[SPARK-57926][SQL] Add IPv4 address functions: inet_aton, inet_ntoa, try_inet_aton#57328jiangxt2 wants to merge 1 commit into
jiangxt2 wants to merge 1 commit into
Conversation
…try_inet_aton Add three built-in SQL functions for IPv4 address manipulation: - inet_aton(STRING) -> LONG: convert IPv4 string to 32-bit integer - inet_ntoa(LONG) -> STRING: convert 32-bit integer to IPv4 string - try_inet_aton(STRING) -> LONG: same as inet_aton but returns null on invalid input regardless of ANSI mode The implementation uses pure integer arithmetic (no java.net.InetAddress) with whole-stage codegen support. Short-form IP addresses (1-3 segments) are supported per Flink convention; leading zeros are parsed as decimal, matching MySQL/Flink behavior. Signed-off-by: jiangxt2 <jiangxt2@vip.qq.com>
jiangxt2
force-pushed
the
feat/ipv4-functions
branch
from
July 17, 2026 10:36
cba34fe to
a380a48
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Spark SQL has no built-in functions for IPv4 address manipulation, requiring
UDFs for common network log analysis tasks.
What changes were proposed in this pull request?
Add three built-in SQL functions for IPv4 address manipulation:
inet_aton(str): converts an IPv4 address string to a 32-bitinteger. Returns null on invalid input in non-ANSI mode, throws
INVALID_IPV4_ADDRESSin ANSI mode.inet_ntoa(value): converts a 32-bit integer to an IPv4 addressstring in dotted-decimal notation. Returns null if the value is out
of range in non-ANSI mode, throws
INVALID_IPV4_LONGin ANSI mode.try_inet_aton(str): same asinet_atonbut returns null oninvalid input regardless of ANSI mode, using the standard
RuntimeReplaceable+InheritAnalysisRulespattern.Short-form IP addresses (1-3 dot-separated segments) are supported per
Flink convention. Leading zeros are parsed as decimal (e.g.
'010.000.000.001'->167772161), matching MySQL and Flink, notoctal like POSIX
inet_aton(3).The implementation uses pure integer arithmetic via
Ipv4Utils(nojava.net.InetAddress), with whole-stage codegen support.Why are the changes needed?
Spark has no built-in IP address functions, while MySQL, ClickHouse,
Doris, Databend, VoltDB, and SingleStore all provide equivalents.
Common use cases include network log analysis (range queries on IP
prefixes), security audit, and IP geolocation, all of which currently
require UDFs.
Does this PR introduce any user-facing change?
Yes. Three new SQL functions:
inet_aton,inet_ntoa,try_inet_aton,with corresponding Scala/Python DataFrame APIs. Two new error classes:
INVALID_IPV4_ADDRESS,INVALID_IPV4_LONG.How was this patch tested?
IpExpressionsSuite: 22 test cases (valid/invalid inputs, shortforms, leading zeros, ANSI mode, round-trip, type mismatch, both
interpreted and codegen paths)
ipv4-functions.sqlWas this patch authored or co-authored using generative AI tooling?
Generative AI tooling (Claude Code) was used as an assistive tool for
implementation guidance and code review.