本文整理汇总了Java中com.google.cloud.dataflow.sdk.values.KV.getKey方法的典型用法代码示例。如果您正苦于以下问题:Java KV.getKey方法的具体用法?Java KV.getKey怎么用?Java KV.getKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.cloud.dataflow.sdk.values.KV
的用法示例。
在下文中一共展示了KV.getKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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包/类
/**
* 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));
}