Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BEAM-12460] Provide a simpler interface to convert Beam Row to GenericRecord #14964

Merged
merged 1 commit into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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