{"record":{"id":"8c377cfe4c453c6f","repo":"prestodb/presto","slug":"hive-function-implementation-error","errorCode":"HIVE_FUNCTION_IMPLEMENTATION_ERROR","errorMessage":"Instantiating %s error","messagePattern":"Instantiating (.+?) error","errorType":"error_code","errorClass":"HiveException","httpStatus":null,"severity":"error","filePath":"presto-hive-function-namespace/src/main/java/com/facebook/presto/hive/functions/aggregation/HiveAggregationFunction.java","lineNumber":175,"sourceCode":"        return resolver.getEvaluator(info.getParameters());\n    }\n\n    @SuppressWarnings(\"deprecation\")\n    private static GenericUDAFResolver createGenericUDAFResolver(Class<?> cls)\n            throws HiveException\n    {\n        try {\n            if (GenericUDAFResolver.class.isAssignableFrom(cls)) {\n                return ((GenericUDAFResolver) cls.getConstructor().newInstance());\n            }\n            else if (UDAF.class.isAssignableFrom(cls)) {\n                Object udaf = cls.getConstructor().newInstance();\n                verify(udaf instanceof UDAF);\n                return new GenericUDAFBridge(((UDAF) udaf));\n            }\n        }\n        catch (Exception e) {\n            throw new HiveException(format(\"Instantiating %s error\", cls), e);\n        }\n        throw unsupportedFunctionType(cls);\n    }\n\n    @Override\n    public SqlFunctionVisibility getVisibility()\n    {\n        return null;\n    }\n}\n","sourceCodeStart":157,"sourceCodeEnd":186,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive-function-namespace/src/main/java/com/facebook/presto/hive/functions/aggregation/HiveAggregationFunction.java#L157-L186","documentation":"HiveAggregationFunction.createGenericUDAFResolver instantiates the Hive aggregation's resolver class reflectively (newInstance) and wraps it (GenericUDAFBridge or GenericUDAFResolver2). Any failure during reflection, construction, instanceof checks, or wrapping is rethrown as a HiveException with code HIVE_FUNCTION_IMPLEMENTATION_ERROR, indicating the registered Hive UDAF class could not be instantiated or does not implement the expected interface.","triggerScenarios":"Resolving a Hive aggregation function whose class fails getConstructor().newInstance() (no public no-arg constructor, constructor throws, class not visible under the function classloader), or fails the UDAF/GenericUDAFResolver2 instanceof verification.","commonSituations":"Hive UDAF written with a private or parameterized constructor; class compiled against incompatible Hive versions so instantiation throws ExceptionInInitializerError/NoSuchMethodError; classloader misconfiguration so the class loads but misbehaves; non-aggregator class registered as a UDAF.","solutions":["Inspect the wrapped cause (getCause()) to see the actual reflection failure and fix the Hive UDAF class (add a public no-arg constructor, fix static initializers).","Ensure the class implements GenericUDAFResolver2 or extends UDAF as the registry expects.","Check Hive/Presto version compatibility of the UDAF jar and redeploy with a compatible build.","Verify the function's class is registered correctly in StaticHiveFunctionRegistry and loadable via the configured classloader."],"exampleFix":"// before\npublic class MyUdaf { private MyUdaf() {} } // cannot be instantiated reflectively\n// after\npublic class MyUdaf extends UDAF {\n    public MyUdaf() {}\n    // ... Evaluator implementation\n}","handlingStrategy":"try-catch","validationCode":"try {\n    Class<?> cls = classLoader.loadClass(className);\n    Object o = cls.getConstructor().newInstance(); // fail early outside resolution path\n} catch (Throwable t) {\n    // report misconfigured/unsupported Hive UDAF before query execution\n}","typeGuard":"static boolean isInstantiableUdaf(Class<?> cls) {\n    try {\n        return UDAF.class.isAssignableFrom(cls) && cls.getConstructor() != null;\n    } catch (NoSuchMethodException e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    resolver = aggregationFunction.createGenericUDAFResolver(cls);\n} catch (HiveException e) {\n    log.error(\"UDAF init failed for \" + cls + \": \" + e.getCause(), e.getCause());\n    throw new PrestoException(FUNCTION_IMPLEMENTATION_ERROR, e.getCause());\n}","preventionTips":["Give Hive UDAF classes a public no-arg constructor.","Ensure the class implements GenericUDAFResolver2 or extends UDAF.","Test-load all registered Hive aggregation classes at plugin startup.","Keep Hive dependencies version-compatible with the Presto hive plugin."],"tags":["hive","udaf","reflection","function-implementation"],"backgroundTag":"function-implementation-error","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"}