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


Java KV.of方法代码示例

本文整理汇总了Java中org.apache.beam.sdk.values.KV.of方法的典型用法代码示例。如果您正苦于以下问题:Java KV.of方法的具体用法?Java KV.of怎么用?Java KV.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.beam.sdk.values.KV的用法示例。


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

示例1: testCachePipeline

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@Test
@Category(NeedsRunner.class)
public void testCachePipeline() throws Exception {

    final KV<String, String> kv = KV.of("trellis:repository/resource", null);

    final Map<String, String> dataConfiguration = singletonMap("repository",
            getClass().getResource("/root").toURI().toString());

    final PCollection<KV<String, String>> pCollection = pipeline
        .apply("Create", Create.of(kv))
        .apply(ParDo.of(new CacheWriter(dataConfiguration)));

    PAssert.that(pCollection).containsInAnyOrder(asList(kv));

    pipeline.run();
}
 
开发者ID:trellis-ldp-archive,项目名称:trellis-rosid-file-streaming,代码行数:18,代码来源:CacheWriterTest.java

示例2: testInvalidDirectoryPipeline

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@Test
@Category(NeedsRunner.class)
public void testInvalidDirectoryPipeline() throws Exception {

    final KV<String, String> kv = KV.of("trellis:repository/resource", null);

    final Map<String, String> dataConfiguration = singletonMap("foo",
            getClass().getResource("/root").toURI().toString());

    final PCollection<KV<String, String>> pCollection = pipeline
        .apply("Create", Create.of(kv))
        .apply(ParDo.of(new CacheWriter(dataConfiguration)));

    PAssert.that(pCollection).empty();

    pipeline.run();
}
 
开发者ID:trellis-ldp-archive,项目名称:trellis-rosid-file-streaming,代码行数:18,代码来源:CacheWriterTest.java

示例3: testInvalidDataPipeline

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@Test
@Category(NeedsRunner.class)
public void testInvalidDataPipeline() throws Exception {

    final String dataset = "<trellis:repository/resource> " +
        "<http://purl.org/dc/terms/subject> <trellis:repository/resource/member> " +
        "<http://www.w3.org/ns/ldp#PreferConta";
    final KV<String, String> kv = KV.of("trellis:repository/resource", dataset);

    final Map<String, String> dataConfiguration = singletonMap("repository",
            getClass().getResource("/dataDirectory").toURI().toString());

    final PCollection<KV<String, String>> pCollection = pipeline
        .apply("Create", Create.of(kv))
        .apply(ParDo.of(new BeamProcessor(dataConfiguration, LDP.PreferContainment.getIRIString(), false)));

    PAssert.that(pCollection).empty();

    pipeline.run();
}
 
开发者ID:trellis-ldp-archive,项目名称:trellis-rosid-file-streaming,代码行数:21,代码来源:BeamProcessorTest.java

示例4: testInvalidDataPipeline

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@Test
@Category(NeedsRunner.class)
public void testInvalidDataPipeline() throws Exception {

    final String dataset = "<trellis:repository/resource> " +
        "<http://purl.org/dc/terms/subject> <trellis:repository/resource/member> " +
        "<http://www.w3.org/ns/ldp#PreferConta";
    final KV<String, String> kv = KV.of("trellis:repository/resource", dataset);

    final String dataConfiguration = "http://localhost/";

    final PCollection<KV<String, String>> pCollection = pipeline
        .apply("Create", Create.of(kv))
        .apply(ParDo.of(new EventProcessor(dataConfiguration)));

    PAssert.that(pCollection).empty();

    pipeline.run();
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:20,代码来源:EventProcessorTest.java

示例5: testInvalidDataPipeline

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@Test
@Category(NeedsRunner.class)
public void testInvalidDataPipeline() throws Exception {

    final String dataset = "<trellis:repository/resource> " +
        "<http://purl.org/dc/terms/subject> <trellis:repository/resource/member> " +
        "<http://www.w3.org/ns/ldp#PreferConta";
    final KV<String, String> kv = KV.of("trellis:repository/resource", dataset);

    final Map<String, String> dataConfiguration = singletonMap("repository", "http://localhost/");

    final PCollection<KV<String, String>> pCollection = pipeline
        .apply("Create", Create.of(kv))
        .apply(ParDo.of(new EventProcessor(dataConfiguration)));

    PAssert.that(pCollection).empty();

    pipeline.run();
}
 
开发者ID:trellis-ldp-archive,项目名称:trellis-rosid-file-streaming,代码行数:20,代码来源:EventProcessorTest.java

示例6: testFormatCounts

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@Test
@SuppressWarnings({"rawtypes", "unchecked"})
public void testFormatCounts() throws Exception {
  DoFnTester<KV<Integer, Long>, TableRow> formatCountsFn =
      DoFnTester.of(new FormatCountsFn());
  KV empty[] = {};
  List<TableRow> results = formatCountsFn.processBundle(empty);
  Assert.assertTrue(results.size() == 0);
  KV input[] = { KV.of(3, 0L),
                 KV.of(4, Long.MAX_VALUE),
                 KV.of(5, Long.MIN_VALUE) };
  results = formatCountsFn.processBundle(input);
  Assert.assertEquals(results.size(), 3);
  Assert.assertEquals(results.get(0).get("month"), 3);
  Assert.assertEquals(results.get(0).get("tornado_count"), 0L);
  Assert.assertEquals(results.get(1).get("month"), 4);
  Assert.assertEquals(results.get(1).get("tornado_count"), Long.MAX_VALUE);
  Assert.assertEquals(results.get(2).get("month"), 5);
  Assert.assertEquals(results.get(2).get("tornado_count"), Long.MIN_VALUE);
}
 
开发者ID:apache,项目名称:beam,代码行数:21,代码来源:BigQueryTornadoesTest.java

示例7: createTestData

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
private static ArrayList<KV<String, String>> createTestData() {
  String[] scientists = {
    "Einstein",
    "Darwin",
    "Copernicus",
    "Pasteur",
    "Curie",
    "Faraday",
    "Newton",
    "Bohr",
    "Galilei",
    "Maxwell"
  };
  ArrayList<KV<String, String>> data = new ArrayList<>();
  for (int i = 0; i < NUM_ELEMENTS; i++) {
    int index = i % scientists.length;
    KV<String, String> element = KV.of("key", scientists[index]);
    data.add(element);
  }
  return data;
}
 
开发者ID:apache,项目名称:beam,代码行数:22,代码来源:GroupIntoBatchesTest.java

示例8: getCurrent

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@Override
public KV<K, V> getCurrent() {
  K key = null;
  V value = null;
  try {
    // Transform key if translation function is provided.
    key =
        transformKeyOrValue((T1) recordReader.getCurrentKey(), keyTranslationFunction,
            keyCoder);
    // Transform value if translation function is provided.
    value =
        transformKeyOrValue((T2) recordReader.getCurrentValue(), valueTranslationFunction,
            valueCoder);
  } catch (IOException | InterruptedException e) {
    LOG.error("Unable to read data: " + "{}", e);
    throw new IllegalStateException("Unable to read data: " + "{}", e);
  }
  return KV.of(key, value);
}
 
开发者ID:apache,项目名称:beam,代码行数:20,代码来源:HadoopInputFormatIO.java

示例9: processElement

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@ProcessElement
public void processElement(ProcessContext c) {
	TableRow row = c.element();
	String url = row.get("WebResourceHash").toString();
	String lastCountTime = row.get("LastCountTime").toString();
	if (url != null && !url.isEmpty())
	{
		Long l = IndexerPipelineUtils.parseDateToLong(IndexerPipelineUtils.dateTimeFormatYMD_HMS_MSTZ, lastCountTime);
		if (l == null) l = 1L;
		KV<String,Long> kv = KV.of(url, l);
		c.output(kv);
	}
}
 
开发者ID:GoogleCloudPlatform,项目名称:dataflow-opinion-analysis,代码行数:14,代码来源:SocialStatsPipeline.java

示例10: processElement

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@ProcessElement
public void processElement(ProcessContext c) {
	TableRow row = c.element();
	String url = IndexerPipelineUtils.getTableRowStringFieldIfNotNull(row,"Url");
	String processingTime = IndexerPipelineUtils.getTableRowStringFieldIfNotNull(row,"ProcessingTime");
	if (url != null && !url.isEmpty())
	{
		Long l = IndexerPipelineUtils.parseDateToLong(IndexerPipelineUtils.dateTimeFormatYMD_HMS_MSTZ, processingTime);
		if (l == null) l = 1L;
		KV<String,Long> kv = KV.of(url, l);
		c.output(kv);
	}
}
 
开发者ID:GoogleCloudPlatform,项目名称:dataflow-opinion-analysis,代码行数:14,代码来源:IndexerPipeline.java

示例11: structuralValue

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@Override
public Object structuralValue(KV<K, V> kv) {
  if (consistentWithEquals()) {
    return kv;
  } else {
    return KV.of(getKeyCoder().structuralValue(kv.getKey()),
                 getValueCoder().structuralValue(kv.getValue()));
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:10,代码来源:KvCoder.java

示例12: mergeAccumulators

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@Override
    public KV<BigDecimal, VarAgg> mergeAccumulators(
            Iterable<KV<BigDecimal, VarAgg>> accumulators) {
      BigDecimal variance = new BigDecimal(0);
      long count = 0;
      BigDecimal sum = new BigDecimal(0);

      Iterator<KV<BigDecimal, VarAgg>> ite = accumulators.iterator();
      while (ite.hasNext()) {
        KV<BigDecimal, VarAgg> r = ite.next();

        BigDecimal b = r.getValue().sum;

        count += r.getValue().count;
        sum = sum.add(b);

//        t = ( r.count / count ) * sum - b;
//        d = t^2 * ( ( count / r.count ) / ( count + r.count ) );
        BigDecimal t = new BigDecimal(r.getValue().count).divide(new BigDecimal(count), mc)
                .multiply(sum).subtract(b);
        BigDecimal d = t.pow(2)
                .multiply(new BigDecimal(r.getValue().count).divide(new BigDecimal(count), mc)
                          .divide(new BigDecimal(count)
                                  .add(new BigDecimal(r.getValue().count))), mc);
        variance = variance.add(r.getKey().add(d));
      }

      return KV.of(variance, new VarAgg(count, sum));
    }
 
开发者ID:apache,项目名称:beam,代码行数:30,代码来源:BeamBuiltinAggregations.java

示例13: testAddAfterSort

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
/** Tests trying to call add after calling sort. Should throw an exception. */
public static void testAddAfterSort(Sorter sorter, ExpectedException thrown) throws Exception {
  thrown.expect(IllegalStateException.class);
  thrown.expectMessage(is("Records can only be added before sort()"));
  KV<byte[], byte[]> kv = KV.of(new byte[] {4, 7}, new byte[] {1, 2});
  sorter.add(kv);
  sorter.sort();
  sorter.add(kv);
}
 
开发者ID:apache,项目名称:beam,代码行数:10,代码来源:SorterTestUtils.java

示例14: fromPairFunction

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
/** A pair to {@link KV} function . */
static <K, V> Function<Tuple2<K, V>, KV<K, V>> fromPairFunction() {
  return new Function<Tuple2<K, V>, KV<K, V>>() {
    @Override
    public KV<K, V> call(Tuple2<K, V> t2) {
      return KV.of(t2._1(), t2._2());
    }
  };
}
 
开发者ID:apache,项目名称:beam,代码行数:10,代码来源:TranslationUtils.java

示例15: decode

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@Override
public KV<Integer, WindowedValue<?>> decode(InputStream in)
    throws IOException {
  Integer id = VarIntCoder.of().decode(in);
  Coder<WindowedValue<?>> coder = idsToCoders.get(id);
  WindowedValue<?> value = coder.decode(in);
  return KV.<Integer, WindowedValue<?>>of(id, value);
}
 
开发者ID:apache,项目名称:beam,代码行数:9,代码来源:DoFnOperator.java


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