Skip to content

Commit a62ff34

Browse files
authored
Better error message when trying to get Beam Schema from proto schema with Struct (#32260)
* Better error message when trying to get Beam Schema from proto schema with Struct * minor fix - consolidate
1 parent ed4c03e commit a62ff34

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

sdks/java/extensions/protobuf/src/main/java/org/apache/beam/sdk/extensions/protobuf/ProtoSchemaTranslator.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,12 @@ static synchronized Schema getSchema(Descriptors.Descriptor descriptor) {
169169
if (alreadyVisitedSchemas.containsKey(descriptor)) {
170170
@Nullable Schema existingSchema = alreadyVisitedSchemas.get(descriptor);
171171
if (existingSchema == null) {
172+
String name = descriptor.getFullName();
173+
if ("google.protobuf.Struct".equals(name)) {
174+
throw new UnsupportedOperationException("Infer schema of Struct type is not supported.");
175+
}
172176
throw new IllegalArgumentException(
173-
"Cannot infer schema with a circular reference. Proto Field: "
174-
+ descriptor.getFullName());
177+
"Cannot infer schema with a circular reference. Proto Field: " + name);
175178
}
176179
return existingSchema;
177180
}
@@ -339,7 +342,7 @@ private static FieldType beamFieldTypeFromSingularProtoField(
339342
fieldType = FieldType.logicalType(new NanosDuration());
340343
break;
341344
case "google.protobuf.Any":
342-
throw new RuntimeException("Any not yet supported");
345+
throw new UnsupportedOperationException("Any not yet supported");
343346
default:
344347
fieldType = FieldType.row(getSchema(protoFieldDescriptor.getMessageType()));
345348
}

0 commit comments

Comments
 (0)