Search in sources :

Example 1 with TextInputFormatter

use of edu.iu.dsc.tws.data.api.formatters.TextInputFormatter in project twister2 by DSC-SPIDAL.

the class WordCountExample method init.

@Override
public void init(Config config, int id, ResourcePlan resourcePlan) {
    Config.Builder builder = new Config.Builder();
    builder.put("input.file.path", "/home/pulasthi/git/twister2/twister2" + "/data/src/test/resources/TextInputFormatTestFile.text");
    Config txtFileConf = builder.build();
    Path path = new Path("/home/pulasthi/git/twister2/twister2/data/src/test/" + "resources/TextInputFormatTestFile.text");
    @SuppressWarnings("unchecked") InputFormat txtInput = new TextInputFormatter(path);
    txtInput.configure(txtFileConf);
    int minSplits = 8;
    try {
        InputSplit[] inputSplits = txtInput.createInputSplits(minSplits);
        InputSplitAssigner inputSplitAssigner = txtInput.getInputSplitAssigner(inputSplits);
        MapperSource mapperSource = new MapperSource(txtInput, inputSplitAssigner.getNextInputSplit(null, id));
        Mapper wordCountMapper = new Mapper();
        wordCountMapper.setInputSource(mapperSource);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Path(edu.iu.dsc.tws.data.fs.Path) TextInputFormatter(edu.iu.dsc.tws.data.api.formatters.TextInputFormatter) InputSplitAssigner(edu.iu.dsc.tws.data.fs.io.InputSplitAssigner) Config(edu.iu.dsc.tws.common.config.Config) IOException(java.io.IOException) InputFormat(edu.iu.dsc.tws.data.api.InputFormat) InputSplit(edu.iu.dsc.tws.data.fs.io.InputSplit) FileInputSplit(edu.iu.dsc.tws.data.fs.FileInputSplit)

Aggregations

Config (edu.iu.dsc.tws.common.config.Config)1 InputFormat (edu.iu.dsc.tws.data.api.InputFormat)1 TextInputFormatter (edu.iu.dsc.tws.data.api.formatters.TextInputFormatter)1 FileInputSplit (edu.iu.dsc.tws.data.fs.FileInputSplit)1 Path (edu.iu.dsc.tws.data.fs.Path)1 InputSplit (edu.iu.dsc.tws.data.fs.io.InputSplit)1 InputSplitAssigner (edu.iu.dsc.tws.data.fs.io.InputSplitAssigner)1 IOException (java.io.IOException)1