{"record":{"id":"130704c0a36efa42","repo":"apache/flink","slug":"unexpected-logicaltype","errorCode":null,"errorMessage":"Unexpected LogicalType: ","messagePattern":"Unexpected LogicalType: ","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"flink-formats/flink-protobuf/src/main/java/org/apache/flink/formats/protobuf/util/PbSchemaValidationUtils.java","lineNumber":105,"sourceCode":"                            }\n                        });\n    }\n\n    /**\n     * Validate type match of general type.\n     *\n     * @param fd the {@link Descriptors.Descriptor} of the protobuf object.\n     * @param logicalType the corresponding {@link LogicalType} to the {@link FieldDescriptor}\n     */\n    private static void validateTypeMatch(FieldDescriptor fd, LogicalType logicalType) {\n        if (!fd.isRepeated()) {\n            if (fd.getJavaType() != JavaType.MESSAGE) {\n                // simple type\n                validateSimpleType(fd, logicalType.getTypeRoot());\n            } else {\n                // message type\n                if (!(logicalType instanceof RowType)) {\n                    throw new ValidationException(\n                            \"Unexpected LogicalType: \" + logicalType + \". It should be RowType\");\n                }\n                validateTypeMatch(fd.getMessageType(), (RowType) logicalType);\n            }\n        } else {\n            if (fd.isMapField()) {\n                // map type\n                if (!(logicalType instanceof MapType)) {\n                    throw new ValidationException(\n                            \"Unexpected LogicalType: \" + logicalType + \". It should be MapType\");\n                }\n                MapType mapType = (MapType) logicalType;\n                validateSimpleType(\n                        fd.getMessageType().findFieldByName(PbConstant.PB_MAP_KEY_NAME),\n                        mapType.getKeyType().getTypeRoot());\n                validateTypeMatch(\n                        fd.getMessageType().findFieldByName(PbConstant.PB_MAP_VALUE_NAME),\n                        mapType.getValueType());","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-formats/flink-protobuf/src/main/java/org/apache/flink/formats/protobuf/util/PbSchemaValidationUtils.java#L87-L123","documentation":"Validation rule: a non-repeated proto field of JavaType MESSAGE maps structurally to a Flink RowType. If the DDL declares any other type for such a field (scalar, array, map), this ValidationException is thrown with the actual LogicalType. It is raised at DDL validation time by PbSchemaValidationUtils.","triggerScenarios":"Proto: message Outer { Inner inner = 1; } with DDL column inner INT/VARCHAR/ARRAY<...> instead of ROW(...).","commonSituations":"Hand-written DDLs that flatten message fields as scalars; schema drift after a proto field changed from scalar to message.","solutions":["Declare the column as ROW(field types...) matching the nested message's fields.","Or use a computed column/dedicated view to flatten: inner_id AS inner.id if flattening is desired (map the ROW first).","Regenerate and re-inspect the .proto to confirm the field is a message."],"exampleFix":"-- before\ninner VARCHAR,\n-- after\ninner ROW<street STRING, city STRING>,","handlingStrategy":"validation","validationCode":"FieldDescriptor fd = descriptor.findFieldByName(name);\nif (!fd.isRepeated() && fd.getJavaType() == FieldDescriptor.JavaType.MESSAGE\n        && !(flinkType instanceof RowType)) {\n    throw new ValidationException(name + \" must be ROW\");\n}","typeGuard":"boolean matchesProtoShape(FieldDescriptor fd, LogicalType t) {\n    if (!fd.isRepeated() && fd.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {\n        return t instanceof RowType;\n    }\n    return true;\n}","tryCatchPattern":null,"preventionTips":["Model nested proto messages as ROW types in DDLs by convention.","Run validatePbStruct(descriptor, rowType) in CI for every DDL/proto pair."],"tags":["protobuf","schema-validation","row-type","ddl"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}