private GroupedValues( GlobalCombineFn<? super InputT, ?, OutputT> fn, DisplayData.ItemSpec<? extends Class<?>> fnDisplayData, List<PCollectionView<?>> sideInputs) { this.fn = SerializableUtils.clone(fn); this.fnDisplayData = fnDisplayData; this.sideInputs = sideInputs; }
public static <InT, OutT extends Serializable> SerializableFunction<InT, OutT> clonesOf( final OutT base) { return input -> SerializableUtils.clone(base); }
public static <T extends Serializable> T ensureSerializable(T value) { return clone(value); }
private GroupedValues( GlobalCombineFn<? super InputT, ?, OutputT> fn, DisplayData.ItemSpec<? extends Class<?>> fnDisplayData) { this.fn = SerializableUtils.clone(fn); this.fnDisplayData = fnDisplayData; this.sideInputs = ImmutableList.of(); }
@VisibleForTesting static <T> byte[] encode(Coder<T> coder, Coder.Context context, T value) throws CoderException, IOException { @SuppressWarnings("unchecked") Coder<T> deserializedCoder = SerializableUtils.clone(coder); ByteArrayOutputStream os = new ByteArrayOutputStream(); deserializedCoder.encode(value, new UnownedOutputStream(os), context); return os.toByteArray(); }
public static <K, InputT, AccumT, OutputT> AppliedCombineFn<K, InputT, AccumT, OutputT> withAccumulatorCoder( GlobalCombineFn<? super InputT, AccumT, OutputT> fn, Coder<AccumT> accumCoder, Iterable<PCollectionView<?>> sideInputViews, KvCoder<K, InputT> kvCoder, WindowingStrategy<?, ?> windowingStrategy) { // Casting down the K and InputT is safe because they're only used as inputs. @SuppressWarnings("unchecked") GlobalCombineFn<InputT, AccumT, OutputT> clonedFn = (GlobalCombineFn<InputT, AccumT, OutputT>) SerializableUtils.clone(fn); return create(clonedFn, accumCoder, sideInputViews, kvCoder, windowingStrategy); }
public static <K, InputT, AccumT, OutputT> AppliedCombineFn<K, InputT, AccumT, OutputT> withInputCoder( GlobalCombineFn<? super InputT, AccumT, OutputT> fn, CoderRegistry registry, KvCoder<K, InputT> kvCoder, Iterable<PCollectionView<?>> sideInputViews, WindowingStrategy<?, ?> windowingStrategy) { // Casting down the K and InputT is safe because they're only used as inputs. @SuppressWarnings("unchecked") GlobalCombineFn<InputT, AccumT, OutputT> clonedFn = (GlobalCombineFn<InputT, AccumT, OutputT>) SerializableUtils.clone(fn); try { Coder<AccumT> accumulatorCoder = clonedFn.getAccumulatorCoder(registry, kvCoder.getValueCoder()); return create(clonedFn, accumulatorCoder, sideInputViews, kvCoder, windowingStrategy); } catch (CannotProvideCoderException e) { throw new IllegalStateException("Could not determine coder for accumulator", e); } }
private RowCoder(Schema schema, UUID id) { if (schema.getUUID() != null) { checkArgument( schema.getUUID().equals(id), "Schema has a UUID that doesn't match argument to constructor. %s v.s. %s", schema.getUUID(), id); } else { schema = SerializableUtils.clone(schema); schema.setUUID(id); } this.schema = schema; this.id = id; }
@Test public void testOptionsAreNotSerializable() { expectedException.expectCause(Matchers.instanceOf(NotSerializableException.class)); SerializableUtils.clone(new CapturesOptions()); }
@Test public void testSerializable() { DisplayData data = DisplayData.from( new HasDisplayData() { @Override public void populateDisplayData(DisplayData.Builder builder) { builder.add(DisplayData.item("foo", "bar")); } }); DisplayData serData = SerializableUtils.clone(data); assertEquals(data, serData); }
@Test public void getAfterSerialization() { WindowSupplier supplier = WindowSupplier.of(IntervalWindow.getCoder(), ImmutableList.of(window, otherWindow)); assertThat( SerializableUtils.clone(supplier).get(), Matchers.containsInAnyOrder(otherWindow, window)); }
@Test public void testSerializableCoderConstruction() throws Exception { SerializableCoder<MyRecord> coder = SerializableCoder.of(MyRecord.class); assertEquals(coder.getRecordType(), MyRecord.class); CoderProperties.coderSerializable(coder); SerializableCoder<?> decoded = SerializableUtils.clone(coder); assertThat(decoded.getRecordType(), Matchers.<Object>equalTo(MyRecord.class)); }
@Test public void testEncodeDecodeAfterClone() throws Exception { JAXBCoder<TestType> coder = SerializableUtils.clone(JAXBCoder.of(TestType.class)); byte[] encoded = CoderUtils.encodeToByteArray(coder, new TestType("abc", 9999)); assertEquals(new TestType("abc", 9999), CoderUtils.decodeFromByteArray(coder, encoded)); }
@Test public void testDeflateCodecSerDeWithLevels() throws Exception { for (int i = 0; i < 10; ++i) { SerializableAvroCodecFactory codecFactory = new SerializableAvroCodecFactory(CodecFactory.deflateCodec(i)); SerializableAvroCodecFactory serdeC = SerializableUtils.clone(codecFactory); assertEquals(CodecFactory.deflateCodec(i).toString(), serdeC.getCodec().toString()); } }
@Test public void testXZCodecSerDeWithLevels() throws Exception { for (int i = 0; i < 10; ++i) { SerializableAvroCodecFactory codecFactory = new SerializableAvroCodecFactory(CodecFactory.xzCodec(i)); SerializableAvroCodecFactory serdeC = SerializableUtils.clone(codecFactory); assertEquals(CodecFactory.xzCodec(i).toString(), serdeC.getCodec().toString()); } }
@Test public void testDefaultCodecsSerDe() throws Exception { for (String codec : avroCodecs) { SerializableAvroCodecFactory codecFactory = new SerializableAvroCodecFactory(CodecFactory.fromString(codec)); SerializableAvroCodecFactory serdeC = SerializableUtils.clone(codecFactory); assertEquals(CodecFactory.fromString(codec).toString(), serdeC.getCodec().toString()); } }
@Test public void testAvroCoderEncoding() throws Exception { AvroCoder<Pojo> coder = AvroCoder.of(Pojo.class); CoderProperties.coderSerializable(coder); AvroCoder<Pojo> copy = SerializableUtils.clone(coder); Pojo pojo = new Pojo("foo", 3); Pojo equalPojo = new Pojo("foo", 3); Pojo otherPojo = new Pojo("bar", -19); CoderProperties.coderConsistentWithEquals(coder, pojo, equalPojo); CoderProperties.coderConsistentWithEquals(copy, pojo, equalPojo); CoderProperties.coderConsistentWithEquals(coder, pojo, otherPojo); CoderProperties.coderConsistentWithEquals(copy, pojo, otherPojo); }
@Test @SuppressWarnings("unchecked") public void testWriteWithSerDeCustomXZCodec() throws Exception { AvroIO.Write<String> write = AvroIO.write(String.class).to("/tmp/foo/baz").withCodec(CodecFactory.xzCodec(9)); assertEquals( CodecFactory.xzCodec(9).toString(), SerializableUtils.clone(write.inner.getCodec()).getCodec().toString()); }
@Test @SuppressWarnings("unchecked") public void testWriteWithSerDeCustomDeflateCodec() throws Exception { AvroIO.Write<String> write = AvroIO.write(String.class).to("/tmp/foo/baz").withCodec(CodecFactory.deflateCodec(9)); assertEquals( CodecFactory.deflateCodec(9).toString(), SerializableUtils.clone(write.inner.getCodec()).getCodec().toString()); }
@Test public void testSerializationAndDeserialization() throws Exception { PipelineOptions options = PipelineOptionsFactory.fromArgs("--foo=testValue", "--ignoredField=overridden") .as(MyOptions.class); SerializablePipelineOptions serializableOptions = new SerializablePipelineOptions(options); assertEquals("testValue", serializableOptions.get().as(MyOptions.class).getFoo()); assertEquals("overridden", serializableOptions.get().as(MyOptions.class).getIgnoredField()); SerializablePipelineOptions copy = SerializableUtils.clone(serializableOptions); assertEquals("testValue", copy.get().as(MyOptions.class).getFoo()); assertEquals("not overridden", copy.get().as(MyOptions.class).getIgnoredField()); }