use of com.google.cloud.teleport.templates.common.BigQueryConverters.AvroToEntity in project DataflowTemplates by GoogleCloudPlatform.
the class BigQueryConvertersTest method testAvroToEntityDefaultNamespace.
/**
* Tests that {@link BigQueryConverters.AvroToEntity} creates an Entity with a default namespace
* when the namespace is not specified.
*/
@Test
public void testAvroToEntityDefaultNamespace() throws Exception {
// Create test data
List<TableFieldSchema> fields = new ArrayList<>();
fields.add(new TableFieldSchema().setName(idField).setType("STRING"));
fields.add(new TableFieldSchema().setName(shortStringField).setType("STRING"));
TableSchema bqSchema = new TableSchema().setFields(fields);
Schema avroSchema = new Schema.Parser().parse(String.format(avroSchemaTemplate, new StringBuilder().append(String.format(avroFieldTemplate, idField, "int", idFieldDesc)).append(",").append(generateShortStringField()).toString()));
GenericRecordBuilder builder = new GenericRecordBuilder(avroSchema);
builder.set(idField, 1);
builder.set(shortStringField, shortStringFieldValue);
Record record = builder.build();
SchemaAndRecord inputBqData = new SchemaAndRecord(record, bqSchema);
// Run the test
AvroToEntity noNamespaceConverter = AvroToEntity.newBuilder().setEntityKind(entityKind).setUniqueNameColumn(uniqueNameColumn).build();
Entity outputEntity = noNamespaceConverter.apply(inputBqData);
// Assess results
assertTrue(outputEntity.hasKey());
assertEquals("", outputEntity.getKey().getPartitionId().getNamespaceId());
}
Aggregations