Search in sources :

Example 1 with BuildTableManifests

use of com.google.cloud.teleport.spanner.ExportTransform.BuildTableManifests in project DataflowTemplates by GoogleCloudPlatform.

the class ExportTransformTest method buildTableManifests.

@Test
public void buildTableManifests() throws Exception {
    Path f1 = Files.createTempFile("table1-file", "1");
    Path f2 = Files.createTempFile("table1-file", "2");
    Path f3 = Files.createTempFile("table2-file", "1");
    // Create the expected manifest string.
    TableManifest.Builder builder = TableManifest.newBuilder();
    builder.addFilesBuilder().setName(f1.getFileName().toString()).setMd5("1B2M2Y8AsgTpgAmY7PhCfg==");
    builder.addFilesBuilder().setName(f2.getFileName().toString()).setMd5("1B2M2Y8AsgTpgAmY7PhCfg==");
    String manifest1 = JsonFormat.printer().print(builder.build());
    builder = TableManifest.newBuilder();
    builder.addFilesBuilder().setName(f3.getFileName().toString()).setMd5("1B2M2Y8AsgTpgAmY7PhCfg==");
    String manifest2 = JsonFormat.printer().print(builder.build());
    final Map<String, Iterable<String>> tablesAndFiles = ImmutableMap.of("table1", ImmutableList.of(f1.toString(), f2.toString()), "table2", ImmutableList.of(f3.toString()));
    // Execute the transform.
    PCollection<KV<String, String>> tableManifests = pipeline.apply("Create", Create.of(tablesAndFiles)).apply("Build table manifest", ParDo.of(new BuildTableManifests()));
    PAssert.that(tableManifests).containsInAnyOrder(KV.of("table1", manifest1), KV.of("table2", manifest2));
    pipeline.run();
}
Also used : Path(java.nio.file.Path) BuildTableManifests(com.google.cloud.teleport.spanner.ExportTransform.BuildTableManifests) TableManifest(com.google.cloud.teleport.spanner.ExportProtos.TableManifest) KV(org.apache.beam.sdk.values.KV) Test(org.junit.Test)

Aggregations

TableManifest (com.google.cloud.teleport.spanner.ExportProtos.TableManifest)1 BuildTableManifests (com.google.cloud.teleport.spanner.ExportTransform.BuildTableManifests)1 Path (java.nio.file.Path)1 KV (org.apache.beam.sdk.values.KV)1 Test (org.junit.Test)1