public Tuple exec()

in src/main/java/org/apache/datasketches/pig/quantiles/GetPmfFromStringsSketch.java [43:68]


  public Tuple exec(final Tuple input) throws IOException {
    if (input.size() < 2) {
      throw new IllegalArgumentException("expected two or more inputs: sketch and list of split points");
    }

    if (!(input.get(0) instanceof DataByteArray)) {
      throw new IllegalArgumentException(
          "expected a DataByteArray as a sketch, got " + input.get(0).getClass().getSimpleName());
    }
    final DataByteArray dba = (DataByteArray) input.get(0);
    final ItemsSketch<String> sketch =
        ItemsSketch.getInstance(Memory.wrap(dba.get()), Comparator.naturalOrder(),
            new ArrayOfStringsSerDe());

    final String[] splitPoints = new String[input.size() - 1];
    for (int i = 1; i < input.size(); i++) {
      if (!(input.get(i) instanceof String)) {
        throw new IllegalArgumentException("expected a string value as a split point, got "
      + input.get(i).getClass().getSimpleName());
      }
      splitPoints[i - 1] = (String) input.get(i);
    }
    final double[] pmf = sketch.getPMF(splitPoints);
    if (pmf == null) { return null; }
    return Util.doubleArrayToTuple(pmf);
  }