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


Java KV.getKey方法代码示例

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


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

示例1: processElement

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@ProcessElement
public void processElement(ProcessContext c) {
	KV<String, Iterable<InputContent>> kv = c.element();
	String documentHash = kv.getKey();
	Iterable<InputContent> dupes = kv.getValue();
	boolean isFirst = true;
	int groupSize = Iterables.size(dupes);
	for (InputContent ic : dupes) {
	
		// Check if this doc was already processed and stored in BQ
		Map<String,Long> sideInputMap = c.sideInput(alreadyProcessedDocsSideInput);
		Long proTime = sideInputMap.get(ic.expectedDocumentHash);
		if (proTime!=null) {
			c.output(PipelineTags.contentNotToIndexExactDupesTag,ic);
			continue;
		}
		
		if (isFirst) {
			isFirst = false;
			c.output(ic);
		} else {
			c.output(PipelineTags.contentNotToIndexExactDupesTag,ic);
		}
	}
}
 
开发者ID:GoogleCloudPlatform,项目名称:dataflow-opinion-analysis,代码行数:26,代码来源:IndexerPipeline.java

示例2: processElement

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
/**
 * A method for processing each element
 * @param c the context
 */
@ProcessElement
public void processElement(final ProcessContext c) {
    final KV<String, String> element = c.element();
    final String key = element.getKey();
    final File dir = resourceDirectory(config, key);
    if (!isNull(dir)) {
        LOGGER.debug("Writing cache for: {}", key);
        if (CachedResource.write(dir, key)) {
            c.output(element);
        } else {
            LOGGER.error("Error writing cached resource for {}", key);
        }
    } else {
        LOGGER.error("Error accessing cached resource location for {}", key);
    }
}
 
开发者ID:trellis-ldp-archive,项目名称:trellis-rosid-file-streaming,代码行数:21,代码来源:CacheWriter.java

示例3: processElement

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
/**
 * A method for processing each element
 * @param c the context
 */
@ProcessElement
public void processElement(final ProcessContext c) {
    final KV<String, String> element = c.element();
    final String key = element.getKey();
    final File dir = resourceDirectory(dataLocation, key);
    if (!isNull(dir)) {
        LOGGER.debug("Writing cache for: {}", key);
        if (CachedResource.write(dir, key)) {
            c.output(element);
        } else {
            LOGGER.error("Error writing cached resource for {}", key);
        }
    } else {
        LOGGER.error("Error accessing cached resource location for {}", key);
    }
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:21,代码来源:CacheWriter.java

示例4: processElement

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@Override
public void processElement(WindowedValue<KV<K, V>> element) {
  KV<K, V> kv = element.getValue();
  K key = kv.getKey();
  byte[] encodedKey;
  try {
    encodedKey = encodeToByteArray(keyCoder, key);
  } catch (CoderException exn) {
    // TODO: Put in better element printing:
    // truncate if too long.
    throw new IllegalArgumentException(
        String.format("unable to encode key %s of input to %s using %s", key, this, keyCoder),
        exn);
  }
  GroupingKey<K> groupingKey = new GroupingKey<>(key, encodedKey);
  List<WindowedValue<V>> values = groupingMap.get(groupingKey);
  if (values == null) {
    values = new ArrayList<>();
    groupingMap.put(groupingKey, values);
  }
  values.add(element.withValue(kv.getValue()));
}
 
开发者ID:apache,项目名称:beam,代码行数:23,代码来源:GroupByKeyOnlyEvaluatorFactory.java

示例5: copy

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
/**
 * Copies a {@link List} of file-like resources from one location to another.
 *
 * <p>The number of source resources must equal the number of destination resources.
 * Destination resources will be created recursively.
 *
 * <p>{@code srcResourceIds} and {@code destResourceIds} must have the same scheme.
 *
 * <p>It doesn't support copying globs.
 *
 * @param srcResourceIds the references of the source resources
 * @param destResourceIds the references of the destination resources
 */
public static void copy(
    List<ResourceId> srcResourceIds, List<ResourceId> destResourceIds, MoveOptions... moveOptions)
    throws IOException {
  validateSrcDestLists(srcResourceIds, destResourceIds);
  if (srcResourceIds.isEmpty()) {
    // Short-circuit.
    return;
  }

  List<ResourceId> srcToCopy = srcResourceIds;
  List<ResourceId> destToCopy = destResourceIds;
  if (Sets.newHashSet(moveOptions).contains(
      MoveOptions.StandardMoveOptions.IGNORE_MISSING_FILES)) {
    KV<List<ResourceId>, List<ResourceId>> existings =
        filterMissingFiles(srcResourceIds, destResourceIds);
    srcToCopy = existings.getKey();
    destToCopy = existings.getValue();
  }
  if (srcToCopy.isEmpty()) {
    return;
  }
  getFileSystemInternal(srcToCopy.iterator().next().getScheme())
      .copy(srcToCopy, destToCopy);
}
 
开发者ID:apache,项目名称:beam,代码行数:38,代码来源:FileSystems.java

示例6: map

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@Override
public WindowedValue<KV<K, List<V>>> map(KV<org.joda.time.Instant,
    WindowedValue<KV<K, List<V>>>> kv) {
  Instant timestamp = kv.getKey();
  WindowedValue<KV<K, List<V>>> wv = kv.getValue();
  return WindowedValue.of(wv.getValue(), timestamp, wv.getWindows(), wv.getPane());
}
 
开发者ID:apache,项目名称:beam,代码行数:8,代码来源:GroupByKeyTranslator.java

示例7: writeRecord

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@Override
public ListenableFuture<MutateRowResponse> writeRecord(
    KV<ByteString, Iterable<Mutation>> record) {
  service.verifyTableExists(tableId);
  Map<ByteString, ByteString> table = service.getTable(tableId);
  ByteString key = record.getKey();
  for (Mutation m : record.getValue()) {
    SetCell cell = m.getSetCell();
    if (cell.getValue().isEmpty()) {
      return Futures.immediateFailedCheckedFuture(new IOException("cell value missing"));
    }
    table.put(key, cell.getValue());
  }
  return Futures.immediateFuture(MutateRowResponse.getDefaultInstance());
}
 
开发者ID:apache,项目名称:beam,代码行数:16,代码来源:BigtableIOTest.java

示例8: add

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@Override
public void add(KV<byte[], byte[]> record) throws IOException {
  checkState(!sortCalled, "Records can only be added before sort()");

  initHadoopSorter();

  BytesWritable key = new BytesWritable(record.getKey());
  BytesWritable value = new BytesWritable(record.getValue());

  writer.append(key, value);
}
 
开发者ID:apache,项目名称:beam,代码行数:12,代码来源:ExternalSorter.java

示例9: testRandom

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
/**
 * Generates random records and executes a test with the provided number of sorters and number of
 * records per sorter.
 */
public static void testRandom(
    SorterGenerator sorterGenerator, int numSorters, int numRecordsPerSorter) throws Exception {
  long start = System.currentTimeMillis();
  for (int i = 0; i < numSorters; ++i) {
    Sorter sorter = sorterGenerator.generateSorter();
    Random rnd = new Random(0L);
    for (int j = 0; j < numRecordsPerSorter; ++j) {
      byte[] key = new byte[8];
      byte[] value = new byte[8];
      rnd.nextBytes(key);
      rnd.nextBytes(value);
      sorter.add(KV.of(key, value));
    }

    byte[] prevKey = null;
    for (KV<byte[], byte[]> record : sorter.sort()) {
      assertTrue(
          prevKey == null
              || UnsignedBytes.lexicographicalComparator().compare(prevKey, record.getKey()) < 0);
      prevKey = record.getKey();
    }
  }
  long end = System.currentTimeMillis();
  System.out.println(
      "Took "
          + (end - start)
          + "ms for "
          + numRecordsPerSorter * numSorters * 1000.0 / (end - start)
          + " records/s");
}
 
开发者ID:apache,项目名称:beam,代码行数:35,代码来源:SorterTestUtils.java

示例10: advance

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@Override
public boolean advance() throws IOException {
  if (iterator.hasNext()) {
    KV<String, Instant> kv = iterator.next();
    collected = false;
    currentRecord = kv.getKey();
    currentTimestamp = kv.getValue();
    return true;
  } else {
    return false;
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:13,代码来源:GroupByKeyTranslatorTest.java

示例11: processElement

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@ProcessElement
public void processElement(ProcessContext c) {
  KV<Integer, String> record = c.element();
  int timestamp = record.getKey();
  String userName = record.getValue();
  if (userName != null) {
    // Sets the implicit timestamp field to be used in windowing.
    c.outputWithTimestamp(userName, new Instant(timestamp));
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:11,代码来源:GroupByNullKeyTest.java

示例12: toPairFunction

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

示例13: prepareOutput

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
protected BigDecimal prepareOutput(KV<BigDecimal, VarAgg> accumulator){
  BigDecimal decimalVar;
  if (accumulator.getValue().count > 1) {
    BigDecimal a = accumulator.getKey();
    BigDecimal b = new BigDecimal(accumulator.getValue().count)
            .subtract(this.isSamp ? BigDecimal.ONE : BigDecimal.ZERO);

    decimalVar = a.divide(b, mc);
  } else {
    decimalVar = BigDecimal.ZERO;
  }
  return decimalVar;
}
 
开发者ID:apache,项目名称:beam,代码行数:14,代码来源:BeamBuiltinAggregations.java

示例14: toString

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@Override
public String toString(KV<Instant, ReadableDuration> state) {
  return "AfterTotalOf{"
      + "timeStarted="
      + state.getKey()
      + ", maxTimeSinceInput="
      + state.getValue()
      + '}';
}
 
开发者ID:apache,项目名称:beam,代码行数:10,代码来源:Watch.java

示例15: getDestination

import org.apache.beam.sdk.values.KV; //导入方法依赖的package包/类
@Override
public String getDestination(ValueInSingleWindow<KV<MsSqlTable, DbRow>> element) {
	KV<MsSqlTable, DbRow> kv = element.getValue();
	MsSqlTable table = kv.getKey();
	return datasetName + "." + table.getFullName();
}
 
开发者ID:favsto,项目名称:sql-to-bigquery-dataflow,代码行数:7,代码来源:BigQueryTableDestination.java


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