本文整理汇总了Java中org.apache.beam.sdk.transforms.SerializableFunction类的典型用法代码示例。如果您正苦于以下问题:Java SerializableFunction类的具体用法?Java SerializableFunction怎么用?Java SerializableFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SerializableFunction类属于org.apache.beam.sdk.transforms包,在下文中一共展示了SerializableFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWriteWithBrokenGetTable
import org.apache.beam.sdk.transforms.SerializableFunction; //导入依赖的package包/类
@Test
public void testWriteWithBrokenGetTable() throws Exception {
p.apply(Create.<TableRow>of(new TableRow().set("foo", "bar")))
.apply(
BigQueryIO.writeTableRows()
.to(
new SerializableFunction<ValueInSingleWindow<TableRow>, TableDestination>() {
@Override
public TableDestination apply(ValueInSingleWindow<TableRow> input) {
return null;
}
})
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_NEVER)
.withTestServices(fakeBqServices)
.withoutValidation());
thrown.expectMessage("result of tableFunction can not be null");
thrown.expectMessage("foo");
p.run();
}
示例2: testDestinationFunction_generatesProperFileParams
import org.apache.beam.sdk.transforms.SerializableFunction; //导入依赖的package包/类
@Test
public void testDestinationFunction_generatesProperFileParams() {
SerializableFunction<BillingEvent, Params> destinationFunction =
InvoicingUtils.makeDestinationFunction("my/directory", StaticValueProvider.of("2017-10"));
BillingEvent billingEvent = mock(BillingEvent.class);
// We mock BillingEvent to make the test independent of the implementation of toFilename()
when(billingEvent.toFilename(any())).thenReturn("invoice_details_2017-10_registrar_tld");
assertThat(destinationFunction.apply(billingEvent))
.isEqualTo(
new Params()
.withShardTemplate("")
.withSuffix(".csv")
.withBaseFilename(
FileBasedSink.convertToFileResourceIfPossible(
"my/directory/invoice_details_2017-10_registrar_tld")));
}
示例3: enableBulkApiConfigurator
import org.apache.beam.sdk.transforms.SerializableFunction; //导入依赖的package包/类
static SerializableFunction<BigtableOptions.Builder, BigtableOptions.Builder>
enableBulkApiConfigurator(final @Nullable SerializableFunction<BigtableOptions.Builder,
BigtableOptions.Builder> userConfigurator) {
return new SerializableFunction<BigtableOptions.Builder, BigtableOptions.Builder>() {
@Override
public BigtableOptions.Builder apply(BigtableOptions.Builder optionsBuilder) {
if (userConfigurator != null) {
optionsBuilder = userConfigurator.apply(optionsBuilder);
}
return optionsBuilder
.setBulkOptions(
optionsBuilder.build().getBulkOptions().toBuilder()
.setUseBulkApi(true)
.build());
}
};
}
示例4: testFullRead
import org.apache.beam.sdk.transforms.SerializableFunction; //导入依赖的package包/类
@Test
public void testFullRead() throws Exception {
PCollection<String> output = pipeline.apply(
MongoDbGridFSIO.<String>read()
.withUri("mongodb://localhost:" + port)
.withDatabase(DATABASE));
PAssert.thatSingleton(
output.apply("Count All", Count.<String>globally()))
.isEqualTo(5000L);
PAssert.that(
output.apply("Count PerElement", Count.<String>perElement()))
.satisfies(new SerializableFunction<Iterable<KV<String, Long>>, Void>() {
@Override
public Void apply(Iterable<KV<String, Long>> input) {
for (KV<String, Long> element : input) {
assertEquals(500L, element.getValue().longValue());
}
return null;
}
});
pipeline.run();
}
示例5: testParseDamagedPdfFile
import org.apache.beam.sdk.transforms.SerializableFunction; //导入依赖的package包/类
@Test
public void testParseDamagedPdfFile() throws IOException {
String path = getClass().getResource("/damaged.pdf").getPath();
PCollection<ParseResult> res = p.apply("ParseInvalidPdfFile", TikaIO.parse().filepattern(path));
PAssert.thatSingleton(res)
.satisfies(
new SerializableFunction<ParseResult, Void>() {
@Override
public Void apply(ParseResult input) {
assertEquals(path, input.getFileLocation());
assertFalse(input.isSuccess());
assertTrue(input.getError() instanceof TikaException);
return null;
}
});
p.run();
}
示例6: UnboundedCountingSource
import org.apache.beam.sdk.transforms.SerializableFunction; //导入依赖的package包/类
/**
* Creates an {@link UnboundedSource} that will produce numbers starting from {@code 0} up to
* {@link Long#MAX_VALUE}, with element timestamps supplied by the specified function.
*
* <p>After {@link Long#MAX_VALUE}, the source never produces more output. (In practice, this
* limit should never be reached.)
*
* <p>Note that the timestamps produced by {@code timestampFn} may not decrease.
*/
private UnboundedCountingSource(
long start,
long stride,
long elementsPerPeriod,
Duration period,
SerializableFunction<Long, Instant> timestampFn) {
this.start = start;
this.stride = stride;
checkArgument(
elementsPerPeriod > 0L,
"Must produce at least one element per period, got %s",
elementsPerPeriod);
this.elementsPerPeriod = elementsPerPeriod;
checkArgument(
period.getMillis() >= 0L, "Must have a non-negative period length, got %s", period);
this.period = period;
this.timestampFn = timestampFn;
}
示例7: testCoGroupByKeyGetOnly
import org.apache.beam.sdk.transforms.SerializableFunction; //导入依赖的package包/类
@Test
@Category(ValidatesRunner.class)
public void testCoGroupByKeyGetOnly() {
final TupleTag<String> tag1 = new TupleTag<>();
final TupleTag<String> tag2 = new TupleTag<>();
PCollection<KV<Integer, CoGbkResult>> coGbkResults =
buildGetOnlyGbk(p, tag1, tag2);
PAssert.thatMap(coGbkResults).satisfies(
new SerializableFunction<Map<Integer, CoGbkResult>, Void>() {
@Override
public Void apply(Map<Integer, CoGbkResult> results) {
assertEquals("collection1-1", results.get(1).getOnly(tag1));
assertEquals("collection1-2", results.get(2).getOnly(tag1));
assertEquals("collection2-2", results.get(2).getOnly(tag2));
assertEquals("collection2-3", results.get(3).getOnly(tag2));
return null;
}
});
p.run();
}
示例8: onlyPaneMultiplePanesFails
import org.apache.beam.sdk.transforms.SerializableFunction; //导入依赖的package包/类
@Test
public void onlyPaneMultiplePanesFails() {
SerializableFunction<Iterable<ValueInSingleWindow<Integer>>, Iterable<Integer>> extractor =
PaneExtractors.onlyPane(PAssert.PAssertionSite.capture(""));
Iterable<ValueInSingleWindow<Integer>> multipleFiring =
ImmutableList.of(
ValueInSingleWindow.of(
4,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(true, false, Timing.EARLY)),
ValueInSingleWindow.of(
2,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(false, false, Timing.ON_TIME, 1L, 0L)),
ValueInSingleWindow.of(
1,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(false, false, Timing.LATE, 2L, 1L)));
thrown.expectMessage("trigger that fires at most once");
extractor.apply(multipleFiring);
}
示例9: onTimePane
import org.apache.beam.sdk.transforms.SerializableFunction; //导入依赖的package包/类
@Test
public void onTimePane() {
SerializableFunction<Iterable<ValueInSingleWindow<Integer>>, Iterable<Integer>> extractor =
PaneExtractors.onTimePane();
Iterable<ValueInSingleWindow<Integer>> onlyOnTime =
ImmutableList.of(
ValueInSingleWindow.of(
4,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(false, false, Timing.ON_TIME, 1L, 0L)),
ValueInSingleWindow.of(
2,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(false, false, Timing.ON_TIME, 1L, 0L)));
assertThat(extractor.apply(onlyOnTime), containsInAnyOrder(2, 4));
}
示例10: finalPaneNoExplicitFinalEmpty
import org.apache.beam.sdk.transforms.SerializableFunction; //导入依赖的package包/类
@Test
public void finalPaneNoExplicitFinalEmpty() {
SerializableFunction<Iterable<ValueInSingleWindow<Integer>>, Iterable<Integer>> extractor =
PaneExtractors.finalPane();
Iterable<ValueInSingleWindow<Integer>> onlyOnTime =
ImmutableList.of(
ValueInSingleWindow.of(
8,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(false, false, Timing.LATE, 2L, 1L)),
ValueInSingleWindow.of(
4,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(false, false, Timing.ON_TIME, 1L, 0L)),
ValueInSingleWindow.of(
1,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(true, false, Timing.EARLY)));
assertThat(extractor.apply(onlyOnTime), emptyIterable());
}
示例11: nonLatePanesSingleEarly
import org.apache.beam.sdk.transforms.SerializableFunction; //导入依赖的package包/类
@Test
public void nonLatePanesSingleEarly() {
SerializableFunction<Iterable<ValueInSingleWindow<Integer>>, Iterable<Integer>> extractor =
PaneExtractors.nonLatePanes();
Iterable<ValueInSingleWindow<Integer>> onlyOnTime =
ImmutableList.of(
ValueInSingleWindow.of(
8,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(true, false, Timing.EARLY)),
ValueInSingleWindow.of(
4,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(true, false, Timing.EARLY)));
assertThat(extractor.apply(onlyOnTime), containsInAnyOrder(4, 8));
}
示例12: nonLatePanesMultiplePanes
import org.apache.beam.sdk.transforms.SerializableFunction; //导入依赖的package包/类
@Test
public void nonLatePanesMultiplePanes() {
SerializableFunction<Iterable<ValueInSingleWindow<Integer>>, Iterable<Integer>> extractor =
PaneExtractors.nonLatePanes();
Iterable<ValueInSingleWindow<Integer>> onlyOnTime =
ImmutableList.of(
ValueInSingleWindow.of(
8,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(false, false, Timing.LATE, 2L, 1L)),
ValueInSingleWindow.of(7, new Instant(0L), GlobalWindow.INSTANCE, PaneInfo.NO_FIRING),
ValueInSingleWindow.of(
4,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(false, false, Timing.ON_TIME, 1L, 0L)),
ValueInSingleWindow.of(
1,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(true, false, Timing.EARLY)));
assertThat(extractor.apply(onlyOnTime), containsInAnyOrder(4, 1, 7));
}
示例13: allPanesMultiplePanes
import org.apache.beam.sdk.transforms.SerializableFunction; //导入依赖的package包/类
@Test
public void allPanesMultiplePanes() {
SerializableFunction<Iterable<ValueInSingleWindow<Integer>>, Iterable<Integer>> extractor =
PaneExtractors.allPanes();
Iterable<ValueInSingleWindow<Integer>> onlyOnTime =
ImmutableList.of(
ValueInSingleWindow.of(
8,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(false, false, Timing.LATE, 2L, 1L)),
ValueInSingleWindow.of(
4,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(false, false, Timing.ON_TIME, 1L, 0L)),
ValueInSingleWindow.of(
1,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(true, false, Timing.EARLY)));
assertThat(extractor.apply(onlyOnTime), containsInAnyOrder(4, 8, 1));
}
示例14: testSerializablePredicate
import org.apache.beam.sdk.transforms.SerializableFunction; //导入依赖的package包/类
/**
* A {@link PAssert} about the contents of a {@link PCollection}
* is allows to be verified by an arbitrary {@link SerializableFunction},
* though.
*/
@Test
@Category(ValidatesRunner.class)
public void testSerializablePredicate() throws Exception {
PCollection<NotSerializableObject> pcollection = pipeline
.apply(Create.of(
new NotSerializableObject(),
new NotSerializableObject())
.withCoder(NotSerializableObjectCoder.of()));
PAssert.that(pcollection).satisfies(
new SerializableFunction<Iterable<NotSerializableObject>, Void>() {
@Override
public Void apply(Iterable<NotSerializableObject> contents) {
return null; // no problem!
}
});
pipeline.run();
}
示例15: testNewProvider
import org.apache.beam.sdk.transforms.SerializableFunction; //导入依赖的package包/类
@Test
@Category(ValidatesRunner.class)
public void testNewProvider() {
ValueProvider<String> foo = pipeline.newProvider("foo");
ValueProvider<String> foobar =
ValueProvider.NestedValueProvider.of(
foo,
new SerializableFunction<String, String>() {
@Override
public String apply(String input) {
return input + "bar";
}
});
assertFalse(foo.isAccessible());
assertFalse(foobar.isAccessible());
PAssert.that(pipeline.apply("create foo", Create.ofProvider(foo, StringUtf8Coder.of())))
.containsInAnyOrder("foo");
PAssert.that(pipeline.apply("create foobar", Create.ofProvider(foobar, StringUtf8Coder.of())))
.containsInAnyOrder("foobar");
pipeline.run();
}