예제 #1
0
  /**
   * Runs a range query on the local machine by iterating over the whole file.
   *
   * @param fs - FileSystem that contains input file
   * @param file - path to the input file
   * @param queryRange - The range to look in
   * @param shape - An instance of the shape stored in file
   * @param output - Output is sent to this collector. If <code>null</code>, output is not collected
   *     and only the number of results is returned.
   * @return number of results found
   * @throws IOException
   */
  public static <S extends Shape> long rangeQueryLocal(
      FileSystem fs, Path file, Shape queryRange, S shape, ResultCollector<S> output)
      throws IOException {
    long file_size = fs.getFileStatus(file).getLen();
    ShapeRecordReader<S> shapeReader = new ShapeRecordReader<S>(fs.open(file), 0, file_size);

    long resultCount = 0;
    Prism cell = shapeReader.createKey();

    while (shapeReader.next(cell, shape)) {
      if (shape.isIntersected(queryRange)) {
        boolean report_result;
        if (cell.isValid()) {
          // Check for duplicate avoidance
          Prism intersection_mbr = queryRange.getMBR().getIntersection(shape.getMBR());
          report_result =
              cell.contains(intersection_mbr.t1, intersection_mbr.x1, intersection_mbr.y1);
        } else {
          report_result = true;
        }
        if (report_result) {
          resultCount++;
          if (output != null) {
            output.collect(shape);
          }
        }
      }
    }
    shapeReader.close();
    return resultCount;
  }
예제 #2
0
 @Override
 public void configure(JobConf job) {
   super.configure(job);
   try {
     String queryShapeClassName = job.get(QUERY_SHAPE_CLASS);
     Class<? extends Shape> queryShapeClass =
         Class.forName(queryShapeClassName).asSubclass(Shape.class);
     queryShape = queryShapeClass.newInstance();
     queryShape.fromText(new Text(job.get(QUERY_SHAPE)));
     queryMbr = queryShape.getMBR();
     queryField = job.get(QUERY_FIELD);
   } catch (ClassNotFoundException e) {
     e.printStackTrace();
   } catch (InstantiationException e) {
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   }
 }
예제 #3
0
    /** Map function for non-indexed blocks */
    public void map(
        final Prism cellMbr,
        final Writable value,
        final OutputCollector<Writable, IntWritable> output,
        Reporter reporter)
        throws IOException {
      if (value instanceof Shape) {
        try {
          Shape shape = (Shape) value;
          Class<?> c = shape.getClass();
          Field f;
          f = c.getDeclaredField(queryField);
          f.setAccessible(true);

          if (shape.isIntersected(queryShape)) {
            boolean report_result = false;
            if (cellMbr.isValid()) {
              // Check for duplicate avoidance using reference
              // point
              // technique
              double reference_t = Math.max(queryMbr.t1, shape.getMBR().t1);
              double reference_x = Math.max(queryMbr.x1, shape.getMBR().x1);
              double reference_y = Math.max(queryMbr.y1, shape.getMBR().y1);
              report_result = cellMbr.contains(reference_t, reference_x, reference_y);
            } else {
              // A heap block, report right away
              report_result = true;
            }

            if (report_result) {
              Writable result = null;
              if (f.getType().equals(Integer.TYPE)) {
                try {
                  result = new IntWritable((int) f.get(shape));
                } catch (IllegalArgumentException | IllegalAccessException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
              } else if (f.getType().equals(Long.TYPE)) {
                try {
                  result = new LongWritable((int) f.get(shape));
                } catch (IllegalArgumentException | IllegalAccessException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
              } else if (f.getType().equals(Double.TYPE)) {
                try {
                  result = new DoubleWritable((int) f.get(shape));
                } catch (IllegalArgumentException | IllegalAccessException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
              }
              output.collect(result, one);
            }
          }
        } catch (IllegalArgumentException | NoSuchFieldException | SecurityException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      } else if (value instanceof RTree) {
        RTree<Shape> shapes = (RTree<Shape>) value;
        if (shapes.columnar) {
          shapes.searchColumnar(
              queryMbr,
              new ResultCollector<Writable>() {
                @Override
                public void collect(Writable shape) {
                  try {
                    output.collect(shape, one);
                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                }
              },
              queryField);
        } else {
          shapes.search(
              queryMbr,
              new ResultCollector<Shape>() {
                @Override
                public void collect(Shape shape) {
                  try {
                    Class<?> c = shape.getClass();
                    Field f;
                    f = c.getDeclaredField(queryField);
                    f.setAccessible(true);
                    Writable result = null;
                    if (f.getType().equals(Integer.class)) {
                      result = new IntWritable((int) f.get(shape));
                    } else if (f.getType().equals(Integer.class)) {
                      result = new IntWritable((int) f.get(shape));
                    } else if (f.getType().equals(Integer.class)) {
                      result = new IntWritable((int) f.get(shape));
                    }
                    output.collect(result, one);

                  } catch (IOException e) {
                    e.printStackTrace();
                  } catch (SecurityException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  } catch (IllegalArgumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  } catch (NoSuchFieldException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  } catch (IllegalAccessException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  }
                }
              },
              queryField);
        }
      }
    }