blob: 2c8ef6e0be5835d4f016809deb986aa5d32c62a9 [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.")
@SuppressWarnings("javadoc")
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();
}
}