Search in sources :

Example 1 with DisplayData

use of org.apache.beam.sdk.transforms.display.DisplayData in project beam by apache.

the class ApproximateQuantilesTest method testDisplayData.

@Test
public void testDisplayData() {
    Top.Natural<Integer> comparer = new Top.Natural<Integer>();
    PTransform<?, ?> approxQuanitiles = ApproximateQuantiles.globally(20, comparer);
    DisplayData displayData = DisplayData.from(approxQuanitiles);
    assertThat(displayData, hasDisplayItem("numQuantiles", 20));
    assertThat(displayData, hasDisplayItem("comparer", comparer.getClass()));
}
Also used : DisplayData(org.apache.beam.sdk.transforms.display.DisplayData) Test(org.junit.Test)

Example 2 with DisplayData

use of org.apache.beam.sdk.transforms.display.DisplayData in project beam by apache.

the class CombineTest method testDisplayDataForWrappedFn.

@Test
public void testDisplayDataForWrappedFn() {
    UniqueInts combineFn = new UniqueInts() {

        @Override
        public void populateDisplayData(DisplayData.Builder builder) {
            builder.add(DisplayData.item("foo", "bar"));
        }
    };
    Combine.PerKey<?, ?, ?> combine = Combine.perKey(combineFn);
    DisplayData displayData = DisplayData.from(combine);
    assertThat(displayData, hasDisplayItem("combineFn", combineFn.getClass()));
    assertThat(displayData, hasDisplayItem(hasNamespace(combineFn.getClass())));
}
Also used : DisplayData(org.apache.beam.sdk.transforms.display.DisplayData) Test(org.junit.Test)

Example 3 with DisplayData

use of org.apache.beam.sdk.transforms.display.DisplayData in project beam by apache.

the class BigtableIOTest method testReadingPrimitiveDisplayData.

@Test
public void testReadingPrimitiveDisplayData() throws IOException, InterruptedException {
    final String table = "fooTable";
    service.createTable(table);
    RowFilter rowFilter = RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8("foo.*")).build();
    DisplayDataEvaluator evaluator = DisplayDataEvaluator.create();
    BigtableIO.Read read = BigtableIO.read().withBigtableOptions(BIGTABLE_OPTIONS).withTableId(table).withRowFilter(rowFilter).withBigtableService(service);
    Set<DisplayData> displayData = evaluator.displayDataForPrimitiveSourceTransforms(read);
    assertThat("BigtableIO.Read should include the table id in its primitive display data", displayData, Matchers.hasItem(hasDisplayItem("tableId")));
    assertThat("BigtableIO.Read should include the row filter, if it exists, in its primitive " + "display data", displayData, Matchers.hasItem(hasDisplayItem("rowFilter")));
}
Also used : RowFilter(com.google.bigtable.v2.RowFilter) ByteString(com.google.protobuf.ByteString) DisplayDataEvaluator(org.apache.beam.sdk.transforms.display.DisplayDataEvaluator) DisplayData(org.apache.beam.sdk.transforms.display.DisplayData) Test(org.junit.Test)

Example 4 with DisplayData

use of org.apache.beam.sdk.transforms.display.DisplayData in project beam by apache.

the class BigQueryIOTest method testQuerySourcePrimitiveDisplayData.

@Test
public void testQuerySourcePrimitiveDisplayData() throws IOException, InterruptedException {
    DisplayDataEvaluator evaluator = DisplayDataEvaluator.create();
    BigQueryIO.Read read = BigQueryIO.read().fromQuery("foobar").withTestServices(new FakeBigQueryServices().withDatasetService(new FakeDatasetService()).withJobService(new FakeJobService())).withoutValidation();
    Set<DisplayData> displayData = evaluator.displayDataForPrimitiveSourceTransforms(read);
    assertThat("BigQueryIO.Read should include the query in its primitive display data", displayData, hasItem(hasDisplayItem("query")));
}
Also used : DisplayDataEvaluator(org.apache.beam.sdk.transforms.display.DisplayDataEvaluator) DisplayData(org.apache.beam.sdk.transforms.display.DisplayData) Test(org.junit.Test)

Example 5 with DisplayData

use of org.apache.beam.sdk.transforms.display.DisplayData in project beam by apache.

the class ReadTest method testPrimitiveDisplayData.

private void testPrimitiveDisplayData(boolean isStreaming) {
    PipelineOptions options = DisplayDataEvaluator.getDefaultOptions();
    options.as(StreamingOptions.class).setStreaming(isStreaming);
    DisplayDataEvaluator evaluator = DisplayDataEvaluator.create(options);
    SerializableBoundedSource boundedSource = new SerializableBoundedSource() {

        @Override
        public void populateDisplayData(DisplayData.Builder builder) {
            builder.add(DisplayData.item("foo", "bar"));
        }
    };
    SerializableUnboundedSource unboundedSource = new SerializableUnboundedSource() {

        @Override
        public void populateDisplayData(DisplayData.Builder builder) {
            builder.add(DisplayData.item("foo", "bar"));
        }
    };
    Read.Bounded<String> bounded = Read.from(boundedSource);
    BoundedReadFromUnboundedSource<String> unbounded = Read.from(unboundedSource).withMaxNumRecords(1234);
    Set<DisplayData> boundedDisplayData = evaluator.displayDataForPrimitiveSourceTransforms(bounded);
    assertThat(boundedDisplayData, hasItem(hasDisplayItem("source", boundedSource.getClass())));
    assertThat(boundedDisplayData, hasItem(includesDisplayDataFor("source", boundedSource)));
    Set<DisplayData> unboundedDisplayData = evaluator.displayDataForPrimitiveSourceTransforms(unbounded);
    assertThat(unboundedDisplayData, hasItem(hasDisplayItem("source")));
    assertThat(unboundedDisplayData, hasItem(includesDisplayDataFor("source", unboundedSource)));
}
Also used : PipelineOptions(org.apache.beam.sdk.options.PipelineOptions) StreamingOptions(org.apache.beam.sdk.options.StreamingOptions) DisplayDataEvaluator(org.apache.beam.sdk.transforms.display.DisplayDataEvaluator) DisplayData(org.apache.beam.sdk.transforms.display.DisplayData)

Aggregations

DisplayData (org.apache.beam.sdk.transforms.display.DisplayData)117 Test (org.junit.Test)115 DisplayDataEvaluator (org.apache.beam.sdk.transforms.display.DisplayDataEvaluator)16 PCollection (org.apache.beam.sdk.values.PCollection)11 ByteString (com.google.protobuf.ByteString)9 Category (org.junit.experimental.categories.Category)9 Matchers.containsString (org.hamcrest.Matchers.containsString)6 Duration (org.joda.time.Duration)6 TableRow (com.google.api.services.bigquery.model.TableRow)4 Params (org.apache.beam.sdk.io.DefaultFilenamePolicy.Params)3 BigQueryHelpers.toJsonString (org.apache.beam.sdk.io.gcp.bigquery.BigQueryHelpers.toJsonString)3 Builder (org.apache.beam.sdk.transforms.display.DisplayData.Builder)3 Instant (org.joda.time.Instant)3 TableSchema (com.google.api.services.bigquery.model.TableSchema)2 RowFilter (com.google.bigtable.v2.RowFilter)2 ArrayList (java.util.ArrayList)2 WritableByteChannelFactory (org.apache.beam.sdk.io.FileBasedSink.WritableByteChannelFactory)2 ParDo (org.apache.beam.sdk.transforms.ParDo)2 StringUtils.byteArrayToJsonString (org.apache.beam.sdk.util.StringUtils.byteArrayToJsonString)2 ImmutableSet (com.google.common.collect.ImmutableSet)1