{"record":{"id":"1d2f21028634a3b6","repo":"prestodb/presto","slug":"invalid-function-argument-1d2f21","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"input types for khyperloglog_agg are not supported","messagePattern":"input types for khyperloglog_agg are not supported","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/type/khyperloglog/KHyperLogLogWithLimitAggregationFunction.java","lineNumber":137,"sourceCode":"            inputFunction = LONG_LONG_INPUT_FUNCTION;\n        }\n        else if (firstInputType.getJavaType() == Slice.class && secondInputType.getJavaType() == long.class) {\n            inputFunction = SLICE_LONG_INPUT_FUNCTION;\n        }\n        else if (firstInputType.getJavaType() == double.class && secondInputType.getJavaType() == long.class) {\n            inputFunction = DOUBLE_LONG_INPUT_FUNCTION;\n        }\n        else if (firstInputType.getJavaType() == long.class && secondInputType.getJavaType() == Slice.class) {\n            inputFunction = LONG_SLICE_INPUT_FUNCTION;\n        }\n        else if (firstInputType.getJavaType() == Slice.class && secondInputType.getJavaType() == Slice.class) {\n            inputFunction = SLICE_SLICE_INPUT_FUNCTION;\n        }\n        else if (firstInputType.getJavaType() == double.class && secondInputType.getJavaType() == Slice.class) {\n            inputFunction = DOUBLE_SLICE_INPUT_FUNCTION;\n        }\n        else {\n            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"input types for khyperloglog_agg are not supported\");\n        }\n        return inputFunction;\n    }\n\n    @Override\n    public String getDescription()\n    {\n        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.\";\n    }\n\n    public static void input(KHyperLogLogState state, long value, long uii)\n    {\n        if (state.getKHLL() == null) {\n            state.setKHLL(new KHyperLogLog());\n        }\n        state.getKHLL().add(value, uii);\n    }\n","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/type/khyperloglog/KHyperLogLogWithLimitAggregationFunction.java#L119-L155","documentation":"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.","triggerScenarios":"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).","commonSituations":"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(...)).","solutions":["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","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","Verify the column type with DESCRIBE / typeof() and use the correct aggregate for that type","Upgrade Presto if you believe the type should be supported — newer versions may have extended the whitelist"],"exampleFix":"-- before\nSELECT khyperloglog_agg(tags, 128) FROM events; -- tags is ARRAY(VARCHAR)\n-- after\nSELECT khyperloglog_agg(CAST(tags AS VARCHAR), 128) FROM events;","handlingStrategy":"validation","validationCode":"SELECT typeof(col) FROM t LIMIT 0; -- must be bigint/double/boolean/varchar-like before calling khyperloglog_agg","typeGuard":"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; }","tryCatchPattern":null,"preventionTips":["Always check typeof() of the first argument before using khyperloglog_agg","Cast complex types to scalars (VARCHAR/BIGINT) before aggregating","Never nest khyperloglog_agg inside itself"],"tags":["presto","aggregation","function-argument","khyperloglog"],"backgroundTag":"invalid-function-arguments","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}