Example usage for org.apache.hadoop.mapreduce InputSplit getLocationInfo

List of usage examples for org.apache.hadoop.mapreduce InputSplit getLocationInfo

Introduction

In this page you can find the example usage for org.apache.hadoop.mapreduce InputSplit getLocationInfo.

Prototype

@Evolving
public SplitLocationInfo[] getLocationInfo() throws IOException 

Source Link

Document

Gets info about which nodes the input split is stored on and how it is stored at each location.

Usage

From source file:org.apache.vxquery.hdfs2.HDFSFunctions.java

License:Apache License

/**
 * Create a HashMap that has as key the hostname and values the splits that belong to this hostname;
 * //www.j  ava  2  s .c  o  m
 * @return
 * @throws IOException
 */
public HashMap<String, ArrayList<Integer>> getLocationsOfSplits() throws IOException {
    HashMap<String, ArrayList<Integer>> splits_map = new HashMap<String, ArrayList<Integer>>();
    ArrayList<Integer> temp;
    int i = 0;
    String hostname;
    for (InputSplit s : this.splits) {
        SplitLocationInfo info[] = s.getLocationInfo();
        hostname = info[0].getLocation();
        if (splits_map.containsKey(hostname)) {
            temp = splits_map.get(hostname);
            temp.add(i);
        } else {
            temp = new ArrayList<Integer>();
            temp.add(i);
            splits_map.put(hostname, temp);
        }
        i++;
    }

    return splits_map;
}