TheNeuralBit commented on a change in pull request #11119: [BEAM-9498] Include
descriptor and type of unsupported fields in RowJson exception
URL: https://github.com/apache/beam/pull/11119#discussion_r394028731
##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/util/RowJson.java
##########
@@ -84,41 +85,76 @@
private static final ImmutableSet<TypeName> SUPPORTED_TYPES =
ImmutableSet.of(BYTE, INT16, INT32, INT64, FLOAT, DOUBLE, BOOLEAN,
STRING, DECIMAL);
+ /**
+ * Throws {@link UnsupportedRowJsonException} if {@code schema} contains an
unsupported field
+ * type.
+ */
public static void verifySchemaSupported(Schema schema) {
- schema.getFields().forEach(RowJson::verifyFieldTypeSupported);
+ ImmutableList<UnsupportedField> unsupportedFields =
findUnsupportedFields(schema);
+ if (!unsupportedFields.isEmpty()) {
+ throw new UnsupportedRowJsonException(
+ String.format(
+ "Field type%s %s not supported when converting between JSON and
Rows. Supported types are: %s",
+ unsupportedFields.size() > 1 ? "s" : "",
+ unsupportedFields.toString(),
+ SUPPORTED_TYPES.toString()));
+ }
+ }
+
+ private static class UnsupportedField {
+ final String descriptor;
+ final TypeName typeName;
+
+ UnsupportedField(String descriptor, TypeName typeName) {
+ this.descriptor = descriptor;
+ this.typeName = typeName;
+ }
+
+ @Override
+ public String toString() {
+ return this.descriptor + "=" + this.typeName;
+ }
+ }
+
+ private static ImmutableList<UnsupportedField> findUnsupportedFields(Schema
schema) {
+ return schema.getFields().stream()
+ .flatMap((field) -> findUnsupportedFields(field).stream())
+ .collect(toImmutableList());
}
- static void verifyFieldTypeSupported(Field field) {
+ private static ImmutableList<UnsupportedField> findUnsupportedFields(Field
field) {
FieldType fieldType = field.getType();
Review comment:
Done! thanks
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services