use of org.apache.beam.sdk.options.PipelineOptions in project beam by apache.
the class TextIOTest method testInitialSplitAutoModeGz.
@Test
public void testInitialSplitAutoModeGz() throws Exception {
long desiredBundleSize = 1000;
PipelineOptions options = TestPipeline.testingPipelineOptions();
// Sanity check: file is at least 2 bundles long.
assertThat(largeGz.length(), greaterThan(2 * desiredBundleSize));
FileBasedSource<String> source = TextIO.read().from(largeGz.getPath()).getSource();
List<? extends FileBasedSource<String>> splits = source.split(desiredBundleSize, options);
// Exactly 1 split, even in AUTO mode, since it is a gzip file.
assertThat(splits, hasSize(equalTo(1)));
SourceTestUtils.assertSourcesEqualReferenceSource(source, splits, options);
}
use of org.apache.beam.sdk.options.PipelineOptions in project beam by apache.
the class ForwardingPTransformTest method validateDelegates.
@Test
public void validateDelegates() {
@SuppressWarnings("unchecked") PipelineOptions options = Mockito.mock(PipelineOptions.class);
Mockito.doThrow(RuntimeException.class).when(delegate).validate(options);
thrown.expect(RuntimeException.class);
forwarding.validate(options);
}
use of org.apache.beam.sdk.options.PipelineOptions in project beam by apache.
the class FlinkPartialReduceFunction method combine.
@Override
public void combine(Iterable<WindowedValue<KV<K, InputT>>> elements, Collector<WindowedValue<KV<K, AccumT>>> out) throws Exception {
PipelineOptions options = serializedOptions.getPipelineOptions();
FlinkSideInputReader sideInputReader = new FlinkSideInputReader(sideInputs, getRuntimeContext());
AbstractFlinkCombineRunner<K, InputT, AccumT, AccumT, W> reduceRunner;
if (!windowingStrategy.getWindowFn().isNonMerging() && !windowingStrategy.getWindowFn().windowCoder().equals(IntervalWindow.getCoder())) {
reduceRunner = new HashingFlinkCombineRunner<>();
} else {
reduceRunner = new SortingFlinkCombineRunner<>();
}
reduceRunner.combine(new AbstractFlinkCombineRunner.PartialFlinkCombiner<K, InputT, AccumT>(combineFn), windowingStrategy, sideInputReader, options, elements, out);
}
use of org.apache.beam.sdk.options.PipelineOptions in project beam by apache.
the class OffsetBasedSourceTest method testProgressEmptySource.
@Test
public void testProgressEmptySource() throws IOException {
PipelineOptions options = PipelineOptionsFactory.create();
CoarseRangeSource source = new CoarseRangeSource(13, 17, 1, 100);
try (OffsetBasedReader<Integer> reader = source.createReader(options)) {
// before starting
assertEquals(0.0, reader.getFractionConsumed(), 1e-6);
assertEquals(0, reader.getSplitPointsConsumed());
assertEquals(BoundedReader.SPLIT_POINTS_UNKNOWN, reader.getSplitPointsRemaining());
// confirm empty
assertFalse(reader.start());
// after reading empty source
assertEquals(1.0, reader.getFractionConsumed(), 1e-6);
assertEquals(0, reader.getSplitPointsConsumed());
assertEquals(0, reader.getSplitPointsRemaining());
}
}
use of org.apache.beam.sdk.options.PipelineOptions in project beam by apache.
the class CompressedSourceTest method testSplittableProgress.
@Test
public void testSplittableProgress() throws IOException {
File tmpFile = tmpFolder.newFile("nonempty.txt");
String filename = tmpFile.toPath().toString();
Files.write(new byte[2], tmpFile);
PipelineOptions options = PipelineOptionsFactory.create();
CompressedSource<Byte> source = CompressedSource.from(new ByteSource(filename, 1));
try (BoundedReader<Byte> readerOrig = source.createReader(options)) {
assertThat(readerOrig, not(instanceOf(CompressedReader.class)));
assertThat(readerOrig, instanceOf(FileBasedReader.class));
FileBasedReader<Byte> reader = (FileBasedReader<Byte>) readerOrig;
// Check preconditions before starting
assertEquals(0.0, reader.getFractionConsumed(), 1e-6);
assertEquals(0, reader.getSplitPointsConsumed());
assertEquals(BoundedReader.SPLIT_POINTS_UNKNOWN, reader.getSplitPointsRemaining());
// First record: none consumed, unknown remaining.
assertTrue(reader.start());
assertEquals(0, reader.getSplitPointsConsumed());
assertEquals(BoundedReader.SPLIT_POINTS_UNKNOWN, reader.getSplitPointsRemaining());
// Second record: 1 consumed, know that we're on the last record.
assertTrue(reader.advance());
assertEquals(1, reader.getSplitPointsConsumed());
assertEquals(1, reader.getSplitPointsRemaining());
// Confirm empty and check post-conditions
assertFalse(reader.advance());
assertEquals(1.0, reader.getFractionConsumed(), 1e-6);
assertEquals(2, reader.getSplitPointsConsumed());
assertEquals(0, reader.getSplitPointsRemaining());
}
}
Aggregations