apache/flink · error · UnsupportedOperationException

The key is only defined for keyed operator

Error message

The key is only defined for keyed operator

What it means

Error "The key is only defined for keyed operator" thrown in apache/flink.

Source

Thrown at flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/TwoInputBroadcastProcessOperator.java:206

                false,
                null,
                output,
                watermarkDeclarationMap);
    }

    @Override
    public void endInput(int inputId) throws Exception {
        // sanity check.
        checkState(inputId >= 1 && inputId <= 2);
        if (inputId == 1) {
            userFunction.endNonBroadcastInput(nonPartitionedContext);
        } else {
            userFunction.endBroadcastInput(nonPartitionedContext);
        }
    }

    protected Object currentKey() {
        throw new UnsupportedOperationException("The key is only defined for keyed operator");
    }

    protected BiConsumer<Runnable, Object> getProcessorWithKey() {
        if (isAsyncKeyOrderedProcessingEnabled()) {
            return (r, k) -> asyncProcessWithKey(k, r::run);
        } else {
            return (r, k) -> {
                Object oldKey = currentKey();
                try {
                    r.run();
                } finally {
                    setCurrentKey(oldKey);
                }
            };
        }
    }

    protected ProcessingTimeManager getProcessingTimeManager() {

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Address the cause reported by the error message: The key is only defined for keyed operator
  2. Verify the inputs, configuration values, and classpath/dependency setup related to this operation, then retry.

Example fix

Correct the condition described ("The key is only defined for keyed operator") and rerun the job or command.

When it happens

Trigger: Triggered at runtime when the operation fails because: The key is only defined for keyed operator.

Common situations: Commonly caused by misconfiguration, missing dependencies or files, unsupported types or operations, or invalid user input leading to: The key is only defined for keyed operator.


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/9b041bff0fee52ac. Report an issue: GitHub.