Java Code Examples for org.apache.beam.sdk.transforms.display.DisplayData#from()

The following examples show how to use org.apache.beam.sdk.transforms.display.DisplayData#from() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmlIOTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void testDisplayData() {
  DisplayData displayData =
      DisplayData.from(
          XmlIO.<Integer>read()
              .from("foo.xml")
              .withRootElement("bird")
              .withRecordElement("cat")
              .withMinBundleSize(1234)
              .withRecordClass(Integer.class));

  Assert.assertThat(displayData, hasDisplayItem("filePattern", "foo.xml"));
  Assert.assertThat(displayData, hasDisplayItem("rootElement", "bird"));
  Assert.assertThat(displayData, hasDisplayItem("recordElement", "cat"));
  Assert.assertThat(displayData, hasDisplayItem("recordClass", Integer.class));
  Assert.assertThat(displayData, hasDisplayItem("minBundleSize", 1234));
}
 
Example 2
Source File: PubsubIOTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteWithPubsubGrpcClientFactory() {
  String topic = "projects/project/topics/topic";
  PubsubIO.Write<?> write =
      PubsubIO.writeStrings()
          .to(topic)
          .withClientFactory(PubsubGrpcClient.FACTORY)
          .withTimestampAttribute("myTimestamp")
          .withIdAttribute("myId");

  DisplayData displayData = DisplayData.from(write);

  assertThat(displayData, hasDisplayItem("topic", topic));
  assertThat(displayData, hasDisplayItem("timestampAttribute", "myTimestamp"));
  assertThat(displayData, hasDisplayItem("idAttribute", "myId"));
}
 
Example 3
Source File: KafkaIOTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void testSinkDisplayData() {
  try (MockProducerWrapper producerWrapper = new MockProducerWrapper()) {
    KafkaIO.Write<Integer, Long> write =
        KafkaIO.<Integer, Long>write()
            .withBootstrapServers("myServerA:9092,myServerB:9092")
            .withTopic("myTopic")
            .withValueSerializer(LongSerializer.class)
            .withProducerFactoryFn(new ProducerFactoryFn(producerWrapper.producerKey))
            .withProducerConfigUpdates(ImmutableMap.of("retry.backoff.ms", 100));

    DisplayData displayData = DisplayData.from(write);

    assertThat(displayData, hasDisplayItem("topic", "myTopic"));
    assertThat(displayData, hasDisplayItem("bootstrap.servers", "myServerA:9092,myServerB:9092"));
    assertThat(displayData, hasDisplayItem("retries", 3));
    assertThat(displayData, hasDisplayItem("retry.backoff.ms", 100));
  }
}
 
Example 4
Source File: ParDoTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithOutputTagsDisplayData() {
  DoFn<String, String> fn =
      new DoFn<String, String>() {
        @ProcessElement
        public void proccessElement(ProcessContext c) {}

        @Override
        public void populateDisplayData(Builder builder) {
          builder.add(DisplayData.item("fnMetadata", "foobar"));
        }
      };

  ParDo.MultiOutput<String, String> parDo =
      ParDo.of(fn).withOutputTags(new TupleTag<>(), TupleTagList.empty());

  DisplayData displayData = DisplayData.from(parDo);
  assertThat(displayData, includesDisplayDataFor("fn", fn));
  assertThat(displayData, hasDisplayItem("fn", fn.getClass()));
}
 
Example 5
Source File: BigtableConfigTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void testPopulateDisplayData() {
  DisplayData displayData =
      DisplayData.from(
          config.withProjectId(PROJECT_ID).withInstanceId(INSTANCE_ID).withTableId(TABLE_ID)
              ::populateDisplayData);

  assertThat(
      displayData,
      hasDisplayItem(
          allOf(
              hasKey("projectId"), hasLabel("Bigtable Project Id"), hasValue(PROJECT_ID.get()))));

  assertThat(
      displayData,
      hasDisplayItem(
          allOf(
              hasKey("instanceId"),
              hasLabel("Bigtable Instance Id"),
              hasValue(INSTANCE_ID.get()))));

  assertThat(
      displayData,
      hasDisplayItem(
          allOf(hasKey("tableId"), hasLabel("Bigtable Table Id"), hasValue(TABLE_ID.get()))));
}
 
Example 6
Source File: ParDoTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void testDoFnWithContextDisplayData() {
  DoFn<String, String> fn =
      new DoFn<String, String>() {
        @ProcessElement
        public void proccessElement(ProcessContext c) {}

        @Override
        public void populateDisplayData(Builder builder) {
          builder.add(DisplayData.item("fnMetadata", "foobar"));
        }
      };

  SingleOutput<String, String> parDo = ParDo.of(fn);

  DisplayData displayData = DisplayData.from(parDo);
  assertThat(displayData, includesDisplayDataFor("fn", fn));
  assertThat(displayData, hasDisplayItem("fn", fn.getClass()));
}
 
Example 7
Source File: ProxyInvocationHandlerTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testDisplayDataExcludesValuesAccessedButNeverSet() {
  HasDefaults options = PipelineOptionsFactory.as(HasDefaults.class);
  assertEquals("bar", options.getFoo());

  DisplayData data = DisplayData.from(options);
  assertThat(data, not(hasDisplayItem("foo")));
}
 
Example 8
Source File: ApproximateQuantilesTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testDisplayData() {
  Top.Natural<Integer> comparer = new Top.Natural<>();
  PTransform<?, ?> approxQuanitiles = ApproximateQuantiles.globally(20, comparer);
  DisplayData displayData = DisplayData.from(approxQuanitiles);

  assertThat(displayData, hasDisplayItem("numQuantiles", 20));
  assertThat(displayData, hasDisplayItem("comparer", comparer.getClass()));
}
 
Example 9
Source File: DatastoreV1Test.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteDisplayData() {
  Write write = DatastoreIO.v1().write().withProjectId(PROJECT_ID);

  DisplayData displayData = DisplayData.from(write);

  assertThat(displayData, hasDisplayItem("projectId", PROJECT_ID));
}
 
Example 10
Source File: GenerateSequenceTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testBoundedDisplayDataSubrange() {
  PTransform<?, ?> input = GenerateSequence.from(12).to(1234);
  DisplayData displayData = DisplayData.from(input);
  assertThat(displayData, hasDisplayItem("from", 12));
  assertThat(displayData, hasDisplayItem("to", 1234));
}
 
Example 11
Source File: PipelineTranslator.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
/**
 * @param ctx       provides translation context
 * @param beamNode  the beam node to be translated
 * @param transform transform which can be obtained from {@code beamNode}
 */
@PrimitiveTransformTranslator(Read.Unbounded.class)
private static void unboundedReadTranslator(final PipelineTranslationContext ctx,
                                            final TransformHierarchy.Node beamNode,
                                            final Read.Unbounded<?> transform) {
  final IRVertex vertex = new BeamUnboundedSourceVertex<>(transform.getSource(), DisplayData.from(transform));
  ctx.addVertex(vertex);
  beamNode.getInputs().values().forEach(input -> ctx.addEdgeTo(vertex, input));
  beamNode.getOutputs().values().forEach(output -> ctx.registerMainOutputFrom(beamNode, vertex, output));
}
 
Example 12
Source File: CombineTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@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())));
}
 
Example 13
Source File: ProxyInvocationHandlerTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testDisplayDataNullValuesConvertedToEmptyString() throws Exception {
  FooOptions options = PipelineOptionsFactory.as(FooOptions.class);
  options.setFoo(null);

  DisplayData data = DisplayData.from(options);
  assertThat(data, hasDisplayItem("foo", ""));

  FooOptions deserializedOptions = serializeDeserialize(FooOptions.class, options);
  DisplayData deserializedData = DisplayData.from(deserializedOptions);
  assertThat(deserializedData, hasDisplayItem("foo", ""));
}
 
Example 14
Source File: ProxyInvocationHandlerTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testDisplayDataJsonValueSetAfterDeserialization() throws Exception {
  FooOptions options = PipelineOptionsFactory.as(FooOptions.class);
  options.setFoo("bar");
  DisplayData data = DisplayData.from(options);
  assertThat(data, hasDisplayItem("foo", "bar"));

  FooOptions deserializedOptions = serializeDeserialize(FooOptions.class, options);
  deserializedOptions.setFoo("baz");
  DisplayData dataAfterDeserialization = DisplayData.from(deserializedOptions);
  assertThat(dataAfterDeserialization, hasDisplayItem("foo", "baz"));
}
 
Example 15
Source File: HBaseIOTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadingDisplayData() {
  HBaseIO.Read read = HBaseIO.read().withConfiguration(conf).withTableId("fooTable");
  DisplayData displayData = DisplayData.from(read);
  assertThat(displayData, hasDisplayItem("tableId", "fooTable"));
  assertThat(displayData, hasDisplayItem("configuration"));
}
 
Example 16
Source File: ProxyInvocationHandlerTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testDisplayDataExcludedFromOverriddenBaseClass() {
  ExtendsBaseOptions options = PipelineOptionsFactory.as(ExtendsBaseOptions.class);
  options.setFoo("bar");

  DisplayData displayData = DisplayData.from(options);
  assertThat(displayData, not(hasDisplayItem(hasNamespace(BaseOptions.class))));
}
 
Example 17
Source File: ProxyInvocationHandlerTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testDisplayDataArrayValue() throws Exception {
  ArrayOptions options = PipelineOptionsFactory.as(ArrayOptions.class);
  options.setDeepArray(new String[][] {new String[] {"a", "b"}, new String[] {"c"}});
  options.setDeepPrimitiveArray(new int[][] {new int[] {1, 2}, new int[] {3}});

  DisplayData data = DisplayData.from(options);
  assertThat(data, hasDisplayItem("deepArray", "[[a, b], [c]]"));
  assertThat(data, hasDisplayItem("deepPrimitiveArray", "[[1, 2], [3]]"));

  ArrayOptions deserializedOptions = serializeDeserialize(ArrayOptions.class, options);
  DisplayData deserializedData = DisplayData.from(deserializedOptions);
  assertThat(deserializedData, hasDisplayItem("deepPrimitiveArray", "[[1, 2], [3]]"));
}
 
Example 18
Source File: AvroSourceTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testDisplayData() {
  AvroSource<Bird> source =
      AvroSource.from("foobar.txt").withSchema(Bird.class).withMinBundleSize(1234);

  DisplayData displayData = DisplayData.from(source);
  assertThat(displayData, hasDisplayItem("filePattern", "foobar.txt"));
  assertThat(displayData, hasDisplayItem("minBundleSize", 1234));
}
 
Example 19
Source File: DatastoreV1Test.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteKeyDisplayData() {
  DeleteKey deleteKey = DatastoreIO.v1().deleteKey().withProjectId(PROJECT_ID);

  DisplayData displayData = DisplayData.from(deleteKey);

  assertThat(displayData, hasDisplayItem("projectId", PROJECT_ID));
}
 
Example 20
Source File: TextIOWriteTest.java    From beam with Apache License 2.0 4 votes vote down vote up
@Test
@Category(NeedsRunner.class)
public void testWriteWithWritableByteChannelFactory() throws Exception {
  Coder<String> coder = StringUtf8Coder.of();
  String outputName = "file.txt";
  ResourceId baseDir =
      FileSystems.matchNewResource(
          Files.createTempDirectory(tempFolder.getRoot().toPath(), "testwrite").toString(), true);

  PCollection<String> input = p.apply(Create.of(Arrays.asList(LINES2_ARRAY)).withCoder(coder));

  final WritableByteChannelFactory writableByteChannelFactory =
      new DrunkWritableByteChannelFactory();
  TextIO.Write write =
      TextIO.write()
          .to(
              baseDir
                  .resolve(outputName, ResolveOptions.StandardResolveOptions.RESOLVE_FILE)
                  .toString())
          .withoutSharding()
          .withWritableByteChannelFactory(writableByteChannelFactory);
  DisplayData displayData = DisplayData.from(write);
  assertThat(displayData, hasDisplayItem("writableByteChannelFactory", "DRUNK"));

  input.apply(write);

  p.run();

  final List<String> drunkElems = new ArrayList<>(LINES2_ARRAY.length * 2 + 2);
  for (String elem : LINES2_ARRAY) {
    drunkElems.add(elem);
    drunkElems.add(elem);
  }
  assertOutputFiles(
      drunkElems.toArray(new String[0]),
      null,
      null,
      1,
      baseDir.resolve(
          outputName + writableByteChannelFactory.getSuggestedFilenameSuffix(),
          ResolveOptions.StandardResolveOptions.RESOLVE_FILE),
      write.inner.getShardTemplate());
}