/*
   * (non-Javadoc)
   *
   * @see
   * com.basho.riak.client.raw.RawClient#fetchIndex(com.basho.riak.client.
   * raw.query.IndexQuery)
   */
  public List<String> fetchIndex(IndexQuery indexQuery) throws IOException {
    final MapReduce mr = new IndexMapReduce(this, indexQuery);

    mr.addReducePhase(NamedErlangFunction.REDUCE_IDENTITY, Args.REDUCE_PHASE_ONLY_1);
    // only return the key, to match the http rest api
    mr.addReducePhase(
        new JSSourceFunction("function(v) { return v.map(function(e) { return e[1]; }); }"),
        Args.REDUCE_PHASE_ONLY_1);

    try {
      MapReduceResult result = mr.execute();
      return new ArrayList<String>(result.getResult(String.class));
    } catch (RiakException e) {
      throw new IOException(e);
    }
  }
        public void reduce(String key, Cons value, MapReduce mr) {
          // System.out.println("  red1 key = " + key + "  val = " + value.toString());
          int sum = 0;
          for (Cons lst = value; lst != null; lst = rest(lst)) {
            sum += Integer.decode((String) first((Cons) first(lst)));
          }

          mr.collect_reduce(key, new Integer(sum));
        }
Пример #3
0
 public MapReduce mapreduce() {
   return MapReduce.create(this);
 }
 public void map(String key, String value, MapReduce mr) {
   mr.collect_map("line", list("1"));
 }