blob: e8cdf4bb4eb9710652f608448fff1a505b7d6fcb [file] [log] [blame]
/*
* Copyright 2016, Yahoo! Inc.
* Licensed under the terms of the Apache License 2.0. See LICENSE file at the project root for terms.
*/
package com.yahoo.sketches.hive.quantiles;
import java.util.Comparator;
import org.apache.hadoop.io.BytesWritable;
import com.yahoo.sketches.ArrayOfItemsSerDe;
import com.yahoo.sketches.ArrayOfStringsSerDe;
import com.yahoo.sketches.quantiles.ItemsSketch;
import org.testng.annotations.Test;
import org.testng.Assert;
@SuppressWarnings("javadoc")
public class GetKFromStringsSketchUDFTest {
static final Comparator<String> comparator = Comparator.naturalOrder();
static final ArrayOfItemsSerDe<String> serDe = new ArrayOfStringsSerDe();
@Test
public void nullSketch() {
Integer result = new GetKFromStringsSketchUDF().evaluate(null);
Assert.assertNull(result);
}
@Test
public void normalCase() {
ItemsSketch<String> sketch = ItemsSketch.getInstance(comparator);
Integer result = new GetKFromStringsSketchUDF().evaluate(new BytesWritable(sketch.toByteArray(serDe)));
Assert.assertNotNull(result);
Assert.assertEquals(result, Integer.valueOf(128));
}
}