本文整理汇总了Java中org.apache.beam.sdk.transforms.SimpleFunction类的典型用法代码示例。如果您正苦于以下问题:Java SimpleFunction类的具体用法?Java SimpleFunction怎么用?Java SimpleFunction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SimpleFunction类属于org.apache.beam.sdk.transforms包,在下文中一共展示了SimpleFunction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
public static void main(String[] args) {
Pipeline p = Pipeline.create(
PipelineOptionsFactory.fromArgs(args).withValidation().create());
p.apply(Create.of("Hello", "World"))
.apply(MapElements.via(new SimpleFunction<String, String>() {
@Override
public String apply(String input) {
return input.toUpperCase();
}
}))
.apply(ParDo.of(new DoFn<String, Void>() {
@ProcessElement
public void processElement(ProcessContext c) {
LOG.info(c.element());
}
}));
p.run();
}
开发者ID:apache,项目名称:beam,代码行数:21,代码来源:StarterPipeline.java
示例2: expand
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
@Override
public PCollection<T> expand(PCollection<T> input) {
WindowingStrategy<?, ?> outputWindowingStrategy = getOutputWindowing(
input.getWindowingStrategy());
return input
// We first apply a (trivial) transform to the input PCollection to produce a new
// PCollection. This ensures that we don't modify the windowing strategy of the input
// which may be used elsewhere.
.apply("Identity", MapElements.via(new SimpleFunction<T, T>() {
@Override public T apply(T element) {
return element;
}
}))
// Then we modify the windowing strategy.
.setWindowingStrategyInternal(outputWindowingStrategy);
}
开发者ID:apache,项目名称:beam,代码行数:18,代码来源:Window.java
示例3: PCollectionSingletonIterableAssert
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
public PCollectionSingletonIterableAssert(
PCollection<Iterable<T>> actual,
AssertionWindows rewindowingStrategy,
SimpleFunction<Iterable<ValueInSingleWindow<Iterable<T>>>, Iterable<Iterable<T>>>
paneExtractor,
PAssertionSite site) {
this.actual = actual;
@SuppressWarnings("unchecked")
Coder<T> typedCoder = (Coder<T>) actual.getCoder().getCoderArguments().get(0);
this.elementCoder = typedCoder;
this.rewindowingStrategy = rewindowingStrategy;
this.paneExtractor = paneExtractor;
this.site = site;
}
开发者ID:apache,项目名称:beam,代码行数:17,代码来源:PAssert.java
示例4: setUp
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws IOException, InterruptedException {
serConf = loadTestConfiguration(
EmployeeInputFormat.class,
Text.class,
Employee.class);
myKeyTranslate = new SimpleFunction<Text, String>() {
@Override
public String apply(Text input) {
return input.toString();
}
};
myValueTranslate = new SimpleFunction<Employee, String>() {
@Override
public String apply(Employee input) {
return input.getEmpName() + "_" + input.getEmpAddress();
}
};
}
开发者ID:apache,项目名称:beam,代码行数:20,代码来源:HadoopInputFormatIOTest.java
示例5: testReadValidationFailsWithWrongInputTypeKeyTranslationFunction
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
/**
* This test validates functionality of {@link HadoopInputFormatIO.Read#validateTransform()
* Read.validateTransform()} function when myKeyTranslate's (simple function provided by user for
* key translation) input type is not same as Hadoop InputFormat's keyClass(Which is property set
* in configuration as "key.class").
*/
@Test
public void testReadValidationFailsWithWrongInputTypeKeyTranslationFunction() {
SimpleFunction<LongWritable, String> myKeyTranslateWithWrongInputType =
new SimpleFunction<LongWritable, String>() {
@Override
public String apply(LongWritable input) {
return input.toString();
}
};
HadoopInputFormatIO.Read<String, Employee> read = HadoopInputFormatIO.<String, Employee>read()
.withConfiguration(serConf.get())
.withKeyTranslation(myKeyTranslateWithWrongInputType);
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(String.format(
"Key translation's input type is not same as hadoop InputFormat : %s key " + "class : %s",
serConf.get().getClass("mapreduce.job.inputformat.class",
InputFormat.class), serConf.get()
.getClass("key.class", Object.class)));
read.validateTransform();
}
开发者ID:apache,项目名称:beam,代码行数:27,代码来源:HadoopInputFormatIOTest.java
示例6: testReadValidationFailsWithWrongInputTypeValueTranslationFunction
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
/**
* This test validates functionality of {@link HadoopInputFormatIO.Read#validateTransform()
* Read.validateTransform()} function when myValueTranslate's (simple function provided by user
* for value translation) input type is not same as Hadoop InputFormat's valueClass(Which is
* property set in configuration as "value.class").
*/
@Test
public void testReadValidationFailsWithWrongInputTypeValueTranslationFunction() {
SimpleFunction<LongWritable, String> myValueTranslateWithWrongInputType =
new SimpleFunction<LongWritable, String>() {
@Override
public String apply(LongWritable input) {
return input.toString();
}
};
HadoopInputFormatIO.Read<Text, String> read =
HadoopInputFormatIO.<Text, String>read()
.withConfiguration(serConf.get())
.withValueTranslation(myValueTranslateWithWrongInputType);
String expectedMessage =
String.format(
"Value translation's input type is not same as hadoop InputFormat : "
+ "%s value class : %s",
serConf.get().getClass("mapreduce.job.inputformat.class",
InputFormat.class),
serConf.get().getClass("value.class", Object.class));
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(expectedMessage);
read.validateTransform();
}
开发者ID:apache,项目名称:beam,代码行数:31,代码来源:HadoopInputFormatIOTest.java
示例7: testCreateNeverWithStreaming
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
@Test
public void testCreateNeverWithStreaming() throws Exception {
p.enableAbandonedNodeEnforcement(false);
TableReference tableRef = new TableReference();
tableRef.setDatasetId("dataset");
tableRef.setTableId("sometable");
PCollection<TableRow> tableRows =
p.apply(GenerateSequence.from(0))
.apply(
MapElements.via(
new SimpleFunction<Long, TableRow>() {
@Override
public TableRow apply(Long input) {
return null;
}
}))
.setCoder(TableRowJsonCoder.of());
tableRows
.apply(BigQueryIO.writeTableRows().to(tableRef)
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_NEVER)
.withoutValidation());
}
开发者ID:apache,项目名称:beam,代码行数:25,代码来源:BigQueryIOWriteTest.java
示例8: PCollectionContentsAssert
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
public PCollectionContentsAssert(
PCollection<T> actual,
AssertionWindows rewindowingStrategy,
SimpleFunction<Iterable<ValueInSingleWindow<T>>, Iterable<T>> paneExtractor,
PAssertionSite site) {
this.actual = actual;
this.rewindowingStrategy = rewindowingStrategy;
this.paneExtractor = paneExtractor;
this.site = site;
}
开发者ID:apache,项目名称:beam,代码行数:11,代码来源:PAssert.java
示例9: withPane
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
private PCollectionContentsAssert<T> withPane(
BoundedWindow window,
SimpleFunction<Iterable<ValueInSingleWindow<T>>, Iterable<T>> paneExtractor) {
@SuppressWarnings({"unchecked", "rawtypes"})
Coder<BoundedWindow> windowCoder =
(Coder) actual.getWindowingStrategy().getWindowFn().windowCoder();
return new PCollectionContentsAssert<>(
actual, IntoStaticWindows.of(windowCoder, window), paneExtractor, site);
}
开发者ID:apache,项目名称:beam,代码行数:10,代码来源:PAssert.java
示例10: withPanes
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
private PCollectionSingletonIterableAssert<T> withPanes(
BoundedWindow window,
SimpleFunction<Iterable<ValueInSingleWindow<Iterable<T>>>, Iterable<Iterable<T>>>
paneExtractor) {
@SuppressWarnings({"unchecked", "rawtypes"})
Coder<BoundedWindow> windowCoder =
(Coder) actual.getWindowingStrategy().getWindowFn().windowCoder();
return new PCollectionSingletonIterableAssert<>(
actual, IntoStaticWindows.of(windowCoder, window), paneExtractor, site);
}
开发者ID:apache,项目名称:beam,代码行数:11,代码来源:PAssert.java
示例11: PCollectionViewAssert
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
private PCollectionViewAssert(
PCollection<ElemT> actual,
PTransform<PCollection<ElemT>, PCollectionView<ViewT>> view,
AssertionWindows rewindowActuals,
SimpleFunction<Iterable<ValueInSingleWindow<ElemT>>, Iterable<ElemT>> paneExtractor,
Coder<ViewT> coder,
PAssertionSite site) {
this.actual = actual;
this.view = view;
this.rewindowActuals = rewindowActuals;
this.paneExtractor = paneExtractor;
this.coder = coder;
this.site = site;
}
开发者ID:apache,项目名称:beam,代码行数:15,代码来源:PAssert.java
示例12: inPane
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
private PCollectionViewAssert<ElemT, ViewT> inPane(
BoundedWindow window,
SimpleFunction<Iterable<ValueInSingleWindow<ElemT>>, Iterable<ElemT>> paneExtractor) {
return new PCollectionViewAssert<>(
actual,
view,
IntoStaticWindows.of(
(Coder) actual.getWindowingStrategy().getWindowFn().windowCoder(), window),
paneExtractor,
coder,
site);
}
开发者ID:apache,项目名称:beam,代码行数:13,代码来源:PAssert.java
示例13: from
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
public static <T, ActualT> CreateActual<T, ActualT> from(
PCollection<T> actual,
AssertionWindows rewindowActuals,
SimpleFunction<Iterable<ValueInSingleWindow<T>>, Iterable<T>> extractPane,
PTransform<PCollection<T>, PCollectionView<ActualT>> actualView) {
return new CreateActual<>(actual, rewindowActuals, extractPane, actualView);
}
开发者ID:apache,项目名称:beam,代码行数:8,代码来源:PAssert.java
示例14: CreateActual
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
private CreateActual(
PCollection<T> actual,
AssertionWindows rewindowActuals,
SimpleFunction<Iterable<ValueInSingleWindow<T>>, Iterable<T>> extractPane,
PTransform<PCollection<T>, PCollectionView<ActualT>> actualView) {
this.actual = actual;
this.rewindowActuals = rewindowActuals;
this.extractPane = extractPane;
this.actualView = actualView;
}
开发者ID:apache,项目名称:beam,代码行数:11,代码来源:PAssert.java
示例15: GroupThenAssert
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
private GroupThenAssert(
SerializableFunction<Iterable<T>, Void> checkerFn,
AssertionWindows rewindowingStrategy,
SimpleFunction<Iterable<ValueInSingleWindow<T>>, Iterable<T>> paneExtractor,
PAssertionSite site) {
this.checkerFn = checkerFn;
this.rewindowingStrategy = rewindowingStrategy;
this.paneExtractor = paneExtractor;
this.site = site;
}
开发者ID:apache,项目名称:beam,代码行数:11,代码来源:PAssert.java
示例16: GroupThenAssertForSingleton
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
private GroupThenAssertForSingleton(
SerializableFunction<Iterable<T>, Void> checkerFn,
AssertionWindows rewindowingStrategy,
SimpleFunction<Iterable<ValueInSingleWindow<Iterable<T>>>, Iterable<Iterable<T>>>
paneExtractor,
PAssertionSite site) {
this.checkerFn = checkerFn;
this.rewindowingStrategy = rewindowingStrategy;
this.paneExtractor = paneExtractor;
this.site = site;
}
开发者ID:apache,项目名称:beam,代码行数:12,代码来源:PAssert.java
示例17: testExpandHasMatchingTags
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
@Test
public void testExpandHasMatchingTags() {
TupleTag<Integer> intTag = new TupleTag<>();
TupleTag<String> strTag = new TupleTag<>();
TupleTag<Long> longTag = new TupleTag<>();
Pipeline p = TestPipeline.create();
PCollection<Long> longs = p.apply(GenerateSequence.from(0).to(100));
PCollection<String> strs = p.apply(Create.of("foo", "bar", "baz"));
PCollection<Integer> ints = longs.apply(MapElements.via(new SimpleFunction<Long, Integer>() {
@Override
public Integer apply(Long input) {
return input.intValue();
}
}));
Map<TupleTag<?>, PCollection<?>> pcsByTag =
ImmutableMap.<TupleTag<?>, PCollection<?>>builder()
.put(strTag, strs)
.put(intTag, ints)
.put(longTag, longs)
.build();
PCollectionTuple tuple =
PCollectionTuple.of(intTag, ints).and(longTag, longs).and(strTag, strs);
assertThat(tuple.getAll(), equalTo(pcsByTag));
PCollectionTuple reconstructed = PCollectionTuple.empty(p);
for (Entry<TupleTag<?>, PValue> taggedValue : tuple.expand().entrySet()) {
TupleTag<?> tag = taggedValue.getKey();
PValue value = taggedValue.getValue();
assertThat("The tag should map back to the value", tuple.get(tag), equalTo(value));
assertThat(value, Matchers.<PValue>equalTo(pcsByTag.get(tag)));
reconstructed = reconstructed.and(tag, (PCollection) value);
}
assertThat(reconstructed, equalTo(tuple));
}
开发者ID:apache,项目名称:beam,代码行数:37,代码来源:PCollectionTupleTest.java
示例18: addSuffix
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
private static PTransform<PCollection<? extends String>, PCollection<String>> addSuffix(
final String suffix) {
return MapElements.via(new SimpleFunction<String, String>() {
@Override
public String apply(String input) {
return input + suffix;
}
});
}
开发者ID:apache,项目名称:beam,代码行数:10,代码来源:PipelineTest.java
示例19: addTransform
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
@SuppressWarnings("UnusedReturnValue")
private static PCollection<String> addTransform(final PCollection<String> pCollection) {
return pCollection.apply(
"Map2",
MapElements.via(
new SimpleFunction<String, String>() {
@Override
public String apply(final String input) {
return WHATEVER;
}
}));
}
开发者ID:apache,项目名称:beam,代码行数:14,代码来源:TestPipelineTest.java
示例20: pCollection
import org.apache.beam.sdk.transforms.SimpleFunction; //导入依赖的package包/类
private static PCollection<String> pCollection(final Pipeline pipeline) {
return pipeline
.apply("Create", Create.of(WORDS).withCoder(StringUtf8Coder.of()))
.apply(
"Map1",
MapElements.via(
new SimpleFunction<String, String>() {
@Override
public String apply(final String input) {
return WHATEVER;
}
}));
}
开发者ID:apache,项目名称:beam,代码行数:15,代码来源:TestPipelineTest.java
注:本文中的org.apache.beam.sdk.transforms.SimpleFunction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论