title: Hive UDF With Parameters
body: <p>I want to write a custom UDF (UDAF/UDTF) that can take in a constant parameter.</p>
  
  <p>For example, I want to write a function MAX(COL, i), where COL is the collection of values to find the max value, and i is the position (ie. i = 1, find the highest, i = 2, find the second highest, etc.), such that the Hive query looks like:</p>
  
  <pre><code>SELECT
  MAX(value, 2)
  FROM table;
  </code></pre>
  
  <p>This isn't just for MAX, so I need a general way of being able to do this, so sorting and selecting from the sorted collection will not work.</p>