prestodb/presto · warning · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

Invalid QuadKey digit sequence: 

What it means

BingTile.fromQuadKey parses a QuadKey string digit-by-digit, where each digit must be one of '0'-'3'. Any other character hits the default branch and throws INVALID_FUNCTION_ARGUMENT, meaning the input is not a valid Bing Maps quadkey for the bing_tile_quadkey/geometry functions.

Source

Thrown at presto-geospatial-toolkit/src/main/java/com/facebook/presto/geospatial/BingTile.java:118

        int tileX = 0;
        int tileY = 0;
        for (int i = zoomLevel; i > 0; i--) {
            int mask = 1 << (i - 1);
            switch (quadKey.charAt(zoomLevel - i)) {
                case '0':
                    break;
                case '1':
                    tileX |= mask;
                    break;
                case '2':
                    tileY |= mask;
                    break;
                case '3':
                    tileX |= mask;
                    tileY |= mask;
                    break;
                default:
                    throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid QuadKey digit sequence: " + quadKey);
            }
        }

        return new BingTile(tileX, tileY, zoomLevel);
    }

    @JsonProperty
    public int getX()
    {
        return x;
    }

    @JsonProperty
    public int getY()
    {
        return y;
    }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Ensure the quadkey contains only characters 0-3 and its length equals the zoom level (1-23).
  2. Use bing_tile(zoom, x, y) or bing_tile_at(lat, lon, zoom) to construct tiles instead of hand-built quadkeys.
  3. Validate input data upstream before invoking the function.

Example fix

// before
SELECT bing_tile_quadkey('01234abc'); -- invalid digits
// after
SELECT bing_tile_quadkey('0123'); -- only 0-3 digits
Defensive patterns

Strategy: validation

Validate before calling

boolean isValidQuadKey(String q) {
    return q != null && !q.isEmpty() && q.length() <= 23
        && q.chars().allMatch(c -> c >= '0' && c <= '3');
}

Type guard

boolean isQuadKey(String s) {
    return s != null && s.matches("[0-3]{1,23}");
}

Try / catch

try {
    BingTile tile = BingTile.fromQuadKey(quadKey);
} catch (PrestoException e) {
    if (e.getErrorCode().equals(INVALID_FUNCTION_ARGUMENT.toErrorCode())) {
        // sanitize or reject the quadKey input
    }
}

Prevention

When it happens

Trigger: Calling a geospatial SQL function with a quadkey containing characters outside '0','1','2','3' (e.g. '024', 'abc', empty or whitespace-containing strings passing validation).

Common situations: Copy-pasting identifiers that look like quadkeys but are base-10 tile ids or hex strings; typos like 'o' vs '0'; passing latitude/longitude strings instead of quadkeys.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/0c6f6e8125c990a6. Report an issue: GitHub.