prestodb/presto · error · HiveException

HIVE_FUNCTION_IMPLEMENTATION_ERROR

HIVE_FUNCTION_IMPLEMENTATION_ERROR

Error message

Instantiating %s error

What it means

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.

Source

Thrown at presto-hive-function-namespace/src/main/java/com/facebook/presto/hive/functions/aggregation/HiveAggregationFunction.java:175

        return resolver.getEvaluator(info.getParameters());
    }

    @SuppressWarnings("deprecation")
    private static GenericUDAFResolver createGenericUDAFResolver(Class<?> cls)
            throws HiveException
    {
        try {
            if (GenericUDAFResolver.class.isAssignableFrom(cls)) {
                return ((GenericUDAFResolver) cls.getConstructor().newInstance());
            }
            else if (UDAF.class.isAssignableFrom(cls)) {
                Object udaf = cls.getConstructor().newInstance();
                verify(udaf instanceof UDAF);
                return new GenericUDAFBridge(((UDAF) udaf));
            }
        }
        catch (Exception e) {
            throw new HiveException(format("Instantiating %s error", cls), e);
        }
        throw unsupportedFunctionType(cls);
    }

    @Override
    public SqlFunctionVisibility getVisibility()
    {
        return null;
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. 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).
  2. Ensure the class implements GenericUDAFResolver2 or extends UDAF as the registry expects.
  3. Check Hive/Presto version compatibility of the UDAF jar and redeploy with a compatible build.
  4. Verify the function's class is registered correctly in StaticHiveFunctionRegistry and loadable via the configured classloader.

Example fix

// before
public class MyUdaf { private MyUdaf() {} } // cannot be instantiated reflectively
// after
public class MyUdaf extends UDAF {
    public MyUdaf() {}
    // ... Evaluator implementation
}
Defensive patterns

Strategy: try-catch

Validate before calling

try {
    Class<?> cls = classLoader.loadClass(className);
    Object o = cls.getConstructor().newInstance(); // fail early outside resolution path
} catch (Throwable t) {
    // report misconfigured/unsupported Hive UDAF before query execution
}

Type guard

static boolean isInstantiableUdaf(Class<?> cls) {
    try {
        return UDAF.class.isAssignableFrom(cls) && cls.getConstructor() != null;
    } catch (NoSuchMethodException e) {
        return false;
    }
}

Try / catch

try {
    resolver = aggregationFunction.createGenericUDAFResolver(cls);
} catch (HiveException e) {
    log.error("UDAF init failed for " + cls + ": " + e.getCause(), e.getCause());
    throw new PrestoException(FUNCTION_IMPLEMENTATION_ERROR, e.getCause());
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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