[ https://issues.apache.org/jira/browse/BEAM-6257?focusedWorklogId=218204&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-218204 ]
ASF GitHub Bot logged work on BEAM-6257: ---------------------------------------- Author: ASF GitHub Bot Created on: 25/Mar/19 18:29 Start Date: 25/Mar/19 18:29 Worklog Time Spent: 10m Work Description: ibzib commented on pull request #8094: [BEAM-6257] PAssert.thatSingleton: use GBK instead of side inputs URL: https://github.com/apache/beam/pull/8094#discussion_r268791096 ########## File path: sdks/java/core/src/main/java/org/apache/beam/sdk/testing/PAssert.java ########## @@ -782,6 +782,121 @@ public PCollectionSingletonIterableAssert( } } + /** + * A {@link SingletonAssert} about the contents of a {@link PCollection} when it contains a single + * value of type {@code T}. This does not require the runner to support side inputs. + */ + private static class PCollectionSingletonAssert<T> implements SingletonAssert<T> { + private final PCollection<T> actual; + private final Coder<T> coder; + private final AssertionWindows rewindowingStrategy; + private final SimpleFunction<Iterable<ValueInSingleWindow<T>>, Iterable<T>> paneExtractor; + + private final PAssertionSite site; + + PCollectionSingletonAssert(PCollection<T> actual, PAssertionSite site) { + this(actual, IntoGlobalWindow.of(), PaneExtractors.allPanes(), site); + } + + PCollectionSingletonAssert( + PCollection<T> actual, + AssertionWindows rewindowingStrategy, + SimpleFunction<Iterable<ValueInSingleWindow<T>>, Iterable<T>> paneExtractor, + PAssertionSite site) { + this.actual = actual; + this.coder = actual.getCoder(); + this.rewindowingStrategy = rewindowingStrategy; + this.paneExtractor = paneExtractor; + this.site = site; + } + + @Override + public PCollectionSingletonAssert<T> inFinalPane(BoundedWindow window) { + return withPanes(window, PaneExtractors.finalPane()); + } + + @Override + public PCollectionSingletonAssert<T> inOnTimePane(BoundedWindow window) { + return withPanes(window, PaneExtractors.onTimePane()); + } + + @Override + public PCollectionSingletonAssert<T> inEarlyPane(BoundedWindow window) { + return withPanes(window, PaneExtractors.earlyPanes()); + } + + @Override + public SingletonAssert<T> isEqualTo(T expected) { + return satisfies(new AssertIsEqualToRelation<>(), expected); + } + + @Override + public SingletonAssert<T> notEqualTo(T notExpected) { + return satisfies(new AssertNotEqualToRelation<>(), notExpected); + } + + @Override + public PCollectionSingletonAssert<T> inOnlyPane(BoundedWindow window) { + return withPanes(window, PaneExtractors.onlyPane(site)); + } + + private PCollectionSingletonAssert<T> withPanes( + BoundedWindow window, + SimpleFunction<Iterable<ValueInSingleWindow<T>>, Iterable<T>> paneExtractor) { + @SuppressWarnings({"unchecked", "rawtypes"}) + Coder<BoundedWindow> windowCoder = + (Coder) actual.getWindowingStrategy().getWindowFn().windowCoder(); + return new PCollectionSingletonAssert<>( + actual, IntoStaticWindows.of(windowCoder, window), paneExtractor, site); + } + + @Override + public PCollectionSingletonAssert<T> satisfies(SerializableFunction<T, Void> checkerFn) { + actual.apply( + "PAssert$" + (assertCount++), + new GroupThenAssertForSingleton<>(checkerFn, rewindowingStrategy, paneExtractor, site)); + return this; + } + + /** + * Applies an {@link AssertRelation} to check the provided relation against the value of this + * assert and the provided expected value. + * + * <p>Returns this {@code SingletonAssert}. + */ + private PCollectionSingletonAssert<T> satisfies( + AssertRelation<T, T> relation, final T expected) { + return satisfies(new CheckRelationAgainstExpected<>(relation, expected, coder)); + } + + /** + * @throws UnsupportedOperationException always + * @deprecated {@link Object#equals(Object)} is not supported on PAssert objects. If you meant + * to test object equality, use {@link #isEqualTo} instead. + */ + @SuppressFBWarnings Review comment: fixed ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 218204) Time Spent: 1h 50m (was: 1h 40m) > Can we deprecate the side input paths through PAssert? > ------------------------------------------------------ > > Key: BEAM-6257 > URL: https://issues.apache.org/jira/browse/BEAM-6257 > Project: Beam > Issue Type: Improvement > Components: sdk-java-core > Reporter: Kenneth Knowles > Priority: Major > Labels: starter, triaged > Time Spent: 1h 50m > Remaining Estimate: 0h > > PAssert has two distinct paths - one uses GBK with a single-firing trigger, > and one uses side inputs. Side inputs are usually a later addition to a > runner, while GBK is one of the first primitives (with a single firing it is > even simple). Filing this against myself to figure out why the side input > version is not deprecated, and if it can be deprecated. > Marking this as a "starter" task because finding and eliminating side input > version of PAssert should be fairly easy. You might need help but can ask on > dev@ -- This message was sent by Atlassian JIRA (v7.6.3#76005)