question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add array_average function

See original GitHub issue

Would be great if trino can add array_average and array_sum functions like in presto

array_average(array(double)) → double#
Returns the average of all non-null elements of the array. If there is no non-null elements, returns null.
array_sum(array(T)) → bigint/double#
Returns the sum of all non-null elements of the array. If there is no non-null elements, returns 0. The behavior is similar to aggregation function sum().

T must be coercible to double. Returns bigint if T is coercible to bigint. Otherwise, returns double.

https://prestodb.io/docs/current/functions/array.html

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mdesmetcommented, Mar 7, 2022

From an end user perspective, it sill makes sense to add these functions similar to other database engines: It will be much easier to use and much readable and compact using array_average compared to subqueries or UNNEST.

One question i had in the PR is about rewriting those queries into some construct already supported (array_reduce/unnest/…) or a proper implementation.

@martint, @ebyhr : Can we make a decision, if we want to support this function? if yes how to support it by rewriting or by a proper implementation.

IMHO rewriting is better, but i would rather rewrite it to array_reduce then to unnest.

1reaction
ebyhrcommented, Aug 7, 2021

Let me change the title as there is another issue for array_sum in #4346

Read more comments on GitHub >

github_iconTop Results From Across the Web

Finding the average of an array using JS - Stack Overflow
You calculate an average by adding all the elements and then dividing by the number of elements. var ...
Read more >
JavaScript How to Calculate Average of an Array
To find the average of an array in JavaScript, calculate the sum of the elements and divide the sum by the length of...
Read more >
Javascript: Getting Average value of an Array - Flexiple
Simple approach to finding the average of an array ... We would first count the total number of elements in an array followed...
Read more >
Program for average of an array (Iterative and Recursive)
Given an array, the task is to find average of that array. Average is the sum of array elements divided by the number...
Read more >
C Program to Calculate Average Using Arrays - Programiz
In this C programming example, you will learn to calculate the average of n number of elements entered by the user using arrays....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found