Skip to main content

argmax aggregate function

  • April 19, 2017
  • 2 replies
  • 17 views

amosmoss

Hi all,

I am wondering if there is an implementation for the argmax aggregate function in vertica.
ARGMAX(col_a, col_c) returns col_c's value, for which col_a has the largest value.

This can also be used within analytic windows and ranges.

Thanks,
Amos.

2 replies

amosmoss
  • Author
  • New Participant
  • April 23, 2017

Thanks Eugenia :)

Is there a way to create a feature request for this? I'm assuming UDTFS are not as fast as native functions. Am I right?

Best,
Amos.


amosmoss
  • Author
  • New Participant
  • April 23, 2017

Hi,

The thing is that this kind of aggregate function needs to materialize the second argument, only after we find the max of the first one, and not for every row. So I don't think is would be as efficient as possible.

In addition, from what I read in the docs, only one UDTF is allowed in the select clause, without anything else, which misses the whole point of issuing a a query such:

-- Getting the highest earning employee in each department
select argmax(salery, employee_name), department
from employees
group by department;

or even:
-- For each employee, get the salery diff to the department's senior
select employee_name, argmax(age, salery) over (partition by department) - salery as salery_diff_to_senior
from employees;

Is there a way keep track on this feature request?

Thanks,
Amos.