Refine search
@ProcessElement public void processElement(ProcessContext ctx) { GenericRecord genericRecord = ctx.element(); Schema schema = new Schema.Parser().parse(schemaJson); StringBuilder row = new StringBuilder(); for (Schema.Field field : schema.getFields()) { String fieldType = field.schema().getType().toString().toLowerCase(); if (!acceptedTypes.contains(fieldType)) { LOG.error("Data transformation doesn't support: " + fieldType); throw new IllegalArgumentException("Field type " + fieldType + " is not supported."); } if (row.length() > 0) { row.append(delimiter); } row.append(genericRecord.get(field.name())); } ctx.output(row.toString()); } }
@ProcessElement public void processElement(ProcessContext c) { String[] columns = c.element().split(DELIMITER); try { Long singerId = Long.parseLong(columns[0].trim()); Long albumId = Long.parseLong(columns[1].trim()); String albumTitle = columns[2].trim(); c.output(new Album(singerId, albumId, albumTitle)); } catch (ArrayIndexOutOfBoundsException | NumberFormatException e) { LOG.info("ParseAlbum: parse error on '" + c.element() + "': " + e.getMessage()); } } }
@ProcessElement public void processElement(ProcessContext c) { String[] columns = c.element().split(DELIMITER); try { Long singerId = Long.parseLong(columns[0].trim()); String firstName = columns[1].trim(); String lastName = columns[2].trim(); c.output(new Singer(singerId, firstName, lastName)); } catch (ArrayIndexOutOfBoundsException | NumberFormatException e) { LOG.info("ParseSinger: parse error on '" + c.element() + "': " + e.getMessage()); } } }
@ProcessElement public void processElement(ProcessContext c) { KV<KV<String, String>, KV<Double, Integer>> result = c.element(); String call1 = result.getKey().getKey(); String call2 = result.getKey().getValue(); Double sumOfRatios = result.getValue().getKey(); int numberOfRatios = result.getValue().getValue(); c.output(Joiner.on('\t').join(call1, call2, sumOfRatios / numberOfRatios, sumOfRatios, numberOfRatios)); } }
@ProcessElement public void processElement(ProcessContext c) { KV<K, Iterable<WindowedValue<V>>> kvs = c.element(); K key = kvs.getKey(); Iterable<WindowedValue<V>> unsortedValues = kvs.getValue(); List<WindowedValue<V>> sortedValues = new ArrayList<>(); for (WindowedValue<V> value : unsortedValues) { sortedValues.add(value); } sortedValues.sort(Comparator.comparing(WindowedValue::getTimestamp)); c.output(KV.of(key, sortedValues)); } }))
@ProcessElement public void processElement(ProcessContext c, BoundedWindow window) { StringBuilder str = new StringBuilder(); KV<String, List<CompletionCandidate>> elem = c.element(); str.append(elem.getKey() + " @ " + window + " -> "); for (CompletionCandidate cand: elem.getValue()) { str.append(cand.toString() + " "); } System.out.println(str.toString()); c.output(str.toString()); } }