prestodb/presto · error · PrestoException
INVALID_FUNCTION_ARGUMENT
INVALID_FUNCTION_ARGUMENT
Error message
ip_prefix_collapse does not support null elements
What it means
ip_prefix_collapse(array(IPPREFIX)) sorts its input and then checks whether the first or last element (after sorting) is null; since a null anywhere in the sorted array ends up at an end, any null element causes an INVALID_FUNCTION_ARGUMENT error. The function refuses to collapse arrays containing nulls.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/IpPrefixFunctions.java:234
public static Block collapseIpPrefixes(@SqlType("array(IPPREFIX)") Block unsortedIpPrefixArray)
{
int inputPrefixCount = unsortedIpPrefixArray.getPositionCount();
// If we get an empty array or an array non-null single element, just return the original array.
if (inputPrefixCount == 0 || (inputPrefixCount == 1 && !unsortedIpPrefixArray.isNull(0))) {
return unsortedIpPrefixArray;
}
// Sort prefixes. lessThanFunction is never used. NULLs are placed at the end.
// Prefixes are ordered by first IP and then prefix length.
// Example:
// Input: 10.0.0.0/8, 9.255.255.0/24, 10.0.0.0/7, 10.1.0.0/24, 10.10.0.0/16
// Output: 9.255.255.0/24, 10.0.0.0/7, 10.0.0.0/8, 10.1.0.0/24, 10.10.0.0/16
Block ipPrefixArray = sort(null, IPPREFIX, unsortedIpPrefixArray);
// throw if anything is null
if (ipPrefixArray.isNull(0) || ipPrefixArray.isNull(inputPrefixCount - 1)) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "ip_prefix_collapse does not support null elements");
}
// check the first and last prefixes in the array to make sure their IP versions match.
Slice firstIpPrefix = IPPREFIX.getSlice(ipPrefixArray, 0);
boolean v4 = isIpv4(firstIpPrefix);
Slice lastIpPrefix = IPPREFIX.getSlice(ipPrefixArray, inputPrefixCount - 1);
if (isIpv4(lastIpPrefix) != v4) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "All IPPREFIX elements must be the same IP version.");
}
List<List<Slice>> outputIpPrefixes = new ArrayList<>();
int outputPrefixCount = 0;
int ipMaxBitLength = v4 ? 32 : 128;
List<BigInteger[]> mergedIpRanges = mergeIpRanges(ipPrefixArray);
for (BigInteger[] ipRange : mergedIpRanges) {
List<Slice> ipPrefixes = generateMinIpPrefixes(ipRange[0], ipRange[1], ipMaxBitLength);
outputIpPrefixes.add(ipPrefixes);View on GitHub (pinned to 55bb57d202)
Solutions
- Filter out nulls before collapsing: ip_prefix_collapse(array_remove(prefixes, NULL)) or a FILTER clause.
- Replace nulls with a default prefix if semantically acceptable.
- Fix upstream data so the prefix array is fully populated.
Example fix
// before SELECT ip_prefix_collapse(prefixes) // after SELECT ip_prefix_collapse(ARRAY_REMOVE(prefixes, NULL))
Defensive patterns
Strategy: validation
Validate before calling
-- strip nulls before collapsing SELECT ip_prefix_collapse(ARRAY_REMOVE(prefixes, NULL)) FROM t;
Prevention
- Apply array_remove(x, NULL) or FILTER ... WHERE p IS NOT NULL before ip_prefix_collapse
- Enforce NOT NULL on IPPREFIX columns used for collapsing
- Check COALESCE on upstream joins that can introduce nulls
When it happens
Trigger: Calling ip_prefix_collapse(array) where the array contains at least one NULL IPPREFIX element.
Common situations: Aggregating prefix lists from partially populated columns; joins or array constructors that introduce NULLs; ETL output with missing prefixes.
Related errors
- INVALID_FUNCTION_ARGUMENT
- INVALID_FUNCTION_ARGUMENT
- INVALID_TABLE_PROPERTY
- Invalid time from server:
- Expected column to be a time type but is
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/f9ecb4c7b3881502.
Report an issue: GitHub.