trinodb / trino

Official repository of Trino, the distributed SQL query engine for big data, formerly known as PrestoSQL (https://trino.io)
https://trino.io
Apache License 2.0
10.19k stars 2.94k forks source link

Function currying #1062

Open findepi opened 5 years ago

findepi commented 5 years ago

Some functions are often invoked with one argument being a constant and they do some preparatory computations that do not need to be done for each row.

Example: date_format builds a format object from format string, before considering datetime argument.

Such functions could benefit from "currying", allowing certain computations to be done when only some argument is bound but not all yet. The "known" argument may be a constant or may be a value which is constant for a batch of rows (e.g. partition key, or anything stored in RLE block).

dain commented 5 years ago

Currently this is handled in regex and Json functions by introducing new types for the computed value, and then relying on the constant folder to convert this to constants which are bound into the generated byte code. This is of course pretty cumbersome.

Do you have thoughts on how this would work in practice?

BTW, I'd like to have a system that could capture the "extra" computed values used by PolymorphicScalarFunction.