apache/cassandra · error · InvalidRequestException

Function ' ' exists but hasn't been loaded successfully for…

Error message

Function '%s' exists but hasn't been loaded successfully for the following reason: %s. Please see the server log for details

What it means

When a user-defined function (UDF) failed to load (e.g. its Java/JavaScript class could not be compiled, the declared body was invalid, or a dependency was missing), Cassandra creates a broken placeholder UDFunction whose aggregate execution path (executeAggregateUserDefined) unconditionally throws broken() — an InvalidRequestException stating the function exists but wasn't loaded, with the original reason embedded.

Solutions

  1. Read the server log for the original load failure reason cited in the message
  2. Fix and re-create the function: DROP FUNCTION then CREATE FUNCTION with corrected code
  3. Ensure all nodes run a JDK compatible with the UDF's language and that cassandra.yaml allows UDFs (enable_user_defined_functions: true)
  4. Check that the body only uses sandbox-permitted APIs and compiles for the cluster's Java version

Example fix

// before: body fails to compile/load on JDK 17
CREATE FUNCTION f(x int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return x.intValue().longValue();';
// after
datastax session.execute("CREATE OR REPLACE FUNCTION f(x int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return Long.valueOf(x.longValue());'");
Defensive patterns

Strategy: try-catch

Validate before calling

// verify the UDF loaded before use
const rows = await session.execute("SELECT function_name FROM system_schema.functions WHERE keyspace_name='ks' AND function_name='f'");
if (rows.rows.length === 0) throw new Error('UDF f missing');

Try / catch

try {
  await session.execute("SELECT f(x) FROM ks.t");
} catch (e) {
  if (/hasn't been loaded successfully/.test(e.message)) {
    console.error('UDF broken, check server log; re-create function', e.message);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling an aggregate UDF (created via CREATE FUNCTION ... RETURNS NULL ON NULL INPUT with an aggregate/ finalfunc pattern, or applied via aggregate execution paths like SELECT myudf(col) in aggregation) whose runtime class never compiled/loaded after CREATE FUNCTION or after node restart/reload.

Common situations: Java runtime version changed after UDF creation (Java 8 code failing on Java 11/17 nodes); sandbox-restricted APIs used in the function body; malformed script body; a schema-restore where the UDF code fails on new nodes.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/709badec40019d66. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/functions/UDFunction.java:300

                                                  List<ColumnIdentifier> argNames,
                                                  List<AbstractType<?>> argTypes,
                                                  AbstractType<?> returnType,
                                                  boolean calledOnNullInput,
                                                  String language,
                                                  String body,
                                                  InvalidRequestException reason)
    {
        return new UDFunction(name, argNames, argTypes, returnType, calledOnNullInput, language, body)
        {
            protected ExecutorService executor()
            {
                return ImmediateExecutor.INSTANCE;
            }

            @Override
            protected Object executeAggregateUserDefined(Object firstParam, Arguments arguments)
            {
                throw broken();
            }

            @Override
            public ByteBuffer executeUserDefined(Arguments arguments)
            {
                throw broken();
            }

            private InvalidRequestException broken()
            {
                return new InvalidRequestException(String.format("Function '%s' exists but hasn't been loaded successfully "
                                                                 + "for the following reason: %s. Please see the server log for details",
                                                                 this,
                                                                 reason.getMessage()));
            }
        };
    }

View on GitHub (pinned to 88fd0f6a0e)