apache/flink · error · RuntimeException

Could not serialize row '%s'.

Error message

Could not serialize row '%s'.

What it means

The catch-all in OggJsonSerializationSchema.serialize wraps every Throwable from building the [before, after, op_type] envelope and calling the internal JSON serializer into RuntimeException('Could not serialize row ...'). The meaningful failure is the attached cause: unsupported RowKind, null in a non-nullable field, or a field value the generated serializer cannot convert to JSON.

Source

Thrown at flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/ogg/OggJsonSerializationSchema.java:112

                case UPDATE_AFTER:
                    genericRowData.setField(0, null);
                    genericRowData.setField(1, rowData);
                    genericRowData.setField(2, OP_INSERT);
                    return jsonSerializer.serialize(genericRowData);
                case UPDATE_BEFORE:
                case DELETE:
                    genericRowData.setField(0, rowData);
                    genericRowData.setField(1, null);
                    genericRowData.setField(2, OP_DELETE);
                    return jsonSerializer.serialize(genericRowData);
                default:
                    throw new UnsupportedOperationException(
                            format(
                                    "Unsupported operation '%s' for row kind.",
                                    rowData.getRowKind()));
            }
        } catch (Throwable t) {
            throw new RuntimeException(format("Could not serialize row '%s'.", rowData), t);
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        OggJsonSerializationSchema that = (OggJsonSerializationSchema) o;
        return Objects.equals(jsonSerializer, that.jsonSerializer);
    }

    @Override
    public int hashCode() {
        return Objects.hash(jsonSerializer);

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Inspect the cause chain (t) — fix the underlying RowKind/type/null problem it names.
  2. Rebuild the serialization schema (restart/re-create the sink) after any DDL change so codegen matches.
  3. Add a narrow map upstream validating arity and nullability against the sink schema before rows hit the sink.
Defensive patterns

Strategy: try-catch

Validate before calling

if (row.getArity() != sinkArity) throw new IllegalArgumentException("arity mismatch vs ogg-json sink");

Try / catch

try { schema.serialize(row); } catch (RuntimeException e) { log.error("ogg serialize failed, cause {}", e.getCause()); deadLetter.write(row, e.getCause()); }

Prevention

When it happens

Trigger: Any exception inside serialize(): default-branch RowKind error; schema mismatch between the RowData produced upstream and the physical RowType the schema was built for; nulls where primitives are expected.

Common situations: Sink DDL drifted from the producing schema (field order/count/type changes) while the serialization schema was not rebuilt; custom RowData implementations returning null fields.

Related errors


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