@Override public void selectCells(GlobalIndex<Partition> gIndex, ResultCollector<Partition> output) { int numPartitions; if (gIndex.isReplicated()) { // Need to process all partitions to perform duplicate avoidance numPartitions = gIndex.rangeQuery(queryRange, output); LOG.info("Selected " + numPartitions + " partitions overlapping " + queryRange); } else { Prism queryRange = this.queryRange.getMBR(); // Need to process only partitions on the perimeter of the query // range // Partitions that are totally contained in query range should // not be // processed and should be copied to output directly numPartitions = 0; for (Partition p : gIndex) { if (queryRange.contains(p)) { // TODO partitions totally contained in query range // should be copied // to output directly // XXX Until hard links are supported, R-tree blocks are // processed // similar to R+-tree output.collect(p); numPartitions++; } else if (p.isIntersected(queryRange)) { output.collect(p); numPartitions++; } } LOG.info("Selected " + numPartitions + " partitions on the perimeter of " + queryRange); } }
/** * 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; }