@Override public PCollectionView<T> expand(PCollection<T> input) { try { GroupByKey.applicableTo(input); } catch (IllegalStateException e) { throw new IllegalStateException("Unable to create a side-input view from input", e); } Combine.Globally<T, T> singletonCombine = Combine.globally(new SingletonCombineFn<>(hasDefault, input.getCoder(), defaultValue)); if (!hasDefault) { singletonCombine = singletonCombine.withoutDefaults(); } return input.apply(singletonCombine.asSingletonView()); } }
@Override public PCollectionView<List<T>> expand(PCollection<T> input) { try { GroupByKey.applicableTo(input); } catch (IllegalStateException e) { throw new IllegalStateException("Unable to create a side-input view from input", e); } PCollection<KV<Void, T>> materializationInput = input.apply(new VoidKeyToMultimapMaterialization<>()); PCollectionView<List<T>> view = PCollectionViews.listView( materializationInput, materializationInput.getWindowingStrategy()); materializationInput.apply(CreatePCollectionView.of(view)); return view; } }
@Override public PCollectionView<Map<K, V>> expand(PCollection<KV<K, V>> input) { try { GroupByKey.applicableTo(input); } catch (IllegalStateException e) { throw new IllegalStateException("Unable to create a side-input view from input", e); } PCollection<KV<Void, KV<K, V>>> materializationInput = input.apply(new VoidKeyToMultimapMaterialization<>()); PCollectionView<Map<K, V>> view = PCollectionViews.mapView( materializationInput, materializationInput.getWindowingStrategy()); materializationInput.apply(CreatePCollectionView.of(view)); return view; } }
@Override public PCollectionView<Iterable<T>> expand(PCollection<T> input) { try { GroupByKey.applicableTo(input); } catch (IllegalStateException e) { throw new IllegalStateException("Unable to create a side-input view from input", e); } PCollection<KV<Void, T>> materializationInput = input.apply(new VoidKeyToMultimapMaterialization<>()); PCollectionView<Iterable<T>> view = PCollectionViews.iterableView( materializationInput, materializationInput.getWindowingStrategy()); materializationInput.apply(CreatePCollectionView.of(view)); return view; } }
@Override public PCollectionView<Map<K, Iterable<V>>> expand(PCollection<KV<K, V>> input) { try { GroupByKey.applicableTo(input); } catch (IllegalStateException e) { throw new IllegalStateException("Unable to create a side-input view from input", e); } PCollection<KV<Void, KV<K, V>>> materializationInput = input.apply(new VoidKeyToMultimapMaterialization<>()); PCollectionView<Map<K, Iterable<V>>> view = PCollectionViews.multimapView( materializationInput, materializationInput.getWindowingStrategy()); materializationInput.apply(CreatePCollectionView.of(view)); return view; } }
@Override public PCollection<KV<K, Iterable<V>>> expand(PCollection<KV<K, V>> input) { applicableTo(input); // Verify that the input Coder<KV<K, V>> is a KvCoder<K, V>, and that // the key coder is deterministic. Coder<K> keyCoder = getKeyCoder(input.getCoder()); try { keyCoder.verifyDeterministic(); } catch (NonDeterministicException e) { throw new IllegalStateException("the keyCoder of a GroupByKey must be deterministic", e); } // This primitive operation groups by the combination of key and window, // merging windows as needed, using the windows assigned to the // key/value input elements and the window merge operation of the // window function associated with the input PCollection. return PCollection.createPrimitiveOutputInternal( input.getPipeline(), updateWindowingStrategy(input.getWindowingStrategy()), input.isBounded(), getOutputKvCoder(input.getCoder())); }