Search in sources :

Example 1 with BigtableToAvroFn

use of com.google.cloud.teleport.bigtable.BigtableToAvro.BigtableToAvroFn in project DataflowTemplates by GoogleCloudPlatform.

the class BigtableToAvroTest method applyBigtableToAvroFn.

@Test
public void applyBigtableToAvroFn() throws Exception {
    Row bigtableRow1 = createBigtableRow("row1");
    bigtableRow1 = upsertBigtableCell(bigtableRow1, "family1", "column1", 1, "value1");
    bigtableRow1 = upsertBigtableCell(bigtableRow1, "family1", "column1", 2, "value2");
    bigtableRow1 = upsertBigtableCell(bigtableRow1, "family1", "column2", 1, "value3");
    bigtableRow1 = upsertBigtableCell(bigtableRow1, "family2", "column1", 1, "value4");
    Row bigtableRow2 = createBigtableRow("row2");
    bigtableRow2 = upsertBigtableCell(bigtableRow2, "family2", "column2", 1, "value2");
    final List<Row> bigtableRows = ImmutableList.of(bigtableRow1, bigtableRow2);
    BigtableRow avroRow1 = createAvroRow("row1");
    addAvroCell(avroRow1, "family1", "column1", 1, "value1");
    // Expect a new cell due to a different timestamp of "2".
    addAvroCell(avroRow1, "family1", "column1", 2, "value2");
    // Expect a new cell due to a different column of "column2".
    addAvroCell(avroRow1, "family1", "column2", 1, "value3");
    // Expect a new cell due to a different family of "family2".
    addAvroCell(avroRow1, "family2", "column1", 1, "value4");
    BigtableRow avroRow2 = createAvroRow("row2");
    addAvroCell(avroRow2, "family2", "column2", 1, "value2");
    final List<BigtableRow> expectedAvroRows = ImmutableList.of(avroRow1, avroRow2);
    PCollection<BigtableRow> avroRows = pipeline.apply("Create", Create.of(bigtableRows)).apply("Transform to Avro", MapElements.via(new BigtableToAvroFn()));
    PAssert.that(avroRows).containsInAnyOrder(expectedAvroRows);
    pipeline.run();
}
Also used : BigtableToAvroFn(com.google.cloud.teleport.bigtable.BigtableToAvro.BigtableToAvroFn) TestUtils.createBigtableRow(com.google.cloud.teleport.bigtable.TestUtils.createBigtableRow) Row(com.google.bigtable.v2.Row) TestUtils.createBigtableRow(com.google.cloud.teleport.bigtable.TestUtils.createBigtableRow) TestUtils.createAvroRow(com.google.cloud.teleport.bigtable.TestUtils.createAvroRow) Test(org.junit.Test)

Aggregations

Row (com.google.bigtable.v2.Row)1 BigtableToAvroFn (com.google.cloud.teleport.bigtable.BigtableToAvro.BigtableToAvroFn)1 TestUtils.createAvroRow (com.google.cloud.teleport.bigtable.TestUtils.createAvroRow)1 TestUtils.createBigtableRow (com.google.cloud.teleport.bigtable.TestUtils.createBigtableRow)1 Test (org.junit.Test)1