/** Like {@link #via(SerializableFunction)}, but allows access to additional context. */ @Experimental(Experimental.Kind.CONTEXTFUL) public <NewInputT> FlatMapElements<NewInputT, OutputT> via( Contextful<Fn<NewInputT, Iterable<OutputT>>> fn) { return new FlatMapElements<>( fn, fn.getClosure(), TypeDescriptors.inputOf(fn.getClosure()), outputType); }
/** * Like {@link #via(SerializableFunction)}, but supports access to context, such as side inputs. */ @Experimental(Kind.CONTEXTFUL) public <NewInputT> MapElements<NewInputT, OutputT> via(Contextful<Fn<NewInputT, OutputT>> fn) { return new MapElements<>( fn, fn.getClosure(), TypeDescriptors.inputOf(fn.getClosure()), outputType); }
@Override public OutputT formatRecord(UserT record) { try { return ((Fn<UserT, OutputT>) spec.getOutputFn().getClosure()) .apply(record, getContext()); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public DestinationT getDestination(UserT element) { try { return spec.getDestinationFn().getClosure().apply(element, getContext()); } catch (Exception e) { throw new RuntimeException(e); } }
@ProcessElement public void processElement( @Element InputT element, OutputReceiver<OutputT> receiver, ProcessContext c) throws Exception { receiver.output( fn.getClosure().apply(element, Fn.Context.wrapProcessContext(c))); }
final FileNaming namingFn; try { namingFn = spec.getFileNamingFn().getClosure().apply(destination, getContext()); } catch (Exception e) { throw new RuntimeException(e);
private Coder<DestinationT> resolveDestinationCoder(PCollection<UserT> input) { Coder<DestinationT> destinationCoder = getDestinationCoder(); if (destinationCoder == null) { TypeDescriptor<DestinationT> destinationT = TypeDescriptors.outputOf(getDestinationFn().getClosure()); try { destinationCoder = input.getPipeline().getCoderRegistry().getCoder(destinationT); } catch (CannotProvideCoderException e) { throw new IllegalArgumentException( "Unable to infer a coder for destination type (inferred from .by() as \"" + destinationT + "\") - specify it explicitly using .withDestinationCoder()"); } } return destinationCoder; }
private static FileIO.Write.FileNaming resolveFileNaming(FileIO.Write<?, ?> write) throws Exception { return write.resolveFileNamingFn().getClosure().apply(null, null); }
Instant now = Instant.now(); Growth.PollResult<OutputT> res = spec.getPollFn().getClosure().apply(c.element(), wrapProcessContext(c));
getPollFn().getClosure(), PollFn.class, new TypeVariableExtractor<PollFn<InputT, OutputT>, OutputT>() {});
return fn( (element, c) -> { FileNaming naming = getFileNamingFn().getClosure().apply(element, c); return getOutputDirectory() == null ? naming