GitHub user zyratlo added a comment to the discussion: Feature Proposal: Extend 
Python UDF operators to allow users to modify parameters without editing the 
code

Sure. Here is a simple workflow to demonstrate how we can expose parameters 
using a Text Input Operator.

<img width="441" height="272" alt="image" 
src="https://github.com/user-attachments/assets/05ab9840-d6cc-4e01-83e2-af5972224791";
 />

The Python UDF takes a CSV file as input and performs an ML training algorithm. 
In this example, the developer has chosen to make the `test_size` and 
`random_seed` parameters configurable. To support this, an additional `Text 
Input` operator has been added as input to the UDF. The source code of the UDF 
must take into account both input ports, which is shown in the below screenshot:

<img width="1452" height="920" alt="image" 
src="https://github.com/user-attachments/assets/3a3f59c1-b104-470d-ae5b-8d8f1d12bf32";
 />

In the code, the `if` block executes on port 0, which is the parameter input. 
This code sets the class variable `parameters` to hold the values for 
`test_size` and `random_seed`. The `else` block will execute on any other port, 
so it runs with the CSV file input and will use the inputted values for the two 
parameters.

To ensure the parameters are processed first before the rest of the code, we 
ensure that the `File Scan Port` has a dependency on port 0 (since input ports 
are numbered top-down beginning at 0). This will mean that the `File Scan Port` 
will not be processed until the `Parameter Port` has finished:

<img width="499" height="330" alt="image" 
src="https://github.com/user-attachments/assets/503747d1-0319-4f9e-b7ea-4e845bf1f10c";
 />

Now, when the non-coding user wants to modify the parameters, they can simply 
edit the text in the `Text Input` operator instead of directly changing the UDF 
code.

<img width="552" height="330" alt="image" 
src="https://github.com/user-attachments/assets/995c5d22-8318-4396-9208-68fb8804c525";
 />

In this example, the developer assumes the formatting and order of the 
parameters will be consistent. However, it is easy to convert this to be 
dynamic parsing instead.

GitHub link: 
https://github.com/apache/texera/discussions/4154#discussioncomment-15481568

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]

Reply via email to