Skip to content

Commit

Permalink
[BEAM-12460] Provide a simpler interface to convert Beam Row to Gener…
Browse files Browse the repository at this point in the history
…icRecord.
  • Loading branch information
anantdamle committed Jun 8, 2021
1 parent 4e22ff3 commit c13a0cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,14 @@ public static Row toBeamRowStrict(GenericRecord record, @Nullable Schema schema)
return builder.build();
}

/**
* Convert from a Beam Row to an AVRO GenericRecord. The Avro Schema is inferred from the Beam
* schema on the row.
*/
public static GenericRecord toGenericRecord(Row row) {
return toGenericRecord(row, null);
}

/**
* Convert from a Beam Row to an AVRO GenericRecord. If a Schema is not provided, one is inferred
* from the Beam schema on the row.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,13 @@ public void testBeamRowToGenericRecord() {
assertEquals(getGenericRecord(), genericRecord);
}

@Test
public void testBeamRowToGenericRecordInferSchema() {
GenericRecord genericRecord = AvroUtils.toGenericRecord(getBeamRow());
assertEquals(getAvroSchema(), genericRecord.getSchema());
assertEquals(getGenericRecord(), genericRecord);
}

@Test
public void testRowToGenericRecordFunction() {
SerializableUtils.ensureSerializable(AvroUtils.getRowToGenericRecordFunction(NULL_SCHEMA));
Expand Down

0 comments on commit c13a0cc

Please sign in to comment.