在Hadoop级联中从管道外部的管道中获取字段值

在Hadoop级联中从管道外部的管道中获取字段值,hadoop,cascading,Hadoop,Cascading,关于上述主题,是否有任何方法可以从管道中获取字段的值。在Hadoop级联中使用管道范围之外的值?数据的分隔符为“|”: first_name|description Binod|nothing Rohit|nothing Ramesh|abc 从上面的管道中,我需要从描述中获得一个值,无论是'nothing'还是'abc'我假设这就是您想要的:您有一个带有一个字段的管道,即${first_name}和${description}的串联。您希望输出是一个字段为${description}的管道

关于上述主题,是否有任何方法可以从管道中获取字段的值。在Hadoop级联中使用管道范围之外的值?数据的分隔符为“|”:

first_name|description

Binod|nothing
Rohit|nothing
Ramesh|abc

从上面的管道中,我需要从描述中获得一个值,无论是'nothing'还是'abc'

我假设这就是您想要的:您有一个带有一个字段的管道,即${first_name}和${description}的串联。您希望输出是一个字段为${description}的管道

如果是这样,我会这样做:实现一个提取描述并让您的流执行它的方法

您的函数(我们称之为ExtractDescriptionFunction)应该重写方法操作,如下所示:

@Override
public void operate(FlowProcess flowProcess, FunctionCall<Tuple> functionCall) {
  TupleEntry arguments = functionCall.getArguments();

  String concatenation = arguments.getString("$input_field_name");
  String[] values = concatenation.split("\\|"); // you might want to have some data sanity check here
  String description = values[1];

  Tuple tuple = functionCall.getContext();
  tuple.set(0, description);
  functionCall.getOutputCollector().add(tuple);
}
@覆盖
公共void操作(流程流程、函数调用、函数调用){
TupleEntry arguments=functionCall.getArguments();
字符串连接=arguments.getString($input_field_name”);
String[]values=concatenation.split(\\\\;”;//您可能需要在此处进行一些数据健全性检查
字符串描述=值[1];
Tuple Tuple=functionCall.getContext();
tuple.set(0,描述);
functionCall.getOutputCollector().add(元组);
}
然后,在流定义中添加以下内容:

Pipe outputPipe=neweach(inputPipe,newextractDescriptionFunction())


希望这有帮助。

我不明白你想说什么。您的意思是提取管道范围之外的字段
${description}
的值吗。如果可能的话,在伪代码中使用类似的内容


str=get value of description ininputPipe(在作业范围内,而不是函数或缓冲区)

Hadoop级联是通过在管道之间流动数据并在Map Reduce Hadoop系统上并行执行来创建真实场景的概念而开发的

java程序的执行不必依赖于级联流的其余部分(从创建源tap到接收器tap),Hadoop级联的作用是:它在不同的独立JVM实例中执行这两个不同的进程,它们将无法共享它们的值

以下代码及其输出显示了简短提示:

System.out.println("Before Debugging");
m_eligPipe = new Each(m_eligPipe, new Fields("first_name"), new Debug("On Middle", true));
System.out.println("After Debugging");
预期输出:

Before Debugging
On Middle: ['first_name']
On Middle: ['Binod']
On Middle: ['Rohit']
On Middle: ['Ramesh']
After Debugging
Before Debugging
After Debugging
...
...
On Middle: ['first_name']
On Middle: ['Binod']
On Middle: ['Rohit']
On Middle: ['Ramesh']
实际输出:

Before Debugging
On Middle: ['first_name']
On Middle: ['Binod']
On Middle: ['Rohit']
On Middle: ['Ramesh']
After Debugging
Before Debugging
After Debugging
...
...
On Middle: ['first_name']
On Middle: ['Binod']
On Middle: ['Rohit']
On Middle: ['Ramesh']

谢谢你的回答,但我的问题是“我们能在管道外提取描述吗?通过上述函数,描述被提取,但仍在管道内。我想提取该描述,并想将其用作管道外的条件,如:if(description!=null){something;}(如果我们不能提取原因是什么?).我认为级联不支持在运行时定义流。整个数据集共享同一管道。也就是说,过滤器可能会有所帮助。在流定义中,可以有如下内容:
pipedescriptionnullpipe=neweach(inPipe,newcheckdescriptioninsullfilter())
管道描述NotNullPipe=new Each(inPipe,new Not(new checkDescriptionInAllFilter())