Python and Java support for serverless tasks¶
Serverless tasks can invoke the following object types and functions: user-defined functions (UDFs) and stored procedures written in Python, Java, and Scala.
You can use Python or Java in your tasks in a few different ways. To understand the difference between these options, see Choosing whether to write a stored procedure or a user-defined function.
User-defined functions¶
You can create UDFs to call in your task’s AS clause. You can use UDFs to perform operations not available in SQL. For more information about UDFs, see User-defined functions overview.
The following examples in Python and Java create a function that adds one to the input value.
The following examples create my_task2 that adds one to the return value of my_task1.
Stored procedures¶
You can create stored procedures to call in your task’s AS clause. Stored procedures generally perform administrative operations by executing SQL statements. For more information about stored procedures, see Stored procedures overview.
The following examples in Python and Java accept a table name and role name to return a filtered table with rows that match the specified role.
The following examples create task2 that calls the stored procedure with the table returned from task1 and the role of dev.
SQL AS clause¶
You can also define Python or Java code directly in the AS clause of your task definition.
The following example uses Python to set the return value of task2 to a string.