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

The following examples show how to use org.apache.beam.sdk.transforms.display.DisplayData#inferType() . 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: KafkaIO.java    From DataflowTemplates with Apache License 2.0 6 votes vote down vote up
@Override
public void populateDisplayData(DisplayData.Builder builder) {
  super.populateDisplayData(builder);
  builder.addIfNotNull(DisplayData.item("topic", getTopic()).withLabel("Topic"));
  Set<String> ignoredProducerPropertiesKeys = IGNORED_PRODUCER_PROPERTIES.keySet();
  for (Map.Entry<String, Object> conf : getProducerConfig().entrySet()) {
    String key = conf.getKey();
    if (!ignoredProducerPropertiesKeys.contains(key)) {
      Object value =
          DisplayData.inferType(conf.getValue()) != null
              ? conf.getValue()
              : String.valueOf(conf.getValue());
      builder.add(DisplayData.item(key, ValueProvider.StaticValueProvider.of(value)));
    }
  }
}
 
Example 2
Source File: ConstantAvroDestination.java    From beam with Apache License 2.0 6 votes vote down vote up
@Override
public void populateDisplayData(DisplayData.Builder builder) {
  for (Map.Entry<String, Object> entry : metadata.entrySet()) {
    DisplayData.Type type = DisplayData.inferType(entry.getValue());
    if (type != null) {
      builder.add(DisplayData.item(entry.getKey(), type, entry.getValue()));
    } else {
      String base64 = BaseEncoding.base64().encode((byte[]) entry.getValue());
      String repr =
          base64.length() <= METADATA_BYTES_MAX_LENGTH
              ? base64
              : base64.substring(0, METADATA_BYTES_MAX_LENGTH) + "...";
      builder.add(DisplayData.item(entry.getKey(), repr));
    }
  }
}
 
Example 3
Source File: KafkaIO.java    From beam with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void populateDisplayData(DisplayData.Builder builder) {
  super.populateDisplayData(builder);
  List<String> topics = getTopics();
  List<TopicPartition> topicPartitions = getTopicPartitions();
  if (topics.size() > 0) {
    builder.add(DisplayData.item("topics", Joiner.on(",").join(topics)).withLabel("Topic/s"));
  } else if (topicPartitions.size() > 0) {
    builder.add(
        DisplayData.item("topicPartitions", Joiner.on(",").join(topicPartitions))
            .withLabel("Topic Partition/s"));
  }
  Set<String> ignoredConsumerPropertiesKeys = IGNORED_CONSUMER_PROPERTIES.keySet();
  for (Map.Entry<String, Object> conf : getConsumerConfig().entrySet()) {
    String key = conf.getKey();
    if (!ignoredConsumerPropertiesKeys.contains(key)) {
      Object value =
          DisplayData.inferType(conf.getValue()) != null
              ? conf.getValue()
              : String.valueOf(conf.getValue());
      builder.add(DisplayData.item(key, ValueProvider.StaticValueProvider.of(value)));
    }
  }
}
 
Example 4
Source File: KafkaIO.java    From beam with Apache License 2.0 6 votes vote down vote up
@Override
public void populateDisplayData(DisplayData.Builder builder) {
  super.populateDisplayData(builder);
  builder.addIfNotNull(DisplayData.item("topic", getTopic()).withLabel("Topic"));
  Set<String> ignoredProducerPropertiesKeys = IGNORED_PRODUCER_PROPERTIES.keySet();
  for (Map.Entry<String, Object> conf : getProducerConfig().entrySet()) {
    String key = conf.getKey();
    if (!ignoredProducerPropertiesKeys.contains(key)) {
      Object value =
          DisplayData.inferType(conf.getValue()) != null
              ? conf.getValue()
              : String.valueOf(conf.getValue());
      builder.add(DisplayData.item(key, ValueProvider.StaticValueProvider.of(value)));
    }
  }
}
 
Example 5
Source File: KafkaIO.java    From DataflowTemplates with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void populateDisplayData(DisplayData.Builder builder) {
  super.populateDisplayData(builder);
  ValueProvider<List<String>> topics = getTopics();
  List<TopicPartition> topicPartitions = getTopicPartitions();
  if (topics != null) {
    if (topics.isAccessible()) {
      builder.add(DisplayData.item("topics", Joiner.on(",").join(topics.get()))
                      .withLabel("Topic/s"));
    } else {
      builder.add(DisplayData.item("topics", topics).withLabel("Topic/s"));
    }
  } else if (topicPartitions.size() > 0) {
    builder.add(
        DisplayData.item("topicPartitions", Joiner.on(",").join(topicPartitions))
            .withLabel("Topic Partition/s"));
  }
  builder.add(DisplayData.item(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, getBootstrapServers()));
  Set<String> ignoredConsumerPropertiesKeys = IGNORED_CONSUMER_PROPERTIES.keySet();
  for (Map.Entry<String, Object> conf : getConsumerConfig().entrySet()) {
    String key = conf.getKey();
    if (!ignoredConsumerPropertiesKeys.contains(key)) {
      Object value =
          DisplayData.inferType(conf.getValue()) != null
              ? conf.getValue()
              : String.valueOf(conf.getValue());
      builder.add(DisplayData.item(key, ValueProvider.StaticValueProvider.of(value)));
    }
  }
}
 
Example 6
Source File: ProxyInvocationHandler.java    From beam with Apache License 2.0 5 votes vote down vote up
/**
 * Infer the value and {@link DisplayData.Type type} for the given {@link PipelineOptions}
 * value.
 */
static DisplayDataValue resolve(@Nullable Object value) {
  DisplayData.Type type = DisplayData.inferType(value);

  if (type == null) {
    value = displayDataString(value);
    type = DisplayData.Type.STRING;
  }

  return new AutoValue_ProxyInvocationHandler_DisplayDataValue(value, type);
}