@ProcessElement public void processElement(ProcessContext c) throws Exception { Instant timestamp = Instant.now(); Random random = new Random(); if (random.nextDouble() < THRESHOLD) { int range = MAX_DELAY - MIN_DELAY; int delayInMinutes = random.nextInt(range) + MIN_DELAY; long delayInMillis = TimeUnit.MINUTES.toMillis(delayInMinutes); timestamp = new Instant(timestamp.getMillis() - delayInMillis); } c.outputWithTimestamp(c.element(), timestamp); } }
@ProcessElement public void processElement(ProcessContext c) { // Generate a timestamp that falls somewhere in the past RAND_RANGE hours. long randMillis = (long) (Math.random() * RAND_RANGE.getMillis()); // Instant randomTimestamp = minTimestamp.plus(randMillis); Instant randomTimestamp = minTimestamp.minus(randMillis); // Concept #2: Set the data element with that timestamp. c.outputWithTimestamp(c.element(), new Instant(randomTimestamp)); } }
@ProcessElement public void processElement(ProcessContext c) { List<String> words = Splitter.onPattern("[^a-zA-Z0-9']+").splitToList(c.element()); if (words.size() == 2) { c.outputWithTimestamp(words.get(0), new Instant(Long.parseLong(words.get(1)))); } } }
@Override public <T> void outputWithTimestamp(TupleTag<T> tag, T output, Instant timestamp) { outerContext.outputWithTimestamp(tag, output, timestamp); }
@ProcessElement public void processElement(DoFn<String, String>.ProcessContext c) throws Exception { String[] items = c.element().split(","); String timestamp = tryParseTimestamp(items); if (timestamp != null) { try { c.outputWithTimestamp(c.element(), new Instant(dateTimeFormat.parseMillis(timestamp))); } catch (IllegalArgumentException e) { // Skip the invalid input. } } } }
@Override public void outputWithTimestamp(OutputT output, Instant timestamp) { outerContext.outputWithTimestamp(output, timestamp); }
@ProcessElement public void processElement(ProcessContext c) { Tuple2<Long, String> t = c.element(); c.outputWithTimestamp(Tuple2.of(t.f0, t.f1), new Instant(t.f0)); } }))
@ProcessElement public void processElement(ProcessContext c) throws Exception { TableRow row = c.element(); long timestamp = (Integer) row.get("timestamp"); String userName = (String) row.get("contributor_username"); if (userName != null) { // Sets the timestamp field to be used in windowing. c.outputWithTimestamp(userName, new Instant(timestamp * 1000L)); } } }))
@ProcessElement public void processElement(DoFn<String, String>.ProcessContext c) throws Exception { String[] items = c.element().split(",", -1); if (items.length > 0) { try { String timestamp = items[0]; c.outputWithTimestamp(c.element(), new Instant(dateTimeFormat.parseMillis(timestamp))); } catch (IllegalArgumentException e) { // Skip the invalid input. } } } }
@ProcessElement public void readSoruce(ProcessContext ctxt) throws IOException { BoundedSource.BoundedReader<T> reader = ctxt.element().createReader(ctxt.getPipelineOptions()); for (boolean more = reader.start(); more; more = reader.advance()) { ctxt.outputWithTimestamp(reader.getCurrent(), reader.getCurrentTimestamp()); } } }
@ProcessElement public void processElement(ProcessContext context) { context.outputWithTimestamp(context.element(), context.timestamp().minus(context.element())); }
@ProcessElement public void reassignTimestamps( ProcessContext context, @Element Long element) { // Shift the latest element as far backwards in time as the model permits context.outputWithTimestamp(element, BoundedWindow.TIMESTAMP_MIN_VALUE); }
@ProcessElement public void processElement(ProcessContext c) { KV<Integer, String> record = c.element(); int timestamp = record.getKey(); String userName = record.getValue(); if (userName != null) { // Sets the implicit timestamp field to be used in windowing. c.outputWithTimestamp(userName, new Instant(timestamp)); } } }
@ProcessElement public void processElement(ProcessContext c) throws Exception { TableRow row = c.element(); long timestamp = (Integer) row.get("timestamp"); String userName = (String) row.get("contributor_username"); if (userName != null) { // Sets the timestamp field to be used in windowing. c.outputWithTimestamp(userName, new Instant(timestamp * 1000L)); } } }))
@ProcessElement public void processElement(ProcessContext c) { c.outputWithTimestamp( new PubsubMessage(c.element().getBytes(StandardCharsets.UTF_8), attributes), new Instant(TIMESTAMP)); } }
@ProcessElement public void processElement(ProcessContext c) throws Exception { TableRow row = c.element(); long timestamp = (Integer) row.get("timestamp"); String userName = (String) row.get("contributor_username"); if (userName != null) { // Sets the timestamp field to be used in windowing. c.outputWithTimestamp(userName, new Instant(timestamp * 1000L)); } } }))
@ProcessElement public void processElement(ProcessContext c) { KV<Integer, String> record = c.element(); int timestamp = record.getKey(); String userName = record.getValue(); if (userName != null) { // Sets the implicit timestamp field to be used in windowing. c.outputWithTimestamp(userName, new Instant(timestamp)); } } }
@ProcessElement public void processElement(ProcessContext c) { KV<Integer, String> record = c.element(); int timestamp = record.getKey(); String userName = record.getValue(); if (userName != null) { // Sets the implicit timestamp field to be used in windowing. c.outputWithTimestamp(userName, new Instant(timestamp)); } } }
@Override public void outputWithTimestamp(OutputT output, Instant timestamp) { outerContext.outputWithTimestamp(output, timestamp); } };
@ProcessElement public void processElement(ProcessContext c) throws Exception { checkState(state == LifecycleState.INSIDE_BUNDLE, "Wrong state: %s", state); agg.inc(c.element()); Instant instant = new Instant(1000L * c.element()); c.outputWithTimestamp(c.element().toString(), instant); }