use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Supplier in project beam by apache.
the class PubsubReadIT method testReadPublicData.
@Test
public void testReadPublicData() throws Exception {
// The pipeline will never terminate on its own
pipeline.getOptions().as(TestPipelineOptions.class).setBlockOnRun(false);
PCollection<String> messages = pipeline.apply(PubsubIO.readStrings().fromTopic("projects/pubsub-public-data/topics/taxirides-realtime"));
messages.apply("waitForAnyMessage", signal.signalSuccessWhen(messages.getCoder(), anyMessages -> true));
Supplier<Void> start = signal.waitForStart(Duration.standardMinutes(5));
pipeline.apply(signal.signalStart());
PipelineResult job = pipeline.run();
start.get();
signal.waitForSuccess(Duration.standardMinutes(5));
// A runner may not support cancel
try {
job.cancel();
} catch (UnsupportedOperationException exc) {
// noop
}
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Supplier in project beam by apache.
the class BigQuerySourceBase method createSources.
List<BoundedSource<T>> createSources(List<ResourceId> files, TableSchema schema, List<MatchResult.Metadata> metadata) throws IOException, InterruptedException {
final String jsonSchema = BigQueryIO.JSON_FACTORY.toString(schema);
SerializableFunction<GenericRecord, T> fnWrapper = new SerializableFunction<GenericRecord, T>() {
private Supplier<TableSchema> schema = Suppliers.memoize(Suppliers.compose(new TableSchemaFunction(), Suppliers.ofInstance(jsonSchema)));
@Override
public T apply(GenericRecord input) {
return parseFn.apply(new SchemaAndRecord(input, schema.get()));
}
};
List<BoundedSource<T>> avroSources = Lists.newArrayList();
// mode.
if (metadata != null) {
for (MatchResult.Metadata file : metadata) {
avroSources.add(AvroSource.from(file).withParseFn(fnWrapper, getOutputCoder()));
}
} else {
for (ResourceId file : files) {
avroSources.add(AvroSource.from(file.toString()).withParseFn(fnWrapper, getOutputCoder()));
}
}
return ImmutableList.copyOf(avroSources);
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Supplier in project beam by apache.
the class FhirIOReadIT method testFhirIORead.
@Test
public void testFhirIORead() throws Exception {
pipeline.getOptions().as(DirectOptions.class).setBlockOnRun(false);
FhirIO.Read.Result result = pipeline.apply(PubsubIO.readStrings().fromSubscription(pubsubSubscription)).apply(FhirIO.readResources());
PCollection<String> resources = result.getResources();
resources.apply("waitForAnyMessage", signal.signalSuccessWhen(resources.getCoder(), anyResources -> true));
// wait for any resource
Supplier<Void> start = signal.waitForStart(Duration.standardMinutes(5));
pipeline.apply(signal.signalStart());
PipelineResult job = pipeline.run();
start.get();
signal.waitForSuccess(Duration.standardMinutes(5));
// A runner may not support cancel
try {
job.cancel();
} catch (UnsupportedOperationException exc) {
// noop
}
}
Aggregations