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


Java KV.of方法代码示例

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


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

示例1: getCurrent

import com.google.cloud.dataflow.sdk.values.KV; //导入方法依赖的package包/类
/**
 * Get the next file in queue.
 * @return A Key-Value pair where the key is a list of strings representing the path of
 * the file and the value is a string representing the content of the file.
 * @throws NoSuchElementException If the file can't be read from the GCS API.
 */
@Override
public KV<List<String>, String> getCurrent() throws NoSuchElementException {
  String filePath = this.currentFiles.get(0);
  String fileContent = null;
  try {
    fileContent = this.source.getFileContent(filePath);
  } catch (IOException ioe) {
    throw new NoSuchElementException(
        "Object " + filePath + " not found in bucket " + this.source.bucket);
  } catch (GeneralSecurityException gse) {
    throw new NoSuchElementException(
        "Cannot access object "
            + filePath
            + " in bucket "
            + this.source.bucket
            + " due to security reasons");
  }
  List<String> splitPath = Arrays.asList(filePath.split(this.source.getDirDelimiter()));
  return KV.of(splitPath, fileContent);
}
 
开发者ID:GoogleCloudPlatform,项目名称:policyscanner,代码行数:27,代码来源:GCSFilesSource.java

示例2: apply

import com.google.cloud.dataflow.sdk.values.KV; //导入方法依赖的package包/类
@Override
public KV<String, WorkflowArgs> apply(Iterable<KV<String, WorkflowArgs>> input) {
  String key = null;
  WorkflowArgs retval = null;

  // Merge arguments
  for (KV<String, WorkflowArgs> kv : input) {

    // Modify a copy
    WorkflowArgs wa = new WorkflowArgs(kv.getValue());

    // First time, nothing to merge
    if (retval == null) {
      key = kv.getKey();
      retval = wa;
    // Find differences and merge
    } else {
      retval.gatherArgs(wa);
    }
  }
  return KV.of(key, retval);
}
 
开发者ID:googlegenomics,项目名称:dockerflow,代码行数:23,代码来源:MergeBranches.java

示例3: doMutation_encodesKeysAndCounts

import com.google.cloud.dataflow.sdk.values.KV; //导入方法依赖的package包/类
@Test
public void doMutation_encodesKeysAndCounts() {
  // Arrange
  DoFnTester<KV<String, Integer>, Mutation> tester = DoFnTester.of(LoadBooks.ENCODE_NGRAM);
  KV<String, Integer> input = KV.of("this is a test", 513);

  // Act
  List<Mutation> output = tester.processBatch(input);

  // Assert
  Put put = (Put) output.get(0);
  assertThat(put.getRow()).isEqualTo("this is a test".getBytes(StandardCharsets.UTF_8));
  Cell valueCell = put.get(LoadBooks.FAMILY, LoadBooks.COUNT_QUALIFIER).get(0);
  byte[] valueArray = valueCell.getValueArray();
  byte[] value =
      Arrays.copyOfRange(
          valueArray,
          valueCell.getValueOffset(),
          valueCell.getValueOffset() + valueCell.getValueLength());
  assertThat(value).isEqualTo(new byte[] {0, 0, 2, 1});
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-bigtable-examples,代码行数:22,代码来源:LoadBooksTest.java

示例4: apply

import com.google.cloud.dataflow.sdk.values.KV; //导入方法依赖的package包/类
@Override
public KV<LatLon, TableRow> apply(TableRow t) {
  float lat = Float.parseFloat(t.get("latitude").toString());
  float lon = Float.parseFloat(t.get("longitude").toString());
  final float PRECISION = 0.005f; // very approximately 500m
  float roundedLat = (float) Math.floor(lat / PRECISION) * PRECISION + PRECISION / 2;
  float roundedLon = (float) Math.floor(lon / PRECISION) * PRECISION + PRECISION / 2;
  LatLon key = new LatLon(roundedLat, roundedLon);

  return KV.of(key, t);
}
 
开发者ID:googlecodelabs,项目名称:cloud-dataflow-nyc-taxi-tycoon,代码行数:12,代码来源:CountRides.java

示例5: processElement

import com.google.cloud.dataflow.sdk.values.KV; //导入方法依赖的package包/类
@Override
public void processElement(
    DoFn<KV<String, TSAggValueProto>, KV<String, WorkDataPoint>>.ProcessContext c) 
    throws Exception {

  // Extract only the needed data to do the work and create Proto

  TSProto openFX = c.element().getValue().getOpenState();
  TSProto closeFX = c.element().getValue().getCloseState();

  double closeOverOpen = closeFX.getAskPrice() / openFX.getAskPrice();

  double logRtn = Math.log(closeOverOpen);
  
  String key = c.element().getKey();

  WorkDataPoint data =
      WorkDataPoint.newBuilder().setKey(key).setTime(closeFX.getTime())
          .setValue(logRtn).build();

    String partition = c.window().maxTimestamp().toString();
    
    KV<String, WorkDataPoint> bars = KV.of(partition, data);
    
    c.outputWithTimestamp(bars, c.timestamp());

    c.sideOutput(tag, 1);
}
 
开发者ID:GoogleCloudPlatform,项目名称:data-timeseries-java,代码行数:29,代码来源:DistributeWorkDataDoFn.java


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