Java 级联-如何读取分隔符分隔的文件并获取特定字段值

Java 级联-如何读取分隔符分隔的文件并获取特定字段值,java,cascading,Java,Cascading,我尝试使用级联来读取分隔符分隔的文件,并尝试读取特定字段 代码示例: FileTap inTap = new FileTap(new TextDelimited( true, "," ), "C://Users//user//Desktop//test//file.txt"); name,age,email 文件内容: FileTap inTap = new FileTap(new TextDelimited( true, "," ), "C://Users//user//Desktop//

我尝试使用级联来读取分隔符分隔的文件,并尝试读取特定字段

代码示例:

FileTap inTap = new FileTap(new TextDelimited( true, "," ), "C://Users//user//Desktop//test//file.txt");
name,age,email
文件内容:

FileTap inTap = new FileTap(new TextDelimited( true, "," ), "C://Users//user//Desktop//test//file.txt");
name,age,email
如何从所有记录中仅获取
name
字段


更新:我正在尝试使用级联API类来实现这一点。

您应该使用TextLine方案,而不是textdimited方案

new Hfs(new cascading.scheme.hadoop.TextLine(asSourceFields), filePath, SinkMode.REPLACE);
从该源代码点击中读取一行后,必须使用
cascading.operation.Function
拆分该行并创建一个仅包含“name”字段的元组

举个例子

public class SplitLine extends BaseOperation implements Function {

    public SplitLine() {
        super(1, new Fields("name"));
    }

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

        String line = arguments.getString(0);
        String[] tokens = line.split("\t");

        // Check that the split worked as assumed.
        if (tokens.length == 3) {
            Tuple output = new Tuple("name");
            output.set(0, tokens[0]);

            functionCall.getOutputCollector().add(output);
        }
    }
}

您应该使用文本行方案而不是文本分隔方案

new Hfs(new cascading.scheme.hadoop.TextLine(asSourceFields), filePath, SinkMode.REPLACE);
从该源代码点击中读取一行后,必须使用
cascading.operation.Function
拆分该行并创建一个仅包含“name”字段的元组

举个例子

public class SplitLine extends BaseOperation implements Function {

    public SplitLine() {
        super(1, new Fields("name"));
    }

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

        String line = arguments.getString(0);
        String[] tokens = line.split("\t");

        // Check that the split worked as assumed.
        if (tokens.length == 3) {
            Tuple output = new Tuple("name");
            output.set(0, tokens[0]);

            functionCall.getOutputCollector().add(output);
        }
    }
}

@Chris311:我尝试使用级联API类而不是普通Java来完成此操作。@Chris311:我尝试使用级联API类而不是普通Java来完成此操作。谢谢详细的回答。谢谢详细的回答。