prestodb/presto · error · PrestoException
INVALID_CAST_ARGUMENT
INVALID_CAST_ARGUMENT
Error message
Cannot cast value to IPPREFIX:
What it means
Cast error in castFromVarcharToIpPrefix: the input text is not a valid IPPREFIX literal — either it lacks the required '/' subnet suffix, or the address/subnet portion failed parsing. The original string is appended; the faulty input is the varchar being cast to IPPREFIX.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/type/IpPrefixOperators.java:140
}
@ScalarOperator(XX_HASH_64)
@SqlType(StandardTypes.BIGINT)
public static long xxHash64(@SqlType(StandardTypes.IPPREFIX) Slice value)
{
return XxHash64.hash(value);
}
@LiteralParameters("x")
@ScalarOperator(CAST)
@SqlType(StandardTypes.IPPREFIX)
public static Slice castFromVarcharToIpPrefix(@SqlType("varchar(x)") Slice slice)
{
byte[] address;
int subnetSize;
String string = slice.toStringUtf8();
if (!string.contains("/")) {
throw new PrestoException(INVALID_CAST_ARGUMENT, "Cannot cast value to IPPREFIX: " + slice.toStringUtf8());
}
String[] parts = string.split("/");
try {
address = InetAddresses.forString(parts[0]).getAddress();
}
catch (IllegalArgumentException e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, "Cannot cast value to IPPREFIX: " + slice.toStringUtf8());
}
subnetSize = Integer.parseInt(parts[1]);
byte[] bytes = new byte[IPPREFIX.getFixedSize()];
if (address.length == 4) {
if (subnetSize < 0 || 32 < subnetSize) {
throw new PrestoException(INVALID_CAST_ARGUMENT, "Cannot cast value to IPPREFIX: " + slice.toStringUtf8());
}
for (int i = 0; i < 4; i++) {
address[3 - i] &= -0x1 << min(max((32 - subnetSize) - 8 * i, 0), 8);View on GitHub (pinned to 55bb57d202)
Solutions
- Use CIDR notation like '10.0.0.0/8' or '2001:db8::/32'
- Ensure the subnet prefix length is within range for the address family
- Validate the string format before casting
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at presto-main-base/src/main/java/com/facebook/presto/type/IpPrefixOperators.java:140 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/cb41040e5a0502c3.
Report an issue: GitHub.