prestodb/presto · error · PrestoException

INVALID_CAST_ARGUMENT

INVALID_CAST_ARGUMENT

Error message

Cannot cast value to IPADDRESS: 

What it means

Cast error in castFromVarcharToIpAddress: Guava's InetAddresses.forString rejected the input text as not a valid IP literal (bad formatting or unexpected components). The original text is appended; the faulty input is the varchar being cast to IPADDRESS.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/type/IpAddressOperators.java:133

    @ScalarOperator(XX_HASH_64)
    @SqlType(StandardTypes.BIGINT)
    public static long xxHash64(@SqlType(StandardTypes.IPADDRESS) Slice value)
    {
        return XxHash64.hash(value);
    }

    @LiteralParameters("x")
    @ScalarOperator(CAST)
    @SqlType(StandardTypes.IPADDRESS)
    public static Slice castFromVarcharToIpAddress(@SqlType("varchar(x)") Slice slice)
    {
        byte[] address;
        try {
            address = InetAddresses.forString(slice.toStringUtf8()).getAddress();
        }
        catch (IllegalArgumentException e) {
            throw new PrestoException(INVALID_CAST_ARGUMENT, "Cannot cast value to IPADDRESS: " + slice.toStringUtf8());
        }

        byte[] bytes;
        if (address.length == 4) {
            bytes = new byte[16];
            bytes[10] = (byte) 0xff;
            bytes[11] = (byte) 0xff;
            arraycopy(address, 0, bytes, 12, 4);
        }
        else if (address.length == 16) {
            bytes = address;
        }
        else {
            throw new PrestoException(GENERIC_INTERNAL_ERROR, "Invalid InetAddress length: " + address.length);
        }

        return wrappedBuffer(bytes);
    }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Use canonical IPv4 or IPv6 literals, e.g. '10.0.0.1' or '::1'
  2. Trim whitespace and remove port/suffix notation before casting
  3. Validate candidate values with a regexp before the cast
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at presto-main-base/src/main/java/com/facebook/presto/type/IpAddressOperators.java:133 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/a86538a4ac30bb86. Report an issue: GitHub.