blob: 028cc454137d5de0142db681bbc311755f97259b [file] [log] [blame]
/*
* Copyright 2019, Verizon Media.
* 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;
public class GetNFromStringsSketchUDFTest {
static final Comparator<String> comparator = Comparator.naturalOrder();
static final ArrayOfItemsSerDe<String> serDe = new ArrayOfStringsSerDe();
@Test
public void nullSketch() {
Long result = new GetNFromStringsSketchUDF().evaluate(null);
Assert.assertNull(result);
}
@Test
public void normalCase() {
ItemsSketch<String> sketch = ItemsSketch.getInstance(comparator);
sketch.update("a");
sketch.update("b");
sketch.update("c");
Long result = new GetNFromStringsSketchUDF().evaluate(new BytesWritable(sketch.toByteArray(serDe)));
Assert.assertNotNull(result);
Assert.assertEquals(result, Long.valueOf(3));
}
}