private static Schema getUnnestedSchema( Schema schema, List<String> nameComponents, SerializableFunction<List<String>, String> fn) { Schema.Builder builder = Schema.builder(); for (Field field : schema.getFields()) { nameComponents.add(field.getName()); if (field.getType().getTypeName().isCompositeType()) { Schema nestedSchema = getUnnestedSchema(field.getType().getRowSchema(), nameComponents, fn); for (Field nestedField : nestedSchema.getFields()) { builder.addField(nestedField); } } else { String name = fn.apply(nameComponents); Field newField = field.toBuilder().setName(name).build(); builder.addField(newField); } nameComponents.remove(nameComponents.size() - 1); } return builder.build(); } /** Unnest a row. */
/** Returns a copy of the Field with the {@link FieldType} set. */ public Field withType(FieldType fieldType) { return toBuilder().setType(fieldType).build(); }
/** Returns a copy of the Field with isNullable set. */ public Field withNullable(boolean isNullable) { return toBuilder().setNullable(isNullable).build(); }
/** Returns a copy of the Field with the description set. */ public Field withDescription(String description) { return toBuilder().setDescription(description).build(); }
/** Returns a copy of the Field with the name set. */ public Field withName(String name) { return toBuilder().setName(name).build(); }