/** {@inheritDoc} */
  @Override
  public void accumulate(NamedList stv) {
    if (computeCount) {
      count += (Long) stv.get("count");
    }
    if (computeMissing) {
      missing += (Long) stv.get("missing");
    }
    if (computeCalcDistinct) {
      distinctValues.addAll((Collection<T>) stv.get("distinctValues"));
      countDistinct = distinctValues.size();
    }

    if (computeMinOrMax) {
      updateMinMax((T) stv.get("min"), (T) stv.get("max"));
    }

    if (computeCardinality) {
      byte[] data = (byte[]) stv.get("cardinality");
      HLL other = HLL.fromBytes(data);
      if (hll.getType().equals(HLLType.EMPTY)) {
        // The HLL.union method goes out of it's way not to modify the "other" HLL.
        // Which means in the case of merging into an "EMPTY" HLL (garunteed to happen at
        // least once in every coordination of shard requests) it always clones all
        // of the internal storage -- but since we're going to throw "other" away after
        // the merge, this just means a short term doubling of RAM that we can skip.
        hll = other;
      } else {
        hll.union(other);
      }
    }

    updateTypeSpecificStats(stv);

    NamedList f = (NamedList) stv.get(FACETS);
    if (f == null) {
      return;
    }

    for (int i = 0; i < f.size(); i++) {
      String field = f.getName(i);
      NamedList vals = (NamedList) f.getVal(i);
      Map<String, StatsValues> addTo = facets.get(field);
      if (addTo == null) {
        addTo = new HashMap<>();
        facets.put(field, addTo);
      }
      for (int j = 0; j < vals.size(); j++) {
        String val = vals.getName(j);
        StatsValues vvals = addTo.get(val);
        if (vvals == null) {
          vvals = StatsValuesFactory.createStatsValues(statsField);
          addTo.put(val, vvals);
        }
        vvals.accumulate((NamedList) vals.getVal(j));
      }
    }
  }
  /** {@inheritDoc} */
  @Override
  public void accumulate(NamedList stv) {
    count += (Long) stv.get("count");
    missing += (Long) stv.get("missing");
    if (calcDistinct) {
      distinctValues.addAll((Collection<T>) stv.get("distinctValues"));
      countDistinct = distinctValues.size();
    }

    updateMinMax((T) stv.get("min"), (T) stv.get("max"));
    updateTypeSpecificStats(stv);

    NamedList f = (NamedList) stv.get(FACETS);
    if (f == null) {
      return;
    }

    for (int i = 0; i < f.size(); i++) {
      String field = f.getName(i);
      NamedList vals = (NamedList) f.getVal(i);
      Map<String, StatsValues> addTo = facets.get(field);
      if (addTo == null) {
        addTo = new HashMap<String, StatsValues>();
        facets.put(field, addTo);
      }
      for (int j = 0; j < vals.size(); j++) {
        String val = vals.getName(j);
        StatsValues vvals = addTo.get(val);
        if (vvals == null) {
          vvals = StatsValuesFactory.createStatsValues(qcontext, sf, calcDistinct);
          addTo.put(val, vvals);
        }
        vvals.accumulate((NamedList) vals.getVal(j));
      }
    }
  }
 private static void alias(String source, String dest) {
   standardValueSourceParsers.put(dest, standardValueSourceParsers.get(source));
 }
 /**
  * Adds a new parser for the name and returns any existing one that was overriden. This is not
  * thread safe.
  */
 public static ValueSourceParser addParser(NamedParser p) {
   return standardValueSourceParsers.put(p.name(), p);
 }
 /**
  * Adds a new parser for the name and returns any existing one that was overriden. This is not
  * thread safe.
  */
 public static ValueSourceParser addParser(String name, ValueSourceParser p) {
   return standardValueSourceParsers.put(name, p);
 }