blob: 6bb8cfb6e04c3dcdf604d9535b8b158a3abd8fc4 [file] [log] [blame]
/*
* Copyright 2018, Oath 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.kll;
import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.BytesWritable;
import com.yahoo.memory.Memory;
import com.yahoo.sketches.kll.KllFloatsSketch;
@Description(name = "SketchToString", value = "_FUNC_(sketch)",
extended = " Returns a human-readable summary of a given KllFloatsSketch.")
public class SketchToStringUDF extends UDF {
/**
* Returns a summary of a given sketch
* @param serializedSketch serialized sketch
* @return text summary
*/
public String evaluate(final BytesWritable serializedSketch) {
if (serializedSketch == null) { return null; }
final KllFloatsSketch sketch = KllFloatsSketch.heapify(Memory.wrap(serializedSketch.getBytes()));
return sketch.toString();
}
}