public String exec()

in src/main/java/org/apache/datasketches/pig/quantiles/GetQuantileFromStringsSketch.java [42:61]


  public String exec(final Tuple input) throws IOException {
    if (input.size() != 2) {
      throw new IllegalArgumentException("expected two inputs: sketch and fraction");
    }

    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());

    if (!(input.get(1) instanceof Double)) {
      throw new IllegalArgumentException(
          "expected a double value as a fraction, got " + input.get(1).getClass().getSimpleName());
    }
    final double fraction = (double) input.get(1);
    return sketch.getQuantile(fraction);
  }