Dynamic output parameters in Python UDF

IljaHramcov
Padawan

Hello everyone,
I have written a Python UDF that produces an undefined number of columns. I want to set the output parameters dynamically (there are sometimes 1300 columns). In the run() function a dataframe is generated, where the column names and datatypes are available. I now know that the function default_output_columns() is executed before the run() function. Is there still a way to pass this dataframe to the default_output_columns() function as a parameter? Or can I somehow use the ctx object in the default_output_columns() function?

Many greetings
Ilja

2 REPLIES 2

littlekoi
Xpert

Generally speaking, you have to know all columns and types before execution of run().

Exasol sever must be able to plan query ahead, and in order to plan it all output columns are required.

If you run query with UDF from remote Python script, you may be able to access config or metadata required to build column list. And you can build it using EMITS query part:

For example:

SELECT my_udf(a, b, c, d) EMITS (id DECIMAL(9,0), str VARCHAR(100), ...)
FROM ...

EMITS is generated dynamically outside of Exasol in a script which builds and runs this query.

exa-Chris
Community Manager
Community Manager

Good Morning Ilja,
thanks for the patience, I nudged internally to see how we quickly can reply.

Rgds

exa-Chris

Connecting Customers, Partners, Prospects and Exasolians is my passion. Apart from that I cycle, listen to music, and try to understand what all those technical discussions really mean...