use of org.apache.beam.sdk.options.PipelineOptions in project beam by apache.
the class DirectRunnerTest method getPipeline.
private Pipeline getPipeline() {
PipelineOptions opts = PipelineOptionsFactory.create();
opts.setRunner(DirectRunner.class);
return Pipeline.create(opts);
}
use of org.apache.beam.sdk.options.PipelineOptions in project beam by apache.
the class BigQueryIOTest method testTransformingSourceUnsplittable.
@Test
public void testTransformingSourceUnsplittable() throws Exception {
int numElements = 10000;
@SuppressWarnings("deprecation") BoundedSource<Long> longSource = SourceTestUtils.toUnsplittableSource(CountingSource.upTo(numElements));
SerializableFunction<Long, String> toStringFn = new SerializableFunction<Long, String>() {
@Override
public String apply(Long input) {
return input.toString();
}
};
BoundedSource<String> stringSource = new TransformingSource<>(longSource, toStringFn, StringUtf8Coder.of());
List<String> expected = Lists.newArrayList();
for (int i = 0; i < numElements; i++) {
expected.add(String.valueOf(i));
}
PipelineOptions options = PipelineOptionsFactory.create();
Assert.assertThat(SourceTestUtils.readFromSource(stringSource, options), CoreMatchers.is(expected));
SourceTestUtils.assertSplitAtFractionBehavior(stringSource, 100, 0.3, ExpectedSplitOutcome.MUST_BE_CONSISTENT_IF_SUCCEEDS, options);
SourceTestUtils.assertSourcesEqualReferenceSource(stringSource, stringSource.split(100, options), options);
}
use of org.apache.beam.sdk.options.PipelineOptions in project beam by apache.
the class BigQueryIOTest method testBigQueryTableSourceThroughJsonAPI.
@Test
public void testBigQueryTableSourceThroughJsonAPI() throws Exception {
FakeDatasetService datasetService = new FakeDatasetService();
FakeBigQueryServices fakeBqServices = new FakeBigQueryServices().withJobService(new FakeJobService()).withDatasetService(datasetService);
List<TableRow> expected = ImmutableList.of(new TableRow().set("name", "a").set("number", "1"), new TableRow().set("name", "b").set("number", "2"), new TableRow().set("name", "c").set("number", "3"), new TableRow().set("name", "d").set("number", "4"), new TableRow().set("name", "e").set("number", "5"), new TableRow().set("name", "f").set("number", "6"));
TableReference table = BigQueryHelpers.parseTableSpec("project:data_set.table_name");
datasetService.createDataset(table.getProjectId(), table.getDatasetId(), "", "");
datasetService.createTable(new Table().setTableReference(table));
datasetService.insertAll(table, expected, null);
Path baseDir = Files.createTempDirectory(tempFolder, "testBigQueryTableSourceThroughJsonAPI");
String stepUuid = "testStepUuid";
BoundedSource<TableRow> bqSource = BigQueryTableSource.create(stepUuid, StaticValueProvider.of(table), fakeBqServices);
PipelineOptions options = PipelineOptionsFactory.create();
options.setTempLocation(baseDir.toString());
Assert.assertThat(SourceTestUtils.readFromSource(bqSource, options), CoreMatchers.is(expected));
SourceTestUtils.assertSplitAtFractionBehavior(bqSource, 2, 0.3, ExpectedSplitOutcome.MUST_BE_CONSISTENT_IF_SUCCEEDS, options);
}
use of org.apache.beam.sdk.options.PipelineOptions in project beam by apache.
the class CreateTest method testSourceSplitEmpty.
@Test
public void testSourceSplitEmpty() throws Exception {
CreateSource<Integer> source = CreateSource.fromIterable(ImmutableList.<Integer>of(), BigEndianIntegerCoder.of());
PipelineOptions options = PipelineOptionsFactory.create();
List<? extends BoundedSource<Integer>> splitSources = source.split(12, options);
SourceTestUtils.assertSourcesEqualReferenceSource(source, splitSources, options);
}
use of org.apache.beam.sdk.options.PipelineOptions in project beam by apache.
the class CreateTest method testSourceSplit.
@Test
public void testSourceSplit() throws Exception {
CreateSource<Integer> source = CreateSource.fromIterable(ImmutableList.of(1, 2, 3, 4, 5, 6, 7, 8), BigEndianIntegerCoder.of());
PipelineOptions options = PipelineOptionsFactory.create();
List<? extends BoundedSource<Integer>> splitSources = source.split(12, options);
assertThat(splitSources, hasSize(3));
SourceTestUtils.assertSourcesEqualReferenceSource(source, splitSources, options);
}
Aggregations