public QuantileStateCoder(ComparatorT compareFn, Coder<T> elementCoder) { this.compareFn = compareFn; this.elementCoder = elementCoder; this.elementListCoder = ListCoder.of(elementCoder); }
/** * Ctor requires coder for the element type. * * @param typeCoder coder for the element type */ private CollectionAccumulatorCoder(Coder<T> typeCoder) { this.listCoder = ListCoder.of(typeCoder); }
public BoundedHeapCoder(int maximumSize, ComparatorT compareFn, Coder<T> elementCoder) { listCoder = ListCoder.of(elementCoder); this.compareFn = compareFn; this.maximumSize = maximumSize; }
@Override public Coder<List<T>> getDefaultOutputCoder(CoderRegistry registry, Coder<T> inputCoder) { return ListCoder.of(inputCoder); } }
@Override public Coder<List<T>> getDefaultOutputCoder(CoderRegistry registry, Coder<T> inputCoder) { return ListCoder.of(inputCoder); } }
@Override public Coder<List<T>> getDefaultOutputCoder(CoderRegistry registry, Coder<T> inputCoder) { return ListCoder.of(inputCoder); } }
@Override public Coder<List<T>> getAccumulatorCoder(CoderRegistry registry, Coder<T> inputCoder) { return ListCoder.of(inputCoder); }
@Override public Coder<List<T>> getDefaultOutputCoder(CoderRegistry registry, Coder<T> inputCoder) { return ListCoder.of(inputCoder); } }
public SerializableArrayViaCoder(Coder<T> elementCoder, T[] value) { this.coder = ListCoder.of(elementCoder); this.value = value; try { this.encodedValue = CoderUtils.encodeToByteArray(coder, Arrays.asList(value)); } catch (CoderException exc) { throw UserCodeException.wrap(exc); } }
public Coder<List> getAccumulatorCoder() { AvroCoder valueCoder = null; if (avroSchemaStr != null) { valueCoder = AvroCoder.of(new Schema.Parser().parse(avroSchemaStr)); } return (Coder<List>) (avroSchemaStr == null ? ListCoder.of(NullableCoder.of(StringUtf8Coder.of())) : ListCoder.of(NullableCoder.of(valueCoder))); } }
@Test public void testCoderIsSerializableWithWellKnownCoderType() throws Exception { CoderProperties.coderSerializable(ListCoder.of(GlobalWindow.Coder.INSTANCE)); }
@Test public void testEmptyList() throws Exception { List<Integer> list = Collections.emptyList(); Coder<List<Integer>> coder = ListCoder.of(VarIntCoder.of()); CoderProperties.coderDecodeEncodeEqual(coder, list); }
/** * Tests that {@link MutationDetectors#forValueWithCoder} does not false positive on an list of * arrays, even when some array is set to a deeply equal array that is not {@code equals}. */ @Test public void testEquivalentListOfArrays() throws Exception { List<byte[]> value = Arrays.asList(new byte[] {0x1}, new byte[] {0x2, 0x3}, new byte[] {0x4}); MutationDetector detector = MutationDetectors.forValueWithCoder(value, ListCoder.of(ByteArrayCoder.of())); value.set(0, new byte[] {0x1}); detector.verifyUnmodified(); } }
/** Tests that {@link MutationDetectors#forValueWithCoder} detects a mutation to a list. */ @Test public void testMutatingList() throws Exception { List<Integer> value = Arrays.asList(1, 2, 3, 4); MutationDetector detector = MutationDetectors.forValueWithCoder(value, ListCoder.of(VarIntCoder.of())); value.set(0, 37); thrown.expect(IllegalMutationException.class); detector.verifyUnmodified(); }
@Test public void testListWithNullsAndVarIntCoderThrowsException() throws Exception { thrown.expect(CoderException.class); thrown.expectMessage("cannot encode a null Integer"); List<Integer> list = Arrays.asList(1, 2, 3, null, 4); Coder<List<Integer>> coder = ListCoder.of(VarIntCoder.of()); CoderProperties.coderDecodeEncodeEqual(coder, list); }
/** * Tests that {@link MutationDetectors#forValueWithCoder} does not false positive on a {@link * LinkedList} that will clone as an {@code ArrayList}. */ @Test public void testUnmodifiedLinkedList() throws Exception { List<Integer> value = Lists.newLinkedList(Arrays.asList(1, 2, 3, 4)); MutationDetector detector = MutationDetectors.forValueWithCoder(value, ListCoder.of(VarIntCoder.of())); detector.verifyUnmodified(); }
@Test public void testDefaultCoderInCollection() throws Exception { CoderRegistry registry = CoderRegistry.createDefault(); registry.registerCoderProvider(new DefaultCoderProvider()); Coder<List<AvroRecord>> avroRecordCoder = registry.getCoder(new TypeDescriptor<List<AvroRecord>>() {}); assertThat(avroRecordCoder, instanceOf(ListCoder.class)); assertThat(((ListCoder) avroRecordCoder).getElemCoder(), instanceOf(AvroCoder.class)); assertThat( registry.getCoder(new TypeDescriptor<List<SerializableRecord>>() {}), Matchers.equalTo(ListCoder.of(SerializableCoder.of(SerializableRecord.class)))); }
@Test public void testComponentIncompatibility() throws Exception { thrown.expect(IncompatibleCoderException.class); thrown.expectMessage("component coder is incompatible"); CoderRegistry.verifyCompatible( ListCoder.of(BigEndianIntegerCoder.of()), new TypeDescriptor<List<String>>() {}.getType()); }
@Test public void testListSideInputTranslation() throws Exception { assertEquals( ListCoder.of(KvCoder.of(VoidCoder.of(), VarIntCoder.of())), getTranslatedSideInputCoder(ImmutableList.of(11, 13, 17, 23), View.asList())); }
@Test @Category(ValidatesRunner.class) public void testFlattenIterablesLists() { PCollection<List<String>> input = p.apply(Create.<List<String>>of(LINES).withCoder(ListCoder.of(StringUtf8Coder.of()))); PCollection<String> output = input.apply(Flatten.iterables()); PAssert.that(output).containsInAnyOrder(LINES_ARRAY); p.run(); }