scwhittle commented on code in PR #40543:
URL: https://github.com/apache/beam/pull/40543#discussion_r4695151827
##########
sdks/java/core/src/test/java/org/apache/beam/sdk/io/WriteFilesTest.java:
##########
@@ -422,6 +434,505 @@ public void testWithRunnerDeterminedShardingTestStream()
throws IOException {
getBaseOutputFilename(), elements, Optional.absent(),
!write.getWindowedWrites(), null);
}
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteAllBundlesLarge() throws IOException {
+ runDirectWriteTestStream(1L);
+ }
+
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteAllBundlesSmall() throws IOException {
+ runDirectWriteTestStream(Long.MAX_VALUE);
+ }
+
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteUnshardedMixedBundles() throws IOException {
+ List<String> elements = Lists.newArrayList();
+ for (int i = 0; i < 30; ++i) {
+ elements.add("number: " + i);
+ }
+ Instant startInstant = new Instant(0L);
+ // Two 10-element bundles (~100 bytes each), one 8-element bundle (~88
bytes), and one
+ // 2-element bundle (~22 bytes, < 50) so both direct and auto-sharded
paths run.
+ TestStream<String> testStream =
+ TestStream.create(StringUtf8Coder.of())
+ .advanceWatermarkTo(startInstant)
+ .addElements(elements.get(0),
Iterables.toArray(elements.subList(1, 10), String.class))
+ .advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(5)))
+ .addElements(
+ elements.get(10), Iterables.toArray(elements.subList(11, 20),
String.class))
+
.advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(10)))
+ .addElements(
+ elements.get(20), Iterables.toArray(elements.subList(21, 28),
String.class))
+ .addElements(elements.get(28), elements.get(29))
+ .advanceWatermarkToInfinity();
+
+ WriteFiles<String, Void, String> write =
+ WriteFiles.to(makeSimpleSink())
+ .withWindowedWrites()
+ .withRunnerDeterminedSharding()
+ .withDirectWriteByteThreshold(50L);
+ p.apply(testStream)
+ .apply(Window.into(FixedWindows.of(Duration.standardSeconds(10))))
+ .apply(write)
+ .getPerDestinationOutputFilenames()
+ .apply(new VerifyFilesExist<>());
+ PipelineResult result = p.run();
+
+ checkFileContents(getBaseOutputFilename(), elements, Optional.absent(),
false, null);
+ assertThat(counterValue(result, "directWriteBundles"),
Matchers.greaterThan(0L));
+ }
+
+ @Test
+ @Category(NeedsRunner.class)
+ public void testDirectWriteDisabledForBoundedWithFixedSharding() throws
IOException {
+ List<String> elements = Lists.newArrayList();
+ for (int i = 0; i < 30; ++i) {
+ elements.add("number: " + i);
+ }
+ WriteFiles<String, Void, String> write =
+
WriteFiles.to(makeSimpleSink()).withNumShards(3).withDirectWriteByteThreshold(1L);
+ p.apply(Create.of(elements)).apply(write);
+ PipelineResult result = p.run();
+
+ checkFileContents(getBaseOutputFilename(), elements, Optional.of(3), true,
null);
+ assertEquals(0L, counterValue(result, "directWriteBundles"));
+ }
+
+ @Test
+ @Category(NeedsRunner.class)
+ public void testDirectWriteDisabledForBoundedWithoutFixedSharding() throws
IOException {
+ List<String> elements = Lists.newArrayList();
+ for (int i = 0; i < 30; ++i) {
+ elements.add("number: " + i);
+ }
+ WriteFiles<String, Void, String> write =
+ WriteFiles.to(makeSimpleSink()).withDirectWriteByteThreshold(1L);
+ p.apply(Create.of(elements)).apply(write);
+ PipelineResult result = p.run();
+
+ checkFileContents(getBaseOutputFilename(), elements, Optional.absent(),
false, null);
+ assertEquals(0L, counterValue(result, "directWriteBundles"));
+ }
+
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteNonDefaultTriggerLargeBundles() throws
IOException {
+ runDirectWriteNonDefaultTrigger(1L,
Repeatedly.forever(AfterPane.elementCountAtLeast(5)));
+ }
+
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteNonDefaultTriggerSmallBundles() throws
IOException {
+ runDirectWriteNonDefaultTrigger(
+ Long.MAX_VALUE, Repeatedly.forever(AfterPane.elementCountAtLeast(5)));
+ }
+
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteProcessingTimeTriggerLargeBundles() throws
IOException {
+ runDirectWriteNonDefaultTrigger(
+ 1L,
+ Repeatedly.forever(
+
AfterProcessingTime.pastFirstElementInPane().plusDelayOf(Duration.standardSeconds(1))));
+ }
+
+ private void runDirectWriteNonDefaultTrigger(long thresholdBytes, Trigger
trigger)
+ throws IOException {
+ List<String> elements = Lists.newArrayList();
+ for (int i = 0; i < 30; ++i) {
+ elements.add("number: " + i);
+ }
+ Instant startInstant = new Instant(0L);
+ TestStream<String> testStream =
+ TestStream.create(StringUtf8Coder.of())
+ .advanceWatermarkTo(startInstant)
+ .addElements(elements.get(0),
Iterables.toArray(elements.subList(1, 10), String.class))
+ .advanceProcessingTime(Duration.standardSeconds(2))
+ .advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(5)))
+ .addElements(
+ elements.get(10), Iterables.toArray(elements.subList(11, 20),
String.class))
+ .advanceProcessingTime(Duration.standardSeconds(2))
+
.advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(10)))
+ .addElements(
+ elements.get(20), Iterables.toArray(elements.subList(21, 30),
String.class))
+ .advanceProcessingTime(Duration.standardSeconds(2))
+ .advanceWatermarkToInfinity();
+
+ FilenamePolicy paneAwarePolicy =
+ new PaneAwarePerWindowFiles(
+ getBaseOutputDirectory().resolve("file",
StandardResolveOptions.RESOLVE_FILE),
+ "simple");
+
+ WriteFiles<String, Void, String> write =
+ WriteFiles.to(SimpleSink.makeSimpleSink(getBaseOutputDirectory(),
paneAwarePolicy))
+ .withWindowedWrites()
+ .withNumShards(3)
+ .withDirectWriteByteThreshold(thresholdBytes);
+ p.apply(testStream)
+ .apply(
+ Window.<String>into(FixedWindows.of(Duration.standardSeconds(10)))
+ .triggering(trigger)
+ .discardingFiredPanes()
+ .withAllowedLateness(Duration.standardMinutes(1)))
+ .apply(write)
+ .getPerDestinationOutputFilenames()
+ .apply(new VerifyFilesExist<>());
+ PipelineResult result = p.run();
+
+ checkFileContents(getBaseOutputFilename(), elements, Optional.absent(),
false, null);
+ assertDirectWriteMetrics(result, thresholdBytes);
+ }
+
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteDisabledWithAccumulatingPanes() throws
IOException {
Review Comment:
ditto see if we can verify without actually executing
##########
sdks/java/core/src/test/java/org/apache/beam/sdk/io/WriteFilesTest.java:
##########
@@ -422,6 +434,505 @@ public void testWithRunnerDeterminedShardingTestStream()
throws IOException {
getBaseOutputFilename(), elements, Optional.absent(),
!write.getWindowedWrites(), null);
}
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteAllBundlesLarge() throws IOException {
+ runDirectWriteTestStream(1L);
+ }
+
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteAllBundlesSmall() throws IOException {
+ runDirectWriteTestStream(Long.MAX_VALUE);
+ }
+
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteUnshardedMixedBundles() throws IOException {
+ List<String> elements = Lists.newArrayList();
+ for (int i = 0; i < 30; ++i) {
+ elements.add("number: " + i);
+ }
+ Instant startInstant = new Instant(0L);
+ // Two 10-element bundles (~100 bytes each), one 8-element bundle (~88
bytes), and one
+ // 2-element bundle (~22 bytes, < 50) so both direct and auto-sharded
paths run.
+ TestStream<String> testStream =
+ TestStream.create(StringUtf8Coder.of())
+ .advanceWatermarkTo(startInstant)
+ .addElements(elements.get(0),
Iterables.toArray(elements.subList(1, 10), String.class))
+ .advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(5)))
+ .addElements(
+ elements.get(10), Iterables.toArray(elements.subList(11, 20),
String.class))
+
.advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(10)))
+ .addElements(
+ elements.get(20), Iterables.toArray(elements.subList(21, 28),
String.class))
+ .addElements(elements.get(28), elements.get(29))
+ .advanceWatermarkToInfinity();
+
+ WriteFiles<String, Void, String> write =
+ WriteFiles.to(makeSimpleSink())
+ .withWindowedWrites()
+ .withRunnerDeterminedSharding()
+ .withDirectWriteByteThreshold(50L);
+ p.apply(testStream)
+ .apply(Window.into(FixedWindows.of(Duration.standardSeconds(10))))
+ .apply(write)
+ .getPerDestinationOutputFilenames()
+ .apply(new VerifyFilesExist<>());
+ PipelineResult result = p.run();
+
+ checkFileContents(getBaseOutputFilename(), elements, Optional.absent(),
false, null);
+ assertThat(counterValue(result, "directWriteBundles"),
Matchers.greaterThan(0L));
+ }
+
+ @Test
+ @Category(NeedsRunner.class)
+ public void testDirectWriteDisabledForBoundedWithFixedSharding() throws
IOException {
Review Comment:
is there a way to verify this without actually running the pipeline? just by
examining what the pipeline expands to?
##########
sdks/java/core/src/test/java/org/apache/beam/sdk/io/WriteFilesTest.java:
##########
@@ -422,6 +434,505 @@ public void testWithRunnerDeterminedShardingTestStream()
throws IOException {
getBaseOutputFilename(), elements, Optional.absent(),
!write.getWindowedWrites(), null);
}
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteAllBundlesLarge() throws IOException {
+ runDirectWriteTestStream(1L);
+ }
+
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteAllBundlesSmall() throws IOException {
+ runDirectWriteTestStream(Long.MAX_VALUE);
+ }
+
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteUnshardedMixedBundles() throws IOException {
+ List<String> elements = Lists.newArrayList();
+ for (int i = 0; i < 30; ++i) {
+ elements.add("number: " + i);
+ }
+ Instant startInstant = new Instant(0L);
+ // Two 10-element bundles (~100 bytes each), one 8-element bundle (~88
bytes), and one
+ // 2-element bundle (~22 bytes, < 50) so both direct and auto-sharded
paths run.
+ TestStream<String> testStream =
+ TestStream.create(StringUtf8Coder.of())
+ .advanceWatermarkTo(startInstant)
+ .addElements(elements.get(0),
Iterables.toArray(elements.subList(1, 10), String.class))
+ .advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(5)))
+ .addElements(
+ elements.get(10), Iterables.toArray(elements.subList(11, 20),
String.class))
+
.advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(10)))
+ .addElements(
+ elements.get(20), Iterables.toArray(elements.subList(21, 28),
String.class))
+ .addElements(elements.get(28), elements.get(29))
+ .advanceWatermarkToInfinity();
+
+ WriteFiles<String, Void, String> write =
+ WriteFiles.to(makeSimpleSink())
+ .withWindowedWrites()
+ .withRunnerDeterminedSharding()
+ .withDirectWriteByteThreshold(50L);
+ p.apply(testStream)
+ .apply(Window.into(FixedWindows.of(Duration.standardSeconds(10))))
+ .apply(write)
+ .getPerDestinationOutputFilenames()
+ .apply(new VerifyFilesExist<>());
+ PipelineResult result = p.run();
+
+ checkFileContents(getBaseOutputFilename(), elements, Optional.absent(),
false, null);
+ assertThat(counterValue(result, "directWriteBundles"),
Matchers.greaterThan(0L));
+ }
+
+ @Test
+ @Category(NeedsRunner.class)
+ public void testDirectWriteDisabledForBoundedWithFixedSharding() throws
IOException {
+ List<String> elements = Lists.newArrayList();
+ for (int i = 0; i < 30; ++i) {
+ elements.add("number: " + i);
+ }
+ WriteFiles<String, Void, String> write =
+
WriteFiles.to(makeSimpleSink()).withNumShards(3).withDirectWriteByteThreshold(1L);
+ p.apply(Create.of(elements)).apply(write);
+ PipelineResult result = p.run();
+
+ checkFileContents(getBaseOutputFilename(), elements, Optional.of(3), true,
null);
+ assertEquals(0L, counterValue(result, "directWriteBundles"));
+ }
+
+ @Test
+ @Category(NeedsRunner.class)
+ public void testDirectWriteDisabledForBoundedWithoutFixedSharding() throws
IOException {
Review Comment:
ditto
##########
sdks/java/core/src/test/java/org/apache/beam/sdk/io/WriteFilesTest.java:
##########
@@ -422,6 +434,505 @@ public void testWithRunnerDeterminedShardingTestStream()
throws IOException {
getBaseOutputFilename(), elements, Optional.absent(),
!write.getWindowedWrites(), null);
}
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteAllBundlesLarge() throws IOException {
+ runDirectWriteTestStream(1L);
+ }
+
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteAllBundlesSmall() throws IOException {
+ runDirectWriteTestStream(Long.MAX_VALUE);
+ }
+
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteUnshardedMixedBundles() throws IOException {
+ List<String> elements = Lists.newArrayList();
+ for (int i = 0; i < 30; ++i) {
+ elements.add("number: " + i);
+ }
+ Instant startInstant = new Instant(0L);
+ // Two 10-element bundles (~100 bytes each), one 8-element bundle (~88
bytes), and one
+ // 2-element bundle (~22 bytes, < 50) so both direct and auto-sharded
paths run.
+ TestStream<String> testStream =
+ TestStream.create(StringUtf8Coder.of())
+ .advanceWatermarkTo(startInstant)
+ .addElements(elements.get(0),
Iterables.toArray(elements.subList(1, 10), String.class))
+ .advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(5)))
+ .addElements(
+ elements.get(10), Iterables.toArray(elements.subList(11, 20),
String.class))
+
.advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(10)))
+ .addElements(
+ elements.get(20), Iterables.toArray(elements.subList(21, 28),
String.class))
+ .addElements(elements.get(28), elements.get(29))
+ .advanceWatermarkToInfinity();
+
+ WriteFiles<String, Void, String> write =
+ WriteFiles.to(makeSimpleSink())
+ .withWindowedWrites()
+ .withRunnerDeterminedSharding()
+ .withDirectWriteByteThreshold(50L);
+ p.apply(testStream)
+ .apply(Window.into(FixedWindows.of(Duration.standardSeconds(10))))
+ .apply(write)
+ .getPerDestinationOutputFilenames()
+ .apply(new VerifyFilesExist<>());
+ PipelineResult result = p.run();
+
+ checkFileContents(getBaseOutputFilename(), elements, Optional.absent(),
false, null);
+ assertThat(counterValue(result, "directWriteBundles"),
Matchers.greaterThan(0L));
+ }
+
+ @Test
+ @Category(NeedsRunner.class)
+ public void testDirectWriteDisabledForBoundedWithFixedSharding() throws
IOException {
+ List<String> elements = Lists.newArrayList();
+ for (int i = 0; i < 30; ++i) {
+ elements.add("number: " + i);
+ }
+ WriteFiles<String, Void, String> write =
+
WriteFiles.to(makeSimpleSink()).withNumShards(3).withDirectWriteByteThreshold(1L);
+ p.apply(Create.of(elements)).apply(write);
+ PipelineResult result = p.run();
+
+ checkFileContents(getBaseOutputFilename(), elements, Optional.of(3), true,
null);
+ assertEquals(0L, counterValue(result, "directWriteBundles"));
+ }
+
+ @Test
+ @Category(NeedsRunner.class)
+ public void testDirectWriteDisabledForBoundedWithoutFixedSharding() throws
IOException {
+ List<String> elements = Lists.newArrayList();
+ for (int i = 0; i < 30; ++i) {
+ elements.add("number: " + i);
+ }
+ WriteFiles<String, Void, String> write =
+ WriteFiles.to(makeSimpleSink()).withDirectWriteByteThreshold(1L);
+ p.apply(Create.of(elements)).apply(write);
+ PipelineResult result = p.run();
+
+ checkFileContents(getBaseOutputFilename(), elements, Optional.absent(),
false, null);
+ assertEquals(0L, counterValue(result, "directWriteBundles"));
+ }
+
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteNonDefaultTriggerLargeBundles() throws
IOException {
+ runDirectWriteNonDefaultTrigger(1L,
Repeatedly.forever(AfterPane.elementCountAtLeast(5)));
+ }
+
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteNonDefaultTriggerSmallBundles() throws
IOException {
+ runDirectWriteNonDefaultTrigger(
+ Long.MAX_VALUE, Repeatedly.forever(AfterPane.elementCountAtLeast(5)));
+ }
+
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteProcessingTimeTriggerLargeBundles() throws
IOException {
+ runDirectWriteNonDefaultTrigger(
+ 1L,
+ Repeatedly.forever(
+
AfterProcessingTime.pastFirstElementInPane().plusDelayOf(Duration.standardSeconds(1))));
+ }
+
+ private void runDirectWriteNonDefaultTrigger(long thresholdBytes, Trigger
trigger)
+ throws IOException {
+ List<String> elements = Lists.newArrayList();
+ for (int i = 0; i < 30; ++i) {
+ elements.add("number: " + i);
+ }
+ Instant startInstant = new Instant(0L);
+ TestStream<String> testStream =
+ TestStream.create(StringUtf8Coder.of())
+ .advanceWatermarkTo(startInstant)
+ .addElements(elements.get(0),
Iterables.toArray(elements.subList(1, 10), String.class))
+ .advanceProcessingTime(Duration.standardSeconds(2))
+ .advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(5)))
+ .addElements(
+ elements.get(10), Iterables.toArray(elements.subList(11, 20),
String.class))
+ .advanceProcessingTime(Duration.standardSeconds(2))
+
.advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(10)))
+ .addElements(
+ elements.get(20), Iterables.toArray(elements.subList(21, 30),
String.class))
+ .advanceProcessingTime(Duration.standardSeconds(2))
+ .advanceWatermarkToInfinity();
+
+ FilenamePolicy paneAwarePolicy =
+ new PaneAwarePerWindowFiles(
+ getBaseOutputDirectory().resolve("file",
StandardResolveOptions.RESOLVE_FILE),
+ "simple");
+
+ WriteFiles<String, Void, String> write =
+ WriteFiles.to(SimpleSink.makeSimpleSink(getBaseOutputDirectory(),
paneAwarePolicy))
+ .withWindowedWrites()
+ .withNumShards(3)
+ .withDirectWriteByteThreshold(thresholdBytes);
+ p.apply(testStream)
+ .apply(
+ Window.<String>into(FixedWindows.of(Duration.standardSeconds(10)))
+ .triggering(trigger)
+ .discardingFiredPanes()
+ .withAllowedLateness(Duration.standardMinutes(1)))
+ .apply(write)
+ .getPerDestinationOutputFilenames()
+ .apply(new VerifyFilesExist<>());
+ PipelineResult result = p.run();
+
+ checkFileContents(getBaseOutputFilename(), elements, Optional.absent(),
false, null);
+ assertDirectWriteMetrics(result, thresholdBytes);
+ }
+
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteDisabledWithAccumulatingPanes() throws
IOException {
+ List<String> elements = Lists.newArrayList();
+ for (int i = 0; i < 30; ++i) {
+ elements.add("number: " + i);
+ }
+ Instant startInstant = new Instant(0L);
+ TestStream<String> testStream =
+ TestStream.create(StringUtf8Coder.of())
+ .advanceWatermarkTo(startInstant)
+ .addElements(elements.get(0),
Iterables.toArray(elements.subList(1, 10), String.class))
+ .advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(5)))
+ .addElements(
+ elements.get(10), Iterables.toArray(elements.subList(11, 20),
String.class))
+
.advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(10)))
+ .addElements(
+ elements.get(20), Iterables.toArray(elements.subList(21, 30),
String.class))
+ .advanceWatermarkToInfinity();
+
+ // A 1-byte threshold would otherwise write every bundle directly. The
trigger fires once per
+ // window, so accumulating doesn't repeat records and the file contents
can be checked exactly.
+ WriteFiles<String, Void, String> write =
+ WriteFiles.to(makeSimpleSink())
+ .withWindowedWrites()
+ .withNumShards(3)
+ .withDirectWriteByteThreshold(1L);
+ p.apply(testStream)
+ .apply(
+ Window.<String>into(FixedWindows.of(Duration.standardSeconds(10)))
+ .triggering(AfterWatermark.pastEndOfWindow())
+ .accumulatingFiredPanes()
+ .withAllowedLateness(Duration.ZERO))
+ .apply(write)
+ .getPerDestinationOutputFilenames()
+ .apply(new VerifyFilesExist<>());
+ PipelineResult result = p.run();
+
+ checkFileContents(getBaseOutputFilename(), elements, Optional.absent(),
false, null);
+ assertEquals(0L, counterValue(result, "directWriteBundles"));
+ }
+
+ private static class SideInputDestinations extends
DynamicDestinations<String, String, String> {
+ private final ResourceId baseOutputDirectory;
+ private final PCollectionView<String> sideInputView;
+
+ SideInputDestinations(ResourceId baseOutputDirectory,
PCollectionView<String> sideInputView) {
+ this.baseOutputDirectory = baseOutputDirectory;
+ this.sideInputView = sideInputView;
+ }
+
+ @Override
+ public List<PCollectionView<?>> getSideInputs() {
+ return Collections.singletonList(sideInputView);
+ }
+
+ @Override
+ public String formatRecord(String record) {
+ return record;
+ }
+
+ @Override
+ public String getDestination(String element) {
+ return sideInput(sideInputView);
+ }
+
+ @Override
+ public String getDefaultDestination() {
+ return "file";
+ }
+
+ @Override
+ public FilenamePolicy getFilenamePolicy(String destination) {
+ return new PerWindowFiles(
+ baseOutputDirectory.resolve(destination,
StandardResolveOptions.RESOLVE_FILE), "simple");
+ }
+ }
+
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteWithSideInputs() throws IOException {
+ List<String> elements = Lists.newArrayList();
+ for (int i = 0; i < 30; ++i) {
+ elements.add("number: " + i);
+ }
+ Instant startInstant = new Instant(0L);
+ TestStream<String> testStream =
+ TestStream.create(StringUtf8Coder.of())
+ .advanceWatermarkTo(startInstant)
+ .addElements(elements.get(0),
Iterables.toArray(elements.subList(1, 10), String.class))
+ .advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(5)))
+ .addElements(
+ elements.get(10), Iterables.toArray(elements.subList(11, 20),
String.class))
+
.advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(10)))
+ .addElements(
+ elements.get(20), Iterables.toArray(elements.subList(21, 28),
String.class))
+ .addElements(elements.get(28), elements.get(29))
+ .advanceWatermarkToInfinity();
+
+ PCollectionView<String> sideInputView =
+ p.apply("SideInput", Create.of("file")).apply(View.asSingleton());
+ SideInputDestinations destinations =
+ new SideInputDestinations(getBaseOutputDirectory(), sideInputView);
+ SimpleSink<String> sink =
+ new SimpleSink<>(getBaseOutputDirectory(), destinations,
Compression.UNCOMPRESSED);
+
+ WriteFiles<String, String, String> write =
+ WriteFiles.to(sink)
+ .withWindowedWrites()
+ .withRunnerDeterminedSharding()
+ .withDirectWriteByteThreshold(50L);
+ p.apply(testStream)
+ .apply(Window.into(FixedWindows.of(Duration.standardSeconds(10))))
+ .apply(write)
+ .getPerDestinationOutputFilenames()
+ .apply(new VerifyFilesExist<>());
+ PipelineResult result = p.run();
+
+ checkFileContents(getBaseOutputFilename(), elements, Optional.absent(),
false, null);
+ assertThat(counterValue(result, "directWriteBundles"),
Matchers.greaterThan(0L));
+ }
+
+ @Test
+ @Category({NeedsRunner.class, UsesUnboundedPCollections.class,
UsesTestStream.class})
+ public void testDirectWriteDisabledWithMergingWindows() throws IOException {
+ List<String> elements = Lists.newArrayList();
Review Comment:
ditto
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]