use of org.apache.beam.sdk.values.PCollectionViews.IterableViewFn in project beam by apache.
the class IsmSideInputReader method get.
@Override
public <ViewT> ViewT get(final PCollectionView<ViewT> view, final BoundedWindow window) {
@SuppressWarnings("rawtypes") final TupleTag tag = view.getTagInternal();
checkArgument(tagToIsmReaderMap.containsKey(tag), "calling getSideInput() with unknown view");
// for its use.
try {
ViewFn<?, ?> viewFn = view.getViewFn();
// back to null for the user.
if (viewFn instanceof SingletonViewFn || viewFn instanceof SingletonViewFn2) {
ViewT rval = executionContext.<PCollectionViewWindow<ViewT>, ViewT>getLogicalReferenceCache().get(PCollectionViewWindow.of(view, window), () -> {
@SuppressWarnings("unchecked") ViewT viewT = getSingletonForWindow(tag, (HasDefaultValue<ViewT>) viewFn, window);
@SuppressWarnings("unchecked") ViewT nullPlaceHolder = (ViewT) NULL_PLACE_HOLDER;
return viewT == null ? nullPlaceHolder : viewT;
});
return rval == NULL_PLACE_HOLDER ? null : rval;
} else if (singletonMaterializedTags.contains(tag)) {
checkArgument(viewFn instanceof MapViewFn || viewFn instanceof MapViewFn2 || viewFn instanceof MultimapViewFn || viewFn instanceof MultimapViewFn2, "Unknown view type stored as singleton. Expected one of %s, got %s", KNOWN_SINGLETON_VIEW_TYPES, viewFn.getClass().getName());
return executionContext.<PCollectionViewWindow<ViewT>, ViewT>getLogicalReferenceCache().get(PCollectionViewWindow.of(view, window), () -> {
return getMapSingletonForViewAndWindow(tag, window);
});
} else {
return executionContext.<PCollectionViewWindow<ViewT>, ViewT>getLogicalReferenceCache().get(PCollectionViewWindow.of(view, window), () -> {
if (viewFn instanceof IterableViewFn || viewFn instanceof IterableViewFn2 || viewFn instanceof ListViewFn || viewFn instanceof ListViewFn2) {
@SuppressWarnings("unchecked") ViewT viewT = (ViewT) getListForWindow(tag, window);
return viewT;
} else if (viewFn instanceof MapViewFn || viewFn instanceof MapViewFn2) {
@SuppressWarnings("unchecked") ViewT viewT = (ViewT) getMapForWindow(tag, window);
return viewT;
} else if (viewFn instanceof MultimapViewFn || viewFn instanceof MultimapViewFn2) {
@SuppressWarnings("unchecked") ViewT viewT = (ViewT) getMultimapForWindow(tag, window);
return viewT;
} else if (viewFn instanceof DataflowPortabilityPCollectionView.PortabilityViewFn) {
@SuppressWarnings("unchecked") ViewT viewT = (ViewT) getPortabilityMultimapForWindow(tag, window);
return viewT;
}
throw new IllegalArgumentException("Unknown type of view requested: " + view);
});
}
} catch (ExecutionException e) {
throw new IllegalStateException(String.format("Failed to materialize view %s for window %s.", view, window), e.getCause());
}
}
use of org.apache.beam.sdk.values.PCollectionViews.IterableViewFn in project beam by apache.
the class PTransformMatchersTest method createViewWithViewFnDifferentViewFn.
@Test
public void createViewWithViewFnDifferentViewFn() {
PCollection<Integer> input = p.apply(Create.of(1));
PCollectionView<Iterable<Integer>> view = input.apply(View.asIterable());
// Purposely create a subclass to get a different class then what was expected.
IterableViewFn<Integer> viewFn = new PCollectionViews.IterableViewFn<Integer>(() -> TypeDescriptors.integers()) {
};
CreatePCollectionView<?, ?> createView = CreatePCollectionView.of(view);
PTransformMatcher matcher = PTransformMatchers.createViewWithViewFn(viewFn.getClass());
assertThat(matcher.matches(getAppliedTransform(createView)), is(false));
}
Aggregations