All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.sketches.hive.quantiles.GetKFromDoublesSketchUDF Maven / Gradle / Ivy

There is a newer version: 0.13.0
Show newest version
/*
 * 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 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.quantiles.DoublesSketch;

@Description(name = "GetK", value = "_FUNC_(sketch)",
extended = " Returns parameter K from a given DoublesSketch sketch.")
public class GetKFromDoublesSketchUDF extends UDF {

  /**
   * Returns parameter K from a given sketch
   * @param serializedSketch serialized sketch
   * @return parameter K
   */
  public Integer evaluate(final BytesWritable serializedSketch) {
    if (serializedSketch == null) { return null; }
    final DoublesSketch sketch = DoublesSketch.wrap(Memory.wrap(serializedSketch.getBytes()));
    return sketch.getK();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy