Пример #1
0
  @Override
  protected Triple nextInternal() throws IOException {

    // next is null

    if (null == scannerHeap) {
      initialize();
    }

    while (!scannerHeap.isEmpty()) {

      // get next triple
      Triple next = popTriple();

      while (!scannerHeap.isEmpty()) {
        Triple peek = scannerHeap.peek().peek();

        if (!order.comparator().match(next, peek)) {
          break;
        }
        // remove top scanner
        popTriple();
        // next and peek match... merge them
        next = Triple.merge(next, peek);
        // keep on merging until all matches are done.
        if (null == next) {
          // triples and deletes canceled each other out
          break;
        }
      }

      // are we done? ignore left over deletes
      // EDIT: deletes are filtered in another layer.
      if (null != next /*&& !next.isDelete()*/) {
        return next;
      }
    }

    // all scanners done
    return null;
  }
Пример #2
0
  @Override
  public int run(String[] args) throws Exception {
    Job job = new Job(getConf());
    job.setJarByClass(PredicateCount.class);
    job.setJobName("PredicateCount");

    job.setOutputKeyClass(BytesWritable.class);
    job.setOutputValueClass(IntWritable.class);

    job.setMapperClass(Map.class);
    job.setCombinerClass(Reduce.class);
    job.setReducerClass(Reduce.class);

    job.setInputFormatClass(TripleInputFormat.class);
    job.setOutputFormatClass(SequenceFileOutputFormat.class);

    int argc = 0;

    TripleInputFormat.setStoreAddress(job, args[argc++]);
    TripleInputFormat.setIndex(job, args[argc++]);
    if ("-p".equals(args[argc])) {
      argc++;
      String s = args[argc++];
      String p = args[argc++];
      String o = args[argc++];
      if ("*".equals(s)) s = null;
      if ("*".equals(p)) p = null;
      if ("*".equals(o)) o = null;
      TripleInputFormat.setPattern(job, Triple.newPattern(s, p, o));
    } else {
      FileOutputFormat.setOutputPath(job, new Path(args[argc]));
    }

    boolean success = job.waitForCompletion(true);
    return success ? 0 : 1;
  }
Пример #3
0
 public void map(NullWritable key, Triple value, Context context)
     throws IOException, InterruptedException {
   pred.set(value.getBuffer(), value.getPredicateOffset(), value.getPredicateLength());
   context.write(pred, one);
 }