当前位置: 首页>>代码示例>>Java>>正文


Java DoFn类代码示例

本文整理汇总了Java中org.apache.crunch.DoFn的典型用法代码示例。如果您正苦于以下问题:Java DoFn类的具体用法?Java DoFn怎么用?Java DoFn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DoFn类属于org.apache.crunch包,在下文中一共展示了DoFn类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDetach

import org.apache.crunch.DoFn; //导入依赖的package包/类
@Test
public void testDetach() {
  Collection<TestAvroRecord> expected = Lists.newArrayList(
          new TestAvroRecord(new Utf8("something"), new Utf8("*"), 1L),
          new TestAvroRecord(new Utf8("something"), new Utf8("**"), 1L),
          new TestAvroRecord(new Utf8("something"), new Utf8("***"), 1L)
  );
  DoFn<Pair<String, Iterable<TestAvroRecord>>, Collection<TestAvroRecord>> doFn =
          DoFns.detach(new CollectingMapFn(), Avros.specifics(TestAvroRecord.class));
  Pair<String, Iterable<TestAvroRecord>> input = Pair.of("key", (Iterable<TestAvroRecord>) new AvroIterable());
  InMemoryEmitter<Collection<TestAvroRecord>> emitter = new InMemoryEmitter<Collection<TestAvroRecord>>();

  doFn.configure(new Configuration());
  doFn.initialize();
  doFn.process(input, emitter);
  doFn.cleanup(emitter);

  assertEquals(expected, emitter.getOutput().get(0));
}
 
开发者ID:spotify,项目名称:crunch-lib,代码行数:20,代码来源:DoFnsTest.java

示例2: DetachingDoFn

import org.apache.crunch.DoFn; //导入依赖的package包/类
public DetachingDoFn(DoFn<Pair<K, Iterable<V>>, T> reduceFn, PType<V> valueType) {
  this.reduceFn = reduceFn;
  this.valueType = valueType;
}
 
开发者ID:spotify,项目名称:crunch-lib,代码行数:5,代码来源:DoFns.java

示例3: detach

import org.apache.crunch.DoFn; //导入依赖的package包/类
/**
 * "Reduce" DoFn wrapper which detaches the values in the iterable, preventing the unexpected behaviour related to
 * object reuse often observed when using Avro. Wrap your DoFn in a detach(...) and pass in a PType for the Iterable
 * value, and then you'll be handed an Iterable of real distinct objects, instead of the same object being handed to
 * you multiple times with different data.
 *
 * You should use this when you have a parallelDo after a groupBy, and you'd like to capture the objects arriving in
 * the Iterable part of the incoming Pair and pass it through to the output (for example if you want to create an
 * array of outputs from the values to be output as one record).
 *
 * The will incur a performance hit, as it means that every object read from the Iterable will allocate a new Java
 * object for the record and objects for all its non-primitive fields too. If you are rolling up records into a
 * collection then this will be necessary anyway, but if you are only outputting derived data this may impact the
 * speed and memory usage of your job unnecessarily.
 *
 * @param reduceFn Underlying DoFn to wrap
 * @param valueType PType of the object contained within the Iterable
 * @param <K> Reduce key
 * @param <V> Iterable value
 * @param <T> Output type of DoFn
 * @return DoFn which will detach values for you
 */
public static <K, V, T> DoFn<Pair<K, Iterable<V>>, T> detach(final DoFn<Pair<K, Iterable<V>>, T> reduceFn, final PType<V> valueType) {
  return new DetachingDoFn<K, V, T>(reduceFn, valueType);
}
 
开发者ID:spotify,项目名称:crunch-lib,代码行数:26,代码来源:DoFns.java


注:本文中的org.apache.crunch.DoFn类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。