本文整理汇总了Java中com.google.cloud.dataflow.sdk.values.KV.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java KV.getValue方法的具体用法?Java KV.getValue怎么用?Java KV.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.cloud.dataflow.sdk.values.KV
的用法示例。
在下文中一共展示了KV.getValue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: processElement
import com.google.cloud.dataflow.sdk.values.KV; //导入方法依赖的package包/类
@Override
public void processElement(ProcessContext c) throws Exception {
List<KV<T, Iterable<U>>> kvs2 = c.sideInput(view);
KV<T, Iterable<U>> kv1 = c.element();
T k1 = kv1.getKey();
Iterable<U> v1 = kv1.getValue();
boolean foundMatch = false;
for (KV<T, Iterable<U>> kv2 : kvs2) {
if (k1.equals(kv2.getKey())) {
// Found the key, now check the values (in any permutation).
if (CollectionUtils.isEqualCollection(Lists.newArrayList(v1), Lists.newArrayList(kv2.getValue()))) {
// Found a match!
foundMatch = true;
}
}
}
Assert.assertTrue(foundMatch, "Unable to find a match for " + kv1.toString() + " in p2");
}
示例3: processElement
import com.google.cloud.dataflow.sdk.values.KV; //导入方法依赖的package包/类
@Override
public void processElement(ProcessContext c) {
KV<Integer, Iterable<TableRow>> kv = c.element();
String keyword = "";
StringBuffer bf = new StringBuffer();
for (TableRow row : kv.getValue()) {
String utterance = row.get("utterance").toString();
bf.append(row.get("utterance"));
bf.append(row.get(","));
keyword = utterance;
}
LOG.info(kv.getKey().toString() + ":" + keyword + ":" + bf.toString());
}
示例4: makeEntity
import com.google.cloud.dataflow.sdk.values.KV; //导入方法依赖的package包/类
public Entity makeEntity(KV<Integer, Iterable<TableRow>> content) {
Key key = Key.newBuilder()
.addPath(PathElement.newBuilder().setKind(this.kind).setId(content.getKey())).build();
String keyword = "";
List<Value> list = new ArrayList<>();
for (TableRow row : content.getValue()) {
String utterance = row.get("utterance").toString();
if (utterance == null || utterance.length() < 1) {
continue;
}
String word = row.get("keyword").toString();
if (keyword.equals(row.get("keyword")) == false) {
keyword = word;
}
if (list.size() > 1000) {
LOG.info("Truncated the text." + "keyword_id = " + content.getKey() + ", keyword = " + word);
break;
}
list.add(Value.newBuilder().setStringValue(utterance).build());
}
Entity.Builder entityBuilder = Entity.newBuilder();
entityBuilder.setKey(key);
Map<String, Value> propertyMap = new HashMap<String, Value>();
propertyMap.put("KeywordID", Value.newBuilder().setIntegerValue(content.getKey()).build());
propertyMap.put("Keyword", Value.newBuilder().setStringValue(keyword).build());
ArrayValue array = ArrayValue.newBuilder().addAllValues(list).build();
propertyMap.put("Candidates", Value.newBuilder().setArrayValue(array).build());
entityBuilder.putAllProperties(propertyMap);
return entityBuilder.build();
}
示例5: processElement
import com.google.cloud.dataflow.sdk.values.KV; //导入方法依赖的package包/类
/**
* Converts a Key-Value pair of (FilePath, FileContent) to (GCPResource, GCPResourceState).
* The FilePath is a list of Strings which represents the location of a file.
* The FileContent is the content of the file described by the FilePath.
* The path is used to obtain the resource, and the content describes the state of that resource.
* @param processContext The ProcessContext object that contains processContext-specific
* methods and objects.
*/
@Override
public void processElement(ProcessContext processContext) {
KV<List<String>, String> input = processContext.element();
List<String> filePath = input.getKey();
String fileContent = input.getValue();
String orgName = filePath.size() > 0 ? filePath.get(0) : null;
String projectId = filePath.size() > 1 ? filePath.get(1) : null;
String policyFileName = filePath.size() > 2 ? filePath.get(2) : null;
GCPProject project = new GCPProject(projectId, orgName);
if (filePath.size() == 3 && GCPResourcePolicy.getPolicyFile().equals(policyFileName)) {
// only project policies are supported for now.
// filePath.size() must be 3 and of the form org_id/project_id/POLICY_FILE.
Gson gson = new Gson();
try {
List<PolicyBinding> bindings = Arrays.asList(
gson.fromJson(fileContent, PolicyBinding[].class));
GCPResourceState policy = new GCPResourcePolicy(project, bindings);
processContext.output(KV.of((GCPResource) project, policy));
return;
} catch (JsonSyntaxException jse) {
addToSideOutput(
processContext,
project,
String.format("Invalid policy json %s/%s/%s", orgName, projectId, policyFileName));
}
}
addToSideOutput(
processContext,
project,
String.format("Invalid policy filepath %s/%s/%s", orgName, projectId, policyFileName));
}
示例6: processElement
import com.google.cloud.dataflow.sdk.values.KV; //导入方法依赖的package包/类
@Override
public void processElement(ProcessContext context)
throws Exception {
KV<String, Iterable<GCPResource>> element = context.element();
for (GCPResource resource : element.getValue()) {
context.output(element.getKey() + ":" + resource.getId());
}
}
示例7: processElement
import com.google.cloud.dataflow.sdk.values.KV; //导入方法依赖的package包/类
public void processElement(ProcessContext c) {
KV<String, Integer> ngram = c.element();
byte[] key = ngram.getKey().getBytes(STRING_ENCODING);
int count = ngram.getValue();
byte[] data = Bytes.toBytes(count);
c.output(new Put(key).addColumn(FAMILY, COUNT_QUALIFIER, data));
}