apache/flink · error · InvalidFieldReferenceException

Nested field expression "{}" not possible on atomic type {}.

Error message

Nested field expression "{}" not possible on atomic type {}.

What it means

Thrown by RowTypeInfo.getFlatFields when a nested field expression (e.g. "0.sub" or "myField.sub") references a Row field whose TypeInformation is atomic (not a CompositeType). You cannot drill into a scalar with a dot-separated tail. This is an InvalidFieldReferenceException.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/java/typeutils/RowTypeInfo.java:159

            for (int i = 0; i < fieldIndex; i++) {
                offset += this.getTypeAt(i).getTotalFields();
            }

            String tail = matcher.group(3);

            if (tail == null) {
                // expression hasn't nested field
                if (fieldType instanceof CompositeType) {
                    ((CompositeType) fieldType).getFlatFields("*", offset, result);
                } else {
                    result.add(new FlatFieldDescriptor(offset, fieldType));
                }
            } else {
                // expression has nested field
                if (fieldType instanceof CompositeType) {
                    ((CompositeType) fieldType).getFlatFields(tail, offset, result);
                } else {
                    throw new InvalidFieldReferenceException(
                            "Nested field expression \""
                                    + tail
                                    + "\" not possible on atomic type "
                                    + fieldType
                                    + ".");
                }
            }
        }
    }

    @Override
    public <X> TypeInformation<X> getTypeAt(String fieldExpression) {
        Matcher matcher = PATTERN_NESTED_FIELDS.matcher(fieldExpression);
        if (!matcher.matches()) {
            if (fieldExpression.equals(ExpressionKeys.SELECT_ALL_CHAR)
                    || fieldExpression.equals(ExpressionKeys.SELECT_ALL_CHAR_SCALA)) {
                throw new InvalidFieldReferenceException(
                        "Wildcard expressions are not allowed here.");

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Remove the '.tail' — reference the atomic field directly by index or name.
  2. If nesting is required, confirm the field's TypeInformation is a CompositeType via rowType.getTypeAt(index).

Example fix

// before
rowType.getFlatFields("f0.inner"); // f0 is a String
// after
rowType.getFlatFields("f0");
Defensive patterns

Strategy: type-guard

Validate before calling

TypeInformation<?> ft = rowType.getTypeAt(fieldIndex);
if (tail != null && !(ft instanceof CompositeType)) {
    throw new IllegalArgumentException(
        "Cannot nest into atomic " + ft);
}

Type guard

boolean canNestInto(RowTypeInfo type, int index) {
    return type.getTypeAt(index) instanceof CompositeType;
}

Prevention

When it happens

Trigger: Calling rowType.getFlatFields("f1.length") where field f1 is a String, or keyBy("0.value") where field 0 is an Integer. The tail (matcher.group(3)) is non-null but fieldType is not a CompositeType.

Common situations: Developer assumes a Row field holds a nested POJO/Tuple/Row but it resolves to a basic type. Common when working with schema-evolved Rows or when the nested type is not Flink-POJO-compliant.

Related errors


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