private static Coder<?> getAccumulatorCoder(AppliedPTransform<?, ?, ?> transform) throws IOException { SdkComponents sdkComponents = SdkComponents.create(transform.getPipeline().getOptions()); String id = getCombinePayload(transform, sdkComponents) .map(CombinePayload::getAccumulatorCoderId) .orElseThrow(() -> new IOException("Transform does not contain an AccumulatorCoder")); Components components = sdkComponents.toComponents(); return CoderTranslation.fromProto( components.getCodersOrThrow(id), RehydratedComponents.forComponents(components)); }
@Test public void registerCoder() throws IOException { Coder<?> coder = KvCoder.of(StringUtf8Coder.of(), IterableCoder.of(SetCoder.of(ByteArrayCoder.of()))); String id = components.registerCoder(coder); assertThat(components.registerCoder(coder), equalTo(id)); assertThat(id, not(isEmptyOrNullString())); VarLongCoder otherCoder = VarLongCoder.of(); assertThat(components.registerCoder(otherCoder), not(equalTo(id))); components.toComponents().getCodersOrThrow(id); components.toComponents().getCodersOrThrow(components.registerCoder(otherCoder)); }
components.getCodersOrThrow(coderId).getComponentCoderIdsList()) { checkArgument( components.containsCoders(componentCoderId),
equalTo(p.getComponents().getTransformsOrThrow("first"))); assertThat( updated.getComponents().getCodersOrThrow("coder"), equalTo(p.getComponents().getCodersOrThrow("coder"))); assertThat(updated.getRootTransformIdsList(), equalTo(p.getRootTransformIdsList()));
ModelCoders.KvCoderComponents timerKvCoderComponents = ModelCoders.getKvCoderComponents( components.getCodersOrThrow(timerPCollection.getCoderId())); Coder<?> timerKeyCoder = CoderTranslation.fromProto( components.getCodersOrThrow(timerKvCoderComponents.keyCoderId()), rehydratedComponents); assertEquals(VarLongCoder.of(), timerKeyCoder); Coder<?> timerValueCoder = CoderTranslation.fromProto( components.getCodersOrThrow(timerKvCoderComponents.valueCoderId()), rehydratedComponents); assertEquals(
@Test public void registerCoderEqualsNotSame() throws IOException { Coder<?> coder = KvCoder.of(StringUtf8Coder.of(), IterableCoder.of(SetCoder.of(ByteArrayCoder.of()))); Coder<?> otherCoder = KvCoder.of(StringUtf8Coder.of(), IterableCoder.of(SetCoder.of(ByteArrayCoder.of()))); assertThat(coder, equalTo(otherCoder)); String id = components.registerCoder(coder); String otherId = components.registerCoder(otherCoder); assertThat(otherId, not(equalTo(id))); components.toComponents().getCodersOrThrow(id); components.toComponents().getCodersOrThrow(otherId); }