Skip to content
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
2 changes: 1 addition & 1 deletion .github/trigger_files/beam_PostCommit_Java_DataflowV1.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"comment": "Modify this file in a trivial way to cause this test suite to run"
"comment": "Modify this file in a trivial way to cause this test suite to run"
}
3 changes: 3 additions & 0 deletions .github/trigger_files/beam_PostCommit_Java_DataflowV2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"comment": "Modify this file in a trivial way to cause this test suite to run"
}
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,10 @@ public static Row toBeamRow(GenericRecord record, Schema schema, ConversionOptio
.map(
field -> {
try {
return convertAvroFormat(field.getType(), record.get(field.getName()), options);
org.apache.avro.Schema.Field avroField =
record.getSchema().getField(field.getName());
Object value = avroField != null ? record.get(avroField.pos()) : null;
return convertAvroFormat(field.getType(), value, options);
} catch (Exception cause) {
throw new IllegalArgumentException(
"Error converting field " + field + ": " + cause.getMessage(), cause);
Expand Down Expand Up @@ -709,7 +712,8 @@ public static Row toBeamRow(Schema rowSchema, TableSchema bqSchema, TableRow jso
+ jsonBQValue.getClass()
+ "' to '"
+ fieldType
+ "' because the BigQuery type is a List, while the output type is not a collection.");
+ "' because the BigQuery type is a List, while the output type is not a"
+ " collection.");
}

boolean innerTypeIsMap = fieldType.getCollectionElementType().getTypeName().isMapType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,22 @@ public void testToBeamRow_avro_array_array_row() {
assertEquals(expected, beamRow);
}

@Test
public void testToBeamRow_projection() {
long testId = 123L;
// recordSchema is a projection of FLAT_TYPE schema
org.apache.avro.Schema recordSchema =
org.apache.avro.SchemaBuilder.record("__root__").fields().optionalLong("id").endRecord();
GenericData.Record record = new GenericData.Record(recordSchema);
record.put("id", testId);

Row expected = Row.withSchema(FLAT_TYPE).withFieldValue("id", testId).build();
Row actual =
BigQueryUtils.toBeamRow(
record, FLAT_TYPE, BigQueryUtils.ConversionOptions.builder().build());
assertEquals(expected, actual);
}

@Test
public void testToTableSpec() {
TableReference withProject =
Expand Down