Skip to content
Advertisement

Avoid computing same value multiple times in Presto

Sample Table :

Desired output :

Currently I am trying to write a Presto Query to use on Amazon Athena,

the above query causes split(dummy_data,'_')[2] to be computed two times. If there a way to avoid the double computation ? Also does Presto figure out that its the same computation and avoids recomputing ?

I am trying to avoid using sub-query or With clause.

Advertisement

Answer

Currently Presto does not de-decuplicate sub-expression calculations. I created feature request for this: https://github.com/prestosql/presto/issues/1070. You can see that the expression is evaluated more than once by checking the EXPLAIN output (see the issue for example).

As you know, you can force de-duplication by using an inline view:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement