/** * Build a {@link StructuredRecord} with the fields set by this builder. * * @return a {@link StructuredRecord} with the fields set by this builder * @throws UnexpectedFormatException if there is at least one non-nullable field without a value */ public StructuredRecord build() throws UnexpectedFormatException { // check that all non-nullable fields have a value. for (Schema.Field field : schema.getFields()) { String fieldName = field.getName(); if (!fields.containsKey(fieldName)) { // if the field is not nullable and there is no value set for the field, this is invalid. if (!field.getSchema().isNullable()) { throw new UnexpectedFormatException("Field " + fieldName + " must contain a value."); } else { // otherwise, set the value for the field to null fields.put(fieldName, null); } } } return new StructuredRecord(schema, fields); }
/** * Build a {@link StructuredRecord} with the fields set by this builder. * * @return a {@link StructuredRecord} with the fields set by this builder * @throws UnexpectedFormatException if there is at least one non-nullable field without a value */ public StructuredRecord build() throws UnexpectedFormatException { // check that all non-nullable fields have a value. for (Schema.Field field : schema.getFields()) { String fieldName = field.getName(); if (!fields.containsKey(fieldName)) { // if the field is not nullable and there is no value set for the field, this is invalid. if (!field.getSchema().isNullable()) { throw new UnexpectedFormatException("Field " + fieldName + " must contain a value."); } else { // otherwise, set the value for the field to null fields.put(fieldName, null); } } } return new StructuredRecord(schema, fields); }