Ejemplo n.º 1
0
    @Override
    public void reduce(Text key, Iterable<Text> values, Context context)
        throws IOException, InterruptedException {
      // For each value, figure out which file it's from and store it
      // accordingly.
      List<String> first = new ArrayList<String>();
      List<String> second = new ArrayList<String>();

      for (Text value : values) {
        if (value.charAt(0) == '1') {
          first.add(value.toString().substring(1));
        } else second.add(value.toString().substring(1));
        context.setStatus("OK");
      }

      context.setStatus("OK");

      if (first.size() == 0) return;
      if (second.size() == 0) second.add(null);

      // Do the cross product
      for (String s1 : first) {
        for (String s2 : second) {
          if (s2 == null) OUT.set(key.toString() + "\t" + s1 + "\t\t");
          else OUT.set(key.toString() + "\t" + s1 + "\t" + key.toString() + "\t" + s2);
          context.write(NULL, OUT);
        }
      }
    }
Ejemplo n.º 2
0
 public int[] searchBounds(Text key) throws IOException {
   if (key.getLength() == 0) return defaultReturn;
   int[] boundaries = map.get(key.charAt(0));
   if (boundaries == null) return defaultReturn;
   return boundaries;
 }
Ejemplo n.º 3
0
    public void map(Object key, Text value, Context context)
        throws IOException, InterruptedException {
      int start = 0;
      while (start < value.getLength()) {
        // Find the start of a node
        start = value.find("node", start);

        if (start == -1) break;

        // Find the id of that node
        start = value.find(" id", start);
        if (start == -1) break;
        start += 5;
        int c = ':';
        StringBuilder temp = new StringBuilder();
        for (; start < value.getLength(); start++) {
          c = value.charAt(start);
          if (c != '"') temp.append(c);
          else break;
        }
        if (start > value.getLength()) break;
        try {
          id.set(Long.parseLong(temp.toString()));
        } catch (NumberFormatException e) {
          // My Job isn't to worry about java not having unsigned values because they are stupid
          id.set(404);
        }

        start = value.find(" lat", start);
        if (start == -1) break;
        start += 6;
        c = ':';
        temp.delete(0, temp.length());
        for (; start < value.getLength(); start++) {
          c = value.charAt(start);
          if (c != '"') temp.append((char) c);
          else break;
        }
        if (start > value.getLength()) break;
        node.setY(Double.parseDouble(temp.toString()));
        if (node.getY() < minlat || node.getY() > maxlat) {
          continue; // Don't care about nodes outside our area of interest
        }

        start = value.find(" lon", start);
        if (start == -1) break;
        start += 6;
        c = ':';
        temp.delete(0, temp.length());
        for (; start < value.getLength(); start++) {
          c = value.charAt(start);
          if (c != '"') temp.append((char) c);
          else break;
        }
        if (start > value.getLength()) break;
        node.setX(Double.parseDouble(temp.toString()));
        if (node.getX() < minlon || node.getX() > maxlon)
          continue; // Don't care about nodes outside our area of interest
        context.write(node, id);
      }
    }