GitHub user yangzhang75 created a discussion: Proposal: Python UDF parameters that are picked, not typed — a dropdown and the dataset browser
## Summary A Python UDF declares its own parameters in its code, and whoever runs the workflow fills them in from the property panel, or on the Form View from the form. A parameter that names a model or a dataset opens a picker; every other one is a text box, whatever the value means. This proposal lets a parameter say what it accepts, and makes the picker that already exists reach a file and work everywhere. One that lists its values gets a dropdown. One that names a dataset, or a file in one, gets the browser Texera already has. One that says nothing is unchanged. ## Demo https://github.com/user-attachments/assets/22714adc-1beb-41d6-9906-83601bdb426f ## Why 1. **A file has to be spelled out by hand.** A dataset is a versioned container, and each version holds a file tree. The picker stops at the version, so whoever runs the workflow types the rest of the path exactly right, although Texera lists every file a click away elsewhere. 2. **Nothing says what a box accepts.** A parameter that takes one of three methods looks like a parameter that takes any text. A wrong value surfaces when the UDF runs, if at all. The author can only say what is expected in words: the input's help text, or the instructions on the form. ## Proposal A parameter says what it accepts in the same call that already gives it a name and a type. ### 1. A parameter can list its values ```python # today self.method = self.UiParameter("method", AttributeType.STRING).value # proposed self.method = self.UiParameter("method", AttributeType.STRING, choices=["soupx", "decontx"]).value ``` It renders as a dropdown of those values, on the panel and on the form. A value already filled in survives a change to the list, unless the new list no longer offers it. ### 2. A parameter can name a dataset version, or one file in it ```python # the whole version, for a UDF that reads several files out of it self.model_dir = self.UiParameter("model_dir", AttributeType.STRING, value=Resource.DATASET).value # one file, which is what a UDF usually opens self.input_file = self.UiParameter("input_file", AttributeType.STRING, value=Resource.DATASET_FILE).value ``` Naming a dataset this way already exists; these are two members of the enum it already uses, so there is one way to point a parameter at a resource, not two. Each browser only answers what was asked for: the version picker cannot return a file, and the file picker cannot be confirmed until a file is chosen. Two things change. **A file can be picked at all.** Today the picker stops at the version, so a UDF that opens one file has whoever fills the form pick the version and type the file name after it. **What the UDF receives can be read on any deployment.** Today it is a folder path, and that folder only exists on a Kubernetes computing unit, so a workflow written this way fails on a local one. Handing over the dataset's own path instead lets the same workflow run in both places: pytexera reads that path through the dataset API, which every deployment has. ### 3. The declaration comes from the code The frontend already reads each parameter's name and type out of the UDF source, and what it accepts comes from the same place. It is read again whenever the workflow is opened, so it stays in step with the code, and a workflow built by a script or imported from a file shows its controls too. The copy stored with the workflow is a cache. The declaration drives the UI only. The backend does not reject a value outside the declared set: the stored set can be older than the code, and rejecting a value would tell an author their own code is wrong. Thoughts on any of this are welcome. GitHub link: https://github.com/apache/texera/discussions/9338 ---- This is an automatically sent email for [email protected]. To unsubscribe, please send an email to: [email protected]
