/** * 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); }
@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))); } } } }
@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))); } } } }
@Test public void testKnownTypeInference() { assertEquals(DisplayData.Type.INTEGER, DisplayData.inferType(1234)); assertEquals(DisplayData.Type.INTEGER, DisplayData.inferType(1234L)); assertEquals(DisplayData.Type.FLOAT, DisplayData.inferType(12.3)); assertEquals(DisplayData.Type.FLOAT, DisplayData.inferType(12.3f)); assertEquals(DisplayData.Type.BOOLEAN, DisplayData.inferType(true)); assertEquals(DisplayData.Type.TIMESTAMP, DisplayData.inferType(Instant.now())); assertEquals(DisplayData.Type.DURATION, DisplayData.inferType(Duration.millis(1234))); assertEquals(DisplayData.Type.JAVA_CLASS, DisplayData.inferType(DisplayDataTest.class)); assertEquals(DisplayData.Type.STRING, DisplayData.inferType("hello world")); assertEquals(null, DisplayData.inferType(null)); assertEquals(null, DisplayData.inferType(new Object() {})); }
/** Create a display item for the specified key and {@link ValueProvider}. */ public static ItemSpec<?> item(String key, @Nullable ValueProvider<?> value) { if (value == null) { return item(key, Type.STRING, null); } if (value.isAccessible()) { Object got = value.get(); if (got == null) { return item(key, Type.STRING, null); } Type type = inferType(got); if (type != null) { return item(key, type, got); } } // General case: not null and type not inferable. Fall back to toString of the VP itself. return item(key, Type.STRING, String.valueOf(value)); }
@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))); } } } }
if (!ignoredConsumerPropertiesKeys.contains(key)) { Object value = DisplayData.inferType(conf.getValue()) != null ? conf.getValue() : String.valueOf(conf.getValue());