/** * Returns the default {@code Coder} to use for the output of this single-output {@code * PTransform} when applied to the given input. * * <p>By default, always throws. * * @throws CannotProvideCoderException if none can be inferred. * @deprecated Instead, the PTransform should explicitly call {@link PCollection#setCoder} on the * returned PCollection. */ @Deprecated protected Coder<?> getDefaultOutputCoder(@SuppressWarnings("unused") InputT input) throws CannotProvideCoderException { return getDefaultOutputCoder(); }
/** * Returns the default {@code Coder} to use for the given output of this single-output {@code * PTransform} when applied to the given input. * * <p>By default, always throws. * * @throws CannotProvideCoderException if none can be inferred. * @deprecated Instead, the PTransform should explicitly call {@link PCollection#setCoder} on the * returned PCollection. */ @Deprecated public <T> Coder<T> getDefaultOutputCoder( InputT input, @SuppressWarnings("unused") PCollection<T> output) throws CannotProvideCoderException { @SuppressWarnings("unchecked") Coder<T> defaultOutputCoder = (Coder<T>) getDefaultOutputCoder(input); return defaultOutputCoder; }
@Override public OutputT expand(InputT input) { OutputT res = delegate().expand(input); if (res instanceof PCollection) { PCollection pc = (PCollection) res; try { pc.setCoder(delegate().getDefaultOutputCoder(input, pc)); } catch (CannotProvideCoderException e) { // Let coder inference happen later. } } return res; }
try { return new CoderOrFailure<>( ((PTransform) transform).getDefaultOutputCoder(input, this), null); } catch (CannotProvideCoderException exc) { inputCoderException = exc;
@Test public void getDefaultOutputCoderDelegates() throws Exception { @SuppressWarnings("unchecked") PCollection<Integer> input = PCollection.createPrimitiveOutputInternal( null /* pipeline */, WindowingStrategy.globalDefault(), PCollection.IsBounded.BOUNDED, null /* coder */); @SuppressWarnings("unchecked") PCollection<String> output = PCollection.createPrimitiveOutputInternal( null /* pipeline */, WindowingStrategy.globalDefault(), PCollection.IsBounded.BOUNDED, null /* coder */); @SuppressWarnings("unchecked") Coder<String> outputCoder = mock(Coder.class); when(delegate.expand(input)).thenReturn(output); when(delegate.getDefaultOutputCoder(input, output)).thenReturn(outputCoder); assertThat(forwarding.expand(input).getCoder(), equalTo(outputCoder)); }