prestodb/presto · error · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

input types for khyperloglog_agg are not supported

What it means

KHyperLogLogWithLimitAggregationFunction.selects its input MethodHandle based on the Java types of the first and second input arguments. Only a fixed set of (javaType, Slice) combinations is supported (e.g. long, double, boolean with Slice, or Slice/Slice). When the SQL engine binds khyperloglog_agg with an argument type outside this whitelist, this PrestoException with INVALID_FUNCTION_ARGUMENT is thrown at function- resolution/binding time.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/type/khyperloglog/KHyperLogLogWithLimitAggregationFunction.java:137

            inputFunction = LONG_LONG_INPUT_FUNCTION;
        }
        else if (firstInputType.getJavaType() == Slice.class && secondInputType.getJavaType() == long.class) {
            inputFunction = SLICE_LONG_INPUT_FUNCTION;
        }
        else if (firstInputType.getJavaType() == double.class && secondInputType.getJavaType() == long.class) {
            inputFunction = DOUBLE_LONG_INPUT_FUNCTION;
        }
        else if (firstInputType.getJavaType() == long.class && secondInputType.getJavaType() == Slice.class) {
            inputFunction = LONG_SLICE_INPUT_FUNCTION;
        }
        else if (firstInputType.getJavaType() == Slice.class && secondInputType.getJavaType() == Slice.class) {
            inputFunction = SLICE_SLICE_INPUT_FUNCTION;
        }
        else if (firstInputType.getJavaType() == double.class && secondInputType.getJavaType() == Slice.class) {
            inputFunction = DOUBLE_SLICE_INPUT_FUNCTION;
        }
        else {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "input types for khyperloglog_agg are not supported");
        }
        return inputFunction;
    }

    @Override
    public String getDescription()
    {
        return "Returns the KHyperLogLog sketch that represents the relationship between columns x and y. The MinHash structure summarizes x and the HyperLogLog sketches represent y values linked to x values.";
    }

    public static void input(KHyperLogLogState state, long value, long uii)
    {
        if (state.getKHLL() == null) {
            state.setKHLL(new KHyperLogLog());
        }
        state.getKHLL().add(value, uii);
    }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Cast the first argument to a supported scalar type, e.g. CAST(col AS VARCHAR) or CAST(col AS BIGINT) before passing to khyperloglog_agg
  2. If the input is a complex type, pre-aggregate it into a scalar key (or hash it, e.g. checksum/xxhash64) and aggregate the scalar
  3. Verify the column type with DESCRIBE / typeof() and use the correct aggregate for that type
  4. Upgrade Presto if you believe the type should be supported — newer versions may have extended the whitelist

Example fix

-- before
SELECT khyperloglog_agg(tags, 128) FROM events; -- tags is ARRAY(VARCHAR)
-- after
SELECT khyperloglog_agg(CAST(tags AS VARCHAR), 128) FROM events;
Defensive patterns

Strategy: validation

Validate before calling

SELECT typeof(col) FROM t LIMIT 0; -- must be bigint/double/boolean/varchar-like before calling khyperloglog_agg

Type guard

boolean isKhhllCompatible(Type t) { Class<?> j = t.getJavaType(); return j == long.class || j == double.class || j == boolean.class || j == com.facebook.presto.spi.block.Block.class && false || j == io.airlift.slice.Slice.class; }

Prevention

When it happens

Trigger: Calling khyperloglog_agg with a first argument whose native Java type is not one of the supported types (long/double/boolean/Slice) — e.g. passing a complex type such as an ARRAY, MAP, ROW, or khyperloglog itself — combined with a Slice second argument (the limit).

Common situations: Wrapping khyperloglog_agg around a non-numeric/non-slice column (JSON, array, map columns); schema drift where a column changed from bigint to a struct/complex type; accidentally nesting aggregations like khyperloglog_agg(khyperloglog_agg(...)).

Related errors


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