FullWindowedValueCoder(Coder<T> valueCoder, Coder<? extends BoundedWindow> windowCoder) { super(valueCoder); this.windowCoder = checkNotNull(windowCoder); // It's not possible to statically type-check correct use of the // windowCoder (we have to ensure externally that we only get // windows of the class handled by windowCoder), so type // windowsCoder in a way that makes encode() and decode() work // right, and cast the window type away here. @SuppressWarnings({"unchecked", "rawtypes"}) Coder<Collection<? extends BoundedWindow>> collectionCoder = (Coder) CollectionCoder.of(this.windowCoder); this.windowsCoder = collectionCoder; }
public static <T> CollectionCoder<T> of(Coder<T> elemCoder) { return new CollectionCoder<>(elemCoder); }
@Override public TypeDescriptor<Collection<T>> getEncodedTypeDescriptor() { return new TypeDescriptor<Collection<T>>() {}.where( new TypeParameter<T>() {}, getElemCoder().getEncodedTypeDescriptor()); } }
@Test public void testCoderIsSerializableWithWellKnownCoderType() throws Exception { CoderProperties.coderSerializable(CollectionCoder.of(GlobalWindow.Coder.INSTANCE)); }
return SetCoder.of(inferCoderFromObjects(coderRegistry, schemaRegistry, ((Iterable) o))); } else if (o instanceof Collection) { return CollectionCoder.of( inferCoderFromObjects(coderRegistry, schemaRegistry, ((Iterable) o))); } else if (o instanceof Iterable) {
@Test @Category(ValidatesRunner.class) public void testFlattenIterablesCollections() { Set<String> linesSet = ImmutableSet.copyOf(LINES); PCollection<Collection<String>> input = p.apply( Create.<Collection<String>>of(linesSet) .withCoder(CollectionCoder.of(StringUtf8Coder.of()))); PCollection<String> output = input.apply(Flatten.iterables()); PAssert.that(output).containsInAnyOrder(LINES_ARRAY); p.run(); }
.add(SerializableCoder.of(Record.class)) .add(AvroCoder.of(Record.class)) .add(CollectionCoder.of(VarLongCoder.of())) .add(ListCoder.of(VarLongCoder.of())) .add(SetCoder.of(VarLongCoder.of()))