Java Code Examples for org.apache.beam.sdk.transforms.display.DisplayData#Item
The following examples show how to use
org.apache.beam.sdk.transforms.display.DisplayData#Item .
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: DisplayDataTranslation.java From beam with Apache License 2.0 | 6 votes |
public static List<RunnerApi.DisplayData> toProto(DisplayData displayData) { ImmutableList.Builder<RunnerApi.DisplayData> builder = ImmutableList.builder(); for (DisplayData.Item item : displayData.items()) { Function<DisplayData.Item, ByteString> translator = WELL_KNOWN_URN_TRANSLATORS.get(item.getKey()); String urn; if (translator != null) { urn = item.getKey(); } else { urn = LABELLED_STRING; translator = DisplayDataTranslation::translateStringUtf8; } builder.add( RunnerApi.DisplayData.newBuilder() .setUrn(urn) .setPayload(translator.apply(item)) .build()); } return builder.build(); }
Example 2
Source File: ProxyInvocationHandler.java From beam with Apache License 2.0 | 5 votes |
@Override public void serialize(PipelineOptions value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { ProxyInvocationHandler handler = (ProxyInvocationHandler) Proxy.getInvocationHandler(value); synchronized (handler) { // We first filter out any properties that have been modified since // the last serialization of this PipelineOptions and then verify that // they are all serializable. Map<String, BoundValue> filteredOptions = Maps.newHashMap(handler.options); PipelineOptionsFactory.Cache cache = PipelineOptionsFactory.CACHE.get(); removeIgnoredOptions(cache, handler.knownInterfaces, filteredOptions); ensureSerializable(cache, handler.knownInterfaces, filteredOptions); // Now we create the map of serializable options by taking the original // set of serialized options (if any) and updating them with any properties // instances that have been modified since the previous serialization. Map<String, Object> serializableOptions = Maps.newHashMap(handler.jsonOptions); for (Map.Entry<String, BoundValue> entry : filteredOptions.entrySet()) { serializableOptions.put(entry.getKey(), entry.getValue().getValue()); } jgen.writeStartObject(); jgen.writeFieldName("options"); jgen.writeObject(serializableOptions); List<Map<String, Object>> serializedDisplayData = Lists.newArrayList(); DisplayData displayData = DisplayData.from(value); for (DisplayData.Item item : displayData.items()) { @SuppressWarnings("unchecked") Map<String, Object> serializedItem = PipelineOptionsFactory.MAPPER.convertValue(item, Map.class); serializedDisplayData.add(serializedItem); } jgen.writeFieldName("display_data"); jgen.writeObject(serializedDisplayData); jgen.writeEndObject(); } }
Example 3
Source File: DisplayDataTranslation.java From beam with Apache License 2.0 | 5 votes |
private static ByteString translateStringUtf8(DisplayData.Item item) { String value = String.valueOf(item.getValue() == null ? item.getShortValue() : item.getValue()); String label = item.getLabel() == null ? item.getKey() : item.getLabel(); return RunnerApi.LabelledStringPayload.newBuilder() .setLabel(label) .setValue(value) .build() .toByteString(); }