Java Code Examples for org.apache.hadoop.mapred.InputSplit#getLocations()

The following examples show how to use org.apache.hadoop.mapred.InputSplit#getLocations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SingleDataCenterEvaluatorToPartitionStrategy.java    From reef with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateLocations(final NumberedSplit<InputSplit> numberedSplit) {
  try {
    final InputSplit split = numberedSplit.getEntry();
    final String[] locations = split.getLocations();
    for (final String location : locations) {
      BlockingQueue<NumberedSplit<InputSplit>> newSplitQue = new LinkedBlockingQueue<>();
      final BlockingQueue<NumberedSplit<InputSplit>> splitQue = locationToSplits.putIfAbsent(location, newSplitQue);
      if (splitQue != null) {
        newSplitQue = splitQue;
      }
      newSplitQue.add(numberedSplit);
    }
  } catch (final IOException e) {
    throw new RuntimeException("Unable to get InputSplits using the specified InputFormat", e);
  }
}
 
Example 2
Source File: SparkSourceUtil.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the source location of a Spark partition.
 *
 * @param partition the partition to get location.
 * @return a list of locations.
 * @throws RuntimeException if failed to get source location.
 */
static List<String> getPartitionLocation(final Partition partition) {
  try {
    if (partition instanceof HadoopPartition) {
      final Field inputSplitField = partition.getClass().getDeclaredField("inputSplit");
      inputSplitField.setAccessible(true);
      final InputSplit inputSplit = (InputSplit) ((SerializableWritable) inputSplitField.get(partition)).value();

      final String[] splitLocations = inputSplit.getLocations();
      final List<String> parsedLocations = new ArrayList<>();

      for (final String loc : splitLocations) {
        final String canonicalHostName = InetAddress.getByName(loc).getCanonicalHostName();
        parsedLocations.add(canonicalHostName);
      }

      if (parsedLocations.size() == 1 && parsedLocations.get(0).equals("localhost")) {
        return Collections.emptyList();
      } else {
        return parsedLocations;
      }
    } else {
      return Collections.emptyList();
    }
  } catch (final Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 3
Source File: CompositeInputSplit.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Collect a set of hosts from all child InputSplits.
 */
public String[] getLocations() throws IOException {
  HashSet<String> hosts = new HashSet<String>();
  for (InputSplit s : splits) {
    String[] hints = s.getLocations();
    if (hints != null && hints.length > 0) {
      for (String host : hints) {
        hosts.add(host);
      }
    }
  }
  return hosts.toArray(new String[hosts.size()]);
}
 
Example 4
Source File: CompositeInputSplit.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Collect a set of hosts from all child InputSplits.
 */
public String[] getLocations() throws IOException {
  HashSet<String> hosts = new HashSet<String>();
  for (InputSplit s : splits) {
    String[] hints = s.getLocations();
    if (hints != null && hints.length > 0) {
      for (String host : hints) {
        hosts.add(host);
      }
    }
  }
  return hosts.toArray(new String[hosts.size()]);
}
 
Example 5
Source File: CompositeInputSplit.java    From RDFS with Apache License 2.0 5 votes vote down vote up
/**
 * Collect a set of hosts from all child InputSplits.
 */
public String[] getLocations() throws IOException {
  HashSet<String> hosts = new HashSet<String>();
  for (InputSplit s : splits) {
    String[] hints = s.getLocations();
    if (hints != null && hints.length > 0) {
      for (String host : hints) {
        hosts.add(host);
      }
    }
  }
  return hosts.toArray(new String[hosts.size()]);
}
 
Example 6
Source File: CompositeInputSplit.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
/**
 * Collect a set of hosts from all child InputSplits.
 */
public String[] getLocations() throws IOException {
  HashSet<String> hosts = new HashSet<String>();
  for (InputSplit s : splits) {
    String[] hints = s.getLocations();
    if (hints != null && hints.length > 0) {
      for (String host : hints) {
        hosts.add(host);
      }
    }
  }
  return hosts.toArray(new String[hosts.size()]);
}