@Test
public void testApproxPercentile()
throws Exception
{
MaterializedResult raw = computeActual("SELECT orderstatus, orderkey, totalprice FROM ORDERS");
Multimap<String, Long> orderKeyByStatus = ArrayListMultimap.create();
Multimap<String, Double> totalPriceByStatus = ArrayListMultimap.create();
for (MaterializedTuple tuple : raw.getMaterializedTuples()) {
orderKeyByStatus.put((String) tuple.getField(0), (Long) tuple.getField(1));
totalPriceByStatus.put((String) tuple.getField(0), (Double) tuple.getField(2));
}
MaterializedResult actual = computeActual("" +
"SELECT orderstatus, " +
" approx_percentile(orderkey, 0.5), " +
" approx_percentile(totalprice, 0.5)," +
" approx_percentile(orderkey, 2, 0.5)," +
" approx_percentile(totalprice, 2, 0.5)\n" +
"FROM ORDERS\n" +
"GROUP BY orderstatus");
for (MaterializedTuple tuple : actual.getMaterializedTuples()) {
String status = (String) tuple.getField(0);
Long orderKey = (Long) tuple.getField(1);
Double totalPrice = (Double) tuple.getField(2);
Long orderKeyWeighted = (Long) tuple.getField(3);
Double totalPriceWeighted = (Double) tuple.getField(4);