Manfred and Cole are joined by David Phillips to talk about the new support of user-defined functions written in Python. We discuss motivation, development history, dive into implementation details, and explore some examples.
Follow are some highlights of the Trino releases since episode 67:
random_string
function for the Faker
connector.extra_properties
in the Iceberg connector.geometry
type in the PostgreSQL connector.launcher
script.microdnf
package manager from the Docker image.$all_manifests
metadata tables in the Iceberg connector.$transactions
metadata table in the Delta Lake connector.MERGE
statements for PostgreSQL.As always, numerous performance improvements, bug fixes, and other features were added as well.
First there were custom plugins with user defined functions, and for a long time, that was all there is.
In 2023, David contributed SQL user-defined functions, also known as SQL routines, and we ran a competition for examples. Manfred wrote the docs and did a training session with Dain and Martin. And even back then, David had plans to add other languages, and started working on Python.
At Trino Summit in 2024 Martin Traverso announced the new upcoming feature in the keynote, and with Trino 468 we shipped support for Python user-defined functions.
Why support Python for user-defined functions, as compared to just SQL? Simply put, more is better, and Python is everywhere. We chat with David about the details.
David tell us more about figuring out how to make it all work at all. He touches on topics such as security, performance, deployment, monitoring, and collaboration with other projects. We also talk about why other approaches like using local CPython were discarded.
In this discussion we talk try to cover the following topics:
Let’s chat about this nesting:
A simple example from the documentation:
FUNCTION python_udf_name(input_parameter data_type)
RETURNS result_data_type
LANGUAGE PYTHON
WITH (handler = 'python_function')
AS $$
...
def python_function(input):
return ...
...
$$
David shows us more, and we talk about the details.
We are looking for feedback:
Future work depends on the feedback but definitely includes the following:
If you want to learn more about Trino, check out the definitive guide from O’Reilly. You can get the free PDF from Starburst or buy the English, Polish, Chinese, or Japanese edition.